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_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
35 static int qla2x00_restart_isp(scsi_qla_host_t
*);
37 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
38 static int qla84xx_init_chip(scsi_qla_host_t
*);
39 static int qla25xx_init_queues(struct qla_hw_data
*);
41 /* SRB Extensions ---------------------------------------------------------- */
44 qla2x00_sp_timeout(unsigned long __data
)
46 srb_t
*sp
= (srb_t
*)__data
;
47 struct srb_iocb
*iocb
;
48 fc_port_t
*fcport
= sp
->fcport
;
49 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
53 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
54 req
= ha
->req_q_map
[0];
55 req
->outstanding_cmds
[sp
->handle
] = NULL
;
56 iocb
= &sp
->u
.iocb_cmd
;
58 sp
->free(fcport
->vha
, sp
);
59 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
63 qla2x00_sp_free(void *data
, void *ptr
)
65 srb_t
*sp
= (srb_t
*)ptr
;
66 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
67 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
69 del_timer(&iocb
->timer
);
70 mempool_free(sp
, vha
->hw
->srb_mempool
);
72 QLA_VHA_MARK_NOT_BUSY(vha
);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
77 static inline unsigned long
78 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
81 struct qla_hw_data
*ha
= vha
->hw
;
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo
= ha
->r_a_tov
/ 10 * 2;
85 if (!IS_FWI2_CAPABLE(ha
)) {
87 * Except for earlier ISPs where the timeout is seeded from the
88 * initialization control block.
90 tmo
= ha
->login_timeout
;
96 qla2x00_async_iocb_timeout(void *data
)
98 srb_t
*sp
= (srb_t
*)data
;
99 fc_port_t
*fcport
= sp
->fcport
;
101 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
102 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
103 sp
->name
, sp
->handle
, fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
104 fcport
->d_id
.b
.al_pa
);
106 fcport
->flags
&= ~FCF_ASYNC_SENT
;
107 if (sp
->type
== SRB_LOGIN_CMD
) {
108 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
109 qla2x00_post_async_logout_work(fcport
->vha
, fcport
, NULL
);
110 /* Retry as needed. */
111 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
112 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
113 QLA_LOGIO_LOGIN_RETRIED
: 0;
114 qla2x00_post_async_login_done_work(fcport
->vha
, fcport
,
120 qla2x00_async_login_sp_done(void *data
, void *ptr
, int res
)
122 srb_t
*sp
= (srb_t
*)ptr
;
123 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
124 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
126 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
127 qla2x00_post_async_login_done_work(sp
->fcport
->vha
, sp
->fcport
,
129 sp
->free(sp
->fcport
->vha
, sp
);
133 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
137 struct srb_iocb
*lio
;
140 rval
= QLA_FUNCTION_FAILED
;
141 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
145 sp
->type
= SRB_LOGIN_CMD
;
147 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
149 lio
= &sp
->u
.iocb_cmd
;
150 lio
->timeout
= qla2x00_async_iocb_timeout
;
151 sp
->done
= qla2x00_async_login_sp_done
;
152 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
153 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
154 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
155 rval
= qla2x00_start_sp(sp
);
156 if (rval
!= QLA_SUCCESS
)
159 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
160 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
161 "retries=%d.\n", sp
->handle
, fcport
->loop_id
,
162 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
163 fcport
->login_retry
);
167 sp
->free(fcport
->vha
, sp
);
173 qla2x00_async_logout_sp_done(void *data
, void *ptr
, int res
)
175 srb_t
*sp
= (srb_t
*)ptr
;
176 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
177 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
179 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
180 qla2x00_post_async_logout_done_work(sp
->fcport
->vha
, sp
->fcport
,
182 sp
->free(sp
->fcport
->vha
, sp
);
186 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
189 struct srb_iocb
*lio
;
192 rval
= QLA_FUNCTION_FAILED
;
193 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
197 sp
->type
= SRB_LOGOUT_CMD
;
199 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
201 lio
= &sp
->u
.iocb_cmd
;
202 lio
->timeout
= qla2x00_async_iocb_timeout
;
203 sp
->done
= qla2x00_async_logout_sp_done
;
204 rval
= qla2x00_start_sp(sp
);
205 if (rval
!= QLA_SUCCESS
)
208 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
209 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
210 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
211 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
215 sp
->free(fcport
->vha
, sp
);
221 qla2x00_async_adisc_sp_done(void *data
, void *ptr
, int res
)
223 srb_t
*sp
= (srb_t
*)ptr
;
224 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
225 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
227 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
228 qla2x00_post_async_adisc_done_work(sp
->fcport
->vha
, sp
->fcport
,
230 sp
->free(sp
->fcport
->vha
, sp
);
234 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
238 struct srb_iocb
*lio
;
241 rval
= QLA_FUNCTION_FAILED
;
242 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
246 sp
->type
= SRB_ADISC_CMD
;
248 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
250 lio
= &sp
->u
.iocb_cmd
;
251 lio
->timeout
= qla2x00_async_iocb_timeout
;
252 sp
->done
= qla2x00_async_adisc_sp_done
;
253 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
254 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
255 rval
= qla2x00_start_sp(sp
);
256 if (rval
!= QLA_SUCCESS
)
259 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
260 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
261 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
262 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
266 sp
->free(fcport
->vha
, sp
);
272 qla2x00_async_tm_cmd_done(void *data
, void *ptr
, int res
)
274 srb_t
*sp
= (srb_t
*)ptr
;
275 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
276 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
281 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
282 flags
= iocb
->u
.tmf
.flags
;
283 lun
= (uint16_t)iocb
->u
.tmf
.lun
;
285 /* Issue Marker IOCB */
286 rval
= qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
287 vha
->hw
->rsp_q_map
[0], sp
->fcport
->loop_id
, lun
,
288 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
290 if ((rval
!= QLA_SUCCESS
) || iocb
->u
.tmf
.data
) {
291 ql_dbg(ql_dbg_taskm
, vha
, 0x8030,
292 "TM IOCB failed (%x).\n", rval
);
295 sp
->free(sp
->fcport
->vha
, sp
);
299 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t tm_flags
, uint32_t lun
,
302 struct scsi_qla_host
*vha
= fcport
->vha
;
304 struct srb_iocb
*tcf
;
307 rval
= QLA_FUNCTION_FAILED
;
308 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
312 sp
->type
= SRB_TM_CMD
;
314 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
316 tcf
= &sp
->u
.iocb_cmd
;
317 tcf
->u
.tmf
.flags
= tm_flags
;
318 tcf
->u
.tmf
.lun
= lun
;
319 tcf
->u
.tmf
.data
= tag
;
320 tcf
->timeout
= qla2x00_async_iocb_timeout
;
321 sp
->done
= qla2x00_async_tm_cmd_done
;
323 rval
= qla2x00_start_sp(sp
);
324 if (rval
!= QLA_SUCCESS
)
327 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
328 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
329 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
330 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
334 sp
->free(fcport
->vha
, sp
);
340 qla2x00_async_login_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
346 case MBS_COMMAND_COMPLETE
:
348 * Driver must validate login state - If PRLI not complete,
349 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
352 rval
= qla2x00_get_port_database(vha
, fcport
, 0);
353 if (rval
== QLA_NOT_LOGGED_IN
) {
354 fcport
->flags
&= ~FCF_ASYNC_SENT
;
355 fcport
->flags
|= FCF_LOGIN_NEEDED
;
356 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
360 if (rval
!= QLA_SUCCESS
) {
361 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
362 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
365 if (fcport
->flags
& FCF_FCP2_DEVICE
) {
366 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
369 qla2x00_update_fcport(vha
, fcport
);
371 case MBS_COMMAND_ERROR
:
372 fcport
->flags
&= ~FCF_ASYNC_SENT
;
373 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
374 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
376 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
378 case MBS_PORT_ID_USED
:
379 fcport
->loop_id
= data
[1];
380 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
381 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
383 case MBS_LOOP_ID_USED
:
385 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
386 if (rval
!= QLA_SUCCESS
) {
387 fcport
->flags
&= ~FCF_ASYNC_SENT
;
388 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
391 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
398 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
401 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
406 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
409 if (data
[0] == MBS_COMMAND_COMPLETE
) {
410 qla2x00_update_fcport(vha
, fcport
);
416 fcport
->flags
&= ~FCF_ASYNC_SENT
;
417 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
418 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
420 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
425 /****************************************************************************/
426 /* QLogic ISP2x00 Hardware Support Functions. */
427 /****************************************************************************/
430 * qla2x00_initialize_adapter
434 * ha = adapter block pointer.
440 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
443 struct qla_hw_data
*ha
= vha
->hw
;
444 struct req_que
*req
= ha
->req_q_map
[0];
446 /* Clear adapter flags. */
447 vha
->flags
.online
= 0;
448 ha
->flags
.chip_reset_done
= 0;
449 vha
->flags
.reset_active
= 0;
450 ha
->flags
.pci_channel_io_perm_failure
= 0;
451 ha
->flags
.eeh_busy
= 0;
452 ha
->flags
.thermal_supported
= 1;
453 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
454 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
455 vha
->device_flags
= DFLG_NO_CABLE
;
457 vha
->flags
.management_server_logged_in
= 0;
458 vha
->marker_needed
= 0;
459 ha
->isp_abort_cnt
= 0;
460 ha
->beacon_blink_led
= 0;
462 set_bit(0, ha
->req_qid_map
);
463 set_bit(0, ha
->rsp_qid_map
);
465 ql_dbg(ql_dbg_init
, vha
, 0x0040,
466 "Configuring PCI space...\n");
467 rval
= ha
->isp_ops
->pci_config(vha
);
469 ql_log(ql_log_warn
, vha
, 0x0044,
470 "Unable to configure PCI space.\n");
474 ha
->isp_ops
->reset_chip(vha
);
476 rval
= qla2xxx_get_flash_info(vha
);
478 ql_log(ql_log_fatal
, vha
, 0x004f,
479 "Unable to validate FLASH data.\n");
483 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
484 ql_dbg(ql_dbg_init
, vha
, 0x0061,
485 "Configure NVRAM parameters...\n");
487 ha
->isp_ops
->nvram_config(vha
);
489 if (ha
->flags
.disable_serdes
) {
490 /* Mask HBA via NVRAM settings? */
491 ql_log(ql_log_info
, vha
, 0x0077,
493 "%02x%02x%02x%02x%02x%02x%02x%02x (via NVRAM).\n",
494 vha
->port_name
[0], vha
->port_name
[1],
495 vha
->port_name
[2], vha
->port_name
[3],
496 vha
->port_name
[4], vha
->port_name
[5],
497 vha
->port_name
[6], vha
->port_name
[7]);
498 return QLA_FUNCTION_FAILED
;
501 ql_dbg(ql_dbg_init
, vha
, 0x0078,
502 "Verifying loaded RISC code...\n");
504 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
505 rval
= ha
->isp_ops
->chip_diag(vha
);
508 rval
= qla2x00_setup_chip(vha
);
513 if (IS_QLA84XX(ha
)) {
514 ha
->cs84xx
= qla84xx_get_chip(vha
);
516 ql_log(ql_log_warn
, vha
, 0x00d0,
517 "Unable to configure ISP84XX.\n");
518 return QLA_FUNCTION_FAILED
;
521 rval
= qla2x00_init_rings(vha
);
522 ha
->flags
.chip_reset_done
= 1;
524 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
525 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
526 rval
= qla84xx_init_chip(vha
);
527 if (rval
!= QLA_SUCCESS
) {
528 ql_log(ql_log_warn
, vha
, 0x00d4,
529 "Unable to initialize ISP84XX.\n");
530 qla84xx_put_chip(vha
);
534 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
535 qla24xx_read_fcp_prio_cfg(vha
);
541 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
544 * Returns 0 on success.
547 qla2100_pci_config(scsi_qla_host_t
*vha
)
551 struct qla_hw_data
*ha
= vha
->hw
;
552 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
554 pci_set_master(ha
->pdev
);
555 pci_try_set_mwi(ha
->pdev
);
557 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
558 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
559 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
561 pci_disable_rom(ha
->pdev
);
563 /* Get PCI bus information. */
564 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
565 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
566 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
572 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
575 * Returns 0 on success.
578 qla2300_pci_config(scsi_qla_host_t
*vha
)
581 unsigned long flags
= 0;
583 struct qla_hw_data
*ha
= vha
->hw
;
584 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
586 pci_set_master(ha
->pdev
);
587 pci_try_set_mwi(ha
->pdev
);
589 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
590 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
592 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
593 w
&= ~PCI_COMMAND_INTX_DISABLE
;
594 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
597 * If this is a 2300 card and not 2312, reset the
598 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
599 * the 2310 also reports itself as a 2300 so we need to get the
600 * fb revision level -- a 6 indicates it really is a 2300 and
603 if (IS_QLA2300(ha
)) {
604 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
607 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
608 for (cnt
= 0; cnt
< 30000; cnt
++) {
609 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
615 /* Select FPM registers. */
616 WRT_REG_WORD(®
->ctrl_status
, 0x20);
617 RD_REG_WORD(®
->ctrl_status
);
619 /* Get the fb rev level */
620 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
622 if (ha
->fb_rev
== FPM_2300
)
623 pci_clear_mwi(ha
->pdev
);
625 /* Deselect FPM registers. */
626 WRT_REG_WORD(®
->ctrl_status
, 0x0);
627 RD_REG_WORD(®
->ctrl_status
);
629 /* Release RISC module. */
630 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
631 for (cnt
= 0; cnt
< 30000; cnt
++) {
632 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
638 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
641 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
643 pci_disable_rom(ha
->pdev
);
645 /* Get PCI bus information. */
646 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
647 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
648 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
654 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
657 * Returns 0 on success.
660 qla24xx_pci_config(scsi_qla_host_t
*vha
)
663 unsigned long flags
= 0;
664 struct qla_hw_data
*ha
= vha
->hw
;
665 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
667 pci_set_master(ha
->pdev
);
668 pci_try_set_mwi(ha
->pdev
);
670 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
671 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
672 w
&= ~PCI_COMMAND_INTX_DISABLE
;
673 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
675 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
677 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
678 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
679 pcix_set_mmrbc(ha
->pdev
, 2048);
681 /* PCIe -- adjust Maximum Read Request Size (2048). */
682 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
683 pcie_set_readrq(ha
->pdev
, 2048);
685 pci_disable_rom(ha
->pdev
);
687 ha
->chip_revision
= ha
->pdev
->revision
;
689 /* Get PCI bus information. */
690 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
691 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
692 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
698 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
701 * Returns 0 on success.
704 qla25xx_pci_config(scsi_qla_host_t
*vha
)
707 struct qla_hw_data
*ha
= vha
->hw
;
709 pci_set_master(ha
->pdev
);
710 pci_try_set_mwi(ha
->pdev
);
712 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
713 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
714 w
&= ~PCI_COMMAND_INTX_DISABLE
;
715 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
717 /* PCIe -- adjust Maximum Read Request Size (2048). */
718 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_EXP
))
719 pcie_set_readrq(ha
->pdev
, 2048);
721 pci_disable_rom(ha
->pdev
);
723 ha
->chip_revision
= ha
->pdev
->revision
;
729 * qla2x00_isp_firmware() - Choose firmware image.
732 * Returns 0 on success.
735 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
738 uint16_t loop_id
, topo
, sw_cap
;
739 uint8_t domain
, area
, al_pa
;
740 struct qla_hw_data
*ha
= vha
->hw
;
742 /* Assume loading risc code */
743 rval
= QLA_FUNCTION_FAILED
;
745 if (ha
->flags
.disable_risc_code_load
) {
746 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
748 /* Verify checksum of loaded RISC code. */
749 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
750 if (rval
== QLA_SUCCESS
) {
751 /* And, verify we are not in ROM code. */
752 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
753 &area
, &domain
, &topo
, &sw_cap
);
758 ql_dbg(ql_dbg_init
, vha
, 0x007a,
759 "**** Load RISC code ****.\n");
765 * qla2x00_reset_chip() - Reset ISP chip.
768 * Returns 0 on success.
771 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
773 unsigned long flags
= 0;
774 struct qla_hw_data
*ha
= vha
->hw
;
775 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
779 if (unlikely(pci_channel_offline(ha
->pdev
)))
782 ha
->isp_ops
->disable_intrs(ha
);
784 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
786 /* Turn off master enable */
788 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
789 cmd
&= ~PCI_COMMAND_MASTER
;
790 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
792 if (!IS_QLA2100(ha
)) {
794 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
795 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
796 for (cnt
= 0; cnt
< 30000; cnt
++) {
797 if ((RD_REG_WORD(®
->hccr
) &
798 HCCR_RISC_PAUSE
) != 0)
803 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
807 /* Select FPM registers. */
808 WRT_REG_WORD(®
->ctrl_status
, 0x20);
809 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
811 /* FPM Soft Reset. */
812 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
813 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
815 /* Toggle Fpm Reset. */
816 if (!IS_QLA2200(ha
)) {
817 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
818 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
821 /* Select frame buffer registers. */
822 WRT_REG_WORD(®
->ctrl_status
, 0x10);
823 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
825 /* Reset frame buffer FIFOs. */
826 if (IS_QLA2200(ha
)) {
827 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
828 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
830 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
832 /* Read back fb_cmd until zero or 3 seconds max */
833 for (cnt
= 0; cnt
< 3000; cnt
++) {
834 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
840 /* Select RISC module registers. */
841 WRT_REG_WORD(®
->ctrl_status
, 0);
842 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
844 /* Reset RISC processor. */
845 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
846 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
848 /* Release RISC processor. */
849 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
850 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
853 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
854 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
856 /* Reset ISP chip. */
857 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
859 /* Wait for RISC to recover from reset. */
860 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
862 * It is necessary to for a delay here since the card doesn't
863 * respond to PCI reads during a reset. On some architectures
864 * this will result in an MCA.
867 for (cnt
= 30000; cnt
; cnt
--) {
868 if ((RD_REG_WORD(®
->ctrl_status
) &
869 CSR_ISP_SOFT_RESET
) == 0)
876 /* Reset RISC processor. */
877 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
879 WRT_REG_WORD(®
->semaphore
, 0);
881 /* Release RISC processor. */
882 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
883 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
885 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
886 for (cnt
= 0; cnt
< 30000; cnt
++) {
887 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
895 /* Turn on master enable */
896 cmd
|= PCI_COMMAND_MASTER
;
897 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
899 /* Disable RISC pause on FPM parity error. */
900 if (!IS_QLA2100(ha
)) {
901 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
902 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
905 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
909 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
911 * Returns 0 on success.
914 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
916 uint16_t mb
[4] = {0x1010, 0, 1, 0};
918 if (!IS_QLA81XX(vha
->hw
))
921 return qla81xx_write_mpi_register(vha
, mb
);
925 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
928 * Returns 0 on success.
931 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
933 unsigned long flags
= 0;
934 struct qla_hw_data
*ha
= vha
->hw
;
935 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
938 static int abts_cnt
; /* ISP abort retry counts */
940 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
943 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
944 for (cnt
= 0; cnt
< 30000; cnt
++) {
945 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
951 WRT_REG_DWORD(®
->ctrl_status
,
952 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
953 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
956 /* Wait for firmware to complete NVRAM accesses. */
957 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
958 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
960 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
964 /* Wait for soft-reset to complete. */
965 d2
= RD_REG_DWORD(®
->ctrl_status
);
966 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
968 d2
= RD_REG_DWORD(®
->ctrl_status
);
972 /* If required, do an MPI FW reset now */
973 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
974 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
975 if (++abts_cnt
< 5) {
976 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
977 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
980 * We exhausted the ISP abort retries. We have to
981 * set the board offline.
984 vha
->flags
.online
= 0;
989 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
990 RD_REG_DWORD(®
->hccr
);
992 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
993 RD_REG_DWORD(®
->hccr
);
995 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
996 RD_REG_DWORD(®
->hccr
);
998 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
999 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
1001 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1005 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1007 if (IS_NOPOLLING_TYPE(ha
))
1008 ha
->isp_ops
->enable_intrs(ha
);
1012 * qla24xx_reset_chip() - Reset ISP24xx chip.
1015 * Returns 0 on success.
1018 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
1020 struct qla_hw_data
*ha
= vha
->hw
;
1022 if (pci_channel_offline(ha
->pdev
) &&
1023 ha
->flags
.pci_channel_io_perm_failure
) {
1027 ha
->isp_ops
->disable_intrs(ha
);
1029 /* Perform RISC reset. */
1030 qla24xx_reset_risc(vha
);
1034 * qla2x00_chip_diag() - Test chip for proper operation.
1037 * Returns 0 on success.
1040 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
1043 struct qla_hw_data
*ha
= vha
->hw
;
1044 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1045 unsigned long flags
= 0;
1049 struct req_que
*req
= ha
->req_q_map
[0];
1051 /* Assume a failed state */
1052 rval
= QLA_FUNCTION_FAILED
;
1054 ql_dbg(ql_dbg_init
, vha
, 0x007b,
1055 "Testing device at %lx.\n", (u_long
)®
->flash_address
);
1057 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1059 /* Reset ISP chip. */
1060 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1063 * We need to have a delay here since the card will not respond while
1064 * in reset causing an MCA on some architectures.
1067 data
= qla2x00_debounce_register(®
->ctrl_status
);
1068 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
1070 data
= RD_REG_WORD(®
->ctrl_status
);
1075 goto chip_diag_failed
;
1077 ql_dbg(ql_dbg_init
, vha
, 0x007c,
1078 "Reset register cleared by chip reset.\n");
1080 /* Reset RISC processor. */
1081 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1082 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1084 /* Workaround for QLA2312 PCI parity error */
1085 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1086 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
1087 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
1089 data
= RD_MAILBOX_REG(ha
, reg
, 0);
1096 goto chip_diag_failed
;
1098 /* Check product ID of chip */
1099 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product Id of chip.\n");
1101 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
1102 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
1103 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
1104 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
1105 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
1106 mb
[3] != PROD_ID_3
) {
1107 ql_log(ql_log_warn
, vha
, 0x0062,
1108 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1109 mb
[1], mb
[2], mb
[3]);
1111 goto chip_diag_failed
;
1113 ha
->product_id
[0] = mb
[1];
1114 ha
->product_id
[1] = mb
[2];
1115 ha
->product_id
[2] = mb
[3];
1116 ha
->product_id
[3] = mb
[4];
1118 /* Adjust fw RISC transfer size */
1119 if (req
->length
> 1024)
1120 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
1122 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
1125 if (IS_QLA2200(ha
) &&
1126 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
1127 /* Limit firmware transfer size with a 2200A */
1128 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
1130 ha
->device_type
|= DT_ISP2200A
;
1131 ha
->fw_transfer_size
= 128;
1134 /* Wrap Incoming Mailboxes Test. */
1135 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1137 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
1138 rval
= qla2x00_mbx_reg_test(vha
);
1140 ql_log(ql_log_warn
, vha
, 0x0080,
1141 "Failed mailbox send register test.\n");
1143 /* Flag a successful rval */
1145 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1149 ql_log(ql_log_info
, vha
, 0x0081,
1150 "Chip diagnostics **** FAILED ****.\n");
1152 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1158 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1161 * Returns 0 on success.
1164 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
1167 struct qla_hw_data
*ha
= vha
->hw
;
1168 struct req_que
*req
= ha
->req_q_map
[0];
1173 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
1175 rval
= qla2x00_mbx_reg_test(vha
);
1177 ql_log(ql_log_warn
, vha
, 0x0082,
1178 "Failed mailbox send register test.\n");
1180 /* Flag a successful rval */
1188 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1191 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1192 eft_size
, fce_size
, mq_size
;
1195 struct qla_hw_data
*ha
= vha
->hw
;
1196 struct req_que
*req
= ha
->req_q_map
[0];
1197 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1200 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
1201 "Firmware dump already allocated.\n");
1206 fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1207 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1208 fixed_size
= sizeof(struct qla2100_fw_dump
);
1209 } else if (IS_QLA23XX(ha
)) {
1210 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1211 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1213 } else if (IS_FWI2_CAPABLE(ha
)) {
1215 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
1216 else if (IS_QLA81XX(ha
))
1217 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1218 else if (IS_QLA25XX(ha
))
1219 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1221 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1222 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1225 if (!IS_QLA83XX(ha
))
1226 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1228 * Allocate maximum buffer size for all queues.
1229 * Resizing must be done at end-of-dump processing.
1231 mq_size
+= ha
->max_req_queues
*
1232 (req
->length
* sizeof(request_t
));
1233 mq_size
+= ha
->max_rsp_queues
*
1234 (rsp
->length
* sizeof(response_t
));
1236 /* Allocate memory for Fibre Channel Event Buffer. */
1237 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
))
1240 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1243 ql_log(ql_log_warn
, vha
, 0x00be,
1244 "Unable to allocate (%d KB) for FCE.\n",
1249 memset(tc
, 0, FCE_SIZE
);
1250 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1251 ha
->fce_mb
, &ha
->fce_bufs
);
1253 ql_log(ql_log_warn
, vha
, 0x00bf,
1254 "Unable to initialize FCE (%d).\n", rval
);
1255 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1257 ha
->flags
.fce_enabled
= 0;
1260 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
1261 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
1263 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1264 ha
->flags
.fce_enabled
= 1;
1265 ha
->fce_dma
= tc_dma
;
1268 /* Allocate memory for Extended Trace Buffer. */
1269 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1272 ql_log(ql_log_warn
, vha
, 0x00c1,
1273 "Unable to allocate (%d KB) for EFT.\n",
1278 memset(tc
, 0, EFT_SIZE
);
1279 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1281 ql_log(ql_log_warn
, vha
, 0x00c2,
1282 "Unable to initialize EFT (%d).\n", rval
);
1283 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1287 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
1288 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
1290 eft_size
= EFT_SIZE
;
1291 ha
->eft_dma
= tc_dma
;
1295 req_q_size
= req
->length
* sizeof(request_t
);
1296 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1298 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1299 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1300 ha
->chain_offset
= dump_size
;
1301 dump_size
+= mq_size
+ fce_size
;
1303 ha
->fw_dump
= vmalloc(dump_size
);
1305 ql_log(ql_log_warn
, vha
, 0x00c4,
1306 "Unable to allocate (%d KB) for firmware dump.\n",
1310 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
1317 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1324 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
1325 "Allocated (%d KB) for firmware dump.\n", dump_size
/ 1024);
1327 ha
->fw_dump_len
= dump_size
;
1328 ha
->fw_dump
->signature
[0] = 'Q';
1329 ha
->fw_dump
->signature
[1] = 'L';
1330 ha
->fw_dump
->signature
[2] = 'G';
1331 ha
->fw_dump
->signature
[3] = 'C';
1332 ha
->fw_dump
->version
= __constant_htonl(1);
1334 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1335 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1336 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1337 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1339 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1340 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1341 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1343 ha
->fw_dump
->header_size
=
1344 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1348 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1350 #define MPS_MASK 0xe0
1355 if (!IS_QLA81XX(vha
->hw
))
1358 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1359 if (rval
!= QLA_SUCCESS
) {
1360 ql_log(ql_log_warn
, vha
, 0x0105,
1361 "Unable to acquire semaphore.\n");
1365 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1366 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1367 if (rval
!= QLA_SUCCESS
) {
1368 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
1373 if (dc
== (dw
& MPS_MASK
))
1378 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1379 if (rval
!= QLA_SUCCESS
) {
1380 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
1384 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1385 if (rval
!= QLA_SUCCESS
) {
1386 ql_log(ql_log_warn
, vha
, 0x006d,
1387 "Unable to release semaphore.\n");
1395 * qla2x00_setup_chip() - Load and start RISC firmware.
1398 * Returns 0 on success.
1401 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1404 uint32_t srisc_address
= 0;
1405 struct qla_hw_data
*ha
= vha
->hw
;
1406 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1407 unsigned long flags
;
1408 uint16_t fw_major_version
;
1410 if (IS_QLA82XX(ha
)) {
1411 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1412 if (rval
== QLA_SUCCESS
) {
1413 qla2x00_stop_firmware(vha
);
1414 goto enable_82xx_npiv
;
1419 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1420 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1421 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1422 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1423 RD_REG_WORD(®
->hccr
);
1424 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1427 qla81xx_mpi_sync(vha
);
1429 /* Load firmware sequences */
1430 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1431 if (rval
== QLA_SUCCESS
) {
1432 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
1433 "Verifying Checksum of loaded RISC code.\n");
1435 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1436 if (rval
== QLA_SUCCESS
) {
1437 /* Start firmware execution. */
1438 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
1439 "Starting firmware.\n");
1441 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1442 /* Retrieve firmware information. */
1443 if (rval
== QLA_SUCCESS
) {
1445 fw_major_version
= ha
->fw_major_version
;
1447 qla82xx_check_md_needed(vha
);
1449 rval
= qla2x00_get_fw_version(vha
);
1450 if (rval
!= QLA_SUCCESS
)
1452 ha
->flags
.npiv_supported
= 0;
1453 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1454 (ha
->fw_attributes
& BIT_2
)) {
1455 ha
->flags
.npiv_supported
= 1;
1456 if ((!ha
->max_npiv_vports
) ||
1457 ((ha
->max_npiv_vports
+ 1) %
1458 MIN_MULTI_ID_FABRIC
))
1459 ha
->max_npiv_vports
=
1460 MIN_MULTI_ID_FABRIC
- 1;
1462 qla2x00_get_resource_cnts(vha
, NULL
,
1463 &ha
->fw_xcb_count
, NULL
, NULL
,
1464 &ha
->max_npiv_vports
, NULL
);
1466 if (!fw_major_version
&& ql2xallocfwdump
1468 qla2x00_alloc_fw_dump(vha
);
1471 ql_log(ql_log_fatal
, vha
, 0x00cd,
1472 "ISP Firmware failed checksum.\n");
1477 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1478 /* Enable proper parity. */
1479 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1482 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1484 /* SRAM, Instruction RAM and GP RAM parity */
1485 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1486 RD_REG_WORD(®
->hccr
);
1487 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1491 goto skip_fac_check
;
1493 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1496 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1497 if (rval
== QLA_SUCCESS
) {
1498 ha
->flags
.fac_supported
= 1;
1499 ha
->fdt_block_size
= size
<< 2;
1501 ql_log(ql_log_warn
, vha
, 0x00ce,
1502 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1503 ha
->fw_major_version
, ha
->fw_minor_version
,
1504 ha
->fw_subminor_version
);
1506 if (IS_QLA83XX(ha
)) {
1507 ha
->flags
.fac_supported
= 0;
1514 ql_log(ql_log_fatal
, vha
, 0x00cf,
1515 "Setup chip ****FAILED****.\n");
1522 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1525 * Beginning of request ring has initialization control block already built
1526 * by nvram config routine.
1528 * Returns 0 on success.
1531 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1536 rsp
->ring_ptr
= rsp
->ring
;
1537 rsp
->ring_index
= 0;
1538 rsp
->status_srb
= NULL
;
1539 pkt
= rsp
->ring_ptr
;
1540 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1541 pkt
->signature
= RESPONSE_PROCESSED
;
1547 * qla2x00_update_fw_options() - Read and process firmware options.
1550 * Returns 0 on success.
1553 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1555 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1556 struct qla_hw_data
*ha
= vha
->hw
;
1558 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1559 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1561 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1564 /* Serial Link options. */
1565 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
1566 "Serial link options.\n");
1567 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
1568 (uint8_t *)&ha
->fw_seriallink_options
,
1569 sizeof(ha
->fw_seriallink_options
));
1571 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1572 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1573 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1576 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1577 emphasis
= (ha
->fw_seriallink_options
[2] &
1578 (BIT_4
| BIT_3
)) >> 3;
1579 tx_sens
= ha
->fw_seriallink_options
[0] &
1580 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1581 rx_sens
= (ha
->fw_seriallink_options
[0] &
1582 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1583 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1584 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1587 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1588 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1589 ha
->fw_options
[10] |= BIT_5
|
1590 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1591 (tx_sens
& (BIT_1
| BIT_0
));
1594 swing
= (ha
->fw_seriallink_options
[2] &
1595 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1596 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1597 tx_sens
= ha
->fw_seriallink_options
[1] &
1598 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1599 rx_sens
= (ha
->fw_seriallink_options
[1] &
1600 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1601 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1602 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1605 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1606 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1607 ha
->fw_options
[11] |= BIT_5
|
1608 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1609 (tx_sens
& (BIT_1
| BIT_0
));
1613 /* Return command IOCBs without waiting for an ABTS to complete. */
1614 ha
->fw_options
[3] |= BIT_13
;
1617 if (ha
->flags
.enable_led_scheme
)
1618 ha
->fw_options
[2] |= BIT_12
;
1620 /* Detect ISP6312. */
1622 ha
->fw_options
[2] |= BIT_13
;
1624 /* Update firmware options. */
1625 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1629 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1632 struct qla_hw_data
*ha
= vha
->hw
;
1637 /* Update Serial Link options. */
1638 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
1641 rval
= qla2x00_set_serdes_params(vha
,
1642 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
1643 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
1644 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
1645 if (rval
!= QLA_SUCCESS
) {
1646 ql_log(ql_log_warn
, vha
, 0x0104,
1647 "Unable to update Serial Link options (%x).\n", rval
);
1652 qla2x00_config_rings(struct scsi_qla_host
*vha
)
1654 struct qla_hw_data
*ha
= vha
->hw
;
1655 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1656 struct req_que
*req
= ha
->req_q_map
[0];
1657 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1659 /* Setup ring parameters in initialization control block. */
1660 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1661 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1662 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
1663 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
1664 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1665 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1666 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1667 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1669 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
1670 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
1671 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
1672 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
1673 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
1677 qla24xx_config_rings(struct scsi_qla_host
*vha
)
1679 struct qla_hw_data
*ha
= vha
->hw
;
1680 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
1681 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
1682 struct qla_msix_entry
*msix
;
1683 struct init_cb_24xx
*icb
;
1685 struct req_que
*req
= ha
->req_q_map
[0];
1686 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1688 /* Setup ring parameters in initialization control block. */
1689 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
1690 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
1691 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
1692 icb
->request_q_length
= cpu_to_le16(req
->length
);
1693 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
1694 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
1695 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
1696 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
1697 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
1699 if (ha
->mqenable
|| IS_QLA83XX(ha
)) {
1700 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
1701 icb
->rid
= __constant_cpu_to_le16(rid
);
1702 if (ha
->flags
.msix_enabled
) {
1703 msix
= &ha
->msix_entries
[1];
1704 ql_dbg(ql_dbg_init
, vha
, 0x00fd,
1705 "Registering vector 0x%x for base que.\n",
1707 icb
->msix
= cpu_to_le16(msix
->entry
);
1709 /* Use alternate PCI bus number */
1711 icb
->firmware_options_2
|=
1712 __constant_cpu_to_le32(BIT_19
);
1713 /* Use alternate PCI devfn */
1715 icb
->firmware_options_2
|=
1716 __constant_cpu_to_le32(BIT_18
);
1718 /* Use Disable MSIX Handshake mode for capable adapters */
1719 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
1720 (ha
->flags
.msix_enabled
)) {
1721 icb
->firmware_options_2
&=
1722 __constant_cpu_to_le32(~BIT_22
);
1723 ha
->flags
.disable_msix_handshake
= 1;
1724 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
1725 "MSIX Handshake Disable Mode turned on.\n");
1727 icb
->firmware_options_2
|=
1728 __constant_cpu_to_le32(BIT_22
);
1730 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
1732 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
1733 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
1734 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
1735 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
1737 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
1738 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
1739 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
1740 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
1743 RD_REG_DWORD(&ioreg
->hccr
);
1747 * qla2x00_init_rings() - Initializes firmware.
1750 * Beginning of request ring has initialization control block already built
1751 * by nvram config routine.
1753 * Returns 0 on success.
1756 qla2x00_init_rings(scsi_qla_host_t
*vha
)
1759 unsigned long flags
= 0;
1761 struct qla_hw_data
*ha
= vha
->hw
;
1762 struct req_que
*req
;
1763 struct rsp_que
*rsp
;
1764 struct mid_init_cb_24xx
*mid_init_cb
=
1765 (struct mid_init_cb_24xx
*) ha
->init_cb
;
1767 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1769 /* Clear outstanding commands array. */
1770 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
1771 req
= ha
->req_q_map
[que
];
1774 for (cnt
= 1; cnt
< MAX_OUTSTANDING_COMMANDS
; cnt
++)
1775 req
->outstanding_cmds
[cnt
] = NULL
;
1777 req
->current_outstanding_cmd
= 1;
1779 /* Initialize firmware. */
1780 req
->ring_ptr
= req
->ring
;
1781 req
->ring_index
= 0;
1782 req
->cnt
= req
->length
;
1785 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
1786 rsp
= ha
->rsp_q_map
[que
];
1789 /* Initialize response queue entries */
1790 qla2x00_init_response_q_entries(rsp
);
1793 spin_lock(&ha
->vport_slock
);
1795 spin_unlock(&ha
->vport_slock
);
1797 ha
->isp_ops
->config_rings(vha
);
1799 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1801 /* Update any ISP specific firmware options before initialization. */
1802 ha
->isp_ops
->update_fw_options(vha
);
1804 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
1806 if (ha
->flags
.npiv_supported
) {
1807 if (ha
->operating_mode
== LOOP
)
1808 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
1809 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
1812 if (IS_FWI2_CAPABLE(ha
)) {
1813 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
1814 mid_init_cb
->init_cb
.execution_throttle
=
1815 cpu_to_le16(ha
->fw_xcb_count
);
1818 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
1820 ql_log(ql_log_fatal
, vha
, 0x00d2,
1821 "Init Firmware **** FAILED ****.\n");
1823 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
1824 "Init Firmware -- success.\n");
1831 * qla2x00_fw_ready() - Waits for firmware ready.
1834 * Returns 0 on success.
1837 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
1840 unsigned long wtime
, mtime
, cs84xx_time
;
1841 uint16_t min_wait
; /* Minimum wait time if loop is down */
1842 uint16_t wait_time
; /* Wait time if loop is coming ready */
1844 struct qla_hw_data
*ha
= vha
->hw
;
1848 /* 20 seconds for loop down. */
1852 * Firmware should take at most one RATOV to login, plus 5 seconds for
1853 * our own processing.
1855 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
1856 wait_time
= min_wait
;
1859 /* Min wait time if loop down */
1860 mtime
= jiffies
+ (min_wait
* HZ
);
1862 /* wait time before firmware ready */
1863 wtime
= jiffies
+ (wait_time
* HZ
);
1865 /* Wait for ISP to finish LIP */
1866 if (!vha
->flags
.init_done
)
1867 ql_log(ql_log_info
, vha
, 0x801e,
1868 "Waiting for LIP to complete.\n");
1871 rval
= qla2x00_get_firmware_state(vha
, state
);
1872 if (rval
== QLA_SUCCESS
) {
1873 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
1874 vha
->device_flags
&= ~DFLG_NO_CABLE
;
1876 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
1877 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
1878 "fw_state=%x 84xx=%x.\n", state
[0],
1880 if ((state
[2] & FSTATE_LOGGED_IN
) &&
1881 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
1882 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
1883 "Sending verify iocb.\n");
1885 cs84xx_time
= jiffies
;
1886 rval
= qla84xx_init_chip(vha
);
1887 if (rval
!= QLA_SUCCESS
) {
1890 "Init chip failed.\n");
1894 /* Add time taken to initialize. */
1895 cs84xx_time
= jiffies
- cs84xx_time
;
1896 wtime
+= cs84xx_time
;
1897 mtime
+= cs84xx_time
;
1898 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
1899 "Increasing wait time by %ld. "
1900 "New time %ld.\n", cs84xx_time
,
1903 } else if (state
[0] == FSTATE_READY
) {
1904 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
1905 "F/W Ready - OK.\n");
1907 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
1908 &ha
->login_timeout
, &ha
->r_a_tov
);
1914 rval
= QLA_FUNCTION_FAILED
;
1916 if (atomic_read(&vha
->loop_down_timer
) &&
1917 state
[0] != FSTATE_READY
) {
1918 /* Loop down. Timeout on min_wait for states
1919 * other than Wait for Login.
1921 if (time_after_eq(jiffies
, mtime
)) {
1922 ql_log(ql_log_info
, vha
, 0x8038,
1923 "Cable is unplugged...\n");
1925 vha
->device_flags
|= DFLG_NO_CABLE
;
1930 /* Mailbox cmd failed. Timeout on min_wait. */
1931 if (time_after_eq(jiffies
, mtime
) ||
1932 ha
->flags
.isp82xx_fw_hung
)
1936 if (time_after_eq(jiffies
, wtime
))
1939 /* Delay for a while */
1943 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
1944 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state
[0],
1945 state
[1], state
[2], state
[3], state
[4], jiffies
);
1947 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
1948 ql_log(ql_log_warn
, vha
, 0x803b,
1949 "Firmware ready **** FAILED ****.\n");
1956 * qla2x00_configure_hba
1957 * Setup adapter context.
1960 * ha = adapter state pointer.
1969 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
1978 char connect_type
[22];
1979 struct qla_hw_data
*ha
= vha
->hw
;
1981 /* Get host addresses. */
1982 rval
= qla2x00_get_adapter_id(vha
,
1983 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
1984 if (rval
!= QLA_SUCCESS
) {
1985 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
1986 IS_CNA_CAPABLE(ha
) ||
1987 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
1988 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
1989 "Loop is in a transition state.\n");
1991 ql_log(ql_log_warn
, vha
, 0x2009,
1992 "Unable to get host loop ID.\n");
1993 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1999 ql_log(ql_log_info
, vha
, 0x200a,
2000 "Cannot get topology - retrying.\n");
2001 return (QLA_FUNCTION_FAILED
);
2004 vha
->loop_id
= loop_id
;
2007 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
2008 ha
->operating_mode
= LOOP
;
2013 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
2014 ha
->current_topology
= ISP_CFG_NL
;
2015 strcpy(connect_type
, "(Loop)");
2019 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
2020 ha
->switch_cap
= sw_cap
;
2021 ha
->current_topology
= ISP_CFG_FL
;
2022 strcpy(connect_type
, "(FL_Port)");
2026 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
2027 ha
->operating_mode
= P2P
;
2028 ha
->current_topology
= ISP_CFG_N
;
2029 strcpy(connect_type
, "(N_Port-to-N_Port)");
2033 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
2034 ha
->switch_cap
= sw_cap
;
2035 ha
->operating_mode
= P2P
;
2036 ha
->current_topology
= ISP_CFG_F
;
2037 strcpy(connect_type
, "(F_Port)");
2041 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
2042 "HBA in unknown topology %x, using NL.\n", topo
);
2043 ha
->current_topology
= ISP_CFG_NL
;
2044 strcpy(connect_type
, "(Loop)");
2048 /* Save Host port and loop ID. */
2049 /* byte order - Big Endian */
2050 vha
->d_id
.b
.domain
= domain
;
2051 vha
->d_id
.b
.area
= area
;
2052 vha
->d_id
.b
.al_pa
= al_pa
;
2054 if (!vha
->flags
.init_done
)
2055 ql_log(ql_log_info
, vha
, 0x2010,
2056 "Topology - %s, Host Loop address 0x%x.\n",
2057 connect_type
, vha
->loop_id
);
2060 ql_log(ql_log_warn
, vha
, 0x2011,
2061 "%s FAILED\n", __func__
);
2063 ql_dbg(ql_dbg_disc
, vha
, 0x2012,
2064 "%s success\n", __func__
);
2071 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
2076 struct qla_hw_data
*ha
= vha
->hw
;
2077 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
2078 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
2080 if (memcmp(model
, BINZERO
, len
) != 0) {
2081 strncpy(ha
->model_number
, model
, len
);
2082 st
= en
= ha
->model_number
;
2085 if (*en
!= 0x20 && *en
!= 0x00)
2090 index
= (ha
->pdev
->subsystem_device
& 0xff);
2092 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2093 index
< QLA_MODEL_NAMES
)
2094 strncpy(ha
->model_desc
,
2095 qla2x00_model_name
[index
* 2 + 1],
2096 sizeof(ha
->model_desc
) - 1);
2098 index
= (ha
->pdev
->subsystem_device
& 0xff);
2100 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2101 index
< QLA_MODEL_NAMES
) {
2102 strcpy(ha
->model_number
,
2103 qla2x00_model_name
[index
* 2]);
2104 strncpy(ha
->model_desc
,
2105 qla2x00_model_name
[index
* 2 + 1],
2106 sizeof(ha
->model_desc
) - 1);
2108 strcpy(ha
->model_number
, def
);
2111 if (IS_FWI2_CAPABLE(ha
))
2112 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
2113 sizeof(ha
->model_desc
));
2116 /* On sparc systems, obtain port and node WWN from firmware
2119 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
2122 struct qla_hw_data
*ha
= vha
->hw
;
2123 struct pci_dev
*pdev
= ha
->pdev
;
2124 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
2128 val
= of_get_property(dp
, "port-wwn", &len
);
2129 if (val
&& len
>= WWN_SIZE
)
2130 memcpy(nv
->port_name
, val
, WWN_SIZE
);
2132 val
= of_get_property(dp
, "node-wwn", &len
);
2133 if (val
&& len
>= WWN_SIZE
)
2134 memcpy(nv
->node_name
, val
, WWN_SIZE
);
2139 * NVRAM configuration for ISP 2xxx
2142 * ha = adapter block pointer.
2145 * initialization control block in response_ring
2146 * host adapters parameters in host adapter block
2152 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
2157 uint8_t *dptr1
, *dptr2
;
2158 struct qla_hw_data
*ha
= vha
->hw
;
2159 init_cb_t
*icb
= ha
->init_cb
;
2160 nvram_t
*nv
= ha
->nvram
;
2161 uint8_t *ptr
= ha
->nvram
;
2162 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2166 /* Determine NVRAM starting address. */
2167 ha
->nvram_size
= sizeof(nvram_t
);
2169 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
2170 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
2171 ha
->nvram_base
= 0x80;
2173 /* Get NVRAM data and calculate checksum. */
2174 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
2175 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
2178 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
2179 "Contents of NVRAM.\n");
2180 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
2181 (uint8_t *)nv
, ha
->nvram_size
);
2183 /* Bad NVRAM data, set defaults parameters. */
2184 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2185 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
2186 /* Reset NVRAM data. */
2187 ql_log(ql_log_warn
, vha
, 0x0064,
2188 "Inconsistent NVRAM "
2189 "detected: checksum=0x%x id=%c version=0x%x.\n",
2190 chksum
, nv
->id
[0], nv
->nvram_version
);
2191 ql_log(ql_log_warn
, vha
, 0x0065,
2193 "functioning (yet invalid -- WWPN) defaults.\n");
2196 * Set default initialization control block.
2198 memset(nv
, 0, ha
->nvram_size
);
2199 nv
->parameter_block_version
= ICB_VERSION
;
2201 if (IS_QLA23XX(ha
)) {
2202 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2203 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2204 nv
->add_firmware_options
[0] = BIT_5
;
2205 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2206 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2207 nv
->special_options
[1] = BIT_7
;
2208 } else if (IS_QLA2200(ha
)) {
2209 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2210 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2211 nv
->add_firmware_options
[0] = BIT_5
;
2212 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2213 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2214 } else if (IS_QLA2100(ha
)) {
2215 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2216 nv
->firmware_options
[1] = BIT_5
;
2217 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2220 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2221 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2222 nv
->retry_count
= 8;
2223 nv
->retry_delay
= 1;
2225 nv
->port_name
[0] = 33;
2226 nv
->port_name
[3] = 224;
2227 nv
->port_name
[4] = 139;
2229 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2231 nv
->login_timeout
= 4;
2234 * Set default host adapter parameters
2236 nv
->host_p
[1] = BIT_2
;
2237 nv
->reset_delay
= 5;
2238 nv
->port_down_retry_count
= 8;
2239 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2240 nv
->link_down_timeout
= 60;
2245 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2247 * The SN2 does not provide BIOS emulation which means you can't change
2248 * potentially bogus BIOS settings. Force the use of default settings
2249 * for link rate and frame size. Hope that the rest of the settings
2252 if (ia64_platform_is("sn2")) {
2253 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2255 nv
->special_options
[1] = BIT_7
;
2259 /* Reset Initialization control block */
2260 memset(icb
, 0, ha
->init_cb_size
);
2263 * Setup driver NVRAM options.
2265 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2266 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2267 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2268 nv
->firmware_options
[1] &= ~BIT_4
;
2270 if (IS_QLA23XX(ha
)) {
2271 nv
->firmware_options
[0] |= BIT_2
;
2272 nv
->firmware_options
[0] &= ~BIT_3
;
2273 nv
->firmware_options
[0] &= ~BIT_6
;
2274 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2276 if (IS_QLA2300(ha
)) {
2277 if (ha
->fb_rev
== FPM_2310
) {
2278 strcpy(ha
->model_number
, "QLA2310");
2280 strcpy(ha
->model_number
, "QLA2300");
2283 qla2x00_set_model_info(vha
, nv
->model_number
,
2284 sizeof(nv
->model_number
), "QLA23xx");
2286 } else if (IS_QLA2200(ha
)) {
2287 nv
->firmware_options
[0] |= BIT_2
;
2289 * 'Point-to-point preferred, else loop' is not a safe
2290 * connection mode setting.
2292 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2294 /* Force 'loop preferred, else point-to-point'. */
2295 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2296 nv
->add_firmware_options
[0] |= BIT_5
;
2298 strcpy(ha
->model_number
, "QLA22xx");
2299 } else /*if (IS_QLA2100(ha))*/ {
2300 strcpy(ha
->model_number
, "QLA2100");
2304 * Copy over NVRAM RISC parameter block to initialization control block.
2306 dptr1
= (uint8_t *)icb
;
2307 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2308 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2310 *dptr1
++ = *dptr2
++;
2312 /* Copy 2nd half. */
2313 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2314 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2316 *dptr1
++ = *dptr2
++;
2318 /* Use alternate WWN? */
2319 if (nv
->host_p
[1] & BIT_7
) {
2320 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2321 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2324 /* Prepare nodename */
2325 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2327 * Firmware will apply the following mask if the nodename was
2330 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2331 icb
->node_name
[0] &= 0xF0;
2335 * Set host adapter parameters.
2339 * BIT_7 in the host-parameters section allows for modification to
2340 * internal driver logging.
2342 if (nv
->host_p
[0] & BIT_7
)
2343 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
2344 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2345 /* Always load RISC code on non ISP2[12]00 chips. */
2346 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2347 ha
->flags
.disable_risc_code_load
= 0;
2348 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2349 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2350 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2351 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2352 ha
->flags
.disable_serdes
= 0;
2354 ha
->operating_mode
=
2355 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2357 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2358 sizeof(ha
->fw_seriallink_options
));
2360 /* save HBA serial number */
2361 ha
->serial0
= icb
->port_name
[5];
2362 ha
->serial1
= icb
->port_name
[6];
2363 ha
->serial2
= icb
->port_name
[7];
2364 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2365 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2367 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2369 ha
->retry_count
= nv
->retry_count
;
2371 /* Set minimum login_timeout to 4 seconds. */
2372 if (nv
->login_timeout
!= ql2xlogintimeout
)
2373 nv
->login_timeout
= ql2xlogintimeout
;
2374 if (nv
->login_timeout
< 4)
2375 nv
->login_timeout
= 4;
2376 ha
->login_timeout
= nv
->login_timeout
;
2377 icb
->login_timeout
= nv
->login_timeout
;
2379 /* Set minimum RATOV to 100 tenths of a second. */
2382 ha
->loop_reset_delay
= nv
->reset_delay
;
2384 /* Link Down Timeout = 0:
2386 * When Port Down timer expires we will start returning
2387 * I/O's to OS with "DID_NO_CONNECT".
2389 * Link Down Timeout != 0:
2391 * The driver waits for the link to come up after link down
2392 * before returning I/Os to OS with "DID_NO_CONNECT".
2394 if (nv
->link_down_timeout
== 0) {
2395 ha
->loop_down_abort_time
=
2396 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2398 ha
->link_down_timeout
= nv
->link_down_timeout
;
2399 ha
->loop_down_abort_time
=
2400 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2404 * Need enough time to try and get the port back.
2406 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2407 if (qlport_down_retry
)
2408 ha
->port_down_retry_count
= qlport_down_retry
;
2409 /* Set login_retry_count */
2410 ha
->login_retry_count
= nv
->retry_count
;
2411 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2412 ha
->port_down_retry_count
> 3)
2413 ha
->login_retry_count
= ha
->port_down_retry_count
;
2414 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2415 ha
->login_retry_count
= ha
->port_down_retry_count
;
2416 if (ql2xloginretrycount
)
2417 ha
->login_retry_count
= ql2xloginretrycount
;
2419 icb
->lun_enables
= __constant_cpu_to_le16(0);
2420 icb
->command_resource_count
= 0;
2421 icb
->immediate_notify_resource_count
= 0;
2422 icb
->timeout
= __constant_cpu_to_le16(0);
2424 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2426 icb
->firmware_options
[0] &= ~BIT_3
;
2427 icb
->add_firmware_options
[0] &=
2428 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2429 icb
->add_firmware_options
[0] |= BIT_2
;
2430 icb
->response_accumulation_timer
= 3;
2431 icb
->interrupt_delay_timer
= 5;
2433 vha
->flags
.process_response_queue
= 1;
2436 if (!vha
->flags
.init_done
) {
2437 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2438 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2439 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2440 icb
->interrupt_delay_timer
: 2;
2442 icb
->add_firmware_options
[0] &=
2443 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2444 vha
->flags
.process_response_queue
= 0;
2445 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2446 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2448 ql_log(ql_log_info
, vha
, 0x0068,
2449 "ZIO mode %d enabled; timer delay (%d us).\n",
2450 ha
->zio_mode
, ha
->zio_timer
* 100);
2452 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2453 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2454 vha
->flags
.process_response_queue
= 1;
2459 ql_log(ql_log_warn
, vha
, 0x0069,
2460 "NVRAM configuration failed.\n");
2466 qla2x00_rport_del(void *data
)
2468 fc_port_t
*fcport
= data
;
2469 struct fc_rport
*rport
;
2470 unsigned long flags
;
2472 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2473 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2474 fcport
->drport
= NULL
;
2475 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2477 fc_remote_port_delete(rport
);
2481 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2483 * @flags: allocation flags
2485 * Returns a pointer to the allocated fcport, or NULL, if none available.
2488 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2492 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2496 /* Setup fcport template structure. */
2498 fcport
->port_type
= FCT_UNKNOWN
;
2499 fcport
->loop_id
= FC_NO_LOOP_ID
;
2500 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
2501 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2502 fcport
->scan_state
= QLA_FCPORT_SCAN_NONE
;
2508 * qla2x00_configure_loop
2509 * Updates Fibre Channel Device Database with what is actually on loop.
2512 * ha = adapter block pointer.
2517 * 2 = database was full and device was not configured.
2520 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2523 unsigned long flags
, save_flags
;
2524 struct qla_hw_data
*ha
= vha
->hw
;
2527 /* Get Initiator ID */
2528 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2529 rval
= qla2x00_configure_hba(vha
);
2530 if (rval
!= QLA_SUCCESS
) {
2531 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
2532 "Unable to configure HBA.\n");
2537 save_flags
= flags
= vha
->dpc_flags
;
2538 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
2539 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
2542 * If we have both an RSCN and PORT UPDATE pending then handle them
2543 * both at the same time.
2545 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2546 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2548 qla2x00_get_data_rate(vha
);
2550 /* Determine what we need to do */
2551 if (ha
->current_topology
== ISP_CFG_FL
&&
2552 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2554 set_bit(RSCN_UPDATE
, &flags
);
2556 } else if (ha
->current_topology
== ISP_CFG_F
&&
2557 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2559 set_bit(RSCN_UPDATE
, &flags
);
2560 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2562 } else if (ha
->current_topology
== ISP_CFG_N
) {
2563 clear_bit(RSCN_UPDATE
, &flags
);
2565 } else if (!vha
->flags
.online
||
2566 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2568 set_bit(RSCN_UPDATE
, &flags
);
2569 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2572 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2573 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2574 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
2575 "Loop resync needed, failing.\n");
2576 rval
= QLA_FUNCTION_FAILED
;
2578 rval
= qla2x00_configure_local_loop(vha
);
2581 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2582 if (LOOP_TRANSITION(vha
)) {
2583 ql_dbg(ql_dbg_disc
, vha
, 0x201e,
2584 "Needs RSCN update and loop transition.\n");
2585 rval
= QLA_FUNCTION_FAILED
;
2588 rval
= qla2x00_configure_fabric(vha
);
2591 if (rval
== QLA_SUCCESS
) {
2592 if (atomic_read(&vha
->loop_down_timer
) ||
2593 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2594 rval
= QLA_FUNCTION_FAILED
;
2596 atomic_set(&vha
->loop_state
, LOOP_READY
);
2597 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
2603 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
2604 "%s *** FAILED ***.\n", __func__
);
2606 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
2607 "%s: exiting normally.\n", __func__
);
2610 /* Restore state if a resync event occurred during processing */
2611 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2612 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
2613 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2614 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
2615 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2625 * qla2x00_configure_local_loop
2626 * Updates Fibre Channel Device Database with local loop devices.
2629 * ha = adapter block pointer.
2635 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
2640 fc_port_t
*fcport
, *new_fcport
;
2646 uint8_t domain
, area
, al_pa
;
2647 struct qla_hw_data
*ha
= vha
->hw
;
2651 entries
= MAX_FIBRE_DEVICES_LOOP
;
2653 ql_dbg(ql_dbg_disc
, vha
, 0x2016,
2654 "Getting FCAL position map.\n");
2655 if (ql2xextended_error_logging
& ql_dbg_disc
)
2656 qla2x00_get_fcal_position_map(vha
, NULL
);
2658 /* Get list of logged in devices. */
2659 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
2660 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
2662 if (rval
!= QLA_SUCCESS
)
2663 goto cleanup_allocation
;
2665 ql_dbg(ql_dbg_disc
, vha
, 0x2017,
2666 "Entries in ID list (%d).\n", entries
);
2667 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
2668 (uint8_t *)ha
->gid_list
,
2669 entries
* sizeof(struct gid_list_info
));
2671 /* Allocate temporary fcport for any new fcports discovered. */
2672 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2673 if (new_fcport
== NULL
) {
2674 ql_log(ql_log_warn
, vha
, 0x2018,
2675 "Memory allocation failed for fcport.\n");
2676 rval
= QLA_MEMORY_ALLOC_FAILED
;
2677 goto cleanup_allocation
;
2679 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2682 * Mark local devices that were present with FCF_DEVICE_LOST for now.
2684 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2685 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
2686 fcport
->port_type
!= FCT_BROADCAST
&&
2687 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
2689 ql_dbg(ql_dbg_disc
, vha
, 0x2019,
2690 "Marking port lost loop_id=0x%04x.\n",
2693 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
2697 /* Add devices to port list. */
2698 id_iter
= (char *)ha
->gid_list
;
2699 for (index
= 0; index
< entries
; index
++) {
2700 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
2701 area
= ((struct gid_list_info
*)id_iter
)->area
;
2702 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
2703 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
2704 loop_id
= (uint16_t)
2705 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
2707 loop_id
= le16_to_cpu(
2708 ((struct gid_list_info
*)id_iter
)->loop_id
);
2709 id_iter
+= ha
->gid_list_info_size
;
2711 /* Bypass reserved domain fields. */
2712 if ((domain
& 0xf0) == 0xf0)
2715 /* Bypass if not same domain and area of adapter. */
2716 if (area
&& domain
&&
2717 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
2720 /* Bypass invalid local loop ID. */
2721 if (loop_id
> LAST_LOCAL_LOOP_ID
)
2724 /* Fill in member data. */
2725 new_fcport
->d_id
.b
.domain
= domain
;
2726 new_fcport
->d_id
.b
.area
= area
;
2727 new_fcport
->d_id
.b
.al_pa
= al_pa
;
2728 new_fcport
->loop_id
= loop_id
;
2729 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
2730 if (rval2
!= QLA_SUCCESS
) {
2731 ql_dbg(ql_dbg_disc
, vha
, 0x201a,
2732 "Failed to retrieve fcport information "
2733 "-- get_port_database=%x, loop_id=0x%04x.\n",
2734 rval2
, new_fcport
->loop_id
);
2735 ql_dbg(ql_dbg_disc
, vha
, 0x201b,
2736 "Scheduling resync.\n");
2737 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2741 /* Check for matching device in port list. */
2744 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2745 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
2749 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2750 fcport
->loop_id
= new_fcport
->loop_id
;
2751 fcport
->port_type
= new_fcport
->port_type
;
2752 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
2753 memcpy(fcport
->node_name
, new_fcport
->node_name
,
2761 /* New device, add to fcports list. */
2762 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
2764 /* Allocate a new replacement fcport. */
2765 fcport
= new_fcport
;
2766 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
2767 if (new_fcport
== NULL
) {
2768 ql_log(ql_log_warn
, vha
, 0x201c,
2769 "Failed to allocate memory for fcport.\n");
2770 rval
= QLA_MEMORY_ALLOC_FAILED
;
2771 goto cleanup_allocation
;
2773 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
2776 /* Base iIDMA settings on HBA port speed. */
2777 fcport
->fp_speed
= ha
->link_data_rate
;
2779 qla2x00_update_fcport(vha
, fcport
);
2787 if (rval
!= QLA_SUCCESS
) {
2788 ql_dbg(ql_dbg_disc
, vha
, 0x201d,
2789 "Configure local loop error exit: rval=%x.\n", rval
);
2796 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2801 struct qla_hw_data
*ha
= vha
->hw
;
2803 if (!IS_IIDMA_CAPABLE(ha
))
2806 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
2809 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
2810 fcport
->fp_speed
> ha
->link_data_rate
)
2813 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
2815 if (rval
!= QLA_SUCCESS
) {
2816 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
2817 "Unable to adjust iIDMA "
2818 "%02x%02x%02x%02x%02x%02x%02x%02x -- %04x %x %04x "
2819 "%04x.\n", fcport
->port_name
[0], fcport
->port_name
[1],
2820 fcport
->port_name
[2], fcport
->port_name
[3],
2821 fcport
->port_name
[4], fcport
->port_name
[5],
2822 fcport
->port_name
[6], fcport
->port_name
[7], rval
,
2823 fcport
->fp_speed
, mb
[0], mb
[1]);
2825 link_speed
= qla2x00_get_link_speed_str(ha
);
2826 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
2827 "iIDMA adjusted to %s GB/s "
2828 "on %02x%02x%02x%02x%02x%02x%02x%02x.\n", link_speed
,
2829 fcport
->port_name
[0], fcport
->port_name
[1],
2830 fcport
->port_name
[2], fcport
->port_name
[3],
2831 fcport
->port_name
[4], fcport
->port_name
[5],
2832 fcport
->port_name
[6], fcport
->port_name
[7]);
2837 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2839 struct fc_rport_identifiers rport_ids
;
2840 struct fc_rport
*rport
;
2841 unsigned long flags
;
2843 qla2x00_rport_del(fcport
);
2845 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
2846 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
2847 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
2848 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
2849 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2850 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
2852 ql_log(ql_log_warn
, vha
, 0x2006,
2853 "Unable to allocate fc remote port.\n");
2856 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2857 *((fc_port_t
**)rport
->dd_data
) = fcport
;
2858 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2860 rport
->supported_classes
= fcport
->supported_classes
;
2862 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
2863 if (fcport
->port_type
== FCT_INITIATOR
)
2864 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
2865 if (fcport
->port_type
== FCT_TARGET
)
2866 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
2867 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
2871 * qla2x00_update_fcport
2872 * Updates device on list.
2875 * ha = adapter block pointer.
2876 * fcport = port structure pointer.
2886 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
2889 fcport
->login_retry
= 0;
2890 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
2892 qla2x00_iidma_fcport(vha
, fcport
);
2893 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
2894 qla2x00_reg_remote_port(vha
, fcport
);
2895 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
2899 * qla2x00_configure_fabric
2900 * Setup SNS devices with loop ID's.
2903 * ha = adapter block pointer.
2910 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
2914 uint16_t next_loopid
;
2915 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
2917 LIST_HEAD(new_fcports
);
2918 struct qla_hw_data
*ha
= vha
->hw
;
2919 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
2921 /* If FL port exists, then SNS is present */
2922 if (IS_FWI2_CAPABLE(ha
))
2923 loop_id
= NPH_F_PORT
;
2925 loop_id
= SNS_FL_PORT
;
2926 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
2927 if (rval
!= QLA_SUCCESS
) {
2928 ql_dbg(ql_dbg_disc
, vha
, 0x201f,
2929 "MBX_GET_PORT_NAME failed, No FL Port.\n");
2931 vha
->device_flags
&= ~SWITCH_FOUND
;
2932 return (QLA_SUCCESS
);
2934 vha
->device_flags
|= SWITCH_FOUND
;
2938 if (ql2xfdmienable
&&
2939 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
2940 qla2x00_fdmi_register(vha
);
2942 /* Ensure we are logged into the SNS. */
2943 if (IS_FWI2_CAPABLE(ha
))
2946 loop_id
= SIMPLE_NAME_SERVER
;
2947 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
2948 0xfc, mb
, BIT_1
|BIT_0
);
2949 if (rval
!= QLA_SUCCESS
) {
2950 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
2953 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
2954 ql_dbg(ql_dbg_disc
, vha
, 0x2042,
2955 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
2956 "mb[6]=%x mb[7]=%x.\n", loop_id
, mb
[0], mb
[1],
2957 mb
[2], mb
[6], mb
[7]);
2958 return (QLA_SUCCESS
);
2961 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
2962 if (qla2x00_rft_id(vha
)) {
2964 ql_dbg(ql_dbg_disc
, vha
, 0x2045,
2965 "Register FC-4 TYPE failed.\n");
2967 if (qla2x00_rff_id(vha
)) {
2969 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
2970 "Register FC-4 Features failed.\n");
2972 if (qla2x00_rnn_id(vha
)) {
2974 ql_dbg(ql_dbg_disc
, vha
, 0x204f,
2975 "Register Node Name failed.\n");
2976 } else if (qla2x00_rsnn_nn(vha
)) {
2978 ql_dbg(ql_dbg_disc
, vha
, 0x2053,
2979 "Register Symobilic Node Name failed.\n");
2983 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
2984 if (rval
!= QLA_SUCCESS
)
2987 /* Add new ports to existing port list */
2988 list_splice_tail_init(&new_fcports
, &vha
->vp_fcports
);
2990 /* Starting free loop ID. */
2991 next_loopid
= ha
->min_external_loopid
;
2993 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
2994 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
2997 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
3000 /* Logout lost/gone fabric devices (non-FCP2) */
3001 if (fcport
->scan_state
!= QLA_FCPORT_SCAN_FOUND
&&
3002 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3003 qla2x00_mark_device_lost(vha
, fcport
,
3004 ql2xplogiabsentdevice
, 0);
3005 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3006 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3007 fcport
->port_type
!= FCT_INITIATOR
&&
3008 fcport
->port_type
!= FCT_BROADCAST
) {
3009 ha
->isp_ops
->fabric_logout(vha
,
3011 fcport
->d_id
.b
.domain
,
3012 fcport
->d_id
.b
.area
,
3013 fcport
->d_id
.b
.al_pa
);
3017 fcport
->scan_state
= QLA_FCPORT_SCAN_NONE
;
3019 /* Login fabric devices that need a login */
3020 if ((fcport
->flags
& FCF_LOGIN_NEEDED
) != 0 &&
3021 atomic_read(&vha
->loop_down_timer
) == 0) {
3022 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3023 fcport
->loop_id
= next_loopid
;
3024 rval
= qla2x00_find_new_loop_id(
3026 if (rval
!= QLA_SUCCESS
) {
3027 /* Ran out of IDs to use */
3033 /* Login and update database */
3034 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3039 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
3040 "Configure fabric error exit rval=%d.\n", rval
);
3047 * qla2x00_find_all_fabric_devs
3050 * ha = adapter block pointer.
3051 * dev = database device entry pointer.
3060 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
3061 struct list_head
*new_fcports
)
3065 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
3070 int first_dev
, last_dev
;
3071 port_id_t wrap
= {}, nxt_d_id
;
3072 struct qla_hw_data
*ha
= vha
->hw
;
3073 struct scsi_qla_host
*vp
, *base_vha
= pci_get_drvdata(ha
->pdev
);
3074 struct scsi_qla_host
*tvp
;
3078 /* Try GID_PT to get device list, else GAN. */
3080 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
3085 ql_dbg(ql_dbg_disc
, vha
, 0x2054,
3086 "GID_PT allocations failed, fallback on GA_NXT.\n");
3088 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
3089 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
3091 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
3093 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
3095 } else if (ql2xiidmaenable
&&
3096 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
3097 qla2x00_gpsc(vha
, swl
);
3100 /* If other queries succeeded probe for FC-4 type */
3102 qla2x00_gff_id(vha
, swl
);
3106 /* Allocate temporary fcport for any new fcports discovered. */
3107 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3108 if (new_fcport
== NULL
) {
3109 ql_log(ql_log_warn
, vha
, 0x205e,
3110 "Failed to allocate memory for fcport.\n");
3111 return (QLA_MEMORY_ALLOC_FAILED
);
3113 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3114 /* Set start port ID scan at adapter ID. */
3118 /* Starting free loop ID. */
3119 loop_id
= ha
->min_external_loopid
;
3120 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
3121 if (qla2x00_is_reserved_id(vha
, loop_id
))
3124 if (ha
->current_topology
== ISP_CFG_FL
&&
3125 (atomic_read(&vha
->loop_down_timer
) ||
3126 LOOP_TRANSITION(vha
))) {
3127 atomic_set(&vha
->loop_down_timer
, 0);
3128 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3129 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3135 wrap
.b24
= new_fcport
->d_id
.b24
;
3137 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
3138 memcpy(new_fcport
->node_name
,
3139 swl
[swl_idx
].node_name
, WWN_SIZE
);
3140 memcpy(new_fcport
->port_name
,
3141 swl
[swl_idx
].port_name
, WWN_SIZE
);
3142 memcpy(new_fcport
->fabric_port_name
,
3143 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
3144 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
3145 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
3147 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
3153 /* Send GA_NXT to the switch */
3154 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
3155 if (rval
!= QLA_SUCCESS
) {
3156 ql_log(ql_log_warn
, vha
, 0x2064,
3157 "SNS scan failed -- assuming "
3158 "zero-entry result.\n");
3159 list_for_each_entry_safe(fcport
, fcptemp
,
3160 new_fcports
, list
) {
3161 list_del(&fcport
->list
);
3169 /* If wrap on switch device list, exit. */
3171 wrap
.b24
= new_fcport
->d_id
.b24
;
3173 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3174 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
3175 "Device wrap (%02x%02x%02x).\n",
3176 new_fcport
->d_id
.b
.domain
,
3177 new_fcport
->d_id
.b
.area
,
3178 new_fcport
->d_id
.b
.al_pa
);
3182 /* Bypass if same physical adapter. */
3183 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3186 /* Bypass virtual ports of the same host. */
3188 if (ha
->num_vhosts
) {
3189 unsigned long flags
;
3191 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3192 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3193 if (new_fcport
->d_id
.b24
== vp
->d_id
.b24
) {
3198 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3204 /* Bypass if same domain and area of adapter. */
3205 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3206 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3210 /* Bypass reserved domain fields. */
3211 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3214 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3215 if (ql2xgffidenable
&&
3216 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
3217 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
3220 /* Locate matching device in database. */
3222 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3223 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3227 fcport
->scan_state
= QLA_FCPORT_SCAN_FOUND
;
3231 /* Update port state. */
3232 memcpy(fcport
->fabric_port_name
,
3233 new_fcport
->fabric_port_name
, WWN_SIZE
);
3234 fcport
->fp_speed
= new_fcport
->fp_speed
;
3237 * If address the same and state FCS_ONLINE, nothing
3240 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3241 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3246 * If device was not a fabric device before.
3248 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3249 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3250 fcport
->loop_id
= FC_NO_LOOP_ID
;
3251 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3257 * Port ID changed or device was marked to be updated;
3258 * Log it out if still logged in and mark it for
3261 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3262 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3263 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3264 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3265 (fcport
->flags
& FCF_ASYNC_SENT
) == 0 &&
3266 fcport
->port_type
!= FCT_INITIATOR
&&
3267 fcport
->port_type
!= FCT_BROADCAST
) {
3268 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3269 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3270 fcport
->d_id
.b
.al_pa
);
3271 fcport
->loop_id
= FC_NO_LOOP_ID
;
3279 /* If device was not in our fcports list, then add it. */
3280 list_add_tail(&new_fcport
->list
, new_fcports
);
3282 /* Allocate a new replacement fcport. */
3283 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3284 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3285 if (new_fcport
== NULL
) {
3286 ql_log(ql_log_warn
, vha
, 0x2066,
3287 "Memory allocation failed for fcport.\n");
3288 return (QLA_MEMORY_ALLOC_FAILED
);
3290 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3291 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3300 * qla2x00_find_new_loop_id
3301 * Scan through our port list and find a new usable loop ID.
3304 * ha: adapter state pointer.
3305 * dev: port structure pointer.
3308 * qla2x00 local function return status code.
3314 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3319 uint16_t first_loop_id
;
3320 struct qla_hw_data
*ha
= vha
->hw
;
3321 struct scsi_qla_host
*vp
;
3322 struct scsi_qla_host
*tvp
;
3323 unsigned long flags
= 0;
3327 /* Save starting loop ID. */
3328 first_loop_id
= dev
->loop_id
;
3331 /* Skip loop ID if already used by adapter. */
3332 if (dev
->loop_id
== vha
->loop_id
)
3335 /* Skip reserved loop IDs. */
3336 while (qla2x00_is_reserved_id(vha
, dev
->loop_id
))
3339 /* Reset loop ID if passed the end. */
3340 if (dev
->loop_id
> ha
->max_loop_id
) {
3341 /* first loop ID. */
3342 dev
->loop_id
= ha
->min_external_loopid
;
3345 /* Check for loop ID being already in use. */
3349 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3350 list_for_each_entry_safe(vp
, tvp
, &ha
->vp_list
, list
) {
3351 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
) {
3352 if (fcport
->loop_id
== dev
->loop_id
&&
3354 /* ID possibly in use */
3362 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3364 /* If not in use then it is free to use. */
3366 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
3367 "Assigning new loopid=%x, portid=%x.\n",
3368 dev
->loop_id
, dev
->d_id
.b24
);
3372 /* ID in use. Try next value. */
3375 /* If wrap around. No free ID to use. */
3376 if (dev
->loop_id
== first_loop_id
) {
3377 dev
->loop_id
= FC_NO_LOOP_ID
;
3378 rval
= QLA_FUNCTION_FAILED
;
3387 * qla2x00_fabric_dev_login
3388 * Login fabric target device and update FC port database.
3391 * ha: adapter state pointer.
3392 * fcport: port structure list pointer.
3393 * next_loopid: contains value of a new loop ID that can be used
3394 * by the next login attempt.
3397 * qla2x00 local function return status code.
3403 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3404 uint16_t *next_loopid
)
3409 struct qla_hw_data
*ha
= vha
->hw
;
3414 if (IS_ALOGIO_CAPABLE(ha
)) {
3415 if (fcport
->flags
& FCF_ASYNC_SENT
)
3417 fcport
->flags
|= FCF_ASYNC_SENT
;
3418 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3423 fcport
->flags
&= ~FCF_ASYNC_SENT
;
3424 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3425 if (rval
== QLA_SUCCESS
) {
3426 /* Send an ADISC to FCP2 devices.*/
3428 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3430 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3431 if (rval
!= QLA_SUCCESS
) {
3432 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3433 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3434 fcport
->d_id
.b
.al_pa
);
3435 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3437 qla2x00_update_fcport(vha
, fcport
);
3441 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3448 * qla2x00_fabric_login
3449 * Issue fabric login command.
3452 * ha = adapter block pointer.
3453 * device = pointer to FC device type structure.
3456 * 0 - Login successfully
3458 * 2 - Initiator device
3462 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3463 uint16_t *next_loopid
)
3467 uint16_t tmp_loopid
;
3468 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3469 struct qla_hw_data
*ha
= vha
->hw
;
3475 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
3476 "Trying Fabric Login w/loop id 0x%04x for port "
3478 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3479 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
3481 /* Login fcport on switch. */
3482 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3483 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3484 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3485 if (rval
!= QLA_SUCCESS
) {
3488 if (mb
[0] == MBS_PORT_ID_USED
) {
3490 * Device has another loop ID. The firmware team
3491 * recommends the driver perform an implicit login with
3492 * the specified ID again. The ID we just used is save
3493 * here so we return with an ID that can be tried by
3497 tmp_loopid
= fcport
->loop_id
;
3498 fcport
->loop_id
= mb
[1];
3500 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
3501 "Fabric Login: port in use - next loop "
3502 "id=0x%04x, port id= %02x%02x%02x.\n",
3503 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3504 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
3506 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3511 /* A retry occurred before. */
3512 *next_loopid
= tmp_loopid
;
3515 * No retry occurred before. Just increment the
3516 * ID value for next login.
3518 *next_loopid
= (fcport
->loop_id
+ 1);
3521 if (mb
[1] & BIT_0
) {
3522 fcport
->port_type
= FCT_INITIATOR
;
3524 fcport
->port_type
= FCT_TARGET
;
3525 if (mb
[1] & BIT_1
) {
3526 fcport
->flags
|= FCF_FCP2_DEVICE
;
3531 fcport
->supported_classes
|= FC_COS_CLASS2
;
3533 fcport
->supported_classes
|= FC_COS_CLASS3
;
3537 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3539 * Loop ID already used, try next loop ID.
3542 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3543 if (rval
!= QLA_SUCCESS
) {
3544 /* Ran out of loop IDs to use */
3547 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3549 * Firmware possibly timed out during login. If NO
3550 * retries are left to do then the device is declared
3553 *next_loopid
= fcport
->loop_id
;
3554 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3555 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3556 fcport
->d_id
.b
.al_pa
);
3557 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3563 * unrecoverable / not handled error
3565 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
3566 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3567 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
3568 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
3569 fcport
->loop_id
, jiffies
);
3571 *next_loopid
= fcport
->loop_id
;
3572 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3573 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3574 fcport
->d_id
.b
.al_pa
);
3575 fcport
->loop_id
= FC_NO_LOOP_ID
;
3576 fcport
->login_retry
= 0;
3587 * qla2x00_local_device_login
3588 * Issue local device login command.
3591 * ha = adapter block pointer.
3592 * loop_id = loop id of device to login to.
3594 * Returns (Where's the #define!!!!):
3595 * 0 - Login successfully
3600 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3603 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3605 memset(mb
, 0, sizeof(mb
));
3606 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3607 if (rval
== QLA_SUCCESS
) {
3608 /* Interrogate mailbox registers for any errors */
3609 if (mb
[0] == MBS_COMMAND_ERROR
)
3611 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
3612 /* device not in PCB table */
3620 * qla2x00_loop_resync
3621 * Resync with fibre channel devices.
3624 * ha = adapter block pointer.
3630 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
3632 int rval
= QLA_SUCCESS
;
3634 struct req_que
*req
;
3635 struct rsp_que
*rsp
;
3637 if (vha
->hw
->flags
.cpu_affinity_enabled
)
3638 req
= vha
->hw
->req_q_map
[0];
3643 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3644 if (vha
->flags
.online
) {
3645 if (!(rval
= qla2x00_fw_ready(vha
))) {
3646 /* Wait at most MAX_TARGET RSCNs for a stable link. */
3649 /* Issue a marker after FW becomes ready. */
3650 qla2x00_marker(vha
, req
, rsp
, 0, 0,
3652 vha
->marker_needed
= 0;
3654 /* Remap devices on Loop. */
3655 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3657 qla2x00_configure_loop(vha
);
3659 } while (!atomic_read(&vha
->loop_down_timer
) &&
3660 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3661 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
3666 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
3667 return (QLA_FUNCTION_FAILED
);
3670 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
3671 "%s *** FAILED ***.\n", __func__
);
3677 * qla2x00_perform_loop_resync
3678 * Description: This function will set the appropriate flags and call
3679 * qla2x00_loop_resync. If successful loop will be resynced
3680 * Arguments : scsi_qla_host_t pointer
3681 * returm : Success or Failure
3684 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
3688 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
3689 /*Configure the flags so that resync happens properly*/
3690 atomic_set(&ha
->loop_down_timer
, 0);
3691 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
3692 atomic_set(&ha
->loop_state
, LOOP_UP
);
3693 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
3694 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
3695 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
3697 rval
= qla2x00_loop_resync(ha
);
3699 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
3701 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
3708 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
3711 struct scsi_qla_host
*vha
;
3712 struct qla_hw_data
*ha
= base_vha
->hw
;
3713 unsigned long flags
;
3715 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3716 /* Go with deferred removal of rport references. */
3717 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
3718 atomic_inc(&vha
->vref_count
);
3719 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3720 if (fcport
->drport
&&
3721 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
3722 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3724 qla2x00_rport_del(fcport
);
3726 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3729 atomic_dec(&vha
->vref_count
);
3731 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3735 * qla82xx_quiescent_state_cleanup
3736 * Description: This function will block the new I/Os
3737 * Its not aborting any I/Os as context
3738 * is not destroyed during quiescence
3739 * Arguments: scsi_qla_host_t
3743 qla82xx_quiescent_state_cleanup(scsi_qla_host_t
*vha
)
3745 struct qla_hw_data
*ha
= vha
->hw
;
3746 struct scsi_qla_host
*vp
;
3748 ql_dbg(ql_dbg_p3p
, vha
, 0xb002,
3749 "Performing ISP error recovery - ha=%p.\n", ha
);
3751 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
3752 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3753 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3754 qla2x00_mark_all_devices_lost(vha
, 0);
3755 list_for_each_entry(vp
, &ha
->vp_list
, list
)
3756 qla2x00_mark_all_devices_lost(vha
, 0);
3758 if (!atomic_read(&vha
->loop_down_timer
))
3759 atomic_set(&vha
->loop_down_timer
,
3762 /* Wait for pending cmds to complete */
3763 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
3767 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
3769 struct qla_hw_data
*ha
= vha
->hw
;
3770 struct scsi_qla_host
*vp
;
3771 unsigned long flags
;
3774 /* For ISP82XX, driver waits for completion of the commands.
3775 * online flag should be set.
3777 if (!IS_QLA82XX(ha
))
3778 vha
->flags
.online
= 0;
3779 ha
->flags
.chip_reset_done
= 0;
3780 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3781 vha
->qla_stats
.total_isp_aborts
++;
3783 ql_log(ql_log_info
, vha
, 0x00af,
3784 "Performing ISP error recovery - ha=%p.\n", ha
);
3786 /* For ISP82XX, reset_chip is just disabling interrupts.
3787 * Driver waits for the completion of the commands.
3788 * the interrupts need to be enabled.
3790 if (!IS_QLA82XX(ha
))
3791 ha
->isp_ops
->reset_chip(vha
);
3793 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
3794 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
3795 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
3796 qla2x00_mark_all_devices_lost(vha
, 0);
3798 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3799 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3800 atomic_inc(&vp
->vref_count
);
3801 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3803 qla2x00_mark_all_devices_lost(vp
, 0);
3805 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3806 atomic_dec(&vp
->vref_count
);
3808 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3810 if (!atomic_read(&vha
->loop_down_timer
))
3811 atomic_set(&vha
->loop_down_timer
,
3815 /* Clear all async request states across all VPs. */
3816 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
3817 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3818 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3819 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3820 atomic_inc(&vp
->vref_count
);
3821 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3823 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
3824 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3826 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3827 atomic_dec(&vp
->vref_count
);
3829 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3831 if (!ha
->flags
.eeh_busy
) {
3832 /* Make sure for ISP 82XX IO DMA is complete */
3833 if (IS_QLA82XX(ha
)) {
3834 qla82xx_chip_reset_cleanup(vha
);
3835 ql_log(ql_log_info
, vha
, 0x00b4,
3836 "Done chip reset cleanup.\n");
3838 /* Done waiting for pending commands.
3839 * Reset the online flag.
3841 vha
->flags
.online
= 0;
3844 /* Requeue all commands in outstanding command list. */
3845 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
3851 * Resets ISP and aborts all outstanding commands.
3854 * ha = adapter block pointer.
3860 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
3864 struct qla_hw_data
*ha
= vha
->hw
;
3865 struct scsi_qla_host
*vp
;
3866 struct req_que
*req
= ha
->req_q_map
[0];
3867 unsigned long flags
;
3869 if (vha
->flags
.online
) {
3870 qla2x00_abort_isp_cleanup(vha
);
3872 if (unlikely(pci_channel_offline(ha
->pdev
) &&
3873 ha
->flags
.pci_channel_io_perm_failure
)) {
3874 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3879 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
3881 ha
->isp_ops
->nvram_config(vha
);
3883 if (!qla2x00_restart_isp(vha
)) {
3884 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
3886 if (!atomic_read(&vha
->loop_down_timer
)) {
3888 * Issue marker command only when we are going
3889 * to start the I/O .
3891 vha
->marker_needed
= 1;
3894 vha
->flags
.online
= 1;
3896 ha
->isp_ops
->enable_intrs(ha
);
3898 ha
->isp_abort_cnt
= 0;
3899 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3901 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
3902 qla2x00_get_fw_version(vha
);
3904 ha
->flags
.fce_enabled
= 1;
3906 fce_calc_size(ha
->fce_bufs
));
3907 rval
= qla2x00_enable_fce_trace(vha
,
3908 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
3911 ql_log(ql_log_warn
, vha
, 0x8033,
3912 "Unable to reinitialize FCE "
3914 ha
->flags
.fce_enabled
= 0;
3919 memset(ha
->eft
, 0, EFT_SIZE
);
3920 rval
= qla2x00_enable_eft_trace(vha
,
3921 ha
->eft_dma
, EFT_NUM_BUFFERS
);
3923 ql_log(ql_log_warn
, vha
, 0x8034,
3924 "Unable to reinitialize EFT "
3928 } else { /* failed the ISP abort */
3929 vha
->flags
.online
= 1;
3930 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
3931 if (ha
->isp_abort_cnt
== 0) {
3932 ql_log(ql_log_fatal
, vha
, 0x8035,
3933 "ISP error recover failed - "
3934 "board disabled.\n");
3936 * The next call disables the board
3939 ha
->isp_ops
->reset_adapter(vha
);
3940 vha
->flags
.online
= 0;
3941 clear_bit(ISP_ABORT_RETRY
,
3944 } else { /* schedule another ISP abort */
3945 ha
->isp_abort_cnt
--;
3946 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
3947 "ISP abort - retry remaining %d.\n",
3952 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
3953 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
3954 "ISP error recovery - retrying (%d) "
3955 "more times.\n", ha
->isp_abort_cnt
);
3956 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
3964 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
3966 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3967 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
3969 atomic_inc(&vp
->vref_count
);
3970 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3972 qla2x00_vp_abort_isp(vp
);
3974 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3975 atomic_dec(&vp
->vref_count
);
3978 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3981 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
3989 * qla2x00_restart_isp
3990 * restarts the ISP after a reset
3993 * ha = adapter block pointer.
3999 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
4003 struct qla_hw_data
*ha
= vha
->hw
;
4004 struct req_que
*req
= ha
->req_q_map
[0];
4005 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4007 /* If firmware needs to be loaded */
4008 if (qla2x00_isp_firmware(vha
)) {
4009 vha
->flags
.online
= 0;
4010 status
= ha
->isp_ops
->chip_diag(vha
);
4012 status
= qla2x00_setup_chip(vha
);
4015 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
4016 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4017 ha
->flags
.chip_reset_done
= 1;
4018 /* Initialize the queues in use */
4019 qla25xx_init_queues(ha
);
4021 status
= qla2x00_fw_ready(vha
);
4023 ql_dbg(ql_dbg_taskm
, vha
, 0x8031,
4024 "Start configure loop status = %d.\n", status
);
4026 /* Issue a marker after FW becomes ready. */
4027 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4029 vha
->flags
.online
= 1;
4030 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4033 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4034 qla2x00_configure_loop(vha
);
4036 } while (!atomic_read(&vha
->loop_down_timer
) &&
4037 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4038 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4042 /* if no cable then assume it's good */
4043 if ((vha
->device_flags
& DFLG_NO_CABLE
))
4046 ql_dbg(ql_dbg_taskm
, vha
, 0x8032,
4047 "Configure loop done, status = 0x%x.\n", status
);
4053 qla25xx_init_queues(struct qla_hw_data
*ha
)
4055 struct rsp_que
*rsp
= NULL
;
4056 struct req_que
*req
= NULL
;
4057 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4061 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
4062 rsp
= ha
->rsp_q_map
[i
];
4064 rsp
->options
&= ~BIT_0
;
4065 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
4066 if (ret
!= QLA_SUCCESS
)
4067 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
4068 "%s Rsp que: %d init failed.\n",
4071 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
4072 "%s Rsp que: %d inited.\n",
4076 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
4077 req
= ha
->req_q_map
[i
];
4079 /* Clear outstanding commands array. */
4080 req
->options
&= ~BIT_0
;
4081 ret
= qla25xx_init_req_que(base_vha
, req
);
4082 if (ret
!= QLA_SUCCESS
)
4083 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
4084 "%s Req que: %d init failed.\n",
4087 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
4088 "%s Req que: %d inited.\n",
4096 * qla2x00_reset_adapter
4100 * ha = adapter block pointer.
4103 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
4105 unsigned long flags
= 0;
4106 struct qla_hw_data
*ha
= vha
->hw
;
4107 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4109 vha
->flags
.online
= 0;
4110 ha
->isp_ops
->disable_intrs(ha
);
4112 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4113 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
4114 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4115 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
4116 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4117 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4121 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
4123 unsigned long flags
= 0;
4124 struct qla_hw_data
*ha
= vha
->hw
;
4125 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4130 vha
->flags
.online
= 0;
4131 ha
->isp_ops
->disable_intrs(ha
);
4133 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4134 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
4135 RD_REG_DWORD(®
->hccr
);
4136 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
4137 RD_REG_DWORD(®
->hccr
);
4138 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4140 if (IS_NOPOLLING_TYPE(ha
))
4141 ha
->isp_ops
->enable_intrs(ha
);
4144 /* On sparc systems, obtain port and node WWN from firmware
4147 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
4148 struct nvram_24xx
*nv
)
4151 struct qla_hw_data
*ha
= vha
->hw
;
4152 struct pci_dev
*pdev
= ha
->pdev
;
4153 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4157 val
= of_get_property(dp
, "port-wwn", &len
);
4158 if (val
&& len
>= WWN_SIZE
)
4159 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4161 val
= of_get_property(dp
, "node-wwn", &len
);
4162 if (val
&& len
>= WWN_SIZE
)
4163 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4168 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
4171 struct init_cb_24xx
*icb
;
4172 struct nvram_24xx
*nv
;
4174 uint8_t *dptr1
, *dptr2
;
4177 struct qla_hw_data
*ha
= vha
->hw
;
4180 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4183 /* Determine NVRAM starting address. */
4184 if (ha
->flags
.port0
) {
4185 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
4186 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
4188 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
4189 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
4191 ha
->nvram_size
= sizeof(struct nvram_24xx
);
4192 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4194 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
4196 /* Get VPD data into cache */
4197 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4198 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
4199 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
4201 /* Get NVRAM data into cache and calculate checksum. */
4202 dptr
= (uint32_t *)nv
;
4203 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
4205 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4206 chksum
+= le32_to_cpu(*dptr
++);
4208 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
4209 "Contents of NVRAM\n");
4210 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
4211 (uint8_t *)nv
, ha
->nvram_size
);
4213 /* Bad NVRAM data, set defaults parameters. */
4214 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4215 || nv
->id
[3] != ' ' ||
4216 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4217 /* Reset NVRAM data. */
4218 ql_log(ql_log_warn
, vha
, 0x006b,
4219 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
4220 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
4221 ql_log(ql_log_warn
, vha
, 0x006c,
4222 "Falling back to functioning (yet invalid -- WWPN) "
4226 * Set default initialization control block.
4228 memset(nv
, 0, ha
->nvram_size
);
4229 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4230 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4231 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4232 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4233 nv
->exchange_count
= __constant_cpu_to_le16(0);
4234 nv
->hard_address
= __constant_cpu_to_le16(124);
4235 nv
->port_name
[0] = 0x21;
4236 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4237 nv
->port_name
[2] = 0x00;
4238 nv
->port_name
[3] = 0xe0;
4239 nv
->port_name
[4] = 0x8b;
4240 nv
->port_name
[5] = 0x1c;
4241 nv
->port_name
[6] = 0x55;
4242 nv
->port_name
[7] = 0x86;
4243 nv
->node_name
[0] = 0x20;
4244 nv
->node_name
[1] = 0x00;
4245 nv
->node_name
[2] = 0x00;
4246 nv
->node_name
[3] = 0xe0;
4247 nv
->node_name
[4] = 0x8b;
4248 nv
->node_name
[5] = 0x1c;
4249 nv
->node_name
[6] = 0x55;
4250 nv
->node_name
[7] = 0x86;
4251 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4252 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4253 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4254 nv
->login_timeout
= __constant_cpu_to_le16(0);
4255 nv
->firmware_options_1
=
4256 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4257 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4258 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4259 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4260 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4261 nv
->efi_parameters
= __constant_cpu_to_le32(0);
4262 nv
->reset_delay
= 5;
4263 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
4264 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
4265 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
4270 /* Reset Initialization control block */
4271 memset(icb
, 0, ha
->init_cb_size
);
4273 /* Copy 1st segment. */
4274 dptr1
= (uint8_t *)icb
;
4275 dptr2
= (uint8_t *)&nv
->version
;
4276 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
4278 *dptr1
++ = *dptr2
++;
4280 icb
->login_retry_count
= nv
->login_retry_count
;
4281 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
4283 /* Copy 2nd segment. */
4284 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
4285 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
4286 cnt
= (uint8_t *)&icb
->reserved_3
-
4287 (uint8_t *)&icb
->interrupt_delay_timer
;
4289 *dptr1
++ = *dptr2
++;
4292 * Setup driver NVRAM options.
4294 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
4297 /* Use alternate WWN? */
4298 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
4299 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4300 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4303 /* Prepare nodename */
4304 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
4306 * Firmware will apply the following mask if the nodename was
4309 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4310 icb
->node_name
[0] &= 0xF0;
4313 /* Set host adapter parameters. */
4314 ha
->flags
.disable_risc_code_load
= 0;
4315 ha
->flags
.enable_lip_reset
= 0;
4316 ha
->flags
.enable_lip_full_login
=
4317 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
4318 ha
->flags
.enable_target_reset
=
4319 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
4320 ha
->flags
.enable_led_scheme
= 0;
4321 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
4323 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
4324 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4326 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
4327 sizeof(ha
->fw_seriallink_options24
));
4329 /* save HBA serial number */
4330 ha
->serial0
= icb
->port_name
[5];
4331 ha
->serial1
= icb
->port_name
[6];
4332 ha
->serial2
= icb
->port_name
[7];
4333 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4334 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4336 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4338 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
4340 /* Set minimum login_timeout to 4 seconds. */
4341 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
4342 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
4343 if (le16_to_cpu(nv
->login_timeout
) < 4)
4344 nv
->login_timeout
= __constant_cpu_to_le16(4);
4345 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
4346 icb
->login_timeout
= nv
->login_timeout
;
4348 /* Set minimum RATOV to 100 tenths of a second. */
4351 ha
->loop_reset_delay
= nv
->reset_delay
;
4353 /* Link Down Timeout = 0:
4355 * When Port Down timer expires we will start returning
4356 * I/O's to OS with "DID_NO_CONNECT".
4358 * Link Down Timeout != 0:
4360 * The driver waits for the link to come up after link down
4361 * before returning I/Os to OS with "DID_NO_CONNECT".
4363 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
4364 ha
->loop_down_abort_time
=
4365 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4367 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
4368 ha
->loop_down_abort_time
=
4369 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4372 /* Need enough time to try and get the port back. */
4373 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
4374 if (qlport_down_retry
)
4375 ha
->port_down_retry_count
= qlport_down_retry
;
4377 /* Set login_retry_count */
4378 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
4379 if (ha
->port_down_retry_count
==
4380 le16_to_cpu(nv
->port_down_retry_count
) &&
4381 ha
->port_down_retry_count
> 3)
4382 ha
->login_retry_count
= ha
->port_down_retry_count
;
4383 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4384 ha
->login_retry_count
= ha
->port_down_retry_count
;
4385 if (ql2xloginretrycount
)
4386 ha
->login_retry_count
= ql2xloginretrycount
;
4389 if (!vha
->flags
.init_done
) {
4390 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
4391 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4392 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
4393 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
4395 icb
->firmware_options_2
&= __constant_cpu_to_le32(
4396 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
4397 vha
->flags
.process_response_queue
= 0;
4398 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4399 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4401 ql_log(ql_log_info
, vha
, 0x006f,
4402 "ZIO mode %d enabled; timer delay (%d us).\n",
4403 ha
->zio_mode
, ha
->zio_timer
* 100);
4405 icb
->firmware_options_2
|= cpu_to_le32(
4406 (uint32_t)ha
->zio_mode
);
4407 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
4408 vha
->flags
.process_response_queue
= 1;
4412 ql_log(ql_log_warn
, vha
, 0x0070,
4413 "NVRAM configuration failed.\n");
4419 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
4422 int rval
= QLA_SUCCESS
;
4423 int segments
, fragment
;
4424 uint32_t *dcode
, dlen
;
4428 struct qla_hw_data
*ha
= vha
->hw
;
4429 struct req_que
*req
= ha
->req_q_map
[0];
4431 ql_dbg(ql_dbg_init
, vha
, 0x008b,
4432 "FW: Loading firmware from flash (%x).\n", faddr
);
4436 segments
= FA_RISC_CODE_SEGMENTS
;
4437 dcode
= (uint32_t *)req
->ring
;
4440 /* Validate firmware image by checking version. */
4441 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
4442 for (i
= 0; i
< 4; i
++)
4443 dcode
[i
] = be32_to_cpu(dcode
[i
]);
4444 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4445 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4446 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4448 ql_log(ql_log_fatal
, vha
, 0x008c,
4449 "Unable to verify the integrity of flash firmware "
4451 ql_log(ql_log_fatal
, vha
, 0x008d,
4452 "Firmware data: %08x %08x %08x %08x.\n",
4453 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
4455 return QLA_FUNCTION_FAILED
;
4458 while (segments
&& rval
== QLA_SUCCESS
) {
4459 /* Read segment's load information. */
4460 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
4462 risc_addr
= be32_to_cpu(dcode
[2]);
4463 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4464 risc_size
= be32_to_cpu(dcode
[3]);
4467 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4468 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4469 if (dlen
> risc_size
)
4472 ql_dbg(ql_dbg_init
, vha
, 0x008e,
4473 "Loading risc segment@ risc addr %x "
4474 "number of dwords 0x%x offset 0x%x.\n",
4475 risc_addr
, dlen
, faddr
);
4477 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
4478 for (i
= 0; i
< dlen
; i
++)
4479 dcode
[i
] = swab32(dcode
[i
]);
4481 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4484 ql_log(ql_log_fatal
, vha
, 0x008f,
4485 "Failed to load segment %d of firmware.\n",
4503 #define QLA_FW_URL "ftp://ftp.qlogic.com/outgoing/linux/firmware/"
4506 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4510 uint16_t *wcode
, *fwcode
;
4511 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
4512 struct fw_blob
*blob
;
4513 struct qla_hw_data
*ha
= vha
->hw
;
4514 struct req_que
*req
= ha
->req_q_map
[0];
4516 /* Load firmware blob. */
4517 blob
= qla2x00_request_firmware(vha
);
4519 ql_log(ql_log_info
, vha
, 0x0083,
4520 "Fimware image unavailable.\n");
4521 ql_log(ql_log_info
, vha
, 0x0084,
4522 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
4523 return QLA_FUNCTION_FAILED
;
4528 wcode
= (uint16_t *)req
->ring
;
4530 fwcode
= (uint16_t *)blob
->fw
->data
;
4533 /* Validate firmware image by checking version. */
4534 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
4535 ql_log(ql_log_fatal
, vha
, 0x0085,
4536 "Unable to verify integrity of firmware image (%Zd).\n",
4538 goto fail_fw_integrity
;
4540 for (i
= 0; i
< 4; i
++)
4541 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
4542 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
4543 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
4544 wcode
[2] == 0 && wcode
[3] == 0)) {
4545 ql_log(ql_log_fatal
, vha
, 0x0086,
4546 "Unable to verify integrity of firmware image.\n");
4547 ql_log(ql_log_fatal
, vha
, 0x0087,
4548 "Firmware data: %04x %04x %04x %04x.\n",
4549 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
4550 goto fail_fw_integrity
;
4554 while (*seg
&& rval
== QLA_SUCCESS
) {
4556 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
4557 risc_size
= be16_to_cpu(fwcode
[3]);
4559 /* Validate firmware image size. */
4560 fwclen
+= risc_size
* sizeof(uint16_t);
4561 if (blob
->fw
->size
< fwclen
) {
4562 ql_log(ql_log_fatal
, vha
, 0x0088,
4563 "Unable to verify integrity of firmware image "
4564 "(%Zd).\n", blob
->fw
->size
);
4565 goto fail_fw_integrity
;
4569 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4570 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
4571 if (wlen
> risc_size
)
4573 ql_dbg(ql_dbg_init
, vha
, 0x0089,
4574 "Loading risc segment@ risc addr %x number of "
4575 "words 0x%x.\n", risc_addr
, wlen
);
4577 for (i
= 0; i
< wlen
; i
++)
4578 wcode
[i
] = swab16(fwcode
[i
]);
4580 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4583 ql_log(ql_log_fatal
, vha
, 0x008a,
4584 "Failed to load segment %d of firmware.\n",
4601 return QLA_FUNCTION_FAILED
;
4605 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4608 int segments
, fragment
;
4609 uint32_t *dcode
, dlen
;
4613 struct fw_blob
*blob
;
4614 uint32_t *fwcode
, fwclen
;
4615 struct qla_hw_data
*ha
= vha
->hw
;
4616 struct req_que
*req
= ha
->req_q_map
[0];
4618 /* Load firmware blob. */
4619 blob
= qla2x00_request_firmware(vha
);
4621 ql_log(ql_log_warn
, vha
, 0x0090,
4622 "Fimware image unavailable.\n");
4623 ql_log(ql_log_warn
, vha
, 0x0091,
4624 "Firmware images can be retrieved from: "
4627 return QLA_FUNCTION_FAILED
;
4630 ql_dbg(ql_dbg_init
, vha
, 0x0092,
4631 "FW: Loading via request-firmware.\n");
4635 segments
= FA_RISC_CODE_SEGMENTS
;
4636 dcode
= (uint32_t *)req
->ring
;
4638 fwcode
= (uint32_t *)blob
->fw
->data
;
4641 /* Validate firmware image by checking version. */
4642 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
4643 ql_log(ql_log_fatal
, vha
, 0x0093,
4644 "Unable to verify integrity of firmware image (%Zd).\n",
4646 goto fail_fw_integrity
;
4648 for (i
= 0; i
< 4; i
++)
4649 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
4650 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
4651 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
4652 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
4654 ql_log(ql_log_fatal
, vha
, 0x0094,
4655 "Unable to verify integrity of firmware image (%Zd).\n",
4657 ql_log(ql_log_fatal
, vha
, 0x0095,
4658 "Firmware data: %08x %08x %08x %08x.\n",
4659 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
4660 goto fail_fw_integrity
;
4663 while (segments
&& rval
== QLA_SUCCESS
) {
4664 risc_addr
= be32_to_cpu(fwcode
[2]);
4665 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
4666 risc_size
= be32_to_cpu(fwcode
[3]);
4668 /* Validate firmware image size. */
4669 fwclen
+= risc_size
* sizeof(uint32_t);
4670 if (blob
->fw
->size
< fwclen
) {
4671 ql_log(ql_log_fatal
, vha
, 0x0096,
4672 "Unable to verify integrity of firmware image "
4673 "(%Zd).\n", blob
->fw
->size
);
4675 goto fail_fw_integrity
;
4679 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
4680 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
4681 if (dlen
> risc_size
)
4684 ql_dbg(ql_dbg_init
, vha
, 0x0097,
4685 "Loading risc segment@ risc addr %x "
4686 "number of dwords 0x%x.\n", risc_addr
, dlen
);
4688 for (i
= 0; i
< dlen
; i
++)
4689 dcode
[i
] = swab32(fwcode
[i
]);
4691 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
4694 ql_log(ql_log_fatal
, vha
, 0x0098,
4695 "Failed to load segment %d of firmware.\n",
4712 return QLA_FUNCTION_FAILED
;
4716 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4720 if (ql2xfwloadbin
== 1)
4721 return qla81xx_load_risc(vha
, srisc_addr
);
4725 * 1) Firmware via request-firmware interface (.bin file).
4726 * 2) Firmware residing in flash.
4728 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4729 if (rval
== QLA_SUCCESS
)
4732 return qla24xx_load_risc_flash(vha
, srisc_addr
,
4733 vha
->hw
->flt_region_fw
);
4737 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
4740 struct qla_hw_data
*ha
= vha
->hw
;
4742 if (ql2xfwloadbin
== 2)
4747 * 1) Firmware residing in flash.
4748 * 2) Firmware via request-firmware interface (.bin file).
4749 * 3) Golden-Firmware residing in flash -- limited operation.
4751 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
4752 if (rval
== QLA_SUCCESS
)
4756 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
4757 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
4760 ql_log(ql_log_info
, vha
, 0x0099,
4761 "Attempting to fallback to golden firmware.\n");
4762 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
4763 if (rval
!= QLA_SUCCESS
)
4766 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
4767 ha
->flags
.running_gold_fw
= 1;
4772 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
4775 struct qla_hw_data
*ha
= vha
->hw
;
4777 if (ha
->flags
.pci_channel_io_perm_failure
)
4779 if (!IS_FWI2_CAPABLE(ha
))
4781 if (!ha
->fw_major_version
)
4784 ret
= qla2x00_stop_firmware(vha
);
4785 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
4786 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
4787 ha
->isp_ops
->reset_chip(vha
);
4788 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
4790 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
4792 ql_log(ql_log_info
, vha
, 0x8015,
4793 "Attempting retry of stop-firmware command.\n");
4794 ret
= qla2x00_stop_firmware(vha
);
4799 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
4801 int rval
= QLA_SUCCESS
;
4803 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4804 struct qla_hw_data
*ha
= vha
->hw
;
4805 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4806 struct req_que
*req
;
4807 struct rsp_que
*rsp
;
4812 rval
= qla2x00_fw_ready(base_vha
);
4813 if (ha
->flags
.cpu_affinity_enabled
)
4814 req
= ha
->req_q_map
[0];
4819 if (rval
== QLA_SUCCESS
) {
4820 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4821 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4824 vha
->flags
.management_server_logged_in
= 0;
4826 /* Login to SNS first */
4827 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
4829 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
4830 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
4831 ql_dbg(ql_dbg_init
, vha
, 0x0120,
4832 "Failed SNS login: loop_id=%x, rval2=%d\n",
4835 ql_dbg(ql_dbg_init
, vha
, 0x0103,
4836 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
4837 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
4838 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
4839 return (QLA_FUNCTION_FAILED
);
4842 atomic_set(&vha
->loop_down_timer
, 0);
4843 atomic_set(&vha
->loop_state
, LOOP_UP
);
4844 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4845 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4846 rval
= qla2x00_loop_resync(base_vha
);
4851 /* 84XX Support **************************************************************/
4853 static LIST_HEAD(qla_cs84xx_list
);
4854 static DEFINE_MUTEX(qla_cs84xx_mutex
);
4856 static struct qla_chip_state_84xx
*
4857 qla84xx_get_chip(struct scsi_qla_host
*vha
)
4859 struct qla_chip_state_84xx
*cs84xx
;
4860 struct qla_hw_data
*ha
= vha
->hw
;
4862 mutex_lock(&qla_cs84xx_mutex
);
4864 /* Find any shared 84xx chip. */
4865 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
4866 if (cs84xx
->bus
== ha
->pdev
->bus
) {
4867 kref_get(&cs84xx
->kref
);
4872 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
4876 kref_init(&cs84xx
->kref
);
4877 spin_lock_init(&cs84xx
->access_lock
);
4878 mutex_init(&cs84xx
->fw_update_mutex
);
4879 cs84xx
->bus
= ha
->pdev
->bus
;
4881 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
4883 mutex_unlock(&qla_cs84xx_mutex
);
4888 __qla84xx_chip_release(struct kref
*kref
)
4890 struct qla_chip_state_84xx
*cs84xx
=
4891 container_of(kref
, struct qla_chip_state_84xx
, kref
);
4893 mutex_lock(&qla_cs84xx_mutex
);
4894 list_del(&cs84xx
->list
);
4895 mutex_unlock(&qla_cs84xx_mutex
);
4900 qla84xx_put_chip(struct scsi_qla_host
*vha
)
4902 struct qla_hw_data
*ha
= vha
->hw
;
4904 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
4908 qla84xx_init_chip(scsi_qla_host_t
*vha
)
4912 struct qla_hw_data
*ha
= vha
->hw
;
4914 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
4916 rval
= qla84xx_verify_chip(vha
, status
);
4918 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
4920 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
4924 /* 81XX Support **************************************************************/
4927 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
4930 struct init_cb_81xx
*icb
;
4931 struct nvram_81xx
*nv
;
4933 uint8_t *dptr1
, *dptr2
;
4936 struct qla_hw_data
*ha
= vha
->hw
;
4939 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
4942 /* Determine NVRAM starting address. */
4943 ha
->nvram_size
= sizeof(struct nvram_81xx
);
4944 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4946 /* Get VPD data into cache */
4947 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4948 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
4951 /* Get NVRAM data into cache and calculate checksum. */
4952 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
4954 dptr
= (uint32_t *)nv
;
4955 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4956 chksum
+= le32_to_cpu(*dptr
++);
4958 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
4959 "Contents of NVRAM:\n");
4960 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
4961 (uint8_t *)nv
, ha
->nvram_size
);
4963 /* Bad NVRAM data, set defaults parameters. */
4964 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4965 || nv
->id
[3] != ' ' ||
4966 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4967 /* Reset NVRAM data. */
4968 ql_log(ql_log_info
, vha
, 0x0073,
4969 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
4970 "version=0x%x.\n", chksum
, nv
->id
[0],
4971 le16_to_cpu(nv
->nvram_version
));
4972 ql_log(ql_log_info
, vha
, 0x0074,
4973 "Falling back to functioning (yet invalid -- WWPN) "
4977 * Set default initialization control block.
4979 memset(nv
, 0, ha
->nvram_size
);
4980 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4981 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4982 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4983 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4984 nv
->exchange_count
= __constant_cpu_to_le16(0);
4985 nv
->port_name
[0] = 0x21;
4986 nv
->port_name
[1] = 0x00 + ha
->port_no
;
4987 nv
->port_name
[2] = 0x00;
4988 nv
->port_name
[3] = 0xe0;
4989 nv
->port_name
[4] = 0x8b;
4990 nv
->port_name
[5] = 0x1c;
4991 nv
->port_name
[6] = 0x55;
4992 nv
->port_name
[7] = 0x86;
4993 nv
->node_name
[0] = 0x20;
4994 nv
->node_name
[1] = 0x00;
4995 nv
->node_name
[2] = 0x00;
4996 nv
->node_name
[3] = 0xe0;
4997 nv
->node_name
[4] = 0x8b;
4998 nv
->node_name
[5] = 0x1c;
4999 nv
->node_name
[6] = 0x55;
5000 nv
->node_name
[7] = 0x86;
5001 nv
->login_retry_count
= __constant_cpu_to_le16(8);
5002 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
5003 nv
->login_timeout
= __constant_cpu_to_le16(0);
5004 nv
->firmware_options_1
=
5005 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
5006 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
5007 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
5008 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
5009 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
5010 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5011 nv
->reset_delay
= 5;
5012 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5013 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5014 nv
->link_down_timeout
= __constant_cpu_to_le16(180);
5015 nv
->enode_mac
[0] = 0x00;
5016 nv
->enode_mac
[1] = 0xC0;
5017 nv
->enode_mac
[2] = 0xDD;
5018 nv
->enode_mac
[3] = 0x04;
5019 nv
->enode_mac
[4] = 0x05;
5020 nv
->enode_mac
[5] = 0x06 + ha
->port_no
;
5025 /* Reset Initialization control block */
5026 memset(icb
, 0, ha
->init_cb_size
);
5028 /* Copy 1st segment. */
5029 dptr1
= (uint8_t *)icb
;
5030 dptr2
= (uint8_t *)&nv
->version
;
5031 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5033 *dptr1
++ = *dptr2
++;
5035 icb
->login_retry_count
= nv
->login_retry_count
;
5037 /* Copy 2nd segment. */
5038 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5039 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5040 cnt
= (uint8_t *)&icb
->reserved_5
-
5041 (uint8_t *)&icb
->interrupt_delay_timer
;
5043 *dptr1
++ = *dptr2
++;
5045 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
5046 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5047 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
5048 icb
->enode_mac
[0] = 0x00;
5049 icb
->enode_mac
[1] = 0xC0;
5050 icb
->enode_mac
[2] = 0xDD;
5051 icb
->enode_mac
[3] = 0x04;
5052 icb
->enode_mac
[4] = 0x05;
5053 icb
->enode_mac
[5] = 0x06 + ha
->port_no
;
5056 /* Use extended-initialization control block. */
5057 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
5060 * Setup driver NVRAM options.
5062 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
5065 /* Use alternate WWN? */
5066 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
5067 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
5068 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
5071 /* Prepare nodename */
5072 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
5074 * Firmware will apply the following mask if the nodename was
5077 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
5078 icb
->node_name
[0] &= 0xF0;
5081 /* Set host adapter parameters. */
5082 ha
->flags
.disable_risc_code_load
= 0;
5083 ha
->flags
.enable_lip_reset
= 0;
5084 ha
->flags
.enable_lip_full_login
=
5085 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
5086 ha
->flags
.enable_target_reset
=
5087 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
5088 ha
->flags
.enable_led_scheme
= 0;
5089 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
5091 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
5092 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
5094 /* save HBA serial number */
5095 ha
->serial0
= icb
->port_name
[5];
5096 ha
->serial1
= icb
->port_name
[6];
5097 ha
->serial2
= icb
->port_name
[7];
5098 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
5099 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
5101 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5103 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
5105 /* Set minimum login_timeout to 4 seconds. */
5106 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
5107 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
5108 if (le16_to_cpu(nv
->login_timeout
) < 4)
5109 nv
->login_timeout
= __constant_cpu_to_le16(4);
5110 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
5111 icb
->login_timeout
= nv
->login_timeout
;
5113 /* Set minimum RATOV to 100 tenths of a second. */
5116 ha
->loop_reset_delay
= nv
->reset_delay
;
5118 /* Link Down Timeout = 0:
5120 * When Port Down timer expires we will start returning
5121 * I/O's to OS with "DID_NO_CONNECT".
5123 * Link Down Timeout != 0:
5125 * The driver waits for the link to come up after link down
5126 * before returning I/Os to OS with "DID_NO_CONNECT".
5128 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
5129 ha
->loop_down_abort_time
=
5130 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
5132 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
5133 ha
->loop_down_abort_time
=
5134 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
5137 /* Need enough time to try and get the port back. */
5138 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
5139 if (qlport_down_retry
)
5140 ha
->port_down_retry_count
= qlport_down_retry
;
5142 /* Set login_retry_count */
5143 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
5144 if (ha
->port_down_retry_count
==
5145 le16_to_cpu(nv
->port_down_retry_count
) &&
5146 ha
->port_down_retry_count
> 3)
5147 ha
->login_retry_count
= ha
->port_down_retry_count
;
5148 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
5149 ha
->login_retry_count
= ha
->port_down_retry_count
;
5150 if (ql2xloginretrycount
)
5151 ha
->login_retry_count
= ql2xloginretrycount
;
5153 /* if not running MSI-X we need handshaking on interrupts */
5154 if (!vha
->hw
->flags
.msix_enabled
&& IS_QLA83XX(ha
))
5155 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_22
);
5158 if (!vha
->flags
.init_done
) {
5159 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
5160 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
5161 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
5162 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
5164 icb
->firmware_options_2
&= __constant_cpu_to_le32(
5165 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
5166 vha
->flags
.process_response_queue
= 0;
5167 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
5168 ha
->zio_mode
= QLA_ZIO_MODE_6
;
5170 ql_log(ql_log_info
, vha
, 0x0075,
5171 "ZIO mode %d enabled; timer delay (%d us).\n",
5173 ha
->zio_timer
* 100);
5175 icb
->firmware_options_2
|= cpu_to_le32(
5176 (uint32_t)ha
->zio_mode
);
5177 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
5178 vha
->flags
.process_response_queue
= 1;
5182 ql_log(ql_log_warn
, vha
, 0x0076,
5183 "NVRAM configuration failed.\n");
5189 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
5193 struct qla_hw_data
*ha
= vha
->hw
;
5194 struct req_que
*req
= ha
->req_q_map
[0];
5195 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
5196 struct scsi_qla_host
*vp
;
5197 unsigned long flags
;
5199 status
= qla2x00_init_rings(vha
);
5201 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5202 ha
->flags
.chip_reset_done
= 1;
5204 status
= qla2x00_fw_ready(vha
);
5206 ql_log(ql_log_info
, vha
, 0x803c,
5207 "Start configure loop, status =%d.\n", status
);
5209 /* Issue a marker after FW becomes ready. */
5210 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5212 vha
->flags
.online
= 1;
5213 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5216 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5217 qla2x00_configure_loop(vha
);
5219 } while (!atomic_read(&vha
->loop_down_timer
) &&
5220 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
5222 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
5225 /* if no cable then assume it's good */
5226 if ((vha
->device_flags
& DFLG_NO_CABLE
))
5229 ql_log(ql_log_info
, vha
, 0x8000,
5230 "Configure loop done, status = 0x%x.\n", status
);
5234 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5236 if (!atomic_read(&vha
->loop_down_timer
)) {
5238 * Issue marker command only when we are going
5239 * to start the I/O .
5241 vha
->marker_needed
= 1;
5244 vha
->flags
.online
= 1;
5246 ha
->isp_ops
->enable_intrs(ha
);
5248 ha
->isp_abort_cnt
= 0;
5249 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5251 /* Update the firmware version */
5252 status
= qla82xx_check_md_needed(vha
);
5255 ha
->flags
.fce_enabled
= 1;
5257 fce_calc_size(ha
->fce_bufs
));
5258 rval
= qla2x00_enable_fce_trace(vha
,
5259 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
5262 ql_log(ql_log_warn
, vha
, 0x8001,
5263 "Unable to reinitialize FCE (%d).\n",
5265 ha
->flags
.fce_enabled
= 0;
5270 memset(ha
->eft
, 0, EFT_SIZE
);
5271 rval
= qla2x00_enable_eft_trace(vha
,
5272 ha
->eft_dma
, EFT_NUM_BUFFERS
);
5274 ql_log(ql_log_warn
, vha
, 0x8010,
5275 "Unable to reinitialize EFT (%d).\n",
5282 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
5283 "qla82xx_restart_isp succeeded.\n");
5285 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5286 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
5288 atomic_inc(&vp
->vref_count
);
5289 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5291 qla2x00_vp_abort_isp(vp
);
5293 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5294 atomic_dec(&vp
->vref_count
);
5297 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5300 ql_log(ql_log_warn
, vha
, 0x8016,
5301 "qla82xx_restart_isp **** FAILED ****.\n");
5308 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
5310 struct qla_hw_data
*ha
= vha
->hw
;
5315 /* Enable ETS Burst. */
5316 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
5317 ha
->fw_options
[2] |= BIT_9
;
5318 qla2x00_set_fw_options(vha
, ha
->fw_options
);
5322 * qla24xx_get_fcp_prio
5323 * Gets the fcp cmd priority value for the logged in port.
5324 * Looks for a match of the port descriptors within
5325 * each of the fcp prio config entries. If a match is found,
5326 * the tag (priority) value is returned.
5329 * vha = scsi host structure pointer.
5330 * fcport = port structure pointer.
5333 * non-zero (if found)
5340 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5343 uint8_t pid_match
, wwn_match
;
5345 uint32_t pid1
, pid2
;
5346 uint64_t wwn1
, wwn2
;
5347 struct qla_fcp_prio_entry
*pri_entry
;
5348 struct qla_hw_data
*ha
= vha
->hw
;
5350 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
5354 entries
= ha
->fcp_prio_cfg
->num_entries
;
5355 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
5357 for (i
= 0; i
< entries
; i
++) {
5358 pid_match
= wwn_match
= 0;
5360 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
5365 /* check source pid for a match */
5366 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
5367 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
5368 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
5369 if (pid1
== INVALID_PORT_ID
)
5371 else if (pid1
== pid2
)
5375 /* check destination pid for a match */
5376 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
5377 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
5378 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
5379 if (pid1
== INVALID_PORT_ID
)
5381 else if (pid1
== pid2
)
5385 /* check source WWN for a match */
5386 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
5387 wwn1
= wwn_to_u64(vha
->port_name
);
5388 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
5389 if (wwn2
== (uint64_t)-1)
5391 else if (wwn1
== wwn2
)
5395 /* check destination WWN for a match */
5396 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
5397 wwn1
= wwn_to_u64(fcport
->port_name
);
5398 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
5399 if (wwn2
== (uint64_t)-1)
5401 else if (wwn1
== wwn2
)
5405 if (pid_match
== 2 || wwn_match
== 2) {
5406 /* Found a matching entry */
5407 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
5408 priority
= pri_entry
->tag
;
5419 * qla24xx_update_fcport_fcp_prio
5420 * Activates fcp priority for the logged in fc port
5423 * vha = scsi host structure pointer.
5424 * fcp = port structure pointer.
5427 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5433 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5439 if (fcport
->port_type
!= FCT_TARGET
||
5440 fcport
->loop_id
== FC_NO_LOOP_ID
)
5441 return QLA_FUNCTION_FAILED
;
5443 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
5445 return QLA_FUNCTION_FAILED
;
5447 if (IS_QLA82XX(vha
->hw
)) {
5448 fcport
->fcp_prio
= priority
& 0xf;
5452 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
5453 if (ret
== QLA_SUCCESS
) {
5454 if (fcport
->fcp_prio
!= priority
)
5455 ql_dbg(ql_dbg_user
, vha
, 0x709e,
5456 "Updated FCP_CMND priority - value=%d loop_id=%d "
5457 "port_id=%02x%02x%02x.\n", priority
,
5458 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5459 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5460 fcport
->fcp_prio
= priority
& 0xf;
5462 ql_dbg(ql_dbg_user
, vha
, 0x704f,
5463 "Unable to update FCP_CMND priority - ret=0x%x for "
5464 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
5465 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5466 fcport
->d_id
.b
.al_pa
);
5471 * qla24xx_update_all_fcp_prio
5472 * Activates fcp priority for all the logged in ports
5475 * ha = adapter block pointer.
5478 * QLA_SUCCESS or QLA_FUNCTION_FAILED
5484 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
5489 ret
= QLA_FUNCTION_FAILED
;
5490 /* We need to set priority for all logged in ports */
5491 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5492 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);