2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 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
*);
34 static int qla2x00_restart_isp(scsi_qla_host_t
*);
36 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
37 static int qla84xx_init_chip(scsi_qla_host_t
*);
38 static int qla25xx_init_queues(struct qla_hw_data
*);
39 static int qla24xx_post_prli_work(struct scsi_qla_host
*, fc_port_t
*);
40 static void qla24xx_handle_plogi_done_event(struct scsi_qla_host
*,
42 static void qla24xx_handle_prli_done_event(struct scsi_qla_host
*,
44 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*, struct event_arg
*);
46 /* SRB Extensions ---------------------------------------------------------- */
49 qla2x00_sp_timeout(struct timer_list
*t
)
51 srb_t
*sp
= from_timer(sp
, t
, u
.iocb_cmd
.timer
);
52 struct srb_iocb
*iocb
;
53 scsi_qla_host_t
*vha
= sp
->vha
;
57 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
58 req
= vha
->hw
->req_q_map
[0];
59 req
->outstanding_cmds
[sp
->handle
] = NULL
;
60 iocb
= &sp
->u
.iocb_cmd
;
62 if (sp
->type
!= SRB_ELS_DCMD
)
64 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
68 qla2x00_sp_free(void *ptr
)
71 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
73 del_timer(&iocb
->timer
);
77 /* Asynchronous Login/Logout Routines -------------------------------------- */
80 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
83 struct qla_hw_data
*ha
= vha
->hw
;
85 /* Firmware should use switch negotiated r_a_tov for timeout. */
86 tmo
= ha
->r_a_tov
/ 10 * 2;
88 tmo
= FX00_DEF_RATOV
* 2;
89 } else if (!IS_FWI2_CAPABLE(ha
)) {
91 * Except for earlier ISPs where the timeout is seeded from the
92 * initialization control block.
94 tmo
= ha
->login_timeout
;
100 qla2x00_async_iocb_timeout(void *data
)
103 fc_port_t
*fcport
= sp
->fcport
;
104 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
108 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
109 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
110 sp
->name
, sp
->handle
, fcport
->d_id
.b24
, fcport
->port_name
);
112 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
114 pr_info("Async-%s timeout - hdl=%x.\n",
115 sp
->name
, sp
->handle
);
122 /* Retry as needed. */
123 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
124 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
125 QLA_LOGIO_LOGIN_RETRIED
: 0;
126 memset(&ea
, 0, sizeof(ea
));
127 ea
.event
= FCME_PLOGI_DONE
;
128 ea
.fcport
= sp
->fcport
;
129 ea
.data
[0] = lio
->u
.logio
.data
[0];
130 ea
.data
[1] = lio
->u
.logio
.data
[1];
132 qla24xx_handle_plogi_done_event(fcport
->vha
, &ea
);
137 qlt_logo_completion_handler(fcport
, QLA_FUNCTION_TIMEOUT
);
139 case SRB_CT_PTHRU_CMD
:
145 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
151 qla2x00_async_login_sp_done(void *ptr
, int res
)
154 struct scsi_qla_host
*vha
= sp
->vha
;
155 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
158 ql_dbg(ql_dbg_disc
, vha
, 0x20dd,
159 "%s %8phC res %d \n", __func__
, sp
->fcport
->port_name
, res
);
161 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
163 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
164 memset(&ea
, 0, sizeof(ea
));
165 ea
.event
= FCME_PLOGI_DONE
;
166 ea
.fcport
= sp
->fcport
;
167 ea
.data
[0] = lio
->u
.logio
.data
[0];
168 ea
.data
[1] = lio
->u
.logio
.data
[1];
169 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
170 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
172 qla2x00_fcport_event_handler(vha
, &ea
);
179 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
183 struct srb_iocb
*lio
;
184 int rval
= QLA_FUNCTION_FAILED
;
186 if (!vha
->flags
.online
)
189 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
193 fcport
->flags
|= FCF_ASYNC_SENT
;
194 fcport
->logout_completed
= 0;
196 fcport
->disc_state
= DSC_LOGIN_PEND
;
197 sp
->type
= SRB_LOGIN_CMD
;
199 sp
->gen1
= fcport
->rscn_gen
;
200 sp
->gen2
= fcport
->login_gen
;
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_login_sp_done
;
206 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
208 if (fcport
->fc4f_nvme
)
209 lio
->u
.logio
.flags
|= SRB_LOGIN_SKIP_PRLI
;
211 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
212 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
213 rval
= qla2x00_start_sp(sp
);
214 if (rval
!= QLA_SUCCESS
) {
215 fcport
->flags
|= FCF_LOGIN_NEEDED
;
216 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
220 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
221 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
222 "retries=%d.\n", fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
223 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
224 fcport
->login_retry
);
229 fcport
->flags
&= ~FCF_ASYNC_SENT
;
235 qla2x00_async_logout_sp_done(void *ptr
, int res
)
238 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
240 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
241 if (!test_bit(UNLOADING
, &sp
->vha
->dpc_flags
))
242 qla2x00_post_async_logout_done_work(sp
->vha
, sp
->fcport
,
248 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
251 struct srb_iocb
*lio
;
252 int rval
= QLA_FUNCTION_FAILED
;
254 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
257 fcport
->flags
|= FCF_ASYNC_SENT
;
258 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
262 sp
->type
= SRB_LOGOUT_CMD
;
264 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
266 lio
= &sp
->u
.iocb_cmd
;
267 lio
->timeout
= qla2x00_async_iocb_timeout
;
268 sp
->done
= qla2x00_async_logout_sp_done
;
269 rval
= qla2x00_start_sp(sp
);
270 if (rval
!= QLA_SUCCESS
)
273 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
274 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
275 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
276 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
283 fcport
->flags
&= ~FCF_ASYNC_SENT
;
288 qla2x00_async_prlo_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
291 /* Don't re-login in target mode */
292 if (!fcport
->tgt_session
)
293 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
294 qlt_logo_completion_handler(fcport
, data
[0]);
298 qla2x00_async_prlo_sp_done(void *s
, int res
)
300 srb_t
*sp
= (srb_t
*)s
;
301 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
302 struct scsi_qla_host
*vha
= sp
->vha
;
304 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
305 qla2x00_post_async_prlo_done_work(sp
->fcport
->vha
, sp
->fcport
,
311 qla2x00_async_prlo(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
314 struct srb_iocb
*lio
;
317 rval
= QLA_FUNCTION_FAILED
;
318 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
322 sp
->type
= SRB_PRLO_CMD
;
324 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
326 lio
= &sp
->u
.iocb_cmd
;
327 lio
->timeout
= qla2x00_async_iocb_timeout
;
328 sp
->done
= qla2x00_async_prlo_sp_done
;
329 rval
= qla2x00_start_sp(sp
);
330 if (rval
!= QLA_SUCCESS
)
333 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
334 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
335 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
336 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
346 void qla24xx_handle_adisc_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
348 struct fc_port
*fcport
= ea
->fcport
;
350 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
351 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
352 __func__
, fcport
->port_name
, fcport
->disc_state
,
353 fcport
->fw_login_state
, ea
->rc
, fcport
->login_gen
, ea
->sp
->gen2
,
354 fcport
->rscn_gen
, ea
->sp
->gen1
, fcport
->loop_id
);
356 if (ea
->data
[0] != MBS_COMMAND_COMPLETE
) {
357 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
358 "%s %8phC: adisc fail: post delete\n",
359 __func__
, ea
->fcport
->port_name
);
360 qlt_schedule_sess_for_deletion(ea
->fcport
);
364 if (ea
->fcport
->disc_state
== DSC_DELETE_PEND
)
367 if (ea
->sp
->gen2
!= ea
->fcport
->login_gen
) {
368 /* target side must have changed it. */
369 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
370 "%s %8phC generation changed\n",
371 __func__
, ea
->fcport
->port_name
);
373 } else if (ea
->sp
->gen1
!= ea
->fcport
->rscn_gen
) {
374 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
375 __func__
, __LINE__
, ea
->fcport
->port_name
);
376 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
380 __qla24xx_handle_gpdb_event(vha
, ea
);
384 qla2x00_async_adisc_sp_done(void *ptr
, int res
)
387 struct scsi_qla_host
*vha
= sp
->vha
;
389 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
391 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
392 "Async done-%s res %x %8phC\n",
393 sp
->name
, res
, sp
->fcport
->port_name
);
395 memset(&ea
, 0, sizeof(ea
));
396 ea
.event
= FCME_ADISC_DONE
;
398 ea
.data
[0] = lio
->u
.logio
.data
[0];
399 ea
.data
[1] = lio
->u
.logio
.data
[1];
400 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
401 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
402 ea
.fcport
= sp
->fcport
;
405 qla2x00_fcport_event_handler(vha
, &ea
);
411 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
415 struct srb_iocb
*lio
;
418 rval
= QLA_FUNCTION_FAILED
;
419 fcport
->flags
|= FCF_ASYNC_SENT
;
420 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
424 sp
->type
= SRB_ADISC_CMD
;
426 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
428 lio
= &sp
->u
.iocb_cmd
;
429 lio
->timeout
= qla2x00_async_iocb_timeout
;
430 sp
->done
= qla2x00_async_adisc_sp_done
;
431 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
432 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
433 rval
= qla2x00_start_sp(sp
);
434 if (rval
!= QLA_SUCCESS
)
437 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
438 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
439 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
, fcport
->port_name
);
445 fcport
->flags
&= ~FCF_ASYNC_SENT
;
446 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
450 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t
*vha
,
451 struct event_arg
*ea
)
453 fc_port_t
*fcport
, *conflict_fcport
;
454 struct get_name_list_extended
*e
;
455 u16 i
, n
, found
= 0, loop_id
;
459 u8 current_login_state
;
462 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
463 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
464 __func__
, fcport
->port_name
, fcport
->disc_state
,
465 fcport
->fw_login_state
, ea
->rc
,
466 fcport
->login_gen
, fcport
->last_login_gen
,
467 fcport
->rscn_gen
, fcport
->last_rscn_gen
, vha
->loop_id
);
469 if (fcport
->disc_state
== DSC_DELETE_PEND
)
472 if (ea
->rc
) { /* rval */
473 if (fcport
->login_retry
== 0) {
474 fcport
->login_retry
= vha
->hw
->login_retry_count
;
475 ql_dbg(ql_dbg_disc
, vha
, 0x20de,
476 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
477 fcport
->port_name
, fcport
->login_retry
);
482 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
483 ql_dbg(ql_dbg_disc
, vha
, 0x20df,
484 "%s %8phC rscn gen changed rscn %d|%d \n",
485 __func__
, fcport
->port_name
,
486 fcport
->last_rscn_gen
, fcport
->rscn_gen
);
487 qla24xx_post_gidpn_work(vha
, fcport
);
489 } else if (fcport
->last_login_gen
!= fcport
->login_gen
) {
490 ql_dbg(ql_dbg_disc
, vha
, 0x20e0,
491 "%s %8phC login gen changed\n",
492 __func__
, fcport
->port_name
);
496 n
= ea
->data
[0] / sizeof(struct get_name_list_extended
);
498 ql_dbg(ql_dbg_disc
, vha
, 0x20e1,
499 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
500 __func__
, __LINE__
, fcport
->port_name
, n
,
501 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
502 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
);
504 for (i
= 0; i
< n
; i
++) {
506 wwn
= wwn_to_u64(e
->port_name
);
508 if (memcmp((u8
*)&wwn
, fcport
->port_name
, WWN_SIZE
))
512 id
.b
.domain
= e
->port_id
[2];
513 id
.b
.area
= e
->port_id
[1];
514 id
.b
.al_pa
= e
->port_id
[0];
517 loop_id
= le16_to_cpu(e
->nport_handle
);
518 loop_id
= (loop_id
& 0x7fff);
520 ql_dbg(ql_dbg_disc
, vha
, 0x20e2,
521 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
522 __func__
, fcport
->port_name
,
523 e
->current_login_state
, fcport
->fw_login_state
,
524 id
.b
.domain
, id
.b
.area
, id
.b
.al_pa
,
525 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
526 fcport
->d_id
.b
.al_pa
, loop_id
, fcport
->loop_id
);
528 if ((id
.b24
!= fcport
->d_id
.b24
) ||
529 ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
530 (fcport
->loop_id
!= loop_id
))) {
531 ql_dbg(ql_dbg_disc
, vha
, 0x20e3,
532 "%s %d %8phC post del sess\n",
533 __func__
, __LINE__
, fcport
->port_name
);
534 qlt_schedule_sess_for_deletion(fcport
);
538 fcport
->loop_id
= loop_id
;
540 wwn
= wwn_to_u64(fcport
->port_name
);
541 qlt_find_sess_invalidate_other(vha
, wwn
,
542 id
, loop_id
, &conflict_fcport
);
544 if (conflict_fcport
) {
546 * Another share fcport share the same loop_id &
547 * nport id. Conflict fcport needs to finish
548 * cleanup before this fcport can proceed to login.
550 conflict_fcport
->conflict
= fcport
;
551 fcport
->login_pause
= 1;
554 if (fcport
->fc4f_nvme
)
555 current_login_state
= e
->current_login_state
>> 4;
557 current_login_state
= e
->current_login_state
& 0xf;
559 switch (current_login_state
) {
560 case DSC_LS_PRLI_COMP
:
561 ql_dbg(ql_dbg_disc
, vha
, 0x20e4,
562 "%s %d %8phC post gpdb\n",
563 __func__
, __LINE__
, fcport
->port_name
);
565 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
566 fcport
->port_type
= FCT_INITIATOR
;
568 fcport
->port_type
= FCT_TARGET
;
570 data
[0] = data
[1] = 0;
571 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
573 case DSC_LS_PORT_UNAVAIL
:
575 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
576 qla2x00_find_new_loop_id(vha
, fcport
);
577 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
579 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
581 __func__
, __LINE__
, fcport
->port_name
);
582 qla24xx_fcport_handle_login(vha
, fcport
);
588 /* fw has no record of this port */
589 for (i
= 0; i
< n
; i
++) {
591 id
.b
.domain
= e
->port_id
[0];
592 id
.b
.area
= e
->port_id
[1];
593 id
.b
.al_pa
= e
->port_id
[2];
595 loop_id
= le16_to_cpu(e
->nport_handle
);
597 if (fcport
->d_id
.b24
== id
.b24
) {
599 qla2x00_find_fcport_by_wwpn(vha
,
601 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
602 "%s %d %8phC post del sess\n",
604 conflict_fcport
->port_name
);
605 qlt_schedule_sess_for_deletion
609 /* FW already picked this loop id for another fcport */
610 if (fcport
->loop_id
== loop_id
)
611 fcport
->loop_id
= FC_NO_LOOP_ID
;
613 qla24xx_fcport_handle_login(vha
, fcport
);
618 qla24xx_async_gnl_sp_done(void *s
, int res
)
621 struct scsi_qla_host
*vha
= sp
->vha
;
623 struct fc_port
*fcport
= NULL
, *tf
;
624 u16 i
, n
= 0, loop_id
;
626 struct get_name_list_extended
*e
;
631 ql_dbg(ql_dbg_disc
, vha
, 0x20e7,
632 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
633 sp
->name
, res
, sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1],
634 sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[2]);
636 memset(&ea
, 0, sizeof(ea
));
639 ea
.event
= FCME_GNL_DONE
;
641 if (sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] >=
642 sizeof(struct get_name_list_extended
)) {
643 n
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] /
644 sizeof(struct get_name_list_extended
);
645 ea
.data
[0] = sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1]; /* amnt xfered */
648 for (i
= 0; i
< n
; i
++) {
650 loop_id
= le16_to_cpu(e
->nport_handle
);
651 /* mask out reserve bit */
652 loop_id
= (loop_id
& 0x7fff);
653 set_bit(loop_id
, vha
->hw
->loop_id_map
);
654 wwn
= wwn_to_u64(e
->port_name
);
656 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0x20e8,
657 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
658 __func__
, (void *)&wwn
, e
->port_id
[2], e
->port_id
[1],
659 e
->port_id
[0], e
->current_login_state
, e
->last_login_state
,
663 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
668 if (!list_empty(&vha
->gnl
.fcports
))
669 list_splice_init(&vha
->gnl
.fcports
, &h
);
671 list_for_each_entry_safe(fcport
, tf
, &h
, gnl_entry
) {
672 list_del_init(&fcport
->gnl_entry
);
673 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
676 qla2x00_fcport_event_handler(vha
, &ea
);
679 /* create new fcport if fw has knowledge of new sessions */
680 for (i
= 0; i
< n
; i
++) {
685 wwn
= wwn_to_u64(e
->port_name
);
688 list_for_each_entry_safe(fcport
, tf
, &vha
->vp_fcports
, list
) {
689 if (!memcmp((u8
*)&wwn
, fcport
->port_name
,
696 id
.b
.domain
= e
->port_id
[2];
697 id
.b
.area
= e
->port_id
[1];
698 id
.b
.al_pa
= e
->port_id
[0];
701 if (!found
&& wwn
&& !IS_SW_RESV_ADDR(id
)) {
702 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
703 "%s %d %8phC %06x post new sess\n",
704 __func__
, __LINE__
, (u8
*)&wwn
, id
.b24
);
705 wwnn
= wwn_to_u64(e
->node_name
);
706 qla24xx_post_newsess_work(vha
, &id
, (u8
*)&wwn
,
707 (u8
*)&wwnn
, NULL
, FC4_TYPE_UNKNOWN
);
711 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
716 int qla24xx_async_gnl(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
719 struct srb_iocb
*mbx
;
720 int rval
= QLA_FUNCTION_FAILED
;
724 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
727 ql_dbg(ql_dbg_disc
, vha
, 0x20d9,
728 "Async-gnlist WWPN %8phC \n", fcport
->port_name
);
730 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
731 fcport
->disc_state
= DSC_GNL
;
732 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
733 fcport
->last_login_gen
= fcport
->login_gen
;
735 list_add_tail(&fcport
->gnl_entry
, &vha
->gnl
.fcports
);
737 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
741 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
743 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
747 fcport
->flags
|= FCF_ASYNC_SENT
;
748 sp
->type
= SRB_MB_IOCB
;
750 sp
->gen1
= fcport
->rscn_gen
;
751 sp
->gen2
= fcport
->login_gen
;
753 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
755 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
756 mb
[0] = MBC_PORT_NODE_NAME_LIST
;
757 mb
[1] = BIT_2
| BIT_3
;
758 mb
[2] = MSW(vha
->gnl
.ldma
);
759 mb
[3] = LSW(vha
->gnl
.ldma
);
760 mb
[6] = MSW(MSD(vha
->gnl
.ldma
));
761 mb
[7] = LSW(MSD(vha
->gnl
.ldma
));
762 mb
[8] = vha
->gnl
.size
;
765 mbx
= &sp
->u
.iocb_cmd
;
766 mbx
->timeout
= qla2x00_async_iocb_timeout
;
768 sp
->done
= qla24xx_async_gnl_sp_done
;
770 rval
= qla2x00_start_sp(sp
);
771 if (rval
!= QLA_SUCCESS
)
774 ql_dbg(ql_dbg_disc
, vha
, 0x20da,
775 "Async-%s - OUT WWPN %8phC hndl %x\n",
776 sp
->name
, fcport
->port_name
, sp
->handle
);
782 fcport
->flags
&= ~FCF_ASYNC_SENT
;
787 int qla24xx_post_gnl_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
789 struct qla_work_evt
*e
;
791 e
= qla2x00_alloc_work(vha
, QLA_EVT_GNL
);
793 return QLA_FUNCTION_FAILED
;
795 e
->u
.fcport
.fcport
= fcport
;
796 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
797 return qla2x00_post_work(vha
, e
);
801 void qla24xx_async_gpdb_sp_done(void *s
, int res
)
804 struct scsi_qla_host
*vha
= sp
->vha
;
805 struct qla_hw_data
*ha
= vha
->hw
;
806 fc_port_t
*fcport
= sp
->fcport
;
807 u16
*mb
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
;
810 ql_dbg(ql_dbg_disc
, vha
, 0x20db,
811 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
812 sp
->name
, res
, fcport
->port_name
, mb
[1], mb
[2]);
814 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
816 memset(&ea
, 0, sizeof(ea
));
817 ea
.event
= FCME_GPDB_DONE
;
821 qla2x00_fcport_event_handler(vha
, &ea
);
823 dma_pool_free(ha
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
824 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
829 static int qla24xx_post_prli_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
831 struct qla_work_evt
*e
;
833 e
= qla2x00_alloc_work(vha
, QLA_EVT_PRLI
);
835 return QLA_FUNCTION_FAILED
;
837 e
->u
.fcport
.fcport
= fcport
;
839 return qla2x00_post_work(vha
, e
);
843 qla2x00_async_prli_sp_done(void *ptr
, int res
)
846 struct scsi_qla_host
*vha
= sp
->vha
;
847 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
850 ql_dbg(ql_dbg_disc
, vha
, 0x2129,
851 "%s %8phC res %d \n", __func__
,
852 sp
->fcport
->port_name
, res
);
854 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
856 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
857 memset(&ea
, 0, sizeof(ea
));
858 ea
.event
= FCME_PRLI_DONE
;
859 ea
.fcport
= sp
->fcport
;
860 ea
.data
[0] = lio
->u
.logio
.data
[0];
861 ea
.data
[1] = lio
->u
.logio
.data
[1];
862 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
863 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
866 qla2x00_fcport_event_handler(vha
, &ea
);
873 qla24xx_async_prli(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
876 struct srb_iocb
*lio
;
877 int rval
= QLA_FUNCTION_FAILED
;
879 if (!vha
->flags
.online
)
882 if (fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
||
883 fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
||
884 fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)
887 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
891 fcport
->flags
|= FCF_ASYNC_SENT
;
892 fcport
->logout_completed
= 0;
894 sp
->type
= SRB_PRLI_CMD
;
896 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
898 lio
= &sp
->u
.iocb_cmd
;
899 lio
->timeout
= qla2x00_async_iocb_timeout
;
900 sp
->done
= qla2x00_async_prli_sp_done
;
901 lio
->u
.logio
.flags
= 0;
903 if (fcport
->fc4f_nvme
)
904 lio
->u
.logio
.flags
|= SRB_LOGIN_NVME_PRLI
;
906 rval
= qla2x00_start_sp(sp
);
907 if (rval
!= QLA_SUCCESS
) {
908 fcport
->flags
|= FCF_LOGIN_NEEDED
;
909 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
913 ql_dbg(ql_dbg_disc
, vha
, 0x211b,
914 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
915 fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
916 fcport
->d_id
.b24
, fcport
->login_retry
);
922 fcport
->flags
&= ~FCF_ASYNC_SENT
;
926 int qla24xx_post_gpdb_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
928 struct qla_work_evt
*e
;
930 e
= qla2x00_alloc_work(vha
, QLA_EVT_GPDB
);
932 return QLA_FUNCTION_FAILED
;
934 e
->u
.fcport
.fcport
= fcport
;
935 e
->u
.fcport
.opt
= opt
;
936 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
937 return qla2x00_post_work(vha
, e
);
940 int qla24xx_async_gpdb(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
943 struct srb_iocb
*mbx
;
944 int rval
= QLA_FUNCTION_FAILED
;
947 struct port_database_24xx
*pd
;
948 struct qla_hw_data
*ha
= vha
->hw
;
950 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
953 fcport
->disc_state
= DSC_GPDB
;
955 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
959 fcport
->flags
|= FCF_ASYNC_SENT
;
960 sp
->type
= SRB_MB_IOCB
;
962 sp
->gen1
= fcport
->rscn_gen
;
963 sp
->gen2
= fcport
->login_gen
;
964 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
966 pd
= dma_pool_zalloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
968 ql_log(ql_log_warn
, vha
, 0xd043,
969 "Failed to allocate port database structure.\n");
973 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
974 mb
[0] = MBC_GET_PORT_DATABASE
;
975 mb
[1] = fcport
->loop_id
;
978 mb
[6] = MSW(MSD(pd_dma
));
979 mb
[7] = LSW(MSD(pd_dma
));
983 mbx
= &sp
->u
.iocb_cmd
;
984 mbx
->timeout
= qla2x00_async_iocb_timeout
;
985 mbx
->u
.mbx
.in
= (void *)pd
;
986 mbx
->u
.mbx
.in_dma
= pd_dma
;
988 sp
->done
= qla24xx_async_gpdb_sp_done
;
990 rval
= qla2x00_start_sp(sp
);
991 if (rval
!= QLA_SUCCESS
)
994 ql_dbg(ql_dbg_disc
, vha
, 0x20dc,
995 "Async-%s %8phC hndl %x opt %x\n",
996 sp
->name
, fcport
->port_name
, sp
->handle
, opt
);
1002 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1005 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1007 qla24xx_post_gpdb_work(vha
, fcport
, opt
);
1012 void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1014 unsigned long flags
;
1016 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1017 ea
->fcport
->login_gen
++;
1018 ea
->fcport
->deleted
= 0;
1019 ea
->fcport
->logout_on_delete
= 1;
1021 if (!ea
->fcport
->login_succ
&& !IS_SW_RESV_ADDR(ea
->fcport
->d_id
)) {
1022 vha
->fcport_count
++;
1023 ea
->fcport
->login_succ
= 1;
1025 if (!IS_IIDMA_CAPABLE(vha
->hw
) ||
1026 !vha
->hw
->flags
.gpsc_supported
) {
1027 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1028 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1029 __func__
, __LINE__
, ea
->fcport
->port_name
,
1032 qla24xx_post_upd_fcport_work(vha
, ea
->fcport
);
1034 if (ea
->fcport
->id_changed
) {
1035 ea
->fcport
->id_changed
= 0;
1036 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
1037 "%s %d %8phC post gfpnid fcp_cnt %d\n",
1038 __func__
, __LINE__
, ea
->fcport
->port_name
,
1040 qla24xx_post_gfpnid_work(vha
, ea
->fcport
);
1042 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
1043 "%s %d %8phC post gpsc fcp_cnt %d\n",
1044 __func__
, __LINE__
, ea
->fcport
->port_name
,
1046 qla24xx_post_gpsc_work(vha
, ea
->fcport
);
1049 } else if (ea
->fcport
->login_succ
) {
1051 * We have an existing session. A late RSCN delivery
1052 * must have triggered the session to be re-validate.
1053 * Session is still valid.
1055 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1056 "%s %d %8phC session revalidate success\n",
1057 __func__
, __LINE__
, ea
->fcport
->port_name
);
1058 ea
->fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
1060 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1064 void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1066 fc_port_t
*fcport
= ea
->fcport
;
1067 struct port_database_24xx
*pd
;
1068 struct srb
*sp
= ea
->sp
;
1070 pd
= (struct port_database_24xx
*)sp
->u
.iocb_cmd
.u
.mbx
.in
;
1072 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1074 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
1075 "%s %8phC DS %d LS %d rc %d\n", __func__
, fcport
->port_name
,
1076 fcport
->disc_state
, pd
->current_login_state
, ea
->rc
);
1078 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1081 switch (pd
->current_login_state
) {
1082 case PDS_PRLI_COMPLETE
:
1083 __qla24xx_parse_gpdb(vha
, fcport
, pd
);
1085 case PDS_PLOGI_PENDING
:
1086 case PDS_PLOGI_COMPLETE
:
1087 case PDS_PRLI_PENDING
:
1088 case PDS_PRLI2_PENDING
:
1089 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC relogin needed\n",
1090 __func__
, __LINE__
, fcport
->port_name
);
1091 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1093 case PDS_LOGO_PENDING
:
1094 case PDS_PORT_UNAVAILABLE
:
1096 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC post del sess\n",
1097 __func__
, __LINE__
, fcport
->port_name
);
1098 qlt_schedule_sess_for_deletion(fcport
);
1101 __qla24xx_handle_gpdb_event(vha
, ea
);
1104 static void qla_chk_n2n_b4_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1109 if (qla_tgt_mode_enabled(vha
))
1112 if (qla_dual_mode_enabled(vha
)) {
1113 if (N2N_TOPO(vha
->hw
)) {
1116 mywwn
= wwn_to_u64(vha
->port_name
);
1117 wwn
= wwn_to_u64(fcport
->port_name
);
1120 else if ((fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1121 && time_after_eq(jiffies
,
1122 fcport
->plogi_nack_done_deadline
))
1128 /* initiator mode */
1133 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1134 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1135 rc
= qla2x00_find_new_loop_id(vha
, fcport
);
1137 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
1138 "%s %d %8phC post del sess - out of loopid\n",
1139 __func__
, __LINE__
, fcport
->port_name
);
1140 fcport
->scan_state
= 0;
1141 qlt_schedule_sess_for_deletion(fcport
);
1145 ql_dbg(ql_dbg_disc
, vha
, 0x20bf,
1146 "%s %d %8phC post login\n",
1147 __func__
, __LINE__
, fcport
->port_name
);
1148 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
1152 int qla24xx_fcport_handle_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1157 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1158 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
1159 __func__
, fcport
->port_name
, fcport
->disc_state
,
1160 fcport
->fw_login_state
, fcport
->login_pause
, fcport
->flags
,
1161 fcport
->conflict
, fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1162 fcport
->login_gen
, fcport
->login_retry
,
1163 fcport
->loop_id
, fcport
->scan_state
);
1165 if (fcport
->login_retry
== 0)
1168 if (fcport
->scan_state
!= QLA_FCPORT_FOUND
)
1171 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1172 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1175 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1176 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1177 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1182 /* for pure Target Mode. Login will not be initiated */
1183 if (vha
->host
->active_mode
== MODE_TARGET
)
1186 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1187 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1191 fcport
->login_retry
--;
1193 switch (fcport
->disc_state
) {
1195 wwn
= wwn_to_u64(fcport
->node_name
);
1197 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1198 "%s %d %8phC post GNNID\n",
1199 __func__
, __LINE__
, fcport
->port_name
);
1200 qla24xx_post_gnnid_work(vha
, fcport
);
1201 } else if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1202 ql_dbg(ql_dbg_disc
, vha
, 0x20bd,
1203 "%s %d %8phC post gnl\n",
1204 __func__
, __LINE__
, fcport
->port_name
);
1205 qla24xx_post_gnl_work(vha
, fcport
);
1207 qla_chk_n2n_b4_login(vha
, fcport
);
1212 if (fcport
->login_pause
) {
1213 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1214 fcport
->last_login_gen
= fcport
->login_gen
;
1215 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1219 qla_chk_n2n_b4_login(vha
, fcport
);
1222 case DSC_LOGIN_FAILED
:
1223 ql_dbg(ql_dbg_disc
, vha
, 0x20d0,
1224 "%s %d %8phC post gidpn\n",
1225 __func__
, __LINE__
, fcport
->port_name
);
1226 if (N2N_TOPO(vha
->hw
))
1227 qla_chk_n2n_b4_login(vha
, fcport
);
1229 qla24xx_post_gidpn_work(vha
, fcport
);
1232 case DSC_LOGIN_COMPLETE
:
1233 /* recheck login state */
1234 ql_dbg(ql_dbg_disc
, vha
, 0x20d1,
1235 "%s %d %8phC post adisc\n",
1236 __func__
, __LINE__
, fcport
->port_name
);
1237 data
[0] = data
[1] = 0;
1238 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
1249 void qla24xx_handle_rscn_event(fc_port_t
*fcport
, struct event_arg
*ea
)
1253 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210c,
1254 "%s %8phC DS %d LS %d\n",
1255 __func__
, fcport
->port_name
, fcport
->disc_state
,
1256 fcport
->fw_login_state
);
1258 if (fcport
->flags
& FCF_ASYNC_SENT
)
1261 switch (fcport
->disc_state
) {
1263 case DSC_LOGIN_COMPLETE
:
1264 qla24xx_post_gpnid_work(fcport
->vha
, &ea
->id
);
1271 int qla24xx_post_newsess_work(struct scsi_qla_host
*vha
, port_id_t
*id
,
1272 u8
*port_name
, u8
*node_name
, void *pla
, u8 fc4_type
)
1274 struct qla_work_evt
*e
;
1275 e
= qla2x00_alloc_work(vha
, QLA_EVT_NEW_SESS
);
1277 return QLA_FUNCTION_FAILED
;
1279 e
->u
.new_sess
.id
= *id
;
1280 e
->u
.new_sess
.pla
= pla
;
1281 e
->u
.new_sess
.fc4_type
= fc4_type
;
1282 memcpy(e
->u
.new_sess
.port_name
, port_name
, WWN_SIZE
);
1284 memcpy(e
->u
.new_sess
.node_name
, node_name
, WWN_SIZE
);
1286 return qla2x00_post_work(vha
, e
);
1290 void qla24xx_handle_relogin_event(scsi_qla_host_t
*vha
,
1291 struct event_arg
*ea
)
1293 fc_port_t
*fcport
= ea
->fcport
;
1295 ql_dbg(ql_dbg_disc
, vha
, 0x2102,
1296 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1297 __func__
, fcport
->port_name
, fcport
->disc_state
,
1298 fcport
->fw_login_state
, fcport
->login_pause
,
1299 fcport
->deleted
, fcport
->conflict
,
1300 fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1301 fcport
->last_login_gen
, fcport
->login_gen
,
1304 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1305 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1308 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1309 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1310 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1315 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1316 fcport
->login_retry
++;
1317 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1321 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
1322 fcport
->login_retry
++;
1326 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
1327 ql_dbg(ql_dbg_disc
, vha
, 0x20e9, "%s %d %8phC post gidpn\n",
1328 __func__
, __LINE__
, fcport
->port_name
);
1330 qla24xx_post_gidpn_work(vha
, fcport
);
1334 qla24xx_fcport_handle_login(vha
, fcport
);
1337 void qla2x00_fcport_event_handler(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1340 uint32_t id
= 0, mask
, rid
;
1341 unsigned long flags
;
1343 switch (ea
->event
) {
1345 case FCME_GIDPN_DONE
:
1346 case FCME_GPSC_DONE
:
1347 case FCME_GPNID_DONE
:
1348 case FCME_GNNID_DONE
:
1349 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
1350 test_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))
1357 switch (ea
->event
) {
1359 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1362 qla24xx_handle_relogin_event(vha
, ea
);
1365 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1367 switch (ea
->id
.b
.rsvd_1
) {
1368 case RSCN_PORT_ADDR
:
1369 spin_lock_irqsave(&vha
->work_lock
, flags
);
1370 if (vha
->scan
.scan_flags
== 0) {
1371 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1372 "%s: schedule\n", __func__
);
1373 vha
->scan
.scan_flags
|= SF_QUEUED
;
1374 schedule_delayed_work(&vha
->scan
.scan_work
, 5);
1376 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1379 case RSCN_AREA_ADDR
:
1381 if (ea
->id
.b
.rsvd_1
== RSCN_AREA_ADDR
) {
1383 ql_dbg(ql_dbg_async
, vha
, 0x5044,
1384 "RSCN: Area 0x%06x was affected\n",
1388 ql_dbg(ql_dbg_async
, vha
, 0x507a,
1389 "RSCN: Domain 0x%06x was affected\n",
1393 rid
= ea
->id
.b24
& mask
;
1394 list_for_each_entry_safe(f
, tf
, &vha
->vp_fcports
,
1396 id
= f
->d_id
.b24
& mask
;
1399 qla24xx_handle_rscn_event(f
, ea
);
1405 ql_log(ql_log_warn
, vha
, 0xd045,
1406 "RSCN: Fabric was affected. Addr format %d\n",
1408 qla2x00_mark_all_devices_lost(vha
, 1);
1409 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1410 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1413 case FCME_GIDPN_DONE
:
1414 qla24xx_handle_gidpn_event(vha
, ea
);
1417 qla24xx_handle_gnl_done_event(vha
, ea
);
1419 case FCME_GPSC_DONE
:
1420 qla24xx_handle_gpsc_event(vha
, ea
);
1422 case FCME_PLOGI_DONE
: /* Initiator side sent LLIOCB */
1423 qla24xx_handle_plogi_done_event(vha
, ea
);
1425 case FCME_PRLI_DONE
:
1426 qla24xx_handle_prli_done_event(vha
, ea
);
1428 case FCME_GPDB_DONE
:
1429 qla24xx_handle_gpdb_event(vha
, ea
);
1431 case FCME_GPNID_DONE
:
1432 qla24xx_handle_gpnid_event(vha
, ea
);
1434 case FCME_GFFID_DONE
:
1435 qla24xx_handle_gffid_event(vha
, ea
);
1437 case FCME_ADISC_DONE
:
1438 qla24xx_handle_adisc_event(vha
, ea
);
1440 case FCME_GNNID_DONE
:
1441 qla24xx_handle_gnnid_event(vha
, ea
);
1443 case FCME_GFPNID_DONE
:
1444 qla24xx_handle_gfpnid_event(vha
, ea
);
1453 qla2x00_tmf_iocb_timeout(void *data
)
1456 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1458 tmf
->u
.tmf
.comp_status
= CS_TIMEOUT
;
1459 complete(&tmf
->u
.tmf
.comp
);
1463 qla2x00_tmf_sp_done(void *ptr
, int res
)
1466 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1468 complete(&tmf
->u
.tmf
.comp
);
1472 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
1475 struct scsi_qla_host
*vha
= fcport
->vha
;
1476 struct srb_iocb
*tm_iocb
;
1478 int rval
= QLA_FUNCTION_FAILED
;
1480 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1484 tm_iocb
= &sp
->u
.iocb_cmd
;
1485 sp
->type
= SRB_TM_CMD
;
1487 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1488 tm_iocb
->u
.tmf
.flags
= flags
;
1489 tm_iocb
->u
.tmf
.lun
= lun
;
1490 tm_iocb
->u
.tmf
.data
= tag
;
1491 sp
->done
= qla2x00_tmf_sp_done
;
1492 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
1493 init_completion(&tm_iocb
->u
.tmf
.comp
);
1495 rval
= qla2x00_start_sp(sp
);
1496 if (rval
!= QLA_SUCCESS
)
1499 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
1500 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1501 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1502 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1504 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
1506 rval
= tm_iocb
->u
.tmf
.comp_status
== CS_COMPLETE
?
1507 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1509 if ((rval
!= QLA_SUCCESS
) || tm_iocb
->u
.tmf
.data
) {
1510 ql_dbg(ql_dbg_taskm
, vha
, 0x8030,
1511 "TM IOCB failed (%x).\n", rval
);
1514 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
1515 flags
= tm_iocb
->u
.tmf
.flags
;
1516 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
1518 /* Issue Marker IOCB */
1519 qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
1520 vha
->hw
->rsp_q_map
[0], sp
->fcport
->loop_id
, lun
,
1521 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
1526 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1532 qla24xx_abort_iocb_timeout(void *data
)
1535 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1537 abt
->u
.abt
.comp_status
= CS_TIMEOUT
;
1538 complete(&abt
->u
.abt
.comp
);
1542 qla24xx_abort_sp_done(void *ptr
, int res
)
1545 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1547 complete(&abt
->u
.abt
.comp
);
1551 qla24xx_async_abort_cmd(srb_t
*cmd_sp
)
1553 scsi_qla_host_t
*vha
= cmd_sp
->vha
;
1554 fc_port_t
*fcport
= cmd_sp
->fcport
;
1555 struct srb_iocb
*abt_iocb
;
1557 int rval
= QLA_FUNCTION_FAILED
;
1559 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1563 abt_iocb
= &sp
->u
.iocb_cmd
;
1564 sp
->type
= SRB_ABT_CMD
;
1566 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1567 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
1569 if (vha
->flags
.qpairs_available
&& cmd_sp
->qpair
)
1570 abt_iocb
->u
.abt
.req_que_no
=
1571 cpu_to_le16(cmd_sp
->qpair
->req
->id
);
1573 abt_iocb
->u
.abt
.req_que_no
= cpu_to_le16(vha
->req
->id
);
1575 sp
->done
= qla24xx_abort_sp_done
;
1576 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
1577 init_completion(&abt_iocb
->u
.abt
.comp
);
1579 rval
= qla2x00_start_sp(sp
);
1580 if (rval
!= QLA_SUCCESS
)
1583 ql_dbg(ql_dbg_async
, vha
, 0x507c,
1584 "Abort command issued - hdl=%x, target_id=%x\n",
1585 cmd_sp
->handle
, fcport
->tgt_id
);
1587 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
1589 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
1590 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1599 qla24xx_async_abort_command(srb_t
*sp
)
1601 unsigned long flags
= 0;
1604 fc_port_t
*fcport
= sp
->fcport
;
1605 struct scsi_qla_host
*vha
= fcport
->vha
;
1606 struct qla_hw_data
*ha
= vha
->hw
;
1607 struct req_que
*req
= vha
->req
;
1609 if (vha
->flags
.qpairs_available
&& sp
->qpair
)
1610 req
= sp
->qpair
->req
;
1612 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1613 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
1614 if (req
->outstanding_cmds
[handle
] == sp
)
1617 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1618 if (handle
== req
->num_outstanding_cmds
) {
1619 /* Command not found. */
1620 return QLA_FUNCTION_FAILED
;
1622 if (sp
->type
== SRB_FXIOCB_DCMD
)
1623 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
1624 FXDISC_ABORT_IOCTL
);
1626 return qla24xx_async_abort_cmd(sp
);
1630 qla24xx_handle_prli_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1632 switch (ea
->data
[0]) {
1633 case MBS_COMMAND_COMPLETE
:
1634 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1635 "%s %d %8phC post gpdb\n",
1636 __func__
, __LINE__
, ea
->fcport
->port_name
);
1638 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1639 ea
->fcport
->logout_on_delete
= 1;
1640 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1643 if (ea
->fcport
->n2n_flag
) {
1644 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1645 "%s %d %8phC post fc4 prli\n",
1646 __func__
, __LINE__
, ea
->fcport
->port_name
);
1647 ea
->fcport
->fc4f_nvme
= 0;
1648 ea
->fcport
->n2n_flag
= 0;
1649 qla24xx_post_prli_work(vha
, ea
->fcport
);
1651 ql_dbg(ql_dbg_disc
, vha
, 0x2119,
1652 "%s %d %8phC unhandle event of %x\n",
1653 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[0]);
1659 qla24xx_handle_plogi_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1661 port_id_t cid
; /* conflict Nport id */
1663 struct fc_port
*conflict_fcport
;
1664 unsigned long flags
;
1665 struct fc_port
*fcport
= ea
->fcport
;
1667 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1668 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1669 __func__
, fcport
->port_name
, fcport
->disc_state
,
1670 fcport
->fw_login_state
, ea
->rc
, ea
->sp
->gen2
, fcport
->login_gen
,
1671 ea
->sp
->gen2
, fcport
->rscn_gen
|ea
->sp
->gen1
,
1672 ea
->data
[0], ea
->data
[1], ea
->iop
[0], ea
->iop
[1]);
1674 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1675 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)) {
1676 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1677 "%s %d %8phC Remote is trying to login\n",
1678 __func__
, __LINE__
, fcport
->port_name
);
1682 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1685 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1686 /* target side must have changed it. */
1687 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1688 "%s %8phC generation changed\n",
1689 __func__
, fcport
->port_name
);
1690 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1692 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1693 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
1694 __func__
, __LINE__
, fcport
->port_name
);
1695 qla24xx_post_gidpn_work(vha
, fcport
);
1699 switch (ea
->data
[0]) {
1700 case MBS_COMMAND_COMPLETE
:
1702 * Driver must validate login state - If PRLI not complete,
1703 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1706 if (ea
->fcport
->fc4f_nvme
) {
1707 ql_dbg(ql_dbg_disc
, vha
, 0x2117,
1708 "%s %d %8phC post prli\n",
1709 __func__
, __LINE__
, ea
->fcport
->port_name
);
1710 qla24xx_post_prli_work(vha
, ea
->fcport
);
1712 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1713 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1714 __func__
, __LINE__
, ea
->fcport
->port_name
,
1715 ea
->fcport
->loop_id
, ea
->fcport
->d_id
.b24
);
1717 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1718 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1719 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1720 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1721 ea
->fcport
->logout_on_delete
= 1;
1722 ea
->fcport
->send_els_logo
= 0;
1723 ea
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
1724 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1726 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1729 case MBS_COMMAND_ERROR
:
1730 ql_dbg(ql_dbg_disc
, vha
, 0x20eb, "%s %d %8phC cmd error %x\n",
1731 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[1]);
1733 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1734 ea
->fcport
->disc_state
= DSC_LOGIN_FAILED
;
1735 if (ea
->data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1736 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1738 qla2x00_mark_device_lost(vha
, ea
->fcport
, 1, 0);
1740 case MBS_LOOP_ID_USED
:
1741 /* data[1] = IO PARAM 1 = nport ID */
1742 cid
.b
.domain
= (ea
->iop
[1] >> 16) & 0xff;
1743 cid
.b
.area
= (ea
->iop
[1] >> 8) & 0xff;
1744 cid
.b
.al_pa
= ea
->iop
[1] & 0xff;
1747 ql_dbg(ql_dbg_disc
, vha
, 0x20ec,
1748 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1749 __func__
, __LINE__
, ea
->fcport
->port_name
,
1750 ea
->fcport
->loop_id
);
1752 if (IS_SW_RESV_ADDR(cid
)) {
1753 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1754 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1756 qla2x00_clear_loop_id(ea
->fcport
);
1758 qla24xx_post_gnl_work(vha
, ea
->fcport
);
1760 case MBS_PORT_ID_USED
:
1761 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1762 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1763 __func__
, __LINE__
, ea
->fcport
->port_name
,
1764 ea
->fcport
->d_id
.b
.domain
, ea
->fcport
->d_id
.b
.area
,
1765 ea
->fcport
->d_id
.b
.al_pa
);
1767 lid
= ea
->iop
[1] & 0xffff;
1768 qlt_find_sess_invalidate_other(vha
,
1769 wwn_to_u64(ea
->fcport
->port_name
),
1770 ea
->fcport
->d_id
, lid
, &conflict_fcport
);
1772 if (conflict_fcport
) {
1774 * Another fcport share the same loop_id/nport id.
1775 * Conflict fcport needs to finish cleanup before this
1776 * fcport can proceed to login.
1778 conflict_fcport
->conflict
= ea
->fcport
;
1779 ea
->fcport
->login_pause
= 1;
1781 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1782 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1783 __func__
, __LINE__
, ea
->fcport
->port_name
,
1784 ea
->fcport
->d_id
.b24
, lid
);
1785 qla2x00_clear_loop_id(ea
->fcport
);
1786 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
1788 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1789 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1790 __func__
, __LINE__
, ea
->fcport
->port_name
,
1791 ea
->fcport
->d_id
.b24
, lid
);
1793 qla2x00_clear_loop_id(ea
->fcport
);
1794 set_bit(lid
, vha
->hw
->loop_id_map
);
1795 ea
->fcport
->loop_id
= lid
;
1796 ea
->fcport
->keep_nport_handle
= 0;
1797 qlt_schedule_sess_for_deletion(ea
->fcport
);
1805 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
1808 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
1809 qlt_logo_completion_handler(fcport
, data
[0]);
1810 fcport
->login_gen
++;
1815 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
1818 if (data
[0] == MBS_COMMAND_COMPLETE
) {
1819 qla2x00_update_fcport(vha
, fcport
);
1825 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1826 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1827 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1829 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
1834 /****************************************************************************/
1835 /* QLogic ISP2x00 Hardware Support Functions. */
1836 /****************************************************************************/
1839 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
1841 int rval
= QLA_SUCCESS
;
1842 struct qla_hw_data
*ha
= vha
->hw
;
1843 uint32_t idc_major_ver
, idc_minor_ver
;
1846 qla83xx_idc_lock(vha
, 0);
1848 /* SV: TODO: Assign initialization timeout from
1849 * flash-info / other param
1851 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
1852 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
1854 /* Set our fcoe function presence */
1855 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
1856 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
1857 "Error while setting DRV-Presence.\n");
1858 rval
= QLA_FUNCTION_FAILED
;
1862 /* Decide the reset ownership */
1863 qla83xx_reset_ownership(vha
);
1866 * On first protocol driver load:
1867 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1869 * Others: Check compatibility with current IDC Major version.
1871 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
1872 if (ha
->flags
.nic_core_reset_owner
) {
1873 /* Set IDC Major version */
1874 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
1875 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
1877 /* Clearing IDC-Lock-Recovery register */
1878 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
1879 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
1881 * Clear further IDC participation if we are not compatible with
1882 * the current IDC Major Version.
1884 ql_log(ql_log_warn
, vha
, 0xb07d,
1885 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1886 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
1887 __qla83xx_clear_drv_presence(vha
);
1888 rval
= QLA_FUNCTION_FAILED
;
1891 /* Each function sets its supported Minor version. */
1892 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
1893 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
1894 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
1896 if (ha
->flags
.nic_core_reset_owner
) {
1897 memset(config
, 0, sizeof(config
));
1898 if (!qla81xx_get_port_config(vha
, config
))
1899 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
1903 rval
= qla83xx_idc_state_handler(vha
);
1906 qla83xx_idc_unlock(vha
, 0);
1912 * qla2x00_initialize_adapter
1916 * ha = adapter block pointer.
1922 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
1925 struct qla_hw_data
*ha
= vha
->hw
;
1926 struct req_que
*req
= ha
->req_q_map
[0];
1928 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
1929 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
1931 /* Clear adapter flags. */
1932 vha
->flags
.online
= 0;
1933 ha
->flags
.chip_reset_done
= 0;
1934 vha
->flags
.reset_active
= 0;
1935 ha
->flags
.pci_channel_io_perm_failure
= 0;
1936 ha
->flags
.eeh_busy
= 0;
1937 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
1938 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1939 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1940 vha
->device_flags
= DFLG_NO_CABLE
;
1942 vha
->flags
.management_server_logged_in
= 0;
1943 vha
->marker_needed
= 0;
1944 ha
->isp_abort_cnt
= 0;
1945 ha
->beacon_blink_led
= 0;
1947 set_bit(0, ha
->req_qid_map
);
1948 set_bit(0, ha
->rsp_qid_map
);
1950 ql_dbg(ql_dbg_init
, vha
, 0x0040,
1951 "Configuring PCI space...\n");
1952 rval
= ha
->isp_ops
->pci_config(vha
);
1954 ql_log(ql_log_warn
, vha
, 0x0044,
1955 "Unable to configure PCI space.\n");
1959 ha
->isp_ops
->reset_chip(vha
);
1961 rval
= qla2xxx_get_flash_info(vha
);
1963 ql_log(ql_log_fatal
, vha
, 0x004f,
1964 "Unable to validate FLASH data.\n");
1968 if (IS_QLA8044(ha
)) {
1969 qla8044_read_reset_template(vha
);
1971 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1972 * If DONRESET_BIT0 is set, drivers should not set dev_state
1973 * to NEED_RESET. But if NEED_RESET is set, drivers should
1974 * should honor the reset. */
1975 if (ql2xdontresethba
== 1)
1976 qla8044_set_idc_dontreset(vha
);
1979 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
1980 ql_dbg(ql_dbg_init
, vha
, 0x0061,
1981 "Configure NVRAM parameters...\n");
1983 ha
->isp_ops
->nvram_config(vha
);
1985 if (ha
->flags
.disable_serdes
) {
1986 /* Mask HBA via NVRAM settings? */
1987 ql_log(ql_log_info
, vha
, 0x0077,
1988 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
1989 return QLA_FUNCTION_FAILED
;
1992 ql_dbg(ql_dbg_init
, vha
, 0x0078,
1993 "Verifying loaded RISC code...\n");
1995 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
1996 rval
= ha
->isp_ops
->chip_diag(vha
);
1999 rval
= qla2x00_setup_chip(vha
);
2004 if (IS_QLA84XX(ha
)) {
2005 ha
->cs84xx
= qla84xx_get_chip(vha
);
2007 ql_log(ql_log_warn
, vha
, 0x00d0,
2008 "Unable to configure ISP84XX.\n");
2009 return QLA_FUNCTION_FAILED
;
2013 if (qla_ini_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
2014 rval
= qla2x00_init_rings(vha
);
2016 ha
->flags
.chip_reset_done
= 1;
2018 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
2019 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2020 rval
= qla84xx_init_chip(vha
);
2021 if (rval
!= QLA_SUCCESS
) {
2022 ql_log(ql_log_warn
, vha
, 0x00d4,
2023 "Unable to initialize ISP84XX.\n");
2024 qla84xx_put_chip(vha
);
2028 /* Load the NIC Core f/w if we are the first protocol driver. */
2029 if (IS_QLA8031(ha
)) {
2030 rval
= qla83xx_nic_core_fw_load(vha
);
2032 ql_log(ql_log_warn
, vha
, 0x0124,
2033 "Error in initializing NIC Core f/w.\n");
2036 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
2037 qla24xx_read_fcp_prio_cfg(vha
);
2039 if (IS_P3P_TYPE(ha
))
2040 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2042 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2048 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2051 * Returns 0 on success.
2054 qla2100_pci_config(scsi_qla_host_t
*vha
)
2057 unsigned long flags
;
2058 struct qla_hw_data
*ha
= vha
->hw
;
2059 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2061 pci_set_master(ha
->pdev
);
2062 pci_try_set_mwi(ha
->pdev
);
2064 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2065 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2066 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2068 pci_disable_rom(ha
->pdev
);
2070 /* Get PCI bus information. */
2071 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2072 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2073 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2079 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2082 * Returns 0 on success.
2085 qla2300_pci_config(scsi_qla_host_t
*vha
)
2088 unsigned long flags
= 0;
2090 struct qla_hw_data
*ha
= vha
->hw
;
2091 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2093 pci_set_master(ha
->pdev
);
2094 pci_try_set_mwi(ha
->pdev
);
2096 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2097 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2099 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2100 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2101 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2104 * If this is a 2300 card and not 2312, reset the
2105 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2106 * the 2310 also reports itself as a 2300 so we need to get the
2107 * fb revision level -- a 6 indicates it really is a 2300 and
2110 if (IS_QLA2300(ha
)) {
2111 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2114 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2115 for (cnt
= 0; cnt
< 30000; cnt
++) {
2116 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2122 /* Select FPM registers. */
2123 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2124 RD_REG_WORD(®
->ctrl_status
);
2126 /* Get the fb rev level */
2127 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
2129 if (ha
->fb_rev
== FPM_2300
)
2130 pci_clear_mwi(ha
->pdev
);
2132 /* Deselect FPM registers. */
2133 WRT_REG_WORD(®
->ctrl_status
, 0x0);
2134 RD_REG_WORD(®
->ctrl_status
);
2136 /* Release RISC module. */
2137 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2138 for (cnt
= 0; cnt
< 30000; cnt
++) {
2139 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
2145 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2148 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2150 pci_disable_rom(ha
->pdev
);
2152 /* Get PCI bus information. */
2153 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2154 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2155 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2161 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2164 * Returns 0 on success.
2167 qla24xx_pci_config(scsi_qla_host_t
*vha
)
2170 unsigned long flags
= 0;
2171 struct qla_hw_data
*ha
= vha
->hw
;
2172 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2174 pci_set_master(ha
->pdev
);
2175 pci_try_set_mwi(ha
->pdev
);
2177 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2178 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2179 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2180 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2182 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2184 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2185 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
2186 pcix_set_mmrbc(ha
->pdev
, 2048);
2188 /* PCIe -- adjust Maximum Read Request Size (2048). */
2189 if (pci_is_pcie(ha
->pdev
))
2190 pcie_set_readrq(ha
->pdev
, 4096);
2192 pci_disable_rom(ha
->pdev
);
2194 ha
->chip_revision
= ha
->pdev
->revision
;
2196 /* Get PCI bus information. */
2197 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2198 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
2199 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2205 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2208 * Returns 0 on success.
2211 qla25xx_pci_config(scsi_qla_host_t
*vha
)
2214 struct qla_hw_data
*ha
= vha
->hw
;
2216 pci_set_master(ha
->pdev
);
2217 pci_try_set_mwi(ha
->pdev
);
2219 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2220 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2221 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2222 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2224 /* PCIe -- adjust Maximum Read Request Size (2048). */
2225 if (pci_is_pcie(ha
->pdev
))
2226 pcie_set_readrq(ha
->pdev
, 4096);
2228 pci_disable_rom(ha
->pdev
);
2230 ha
->chip_revision
= ha
->pdev
->revision
;
2236 * qla2x00_isp_firmware() - Choose firmware image.
2239 * Returns 0 on success.
2242 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
2245 uint16_t loop_id
, topo
, sw_cap
;
2246 uint8_t domain
, area
, al_pa
;
2247 struct qla_hw_data
*ha
= vha
->hw
;
2249 /* Assume loading risc code */
2250 rval
= QLA_FUNCTION_FAILED
;
2252 if (ha
->flags
.disable_risc_code_load
) {
2253 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
2255 /* Verify checksum of loaded RISC code. */
2256 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
2257 if (rval
== QLA_SUCCESS
) {
2258 /* And, verify we are not in ROM code. */
2259 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
2260 &area
, &domain
, &topo
, &sw_cap
);
2265 ql_dbg(ql_dbg_init
, vha
, 0x007a,
2266 "**** Load RISC code ****.\n");
2272 * qla2x00_reset_chip() - Reset ISP chip.
2275 * Returns 0 on success.
2278 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
2280 unsigned long flags
= 0;
2281 struct qla_hw_data
*ha
= vha
->hw
;
2282 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2286 if (unlikely(pci_channel_offline(ha
->pdev
)))
2289 ha
->isp_ops
->disable_intrs(ha
);
2291 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2293 /* Turn off master enable */
2295 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
2296 cmd
&= ~PCI_COMMAND_MASTER
;
2297 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2299 if (!IS_QLA2100(ha
)) {
2301 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2302 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2303 for (cnt
= 0; cnt
< 30000; cnt
++) {
2304 if ((RD_REG_WORD(®
->hccr
) &
2305 HCCR_RISC_PAUSE
) != 0)
2310 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2314 /* Select FPM registers. */
2315 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2316 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2318 /* FPM Soft Reset. */
2319 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
2320 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2322 /* Toggle Fpm Reset. */
2323 if (!IS_QLA2200(ha
)) {
2324 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
2325 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2328 /* Select frame buffer registers. */
2329 WRT_REG_WORD(®
->ctrl_status
, 0x10);
2330 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2332 /* Reset frame buffer FIFOs. */
2333 if (IS_QLA2200(ha
)) {
2334 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
2335 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
2337 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
2339 /* Read back fb_cmd until zero or 3 seconds max */
2340 for (cnt
= 0; cnt
< 3000; cnt
++) {
2341 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
2347 /* Select RISC module registers. */
2348 WRT_REG_WORD(®
->ctrl_status
, 0);
2349 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2351 /* Reset RISC processor. */
2352 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2353 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2355 /* Release RISC processor. */
2356 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2357 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2360 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
2361 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
2363 /* Reset ISP chip. */
2364 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2366 /* Wait for RISC to recover from reset. */
2367 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2369 * It is necessary to for a delay here since the card doesn't
2370 * respond to PCI reads during a reset. On some architectures
2371 * this will result in an MCA.
2374 for (cnt
= 30000; cnt
; cnt
--) {
2375 if ((RD_REG_WORD(®
->ctrl_status
) &
2376 CSR_ISP_SOFT_RESET
) == 0)
2383 /* Reset RISC processor. */
2384 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2386 WRT_REG_WORD(®
->semaphore
, 0);
2388 /* Release RISC processor. */
2389 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2390 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2392 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2393 for (cnt
= 0; cnt
< 30000; cnt
++) {
2394 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
2402 /* Turn on master enable */
2403 cmd
|= PCI_COMMAND_MASTER
;
2404 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2406 /* Disable RISC pause on FPM parity error. */
2407 if (!IS_QLA2100(ha
)) {
2408 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
2409 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2412 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2416 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2419 * Returns 0 on success.
2422 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
2424 uint16_t mb
[4] = {0x1010, 0, 1, 0};
2426 if (!IS_QLA81XX(vha
->hw
))
2429 return qla81xx_write_mpi_register(vha
, mb
);
2433 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2436 * Returns 0 on success.
2439 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
2441 unsigned long flags
= 0;
2442 struct qla_hw_data
*ha
= vha
->hw
;
2443 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2446 static int abts_cnt
; /* ISP abort retry counts */
2447 int rval
= QLA_SUCCESS
;
2449 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2452 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2453 for (cnt
= 0; cnt
< 30000; cnt
++) {
2454 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
2460 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
))
2461 set_bit(DMA_SHUTDOWN_CMPL
, &ha
->fw_dump_cap_flags
);
2463 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017e,
2464 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2465 RD_REG_DWORD(®
->hccr
),
2466 RD_REG_DWORD(®
->ctrl_status
),
2467 (RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
));
2469 WRT_REG_DWORD(®
->ctrl_status
,
2470 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2471 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2475 /* Wait for firmware to complete NVRAM accesses. */
2476 RD_REG_WORD(®
->mailbox0
);
2477 for (cnt
= 10000; RD_REG_WORD(®
->mailbox0
) != 0 &&
2478 rval
== QLA_SUCCESS
; cnt
--) {
2483 rval
= QLA_FUNCTION_TIMEOUT
;
2486 if (rval
== QLA_SUCCESS
)
2487 set_bit(ISP_MBX_RDY
, &ha
->fw_dump_cap_flags
);
2489 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017f,
2490 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2491 RD_REG_DWORD(®
->hccr
),
2492 RD_REG_DWORD(®
->mailbox0
));
2494 /* Wait for soft-reset to complete. */
2495 RD_REG_DWORD(®
->ctrl_status
);
2496 for (cnt
= 0; cnt
< 60; cnt
++) {
2498 if ((RD_REG_DWORD(®
->ctrl_status
) &
2499 CSRX_ISP_SOFT_RESET
) == 0)
2504 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_ISP_SOFT_RESET
))
2505 set_bit(ISP_SOFT_RESET_CMPL
, &ha
->fw_dump_cap_flags
);
2507 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015d,
2508 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2509 RD_REG_DWORD(®
->hccr
),
2510 RD_REG_DWORD(®
->ctrl_status
));
2512 /* If required, do an MPI FW reset now */
2513 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
2514 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
2515 if (++abts_cnt
< 5) {
2516 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2517 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
2520 * We exhausted the ISP abort retries. We have to
2521 * set the board offline.
2524 vha
->flags
.online
= 0;
2529 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
2530 RD_REG_DWORD(®
->hccr
);
2532 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
2533 RD_REG_DWORD(®
->hccr
);
2535 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
2536 RD_REG_DWORD(®
->hccr
);
2538 RD_REG_WORD(®
->mailbox0
);
2539 for (cnt
= 60; RD_REG_WORD(®
->mailbox0
) != 0 &&
2540 rval
== QLA_SUCCESS
; cnt
--) {
2545 rval
= QLA_FUNCTION_TIMEOUT
;
2547 if (rval
== QLA_SUCCESS
)
2548 set_bit(RISC_RDY_AFT_RESET
, &ha
->fw_dump_cap_flags
);
2550 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015e,
2551 "Host Risc 0x%x, mailbox0 0x%x\n",
2552 RD_REG_DWORD(®
->hccr
),
2553 RD_REG_WORD(®
->mailbox0
));
2555 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2557 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015f,
2558 "Driver in %s mode\n",
2559 IS_NOPOLLING_TYPE(ha
) ? "Interrupt" : "Polling");
2561 if (IS_NOPOLLING_TYPE(ha
))
2562 ha
->isp_ops
->enable_intrs(ha
);
2568 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
2570 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2572 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2573 *data
= RD_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
);
2578 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
2580 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2582 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2583 WRT_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
, data
);
2587 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
2590 uint delta_msec
= 100;
2591 uint elapsed_msec
= 0;
2595 if (vha
->hw
->pdev
->subsystem_device
!= 0x0175 &&
2596 vha
->hw
->pdev
->subsystem_device
!= 0x0240)
2599 WRT_REG_DWORD(&vha
->hw
->iobase
->isp24
.hccr
, HCCRX_SET_RISC_PAUSE
);
2603 timeout_msec
= TIMEOUT_SEMAPHORE
;
2604 n
= timeout_msec
/ delta_msec
;
2606 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
2607 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2608 if (wd32
& RISC_SEMAPHORE
)
2611 elapsed_msec
+= delta_msec
;
2612 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2616 if (!(wd32
& RISC_SEMAPHORE
))
2619 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2622 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
2623 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
2624 n
= timeout_msec
/ delta_msec
;
2626 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2627 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2630 elapsed_msec
+= delta_msec
;
2631 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2635 if (wd32
& RISC_SEMAPHORE_FORCE
)
2636 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
2641 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
2648 * qla24xx_reset_chip() - Reset ISP24xx chip.
2651 * Returns 0 on success.
2654 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
2656 struct qla_hw_data
*ha
= vha
->hw
;
2658 if (pci_channel_offline(ha
->pdev
) &&
2659 ha
->flags
.pci_channel_io_perm_failure
) {
2663 ha
->isp_ops
->disable_intrs(ha
);
2665 qla25xx_manipulate_risc_semaphore(vha
);
2667 /* Perform RISC reset. */
2668 qla24xx_reset_risc(vha
);
2672 * qla2x00_chip_diag() - Test chip for proper operation.
2675 * Returns 0 on success.
2678 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
2681 struct qla_hw_data
*ha
= vha
->hw
;
2682 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2683 unsigned long flags
= 0;
2687 struct req_que
*req
= ha
->req_q_map
[0];
2689 /* Assume a failed state */
2690 rval
= QLA_FUNCTION_FAILED
;
2692 ql_dbg(ql_dbg_init
, vha
, 0x007b, "Testing device at %p.\n",
2693 ®
->flash_address
);
2695 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2697 /* Reset ISP chip. */
2698 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2701 * We need to have a delay here since the card will not respond while
2702 * in reset causing an MCA on some architectures.
2705 data
= qla2x00_debounce_register(®
->ctrl_status
);
2706 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
2708 data
= RD_REG_WORD(®
->ctrl_status
);
2713 goto chip_diag_failed
;
2715 ql_dbg(ql_dbg_init
, vha
, 0x007c,
2716 "Reset register cleared by chip reset.\n");
2718 /* Reset RISC processor. */
2719 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2720 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2722 /* Workaround for QLA2312 PCI parity error */
2723 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2724 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
2725 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
2727 data
= RD_MAILBOX_REG(ha
, reg
, 0);
2734 goto chip_diag_failed
;
2736 /* Check product ID of chip */
2737 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product ID of chip.\n");
2739 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
2740 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
2741 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
2742 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
2743 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
2744 mb
[3] != PROD_ID_3
) {
2745 ql_log(ql_log_warn
, vha
, 0x0062,
2746 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2747 mb
[1], mb
[2], mb
[3]);
2749 goto chip_diag_failed
;
2751 ha
->product_id
[0] = mb
[1];
2752 ha
->product_id
[1] = mb
[2];
2753 ha
->product_id
[2] = mb
[3];
2754 ha
->product_id
[3] = mb
[4];
2756 /* Adjust fw RISC transfer size */
2757 if (req
->length
> 1024)
2758 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
2760 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
2763 if (IS_QLA2200(ha
) &&
2764 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
2765 /* Limit firmware transfer size with a 2200A */
2766 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
2768 ha
->device_type
|= DT_ISP2200A
;
2769 ha
->fw_transfer_size
= 128;
2772 /* Wrap Incoming Mailboxes Test. */
2773 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2775 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
2776 rval
= qla2x00_mbx_reg_test(vha
);
2778 ql_log(ql_log_warn
, vha
, 0x0080,
2779 "Failed mailbox send register test.\n");
2781 /* Flag a successful rval */
2783 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2787 ql_log(ql_log_info
, vha
, 0x0081,
2788 "Chip diagnostics **** FAILED ****.\n");
2790 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2796 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2799 * Returns 0 on success.
2802 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
2805 struct qla_hw_data
*ha
= vha
->hw
;
2806 struct req_que
*req
= ha
->req_q_map
[0];
2808 if (IS_P3P_TYPE(ha
))
2811 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
2813 rval
= qla2x00_mbx_reg_test(vha
);
2815 ql_log(ql_log_warn
, vha
, 0x0082,
2816 "Failed mailbox send register test.\n");
2818 /* Flag a successful rval */
2826 qla2x00_alloc_offload_mem(scsi_qla_host_t
*vha
)
2831 struct qla_hw_data
*ha
= vha
->hw
;
2834 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
2835 "%s: Offload Mem is already allocated.\n",
2840 if (IS_FWI2_CAPABLE(ha
)) {
2841 /* Allocate memory for Fibre Channel Event Buffer. */
2842 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2847 dma_free_coherent(&ha
->pdev
->dev
,
2848 FCE_SIZE
, ha
->fce
, ha
->fce_dma
);
2850 /* Allocate memory for Fibre Channel Event Buffer. */
2851 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
2854 ql_log(ql_log_warn
, vha
, 0x00be,
2855 "Unable to allocate (%d KB) for FCE.\n",
2860 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
2861 ha
->fce_mb
, &ha
->fce_bufs
);
2863 ql_log(ql_log_warn
, vha
, 0x00bf,
2864 "Unable to initialize FCE (%d).\n", rval
);
2865 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
2867 ha
->flags
.fce_enabled
= 0;
2870 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
2871 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
2873 ha
->flags
.fce_enabled
= 1;
2874 ha
->fce_dma
= tc_dma
;
2879 dma_free_coherent(&ha
->pdev
->dev
,
2880 EFT_SIZE
, ha
->eft
, ha
->eft_dma
);
2882 /* Allocate memory for Extended Trace Buffer. */
2883 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
2886 ql_log(ql_log_warn
, vha
, 0x00c1,
2887 "Unable to allocate (%d KB) for EFT.\n",
2892 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
2894 ql_log(ql_log_warn
, vha
, 0x00c2,
2895 "Unable to initialize EFT (%d).\n", rval
);
2896 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
2900 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
2901 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
2903 ha
->eft_dma
= tc_dma
;
2912 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
2914 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
2915 eft_size
, fce_size
, mq_size
;
2916 struct qla_hw_data
*ha
= vha
->hw
;
2917 struct req_que
*req
= ha
->req_q_map
[0];
2918 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
2919 struct qla2xxx_fw_dump
*fw_dump
;
2921 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
2922 req_q_size
= rsp_q_size
= 0;
2924 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2925 fixed_size
= sizeof(struct qla2100_fw_dump
);
2926 } else if (IS_QLA23XX(ha
)) {
2927 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
2928 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
2930 } else if (IS_FWI2_CAPABLE(ha
)) {
2931 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))
2932 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
2933 else if (IS_QLA81XX(ha
))
2934 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
2935 else if (IS_QLA25XX(ha
))
2936 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
2938 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
2940 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
2943 if (!IS_QLA83XX(ha
) && !IS_QLA27XX(ha
))
2944 mq_size
= sizeof(struct qla2xxx_mq_chain
);
2946 * Allocate maximum buffer size for all queues.
2947 * Resizing must be done at end-of-dump processing.
2949 mq_size
+= ha
->max_req_queues
*
2950 (req
->length
* sizeof(request_t
));
2951 mq_size
+= ha
->max_rsp_queues
*
2952 (rsp
->length
* sizeof(response_t
));
2954 if (ha
->tgt
.atio_ring
)
2955 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
2956 /* Allocate memory for Fibre Channel Event Buffer. */
2957 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2961 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
2963 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
2964 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
2965 eft_size
= EFT_SIZE
;
2968 if (IS_QLA27XX(ha
)) {
2969 if (!ha
->fw_dump_template
) {
2970 ql_log(ql_log_warn
, vha
, 0x00ba,
2971 "Failed missing fwdump template\n");
2974 dump_size
= qla27xx_fwdt_calculate_dump_size(vha
);
2975 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
2976 "-> allocating fwdump (%x bytes)...\n", dump_size
);
2980 req_q_size
= req
->length
* sizeof(request_t
);
2981 rsp_q_size
= rsp
->length
* sizeof(response_t
);
2982 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
2983 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
2984 ha
->chain_offset
= dump_size
;
2985 dump_size
+= mq_size
+ fce_size
;
2987 if (ha
->exchoffld_buf
)
2988 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
2990 if (ha
->exlogin_buf
)
2991 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
2995 if (!ha
->fw_dump_len
|| dump_size
!= ha
->fw_dump_len
) {
2996 fw_dump
= vmalloc(dump_size
);
2998 ql_log(ql_log_warn
, vha
, 0x00c4,
2999 "Unable to allocate (%d KB) for firmware dump.\n",
3004 ha
->fw_dump
= fw_dump
;
3006 ha
->fw_dump_len
= dump_size
;
3007 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3008 "Allocated (%d KB) for firmware dump.\n",
3014 ha
->fw_dump
->signature
[0] = 'Q';
3015 ha
->fw_dump
->signature
[1] = 'L';
3016 ha
->fw_dump
->signature
[2] = 'G';
3017 ha
->fw_dump
->signature
[3] = 'C';
3018 ha
->fw_dump
->version
= htonl(1);
3020 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
3021 ha
->fw_dump
->mem_size
= htonl(mem_size
);
3022 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
3023 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
3025 ha
->fw_dump
->eft_size
= htonl(eft_size
);
3026 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
3027 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
3029 ha
->fw_dump
->header_size
=
3030 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
3036 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
3038 #define MPS_MASK 0xe0
3043 if (!IS_QLA81XX(vha
->hw
))
3046 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
3047 if (rval
!= QLA_SUCCESS
) {
3048 ql_log(ql_log_warn
, vha
, 0x0105,
3049 "Unable to acquire semaphore.\n");
3053 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
3054 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
3055 if (rval
!= QLA_SUCCESS
) {
3056 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
3061 if (dc
== (dw
& MPS_MASK
))
3066 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
3067 if (rval
!= QLA_SUCCESS
) {
3068 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
3072 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
3073 if (rval
!= QLA_SUCCESS
) {
3074 ql_log(ql_log_warn
, vha
, 0x006d,
3075 "Unable to release semaphore.\n");
3083 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
3085 /* Don't try to reallocate the array */
3086 if (req
->outstanding_cmds
)
3089 if (!IS_FWI2_CAPABLE(ha
))
3090 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
3092 if (ha
->cur_fw_xcb_count
<= ha
->cur_fw_iocb_count
)
3093 req
->num_outstanding_cmds
= ha
->cur_fw_xcb_count
;
3095 req
->num_outstanding_cmds
= ha
->cur_fw_iocb_count
;
3098 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
3099 req
->num_outstanding_cmds
, GFP_KERNEL
);
3101 if (!req
->outstanding_cmds
) {
3103 * Try to allocate a minimal size just so we can get through
3106 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
3107 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
3108 req
->num_outstanding_cmds
, GFP_KERNEL
);
3110 if (!req
->outstanding_cmds
) {
3111 ql_log(ql_log_fatal
, NULL
, 0x0126,
3112 "Failed to allocate memory for "
3113 "outstanding_cmds for req_que %p.\n", req
);
3114 req
->num_outstanding_cmds
= 0;
3115 return QLA_FUNCTION_FAILED
;
3122 #define PRINT_FIELD(_field, _flag, _str) { \
3123 if (a0->_field & _flag) {\
3129 len = snprintf(ptr, leftover, "%s", _str); \
3136 static void qla2xxx_print_sfp_info(struct scsi_qla_host
*vha
)
3139 struct sff_8247_a0
*a0
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3140 u8 str
[STR_LEN
], *ptr
, p
;
3143 memset(str
, 0, STR_LEN
);
3144 snprintf(str
, SFF_VEN_NAME_LEN
+1, a0
->vendor_name
);
3145 ql_dbg(ql_dbg_init
, vha
, 0x015a,
3146 "SFP MFG Name: %s\n", str
);
3148 memset(str
, 0, STR_LEN
);
3149 snprintf(str
, SFF_PART_NAME_LEN
+1, a0
->vendor_pn
);
3150 ql_dbg(ql_dbg_init
, vha
, 0x015c,
3151 "SFP Part Name: %s\n", str
);
3154 memset(str
, 0, STR_LEN
);
3158 PRINT_FIELD(fc_med_cc9
, FC_MED_TW
, "Twin AX");
3159 PRINT_FIELD(fc_med_cc9
, FC_MED_TP
, "Twisted Pair");
3160 PRINT_FIELD(fc_med_cc9
, FC_MED_MI
, "Min Coax");
3161 PRINT_FIELD(fc_med_cc9
, FC_MED_TV
, "Video Coax");
3162 PRINT_FIELD(fc_med_cc9
, FC_MED_M6
, "MultiMode 62.5um");
3163 PRINT_FIELD(fc_med_cc9
, FC_MED_M5
, "MultiMode 50um");
3164 PRINT_FIELD(fc_med_cc9
, FC_MED_SM
, "SingleMode");
3165 ql_dbg(ql_dbg_init
, vha
, 0x0160,
3166 "SFP Media: %s\n", str
);
3169 memset(str
, 0, STR_LEN
);
3173 PRINT_FIELD(fc_ll_cc7
, FC_LL_VL
, "Very Long");
3174 PRINT_FIELD(fc_ll_cc7
, FC_LL_S
, "Short");
3175 PRINT_FIELD(fc_ll_cc7
, FC_LL_I
, "Intermediate");
3176 PRINT_FIELD(fc_ll_cc7
, FC_LL_L
, "Long");
3177 PRINT_FIELD(fc_ll_cc7
, FC_LL_M
, "Medium");
3178 ql_dbg(ql_dbg_init
, vha
, 0x0196,
3179 "SFP Link Length: %s\n", str
);
3181 memset(str
, 0, STR_LEN
);
3185 PRINT_FIELD(fc_ll_cc7
, FC_LL_SA
, "Short Wave (SA)");
3186 PRINT_FIELD(fc_ll_cc7
, FC_LL_LC
, "Long Wave(LC)");
3187 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SN
, "Short Wave (SN)");
3188 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SL
, "Short Wave (SL)");
3189 PRINT_FIELD(fc_tec_cc8
, FC_TEC_LL
, "Long Wave (LL)");
3190 ql_dbg(ql_dbg_init
, vha
, 0x016e,
3191 "SFP FC Link Tech: %s\n", str
);
3194 ql_dbg(ql_dbg_init
, vha
, 0x016f,
3195 "SFP Distant: %d km\n", a0
->length_km
);
3196 if (a0
->length_100m
)
3197 ql_dbg(ql_dbg_init
, vha
, 0x0170,
3198 "SFP Distant: %d m\n", a0
->length_100m
*100);
3199 if (a0
->length_50um_10m
)
3200 ql_dbg(ql_dbg_init
, vha
, 0x0189,
3201 "SFP Distant (WL=50um): %d m\n", a0
->length_50um_10m
* 10);
3202 if (a0
->length_62um_10m
)
3203 ql_dbg(ql_dbg_init
, vha
, 0x018a,
3204 "SFP Distant (WL=62.5um): %d m\n", a0
->length_62um_10m
* 10);
3205 if (a0
->length_om4_10m
)
3206 ql_dbg(ql_dbg_init
, vha
, 0x0194,
3207 "SFP Distant (OM4): %d m\n", a0
->length_om4_10m
* 10);
3208 if (a0
->length_om3_10m
)
3209 ql_dbg(ql_dbg_init
, vha
, 0x0195,
3210 "SFP Distant (OM3): %d m\n", a0
->length_om3_10m
* 10);
3216 * QLA_SUCCESS: no action
3217 * QLA_INTERFACE_ERROR: SFP is not there.
3218 * QLA_FUNCTION_FAILED: detected New SFP
3221 qla24xx_detect_sfp(scsi_qla_host_t
*vha
)
3223 int rc
= QLA_SUCCESS
;
3224 struct sff_8247_a0
*a
;
3225 struct qla_hw_data
*ha
= vha
->hw
;
3227 if (!AUTO_DETECT_SFP_SUPPORT(vha
))
3230 rc
= qla2x00_read_sfp_dev(vha
, NULL
, 0);
3234 a
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3235 qla2xxx_print_sfp_info(vha
);
3237 if (a
->fc_ll_cc7
& FC_LL_VL
|| a
->fc_ll_cc7
& FC_LL_L
) {
3239 ha
->flags
.detected_lr_sfp
= 1;
3241 if (a
->length_km
> 5 || a
->length_100m
> 50)
3242 ha
->long_range_distance
= LR_DISTANCE_10K
;
3244 ha
->long_range_distance
= LR_DISTANCE_5K
;
3246 if (ha
->flags
.detected_lr_sfp
!= ha
->flags
.using_lr_setting
)
3247 ql_dbg(ql_dbg_async
, vha
, 0x507b,
3248 "Detected Long Range SFP.\n");
3251 ha
->flags
.detected_lr_sfp
= 0;
3252 if (ha
->flags
.using_lr_setting
)
3253 ql_dbg(ql_dbg_async
, vha
, 0x5084,
3254 "Detected Short Range SFP.\n");
3257 if (!vha
->flags
.init_done
)
3264 * qla2x00_setup_chip() - Load and start RISC firmware.
3267 * Returns 0 on success.
3270 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
3273 uint32_t srisc_address
= 0;
3274 struct qla_hw_data
*ha
= vha
->hw
;
3275 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3276 unsigned long flags
;
3277 uint16_t fw_major_version
;
3279 if (IS_P3P_TYPE(ha
)) {
3280 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3281 if (rval
== QLA_SUCCESS
) {
3282 qla2x00_stop_firmware(vha
);
3283 goto enable_82xx_npiv
;
3288 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3289 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3290 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3291 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3292 RD_REG_WORD(®
->hccr
);
3293 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3296 qla81xx_mpi_sync(vha
);
3298 /* Load firmware sequences */
3299 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3300 if (rval
== QLA_SUCCESS
) {
3301 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
3302 "Verifying Checksum of loaded RISC code.\n");
3304 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
3305 if (rval
== QLA_SUCCESS
) {
3306 /* Start firmware execution. */
3307 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3308 "Starting firmware.\n");
3311 ha
->flags
.exlogins_enabled
= 1;
3313 if (qla_is_exch_offld_enabled(vha
))
3314 ha
->flags
.exchoffld_enabled
= 1;
3316 rval
= qla2x00_execute_fw(vha
, srisc_address
);
3317 /* Retrieve firmware information. */
3318 if (rval
== QLA_SUCCESS
) {
3319 qla24xx_detect_sfp(vha
);
3321 rval
= qla2x00_set_exlogins_buffer(vha
);
3322 if (rval
!= QLA_SUCCESS
)
3325 rval
= qla2x00_set_exchoffld_buffer(vha
);
3326 if (rval
!= QLA_SUCCESS
)
3330 fw_major_version
= ha
->fw_major_version
;
3331 if (IS_P3P_TYPE(ha
))
3332 qla82xx_check_md_needed(vha
);
3334 rval
= qla2x00_get_fw_version(vha
);
3335 if (rval
!= QLA_SUCCESS
)
3337 ha
->flags
.npiv_supported
= 0;
3338 if (IS_QLA2XXX_MIDTYPE(ha
) &&
3339 (ha
->fw_attributes
& BIT_2
)) {
3340 ha
->flags
.npiv_supported
= 1;
3341 if ((!ha
->max_npiv_vports
) ||
3342 ((ha
->max_npiv_vports
+ 1) %
3343 MIN_MULTI_ID_FABRIC
))
3344 ha
->max_npiv_vports
=
3345 MIN_MULTI_ID_FABRIC
- 1;
3347 qla2x00_get_resource_cnts(vha
);
3350 * Allocate the array of outstanding commands
3351 * now that we know the firmware resources.
3353 rval
= qla2x00_alloc_outstanding_cmds(ha
,
3355 if (rval
!= QLA_SUCCESS
)
3358 if (!fw_major_version
&& !(IS_P3P_TYPE(ha
)))
3359 qla2x00_alloc_offload_mem(vha
);
3361 if (ql2xallocfwdump
&& !(IS_P3P_TYPE(ha
)))
3362 qla2x00_alloc_fw_dump(vha
);
3368 ql_log(ql_log_fatal
, vha
, 0x00cd,
3369 "ISP Firmware failed checksum.\n");
3375 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3376 /* Enable proper parity. */
3377 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3380 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
3382 /* SRAM, Instruction RAM and GP RAM parity */
3383 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
3384 RD_REG_WORD(®
->hccr
);
3385 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3389 ha
->flags
.fac_supported
= 1;
3390 else if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
3393 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
3394 if (rval
== QLA_SUCCESS
) {
3395 ha
->flags
.fac_supported
= 1;
3396 ha
->fdt_block_size
= size
<< 2;
3398 ql_log(ql_log_warn
, vha
, 0x00ce,
3399 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3400 ha
->fw_major_version
, ha
->fw_minor_version
,
3401 ha
->fw_subminor_version
);
3403 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3404 ha
->flags
.fac_supported
= 0;
3411 ql_log(ql_log_fatal
, vha
, 0x00cf,
3412 "Setup chip ****FAILED****.\n");
3419 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3420 * @rsp: response queue
3422 * Beginning of request ring has initialization control block already built
3423 * by nvram config routine.
3425 * Returns 0 on success.
3428 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
3433 rsp
->ring_ptr
= rsp
->ring
;
3434 rsp
->ring_index
= 0;
3435 rsp
->status_srb
= NULL
;
3436 pkt
= rsp
->ring_ptr
;
3437 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
3438 pkt
->signature
= RESPONSE_PROCESSED
;
3444 * qla2x00_update_fw_options() - Read and process firmware options.
3447 * Returns 0 on success.
3450 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
3452 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
3453 struct qla_hw_data
*ha
= vha
->hw
;
3455 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
3456 qla2x00_get_fw_options(vha
, ha
->fw_options
);
3458 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3461 /* Serial Link options. */
3462 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
3463 "Serial link options.\n");
3464 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
3465 (uint8_t *)&ha
->fw_seriallink_options
,
3466 sizeof(ha
->fw_seriallink_options
));
3468 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
3469 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
3470 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
3473 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
3474 emphasis
= (ha
->fw_seriallink_options
[2] &
3475 (BIT_4
| BIT_3
)) >> 3;
3476 tx_sens
= ha
->fw_seriallink_options
[0] &
3477 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3478 rx_sens
= (ha
->fw_seriallink_options
[0] &
3479 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3480 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
3481 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3484 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
3485 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3486 ha
->fw_options
[10] |= BIT_5
|
3487 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3488 (tx_sens
& (BIT_1
| BIT_0
));
3491 swing
= (ha
->fw_seriallink_options
[2] &
3492 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
3493 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
3494 tx_sens
= ha
->fw_seriallink_options
[1] &
3495 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3496 rx_sens
= (ha
->fw_seriallink_options
[1] &
3497 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3498 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
3499 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3502 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
3503 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3504 ha
->fw_options
[11] |= BIT_5
|
3505 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3506 (tx_sens
& (BIT_1
| BIT_0
));
3510 /* Return command IOCBs without waiting for an ABTS to complete. */
3511 ha
->fw_options
[3] |= BIT_13
;
3514 if (ha
->flags
.enable_led_scheme
)
3515 ha
->fw_options
[2] |= BIT_12
;
3517 /* Detect ISP6312. */
3519 ha
->fw_options
[2] |= BIT_13
;
3521 /* Set Retry FLOGI in case of P2P connection */
3522 if (ha
->operating_mode
== P2P
) {
3523 ha
->fw_options
[2] |= BIT_3
;
3524 ql_dbg(ql_dbg_disc
, vha
, 0x2100,
3525 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3526 __func__
, ha
->fw_options
[2]);
3529 /* Update firmware options. */
3530 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3534 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
3537 struct qla_hw_data
*ha
= vha
->hw
;
3539 if (IS_P3P_TYPE(ha
))
3542 /* Hold status IOCBs until ABTS response received. */
3544 ha
->fw_options
[3] |= BIT_12
;
3546 /* Set Retry FLOGI in case of P2P connection */
3547 if (ha
->operating_mode
== P2P
) {
3548 ha
->fw_options
[2] |= BIT_3
;
3549 ql_dbg(ql_dbg_disc
, vha
, 0x2101,
3550 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3551 __func__
, ha
->fw_options
[2]);
3554 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3555 if (ql2xmvasynctoatio
&&
3556 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))) {
3557 if (qla_tgt_mode_enabled(vha
) ||
3558 qla_dual_mode_enabled(vha
))
3559 ha
->fw_options
[2] |= BIT_11
;
3561 ha
->fw_options
[2] &= ~BIT_11
;
3564 if (IS_QLA25XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3566 * Tell FW to track each exchange to prevent
3567 * driver from using stale exchange.
3569 if (qla_tgt_mode_enabled(vha
) ||
3570 qla_dual_mode_enabled(vha
))
3571 ha
->fw_options
[2] |= BIT_4
;
3573 ha
->fw_options
[2] &= ~BIT_4
;
3575 /* Reserve 1/2 of emergency exchanges for ELS.*/
3576 if (qla2xuseresexchforels
)
3577 ha
->fw_options
[2] |= BIT_8
;
3579 ha
->fw_options
[2] &= ~BIT_8
;
3582 ql_dbg(ql_dbg_init
, vha
, 0x00e8,
3583 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3584 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
3585 ha
->fw_options
[3], vha
->host
->active_mode
);
3587 if (ha
->fw_options
[1] || ha
->fw_options
[2] || ha
->fw_options
[3])
3588 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3590 /* Update Serial Link options. */
3591 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
3594 rval
= qla2x00_set_serdes_params(vha
,
3595 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
3596 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
3597 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
3598 if (rval
!= QLA_SUCCESS
) {
3599 ql_log(ql_log_warn
, vha
, 0x0104,
3600 "Unable to update Serial Link options (%x).\n", rval
);
3605 qla2x00_config_rings(struct scsi_qla_host
*vha
)
3607 struct qla_hw_data
*ha
= vha
->hw
;
3608 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3609 struct req_que
*req
= ha
->req_q_map
[0];
3610 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3612 /* Setup ring parameters in initialization control block. */
3613 ha
->init_cb
->request_q_outpointer
= cpu_to_le16(0);
3614 ha
->init_cb
->response_q_inpointer
= cpu_to_le16(0);
3615 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
3616 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
3617 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3618 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3619 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3620 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3622 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
3623 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
3624 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
3625 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
3626 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
3630 qla24xx_config_rings(struct scsi_qla_host
*vha
)
3632 struct qla_hw_data
*ha
= vha
->hw
;
3633 device_reg_t
*reg
= ISP_QUE_REG(ha
, 0);
3634 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
3635 struct qla_msix_entry
*msix
;
3636 struct init_cb_24xx
*icb
;
3638 struct req_que
*req
= ha
->req_q_map
[0];
3639 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3641 /* Setup ring parameters in initialization control block. */
3642 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3643 icb
->request_q_outpointer
= cpu_to_le16(0);
3644 icb
->response_q_inpointer
= cpu_to_le16(0);
3645 icb
->request_q_length
= cpu_to_le16(req
->length
);
3646 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
3647 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3648 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3649 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3650 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3652 /* Setup ATIO queue dma pointers for target mode */
3653 icb
->atio_q_inpointer
= cpu_to_le16(0);
3654 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
3655 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
3656 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
3658 if (IS_SHADOW_REG_CAPABLE(ha
))
3659 icb
->firmware_options_2
|= cpu_to_le32(BIT_30
|BIT_29
);
3661 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3662 icb
->qos
= cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
3663 icb
->rid
= cpu_to_le16(rid
);
3664 if (ha
->flags
.msix_enabled
) {
3665 msix
= &ha
->msix_entries
[1];
3666 ql_dbg(ql_dbg_init
, vha
, 0x0019,
3667 "Registering vector 0x%x for base que.\n",
3669 icb
->msix
= cpu_to_le16(msix
->entry
);
3671 /* Use alternate PCI bus number */
3673 icb
->firmware_options_2
|= cpu_to_le32(BIT_19
);
3674 /* Use alternate PCI devfn */
3676 icb
->firmware_options_2
|= cpu_to_le32(BIT_18
);
3678 /* Use Disable MSIX Handshake mode for capable adapters */
3679 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
3680 (ha
->flags
.msix_enabled
)) {
3681 icb
->firmware_options_2
&= cpu_to_le32(~BIT_22
);
3682 ha
->flags
.disable_msix_handshake
= 1;
3683 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
3684 "MSIX Handshake Disable Mode turned on.\n");
3686 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
3688 icb
->firmware_options_2
|= cpu_to_le32(BIT_23
);
3690 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
3691 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
3692 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
3693 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
3695 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
3696 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
3697 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
3698 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
3700 qlt_24xx_config_rings(vha
);
3703 RD_REG_DWORD(&ioreg
->hccr
);
3707 * qla2x00_init_rings() - Initializes firmware.
3710 * Beginning of request ring has initialization control block already built
3711 * by nvram config routine.
3713 * Returns 0 on success.
3716 qla2x00_init_rings(scsi_qla_host_t
*vha
)
3719 unsigned long flags
= 0;
3721 struct qla_hw_data
*ha
= vha
->hw
;
3722 struct req_que
*req
;
3723 struct rsp_que
*rsp
;
3724 struct mid_init_cb_24xx
*mid_init_cb
=
3725 (struct mid_init_cb_24xx
*) ha
->init_cb
;
3727 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3729 /* Clear outstanding commands array. */
3730 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
3731 req
= ha
->req_q_map
[que
];
3732 if (!req
|| !test_bit(que
, ha
->req_qid_map
))
3734 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
3736 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
3737 req
->outstanding_cmds
[cnt
] = NULL
;
3739 req
->current_outstanding_cmd
= 1;
3741 /* Initialize firmware. */
3742 req
->ring_ptr
= req
->ring
;
3743 req
->ring_index
= 0;
3744 req
->cnt
= req
->length
;
3747 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
3748 rsp
= ha
->rsp_q_map
[que
];
3749 if (!rsp
|| !test_bit(que
, ha
->rsp_qid_map
))
3751 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
3753 /* Initialize response queue entries */
3755 qlafx00_init_response_q_entries(rsp
);
3757 qla2x00_init_response_q_entries(rsp
);
3760 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
3761 ha
->tgt
.atio_ring_index
= 0;
3762 /* Initialize ATIO queue entries */
3763 qlt_init_atio_q_entries(vha
);
3765 ha
->isp_ops
->config_rings(vha
);
3767 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3769 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
3771 if (IS_QLAFX00(ha
)) {
3772 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
3776 /* Update any ISP specific firmware options before initialization. */
3777 ha
->isp_ops
->update_fw_options(vha
);
3779 if (ha
->flags
.npiv_supported
) {
3780 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
3781 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
3782 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
3785 if (IS_FWI2_CAPABLE(ha
)) {
3786 mid_init_cb
->options
= cpu_to_le16(BIT_1
);
3787 mid_init_cb
->init_cb
.execution_throttle
=
3788 cpu_to_le16(ha
->cur_fw_xcb_count
);
3789 ha
->flags
.dport_enabled
=
3790 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_7
) != 0;
3791 ql_dbg(ql_dbg_init
, vha
, 0x0191, "DPORT Support: %s.\n",
3792 (ha
->flags
.dport_enabled
) ? "enabled" : "disabled");
3793 /* FA-WWPN Status */
3794 ha
->flags
.fawwpn_enabled
=
3795 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_6
) != 0;
3796 ql_dbg(ql_dbg_init
, vha
, 0x00bc, "FA-WWPN Support: %s.\n",
3797 (ha
->flags
.fawwpn_enabled
) ? "enabled" : "disabled");
3800 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
3803 ql_log(ql_log_fatal
, vha
, 0x00d2,
3804 "Init Firmware **** FAILED ****.\n");
3806 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
3807 "Init Firmware -- success.\n");
3815 * qla2x00_fw_ready() - Waits for firmware ready.
3818 * Returns 0 on success.
3821 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
3824 unsigned long wtime
, mtime
, cs84xx_time
;
3825 uint16_t min_wait
; /* Minimum wait time if loop is down */
3826 uint16_t wait_time
; /* Wait time if loop is coming ready */
3828 struct qla_hw_data
*ha
= vha
->hw
;
3830 if (IS_QLAFX00(vha
->hw
))
3831 return qlafx00_fw_ready(vha
);
3835 /* Time to wait for loop down */
3836 if (IS_P3P_TYPE(ha
))
3842 * Firmware should take at most one RATOV to login, plus 5 seconds for
3843 * our own processing.
3845 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
3846 wait_time
= min_wait
;
3849 /* Min wait time if loop down */
3850 mtime
= jiffies
+ (min_wait
* HZ
);
3852 /* wait time before firmware ready */
3853 wtime
= jiffies
+ (wait_time
* HZ
);
3855 /* Wait for ISP to finish LIP */
3856 if (!vha
->flags
.init_done
)
3857 ql_log(ql_log_info
, vha
, 0x801e,
3858 "Waiting for LIP to complete.\n");
3861 memset(state
, -1, sizeof(state
));
3862 rval
= qla2x00_get_firmware_state(vha
, state
);
3863 if (rval
== QLA_SUCCESS
) {
3864 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
3865 vha
->device_flags
&= ~DFLG_NO_CABLE
;
3867 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
3868 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
3869 "fw_state=%x 84xx=%x.\n", state
[0],
3871 if ((state
[2] & FSTATE_LOGGED_IN
) &&
3872 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
3873 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
3874 "Sending verify iocb.\n");
3876 cs84xx_time
= jiffies
;
3877 rval
= qla84xx_init_chip(vha
);
3878 if (rval
!= QLA_SUCCESS
) {
3881 "Init chip failed.\n");
3885 /* Add time taken to initialize. */
3886 cs84xx_time
= jiffies
- cs84xx_time
;
3887 wtime
+= cs84xx_time
;
3888 mtime
+= cs84xx_time
;
3889 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
3890 "Increasing wait time by %ld. "
3891 "New time %ld.\n", cs84xx_time
,
3894 } else if (state
[0] == FSTATE_READY
) {
3895 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
3896 "F/W Ready - OK.\n");
3898 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
3899 &ha
->login_timeout
, &ha
->r_a_tov
);
3905 rval
= QLA_FUNCTION_FAILED
;
3907 if (atomic_read(&vha
->loop_down_timer
) &&
3908 state
[0] != FSTATE_READY
) {
3909 /* Loop down. Timeout on min_wait for states
3910 * other than Wait for Login.
3912 if (time_after_eq(jiffies
, mtime
)) {
3913 ql_log(ql_log_info
, vha
, 0x8038,
3914 "Cable is unplugged...\n");
3916 vha
->device_flags
|= DFLG_NO_CABLE
;
3921 /* Mailbox cmd failed. Timeout on min_wait. */
3922 if (time_after_eq(jiffies
, mtime
) ||
3923 ha
->flags
.isp82xx_fw_hung
)
3927 if (time_after_eq(jiffies
, wtime
))
3930 /* Delay for a while */
3934 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
3935 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state
[0],
3936 state
[1], state
[2], state
[3], state
[4], state
[5], jiffies
);
3938 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
3939 ql_log(ql_log_warn
, vha
, 0x803b,
3940 "Firmware ready **** FAILED ****.\n");
3947 * qla2x00_configure_hba
3948 * Setup adapter context.
3951 * ha = adapter state pointer.
3960 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
3969 char connect_type
[22];
3970 struct qla_hw_data
*ha
= vha
->hw
;
3971 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
3973 unsigned long flags
;
3975 /* Get host addresses. */
3976 rval
= qla2x00_get_adapter_id(vha
,
3977 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
3978 if (rval
!= QLA_SUCCESS
) {
3979 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
3980 IS_CNA_CAPABLE(ha
) ||
3981 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
3982 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
3983 "Loop is in a transition state.\n");
3985 ql_log(ql_log_warn
, vha
, 0x2009,
3986 "Unable to get host loop ID.\n");
3987 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
3988 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
3989 ql_log(ql_log_warn
, vha
, 0x1151,
3990 "Doing link init.\n");
3991 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
3994 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4000 ql_log(ql_log_info
, vha
, 0x200a,
4001 "Cannot get topology - retrying.\n");
4002 return (QLA_FUNCTION_FAILED
);
4005 vha
->loop_id
= loop_id
;
4008 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
4009 ha
->operating_mode
= LOOP
;
4014 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
4015 ha
->current_topology
= ISP_CFG_NL
;
4016 strcpy(connect_type
, "(Loop)");
4020 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
4021 ha
->switch_cap
= sw_cap
;
4022 ha
->current_topology
= ISP_CFG_FL
;
4023 strcpy(connect_type
, "(FL_Port)");
4027 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
4028 ha
->operating_mode
= P2P
;
4029 ha
->current_topology
= ISP_CFG_N
;
4030 strcpy(connect_type
, "(N_Port-to-N_Port)");
4034 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
4035 ha
->switch_cap
= sw_cap
;
4036 ha
->operating_mode
= P2P
;
4037 ha
->current_topology
= ISP_CFG_F
;
4038 strcpy(connect_type
, "(F_Port)");
4042 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
4043 "HBA in unknown topology %x, using NL.\n", topo
);
4044 ha
->current_topology
= ISP_CFG_NL
;
4045 strcpy(connect_type
, "(Loop)");
4049 /* Save Host port and loop ID. */
4050 /* byte order - Big Endian */
4051 id
.b
.domain
= domain
;
4055 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4056 qlt_update_host_map(vha
, id
);
4057 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4059 if (!vha
->flags
.init_done
)
4060 ql_log(ql_log_info
, vha
, 0x2010,
4061 "Topology - %s, Host Loop address 0x%x.\n",
4062 connect_type
, vha
->loop_id
);
4068 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
4073 struct qla_hw_data
*ha
= vha
->hw
;
4074 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
4075 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
4077 if (memcmp(model
, BINZERO
, len
) != 0) {
4078 strncpy(ha
->model_number
, model
, len
);
4079 st
= en
= ha
->model_number
;
4082 if (*en
!= 0x20 && *en
!= 0x00)
4087 index
= (ha
->pdev
->subsystem_device
& 0xff);
4089 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4090 index
< QLA_MODEL_NAMES
)
4091 strncpy(ha
->model_desc
,
4092 qla2x00_model_name
[index
* 2 + 1],
4093 sizeof(ha
->model_desc
) - 1);
4095 index
= (ha
->pdev
->subsystem_device
& 0xff);
4097 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4098 index
< QLA_MODEL_NAMES
) {
4099 strcpy(ha
->model_number
,
4100 qla2x00_model_name
[index
* 2]);
4101 strncpy(ha
->model_desc
,
4102 qla2x00_model_name
[index
* 2 + 1],
4103 sizeof(ha
->model_desc
) - 1);
4105 strcpy(ha
->model_number
, def
);
4108 if (IS_FWI2_CAPABLE(ha
))
4109 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
4110 sizeof(ha
->model_desc
));
4113 /* On sparc systems, obtain port and node WWN from firmware
4116 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
4119 struct qla_hw_data
*ha
= vha
->hw
;
4120 struct pci_dev
*pdev
= ha
->pdev
;
4121 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4125 val
= of_get_property(dp
, "port-wwn", &len
);
4126 if (val
&& len
>= WWN_SIZE
)
4127 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4129 val
= of_get_property(dp
, "node-wwn", &len
);
4130 if (val
&& len
>= WWN_SIZE
)
4131 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4136 * NVRAM configuration for ISP 2xxx
4139 * ha = adapter block pointer.
4142 * initialization control block in response_ring
4143 * host adapters parameters in host adapter block
4149 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
4154 uint8_t *dptr1
, *dptr2
;
4155 struct qla_hw_data
*ha
= vha
->hw
;
4156 init_cb_t
*icb
= ha
->init_cb
;
4157 nvram_t
*nv
= ha
->nvram
;
4158 uint8_t *ptr
= ha
->nvram
;
4159 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4163 /* Determine NVRAM starting address. */
4164 ha
->nvram_size
= sizeof(nvram_t
);
4166 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
4167 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
4168 ha
->nvram_base
= 0x80;
4170 /* Get NVRAM data and calculate checksum. */
4171 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
4172 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
4175 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
4176 "Contents of NVRAM.\n");
4177 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
4178 (uint8_t *)nv
, ha
->nvram_size
);
4180 /* Bad NVRAM data, set defaults parameters. */
4181 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
4182 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
4183 /* Reset NVRAM data. */
4184 ql_log(ql_log_warn
, vha
, 0x0064,
4185 "Inconsistent NVRAM "
4186 "detected: checksum=0x%x id=%c version=0x%x.\n",
4187 chksum
, nv
->id
[0], nv
->nvram_version
);
4188 ql_log(ql_log_warn
, vha
, 0x0065,
4190 "functioning (yet invalid -- WWPN) defaults.\n");
4193 * Set default initialization control block.
4195 memset(nv
, 0, ha
->nvram_size
);
4196 nv
->parameter_block_version
= ICB_VERSION
;
4198 if (IS_QLA23XX(ha
)) {
4199 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4200 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4201 nv
->add_firmware_options
[0] = BIT_5
;
4202 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4203 nv
->frame_payload_size
= 2048;
4204 nv
->special_options
[1] = BIT_7
;
4205 } else if (IS_QLA2200(ha
)) {
4206 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4207 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4208 nv
->add_firmware_options
[0] = BIT_5
;
4209 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4210 nv
->frame_payload_size
= 1024;
4211 } else if (IS_QLA2100(ha
)) {
4212 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
4213 nv
->firmware_options
[1] = BIT_5
;
4214 nv
->frame_payload_size
= 1024;
4217 nv
->max_iocb_allocation
= cpu_to_le16(256);
4218 nv
->execution_throttle
= cpu_to_le16(16);
4219 nv
->retry_count
= 8;
4220 nv
->retry_delay
= 1;
4222 nv
->port_name
[0] = 33;
4223 nv
->port_name
[3] = 224;
4224 nv
->port_name
[4] = 139;
4226 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
4228 nv
->login_timeout
= 4;
4231 * Set default host adapter parameters
4233 nv
->host_p
[1] = BIT_2
;
4234 nv
->reset_delay
= 5;
4235 nv
->port_down_retry_count
= 8;
4236 nv
->max_luns_per_target
= cpu_to_le16(8);
4237 nv
->link_down_timeout
= 60;
4242 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4244 * The SN2 does not provide BIOS emulation which means you can't change
4245 * potentially bogus BIOS settings. Force the use of default settings
4246 * for link rate and frame size. Hope that the rest of the settings
4249 if (ia64_platform_is("sn2")) {
4250 nv
->frame_payload_size
= 2048;
4252 nv
->special_options
[1] = BIT_7
;
4256 /* Reset Initialization control block */
4257 memset(icb
, 0, ha
->init_cb_size
);
4260 * Setup driver NVRAM options.
4262 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
4263 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
4264 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
4265 nv
->firmware_options
[1] &= ~BIT_4
;
4267 if (IS_QLA23XX(ha
)) {
4268 nv
->firmware_options
[0] |= BIT_2
;
4269 nv
->firmware_options
[0] &= ~BIT_3
;
4270 nv
->special_options
[0] &= ~BIT_6
;
4271 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
4273 if (IS_QLA2300(ha
)) {
4274 if (ha
->fb_rev
== FPM_2310
) {
4275 strcpy(ha
->model_number
, "QLA2310");
4277 strcpy(ha
->model_number
, "QLA2300");
4280 qla2x00_set_model_info(vha
, nv
->model_number
,
4281 sizeof(nv
->model_number
), "QLA23xx");
4283 } else if (IS_QLA2200(ha
)) {
4284 nv
->firmware_options
[0] |= BIT_2
;
4286 * 'Point-to-point preferred, else loop' is not a safe
4287 * connection mode setting.
4289 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
4291 /* Force 'loop preferred, else point-to-point'. */
4292 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
4293 nv
->add_firmware_options
[0] |= BIT_5
;
4295 strcpy(ha
->model_number
, "QLA22xx");
4296 } else /*if (IS_QLA2100(ha))*/ {
4297 strcpy(ha
->model_number
, "QLA2100");
4301 * Copy over NVRAM RISC parameter block to initialization control block.
4303 dptr1
= (uint8_t *)icb
;
4304 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
4305 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
4307 *dptr1
++ = *dptr2
++;
4309 /* Copy 2nd half. */
4310 dptr1
= (uint8_t *)icb
->add_firmware_options
;
4311 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
4313 *dptr1
++ = *dptr2
++;
4315 /* Use alternate WWN? */
4316 if (nv
->host_p
[1] & BIT_7
) {
4317 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4318 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4321 /* Prepare nodename */
4322 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
4324 * Firmware will apply the following mask if the nodename was
4327 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4328 icb
->node_name
[0] &= 0xF0;
4332 * Set host adapter parameters.
4336 * BIT_7 in the host-parameters section allows for modification to
4337 * internal driver logging.
4339 if (nv
->host_p
[0] & BIT_7
)
4340 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
4341 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
4342 /* Always load RISC code on non ISP2[12]00 chips. */
4343 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
4344 ha
->flags
.disable_risc_code_load
= 0;
4345 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
4346 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
4347 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
4348 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
4349 ha
->flags
.disable_serdes
= 0;
4351 ha
->operating_mode
=
4352 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4354 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
4355 sizeof(ha
->fw_seriallink_options
));
4357 /* save HBA serial number */
4358 ha
->serial0
= icb
->port_name
[5];
4359 ha
->serial1
= icb
->port_name
[6];
4360 ha
->serial2
= icb
->port_name
[7];
4361 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4362 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4364 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
4366 ha
->retry_count
= nv
->retry_count
;
4368 /* Set minimum login_timeout to 4 seconds. */
4369 if (nv
->login_timeout
!= ql2xlogintimeout
)
4370 nv
->login_timeout
= ql2xlogintimeout
;
4371 if (nv
->login_timeout
< 4)
4372 nv
->login_timeout
= 4;
4373 ha
->login_timeout
= nv
->login_timeout
;
4375 /* Set minimum RATOV to 100 tenths of a second. */
4378 ha
->loop_reset_delay
= nv
->reset_delay
;
4380 /* Link Down Timeout = 0:
4382 * When Port Down timer expires we will start returning
4383 * I/O's to OS with "DID_NO_CONNECT".
4385 * Link Down Timeout != 0:
4387 * The driver waits for the link to come up after link down
4388 * before returning I/Os to OS with "DID_NO_CONNECT".
4390 if (nv
->link_down_timeout
== 0) {
4391 ha
->loop_down_abort_time
=
4392 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4394 ha
->link_down_timeout
= nv
->link_down_timeout
;
4395 ha
->loop_down_abort_time
=
4396 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4400 * Need enough time to try and get the port back.
4402 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
4403 if (qlport_down_retry
)
4404 ha
->port_down_retry_count
= qlport_down_retry
;
4405 /* Set login_retry_count */
4406 ha
->login_retry_count
= nv
->retry_count
;
4407 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
4408 ha
->port_down_retry_count
> 3)
4409 ha
->login_retry_count
= ha
->port_down_retry_count
;
4410 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4411 ha
->login_retry_count
= ha
->port_down_retry_count
;
4412 if (ql2xloginretrycount
)
4413 ha
->login_retry_count
= ql2xloginretrycount
;
4415 icb
->lun_enables
= cpu_to_le16(0);
4416 icb
->command_resource_count
= 0;
4417 icb
->immediate_notify_resource_count
= 0;
4418 icb
->timeout
= cpu_to_le16(0);
4420 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
4422 icb
->firmware_options
[0] &= ~BIT_3
;
4423 icb
->add_firmware_options
[0] &=
4424 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4425 icb
->add_firmware_options
[0] |= BIT_2
;
4426 icb
->response_accumulation_timer
= 3;
4427 icb
->interrupt_delay_timer
= 5;
4429 vha
->flags
.process_response_queue
= 1;
4432 if (!vha
->flags
.init_done
) {
4433 ha
->zio_mode
= icb
->add_firmware_options
[0] &
4434 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4435 ha
->zio_timer
= icb
->interrupt_delay_timer
?
4436 icb
->interrupt_delay_timer
: 2;
4438 icb
->add_firmware_options
[0] &=
4439 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4440 vha
->flags
.process_response_queue
= 0;
4441 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4442 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4444 ql_log(ql_log_info
, vha
, 0x0068,
4445 "ZIO mode %d enabled; timer delay (%d us).\n",
4446 ha
->zio_mode
, ha
->zio_timer
* 100);
4448 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
4449 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
4450 vha
->flags
.process_response_queue
= 1;
4455 ql_log(ql_log_warn
, vha
, 0x0069,
4456 "NVRAM configuration failed.\n");
4462 qla2x00_rport_del(void *data
)
4464 fc_port_t
*fcport
= data
;
4465 struct fc_rport
*rport
;
4466 unsigned long flags
;
4468 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
4469 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
4470 fcport
->drport
= NULL
;
4471 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
4473 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210b,
4474 "%s %8phN. rport %p roles %x\n",
4475 __func__
, fcport
->port_name
, rport
,
4478 fc_remote_port_delete(rport
);
4483 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4485 * @flags: allocation flags
4487 * Returns a pointer to the allocated fcport, or NULL, if none available.
4490 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
4494 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
4498 /* Setup fcport template structure. */
4500 fcport
->port_type
= FCT_UNKNOWN
;
4501 fcport
->loop_id
= FC_NO_LOOP_ID
;
4502 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
4503 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
4505 fcport
->ct_desc
.ct_sns
= dma_alloc_coherent(&vha
->hw
->pdev
->dev
,
4506 sizeof(struct ct_sns_pkt
), &fcport
->ct_desc
.ct_sns_dma
,
4508 fcport
->disc_state
= DSC_DELETED
;
4509 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4510 fcport
->deleted
= QLA_SESS_DELETED
;
4511 fcport
->login_retry
= vha
->hw
->login_retry_count
;
4512 fcport
->login_retry
= 5;
4513 fcport
->logout_on_delete
= 1;
4515 if (!fcport
->ct_desc
.ct_sns
) {
4516 ql_log(ql_log_warn
, vha
, 0xd049,
4517 "Failed to allocate ct_sns request.\n");
4521 INIT_WORK(&fcport
->del_work
, qla24xx_delete_sess_fn
);
4522 INIT_LIST_HEAD(&fcport
->gnl_entry
);
4523 INIT_LIST_HEAD(&fcport
->list
);
4529 qla2x00_free_fcport(fc_port_t
*fcport
)
4531 if (fcport
->ct_desc
.ct_sns
) {
4532 dma_free_coherent(&fcport
->vha
->hw
->pdev
->dev
,
4533 sizeof(struct ct_sns_pkt
), fcport
->ct_desc
.ct_sns
,
4534 fcport
->ct_desc
.ct_sns_dma
);
4536 fcport
->ct_desc
.ct_sns
= NULL
;
4542 * qla2x00_configure_loop
4543 * Updates Fibre Channel Device Database with what is actually on loop.
4546 * ha = adapter block pointer.
4551 * 2 = database was full and device was not configured.
4554 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
4557 unsigned long flags
, save_flags
;
4558 struct qla_hw_data
*ha
= vha
->hw
;
4561 /* Get Initiator ID */
4562 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
4563 rval
= qla2x00_configure_hba(vha
);
4564 if (rval
!= QLA_SUCCESS
) {
4565 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
4566 "Unable to configure HBA.\n");
4571 save_flags
= flags
= vha
->dpc_flags
;
4572 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
4573 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
4576 * If we have both an RSCN and PORT UPDATE pending then handle them
4577 * both at the same time.
4579 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4580 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4582 qla2x00_get_data_rate(vha
);
4584 /* Determine what we need to do */
4585 if (ha
->current_topology
== ISP_CFG_FL
&&
4586 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4588 set_bit(RSCN_UPDATE
, &flags
);
4590 } else if (ha
->current_topology
== ISP_CFG_F
&&
4591 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4593 set_bit(RSCN_UPDATE
, &flags
);
4594 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4596 } else if (ha
->current_topology
== ISP_CFG_N
) {
4597 clear_bit(RSCN_UPDATE
, &flags
);
4598 if (ha
->flags
.rida_fmt2
) {
4599 /* With Rida Format 2, the login is already triggered.
4600 * We know who is on the other side of the wire.
4601 * No need to login to do login to find out or drop into
4602 * qla2x00_configure_local_loop().
4604 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4605 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4607 if (qla_tgt_mode_enabled(vha
)) {
4608 /* allow the other side to start the login */
4609 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4610 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4613 } else if (ha
->current_topology
== ISP_CFG_NL
) {
4614 clear_bit(RSCN_UPDATE
, &flags
);
4615 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4616 } else if (!vha
->flags
.online
||
4617 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
4618 set_bit(RSCN_UPDATE
, &flags
);
4619 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4622 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
4623 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4624 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
4625 "Loop resync needed, failing.\n");
4626 rval
= QLA_FUNCTION_FAILED
;
4628 rval
= qla2x00_configure_local_loop(vha
);
4631 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
4632 if (LOOP_TRANSITION(vha
)) {
4633 ql_dbg(ql_dbg_disc
, vha
, 0x2099,
4634 "Needs RSCN update and loop transition.\n");
4635 rval
= QLA_FUNCTION_FAILED
;
4638 rval
= qla2x00_configure_fabric(vha
);
4641 if (rval
== QLA_SUCCESS
) {
4642 if (atomic_read(&vha
->loop_down_timer
) ||
4643 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4644 rval
= QLA_FUNCTION_FAILED
;
4646 atomic_set(&vha
->loop_state
, LOOP_READY
);
4647 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
4649 ha
->flags
.fw_init_done
= 1;
4652 * Process any ATIO queue entries that came in
4653 * while we weren't online.
4655 if (qla_tgt_mode_enabled(vha
) ||
4656 qla_dual_mode_enabled(vha
)) {
4657 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
)) {
4658 spin_lock_irqsave(&ha
->tgt
.atio_lock
,
4660 qlt_24xx_process_atio_queue(vha
, 0);
4661 spin_unlock_irqrestore(
4662 &ha
->tgt
.atio_lock
, flags
);
4664 spin_lock_irqsave(&ha
->hardware_lock
,
4666 qlt_24xx_process_atio_queue(vha
, 1);
4667 spin_unlock_irqrestore(
4668 &ha
->hardware_lock
, flags
);
4675 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
4676 "%s *** FAILED ***.\n", __func__
);
4678 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
4679 "%s: exiting normally.\n", __func__
);
4682 /* Restore state if a resync event occurred during processing */
4683 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4684 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
4685 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4686 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
4687 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4696 * Updates Fibre Channel Device Database with local loop devices.
4699 * ha = adapter block pointer.
4703 static int qla24xx_n2n_handle_login(struct scsi_qla_host
*vha
,
4706 struct qla_hw_data
*ha
= vha
->hw
;
4707 int res
= QLA_SUCCESS
, rval
;
4708 int greater_wwpn
= 0;
4711 if (ha
->current_topology
!= ISP_CFG_N
)
4714 if (wwn_to_u64(vha
->port_name
) >
4715 wwn_to_u64(vha
->n2n_port_name
)) {
4716 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
4717 "HBA WWPN is greater %llx > target %llx\n",
4718 wwn_to_u64(vha
->port_name
),
4719 wwn_to_u64(vha
->n2n_port_name
));
4721 fcport
->d_id
.b24
= vha
->n2n_id
;
4724 fcport
->loop_id
= vha
->loop_id
;
4725 fcport
->fc4f_nvme
= 0;
4728 ql_dbg(ql_dbg_disc
, vha
, 0x4001,
4729 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4730 fcport
->d_id
.b24
, vha
->loop_id
);
4732 /* Fill in member data. */
4733 if (!greater_wwpn
) {
4734 rval
= qla2x00_get_port_database(vha
, fcport
, 0);
4735 ql_dbg(ql_dbg_disc
, vha
, 0x1051,
4736 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4737 fcport
->current_login_state
, fcport
->last_login_state
,
4738 fcport
->d_id
.b24
, fcport
->loop_id
, rval
);
4740 if (((fcport
->current_login_state
& 0xf) == 0x4) ||
4741 ((fcport
->current_login_state
& 0xf) == 0x6))
4745 if (logged_in
|| greater_wwpn
) {
4746 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
4747 qla_nvme_register_hba(vha
);
4749 /* Set connected N_Port d_id */
4750 if (vha
->flags
.nvme_enabled
)
4751 fcport
->fc4f_nvme
= 1;
4753 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4754 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4755 fcport
->disc_state
= DSC_GNL
;
4756 fcport
->n2n_flag
= 1;
4758 vha
->hw
->flags
.gpsc_supported
= 0;
4761 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
4762 "%s %d PLOGI ELS %8phC\n",
4763 __func__
, __LINE__
, fcport
->port_name
);
4765 res
= qla24xx_els_dcmd2_iocb(vha
, ELS_DCMD_PLOGI
,
4766 fcport
, fcport
->d_id
);
4769 if (res
!= QLA_SUCCESS
) {
4770 ql_log(ql_log_info
, vha
, 0xd04d,
4771 "PLOGI Failed: portid=%06x - retrying\n",
4775 /* State 0x6 means FCP PRLI complete */
4776 if ((fcport
->current_login_state
& 0xf) == 0x6) {
4777 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
4778 "%s %d %8phC post GPDB work\n",
4779 __func__
, __LINE__
, fcport
->port_name
);
4780 fcport
->chip_reset
=
4781 vha
->hw
->base_qpair
->chip_reset
;
4782 qla24xx_post_gpdb_work(vha
, fcport
, 0);
4784 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
4785 "%s %d %8phC post NVMe PRLI\n",
4786 __func__
, __LINE__
, fcport
->port_name
);
4787 qla24xx_post_prli_work(vha
, fcport
);
4791 /* Wait for next database change */
4792 set_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
);
4799 * qla2x00_configure_local_loop
4800 * Updates Fibre Channel Device Database with local loop devices.
4803 * ha = adapter block pointer.
4809 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
4814 fc_port_t
*fcport
, *new_fcport
;
4820 uint8_t domain
, area
, al_pa
;
4821 struct qla_hw_data
*ha
= vha
->hw
;
4822 unsigned long flags
;
4826 entries
= MAX_FIBRE_DEVICES_LOOP
;
4828 /* Get list of logged in devices. */
4829 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
4830 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
4832 if (rval
!= QLA_SUCCESS
)
4833 goto cleanup_allocation
;
4835 ql_dbg(ql_dbg_disc
, vha
, 0x2011,
4836 "Entries in ID list (%d).\n", entries
);
4837 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
4838 (uint8_t *)ha
->gid_list
,
4839 entries
* sizeof(struct gid_list_info
));
4841 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4842 fcport
->scan_state
= QLA_FCPORT_SCAN
;
4845 /* Allocate temporary fcport for any new fcports discovered. */
4846 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4847 if (new_fcport
== NULL
) {
4848 ql_log(ql_log_warn
, vha
, 0x2012,
4849 "Memory allocation failed for fcport.\n");
4850 rval
= QLA_MEMORY_ALLOC_FAILED
;
4851 goto cleanup_allocation
;
4853 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4855 /* Inititae N2N login. */
4856 if (test_and_clear_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
)) {
4857 rval
= qla24xx_n2n_handle_login(vha
, new_fcport
);
4858 if (rval
!= QLA_SUCCESS
)
4859 goto cleanup_allocation
;
4863 /* Add devices to port list. */
4864 id_iter
= (char *)ha
->gid_list
;
4865 for (index
= 0; index
< entries
; index
++) {
4866 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
4867 area
= ((struct gid_list_info
*)id_iter
)->area
;
4868 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
4869 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
4870 loop_id
= (uint16_t)
4871 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
4873 loop_id
= le16_to_cpu(
4874 ((struct gid_list_info
*)id_iter
)->loop_id
);
4875 id_iter
+= ha
->gid_list_info_size
;
4877 /* Bypass reserved domain fields. */
4878 if ((domain
& 0xf0) == 0xf0)
4881 /* Bypass if not same domain and area of adapter. */
4882 if (area
&& domain
&&
4883 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
4886 /* Bypass invalid local loop ID. */
4887 if (loop_id
> LAST_LOCAL_LOOP_ID
)
4890 memset(new_fcport
->port_name
, 0, WWN_SIZE
);
4892 /* Fill in member data. */
4893 new_fcport
->d_id
.b
.domain
= domain
;
4894 new_fcport
->d_id
.b
.area
= area
;
4895 new_fcport
->d_id
.b
.al_pa
= al_pa
;
4896 new_fcport
->loop_id
= loop_id
;
4897 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
4899 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
4900 if (rval2
!= QLA_SUCCESS
) {
4901 ql_dbg(ql_dbg_disc
, vha
, 0x2097,
4902 "Failed to retrieve fcport information "
4903 "-- get_port_database=%x, loop_id=0x%04x.\n",
4904 rval2
, new_fcport
->loop_id
);
4905 /* Skip retry if N2N */
4906 if (ha
->current_topology
!= ISP_CFG_N
) {
4907 ql_dbg(ql_dbg_disc
, vha
, 0x2105,
4908 "Scheduling resync.\n");
4909 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4914 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4915 /* Check for matching device in port list. */
4918 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4919 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
4923 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4924 fcport
->loop_id
= new_fcport
->loop_id
;
4925 fcport
->port_type
= new_fcport
->port_type
;
4926 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
4927 memcpy(fcport
->node_name
, new_fcport
->node_name
,
4929 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4935 /* New device, add to fcports list. */
4936 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
4938 /* Allocate a new replacement fcport. */
4939 fcport
= new_fcport
;
4941 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4943 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4945 if (new_fcport
== NULL
) {
4946 ql_log(ql_log_warn
, vha
, 0xd031,
4947 "Failed to allocate memory for fcport.\n");
4948 rval
= QLA_MEMORY_ALLOC_FAILED
;
4949 goto cleanup_allocation
;
4951 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4952 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4955 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4957 /* Base iIDMA settings on HBA port speed. */
4958 fcport
->fp_speed
= ha
->link_data_rate
;
4963 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4964 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
4967 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
4968 if ((qla_dual_mode_enabled(vha
) ||
4969 qla_ini_mode_enabled(vha
)) &&
4970 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
4971 qla2x00_mark_device_lost(vha
, fcport
,
4972 ql2xplogiabsentdevice
, 0);
4973 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
4974 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
4975 fcport
->port_type
!= FCT_INITIATOR
&&
4976 fcport
->port_type
!= FCT_BROADCAST
) {
4977 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
4978 "%s %d %8phC post del sess\n",
4982 qlt_schedule_sess_for_deletion(fcport
);
4988 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
4989 qla24xx_fcport_handle_login(vha
, fcport
);
4995 if (rval
!= QLA_SUCCESS
) {
4996 ql_dbg(ql_dbg_disc
, vha
, 0x2098,
4997 "Configure local loop error exit: rval=%x.\n", rval
);
5004 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5007 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5008 struct qla_hw_data
*ha
= vha
->hw
;
5010 if (!IS_IIDMA_CAPABLE(ha
))
5013 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
5016 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
5017 fcport
->fp_speed
> ha
->link_data_rate
)
5020 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
5022 if (rval
!= QLA_SUCCESS
) {
5023 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
5024 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5025 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
5027 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
5028 "iIDMA adjusted to %s GB/s on %8phN.\n",
5029 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
5034 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5036 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5038 struct fc_rport_identifiers rport_ids
;
5039 struct fc_rport
*rport
;
5040 unsigned long flags
;
5042 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
5043 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
5044 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
5045 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
5046 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5047 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
5049 ql_log(ql_log_warn
, vha
, 0x2006,
5050 "Unable to allocate fc remote port.\n");
5054 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
5055 *((fc_port_t
**)rport
->dd_data
) = fcport
;
5056 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
5058 rport
->supported_classes
= fcport
->supported_classes
;
5060 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5061 if (fcport
->port_type
== FCT_INITIATOR
)
5062 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
5063 if (fcport
->port_type
== FCT_TARGET
)
5064 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
5066 ql_dbg(ql_dbg_disc
, vha
, 0x20ee,
5067 "%s %8phN. rport %p is %s mode\n",
5068 __func__
, fcport
->port_name
, rport
,
5069 (fcport
->port_type
== FCT_TARGET
) ? "tgt" : "ini");
5071 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
5075 * qla2x00_update_fcport
5076 * Updates device on list.
5079 * ha = adapter block pointer.
5080 * fcport = port structure pointer.
5090 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5094 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5097 ql_dbg(ql_dbg_disc
, vha
, 0x20ef, "%s %8phC\n",
5098 __func__
, fcport
->port_name
);
5100 if (IS_QLAFX00(vha
->hw
)) {
5101 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5104 fcport
->login_retry
= 0;
5105 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
5106 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5107 fcport
->deleted
= 0;
5108 fcport
->logout_on_delete
= 1;
5110 if (fcport
->fc4f_nvme
) {
5111 qla_nvme_register_remote(vha
, fcport
);
5115 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5116 qla2x00_iidma_fcport(vha
, fcport
);
5117 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5120 switch (vha
->host
->active_mode
) {
5121 case MODE_INITIATOR
:
5122 qla2x00_reg_remote_port(vha
, fcport
);
5125 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5126 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5127 qlt_fc_port_added(vha
, fcport
);
5130 qla2x00_reg_remote_port(vha
, fcport
);
5131 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5132 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5133 qlt_fc_port_added(vha
, fcport
);
5141 * qla2x00_configure_fabric
5142 * Setup SNS devices with loop ID's.
5145 * ha = adapter block pointer.
5152 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
5156 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5158 LIST_HEAD(new_fcports
);
5159 struct qla_hw_data
*ha
= vha
->hw
;
5162 /* If FL port exists, then SNS is present */
5163 if (IS_FWI2_CAPABLE(ha
))
5164 loop_id
= NPH_F_PORT
;
5166 loop_id
= SNS_FL_PORT
;
5167 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
5168 if (rval
!= QLA_SUCCESS
) {
5169 ql_dbg(ql_dbg_disc
, vha
, 0x20a0,
5170 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5172 vha
->device_flags
&= ~SWITCH_FOUND
;
5173 return (QLA_SUCCESS
);
5175 vha
->device_flags
|= SWITCH_FOUND
;
5178 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
5179 rval
= qla2x00_send_change_request(vha
, 0x3, 0);
5180 if (rval
!= QLA_SUCCESS
)
5181 ql_log(ql_log_warn
, vha
, 0x121,
5182 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5188 qla2x00_mgmt_svr_login(vha
);
5191 if (ql2xfdmienable
&&
5192 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
5193 qla2x00_fdmi_register(vha
);
5195 /* Ensure we are logged into the SNS. */
5196 loop_id
= NPH_SNS_LID(ha
);
5197 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
5198 0xfc, mb
, BIT_1
|BIT_0
);
5199 if (rval
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5200 ql_dbg(ql_dbg_disc
, vha
, 0x20a1,
5201 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5202 loop_id
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7], rval
);
5203 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5206 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
5207 if (qla2x00_rft_id(vha
)) {
5209 ql_dbg(ql_dbg_disc
, vha
, 0x20a2,
5210 "Register FC-4 TYPE failed.\n");
5211 if (test_bit(LOOP_RESYNC_NEEDED
,
5215 if (qla2x00_rff_id(vha
, FC4_TYPE_FCP_SCSI
)) {
5217 ql_dbg(ql_dbg_disc
, vha
, 0x209a,
5218 "Register FC-4 Features failed.\n");
5219 if (test_bit(LOOP_RESYNC_NEEDED
,
5223 if (vha
->flags
.nvme_enabled
) {
5224 if (qla2x00_rff_id(vha
, FC_TYPE_NVME
)) {
5225 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
5226 "Register NVME FC Type Features failed.\n");
5229 if (qla2x00_rnn_id(vha
)) {
5231 ql_dbg(ql_dbg_disc
, vha
, 0x2104,
5232 "Register Node Name failed.\n");
5233 if (test_bit(LOOP_RESYNC_NEEDED
,
5236 } else if (qla2x00_rsnn_nn(vha
)) {
5238 ql_dbg(ql_dbg_disc
, vha
, 0x209b,
5239 "Register Symbolic Node Name failed.\n");
5240 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5246 /* Mark the time right before querying FW for connected ports.
5247 * This process is long, asynchronous and by the time it's done,
5248 * collected information might not be accurate anymore. E.g.
5249 * disconnected port might have re-connected and a brand new
5250 * session has been created. In this case session's generation
5251 * will be newer than discovery_gen. */
5252 qlt_do_generation_tick(vha
, &discovery_gen
);
5254 if (USE_ASYNC_SCAN(ha
)) {
5256 rval
= qla24xx_async_gpnft(vha
, FC4_TYPE_FCP_SCSI
);
5258 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5260 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5261 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5263 rval
= qla2x00_find_all_fabric_devs(vha
);
5265 if (rval
!= QLA_SUCCESS
)
5269 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
5270 qla_nvme_register_hba(vha
);
5273 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
5274 "Configure fabric error exit rval=%d.\n", rval
);
5280 * qla2x00_find_all_fabric_devs
5283 * ha = adapter block pointer.
5284 * dev = database device entry pointer.
5293 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
)
5297 fc_port_t
*fcport
, *new_fcport
;
5302 int first_dev
, last_dev
;
5303 port_id_t wrap
= {}, nxt_d_id
;
5304 struct qla_hw_data
*ha
= vha
->hw
;
5305 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5306 unsigned long flags
;
5310 /* Try GID_PT to get device list, else GAN. */
5312 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
5317 ql_dbg(ql_dbg_disc
, vha
, 0x209c,
5318 "GID_PT allocations failed, fallback on GA_NXT.\n");
5320 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
5321 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
5323 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5325 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
5327 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5329 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
5331 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5333 } else if (qla2x00_gfpn_id(vha
, swl
) != QLA_SUCCESS
) {
5335 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5339 /* If other queries succeeded probe for FC-4 type */
5341 qla2x00_gff_id(vha
, swl
);
5342 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5348 /* Allocate temporary fcport for any new fcports discovered. */
5349 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5350 if (new_fcport
== NULL
) {
5351 ql_log(ql_log_warn
, vha
, 0x209d,
5352 "Failed to allocate memory for fcport.\n");
5353 return (QLA_MEMORY_ALLOC_FAILED
);
5355 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5356 /* Set start port ID scan at adapter ID. */
5360 /* Starting free loop ID. */
5361 loop_id
= ha
->min_external_loopid
;
5362 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
5363 if (qla2x00_is_reserved_id(vha
, loop_id
))
5366 if (ha
->current_topology
== ISP_CFG_FL
&&
5367 (atomic_read(&vha
->loop_down_timer
) ||
5368 LOOP_TRANSITION(vha
))) {
5369 atomic_set(&vha
->loop_down_timer
, 0);
5370 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5371 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5377 wrap
.b24
= new_fcport
->d_id
.b24
;
5379 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
5380 memcpy(new_fcport
->node_name
,
5381 swl
[swl_idx
].node_name
, WWN_SIZE
);
5382 memcpy(new_fcport
->port_name
,
5383 swl
[swl_idx
].port_name
, WWN_SIZE
);
5384 memcpy(new_fcport
->fabric_port_name
,
5385 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
5386 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
5387 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
5389 new_fcport
->nvme_flag
= 0;
5390 new_fcport
->fc4f_nvme
= 0;
5391 if (vha
->flags
.nvme_enabled
&&
5392 swl
[swl_idx
].fc4f_nvme
) {
5393 new_fcport
->fc4f_nvme
=
5394 swl
[swl_idx
].fc4f_nvme
;
5395 ql_log(ql_log_info
, vha
, 0x2131,
5396 "FOUND: NVME port %8phC as FC Type 28h\n",
5397 new_fcport
->port_name
);
5400 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
5406 /* Send GA_NXT to the switch */
5407 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
5408 if (rval
!= QLA_SUCCESS
) {
5409 ql_log(ql_log_warn
, vha
, 0x209e,
5410 "SNS scan failed -- assuming "
5411 "zero-entry result.\n");
5417 /* If wrap on switch device list, exit. */
5419 wrap
.b24
= new_fcport
->d_id
.b24
;
5421 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
5422 ql_dbg(ql_dbg_disc
, vha
, 0x209f,
5423 "Device wrap (%02x%02x%02x).\n",
5424 new_fcport
->d_id
.b
.domain
,
5425 new_fcport
->d_id
.b
.area
,
5426 new_fcport
->d_id
.b
.al_pa
);
5430 /* Bypass if same physical adapter. */
5431 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
5434 /* Bypass virtual ports of the same host. */
5435 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
5438 /* Bypass if same domain and area of adapter. */
5439 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
5440 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
5444 /* Bypass reserved domain fields. */
5445 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
5448 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5449 if (ql2xgffidenable
&&
5450 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
5451 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
5454 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5456 /* Locate matching device in database. */
5458 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5459 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5463 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5467 /* Update port state. */
5468 memcpy(fcport
->fabric_port_name
,
5469 new_fcport
->fabric_port_name
, WWN_SIZE
);
5470 fcport
->fp_speed
= new_fcport
->fp_speed
;
5473 * If address the same and state FCS_ONLINE
5474 * (or in target mode), nothing changed.
5476 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
5477 (atomic_read(&fcport
->state
) == FCS_ONLINE
||
5478 (vha
->host
->active_mode
== MODE_TARGET
))) {
5483 * If device was not a fabric device before.
5485 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
5486 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5487 qla2x00_clear_loop_id(fcport
);
5488 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
5494 * Port ID changed or device was marked to be updated;
5495 * Log it out if still logged in and mark it for
5498 if (qla_tgt_mode_enabled(base_vha
)) {
5499 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf080,
5500 "port changed FC ID, %8phC"
5501 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5503 fcport
->d_id
.b
.domain
,
5504 fcport
->d_id
.b
.area
,
5505 fcport
->d_id
.b
.al_pa
,
5507 new_fcport
->d_id
.b
.domain
,
5508 new_fcport
->d_id
.b
.area
,
5509 new_fcport
->d_id
.b
.al_pa
);
5510 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5514 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5515 fcport
->flags
|= FCF_LOGIN_NEEDED
;
5520 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5523 /* If device was not in our fcports list, then add it. */
5524 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5525 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5527 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5530 /* Allocate a new replacement fcport. */
5531 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
5532 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5533 if (new_fcport
== NULL
) {
5534 ql_log(ql_log_warn
, vha
, 0xd032,
5535 "Memory allocation failed for fcport.\n");
5536 return (QLA_MEMORY_ALLOC_FAILED
);
5538 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5539 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
5542 qla2x00_free_fcport(new_fcport
);
5545 * Logout all previous fabric dev marked lost, except FCP2 devices.
5547 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5548 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5551 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
5552 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
5555 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5556 if ((qla_dual_mode_enabled(vha
) ||
5557 qla_ini_mode_enabled(vha
)) &&
5558 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5559 qla2x00_mark_device_lost(vha
, fcport
,
5560 ql2xplogiabsentdevice
, 0);
5561 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5562 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5563 fcport
->port_type
!= FCT_INITIATOR
&&
5564 fcport
->port_type
!= FCT_BROADCAST
) {
5565 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5566 "%s %d %8phC post del sess\n",
5569 qlt_schedule_sess_for_deletion(fcport
);
5575 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5576 qla24xx_fcport_handle_login(vha
, fcport
);
5582 * qla2x00_find_new_loop_id
5583 * Scan through our port list and find a new usable loop ID.
5586 * ha: adapter state pointer.
5587 * dev: port structure pointer.
5590 * qla2x00 local function return status code.
5596 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
5599 struct qla_hw_data
*ha
= vha
->hw
;
5600 unsigned long flags
= 0;
5604 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5606 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
5608 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
5609 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
5610 dev
->loop_id
= FC_NO_LOOP_ID
;
5611 rval
= QLA_FUNCTION_FAILED
;
5613 set_bit(dev
->loop_id
, ha
->loop_id_map
);
5615 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5617 if (rval
== QLA_SUCCESS
)
5618 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
5619 "Assigning new loopid=%x, portid=%x.\n",
5620 dev
->loop_id
, dev
->d_id
.b24
);
5622 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
5623 "No loop_id's available, portid=%x.\n",
5631 * qla2x00_fabric_login
5632 * Issue fabric login command.
5635 * ha = adapter block pointer.
5636 * device = pointer to FC device type structure.
5639 * 0 - Login successfully
5641 * 2 - Initiator device
5645 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
5646 uint16_t *next_loopid
)
5650 uint16_t tmp_loopid
;
5651 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5652 struct qla_hw_data
*ha
= vha
->hw
;
5658 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
5659 "Trying Fabric Login w/loop id 0x%04x for port "
5661 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5662 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5664 /* Login fcport on switch. */
5665 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
5666 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5667 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
5668 if (rval
!= QLA_SUCCESS
) {
5671 if (mb
[0] == MBS_PORT_ID_USED
) {
5673 * Device has another loop ID. The firmware team
5674 * recommends the driver perform an implicit login with
5675 * the specified ID again. The ID we just used is save
5676 * here so we return with an ID that can be tried by
5680 tmp_loopid
= fcport
->loop_id
;
5681 fcport
->loop_id
= mb
[1];
5683 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
5684 "Fabric Login: port in use - next loop "
5685 "id=0x%04x, port id= %02x%02x%02x.\n",
5686 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5687 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5689 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
5694 /* A retry occurred before. */
5695 *next_loopid
= tmp_loopid
;
5698 * No retry occurred before. Just increment the
5699 * ID value for next login.
5701 *next_loopid
= (fcport
->loop_id
+ 1);
5704 if (mb
[1] & BIT_0
) {
5705 fcport
->port_type
= FCT_INITIATOR
;
5707 fcport
->port_type
= FCT_TARGET
;
5708 if (mb
[1] & BIT_1
) {
5709 fcport
->flags
|= FCF_FCP2_DEVICE
;
5714 fcport
->supported_classes
|= FC_COS_CLASS2
;
5716 fcport
->supported_classes
|= FC_COS_CLASS3
;
5718 if (IS_FWI2_CAPABLE(ha
)) {
5721 FCF_CONF_COMP_SUPPORTED
;
5726 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
5728 * Loop ID already used, try next loop ID.
5731 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
5732 if (rval
!= QLA_SUCCESS
) {
5733 /* Ran out of loop IDs to use */
5736 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
5738 * Firmware possibly timed out during login. If NO
5739 * retries are left to do then the device is declared
5742 *next_loopid
= fcport
->loop_id
;
5743 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5744 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5745 fcport
->d_id
.b
.al_pa
);
5746 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
5752 * unrecoverable / not handled error
5754 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
5755 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5756 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
5757 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
5758 fcport
->loop_id
, jiffies
);
5760 *next_loopid
= fcport
->loop_id
;
5761 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5762 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5763 fcport
->d_id
.b
.al_pa
);
5764 qla2x00_clear_loop_id(fcport
);
5765 fcport
->login_retry
= 0;
5776 * qla2x00_local_device_login
5777 * Issue local device login command.
5780 * ha = adapter block pointer.
5781 * loop_id = loop id of device to login to.
5783 * Returns (Where's the #define!!!!):
5784 * 0 - Login successfully
5789 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5792 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5794 memset(mb
, 0, sizeof(mb
));
5795 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
5796 if (rval
== QLA_SUCCESS
) {
5797 /* Interrogate mailbox registers for any errors */
5798 if (mb
[0] == MBS_COMMAND_ERROR
)
5800 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
5801 /* device not in PCB table */
5809 * qla2x00_loop_resync
5810 * Resync with fibre channel devices.
5813 * ha = adapter block pointer.
5819 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
5821 int rval
= QLA_SUCCESS
;
5823 struct req_que
*req
;
5824 struct rsp_que
*rsp
;
5829 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5830 if (vha
->flags
.online
) {
5831 if (!(rval
= qla2x00_fw_ready(vha
))) {
5832 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5835 if (!IS_QLAFX00(vha
->hw
)) {
5837 * Issue a marker after FW becomes
5840 qla2x00_marker(vha
, req
, rsp
, 0, 0,
5842 vha
->marker_needed
= 0;
5845 /* Remap devices on Loop. */
5846 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5848 if (IS_QLAFX00(vha
->hw
))
5849 qlafx00_configure_devices(vha
);
5851 qla2x00_configure_loop(vha
);
5854 } while (!atomic_read(&vha
->loop_down_timer
) &&
5855 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
5856 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
5861 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
5862 return (QLA_FUNCTION_FAILED
);
5865 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
5866 "%s *** FAILED ***.\n", __func__
);
5872 * qla2x00_perform_loop_resync
5873 * Description: This function will set the appropriate flags and call
5874 * qla2x00_loop_resync. If successful loop will be resynced
5875 * Arguments : scsi_qla_host_t pointer
5876 * returm : Success or Failure
5879 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
5883 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
5884 /*Configure the flags so that resync happens properly*/
5885 atomic_set(&ha
->loop_down_timer
, 0);
5886 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
5887 atomic_set(&ha
->loop_state
, LOOP_UP
);
5888 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
5889 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
5890 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
5892 rval
= qla2x00_loop_resync(ha
);
5894 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
5896 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
5903 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
5906 struct scsi_qla_host
*vha
;
5907 struct qla_hw_data
*ha
= base_vha
->hw
;
5908 unsigned long flags
;
5910 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5911 /* Go with deferred removal of rport references. */
5912 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
5913 atomic_inc(&vha
->vref_count
);
5914 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5915 if (fcport
->drport
&&
5916 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
5917 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5918 qla2x00_rport_del(fcport
);
5920 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5923 atomic_dec(&vha
->vref_count
);
5924 wake_up(&vha
->vref_waitq
);
5926 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5929 /* Assumes idc_lock always held on entry */
5931 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
5933 struct qla_hw_data
*ha
= vha
->hw
;
5934 uint32_t drv_presence
, drv_presence_mask
;
5935 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
5936 uint32_t class_type_mask
= 0x3;
5937 uint16_t fcoe_other_function
= 0xffff, i
;
5939 if (IS_QLA8044(ha
)) {
5940 drv_presence
= qla8044_rd_direct(vha
,
5941 QLA8044_CRB_DRV_ACTIVE_INDEX
);
5942 dev_part_info1
= qla8044_rd_direct(vha
,
5943 QLA8044_CRB_DEV_PART_INFO_INDEX
);
5944 dev_part_info2
= qla8044_rd_direct(vha
,
5945 QLA8044_CRB_DEV_PART_INFO2
);
5947 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
5948 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
5949 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
5951 for (i
= 0; i
< 8; i
++) {
5952 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
5953 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
5954 (i
!= ha
->portnum
)) {
5955 fcoe_other_function
= i
;
5959 if (fcoe_other_function
== 0xffff) {
5960 for (i
= 0; i
< 8; i
++) {
5961 class_type
= ((dev_part_info2
>> (i
* 4)) &
5963 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
5964 ((i
+ 8) != ha
->portnum
)) {
5965 fcoe_other_function
= i
+ 8;
5971 * Prepare drv-presence mask based on fcoe functions present.
5972 * However consider only valid physical fcoe function numbers (0-15).
5974 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
5975 ((fcoe_other_function
== 0xffff) ?
5976 0 : (1 << (fcoe_other_function
))));
5978 /* We are the reset owner iff:
5979 * - No other protocol drivers present.
5980 * - This is the lowest among fcoe functions. */
5981 if (!(drv_presence
& drv_presence_mask
) &&
5982 (ha
->portnum
< fcoe_other_function
)) {
5983 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
5984 "This host is Reset owner.\n");
5985 ha
->flags
.nic_core_reset_owner
= 1;
5990 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
5992 int rval
= QLA_SUCCESS
;
5993 struct qla_hw_data
*ha
= vha
->hw
;
5996 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
5997 if (rval
== QLA_SUCCESS
) {
5998 drv_ack
|= (1 << ha
->portnum
);
5999 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6006 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
6008 int rval
= QLA_SUCCESS
;
6009 struct qla_hw_data
*ha
= vha
->hw
;
6012 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6013 if (rval
== QLA_SUCCESS
) {
6014 drv_ack
&= ~(1 << ha
->portnum
);
6015 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6022 qla83xx_dev_state_to_string(uint32_t dev_state
)
6024 switch (dev_state
) {
6025 case QLA8XXX_DEV_COLD
:
6026 return "COLD/RE-INIT";
6027 case QLA8XXX_DEV_INITIALIZING
:
6028 return "INITIALIZING";
6029 case QLA8XXX_DEV_READY
:
6031 case QLA8XXX_DEV_NEED_RESET
:
6032 return "NEED RESET";
6033 case QLA8XXX_DEV_NEED_QUIESCENT
:
6034 return "NEED QUIESCENT";
6035 case QLA8XXX_DEV_FAILED
:
6037 case QLA8XXX_DEV_QUIESCENT
:
6044 /* Assumes idc-lock always held on entry */
6046 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
6048 struct qla_hw_data
*ha
= vha
->hw
;
6049 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
6051 switch (audit_type
) {
6052 case IDC_AUDIT_TIMESTAMP
:
6053 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
6054 idc_audit_reg
= (ha
->portnum
) |
6055 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
6056 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6059 case IDC_AUDIT_COMPLETION
:
6060 duration_secs
= ((jiffies_to_msecs(jiffies
) -
6061 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
6062 idc_audit_reg
= (ha
->portnum
) |
6063 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
6064 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6068 ql_log(ql_log_warn
, vha
, 0xb078,
6069 "Invalid audit type specified.\n");
6074 /* Assumes idc_lock always held on entry */
6076 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
6078 struct qla_hw_data
*ha
= vha
->hw
;
6079 uint32_t idc_control
, dev_state
;
6081 __qla83xx_get_idc_control(vha
, &idc_control
);
6082 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
6083 ql_log(ql_log_info
, vha
, 0xb080,
6084 "NIC Core reset has been disabled. idc-control=0x%x\n",
6086 return QLA_FUNCTION_FAILED
;
6089 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6090 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6091 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
6092 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
6093 QLA8XXX_DEV_NEED_RESET
);
6094 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
6095 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
6097 const char *state
= qla83xx_dev_state_to_string(dev_state
);
6098 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
6100 /* SV: XXX: Is timeout required here? */
6101 /* Wait for IDC state change READY -> NEED_RESET */
6102 while (dev_state
== QLA8XXX_DEV_READY
) {
6103 qla83xx_idc_unlock(vha
, 0);
6105 qla83xx_idc_lock(vha
, 0);
6106 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6110 /* Send IDC ack by writing to drv-ack register */
6111 __qla83xx_set_drv_ack(vha
);
6117 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
6119 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6123 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
6125 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6129 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
6131 uint32_t drv_presence
= 0;
6132 struct qla_hw_data
*ha
= vha
->hw
;
6134 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6135 if (drv_presence
& (1 << ha
->portnum
))
6138 return QLA_TEST_FAILED
;
6142 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
6144 int rval
= QLA_SUCCESS
;
6145 struct qla_hw_data
*ha
= vha
->hw
;
6147 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
6148 "Entered %s().\n", __func__
);
6150 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
6151 ql_log(ql_log_warn
, vha
, 0xb059,
6152 "Device in unrecoverable FAILED state.\n");
6153 return QLA_FUNCTION_FAILED
;
6156 qla83xx_idc_lock(vha
, 0);
6158 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
6159 ql_log(ql_log_warn
, vha
, 0xb05a,
6160 "Function=0x%x has been removed from IDC participation.\n",
6162 rval
= QLA_FUNCTION_FAILED
;
6166 qla83xx_reset_ownership(vha
);
6168 rval
= qla83xx_initiating_reset(vha
);
6171 * Perform reset if we are the reset-owner,
6172 * else wait till IDC state changes to READY/FAILED.
6174 if (rval
== QLA_SUCCESS
) {
6175 rval
= qla83xx_idc_state_handler(vha
);
6177 if (rval
== QLA_SUCCESS
)
6178 ha
->flags
.nic_core_hung
= 0;
6179 __qla83xx_clear_drv_ack(vha
);
6183 qla83xx_idc_unlock(vha
, 0);
6185 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
6191 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
6193 struct qla_hw_data
*ha
= vha
->hw
;
6194 int rval
= QLA_FUNCTION_FAILED
;
6196 if (!IS_MCTP_CAPABLE(ha
)) {
6197 /* This message can be removed from the final version */
6198 ql_log(ql_log_info
, vha
, 0x506d,
6199 "This board is not MCTP capable\n");
6203 if (!ha
->mctp_dump
) {
6204 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
6205 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
6207 if (!ha
->mctp_dump
) {
6208 ql_log(ql_log_warn
, vha
, 0x506e,
6209 "Failed to allocate memory for mctp dump\n");
6214 #define MCTP_DUMP_STR_ADDR 0x00000000
6215 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
6216 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
6217 if (rval
!= QLA_SUCCESS
) {
6218 ql_log(ql_log_warn
, vha
, 0x506f,
6219 "Failed to capture mctp dump\n");
6221 ql_log(ql_log_info
, vha
, 0x5070,
6222 "Mctp dump capture for host (%ld/%p).\n",
6223 vha
->host_no
, ha
->mctp_dump
);
6224 ha
->mctp_dumped
= 1;
6227 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
6228 ha
->flags
.nic_core_reset_hdlr_active
= 1;
6229 rval
= qla83xx_restart_nic_firmware(vha
);
6231 /* NIC Core reset failed. */
6232 ql_log(ql_log_warn
, vha
, 0x5071,
6233 "Failed to restart nic firmware\n");
6235 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
6236 "Restarted NIC firmware successfully.\n");
6237 ha
->flags
.nic_core_reset_hdlr_active
= 0;
6245 * qla2x00_quiesce_io
6246 * Description: This function will block the new I/Os
6247 * Its not aborting any I/Os as context
6248 * is not destroyed during quiescence
6249 * Arguments: scsi_qla_host_t
6253 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
6255 struct qla_hw_data
*ha
= vha
->hw
;
6256 struct scsi_qla_host
*vp
;
6258 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
6259 "Quiescing I/O - ha=%p.\n", ha
);
6261 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
6262 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6263 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6264 qla2x00_mark_all_devices_lost(vha
, 0);
6265 list_for_each_entry(vp
, &ha
->vp_list
, list
)
6266 qla2x00_mark_all_devices_lost(vp
, 0);
6268 if (!atomic_read(&vha
->loop_down_timer
))
6269 atomic_set(&vha
->loop_down_timer
,
6272 /* Wait for pending cmds to complete */
6273 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
6277 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
6279 struct qla_hw_data
*ha
= vha
->hw
;
6280 struct scsi_qla_host
*vp
;
6281 unsigned long flags
;
6285 /* For ISP82XX, driver waits for completion of the commands.
6286 * online flag should be set.
6288 if (!(IS_P3P_TYPE(ha
)))
6289 vha
->flags
.online
= 0;
6290 ha
->flags
.chip_reset_done
= 0;
6291 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6292 vha
->qla_stats
.total_isp_aborts
++;
6294 ql_log(ql_log_info
, vha
, 0x00af,
6295 "Performing ISP error recovery - ha=%p.\n", ha
);
6297 /* For ISP82XX, reset_chip is just disabling interrupts.
6298 * Driver waits for the completion of the commands.
6299 * the interrupts need to be enabled.
6301 if (!(IS_P3P_TYPE(ha
)))
6302 ha
->isp_ops
->reset_chip(vha
);
6305 ha
->flags
.rida_fmt2
= 0;
6306 ha
->flags
.n2n_ae
= 0;
6307 ha
->flags
.lip_ae
= 0;
6308 ha
->current_topology
= 0;
6309 ha
->flags
.fw_started
= 0;
6310 ha
->flags
.fw_init_done
= 0;
6311 ha
->base_qpair
->chip_reset
++;
6312 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6313 if (ha
->queue_pair_map
[i
])
6314 ha
->queue_pair_map
[i
]->chip_reset
=
6315 ha
->base_qpair
->chip_reset
;
6318 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
6319 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6320 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6321 qla2x00_mark_all_devices_lost(vha
, 0);
6323 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6324 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6325 atomic_inc(&vp
->vref_count
);
6326 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6328 qla2x00_mark_all_devices_lost(vp
, 0);
6330 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6331 atomic_dec(&vp
->vref_count
);
6333 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6335 if (!atomic_read(&vha
->loop_down_timer
))
6336 atomic_set(&vha
->loop_down_timer
,
6340 /* Clear all async request states across all VPs. */
6341 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
6342 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6343 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6344 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6345 atomic_inc(&vp
->vref_count
);
6346 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6348 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
6349 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6351 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6352 atomic_dec(&vp
->vref_count
);
6354 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6356 if (!ha
->flags
.eeh_busy
) {
6357 /* Make sure for ISP 82XX IO DMA is complete */
6358 if (IS_P3P_TYPE(ha
)) {
6359 qla82xx_chip_reset_cleanup(vha
);
6360 ql_log(ql_log_info
, vha
, 0x00b4,
6361 "Done chip reset cleanup.\n");
6363 /* Done waiting for pending commands.
6364 * Reset the online flag.
6366 vha
->flags
.online
= 0;
6369 /* Requeue all commands in outstanding command list. */
6370 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6372 /* memory barrier */
6378 * Resets ISP and aborts all outstanding commands.
6381 * ha = adapter block pointer.
6387 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
6391 struct qla_hw_data
*ha
= vha
->hw
;
6392 struct scsi_qla_host
*vp
;
6393 struct req_que
*req
= ha
->req_q_map
[0];
6394 unsigned long flags
;
6396 if (vha
->flags
.online
) {
6397 qla2x00_abort_isp_cleanup(vha
);
6399 if (IS_QLA8031(ha
)) {
6400 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
6401 "Clearing fcoe driver presence.\n");
6402 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
6403 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
6404 "Error while clearing DRV-Presence.\n");
6407 if (unlikely(pci_channel_offline(ha
->pdev
) &&
6408 ha
->flags
.pci_channel_io_perm_failure
)) {
6409 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6414 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
6416 ha
->isp_ops
->nvram_config(vha
);
6418 if (!qla2x00_restart_isp(vha
)) {
6419 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6421 if (!atomic_read(&vha
->loop_down_timer
)) {
6423 * Issue marker command only when we are going
6424 * to start the I/O .
6426 vha
->marker_needed
= 1;
6429 vha
->flags
.online
= 1;
6431 ha
->isp_ops
->enable_intrs(ha
);
6433 ha
->isp_abort_cnt
= 0;
6434 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6436 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
6437 qla2x00_get_fw_version(vha
);
6439 ha
->flags
.fce_enabled
= 1;
6441 fce_calc_size(ha
->fce_bufs
));
6442 rval
= qla2x00_enable_fce_trace(vha
,
6443 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6446 ql_log(ql_log_warn
, vha
, 0x8033,
6447 "Unable to reinitialize FCE "
6449 ha
->flags
.fce_enabled
= 0;
6454 memset(ha
->eft
, 0, EFT_SIZE
);
6455 rval
= qla2x00_enable_eft_trace(vha
,
6456 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6458 ql_log(ql_log_warn
, vha
, 0x8034,
6459 "Unable to reinitialize EFT "
6463 } else { /* failed the ISP abort */
6464 vha
->flags
.online
= 1;
6465 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
6466 if (ha
->isp_abort_cnt
== 0) {
6467 ql_log(ql_log_fatal
, vha
, 0x8035,
6468 "ISP error recover failed - "
6469 "board disabled.\n");
6471 * The next call disables the board
6474 ha
->isp_ops
->reset_adapter(vha
);
6475 vha
->flags
.online
= 0;
6476 clear_bit(ISP_ABORT_RETRY
,
6479 } else { /* schedule another ISP abort */
6480 ha
->isp_abort_cnt
--;
6481 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
6482 "ISP abort - retry remaining %d.\n",
6487 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
6488 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
6489 "ISP error recovery - retrying (%d) "
6490 "more times.\n", ha
->isp_abort_cnt
);
6491 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6499 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
6500 qla2x00_configure_hba(vha
);
6501 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6502 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6504 atomic_inc(&vp
->vref_count
);
6505 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6507 qla2x00_vp_abort_isp(vp
);
6509 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6510 atomic_dec(&vp
->vref_count
);
6513 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6515 if (IS_QLA8031(ha
)) {
6516 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
6517 "Setting back fcoe driver presence.\n");
6518 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
6519 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
6520 "Error while setting DRV-Presence.\n");
6523 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
6531 * qla2x00_restart_isp
6532 * restarts the ISP after a reset
6535 * ha = adapter block pointer.
6541 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
6544 struct qla_hw_data
*ha
= vha
->hw
;
6545 struct req_que
*req
= ha
->req_q_map
[0];
6546 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
6548 /* If firmware needs to be loaded */
6549 if (qla2x00_isp_firmware(vha
)) {
6550 vha
->flags
.online
= 0;
6551 status
= ha
->isp_ops
->chip_diag(vha
);
6553 status
= qla2x00_setup_chip(vha
);
6556 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
6557 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6558 ha
->flags
.chip_reset_done
= 1;
6560 /* Initialize the queues in use */
6561 qla25xx_init_queues(ha
);
6563 status
= qla2x00_fw_ready(vha
);
6565 /* Issue a marker after FW becomes ready. */
6566 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
6567 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6570 /* if no cable then assume it's good */
6571 if ((vha
->device_flags
& DFLG_NO_CABLE
))
6578 qla25xx_init_queues(struct qla_hw_data
*ha
)
6580 struct rsp_que
*rsp
= NULL
;
6581 struct req_que
*req
= NULL
;
6582 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
6586 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
6587 rsp
= ha
->rsp_q_map
[i
];
6588 if (rsp
&& test_bit(i
, ha
->rsp_qid_map
)) {
6589 rsp
->options
&= ~BIT_0
;
6590 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
6591 if (ret
!= QLA_SUCCESS
)
6592 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
6593 "%s Rsp que: %d init failed.\n",
6596 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
6597 "%s Rsp que: %d inited.\n",
6601 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
6602 req
= ha
->req_q_map
[i
];
6603 if (req
&& test_bit(i
, ha
->req_qid_map
)) {
6604 /* Clear outstanding commands array. */
6605 req
->options
&= ~BIT_0
;
6606 ret
= qla25xx_init_req_que(base_vha
, req
);
6607 if (ret
!= QLA_SUCCESS
)
6608 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
6609 "%s Req que: %d init failed.\n",
6612 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
6613 "%s Req que: %d inited.\n",
6621 * qla2x00_reset_adapter
6625 * ha = adapter block pointer.
6628 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
6630 unsigned long flags
= 0;
6631 struct qla_hw_data
*ha
= vha
->hw
;
6632 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
6634 vha
->flags
.online
= 0;
6635 ha
->isp_ops
->disable_intrs(ha
);
6637 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6638 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
6639 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6640 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
6641 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6642 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6646 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
6648 unsigned long flags
= 0;
6649 struct qla_hw_data
*ha
= vha
->hw
;
6650 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
6652 if (IS_P3P_TYPE(ha
))
6655 vha
->flags
.online
= 0;
6656 ha
->isp_ops
->disable_intrs(ha
);
6658 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6659 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
6660 RD_REG_DWORD(®
->hccr
);
6661 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
6662 RD_REG_DWORD(®
->hccr
);
6663 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6665 if (IS_NOPOLLING_TYPE(ha
))
6666 ha
->isp_ops
->enable_intrs(ha
);
6669 /* On sparc systems, obtain port and node WWN from firmware
6672 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
6673 struct nvram_24xx
*nv
)
6676 struct qla_hw_data
*ha
= vha
->hw
;
6677 struct pci_dev
*pdev
= ha
->pdev
;
6678 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
6682 val
= of_get_property(dp
, "port-wwn", &len
);
6683 if (val
&& len
>= WWN_SIZE
)
6684 memcpy(nv
->port_name
, val
, WWN_SIZE
);
6686 val
= of_get_property(dp
, "node-wwn", &len
);
6687 if (val
&& len
>= WWN_SIZE
)
6688 memcpy(nv
->node_name
, val
, WWN_SIZE
);
6693 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
6696 struct init_cb_24xx
*icb
;
6697 struct nvram_24xx
*nv
;
6699 uint8_t *dptr1
, *dptr2
;
6702 struct qla_hw_data
*ha
= vha
->hw
;
6705 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6708 /* Determine NVRAM starting address. */
6709 if (ha
->port_no
== 0) {
6710 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
6711 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
6713 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
6714 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
6717 ha
->nvram_size
= sizeof(struct nvram_24xx
);
6718 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
6720 /* Get VPD data into cache */
6721 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
6722 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
6723 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
6725 /* Get NVRAM data into cache and calculate checksum. */
6726 dptr
= (uint32_t *)nv
;
6727 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
6729 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
6730 chksum
+= le32_to_cpu(*dptr
);
6732 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
6733 "Contents of NVRAM\n");
6734 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
6735 (uint8_t *)nv
, ha
->nvram_size
);
6737 /* Bad NVRAM data, set defaults parameters. */
6738 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
6739 || nv
->id
[3] != ' ' ||
6740 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
6741 /* Reset NVRAM data. */
6742 ql_log(ql_log_warn
, vha
, 0x006b,
6743 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6744 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
6745 ql_log(ql_log_warn
, vha
, 0x006c,
6746 "Falling back to functioning (yet invalid -- WWPN) "
6750 * Set default initialization control block.
6752 memset(nv
, 0, ha
->nvram_size
);
6753 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
6754 nv
->version
= cpu_to_le16(ICB_VERSION
);
6755 nv
->frame_payload_size
= 2048;
6756 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
6757 nv
->exchange_count
= cpu_to_le16(0);
6758 nv
->hard_address
= cpu_to_le16(124);
6759 nv
->port_name
[0] = 0x21;
6760 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
6761 nv
->port_name
[2] = 0x00;
6762 nv
->port_name
[3] = 0xe0;
6763 nv
->port_name
[4] = 0x8b;
6764 nv
->port_name
[5] = 0x1c;
6765 nv
->port_name
[6] = 0x55;
6766 nv
->port_name
[7] = 0x86;
6767 nv
->node_name
[0] = 0x20;
6768 nv
->node_name
[1] = 0x00;
6769 nv
->node_name
[2] = 0x00;
6770 nv
->node_name
[3] = 0xe0;
6771 nv
->node_name
[4] = 0x8b;
6772 nv
->node_name
[5] = 0x1c;
6773 nv
->node_name
[6] = 0x55;
6774 nv
->node_name
[7] = 0x86;
6775 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
6776 nv
->login_retry_count
= cpu_to_le16(8);
6777 nv
->interrupt_delay_timer
= cpu_to_le16(0);
6778 nv
->login_timeout
= cpu_to_le16(0);
6779 nv
->firmware_options_1
=
6780 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
6781 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
6782 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6783 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
6784 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
6785 nv
->efi_parameters
= cpu_to_le32(0);
6786 nv
->reset_delay
= 5;
6787 nv
->max_luns_per_target
= cpu_to_le16(128);
6788 nv
->port_down_retry_count
= cpu_to_le16(30);
6789 nv
->link_down_timeout
= cpu_to_le16(30);
6794 if (qla_tgt_mode_enabled(vha
)) {
6795 /* Don't enable full login after initial LIP */
6796 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6797 /* Don't enable LIP full login for initiator */
6798 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6801 qlt_24xx_config_nvram_stage1(vha
, nv
);
6803 /* Reset Initialization control block */
6804 memset(icb
, 0, ha
->init_cb_size
);
6806 /* Copy 1st segment. */
6807 dptr1
= (uint8_t *)icb
;
6808 dptr2
= (uint8_t *)&nv
->version
;
6809 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
6811 *dptr1
++ = *dptr2
++;
6813 icb
->login_retry_count
= nv
->login_retry_count
;
6814 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
6816 /* Copy 2nd segment. */
6817 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
6818 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
6819 cnt
= (uint8_t *)&icb
->reserved_3
-
6820 (uint8_t *)&icb
->interrupt_delay_timer
;
6822 *dptr1
++ = *dptr2
++;
6825 * Setup driver NVRAM options.
6827 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
6830 qlt_24xx_config_nvram_stage2(vha
, icb
);
6832 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
6833 /* Use alternate WWN? */
6834 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
6835 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
6838 /* Prepare nodename */
6839 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
6841 * Firmware will apply the following mask if the nodename was
6844 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
6845 icb
->node_name
[0] &= 0xF0;
6848 /* Set host adapter parameters. */
6849 ha
->flags
.disable_risc_code_load
= 0;
6850 ha
->flags
.enable_lip_reset
= 0;
6851 ha
->flags
.enable_lip_full_login
=
6852 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
6853 ha
->flags
.enable_target_reset
=
6854 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
6855 ha
->flags
.enable_led_scheme
= 0;
6856 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
6858 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
6859 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
6861 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
6862 sizeof(ha
->fw_seriallink_options24
));
6864 /* save HBA serial number */
6865 ha
->serial0
= icb
->port_name
[5];
6866 ha
->serial1
= icb
->port_name
[6];
6867 ha
->serial2
= icb
->port_name
[7];
6868 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
6869 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
6871 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
6873 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
6875 /* Set minimum login_timeout to 4 seconds. */
6876 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
6877 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
6878 if (le16_to_cpu(nv
->login_timeout
) < 4)
6879 nv
->login_timeout
= cpu_to_le16(4);
6880 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
6882 /* Set minimum RATOV to 100 tenths of a second. */
6885 ha
->loop_reset_delay
= nv
->reset_delay
;
6887 /* Link Down Timeout = 0:
6889 * When Port Down timer expires we will start returning
6890 * I/O's to OS with "DID_NO_CONNECT".
6892 * Link Down Timeout != 0:
6894 * The driver waits for the link to come up after link down
6895 * before returning I/Os to OS with "DID_NO_CONNECT".
6897 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
6898 ha
->loop_down_abort_time
=
6899 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
6901 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
6902 ha
->loop_down_abort_time
=
6903 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
6906 /* Need enough time to try and get the port back. */
6907 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
6908 if (qlport_down_retry
)
6909 ha
->port_down_retry_count
= qlport_down_retry
;
6911 /* Set login_retry_count */
6912 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
6913 if (ha
->port_down_retry_count
==
6914 le16_to_cpu(nv
->port_down_retry_count
) &&
6915 ha
->port_down_retry_count
> 3)
6916 ha
->login_retry_count
= ha
->port_down_retry_count
;
6917 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
6918 ha
->login_retry_count
= ha
->port_down_retry_count
;
6919 if (ql2xloginretrycount
)
6920 ha
->login_retry_count
= ql2xloginretrycount
;
6923 if (!vha
->flags
.init_done
) {
6924 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
6925 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6926 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
6927 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
6929 icb
->firmware_options_2
&= cpu_to_le32(
6930 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
6931 vha
->flags
.process_response_queue
= 0;
6932 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
6933 ha
->zio_mode
= QLA_ZIO_MODE_6
;
6935 ql_log(ql_log_info
, vha
, 0x006f,
6936 "ZIO mode %d enabled; timer delay (%d us).\n",
6937 ha
->zio_mode
, ha
->zio_timer
* 100);
6939 icb
->firmware_options_2
|= cpu_to_le32(
6940 (uint32_t)ha
->zio_mode
);
6941 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
6942 vha
->flags
.process_response_queue
= 1;
6946 ql_log(ql_log_warn
, vha
, 0x0070,
6947 "NVRAM configuration failed.\n");
6952 uint8_t qla27xx_find_valid_image(struct scsi_qla_host
*vha
)
6954 struct qla27xx_image_status pri_image_status
, sec_image_status
;
6955 uint8_t valid_pri_image
, valid_sec_image
;
6957 uint32_t cnt
, chksum
, size
;
6958 struct qla_hw_data
*ha
= vha
->hw
;
6960 valid_pri_image
= valid_sec_image
= 1;
6961 ha
->active_image
= 0;
6962 size
= sizeof(struct qla27xx_image_status
) / sizeof(uint32_t);
6964 if (!ha
->flt_region_img_status_pri
) {
6965 valid_pri_image
= 0;
6966 goto check_sec_image
;
6969 qla24xx_read_flash_data(vha
, (uint32_t *)(&pri_image_status
),
6970 ha
->flt_region_img_status_pri
, size
);
6972 if (pri_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
6973 ql_dbg(ql_dbg_init
, vha
, 0x018b,
6974 "Primary image signature (0x%x) not valid\n",
6975 pri_image_status
.signature
);
6976 valid_pri_image
= 0;
6977 goto check_sec_image
;
6980 wptr
= (uint32_t *)(&pri_image_status
);
6983 for (chksum
= 0; cnt
--; wptr
++)
6984 chksum
+= le32_to_cpu(*wptr
);
6987 ql_dbg(ql_dbg_init
, vha
, 0x018c,
6988 "Checksum validation failed for primary image (0x%x)\n",
6990 valid_pri_image
= 0;
6994 if (!ha
->flt_region_img_status_sec
) {
6995 valid_sec_image
= 0;
6996 goto check_valid_image
;
6999 qla24xx_read_flash_data(vha
, (uint32_t *)(&sec_image_status
),
7000 ha
->flt_region_img_status_sec
, size
);
7002 if (sec_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
7003 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7004 "Secondary image signature(0x%x) not valid\n",
7005 sec_image_status
.signature
);
7006 valid_sec_image
= 0;
7007 goto check_valid_image
;
7010 wptr
= (uint32_t *)(&sec_image_status
);
7012 for (chksum
= 0; cnt
--; wptr
++)
7013 chksum
+= le32_to_cpu(*wptr
);
7015 ql_dbg(ql_dbg_init
, vha
, 0x018e,
7016 "Checksum validation failed for secondary image (0x%x)\n",
7018 valid_sec_image
= 0;
7022 if (valid_pri_image
&& (pri_image_status
.image_status_mask
& 0x1))
7023 ha
->active_image
= QLA27XX_PRIMARY_IMAGE
;
7024 if (valid_sec_image
&& (sec_image_status
.image_status_mask
& 0x1)) {
7025 if (!ha
->active_image
||
7026 pri_image_status
.generation_number
<
7027 sec_image_status
.generation_number
)
7028 ha
->active_image
= QLA27XX_SECONDARY_IMAGE
;
7031 ql_dbg(ql_dbg_init
, vha
, 0x018f, "%s image\n",
7032 ha
->active_image
== 0 ? "default bootld and fw" :
7033 ha
->active_image
== 1 ? "primary" :
7034 ha
->active_image
== 2 ? "secondary" :
7037 return ha
->active_image
;
7041 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
7044 int rval
= QLA_SUCCESS
;
7045 int segments
, fragment
;
7046 uint32_t *dcode
, dlen
;
7050 struct qla_hw_data
*ha
= vha
->hw
;
7051 struct req_que
*req
= ha
->req_q_map
[0];
7053 ql_dbg(ql_dbg_init
, vha
, 0x008b,
7054 "FW: Loading firmware from flash (%x).\n", faddr
);
7058 segments
= FA_RISC_CODE_SEGMENTS
;
7059 dcode
= (uint32_t *)req
->ring
;
7062 if (IS_QLA27XX(ha
) &&
7063 qla27xx_find_valid_image(vha
) == QLA27XX_SECONDARY_IMAGE
)
7064 faddr
= ha
->flt_region_fw_sec
;
7066 /* Validate firmware image by checking version. */
7067 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
7068 for (i
= 0; i
< 4; i
++)
7069 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7070 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7071 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7072 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7074 ql_log(ql_log_fatal
, vha
, 0x008c,
7075 "Unable to verify the integrity of flash firmware "
7077 ql_log(ql_log_fatal
, vha
, 0x008d,
7078 "Firmware data: %08x %08x %08x %08x.\n",
7079 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7081 return QLA_FUNCTION_FAILED
;
7084 while (segments
&& rval
== QLA_SUCCESS
) {
7085 /* Read segment's load information. */
7086 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
7088 risc_addr
= be32_to_cpu(dcode
[2]);
7089 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7090 risc_size
= be32_to_cpu(dcode
[3]);
7093 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7094 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7095 if (dlen
> risc_size
)
7098 ql_dbg(ql_dbg_init
, vha
, 0x008e,
7099 "Loading risc segment@ risc addr %x "
7100 "number of dwords 0x%x offset 0x%x.\n",
7101 risc_addr
, dlen
, faddr
);
7103 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
7104 for (i
= 0; i
< dlen
; i
++)
7105 dcode
[i
] = swab32(dcode
[i
]);
7107 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7110 ql_log(ql_log_fatal
, vha
, 0x008f,
7111 "Failed to load segment %d of firmware.\n",
7113 return QLA_FUNCTION_FAILED
;
7126 if (!IS_QLA27XX(ha
))
7129 if (ha
->fw_dump_template
)
7130 vfree(ha
->fw_dump_template
);
7131 ha
->fw_dump_template
= NULL
;
7132 ha
->fw_dump_template_len
= 0;
7134 ql_dbg(ql_dbg_init
, vha
, 0x0161,
7135 "Loading fwdump template from %x\n", faddr
);
7136 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
7137 risc_size
= be32_to_cpu(dcode
[2]);
7138 ql_dbg(ql_dbg_init
, vha
, 0x0162,
7139 "-> array size %x dwords\n", risc_size
);
7140 if (risc_size
== 0 || risc_size
== ~0)
7141 goto default_template
;
7143 dlen
= (risc_size
- 8) * sizeof(*dcode
);
7144 ql_dbg(ql_dbg_init
, vha
, 0x0163,
7145 "-> template allocating %x bytes...\n", dlen
);
7146 ha
->fw_dump_template
= vmalloc(dlen
);
7147 if (!ha
->fw_dump_template
) {
7148 ql_log(ql_log_warn
, vha
, 0x0164,
7149 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7150 goto default_template
;
7155 dcode
= ha
->fw_dump_template
;
7156 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
7157 for (i
= 0; i
< risc_size
; i
++)
7158 dcode
[i
] = le32_to_cpu(dcode
[i
]);
7160 if (!qla27xx_fwdt_template_valid(dcode
)) {
7161 ql_log(ql_log_warn
, vha
, 0x0165,
7162 "Failed fwdump template validate\n");
7163 goto default_template
;
7166 dlen
= qla27xx_fwdt_template_size(dcode
);
7167 ql_dbg(ql_dbg_init
, vha
, 0x0166,
7168 "-> template size %x bytes\n", dlen
);
7169 if (dlen
> risc_size
* sizeof(*dcode
)) {
7170 ql_log(ql_log_warn
, vha
, 0x0167,
7171 "Failed fwdump template exceeds array by %zx bytes\n",
7172 (size_t)(dlen
- risc_size
* sizeof(*dcode
)));
7173 goto default_template
;
7175 ha
->fw_dump_template_len
= dlen
;
7179 ql_log(ql_log_warn
, vha
, 0x0168, "Using default fwdump template\n");
7180 if (ha
->fw_dump_template
)
7181 vfree(ha
->fw_dump_template
);
7182 ha
->fw_dump_template
= NULL
;
7183 ha
->fw_dump_template_len
= 0;
7185 dlen
= qla27xx_fwdt_template_default_size();
7186 ql_dbg(ql_dbg_init
, vha
, 0x0169,
7187 "-> template allocating %x bytes...\n", dlen
);
7188 ha
->fw_dump_template
= vmalloc(dlen
);
7189 if (!ha
->fw_dump_template
) {
7190 ql_log(ql_log_warn
, vha
, 0x016a,
7191 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7192 goto failed_template
;
7195 dcode
= ha
->fw_dump_template
;
7196 risc_size
= dlen
/ sizeof(*dcode
);
7197 memcpy(dcode
, qla27xx_fwdt_template_default(), dlen
);
7198 for (i
= 0; i
< risc_size
; i
++)
7199 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7201 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7202 ql_log(ql_log_warn
, vha
, 0x016b,
7203 "Failed fwdump template validate\n");
7204 goto failed_template
;
7207 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7208 ql_dbg(ql_dbg_init
, vha
, 0x016c,
7209 "-> template size %x bytes\n", dlen
);
7210 ha
->fw_dump_template_len
= dlen
;
7214 ql_log(ql_log_warn
, vha
, 0x016d, "Failed default fwdump template\n");
7215 if (ha
->fw_dump_template
)
7216 vfree(ha
->fw_dump_template
);
7217 ha
->fw_dump_template
= NULL
;
7218 ha
->fw_dump_template_len
= 0;
7222 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7225 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7229 uint16_t *wcode
, *fwcode
;
7230 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
7231 struct fw_blob
*blob
;
7232 struct qla_hw_data
*ha
= vha
->hw
;
7233 struct req_que
*req
= ha
->req_q_map
[0];
7235 /* Load firmware blob. */
7236 blob
= qla2x00_request_firmware(vha
);
7238 ql_log(ql_log_info
, vha
, 0x0083,
7239 "Firmware image unavailable.\n");
7240 ql_log(ql_log_info
, vha
, 0x0084,
7241 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
7242 return QLA_FUNCTION_FAILED
;
7247 wcode
= (uint16_t *)req
->ring
;
7249 fwcode
= (uint16_t *)blob
->fw
->data
;
7252 /* Validate firmware image by checking version. */
7253 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
7254 ql_log(ql_log_fatal
, vha
, 0x0085,
7255 "Unable to verify integrity of firmware image (%zd).\n",
7257 goto fail_fw_integrity
;
7259 for (i
= 0; i
< 4; i
++)
7260 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
7261 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
7262 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
7263 wcode
[2] == 0 && wcode
[3] == 0)) {
7264 ql_log(ql_log_fatal
, vha
, 0x0086,
7265 "Unable to verify integrity of firmware image.\n");
7266 ql_log(ql_log_fatal
, vha
, 0x0087,
7267 "Firmware data: %04x %04x %04x %04x.\n",
7268 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
7269 goto fail_fw_integrity
;
7273 while (*seg
&& rval
== QLA_SUCCESS
) {
7275 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
7276 risc_size
= be16_to_cpu(fwcode
[3]);
7278 /* Validate firmware image size. */
7279 fwclen
+= risc_size
* sizeof(uint16_t);
7280 if (blob
->fw
->size
< fwclen
) {
7281 ql_log(ql_log_fatal
, vha
, 0x0088,
7282 "Unable to verify integrity of firmware image "
7283 "(%zd).\n", blob
->fw
->size
);
7284 goto fail_fw_integrity
;
7288 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7289 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
7290 if (wlen
> risc_size
)
7292 ql_dbg(ql_dbg_init
, vha
, 0x0089,
7293 "Loading risc segment@ risc addr %x number of "
7294 "words 0x%x.\n", risc_addr
, wlen
);
7296 for (i
= 0; i
< wlen
; i
++)
7297 wcode
[i
] = swab16(fwcode
[i
]);
7299 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7302 ql_log(ql_log_fatal
, vha
, 0x008a,
7303 "Failed to load segment %d of firmware.\n",
7320 return QLA_FUNCTION_FAILED
;
7324 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7327 int segments
, fragment
;
7328 uint32_t *dcode
, dlen
;
7332 struct fw_blob
*blob
;
7333 const uint32_t *fwcode
;
7335 struct qla_hw_data
*ha
= vha
->hw
;
7336 struct req_que
*req
= ha
->req_q_map
[0];
7338 /* Load firmware blob. */
7339 blob
= qla2x00_request_firmware(vha
);
7341 ql_log(ql_log_warn
, vha
, 0x0090,
7342 "Firmware image unavailable.\n");
7343 ql_log(ql_log_warn
, vha
, 0x0091,
7344 "Firmware images can be retrieved from: "
7347 return QLA_FUNCTION_FAILED
;
7350 ql_dbg(ql_dbg_init
, vha
, 0x0092,
7351 "FW: Loading via request-firmware.\n");
7355 segments
= FA_RISC_CODE_SEGMENTS
;
7356 dcode
= (uint32_t *)req
->ring
;
7358 fwcode
= (uint32_t *)blob
->fw
->data
;
7361 /* Validate firmware image by checking version. */
7362 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
7363 ql_log(ql_log_fatal
, vha
, 0x0093,
7364 "Unable to verify integrity of firmware image (%zd).\n",
7366 return QLA_FUNCTION_FAILED
;
7368 for (i
= 0; i
< 4; i
++)
7369 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
7370 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7371 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7372 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7374 ql_log(ql_log_fatal
, vha
, 0x0094,
7375 "Unable to verify integrity of firmware image (%zd).\n",
7377 ql_log(ql_log_fatal
, vha
, 0x0095,
7378 "Firmware data: %08x %08x %08x %08x.\n",
7379 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7380 return QLA_FUNCTION_FAILED
;
7383 while (segments
&& rval
== QLA_SUCCESS
) {
7384 risc_addr
= be32_to_cpu(fwcode
[2]);
7385 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7386 risc_size
= be32_to_cpu(fwcode
[3]);
7388 /* Validate firmware image size. */
7389 fwclen
+= risc_size
* sizeof(uint32_t);
7390 if (blob
->fw
->size
< fwclen
) {
7391 ql_log(ql_log_fatal
, vha
, 0x0096,
7392 "Unable to verify integrity of firmware image "
7393 "(%zd).\n", blob
->fw
->size
);
7394 return QLA_FUNCTION_FAILED
;
7398 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7399 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7400 if (dlen
> risc_size
)
7403 ql_dbg(ql_dbg_init
, vha
, 0x0097,
7404 "Loading risc segment@ risc addr %x "
7405 "number of dwords 0x%x.\n", risc_addr
, dlen
);
7407 for (i
= 0; i
< dlen
; i
++)
7408 dcode
[i
] = swab32(fwcode
[i
]);
7410 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7413 ql_log(ql_log_fatal
, vha
, 0x0098,
7414 "Failed to load segment %d of firmware.\n",
7416 return QLA_FUNCTION_FAILED
;
7429 if (!IS_QLA27XX(ha
))
7432 if (ha
->fw_dump_template
)
7433 vfree(ha
->fw_dump_template
);
7434 ha
->fw_dump_template
= NULL
;
7435 ha
->fw_dump_template_len
= 0;
7437 ql_dbg(ql_dbg_init
, vha
, 0x171,
7438 "Loading fwdump template from %x\n",
7439 (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
));
7440 risc_size
= be32_to_cpu(fwcode
[2]);
7441 ql_dbg(ql_dbg_init
, vha
, 0x172,
7442 "-> array size %x dwords\n", risc_size
);
7443 if (risc_size
== 0 || risc_size
== ~0)
7444 goto default_template
;
7446 dlen
= (risc_size
- 8) * sizeof(*fwcode
);
7447 ql_dbg(ql_dbg_init
, vha
, 0x0173,
7448 "-> template allocating %x bytes...\n", dlen
);
7449 ha
->fw_dump_template
= vmalloc(dlen
);
7450 if (!ha
->fw_dump_template
) {
7451 ql_log(ql_log_warn
, vha
, 0x0174,
7452 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7453 goto default_template
;
7458 dcode
= ha
->fw_dump_template
;
7459 for (i
= 0; i
< risc_size
; i
++)
7460 dcode
[i
] = le32_to_cpu(fwcode
[i
]);
7462 if (!qla27xx_fwdt_template_valid(dcode
)) {
7463 ql_log(ql_log_warn
, vha
, 0x0175,
7464 "Failed fwdump template validate\n");
7465 goto default_template
;
7468 dlen
= qla27xx_fwdt_template_size(dcode
);
7469 ql_dbg(ql_dbg_init
, vha
, 0x0176,
7470 "-> template size %x bytes\n", dlen
);
7471 if (dlen
> risc_size
* sizeof(*fwcode
)) {
7472 ql_log(ql_log_warn
, vha
, 0x0177,
7473 "Failed fwdump template exceeds array by %zx bytes\n",
7474 (size_t)(dlen
- risc_size
* sizeof(*fwcode
)));
7475 goto default_template
;
7477 ha
->fw_dump_template_len
= dlen
;
7481 ql_log(ql_log_warn
, vha
, 0x0178, "Using default fwdump template\n");
7482 if (ha
->fw_dump_template
)
7483 vfree(ha
->fw_dump_template
);
7484 ha
->fw_dump_template
= NULL
;
7485 ha
->fw_dump_template_len
= 0;
7487 dlen
= qla27xx_fwdt_template_default_size();
7488 ql_dbg(ql_dbg_init
, vha
, 0x0179,
7489 "-> template allocating %x bytes...\n", dlen
);
7490 ha
->fw_dump_template
= vmalloc(dlen
);
7491 if (!ha
->fw_dump_template
) {
7492 ql_log(ql_log_warn
, vha
, 0x017a,
7493 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7494 goto failed_template
;
7497 dcode
= ha
->fw_dump_template
;
7498 risc_size
= dlen
/ sizeof(*fwcode
);
7499 fwcode
= qla27xx_fwdt_template_default();
7500 for (i
= 0; i
< risc_size
; i
++)
7501 dcode
[i
] = be32_to_cpu(fwcode
[i
]);
7503 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7504 ql_log(ql_log_warn
, vha
, 0x017b,
7505 "Failed fwdump template validate\n");
7506 goto failed_template
;
7509 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7510 ql_dbg(ql_dbg_init
, vha
, 0x017c,
7511 "-> template size %x bytes\n", dlen
);
7512 ha
->fw_dump_template_len
= dlen
;
7516 ql_log(ql_log_warn
, vha
, 0x017d, "Failed default fwdump template\n");
7517 if (ha
->fw_dump_template
)
7518 vfree(ha
->fw_dump_template
);
7519 ha
->fw_dump_template
= NULL
;
7520 ha
->fw_dump_template_len
= 0;
7525 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7529 if (ql2xfwloadbin
== 1)
7530 return qla81xx_load_risc(vha
, srisc_addr
);
7534 * 1) Firmware via request-firmware interface (.bin file).
7535 * 2) Firmware residing in flash.
7537 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7538 if (rval
== QLA_SUCCESS
)
7541 return qla24xx_load_risc_flash(vha
, srisc_addr
,
7542 vha
->hw
->flt_region_fw
);
7546 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7549 struct qla_hw_data
*ha
= vha
->hw
;
7551 if (ql2xfwloadbin
== 2)
7556 * 1) Firmware residing in flash.
7557 * 2) Firmware via request-firmware interface (.bin file).
7558 * 3) Golden-Firmware residing in flash -- limited operation.
7560 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
7561 if (rval
== QLA_SUCCESS
)
7565 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7566 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
7569 ql_log(ql_log_info
, vha
, 0x0099,
7570 "Attempting to fallback to golden firmware.\n");
7571 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
7572 if (rval
!= QLA_SUCCESS
)
7575 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
7576 ha
->flags
.running_gold_fw
= 1;
7581 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
7584 struct qla_hw_data
*ha
= vha
->hw
;
7586 if (ha
->flags
.pci_channel_io_perm_failure
)
7588 if (!IS_FWI2_CAPABLE(ha
))
7590 if (!ha
->fw_major_version
)
7592 if (!ha
->flags
.fw_started
)
7595 ret
= qla2x00_stop_firmware(vha
);
7596 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
7597 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
7598 ha
->isp_ops
->reset_chip(vha
);
7599 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
7601 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
7603 ql_log(ql_log_info
, vha
, 0x8015,
7604 "Attempting retry of stop-firmware command.\n");
7605 ret
= qla2x00_stop_firmware(vha
);
7609 ha
->flags
.fw_init_done
= 0;
7613 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
7615 int rval
= QLA_SUCCESS
;
7617 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
7618 struct qla_hw_data
*ha
= vha
->hw
;
7619 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
7620 struct req_que
*req
;
7621 struct rsp_que
*rsp
;
7626 rval
= qla2x00_fw_ready(base_vha
);
7628 req
= vha
->qpair
->req
;
7630 req
= ha
->req_q_map
[0];
7633 if (rval
== QLA_SUCCESS
) {
7634 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
7635 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
7638 vha
->flags
.management_server_logged_in
= 0;
7640 /* Login to SNS first */
7641 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
7643 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
7644 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
7645 ql_dbg(ql_dbg_init
, vha
, 0x0120,
7646 "Failed SNS login: loop_id=%x, rval2=%d\n",
7649 ql_dbg(ql_dbg_init
, vha
, 0x0103,
7650 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7651 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7652 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
7653 return (QLA_FUNCTION_FAILED
);
7656 atomic_set(&vha
->loop_down_timer
, 0);
7657 atomic_set(&vha
->loop_state
, LOOP_UP
);
7658 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
7659 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
7660 rval
= qla2x00_loop_resync(base_vha
);
7665 /* 84XX Support **************************************************************/
7667 static LIST_HEAD(qla_cs84xx_list
);
7668 static DEFINE_MUTEX(qla_cs84xx_mutex
);
7670 static struct qla_chip_state_84xx
*
7671 qla84xx_get_chip(struct scsi_qla_host
*vha
)
7673 struct qla_chip_state_84xx
*cs84xx
;
7674 struct qla_hw_data
*ha
= vha
->hw
;
7676 mutex_lock(&qla_cs84xx_mutex
);
7678 /* Find any shared 84xx chip. */
7679 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
7680 if (cs84xx
->bus
== ha
->pdev
->bus
) {
7681 kref_get(&cs84xx
->kref
);
7686 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
7690 kref_init(&cs84xx
->kref
);
7691 spin_lock_init(&cs84xx
->access_lock
);
7692 mutex_init(&cs84xx
->fw_update_mutex
);
7693 cs84xx
->bus
= ha
->pdev
->bus
;
7695 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
7697 mutex_unlock(&qla_cs84xx_mutex
);
7702 __qla84xx_chip_release(struct kref
*kref
)
7704 struct qla_chip_state_84xx
*cs84xx
=
7705 container_of(kref
, struct qla_chip_state_84xx
, kref
);
7707 mutex_lock(&qla_cs84xx_mutex
);
7708 list_del(&cs84xx
->list
);
7709 mutex_unlock(&qla_cs84xx_mutex
);
7714 qla84xx_put_chip(struct scsi_qla_host
*vha
)
7716 struct qla_hw_data
*ha
= vha
->hw
;
7718 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
7722 qla84xx_init_chip(scsi_qla_host_t
*vha
)
7726 struct qla_hw_data
*ha
= vha
->hw
;
7728 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
7730 rval
= qla84xx_verify_chip(vha
, status
);
7732 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
7734 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
7738 /* 81XX Support **************************************************************/
7741 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
7744 struct init_cb_81xx
*icb
;
7745 struct nvram_81xx
*nv
;
7747 uint8_t *dptr1
, *dptr2
;
7750 struct qla_hw_data
*ha
= vha
->hw
;
7753 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
7756 /* Determine NVRAM starting address. */
7757 ha
->nvram_size
= sizeof(struct nvram_81xx
);
7758 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
7759 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
7760 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
7762 /* Get VPD data into cache */
7763 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
7764 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
7767 /* Get NVRAM data into cache and calculate checksum. */
7768 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
7770 dptr
= (uint32_t *)nv
;
7771 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
7772 chksum
+= le32_to_cpu(*dptr
);
7774 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
7775 "Contents of NVRAM:\n");
7776 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
7777 (uint8_t *)nv
, ha
->nvram_size
);
7779 /* Bad NVRAM data, set defaults parameters. */
7780 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
7781 || nv
->id
[3] != ' ' ||
7782 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
7783 /* Reset NVRAM data. */
7784 ql_log(ql_log_info
, vha
, 0x0073,
7785 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7786 "version=0x%x.\n", chksum
, nv
->id
[0],
7787 le16_to_cpu(nv
->nvram_version
));
7788 ql_log(ql_log_info
, vha
, 0x0074,
7789 "Falling back to functioning (yet invalid -- WWPN) "
7793 * Set default initialization control block.
7795 memset(nv
, 0, ha
->nvram_size
);
7796 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
7797 nv
->version
= cpu_to_le16(ICB_VERSION
);
7798 nv
->frame_payload_size
= 2048;
7799 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
7800 nv
->exchange_count
= cpu_to_le16(0);
7801 nv
->port_name
[0] = 0x21;
7802 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
7803 nv
->port_name
[2] = 0x00;
7804 nv
->port_name
[3] = 0xe0;
7805 nv
->port_name
[4] = 0x8b;
7806 nv
->port_name
[5] = 0x1c;
7807 nv
->port_name
[6] = 0x55;
7808 nv
->port_name
[7] = 0x86;
7809 nv
->node_name
[0] = 0x20;
7810 nv
->node_name
[1] = 0x00;
7811 nv
->node_name
[2] = 0x00;
7812 nv
->node_name
[3] = 0xe0;
7813 nv
->node_name
[4] = 0x8b;
7814 nv
->node_name
[5] = 0x1c;
7815 nv
->node_name
[6] = 0x55;
7816 nv
->node_name
[7] = 0x86;
7817 nv
->login_retry_count
= cpu_to_le16(8);
7818 nv
->interrupt_delay_timer
= cpu_to_le16(0);
7819 nv
->login_timeout
= cpu_to_le16(0);
7820 nv
->firmware_options_1
=
7821 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
7822 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
7823 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
7824 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
7825 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
7826 nv
->efi_parameters
= cpu_to_le32(0);
7827 nv
->reset_delay
= 5;
7828 nv
->max_luns_per_target
= cpu_to_le16(128);
7829 nv
->port_down_retry_count
= cpu_to_le16(30);
7830 nv
->link_down_timeout
= cpu_to_le16(180);
7831 nv
->enode_mac
[0] = 0x00;
7832 nv
->enode_mac
[1] = 0xC0;
7833 nv
->enode_mac
[2] = 0xDD;
7834 nv
->enode_mac
[3] = 0x04;
7835 nv
->enode_mac
[4] = 0x05;
7836 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
7841 if (IS_T10_PI_CAPABLE(ha
))
7842 nv
->frame_payload_size
&= ~7;
7844 qlt_81xx_config_nvram_stage1(vha
, nv
);
7846 /* Reset Initialization control block */
7847 memset(icb
, 0, ha
->init_cb_size
);
7849 /* Copy 1st segment. */
7850 dptr1
= (uint8_t *)icb
;
7851 dptr2
= (uint8_t *)&nv
->version
;
7852 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
7854 *dptr1
++ = *dptr2
++;
7856 icb
->login_retry_count
= nv
->login_retry_count
;
7858 /* Copy 2nd segment. */
7859 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
7860 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
7861 cnt
= (uint8_t *)&icb
->reserved_5
-
7862 (uint8_t *)&icb
->interrupt_delay_timer
;
7864 *dptr1
++ = *dptr2
++;
7866 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
7867 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7868 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
7869 icb
->enode_mac
[0] = 0x00;
7870 icb
->enode_mac
[1] = 0xC0;
7871 icb
->enode_mac
[2] = 0xDD;
7872 icb
->enode_mac
[3] = 0x04;
7873 icb
->enode_mac
[4] = 0x05;
7874 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
7877 /* Use extended-initialization control block. */
7878 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
7881 * Setup driver NVRAM options.
7883 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
7886 qlt_81xx_config_nvram_stage2(vha
, icb
);
7888 /* Use alternate WWN? */
7889 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
7890 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
7891 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
7894 /* Prepare nodename */
7895 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
7897 * Firmware will apply the following mask if the nodename was
7900 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
7901 icb
->node_name
[0] &= 0xF0;
7904 /* Set host adapter parameters. */
7905 ha
->flags
.disable_risc_code_load
= 0;
7906 ha
->flags
.enable_lip_reset
= 0;
7907 ha
->flags
.enable_lip_full_login
=
7908 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
7909 ha
->flags
.enable_target_reset
=
7910 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
7911 ha
->flags
.enable_led_scheme
= 0;
7912 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
7914 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
7915 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
7917 /* save HBA serial number */
7918 ha
->serial0
= icb
->port_name
[5];
7919 ha
->serial1
= icb
->port_name
[6];
7920 ha
->serial2
= icb
->port_name
[7];
7921 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
7922 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
7924 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
7926 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
7928 /* Set minimum login_timeout to 4 seconds. */
7929 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
7930 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
7931 if (le16_to_cpu(nv
->login_timeout
) < 4)
7932 nv
->login_timeout
= cpu_to_le16(4);
7933 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
7935 /* Set minimum RATOV to 100 tenths of a second. */
7938 ha
->loop_reset_delay
= nv
->reset_delay
;
7940 /* Link Down Timeout = 0:
7942 * When Port Down timer expires we will start returning
7943 * I/O's to OS with "DID_NO_CONNECT".
7945 * Link Down Timeout != 0:
7947 * The driver waits for the link to come up after link down
7948 * before returning I/Os to OS with "DID_NO_CONNECT".
7950 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
7951 ha
->loop_down_abort_time
=
7952 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
7954 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
7955 ha
->loop_down_abort_time
=
7956 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
7959 /* Need enough time to try and get the port back. */
7960 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
7961 if (qlport_down_retry
)
7962 ha
->port_down_retry_count
= qlport_down_retry
;
7964 /* Set login_retry_count */
7965 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
7966 if (ha
->port_down_retry_count
==
7967 le16_to_cpu(nv
->port_down_retry_count
) &&
7968 ha
->port_down_retry_count
> 3)
7969 ha
->login_retry_count
= ha
->port_down_retry_count
;
7970 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
7971 ha
->login_retry_count
= ha
->port_down_retry_count
;
7972 if (ql2xloginretrycount
)
7973 ha
->login_retry_count
= ql2xloginretrycount
;
7975 /* if not running MSI-X we need handshaking on interrupts */
7976 if (!vha
->hw
->flags
.msix_enabled
&& (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)))
7977 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
7980 if (!vha
->flags
.init_done
) {
7981 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
7982 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
7983 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
7984 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
7986 icb
->firmware_options_2
&= cpu_to_le32(
7987 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
7988 vha
->flags
.process_response_queue
= 0;
7989 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
7990 ha
->zio_mode
= QLA_ZIO_MODE_6
;
7992 ql_log(ql_log_info
, vha
, 0x0075,
7993 "ZIO mode %d enabled; timer delay (%d us).\n",
7995 ha
->zio_timer
* 100);
7997 icb
->firmware_options_2
|= cpu_to_le32(
7998 (uint32_t)ha
->zio_mode
);
7999 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
8000 vha
->flags
.process_response_queue
= 1;
8003 /* enable RIDA Format2 */
8004 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
8005 icb
->firmware_options_3
|= BIT_0
;
8007 if (IS_QLA27XX(ha
)) {
8008 icb
->firmware_options_3
|= BIT_8
;
8009 ql_dbg(ql_log_info
, vha
, 0x0075,
8010 "Enabling direct connection.\n");
8014 ql_log(ql_log_warn
, vha
, 0x0076,
8015 "NVRAM configuration failed.\n");
8021 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
8024 struct qla_hw_data
*ha
= vha
->hw
;
8025 struct req_que
*req
= ha
->req_q_map
[0];
8026 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
8027 struct scsi_qla_host
*vp
;
8028 unsigned long flags
;
8030 status
= qla2x00_init_rings(vha
);
8032 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8033 ha
->flags
.chip_reset_done
= 1;
8035 status
= qla2x00_fw_ready(vha
);
8037 /* Issue a marker after FW becomes ready. */
8038 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
8039 vha
->flags
.online
= 1;
8040 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8043 /* if no cable then assume it's good */
8044 if ((vha
->device_flags
& DFLG_NO_CABLE
))
8049 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8051 if (!atomic_read(&vha
->loop_down_timer
)) {
8053 * Issue marker command only when we are going
8054 * to start the I/O .
8056 vha
->marker_needed
= 1;
8059 ha
->isp_ops
->enable_intrs(ha
);
8061 ha
->isp_abort_cnt
= 0;
8062 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
8064 /* Update the firmware version */
8065 status
= qla82xx_check_md_needed(vha
);
8068 ha
->flags
.fce_enabled
= 1;
8070 fce_calc_size(ha
->fce_bufs
));
8071 rval
= qla2x00_enable_fce_trace(vha
,
8072 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
8075 ql_log(ql_log_warn
, vha
, 0x8001,
8076 "Unable to reinitialize FCE (%d).\n",
8078 ha
->flags
.fce_enabled
= 0;
8083 memset(ha
->eft
, 0, EFT_SIZE
);
8084 rval
= qla2x00_enable_eft_trace(vha
,
8085 ha
->eft_dma
, EFT_NUM_BUFFERS
);
8087 ql_log(ql_log_warn
, vha
, 0x8010,
8088 "Unable to reinitialize EFT (%d).\n",
8095 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
8096 "qla82xx_restart_isp succeeded.\n");
8098 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8099 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
8101 atomic_inc(&vp
->vref_count
);
8102 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8104 qla2x00_vp_abort_isp(vp
);
8106 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8107 atomic_dec(&vp
->vref_count
);
8110 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8113 ql_log(ql_log_warn
, vha
, 0x8016,
8114 "qla82xx_restart_isp **** FAILED ****.\n");
8121 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
8123 struct qla_hw_data
*ha
= vha
->hw
;
8125 /* Hold status IOCBs until ABTS response received. */
8127 ha
->fw_options
[3] |= BIT_12
;
8129 /* Set Retry FLOGI in case of P2P connection */
8130 if (ha
->operating_mode
== P2P
) {
8131 ha
->fw_options
[2] |= BIT_3
;
8132 ql_dbg(ql_dbg_disc
, vha
, 0x2103,
8133 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8134 __func__
, ha
->fw_options
[2]);
8137 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8138 if (ql2xmvasynctoatio
) {
8139 if (qla_tgt_mode_enabled(vha
) ||
8140 qla_dual_mode_enabled(vha
))
8141 ha
->fw_options
[2] |= BIT_11
;
8143 ha
->fw_options
[2] &= ~BIT_11
;
8146 if (qla_tgt_mode_enabled(vha
) ||
8147 qla_dual_mode_enabled(vha
)) {
8148 /* FW auto send SCSI status during */
8149 ha
->fw_options
[1] |= BIT_8
;
8150 ha
->fw_options
[10] |= (u16
)SAM_STAT_BUSY
<< 8;
8152 /* FW perform Exchange validation */
8153 ha
->fw_options
[2] |= BIT_4
;
8155 ha
->fw_options
[1] &= ~BIT_8
;
8156 ha
->fw_options
[10] &= 0x00ff;
8158 ha
->fw_options
[2] &= ~BIT_4
;
8161 if (ql2xetsenable
) {
8162 /* Enable ETS Burst. */
8163 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
8164 ha
->fw_options
[2] |= BIT_9
;
8167 ql_dbg(ql_dbg_init
, vha
, 0x00e9,
8168 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8169 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
8170 ha
->fw_options
[3], vha
->host
->active_mode
);
8172 qla2x00_set_fw_options(vha
, ha
->fw_options
);
8176 * qla24xx_get_fcp_prio
8177 * Gets the fcp cmd priority value for the logged in port.
8178 * Looks for a match of the port descriptors within
8179 * each of the fcp prio config entries. If a match is found,
8180 * the tag (priority) value is returned.
8183 * vha = scsi host structure pointer.
8184 * fcport = port structure pointer.
8187 * non-zero (if found)
8194 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8197 uint8_t pid_match
, wwn_match
;
8199 uint32_t pid1
, pid2
;
8200 uint64_t wwn1
, wwn2
;
8201 struct qla_fcp_prio_entry
*pri_entry
;
8202 struct qla_hw_data
*ha
= vha
->hw
;
8204 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
8208 entries
= ha
->fcp_prio_cfg
->num_entries
;
8209 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
8211 for (i
= 0; i
< entries
; i
++) {
8212 pid_match
= wwn_match
= 0;
8214 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
8219 /* check source pid for a match */
8220 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
8221 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
8222 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
8223 if (pid1
== INVALID_PORT_ID
)
8225 else if (pid1
== pid2
)
8229 /* check destination pid for a match */
8230 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
8231 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
8232 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
8233 if (pid1
== INVALID_PORT_ID
)
8235 else if (pid1
== pid2
)
8239 /* check source WWN for a match */
8240 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
8241 wwn1
= wwn_to_u64(vha
->port_name
);
8242 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
8243 if (wwn2
== (uint64_t)-1)
8245 else if (wwn1
== wwn2
)
8249 /* check destination WWN for a match */
8250 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
8251 wwn1
= wwn_to_u64(fcport
->port_name
);
8252 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
8253 if (wwn2
== (uint64_t)-1)
8255 else if (wwn1
== wwn2
)
8259 if (pid_match
== 2 || wwn_match
== 2) {
8260 /* Found a matching entry */
8261 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
8262 priority
= pri_entry
->tag
;
8273 * qla24xx_update_fcport_fcp_prio
8274 * Activates fcp priority for the logged in fc port
8277 * vha = scsi host structure pointer.
8278 * fcp = port structure pointer.
8281 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8287 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8293 if (fcport
->port_type
!= FCT_TARGET
||
8294 fcport
->loop_id
== FC_NO_LOOP_ID
)
8295 return QLA_FUNCTION_FAILED
;
8297 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
8299 return QLA_FUNCTION_FAILED
;
8301 if (IS_P3P_TYPE(vha
->hw
)) {
8302 fcport
->fcp_prio
= priority
& 0xf;
8306 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
8307 if (ret
== QLA_SUCCESS
) {
8308 if (fcport
->fcp_prio
!= priority
)
8309 ql_dbg(ql_dbg_user
, vha
, 0x709e,
8310 "Updated FCP_CMND priority - value=%d loop_id=%d "
8311 "port_id=%02x%02x%02x.\n", priority
,
8312 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
8313 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
8314 fcport
->fcp_prio
= priority
& 0xf;
8316 ql_dbg(ql_dbg_user
, vha
, 0x704f,
8317 "Unable to update FCP_CMND priority - ret=0x%x for "
8318 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
8319 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
8320 fcport
->d_id
.b
.al_pa
);
8325 * qla24xx_update_all_fcp_prio
8326 * Activates fcp priority for all the logged in ports
8329 * ha = adapter block pointer.
8332 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8338 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
8343 ret
= QLA_FUNCTION_FAILED
;
8344 /* We need to set priority for all logged in ports */
8345 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
8346 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);
8351 struct qla_qpair
*qla2xxx_create_qpair(struct scsi_qla_host
*vha
, int qos
,
8352 int vp_idx
, bool startqp
)
8357 struct qla_hw_data
*ha
= vha
->hw
;
8358 uint16_t qpair_id
= 0;
8359 struct qla_qpair
*qpair
= NULL
;
8360 struct qla_msix_entry
*msix
;
8362 if (!(ha
->fw_attributes
& BIT_6
) || !ha
->flags
.msix_enabled
) {
8363 ql_log(ql_log_warn
, vha
, 0x00181,
8364 "FW/Driver is not multi-queue capable.\n");
8368 if (ql2xmqsupport
|| ql2xnvmeenable
) {
8369 qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
8370 if (qpair
== NULL
) {
8371 ql_log(ql_log_warn
, vha
, 0x0182,
8372 "Failed to allocate memory for queue pair.\n");
8375 memset(qpair
, 0, sizeof(struct qla_qpair
));
8377 qpair
->hw
= vha
->hw
;
8379 qpair
->qp_lock_ptr
= &qpair
->qp_lock
;
8380 spin_lock_init(&qpair
->qp_lock
);
8381 qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
8383 /* Assign available que pair id */
8384 mutex_lock(&ha
->mq_lock
);
8385 qpair_id
= find_first_zero_bit(ha
->qpair_qid_map
, ha
->max_qpairs
);
8386 if (ha
->num_qpairs
>= ha
->max_qpairs
) {
8387 mutex_unlock(&ha
->mq_lock
);
8388 ql_log(ql_log_warn
, vha
, 0x0183,
8389 "No resources to create additional q pair.\n");
8393 set_bit(qpair_id
, ha
->qpair_qid_map
);
8394 ha
->queue_pair_map
[qpair_id
] = qpair
;
8395 qpair
->id
= qpair_id
;
8396 qpair
->vp_idx
= vp_idx
;
8397 qpair
->fw_started
= ha
->flags
.fw_started
;
8398 INIT_LIST_HEAD(&qpair
->hints_list
);
8399 INIT_LIST_HEAD(&qpair
->nvme_done_list
);
8400 qpair
->chip_reset
= ha
->base_qpair
->chip_reset
;
8401 qpair
->enable_class_2
= ha
->base_qpair
->enable_class_2
;
8402 qpair
->enable_explicit_conf
=
8403 ha
->base_qpair
->enable_explicit_conf
;
8405 for (i
= 0; i
< ha
->msix_count
; i
++) {
8406 msix
= &ha
->msix_entries
[i
];
8410 ql_dbg(ql_dbg_multiq
, vha
, 0xc00f,
8411 "Vector %x selected for qpair\n", msix
->vector
);
8415 ql_log(ql_log_warn
, vha
, 0x0184,
8416 "Out of MSI-X vectors!.\n");
8420 qpair
->msix
->in_use
= 1;
8421 list_add_tail(&qpair
->qp_list_elem
, &vha
->qp_list
);
8422 qpair
->pdev
= ha
->pdev
;
8423 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
))
8424 qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
8426 mutex_unlock(&ha
->mq_lock
);
8428 /* Create response queue first */
8429 rsp_id
= qla25xx_create_rsp_que(ha
, 0, 0, 0, qpair
, startqp
);
8431 ql_log(ql_log_warn
, vha
, 0x0185,
8432 "Failed to create response queue.\n");
8436 qpair
->rsp
= ha
->rsp_q_map
[rsp_id
];
8438 /* Create request queue */
8439 req_id
= qla25xx_create_req_que(ha
, 0, vp_idx
, 0, rsp_id
, qos
,
8442 ql_log(ql_log_warn
, vha
, 0x0186,
8443 "Failed to create request queue.\n");
8447 qpair
->req
= ha
->req_q_map
[req_id
];
8448 qpair
->rsp
->req
= qpair
->req
;
8449 qpair
->rsp
->qpair
= qpair
;
8450 /* init qpair to this cpu. Will adjust at run time. */
8451 qla_cpu_update(qpair
, smp_processor_id());
8453 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
8454 if (ha
->fw_attributes
& BIT_4
)
8455 qpair
->difdix_supported
= 1;
8458 qpair
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
8459 if (!qpair
->srb_mempool
) {
8460 ql_log(ql_log_warn
, vha
, 0xd036,
8461 "Failed to create srb mempool for qpair %d\n",
8466 /* Mark as online */
8469 if (!vha
->flags
.qpairs_available
)
8470 vha
->flags
.qpairs_available
= 1;
8472 ql_dbg(ql_dbg_multiq
, vha
, 0xc00d,
8473 "Request/Response queue pair created, id %d\n",
8475 ql_dbg(ql_dbg_init
, vha
, 0x0187,
8476 "Request/Response queue pair created, id %d\n",
8483 qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8485 mutex_lock(&ha
->mq_lock
);
8486 qpair
->msix
->in_use
= 0;
8487 list_del(&qpair
->qp_list_elem
);
8488 if (list_empty(&vha
->qp_list
))
8489 vha
->flags
.qpairs_available
= 0;
8491 ha
->queue_pair_map
[qpair_id
] = NULL
;
8492 clear_bit(qpair_id
, ha
->qpair_qid_map
);
8494 mutex_unlock(&ha
->mq_lock
);
8500 int qla2xxx_delete_qpair(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
)
8502 int ret
= QLA_FUNCTION_FAILED
;
8503 struct qla_hw_data
*ha
= qpair
->hw
;
8505 qpair
->delete_in_progress
= 1;
8506 while (atomic_read(&qpair
->ref_count
))
8509 ret
= qla25xx_delete_req_que(vha
, qpair
->req
);
8510 if (ret
!= QLA_SUCCESS
)
8513 ret
= qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8514 if (ret
!= QLA_SUCCESS
)
8517 mutex_lock(&ha
->mq_lock
);
8518 ha
->queue_pair_map
[qpair
->id
] = NULL
;
8519 clear_bit(qpair
->id
, ha
->qpair_qid_map
);
8521 list_del(&qpair
->qp_list_elem
);
8522 if (list_empty(&vha
->qp_list
)) {
8523 vha
->flags
.qpairs_available
= 0;
8524 vha
->flags
.qpairs_req_created
= 0;
8525 vha
->flags
.qpairs_rsp_created
= 0;
8527 mempool_destroy(qpair
->srb_mempool
);
8529 mutex_unlock(&ha
->mq_lock
);