2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2013 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"
20 #include <target/target_core_base.h>
21 #include "qla_target.h"
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
27 static int qla2x00_setup_chip(scsi_qla_host_t
*);
28 static int qla2x00_fw_ready(scsi_qla_host_t
*);
29 static int qla2x00_configure_hba(scsi_qla_host_t
*);
30 static int qla2x00_configure_loop(scsi_qla_host_t
*);
31 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
32 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
33 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*, struct list_head
*);
34 static int qla2x00_fabric_dev_login(scsi_qla_host_t
*, fc_port_t
*,
37 static int qla2x00_restart_isp(scsi_qla_host_t
*);
39 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
40 static int qla84xx_init_chip(scsi_qla_host_t
*);
41 static int qla25xx_init_queues(struct qla_hw_data
*);
43 /* SRB Extensions ---------------------------------------------------------- */
46 qla2x00_sp_timeout(unsigned long __data
)
48 srb_t
*sp
= (srb_t
*)__data
;
49 struct srb_iocb
*iocb
;
50 fc_port_t
*fcport
= sp
->fcport
;
51 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
55 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
56 req
= ha
->req_q_map
[0];
57 req
->outstanding_cmds
[sp
->handle
] = NULL
;
58 iocb
= &sp
->u
.iocb_cmd
;
60 sp
->free(fcport
->vha
, sp
);
61 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
65 qla2x00_sp_free(void *data
, void *ptr
)
67 srb_t
*sp
= (srb_t
*)ptr
;
68 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
69 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
71 del_timer(&iocb
->timer
);
72 qla2x00_rel_sp(vha
, sp
);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
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;
86 tmo
= FX00_DEF_RATOV
* 2;
87 } else if (!IS_FWI2_CAPABLE(ha
)) {
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
92 tmo
= ha
->login_timeout
;
98 qla2x00_async_iocb_timeout(void *data
)
100 srb_t
*sp
= (srb_t
*)data
;
101 fc_port_t
*fcport
= sp
->fcport
;
103 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
104 "Async-%s timeout - hdl=%x portid=%02x%02x%02x.\n",
105 sp
->name
, sp
->handle
, fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
106 fcport
->d_id
.b
.al_pa
);
108 fcport
->flags
&= ~FCF_ASYNC_SENT
;
109 if (sp
->type
== SRB_LOGIN_CMD
) {
110 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
111 qla2x00_post_async_logout_work(fcport
->vha
, fcport
, NULL
);
112 /* Retry as needed. */
113 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
114 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
115 QLA_LOGIO_LOGIN_RETRIED
: 0;
116 qla2x00_post_async_login_done_work(fcport
->vha
, fcport
,
122 qla2x00_async_login_sp_done(void *data
, void *ptr
, int res
)
124 srb_t
*sp
= (srb_t
*)ptr
;
125 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
126 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
128 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
129 qla2x00_post_async_login_done_work(sp
->fcport
->vha
, sp
->fcport
,
131 sp
->free(sp
->fcport
->vha
, sp
);
135 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
139 struct srb_iocb
*lio
;
142 rval
= QLA_FUNCTION_FAILED
;
143 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
147 sp
->type
= SRB_LOGIN_CMD
;
149 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
151 lio
= &sp
->u
.iocb_cmd
;
152 lio
->timeout
= qla2x00_async_iocb_timeout
;
153 sp
->done
= qla2x00_async_login_sp_done
;
154 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
155 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
156 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
157 rval
= qla2x00_start_sp(sp
);
158 if (rval
!= QLA_SUCCESS
)
161 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
162 "Async-login - hdl=%x, loopid=%x portid=%02x%02x%02x "
163 "retries=%d.\n", sp
->handle
, fcport
->loop_id
,
164 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
165 fcport
->login_retry
);
169 sp
->free(fcport
->vha
, sp
);
175 qla2x00_async_logout_sp_done(void *data
, void *ptr
, int res
)
177 srb_t
*sp
= (srb_t
*)ptr
;
178 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
179 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
181 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
182 qla2x00_post_async_logout_done_work(sp
->fcport
->vha
, sp
->fcport
,
184 sp
->free(sp
->fcport
->vha
, sp
);
188 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
191 struct srb_iocb
*lio
;
194 rval
= QLA_FUNCTION_FAILED
;
195 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
199 sp
->type
= SRB_LOGOUT_CMD
;
201 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
203 lio
= &sp
->u
.iocb_cmd
;
204 lio
->timeout
= qla2x00_async_iocb_timeout
;
205 sp
->done
= qla2x00_async_logout_sp_done
;
206 rval
= qla2x00_start_sp(sp
);
207 if (rval
!= QLA_SUCCESS
)
210 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
211 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
212 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
213 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
217 sp
->free(fcport
->vha
, sp
);
223 qla2x00_async_adisc_sp_done(void *data
, void *ptr
, int res
)
225 srb_t
*sp
= (srb_t
*)ptr
;
226 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
227 struct scsi_qla_host
*vha
= (scsi_qla_host_t
*)data
;
229 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
230 qla2x00_post_async_adisc_done_work(sp
->fcport
->vha
, sp
->fcport
,
232 sp
->free(sp
->fcport
->vha
, sp
);
236 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
240 struct srb_iocb
*lio
;
243 rval
= QLA_FUNCTION_FAILED
;
244 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
248 sp
->type
= SRB_ADISC_CMD
;
250 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
252 lio
= &sp
->u
.iocb_cmd
;
253 lio
->timeout
= qla2x00_async_iocb_timeout
;
254 sp
->done
= qla2x00_async_adisc_sp_done
;
255 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
256 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
257 rval
= qla2x00_start_sp(sp
);
258 if (rval
!= QLA_SUCCESS
)
261 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
262 "Async-adisc - hdl=%x loopid=%x portid=%02x%02x%02x.\n",
263 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
264 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
268 sp
->free(fcport
->vha
, sp
);
274 qla2x00_tmf_iocb_timeout(void *data
)
276 srb_t
*sp
= (srb_t
*)data
;
277 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
279 tmf
->u
.tmf
.comp_status
= CS_TIMEOUT
;
280 complete(&tmf
->u
.tmf
.comp
);
284 qla2x00_tmf_sp_done(void *data
, void *ptr
, int res
)
286 srb_t
*sp
= (srb_t
*)ptr
;
287 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
288 complete(&tmf
->u
.tmf
.comp
);
292 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
295 struct scsi_qla_host
*vha
= fcport
->vha
;
296 struct srb_iocb
*tm_iocb
;
298 int rval
= QLA_FUNCTION_FAILED
;
300 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
304 tm_iocb
= &sp
->u
.iocb_cmd
;
305 sp
->type
= SRB_TM_CMD
;
307 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
308 tm_iocb
->u
.tmf
.flags
= flags
;
309 tm_iocb
->u
.tmf
.lun
= lun
;
310 tm_iocb
->u
.tmf
.data
= tag
;
311 sp
->done
= qla2x00_tmf_sp_done
;
312 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
313 init_completion(&tm_iocb
->u
.tmf
.comp
);
315 rval
= qla2x00_start_sp(sp
);
316 if (rval
!= QLA_SUCCESS
)
319 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
320 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
321 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
322 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
324 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
326 rval
= tm_iocb
->u
.tmf
.comp_status
== CS_COMPLETE
?
327 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
329 if ((rval
!= QLA_SUCCESS
) || tm_iocb
->u
.tmf
.data
) {
330 ql_dbg(ql_dbg_taskm
, vha
, 0x8030,
331 "TM IOCB failed (%x).\n", rval
);
334 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
335 flags
= tm_iocb
->u
.tmf
.flags
;
336 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
338 /* Issue Marker IOCB */
339 qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
340 vha
->hw
->rsp_q_map
[0], sp
->fcport
->loop_id
, lun
,
341 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
351 qla24xx_abort_iocb_timeout(void *data
)
353 srb_t
*sp
= (srb_t
*)data
;
354 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
356 abt
->u
.abt
.comp_status
= CS_TIMEOUT
;
357 complete(&abt
->u
.abt
.comp
);
361 qla24xx_abort_sp_done(void *data
, void *ptr
, int res
)
363 srb_t
*sp
= (srb_t
*)ptr
;
364 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
366 complete(&abt
->u
.abt
.comp
);
370 qla24xx_async_abort_cmd(srb_t
*cmd_sp
)
372 scsi_qla_host_t
*vha
= cmd_sp
->fcport
->vha
;
373 fc_port_t
*fcport
= cmd_sp
->fcport
;
374 struct srb_iocb
*abt_iocb
;
376 int rval
= QLA_FUNCTION_FAILED
;
378 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
382 abt_iocb
= &sp
->u
.iocb_cmd
;
383 sp
->type
= SRB_ABT_CMD
;
385 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
386 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
387 sp
->done
= qla24xx_abort_sp_done
;
388 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
389 init_completion(&abt_iocb
->u
.abt
.comp
);
391 rval
= qla2x00_start_sp(sp
);
392 if (rval
!= QLA_SUCCESS
)
395 ql_dbg(ql_dbg_async
, vha
, 0x507c,
396 "Abort command issued - hdl=%x, target_id=%x\n",
397 cmd_sp
->handle
, fcport
->tgt_id
);
399 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
401 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
402 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
411 qla24xx_async_abort_command(srb_t
*sp
)
413 unsigned long flags
= 0;
416 fc_port_t
*fcport
= sp
->fcport
;
417 struct scsi_qla_host
*vha
= fcport
->vha
;
418 struct qla_hw_data
*ha
= vha
->hw
;
419 struct req_que
*req
= vha
->req
;
421 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
422 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
423 if (req
->outstanding_cmds
[handle
] == sp
)
426 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
427 if (handle
== req
->num_outstanding_cmds
) {
428 /* Command not found. */
429 return QLA_FUNCTION_FAILED
;
431 if (sp
->type
== SRB_FXIOCB_DCMD
)
432 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
435 return qla24xx_async_abort_cmd(sp
);
439 qla2x00_async_login_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
445 case MBS_COMMAND_COMPLETE
:
447 * Driver must validate login state - If PRLI not complete,
448 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
451 rval
= qla2x00_get_port_database(vha
, fcport
, 0);
452 if (rval
== QLA_NOT_LOGGED_IN
) {
453 fcport
->flags
&= ~FCF_ASYNC_SENT
;
454 fcport
->flags
|= FCF_LOGIN_NEEDED
;
455 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
459 if (rval
!= QLA_SUCCESS
) {
460 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
461 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
464 if (fcport
->flags
& FCF_FCP2_DEVICE
) {
465 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
468 qla2x00_update_fcport(vha
, fcport
);
470 case MBS_COMMAND_ERROR
:
471 fcport
->flags
&= ~FCF_ASYNC_SENT
;
472 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
473 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
475 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
477 case MBS_PORT_ID_USED
:
478 fcport
->loop_id
= data
[1];
479 qla2x00_post_async_logout_work(vha
, fcport
, NULL
);
480 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
482 case MBS_LOOP_ID_USED
:
484 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
485 if (rval
!= QLA_SUCCESS
) {
486 fcport
->flags
&= ~FCF_ASYNC_SENT
;
487 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
490 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
497 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
500 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
505 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
508 if (data
[0] == MBS_COMMAND_COMPLETE
) {
509 qla2x00_update_fcport(vha
, fcport
);
515 fcport
->flags
&= ~FCF_ASYNC_SENT
;
516 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
517 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
519 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
524 /****************************************************************************/
525 /* QLogic ISP2x00 Hardware Support Functions. */
526 /****************************************************************************/
529 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
531 int rval
= QLA_SUCCESS
;
532 struct qla_hw_data
*ha
= vha
->hw
;
533 uint32_t idc_major_ver
, idc_minor_ver
;
536 qla83xx_idc_lock(vha
, 0);
538 /* SV: TODO: Assign initialization timeout from
539 * flash-info / other param
541 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
542 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
544 /* Set our fcoe function presence */
545 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
546 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
547 "Error while setting DRV-Presence.\n");
548 rval
= QLA_FUNCTION_FAILED
;
552 /* Decide the reset ownership */
553 qla83xx_reset_ownership(vha
);
556 * On first protocol driver load:
557 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
559 * Others: Check compatibility with current IDC Major version.
561 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
562 if (ha
->flags
.nic_core_reset_owner
) {
563 /* Set IDC Major version */
564 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
565 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
567 /* Clearing IDC-Lock-Recovery register */
568 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
569 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
571 * Clear further IDC participation if we are not compatible with
572 * the current IDC Major Version.
574 ql_log(ql_log_warn
, vha
, 0xb07d,
575 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
576 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
577 __qla83xx_clear_drv_presence(vha
);
578 rval
= QLA_FUNCTION_FAILED
;
581 /* Each function sets its supported Minor version. */
582 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
583 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
584 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
586 if (ha
->flags
.nic_core_reset_owner
) {
587 memset(config
, 0, sizeof(config
));
588 if (!qla81xx_get_port_config(vha
, config
))
589 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
593 rval
= qla83xx_idc_state_handler(vha
);
596 qla83xx_idc_unlock(vha
, 0);
602 * qla2x00_initialize_adapter
606 * ha = adapter block pointer.
612 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
615 struct qla_hw_data
*ha
= vha
->hw
;
616 struct req_que
*req
= ha
->req_q_map
[0];
618 /* Clear adapter flags. */
619 vha
->flags
.online
= 0;
620 ha
->flags
.chip_reset_done
= 0;
621 vha
->flags
.reset_active
= 0;
622 ha
->flags
.pci_channel_io_perm_failure
= 0;
623 ha
->flags
.eeh_busy
= 0;
624 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
625 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
626 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
627 vha
->device_flags
= DFLG_NO_CABLE
;
629 vha
->flags
.management_server_logged_in
= 0;
630 vha
->marker_needed
= 0;
631 ha
->isp_abort_cnt
= 0;
632 ha
->beacon_blink_led
= 0;
634 set_bit(0, ha
->req_qid_map
);
635 set_bit(0, ha
->rsp_qid_map
);
637 ql_dbg(ql_dbg_init
, vha
, 0x0040,
638 "Configuring PCI space...\n");
639 rval
= ha
->isp_ops
->pci_config(vha
);
641 ql_log(ql_log_warn
, vha
, 0x0044,
642 "Unable to configure PCI space.\n");
646 ha
->isp_ops
->reset_chip(vha
);
648 rval
= qla2xxx_get_flash_info(vha
);
650 ql_log(ql_log_fatal
, vha
, 0x004f,
651 "Unable to validate FLASH data.\n");
655 if (IS_QLA8044(ha
)) {
656 qla8044_read_reset_template(vha
);
658 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
659 * If DONRESET_BIT0 is set, drivers should not set dev_state
660 * to NEED_RESET. But if NEED_RESET is set, drivers should
661 * should honor the reset. */
662 if (ql2xdontresethba
== 1)
663 qla8044_set_idc_dontreset(vha
);
666 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
667 ql_dbg(ql_dbg_init
, vha
, 0x0061,
668 "Configure NVRAM parameters...\n");
670 ha
->isp_ops
->nvram_config(vha
);
672 if (ha
->flags
.disable_serdes
) {
673 /* Mask HBA via NVRAM settings? */
674 ql_log(ql_log_info
, vha
, 0x0077,
675 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
676 return QLA_FUNCTION_FAILED
;
679 ql_dbg(ql_dbg_init
, vha
, 0x0078,
680 "Verifying loaded RISC code...\n");
682 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
683 rval
= ha
->isp_ops
->chip_diag(vha
);
686 rval
= qla2x00_setup_chip(vha
);
691 if (IS_QLA84XX(ha
)) {
692 ha
->cs84xx
= qla84xx_get_chip(vha
);
694 ql_log(ql_log_warn
, vha
, 0x00d0,
695 "Unable to configure ISP84XX.\n");
696 return QLA_FUNCTION_FAILED
;
700 if (qla_ini_mode_enabled(vha
))
701 rval
= qla2x00_init_rings(vha
);
703 ha
->flags
.chip_reset_done
= 1;
705 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
706 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
707 rval
= qla84xx_init_chip(vha
);
708 if (rval
!= QLA_SUCCESS
) {
709 ql_log(ql_log_warn
, vha
, 0x00d4,
710 "Unable to initialize ISP84XX.\n");
711 qla84xx_put_chip(vha
);
715 /* Load the NIC Core f/w if we are the first protocol driver. */
716 if (IS_QLA8031(ha
)) {
717 rval
= qla83xx_nic_core_fw_load(vha
);
719 ql_log(ql_log_warn
, vha
, 0x0124,
720 "Error in initializing NIC Core f/w.\n");
723 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
724 qla24xx_read_fcp_prio_cfg(vha
);
727 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
729 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
735 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
738 * Returns 0 on success.
741 qla2100_pci_config(scsi_qla_host_t
*vha
)
745 struct qla_hw_data
*ha
= vha
->hw
;
746 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
748 pci_set_master(ha
->pdev
);
749 pci_try_set_mwi(ha
->pdev
);
751 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
752 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
753 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
755 pci_disable_rom(ha
->pdev
);
757 /* Get PCI bus information. */
758 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
759 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
760 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
766 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
769 * Returns 0 on success.
772 qla2300_pci_config(scsi_qla_host_t
*vha
)
775 unsigned long flags
= 0;
777 struct qla_hw_data
*ha
= vha
->hw
;
778 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
780 pci_set_master(ha
->pdev
);
781 pci_try_set_mwi(ha
->pdev
);
783 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
784 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
786 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
787 w
&= ~PCI_COMMAND_INTX_DISABLE
;
788 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
791 * If this is a 2300 card and not 2312, reset the
792 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
793 * the 2310 also reports itself as a 2300 so we need to get the
794 * fb revision level -- a 6 indicates it really is a 2300 and
797 if (IS_QLA2300(ha
)) {
798 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
801 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
802 for (cnt
= 0; cnt
< 30000; cnt
++) {
803 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
809 /* Select FPM registers. */
810 WRT_REG_WORD(®
->ctrl_status
, 0x20);
811 RD_REG_WORD(®
->ctrl_status
);
813 /* Get the fb rev level */
814 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
816 if (ha
->fb_rev
== FPM_2300
)
817 pci_clear_mwi(ha
->pdev
);
819 /* Deselect FPM registers. */
820 WRT_REG_WORD(®
->ctrl_status
, 0x0);
821 RD_REG_WORD(®
->ctrl_status
);
823 /* Release RISC module. */
824 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
825 for (cnt
= 0; cnt
< 30000; cnt
++) {
826 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
832 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
835 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
837 pci_disable_rom(ha
->pdev
);
839 /* Get PCI bus information. */
840 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
841 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
842 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
848 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
851 * Returns 0 on success.
854 qla24xx_pci_config(scsi_qla_host_t
*vha
)
857 unsigned long flags
= 0;
858 struct qla_hw_data
*ha
= vha
->hw
;
859 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
861 pci_set_master(ha
->pdev
);
862 pci_try_set_mwi(ha
->pdev
);
864 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
865 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
866 w
&= ~PCI_COMMAND_INTX_DISABLE
;
867 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
869 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
871 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
872 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
873 pcix_set_mmrbc(ha
->pdev
, 2048);
875 /* PCIe -- adjust Maximum Read Request Size (2048). */
876 if (pci_is_pcie(ha
->pdev
))
877 pcie_set_readrq(ha
->pdev
, 4096);
879 pci_disable_rom(ha
->pdev
);
881 ha
->chip_revision
= ha
->pdev
->revision
;
883 /* Get PCI bus information. */
884 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
885 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
886 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
892 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
895 * Returns 0 on success.
898 qla25xx_pci_config(scsi_qla_host_t
*vha
)
901 struct qla_hw_data
*ha
= vha
->hw
;
903 pci_set_master(ha
->pdev
);
904 pci_try_set_mwi(ha
->pdev
);
906 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
907 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
908 w
&= ~PCI_COMMAND_INTX_DISABLE
;
909 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
911 /* PCIe -- adjust Maximum Read Request Size (2048). */
912 if (pci_is_pcie(ha
->pdev
))
913 pcie_set_readrq(ha
->pdev
, 4096);
915 pci_disable_rom(ha
->pdev
);
917 ha
->chip_revision
= ha
->pdev
->revision
;
923 * qla2x00_isp_firmware() - Choose firmware image.
926 * Returns 0 on success.
929 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
932 uint16_t loop_id
, topo
, sw_cap
;
933 uint8_t domain
, area
, al_pa
;
934 struct qla_hw_data
*ha
= vha
->hw
;
936 /* Assume loading risc code */
937 rval
= QLA_FUNCTION_FAILED
;
939 if (ha
->flags
.disable_risc_code_load
) {
940 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
942 /* Verify checksum of loaded RISC code. */
943 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
944 if (rval
== QLA_SUCCESS
) {
945 /* And, verify we are not in ROM code. */
946 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
947 &area
, &domain
, &topo
, &sw_cap
);
952 ql_dbg(ql_dbg_init
, vha
, 0x007a,
953 "**** Load RISC code ****.\n");
959 * qla2x00_reset_chip() - Reset ISP chip.
962 * Returns 0 on success.
965 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
967 unsigned long flags
= 0;
968 struct qla_hw_data
*ha
= vha
->hw
;
969 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
973 if (unlikely(pci_channel_offline(ha
->pdev
)))
976 ha
->isp_ops
->disable_intrs(ha
);
978 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
980 /* Turn off master enable */
982 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
983 cmd
&= ~PCI_COMMAND_MASTER
;
984 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
986 if (!IS_QLA2100(ha
)) {
988 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
989 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
990 for (cnt
= 0; cnt
< 30000; cnt
++) {
991 if ((RD_REG_WORD(®
->hccr
) &
992 HCCR_RISC_PAUSE
) != 0)
997 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
1001 /* Select FPM registers. */
1002 WRT_REG_WORD(®
->ctrl_status
, 0x20);
1003 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1005 /* FPM Soft Reset. */
1006 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
1007 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
1009 /* Toggle Fpm Reset. */
1010 if (!IS_QLA2200(ha
)) {
1011 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
1012 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
1015 /* Select frame buffer registers. */
1016 WRT_REG_WORD(®
->ctrl_status
, 0x10);
1017 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1019 /* Reset frame buffer FIFOs. */
1020 if (IS_QLA2200(ha
)) {
1021 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
1022 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
1024 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
1026 /* Read back fb_cmd until zero or 3 seconds max */
1027 for (cnt
= 0; cnt
< 3000; cnt
++) {
1028 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
1034 /* Select RISC module registers. */
1035 WRT_REG_WORD(®
->ctrl_status
, 0);
1036 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
1038 /* Reset RISC processor. */
1039 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1040 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
1042 /* Release RISC processor. */
1043 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1044 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
1047 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
1048 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
1050 /* Reset ISP chip. */
1051 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1053 /* Wait for RISC to recover from reset. */
1054 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1056 * It is necessary to for a delay here since the card doesn't
1057 * respond to PCI reads during a reset. On some architectures
1058 * this will result in an MCA.
1061 for (cnt
= 30000; cnt
; cnt
--) {
1062 if ((RD_REG_WORD(®
->ctrl_status
) &
1063 CSR_ISP_SOFT_RESET
) == 0)
1070 /* Reset RISC processor. */
1071 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1073 WRT_REG_WORD(®
->semaphore
, 0);
1075 /* Release RISC processor. */
1076 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1077 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
1079 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1080 for (cnt
= 0; cnt
< 30000; cnt
++) {
1081 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
1089 /* Turn on master enable */
1090 cmd
|= PCI_COMMAND_MASTER
;
1091 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
1093 /* Disable RISC pause on FPM parity error. */
1094 if (!IS_QLA2100(ha
)) {
1095 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
1096 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
1099 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1103 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
1105 * Returns 0 on success.
1108 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
1110 uint16_t mb
[4] = {0x1010, 0, 1, 0};
1112 if (!IS_QLA81XX(vha
->hw
))
1115 return qla81xx_write_mpi_register(vha
, mb
);
1119 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
1122 * Returns 0 on success.
1125 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
1127 unsigned long flags
= 0;
1128 struct qla_hw_data
*ha
= vha
->hw
;
1129 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
1132 static int abts_cnt
; /* ISP abort retry counts */
1134 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1137 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
1138 for (cnt
= 0; cnt
< 30000; cnt
++) {
1139 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
1145 WRT_REG_DWORD(®
->ctrl_status
,
1146 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
1147 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
1150 /* Wait for firmware to complete NVRAM accesses. */
1151 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1152 for (cnt
= 10000 ; cnt
&& d2
; cnt
--) {
1154 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1158 /* Wait for soft-reset to complete. */
1159 d2
= RD_REG_DWORD(®
->ctrl_status
);
1160 for (cnt
= 6000000 ; cnt
&& (d2
& CSRX_ISP_SOFT_RESET
); cnt
--) {
1162 d2
= RD_REG_DWORD(®
->ctrl_status
);
1166 /* If required, do an MPI FW reset now */
1167 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
1168 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
1169 if (++abts_cnt
< 5) {
1170 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
1171 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
1174 * We exhausted the ISP abort retries. We have to
1175 * set the board offline.
1178 vha
->flags
.online
= 0;
1183 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
1184 RD_REG_DWORD(®
->hccr
);
1186 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
1187 RD_REG_DWORD(®
->hccr
);
1189 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
1190 RD_REG_DWORD(®
->hccr
);
1192 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1193 for (cnt
= 6000000 ; cnt
&& d2
; cnt
--) {
1195 d2
= (uint32_t) RD_REG_WORD(®
->mailbox0
);
1199 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1201 if (IS_NOPOLLING_TYPE(ha
))
1202 ha
->isp_ops
->enable_intrs(ha
);
1206 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
1208 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
1210 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
1211 *data
= RD_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
);
1216 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
1218 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
1220 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
1221 WRT_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
, data
);
1225 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
1227 struct qla_hw_data
*ha
= vha
->hw
;
1229 uint delta_msec
= 100;
1230 uint elapsed_msec
= 0;
1234 if (!IS_QLA25XX(ha
) && !IS_QLA2031(ha
))
1238 timeout_msec
= TIMEOUT_SEMAPHORE
;
1239 n
= timeout_msec
/ delta_msec
;
1241 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
1242 qla25xx_read_risc_sema_reg(vha
, &wd32
);
1243 if (wd32
& RISC_SEMAPHORE
)
1246 elapsed_msec
+= delta_msec
;
1247 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
1251 if (!(wd32
& RISC_SEMAPHORE
))
1254 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
1257 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
1258 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
1259 n
= timeout_msec
/ delta_msec
;
1261 qla25xx_read_risc_sema_reg(vha
, &wd32
);
1262 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
1265 elapsed_msec
+= delta_msec
;
1266 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
1270 if (wd32
& RISC_SEMAPHORE_FORCE
)
1271 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
1276 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
1283 * qla24xx_reset_chip() - Reset ISP24xx chip.
1286 * Returns 0 on success.
1289 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
1291 struct qla_hw_data
*ha
= vha
->hw
;
1293 if (pci_channel_offline(ha
->pdev
) &&
1294 ha
->flags
.pci_channel_io_perm_failure
) {
1298 ha
->isp_ops
->disable_intrs(ha
);
1300 qla25xx_manipulate_risc_semaphore(vha
);
1302 /* Perform RISC reset. */
1303 qla24xx_reset_risc(vha
);
1307 * qla2x00_chip_diag() - Test chip for proper operation.
1310 * Returns 0 on success.
1313 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
1316 struct qla_hw_data
*ha
= vha
->hw
;
1317 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1318 unsigned long flags
= 0;
1322 struct req_que
*req
= ha
->req_q_map
[0];
1324 /* Assume a failed state */
1325 rval
= QLA_FUNCTION_FAILED
;
1327 ql_dbg(ql_dbg_init
, vha
, 0x007b,
1328 "Testing device at %lx.\n", (u_long
)®
->flash_address
);
1330 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1332 /* Reset ISP chip. */
1333 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
1336 * We need to have a delay here since the card will not respond while
1337 * in reset causing an MCA on some architectures.
1340 data
= qla2x00_debounce_register(®
->ctrl_status
);
1341 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
1343 data
= RD_REG_WORD(®
->ctrl_status
);
1348 goto chip_diag_failed
;
1350 ql_dbg(ql_dbg_init
, vha
, 0x007c,
1351 "Reset register cleared by chip reset.\n");
1353 /* Reset RISC processor. */
1354 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
1355 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
1357 /* Workaround for QLA2312 PCI parity error */
1358 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
1359 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
1360 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
1362 data
= RD_MAILBOX_REG(ha
, reg
, 0);
1369 goto chip_diag_failed
;
1371 /* Check product ID of chip */
1372 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product Id of chip.\n");
1374 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
1375 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
1376 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
1377 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
1378 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
1379 mb
[3] != PROD_ID_3
) {
1380 ql_log(ql_log_warn
, vha
, 0x0062,
1381 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
1382 mb
[1], mb
[2], mb
[3]);
1384 goto chip_diag_failed
;
1386 ha
->product_id
[0] = mb
[1];
1387 ha
->product_id
[1] = mb
[2];
1388 ha
->product_id
[2] = mb
[3];
1389 ha
->product_id
[3] = mb
[4];
1391 /* Adjust fw RISC transfer size */
1392 if (req
->length
> 1024)
1393 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
1395 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
1398 if (IS_QLA2200(ha
) &&
1399 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
1400 /* Limit firmware transfer size with a 2200A */
1401 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
1403 ha
->device_type
|= DT_ISP2200A
;
1404 ha
->fw_transfer_size
= 128;
1407 /* Wrap Incoming Mailboxes Test. */
1408 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1410 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
1411 rval
= qla2x00_mbx_reg_test(vha
);
1413 ql_log(ql_log_warn
, vha
, 0x0080,
1414 "Failed mailbox send register test.\n");
1416 /* Flag a successful rval */
1418 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1422 ql_log(ql_log_info
, vha
, 0x0081,
1423 "Chip diagnostics **** FAILED ****.\n");
1425 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1431 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
1434 * Returns 0 on success.
1437 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
1440 struct qla_hw_data
*ha
= vha
->hw
;
1441 struct req_que
*req
= ha
->req_q_map
[0];
1443 if (IS_P3P_TYPE(ha
))
1446 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
1448 rval
= qla2x00_mbx_reg_test(vha
);
1450 ql_log(ql_log_warn
, vha
, 0x0082,
1451 "Failed mailbox send register test.\n");
1453 /* Flag a successful rval */
1461 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
1464 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
1465 eft_size
, fce_size
, mq_size
;
1468 struct qla_hw_data
*ha
= vha
->hw
;
1469 struct req_que
*req
= ha
->req_q_map
[0];
1470 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
1473 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
1474 "Firmware dump already allocated.\n");
1479 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
1480 req_q_size
= rsp_q_size
= 0;
1485 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
1486 fixed_size
= sizeof(struct qla2100_fw_dump
);
1487 } else if (IS_QLA23XX(ha
)) {
1488 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
1489 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
1491 } else if (IS_FWI2_CAPABLE(ha
)) {
1493 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
1494 else if (IS_QLA81XX(ha
))
1495 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
1496 else if (IS_QLA25XX(ha
))
1497 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
1499 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
1501 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
1504 if (!IS_QLA83XX(ha
))
1505 mq_size
= sizeof(struct qla2xxx_mq_chain
);
1507 * Allocate maximum buffer size for all queues.
1508 * Resizing must be done at end-of-dump processing.
1510 mq_size
+= ha
->max_req_queues
*
1511 (req
->length
* sizeof(request_t
));
1512 mq_size
+= ha
->max_rsp_queues
*
1513 (rsp
->length
* sizeof(response_t
));
1515 if (ha
->tgt
.atio_ring
)
1516 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
1517 /* Allocate memory for Fibre Channel Event Buffer. */
1518 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
1524 dma_free_coherent(&ha
->pdev
->dev
,
1525 FCE_SIZE
, ha
->fce
, ha
->fce_dma
);
1527 /* Allocate memory for Fibre Channel Event Buffer. */
1528 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
1531 ql_log(ql_log_warn
, vha
, 0x00be,
1532 "Unable to allocate (%d KB) for FCE.\n",
1537 memset(tc
, 0, FCE_SIZE
);
1538 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
1539 ha
->fce_mb
, &ha
->fce_bufs
);
1541 ql_log(ql_log_warn
, vha
, 0x00bf,
1542 "Unable to initialize FCE (%d).\n", rval
);
1543 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
1545 ha
->flags
.fce_enabled
= 0;
1548 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
1549 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
1551 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
1552 ha
->flags
.fce_enabled
= 1;
1553 ha
->fce_dma
= tc_dma
;
1558 dma_free_coherent(&ha
->pdev
->dev
,
1559 EFT_SIZE
, ha
->eft
, ha
->eft_dma
);
1561 /* Allocate memory for Extended Trace Buffer. */
1562 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
1565 ql_log(ql_log_warn
, vha
, 0x00c1,
1566 "Unable to allocate (%d KB) for EFT.\n",
1571 memset(tc
, 0, EFT_SIZE
);
1572 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
1574 ql_log(ql_log_warn
, vha
, 0x00c2,
1575 "Unable to initialize EFT (%d).\n", rval
);
1576 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
1580 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
1581 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
1583 eft_size
= EFT_SIZE
;
1584 ha
->eft_dma
= tc_dma
;
1589 if (IS_QLA27XX(ha
)) {
1590 if (!ha
->fw_dump_template
) {
1591 ql_log(ql_log_warn
, vha
, 0x00ba,
1592 "Failed missing fwdump template\n");
1595 dump_size
= qla27xx_fwdt_calculate_dump_size(vha
);
1596 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
1597 "-> allocating fwdump (%x bytes)...\n", dump_size
);
1601 req_q_size
= req
->length
* sizeof(request_t
);
1602 rsp_q_size
= rsp
->length
* sizeof(response_t
);
1603 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
1604 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
1605 ha
->chain_offset
= dump_size
;
1606 dump_size
+= mq_size
+ fce_size
;
1609 ha
->fw_dump
= vmalloc(dump_size
);
1611 ql_log(ql_log_warn
, vha
, 0x00c4,
1612 "Unable to allocate (%d KB) for firmware dump.\n",
1616 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, ha
->fce
,
1623 dma_free_coherent(&ha
->pdev
->dev
, eft_size
, ha
->eft
,
1630 ha
->fw_dump_len
= dump_size
;
1631 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
1632 "Allocated (%d KB) for firmware dump.\n", dump_size
/ 1024);
1637 ha
->fw_dump
->signature
[0] = 'Q';
1638 ha
->fw_dump
->signature
[1] = 'L';
1639 ha
->fw_dump
->signature
[2] = 'G';
1640 ha
->fw_dump
->signature
[3] = 'C';
1641 ha
->fw_dump
->version
= __constant_htonl(1);
1643 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
1644 ha
->fw_dump
->mem_size
= htonl(mem_size
);
1645 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
1646 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
1648 ha
->fw_dump
->eft_size
= htonl(eft_size
);
1649 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
1650 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
1652 ha
->fw_dump
->header_size
=
1653 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
1657 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
1659 #define MPS_MASK 0xe0
1664 if (!IS_QLA81XX(vha
->hw
))
1667 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
1668 if (rval
!= QLA_SUCCESS
) {
1669 ql_log(ql_log_warn
, vha
, 0x0105,
1670 "Unable to acquire semaphore.\n");
1674 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
1675 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
1676 if (rval
!= QLA_SUCCESS
) {
1677 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
1682 if (dc
== (dw
& MPS_MASK
))
1687 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
1688 if (rval
!= QLA_SUCCESS
) {
1689 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
1693 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
1694 if (rval
!= QLA_SUCCESS
) {
1695 ql_log(ql_log_warn
, vha
, 0x006d,
1696 "Unable to release semaphore.\n");
1704 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
1706 /* Don't try to reallocate the array */
1707 if (req
->outstanding_cmds
)
1710 if (!IS_FWI2_CAPABLE(ha
) || (ha
->mqiobase
&&
1711 (ql2xmultique_tag
|| ql2xmaxqueues
> 1)))
1712 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
1714 if (ha
->fw_xcb_count
<= ha
->fw_iocb_count
)
1715 req
->num_outstanding_cmds
= ha
->fw_xcb_count
;
1717 req
->num_outstanding_cmds
= ha
->fw_iocb_count
;
1720 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
1721 req
->num_outstanding_cmds
, GFP_KERNEL
);
1723 if (!req
->outstanding_cmds
) {
1725 * Try to allocate a minimal size just so we can get through
1728 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
1729 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
1730 req
->num_outstanding_cmds
, GFP_KERNEL
);
1732 if (!req
->outstanding_cmds
) {
1733 ql_log(ql_log_fatal
, NULL
, 0x0126,
1734 "Failed to allocate memory for "
1735 "outstanding_cmds for req_que %p.\n", req
);
1736 req
->num_outstanding_cmds
= 0;
1737 return QLA_FUNCTION_FAILED
;
1745 * qla2x00_setup_chip() - Load and start RISC firmware.
1748 * Returns 0 on success.
1751 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
1754 uint32_t srisc_address
= 0;
1755 struct qla_hw_data
*ha
= vha
->hw
;
1756 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
1757 unsigned long flags
;
1758 uint16_t fw_major_version
;
1760 if (IS_P3P_TYPE(ha
)) {
1761 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1762 if (rval
== QLA_SUCCESS
) {
1763 qla2x00_stop_firmware(vha
);
1764 goto enable_82xx_npiv
;
1769 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1770 /* Disable SRAM, Instruction RAM and GP RAM parity. */
1771 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1772 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
1773 RD_REG_WORD(®
->hccr
);
1774 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1777 qla81xx_mpi_sync(vha
);
1779 /* Load firmware sequences */
1780 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
1781 if (rval
== QLA_SUCCESS
) {
1782 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
1783 "Verifying Checksum of loaded RISC code.\n");
1785 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
1786 if (rval
== QLA_SUCCESS
) {
1787 /* Start firmware execution. */
1788 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
1789 "Starting firmware.\n");
1791 rval
= qla2x00_execute_fw(vha
, srisc_address
);
1792 /* Retrieve firmware information. */
1793 if (rval
== QLA_SUCCESS
) {
1795 fw_major_version
= ha
->fw_major_version
;
1796 if (IS_P3P_TYPE(ha
))
1797 qla82xx_check_md_needed(vha
);
1799 rval
= qla2x00_get_fw_version(vha
);
1800 if (rval
!= QLA_SUCCESS
)
1802 ha
->flags
.npiv_supported
= 0;
1803 if (IS_QLA2XXX_MIDTYPE(ha
) &&
1804 (ha
->fw_attributes
& BIT_2
)) {
1805 ha
->flags
.npiv_supported
= 1;
1806 if ((!ha
->max_npiv_vports
) ||
1807 ((ha
->max_npiv_vports
+ 1) %
1808 MIN_MULTI_ID_FABRIC
))
1809 ha
->max_npiv_vports
=
1810 MIN_MULTI_ID_FABRIC
- 1;
1812 qla2x00_get_resource_cnts(vha
, NULL
,
1813 &ha
->fw_xcb_count
, NULL
, &ha
->fw_iocb_count
,
1814 &ha
->max_npiv_vports
, NULL
);
1817 * Allocate the array of outstanding commands
1818 * now that we know the firmware resources.
1820 rval
= qla2x00_alloc_outstanding_cmds(ha
,
1822 if (rval
!= QLA_SUCCESS
)
1825 if (!fw_major_version
&& ql2xallocfwdump
1826 && !(IS_P3P_TYPE(ha
)))
1827 qla2x00_alloc_fw_dump(vha
);
1832 ql_log(ql_log_fatal
, vha
, 0x00cd,
1833 "ISP Firmware failed checksum.\n");
1839 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
1840 /* Enable proper parity. */
1841 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1844 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
1846 /* SRAM, Instruction RAM and GP RAM parity */
1847 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
1848 RD_REG_WORD(®
->hccr
);
1849 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1852 if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
1855 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
1856 if (rval
== QLA_SUCCESS
) {
1857 ha
->flags
.fac_supported
= 1;
1858 ha
->fdt_block_size
= size
<< 2;
1860 ql_log(ql_log_warn
, vha
, 0x00ce,
1861 "Unsupported FAC firmware (%d.%02d.%02d).\n",
1862 ha
->fw_major_version
, ha
->fw_minor_version
,
1863 ha
->fw_subminor_version
);
1865 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
1866 ha
->flags
.fac_supported
= 0;
1873 ql_log(ql_log_fatal
, vha
, 0x00cf,
1874 "Setup chip ****FAILED****.\n");
1881 * qla2x00_init_response_q_entries() - Initializes response queue entries.
1884 * Beginning of request ring has initialization control block already built
1885 * by nvram config routine.
1887 * Returns 0 on success.
1890 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
1895 rsp
->ring_ptr
= rsp
->ring
;
1896 rsp
->ring_index
= 0;
1897 rsp
->status_srb
= NULL
;
1898 pkt
= rsp
->ring_ptr
;
1899 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
1900 pkt
->signature
= RESPONSE_PROCESSED
;
1906 * qla2x00_update_fw_options() - Read and process firmware options.
1909 * Returns 0 on success.
1912 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
1914 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
1915 struct qla_hw_data
*ha
= vha
->hw
;
1917 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
1918 qla2x00_get_fw_options(vha
, ha
->fw_options
);
1920 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
1923 /* Serial Link options. */
1924 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
1925 "Serial link options.\n");
1926 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
1927 (uint8_t *)&ha
->fw_seriallink_options
,
1928 sizeof(ha
->fw_seriallink_options
));
1930 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
1931 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
1932 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
1935 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
1936 emphasis
= (ha
->fw_seriallink_options
[2] &
1937 (BIT_4
| BIT_3
)) >> 3;
1938 tx_sens
= ha
->fw_seriallink_options
[0] &
1939 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1940 rx_sens
= (ha
->fw_seriallink_options
[0] &
1941 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1942 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
1943 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1946 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
1947 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1948 ha
->fw_options
[10] |= BIT_5
|
1949 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1950 (tx_sens
& (BIT_1
| BIT_0
));
1953 swing
= (ha
->fw_seriallink_options
[2] &
1954 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
1955 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
1956 tx_sens
= ha
->fw_seriallink_options
[1] &
1957 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
1958 rx_sens
= (ha
->fw_seriallink_options
[1] &
1959 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
1960 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
1961 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
1964 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
1965 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
1966 ha
->fw_options
[11] |= BIT_5
|
1967 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
1968 (tx_sens
& (BIT_1
| BIT_0
));
1972 /* Return command IOCBs without waiting for an ABTS to complete. */
1973 ha
->fw_options
[3] |= BIT_13
;
1976 if (ha
->flags
.enable_led_scheme
)
1977 ha
->fw_options
[2] |= BIT_12
;
1979 /* Detect ISP6312. */
1981 ha
->fw_options
[2] |= BIT_13
;
1983 /* Update firmware options. */
1984 qla2x00_set_fw_options(vha
, ha
->fw_options
);
1988 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
1991 struct qla_hw_data
*ha
= vha
->hw
;
1993 if (IS_P3P_TYPE(ha
))
1996 /* Update Serial Link options. */
1997 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
2000 rval
= qla2x00_set_serdes_params(vha
,
2001 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
2002 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
2003 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
2004 if (rval
!= QLA_SUCCESS
) {
2005 ql_log(ql_log_warn
, vha
, 0x0104,
2006 "Unable to update Serial Link options (%x).\n", rval
);
2011 qla2x00_config_rings(struct scsi_qla_host
*vha
)
2013 struct qla_hw_data
*ha
= vha
->hw
;
2014 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2015 struct req_que
*req
= ha
->req_q_map
[0];
2016 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
2018 /* Setup ring parameters in initialization control block. */
2019 ha
->init_cb
->request_q_outpointer
= __constant_cpu_to_le16(0);
2020 ha
->init_cb
->response_q_inpointer
= __constant_cpu_to_le16(0);
2021 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
2022 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
2023 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
2024 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
2025 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
2026 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
2028 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
2029 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
2030 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
2031 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
2032 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
2036 qla24xx_config_rings(struct scsi_qla_host
*vha
)
2038 struct qla_hw_data
*ha
= vha
->hw
;
2039 device_reg_t __iomem
*reg
= ISP_QUE_REG(ha
, 0);
2040 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
2041 struct qla_msix_entry
*msix
;
2042 struct init_cb_24xx
*icb
;
2044 struct req_que
*req
= ha
->req_q_map
[0];
2045 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
2047 /* Setup ring parameters in initialization control block. */
2048 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
2049 icb
->request_q_outpointer
= __constant_cpu_to_le16(0);
2050 icb
->response_q_inpointer
= __constant_cpu_to_le16(0);
2051 icb
->request_q_length
= cpu_to_le16(req
->length
);
2052 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
2053 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
2054 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
2055 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
2056 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
2058 /* Setup ATIO queue dma pointers for target mode */
2059 icb
->atio_q_inpointer
= __constant_cpu_to_le16(0);
2060 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
2061 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
2062 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
2064 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
2065 icb
->qos
= __constant_cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
2066 icb
->rid
= __constant_cpu_to_le16(rid
);
2067 if (ha
->flags
.msix_enabled
) {
2068 msix
= &ha
->msix_entries
[1];
2069 ql_dbg(ql_dbg_init
, vha
, 0x00fd,
2070 "Registering vector 0x%x for base que.\n",
2072 icb
->msix
= cpu_to_le16(msix
->entry
);
2074 /* Use alternate PCI bus number */
2076 icb
->firmware_options_2
|=
2077 __constant_cpu_to_le32(BIT_19
);
2078 /* Use alternate PCI devfn */
2080 icb
->firmware_options_2
|=
2081 __constant_cpu_to_le32(BIT_18
);
2083 /* Use Disable MSIX Handshake mode for capable adapters */
2084 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
2085 (ha
->flags
.msix_enabled
)) {
2086 icb
->firmware_options_2
&=
2087 __constant_cpu_to_le32(~BIT_22
);
2088 ha
->flags
.disable_msix_handshake
= 1;
2089 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
2090 "MSIX Handshake Disable Mode turned on.\n");
2092 icb
->firmware_options_2
|=
2093 __constant_cpu_to_le32(BIT_22
);
2095 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_23
);
2097 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
2098 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
2099 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
2100 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
2102 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
2103 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
2104 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
2105 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
2107 qlt_24xx_config_rings(vha
);
2110 RD_REG_DWORD(&ioreg
->hccr
);
2114 * qla2x00_init_rings() - Initializes firmware.
2117 * Beginning of request ring has initialization control block already built
2118 * by nvram config routine.
2120 * Returns 0 on success.
2123 qla2x00_init_rings(scsi_qla_host_t
*vha
)
2126 unsigned long flags
= 0;
2128 struct qla_hw_data
*ha
= vha
->hw
;
2129 struct req_que
*req
;
2130 struct rsp_que
*rsp
;
2131 struct mid_init_cb_24xx
*mid_init_cb
=
2132 (struct mid_init_cb_24xx
*) ha
->init_cb
;
2134 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2136 /* Clear outstanding commands array. */
2137 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
2138 req
= ha
->req_q_map
[que
];
2141 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
2142 req
->outstanding_cmds
[cnt
] = NULL
;
2144 req
->current_outstanding_cmd
= 1;
2146 /* Initialize firmware. */
2147 req
->ring_ptr
= req
->ring
;
2148 req
->ring_index
= 0;
2149 req
->cnt
= req
->length
;
2152 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
2153 rsp
= ha
->rsp_q_map
[que
];
2156 /* Initialize response queue entries */
2158 qlafx00_init_response_q_entries(rsp
);
2160 qla2x00_init_response_q_entries(rsp
);
2163 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
2164 ha
->tgt
.atio_ring_index
= 0;
2165 /* Initialize ATIO queue entries */
2166 qlt_init_atio_q_entries(vha
);
2168 ha
->isp_ops
->config_rings(vha
);
2170 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2172 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
2174 if (IS_QLAFX00(ha
)) {
2175 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
2179 /* Update any ISP specific firmware options before initialization. */
2180 ha
->isp_ops
->update_fw_options(vha
);
2182 if (ha
->flags
.npiv_supported
) {
2183 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
2184 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
2185 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
2188 if (IS_FWI2_CAPABLE(ha
)) {
2189 mid_init_cb
->options
= __constant_cpu_to_le16(BIT_1
);
2190 mid_init_cb
->init_cb
.execution_throttle
=
2191 cpu_to_le16(ha
->fw_xcb_count
);
2194 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
2197 ql_log(ql_log_fatal
, vha
, 0x00d2,
2198 "Init Firmware **** FAILED ****.\n");
2200 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
2201 "Init Firmware -- success.\n");
2208 * qla2x00_fw_ready() - Waits for firmware ready.
2211 * Returns 0 on success.
2214 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
2217 unsigned long wtime
, mtime
, cs84xx_time
;
2218 uint16_t min_wait
; /* Minimum wait time if loop is down */
2219 uint16_t wait_time
; /* Wait time if loop is coming ready */
2221 struct qla_hw_data
*ha
= vha
->hw
;
2223 if (IS_QLAFX00(vha
->hw
))
2224 return qlafx00_fw_ready(vha
);
2228 /* 20 seconds for loop down. */
2232 * Firmware should take at most one RATOV to login, plus 5 seconds for
2233 * our own processing.
2235 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
2236 wait_time
= min_wait
;
2239 /* Min wait time if loop down */
2240 mtime
= jiffies
+ (min_wait
* HZ
);
2242 /* wait time before firmware ready */
2243 wtime
= jiffies
+ (wait_time
* HZ
);
2245 /* Wait for ISP to finish LIP */
2246 if (!vha
->flags
.init_done
)
2247 ql_log(ql_log_info
, vha
, 0x801e,
2248 "Waiting for LIP to complete.\n");
2251 memset(state
, -1, sizeof(state
));
2252 rval
= qla2x00_get_firmware_state(vha
, state
);
2253 if (rval
== QLA_SUCCESS
) {
2254 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
2255 vha
->device_flags
&= ~DFLG_NO_CABLE
;
2257 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
2258 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
2259 "fw_state=%x 84xx=%x.\n", state
[0],
2261 if ((state
[2] & FSTATE_LOGGED_IN
) &&
2262 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
2263 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
2264 "Sending verify iocb.\n");
2266 cs84xx_time
= jiffies
;
2267 rval
= qla84xx_init_chip(vha
);
2268 if (rval
!= QLA_SUCCESS
) {
2271 "Init chip failed.\n");
2275 /* Add time taken to initialize. */
2276 cs84xx_time
= jiffies
- cs84xx_time
;
2277 wtime
+= cs84xx_time
;
2278 mtime
+= cs84xx_time
;
2279 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
2280 "Increasing wait time by %ld. "
2281 "New time %ld.\n", cs84xx_time
,
2284 } else if (state
[0] == FSTATE_READY
) {
2285 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
2286 "F/W Ready - OK.\n");
2288 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
2289 &ha
->login_timeout
, &ha
->r_a_tov
);
2295 rval
= QLA_FUNCTION_FAILED
;
2297 if (atomic_read(&vha
->loop_down_timer
) &&
2298 state
[0] != FSTATE_READY
) {
2299 /* Loop down. Timeout on min_wait for states
2300 * other than Wait for Login.
2302 if (time_after_eq(jiffies
, mtime
)) {
2303 ql_log(ql_log_info
, vha
, 0x8038,
2304 "Cable is unplugged...\n");
2306 vha
->device_flags
|= DFLG_NO_CABLE
;
2311 /* Mailbox cmd failed. Timeout on min_wait. */
2312 if (time_after_eq(jiffies
, mtime
) ||
2313 ha
->flags
.isp82xx_fw_hung
)
2317 if (time_after_eq(jiffies
, wtime
))
2320 /* Delay for a while */
2324 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
2325 "fw_state=%x (%x, %x, %x, %x) " "curr time=%lx.\n", state
[0],
2326 state
[1], state
[2], state
[3], state
[4], jiffies
);
2328 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
2329 ql_log(ql_log_warn
, vha
, 0x803b,
2330 "Firmware ready **** FAILED ****.\n");
2337 * qla2x00_configure_hba
2338 * Setup adapter context.
2341 * ha = adapter state pointer.
2350 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
2359 char connect_type
[22];
2360 struct qla_hw_data
*ha
= vha
->hw
;
2361 unsigned long flags
;
2362 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
2364 /* Get host addresses. */
2365 rval
= qla2x00_get_adapter_id(vha
,
2366 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
2367 if (rval
!= QLA_SUCCESS
) {
2368 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
2369 IS_CNA_CAPABLE(ha
) ||
2370 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
2371 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
2372 "Loop is in a transition state.\n");
2374 ql_log(ql_log_warn
, vha
, 0x2009,
2375 "Unable to get host loop ID.\n");
2376 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
2377 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
2378 ql_log(ql_log_warn
, vha
, 0x1151,
2379 "Doing link init.\n");
2380 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
2383 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2389 ql_log(ql_log_info
, vha
, 0x200a,
2390 "Cannot get topology - retrying.\n");
2391 return (QLA_FUNCTION_FAILED
);
2394 vha
->loop_id
= loop_id
;
2397 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
2398 ha
->operating_mode
= LOOP
;
2403 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
2404 ha
->current_topology
= ISP_CFG_NL
;
2405 strcpy(connect_type
, "(Loop)");
2409 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
2410 ha
->switch_cap
= sw_cap
;
2411 ha
->current_topology
= ISP_CFG_FL
;
2412 strcpy(connect_type
, "(FL_Port)");
2416 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
2417 ha
->operating_mode
= P2P
;
2418 ha
->current_topology
= ISP_CFG_N
;
2419 strcpy(connect_type
, "(N_Port-to-N_Port)");
2423 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
2424 ha
->switch_cap
= sw_cap
;
2425 ha
->operating_mode
= P2P
;
2426 ha
->current_topology
= ISP_CFG_F
;
2427 strcpy(connect_type
, "(F_Port)");
2431 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
2432 "HBA in unknown topology %x, using NL.\n", topo
);
2433 ha
->current_topology
= ISP_CFG_NL
;
2434 strcpy(connect_type
, "(Loop)");
2438 /* Save Host port and loop ID. */
2439 /* byte order - Big Endian */
2440 vha
->d_id
.b
.domain
= domain
;
2441 vha
->d_id
.b
.area
= area
;
2442 vha
->d_id
.b
.al_pa
= al_pa
;
2444 spin_lock_irqsave(&ha
->vport_slock
, flags
);
2445 qlt_update_vp_map(vha
, SET_AL_PA
);
2446 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
2448 if (!vha
->flags
.init_done
)
2449 ql_log(ql_log_info
, vha
, 0x2010,
2450 "Topology - %s, Host Loop address 0x%x.\n",
2451 connect_type
, vha
->loop_id
);
2457 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
2462 struct qla_hw_data
*ha
= vha
->hw
;
2463 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
2464 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
2466 if (memcmp(model
, BINZERO
, len
) != 0) {
2467 strncpy(ha
->model_number
, model
, len
);
2468 st
= en
= ha
->model_number
;
2471 if (*en
!= 0x20 && *en
!= 0x00)
2476 index
= (ha
->pdev
->subsystem_device
& 0xff);
2478 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2479 index
< QLA_MODEL_NAMES
)
2480 strncpy(ha
->model_desc
,
2481 qla2x00_model_name
[index
* 2 + 1],
2482 sizeof(ha
->model_desc
) - 1);
2484 index
= (ha
->pdev
->subsystem_device
& 0xff);
2486 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
2487 index
< QLA_MODEL_NAMES
) {
2488 strcpy(ha
->model_number
,
2489 qla2x00_model_name
[index
* 2]);
2490 strncpy(ha
->model_desc
,
2491 qla2x00_model_name
[index
* 2 + 1],
2492 sizeof(ha
->model_desc
) - 1);
2494 strcpy(ha
->model_number
, def
);
2497 if (IS_FWI2_CAPABLE(ha
))
2498 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
2499 sizeof(ha
->model_desc
));
2502 /* On sparc systems, obtain port and node WWN from firmware
2505 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
2508 struct qla_hw_data
*ha
= vha
->hw
;
2509 struct pci_dev
*pdev
= ha
->pdev
;
2510 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
2514 val
= of_get_property(dp
, "port-wwn", &len
);
2515 if (val
&& len
>= WWN_SIZE
)
2516 memcpy(nv
->port_name
, val
, WWN_SIZE
);
2518 val
= of_get_property(dp
, "node-wwn", &len
);
2519 if (val
&& len
>= WWN_SIZE
)
2520 memcpy(nv
->node_name
, val
, WWN_SIZE
);
2525 * NVRAM configuration for ISP 2xxx
2528 * ha = adapter block pointer.
2531 * initialization control block in response_ring
2532 * host adapters parameters in host adapter block
2538 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
2543 uint8_t *dptr1
, *dptr2
;
2544 struct qla_hw_data
*ha
= vha
->hw
;
2545 init_cb_t
*icb
= ha
->init_cb
;
2546 nvram_t
*nv
= ha
->nvram
;
2547 uint8_t *ptr
= ha
->nvram
;
2548 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2552 /* Determine NVRAM starting address. */
2553 ha
->nvram_size
= sizeof(nvram_t
);
2555 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
2556 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
2557 ha
->nvram_base
= 0x80;
2559 /* Get NVRAM data and calculate checksum. */
2560 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
2561 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
2564 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
2565 "Contents of NVRAM.\n");
2566 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
2567 (uint8_t *)nv
, ha
->nvram_size
);
2569 /* Bad NVRAM data, set defaults parameters. */
2570 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
2571 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
2572 /* Reset NVRAM data. */
2573 ql_log(ql_log_warn
, vha
, 0x0064,
2574 "Inconsistent NVRAM "
2575 "detected: checksum=0x%x id=%c version=0x%x.\n",
2576 chksum
, nv
->id
[0], nv
->nvram_version
);
2577 ql_log(ql_log_warn
, vha
, 0x0065,
2579 "functioning (yet invalid -- WWPN) defaults.\n");
2582 * Set default initialization control block.
2584 memset(nv
, 0, ha
->nvram_size
);
2585 nv
->parameter_block_version
= ICB_VERSION
;
2587 if (IS_QLA23XX(ha
)) {
2588 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2589 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2590 nv
->add_firmware_options
[0] = BIT_5
;
2591 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2592 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2593 nv
->special_options
[1] = BIT_7
;
2594 } else if (IS_QLA2200(ha
)) {
2595 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
2596 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
2597 nv
->add_firmware_options
[0] = BIT_5
;
2598 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
2599 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2600 } else if (IS_QLA2100(ha
)) {
2601 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
2602 nv
->firmware_options
[1] = BIT_5
;
2603 nv
->frame_payload_size
= __constant_cpu_to_le16(1024);
2606 nv
->max_iocb_allocation
= __constant_cpu_to_le16(256);
2607 nv
->execution_throttle
= __constant_cpu_to_le16(16);
2608 nv
->retry_count
= 8;
2609 nv
->retry_delay
= 1;
2611 nv
->port_name
[0] = 33;
2612 nv
->port_name
[3] = 224;
2613 nv
->port_name
[4] = 139;
2615 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
2617 nv
->login_timeout
= 4;
2620 * Set default host adapter parameters
2622 nv
->host_p
[1] = BIT_2
;
2623 nv
->reset_delay
= 5;
2624 nv
->port_down_retry_count
= 8;
2625 nv
->max_luns_per_target
= __constant_cpu_to_le16(8);
2626 nv
->link_down_timeout
= 60;
2631 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
2633 * The SN2 does not provide BIOS emulation which means you can't change
2634 * potentially bogus BIOS settings. Force the use of default settings
2635 * for link rate and frame size. Hope that the rest of the settings
2638 if (ia64_platform_is("sn2")) {
2639 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
2641 nv
->special_options
[1] = BIT_7
;
2645 /* Reset Initialization control block */
2646 memset(icb
, 0, ha
->init_cb_size
);
2649 * Setup driver NVRAM options.
2651 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
2652 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
2653 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
2654 nv
->firmware_options
[1] &= ~BIT_4
;
2656 if (IS_QLA23XX(ha
)) {
2657 nv
->firmware_options
[0] |= BIT_2
;
2658 nv
->firmware_options
[0] &= ~BIT_3
;
2659 nv
->special_options
[0] &= ~BIT_6
;
2660 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
2662 if (IS_QLA2300(ha
)) {
2663 if (ha
->fb_rev
== FPM_2310
) {
2664 strcpy(ha
->model_number
, "QLA2310");
2666 strcpy(ha
->model_number
, "QLA2300");
2669 qla2x00_set_model_info(vha
, nv
->model_number
,
2670 sizeof(nv
->model_number
), "QLA23xx");
2672 } else if (IS_QLA2200(ha
)) {
2673 nv
->firmware_options
[0] |= BIT_2
;
2675 * 'Point-to-point preferred, else loop' is not a safe
2676 * connection mode setting.
2678 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
2680 /* Force 'loop preferred, else point-to-point'. */
2681 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
2682 nv
->add_firmware_options
[0] |= BIT_5
;
2684 strcpy(ha
->model_number
, "QLA22xx");
2685 } else /*if (IS_QLA2100(ha))*/ {
2686 strcpy(ha
->model_number
, "QLA2100");
2690 * Copy over NVRAM RISC parameter block to initialization control block.
2692 dptr1
= (uint8_t *)icb
;
2693 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
2694 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
2696 *dptr1
++ = *dptr2
++;
2698 /* Copy 2nd half. */
2699 dptr1
= (uint8_t *)icb
->add_firmware_options
;
2700 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
2702 *dptr1
++ = *dptr2
++;
2704 /* Use alternate WWN? */
2705 if (nv
->host_p
[1] & BIT_7
) {
2706 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
2707 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
2710 /* Prepare nodename */
2711 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
2713 * Firmware will apply the following mask if the nodename was
2716 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
2717 icb
->node_name
[0] &= 0xF0;
2721 * Set host adapter parameters.
2725 * BIT_7 in the host-parameters section allows for modification to
2726 * internal driver logging.
2728 if (nv
->host_p
[0] & BIT_7
)
2729 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
2730 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
2731 /* Always load RISC code on non ISP2[12]00 chips. */
2732 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
2733 ha
->flags
.disable_risc_code_load
= 0;
2734 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
2735 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
2736 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
2737 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
2738 ha
->flags
.disable_serdes
= 0;
2740 ha
->operating_mode
=
2741 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
2743 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
2744 sizeof(ha
->fw_seriallink_options
));
2746 /* save HBA serial number */
2747 ha
->serial0
= icb
->port_name
[5];
2748 ha
->serial1
= icb
->port_name
[6];
2749 ha
->serial2
= icb
->port_name
[7];
2750 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
2751 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
2753 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
2755 ha
->retry_count
= nv
->retry_count
;
2757 /* Set minimum login_timeout to 4 seconds. */
2758 if (nv
->login_timeout
!= ql2xlogintimeout
)
2759 nv
->login_timeout
= ql2xlogintimeout
;
2760 if (nv
->login_timeout
< 4)
2761 nv
->login_timeout
= 4;
2762 ha
->login_timeout
= nv
->login_timeout
;
2763 icb
->login_timeout
= nv
->login_timeout
;
2765 /* Set minimum RATOV to 100 tenths of a second. */
2768 ha
->loop_reset_delay
= nv
->reset_delay
;
2770 /* Link Down Timeout = 0:
2772 * When Port Down timer expires we will start returning
2773 * I/O's to OS with "DID_NO_CONNECT".
2775 * Link Down Timeout != 0:
2777 * The driver waits for the link to come up after link down
2778 * before returning I/Os to OS with "DID_NO_CONNECT".
2780 if (nv
->link_down_timeout
== 0) {
2781 ha
->loop_down_abort_time
=
2782 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
2784 ha
->link_down_timeout
= nv
->link_down_timeout
;
2785 ha
->loop_down_abort_time
=
2786 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
2790 * Need enough time to try and get the port back.
2792 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
2793 if (qlport_down_retry
)
2794 ha
->port_down_retry_count
= qlport_down_retry
;
2795 /* Set login_retry_count */
2796 ha
->login_retry_count
= nv
->retry_count
;
2797 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
2798 ha
->port_down_retry_count
> 3)
2799 ha
->login_retry_count
= ha
->port_down_retry_count
;
2800 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
2801 ha
->login_retry_count
= ha
->port_down_retry_count
;
2802 if (ql2xloginretrycount
)
2803 ha
->login_retry_count
= ql2xloginretrycount
;
2805 icb
->lun_enables
= __constant_cpu_to_le16(0);
2806 icb
->command_resource_count
= 0;
2807 icb
->immediate_notify_resource_count
= 0;
2808 icb
->timeout
= __constant_cpu_to_le16(0);
2810 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2812 icb
->firmware_options
[0] &= ~BIT_3
;
2813 icb
->add_firmware_options
[0] &=
2814 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2815 icb
->add_firmware_options
[0] |= BIT_2
;
2816 icb
->response_accumulation_timer
= 3;
2817 icb
->interrupt_delay_timer
= 5;
2819 vha
->flags
.process_response_queue
= 1;
2822 if (!vha
->flags
.init_done
) {
2823 ha
->zio_mode
= icb
->add_firmware_options
[0] &
2824 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2825 ha
->zio_timer
= icb
->interrupt_delay_timer
?
2826 icb
->interrupt_delay_timer
: 2;
2828 icb
->add_firmware_options
[0] &=
2829 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
2830 vha
->flags
.process_response_queue
= 0;
2831 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
2832 ha
->zio_mode
= QLA_ZIO_MODE_6
;
2834 ql_log(ql_log_info
, vha
, 0x0068,
2835 "ZIO mode %d enabled; timer delay (%d us).\n",
2836 ha
->zio_mode
, ha
->zio_timer
* 100);
2838 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
2839 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
2840 vha
->flags
.process_response_queue
= 1;
2845 ql_log(ql_log_warn
, vha
, 0x0069,
2846 "NVRAM configuration failed.\n");
2852 qla2x00_rport_del(void *data
)
2854 fc_port_t
*fcport
= data
;
2855 struct fc_rport
*rport
;
2856 scsi_qla_host_t
*vha
= fcport
->vha
;
2857 unsigned long flags
;
2859 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
2860 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
2861 fcport
->drport
= NULL
;
2862 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
2864 fc_remote_port_delete(rport
);
2866 * Release the target mode FC NEXUS in qla_target.c code
2867 * if target mod is enabled.
2869 qlt_fc_port_deleted(vha
, fcport
);
2874 * qla2x00_alloc_fcport() - Allocate a generic fcport.
2876 * @flags: allocation flags
2878 * Returns a pointer to the allocated fcport, or NULL, if none available.
2881 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
2885 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
2889 /* Setup fcport template structure. */
2891 fcport
->port_type
= FCT_UNKNOWN
;
2892 fcport
->loop_id
= FC_NO_LOOP_ID
;
2893 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
2894 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
2900 * qla2x00_configure_loop
2901 * Updates Fibre Channel Device Database with what is actually on loop.
2904 * ha = adapter block pointer.
2909 * 2 = database was full and device was not configured.
2912 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
2915 unsigned long flags
, save_flags
;
2916 struct qla_hw_data
*ha
= vha
->hw
;
2919 /* Get Initiator ID */
2920 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
2921 rval
= qla2x00_configure_hba(vha
);
2922 if (rval
!= QLA_SUCCESS
) {
2923 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
2924 "Unable to configure HBA.\n");
2929 save_flags
= flags
= vha
->dpc_flags
;
2930 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
2931 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
2934 * If we have both an RSCN and PORT UPDATE pending then handle them
2935 * both at the same time.
2937 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
2938 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
2940 qla2x00_get_data_rate(vha
);
2942 /* Determine what we need to do */
2943 if (ha
->current_topology
== ISP_CFG_FL
&&
2944 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2946 set_bit(RSCN_UPDATE
, &flags
);
2948 } else if (ha
->current_topology
== ISP_CFG_F
&&
2949 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
2951 set_bit(RSCN_UPDATE
, &flags
);
2952 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
2954 } else if (ha
->current_topology
== ISP_CFG_N
) {
2955 clear_bit(RSCN_UPDATE
, &flags
);
2957 } else if (!vha
->flags
.online
||
2958 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
2960 set_bit(RSCN_UPDATE
, &flags
);
2961 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
2964 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
2965 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2966 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
2967 "Loop resync needed, failing.\n");
2968 rval
= QLA_FUNCTION_FAILED
;
2970 rval
= qla2x00_configure_local_loop(vha
);
2973 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
2974 if (LOOP_TRANSITION(vha
)) {
2975 ql_dbg(ql_dbg_disc
, vha
, 0x201e,
2976 "Needs RSCN update and loop transition.\n");
2977 rval
= QLA_FUNCTION_FAILED
;
2980 rval
= qla2x00_configure_fabric(vha
);
2983 if (rval
== QLA_SUCCESS
) {
2984 if (atomic_read(&vha
->loop_down_timer
) ||
2985 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
2986 rval
= QLA_FUNCTION_FAILED
;
2988 atomic_set(&vha
->loop_state
, LOOP_READY
);
2989 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
2995 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
2996 "%s *** FAILED ***.\n", __func__
);
2998 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
2999 "%s: exiting normally.\n", __func__
);
3002 /* Restore state if a resync event occurred during processing */
3003 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
3004 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
3005 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3006 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
3007 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
3017 * qla2x00_configure_local_loop
3018 * Updates Fibre Channel Device Database with local loop devices.
3021 * ha = adapter block pointer.
3027 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
3032 fc_port_t
*fcport
, *new_fcport
;
3038 uint8_t domain
, area
, al_pa
;
3039 struct qla_hw_data
*ha
= vha
->hw
;
3043 entries
= MAX_FIBRE_DEVICES_LOOP
;
3045 /* Get list of logged in devices. */
3046 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
3047 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
3049 if (rval
!= QLA_SUCCESS
)
3050 goto cleanup_allocation
;
3052 ql_dbg(ql_dbg_disc
, vha
, 0x2017,
3053 "Entries in ID list (%d).\n", entries
);
3054 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
3055 (uint8_t *)ha
->gid_list
,
3056 entries
* sizeof(struct gid_list_info
));
3058 /* Allocate temporary fcport for any new fcports discovered. */
3059 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3060 if (new_fcport
== NULL
) {
3061 ql_log(ql_log_warn
, vha
, 0x2018,
3062 "Memory allocation failed for fcport.\n");
3063 rval
= QLA_MEMORY_ALLOC_FAILED
;
3064 goto cleanup_allocation
;
3066 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
3069 * Mark local devices that were present with FCF_DEVICE_LOST for now.
3071 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3072 if (atomic_read(&fcport
->state
) == FCS_ONLINE
&&
3073 fcport
->port_type
!= FCT_BROADCAST
&&
3074 (fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3076 ql_dbg(ql_dbg_disc
, vha
, 0x2019,
3077 "Marking port lost loop_id=0x%04x.\n",
3080 qla2x00_set_fcport_state(fcport
, FCS_DEVICE_LOST
);
3084 /* Add devices to port list. */
3085 id_iter
= (char *)ha
->gid_list
;
3086 for (index
= 0; index
< entries
; index
++) {
3087 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
3088 area
= ((struct gid_list_info
*)id_iter
)->area
;
3089 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
3090 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3091 loop_id
= (uint16_t)
3092 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
3094 loop_id
= le16_to_cpu(
3095 ((struct gid_list_info
*)id_iter
)->loop_id
);
3096 id_iter
+= ha
->gid_list_info_size
;
3098 /* Bypass reserved domain fields. */
3099 if ((domain
& 0xf0) == 0xf0)
3102 /* Bypass if not same domain and area of adapter. */
3103 if (area
&& domain
&&
3104 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
3107 /* Bypass invalid local loop ID. */
3108 if (loop_id
> LAST_LOCAL_LOOP_ID
)
3111 memset(new_fcport
, 0, sizeof(fc_port_t
));
3113 /* Fill in member data. */
3114 new_fcport
->d_id
.b
.domain
= domain
;
3115 new_fcport
->d_id
.b
.area
= area
;
3116 new_fcport
->d_id
.b
.al_pa
= al_pa
;
3117 new_fcport
->loop_id
= loop_id
;
3118 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
3119 if (rval2
!= QLA_SUCCESS
) {
3120 ql_dbg(ql_dbg_disc
, vha
, 0x201a,
3121 "Failed to retrieve fcport information "
3122 "-- get_port_database=%x, loop_id=0x%04x.\n",
3123 rval2
, new_fcport
->loop_id
);
3124 ql_dbg(ql_dbg_disc
, vha
, 0x201b,
3125 "Scheduling resync.\n");
3126 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3130 /* Check for matching device in port list. */
3133 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3134 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3138 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
3139 fcport
->loop_id
= new_fcport
->loop_id
;
3140 fcport
->port_type
= new_fcport
->port_type
;
3141 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3142 memcpy(fcport
->node_name
, new_fcport
->node_name
,
3150 /* New device, add to fcports list. */
3151 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
3153 /* Allocate a new replacement fcport. */
3154 fcport
= new_fcport
;
3155 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3156 if (new_fcport
== NULL
) {
3157 ql_log(ql_log_warn
, vha
, 0x201c,
3158 "Failed to allocate memory for fcport.\n");
3159 rval
= QLA_MEMORY_ALLOC_FAILED
;
3160 goto cleanup_allocation
;
3162 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
3165 /* Base iIDMA settings on HBA port speed. */
3166 fcport
->fp_speed
= ha
->link_data_rate
;
3168 qla2x00_update_fcport(vha
, fcport
);
3176 if (rval
!= QLA_SUCCESS
) {
3177 ql_dbg(ql_dbg_disc
, vha
, 0x201d,
3178 "Configure local loop error exit: rval=%x.\n", rval
);
3185 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3189 struct qla_hw_data
*ha
= vha
->hw
;
3191 if (!IS_IIDMA_CAPABLE(ha
))
3194 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
3197 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
3198 fcport
->fp_speed
> ha
->link_data_rate
)
3201 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
3203 if (rval
!= QLA_SUCCESS
) {
3204 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
3205 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
3206 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
3208 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
3209 "iIDMA adjusted to %s GB/s on %8phN.\n",
3210 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
3216 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3218 struct fc_rport_identifiers rport_ids
;
3219 struct fc_rport
*rport
;
3220 unsigned long flags
;
3222 qla2x00_rport_del(fcport
);
3224 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
3225 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
3226 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
3227 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
3228 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
3229 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
3231 ql_log(ql_log_warn
, vha
, 0x2006,
3232 "Unable to allocate fc remote port.\n");
3236 * Create target mode FC NEXUS in qla_target.c if target mode is
3239 qlt_fc_port_added(vha
, fcport
);
3241 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
3242 *((fc_port_t
**)rport
->dd_data
) = fcport
;
3243 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
3245 rport
->supported_classes
= fcport
->supported_classes
;
3247 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
3248 if (fcport
->port_type
== FCT_INITIATOR
)
3249 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
3250 if (fcport
->port_type
== FCT_TARGET
)
3251 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
3252 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
3256 * qla2x00_update_fcport
3257 * Updates device on list.
3260 * ha = adapter block pointer.
3261 * fcport = port structure pointer.
3271 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3275 if (IS_QLAFX00(vha
->hw
)) {
3276 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
3277 qla2x00_reg_remote_port(vha
, fcport
);
3280 fcport
->login_retry
= 0;
3281 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
3283 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
3284 qla2x00_iidma_fcport(vha
, fcport
);
3285 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
3286 qla2x00_reg_remote_port(vha
, fcport
);
3290 * qla2x00_configure_fabric
3291 * Setup SNS devices with loop ID's.
3294 * ha = adapter block pointer.
3301 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
3304 fc_port_t
*fcport
, *fcptemp
;
3305 uint16_t next_loopid
;
3306 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3308 LIST_HEAD(new_fcports
);
3309 struct qla_hw_data
*ha
= vha
->hw
;
3310 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
3312 /* If FL port exists, then SNS is present */
3313 if (IS_FWI2_CAPABLE(ha
))
3314 loop_id
= NPH_F_PORT
;
3316 loop_id
= SNS_FL_PORT
;
3317 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
3318 if (rval
!= QLA_SUCCESS
) {
3319 ql_dbg(ql_dbg_disc
, vha
, 0x201f,
3320 "MBX_GET_PORT_NAME failed, No FL Port.\n");
3322 vha
->device_flags
&= ~SWITCH_FOUND
;
3323 return (QLA_SUCCESS
);
3325 vha
->device_flags
|= SWITCH_FOUND
;
3329 if (ql2xfdmienable
&&
3330 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
3331 qla2x00_fdmi_register(vha
);
3333 /* Ensure we are logged into the SNS. */
3334 if (IS_FWI2_CAPABLE(ha
))
3337 loop_id
= SIMPLE_NAME_SERVER
;
3338 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
3339 0xfc, mb
, BIT_1
|BIT_0
);
3340 if (rval
!= QLA_SUCCESS
) {
3341 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3344 if (mb
[0] != MBS_COMMAND_COMPLETE
) {
3345 ql_dbg(ql_dbg_disc
, vha
, 0x2042,
3346 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x "
3347 "mb[6]=%x mb[7]=%x.\n", loop_id
, mb
[0], mb
[1],
3348 mb
[2], mb
[6], mb
[7]);
3349 return (QLA_SUCCESS
);
3352 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
3353 if (qla2x00_rft_id(vha
)) {
3355 ql_dbg(ql_dbg_disc
, vha
, 0x2045,
3356 "Register FC-4 TYPE failed.\n");
3358 if (qla2x00_rff_id(vha
)) {
3360 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
3361 "Register FC-4 Features failed.\n");
3363 if (qla2x00_rnn_id(vha
)) {
3365 ql_dbg(ql_dbg_disc
, vha
, 0x204f,
3366 "Register Node Name failed.\n");
3367 } else if (qla2x00_rsnn_nn(vha
)) {
3369 ql_dbg(ql_dbg_disc
, vha
, 0x2053,
3370 "Register Symobilic Node Name failed.\n");
3374 #define QLA_FCPORT_SCAN 1
3375 #define QLA_FCPORT_FOUND 2
3377 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3378 fcport
->scan_state
= QLA_FCPORT_SCAN
;
3381 rval
= qla2x00_find_all_fabric_devs(vha
, &new_fcports
);
3382 if (rval
!= QLA_SUCCESS
)
3386 * Logout all previous fabric devices marked lost, except
3389 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3390 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3393 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
3396 if (fcport
->scan_state
== QLA_FCPORT_SCAN
&&
3397 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3398 qla2x00_mark_device_lost(vha
, fcport
,
3399 ql2xplogiabsentdevice
, 0);
3400 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3401 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3402 fcport
->port_type
!= FCT_INITIATOR
&&
3403 fcport
->port_type
!= FCT_BROADCAST
) {
3404 ha
->isp_ops
->fabric_logout(vha
,
3406 fcport
->d_id
.b
.domain
,
3407 fcport
->d_id
.b
.area
,
3408 fcport
->d_id
.b
.al_pa
);
3409 fcport
->loop_id
= FC_NO_LOOP_ID
;
3414 /* Starting free loop ID. */
3415 next_loopid
= ha
->min_external_loopid
;
3418 * Scan through our port list and login entries that need to be
3421 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3422 if (atomic_read(&vha
->loop_down_timer
) ||
3423 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3426 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
3427 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
3430 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
3431 fcport
->loop_id
= next_loopid
;
3432 rval
= qla2x00_find_new_loop_id(
3434 if (rval
!= QLA_SUCCESS
) {
3435 /* Ran out of IDs to use */
3439 /* Login and update database */
3440 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3443 /* Exit if out of loop IDs. */
3444 if (rval
!= QLA_SUCCESS
) {
3449 * Login and add the new devices to our port list.
3451 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3452 if (atomic_read(&vha
->loop_down_timer
) ||
3453 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
3456 /* Find a new loop ID to use. */
3457 fcport
->loop_id
= next_loopid
;
3458 rval
= qla2x00_find_new_loop_id(base_vha
, fcport
);
3459 if (rval
!= QLA_SUCCESS
) {
3460 /* Ran out of IDs to use */
3464 /* Login and update database */
3465 qla2x00_fabric_dev_login(vha
, fcport
, &next_loopid
);
3467 list_move_tail(&fcport
->list
, &vha
->vp_fcports
);
3471 /* Free all new device structures not processed. */
3472 list_for_each_entry_safe(fcport
, fcptemp
, &new_fcports
, list
) {
3473 list_del(&fcport
->list
);
3478 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
3479 "Configure fabric error exit rval=%d.\n", rval
);
3486 * qla2x00_find_all_fabric_devs
3489 * ha = adapter block pointer.
3490 * dev = database device entry pointer.
3499 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
,
3500 struct list_head
*new_fcports
)
3504 fc_port_t
*fcport
, *new_fcport
, *fcptemp
;
3509 int first_dev
, last_dev
;
3510 port_id_t wrap
= {}, nxt_d_id
;
3511 struct qla_hw_data
*ha
= vha
->hw
;
3512 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
3516 /* Try GID_PT to get device list, else GAN. */
3518 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
3523 ql_dbg(ql_dbg_disc
, vha
, 0x2054,
3524 "GID_PT allocations failed, fallback on GA_NXT.\n");
3526 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
3527 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
3529 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
3531 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
3533 } else if (ql2xiidmaenable
&&
3534 qla2x00_gfpn_id(vha
, swl
) == QLA_SUCCESS
) {
3535 qla2x00_gpsc(vha
, swl
);
3538 /* If other queries succeeded probe for FC-4 type */
3540 qla2x00_gff_id(vha
, swl
);
3544 /* Allocate temporary fcport for any new fcports discovered. */
3545 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3546 if (new_fcport
== NULL
) {
3547 ql_log(ql_log_warn
, vha
, 0x205e,
3548 "Failed to allocate memory for fcport.\n");
3549 return (QLA_MEMORY_ALLOC_FAILED
);
3551 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3552 /* Set start port ID scan at adapter ID. */
3556 /* Starting free loop ID. */
3557 loop_id
= ha
->min_external_loopid
;
3558 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
3559 if (qla2x00_is_reserved_id(vha
, loop_id
))
3562 if (ha
->current_topology
== ISP_CFG_FL
&&
3563 (atomic_read(&vha
->loop_down_timer
) ||
3564 LOOP_TRANSITION(vha
))) {
3565 atomic_set(&vha
->loop_down_timer
, 0);
3566 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
3567 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
3573 wrap
.b24
= new_fcport
->d_id
.b24
;
3575 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
3576 memcpy(new_fcport
->node_name
,
3577 swl
[swl_idx
].node_name
, WWN_SIZE
);
3578 memcpy(new_fcport
->port_name
,
3579 swl
[swl_idx
].port_name
, WWN_SIZE
);
3580 memcpy(new_fcport
->fabric_port_name
,
3581 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
3582 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
3583 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
3585 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
3591 /* Send GA_NXT to the switch */
3592 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
3593 if (rval
!= QLA_SUCCESS
) {
3594 ql_log(ql_log_warn
, vha
, 0x2064,
3595 "SNS scan failed -- assuming "
3596 "zero-entry result.\n");
3597 list_for_each_entry_safe(fcport
, fcptemp
,
3598 new_fcports
, list
) {
3599 list_del(&fcport
->list
);
3607 /* If wrap on switch device list, exit. */
3609 wrap
.b24
= new_fcport
->d_id
.b24
;
3611 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
3612 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
3613 "Device wrap (%02x%02x%02x).\n",
3614 new_fcport
->d_id
.b
.domain
,
3615 new_fcport
->d_id
.b
.area
,
3616 new_fcport
->d_id
.b
.al_pa
);
3620 /* Bypass if same physical adapter. */
3621 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
3624 /* Bypass virtual ports of the same host. */
3625 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
3628 /* Bypass if same domain and area of adapter. */
3629 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
3630 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
3634 /* Bypass reserved domain fields. */
3635 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
3638 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
3639 if (ql2xgffidenable
&&
3640 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
3641 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
3644 /* Locate matching device in database. */
3646 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
3647 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
3651 fcport
->scan_state
= QLA_FCPORT_FOUND
;
3655 /* Update port state. */
3656 memcpy(fcport
->fabric_port_name
,
3657 new_fcport
->fabric_port_name
, WWN_SIZE
);
3658 fcport
->fp_speed
= new_fcport
->fp_speed
;
3661 * If address the same and state FCS_ONLINE, nothing
3664 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
3665 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
3670 * If device was not a fabric device before.
3672 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
3673 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3674 qla2x00_clear_loop_id(fcport
);
3675 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
3681 * Port ID changed or device was marked to be updated;
3682 * Log it out if still logged in and mark it for
3685 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
3686 fcport
->flags
|= FCF_LOGIN_NEEDED
;
3687 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
3688 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
3689 (fcport
->flags
& FCF_ASYNC_SENT
) == 0 &&
3690 fcport
->port_type
!= FCT_INITIATOR
&&
3691 fcport
->port_type
!= FCT_BROADCAST
) {
3692 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3693 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3694 fcport
->d_id
.b
.al_pa
);
3695 qla2x00_clear_loop_id(fcport
);
3703 /* If device was not in our fcports list, then add it. */
3704 list_add_tail(&new_fcport
->list
, new_fcports
);
3706 /* Allocate a new replacement fcport. */
3707 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
3708 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
3709 if (new_fcport
== NULL
) {
3710 ql_log(ql_log_warn
, vha
, 0x2066,
3711 "Memory allocation failed for fcport.\n");
3712 return (QLA_MEMORY_ALLOC_FAILED
);
3714 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
3715 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
3724 * qla2x00_find_new_loop_id
3725 * Scan through our port list and find a new usable loop ID.
3728 * ha: adapter state pointer.
3729 * dev: port structure pointer.
3732 * qla2x00 local function return status code.
3738 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
3741 struct qla_hw_data
*ha
= vha
->hw
;
3742 unsigned long flags
= 0;
3746 spin_lock_irqsave(&ha
->vport_slock
, flags
);
3748 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
3750 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
3751 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
3752 dev
->loop_id
= FC_NO_LOOP_ID
;
3753 rval
= QLA_FUNCTION_FAILED
;
3755 set_bit(dev
->loop_id
, ha
->loop_id_map
);
3757 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
3759 if (rval
== QLA_SUCCESS
)
3760 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
3761 "Assigning new loopid=%x, portid=%x.\n",
3762 dev
->loop_id
, dev
->d_id
.b24
);
3764 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
3765 "No loop_id's available, portid=%x.\n",
3772 * qla2x00_fabric_dev_login
3773 * Login fabric target device and update FC port database.
3776 * ha: adapter state pointer.
3777 * fcport: port structure list pointer.
3778 * next_loopid: contains value of a new loop ID that can be used
3779 * by the next login attempt.
3782 * qla2x00 local function return status code.
3788 qla2x00_fabric_dev_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3789 uint16_t *next_loopid
)
3794 struct qla_hw_data
*ha
= vha
->hw
;
3799 if (IS_ALOGIO_CAPABLE(ha
)) {
3800 if (fcport
->flags
& FCF_ASYNC_SENT
)
3802 fcport
->flags
|= FCF_ASYNC_SENT
;
3803 rval
= qla2x00_post_async_login_work(vha
, fcport
, NULL
);
3808 fcport
->flags
&= ~FCF_ASYNC_SENT
;
3809 rval
= qla2x00_fabric_login(vha
, fcport
, next_loopid
);
3810 if (rval
== QLA_SUCCESS
) {
3811 /* Send an ADISC to FCP2 devices.*/
3813 if (fcport
->flags
& FCF_FCP2_DEVICE
)
3815 rval
= qla2x00_get_port_database(vha
, fcport
, opts
);
3816 if (rval
!= QLA_SUCCESS
) {
3817 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3818 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3819 fcport
->d_id
.b
.al_pa
);
3820 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3822 qla2x00_update_fcport(vha
, fcport
);
3826 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3833 * qla2x00_fabric_login
3834 * Issue fabric login command.
3837 * ha = adapter block pointer.
3838 * device = pointer to FC device type structure.
3841 * 0 - Login successfully
3843 * 2 - Initiator device
3847 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
3848 uint16_t *next_loopid
)
3852 uint16_t tmp_loopid
;
3853 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3854 struct qla_hw_data
*ha
= vha
->hw
;
3860 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
3861 "Trying Fabric Login w/loop id 0x%04x for port "
3863 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3864 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
3866 /* Login fcport on switch. */
3867 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
3868 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3869 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
3870 if (rval
!= QLA_SUCCESS
) {
3873 if (mb
[0] == MBS_PORT_ID_USED
) {
3875 * Device has another loop ID. The firmware team
3876 * recommends the driver perform an implicit login with
3877 * the specified ID again. The ID we just used is save
3878 * here so we return with an ID that can be tried by
3882 tmp_loopid
= fcport
->loop_id
;
3883 fcport
->loop_id
= mb
[1];
3885 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
3886 "Fabric Login: port in use - next loop "
3887 "id=0x%04x, port id= %02x%02x%02x.\n",
3888 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
3889 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
3891 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
3896 /* A retry occurred before. */
3897 *next_loopid
= tmp_loopid
;
3900 * No retry occurred before. Just increment the
3901 * ID value for next login.
3903 *next_loopid
= (fcport
->loop_id
+ 1);
3906 if (mb
[1] & BIT_0
) {
3907 fcport
->port_type
= FCT_INITIATOR
;
3909 fcport
->port_type
= FCT_TARGET
;
3910 if (mb
[1] & BIT_1
) {
3911 fcport
->flags
|= FCF_FCP2_DEVICE
;
3916 fcport
->supported_classes
|= FC_COS_CLASS2
;
3918 fcport
->supported_classes
|= FC_COS_CLASS3
;
3920 if (IS_FWI2_CAPABLE(ha
)) {
3923 FCF_CONF_COMP_SUPPORTED
;
3928 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
3930 * Loop ID already used, try next loop ID.
3933 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
3934 if (rval
!= QLA_SUCCESS
) {
3935 /* Ran out of loop IDs to use */
3938 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
3940 * Firmware possibly timed out during login. If NO
3941 * retries are left to do then the device is declared
3944 *next_loopid
= fcport
->loop_id
;
3945 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3946 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3947 fcport
->d_id
.b
.al_pa
);
3948 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
3954 * unrecoverable / not handled error
3956 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
3957 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
3958 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
3959 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
3960 fcport
->loop_id
, jiffies
);
3962 *next_loopid
= fcport
->loop_id
;
3963 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
3964 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
3965 fcport
->d_id
.b
.al_pa
);
3966 qla2x00_clear_loop_id(fcport
);
3967 fcport
->login_retry
= 0;
3978 * qla2x00_local_device_login
3979 * Issue local device login command.
3982 * ha = adapter block pointer.
3983 * loop_id = loop id of device to login to.
3985 * Returns (Where's the #define!!!!):
3986 * 0 - Login successfully
3991 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
3994 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
3996 memset(mb
, 0, sizeof(mb
));
3997 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
3998 if (rval
== QLA_SUCCESS
) {
3999 /* Interrogate mailbox registers for any errors */
4000 if (mb
[0] == MBS_COMMAND_ERROR
)
4002 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
4003 /* device not in PCB table */
4011 * qla2x00_loop_resync
4012 * Resync with fibre channel devices.
4015 * ha = adapter block pointer.
4021 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
4023 int rval
= QLA_SUCCESS
;
4025 struct req_que
*req
;
4026 struct rsp_que
*rsp
;
4028 if (vha
->hw
->flags
.cpu_affinity_enabled
)
4029 req
= vha
->hw
->req_q_map
[0];
4034 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4035 if (vha
->flags
.online
) {
4036 if (!(rval
= qla2x00_fw_ready(vha
))) {
4037 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4040 if (!IS_QLAFX00(vha
->hw
)) {
4042 * Issue a marker after FW becomes
4045 qla2x00_marker(vha
, req
, rsp
, 0, 0,
4047 vha
->marker_needed
= 0;
4050 /* Remap devices on Loop. */
4051 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4053 if (IS_QLAFX00(vha
->hw
))
4054 qlafx00_configure_devices(vha
);
4056 qla2x00_configure_loop(vha
);
4059 } while (!atomic_read(&vha
->loop_down_timer
) &&
4060 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4061 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4066 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4067 return (QLA_FUNCTION_FAILED
);
4070 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
4071 "%s *** FAILED ***.\n", __func__
);
4077 * qla2x00_perform_loop_resync
4078 * Description: This function will set the appropriate flags and call
4079 * qla2x00_loop_resync. If successful loop will be resynced
4080 * Arguments : scsi_qla_host_t pointer
4081 * returm : Success or Failure
4084 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
4088 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
4089 /*Configure the flags so that resync happens properly*/
4090 atomic_set(&ha
->loop_down_timer
, 0);
4091 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
4092 atomic_set(&ha
->loop_state
, LOOP_UP
);
4093 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
4094 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
4095 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
4097 rval
= qla2x00_loop_resync(ha
);
4099 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
4101 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
4108 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
4111 struct scsi_qla_host
*vha
;
4112 struct qla_hw_data
*ha
= base_vha
->hw
;
4113 unsigned long flags
;
4115 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4116 /* Go with deferred removal of rport references. */
4117 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
4118 atomic_inc(&vha
->vref_count
);
4119 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4120 if (fcport
->drport
&&
4121 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
4122 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4123 qla2x00_rport_del(fcport
);
4124 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4127 atomic_dec(&vha
->vref_count
);
4129 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4132 /* Assumes idc_lock always held on entry */
4134 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
4136 struct qla_hw_data
*ha
= vha
->hw
;
4137 uint32_t drv_presence
, drv_presence_mask
;
4138 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
4139 uint32_t class_type_mask
= 0x3;
4140 uint16_t fcoe_other_function
= 0xffff, i
;
4142 if (IS_QLA8044(ha
)) {
4143 drv_presence
= qla8044_rd_direct(vha
,
4144 QLA8044_CRB_DRV_ACTIVE_INDEX
);
4145 dev_part_info1
= qla8044_rd_direct(vha
,
4146 QLA8044_CRB_DEV_PART_INFO_INDEX
);
4147 dev_part_info2
= qla8044_rd_direct(vha
,
4148 QLA8044_CRB_DEV_PART_INFO2
);
4150 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
4151 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
4152 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
4154 for (i
= 0; i
< 8; i
++) {
4155 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
4156 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
4157 (i
!= ha
->portnum
)) {
4158 fcoe_other_function
= i
;
4162 if (fcoe_other_function
== 0xffff) {
4163 for (i
= 0; i
< 8; i
++) {
4164 class_type
= ((dev_part_info2
>> (i
* 4)) &
4166 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
4167 ((i
+ 8) != ha
->portnum
)) {
4168 fcoe_other_function
= i
+ 8;
4174 * Prepare drv-presence mask based on fcoe functions present.
4175 * However consider only valid physical fcoe function numbers (0-15).
4177 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
4178 ((fcoe_other_function
== 0xffff) ?
4179 0 : (1 << (fcoe_other_function
))));
4181 /* We are the reset owner iff:
4182 * - No other protocol drivers present.
4183 * - This is the lowest among fcoe functions. */
4184 if (!(drv_presence
& drv_presence_mask
) &&
4185 (ha
->portnum
< fcoe_other_function
)) {
4186 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
4187 "This host is Reset owner.\n");
4188 ha
->flags
.nic_core_reset_owner
= 1;
4193 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
4195 int rval
= QLA_SUCCESS
;
4196 struct qla_hw_data
*ha
= vha
->hw
;
4199 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
4200 if (rval
== QLA_SUCCESS
) {
4201 drv_ack
|= (1 << ha
->portnum
);
4202 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
4209 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
4211 int rval
= QLA_SUCCESS
;
4212 struct qla_hw_data
*ha
= vha
->hw
;
4215 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
4216 if (rval
== QLA_SUCCESS
) {
4217 drv_ack
&= ~(1 << ha
->portnum
);
4218 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
4225 qla83xx_dev_state_to_string(uint32_t dev_state
)
4227 switch (dev_state
) {
4228 case QLA8XXX_DEV_COLD
:
4229 return "COLD/RE-INIT";
4230 case QLA8XXX_DEV_INITIALIZING
:
4231 return "INITIALIZING";
4232 case QLA8XXX_DEV_READY
:
4234 case QLA8XXX_DEV_NEED_RESET
:
4235 return "NEED RESET";
4236 case QLA8XXX_DEV_NEED_QUIESCENT
:
4237 return "NEED QUIESCENT";
4238 case QLA8XXX_DEV_FAILED
:
4240 case QLA8XXX_DEV_QUIESCENT
:
4247 /* Assumes idc-lock always held on entry */
4249 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
4251 struct qla_hw_data
*ha
= vha
->hw
;
4252 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
4254 switch (audit_type
) {
4255 case IDC_AUDIT_TIMESTAMP
:
4256 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
4257 idc_audit_reg
= (ha
->portnum
) |
4258 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
4259 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
4262 case IDC_AUDIT_COMPLETION
:
4263 duration_secs
= ((jiffies_to_msecs(jiffies
) -
4264 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
4265 idc_audit_reg
= (ha
->portnum
) |
4266 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
4267 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
4271 ql_log(ql_log_warn
, vha
, 0xb078,
4272 "Invalid audit type specified.\n");
4277 /* Assumes idc_lock always held on entry */
4279 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
4281 struct qla_hw_data
*ha
= vha
->hw
;
4282 uint32_t idc_control
, dev_state
;
4284 __qla83xx_get_idc_control(vha
, &idc_control
);
4285 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
4286 ql_log(ql_log_info
, vha
, 0xb080,
4287 "NIC Core reset has been disabled. idc-control=0x%x\n",
4289 return QLA_FUNCTION_FAILED
;
4292 /* Set NEED-RESET iff in READY state and we are the reset-owner */
4293 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
4294 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
4295 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
4296 QLA8XXX_DEV_NEED_RESET
);
4297 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
4298 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
4300 const char *state
= qla83xx_dev_state_to_string(dev_state
);
4301 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
4303 /* SV: XXX: Is timeout required here? */
4304 /* Wait for IDC state change READY -> NEED_RESET */
4305 while (dev_state
== QLA8XXX_DEV_READY
) {
4306 qla83xx_idc_unlock(vha
, 0);
4308 qla83xx_idc_lock(vha
, 0);
4309 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
4313 /* Send IDC ack by writing to drv-ack register */
4314 __qla83xx_set_drv_ack(vha
);
4320 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
4322 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
4326 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
4328 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
4332 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
4334 uint32_t drv_presence
= 0;
4335 struct qla_hw_data
*ha
= vha
->hw
;
4337 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
4338 if (drv_presence
& (1 << ha
->portnum
))
4341 return QLA_TEST_FAILED
;
4345 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
4347 int rval
= QLA_SUCCESS
;
4348 struct qla_hw_data
*ha
= vha
->hw
;
4350 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
4351 "Entered %s().\n", __func__
);
4353 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
4354 ql_log(ql_log_warn
, vha
, 0xb059,
4355 "Device in unrecoverable FAILED state.\n");
4356 return QLA_FUNCTION_FAILED
;
4359 qla83xx_idc_lock(vha
, 0);
4361 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
4362 ql_log(ql_log_warn
, vha
, 0xb05a,
4363 "Function=0x%x has been removed from IDC participation.\n",
4365 rval
= QLA_FUNCTION_FAILED
;
4369 qla83xx_reset_ownership(vha
);
4371 rval
= qla83xx_initiating_reset(vha
);
4374 * Perform reset if we are the reset-owner,
4375 * else wait till IDC state changes to READY/FAILED.
4377 if (rval
== QLA_SUCCESS
) {
4378 rval
= qla83xx_idc_state_handler(vha
);
4380 if (rval
== QLA_SUCCESS
)
4381 ha
->flags
.nic_core_hung
= 0;
4382 __qla83xx_clear_drv_ack(vha
);
4386 qla83xx_idc_unlock(vha
, 0);
4388 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
4394 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
4396 struct qla_hw_data
*ha
= vha
->hw
;
4397 int rval
= QLA_FUNCTION_FAILED
;
4399 if (!IS_MCTP_CAPABLE(ha
)) {
4400 /* This message can be removed from the final version */
4401 ql_log(ql_log_info
, vha
, 0x506d,
4402 "This board is not MCTP capable\n");
4406 if (!ha
->mctp_dump
) {
4407 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
4408 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
4410 if (!ha
->mctp_dump
) {
4411 ql_log(ql_log_warn
, vha
, 0x506e,
4412 "Failed to allocate memory for mctp dump\n");
4417 #define MCTP_DUMP_STR_ADDR 0x00000000
4418 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
4419 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
4420 if (rval
!= QLA_SUCCESS
) {
4421 ql_log(ql_log_warn
, vha
, 0x506f,
4422 "Failed to capture mctp dump\n");
4424 ql_log(ql_log_info
, vha
, 0x5070,
4425 "Mctp dump capture for host (%ld/%p).\n",
4426 vha
->host_no
, ha
->mctp_dump
);
4427 ha
->mctp_dumped
= 1;
4430 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
4431 ha
->flags
.nic_core_reset_hdlr_active
= 1;
4432 rval
= qla83xx_restart_nic_firmware(vha
);
4434 /* NIC Core reset failed. */
4435 ql_log(ql_log_warn
, vha
, 0x5071,
4436 "Failed to restart nic firmware\n");
4438 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
4439 "Restarted NIC firmware successfully.\n");
4440 ha
->flags
.nic_core_reset_hdlr_active
= 0;
4448 * qla2x00_quiesce_io
4449 * Description: This function will block the new I/Os
4450 * Its not aborting any I/Os as context
4451 * is not destroyed during quiescence
4452 * Arguments: scsi_qla_host_t
4456 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
4458 struct qla_hw_data
*ha
= vha
->hw
;
4459 struct scsi_qla_host
*vp
;
4461 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
4462 "Quiescing I/O - ha=%p.\n", ha
);
4464 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
4465 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
4466 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
4467 qla2x00_mark_all_devices_lost(vha
, 0);
4468 list_for_each_entry(vp
, &ha
->vp_list
, list
)
4469 qla2x00_mark_all_devices_lost(vp
, 0);
4471 if (!atomic_read(&vha
->loop_down_timer
))
4472 atomic_set(&vha
->loop_down_timer
,
4475 /* Wait for pending cmds to complete */
4476 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
4480 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
4482 struct qla_hw_data
*ha
= vha
->hw
;
4483 struct scsi_qla_host
*vp
;
4484 unsigned long flags
;
4487 /* For ISP82XX, driver waits for completion of the commands.
4488 * online flag should be set.
4490 if (!(IS_P3P_TYPE(ha
)))
4491 vha
->flags
.online
= 0;
4492 ha
->flags
.chip_reset_done
= 0;
4493 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4494 vha
->qla_stats
.total_isp_aborts
++;
4496 ql_log(ql_log_info
, vha
, 0x00af,
4497 "Performing ISP error recovery - ha=%p.\n", ha
);
4499 /* For ISP82XX, reset_chip is just disabling interrupts.
4500 * Driver waits for the completion of the commands.
4501 * the interrupts need to be enabled.
4503 if (!(IS_P3P_TYPE(ha
)))
4504 ha
->isp_ops
->reset_chip(vha
);
4506 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
4507 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
4508 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
4509 qla2x00_mark_all_devices_lost(vha
, 0);
4511 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4512 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4513 atomic_inc(&vp
->vref_count
);
4514 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4516 qla2x00_mark_all_devices_lost(vp
, 0);
4518 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4519 atomic_dec(&vp
->vref_count
);
4521 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4523 if (!atomic_read(&vha
->loop_down_timer
))
4524 atomic_set(&vha
->loop_down_timer
,
4528 /* Clear all async request states across all VPs. */
4529 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
4530 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
4531 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4532 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4533 atomic_inc(&vp
->vref_count
);
4534 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4536 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
4537 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
4539 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4540 atomic_dec(&vp
->vref_count
);
4542 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4544 if (!ha
->flags
.eeh_busy
) {
4545 /* Make sure for ISP 82XX IO DMA is complete */
4546 if (IS_P3P_TYPE(ha
)) {
4547 qla82xx_chip_reset_cleanup(vha
);
4548 ql_log(ql_log_info
, vha
, 0x00b4,
4549 "Done chip reset cleanup.\n");
4551 /* Done waiting for pending commands.
4552 * Reset the online flag.
4554 vha
->flags
.online
= 0;
4557 /* Requeue all commands in outstanding command list. */
4558 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
4564 * Resets ISP and aborts all outstanding commands.
4567 * ha = adapter block pointer.
4573 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
4577 struct qla_hw_data
*ha
= vha
->hw
;
4578 struct scsi_qla_host
*vp
;
4579 struct req_que
*req
= ha
->req_q_map
[0];
4580 unsigned long flags
;
4582 if (vha
->flags
.online
) {
4583 qla2x00_abort_isp_cleanup(vha
);
4585 if (IS_QLA8031(ha
)) {
4586 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
4587 "Clearing fcoe driver presence.\n");
4588 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
4589 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
4590 "Error while clearing DRV-Presence.\n");
4593 if (unlikely(pci_channel_offline(ha
->pdev
) &&
4594 ha
->flags
.pci_channel_io_perm_failure
)) {
4595 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4600 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
4602 ha
->isp_ops
->nvram_config(vha
);
4604 if (!qla2x00_restart_isp(vha
)) {
4605 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4607 if (!atomic_read(&vha
->loop_down_timer
)) {
4609 * Issue marker command only when we are going
4610 * to start the I/O .
4612 vha
->marker_needed
= 1;
4615 vha
->flags
.online
= 1;
4617 ha
->isp_ops
->enable_intrs(ha
);
4619 ha
->isp_abort_cnt
= 0;
4620 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4622 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
4623 qla2x00_get_fw_version(vha
);
4625 ha
->flags
.fce_enabled
= 1;
4627 fce_calc_size(ha
->fce_bufs
));
4628 rval
= qla2x00_enable_fce_trace(vha
,
4629 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
4632 ql_log(ql_log_warn
, vha
, 0x8033,
4633 "Unable to reinitialize FCE "
4635 ha
->flags
.fce_enabled
= 0;
4640 memset(ha
->eft
, 0, EFT_SIZE
);
4641 rval
= qla2x00_enable_eft_trace(vha
,
4642 ha
->eft_dma
, EFT_NUM_BUFFERS
);
4644 ql_log(ql_log_warn
, vha
, 0x8034,
4645 "Unable to reinitialize EFT "
4649 } else { /* failed the ISP abort */
4650 vha
->flags
.online
= 1;
4651 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
4652 if (ha
->isp_abort_cnt
== 0) {
4653 ql_log(ql_log_fatal
, vha
, 0x8035,
4654 "ISP error recover failed - "
4655 "board disabled.\n");
4657 * The next call disables the board
4660 ha
->isp_ops
->reset_adapter(vha
);
4661 vha
->flags
.online
= 0;
4662 clear_bit(ISP_ABORT_RETRY
,
4665 } else { /* schedule another ISP abort */
4666 ha
->isp_abort_cnt
--;
4667 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
4668 "ISP abort - retry remaining %d.\n",
4673 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
4674 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
4675 "ISP error recovery - retrying (%d) "
4676 "more times.\n", ha
->isp_abort_cnt
);
4677 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
4685 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
4687 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4688 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
4690 atomic_inc(&vp
->vref_count
);
4691 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4693 qla2x00_vp_abort_isp(vp
);
4695 spin_lock_irqsave(&ha
->vport_slock
, flags
);
4696 atomic_dec(&vp
->vref_count
);
4699 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
4701 if (IS_QLA8031(ha
)) {
4702 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
4703 "Setting back fcoe driver presence.\n");
4704 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
4705 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
4706 "Error while setting DRV-Presence.\n");
4709 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
4717 * qla2x00_restart_isp
4718 * restarts the ISP after a reset
4721 * ha = adapter block pointer.
4727 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
4731 struct qla_hw_data
*ha
= vha
->hw
;
4732 struct req_que
*req
= ha
->req_q_map
[0];
4733 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4734 unsigned long flags
;
4736 /* If firmware needs to be loaded */
4737 if (qla2x00_isp_firmware(vha
)) {
4738 vha
->flags
.online
= 0;
4739 status
= ha
->isp_ops
->chip_diag(vha
);
4741 status
= qla2x00_setup_chip(vha
);
4744 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
4745 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
4746 ha
->flags
.chip_reset_done
= 1;
4747 /* Initialize the queues in use */
4748 qla25xx_init_queues(ha
);
4750 status
= qla2x00_fw_ready(vha
);
4752 ql_dbg(ql_dbg_taskm
, vha
, 0x8031,
4753 "Start configure loop status = %d.\n", status
);
4755 /* Issue a marker after FW becomes ready. */
4756 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
4758 vha
->flags
.online
= 1;
4761 * Process any ATIO queue entries that came in
4762 * while we weren't online.
4764 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4765 if (qla_tgt_mode_enabled(vha
))
4766 qlt_24xx_process_atio_queue(vha
);
4767 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4769 /* Wait at most MAX_TARGET RSCNs for a stable link. */
4772 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4773 qla2x00_configure_loop(vha
);
4775 } while (!atomic_read(&vha
->loop_down_timer
) &&
4776 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
4777 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
4781 /* if no cable then assume it's good */
4782 if ((vha
->device_flags
& DFLG_NO_CABLE
))
4785 ql_dbg(ql_dbg_taskm
, vha
, 0x8032,
4786 "Configure loop done, status = 0x%x.\n", status
);
4792 qla25xx_init_queues(struct qla_hw_data
*ha
)
4794 struct rsp_que
*rsp
= NULL
;
4795 struct req_que
*req
= NULL
;
4796 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
4800 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
4801 rsp
= ha
->rsp_q_map
[i
];
4803 rsp
->options
&= ~BIT_0
;
4804 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
4805 if (ret
!= QLA_SUCCESS
)
4806 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
4807 "%s Rsp que: %d init failed.\n",
4810 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
4811 "%s Rsp que: %d inited.\n",
4815 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
4816 req
= ha
->req_q_map
[i
];
4818 /* Clear outstanding commands array. */
4819 req
->options
&= ~BIT_0
;
4820 ret
= qla25xx_init_req_que(base_vha
, req
);
4821 if (ret
!= QLA_SUCCESS
)
4822 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
4823 "%s Req que: %d init failed.\n",
4826 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
4827 "%s Req que: %d inited.\n",
4835 * qla2x00_reset_adapter
4839 * ha = adapter block pointer.
4842 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
4844 unsigned long flags
= 0;
4845 struct qla_hw_data
*ha
= vha
->hw
;
4846 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4848 vha
->flags
.online
= 0;
4849 ha
->isp_ops
->disable_intrs(ha
);
4851 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4852 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
4853 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4854 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
4855 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
4856 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4860 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
4862 unsigned long flags
= 0;
4863 struct qla_hw_data
*ha
= vha
->hw
;
4864 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
4866 if (IS_P3P_TYPE(ha
))
4869 vha
->flags
.online
= 0;
4870 ha
->isp_ops
->disable_intrs(ha
);
4872 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4873 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
4874 RD_REG_DWORD(®
->hccr
);
4875 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
4876 RD_REG_DWORD(®
->hccr
);
4877 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4879 if (IS_NOPOLLING_TYPE(ha
))
4880 ha
->isp_ops
->enable_intrs(ha
);
4883 /* On sparc systems, obtain port and node WWN from firmware
4886 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
4887 struct nvram_24xx
*nv
)
4890 struct qla_hw_data
*ha
= vha
->hw
;
4891 struct pci_dev
*pdev
= ha
->pdev
;
4892 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4896 val
= of_get_property(dp
, "port-wwn", &len
);
4897 if (val
&& len
>= WWN_SIZE
)
4898 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4900 val
= of_get_property(dp
, "node-wwn", &len
);
4901 if (val
&& len
>= WWN_SIZE
)
4902 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4907 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
4910 struct init_cb_24xx
*icb
;
4911 struct nvram_24xx
*nv
;
4913 uint8_t *dptr1
, *dptr2
;
4916 struct qla_hw_data
*ha
= vha
->hw
;
4919 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4922 /* Determine NVRAM starting address. */
4923 if (ha
->port_no
== 0) {
4924 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
4925 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
4927 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
4928 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
4931 ha
->nvram_size
= sizeof(struct nvram_24xx
);
4932 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
4934 /* Get VPD data into cache */
4935 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
4936 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
4937 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
4939 /* Get NVRAM data into cache and calculate checksum. */
4940 dptr
= (uint32_t *)nv
;
4941 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
4943 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
4944 chksum
+= le32_to_cpu(*dptr
++);
4946 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
4947 "Contents of NVRAM\n");
4948 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
4949 (uint8_t *)nv
, ha
->nvram_size
);
4951 /* Bad NVRAM data, set defaults parameters. */
4952 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
4953 || nv
->id
[3] != ' ' ||
4954 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
4955 /* Reset NVRAM data. */
4956 ql_log(ql_log_warn
, vha
, 0x006b,
4957 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
4958 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
4959 ql_log(ql_log_warn
, vha
, 0x006c,
4960 "Falling back to functioning (yet invalid -- WWPN) "
4964 * Set default initialization control block.
4966 memset(nv
, 0, ha
->nvram_size
);
4967 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
4968 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
4969 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
4970 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
4971 nv
->exchange_count
= __constant_cpu_to_le16(0);
4972 nv
->hard_address
= __constant_cpu_to_le16(124);
4973 nv
->port_name
[0] = 0x21;
4974 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
4975 nv
->port_name
[2] = 0x00;
4976 nv
->port_name
[3] = 0xe0;
4977 nv
->port_name
[4] = 0x8b;
4978 nv
->port_name
[5] = 0x1c;
4979 nv
->port_name
[6] = 0x55;
4980 nv
->port_name
[7] = 0x86;
4981 nv
->node_name
[0] = 0x20;
4982 nv
->node_name
[1] = 0x00;
4983 nv
->node_name
[2] = 0x00;
4984 nv
->node_name
[3] = 0xe0;
4985 nv
->node_name
[4] = 0x8b;
4986 nv
->node_name
[5] = 0x1c;
4987 nv
->node_name
[6] = 0x55;
4988 nv
->node_name
[7] = 0x86;
4989 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
4990 nv
->login_retry_count
= __constant_cpu_to_le16(8);
4991 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
4992 nv
->login_timeout
= __constant_cpu_to_le16(0);
4993 nv
->firmware_options_1
=
4994 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
4995 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
4996 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
4997 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
4998 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
4999 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5000 nv
->reset_delay
= 5;
5001 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5002 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5003 nv
->link_down_timeout
= __constant_cpu_to_le16(30);
5008 if (!qla_ini_mode_enabled(vha
)) {
5009 /* Don't enable full login after initial LIP */
5010 nv
->firmware_options_1
&= __constant_cpu_to_le32(~BIT_13
);
5011 /* Don't enable LIP full login for initiator */
5012 nv
->host_p
&= __constant_cpu_to_le32(~BIT_10
);
5015 qlt_24xx_config_nvram_stage1(vha
, nv
);
5017 /* Reset Initialization control block */
5018 memset(icb
, 0, ha
->init_cb_size
);
5020 /* Copy 1st segment. */
5021 dptr1
= (uint8_t *)icb
;
5022 dptr2
= (uint8_t *)&nv
->version
;
5023 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5025 *dptr1
++ = *dptr2
++;
5027 icb
->login_retry_count
= nv
->login_retry_count
;
5028 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
5030 /* Copy 2nd segment. */
5031 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5032 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5033 cnt
= (uint8_t *)&icb
->reserved_3
-
5034 (uint8_t *)&icb
->interrupt_delay_timer
;
5036 *dptr1
++ = *dptr2
++;
5039 * Setup driver NVRAM options.
5041 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
5044 qlt_24xx_config_nvram_stage2(vha
, icb
);
5046 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
5047 /* Use alternate WWN? */
5048 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
5049 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
5052 /* Prepare nodename */
5053 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
5055 * Firmware will apply the following mask if the nodename was
5058 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
5059 icb
->node_name
[0] &= 0xF0;
5062 /* Set host adapter parameters. */
5063 ha
->flags
.disable_risc_code_load
= 0;
5064 ha
->flags
.enable_lip_reset
= 0;
5065 ha
->flags
.enable_lip_full_login
=
5066 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
5067 ha
->flags
.enable_target_reset
=
5068 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
5069 ha
->flags
.enable_led_scheme
= 0;
5070 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
5072 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
5073 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
5075 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
5076 sizeof(ha
->fw_seriallink_options24
));
5078 /* save HBA serial number */
5079 ha
->serial0
= icb
->port_name
[5];
5080 ha
->serial1
= icb
->port_name
[6];
5081 ha
->serial2
= icb
->port_name
[7];
5082 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
5083 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
5085 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5087 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
5089 /* Set minimum login_timeout to 4 seconds. */
5090 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
5091 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
5092 if (le16_to_cpu(nv
->login_timeout
) < 4)
5093 nv
->login_timeout
= __constant_cpu_to_le16(4);
5094 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
5095 icb
->login_timeout
= nv
->login_timeout
;
5097 /* Set minimum RATOV to 100 tenths of a second. */
5100 ha
->loop_reset_delay
= nv
->reset_delay
;
5102 /* Link Down Timeout = 0:
5104 * When Port Down timer expires we will start returning
5105 * I/O's to OS with "DID_NO_CONNECT".
5107 * Link Down Timeout != 0:
5109 * The driver waits for the link to come up after link down
5110 * before returning I/Os to OS with "DID_NO_CONNECT".
5112 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
5113 ha
->loop_down_abort_time
=
5114 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
5116 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
5117 ha
->loop_down_abort_time
=
5118 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
5121 /* Need enough time to try and get the port back. */
5122 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
5123 if (qlport_down_retry
)
5124 ha
->port_down_retry_count
= qlport_down_retry
;
5126 /* Set login_retry_count */
5127 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
5128 if (ha
->port_down_retry_count
==
5129 le16_to_cpu(nv
->port_down_retry_count
) &&
5130 ha
->port_down_retry_count
> 3)
5131 ha
->login_retry_count
= ha
->port_down_retry_count
;
5132 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
5133 ha
->login_retry_count
= ha
->port_down_retry_count
;
5134 if (ql2xloginretrycount
)
5135 ha
->login_retry_count
= ql2xloginretrycount
;
5138 if (!vha
->flags
.init_done
) {
5139 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
5140 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
5141 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
5142 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
5144 icb
->firmware_options_2
&= __constant_cpu_to_le32(
5145 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
5146 vha
->flags
.process_response_queue
= 0;
5147 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
5148 ha
->zio_mode
= QLA_ZIO_MODE_6
;
5150 ql_log(ql_log_info
, vha
, 0x006f,
5151 "ZIO mode %d enabled; timer delay (%d us).\n",
5152 ha
->zio_mode
, ha
->zio_timer
* 100);
5154 icb
->firmware_options_2
|= cpu_to_le32(
5155 (uint32_t)ha
->zio_mode
);
5156 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
5157 vha
->flags
.process_response_queue
= 1;
5161 ql_log(ql_log_warn
, vha
, 0x0070,
5162 "NVRAM configuration failed.\n");
5168 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
5171 int rval
= QLA_SUCCESS
;
5172 int segments
, fragment
;
5173 uint32_t *dcode
, dlen
;
5177 struct qla_hw_data
*ha
= vha
->hw
;
5178 struct req_que
*req
= ha
->req_q_map
[0];
5180 ql_dbg(ql_dbg_init
, vha
, 0x008b,
5181 "FW: Loading firmware from flash (%x).\n", faddr
);
5185 segments
= FA_RISC_CODE_SEGMENTS
;
5186 dcode
= (uint32_t *)req
->ring
;
5189 /* Validate firmware image by checking version. */
5190 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
5191 for (i
= 0; i
< 4; i
++)
5192 dcode
[i
] = be32_to_cpu(dcode
[i
]);
5193 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
5194 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
5195 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
5197 ql_log(ql_log_fatal
, vha
, 0x008c,
5198 "Unable to verify the integrity of flash firmware "
5200 ql_log(ql_log_fatal
, vha
, 0x008d,
5201 "Firmware data: %08x %08x %08x %08x.\n",
5202 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
5204 return QLA_FUNCTION_FAILED
;
5207 while (segments
&& rval
== QLA_SUCCESS
) {
5208 /* Read segment's load information. */
5209 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
5211 risc_addr
= be32_to_cpu(dcode
[2]);
5212 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
5213 risc_size
= be32_to_cpu(dcode
[3]);
5216 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
5217 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
5218 if (dlen
> risc_size
)
5221 ql_dbg(ql_dbg_init
, vha
, 0x008e,
5222 "Loading risc segment@ risc addr %x "
5223 "number of dwords 0x%x offset 0x%x.\n",
5224 risc_addr
, dlen
, faddr
);
5226 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
5227 for (i
= 0; i
< dlen
; i
++)
5228 dcode
[i
] = swab32(dcode
[i
]);
5230 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
5233 ql_log(ql_log_fatal
, vha
, 0x008f,
5234 "Failed to load segment %d of firmware.\n",
5249 if (!IS_QLA27XX(ha
))
5252 if (ha
->fw_dump_template
)
5253 vfree(ha
->fw_dump_template
);
5254 ha
->fw_dump_template
= NULL
;
5255 ha
->fw_dump_template_len
= 0;
5257 ql_dbg(ql_dbg_init
, vha
, 0x0161,
5258 "Loading fwdump template from %x\n", faddr
);
5259 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
5260 risc_size
= be32_to_cpu(dcode
[2]);
5261 ql_dbg(ql_dbg_init
, vha
, 0x0162,
5262 "-> array size %x dwords\n", risc_size
);
5263 if (risc_size
== 0 || risc_size
== ~0)
5264 goto default_template
;
5266 dlen
= (risc_size
- 8) * sizeof(*dcode
);
5267 ql_dbg(ql_dbg_init
, vha
, 0x0163,
5268 "-> template allocating %x bytes...\n", dlen
);
5269 ha
->fw_dump_template
= vmalloc(dlen
);
5270 if (!ha
->fw_dump_template
) {
5271 ql_log(ql_log_warn
, vha
, 0x0164,
5272 "Failed fwdump template allocate %x bytes.\n", risc_size
);
5273 goto default_template
;
5278 dcode
= ha
->fw_dump_template
;
5279 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
5280 for (i
= 0; i
< risc_size
; i
++)
5281 dcode
[i
] = le32_to_cpu(dcode
[i
]);
5283 if (!qla27xx_fwdt_template_valid(dcode
)) {
5284 ql_log(ql_log_warn
, vha
, 0x0165,
5285 "Failed fwdump template validate\n");
5286 goto default_template
;
5289 dlen
= qla27xx_fwdt_template_size(dcode
);
5290 ql_dbg(ql_dbg_init
, vha
, 0x0166,
5291 "-> template size %x bytes\n", dlen
);
5292 if (dlen
> risc_size
* sizeof(*dcode
)) {
5293 ql_log(ql_log_warn
, vha
, 0x0167,
5294 "Failed fwdump template exceeds array by %x bytes\n",
5295 (uint32_t)(dlen
- risc_size
* sizeof(*dcode
)));
5296 goto default_template
;
5298 ha
->fw_dump_template_len
= dlen
;
5302 ql_log(ql_log_warn
, vha
, 0x0168, "Using default fwdump template\n");
5303 if (ha
->fw_dump_template
)
5304 vfree(ha
->fw_dump_template
);
5305 ha
->fw_dump_template
= NULL
;
5306 ha
->fw_dump_template_len
= 0;
5308 dlen
= qla27xx_fwdt_template_default_size();
5309 ql_dbg(ql_dbg_init
, vha
, 0x0169,
5310 "-> template allocating %x bytes...\n", dlen
);
5311 ha
->fw_dump_template
= vmalloc(dlen
);
5312 if (!ha
->fw_dump_template
) {
5313 ql_log(ql_log_warn
, vha
, 0x016a,
5314 "Failed fwdump template allocate %x bytes.\n", risc_size
);
5315 goto failed_template
;
5318 dcode
= ha
->fw_dump_template
;
5319 risc_size
= dlen
/ sizeof(*dcode
);
5320 memcpy(dcode
, qla27xx_fwdt_template_default(), dlen
);
5321 for (i
= 0; i
< risc_size
; i
++)
5322 dcode
[i
] = be32_to_cpu(dcode
[i
]);
5324 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
5325 ql_log(ql_log_warn
, vha
, 0x016b,
5326 "Failed fwdump template validate\n");
5327 goto failed_template
;
5330 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
5331 ql_dbg(ql_dbg_init
, vha
, 0x016c,
5332 "-> template size %x bytes\n", dlen
);
5333 ha
->fw_dump_template_len
= dlen
;
5337 ql_log(ql_log_warn
, vha
, 0x016d, "Failed default fwdump template\n");
5338 if (ha
->fw_dump_template
)
5339 vfree(ha
->fw_dump_template
);
5340 ha
->fw_dump_template
= NULL
;
5341 ha
->fw_dump_template_len
= 0;
5345 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
5348 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
5352 uint16_t *wcode
, *fwcode
;
5353 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
5354 struct fw_blob
*blob
;
5355 struct qla_hw_data
*ha
= vha
->hw
;
5356 struct req_que
*req
= ha
->req_q_map
[0];
5358 /* Load firmware blob. */
5359 blob
= qla2x00_request_firmware(vha
);
5361 ql_log(ql_log_info
, vha
, 0x0083,
5362 "Fimware image unavailable.\n");
5363 ql_log(ql_log_info
, vha
, 0x0084,
5364 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
5365 return QLA_FUNCTION_FAILED
;
5370 wcode
= (uint16_t *)req
->ring
;
5372 fwcode
= (uint16_t *)blob
->fw
->data
;
5375 /* Validate firmware image by checking version. */
5376 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
5377 ql_log(ql_log_fatal
, vha
, 0x0085,
5378 "Unable to verify integrity of firmware image (%Zd).\n",
5380 goto fail_fw_integrity
;
5382 for (i
= 0; i
< 4; i
++)
5383 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
5384 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
5385 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
5386 wcode
[2] == 0 && wcode
[3] == 0)) {
5387 ql_log(ql_log_fatal
, vha
, 0x0086,
5388 "Unable to verify integrity of firmware image.\n");
5389 ql_log(ql_log_fatal
, vha
, 0x0087,
5390 "Firmware data: %04x %04x %04x %04x.\n",
5391 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
5392 goto fail_fw_integrity
;
5396 while (*seg
&& rval
== QLA_SUCCESS
) {
5398 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
5399 risc_size
= be16_to_cpu(fwcode
[3]);
5401 /* Validate firmware image size. */
5402 fwclen
+= risc_size
* sizeof(uint16_t);
5403 if (blob
->fw
->size
< fwclen
) {
5404 ql_log(ql_log_fatal
, vha
, 0x0088,
5405 "Unable to verify integrity of firmware image "
5406 "(%Zd).\n", blob
->fw
->size
);
5407 goto fail_fw_integrity
;
5411 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
5412 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
5413 if (wlen
> risc_size
)
5415 ql_dbg(ql_dbg_init
, vha
, 0x0089,
5416 "Loading risc segment@ risc addr %x number of "
5417 "words 0x%x.\n", risc_addr
, wlen
);
5419 for (i
= 0; i
< wlen
; i
++)
5420 wcode
[i
] = swab16(fwcode
[i
]);
5422 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
5425 ql_log(ql_log_fatal
, vha
, 0x008a,
5426 "Failed to load segment %d of firmware.\n",
5443 return QLA_FUNCTION_FAILED
;
5447 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
5450 int segments
, fragment
;
5451 uint32_t *dcode
, dlen
;
5455 struct fw_blob
*blob
;
5456 const uint32_t *fwcode
;
5458 struct qla_hw_data
*ha
= vha
->hw
;
5459 struct req_que
*req
= ha
->req_q_map
[0];
5461 /* Load firmware blob. */
5462 blob
= qla2x00_request_firmware(vha
);
5464 ql_log(ql_log_warn
, vha
, 0x0090,
5465 "Fimware image unavailable.\n");
5466 ql_log(ql_log_warn
, vha
, 0x0091,
5467 "Firmware images can be retrieved from: "
5470 return QLA_FUNCTION_FAILED
;
5473 ql_dbg(ql_dbg_init
, vha
, 0x0092,
5474 "FW: Loading via request-firmware.\n");
5478 segments
= FA_RISC_CODE_SEGMENTS
;
5479 dcode
= (uint32_t *)req
->ring
;
5481 fwcode
= (uint32_t *)blob
->fw
->data
;
5484 /* Validate firmware image by checking version. */
5485 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
5486 ql_log(ql_log_fatal
, vha
, 0x0093,
5487 "Unable to verify integrity of firmware image (%Zd).\n",
5489 return QLA_FUNCTION_FAILED
;
5491 for (i
= 0; i
< 4; i
++)
5492 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
5493 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
5494 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
5495 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
5497 ql_log(ql_log_fatal
, vha
, 0x0094,
5498 "Unable to verify integrity of firmware image (%Zd).\n",
5500 ql_log(ql_log_fatal
, vha
, 0x0095,
5501 "Firmware data: %08x %08x %08x %08x.\n",
5502 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
5503 return QLA_FUNCTION_FAILED
;
5506 while (segments
&& rval
== QLA_SUCCESS
) {
5507 risc_addr
= be32_to_cpu(fwcode
[2]);
5508 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
5509 risc_size
= be32_to_cpu(fwcode
[3]);
5511 /* Validate firmware image size. */
5512 fwclen
+= risc_size
* sizeof(uint32_t);
5513 if (blob
->fw
->size
< fwclen
) {
5514 ql_log(ql_log_fatal
, vha
, 0x0096,
5515 "Unable to verify integrity of firmware image "
5516 "(%Zd).\n", blob
->fw
->size
);
5517 return QLA_FUNCTION_FAILED
;
5521 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
5522 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
5523 if (dlen
> risc_size
)
5526 ql_dbg(ql_dbg_init
, vha
, 0x0097,
5527 "Loading risc segment@ risc addr %x "
5528 "number of dwords 0x%x.\n", risc_addr
, dlen
);
5530 for (i
= 0; i
< dlen
; i
++)
5531 dcode
[i
] = swab32(fwcode
[i
]);
5533 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
5536 ql_log(ql_log_fatal
, vha
, 0x0098,
5537 "Failed to load segment %d of firmware.\n",
5552 if (!IS_QLA27XX(ha
))
5555 if (ha
->fw_dump_template
)
5556 vfree(ha
->fw_dump_template
);
5557 ha
->fw_dump_template
= NULL
;
5558 ha
->fw_dump_template_len
= 0;
5560 ql_dbg(ql_dbg_init
, vha
, 0x171,
5561 "Loading fwdump template from %x\n",
5562 (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
));
5563 risc_size
= be32_to_cpu(fwcode
[2]);
5564 ql_dbg(ql_dbg_init
, vha
, 0x172,
5565 "-> array size %x dwords\n", risc_size
);
5566 if (risc_size
== 0 || risc_size
== ~0)
5567 goto default_template
;
5569 dlen
= (risc_size
- 8) * sizeof(*fwcode
);
5570 ql_dbg(ql_dbg_init
, vha
, 0x0173,
5571 "-> template allocating %x bytes...\n", dlen
);
5572 ha
->fw_dump_template
= vmalloc(dlen
);
5573 if (!ha
->fw_dump_template
) {
5574 ql_log(ql_log_warn
, vha
, 0x0174,
5575 "Failed fwdump template allocate %x bytes.\n", risc_size
);
5576 goto default_template
;
5581 dcode
= ha
->fw_dump_template
;
5582 for (i
= 0; i
< risc_size
; i
++)
5583 dcode
[i
] = le32_to_cpu(fwcode
[i
]);
5585 if (!qla27xx_fwdt_template_valid(dcode
)) {
5586 ql_log(ql_log_warn
, vha
, 0x0175,
5587 "Failed fwdump template validate\n");
5588 goto default_template
;
5591 dlen
= qla27xx_fwdt_template_size(dcode
);
5592 ql_dbg(ql_dbg_init
, vha
, 0x0176,
5593 "-> template size %x bytes\n", dlen
);
5594 if (dlen
> risc_size
* sizeof(*fwcode
)) {
5595 ql_log(ql_log_warn
, vha
, 0x0177,
5596 "Failed fwdump template exceeds array by %x bytes\n",
5597 (uint32_t)(dlen
- risc_size
* sizeof(*fwcode
)));
5598 goto default_template
;
5600 ha
->fw_dump_template_len
= dlen
;
5604 ql_log(ql_log_warn
, vha
, 0x0178, "Using default fwdump template\n");
5605 if (ha
->fw_dump_template
)
5606 vfree(ha
->fw_dump_template
);
5607 ha
->fw_dump_template
= NULL
;
5608 ha
->fw_dump_template_len
= 0;
5610 dlen
= qla27xx_fwdt_template_default_size();
5611 ql_dbg(ql_dbg_init
, vha
, 0x0179,
5612 "-> template allocating %x bytes...\n", dlen
);
5613 ha
->fw_dump_template
= vmalloc(dlen
);
5614 if (!ha
->fw_dump_template
) {
5615 ql_log(ql_log_warn
, vha
, 0x017a,
5616 "Failed fwdump template allocate %x bytes.\n", risc_size
);
5617 goto failed_template
;
5620 dcode
= ha
->fw_dump_template
;
5621 risc_size
= dlen
/ sizeof(*fwcode
);
5622 fwcode
= qla27xx_fwdt_template_default();
5623 for (i
= 0; i
< risc_size
; i
++)
5624 dcode
[i
] = be32_to_cpu(fwcode
[i
]);
5626 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
5627 ql_log(ql_log_warn
, vha
, 0x017b,
5628 "Failed fwdump template validate\n");
5629 goto failed_template
;
5632 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
5633 ql_dbg(ql_dbg_init
, vha
, 0x017c,
5634 "-> template size %x bytes\n", dlen
);
5635 ha
->fw_dump_template_len
= dlen
;
5639 ql_log(ql_log_warn
, vha
, 0x017d, "Failed default fwdump template\n");
5640 if (ha
->fw_dump_template
)
5641 vfree(ha
->fw_dump_template
);
5642 ha
->fw_dump_template
= NULL
;
5643 ha
->fw_dump_template_len
= 0;
5648 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
5652 if (ql2xfwloadbin
== 1)
5653 return qla81xx_load_risc(vha
, srisc_addr
);
5657 * 1) Firmware via request-firmware interface (.bin file).
5658 * 2) Firmware residing in flash.
5660 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
5661 if (rval
== QLA_SUCCESS
)
5664 return qla24xx_load_risc_flash(vha
, srisc_addr
,
5665 vha
->hw
->flt_region_fw
);
5669 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
5672 struct qla_hw_data
*ha
= vha
->hw
;
5674 if (ql2xfwloadbin
== 2)
5679 * 1) Firmware residing in flash.
5680 * 2) Firmware via request-firmware interface (.bin file).
5681 * 3) Golden-Firmware residing in flash -- limited operation.
5683 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
5684 if (rval
== QLA_SUCCESS
)
5688 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
5689 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
5692 ql_log(ql_log_info
, vha
, 0x0099,
5693 "Attempting to fallback to golden firmware.\n");
5694 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
5695 if (rval
!= QLA_SUCCESS
)
5698 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
5699 ha
->flags
.running_gold_fw
= 1;
5704 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
5707 struct qla_hw_data
*ha
= vha
->hw
;
5709 if (ha
->flags
.pci_channel_io_perm_failure
)
5711 if (!IS_FWI2_CAPABLE(ha
))
5713 if (!ha
->fw_major_version
)
5716 ret
= qla2x00_stop_firmware(vha
);
5717 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
5718 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
5719 ha
->isp_ops
->reset_chip(vha
);
5720 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
5722 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
5724 ql_log(ql_log_info
, vha
, 0x8015,
5725 "Attempting retry of stop-firmware command.\n");
5726 ret
= qla2x00_stop_firmware(vha
);
5731 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
5733 int rval
= QLA_SUCCESS
;
5735 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5736 struct qla_hw_data
*ha
= vha
->hw
;
5737 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5738 struct req_que
*req
;
5739 struct rsp_que
*rsp
;
5744 rval
= qla2x00_fw_ready(base_vha
);
5745 if (ha
->flags
.cpu_affinity_enabled
)
5746 req
= ha
->req_q_map
[0];
5751 if (rval
== QLA_SUCCESS
) {
5752 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
5753 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
5756 vha
->flags
.management_server_logged_in
= 0;
5758 /* Login to SNS first */
5759 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
5761 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5762 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
5763 ql_dbg(ql_dbg_init
, vha
, 0x0120,
5764 "Failed SNS login: loop_id=%x, rval2=%d\n",
5767 ql_dbg(ql_dbg_init
, vha
, 0x0103,
5768 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
5769 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
5770 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
5771 return (QLA_FUNCTION_FAILED
);
5774 atomic_set(&vha
->loop_down_timer
, 0);
5775 atomic_set(&vha
->loop_state
, LOOP_UP
);
5776 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5777 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5778 rval
= qla2x00_loop_resync(base_vha
);
5783 /* 84XX Support **************************************************************/
5785 static LIST_HEAD(qla_cs84xx_list
);
5786 static DEFINE_MUTEX(qla_cs84xx_mutex
);
5788 static struct qla_chip_state_84xx
*
5789 qla84xx_get_chip(struct scsi_qla_host
*vha
)
5791 struct qla_chip_state_84xx
*cs84xx
;
5792 struct qla_hw_data
*ha
= vha
->hw
;
5794 mutex_lock(&qla_cs84xx_mutex
);
5796 /* Find any shared 84xx chip. */
5797 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
5798 if (cs84xx
->bus
== ha
->pdev
->bus
) {
5799 kref_get(&cs84xx
->kref
);
5804 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
5808 kref_init(&cs84xx
->kref
);
5809 spin_lock_init(&cs84xx
->access_lock
);
5810 mutex_init(&cs84xx
->fw_update_mutex
);
5811 cs84xx
->bus
= ha
->pdev
->bus
;
5813 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
5815 mutex_unlock(&qla_cs84xx_mutex
);
5820 __qla84xx_chip_release(struct kref
*kref
)
5822 struct qla_chip_state_84xx
*cs84xx
=
5823 container_of(kref
, struct qla_chip_state_84xx
, kref
);
5825 mutex_lock(&qla_cs84xx_mutex
);
5826 list_del(&cs84xx
->list
);
5827 mutex_unlock(&qla_cs84xx_mutex
);
5832 qla84xx_put_chip(struct scsi_qla_host
*vha
)
5834 struct qla_hw_data
*ha
= vha
->hw
;
5836 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
5840 qla84xx_init_chip(scsi_qla_host_t
*vha
)
5844 struct qla_hw_data
*ha
= vha
->hw
;
5846 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
5848 rval
= qla84xx_verify_chip(vha
, status
);
5850 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
5852 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
5856 /* 81XX Support **************************************************************/
5859 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
5862 struct init_cb_81xx
*icb
;
5863 struct nvram_81xx
*nv
;
5865 uint8_t *dptr1
, *dptr2
;
5868 struct qla_hw_data
*ha
= vha
->hw
;
5871 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
5874 /* Determine NVRAM starting address. */
5875 ha
->nvram_size
= sizeof(struct nvram_81xx
);
5876 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
5877 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
5878 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
5880 /* Get VPD data into cache */
5881 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
5882 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
5885 /* Get NVRAM data into cache and calculate checksum. */
5886 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
5888 dptr
= (uint32_t *)nv
;
5889 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++)
5890 chksum
+= le32_to_cpu(*dptr
++);
5892 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
5893 "Contents of NVRAM:\n");
5894 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
5895 (uint8_t *)nv
, ha
->nvram_size
);
5897 /* Bad NVRAM data, set defaults parameters. */
5898 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
5899 || nv
->id
[3] != ' ' ||
5900 nv
->nvram_version
< __constant_cpu_to_le16(ICB_VERSION
)) {
5901 /* Reset NVRAM data. */
5902 ql_log(ql_log_info
, vha
, 0x0073,
5903 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
5904 "version=0x%x.\n", chksum
, nv
->id
[0],
5905 le16_to_cpu(nv
->nvram_version
));
5906 ql_log(ql_log_info
, vha
, 0x0074,
5907 "Falling back to functioning (yet invalid -- WWPN) "
5911 * Set default initialization control block.
5913 memset(nv
, 0, ha
->nvram_size
);
5914 nv
->nvram_version
= __constant_cpu_to_le16(ICB_VERSION
);
5915 nv
->version
= __constant_cpu_to_le16(ICB_VERSION
);
5916 nv
->frame_payload_size
= __constant_cpu_to_le16(2048);
5917 nv
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
5918 nv
->exchange_count
= __constant_cpu_to_le16(0);
5919 nv
->port_name
[0] = 0x21;
5920 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
5921 nv
->port_name
[2] = 0x00;
5922 nv
->port_name
[3] = 0xe0;
5923 nv
->port_name
[4] = 0x8b;
5924 nv
->port_name
[5] = 0x1c;
5925 nv
->port_name
[6] = 0x55;
5926 nv
->port_name
[7] = 0x86;
5927 nv
->node_name
[0] = 0x20;
5928 nv
->node_name
[1] = 0x00;
5929 nv
->node_name
[2] = 0x00;
5930 nv
->node_name
[3] = 0xe0;
5931 nv
->node_name
[4] = 0x8b;
5932 nv
->node_name
[5] = 0x1c;
5933 nv
->node_name
[6] = 0x55;
5934 nv
->node_name
[7] = 0x86;
5935 nv
->login_retry_count
= __constant_cpu_to_le16(8);
5936 nv
->interrupt_delay_timer
= __constant_cpu_to_le16(0);
5937 nv
->login_timeout
= __constant_cpu_to_le16(0);
5938 nv
->firmware_options_1
=
5939 __constant_cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
5940 nv
->firmware_options_2
= __constant_cpu_to_le32(2 << 4);
5941 nv
->firmware_options_2
|= __constant_cpu_to_le32(BIT_12
);
5942 nv
->firmware_options_3
= __constant_cpu_to_le32(2 << 13);
5943 nv
->host_p
= __constant_cpu_to_le32(BIT_11
|BIT_10
);
5944 nv
->efi_parameters
= __constant_cpu_to_le32(0);
5945 nv
->reset_delay
= 5;
5946 nv
->max_luns_per_target
= __constant_cpu_to_le16(128);
5947 nv
->port_down_retry_count
= __constant_cpu_to_le16(30);
5948 nv
->link_down_timeout
= __constant_cpu_to_le16(180);
5949 nv
->enode_mac
[0] = 0x00;
5950 nv
->enode_mac
[1] = 0xC0;
5951 nv
->enode_mac
[2] = 0xDD;
5952 nv
->enode_mac
[3] = 0x04;
5953 nv
->enode_mac
[4] = 0x05;
5954 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
5959 if (IS_T10_PI_CAPABLE(ha
))
5960 nv
->frame_payload_size
&= ~7;
5962 qlt_81xx_config_nvram_stage1(vha
, nv
);
5964 /* Reset Initialization control block */
5965 memset(icb
, 0, ha
->init_cb_size
);
5967 /* Copy 1st segment. */
5968 dptr1
= (uint8_t *)icb
;
5969 dptr2
= (uint8_t *)&nv
->version
;
5970 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
5972 *dptr1
++ = *dptr2
++;
5974 icb
->login_retry_count
= nv
->login_retry_count
;
5976 /* Copy 2nd segment. */
5977 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
5978 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
5979 cnt
= (uint8_t *)&icb
->reserved_5
-
5980 (uint8_t *)&icb
->interrupt_delay_timer
;
5982 *dptr1
++ = *dptr2
++;
5984 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
5985 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
5986 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
5987 icb
->enode_mac
[0] = 0x00;
5988 icb
->enode_mac
[1] = 0xC0;
5989 icb
->enode_mac
[2] = 0xDD;
5990 icb
->enode_mac
[3] = 0x04;
5991 icb
->enode_mac
[4] = 0x05;
5992 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
5995 /* Use extended-initialization control block. */
5996 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
5999 * Setup driver NVRAM options.
6001 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
6004 qlt_81xx_config_nvram_stage2(vha
, icb
);
6006 /* Use alternate WWN? */
6007 if (nv
->host_p
& __constant_cpu_to_le32(BIT_15
)) {
6008 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
6009 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
6012 /* Prepare nodename */
6013 if ((icb
->firmware_options_1
& __constant_cpu_to_le32(BIT_14
)) == 0) {
6015 * Firmware will apply the following mask if the nodename was
6018 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
6019 icb
->node_name
[0] &= 0xF0;
6022 /* Set host adapter parameters. */
6023 ha
->flags
.disable_risc_code_load
= 0;
6024 ha
->flags
.enable_lip_reset
= 0;
6025 ha
->flags
.enable_lip_full_login
=
6026 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
6027 ha
->flags
.enable_target_reset
=
6028 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
6029 ha
->flags
.enable_led_scheme
= 0;
6030 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
6032 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
6033 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
6035 /* save HBA serial number */
6036 ha
->serial0
= icb
->port_name
[5];
6037 ha
->serial1
= icb
->port_name
[6];
6038 ha
->serial2
= icb
->port_name
[7];
6039 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
6040 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
6042 icb
->execution_throttle
= __constant_cpu_to_le16(0xFFFF);
6044 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
6046 /* Set minimum login_timeout to 4 seconds. */
6047 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
6048 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
6049 if (le16_to_cpu(nv
->login_timeout
) < 4)
6050 nv
->login_timeout
= __constant_cpu_to_le16(4);
6051 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
6052 icb
->login_timeout
= nv
->login_timeout
;
6054 /* Set minimum RATOV to 100 tenths of a second. */
6057 ha
->loop_reset_delay
= nv
->reset_delay
;
6059 /* Link Down Timeout = 0:
6061 * When Port Down timer expires we will start returning
6062 * I/O's to OS with "DID_NO_CONNECT".
6064 * Link Down Timeout != 0:
6066 * The driver waits for the link to come up after link down
6067 * before returning I/Os to OS with "DID_NO_CONNECT".
6069 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
6070 ha
->loop_down_abort_time
=
6071 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
6073 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
6074 ha
->loop_down_abort_time
=
6075 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
6078 /* Need enough time to try and get the port back. */
6079 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
6080 if (qlport_down_retry
)
6081 ha
->port_down_retry_count
= qlport_down_retry
;
6083 /* Set login_retry_count */
6084 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
6085 if (ha
->port_down_retry_count
==
6086 le16_to_cpu(nv
->port_down_retry_count
) &&
6087 ha
->port_down_retry_count
> 3)
6088 ha
->login_retry_count
= ha
->port_down_retry_count
;
6089 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
6090 ha
->login_retry_count
= ha
->port_down_retry_count
;
6091 if (ql2xloginretrycount
)
6092 ha
->login_retry_count
= ql2xloginretrycount
;
6094 /* if not running MSI-X we need handshaking on interrupts */
6095 if (!vha
->hw
->flags
.msix_enabled
&& (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)))
6096 icb
->firmware_options_2
|= __constant_cpu_to_le32(BIT_22
);
6099 if (!vha
->flags
.init_done
) {
6100 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
6101 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6102 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
6103 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
6105 icb
->firmware_options_2
&= __constant_cpu_to_le32(
6106 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
6107 vha
->flags
.process_response_queue
= 0;
6108 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
6109 ha
->zio_mode
= QLA_ZIO_MODE_6
;
6111 ql_log(ql_log_info
, vha
, 0x0075,
6112 "ZIO mode %d enabled; timer delay (%d us).\n",
6114 ha
->zio_timer
* 100);
6116 icb
->firmware_options_2
|= cpu_to_le32(
6117 (uint32_t)ha
->zio_mode
);
6118 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
6119 vha
->flags
.process_response_queue
= 1;
6123 ql_log(ql_log_warn
, vha
, 0x0076,
6124 "NVRAM configuration failed.\n");
6130 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
6134 struct qla_hw_data
*ha
= vha
->hw
;
6135 struct req_que
*req
= ha
->req_q_map
[0];
6136 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
6137 struct scsi_qla_host
*vp
;
6138 unsigned long flags
;
6140 status
= qla2x00_init_rings(vha
);
6142 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6143 ha
->flags
.chip_reset_done
= 1;
6145 status
= qla2x00_fw_ready(vha
);
6147 ql_log(ql_log_info
, vha
, 0x803c,
6148 "Start configure loop, status =%d.\n", status
);
6150 /* Issue a marker after FW becomes ready. */
6151 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
6153 vha
->flags
.online
= 1;
6154 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6157 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6158 qla2x00_configure_loop(vha
);
6160 } while (!atomic_read(&vha
->loop_down_timer
) &&
6161 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
)) &&
6163 (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)));
6166 /* if no cable then assume it's good */
6167 if ((vha
->device_flags
& DFLG_NO_CABLE
))
6170 ql_log(ql_log_info
, vha
, 0x8000,
6171 "Configure loop done, status = 0x%x.\n", status
);
6175 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6177 if (!atomic_read(&vha
->loop_down_timer
)) {
6179 * Issue marker command only when we are going
6180 * to start the I/O .
6182 vha
->marker_needed
= 1;
6185 vha
->flags
.online
= 1;
6187 ha
->isp_ops
->enable_intrs(ha
);
6189 ha
->isp_abort_cnt
= 0;
6190 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6192 /* Update the firmware version */
6193 status
= qla82xx_check_md_needed(vha
);
6196 ha
->flags
.fce_enabled
= 1;
6198 fce_calc_size(ha
->fce_bufs
));
6199 rval
= qla2x00_enable_fce_trace(vha
,
6200 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6203 ql_log(ql_log_warn
, vha
, 0x8001,
6204 "Unable to reinitialize FCE (%d).\n",
6206 ha
->flags
.fce_enabled
= 0;
6211 memset(ha
->eft
, 0, EFT_SIZE
);
6212 rval
= qla2x00_enable_eft_trace(vha
,
6213 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6215 ql_log(ql_log_warn
, vha
, 0x8010,
6216 "Unable to reinitialize EFT (%d).\n",
6223 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
6224 "qla82xx_restart_isp succeeded.\n");
6226 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6227 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6229 atomic_inc(&vp
->vref_count
);
6230 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6232 qla2x00_vp_abort_isp(vp
);
6234 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6235 atomic_dec(&vp
->vref_count
);
6238 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6241 ql_log(ql_log_warn
, vha
, 0x8016,
6242 "qla82xx_restart_isp **** FAILED ****.\n");
6249 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
6251 struct qla_hw_data
*ha
= vha
->hw
;
6256 /* Enable ETS Burst. */
6257 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
6258 ha
->fw_options
[2] |= BIT_9
;
6259 qla2x00_set_fw_options(vha
, ha
->fw_options
);
6263 * qla24xx_get_fcp_prio
6264 * Gets the fcp cmd priority value for the logged in port.
6265 * Looks for a match of the port descriptors within
6266 * each of the fcp prio config entries. If a match is found,
6267 * the tag (priority) value is returned.
6270 * vha = scsi host structure pointer.
6271 * fcport = port structure pointer.
6274 * non-zero (if found)
6281 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
6284 uint8_t pid_match
, wwn_match
;
6286 uint32_t pid1
, pid2
;
6287 uint64_t wwn1
, wwn2
;
6288 struct qla_fcp_prio_entry
*pri_entry
;
6289 struct qla_hw_data
*ha
= vha
->hw
;
6291 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
6295 entries
= ha
->fcp_prio_cfg
->num_entries
;
6296 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
6298 for (i
= 0; i
< entries
; i
++) {
6299 pid_match
= wwn_match
= 0;
6301 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
6306 /* check source pid for a match */
6307 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
6308 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
6309 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
6310 if (pid1
== INVALID_PORT_ID
)
6312 else if (pid1
== pid2
)
6316 /* check destination pid for a match */
6317 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
6318 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
6319 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
6320 if (pid1
== INVALID_PORT_ID
)
6322 else if (pid1
== pid2
)
6326 /* check source WWN for a match */
6327 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
6328 wwn1
= wwn_to_u64(vha
->port_name
);
6329 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
6330 if (wwn2
== (uint64_t)-1)
6332 else if (wwn1
== wwn2
)
6336 /* check destination WWN for a match */
6337 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
6338 wwn1
= wwn_to_u64(fcport
->port_name
);
6339 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
6340 if (wwn2
== (uint64_t)-1)
6342 else if (wwn1
== wwn2
)
6346 if (pid_match
== 2 || wwn_match
== 2) {
6347 /* Found a matching entry */
6348 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
6349 priority
= pri_entry
->tag
;
6360 * qla24xx_update_fcport_fcp_prio
6361 * Activates fcp priority for the logged in fc port
6364 * vha = scsi host structure pointer.
6365 * fcp = port structure pointer.
6368 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6374 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
6380 if (fcport
->port_type
!= FCT_TARGET
||
6381 fcport
->loop_id
== FC_NO_LOOP_ID
)
6382 return QLA_FUNCTION_FAILED
;
6384 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
6386 return QLA_FUNCTION_FAILED
;
6388 if (IS_P3P_TYPE(vha
->hw
)) {
6389 fcport
->fcp_prio
= priority
& 0xf;
6393 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
6394 if (ret
== QLA_SUCCESS
) {
6395 if (fcport
->fcp_prio
!= priority
)
6396 ql_dbg(ql_dbg_user
, vha
, 0x709e,
6397 "Updated FCP_CMND priority - value=%d loop_id=%d "
6398 "port_id=%02x%02x%02x.\n", priority
,
6399 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
6400 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
6401 fcport
->fcp_prio
= priority
& 0xf;
6403 ql_dbg(ql_dbg_user
, vha
, 0x704f,
6404 "Unable to update FCP_CMND priority - ret=0x%x for "
6405 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
6406 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
6407 fcport
->d_id
.b
.al_pa
);
6412 * qla24xx_update_all_fcp_prio
6413 * Activates fcp priority for all the logged in ports
6416 * ha = adapter block pointer.
6419 * QLA_SUCCESS or QLA_FUNCTION_FAILED
6425 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
6430 ret
= QLA_FUNCTION_FAILED
;
6431 /* We need to set priority for all logged in ports */
6432 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
6433 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);