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
;
55 struct qla_hw_data
*ha
= sp
->vha
->hw
;
57 WARN_ON_ONCE(irqs_disabled());
58 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
60 req
->outstanding_cmds
[sp
->handle
] = NULL
;
61 iocb
= &sp
->u
.iocb_cmd
;
62 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
67 qla2x00_sp_free(void *ptr
)
70 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
72 del_timer(&iocb
->timer
);
76 /* Asynchronous Login/Logout Routines -------------------------------------- */
79 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
82 struct qla_hw_data
*ha
= vha
->hw
;
84 /* Firmware should use switch negotiated r_a_tov for timeout. */
85 tmo
= ha
->r_a_tov
/ 10 * 2;
87 tmo
= FX00_DEF_RATOV
* 2;
88 } else if (!IS_FWI2_CAPABLE(ha
)) {
90 * Except for earlier ISPs where the timeout is seeded from the
91 * initialization control block.
93 tmo
= ha
->login_timeout
;
99 qla2x00_async_iocb_timeout(void *data
)
102 fc_port_t
*fcport
= sp
->fcport
;
103 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
108 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
109 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
110 sp
->name
, sp
->handle
, fcport
->d_id
.b24
, fcport
->port_name
);
112 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
114 pr_info("Async-%s timeout - hdl=%x.\n",
115 sp
->name
, sp
->handle
);
120 rc
= qla24xx_async_abort_cmd(sp
, false);
122 /* Retry as needed. */
123 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
124 lio
->u
.logio
.data
[1] =
125 lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
126 QLA_LOGIO_LOGIN_RETRIED
: 0;
127 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
128 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
;
130 if (sp
->qpair
->req
->outstanding_cmds
[h
] ==
132 sp
->qpair
->req
->outstanding_cmds
[h
] =
137 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
138 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
142 case SRB_CT_PTHRU_CMD
:
148 rc
= qla24xx_async_abort_cmd(sp
, false);
150 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
151 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
;
153 if (sp
->qpair
->req
->outstanding_cmds
[h
] ==
155 sp
->qpair
->req
->outstanding_cmds
[h
] =
160 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
161 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
168 qla2x00_async_login_sp_done(void *ptr
, int res
)
171 struct scsi_qla_host
*vha
= sp
->vha
;
172 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
175 ql_dbg(ql_dbg_disc
, vha
, 0x20dd,
176 "%s %8phC res %d \n", __func__
, sp
->fcport
->port_name
, res
);
178 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
180 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
181 memset(&ea
, 0, sizeof(ea
));
182 ea
.event
= FCME_PLOGI_DONE
;
183 ea
.fcport
= sp
->fcport
;
184 ea
.data
[0] = lio
->u
.logio
.data
[0];
185 ea
.data
[1] = lio
->u
.logio
.data
[1];
186 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
187 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
189 qla2x00_fcport_event_handler(vha
, &ea
);
196 fcport_is_smaller(fc_port_t
*fcport
)
198 if (wwn_to_u64(fcport
->port_name
) <
199 wwn_to_u64(fcport
->vha
->port_name
))
206 fcport_is_bigger(fc_port_t
*fcport
)
208 return !fcport_is_smaller(fcport
);
212 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
216 struct srb_iocb
*lio
;
217 int rval
= QLA_FUNCTION_FAILED
;
219 if (!vha
->flags
.online
)
222 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
226 fcport
->flags
|= FCF_ASYNC_SENT
;
227 fcport
->logout_completed
= 0;
229 fcport
->disc_state
= DSC_LOGIN_PEND
;
230 sp
->type
= SRB_LOGIN_CMD
;
232 sp
->gen1
= fcport
->rscn_gen
;
233 sp
->gen2
= fcport
->login_gen
;
235 lio
= &sp
->u
.iocb_cmd
;
236 lio
->timeout
= qla2x00_async_iocb_timeout
;
237 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
239 sp
->done
= qla2x00_async_login_sp_done
;
240 if (N2N_TOPO(fcport
->vha
->hw
) && fcport_is_bigger(fcport
))
241 lio
->u
.logio
.flags
|= SRB_LOGIN_PRLI_ONLY
;
243 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
245 if (fcport
->fc4f_nvme
)
246 lio
->u
.logio
.flags
|= SRB_LOGIN_SKIP_PRLI
;
248 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
249 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
250 "retries=%d.\n", fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
251 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
252 fcport
->login_retry
);
254 rval
= qla2x00_start_sp(sp
);
255 if (rval
!= QLA_SUCCESS
) {
256 fcport
->flags
|= FCF_LOGIN_NEEDED
;
257 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
265 fcport
->flags
&= ~FCF_ASYNC_SENT
;
267 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
272 qla2x00_async_logout_sp_done(void *ptr
, int res
)
276 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
277 sp
->fcport
->login_gen
++;
278 qlt_logo_completion_handler(sp
->fcport
, res
);
283 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
286 struct srb_iocb
*lio
;
287 int rval
= QLA_FUNCTION_FAILED
;
289 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
292 fcport
->flags
|= FCF_ASYNC_SENT
;
293 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
297 sp
->type
= SRB_LOGOUT_CMD
;
300 lio
= &sp
->u
.iocb_cmd
;
301 lio
->timeout
= qla2x00_async_iocb_timeout
;
302 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
304 sp
->done
= qla2x00_async_logout_sp_done
;
306 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
307 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
308 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
309 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
312 rval
= qla2x00_start_sp(sp
);
313 if (rval
!= QLA_SUCCESS
)
320 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
325 qla2x00_async_prlo_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
328 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
329 /* Don't re-login in target mode */
330 if (!fcport
->tgt_session
)
331 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
332 qlt_logo_completion_handler(fcport
, data
[0]);
336 qla2x00_async_prlo_sp_done(void *s
, int res
)
338 srb_t
*sp
= (srb_t
*)s
;
339 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
340 struct scsi_qla_host
*vha
= sp
->vha
;
342 sp
->fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
343 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
344 qla2x00_post_async_prlo_done_work(sp
->fcport
->vha
, sp
->fcport
,
350 qla2x00_async_prlo(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
353 struct srb_iocb
*lio
;
356 rval
= QLA_FUNCTION_FAILED
;
357 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
361 sp
->type
= SRB_PRLO_CMD
;
364 lio
= &sp
->u
.iocb_cmd
;
365 lio
->timeout
= qla2x00_async_iocb_timeout
;
366 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
368 sp
->done
= qla2x00_async_prlo_sp_done
;
370 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
371 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
372 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
373 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
375 rval
= qla2x00_start_sp(sp
);
376 if (rval
!= QLA_SUCCESS
)
384 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
389 void qla24xx_handle_adisc_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
391 struct fc_port
*fcport
= ea
->fcport
;
393 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
394 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
395 __func__
, fcport
->port_name
, fcport
->disc_state
,
396 fcport
->fw_login_state
, ea
->rc
, fcport
->login_gen
, ea
->sp
->gen2
,
397 fcport
->rscn_gen
, ea
->sp
->gen1
, fcport
->loop_id
);
399 if (ea
->data
[0] != MBS_COMMAND_COMPLETE
) {
400 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
401 "%s %8phC: adisc fail: post delete\n",
402 __func__
, ea
->fcport
->port_name
);
403 /* deleted = 0 & logout_on_delete = force fw cleanup */
405 fcport
->logout_on_delete
= 1;
406 qlt_schedule_sess_for_deletion(ea
->fcport
);
410 if (ea
->fcport
->disc_state
== DSC_DELETE_PEND
)
413 if (ea
->sp
->gen2
!= ea
->fcport
->login_gen
) {
414 /* target side must have changed it. */
415 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
416 "%s %8phC generation changed\n",
417 __func__
, ea
->fcport
->port_name
);
419 } else if (ea
->sp
->gen1
!= ea
->fcport
->rscn_gen
) {
420 qla_rscn_replay(fcport
);
421 qlt_schedule_sess_for_deletion(fcport
);
425 __qla24xx_handle_gpdb_event(vha
, ea
);
428 static int qla_post_els_plogi_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
430 struct qla_work_evt
*e
;
432 e
= qla2x00_alloc_work(vha
, QLA_EVT_ELS_PLOGI
);
434 return QLA_FUNCTION_FAILED
;
436 e
->u
.fcport
.fcport
= fcport
;
437 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
438 return qla2x00_post_work(vha
, e
);
442 qla2x00_async_adisc_sp_done(void *ptr
, int res
)
445 struct scsi_qla_host
*vha
= sp
->vha
;
447 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
449 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
450 "Async done-%s res %x %8phC\n",
451 sp
->name
, res
, sp
->fcport
->port_name
);
453 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
455 memset(&ea
, 0, sizeof(ea
));
456 ea
.event
= FCME_ADISC_DONE
;
458 ea
.data
[0] = lio
->u
.logio
.data
[0];
459 ea
.data
[1] = lio
->u
.logio
.data
[1];
460 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
461 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
462 ea
.fcport
= sp
->fcport
;
465 qla2x00_fcport_event_handler(vha
, &ea
);
471 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
475 struct srb_iocb
*lio
;
476 int rval
= QLA_FUNCTION_FAILED
;
478 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
481 fcport
->flags
|= FCF_ASYNC_SENT
;
482 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
486 sp
->type
= SRB_ADISC_CMD
;
489 lio
= &sp
->u
.iocb_cmd
;
490 lio
->timeout
= qla2x00_async_iocb_timeout
;
491 sp
->gen1
= fcport
->rscn_gen
;
492 sp
->gen2
= fcport
->login_gen
;
493 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
495 sp
->done
= qla2x00_async_adisc_sp_done
;
496 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
497 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
499 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
500 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
501 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
, fcport
->port_name
);
503 rval
= qla2x00_start_sp(sp
);
504 if (rval
!= QLA_SUCCESS
)
512 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
513 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
517 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t
*vha
,
518 struct event_arg
*ea
)
520 fc_port_t
*fcport
, *conflict_fcport
;
521 struct get_name_list_extended
*e
;
522 u16 i
, n
, found
= 0, loop_id
;
526 u8 current_login_state
;
529 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
530 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
531 __func__
, fcport
->port_name
, fcport
->disc_state
,
532 fcport
->fw_login_state
, ea
->rc
,
533 fcport
->login_gen
, fcport
->last_login_gen
,
534 fcport
->rscn_gen
, fcport
->last_rscn_gen
, vha
->loop_id
);
536 if (fcport
->disc_state
== DSC_DELETE_PEND
)
539 if (ea
->rc
) { /* rval */
540 if (fcport
->login_retry
== 0) {
541 ql_dbg(ql_dbg_disc
, vha
, 0x20de,
542 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
543 fcport
->port_name
, fcport
->login_retry
);
548 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
549 qla_rscn_replay(fcport
);
550 qlt_schedule_sess_for_deletion(fcport
);
552 } else if (fcport
->last_login_gen
!= fcport
->login_gen
) {
553 ql_dbg(ql_dbg_disc
, vha
, 0x20e0,
554 "%s %8phC login gen changed\n",
555 __func__
, fcport
->port_name
);
559 n
= ea
->data
[0] / sizeof(struct get_name_list_extended
);
561 ql_dbg(ql_dbg_disc
, vha
, 0x20e1,
562 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
563 __func__
, __LINE__
, fcport
->port_name
, n
,
564 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
565 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
);
567 for (i
= 0; i
< n
; i
++) {
569 wwn
= wwn_to_u64(e
->port_name
);
570 id
.b
.domain
= e
->port_id
[2];
571 id
.b
.area
= e
->port_id
[1];
572 id
.b
.al_pa
= e
->port_id
[0];
575 if (memcmp((u8
*)&wwn
, fcport
->port_name
, WWN_SIZE
))
578 if (IS_SW_RESV_ADDR(id
))
583 loop_id
= le16_to_cpu(e
->nport_handle
);
584 loop_id
= (loop_id
& 0x7fff);
585 if (fcport
->fc4f_nvme
)
586 current_login_state
= e
->current_login_state
>> 4;
588 current_login_state
= e
->current_login_state
& 0xf;
591 ql_dbg(ql_dbg_disc
, vha
, 0x20e2,
592 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
593 __func__
, fcport
->port_name
,
594 e
->current_login_state
, fcport
->fw_login_state
,
595 fcport
->fc4f_nvme
, id
.b
.domain
, id
.b
.area
, id
.b
.al_pa
,
596 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
597 fcport
->d_id
.b
.al_pa
, loop_id
, fcport
->loop_id
);
599 switch (fcport
->disc_state
) {
600 case DSC_DELETE_PEND
:
604 if ((id
.b24
!= fcport
->d_id
.b24
&&
606 (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
607 fcport
->loop_id
!= loop_id
)) {
608 ql_dbg(ql_dbg_disc
, vha
, 0x20e3,
609 "%s %d %8phC post del sess\n",
610 __func__
, __LINE__
, fcport
->port_name
);
611 qlt_schedule_sess_for_deletion(fcport
);
617 fcport
->loop_id
= loop_id
;
619 wwn
= wwn_to_u64(fcport
->port_name
);
620 qlt_find_sess_invalidate_other(vha
, wwn
,
621 id
, loop_id
, &conflict_fcport
);
623 if (conflict_fcport
) {
625 * Another share fcport share the same loop_id &
626 * nport id. Conflict fcport needs to finish
627 * cleanup before this fcport can proceed to login.
629 conflict_fcport
->conflict
= fcport
;
630 fcport
->login_pause
= 1;
633 switch (vha
->hw
->current_topology
) {
635 switch (current_login_state
) {
636 case DSC_LS_PRLI_COMP
:
637 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
,
638 vha
, 0x20e4, "%s %d %8phC post gpdb\n",
639 __func__
, __LINE__
, fcport
->port_name
);
641 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
642 fcport
->port_type
= FCT_INITIATOR
;
644 fcport
->port_type
= FCT_TARGET
;
645 data
[0] = data
[1] = 0;
646 qla2x00_post_async_adisc_work(vha
, fcport
,
649 case DSC_LS_PORT_UNAVAIL
:
651 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
652 qla2x00_find_new_loop_id(vha
, fcport
);
653 fcport
->fw_login_state
=
656 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
657 "%s %d %8phC\n", __func__
, __LINE__
,
659 qla24xx_fcport_handle_login(vha
, fcport
);
664 fcport
->fw_login_state
= current_login_state
;
666 switch (current_login_state
) {
667 case DSC_LS_PRLI_COMP
:
668 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
669 fcport
->port_type
= FCT_INITIATOR
;
671 fcport
->port_type
= FCT_TARGET
;
673 data
[0] = data
[1] = 0;
674 qla2x00_post_async_adisc_work(vha
, fcport
,
677 case DSC_LS_PLOGI_COMP
:
678 if (fcport_is_bigger(fcport
)) {
679 /* local adapter is smaller */
680 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
681 qla2x00_clear_loop_id(fcport
);
683 fcport
->loop_id
= loop_id
;
684 qla24xx_fcport_handle_login(vha
,
690 if (fcport_is_smaller(fcport
)) {
691 /* local adapter is bigger */
692 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
693 qla2x00_clear_loop_id(fcport
);
695 fcport
->loop_id
= loop_id
;
696 qla24xx_fcport_handle_login(vha
,
702 } /* switch (ha->current_topology) */
706 switch (vha
->hw
->current_topology
) {
709 for (i
= 0; i
< n
; i
++) {
711 id
.b
.domain
= e
->port_id
[0];
712 id
.b
.area
= e
->port_id
[1];
713 id
.b
.al_pa
= e
->port_id
[2];
715 loop_id
= le16_to_cpu(e
->nport_handle
);
717 if (fcport
->d_id
.b24
== id
.b24
) {
719 qla2x00_find_fcport_by_wwpn(vha
,
721 if (conflict_fcport
) {
722 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
,
724 "%s %d %8phC post del sess\n",
726 conflict_fcport
->port_name
);
727 qlt_schedule_sess_for_deletion
732 * FW already picked this loop id for
735 if (fcport
->loop_id
== loop_id
)
736 fcport
->loop_id
= FC_NO_LOOP_ID
;
738 qla24xx_fcport_handle_login(vha
, fcport
);
741 fcport
->disc_state
= DSC_DELETED
;
742 if (time_after_eq(jiffies
, fcport
->dm_login_expire
)) {
743 if (fcport
->n2n_link_reset_cnt
< 2) {
744 fcport
->n2n_link_reset_cnt
++;
746 * remote port is not sending PLOGI.
747 * Reset link to kick start his state
750 set_bit(N2N_LINK_RESET
,
753 if (fcport
->n2n_chip_reset
< 1) {
754 ql_log(ql_log_info
, vha
, 0x705d,
755 "Chip reset to bring laser down");
756 set_bit(ISP_ABORT_NEEDED
,
758 fcport
->n2n_chip_reset
++;
760 ql_log(ql_log_info
, vha
, 0x705d,
761 "Remote port %8ph is not coming back\n",
763 fcport
->scan_state
= 0;
766 qla2xxx_wake_dpc(vha
);
769 * report port suppose to do PLOGI. Give him
770 * more time. FW will catch it.
772 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
782 qla24xx_async_gnl_sp_done(void *s
, int res
)
785 struct scsi_qla_host
*vha
= sp
->vha
;
787 struct fc_port
*fcport
= NULL
, *tf
;
788 u16 i
, n
= 0, loop_id
;
790 struct get_name_list_extended
*e
;
795 ql_dbg(ql_dbg_disc
, vha
, 0x20e7,
796 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
797 sp
->name
, res
, sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1],
798 sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[2]);
800 if (res
== QLA_FUNCTION_TIMEOUT
)
803 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
|FCF_ASYNC_ACTIVE
);
804 memset(&ea
, 0, sizeof(ea
));
807 ea
.event
= FCME_GNL_DONE
;
809 if (sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] >=
810 sizeof(struct get_name_list_extended
)) {
811 n
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] /
812 sizeof(struct get_name_list_extended
);
813 ea
.data
[0] = sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1]; /* amnt xfered */
816 for (i
= 0; i
< n
; i
++) {
818 loop_id
= le16_to_cpu(e
->nport_handle
);
819 /* mask out reserve bit */
820 loop_id
= (loop_id
& 0x7fff);
821 set_bit(loop_id
, vha
->hw
->loop_id_map
);
822 wwn
= wwn_to_u64(e
->port_name
);
824 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0x20e8,
825 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
826 __func__
, (void *)&wwn
, e
->port_id
[2], e
->port_id
[1],
827 e
->port_id
[0], e
->current_login_state
, e
->last_login_state
,
831 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
835 if (!list_empty(&vha
->gnl
.fcports
))
836 list_splice_init(&vha
->gnl
.fcports
, &h
);
837 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
839 list_for_each_entry_safe(fcport
, tf
, &h
, gnl_entry
) {
840 list_del_init(&fcport
->gnl_entry
);
841 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
842 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
843 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
846 qla2x00_fcport_event_handler(vha
, &ea
);
849 /* create new fcport if fw has knowledge of new sessions */
850 for (i
= 0; i
< n
; i
++) {
855 wwn
= wwn_to_u64(e
->port_name
);
858 list_for_each_entry_safe(fcport
, tf
, &vha
->vp_fcports
, list
) {
859 if (!memcmp((u8
*)&wwn
, fcport
->port_name
,
866 id
.b
.domain
= e
->port_id
[2];
867 id
.b
.area
= e
->port_id
[1];
868 id
.b
.al_pa
= e
->port_id
[0];
871 if (!found
&& wwn
&& !IS_SW_RESV_ADDR(id
)) {
872 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
873 "%s %d %8phC %06x post new sess\n",
874 __func__
, __LINE__
, (u8
*)&wwn
, id
.b24
);
875 wwnn
= wwn_to_u64(e
->node_name
);
876 qla24xx_post_newsess_work(vha
, &id
, (u8
*)&wwn
,
877 (u8
*)&wwnn
, NULL
, FC4_TYPE_UNKNOWN
);
881 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
883 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
888 int qla24xx_async_gnl(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
891 struct srb_iocb
*mbx
;
892 int rval
= QLA_FUNCTION_FAILED
;
896 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
899 ql_dbg(ql_dbg_disc
, vha
, 0x20d9,
900 "Async-gnlist WWPN %8phC \n", fcport
->port_name
);
902 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
903 fcport
->flags
|= FCF_ASYNC_SENT
;
904 fcport
->disc_state
= DSC_GNL
;
905 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
906 fcport
->last_login_gen
= fcport
->login_gen
;
908 list_add_tail(&fcport
->gnl_entry
, &vha
->gnl
.fcports
);
910 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
914 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
916 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
920 sp
->type
= SRB_MB_IOCB
;
922 sp
->gen1
= fcport
->rscn_gen
;
923 sp
->gen2
= fcport
->login_gen
;
925 mbx
= &sp
->u
.iocb_cmd
;
926 mbx
->timeout
= qla2x00_async_iocb_timeout
;
927 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
929 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
930 mb
[0] = MBC_PORT_NODE_NAME_LIST
;
931 mb
[1] = BIT_2
| BIT_3
;
932 mb
[2] = MSW(vha
->gnl
.ldma
);
933 mb
[3] = LSW(vha
->gnl
.ldma
);
934 mb
[6] = MSW(MSD(vha
->gnl
.ldma
));
935 mb
[7] = LSW(MSD(vha
->gnl
.ldma
));
936 mb
[8] = vha
->gnl
.size
;
939 sp
->done
= qla24xx_async_gnl_sp_done
;
941 ql_dbg(ql_dbg_disc
, vha
, 0x20da,
942 "Async-%s - OUT WWPN %8phC hndl %x\n",
943 sp
->name
, fcport
->port_name
, sp
->handle
);
945 rval
= qla2x00_start_sp(sp
);
946 if (rval
!= QLA_SUCCESS
)
953 fcport
->flags
&= ~FCF_ASYNC_SENT
;
958 int qla24xx_post_gnl_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
960 struct qla_work_evt
*e
;
962 e
= qla2x00_alloc_work(vha
, QLA_EVT_GNL
);
964 return QLA_FUNCTION_FAILED
;
966 e
->u
.fcport
.fcport
= fcport
;
967 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
968 return qla2x00_post_work(vha
, e
);
972 void qla24xx_async_gpdb_sp_done(void *s
, int res
)
975 struct scsi_qla_host
*vha
= sp
->vha
;
976 struct qla_hw_data
*ha
= vha
->hw
;
977 fc_port_t
*fcport
= sp
->fcport
;
978 u16
*mb
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
;
981 ql_dbg(ql_dbg_disc
, vha
, 0x20db,
982 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
983 sp
->name
, res
, fcport
->port_name
, mb
[1], mb
[2]);
985 if (res
== QLA_FUNCTION_TIMEOUT
) {
986 dma_pool_free(sp
->vha
->hw
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
987 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
991 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
992 memset(&ea
, 0, sizeof(ea
));
993 ea
.event
= FCME_GPDB_DONE
;
997 qla2x00_fcport_event_handler(vha
, &ea
);
999 dma_pool_free(ha
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
1000 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
1005 static int qla24xx_post_prli_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1007 struct qla_work_evt
*e
;
1009 e
= qla2x00_alloc_work(vha
, QLA_EVT_PRLI
);
1011 return QLA_FUNCTION_FAILED
;
1013 e
->u
.fcport
.fcport
= fcport
;
1015 return qla2x00_post_work(vha
, e
);
1019 qla2x00_async_prli_sp_done(void *ptr
, int res
)
1022 struct scsi_qla_host
*vha
= sp
->vha
;
1023 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
1024 struct event_arg ea
;
1026 ql_dbg(ql_dbg_disc
, vha
, 0x2129,
1027 "%s %8phC res %d \n", __func__
,
1028 sp
->fcport
->port_name
, res
);
1030 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1032 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
1033 memset(&ea
, 0, sizeof(ea
));
1034 ea
.event
= FCME_PRLI_DONE
;
1035 ea
.fcport
= sp
->fcport
;
1036 ea
.data
[0] = lio
->u
.logio
.data
[0];
1037 ea
.data
[1] = lio
->u
.logio
.data
[1];
1038 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
1039 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
1042 qla2x00_fcport_event_handler(vha
, &ea
);
1049 qla24xx_async_prli(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1052 struct srb_iocb
*lio
;
1053 int rval
= QLA_FUNCTION_FAILED
;
1055 if (!vha
->flags
.online
)
1058 if (fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
||
1059 fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)
1062 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1066 fcport
->flags
|= FCF_ASYNC_SENT
;
1067 fcport
->logout_completed
= 0;
1069 sp
->type
= SRB_PRLI_CMD
;
1072 lio
= &sp
->u
.iocb_cmd
;
1073 lio
->timeout
= qla2x00_async_iocb_timeout
;
1074 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
1076 sp
->done
= qla2x00_async_prli_sp_done
;
1077 lio
->u
.logio
.flags
= 0;
1079 if (fcport
->fc4f_nvme
)
1080 lio
->u
.logio
.flags
|= SRB_LOGIN_NVME_PRLI
;
1082 ql_dbg(ql_dbg_disc
, vha
, 0x211b,
1083 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1084 fcport
->port_name
, sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
,
1085 fcport
->login_retry
, fcport
->fc4f_nvme
? "nvme" : "fc");
1087 rval
= qla2x00_start_sp(sp
);
1088 if (rval
!= QLA_SUCCESS
) {
1089 fcport
->flags
|= FCF_LOGIN_NEEDED
;
1090 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1098 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1102 int qla24xx_post_gpdb_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
1104 struct qla_work_evt
*e
;
1106 e
= qla2x00_alloc_work(vha
, QLA_EVT_GPDB
);
1108 return QLA_FUNCTION_FAILED
;
1110 e
->u
.fcport
.fcport
= fcport
;
1111 e
->u
.fcport
.opt
= opt
;
1112 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
1113 return qla2x00_post_work(vha
, e
);
1116 int qla24xx_async_gpdb(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
1119 struct srb_iocb
*mbx
;
1120 int rval
= QLA_FUNCTION_FAILED
;
1123 struct port_database_24xx
*pd
;
1124 struct qla_hw_data
*ha
= vha
->hw
;
1126 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
1129 fcport
->disc_state
= DSC_GPDB
;
1131 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1135 fcport
->flags
|= FCF_ASYNC_SENT
;
1136 sp
->type
= SRB_MB_IOCB
;
1138 sp
->gen1
= fcport
->rscn_gen
;
1139 sp
->gen2
= fcport
->login_gen
;
1141 mbx
= &sp
->u
.iocb_cmd
;
1142 mbx
->timeout
= qla2x00_async_iocb_timeout
;
1143 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
1145 pd
= dma_pool_zalloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
1147 ql_log(ql_log_warn
, vha
, 0xd043,
1148 "Failed to allocate port database structure.\n");
1152 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
1153 mb
[0] = MBC_GET_PORT_DATABASE
;
1154 mb
[1] = fcport
->loop_id
;
1155 mb
[2] = MSW(pd_dma
);
1156 mb
[3] = LSW(pd_dma
);
1157 mb
[6] = MSW(MSD(pd_dma
));
1158 mb
[7] = LSW(MSD(pd_dma
));
1159 mb
[9] = vha
->vp_idx
;
1162 mbx
->u
.mbx
.in
= (void *)pd
;
1163 mbx
->u
.mbx
.in_dma
= pd_dma
;
1165 sp
->done
= qla24xx_async_gpdb_sp_done
;
1167 ql_dbg(ql_dbg_disc
, vha
, 0x20dc,
1168 "Async-%s %8phC hndl %x opt %x\n",
1169 sp
->name
, fcport
->port_name
, sp
->handle
, opt
);
1171 rval
= qla2x00_start_sp(sp
);
1172 if (rval
!= QLA_SUCCESS
)
1178 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1181 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1183 qla24xx_post_gpdb_work(vha
, fcport
, opt
);
1188 void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1190 unsigned long flags
;
1192 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1193 ea
->fcport
->login_gen
++;
1194 ea
->fcport
->deleted
= 0;
1195 ea
->fcport
->logout_on_delete
= 1;
1197 if (!ea
->fcport
->login_succ
&& !IS_SW_RESV_ADDR(ea
->fcport
->d_id
)) {
1198 vha
->fcport_count
++;
1199 ea
->fcport
->login_succ
= 1;
1201 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1202 qla24xx_sched_upd_fcport(ea
->fcport
);
1203 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1204 } else if (ea
->fcport
->login_succ
) {
1206 * We have an existing session. A late RSCN delivery
1207 * must have triggered the session to be re-validate.
1208 * Session is still valid.
1210 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1211 "%s %d %8phC session revalidate success\n",
1212 __func__
, __LINE__
, ea
->fcport
->port_name
);
1213 ea
->fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
1215 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1219 void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1221 fc_port_t
*fcport
= ea
->fcport
;
1222 struct port_database_24xx
*pd
;
1223 struct srb
*sp
= ea
->sp
;
1226 pd
= (struct port_database_24xx
*)sp
->u
.iocb_cmd
.u
.mbx
.in
;
1228 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1230 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
1231 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__
, fcport
->port_name
,
1232 fcport
->disc_state
, pd
->current_login_state
, fcport
->fc4f_nvme
,
1235 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1238 if (fcport
->fc4f_nvme
)
1239 ls
= pd
->current_login_state
>> 4;
1241 ls
= pd
->current_login_state
& 0xf;
1243 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1244 /* target side must have changed it. */
1246 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1247 "%s %8phC generation changed\n",
1248 __func__
, fcport
->port_name
);
1250 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1251 qla_rscn_replay(fcport
);
1252 qlt_schedule_sess_for_deletion(fcport
);
1257 case PDS_PRLI_COMPLETE
:
1258 __qla24xx_parse_gpdb(vha
, fcport
, pd
);
1260 case PDS_PLOGI_PENDING
:
1261 case PDS_PLOGI_COMPLETE
:
1262 case PDS_PRLI_PENDING
:
1263 case PDS_PRLI2_PENDING
:
1264 /* Set discovery state back to GNL to Relogin attempt */
1265 if (qla_dual_mode_enabled(vha
) ||
1266 qla_ini_mode_enabled(vha
)) {
1267 fcport
->disc_state
= DSC_GNL
;
1268 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1271 case PDS_LOGO_PENDING
:
1272 case PDS_PORT_UNAVAILABLE
:
1274 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC post del sess\n",
1275 __func__
, __LINE__
, fcport
->port_name
);
1276 qlt_schedule_sess_for_deletion(fcport
);
1279 __qla24xx_handle_gpdb_event(vha
, ea
);
1282 static void qla_chk_n2n_b4_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1287 if (qla_tgt_mode_enabled(vha
))
1290 if (qla_dual_mode_enabled(vha
)) {
1291 if (N2N_TOPO(vha
->hw
)) {
1294 mywwn
= wwn_to_u64(vha
->port_name
);
1295 wwn
= wwn_to_u64(fcport
->port_name
);
1298 else if ((fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1299 && time_after_eq(jiffies
,
1300 fcport
->plogi_nack_done_deadline
))
1306 /* initiator mode */
1310 if (login
&& fcport
->login_retry
) {
1311 fcport
->login_retry
--;
1312 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1313 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1314 rc
= qla2x00_find_new_loop_id(vha
, fcport
);
1316 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
1317 "%s %d %8phC post del sess - out of loopid\n",
1318 __func__
, __LINE__
, fcport
->port_name
);
1319 fcport
->scan_state
= 0;
1320 qlt_schedule_sess_for_deletion(fcport
);
1324 ql_dbg(ql_dbg_disc
, vha
, 0x20bf,
1325 "%s %d %8phC post login\n",
1326 __func__
, __LINE__
, fcport
->port_name
);
1327 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
1331 int qla24xx_fcport_handle_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1337 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0x20d8,
1338 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1339 __func__
, fcport
->port_name
, fcport
->disc_state
,
1340 fcport
->fw_login_state
, fcport
->login_pause
, fcport
->flags
,
1341 fcport
->conflict
, fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1342 fcport
->login_gen
, fcport
->loop_id
, fcport
->scan_state
);
1344 if (fcport
->scan_state
!= QLA_FCPORT_FOUND
)
1347 if ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
1348 ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1349 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)))
1352 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1353 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1354 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1359 /* for pure Target Mode. Login will not be initiated */
1360 if (vha
->host
->active_mode
== MODE_TARGET
)
1363 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1364 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1368 switch (fcport
->disc_state
) {
1370 wwn
= wwn_to_u64(fcport
->node_name
);
1371 switch (vha
->hw
->current_topology
) {
1373 if (fcport_is_smaller(fcport
)) {
1374 /* this adapter is bigger */
1375 if (fcport
->login_retry
) {
1376 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1377 qla2x00_find_new_loop_id(vha
,
1379 fcport
->fw_login_state
=
1380 DSC_LS_PORT_UNAVAIL
;
1382 fcport
->login_retry
--;
1383 qla_post_els_plogi_work(vha
, fcport
);
1385 ql_log(ql_log_info
, vha
, 0x705d,
1386 "Unable to reach remote port %8phC",
1390 qla24xx_post_gnl_work(vha
, fcport
);
1395 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1396 "%s %d %8phC post GNNID\n",
1397 __func__
, __LINE__
, fcport
->port_name
);
1398 qla24xx_post_gnnid_work(vha
, fcport
);
1399 } else if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1400 ql_dbg(ql_dbg_disc
, vha
, 0x20bd,
1401 "%s %d %8phC post gnl\n",
1402 __func__
, __LINE__
, fcport
->port_name
);
1403 qla24xx_post_gnl_work(vha
, fcport
);
1405 qla_chk_n2n_b4_login(vha
, fcport
);
1412 switch (vha
->hw
->current_topology
) {
1414 if ((fcport
->current_login_state
& 0xf) == 0x6) {
1415 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1416 "%s %d %8phC post GPDB work\n",
1417 __func__
, __LINE__
, fcport
->port_name
);
1418 fcport
->chip_reset
=
1419 vha
->hw
->base_qpair
->chip_reset
;
1420 qla24xx_post_gpdb_work(vha
, fcport
, 0);
1422 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1423 "%s %d %8phC post NVMe PRLI\n",
1424 __func__
, __LINE__
, fcport
->port_name
);
1425 qla24xx_post_prli_work(vha
, fcport
);
1429 if (fcport
->login_pause
) {
1430 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1431 fcport
->last_login_gen
= fcport
->login_gen
;
1432 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1435 qla_chk_n2n_b4_login(vha
, fcport
);
1440 case DSC_LOGIN_FAILED
:
1441 if (N2N_TOPO(vha
->hw
))
1442 qla_chk_n2n_b4_login(vha
, fcport
);
1444 qlt_schedule_sess_for_deletion(fcport
);
1447 case DSC_LOGIN_COMPLETE
:
1448 /* recheck login state */
1449 data
[0] = data
[1] = 0;
1450 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
1453 case DSC_LOGIN_PEND
:
1454 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1455 qla24xx_post_prli_work(vha
, fcport
);
1458 case DSC_UPD_FCPORT
:
1459 sec
= jiffies_to_msecs(jiffies
-
1460 fcport
->jiffies_at_registration
)/1000;
1461 if (fcport
->sec_since_registration
< sec
&& sec
&&
1463 fcport
->sec_since_registration
= sec
;
1464 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0xffff,
1465 "%s %8phC - Slow Rport registration(%d Sec)\n",
1466 __func__
, fcport
->port_name
, sec
);
1469 if (fcport
->next_disc_state
!= DSC_DELETE_PEND
)
1470 fcport
->next_disc_state
= DSC_ADISC
;
1471 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1481 int qla24xx_post_newsess_work(struct scsi_qla_host
*vha
, port_id_t
*id
,
1482 u8
*port_name
, u8
*node_name
, void *pla
, u8 fc4_type
)
1484 struct qla_work_evt
*e
;
1485 e
= qla2x00_alloc_work(vha
, QLA_EVT_NEW_SESS
);
1487 return QLA_FUNCTION_FAILED
;
1489 e
->u
.new_sess
.id
= *id
;
1490 e
->u
.new_sess
.pla
= pla
;
1491 e
->u
.new_sess
.fc4_type
= fc4_type
;
1492 memcpy(e
->u
.new_sess
.port_name
, port_name
, WWN_SIZE
);
1494 memcpy(e
->u
.new_sess
.node_name
, node_name
, WWN_SIZE
);
1496 return qla2x00_post_work(vha
, e
);
1500 void qla24xx_handle_relogin_event(scsi_qla_host_t
*vha
,
1501 struct event_arg
*ea
)
1503 fc_port_t
*fcport
= ea
->fcport
;
1505 ql_dbg(ql_dbg_disc
, vha
, 0x2102,
1506 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1507 __func__
, fcport
->port_name
, fcport
->disc_state
,
1508 fcport
->fw_login_state
, fcport
->login_pause
,
1509 fcport
->deleted
, fcport
->conflict
,
1510 fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1511 fcport
->last_login_gen
, fcport
->login_gen
,
1514 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1515 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1518 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1519 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1520 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1525 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
1526 ql_dbg(ql_dbg_disc
, vha
, 0x20e9, "%s %d %8phC post gidpn\n",
1527 __func__
, __LINE__
, fcport
->port_name
);
1532 qla24xx_fcport_handle_login(vha
, fcport
);
1536 static void qla_handle_els_plogi_done(scsi_qla_host_t
*vha
,
1537 struct event_arg
*ea
)
1539 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1540 "%s %d %8phC post PRLI\n",
1541 __func__
, __LINE__
, ea
->fcport
->port_name
);
1542 qla24xx_post_prli_work(vha
, ea
->fcport
);
1545 void qla2x00_fcport_event_handler(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1549 switch (ea
->event
) {
1551 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1554 qla24xx_handle_relogin_event(vha
, ea
);
1557 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1560 unsigned long flags
;
1561 fcport
= qla2x00_find_fcport_by_nportid
1564 fcport
->scan_needed
= 1;
1568 spin_lock_irqsave(&vha
->work_lock
, flags
);
1569 if (vha
->scan
.scan_flags
== 0) {
1570 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1571 "%s: schedule\n", __func__
);
1572 vha
->scan
.scan_flags
|= SF_QUEUED
;
1573 schedule_delayed_work(&vha
->scan
.scan_work
, 5);
1575 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1579 qla24xx_handle_gnl_done_event(vha
, ea
);
1581 case FCME_GPSC_DONE
:
1582 qla24xx_handle_gpsc_event(vha
, ea
);
1584 case FCME_PLOGI_DONE
: /* Initiator side sent LLIOCB */
1585 qla24xx_handle_plogi_done_event(vha
, ea
);
1587 case FCME_PRLI_DONE
:
1588 qla24xx_handle_prli_done_event(vha
, ea
);
1590 case FCME_GPDB_DONE
:
1591 qla24xx_handle_gpdb_event(vha
, ea
);
1593 case FCME_GPNID_DONE
:
1594 qla24xx_handle_gpnid_event(vha
, ea
);
1596 case FCME_GFFID_DONE
:
1597 qla24xx_handle_gffid_event(vha
, ea
);
1599 case FCME_ADISC_DONE
:
1600 qla24xx_handle_adisc_event(vha
, ea
);
1602 case FCME_GNNID_DONE
:
1603 qla24xx_handle_gnnid_event(vha
, ea
);
1605 case FCME_GFPNID_DONE
:
1606 qla24xx_handle_gfpnid_event(vha
, ea
);
1608 case FCME_ELS_PLOGI_DONE
:
1609 qla_handle_els_plogi_done(vha
, ea
);
1618 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1619 * to be consumed by the fcport
1621 void qla_rscn_replay(fc_port_t
*fcport
)
1623 struct event_arg ea
;
1625 switch (fcport
->disc_state
) {
1626 case DSC_DELETE_PEND
:
1632 if (fcport
->scan_needed
) {
1633 memset(&ea
, 0, sizeof(ea
));
1634 ea
.event
= FCME_RSCN
;
1635 ea
.id
= fcport
->d_id
;
1636 ea
.id
.b
.rsvd_1
= RSCN_PORT_ADDR
;
1637 qla2x00_fcport_event_handler(fcport
->vha
, &ea
);
1642 qla2x00_tmf_iocb_timeout(void *data
)
1645 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1647 tmf
->u
.tmf
.comp_status
= CS_TIMEOUT
;
1648 complete(&tmf
->u
.tmf
.comp
);
1652 qla2x00_tmf_sp_done(void *ptr
, int res
)
1655 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1657 complete(&tmf
->u
.tmf
.comp
);
1661 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
1664 struct scsi_qla_host
*vha
= fcport
->vha
;
1665 struct srb_iocb
*tm_iocb
;
1667 int rval
= QLA_FUNCTION_FAILED
;
1669 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1673 tm_iocb
= &sp
->u
.iocb_cmd
;
1674 sp
->type
= SRB_TM_CMD
;
1677 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
1678 init_completion(&tm_iocb
->u
.tmf
.comp
);
1679 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1681 tm_iocb
->u
.tmf
.flags
= flags
;
1682 tm_iocb
->u
.tmf
.lun
= lun
;
1683 tm_iocb
->u
.tmf
.data
= tag
;
1684 sp
->done
= qla2x00_tmf_sp_done
;
1686 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
1687 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1688 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1689 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1691 rval
= qla2x00_start_sp(sp
);
1692 if (rval
!= QLA_SUCCESS
)
1694 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
1696 rval
= tm_iocb
->u
.tmf
.data
;
1698 if (rval
!= QLA_SUCCESS
) {
1699 ql_log(ql_log_warn
, vha
, 0x8030,
1700 "TM IOCB failed (%x).\n", rval
);
1703 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
1704 flags
= tm_iocb
->u
.tmf
.flags
;
1705 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
1707 /* Issue Marker IOCB */
1708 qla2x00_marker(vha
, vha
->hw
->base_qpair
,
1709 fcport
->loop_id
, lun
,
1710 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
1715 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1721 qla24xx_abort_iocb_timeout(void *data
)
1724 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1726 abt
->u
.abt
.comp_status
= CS_TIMEOUT
;
1727 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
1731 qla24xx_abort_sp_done(void *ptr
, int res
)
1734 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1736 if (del_timer(&sp
->u
.iocb_cmd
.timer
)) {
1737 if (sp
->flags
& SRB_WAKEUP_ON_COMP
)
1738 complete(&abt
->u
.abt
.comp
);
1745 qla24xx_async_abort_cmd(srb_t
*cmd_sp
, bool wait
)
1747 scsi_qla_host_t
*vha
= cmd_sp
->vha
;
1748 struct srb_iocb
*abt_iocb
;
1750 int rval
= QLA_FUNCTION_FAILED
;
1752 sp
= qla2xxx_get_qpair_sp(cmd_sp
->vha
, cmd_sp
->qpair
, cmd_sp
->fcport
,
1757 abt_iocb
= &sp
->u
.iocb_cmd
;
1758 sp
->type
= SRB_ABT_CMD
;
1760 sp
->qpair
= cmd_sp
->qpair
;
1762 sp
->flags
= SRB_WAKEUP_ON_COMP
;
1764 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
1765 init_completion(&abt_iocb
->u
.abt
.comp
);
1766 /* FW can send 2 x ABTS's timeout/20s */
1767 qla2x00_init_timer(sp
, 42);
1769 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
1770 abt_iocb
->u
.abt
.req_que_no
= cpu_to_le16(cmd_sp
->qpair
->req
->id
);
1772 sp
->done
= qla24xx_abort_sp_done
;
1774 ql_dbg(ql_dbg_async
, vha
, 0x507c,
1775 "Abort command issued - hdl=%x, type=%x\n",
1776 cmd_sp
->handle
, cmd_sp
->type
);
1778 rval
= qla2x00_start_sp(sp
);
1779 if (rval
!= QLA_SUCCESS
)
1783 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
1784 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
1785 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1797 qla24xx_async_abort_command(srb_t
*sp
)
1799 unsigned long flags
= 0;
1802 fc_port_t
*fcport
= sp
->fcport
;
1803 struct qla_qpair
*qpair
= sp
->qpair
;
1804 struct scsi_qla_host
*vha
= fcport
->vha
;
1805 struct req_que
*req
= qpair
->req
;
1807 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
1808 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
1809 if (req
->outstanding_cmds
[handle
] == sp
)
1812 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
1814 if (handle
== req
->num_outstanding_cmds
) {
1815 /* Command not found. */
1816 return QLA_FUNCTION_FAILED
;
1818 if (sp
->type
== SRB_FXIOCB_DCMD
)
1819 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
1820 FXDISC_ABORT_IOCTL
);
1822 return qla24xx_async_abort_cmd(sp
, true);
1826 qla24xx_handle_prli_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1828 switch (ea
->data
[0]) {
1829 case MBS_COMMAND_COMPLETE
:
1830 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1831 "%s %d %8phC post gpdb\n",
1832 __func__
, __LINE__
, ea
->fcport
->port_name
);
1834 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1835 ea
->fcport
->logout_on_delete
= 1;
1836 ea
->fcport
->nvme_prli_service_param
= ea
->iop
[0];
1837 if (ea
->iop
[0] & NVME_PRLI_SP_FIRST_BURST
)
1838 ea
->fcport
->nvme_first_burst_size
=
1839 (ea
->iop
[1] & 0xffff) * 512;
1841 ea
->fcport
->nvme_first_burst_size
= 0;
1842 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1845 if ((ea
->iop
[0] == LSC_SCODE_ELS_REJECT
) &&
1846 (ea
->iop
[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1847 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1848 ea
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
1852 if (ea
->fcport
->n2n_flag
) {
1853 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1854 "%s %d %8phC post fc4 prli\n",
1855 __func__
, __LINE__
, ea
->fcport
->port_name
);
1856 ea
->fcport
->fc4f_nvme
= 0;
1857 ea
->fcport
->n2n_flag
= 0;
1858 qla24xx_post_prli_work(vha
, ea
->fcport
);
1860 ql_dbg(ql_dbg_disc
, vha
, 0x2119,
1861 "%s %d %8phC unhandle event of %x\n",
1862 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[0]);
1868 qla24xx_handle_plogi_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1870 port_id_t cid
; /* conflict Nport id */
1872 struct fc_port
*conflict_fcport
;
1873 unsigned long flags
;
1874 struct fc_port
*fcport
= ea
->fcport
;
1876 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1877 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1878 __func__
, fcport
->port_name
, fcport
->disc_state
,
1879 fcport
->fw_login_state
, ea
->rc
, ea
->sp
->gen2
, fcport
->login_gen
,
1880 ea
->sp
->gen1
, fcport
->rscn_gen
,
1881 ea
->data
[0], ea
->data
[1], ea
->iop
[0], ea
->iop
[1]);
1883 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1884 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)) {
1885 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1886 "%s %d %8phC Remote is trying to login\n",
1887 __func__
, __LINE__
, fcport
->port_name
);
1891 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1894 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1895 /* target side must have changed it. */
1896 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1897 "%s %8phC generation changed\n",
1898 __func__
, fcport
->port_name
);
1899 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1901 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1902 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1903 "%s %8phC RSCN generation changed\n",
1904 __func__
, fcport
->port_name
);
1905 qla_rscn_replay(fcport
);
1906 qlt_schedule_sess_for_deletion(fcport
);
1910 switch (ea
->data
[0]) {
1911 case MBS_COMMAND_COMPLETE
:
1913 * Driver must validate login state - If PRLI not complete,
1914 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1917 if (ea
->fcport
->fc4f_nvme
) {
1918 ql_dbg(ql_dbg_disc
, vha
, 0x2117,
1919 "%s %d %8phC post prli\n",
1920 __func__
, __LINE__
, ea
->fcport
->port_name
);
1921 qla24xx_post_prli_work(vha
, ea
->fcport
);
1923 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1924 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1925 __func__
, __LINE__
, ea
->fcport
->port_name
,
1926 ea
->fcport
->loop_id
, ea
->fcport
->d_id
.b24
);
1928 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1929 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1930 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1931 ea
->fcport
->logout_on_delete
= 1;
1932 ea
->fcport
->send_els_logo
= 0;
1933 ea
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
1934 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1936 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1939 case MBS_COMMAND_ERROR
:
1940 ql_dbg(ql_dbg_disc
, vha
, 0x20eb, "%s %d %8phC cmd error %x\n",
1941 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[1]);
1943 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1944 ea
->fcport
->disc_state
= DSC_LOGIN_FAILED
;
1945 if (ea
->data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1946 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1948 qla2x00_mark_device_lost(vha
, ea
->fcport
, 1, 0);
1950 case MBS_LOOP_ID_USED
:
1951 /* data[1] = IO PARAM 1 = nport ID */
1952 cid
.b
.domain
= (ea
->iop
[1] >> 16) & 0xff;
1953 cid
.b
.area
= (ea
->iop
[1] >> 8) & 0xff;
1954 cid
.b
.al_pa
= ea
->iop
[1] & 0xff;
1957 ql_dbg(ql_dbg_disc
, vha
, 0x20ec,
1958 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
1959 __func__
, __LINE__
, ea
->fcport
->port_name
,
1960 ea
->fcport
->loop_id
, cid
.b24
);
1962 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1963 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1964 qla24xx_post_gnl_work(vha
, ea
->fcport
);
1966 case MBS_PORT_ID_USED
:
1967 lid
= ea
->iop
[1] & 0xffff;
1968 qlt_find_sess_invalidate_other(vha
,
1969 wwn_to_u64(ea
->fcport
->port_name
),
1970 ea
->fcport
->d_id
, lid
, &conflict_fcport
);
1972 if (conflict_fcport
) {
1974 * Another fcport share the same loop_id/nport id.
1975 * Conflict fcport needs to finish cleanup before this
1976 * fcport can proceed to login.
1978 conflict_fcport
->conflict
= ea
->fcport
;
1979 ea
->fcport
->login_pause
= 1;
1981 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1982 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1983 __func__
, __LINE__
, ea
->fcport
->port_name
,
1984 ea
->fcport
->d_id
.b24
, lid
);
1986 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1987 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1988 __func__
, __LINE__
, ea
->fcport
->port_name
,
1989 ea
->fcport
->d_id
.b24
, lid
);
1991 qla2x00_clear_loop_id(ea
->fcport
);
1992 set_bit(lid
, vha
->hw
->loop_id_map
);
1993 ea
->fcport
->loop_id
= lid
;
1994 ea
->fcport
->keep_nport_handle
= 0;
1995 qlt_schedule_sess_for_deletion(ea
->fcport
);
2003 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
2006 qlt_logo_completion_handler(fcport
, data
[0]);
2007 fcport
->login_gen
++;
2008 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
2012 /****************************************************************************/
2013 /* QLogic ISP2x00 Hardware Support Functions. */
2014 /****************************************************************************/
2017 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
2019 int rval
= QLA_SUCCESS
;
2020 struct qla_hw_data
*ha
= vha
->hw
;
2021 uint32_t idc_major_ver
, idc_minor_ver
;
2024 qla83xx_idc_lock(vha
, 0);
2026 /* SV: TODO: Assign initialization timeout from
2027 * flash-info / other param
2029 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
2030 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
2032 /* Set our fcoe function presence */
2033 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
2034 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
2035 "Error while setting DRV-Presence.\n");
2036 rval
= QLA_FUNCTION_FAILED
;
2040 /* Decide the reset ownership */
2041 qla83xx_reset_ownership(vha
);
2044 * On first protocol driver load:
2045 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2047 * Others: Check compatibility with current IDC Major version.
2049 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
2050 if (ha
->flags
.nic_core_reset_owner
) {
2051 /* Set IDC Major version */
2052 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
2053 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
2055 /* Clearing IDC-Lock-Recovery register */
2056 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
2057 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
2059 * Clear further IDC participation if we are not compatible with
2060 * the current IDC Major Version.
2062 ql_log(ql_log_warn
, vha
, 0xb07d,
2063 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2064 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
2065 __qla83xx_clear_drv_presence(vha
);
2066 rval
= QLA_FUNCTION_FAILED
;
2069 /* Each function sets its supported Minor version. */
2070 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
2071 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
2072 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
2074 if (ha
->flags
.nic_core_reset_owner
) {
2075 memset(config
, 0, sizeof(config
));
2076 if (!qla81xx_get_port_config(vha
, config
))
2077 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
2081 rval
= qla83xx_idc_state_handler(vha
);
2084 qla83xx_idc_unlock(vha
, 0);
2090 * qla2x00_initialize_adapter
2094 * ha = adapter block pointer.
2100 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
2103 struct qla_hw_data
*ha
= vha
->hw
;
2104 struct req_que
*req
= ha
->req_q_map
[0];
2106 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
2107 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
2109 /* Clear adapter flags. */
2110 vha
->flags
.online
= 0;
2111 ha
->flags
.chip_reset_done
= 0;
2112 vha
->flags
.reset_active
= 0;
2113 ha
->flags
.pci_channel_io_perm_failure
= 0;
2114 ha
->flags
.eeh_busy
= 0;
2115 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
2116 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
2117 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
2118 vha
->device_flags
= DFLG_NO_CABLE
;
2120 vha
->flags
.management_server_logged_in
= 0;
2121 vha
->marker_needed
= 0;
2122 ha
->isp_abort_cnt
= 0;
2123 ha
->beacon_blink_led
= 0;
2125 set_bit(0, ha
->req_qid_map
);
2126 set_bit(0, ha
->rsp_qid_map
);
2128 ql_dbg(ql_dbg_init
, vha
, 0x0040,
2129 "Configuring PCI space...\n");
2130 rval
= ha
->isp_ops
->pci_config(vha
);
2132 ql_log(ql_log_warn
, vha
, 0x0044,
2133 "Unable to configure PCI space.\n");
2137 ha
->isp_ops
->reset_chip(vha
);
2139 rval
= qla2xxx_get_flash_info(vha
);
2141 ql_log(ql_log_fatal
, vha
, 0x004f,
2142 "Unable to validate FLASH data.\n");
2146 if (IS_QLA8044(ha
)) {
2147 qla8044_read_reset_template(vha
);
2149 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2150 * If DONRESET_BIT0 is set, drivers should not set dev_state
2151 * to NEED_RESET. But if NEED_RESET is set, drivers should
2152 * should honor the reset. */
2153 if (ql2xdontresethba
== 1)
2154 qla8044_set_idc_dontreset(vha
);
2157 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
2158 ql_dbg(ql_dbg_init
, vha
, 0x0061,
2159 "Configure NVRAM parameters...\n");
2161 ha
->isp_ops
->nvram_config(vha
);
2163 if (ha
->flags
.disable_serdes
) {
2164 /* Mask HBA via NVRAM settings? */
2165 ql_log(ql_log_info
, vha
, 0x0077,
2166 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
2167 return QLA_FUNCTION_FAILED
;
2170 ql_dbg(ql_dbg_init
, vha
, 0x0078,
2171 "Verifying loaded RISC code...\n");
2173 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
2174 rval
= ha
->isp_ops
->chip_diag(vha
);
2177 rval
= qla2x00_setup_chip(vha
);
2182 if (IS_QLA84XX(ha
)) {
2183 ha
->cs84xx
= qla84xx_get_chip(vha
);
2185 ql_log(ql_log_warn
, vha
, 0x00d0,
2186 "Unable to configure ISP84XX.\n");
2187 return QLA_FUNCTION_FAILED
;
2191 if (qla_ini_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
2192 rval
= qla2x00_init_rings(vha
);
2194 ha
->flags
.chip_reset_done
= 1;
2196 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
2197 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2198 rval
= qla84xx_init_chip(vha
);
2199 if (rval
!= QLA_SUCCESS
) {
2200 ql_log(ql_log_warn
, vha
, 0x00d4,
2201 "Unable to initialize ISP84XX.\n");
2202 qla84xx_put_chip(vha
);
2206 /* Load the NIC Core f/w if we are the first protocol driver. */
2207 if (IS_QLA8031(ha
)) {
2208 rval
= qla83xx_nic_core_fw_load(vha
);
2210 ql_log(ql_log_warn
, vha
, 0x0124,
2211 "Error in initializing NIC Core f/w.\n");
2214 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
2215 qla24xx_read_fcp_prio_cfg(vha
);
2217 if (IS_P3P_TYPE(ha
))
2218 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2220 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2226 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2229 * Returns 0 on success.
2232 qla2100_pci_config(scsi_qla_host_t
*vha
)
2235 unsigned long flags
;
2236 struct qla_hw_data
*ha
= vha
->hw
;
2237 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2239 pci_set_master(ha
->pdev
);
2240 pci_try_set_mwi(ha
->pdev
);
2242 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2243 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2244 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2246 pci_disable_rom(ha
->pdev
);
2248 /* Get PCI bus information. */
2249 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2250 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2251 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2257 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2260 * Returns 0 on success.
2263 qla2300_pci_config(scsi_qla_host_t
*vha
)
2266 unsigned long flags
= 0;
2268 struct qla_hw_data
*ha
= vha
->hw
;
2269 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2271 pci_set_master(ha
->pdev
);
2272 pci_try_set_mwi(ha
->pdev
);
2274 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2275 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2277 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2278 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2279 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2282 * If this is a 2300 card and not 2312, reset the
2283 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2284 * the 2310 also reports itself as a 2300 so we need to get the
2285 * fb revision level -- a 6 indicates it really is a 2300 and
2288 if (IS_QLA2300(ha
)) {
2289 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2292 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2293 for (cnt
= 0; cnt
< 30000; cnt
++) {
2294 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2300 /* Select FPM registers. */
2301 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2302 RD_REG_WORD(®
->ctrl_status
);
2304 /* Get the fb rev level */
2305 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
2307 if (ha
->fb_rev
== FPM_2300
)
2308 pci_clear_mwi(ha
->pdev
);
2310 /* Deselect FPM registers. */
2311 WRT_REG_WORD(®
->ctrl_status
, 0x0);
2312 RD_REG_WORD(®
->ctrl_status
);
2314 /* Release RISC module. */
2315 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2316 for (cnt
= 0; cnt
< 30000; cnt
++) {
2317 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
2323 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2326 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2328 pci_disable_rom(ha
->pdev
);
2330 /* Get PCI bus information. */
2331 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2332 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2333 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2339 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2342 * Returns 0 on success.
2345 qla24xx_pci_config(scsi_qla_host_t
*vha
)
2348 unsigned long flags
= 0;
2349 struct qla_hw_data
*ha
= vha
->hw
;
2350 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2352 pci_set_master(ha
->pdev
);
2353 pci_try_set_mwi(ha
->pdev
);
2355 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2356 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2357 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2358 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2360 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2362 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2363 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
2364 pcix_set_mmrbc(ha
->pdev
, 2048);
2366 /* PCIe -- adjust Maximum Read Request Size (2048). */
2367 if (pci_is_pcie(ha
->pdev
))
2368 pcie_set_readrq(ha
->pdev
, 4096);
2370 pci_disable_rom(ha
->pdev
);
2372 ha
->chip_revision
= ha
->pdev
->revision
;
2374 /* Get PCI bus information. */
2375 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2376 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
2377 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2383 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2386 * Returns 0 on success.
2389 qla25xx_pci_config(scsi_qla_host_t
*vha
)
2392 struct qla_hw_data
*ha
= vha
->hw
;
2394 pci_set_master(ha
->pdev
);
2395 pci_try_set_mwi(ha
->pdev
);
2397 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2398 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2399 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2400 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2402 /* PCIe -- adjust Maximum Read Request Size (2048). */
2403 if (pci_is_pcie(ha
->pdev
))
2404 pcie_set_readrq(ha
->pdev
, 4096);
2406 pci_disable_rom(ha
->pdev
);
2408 ha
->chip_revision
= ha
->pdev
->revision
;
2414 * qla2x00_isp_firmware() - Choose firmware image.
2417 * Returns 0 on success.
2420 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
2423 uint16_t loop_id
, topo
, sw_cap
;
2424 uint8_t domain
, area
, al_pa
;
2425 struct qla_hw_data
*ha
= vha
->hw
;
2427 /* Assume loading risc code */
2428 rval
= QLA_FUNCTION_FAILED
;
2430 if (ha
->flags
.disable_risc_code_load
) {
2431 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
2433 /* Verify checksum of loaded RISC code. */
2434 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
2435 if (rval
== QLA_SUCCESS
) {
2436 /* And, verify we are not in ROM code. */
2437 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
2438 &area
, &domain
, &topo
, &sw_cap
);
2443 ql_dbg(ql_dbg_init
, vha
, 0x007a,
2444 "**** Load RISC code ****.\n");
2450 * qla2x00_reset_chip() - Reset ISP chip.
2453 * Returns 0 on success.
2456 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
2458 unsigned long flags
= 0;
2459 struct qla_hw_data
*ha
= vha
->hw
;
2460 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2464 if (unlikely(pci_channel_offline(ha
->pdev
)))
2467 ha
->isp_ops
->disable_intrs(ha
);
2469 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2471 /* Turn off master enable */
2473 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
2474 cmd
&= ~PCI_COMMAND_MASTER
;
2475 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2477 if (!IS_QLA2100(ha
)) {
2479 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2480 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2481 for (cnt
= 0; cnt
< 30000; cnt
++) {
2482 if ((RD_REG_WORD(®
->hccr
) &
2483 HCCR_RISC_PAUSE
) != 0)
2488 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2492 /* Select FPM registers. */
2493 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2494 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2496 /* FPM Soft Reset. */
2497 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
2498 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2500 /* Toggle Fpm Reset. */
2501 if (!IS_QLA2200(ha
)) {
2502 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
2503 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2506 /* Select frame buffer registers. */
2507 WRT_REG_WORD(®
->ctrl_status
, 0x10);
2508 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2510 /* Reset frame buffer FIFOs. */
2511 if (IS_QLA2200(ha
)) {
2512 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
2513 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
2515 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
2517 /* Read back fb_cmd until zero or 3 seconds max */
2518 for (cnt
= 0; cnt
< 3000; cnt
++) {
2519 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
2525 /* Select RISC module registers. */
2526 WRT_REG_WORD(®
->ctrl_status
, 0);
2527 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2529 /* Reset RISC processor. */
2530 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2531 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2533 /* Release RISC processor. */
2534 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2535 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2538 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
2539 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
2541 /* Reset ISP chip. */
2542 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2544 /* Wait for RISC to recover from reset. */
2545 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2547 * It is necessary to for a delay here since the card doesn't
2548 * respond to PCI reads during a reset. On some architectures
2549 * this will result in an MCA.
2552 for (cnt
= 30000; cnt
; cnt
--) {
2553 if ((RD_REG_WORD(®
->ctrl_status
) &
2554 CSR_ISP_SOFT_RESET
) == 0)
2561 /* Reset RISC processor. */
2562 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2564 WRT_REG_WORD(®
->semaphore
, 0);
2566 /* Release RISC processor. */
2567 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2568 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2570 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2571 for (cnt
= 0; cnt
< 30000; cnt
++) {
2572 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
2580 /* Turn on master enable */
2581 cmd
|= PCI_COMMAND_MASTER
;
2582 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2584 /* Disable RISC pause on FPM parity error. */
2585 if (!IS_QLA2100(ha
)) {
2586 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
2587 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2590 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2594 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2597 * Returns 0 on success.
2600 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
2602 uint16_t mb
[4] = {0x1010, 0, 1, 0};
2604 if (!IS_QLA81XX(vha
->hw
))
2607 return qla81xx_write_mpi_register(vha
, mb
);
2611 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2614 * Returns 0 on success.
2617 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
2619 unsigned long flags
= 0;
2620 struct qla_hw_data
*ha
= vha
->hw
;
2621 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2624 static int abts_cnt
; /* ISP abort retry counts */
2625 int rval
= QLA_SUCCESS
;
2627 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2630 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2631 for (cnt
= 0; cnt
< 30000; cnt
++) {
2632 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
2638 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
))
2639 set_bit(DMA_SHUTDOWN_CMPL
, &ha
->fw_dump_cap_flags
);
2641 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017e,
2642 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2643 RD_REG_DWORD(®
->hccr
),
2644 RD_REG_DWORD(®
->ctrl_status
),
2645 (RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
));
2647 WRT_REG_DWORD(®
->ctrl_status
,
2648 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2649 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2653 /* Wait for firmware to complete NVRAM accesses. */
2654 RD_REG_WORD(®
->mailbox0
);
2655 for (cnt
= 10000; RD_REG_WORD(®
->mailbox0
) != 0 &&
2656 rval
== QLA_SUCCESS
; cnt
--) {
2661 rval
= QLA_FUNCTION_TIMEOUT
;
2664 if (rval
== QLA_SUCCESS
)
2665 set_bit(ISP_MBX_RDY
, &ha
->fw_dump_cap_flags
);
2667 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017f,
2668 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2669 RD_REG_DWORD(®
->hccr
),
2670 RD_REG_DWORD(®
->mailbox0
));
2672 /* Wait for soft-reset to complete. */
2673 RD_REG_DWORD(®
->ctrl_status
);
2674 for (cnt
= 0; cnt
< 60; cnt
++) {
2676 if ((RD_REG_DWORD(®
->ctrl_status
) &
2677 CSRX_ISP_SOFT_RESET
) == 0)
2682 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_ISP_SOFT_RESET
))
2683 set_bit(ISP_SOFT_RESET_CMPL
, &ha
->fw_dump_cap_flags
);
2685 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015d,
2686 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2687 RD_REG_DWORD(®
->hccr
),
2688 RD_REG_DWORD(®
->ctrl_status
));
2690 /* If required, do an MPI FW reset now */
2691 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
2692 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
2693 if (++abts_cnt
< 5) {
2694 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2695 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
2698 * We exhausted the ISP abort retries. We have to
2699 * set the board offline.
2702 vha
->flags
.online
= 0;
2707 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
2708 RD_REG_DWORD(®
->hccr
);
2710 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
2711 RD_REG_DWORD(®
->hccr
);
2713 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
2714 RD_REG_DWORD(®
->hccr
);
2716 RD_REG_WORD(®
->mailbox0
);
2717 for (cnt
= 60; RD_REG_WORD(®
->mailbox0
) != 0 &&
2718 rval
== QLA_SUCCESS
; cnt
--) {
2723 rval
= QLA_FUNCTION_TIMEOUT
;
2725 if (rval
== QLA_SUCCESS
)
2726 set_bit(RISC_RDY_AFT_RESET
, &ha
->fw_dump_cap_flags
);
2728 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015e,
2729 "Host Risc 0x%x, mailbox0 0x%x\n",
2730 RD_REG_DWORD(®
->hccr
),
2731 RD_REG_WORD(®
->mailbox0
));
2733 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2735 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015f,
2736 "Driver in %s mode\n",
2737 IS_NOPOLLING_TYPE(ha
) ? "Interrupt" : "Polling");
2739 if (IS_NOPOLLING_TYPE(ha
))
2740 ha
->isp_ops
->enable_intrs(ha
);
2746 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
2748 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2750 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2751 *data
= RD_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
);
2756 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
2758 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2760 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2761 WRT_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
, data
);
2765 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
2768 uint delta_msec
= 100;
2769 uint elapsed_msec
= 0;
2773 if (vha
->hw
->pdev
->subsystem_device
!= 0x0175 &&
2774 vha
->hw
->pdev
->subsystem_device
!= 0x0240)
2777 WRT_REG_DWORD(&vha
->hw
->iobase
->isp24
.hccr
, HCCRX_SET_RISC_PAUSE
);
2781 timeout_msec
= TIMEOUT_SEMAPHORE
;
2782 n
= timeout_msec
/ delta_msec
;
2784 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
2785 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2786 if (wd32
& RISC_SEMAPHORE
)
2789 elapsed_msec
+= delta_msec
;
2790 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2794 if (!(wd32
& RISC_SEMAPHORE
))
2797 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2800 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
2801 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
2802 n
= timeout_msec
/ delta_msec
;
2804 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2805 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2808 elapsed_msec
+= delta_msec
;
2809 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2813 if (wd32
& RISC_SEMAPHORE_FORCE
)
2814 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
2819 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
2826 * qla24xx_reset_chip() - Reset ISP24xx chip.
2829 * Returns 0 on success.
2832 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
2834 struct qla_hw_data
*ha
= vha
->hw
;
2836 if (pci_channel_offline(ha
->pdev
) &&
2837 ha
->flags
.pci_channel_io_perm_failure
) {
2841 ha
->isp_ops
->disable_intrs(ha
);
2843 qla25xx_manipulate_risc_semaphore(vha
);
2845 /* Perform RISC reset. */
2846 qla24xx_reset_risc(vha
);
2850 * qla2x00_chip_diag() - Test chip for proper operation.
2853 * Returns 0 on success.
2856 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
2859 struct qla_hw_data
*ha
= vha
->hw
;
2860 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2861 unsigned long flags
= 0;
2865 struct req_que
*req
= ha
->req_q_map
[0];
2867 /* Assume a failed state */
2868 rval
= QLA_FUNCTION_FAILED
;
2870 ql_dbg(ql_dbg_init
, vha
, 0x007b, "Testing device at %p.\n",
2871 ®
->flash_address
);
2873 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2875 /* Reset ISP chip. */
2876 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2879 * We need to have a delay here since the card will not respond while
2880 * in reset causing an MCA on some architectures.
2883 data
= qla2x00_debounce_register(®
->ctrl_status
);
2884 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
2886 data
= RD_REG_WORD(®
->ctrl_status
);
2891 goto chip_diag_failed
;
2893 ql_dbg(ql_dbg_init
, vha
, 0x007c,
2894 "Reset register cleared by chip reset.\n");
2896 /* Reset RISC processor. */
2897 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2898 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2900 /* Workaround for QLA2312 PCI parity error */
2901 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2902 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
2903 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
2905 data
= RD_MAILBOX_REG(ha
, reg
, 0);
2912 goto chip_diag_failed
;
2914 /* Check product ID of chip */
2915 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product ID of chip.\n");
2917 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
2918 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
2919 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
2920 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
2921 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
2922 mb
[3] != PROD_ID_3
) {
2923 ql_log(ql_log_warn
, vha
, 0x0062,
2924 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2925 mb
[1], mb
[2], mb
[3]);
2927 goto chip_diag_failed
;
2929 ha
->product_id
[0] = mb
[1];
2930 ha
->product_id
[1] = mb
[2];
2931 ha
->product_id
[2] = mb
[3];
2932 ha
->product_id
[3] = mb
[4];
2934 /* Adjust fw RISC transfer size */
2935 if (req
->length
> 1024)
2936 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
2938 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
2941 if (IS_QLA2200(ha
) &&
2942 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
2943 /* Limit firmware transfer size with a 2200A */
2944 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
2946 ha
->device_type
|= DT_ISP2200A
;
2947 ha
->fw_transfer_size
= 128;
2950 /* Wrap Incoming Mailboxes Test. */
2951 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2953 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
2954 rval
= qla2x00_mbx_reg_test(vha
);
2956 ql_log(ql_log_warn
, vha
, 0x0080,
2957 "Failed mailbox send register test.\n");
2959 /* Flag a successful rval */
2961 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2965 ql_log(ql_log_info
, vha
, 0x0081,
2966 "Chip diagnostics **** FAILED ****.\n");
2968 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2974 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2977 * Returns 0 on success.
2980 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
2983 struct qla_hw_data
*ha
= vha
->hw
;
2984 struct req_que
*req
= ha
->req_q_map
[0];
2986 if (IS_P3P_TYPE(ha
))
2989 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
2991 rval
= qla2x00_mbx_reg_test(vha
);
2993 ql_log(ql_log_warn
, vha
, 0x0082,
2994 "Failed mailbox send register test.\n");
2996 /* Flag a successful rval */
3004 qla2x00_alloc_offload_mem(scsi_qla_host_t
*vha
)
3009 struct qla_hw_data
*ha
= vha
->hw
;
3012 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
3013 "%s: Offload Mem is already allocated.\n",
3018 if (IS_FWI2_CAPABLE(ha
)) {
3019 /* Allocate memory for Fibre Channel Event Buffer. */
3020 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
3025 dma_free_coherent(&ha
->pdev
->dev
,
3026 FCE_SIZE
, ha
->fce
, ha
->fce_dma
);
3028 /* Allocate memory for Fibre Channel Event Buffer. */
3029 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
3032 ql_log(ql_log_warn
, vha
, 0x00be,
3033 "Unable to allocate (%d KB) for FCE.\n",
3038 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
3039 ha
->fce_mb
, &ha
->fce_bufs
);
3041 ql_log(ql_log_warn
, vha
, 0x00bf,
3042 "Unable to initialize FCE (%d).\n", rval
);
3043 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
3045 ha
->flags
.fce_enabled
= 0;
3048 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
3049 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
3051 ha
->flags
.fce_enabled
= 1;
3052 ha
->fce_dma
= tc_dma
;
3057 dma_free_coherent(&ha
->pdev
->dev
,
3058 EFT_SIZE
, ha
->eft
, ha
->eft_dma
);
3060 /* Allocate memory for Extended Trace Buffer. */
3061 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
3064 ql_log(ql_log_warn
, vha
, 0x00c1,
3065 "Unable to allocate (%d KB) for EFT.\n",
3070 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
3072 ql_log(ql_log_warn
, vha
, 0x00c2,
3073 "Unable to initialize EFT (%d).\n", rval
);
3074 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
3078 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
3079 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
3081 ha
->eft_dma
= tc_dma
;
3090 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
3092 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
3093 eft_size
, fce_size
, mq_size
;
3094 struct qla_hw_data
*ha
= vha
->hw
;
3095 struct req_que
*req
= ha
->req_q_map
[0];
3096 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3097 struct qla2xxx_fw_dump
*fw_dump
;
3099 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
3100 req_q_size
= rsp_q_size
= 0;
3102 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3103 fixed_size
= sizeof(struct qla2100_fw_dump
);
3104 } else if (IS_QLA23XX(ha
)) {
3105 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
3106 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
3108 } else if (IS_FWI2_CAPABLE(ha
)) {
3109 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))
3110 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
3111 else if (IS_QLA81XX(ha
))
3112 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
3113 else if (IS_QLA25XX(ha
))
3114 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
3116 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
3118 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
3121 if (!IS_QLA83XX(ha
) && !IS_QLA27XX(ha
))
3122 mq_size
= sizeof(struct qla2xxx_mq_chain
);
3124 * Allocate maximum buffer size for all queues.
3125 * Resizing must be done at end-of-dump processing.
3127 mq_size
+= ha
->max_req_queues
*
3128 (req
->length
* sizeof(request_t
));
3129 mq_size
+= ha
->max_rsp_queues
*
3130 (rsp
->length
* sizeof(response_t
));
3132 if (ha
->tgt
.atio_ring
)
3133 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
3134 /* Allocate memory for Fibre Channel Event Buffer. */
3135 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
3139 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
3141 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
3142 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
3143 eft_size
= EFT_SIZE
;
3146 if (IS_QLA27XX(ha
)) {
3147 if (!ha
->fw_dump_template
) {
3148 ql_log(ql_log_warn
, vha
, 0x00ba,
3149 "Failed missing fwdump template\n");
3152 dump_size
= qla27xx_fwdt_calculate_dump_size(vha
);
3153 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
3154 "-> allocating fwdump (%x bytes)...\n", dump_size
);
3158 req_q_size
= req
->length
* sizeof(request_t
);
3159 rsp_q_size
= rsp
->length
* sizeof(response_t
);
3160 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
3161 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
3162 ha
->chain_offset
= dump_size
;
3163 dump_size
+= mq_size
+ fce_size
;
3165 if (ha
->exchoffld_buf
)
3166 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3168 if (ha
->exlogin_buf
)
3169 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3173 if (!ha
->fw_dump_len
|| dump_size
!= ha
->fw_dump_len
) {
3174 fw_dump
= vmalloc(dump_size
);
3176 ql_log(ql_log_warn
, vha
, 0x00c4,
3177 "Unable to allocate (%d KB) for firmware dump.\n",
3182 ha
->fw_dump
= fw_dump
;
3184 ha
->fw_dump_len
= dump_size
;
3185 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3186 "Allocated (%d KB) for firmware dump.\n",
3192 ha
->fw_dump
->signature
[0] = 'Q';
3193 ha
->fw_dump
->signature
[1] = 'L';
3194 ha
->fw_dump
->signature
[2] = 'G';
3195 ha
->fw_dump
->signature
[3] = 'C';
3196 ha
->fw_dump
->version
= htonl(1);
3198 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
3199 ha
->fw_dump
->mem_size
= htonl(mem_size
);
3200 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
3201 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
3203 ha
->fw_dump
->eft_size
= htonl(eft_size
);
3204 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
3205 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
3207 ha
->fw_dump
->header_size
=
3208 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
3214 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
3216 #define MPS_MASK 0xe0
3221 if (!IS_QLA81XX(vha
->hw
))
3224 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
3225 if (rval
!= QLA_SUCCESS
) {
3226 ql_log(ql_log_warn
, vha
, 0x0105,
3227 "Unable to acquire semaphore.\n");
3231 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
3232 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
3233 if (rval
!= QLA_SUCCESS
) {
3234 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
3239 if (dc
== (dw
& MPS_MASK
))
3244 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
3245 if (rval
!= QLA_SUCCESS
) {
3246 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
3250 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
3251 if (rval
!= QLA_SUCCESS
) {
3252 ql_log(ql_log_warn
, vha
, 0x006d,
3253 "Unable to release semaphore.\n");
3261 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
3263 /* Don't try to reallocate the array */
3264 if (req
->outstanding_cmds
)
3267 if (!IS_FWI2_CAPABLE(ha
))
3268 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
3270 if (ha
->cur_fw_xcb_count
<= ha
->cur_fw_iocb_count
)
3271 req
->num_outstanding_cmds
= ha
->cur_fw_xcb_count
;
3273 req
->num_outstanding_cmds
= ha
->cur_fw_iocb_count
;
3276 req
->outstanding_cmds
= kcalloc(req
->num_outstanding_cmds
,
3280 if (!req
->outstanding_cmds
) {
3282 * Try to allocate a minimal size just so we can get through
3285 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
3286 req
->outstanding_cmds
= kcalloc(req
->num_outstanding_cmds
,
3290 if (!req
->outstanding_cmds
) {
3291 ql_log(ql_log_fatal
, NULL
, 0x0126,
3292 "Failed to allocate memory for "
3293 "outstanding_cmds for req_que %p.\n", req
);
3294 req
->num_outstanding_cmds
= 0;
3295 return QLA_FUNCTION_FAILED
;
3302 #define PRINT_FIELD(_field, _flag, _str) { \
3303 if (a0->_field & _flag) {\
3309 len = snprintf(ptr, leftover, "%s", _str); \
3316 static void qla2xxx_print_sfp_info(struct scsi_qla_host
*vha
)
3319 struct sff_8247_a0
*a0
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3320 u8 str
[STR_LEN
], *ptr
, p
;
3323 memset(str
, 0, STR_LEN
);
3324 snprintf(str
, SFF_VEN_NAME_LEN
+1, a0
->vendor_name
);
3325 ql_dbg(ql_dbg_init
, vha
, 0x015a,
3326 "SFP MFG Name: %s\n", str
);
3328 memset(str
, 0, STR_LEN
);
3329 snprintf(str
, SFF_PART_NAME_LEN
+1, a0
->vendor_pn
);
3330 ql_dbg(ql_dbg_init
, vha
, 0x015c,
3331 "SFP Part Name: %s\n", str
);
3334 memset(str
, 0, STR_LEN
);
3338 PRINT_FIELD(fc_med_cc9
, FC_MED_TW
, "Twin AX");
3339 PRINT_FIELD(fc_med_cc9
, FC_MED_TP
, "Twisted Pair");
3340 PRINT_FIELD(fc_med_cc9
, FC_MED_MI
, "Min Coax");
3341 PRINT_FIELD(fc_med_cc9
, FC_MED_TV
, "Video Coax");
3342 PRINT_FIELD(fc_med_cc9
, FC_MED_M6
, "MultiMode 62.5um");
3343 PRINT_FIELD(fc_med_cc9
, FC_MED_M5
, "MultiMode 50um");
3344 PRINT_FIELD(fc_med_cc9
, FC_MED_SM
, "SingleMode");
3345 ql_dbg(ql_dbg_init
, vha
, 0x0160,
3346 "SFP Media: %s\n", str
);
3349 memset(str
, 0, STR_LEN
);
3353 PRINT_FIELD(fc_ll_cc7
, FC_LL_VL
, "Very Long");
3354 PRINT_FIELD(fc_ll_cc7
, FC_LL_S
, "Short");
3355 PRINT_FIELD(fc_ll_cc7
, FC_LL_I
, "Intermediate");
3356 PRINT_FIELD(fc_ll_cc7
, FC_LL_L
, "Long");
3357 PRINT_FIELD(fc_ll_cc7
, FC_LL_M
, "Medium");
3358 ql_dbg(ql_dbg_init
, vha
, 0x0196,
3359 "SFP Link Length: %s\n", str
);
3361 memset(str
, 0, STR_LEN
);
3365 PRINT_FIELD(fc_ll_cc7
, FC_LL_SA
, "Short Wave (SA)");
3366 PRINT_FIELD(fc_ll_cc7
, FC_LL_LC
, "Long Wave(LC)");
3367 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SN
, "Short Wave (SN)");
3368 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SL
, "Short Wave (SL)");
3369 PRINT_FIELD(fc_tec_cc8
, FC_TEC_LL
, "Long Wave (LL)");
3370 ql_dbg(ql_dbg_init
, vha
, 0x016e,
3371 "SFP FC Link Tech: %s\n", str
);
3374 ql_dbg(ql_dbg_init
, vha
, 0x016f,
3375 "SFP Distant: %d km\n", a0
->length_km
);
3376 if (a0
->length_100m
)
3377 ql_dbg(ql_dbg_init
, vha
, 0x0170,
3378 "SFP Distant: %d m\n", a0
->length_100m
*100);
3379 if (a0
->length_50um_10m
)
3380 ql_dbg(ql_dbg_init
, vha
, 0x0189,
3381 "SFP Distant (WL=50um): %d m\n", a0
->length_50um_10m
* 10);
3382 if (a0
->length_62um_10m
)
3383 ql_dbg(ql_dbg_init
, vha
, 0x018a,
3384 "SFP Distant (WL=62.5um): %d m\n", a0
->length_62um_10m
* 10);
3385 if (a0
->length_om4_10m
)
3386 ql_dbg(ql_dbg_init
, vha
, 0x0194,
3387 "SFP Distant (OM4): %d m\n", a0
->length_om4_10m
* 10);
3388 if (a0
->length_om3_10m
)
3389 ql_dbg(ql_dbg_init
, vha
, 0x0195,
3390 "SFP Distant (OM3): %d m\n", a0
->length_om3_10m
* 10);
3396 * QLA_SUCCESS: no action
3397 * QLA_INTERFACE_ERROR: SFP is not there.
3398 * QLA_FUNCTION_FAILED: detected New SFP
3401 qla24xx_detect_sfp(scsi_qla_host_t
*vha
)
3403 int rc
= QLA_SUCCESS
;
3404 struct sff_8247_a0
*a
;
3405 struct qla_hw_data
*ha
= vha
->hw
;
3407 if (!AUTO_DETECT_SFP_SUPPORT(vha
))
3410 rc
= qla2x00_read_sfp_dev(vha
, NULL
, 0);
3414 a
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3415 qla2xxx_print_sfp_info(vha
);
3417 if (a
->fc_ll_cc7
& FC_LL_VL
|| a
->fc_ll_cc7
& FC_LL_L
) {
3419 ha
->flags
.detected_lr_sfp
= 1;
3421 if (a
->length_km
> 5 || a
->length_100m
> 50)
3422 ha
->long_range_distance
= LR_DISTANCE_10K
;
3424 ha
->long_range_distance
= LR_DISTANCE_5K
;
3426 if (ha
->flags
.detected_lr_sfp
!= ha
->flags
.using_lr_setting
)
3427 ql_dbg(ql_dbg_async
, vha
, 0x507b,
3428 "Detected Long Range SFP.\n");
3431 ha
->flags
.detected_lr_sfp
= 0;
3432 if (ha
->flags
.using_lr_setting
)
3433 ql_dbg(ql_dbg_async
, vha
, 0x5084,
3434 "Detected Short Range SFP.\n");
3437 if (!vha
->flags
.init_done
)
3444 * qla2x00_setup_chip() - Load and start RISC firmware.
3447 * Returns 0 on success.
3450 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
3453 uint32_t srisc_address
= 0;
3454 struct qla_hw_data
*ha
= vha
->hw
;
3455 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3456 unsigned long flags
;
3457 uint16_t fw_major_version
;
3459 if (IS_P3P_TYPE(ha
)) {
3460 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3461 if (rval
== QLA_SUCCESS
) {
3462 qla2x00_stop_firmware(vha
);
3463 goto enable_82xx_npiv
;
3468 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3469 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3470 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3471 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3472 RD_REG_WORD(®
->hccr
);
3473 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3476 qla81xx_mpi_sync(vha
);
3478 /* Load firmware sequences */
3479 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3480 if (rval
== QLA_SUCCESS
) {
3481 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
3482 "Verifying Checksum of loaded RISC code.\n");
3484 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
3485 if (rval
== QLA_SUCCESS
) {
3486 /* Start firmware execution. */
3487 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3488 "Starting firmware.\n");
3491 ha
->flags
.exlogins_enabled
= 1;
3493 if (qla_is_exch_offld_enabled(vha
))
3494 ha
->flags
.exchoffld_enabled
= 1;
3496 rval
= qla2x00_execute_fw(vha
, srisc_address
);
3497 /* Retrieve firmware information. */
3498 if (rval
== QLA_SUCCESS
) {
3499 qla24xx_detect_sfp(vha
);
3501 if ((IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) &&
3502 (ha
->zio_mode
== QLA_ZIO_MODE_6
))
3503 qla27xx_set_zio_threshold(vha
,
3504 ha
->last_zio_threshold
);
3506 rval
= qla2x00_set_exlogins_buffer(vha
);
3507 if (rval
!= QLA_SUCCESS
)
3510 rval
= qla2x00_set_exchoffld_buffer(vha
);
3511 if (rval
!= QLA_SUCCESS
)
3515 fw_major_version
= ha
->fw_major_version
;
3516 if (IS_P3P_TYPE(ha
))
3517 qla82xx_check_md_needed(vha
);
3519 rval
= qla2x00_get_fw_version(vha
);
3520 if (rval
!= QLA_SUCCESS
)
3522 ha
->flags
.npiv_supported
= 0;
3523 if (IS_QLA2XXX_MIDTYPE(ha
) &&
3524 (ha
->fw_attributes
& BIT_2
)) {
3525 ha
->flags
.npiv_supported
= 1;
3526 if ((!ha
->max_npiv_vports
) ||
3527 ((ha
->max_npiv_vports
+ 1) %
3528 MIN_MULTI_ID_FABRIC
))
3529 ha
->max_npiv_vports
=
3530 MIN_MULTI_ID_FABRIC
- 1;
3532 qla2x00_get_resource_cnts(vha
);
3535 * Allocate the array of outstanding commands
3536 * now that we know the firmware resources.
3538 rval
= qla2x00_alloc_outstanding_cmds(ha
,
3540 if (rval
!= QLA_SUCCESS
)
3543 if (!fw_major_version
&& !(IS_P3P_TYPE(ha
)))
3544 qla2x00_alloc_offload_mem(vha
);
3546 if (ql2xallocfwdump
&& !(IS_P3P_TYPE(ha
)))
3547 qla2x00_alloc_fw_dump(vha
);
3553 ql_log(ql_log_fatal
, vha
, 0x00cd,
3554 "ISP Firmware failed checksum.\n");
3560 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3561 /* Enable proper parity. */
3562 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3565 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
3567 /* SRAM, Instruction RAM and GP RAM parity */
3568 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
3569 RD_REG_WORD(®
->hccr
);
3570 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3574 ha
->flags
.fac_supported
= 1;
3575 else if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
3578 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
3579 if (rval
== QLA_SUCCESS
) {
3580 ha
->flags
.fac_supported
= 1;
3581 ha
->fdt_block_size
= size
<< 2;
3583 ql_log(ql_log_warn
, vha
, 0x00ce,
3584 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3585 ha
->fw_major_version
, ha
->fw_minor_version
,
3586 ha
->fw_subminor_version
);
3588 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3589 ha
->flags
.fac_supported
= 0;
3596 ql_log(ql_log_fatal
, vha
, 0x00cf,
3597 "Setup chip ****FAILED****.\n");
3604 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3605 * @rsp: response queue
3607 * Beginning of request ring has initialization control block already built
3608 * by nvram config routine.
3610 * Returns 0 on success.
3613 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
3618 rsp
->ring_ptr
= rsp
->ring
;
3619 rsp
->ring_index
= 0;
3620 rsp
->status_srb
= NULL
;
3621 pkt
= rsp
->ring_ptr
;
3622 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
3623 pkt
->signature
= RESPONSE_PROCESSED
;
3629 * qla2x00_update_fw_options() - Read and process firmware options.
3632 * Returns 0 on success.
3635 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
3637 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
3638 struct qla_hw_data
*ha
= vha
->hw
;
3640 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
3641 qla2x00_get_fw_options(vha
, ha
->fw_options
);
3643 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3646 /* Serial Link options. */
3647 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
3648 "Serial link options.\n");
3649 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
3650 (uint8_t *)&ha
->fw_seriallink_options
,
3651 sizeof(ha
->fw_seriallink_options
));
3653 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
3654 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
3655 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
3658 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
3659 emphasis
= (ha
->fw_seriallink_options
[2] &
3660 (BIT_4
| BIT_3
)) >> 3;
3661 tx_sens
= ha
->fw_seriallink_options
[0] &
3662 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3663 rx_sens
= (ha
->fw_seriallink_options
[0] &
3664 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3665 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
3666 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3669 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
3670 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3671 ha
->fw_options
[10] |= BIT_5
|
3672 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3673 (tx_sens
& (BIT_1
| BIT_0
));
3676 swing
= (ha
->fw_seriallink_options
[2] &
3677 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
3678 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
3679 tx_sens
= ha
->fw_seriallink_options
[1] &
3680 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3681 rx_sens
= (ha
->fw_seriallink_options
[1] &
3682 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3683 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
3684 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3687 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
3688 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3689 ha
->fw_options
[11] |= BIT_5
|
3690 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3691 (tx_sens
& (BIT_1
| BIT_0
));
3695 /* Return command IOCBs without waiting for an ABTS to complete. */
3696 ha
->fw_options
[3] |= BIT_13
;
3699 if (ha
->flags
.enable_led_scheme
)
3700 ha
->fw_options
[2] |= BIT_12
;
3702 /* Detect ISP6312. */
3704 ha
->fw_options
[2] |= BIT_13
;
3706 /* Set Retry FLOGI in case of P2P connection */
3707 if (ha
->operating_mode
== P2P
) {
3708 ha
->fw_options
[2] |= BIT_3
;
3709 ql_dbg(ql_dbg_disc
, vha
, 0x2100,
3710 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3711 __func__
, ha
->fw_options
[2]);
3714 /* Update firmware options. */
3715 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3719 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
3722 struct qla_hw_data
*ha
= vha
->hw
;
3724 if (IS_P3P_TYPE(ha
))
3727 /* Hold status IOCBs until ABTS response received. */
3729 ha
->fw_options
[3] |= BIT_12
;
3731 /* Set Retry FLOGI in case of P2P connection */
3732 if (ha
->operating_mode
== P2P
) {
3733 ha
->fw_options
[2] |= BIT_3
;
3734 ql_dbg(ql_dbg_disc
, vha
, 0x2101,
3735 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3736 __func__
, ha
->fw_options
[2]);
3739 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3740 if (ql2xmvasynctoatio
&&
3741 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))) {
3742 if (qla_tgt_mode_enabled(vha
) ||
3743 qla_dual_mode_enabled(vha
))
3744 ha
->fw_options
[2] |= BIT_11
;
3746 ha
->fw_options
[2] &= ~BIT_11
;
3749 if (IS_QLA25XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3751 * Tell FW to track each exchange to prevent
3752 * driver from using stale exchange.
3754 if (qla_tgt_mode_enabled(vha
) ||
3755 qla_dual_mode_enabled(vha
))
3756 ha
->fw_options
[2] |= BIT_4
;
3758 ha
->fw_options
[2] &= ~BIT_4
;
3760 /* Reserve 1/2 of emergency exchanges for ELS.*/
3761 if (qla2xuseresexchforels
)
3762 ha
->fw_options
[2] |= BIT_8
;
3764 ha
->fw_options
[2] &= ~BIT_8
;
3767 ql_dbg(ql_dbg_init
, vha
, 0x00e8,
3768 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3769 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
3770 ha
->fw_options
[3], vha
->host
->active_mode
);
3772 if (ha
->fw_options
[1] || ha
->fw_options
[2] || ha
->fw_options
[3])
3773 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3775 /* Update Serial Link options. */
3776 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
3779 rval
= qla2x00_set_serdes_params(vha
,
3780 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
3781 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
3782 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
3783 if (rval
!= QLA_SUCCESS
) {
3784 ql_log(ql_log_warn
, vha
, 0x0104,
3785 "Unable to update Serial Link options (%x).\n", rval
);
3790 qla2x00_config_rings(struct scsi_qla_host
*vha
)
3792 struct qla_hw_data
*ha
= vha
->hw
;
3793 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3794 struct req_que
*req
= ha
->req_q_map
[0];
3795 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3797 /* Setup ring parameters in initialization control block. */
3798 ha
->init_cb
->request_q_outpointer
= cpu_to_le16(0);
3799 ha
->init_cb
->response_q_inpointer
= cpu_to_le16(0);
3800 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
3801 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
3802 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3803 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3804 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3805 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3807 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
3808 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
3809 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
3810 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
3811 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
3815 qla24xx_config_rings(struct scsi_qla_host
*vha
)
3817 struct qla_hw_data
*ha
= vha
->hw
;
3818 device_reg_t
*reg
= ISP_QUE_REG(ha
, 0);
3819 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
3820 struct qla_msix_entry
*msix
;
3821 struct init_cb_24xx
*icb
;
3823 struct req_que
*req
= ha
->req_q_map
[0];
3824 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3826 /* Setup ring parameters in initialization control block. */
3827 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3828 icb
->request_q_outpointer
= cpu_to_le16(0);
3829 icb
->response_q_inpointer
= cpu_to_le16(0);
3830 icb
->request_q_length
= cpu_to_le16(req
->length
);
3831 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
3832 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3833 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3834 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3835 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3837 /* Setup ATIO queue dma pointers for target mode */
3838 icb
->atio_q_inpointer
= cpu_to_le16(0);
3839 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
3840 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
3841 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
3843 if (IS_SHADOW_REG_CAPABLE(ha
))
3844 icb
->firmware_options_2
|= cpu_to_le32(BIT_30
|BIT_29
);
3846 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3847 icb
->qos
= cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
3848 icb
->rid
= cpu_to_le16(rid
);
3849 if (ha
->flags
.msix_enabled
) {
3850 msix
= &ha
->msix_entries
[1];
3851 ql_dbg(ql_dbg_init
, vha
, 0x0019,
3852 "Registering vector 0x%x for base que.\n",
3854 icb
->msix
= cpu_to_le16(msix
->entry
);
3856 /* Use alternate PCI bus number */
3858 icb
->firmware_options_2
|= cpu_to_le32(BIT_19
);
3859 /* Use alternate PCI devfn */
3861 icb
->firmware_options_2
|= cpu_to_le32(BIT_18
);
3863 /* Use Disable MSIX Handshake mode for capable adapters */
3864 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
3865 (ha
->flags
.msix_enabled
)) {
3866 icb
->firmware_options_2
&= cpu_to_le32(~BIT_22
);
3867 ha
->flags
.disable_msix_handshake
= 1;
3868 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
3869 "MSIX Handshake Disable Mode turned on.\n");
3871 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
3873 icb
->firmware_options_2
|= cpu_to_le32(BIT_23
);
3875 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
3876 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
3877 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
3878 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
3880 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
3881 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
3882 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
3883 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
3886 qlt_24xx_config_rings(vha
);
3888 /* If the user has configured the speed, set it here */
3889 if (ha
->set_data_rate
) {
3890 ql_dbg(ql_dbg_init
, vha
, 0x00fd,
3891 "Speed set by user : %s Gbps \n",
3892 qla2x00_get_link_speed_str(ha
, ha
->set_data_rate
));
3893 icb
->firmware_options_3
= (ha
->set_data_rate
<< 13);
3897 RD_REG_DWORD(&ioreg
->hccr
);
3901 * qla2x00_init_rings() - Initializes firmware.
3904 * Beginning of request ring has initialization control block already built
3905 * by nvram config routine.
3907 * Returns 0 on success.
3910 qla2x00_init_rings(scsi_qla_host_t
*vha
)
3913 unsigned long flags
= 0;
3915 struct qla_hw_data
*ha
= vha
->hw
;
3916 struct req_que
*req
;
3917 struct rsp_que
*rsp
;
3918 struct mid_init_cb_24xx
*mid_init_cb
=
3919 (struct mid_init_cb_24xx
*) ha
->init_cb
;
3921 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3923 /* Clear outstanding commands array. */
3924 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
3925 req
= ha
->req_q_map
[que
];
3926 if (!req
|| !test_bit(que
, ha
->req_qid_map
))
3928 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
3930 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
3931 req
->outstanding_cmds
[cnt
] = NULL
;
3933 req
->current_outstanding_cmd
= 1;
3935 /* Initialize firmware. */
3936 req
->ring_ptr
= req
->ring
;
3937 req
->ring_index
= 0;
3938 req
->cnt
= req
->length
;
3941 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
3942 rsp
= ha
->rsp_q_map
[que
];
3943 if (!rsp
|| !test_bit(que
, ha
->rsp_qid_map
))
3945 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
3947 /* Initialize response queue entries */
3949 qlafx00_init_response_q_entries(rsp
);
3951 qla2x00_init_response_q_entries(rsp
);
3954 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
3955 ha
->tgt
.atio_ring_index
= 0;
3956 /* Initialize ATIO queue entries */
3957 qlt_init_atio_q_entries(vha
);
3959 ha
->isp_ops
->config_rings(vha
);
3961 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3963 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
3965 if (IS_QLAFX00(ha
)) {
3966 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
3970 /* Update any ISP specific firmware options before initialization. */
3971 ha
->isp_ops
->update_fw_options(vha
);
3973 if (ha
->flags
.npiv_supported
) {
3974 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
3975 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
3976 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
3979 if (IS_FWI2_CAPABLE(ha
)) {
3980 mid_init_cb
->options
= cpu_to_le16(BIT_1
);
3981 mid_init_cb
->init_cb
.execution_throttle
=
3982 cpu_to_le16(ha
->cur_fw_xcb_count
);
3983 ha
->flags
.dport_enabled
=
3984 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_7
) != 0;
3985 ql_dbg(ql_dbg_init
, vha
, 0x0191, "DPORT Support: %s.\n",
3986 (ha
->flags
.dport_enabled
) ? "enabled" : "disabled");
3987 /* FA-WWPN Status */
3988 ha
->flags
.fawwpn_enabled
=
3989 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_6
) != 0;
3990 ql_dbg(ql_dbg_init
, vha
, 0x00bc, "FA-WWPN Support: %s.\n",
3991 (ha
->flags
.fawwpn_enabled
) ? "enabled" : "disabled");
3994 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
3997 ql_log(ql_log_fatal
, vha
, 0x00d2,
3998 "Init Firmware **** FAILED ****.\n");
4000 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
4001 "Init Firmware -- success.\n");
4003 vha
->u_ql2xexchoffld
= vha
->u_ql2xiniexchg
= 0;
4010 * qla2x00_fw_ready() - Waits for firmware ready.
4013 * Returns 0 on success.
4016 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
4019 unsigned long wtime
, mtime
, cs84xx_time
;
4020 uint16_t min_wait
; /* Minimum wait time if loop is down */
4021 uint16_t wait_time
; /* Wait time if loop is coming ready */
4023 struct qla_hw_data
*ha
= vha
->hw
;
4025 if (IS_QLAFX00(vha
->hw
))
4026 return qlafx00_fw_ready(vha
);
4030 /* Time to wait for loop down */
4031 if (IS_P3P_TYPE(ha
))
4037 * Firmware should take at most one RATOV to login, plus 5 seconds for
4038 * our own processing.
4040 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
4041 wait_time
= min_wait
;
4044 /* Min wait time if loop down */
4045 mtime
= jiffies
+ (min_wait
* HZ
);
4047 /* wait time before firmware ready */
4048 wtime
= jiffies
+ (wait_time
* HZ
);
4050 /* Wait for ISP to finish LIP */
4051 if (!vha
->flags
.init_done
)
4052 ql_log(ql_log_info
, vha
, 0x801e,
4053 "Waiting for LIP to complete.\n");
4056 memset(state
, -1, sizeof(state
));
4057 rval
= qla2x00_get_firmware_state(vha
, state
);
4058 if (rval
== QLA_SUCCESS
) {
4059 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
4060 vha
->device_flags
&= ~DFLG_NO_CABLE
;
4062 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
4063 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
4064 "fw_state=%x 84xx=%x.\n", state
[0],
4066 if ((state
[2] & FSTATE_LOGGED_IN
) &&
4067 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
4068 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
4069 "Sending verify iocb.\n");
4071 cs84xx_time
= jiffies
;
4072 rval
= qla84xx_init_chip(vha
);
4073 if (rval
!= QLA_SUCCESS
) {
4076 "Init chip failed.\n");
4080 /* Add time taken to initialize. */
4081 cs84xx_time
= jiffies
- cs84xx_time
;
4082 wtime
+= cs84xx_time
;
4083 mtime
+= cs84xx_time
;
4084 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
4085 "Increasing wait time by %ld. "
4086 "New time %ld.\n", cs84xx_time
,
4089 } else if (state
[0] == FSTATE_READY
) {
4090 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
4091 "F/W Ready - OK.\n");
4093 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
4094 &ha
->login_timeout
, &ha
->r_a_tov
);
4100 rval
= QLA_FUNCTION_FAILED
;
4102 if (atomic_read(&vha
->loop_down_timer
) &&
4103 state
[0] != FSTATE_READY
) {
4104 /* Loop down. Timeout on min_wait for states
4105 * other than Wait for Login.
4107 if (time_after_eq(jiffies
, mtime
)) {
4108 ql_log(ql_log_info
, vha
, 0x8038,
4109 "Cable is unplugged...\n");
4111 vha
->device_flags
|= DFLG_NO_CABLE
;
4116 /* Mailbox cmd failed. Timeout on min_wait. */
4117 if (time_after_eq(jiffies
, mtime
) ||
4118 ha
->flags
.isp82xx_fw_hung
)
4122 if (time_after_eq(jiffies
, wtime
))
4125 /* Delay for a while */
4129 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
4130 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state
[0],
4131 state
[1], state
[2], state
[3], state
[4], state
[5], jiffies
);
4133 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
4134 ql_log(ql_log_warn
, vha
, 0x803b,
4135 "Firmware ready **** FAILED ****.\n");
4142 * qla2x00_configure_hba
4143 * Setup adapter context.
4146 * ha = adapter state pointer.
4155 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
4164 char connect_type
[22];
4165 struct qla_hw_data
*ha
= vha
->hw
;
4166 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4168 unsigned long flags
;
4170 /* Get host addresses. */
4171 rval
= qla2x00_get_adapter_id(vha
,
4172 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
4173 if (rval
!= QLA_SUCCESS
) {
4174 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
4175 IS_CNA_CAPABLE(ha
) ||
4176 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
4177 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
4178 "Loop is in a transition state.\n");
4180 ql_log(ql_log_warn
, vha
, 0x2009,
4181 "Unable to get host loop ID.\n");
4182 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
4183 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
4184 ql_log(ql_log_warn
, vha
, 0x1151,
4185 "Doing link init.\n");
4186 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
4189 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4195 ql_log(ql_log_info
, vha
, 0x200a,
4196 "Cannot get topology - retrying.\n");
4197 return (QLA_FUNCTION_FAILED
);
4200 vha
->loop_id
= loop_id
;
4203 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
4204 ha
->operating_mode
= LOOP
;
4209 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
4210 ha
->current_topology
= ISP_CFG_NL
;
4211 strcpy(connect_type
, "(Loop)");
4215 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
4216 ha
->switch_cap
= sw_cap
;
4217 ha
->current_topology
= ISP_CFG_FL
;
4218 strcpy(connect_type
, "(FL_Port)");
4222 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
4223 ha
->operating_mode
= P2P
;
4224 ha
->current_topology
= ISP_CFG_N
;
4225 strcpy(connect_type
, "(N_Port-to-N_Port)");
4229 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
4230 ha
->switch_cap
= sw_cap
;
4231 ha
->operating_mode
= P2P
;
4232 ha
->current_topology
= ISP_CFG_F
;
4233 strcpy(connect_type
, "(F_Port)");
4237 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
4238 "HBA in unknown topology %x, using NL.\n", topo
);
4239 ha
->current_topology
= ISP_CFG_NL
;
4240 strcpy(connect_type
, "(Loop)");
4244 /* Save Host port and loop ID. */
4245 /* byte order - Big Endian */
4246 id
.b
.domain
= domain
;
4250 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4251 if (!(topo
== 2 && ha
->flags
.n2n_bigger
))
4252 qlt_update_host_map(vha
, id
);
4253 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4255 if (!vha
->flags
.init_done
)
4256 ql_log(ql_log_info
, vha
, 0x2010,
4257 "Topology - %s, Host Loop address 0x%x.\n",
4258 connect_type
, vha
->loop_id
);
4264 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
4269 struct qla_hw_data
*ha
= vha
->hw
;
4270 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
4271 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
4273 if (memcmp(model
, BINZERO
, len
) != 0) {
4274 strncpy(ha
->model_number
, model
, len
);
4275 st
= en
= ha
->model_number
;
4278 if (*en
!= 0x20 && *en
!= 0x00)
4283 index
= (ha
->pdev
->subsystem_device
& 0xff);
4285 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4286 index
< QLA_MODEL_NAMES
)
4287 strncpy(ha
->model_desc
,
4288 qla2x00_model_name
[index
* 2 + 1],
4289 sizeof(ha
->model_desc
) - 1);
4291 index
= (ha
->pdev
->subsystem_device
& 0xff);
4293 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4294 index
< QLA_MODEL_NAMES
) {
4295 strcpy(ha
->model_number
,
4296 qla2x00_model_name
[index
* 2]);
4297 strncpy(ha
->model_desc
,
4298 qla2x00_model_name
[index
* 2 + 1],
4299 sizeof(ha
->model_desc
) - 1);
4301 strcpy(ha
->model_number
, def
);
4304 if (IS_FWI2_CAPABLE(ha
))
4305 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
4306 sizeof(ha
->model_desc
));
4309 /* On sparc systems, obtain port and node WWN from firmware
4312 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
4315 struct qla_hw_data
*ha
= vha
->hw
;
4316 struct pci_dev
*pdev
= ha
->pdev
;
4317 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4321 val
= of_get_property(dp
, "port-wwn", &len
);
4322 if (val
&& len
>= WWN_SIZE
)
4323 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4325 val
= of_get_property(dp
, "node-wwn", &len
);
4326 if (val
&& len
>= WWN_SIZE
)
4327 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4332 * NVRAM configuration for ISP 2xxx
4335 * ha = adapter block pointer.
4338 * initialization control block in response_ring
4339 * host adapters parameters in host adapter block
4345 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
4350 uint8_t *dptr1
, *dptr2
;
4351 struct qla_hw_data
*ha
= vha
->hw
;
4352 init_cb_t
*icb
= ha
->init_cb
;
4353 nvram_t
*nv
= ha
->nvram
;
4354 uint8_t *ptr
= ha
->nvram
;
4355 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4359 /* Determine NVRAM starting address. */
4360 ha
->nvram_size
= sizeof(nvram_t
);
4362 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
4363 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
4364 ha
->nvram_base
= 0x80;
4366 /* Get NVRAM data and calculate checksum. */
4367 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
4368 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
4371 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
4372 "Contents of NVRAM.\n");
4373 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
4374 (uint8_t *)nv
, ha
->nvram_size
);
4376 /* Bad NVRAM data, set defaults parameters. */
4377 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
4378 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
4379 /* Reset NVRAM data. */
4380 ql_log(ql_log_warn
, vha
, 0x0064,
4381 "Inconsistent NVRAM "
4382 "detected: checksum=0x%x id=%c version=0x%x.\n",
4383 chksum
, nv
->id
[0], nv
->nvram_version
);
4384 ql_log(ql_log_warn
, vha
, 0x0065,
4386 "functioning (yet invalid -- WWPN) defaults.\n");
4389 * Set default initialization control block.
4391 memset(nv
, 0, ha
->nvram_size
);
4392 nv
->parameter_block_version
= ICB_VERSION
;
4394 if (IS_QLA23XX(ha
)) {
4395 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4396 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4397 nv
->add_firmware_options
[0] = BIT_5
;
4398 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4399 nv
->frame_payload_size
= 2048;
4400 nv
->special_options
[1] = BIT_7
;
4401 } else if (IS_QLA2200(ha
)) {
4402 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4403 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4404 nv
->add_firmware_options
[0] = BIT_5
;
4405 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4406 nv
->frame_payload_size
= 1024;
4407 } else if (IS_QLA2100(ha
)) {
4408 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
4409 nv
->firmware_options
[1] = BIT_5
;
4410 nv
->frame_payload_size
= 1024;
4413 nv
->max_iocb_allocation
= cpu_to_le16(256);
4414 nv
->execution_throttle
= cpu_to_le16(16);
4415 nv
->retry_count
= 8;
4416 nv
->retry_delay
= 1;
4418 nv
->port_name
[0] = 33;
4419 nv
->port_name
[3] = 224;
4420 nv
->port_name
[4] = 139;
4422 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
4424 nv
->login_timeout
= 4;
4427 * Set default host adapter parameters
4429 nv
->host_p
[1] = BIT_2
;
4430 nv
->reset_delay
= 5;
4431 nv
->port_down_retry_count
= 8;
4432 nv
->max_luns_per_target
= cpu_to_le16(8);
4433 nv
->link_down_timeout
= 60;
4438 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4440 * The SN2 does not provide BIOS emulation which means you can't change
4441 * potentially bogus BIOS settings. Force the use of default settings
4442 * for link rate and frame size. Hope that the rest of the settings
4445 if (ia64_platform_is("sn2")) {
4446 nv
->frame_payload_size
= 2048;
4448 nv
->special_options
[1] = BIT_7
;
4452 /* Reset Initialization control block */
4453 memset(icb
, 0, ha
->init_cb_size
);
4456 * Setup driver NVRAM options.
4458 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
4459 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
4460 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
4461 nv
->firmware_options
[1] &= ~BIT_4
;
4463 if (IS_QLA23XX(ha
)) {
4464 nv
->firmware_options
[0] |= BIT_2
;
4465 nv
->firmware_options
[0] &= ~BIT_3
;
4466 nv
->special_options
[0] &= ~BIT_6
;
4467 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
4469 if (IS_QLA2300(ha
)) {
4470 if (ha
->fb_rev
== FPM_2310
) {
4471 strcpy(ha
->model_number
, "QLA2310");
4473 strcpy(ha
->model_number
, "QLA2300");
4476 qla2x00_set_model_info(vha
, nv
->model_number
,
4477 sizeof(nv
->model_number
), "QLA23xx");
4479 } else if (IS_QLA2200(ha
)) {
4480 nv
->firmware_options
[0] |= BIT_2
;
4482 * 'Point-to-point preferred, else loop' is not a safe
4483 * connection mode setting.
4485 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
4487 /* Force 'loop preferred, else point-to-point'. */
4488 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
4489 nv
->add_firmware_options
[0] |= BIT_5
;
4491 strcpy(ha
->model_number
, "QLA22xx");
4492 } else /*if (IS_QLA2100(ha))*/ {
4493 strcpy(ha
->model_number
, "QLA2100");
4497 * Copy over NVRAM RISC parameter block to initialization control block.
4499 dptr1
= (uint8_t *)icb
;
4500 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
4501 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
4503 *dptr1
++ = *dptr2
++;
4505 /* Copy 2nd half. */
4506 dptr1
= (uint8_t *)icb
->add_firmware_options
;
4507 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
4509 *dptr1
++ = *dptr2
++;
4510 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
4511 /* Use alternate WWN? */
4512 if (nv
->host_p
[1] & BIT_7
) {
4513 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4514 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4517 /* Prepare nodename */
4518 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
4520 * Firmware will apply the following mask if the nodename was
4523 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4524 icb
->node_name
[0] &= 0xF0;
4528 * Set host adapter parameters.
4532 * BIT_7 in the host-parameters section allows for modification to
4533 * internal driver logging.
4535 if (nv
->host_p
[0] & BIT_7
)
4536 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
4537 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
4538 /* Always load RISC code on non ISP2[12]00 chips. */
4539 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
4540 ha
->flags
.disable_risc_code_load
= 0;
4541 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
4542 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
4543 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
4544 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
4545 ha
->flags
.disable_serdes
= 0;
4547 ha
->operating_mode
=
4548 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4550 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
4551 sizeof(ha
->fw_seriallink_options
));
4553 /* save HBA serial number */
4554 ha
->serial0
= icb
->port_name
[5];
4555 ha
->serial1
= icb
->port_name
[6];
4556 ha
->serial2
= icb
->port_name
[7];
4557 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4558 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4560 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
4562 ha
->retry_count
= nv
->retry_count
;
4564 /* Set minimum login_timeout to 4 seconds. */
4565 if (nv
->login_timeout
!= ql2xlogintimeout
)
4566 nv
->login_timeout
= ql2xlogintimeout
;
4567 if (nv
->login_timeout
< 4)
4568 nv
->login_timeout
= 4;
4569 ha
->login_timeout
= nv
->login_timeout
;
4571 /* Set minimum RATOV to 100 tenths of a second. */
4574 ha
->loop_reset_delay
= nv
->reset_delay
;
4576 /* Link Down Timeout = 0:
4578 * When Port Down timer expires we will start returning
4579 * I/O's to OS with "DID_NO_CONNECT".
4581 * Link Down Timeout != 0:
4583 * The driver waits for the link to come up after link down
4584 * before returning I/Os to OS with "DID_NO_CONNECT".
4586 if (nv
->link_down_timeout
== 0) {
4587 ha
->loop_down_abort_time
=
4588 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4590 ha
->link_down_timeout
= nv
->link_down_timeout
;
4591 ha
->loop_down_abort_time
=
4592 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4596 * Need enough time to try and get the port back.
4598 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
4599 if (qlport_down_retry
)
4600 ha
->port_down_retry_count
= qlport_down_retry
;
4601 /* Set login_retry_count */
4602 ha
->login_retry_count
= nv
->retry_count
;
4603 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
4604 ha
->port_down_retry_count
> 3)
4605 ha
->login_retry_count
= ha
->port_down_retry_count
;
4606 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4607 ha
->login_retry_count
= ha
->port_down_retry_count
;
4608 if (ql2xloginretrycount
)
4609 ha
->login_retry_count
= ql2xloginretrycount
;
4611 icb
->lun_enables
= cpu_to_le16(0);
4612 icb
->command_resource_count
= 0;
4613 icb
->immediate_notify_resource_count
= 0;
4614 icb
->timeout
= cpu_to_le16(0);
4616 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
4618 icb
->firmware_options
[0] &= ~BIT_3
;
4619 icb
->add_firmware_options
[0] &=
4620 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4621 icb
->add_firmware_options
[0] |= BIT_2
;
4622 icb
->response_accumulation_timer
= 3;
4623 icb
->interrupt_delay_timer
= 5;
4625 vha
->flags
.process_response_queue
= 1;
4628 if (!vha
->flags
.init_done
) {
4629 ha
->zio_mode
= icb
->add_firmware_options
[0] &
4630 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4631 ha
->zio_timer
= icb
->interrupt_delay_timer
?
4632 icb
->interrupt_delay_timer
: 2;
4634 icb
->add_firmware_options
[0] &=
4635 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4636 vha
->flags
.process_response_queue
= 0;
4637 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4638 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4640 ql_log(ql_log_info
, vha
, 0x0068,
4641 "ZIO mode %d enabled; timer delay (%d us).\n",
4642 ha
->zio_mode
, ha
->zio_timer
* 100);
4644 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
4645 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
4646 vha
->flags
.process_response_queue
= 1;
4651 ql_log(ql_log_warn
, vha
, 0x0069,
4652 "NVRAM configuration failed.\n");
4658 qla2x00_rport_del(void *data
)
4660 fc_port_t
*fcport
= data
;
4661 struct fc_rport
*rport
;
4662 unsigned long flags
;
4664 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
4665 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
4666 fcport
->drport
= NULL
;
4667 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
4669 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210b,
4670 "%s %8phN. rport %p roles %x\n",
4671 __func__
, fcport
->port_name
, rport
,
4674 fc_remote_port_delete(rport
);
4679 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4681 * @flags: allocation flags
4683 * Returns a pointer to the allocated fcport, or NULL, if none available.
4686 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
4690 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
4694 fcport
->ct_desc
.ct_sns
= dma_alloc_coherent(&vha
->hw
->pdev
->dev
,
4695 sizeof(struct ct_sns_pkt
), &fcport
->ct_desc
.ct_sns_dma
,
4697 if (!fcport
->ct_desc
.ct_sns
) {
4698 ql_log(ql_log_warn
, vha
, 0xd049,
4699 "Failed to allocate ct_sns request.\n");
4704 /* Setup fcport template structure. */
4706 fcport
->port_type
= FCT_UNKNOWN
;
4707 fcport
->loop_id
= FC_NO_LOOP_ID
;
4708 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
4709 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
4710 fcport
->fp_speed
= PORT_SPEED_UNKNOWN
;
4712 fcport
->disc_state
= DSC_DELETED
;
4713 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4714 fcport
->deleted
= QLA_SESS_DELETED
;
4715 fcport
->login_retry
= vha
->hw
->login_retry_count
;
4716 fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
4717 fcport
->logout_on_delete
= 1;
4719 if (!fcport
->ct_desc
.ct_sns
) {
4720 ql_log(ql_log_warn
, vha
, 0xd049,
4721 "Failed to allocate ct_sns request.\n");
4726 INIT_WORK(&fcport
->del_work
, qla24xx_delete_sess_fn
);
4727 INIT_WORK(&fcport
->reg_work
, qla_register_fcport_fn
);
4728 INIT_LIST_HEAD(&fcport
->gnl_entry
);
4729 INIT_LIST_HEAD(&fcport
->list
);
4735 qla2x00_free_fcport(fc_port_t
*fcport
)
4737 if (fcport
->ct_desc
.ct_sns
) {
4738 dma_free_coherent(&fcport
->vha
->hw
->pdev
->dev
,
4739 sizeof(struct ct_sns_pkt
), fcport
->ct_desc
.ct_sns
,
4740 fcport
->ct_desc
.ct_sns_dma
);
4742 fcport
->ct_desc
.ct_sns
= NULL
;
4748 * qla2x00_configure_loop
4749 * Updates Fibre Channel Device Database with what is actually on loop.
4752 * ha = adapter block pointer.
4757 * 2 = database was full and device was not configured.
4760 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
4763 unsigned long flags
, save_flags
;
4764 struct qla_hw_data
*ha
= vha
->hw
;
4767 /* Get Initiator ID */
4768 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
4769 rval
= qla2x00_configure_hba(vha
);
4770 if (rval
!= QLA_SUCCESS
) {
4771 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
4772 "Unable to configure HBA.\n");
4777 save_flags
= flags
= vha
->dpc_flags
;
4778 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
4779 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
4782 * If we have both an RSCN and PORT UPDATE pending then handle them
4783 * both at the same time.
4785 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4786 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4788 qla2x00_get_data_rate(vha
);
4790 /* Determine what we need to do */
4791 if (ha
->current_topology
== ISP_CFG_FL
&&
4792 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4794 set_bit(RSCN_UPDATE
, &flags
);
4796 } else if (ha
->current_topology
== ISP_CFG_F
&&
4797 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4799 set_bit(RSCN_UPDATE
, &flags
);
4800 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4802 } else if (ha
->current_topology
== ISP_CFG_N
) {
4803 clear_bit(RSCN_UPDATE
, &flags
);
4804 if (qla_tgt_mode_enabled(vha
)) {
4805 /* allow the other side to start the login */
4806 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4807 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4809 } else if (ha
->current_topology
== ISP_CFG_NL
) {
4810 clear_bit(RSCN_UPDATE
, &flags
);
4811 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4812 } else if (!vha
->flags
.online
||
4813 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
4814 set_bit(RSCN_UPDATE
, &flags
);
4815 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4818 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
4819 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4820 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
4821 "Loop resync needed, failing.\n");
4822 rval
= QLA_FUNCTION_FAILED
;
4824 rval
= qla2x00_configure_local_loop(vha
);
4827 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
4828 if (LOOP_TRANSITION(vha
)) {
4829 ql_dbg(ql_dbg_disc
, vha
, 0x2099,
4830 "Needs RSCN update and loop transition.\n");
4831 rval
= QLA_FUNCTION_FAILED
;
4834 rval
= qla2x00_configure_fabric(vha
);
4837 if (rval
== QLA_SUCCESS
) {
4838 if (atomic_read(&vha
->loop_down_timer
) ||
4839 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4840 rval
= QLA_FUNCTION_FAILED
;
4842 atomic_set(&vha
->loop_state
, LOOP_READY
);
4843 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
4845 ha
->flags
.fw_init_done
= 1;
4848 * Process any ATIO queue entries that came in
4849 * while we weren't online.
4851 if (qla_tgt_mode_enabled(vha
) ||
4852 qla_dual_mode_enabled(vha
)) {
4853 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
4854 qlt_24xx_process_atio_queue(vha
, 0);
4855 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
,
4862 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
4863 "%s *** FAILED ***.\n", __func__
);
4865 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
4866 "%s: exiting normally.\n", __func__
);
4869 /* Restore state if a resync event occurred during processing */
4870 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4871 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
4872 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4873 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
4874 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4882 * qla2x00_configure_local_loop
4883 * Updates Fibre Channel Device Database with local loop devices.
4886 * ha = adapter block pointer.
4892 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
4897 fc_port_t
*fcport
, *new_fcport
;
4903 uint8_t domain
, area
, al_pa
;
4904 struct qla_hw_data
*ha
= vha
->hw
;
4905 unsigned long flags
;
4907 /* Inititae N2N login. */
4908 if (test_and_clear_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
)) {
4912 memset(ha
->init_cb
, 0, ha
->init_cb_size
);
4913 sz
= min_t(int, sizeof(struct els_plogi_payload
),
4915 rval
= qla24xx_get_port_login_templ(vha
, ha
->init_cb_dma
,
4916 (void *)ha
->init_cb
, sz
);
4917 if (rval
== QLA_SUCCESS
) {
4918 bp
= (uint32_t *)ha
->init_cb
;
4919 for (i
= 0; i
< sz
/4 ; i
++, bp
++)
4920 *bp
= cpu_to_be32(*bp
);
4922 memcpy(&ha
->plogi_els_payld
.data
, (void *)ha
->init_cb
,
4923 sizeof(ha
->plogi_els_payld
.data
));
4924 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4926 ql_dbg(ql_dbg_init
, vha
, 0x00d1,
4927 "PLOGI ELS param read fail.\n");
4934 entries
= MAX_FIBRE_DEVICES_LOOP
;
4936 /* Get list of logged in devices. */
4937 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
4938 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
4940 if (rval
!= QLA_SUCCESS
)
4941 goto cleanup_allocation
;
4943 ql_dbg(ql_dbg_disc
, vha
, 0x2011,
4944 "Entries in ID list (%d).\n", entries
);
4945 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
4946 (uint8_t *)ha
->gid_list
,
4947 entries
* sizeof(struct gid_list_info
));
4950 spin_lock_irqsave(&vha
->work_lock
, flags
);
4951 vha
->scan
.scan_retry
++;
4952 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
4954 if (vha
->scan
.scan_retry
< MAX_SCAN_RETRIES
) {
4955 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4956 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4959 vha
->scan
.scan_retry
= 0;
4962 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4963 fcport
->scan_state
= QLA_FCPORT_SCAN
;
4966 /* Allocate temporary fcport for any new fcports discovered. */
4967 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4968 if (new_fcport
== NULL
) {
4969 ql_log(ql_log_warn
, vha
, 0x2012,
4970 "Memory allocation failed for fcport.\n");
4971 rval
= QLA_MEMORY_ALLOC_FAILED
;
4972 goto cleanup_allocation
;
4974 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4976 /* Add devices to port list. */
4977 id_iter
= (char *)ha
->gid_list
;
4978 for (index
= 0; index
< entries
; index
++) {
4979 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
4980 area
= ((struct gid_list_info
*)id_iter
)->area
;
4981 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
4982 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
4983 loop_id
= (uint16_t)
4984 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
4986 loop_id
= le16_to_cpu(
4987 ((struct gid_list_info
*)id_iter
)->loop_id
);
4988 id_iter
+= ha
->gid_list_info_size
;
4990 /* Bypass reserved domain fields. */
4991 if ((domain
& 0xf0) == 0xf0)
4994 /* Bypass invalid local loop ID. */
4995 if (loop_id
> LAST_LOCAL_LOOP_ID
)
4998 memset(new_fcport
->port_name
, 0, WWN_SIZE
);
5000 /* Fill in member data. */
5001 new_fcport
->d_id
.b
.domain
= domain
;
5002 new_fcport
->d_id
.b
.area
= area
;
5003 new_fcport
->d_id
.b
.al_pa
= al_pa
;
5004 new_fcport
->loop_id
= loop_id
;
5005 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5007 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
5008 if (rval2
!= QLA_SUCCESS
) {
5009 ql_dbg(ql_dbg_disc
, vha
, 0x2097,
5010 "Failed to retrieve fcport information "
5011 "-- get_port_database=%x, loop_id=0x%04x.\n",
5012 rval2
, new_fcport
->loop_id
);
5013 /* Skip retry if N2N */
5014 if (ha
->current_topology
!= ISP_CFG_N
) {
5015 ql_dbg(ql_dbg_disc
, vha
, 0x2105,
5016 "Scheduling resync.\n");
5017 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5022 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5023 /* Check for matching device in port list. */
5026 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5027 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5031 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5032 fcport
->loop_id
= new_fcport
->loop_id
;
5033 fcport
->port_type
= new_fcport
->port_type
;
5034 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5035 memcpy(fcport
->node_name
, new_fcport
->node_name
,
5037 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5043 /* New device, add to fcports list. */
5044 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5046 /* Allocate a new replacement fcport. */
5047 fcport
= new_fcport
;
5049 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5051 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5053 if (new_fcport
== NULL
) {
5054 ql_log(ql_log_warn
, vha
, 0xd031,
5055 "Failed to allocate memory for fcport.\n");
5056 rval
= QLA_MEMORY_ALLOC_FAILED
;
5057 goto cleanup_allocation
;
5059 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5060 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5063 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5065 /* Base iIDMA settings on HBA port speed. */
5066 fcport
->fp_speed
= ha
->link_data_rate
;
5071 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5072 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5075 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5076 if ((qla_dual_mode_enabled(vha
) ||
5077 qla_ini_mode_enabled(vha
)) &&
5078 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5079 qla2x00_mark_device_lost(vha
, fcport
,
5080 ql2xplogiabsentdevice
, 0);
5081 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5082 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5083 fcport
->port_type
!= FCT_INITIATOR
&&
5084 fcport
->port_type
!= FCT_BROADCAST
) {
5085 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5086 "%s %d %8phC post del sess\n",
5090 qlt_schedule_sess_for_deletion(fcport
);
5096 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5097 qla24xx_fcport_handle_login(vha
, fcport
);
5103 if (rval
!= QLA_SUCCESS
) {
5104 ql_dbg(ql_dbg_disc
, vha
, 0x2098,
5105 "Configure local loop error exit: rval=%x.\n", rval
);
5112 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5115 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5116 struct qla_hw_data
*ha
= vha
->hw
;
5118 if (!IS_IIDMA_CAPABLE(ha
))
5121 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
5124 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
5125 fcport
->fp_speed
> ha
->link_data_rate
||
5126 !ha
->flags
.gpsc_supported
)
5129 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
5131 if (rval
!= QLA_SUCCESS
) {
5132 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
5133 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5134 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
5136 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
5137 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5138 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
5139 fcport
->fp_speed
, fcport
->port_name
);
5143 void qla_do_iidma_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
5145 qla2x00_iidma_fcport(vha
, fcport
);
5146 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5149 int qla_post_iidma_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
5151 struct qla_work_evt
*e
;
5153 e
= qla2x00_alloc_work(vha
, QLA_EVT_IIDMA
);
5155 return QLA_FUNCTION_FAILED
;
5157 e
->u
.fcport
.fcport
= fcport
;
5158 return qla2x00_post_work(vha
, e
);
5161 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5163 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5165 struct fc_rport_identifiers rport_ids
;
5166 struct fc_rport
*rport
;
5167 unsigned long flags
;
5169 if (atomic_read(&fcport
->state
) == FCS_ONLINE
)
5172 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
5173 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
5174 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
5175 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
5176 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5177 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
5179 ql_log(ql_log_warn
, vha
, 0x2006,
5180 "Unable to allocate fc remote port.\n");
5184 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
5185 *((fc_port_t
**)rport
->dd_data
) = fcport
;
5186 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
5188 rport
->supported_classes
= fcport
->supported_classes
;
5190 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5191 if (fcport
->port_type
== FCT_INITIATOR
)
5192 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
5193 if (fcport
->port_type
== FCT_TARGET
)
5194 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
5196 ql_dbg(ql_dbg_disc
, vha
, 0x20ee,
5197 "%s %8phN. rport %p is %s mode\n",
5198 __func__
, fcport
->port_name
, rport
,
5199 (fcport
->port_type
== FCT_TARGET
) ? "tgt" : "ini");
5201 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
5205 * qla2x00_update_fcport
5206 * Updates device on list.
5209 * ha = adapter block pointer.
5210 * fcport = port structure pointer.
5220 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5222 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5225 ql_dbg(ql_dbg_disc
, vha
, 0x20ef, "%s %8phC\n",
5226 __func__
, fcport
->port_name
);
5228 fcport
->disc_state
= DSC_UPD_FCPORT
;
5229 fcport
->login_retry
= vha
->hw
->login_retry_count
;
5230 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
5231 fcport
->deleted
= 0;
5232 fcport
->logout_on_delete
= 1;
5233 fcport
->login_retry
= vha
->hw
->login_retry_count
;
5234 fcport
->n2n_chip_reset
= fcport
->n2n_link_reset_cnt
= 0;
5236 switch (vha
->hw
->current_topology
) {
5239 fcport
->keep_nport_handle
= 1;
5245 qla2x00_iidma_fcport(vha
, fcport
);
5247 if (fcport
->fc4f_nvme
) {
5248 qla_nvme_register_remote(vha
, fcport
);
5249 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5250 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5254 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5256 switch (vha
->host
->active_mode
) {
5257 case MODE_INITIATOR
:
5258 qla2x00_reg_remote_port(vha
, fcport
);
5261 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5262 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5263 qlt_fc_port_added(vha
, fcport
);
5266 qla2x00_reg_remote_port(vha
, fcport
);
5267 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5268 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5269 qlt_fc_port_added(vha
, fcport
);
5275 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
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
);
5294 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5297 void qla_register_fcport_fn(struct work_struct
*work
)
5299 fc_port_t
*fcport
= container_of(work
, struct fc_port
, reg_work
);
5300 u32 rscn_gen
= fcport
->rscn_gen
;
5303 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5306 qla2x00_update_fcport(fcport
->vha
, fcport
);
5308 if (rscn_gen
!= fcport
->rscn_gen
) {
5309 /* RSCN(s) came in while registration */
5310 switch (fcport
->next_disc_state
) {
5311 case DSC_DELETE_PEND
:
5312 qlt_schedule_sess_for_deletion(fcport
);
5315 data
[0] = data
[1] = 0;
5316 qla2x00_post_async_adisc_work(fcport
->vha
, fcport
,
5326 * qla2x00_configure_fabric
5327 * Setup SNS devices with loop ID's.
5330 * ha = adapter block pointer.
5337 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
5341 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5343 LIST_HEAD(new_fcports
);
5344 struct qla_hw_data
*ha
= vha
->hw
;
5347 /* If FL port exists, then SNS is present */
5348 if (IS_FWI2_CAPABLE(ha
))
5349 loop_id
= NPH_F_PORT
;
5351 loop_id
= SNS_FL_PORT
;
5352 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
5353 if (rval
!= QLA_SUCCESS
) {
5354 ql_dbg(ql_dbg_disc
, vha
, 0x20a0,
5355 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5357 vha
->device_flags
&= ~SWITCH_FOUND
;
5358 return (QLA_SUCCESS
);
5360 vha
->device_flags
|= SWITCH_FOUND
;
5363 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
5364 rval
= qla2x00_send_change_request(vha
, 0x3, 0);
5365 if (rval
!= QLA_SUCCESS
)
5366 ql_log(ql_log_warn
, vha
, 0x121,
5367 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5373 qla2x00_mgmt_svr_login(vha
);
5376 if (ql2xfdmienable
&&
5377 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
5378 qla2x00_fdmi_register(vha
);
5380 /* Ensure we are logged into the SNS. */
5381 loop_id
= NPH_SNS_LID(ha
);
5382 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
5383 0xfc, mb
, BIT_1
|BIT_0
);
5384 if (rval
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5385 ql_dbg(ql_dbg_disc
, vha
, 0x20a1,
5386 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5387 loop_id
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7], rval
);
5388 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5391 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
5392 if (qla2x00_rft_id(vha
)) {
5394 ql_dbg(ql_dbg_disc
, vha
, 0x20a2,
5395 "Register FC-4 TYPE failed.\n");
5396 if (test_bit(LOOP_RESYNC_NEEDED
,
5400 if (qla2x00_rff_id(vha
, FC4_TYPE_FCP_SCSI
)) {
5402 ql_dbg(ql_dbg_disc
, vha
, 0x209a,
5403 "Register FC-4 Features failed.\n");
5404 if (test_bit(LOOP_RESYNC_NEEDED
,
5408 if (vha
->flags
.nvme_enabled
) {
5409 if (qla2x00_rff_id(vha
, FC_TYPE_NVME
)) {
5410 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
5411 "Register NVME FC Type Features failed.\n");
5414 if (qla2x00_rnn_id(vha
)) {
5416 ql_dbg(ql_dbg_disc
, vha
, 0x2104,
5417 "Register Node Name failed.\n");
5418 if (test_bit(LOOP_RESYNC_NEEDED
,
5421 } else if (qla2x00_rsnn_nn(vha
)) {
5423 ql_dbg(ql_dbg_disc
, vha
, 0x209b,
5424 "Register Symbolic Node Name failed.\n");
5425 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5431 /* Mark the time right before querying FW for connected ports.
5432 * This process is long, asynchronous and by the time it's done,
5433 * collected information might not be accurate anymore. E.g.
5434 * disconnected port might have re-connected and a brand new
5435 * session has been created. In this case session's generation
5436 * will be newer than discovery_gen. */
5437 qlt_do_generation_tick(vha
, &discovery_gen
);
5439 if (USE_ASYNC_SCAN(ha
)) {
5440 rval
= qla24xx_async_gpnft(vha
, FC4_TYPE_FCP_SCSI
,
5443 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5445 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5446 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5448 rval
= qla2x00_find_all_fabric_devs(vha
);
5450 if (rval
!= QLA_SUCCESS
)
5454 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
5455 qla_nvme_register_hba(vha
);
5458 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
5459 "Configure fabric error exit rval=%d.\n", rval
);
5465 * qla2x00_find_all_fabric_devs
5468 * ha = adapter block pointer.
5469 * dev = database device entry pointer.
5478 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
)
5482 fc_port_t
*fcport
, *new_fcport
;
5487 int first_dev
, last_dev
;
5488 port_id_t wrap
= {}, nxt_d_id
;
5489 struct qla_hw_data
*ha
= vha
->hw
;
5490 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5491 unsigned long flags
;
5495 /* Try GID_PT to get device list, else GAN. */
5497 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
5502 ql_dbg(ql_dbg_disc
, vha
, 0x209c,
5503 "GID_PT allocations failed, fallback on GA_NXT.\n");
5505 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
5506 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
5508 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5510 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
5512 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5514 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
5516 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5518 } else if (qla2x00_gfpn_id(vha
, swl
) != QLA_SUCCESS
) {
5520 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5524 /* If other queries succeeded probe for FC-4 type */
5526 qla2x00_gff_id(vha
, swl
);
5527 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5533 /* Allocate temporary fcport for any new fcports discovered. */
5534 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5535 if (new_fcport
== NULL
) {
5536 ql_log(ql_log_warn
, vha
, 0x209d,
5537 "Failed to allocate memory for fcport.\n");
5538 return (QLA_MEMORY_ALLOC_FAILED
);
5540 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5541 /* Set start port ID scan at adapter ID. */
5545 /* Starting free loop ID. */
5546 loop_id
= ha
->min_external_loopid
;
5547 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
5548 if (qla2x00_is_reserved_id(vha
, loop_id
))
5551 if (ha
->current_topology
== ISP_CFG_FL
&&
5552 (atomic_read(&vha
->loop_down_timer
) ||
5553 LOOP_TRANSITION(vha
))) {
5554 atomic_set(&vha
->loop_down_timer
, 0);
5555 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5556 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5562 wrap
.b24
= new_fcport
->d_id
.b24
;
5564 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
5565 memcpy(new_fcport
->node_name
,
5566 swl
[swl_idx
].node_name
, WWN_SIZE
);
5567 memcpy(new_fcport
->port_name
,
5568 swl
[swl_idx
].port_name
, WWN_SIZE
);
5569 memcpy(new_fcport
->fabric_port_name
,
5570 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
5571 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
5572 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
5574 new_fcport
->nvme_flag
= 0;
5575 new_fcport
->fc4f_nvme
= 0;
5576 if (vha
->flags
.nvme_enabled
&&
5577 swl
[swl_idx
].fc4f_nvme
) {
5578 new_fcport
->fc4f_nvme
=
5579 swl
[swl_idx
].fc4f_nvme
;
5580 ql_log(ql_log_info
, vha
, 0x2131,
5581 "FOUND: NVME port %8phC as FC Type 28h\n",
5582 new_fcport
->port_name
);
5585 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
5591 /* Send GA_NXT to the switch */
5592 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
5593 if (rval
!= QLA_SUCCESS
) {
5594 ql_log(ql_log_warn
, vha
, 0x209e,
5595 "SNS scan failed -- assuming "
5596 "zero-entry result.\n");
5602 /* If wrap on switch device list, exit. */
5604 wrap
.b24
= new_fcport
->d_id
.b24
;
5606 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
5607 ql_dbg(ql_dbg_disc
, vha
, 0x209f,
5608 "Device wrap (%02x%02x%02x).\n",
5609 new_fcport
->d_id
.b
.domain
,
5610 new_fcport
->d_id
.b
.area
,
5611 new_fcport
->d_id
.b
.al_pa
);
5615 /* Bypass if same physical adapter. */
5616 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
5619 /* Bypass virtual ports of the same host. */
5620 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
5623 /* Bypass if same domain and area of adapter. */
5624 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
5625 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
5629 /* Bypass reserved domain fields. */
5630 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
5633 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5634 if (ql2xgffidenable
&&
5635 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
5636 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
5639 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5641 /* Locate matching device in database. */
5643 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5644 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5648 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5652 /* Update port state. */
5653 memcpy(fcport
->fabric_port_name
,
5654 new_fcport
->fabric_port_name
, WWN_SIZE
);
5655 fcport
->fp_speed
= new_fcport
->fp_speed
;
5658 * If address the same and state FCS_ONLINE
5659 * (or in target mode), nothing changed.
5661 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
5662 (atomic_read(&fcport
->state
) == FCS_ONLINE
||
5663 (vha
->host
->active_mode
== MODE_TARGET
))) {
5668 * If device was not a fabric device before.
5670 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
5671 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5672 qla2x00_clear_loop_id(fcport
);
5673 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
5679 * Port ID changed or device was marked to be updated;
5680 * Log it out if still logged in and mark it for
5683 if (qla_tgt_mode_enabled(base_vha
)) {
5684 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf080,
5685 "port changed FC ID, %8phC"
5686 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5688 fcport
->d_id
.b
.domain
,
5689 fcport
->d_id
.b
.area
,
5690 fcport
->d_id
.b
.al_pa
,
5692 new_fcport
->d_id
.b
.domain
,
5693 new_fcport
->d_id
.b
.area
,
5694 new_fcport
->d_id
.b
.al_pa
);
5695 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5699 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5700 fcport
->flags
|= FCF_LOGIN_NEEDED
;
5704 if (fcport
->fc4f_nvme
) {
5705 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
5706 fcport
->disc_state
= DSC_GNL
;
5707 vha
->fcport_count
--;
5708 fcport
->login_succ
= 0;
5713 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5716 /* If device was not in our fcports list, then add it. */
5717 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5718 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5720 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5723 /* Allocate a new replacement fcport. */
5724 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
5725 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5726 if (new_fcport
== NULL
) {
5727 ql_log(ql_log_warn
, vha
, 0xd032,
5728 "Memory allocation failed for fcport.\n");
5729 return (QLA_MEMORY_ALLOC_FAILED
);
5731 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5732 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
5735 qla2x00_free_fcport(new_fcport
);
5738 * Logout all previous fabric dev marked lost, except FCP2 devices.
5740 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5741 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5744 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
5745 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
5748 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5749 if ((qla_dual_mode_enabled(vha
) ||
5750 qla_ini_mode_enabled(vha
)) &&
5751 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5752 qla2x00_mark_device_lost(vha
, fcport
,
5753 ql2xplogiabsentdevice
, 0);
5754 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5755 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5756 fcport
->port_type
!= FCT_INITIATOR
&&
5757 fcport
->port_type
!= FCT_BROADCAST
) {
5758 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5759 "%s %d %8phC post del sess\n",
5762 qlt_schedule_sess_for_deletion(fcport
);
5768 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5769 qla24xx_fcport_handle_login(vha
, fcport
);
5775 * qla2x00_find_new_loop_id
5776 * Scan through our port list and find a new usable loop ID.
5779 * ha: adapter state pointer.
5780 * dev: port structure pointer.
5783 * qla2x00 local function return status code.
5789 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
5792 struct qla_hw_data
*ha
= vha
->hw
;
5793 unsigned long flags
= 0;
5797 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5799 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
5801 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
5802 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
5803 dev
->loop_id
= FC_NO_LOOP_ID
;
5804 rval
= QLA_FUNCTION_FAILED
;
5806 set_bit(dev
->loop_id
, ha
->loop_id_map
);
5808 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5810 if (rval
== QLA_SUCCESS
)
5811 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
5812 "Assigning new loopid=%x, portid=%x.\n",
5813 dev
->loop_id
, dev
->d_id
.b24
);
5815 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
5816 "No loop_id's available, portid=%x.\n",
5823 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5825 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t
*vha
)
5827 int loop_id
= FC_NO_LOOP_ID
;
5828 int lid
= NPH_MGMT_SERVER
- vha
->vp_idx
;
5829 unsigned long flags
;
5830 struct qla_hw_data
*ha
= vha
->hw
;
5832 if (vha
->vp_idx
== 0) {
5833 set_bit(NPH_MGMT_SERVER
, ha
->loop_id_map
);
5834 return NPH_MGMT_SERVER
;
5837 /* pick id from high and work down to low */
5838 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5839 for (; lid
> 0; lid
--) {
5840 if (!test_bit(lid
, vha
->hw
->loop_id_map
)) {
5841 set_bit(lid
, vha
->hw
->loop_id_map
);
5846 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5852 * qla2x00_fabric_login
5853 * Issue fabric login command.
5856 * ha = adapter block pointer.
5857 * device = pointer to FC device type structure.
5860 * 0 - Login successfully
5862 * 2 - Initiator device
5866 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
5867 uint16_t *next_loopid
)
5871 uint16_t tmp_loopid
;
5872 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5873 struct qla_hw_data
*ha
= vha
->hw
;
5879 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
5880 "Trying Fabric Login w/loop id 0x%04x for port "
5882 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5883 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5885 /* Login fcport on switch. */
5886 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
5887 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5888 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
5889 if (rval
!= QLA_SUCCESS
) {
5892 if (mb
[0] == MBS_PORT_ID_USED
) {
5894 * Device has another loop ID. The firmware team
5895 * recommends the driver perform an implicit login with
5896 * the specified ID again. The ID we just used is save
5897 * here so we return with an ID that can be tried by
5901 tmp_loopid
= fcport
->loop_id
;
5902 fcport
->loop_id
= mb
[1];
5904 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
5905 "Fabric Login: port in use - next loop "
5906 "id=0x%04x, port id= %02x%02x%02x.\n",
5907 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5908 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5910 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
5915 /* A retry occurred before. */
5916 *next_loopid
= tmp_loopid
;
5919 * No retry occurred before. Just increment the
5920 * ID value for next login.
5922 *next_loopid
= (fcport
->loop_id
+ 1);
5925 if (mb
[1] & BIT_0
) {
5926 fcport
->port_type
= FCT_INITIATOR
;
5928 fcport
->port_type
= FCT_TARGET
;
5929 if (mb
[1] & BIT_1
) {
5930 fcport
->flags
|= FCF_FCP2_DEVICE
;
5935 fcport
->supported_classes
|= FC_COS_CLASS2
;
5937 fcport
->supported_classes
|= FC_COS_CLASS3
;
5939 if (IS_FWI2_CAPABLE(ha
)) {
5942 FCF_CONF_COMP_SUPPORTED
;
5947 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
5949 * Loop ID already used, try next loop ID.
5952 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
5953 if (rval
!= QLA_SUCCESS
) {
5954 /* Ran out of loop IDs to use */
5957 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
5959 * Firmware possibly timed out during login. If NO
5960 * retries are left to do then the device is declared
5963 *next_loopid
= fcport
->loop_id
;
5964 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5965 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5966 fcport
->d_id
.b
.al_pa
);
5967 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
5973 * unrecoverable / not handled error
5975 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
5976 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5977 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
5978 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
5979 fcport
->loop_id
, jiffies
);
5981 *next_loopid
= fcport
->loop_id
;
5982 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5983 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5984 fcport
->d_id
.b
.al_pa
);
5985 qla2x00_clear_loop_id(fcport
);
5986 fcport
->login_retry
= 0;
5997 * qla2x00_local_device_login
5998 * Issue local device login command.
6001 * ha = adapter block pointer.
6002 * loop_id = loop id of device to login to.
6004 * Returns (Where's the #define!!!!):
6005 * 0 - Login successfully
6010 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
6013 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6015 memset(mb
, 0, sizeof(mb
));
6016 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
6017 if (rval
== QLA_SUCCESS
) {
6018 /* Interrogate mailbox registers for any errors */
6019 if (mb
[0] == MBS_COMMAND_ERROR
)
6021 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
6022 /* device not in PCB table */
6030 * qla2x00_loop_resync
6031 * Resync with fibre channel devices.
6034 * ha = adapter block pointer.
6040 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
6042 int rval
= QLA_SUCCESS
;
6045 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6046 if (vha
->flags
.online
) {
6047 if (!(rval
= qla2x00_fw_ready(vha
))) {
6048 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6051 if (!IS_QLAFX00(vha
->hw
)) {
6053 * Issue a marker after FW becomes
6056 qla2x00_marker(vha
, vha
->hw
->base_qpair
,
6058 vha
->marker_needed
= 0;
6061 /* Remap devices on Loop. */
6062 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6064 if (IS_QLAFX00(vha
->hw
))
6065 qlafx00_configure_devices(vha
);
6067 qla2x00_configure_loop(vha
);
6070 } while (!atomic_read(&vha
->loop_down_timer
) &&
6071 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
6072 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
6077 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
6078 return (QLA_FUNCTION_FAILED
);
6081 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
6082 "%s *** FAILED ***.\n", __func__
);
6088 * qla2x00_perform_loop_resync
6089 * Description: This function will set the appropriate flags and call
6090 * qla2x00_loop_resync. If successful loop will be resynced
6091 * Arguments : scsi_qla_host_t pointer
6092 * returm : Success or Failure
6095 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
6099 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
6100 /*Configure the flags so that resync happens properly*/
6101 atomic_set(&ha
->loop_down_timer
, 0);
6102 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
6103 atomic_set(&ha
->loop_state
, LOOP_UP
);
6104 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
6105 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
6106 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
6108 rval
= qla2x00_loop_resync(ha
);
6110 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
6112 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
6119 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
6122 struct scsi_qla_host
*vha
;
6123 struct qla_hw_data
*ha
= base_vha
->hw
;
6124 unsigned long flags
;
6126 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6127 /* Go with deferred removal of rport references. */
6128 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
6129 atomic_inc(&vha
->vref_count
);
6130 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
6131 if (fcport
->drport
&&
6132 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
6133 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6134 qla2x00_rport_del(fcport
);
6136 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6139 atomic_dec(&vha
->vref_count
);
6140 wake_up(&vha
->vref_waitq
);
6142 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6145 /* Assumes idc_lock always held on entry */
6147 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
6149 struct qla_hw_data
*ha
= vha
->hw
;
6150 uint32_t drv_presence
, drv_presence_mask
;
6151 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
6152 uint32_t class_type_mask
= 0x3;
6153 uint16_t fcoe_other_function
= 0xffff, i
;
6155 if (IS_QLA8044(ha
)) {
6156 drv_presence
= qla8044_rd_direct(vha
,
6157 QLA8044_CRB_DRV_ACTIVE_INDEX
);
6158 dev_part_info1
= qla8044_rd_direct(vha
,
6159 QLA8044_CRB_DEV_PART_INFO_INDEX
);
6160 dev_part_info2
= qla8044_rd_direct(vha
,
6161 QLA8044_CRB_DEV_PART_INFO2
);
6163 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6164 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
6165 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
6167 for (i
= 0; i
< 8; i
++) {
6168 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
6169 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
6170 (i
!= ha
->portnum
)) {
6171 fcoe_other_function
= i
;
6175 if (fcoe_other_function
== 0xffff) {
6176 for (i
= 0; i
< 8; i
++) {
6177 class_type
= ((dev_part_info2
>> (i
* 4)) &
6179 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
6180 ((i
+ 8) != ha
->portnum
)) {
6181 fcoe_other_function
= i
+ 8;
6187 * Prepare drv-presence mask based on fcoe functions present.
6188 * However consider only valid physical fcoe function numbers (0-15).
6190 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
6191 ((fcoe_other_function
== 0xffff) ?
6192 0 : (1 << (fcoe_other_function
))));
6194 /* We are the reset owner iff:
6195 * - No other protocol drivers present.
6196 * - This is the lowest among fcoe functions. */
6197 if (!(drv_presence
& drv_presence_mask
) &&
6198 (ha
->portnum
< fcoe_other_function
)) {
6199 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
6200 "This host is Reset owner.\n");
6201 ha
->flags
.nic_core_reset_owner
= 1;
6206 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
6208 int rval
= QLA_SUCCESS
;
6209 struct qla_hw_data
*ha
= vha
->hw
;
6212 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6213 if (rval
== QLA_SUCCESS
) {
6214 drv_ack
|= (1 << ha
->portnum
);
6215 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6222 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
6224 int rval
= QLA_SUCCESS
;
6225 struct qla_hw_data
*ha
= vha
->hw
;
6228 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6229 if (rval
== QLA_SUCCESS
) {
6230 drv_ack
&= ~(1 << ha
->portnum
);
6231 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6238 qla83xx_dev_state_to_string(uint32_t dev_state
)
6240 switch (dev_state
) {
6241 case QLA8XXX_DEV_COLD
:
6242 return "COLD/RE-INIT";
6243 case QLA8XXX_DEV_INITIALIZING
:
6244 return "INITIALIZING";
6245 case QLA8XXX_DEV_READY
:
6247 case QLA8XXX_DEV_NEED_RESET
:
6248 return "NEED RESET";
6249 case QLA8XXX_DEV_NEED_QUIESCENT
:
6250 return "NEED QUIESCENT";
6251 case QLA8XXX_DEV_FAILED
:
6253 case QLA8XXX_DEV_QUIESCENT
:
6260 /* Assumes idc-lock always held on entry */
6262 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
6264 struct qla_hw_data
*ha
= vha
->hw
;
6265 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
6267 switch (audit_type
) {
6268 case IDC_AUDIT_TIMESTAMP
:
6269 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
6270 idc_audit_reg
= (ha
->portnum
) |
6271 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
6272 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6275 case IDC_AUDIT_COMPLETION
:
6276 duration_secs
= ((jiffies_to_msecs(jiffies
) -
6277 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
6278 idc_audit_reg
= (ha
->portnum
) |
6279 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
6280 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6284 ql_log(ql_log_warn
, vha
, 0xb078,
6285 "Invalid audit type specified.\n");
6290 /* Assumes idc_lock always held on entry */
6292 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
6294 struct qla_hw_data
*ha
= vha
->hw
;
6295 uint32_t idc_control
, dev_state
;
6297 __qla83xx_get_idc_control(vha
, &idc_control
);
6298 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
6299 ql_log(ql_log_info
, vha
, 0xb080,
6300 "NIC Core reset has been disabled. idc-control=0x%x\n",
6302 return QLA_FUNCTION_FAILED
;
6305 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6306 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6307 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
6308 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
6309 QLA8XXX_DEV_NEED_RESET
);
6310 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
6311 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
6313 const char *state
= qla83xx_dev_state_to_string(dev_state
);
6314 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
6316 /* SV: XXX: Is timeout required here? */
6317 /* Wait for IDC state change READY -> NEED_RESET */
6318 while (dev_state
== QLA8XXX_DEV_READY
) {
6319 qla83xx_idc_unlock(vha
, 0);
6321 qla83xx_idc_lock(vha
, 0);
6322 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6326 /* Send IDC ack by writing to drv-ack register */
6327 __qla83xx_set_drv_ack(vha
);
6333 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
6335 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6339 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
6341 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6345 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
6347 uint32_t drv_presence
= 0;
6348 struct qla_hw_data
*ha
= vha
->hw
;
6350 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6351 if (drv_presence
& (1 << ha
->portnum
))
6354 return QLA_TEST_FAILED
;
6358 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
6360 int rval
= QLA_SUCCESS
;
6361 struct qla_hw_data
*ha
= vha
->hw
;
6363 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
6364 "Entered %s().\n", __func__
);
6366 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
6367 ql_log(ql_log_warn
, vha
, 0xb059,
6368 "Device in unrecoverable FAILED state.\n");
6369 return QLA_FUNCTION_FAILED
;
6372 qla83xx_idc_lock(vha
, 0);
6374 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
6375 ql_log(ql_log_warn
, vha
, 0xb05a,
6376 "Function=0x%x has been removed from IDC participation.\n",
6378 rval
= QLA_FUNCTION_FAILED
;
6382 qla83xx_reset_ownership(vha
);
6384 rval
= qla83xx_initiating_reset(vha
);
6387 * Perform reset if we are the reset-owner,
6388 * else wait till IDC state changes to READY/FAILED.
6390 if (rval
== QLA_SUCCESS
) {
6391 rval
= qla83xx_idc_state_handler(vha
);
6393 if (rval
== QLA_SUCCESS
)
6394 ha
->flags
.nic_core_hung
= 0;
6395 __qla83xx_clear_drv_ack(vha
);
6399 qla83xx_idc_unlock(vha
, 0);
6401 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
6407 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
6409 struct qla_hw_data
*ha
= vha
->hw
;
6410 int rval
= QLA_FUNCTION_FAILED
;
6412 if (!IS_MCTP_CAPABLE(ha
)) {
6413 /* This message can be removed from the final version */
6414 ql_log(ql_log_info
, vha
, 0x506d,
6415 "This board is not MCTP capable\n");
6419 if (!ha
->mctp_dump
) {
6420 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
6421 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
6423 if (!ha
->mctp_dump
) {
6424 ql_log(ql_log_warn
, vha
, 0x506e,
6425 "Failed to allocate memory for mctp dump\n");
6430 #define MCTP_DUMP_STR_ADDR 0x00000000
6431 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
6432 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
6433 if (rval
!= QLA_SUCCESS
) {
6434 ql_log(ql_log_warn
, vha
, 0x506f,
6435 "Failed to capture mctp dump\n");
6437 ql_log(ql_log_info
, vha
, 0x5070,
6438 "Mctp dump capture for host (%ld/%p).\n",
6439 vha
->host_no
, ha
->mctp_dump
);
6440 ha
->mctp_dumped
= 1;
6443 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
6444 ha
->flags
.nic_core_reset_hdlr_active
= 1;
6445 rval
= qla83xx_restart_nic_firmware(vha
);
6447 /* NIC Core reset failed. */
6448 ql_log(ql_log_warn
, vha
, 0x5071,
6449 "Failed to restart nic firmware\n");
6451 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
6452 "Restarted NIC firmware successfully.\n");
6453 ha
->flags
.nic_core_reset_hdlr_active
= 0;
6461 * qla2x00_quiesce_io
6462 * Description: This function will block the new I/Os
6463 * Its not aborting any I/Os as context
6464 * is not destroyed during quiescence
6465 * Arguments: scsi_qla_host_t
6469 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
6471 struct qla_hw_data
*ha
= vha
->hw
;
6472 struct scsi_qla_host
*vp
;
6474 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
6475 "Quiescing I/O - ha=%p.\n", ha
);
6477 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
6478 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6479 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6480 qla2x00_mark_all_devices_lost(vha
, 0);
6481 list_for_each_entry(vp
, &ha
->vp_list
, list
)
6482 qla2x00_mark_all_devices_lost(vp
, 0);
6484 if (!atomic_read(&vha
->loop_down_timer
))
6485 atomic_set(&vha
->loop_down_timer
,
6488 /* Wait for pending cmds to complete */
6489 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
6493 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
6495 struct qla_hw_data
*ha
= vha
->hw
;
6496 struct scsi_qla_host
*vp
;
6497 unsigned long flags
;
6501 /* For ISP82XX, driver waits for completion of the commands.
6502 * online flag should be set.
6504 if (!(IS_P3P_TYPE(ha
)))
6505 vha
->flags
.online
= 0;
6506 ha
->flags
.chip_reset_done
= 0;
6507 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6508 vha
->qla_stats
.total_isp_aborts
++;
6510 ql_log(ql_log_info
, vha
, 0x00af,
6511 "Performing ISP error recovery - ha=%p.\n", ha
);
6513 ha
->flags
.purge_mbox
= 1;
6514 /* For ISP82XX, reset_chip is just disabling interrupts.
6515 * Driver waits for the completion of the commands.
6516 * the interrupts need to be enabled.
6518 if (!(IS_P3P_TYPE(ha
)))
6519 ha
->isp_ops
->reset_chip(vha
);
6521 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
6523 ha
->flags
.rida_fmt2
= 0;
6524 ha
->flags
.n2n_ae
= 0;
6525 ha
->flags
.lip_ae
= 0;
6526 ha
->current_topology
= 0;
6527 ha
->flags
.fw_started
= 0;
6528 ha
->flags
.fw_init_done
= 0;
6530 ha
->base_qpair
->chip_reset
= ha
->chip_reset
;
6531 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6532 if (ha
->queue_pair_map
[i
])
6533 ha
->queue_pair_map
[i
]->chip_reset
=
6534 ha
->base_qpair
->chip_reset
;
6537 /* purge MBox commands */
6538 if (atomic_read(&ha
->num_pend_mbx_stage3
)) {
6539 clear_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
);
6540 complete(&ha
->mbx_intr_comp
);
6544 while (atomic_read(&ha
->num_pend_mbx_stage3
) ||
6545 atomic_read(&ha
->num_pend_mbx_stage2
) ||
6546 atomic_read(&ha
->num_pend_mbx_stage1
)) {
6552 ha
->flags
.purge_mbox
= 0;
6554 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
6555 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6556 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6557 qla2x00_mark_all_devices_lost(vha
, 0);
6559 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6560 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6561 atomic_inc(&vp
->vref_count
);
6562 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6564 qla2x00_mark_all_devices_lost(vp
, 0);
6566 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6567 atomic_dec(&vp
->vref_count
);
6569 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6571 if (!atomic_read(&vha
->loop_down_timer
))
6572 atomic_set(&vha
->loop_down_timer
,
6576 /* Clear all async request states across all VPs. */
6577 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
6578 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6579 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6580 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6581 atomic_inc(&vp
->vref_count
);
6582 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6584 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
6585 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6587 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6588 atomic_dec(&vp
->vref_count
);
6590 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6592 if (!ha
->flags
.eeh_busy
) {
6593 /* Make sure for ISP 82XX IO DMA is complete */
6594 if (IS_P3P_TYPE(ha
)) {
6595 qla82xx_chip_reset_cleanup(vha
);
6596 ql_log(ql_log_info
, vha
, 0x00b4,
6597 "Done chip reset cleanup.\n");
6599 /* Done waiting for pending commands.
6600 * Reset the online flag.
6602 vha
->flags
.online
= 0;
6605 /* Requeue all commands in outstanding command list. */
6606 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6608 /* memory barrier */
6614 * Resets ISP and aborts all outstanding commands.
6617 * ha = adapter block pointer.
6623 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
6627 struct qla_hw_data
*ha
= vha
->hw
;
6628 struct scsi_qla_host
*vp
;
6629 struct req_que
*req
= ha
->req_q_map
[0];
6630 unsigned long flags
;
6632 if (vha
->flags
.online
) {
6633 qla2x00_abort_isp_cleanup(vha
);
6635 if (IS_QLA8031(ha
)) {
6636 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
6637 "Clearing fcoe driver presence.\n");
6638 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
6639 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
6640 "Error while clearing DRV-Presence.\n");
6643 if (unlikely(pci_channel_offline(ha
->pdev
) &&
6644 ha
->flags
.pci_channel_io_perm_failure
)) {
6645 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6650 switch (vha
->qlini_mode
) {
6651 case QLA2XXX_INI_MODE_DISABLED
:
6652 if (!qla_tgt_mode_enabled(vha
))
6655 case QLA2XXX_INI_MODE_DUAL
:
6656 if (!qla_dual_mode_enabled(vha
))
6659 case QLA2XXX_INI_MODE_ENABLED
:
6664 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
6666 ha
->isp_ops
->nvram_config(vha
);
6668 if (!qla2x00_restart_isp(vha
)) {
6669 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6671 if (!atomic_read(&vha
->loop_down_timer
)) {
6673 * Issue marker command only when we are going
6674 * to start the I/O .
6676 vha
->marker_needed
= 1;
6679 vha
->flags
.online
= 1;
6681 ha
->isp_ops
->enable_intrs(ha
);
6683 ha
->isp_abort_cnt
= 0;
6684 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6686 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
6687 qla2x00_get_fw_version(vha
);
6689 ha
->flags
.fce_enabled
= 1;
6691 fce_calc_size(ha
->fce_bufs
));
6692 rval
= qla2x00_enable_fce_trace(vha
,
6693 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6696 ql_log(ql_log_warn
, vha
, 0x8033,
6697 "Unable to reinitialize FCE "
6699 ha
->flags
.fce_enabled
= 0;
6704 memset(ha
->eft
, 0, EFT_SIZE
);
6705 rval
= qla2x00_enable_eft_trace(vha
,
6706 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6708 ql_log(ql_log_warn
, vha
, 0x8034,
6709 "Unable to reinitialize EFT "
6713 } else { /* failed the ISP abort */
6714 vha
->flags
.online
= 1;
6715 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
6716 if (ha
->isp_abort_cnt
== 0) {
6717 ql_log(ql_log_fatal
, vha
, 0x8035,
6718 "ISP error recover failed - "
6719 "board disabled.\n");
6721 * The next call disables the board
6724 qla2x00_abort_isp_cleanup(vha
);
6725 vha
->flags
.online
= 0;
6726 clear_bit(ISP_ABORT_RETRY
,
6729 } else { /* schedule another ISP abort */
6730 ha
->isp_abort_cnt
--;
6731 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
6732 "ISP abort - retry remaining %d.\n",
6737 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
6738 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
6739 "ISP error recovery - retrying (%d) "
6740 "more times.\n", ha
->isp_abort_cnt
);
6741 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6749 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
6750 qla2x00_configure_hba(vha
);
6751 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6752 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6754 atomic_inc(&vp
->vref_count
);
6755 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6757 qla2x00_vp_abort_isp(vp
);
6759 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6760 atomic_dec(&vp
->vref_count
);
6763 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6765 if (IS_QLA8031(ha
)) {
6766 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
6767 "Setting back fcoe driver presence.\n");
6768 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
6769 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
6770 "Error while setting DRV-Presence.\n");
6773 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
6781 * qla2x00_restart_isp
6782 * restarts the ISP after a reset
6785 * ha = adapter block pointer.
6791 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
6794 struct qla_hw_data
*ha
= vha
->hw
;
6796 /* If firmware needs to be loaded */
6797 if (qla2x00_isp_firmware(vha
)) {
6798 vha
->flags
.online
= 0;
6799 status
= ha
->isp_ops
->chip_diag(vha
);
6801 status
= qla2x00_setup_chip(vha
);
6804 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
6805 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6806 ha
->flags
.chip_reset_done
= 1;
6808 /* Initialize the queues in use */
6809 qla25xx_init_queues(ha
);
6811 status
= qla2x00_fw_ready(vha
);
6813 /* Issue a marker after FW becomes ready. */
6814 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
6815 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6818 /* if no cable then assume it's good */
6819 if ((vha
->device_flags
& DFLG_NO_CABLE
))
6826 qla25xx_init_queues(struct qla_hw_data
*ha
)
6828 struct rsp_que
*rsp
= NULL
;
6829 struct req_que
*req
= NULL
;
6830 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
6834 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
6835 rsp
= ha
->rsp_q_map
[i
];
6836 if (rsp
&& test_bit(i
, ha
->rsp_qid_map
)) {
6837 rsp
->options
&= ~BIT_0
;
6838 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
6839 if (ret
!= QLA_SUCCESS
)
6840 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
6841 "%s Rsp que: %d init failed.\n",
6844 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
6845 "%s Rsp que: %d inited.\n",
6849 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
6850 req
= ha
->req_q_map
[i
];
6851 if (req
&& test_bit(i
, ha
->req_qid_map
)) {
6852 /* Clear outstanding commands array. */
6853 req
->options
&= ~BIT_0
;
6854 ret
= qla25xx_init_req_que(base_vha
, req
);
6855 if (ret
!= QLA_SUCCESS
)
6856 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
6857 "%s Req que: %d init failed.\n",
6860 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
6861 "%s Req que: %d inited.\n",
6869 * qla2x00_reset_adapter
6873 * ha = adapter block pointer.
6876 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
6878 unsigned long flags
= 0;
6879 struct qla_hw_data
*ha
= vha
->hw
;
6880 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
6882 vha
->flags
.online
= 0;
6883 ha
->isp_ops
->disable_intrs(ha
);
6885 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6886 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
6887 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6888 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
6889 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6890 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6894 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
6896 unsigned long flags
= 0;
6897 struct qla_hw_data
*ha
= vha
->hw
;
6898 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
6900 if (IS_P3P_TYPE(ha
))
6903 vha
->flags
.online
= 0;
6904 ha
->isp_ops
->disable_intrs(ha
);
6906 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6907 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
6908 RD_REG_DWORD(®
->hccr
);
6909 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
6910 RD_REG_DWORD(®
->hccr
);
6911 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6913 if (IS_NOPOLLING_TYPE(ha
))
6914 ha
->isp_ops
->enable_intrs(ha
);
6917 /* On sparc systems, obtain port and node WWN from firmware
6920 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
6921 struct nvram_24xx
*nv
)
6924 struct qla_hw_data
*ha
= vha
->hw
;
6925 struct pci_dev
*pdev
= ha
->pdev
;
6926 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
6930 val
= of_get_property(dp
, "port-wwn", &len
);
6931 if (val
&& len
>= WWN_SIZE
)
6932 memcpy(nv
->port_name
, val
, WWN_SIZE
);
6934 val
= of_get_property(dp
, "node-wwn", &len
);
6935 if (val
&& len
>= WWN_SIZE
)
6936 memcpy(nv
->node_name
, val
, WWN_SIZE
);
6941 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
6944 struct init_cb_24xx
*icb
;
6945 struct nvram_24xx
*nv
;
6947 uint8_t *dptr1
, *dptr2
;
6950 struct qla_hw_data
*ha
= vha
->hw
;
6953 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6956 /* Determine NVRAM starting address. */
6957 if (ha
->port_no
== 0) {
6958 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
6959 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
6961 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
6962 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
6965 ha
->nvram_size
= sizeof(struct nvram_24xx
);
6966 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
6968 /* Get VPD data into cache */
6969 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
6970 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
6971 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
6973 /* Get NVRAM data into cache and calculate checksum. */
6974 dptr
= (uint32_t *)nv
;
6975 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
6977 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
6978 chksum
+= le32_to_cpu(*dptr
);
6980 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
6981 "Contents of NVRAM\n");
6982 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
6983 (uint8_t *)nv
, ha
->nvram_size
);
6985 /* Bad NVRAM data, set defaults parameters. */
6986 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
6987 || nv
->id
[3] != ' ' ||
6988 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
6989 /* Reset NVRAM data. */
6990 ql_log(ql_log_warn
, vha
, 0x006b,
6991 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6992 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
6993 ql_log(ql_log_warn
, vha
, 0x006c,
6994 "Falling back to functioning (yet invalid -- WWPN) "
6998 * Set default initialization control block.
7000 memset(nv
, 0, ha
->nvram_size
);
7001 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
7002 nv
->version
= cpu_to_le16(ICB_VERSION
);
7003 nv
->frame_payload_size
= 2048;
7004 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
7005 nv
->exchange_count
= cpu_to_le16(0);
7006 nv
->hard_address
= cpu_to_le16(124);
7007 nv
->port_name
[0] = 0x21;
7008 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
7009 nv
->port_name
[2] = 0x00;
7010 nv
->port_name
[3] = 0xe0;
7011 nv
->port_name
[4] = 0x8b;
7012 nv
->port_name
[5] = 0x1c;
7013 nv
->port_name
[6] = 0x55;
7014 nv
->port_name
[7] = 0x86;
7015 nv
->node_name
[0] = 0x20;
7016 nv
->node_name
[1] = 0x00;
7017 nv
->node_name
[2] = 0x00;
7018 nv
->node_name
[3] = 0xe0;
7019 nv
->node_name
[4] = 0x8b;
7020 nv
->node_name
[5] = 0x1c;
7021 nv
->node_name
[6] = 0x55;
7022 nv
->node_name
[7] = 0x86;
7023 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
7024 nv
->login_retry_count
= cpu_to_le16(8);
7025 nv
->interrupt_delay_timer
= cpu_to_le16(0);
7026 nv
->login_timeout
= cpu_to_le16(0);
7027 nv
->firmware_options_1
=
7028 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
7029 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
7030 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
7031 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
7032 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
7033 nv
->efi_parameters
= cpu_to_le32(0);
7034 nv
->reset_delay
= 5;
7035 nv
->max_luns_per_target
= cpu_to_le16(128);
7036 nv
->port_down_retry_count
= cpu_to_le16(30);
7037 nv
->link_down_timeout
= cpu_to_le16(30);
7042 if (qla_tgt_mode_enabled(vha
)) {
7043 /* Don't enable full login after initial LIP */
7044 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
7045 /* Don't enable LIP full login for initiator */
7046 nv
->host_p
&= cpu_to_le32(~BIT_10
);
7049 qlt_24xx_config_nvram_stage1(vha
, nv
);
7051 /* Reset Initialization control block */
7052 memset(icb
, 0, ha
->init_cb_size
);
7054 /* Copy 1st segment. */
7055 dptr1
= (uint8_t *)icb
;
7056 dptr2
= (uint8_t *)&nv
->version
;
7057 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
7059 *dptr1
++ = *dptr2
++;
7061 icb
->login_retry_count
= nv
->login_retry_count
;
7062 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
7064 /* Copy 2nd segment. */
7065 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
7066 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
7067 cnt
= (uint8_t *)&icb
->reserved_3
-
7068 (uint8_t *)&icb
->interrupt_delay_timer
;
7070 *dptr1
++ = *dptr2
++;
7071 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
7073 * Setup driver NVRAM options.
7075 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
7078 qlt_24xx_config_nvram_stage2(vha
, icb
);
7080 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
7081 /* Use alternate WWN? */
7082 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
7083 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
7086 /* Prepare nodename */
7087 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
7089 * Firmware will apply the following mask if the nodename was
7092 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
7093 icb
->node_name
[0] &= 0xF0;
7096 /* Set host adapter parameters. */
7097 ha
->flags
.disable_risc_code_load
= 0;
7098 ha
->flags
.enable_lip_reset
= 0;
7099 ha
->flags
.enable_lip_full_login
=
7100 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
7101 ha
->flags
.enable_target_reset
=
7102 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
7103 ha
->flags
.enable_led_scheme
= 0;
7104 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
7106 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
7107 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
7109 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
7110 sizeof(ha
->fw_seriallink_options24
));
7112 /* save HBA serial number */
7113 ha
->serial0
= icb
->port_name
[5];
7114 ha
->serial1
= icb
->port_name
[6];
7115 ha
->serial2
= icb
->port_name
[7];
7116 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
7117 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
7119 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
7121 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
7123 /* Set minimum login_timeout to 4 seconds. */
7124 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
7125 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
7126 if (le16_to_cpu(nv
->login_timeout
) < 4)
7127 nv
->login_timeout
= cpu_to_le16(4);
7128 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
7130 /* Set minimum RATOV to 100 tenths of a second. */
7133 ha
->loop_reset_delay
= nv
->reset_delay
;
7135 /* Link Down Timeout = 0:
7137 * When Port Down timer expires we will start returning
7138 * I/O's to OS with "DID_NO_CONNECT".
7140 * Link Down Timeout != 0:
7142 * The driver waits for the link to come up after link down
7143 * before returning I/Os to OS with "DID_NO_CONNECT".
7145 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
7146 ha
->loop_down_abort_time
=
7147 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
7149 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
7150 ha
->loop_down_abort_time
=
7151 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
7154 /* Need enough time to try and get the port back. */
7155 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
7156 if (qlport_down_retry
)
7157 ha
->port_down_retry_count
= qlport_down_retry
;
7159 /* Set login_retry_count */
7160 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
7161 if (ha
->port_down_retry_count
==
7162 le16_to_cpu(nv
->port_down_retry_count
) &&
7163 ha
->port_down_retry_count
> 3)
7164 ha
->login_retry_count
= ha
->port_down_retry_count
;
7165 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
7166 ha
->login_retry_count
= ha
->port_down_retry_count
;
7167 if (ql2xloginretrycount
)
7168 ha
->login_retry_count
= ql2xloginretrycount
;
7170 /* N2N: driver will initiate Login instead of FW */
7171 icb
->firmware_options_3
|= BIT_8
;
7174 if (!vha
->flags
.init_done
) {
7175 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
7176 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
7177 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
7178 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
7180 icb
->firmware_options_2
&= cpu_to_le32(
7181 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
7182 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
7183 ha
->zio_mode
= QLA_ZIO_MODE_6
;
7185 ql_log(ql_log_info
, vha
, 0x006f,
7186 "ZIO mode %d enabled; timer delay (%d us).\n",
7187 ha
->zio_mode
, ha
->zio_timer
* 100);
7189 icb
->firmware_options_2
|= cpu_to_le32(
7190 (uint32_t)ha
->zio_mode
);
7191 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
7195 ql_log(ql_log_warn
, vha
, 0x0070,
7196 "NVRAM configuration failed.\n");
7201 uint8_t qla27xx_find_valid_image(struct scsi_qla_host
*vha
)
7203 struct qla27xx_image_status pri_image_status
, sec_image_status
;
7204 uint8_t valid_pri_image
, valid_sec_image
;
7206 uint32_t cnt
, chksum
, size
;
7207 struct qla_hw_data
*ha
= vha
->hw
;
7209 valid_pri_image
= valid_sec_image
= 1;
7210 ha
->active_image
= 0;
7211 size
= sizeof(struct qla27xx_image_status
) / sizeof(uint32_t);
7213 if (!ha
->flt_region_img_status_pri
) {
7214 valid_pri_image
= 0;
7215 goto check_sec_image
;
7218 qla24xx_read_flash_data(vha
, (uint32_t *)(&pri_image_status
),
7219 ha
->flt_region_img_status_pri
, size
);
7221 if (pri_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
7222 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7223 "Primary image signature (0x%x) not valid\n",
7224 pri_image_status
.signature
);
7225 valid_pri_image
= 0;
7226 goto check_sec_image
;
7229 wptr
= (uint32_t *)(&pri_image_status
);
7232 for (chksum
= 0; cnt
--; wptr
++)
7233 chksum
+= le32_to_cpu(*wptr
);
7236 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7237 "Checksum validation failed for primary image (0x%x)\n",
7239 valid_pri_image
= 0;
7243 if (!ha
->flt_region_img_status_sec
) {
7244 valid_sec_image
= 0;
7245 goto check_valid_image
;
7248 qla24xx_read_flash_data(vha
, (uint32_t *)(&sec_image_status
),
7249 ha
->flt_region_img_status_sec
, size
);
7251 if (sec_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
7252 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7253 "Secondary image signature(0x%x) not valid\n",
7254 sec_image_status
.signature
);
7255 valid_sec_image
= 0;
7256 goto check_valid_image
;
7259 wptr
= (uint32_t *)(&sec_image_status
);
7261 for (chksum
= 0; cnt
--; wptr
++)
7262 chksum
+= le32_to_cpu(*wptr
);
7264 ql_dbg(ql_dbg_init
, vha
, 0x018e,
7265 "Checksum validation failed for secondary image (0x%x)\n",
7267 valid_sec_image
= 0;
7271 if (valid_pri_image
&& (pri_image_status
.image_status_mask
& 0x1))
7272 ha
->active_image
= QLA27XX_PRIMARY_IMAGE
;
7273 if (valid_sec_image
&& (sec_image_status
.image_status_mask
& 0x1)) {
7274 if (!ha
->active_image
||
7275 pri_image_status
.generation_number
<
7276 sec_image_status
.generation_number
)
7277 ha
->active_image
= QLA27XX_SECONDARY_IMAGE
;
7280 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x018f, "%s image\n",
7281 ha
->active_image
== 0 ? "default bootld and fw" :
7282 ha
->active_image
== 1 ? "primary" :
7283 ha
->active_image
== 2 ? "secondary" :
7286 return ha
->active_image
;
7290 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
7293 int rval
= QLA_SUCCESS
;
7294 int segments
, fragment
;
7295 uint32_t *dcode
, dlen
;
7299 struct qla_hw_data
*ha
= vha
->hw
;
7300 struct req_que
*req
= ha
->req_q_map
[0];
7302 ql_dbg(ql_dbg_init
, vha
, 0x008b,
7303 "FW: Loading firmware from flash (%x).\n", faddr
);
7307 segments
= FA_RISC_CODE_SEGMENTS
;
7308 dcode
= (uint32_t *)req
->ring
;
7311 if (IS_QLA27XX(ha
) &&
7312 qla27xx_find_valid_image(vha
) == QLA27XX_SECONDARY_IMAGE
)
7313 faddr
= ha
->flt_region_fw_sec
;
7315 /* Validate firmware image by checking version. */
7316 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
7317 for (i
= 0; i
< 4; i
++)
7318 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7319 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7320 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7321 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7323 ql_log(ql_log_fatal
, vha
, 0x008c,
7324 "Unable to verify the integrity of flash firmware "
7326 ql_log(ql_log_fatal
, vha
, 0x008d,
7327 "Firmware data: %08x %08x %08x %08x.\n",
7328 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7330 return QLA_FUNCTION_FAILED
;
7333 while (segments
&& rval
== QLA_SUCCESS
) {
7334 /* Read segment's load information. */
7335 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
7337 risc_addr
= be32_to_cpu(dcode
[2]);
7338 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7339 risc_size
= be32_to_cpu(dcode
[3]);
7342 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7343 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7344 if (dlen
> risc_size
)
7347 ql_dbg(ql_dbg_init
, vha
, 0x008e,
7348 "Loading risc segment@ risc addr %x "
7349 "number of dwords 0x%x offset 0x%x.\n",
7350 risc_addr
, dlen
, faddr
);
7352 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
7353 for (i
= 0; i
< dlen
; i
++)
7354 dcode
[i
] = swab32(dcode
[i
]);
7356 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7359 ql_log(ql_log_fatal
, vha
, 0x008f,
7360 "Failed to load segment %d of firmware.\n",
7362 return QLA_FUNCTION_FAILED
;
7375 if (!IS_QLA27XX(ha
))
7378 if (ha
->fw_dump_template
)
7379 vfree(ha
->fw_dump_template
);
7380 ha
->fw_dump_template
= NULL
;
7381 ha
->fw_dump_template_len
= 0;
7383 ql_dbg(ql_dbg_init
, vha
, 0x0161,
7384 "Loading fwdump template from %x\n", faddr
);
7385 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
7386 risc_size
= be32_to_cpu(dcode
[2]);
7387 ql_dbg(ql_dbg_init
, vha
, 0x0162,
7388 "-> array size %x dwords\n", risc_size
);
7389 if (risc_size
== 0 || risc_size
== ~0)
7390 goto default_template
;
7392 dlen
= (risc_size
- 8) * sizeof(*dcode
);
7393 ql_dbg(ql_dbg_init
, vha
, 0x0163,
7394 "-> template allocating %x bytes...\n", dlen
);
7395 ha
->fw_dump_template
= vmalloc(dlen
);
7396 if (!ha
->fw_dump_template
) {
7397 ql_log(ql_log_warn
, vha
, 0x0164,
7398 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7399 goto default_template
;
7404 dcode
= ha
->fw_dump_template
;
7405 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
7406 for (i
= 0; i
< risc_size
; i
++)
7407 dcode
[i
] = le32_to_cpu(dcode
[i
]);
7409 if (!qla27xx_fwdt_template_valid(dcode
)) {
7410 ql_log(ql_log_warn
, vha
, 0x0165,
7411 "Failed fwdump template validate\n");
7412 goto default_template
;
7415 dlen
= qla27xx_fwdt_template_size(dcode
);
7416 ql_dbg(ql_dbg_init
, vha
, 0x0166,
7417 "-> template size %x bytes\n", dlen
);
7418 if (dlen
> risc_size
* sizeof(*dcode
)) {
7419 ql_log(ql_log_warn
, vha
, 0x0167,
7420 "Failed fwdump template exceeds array by %zx bytes\n",
7421 (size_t)(dlen
- risc_size
* sizeof(*dcode
)));
7422 goto default_template
;
7424 ha
->fw_dump_template_len
= dlen
;
7428 ql_log(ql_log_warn
, vha
, 0x0168, "Using 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;
7434 dlen
= qla27xx_fwdt_template_default_size();
7435 ql_dbg(ql_dbg_init
, vha
, 0x0169,
7436 "-> template allocating %x bytes...\n", dlen
);
7437 ha
->fw_dump_template
= vmalloc(dlen
);
7438 if (!ha
->fw_dump_template
) {
7439 ql_log(ql_log_warn
, vha
, 0x016a,
7440 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7441 goto failed_template
;
7444 dcode
= ha
->fw_dump_template
;
7445 risc_size
= dlen
/ sizeof(*dcode
);
7446 memcpy(dcode
, qla27xx_fwdt_template_default(), dlen
);
7447 for (i
= 0; i
< risc_size
; i
++)
7448 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7450 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7451 ql_log(ql_log_warn
, vha
, 0x016b,
7452 "Failed fwdump template validate\n");
7453 goto failed_template
;
7456 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7457 ql_dbg(ql_dbg_init
, vha
, 0x016c,
7458 "-> template size %x bytes\n", dlen
);
7459 ha
->fw_dump_template_len
= dlen
;
7463 ql_log(ql_log_warn
, vha
, 0x016d, "Failed default fwdump template\n");
7464 if (ha
->fw_dump_template
)
7465 vfree(ha
->fw_dump_template
);
7466 ha
->fw_dump_template
= NULL
;
7467 ha
->fw_dump_template_len
= 0;
7471 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7474 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7478 uint16_t *wcode
, *fwcode
;
7479 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
7480 struct fw_blob
*blob
;
7481 struct qla_hw_data
*ha
= vha
->hw
;
7482 struct req_que
*req
= ha
->req_q_map
[0];
7484 /* Load firmware blob. */
7485 blob
= qla2x00_request_firmware(vha
);
7487 ql_log(ql_log_info
, vha
, 0x0083,
7488 "Firmware image unavailable.\n");
7489 ql_log(ql_log_info
, vha
, 0x0084,
7490 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
7491 return QLA_FUNCTION_FAILED
;
7496 wcode
= (uint16_t *)req
->ring
;
7498 fwcode
= (uint16_t *)blob
->fw
->data
;
7501 /* Validate firmware image by checking version. */
7502 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
7503 ql_log(ql_log_fatal
, vha
, 0x0085,
7504 "Unable to verify integrity of firmware image (%zd).\n",
7506 goto fail_fw_integrity
;
7508 for (i
= 0; i
< 4; i
++)
7509 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
7510 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
7511 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
7512 wcode
[2] == 0 && wcode
[3] == 0)) {
7513 ql_log(ql_log_fatal
, vha
, 0x0086,
7514 "Unable to verify integrity of firmware image.\n");
7515 ql_log(ql_log_fatal
, vha
, 0x0087,
7516 "Firmware data: %04x %04x %04x %04x.\n",
7517 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
7518 goto fail_fw_integrity
;
7522 while (*seg
&& rval
== QLA_SUCCESS
) {
7524 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
7525 risc_size
= be16_to_cpu(fwcode
[3]);
7527 /* Validate firmware image size. */
7528 fwclen
+= risc_size
* sizeof(uint16_t);
7529 if (blob
->fw
->size
< fwclen
) {
7530 ql_log(ql_log_fatal
, vha
, 0x0088,
7531 "Unable to verify integrity of firmware image "
7532 "(%zd).\n", blob
->fw
->size
);
7533 goto fail_fw_integrity
;
7537 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7538 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
7539 if (wlen
> risc_size
)
7541 ql_dbg(ql_dbg_init
, vha
, 0x0089,
7542 "Loading risc segment@ risc addr %x number of "
7543 "words 0x%x.\n", risc_addr
, wlen
);
7545 for (i
= 0; i
< wlen
; i
++)
7546 wcode
[i
] = swab16(fwcode
[i
]);
7548 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7551 ql_log(ql_log_fatal
, vha
, 0x008a,
7552 "Failed to load segment %d of firmware.\n",
7569 return QLA_FUNCTION_FAILED
;
7573 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7576 int segments
, fragment
;
7577 uint32_t *dcode
, dlen
;
7581 struct fw_blob
*blob
;
7582 const uint32_t *fwcode
;
7584 struct qla_hw_data
*ha
= vha
->hw
;
7585 struct req_que
*req
= ha
->req_q_map
[0];
7587 /* Load firmware blob. */
7588 blob
= qla2x00_request_firmware(vha
);
7590 ql_log(ql_log_warn
, vha
, 0x0090,
7591 "Firmware image unavailable.\n");
7592 ql_log(ql_log_warn
, vha
, 0x0091,
7593 "Firmware images can be retrieved from: "
7596 return QLA_FUNCTION_FAILED
;
7599 ql_dbg(ql_dbg_init
, vha
, 0x0092,
7600 "FW: Loading via request-firmware.\n");
7604 segments
= FA_RISC_CODE_SEGMENTS
;
7605 dcode
= (uint32_t *)req
->ring
;
7607 fwcode
= (uint32_t *)blob
->fw
->data
;
7610 /* Validate firmware image by checking version. */
7611 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
7612 ql_log(ql_log_fatal
, vha
, 0x0093,
7613 "Unable to verify integrity of firmware image (%zd).\n",
7615 return QLA_FUNCTION_FAILED
;
7617 for (i
= 0; i
< 4; i
++)
7618 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
7619 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7620 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7621 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7623 ql_log(ql_log_fatal
, vha
, 0x0094,
7624 "Unable to verify integrity of firmware image (%zd).\n",
7626 ql_log(ql_log_fatal
, vha
, 0x0095,
7627 "Firmware data: %08x %08x %08x %08x.\n",
7628 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7629 return QLA_FUNCTION_FAILED
;
7632 while (segments
&& rval
== QLA_SUCCESS
) {
7633 risc_addr
= be32_to_cpu(fwcode
[2]);
7634 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7635 risc_size
= be32_to_cpu(fwcode
[3]);
7637 /* Validate firmware image size. */
7638 fwclen
+= risc_size
* sizeof(uint32_t);
7639 if (blob
->fw
->size
< fwclen
) {
7640 ql_log(ql_log_fatal
, vha
, 0x0096,
7641 "Unable to verify integrity of firmware image "
7642 "(%zd).\n", blob
->fw
->size
);
7643 return QLA_FUNCTION_FAILED
;
7647 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7648 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7649 if (dlen
> risc_size
)
7652 ql_dbg(ql_dbg_init
, vha
, 0x0097,
7653 "Loading risc segment@ risc addr %x "
7654 "number of dwords 0x%x.\n", risc_addr
, dlen
);
7656 for (i
= 0; i
< dlen
; i
++)
7657 dcode
[i
] = swab32(fwcode
[i
]);
7659 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7662 ql_log(ql_log_fatal
, vha
, 0x0098,
7663 "Failed to load segment %d of firmware.\n",
7665 return QLA_FUNCTION_FAILED
;
7678 if (!IS_QLA27XX(ha
))
7681 if (ha
->fw_dump_template
)
7682 vfree(ha
->fw_dump_template
);
7683 ha
->fw_dump_template
= NULL
;
7684 ha
->fw_dump_template_len
= 0;
7686 ql_dbg(ql_dbg_init
, vha
, 0x171,
7687 "Loading fwdump template from %x\n",
7688 (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
));
7689 risc_size
= be32_to_cpu(fwcode
[2]);
7690 ql_dbg(ql_dbg_init
, vha
, 0x172,
7691 "-> array size %x dwords\n", risc_size
);
7692 if (risc_size
== 0 || risc_size
== ~0)
7693 goto default_template
;
7695 dlen
= (risc_size
- 8) * sizeof(*fwcode
);
7696 ql_dbg(ql_dbg_init
, vha
, 0x0173,
7697 "-> template allocating %x bytes...\n", dlen
);
7698 ha
->fw_dump_template
= vmalloc(dlen
);
7699 if (!ha
->fw_dump_template
) {
7700 ql_log(ql_log_warn
, vha
, 0x0174,
7701 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7702 goto default_template
;
7707 dcode
= ha
->fw_dump_template
;
7708 for (i
= 0; i
< risc_size
; i
++)
7709 dcode
[i
] = le32_to_cpu(fwcode
[i
]);
7711 if (!qla27xx_fwdt_template_valid(dcode
)) {
7712 ql_log(ql_log_warn
, vha
, 0x0175,
7713 "Failed fwdump template validate\n");
7714 goto default_template
;
7717 dlen
= qla27xx_fwdt_template_size(dcode
);
7718 ql_dbg(ql_dbg_init
, vha
, 0x0176,
7719 "-> template size %x bytes\n", dlen
);
7720 if (dlen
> risc_size
* sizeof(*fwcode
)) {
7721 ql_log(ql_log_warn
, vha
, 0x0177,
7722 "Failed fwdump template exceeds array by %zx bytes\n",
7723 (size_t)(dlen
- risc_size
* sizeof(*fwcode
)));
7724 goto default_template
;
7726 ha
->fw_dump_template_len
= dlen
;
7730 ql_log(ql_log_warn
, vha
, 0x0178, "Using 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;
7736 dlen
= qla27xx_fwdt_template_default_size();
7737 ql_dbg(ql_dbg_init
, vha
, 0x0179,
7738 "-> template allocating %x bytes...\n", dlen
);
7739 ha
->fw_dump_template
= vmalloc(dlen
);
7740 if (!ha
->fw_dump_template
) {
7741 ql_log(ql_log_warn
, vha
, 0x017a,
7742 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7743 goto failed_template
;
7746 dcode
= ha
->fw_dump_template
;
7747 risc_size
= dlen
/ sizeof(*fwcode
);
7748 fwcode
= qla27xx_fwdt_template_default();
7749 for (i
= 0; i
< risc_size
; i
++)
7750 dcode
[i
] = be32_to_cpu(fwcode
[i
]);
7752 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7753 ql_log(ql_log_warn
, vha
, 0x017b,
7754 "Failed fwdump template validate\n");
7755 goto failed_template
;
7758 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7759 ql_dbg(ql_dbg_init
, vha
, 0x017c,
7760 "-> template size %x bytes\n", dlen
);
7761 ha
->fw_dump_template_len
= dlen
;
7765 ql_log(ql_log_warn
, vha
, 0x017d, "Failed default fwdump template\n");
7766 if (ha
->fw_dump_template
)
7767 vfree(ha
->fw_dump_template
);
7768 ha
->fw_dump_template
= NULL
;
7769 ha
->fw_dump_template_len
= 0;
7774 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7778 if (ql2xfwloadbin
== 1)
7779 return qla81xx_load_risc(vha
, srisc_addr
);
7783 * 1) Firmware via request-firmware interface (.bin file).
7784 * 2) Firmware residing in flash.
7786 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7787 if (rval
== QLA_SUCCESS
)
7790 return qla24xx_load_risc_flash(vha
, srisc_addr
,
7791 vha
->hw
->flt_region_fw
);
7795 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7798 struct qla_hw_data
*ha
= vha
->hw
;
7800 if (ql2xfwloadbin
== 2)
7805 * 1) Firmware residing in flash.
7806 * 2) Firmware via request-firmware interface (.bin file).
7807 * 3) Golden-Firmware residing in flash -- limited operation.
7809 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
7810 if (rval
== QLA_SUCCESS
)
7814 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7815 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
7818 ql_log(ql_log_info
, vha
, 0x0099,
7819 "Attempting to fallback to golden firmware.\n");
7820 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
7821 if (rval
!= QLA_SUCCESS
)
7824 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
7825 ha
->flags
.running_gold_fw
= 1;
7830 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
7833 struct qla_hw_data
*ha
= vha
->hw
;
7835 if (ha
->flags
.pci_channel_io_perm_failure
)
7837 if (!IS_FWI2_CAPABLE(ha
))
7839 if (!ha
->fw_major_version
)
7841 if (!ha
->flags
.fw_started
)
7844 ret
= qla2x00_stop_firmware(vha
);
7845 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
7846 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
7847 ha
->isp_ops
->reset_chip(vha
);
7848 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
7850 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
7852 ql_log(ql_log_info
, vha
, 0x8015,
7853 "Attempting retry of stop-firmware command.\n");
7854 ret
= qla2x00_stop_firmware(vha
);
7858 ha
->flags
.fw_init_done
= 0;
7862 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
7864 int rval
= QLA_SUCCESS
;
7866 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
7867 struct qla_hw_data
*ha
= vha
->hw
;
7868 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
7873 rval
= qla2x00_fw_ready(base_vha
);
7875 if (rval
== QLA_SUCCESS
) {
7876 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
7877 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
7880 vha
->flags
.management_server_logged_in
= 0;
7882 /* Login to SNS first */
7883 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
7885 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
7886 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
7887 ql_dbg(ql_dbg_init
, vha
, 0x0120,
7888 "Failed SNS login: loop_id=%x, rval2=%d\n",
7891 ql_dbg(ql_dbg_init
, vha
, 0x0103,
7892 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7893 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7894 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
7895 return (QLA_FUNCTION_FAILED
);
7898 atomic_set(&vha
->loop_down_timer
, 0);
7899 atomic_set(&vha
->loop_state
, LOOP_UP
);
7900 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
7901 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
7902 rval
= qla2x00_loop_resync(base_vha
);
7907 /* 84XX Support **************************************************************/
7909 static LIST_HEAD(qla_cs84xx_list
);
7910 static DEFINE_MUTEX(qla_cs84xx_mutex
);
7912 static struct qla_chip_state_84xx
*
7913 qla84xx_get_chip(struct scsi_qla_host
*vha
)
7915 struct qla_chip_state_84xx
*cs84xx
;
7916 struct qla_hw_data
*ha
= vha
->hw
;
7918 mutex_lock(&qla_cs84xx_mutex
);
7920 /* Find any shared 84xx chip. */
7921 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
7922 if (cs84xx
->bus
== ha
->pdev
->bus
) {
7923 kref_get(&cs84xx
->kref
);
7928 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
7932 kref_init(&cs84xx
->kref
);
7933 spin_lock_init(&cs84xx
->access_lock
);
7934 mutex_init(&cs84xx
->fw_update_mutex
);
7935 cs84xx
->bus
= ha
->pdev
->bus
;
7937 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
7939 mutex_unlock(&qla_cs84xx_mutex
);
7944 __qla84xx_chip_release(struct kref
*kref
)
7946 struct qla_chip_state_84xx
*cs84xx
=
7947 container_of(kref
, struct qla_chip_state_84xx
, kref
);
7949 mutex_lock(&qla_cs84xx_mutex
);
7950 list_del(&cs84xx
->list
);
7951 mutex_unlock(&qla_cs84xx_mutex
);
7956 qla84xx_put_chip(struct scsi_qla_host
*vha
)
7958 struct qla_hw_data
*ha
= vha
->hw
;
7960 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
7964 qla84xx_init_chip(scsi_qla_host_t
*vha
)
7968 struct qla_hw_data
*ha
= vha
->hw
;
7970 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
7972 rval
= qla84xx_verify_chip(vha
, status
);
7974 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
7976 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
7980 /* 81XX Support **************************************************************/
7983 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
7986 struct init_cb_81xx
*icb
;
7987 struct nvram_81xx
*nv
;
7989 uint8_t *dptr1
, *dptr2
;
7992 struct qla_hw_data
*ha
= vha
->hw
;
7995 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
7998 /* Determine NVRAM starting address. */
7999 ha
->nvram_size
= sizeof(struct nvram_81xx
);
8000 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
8001 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
8002 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
8004 /* Get VPD data into cache */
8005 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
8006 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
8009 /* Get NVRAM data into cache and calculate checksum. */
8010 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
8012 dptr
= (uint32_t *)nv
;
8013 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
8014 chksum
+= le32_to_cpu(*dptr
);
8016 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
8017 "Contents of NVRAM:\n");
8018 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
8019 (uint8_t *)nv
, ha
->nvram_size
);
8021 /* Bad NVRAM data, set defaults parameters. */
8022 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
8023 || nv
->id
[3] != ' ' ||
8024 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
8025 /* Reset NVRAM data. */
8026 ql_log(ql_log_info
, vha
, 0x0073,
8027 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
8028 "version=0x%x.\n", chksum
, nv
->id
[0],
8029 le16_to_cpu(nv
->nvram_version
));
8030 ql_log(ql_log_info
, vha
, 0x0074,
8031 "Falling back to functioning (yet invalid -- WWPN) "
8035 * Set default initialization control block.
8037 memset(nv
, 0, ha
->nvram_size
);
8038 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
8039 nv
->version
= cpu_to_le16(ICB_VERSION
);
8040 nv
->frame_payload_size
= 2048;
8041 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
8042 nv
->exchange_count
= cpu_to_le16(0);
8043 nv
->port_name
[0] = 0x21;
8044 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
8045 nv
->port_name
[2] = 0x00;
8046 nv
->port_name
[3] = 0xe0;
8047 nv
->port_name
[4] = 0x8b;
8048 nv
->port_name
[5] = 0x1c;
8049 nv
->port_name
[6] = 0x55;
8050 nv
->port_name
[7] = 0x86;
8051 nv
->node_name
[0] = 0x20;
8052 nv
->node_name
[1] = 0x00;
8053 nv
->node_name
[2] = 0x00;
8054 nv
->node_name
[3] = 0xe0;
8055 nv
->node_name
[4] = 0x8b;
8056 nv
->node_name
[5] = 0x1c;
8057 nv
->node_name
[6] = 0x55;
8058 nv
->node_name
[7] = 0x86;
8059 nv
->login_retry_count
= cpu_to_le16(8);
8060 nv
->interrupt_delay_timer
= cpu_to_le16(0);
8061 nv
->login_timeout
= cpu_to_le16(0);
8062 nv
->firmware_options_1
=
8063 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
8064 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
8065 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
8066 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
8067 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
8068 nv
->efi_parameters
= cpu_to_le32(0);
8069 nv
->reset_delay
= 5;
8070 nv
->max_luns_per_target
= cpu_to_le16(128);
8071 nv
->port_down_retry_count
= cpu_to_le16(30);
8072 nv
->link_down_timeout
= cpu_to_le16(180);
8073 nv
->enode_mac
[0] = 0x00;
8074 nv
->enode_mac
[1] = 0xC0;
8075 nv
->enode_mac
[2] = 0xDD;
8076 nv
->enode_mac
[3] = 0x04;
8077 nv
->enode_mac
[4] = 0x05;
8078 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
8083 if (IS_T10_PI_CAPABLE(ha
))
8084 nv
->frame_payload_size
&= ~7;
8086 qlt_81xx_config_nvram_stage1(vha
, nv
);
8088 /* Reset Initialization control block */
8089 memset(icb
, 0, ha
->init_cb_size
);
8091 /* Copy 1st segment. */
8092 dptr1
= (uint8_t *)icb
;
8093 dptr2
= (uint8_t *)&nv
->version
;
8094 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
8096 *dptr1
++ = *dptr2
++;
8098 icb
->login_retry_count
= nv
->login_retry_count
;
8100 /* Copy 2nd segment. */
8101 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
8102 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
8103 cnt
= (uint8_t *)&icb
->reserved_5
-
8104 (uint8_t *)&icb
->interrupt_delay_timer
;
8106 *dptr1
++ = *dptr2
++;
8108 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
8109 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8110 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
8111 icb
->enode_mac
[0] = 0x00;
8112 icb
->enode_mac
[1] = 0xC0;
8113 icb
->enode_mac
[2] = 0xDD;
8114 icb
->enode_mac
[3] = 0x04;
8115 icb
->enode_mac
[4] = 0x05;
8116 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
8119 /* Use extended-initialization control block. */
8120 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
8121 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
8123 * Setup driver NVRAM options.
8125 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
8128 qlt_81xx_config_nvram_stage2(vha
, icb
);
8130 /* Use alternate WWN? */
8131 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
8132 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
8133 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
8136 /* Prepare nodename */
8137 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
8139 * Firmware will apply the following mask if the nodename was
8142 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
8143 icb
->node_name
[0] &= 0xF0;
8146 /* Set host adapter parameters. */
8147 ha
->flags
.disable_risc_code_load
= 0;
8148 ha
->flags
.enable_lip_reset
= 0;
8149 ha
->flags
.enable_lip_full_login
=
8150 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
8151 ha
->flags
.enable_target_reset
=
8152 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
8153 ha
->flags
.enable_led_scheme
= 0;
8154 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
8156 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
8157 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
8159 /* save HBA serial number */
8160 ha
->serial0
= icb
->port_name
[5];
8161 ha
->serial1
= icb
->port_name
[6];
8162 ha
->serial2
= icb
->port_name
[7];
8163 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
8164 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
8166 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
8168 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
8170 /* Set minimum login_timeout to 4 seconds. */
8171 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
8172 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
8173 if (le16_to_cpu(nv
->login_timeout
) < 4)
8174 nv
->login_timeout
= cpu_to_le16(4);
8175 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
8177 /* Set minimum RATOV to 100 tenths of a second. */
8180 ha
->loop_reset_delay
= nv
->reset_delay
;
8182 /* Link Down Timeout = 0:
8184 * When Port Down timer expires we will start returning
8185 * I/O's to OS with "DID_NO_CONNECT".
8187 * Link Down Timeout != 0:
8189 * The driver waits for the link to come up after link down
8190 * before returning I/Os to OS with "DID_NO_CONNECT".
8192 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
8193 ha
->loop_down_abort_time
=
8194 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
8196 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
8197 ha
->loop_down_abort_time
=
8198 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
8201 /* Need enough time to try and get the port back. */
8202 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
8203 if (qlport_down_retry
)
8204 ha
->port_down_retry_count
= qlport_down_retry
;
8206 /* Set login_retry_count */
8207 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
8208 if (ha
->port_down_retry_count
==
8209 le16_to_cpu(nv
->port_down_retry_count
) &&
8210 ha
->port_down_retry_count
> 3)
8211 ha
->login_retry_count
= ha
->port_down_retry_count
;
8212 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
8213 ha
->login_retry_count
= ha
->port_down_retry_count
;
8214 if (ql2xloginretrycount
)
8215 ha
->login_retry_count
= ql2xloginretrycount
;
8217 /* if not running MSI-X we need handshaking on interrupts */
8218 if (!vha
->hw
->flags
.msix_enabled
&& (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)))
8219 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
8222 if (!vha
->flags
.init_done
) {
8223 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
8224 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
8225 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
8226 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
8228 icb
->firmware_options_2
&= cpu_to_le32(
8229 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
8230 vha
->flags
.process_response_queue
= 0;
8231 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
8232 ha
->zio_mode
= QLA_ZIO_MODE_6
;
8234 ql_log(ql_log_info
, vha
, 0x0075,
8235 "ZIO mode %d enabled; timer delay (%d us).\n",
8237 ha
->zio_timer
* 100);
8239 icb
->firmware_options_2
|= cpu_to_le32(
8240 (uint32_t)ha
->zio_mode
);
8241 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
8242 vha
->flags
.process_response_queue
= 1;
8245 /* enable RIDA Format2 */
8246 icb
->firmware_options_3
|= BIT_0
;
8248 /* N2N: driver will initiate Login instead of FW */
8249 icb
->firmware_options_3
|= BIT_8
;
8251 if (IS_QLA27XX(ha
)) {
8252 icb
->firmware_options_3
|= BIT_8
;
8253 ql_dbg(ql_log_info
, vha
, 0x0075,
8254 "Enabling direct connection.\n");
8258 ql_log(ql_log_warn
, vha
, 0x0076,
8259 "NVRAM configuration failed.\n");
8265 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
8268 struct qla_hw_data
*ha
= vha
->hw
;
8269 struct scsi_qla_host
*vp
;
8270 unsigned long flags
;
8272 status
= qla2x00_init_rings(vha
);
8274 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8275 ha
->flags
.chip_reset_done
= 1;
8277 status
= qla2x00_fw_ready(vha
);
8279 /* Issue a marker after FW becomes ready. */
8280 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
8281 vha
->flags
.online
= 1;
8282 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8285 /* if no cable then assume it's good */
8286 if ((vha
->device_flags
& DFLG_NO_CABLE
))
8291 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8293 if (!atomic_read(&vha
->loop_down_timer
)) {
8295 * Issue marker command only when we are going
8296 * to start the I/O .
8298 vha
->marker_needed
= 1;
8301 ha
->isp_ops
->enable_intrs(ha
);
8303 ha
->isp_abort_cnt
= 0;
8304 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
8306 /* Update the firmware version */
8307 status
= qla82xx_check_md_needed(vha
);
8310 ha
->flags
.fce_enabled
= 1;
8312 fce_calc_size(ha
->fce_bufs
));
8313 rval
= qla2x00_enable_fce_trace(vha
,
8314 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
8317 ql_log(ql_log_warn
, vha
, 0x8001,
8318 "Unable to reinitialize FCE (%d).\n",
8320 ha
->flags
.fce_enabled
= 0;
8325 memset(ha
->eft
, 0, EFT_SIZE
);
8326 rval
= qla2x00_enable_eft_trace(vha
,
8327 ha
->eft_dma
, EFT_NUM_BUFFERS
);
8329 ql_log(ql_log_warn
, vha
, 0x8010,
8330 "Unable to reinitialize EFT (%d).\n",
8337 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
8338 "qla82xx_restart_isp succeeded.\n");
8340 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8341 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
8343 atomic_inc(&vp
->vref_count
);
8344 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8346 qla2x00_vp_abort_isp(vp
);
8348 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8349 atomic_dec(&vp
->vref_count
);
8352 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8355 ql_log(ql_log_warn
, vha
, 0x8016,
8356 "qla82xx_restart_isp **** FAILED ****.\n");
8363 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
8365 struct qla_hw_data
*ha
= vha
->hw
;
8367 /* Hold status IOCBs until ABTS response received. */
8369 ha
->fw_options
[3] |= BIT_12
;
8371 /* Set Retry FLOGI in case of P2P connection */
8372 if (ha
->operating_mode
== P2P
) {
8373 ha
->fw_options
[2] |= BIT_3
;
8374 ql_dbg(ql_dbg_disc
, vha
, 0x2103,
8375 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8376 __func__
, ha
->fw_options
[2]);
8379 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8380 if (ql2xmvasynctoatio
) {
8381 if (qla_tgt_mode_enabled(vha
) ||
8382 qla_dual_mode_enabled(vha
))
8383 ha
->fw_options
[2] |= BIT_11
;
8385 ha
->fw_options
[2] &= ~BIT_11
;
8388 if (qla_tgt_mode_enabled(vha
) ||
8389 qla_dual_mode_enabled(vha
)) {
8390 /* FW auto send SCSI status during */
8391 ha
->fw_options
[1] |= BIT_8
;
8392 ha
->fw_options
[10] |= (u16
)SAM_STAT_BUSY
<< 8;
8394 /* FW perform Exchange validation */
8395 ha
->fw_options
[2] |= BIT_4
;
8397 ha
->fw_options
[1] &= ~BIT_8
;
8398 ha
->fw_options
[10] &= 0x00ff;
8400 ha
->fw_options
[2] &= ~BIT_4
;
8403 if (ql2xetsenable
) {
8404 /* Enable ETS Burst. */
8405 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
8406 ha
->fw_options
[2] |= BIT_9
;
8409 ql_dbg(ql_dbg_init
, vha
, 0x00e9,
8410 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8411 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
8412 ha
->fw_options
[3], vha
->host
->active_mode
);
8414 qla2x00_set_fw_options(vha
, ha
->fw_options
);
8418 * qla24xx_get_fcp_prio
8419 * Gets the fcp cmd priority value for the logged in port.
8420 * Looks for a match of the port descriptors within
8421 * each of the fcp prio config entries. If a match is found,
8422 * the tag (priority) value is returned.
8425 * vha = scsi host structure pointer.
8426 * fcport = port structure pointer.
8429 * non-zero (if found)
8436 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8439 uint8_t pid_match
, wwn_match
;
8441 uint32_t pid1
, pid2
;
8442 uint64_t wwn1
, wwn2
;
8443 struct qla_fcp_prio_entry
*pri_entry
;
8444 struct qla_hw_data
*ha
= vha
->hw
;
8446 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
8450 entries
= ha
->fcp_prio_cfg
->num_entries
;
8451 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
8453 for (i
= 0; i
< entries
; i
++) {
8454 pid_match
= wwn_match
= 0;
8456 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
8461 /* check source pid for a match */
8462 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
8463 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
8464 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
8465 if (pid1
== INVALID_PORT_ID
)
8467 else if (pid1
== pid2
)
8471 /* check destination pid for a match */
8472 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
8473 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
8474 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
8475 if (pid1
== INVALID_PORT_ID
)
8477 else if (pid1
== pid2
)
8481 /* check source WWN for a match */
8482 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
8483 wwn1
= wwn_to_u64(vha
->port_name
);
8484 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
8485 if (wwn2
== (uint64_t)-1)
8487 else if (wwn1
== wwn2
)
8491 /* check destination WWN for a match */
8492 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
8493 wwn1
= wwn_to_u64(fcport
->port_name
);
8494 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
8495 if (wwn2
== (uint64_t)-1)
8497 else if (wwn1
== wwn2
)
8501 if (pid_match
== 2 || wwn_match
== 2) {
8502 /* Found a matching entry */
8503 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
8504 priority
= pri_entry
->tag
;
8515 * qla24xx_update_fcport_fcp_prio
8516 * Activates fcp priority for the logged in fc port
8519 * vha = scsi host structure pointer.
8520 * fcp = port structure pointer.
8523 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8529 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8535 if (fcport
->port_type
!= FCT_TARGET
||
8536 fcport
->loop_id
== FC_NO_LOOP_ID
)
8537 return QLA_FUNCTION_FAILED
;
8539 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
8541 return QLA_FUNCTION_FAILED
;
8543 if (IS_P3P_TYPE(vha
->hw
)) {
8544 fcport
->fcp_prio
= priority
& 0xf;
8548 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
8549 if (ret
== QLA_SUCCESS
) {
8550 if (fcport
->fcp_prio
!= priority
)
8551 ql_dbg(ql_dbg_user
, vha
, 0x709e,
8552 "Updated FCP_CMND priority - value=%d loop_id=%d "
8553 "port_id=%02x%02x%02x.\n", priority
,
8554 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
8555 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
8556 fcport
->fcp_prio
= priority
& 0xf;
8558 ql_dbg(ql_dbg_user
, vha
, 0x704f,
8559 "Unable to update FCP_CMND priority - ret=0x%x for "
8560 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
8561 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
8562 fcport
->d_id
.b
.al_pa
);
8567 * qla24xx_update_all_fcp_prio
8568 * Activates fcp priority for all the logged in ports
8571 * ha = adapter block pointer.
8574 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8580 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
8585 ret
= QLA_FUNCTION_FAILED
;
8586 /* We need to set priority for all logged in ports */
8587 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
8588 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);
8593 struct qla_qpair
*qla2xxx_create_qpair(struct scsi_qla_host
*vha
, int qos
,
8594 int vp_idx
, bool startqp
)
8599 struct qla_hw_data
*ha
= vha
->hw
;
8600 uint16_t qpair_id
= 0;
8601 struct qla_qpair
*qpair
= NULL
;
8602 struct qla_msix_entry
*msix
;
8604 if (!(ha
->fw_attributes
& BIT_6
) || !ha
->flags
.msix_enabled
) {
8605 ql_log(ql_log_warn
, vha
, 0x00181,
8606 "FW/Driver is not multi-queue capable.\n");
8610 if (ql2xmqsupport
|| ql2xnvmeenable
) {
8611 qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
8612 if (qpair
== NULL
) {
8613 ql_log(ql_log_warn
, vha
, 0x0182,
8614 "Failed to allocate memory for queue pair.\n");
8617 memset(qpair
, 0, sizeof(struct qla_qpair
));
8619 qpair
->hw
= vha
->hw
;
8621 qpair
->qp_lock_ptr
= &qpair
->qp_lock
;
8622 spin_lock_init(&qpair
->qp_lock
);
8623 qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
8625 /* Assign available que pair id */
8626 mutex_lock(&ha
->mq_lock
);
8627 qpair_id
= find_first_zero_bit(ha
->qpair_qid_map
, ha
->max_qpairs
);
8628 if (ha
->num_qpairs
>= ha
->max_qpairs
) {
8629 mutex_unlock(&ha
->mq_lock
);
8630 ql_log(ql_log_warn
, vha
, 0x0183,
8631 "No resources to create additional q pair.\n");
8635 set_bit(qpair_id
, ha
->qpair_qid_map
);
8636 ha
->queue_pair_map
[qpair_id
] = qpair
;
8637 qpair
->id
= qpair_id
;
8638 qpair
->vp_idx
= vp_idx
;
8639 qpair
->fw_started
= ha
->flags
.fw_started
;
8640 INIT_LIST_HEAD(&qpair
->hints_list
);
8641 qpair
->chip_reset
= ha
->base_qpair
->chip_reset
;
8642 qpair
->enable_class_2
= ha
->base_qpair
->enable_class_2
;
8643 qpair
->enable_explicit_conf
=
8644 ha
->base_qpair
->enable_explicit_conf
;
8646 for (i
= 0; i
< ha
->msix_count
; i
++) {
8647 msix
= &ha
->msix_entries
[i
];
8651 ql_dbg(ql_dbg_multiq
, vha
, 0xc00f,
8652 "Vector %x selected for qpair\n", msix
->vector
);
8656 ql_log(ql_log_warn
, vha
, 0x0184,
8657 "Out of MSI-X vectors!.\n");
8661 qpair
->msix
->in_use
= 1;
8662 list_add_tail(&qpair
->qp_list_elem
, &vha
->qp_list
);
8663 qpair
->pdev
= ha
->pdev
;
8664 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
))
8665 qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
8667 mutex_unlock(&ha
->mq_lock
);
8669 /* Create response queue first */
8670 rsp_id
= qla25xx_create_rsp_que(ha
, 0, 0, 0, qpair
, startqp
);
8672 ql_log(ql_log_warn
, vha
, 0x0185,
8673 "Failed to create response queue.\n");
8677 qpair
->rsp
= ha
->rsp_q_map
[rsp_id
];
8679 /* Create request queue */
8680 req_id
= qla25xx_create_req_que(ha
, 0, vp_idx
, 0, rsp_id
, qos
,
8683 ql_log(ql_log_warn
, vha
, 0x0186,
8684 "Failed to create request queue.\n");
8688 qpair
->req
= ha
->req_q_map
[req_id
];
8689 qpair
->rsp
->req
= qpair
->req
;
8690 qpair
->rsp
->qpair
= qpair
;
8691 /* init qpair to this cpu. Will adjust at run time. */
8692 qla_cpu_update(qpair
, smp_processor_id());
8694 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
8695 if (ha
->fw_attributes
& BIT_4
)
8696 qpair
->difdix_supported
= 1;
8699 qpair
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
8700 if (!qpair
->srb_mempool
) {
8701 ql_log(ql_log_warn
, vha
, 0xd036,
8702 "Failed to create srb mempool for qpair %d\n",
8707 /* Mark as online */
8710 if (!vha
->flags
.qpairs_available
)
8711 vha
->flags
.qpairs_available
= 1;
8713 ql_dbg(ql_dbg_multiq
, vha
, 0xc00d,
8714 "Request/Response queue pair created, id %d\n",
8716 ql_dbg(ql_dbg_init
, vha
, 0x0187,
8717 "Request/Response queue pair created, id %d\n",
8724 qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8726 mutex_lock(&ha
->mq_lock
);
8727 qpair
->msix
->in_use
= 0;
8728 list_del(&qpair
->qp_list_elem
);
8729 if (list_empty(&vha
->qp_list
))
8730 vha
->flags
.qpairs_available
= 0;
8732 ha
->queue_pair_map
[qpair_id
] = NULL
;
8733 clear_bit(qpair_id
, ha
->qpair_qid_map
);
8735 mutex_unlock(&ha
->mq_lock
);
8741 int qla2xxx_delete_qpair(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
)
8743 int ret
= QLA_FUNCTION_FAILED
;
8744 struct qla_hw_data
*ha
= qpair
->hw
;
8746 qpair
->delete_in_progress
= 1;
8747 while (atomic_read(&qpair
->ref_count
))
8750 ret
= qla25xx_delete_req_que(vha
, qpair
->req
);
8751 if (ret
!= QLA_SUCCESS
)
8754 ret
= qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8755 if (ret
!= QLA_SUCCESS
)
8758 mutex_lock(&ha
->mq_lock
);
8759 ha
->queue_pair_map
[qpair
->id
] = NULL
;
8760 clear_bit(qpair
->id
, ha
->qpair_qid_map
);
8762 list_del(&qpair
->qp_list_elem
);
8763 if (list_empty(&vha
->qp_list
)) {
8764 vha
->flags
.qpairs_available
= 0;
8765 vha
->flags
.qpairs_req_created
= 0;
8766 vha
->flags
.qpairs_rsp_created
= 0;
8768 mempool_destroy(qpair
->srb_mempool
);
8770 mutex_unlock(&ha
->mq_lock
);