1 // SPDX-License-Identifier: GPL-2.0-only
3 * QLogic Fibre Channel HBA Driver
4 * Copyright (c) 2003-2014 QLogic Corporation
9 #include <linux/delay.h>
10 #include <linux/slab.h>
11 #include <linux/vmalloc.h>
13 #include "qla_devtbl.h"
19 #include "qla_target.h"
22 * QLogic ISP2x00 Hardware Support Function Prototypes.
24 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
25 static int qla2x00_setup_chip(scsi_qla_host_t
*);
26 static int qla2x00_fw_ready(scsi_qla_host_t
*);
27 static int qla2x00_configure_hba(scsi_qla_host_t
*);
28 static int qla2x00_configure_loop(scsi_qla_host_t
*);
29 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
30 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
31 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*);
32 static int qla2x00_restart_isp(scsi_qla_host_t
*);
34 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
35 static int qla84xx_init_chip(scsi_qla_host_t
*);
36 static int qla25xx_init_queues(struct qla_hw_data
*);
37 static int qla24xx_post_prli_work(struct scsi_qla_host
*, fc_port_t
*);
38 static void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
,
39 struct event_arg
*ea
);
40 static void qla24xx_handle_prli_done_event(struct scsi_qla_host
*,
42 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*, struct event_arg
*);
44 /* SRB Extensions ---------------------------------------------------------- */
47 qla2x00_sp_timeout(struct timer_list
*t
)
49 srb_t
*sp
= from_timer(sp
, t
, u
.iocb_cmd
.timer
);
50 struct srb_iocb
*iocb
;
52 WARN_ON(irqs_disabled());
53 iocb
= &sp
->u
.iocb_cmd
;
57 void qla2x00_sp_free(srb_t
*sp
)
59 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
61 del_timer(&iocb
->timer
);
65 void qla2xxx_rel_done_warning(srb_t
*sp
, int res
)
67 WARN_ONCE(1, "Calling done() of an already freed srb %p object\n", sp
);
70 void qla2xxx_rel_free_warning(srb_t
*sp
)
72 WARN_ONCE(1, "Calling free() of an already freed srb %p object\n", sp
);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
78 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
81 struct qla_hw_data
*ha
= vha
->hw
;
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo
= ha
->r_a_tov
/ 10 * 2;
86 tmo
= FX00_DEF_RATOV
* 2;
87 } else if (!IS_FWI2_CAPABLE(ha
)) {
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
92 tmo
= ha
->login_timeout
;
97 static void qla24xx_abort_iocb_timeout(void *data
)
100 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
101 struct qla_qpair
*qpair
= sp
->qpair
;
106 ql_dbg(ql_dbg_async
, sp
->vha
, 0x507c,
107 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
108 sp
->cmd_sp
->handle
, sp
->cmd_sp
->type
,
109 sp
->handle
, sp
->type
);
111 ql_dbg(ql_dbg_async
, sp
->vha
, 0x507c,
112 "Abort timeout 2 - hdl=%x, type=%x\n",
113 sp
->handle
, sp
->type
);
115 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
116 for (handle
= 1; handle
< qpair
->req
->num_outstanding_cmds
; handle
++) {
117 if (sp
->cmd_sp
&& (qpair
->req
->outstanding_cmds
[handle
] ==
119 qpair
->req
->outstanding_cmds
[handle
] = NULL
;
121 /* removing the abort */
122 if (qpair
->req
->outstanding_cmds
[handle
] == sp
) {
123 qpair
->req
->outstanding_cmds
[handle
] = NULL
;
127 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
130 sp
->cmd_sp
->done(sp
->cmd_sp
, QLA_OS_TIMER_EXPIRED
);
132 abt
->u
.abt
.comp_status
= cpu_to_le16(CS_TIMEOUT
);
133 sp
->done(sp
, QLA_OS_TIMER_EXPIRED
);
136 static void qla24xx_abort_sp_done(srb_t
*sp
, int res
)
138 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
140 del_timer(&sp
->u
.iocb_cmd
.timer
);
141 if (sp
->flags
& SRB_WAKEUP_ON_COMP
)
142 complete(&abt
->u
.abt
.comp
);
147 int qla24xx_async_abort_cmd(srb_t
*cmd_sp
, bool wait
)
149 scsi_qla_host_t
*vha
= cmd_sp
->vha
;
150 struct srb_iocb
*abt_iocb
;
152 int rval
= QLA_FUNCTION_FAILED
;
154 sp
= qla2xxx_get_qpair_sp(cmd_sp
->vha
, cmd_sp
->qpair
, cmd_sp
->fcport
,
159 abt_iocb
= &sp
->u
.iocb_cmd
;
160 sp
->type
= SRB_ABT_CMD
;
162 sp
->qpair
= cmd_sp
->qpair
;
165 sp
->flags
= SRB_WAKEUP_ON_COMP
;
167 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
168 init_completion(&abt_iocb
->u
.abt
.comp
);
169 /* FW can send 2 x ABTS's timeout/20s */
170 qla2x00_init_timer(sp
, 42);
172 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
173 abt_iocb
->u
.abt
.req_que_no
= cpu_to_le16(cmd_sp
->qpair
->req
->id
);
175 sp
->done
= qla24xx_abort_sp_done
;
177 ql_dbg(ql_dbg_async
, vha
, 0x507c,
178 "Abort command issued - hdl=%x, type=%x\n", cmd_sp
->handle
,
181 rval
= qla2x00_start_sp(sp
);
182 if (rval
!= QLA_SUCCESS
) {
188 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
189 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
190 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
198 qla2x00_async_iocb_timeout(void *data
)
201 fc_port_t
*fcport
= sp
->fcport
;
202 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
207 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
208 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
209 sp
->name
, sp
->handle
, fcport
->d_id
.b24
, fcport
->port_name
);
211 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
213 pr_info("Async-%s timeout - hdl=%x.\n",
214 sp
->name
, sp
->handle
);
219 rc
= qla24xx_async_abort_cmd(sp
, false);
221 /* Retry as needed. */
222 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
223 lio
->u
.logio
.data
[1] =
224 lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
225 QLA_LOGIO_LOGIN_RETRIED
: 0;
226 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
227 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
;
229 if (sp
->qpair
->req
->outstanding_cmds
[h
] ==
231 sp
->qpair
->req
->outstanding_cmds
[h
] =
236 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
237 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
241 case SRB_CT_PTHRU_CMD
:
248 rc
= qla24xx_async_abort_cmd(sp
, false);
250 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
251 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
;
253 if (sp
->qpair
->req
->outstanding_cmds
[h
] ==
255 sp
->qpair
->req
->outstanding_cmds
[h
] =
260 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
261 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
267 static void qla2x00_async_login_sp_done(srb_t
*sp
, int res
)
269 struct scsi_qla_host
*vha
= sp
->vha
;
270 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
273 ql_dbg(ql_dbg_disc
, vha
, 0x20dd,
274 "%s %8phC res %d \n", __func__
, sp
->fcport
->port_name
, res
);
276 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
278 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
279 memset(&ea
, 0, sizeof(ea
));
280 ea
.fcport
= sp
->fcport
;
281 ea
.data
[0] = lio
->u
.logio
.data
[0];
282 ea
.data
[1] = lio
->u
.logio
.data
[1];
283 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
284 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
286 qla24xx_handle_plogi_done_event(vha
, &ea
);
293 fcport_is_smaller(fc_port_t
*fcport
)
295 if (wwn_to_u64(fcport
->port_name
) <
296 wwn_to_u64(fcport
->vha
->port_name
))
303 fcport_is_bigger(fc_port_t
*fcport
)
305 return !fcport_is_smaller(fcport
);
309 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
313 struct srb_iocb
*lio
;
314 int rval
= QLA_FUNCTION_FAILED
;
316 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
) ||
317 fcport
->loop_id
== FC_NO_LOOP_ID
) {
318 ql_log(ql_log_warn
, vha
, 0xffff,
319 "%s: %8phC - not sending command.\n",
320 __func__
, fcport
->port_name
);
324 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
328 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_PEND
);
329 fcport
->flags
|= FCF_ASYNC_SENT
;
330 fcport
->logout_completed
= 0;
332 sp
->type
= SRB_LOGIN_CMD
;
334 sp
->gen1
= fcport
->rscn_gen
;
335 sp
->gen2
= fcport
->login_gen
;
337 lio
= &sp
->u
.iocb_cmd
;
338 lio
->timeout
= qla2x00_async_iocb_timeout
;
339 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
341 sp
->done
= qla2x00_async_login_sp_done
;
342 if (N2N_TOPO(fcport
->vha
->hw
) && fcport_is_bigger(fcport
))
343 lio
->u
.logio
.flags
|= SRB_LOGIN_PRLI_ONLY
;
345 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
347 if (NVME_TARGET(vha
->hw
, fcport
))
348 lio
->u
.logio
.flags
|= SRB_LOGIN_SKIP_PRLI
;
350 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
351 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
352 "retries=%d.\n", fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
353 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
354 fcport
->login_retry
);
356 rval
= qla2x00_start_sp(sp
);
357 if (rval
!= QLA_SUCCESS
) {
358 fcport
->flags
|= FCF_LOGIN_NEEDED
;
359 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
367 fcport
->flags
&= ~FCF_ASYNC_SENT
;
369 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
373 static void qla2x00_async_logout_sp_done(srb_t
*sp
, int res
)
375 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
376 sp
->fcport
->login_gen
++;
377 qlt_logo_completion_handler(sp
->fcport
, res
);
382 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
385 struct srb_iocb
*lio
;
386 int rval
= QLA_FUNCTION_FAILED
;
388 fcport
->flags
|= FCF_ASYNC_SENT
;
389 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
393 sp
->type
= SRB_LOGOUT_CMD
;
396 lio
= &sp
->u
.iocb_cmd
;
397 lio
->timeout
= qla2x00_async_iocb_timeout
;
398 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
400 sp
->done
= qla2x00_async_logout_sp_done
;
402 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
403 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
404 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
405 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
408 rval
= qla2x00_start_sp(sp
);
409 if (rval
!= QLA_SUCCESS
)
416 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
421 qla2x00_async_prlo_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
424 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
425 /* Don't re-login in target mode */
426 if (!fcport
->tgt_session
)
427 qla2x00_mark_device_lost(vha
, fcport
, 1);
428 qlt_logo_completion_handler(fcport
, data
[0]);
431 static void qla2x00_async_prlo_sp_done(srb_t
*sp
, int res
)
433 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
434 struct scsi_qla_host
*vha
= sp
->vha
;
436 sp
->fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
437 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
438 qla2x00_post_async_prlo_done_work(sp
->fcport
->vha
, sp
->fcport
,
444 qla2x00_async_prlo(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
447 struct srb_iocb
*lio
;
450 rval
= QLA_FUNCTION_FAILED
;
451 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
455 sp
->type
= SRB_PRLO_CMD
;
458 lio
= &sp
->u
.iocb_cmd
;
459 lio
->timeout
= qla2x00_async_iocb_timeout
;
460 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
462 sp
->done
= qla2x00_async_prlo_sp_done
;
464 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
465 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
466 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
467 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
469 rval
= qla2x00_start_sp(sp
);
470 if (rval
!= QLA_SUCCESS
)
478 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
483 void qla24xx_handle_adisc_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
485 struct fc_port
*fcport
= ea
->fcport
;
487 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
488 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
489 __func__
, fcport
->port_name
, fcport
->disc_state
,
490 fcport
->fw_login_state
, ea
->rc
, fcport
->login_gen
, ea
->sp
->gen2
,
491 fcport
->rscn_gen
, ea
->sp
->gen1
, fcport
->loop_id
);
493 WARN_ONCE(!qla2xxx_is_valid_mbs(ea
->data
[0]), "mbs: %#x\n",
496 if (ea
->data
[0] != MBS_COMMAND_COMPLETE
) {
497 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
498 "%s %8phC: adisc fail: post delete\n",
499 __func__
, ea
->fcport
->port_name
);
500 /* deleted = 0 & logout_on_delete = force fw cleanup */
502 fcport
->logout_on_delete
= 1;
503 qlt_schedule_sess_for_deletion(ea
->fcport
);
507 if (ea
->fcport
->disc_state
== DSC_DELETE_PEND
)
510 if (ea
->sp
->gen2
!= ea
->fcport
->login_gen
) {
511 /* target side must have changed it. */
512 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
513 "%s %8phC generation changed\n",
514 __func__
, ea
->fcport
->port_name
);
516 } else if (ea
->sp
->gen1
!= ea
->fcport
->rscn_gen
) {
517 qla_rscn_replay(fcport
);
518 qlt_schedule_sess_for_deletion(fcport
);
522 __qla24xx_handle_gpdb_event(vha
, ea
);
525 static int qla_post_els_plogi_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
527 struct qla_work_evt
*e
;
529 e
= qla2x00_alloc_work(vha
, QLA_EVT_ELS_PLOGI
);
531 return QLA_FUNCTION_FAILED
;
533 e
->u
.fcport
.fcport
= fcport
;
534 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
535 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_PEND
);
536 return qla2x00_post_work(vha
, e
);
539 static void qla2x00_async_adisc_sp_done(srb_t
*sp
, int res
)
541 struct scsi_qla_host
*vha
= sp
->vha
;
543 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
545 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
546 "Async done-%s res %x %8phC\n",
547 sp
->name
, res
, sp
->fcport
->port_name
);
549 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
551 memset(&ea
, 0, sizeof(ea
));
553 ea
.data
[0] = lio
->u
.logio
.data
[0];
554 ea
.data
[1] = lio
->u
.logio
.data
[1];
555 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
556 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
557 ea
.fcport
= sp
->fcport
;
560 qla24xx_handle_adisc_event(vha
, &ea
);
566 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
570 struct srb_iocb
*lio
;
571 int rval
= QLA_FUNCTION_FAILED
;
573 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
576 fcport
->flags
|= FCF_ASYNC_SENT
;
577 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
581 sp
->type
= SRB_ADISC_CMD
;
584 lio
= &sp
->u
.iocb_cmd
;
585 lio
->timeout
= qla2x00_async_iocb_timeout
;
586 sp
->gen1
= fcport
->rscn_gen
;
587 sp
->gen2
= fcport
->login_gen
;
588 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
590 sp
->done
= qla2x00_async_adisc_sp_done
;
591 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
592 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
594 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
595 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
596 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
, fcport
->port_name
);
598 rval
= qla2x00_start_sp(sp
);
599 if (rval
!= QLA_SUCCESS
)
607 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
608 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
612 static bool qla2x00_is_reserved_id(scsi_qla_host_t
*vha
, uint16_t loop_id
)
614 struct qla_hw_data
*ha
= vha
->hw
;
616 if (IS_FWI2_CAPABLE(ha
))
617 return loop_id
> NPH_LAST_HANDLE
;
619 return (loop_id
> ha
->max_loop_id
&& loop_id
< SNS_FIRST_LOOP_ID
) ||
620 loop_id
== MANAGEMENT_SERVER
|| loop_id
== BROADCAST
;
624 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
625 * @vha: adapter state pointer.
626 * @dev: port structure pointer.
629 * qla2x00 local function return status code.
634 static int qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
637 struct qla_hw_data
*ha
= vha
->hw
;
638 unsigned long flags
= 0;
642 spin_lock_irqsave(&ha
->vport_slock
, flags
);
644 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
, LOOPID_MAP_SIZE
);
645 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
646 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
647 dev
->loop_id
= FC_NO_LOOP_ID
;
648 rval
= QLA_FUNCTION_FAILED
;
650 set_bit(dev
->loop_id
, ha
->loop_id_map
);
652 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
654 if (rval
== QLA_SUCCESS
)
655 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
656 "Assigning new loopid=%x, portid=%x.\n",
657 dev
->loop_id
, dev
->d_id
.b24
);
659 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
660 "No loop_id's available, portid=%x.\n",
666 void qla2x00_clear_loop_id(fc_port_t
*fcport
)
668 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
670 if (fcport
->loop_id
== FC_NO_LOOP_ID
||
671 qla2x00_is_reserved_id(fcport
->vha
, fcport
->loop_id
))
674 clear_bit(fcport
->loop_id
, ha
->loop_id_map
);
675 fcport
->loop_id
= FC_NO_LOOP_ID
;
678 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t
*vha
,
679 struct event_arg
*ea
)
681 fc_port_t
*fcport
, *conflict_fcport
;
682 struct get_name_list_extended
*e
;
683 u16 i
, n
, found
= 0, loop_id
;
687 u8 current_login_state
, nvme_cls
;
690 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
691 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
692 __func__
, fcport
->port_name
, fcport
->disc_state
,
693 fcport
->fw_login_state
, ea
->rc
,
694 fcport
->login_gen
, fcport
->last_login_gen
,
695 fcport
->rscn_gen
, fcport
->last_rscn_gen
, vha
->loop_id
);
697 if (fcport
->disc_state
== DSC_DELETE_PEND
)
700 if (ea
->rc
) { /* rval */
701 if (fcport
->login_retry
== 0) {
702 ql_dbg(ql_dbg_disc
, vha
, 0x20de,
703 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
704 fcport
->port_name
, fcport
->login_retry
);
709 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
710 qla_rscn_replay(fcport
);
711 qlt_schedule_sess_for_deletion(fcport
);
713 } else if (fcport
->last_login_gen
!= fcport
->login_gen
) {
714 ql_dbg(ql_dbg_disc
, vha
, 0x20e0,
715 "%s %8phC login gen changed\n",
716 __func__
, fcport
->port_name
);
720 n
= ea
->data
[0] / sizeof(struct get_name_list_extended
);
722 ql_dbg(ql_dbg_disc
, vha
, 0x20e1,
723 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
724 __func__
, __LINE__
, fcport
->port_name
, n
,
725 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
726 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
);
728 for (i
= 0; i
< n
; i
++) {
730 wwn
= wwn_to_u64(e
->port_name
);
731 id
.b
.domain
= e
->port_id
[2];
732 id
.b
.area
= e
->port_id
[1];
733 id
.b
.al_pa
= e
->port_id
[0];
736 if (memcmp((u8
*)&wwn
, fcport
->port_name
, WWN_SIZE
))
739 if (IS_SW_RESV_ADDR(id
))
744 loop_id
= le16_to_cpu(e
->nport_handle
);
745 loop_id
= (loop_id
& 0x7fff);
746 nvme_cls
= e
->current_login_state
>> 4;
747 current_login_state
= e
->current_login_state
& 0xf;
749 if (PRLI_PHASE(nvme_cls
)) {
750 current_login_state
= nvme_cls
;
751 fcport
->fc4_type
&= ~FS_FC4TYPE_FCP
;
752 fcport
->fc4_type
|= FS_FC4TYPE_NVME
;
753 } else if (PRLI_PHASE(current_login_state
)) {
754 fcport
->fc4_type
|= FS_FC4TYPE_FCP
;
755 fcport
->fc4_type
&= ~FS_FC4TYPE_NVME
;
758 ql_dbg(ql_dbg_disc
, vha
, 0x20e2,
759 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
760 __func__
, fcport
->port_name
,
761 e
->current_login_state
, fcport
->fw_login_state
,
762 fcport
->fc4_type
, id
.b24
, fcport
->d_id
.b24
,
763 loop_id
, fcport
->loop_id
);
765 switch (fcport
->disc_state
) {
766 case DSC_DELETE_PEND
:
770 if ((id
.b24
!= fcport
->d_id
.b24
&&
772 fcport
->loop_id
!= FC_NO_LOOP_ID
) ||
773 (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
774 fcport
->loop_id
!= loop_id
)) {
775 ql_dbg(ql_dbg_disc
, vha
, 0x20e3,
776 "%s %d %8phC post del sess\n",
777 __func__
, __LINE__
, fcport
->port_name
);
778 if (fcport
->n2n_flag
)
779 fcport
->d_id
.b24
= 0;
780 qlt_schedule_sess_for_deletion(fcport
);
786 fcport
->loop_id
= loop_id
;
787 if (fcport
->n2n_flag
)
788 fcport
->d_id
.b24
= id
.b24
;
790 wwn
= wwn_to_u64(fcport
->port_name
);
791 qlt_find_sess_invalidate_other(vha
, wwn
,
792 id
, loop_id
, &conflict_fcport
);
794 if (conflict_fcport
) {
796 * Another share fcport share the same loop_id &
797 * nport id. Conflict fcport needs to finish
798 * cleanup before this fcport can proceed to login.
800 conflict_fcport
->conflict
= fcport
;
801 fcport
->login_pause
= 1;
804 switch (vha
->hw
->current_topology
) {
806 switch (current_login_state
) {
807 case DSC_LS_PRLI_COMP
:
808 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
,
809 vha
, 0x20e4, "%s %d %8phC post gpdb\n",
810 __func__
, __LINE__
, fcport
->port_name
);
812 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
813 fcport
->port_type
= FCT_INITIATOR
;
815 fcport
->port_type
= FCT_TARGET
;
816 data
[0] = data
[1] = 0;
817 qla2x00_post_async_adisc_work(vha
, fcport
,
820 case DSC_LS_PORT_UNAVAIL
:
822 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
823 qla2x00_find_new_loop_id(vha
, fcport
);
824 fcport
->fw_login_state
=
827 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
828 "%s %d %8phC\n", __func__
, __LINE__
,
830 qla24xx_fcport_handle_login(vha
, fcport
);
835 fcport
->fw_login_state
= current_login_state
;
837 switch (current_login_state
) {
838 case DSC_LS_PRLI_PEND
:
840 * In the middle of PRLI. Let it finish.
841 * Allow relogin code to recheck state again
842 * with GNL. Push disc_state back to DELETED
843 * so GNL can go out again
845 qla2x00_set_fcport_disc_state(fcport
,
848 case DSC_LS_PRLI_COMP
:
849 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
850 fcport
->port_type
= FCT_INITIATOR
;
852 fcport
->port_type
= FCT_TARGET
;
854 data
[0] = data
[1] = 0;
855 qla2x00_post_async_adisc_work(vha
, fcport
,
858 case DSC_LS_PLOGI_COMP
:
859 if (fcport_is_bigger(fcport
)) {
860 /* local adapter is smaller */
861 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
862 qla2x00_clear_loop_id(fcport
);
864 fcport
->loop_id
= loop_id
;
865 qla24xx_fcport_handle_login(vha
,
871 if (fcport_is_smaller(fcport
)) {
872 /* local adapter is bigger */
873 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
874 qla2x00_clear_loop_id(fcport
);
876 fcport
->loop_id
= loop_id
;
877 qla24xx_fcport_handle_login(vha
,
883 } /* switch (ha->current_topology) */
887 switch (vha
->hw
->current_topology
) {
890 for (i
= 0; i
< n
; i
++) {
892 id
.b
.domain
= e
->port_id
[0];
893 id
.b
.area
= e
->port_id
[1];
894 id
.b
.al_pa
= e
->port_id
[2];
896 loop_id
= le16_to_cpu(e
->nport_handle
);
898 if (fcport
->d_id
.b24
== id
.b24
) {
900 qla2x00_find_fcport_by_wwpn(vha
,
902 if (conflict_fcport
) {
903 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
,
905 "%s %d %8phC post del sess\n",
907 conflict_fcport
->port_name
);
908 qlt_schedule_sess_for_deletion
913 * FW already picked this loop id for
916 if (fcport
->loop_id
== loop_id
)
917 fcport
->loop_id
= FC_NO_LOOP_ID
;
919 qla24xx_fcport_handle_login(vha
, fcport
);
922 qla2x00_set_fcport_disc_state(fcport
, DSC_DELETED
);
923 if (time_after_eq(jiffies
, fcport
->dm_login_expire
)) {
924 if (fcport
->n2n_link_reset_cnt
< 2) {
925 fcport
->n2n_link_reset_cnt
++;
927 * remote port is not sending PLOGI.
928 * Reset link to kick start his state
931 set_bit(N2N_LINK_RESET
,
934 if (fcport
->n2n_chip_reset
< 1) {
935 ql_log(ql_log_info
, vha
, 0x705d,
936 "Chip reset to bring laser down");
937 set_bit(ISP_ABORT_NEEDED
,
939 fcport
->n2n_chip_reset
++;
941 ql_log(ql_log_info
, vha
, 0x705d,
942 "Remote port %8ph is not coming back\n",
944 fcport
->scan_state
= 0;
947 qla2xxx_wake_dpc(vha
);
950 * report port suppose to do PLOGI. Give him
951 * more time. FW will catch it.
953 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
962 static void qla24xx_async_gnl_sp_done(srb_t
*sp
, int res
)
964 struct scsi_qla_host
*vha
= sp
->vha
;
966 struct fc_port
*fcport
= NULL
, *tf
;
967 u16 i
, n
= 0, loop_id
;
969 struct get_name_list_extended
*e
;
974 ql_dbg(ql_dbg_disc
, vha
, 0x20e7,
975 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
976 sp
->name
, res
, sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1],
977 sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[2]);
979 if (res
== QLA_FUNCTION_TIMEOUT
)
982 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
|FCF_ASYNC_ACTIVE
);
983 memset(&ea
, 0, sizeof(ea
));
987 if (sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] >=
988 sizeof(struct get_name_list_extended
)) {
989 n
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] /
990 sizeof(struct get_name_list_extended
);
991 ea
.data
[0] = sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1]; /* amnt xfered */
994 for (i
= 0; i
< n
; i
++) {
996 loop_id
= le16_to_cpu(e
->nport_handle
);
997 /* mask out reserve bit */
998 loop_id
= (loop_id
& 0x7fff);
999 set_bit(loop_id
, vha
->hw
->loop_id_map
);
1000 wwn
= wwn_to_u64(e
->port_name
);
1002 ql_dbg(ql_dbg_disc
, vha
, 0x20e8,
1003 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
1004 __func__
, &wwn
, e
->port_id
[2], e
->port_id
[1],
1005 e
->port_id
[0], e
->current_login_state
, e
->last_login_state
,
1006 (loop_id
& 0x7fff));
1009 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1013 if (!list_empty(&vha
->gnl
.fcports
))
1014 list_splice_init(&vha
->gnl
.fcports
, &h
);
1015 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1017 list_for_each_entry_safe(fcport
, tf
, &h
, gnl_entry
) {
1018 list_del_init(&fcport
->gnl_entry
);
1019 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1020 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
1021 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1024 qla24xx_handle_gnl_done_event(vha
, &ea
);
1027 /* create new fcport if fw has knowledge of new sessions */
1028 for (i
= 0; i
< n
; i
++) {
1033 wwn
= wwn_to_u64(e
->port_name
);
1036 list_for_each_entry_safe(fcport
, tf
, &vha
->vp_fcports
, list
) {
1037 if (!memcmp((u8
*)&wwn
, fcport
->port_name
,
1044 id
.b
.domain
= e
->port_id
[2];
1045 id
.b
.area
= e
->port_id
[1];
1046 id
.b
.al_pa
= e
->port_id
[0];
1049 if (!found
&& wwn
&& !IS_SW_RESV_ADDR(id
)) {
1050 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
1051 "%s %d %8phC %06x post new sess\n",
1052 __func__
, __LINE__
, (u8
*)&wwn
, id
.b24
);
1053 wwnn
= wwn_to_u64(e
->node_name
);
1054 qla24xx_post_newsess_work(vha
, &id
, (u8
*)&wwn
,
1055 (u8
*)&wwnn
, NULL
, 0);
1059 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1061 if (!list_empty(&vha
->gnl
.fcports
)) {
1063 list_for_each_entry_safe(fcport
, tf
, &vha
->gnl
.fcports
,
1065 list_del_init(&fcport
->gnl_entry
);
1066 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
1067 if (qla24xx_post_gnl_work(vha
, fcport
) == QLA_SUCCESS
)
1071 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1076 int qla24xx_async_gnl(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1079 struct srb_iocb
*mbx
;
1080 int rval
= QLA_FUNCTION_FAILED
;
1081 unsigned long flags
;
1084 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
1087 ql_dbg(ql_dbg_disc
, vha
, 0x20d9,
1088 "Async-gnlist WWPN %8phC \n", fcport
->port_name
);
1090 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1091 fcport
->flags
|= FCF_ASYNC_SENT
;
1092 qla2x00_set_fcport_disc_state(fcport
, DSC_GNL
);
1093 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1094 fcport
->last_login_gen
= fcport
->login_gen
;
1096 list_add_tail(&fcport
->gnl_entry
, &vha
->gnl
.fcports
);
1097 if (vha
->gnl
.sent
) {
1098 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1102 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1104 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1108 sp
->type
= SRB_MB_IOCB
;
1109 sp
->name
= "gnlist";
1110 sp
->gen1
= fcport
->rscn_gen
;
1111 sp
->gen2
= fcport
->login_gen
;
1113 mbx
= &sp
->u
.iocb_cmd
;
1114 mbx
->timeout
= qla2x00_async_iocb_timeout
;
1115 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
1117 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
1118 mb
[0] = MBC_PORT_NODE_NAME_LIST
;
1119 mb
[1] = BIT_2
| BIT_3
;
1120 mb
[2] = MSW(vha
->gnl
.ldma
);
1121 mb
[3] = LSW(vha
->gnl
.ldma
);
1122 mb
[6] = MSW(MSD(vha
->gnl
.ldma
));
1123 mb
[7] = LSW(MSD(vha
->gnl
.ldma
));
1124 mb
[8] = vha
->gnl
.size
;
1125 mb
[9] = vha
->vp_idx
;
1127 sp
->done
= qla24xx_async_gnl_sp_done
;
1129 ql_dbg(ql_dbg_disc
, vha
, 0x20da,
1130 "Async-%s - OUT WWPN %8phC hndl %x\n",
1131 sp
->name
, fcport
->port_name
, sp
->handle
);
1133 rval
= qla2x00_start_sp(sp
);
1134 if (rval
!= QLA_SUCCESS
)
1142 fcport
->flags
&= ~(FCF_ASYNC_ACTIVE
| FCF_ASYNC_SENT
);
1146 int qla24xx_post_gnl_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1148 struct qla_work_evt
*e
;
1150 e
= qla2x00_alloc_work(vha
, QLA_EVT_GNL
);
1152 return QLA_FUNCTION_FAILED
;
1154 e
->u
.fcport
.fcport
= fcport
;
1155 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
1156 return qla2x00_post_work(vha
, e
);
1159 static void qla24xx_async_gpdb_sp_done(srb_t
*sp
, int res
)
1161 struct scsi_qla_host
*vha
= sp
->vha
;
1162 struct qla_hw_data
*ha
= vha
->hw
;
1163 fc_port_t
*fcport
= sp
->fcport
;
1164 u16
*mb
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
;
1165 struct event_arg ea
;
1167 ql_dbg(ql_dbg_disc
, vha
, 0x20db,
1168 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1169 sp
->name
, res
, fcport
->port_name
, mb
[1], mb
[2]);
1171 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
1173 if (res
== QLA_FUNCTION_TIMEOUT
)
1176 memset(&ea
, 0, sizeof(ea
));
1180 qla24xx_handle_gpdb_event(vha
, &ea
);
1183 dma_pool_free(ha
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
1184 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
1189 static int qla24xx_post_prli_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1191 struct qla_work_evt
*e
;
1193 e
= qla2x00_alloc_work(vha
, QLA_EVT_PRLI
);
1195 return QLA_FUNCTION_FAILED
;
1197 e
->u
.fcport
.fcport
= fcport
;
1199 return qla2x00_post_work(vha
, e
);
1202 static void qla2x00_async_prli_sp_done(srb_t
*sp
, int res
)
1204 struct scsi_qla_host
*vha
= sp
->vha
;
1205 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
1206 struct event_arg ea
;
1208 ql_dbg(ql_dbg_disc
, vha
, 0x2129,
1209 "%s %8phC res %d \n", __func__
,
1210 sp
->fcport
->port_name
, res
);
1212 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1214 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
1215 memset(&ea
, 0, sizeof(ea
));
1216 ea
.fcport
= sp
->fcport
;
1217 ea
.data
[0] = lio
->u
.logio
.data
[0];
1218 ea
.data
[1] = lio
->u
.logio
.data
[1];
1219 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
1220 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
1223 qla24xx_handle_prli_done_event(vha
, &ea
);
1230 qla24xx_async_prli(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1233 struct srb_iocb
*lio
;
1234 int rval
= QLA_FUNCTION_FAILED
;
1236 if (!vha
->flags
.online
) {
1237 ql_dbg(ql_dbg_disc
, vha
, 0xffff, "%s %d %8phC exit\n",
1238 __func__
, __LINE__
, fcport
->port_name
);
1242 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
||
1243 fcport
->fw_login_state
== DSC_LS_PRLI_PEND
) &&
1244 qla_dual_mode_enabled(vha
)) {
1245 ql_dbg(ql_dbg_disc
, vha
, 0xffff, "%s %d %8phC exit\n",
1246 __func__
, __LINE__
, fcport
->port_name
);
1250 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1254 fcport
->flags
|= FCF_ASYNC_SENT
;
1255 fcport
->logout_completed
= 0;
1257 sp
->type
= SRB_PRLI_CMD
;
1260 lio
= &sp
->u
.iocb_cmd
;
1261 lio
->timeout
= qla2x00_async_iocb_timeout
;
1262 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
1264 sp
->done
= qla2x00_async_prli_sp_done
;
1265 lio
->u
.logio
.flags
= 0;
1267 if (NVME_TARGET(vha
->hw
, fcport
))
1268 lio
->u
.logio
.flags
|= SRB_LOGIN_NVME_PRLI
;
1270 ql_dbg(ql_dbg_disc
, vha
, 0x211b,
1271 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d fc4type %x priority %x %s.\n",
1272 fcport
->port_name
, sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
,
1273 fcport
->login_retry
, fcport
->fc4_type
, vha
->hw
->fc4_type_priority
,
1274 NVME_TARGET(vha
->hw
, fcport
) ? "nvme" : "fcp");
1276 rval
= qla2x00_start_sp(sp
);
1277 if (rval
!= QLA_SUCCESS
) {
1278 fcport
->flags
|= FCF_LOGIN_NEEDED
;
1279 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1287 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1291 int qla24xx_post_gpdb_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
1293 struct qla_work_evt
*e
;
1295 e
= qla2x00_alloc_work(vha
, QLA_EVT_GPDB
);
1297 return QLA_FUNCTION_FAILED
;
1299 e
->u
.fcport
.fcport
= fcport
;
1300 e
->u
.fcport
.opt
= opt
;
1301 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
1302 return qla2x00_post_work(vha
, e
);
1305 int qla24xx_async_gpdb(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
1308 struct srb_iocb
*mbx
;
1309 int rval
= QLA_FUNCTION_FAILED
;
1312 struct port_database_24xx
*pd
;
1313 struct qla_hw_data
*ha
= vha
->hw
;
1315 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
) ||
1316 fcport
->loop_id
== FC_NO_LOOP_ID
) {
1317 ql_log(ql_log_warn
, vha
, 0xffff,
1318 "%s: %8phC - not sending command.\n",
1319 __func__
, fcport
->port_name
);
1323 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1327 qla2x00_set_fcport_disc_state(fcport
, DSC_GPDB
);
1329 fcport
->flags
|= FCF_ASYNC_SENT
;
1330 sp
->type
= SRB_MB_IOCB
;
1332 sp
->gen1
= fcport
->rscn_gen
;
1333 sp
->gen2
= fcport
->login_gen
;
1335 mbx
= &sp
->u
.iocb_cmd
;
1336 mbx
->timeout
= qla2x00_async_iocb_timeout
;
1337 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
1339 pd
= dma_pool_zalloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
1341 ql_log(ql_log_warn
, vha
, 0xd043,
1342 "Failed to allocate port database structure.\n");
1346 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
1347 mb
[0] = MBC_GET_PORT_DATABASE
;
1348 mb
[1] = fcport
->loop_id
;
1349 mb
[2] = MSW(pd_dma
);
1350 mb
[3] = LSW(pd_dma
);
1351 mb
[6] = MSW(MSD(pd_dma
));
1352 mb
[7] = LSW(MSD(pd_dma
));
1353 mb
[9] = vha
->vp_idx
;
1357 mbx
->u
.mbx
.in_dma
= pd_dma
;
1359 sp
->done
= qla24xx_async_gpdb_sp_done
;
1361 ql_dbg(ql_dbg_disc
, vha
, 0x20dc,
1362 "Async-%s %8phC hndl %x opt %x\n",
1363 sp
->name
, fcport
->port_name
, sp
->handle
, opt
);
1365 rval
= qla2x00_start_sp(sp
);
1366 if (rval
!= QLA_SUCCESS
)
1372 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1375 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1377 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
1378 qla24xx_post_gpdb_work(vha
, fcport
, opt
);
1383 void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1385 unsigned long flags
;
1387 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1388 ea
->fcport
->login_gen
++;
1389 ea
->fcport
->deleted
= 0;
1390 ea
->fcport
->logout_on_delete
= 1;
1392 if (!ea
->fcport
->login_succ
&& !IS_SW_RESV_ADDR(ea
->fcport
->d_id
)) {
1393 vha
->fcport_count
++;
1394 ea
->fcport
->login_succ
= 1;
1396 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1397 qla24xx_sched_upd_fcport(ea
->fcport
);
1398 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1399 } else if (ea
->fcport
->login_succ
) {
1401 * We have an existing session. A late RSCN delivery
1402 * must have triggered the session to be re-validate.
1403 * Session is still valid.
1405 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1406 "%s %d %8phC session revalidate success\n",
1407 __func__
, __LINE__
, ea
->fcport
->port_name
);
1408 qla2x00_set_fcport_disc_state(ea
->fcport
, DSC_LOGIN_COMPLETE
);
1410 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1414 void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1416 fc_port_t
*fcport
= ea
->fcport
;
1417 struct port_database_24xx
*pd
;
1418 struct srb
*sp
= ea
->sp
;
1421 pd
= (struct port_database_24xx
*)sp
->u
.iocb_cmd
.u
.mbx
.in
;
1423 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1425 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
1426 "%s %8phC DS %d LS %d fc4_type %x rc %d\n", __func__
,
1427 fcport
->port_name
, fcport
->disc_state
, pd
->current_login_state
,
1428 fcport
->fc4_type
, ea
->rc
);
1430 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1433 if (NVME_TARGET(vha
->hw
, fcport
))
1434 ls
= pd
->current_login_state
>> 4;
1436 ls
= pd
->current_login_state
& 0xf;
1438 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1439 /* target side must have changed it. */
1441 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1442 "%s %8phC generation changed\n",
1443 __func__
, fcport
->port_name
);
1445 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1446 qla_rscn_replay(fcport
);
1447 qlt_schedule_sess_for_deletion(fcport
);
1452 case PDS_PRLI_COMPLETE
:
1453 __qla24xx_parse_gpdb(vha
, fcport
, pd
);
1455 case PDS_PLOGI_PENDING
:
1456 case PDS_PLOGI_COMPLETE
:
1457 case PDS_PRLI_PENDING
:
1458 case PDS_PRLI2_PENDING
:
1459 /* Set discovery state back to GNL to Relogin attempt */
1460 if (qla_dual_mode_enabled(vha
) ||
1461 qla_ini_mode_enabled(vha
)) {
1462 qla2x00_set_fcport_disc_state(fcport
, DSC_GNL
);
1463 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1466 case PDS_LOGO_PENDING
:
1467 case PDS_PORT_UNAVAILABLE
:
1469 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC post del sess\n",
1470 __func__
, __LINE__
, fcport
->port_name
);
1471 qlt_schedule_sess_for_deletion(fcport
);
1474 __qla24xx_handle_gpdb_event(vha
, ea
);
1477 static void qla_chk_n2n_b4_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1482 if (qla_tgt_mode_enabled(vha
))
1485 if (qla_dual_mode_enabled(vha
)) {
1486 if (N2N_TOPO(vha
->hw
)) {
1489 mywwn
= wwn_to_u64(vha
->port_name
);
1490 wwn
= wwn_to_u64(fcport
->port_name
);
1493 else if ((fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1494 && time_after_eq(jiffies
,
1495 fcport
->plogi_nack_done_deadline
))
1501 /* initiator mode */
1505 if (login
&& fcport
->login_retry
) {
1506 fcport
->login_retry
--;
1507 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1508 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1509 rc
= qla2x00_find_new_loop_id(vha
, fcport
);
1511 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
1512 "%s %d %8phC post del sess - out of loopid\n",
1513 __func__
, __LINE__
, fcport
->port_name
);
1514 fcport
->scan_state
= 0;
1515 qlt_schedule_sess_for_deletion(fcport
);
1519 ql_dbg(ql_dbg_disc
, vha
, 0x20bf,
1520 "%s %d %8phC post login\n",
1521 __func__
, __LINE__
, fcport
->port_name
);
1522 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
1526 int qla24xx_fcport_handle_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1532 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1533 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1534 __func__
, fcport
->port_name
, fcport
->disc_state
,
1535 fcport
->fw_login_state
, fcport
->login_pause
, fcport
->flags
,
1536 fcport
->conflict
, fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1537 fcport
->login_gen
, fcport
->loop_id
, fcport
->scan_state
);
1539 if (fcport
->scan_state
!= QLA_FCPORT_FOUND
)
1542 if ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
1543 qla_dual_mode_enabled(vha
) &&
1544 ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1545 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)))
1548 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
&&
1549 !N2N_TOPO(vha
->hw
)) {
1550 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1551 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1556 /* Target won't initiate port login if fabric is present */
1557 if (vha
->host
->active_mode
== MODE_TARGET
&& !N2N_TOPO(vha
->hw
))
1560 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1561 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1565 switch (fcport
->disc_state
) {
1567 wwn
= wwn_to_u64(fcport
->node_name
);
1568 switch (vha
->hw
->current_topology
) {
1570 if (fcport_is_smaller(fcport
)) {
1571 /* this adapter is bigger */
1572 if (fcport
->login_retry
) {
1573 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1574 qla2x00_find_new_loop_id(vha
,
1576 fcport
->fw_login_state
=
1577 DSC_LS_PORT_UNAVAIL
;
1579 fcport
->login_retry
--;
1580 qla_post_els_plogi_work(vha
, fcport
);
1582 ql_log(ql_log_info
, vha
, 0x705d,
1583 "Unable to reach remote port %8phC",
1587 qla24xx_post_gnl_work(vha
, fcport
);
1592 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1593 "%s %d %8phC post GNNID\n",
1594 __func__
, __LINE__
, fcport
->port_name
);
1595 qla24xx_post_gnnid_work(vha
, fcport
);
1596 } else if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1597 ql_dbg(ql_dbg_disc
, vha
, 0x20bd,
1598 "%s %d %8phC post gnl\n",
1599 __func__
, __LINE__
, fcport
->port_name
);
1600 qla24xx_post_gnl_work(vha
, fcport
);
1602 qla_chk_n2n_b4_login(vha
, fcport
);
1609 switch (vha
->hw
->current_topology
) {
1611 if ((fcport
->current_login_state
& 0xf) == 0x6) {
1612 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1613 "%s %d %8phC post GPDB work\n",
1614 __func__
, __LINE__
, fcport
->port_name
);
1615 fcport
->chip_reset
=
1616 vha
->hw
->base_qpair
->chip_reset
;
1617 qla24xx_post_gpdb_work(vha
, fcport
, 0);
1619 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1620 "%s %d %8phC post %s PRLI\n",
1621 __func__
, __LINE__
, fcport
->port_name
,
1622 NVME_TARGET(vha
->hw
, fcport
) ? "NVME" :
1624 qla24xx_post_prli_work(vha
, fcport
);
1628 if (fcport
->login_pause
) {
1629 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1630 "%s %d %8phC exit\n",
1633 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1634 fcport
->last_login_gen
= fcport
->login_gen
;
1635 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1638 qla_chk_n2n_b4_login(vha
, fcport
);
1643 case DSC_LOGIN_FAILED
:
1644 if (N2N_TOPO(vha
->hw
))
1645 qla_chk_n2n_b4_login(vha
, fcport
);
1647 qlt_schedule_sess_for_deletion(fcport
);
1650 case DSC_LOGIN_COMPLETE
:
1651 /* recheck login state */
1652 data
[0] = data
[1] = 0;
1653 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
1656 case DSC_LOGIN_PEND
:
1657 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1658 qla24xx_post_prli_work(vha
, fcport
);
1661 case DSC_UPD_FCPORT
:
1662 sec
= jiffies_to_msecs(jiffies
-
1663 fcport
->jiffies_at_registration
)/1000;
1664 if (fcport
->sec_since_registration
< sec
&& sec
&&
1666 fcport
->sec_since_registration
= sec
;
1667 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0xffff,
1668 "%s %8phC - Slow Rport registration(%d Sec)\n",
1669 __func__
, fcport
->port_name
, sec
);
1672 if (fcport
->next_disc_state
!= DSC_DELETE_PEND
)
1673 fcport
->next_disc_state
= DSC_ADISC
;
1674 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1684 int qla24xx_post_newsess_work(struct scsi_qla_host
*vha
, port_id_t
*id
,
1685 u8
*port_name
, u8
*node_name
, void *pla
, u8 fc4_type
)
1687 struct qla_work_evt
*e
;
1689 e
= qla2x00_alloc_work(vha
, QLA_EVT_NEW_SESS
);
1691 return QLA_FUNCTION_FAILED
;
1693 e
->u
.new_sess
.id
= *id
;
1694 e
->u
.new_sess
.pla
= pla
;
1695 e
->u
.new_sess
.fc4_type
= fc4_type
;
1696 memcpy(e
->u
.new_sess
.port_name
, port_name
, WWN_SIZE
);
1698 memcpy(e
->u
.new_sess
.node_name
, node_name
, WWN_SIZE
);
1700 return qla2x00_post_work(vha
, e
);
1703 void qla2x00_handle_rscn(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1706 unsigned long flags
;
1708 fcport
= qla2x00_find_fcport_by_nportid(vha
, &ea
->id
, 1);
1710 fcport
->scan_needed
= 1;
1714 spin_lock_irqsave(&vha
->work_lock
, flags
);
1715 if (vha
->scan
.scan_flags
== 0) {
1716 ql_dbg(ql_dbg_disc
, vha
, 0xffff, "%s: schedule\n", __func__
);
1717 vha
->scan
.scan_flags
|= SF_QUEUED
;
1718 schedule_delayed_work(&vha
->scan
.scan_work
, 5);
1720 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1723 void qla24xx_handle_relogin_event(scsi_qla_host_t
*vha
,
1724 struct event_arg
*ea
)
1726 fc_port_t
*fcport
= ea
->fcport
;
1728 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1731 ql_dbg(ql_dbg_disc
, vha
, 0x2102,
1732 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1733 __func__
, fcport
->port_name
, fcport
->disc_state
,
1734 fcport
->fw_login_state
, fcport
->login_pause
,
1735 fcport
->deleted
, fcport
->conflict
,
1736 fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1737 fcport
->last_login_gen
, fcport
->login_gen
,
1740 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
1741 ql_dbg(ql_dbg_disc
, vha
, 0x20e9, "%s %d %8phC post gnl\n",
1742 __func__
, __LINE__
, fcport
->port_name
);
1743 qla24xx_post_gnl_work(vha
, fcport
);
1747 qla24xx_fcport_handle_login(vha
, fcport
);
1750 void qla_handle_els_plogi_done(scsi_qla_host_t
*vha
,
1751 struct event_arg
*ea
)
1753 /* for pure Target Mode, PRLI will not be initiated */
1754 if (vha
->host
->active_mode
== MODE_TARGET
)
1757 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1758 "%s %d %8phC post PRLI\n",
1759 __func__
, __LINE__
, ea
->fcport
->port_name
);
1760 qla24xx_post_prli_work(vha
, ea
->fcport
);
1764 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1765 * to be consumed by the fcport
1767 void qla_rscn_replay(fc_port_t
*fcport
)
1769 struct event_arg ea
;
1771 switch (fcport
->disc_state
) {
1772 case DSC_DELETE_PEND
:
1778 if (fcport
->scan_needed
) {
1779 memset(&ea
, 0, sizeof(ea
));
1780 ea
.id
= fcport
->d_id
;
1781 ea
.id
.b
.rsvd_1
= RSCN_PORT_ADDR
;
1782 qla2x00_handle_rscn(fcport
->vha
, &ea
);
1787 qla2x00_tmf_iocb_timeout(void *data
)
1790 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1792 unsigned long flags
;
1794 rc
= qla24xx_async_abort_cmd(sp
, false);
1796 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
1797 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
; h
++) {
1798 if (sp
->qpair
->req
->outstanding_cmds
[h
] == sp
) {
1799 sp
->qpair
->req
->outstanding_cmds
[h
] = NULL
;
1803 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
1804 tmf
->u
.tmf
.comp_status
= cpu_to_le16(CS_TIMEOUT
);
1805 tmf
->u
.tmf
.data
= QLA_FUNCTION_FAILED
;
1806 complete(&tmf
->u
.tmf
.comp
);
1810 static void qla2x00_tmf_sp_done(srb_t
*sp
, int res
)
1812 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1814 complete(&tmf
->u
.tmf
.comp
);
1818 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
1821 struct scsi_qla_host
*vha
= fcport
->vha
;
1822 struct srb_iocb
*tm_iocb
;
1824 int rval
= QLA_FUNCTION_FAILED
;
1826 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1830 tm_iocb
= &sp
->u
.iocb_cmd
;
1831 sp
->type
= SRB_TM_CMD
;
1834 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
1835 init_completion(&tm_iocb
->u
.tmf
.comp
);
1836 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1838 tm_iocb
->u
.tmf
.flags
= flags
;
1839 tm_iocb
->u
.tmf
.lun
= lun
;
1840 tm_iocb
->u
.tmf
.data
= tag
;
1841 sp
->done
= qla2x00_tmf_sp_done
;
1843 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
1844 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1845 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1846 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1848 rval
= qla2x00_start_sp(sp
);
1849 if (rval
!= QLA_SUCCESS
)
1851 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
1853 rval
= tm_iocb
->u
.tmf
.data
;
1855 if (rval
!= QLA_SUCCESS
) {
1856 ql_log(ql_log_warn
, vha
, 0x8030,
1857 "TM IOCB failed (%x).\n", rval
);
1860 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
1861 flags
= tm_iocb
->u
.tmf
.flags
;
1862 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
1864 /* Issue Marker IOCB */
1865 qla2x00_marker(vha
, vha
->hw
->base_qpair
,
1866 fcport
->loop_id
, lun
,
1867 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
1872 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1878 qla24xx_async_abort_command(srb_t
*sp
)
1880 unsigned long flags
= 0;
1883 fc_port_t
*fcport
= sp
->fcport
;
1884 struct qla_qpair
*qpair
= sp
->qpair
;
1885 struct scsi_qla_host
*vha
= fcport
->vha
;
1886 struct req_que
*req
= qpair
->req
;
1888 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
1889 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
1890 if (req
->outstanding_cmds
[handle
] == sp
)
1893 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
1895 if (handle
== req
->num_outstanding_cmds
) {
1896 /* Command not found. */
1897 return QLA_FUNCTION_FAILED
;
1899 if (sp
->type
== SRB_FXIOCB_DCMD
)
1900 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
1901 FXDISC_ABORT_IOCTL
);
1903 return qla24xx_async_abort_cmd(sp
, true);
1907 qla24xx_handle_prli_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1909 WARN_ONCE(!qla2xxx_is_valid_mbs(ea
->data
[0]), "mbs: %#x\n",
1912 switch (ea
->data
[0]) {
1913 case MBS_COMMAND_COMPLETE
:
1914 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1915 "%s %d %8phC post gpdb\n",
1916 __func__
, __LINE__
, ea
->fcport
->port_name
);
1918 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1919 ea
->fcport
->logout_on_delete
= 1;
1920 ea
->fcport
->nvme_prli_service_param
= ea
->iop
[0];
1921 if (ea
->iop
[0] & NVME_PRLI_SP_FIRST_BURST
)
1922 ea
->fcport
->nvme_first_burst_size
=
1923 (ea
->iop
[1] & 0xffff) * 512;
1925 ea
->fcport
->nvme_first_burst_size
= 0;
1926 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1929 if ((ea
->iop
[0] == LSC_SCODE_ELS_REJECT
) &&
1930 (ea
->iop
[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1931 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1932 ea
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
1936 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1937 "%s %d %8phC priority %s, fc4type %x\n",
1938 __func__
, __LINE__
, ea
->fcport
->port_name
,
1939 vha
->hw
->fc4_type_priority
== FC4_PRIORITY_FCP
?
1940 "FCP" : "NVMe", ea
->fcport
->fc4_type
);
1942 if (N2N_TOPO(vha
->hw
)) {
1943 if (vha
->hw
->fc4_type_priority
== FC4_PRIORITY_NVME
) {
1944 ea
->fcport
->fc4_type
&= ~FS_FC4TYPE_NVME
;
1945 ea
->fcport
->fc4_type
|= FS_FC4TYPE_FCP
;
1947 ea
->fcport
->fc4_type
&= ~FS_FC4TYPE_FCP
;
1948 ea
->fcport
->fc4_type
|= FS_FC4TYPE_NVME
;
1951 if (ea
->fcport
->n2n_link_reset_cnt
< 3) {
1952 ea
->fcport
->n2n_link_reset_cnt
++;
1953 vha
->relogin_jif
= jiffies
+ 2 * HZ
;
1955 * PRLI failed. Reset link to kick start
1958 set_bit(N2N_LINK_RESET
, &vha
->dpc_flags
);
1960 ql_log(ql_log_warn
, vha
, 0x2119,
1961 "%s %d %8phC Unable to reconnect\n",
1963 ea
->fcport
->port_name
);
1967 * switch connect. login failed. Take connection down
1968 * and allow relogin to retrigger
1970 if (NVME_FCP_TARGET(ea
->fcport
)) {
1971 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1972 "%s %d %8phC post %s prli\n",
1974 ea
->fcport
->port_name
,
1975 (ea
->fcport
->fc4_type
& FS_FC4TYPE_NVME
)
1977 if (vha
->hw
->fc4_type_priority
== FC4_PRIORITY_NVME
)
1978 ea
->fcport
->fc4_type
&= ~FS_FC4TYPE_NVME
;
1980 ea
->fcport
->fc4_type
&= ~FS_FC4TYPE_FCP
;
1983 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1984 ea
->fcport
->keep_nport_handle
= 0;
1985 ea
->fcport
->logout_on_delete
= 1;
1986 qlt_schedule_sess_for_deletion(ea
->fcport
);
1993 qla24xx_handle_plogi_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1995 port_id_t cid
; /* conflict Nport id */
1997 struct fc_port
*conflict_fcport
;
1998 unsigned long flags
;
1999 struct fc_port
*fcport
= ea
->fcport
;
2001 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
2002 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
2003 __func__
, fcport
->port_name
, fcport
->disc_state
,
2004 fcport
->fw_login_state
, ea
->rc
, ea
->sp
->gen2
, fcport
->login_gen
,
2005 ea
->sp
->gen1
, fcport
->rscn_gen
,
2006 ea
->data
[0], ea
->data
[1], ea
->iop
[0], ea
->iop
[1]);
2008 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
2009 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)) {
2010 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
2011 "%s %d %8phC Remote is trying to login\n",
2012 __func__
, __LINE__
, fcport
->port_name
);
2016 if ((fcport
->disc_state
== DSC_DELETE_PEND
) ||
2017 (fcport
->disc_state
== DSC_DELETED
)) {
2018 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2022 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
2023 /* target side must have changed it. */
2024 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
2025 "%s %8phC generation changed\n",
2026 __func__
, fcport
->port_name
);
2027 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2029 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
2030 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
2031 "%s %8phC RSCN generation changed\n",
2032 __func__
, fcport
->port_name
);
2033 qla_rscn_replay(fcport
);
2034 qlt_schedule_sess_for_deletion(fcport
);
2038 WARN_ONCE(!qla2xxx_is_valid_mbs(ea
->data
[0]), "mbs: %#x\n",
2041 switch (ea
->data
[0]) {
2042 case MBS_COMMAND_COMPLETE
:
2044 * Driver must validate login state - If PRLI not complete,
2045 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2048 if (NVME_TARGET(vha
->hw
, ea
->fcport
)) {
2049 ql_dbg(ql_dbg_disc
, vha
, 0x2117,
2050 "%s %d %8phC post prli\n",
2051 __func__
, __LINE__
, ea
->fcport
->port_name
);
2052 qla24xx_post_prli_work(vha
, ea
->fcport
);
2054 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
2055 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2056 __func__
, __LINE__
, ea
->fcport
->port_name
,
2057 ea
->fcport
->loop_id
, ea
->fcport
->d_id
.b24
);
2059 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
2060 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
2061 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
2062 ea
->fcport
->logout_on_delete
= 1;
2063 ea
->fcport
->send_els_logo
= 0;
2064 ea
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
2065 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
2067 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
2070 case MBS_COMMAND_ERROR
:
2071 ql_dbg(ql_dbg_disc
, vha
, 0x20eb, "%s %d %8phC cmd error %x\n",
2072 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[1]);
2074 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
2075 qla2x00_set_fcport_disc_state(ea
->fcport
, DSC_LOGIN_FAILED
);
2076 if (ea
->data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
2077 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2079 qla2x00_mark_device_lost(vha
, ea
->fcport
, 1);
2081 case MBS_LOOP_ID_USED
:
2082 /* data[1] = IO PARAM 1 = nport ID */
2083 cid
.b
.domain
= (ea
->iop
[1] >> 16) & 0xff;
2084 cid
.b
.area
= (ea
->iop
[1] >> 8) & 0xff;
2085 cid
.b
.al_pa
= ea
->iop
[1] & 0xff;
2088 ql_dbg(ql_dbg_disc
, vha
, 0x20ec,
2089 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2090 __func__
, __LINE__
, ea
->fcport
->port_name
,
2091 ea
->fcport
->loop_id
, cid
.b24
);
2093 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
2094 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
2095 qla24xx_post_gnl_work(vha
, ea
->fcport
);
2097 case MBS_PORT_ID_USED
:
2098 lid
= ea
->iop
[1] & 0xffff;
2099 qlt_find_sess_invalidate_other(vha
,
2100 wwn_to_u64(ea
->fcport
->port_name
),
2101 ea
->fcport
->d_id
, lid
, &conflict_fcport
);
2103 if (conflict_fcport
) {
2105 * Another fcport share the same loop_id/nport id.
2106 * Conflict fcport needs to finish cleanup before this
2107 * fcport can proceed to login.
2109 conflict_fcport
->conflict
= ea
->fcport
;
2110 ea
->fcport
->login_pause
= 1;
2112 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
2113 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2114 __func__
, __LINE__
, ea
->fcport
->port_name
,
2115 ea
->fcport
->d_id
.b24
, lid
);
2117 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
2118 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2119 __func__
, __LINE__
, ea
->fcport
->port_name
,
2120 ea
->fcport
->d_id
.b24
, lid
);
2122 qla2x00_clear_loop_id(ea
->fcport
);
2123 set_bit(lid
, vha
->hw
->loop_id_map
);
2124 ea
->fcport
->loop_id
= lid
;
2125 ea
->fcport
->keep_nport_handle
= 0;
2126 ea
->fcport
->logout_on_delete
= 1;
2127 qlt_schedule_sess_for_deletion(ea
->fcport
);
2134 /****************************************************************************/
2135 /* QLogic ISP2x00 Hardware Support Functions. */
2136 /****************************************************************************/
2139 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
2141 int rval
= QLA_SUCCESS
;
2142 struct qla_hw_data
*ha
= vha
->hw
;
2143 uint32_t idc_major_ver
, idc_minor_ver
;
2146 qla83xx_idc_lock(vha
, 0);
2148 /* SV: TODO: Assign initialization timeout from
2149 * flash-info / other param
2151 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
2152 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
2154 /* Set our fcoe function presence */
2155 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
2156 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
2157 "Error while setting DRV-Presence.\n");
2158 rval
= QLA_FUNCTION_FAILED
;
2162 /* Decide the reset ownership */
2163 qla83xx_reset_ownership(vha
);
2166 * On first protocol driver load:
2167 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2169 * Others: Check compatibility with current IDC Major version.
2171 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
2172 if (ha
->flags
.nic_core_reset_owner
) {
2173 /* Set IDC Major version */
2174 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
2175 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
2177 /* Clearing IDC-Lock-Recovery register */
2178 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
2179 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
2181 * Clear further IDC participation if we are not compatible with
2182 * the current IDC Major Version.
2184 ql_log(ql_log_warn
, vha
, 0xb07d,
2185 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2186 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
2187 __qla83xx_clear_drv_presence(vha
);
2188 rval
= QLA_FUNCTION_FAILED
;
2191 /* Each function sets its supported Minor version. */
2192 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
2193 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
2194 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
2196 if (ha
->flags
.nic_core_reset_owner
) {
2197 memset(config
, 0, sizeof(config
));
2198 if (!qla81xx_get_port_config(vha
, config
))
2199 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
2203 rval
= qla83xx_idc_state_handler(vha
);
2206 qla83xx_idc_unlock(vha
, 0);
2212 * qla2x00_initialize_adapter
2216 * ha = adapter block pointer.
2222 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
2225 struct qla_hw_data
*ha
= vha
->hw
;
2226 struct req_que
*req
= ha
->req_q_map
[0];
2227 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2229 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
2230 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
2232 /* Clear adapter flags. */
2233 vha
->flags
.online
= 0;
2234 ha
->flags
.chip_reset_done
= 0;
2235 vha
->flags
.reset_active
= 0;
2236 ha
->flags
.pci_channel_io_perm_failure
= 0;
2237 ha
->flags
.eeh_busy
= 0;
2238 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
2239 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
2240 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
2241 vha
->device_flags
= DFLG_NO_CABLE
;
2243 vha
->flags
.management_server_logged_in
= 0;
2244 vha
->marker_needed
= 0;
2245 ha
->isp_abort_cnt
= 0;
2246 ha
->beacon_blink_led
= 0;
2248 set_bit(0, ha
->req_qid_map
);
2249 set_bit(0, ha
->rsp_qid_map
);
2251 ql_dbg(ql_dbg_init
, vha
, 0x0040,
2252 "Configuring PCI space...\n");
2253 rval
= ha
->isp_ops
->pci_config(vha
);
2255 ql_log(ql_log_warn
, vha
, 0x0044,
2256 "Unable to configure PCI space.\n");
2260 ha
->isp_ops
->reset_chip(vha
);
2262 /* Check for secure flash support */
2263 if (IS_QLA28XX(ha
)) {
2264 if (rd_reg_word(®
->mailbox12
) & BIT_0
)
2265 ha
->flags
.secure_adapter
= 1;
2266 ql_log(ql_log_info
, vha
, 0xffff, "Secure Adapter: %s\n",
2267 (ha
->flags
.secure_adapter
) ? "Yes" : "No");
2271 rval
= qla2xxx_get_flash_info(vha
);
2273 ql_log(ql_log_fatal
, vha
, 0x004f,
2274 "Unable to validate FLASH data.\n");
2278 if (IS_QLA8044(ha
)) {
2279 qla8044_read_reset_template(vha
);
2281 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2282 * If DONRESET_BIT0 is set, drivers should not set dev_state
2283 * to NEED_RESET. But if NEED_RESET is set, drivers should
2284 * should honor the reset. */
2285 if (ql2xdontresethba
== 1)
2286 qla8044_set_idc_dontreset(vha
);
2289 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
2290 ql_dbg(ql_dbg_init
, vha
, 0x0061,
2291 "Configure NVRAM parameters...\n");
2293 /* Let priority default to FCP, can be overridden by nvram_config */
2294 ha
->fc4_type_priority
= FC4_PRIORITY_FCP
;
2296 ha
->isp_ops
->nvram_config(vha
);
2298 if (ha
->fc4_type_priority
!= FC4_PRIORITY_FCP
&&
2299 ha
->fc4_type_priority
!= FC4_PRIORITY_NVME
)
2300 ha
->fc4_type_priority
= FC4_PRIORITY_FCP
;
2302 ql_log(ql_log_info
, vha
, 0xffff, "FC4 priority set to %s\n",
2303 ha
->fc4_type_priority
== FC4_PRIORITY_FCP
? "FCP" : "NVMe");
2305 if (ha
->flags
.disable_serdes
) {
2306 /* Mask HBA via NVRAM settings? */
2307 ql_log(ql_log_info
, vha
, 0x0077,
2308 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
2309 return QLA_FUNCTION_FAILED
;
2312 ql_dbg(ql_dbg_init
, vha
, 0x0078,
2313 "Verifying loaded RISC code...\n");
2315 /* If smartsan enabled then require fdmi and rdp enabled */
2321 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
2322 rval
= ha
->isp_ops
->chip_diag(vha
);
2325 rval
= qla2x00_setup_chip(vha
);
2330 if (IS_QLA84XX(ha
)) {
2331 ha
->cs84xx
= qla84xx_get_chip(vha
);
2333 ql_log(ql_log_warn
, vha
, 0x00d0,
2334 "Unable to configure ISP84XX.\n");
2335 return QLA_FUNCTION_FAILED
;
2339 if (qla_ini_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
2340 rval
= qla2x00_init_rings(vha
);
2342 /* No point in continuing if firmware initialization failed. */
2343 if (rval
!= QLA_SUCCESS
)
2346 ha
->flags
.chip_reset_done
= 1;
2348 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
2349 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2350 rval
= qla84xx_init_chip(vha
);
2351 if (rval
!= QLA_SUCCESS
) {
2352 ql_log(ql_log_warn
, vha
, 0x00d4,
2353 "Unable to initialize ISP84XX.\n");
2354 qla84xx_put_chip(vha
);
2358 /* Load the NIC Core f/w if we are the first protocol driver. */
2359 if (IS_QLA8031(ha
)) {
2360 rval
= qla83xx_nic_core_fw_load(vha
);
2362 ql_log(ql_log_warn
, vha
, 0x0124,
2363 "Error in initializing NIC Core f/w.\n");
2366 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
2367 qla24xx_read_fcp_prio_cfg(vha
);
2369 if (IS_P3P_TYPE(ha
))
2370 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2372 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2378 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2381 * Returns 0 on success.
2384 qla2100_pci_config(scsi_qla_host_t
*vha
)
2387 unsigned long flags
;
2388 struct qla_hw_data
*ha
= vha
->hw
;
2389 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2391 pci_set_master(ha
->pdev
);
2392 pci_try_set_mwi(ha
->pdev
);
2394 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2395 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2396 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2398 pci_disable_rom(ha
->pdev
);
2400 /* Get PCI bus information. */
2401 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2402 ha
->pci_attr
= rd_reg_word(®
->ctrl_status
);
2403 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2409 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2412 * Returns 0 on success.
2415 qla2300_pci_config(scsi_qla_host_t
*vha
)
2418 unsigned long flags
= 0;
2420 struct qla_hw_data
*ha
= vha
->hw
;
2421 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2423 pci_set_master(ha
->pdev
);
2424 pci_try_set_mwi(ha
->pdev
);
2426 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2427 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2429 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2430 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2431 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2434 * If this is a 2300 card and not 2312, reset the
2435 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2436 * the 2310 also reports itself as a 2300 so we need to get the
2437 * fb revision level -- a 6 indicates it really is a 2300 and
2440 if (IS_QLA2300(ha
)) {
2441 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2444 wrt_reg_word(®
->hccr
, HCCR_PAUSE_RISC
);
2445 for (cnt
= 0; cnt
< 30000; cnt
++) {
2446 if ((rd_reg_word(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2452 /* Select FPM registers. */
2453 wrt_reg_word(®
->ctrl_status
, 0x20);
2454 rd_reg_word(®
->ctrl_status
);
2456 /* Get the fb rev level */
2457 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
2459 if (ha
->fb_rev
== FPM_2300
)
2460 pci_clear_mwi(ha
->pdev
);
2462 /* Deselect FPM registers. */
2463 wrt_reg_word(®
->ctrl_status
, 0x0);
2464 rd_reg_word(®
->ctrl_status
);
2466 /* Release RISC module. */
2467 wrt_reg_word(®
->hccr
, HCCR_RELEASE_RISC
);
2468 for (cnt
= 0; cnt
< 30000; cnt
++) {
2469 if ((rd_reg_word(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
2475 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2478 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2480 pci_disable_rom(ha
->pdev
);
2482 /* Get PCI bus information. */
2483 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2484 ha
->pci_attr
= rd_reg_word(®
->ctrl_status
);
2485 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2491 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2494 * Returns 0 on success.
2497 qla24xx_pci_config(scsi_qla_host_t
*vha
)
2500 unsigned long flags
= 0;
2501 struct qla_hw_data
*ha
= vha
->hw
;
2502 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2504 pci_set_master(ha
->pdev
);
2505 pci_try_set_mwi(ha
->pdev
);
2507 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2508 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2509 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2510 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2512 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2514 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2515 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
2516 pcix_set_mmrbc(ha
->pdev
, 2048);
2518 /* PCIe -- adjust Maximum Read Request Size (2048). */
2519 if (pci_is_pcie(ha
->pdev
))
2520 pcie_set_readrq(ha
->pdev
, 4096);
2522 pci_disable_rom(ha
->pdev
);
2524 ha
->chip_revision
= ha
->pdev
->revision
;
2526 /* Get PCI bus information. */
2527 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2528 ha
->pci_attr
= rd_reg_dword(®
->ctrl_status
);
2529 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2535 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2538 * Returns 0 on success.
2541 qla25xx_pci_config(scsi_qla_host_t
*vha
)
2544 struct qla_hw_data
*ha
= vha
->hw
;
2546 pci_set_master(ha
->pdev
);
2547 pci_try_set_mwi(ha
->pdev
);
2549 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2550 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2551 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2552 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2554 /* PCIe -- adjust Maximum Read Request Size (2048). */
2555 if (pci_is_pcie(ha
->pdev
))
2556 pcie_set_readrq(ha
->pdev
, 4096);
2558 pci_disable_rom(ha
->pdev
);
2560 ha
->chip_revision
= ha
->pdev
->revision
;
2566 * qla2x00_isp_firmware() - Choose firmware image.
2569 * Returns 0 on success.
2572 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
2575 uint16_t loop_id
, topo
, sw_cap
;
2576 uint8_t domain
, area
, al_pa
;
2577 struct qla_hw_data
*ha
= vha
->hw
;
2579 /* Assume loading risc code */
2580 rval
= QLA_FUNCTION_FAILED
;
2582 if (ha
->flags
.disable_risc_code_load
) {
2583 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
2585 /* Verify checksum of loaded RISC code. */
2586 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
2587 if (rval
== QLA_SUCCESS
) {
2588 /* And, verify we are not in ROM code. */
2589 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
2590 &area
, &domain
, &topo
, &sw_cap
);
2595 ql_dbg(ql_dbg_init
, vha
, 0x007a,
2596 "**** Load RISC code ****.\n");
2602 * qla2x00_reset_chip() - Reset ISP chip.
2605 * Returns 0 on success.
2608 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
2610 unsigned long flags
= 0;
2611 struct qla_hw_data
*ha
= vha
->hw
;
2612 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2615 int rval
= QLA_FUNCTION_FAILED
;
2617 if (unlikely(pci_channel_offline(ha
->pdev
)))
2620 ha
->isp_ops
->disable_intrs(ha
);
2622 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2624 /* Turn off master enable */
2626 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
2627 cmd
&= ~PCI_COMMAND_MASTER
;
2628 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2630 if (!IS_QLA2100(ha
)) {
2632 wrt_reg_word(®
->hccr
, HCCR_PAUSE_RISC
);
2633 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2634 for (cnt
= 0; cnt
< 30000; cnt
++) {
2635 if ((rd_reg_word(®
->hccr
) &
2636 HCCR_RISC_PAUSE
) != 0)
2641 rd_reg_word(®
->hccr
); /* PCI Posting. */
2645 /* Select FPM registers. */
2646 wrt_reg_word(®
->ctrl_status
, 0x20);
2647 rd_reg_word(®
->ctrl_status
); /* PCI Posting. */
2649 /* FPM Soft Reset. */
2650 wrt_reg_word(®
->fpm_diag_config
, 0x100);
2651 rd_reg_word(®
->fpm_diag_config
); /* PCI Posting. */
2653 /* Toggle Fpm Reset. */
2654 if (!IS_QLA2200(ha
)) {
2655 wrt_reg_word(®
->fpm_diag_config
, 0x0);
2656 rd_reg_word(®
->fpm_diag_config
); /* PCI Posting. */
2659 /* Select frame buffer registers. */
2660 wrt_reg_word(®
->ctrl_status
, 0x10);
2661 rd_reg_word(®
->ctrl_status
); /* PCI Posting. */
2663 /* Reset frame buffer FIFOs. */
2664 if (IS_QLA2200(ha
)) {
2665 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
2666 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
2668 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
2670 /* Read back fb_cmd until zero or 3 seconds max */
2671 for (cnt
= 0; cnt
< 3000; cnt
++) {
2672 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
2678 /* Select RISC module registers. */
2679 wrt_reg_word(®
->ctrl_status
, 0);
2680 rd_reg_word(®
->ctrl_status
); /* PCI Posting. */
2682 /* Reset RISC processor. */
2683 wrt_reg_word(®
->hccr
, HCCR_RESET_RISC
);
2684 rd_reg_word(®
->hccr
); /* PCI Posting. */
2686 /* Release RISC processor. */
2687 wrt_reg_word(®
->hccr
, HCCR_RELEASE_RISC
);
2688 rd_reg_word(®
->hccr
); /* PCI Posting. */
2691 wrt_reg_word(®
->hccr
, HCCR_CLR_RISC_INT
);
2692 wrt_reg_word(®
->hccr
, HCCR_CLR_HOST_INT
);
2694 /* Reset ISP chip. */
2695 wrt_reg_word(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2697 /* Wait for RISC to recover from reset. */
2698 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2700 * It is necessary to for a delay here since the card doesn't
2701 * respond to PCI reads during a reset. On some architectures
2702 * this will result in an MCA.
2705 for (cnt
= 30000; cnt
; cnt
--) {
2706 if ((rd_reg_word(®
->ctrl_status
) &
2707 CSR_ISP_SOFT_RESET
) == 0)
2714 /* Reset RISC processor. */
2715 wrt_reg_word(®
->hccr
, HCCR_RESET_RISC
);
2717 wrt_reg_word(®
->semaphore
, 0);
2719 /* Release RISC processor. */
2720 wrt_reg_word(®
->hccr
, HCCR_RELEASE_RISC
);
2721 rd_reg_word(®
->hccr
); /* PCI Posting. */
2723 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2724 for (cnt
= 0; cnt
< 30000; cnt
++) {
2725 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
2733 /* Turn on master enable */
2734 cmd
|= PCI_COMMAND_MASTER
;
2735 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2737 /* Disable RISC pause on FPM parity error. */
2738 if (!IS_QLA2100(ha
)) {
2739 wrt_reg_word(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
2740 rd_reg_word(®
->hccr
); /* PCI Posting. */
2743 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2749 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2752 * Returns 0 on success.
2755 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
2757 uint16_t mb
[4] = {0x1010, 0, 1, 0};
2759 if (!IS_QLA81XX(vha
->hw
))
2762 return qla81xx_write_mpi_register(vha
, mb
);
2766 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2769 * Returns 0 on success.
2772 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
2774 unsigned long flags
= 0;
2775 struct qla_hw_data
*ha
= vha
->hw
;
2776 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2779 static int abts_cnt
; /* ISP abort retry counts */
2780 int rval
= QLA_SUCCESS
;
2782 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2785 wrt_reg_dword(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2786 for (cnt
= 0; cnt
< 30000; cnt
++) {
2787 if ((rd_reg_dword(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
2793 if (!(rd_reg_dword(®
->ctrl_status
) & CSRX_DMA_ACTIVE
))
2794 set_bit(DMA_SHUTDOWN_CMPL
, &ha
->fw_dump_cap_flags
);
2796 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017e,
2797 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2798 rd_reg_dword(®
->hccr
),
2799 rd_reg_dword(®
->ctrl_status
),
2800 (rd_reg_dword(®
->ctrl_status
) & CSRX_DMA_ACTIVE
));
2802 wrt_reg_dword(®
->ctrl_status
,
2803 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2804 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2808 /* Wait for firmware to complete NVRAM accesses. */
2809 rd_reg_word(®
->mailbox0
);
2810 for (cnt
= 10000; rd_reg_word(®
->mailbox0
) != 0 &&
2811 rval
== QLA_SUCCESS
; cnt
--) {
2816 rval
= QLA_FUNCTION_TIMEOUT
;
2819 if (rval
== QLA_SUCCESS
)
2820 set_bit(ISP_MBX_RDY
, &ha
->fw_dump_cap_flags
);
2822 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017f,
2823 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2824 rd_reg_dword(®
->hccr
),
2825 rd_reg_word(®
->mailbox0
));
2827 /* Wait for soft-reset to complete. */
2828 rd_reg_dword(®
->ctrl_status
);
2829 for (cnt
= 0; cnt
< 60; cnt
++) {
2831 if ((rd_reg_dword(®
->ctrl_status
) &
2832 CSRX_ISP_SOFT_RESET
) == 0)
2837 if (!(rd_reg_dword(®
->ctrl_status
) & CSRX_ISP_SOFT_RESET
))
2838 set_bit(ISP_SOFT_RESET_CMPL
, &ha
->fw_dump_cap_flags
);
2840 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015d,
2841 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2842 rd_reg_dword(®
->hccr
),
2843 rd_reg_dword(®
->ctrl_status
));
2845 /* If required, do an MPI FW reset now */
2846 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
2847 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
2848 if (++abts_cnt
< 5) {
2849 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2850 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
2853 * We exhausted the ISP abort retries. We have to
2854 * set the board offline.
2857 vha
->flags
.online
= 0;
2862 wrt_reg_dword(®
->hccr
, HCCRX_SET_RISC_RESET
);
2863 rd_reg_dword(®
->hccr
);
2865 wrt_reg_dword(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
2866 rd_reg_dword(®
->hccr
);
2868 wrt_reg_dword(®
->hccr
, HCCRX_CLR_RISC_RESET
);
2869 rd_reg_dword(®
->hccr
);
2871 rd_reg_word(®
->mailbox0
);
2872 for (cnt
= 60; rd_reg_word(®
->mailbox0
) != 0 &&
2873 rval
== QLA_SUCCESS
; cnt
--) {
2878 rval
= QLA_FUNCTION_TIMEOUT
;
2880 if (rval
== QLA_SUCCESS
)
2881 set_bit(RISC_RDY_AFT_RESET
, &ha
->fw_dump_cap_flags
);
2883 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015e,
2884 "Host Risc 0x%x, mailbox0 0x%x\n",
2885 rd_reg_dword(®
->hccr
),
2886 rd_reg_word(®
->mailbox0
));
2888 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2890 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015f,
2891 "Driver in %s mode\n",
2892 IS_NOPOLLING_TYPE(ha
) ? "Interrupt" : "Polling");
2894 if (IS_NOPOLLING_TYPE(ha
))
2895 ha
->isp_ops
->enable_intrs(ha
);
2901 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
2903 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2905 wrt_reg_dword(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2906 *data
= rd_reg_dword(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFSET
);
2910 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
2912 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2914 wrt_reg_dword(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2915 wrt_reg_dword(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFSET
, data
);
2919 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
2922 uint delta_msec
= 100;
2923 uint elapsed_msec
= 0;
2927 if (vha
->hw
->pdev
->subsystem_device
!= 0x0175 &&
2928 vha
->hw
->pdev
->subsystem_device
!= 0x0240)
2931 wrt_reg_dword(&vha
->hw
->iobase
->isp24
.hccr
, HCCRX_SET_RISC_PAUSE
);
2935 timeout_msec
= TIMEOUT_SEMAPHORE
;
2936 n
= timeout_msec
/ delta_msec
;
2938 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
2939 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2940 if (wd32
& RISC_SEMAPHORE
)
2943 elapsed_msec
+= delta_msec
;
2944 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2948 if (!(wd32
& RISC_SEMAPHORE
))
2951 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2954 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
2955 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
2956 n
= timeout_msec
/ delta_msec
;
2958 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2959 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2962 elapsed_msec
+= delta_msec
;
2963 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2967 if (wd32
& RISC_SEMAPHORE_FORCE
)
2968 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
2973 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
2980 * qla24xx_reset_chip() - Reset ISP24xx chip.
2983 * Returns 0 on success.
2986 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
2988 struct qla_hw_data
*ha
= vha
->hw
;
2989 int rval
= QLA_FUNCTION_FAILED
;
2991 if (pci_channel_offline(ha
->pdev
) &&
2992 ha
->flags
.pci_channel_io_perm_failure
) {
2996 ha
->isp_ops
->disable_intrs(ha
);
2998 qla25xx_manipulate_risc_semaphore(vha
);
3000 /* Perform RISC reset. */
3001 rval
= qla24xx_reset_risc(vha
);
3007 * qla2x00_chip_diag() - Test chip for proper operation.
3010 * Returns 0 on success.
3013 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
3016 struct qla_hw_data
*ha
= vha
->hw
;
3017 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3018 unsigned long flags
= 0;
3022 struct req_que
*req
= ha
->req_q_map
[0];
3024 /* Assume a failed state */
3025 rval
= QLA_FUNCTION_FAILED
;
3027 ql_dbg(ql_dbg_init
, vha
, 0x007b, "Testing device at %p.\n",
3028 ®
->flash_address
);
3030 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3032 /* Reset ISP chip. */
3033 wrt_reg_word(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
3036 * We need to have a delay here since the card will not respond while
3037 * in reset causing an MCA on some architectures.
3040 data
= qla2x00_debounce_register(®
->ctrl_status
);
3041 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
3043 data
= rd_reg_word(®
->ctrl_status
);
3048 goto chip_diag_failed
;
3050 ql_dbg(ql_dbg_init
, vha
, 0x007c,
3051 "Reset register cleared by chip reset.\n");
3053 /* Reset RISC processor. */
3054 wrt_reg_word(®
->hccr
, HCCR_RESET_RISC
);
3055 wrt_reg_word(®
->hccr
, HCCR_RELEASE_RISC
);
3057 /* Workaround for QLA2312 PCI parity error */
3058 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
3059 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
3060 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
3062 data
= RD_MAILBOX_REG(ha
, reg
, 0);
3069 goto chip_diag_failed
;
3071 /* Check product ID of chip */
3072 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product ID of chip.\n");
3074 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
3075 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
3076 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
3077 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
3078 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
3079 mb
[3] != PROD_ID_3
) {
3080 ql_log(ql_log_warn
, vha
, 0x0062,
3081 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3082 mb
[1], mb
[2], mb
[3]);
3084 goto chip_diag_failed
;
3086 ha
->product_id
[0] = mb
[1];
3087 ha
->product_id
[1] = mb
[2];
3088 ha
->product_id
[2] = mb
[3];
3089 ha
->product_id
[3] = mb
[4];
3091 /* Adjust fw RISC transfer size */
3092 if (req
->length
> 1024)
3093 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
3095 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
3098 if (IS_QLA2200(ha
) &&
3099 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
3100 /* Limit firmware transfer size with a 2200A */
3101 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
3103 ha
->device_type
|= DT_ISP2200A
;
3104 ha
->fw_transfer_size
= 128;
3107 /* Wrap Incoming Mailboxes Test. */
3108 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3110 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
3111 rval
= qla2x00_mbx_reg_test(vha
);
3113 ql_log(ql_log_warn
, vha
, 0x0080,
3114 "Failed mailbox send register test.\n");
3116 /* Flag a successful rval */
3118 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3122 ql_log(ql_log_info
, vha
, 0x0081,
3123 "Chip diagnostics **** FAILED ****.\n");
3125 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3131 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3134 * Returns 0 on success.
3137 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
3140 struct qla_hw_data
*ha
= vha
->hw
;
3141 struct req_que
*req
= ha
->req_q_map
[0];
3143 if (IS_P3P_TYPE(ha
))
3146 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
3148 rval
= qla2x00_mbx_reg_test(vha
);
3150 ql_log(ql_log_warn
, vha
, 0x0082,
3151 "Failed mailbox send register test.\n");
3153 /* Flag a successful rval */
3161 qla2x00_init_fce_trace(scsi_qla_host_t
*vha
)
3166 struct qla_hw_data
*ha
= vha
->hw
;
3168 if (!IS_FWI2_CAPABLE(ha
))
3171 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
3172 !IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
3176 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
3177 "%s: FCE Mem is already allocated.\n",
3182 /* Allocate memory for Fibre Channel Event Buffer. */
3183 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
3186 ql_log(ql_log_warn
, vha
, 0x00be,
3187 "Unable to allocate (%d KB) for FCE.\n",
3192 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
3193 ha
->fce_mb
, &ha
->fce_bufs
);
3195 ql_log(ql_log_warn
, vha
, 0x00bf,
3196 "Unable to initialize FCE (%d).\n", rval
);
3197 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
, tc_dma
);
3201 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
3202 "Allocated (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
3204 ha
->flags
.fce_enabled
= 1;
3205 ha
->fce_dma
= tc_dma
;
3210 qla2x00_init_eft_trace(scsi_qla_host_t
*vha
)
3215 struct qla_hw_data
*ha
= vha
->hw
;
3217 if (!IS_FWI2_CAPABLE(ha
))
3221 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
3222 "%s: EFT Mem is already allocated.\n",
3227 /* Allocate memory for Extended Trace Buffer. */
3228 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
3231 ql_log(ql_log_warn
, vha
, 0x00c1,
3232 "Unable to allocate (%d KB) for EFT.\n",
3237 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
3239 ql_log(ql_log_warn
, vha
, 0x00c2,
3240 "Unable to initialize EFT (%d).\n", rval
);
3241 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
, tc_dma
);
3245 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
3246 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
3248 ha
->eft_dma
= tc_dma
;
3253 qla2x00_alloc_offload_mem(scsi_qla_host_t
*vha
)
3255 qla2x00_init_fce_trace(vha
);
3256 qla2x00_init_eft_trace(vha
);
3260 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
3262 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
3263 eft_size
, fce_size
, mq_size
;
3264 struct qla_hw_data
*ha
= vha
->hw
;
3265 struct req_que
*req
= ha
->req_q_map
[0];
3266 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3267 struct qla2xxx_fw_dump
*fw_dump
;
3269 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
3270 req_q_size
= rsp_q_size
= 0;
3272 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3273 fixed_size
= sizeof(struct qla2100_fw_dump
);
3274 } else if (IS_QLA23XX(ha
)) {
3275 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
3276 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
3278 } else if (IS_FWI2_CAPABLE(ha
)) {
3279 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
))
3280 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
3281 else if (IS_QLA81XX(ha
))
3282 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
3283 else if (IS_QLA25XX(ha
))
3284 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
3286 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
3288 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
3291 if (!IS_QLA83XX(ha
) && !IS_QLA27XX(ha
) &&
3293 mq_size
= sizeof(struct qla2xxx_mq_chain
);
3295 * Allocate maximum buffer size for all queues - Q0.
3296 * Resizing must be done at end-of-dump processing.
3298 mq_size
+= (ha
->max_req_queues
- 1) *
3299 (req
->length
* sizeof(request_t
));
3300 mq_size
+= (ha
->max_rsp_queues
- 1) *
3301 (rsp
->length
* sizeof(response_t
));
3303 if (ha
->tgt
.atio_ring
)
3304 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
3306 qla2x00_init_fce_trace(vha
);
3308 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
3309 qla2x00_init_eft_trace(vha
);
3311 eft_size
= EFT_SIZE
;
3314 if (IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
3315 struct fwdt
*fwdt
= ha
->fwdt
;
3318 for (j
= 0; j
< 2; j
++, fwdt
++) {
3319 if (!fwdt
->template) {
3320 ql_dbg(ql_dbg_init
, vha
, 0x00ba,
3321 "-> fwdt%u no template\n", j
);
3324 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
3325 "-> fwdt%u calculating fwdump size...\n", j
);
3326 fwdt
->dump_size
= qla27xx_fwdt_calculate_dump_size(
3327 vha
, fwdt
->template);
3328 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
3329 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3330 j
, fwdt
->dump_size
);
3331 dump_size
+= fwdt
->dump_size
;
3333 /* Add space for spare MPI fw dump. */
3334 dump_size
+= ha
->fwdt
[1].dump_size
;
3336 req_q_size
= req
->length
* sizeof(request_t
);
3337 rsp_q_size
= rsp
->length
* sizeof(response_t
);
3338 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
3339 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
3341 ha
->chain_offset
= dump_size
;
3342 dump_size
+= mq_size
+ fce_size
;
3343 if (ha
->exchoffld_buf
)
3344 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3346 if (ha
->exlogin_buf
)
3347 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3351 if (!ha
->fw_dump_len
|| dump_size
> ha
->fw_dump_alloc_len
) {
3353 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3354 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3355 __func__
, dump_size
, ha
->fw_dump_len
,
3356 ha
->fw_dump_alloc_len
);
3358 fw_dump
= vmalloc(dump_size
);
3360 ql_log(ql_log_warn
, vha
, 0x00c4,
3361 "Unable to allocate (%d KB) for firmware dump.\n",
3364 mutex_lock(&ha
->optrom_mutex
);
3365 if (ha
->fw_dumped
) {
3366 memcpy(fw_dump
, ha
->fw_dump
, ha
->fw_dump_len
);
3368 ha
->fw_dump
= fw_dump
;
3369 ha
->fw_dump_alloc_len
= dump_size
;
3370 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3371 "Re-Allocated (%d KB) and save firmware dump.\n",
3376 ha
->fw_dump
= fw_dump
;
3378 ha
->fw_dump_len
= ha
->fw_dump_alloc_len
=
3380 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3381 "Allocated (%d KB) for firmware dump.\n",
3384 if (IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
3385 ha
->mpi_fw_dump
= (char *)fw_dump
+
3386 ha
->fwdt
[1].dump_size
;
3387 mutex_unlock(&ha
->optrom_mutex
);
3391 ha
->fw_dump
->signature
[0] = 'Q';
3392 ha
->fw_dump
->signature
[1] = 'L';
3393 ha
->fw_dump
->signature
[2] = 'G';
3394 ha
->fw_dump
->signature
[3] = 'C';
3395 ha
->fw_dump
->version
= htonl(1);
3397 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
3398 ha
->fw_dump
->mem_size
= htonl(mem_size
);
3399 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
3400 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
3402 ha
->fw_dump
->eft_size
= htonl(eft_size
);
3403 ha
->fw_dump
->eft_addr_l
=
3404 htonl(LSD(ha
->eft_dma
));
3405 ha
->fw_dump
->eft_addr_h
=
3406 htonl(MSD(ha
->eft_dma
));
3408 ha
->fw_dump
->header_size
=
3410 (struct qla2xxx_fw_dump
, isp
));
3412 mutex_unlock(&ha
->optrom_mutex
);
3418 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
3420 #define MPS_MASK 0xe0
3425 if (!IS_QLA81XX(vha
->hw
))
3428 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
3429 if (rval
!= QLA_SUCCESS
) {
3430 ql_log(ql_log_warn
, vha
, 0x0105,
3431 "Unable to acquire semaphore.\n");
3435 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
3436 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
3437 if (rval
!= QLA_SUCCESS
) {
3438 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
3443 if (dc
== (dw
& MPS_MASK
))
3448 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
3449 if (rval
!= QLA_SUCCESS
) {
3450 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
3454 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
3455 if (rval
!= QLA_SUCCESS
) {
3456 ql_log(ql_log_warn
, vha
, 0x006d,
3457 "Unable to release semaphore.\n");
3465 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
3467 /* Don't try to reallocate the array */
3468 if (req
->outstanding_cmds
)
3471 if (!IS_FWI2_CAPABLE(ha
))
3472 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
3474 if (ha
->cur_fw_xcb_count
<= ha
->cur_fw_iocb_count
)
3475 req
->num_outstanding_cmds
= ha
->cur_fw_xcb_count
;
3477 req
->num_outstanding_cmds
= ha
->cur_fw_iocb_count
;
3480 req
->outstanding_cmds
= kcalloc(req
->num_outstanding_cmds
,
3484 if (!req
->outstanding_cmds
) {
3486 * Try to allocate a minimal size just so we can get through
3489 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
3490 req
->outstanding_cmds
= kcalloc(req
->num_outstanding_cmds
,
3494 if (!req
->outstanding_cmds
) {
3495 ql_log(ql_log_fatal
, NULL
, 0x0126,
3496 "Failed to allocate memory for "
3497 "outstanding_cmds for req_que %p.\n", req
);
3498 req
->num_outstanding_cmds
= 0;
3499 return QLA_FUNCTION_FAILED
;
3506 #define PRINT_FIELD(_field, _flag, _str) { \
3507 if (a0->_field & _flag) {\
3513 len = snprintf(ptr, leftover, "%s", _str); \
3520 static void qla2xxx_print_sfp_info(struct scsi_qla_host
*vha
)
3523 struct sff_8247_a0
*a0
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3524 u8 str
[STR_LEN
], *ptr
, p
;
3527 memset(str
, 0, STR_LEN
);
3528 snprintf(str
, SFF_VEN_NAME_LEN
+1, a0
->vendor_name
);
3529 ql_dbg(ql_dbg_init
, vha
, 0x015a,
3530 "SFP MFG Name: %s\n", str
);
3532 memset(str
, 0, STR_LEN
);
3533 snprintf(str
, SFF_PART_NAME_LEN
+1, a0
->vendor_pn
);
3534 ql_dbg(ql_dbg_init
, vha
, 0x015c,
3535 "SFP Part Name: %s\n", str
);
3538 memset(str
, 0, STR_LEN
);
3542 PRINT_FIELD(fc_med_cc9
, FC_MED_TW
, "Twin AX");
3543 PRINT_FIELD(fc_med_cc9
, FC_MED_TP
, "Twisted Pair");
3544 PRINT_FIELD(fc_med_cc9
, FC_MED_MI
, "Min Coax");
3545 PRINT_FIELD(fc_med_cc9
, FC_MED_TV
, "Video Coax");
3546 PRINT_FIELD(fc_med_cc9
, FC_MED_M6
, "MultiMode 62.5um");
3547 PRINT_FIELD(fc_med_cc9
, FC_MED_M5
, "MultiMode 50um");
3548 PRINT_FIELD(fc_med_cc9
, FC_MED_SM
, "SingleMode");
3549 ql_dbg(ql_dbg_init
, vha
, 0x0160,
3550 "SFP Media: %s\n", str
);
3553 memset(str
, 0, STR_LEN
);
3557 PRINT_FIELD(fc_ll_cc7
, FC_LL_VL
, "Very Long");
3558 PRINT_FIELD(fc_ll_cc7
, FC_LL_S
, "Short");
3559 PRINT_FIELD(fc_ll_cc7
, FC_LL_I
, "Intermediate");
3560 PRINT_FIELD(fc_ll_cc7
, FC_LL_L
, "Long");
3561 PRINT_FIELD(fc_ll_cc7
, FC_LL_M
, "Medium");
3562 ql_dbg(ql_dbg_init
, vha
, 0x0196,
3563 "SFP Link Length: %s\n", str
);
3565 memset(str
, 0, STR_LEN
);
3569 PRINT_FIELD(fc_ll_cc7
, FC_LL_SA
, "Short Wave (SA)");
3570 PRINT_FIELD(fc_ll_cc7
, FC_LL_LC
, "Long Wave(LC)");
3571 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SN
, "Short Wave (SN)");
3572 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SL
, "Short Wave (SL)");
3573 PRINT_FIELD(fc_tec_cc8
, FC_TEC_LL
, "Long Wave (LL)");
3574 ql_dbg(ql_dbg_init
, vha
, 0x016e,
3575 "SFP FC Link Tech: %s\n", str
);
3578 ql_dbg(ql_dbg_init
, vha
, 0x016f,
3579 "SFP Distant: %d km\n", a0
->length_km
);
3580 if (a0
->length_100m
)
3581 ql_dbg(ql_dbg_init
, vha
, 0x0170,
3582 "SFP Distant: %d m\n", a0
->length_100m
*100);
3583 if (a0
->length_50um_10m
)
3584 ql_dbg(ql_dbg_init
, vha
, 0x0189,
3585 "SFP Distant (WL=50um): %d m\n", a0
->length_50um_10m
* 10);
3586 if (a0
->length_62um_10m
)
3587 ql_dbg(ql_dbg_init
, vha
, 0x018a,
3588 "SFP Distant (WL=62.5um): %d m\n", a0
->length_62um_10m
* 10);
3589 if (a0
->length_om4_10m
)
3590 ql_dbg(ql_dbg_init
, vha
, 0x0194,
3591 "SFP Distant (OM4): %d m\n", a0
->length_om4_10m
* 10);
3592 if (a0
->length_om3_10m
)
3593 ql_dbg(ql_dbg_init
, vha
, 0x0195,
3594 "SFP Distant (OM3): %d m\n", a0
->length_om3_10m
* 10);
3599 * qla24xx_detect_sfp()
3601 * @vha: adapter state pointer.
3604 * 0 -- Configure firmware to use short-range settings -- normal
3605 * buffer-to-buffer credits.
3607 * 1 -- Configure firmware to use long-range settings -- extra
3608 * buffer-to-buffer credits should be allocated with
3609 * ha->lr_distance containing distance settings from NVRAM or SFP
3613 qla24xx_detect_sfp(scsi_qla_host_t
*vha
)
3616 struct sff_8247_a0
*a
;
3617 struct qla_hw_data
*ha
= vha
->hw
;
3618 struct nvram_81xx
*nv
= ha
->nvram
;
3619 #define LR_DISTANCE_UNKNOWN 2
3620 static const char * const types
[] = { "Short", "Long" };
3621 static const char * const lengths
[] = { "(10km)", "(5km)", "" };
3624 /* Seed with NVRAM settings. */
3626 ha
->flags
.lr_detected
= 0;
3627 if (IS_BPM_RANGE_CAPABLE(ha
) &&
3628 (nv
->enhanced_features
& NEF_LR_DIST_ENABLE
)) {
3630 ha
->flags
.lr_detected
= 1;
3632 (nv
->enhanced_features
>> LR_DIST_NV_POS
)
3636 if (!IS_BPM_ENABLED(vha
))
3638 /* Determine SR/LR capabilities of SFP/Transceiver. */
3639 rc
= qla2x00_read_sfp_dev(vha
, NULL
, 0);
3644 a
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3645 qla2xxx_print_sfp_info(vha
);
3647 ha
->flags
.lr_detected
= 0;
3649 if (ll
& FC_LL_VL
|| ll
& FC_LL_L
) {
3650 /* Long range, track length. */
3651 ha
->flags
.lr_detected
= 1;
3653 if (a
->length_km
> 5 || a
->length_100m
> 50)
3654 ha
->lr_distance
= LR_DISTANCE_10K
;
3656 ha
->lr_distance
= LR_DISTANCE_5K
;
3660 ql_dbg(ql_dbg_async
, vha
, 0x507b,
3661 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
3662 types
[ha
->flags
.lr_detected
],
3663 ha
->flags
.lr_detected
? lengths
[ha
->lr_distance
] :
3664 lengths
[LR_DISTANCE_UNKNOWN
],
3665 used_nvram
, ll
, ha
->flags
.lr_detected
, ha
->lr_distance
);
3666 return ha
->flags
.lr_detected
;
3669 void qla_init_iocb_limit(scsi_qla_host_t
*vha
)
3673 struct qla_hw_data
*ha
= vha
->hw
;
3675 num_qps
= ha
->num_qpairs
+ 1;
3676 limit
= (ha
->orig_fw_iocb_count
* QLA_IOCB_PCT_LIMIT
) / 100;
3678 ha
->base_qpair
->fwres
.iocbs_total
= ha
->orig_fw_iocb_count
;
3679 ha
->base_qpair
->fwres
.iocbs_limit
= limit
;
3680 ha
->base_qpair
->fwres
.iocbs_qp_limit
= limit
/ num_qps
;
3681 ha
->base_qpair
->fwres
.iocbs_used
= 0;
3682 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
3683 if (ha
->queue_pair_map
[i
]) {
3684 ha
->queue_pair_map
[i
]->fwres
.iocbs_total
=
3685 ha
->orig_fw_iocb_count
;
3686 ha
->queue_pair_map
[i
]->fwres
.iocbs_limit
= limit
;
3687 ha
->queue_pair_map
[i
]->fwres
.iocbs_qp_limit
=
3689 ha
->queue_pair_map
[i
]->fwres
.iocbs_used
= 0;
3695 * qla2x00_setup_chip() - Load and start RISC firmware.
3698 * Returns 0 on success.
3701 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
3704 uint32_t srisc_address
= 0;
3705 struct qla_hw_data
*ha
= vha
->hw
;
3706 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3707 unsigned long flags
;
3708 uint16_t fw_major_version
;
3711 if (IS_P3P_TYPE(ha
)) {
3712 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3713 if (rval
== QLA_SUCCESS
) {
3714 qla2x00_stop_firmware(vha
);
3715 goto enable_82xx_npiv
;
3720 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3721 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3722 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3723 wrt_reg_word(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3724 rd_reg_word(®
->hccr
);
3725 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3728 qla81xx_mpi_sync(vha
);
3731 /* Load firmware sequences */
3732 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3733 if (rval
== QLA_SUCCESS
) {
3734 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
3735 "Verifying Checksum of loaded RISC code.\n");
3737 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
3738 if (rval
== QLA_SUCCESS
) {
3739 /* Start firmware execution. */
3740 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3741 "Starting firmware.\n");
3744 ha
->flags
.exlogins_enabled
= 1;
3746 if (qla_is_exch_offld_enabled(vha
))
3747 ha
->flags
.exchoffld_enabled
= 1;
3749 rval
= qla2x00_execute_fw(vha
, srisc_address
);
3750 /* Retrieve firmware information. */
3751 if (rval
== QLA_SUCCESS
) {
3752 /* Enable BPM support? */
3753 if (!done_once
++ && qla24xx_detect_sfp(vha
)) {
3754 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3755 "Re-starting firmware -- BPM.\n");
3756 /* Best-effort - re-init. */
3757 ha
->isp_ops
->reset_chip(vha
);
3758 ha
->isp_ops
->chip_diag(vha
);
3759 goto execute_fw_with_lr
;
3762 if (IS_ZIO_THRESHOLD_CAPABLE(ha
))
3763 qla27xx_set_zio_threshold(vha
,
3764 ha
->last_zio_threshold
);
3766 rval
= qla2x00_set_exlogins_buffer(vha
);
3767 if (rval
!= QLA_SUCCESS
)
3770 rval
= qla2x00_set_exchoffld_buffer(vha
);
3771 if (rval
!= QLA_SUCCESS
)
3775 fw_major_version
= ha
->fw_major_version
;
3776 if (IS_P3P_TYPE(ha
))
3777 qla82xx_check_md_needed(vha
);
3779 rval
= qla2x00_get_fw_version(vha
);
3780 if (rval
!= QLA_SUCCESS
)
3782 ha
->flags
.npiv_supported
= 0;
3783 if (IS_QLA2XXX_MIDTYPE(ha
) &&
3784 (ha
->fw_attributes
& BIT_2
)) {
3785 ha
->flags
.npiv_supported
= 1;
3786 if ((!ha
->max_npiv_vports
) ||
3787 ((ha
->max_npiv_vports
+ 1) %
3788 MIN_MULTI_ID_FABRIC
))
3789 ha
->max_npiv_vports
=
3790 MIN_MULTI_ID_FABRIC
- 1;
3792 qla2x00_get_resource_cnts(vha
);
3793 qla_init_iocb_limit(vha
);
3796 * Allocate the array of outstanding commands
3797 * now that we know the firmware resources.
3799 rval
= qla2x00_alloc_outstanding_cmds(ha
,
3801 if (rval
!= QLA_SUCCESS
)
3804 if (!fw_major_version
&& !(IS_P3P_TYPE(ha
)))
3805 qla2x00_alloc_offload_mem(vha
);
3807 if (ql2xallocfwdump
&& !(IS_P3P_TYPE(ha
)))
3808 qla2x00_alloc_fw_dump(vha
);
3814 ql_log(ql_log_fatal
, vha
, 0x00cd,
3815 "ISP Firmware failed checksum.\n");
3819 /* Enable PUREX PASSTHRU */
3820 if (ql2xrdpenable
|| ha
->flags
.scm_supported_f
)
3821 qla25xx_set_els_cmds_supported(vha
);
3825 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3826 /* Enable proper parity. */
3827 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3830 wrt_reg_word(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
3832 /* SRAM, Instruction RAM and GP RAM parity */
3833 wrt_reg_word(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
3834 rd_reg_word(®
->hccr
);
3835 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3838 if (IS_QLA27XX(ha
) || IS_QLA28XX(ha
))
3839 ha
->flags
.fac_supported
= 1;
3840 else if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
3843 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
3844 if (rval
== QLA_SUCCESS
) {
3845 ha
->flags
.fac_supported
= 1;
3846 ha
->fdt_block_size
= size
<< 2;
3848 ql_log(ql_log_warn
, vha
, 0x00ce,
3849 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3850 ha
->fw_major_version
, ha
->fw_minor_version
,
3851 ha
->fw_subminor_version
);
3853 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) ||
3855 ha
->flags
.fac_supported
= 0;
3862 ql_log(ql_log_fatal
, vha
, 0x00cf,
3863 "Setup chip ****FAILED****.\n");
3870 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3871 * @rsp: response queue
3873 * Beginning of request ring has initialization control block already built
3874 * by nvram config routine.
3876 * Returns 0 on success.
3879 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
3884 rsp
->ring_ptr
= rsp
->ring
;
3885 rsp
->ring_index
= 0;
3886 rsp
->status_srb
= NULL
;
3887 pkt
= rsp
->ring_ptr
;
3888 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
3889 pkt
->signature
= RESPONSE_PROCESSED
;
3895 * qla2x00_update_fw_options() - Read and process firmware options.
3898 * Returns 0 on success.
3901 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
3903 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
3904 struct qla_hw_data
*ha
= vha
->hw
;
3906 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
3907 qla2x00_get_fw_options(vha
, ha
->fw_options
);
3909 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3912 /* Serial Link options. */
3913 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
3914 "Serial link options.\n");
3915 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
3916 ha
->fw_seriallink_options
, sizeof(ha
->fw_seriallink_options
));
3918 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
3919 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
3920 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
3923 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
3924 emphasis
= (ha
->fw_seriallink_options
[2] &
3925 (BIT_4
| BIT_3
)) >> 3;
3926 tx_sens
= ha
->fw_seriallink_options
[0] &
3927 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3928 rx_sens
= (ha
->fw_seriallink_options
[0] &
3929 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3930 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
3931 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3934 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
3935 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3936 ha
->fw_options
[10] |= BIT_5
|
3937 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3938 (tx_sens
& (BIT_1
| BIT_0
));
3941 swing
= (ha
->fw_seriallink_options
[2] &
3942 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
3943 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
3944 tx_sens
= ha
->fw_seriallink_options
[1] &
3945 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3946 rx_sens
= (ha
->fw_seriallink_options
[1] &
3947 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3948 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
3949 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3952 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
3953 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3954 ha
->fw_options
[11] |= BIT_5
|
3955 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3956 (tx_sens
& (BIT_1
| BIT_0
));
3960 /* Return command IOCBs without waiting for an ABTS to complete. */
3961 ha
->fw_options
[3] |= BIT_13
;
3964 if (ha
->flags
.enable_led_scheme
)
3965 ha
->fw_options
[2] |= BIT_12
;
3967 /* Detect ISP6312. */
3969 ha
->fw_options
[2] |= BIT_13
;
3971 /* Set Retry FLOGI in case of P2P connection */
3972 if (ha
->operating_mode
== P2P
) {
3973 ha
->fw_options
[2] |= BIT_3
;
3974 ql_dbg(ql_dbg_disc
, vha
, 0x2100,
3975 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3976 __func__
, ha
->fw_options
[2]);
3979 /* Update firmware options. */
3980 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3984 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
3987 struct qla_hw_data
*ha
= vha
->hw
;
3989 if (IS_P3P_TYPE(ha
))
3992 /* Hold status IOCBs until ABTS response received. */
3994 ha
->fw_options
[3] |= BIT_12
;
3996 /* Set Retry FLOGI in case of P2P connection */
3997 if (ha
->operating_mode
== P2P
) {
3998 ha
->fw_options
[2] |= BIT_3
;
3999 ql_dbg(ql_dbg_disc
, vha
, 0x2101,
4000 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
4001 __func__
, ha
->fw_options
[2]);
4004 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
4005 if (ql2xmvasynctoatio
&&
4006 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
))) {
4007 if (qla_tgt_mode_enabled(vha
) ||
4008 qla_dual_mode_enabled(vha
))
4009 ha
->fw_options
[2] |= BIT_11
;
4011 ha
->fw_options
[2] &= ~BIT_11
;
4014 if (IS_QLA25XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
) ||
4017 * Tell FW to track each exchange to prevent
4018 * driver from using stale exchange.
4020 if (qla_tgt_mode_enabled(vha
) ||
4021 qla_dual_mode_enabled(vha
))
4022 ha
->fw_options
[2] |= BIT_4
;
4024 ha
->fw_options
[2] &= ~BIT_4
;
4026 /* Reserve 1/2 of emergency exchanges for ELS.*/
4027 if (qla2xuseresexchforels
)
4028 ha
->fw_options
[2] |= BIT_8
;
4030 ha
->fw_options
[2] &= ~BIT_8
;
4033 if (ql2xrdpenable
|| ha
->flags
.scm_supported_f
)
4034 ha
->fw_options
[1] |= ADD_FO1_ENABLE_PUREX_IOCB
;
4036 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
4037 if (IS_BPM_RANGE_CAPABLE(ha
))
4038 ha
->fw_options
[3] |= BIT_10
;
4040 ql_dbg(ql_dbg_init
, vha
, 0x00e8,
4041 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
4042 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
4043 ha
->fw_options
[3], vha
->host
->active_mode
);
4045 if (ha
->fw_options
[1] || ha
->fw_options
[2] || ha
->fw_options
[3])
4046 qla2x00_set_fw_options(vha
, ha
->fw_options
);
4048 /* Update Serial Link options. */
4049 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
4052 rval
= qla2x00_set_serdes_params(vha
,
4053 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
4054 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
4055 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
4056 if (rval
!= QLA_SUCCESS
) {
4057 ql_log(ql_log_warn
, vha
, 0x0104,
4058 "Unable to update Serial Link options (%x).\n", rval
);
4063 qla2x00_config_rings(struct scsi_qla_host
*vha
)
4065 struct qla_hw_data
*ha
= vha
->hw
;
4066 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4067 struct req_que
*req
= ha
->req_q_map
[0];
4068 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4070 /* Setup ring parameters in initialization control block. */
4071 ha
->init_cb
->request_q_outpointer
= cpu_to_le16(0);
4072 ha
->init_cb
->response_q_inpointer
= cpu_to_le16(0);
4073 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
4074 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
4075 put_unaligned_le64(req
->dma
, &ha
->init_cb
->request_q_address
);
4076 put_unaligned_le64(rsp
->dma
, &ha
->init_cb
->response_q_address
);
4078 wrt_reg_word(ISP_REQ_Q_IN(ha
, reg
), 0);
4079 wrt_reg_word(ISP_REQ_Q_OUT(ha
, reg
), 0);
4080 wrt_reg_word(ISP_RSP_Q_IN(ha
, reg
), 0);
4081 wrt_reg_word(ISP_RSP_Q_OUT(ha
, reg
), 0);
4082 rd_reg_word(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
4086 qla24xx_config_rings(struct scsi_qla_host
*vha
)
4088 struct qla_hw_data
*ha
= vha
->hw
;
4089 device_reg_t
*reg
= ISP_QUE_REG(ha
, 0);
4090 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
4091 struct qla_msix_entry
*msix
;
4092 struct init_cb_24xx
*icb
;
4094 struct req_que
*req
= ha
->req_q_map
[0];
4095 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4097 /* Setup ring parameters in initialization control block. */
4098 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4099 icb
->request_q_outpointer
= cpu_to_le16(0);
4100 icb
->response_q_inpointer
= cpu_to_le16(0);
4101 icb
->request_q_length
= cpu_to_le16(req
->length
);
4102 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
4103 put_unaligned_le64(req
->dma
, &icb
->request_q_address
);
4104 put_unaligned_le64(rsp
->dma
, &icb
->response_q_address
);
4106 /* Setup ATIO queue dma pointers for target mode */
4107 icb
->atio_q_inpointer
= cpu_to_le16(0);
4108 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
4109 put_unaligned_le64(ha
->tgt
.atio_dma
, &icb
->atio_q_address
);
4111 if (IS_SHADOW_REG_CAPABLE(ha
))
4112 icb
->firmware_options_2
|= cpu_to_le32(BIT_30
|BIT_29
);
4114 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
) ||
4116 icb
->qos
= cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
4117 icb
->rid
= cpu_to_le16(rid
);
4118 if (ha
->flags
.msix_enabled
) {
4119 msix
= &ha
->msix_entries
[1];
4120 ql_dbg(ql_dbg_init
, vha
, 0x0019,
4121 "Registering vector 0x%x for base que.\n",
4123 icb
->msix
= cpu_to_le16(msix
->entry
);
4125 /* Use alternate PCI bus number */
4127 icb
->firmware_options_2
|= cpu_to_le32(BIT_19
);
4128 /* Use alternate PCI devfn */
4130 icb
->firmware_options_2
|= cpu_to_le32(BIT_18
);
4132 /* Use Disable MSIX Handshake mode for capable adapters */
4133 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
4134 (ha
->flags
.msix_enabled
)) {
4135 icb
->firmware_options_2
&= cpu_to_le32(~BIT_22
);
4136 ha
->flags
.disable_msix_handshake
= 1;
4137 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
4138 "MSIX Handshake Disable Mode turned on.\n");
4140 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
4142 icb
->firmware_options_2
|= cpu_to_le32(BIT_23
);
4144 wrt_reg_dword(®
->isp25mq
.req_q_in
, 0);
4145 wrt_reg_dword(®
->isp25mq
.req_q_out
, 0);
4146 wrt_reg_dword(®
->isp25mq
.rsp_q_in
, 0);
4147 wrt_reg_dword(®
->isp25mq
.rsp_q_out
, 0);
4149 wrt_reg_dword(®
->isp24
.req_q_in
, 0);
4150 wrt_reg_dword(®
->isp24
.req_q_out
, 0);
4151 wrt_reg_dword(®
->isp24
.rsp_q_in
, 0);
4152 wrt_reg_dword(®
->isp24
.rsp_q_out
, 0);
4155 qlt_24xx_config_rings(vha
);
4157 /* If the user has configured the speed, set it here */
4158 if (ha
->set_data_rate
) {
4159 ql_dbg(ql_dbg_init
, vha
, 0x00fd,
4160 "Speed set by user : %s Gbps \n",
4161 qla2x00_get_link_speed_str(ha
, ha
->set_data_rate
));
4162 icb
->firmware_options_3
= cpu_to_le32(ha
->set_data_rate
<< 13);
4166 rd_reg_word(&ioreg
->hccr
);
4170 * qla2x00_init_rings() - Initializes firmware.
4173 * Beginning of request ring has initialization control block already built
4174 * by nvram config routine.
4176 * Returns 0 on success.
4179 qla2x00_init_rings(scsi_qla_host_t
*vha
)
4182 unsigned long flags
= 0;
4184 struct qla_hw_data
*ha
= vha
->hw
;
4185 struct req_que
*req
;
4186 struct rsp_que
*rsp
;
4187 struct mid_init_cb_24xx
*mid_init_cb
=
4188 (struct mid_init_cb_24xx
*) ha
->init_cb
;
4190 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4192 /* Clear outstanding commands array. */
4193 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
4194 req
= ha
->req_q_map
[que
];
4195 if (!req
|| !test_bit(que
, ha
->req_qid_map
))
4197 req
->out_ptr
= (uint16_t *)(req
->ring
+ req
->length
);
4199 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
4200 req
->outstanding_cmds
[cnt
] = NULL
;
4202 req
->current_outstanding_cmd
= 1;
4204 /* Initialize firmware. */
4205 req
->ring_ptr
= req
->ring
;
4206 req
->ring_index
= 0;
4207 req
->cnt
= req
->length
;
4210 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
4211 rsp
= ha
->rsp_q_map
[que
];
4212 if (!rsp
|| !test_bit(que
, ha
->rsp_qid_map
))
4214 rsp
->in_ptr
= (uint16_t *)(rsp
->ring
+ rsp
->length
);
4216 /* Initialize response queue entries */
4218 qlafx00_init_response_q_entries(rsp
);
4220 qla2x00_init_response_q_entries(rsp
);
4223 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
4224 ha
->tgt
.atio_ring_index
= 0;
4225 /* Initialize ATIO queue entries */
4226 qlt_init_atio_q_entries(vha
);
4228 ha
->isp_ops
->config_rings(vha
);
4230 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4232 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
4234 if (IS_QLAFX00(ha
)) {
4235 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
4239 /* Update any ISP specific firmware options before initialization. */
4240 ha
->isp_ops
->update_fw_options(vha
);
4242 if (ha
->flags
.npiv_supported
) {
4243 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
4244 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
4245 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
4248 if (IS_FWI2_CAPABLE(ha
)) {
4249 mid_init_cb
->options
= cpu_to_le16(BIT_1
);
4250 mid_init_cb
->init_cb
.execution_throttle
=
4251 cpu_to_le16(ha
->cur_fw_xcb_count
);
4252 ha
->flags
.dport_enabled
=
4253 (le32_to_cpu(mid_init_cb
->init_cb
.firmware_options_1
) &
4255 ql_dbg(ql_dbg_init
, vha
, 0x0191, "DPORT Support: %s.\n",
4256 (ha
->flags
.dport_enabled
) ? "enabled" : "disabled");
4257 /* FA-WWPN Status */
4258 ha
->flags
.fawwpn_enabled
=
4259 (le32_to_cpu(mid_init_cb
->init_cb
.firmware_options_1
) &
4261 ql_dbg(ql_dbg_init
, vha
, 0x00bc, "FA-WWPN Support: %s.\n",
4262 (ha
->flags
.fawwpn_enabled
) ? "enabled" : "disabled");
4265 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
4268 ql_log(ql_log_fatal
, vha
, 0x00d2,
4269 "Init Firmware **** FAILED ****.\n");
4271 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
4272 "Init Firmware -- success.\n");
4274 vha
->u_ql2xexchoffld
= vha
->u_ql2xiniexchg
= 0;
4281 * qla2x00_fw_ready() - Waits for firmware ready.
4284 * Returns 0 on success.
4287 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
4290 unsigned long wtime
, mtime
, cs84xx_time
;
4291 uint16_t min_wait
; /* Minimum wait time if loop is down */
4292 uint16_t wait_time
; /* Wait time if loop is coming ready */
4294 struct qla_hw_data
*ha
= vha
->hw
;
4296 if (IS_QLAFX00(vha
->hw
))
4297 return qlafx00_fw_ready(vha
);
4301 /* Time to wait for loop down */
4302 if (IS_P3P_TYPE(ha
))
4308 * Firmware should take at most one RATOV to login, plus 5 seconds for
4309 * our own processing.
4311 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
4312 wait_time
= min_wait
;
4315 /* Min wait time if loop down */
4316 mtime
= jiffies
+ (min_wait
* HZ
);
4318 /* wait time before firmware ready */
4319 wtime
= jiffies
+ (wait_time
* HZ
);
4321 /* Wait for ISP to finish LIP */
4322 if (!vha
->flags
.init_done
)
4323 ql_log(ql_log_info
, vha
, 0x801e,
4324 "Waiting for LIP to complete.\n");
4327 memset(state
, -1, sizeof(state
));
4328 rval
= qla2x00_get_firmware_state(vha
, state
);
4329 if (rval
== QLA_SUCCESS
) {
4330 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
4331 vha
->device_flags
&= ~DFLG_NO_CABLE
;
4333 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
4334 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
4335 "fw_state=%x 84xx=%x.\n", state
[0],
4337 if ((state
[2] & FSTATE_LOGGED_IN
) &&
4338 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
4339 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
4340 "Sending verify iocb.\n");
4342 cs84xx_time
= jiffies
;
4343 rval
= qla84xx_init_chip(vha
);
4344 if (rval
!= QLA_SUCCESS
) {
4347 "Init chip failed.\n");
4351 /* Add time taken to initialize. */
4352 cs84xx_time
= jiffies
- cs84xx_time
;
4353 wtime
+= cs84xx_time
;
4354 mtime
+= cs84xx_time
;
4355 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
4356 "Increasing wait time by %ld. "
4357 "New time %ld.\n", cs84xx_time
,
4360 } else if (state
[0] == FSTATE_READY
) {
4361 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
4362 "F/W Ready - OK.\n");
4364 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
4365 &ha
->login_timeout
, &ha
->r_a_tov
);
4371 rval
= QLA_FUNCTION_FAILED
;
4373 if (atomic_read(&vha
->loop_down_timer
) &&
4374 state
[0] != FSTATE_READY
) {
4375 /* Loop down. Timeout on min_wait for states
4376 * other than Wait for Login.
4378 if (time_after_eq(jiffies
, mtime
)) {
4379 ql_log(ql_log_info
, vha
, 0x8038,
4380 "Cable is unplugged...\n");
4382 vha
->device_flags
|= DFLG_NO_CABLE
;
4387 /* Mailbox cmd failed. Timeout on min_wait. */
4388 if (time_after_eq(jiffies
, mtime
) ||
4389 ha
->flags
.isp82xx_fw_hung
)
4393 if (time_after_eq(jiffies
, wtime
))
4396 /* Delay for a while */
4400 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
4401 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state
[0],
4402 state
[1], state
[2], state
[3], state
[4], state
[5], jiffies
);
4404 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
4405 ql_log(ql_log_warn
, vha
, 0x803b,
4406 "Firmware ready **** FAILED ****.\n");
4413 * qla2x00_configure_hba
4414 * Setup adapter context.
4417 * ha = adapter state pointer.
4426 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
4435 char connect_type
[22];
4436 struct qla_hw_data
*ha
= vha
->hw
;
4437 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4439 unsigned long flags
;
4441 /* Get host addresses. */
4442 rval
= qla2x00_get_adapter_id(vha
,
4443 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
4444 if (rval
!= QLA_SUCCESS
) {
4445 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
4446 IS_CNA_CAPABLE(ha
) ||
4447 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
4448 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
4449 "Loop is in a transition state.\n");
4451 ql_log(ql_log_warn
, vha
, 0x2009,
4452 "Unable to get host loop ID.\n");
4453 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
4454 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
4455 ql_log(ql_log_warn
, vha
, 0x1151,
4456 "Doing link init.\n");
4457 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
4460 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4466 ql_log(ql_log_info
, vha
, 0x200a,
4467 "Cannot get topology - retrying.\n");
4468 return (QLA_FUNCTION_FAILED
);
4471 vha
->loop_id
= loop_id
;
4474 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
4475 ha
->operating_mode
= LOOP
;
4480 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
4481 ha
->current_topology
= ISP_CFG_NL
;
4482 strcpy(connect_type
, "(Loop)");
4486 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
4487 ha
->switch_cap
= sw_cap
;
4488 ha
->current_topology
= ISP_CFG_FL
;
4489 strcpy(connect_type
, "(FL_Port)");
4493 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
4494 ha
->operating_mode
= P2P
;
4495 ha
->current_topology
= ISP_CFG_N
;
4496 strcpy(connect_type
, "(N_Port-to-N_Port)");
4500 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
4501 ha
->switch_cap
= sw_cap
;
4502 ha
->operating_mode
= P2P
;
4503 ha
->current_topology
= ISP_CFG_F
;
4504 strcpy(connect_type
, "(F_Port)");
4508 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
4509 "HBA in unknown topology %x, using NL.\n", topo
);
4510 ha
->current_topology
= ISP_CFG_NL
;
4511 strcpy(connect_type
, "(Loop)");
4515 /* Save Host port and loop ID. */
4516 /* byte order - Big Endian */
4517 id
.b
.domain
= domain
;
4521 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4522 if (!(topo
== 2 && ha
->flags
.n2n_bigger
))
4523 qlt_update_host_map(vha
, id
);
4524 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4526 if (!vha
->flags
.init_done
)
4527 ql_log(ql_log_info
, vha
, 0x2010,
4528 "Topology - %s, Host Loop address 0x%x.\n",
4529 connect_type
, vha
->loop_id
);
4535 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
4540 uint64_t zero
[2] = { 0 };
4541 struct qla_hw_data
*ha
= vha
->hw
;
4542 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
4543 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
4545 if (len
> sizeof(zero
))
4547 if (memcmp(model
, &zero
, len
) != 0) {
4548 memcpy(ha
->model_number
, model
, len
);
4549 st
= en
= ha
->model_number
;
4552 if (*en
!= 0x20 && *en
!= 0x00)
4557 index
= (ha
->pdev
->subsystem_device
& 0xff);
4559 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4560 index
< QLA_MODEL_NAMES
)
4561 strlcpy(ha
->model_desc
,
4562 qla2x00_model_name
[index
* 2 + 1],
4563 sizeof(ha
->model_desc
));
4565 index
= (ha
->pdev
->subsystem_device
& 0xff);
4567 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4568 index
< QLA_MODEL_NAMES
) {
4569 strlcpy(ha
->model_number
,
4570 qla2x00_model_name
[index
* 2],
4571 sizeof(ha
->model_number
));
4572 strlcpy(ha
->model_desc
,
4573 qla2x00_model_name
[index
* 2 + 1],
4574 sizeof(ha
->model_desc
));
4576 strlcpy(ha
->model_number
, def
,
4577 sizeof(ha
->model_number
));
4580 if (IS_FWI2_CAPABLE(ha
))
4581 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
4582 sizeof(ha
->model_desc
));
4585 /* On sparc systems, obtain port and node WWN from firmware
4588 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
4591 struct qla_hw_data
*ha
= vha
->hw
;
4592 struct pci_dev
*pdev
= ha
->pdev
;
4593 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4597 val
= of_get_property(dp
, "port-wwn", &len
);
4598 if (val
&& len
>= WWN_SIZE
)
4599 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4601 val
= of_get_property(dp
, "node-wwn", &len
);
4602 if (val
&& len
>= WWN_SIZE
)
4603 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4608 * NVRAM configuration for ISP 2xxx
4611 * ha = adapter block pointer.
4614 * initialization control block in response_ring
4615 * host adapters parameters in host adapter block
4621 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
4626 uint8_t *dptr1
, *dptr2
;
4627 struct qla_hw_data
*ha
= vha
->hw
;
4628 init_cb_t
*icb
= ha
->init_cb
;
4629 nvram_t
*nv
= ha
->nvram
;
4630 uint8_t *ptr
= ha
->nvram
;
4631 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4635 /* Determine NVRAM starting address. */
4636 ha
->nvram_size
= sizeof(*nv
);
4638 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
4639 if ((rd_reg_word(®
->ctrl_status
) >> 14) == 1)
4640 ha
->nvram_base
= 0x80;
4642 /* Get NVRAM data and calculate checksum. */
4643 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
4644 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
4647 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
4648 "Contents of NVRAM.\n");
4649 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
4650 nv
, ha
->nvram_size
);
4652 /* Bad NVRAM data, set defaults parameters. */
4653 if (chksum
|| memcmp("ISP ", nv
->id
, sizeof(nv
->id
)) ||
4654 nv
->nvram_version
< 1) {
4655 /* Reset NVRAM data. */
4656 ql_log(ql_log_warn
, vha
, 0x0064,
4657 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4658 chksum
, nv
->id
, nv
->nvram_version
);
4659 ql_log(ql_log_warn
, vha
, 0x0065,
4661 "functioning (yet invalid -- WWPN) defaults.\n");
4664 * Set default initialization control block.
4666 memset(nv
, 0, ha
->nvram_size
);
4667 nv
->parameter_block_version
= ICB_VERSION
;
4669 if (IS_QLA23XX(ha
)) {
4670 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4671 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4672 nv
->add_firmware_options
[0] = BIT_5
;
4673 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4674 nv
->frame_payload_size
= cpu_to_le16(2048);
4675 nv
->special_options
[1] = BIT_7
;
4676 } else if (IS_QLA2200(ha
)) {
4677 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4678 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4679 nv
->add_firmware_options
[0] = BIT_5
;
4680 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4681 nv
->frame_payload_size
= cpu_to_le16(1024);
4682 } else if (IS_QLA2100(ha
)) {
4683 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
4684 nv
->firmware_options
[1] = BIT_5
;
4685 nv
->frame_payload_size
= cpu_to_le16(1024);
4688 nv
->max_iocb_allocation
= cpu_to_le16(256);
4689 nv
->execution_throttle
= cpu_to_le16(16);
4690 nv
->retry_count
= 8;
4691 nv
->retry_delay
= 1;
4693 nv
->port_name
[0] = 33;
4694 nv
->port_name
[3] = 224;
4695 nv
->port_name
[4] = 139;
4697 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
4699 nv
->login_timeout
= 4;
4702 * Set default host adapter parameters
4704 nv
->host_p
[1] = BIT_2
;
4705 nv
->reset_delay
= 5;
4706 nv
->port_down_retry_count
= 8;
4707 nv
->max_luns_per_target
= cpu_to_le16(8);
4708 nv
->link_down_timeout
= 60;
4713 /* Reset Initialization control block */
4714 memset(icb
, 0, ha
->init_cb_size
);
4717 * Setup driver NVRAM options.
4719 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
4720 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
4721 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
4722 nv
->firmware_options
[1] &= ~BIT_4
;
4724 if (IS_QLA23XX(ha
)) {
4725 nv
->firmware_options
[0] |= BIT_2
;
4726 nv
->firmware_options
[0] &= ~BIT_3
;
4727 nv
->special_options
[0] &= ~BIT_6
;
4728 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
4730 if (IS_QLA2300(ha
)) {
4731 if (ha
->fb_rev
== FPM_2310
) {
4732 strcpy(ha
->model_number
, "QLA2310");
4734 strcpy(ha
->model_number
, "QLA2300");
4737 qla2x00_set_model_info(vha
, nv
->model_number
,
4738 sizeof(nv
->model_number
), "QLA23xx");
4740 } else if (IS_QLA2200(ha
)) {
4741 nv
->firmware_options
[0] |= BIT_2
;
4743 * 'Point-to-point preferred, else loop' is not a safe
4744 * connection mode setting.
4746 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
4748 /* Force 'loop preferred, else point-to-point'. */
4749 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
4750 nv
->add_firmware_options
[0] |= BIT_5
;
4752 strcpy(ha
->model_number
, "QLA22xx");
4753 } else /*if (IS_QLA2100(ha))*/ {
4754 strcpy(ha
->model_number
, "QLA2100");
4758 * Copy over NVRAM RISC parameter block to initialization control block.
4760 dptr1
= (uint8_t *)icb
;
4761 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
4762 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
4764 *dptr1
++ = *dptr2
++;
4766 /* Copy 2nd half. */
4767 dptr1
= (uint8_t *)icb
->add_firmware_options
;
4768 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
4770 *dptr1
++ = *dptr2
++;
4771 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
4772 /* Use alternate WWN? */
4773 if (nv
->host_p
[1] & BIT_7
) {
4774 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4775 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4778 /* Prepare nodename */
4779 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
4781 * Firmware will apply the following mask if the nodename was
4784 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4785 icb
->node_name
[0] &= 0xF0;
4789 * Set host adapter parameters.
4793 * BIT_7 in the host-parameters section allows for modification to
4794 * internal driver logging.
4796 if (nv
->host_p
[0] & BIT_7
)
4797 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
4798 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
4799 /* Always load RISC code on non ISP2[12]00 chips. */
4800 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
4801 ha
->flags
.disable_risc_code_load
= 0;
4802 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
4803 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
4804 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
4805 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
4806 ha
->flags
.disable_serdes
= 0;
4808 ha
->operating_mode
=
4809 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4811 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
4812 sizeof(ha
->fw_seriallink_options
));
4814 /* save HBA serial number */
4815 ha
->serial0
= icb
->port_name
[5];
4816 ha
->serial1
= icb
->port_name
[6];
4817 ha
->serial2
= icb
->port_name
[7];
4818 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4819 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4821 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
4823 ha
->retry_count
= nv
->retry_count
;
4825 /* Set minimum login_timeout to 4 seconds. */
4826 if (nv
->login_timeout
!= ql2xlogintimeout
)
4827 nv
->login_timeout
= ql2xlogintimeout
;
4828 if (nv
->login_timeout
< 4)
4829 nv
->login_timeout
= 4;
4830 ha
->login_timeout
= nv
->login_timeout
;
4832 /* Set minimum RATOV to 100 tenths of a second. */
4835 ha
->loop_reset_delay
= nv
->reset_delay
;
4837 /* Link Down Timeout = 0:
4839 * When Port Down timer expires we will start returning
4840 * I/O's to OS with "DID_NO_CONNECT".
4842 * Link Down Timeout != 0:
4844 * The driver waits for the link to come up after link down
4845 * before returning I/Os to OS with "DID_NO_CONNECT".
4847 if (nv
->link_down_timeout
== 0) {
4848 ha
->loop_down_abort_time
=
4849 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4851 ha
->link_down_timeout
= nv
->link_down_timeout
;
4852 ha
->loop_down_abort_time
=
4853 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4857 * Need enough time to try and get the port back.
4859 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
4860 if (qlport_down_retry
)
4861 ha
->port_down_retry_count
= qlport_down_retry
;
4862 /* Set login_retry_count */
4863 ha
->login_retry_count
= nv
->retry_count
;
4864 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
4865 ha
->port_down_retry_count
> 3)
4866 ha
->login_retry_count
= ha
->port_down_retry_count
;
4867 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4868 ha
->login_retry_count
= ha
->port_down_retry_count
;
4869 if (ql2xloginretrycount
)
4870 ha
->login_retry_count
= ql2xloginretrycount
;
4872 icb
->lun_enables
= cpu_to_le16(0);
4873 icb
->command_resource_count
= 0;
4874 icb
->immediate_notify_resource_count
= 0;
4875 icb
->timeout
= cpu_to_le16(0);
4877 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
4879 icb
->firmware_options
[0] &= ~BIT_3
;
4880 icb
->add_firmware_options
[0] &=
4881 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4882 icb
->add_firmware_options
[0] |= BIT_2
;
4883 icb
->response_accumulation_timer
= 3;
4884 icb
->interrupt_delay_timer
= 5;
4886 vha
->flags
.process_response_queue
= 1;
4889 if (!vha
->flags
.init_done
) {
4890 ha
->zio_mode
= icb
->add_firmware_options
[0] &
4891 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4892 ha
->zio_timer
= icb
->interrupt_delay_timer
?
4893 icb
->interrupt_delay_timer
: 2;
4895 icb
->add_firmware_options
[0] &=
4896 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4897 vha
->flags
.process_response_queue
= 0;
4898 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4899 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4901 ql_log(ql_log_info
, vha
, 0x0068,
4902 "ZIO mode %d enabled; timer delay (%d us).\n",
4903 ha
->zio_mode
, ha
->zio_timer
* 100);
4905 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
4906 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
4907 vha
->flags
.process_response_queue
= 1;
4912 ql_log(ql_log_warn
, vha
, 0x0069,
4913 "NVRAM configuration failed.\n");
4919 qla2x00_rport_del(void *data
)
4921 fc_port_t
*fcport
= data
;
4922 struct fc_rport
*rport
;
4923 unsigned long flags
;
4925 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
4926 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
4927 fcport
->drport
= NULL
;
4928 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
4930 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210b,
4931 "%s %8phN. rport %p roles %x\n",
4932 __func__
, fcport
->port_name
, rport
,
4935 fc_remote_port_delete(rport
);
4939 void qla2x00_set_fcport_state(fc_port_t
*fcport
, int state
)
4943 old_state
= atomic_read(&fcport
->state
);
4944 atomic_set(&fcport
->state
, state
);
4946 /* Don't print state transitions during initial allocation of fcport */
4947 if (old_state
&& old_state
!= state
) {
4948 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x207d,
4949 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4950 fcport
->port_name
, port_state_str
[old_state
],
4951 port_state_str
[state
], fcport
->d_id
.b
.domain
,
4952 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
4957 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4959 * @flags: allocation flags
4961 * Returns a pointer to the allocated fcport, or NULL, if none available.
4964 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
4968 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
4972 fcport
->ct_desc
.ct_sns
= dma_alloc_coherent(&vha
->hw
->pdev
->dev
,
4973 sizeof(struct ct_sns_pkt
), &fcport
->ct_desc
.ct_sns_dma
,
4975 if (!fcport
->ct_desc
.ct_sns
) {
4976 ql_log(ql_log_warn
, vha
, 0xd049,
4977 "Failed to allocate ct_sns request.\n");
4982 /* Setup fcport template structure. */
4984 fcport
->port_type
= FCT_UNKNOWN
;
4985 fcport
->loop_id
= FC_NO_LOOP_ID
;
4986 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
4987 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
4988 fcport
->fp_speed
= PORT_SPEED_UNKNOWN
;
4990 fcport
->disc_state
= DSC_DELETED
;
4991 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4992 fcport
->deleted
= QLA_SESS_DELETED
;
4993 fcport
->login_retry
= vha
->hw
->login_retry_count
;
4994 fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
4995 fcport
->logout_on_delete
= 1;
4997 if (!fcport
->ct_desc
.ct_sns
) {
4998 ql_log(ql_log_warn
, vha
, 0xd049,
4999 "Failed to allocate ct_sns request.\n");
5004 INIT_WORK(&fcport
->del_work
, qla24xx_delete_sess_fn
);
5005 INIT_WORK(&fcport
->free_work
, qlt_free_session_done
);
5006 INIT_WORK(&fcport
->reg_work
, qla_register_fcport_fn
);
5007 INIT_LIST_HEAD(&fcport
->gnl_entry
);
5008 INIT_LIST_HEAD(&fcport
->list
);
5010 INIT_LIST_HEAD(&fcport
->sess_cmd_list
);
5011 spin_lock_init(&fcport
->sess_cmd_lock
);
5017 qla2x00_free_fcport(fc_port_t
*fcport
)
5019 if (fcport
->ct_desc
.ct_sns
) {
5020 dma_free_coherent(&fcport
->vha
->hw
->pdev
->dev
,
5021 sizeof(struct ct_sns_pkt
), fcport
->ct_desc
.ct_sns
,
5022 fcport
->ct_desc
.ct_sns_dma
);
5024 fcport
->ct_desc
.ct_sns
= NULL
;
5026 list_del(&fcport
->list
);
5027 qla2x00_clear_loop_id(fcport
);
5031 static void qla_get_login_template(scsi_qla_host_t
*vha
)
5033 struct qla_hw_data
*ha
= vha
->hw
;
5038 memset(ha
->init_cb
, 0, ha
->init_cb_size
);
5039 sz
= min_t(int, sizeof(struct fc_els_flogi
), ha
->init_cb_size
);
5040 rval
= qla24xx_get_port_login_templ(vha
, ha
->init_cb_dma
,
5042 if (rval
!= QLA_SUCCESS
) {
5043 ql_dbg(ql_dbg_init
, vha
, 0x00d1,
5044 "PLOGI ELS param read fail.\n");
5047 q
= (__be32
*)&ha
->plogi_els_payld
.fl_csp
;
5049 bp
= (uint32_t *)ha
->init_cb
;
5050 cpu_to_be32_array(q
, bp
, sz
/ 4);
5051 ha
->flags
.plogi_template_valid
= 1;
5055 * qla2x00_configure_loop
5056 * Updates Fibre Channel Device Database with what is actually on loop.
5059 * ha = adapter block pointer.
5064 * 2 = database was full and device was not configured.
5067 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
5070 unsigned long flags
, save_flags
;
5071 struct qla_hw_data
*ha
= vha
->hw
;
5075 /* Get Initiator ID */
5076 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
5077 rval
= qla2x00_configure_hba(vha
);
5078 if (rval
!= QLA_SUCCESS
) {
5079 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
5080 "Unable to configure HBA.\n");
5085 save_flags
= flags
= vha
->dpc_flags
;
5086 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
5087 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
5090 * If we have both an RSCN and PORT UPDATE pending then handle them
5091 * both at the same time.
5093 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5094 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
5096 qla2x00_get_data_rate(vha
);
5097 qla_get_login_template(vha
);
5099 /* Determine what we need to do */
5100 if ((ha
->current_topology
== ISP_CFG_FL
||
5101 ha
->current_topology
== ISP_CFG_F
) &&
5102 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
5104 set_bit(RSCN_UPDATE
, &flags
);
5105 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
5107 } else if (ha
->current_topology
== ISP_CFG_NL
||
5108 ha
->current_topology
== ISP_CFG_N
) {
5109 clear_bit(RSCN_UPDATE
, &flags
);
5110 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
5111 } else if (!vha
->flags
.online
||
5112 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
5113 set_bit(RSCN_UPDATE
, &flags
);
5114 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
5117 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
5118 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
5119 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
5120 "Loop resync needed, failing.\n");
5121 rval
= QLA_FUNCTION_FAILED
;
5123 rval
= qla2x00_configure_local_loop(vha
);
5126 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
5127 if (LOOP_TRANSITION(vha
)) {
5128 ql_dbg(ql_dbg_disc
, vha
, 0x2099,
5129 "Needs RSCN update and loop transition.\n");
5130 rval
= QLA_FUNCTION_FAILED
;
5133 rval
= qla2x00_configure_fabric(vha
);
5136 if (rval
== QLA_SUCCESS
) {
5137 if (atomic_read(&vha
->loop_down_timer
) ||
5138 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
5139 rval
= QLA_FUNCTION_FAILED
;
5141 atomic_set(&vha
->loop_state
, LOOP_READY
);
5142 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
5144 ha
->flags
.fw_init_done
= 1;
5147 * Process any ATIO queue entries that came in
5148 * while we weren't online.
5150 if (qla_tgt_mode_enabled(vha
) ||
5151 qla_dual_mode_enabled(vha
)) {
5152 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
5153 qlt_24xx_process_atio_queue(vha
, 0);
5154 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
,
5161 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
5162 "%s *** FAILED ***.\n", __func__
);
5164 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
5165 "%s: exiting normally.\n", __func__
);
5168 /* Restore state if a resync event occurred during processing */
5169 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
5170 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
5171 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5172 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
5173 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
5180 static int qla2x00_configure_n2n_loop(scsi_qla_host_t
*vha
)
5182 unsigned long flags
;
5185 if (test_and_clear_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
))
5186 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
5188 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5189 if (fcport
->n2n_flag
) {
5190 qla24xx_fcport_handle_login(vha
, fcport
);
5195 spin_lock_irqsave(&vha
->work_lock
, flags
);
5196 vha
->scan
.scan_retry
++;
5197 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
5199 if (vha
->scan
.scan_retry
< MAX_SCAN_RETRIES
) {
5200 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5201 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5203 return QLA_FUNCTION_FAILED
;
5207 * qla2x00_configure_local_loop
5208 * Updates Fibre Channel Device Database with local loop devices.
5211 * ha = adapter block pointer.
5217 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
5222 fc_port_t
*fcport
, *new_fcport
;
5225 struct gid_list_info
*gid
;
5227 uint8_t domain
, area
, al_pa
;
5228 struct qla_hw_data
*ha
= vha
->hw
;
5229 unsigned long flags
;
5231 /* Inititae N2N login. */
5233 return qla2x00_configure_n2n_loop(vha
);
5237 entries
= MAX_FIBRE_DEVICES_LOOP
;
5239 /* Get list of logged in devices. */
5240 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
5241 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
5243 if (rval
!= QLA_SUCCESS
)
5246 ql_dbg(ql_dbg_disc
, vha
, 0x2011,
5247 "Entries in ID list (%d).\n", entries
);
5248 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
5249 ha
->gid_list
, entries
* sizeof(*ha
->gid_list
));
5252 spin_lock_irqsave(&vha
->work_lock
, flags
);
5253 vha
->scan
.scan_retry
++;
5254 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
5256 if (vha
->scan
.scan_retry
< MAX_SCAN_RETRIES
) {
5257 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5258 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5261 vha
->scan
.scan_retry
= 0;
5264 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5265 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5268 /* Allocate temporary fcport for any new fcports discovered. */
5269 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5270 if (new_fcport
== NULL
) {
5271 ql_log(ql_log_warn
, vha
, 0x2012,
5272 "Memory allocation failed for fcport.\n");
5273 rval
= QLA_MEMORY_ALLOC_FAILED
;
5276 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5278 /* Add devices to port list. */
5280 for (index
= 0; index
< entries
; index
++) {
5281 domain
= gid
->domain
;
5284 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
5285 loop_id
= gid
->loop_id_2100
;
5287 loop_id
= le16_to_cpu(gid
->loop_id
);
5288 gid
= (void *)gid
+ ha
->gid_list_info_size
;
5290 /* Bypass reserved domain fields. */
5291 if ((domain
& 0xf0) == 0xf0)
5294 /* Bypass if not same domain and area of adapter. */
5295 if (area
&& domain
&& ((area
!= vha
->d_id
.b
.area
) ||
5296 (domain
!= vha
->d_id
.b
.domain
)) &&
5297 (ha
->current_topology
== ISP_CFG_NL
))
5301 /* Bypass invalid local loop ID. */
5302 if (loop_id
> LAST_LOCAL_LOOP_ID
)
5305 memset(new_fcport
->port_name
, 0, WWN_SIZE
);
5307 /* Fill in member data. */
5308 new_fcport
->d_id
.b
.domain
= domain
;
5309 new_fcport
->d_id
.b
.area
= area
;
5310 new_fcport
->d_id
.b
.al_pa
= al_pa
;
5311 new_fcport
->loop_id
= loop_id
;
5312 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5314 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
5315 if (rval2
!= QLA_SUCCESS
) {
5316 ql_dbg(ql_dbg_disc
, vha
, 0x2097,
5317 "Failed to retrieve fcport information "
5318 "-- get_port_database=%x, loop_id=0x%04x.\n",
5319 rval2
, new_fcport
->loop_id
);
5320 /* Skip retry if N2N */
5321 if (ha
->current_topology
!= ISP_CFG_N
) {
5322 ql_dbg(ql_dbg_disc
, vha
, 0x2105,
5323 "Scheduling resync.\n");
5324 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5329 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5330 /* Check for matching device in port list. */
5333 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5334 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5338 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5339 fcport
->loop_id
= new_fcport
->loop_id
;
5340 fcport
->port_type
= new_fcport
->port_type
;
5341 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5342 memcpy(fcport
->node_name
, new_fcport
->node_name
,
5344 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5350 /* New device, add to fcports list. */
5351 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5353 /* Allocate a new replacement fcport. */
5354 fcport
= new_fcport
;
5356 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5358 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5360 if (new_fcport
== NULL
) {
5361 ql_log(ql_log_warn
, vha
, 0xd031,
5362 "Failed to allocate memory for fcport.\n");
5363 rval
= QLA_MEMORY_ALLOC_FAILED
;
5366 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5367 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5370 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5372 /* Base iIDMA settings on HBA port speed. */
5373 fcport
->fp_speed
= ha
->link_data_rate
;
5378 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5379 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5382 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5383 if ((qla_dual_mode_enabled(vha
) ||
5384 qla_ini_mode_enabled(vha
)) &&
5385 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5386 qla2x00_mark_device_lost(vha
, fcport
,
5387 ql2xplogiabsentdevice
);
5388 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5389 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5390 fcport
->port_type
!= FCT_INITIATOR
&&
5391 fcport
->port_type
!= FCT_BROADCAST
) {
5392 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5393 "%s %d %8phC post del sess\n",
5397 qlt_schedule_sess_for_deletion(fcport
);
5403 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5404 qla24xx_fcport_handle_login(vha
, fcport
);
5407 qla2x00_free_fcport(new_fcport
);
5412 ql_dbg(ql_dbg_disc
, vha
, 0x2098,
5413 "Configure local loop error exit: rval=%x.\n", rval
);
5418 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5421 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5422 struct qla_hw_data
*ha
= vha
->hw
;
5424 if (!IS_IIDMA_CAPABLE(ha
))
5427 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
5430 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
5431 fcport
->fp_speed
> ha
->link_data_rate
||
5432 !ha
->flags
.gpsc_supported
)
5435 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
5437 if (rval
!= QLA_SUCCESS
) {
5438 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
5439 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5440 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
5442 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
5443 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5444 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
5445 fcport
->fp_speed
, fcport
->port_name
);
5449 void qla_do_iidma_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
5451 qla2x00_iidma_fcport(vha
, fcport
);
5452 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5455 int qla_post_iidma_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
5457 struct qla_work_evt
*e
;
5459 e
= qla2x00_alloc_work(vha
, QLA_EVT_IIDMA
);
5461 return QLA_FUNCTION_FAILED
;
5463 e
->u
.fcport
.fcport
= fcport
;
5464 return qla2x00_post_work(vha
, e
);
5467 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5469 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5471 struct fc_rport_identifiers rport_ids
;
5472 struct fc_rport
*rport
;
5473 unsigned long flags
;
5475 if (atomic_read(&fcport
->state
) == FCS_ONLINE
)
5478 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
5479 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
5480 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
5481 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
5482 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5483 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
5485 ql_log(ql_log_warn
, vha
, 0x2006,
5486 "Unable to allocate fc remote port.\n");
5490 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
5491 *((fc_port_t
**)rport
->dd_data
) = fcport
;
5492 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
5494 rport
->supported_classes
= fcport
->supported_classes
;
5496 rport_ids
.roles
= FC_PORT_ROLE_UNKNOWN
;
5497 if (fcport
->port_type
== FCT_INITIATOR
)
5498 rport_ids
.roles
|= FC_PORT_ROLE_FCP_INITIATOR
;
5499 if (fcport
->port_type
== FCT_TARGET
)
5500 rport_ids
.roles
|= FC_PORT_ROLE_FCP_TARGET
;
5501 if (fcport
->port_type
& FCT_NVME_INITIATOR
)
5502 rport_ids
.roles
|= FC_PORT_ROLE_NVME_INITIATOR
;
5503 if (fcport
->port_type
& FCT_NVME_TARGET
)
5504 rport_ids
.roles
|= FC_PORT_ROLE_NVME_TARGET
;
5505 if (fcport
->port_type
& FCT_NVME_DISCOVERY
)
5506 rport_ids
.roles
|= FC_PORT_ROLE_NVME_DISCOVERY
;
5508 ql_dbg(ql_dbg_disc
, vha
, 0x20ee,
5509 "%s %8phN. rport %p is %s mode\n",
5510 __func__
, fcport
->port_name
, rport
,
5511 (fcport
->port_type
== FCT_TARGET
) ? "tgt" :
5512 ((fcport
->port_type
& FCT_NVME
) ? "nvme" : "ini"));
5514 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
5518 * qla2x00_update_fcport
5519 * Updates device on list.
5522 * ha = adapter block pointer.
5523 * fcport = port structure pointer.
5533 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5535 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5538 ql_dbg(ql_dbg_disc
, vha
, 0x20ef, "%s %8phC\n",
5539 __func__
, fcport
->port_name
);
5541 qla2x00_set_fcport_disc_state(fcport
, DSC_UPD_FCPORT
);
5542 fcport
->login_retry
= vha
->hw
->login_retry_count
;
5543 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
5544 fcport
->deleted
= 0;
5545 if (vha
->hw
->current_topology
== ISP_CFG_NL
)
5546 fcport
->logout_on_delete
= 0;
5548 fcport
->logout_on_delete
= 1;
5549 fcport
->n2n_chip_reset
= fcport
->n2n_link_reset_cnt
= 0;
5551 switch (vha
->hw
->current_topology
) {
5554 fcport
->keep_nport_handle
= 1;
5560 qla2x00_iidma_fcport(vha
, fcport
);
5562 qla2x00_dfs_create_rport(vha
, fcport
);
5564 if (NVME_TARGET(vha
->hw
, fcport
)) {
5565 qla_nvme_register_remote(vha
, fcport
);
5566 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_COMPLETE
);
5567 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5571 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5573 switch (vha
->host
->active_mode
) {
5574 case MODE_INITIATOR
:
5575 qla2x00_reg_remote_port(vha
, fcport
);
5578 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5579 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5580 qlt_fc_port_added(vha
, fcport
);
5583 qla2x00_reg_remote_port(vha
, fcport
);
5584 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5585 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5586 qlt_fc_port_added(vha
, fcport
);
5592 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5594 if (IS_IIDMA_CAPABLE(vha
->hw
) && vha
->hw
->flags
.gpsc_supported
) {
5595 if (fcport
->id_changed
) {
5596 fcport
->id_changed
= 0;
5597 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
5598 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5599 __func__
, __LINE__
, fcport
->port_name
,
5601 qla24xx_post_gfpnid_work(vha
, fcport
);
5603 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
5604 "%s %d %8phC post gpsc fcp_cnt %d\n",
5605 __func__
, __LINE__
, fcport
->port_name
,
5607 qla24xx_post_gpsc_work(vha
, fcport
);
5611 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_COMPLETE
);
5614 void qla_register_fcport_fn(struct work_struct
*work
)
5616 fc_port_t
*fcport
= container_of(work
, struct fc_port
, reg_work
);
5617 u32 rscn_gen
= fcport
->rscn_gen
;
5620 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5623 qla2x00_update_fcport(fcport
->vha
, fcport
);
5625 if (rscn_gen
!= fcport
->rscn_gen
) {
5626 /* RSCN(s) came in while registration */
5627 switch (fcport
->next_disc_state
) {
5628 case DSC_DELETE_PEND
:
5629 qlt_schedule_sess_for_deletion(fcport
);
5632 data
[0] = data
[1] = 0;
5633 qla2x00_post_async_adisc_work(fcport
->vha
, fcport
,
5643 * qla2x00_configure_fabric
5644 * Setup SNS devices with loop ID's.
5647 * ha = adapter block pointer.
5654 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
5658 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5660 LIST_HEAD(new_fcports
);
5661 struct qla_hw_data
*ha
= vha
->hw
;
5664 /* If FL port exists, then SNS is present */
5665 if (IS_FWI2_CAPABLE(ha
))
5666 loop_id
= NPH_F_PORT
;
5668 loop_id
= SNS_FL_PORT
;
5669 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
5670 if (rval
!= QLA_SUCCESS
) {
5671 ql_dbg(ql_dbg_disc
, vha
, 0x20a0,
5672 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5674 vha
->device_flags
&= ~SWITCH_FOUND
;
5675 return (QLA_SUCCESS
);
5677 vha
->device_flags
|= SWITCH_FOUND
;
5679 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_port_name
, 0);
5680 if (rval
!= QLA_SUCCESS
)
5681 ql_dbg(ql_dbg_disc
, vha
, 0x20ff,
5682 "Failed to get Fabric Port Name\n");
5684 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
5685 rval
= qla2x00_send_change_request(vha
, 0x3, 0);
5686 if (rval
!= QLA_SUCCESS
)
5687 ql_log(ql_log_warn
, vha
, 0x121,
5688 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5693 qla2x00_mgmt_svr_login(vha
);
5695 /* Ensure we are logged into the SNS. */
5696 loop_id
= NPH_SNS_LID(ha
);
5697 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
5698 0xfc, mb
, BIT_1
|BIT_0
);
5699 if (rval
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5700 ql_dbg(ql_dbg_disc
, vha
, 0x20a1,
5701 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5702 loop_id
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7], rval
);
5703 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5708 if (ql2xfdmienable
&&
5709 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
5710 qla2x00_fdmi_register(vha
);
5712 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
5713 if (qla2x00_rft_id(vha
)) {
5715 ql_dbg(ql_dbg_disc
, vha
, 0x20a2,
5716 "Register FC-4 TYPE failed.\n");
5717 if (test_bit(LOOP_RESYNC_NEEDED
,
5721 if (qla2x00_rff_id(vha
, FC4_TYPE_FCP_SCSI
)) {
5723 ql_dbg(ql_dbg_disc
, vha
, 0x209a,
5724 "Register FC-4 Features failed.\n");
5725 if (test_bit(LOOP_RESYNC_NEEDED
,
5729 if (vha
->flags
.nvme_enabled
) {
5730 if (qla2x00_rff_id(vha
, FC_TYPE_NVME
)) {
5731 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
5732 "Register NVME FC Type Features failed.\n");
5735 if (qla2x00_rnn_id(vha
)) {
5737 ql_dbg(ql_dbg_disc
, vha
, 0x2104,
5738 "Register Node Name failed.\n");
5739 if (test_bit(LOOP_RESYNC_NEEDED
,
5742 } else if (qla2x00_rsnn_nn(vha
)) {
5744 ql_dbg(ql_dbg_disc
, vha
, 0x209b,
5745 "Register Symbolic Node Name failed.\n");
5746 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5752 /* Mark the time right before querying FW for connected ports.
5753 * This process is long, asynchronous and by the time it's done,
5754 * collected information might not be accurate anymore. E.g.
5755 * disconnected port might have re-connected and a brand new
5756 * session has been created. In this case session's generation
5757 * will be newer than discovery_gen. */
5758 qlt_do_generation_tick(vha
, &discovery_gen
);
5760 if (USE_ASYNC_SCAN(ha
)) {
5761 rval
= qla24xx_async_gpnft(vha
, FC4_TYPE_FCP_SCSI
,
5764 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5766 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5767 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5769 rval
= qla2x00_find_all_fabric_devs(vha
);
5771 if (rval
!= QLA_SUCCESS
)
5775 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
5776 qla_nvme_register_hba(vha
);
5779 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
5780 "Configure fabric error exit rval=%d.\n", rval
);
5786 * qla2x00_find_all_fabric_devs
5789 * ha = adapter block pointer.
5790 * dev = database device entry pointer.
5799 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
)
5803 fc_port_t
*fcport
, *new_fcport
;
5808 int first_dev
, last_dev
;
5809 port_id_t wrap
= {}, nxt_d_id
;
5810 struct qla_hw_data
*ha
= vha
->hw
;
5811 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5812 unsigned long flags
;
5816 /* Try GID_PT to get device list, else GAN. */
5818 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
5823 ql_dbg(ql_dbg_disc
, vha
, 0x209c,
5824 "GID_PT allocations failed, fallback on GA_NXT.\n");
5826 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
5827 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
5829 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5831 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
5833 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5835 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
5837 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5839 } else if (qla2x00_gfpn_id(vha
, swl
) != QLA_SUCCESS
) {
5841 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5845 /* If other queries succeeded probe for FC-4 type */
5847 qla2x00_gff_id(vha
, swl
);
5848 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5854 /* Allocate temporary fcport for any new fcports discovered. */
5855 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5856 if (new_fcport
== NULL
) {
5857 ql_log(ql_log_warn
, vha
, 0x209d,
5858 "Failed to allocate memory for fcport.\n");
5859 return (QLA_MEMORY_ALLOC_FAILED
);
5861 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5862 /* Set start port ID scan at adapter ID. */
5866 /* Starting free loop ID. */
5867 loop_id
= ha
->min_external_loopid
;
5868 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
5869 if (qla2x00_is_reserved_id(vha
, loop_id
))
5872 if (ha
->current_topology
== ISP_CFG_FL
&&
5873 (atomic_read(&vha
->loop_down_timer
) ||
5874 LOOP_TRANSITION(vha
))) {
5875 atomic_set(&vha
->loop_down_timer
, 0);
5876 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5877 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5883 wrap
.b24
= new_fcport
->d_id
.b24
;
5885 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
5886 memcpy(new_fcport
->node_name
,
5887 swl
[swl_idx
].node_name
, WWN_SIZE
);
5888 memcpy(new_fcport
->port_name
,
5889 swl
[swl_idx
].port_name
, WWN_SIZE
);
5890 memcpy(new_fcport
->fabric_port_name
,
5891 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
5892 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
5893 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
5895 new_fcport
->nvme_flag
= 0;
5896 if (vha
->flags
.nvme_enabled
&&
5897 swl
[swl_idx
].fc4_type
& FS_FC4TYPE_NVME
) {
5898 ql_log(ql_log_info
, vha
, 0x2131,
5899 "FOUND: NVME port %8phC as FC Type 28h\n",
5900 new_fcport
->port_name
);
5903 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
5909 /* Send GA_NXT to the switch */
5910 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
5911 if (rval
!= QLA_SUCCESS
) {
5912 ql_log(ql_log_warn
, vha
, 0x209e,
5913 "SNS scan failed -- assuming "
5914 "zero-entry result.\n");
5920 /* If wrap on switch device list, exit. */
5922 wrap
.b24
= new_fcport
->d_id
.b24
;
5924 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
5925 ql_dbg(ql_dbg_disc
, vha
, 0x209f,
5926 "Device wrap (%02x%02x%02x).\n",
5927 new_fcport
->d_id
.b
.domain
,
5928 new_fcport
->d_id
.b
.area
,
5929 new_fcport
->d_id
.b
.al_pa
);
5933 /* Bypass if same physical adapter. */
5934 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
5937 /* Bypass virtual ports of the same host. */
5938 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
5941 /* Bypass if same domain and area of adapter. */
5942 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
5943 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
5947 /* Bypass reserved domain fields. */
5948 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
5951 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5952 if (ql2xgffidenable
&&
5953 (!(new_fcport
->fc4_type
& FS_FC4TYPE_FCP
) &&
5954 new_fcport
->fc4_type
!= 0))
5957 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5959 /* Locate matching device in database. */
5961 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5962 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5966 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5970 /* Update port state. */
5971 memcpy(fcport
->fabric_port_name
,
5972 new_fcport
->fabric_port_name
, WWN_SIZE
);
5973 fcport
->fp_speed
= new_fcport
->fp_speed
;
5976 * If address the same and state FCS_ONLINE
5977 * (or in target mode), nothing changed.
5979 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
5980 (atomic_read(&fcport
->state
) == FCS_ONLINE
||
5981 (vha
->host
->active_mode
== MODE_TARGET
))) {
5985 if (fcport
->login_retry
== 0)
5986 fcport
->login_retry
=
5987 vha
->hw
->login_retry_count
;
5989 * If device was not a fabric device before.
5991 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
5992 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5993 qla2x00_clear_loop_id(fcport
);
5994 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
6000 * Port ID changed or device was marked to be updated;
6001 * Log it out if still logged in and mark it for
6004 if (qla_tgt_mode_enabled(base_vha
)) {
6005 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf080,
6006 "port changed FC ID, %8phC"
6007 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
6009 fcport
->d_id
.b
.domain
,
6010 fcport
->d_id
.b
.area
,
6011 fcport
->d_id
.b
.al_pa
,
6013 new_fcport
->d_id
.b
.domain
,
6014 new_fcport
->d_id
.b
.area
,
6015 new_fcport
->d_id
.b
.al_pa
);
6016 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
6020 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
6021 fcport
->flags
|= FCF_LOGIN_NEEDED
;
6025 if (found
&& NVME_TARGET(vha
->hw
, fcport
)) {
6026 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
6027 qla2x00_set_fcport_disc_state(fcport
, DSC_GNL
);
6028 vha
->fcport_count
--;
6029 fcport
->login_succ
= 0;
6034 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
6037 /* If device was not in our fcports list, then add it. */
6038 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
6039 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
6041 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
6044 /* Allocate a new replacement fcport. */
6045 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
6046 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
6047 if (new_fcport
== NULL
) {
6048 ql_log(ql_log_warn
, vha
, 0xd032,
6049 "Memory allocation failed for fcport.\n");
6050 return (QLA_MEMORY_ALLOC_FAILED
);
6052 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
6053 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
6056 qla2x00_free_fcport(new_fcport
);
6059 * Logout all previous fabric dev marked lost, except FCP2 devices.
6061 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
6062 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
6065 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
6068 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
6069 if ((qla_dual_mode_enabled(vha
) ||
6070 qla_ini_mode_enabled(vha
)) &&
6071 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
6072 qla2x00_mark_device_lost(vha
, fcport
,
6073 ql2xplogiabsentdevice
);
6074 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
6075 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
6076 fcport
->port_type
!= FCT_INITIATOR
&&
6077 fcport
->port_type
!= FCT_BROADCAST
) {
6078 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
6079 "%s %d %8phC post del sess\n",
6082 qlt_schedule_sess_for_deletion(fcport
);
6088 if (fcport
->scan_state
== QLA_FCPORT_FOUND
&&
6089 (fcport
->flags
& FCF_LOGIN_NEEDED
) != 0)
6090 qla24xx_fcport_handle_login(vha
, fcport
);
6095 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6097 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t
*vha
)
6099 int loop_id
= FC_NO_LOOP_ID
;
6100 int lid
= NPH_MGMT_SERVER
- vha
->vp_idx
;
6101 unsigned long flags
;
6102 struct qla_hw_data
*ha
= vha
->hw
;
6104 if (vha
->vp_idx
== 0) {
6105 set_bit(NPH_MGMT_SERVER
, ha
->loop_id_map
);
6106 return NPH_MGMT_SERVER
;
6109 /* pick id from high and work down to low */
6110 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6111 for (; lid
> 0; lid
--) {
6112 if (!test_bit(lid
, vha
->hw
->loop_id_map
)) {
6113 set_bit(lid
, vha
->hw
->loop_id_map
);
6118 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6124 * qla2x00_fabric_login
6125 * Issue fabric login command.
6128 * ha = adapter block pointer.
6129 * device = pointer to FC device type structure.
6132 * 0 - Login successfully
6134 * 2 - Initiator device
6138 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
6139 uint16_t *next_loopid
)
6143 uint16_t tmp_loopid
;
6144 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6145 struct qla_hw_data
*ha
= vha
->hw
;
6151 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
6152 "Trying Fabric Login w/loop id 0x%04x for port "
6154 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
6155 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
6157 /* Login fcport on switch. */
6158 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
6159 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
6160 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
6161 if (rval
!= QLA_SUCCESS
) {
6164 if (mb
[0] == MBS_PORT_ID_USED
) {
6166 * Device has another loop ID. The firmware team
6167 * recommends the driver perform an implicit login with
6168 * the specified ID again. The ID we just used is save
6169 * here so we return with an ID that can be tried by
6173 tmp_loopid
= fcport
->loop_id
;
6174 fcport
->loop_id
= mb
[1];
6176 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
6177 "Fabric Login: port in use - next loop "
6178 "id=0x%04x, port id= %02x%02x%02x.\n",
6179 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
6180 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
6182 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
6187 /* A retry occurred before. */
6188 *next_loopid
= tmp_loopid
;
6191 * No retry occurred before. Just increment the
6192 * ID value for next login.
6194 *next_loopid
= (fcport
->loop_id
+ 1);
6197 if (mb
[1] & BIT_0
) {
6198 fcport
->port_type
= FCT_INITIATOR
;
6200 fcport
->port_type
= FCT_TARGET
;
6201 if (mb
[1] & BIT_1
) {
6202 fcport
->flags
|= FCF_FCP2_DEVICE
;
6207 fcport
->supported_classes
|= FC_COS_CLASS2
;
6209 fcport
->supported_classes
|= FC_COS_CLASS3
;
6211 if (IS_FWI2_CAPABLE(ha
)) {
6214 FCF_CONF_COMP_SUPPORTED
;
6219 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
6221 * Loop ID already used, try next loop ID.
6224 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
6225 if (rval
!= QLA_SUCCESS
) {
6226 /* Ran out of loop IDs to use */
6229 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
6231 * Firmware possibly timed out during login. If NO
6232 * retries are left to do then the device is declared
6235 *next_loopid
= fcport
->loop_id
;
6236 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
6237 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
6238 fcport
->d_id
.b
.al_pa
);
6239 qla2x00_mark_device_lost(vha
, fcport
, 1);
6245 * unrecoverable / not handled error
6247 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
6248 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6249 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
6250 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
6251 fcport
->loop_id
, jiffies
);
6253 *next_loopid
= fcport
->loop_id
;
6254 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
6255 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
6256 fcport
->d_id
.b
.al_pa
);
6257 qla2x00_clear_loop_id(fcport
);
6258 fcport
->login_retry
= 0;
6269 * qla2x00_local_device_login
6270 * Issue local device login command.
6273 * ha = adapter block pointer.
6274 * loop_id = loop id of device to login to.
6276 * Returns (Where's the #define!!!!):
6277 * 0 - Login successfully
6282 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
6285 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6287 memset(mb
, 0, sizeof(mb
));
6288 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
6289 if (rval
== QLA_SUCCESS
) {
6290 /* Interrogate mailbox registers for any errors */
6291 if (mb
[0] == MBS_COMMAND_ERROR
)
6293 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
6294 /* device not in PCB table */
6302 * qla2x00_loop_resync
6303 * Resync with fibre channel devices.
6306 * ha = adapter block pointer.
6312 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
6314 int rval
= QLA_SUCCESS
;
6317 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6318 if (vha
->flags
.online
) {
6319 if (!(rval
= qla2x00_fw_ready(vha
))) {
6320 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6323 if (!IS_QLAFX00(vha
->hw
)) {
6325 * Issue a marker after FW becomes
6328 qla2x00_marker(vha
, vha
->hw
->base_qpair
,
6330 vha
->marker_needed
= 0;
6333 /* Remap devices on Loop. */
6334 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6336 if (IS_QLAFX00(vha
->hw
))
6337 qlafx00_configure_devices(vha
);
6339 qla2x00_configure_loop(vha
);
6342 } while (!atomic_read(&vha
->loop_down_timer
) &&
6343 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
6344 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
6349 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
6350 return (QLA_FUNCTION_FAILED
);
6353 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
6354 "%s *** FAILED ***.\n", __func__
);
6360 * qla2x00_perform_loop_resync
6361 * Description: This function will set the appropriate flags and call
6362 * qla2x00_loop_resync. If successful loop will be resynced
6363 * Arguments : scsi_qla_host_t pointer
6364 * returm : Success or Failure
6367 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
6371 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
6372 /*Configure the flags so that resync happens properly*/
6373 atomic_set(&ha
->loop_down_timer
, 0);
6374 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
6375 atomic_set(&ha
->loop_state
, LOOP_UP
);
6376 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
6377 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
6378 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
6380 rval
= qla2x00_loop_resync(ha
);
6382 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
6384 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
6391 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
6394 struct scsi_qla_host
*vha
;
6395 struct qla_hw_data
*ha
= base_vha
->hw
;
6396 unsigned long flags
;
6398 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6399 /* Go with deferred removal of rport references. */
6400 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
6401 atomic_inc(&vha
->vref_count
);
6402 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
6403 if (fcport
->drport
&&
6404 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
6405 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6406 qla2x00_rport_del(fcport
);
6408 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6411 atomic_dec(&vha
->vref_count
);
6412 wake_up(&vha
->vref_waitq
);
6414 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6417 /* Assumes idc_lock always held on entry */
6419 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
6421 struct qla_hw_data
*ha
= vha
->hw
;
6422 uint32_t drv_presence
, drv_presence_mask
;
6423 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
6424 uint32_t class_type_mask
= 0x3;
6425 uint16_t fcoe_other_function
= 0xffff, i
;
6427 if (IS_QLA8044(ha
)) {
6428 drv_presence
= qla8044_rd_direct(vha
,
6429 QLA8044_CRB_DRV_ACTIVE_INDEX
);
6430 dev_part_info1
= qla8044_rd_direct(vha
,
6431 QLA8044_CRB_DEV_PART_INFO_INDEX
);
6432 dev_part_info2
= qla8044_rd_direct(vha
,
6433 QLA8044_CRB_DEV_PART_INFO2
);
6435 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6436 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
6437 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
6439 for (i
= 0; i
< 8; i
++) {
6440 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
6441 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
6442 (i
!= ha
->portnum
)) {
6443 fcoe_other_function
= i
;
6447 if (fcoe_other_function
== 0xffff) {
6448 for (i
= 0; i
< 8; i
++) {
6449 class_type
= ((dev_part_info2
>> (i
* 4)) &
6451 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
6452 ((i
+ 8) != ha
->portnum
)) {
6453 fcoe_other_function
= i
+ 8;
6459 * Prepare drv-presence mask based on fcoe functions present.
6460 * However consider only valid physical fcoe function numbers (0-15).
6462 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
6463 ((fcoe_other_function
== 0xffff) ?
6464 0 : (1 << (fcoe_other_function
))));
6466 /* We are the reset owner iff:
6467 * - No other protocol drivers present.
6468 * - This is the lowest among fcoe functions. */
6469 if (!(drv_presence
& drv_presence_mask
) &&
6470 (ha
->portnum
< fcoe_other_function
)) {
6471 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
6472 "This host is Reset owner.\n");
6473 ha
->flags
.nic_core_reset_owner
= 1;
6478 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
6480 int rval
= QLA_SUCCESS
;
6481 struct qla_hw_data
*ha
= vha
->hw
;
6484 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6485 if (rval
== QLA_SUCCESS
) {
6486 drv_ack
|= (1 << ha
->portnum
);
6487 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6494 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
6496 int rval
= QLA_SUCCESS
;
6497 struct qla_hw_data
*ha
= vha
->hw
;
6500 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6501 if (rval
== QLA_SUCCESS
) {
6502 drv_ack
&= ~(1 << ha
->portnum
);
6503 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6510 qla83xx_dev_state_to_string(uint32_t dev_state
)
6512 switch (dev_state
) {
6513 case QLA8XXX_DEV_COLD
:
6514 return "COLD/RE-INIT";
6515 case QLA8XXX_DEV_INITIALIZING
:
6516 return "INITIALIZING";
6517 case QLA8XXX_DEV_READY
:
6519 case QLA8XXX_DEV_NEED_RESET
:
6520 return "NEED RESET";
6521 case QLA8XXX_DEV_NEED_QUIESCENT
:
6522 return "NEED QUIESCENT";
6523 case QLA8XXX_DEV_FAILED
:
6525 case QLA8XXX_DEV_QUIESCENT
:
6532 /* Assumes idc-lock always held on entry */
6534 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
6536 struct qla_hw_data
*ha
= vha
->hw
;
6537 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
6539 switch (audit_type
) {
6540 case IDC_AUDIT_TIMESTAMP
:
6541 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
6542 idc_audit_reg
= (ha
->portnum
) |
6543 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
6544 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6547 case IDC_AUDIT_COMPLETION
:
6548 duration_secs
= ((jiffies_to_msecs(jiffies
) -
6549 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
6550 idc_audit_reg
= (ha
->portnum
) |
6551 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
6552 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6556 ql_log(ql_log_warn
, vha
, 0xb078,
6557 "Invalid audit type specified.\n");
6562 /* Assumes idc_lock always held on entry */
6564 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
6566 struct qla_hw_data
*ha
= vha
->hw
;
6567 uint32_t idc_control
, dev_state
;
6569 __qla83xx_get_idc_control(vha
, &idc_control
);
6570 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
6571 ql_log(ql_log_info
, vha
, 0xb080,
6572 "NIC Core reset has been disabled. idc-control=0x%x\n",
6574 return QLA_FUNCTION_FAILED
;
6577 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6578 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6579 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
6580 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
6581 QLA8XXX_DEV_NEED_RESET
);
6582 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
6583 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
6585 const char *state
= qla83xx_dev_state_to_string(dev_state
);
6587 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
6589 /* SV: XXX: Is timeout required here? */
6590 /* Wait for IDC state change READY -> NEED_RESET */
6591 while (dev_state
== QLA8XXX_DEV_READY
) {
6592 qla83xx_idc_unlock(vha
, 0);
6594 qla83xx_idc_lock(vha
, 0);
6595 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6599 /* Send IDC ack by writing to drv-ack register */
6600 __qla83xx_set_drv_ack(vha
);
6606 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
6608 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6612 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
6614 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6618 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
6620 uint32_t drv_presence
= 0;
6621 struct qla_hw_data
*ha
= vha
->hw
;
6623 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6624 if (drv_presence
& (1 << ha
->portnum
))
6627 return QLA_TEST_FAILED
;
6631 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
6633 int rval
= QLA_SUCCESS
;
6634 struct qla_hw_data
*ha
= vha
->hw
;
6636 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
6637 "Entered %s().\n", __func__
);
6639 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
6640 ql_log(ql_log_warn
, vha
, 0xb059,
6641 "Device in unrecoverable FAILED state.\n");
6642 return QLA_FUNCTION_FAILED
;
6645 qla83xx_idc_lock(vha
, 0);
6647 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
6648 ql_log(ql_log_warn
, vha
, 0xb05a,
6649 "Function=0x%x has been removed from IDC participation.\n",
6651 rval
= QLA_FUNCTION_FAILED
;
6655 qla83xx_reset_ownership(vha
);
6657 rval
= qla83xx_initiating_reset(vha
);
6660 * Perform reset if we are the reset-owner,
6661 * else wait till IDC state changes to READY/FAILED.
6663 if (rval
== QLA_SUCCESS
) {
6664 rval
= qla83xx_idc_state_handler(vha
);
6666 if (rval
== QLA_SUCCESS
)
6667 ha
->flags
.nic_core_hung
= 0;
6668 __qla83xx_clear_drv_ack(vha
);
6672 qla83xx_idc_unlock(vha
, 0);
6674 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
6680 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
6682 struct qla_hw_data
*ha
= vha
->hw
;
6683 int rval
= QLA_FUNCTION_FAILED
;
6685 if (!IS_MCTP_CAPABLE(ha
)) {
6686 /* This message can be removed from the final version */
6687 ql_log(ql_log_info
, vha
, 0x506d,
6688 "This board is not MCTP capable\n");
6692 if (!ha
->mctp_dump
) {
6693 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
6694 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
6696 if (!ha
->mctp_dump
) {
6697 ql_log(ql_log_warn
, vha
, 0x506e,
6698 "Failed to allocate memory for mctp dump\n");
6703 #define MCTP_DUMP_STR_ADDR 0x00000000
6704 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
6705 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
6706 if (rval
!= QLA_SUCCESS
) {
6707 ql_log(ql_log_warn
, vha
, 0x506f,
6708 "Failed to capture mctp dump\n");
6710 ql_log(ql_log_info
, vha
, 0x5070,
6711 "Mctp dump capture for host (%ld/%p).\n",
6712 vha
->host_no
, ha
->mctp_dump
);
6713 ha
->mctp_dumped
= 1;
6716 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
6717 ha
->flags
.nic_core_reset_hdlr_active
= 1;
6718 rval
= qla83xx_restart_nic_firmware(vha
);
6720 /* NIC Core reset failed. */
6721 ql_log(ql_log_warn
, vha
, 0x5071,
6722 "Failed to restart nic firmware\n");
6724 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
6725 "Restarted NIC firmware successfully.\n");
6726 ha
->flags
.nic_core_reset_hdlr_active
= 0;
6734 * qla2x00_quiesce_io
6735 * Description: This function will block the new I/Os
6736 * Its not aborting any I/Os as context
6737 * is not destroyed during quiescence
6738 * Arguments: scsi_qla_host_t
6742 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
6744 struct qla_hw_data
*ha
= vha
->hw
;
6745 struct scsi_qla_host
*vp
;
6747 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
6748 "Quiescing I/O - ha=%p.\n", ha
);
6750 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
6751 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6752 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6753 qla2x00_mark_all_devices_lost(vha
);
6754 list_for_each_entry(vp
, &ha
->vp_list
, list
)
6755 qla2x00_mark_all_devices_lost(vp
);
6757 if (!atomic_read(&vha
->loop_down_timer
))
6758 atomic_set(&vha
->loop_down_timer
,
6761 /* Wait for pending cmds to complete */
6762 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
)
6767 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
6769 struct qla_hw_data
*ha
= vha
->hw
;
6770 struct scsi_qla_host
*vp
;
6771 unsigned long flags
;
6775 /* For ISP82XX, driver waits for completion of the commands.
6776 * online flag should be set.
6778 if (!(IS_P3P_TYPE(ha
)))
6779 vha
->flags
.online
= 0;
6780 ha
->flags
.chip_reset_done
= 0;
6781 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6782 vha
->qla_stats
.total_isp_aborts
++;
6784 ql_log(ql_log_info
, vha
, 0x00af,
6785 "Performing ISP error recovery - ha=%p.\n", ha
);
6787 ha
->flags
.purge_mbox
= 1;
6788 /* For ISP82XX, reset_chip is just disabling interrupts.
6789 * Driver waits for the completion of the commands.
6790 * the interrupts need to be enabled.
6792 if (!(IS_P3P_TYPE(ha
)))
6793 ha
->isp_ops
->reset_chip(vha
);
6795 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
6797 ha
->flags
.rida_fmt2
= 0;
6798 ha
->flags
.n2n_ae
= 0;
6799 ha
->flags
.lip_ae
= 0;
6800 ha
->current_topology
= 0;
6802 ha
->flags
.fw_init_done
= 0;
6804 ha
->base_qpair
->chip_reset
= ha
->chip_reset
;
6805 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6806 if (ha
->queue_pair_map
[i
])
6807 ha
->queue_pair_map
[i
]->chip_reset
=
6808 ha
->base_qpair
->chip_reset
;
6811 /* purge MBox commands */
6812 if (atomic_read(&ha
->num_pend_mbx_stage3
)) {
6813 clear_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
);
6814 complete(&ha
->mbx_intr_comp
);
6818 while (atomic_read(&ha
->num_pend_mbx_stage3
) ||
6819 atomic_read(&ha
->num_pend_mbx_stage2
) ||
6820 atomic_read(&ha
->num_pend_mbx_stage1
)) {
6826 ha
->flags
.purge_mbox
= 0;
6828 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
6829 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6830 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6831 qla2x00_mark_all_devices_lost(vha
);
6833 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6834 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6835 atomic_inc(&vp
->vref_count
);
6836 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6838 qla2x00_mark_all_devices_lost(vp
);
6840 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6841 atomic_dec(&vp
->vref_count
);
6843 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6845 if (!atomic_read(&vha
->loop_down_timer
))
6846 atomic_set(&vha
->loop_down_timer
,
6850 /* Clear all async request states across all VPs. */
6851 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
6852 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6853 fcport
->scan_state
= 0;
6855 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6856 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6857 atomic_inc(&vp
->vref_count
);
6858 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6860 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
6861 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6863 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6864 atomic_dec(&vp
->vref_count
);
6866 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6868 if (!ha
->flags
.eeh_busy
) {
6869 /* Make sure for ISP 82XX IO DMA is complete */
6870 if (IS_P3P_TYPE(ha
)) {
6871 qla82xx_chip_reset_cleanup(vha
);
6872 ql_log(ql_log_info
, vha
, 0x00b4,
6873 "Done chip reset cleanup.\n");
6875 /* Done waiting for pending commands.
6876 * Reset the online flag.
6878 vha
->flags
.online
= 0;
6881 /* Requeue all commands in outstanding command list. */
6882 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6884 /* memory barrier */
6890 * Resets ISP and aborts all outstanding commands.
6893 * ha = adapter block pointer.
6899 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
6903 struct qla_hw_data
*ha
= vha
->hw
;
6904 struct scsi_qla_host
*vp
;
6905 struct req_que
*req
= ha
->req_q_map
[0];
6906 unsigned long flags
;
6908 if (vha
->flags
.online
) {
6909 qla2x00_abort_isp_cleanup(vha
);
6911 if (test_and_clear_bit(ISP_ABORT_TO_ROM
, &vha
->dpc_flags
)) {
6912 ha
->flags
.chip_reset_done
= 1;
6913 vha
->flags
.online
= 1;
6915 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6919 if (IS_QLA8031(ha
)) {
6920 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
6921 "Clearing fcoe driver presence.\n");
6922 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
6923 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
6924 "Error while clearing DRV-Presence.\n");
6927 if (unlikely(pci_channel_offline(ha
->pdev
) &&
6928 ha
->flags
.pci_channel_io_perm_failure
)) {
6929 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6934 switch (vha
->qlini_mode
) {
6935 case QLA2XXX_INI_MODE_DISABLED
:
6936 if (!qla_tgt_mode_enabled(vha
))
6939 case QLA2XXX_INI_MODE_DUAL
:
6940 if (!qla_dual_mode_enabled(vha
))
6943 case QLA2XXX_INI_MODE_ENABLED
:
6948 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
6950 ha
->isp_ops
->nvram_config(vha
);
6952 if (!qla2x00_restart_isp(vha
)) {
6953 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6955 if (!atomic_read(&vha
->loop_down_timer
)) {
6957 * Issue marker command only when we are going
6958 * to start the I/O .
6960 vha
->marker_needed
= 1;
6963 vha
->flags
.online
= 1;
6965 ha
->isp_ops
->enable_intrs(ha
);
6967 ha
->isp_abort_cnt
= 0;
6968 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6970 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
6971 qla2x00_get_fw_version(vha
);
6973 ha
->flags
.fce_enabled
= 1;
6975 fce_calc_size(ha
->fce_bufs
));
6976 rval
= qla2x00_enable_fce_trace(vha
,
6977 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6980 ql_log(ql_log_warn
, vha
, 0x8033,
6981 "Unable to reinitialize FCE "
6983 ha
->flags
.fce_enabled
= 0;
6988 memset(ha
->eft
, 0, EFT_SIZE
);
6989 rval
= qla2x00_enable_eft_trace(vha
,
6990 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6992 ql_log(ql_log_warn
, vha
, 0x8034,
6993 "Unable to reinitialize EFT "
6997 } else { /* failed the ISP abort */
6998 vha
->flags
.online
= 1;
6999 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
7000 if (ha
->isp_abort_cnt
== 0) {
7001 ql_log(ql_log_fatal
, vha
, 0x8035,
7002 "ISP error recover failed - "
7003 "board disabled.\n");
7005 * The next call disables the board
7008 qla2x00_abort_isp_cleanup(vha
);
7009 vha
->flags
.online
= 0;
7010 clear_bit(ISP_ABORT_RETRY
,
7013 } else { /* schedule another ISP abort */
7014 ha
->isp_abort_cnt
--;
7015 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
7016 "ISP abort - retry remaining %d.\n",
7021 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
7022 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
7023 "ISP error recovery - retrying (%d) "
7024 "more times.\n", ha
->isp_abort_cnt
);
7025 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
7033 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
7034 qla2x00_configure_hba(vha
);
7035 spin_lock_irqsave(&ha
->vport_slock
, flags
);
7036 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
7038 atomic_inc(&vp
->vref_count
);
7039 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
7041 qla2x00_vp_abort_isp(vp
);
7043 spin_lock_irqsave(&ha
->vport_slock
, flags
);
7044 atomic_dec(&vp
->vref_count
);
7047 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
7049 if (IS_QLA8031(ha
)) {
7050 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
7051 "Setting back fcoe driver presence.\n");
7052 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
7053 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
7054 "Error while setting DRV-Presence.\n");
7057 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
7065 * qla2x00_restart_isp
7066 * restarts the ISP after a reset
7069 * ha = adapter block pointer.
7075 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
7078 struct qla_hw_data
*ha
= vha
->hw
;
7080 /* If firmware needs to be loaded */
7081 if (qla2x00_isp_firmware(vha
)) {
7082 vha
->flags
.online
= 0;
7083 status
= ha
->isp_ops
->chip_diag(vha
);
7086 status
= qla2x00_setup_chip(vha
);
7091 status
= qla2x00_init_rings(vha
);
7095 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
7096 ha
->flags
.chip_reset_done
= 1;
7098 /* Initialize the queues in use */
7099 qla25xx_init_queues(ha
);
7101 status
= qla2x00_fw_ready(vha
);
7103 /* if no cable then assume it's good */
7104 return vha
->device_flags
& DFLG_NO_CABLE
? 0 : status
;
7107 /* Issue a marker after FW becomes ready. */
7108 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
7109 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
7115 qla25xx_init_queues(struct qla_hw_data
*ha
)
7117 struct rsp_que
*rsp
= NULL
;
7118 struct req_que
*req
= NULL
;
7119 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
7123 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
7124 rsp
= ha
->rsp_q_map
[i
];
7125 if (rsp
&& test_bit(i
, ha
->rsp_qid_map
)) {
7126 rsp
->options
&= ~BIT_0
;
7127 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
7128 if (ret
!= QLA_SUCCESS
)
7129 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
7130 "%s Rsp que: %d init failed.\n",
7133 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
7134 "%s Rsp que: %d inited.\n",
7138 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
7139 req
= ha
->req_q_map
[i
];
7140 if (req
&& test_bit(i
, ha
->req_qid_map
)) {
7141 /* Clear outstanding commands array. */
7142 req
->options
&= ~BIT_0
;
7143 ret
= qla25xx_init_req_que(base_vha
, req
);
7144 if (ret
!= QLA_SUCCESS
)
7145 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
7146 "%s Req que: %d init failed.\n",
7149 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
7150 "%s Req que: %d inited.\n",
7158 * qla2x00_reset_adapter
7162 * ha = adapter block pointer.
7165 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
7167 unsigned long flags
= 0;
7168 struct qla_hw_data
*ha
= vha
->hw
;
7169 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
7171 vha
->flags
.online
= 0;
7172 ha
->isp_ops
->disable_intrs(ha
);
7174 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
7175 wrt_reg_word(®
->hccr
, HCCR_RESET_RISC
);
7176 rd_reg_word(®
->hccr
); /* PCI Posting. */
7177 wrt_reg_word(®
->hccr
, HCCR_RELEASE_RISC
);
7178 rd_reg_word(®
->hccr
); /* PCI Posting. */
7179 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
7185 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
7187 unsigned long flags
= 0;
7188 struct qla_hw_data
*ha
= vha
->hw
;
7189 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
7191 if (IS_P3P_TYPE(ha
))
7194 vha
->flags
.online
= 0;
7195 ha
->isp_ops
->disable_intrs(ha
);
7197 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
7198 wrt_reg_dword(®
->hccr
, HCCRX_SET_RISC_RESET
);
7199 rd_reg_dword(®
->hccr
);
7200 wrt_reg_dword(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
7201 rd_reg_dword(®
->hccr
);
7202 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
7204 if (IS_NOPOLLING_TYPE(ha
))
7205 ha
->isp_ops
->enable_intrs(ha
);
7210 /* On sparc systems, obtain port and node WWN from firmware
7213 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
7214 struct nvram_24xx
*nv
)
7217 struct qla_hw_data
*ha
= vha
->hw
;
7218 struct pci_dev
*pdev
= ha
->pdev
;
7219 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
7223 val
= of_get_property(dp
, "port-wwn", &len
);
7224 if (val
&& len
>= WWN_SIZE
)
7225 memcpy(nv
->port_name
, val
, WWN_SIZE
);
7227 val
= of_get_property(dp
, "node-wwn", &len
);
7228 if (val
&& len
>= WWN_SIZE
)
7229 memcpy(nv
->node_name
, val
, WWN_SIZE
);
7234 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
7237 struct init_cb_24xx
*icb
;
7238 struct nvram_24xx
*nv
;
7240 uint8_t *dptr1
, *dptr2
;
7243 struct qla_hw_data
*ha
= vha
->hw
;
7246 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
7249 /* Determine NVRAM starting address. */
7250 if (ha
->port_no
== 0) {
7251 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
7252 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
7254 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
7255 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
7258 ha
->nvram_size
= sizeof(*nv
);
7259 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
7261 /* Get VPD data into cache */
7262 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
7263 ha
->isp_ops
->read_nvram(vha
, ha
->vpd
,
7264 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
7266 /* Get NVRAM data into cache and calculate checksum. */
7267 dptr
= (__force __le32
*)nv
;
7268 ha
->isp_ops
->read_nvram(vha
, dptr
, ha
->nvram_base
, ha
->nvram_size
);
7269 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
7270 chksum
+= le32_to_cpu(*dptr
);
7272 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
7273 "Contents of NVRAM\n");
7274 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
7275 nv
, ha
->nvram_size
);
7277 /* Bad NVRAM data, set defaults parameters. */
7278 if (chksum
|| memcmp("ISP ", nv
->id
, sizeof(nv
->id
)) ||
7279 le16_to_cpu(nv
->nvram_version
) < ICB_VERSION
) {
7280 /* Reset NVRAM data. */
7281 ql_log(ql_log_warn
, vha
, 0x006b,
7282 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7283 chksum
, nv
->id
, nv
->nvram_version
);
7284 ql_dump_buffer(ql_dbg_init
, vha
, 0x006b, nv
, sizeof(*nv
));
7285 ql_log(ql_log_warn
, vha
, 0x006c,
7286 "Falling back to functioning (yet invalid -- WWPN) "
7290 * Set default initialization control block.
7292 memset(nv
, 0, ha
->nvram_size
);
7293 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
7294 nv
->version
= cpu_to_le16(ICB_VERSION
);
7295 nv
->frame_payload_size
= cpu_to_le16(2048);
7296 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
7297 nv
->exchange_count
= cpu_to_le16(0);
7298 nv
->hard_address
= cpu_to_le16(124);
7299 nv
->port_name
[0] = 0x21;
7300 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
7301 nv
->port_name
[2] = 0x00;
7302 nv
->port_name
[3] = 0xe0;
7303 nv
->port_name
[4] = 0x8b;
7304 nv
->port_name
[5] = 0x1c;
7305 nv
->port_name
[6] = 0x55;
7306 nv
->port_name
[7] = 0x86;
7307 nv
->node_name
[0] = 0x20;
7308 nv
->node_name
[1] = 0x00;
7309 nv
->node_name
[2] = 0x00;
7310 nv
->node_name
[3] = 0xe0;
7311 nv
->node_name
[4] = 0x8b;
7312 nv
->node_name
[5] = 0x1c;
7313 nv
->node_name
[6] = 0x55;
7314 nv
->node_name
[7] = 0x86;
7315 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
7316 nv
->login_retry_count
= cpu_to_le16(8);
7317 nv
->interrupt_delay_timer
= cpu_to_le16(0);
7318 nv
->login_timeout
= cpu_to_le16(0);
7319 nv
->firmware_options_1
=
7320 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
7321 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
7322 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
7323 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
7324 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
7325 nv
->efi_parameters
= cpu_to_le32(0);
7326 nv
->reset_delay
= 5;
7327 nv
->max_luns_per_target
= cpu_to_le16(128);
7328 nv
->port_down_retry_count
= cpu_to_le16(30);
7329 nv
->link_down_timeout
= cpu_to_le16(30);
7334 if (qla_tgt_mode_enabled(vha
)) {
7335 /* Don't enable full login after initial LIP */
7336 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
7337 /* Don't enable LIP full login for initiator */
7338 nv
->host_p
&= cpu_to_le32(~BIT_10
);
7341 qlt_24xx_config_nvram_stage1(vha
, nv
);
7343 /* Reset Initialization control block */
7344 memset(icb
, 0, ha
->init_cb_size
);
7346 /* Copy 1st segment. */
7347 dptr1
= (uint8_t *)icb
;
7348 dptr2
= (uint8_t *)&nv
->version
;
7349 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
7351 *dptr1
++ = *dptr2
++;
7353 icb
->login_retry_count
= nv
->login_retry_count
;
7354 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
7356 /* Copy 2nd segment. */
7357 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
7358 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
7359 cnt
= (uint8_t *)&icb
->reserved_3
-
7360 (uint8_t *)&icb
->interrupt_delay_timer
;
7362 *dptr1
++ = *dptr2
++;
7363 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
7365 * Setup driver NVRAM options.
7367 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
7370 qlt_24xx_config_nvram_stage2(vha
, icb
);
7372 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
7373 /* Use alternate WWN? */
7374 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
7375 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
7378 /* Prepare nodename */
7379 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
7381 * Firmware will apply the following mask if the nodename was
7384 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
7385 icb
->node_name
[0] &= 0xF0;
7388 /* Set host adapter parameters. */
7389 ha
->flags
.disable_risc_code_load
= 0;
7390 ha
->flags
.enable_lip_reset
= 0;
7391 ha
->flags
.enable_lip_full_login
=
7392 le32_to_cpu(nv
->host_p
) & BIT_10
? 1 : 0;
7393 ha
->flags
.enable_target_reset
=
7394 le32_to_cpu(nv
->host_p
) & BIT_11
? 1 : 0;
7395 ha
->flags
.enable_led_scheme
= 0;
7396 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1 : 0;
7398 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
7399 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
7401 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
7402 sizeof(ha
->fw_seriallink_options24
));
7404 /* save HBA serial number */
7405 ha
->serial0
= icb
->port_name
[5];
7406 ha
->serial1
= icb
->port_name
[6];
7407 ha
->serial2
= icb
->port_name
[7];
7408 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
7409 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
7411 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
7413 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
7415 /* Set minimum login_timeout to 4 seconds. */
7416 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
7417 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
7418 if (le16_to_cpu(nv
->login_timeout
) < 4)
7419 nv
->login_timeout
= cpu_to_le16(4);
7420 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
7422 /* Set minimum RATOV to 100 tenths of a second. */
7425 ha
->loop_reset_delay
= nv
->reset_delay
;
7427 /* Link Down Timeout = 0:
7429 * When Port Down timer expires we will start returning
7430 * I/O's to OS with "DID_NO_CONNECT".
7432 * Link Down Timeout != 0:
7434 * The driver waits for the link to come up after link down
7435 * before returning I/Os to OS with "DID_NO_CONNECT".
7437 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
7438 ha
->loop_down_abort_time
=
7439 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
7441 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
7442 ha
->loop_down_abort_time
=
7443 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
7446 /* Need enough time to try and get the port back. */
7447 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
7448 if (qlport_down_retry
)
7449 ha
->port_down_retry_count
= qlport_down_retry
;
7451 /* Set login_retry_count */
7452 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
7453 if (ha
->port_down_retry_count
==
7454 le16_to_cpu(nv
->port_down_retry_count
) &&
7455 ha
->port_down_retry_count
> 3)
7456 ha
->login_retry_count
= ha
->port_down_retry_count
;
7457 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
7458 ha
->login_retry_count
= ha
->port_down_retry_count
;
7459 if (ql2xloginretrycount
)
7460 ha
->login_retry_count
= ql2xloginretrycount
;
7462 /* N2N: driver will initiate Login instead of FW */
7463 icb
->firmware_options_3
|= cpu_to_le32(BIT_8
);
7466 if (!vha
->flags
.init_done
) {
7467 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
7468 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
7469 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
7470 le16_to_cpu(icb
->interrupt_delay_timer
) : 2;
7472 icb
->firmware_options_2
&= cpu_to_le32(
7473 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
7474 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
7475 ha
->zio_mode
= QLA_ZIO_MODE_6
;
7477 ql_log(ql_log_info
, vha
, 0x006f,
7478 "ZIO mode %d enabled; timer delay (%d us).\n",
7479 ha
->zio_mode
, ha
->zio_timer
* 100);
7481 icb
->firmware_options_2
|= cpu_to_le32(
7482 (uint32_t)ha
->zio_mode
);
7483 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
7487 ql_log(ql_log_warn
, vha
, 0x0070,
7488 "NVRAM configuration failed.\n");
7494 qla27xx_print_image(struct scsi_qla_host
*vha
, char *name
,
7495 struct qla27xx_image_status
*image_status
)
7497 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7498 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7500 image_status
->image_status_mask
,
7501 le16_to_cpu(image_status
->generation
),
7502 image_status
->ver_major
,
7503 image_status
->ver_minor
,
7504 image_status
->bitmap
,
7505 le32_to_cpu(image_status
->checksum
),
7506 le32_to_cpu(image_status
->signature
));
7510 qla28xx_check_aux_image_status_signature(
7511 struct qla27xx_image_status
*image_status
)
7513 ulong signature
= le32_to_cpu(image_status
->signature
);
7515 return signature
!= QLA28XX_AUX_IMG_STATUS_SIGN
;
7519 qla27xx_check_image_status_signature(struct qla27xx_image_status
*image_status
)
7521 ulong signature
= le32_to_cpu(image_status
->signature
);
7524 signature
!= QLA27XX_IMG_STATUS_SIGN
&&
7525 signature
!= QLA28XX_IMG_STATUS_SIGN
;
7529 qla27xx_image_status_checksum(struct qla27xx_image_status
*image_status
)
7531 __le32
*p
= (__force __le32
*)image_status
;
7532 uint n
= sizeof(*image_status
) / sizeof(*p
);
7536 sum
+= le32_to_cpup(p
);
7542 qla28xx_component_bitmask(struct qla27xx_image_status
*aux
, uint bitmask
)
7544 return aux
->bitmap
& bitmask
?
7545 QLA27XX_SECONDARY_IMAGE
: QLA27XX_PRIMARY_IMAGE
;
7549 qla28xx_component_status(
7550 struct active_regions
*active_regions
, struct qla27xx_image_status
*aux
)
7552 active_regions
->aux
.board_config
=
7553 qla28xx_component_bitmask(aux
, QLA28XX_AUX_IMG_BOARD_CONFIG
);
7555 active_regions
->aux
.vpd_nvram
=
7556 qla28xx_component_bitmask(aux
, QLA28XX_AUX_IMG_VPD_NVRAM
);
7558 active_regions
->aux
.npiv_config_0_1
=
7559 qla28xx_component_bitmask(aux
, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1
);
7561 active_regions
->aux
.npiv_config_2_3
=
7562 qla28xx_component_bitmask(aux
, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3
);
7566 qla27xx_compare_image_generation(
7567 struct qla27xx_image_status
*pri_image_status
,
7568 struct qla27xx_image_status
*sec_image_status
)
7570 /* calculate generation delta as uint16 (this accounts for wrap) */
7572 le16_to_cpu(pri_image_status
->generation
) -
7573 le16_to_cpu(sec_image_status
->generation
);
7575 ql_dbg(ql_dbg_init
, NULL
, 0x0180, "generation delta = %d\n", delta
);
7581 qla28xx_get_aux_images(
7582 struct scsi_qla_host
*vha
, struct active_regions
*active_regions
)
7584 struct qla_hw_data
*ha
= vha
->hw
;
7585 struct qla27xx_image_status pri_aux_image_status
, sec_aux_image_status
;
7586 bool valid_pri_image
= false, valid_sec_image
= false;
7587 bool active_pri_image
= false, active_sec_image
= false;
7589 if (!ha
->flt_region_aux_img_status_pri
) {
7590 ql_dbg(ql_dbg_init
, vha
, 0x018a, "Primary aux image not addressed\n");
7591 goto check_sec_image
;
7594 qla24xx_read_flash_data(vha
, (uint32_t *)&pri_aux_image_status
,
7595 ha
->flt_region_aux_img_status_pri
,
7596 sizeof(pri_aux_image_status
) >> 2);
7597 qla27xx_print_image(vha
, "Primary aux image", &pri_aux_image_status
);
7599 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status
)) {
7600 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7601 "Primary aux image signature (%#x) not valid\n",
7602 le32_to_cpu(pri_aux_image_status
.signature
));
7603 goto check_sec_image
;
7606 if (qla27xx_image_status_checksum(&pri_aux_image_status
)) {
7607 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7608 "Primary aux image checksum failed\n");
7609 goto check_sec_image
;
7612 valid_pri_image
= true;
7614 if (pri_aux_image_status
.image_status_mask
& 1) {
7615 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7616 "Primary aux image is active\n");
7617 active_pri_image
= true;
7621 if (!ha
->flt_region_aux_img_status_sec
) {
7622 ql_dbg(ql_dbg_init
, vha
, 0x018a,
7623 "Secondary aux image not addressed\n");
7624 goto check_valid_image
;
7627 qla24xx_read_flash_data(vha
, (uint32_t *)&sec_aux_image_status
,
7628 ha
->flt_region_aux_img_status_sec
,
7629 sizeof(sec_aux_image_status
) >> 2);
7630 qla27xx_print_image(vha
, "Secondary aux image", &sec_aux_image_status
);
7632 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status
)) {
7633 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7634 "Secondary aux image signature (%#x) not valid\n",
7635 le32_to_cpu(sec_aux_image_status
.signature
));
7636 goto check_valid_image
;
7639 if (qla27xx_image_status_checksum(&sec_aux_image_status
)) {
7640 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7641 "Secondary aux image checksum failed\n");
7642 goto check_valid_image
;
7645 valid_sec_image
= true;
7647 if (sec_aux_image_status
.image_status_mask
& 1) {
7648 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7649 "Secondary aux image is active\n");
7650 active_sec_image
= true;
7654 if (valid_pri_image
&& active_pri_image
&&
7655 valid_sec_image
&& active_sec_image
) {
7656 if (qla27xx_compare_image_generation(&pri_aux_image_status
,
7657 &sec_aux_image_status
) >= 0) {
7658 qla28xx_component_status(active_regions
,
7659 &pri_aux_image_status
);
7661 qla28xx_component_status(active_regions
,
7662 &sec_aux_image_status
);
7664 } else if (valid_pri_image
&& active_pri_image
) {
7665 qla28xx_component_status(active_regions
, &pri_aux_image_status
);
7666 } else if (valid_sec_image
&& active_sec_image
) {
7667 qla28xx_component_status(active_regions
, &sec_aux_image_status
);
7670 ql_dbg(ql_dbg_init
, vha
, 0x018f,
7671 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7672 active_regions
->aux
.board_config
,
7673 active_regions
->aux
.vpd_nvram
,
7674 active_regions
->aux
.npiv_config_0_1
,
7675 active_regions
->aux
.npiv_config_2_3
);
7679 qla27xx_get_active_image(struct scsi_qla_host
*vha
,
7680 struct active_regions
*active_regions
)
7682 struct qla_hw_data
*ha
= vha
->hw
;
7683 struct qla27xx_image_status pri_image_status
, sec_image_status
;
7684 bool valid_pri_image
= false, valid_sec_image
= false;
7685 bool active_pri_image
= false, active_sec_image
= false;
7687 if (!ha
->flt_region_img_status_pri
) {
7688 ql_dbg(ql_dbg_init
, vha
, 0x018a, "Primary image not addressed\n");
7689 goto check_sec_image
;
7692 if (qla24xx_read_flash_data(vha
, (uint32_t *)&pri_image_status
,
7693 ha
->flt_region_img_status_pri
, sizeof(pri_image_status
) >> 2) !=
7696 goto check_sec_image
;
7698 qla27xx_print_image(vha
, "Primary image", &pri_image_status
);
7700 if (qla27xx_check_image_status_signature(&pri_image_status
)) {
7701 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7702 "Primary image signature (%#x) not valid\n",
7703 le32_to_cpu(pri_image_status
.signature
));
7704 goto check_sec_image
;
7707 if (qla27xx_image_status_checksum(&pri_image_status
)) {
7708 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7709 "Primary image checksum failed\n");
7710 goto check_sec_image
;
7713 valid_pri_image
= true;
7715 if (pri_image_status
.image_status_mask
& 1) {
7716 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7717 "Primary image is active\n");
7718 active_pri_image
= true;
7722 if (!ha
->flt_region_img_status_sec
) {
7723 ql_dbg(ql_dbg_init
, vha
, 0x018a, "Secondary image not addressed\n");
7724 goto check_valid_image
;
7727 qla24xx_read_flash_data(vha
, (uint32_t *)(&sec_image_status
),
7728 ha
->flt_region_img_status_sec
, sizeof(sec_image_status
) >> 2);
7729 qla27xx_print_image(vha
, "Secondary image", &sec_image_status
);
7731 if (qla27xx_check_image_status_signature(&sec_image_status
)) {
7732 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7733 "Secondary image signature (%#x) not valid\n",
7734 le32_to_cpu(sec_image_status
.signature
));
7735 goto check_valid_image
;
7738 if (qla27xx_image_status_checksum(&sec_image_status
)) {
7739 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7740 "Secondary image checksum failed\n");
7741 goto check_valid_image
;
7744 valid_sec_image
= true;
7746 if (sec_image_status
.image_status_mask
& 1) {
7747 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7748 "Secondary image is active\n");
7749 active_sec_image
= true;
7753 if (valid_pri_image
&& active_pri_image
)
7754 active_regions
->global
= QLA27XX_PRIMARY_IMAGE
;
7756 if (valid_sec_image
&& active_sec_image
) {
7757 if (!active_regions
->global
||
7758 qla27xx_compare_image_generation(
7759 &pri_image_status
, &sec_image_status
) < 0) {
7760 active_regions
->global
= QLA27XX_SECONDARY_IMAGE
;
7764 ql_dbg(ql_dbg_init
, vha
, 0x018f, "active image %s (%u)\n",
7765 active_regions
->global
== QLA27XX_DEFAULT_IMAGE
?
7766 "default (boot/fw)" :
7767 active_regions
->global
== QLA27XX_PRIMARY_IMAGE
?
7769 active_regions
->global
== QLA27XX_SECONDARY_IMAGE
?
7770 "secondary" : "invalid",
7771 active_regions
->global
);
7774 bool qla24xx_risc_firmware_invalid(uint32_t *dword
)
7777 !(dword
[4] | dword
[5] | dword
[6] | dword
[7]) ||
7778 !(~dword
[4] | ~dword
[5] | ~dword
[6] | ~dword
[7]);
7782 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
7786 uint templates
, segments
, fragment
;
7791 uint32_t risc_addr
, risc_size
, risc_attr
= 0;
7792 struct qla_hw_data
*ha
= vha
->hw
;
7793 struct req_que
*req
= ha
->req_q_map
[0];
7794 struct fwdt
*fwdt
= ha
->fwdt
;
7796 ql_dbg(ql_dbg_init
, vha
, 0x008b,
7797 "FW: Loading firmware from flash (%x).\n", faddr
);
7799 dcode
= (uint32_t *)req
->ring
;
7800 qla24xx_read_flash_data(vha
, dcode
, faddr
, 8);
7801 if (qla24xx_risc_firmware_invalid(dcode
)) {
7802 ql_log(ql_log_fatal
, vha
, 0x008c,
7803 "Unable to verify the integrity of flash firmware "
7805 ql_log(ql_log_fatal
, vha
, 0x008d,
7806 "Firmware data: %08x %08x %08x %08x.\n",
7807 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7809 return QLA_FUNCTION_FAILED
;
7812 dcode
= (uint32_t *)req
->ring
;
7814 segments
= FA_RISC_CODE_SEGMENTS
;
7815 for (j
= 0; j
< segments
; j
++) {
7816 ql_dbg(ql_dbg_init
, vha
, 0x008d,
7817 "-> Loading segment %u...\n", j
);
7818 qla24xx_read_flash_data(vha
, dcode
, faddr
, 10);
7819 risc_addr
= be32_to_cpu((__force __be32
)dcode
[2]);
7820 risc_size
= be32_to_cpu((__force __be32
)dcode
[3]);
7822 *srisc_addr
= risc_addr
;
7823 risc_attr
= be32_to_cpu((__force __be32
)dcode
[9]);
7826 dlen
= ha
->fw_transfer_size
>> 2;
7827 for (fragment
= 0; risc_size
; fragment
++) {
7828 if (dlen
> risc_size
)
7831 ql_dbg(ql_dbg_init
, vha
, 0x008e,
7832 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7833 fragment
, risc_addr
, faddr
, dlen
);
7834 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
7835 for (i
= 0; i
< dlen
; i
++)
7836 dcode
[i
] = swab32(dcode
[i
]);
7838 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
, dlen
);
7840 ql_log(ql_log_fatal
, vha
, 0x008f,
7841 "-> Failed load firmware fragment %u.\n",
7843 return QLA_FUNCTION_FAILED
;
7852 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
7855 templates
= (risc_attr
& BIT_9
) ? 2 : 1;
7856 ql_dbg(ql_dbg_init
, vha
, 0x0160, "-> templates = %u\n", templates
);
7857 for (j
= 0; j
< templates
; j
++, fwdt
++) {
7859 vfree(fwdt
->template);
7860 fwdt
->template = NULL
;
7863 dcode
= (uint32_t *)req
->ring
;
7864 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
7865 risc_size
= be32_to_cpu((__force __be32
)dcode
[2]);
7866 ql_dbg(ql_dbg_init
, vha
, 0x0161,
7867 "-> fwdt%u template array at %#x (%#x dwords)\n",
7868 j
, faddr
, risc_size
);
7869 if (!risc_size
|| !~risc_size
) {
7870 ql_dbg(ql_dbg_init
, vha
, 0x0162,
7871 "-> fwdt%u failed to read array\n", j
);
7875 /* skip header and ignore checksum */
7879 ql_dbg(ql_dbg_init
, vha
, 0x0163,
7880 "-> fwdt%u template allocate template %#x words...\n",
7882 fwdt
->template = vmalloc(risc_size
* sizeof(*dcode
));
7883 if (!fwdt
->template) {
7884 ql_log(ql_log_warn
, vha
, 0x0164,
7885 "-> fwdt%u failed allocate template.\n", j
);
7889 dcode
= fwdt
->template;
7890 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
7892 if (!qla27xx_fwdt_template_valid(dcode
)) {
7893 ql_log(ql_log_warn
, vha
, 0x0165,
7894 "-> fwdt%u failed template validate\n", j
);
7898 dlen
= qla27xx_fwdt_template_size(dcode
);
7899 ql_dbg(ql_dbg_init
, vha
, 0x0166,
7900 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7901 j
, dlen
, dlen
/ sizeof(*dcode
));
7902 if (dlen
> risc_size
* sizeof(*dcode
)) {
7903 ql_log(ql_log_warn
, vha
, 0x0167,
7904 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7905 j
, dlen
- risc_size
* sizeof(*dcode
));
7909 fwdt
->length
= dlen
;
7910 ql_dbg(ql_dbg_init
, vha
, 0x0168,
7911 "-> fwdt%u loaded template ok\n", j
);
7913 faddr
+= risc_size
+ 1;
7920 vfree(fwdt
->template);
7921 fwdt
->template = NULL
;
7927 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7930 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7936 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
7937 struct fw_blob
*blob
;
7938 struct qla_hw_data
*ha
= vha
->hw
;
7939 struct req_que
*req
= ha
->req_q_map
[0];
7941 /* Load firmware blob. */
7942 blob
= qla2x00_request_firmware(vha
);
7944 ql_log(ql_log_info
, vha
, 0x0083,
7945 "Firmware image unavailable.\n");
7946 ql_log(ql_log_info
, vha
, 0x0084,
7947 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
7948 return QLA_FUNCTION_FAILED
;
7953 wcode
= (uint16_t *)req
->ring
;
7955 fwcode
= (__force __be16
*)blob
->fw
->data
;
7958 /* Validate firmware image by checking version. */
7959 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
7960 ql_log(ql_log_fatal
, vha
, 0x0085,
7961 "Unable to verify integrity of firmware image (%zd).\n",
7963 goto fail_fw_integrity
;
7965 for (i
= 0; i
< 4; i
++)
7966 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
7967 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
7968 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
7969 wcode
[2] == 0 && wcode
[3] == 0)) {
7970 ql_log(ql_log_fatal
, vha
, 0x0086,
7971 "Unable to verify integrity of firmware image.\n");
7972 ql_log(ql_log_fatal
, vha
, 0x0087,
7973 "Firmware data: %04x %04x %04x %04x.\n",
7974 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
7975 goto fail_fw_integrity
;
7979 while (*seg
&& rval
== QLA_SUCCESS
) {
7981 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
7982 risc_size
= be16_to_cpu(fwcode
[3]);
7984 /* Validate firmware image size. */
7985 fwclen
+= risc_size
* sizeof(uint16_t);
7986 if (blob
->fw
->size
< fwclen
) {
7987 ql_log(ql_log_fatal
, vha
, 0x0088,
7988 "Unable to verify integrity of firmware image "
7989 "(%zd).\n", blob
->fw
->size
);
7990 goto fail_fw_integrity
;
7994 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7995 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
7996 if (wlen
> risc_size
)
7998 ql_dbg(ql_dbg_init
, vha
, 0x0089,
7999 "Loading risc segment@ risc addr %x number of "
8000 "words 0x%x.\n", risc_addr
, wlen
);
8002 for (i
= 0; i
< wlen
; i
++)
8003 wcode
[i
] = swab16((__force u32
)fwcode
[i
]);
8005 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
8008 ql_log(ql_log_fatal
, vha
, 0x008a,
8009 "Failed to load segment %d of firmware.\n",
8026 return QLA_FUNCTION_FAILED
;
8030 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
8033 uint templates
, segments
, fragment
;
8036 uint32_t risc_addr
, risc_size
, risc_attr
= 0;
8039 struct fw_blob
*blob
;
8041 struct qla_hw_data
*ha
= vha
->hw
;
8042 struct req_que
*req
= ha
->req_q_map
[0];
8043 struct fwdt
*fwdt
= ha
->fwdt
;
8045 ql_dbg(ql_dbg_init
, vha
, 0x0090,
8046 "-> FW: Loading via request-firmware.\n");
8048 blob
= qla2x00_request_firmware(vha
);
8050 ql_log(ql_log_warn
, vha
, 0x0092,
8051 "-> Firmware file not found.\n");
8053 return QLA_FUNCTION_FAILED
;
8056 fwcode
= (__force __be32
*)blob
->fw
->data
;
8057 dcode
= (__force
uint32_t *)fwcode
;
8058 if (qla24xx_risc_firmware_invalid(dcode
)) {
8059 ql_log(ql_log_fatal
, vha
, 0x0093,
8060 "Unable to verify integrity of firmware image (%zd).\n",
8062 ql_log(ql_log_fatal
, vha
, 0x0095,
8063 "Firmware data: %08x %08x %08x %08x.\n",
8064 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
8065 return QLA_FUNCTION_FAILED
;
8068 dcode
= (uint32_t *)req
->ring
;
8070 segments
= FA_RISC_CODE_SEGMENTS
;
8071 for (j
= 0; j
< segments
; j
++) {
8072 ql_dbg(ql_dbg_init
, vha
, 0x0096,
8073 "-> Loading segment %u...\n", j
);
8074 risc_addr
= be32_to_cpu(fwcode
[2]);
8075 risc_size
= be32_to_cpu(fwcode
[3]);
8078 *srisc_addr
= risc_addr
;
8079 risc_attr
= be32_to_cpu(fwcode
[9]);
8082 dlen
= ha
->fw_transfer_size
>> 2;
8083 for (fragment
= 0; risc_size
; fragment
++) {
8084 if (dlen
> risc_size
)
8087 ql_dbg(ql_dbg_init
, vha
, 0x0097,
8088 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
8089 fragment
, risc_addr
,
8090 (uint32_t)(fwcode
- (typeof(fwcode
))blob
->fw
->data
),
8093 for (i
= 0; i
< dlen
; i
++)
8094 dcode
[i
] = swab32((__force u32
)fwcode
[i
]);
8096 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
, dlen
);
8098 ql_log(ql_log_fatal
, vha
, 0x0098,
8099 "-> Failed load firmware fragment %u.\n",
8101 return QLA_FUNCTION_FAILED
;
8110 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
8113 templates
= (risc_attr
& BIT_9
) ? 2 : 1;
8114 ql_dbg(ql_dbg_init
, vha
, 0x0170, "-> templates = %u\n", templates
);
8115 for (j
= 0; j
< templates
; j
++, fwdt
++) {
8117 vfree(fwdt
->template);
8118 fwdt
->template = NULL
;
8121 risc_size
= be32_to_cpu(fwcode
[2]);
8122 ql_dbg(ql_dbg_init
, vha
, 0x0171,
8123 "-> fwdt%u template array at %#x (%#x dwords)\n",
8124 j
, (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
),
8126 if (!risc_size
|| !~risc_size
) {
8127 ql_dbg(ql_dbg_init
, vha
, 0x0172,
8128 "-> fwdt%u failed to read array\n", j
);
8132 /* skip header and ignore checksum */
8136 ql_dbg(ql_dbg_init
, vha
, 0x0173,
8137 "-> fwdt%u template allocate template %#x words...\n",
8139 fwdt
->template = vmalloc(risc_size
* sizeof(*dcode
));
8140 if (!fwdt
->template) {
8141 ql_log(ql_log_warn
, vha
, 0x0174,
8142 "-> fwdt%u failed allocate template.\n", j
);
8146 dcode
= fwdt
->template;
8147 for (i
= 0; i
< risc_size
; i
++)
8148 dcode
[i
] = (__force u32
)fwcode
[i
];
8150 if (!qla27xx_fwdt_template_valid(dcode
)) {
8151 ql_log(ql_log_warn
, vha
, 0x0175,
8152 "-> fwdt%u failed template validate\n", j
);
8156 dlen
= qla27xx_fwdt_template_size(dcode
);
8157 ql_dbg(ql_dbg_init
, vha
, 0x0176,
8158 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8159 j
, dlen
, dlen
/ sizeof(*dcode
));
8160 if (dlen
> risc_size
* sizeof(*dcode
)) {
8161 ql_log(ql_log_warn
, vha
, 0x0177,
8162 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8163 j
, dlen
- risc_size
* sizeof(*dcode
));
8167 fwdt
->length
= dlen
;
8168 ql_dbg(ql_dbg_init
, vha
, 0x0178,
8169 "-> fwdt%u loaded template ok\n", j
);
8171 fwcode
+= risc_size
+ 1;
8178 vfree(fwdt
->template);
8179 fwdt
->template = NULL
;
8186 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
8190 if (ql2xfwloadbin
== 1)
8191 return qla81xx_load_risc(vha
, srisc_addr
);
8195 * 1) Firmware via request-firmware interface (.bin file).
8196 * 2) Firmware residing in flash.
8198 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
8199 if (rval
== QLA_SUCCESS
)
8202 return qla24xx_load_risc_flash(vha
, srisc_addr
,
8203 vha
->hw
->flt_region_fw
);
8207 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
8210 struct qla_hw_data
*ha
= vha
->hw
;
8211 struct active_regions active_regions
= { };
8213 if (ql2xfwloadbin
== 2)
8216 /* FW Load priority:
8217 * 1) Firmware residing in flash.
8218 * 2) Firmware via request-firmware interface (.bin file).
8219 * 3) Golden-Firmware residing in flash -- (limited operation).
8222 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
8223 goto try_primary_fw
;
8225 qla27xx_get_active_image(vha
, &active_regions
);
8227 if (active_regions
.global
!= QLA27XX_SECONDARY_IMAGE
)
8228 goto try_primary_fw
;
8230 ql_dbg(ql_dbg_init
, vha
, 0x008b,
8231 "Loading secondary firmware image.\n");
8232 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw_sec
);
8237 ql_dbg(ql_dbg_init
, vha
, 0x008b,
8238 "Loading primary firmware image.\n");
8239 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
8244 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
8245 if (!rval
|| !ha
->flt_region_gold_fw
)
8248 ql_log(ql_log_info
, vha
, 0x0099,
8249 "Attempting to fallback to golden firmware.\n");
8250 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
8254 ql_log(ql_log_info
, vha
, 0x009a, "Need firmware flash update.\n");
8255 ha
->flags
.running_gold_fw
= 1;
8260 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
8263 struct qla_hw_data
*ha
= vha
->hw
;
8265 if (ha
->flags
.pci_channel_io_perm_failure
)
8267 if (!IS_FWI2_CAPABLE(ha
))
8269 if (!ha
->fw_major_version
)
8271 if (!ha
->flags
.fw_started
)
8274 ret
= qla2x00_stop_firmware(vha
);
8275 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
8276 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
8277 ha
->isp_ops
->reset_chip(vha
);
8278 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
8280 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
8282 ql_log(ql_log_info
, vha
, 0x8015,
8283 "Attempting retry of stop-firmware command.\n");
8284 ret
= qla2x00_stop_firmware(vha
);
8288 ha
->flags
.fw_init_done
= 0;
8292 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
8294 int rval
= QLA_SUCCESS
;
8296 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
8297 struct qla_hw_data
*ha
= vha
->hw
;
8298 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
8303 rval
= qla2x00_fw_ready(base_vha
);
8305 if (rval
== QLA_SUCCESS
) {
8306 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8307 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
8310 vha
->flags
.management_server_logged_in
= 0;
8312 /* Login to SNS first */
8313 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
8315 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
8316 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
8317 ql_dbg(ql_dbg_init
, vha
, 0x0120,
8318 "Failed SNS login: loop_id=%x, rval2=%d\n",
8321 ql_dbg(ql_dbg_init
, vha
, 0x0103,
8322 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8323 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8324 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
8325 return (QLA_FUNCTION_FAILED
);
8328 atomic_set(&vha
->loop_down_timer
, 0);
8329 atomic_set(&vha
->loop_state
, LOOP_UP
);
8330 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8331 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
8332 rval
= qla2x00_loop_resync(base_vha
);
8337 /* 84XX Support **************************************************************/
8339 static LIST_HEAD(qla_cs84xx_list
);
8340 static DEFINE_MUTEX(qla_cs84xx_mutex
);
8342 static struct qla_chip_state_84xx
*
8343 qla84xx_get_chip(struct scsi_qla_host
*vha
)
8345 struct qla_chip_state_84xx
*cs84xx
;
8346 struct qla_hw_data
*ha
= vha
->hw
;
8348 mutex_lock(&qla_cs84xx_mutex
);
8350 /* Find any shared 84xx chip. */
8351 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
8352 if (cs84xx
->bus
== ha
->pdev
->bus
) {
8353 kref_get(&cs84xx
->kref
);
8358 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
8362 kref_init(&cs84xx
->kref
);
8363 spin_lock_init(&cs84xx
->access_lock
);
8364 mutex_init(&cs84xx
->fw_update_mutex
);
8365 cs84xx
->bus
= ha
->pdev
->bus
;
8367 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
8369 mutex_unlock(&qla_cs84xx_mutex
);
8374 __qla84xx_chip_release(struct kref
*kref
)
8376 struct qla_chip_state_84xx
*cs84xx
=
8377 container_of(kref
, struct qla_chip_state_84xx
, kref
);
8379 mutex_lock(&qla_cs84xx_mutex
);
8380 list_del(&cs84xx
->list
);
8381 mutex_unlock(&qla_cs84xx_mutex
);
8386 qla84xx_put_chip(struct scsi_qla_host
*vha
)
8388 struct qla_hw_data
*ha
= vha
->hw
;
8391 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
8395 qla84xx_init_chip(scsi_qla_host_t
*vha
)
8399 struct qla_hw_data
*ha
= vha
->hw
;
8401 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
8403 rval
= qla84xx_verify_chip(vha
, status
);
8405 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
8407 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
8411 /* 81XX Support **************************************************************/
8414 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
8417 struct init_cb_81xx
*icb
;
8418 struct nvram_81xx
*nv
;
8420 uint8_t *dptr1
, *dptr2
;
8423 struct qla_hw_data
*ha
= vha
->hw
;
8425 struct active_regions active_regions
= { };
8428 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
8431 /* Determine NVRAM starting address. */
8432 ha
->nvram_size
= sizeof(*nv
);
8433 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
8434 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
8435 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
8437 if (IS_QLA28XX(ha
) || IS_QLA27XX(ha
))
8438 qla28xx_get_aux_images(vha
, &active_regions
);
8440 /* Get VPD data into cache */
8441 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
8443 faddr
= ha
->flt_region_vpd
;
8444 if (IS_QLA28XX(ha
)) {
8445 if (active_regions
.aux
.vpd_nvram
== QLA27XX_SECONDARY_IMAGE
)
8446 faddr
= ha
->flt_region_vpd_sec
;
8447 ql_dbg(ql_dbg_init
, vha
, 0x0110,
8448 "Loading %s nvram image.\n",
8449 active_regions
.aux
.vpd_nvram
== QLA27XX_PRIMARY_IMAGE
?
8450 "primary" : "secondary");
8452 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, faddr
<< 2, ha
->vpd_size
);
8454 /* Get NVRAM data into cache and calculate checksum. */
8455 faddr
= ha
->flt_region_nvram
;
8456 if (IS_QLA28XX(ha
)) {
8457 if (active_regions
.aux
.vpd_nvram
== QLA27XX_SECONDARY_IMAGE
)
8458 faddr
= ha
->flt_region_nvram_sec
;
8460 ql_dbg(ql_dbg_init
, vha
, 0x0110,
8461 "Loading %s nvram image.\n",
8462 active_regions
.aux
.vpd_nvram
== QLA27XX_PRIMARY_IMAGE
?
8463 "primary" : "secondary");
8464 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, faddr
<< 2, ha
->nvram_size
);
8466 dptr
= (__force __le32
*)nv
;
8467 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
8468 chksum
+= le32_to_cpu(*dptr
);
8470 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
8471 "Contents of NVRAM:\n");
8472 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
8473 nv
, ha
->nvram_size
);
8475 /* Bad NVRAM data, set defaults parameters. */
8476 if (chksum
|| memcmp("ISP ", nv
->id
, sizeof(nv
->id
)) ||
8477 le16_to_cpu(nv
->nvram_version
) < ICB_VERSION
) {
8478 /* Reset NVRAM data. */
8479 ql_log(ql_log_info
, vha
, 0x0073,
8480 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8481 chksum
, nv
->id
, le16_to_cpu(nv
->nvram_version
));
8482 ql_dump_buffer(ql_dbg_init
, vha
, 0x0073, nv
, sizeof(*nv
));
8483 ql_log(ql_log_info
, vha
, 0x0074,
8484 "Falling back to functioning (yet invalid -- WWPN) "
8488 * Set default initialization control block.
8490 memset(nv
, 0, ha
->nvram_size
);
8491 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
8492 nv
->version
= cpu_to_le16(ICB_VERSION
);
8493 nv
->frame_payload_size
= cpu_to_le16(2048);
8494 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
8495 nv
->exchange_count
= cpu_to_le16(0);
8496 nv
->port_name
[0] = 0x21;
8497 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
8498 nv
->port_name
[2] = 0x00;
8499 nv
->port_name
[3] = 0xe0;
8500 nv
->port_name
[4] = 0x8b;
8501 nv
->port_name
[5] = 0x1c;
8502 nv
->port_name
[6] = 0x55;
8503 nv
->port_name
[7] = 0x86;
8504 nv
->node_name
[0] = 0x20;
8505 nv
->node_name
[1] = 0x00;
8506 nv
->node_name
[2] = 0x00;
8507 nv
->node_name
[3] = 0xe0;
8508 nv
->node_name
[4] = 0x8b;
8509 nv
->node_name
[5] = 0x1c;
8510 nv
->node_name
[6] = 0x55;
8511 nv
->node_name
[7] = 0x86;
8512 nv
->login_retry_count
= cpu_to_le16(8);
8513 nv
->interrupt_delay_timer
= cpu_to_le16(0);
8514 nv
->login_timeout
= cpu_to_le16(0);
8515 nv
->firmware_options_1
=
8516 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
8517 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
8518 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
8519 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
8520 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
8521 nv
->efi_parameters
= cpu_to_le32(0);
8522 nv
->reset_delay
= 5;
8523 nv
->max_luns_per_target
= cpu_to_le16(128);
8524 nv
->port_down_retry_count
= cpu_to_le16(30);
8525 nv
->link_down_timeout
= cpu_to_le16(180);
8526 nv
->enode_mac
[0] = 0x00;
8527 nv
->enode_mac
[1] = 0xC0;
8528 nv
->enode_mac
[2] = 0xDD;
8529 nv
->enode_mac
[3] = 0x04;
8530 nv
->enode_mac
[4] = 0x05;
8531 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
8536 if (IS_T10_PI_CAPABLE(ha
))
8537 nv
->frame_payload_size
&= cpu_to_le16(~7);
8539 qlt_81xx_config_nvram_stage1(vha
, nv
);
8541 /* Reset Initialization control block */
8542 memset(icb
, 0, ha
->init_cb_size
);
8544 /* Copy 1st segment. */
8545 dptr1
= (uint8_t *)icb
;
8546 dptr2
= (uint8_t *)&nv
->version
;
8547 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
8549 *dptr1
++ = *dptr2
++;
8551 icb
->login_retry_count
= nv
->login_retry_count
;
8553 /* Copy 2nd segment. */
8554 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
8555 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
8556 cnt
= (uint8_t *)&icb
->reserved_5
-
8557 (uint8_t *)&icb
->interrupt_delay_timer
;
8559 *dptr1
++ = *dptr2
++;
8561 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
8562 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8563 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
8564 icb
->enode_mac
[0] = 0x00;
8565 icb
->enode_mac
[1] = 0xC0;
8566 icb
->enode_mac
[2] = 0xDD;
8567 icb
->enode_mac
[3] = 0x04;
8568 icb
->enode_mac
[4] = 0x05;
8569 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
8572 /* Use extended-initialization control block. */
8573 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
8574 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
8576 * Setup driver NVRAM options.
8578 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
8581 qlt_81xx_config_nvram_stage2(vha
, icb
);
8583 /* Use alternate WWN? */
8584 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
8585 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
8586 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
8589 /* Prepare nodename */
8590 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
8592 * Firmware will apply the following mask if the nodename was
8595 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
8596 icb
->node_name
[0] &= 0xF0;
8599 if (IS_QLA28XX(ha
) || IS_QLA27XX(ha
)) {
8600 if ((nv
->enhanced_features
& BIT_7
) == 0)
8601 ha
->flags
.scm_supported_a
= 1;
8604 /* Set host adapter parameters. */
8605 ha
->flags
.disable_risc_code_load
= 0;
8606 ha
->flags
.enable_lip_reset
= 0;
8607 ha
->flags
.enable_lip_full_login
=
8608 le32_to_cpu(nv
->host_p
) & BIT_10
? 1 : 0;
8609 ha
->flags
.enable_target_reset
=
8610 le32_to_cpu(nv
->host_p
) & BIT_11
? 1 : 0;
8611 ha
->flags
.enable_led_scheme
= 0;
8612 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1 : 0;
8614 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
8615 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
8617 /* save HBA serial number */
8618 ha
->serial0
= icb
->port_name
[5];
8619 ha
->serial1
= icb
->port_name
[6];
8620 ha
->serial2
= icb
->port_name
[7];
8621 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
8622 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
8624 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
8626 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
8628 /* Set minimum login_timeout to 4 seconds. */
8629 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
8630 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
8631 if (le16_to_cpu(nv
->login_timeout
) < 4)
8632 nv
->login_timeout
= cpu_to_le16(4);
8633 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
8635 /* Set minimum RATOV to 100 tenths of a second. */
8638 ha
->loop_reset_delay
= nv
->reset_delay
;
8640 /* Link Down Timeout = 0:
8642 * When Port Down timer expires we will start returning
8643 * I/O's to OS with "DID_NO_CONNECT".
8645 * Link Down Timeout != 0:
8647 * The driver waits for the link to come up after link down
8648 * before returning I/Os to OS with "DID_NO_CONNECT".
8650 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
8651 ha
->loop_down_abort_time
=
8652 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
8654 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
8655 ha
->loop_down_abort_time
=
8656 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
8659 /* Need enough time to try and get the port back. */
8660 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
8661 if (qlport_down_retry
)
8662 ha
->port_down_retry_count
= qlport_down_retry
;
8664 /* Set login_retry_count */
8665 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
8666 if (ha
->port_down_retry_count
==
8667 le16_to_cpu(nv
->port_down_retry_count
) &&
8668 ha
->port_down_retry_count
> 3)
8669 ha
->login_retry_count
= ha
->port_down_retry_count
;
8670 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
8671 ha
->login_retry_count
= ha
->port_down_retry_count
;
8672 if (ql2xloginretrycount
)
8673 ha
->login_retry_count
= ql2xloginretrycount
;
8675 /* if not running MSI-X we need handshaking on interrupts */
8676 if (!vha
->hw
->flags
.msix_enabled
&&
8677 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
)))
8678 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
8681 if (!vha
->flags
.init_done
) {
8682 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
8683 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
8684 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
8685 le16_to_cpu(icb
->interrupt_delay_timer
) : 2;
8687 icb
->firmware_options_2
&= cpu_to_le32(
8688 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
8689 vha
->flags
.process_response_queue
= 0;
8690 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
8691 ha
->zio_mode
= QLA_ZIO_MODE_6
;
8693 ql_log(ql_log_info
, vha
, 0x0075,
8694 "ZIO mode %d enabled; timer delay (%d us).\n",
8696 ha
->zio_timer
* 100);
8698 icb
->firmware_options_2
|= cpu_to_le32(
8699 (uint32_t)ha
->zio_mode
);
8700 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
8701 vha
->flags
.process_response_queue
= 1;
8704 /* enable RIDA Format2 */
8705 icb
->firmware_options_3
|= cpu_to_le32(BIT_0
);
8707 /* N2N: driver will initiate Login instead of FW */
8708 icb
->firmware_options_3
|= cpu_to_le32(BIT_8
);
8710 /* Determine NVMe/FCP priority for target ports */
8711 ha
->fc4_type_priority
= qla2xxx_get_fc4_priority(vha
);
8714 ql_log(ql_log_warn
, vha
, 0x0076,
8715 "NVRAM configuration failed.\n");
8721 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
8724 struct qla_hw_data
*ha
= vha
->hw
;
8725 struct scsi_qla_host
*vp
;
8726 unsigned long flags
;
8728 status
= qla2x00_init_rings(vha
);
8730 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8731 ha
->flags
.chip_reset_done
= 1;
8733 status
= qla2x00_fw_ready(vha
);
8735 /* Issue a marker after FW becomes ready. */
8736 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
8737 vha
->flags
.online
= 1;
8738 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8741 /* if no cable then assume it's good */
8742 if ((vha
->device_flags
& DFLG_NO_CABLE
))
8747 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8749 if (!atomic_read(&vha
->loop_down_timer
)) {
8751 * Issue marker command only when we are going
8752 * to start the I/O .
8754 vha
->marker_needed
= 1;
8757 ha
->isp_ops
->enable_intrs(ha
);
8759 ha
->isp_abort_cnt
= 0;
8760 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
8762 /* Update the firmware version */
8763 status
= qla82xx_check_md_needed(vha
);
8766 ha
->flags
.fce_enabled
= 1;
8768 fce_calc_size(ha
->fce_bufs
));
8769 rval
= qla2x00_enable_fce_trace(vha
,
8770 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
8773 ql_log(ql_log_warn
, vha
, 0x8001,
8774 "Unable to reinitialize FCE (%d).\n",
8776 ha
->flags
.fce_enabled
= 0;
8781 memset(ha
->eft
, 0, EFT_SIZE
);
8782 rval
= qla2x00_enable_eft_trace(vha
,
8783 ha
->eft_dma
, EFT_NUM_BUFFERS
);
8785 ql_log(ql_log_warn
, vha
, 0x8010,
8786 "Unable to reinitialize EFT (%d).\n",
8793 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
8794 "qla82xx_restart_isp succeeded.\n");
8796 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8797 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
8799 atomic_inc(&vp
->vref_count
);
8800 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8802 qla2x00_vp_abort_isp(vp
);
8804 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8805 atomic_dec(&vp
->vref_count
);
8808 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8811 ql_log(ql_log_warn
, vha
, 0x8016,
8812 "qla82xx_restart_isp **** FAILED ****.\n");
8819 * qla24xx_get_fcp_prio
8820 * Gets the fcp cmd priority value for the logged in port.
8821 * Looks for a match of the port descriptors within
8822 * each of the fcp prio config entries. If a match is found,
8823 * the tag (priority) value is returned.
8826 * vha = scsi host structure pointer.
8827 * fcport = port structure pointer.
8830 * non-zero (if found)
8837 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8840 uint8_t pid_match
, wwn_match
;
8842 uint32_t pid1
, pid2
;
8843 uint64_t wwn1
, wwn2
;
8844 struct qla_fcp_prio_entry
*pri_entry
;
8845 struct qla_hw_data
*ha
= vha
->hw
;
8847 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
8851 entries
= ha
->fcp_prio_cfg
->num_entries
;
8852 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
8854 for (i
= 0; i
< entries
; i
++) {
8855 pid_match
= wwn_match
= 0;
8857 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
8862 /* check source pid for a match */
8863 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
8864 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
8865 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
8866 if (pid1
== INVALID_PORT_ID
)
8868 else if (pid1
== pid2
)
8872 /* check destination pid for a match */
8873 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
8874 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
8875 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
8876 if (pid1
== INVALID_PORT_ID
)
8878 else if (pid1
== pid2
)
8882 /* check source WWN for a match */
8883 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
8884 wwn1
= wwn_to_u64(vha
->port_name
);
8885 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
8886 if (wwn2
== (uint64_t)-1)
8888 else if (wwn1
== wwn2
)
8892 /* check destination WWN for a match */
8893 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
8894 wwn1
= wwn_to_u64(fcport
->port_name
);
8895 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
8896 if (wwn2
== (uint64_t)-1)
8898 else if (wwn1
== wwn2
)
8902 if (pid_match
== 2 || wwn_match
== 2) {
8903 /* Found a matching entry */
8904 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
8905 priority
= pri_entry
->tag
;
8916 * qla24xx_update_fcport_fcp_prio
8917 * Activates fcp priority for the logged in fc port
8920 * vha = scsi host structure pointer.
8921 * fcp = port structure pointer.
8924 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8930 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8936 if (fcport
->port_type
!= FCT_TARGET
||
8937 fcport
->loop_id
== FC_NO_LOOP_ID
)
8938 return QLA_FUNCTION_FAILED
;
8940 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
8942 return QLA_FUNCTION_FAILED
;
8944 if (IS_P3P_TYPE(vha
->hw
)) {
8945 fcport
->fcp_prio
= priority
& 0xf;
8949 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
8950 if (ret
== QLA_SUCCESS
) {
8951 if (fcport
->fcp_prio
!= priority
)
8952 ql_dbg(ql_dbg_user
, vha
, 0x709e,
8953 "Updated FCP_CMND priority - value=%d loop_id=%d "
8954 "port_id=%02x%02x%02x.\n", priority
,
8955 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
8956 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
8957 fcport
->fcp_prio
= priority
& 0xf;
8959 ql_dbg(ql_dbg_user
, vha
, 0x704f,
8960 "Unable to update FCP_CMND priority - ret=0x%x for "
8961 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
8962 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
8963 fcport
->d_id
.b
.al_pa
);
8968 * qla24xx_update_all_fcp_prio
8969 * Activates fcp priority for all the logged in ports
8972 * ha = adapter block pointer.
8975 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8981 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
8986 ret
= QLA_FUNCTION_FAILED
;
8987 /* We need to set priority for all logged in ports */
8988 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
8989 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);
8994 struct qla_qpair
*qla2xxx_create_qpair(struct scsi_qla_host
*vha
, int qos
,
8995 int vp_idx
, bool startqp
)
9000 struct qla_hw_data
*ha
= vha
->hw
;
9001 uint16_t qpair_id
= 0;
9002 struct qla_qpair
*qpair
= NULL
;
9003 struct qla_msix_entry
*msix
;
9005 if (!(ha
->fw_attributes
& BIT_6
) || !ha
->flags
.msix_enabled
) {
9006 ql_log(ql_log_warn
, vha
, 0x00181,
9007 "FW/Driver is not multi-queue capable.\n");
9011 if (ql2xmqsupport
|| ql2xnvmeenable
) {
9012 qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
9013 if (qpair
== NULL
) {
9014 ql_log(ql_log_warn
, vha
, 0x0182,
9015 "Failed to allocate memory for queue pair.\n");
9019 qpair
->hw
= vha
->hw
;
9021 qpair
->qp_lock_ptr
= &qpair
->qp_lock
;
9022 spin_lock_init(&qpair
->qp_lock
);
9023 qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
9025 /* Assign available que pair id */
9026 mutex_lock(&ha
->mq_lock
);
9027 qpair_id
= find_first_zero_bit(ha
->qpair_qid_map
, ha
->max_qpairs
);
9028 if (ha
->num_qpairs
>= ha
->max_qpairs
) {
9029 mutex_unlock(&ha
->mq_lock
);
9030 ql_log(ql_log_warn
, vha
, 0x0183,
9031 "No resources to create additional q pair.\n");
9035 set_bit(qpair_id
, ha
->qpair_qid_map
);
9036 ha
->queue_pair_map
[qpair_id
] = qpair
;
9037 qpair
->id
= qpair_id
;
9038 qpair
->vp_idx
= vp_idx
;
9039 qpair
->fw_started
= ha
->flags
.fw_started
;
9040 INIT_LIST_HEAD(&qpair
->hints_list
);
9041 qpair
->chip_reset
= ha
->base_qpair
->chip_reset
;
9042 qpair
->enable_class_2
= ha
->base_qpair
->enable_class_2
;
9043 qpair
->enable_explicit_conf
=
9044 ha
->base_qpair
->enable_explicit_conf
;
9046 for (i
= 0; i
< ha
->msix_count
; i
++) {
9047 msix
= &ha
->msix_entries
[i
];
9051 ql_dbg(ql_dbg_multiq
, vha
, 0xc00f,
9052 "Vector %x selected for qpair\n", msix
->vector
);
9056 ql_log(ql_log_warn
, vha
, 0x0184,
9057 "Out of MSI-X vectors!.\n");
9061 qpair
->msix
->in_use
= 1;
9062 list_add_tail(&qpair
->qp_list_elem
, &vha
->qp_list
);
9063 qpair
->pdev
= ha
->pdev
;
9064 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
) || IS_QLA28XX(ha
))
9065 qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
9067 mutex_unlock(&ha
->mq_lock
);
9069 /* Create response queue first */
9070 rsp_id
= qla25xx_create_rsp_que(ha
, 0, 0, 0, qpair
, startqp
);
9072 ql_log(ql_log_warn
, vha
, 0x0185,
9073 "Failed to create response queue.\n");
9077 qpair
->rsp
= ha
->rsp_q_map
[rsp_id
];
9079 /* Create request queue */
9080 req_id
= qla25xx_create_req_que(ha
, 0, vp_idx
, 0, rsp_id
, qos
,
9083 ql_log(ql_log_warn
, vha
, 0x0186,
9084 "Failed to create request queue.\n");
9088 qpair
->req
= ha
->req_q_map
[req_id
];
9089 qpair
->rsp
->req
= qpair
->req
;
9090 qpair
->rsp
->qpair
= qpair
;
9091 /* init qpair to this cpu. Will adjust at run time. */
9092 qla_cpu_update(qpair
, smp_processor_id());
9094 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
9095 if (ha
->fw_attributes
& BIT_4
)
9096 qpair
->difdix_supported
= 1;
9099 qpair
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
9100 if (!qpair
->srb_mempool
) {
9101 ql_log(ql_log_warn
, vha
, 0xd036,
9102 "Failed to create srb mempool for qpair %d\n",
9107 /* Mark as online */
9110 if (!vha
->flags
.qpairs_available
)
9111 vha
->flags
.qpairs_available
= 1;
9113 ql_dbg(ql_dbg_multiq
, vha
, 0xc00d,
9114 "Request/Response queue pair created, id %d\n",
9116 ql_dbg(ql_dbg_init
, vha
, 0x0187,
9117 "Request/Response queue pair created, id %d\n",
9124 qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
9126 mutex_lock(&ha
->mq_lock
);
9127 qpair
->msix
->in_use
= 0;
9128 list_del(&qpair
->qp_list_elem
);
9129 if (list_empty(&vha
->qp_list
))
9130 vha
->flags
.qpairs_available
= 0;
9132 ha
->queue_pair_map
[qpair_id
] = NULL
;
9133 clear_bit(qpair_id
, ha
->qpair_qid_map
);
9135 mutex_unlock(&ha
->mq_lock
);
9141 int qla2xxx_delete_qpair(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
)
9143 int ret
= QLA_FUNCTION_FAILED
;
9144 struct qla_hw_data
*ha
= qpair
->hw
;
9146 qpair
->delete_in_progress
= 1;
9148 ret
= qla25xx_delete_req_que(vha
, qpair
->req
);
9149 if (ret
!= QLA_SUCCESS
)
9152 ret
= qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
9153 if (ret
!= QLA_SUCCESS
)
9156 mutex_lock(&ha
->mq_lock
);
9157 ha
->queue_pair_map
[qpair
->id
] = NULL
;
9158 clear_bit(qpair
->id
, ha
->qpair_qid_map
);
9160 list_del(&qpair
->qp_list_elem
);
9161 if (list_empty(&vha
->qp_list
)) {
9162 vha
->flags
.qpairs_available
= 0;
9163 vha
->flags
.qpairs_req_created
= 0;
9164 vha
->flags
.qpairs_rsp_created
= 0;
9166 mempool_destroy(qpair
->srb_mempool
);
9168 mutex_unlock(&ha
->mq_lock
);