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
;
56 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
58 req
->outstanding_cmds
[sp
->handle
] = NULL
;
59 iocb
= &sp
->u
.iocb_cmd
;
60 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
65 qla2x00_sp_free(void *ptr
)
68 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
70 del_timer(&iocb
->timer
);
74 /* Asynchronous Login/Logout Routines -------------------------------------- */
77 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
80 struct qla_hw_data
*ha
= vha
->hw
;
82 /* Firmware should use switch negotiated r_a_tov for timeout. */
83 tmo
= ha
->r_a_tov
/ 10 * 2;
85 tmo
= FX00_DEF_RATOV
* 2;
86 } else if (!IS_FWI2_CAPABLE(ha
)) {
88 * Except for earlier ISPs where the timeout is seeded from the
89 * initialization control block.
91 tmo
= ha
->login_timeout
;
97 qla2x00_async_iocb_timeout(void *data
)
100 fc_port_t
*fcport
= sp
->fcport
;
101 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
106 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
107 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
108 sp
->name
, sp
->handle
, fcport
->d_id
.b24
, fcport
->port_name
);
110 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
112 pr_info("Async-%s timeout - hdl=%x.\n",
113 sp
->name
, sp
->handle
);
118 rc
= qla24xx_async_abort_cmd(sp
, false);
120 /* Retry as needed. */
121 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
122 lio
->u
.logio
.data
[1] =
123 lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
124 QLA_LOGIO_LOGIN_RETRIED
: 0;
125 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
126 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
;
128 if (sp
->qpair
->req
->outstanding_cmds
[h
] ==
130 sp
->qpair
->req
->outstanding_cmds
[h
] =
135 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
136 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
140 case SRB_CT_PTHRU_CMD
:
146 rc
= qla24xx_async_abort_cmd(sp
, false);
148 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
149 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
;
151 if (sp
->qpair
->req
->outstanding_cmds
[h
] ==
153 sp
->qpair
->req
->outstanding_cmds
[h
] =
158 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
159 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
166 qla2x00_async_login_sp_done(void *ptr
, int res
)
169 struct scsi_qla_host
*vha
= sp
->vha
;
170 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
173 ql_dbg(ql_dbg_disc
, vha
, 0x20dd,
174 "%s %8phC res %d \n", __func__
, sp
->fcport
->port_name
, res
);
176 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
178 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
179 memset(&ea
, 0, sizeof(ea
));
180 ea
.event
= FCME_PLOGI_DONE
;
181 ea
.fcport
= sp
->fcport
;
182 ea
.data
[0] = lio
->u
.logio
.data
[0];
183 ea
.data
[1] = lio
->u
.logio
.data
[1];
184 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
185 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
187 qla2x00_fcport_event_handler(vha
, &ea
);
194 fcport_is_smaller(fc_port_t
*fcport
)
196 if (wwn_to_u64(fcport
->port_name
) <
197 wwn_to_u64(fcport
->vha
->port_name
))
204 fcport_is_bigger(fc_port_t
*fcport
)
206 return !fcport_is_smaller(fcport
);
210 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
214 struct srb_iocb
*lio
;
215 int rval
= QLA_FUNCTION_FAILED
;
217 if (!vha
->flags
.online
)
220 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
224 fcport
->flags
|= FCF_ASYNC_SENT
;
225 fcport
->logout_completed
= 0;
227 fcport
->disc_state
= DSC_LOGIN_PEND
;
228 sp
->type
= SRB_LOGIN_CMD
;
230 sp
->gen1
= fcport
->rscn_gen
;
231 sp
->gen2
= fcport
->login_gen
;
233 lio
= &sp
->u
.iocb_cmd
;
234 lio
->timeout
= qla2x00_async_iocb_timeout
;
235 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
237 sp
->done
= qla2x00_async_login_sp_done
;
238 if (N2N_TOPO(fcport
->vha
->hw
) && fcport_is_bigger(fcport
)) {
239 lio
->u
.logio
.flags
|= SRB_LOGIN_PRLI_ONLY
;
241 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
243 if (fcport
->fc4f_nvme
)
244 lio
->u
.logio
.flags
|= SRB_LOGIN_SKIP_PRLI
;
248 rval
= qla2x00_start_sp(sp
);
249 if (rval
!= QLA_SUCCESS
) {
250 fcport
->flags
|= FCF_LOGIN_NEEDED
;
251 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
255 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
256 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
257 "retries=%d.\n", fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
258 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
259 fcport
->login_retry
);
264 fcport
->flags
&= ~FCF_ASYNC_SENT
;
266 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
271 qla2x00_async_logout_sp_done(void *ptr
, int res
)
275 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
276 sp
->fcport
->login_gen
++;
277 qlt_logo_completion_handler(sp
->fcport
, res
);
282 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
285 struct srb_iocb
*lio
;
286 int rval
= QLA_FUNCTION_FAILED
;
288 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
291 fcport
->flags
|= FCF_ASYNC_SENT
;
292 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
296 sp
->type
= SRB_LOGOUT_CMD
;
299 lio
= &sp
->u
.iocb_cmd
;
300 lio
->timeout
= qla2x00_async_iocb_timeout
;
301 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
303 sp
->done
= qla2x00_async_logout_sp_done
;
304 rval
= qla2x00_start_sp(sp
);
305 if (rval
!= QLA_SUCCESS
)
308 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
309 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
310 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
311 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
318 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
323 qla2x00_async_prlo_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
326 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
327 /* Don't re-login in target mode */
328 if (!fcport
->tgt_session
)
329 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
330 qlt_logo_completion_handler(fcport
, data
[0]);
334 qla2x00_async_prlo_sp_done(void *s
, int res
)
336 srb_t
*sp
= (srb_t
*)s
;
337 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
338 struct scsi_qla_host
*vha
= sp
->vha
;
340 sp
->fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
341 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
342 qla2x00_post_async_prlo_done_work(sp
->fcport
->vha
, sp
->fcport
,
348 qla2x00_async_prlo(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
351 struct srb_iocb
*lio
;
354 rval
= QLA_FUNCTION_FAILED
;
355 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
359 sp
->type
= SRB_PRLO_CMD
;
362 lio
= &sp
->u
.iocb_cmd
;
363 lio
->timeout
= qla2x00_async_iocb_timeout
;
364 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
366 sp
->done
= qla2x00_async_prlo_sp_done
;
367 rval
= qla2x00_start_sp(sp
);
368 if (rval
!= QLA_SUCCESS
)
371 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
372 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
373 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
374 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
380 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
385 void qla24xx_handle_adisc_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
387 struct fc_port
*fcport
= ea
->fcport
;
389 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
390 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
391 __func__
, fcport
->port_name
, fcport
->disc_state
,
392 fcport
->fw_login_state
, ea
->rc
, fcport
->login_gen
, ea
->sp
->gen2
,
393 fcport
->rscn_gen
, ea
->sp
->gen1
, fcport
->loop_id
);
395 if (ea
->data
[0] != MBS_COMMAND_COMPLETE
) {
396 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
397 "%s %8phC: adisc fail: post delete\n",
398 __func__
, ea
->fcport
->port_name
);
399 qlt_schedule_sess_for_deletion(ea
->fcport
);
403 if (ea
->fcport
->disc_state
== DSC_DELETE_PEND
)
406 if (ea
->sp
->gen2
!= ea
->fcport
->login_gen
) {
407 /* target side must have changed it. */
408 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
409 "%s %8phC generation changed\n",
410 __func__
, ea
->fcport
->port_name
);
412 } else if (ea
->sp
->gen1
!= ea
->fcport
->rscn_gen
) {
413 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
414 __func__
, __LINE__
, ea
->fcport
->port_name
);
415 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
419 __qla24xx_handle_gpdb_event(vha
, ea
);
422 int qla_post_els_plogi_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
424 struct qla_work_evt
*e
;
426 e
= qla2x00_alloc_work(vha
, QLA_EVT_ELS_PLOGI
);
428 return QLA_FUNCTION_FAILED
;
430 e
->u
.fcport
.fcport
= fcport
;
431 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
432 return qla2x00_post_work(vha
, e
);
436 qla2x00_async_adisc_sp_done(void *ptr
, int res
)
439 struct scsi_qla_host
*vha
= sp
->vha
;
441 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
443 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
444 "Async done-%s res %x %8phC\n",
445 sp
->name
, res
, sp
->fcport
->port_name
);
447 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
449 memset(&ea
, 0, sizeof(ea
));
450 ea
.event
= FCME_ADISC_DONE
;
452 ea
.data
[0] = lio
->u
.logio
.data
[0];
453 ea
.data
[1] = lio
->u
.logio
.data
[1];
454 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
455 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
456 ea
.fcport
= sp
->fcport
;
459 qla2x00_fcport_event_handler(vha
, &ea
);
465 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
469 struct srb_iocb
*lio
;
472 rval
= QLA_FUNCTION_FAILED
;
473 fcport
->flags
|= FCF_ASYNC_SENT
;
474 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
478 sp
->type
= SRB_ADISC_CMD
;
481 lio
= &sp
->u
.iocb_cmd
;
482 lio
->timeout
= qla2x00_async_iocb_timeout
;
483 sp
->gen1
= fcport
->rscn_gen
;
484 sp
->gen2
= fcport
->login_gen
;
485 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
487 sp
->done
= qla2x00_async_adisc_sp_done
;
488 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
489 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
490 rval
= qla2x00_start_sp(sp
);
491 if (rval
!= QLA_SUCCESS
)
494 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
495 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
496 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
, fcport
->port_name
);
502 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
503 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
507 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t
*vha
,
508 struct event_arg
*ea
)
510 fc_port_t
*fcport
, *conflict_fcport
;
511 struct get_name_list_extended
*e
;
512 u16 i
, n
, found
= 0, loop_id
;
516 u8 current_login_state
;
519 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
520 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
521 __func__
, fcport
->port_name
, fcport
->disc_state
,
522 fcport
->fw_login_state
, ea
->rc
,
523 fcport
->login_gen
, fcport
->last_login_gen
,
524 fcport
->rscn_gen
, fcport
->last_rscn_gen
, vha
->loop_id
);
526 if (fcport
->disc_state
== DSC_DELETE_PEND
)
529 if (ea
->rc
) { /* rval */
530 if (fcport
->login_retry
== 0) {
531 ql_dbg(ql_dbg_disc
, vha
, 0x20de,
532 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
533 fcport
->port_name
, fcport
->login_retry
);
538 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
539 ql_dbg(ql_dbg_disc
, vha
, 0x20df,
540 "%s %8phC rscn gen changed rscn %d|%d \n",
541 __func__
, fcport
->port_name
,
542 fcport
->last_rscn_gen
, fcport
->rscn_gen
);
543 qla24xx_post_gidpn_work(vha
, fcport
);
545 } else if (fcport
->last_login_gen
!= fcport
->login_gen
) {
546 ql_dbg(ql_dbg_disc
, vha
, 0x20e0,
547 "%s %8phC login gen changed\n",
548 __func__
, fcport
->port_name
);
552 n
= ea
->data
[0] / sizeof(struct get_name_list_extended
);
554 ql_dbg(ql_dbg_disc
, vha
, 0x20e1,
555 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
556 __func__
, __LINE__
, fcport
->port_name
, n
,
557 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
558 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
);
560 for (i
= 0; i
< n
; i
++) {
562 wwn
= wwn_to_u64(e
->port_name
);
563 id
.b
.domain
= e
->port_id
[2];
564 id
.b
.area
= e
->port_id
[1];
565 id
.b
.al_pa
= e
->port_id
[0];
568 if (memcmp((u8
*)&wwn
, fcport
->port_name
, WWN_SIZE
))
571 if (IS_SW_RESV_ADDR(id
))
576 loop_id
= le16_to_cpu(e
->nport_handle
);
577 loop_id
= (loop_id
& 0x7fff);
578 if (fcport
->fc4f_nvme
)
579 current_login_state
= e
->current_login_state
>> 4;
581 current_login_state
= e
->current_login_state
& 0xf;
584 ql_dbg(ql_dbg_disc
, vha
, 0x20e2,
585 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
586 __func__
, fcport
->port_name
,
587 e
->current_login_state
, fcport
->fw_login_state
,
588 fcport
->fc4f_nvme
, id
.b
.domain
, id
.b
.area
, id
.b
.al_pa
,
589 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
590 fcport
->d_id
.b
.al_pa
, loop_id
, fcport
->loop_id
);
592 switch (fcport
->disc_state
) {
593 case DSC_DELETE_PEND
:
597 if ((id
.b24
!= fcport
->d_id
.b24
&&
599 (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
600 fcport
->loop_id
!= loop_id
)) {
601 ql_dbg(ql_dbg_disc
, vha
, 0x20e3,
602 "%s %d %8phC post del sess\n",
603 __func__
, __LINE__
, fcport
->port_name
);
604 qlt_schedule_sess_for_deletion(fcport
);
610 fcport
->loop_id
= loop_id
;
612 wwn
= wwn_to_u64(fcport
->port_name
);
613 qlt_find_sess_invalidate_other(vha
, wwn
,
614 id
, loop_id
, &conflict_fcport
);
616 if (conflict_fcport
) {
618 * Another share fcport share the same loop_id &
619 * nport id. Conflict fcport needs to finish
620 * cleanup before this fcport can proceed to login.
622 conflict_fcport
->conflict
= fcport
;
623 fcport
->login_pause
= 1;
626 switch (vha
->hw
->current_topology
) {
628 switch (current_login_state
) {
629 case DSC_LS_PRLI_COMP
:
630 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
,
631 vha
, 0x20e4, "%s %d %8phC post gpdb\n",
632 __func__
, __LINE__
, fcport
->port_name
);
634 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
635 fcport
->port_type
= FCT_INITIATOR
;
637 fcport
->port_type
= FCT_TARGET
;
638 data
[0] = data
[1] = 0;
639 qla2x00_post_async_adisc_work(vha
, fcport
,
642 case DSC_LS_PORT_UNAVAIL
:
644 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
645 qla2x00_clear_loop_id(fcport
);
647 fcport
->loop_id
= loop_id
;
648 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
649 qla24xx_fcport_handle_login(vha
, fcport
);
654 fcport
->fw_login_state
= current_login_state
;
656 switch (current_login_state
) {
657 case DSC_LS_PRLI_COMP
:
658 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
659 fcport
->port_type
= FCT_INITIATOR
;
661 fcport
->port_type
= FCT_TARGET
;
663 data
[0] = data
[1] = 0;
664 qla2x00_post_async_adisc_work(vha
, fcport
,
667 case DSC_LS_PLOGI_COMP
:
668 if (fcport_is_bigger(fcport
)) {
669 /* local adapter is smaller */
670 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
671 qla2x00_clear_loop_id(fcport
);
673 fcport
->loop_id
= loop_id
;
674 qla24xx_fcport_handle_login(vha
,
680 if (fcport_is_smaller(fcport
)) {
681 /* local adapter is bigger */
682 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
683 qla2x00_clear_loop_id(fcport
);
685 fcport
->loop_id
= loop_id
;
686 qla24xx_fcport_handle_login(vha
,
692 } /* switch (ha->current_topology) */
696 switch (vha
->hw
->current_topology
) {
699 for (i
= 0; i
< n
; i
++) {
701 id
.b
.domain
= e
->port_id
[0];
702 id
.b
.area
= e
->port_id
[1];
703 id
.b
.al_pa
= e
->port_id
[2];
705 loop_id
= le16_to_cpu(e
->nport_handle
);
707 if (fcport
->d_id
.b24
== id
.b24
) {
709 qla2x00_find_fcport_by_wwpn(vha
,
711 if (conflict_fcport
) {
712 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
,
714 "%s %d %8phC post del sess\n",
716 conflict_fcport
->port_name
);
717 qlt_schedule_sess_for_deletion
722 * FW already picked this loop id for
725 if (fcport
->loop_id
== loop_id
)
726 fcport
->loop_id
= FC_NO_LOOP_ID
;
728 qla24xx_fcport_handle_login(vha
, fcport
);
731 fcport
->disc_state
= DSC_DELETED
;
732 if (time_after_eq(jiffies
, fcport
->dm_login_expire
)) {
733 if (fcport
->n2n_link_reset_cnt
< 2) {
734 fcport
->n2n_link_reset_cnt
++;
736 * remote port is not sending PLOGI.
737 * Reset link to kick start his state
740 set_bit(N2N_LINK_RESET
,
743 if (fcport
->n2n_chip_reset
< 1) {
744 ql_log(ql_log_info
, vha
, 0x705d,
745 "Chip reset to bring laser down");
746 set_bit(ISP_ABORT_NEEDED
,
748 fcport
->n2n_chip_reset
++;
750 ql_log(ql_log_info
, vha
, 0x705d,
751 "Remote port %8ph is not coming back\n",
753 fcport
->scan_state
= 0;
756 qla2xxx_wake_dpc(vha
);
759 * report port suppose to do PLOGI. Give him
760 * more time. FW will catch it.
762 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
772 qla24xx_async_gnl_sp_done(void *s
, int res
)
775 struct scsi_qla_host
*vha
= sp
->vha
;
777 struct fc_port
*fcport
= NULL
, *tf
;
778 u16 i
, n
= 0, loop_id
;
780 struct get_name_list_extended
*e
;
785 ql_dbg(ql_dbg_disc
, vha
, 0x20e7,
786 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
787 sp
->name
, res
, sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1],
788 sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[2]);
790 memset(&ea
, 0, sizeof(ea
));
793 ea
.event
= FCME_GNL_DONE
;
795 if (sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] >=
796 sizeof(struct get_name_list_extended
)) {
797 n
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] /
798 sizeof(struct get_name_list_extended
);
799 ea
.data
[0] = sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1]; /* amnt xfered */
802 for (i
= 0; i
< n
; i
++) {
804 loop_id
= le16_to_cpu(e
->nport_handle
);
805 /* mask out reserve bit */
806 loop_id
= (loop_id
& 0x7fff);
807 set_bit(loop_id
, vha
->hw
->loop_id_map
);
808 wwn
= wwn_to_u64(e
->port_name
);
810 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0x20e8,
811 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
812 __func__
, (void *)&wwn
, e
->port_id
[2], e
->port_id
[1],
813 e
->port_id
[0], e
->current_login_state
, e
->last_login_state
,
817 spin_lock_irqsave(&vha
->gnl
.fcports_lock
, flags
);
821 if (!list_empty(&vha
->gnl
.fcports
))
822 list_splice_init(&vha
->gnl
.fcports
, &h
);
824 list_for_each_entry_safe(fcport
, tf
, &h
, gnl_entry
) {
825 list_del_init(&fcport
->gnl_entry
);
826 spin_lock(&vha
->hw
->tgt
.sess_lock
);
827 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
828 spin_unlock(&vha
->hw
->tgt
.sess_lock
);
831 qla2x00_fcport_event_handler(vha
, &ea
);
833 spin_unlock_irqrestore(&vha
->gnl
.fcports_lock
, flags
);
835 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
836 /* create new fcport if fw has knowledge of new sessions */
837 for (i
= 0; i
< n
; i
++) {
842 wwn
= wwn_to_u64(e
->port_name
);
845 list_for_each_entry_safe(fcport
, tf
, &vha
->vp_fcports
, list
) {
846 if (!memcmp((u8
*)&wwn
, fcport
->port_name
,
853 id
.b
.domain
= e
->port_id
[2];
854 id
.b
.area
= e
->port_id
[1];
855 id
.b
.al_pa
= e
->port_id
[0];
858 if (!found
&& wwn
&& !IS_SW_RESV_ADDR(id
)) {
859 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
860 "%s %d %8phC %06x post new sess\n",
861 __func__
, __LINE__
, (u8
*)&wwn
, id
.b24
);
862 wwnn
= wwn_to_u64(e
->node_name
);
863 qla24xx_post_newsess_work(vha
, &id
, (u8
*)&wwn
,
864 (u8
*)&wwnn
, NULL
, FC4_TYPE_UNKNOWN
);
868 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
873 int qla24xx_async_gnl(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
876 struct srb_iocb
*mbx
;
877 int rval
= QLA_FUNCTION_FAILED
;
881 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
884 ql_dbg(ql_dbg_disc
, vha
, 0x20d9,
885 "Async-gnlist WWPN %8phC \n", fcport
->port_name
);
887 spin_lock_irqsave(&vha
->gnl
.fcports_lock
, flags
);
888 if (!list_empty(&fcport
->gnl_entry
)) {
889 spin_unlock_irqrestore(&vha
->gnl
.fcports_lock
, flags
);
894 spin_lock(&vha
->hw
->tgt
.sess_lock
);
895 fcport
->disc_state
= DSC_GNL
;
896 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
897 fcport
->last_login_gen
= fcport
->login_gen
;
898 spin_unlock(&vha
->hw
->tgt
.sess_lock
);
900 list_add_tail(&fcport
->gnl_entry
, &vha
->gnl
.fcports
);
901 spin_unlock_irqrestore(&vha
->gnl
.fcports_lock
, flags
);
903 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
907 fcport
->flags
|= FCF_ASYNC_SENT
;
908 sp
->type
= SRB_MB_IOCB
;
910 sp
->gen1
= fcport
->rscn_gen
;
911 sp
->gen2
= fcport
->login_gen
;
913 mbx
= &sp
->u
.iocb_cmd
;
914 mbx
->timeout
= qla2x00_async_iocb_timeout
;
915 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
917 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
918 mb
[0] = MBC_PORT_NODE_NAME_LIST
;
919 mb
[1] = BIT_2
| BIT_3
;
920 mb
[2] = MSW(vha
->gnl
.ldma
);
921 mb
[3] = LSW(vha
->gnl
.ldma
);
922 mb
[6] = MSW(MSD(vha
->gnl
.ldma
));
923 mb
[7] = LSW(MSD(vha
->gnl
.ldma
));
924 mb
[8] = vha
->gnl
.size
;
927 sp
->done
= qla24xx_async_gnl_sp_done
;
929 rval
= qla2x00_start_sp(sp
);
930 if (rval
!= QLA_SUCCESS
)
933 ql_dbg(ql_dbg_disc
, vha
, 0x20da,
934 "Async-%s - OUT WWPN %8phC hndl %x\n",
935 sp
->name
, fcport
->port_name
, sp
->handle
);
941 fcport
->flags
&= ~FCF_ASYNC_SENT
;
946 int qla24xx_post_gnl_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
948 struct qla_work_evt
*e
;
950 e
= qla2x00_alloc_work(vha
, QLA_EVT_GNL
);
952 return QLA_FUNCTION_FAILED
;
954 e
->u
.fcport
.fcport
= fcport
;
955 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
956 return qla2x00_post_work(vha
, e
);
960 void qla24xx_async_gpdb_sp_done(void *s
, int res
)
963 struct scsi_qla_host
*vha
= sp
->vha
;
964 struct qla_hw_data
*ha
= vha
->hw
;
965 fc_port_t
*fcport
= sp
->fcport
;
966 u16
*mb
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
;
969 ql_dbg(ql_dbg_disc
, vha
, 0x20db,
970 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
971 sp
->name
, res
, fcport
->port_name
, mb
[1], mb
[2]);
973 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
975 memset(&ea
, 0, sizeof(ea
));
976 ea
.event
= FCME_GPDB_DONE
;
980 qla2x00_fcport_event_handler(vha
, &ea
);
982 dma_pool_free(ha
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
983 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
988 static int qla24xx_post_prli_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
990 struct qla_work_evt
*e
;
992 e
= qla2x00_alloc_work(vha
, QLA_EVT_PRLI
);
994 return QLA_FUNCTION_FAILED
;
996 e
->u
.fcport
.fcport
= fcport
;
998 return qla2x00_post_work(vha
, e
);
1002 qla2x00_async_prli_sp_done(void *ptr
, int res
)
1005 struct scsi_qla_host
*vha
= sp
->vha
;
1006 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
1007 struct event_arg ea
;
1009 ql_dbg(ql_dbg_disc
, vha
, 0x2129,
1010 "%s %8phC res %d \n", __func__
,
1011 sp
->fcport
->port_name
, res
);
1013 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1015 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
1016 memset(&ea
, 0, sizeof(ea
));
1017 ea
.event
= FCME_PRLI_DONE
;
1018 ea
.fcport
= sp
->fcport
;
1019 ea
.data
[0] = lio
->u
.logio
.data
[0];
1020 ea
.data
[1] = lio
->u
.logio
.data
[1];
1021 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
1022 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
1025 qla2x00_fcport_event_handler(vha
, &ea
);
1032 qla24xx_async_prli(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1035 struct srb_iocb
*lio
;
1036 int rval
= QLA_FUNCTION_FAILED
;
1038 if (!vha
->flags
.online
)
1041 if (fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
||
1042 fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)
1045 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1049 fcport
->flags
|= FCF_ASYNC_SENT
;
1050 fcport
->logout_completed
= 0;
1052 sp
->type
= SRB_PRLI_CMD
;
1055 lio
= &sp
->u
.iocb_cmd
;
1056 lio
->timeout
= qla2x00_async_iocb_timeout
;
1057 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
1059 sp
->done
= qla2x00_async_prli_sp_done
;
1060 lio
->u
.logio
.flags
= 0;
1062 if (fcport
->fc4f_nvme
)
1063 lio
->u
.logio
.flags
|= SRB_LOGIN_NVME_PRLI
;
1065 rval
= qla2x00_start_sp(sp
);
1066 if (rval
!= QLA_SUCCESS
) {
1067 fcport
->flags
|= FCF_LOGIN_NEEDED
;
1068 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1072 ql_dbg(ql_dbg_disc
, vha
, 0x211b,
1073 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1074 fcport
->port_name
, sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
,
1075 fcport
->login_retry
, fcport
->fc4f_nvme
? "nvme" : "fc");
1081 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1085 int qla24xx_post_gpdb_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
1087 struct qla_work_evt
*e
;
1089 e
= qla2x00_alloc_work(vha
, QLA_EVT_GPDB
);
1091 return QLA_FUNCTION_FAILED
;
1093 e
->u
.fcport
.fcport
= fcport
;
1094 e
->u
.fcport
.opt
= opt
;
1095 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
1096 return qla2x00_post_work(vha
, e
);
1099 int qla24xx_async_gpdb(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
1102 struct srb_iocb
*mbx
;
1103 int rval
= QLA_FUNCTION_FAILED
;
1106 struct port_database_24xx
*pd
;
1107 struct qla_hw_data
*ha
= vha
->hw
;
1109 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
1112 fcport
->disc_state
= DSC_GPDB
;
1114 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1118 fcport
->flags
|= FCF_ASYNC_SENT
;
1119 sp
->type
= SRB_MB_IOCB
;
1121 sp
->gen1
= fcport
->rscn_gen
;
1122 sp
->gen2
= fcport
->login_gen
;
1124 mbx
= &sp
->u
.iocb_cmd
;
1125 mbx
->timeout
= qla2x00_async_iocb_timeout
;
1126 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
1128 pd
= dma_pool_zalloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
1130 ql_log(ql_log_warn
, vha
, 0xd043,
1131 "Failed to allocate port database structure.\n");
1135 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
1136 mb
[0] = MBC_GET_PORT_DATABASE
;
1137 mb
[1] = fcport
->loop_id
;
1138 mb
[2] = MSW(pd_dma
);
1139 mb
[3] = LSW(pd_dma
);
1140 mb
[6] = MSW(MSD(pd_dma
));
1141 mb
[7] = LSW(MSD(pd_dma
));
1142 mb
[9] = vha
->vp_idx
;
1145 mbx
->u
.mbx
.in
= (void *)pd
;
1146 mbx
->u
.mbx
.in_dma
= pd_dma
;
1148 sp
->done
= qla24xx_async_gpdb_sp_done
;
1150 rval
= qla2x00_start_sp(sp
);
1151 if (rval
!= QLA_SUCCESS
)
1154 ql_dbg(ql_dbg_disc
, vha
, 0x20dc,
1155 "Async-%s %8phC hndl %x opt %x\n",
1156 sp
->name
, fcport
->port_name
, sp
->handle
, opt
);
1162 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1165 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1167 qla24xx_post_gpdb_work(vha
, fcport
, opt
);
1172 void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1174 unsigned long flags
;
1176 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1177 ea
->fcport
->login_gen
++;
1178 ea
->fcport
->deleted
= 0;
1179 ea
->fcport
->logout_on_delete
= 1;
1181 if (!ea
->fcport
->login_succ
&& !IS_SW_RESV_ADDR(ea
->fcport
->d_id
)) {
1182 vha
->fcport_count
++;
1183 ea
->fcport
->login_succ
= 1;
1185 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1186 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1187 __func__
, __LINE__
, ea
->fcport
->port_name
,
1189 qla24xx_post_upd_fcport_work(vha
, ea
->fcport
);
1190 } else if (ea
->fcport
->login_succ
) {
1192 * We have an existing session. A late RSCN delivery
1193 * must have triggered the session to be re-validate.
1194 * Session is still valid.
1196 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1197 "%s %d %8phC session revalidate success\n",
1198 __func__
, __LINE__
, ea
->fcport
->port_name
);
1199 ea
->fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
1201 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1205 void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1207 fc_port_t
*fcport
= ea
->fcport
;
1208 struct port_database_24xx
*pd
;
1209 struct srb
*sp
= ea
->sp
;
1212 pd
= (struct port_database_24xx
*)sp
->u
.iocb_cmd
.u
.mbx
.in
;
1214 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1216 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
1217 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__
, fcport
->port_name
,
1218 fcport
->disc_state
, pd
->current_login_state
, fcport
->fc4f_nvme
,
1221 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1224 if (fcport
->fc4f_nvme
)
1225 ls
= pd
->current_login_state
>> 4;
1227 ls
= pd
->current_login_state
& 0xf;
1230 case PDS_PRLI_COMPLETE
:
1231 __qla24xx_parse_gpdb(vha
, fcport
, pd
);
1233 case PDS_PLOGI_PENDING
:
1234 case PDS_PLOGI_COMPLETE
:
1235 case PDS_PRLI_PENDING
:
1236 case PDS_PRLI2_PENDING
:
1237 /* Set discovery state back to GNL to Relogin attempt */
1238 if (qla_dual_mode_enabled(vha
) ||
1239 qla_ini_mode_enabled(vha
)) {
1240 fcport
->disc_state
= DSC_GNL
;
1241 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1244 case PDS_LOGO_PENDING
:
1245 case PDS_PORT_UNAVAILABLE
:
1247 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC post del sess\n",
1248 __func__
, __LINE__
, fcport
->port_name
);
1249 qlt_schedule_sess_for_deletion(fcport
);
1252 __qla24xx_handle_gpdb_event(vha
, ea
);
1255 static void qla_chk_n2n_b4_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1260 if (qla_tgt_mode_enabled(vha
))
1263 if (qla_dual_mode_enabled(vha
)) {
1264 if (N2N_TOPO(vha
->hw
)) {
1267 mywwn
= wwn_to_u64(vha
->port_name
);
1268 wwn
= wwn_to_u64(fcport
->port_name
);
1271 else if ((fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1272 && time_after_eq(jiffies
,
1273 fcport
->plogi_nack_done_deadline
))
1279 /* initiator mode */
1284 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1285 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1286 rc
= qla2x00_find_new_loop_id(vha
, fcport
);
1288 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
1289 "%s %d %8phC post del sess - out of loopid\n",
1290 __func__
, __LINE__
, fcport
->port_name
);
1291 fcport
->scan_state
= 0;
1292 qlt_schedule_sess_for_deletion(fcport
);
1296 ql_dbg(ql_dbg_disc
, vha
, 0x20bf,
1297 "%s %d %8phC post login\n",
1298 __func__
, __LINE__
, fcport
->port_name
);
1299 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
1303 int qla24xx_fcport_handle_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1308 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1309 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
1310 __func__
, fcport
->port_name
, fcport
->disc_state
,
1311 fcport
->fw_login_state
, fcport
->login_pause
, fcport
->flags
,
1312 fcport
->conflict
, fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1313 fcport
->login_gen
, fcport
->login_retry
,
1314 fcport
->loop_id
, fcport
->scan_state
);
1316 if (fcport
->scan_state
!= QLA_FCPORT_FOUND
)
1319 if ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
1320 ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1321 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)))
1324 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1325 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1326 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1331 /* for pure Target Mode. Login will not be initiated */
1332 if (vha
->host
->active_mode
== MODE_TARGET
)
1335 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1336 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1340 switch (fcport
->disc_state
) {
1342 wwn
= wwn_to_u64(fcport
->node_name
);
1343 switch (vha
->hw
->current_topology
) {
1345 if (fcport_is_smaller(fcport
)) {
1346 /* this adapter is bigger */
1347 if (fcport
->login_retry
) {
1348 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1349 qla2x00_find_new_loop_id(vha
,
1351 fcport
->fw_login_state
=
1352 DSC_LS_PORT_UNAVAIL
;
1354 fcport
->login_retry
--;
1355 qla_post_els_plogi_work(vha
, fcport
);
1357 ql_log(ql_log_info
, vha
, 0x705d,
1358 "Unable to reach remote port %8phC",
1362 qla24xx_post_gnl_work(vha
, fcport
);
1367 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1368 "%s %d %8phC post GNNID\n",
1369 __func__
, __LINE__
, fcport
->port_name
);
1370 qla24xx_post_gnnid_work(vha
, fcport
);
1371 } else if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1372 ql_dbg(ql_dbg_disc
, vha
, 0x20bd,
1373 "%s %d %8phC post gnl\n",
1374 __func__
, __LINE__
, fcport
->port_name
);
1375 qla24xx_post_gnl_work(vha
, fcport
);
1377 qla_chk_n2n_b4_login(vha
, fcport
);
1384 switch (vha
->hw
->current_topology
) {
1386 if ((fcport
->current_login_state
& 0xf) == 0x6) {
1387 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1388 "%s %d %8phC post GPDB work\n",
1389 __func__
, __LINE__
, fcport
->port_name
);
1390 fcport
->chip_reset
=
1391 vha
->hw
->base_qpair
->chip_reset
;
1392 qla24xx_post_gpdb_work(vha
, fcport
, 0);
1394 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1395 "%s %d %8phC post NVMe PRLI\n",
1396 __func__
, __LINE__
, fcport
->port_name
);
1397 qla24xx_post_prli_work(vha
, fcport
);
1401 if (fcport
->login_pause
) {
1402 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1403 fcport
->last_login_gen
= fcport
->login_gen
;
1404 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1407 qla_chk_n2n_b4_login(vha
, fcport
);
1412 case DSC_LOGIN_FAILED
:
1413 fcport
->login_retry
--;
1414 ql_dbg(ql_dbg_disc
, vha
, 0x20d0,
1415 "%s %d %8phC post gidpn\n",
1416 __func__
, __LINE__
, fcport
->port_name
);
1417 if (N2N_TOPO(vha
->hw
))
1418 qla_chk_n2n_b4_login(vha
, fcport
);
1420 qla24xx_post_gidpn_work(vha
, fcport
);
1423 case DSC_LOGIN_COMPLETE
:
1424 /* recheck login state */
1425 ql_dbg(ql_dbg_disc
, vha
, 0x20d1,
1426 "%s %d %8phC post adisc\n",
1427 __func__
, __LINE__
, fcport
->port_name
);
1428 fcport
->login_retry
--;
1429 data
[0] = data
[1] = 0;
1430 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
1433 case DSC_LOGIN_PEND
:
1434 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1435 qla24xx_post_prli_work(vha
, fcport
);
1446 void qla24xx_handle_rscn_event(fc_port_t
*fcport
, struct event_arg
*ea
)
1450 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210c,
1451 "%s %8phC DS %d LS %d\n",
1452 __func__
, fcport
->port_name
, fcport
->disc_state
,
1453 fcport
->fw_login_state
);
1455 if (fcport
->flags
& FCF_ASYNC_SENT
)
1458 switch (fcport
->disc_state
) {
1460 case DSC_LOGIN_COMPLETE
:
1461 qla24xx_post_gpnid_work(fcport
->vha
, &ea
->id
);
1468 int qla24xx_post_newsess_work(struct scsi_qla_host
*vha
, port_id_t
*id
,
1469 u8
*port_name
, u8
*node_name
, void *pla
, u8 fc4_type
)
1471 struct qla_work_evt
*e
;
1472 e
= qla2x00_alloc_work(vha
, QLA_EVT_NEW_SESS
);
1474 return QLA_FUNCTION_FAILED
;
1476 e
->u
.new_sess
.id
= *id
;
1477 e
->u
.new_sess
.pla
= pla
;
1478 e
->u
.new_sess
.fc4_type
= fc4_type
;
1479 memcpy(e
->u
.new_sess
.port_name
, port_name
, WWN_SIZE
);
1481 memcpy(e
->u
.new_sess
.node_name
, node_name
, WWN_SIZE
);
1483 return qla2x00_post_work(vha
, e
);
1487 void qla24xx_handle_relogin_event(scsi_qla_host_t
*vha
,
1488 struct event_arg
*ea
)
1490 fc_port_t
*fcport
= ea
->fcport
;
1492 ql_dbg(ql_dbg_disc
, vha
, 0x2102,
1493 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1494 __func__
, fcport
->port_name
, fcport
->disc_state
,
1495 fcport
->fw_login_state
, fcport
->login_pause
,
1496 fcport
->deleted
, fcport
->conflict
,
1497 fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1498 fcport
->last_login_gen
, fcport
->login_gen
,
1501 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1502 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1505 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1506 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1507 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1512 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
1513 ql_dbg(ql_dbg_disc
, vha
, 0x20e9, "%s %d %8phC post gidpn\n",
1514 __func__
, __LINE__
, fcport
->port_name
);
1516 qla24xx_post_gidpn_work(vha
, fcport
);
1520 qla24xx_fcport_handle_login(vha
, fcport
);
1524 void qla_handle_els_plogi_done(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1526 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1527 "%s %d %8phC post PRLI\n",
1528 __func__
, __LINE__
, ea
->fcport
->port_name
);
1529 qla24xx_post_prli_work(vha
, ea
->fcport
);
1532 void qla2x00_fcport_event_handler(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1535 uint32_t id
= 0, mask
, rid
;
1536 unsigned long flags
;
1539 switch (ea
->event
) {
1541 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1544 qla24xx_handle_relogin_event(vha
, ea
);
1547 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1549 switch (ea
->id
.b
.rsvd_1
) {
1550 case RSCN_PORT_ADDR
:
1551 fcport
= qla2x00_find_fcport_by_nportid
1554 fcport
->rscn_rcvd
= 1;
1556 spin_lock_irqsave(&vha
->work_lock
, flags
);
1557 if (vha
->scan
.scan_flags
== 0) {
1558 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1559 "%s: schedule\n", __func__
);
1560 vha
->scan
.scan_flags
|= SF_QUEUED
;
1561 schedule_delayed_work(&vha
->scan
.scan_work
, 5);
1563 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1566 case RSCN_AREA_ADDR
:
1568 if (ea
->id
.b
.rsvd_1
== RSCN_AREA_ADDR
) {
1570 ql_dbg(ql_dbg_async
, vha
, 0x5044,
1571 "RSCN: Area 0x%06x was affected\n",
1575 ql_dbg(ql_dbg_async
, vha
, 0x507a,
1576 "RSCN: Domain 0x%06x was affected\n",
1580 rid
= ea
->id
.b24
& mask
;
1581 list_for_each_entry_safe(f
, tf
, &vha
->vp_fcports
,
1583 id
= f
->d_id
.b24
& mask
;
1586 qla24xx_handle_rscn_event(f
, ea
);
1592 ql_log(ql_log_warn
, vha
, 0xd045,
1593 "RSCN: Fabric was affected. Addr format %d\n",
1595 qla2x00_mark_all_devices_lost(vha
, 1);
1596 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1597 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1600 case FCME_GIDPN_DONE
:
1601 qla24xx_handle_gidpn_event(vha
, ea
);
1604 qla24xx_handle_gnl_done_event(vha
, ea
);
1606 case FCME_GPSC_DONE
:
1607 qla24xx_handle_gpsc_event(vha
, ea
);
1609 case FCME_PLOGI_DONE
: /* Initiator side sent LLIOCB */
1610 qla24xx_handle_plogi_done_event(vha
, ea
);
1612 case FCME_PRLI_DONE
:
1613 qla24xx_handle_prli_done_event(vha
, ea
);
1615 case FCME_GPDB_DONE
:
1616 qla24xx_handle_gpdb_event(vha
, ea
);
1618 case FCME_GPNID_DONE
:
1619 qla24xx_handle_gpnid_event(vha
, ea
);
1621 case FCME_GFFID_DONE
:
1622 qla24xx_handle_gffid_event(vha
, ea
);
1624 case FCME_ADISC_DONE
:
1625 qla24xx_handle_adisc_event(vha
, ea
);
1627 case FCME_GNNID_DONE
:
1628 qla24xx_handle_gnnid_event(vha
, ea
);
1630 case FCME_GFPNID_DONE
:
1631 qla24xx_handle_gfpnid_event(vha
, ea
);
1633 case FCME_ELS_PLOGI_DONE
:
1634 qla_handle_els_plogi_done(vha
, ea
);
1643 qla2x00_tmf_iocb_timeout(void *data
)
1646 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1648 tmf
->u
.tmf
.comp_status
= CS_TIMEOUT
;
1649 complete(&tmf
->u
.tmf
.comp
);
1653 qla2x00_tmf_sp_done(void *ptr
, int res
)
1656 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1658 complete(&tmf
->u
.tmf
.comp
);
1662 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
1665 struct scsi_qla_host
*vha
= fcport
->vha
;
1666 struct srb_iocb
*tm_iocb
;
1668 int rval
= QLA_FUNCTION_FAILED
;
1670 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1674 tm_iocb
= &sp
->u
.iocb_cmd
;
1675 sp
->type
= SRB_TM_CMD
;
1678 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
1679 init_completion(&tm_iocb
->u
.tmf
.comp
);
1680 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1682 tm_iocb
->u
.tmf
.flags
= flags
;
1683 tm_iocb
->u
.tmf
.lun
= lun
;
1684 tm_iocb
->u
.tmf
.data
= tag
;
1685 sp
->done
= qla2x00_tmf_sp_done
;
1687 rval
= qla2x00_start_sp(sp
);
1688 if (rval
!= QLA_SUCCESS
)
1691 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
1692 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1693 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1694 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1696 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
1698 rval
= tm_iocb
->u
.tmf
.data
;
1700 if (rval
!= QLA_SUCCESS
) {
1701 ql_log(ql_log_warn
, vha
, 0x8030,
1702 "TM IOCB failed (%x).\n", rval
);
1705 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
1706 flags
= tm_iocb
->u
.tmf
.flags
;
1707 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
1709 /* Issue Marker IOCB */
1710 qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
1711 vha
->hw
->rsp_q_map
[0], sp
->fcport
->loop_id
, lun
,
1712 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
1717 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1723 qla24xx_abort_iocb_timeout(void *data
)
1726 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1728 abt
->u
.abt
.comp_status
= CS_TIMEOUT
;
1729 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
1733 qla24xx_abort_sp_done(void *ptr
, int res
)
1736 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1738 if (del_timer(&sp
->u
.iocb_cmd
.timer
)) {
1739 if (sp
->flags
& SRB_WAKEUP_ON_COMP
)
1740 complete(&abt
->u
.abt
.comp
);
1747 qla24xx_async_abort_cmd(srb_t
*cmd_sp
, bool wait
)
1749 scsi_qla_host_t
*vha
= cmd_sp
->vha
;
1750 fc_port_t
*fcport
= cmd_sp
->fcport
;
1751 struct srb_iocb
*abt_iocb
;
1753 int rval
= QLA_FUNCTION_FAILED
;
1755 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1759 abt_iocb
= &sp
->u
.iocb_cmd
;
1760 sp
->type
= SRB_ABT_CMD
;
1763 sp
->flags
= SRB_WAKEUP_ON_COMP
;
1765 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
1766 init_completion(&abt_iocb
->u
.abt
.comp
);
1767 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1769 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
1771 if (vha
->flags
.qpairs_available
&& cmd_sp
->qpair
)
1772 abt_iocb
->u
.abt
.req_que_no
=
1773 cpu_to_le16(cmd_sp
->qpair
->req
->id
);
1775 abt_iocb
->u
.abt
.req_que_no
= cpu_to_le16(vha
->req
->id
);
1777 sp
->done
= qla24xx_abort_sp_done
;
1779 rval
= qla2x00_start_sp(sp
);
1780 if (rval
!= QLA_SUCCESS
)
1783 ql_dbg(ql_dbg_async
, vha
, 0x507c,
1784 "Abort command issued - hdl=%x, target_id=%x\n",
1785 cmd_sp
->handle
, fcport
->tgt_id
);
1788 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
1789 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
1790 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1800 qla24xx_async_abort_command(srb_t
*sp
)
1802 unsigned long flags
= 0;
1805 fc_port_t
*fcport
= sp
->fcport
;
1806 struct scsi_qla_host
*vha
= fcport
->vha
;
1807 struct qla_hw_data
*ha
= vha
->hw
;
1808 struct req_que
*req
= vha
->req
;
1810 if (vha
->flags
.qpairs_available
&& sp
->qpair
)
1811 req
= sp
->qpair
->req
;
1813 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1814 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
1815 if (req
->outstanding_cmds
[handle
] == sp
)
1818 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1819 if (handle
== req
->num_outstanding_cmds
) {
1820 /* Command not found. */
1821 return QLA_FUNCTION_FAILED
;
1823 if (sp
->type
== SRB_FXIOCB_DCMD
)
1824 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
1825 FXDISC_ABORT_IOCTL
);
1827 return qla24xx_async_abort_cmd(sp
, true);
1831 qla24xx_handle_prli_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1833 switch (ea
->data
[0]) {
1834 case MBS_COMMAND_COMPLETE
:
1835 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1836 "%s %d %8phC post gpdb\n",
1837 __func__
, __LINE__
, ea
->fcport
->port_name
);
1839 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1840 ea
->fcport
->logout_on_delete
= 1;
1841 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1844 if ((ea
->iop
[0] == LSC_SCODE_ELS_REJECT
) &&
1845 (ea
->iop
[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1846 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1847 ea
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
1851 if (ea
->fcport
->n2n_flag
) {
1852 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1853 "%s %d %8phC post fc4 prli\n",
1854 __func__
, __LINE__
, ea
->fcport
->port_name
);
1855 ea
->fcport
->fc4f_nvme
= 0;
1856 ea
->fcport
->n2n_flag
= 0;
1857 qla24xx_post_prli_work(vha
, ea
->fcport
);
1859 ql_dbg(ql_dbg_disc
, vha
, 0x2119,
1860 "%s %d %8phC unhandle event of %x\n",
1861 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[0]);
1867 qla24xx_handle_plogi_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1869 port_id_t cid
; /* conflict Nport id */
1871 struct fc_port
*conflict_fcport
;
1872 unsigned long flags
;
1873 struct fc_port
*fcport
= ea
->fcport
;
1875 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1876 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1877 __func__
, fcport
->port_name
, fcport
->disc_state
,
1878 fcport
->fw_login_state
, ea
->rc
, ea
->sp
->gen2
, fcport
->login_gen
,
1879 ea
->sp
->gen2
, fcport
->rscn_gen
|ea
->sp
->gen1
,
1880 ea
->data
[0], ea
->data
[1], ea
->iop
[0], ea
->iop
[1]);
1882 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1883 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)) {
1884 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1885 "%s %d %8phC Remote is trying to login\n",
1886 __func__
, __LINE__
, fcport
->port_name
);
1890 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1893 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1894 /* target side must have changed it. */
1895 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1896 "%s %8phC generation changed\n",
1897 __func__
, fcport
->port_name
);
1898 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1900 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1901 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
1902 __func__
, __LINE__
, fcport
->port_name
);
1903 qla24xx_post_gidpn_work(vha
, fcport
);
1907 switch (ea
->data
[0]) {
1908 case MBS_COMMAND_COMPLETE
:
1910 * Driver must validate login state - If PRLI not complete,
1911 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1914 if (ea
->fcport
->fc4f_nvme
) {
1915 ql_dbg(ql_dbg_disc
, vha
, 0x2117,
1916 "%s %d %8phC post prli\n",
1917 __func__
, __LINE__
, ea
->fcport
->port_name
);
1918 qla24xx_post_prli_work(vha
, ea
->fcport
);
1920 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1921 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1922 __func__
, __LINE__
, ea
->fcport
->port_name
,
1923 ea
->fcport
->loop_id
, ea
->fcport
->d_id
.b24
);
1925 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1926 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1927 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1928 ea
->fcport
->logout_on_delete
= 1;
1929 ea
->fcport
->send_els_logo
= 0;
1930 ea
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
1931 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1933 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1936 case MBS_COMMAND_ERROR
:
1937 ql_dbg(ql_dbg_disc
, vha
, 0x20eb, "%s %d %8phC cmd error %x\n",
1938 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[1]);
1940 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1941 ea
->fcport
->disc_state
= DSC_LOGIN_FAILED
;
1942 if (ea
->data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1943 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1945 qla2x00_mark_device_lost(vha
, ea
->fcport
, 1, 0);
1947 case MBS_LOOP_ID_USED
:
1948 /* data[1] = IO PARAM 1 = nport ID */
1949 cid
.b
.domain
= (ea
->iop
[1] >> 16) & 0xff;
1950 cid
.b
.area
= (ea
->iop
[1] >> 8) & 0xff;
1951 cid
.b
.al_pa
= ea
->iop
[1] & 0xff;
1954 ql_dbg(ql_dbg_disc
, vha
, 0x20ec,
1955 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1956 __func__
, __LINE__
, ea
->fcport
->port_name
,
1957 ea
->fcport
->loop_id
);
1959 if (IS_SW_RESV_ADDR(cid
)) {
1960 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1961 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1963 qla2x00_clear_loop_id(ea
->fcport
);
1965 qla24xx_post_gnl_work(vha
, ea
->fcport
);
1967 case MBS_PORT_ID_USED
:
1968 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1969 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1970 __func__
, __LINE__
, ea
->fcport
->port_name
,
1971 ea
->fcport
->d_id
.b
.domain
, ea
->fcport
->d_id
.b
.area
,
1972 ea
->fcport
->d_id
.b
.al_pa
);
1974 lid
= ea
->iop
[1] & 0xffff;
1975 qlt_find_sess_invalidate_other(vha
,
1976 wwn_to_u64(ea
->fcport
->port_name
),
1977 ea
->fcport
->d_id
, lid
, &conflict_fcport
);
1979 if (conflict_fcport
) {
1981 * Another fcport share the same loop_id/nport id.
1982 * Conflict fcport needs to finish cleanup before this
1983 * fcport can proceed to login.
1985 conflict_fcport
->conflict
= ea
->fcport
;
1986 ea
->fcport
->login_pause
= 1;
1988 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1989 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1990 __func__
, __LINE__
, ea
->fcport
->port_name
,
1991 ea
->fcport
->d_id
.b24
, lid
);
1992 qla2x00_clear_loop_id(ea
->fcport
);
1993 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
1995 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1996 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1997 __func__
, __LINE__
, ea
->fcport
->port_name
,
1998 ea
->fcport
->d_id
.b24
, lid
);
2000 qla2x00_clear_loop_id(ea
->fcport
);
2001 set_bit(lid
, vha
->hw
->loop_id_map
);
2002 ea
->fcport
->loop_id
= lid
;
2003 ea
->fcport
->keep_nport_handle
= 0;
2004 qlt_schedule_sess_for_deletion(ea
->fcport
);
2012 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2015 qlt_logo_completion_handler(fcport
, data
[0]);
2016 fcport
->login_gen
++;
2017 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
2022 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2025 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
2026 if (data
[0] == MBS_COMMAND_COMPLETE
) {
2027 qla2x00_update_fcport(vha
, fcport
);
2033 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
2034 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2036 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
2041 /****************************************************************************/
2042 /* QLogic ISP2x00 Hardware Support Functions. */
2043 /****************************************************************************/
2046 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
2048 int rval
= QLA_SUCCESS
;
2049 struct qla_hw_data
*ha
= vha
->hw
;
2050 uint32_t idc_major_ver
, idc_minor_ver
;
2053 qla83xx_idc_lock(vha
, 0);
2055 /* SV: TODO: Assign initialization timeout from
2056 * flash-info / other param
2058 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
2059 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
2061 /* Set our fcoe function presence */
2062 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
2063 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
2064 "Error while setting DRV-Presence.\n");
2065 rval
= QLA_FUNCTION_FAILED
;
2069 /* Decide the reset ownership */
2070 qla83xx_reset_ownership(vha
);
2073 * On first protocol driver load:
2074 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2076 * Others: Check compatibility with current IDC Major version.
2078 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
2079 if (ha
->flags
.nic_core_reset_owner
) {
2080 /* Set IDC Major version */
2081 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
2082 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
2084 /* Clearing IDC-Lock-Recovery register */
2085 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
2086 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
2088 * Clear further IDC participation if we are not compatible with
2089 * the current IDC Major Version.
2091 ql_log(ql_log_warn
, vha
, 0xb07d,
2092 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2093 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
2094 __qla83xx_clear_drv_presence(vha
);
2095 rval
= QLA_FUNCTION_FAILED
;
2098 /* Each function sets its supported Minor version. */
2099 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
2100 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
2101 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
2103 if (ha
->flags
.nic_core_reset_owner
) {
2104 memset(config
, 0, sizeof(config
));
2105 if (!qla81xx_get_port_config(vha
, config
))
2106 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
2110 rval
= qla83xx_idc_state_handler(vha
);
2113 qla83xx_idc_unlock(vha
, 0);
2119 * qla2x00_initialize_adapter
2123 * ha = adapter block pointer.
2129 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
2132 struct qla_hw_data
*ha
= vha
->hw
;
2133 struct req_que
*req
= ha
->req_q_map
[0];
2135 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
2136 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
2138 /* Clear adapter flags. */
2139 vha
->flags
.online
= 0;
2140 ha
->flags
.chip_reset_done
= 0;
2141 vha
->flags
.reset_active
= 0;
2142 ha
->flags
.pci_channel_io_perm_failure
= 0;
2143 ha
->flags
.eeh_busy
= 0;
2144 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
2145 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
2146 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
2147 vha
->device_flags
= DFLG_NO_CABLE
;
2149 vha
->flags
.management_server_logged_in
= 0;
2150 vha
->marker_needed
= 0;
2151 ha
->isp_abort_cnt
= 0;
2152 ha
->beacon_blink_led
= 0;
2154 set_bit(0, ha
->req_qid_map
);
2155 set_bit(0, ha
->rsp_qid_map
);
2157 ql_dbg(ql_dbg_init
, vha
, 0x0040,
2158 "Configuring PCI space...\n");
2159 rval
= ha
->isp_ops
->pci_config(vha
);
2161 ql_log(ql_log_warn
, vha
, 0x0044,
2162 "Unable to configure PCI space.\n");
2166 ha
->isp_ops
->reset_chip(vha
);
2168 rval
= qla2xxx_get_flash_info(vha
);
2170 ql_log(ql_log_fatal
, vha
, 0x004f,
2171 "Unable to validate FLASH data.\n");
2175 if (IS_QLA8044(ha
)) {
2176 qla8044_read_reset_template(vha
);
2178 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2179 * If DONRESET_BIT0 is set, drivers should not set dev_state
2180 * to NEED_RESET. But if NEED_RESET is set, drivers should
2181 * should honor the reset. */
2182 if (ql2xdontresethba
== 1)
2183 qla8044_set_idc_dontreset(vha
);
2186 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
2187 ql_dbg(ql_dbg_init
, vha
, 0x0061,
2188 "Configure NVRAM parameters...\n");
2190 ha
->isp_ops
->nvram_config(vha
);
2192 if (ha
->flags
.disable_serdes
) {
2193 /* Mask HBA via NVRAM settings? */
2194 ql_log(ql_log_info
, vha
, 0x0077,
2195 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
2196 return QLA_FUNCTION_FAILED
;
2199 ql_dbg(ql_dbg_init
, vha
, 0x0078,
2200 "Verifying loaded RISC code...\n");
2202 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
2203 rval
= ha
->isp_ops
->chip_diag(vha
);
2206 rval
= qla2x00_setup_chip(vha
);
2211 if (IS_QLA84XX(ha
)) {
2212 ha
->cs84xx
= qla84xx_get_chip(vha
);
2214 ql_log(ql_log_warn
, vha
, 0x00d0,
2215 "Unable to configure ISP84XX.\n");
2216 return QLA_FUNCTION_FAILED
;
2220 if (qla_ini_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
2221 rval
= qla2x00_init_rings(vha
);
2223 ha
->flags
.chip_reset_done
= 1;
2225 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
2226 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2227 rval
= qla84xx_init_chip(vha
);
2228 if (rval
!= QLA_SUCCESS
) {
2229 ql_log(ql_log_warn
, vha
, 0x00d4,
2230 "Unable to initialize ISP84XX.\n");
2231 qla84xx_put_chip(vha
);
2235 /* Load the NIC Core f/w if we are the first protocol driver. */
2236 if (IS_QLA8031(ha
)) {
2237 rval
= qla83xx_nic_core_fw_load(vha
);
2239 ql_log(ql_log_warn
, vha
, 0x0124,
2240 "Error in initializing NIC Core f/w.\n");
2243 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
2244 qla24xx_read_fcp_prio_cfg(vha
);
2246 if (IS_P3P_TYPE(ha
))
2247 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2249 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2255 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2258 * Returns 0 on success.
2261 qla2100_pci_config(scsi_qla_host_t
*vha
)
2264 unsigned long flags
;
2265 struct qla_hw_data
*ha
= vha
->hw
;
2266 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2268 pci_set_master(ha
->pdev
);
2269 pci_try_set_mwi(ha
->pdev
);
2271 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2272 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2273 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2275 pci_disable_rom(ha
->pdev
);
2277 /* Get PCI bus information. */
2278 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2279 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2280 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2286 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2289 * Returns 0 on success.
2292 qla2300_pci_config(scsi_qla_host_t
*vha
)
2295 unsigned long flags
= 0;
2297 struct qla_hw_data
*ha
= vha
->hw
;
2298 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2300 pci_set_master(ha
->pdev
);
2301 pci_try_set_mwi(ha
->pdev
);
2303 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2304 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2306 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2307 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2308 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2311 * If this is a 2300 card and not 2312, reset the
2312 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2313 * the 2310 also reports itself as a 2300 so we need to get the
2314 * fb revision level -- a 6 indicates it really is a 2300 and
2317 if (IS_QLA2300(ha
)) {
2318 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2321 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2322 for (cnt
= 0; cnt
< 30000; cnt
++) {
2323 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2329 /* Select FPM registers. */
2330 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2331 RD_REG_WORD(®
->ctrl_status
);
2333 /* Get the fb rev level */
2334 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
2336 if (ha
->fb_rev
== FPM_2300
)
2337 pci_clear_mwi(ha
->pdev
);
2339 /* Deselect FPM registers. */
2340 WRT_REG_WORD(®
->ctrl_status
, 0x0);
2341 RD_REG_WORD(®
->ctrl_status
);
2343 /* Release RISC module. */
2344 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2345 for (cnt
= 0; cnt
< 30000; cnt
++) {
2346 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
2352 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2355 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2357 pci_disable_rom(ha
->pdev
);
2359 /* Get PCI bus information. */
2360 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2361 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2362 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2368 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2371 * Returns 0 on success.
2374 qla24xx_pci_config(scsi_qla_host_t
*vha
)
2377 unsigned long flags
= 0;
2378 struct qla_hw_data
*ha
= vha
->hw
;
2379 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2381 pci_set_master(ha
->pdev
);
2382 pci_try_set_mwi(ha
->pdev
);
2384 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2385 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2386 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2387 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2389 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2391 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2392 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
2393 pcix_set_mmrbc(ha
->pdev
, 2048);
2395 /* PCIe -- adjust Maximum Read Request Size (2048). */
2396 if (pci_is_pcie(ha
->pdev
))
2397 pcie_set_readrq(ha
->pdev
, 4096);
2399 pci_disable_rom(ha
->pdev
);
2401 ha
->chip_revision
= ha
->pdev
->revision
;
2403 /* Get PCI bus information. */
2404 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2405 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
2406 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2412 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2415 * Returns 0 on success.
2418 qla25xx_pci_config(scsi_qla_host_t
*vha
)
2421 struct qla_hw_data
*ha
= vha
->hw
;
2423 pci_set_master(ha
->pdev
);
2424 pci_try_set_mwi(ha
->pdev
);
2426 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2427 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2428 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2429 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2431 /* PCIe -- adjust Maximum Read Request Size (2048). */
2432 if (pci_is_pcie(ha
->pdev
))
2433 pcie_set_readrq(ha
->pdev
, 4096);
2435 pci_disable_rom(ha
->pdev
);
2437 ha
->chip_revision
= ha
->pdev
->revision
;
2443 * qla2x00_isp_firmware() - Choose firmware image.
2446 * Returns 0 on success.
2449 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
2452 uint16_t loop_id
, topo
, sw_cap
;
2453 uint8_t domain
, area
, al_pa
;
2454 struct qla_hw_data
*ha
= vha
->hw
;
2456 /* Assume loading risc code */
2457 rval
= QLA_FUNCTION_FAILED
;
2459 if (ha
->flags
.disable_risc_code_load
) {
2460 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
2462 /* Verify checksum of loaded RISC code. */
2463 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
2464 if (rval
== QLA_SUCCESS
) {
2465 /* And, verify we are not in ROM code. */
2466 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
2467 &area
, &domain
, &topo
, &sw_cap
);
2472 ql_dbg(ql_dbg_init
, vha
, 0x007a,
2473 "**** Load RISC code ****.\n");
2479 * qla2x00_reset_chip() - Reset ISP chip.
2482 * Returns 0 on success.
2485 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
2487 unsigned long flags
= 0;
2488 struct qla_hw_data
*ha
= vha
->hw
;
2489 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2493 if (unlikely(pci_channel_offline(ha
->pdev
)))
2496 ha
->isp_ops
->disable_intrs(ha
);
2498 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2500 /* Turn off master enable */
2502 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
2503 cmd
&= ~PCI_COMMAND_MASTER
;
2504 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2506 if (!IS_QLA2100(ha
)) {
2508 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2509 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2510 for (cnt
= 0; cnt
< 30000; cnt
++) {
2511 if ((RD_REG_WORD(®
->hccr
) &
2512 HCCR_RISC_PAUSE
) != 0)
2517 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2521 /* Select FPM registers. */
2522 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2523 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2525 /* FPM Soft Reset. */
2526 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
2527 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2529 /* Toggle Fpm Reset. */
2530 if (!IS_QLA2200(ha
)) {
2531 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
2532 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2535 /* Select frame buffer registers. */
2536 WRT_REG_WORD(®
->ctrl_status
, 0x10);
2537 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2539 /* Reset frame buffer FIFOs. */
2540 if (IS_QLA2200(ha
)) {
2541 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
2542 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
2544 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
2546 /* Read back fb_cmd until zero or 3 seconds max */
2547 for (cnt
= 0; cnt
< 3000; cnt
++) {
2548 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
2554 /* Select RISC module registers. */
2555 WRT_REG_WORD(®
->ctrl_status
, 0);
2556 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2558 /* Reset RISC processor. */
2559 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2560 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2562 /* Release RISC processor. */
2563 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2564 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2567 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
2568 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
2570 /* Reset ISP chip. */
2571 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2573 /* Wait for RISC to recover from reset. */
2574 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2576 * It is necessary to for a delay here since the card doesn't
2577 * respond to PCI reads during a reset. On some architectures
2578 * this will result in an MCA.
2581 for (cnt
= 30000; cnt
; cnt
--) {
2582 if ((RD_REG_WORD(®
->ctrl_status
) &
2583 CSR_ISP_SOFT_RESET
) == 0)
2590 /* Reset RISC processor. */
2591 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2593 WRT_REG_WORD(®
->semaphore
, 0);
2595 /* Release RISC processor. */
2596 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2597 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2599 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2600 for (cnt
= 0; cnt
< 30000; cnt
++) {
2601 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
2609 /* Turn on master enable */
2610 cmd
|= PCI_COMMAND_MASTER
;
2611 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2613 /* Disable RISC pause on FPM parity error. */
2614 if (!IS_QLA2100(ha
)) {
2615 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
2616 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2619 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2623 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2626 * Returns 0 on success.
2629 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
2631 uint16_t mb
[4] = {0x1010, 0, 1, 0};
2633 if (!IS_QLA81XX(vha
->hw
))
2636 return qla81xx_write_mpi_register(vha
, mb
);
2640 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2643 * Returns 0 on success.
2646 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
2648 unsigned long flags
= 0;
2649 struct qla_hw_data
*ha
= vha
->hw
;
2650 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2653 static int abts_cnt
; /* ISP abort retry counts */
2654 int rval
= QLA_SUCCESS
;
2656 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2659 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2660 for (cnt
= 0; cnt
< 30000; cnt
++) {
2661 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
2667 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
))
2668 set_bit(DMA_SHUTDOWN_CMPL
, &ha
->fw_dump_cap_flags
);
2670 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017e,
2671 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2672 RD_REG_DWORD(®
->hccr
),
2673 RD_REG_DWORD(®
->ctrl_status
),
2674 (RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
));
2676 WRT_REG_DWORD(®
->ctrl_status
,
2677 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2678 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2682 /* Wait for firmware to complete NVRAM accesses. */
2683 RD_REG_WORD(®
->mailbox0
);
2684 for (cnt
= 10000; RD_REG_WORD(®
->mailbox0
) != 0 &&
2685 rval
== QLA_SUCCESS
; cnt
--) {
2690 rval
= QLA_FUNCTION_TIMEOUT
;
2693 if (rval
== QLA_SUCCESS
)
2694 set_bit(ISP_MBX_RDY
, &ha
->fw_dump_cap_flags
);
2696 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017f,
2697 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2698 RD_REG_DWORD(®
->hccr
),
2699 RD_REG_DWORD(®
->mailbox0
));
2701 /* Wait for soft-reset to complete. */
2702 RD_REG_DWORD(®
->ctrl_status
);
2703 for (cnt
= 0; cnt
< 60; cnt
++) {
2705 if ((RD_REG_DWORD(®
->ctrl_status
) &
2706 CSRX_ISP_SOFT_RESET
) == 0)
2711 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_ISP_SOFT_RESET
))
2712 set_bit(ISP_SOFT_RESET_CMPL
, &ha
->fw_dump_cap_flags
);
2714 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015d,
2715 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2716 RD_REG_DWORD(®
->hccr
),
2717 RD_REG_DWORD(®
->ctrl_status
));
2719 /* If required, do an MPI FW reset now */
2720 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
2721 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
2722 if (++abts_cnt
< 5) {
2723 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2724 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
2727 * We exhausted the ISP abort retries. We have to
2728 * set the board offline.
2731 vha
->flags
.online
= 0;
2736 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
2737 RD_REG_DWORD(®
->hccr
);
2739 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
2740 RD_REG_DWORD(®
->hccr
);
2742 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
2743 RD_REG_DWORD(®
->hccr
);
2745 RD_REG_WORD(®
->mailbox0
);
2746 for (cnt
= 60; RD_REG_WORD(®
->mailbox0
) != 0 &&
2747 rval
== QLA_SUCCESS
; cnt
--) {
2752 rval
= QLA_FUNCTION_TIMEOUT
;
2754 if (rval
== QLA_SUCCESS
)
2755 set_bit(RISC_RDY_AFT_RESET
, &ha
->fw_dump_cap_flags
);
2757 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015e,
2758 "Host Risc 0x%x, mailbox0 0x%x\n",
2759 RD_REG_DWORD(®
->hccr
),
2760 RD_REG_WORD(®
->mailbox0
));
2762 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2764 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015f,
2765 "Driver in %s mode\n",
2766 IS_NOPOLLING_TYPE(ha
) ? "Interrupt" : "Polling");
2768 if (IS_NOPOLLING_TYPE(ha
))
2769 ha
->isp_ops
->enable_intrs(ha
);
2775 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
2777 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2779 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2780 *data
= RD_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
);
2785 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
2787 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2789 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2790 WRT_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
, data
);
2794 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
2797 uint delta_msec
= 100;
2798 uint elapsed_msec
= 0;
2802 if (vha
->hw
->pdev
->subsystem_device
!= 0x0175 &&
2803 vha
->hw
->pdev
->subsystem_device
!= 0x0240)
2806 WRT_REG_DWORD(&vha
->hw
->iobase
->isp24
.hccr
, HCCRX_SET_RISC_PAUSE
);
2810 timeout_msec
= TIMEOUT_SEMAPHORE
;
2811 n
= timeout_msec
/ delta_msec
;
2813 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
2814 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2815 if (wd32
& RISC_SEMAPHORE
)
2818 elapsed_msec
+= delta_msec
;
2819 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2823 if (!(wd32
& RISC_SEMAPHORE
))
2826 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2829 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
2830 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
2831 n
= timeout_msec
/ delta_msec
;
2833 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2834 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2837 elapsed_msec
+= delta_msec
;
2838 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2842 if (wd32
& RISC_SEMAPHORE_FORCE
)
2843 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
2848 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
2855 * qla24xx_reset_chip() - Reset ISP24xx chip.
2858 * Returns 0 on success.
2861 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
2863 struct qla_hw_data
*ha
= vha
->hw
;
2865 if (pci_channel_offline(ha
->pdev
) &&
2866 ha
->flags
.pci_channel_io_perm_failure
) {
2870 ha
->isp_ops
->disable_intrs(ha
);
2872 qla25xx_manipulate_risc_semaphore(vha
);
2874 /* Perform RISC reset. */
2875 qla24xx_reset_risc(vha
);
2879 * qla2x00_chip_diag() - Test chip for proper operation.
2882 * Returns 0 on success.
2885 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
2888 struct qla_hw_data
*ha
= vha
->hw
;
2889 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2890 unsigned long flags
= 0;
2894 struct req_que
*req
= ha
->req_q_map
[0];
2896 /* Assume a failed state */
2897 rval
= QLA_FUNCTION_FAILED
;
2899 ql_dbg(ql_dbg_init
, vha
, 0x007b, "Testing device at %p.\n",
2900 ®
->flash_address
);
2902 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2904 /* Reset ISP chip. */
2905 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2908 * We need to have a delay here since the card will not respond while
2909 * in reset causing an MCA on some architectures.
2912 data
= qla2x00_debounce_register(®
->ctrl_status
);
2913 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
2915 data
= RD_REG_WORD(®
->ctrl_status
);
2920 goto chip_diag_failed
;
2922 ql_dbg(ql_dbg_init
, vha
, 0x007c,
2923 "Reset register cleared by chip reset.\n");
2925 /* Reset RISC processor. */
2926 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2927 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2929 /* Workaround for QLA2312 PCI parity error */
2930 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2931 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
2932 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
2934 data
= RD_MAILBOX_REG(ha
, reg
, 0);
2941 goto chip_diag_failed
;
2943 /* Check product ID of chip */
2944 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product ID of chip.\n");
2946 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
2947 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
2948 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
2949 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
2950 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
2951 mb
[3] != PROD_ID_3
) {
2952 ql_log(ql_log_warn
, vha
, 0x0062,
2953 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2954 mb
[1], mb
[2], mb
[3]);
2956 goto chip_diag_failed
;
2958 ha
->product_id
[0] = mb
[1];
2959 ha
->product_id
[1] = mb
[2];
2960 ha
->product_id
[2] = mb
[3];
2961 ha
->product_id
[3] = mb
[4];
2963 /* Adjust fw RISC transfer size */
2964 if (req
->length
> 1024)
2965 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
2967 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
2970 if (IS_QLA2200(ha
) &&
2971 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
2972 /* Limit firmware transfer size with a 2200A */
2973 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
2975 ha
->device_type
|= DT_ISP2200A
;
2976 ha
->fw_transfer_size
= 128;
2979 /* Wrap Incoming Mailboxes Test. */
2980 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2982 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
2983 rval
= qla2x00_mbx_reg_test(vha
);
2985 ql_log(ql_log_warn
, vha
, 0x0080,
2986 "Failed mailbox send register test.\n");
2988 /* Flag a successful rval */
2990 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2994 ql_log(ql_log_info
, vha
, 0x0081,
2995 "Chip diagnostics **** FAILED ****.\n");
2997 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3003 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3006 * Returns 0 on success.
3009 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
3012 struct qla_hw_data
*ha
= vha
->hw
;
3013 struct req_que
*req
= ha
->req_q_map
[0];
3015 if (IS_P3P_TYPE(ha
))
3018 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
3020 rval
= qla2x00_mbx_reg_test(vha
);
3022 ql_log(ql_log_warn
, vha
, 0x0082,
3023 "Failed mailbox send register test.\n");
3025 /* Flag a successful rval */
3033 qla2x00_alloc_offload_mem(scsi_qla_host_t
*vha
)
3038 struct qla_hw_data
*ha
= vha
->hw
;
3041 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
3042 "%s: Offload Mem is already allocated.\n",
3047 if (IS_FWI2_CAPABLE(ha
)) {
3048 /* Allocate memory for Fibre Channel Event Buffer. */
3049 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
3054 dma_free_coherent(&ha
->pdev
->dev
,
3055 FCE_SIZE
, ha
->fce
, ha
->fce_dma
);
3057 /* Allocate memory for Fibre Channel Event Buffer. */
3058 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
3061 ql_log(ql_log_warn
, vha
, 0x00be,
3062 "Unable to allocate (%d KB) for FCE.\n",
3067 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
3068 ha
->fce_mb
, &ha
->fce_bufs
);
3070 ql_log(ql_log_warn
, vha
, 0x00bf,
3071 "Unable to initialize FCE (%d).\n", rval
);
3072 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
3074 ha
->flags
.fce_enabled
= 0;
3077 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
3078 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
3080 ha
->flags
.fce_enabled
= 1;
3081 ha
->fce_dma
= tc_dma
;
3086 dma_free_coherent(&ha
->pdev
->dev
,
3087 EFT_SIZE
, ha
->eft
, ha
->eft_dma
);
3089 /* Allocate memory for Extended Trace Buffer. */
3090 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
3093 ql_log(ql_log_warn
, vha
, 0x00c1,
3094 "Unable to allocate (%d KB) for EFT.\n",
3099 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
3101 ql_log(ql_log_warn
, vha
, 0x00c2,
3102 "Unable to initialize EFT (%d).\n", rval
);
3103 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
3107 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
3108 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
3110 ha
->eft_dma
= tc_dma
;
3119 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
3121 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
3122 eft_size
, fce_size
, mq_size
;
3123 struct qla_hw_data
*ha
= vha
->hw
;
3124 struct req_que
*req
= ha
->req_q_map
[0];
3125 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3126 struct qla2xxx_fw_dump
*fw_dump
;
3128 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
3129 req_q_size
= rsp_q_size
= 0;
3131 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3132 fixed_size
= sizeof(struct qla2100_fw_dump
);
3133 } else if (IS_QLA23XX(ha
)) {
3134 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
3135 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
3137 } else if (IS_FWI2_CAPABLE(ha
)) {
3138 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))
3139 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
3140 else if (IS_QLA81XX(ha
))
3141 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
3142 else if (IS_QLA25XX(ha
))
3143 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
3145 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
3147 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
3150 if (!IS_QLA83XX(ha
) && !IS_QLA27XX(ha
))
3151 mq_size
= sizeof(struct qla2xxx_mq_chain
);
3153 * Allocate maximum buffer size for all queues.
3154 * Resizing must be done at end-of-dump processing.
3156 mq_size
+= ha
->max_req_queues
*
3157 (req
->length
* sizeof(request_t
));
3158 mq_size
+= ha
->max_rsp_queues
*
3159 (rsp
->length
* sizeof(response_t
));
3161 if (ha
->tgt
.atio_ring
)
3162 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
3163 /* Allocate memory for Fibre Channel Event Buffer. */
3164 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
3168 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
3170 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
3171 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
3172 eft_size
= EFT_SIZE
;
3175 if (IS_QLA27XX(ha
)) {
3176 if (!ha
->fw_dump_template
) {
3177 ql_log(ql_log_warn
, vha
, 0x00ba,
3178 "Failed missing fwdump template\n");
3181 dump_size
= qla27xx_fwdt_calculate_dump_size(vha
);
3182 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
3183 "-> allocating fwdump (%x bytes)...\n", dump_size
);
3187 req_q_size
= req
->length
* sizeof(request_t
);
3188 rsp_q_size
= rsp
->length
* sizeof(response_t
);
3189 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
3190 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
3191 ha
->chain_offset
= dump_size
;
3192 dump_size
+= mq_size
+ fce_size
;
3194 if (ha
->exchoffld_buf
)
3195 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3197 if (ha
->exlogin_buf
)
3198 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3202 if (!ha
->fw_dump_len
|| dump_size
!= ha
->fw_dump_len
) {
3203 fw_dump
= vmalloc(dump_size
);
3205 ql_log(ql_log_warn
, vha
, 0x00c4,
3206 "Unable to allocate (%d KB) for firmware dump.\n",
3211 ha
->fw_dump
= fw_dump
;
3213 ha
->fw_dump_len
= dump_size
;
3214 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3215 "Allocated (%d KB) for firmware dump.\n",
3221 ha
->fw_dump
->signature
[0] = 'Q';
3222 ha
->fw_dump
->signature
[1] = 'L';
3223 ha
->fw_dump
->signature
[2] = 'G';
3224 ha
->fw_dump
->signature
[3] = 'C';
3225 ha
->fw_dump
->version
= htonl(1);
3227 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
3228 ha
->fw_dump
->mem_size
= htonl(mem_size
);
3229 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
3230 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
3232 ha
->fw_dump
->eft_size
= htonl(eft_size
);
3233 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
3234 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
3236 ha
->fw_dump
->header_size
=
3237 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
3243 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
3245 #define MPS_MASK 0xe0
3250 if (!IS_QLA81XX(vha
->hw
))
3253 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
3254 if (rval
!= QLA_SUCCESS
) {
3255 ql_log(ql_log_warn
, vha
, 0x0105,
3256 "Unable to acquire semaphore.\n");
3260 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
3261 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
3262 if (rval
!= QLA_SUCCESS
) {
3263 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
3268 if (dc
== (dw
& MPS_MASK
))
3273 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
3274 if (rval
!= QLA_SUCCESS
) {
3275 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
3279 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
3280 if (rval
!= QLA_SUCCESS
) {
3281 ql_log(ql_log_warn
, vha
, 0x006d,
3282 "Unable to release semaphore.\n");
3290 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
3292 /* Don't try to reallocate the array */
3293 if (req
->outstanding_cmds
)
3296 if (!IS_FWI2_CAPABLE(ha
))
3297 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
3299 if (ha
->cur_fw_xcb_count
<= ha
->cur_fw_iocb_count
)
3300 req
->num_outstanding_cmds
= ha
->cur_fw_xcb_count
;
3302 req
->num_outstanding_cmds
= ha
->cur_fw_iocb_count
;
3305 req
->outstanding_cmds
= kcalloc(req
->num_outstanding_cmds
,
3309 if (!req
->outstanding_cmds
) {
3311 * Try to allocate a minimal size just so we can get through
3314 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
3315 req
->outstanding_cmds
= kcalloc(req
->num_outstanding_cmds
,
3319 if (!req
->outstanding_cmds
) {
3320 ql_log(ql_log_fatal
, NULL
, 0x0126,
3321 "Failed to allocate memory for "
3322 "outstanding_cmds for req_que %p.\n", req
);
3323 req
->num_outstanding_cmds
= 0;
3324 return QLA_FUNCTION_FAILED
;
3331 #define PRINT_FIELD(_field, _flag, _str) { \
3332 if (a0->_field & _flag) {\
3338 len = snprintf(ptr, leftover, "%s", _str); \
3345 static void qla2xxx_print_sfp_info(struct scsi_qla_host
*vha
)
3348 struct sff_8247_a0
*a0
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3349 u8 str
[STR_LEN
], *ptr
, p
;
3352 memset(str
, 0, STR_LEN
);
3353 snprintf(str
, SFF_VEN_NAME_LEN
+1, a0
->vendor_name
);
3354 ql_dbg(ql_dbg_init
, vha
, 0x015a,
3355 "SFP MFG Name: %s\n", str
);
3357 memset(str
, 0, STR_LEN
);
3358 snprintf(str
, SFF_PART_NAME_LEN
+1, a0
->vendor_pn
);
3359 ql_dbg(ql_dbg_init
, vha
, 0x015c,
3360 "SFP Part Name: %s\n", str
);
3363 memset(str
, 0, STR_LEN
);
3367 PRINT_FIELD(fc_med_cc9
, FC_MED_TW
, "Twin AX");
3368 PRINT_FIELD(fc_med_cc9
, FC_MED_TP
, "Twisted Pair");
3369 PRINT_FIELD(fc_med_cc9
, FC_MED_MI
, "Min Coax");
3370 PRINT_FIELD(fc_med_cc9
, FC_MED_TV
, "Video Coax");
3371 PRINT_FIELD(fc_med_cc9
, FC_MED_M6
, "MultiMode 62.5um");
3372 PRINT_FIELD(fc_med_cc9
, FC_MED_M5
, "MultiMode 50um");
3373 PRINT_FIELD(fc_med_cc9
, FC_MED_SM
, "SingleMode");
3374 ql_dbg(ql_dbg_init
, vha
, 0x0160,
3375 "SFP Media: %s\n", str
);
3378 memset(str
, 0, STR_LEN
);
3382 PRINT_FIELD(fc_ll_cc7
, FC_LL_VL
, "Very Long");
3383 PRINT_FIELD(fc_ll_cc7
, FC_LL_S
, "Short");
3384 PRINT_FIELD(fc_ll_cc7
, FC_LL_I
, "Intermediate");
3385 PRINT_FIELD(fc_ll_cc7
, FC_LL_L
, "Long");
3386 PRINT_FIELD(fc_ll_cc7
, FC_LL_M
, "Medium");
3387 ql_dbg(ql_dbg_init
, vha
, 0x0196,
3388 "SFP Link Length: %s\n", str
);
3390 memset(str
, 0, STR_LEN
);
3394 PRINT_FIELD(fc_ll_cc7
, FC_LL_SA
, "Short Wave (SA)");
3395 PRINT_FIELD(fc_ll_cc7
, FC_LL_LC
, "Long Wave(LC)");
3396 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SN
, "Short Wave (SN)");
3397 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SL
, "Short Wave (SL)");
3398 PRINT_FIELD(fc_tec_cc8
, FC_TEC_LL
, "Long Wave (LL)");
3399 ql_dbg(ql_dbg_init
, vha
, 0x016e,
3400 "SFP FC Link Tech: %s\n", str
);
3403 ql_dbg(ql_dbg_init
, vha
, 0x016f,
3404 "SFP Distant: %d km\n", a0
->length_km
);
3405 if (a0
->length_100m
)
3406 ql_dbg(ql_dbg_init
, vha
, 0x0170,
3407 "SFP Distant: %d m\n", a0
->length_100m
*100);
3408 if (a0
->length_50um_10m
)
3409 ql_dbg(ql_dbg_init
, vha
, 0x0189,
3410 "SFP Distant (WL=50um): %d m\n", a0
->length_50um_10m
* 10);
3411 if (a0
->length_62um_10m
)
3412 ql_dbg(ql_dbg_init
, vha
, 0x018a,
3413 "SFP Distant (WL=62.5um): %d m\n", a0
->length_62um_10m
* 10);
3414 if (a0
->length_om4_10m
)
3415 ql_dbg(ql_dbg_init
, vha
, 0x0194,
3416 "SFP Distant (OM4): %d m\n", a0
->length_om4_10m
* 10);
3417 if (a0
->length_om3_10m
)
3418 ql_dbg(ql_dbg_init
, vha
, 0x0195,
3419 "SFP Distant (OM3): %d m\n", a0
->length_om3_10m
* 10);
3425 * QLA_SUCCESS: no action
3426 * QLA_INTERFACE_ERROR: SFP is not there.
3427 * QLA_FUNCTION_FAILED: detected New SFP
3430 qla24xx_detect_sfp(scsi_qla_host_t
*vha
)
3432 int rc
= QLA_SUCCESS
;
3433 struct sff_8247_a0
*a
;
3434 struct qla_hw_data
*ha
= vha
->hw
;
3436 if (!AUTO_DETECT_SFP_SUPPORT(vha
))
3439 rc
= qla2x00_read_sfp_dev(vha
, NULL
, 0);
3443 a
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3444 qla2xxx_print_sfp_info(vha
);
3446 if (a
->fc_ll_cc7
& FC_LL_VL
|| a
->fc_ll_cc7
& FC_LL_L
) {
3448 ha
->flags
.detected_lr_sfp
= 1;
3450 if (a
->length_km
> 5 || a
->length_100m
> 50)
3451 ha
->long_range_distance
= LR_DISTANCE_10K
;
3453 ha
->long_range_distance
= LR_DISTANCE_5K
;
3455 if (ha
->flags
.detected_lr_sfp
!= ha
->flags
.using_lr_setting
)
3456 ql_dbg(ql_dbg_async
, vha
, 0x507b,
3457 "Detected Long Range SFP.\n");
3460 ha
->flags
.detected_lr_sfp
= 0;
3461 if (ha
->flags
.using_lr_setting
)
3462 ql_dbg(ql_dbg_async
, vha
, 0x5084,
3463 "Detected Short Range SFP.\n");
3466 if (!vha
->flags
.init_done
)
3473 * qla2x00_setup_chip() - Load and start RISC firmware.
3476 * Returns 0 on success.
3479 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
3482 uint32_t srisc_address
= 0;
3483 struct qla_hw_data
*ha
= vha
->hw
;
3484 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3485 unsigned long flags
;
3486 uint16_t fw_major_version
;
3488 if (IS_P3P_TYPE(ha
)) {
3489 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3490 if (rval
== QLA_SUCCESS
) {
3491 qla2x00_stop_firmware(vha
);
3492 goto enable_82xx_npiv
;
3497 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3498 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3499 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3500 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3501 RD_REG_WORD(®
->hccr
);
3502 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3505 qla81xx_mpi_sync(vha
);
3507 /* Load firmware sequences */
3508 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3509 if (rval
== QLA_SUCCESS
) {
3510 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
3511 "Verifying Checksum of loaded RISC code.\n");
3513 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
3514 if (rval
== QLA_SUCCESS
) {
3515 /* Start firmware execution. */
3516 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3517 "Starting firmware.\n");
3520 ha
->flags
.exlogins_enabled
= 1;
3522 if (qla_is_exch_offld_enabled(vha
))
3523 ha
->flags
.exchoffld_enabled
= 1;
3525 rval
= qla2x00_execute_fw(vha
, srisc_address
);
3526 /* Retrieve firmware information. */
3527 if (rval
== QLA_SUCCESS
) {
3528 qla24xx_detect_sfp(vha
);
3530 rval
= qla2x00_set_exlogins_buffer(vha
);
3531 if (rval
!= QLA_SUCCESS
)
3534 rval
= qla2x00_set_exchoffld_buffer(vha
);
3535 if (rval
!= QLA_SUCCESS
)
3539 fw_major_version
= ha
->fw_major_version
;
3540 if (IS_P3P_TYPE(ha
))
3541 qla82xx_check_md_needed(vha
);
3543 rval
= qla2x00_get_fw_version(vha
);
3544 if (rval
!= QLA_SUCCESS
)
3546 ha
->flags
.npiv_supported
= 0;
3547 if (IS_QLA2XXX_MIDTYPE(ha
) &&
3548 (ha
->fw_attributes
& BIT_2
)) {
3549 ha
->flags
.npiv_supported
= 1;
3550 if ((!ha
->max_npiv_vports
) ||
3551 ((ha
->max_npiv_vports
+ 1) %
3552 MIN_MULTI_ID_FABRIC
))
3553 ha
->max_npiv_vports
=
3554 MIN_MULTI_ID_FABRIC
- 1;
3556 qla2x00_get_resource_cnts(vha
);
3559 * Allocate the array of outstanding commands
3560 * now that we know the firmware resources.
3562 rval
= qla2x00_alloc_outstanding_cmds(ha
,
3564 if (rval
!= QLA_SUCCESS
)
3567 if (!fw_major_version
&& !(IS_P3P_TYPE(ha
)))
3568 qla2x00_alloc_offload_mem(vha
);
3570 if (ql2xallocfwdump
&& !(IS_P3P_TYPE(ha
)))
3571 qla2x00_alloc_fw_dump(vha
);
3577 ql_log(ql_log_fatal
, vha
, 0x00cd,
3578 "ISP Firmware failed checksum.\n");
3584 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3585 /* Enable proper parity. */
3586 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3589 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
3591 /* SRAM, Instruction RAM and GP RAM parity */
3592 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
3593 RD_REG_WORD(®
->hccr
);
3594 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3598 ha
->flags
.fac_supported
= 1;
3599 else if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
3602 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
3603 if (rval
== QLA_SUCCESS
) {
3604 ha
->flags
.fac_supported
= 1;
3605 ha
->fdt_block_size
= size
<< 2;
3607 ql_log(ql_log_warn
, vha
, 0x00ce,
3608 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3609 ha
->fw_major_version
, ha
->fw_minor_version
,
3610 ha
->fw_subminor_version
);
3612 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3613 ha
->flags
.fac_supported
= 0;
3620 ql_log(ql_log_fatal
, vha
, 0x00cf,
3621 "Setup chip ****FAILED****.\n");
3628 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3629 * @rsp: response queue
3631 * Beginning of request ring has initialization control block already built
3632 * by nvram config routine.
3634 * Returns 0 on success.
3637 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
3642 rsp
->ring_ptr
= rsp
->ring
;
3643 rsp
->ring_index
= 0;
3644 rsp
->status_srb
= NULL
;
3645 pkt
= rsp
->ring_ptr
;
3646 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
3647 pkt
->signature
= RESPONSE_PROCESSED
;
3653 * qla2x00_update_fw_options() - Read and process firmware options.
3656 * Returns 0 on success.
3659 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
3661 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
3662 struct qla_hw_data
*ha
= vha
->hw
;
3664 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
3665 qla2x00_get_fw_options(vha
, ha
->fw_options
);
3667 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3670 /* Serial Link options. */
3671 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
3672 "Serial link options.\n");
3673 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
3674 (uint8_t *)&ha
->fw_seriallink_options
,
3675 sizeof(ha
->fw_seriallink_options
));
3677 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
3678 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
3679 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
3682 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
3683 emphasis
= (ha
->fw_seriallink_options
[2] &
3684 (BIT_4
| BIT_3
)) >> 3;
3685 tx_sens
= ha
->fw_seriallink_options
[0] &
3686 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3687 rx_sens
= (ha
->fw_seriallink_options
[0] &
3688 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3689 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
3690 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3693 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
3694 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3695 ha
->fw_options
[10] |= BIT_5
|
3696 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3697 (tx_sens
& (BIT_1
| BIT_0
));
3700 swing
= (ha
->fw_seriallink_options
[2] &
3701 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
3702 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
3703 tx_sens
= ha
->fw_seriallink_options
[1] &
3704 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3705 rx_sens
= (ha
->fw_seriallink_options
[1] &
3706 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3707 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
3708 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3711 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
3712 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3713 ha
->fw_options
[11] |= BIT_5
|
3714 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3715 (tx_sens
& (BIT_1
| BIT_0
));
3719 /* Return command IOCBs without waiting for an ABTS to complete. */
3720 ha
->fw_options
[3] |= BIT_13
;
3723 if (ha
->flags
.enable_led_scheme
)
3724 ha
->fw_options
[2] |= BIT_12
;
3726 /* Detect ISP6312. */
3728 ha
->fw_options
[2] |= BIT_13
;
3730 /* Set Retry FLOGI in case of P2P connection */
3731 if (ha
->operating_mode
== P2P
) {
3732 ha
->fw_options
[2] |= BIT_3
;
3733 ql_dbg(ql_dbg_disc
, vha
, 0x2100,
3734 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3735 __func__
, ha
->fw_options
[2]);
3738 /* Update firmware options. */
3739 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3743 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
3746 struct qla_hw_data
*ha
= vha
->hw
;
3748 if (IS_P3P_TYPE(ha
))
3751 /* Hold status IOCBs until ABTS response received. */
3753 ha
->fw_options
[3] |= BIT_12
;
3755 /* Set Retry FLOGI in case of P2P connection */
3756 if (ha
->operating_mode
== P2P
) {
3757 ha
->fw_options
[2] |= BIT_3
;
3758 ql_dbg(ql_dbg_disc
, vha
, 0x2101,
3759 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3760 __func__
, ha
->fw_options
[2]);
3763 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3764 if (ql2xmvasynctoatio
&&
3765 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))) {
3766 if (qla_tgt_mode_enabled(vha
) ||
3767 qla_dual_mode_enabled(vha
))
3768 ha
->fw_options
[2] |= BIT_11
;
3770 ha
->fw_options
[2] &= ~BIT_11
;
3773 if (IS_QLA25XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3775 * Tell FW to track each exchange to prevent
3776 * driver from using stale exchange.
3778 if (qla_tgt_mode_enabled(vha
) ||
3779 qla_dual_mode_enabled(vha
))
3780 ha
->fw_options
[2] |= BIT_4
;
3782 ha
->fw_options
[2] &= ~BIT_4
;
3784 /* Reserve 1/2 of emergency exchanges for ELS.*/
3785 if (qla2xuseresexchforels
)
3786 ha
->fw_options
[2] |= BIT_8
;
3788 ha
->fw_options
[2] &= ~BIT_8
;
3791 ql_dbg(ql_dbg_init
, vha
, 0x00e8,
3792 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3793 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
3794 ha
->fw_options
[3], vha
->host
->active_mode
);
3796 if (ha
->fw_options
[1] || ha
->fw_options
[2] || ha
->fw_options
[3])
3797 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3799 /* Update Serial Link options. */
3800 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
3803 rval
= qla2x00_set_serdes_params(vha
,
3804 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
3805 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
3806 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
3807 if (rval
!= QLA_SUCCESS
) {
3808 ql_log(ql_log_warn
, vha
, 0x0104,
3809 "Unable to update Serial Link options (%x).\n", rval
);
3814 qla2x00_config_rings(struct scsi_qla_host
*vha
)
3816 struct qla_hw_data
*ha
= vha
->hw
;
3817 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3818 struct req_que
*req
= ha
->req_q_map
[0];
3819 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3821 /* Setup ring parameters in initialization control block. */
3822 ha
->init_cb
->request_q_outpointer
= cpu_to_le16(0);
3823 ha
->init_cb
->response_q_inpointer
= cpu_to_le16(0);
3824 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
3825 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
3826 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3827 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3828 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3829 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3831 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
3832 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
3833 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
3834 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
3835 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
3839 qla24xx_config_rings(struct scsi_qla_host
*vha
)
3841 struct qla_hw_data
*ha
= vha
->hw
;
3842 device_reg_t
*reg
= ISP_QUE_REG(ha
, 0);
3843 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
3844 struct qla_msix_entry
*msix
;
3845 struct init_cb_24xx
*icb
;
3847 struct req_que
*req
= ha
->req_q_map
[0];
3848 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3850 /* Setup ring parameters in initialization control block. */
3851 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3852 icb
->request_q_outpointer
= cpu_to_le16(0);
3853 icb
->response_q_inpointer
= cpu_to_le16(0);
3854 icb
->request_q_length
= cpu_to_le16(req
->length
);
3855 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
3856 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3857 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3858 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3859 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3861 /* Setup ATIO queue dma pointers for target mode */
3862 icb
->atio_q_inpointer
= cpu_to_le16(0);
3863 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
3864 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
3865 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
3867 if (IS_SHADOW_REG_CAPABLE(ha
))
3868 icb
->firmware_options_2
|= cpu_to_le32(BIT_30
|BIT_29
);
3870 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3871 icb
->qos
= cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
3872 icb
->rid
= cpu_to_le16(rid
);
3873 if (ha
->flags
.msix_enabled
) {
3874 msix
= &ha
->msix_entries
[1];
3875 ql_dbg(ql_dbg_init
, vha
, 0x0019,
3876 "Registering vector 0x%x for base que.\n",
3878 icb
->msix
= cpu_to_le16(msix
->entry
);
3880 /* Use alternate PCI bus number */
3882 icb
->firmware_options_2
|= cpu_to_le32(BIT_19
);
3883 /* Use alternate PCI devfn */
3885 icb
->firmware_options_2
|= cpu_to_le32(BIT_18
);
3887 /* Use Disable MSIX Handshake mode for capable adapters */
3888 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
3889 (ha
->flags
.msix_enabled
)) {
3890 icb
->firmware_options_2
&= cpu_to_le32(~BIT_22
);
3891 ha
->flags
.disable_msix_handshake
= 1;
3892 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
3893 "MSIX Handshake Disable Mode turned on.\n");
3895 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
3897 icb
->firmware_options_2
|= cpu_to_le32(BIT_23
);
3899 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
3900 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
3901 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
3902 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
3904 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
3905 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
3906 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
3907 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
3909 qlt_24xx_config_rings(vha
);
3912 RD_REG_DWORD(&ioreg
->hccr
);
3916 * qla2x00_init_rings() - Initializes firmware.
3919 * Beginning of request ring has initialization control block already built
3920 * by nvram config routine.
3922 * Returns 0 on success.
3925 qla2x00_init_rings(scsi_qla_host_t
*vha
)
3928 unsigned long flags
= 0;
3930 struct qla_hw_data
*ha
= vha
->hw
;
3931 struct req_que
*req
;
3932 struct rsp_que
*rsp
;
3933 struct mid_init_cb_24xx
*mid_init_cb
=
3934 (struct mid_init_cb_24xx
*) ha
->init_cb
;
3936 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3938 /* Clear outstanding commands array. */
3939 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
3940 req
= ha
->req_q_map
[que
];
3941 if (!req
|| !test_bit(que
, ha
->req_qid_map
))
3943 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
3945 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
3946 req
->outstanding_cmds
[cnt
] = NULL
;
3948 req
->current_outstanding_cmd
= 1;
3950 /* Initialize firmware. */
3951 req
->ring_ptr
= req
->ring
;
3952 req
->ring_index
= 0;
3953 req
->cnt
= req
->length
;
3956 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
3957 rsp
= ha
->rsp_q_map
[que
];
3958 if (!rsp
|| !test_bit(que
, ha
->rsp_qid_map
))
3960 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
3962 /* Initialize response queue entries */
3964 qlafx00_init_response_q_entries(rsp
);
3966 qla2x00_init_response_q_entries(rsp
);
3969 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
3970 ha
->tgt
.atio_ring_index
= 0;
3971 /* Initialize ATIO queue entries */
3972 qlt_init_atio_q_entries(vha
);
3974 ha
->isp_ops
->config_rings(vha
);
3976 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3978 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
3980 if (IS_QLAFX00(ha
)) {
3981 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
3985 /* Update any ISP specific firmware options before initialization. */
3986 ha
->isp_ops
->update_fw_options(vha
);
3988 if (ha
->flags
.npiv_supported
) {
3989 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
3990 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
3991 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
3994 if (IS_FWI2_CAPABLE(ha
)) {
3995 mid_init_cb
->options
= cpu_to_le16(BIT_1
);
3996 mid_init_cb
->init_cb
.execution_throttle
=
3997 cpu_to_le16(ha
->cur_fw_xcb_count
);
3998 ha
->flags
.dport_enabled
=
3999 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_7
) != 0;
4000 ql_dbg(ql_dbg_init
, vha
, 0x0191, "DPORT Support: %s.\n",
4001 (ha
->flags
.dport_enabled
) ? "enabled" : "disabled");
4002 /* FA-WWPN Status */
4003 ha
->flags
.fawwpn_enabled
=
4004 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_6
) != 0;
4005 ql_dbg(ql_dbg_init
, vha
, 0x00bc, "FA-WWPN Support: %s.\n",
4006 (ha
->flags
.fawwpn_enabled
) ? "enabled" : "disabled");
4009 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
4012 ql_log(ql_log_fatal
, vha
, 0x00d2,
4013 "Init Firmware **** FAILED ****.\n");
4015 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
4016 "Init Firmware -- success.\n");
4024 * qla2x00_fw_ready() - Waits for firmware ready.
4027 * Returns 0 on success.
4030 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
4033 unsigned long wtime
, mtime
, cs84xx_time
;
4034 uint16_t min_wait
; /* Minimum wait time if loop is down */
4035 uint16_t wait_time
; /* Wait time if loop is coming ready */
4037 struct qla_hw_data
*ha
= vha
->hw
;
4039 if (IS_QLAFX00(vha
->hw
))
4040 return qlafx00_fw_ready(vha
);
4044 /* Time to wait for loop down */
4045 if (IS_P3P_TYPE(ha
))
4051 * Firmware should take at most one RATOV to login, plus 5 seconds for
4052 * our own processing.
4054 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
4055 wait_time
= min_wait
;
4058 /* Min wait time if loop down */
4059 mtime
= jiffies
+ (min_wait
* HZ
);
4061 /* wait time before firmware ready */
4062 wtime
= jiffies
+ (wait_time
* HZ
);
4064 /* Wait for ISP to finish LIP */
4065 if (!vha
->flags
.init_done
)
4066 ql_log(ql_log_info
, vha
, 0x801e,
4067 "Waiting for LIP to complete.\n");
4070 memset(state
, -1, sizeof(state
));
4071 rval
= qla2x00_get_firmware_state(vha
, state
);
4072 if (rval
== QLA_SUCCESS
) {
4073 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
4074 vha
->device_flags
&= ~DFLG_NO_CABLE
;
4076 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
4077 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
4078 "fw_state=%x 84xx=%x.\n", state
[0],
4080 if ((state
[2] & FSTATE_LOGGED_IN
) &&
4081 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
4082 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
4083 "Sending verify iocb.\n");
4085 cs84xx_time
= jiffies
;
4086 rval
= qla84xx_init_chip(vha
);
4087 if (rval
!= QLA_SUCCESS
) {
4090 "Init chip failed.\n");
4094 /* Add time taken to initialize. */
4095 cs84xx_time
= jiffies
- cs84xx_time
;
4096 wtime
+= cs84xx_time
;
4097 mtime
+= cs84xx_time
;
4098 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
4099 "Increasing wait time by %ld. "
4100 "New time %ld.\n", cs84xx_time
,
4103 } else if (state
[0] == FSTATE_READY
) {
4104 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
4105 "F/W Ready - OK.\n");
4107 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
4108 &ha
->login_timeout
, &ha
->r_a_tov
);
4114 rval
= QLA_FUNCTION_FAILED
;
4116 if (atomic_read(&vha
->loop_down_timer
) &&
4117 state
[0] != FSTATE_READY
) {
4118 /* Loop down. Timeout on min_wait for states
4119 * other than Wait for Login.
4121 if (time_after_eq(jiffies
, mtime
)) {
4122 ql_log(ql_log_info
, vha
, 0x8038,
4123 "Cable is unplugged...\n");
4125 vha
->device_flags
|= DFLG_NO_CABLE
;
4130 /* Mailbox cmd failed. Timeout on min_wait. */
4131 if (time_after_eq(jiffies
, mtime
) ||
4132 ha
->flags
.isp82xx_fw_hung
)
4136 if (time_after_eq(jiffies
, wtime
))
4139 /* Delay for a while */
4143 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
4144 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state
[0],
4145 state
[1], state
[2], state
[3], state
[4], state
[5], jiffies
);
4147 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
4148 ql_log(ql_log_warn
, vha
, 0x803b,
4149 "Firmware ready **** FAILED ****.\n");
4156 * qla2x00_configure_hba
4157 * Setup adapter context.
4160 * ha = adapter state pointer.
4169 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
4178 char connect_type
[22];
4179 struct qla_hw_data
*ha
= vha
->hw
;
4180 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4182 unsigned long flags
;
4184 /* Get host addresses. */
4185 rval
= qla2x00_get_adapter_id(vha
,
4186 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
4187 if (rval
!= QLA_SUCCESS
) {
4188 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
4189 IS_CNA_CAPABLE(ha
) ||
4190 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
4191 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
4192 "Loop is in a transition state.\n");
4194 ql_log(ql_log_warn
, vha
, 0x2009,
4195 "Unable to get host loop ID.\n");
4196 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
4197 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
4198 ql_log(ql_log_warn
, vha
, 0x1151,
4199 "Doing link init.\n");
4200 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
4203 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4209 ql_log(ql_log_info
, vha
, 0x200a,
4210 "Cannot get topology - retrying.\n");
4211 return (QLA_FUNCTION_FAILED
);
4214 vha
->loop_id
= loop_id
;
4217 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
4218 ha
->operating_mode
= LOOP
;
4223 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
4224 ha
->current_topology
= ISP_CFG_NL
;
4225 strcpy(connect_type
, "(Loop)");
4229 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
4230 ha
->switch_cap
= sw_cap
;
4231 ha
->current_topology
= ISP_CFG_FL
;
4232 strcpy(connect_type
, "(FL_Port)");
4236 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
4237 ha
->operating_mode
= P2P
;
4238 ha
->current_topology
= ISP_CFG_N
;
4239 strcpy(connect_type
, "(N_Port-to-N_Port)");
4243 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
4244 ha
->switch_cap
= sw_cap
;
4245 ha
->operating_mode
= P2P
;
4246 ha
->current_topology
= ISP_CFG_F
;
4247 strcpy(connect_type
, "(F_Port)");
4251 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
4252 "HBA in unknown topology %x, using NL.\n", topo
);
4253 ha
->current_topology
= ISP_CFG_NL
;
4254 strcpy(connect_type
, "(Loop)");
4258 /* Save Host port and loop ID. */
4259 /* byte order - Big Endian */
4260 id
.b
.domain
= domain
;
4264 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4265 if (!(topo
== 2 && ha
->flags
.n2n_bigger
))
4266 qlt_update_host_map(vha
, id
);
4267 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4269 if (!vha
->flags
.init_done
)
4270 ql_log(ql_log_info
, vha
, 0x2010,
4271 "Topology - %s, Host Loop address 0x%x.\n",
4272 connect_type
, vha
->loop_id
);
4278 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
4283 struct qla_hw_data
*ha
= vha
->hw
;
4284 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
4285 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
4287 if (memcmp(model
, BINZERO
, len
) != 0) {
4288 strncpy(ha
->model_number
, model
, len
);
4289 st
= en
= ha
->model_number
;
4292 if (*en
!= 0x20 && *en
!= 0x00)
4297 index
= (ha
->pdev
->subsystem_device
& 0xff);
4299 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4300 index
< QLA_MODEL_NAMES
)
4301 strncpy(ha
->model_desc
,
4302 qla2x00_model_name
[index
* 2 + 1],
4303 sizeof(ha
->model_desc
) - 1);
4305 index
= (ha
->pdev
->subsystem_device
& 0xff);
4307 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4308 index
< QLA_MODEL_NAMES
) {
4309 strcpy(ha
->model_number
,
4310 qla2x00_model_name
[index
* 2]);
4311 strncpy(ha
->model_desc
,
4312 qla2x00_model_name
[index
* 2 + 1],
4313 sizeof(ha
->model_desc
) - 1);
4315 strcpy(ha
->model_number
, def
);
4318 if (IS_FWI2_CAPABLE(ha
))
4319 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
4320 sizeof(ha
->model_desc
));
4323 /* On sparc systems, obtain port and node WWN from firmware
4326 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
4329 struct qla_hw_data
*ha
= vha
->hw
;
4330 struct pci_dev
*pdev
= ha
->pdev
;
4331 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4335 val
= of_get_property(dp
, "port-wwn", &len
);
4336 if (val
&& len
>= WWN_SIZE
)
4337 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4339 val
= of_get_property(dp
, "node-wwn", &len
);
4340 if (val
&& len
>= WWN_SIZE
)
4341 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4346 * NVRAM configuration for ISP 2xxx
4349 * ha = adapter block pointer.
4352 * initialization control block in response_ring
4353 * host adapters parameters in host adapter block
4359 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
4364 uint8_t *dptr1
, *dptr2
;
4365 struct qla_hw_data
*ha
= vha
->hw
;
4366 init_cb_t
*icb
= ha
->init_cb
;
4367 nvram_t
*nv
= ha
->nvram
;
4368 uint8_t *ptr
= ha
->nvram
;
4369 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4373 /* Determine NVRAM starting address. */
4374 ha
->nvram_size
= sizeof(nvram_t
);
4376 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
4377 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
4378 ha
->nvram_base
= 0x80;
4380 /* Get NVRAM data and calculate checksum. */
4381 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
4382 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
4385 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
4386 "Contents of NVRAM.\n");
4387 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
4388 (uint8_t *)nv
, ha
->nvram_size
);
4390 /* Bad NVRAM data, set defaults parameters. */
4391 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
4392 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
4393 /* Reset NVRAM data. */
4394 ql_log(ql_log_warn
, vha
, 0x0064,
4395 "Inconsistent NVRAM "
4396 "detected: checksum=0x%x id=%c version=0x%x.\n",
4397 chksum
, nv
->id
[0], nv
->nvram_version
);
4398 ql_log(ql_log_warn
, vha
, 0x0065,
4400 "functioning (yet invalid -- WWPN) defaults.\n");
4403 * Set default initialization control block.
4405 memset(nv
, 0, ha
->nvram_size
);
4406 nv
->parameter_block_version
= ICB_VERSION
;
4408 if (IS_QLA23XX(ha
)) {
4409 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4410 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4411 nv
->add_firmware_options
[0] = BIT_5
;
4412 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4413 nv
->frame_payload_size
= 2048;
4414 nv
->special_options
[1] = BIT_7
;
4415 } else if (IS_QLA2200(ha
)) {
4416 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4417 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4418 nv
->add_firmware_options
[0] = BIT_5
;
4419 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4420 nv
->frame_payload_size
= 1024;
4421 } else if (IS_QLA2100(ha
)) {
4422 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
4423 nv
->firmware_options
[1] = BIT_5
;
4424 nv
->frame_payload_size
= 1024;
4427 nv
->max_iocb_allocation
= cpu_to_le16(256);
4428 nv
->execution_throttle
= cpu_to_le16(16);
4429 nv
->retry_count
= 8;
4430 nv
->retry_delay
= 1;
4432 nv
->port_name
[0] = 33;
4433 nv
->port_name
[3] = 224;
4434 nv
->port_name
[4] = 139;
4436 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
4438 nv
->login_timeout
= 4;
4441 * Set default host adapter parameters
4443 nv
->host_p
[1] = BIT_2
;
4444 nv
->reset_delay
= 5;
4445 nv
->port_down_retry_count
= 8;
4446 nv
->max_luns_per_target
= cpu_to_le16(8);
4447 nv
->link_down_timeout
= 60;
4452 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4454 * The SN2 does not provide BIOS emulation which means you can't change
4455 * potentially bogus BIOS settings. Force the use of default settings
4456 * for link rate and frame size. Hope that the rest of the settings
4459 if (ia64_platform_is("sn2")) {
4460 nv
->frame_payload_size
= 2048;
4462 nv
->special_options
[1] = BIT_7
;
4466 /* Reset Initialization control block */
4467 memset(icb
, 0, ha
->init_cb_size
);
4470 * Setup driver NVRAM options.
4472 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
4473 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
4474 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
4475 nv
->firmware_options
[1] &= ~BIT_4
;
4477 if (IS_QLA23XX(ha
)) {
4478 nv
->firmware_options
[0] |= BIT_2
;
4479 nv
->firmware_options
[0] &= ~BIT_3
;
4480 nv
->special_options
[0] &= ~BIT_6
;
4481 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
4483 if (IS_QLA2300(ha
)) {
4484 if (ha
->fb_rev
== FPM_2310
) {
4485 strcpy(ha
->model_number
, "QLA2310");
4487 strcpy(ha
->model_number
, "QLA2300");
4490 qla2x00_set_model_info(vha
, nv
->model_number
,
4491 sizeof(nv
->model_number
), "QLA23xx");
4493 } else if (IS_QLA2200(ha
)) {
4494 nv
->firmware_options
[0] |= BIT_2
;
4496 * 'Point-to-point preferred, else loop' is not a safe
4497 * connection mode setting.
4499 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
4501 /* Force 'loop preferred, else point-to-point'. */
4502 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
4503 nv
->add_firmware_options
[0] |= BIT_5
;
4505 strcpy(ha
->model_number
, "QLA22xx");
4506 } else /*if (IS_QLA2100(ha))*/ {
4507 strcpy(ha
->model_number
, "QLA2100");
4511 * Copy over NVRAM RISC parameter block to initialization control block.
4513 dptr1
= (uint8_t *)icb
;
4514 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
4515 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
4517 *dptr1
++ = *dptr2
++;
4519 /* Copy 2nd half. */
4520 dptr1
= (uint8_t *)icb
->add_firmware_options
;
4521 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
4523 *dptr1
++ = *dptr2
++;
4524 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
4525 /* Use alternate WWN? */
4526 if (nv
->host_p
[1] & BIT_7
) {
4527 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4528 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4531 /* Prepare nodename */
4532 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
4534 * Firmware will apply the following mask if the nodename was
4537 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4538 icb
->node_name
[0] &= 0xF0;
4542 * Set host adapter parameters.
4546 * BIT_7 in the host-parameters section allows for modification to
4547 * internal driver logging.
4549 if (nv
->host_p
[0] & BIT_7
)
4550 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
4551 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
4552 /* Always load RISC code on non ISP2[12]00 chips. */
4553 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
4554 ha
->flags
.disable_risc_code_load
= 0;
4555 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
4556 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
4557 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
4558 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
4559 ha
->flags
.disable_serdes
= 0;
4561 ha
->operating_mode
=
4562 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4564 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
4565 sizeof(ha
->fw_seriallink_options
));
4567 /* save HBA serial number */
4568 ha
->serial0
= icb
->port_name
[5];
4569 ha
->serial1
= icb
->port_name
[6];
4570 ha
->serial2
= icb
->port_name
[7];
4571 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4572 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4574 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
4576 ha
->retry_count
= nv
->retry_count
;
4578 /* Set minimum login_timeout to 4 seconds. */
4579 if (nv
->login_timeout
!= ql2xlogintimeout
)
4580 nv
->login_timeout
= ql2xlogintimeout
;
4581 if (nv
->login_timeout
< 4)
4582 nv
->login_timeout
= 4;
4583 ha
->login_timeout
= nv
->login_timeout
;
4585 /* Set minimum RATOV to 100 tenths of a second. */
4588 ha
->loop_reset_delay
= nv
->reset_delay
;
4590 /* Link Down Timeout = 0:
4592 * When Port Down timer expires we will start returning
4593 * I/O's to OS with "DID_NO_CONNECT".
4595 * Link Down Timeout != 0:
4597 * The driver waits for the link to come up after link down
4598 * before returning I/Os to OS with "DID_NO_CONNECT".
4600 if (nv
->link_down_timeout
== 0) {
4601 ha
->loop_down_abort_time
=
4602 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4604 ha
->link_down_timeout
= nv
->link_down_timeout
;
4605 ha
->loop_down_abort_time
=
4606 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4610 * Need enough time to try and get the port back.
4612 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
4613 if (qlport_down_retry
)
4614 ha
->port_down_retry_count
= qlport_down_retry
;
4615 /* Set login_retry_count */
4616 ha
->login_retry_count
= nv
->retry_count
;
4617 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
4618 ha
->port_down_retry_count
> 3)
4619 ha
->login_retry_count
= ha
->port_down_retry_count
;
4620 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4621 ha
->login_retry_count
= ha
->port_down_retry_count
;
4622 if (ql2xloginretrycount
)
4623 ha
->login_retry_count
= ql2xloginretrycount
;
4625 icb
->lun_enables
= cpu_to_le16(0);
4626 icb
->command_resource_count
= 0;
4627 icb
->immediate_notify_resource_count
= 0;
4628 icb
->timeout
= cpu_to_le16(0);
4630 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
4632 icb
->firmware_options
[0] &= ~BIT_3
;
4633 icb
->add_firmware_options
[0] &=
4634 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4635 icb
->add_firmware_options
[0] |= BIT_2
;
4636 icb
->response_accumulation_timer
= 3;
4637 icb
->interrupt_delay_timer
= 5;
4639 vha
->flags
.process_response_queue
= 1;
4642 if (!vha
->flags
.init_done
) {
4643 ha
->zio_mode
= icb
->add_firmware_options
[0] &
4644 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4645 ha
->zio_timer
= icb
->interrupt_delay_timer
?
4646 icb
->interrupt_delay_timer
: 2;
4648 icb
->add_firmware_options
[0] &=
4649 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4650 vha
->flags
.process_response_queue
= 0;
4651 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4652 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4654 ql_log(ql_log_info
, vha
, 0x0068,
4655 "ZIO mode %d enabled; timer delay (%d us).\n",
4656 ha
->zio_mode
, ha
->zio_timer
* 100);
4658 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
4659 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
4660 vha
->flags
.process_response_queue
= 1;
4665 ql_log(ql_log_warn
, vha
, 0x0069,
4666 "NVRAM configuration failed.\n");
4672 qla2x00_rport_del(void *data
)
4674 fc_port_t
*fcport
= data
;
4675 struct fc_rport
*rport
;
4676 unsigned long flags
;
4678 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
4679 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
4680 fcport
->drport
= NULL
;
4681 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
4683 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210b,
4684 "%s %8phN. rport %p roles %x\n",
4685 __func__
, fcport
->port_name
, rport
,
4688 fc_remote_port_delete(rport
);
4693 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4695 * @flags: allocation flags
4697 * Returns a pointer to the allocated fcport, or NULL, if none available.
4700 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
4704 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
4708 /* Setup fcport template structure. */
4710 fcport
->port_type
= FCT_UNKNOWN
;
4711 fcport
->loop_id
= FC_NO_LOOP_ID
;
4712 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
4713 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
4715 fcport
->ct_desc
.ct_sns
= dma_alloc_coherent(&vha
->hw
->pdev
->dev
,
4716 sizeof(struct ct_sns_pkt
), &fcport
->ct_desc
.ct_sns_dma
,
4718 fcport
->disc_state
= DSC_DELETED
;
4719 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4720 fcport
->deleted
= QLA_SESS_DELETED
;
4721 fcport
->login_retry
= vha
->hw
->login_retry_count
;
4722 fcport
->logout_on_delete
= 1;
4724 if (!fcport
->ct_desc
.ct_sns
) {
4725 ql_log(ql_log_warn
, vha
, 0xd049,
4726 "Failed to allocate ct_sns request.\n");
4730 INIT_WORK(&fcport
->del_work
, qla24xx_delete_sess_fn
);
4731 INIT_LIST_HEAD(&fcport
->gnl_entry
);
4732 INIT_LIST_HEAD(&fcport
->list
);
4738 qla2x00_free_fcport(fc_port_t
*fcport
)
4740 if (fcport
->ct_desc
.ct_sns
) {
4741 dma_free_coherent(&fcport
->vha
->hw
->pdev
->dev
,
4742 sizeof(struct ct_sns_pkt
), fcport
->ct_desc
.ct_sns
,
4743 fcport
->ct_desc
.ct_sns_dma
);
4745 fcport
->ct_desc
.ct_sns
= NULL
;
4751 * qla2x00_configure_loop
4752 * Updates Fibre Channel Device Database with what is actually on loop.
4755 * ha = adapter block pointer.
4760 * 2 = database was full and device was not configured.
4763 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
4766 unsigned long flags
, save_flags
;
4767 struct qla_hw_data
*ha
= vha
->hw
;
4770 /* Get Initiator ID */
4771 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
4772 rval
= qla2x00_configure_hba(vha
);
4773 if (rval
!= QLA_SUCCESS
) {
4774 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
4775 "Unable to configure HBA.\n");
4780 save_flags
= flags
= vha
->dpc_flags
;
4781 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
4782 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
4785 * If we have both an RSCN and PORT UPDATE pending then handle them
4786 * both at the same time.
4788 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4789 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4791 qla2x00_get_data_rate(vha
);
4793 /* Determine what we need to do */
4794 if (ha
->current_topology
== ISP_CFG_FL
&&
4795 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4797 set_bit(RSCN_UPDATE
, &flags
);
4799 } else if (ha
->current_topology
== ISP_CFG_F
&&
4800 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4802 set_bit(RSCN_UPDATE
, &flags
);
4803 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4805 } else if (ha
->current_topology
== ISP_CFG_N
) {
4806 clear_bit(RSCN_UPDATE
, &flags
);
4807 if (qla_tgt_mode_enabled(vha
)) {
4808 /* allow the other side to start the login */
4809 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4810 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4812 } else if (ha
->current_topology
== ISP_CFG_NL
) {
4813 clear_bit(RSCN_UPDATE
, &flags
);
4814 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4815 } else if (!vha
->flags
.online
||
4816 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
4817 set_bit(RSCN_UPDATE
, &flags
);
4818 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4821 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
4822 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4823 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
4824 "Loop resync needed, failing.\n");
4825 rval
= QLA_FUNCTION_FAILED
;
4827 rval
= qla2x00_configure_local_loop(vha
);
4830 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
4831 if (LOOP_TRANSITION(vha
)) {
4832 ql_dbg(ql_dbg_disc
, vha
, 0x2099,
4833 "Needs RSCN update and loop transition.\n");
4834 rval
= QLA_FUNCTION_FAILED
;
4837 rval
= qla2x00_configure_fabric(vha
);
4840 if (rval
== QLA_SUCCESS
) {
4841 if (atomic_read(&vha
->loop_down_timer
) ||
4842 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4843 rval
= QLA_FUNCTION_FAILED
;
4845 atomic_set(&vha
->loop_state
, LOOP_READY
);
4846 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
4848 ha
->flags
.fw_init_done
= 1;
4851 * Process any ATIO queue entries that came in
4852 * while we weren't online.
4854 if (qla_tgt_mode_enabled(vha
) ||
4855 qla_dual_mode_enabled(vha
)) {
4856 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
)) {
4857 spin_lock_irqsave(&ha
->tgt
.atio_lock
,
4859 qlt_24xx_process_atio_queue(vha
, 0);
4860 spin_unlock_irqrestore(
4861 &ha
->tgt
.atio_lock
, flags
);
4863 spin_lock_irqsave(&ha
->hardware_lock
,
4865 qlt_24xx_process_atio_queue(vha
, 1);
4866 spin_unlock_irqrestore(
4867 &ha
->hardware_lock
, flags
);
4874 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
4875 "%s *** FAILED ***.\n", __func__
);
4877 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
4878 "%s: exiting normally.\n", __func__
);
4881 /* Restore state if a resync event occurred during processing */
4882 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4883 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
4884 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4885 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
4886 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4894 * qla2x00_configure_local_loop
4895 * Updates Fibre Channel Device Database with local loop devices.
4898 * ha = adapter block pointer.
4904 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
4909 fc_port_t
*fcport
, *new_fcport
;
4915 uint8_t domain
, area
, al_pa
;
4916 struct qla_hw_data
*ha
= vha
->hw
;
4917 unsigned long flags
;
4919 /* Inititae N2N login. */
4920 if (test_and_clear_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
)) {
4924 memset(ha
->init_cb
, 0, ha
->init_cb_size
);
4925 sz
= min_t(int, sizeof(struct els_plogi_payload
),
4927 rval
= qla24xx_get_port_login_templ(vha
, ha
->init_cb_dma
,
4928 (void *)ha
->init_cb
, sz
);
4929 if (rval
== QLA_SUCCESS
) {
4930 bp
= (uint32_t *)ha
->init_cb
;
4931 for (i
= 0; i
< sz
/4 ; i
++, bp
++)
4932 *bp
= cpu_to_be32(*bp
);
4934 memcpy(&ha
->plogi_els_payld
.data
, (void *)ha
->init_cb
,
4935 sizeof(ha
->plogi_els_payld
.data
));
4936 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4938 ql_dbg(ql_dbg_init
, vha
, 0x00d1,
4939 "PLOGI ELS param read fail.\n");
4946 entries
= MAX_FIBRE_DEVICES_LOOP
;
4948 /* Get list of logged in devices. */
4949 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
4950 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
4952 if (rval
!= QLA_SUCCESS
)
4953 goto cleanup_allocation
;
4955 ql_dbg(ql_dbg_disc
, vha
, 0x2011,
4956 "Entries in ID list (%d).\n", entries
);
4957 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
4958 (uint8_t *)ha
->gid_list
,
4959 entries
* sizeof(struct gid_list_info
));
4961 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4962 fcport
->scan_state
= QLA_FCPORT_SCAN
;
4965 /* Allocate temporary fcport for any new fcports discovered. */
4966 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4967 if (new_fcport
== NULL
) {
4968 ql_log(ql_log_warn
, vha
, 0x2012,
4969 "Memory allocation failed for fcport.\n");
4970 rval
= QLA_MEMORY_ALLOC_FAILED
;
4971 goto cleanup_allocation
;
4973 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4975 /* Add devices to port list. */
4976 id_iter
= (char *)ha
->gid_list
;
4977 for (index
= 0; index
< entries
; index
++) {
4978 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
4979 area
= ((struct gid_list_info
*)id_iter
)->area
;
4980 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
4981 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
4982 loop_id
= (uint16_t)
4983 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
4985 loop_id
= le16_to_cpu(
4986 ((struct gid_list_info
*)id_iter
)->loop_id
);
4987 id_iter
+= ha
->gid_list_info_size
;
4989 /* Bypass reserved domain fields. */
4990 if ((domain
& 0xf0) == 0xf0)
4993 /* Bypass if not same domain and area of adapter. */
4994 if (area
&& domain
&&
4995 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
4998 /* Bypass invalid local loop ID. */
4999 if (loop_id
> LAST_LOCAL_LOOP_ID
)
5002 memset(new_fcport
->port_name
, 0, WWN_SIZE
);
5004 /* Fill in member data. */
5005 new_fcport
->d_id
.b
.domain
= domain
;
5006 new_fcport
->d_id
.b
.area
= area
;
5007 new_fcport
->d_id
.b
.al_pa
= al_pa
;
5008 new_fcport
->loop_id
= loop_id
;
5009 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5011 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
5012 if (rval2
!= QLA_SUCCESS
) {
5013 ql_dbg(ql_dbg_disc
, vha
, 0x2097,
5014 "Failed to retrieve fcport information "
5015 "-- get_port_database=%x, loop_id=0x%04x.\n",
5016 rval2
, new_fcport
->loop_id
);
5017 /* Skip retry if N2N */
5018 if (ha
->current_topology
!= ISP_CFG_N
) {
5019 ql_dbg(ql_dbg_disc
, vha
, 0x2105,
5020 "Scheduling resync.\n");
5021 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5026 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5027 /* Check for matching device in port list. */
5030 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5031 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5035 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5036 fcport
->loop_id
= new_fcport
->loop_id
;
5037 fcport
->port_type
= new_fcport
->port_type
;
5038 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5039 memcpy(fcport
->node_name
, new_fcport
->node_name
,
5041 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5047 /* New device, add to fcports list. */
5048 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5050 /* Allocate a new replacement fcport. */
5051 fcport
= new_fcport
;
5053 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5055 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5057 if (new_fcport
== NULL
) {
5058 ql_log(ql_log_warn
, vha
, 0xd031,
5059 "Failed to allocate memory for fcport.\n");
5060 rval
= QLA_MEMORY_ALLOC_FAILED
;
5061 goto cleanup_allocation
;
5063 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5064 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5067 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5069 /* Base iIDMA settings on HBA port speed. */
5070 fcport
->fp_speed
= ha
->link_data_rate
;
5075 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5076 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5079 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5080 if ((qla_dual_mode_enabled(vha
) ||
5081 qla_ini_mode_enabled(vha
)) &&
5082 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5083 qla2x00_mark_device_lost(vha
, fcport
,
5084 ql2xplogiabsentdevice
, 0);
5085 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5086 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5087 fcport
->port_type
!= FCT_INITIATOR
&&
5088 fcport
->port_type
!= FCT_BROADCAST
) {
5089 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5090 "%s %d %8phC post del sess\n",
5094 qlt_schedule_sess_for_deletion(fcport
);
5100 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5101 qla24xx_fcport_handle_login(vha
, fcport
);
5107 if (rval
!= QLA_SUCCESS
) {
5108 ql_dbg(ql_dbg_disc
, vha
, 0x2098,
5109 "Configure local loop error exit: rval=%x.\n", rval
);
5116 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5119 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5120 struct qla_hw_data
*ha
= vha
->hw
;
5122 if (!IS_IIDMA_CAPABLE(ha
))
5125 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
5128 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
5129 fcport
->fp_speed
> ha
->link_data_rate
||
5130 !ha
->flags
.gpsc_supported
)
5133 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
5135 if (rval
!= QLA_SUCCESS
) {
5136 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
5137 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5138 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
5140 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
5141 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5142 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
5143 fcport
->fp_speed
, fcport
->port_name
);
5147 void qla_do_iidma_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
5149 qla2x00_iidma_fcport(vha
, fcport
);
5150 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5153 int qla_post_iidma_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
5155 struct qla_work_evt
*e
;
5157 e
= qla2x00_alloc_work(vha
, QLA_EVT_IIDMA
);
5159 return QLA_FUNCTION_FAILED
;
5161 e
->u
.fcport
.fcport
= fcport
;
5162 return qla2x00_post_work(vha
, e
);
5165 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5167 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5169 struct fc_rport_identifiers rport_ids
;
5170 struct fc_rport
*rport
;
5171 unsigned long flags
;
5173 if (atomic_read(&fcport
->state
) == FCS_ONLINE
)
5176 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
5177 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
5178 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
5179 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
5180 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5181 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
5183 ql_log(ql_log_warn
, vha
, 0x2006,
5184 "Unable to allocate fc remote port.\n");
5188 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
5189 *((fc_port_t
**)rport
->dd_data
) = fcport
;
5190 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
5192 rport
->supported_classes
= fcport
->supported_classes
;
5194 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5195 if (fcport
->port_type
== FCT_INITIATOR
)
5196 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
5197 if (fcport
->port_type
== FCT_TARGET
)
5198 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
5200 ql_dbg(ql_dbg_disc
, vha
, 0x20ee,
5201 "%s %8phN. rport %p is %s mode\n",
5202 __func__
, fcport
->port_name
, rport
,
5203 (fcport
->port_type
== FCT_TARGET
) ? "tgt" : "ini");
5205 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
5209 * qla2x00_update_fcport
5210 * Updates device on list.
5213 * ha = adapter block pointer.
5214 * fcport = port structure pointer.
5224 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5228 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5231 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
5232 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5233 fcport
->deleted
= 0;
5234 fcport
->logout_on_delete
= 1;
5235 fcport
->login_retry
= vha
->hw
->login_retry_count
;
5236 fcport
->n2n_chip_reset
= fcport
->n2n_link_reset_cnt
= 0;
5238 qla2x00_iidma_fcport(vha
, fcport
);
5240 switch (vha
->hw
->current_topology
) {
5243 fcport
->keep_nport_handle
= 1;
5249 if (fcport
->fc4f_nvme
) {
5250 qla_nvme_register_remote(vha
, fcport
);
5251 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5252 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5256 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5258 switch (vha
->host
->active_mode
) {
5259 case MODE_INITIATOR
:
5260 qla2x00_reg_remote_port(vha
, fcport
);
5263 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5264 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5265 qlt_fc_port_added(vha
, fcport
);
5268 qla2x00_reg_remote_port(vha
, fcport
);
5269 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5270 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5271 qlt_fc_port_added(vha
, fcport
);
5277 if (IS_IIDMA_CAPABLE(vha
->hw
) && vha
->hw
->flags
.gpsc_supported
) {
5278 if (fcport
->id_changed
) {
5279 fcport
->id_changed
= 0;
5280 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
5281 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5282 __func__
, __LINE__
, fcport
->port_name
,
5284 qla24xx_post_gfpnid_work(vha
, fcport
);
5286 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
5287 "%s %d %8phC post gpsc fcp_cnt %d\n",
5288 __func__
, __LINE__
, fcport
->port_name
,
5290 qla24xx_post_gpsc_work(vha
, fcport
);
5293 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5297 * qla2x00_configure_fabric
5298 * Setup SNS devices with loop ID's.
5301 * ha = adapter block pointer.
5308 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
5312 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5314 LIST_HEAD(new_fcports
);
5315 struct qla_hw_data
*ha
= vha
->hw
;
5318 /* If FL port exists, then SNS is present */
5319 if (IS_FWI2_CAPABLE(ha
))
5320 loop_id
= NPH_F_PORT
;
5322 loop_id
= SNS_FL_PORT
;
5323 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
5324 if (rval
!= QLA_SUCCESS
) {
5325 ql_dbg(ql_dbg_disc
, vha
, 0x20a0,
5326 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5328 vha
->device_flags
&= ~SWITCH_FOUND
;
5329 return (QLA_SUCCESS
);
5331 vha
->device_flags
|= SWITCH_FOUND
;
5334 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
5335 rval
= qla2x00_send_change_request(vha
, 0x3, 0);
5336 if (rval
!= QLA_SUCCESS
)
5337 ql_log(ql_log_warn
, vha
, 0x121,
5338 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5344 qla2x00_mgmt_svr_login(vha
);
5347 if (ql2xfdmienable
&&
5348 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
5349 qla2x00_fdmi_register(vha
);
5351 /* Ensure we are logged into the SNS. */
5352 loop_id
= NPH_SNS_LID(ha
);
5353 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
5354 0xfc, mb
, BIT_1
|BIT_0
);
5355 if (rval
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5356 ql_dbg(ql_dbg_disc
, vha
, 0x20a1,
5357 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5358 loop_id
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7], rval
);
5359 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5362 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
5363 if (qla2x00_rft_id(vha
)) {
5365 ql_dbg(ql_dbg_disc
, vha
, 0x20a2,
5366 "Register FC-4 TYPE failed.\n");
5367 if (test_bit(LOOP_RESYNC_NEEDED
,
5371 if (qla2x00_rff_id(vha
, FC4_TYPE_FCP_SCSI
)) {
5373 ql_dbg(ql_dbg_disc
, vha
, 0x209a,
5374 "Register FC-4 Features failed.\n");
5375 if (test_bit(LOOP_RESYNC_NEEDED
,
5379 if (vha
->flags
.nvme_enabled
) {
5380 if (qla2x00_rff_id(vha
, FC_TYPE_NVME
)) {
5381 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
5382 "Register NVME FC Type Features failed.\n");
5385 if (qla2x00_rnn_id(vha
)) {
5387 ql_dbg(ql_dbg_disc
, vha
, 0x2104,
5388 "Register Node Name failed.\n");
5389 if (test_bit(LOOP_RESYNC_NEEDED
,
5392 } else if (qla2x00_rsnn_nn(vha
)) {
5394 ql_dbg(ql_dbg_disc
, vha
, 0x209b,
5395 "Register Symbolic Node Name failed.\n");
5396 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5402 /* Mark the time right before querying FW for connected ports.
5403 * This process is long, asynchronous and by the time it's done,
5404 * collected information might not be accurate anymore. E.g.
5405 * disconnected port might have re-connected and a brand new
5406 * session has been created. In this case session's generation
5407 * will be newer than discovery_gen. */
5408 qlt_do_generation_tick(vha
, &discovery_gen
);
5410 if (USE_ASYNC_SCAN(ha
)) {
5411 rval
= qla24xx_async_gpnft(vha
, FC4_TYPE_FCP_SCSI
,
5414 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5416 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5417 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5419 rval
= qla2x00_find_all_fabric_devs(vha
);
5421 if (rval
!= QLA_SUCCESS
)
5425 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
5426 qla_nvme_register_hba(vha
);
5429 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
5430 "Configure fabric error exit rval=%d.\n", rval
);
5436 * qla2x00_find_all_fabric_devs
5439 * ha = adapter block pointer.
5440 * dev = database device entry pointer.
5449 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
)
5453 fc_port_t
*fcport
, *new_fcport
;
5458 int first_dev
, last_dev
;
5459 port_id_t wrap
= {}, nxt_d_id
;
5460 struct qla_hw_data
*ha
= vha
->hw
;
5461 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5462 unsigned long flags
;
5466 /* Try GID_PT to get device list, else GAN. */
5468 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
5473 ql_dbg(ql_dbg_disc
, vha
, 0x209c,
5474 "GID_PT allocations failed, fallback on GA_NXT.\n");
5476 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
5477 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
5479 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5481 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
5483 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5485 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
5487 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5489 } else if (qla2x00_gfpn_id(vha
, swl
) != QLA_SUCCESS
) {
5491 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5495 /* If other queries succeeded probe for FC-4 type */
5497 qla2x00_gff_id(vha
, swl
);
5498 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5504 /* Allocate temporary fcport for any new fcports discovered. */
5505 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5506 if (new_fcport
== NULL
) {
5507 ql_log(ql_log_warn
, vha
, 0x209d,
5508 "Failed to allocate memory for fcport.\n");
5509 return (QLA_MEMORY_ALLOC_FAILED
);
5511 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5512 /* Set start port ID scan at adapter ID. */
5516 /* Starting free loop ID. */
5517 loop_id
= ha
->min_external_loopid
;
5518 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
5519 if (qla2x00_is_reserved_id(vha
, loop_id
))
5522 if (ha
->current_topology
== ISP_CFG_FL
&&
5523 (atomic_read(&vha
->loop_down_timer
) ||
5524 LOOP_TRANSITION(vha
))) {
5525 atomic_set(&vha
->loop_down_timer
, 0);
5526 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5527 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5533 wrap
.b24
= new_fcport
->d_id
.b24
;
5535 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
5536 memcpy(new_fcport
->node_name
,
5537 swl
[swl_idx
].node_name
, WWN_SIZE
);
5538 memcpy(new_fcport
->port_name
,
5539 swl
[swl_idx
].port_name
, WWN_SIZE
);
5540 memcpy(new_fcport
->fabric_port_name
,
5541 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
5542 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
5543 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
5545 new_fcport
->nvme_flag
= 0;
5546 new_fcport
->fc4f_nvme
= 0;
5547 if (vha
->flags
.nvme_enabled
&&
5548 swl
[swl_idx
].fc4f_nvme
) {
5549 new_fcport
->fc4f_nvme
=
5550 swl
[swl_idx
].fc4f_nvme
;
5551 ql_log(ql_log_info
, vha
, 0x2131,
5552 "FOUND: NVME port %8phC as FC Type 28h\n",
5553 new_fcport
->port_name
);
5556 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
5562 /* Send GA_NXT to the switch */
5563 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
5564 if (rval
!= QLA_SUCCESS
) {
5565 ql_log(ql_log_warn
, vha
, 0x209e,
5566 "SNS scan failed -- assuming "
5567 "zero-entry result.\n");
5573 /* If wrap on switch device list, exit. */
5575 wrap
.b24
= new_fcport
->d_id
.b24
;
5577 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
5578 ql_dbg(ql_dbg_disc
, vha
, 0x209f,
5579 "Device wrap (%02x%02x%02x).\n",
5580 new_fcport
->d_id
.b
.domain
,
5581 new_fcport
->d_id
.b
.area
,
5582 new_fcport
->d_id
.b
.al_pa
);
5586 /* Bypass if same physical adapter. */
5587 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
5590 /* Bypass virtual ports of the same host. */
5591 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
5594 /* Bypass if same domain and area of adapter. */
5595 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
5596 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
5600 /* Bypass reserved domain fields. */
5601 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
5604 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5605 if (ql2xgffidenable
&&
5606 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
5607 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
5610 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5612 /* Locate matching device in database. */
5614 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5615 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5619 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5623 /* Update port state. */
5624 memcpy(fcport
->fabric_port_name
,
5625 new_fcport
->fabric_port_name
, WWN_SIZE
);
5626 fcport
->fp_speed
= new_fcport
->fp_speed
;
5629 * If address the same and state FCS_ONLINE
5630 * (or in target mode), nothing changed.
5632 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
5633 (atomic_read(&fcport
->state
) == FCS_ONLINE
||
5634 (vha
->host
->active_mode
== MODE_TARGET
))) {
5639 * If device was not a fabric device before.
5641 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
5642 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5643 qla2x00_clear_loop_id(fcport
);
5644 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
5650 * Port ID changed or device was marked to be updated;
5651 * Log it out if still logged in and mark it for
5654 if (qla_tgt_mode_enabled(base_vha
)) {
5655 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf080,
5656 "port changed FC ID, %8phC"
5657 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5659 fcport
->d_id
.b
.domain
,
5660 fcport
->d_id
.b
.area
,
5661 fcport
->d_id
.b
.al_pa
,
5663 new_fcport
->d_id
.b
.domain
,
5664 new_fcport
->d_id
.b
.area
,
5665 new_fcport
->d_id
.b
.al_pa
);
5666 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5670 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5671 fcport
->flags
|= FCF_LOGIN_NEEDED
;
5675 if (fcport
->fc4f_nvme
) {
5676 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
5677 fcport
->disc_state
= DSC_GNL
;
5678 vha
->fcport_count
--;
5679 fcport
->login_succ
= 0;
5684 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5687 /* If device was not in our fcports list, then add it. */
5688 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5689 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5691 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5694 /* Allocate a new replacement fcport. */
5695 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
5696 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5697 if (new_fcport
== NULL
) {
5698 ql_log(ql_log_warn
, vha
, 0xd032,
5699 "Memory allocation failed for fcport.\n");
5700 return (QLA_MEMORY_ALLOC_FAILED
);
5702 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5703 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
5706 qla2x00_free_fcport(new_fcport
);
5709 * Logout all previous fabric dev marked lost, except FCP2 devices.
5711 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5712 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5715 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
5716 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
5719 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5720 if ((qla_dual_mode_enabled(vha
) ||
5721 qla_ini_mode_enabled(vha
)) &&
5722 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5723 qla2x00_mark_device_lost(vha
, fcport
,
5724 ql2xplogiabsentdevice
, 0);
5725 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5726 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5727 fcport
->port_type
!= FCT_INITIATOR
&&
5728 fcport
->port_type
!= FCT_BROADCAST
) {
5729 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5730 "%s %d %8phC post del sess\n",
5733 qlt_schedule_sess_for_deletion(fcport
);
5739 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5740 qla24xx_fcport_handle_login(vha
, fcport
);
5746 * qla2x00_find_new_loop_id
5747 * Scan through our port list and find a new usable loop ID.
5750 * ha: adapter state pointer.
5751 * dev: port structure pointer.
5754 * qla2x00 local function return status code.
5760 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
5763 struct qla_hw_data
*ha
= vha
->hw
;
5764 unsigned long flags
= 0;
5768 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5770 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
5772 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
5773 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
5774 dev
->loop_id
= FC_NO_LOOP_ID
;
5775 rval
= QLA_FUNCTION_FAILED
;
5777 set_bit(dev
->loop_id
, ha
->loop_id_map
);
5779 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5781 if (rval
== QLA_SUCCESS
)
5782 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
5783 "Assigning new loopid=%x, portid=%x.\n",
5784 dev
->loop_id
, dev
->d_id
.b24
);
5786 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
5787 "No loop_id's available, portid=%x.\n",
5794 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5796 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t
*vha
)
5798 int loop_id
= FC_NO_LOOP_ID
;
5799 int lid
= NPH_MGMT_SERVER
- vha
->vp_idx
;
5800 unsigned long flags
;
5801 struct qla_hw_data
*ha
= vha
->hw
;
5803 if (vha
->vp_idx
== 0) {
5804 set_bit(NPH_MGMT_SERVER
, ha
->loop_id_map
);
5805 return NPH_MGMT_SERVER
;
5808 /* pick id from high and work down to low */
5809 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5810 for (; lid
> 0; lid
--) {
5811 if (!test_bit(lid
, vha
->hw
->loop_id_map
)) {
5812 set_bit(lid
, vha
->hw
->loop_id_map
);
5817 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5823 * qla2x00_fabric_login
5824 * Issue fabric login command.
5827 * ha = adapter block pointer.
5828 * device = pointer to FC device type structure.
5831 * 0 - Login successfully
5833 * 2 - Initiator device
5837 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
5838 uint16_t *next_loopid
)
5842 uint16_t tmp_loopid
;
5843 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5844 struct qla_hw_data
*ha
= vha
->hw
;
5850 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
5851 "Trying Fabric Login w/loop id 0x%04x for port "
5853 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5854 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5856 /* Login fcport on switch. */
5857 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
5858 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5859 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
5860 if (rval
!= QLA_SUCCESS
) {
5863 if (mb
[0] == MBS_PORT_ID_USED
) {
5865 * Device has another loop ID. The firmware team
5866 * recommends the driver perform an implicit login with
5867 * the specified ID again. The ID we just used is save
5868 * here so we return with an ID that can be tried by
5872 tmp_loopid
= fcport
->loop_id
;
5873 fcport
->loop_id
= mb
[1];
5875 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
5876 "Fabric Login: port in use - next loop "
5877 "id=0x%04x, port id= %02x%02x%02x.\n",
5878 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5879 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5881 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
5886 /* A retry occurred before. */
5887 *next_loopid
= tmp_loopid
;
5890 * No retry occurred before. Just increment the
5891 * ID value for next login.
5893 *next_loopid
= (fcport
->loop_id
+ 1);
5896 if (mb
[1] & BIT_0
) {
5897 fcport
->port_type
= FCT_INITIATOR
;
5899 fcport
->port_type
= FCT_TARGET
;
5900 if (mb
[1] & BIT_1
) {
5901 fcport
->flags
|= FCF_FCP2_DEVICE
;
5906 fcport
->supported_classes
|= FC_COS_CLASS2
;
5908 fcport
->supported_classes
|= FC_COS_CLASS3
;
5910 if (IS_FWI2_CAPABLE(ha
)) {
5913 FCF_CONF_COMP_SUPPORTED
;
5918 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
5920 * Loop ID already used, try next loop ID.
5923 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
5924 if (rval
!= QLA_SUCCESS
) {
5925 /* Ran out of loop IDs to use */
5928 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
5930 * Firmware possibly timed out during login. If NO
5931 * retries are left to do then the device is declared
5934 *next_loopid
= fcport
->loop_id
;
5935 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5936 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5937 fcport
->d_id
.b
.al_pa
);
5938 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
5944 * unrecoverable / not handled error
5946 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
5947 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5948 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
5949 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
5950 fcport
->loop_id
, jiffies
);
5952 *next_loopid
= fcport
->loop_id
;
5953 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5954 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5955 fcport
->d_id
.b
.al_pa
);
5956 qla2x00_clear_loop_id(fcport
);
5957 fcport
->login_retry
= 0;
5968 * qla2x00_local_device_login
5969 * Issue local device login command.
5972 * ha = adapter block pointer.
5973 * loop_id = loop id of device to login to.
5975 * Returns (Where's the #define!!!!):
5976 * 0 - Login successfully
5981 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5984 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5986 memset(mb
, 0, sizeof(mb
));
5987 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
5988 if (rval
== QLA_SUCCESS
) {
5989 /* Interrogate mailbox registers for any errors */
5990 if (mb
[0] == MBS_COMMAND_ERROR
)
5992 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
5993 /* device not in PCB table */
6001 * qla2x00_loop_resync
6002 * Resync with fibre channel devices.
6005 * ha = adapter block pointer.
6011 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
6013 int rval
= QLA_SUCCESS
;
6015 struct req_que
*req
;
6016 struct rsp_que
*rsp
;
6021 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6022 if (vha
->flags
.online
) {
6023 if (!(rval
= qla2x00_fw_ready(vha
))) {
6024 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6027 if (!IS_QLAFX00(vha
->hw
)) {
6029 * Issue a marker after FW becomes
6032 qla2x00_marker(vha
, req
, rsp
, 0, 0,
6034 vha
->marker_needed
= 0;
6037 /* Remap devices on Loop. */
6038 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6040 if (IS_QLAFX00(vha
->hw
))
6041 qlafx00_configure_devices(vha
);
6043 qla2x00_configure_loop(vha
);
6046 } while (!atomic_read(&vha
->loop_down_timer
) &&
6047 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
6048 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
6053 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
6054 return (QLA_FUNCTION_FAILED
);
6057 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
6058 "%s *** FAILED ***.\n", __func__
);
6064 * qla2x00_perform_loop_resync
6065 * Description: This function will set the appropriate flags and call
6066 * qla2x00_loop_resync. If successful loop will be resynced
6067 * Arguments : scsi_qla_host_t pointer
6068 * returm : Success or Failure
6071 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
6075 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
6076 /*Configure the flags so that resync happens properly*/
6077 atomic_set(&ha
->loop_down_timer
, 0);
6078 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
6079 atomic_set(&ha
->loop_state
, LOOP_UP
);
6080 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
6081 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
6082 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
6084 rval
= qla2x00_loop_resync(ha
);
6086 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
6088 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
6095 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
6098 struct scsi_qla_host
*vha
;
6099 struct qla_hw_data
*ha
= base_vha
->hw
;
6100 unsigned long flags
;
6102 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6103 /* Go with deferred removal of rport references. */
6104 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
6105 atomic_inc(&vha
->vref_count
);
6106 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
6107 if (fcport
->drport
&&
6108 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
6109 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6110 qla2x00_rport_del(fcport
);
6112 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6115 atomic_dec(&vha
->vref_count
);
6116 wake_up(&vha
->vref_waitq
);
6118 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6121 /* Assumes idc_lock always held on entry */
6123 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
6125 struct qla_hw_data
*ha
= vha
->hw
;
6126 uint32_t drv_presence
, drv_presence_mask
;
6127 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
6128 uint32_t class_type_mask
= 0x3;
6129 uint16_t fcoe_other_function
= 0xffff, i
;
6131 if (IS_QLA8044(ha
)) {
6132 drv_presence
= qla8044_rd_direct(vha
,
6133 QLA8044_CRB_DRV_ACTIVE_INDEX
);
6134 dev_part_info1
= qla8044_rd_direct(vha
,
6135 QLA8044_CRB_DEV_PART_INFO_INDEX
);
6136 dev_part_info2
= qla8044_rd_direct(vha
,
6137 QLA8044_CRB_DEV_PART_INFO2
);
6139 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6140 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
6141 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
6143 for (i
= 0; i
< 8; i
++) {
6144 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
6145 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
6146 (i
!= ha
->portnum
)) {
6147 fcoe_other_function
= i
;
6151 if (fcoe_other_function
== 0xffff) {
6152 for (i
= 0; i
< 8; i
++) {
6153 class_type
= ((dev_part_info2
>> (i
* 4)) &
6155 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
6156 ((i
+ 8) != ha
->portnum
)) {
6157 fcoe_other_function
= i
+ 8;
6163 * Prepare drv-presence mask based on fcoe functions present.
6164 * However consider only valid physical fcoe function numbers (0-15).
6166 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
6167 ((fcoe_other_function
== 0xffff) ?
6168 0 : (1 << (fcoe_other_function
))));
6170 /* We are the reset owner iff:
6171 * - No other protocol drivers present.
6172 * - This is the lowest among fcoe functions. */
6173 if (!(drv_presence
& drv_presence_mask
) &&
6174 (ha
->portnum
< fcoe_other_function
)) {
6175 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
6176 "This host is Reset owner.\n");
6177 ha
->flags
.nic_core_reset_owner
= 1;
6182 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
6184 int rval
= QLA_SUCCESS
;
6185 struct qla_hw_data
*ha
= vha
->hw
;
6188 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6189 if (rval
== QLA_SUCCESS
) {
6190 drv_ack
|= (1 << ha
->portnum
);
6191 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6198 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
6200 int rval
= QLA_SUCCESS
;
6201 struct qla_hw_data
*ha
= vha
->hw
;
6204 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6205 if (rval
== QLA_SUCCESS
) {
6206 drv_ack
&= ~(1 << ha
->portnum
);
6207 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6214 qla83xx_dev_state_to_string(uint32_t dev_state
)
6216 switch (dev_state
) {
6217 case QLA8XXX_DEV_COLD
:
6218 return "COLD/RE-INIT";
6219 case QLA8XXX_DEV_INITIALIZING
:
6220 return "INITIALIZING";
6221 case QLA8XXX_DEV_READY
:
6223 case QLA8XXX_DEV_NEED_RESET
:
6224 return "NEED RESET";
6225 case QLA8XXX_DEV_NEED_QUIESCENT
:
6226 return "NEED QUIESCENT";
6227 case QLA8XXX_DEV_FAILED
:
6229 case QLA8XXX_DEV_QUIESCENT
:
6236 /* Assumes idc-lock always held on entry */
6238 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
6240 struct qla_hw_data
*ha
= vha
->hw
;
6241 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
6243 switch (audit_type
) {
6244 case IDC_AUDIT_TIMESTAMP
:
6245 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
6246 idc_audit_reg
= (ha
->portnum
) |
6247 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
6248 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6251 case IDC_AUDIT_COMPLETION
:
6252 duration_secs
= ((jiffies_to_msecs(jiffies
) -
6253 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
6254 idc_audit_reg
= (ha
->portnum
) |
6255 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
6256 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6260 ql_log(ql_log_warn
, vha
, 0xb078,
6261 "Invalid audit type specified.\n");
6266 /* Assumes idc_lock always held on entry */
6268 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
6270 struct qla_hw_data
*ha
= vha
->hw
;
6271 uint32_t idc_control
, dev_state
;
6273 __qla83xx_get_idc_control(vha
, &idc_control
);
6274 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
6275 ql_log(ql_log_info
, vha
, 0xb080,
6276 "NIC Core reset has been disabled. idc-control=0x%x\n",
6278 return QLA_FUNCTION_FAILED
;
6281 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6282 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6283 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
6284 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
6285 QLA8XXX_DEV_NEED_RESET
);
6286 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
6287 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
6289 const char *state
= qla83xx_dev_state_to_string(dev_state
);
6290 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
6292 /* SV: XXX: Is timeout required here? */
6293 /* Wait for IDC state change READY -> NEED_RESET */
6294 while (dev_state
== QLA8XXX_DEV_READY
) {
6295 qla83xx_idc_unlock(vha
, 0);
6297 qla83xx_idc_lock(vha
, 0);
6298 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6302 /* Send IDC ack by writing to drv-ack register */
6303 __qla83xx_set_drv_ack(vha
);
6309 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
6311 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6315 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
6317 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6321 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
6323 uint32_t drv_presence
= 0;
6324 struct qla_hw_data
*ha
= vha
->hw
;
6326 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6327 if (drv_presence
& (1 << ha
->portnum
))
6330 return QLA_TEST_FAILED
;
6334 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
6336 int rval
= QLA_SUCCESS
;
6337 struct qla_hw_data
*ha
= vha
->hw
;
6339 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
6340 "Entered %s().\n", __func__
);
6342 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
6343 ql_log(ql_log_warn
, vha
, 0xb059,
6344 "Device in unrecoverable FAILED state.\n");
6345 return QLA_FUNCTION_FAILED
;
6348 qla83xx_idc_lock(vha
, 0);
6350 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
6351 ql_log(ql_log_warn
, vha
, 0xb05a,
6352 "Function=0x%x has been removed from IDC participation.\n",
6354 rval
= QLA_FUNCTION_FAILED
;
6358 qla83xx_reset_ownership(vha
);
6360 rval
= qla83xx_initiating_reset(vha
);
6363 * Perform reset if we are the reset-owner,
6364 * else wait till IDC state changes to READY/FAILED.
6366 if (rval
== QLA_SUCCESS
) {
6367 rval
= qla83xx_idc_state_handler(vha
);
6369 if (rval
== QLA_SUCCESS
)
6370 ha
->flags
.nic_core_hung
= 0;
6371 __qla83xx_clear_drv_ack(vha
);
6375 qla83xx_idc_unlock(vha
, 0);
6377 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
6383 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
6385 struct qla_hw_data
*ha
= vha
->hw
;
6386 int rval
= QLA_FUNCTION_FAILED
;
6388 if (!IS_MCTP_CAPABLE(ha
)) {
6389 /* This message can be removed from the final version */
6390 ql_log(ql_log_info
, vha
, 0x506d,
6391 "This board is not MCTP capable\n");
6395 if (!ha
->mctp_dump
) {
6396 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
6397 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
6399 if (!ha
->mctp_dump
) {
6400 ql_log(ql_log_warn
, vha
, 0x506e,
6401 "Failed to allocate memory for mctp dump\n");
6406 #define MCTP_DUMP_STR_ADDR 0x00000000
6407 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
6408 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
6409 if (rval
!= QLA_SUCCESS
) {
6410 ql_log(ql_log_warn
, vha
, 0x506f,
6411 "Failed to capture mctp dump\n");
6413 ql_log(ql_log_info
, vha
, 0x5070,
6414 "Mctp dump capture for host (%ld/%p).\n",
6415 vha
->host_no
, ha
->mctp_dump
);
6416 ha
->mctp_dumped
= 1;
6419 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
6420 ha
->flags
.nic_core_reset_hdlr_active
= 1;
6421 rval
= qla83xx_restart_nic_firmware(vha
);
6423 /* NIC Core reset failed. */
6424 ql_log(ql_log_warn
, vha
, 0x5071,
6425 "Failed to restart nic firmware\n");
6427 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
6428 "Restarted NIC firmware successfully.\n");
6429 ha
->flags
.nic_core_reset_hdlr_active
= 0;
6437 * qla2x00_quiesce_io
6438 * Description: This function will block the new I/Os
6439 * Its not aborting any I/Os as context
6440 * is not destroyed during quiescence
6441 * Arguments: scsi_qla_host_t
6445 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
6447 struct qla_hw_data
*ha
= vha
->hw
;
6448 struct scsi_qla_host
*vp
;
6450 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
6451 "Quiescing I/O - ha=%p.\n", ha
);
6453 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
6454 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6455 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6456 qla2x00_mark_all_devices_lost(vha
, 0);
6457 list_for_each_entry(vp
, &ha
->vp_list
, list
)
6458 qla2x00_mark_all_devices_lost(vp
, 0);
6460 if (!atomic_read(&vha
->loop_down_timer
))
6461 atomic_set(&vha
->loop_down_timer
,
6464 /* Wait for pending cmds to complete */
6465 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
6469 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
6471 struct qla_hw_data
*ha
= vha
->hw
;
6472 struct scsi_qla_host
*vp
;
6473 unsigned long flags
;
6477 /* For ISP82XX, driver waits for completion of the commands.
6478 * online flag should be set.
6480 if (!(IS_P3P_TYPE(ha
)))
6481 vha
->flags
.online
= 0;
6482 ha
->flags
.chip_reset_done
= 0;
6483 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6484 vha
->qla_stats
.total_isp_aborts
++;
6486 ql_log(ql_log_info
, vha
, 0x00af,
6487 "Performing ISP error recovery - ha=%p.\n", ha
);
6489 ha
->flags
.purge_mbox
= 1;
6490 /* For ISP82XX, reset_chip is just disabling interrupts.
6491 * Driver waits for the completion of the commands.
6492 * the interrupts need to be enabled.
6494 if (!(IS_P3P_TYPE(ha
)))
6495 ha
->isp_ops
->reset_chip(vha
);
6498 ha
->flags
.rida_fmt2
= 0;
6499 ha
->flags
.n2n_ae
= 0;
6500 ha
->flags
.lip_ae
= 0;
6501 ha
->current_topology
= 0;
6502 ha
->flags
.fw_started
= 0;
6503 ha
->flags
.fw_init_done
= 0;
6505 ha
->base_qpair
->chip_reset
= ha
->chip_reset
;
6506 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6507 if (ha
->queue_pair_map
[i
])
6508 ha
->queue_pair_map
[i
]->chip_reset
=
6509 ha
->base_qpair
->chip_reset
;
6512 /* purge MBox commands */
6513 if (atomic_read(&ha
->num_pend_mbx_stage3
)) {
6514 clear_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
);
6515 complete(&ha
->mbx_intr_comp
);
6519 while (atomic_read(&ha
->num_pend_mbx_stage3
) ||
6520 atomic_read(&ha
->num_pend_mbx_stage2
) ||
6521 atomic_read(&ha
->num_pend_mbx_stage1
)) {
6527 ha
->flags
.purge_mbox
= 0;
6529 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
6530 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6531 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6532 qla2x00_mark_all_devices_lost(vha
, 0);
6534 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6535 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6536 atomic_inc(&vp
->vref_count
);
6537 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6539 qla2x00_mark_all_devices_lost(vp
, 0);
6541 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6542 atomic_dec(&vp
->vref_count
);
6544 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6546 if (!atomic_read(&vha
->loop_down_timer
))
6547 atomic_set(&vha
->loop_down_timer
,
6551 /* Clear all async request states across all VPs. */
6552 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
6553 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6554 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6555 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6556 atomic_inc(&vp
->vref_count
);
6557 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6559 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
6560 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6562 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6563 atomic_dec(&vp
->vref_count
);
6565 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6567 if (!ha
->flags
.eeh_busy
) {
6568 /* Make sure for ISP 82XX IO DMA is complete */
6569 if (IS_P3P_TYPE(ha
)) {
6570 qla82xx_chip_reset_cleanup(vha
);
6571 ql_log(ql_log_info
, vha
, 0x00b4,
6572 "Done chip reset cleanup.\n");
6574 /* Done waiting for pending commands.
6575 * Reset the online flag.
6577 vha
->flags
.online
= 0;
6580 /* Requeue all commands in outstanding command list. */
6581 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6583 /* memory barrier */
6589 * Resets ISP and aborts all outstanding commands.
6592 * ha = adapter block pointer.
6598 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
6602 struct qla_hw_data
*ha
= vha
->hw
;
6603 struct scsi_qla_host
*vp
;
6604 struct req_que
*req
= ha
->req_q_map
[0];
6605 unsigned long flags
;
6607 if (vha
->flags
.online
) {
6608 qla2x00_abort_isp_cleanup(vha
);
6610 if (IS_QLA8031(ha
)) {
6611 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
6612 "Clearing fcoe driver presence.\n");
6613 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
6614 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
6615 "Error while clearing DRV-Presence.\n");
6618 if (unlikely(pci_channel_offline(ha
->pdev
) &&
6619 ha
->flags
.pci_channel_io_perm_failure
)) {
6620 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6625 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
6627 ha
->isp_ops
->nvram_config(vha
);
6629 if (!qla2x00_restart_isp(vha
)) {
6630 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6632 if (!atomic_read(&vha
->loop_down_timer
)) {
6634 * Issue marker command only when we are going
6635 * to start the I/O .
6637 vha
->marker_needed
= 1;
6640 vha
->flags
.online
= 1;
6642 ha
->isp_ops
->enable_intrs(ha
);
6644 ha
->isp_abort_cnt
= 0;
6645 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6647 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
6648 qla2x00_get_fw_version(vha
);
6650 ha
->flags
.fce_enabled
= 1;
6652 fce_calc_size(ha
->fce_bufs
));
6653 rval
= qla2x00_enable_fce_trace(vha
,
6654 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6657 ql_log(ql_log_warn
, vha
, 0x8033,
6658 "Unable to reinitialize FCE "
6660 ha
->flags
.fce_enabled
= 0;
6665 memset(ha
->eft
, 0, EFT_SIZE
);
6666 rval
= qla2x00_enable_eft_trace(vha
,
6667 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6669 ql_log(ql_log_warn
, vha
, 0x8034,
6670 "Unable to reinitialize EFT "
6674 } else { /* failed the ISP abort */
6675 vha
->flags
.online
= 1;
6676 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
6677 if (ha
->isp_abort_cnt
== 0) {
6678 ql_log(ql_log_fatal
, vha
, 0x8035,
6679 "ISP error recover failed - "
6680 "board disabled.\n");
6682 * The next call disables the board
6685 ha
->isp_ops
->reset_adapter(vha
);
6686 vha
->flags
.online
= 0;
6687 clear_bit(ISP_ABORT_RETRY
,
6690 } else { /* schedule another ISP abort */
6691 ha
->isp_abort_cnt
--;
6692 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
6693 "ISP abort - retry remaining %d.\n",
6698 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
6699 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
6700 "ISP error recovery - retrying (%d) "
6701 "more times.\n", ha
->isp_abort_cnt
);
6702 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6710 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
6711 qla2x00_configure_hba(vha
);
6712 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6713 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6715 atomic_inc(&vp
->vref_count
);
6716 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6718 qla2x00_vp_abort_isp(vp
);
6720 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6721 atomic_dec(&vp
->vref_count
);
6724 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6726 if (IS_QLA8031(ha
)) {
6727 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
6728 "Setting back fcoe driver presence.\n");
6729 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
6730 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
6731 "Error while setting DRV-Presence.\n");
6734 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
6742 * qla2x00_restart_isp
6743 * restarts the ISP after a reset
6746 * ha = adapter block pointer.
6752 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
6755 struct qla_hw_data
*ha
= vha
->hw
;
6756 struct req_que
*req
= ha
->req_q_map
[0];
6757 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
6759 /* If firmware needs to be loaded */
6760 if (qla2x00_isp_firmware(vha
)) {
6761 vha
->flags
.online
= 0;
6762 status
= ha
->isp_ops
->chip_diag(vha
);
6764 status
= qla2x00_setup_chip(vha
);
6767 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
6768 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6769 ha
->flags
.chip_reset_done
= 1;
6771 /* Initialize the queues in use */
6772 qla25xx_init_queues(ha
);
6774 status
= qla2x00_fw_ready(vha
);
6776 /* Issue a marker after FW becomes ready. */
6777 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
6778 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6781 /* if no cable then assume it's good */
6782 if ((vha
->device_flags
& DFLG_NO_CABLE
))
6789 qla25xx_init_queues(struct qla_hw_data
*ha
)
6791 struct rsp_que
*rsp
= NULL
;
6792 struct req_que
*req
= NULL
;
6793 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
6797 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
6798 rsp
= ha
->rsp_q_map
[i
];
6799 if (rsp
&& test_bit(i
, ha
->rsp_qid_map
)) {
6800 rsp
->options
&= ~BIT_0
;
6801 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
6802 if (ret
!= QLA_SUCCESS
)
6803 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
6804 "%s Rsp que: %d init failed.\n",
6807 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
6808 "%s Rsp que: %d inited.\n",
6812 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
6813 req
= ha
->req_q_map
[i
];
6814 if (req
&& test_bit(i
, ha
->req_qid_map
)) {
6815 /* Clear outstanding commands array. */
6816 req
->options
&= ~BIT_0
;
6817 ret
= qla25xx_init_req_que(base_vha
, req
);
6818 if (ret
!= QLA_SUCCESS
)
6819 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
6820 "%s Req que: %d init failed.\n",
6823 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
6824 "%s Req que: %d inited.\n",
6832 * qla2x00_reset_adapter
6836 * ha = adapter block pointer.
6839 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
6841 unsigned long flags
= 0;
6842 struct qla_hw_data
*ha
= vha
->hw
;
6843 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
6845 vha
->flags
.online
= 0;
6846 ha
->isp_ops
->disable_intrs(ha
);
6848 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6849 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
6850 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6851 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
6852 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6853 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6857 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
6859 unsigned long flags
= 0;
6860 struct qla_hw_data
*ha
= vha
->hw
;
6861 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
6863 if (IS_P3P_TYPE(ha
))
6866 vha
->flags
.online
= 0;
6867 ha
->isp_ops
->disable_intrs(ha
);
6869 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6870 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
6871 RD_REG_DWORD(®
->hccr
);
6872 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
6873 RD_REG_DWORD(®
->hccr
);
6874 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6876 if (IS_NOPOLLING_TYPE(ha
))
6877 ha
->isp_ops
->enable_intrs(ha
);
6880 /* On sparc systems, obtain port and node WWN from firmware
6883 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
6884 struct nvram_24xx
*nv
)
6887 struct qla_hw_data
*ha
= vha
->hw
;
6888 struct pci_dev
*pdev
= ha
->pdev
;
6889 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
6893 val
= of_get_property(dp
, "port-wwn", &len
);
6894 if (val
&& len
>= WWN_SIZE
)
6895 memcpy(nv
->port_name
, val
, WWN_SIZE
);
6897 val
= of_get_property(dp
, "node-wwn", &len
);
6898 if (val
&& len
>= WWN_SIZE
)
6899 memcpy(nv
->node_name
, val
, WWN_SIZE
);
6904 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
6907 struct init_cb_24xx
*icb
;
6908 struct nvram_24xx
*nv
;
6910 uint8_t *dptr1
, *dptr2
;
6913 struct qla_hw_data
*ha
= vha
->hw
;
6916 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6919 /* Determine NVRAM starting address. */
6920 if (ha
->port_no
== 0) {
6921 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
6922 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
6924 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
6925 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
6928 ha
->nvram_size
= sizeof(struct nvram_24xx
);
6929 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
6931 /* Get VPD data into cache */
6932 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
6933 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
6934 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
6936 /* Get NVRAM data into cache and calculate checksum. */
6937 dptr
= (uint32_t *)nv
;
6938 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
6940 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
6941 chksum
+= le32_to_cpu(*dptr
);
6943 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
6944 "Contents of NVRAM\n");
6945 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
6946 (uint8_t *)nv
, ha
->nvram_size
);
6948 /* Bad NVRAM data, set defaults parameters. */
6949 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
6950 || nv
->id
[3] != ' ' ||
6951 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
6952 /* Reset NVRAM data. */
6953 ql_log(ql_log_warn
, vha
, 0x006b,
6954 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6955 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
6956 ql_log(ql_log_warn
, vha
, 0x006c,
6957 "Falling back to functioning (yet invalid -- WWPN) "
6961 * Set default initialization control block.
6963 memset(nv
, 0, ha
->nvram_size
);
6964 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
6965 nv
->version
= cpu_to_le16(ICB_VERSION
);
6966 nv
->frame_payload_size
= 2048;
6967 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
6968 nv
->exchange_count
= cpu_to_le16(0);
6969 nv
->hard_address
= cpu_to_le16(124);
6970 nv
->port_name
[0] = 0x21;
6971 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
6972 nv
->port_name
[2] = 0x00;
6973 nv
->port_name
[3] = 0xe0;
6974 nv
->port_name
[4] = 0x8b;
6975 nv
->port_name
[5] = 0x1c;
6976 nv
->port_name
[6] = 0x55;
6977 nv
->port_name
[7] = 0x86;
6978 nv
->node_name
[0] = 0x20;
6979 nv
->node_name
[1] = 0x00;
6980 nv
->node_name
[2] = 0x00;
6981 nv
->node_name
[3] = 0xe0;
6982 nv
->node_name
[4] = 0x8b;
6983 nv
->node_name
[5] = 0x1c;
6984 nv
->node_name
[6] = 0x55;
6985 nv
->node_name
[7] = 0x86;
6986 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
6987 nv
->login_retry_count
= cpu_to_le16(8);
6988 nv
->interrupt_delay_timer
= cpu_to_le16(0);
6989 nv
->login_timeout
= cpu_to_le16(0);
6990 nv
->firmware_options_1
=
6991 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
6992 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
6993 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6994 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
6995 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
6996 nv
->efi_parameters
= cpu_to_le32(0);
6997 nv
->reset_delay
= 5;
6998 nv
->max_luns_per_target
= cpu_to_le16(128);
6999 nv
->port_down_retry_count
= cpu_to_le16(30);
7000 nv
->link_down_timeout
= cpu_to_le16(30);
7005 if (qla_tgt_mode_enabled(vha
)) {
7006 /* Don't enable full login after initial LIP */
7007 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
7008 /* Don't enable LIP full login for initiator */
7009 nv
->host_p
&= cpu_to_le32(~BIT_10
);
7012 qlt_24xx_config_nvram_stage1(vha
, nv
);
7014 /* Reset Initialization control block */
7015 memset(icb
, 0, ha
->init_cb_size
);
7017 /* Copy 1st segment. */
7018 dptr1
= (uint8_t *)icb
;
7019 dptr2
= (uint8_t *)&nv
->version
;
7020 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
7022 *dptr1
++ = *dptr2
++;
7024 icb
->login_retry_count
= nv
->login_retry_count
;
7025 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
7027 /* Copy 2nd segment. */
7028 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
7029 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
7030 cnt
= (uint8_t *)&icb
->reserved_3
-
7031 (uint8_t *)&icb
->interrupt_delay_timer
;
7033 *dptr1
++ = *dptr2
++;
7034 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
7036 * Setup driver NVRAM options.
7038 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
7041 qlt_24xx_config_nvram_stage2(vha
, icb
);
7043 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
7044 /* Use alternate WWN? */
7045 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
7046 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
7049 /* Prepare nodename */
7050 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
7052 * Firmware will apply the following mask if the nodename was
7055 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
7056 icb
->node_name
[0] &= 0xF0;
7059 /* Set host adapter parameters. */
7060 ha
->flags
.disable_risc_code_load
= 0;
7061 ha
->flags
.enable_lip_reset
= 0;
7062 ha
->flags
.enable_lip_full_login
=
7063 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
7064 ha
->flags
.enable_target_reset
=
7065 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
7066 ha
->flags
.enable_led_scheme
= 0;
7067 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
7069 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
7070 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
7072 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
7073 sizeof(ha
->fw_seriallink_options24
));
7075 /* save HBA serial number */
7076 ha
->serial0
= icb
->port_name
[5];
7077 ha
->serial1
= icb
->port_name
[6];
7078 ha
->serial2
= icb
->port_name
[7];
7079 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
7080 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
7082 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
7084 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
7086 /* Set minimum login_timeout to 4 seconds. */
7087 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
7088 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
7089 if (le16_to_cpu(nv
->login_timeout
) < 4)
7090 nv
->login_timeout
= cpu_to_le16(4);
7091 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
7093 /* Set minimum RATOV to 100 tenths of a second. */
7096 ha
->loop_reset_delay
= nv
->reset_delay
;
7098 /* Link Down Timeout = 0:
7100 * When Port Down timer expires we will start returning
7101 * I/O's to OS with "DID_NO_CONNECT".
7103 * Link Down Timeout != 0:
7105 * The driver waits for the link to come up after link down
7106 * before returning I/Os to OS with "DID_NO_CONNECT".
7108 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
7109 ha
->loop_down_abort_time
=
7110 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
7112 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
7113 ha
->loop_down_abort_time
=
7114 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
7117 /* Need enough time to try and get the port back. */
7118 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
7119 if (qlport_down_retry
)
7120 ha
->port_down_retry_count
= qlport_down_retry
;
7122 /* Set login_retry_count */
7123 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
7124 if (ha
->port_down_retry_count
==
7125 le16_to_cpu(nv
->port_down_retry_count
) &&
7126 ha
->port_down_retry_count
> 3)
7127 ha
->login_retry_count
= ha
->port_down_retry_count
;
7128 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
7129 ha
->login_retry_count
= ha
->port_down_retry_count
;
7130 if (ql2xloginretrycount
)
7131 ha
->login_retry_count
= ql2xloginretrycount
;
7133 /* N2N: driver will initiate Login instead of FW */
7134 icb
->firmware_options_3
|= BIT_8
;
7137 if (!vha
->flags
.init_done
) {
7138 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
7139 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
7140 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
7141 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
7143 icb
->firmware_options_2
&= cpu_to_le32(
7144 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
7145 vha
->flags
.process_response_queue
= 0;
7146 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
7147 ha
->zio_mode
= QLA_ZIO_MODE_6
;
7149 ql_log(ql_log_info
, vha
, 0x006f,
7150 "ZIO mode %d enabled; timer delay (%d us).\n",
7151 ha
->zio_mode
, ha
->zio_timer
* 100);
7153 icb
->firmware_options_2
|= cpu_to_le32(
7154 (uint32_t)ha
->zio_mode
);
7155 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
7156 vha
->flags
.process_response_queue
= 1;
7160 ql_log(ql_log_warn
, vha
, 0x0070,
7161 "NVRAM configuration failed.\n");
7166 uint8_t qla27xx_find_valid_image(struct scsi_qla_host
*vha
)
7168 struct qla27xx_image_status pri_image_status
, sec_image_status
;
7169 uint8_t valid_pri_image
, valid_sec_image
;
7171 uint32_t cnt
, chksum
, size
;
7172 struct qla_hw_data
*ha
= vha
->hw
;
7174 valid_pri_image
= valid_sec_image
= 1;
7175 ha
->active_image
= 0;
7176 size
= sizeof(struct qla27xx_image_status
) / sizeof(uint32_t);
7178 if (!ha
->flt_region_img_status_pri
) {
7179 valid_pri_image
= 0;
7180 goto check_sec_image
;
7183 qla24xx_read_flash_data(vha
, (uint32_t *)(&pri_image_status
),
7184 ha
->flt_region_img_status_pri
, size
);
7186 if (pri_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
7187 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7188 "Primary image signature (0x%x) not valid\n",
7189 pri_image_status
.signature
);
7190 valid_pri_image
= 0;
7191 goto check_sec_image
;
7194 wptr
= (uint32_t *)(&pri_image_status
);
7197 for (chksum
= 0; cnt
--; wptr
++)
7198 chksum
+= le32_to_cpu(*wptr
);
7201 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7202 "Checksum validation failed for primary image (0x%x)\n",
7204 valid_pri_image
= 0;
7208 if (!ha
->flt_region_img_status_sec
) {
7209 valid_sec_image
= 0;
7210 goto check_valid_image
;
7213 qla24xx_read_flash_data(vha
, (uint32_t *)(&sec_image_status
),
7214 ha
->flt_region_img_status_sec
, size
);
7216 if (sec_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
7217 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7218 "Secondary image signature(0x%x) not valid\n",
7219 sec_image_status
.signature
);
7220 valid_sec_image
= 0;
7221 goto check_valid_image
;
7224 wptr
= (uint32_t *)(&sec_image_status
);
7226 for (chksum
= 0; cnt
--; wptr
++)
7227 chksum
+= le32_to_cpu(*wptr
);
7229 ql_dbg(ql_dbg_init
, vha
, 0x018e,
7230 "Checksum validation failed for secondary image (0x%x)\n",
7232 valid_sec_image
= 0;
7236 if (valid_pri_image
&& (pri_image_status
.image_status_mask
& 0x1))
7237 ha
->active_image
= QLA27XX_PRIMARY_IMAGE
;
7238 if (valid_sec_image
&& (sec_image_status
.image_status_mask
& 0x1)) {
7239 if (!ha
->active_image
||
7240 pri_image_status
.generation_number
<
7241 sec_image_status
.generation_number
)
7242 ha
->active_image
= QLA27XX_SECONDARY_IMAGE
;
7245 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x018f, "%s image\n",
7246 ha
->active_image
== 0 ? "default bootld and fw" :
7247 ha
->active_image
== 1 ? "primary" :
7248 ha
->active_image
== 2 ? "secondary" :
7251 return ha
->active_image
;
7255 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
7258 int rval
= QLA_SUCCESS
;
7259 int segments
, fragment
;
7260 uint32_t *dcode
, dlen
;
7264 struct qla_hw_data
*ha
= vha
->hw
;
7265 struct req_que
*req
= ha
->req_q_map
[0];
7267 ql_dbg(ql_dbg_init
, vha
, 0x008b,
7268 "FW: Loading firmware from flash (%x).\n", faddr
);
7272 segments
= FA_RISC_CODE_SEGMENTS
;
7273 dcode
= (uint32_t *)req
->ring
;
7276 if (IS_QLA27XX(ha
) &&
7277 qla27xx_find_valid_image(vha
) == QLA27XX_SECONDARY_IMAGE
)
7278 faddr
= ha
->flt_region_fw_sec
;
7280 /* Validate firmware image by checking version. */
7281 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
7282 for (i
= 0; i
< 4; i
++)
7283 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7284 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7285 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7286 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7288 ql_log(ql_log_fatal
, vha
, 0x008c,
7289 "Unable to verify the integrity of flash firmware "
7291 ql_log(ql_log_fatal
, vha
, 0x008d,
7292 "Firmware data: %08x %08x %08x %08x.\n",
7293 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7295 return QLA_FUNCTION_FAILED
;
7298 while (segments
&& rval
== QLA_SUCCESS
) {
7299 /* Read segment's load information. */
7300 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
7302 risc_addr
= be32_to_cpu(dcode
[2]);
7303 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7304 risc_size
= be32_to_cpu(dcode
[3]);
7307 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7308 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7309 if (dlen
> risc_size
)
7312 ql_dbg(ql_dbg_init
, vha
, 0x008e,
7313 "Loading risc segment@ risc addr %x "
7314 "number of dwords 0x%x offset 0x%x.\n",
7315 risc_addr
, dlen
, faddr
);
7317 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
7318 for (i
= 0; i
< dlen
; i
++)
7319 dcode
[i
] = swab32(dcode
[i
]);
7321 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7324 ql_log(ql_log_fatal
, vha
, 0x008f,
7325 "Failed to load segment %d of firmware.\n",
7327 return QLA_FUNCTION_FAILED
;
7340 if (!IS_QLA27XX(ha
))
7343 if (ha
->fw_dump_template
)
7344 vfree(ha
->fw_dump_template
);
7345 ha
->fw_dump_template
= NULL
;
7346 ha
->fw_dump_template_len
= 0;
7348 ql_dbg(ql_dbg_init
, vha
, 0x0161,
7349 "Loading fwdump template from %x\n", faddr
);
7350 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
7351 risc_size
= be32_to_cpu(dcode
[2]);
7352 ql_dbg(ql_dbg_init
, vha
, 0x0162,
7353 "-> array size %x dwords\n", risc_size
);
7354 if (risc_size
== 0 || risc_size
== ~0)
7355 goto default_template
;
7357 dlen
= (risc_size
- 8) * sizeof(*dcode
);
7358 ql_dbg(ql_dbg_init
, vha
, 0x0163,
7359 "-> template allocating %x bytes...\n", dlen
);
7360 ha
->fw_dump_template
= vmalloc(dlen
);
7361 if (!ha
->fw_dump_template
) {
7362 ql_log(ql_log_warn
, vha
, 0x0164,
7363 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7364 goto default_template
;
7369 dcode
= ha
->fw_dump_template
;
7370 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
7371 for (i
= 0; i
< risc_size
; i
++)
7372 dcode
[i
] = le32_to_cpu(dcode
[i
]);
7374 if (!qla27xx_fwdt_template_valid(dcode
)) {
7375 ql_log(ql_log_warn
, vha
, 0x0165,
7376 "Failed fwdump template validate\n");
7377 goto default_template
;
7380 dlen
= qla27xx_fwdt_template_size(dcode
);
7381 ql_dbg(ql_dbg_init
, vha
, 0x0166,
7382 "-> template size %x bytes\n", dlen
);
7383 if (dlen
> risc_size
* sizeof(*dcode
)) {
7384 ql_log(ql_log_warn
, vha
, 0x0167,
7385 "Failed fwdump template exceeds array by %zx bytes\n",
7386 (size_t)(dlen
- risc_size
* sizeof(*dcode
)));
7387 goto default_template
;
7389 ha
->fw_dump_template_len
= dlen
;
7393 ql_log(ql_log_warn
, vha
, 0x0168, "Using default fwdump template\n");
7394 if (ha
->fw_dump_template
)
7395 vfree(ha
->fw_dump_template
);
7396 ha
->fw_dump_template
= NULL
;
7397 ha
->fw_dump_template_len
= 0;
7399 dlen
= qla27xx_fwdt_template_default_size();
7400 ql_dbg(ql_dbg_init
, vha
, 0x0169,
7401 "-> template allocating %x bytes...\n", dlen
);
7402 ha
->fw_dump_template
= vmalloc(dlen
);
7403 if (!ha
->fw_dump_template
) {
7404 ql_log(ql_log_warn
, vha
, 0x016a,
7405 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7406 goto failed_template
;
7409 dcode
= ha
->fw_dump_template
;
7410 risc_size
= dlen
/ sizeof(*dcode
);
7411 memcpy(dcode
, qla27xx_fwdt_template_default(), dlen
);
7412 for (i
= 0; i
< risc_size
; i
++)
7413 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7415 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7416 ql_log(ql_log_warn
, vha
, 0x016b,
7417 "Failed fwdump template validate\n");
7418 goto failed_template
;
7421 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7422 ql_dbg(ql_dbg_init
, vha
, 0x016c,
7423 "-> template size %x bytes\n", dlen
);
7424 ha
->fw_dump_template_len
= dlen
;
7428 ql_log(ql_log_warn
, vha
, 0x016d, "Failed default fwdump template\n");
7429 if (ha
->fw_dump_template
)
7430 vfree(ha
->fw_dump_template
);
7431 ha
->fw_dump_template
= NULL
;
7432 ha
->fw_dump_template_len
= 0;
7436 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7439 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7443 uint16_t *wcode
, *fwcode
;
7444 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
7445 struct fw_blob
*blob
;
7446 struct qla_hw_data
*ha
= vha
->hw
;
7447 struct req_que
*req
= ha
->req_q_map
[0];
7449 /* Load firmware blob. */
7450 blob
= qla2x00_request_firmware(vha
);
7452 ql_log(ql_log_info
, vha
, 0x0083,
7453 "Firmware image unavailable.\n");
7454 ql_log(ql_log_info
, vha
, 0x0084,
7455 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
7456 return QLA_FUNCTION_FAILED
;
7461 wcode
= (uint16_t *)req
->ring
;
7463 fwcode
= (uint16_t *)blob
->fw
->data
;
7466 /* Validate firmware image by checking version. */
7467 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
7468 ql_log(ql_log_fatal
, vha
, 0x0085,
7469 "Unable to verify integrity of firmware image (%zd).\n",
7471 goto fail_fw_integrity
;
7473 for (i
= 0; i
< 4; i
++)
7474 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
7475 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
7476 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
7477 wcode
[2] == 0 && wcode
[3] == 0)) {
7478 ql_log(ql_log_fatal
, vha
, 0x0086,
7479 "Unable to verify integrity of firmware image.\n");
7480 ql_log(ql_log_fatal
, vha
, 0x0087,
7481 "Firmware data: %04x %04x %04x %04x.\n",
7482 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
7483 goto fail_fw_integrity
;
7487 while (*seg
&& rval
== QLA_SUCCESS
) {
7489 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
7490 risc_size
= be16_to_cpu(fwcode
[3]);
7492 /* Validate firmware image size. */
7493 fwclen
+= risc_size
* sizeof(uint16_t);
7494 if (blob
->fw
->size
< fwclen
) {
7495 ql_log(ql_log_fatal
, vha
, 0x0088,
7496 "Unable to verify integrity of firmware image "
7497 "(%zd).\n", blob
->fw
->size
);
7498 goto fail_fw_integrity
;
7502 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7503 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
7504 if (wlen
> risc_size
)
7506 ql_dbg(ql_dbg_init
, vha
, 0x0089,
7507 "Loading risc segment@ risc addr %x number of "
7508 "words 0x%x.\n", risc_addr
, wlen
);
7510 for (i
= 0; i
< wlen
; i
++)
7511 wcode
[i
] = swab16(fwcode
[i
]);
7513 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7516 ql_log(ql_log_fatal
, vha
, 0x008a,
7517 "Failed to load segment %d of firmware.\n",
7534 return QLA_FUNCTION_FAILED
;
7538 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7541 int segments
, fragment
;
7542 uint32_t *dcode
, dlen
;
7546 struct fw_blob
*blob
;
7547 const uint32_t *fwcode
;
7549 struct qla_hw_data
*ha
= vha
->hw
;
7550 struct req_que
*req
= ha
->req_q_map
[0];
7552 /* Load firmware blob. */
7553 blob
= qla2x00_request_firmware(vha
);
7555 ql_log(ql_log_warn
, vha
, 0x0090,
7556 "Firmware image unavailable.\n");
7557 ql_log(ql_log_warn
, vha
, 0x0091,
7558 "Firmware images can be retrieved from: "
7561 return QLA_FUNCTION_FAILED
;
7564 ql_dbg(ql_dbg_init
, vha
, 0x0092,
7565 "FW: Loading via request-firmware.\n");
7569 segments
= FA_RISC_CODE_SEGMENTS
;
7570 dcode
= (uint32_t *)req
->ring
;
7572 fwcode
= (uint32_t *)blob
->fw
->data
;
7575 /* Validate firmware image by checking version. */
7576 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
7577 ql_log(ql_log_fatal
, vha
, 0x0093,
7578 "Unable to verify integrity of firmware image (%zd).\n",
7580 return QLA_FUNCTION_FAILED
;
7582 for (i
= 0; i
< 4; i
++)
7583 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
7584 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7585 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7586 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7588 ql_log(ql_log_fatal
, vha
, 0x0094,
7589 "Unable to verify integrity of firmware image (%zd).\n",
7591 ql_log(ql_log_fatal
, vha
, 0x0095,
7592 "Firmware data: %08x %08x %08x %08x.\n",
7593 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7594 return QLA_FUNCTION_FAILED
;
7597 while (segments
&& rval
== QLA_SUCCESS
) {
7598 risc_addr
= be32_to_cpu(fwcode
[2]);
7599 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7600 risc_size
= be32_to_cpu(fwcode
[3]);
7602 /* Validate firmware image size. */
7603 fwclen
+= risc_size
* sizeof(uint32_t);
7604 if (blob
->fw
->size
< fwclen
) {
7605 ql_log(ql_log_fatal
, vha
, 0x0096,
7606 "Unable to verify integrity of firmware image "
7607 "(%zd).\n", blob
->fw
->size
);
7608 return QLA_FUNCTION_FAILED
;
7612 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7613 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7614 if (dlen
> risc_size
)
7617 ql_dbg(ql_dbg_init
, vha
, 0x0097,
7618 "Loading risc segment@ risc addr %x "
7619 "number of dwords 0x%x.\n", risc_addr
, dlen
);
7621 for (i
= 0; i
< dlen
; i
++)
7622 dcode
[i
] = swab32(fwcode
[i
]);
7624 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7627 ql_log(ql_log_fatal
, vha
, 0x0098,
7628 "Failed to load segment %d of firmware.\n",
7630 return QLA_FUNCTION_FAILED
;
7643 if (!IS_QLA27XX(ha
))
7646 if (ha
->fw_dump_template
)
7647 vfree(ha
->fw_dump_template
);
7648 ha
->fw_dump_template
= NULL
;
7649 ha
->fw_dump_template_len
= 0;
7651 ql_dbg(ql_dbg_init
, vha
, 0x171,
7652 "Loading fwdump template from %x\n",
7653 (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
));
7654 risc_size
= be32_to_cpu(fwcode
[2]);
7655 ql_dbg(ql_dbg_init
, vha
, 0x172,
7656 "-> array size %x dwords\n", risc_size
);
7657 if (risc_size
== 0 || risc_size
== ~0)
7658 goto default_template
;
7660 dlen
= (risc_size
- 8) * sizeof(*fwcode
);
7661 ql_dbg(ql_dbg_init
, vha
, 0x0173,
7662 "-> template allocating %x bytes...\n", dlen
);
7663 ha
->fw_dump_template
= vmalloc(dlen
);
7664 if (!ha
->fw_dump_template
) {
7665 ql_log(ql_log_warn
, vha
, 0x0174,
7666 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7667 goto default_template
;
7672 dcode
= ha
->fw_dump_template
;
7673 for (i
= 0; i
< risc_size
; i
++)
7674 dcode
[i
] = le32_to_cpu(fwcode
[i
]);
7676 if (!qla27xx_fwdt_template_valid(dcode
)) {
7677 ql_log(ql_log_warn
, vha
, 0x0175,
7678 "Failed fwdump template validate\n");
7679 goto default_template
;
7682 dlen
= qla27xx_fwdt_template_size(dcode
);
7683 ql_dbg(ql_dbg_init
, vha
, 0x0176,
7684 "-> template size %x bytes\n", dlen
);
7685 if (dlen
> risc_size
* sizeof(*fwcode
)) {
7686 ql_log(ql_log_warn
, vha
, 0x0177,
7687 "Failed fwdump template exceeds array by %zx bytes\n",
7688 (size_t)(dlen
- risc_size
* sizeof(*fwcode
)));
7689 goto default_template
;
7691 ha
->fw_dump_template_len
= dlen
;
7695 ql_log(ql_log_warn
, vha
, 0x0178, "Using default fwdump template\n");
7696 if (ha
->fw_dump_template
)
7697 vfree(ha
->fw_dump_template
);
7698 ha
->fw_dump_template
= NULL
;
7699 ha
->fw_dump_template_len
= 0;
7701 dlen
= qla27xx_fwdt_template_default_size();
7702 ql_dbg(ql_dbg_init
, vha
, 0x0179,
7703 "-> template allocating %x bytes...\n", dlen
);
7704 ha
->fw_dump_template
= vmalloc(dlen
);
7705 if (!ha
->fw_dump_template
) {
7706 ql_log(ql_log_warn
, vha
, 0x017a,
7707 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7708 goto failed_template
;
7711 dcode
= ha
->fw_dump_template
;
7712 risc_size
= dlen
/ sizeof(*fwcode
);
7713 fwcode
= qla27xx_fwdt_template_default();
7714 for (i
= 0; i
< risc_size
; i
++)
7715 dcode
[i
] = be32_to_cpu(fwcode
[i
]);
7717 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7718 ql_log(ql_log_warn
, vha
, 0x017b,
7719 "Failed fwdump template validate\n");
7720 goto failed_template
;
7723 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7724 ql_dbg(ql_dbg_init
, vha
, 0x017c,
7725 "-> template size %x bytes\n", dlen
);
7726 ha
->fw_dump_template_len
= dlen
;
7730 ql_log(ql_log_warn
, vha
, 0x017d, "Failed default fwdump template\n");
7731 if (ha
->fw_dump_template
)
7732 vfree(ha
->fw_dump_template
);
7733 ha
->fw_dump_template
= NULL
;
7734 ha
->fw_dump_template_len
= 0;
7739 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7743 if (ql2xfwloadbin
== 1)
7744 return qla81xx_load_risc(vha
, srisc_addr
);
7748 * 1) Firmware via request-firmware interface (.bin file).
7749 * 2) Firmware residing in flash.
7751 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7752 if (rval
== QLA_SUCCESS
)
7755 return qla24xx_load_risc_flash(vha
, srisc_addr
,
7756 vha
->hw
->flt_region_fw
);
7760 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7763 struct qla_hw_data
*ha
= vha
->hw
;
7765 if (ql2xfwloadbin
== 2)
7770 * 1) Firmware residing in flash.
7771 * 2) Firmware via request-firmware interface (.bin file).
7772 * 3) Golden-Firmware residing in flash -- limited operation.
7774 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
7775 if (rval
== QLA_SUCCESS
)
7779 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7780 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
7783 ql_log(ql_log_info
, vha
, 0x0099,
7784 "Attempting to fallback to golden firmware.\n");
7785 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
7786 if (rval
!= QLA_SUCCESS
)
7789 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
7790 ha
->flags
.running_gold_fw
= 1;
7795 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
7798 struct qla_hw_data
*ha
= vha
->hw
;
7800 if (ha
->flags
.pci_channel_io_perm_failure
)
7802 if (!IS_FWI2_CAPABLE(ha
))
7804 if (!ha
->fw_major_version
)
7806 if (!ha
->flags
.fw_started
)
7809 ret
= qla2x00_stop_firmware(vha
);
7810 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
7811 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
7812 ha
->isp_ops
->reset_chip(vha
);
7813 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
7815 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
7817 ql_log(ql_log_info
, vha
, 0x8015,
7818 "Attempting retry of stop-firmware command.\n");
7819 ret
= qla2x00_stop_firmware(vha
);
7823 ha
->flags
.fw_init_done
= 0;
7827 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
7829 int rval
= QLA_SUCCESS
;
7831 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
7832 struct qla_hw_data
*ha
= vha
->hw
;
7833 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
7834 struct req_que
*req
;
7835 struct rsp_que
*rsp
;
7840 rval
= qla2x00_fw_ready(base_vha
);
7842 req
= vha
->qpair
->req
;
7844 req
= ha
->req_q_map
[0];
7847 if (rval
== QLA_SUCCESS
) {
7848 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
7849 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
7852 vha
->flags
.management_server_logged_in
= 0;
7854 /* Login to SNS first */
7855 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
7857 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
7858 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
7859 ql_dbg(ql_dbg_init
, vha
, 0x0120,
7860 "Failed SNS login: loop_id=%x, rval2=%d\n",
7863 ql_dbg(ql_dbg_init
, vha
, 0x0103,
7864 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7865 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7866 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
7867 return (QLA_FUNCTION_FAILED
);
7870 atomic_set(&vha
->loop_down_timer
, 0);
7871 atomic_set(&vha
->loop_state
, LOOP_UP
);
7872 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
7873 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
7874 rval
= qla2x00_loop_resync(base_vha
);
7879 /* 84XX Support **************************************************************/
7881 static LIST_HEAD(qla_cs84xx_list
);
7882 static DEFINE_MUTEX(qla_cs84xx_mutex
);
7884 static struct qla_chip_state_84xx
*
7885 qla84xx_get_chip(struct scsi_qla_host
*vha
)
7887 struct qla_chip_state_84xx
*cs84xx
;
7888 struct qla_hw_data
*ha
= vha
->hw
;
7890 mutex_lock(&qla_cs84xx_mutex
);
7892 /* Find any shared 84xx chip. */
7893 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
7894 if (cs84xx
->bus
== ha
->pdev
->bus
) {
7895 kref_get(&cs84xx
->kref
);
7900 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
7904 kref_init(&cs84xx
->kref
);
7905 spin_lock_init(&cs84xx
->access_lock
);
7906 mutex_init(&cs84xx
->fw_update_mutex
);
7907 cs84xx
->bus
= ha
->pdev
->bus
;
7909 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
7911 mutex_unlock(&qla_cs84xx_mutex
);
7916 __qla84xx_chip_release(struct kref
*kref
)
7918 struct qla_chip_state_84xx
*cs84xx
=
7919 container_of(kref
, struct qla_chip_state_84xx
, kref
);
7921 mutex_lock(&qla_cs84xx_mutex
);
7922 list_del(&cs84xx
->list
);
7923 mutex_unlock(&qla_cs84xx_mutex
);
7928 qla84xx_put_chip(struct scsi_qla_host
*vha
)
7930 struct qla_hw_data
*ha
= vha
->hw
;
7932 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
7936 qla84xx_init_chip(scsi_qla_host_t
*vha
)
7940 struct qla_hw_data
*ha
= vha
->hw
;
7942 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
7944 rval
= qla84xx_verify_chip(vha
, status
);
7946 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
7948 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
7952 /* 81XX Support **************************************************************/
7955 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
7958 struct init_cb_81xx
*icb
;
7959 struct nvram_81xx
*nv
;
7961 uint8_t *dptr1
, *dptr2
;
7964 struct qla_hw_data
*ha
= vha
->hw
;
7967 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
7970 /* Determine NVRAM starting address. */
7971 ha
->nvram_size
= sizeof(struct nvram_81xx
);
7972 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
7973 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
7974 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
7976 /* Get VPD data into cache */
7977 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
7978 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
7981 /* Get NVRAM data into cache and calculate checksum. */
7982 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
7984 dptr
= (uint32_t *)nv
;
7985 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
7986 chksum
+= le32_to_cpu(*dptr
);
7988 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
7989 "Contents of NVRAM:\n");
7990 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
7991 (uint8_t *)nv
, ha
->nvram_size
);
7993 /* Bad NVRAM data, set defaults parameters. */
7994 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
7995 || nv
->id
[3] != ' ' ||
7996 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
7997 /* Reset NVRAM data. */
7998 ql_log(ql_log_info
, vha
, 0x0073,
7999 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
8000 "version=0x%x.\n", chksum
, nv
->id
[0],
8001 le16_to_cpu(nv
->nvram_version
));
8002 ql_log(ql_log_info
, vha
, 0x0074,
8003 "Falling back to functioning (yet invalid -- WWPN) "
8007 * Set default initialization control block.
8009 memset(nv
, 0, ha
->nvram_size
);
8010 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
8011 nv
->version
= cpu_to_le16(ICB_VERSION
);
8012 nv
->frame_payload_size
= 2048;
8013 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
8014 nv
->exchange_count
= cpu_to_le16(0);
8015 nv
->port_name
[0] = 0x21;
8016 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
8017 nv
->port_name
[2] = 0x00;
8018 nv
->port_name
[3] = 0xe0;
8019 nv
->port_name
[4] = 0x8b;
8020 nv
->port_name
[5] = 0x1c;
8021 nv
->port_name
[6] = 0x55;
8022 nv
->port_name
[7] = 0x86;
8023 nv
->node_name
[0] = 0x20;
8024 nv
->node_name
[1] = 0x00;
8025 nv
->node_name
[2] = 0x00;
8026 nv
->node_name
[3] = 0xe0;
8027 nv
->node_name
[4] = 0x8b;
8028 nv
->node_name
[5] = 0x1c;
8029 nv
->node_name
[6] = 0x55;
8030 nv
->node_name
[7] = 0x86;
8031 nv
->login_retry_count
= cpu_to_le16(8);
8032 nv
->interrupt_delay_timer
= cpu_to_le16(0);
8033 nv
->login_timeout
= cpu_to_le16(0);
8034 nv
->firmware_options_1
=
8035 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
8036 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
8037 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
8038 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
8039 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
8040 nv
->efi_parameters
= cpu_to_le32(0);
8041 nv
->reset_delay
= 5;
8042 nv
->max_luns_per_target
= cpu_to_le16(128);
8043 nv
->port_down_retry_count
= cpu_to_le16(30);
8044 nv
->link_down_timeout
= cpu_to_le16(180);
8045 nv
->enode_mac
[0] = 0x00;
8046 nv
->enode_mac
[1] = 0xC0;
8047 nv
->enode_mac
[2] = 0xDD;
8048 nv
->enode_mac
[3] = 0x04;
8049 nv
->enode_mac
[4] = 0x05;
8050 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
8055 if (IS_T10_PI_CAPABLE(ha
))
8056 nv
->frame_payload_size
&= ~7;
8058 qlt_81xx_config_nvram_stage1(vha
, nv
);
8060 /* Reset Initialization control block */
8061 memset(icb
, 0, ha
->init_cb_size
);
8063 /* Copy 1st segment. */
8064 dptr1
= (uint8_t *)icb
;
8065 dptr2
= (uint8_t *)&nv
->version
;
8066 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
8068 *dptr1
++ = *dptr2
++;
8070 icb
->login_retry_count
= nv
->login_retry_count
;
8072 /* Copy 2nd segment. */
8073 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
8074 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
8075 cnt
= (uint8_t *)&icb
->reserved_5
-
8076 (uint8_t *)&icb
->interrupt_delay_timer
;
8078 *dptr1
++ = *dptr2
++;
8080 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
8081 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8082 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
8083 icb
->enode_mac
[0] = 0x00;
8084 icb
->enode_mac
[1] = 0xC0;
8085 icb
->enode_mac
[2] = 0xDD;
8086 icb
->enode_mac
[3] = 0x04;
8087 icb
->enode_mac
[4] = 0x05;
8088 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
8091 /* Use extended-initialization control block. */
8092 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
8093 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
8095 * Setup driver NVRAM options.
8097 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
8100 qlt_81xx_config_nvram_stage2(vha
, icb
);
8102 /* Use alternate WWN? */
8103 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
8104 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
8105 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
8108 /* Prepare nodename */
8109 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
8111 * Firmware will apply the following mask if the nodename was
8114 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
8115 icb
->node_name
[0] &= 0xF0;
8118 /* Set host adapter parameters. */
8119 ha
->flags
.disable_risc_code_load
= 0;
8120 ha
->flags
.enable_lip_reset
= 0;
8121 ha
->flags
.enable_lip_full_login
=
8122 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
8123 ha
->flags
.enable_target_reset
=
8124 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
8125 ha
->flags
.enable_led_scheme
= 0;
8126 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
8128 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
8129 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
8131 /* save HBA serial number */
8132 ha
->serial0
= icb
->port_name
[5];
8133 ha
->serial1
= icb
->port_name
[6];
8134 ha
->serial2
= icb
->port_name
[7];
8135 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
8136 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
8138 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
8140 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
8142 /* Set minimum login_timeout to 4 seconds. */
8143 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
8144 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
8145 if (le16_to_cpu(nv
->login_timeout
) < 4)
8146 nv
->login_timeout
= cpu_to_le16(4);
8147 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
8149 /* Set minimum RATOV to 100 tenths of a second. */
8152 ha
->loop_reset_delay
= nv
->reset_delay
;
8154 /* Link Down Timeout = 0:
8156 * When Port Down timer expires we will start returning
8157 * I/O's to OS with "DID_NO_CONNECT".
8159 * Link Down Timeout != 0:
8161 * The driver waits for the link to come up after link down
8162 * before returning I/Os to OS with "DID_NO_CONNECT".
8164 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
8165 ha
->loop_down_abort_time
=
8166 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
8168 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
8169 ha
->loop_down_abort_time
=
8170 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
8173 /* Need enough time to try and get the port back. */
8174 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
8175 if (qlport_down_retry
)
8176 ha
->port_down_retry_count
= qlport_down_retry
;
8178 /* Set login_retry_count */
8179 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
8180 if (ha
->port_down_retry_count
==
8181 le16_to_cpu(nv
->port_down_retry_count
) &&
8182 ha
->port_down_retry_count
> 3)
8183 ha
->login_retry_count
= ha
->port_down_retry_count
;
8184 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
8185 ha
->login_retry_count
= ha
->port_down_retry_count
;
8186 if (ql2xloginretrycount
)
8187 ha
->login_retry_count
= ql2xloginretrycount
;
8189 /* if not running MSI-X we need handshaking on interrupts */
8190 if (!vha
->hw
->flags
.msix_enabled
&& (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)))
8191 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
8194 if (!vha
->flags
.init_done
) {
8195 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
8196 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
8197 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
8198 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
8200 icb
->firmware_options_2
&= cpu_to_le32(
8201 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
8202 vha
->flags
.process_response_queue
= 0;
8203 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
8204 ha
->zio_mode
= QLA_ZIO_MODE_6
;
8206 ql_log(ql_log_info
, vha
, 0x0075,
8207 "ZIO mode %d enabled; timer delay (%d us).\n",
8209 ha
->zio_timer
* 100);
8211 icb
->firmware_options_2
|= cpu_to_le32(
8212 (uint32_t)ha
->zio_mode
);
8213 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
8214 vha
->flags
.process_response_queue
= 1;
8217 /* enable RIDA Format2 */
8218 icb
->firmware_options_3
|= BIT_0
;
8220 /* N2N: driver will initiate Login instead of FW */
8221 icb
->firmware_options_3
|= BIT_8
;
8223 if (IS_QLA27XX(ha
)) {
8224 icb
->firmware_options_3
|= BIT_8
;
8225 ql_dbg(ql_log_info
, vha
, 0x0075,
8226 "Enabling direct connection.\n");
8230 ql_log(ql_log_warn
, vha
, 0x0076,
8231 "NVRAM configuration failed.\n");
8237 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
8240 struct qla_hw_data
*ha
= vha
->hw
;
8241 struct req_que
*req
= ha
->req_q_map
[0];
8242 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
8243 struct scsi_qla_host
*vp
;
8244 unsigned long flags
;
8246 status
= qla2x00_init_rings(vha
);
8248 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8249 ha
->flags
.chip_reset_done
= 1;
8251 status
= qla2x00_fw_ready(vha
);
8253 /* Issue a marker after FW becomes ready. */
8254 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
8255 vha
->flags
.online
= 1;
8256 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8259 /* if no cable then assume it's good */
8260 if ((vha
->device_flags
& DFLG_NO_CABLE
))
8265 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8267 if (!atomic_read(&vha
->loop_down_timer
)) {
8269 * Issue marker command only when we are going
8270 * to start the I/O .
8272 vha
->marker_needed
= 1;
8275 ha
->isp_ops
->enable_intrs(ha
);
8277 ha
->isp_abort_cnt
= 0;
8278 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
8280 /* Update the firmware version */
8281 status
= qla82xx_check_md_needed(vha
);
8284 ha
->flags
.fce_enabled
= 1;
8286 fce_calc_size(ha
->fce_bufs
));
8287 rval
= qla2x00_enable_fce_trace(vha
,
8288 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
8291 ql_log(ql_log_warn
, vha
, 0x8001,
8292 "Unable to reinitialize FCE (%d).\n",
8294 ha
->flags
.fce_enabled
= 0;
8299 memset(ha
->eft
, 0, EFT_SIZE
);
8300 rval
= qla2x00_enable_eft_trace(vha
,
8301 ha
->eft_dma
, EFT_NUM_BUFFERS
);
8303 ql_log(ql_log_warn
, vha
, 0x8010,
8304 "Unable to reinitialize EFT (%d).\n",
8311 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
8312 "qla82xx_restart_isp succeeded.\n");
8314 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8315 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
8317 atomic_inc(&vp
->vref_count
);
8318 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8320 qla2x00_vp_abort_isp(vp
);
8322 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8323 atomic_dec(&vp
->vref_count
);
8326 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8329 ql_log(ql_log_warn
, vha
, 0x8016,
8330 "qla82xx_restart_isp **** FAILED ****.\n");
8337 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
8339 struct qla_hw_data
*ha
= vha
->hw
;
8341 /* Hold status IOCBs until ABTS response received. */
8343 ha
->fw_options
[3] |= BIT_12
;
8345 /* Set Retry FLOGI in case of P2P connection */
8346 if (ha
->operating_mode
== P2P
) {
8347 ha
->fw_options
[2] |= BIT_3
;
8348 ql_dbg(ql_dbg_disc
, vha
, 0x2103,
8349 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8350 __func__
, ha
->fw_options
[2]);
8353 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8354 if (ql2xmvasynctoatio
) {
8355 if (qla_tgt_mode_enabled(vha
) ||
8356 qla_dual_mode_enabled(vha
))
8357 ha
->fw_options
[2] |= BIT_11
;
8359 ha
->fw_options
[2] &= ~BIT_11
;
8362 if (qla_tgt_mode_enabled(vha
) ||
8363 qla_dual_mode_enabled(vha
)) {
8364 /* FW auto send SCSI status during */
8365 ha
->fw_options
[1] |= BIT_8
;
8366 ha
->fw_options
[10] |= (u16
)SAM_STAT_BUSY
<< 8;
8368 /* FW perform Exchange validation */
8369 ha
->fw_options
[2] |= BIT_4
;
8371 ha
->fw_options
[1] &= ~BIT_8
;
8372 ha
->fw_options
[10] &= 0x00ff;
8374 ha
->fw_options
[2] &= ~BIT_4
;
8377 if (ql2xetsenable
) {
8378 /* Enable ETS Burst. */
8379 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
8380 ha
->fw_options
[2] |= BIT_9
;
8383 ql_dbg(ql_dbg_init
, vha
, 0x00e9,
8384 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8385 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
8386 ha
->fw_options
[3], vha
->host
->active_mode
);
8388 qla2x00_set_fw_options(vha
, ha
->fw_options
);
8392 * qla24xx_get_fcp_prio
8393 * Gets the fcp cmd priority value for the logged in port.
8394 * Looks for a match of the port descriptors within
8395 * each of the fcp prio config entries. If a match is found,
8396 * the tag (priority) value is returned.
8399 * vha = scsi host structure pointer.
8400 * fcport = port structure pointer.
8403 * non-zero (if found)
8410 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8413 uint8_t pid_match
, wwn_match
;
8415 uint32_t pid1
, pid2
;
8416 uint64_t wwn1
, wwn2
;
8417 struct qla_fcp_prio_entry
*pri_entry
;
8418 struct qla_hw_data
*ha
= vha
->hw
;
8420 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
8424 entries
= ha
->fcp_prio_cfg
->num_entries
;
8425 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
8427 for (i
= 0; i
< entries
; i
++) {
8428 pid_match
= wwn_match
= 0;
8430 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
8435 /* check source pid for a match */
8436 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
8437 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
8438 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
8439 if (pid1
== INVALID_PORT_ID
)
8441 else if (pid1
== pid2
)
8445 /* check destination pid for a match */
8446 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
8447 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
8448 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
8449 if (pid1
== INVALID_PORT_ID
)
8451 else if (pid1
== pid2
)
8455 /* check source WWN for a match */
8456 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
8457 wwn1
= wwn_to_u64(vha
->port_name
);
8458 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
8459 if (wwn2
== (uint64_t)-1)
8461 else if (wwn1
== wwn2
)
8465 /* check destination WWN for a match */
8466 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
8467 wwn1
= wwn_to_u64(fcport
->port_name
);
8468 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
8469 if (wwn2
== (uint64_t)-1)
8471 else if (wwn1
== wwn2
)
8475 if (pid_match
== 2 || wwn_match
== 2) {
8476 /* Found a matching entry */
8477 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
8478 priority
= pri_entry
->tag
;
8489 * qla24xx_update_fcport_fcp_prio
8490 * Activates fcp priority for the logged in fc port
8493 * vha = scsi host structure pointer.
8494 * fcp = port structure pointer.
8497 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8503 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8509 if (fcport
->port_type
!= FCT_TARGET
||
8510 fcport
->loop_id
== FC_NO_LOOP_ID
)
8511 return QLA_FUNCTION_FAILED
;
8513 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
8515 return QLA_FUNCTION_FAILED
;
8517 if (IS_P3P_TYPE(vha
->hw
)) {
8518 fcport
->fcp_prio
= priority
& 0xf;
8522 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
8523 if (ret
== QLA_SUCCESS
) {
8524 if (fcport
->fcp_prio
!= priority
)
8525 ql_dbg(ql_dbg_user
, vha
, 0x709e,
8526 "Updated FCP_CMND priority - value=%d loop_id=%d "
8527 "port_id=%02x%02x%02x.\n", priority
,
8528 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
8529 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
8530 fcport
->fcp_prio
= priority
& 0xf;
8532 ql_dbg(ql_dbg_user
, vha
, 0x704f,
8533 "Unable to update FCP_CMND priority - ret=0x%x for "
8534 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
8535 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
8536 fcport
->d_id
.b
.al_pa
);
8541 * qla24xx_update_all_fcp_prio
8542 * Activates fcp priority for all the logged in ports
8545 * ha = adapter block pointer.
8548 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8554 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
8559 ret
= QLA_FUNCTION_FAILED
;
8560 /* We need to set priority for all logged in ports */
8561 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
8562 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);
8567 struct qla_qpair
*qla2xxx_create_qpair(struct scsi_qla_host
*vha
, int qos
,
8568 int vp_idx
, bool startqp
)
8573 struct qla_hw_data
*ha
= vha
->hw
;
8574 uint16_t qpair_id
= 0;
8575 struct qla_qpair
*qpair
= NULL
;
8576 struct qla_msix_entry
*msix
;
8578 if (!(ha
->fw_attributes
& BIT_6
) || !ha
->flags
.msix_enabled
) {
8579 ql_log(ql_log_warn
, vha
, 0x00181,
8580 "FW/Driver is not multi-queue capable.\n");
8584 if (ql2xmqsupport
|| ql2xnvmeenable
) {
8585 qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
8586 if (qpair
== NULL
) {
8587 ql_log(ql_log_warn
, vha
, 0x0182,
8588 "Failed to allocate memory for queue pair.\n");
8591 memset(qpair
, 0, sizeof(struct qla_qpair
));
8593 qpair
->hw
= vha
->hw
;
8595 qpair
->qp_lock_ptr
= &qpair
->qp_lock
;
8596 spin_lock_init(&qpair
->qp_lock
);
8597 qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
8599 /* Assign available que pair id */
8600 mutex_lock(&ha
->mq_lock
);
8601 qpair_id
= find_first_zero_bit(ha
->qpair_qid_map
, ha
->max_qpairs
);
8602 if (ha
->num_qpairs
>= ha
->max_qpairs
) {
8603 mutex_unlock(&ha
->mq_lock
);
8604 ql_log(ql_log_warn
, vha
, 0x0183,
8605 "No resources to create additional q pair.\n");
8609 set_bit(qpair_id
, ha
->qpair_qid_map
);
8610 ha
->queue_pair_map
[qpair_id
] = qpair
;
8611 qpair
->id
= qpair_id
;
8612 qpair
->vp_idx
= vp_idx
;
8613 qpair
->fw_started
= ha
->flags
.fw_started
;
8614 INIT_LIST_HEAD(&qpair
->hints_list
);
8615 qpair
->chip_reset
= ha
->base_qpair
->chip_reset
;
8616 qpair
->enable_class_2
= ha
->base_qpair
->enable_class_2
;
8617 qpair
->enable_explicit_conf
=
8618 ha
->base_qpair
->enable_explicit_conf
;
8620 for (i
= 0; i
< ha
->msix_count
; i
++) {
8621 msix
= &ha
->msix_entries
[i
];
8625 ql_dbg(ql_dbg_multiq
, vha
, 0xc00f,
8626 "Vector %x selected for qpair\n", msix
->vector
);
8630 ql_log(ql_log_warn
, vha
, 0x0184,
8631 "Out of MSI-X vectors!.\n");
8635 qpair
->msix
->in_use
= 1;
8636 list_add_tail(&qpair
->qp_list_elem
, &vha
->qp_list
);
8637 qpair
->pdev
= ha
->pdev
;
8638 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
))
8639 qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
8641 mutex_unlock(&ha
->mq_lock
);
8643 /* Create response queue first */
8644 rsp_id
= qla25xx_create_rsp_que(ha
, 0, 0, 0, qpair
, startqp
);
8646 ql_log(ql_log_warn
, vha
, 0x0185,
8647 "Failed to create response queue.\n");
8651 qpair
->rsp
= ha
->rsp_q_map
[rsp_id
];
8653 /* Create request queue */
8654 req_id
= qla25xx_create_req_que(ha
, 0, vp_idx
, 0, rsp_id
, qos
,
8657 ql_log(ql_log_warn
, vha
, 0x0186,
8658 "Failed to create request queue.\n");
8662 qpair
->req
= ha
->req_q_map
[req_id
];
8663 qpair
->rsp
->req
= qpair
->req
;
8664 qpair
->rsp
->qpair
= qpair
;
8665 /* init qpair to this cpu. Will adjust at run time. */
8666 qla_cpu_update(qpair
, smp_processor_id());
8668 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
8669 if (ha
->fw_attributes
& BIT_4
)
8670 qpair
->difdix_supported
= 1;
8673 qpair
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
8674 if (!qpair
->srb_mempool
) {
8675 ql_log(ql_log_warn
, vha
, 0xd036,
8676 "Failed to create srb mempool for qpair %d\n",
8681 /* Mark as online */
8684 if (!vha
->flags
.qpairs_available
)
8685 vha
->flags
.qpairs_available
= 1;
8687 ql_dbg(ql_dbg_multiq
, vha
, 0xc00d,
8688 "Request/Response queue pair created, id %d\n",
8690 ql_dbg(ql_dbg_init
, vha
, 0x0187,
8691 "Request/Response queue pair created, id %d\n",
8698 qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8700 mutex_lock(&ha
->mq_lock
);
8701 qpair
->msix
->in_use
= 0;
8702 list_del(&qpair
->qp_list_elem
);
8703 if (list_empty(&vha
->qp_list
))
8704 vha
->flags
.qpairs_available
= 0;
8706 ha
->queue_pair_map
[qpair_id
] = NULL
;
8707 clear_bit(qpair_id
, ha
->qpair_qid_map
);
8709 mutex_unlock(&ha
->mq_lock
);
8715 int qla2xxx_delete_qpair(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
)
8717 int ret
= QLA_FUNCTION_FAILED
;
8718 struct qla_hw_data
*ha
= qpair
->hw
;
8720 qpair
->delete_in_progress
= 1;
8721 while (atomic_read(&qpair
->ref_count
))
8724 ret
= qla25xx_delete_req_que(vha
, qpair
->req
);
8725 if (ret
!= QLA_SUCCESS
)
8728 ret
= qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8729 if (ret
!= QLA_SUCCESS
)
8732 mutex_lock(&ha
->mq_lock
);
8733 ha
->queue_pair_map
[qpair
->id
] = NULL
;
8734 clear_bit(qpair
->id
, ha
->qpair_qid_map
);
8736 list_del(&qpair
->qp_list_elem
);
8737 if (list_empty(&vha
->qp_list
)) {
8738 vha
->flags
.qpairs_available
= 0;
8739 vha
->flags
.qpairs_req_created
= 0;
8740 vha
->flags
.qpairs_rsp_created
= 0;
8742 mempool_destroy(qpair
->srb_mempool
);
8744 mutex_unlock(&ha
->mq_lock
);