2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
20 #include "qla_target.h"
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
26 static int qla2x00_setup_chip(scsi_qla_host_t
*);
27 static int qla2x00_fw_ready(scsi_qla_host_t
*);
28 static int qla2x00_configure_hba(scsi_qla_host_t
*);
29 static int qla2x00_configure_loop(scsi_qla_host_t
*);
30 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
31 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
32 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*);
33 static int qla2x00_restart_isp(scsi_qla_host_t
*);
35 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
36 static int qla84xx_init_chip(scsi_qla_host_t
*);
37 static int qla25xx_init_queues(struct qla_hw_data
*);
38 static int qla24xx_post_prli_work(struct scsi_qla_host
*, fc_port_t
*);
39 static void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
,
40 struct event_arg
*ea
);
41 static void qla24xx_handle_prli_done_event(struct scsi_qla_host
*,
43 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*, struct event_arg
*);
45 /* SRB Extensions ---------------------------------------------------------- */
48 qla2x00_sp_timeout(struct timer_list
*t
)
50 srb_t
*sp
= from_timer(sp
, t
, u
.iocb_cmd
.timer
);
51 struct srb_iocb
*iocb
;
53 WARN_ON(irqs_disabled());
54 iocb
= &sp
->u
.iocb_cmd
;
58 void qla2x00_sp_free(srb_t
*sp
)
60 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
62 del_timer(&iocb
->timer
);
66 /* Asynchronous Login/Logout Routines -------------------------------------- */
69 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
72 struct qla_hw_data
*ha
= vha
->hw
;
74 /* Firmware should use switch negotiated r_a_tov for timeout. */
75 tmo
= ha
->r_a_tov
/ 10 * 2;
77 tmo
= FX00_DEF_RATOV
* 2;
78 } else if (!IS_FWI2_CAPABLE(ha
)) {
80 * Except for earlier ISPs where the timeout is seeded from the
81 * initialization control block.
83 tmo
= ha
->login_timeout
;
88 static void qla24xx_abort_iocb_timeout(void *data
)
91 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
92 struct qla_qpair
*qpair
= sp
->qpair
;
97 ql_dbg(ql_dbg_async
, sp
->vha
, 0x507c,
98 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
99 sp
->cmd_sp
->handle
, sp
->cmd_sp
->type
,
100 sp
->handle
, sp
->type
);
102 ql_dbg(ql_dbg_async
, sp
->vha
, 0x507c,
103 "Abort timeout 2 - hdl=%x, type=%x\n",
104 sp
->handle
, sp
->type
);
106 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
107 for (handle
= 1; handle
< qpair
->req
->num_outstanding_cmds
; handle
++) {
108 if (sp
->cmd_sp
&& (qpair
->req
->outstanding_cmds
[handle
] ==
110 qpair
->req
->outstanding_cmds
[handle
] = NULL
;
112 /* removing the abort */
113 if (qpair
->req
->outstanding_cmds
[handle
] == sp
) {
114 qpair
->req
->outstanding_cmds
[handle
] = NULL
;
118 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
121 sp
->cmd_sp
->done(sp
->cmd_sp
, QLA_OS_TIMER_EXPIRED
);
123 abt
->u
.abt
.comp_status
= CS_TIMEOUT
;
124 sp
->done(sp
, QLA_OS_TIMER_EXPIRED
);
127 static void qla24xx_abort_sp_done(srb_t
*sp
, int res
)
129 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
131 del_timer(&sp
->u
.iocb_cmd
.timer
);
132 if (sp
->flags
& SRB_WAKEUP_ON_COMP
)
133 complete(&abt
->u
.abt
.comp
);
138 int qla24xx_async_abort_cmd(srb_t
*cmd_sp
, bool wait
)
140 scsi_qla_host_t
*vha
= cmd_sp
->vha
;
141 struct srb_iocb
*abt_iocb
;
143 int rval
= QLA_FUNCTION_FAILED
;
145 sp
= qla2xxx_get_qpair_sp(cmd_sp
->vha
, cmd_sp
->qpair
, cmd_sp
->fcport
,
150 abt_iocb
= &sp
->u
.iocb_cmd
;
151 sp
->type
= SRB_ABT_CMD
;
153 sp
->qpair
= cmd_sp
->qpair
;
156 sp
->flags
= SRB_WAKEUP_ON_COMP
;
158 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
159 init_completion(&abt_iocb
->u
.abt
.comp
);
160 /* FW can send 2 x ABTS's timeout/20s */
161 qla2x00_init_timer(sp
, 42);
163 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
164 abt_iocb
->u
.abt
.req_que_no
= cpu_to_le16(cmd_sp
->qpair
->req
->id
);
166 sp
->done
= qla24xx_abort_sp_done
;
168 ql_dbg(ql_dbg_async
, vha
, 0x507c,
169 "Abort command issued - hdl=%x, type=%x\n", cmd_sp
->handle
,
172 rval
= qla2x00_start_sp(sp
);
173 if (rval
!= QLA_SUCCESS
) {
179 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
180 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
181 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
189 qla2x00_async_iocb_timeout(void *data
)
192 fc_port_t
*fcport
= sp
->fcport
;
193 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
198 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
199 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
200 sp
->name
, sp
->handle
, fcport
->d_id
.b24
, fcport
->port_name
);
202 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
204 pr_info("Async-%s timeout - hdl=%x.\n",
205 sp
->name
, sp
->handle
);
210 rc
= qla24xx_async_abort_cmd(sp
, false);
212 /* Retry as needed. */
213 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
214 lio
->u
.logio
.data
[1] =
215 lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
216 QLA_LOGIO_LOGIN_RETRIED
: 0;
217 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
218 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
;
220 if (sp
->qpair
->req
->outstanding_cmds
[h
] ==
222 sp
->qpair
->req
->outstanding_cmds
[h
] =
227 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
228 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
232 case SRB_CT_PTHRU_CMD
:
239 rc
= qla24xx_async_abort_cmd(sp
, false);
241 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
242 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
;
244 if (sp
->qpair
->req
->outstanding_cmds
[h
] ==
246 sp
->qpair
->req
->outstanding_cmds
[h
] =
251 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
252 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
258 static void qla2x00_async_login_sp_done(srb_t
*sp
, int res
)
260 struct scsi_qla_host
*vha
= sp
->vha
;
261 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
264 ql_dbg(ql_dbg_disc
, vha
, 0x20dd,
265 "%s %8phC res %d \n", __func__
, sp
->fcport
->port_name
, res
);
267 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
269 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
270 memset(&ea
, 0, sizeof(ea
));
271 ea
.fcport
= sp
->fcport
;
272 ea
.data
[0] = lio
->u
.logio
.data
[0];
273 ea
.data
[1] = lio
->u
.logio
.data
[1];
274 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
275 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
277 qla24xx_handle_plogi_done_event(vha
, &ea
);
284 fcport_is_smaller(fc_port_t
*fcport
)
286 if (wwn_to_u64(fcport
->port_name
) <
287 wwn_to_u64(fcport
->vha
->port_name
))
294 fcport_is_bigger(fc_port_t
*fcport
)
296 return !fcport_is_smaller(fcport
);
300 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
304 struct srb_iocb
*lio
;
305 int rval
= QLA_FUNCTION_FAILED
;
307 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
) ||
308 fcport
->loop_id
== FC_NO_LOOP_ID
) {
309 ql_log(ql_log_warn
, vha
, 0xffff,
310 "%s: %8phC - not sending command.\n",
311 __func__
, fcport
->port_name
);
315 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
319 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_PEND
);
320 fcport
->flags
|= FCF_ASYNC_SENT
;
321 fcport
->logout_completed
= 0;
323 sp
->type
= SRB_LOGIN_CMD
;
325 sp
->gen1
= fcport
->rscn_gen
;
326 sp
->gen2
= fcport
->login_gen
;
328 lio
= &sp
->u
.iocb_cmd
;
329 lio
->timeout
= qla2x00_async_iocb_timeout
;
330 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
332 sp
->done
= qla2x00_async_login_sp_done
;
333 if (N2N_TOPO(fcport
->vha
->hw
) && fcport_is_bigger(fcport
))
334 lio
->u
.logio
.flags
|= SRB_LOGIN_PRLI_ONLY
;
336 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
338 if (NVME_TARGET(vha
->hw
, fcport
))
339 lio
->u
.logio
.flags
|= SRB_LOGIN_SKIP_PRLI
;
341 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
342 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
343 "retries=%d.\n", fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
344 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
345 fcport
->login_retry
);
347 rval
= qla2x00_start_sp(sp
);
348 if (rval
!= QLA_SUCCESS
) {
349 fcport
->flags
|= FCF_LOGIN_NEEDED
;
350 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
358 fcport
->flags
&= ~FCF_ASYNC_SENT
;
360 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
364 static void qla2x00_async_logout_sp_done(srb_t
*sp
, int res
)
366 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
367 sp
->fcport
->login_gen
++;
368 qlt_logo_completion_handler(sp
->fcport
, res
);
373 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
376 struct srb_iocb
*lio
;
377 int rval
= QLA_FUNCTION_FAILED
;
379 fcport
->flags
|= FCF_ASYNC_SENT
;
380 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
384 sp
->type
= SRB_LOGOUT_CMD
;
387 lio
= &sp
->u
.iocb_cmd
;
388 lio
->timeout
= qla2x00_async_iocb_timeout
;
389 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
391 sp
->done
= qla2x00_async_logout_sp_done
;
393 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
394 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
395 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
396 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
399 rval
= qla2x00_start_sp(sp
);
400 if (rval
!= QLA_SUCCESS
)
407 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
412 qla2x00_async_prlo_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
415 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
416 /* Don't re-login in target mode */
417 if (!fcport
->tgt_session
)
418 qla2x00_mark_device_lost(vha
, fcport
, 1);
419 qlt_logo_completion_handler(fcport
, data
[0]);
422 static void qla2x00_async_prlo_sp_done(srb_t
*sp
, int res
)
424 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
425 struct scsi_qla_host
*vha
= sp
->vha
;
427 sp
->fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
428 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
429 qla2x00_post_async_prlo_done_work(sp
->fcport
->vha
, sp
->fcport
,
435 qla2x00_async_prlo(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
438 struct srb_iocb
*lio
;
441 rval
= QLA_FUNCTION_FAILED
;
442 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
446 sp
->type
= SRB_PRLO_CMD
;
449 lio
= &sp
->u
.iocb_cmd
;
450 lio
->timeout
= qla2x00_async_iocb_timeout
;
451 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
453 sp
->done
= qla2x00_async_prlo_sp_done
;
455 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
456 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
457 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
458 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
460 rval
= qla2x00_start_sp(sp
);
461 if (rval
!= QLA_SUCCESS
)
469 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
474 void qla24xx_handle_adisc_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
476 struct fc_port
*fcport
= ea
->fcport
;
478 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
479 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
480 __func__
, fcport
->port_name
, fcport
->disc_state
,
481 fcport
->fw_login_state
, ea
->rc
, fcport
->login_gen
, ea
->sp
->gen2
,
482 fcport
->rscn_gen
, ea
->sp
->gen1
, fcport
->loop_id
);
484 WARN_ONCE(!qla2xxx_is_valid_mbs(ea
->data
[0]), "mbs: %#x\n",
487 if (ea
->data
[0] != MBS_COMMAND_COMPLETE
) {
488 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
489 "%s %8phC: adisc fail: post delete\n",
490 __func__
, ea
->fcport
->port_name
);
491 /* deleted = 0 & logout_on_delete = force fw cleanup */
493 fcport
->logout_on_delete
= 1;
494 qlt_schedule_sess_for_deletion(ea
->fcport
);
498 if (ea
->fcport
->disc_state
== DSC_DELETE_PEND
)
501 if (ea
->sp
->gen2
!= ea
->fcport
->login_gen
) {
502 /* target side must have changed it. */
503 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
504 "%s %8phC generation changed\n",
505 __func__
, ea
->fcport
->port_name
);
507 } else if (ea
->sp
->gen1
!= ea
->fcport
->rscn_gen
) {
508 qla_rscn_replay(fcport
);
509 qlt_schedule_sess_for_deletion(fcport
);
513 __qla24xx_handle_gpdb_event(vha
, ea
);
516 static int qla_post_els_plogi_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
518 struct qla_work_evt
*e
;
520 e
= qla2x00_alloc_work(vha
, QLA_EVT_ELS_PLOGI
);
522 return QLA_FUNCTION_FAILED
;
524 e
->u
.fcport
.fcport
= fcport
;
525 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
526 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_PEND
);
527 return qla2x00_post_work(vha
, e
);
530 static void qla2x00_async_adisc_sp_done(srb_t
*sp
, int res
)
532 struct scsi_qla_host
*vha
= sp
->vha
;
534 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
536 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
537 "Async done-%s res %x %8phC\n",
538 sp
->name
, res
, sp
->fcport
->port_name
);
540 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
542 memset(&ea
, 0, sizeof(ea
));
544 ea
.data
[0] = lio
->u
.logio
.data
[0];
545 ea
.data
[1] = lio
->u
.logio
.data
[1];
546 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
547 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
548 ea
.fcport
= sp
->fcport
;
551 qla24xx_handle_adisc_event(vha
, &ea
);
557 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
561 struct srb_iocb
*lio
;
562 int rval
= QLA_FUNCTION_FAILED
;
564 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
567 fcport
->flags
|= FCF_ASYNC_SENT
;
568 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
572 sp
->type
= SRB_ADISC_CMD
;
575 lio
= &sp
->u
.iocb_cmd
;
576 lio
->timeout
= qla2x00_async_iocb_timeout
;
577 sp
->gen1
= fcport
->rscn_gen
;
578 sp
->gen2
= fcport
->login_gen
;
579 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
581 sp
->done
= qla2x00_async_adisc_sp_done
;
582 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
583 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
585 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
586 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
587 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
, fcport
->port_name
);
589 rval
= qla2x00_start_sp(sp
);
590 if (rval
!= QLA_SUCCESS
)
598 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
599 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
603 static bool qla2x00_is_reserved_id(scsi_qla_host_t
*vha
, uint16_t loop_id
)
605 struct qla_hw_data
*ha
= vha
->hw
;
607 if (IS_FWI2_CAPABLE(ha
))
608 return loop_id
> NPH_LAST_HANDLE
;
610 return (loop_id
> ha
->max_loop_id
&& loop_id
< SNS_FIRST_LOOP_ID
) ||
611 loop_id
== MANAGEMENT_SERVER
|| loop_id
== BROADCAST
;
615 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
616 * @vha: adapter state pointer.
617 * @dev: port structure pointer.
620 * qla2x00 local function return status code.
625 static int qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
628 struct qla_hw_data
*ha
= vha
->hw
;
629 unsigned long flags
= 0;
633 spin_lock_irqsave(&ha
->vport_slock
, flags
);
635 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
, LOOPID_MAP_SIZE
);
636 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
637 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
638 dev
->loop_id
= FC_NO_LOOP_ID
;
639 rval
= QLA_FUNCTION_FAILED
;
641 set_bit(dev
->loop_id
, ha
->loop_id_map
);
643 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
645 if (rval
== QLA_SUCCESS
)
646 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
647 "Assigning new loopid=%x, portid=%x.\n",
648 dev
->loop_id
, dev
->d_id
.b24
);
650 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
651 "No loop_id's available, portid=%x.\n",
657 void qla2x00_clear_loop_id(fc_port_t
*fcport
)
659 struct qla_hw_data
*ha
= fcport
->vha
->hw
;
661 if (fcport
->loop_id
== FC_NO_LOOP_ID
||
662 qla2x00_is_reserved_id(fcport
->vha
, fcport
->loop_id
))
665 clear_bit(fcport
->loop_id
, ha
->loop_id_map
);
666 fcport
->loop_id
= FC_NO_LOOP_ID
;
669 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t
*vha
,
670 struct event_arg
*ea
)
672 fc_port_t
*fcport
, *conflict_fcport
;
673 struct get_name_list_extended
*e
;
674 u16 i
, n
, found
= 0, loop_id
;
678 u8 current_login_state
, nvme_cls
;
681 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
682 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
683 __func__
, fcport
->port_name
, fcport
->disc_state
,
684 fcport
->fw_login_state
, ea
->rc
,
685 fcport
->login_gen
, fcport
->last_login_gen
,
686 fcport
->rscn_gen
, fcport
->last_rscn_gen
, vha
->loop_id
);
688 if (fcport
->disc_state
== DSC_DELETE_PEND
)
691 if (ea
->rc
) { /* rval */
692 if (fcport
->login_retry
== 0) {
693 ql_dbg(ql_dbg_disc
, vha
, 0x20de,
694 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
695 fcport
->port_name
, fcport
->login_retry
);
700 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
701 qla_rscn_replay(fcport
);
702 qlt_schedule_sess_for_deletion(fcport
);
704 } else if (fcport
->last_login_gen
!= fcport
->login_gen
) {
705 ql_dbg(ql_dbg_disc
, vha
, 0x20e0,
706 "%s %8phC login gen changed\n",
707 __func__
, fcport
->port_name
);
711 n
= ea
->data
[0] / sizeof(struct get_name_list_extended
);
713 ql_dbg(ql_dbg_disc
, vha
, 0x20e1,
714 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
715 __func__
, __LINE__
, fcport
->port_name
, n
,
716 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
717 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
);
719 for (i
= 0; i
< n
; i
++) {
721 wwn
= wwn_to_u64(e
->port_name
);
722 id
.b
.domain
= e
->port_id
[2];
723 id
.b
.area
= e
->port_id
[1];
724 id
.b
.al_pa
= e
->port_id
[0];
727 if (memcmp((u8
*)&wwn
, fcport
->port_name
, WWN_SIZE
))
730 if (IS_SW_RESV_ADDR(id
))
735 loop_id
= le16_to_cpu(e
->nport_handle
);
736 loop_id
= (loop_id
& 0x7fff);
737 nvme_cls
= e
->current_login_state
>> 4;
738 current_login_state
= e
->current_login_state
& 0xf;
740 if (PRLI_PHASE(nvme_cls
)) {
741 current_login_state
= nvme_cls
;
742 fcport
->fc4_type
&= ~FS_FC4TYPE_FCP
;
743 fcport
->fc4_type
|= FS_FC4TYPE_NVME
;
744 } else if (PRLI_PHASE(current_login_state
)) {
745 fcport
->fc4_type
|= FS_FC4TYPE_FCP
;
746 fcport
->fc4_type
&= ~FS_FC4TYPE_NVME
;
749 ql_dbg(ql_dbg_disc
, vha
, 0x20e2,
750 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
751 __func__
, fcport
->port_name
,
752 e
->current_login_state
, fcport
->fw_login_state
,
753 fcport
->fc4_type
, id
.b24
, fcport
->d_id
.b24
,
754 loop_id
, fcport
->loop_id
);
756 switch (fcport
->disc_state
) {
757 case DSC_DELETE_PEND
:
761 if ((id
.b24
!= fcport
->d_id
.b24
&&
763 fcport
->loop_id
!= FC_NO_LOOP_ID
) ||
764 (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
765 fcport
->loop_id
!= loop_id
)) {
766 ql_dbg(ql_dbg_disc
, vha
, 0x20e3,
767 "%s %d %8phC post del sess\n",
768 __func__
, __LINE__
, fcport
->port_name
);
769 if (fcport
->n2n_flag
)
770 fcport
->d_id
.b24
= 0;
771 qlt_schedule_sess_for_deletion(fcport
);
777 fcport
->loop_id
= loop_id
;
778 if (fcport
->n2n_flag
)
779 fcport
->d_id
.b24
= id
.b24
;
781 wwn
= wwn_to_u64(fcport
->port_name
);
782 qlt_find_sess_invalidate_other(vha
, wwn
,
783 id
, loop_id
, &conflict_fcport
);
785 if (conflict_fcport
) {
787 * Another share fcport share the same loop_id &
788 * nport id. Conflict fcport needs to finish
789 * cleanup before this fcport can proceed to login.
791 conflict_fcport
->conflict
= fcport
;
792 fcport
->login_pause
= 1;
795 switch (vha
->hw
->current_topology
) {
797 switch (current_login_state
) {
798 case DSC_LS_PRLI_COMP
:
799 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
,
800 vha
, 0x20e4, "%s %d %8phC post gpdb\n",
801 __func__
, __LINE__
, fcport
->port_name
);
803 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
804 fcport
->port_type
= FCT_INITIATOR
;
806 fcport
->port_type
= FCT_TARGET
;
807 data
[0] = data
[1] = 0;
808 qla2x00_post_async_adisc_work(vha
, fcport
,
811 case DSC_LS_PORT_UNAVAIL
:
813 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
814 qla2x00_find_new_loop_id(vha
, fcport
);
815 fcport
->fw_login_state
=
818 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
819 "%s %d %8phC\n", __func__
, __LINE__
,
821 qla24xx_fcport_handle_login(vha
, fcport
);
826 fcport
->fw_login_state
= current_login_state
;
828 switch (current_login_state
) {
829 case DSC_LS_PRLI_PEND
:
831 * In the middle of PRLI. Let it finish.
832 * Allow relogin code to recheck state again
833 * with GNL. Push disc_state back to DELETED
834 * so GNL can go out again
836 qla2x00_set_fcport_disc_state(fcport
,
839 case DSC_LS_PRLI_COMP
:
840 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
841 fcport
->port_type
= FCT_INITIATOR
;
843 fcport
->port_type
= FCT_TARGET
;
845 data
[0] = data
[1] = 0;
846 qla2x00_post_async_adisc_work(vha
, fcport
,
849 case DSC_LS_PLOGI_COMP
:
850 if (fcport_is_bigger(fcport
)) {
851 /* local adapter is smaller */
852 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
853 qla2x00_clear_loop_id(fcport
);
855 fcport
->loop_id
= loop_id
;
856 qla24xx_fcport_handle_login(vha
,
862 if (fcport_is_smaller(fcport
)) {
863 /* local adapter is bigger */
864 if (fcport
->loop_id
!= FC_NO_LOOP_ID
)
865 qla2x00_clear_loop_id(fcport
);
867 fcport
->loop_id
= loop_id
;
868 qla24xx_fcport_handle_login(vha
,
874 } /* switch (ha->current_topology) */
878 switch (vha
->hw
->current_topology
) {
881 for (i
= 0; i
< n
; i
++) {
883 id
.b
.domain
= e
->port_id
[0];
884 id
.b
.area
= e
->port_id
[1];
885 id
.b
.al_pa
= e
->port_id
[2];
887 loop_id
= le16_to_cpu(e
->nport_handle
);
889 if (fcport
->d_id
.b24
== id
.b24
) {
891 qla2x00_find_fcport_by_wwpn(vha
,
893 if (conflict_fcport
) {
894 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
,
896 "%s %d %8phC post del sess\n",
898 conflict_fcport
->port_name
);
899 qlt_schedule_sess_for_deletion
904 * FW already picked this loop id for
907 if (fcport
->loop_id
== loop_id
)
908 fcport
->loop_id
= FC_NO_LOOP_ID
;
910 qla24xx_fcport_handle_login(vha
, fcport
);
913 qla2x00_set_fcport_disc_state(fcport
, DSC_DELETED
);
914 if (time_after_eq(jiffies
, fcport
->dm_login_expire
)) {
915 if (fcport
->n2n_link_reset_cnt
< 2) {
916 fcport
->n2n_link_reset_cnt
++;
918 * remote port is not sending PLOGI.
919 * Reset link to kick start his state
922 set_bit(N2N_LINK_RESET
,
925 if (fcport
->n2n_chip_reset
< 1) {
926 ql_log(ql_log_info
, vha
, 0x705d,
927 "Chip reset to bring laser down");
928 set_bit(ISP_ABORT_NEEDED
,
930 fcport
->n2n_chip_reset
++;
932 ql_log(ql_log_info
, vha
, 0x705d,
933 "Remote port %8ph is not coming back\n",
935 fcport
->scan_state
= 0;
938 qla2xxx_wake_dpc(vha
);
941 * report port suppose to do PLOGI. Give him
942 * more time. FW will catch it.
944 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
953 static void qla24xx_async_gnl_sp_done(srb_t
*sp
, int res
)
955 struct scsi_qla_host
*vha
= sp
->vha
;
957 struct fc_port
*fcport
= NULL
, *tf
;
958 u16 i
, n
= 0, loop_id
;
960 struct get_name_list_extended
*e
;
965 ql_dbg(ql_dbg_disc
, vha
, 0x20e7,
966 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
967 sp
->name
, res
, sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1],
968 sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[2]);
970 if (res
== QLA_FUNCTION_TIMEOUT
)
973 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
|FCF_ASYNC_ACTIVE
);
974 memset(&ea
, 0, sizeof(ea
));
978 if (sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] >=
979 sizeof(struct get_name_list_extended
)) {
980 n
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] /
981 sizeof(struct get_name_list_extended
);
982 ea
.data
[0] = sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1]; /* amnt xfered */
985 for (i
= 0; i
< n
; i
++) {
987 loop_id
= le16_to_cpu(e
->nport_handle
);
988 /* mask out reserve bit */
989 loop_id
= (loop_id
& 0x7fff);
990 set_bit(loop_id
, vha
->hw
->loop_id_map
);
991 wwn
= wwn_to_u64(e
->port_name
);
993 ql_dbg(ql_dbg_disc
, vha
, 0x20e8,
994 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
995 __func__
, (void *)&wwn
, e
->port_id
[2], e
->port_id
[1],
996 e
->port_id
[0], e
->current_login_state
, e
->last_login_state
,
1000 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1004 if (!list_empty(&vha
->gnl
.fcports
))
1005 list_splice_init(&vha
->gnl
.fcports
, &h
);
1006 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1008 list_for_each_entry_safe(fcport
, tf
, &h
, gnl_entry
) {
1009 list_del_init(&fcport
->gnl_entry
);
1010 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1011 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
1012 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1015 qla24xx_handle_gnl_done_event(vha
, &ea
);
1018 /* create new fcport if fw has knowledge of new sessions */
1019 for (i
= 0; i
< n
; i
++) {
1024 wwn
= wwn_to_u64(e
->port_name
);
1027 list_for_each_entry_safe(fcport
, tf
, &vha
->vp_fcports
, list
) {
1028 if (!memcmp((u8
*)&wwn
, fcport
->port_name
,
1035 id
.b
.domain
= e
->port_id
[2];
1036 id
.b
.area
= e
->port_id
[1];
1037 id
.b
.al_pa
= e
->port_id
[0];
1040 if (!found
&& wwn
&& !IS_SW_RESV_ADDR(id
)) {
1041 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
1042 "%s %d %8phC %06x post new sess\n",
1043 __func__
, __LINE__
, (u8
*)&wwn
, id
.b24
);
1044 wwnn
= wwn_to_u64(e
->node_name
);
1045 qla24xx_post_newsess_work(vha
, &id
, (u8
*)&wwn
,
1046 (u8
*)&wwnn
, NULL
, 0);
1050 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1052 if (!list_empty(&vha
->gnl
.fcports
)) {
1054 list_for_each_entry_safe(fcport
, tf
, &vha
->gnl
.fcports
,
1056 list_del_init(&fcport
->gnl_entry
);
1057 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
1058 if (qla24xx_post_gnl_work(vha
, fcport
) == QLA_SUCCESS
)
1062 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1067 int qla24xx_async_gnl(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1070 struct srb_iocb
*mbx
;
1071 int rval
= QLA_FUNCTION_FAILED
;
1072 unsigned long flags
;
1075 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
1078 ql_dbg(ql_dbg_disc
, vha
, 0x20d9,
1079 "Async-gnlist WWPN %8phC \n", fcport
->port_name
);
1081 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1082 fcport
->flags
|= FCF_ASYNC_SENT
;
1083 qla2x00_set_fcport_disc_state(fcport
, DSC_GNL
);
1084 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1085 fcport
->last_login_gen
= fcport
->login_gen
;
1087 list_add_tail(&fcport
->gnl_entry
, &vha
->gnl
.fcports
);
1088 if (vha
->gnl
.sent
) {
1089 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1093 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1095 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1099 sp
->type
= SRB_MB_IOCB
;
1100 sp
->name
= "gnlist";
1101 sp
->gen1
= fcport
->rscn_gen
;
1102 sp
->gen2
= fcport
->login_gen
;
1104 mbx
= &sp
->u
.iocb_cmd
;
1105 mbx
->timeout
= qla2x00_async_iocb_timeout
;
1106 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
1108 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
1109 mb
[0] = MBC_PORT_NODE_NAME_LIST
;
1110 mb
[1] = BIT_2
| BIT_3
;
1111 mb
[2] = MSW(vha
->gnl
.ldma
);
1112 mb
[3] = LSW(vha
->gnl
.ldma
);
1113 mb
[6] = MSW(MSD(vha
->gnl
.ldma
));
1114 mb
[7] = LSW(MSD(vha
->gnl
.ldma
));
1115 mb
[8] = vha
->gnl
.size
;
1116 mb
[9] = vha
->vp_idx
;
1118 sp
->done
= qla24xx_async_gnl_sp_done
;
1120 ql_dbg(ql_dbg_disc
, vha
, 0x20da,
1121 "Async-%s - OUT WWPN %8phC hndl %x\n",
1122 sp
->name
, fcport
->port_name
, sp
->handle
);
1124 rval
= qla2x00_start_sp(sp
);
1125 if (rval
!= QLA_SUCCESS
)
1133 fcport
->flags
&= ~(FCF_ASYNC_ACTIVE
| FCF_ASYNC_SENT
);
1137 int qla24xx_post_gnl_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1139 struct qla_work_evt
*e
;
1141 e
= qla2x00_alloc_work(vha
, QLA_EVT_GNL
);
1143 return QLA_FUNCTION_FAILED
;
1145 e
->u
.fcport
.fcport
= fcport
;
1146 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
1147 return qla2x00_post_work(vha
, e
);
1150 static void qla24xx_async_gpdb_sp_done(srb_t
*sp
, int res
)
1152 struct scsi_qla_host
*vha
= sp
->vha
;
1153 struct qla_hw_data
*ha
= vha
->hw
;
1154 fc_port_t
*fcport
= sp
->fcport
;
1155 u16
*mb
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
;
1156 struct event_arg ea
;
1158 ql_dbg(ql_dbg_disc
, vha
, 0x20db,
1159 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1160 sp
->name
, res
, fcport
->port_name
, mb
[1], mb
[2]);
1162 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
1164 if (res
== QLA_FUNCTION_TIMEOUT
)
1167 memset(&ea
, 0, sizeof(ea
));
1171 qla24xx_handle_gpdb_event(vha
, &ea
);
1174 dma_pool_free(ha
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
1175 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
1180 static int qla24xx_post_prli_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1182 struct qla_work_evt
*e
;
1184 e
= qla2x00_alloc_work(vha
, QLA_EVT_PRLI
);
1186 return QLA_FUNCTION_FAILED
;
1188 e
->u
.fcport
.fcport
= fcport
;
1190 return qla2x00_post_work(vha
, e
);
1193 static void qla2x00_async_prli_sp_done(srb_t
*sp
, int res
)
1195 struct scsi_qla_host
*vha
= sp
->vha
;
1196 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
1197 struct event_arg ea
;
1199 ql_dbg(ql_dbg_disc
, vha
, 0x2129,
1200 "%s %8phC res %d \n", __func__
,
1201 sp
->fcport
->port_name
, res
);
1203 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1205 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
1206 memset(&ea
, 0, sizeof(ea
));
1207 ea
.fcport
= sp
->fcport
;
1208 ea
.data
[0] = lio
->u
.logio
.data
[0];
1209 ea
.data
[1] = lio
->u
.logio
.data
[1];
1210 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
1211 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
1214 qla24xx_handle_prli_done_event(vha
, &ea
);
1221 qla24xx_async_prli(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1224 struct srb_iocb
*lio
;
1225 int rval
= QLA_FUNCTION_FAILED
;
1227 if (!vha
->flags
.online
) {
1228 ql_dbg(ql_dbg_disc
, vha
, 0xffff, "%s %d %8phC exit\n",
1229 __func__
, __LINE__
, fcport
->port_name
);
1233 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
||
1234 fcport
->fw_login_state
== DSC_LS_PRLI_PEND
) &&
1235 qla_dual_mode_enabled(vha
)) {
1236 ql_dbg(ql_dbg_disc
, vha
, 0xffff, "%s %d %8phC exit\n",
1237 __func__
, __LINE__
, fcport
->port_name
);
1241 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1245 fcport
->flags
|= FCF_ASYNC_SENT
;
1246 fcport
->logout_completed
= 0;
1248 sp
->type
= SRB_PRLI_CMD
;
1251 lio
= &sp
->u
.iocb_cmd
;
1252 lio
->timeout
= qla2x00_async_iocb_timeout
;
1253 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
1255 sp
->done
= qla2x00_async_prli_sp_done
;
1256 lio
->u
.logio
.flags
= 0;
1258 if (NVME_TARGET(vha
->hw
, fcport
))
1259 lio
->u
.logio
.flags
|= SRB_LOGIN_NVME_PRLI
;
1261 ql_dbg(ql_dbg_disc
, vha
, 0x211b,
1262 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1263 fcport
->port_name
, sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
,
1264 fcport
->login_retry
, NVME_TARGET(vha
->hw
, fcport
) ? "nvme" : "fc");
1266 rval
= qla2x00_start_sp(sp
);
1267 if (rval
!= QLA_SUCCESS
) {
1268 fcport
->flags
|= FCF_LOGIN_NEEDED
;
1269 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1277 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1281 int qla24xx_post_gpdb_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
1283 struct qla_work_evt
*e
;
1285 e
= qla2x00_alloc_work(vha
, QLA_EVT_GPDB
);
1287 return QLA_FUNCTION_FAILED
;
1289 e
->u
.fcport
.fcport
= fcport
;
1290 e
->u
.fcport
.opt
= opt
;
1291 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
1292 return qla2x00_post_work(vha
, e
);
1295 int qla24xx_async_gpdb(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
1298 struct srb_iocb
*mbx
;
1299 int rval
= QLA_FUNCTION_FAILED
;
1302 struct port_database_24xx
*pd
;
1303 struct qla_hw_data
*ha
= vha
->hw
;
1305 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
) ||
1306 fcport
->loop_id
== FC_NO_LOOP_ID
) {
1307 ql_log(ql_log_warn
, vha
, 0xffff,
1308 "%s: %8phC - not sending command.\n",
1309 __func__
, fcport
->port_name
);
1313 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1317 qla2x00_set_fcport_disc_state(fcport
, DSC_GPDB
);
1319 fcport
->flags
|= FCF_ASYNC_SENT
;
1320 sp
->type
= SRB_MB_IOCB
;
1322 sp
->gen1
= fcport
->rscn_gen
;
1323 sp
->gen2
= fcport
->login_gen
;
1325 mbx
= &sp
->u
.iocb_cmd
;
1326 mbx
->timeout
= qla2x00_async_iocb_timeout
;
1327 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
1329 pd
= dma_pool_zalloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
1331 ql_log(ql_log_warn
, vha
, 0xd043,
1332 "Failed to allocate port database structure.\n");
1336 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
1337 mb
[0] = MBC_GET_PORT_DATABASE
;
1338 mb
[1] = fcport
->loop_id
;
1339 mb
[2] = MSW(pd_dma
);
1340 mb
[3] = LSW(pd_dma
);
1341 mb
[6] = MSW(MSD(pd_dma
));
1342 mb
[7] = LSW(MSD(pd_dma
));
1343 mb
[9] = vha
->vp_idx
;
1346 mbx
->u
.mbx
.in
= (void *)pd
;
1347 mbx
->u
.mbx
.in_dma
= pd_dma
;
1349 sp
->done
= qla24xx_async_gpdb_sp_done
;
1351 ql_dbg(ql_dbg_disc
, vha
, 0x20dc,
1352 "Async-%s %8phC hndl %x opt %x\n",
1353 sp
->name
, fcport
->port_name
, sp
->handle
, opt
);
1355 rval
= qla2x00_start_sp(sp
);
1356 if (rval
!= QLA_SUCCESS
)
1362 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1365 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1367 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
1368 qla24xx_post_gpdb_work(vha
, fcport
, opt
);
1373 void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1375 unsigned long flags
;
1377 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1378 ea
->fcport
->login_gen
++;
1379 ea
->fcport
->deleted
= 0;
1380 ea
->fcport
->logout_on_delete
= 1;
1382 if (!ea
->fcport
->login_succ
&& !IS_SW_RESV_ADDR(ea
->fcport
->d_id
)) {
1383 vha
->fcport_count
++;
1384 ea
->fcport
->login_succ
= 1;
1386 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1387 qla24xx_sched_upd_fcport(ea
->fcport
);
1388 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1389 } else if (ea
->fcport
->login_succ
) {
1391 * We have an existing session. A late RSCN delivery
1392 * must have triggered the session to be re-validate.
1393 * Session is still valid.
1395 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1396 "%s %d %8phC session revalidate success\n",
1397 __func__
, __LINE__
, ea
->fcport
->port_name
);
1398 qla2x00_set_fcport_disc_state(ea
->fcport
, DSC_LOGIN_COMPLETE
);
1400 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1404 void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1406 fc_port_t
*fcport
= ea
->fcport
;
1407 struct port_database_24xx
*pd
;
1408 struct srb
*sp
= ea
->sp
;
1411 pd
= (struct port_database_24xx
*)sp
->u
.iocb_cmd
.u
.mbx
.in
;
1413 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1415 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
1416 "%s %8phC DS %d LS %d fc4_type %x rc %d\n", __func__
,
1417 fcport
->port_name
, fcport
->disc_state
, pd
->current_login_state
,
1418 fcport
->fc4_type
, ea
->rc
);
1420 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1423 if (NVME_TARGET(vha
->hw
, fcport
))
1424 ls
= pd
->current_login_state
>> 4;
1426 ls
= pd
->current_login_state
& 0xf;
1428 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1429 /* target side must have changed it. */
1431 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1432 "%s %8phC generation changed\n",
1433 __func__
, fcport
->port_name
);
1435 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1436 qla_rscn_replay(fcport
);
1437 qlt_schedule_sess_for_deletion(fcport
);
1442 case PDS_PRLI_COMPLETE
:
1443 __qla24xx_parse_gpdb(vha
, fcport
, pd
);
1445 case PDS_PLOGI_PENDING
:
1446 case PDS_PLOGI_COMPLETE
:
1447 case PDS_PRLI_PENDING
:
1448 case PDS_PRLI2_PENDING
:
1449 /* Set discovery state back to GNL to Relogin attempt */
1450 if (qla_dual_mode_enabled(vha
) ||
1451 qla_ini_mode_enabled(vha
)) {
1452 qla2x00_set_fcport_disc_state(fcport
, DSC_GNL
);
1453 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1456 case PDS_LOGO_PENDING
:
1457 case PDS_PORT_UNAVAILABLE
:
1459 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC post del sess\n",
1460 __func__
, __LINE__
, fcport
->port_name
);
1461 qlt_schedule_sess_for_deletion(fcport
);
1464 __qla24xx_handle_gpdb_event(vha
, ea
);
1467 static void qla_chk_n2n_b4_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1472 if (qla_tgt_mode_enabled(vha
))
1475 if (qla_dual_mode_enabled(vha
)) {
1476 if (N2N_TOPO(vha
->hw
)) {
1479 mywwn
= wwn_to_u64(vha
->port_name
);
1480 wwn
= wwn_to_u64(fcport
->port_name
);
1483 else if ((fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1484 && time_after_eq(jiffies
,
1485 fcport
->plogi_nack_done_deadline
))
1491 /* initiator mode */
1495 if (login
&& fcport
->login_retry
) {
1496 fcport
->login_retry
--;
1497 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1498 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1499 rc
= qla2x00_find_new_loop_id(vha
, fcport
);
1501 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
1502 "%s %d %8phC post del sess - out of loopid\n",
1503 __func__
, __LINE__
, fcport
->port_name
);
1504 fcport
->scan_state
= 0;
1505 qlt_schedule_sess_for_deletion(fcport
);
1509 ql_dbg(ql_dbg_disc
, vha
, 0x20bf,
1510 "%s %d %8phC post login\n",
1511 __func__
, __LINE__
, fcport
->port_name
);
1512 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
1516 int qla24xx_fcport_handle_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1522 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1523 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1524 __func__
, fcport
->port_name
, fcport
->disc_state
,
1525 fcport
->fw_login_state
, fcport
->login_pause
, fcport
->flags
,
1526 fcport
->conflict
, fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1527 fcport
->login_gen
, fcport
->loop_id
, fcport
->scan_state
);
1529 if (fcport
->scan_state
!= QLA_FCPORT_FOUND
)
1532 if ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
1533 qla_dual_mode_enabled(vha
) &&
1534 ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1535 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)))
1538 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
&&
1539 !N2N_TOPO(vha
->hw
)) {
1540 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1541 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1546 /* Target won't initiate port login if fabric is present */
1547 if (vha
->host
->active_mode
== MODE_TARGET
&& !N2N_TOPO(vha
->hw
))
1550 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1551 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1555 switch (fcport
->disc_state
) {
1557 wwn
= wwn_to_u64(fcport
->node_name
);
1558 switch (vha
->hw
->current_topology
) {
1560 if (fcport_is_smaller(fcport
)) {
1561 /* this adapter is bigger */
1562 if (fcport
->login_retry
) {
1563 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1564 qla2x00_find_new_loop_id(vha
,
1566 fcport
->fw_login_state
=
1567 DSC_LS_PORT_UNAVAIL
;
1569 fcport
->login_retry
--;
1570 qla_post_els_plogi_work(vha
, fcport
);
1572 ql_log(ql_log_info
, vha
, 0x705d,
1573 "Unable to reach remote port %8phC",
1577 qla24xx_post_gnl_work(vha
, fcport
);
1582 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1583 "%s %d %8phC post GNNID\n",
1584 __func__
, __LINE__
, fcport
->port_name
);
1585 qla24xx_post_gnnid_work(vha
, fcport
);
1586 } else if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1587 ql_dbg(ql_dbg_disc
, vha
, 0x20bd,
1588 "%s %d %8phC post gnl\n",
1589 __func__
, __LINE__
, fcport
->port_name
);
1590 qla24xx_post_gnl_work(vha
, fcport
);
1592 qla_chk_n2n_b4_login(vha
, fcport
);
1599 switch (vha
->hw
->current_topology
) {
1601 if ((fcport
->current_login_state
& 0xf) == 0x6) {
1602 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1603 "%s %d %8phC post GPDB work\n",
1604 __func__
, __LINE__
, fcport
->port_name
);
1605 fcport
->chip_reset
=
1606 vha
->hw
->base_qpair
->chip_reset
;
1607 qla24xx_post_gpdb_work(vha
, fcport
, 0);
1609 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1610 "%s %d %8phC post %s PRLI\n",
1611 __func__
, __LINE__
, fcport
->port_name
,
1612 NVME_TARGET(vha
->hw
, fcport
) ? "NVME" :
1614 qla24xx_post_prli_work(vha
, fcport
);
1618 if (fcport
->login_pause
) {
1619 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1620 "%s %d %8phC exit\n",
1623 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1624 fcport
->last_login_gen
= fcport
->login_gen
;
1625 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1628 qla_chk_n2n_b4_login(vha
, fcport
);
1633 case DSC_LOGIN_FAILED
:
1634 if (N2N_TOPO(vha
->hw
))
1635 qla_chk_n2n_b4_login(vha
, fcport
);
1637 qlt_schedule_sess_for_deletion(fcport
);
1640 case DSC_LOGIN_COMPLETE
:
1641 /* recheck login state */
1642 data
[0] = data
[1] = 0;
1643 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
1646 case DSC_LOGIN_PEND
:
1647 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1648 qla24xx_post_prli_work(vha
, fcport
);
1651 case DSC_UPD_FCPORT
:
1652 sec
= jiffies_to_msecs(jiffies
-
1653 fcport
->jiffies_at_registration
)/1000;
1654 if (fcport
->sec_since_registration
< sec
&& sec
&&
1656 fcport
->sec_since_registration
= sec
;
1657 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0xffff,
1658 "%s %8phC - Slow Rport registration(%d Sec)\n",
1659 __func__
, fcport
->port_name
, sec
);
1662 if (fcport
->next_disc_state
!= DSC_DELETE_PEND
)
1663 fcport
->next_disc_state
= DSC_ADISC
;
1664 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1674 int qla24xx_post_newsess_work(struct scsi_qla_host
*vha
, port_id_t
*id
,
1675 u8
*port_name
, u8
*node_name
, void *pla
, u8 fc4_type
)
1677 struct qla_work_evt
*e
;
1679 e
= qla2x00_alloc_work(vha
, QLA_EVT_NEW_SESS
);
1681 return QLA_FUNCTION_FAILED
;
1683 e
->u
.new_sess
.id
= *id
;
1684 e
->u
.new_sess
.pla
= pla
;
1685 e
->u
.new_sess
.fc4_type
= fc4_type
;
1686 memcpy(e
->u
.new_sess
.port_name
, port_name
, WWN_SIZE
);
1688 memcpy(e
->u
.new_sess
.node_name
, node_name
, WWN_SIZE
);
1690 return qla2x00_post_work(vha
, e
);
1693 void qla2x00_handle_rscn(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1696 unsigned long flags
;
1698 fcport
= qla2x00_find_fcport_by_nportid(vha
, &ea
->id
, 1);
1700 fcport
->scan_needed
= 1;
1704 spin_lock_irqsave(&vha
->work_lock
, flags
);
1705 if (vha
->scan
.scan_flags
== 0) {
1706 ql_dbg(ql_dbg_disc
, vha
, 0xffff, "%s: schedule\n", __func__
);
1707 vha
->scan
.scan_flags
|= SF_QUEUED
;
1708 schedule_delayed_work(&vha
->scan
.scan_work
, 5);
1710 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1713 void qla24xx_handle_relogin_event(scsi_qla_host_t
*vha
,
1714 struct event_arg
*ea
)
1716 fc_port_t
*fcport
= ea
->fcport
;
1718 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1721 ql_dbg(ql_dbg_disc
, vha
, 0x2102,
1722 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1723 __func__
, fcport
->port_name
, fcport
->disc_state
,
1724 fcport
->fw_login_state
, fcport
->login_pause
,
1725 fcport
->deleted
, fcport
->conflict
,
1726 fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1727 fcport
->last_login_gen
, fcport
->login_gen
,
1730 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
1731 ql_dbg(ql_dbg_disc
, vha
, 0x20e9, "%s %d %8phC post gnl\n",
1732 __func__
, __LINE__
, fcport
->port_name
);
1733 qla24xx_post_gnl_work(vha
, fcport
);
1737 qla24xx_fcport_handle_login(vha
, fcport
);
1740 void qla_handle_els_plogi_done(scsi_qla_host_t
*vha
,
1741 struct event_arg
*ea
)
1743 /* for pure Target Mode, PRLI will not be initiated */
1744 if (vha
->host
->active_mode
== MODE_TARGET
)
1747 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1748 "%s %d %8phC post PRLI\n",
1749 __func__
, __LINE__
, ea
->fcport
->port_name
);
1750 qla24xx_post_prli_work(vha
, ea
->fcport
);
1754 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1755 * to be consumed by the fcport
1757 void qla_rscn_replay(fc_port_t
*fcport
)
1759 struct event_arg ea
;
1761 switch (fcport
->disc_state
) {
1762 case DSC_DELETE_PEND
:
1768 if (fcport
->scan_needed
) {
1769 memset(&ea
, 0, sizeof(ea
));
1770 ea
.id
= fcport
->d_id
;
1771 ea
.id
.b
.rsvd_1
= RSCN_PORT_ADDR
;
1772 qla2x00_handle_rscn(fcport
->vha
, &ea
);
1777 qla2x00_tmf_iocb_timeout(void *data
)
1780 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1782 unsigned long flags
;
1784 rc
= qla24xx_async_abort_cmd(sp
, false);
1786 spin_lock_irqsave(sp
->qpair
->qp_lock_ptr
, flags
);
1787 for (h
= 1; h
< sp
->qpair
->req
->num_outstanding_cmds
; h
++) {
1788 if (sp
->qpair
->req
->outstanding_cmds
[h
] == sp
) {
1789 sp
->qpair
->req
->outstanding_cmds
[h
] = NULL
;
1793 spin_unlock_irqrestore(sp
->qpair
->qp_lock_ptr
, flags
);
1794 tmf
->u
.tmf
.comp_status
= CS_TIMEOUT
;
1795 tmf
->u
.tmf
.data
= QLA_FUNCTION_FAILED
;
1796 complete(&tmf
->u
.tmf
.comp
);
1800 static void qla2x00_tmf_sp_done(srb_t
*sp
, int res
)
1802 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1804 complete(&tmf
->u
.tmf
.comp
);
1808 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
1811 struct scsi_qla_host
*vha
= fcport
->vha
;
1812 struct srb_iocb
*tm_iocb
;
1814 int rval
= QLA_FUNCTION_FAILED
;
1816 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1820 tm_iocb
= &sp
->u
.iocb_cmd
;
1821 sp
->type
= SRB_TM_CMD
;
1824 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
1825 init_completion(&tm_iocb
->u
.tmf
.comp
);
1826 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1828 tm_iocb
->u
.tmf
.flags
= flags
;
1829 tm_iocb
->u
.tmf
.lun
= lun
;
1830 tm_iocb
->u
.tmf
.data
= tag
;
1831 sp
->done
= qla2x00_tmf_sp_done
;
1833 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
1834 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1835 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1836 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1838 rval
= qla2x00_start_sp(sp
);
1839 if (rval
!= QLA_SUCCESS
)
1841 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
1843 rval
= tm_iocb
->u
.tmf
.data
;
1845 if (rval
!= QLA_SUCCESS
) {
1846 ql_log(ql_log_warn
, vha
, 0x8030,
1847 "TM IOCB failed (%x).\n", rval
);
1850 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
1851 flags
= tm_iocb
->u
.tmf
.flags
;
1852 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
1854 /* Issue Marker IOCB */
1855 qla2x00_marker(vha
, vha
->hw
->base_qpair
,
1856 fcport
->loop_id
, lun
,
1857 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
1862 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1868 qla24xx_async_abort_command(srb_t
*sp
)
1870 unsigned long flags
= 0;
1873 fc_port_t
*fcport
= sp
->fcport
;
1874 struct qla_qpair
*qpair
= sp
->qpair
;
1875 struct scsi_qla_host
*vha
= fcport
->vha
;
1876 struct req_que
*req
= qpair
->req
;
1878 spin_lock_irqsave(qpair
->qp_lock_ptr
, flags
);
1879 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
1880 if (req
->outstanding_cmds
[handle
] == sp
)
1883 spin_unlock_irqrestore(qpair
->qp_lock_ptr
, flags
);
1885 if (handle
== req
->num_outstanding_cmds
) {
1886 /* Command not found. */
1887 return QLA_FUNCTION_FAILED
;
1889 if (sp
->type
== SRB_FXIOCB_DCMD
)
1890 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
1891 FXDISC_ABORT_IOCTL
);
1893 return qla24xx_async_abort_cmd(sp
, true);
1897 qla24xx_handle_prli_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1899 WARN_ONCE(!qla2xxx_is_valid_mbs(ea
->data
[0]), "mbs: %#x\n",
1902 switch (ea
->data
[0]) {
1903 case MBS_COMMAND_COMPLETE
:
1904 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1905 "%s %d %8phC post gpdb\n",
1906 __func__
, __LINE__
, ea
->fcport
->port_name
);
1908 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1909 ea
->fcport
->logout_on_delete
= 1;
1910 ea
->fcport
->nvme_prli_service_param
= ea
->iop
[0];
1911 if (ea
->iop
[0] & NVME_PRLI_SP_FIRST_BURST
)
1912 ea
->fcport
->nvme_first_burst_size
=
1913 (ea
->iop
[1] & 0xffff) * 512;
1915 ea
->fcport
->nvme_first_burst_size
= 0;
1916 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1919 if ((ea
->iop
[0] == LSC_SCODE_ELS_REJECT
) &&
1920 (ea
->iop
[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1921 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1922 ea
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
1927 * Retry PRLI with other FC-4 type if failure occurred on dual
1930 if (NVME_FCP_TARGET(ea
->fcport
)) {
1931 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1932 "%s %d %8phC post %s prli\n",
1933 __func__
, __LINE__
, ea
->fcport
->port_name
,
1934 (ea
->fcport
->fc4_type
& FS_FC4TYPE_NVME
) ?
1936 if (vha
->hw
->fc4_type_priority
== FC4_PRIORITY_NVME
)
1937 ea
->fcport
->fc4_type
&= ~FS_FC4TYPE_NVME
;
1939 ea
->fcport
->fc4_type
&= ~FS_FC4TYPE_FCP
;
1942 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1943 ea
->fcport
->keep_nport_handle
= 0;
1944 ea
->fcport
->logout_on_delete
= 1;
1945 qlt_schedule_sess_for_deletion(ea
->fcport
);
1951 qla24xx_handle_plogi_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1953 port_id_t cid
; /* conflict Nport id */
1955 struct fc_port
*conflict_fcport
;
1956 unsigned long flags
;
1957 struct fc_port
*fcport
= ea
->fcport
;
1959 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1960 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1961 __func__
, fcport
->port_name
, fcport
->disc_state
,
1962 fcport
->fw_login_state
, ea
->rc
, ea
->sp
->gen2
, fcport
->login_gen
,
1963 ea
->sp
->gen1
, fcport
->rscn_gen
,
1964 ea
->data
[0], ea
->data
[1], ea
->iop
[0], ea
->iop
[1]);
1966 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1967 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)) {
1968 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1969 "%s %d %8phC Remote is trying to login\n",
1970 __func__
, __LINE__
, fcport
->port_name
);
1974 if ((fcport
->disc_state
== DSC_DELETE_PEND
) ||
1975 (fcport
->disc_state
== DSC_DELETED
)) {
1976 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1980 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1981 /* target side must have changed it. */
1982 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1983 "%s %8phC generation changed\n",
1984 __func__
, fcport
->port_name
);
1985 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1987 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1988 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1989 "%s %8phC RSCN generation changed\n",
1990 __func__
, fcport
->port_name
);
1991 qla_rscn_replay(fcport
);
1992 qlt_schedule_sess_for_deletion(fcport
);
1996 WARN_ONCE(!qla2xxx_is_valid_mbs(ea
->data
[0]), "mbs: %#x\n",
1999 switch (ea
->data
[0]) {
2000 case MBS_COMMAND_COMPLETE
:
2002 * Driver must validate login state - If PRLI not complete,
2003 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2006 if (NVME_TARGET(vha
->hw
, ea
->fcport
)) {
2007 ql_dbg(ql_dbg_disc
, vha
, 0x2117,
2008 "%s %d %8phC post prli\n",
2009 __func__
, __LINE__
, ea
->fcport
->port_name
);
2010 qla24xx_post_prli_work(vha
, ea
->fcport
);
2012 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
2013 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2014 __func__
, __LINE__
, ea
->fcport
->port_name
,
2015 ea
->fcport
->loop_id
, ea
->fcport
->d_id
.b24
);
2017 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
2018 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
2019 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
2020 ea
->fcport
->logout_on_delete
= 1;
2021 ea
->fcport
->send_els_logo
= 0;
2022 ea
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
2023 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
2025 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
2028 case MBS_COMMAND_ERROR
:
2029 ql_dbg(ql_dbg_disc
, vha
, 0x20eb, "%s %d %8phC cmd error %x\n",
2030 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[1]);
2032 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
2033 qla2x00_set_fcport_disc_state(ea
->fcport
, DSC_LOGIN_FAILED
);
2034 if (ea
->data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
2035 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
2037 qla2x00_mark_device_lost(vha
, ea
->fcport
, 1);
2039 case MBS_LOOP_ID_USED
:
2040 /* data[1] = IO PARAM 1 = nport ID */
2041 cid
.b
.domain
= (ea
->iop
[1] >> 16) & 0xff;
2042 cid
.b
.area
= (ea
->iop
[1] >> 8) & 0xff;
2043 cid
.b
.al_pa
= ea
->iop
[1] & 0xff;
2046 ql_dbg(ql_dbg_disc
, vha
, 0x20ec,
2047 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2048 __func__
, __LINE__
, ea
->fcport
->port_name
,
2049 ea
->fcport
->loop_id
, cid
.b24
);
2051 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
2052 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
2053 qla24xx_post_gnl_work(vha
, ea
->fcport
);
2055 case MBS_PORT_ID_USED
:
2056 lid
= ea
->iop
[1] & 0xffff;
2057 qlt_find_sess_invalidate_other(vha
,
2058 wwn_to_u64(ea
->fcport
->port_name
),
2059 ea
->fcport
->d_id
, lid
, &conflict_fcport
);
2061 if (conflict_fcport
) {
2063 * Another fcport share the same loop_id/nport id.
2064 * Conflict fcport needs to finish cleanup before this
2065 * fcport can proceed to login.
2067 conflict_fcport
->conflict
= ea
->fcport
;
2068 ea
->fcport
->login_pause
= 1;
2070 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
2071 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2072 __func__
, __LINE__
, ea
->fcport
->port_name
,
2073 ea
->fcport
->d_id
.b24
, lid
);
2075 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
2076 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2077 __func__
, __LINE__
, ea
->fcport
->port_name
,
2078 ea
->fcport
->d_id
.b24
, lid
);
2080 qla2x00_clear_loop_id(ea
->fcport
);
2081 set_bit(lid
, vha
->hw
->loop_id_map
);
2082 ea
->fcport
->loop_id
= lid
;
2083 ea
->fcport
->keep_nport_handle
= 0;
2084 ea
->fcport
->logout_on_delete
= 1;
2085 qlt_schedule_sess_for_deletion(ea
->fcport
);
2092 /****************************************************************************/
2093 /* QLogic ISP2x00 Hardware Support Functions. */
2094 /****************************************************************************/
2097 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
2099 int rval
= QLA_SUCCESS
;
2100 struct qla_hw_data
*ha
= vha
->hw
;
2101 uint32_t idc_major_ver
, idc_minor_ver
;
2104 qla83xx_idc_lock(vha
, 0);
2106 /* SV: TODO: Assign initialization timeout from
2107 * flash-info / other param
2109 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
2110 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
2112 /* Set our fcoe function presence */
2113 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
2114 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
2115 "Error while setting DRV-Presence.\n");
2116 rval
= QLA_FUNCTION_FAILED
;
2120 /* Decide the reset ownership */
2121 qla83xx_reset_ownership(vha
);
2124 * On first protocol driver load:
2125 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2127 * Others: Check compatibility with current IDC Major version.
2129 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
2130 if (ha
->flags
.nic_core_reset_owner
) {
2131 /* Set IDC Major version */
2132 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
2133 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
2135 /* Clearing IDC-Lock-Recovery register */
2136 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
2137 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
2139 * Clear further IDC participation if we are not compatible with
2140 * the current IDC Major Version.
2142 ql_log(ql_log_warn
, vha
, 0xb07d,
2143 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2144 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
2145 __qla83xx_clear_drv_presence(vha
);
2146 rval
= QLA_FUNCTION_FAILED
;
2149 /* Each function sets its supported Minor version. */
2150 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
2151 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
2152 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
2154 if (ha
->flags
.nic_core_reset_owner
) {
2155 memset(config
, 0, sizeof(config
));
2156 if (!qla81xx_get_port_config(vha
, config
))
2157 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
2161 rval
= qla83xx_idc_state_handler(vha
);
2164 qla83xx_idc_unlock(vha
, 0);
2170 * qla2x00_initialize_adapter
2174 * ha = adapter block pointer.
2180 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
2183 struct qla_hw_data
*ha
= vha
->hw
;
2184 struct req_que
*req
= ha
->req_q_map
[0];
2185 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2187 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
2188 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
2190 /* Clear adapter flags. */
2191 vha
->flags
.online
= 0;
2192 ha
->flags
.chip_reset_done
= 0;
2193 vha
->flags
.reset_active
= 0;
2194 ha
->flags
.pci_channel_io_perm_failure
= 0;
2195 ha
->flags
.eeh_busy
= 0;
2196 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
2197 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
2198 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
2199 vha
->device_flags
= DFLG_NO_CABLE
;
2201 vha
->flags
.management_server_logged_in
= 0;
2202 vha
->marker_needed
= 0;
2203 ha
->isp_abort_cnt
= 0;
2204 ha
->beacon_blink_led
= 0;
2206 set_bit(0, ha
->req_qid_map
);
2207 set_bit(0, ha
->rsp_qid_map
);
2209 ql_dbg(ql_dbg_init
, vha
, 0x0040,
2210 "Configuring PCI space...\n");
2211 rval
= ha
->isp_ops
->pci_config(vha
);
2213 ql_log(ql_log_warn
, vha
, 0x0044,
2214 "Unable to configure PCI space.\n");
2218 ha
->isp_ops
->reset_chip(vha
);
2220 /* Check for secure flash support */
2221 if (IS_QLA28XX(ha
)) {
2222 if (RD_REG_DWORD(®
->mailbox12
) & BIT_0
)
2223 ha
->flags
.secure_adapter
= 1;
2224 ql_log(ql_log_info
, vha
, 0xffff, "Secure Adapter: %s\n",
2225 (ha
->flags
.secure_adapter
) ? "Yes" : "No");
2229 rval
= qla2xxx_get_flash_info(vha
);
2231 ql_log(ql_log_fatal
, vha
, 0x004f,
2232 "Unable to validate FLASH data.\n");
2236 if (IS_QLA8044(ha
)) {
2237 qla8044_read_reset_template(vha
);
2239 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2240 * If DONRESET_BIT0 is set, drivers should not set dev_state
2241 * to NEED_RESET. But if NEED_RESET is set, drivers should
2242 * should honor the reset. */
2243 if (ql2xdontresethba
== 1)
2244 qla8044_set_idc_dontreset(vha
);
2247 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
2248 ql_dbg(ql_dbg_init
, vha
, 0x0061,
2249 "Configure NVRAM parameters...\n");
2251 /* Let priority default to FCP, can be overridden by nvram_config */
2252 ha
->fc4_type_priority
= FC4_PRIORITY_FCP
;
2254 ha
->isp_ops
->nvram_config(vha
);
2256 if (ha
->fc4_type_priority
!= FC4_PRIORITY_FCP
&&
2257 ha
->fc4_type_priority
!= FC4_PRIORITY_NVME
)
2258 ha
->fc4_type_priority
= FC4_PRIORITY_FCP
;
2260 ql_log(ql_log_info
, vha
, 0xffff, "FC4 priority set to %s\n",
2261 ha
->fc4_type_priority
== FC4_PRIORITY_FCP
? "FCP" : "NVMe");
2263 if (ha
->flags
.disable_serdes
) {
2264 /* Mask HBA via NVRAM settings? */
2265 ql_log(ql_log_info
, vha
, 0x0077,
2266 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
2267 return QLA_FUNCTION_FAILED
;
2270 ql_dbg(ql_dbg_init
, vha
, 0x0078,
2271 "Verifying loaded RISC code...\n");
2273 /* If smartsan enabled then require fdmi and rdp enabled */
2279 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
2280 rval
= ha
->isp_ops
->chip_diag(vha
);
2283 rval
= qla2x00_setup_chip(vha
);
2288 if (IS_QLA84XX(ha
)) {
2289 ha
->cs84xx
= qla84xx_get_chip(vha
);
2291 ql_log(ql_log_warn
, vha
, 0x00d0,
2292 "Unable to configure ISP84XX.\n");
2293 return QLA_FUNCTION_FAILED
;
2297 if (qla_ini_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
2298 rval
= qla2x00_init_rings(vha
);
2300 /* No point in continuing if firmware initialization failed. */
2301 if (rval
!= QLA_SUCCESS
)
2304 ha
->flags
.chip_reset_done
= 1;
2306 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
2307 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2308 rval
= qla84xx_init_chip(vha
);
2309 if (rval
!= QLA_SUCCESS
) {
2310 ql_log(ql_log_warn
, vha
, 0x00d4,
2311 "Unable to initialize ISP84XX.\n");
2312 qla84xx_put_chip(vha
);
2316 /* Load the NIC Core f/w if we are the first protocol driver. */
2317 if (IS_QLA8031(ha
)) {
2318 rval
= qla83xx_nic_core_fw_load(vha
);
2320 ql_log(ql_log_warn
, vha
, 0x0124,
2321 "Error in initializing NIC Core f/w.\n");
2324 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
2325 qla24xx_read_fcp_prio_cfg(vha
);
2327 if (IS_P3P_TYPE(ha
))
2328 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2330 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2336 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2339 * Returns 0 on success.
2342 qla2100_pci_config(scsi_qla_host_t
*vha
)
2345 unsigned long flags
;
2346 struct qla_hw_data
*ha
= vha
->hw
;
2347 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2349 pci_set_master(ha
->pdev
);
2350 pci_try_set_mwi(ha
->pdev
);
2352 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2353 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2354 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2356 pci_disable_rom(ha
->pdev
);
2358 /* Get PCI bus information. */
2359 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2360 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2361 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2367 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2370 * Returns 0 on success.
2373 qla2300_pci_config(scsi_qla_host_t
*vha
)
2376 unsigned long flags
= 0;
2378 struct qla_hw_data
*ha
= vha
->hw
;
2379 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2381 pci_set_master(ha
->pdev
);
2382 pci_try_set_mwi(ha
->pdev
);
2384 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2385 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2387 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2388 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2389 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2392 * If this is a 2300 card and not 2312, reset the
2393 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2394 * the 2310 also reports itself as a 2300 so we need to get the
2395 * fb revision level -- a 6 indicates it really is a 2300 and
2398 if (IS_QLA2300(ha
)) {
2399 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2402 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2403 for (cnt
= 0; cnt
< 30000; cnt
++) {
2404 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2410 /* Select FPM registers. */
2411 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2412 RD_REG_WORD(®
->ctrl_status
);
2414 /* Get the fb rev level */
2415 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
2417 if (ha
->fb_rev
== FPM_2300
)
2418 pci_clear_mwi(ha
->pdev
);
2420 /* Deselect FPM registers. */
2421 WRT_REG_WORD(®
->ctrl_status
, 0x0);
2422 RD_REG_WORD(®
->ctrl_status
);
2424 /* Release RISC module. */
2425 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2426 for (cnt
= 0; cnt
< 30000; cnt
++) {
2427 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
2433 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2436 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2438 pci_disable_rom(ha
->pdev
);
2440 /* Get PCI bus information. */
2441 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2442 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2443 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2449 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2452 * Returns 0 on success.
2455 qla24xx_pci_config(scsi_qla_host_t
*vha
)
2458 unsigned long flags
= 0;
2459 struct qla_hw_data
*ha
= vha
->hw
;
2460 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2462 pci_set_master(ha
->pdev
);
2463 pci_try_set_mwi(ha
->pdev
);
2465 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2466 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2467 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2468 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2470 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2472 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2473 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
2474 pcix_set_mmrbc(ha
->pdev
, 2048);
2476 /* PCIe -- adjust Maximum Read Request Size (2048). */
2477 if (pci_is_pcie(ha
->pdev
))
2478 pcie_set_readrq(ha
->pdev
, 4096);
2480 pci_disable_rom(ha
->pdev
);
2482 ha
->chip_revision
= ha
->pdev
->revision
;
2484 /* Get PCI bus information. */
2485 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2486 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
2487 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2493 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2496 * Returns 0 on success.
2499 qla25xx_pci_config(scsi_qla_host_t
*vha
)
2502 struct qla_hw_data
*ha
= vha
->hw
;
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 /* PCIe -- adjust Maximum Read Request Size (2048). */
2513 if (pci_is_pcie(ha
->pdev
))
2514 pcie_set_readrq(ha
->pdev
, 4096);
2516 pci_disable_rom(ha
->pdev
);
2518 ha
->chip_revision
= ha
->pdev
->revision
;
2524 * qla2x00_isp_firmware() - Choose firmware image.
2527 * Returns 0 on success.
2530 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
2533 uint16_t loop_id
, topo
, sw_cap
;
2534 uint8_t domain
, area
, al_pa
;
2535 struct qla_hw_data
*ha
= vha
->hw
;
2537 /* Assume loading risc code */
2538 rval
= QLA_FUNCTION_FAILED
;
2540 if (ha
->flags
.disable_risc_code_load
) {
2541 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
2543 /* Verify checksum of loaded RISC code. */
2544 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
2545 if (rval
== QLA_SUCCESS
) {
2546 /* And, verify we are not in ROM code. */
2547 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
2548 &area
, &domain
, &topo
, &sw_cap
);
2553 ql_dbg(ql_dbg_init
, vha
, 0x007a,
2554 "**** Load RISC code ****.\n");
2560 * qla2x00_reset_chip() - Reset ISP chip.
2563 * Returns 0 on success.
2566 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
2568 unsigned long flags
= 0;
2569 struct qla_hw_data
*ha
= vha
->hw
;
2570 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2573 int rval
= QLA_FUNCTION_FAILED
;
2575 if (unlikely(pci_channel_offline(ha
->pdev
)))
2578 ha
->isp_ops
->disable_intrs(ha
);
2580 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2582 /* Turn off master enable */
2584 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
2585 cmd
&= ~PCI_COMMAND_MASTER
;
2586 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2588 if (!IS_QLA2100(ha
)) {
2590 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2591 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2592 for (cnt
= 0; cnt
< 30000; cnt
++) {
2593 if ((RD_REG_WORD(®
->hccr
) &
2594 HCCR_RISC_PAUSE
) != 0)
2599 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2603 /* Select FPM registers. */
2604 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2605 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2607 /* FPM Soft Reset. */
2608 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
2609 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2611 /* Toggle Fpm Reset. */
2612 if (!IS_QLA2200(ha
)) {
2613 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
2614 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2617 /* Select frame buffer registers. */
2618 WRT_REG_WORD(®
->ctrl_status
, 0x10);
2619 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2621 /* Reset frame buffer FIFOs. */
2622 if (IS_QLA2200(ha
)) {
2623 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
2624 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
2626 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
2628 /* Read back fb_cmd until zero or 3 seconds max */
2629 for (cnt
= 0; cnt
< 3000; cnt
++) {
2630 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
2636 /* Select RISC module registers. */
2637 WRT_REG_WORD(®
->ctrl_status
, 0);
2638 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2640 /* Reset RISC processor. */
2641 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2642 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2644 /* Release RISC processor. */
2645 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2646 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2649 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
2650 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
2652 /* Reset ISP chip. */
2653 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2655 /* Wait for RISC to recover from reset. */
2656 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2658 * It is necessary to for a delay here since the card doesn't
2659 * respond to PCI reads during a reset. On some architectures
2660 * this will result in an MCA.
2663 for (cnt
= 30000; cnt
; cnt
--) {
2664 if ((RD_REG_WORD(®
->ctrl_status
) &
2665 CSR_ISP_SOFT_RESET
) == 0)
2672 /* Reset RISC processor. */
2673 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2675 WRT_REG_WORD(®
->semaphore
, 0);
2677 /* Release RISC processor. */
2678 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2679 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2681 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2682 for (cnt
= 0; cnt
< 30000; cnt
++) {
2683 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
2691 /* Turn on master enable */
2692 cmd
|= PCI_COMMAND_MASTER
;
2693 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2695 /* Disable RISC pause on FPM parity error. */
2696 if (!IS_QLA2100(ha
)) {
2697 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
2698 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2701 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2707 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2710 * Returns 0 on success.
2713 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
2715 uint16_t mb
[4] = {0x1010, 0, 1, 0};
2717 if (!IS_QLA81XX(vha
->hw
))
2720 return qla81xx_write_mpi_register(vha
, mb
);
2724 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2727 * Returns 0 on success.
2730 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
2732 unsigned long flags
= 0;
2733 struct qla_hw_data
*ha
= vha
->hw
;
2734 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2737 static int abts_cnt
; /* ISP abort retry counts */
2738 int rval
= QLA_SUCCESS
;
2740 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2743 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2744 for (cnt
= 0; cnt
< 30000; cnt
++) {
2745 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
2751 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
))
2752 set_bit(DMA_SHUTDOWN_CMPL
, &ha
->fw_dump_cap_flags
);
2754 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017e,
2755 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2756 RD_REG_DWORD(®
->hccr
),
2757 RD_REG_DWORD(®
->ctrl_status
),
2758 (RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
));
2760 WRT_REG_DWORD(®
->ctrl_status
,
2761 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2762 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2766 /* Wait for firmware to complete NVRAM accesses. */
2767 RD_REG_WORD(®
->mailbox0
);
2768 for (cnt
= 10000; RD_REG_WORD(®
->mailbox0
) != 0 &&
2769 rval
== QLA_SUCCESS
; cnt
--) {
2774 rval
= QLA_FUNCTION_TIMEOUT
;
2777 if (rval
== QLA_SUCCESS
)
2778 set_bit(ISP_MBX_RDY
, &ha
->fw_dump_cap_flags
);
2780 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017f,
2781 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2782 RD_REG_DWORD(®
->hccr
),
2783 RD_REG_DWORD(®
->mailbox0
));
2785 /* Wait for soft-reset to complete. */
2786 RD_REG_DWORD(®
->ctrl_status
);
2787 for (cnt
= 0; cnt
< 60; cnt
++) {
2789 if ((RD_REG_DWORD(®
->ctrl_status
) &
2790 CSRX_ISP_SOFT_RESET
) == 0)
2795 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_ISP_SOFT_RESET
))
2796 set_bit(ISP_SOFT_RESET_CMPL
, &ha
->fw_dump_cap_flags
);
2798 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015d,
2799 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2800 RD_REG_DWORD(®
->hccr
),
2801 RD_REG_DWORD(®
->ctrl_status
));
2803 /* If required, do an MPI FW reset now */
2804 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
2805 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
2806 if (++abts_cnt
< 5) {
2807 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2808 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
2811 * We exhausted the ISP abort retries. We have to
2812 * set the board offline.
2815 vha
->flags
.online
= 0;
2820 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
2821 RD_REG_DWORD(®
->hccr
);
2823 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
2824 RD_REG_DWORD(®
->hccr
);
2826 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
2827 RD_REG_DWORD(®
->hccr
);
2829 RD_REG_WORD(®
->mailbox0
);
2830 for (cnt
= 60; RD_REG_WORD(®
->mailbox0
) != 0 &&
2831 rval
== QLA_SUCCESS
; cnt
--) {
2836 rval
= QLA_FUNCTION_TIMEOUT
;
2838 if (rval
== QLA_SUCCESS
)
2839 set_bit(RISC_RDY_AFT_RESET
, &ha
->fw_dump_cap_flags
);
2841 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015e,
2842 "Host Risc 0x%x, mailbox0 0x%x\n",
2843 RD_REG_DWORD(®
->hccr
),
2844 RD_REG_WORD(®
->mailbox0
));
2846 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2848 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015f,
2849 "Driver in %s mode\n",
2850 IS_NOPOLLING_TYPE(ha
) ? "Interrupt" : "Polling");
2852 if (IS_NOPOLLING_TYPE(ha
))
2853 ha
->isp_ops
->enable_intrs(ha
);
2859 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
2861 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2863 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2864 *data
= RD_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
);
2869 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
2871 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2873 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2874 WRT_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
, data
);
2878 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
2881 uint delta_msec
= 100;
2882 uint elapsed_msec
= 0;
2886 if (vha
->hw
->pdev
->subsystem_device
!= 0x0175 &&
2887 vha
->hw
->pdev
->subsystem_device
!= 0x0240)
2890 WRT_REG_DWORD(&vha
->hw
->iobase
->isp24
.hccr
, HCCRX_SET_RISC_PAUSE
);
2894 timeout_msec
= TIMEOUT_SEMAPHORE
;
2895 n
= timeout_msec
/ delta_msec
;
2897 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
2898 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2899 if (wd32
& RISC_SEMAPHORE
)
2902 elapsed_msec
+= delta_msec
;
2903 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2907 if (!(wd32
& RISC_SEMAPHORE
))
2910 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2913 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
2914 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
2915 n
= timeout_msec
/ delta_msec
;
2917 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2918 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2921 elapsed_msec
+= delta_msec
;
2922 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2926 if (wd32
& RISC_SEMAPHORE_FORCE
)
2927 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
2932 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
2939 * qla24xx_reset_chip() - Reset ISP24xx chip.
2942 * Returns 0 on success.
2945 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
2947 struct qla_hw_data
*ha
= vha
->hw
;
2948 int rval
= QLA_FUNCTION_FAILED
;
2950 if (pci_channel_offline(ha
->pdev
) &&
2951 ha
->flags
.pci_channel_io_perm_failure
) {
2955 ha
->isp_ops
->disable_intrs(ha
);
2957 qla25xx_manipulate_risc_semaphore(vha
);
2959 /* Perform RISC reset. */
2960 rval
= qla24xx_reset_risc(vha
);
2966 * qla2x00_chip_diag() - Test chip for proper operation.
2969 * Returns 0 on success.
2972 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
2975 struct qla_hw_data
*ha
= vha
->hw
;
2976 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2977 unsigned long flags
= 0;
2981 struct req_que
*req
= ha
->req_q_map
[0];
2983 /* Assume a failed state */
2984 rval
= QLA_FUNCTION_FAILED
;
2986 ql_dbg(ql_dbg_init
, vha
, 0x007b, "Testing device at %p.\n",
2987 ®
->flash_address
);
2989 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2991 /* Reset ISP chip. */
2992 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2995 * We need to have a delay here since the card will not respond while
2996 * in reset causing an MCA on some architectures.
2999 data
= qla2x00_debounce_register(®
->ctrl_status
);
3000 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
3002 data
= RD_REG_WORD(®
->ctrl_status
);
3007 goto chip_diag_failed
;
3009 ql_dbg(ql_dbg_init
, vha
, 0x007c,
3010 "Reset register cleared by chip reset.\n");
3012 /* Reset RISC processor. */
3013 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
3014 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
3016 /* Workaround for QLA2312 PCI parity error */
3017 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
3018 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
3019 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
3021 data
= RD_MAILBOX_REG(ha
, reg
, 0);
3028 goto chip_diag_failed
;
3030 /* Check product ID of chip */
3031 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product ID of chip.\n");
3033 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
3034 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
3035 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
3036 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
3037 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
3038 mb
[3] != PROD_ID_3
) {
3039 ql_log(ql_log_warn
, vha
, 0x0062,
3040 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3041 mb
[1], mb
[2], mb
[3]);
3043 goto chip_diag_failed
;
3045 ha
->product_id
[0] = mb
[1];
3046 ha
->product_id
[1] = mb
[2];
3047 ha
->product_id
[2] = mb
[3];
3048 ha
->product_id
[3] = mb
[4];
3050 /* Adjust fw RISC transfer size */
3051 if (req
->length
> 1024)
3052 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
3054 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
3057 if (IS_QLA2200(ha
) &&
3058 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
3059 /* Limit firmware transfer size with a 2200A */
3060 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
3062 ha
->device_type
|= DT_ISP2200A
;
3063 ha
->fw_transfer_size
= 128;
3066 /* Wrap Incoming Mailboxes Test. */
3067 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3069 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
3070 rval
= qla2x00_mbx_reg_test(vha
);
3072 ql_log(ql_log_warn
, vha
, 0x0080,
3073 "Failed mailbox send register test.\n");
3075 /* Flag a successful rval */
3077 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3081 ql_log(ql_log_info
, vha
, 0x0081,
3082 "Chip diagnostics **** FAILED ****.\n");
3084 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3090 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3093 * Returns 0 on success.
3096 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
3099 struct qla_hw_data
*ha
= vha
->hw
;
3100 struct req_que
*req
= ha
->req_q_map
[0];
3102 if (IS_P3P_TYPE(ha
))
3105 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
3107 rval
= qla2x00_mbx_reg_test(vha
);
3109 ql_log(ql_log_warn
, vha
, 0x0082,
3110 "Failed mailbox send register test.\n");
3112 /* Flag a successful rval */
3120 qla2x00_init_fce_trace(scsi_qla_host_t
*vha
)
3125 struct qla_hw_data
*ha
= vha
->hw
;
3127 if (!IS_FWI2_CAPABLE(ha
))
3130 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
3131 !IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
3135 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
3136 "%s: FCE Mem is already allocated.\n",
3141 /* Allocate memory for Fibre Channel Event Buffer. */
3142 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
3145 ql_log(ql_log_warn
, vha
, 0x00be,
3146 "Unable to allocate (%d KB) for FCE.\n",
3151 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
3152 ha
->fce_mb
, &ha
->fce_bufs
);
3154 ql_log(ql_log_warn
, vha
, 0x00bf,
3155 "Unable to initialize FCE (%d).\n", rval
);
3156 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
, tc_dma
);
3160 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
3161 "Allocated (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
3163 ha
->flags
.fce_enabled
= 1;
3164 ha
->fce_dma
= tc_dma
;
3169 qla2x00_init_eft_trace(scsi_qla_host_t
*vha
)
3174 struct qla_hw_data
*ha
= vha
->hw
;
3176 if (!IS_FWI2_CAPABLE(ha
))
3180 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
3181 "%s: EFT Mem is already allocated.\n",
3186 /* Allocate memory for Extended Trace Buffer. */
3187 tc
= dma_alloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
3190 ql_log(ql_log_warn
, vha
, 0x00c1,
3191 "Unable to allocate (%d KB) for EFT.\n",
3196 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
3198 ql_log(ql_log_warn
, vha
, 0x00c2,
3199 "Unable to initialize EFT (%d).\n", rval
);
3200 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
, tc_dma
);
3204 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
3205 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
3207 ha
->eft_dma
= tc_dma
;
3212 qla2x00_alloc_offload_mem(scsi_qla_host_t
*vha
)
3214 qla2x00_init_fce_trace(vha
);
3215 qla2x00_init_eft_trace(vha
);
3219 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
3221 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
3222 eft_size
, fce_size
, mq_size
;
3223 struct qla_hw_data
*ha
= vha
->hw
;
3224 struct req_que
*req
= ha
->req_q_map
[0];
3225 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3226 struct qla2xxx_fw_dump
*fw_dump
;
3228 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
3229 req_q_size
= rsp_q_size
= 0;
3231 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
3232 fixed_size
= sizeof(struct qla2100_fw_dump
);
3233 } else if (IS_QLA23XX(ha
)) {
3234 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
3235 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
3237 } else if (IS_FWI2_CAPABLE(ha
)) {
3238 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
))
3239 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
3240 else if (IS_QLA81XX(ha
))
3241 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
3242 else if (IS_QLA25XX(ha
))
3243 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
3245 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
3247 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
3250 if (!IS_QLA83XX(ha
) && !IS_QLA27XX(ha
) &&
3252 mq_size
= sizeof(struct qla2xxx_mq_chain
);
3254 * Allocate maximum buffer size for all queues - Q0.
3255 * Resizing must be done at end-of-dump processing.
3257 mq_size
+= (ha
->max_req_queues
- 1) *
3258 (req
->length
* sizeof(request_t
));
3259 mq_size
+= (ha
->max_rsp_queues
- 1) *
3260 (rsp
->length
* sizeof(response_t
));
3262 if (ha
->tgt
.atio_ring
)
3263 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
3265 qla2x00_init_fce_trace(vha
);
3267 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
3268 qla2x00_init_eft_trace(vha
);
3270 eft_size
= EFT_SIZE
;
3273 if (IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
3274 struct fwdt
*fwdt
= ha
->fwdt
;
3277 for (j
= 0; j
< 2; j
++, fwdt
++) {
3278 if (!fwdt
->template) {
3279 ql_dbg(ql_dbg_init
, vha
, 0x00ba,
3280 "-> fwdt%u no template\n", j
);
3283 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
3284 "-> fwdt%u calculating fwdump size...\n", j
);
3285 fwdt
->dump_size
= qla27xx_fwdt_calculate_dump_size(
3286 vha
, fwdt
->template);
3287 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
3288 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3289 j
, fwdt
->dump_size
);
3290 dump_size
+= fwdt
->dump_size
;
3293 req_q_size
= req
->length
* sizeof(request_t
);
3294 rsp_q_size
= rsp
->length
* sizeof(response_t
);
3295 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
3296 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
3298 ha
->chain_offset
= dump_size
;
3299 dump_size
+= mq_size
+ fce_size
;
3300 if (ha
->exchoffld_buf
)
3301 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3303 if (ha
->exlogin_buf
)
3304 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3308 if (!ha
->fw_dump_len
|| dump_size
> ha
->fw_dump_alloc_len
) {
3310 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3311 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3312 __func__
, dump_size
, ha
->fw_dump_len
,
3313 ha
->fw_dump_alloc_len
);
3315 fw_dump
= vmalloc(dump_size
);
3317 ql_log(ql_log_warn
, vha
, 0x00c4,
3318 "Unable to allocate (%d KB) for firmware dump.\n",
3321 mutex_lock(&ha
->optrom_mutex
);
3322 if (ha
->fw_dumped
) {
3323 memcpy(fw_dump
, ha
->fw_dump
, ha
->fw_dump_len
);
3325 ha
->fw_dump
= fw_dump
;
3326 ha
->fw_dump_alloc_len
= dump_size
;
3327 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3328 "Re-Allocated (%d KB) and save firmware dump.\n",
3333 ha
->fw_dump
= fw_dump
;
3335 ha
->fw_dump_len
= ha
->fw_dump_alloc_len
=
3337 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3338 "Allocated (%d KB) for firmware dump.\n",
3341 if (IS_QLA27XX(ha
) || IS_QLA28XX(ha
)) {
3342 mutex_unlock(&ha
->optrom_mutex
);
3346 ha
->fw_dump
->signature
[0] = 'Q';
3347 ha
->fw_dump
->signature
[1] = 'L';
3348 ha
->fw_dump
->signature
[2] = 'G';
3349 ha
->fw_dump
->signature
[3] = 'C';
3350 ha
->fw_dump
->version
= htonl(1);
3352 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
3353 ha
->fw_dump
->mem_size
= htonl(mem_size
);
3354 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
3355 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
3357 ha
->fw_dump
->eft_size
= htonl(eft_size
);
3358 ha
->fw_dump
->eft_addr_l
=
3359 htonl(LSD(ha
->eft_dma
));
3360 ha
->fw_dump
->eft_addr_h
=
3361 htonl(MSD(ha
->eft_dma
));
3363 ha
->fw_dump
->header_size
=
3365 (struct qla2xxx_fw_dump
, isp
));
3367 mutex_unlock(&ha
->optrom_mutex
);
3373 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
3375 #define MPS_MASK 0xe0
3380 if (!IS_QLA81XX(vha
->hw
))
3383 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
3384 if (rval
!= QLA_SUCCESS
) {
3385 ql_log(ql_log_warn
, vha
, 0x0105,
3386 "Unable to acquire semaphore.\n");
3390 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
3391 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
3392 if (rval
!= QLA_SUCCESS
) {
3393 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
3398 if (dc
== (dw
& MPS_MASK
))
3403 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
3404 if (rval
!= QLA_SUCCESS
) {
3405 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
3409 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
3410 if (rval
!= QLA_SUCCESS
) {
3411 ql_log(ql_log_warn
, vha
, 0x006d,
3412 "Unable to release semaphore.\n");
3420 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
3422 /* Don't try to reallocate the array */
3423 if (req
->outstanding_cmds
)
3426 if (!IS_FWI2_CAPABLE(ha
))
3427 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
3429 if (ha
->cur_fw_xcb_count
<= ha
->cur_fw_iocb_count
)
3430 req
->num_outstanding_cmds
= ha
->cur_fw_xcb_count
;
3432 req
->num_outstanding_cmds
= ha
->cur_fw_iocb_count
;
3435 req
->outstanding_cmds
= kcalloc(req
->num_outstanding_cmds
,
3439 if (!req
->outstanding_cmds
) {
3441 * Try to allocate a minimal size just so we can get through
3444 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
3445 req
->outstanding_cmds
= kcalloc(req
->num_outstanding_cmds
,
3449 if (!req
->outstanding_cmds
) {
3450 ql_log(ql_log_fatal
, NULL
, 0x0126,
3451 "Failed to allocate memory for "
3452 "outstanding_cmds for req_que %p.\n", req
);
3453 req
->num_outstanding_cmds
= 0;
3454 return QLA_FUNCTION_FAILED
;
3461 #define PRINT_FIELD(_field, _flag, _str) { \
3462 if (a0->_field & _flag) {\
3468 len = snprintf(ptr, leftover, "%s", _str); \
3475 static void qla2xxx_print_sfp_info(struct scsi_qla_host
*vha
)
3478 struct sff_8247_a0
*a0
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3479 u8 str
[STR_LEN
], *ptr
, p
;
3482 memset(str
, 0, STR_LEN
);
3483 snprintf(str
, SFF_VEN_NAME_LEN
+1, a0
->vendor_name
);
3484 ql_dbg(ql_dbg_init
, vha
, 0x015a,
3485 "SFP MFG Name: %s\n", str
);
3487 memset(str
, 0, STR_LEN
);
3488 snprintf(str
, SFF_PART_NAME_LEN
+1, a0
->vendor_pn
);
3489 ql_dbg(ql_dbg_init
, vha
, 0x015c,
3490 "SFP Part Name: %s\n", str
);
3493 memset(str
, 0, STR_LEN
);
3497 PRINT_FIELD(fc_med_cc9
, FC_MED_TW
, "Twin AX");
3498 PRINT_FIELD(fc_med_cc9
, FC_MED_TP
, "Twisted Pair");
3499 PRINT_FIELD(fc_med_cc9
, FC_MED_MI
, "Min Coax");
3500 PRINT_FIELD(fc_med_cc9
, FC_MED_TV
, "Video Coax");
3501 PRINT_FIELD(fc_med_cc9
, FC_MED_M6
, "MultiMode 62.5um");
3502 PRINT_FIELD(fc_med_cc9
, FC_MED_M5
, "MultiMode 50um");
3503 PRINT_FIELD(fc_med_cc9
, FC_MED_SM
, "SingleMode");
3504 ql_dbg(ql_dbg_init
, vha
, 0x0160,
3505 "SFP Media: %s\n", str
);
3508 memset(str
, 0, STR_LEN
);
3512 PRINT_FIELD(fc_ll_cc7
, FC_LL_VL
, "Very Long");
3513 PRINT_FIELD(fc_ll_cc7
, FC_LL_S
, "Short");
3514 PRINT_FIELD(fc_ll_cc7
, FC_LL_I
, "Intermediate");
3515 PRINT_FIELD(fc_ll_cc7
, FC_LL_L
, "Long");
3516 PRINT_FIELD(fc_ll_cc7
, FC_LL_M
, "Medium");
3517 ql_dbg(ql_dbg_init
, vha
, 0x0196,
3518 "SFP Link Length: %s\n", str
);
3520 memset(str
, 0, STR_LEN
);
3524 PRINT_FIELD(fc_ll_cc7
, FC_LL_SA
, "Short Wave (SA)");
3525 PRINT_FIELD(fc_ll_cc7
, FC_LL_LC
, "Long Wave(LC)");
3526 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SN
, "Short Wave (SN)");
3527 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SL
, "Short Wave (SL)");
3528 PRINT_FIELD(fc_tec_cc8
, FC_TEC_LL
, "Long Wave (LL)");
3529 ql_dbg(ql_dbg_init
, vha
, 0x016e,
3530 "SFP FC Link Tech: %s\n", str
);
3533 ql_dbg(ql_dbg_init
, vha
, 0x016f,
3534 "SFP Distant: %d km\n", a0
->length_km
);
3535 if (a0
->length_100m
)
3536 ql_dbg(ql_dbg_init
, vha
, 0x0170,
3537 "SFP Distant: %d m\n", a0
->length_100m
*100);
3538 if (a0
->length_50um_10m
)
3539 ql_dbg(ql_dbg_init
, vha
, 0x0189,
3540 "SFP Distant (WL=50um): %d m\n", a0
->length_50um_10m
* 10);
3541 if (a0
->length_62um_10m
)
3542 ql_dbg(ql_dbg_init
, vha
, 0x018a,
3543 "SFP Distant (WL=62.5um): %d m\n", a0
->length_62um_10m
* 10);
3544 if (a0
->length_om4_10m
)
3545 ql_dbg(ql_dbg_init
, vha
, 0x0194,
3546 "SFP Distant (OM4): %d m\n", a0
->length_om4_10m
* 10);
3547 if (a0
->length_om3_10m
)
3548 ql_dbg(ql_dbg_init
, vha
, 0x0195,
3549 "SFP Distant (OM3): %d m\n", a0
->length_om3_10m
* 10);
3554 * qla24xx_detect_sfp()
3556 * @vha: adapter state pointer.
3559 * 0 -- Configure firmware to use short-range settings -- normal
3560 * buffer-to-buffer credits.
3562 * 1 -- Configure firmware to use long-range settings -- extra
3563 * buffer-to-buffer credits should be allocated with
3564 * ha->lr_distance containing distance settings from NVRAM or SFP
3568 qla24xx_detect_sfp(scsi_qla_host_t
*vha
)
3571 struct sff_8247_a0
*a
;
3572 struct qla_hw_data
*ha
= vha
->hw
;
3573 struct nvram_81xx
*nv
= ha
->nvram
;
3574 #define LR_DISTANCE_UNKNOWN 2
3575 static const char * const types
[] = { "Short", "Long" };
3576 static const char * const lengths
[] = { "(10km)", "(5km)", "" };
3579 /* Seed with NVRAM settings. */
3581 ha
->flags
.lr_detected
= 0;
3582 if (IS_BPM_RANGE_CAPABLE(ha
) &&
3583 (nv
->enhanced_features
& NEF_LR_DIST_ENABLE
)) {
3585 ha
->flags
.lr_detected
= 1;
3587 (nv
->enhanced_features
>> LR_DIST_NV_POS
)
3591 if (!IS_BPM_ENABLED(vha
))
3593 /* Determine SR/LR capabilities of SFP/Transceiver. */
3594 rc
= qla2x00_read_sfp_dev(vha
, NULL
, 0);
3599 a
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3600 qla2xxx_print_sfp_info(vha
);
3602 ha
->flags
.lr_detected
= 0;
3604 if (ll
& FC_LL_VL
|| ll
& FC_LL_L
) {
3605 /* Long range, track length. */
3606 ha
->flags
.lr_detected
= 1;
3608 if (a
->length_km
> 5 || a
->length_100m
> 50)
3609 ha
->lr_distance
= LR_DISTANCE_10K
;
3611 ha
->lr_distance
= LR_DISTANCE_5K
;
3615 ql_dbg(ql_dbg_async
, vha
, 0x507b,
3616 "SFP detect: %s-Range SFP %s (nvr=%x ll=%x lr=%x lrd=%x).\n",
3617 types
[ha
->flags
.lr_detected
],
3618 ha
->flags
.lr_detected
? lengths
[ha
->lr_distance
] :
3619 lengths
[LR_DISTANCE_UNKNOWN
],
3620 used_nvram
, ll
, ha
->flags
.lr_detected
, ha
->lr_distance
);
3621 return ha
->flags
.lr_detected
;
3625 * qla2x00_setup_chip() - Load and start RISC firmware.
3628 * Returns 0 on success.
3631 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
3634 uint32_t srisc_address
= 0;
3635 struct qla_hw_data
*ha
= vha
->hw
;
3636 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3637 unsigned long flags
;
3638 uint16_t fw_major_version
;
3641 if (IS_P3P_TYPE(ha
)) {
3642 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3643 if (rval
== QLA_SUCCESS
) {
3644 qla2x00_stop_firmware(vha
);
3645 goto enable_82xx_npiv
;
3650 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3651 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3652 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3653 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3654 RD_REG_WORD(®
->hccr
);
3655 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3658 qla81xx_mpi_sync(vha
);
3661 /* Load firmware sequences */
3662 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3663 if (rval
== QLA_SUCCESS
) {
3664 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
3665 "Verifying Checksum of loaded RISC code.\n");
3667 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
3668 if (rval
== QLA_SUCCESS
) {
3669 /* Start firmware execution. */
3670 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3671 "Starting firmware.\n");
3674 ha
->flags
.exlogins_enabled
= 1;
3676 if (qla_is_exch_offld_enabled(vha
))
3677 ha
->flags
.exchoffld_enabled
= 1;
3679 rval
= qla2x00_execute_fw(vha
, srisc_address
);
3680 /* Retrieve firmware information. */
3681 if (rval
== QLA_SUCCESS
) {
3682 /* Enable BPM support? */
3683 if (!done_once
++ && qla24xx_detect_sfp(vha
)) {
3684 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3685 "Re-starting firmware -- BPM.\n");
3686 /* Best-effort - re-init. */
3687 ha
->isp_ops
->reset_chip(vha
);
3688 ha
->isp_ops
->chip_diag(vha
);
3689 goto execute_fw_with_lr
;
3692 if ((IS_QLA83XX(ha
) || IS_QLA27XX(ha
) ||
3694 (ha
->zio_mode
== QLA_ZIO_MODE_6
))
3695 qla27xx_set_zio_threshold(vha
,
3696 ha
->last_zio_threshold
);
3698 rval
= qla2x00_set_exlogins_buffer(vha
);
3699 if (rval
!= QLA_SUCCESS
)
3702 rval
= qla2x00_set_exchoffld_buffer(vha
);
3703 if (rval
!= QLA_SUCCESS
)
3707 fw_major_version
= ha
->fw_major_version
;
3708 if (IS_P3P_TYPE(ha
))
3709 qla82xx_check_md_needed(vha
);
3711 rval
= qla2x00_get_fw_version(vha
);
3712 if (rval
!= QLA_SUCCESS
)
3714 ha
->flags
.npiv_supported
= 0;
3715 if (IS_QLA2XXX_MIDTYPE(ha
) &&
3716 (ha
->fw_attributes
& BIT_2
)) {
3717 ha
->flags
.npiv_supported
= 1;
3718 if ((!ha
->max_npiv_vports
) ||
3719 ((ha
->max_npiv_vports
+ 1) %
3720 MIN_MULTI_ID_FABRIC
))
3721 ha
->max_npiv_vports
=
3722 MIN_MULTI_ID_FABRIC
- 1;
3724 qla2x00_get_resource_cnts(vha
);
3727 * Allocate the array of outstanding commands
3728 * now that we know the firmware resources.
3730 rval
= qla2x00_alloc_outstanding_cmds(ha
,
3732 if (rval
!= QLA_SUCCESS
)
3735 if (!fw_major_version
&& !(IS_P3P_TYPE(ha
)))
3736 qla2x00_alloc_offload_mem(vha
);
3738 if (ql2xallocfwdump
&& !(IS_P3P_TYPE(ha
)))
3739 qla2x00_alloc_fw_dump(vha
);
3745 ql_log(ql_log_fatal
, vha
, 0x00cd,
3746 "ISP Firmware failed checksum.\n");
3750 /* Enable PUREX PASSTHRU */
3752 qla25xx_set_els_cmds_supported(vha
);
3756 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3757 /* Enable proper parity. */
3758 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3761 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
3763 /* SRAM, Instruction RAM and GP RAM parity */
3764 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
3765 RD_REG_WORD(®
->hccr
);
3766 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3769 if (IS_QLA27XX(ha
) || IS_QLA28XX(ha
))
3770 ha
->flags
.fac_supported
= 1;
3771 else if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
3774 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
3775 if (rval
== QLA_SUCCESS
) {
3776 ha
->flags
.fac_supported
= 1;
3777 ha
->fdt_block_size
= size
<< 2;
3779 ql_log(ql_log_warn
, vha
, 0x00ce,
3780 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3781 ha
->fw_major_version
, ha
->fw_minor_version
,
3782 ha
->fw_subminor_version
);
3784 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) ||
3786 ha
->flags
.fac_supported
= 0;
3793 ql_log(ql_log_fatal
, vha
, 0x00cf,
3794 "Setup chip ****FAILED****.\n");
3801 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3802 * @rsp: response queue
3804 * Beginning of request ring has initialization control block already built
3805 * by nvram config routine.
3807 * Returns 0 on success.
3810 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
3815 rsp
->ring_ptr
= rsp
->ring
;
3816 rsp
->ring_index
= 0;
3817 rsp
->status_srb
= NULL
;
3818 pkt
= rsp
->ring_ptr
;
3819 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
3820 pkt
->signature
= RESPONSE_PROCESSED
;
3826 * qla2x00_update_fw_options() - Read and process firmware options.
3829 * Returns 0 on success.
3832 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
3834 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
3835 struct qla_hw_data
*ha
= vha
->hw
;
3837 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
3838 qla2x00_get_fw_options(vha
, ha
->fw_options
);
3840 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3843 /* Serial Link options. */
3844 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
3845 "Serial link options.\n");
3846 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
3847 ha
->fw_seriallink_options
, sizeof(ha
->fw_seriallink_options
));
3849 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
3850 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
3851 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
3854 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
3855 emphasis
= (ha
->fw_seriallink_options
[2] &
3856 (BIT_4
| BIT_3
)) >> 3;
3857 tx_sens
= ha
->fw_seriallink_options
[0] &
3858 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3859 rx_sens
= (ha
->fw_seriallink_options
[0] &
3860 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3861 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
3862 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3865 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
3866 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3867 ha
->fw_options
[10] |= BIT_5
|
3868 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3869 (tx_sens
& (BIT_1
| BIT_0
));
3872 swing
= (ha
->fw_seriallink_options
[2] &
3873 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
3874 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
3875 tx_sens
= ha
->fw_seriallink_options
[1] &
3876 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3877 rx_sens
= (ha
->fw_seriallink_options
[1] &
3878 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3879 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
3880 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3883 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
3884 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3885 ha
->fw_options
[11] |= BIT_5
|
3886 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3887 (tx_sens
& (BIT_1
| BIT_0
));
3891 /* Return command IOCBs without waiting for an ABTS to complete. */
3892 ha
->fw_options
[3] |= BIT_13
;
3895 if (ha
->flags
.enable_led_scheme
)
3896 ha
->fw_options
[2] |= BIT_12
;
3898 /* Detect ISP6312. */
3900 ha
->fw_options
[2] |= BIT_13
;
3902 /* Set Retry FLOGI in case of P2P connection */
3903 if (ha
->operating_mode
== P2P
) {
3904 ha
->fw_options
[2] |= BIT_3
;
3905 ql_dbg(ql_dbg_disc
, vha
, 0x2100,
3906 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3907 __func__
, ha
->fw_options
[2]);
3910 /* Update firmware options. */
3911 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3915 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
3918 struct qla_hw_data
*ha
= vha
->hw
;
3920 if (IS_P3P_TYPE(ha
))
3923 /* Hold status IOCBs until ABTS response received. */
3925 ha
->fw_options
[3] |= BIT_12
;
3927 /* Set Retry FLOGI in case of P2P connection */
3928 if (ha
->operating_mode
== P2P
) {
3929 ha
->fw_options
[2] |= BIT_3
;
3930 ql_dbg(ql_dbg_disc
, vha
, 0x2101,
3931 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3932 __func__
, ha
->fw_options
[2]);
3935 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3936 if (ql2xmvasynctoatio
&&
3937 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
))) {
3938 if (qla_tgt_mode_enabled(vha
) ||
3939 qla_dual_mode_enabled(vha
))
3940 ha
->fw_options
[2] |= BIT_11
;
3942 ha
->fw_options
[2] &= ~BIT_11
;
3945 if (IS_QLA25XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
) ||
3948 * Tell FW to track each exchange to prevent
3949 * driver from using stale exchange.
3951 if (qla_tgt_mode_enabled(vha
) ||
3952 qla_dual_mode_enabled(vha
))
3953 ha
->fw_options
[2] |= BIT_4
;
3955 ha
->fw_options
[2] &= ~BIT_4
;
3957 /* Reserve 1/2 of emergency exchanges for ELS.*/
3958 if (qla2xuseresexchforels
)
3959 ha
->fw_options
[2] |= BIT_8
;
3961 ha
->fw_options
[2] &= ~BIT_8
;
3965 ha
->fw_options
[1] |= ADD_FO1_ENABLE_PUREX_IOCB
;
3967 /* Enable Async 8130/8131 events -- transceiver insertion/removal */
3968 if (IS_BPM_RANGE_CAPABLE(ha
))
3969 ha
->fw_options
[3] |= BIT_10
;
3971 ql_dbg(ql_dbg_init
, vha
, 0x00e8,
3972 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3973 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
3974 ha
->fw_options
[3], vha
->host
->active_mode
);
3976 if (ha
->fw_options
[1] || ha
->fw_options
[2] || ha
->fw_options
[3])
3977 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3979 /* Update Serial Link options. */
3980 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
3983 rval
= qla2x00_set_serdes_params(vha
,
3984 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
3985 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
3986 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
3987 if (rval
!= QLA_SUCCESS
) {
3988 ql_log(ql_log_warn
, vha
, 0x0104,
3989 "Unable to update Serial Link options (%x).\n", rval
);
3994 qla2x00_config_rings(struct scsi_qla_host
*vha
)
3996 struct qla_hw_data
*ha
= vha
->hw
;
3997 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3998 struct req_que
*req
= ha
->req_q_map
[0];
3999 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4001 /* Setup ring parameters in initialization control block. */
4002 ha
->init_cb
->request_q_outpointer
= cpu_to_le16(0);
4003 ha
->init_cb
->response_q_inpointer
= cpu_to_le16(0);
4004 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
4005 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
4006 put_unaligned_le64(req
->dma
, &ha
->init_cb
->request_q_address
);
4007 put_unaligned_le64(rsp
->dma
, &ha
->init_cb
->response_q_address
);
4009 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
4010 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
4011 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
4012 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
4013 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
4017 qla24xx_config_rings(struct scsi_qla_host
*vha
)
4019 struct qla_hw_data
*ha
= vha
->hw
;
4020 device_reg_t
*reg
= ISP_QUE_REG(ha
, 0);
4021 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
4022 struct qla_msix_entry
*msix
;
4023 struct init_cb_24xx
*icb
;
4025 struct req_que
*req
= ha
->req_q_map
[0];
4026 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
4028 /* Setup ring parameters in initialization control block. */
4029 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
4030 icb
->request_q_outpointer
= cpu_to_le16(0);
4031 icb
->response_q_inpointer
= cpu_to_le16(0);
4032 icb
->request_q_length
= cpu_to_le16(req
->length
);
4033 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
4034 put_unaligned_le64(req
->dma
, &icb
->request_q_address
);
4035 put_unaligned_le64(rsp
->dma
, &icb
->response_q_address
);
4037 /* Setup ATIO queue dma pointers for target mode */
4038 icb
->atio_q_inpointer
= cpu_to_le16(0);
4039 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
4040 put_unaligned_le64(ha
->tgt
.atio_dma
, &icb
->atio_q_address
);
4042 if (IS_SHADOW_REG_CAPABLE(ha
))
4043 icb
->firmware_options_2
|= cpu_to_le32(BIT_30
|BIT_29
);
4045 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
) ||
4047 icb
->qos
= cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
4048 icb
->rid
= cpu_to_le16(rid
);
4049 if (ha
->flags
.msix_enabled
) {
4050 msix
= &ha
->msix_entries
[1];
4051 ql_dbg(ql_dbg_init
, vha
, 0x0019,
4052 "Registering vector 0x%x for base que.\n",
4054 icb
->msix
= cpu_to_le16(msix
->entry
);
4056 /* Use alternate PCI bus number */
4058 icb
->firmware_options_2
|= cpu_to_le32(BIT_19
);
4059 /* Use alternate PCI devfn */
4061 icb
->firmware_options_2
|= cpu_to_le32(BIT_18
);
4063 /* Use Disable MSIX Handshake mode for capable adapters */
4064 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
4065 (ha
->flags
.msix_enabled
)) {
4066 icb
->firmware_options_2
&= cpu_to_le32(~BIT_22
);
4067 ha
->flags
.disable_msix_handshake
= 1;
4068 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
4069 "MSIX Handshake Disable Mode turned on.\n");
4071 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
4073 icb
->firmware_options_2
|= cpu_to_le32(BIT_23
);
4075 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
4076 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
4077 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
4078 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
4080 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
4081 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
4082 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
4083 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
4086 qlt_24xx_config_rings(vha
);
4088 /* If the user has configured the speed, set it here */
4089 if (ha
->set_data_rate
) {
4090 ql_dbg(ql_dbg_init
, vha
, 0x00fd,
4091 "Speed set by user : %s Gbps \n",
4092 qla2x00_get_link_speed_str(ha
, ha
->set_data_rate
));
4093 icb
->firmware_options_3
= (ha
->set_data_rate
<< 13);
4097 RD_REG_DWORD(&ioreg
->hccr
);
4101 * qla2x00_init_rings() - Initializes firmware.
4104 * Beginning of request ring has initialization control block already built
4105 * by nvram config routine.
4107 * Returns 0 on success.
4110 qla2x00_init_rings(scsi_qla_host_t
*vha
)
4113 unsigned long flags
= 0;
4115 struct qla_hw_data
*ha
= vha
->hw
;
4116 struct req_que
*req
;
4117 struct rsp_que
*rsp
;
4118 struct mid_init_cb_24xx
*mid_init_cb
=
4119 (struct mid_init_cb_24xx
*) ha
->init_cb
;
4121 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4123 /* Clear outstanding commands array. */
4124 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
4125 req
= ha
->req_q_map
[que
];
4126 if (!req
|| !test_bit(que
, ha
->req_qid_map
))
4128 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
4130 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
4131 req
->outstanding_cmds
[cnt
] = NULL
;
4133 req
->current_outstanding_cmd
= 1;
4135 /* Initialize firmware. */
4136 req
->ring_ptr
= req
->ring
;
4137 req
->ring_index
= 0;
4138 req
->cnt
= req
->length
;
4141 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
4142 rsp
= ha
->rsp_q_map
[que
];
4143 if (!rsp
|| !test_bit(que
, ha
->rsp_qid_map
))
4145 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
4147 /* Initialize response queue entries */
4149 qlafx00_init_response_q_entries(rsp
);
4151 qla2x00_init_response_q_entries(rsp
);
4154 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
4155 ha
->tgt
.atio_ring_index
= 0;
4156 /* Initialize ATIO queue entries */
4157 qlt_init_atio_q_entries(vha
);
4159 ha
->isp_ops
->config_rings(vha
);
4161 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4163 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
4165 if (IS_QLAFX00(ha
)) {
4166 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
4170 /* Update any ISP specific firmware options before initialization. */
4171 ha
->isp_ops
->update_fw_options(vha
);
4173 if (ha
->flags
.npiv_supported
) {
4174 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
4175 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
4176 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
4179 if (IS_FWI2_CAPABLE(ha
)) {
4180 mid_init_cb
->options
= cpu_to_le16(BIT_1
);
4181 mid_init_cb
->init_cb
.execution_throttle
=
4182 cpu_to_le16(ha
->cur_fw_xcb_count
);
4183 ha
->flags
.dport_enabled
=
4184 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_7
) != 0;
4185 ql_dbg(ql_dbg_init
, vha
, 0x0191, "DPORT Support: %s.\n",
4186 (ha
->flags
.dport_enabled
) ? "enabled" : "disabled");
4187 /* FA-WWPN Status */
4188 ha
->flags
.fawwpn_enabled
=
4189 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_6
) != 0;
4190 ql_dbg(ql_dbg_init
, vha
, 0x00bc, "FA-WWPN Support: %s.\n",
4191 (ha
->flags
.fawwpn_enabled
) ? "enabled" : "disabled");
4194 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
4197 ql_log(ql_log_fatal
, vha
, 0x00d2,
4198 "Init Firmware **** FAILED ****.\n");
4200 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
4201 "Init Firmware -- success.\n");
4203 vha
->u_ql2xexchoffld
= vha
->u_ql2xiniexchg
= 0;
4210 * qla2x00_fw_ready() - Waits for firmware ready.
4213 * Returns 0 on success.
4216 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
4219 unsigned long wtime
, mtime
, cs84xx_time
;
4220 uint16_t min_wait
; /* Minimum wait time if loop is down */
4221 uint16_t wait_time
; /* Wait time if loop is coming ready */
4223 struct qla_hw_data
*ha
= vha
->hw
;
4225 if (IS_QLAFX00(vha
->hw
))
4226 return qlafx00_fw_ready(vha
);
4230 /* Time to wait for loop down */
4231 if (IS_P3P_TYPE(ha
))
4237 * Firmware should take at most one RATOV to login, plus 5 seconds for
4238 * our own processing.
4240 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
4241 wait_time
= min_wait
;
4244 /* Min wait time if loop down */
4245 mtime
= jiffies
+ (min_wait
* HZ
);
4247 /* wait time before firmware ready */
4248 wtime
= jiffies
+ (wait_time
* HZ
);
4250 /* Wait for ISP to finish LIP */
4251 if (!vha
->flags
.init_done
)
4252 ql_log(ql_log_info
, vha
, 0x801e,
4253 "Waiting for LIP to complete.\n");
4256 memset(state
, -1, sizeof(state
));
4257 rval
= qla2x00_get_firmware_state(vha
, state
);
4258 if (rval
== QLA_SUCCESS
) {
4259 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
4260 vha
->device_flags
&= ~DFLG_NO_CABLE
;
4262 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
4263 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
4264 "fw_state=%x 84xx=%x.\n", state
[0],
4266 if ((state
[2] & FSTATE_LOGGED_IN
) &&
4267 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
4268 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
4269 "Sending verify iocb.\n");
4271 cs84xx_time
= jiffies
;
4272 rval
= qla84xx_init_chip(vha
);
4273 if (rval
!= QLA_SUCCESS
) {
4276 "Init chip failed.\n");
4280 /* Add time taken to initialize. */
4281 cs84xx_time
= jiffies
- cs84xx_time
;
4282 wtime
+= cs84xx_time
;
4283 mtime
+= cs84xx_time
;
4284 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
4285 "Increasing wait time by %ld. "
4286 "New time %ld.\n", cs84xx_time
,
4289 } else if (state
[0] == FSTATE_READY
) {
4290 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
4291 "F/W Ready - OK.\n");
4293 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
4294 &ha
->login_timeout
, &ha
->r_a_tov
);
4300 rval
= QLA_FUNCTION_FAILED
;
4302 if (atomic_read(&vha
->loop_down_timer
) &&
4303 state
[0] != FSTATE_READY
) {
4304 /* Loop down. Timeout on min_wait for states
4305 * other than Wait for Login.
4307 if (time_after_eq(jiffies
, mtime
)) {
4308 ql_log(ql_log_info
, vha
, 0x8038,
4309 "Cable is unplugged...\n");
4311 vha
->device_flags
|= DFLG_NO_CABLE
;
4316 /* Mailbox cmd failed. Timeout on min_wait. */
4317 if (time_after_eq(jiffies
, mtime
) ||
4318 ha
->flags
.isp82xx_fw_hung
)
4322 if (time_after_eq(jiffies
, wtime
))
4325 /* Delay for a while */
4329 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
4330 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state
[0],
4331 state
[1], state
[2], state
[3], state
[4], state
[5], jiffies
);
4333 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
4334 ql_log(ql_log_warn
, vha
, 0x803b,
4335 "Firmware ready **** FAILED ****.\n");
4342 * qla2x00_configure_hba
4343 * Setup adapter context.
4346 * ha = adapter state pointer.
4355 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
4364 char connect_type
[22];
4365 struct qla_hw_data
*ha
= vha
->hw
;
4366 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
4368 unsigned long flags
;
4370 /* Get host addresses. */
4371 rval
= qla2x00_get_adapter_id(vha
,
4372 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
4373 if (rval
!= QLA_SUCCESS
) {
4374 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
4375 IS_CNA_CAPABLE(ha
) ||
4376 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
4377 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
4378 "Loop is in a transition state.\n");
4380 ql_log(ql_log_warn
, vha
, 0x2009,
4381 "Unable to get host loop ID.\n");
4382 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
4383 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
4384 ql_log(ql_log_warn
, vha
, 0x1151,
4385 "Doing link init.\n");
4386 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
4389 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4395 ql_log(ql_log_info
, vha
, 0x200a,
4396 "Cannot get topology - retrying.\n");
4397 return (QLA_FUNCTION_FAILED
);
4400 vha
->loop_id
= loop_id
;
4403 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
4404 ha
->operating_mode
= LOOP
;
4409 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
4410 ha
->current_topology
= ISP_CFG_NL
;
4411 strcpy(connect_type
, "(Loop)");
4415 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
4416 ha
->switch_cap
= sw_cap
;
4417 ha
->current_topology
= ISP_CFG_FL
;
4418 strcpy(connect_type
, "(FL_Port)");
4422 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
4423 ha
->operating_mode
= P2P
;
4424 ha
->current_topology
= ISP_CFG_N
;
4425 strcpy(connect_type
, "(N_Port-to-N_Port)");
4429 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
4430 ha
->switch_cap
= sw_cap
;
4431 ha
->operating_mode
= P2P
;
4432 ha
->current_topology
= ISP_CFG_F
;
4433 strcpy(connect_type
, "(F_Port)");
4437 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
4438 "HBA in unknown topology %x, using NL.\n", topo
);
4439 ha
->current_topology
= ISP_CFG_NL
;
4440 strcpy(connect_type
, "(Loop)");
4444 /* Save Host port and loop ID. */
4445 /* byte order - Big Endian */
4446 id
.b
.domain
= domain
;
4450 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4451 if (!(topo
== 2 && ha
->flags
.n2n_bigger
))
4452 qlt_update_host_map(vha
, id
);
4453 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4455 if (!vha
->flags
.init_done
)
4456 ql_log(ql_log_info
, vha
, 0x2010,
4457 "Topology - %s, Host Loop address 0x%x.\n",
4458 connect_type
, vha
->loop_id
);
4464 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
4469 uint64_t zero
[2] = { 0 };
4470 struct qla_hw_data
*ha
= vha
->hw
;
4471 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
4472 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
4474 if (len
> sizeof(zero
))
4476 if (memcmp(model
, &zero
, len
) != 0) {
4477 memcpy(ha
->model_number
, model
, len
);
4478 st
= en
= ha
->model_number
;
4481 if (*en
!= 0x20 && *en
!= 0x00)
4486 index
= (ha
->pdev
->subsystem_device
& 0xff);
4488 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4489 index
< QLA_MODEL_NAMES
)
4490 strlcpy(ha
->model_desc
,
4491 qla2x00_model_name
[index
* 2 + 1],
4492 sizeof(ha
->model_desc
));
4494 index
= (ha
->pdev
->subsystem_device
& 0xff);
4496 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4497 index
< QLA_MODEL_NAMES
) {
4498 strlcpy(ha
->model_number
,
4499 qla2x00_model_name
[index
* 2],
4500 sizeof(ha
->model_number
));
4501 strlcpy(ha
->model_desc
,
4502 qla2x00_model_name
[index
* 2 + 1],
4503 sizeof(ha
->model_desc
));
4505 strlcpy(ha
->model_number
, def
,
4506 sizeof(ha
->model_number
));
4509 if (IS_FWI2_CAPABLE(ha
))
4510 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
4511 sizeof(ha
->model_desc
));
4514 /* On sparc systems, obtain port and node WWN from firmware
4517 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
4520 struct qla_hw_data
*ha
= vha
->hw
;
4521 struct pci_dev
*pdev
= ha
->pdev
;
4522 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4526 val
= of_get_property(dp
, "port-wwn", &len
);
4527 if (val
&& len
>= WWN_SIZE
)
4528 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4530 val
= of_get_property(dp
, "node-wwn", &len
);
4531 if (val
&& len
>= WWN_SIZE
)
4532 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4537 * NVRAM configuration for ISP 2xxx
4540 * ha = adapter block pointer.
4543 * initialization control block in response_ring
4544 * host adapters parameters in host adapter block
4550 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
4555 uint8_t *dptr1
, *dptr2
;
4556 struct qla_hw_data
*ha
= vha
->hw
;
4557 init_cb_t
*icb
= ha
->init_cb
;
4558 nvram_t
*nv
= ha
->nvram
;
4559 uint8_t *ptr
= ha
->nvram
;
4560 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4564 /* Determine NVRAM starting address. */
4565 ha
->nvram_size
= sizeof(*nv
);
4567 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
4568 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
4569 ha
->nvram_base
= 0x80;
4571 /* Get NVRAM data and calculate checksum. */
4572 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
4573 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
4576 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
4577 "Contents of NVRAM.\n");
4578 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
4579 nv
, ha
->nvram_size
);
4581 /* Bad NVRAM data, set defaults parameters. */
4582 if (chksum
|| memcmp("ISP ", nv
->id
, sizeof(nv
->id
)) ||
4583 nv
->nvram_version
< 1) {
4584 /* Reset NVRAM data. */
4585 ql_log(ql_log_warn
, vha
, 0x0064,
4586 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4587 chksum
, nv
->id
, nv
->nvram_version
);
4588 ql_log(ql_log_warn
, vha
, 0x0065,
4590 "functioning (yet invalid -- WWPN) defaults.\n");
4593 * Set default initialization control block.
4595 memset(nv
, 0, ha
->nvram_size
);
4596 nv
->parameter_block_version
= ICB_VERSION
;
4598 if (IS_QLA23XX(ha
)) {
4599 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4600 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4601 nv
->add_firmware_options
[0] = BIT_5
;
4602 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4603 nv
->frame_payload_size
= 2048;
4604 nv
->special_options
[1] = BIT_7
;
4605 } else if (IS_QLA2200(ha
)) {
4606 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4607 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4608 nv
->add_firmware_options
[0] = BIT_5
;
4609 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4610 nv
->frame_payload_size
= 1024;
4611 } else if (IS_QLA2100(ha
)) {
4612 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
4613 nv
->firmware_options
[1] = BIT_5
;
4614 nv
->frame_payload_size
= 1024;
4617 nv
->max_iocb_allocation
= cpu_to_le16(256);
4618 nv
->execution_throttle
= cpu_to_le16(16);
4619 nv
->retry_count
= 8;
4620 nv
->retry_delay
= 1;
4622 nv
->port_name
[0] = 33;
4623 nv
->port_name
[3] = 224;
4624 nv
->port_name
[4] = 139;
4626 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
4628 nv
->login_timeout
= 4;
4631 * Set default host adapter parameters
4633 nv
->host_p
[1] = BIT_2
;
4634 nv
->reset_delay
= 5;
4635 nv
->port_down_retry_count
= 8;
4636 nv
->max_luns_per_target
= cpu_to_le16(8);
4637 nv
->link_down_timeout
= 60;
4642 /* Reset Initialization control block */
4643 memset(icb
, 0, ha
->init_cb_size
);
4646 * Setup driver NVRAM options.
4648 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
4649 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
4650 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
4651 nv
->firmware_options
[1] &= ~BIT_4
;
4653 if (IS_QLA23XX(ha
)) {
4654 nv
->firmware_options
[0] |= BIT_2
;
4655 nv
->firmware_options
[0] &= ~BIT_3
;
4656 nv
->special_options
[0] &= ~BIT_6
;
4657 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
4659 if (IS_QLA2300(ha
)) {
4660 if (ha
->fb_rev
== FPM_2310
) {
4661 strcpy(ha
->model_number
, "QLA2310");
4663 strcpy(ha
->model_number
, "QLA2300");
4666 qla2x00_set_model_info(vha
, nv
->model_number
,
4667 sizeof(nv
->model_number
), "QLA23xx");
4669 } else if (IS_QLA2200(ha
)) {
4670 nv
->firmware_options
[0] |= BIT_2
;
4672 * 'Point-to-point preferred, else loop' is not a safe
4673 * connection mode setting.
4675 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
4677 /* Force 'loop preferred, else point-to-point'. */
4678 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
4679 nv
->add_firmware_options
[0] |= BIT_5
;
4681 strcpy(ha
->model_number
, "QLA22xx");
4682 } else /*if (IS_QLA2100(ha))*/ {
4683 strcpy(ha
->model_number
, "QLA2100");
4687 * Copy over NVRAM RISC parameter block to initialization control block.
4689 dptr1
= (uint8_t *)icb
;
4690 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
4691 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
4693 *dptr1
++ = *dptr2
++;
4695 /* Copy 2nd half. */
4696 dptr1
= (uint8_t *)icb
->add_firmware_options
;
4697 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
4699 *dptr1
++ = *dptr2
++;
4700 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
4701 /* Use alternate WWN? */
4702 if (nv
->host_p
[1] & BIT_7
) {
4703 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4704 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4707 /* Prepare nodename */
4708 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
4710 * Firmware will apply the following mask if the nodename was
4713 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4714 icb
->node_name
[0] &= 0xF0;
4718 * Set host adapter parameters.
4722 * BIT_7 in the host-parameters section allows for modification to
4723 * internal driver logging.
4725 if (nv
->host_p
[0] & BIT_7
)
4726 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
4727 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
4728 /* Always load RISC code on non ISP2[12]00 chips. */
4729 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
4730 ha
->flags
.disable_risc_code_load
= 0;
4731 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
4732 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
4733 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
4734 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
4735 ha
->flags
.disable_serdes
= 0;
4737 ha
->operating_mode
=
4738 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4740 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
4741 sizeof(ha
->fw_seriallink_options
));
4743 /* save HBA serial number */
4744 ha
->serial0
= icb
->port_name
[5];
4745 ha
->serial1
= icb
->port_name
[6];
4746 ha
->serial2
= icb
->port_name
[7];
4747 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4748 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4750 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
4752 ha
->retry_count
= nv
->retry_count
;
4754 /* Set minimum login_timeout to 4 seconds. */
4755 if (nv
->login_timeout
!= ql2xlogintimeout
)
4756 nv
->login_timeout
= ql2xlogintimeout
;
4757 if (nv
->login_timeout
< 4)
4758 nv
->login_timeout
= 4;
4759 ha
->login_timeout
= nv
->login_timeout
;
4761 /* Set minimum RATOV to 100 tenths of a second. */
4764 ha
->loop_reset_delay
= nv
->reset_delay
;
4766 /* Link Down Timeout = 0:
4768 * When Port Down timer expires we will start returning
4769 * I/O's to OS with "DID_NO_CONNECT".
4771 * Link Down Timeout != 0:
4773 * The driver waits for the link to come up after link down
4774 * before returning I/Os to OS with "DID_NO_CONNECT".
4776 if (nv
->link_down_timeout
== 0) {
4777 ha
->loop_down_abort_time
=
4778 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4780 ha
->link_down_timeout
= nv
->link_down_timeout
;
4781 ha
->loop_down_abort_time
=
4782 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4786 * Need enough time to try and get the port back.
4788 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
4789 if (qlport_down_retry
)
4790 ha
->port_down_retry_count
= qlport_down_retry
;
4791 /* Set login_retry_count */
4792 ha
->login_retry_count
= nv
->retry_count
;
4793 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
4794 ha
->port_down_retry_count
> 3)
4795 ha
->login_retry_count
= ha
->port_down_retry_count
;
4796 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4797 ha
->login_retry_count
= ha
->port_down_retry_count
;
4798 if (ql2xloginretrycount
)
4799 ha
->login_retry_count
= ql2xloginretrycount
;
4801 icb
->lun_enables
= cpu_to_le16(0);
4802 icb
->command_resource_count
= 0;
4803 icb
->immediate_notify_resource_count
= 0;
4804 icb
->timeout
= cpu_to_le16(0);
4806 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
4808 icb
->firmware_options
[0] &= ~BIT_3
;
4809 icb
->add_firmware_options
[0] &=
4810 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4811 icb
->add_firmware_options
[0] |= BIT_2
;
4812 icb
->response_accumulation_timer
= 3;
4813 icb
->interrupt_delay_timer
= 5;
4815 vha
->flags
.process_response_queue
= 1;
4818 if (!vha
->flags
.init_done
) {
4819 ha
->zio_mode
= icb
->add_firmware_options
[0] &
4820 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4821 ha
->zio_timer
= icb
->interrupt_delay_timer
?
4822 icb
->interrupt_delay_timer
: 2;
4824 icb
->add_firmware_options
[0] &=
4825 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4826 vha
->flags
.process_response_queue
= 0;
4827 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4828 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4830 ql_log(ql_log_info
, vha
, 0x0068,
4831 "ZIO mode %d enabled; timer delay (%d us).\n",
4832 ha
->zio_mode
, ha
->zio_timer
* 100);
4834 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
4835 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
4836 vha
->flags
.process_response_queue
= 1;
4841 ql_log(ql_log_warn
, vha
, 0x0069,
4842 "NVRAM configuration failed.\n");
4848 qla2x00_rport_del(void *data
)
4850 fc_port_t
*fcport
= data
;
4851 struct fc_rport
*rport
;
4852 unsigned long flags
;
4854 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
4855 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
4856 fcport
->drport
= NULL
;
4857 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
4859 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210b,
4860 "%s %8phN. rport %p roles %x\n",
4861 __func__
, fcport
->port_name
, rport
,
4864 fc_remote_port_delete(rport
);
4868 void qla2x00_set_fcport_state(fc_port_t
*fcport
, int state
)
4872 old_state
= atomic_read(&fcport
->state
);
4873 atomic_set(&fcport
->state
, state
);
4875 /* Don't print state transitions during initial allocation of fcport */
4876 if (old_state
&& old_state
!= state
) {
4877 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x207d,
4878 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4879 fcport
->port_name
, port_state_str
[old_state
],
4880 port_state_str
[state
], fcport
->d_id
.b
.domain
,
4881 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
4886 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4888 * @flags: allocation flags
4890 * Returns a pointer to the allocated fcport, or NULL, if none available.
4893 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
4897 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
4901 fcport
->ct_desc
.ct_sns
= dma_alloc_coherent(&vha
->hw
->pdev
->dev
,
4902 sizeof(struct ct_sns_pkt
), &fcport
->ct_desc
.ct_sns_dma
,
4904 if (!fcport
->ct_desc
.ct_sns
) {
4905 ql_log(ql_log_warn
, vha
, 0xd049,
4906 "Failed to allocate ct_sns request.\n");
4911 /* Setup fcport template structure. */
4913 fcport
->port_type
= FCT_UNKNOWN
;
4914 fcport
->loop_id
= FC_NO_LOOP_ID
;
4915 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
4916 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
4917 fcport
->fp_speed
= PORT_SPEED_UNKNOWN
;
4919 fcport
->disc_state
= DSC_DELETED
;
4920 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4921 fcport
->deleted
= QLA_SESS_DELETED
;
4922 fcport
->login_retry
= vha
->hw
->login_retry_count
;
4923 fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
4924 fcport
->logout_on_delete
= 1;
4926 if (!fcport
->ct_desc
.ct_sns
) {
4927 ql_log(ql_log_warn
, vha
, 0xd049,
4928 "Failed to allocate ct_sns request.\n");
4933 INIT_WORK(&fcport
->del_work
, qla24xx_delete_sess_fn
);
4934 INIT_WORK(&fcport
->free_work
, qlt_free_session_done
);
4935 INIT_WORK(&fcport
->reg_work
, qla_register_fcport_fn
);
4936 INIT_LIST_HEAD(&fcport
->gnl_entry
);
4937 INIT_LIST_HEAD(&fcport
->list
);
4943 qla2x00_free_fcport(fc_port_t
*fcport
)
4945 if (fcport
->ct_desc
.ct_sns
) {
4946 dma_free_coherent(&fcport
->vha
->hw
->pdev
->dev
,
4947 sizeof(struct ct_sns_pkt
), fcport
->ct_desc
.ct_sns
,
4948 fcport
->ct_desc
.ct_sns_dma
);
4950 fcport
->ct_desc
.ct_sns
= NULL
;
4952 list_del(&fcport
->list
);
4953 qla2x00_clear_loop_id(fcport
);
4958 * qla2x00_configure_loop
4959 * Updates Fibre Channel Device Database with what is actually on loop.
4962 * ha = adapter block pointer.
4967 * 2 = database was full and device was not configured.
4970 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
4973 unsigned long flags
, save_flags
;
4974 struct qla_hw_data
*ha
= vha
->hw
;
4978 /* Get Initiator ID */
4979 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
4980 rval
= qla2x00_configure_hba(vha
);
4981 if (rval
!= QLA_SUCCESS
) {
4982 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
4983 "Unable to configure HBA.\n");
4988 save_flags
= flags
= vha
->dpc_flags
;
4989 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
4990 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
4993 * If we have both an RSCN and PORT UPDATE pending then handle them
4994 * both at the same time.
4996 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4997 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4999 qla2x00_get_data_rate(vha
);
5001 /* Determine what we need to do */
5002 if ((ha
->current_topology
== ISP_CFG_FL
||
5003 ha
->current_topology
== ISP_CFG_F
) &&
5004 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
5006 set_bit(RSCN_UPDATE
, &flags
);
5007 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
5009 } else if (ha
->current_topology
== ISP_CFG_NL
||
5010 ha
->current_topology
== ISP_CFG_N
) {
5011 clear_bit(RSCN_UPDATE
, &flags
);
5012 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
5013 } else if (!vha
->flags
.online
||
5014 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
5015 set_bit(RSCN_UPDATE
, &flags
);
5016 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
5019 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
5020 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
5021 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
5022 "Loop resync needed, failing.\n");
5023 rval
= QLA_FUNCTION_FAILED
;
5025 rval
= qla2x00_configure_local_loop(vha
);
5028 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
5029 if (LOOP_TRANSITION(vha
)) {
5030 ql_dbg(ql_dbg_disc
, vha
, 0x2099,
5031 "Needs RSCN update and loop transition.\n");
5032 rval
= QLA_FUNCTION_FAILED
;
5035 rval
= qla2x00_configure_fabric(vha
);
5038 if (rval
== QLA_SUCCESS
) {
5039 if (atomic_read(&vha
->loop_down_timer
) ||
5040 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
5041 rval
= QLA_FUNCTION_FAILED
;
5043 atomic_set(&vha
->loop_state
, LOOP_READY
);
5044 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
5046 ha
->flags
.fw_init_done
= 1;
5049 * Process any ATIO queue entries that came in
5050 * while we weren't online.
5052 if (qla_tgt_mode_enabled(vha
) ||
5053 qla_dual_mode_enabled(vha
)) {
5054 spin_lock_irqsave(&ha
->tgt
.atio_lock
, flags
);
5055 qlt_24xx_process_atio_queue(vha
, 0);
5056 spin_unlock_irqrestore(&ha
->tgt
.atio_lock
,
5063 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
5064 "%s *** FAILED ***.\n", __func__
);
5066 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
5067 "%s: exiting normally.\n", __func__
);
5070 /* Restore state if a resync event occurred during processing */
5071 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
5072 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
5073 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5074 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
5075 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
5083 * qla2x00_configure_local_loop
5084 * Updates Fibre Channel Device Database with local loop devices.
5087 * ha = adapter block pointer.
5093 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
5098 fc_port_t
*fcport
, *new_fcport
;
5102 struct gid_list_info
*gid
;
5104 uint8_t domain
, area
, al_pa
;
5105 struct qla_hw_data
*ha
= vha
->hw
;
5106 unsigned long flags
;
5108 /* Inititae N2N login. */
5110 if (test_and_clear_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
)) {
5114 memset(ha
->init_cb
, 0, ha
->init_cb_size
);
5115 sz
= min_t(int, sizeof(struct els_plogi_payload
),
5117 rval
= qla24xx_get_port_login_templ(vha
,
5118 ha
->init_cb_dma
, (void *)ha
->init_cb
, sz
);
5119 if (rval
== QLA_SUCCESS
) {
5120 __be32
*q
= &ha
->plogi_els_payld
.data
[0];
5122 bp
= (uint32_t *)ha
->init_cb
;
5123 cpu_to_be32_array(q
, bp
, sz
/ 4);
5125 memcpy(bp
, q
, sizeof(ha
->plogi_els_payld
.data
));
5127 ql_dbg(ql_dbg_init
, vha
, 0x00d1,
5128 "PLOGI ELS param read fail.\n");
5133 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5134 if (fcport
->n2n_flag
) {
5135 qla24xx_fcport_handle_login(vha
, fcport
);
5140 spin_lock_irqsave(&vha
->work_lock
, flags
);
5141 vha
->scan
.scan_retry
++;
5142 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
5144 if (vha
->scan
.scan_retry
< MAX_SCAN_RETRIES
) {
5145 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5146 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5148 return QLA_FUNCTION_FAILED
;
5153 entries
= MAX_FIBRE_DEVICES_LOOP
;
5155 /* Get list of logged in devices. */
5156 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
5157 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
5159 if (rval
!= QLA_SUCCESS
)
5162 ql_dbg(ql_dbg_disc
, vha
, 0x2011,
5163 "Entries in ID list (%d).\n", entries
);
5164 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
5165 ha
->gid_list
, entries
* sizeof(*ha
->gid_list
));
5168 spin_lock_irqsave(&vha
->work_lock
, flags
);
5169 vha
->scan
.scan_retry
++;
5170 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
5172 if (vha
->scan
.scan_retry
< MAX_SCAN_RETRIES
) {
5173 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5174 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5177 vha
->scan
.scan_retry
= 0;
5180 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5181 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5184 /* Allocate temporary fcport for any new fcports discovered. */
5185 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5186 if (new_fcport
== NULL
) {
5187 ql_log(ql_log_warn
, vha
, 0x2012,
5188 "Memory allocation failed for fcport.\n");
5189 rval
= QLA_MEMORY_ALLOC_FAILED
;
5192 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5194 /* Add devices to port list. */
5196 for (index
= 0; index
< entries
; index
++) {
5197 domain
= gid
->domain
;
5200 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
5201 loop_id
= gid
->loop_id_2100
;
5203 loop_id
= le16_to_cpu(gid
->loop_id
);
5204 gid
= (void *)gid
+ ha
->gid_list_info_size
;
5206 /* Bypass reserved domain fields. */
5207 if ((domain
& 0xf0) == 0xf0)
5210 /* Bypass if not same domain and area of adapter. */
5211 if (area
&& domain
&& ((area
!= vha
->d_id
.b
.area
) ||
5212 (domain
!= vha
->d_id
.b
.domain
)) &&
5213 (ha
->current_topology
== ISP_CFG_NL
))
5217 /* Bypass invalid local loop ID. */
5218 if (loop_id
> LAST_LOCAL_LOOP_ID
)
5221 memset(new_fcport
->port_name
, 0, WWN_SIZE
);
5223 /* Fill in member data. */
5224 new_fcport
->d_id
.b
.domain
= domain
;
5225 new_fcport
->d_id
.b
.area
= area
;
5226 new_fcport
->d_id
.b
.al_pa
= al_pa
;
5227 new_fcport
->loop_id
= loop_id
;
5228 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5230 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
5231 if (rval2
!= QLA_SUCCESS
) {
5232 ql_dbg(ql_dbg_disc
, vha
, 0x2097,
5233 "Failed to retrieve fcport information "
5234 "-- get_port_database=%x, loop_id=0x%04x.\n",
5235 rval2
, new_fcport
->loop_id
);
5236 /* Skip retry if N2N */
5237 if (ha
->current_topology
!= ISP_CFG_N
) {
5238 ql_dbg(ql_dbg_disc
, vha
, 0x2105,
5239 "Scheduling resync.\n");
5240 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5245 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5246 /* Check for matching device in port list. */
5249 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5250 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5254 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5255 fcport
->loop_id
= new_fcport
->loop_id
;
5256 fcport
->port_type
= new_fcport
->port_type
;
5257 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5258 memcpy(fcport
->node_name
, new_fcport
->node_name
,
5260 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5266 /* New device, add to fcports list. */
5267 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5269 /* Allocate a new replacement fcport. */
5270 fcport
= new_fcport
;
5272 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5274 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5276 if (new_fcport
== NULL
) {
5277 ql_log(ql_log_warn
, vha
, 0xd031,
5278 "Failed to allocate memory for fcport.\n");
5279 rval
= QLA_MEMORY_ALLOC_FAILED
;
5282 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5283 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
5286 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5288 /* Base iIDMA settings on HBA port speed. */
5289 fcport
->fp_speed
= ha
->link_data_rate
;
5294 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5295 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5298 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5299 if ((qla_dual_mode_enabled(vha
) ||
5300 qla_ini_mode_enabled(vha
)) &&
5301 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5302 qla2x00_mark_device_lost(vha
, fcport
,
5303 ql2xplogiabsentdevice
);
5304 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5305 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5306 fcport
->port_type
!= FCT_INITIATOR
&&
5307 fcport
->port_type
!= FCT_BROADCAST
) {
5308 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5309 "%s %d %8phC post del sess\n",
5313 qlt_schedule_sess_for_deletion(fcport
);
5319 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5320 qla24xx_fcport_handle_login(vha
, fcport
);
5323 qla2x00_free_fcport(new_fcport
);
5328 ql_dbg(ql_dbg_disc
, vha
, 0x2098,
5329 "Configure local loop error exit: rval=%x.\n", rval
);
5334 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5337 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5338 struct qla_hw_data
*ha
= vha
->hw
;
5340 if (!IS_IIDMA_CAPABLE(ha
))
5343 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
5346 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
5347 fcport
->fp_speed
> ha
->link_data_rate
||
5348 !ha
->flags
.gpsc_supported
)
5351 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
5353 if (rval
!= QLA_SUCCESS
) {
5354 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
5355 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5356 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
5358 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
5359 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5360 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
5361 fcport
->fp_speed
, fcport
->port_name
);
5365 void qla_do_iidma_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
5367 qla2x00_iidma_fcport(vha
, fcport
);
5368 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5371 int qla_post_iidma_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
5373 struct qla_work_evt
*e
;
5375 e
= qla2x00_alloc_work(vha
, QLA_EVT_IIDMA
);
5377 return QLA_FUNCTION_FAILED
;
5379 e
->u
.fcport
.fcport
= fcport
;
5380 return qla2x00_post_work(vha
, e
);
5383 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5385 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5387 struct fc_rport_identifiers rport_ids
;
5388 struct fc_rport
*rport
;
5389 unsigned long flags
;
5391 if (atomic_read(&fcport
->state
) == FCS_ONLINE
)
5394 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
5395 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
5396 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
5397 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
5398 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5399 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
5401 ql_log(ql_log_warn
, vha
, 0x2006,
5402 "Unable to allocate fc remote port.\n");
5406 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
5407 *((fc_port_t
**)rport
->dd_data
) = fcport
;
5408 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
5410 rport
->supported_classes
= fcport
->supported_classes
;
5412 rport_ids
.roles
= FC_PORT_ROLE_UNKNOWN
;
5413 if (fcport
->port_type
== FCT_INITIATOR
)
5414 rport_ids
.roles
|= FC_PORT_ROLE_FCP_INITIATOR
;
5415 if (fcport
->port_type
== FCT_TARGET
)
5416 rport_ids
.roles
|= FC_PORT_ROLE_FCP_TARGET
;
5417 if (fcport
->port_type
& FCT_NVME_INITIATOR
)
5418 rport_ids
.roles
|= FC_PORT_ROLE_NVME_INITIATOR
;
5419 if (fcport
->port_type
& FCT_NVME_TARGET
)
5420 rport_ids
.roles
|= FC_PORT_ROLE_NVME_TARGET
;
5421 if (fcport
->port_type
& FCT_NVME_DISCOVERY
)
5422 rport_ids
.roles
|= FC_PORT_ROLE_NVME_DISCOVERY
;
5424 ql_dbg(ql_dbg_disc
, vha
, 0x20ee,
5425 "%s %8phN. rport %p is %s mode\n",
5426 __func__
, fcport
->port_name
, rport
,
5427 (fcport
->port_type
== FCT_TARGET
) ? "tgt" :
5428 ((fcport
->port_type
& FCT_NVME
) ? "nvme" : "ini"));
5430 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
5434 * qla2x00_update_fcport
5435 * Updates device on list.
5438 * ha = adapter block pointer.
5439 * fcport = port structure pointer.
5449 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5451 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5454 ql_dbg(ql_dbg_disc
, vha
, 0x20ef, "%s %8phC\n",
5455 __func__
, fcport
->port_name
);
5457 qla2x00_set_fcport_disc_state(fcport
, DSC_UPD_FCPORT
);
5458 fcport
->login_retry
= vha
->hw
->login_retry_count
;
5459 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
5460 fcport
->deleted
= 0;
5461 if (vha
->hw
->current_topology
== ISP_CFG_NL
)
5462 fcport
->logout_on_delete
= 0;
5464 fcport
->logout_on_delete
= 1;
5465 fcport
->n2n_chip_reset
= fcport
->n2n_link_reset_cnt
= 0;
5467 switch (vha
->hw
->current_topology
) {
5470 fcport
->keep_nport_handle
= 1;
5476 qla2x00_iidma_fcport(vha
, fcport
);
5478 if (NVME_TARGET(vha
->hw
, fcport
)) {
5479 qla_nvme_register_remote(vha
, fcport
);
5480 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_COMPLETE
);
5481 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5485 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5487 switch (vha
->host
->active_mode
) {
5488 case MODE_INITIATOR
:
5489 qla2x00_reg_remote_port(vha
, fcport
);
5492 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5493 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5494 qlt_fc_port_added(vha
, fcport
);
5497 qla2x00_reg_remote_port(vha
, fcport
);
5498 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5499 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5500 qlt_fc_port_added(vha
, fcport
);
5506 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5508 if (IS_IIDMA_CAPABLE(vha
->hw
) && vha
->hw
->flags
.gpsc_supported
) {
5509 if (fcport
->id_changed
) {
5510 fcport
->id_changed
= 0;
5511 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
5512 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5513 __func__
, __LINE__
, fcport
->port_name
,
5515 qla24xx_post_gfpnid_work(vha
, fcport
);
5517 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
5518 "%s %d %8phC post gpsc fcp_cnt %d\n",
5519 __func__
, __LINE__
, fcport
->port_name
,
5521 qla24xx_post_gpsc_work(vha
, fcport
);
5525 qla2x00_set_fcport_disc_state(fcport
, DSC_LOGIN_COMPLETE
);
5528 void qla_register_fcport_fn(struct work_struct
*work
)
5530 fc_port_t
*fcport
= container_of(work
, struct fc_port
, reg_work
);
5531 u32 rscn_gen
= fcport
->rscn_gen
;
5534 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5537 qla2x00_update_fcport(fcport
->vha
, fcport
);
5539 if (rscn_gen
!= fcport
->rscn_gen
) {
5540 /* RSCN(s) came in while registration */
5541 switch (fcport
->next_disc_state
) {
5542 case DSC_DELETE_PEND
:
5543 qlt_schedule_sess_for_deletion(fcport
);
5546 data
[0] = data
[1] = 0;
5547 qla2x00_post_async_adisc_work(fcport
->vha
, fcport
,
5557 * qla2x00_configure_fabric
5558 * Setup SNS devices with loop ID's.
5561 * ha = adapter block pointer.
5568 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
5572 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5574 LIST_HEAD(new_fcports
);
5575 struct qla_hw_data
*ha
= vha
->hw
;
5578 /* If FL port exists, then SNS is present */
5579 if (IS_FWI2_CAPABLE(ha
))
5580 loop_id
= NPH_F_PORT
;
5582 loop_id
= SNS_FL_PORT
;
5583 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
5584 if (rval
!= QLA_SUCCESS
) {
5585 ql_dbg(ql_dbg_disc
, vha
, 0x20a0,
5586 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5588 vha
->device_flags
&= ~SWITCH_FOUND
;
5589 return (QLA_SUCCESS
);
5591 vha
->device_flags
|= SWITCH_FOUND
;
5593 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_port_name
, 0);
5594 if (rval
!= QLA_SUCCESS
)
5595 ql_dbg(ql_dbg_disc
, vha
, 0x20ff,
5596 "Failed to get Fabric Port Name\n");
5598 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
5599 rval
= qla2x00_send_change_request(vha
, 0x3, 0);
5600 if (rval
!= QLA_SUCCESS
)
5601 ql_log(ql_log_warn
, vha
, 0x121,
5602 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5607 qla2x00_mgmt_svr_login(vha
);
5609 /* Ensure we are logged into the SNS. */
5610 loop_id
= NPH_SNS_LID(ha
);
5611 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
5612 0xfc, mb
, BIT_1
|BIT_0
);
5613 if (rval
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5614 ql_dbg(ql_dbg_disc
, vha
, 0x20a1,
5615 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5616 loop_id
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7], rval
);
5617 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5622 if (ql2xfdmienable
&&
5623 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
5624 qla2x00_fdmi_register(vha
);
5626 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
5627 if (qla2x00_rft_id(vha
)) {
5629 ql_dbg(ql_dbg_disc
, vha
, 0x20a2,
5630 "Register FC-4 TYPE failed.\n");
5631 if (test_bit(LOOP_RESYNC_NEEDED
,
5635 if (qla2x00_rff_id(vha
, FC4_TYPE_FCP_SCSI
)) {
5637 ql_dbg(ql_dbg_disc
, vha
, 0x209a,
5638 "Register FC-4 Features failed.\n");
5639 if (test_bit(LOOP_RESYNC_NEEDED
,
5643 if (vha
->flags
.nvme_enabled
) {
5644 if (qla2x00_rff_id(vha
, FC_TYPE_NVME
)) {
5645 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
5646 "Register NVME FC Type Features failed.\n");
5649 if (qla2x00_rnn_id(vha
)) {
5651 ql_dbg(ql_dbg_disc
, vha
, 0x2104,
5652 "Register Node Name failed.\n");
5653 if (test_bit(LOOP_RESYNC_NEEDED
,
5656 } else if (qla2x00_rsnn_nn(vha
)) {
5658 ql_dbg(ql_dbg_disc
, vha
, 0x209b,
5659 "Register Symbolic Node Name failed.\n");
5660 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5666 /* Mark the time right before querying FW for connected ports.
5667 * This process is long, asynchronous and by the time it's done,
5668 * collected information might not be accurate anymore. E.g.
5669 * disconnected port might have re-connected and a brand new
5670 * session has been created. In this case session's generation
5671 * will be newer than discovery_gen. */
5672 qlt_do_generation_tick(vha
, &discovery_gen
);
5674 if (USE_ASYNC_SCAN(ha
)) {
5675 rval
= qla24xx_async_gpnft(vha
, FC4_TYPE_FCP_SCSI
,
5678 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5680 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5681 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5683 rval
= qla2x00_find_all_fabric_devs(vha
);
5685 if (rval
!= QLA_SUCCESS
)
5689 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
5690 qla_nvme_register_hba(vha
);
5693 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
5694 "Configure fabric error exit rval=%d.\n", rval
);
5700 * qla2x00_find_all_fabric_devs
5703 * ha = adapter block pointer.
5704 * dev = database device entry pointer.
5713 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
)
5717 fc_port_t
*fcport
, *new_fcport
;
5722 int first_dev
, last_dev
;
5723 port_id_t wrap
= {}, nxt_d_id
;
5724 struct qla_hw_data
*ha
= vha
->hw
;
5725 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5726 unsigned long flags
;
5730 /* Try GID_PT to get device list, else GAN. */
5732 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
5737 ql_dbg(ql_dbg_disc
, vha
, 0x209c,
5738 "GID_PT allocations failed, fallback on GA_NXT.\n");
5740 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
5741 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
5743 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5745 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
5747 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5749 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
5751 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5753 } else if (qla2x00_gfpn_id(vha
, swl
) != QLA_SUCCESS
) {
5755 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5759 /* If other queries succeeded probe for FC-4 type */
5761 qla2x00_gff_id(vha
, swl
);
5762 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5768 /* Allocate temporary fcport for any new fcports discovered. */
5769 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5770 if (new_fcport
== NULL
) {
5771 ql_log(ql_log_warn
, vha
, 0x209d,
5772 "Failed to allocate memory for fcport.\n");
5773 return (QLA_MEMORY_ALLOC_FAILED
);
5775 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5776 /* Set start port ID scan at adapter ID. */
5780 /* Starting free loop ID. */
5781 loop_id
= ha
->min_external_loopid
;
5782 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
5783 if (qla2x00_is_reserved_id(vha
, loop_id
))
5786 if (ha
->current_topology
== ISP_CFG_FL
&&
5787 (atomic_read(&vha
->loop_down_timer
) ||
5788 LOOP_TRANSITION(vha
))) {
5789 atomic_set(&vha
->loop_down_timer
, 0);
5790 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5791 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5797 wrap
.b24
= new_fcport
->d_id
.b24
;
5799 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
5800 memcpy(new_fcport
->node_name
,
5801 swl
[swl_idx
].node_name
, WWN_SIZE
);
5802 memcpy(new_fcport
->port_name
,
5803 swl
[swl_idx
].port_name
, WWN_SIZE
);
5804 memcpy(new_fcport
->fabric_port_name
,
5805 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
5806 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
5807 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
5809 new_fcport
->nvme_flag
= 0;
5810 if (vha
->flags
.nvme_enabled
&&
5811 swl
[swl_idx
].fc4_type
& FS_FC4TYPE_NVME
) {
5812 ql_log(ql_log_info
, vha
, 0x2131,
5813 "FOUND: NVME port %8phC as FC Type 28h\n",
5814 new_fcport
->port_name
);
5817 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
5823 /* Send GA_NXT to the switch */
5824 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
5825 if (rval
!= QLA_SUCCESS
) {
5826 ql_log(ql_log_warn
, vha
, 0x209e,
5827 "SNS scan failed -- assuming "
5828 "zero-entry result.\n");
5834 /* If wrap on switch device list, exit. */
5836 wrap
.b24
= new_fcport
->d_id
.b24
;
5838 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
5839 ql_dbg(ql_dbg_disc
, vha
, 0x209f,
5840 "Device wrap (%02x%02x%02x).\n",
5841 new_fcport
->d_id
.b
.domain
,
5842 new_fcport
->d_id
.b
.area
,
5843 new_fcport
->d_id
.b
.al_pa
);
5847 /* Bypass if same physical adapter. */
5848 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
5851 /* Bypass virtual ports of the same host. */
5852 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
5855 /* Bypass if same domain and area of adapter. */
5856 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
5857 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
5861 /* Bypass reserved domain fields. */
5862 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
5865 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5866 if (ql2xgffidenable
&&
5867 (!(new_fcport
->fc4_type
& FS_FC4TYPE_FCP
) &&
5868 new_fcport
->fc4_type
!= 0))
5871 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5873 /* Locate matching device in database. */
5875 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5876 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5880 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5884 /* Update port state. */
5885 memcpy(fcport
->fabric_port_name
,
5886 new_fcport
->fabric_port_name
, WWN_SIZE
);
5887 fcport
->fp_speed
= new_fcport
->fp_speed
;
5890 * If address the same and state FCS_ONLINE
5891 * (or in target mode), nothing changed.
5893 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
5894 (atomic_read(&fcport
->state
) == FCS_ONLINE
||
5895 (vha
->host
->active_mode
== MODE_TARGET
))) {
5900 * If device was not a fabric device before.
5902 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
5903 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5904 qla2x00_clear_loop_id(fcport
);
5905 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
5911 * Port ID changed or device was marked to be updated;
5912 * Log it out if still logged in and mark it for
5915 if (qla_tgt_mode_enabled(base_vha
)) {
5916 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf080,
5917 "port changed FC ID, %8phC"
5918 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5920 fcport
->d_id
.b
.domain
,
5921 fcport
->d_id
.b
.area
,
5922 fcport
->d_id
.b
.al_pa
,
5924 new_fcport
->d_id
.b
.domain
,
5925 new_fcport
->d_id
.b
.area
,
5926 new_fcport
->d_id
.b
.al_pa
);
5927 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5931 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5932 fcport
->flags
|= FCF_LOGIN_NEEDED
;
5936 if (NVME_TARGET(vha
->hw
, fcport
)) {
5937 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
5938 qla2x00_set_fcport_disc_state(fcport
, DSC_GNL
);
5939 vha
->fcport_count
--;
5940 fcport
->login_succ
= 0;
5945 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5948 /* If device was not in our fcports list, then add it. */
5949 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5950 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5952 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5955 /* Allocate a new replacement fcport. */
5956 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
5957 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5958 if (new_fcport
== NULL
) {
5959 ql_log(ql_log_warn
, vha
, 0xd032,
5960 "Memory allocation failed for fcport.\n");
5961 return (QLA_MEMORY_ALLOC_FAILED
);
5963 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5964 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
5967 qla2x00_free_fcport(new_fcport
);
5970 * Logout all previous fabric dev marked lost, except FCP2 devices.
5972 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5973 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5976 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0)
5979 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5980 if ((qla_dual_mode_enabled(vha
) ||
5981 qla_ini_mode_enabled(vha
)) &&
5982 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5983 qla2x00_mark_device_lost(vha
, fcport
,
5984 ql2xplogiabsentdevice
);
5985 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5986 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5987 fcport
->port_type
!= FCT_INITIATOR
&&
5988 fcport
->port_type
!= FCT_BROADCAST
) {
5989 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5990 "%s %d %8phC post del sess\n",
5993 qlt_schedule_sess_for_deletion(fcport
);
5999 if (fcport
->scan_state
== QLA_FCPORT_FOUND
&&
6000 (fcport
->flags
& FCF_LOGIN_NEEDED
) != 0)
6001 qla24xx_fcport_handle_login(vha
, fcport
);
6006 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6008 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t
*vha
)
6010 int loop_id
= FC_NO_LOOP_ID
;
6011 int lid
= NPH_MGMT_SERVER
- vha
->vp_idx
;
6012 unsigned long flags
;
6013 struct qla_hw_data
*ha
= vha
->hw
;
6015 if (vha
->vp_idx
== 0) {
6016 set_bit(NPH_MGMT_SERVER
, ha
->loop_id_map
);
6017 return NPH_MGMT_SERVER
;
6020 /* pick id from high and work down to low */
6021 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6022 for (; lid
> 0; lid
--) {
6023 if (!test_bit(lid
, vha
->hw
->loop_id_map
)) {
6024 set_bit(lid
, vha
->hw
->loop_id_map
);
6029 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6035 * qla2x00_fabric_login
6036 * Issue fabric login command.
6039 * ha = adapter block pointer.
6040 * device = pointer to FC device type structure.
6043 * 0 - Login successfully
6045 * 2 - Initiator device
6049 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
6050 uint16_t *next_loopid
)
6054 uint16_t tmp_loopid
;
6055 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6056 struct qla_hw_data
*ha
= vha
->hw
;
6062 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
6063 "Trying Fabric Login w/loop id 0x%04x for port "
6065 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
6066 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
6068 /* Login fcport on switch. */
6069 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
6070 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
6071 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
6072 if (rval
!= QLA_SUCCESS
) {
6075 if (mb
[0] == MBS_PORT_ID_USED
) {
6077 * Device has another loop ID. The firmware team
6078 * recommends the driver perform an implicit login with
6079 * the specified ID again. The ID we just used is save
6080 * here so we return with an ID that can be tried by
6084 tmp_loopid
= fcport
->loop_id
;
6085 fcport
->loop_id
= mb
[1];
6087 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
6088 "Fabric Login: port in use - next loop "
6089 "id=0x%04x, port id= %02x%02x%02x.\n",
6090 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
6091 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
6093 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
6098 /* A retry occurred before. */
6099 *next_loopid
= tmp_loopid
;
6102 * No retry occurred before. Just increment the
6103 * ID value for next login.
6105 *next_loopid
= (fcport
->loop_id
+ 1);
6108 if (mb
[1] & BIT_0
) {
6109 fcport
->port_type
= FCT_INITIATOR
;
6111 fcport
->port_type
= FCT_TARGET
;
6112 if (mb
[1] & BIT_1
) {
6113 fcport
->flags
|= FCF_FCP2_DEVICE
;
6118 fcport
->supported_classes
|= FC_COS_CLASS2
;
6120 fcport
->supported_classes
|= FC_COS_CLASS3
;
6122 if (IS_FWI2_CAPABLE(ha
)) {
6125 FCF_CONF_COMP_SUPPORTED
;
6130 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
6132 * Loop ID already used, try next loop ID.
6135 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
6136 if (rval
!= QLA_SUCCESS
) {
6137 /* Ran out of loop IDs to use */
6140 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
6142 * Firmware possibly timed out during login. If NO
6143 * retries are left to do then the device is declared
6146 *next_loopid
= fcport
->loop_id
;
6147 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
6148 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
6149 fcport
->d_id
.b
.al_pa
);
6150 qla2x00_mark_device_lost(vha
, fcport
, 1);
6156 * unrecoverable / not handled error
6158 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
6159 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6160 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
6161 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
6162 fcport
->loop_id
, jiffies
);
6164 *next_loopid
= fcport
->loop_id
;
6165 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
6166 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
6167 fcport
->d_id
.b
.al_pa
);
6168 qla2x00_clear_loop_id(fcport
);
6169 fcport
->login_retry
= 0;
6180 * qla2x00_local_device_login
6181 * Issue local device login command.
6184 * ha = adapter block pointer.
6185 * loop_id = loop id of device to login to.
6187 * Returns (Where's the #define!!!!):
6188 * 0 - Login successfully
6193 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
6196 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
6198 memset(mb
, 0, sizeof(mb
));
6199 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
6200 if (rval
== QLA_SUCCESS
) {
6201 /* Interrogate mailbox registers for any errors */
6202 if (mb
[0] == MBS_COMMAND_ERROR
)
6204 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
6205 /* device not in PCB table */
6213 * qla2x00_loop_resync
6214 * Resync with fibre channel devices.
6217 * ha = adapter block pointer.
6223 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
6225 int rval
= QLA_SUCCESS
;
6228 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6229 if (vha
->flags
.online
) {
6230 if (!(rval
= qla2x00_fw_ready(vha
))) {
6231 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6234 if (!IS_QLAFX00(vha
->hw
)) {
6236 * Issue a marker after FW becomes
6239 qla2x00_marker(vha
, vha
->hw
->base_qpair
,
6241 vha
->marker_needed
= 0;
6244 /* Remap devices on Loop. */
6245 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6247 if (IS_QLAFX00(vha
->hw
))
6248 qlafx00_configure_devices(vha
);
6250 qla2x00_configure_loop(vha
);
6253 } while (!atomic_read(&vha
->loop_down_timer
) &&
6254 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
6255 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
6260 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
6261 return (QLA_FUNCTION_FAILED
);
6264 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
6265 "%s *** FAILED ***.\n", __func__
);
6271 * qla2x00_perform_loop_resync
6272 * Description: This function will set the appropriate flags and call
6273 * qla2x00_loop_resync. If successful loop will be resynced
6274 * Arguments : scsi_qla_host_t pointer
6275 * returm : Success or Failure
6278 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
6282 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
6283 /*Configure the flags so that resync happens properly*/
6284 atomic_set(&ha
->loop_down_timer
, 0);
6285 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
6286 atomic_set(&ha
->loop_state
, LOOP_UP
);
6287 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
6288 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
6289 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
6291 rval
= qla2x00_loop_resync(ha
);
6293 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
6295 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
6302 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
6305 struct scsi_qla_host
*vha
;
6306 struct qla_hw_data
*ha
= base_vha
->hw
;
6307 unsigned long flags
;
6309 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6310 /* Go with deferred removal of rport references. */
6311 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
6312 atomic_inc(&vha
->vref_count
);
6313 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
6314 if (fcport
->drport
&&
6315 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
6316 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6317 qla2x00_rport_del(fcport
);
6319 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6322 atomic_dec(&vha
->vref_count
);
6323 wake_up(&vha
->vref_waitq
);
6325 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6328 /* Assumes idc_lock always held on entry */
6330 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
6332 struct qla_hw_data
*ha
= vha
->hw
;
6333 uint32_t drv_presence
, drv_presence_mask
;
6334 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
6335 uint32_t class_type_mask
= 0x3;
6336 uint16_t fcoe_other_function
= 0xffff, i
;
6338 if (IS_QLA8044(ha
)) {
6339 drv_presence
= qla8044_rd_direct(vha
,
6340 QLA8044_CRB_DRV_ACTIVE_INDEX
);
6341 dev_part_info1
= qla8044_rd_direct(vha
,
6342 QLA8044_CRB_DEV_PART_INFO_INDEX
);
6343 dev_part_info2
= qla8044_rd_direct(vha
,
6344 QLA8044_CRB_DEV_PART_INFO2
);
6346 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6347 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
6348 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
6350 for (i
= 0; i
< 8; i
++) {
6351 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
6352 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
6353 (i
!= ha
->portnum
)) {
6354 fcoe_other_function
= i
;
6358 if (fcoe_other_function
== 0xffff) {
6359 for (i
= 0; i
< 8; i
++) {
6360 class_type
= ((dev_part_info2
>> (i
* 4)) &
6362 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
6363 ((i
+ 8) != ha
->portnum
)) {
6364 fcoe_other_function
= i
+ 8;
6370 * Prepare drv-presence mask based on fcoe functions present.
6371 * However consider only valid physical fcoe function numbers (0-15).
6373 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
6374 ((fcoe_other_function
== 0xffff) ?
6375 0 : (1 << (fcoe_other_function
))));
6377 /* We are the reset owner iff:
6378 * - No other protocol drivers present.
6379 * - This is the lowest among fcoe functions. */
6380 if (!(drv_presence
& drv_presence_mask
) &&
6381 (ha
->portnum
< fcoe_other_function
)) {
6382 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
6383 "This host is Reset owner.\n");
6384 ha
->flags
.nic_core_reset_owner
= 1;
6389 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
6391 int rval
= QLA_SUCCESS
;
6392 struct qla_hw_data
*ha
= vha
->hw
;
6395 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6396 if (rval
== QLA_SUCCESS
) {
6397 drv_ack
|= (1 << ha
->portnum
);
6398 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6405 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
6407 int rval
= QLA_SUCCESS
;
6408 struct qla_hw_data
*ha
= vha
->hw
;
6411 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6412 if (rval
== QLA_SUCCESS
) {
6413 drv_ack
&= ~(1 << ha
->portnum
);
6414 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6421 qla83xx_dev_state_to_string(uint32_t dev_state
)
6423 switch (dev_state
) {
6424 case QLA8XXX_DEV_COLD
:
6425 return "COLD/RE-INIT";
6426 case QLA8XXX_DEV_INITIALIZING
:
6427 return "INITIALIZING";
6428 case QLA8XXX_DEV_READY
:
6430 case QLA8XXX_DEV_NEED_RESET
:
6431 return "NEED RESET";
6432 case QLA8XXX_DEV_NEED_QUIESCENT
:
6433 return "NEED QUIESCENT";
6434 case QLA8XXX_DEV_FAILED
:
6436 case QLA8XXX_DEV_QUIESCENT
:
6443 /* Assumes idc-lock always held on entry */
6445 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
6447 struct qla_hw_data
*ha
= vha
->hw
;
6448 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
6450 switch (audit_type
) {
6451 case IDC_AUDIT_TIMESTAMP
:
6452 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
6453 idc_audit_reg
= (ha
->portnum
) |
6454 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
6455 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6458 case IDC_AUDIT_COMPLETION
:
6459 duration_secs
= ((jiffies_to_msecs(jiffies
) -
6460 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
6461 idc_audit_reg
= (ha
->portnum
) |
6462 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
6463 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6467 ql_log(ql_log_warn
, vha
, 0xb078,
6468 "Invalid audit type specified.\n");
6473 /* Assumes idc_lock always held on entry */
6475 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
6477 struct qla_hw_data
*ha
= vha
->hw
;
6478 uint32_t idc_control
, dev_state
;
6480 __qla83xx_get_idc_control(vha
, &idc_control
);
6481 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
6482 ql_log(ql_log_info
, vha
, 0xb080,
6483 "NIC Core reset has been disabled. idc-control=0x%x\n",
6485 return QLA_FUNCTION_FAILED
;
6488 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6489 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6490 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
6491 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
6492 QLA8XXX_DEV_NEED_RESET
);
6493 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
6494 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
6496 const char *state
= qla83xx_dev_state_to_string(dev_state
);
6498 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
6500 /* SV: XXX: Is timeout required here? */
6501 /* Wait for IDC state change READY -> NEED_RESET */
6502 while (dev_state
== QLA8XXX_DEV_READY
) {
6503 qla83xx_idc_unlock(vha
, 0);
6505 qla83xx_idc_lock(vha
, 0);
6506 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6510 /* Send IDC ack by writing to drv-ack register */
6511 __qla83xx_set_drv_ack(vha
);
6517 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
6519 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6523 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
6525 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6529 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
6531 uint32_t drv_presence
= 0;
6532 struct qla_hw_data
*ha
= vha
->hw
;
6534 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6535 if (drv_presence
& (1 << ha
->portnum
))
6538 return QLA_TEST_FAILED
;
6542 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
6544 int rval
= QLA_SUCCESS
;
6545 struct qla_hw_data
*ha
= vha
->hw
;
6547 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
6548 "Entered %s().\n", __func__
);
6550 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
6551 ql_log(ql_log_warn
, vha
, 0xb059,
6552 "Device in unrecoverable FAILED state.\n");
6553 return QLA_FUNCTION_FAILED
;
6556 qla83xx_idc_lock(vha
, 0);
6558 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
6559 ql_log(ql_log_warn
, vha
, 0xb05a,
6560 "Function=0x%x has been removed from IDC participation.\n",
6562 rval
= QLA_FUNCTION_FAILED
;
6566 qla83xx_reset_ownership(vha
);
6568 rval
= qla83xx_initiating_reset(vha
);
6571 * Perform reset if we are the reset-owner,
6572 * else wait till IDC state changes to READY/FAILED.
6574 if (rval
== QLA_SUCCESS
) {
6575 rval
= qla83xx_idc_state_handler(vha
);
6577 if (rval
== QLA_SUCCESS
)
6578 ha
->flags
.nic_core_hung
= 0;
6579 __qla83xx_clear_drv_ack(vha
);
6583 qla83xx_idc_unlock(vha
, 0);
6585 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
6591 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
6593 struct qla_hw_data
*ha
= vha
->hw
;
6594 int rval
= QLA_FUNCTION_FAILED
;
6596 if (!IS_MCTP_CAPABLE(ha
)) {
6597 /* This message can be removed from the final version */
6598 ql_log(ql_log_info
, vha
, 0x506d,
6599 "This board is not MCTP capable\n");
6603 if (!ha
->mctp_dump
) {
6604 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
6605 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
6607 if (!ha
->mctp_dump
) {
6608 ql_log(ql_log_warn
, vha
, 0x506e,
6609 "Failed to allocate memory for mctp dump\n");
6614 #define MCTP_DUMP_STR_ADDR 0x00000000
6615 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
6616 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
6617 if (rval
!= QLA_SUCCESS
) {
6618 ql_log(ql_log_warn
, vha
, 0x506f,
6619 "Failed to capture mctp dump\n");
6621 ql_log(ql_log_info
, vha
, 0x5070,
6622 "Mctp dump capture for host (%ld/%p).\n",
6623 vha
->host_no
, ha
->mctp_dump
);
6624 ha
->mctp_dumped
= 1;
6627 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
6628 ha
->flags
.nic_core_reset_hdlr_active
= 1;
6629 rval
= qla83xx_restart_nic_firmware(vha
);
6631 /* NIC Core reset failed. */
6632 ql_log(ql_log_warn
, vha
, 0x5071,
6633 "Failed to restart nic firmware\n");
6635 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
6636 "Restarted NIC firmware successfully.\n");
6637 ha
->flags
.nic_core_reset_hdlr_active
= 0;
6645 * qla2x00_quiesce_io
6646 * Description: This function will block the new I/Os
6647 * Its not aborting any I/Os as context
6648 * is not destroyed during quiescence
6649 * Arguments: scsi_qla_host_t
6653 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
6655 struct qla_hw_data
*ha
= vha
->hw
;
6656 struct scsi_qla_host
*vp
;
6658 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
6659 "Quiescing I/O - ha=%p.\n", ha
);
6661 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
6662 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6663 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6664 qla2x00_mark_all_devices_lost(vha
);
6665 list_for_each_entry(vp
, &ha
->vp_list
, list
)
6666 qla2x00_mark_all_devices_lost(vp
);
6668 if (!atomic_read(&vha
->loop_down_timer
))
6669 atomic_set(&vha
->loop_down_timer
,
6672 /* Wait for pending cmds to complete */
6673 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
)
6678 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
6680 struct qla_hw_data
*ha
= vha
->hw
;
6681 struct scsi_qla_host
*vp
;
6682 unsigned long flags
;
6686 /* For ISP82XX, driver waits for completion of the commands.
6687 * online flag should be set.
6689 if (!(IS_P3P_TYPE(ha
)))
6690 vha
->flags
.online
= 0;
6691 ha
->flags
.chip_reset_done
= 0;
6692 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6693 vha
->qla_stats
.total_isp_aborts
++;
6695 ql_log(ql_log_info
, vha
, 0x00af,
6696 "Performing ISP error recovery - ha=%p.\n", ha
);
6698 ha
->flags
.purge_mbox
= 1;
6699 /* For ISP82XX, reset_chip is just disabling interrupts.
6700 * Driver waits for the completion of the commands.
6701 * the interrupts need to be enabled.
6703 if (!(IS_P3P_TYPE(ha
)))
6704 ha
->isp_ops
->reset_chip(vha
);
6706 ha
->link_data_rate
= PORT_SPEED_UNKNOWN
;
6708 ha
->flags
.rida_fmt2
= 0;
6709 ha
->flags
.n2n_ae
= 0;
6710 ha
->flags
.lip_ae
= 0;
6711 ha
->current_topology
= 0;
6713 ha
->flags
.fw_init_done
= 0;
6715 ha
->base_qpair
->chip_reset
= ha
->chip_reset
;
6716 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6717 if (ha
->queue_pair_map
[i
])
6718 ha
->queue_pair_map
[i
]->chip_reset
=
6719 ha
->base_qpair
->chip_reset
;
6722 /* purge MBox commands */
6723 if (atomic_read(&ha
->num_pend_mbx_stage3
)) {
6724 clear_bit(MBX_INTR_WAIT
, &ha
->mbx_cmd_flags
);
6725 complete(&ha
->mbx_intr_comp
);
6729 while (atomic_read(&ha
->num_pend_mbx_stage3
) ||
6730 atomic_read(&ha
->num_pend_mbx_stage2
) ||
6731 atomic_read(&ha
->num_pend_mbx_stage1
)) {
6737 ha
->flags
.purge_mbox
= 0;
6739 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
6740 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6741 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6742 qla2x00_mark_all_devices_lost(vha
);
6744 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6745 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6746 atomic_inc(&vp
->vref_count
);
6747 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6749 qla2x00_mark_all_devices_lost(vp
);
6751 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6752 atomic_dec(&vp
->vref_count
);
6754 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6756 if (!atomic_read(&vha
->loop_down_timer
))
6757 atomic_set(&vha
->loop_down_timer
,
6761 /* Clear all async request states across all VPs. */
6762 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
6763 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6764 fcport
->scan_state
= 0;
6766 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6767 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6768 atomic_inc(&vp
->vref_count
);
6769 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6771 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
6772 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6774 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6775 atomic_dec(&vp
->vref_count
);
6777 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6779 if (!ha
->flags
.eeh_busy
) {
6780 /* Make sure for ISP 82XX IO DMA is complete */
6781 if (IS_P3P_TYPE(ha
)) {
6782 qla82xx_chip_reset_cleanup(vha
);
6783 ql_log(ql_log_info
, vha
, 0x00b4,
6784 "Done chip reset cleanup.\n");
6786 /* Done waiting for pending commands.
6787 * Reset the online flag.
6789 vha
->flags
.online
= 0;
6792 /* Requeue all commands in outstanding command list. */
6793 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6795 /* memory barrier */
6801 * Resets ISP and aborts all outstanding commands.
6804 * ha = adapter block pointer.
6810 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
6814 struct qla_hw_data
*ha
= vha
->hw
;
6815 struct scsi_qla_host
*vp
;
6816 struct req_que
*req
= ha
->req_q_map
[0];
6817 unsigned long flags
;
6819 if (vha
->flags
.online
) {
6820 qla2x00_abort_isp_cleanup(vha
);
6822 if (test_and_clear_bit(ISP_ABORT_TO_ROM
, &vha
->dpc_flags
)) {
6823 ha
->flags
.chip_reset_done
= 1;
6824 vha
->flags
.online
= 1;
6826 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6830 if (IS_QLA8031(ha
)) {
6831 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
6832 "Clearing fcoe driver presence.\n");
6833 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
6834 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
6835 "Error while clearing DRV-Presence.\n");
6838 if (unlikely(pci_channel_offline(ha
->pdev
) &&
6839 ha
->flags
.pci_channel_io_perm_failure
)) {
6840 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6845 switch (vha
->qlini_mode
) {
6846 case QLA2XXX_INI_MODE_DISABLED
:
6847 if (!qla_tgt_mode_enabled(vha
))
6850 case QLA2XXX_INI_MODE_DUAL
:
6851 if (!qla_dual_mode_enabled(vha
))
6854 case QLA2XXX_INI_MODE_ENABLED
:
6859 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
6861 ha
->isp_ops
->nvram_config(vha
);
6863 if (!qla2x00_restart_isp(vha
)) {
6864 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6866 if (!atomic_read(&vha
->loop_down_timer
)) {
6868 * Issue marker command only when we are going
6869 * to start the I/O .
6871 vha
->marker_needed
= 1;
6874 vha
->flags
.online
= 1;
6876 ha
->isp_ops
->enable_intrs(ha
);
6878 ha
->isp_abort_cnt
= 0;
6879 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6881 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
6882 qla2x00_get_fw_version(vha
);
6884 ha
->flags
.fce_enabled
= 1;
6886 fce_calc_size(ha
->fce_bufs
));
6887 rval
= qla2x00_enable_fce_trace(vha
,
6888 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6891 ql_log(ql_log_warn
, vha
, 0x8033,
6892 "Unable to reinitialize FCE "
6894 ha
->flags
.fce_enabled
= 0;
6899 memset(ha
->eft
, 0, EFT_SIZE
);
6900 rval
= qla2x00_enable_eft_trace(vha
,
6901 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6903 ql_log(ql_log_warn
, vha
, 0x8034,
6904 "Unable to reinitialize EFT "
6908 } else { /* failed the ISP abort */
6909 vha
->flags
.online
= 1;
6910 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
6911 if (ha
->isp_abort_cnt
== 0) {
6912 ql_log(ql_log_fatal
, vha
, 0x8035,
6913 "ISP error recover failed - "
6914 "board disabled.\n");
6916 * The next call disables the board
6919 qla2x00_abort_isp_cleanup(vha
);
6920 vha
->flags
.online
= 0;
6921 clear_bit(ISP_ABORT_RETRY
,
6924 } else { /* schedule another ISP abort */
6925 ha
->isp_abort_cnt
--;
6926 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
6927 "ISP abort - retry remaining %d.\n",
6932 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
6933 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
6934 "ISP error recovery - retrying (%d) "
6935 "more times.\n", ha
->isp_abort_cnt
);
6936 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6944 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
6945 qla2x00_configure_hba(vha
);
6946 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6947 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6949 atomic_inc(&vp
->vref_count
);
6950 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6952 qla2x00_vp_abort_isp(vp
);
6954 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6955 atomic_dec(&vp
->vref_count
);
6958 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6960 if (IS_QLA8031(ha
)) {
6961 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
6962 "Setting back fcoe driver presence.\n");
6963 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
6964 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
6965 "Error while setting DRV-Presence.\n");
6968 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
6976 * qla2x00_restart_isp
6977 * restarts the ISP after a reset
6980 * ha = adapter block pointer.
6986 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
6989 struct qla_hw_data
*ha
= vha
->hw
;
6991 /* If firmware needs to be loaded */
6992 if (qla2x00_isp_firmware(vha
)) {
6993 vha
->flags
.online
= 0;
6994 status
= ha
->isp_ops
->chip_diag(vha
);
6996 status
= qla2x00_setup_chip(vha
);
6999 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
7000 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
7001 ha
->flags
.chip_reset_done
= 1;
7003 /* Initialize the queues in use */
7004 qla25xx_init_queues(ha
);
7006 status
= qla2x00_fw_ready(vha
);
7008 /* Issue a marker after FW becomes ready. */
7009 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
7010 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
7013 /* if no cable then assume it's good */
7014 if ((vha
->device_flags
& DFLG_NO_CABLE
))
7021 qla25xx_init_queues(struct qla_hw_data
*ha
)
7023 struct rsp_que
*rsp
= NULL
;
7024 struct req_que
*req
= NULL
;
7025 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
7029 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
7030 rsp
= ha
->rsp_q_map
[i
];
7031 if (rsp
&& test_bit(i
, ha
->rsp_qid_map
)) {
7032 rsp
->options
&= ~BIT_0
;
7033 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
7034 if (ret
!= QLA_SUCCESS
)
7035 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
7036 "%s Rsp que: %d init failed.\n",
7039 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
7040 "%s Rsp que: %d inited.\n",
7044 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
7045 req
= ha
->req_q_map
[i
];
7046 if (req
&& test_bit(i
, ha
->req_qid_map
)) {
7047 /* Clear outstanding commands array. */
7048 req
->options
&= ~BIT_0
;
7049 ret
= qla25xx_init_req_que(base_vha
, req
);
7050 if (ret
!= QLA_SUCCESS
)
7051 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
7052 "%s Req que: %d init failed.\n",
7055 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
7056 "%s Req que: %d inited.\n",
7064 * qla2x00_reset_adapter
7068 * ha = adapter block pointer.
7071 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
7073 unsigned long flags
= 0;
7074 struct qla_hw_data
*ha
= vha
->hw
;
7075 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
7077 vha
->flags
.online
= 0;
7078 ha
->isp_ops
->disable_intrs(ha
);
7080 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
7081 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
7082 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
7083 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
7084 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
7085 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
7091 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
7093 unsigned long flags
= 0;
7094 struct qla_hw_data
*ha
= vha
->hw
;
7095 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
7096 int rval
= QLA_SUCCESS
;
7098 if (IS_P3P_TYPE(ha
))
7101 vha
->flags
.online
= 0;
7102 ha
->isp_ops
->disable_intrs(ha
);
7104 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
7105 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
7106 RD_REG_DWORD(®
->hccr
);
7107 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
7108 RD_REG_DWORD(®
->hccr
);
7109 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
7111 if (IS_NOPOLLING_TYPE(ha
))
7112 ha
->isp_ops
->enable_intrs(ha
);
7117 /* On sparc systems, obtain port and node WWN from firmware
7120 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
7121 struct nvram_24xx
*nv
)
7124 struct qla_hw_data
*ha
= vha
->hw
;
7125 struct pci_dev
*pdev
= ha
->pdev
;
7126 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
7130 val
= of_get_property(dp
, "port-wwn", &len
);
7131 if (val
&& len
>= WWN_SIZE
)
7132 memcpy(nv
->port_name
, val
, WWN_SIZE
);
7134 val
= of_get_property(dp
, "node-wwn", &len
);
7135 if (val
&& len
>= WWN_SIZE
)
7136 memcpy(nv
->node_name
, val
, WWN_SIZE
);
7141 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
7144 struct init_cb_24xx
*icb
;
7145 struct nvram_24xx
*nv
;
7147 uint8_t *dptr1
, *dptr2
;
7150 struct qla_hw_data
*ha
= vha
->hw
;
7153 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
7156 /* Determine NVRAM starting address. */
7157 if (ha
->port_no
== 0) {
7158 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
7159 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
7161 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
7162 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
7165 ha
->nvram_size
= sizeof(*nv
);
7166 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
7168 /* Get VPD data into cache */
7169 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
7170 ha
->isp_ops
->read_nvram(vha
, ha
->vpd
,
7171 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
7173 /* Get NVRAM data into cache and calculate checksum. */
7174 dptr
= (uint32_t *)nv
;
7175 ha
->isp_ops
->read_nvram(vha
, dptr
, ha
->nvram_base
, ha
->nvram_size
);
7176 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
7177 chksum
+= le32_to_cpu(*dptr
);
7179 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
7180 "Contents of NVRAM\n");
7181 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
7182 nv
, ha
->nvram_size
);
7184 /* Bad NVRAM data, set defaults parameters. */
7185 if (chksum
|| memcmp("ISP ", nv
->id
, sizeof(nv
->id
)) ||
7186 le16_to_cpu(nv
->nvram_version
) < ICB_VERSION
) {
7187 /* Reset NVRAM data. */
7188 ql_log(ql_log_warn
, vha
, 0x006b,
7189 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7190 chksum
, nv
->id
, nv
->nvram_version
);
7191 ql_dump_buffer(ql_dbg_init
, vha
, 0x006b, nv
, sizeof(*nv
));
7192 ql_log(ql_log_warn
, vha
, 0x006c,
7193 "Falling back to functioning (yet invalid -- WWPN) "
7197 * Set default initialization control block.
7199 memset(nv
, 0, ha
->nvram_size
);
7200 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
7201 nv
->version
= cpu_to_le16(ICB_VERSION
);
7202 nv
->frame_payload_size
= 2048;
7203 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
7204 nv
->exchange_count
= cpu_to_le16(0);
7205 nv
->hard_address
= cpu_to_le16(124);
7206 nv
->port_name
[0] = 0x21;
7207 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
7208 nv
->port_name
[2] = 0x00;
7209 nv
->port_name
[3] = 0xe0;
7210 nv
->port_name
[4] = 0x8b;
7211 nv
->port_name
[5] = 0x1c;
7212 nv
->port_name
[6] = 0x55;
7213 nv
->port_name
[7] = 0x86;
7214 nv
->node_name
[0] = 0x20;
7215 nv
->node_name
[1] = 0x00;
7216 nv
->node_name
[2] = 0x00;
7217 nv
->node_name
[3] = 0xe0;
7218 nv
->node_name
[4] = 0x8b;
7219 nv
->node_name
[5] = 0x1c;
7220 nv
->node_name
[6] = 0x55;
7221 nv
->node_name
[7] = 0x86;
7222 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
7223 nv
->login_retry_count
= cpu_to_le16(8);
7224 nv
->interrupt_delay_timer
= cpu_to_le16(0);
7225 nv
->login_timeout
= cpu_to_le16(0);
7226 nv
->firmware_options_1
=
7227 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
7228 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
7229 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
7230 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
7231 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
7232 nv
->efi_parameters
= cpu_to_le32(0);
7233 nv
->reset_delay
= 5;
7234 nv
->max_luns_per_target
= cpu_to_le16(128);
7235 nv
->port_down_retry_count
= cpu_to_le16(30);
7236 nv
->link_down_timeout
= cpu_to_le16(30);
7241 if (qla_tgt_mode_enabled(vha
)) {
7242 /* Don't enable full login after initial LIP */
7243 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
7244 /* Don't enable LIP full login for initiator */
7245 nv
->host_p
&= cpu_to_le32(~BIT_10
);
7248 qlt_24xx_config_nvram_stage1(vha
, nv
);
7250 /* Reset Initialization control block */
7251 memset(icb
, 0, ha
->init_cb_size
);
7253 /* Copy 1st segment. */
7254 dptr1
= (uint8_t *)icb
;
7255 dptr2
= (uint8_t *)&nv
->version
;
7256 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
7258 *dptr1
++ = *dptr2
++;
7260 icb
->login_retry_count
= nv
->login_retry_count
;
7261 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
7263 /* Copy 2nd segment. */
7264 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
7265 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
7266 cnt
= (uint8_t *)&icb
->reserved_3
-
7267 (uint8_t *)&icb
->interrupt_delay_timer
;
7269 *dptr1
++ = *dptr2
++;
7270 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
7272 * Setup driver NVRAM options.
7274 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
7277 qlt_24xx_config_nvram_stage2(vha
, icb
);
7279 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
7280 /* Use alternate WWN? */
7281 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
7282 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
7285 /* Prepare nodename */
7286 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
7288 * Firmware will apply the following mask if the nodename was
7291 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
7292 icb
->node_name
[0] &= 0xF0;
7295 /* Set host adapter parameters. */
7296 ha
->flags
.disable_risc_code_load
= 0;
7297 ha
->flags
.enable_lip_reset
= 0;
7298 ha
->flags
.enable_lip_full_login
=
7299 le32_to_cpu(nv
->host_p
) & BIT_10
? 1 : 0;
7300 ha
->flags
.enable_target_reset
=
7301 le32_to_cpu(nv
->host_p
) & BIT_11
? 1 : 0;
7302 ha
->flags
.enable_led_scheme
= 0;
7303 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1 : 0;
7305 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
7306 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
7308 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
7309 sizeof(ha
->fw_seriallink_options24
));
7311 /* save HBA serial number */
7312 ha
->serial0
= icb
->port_name
[5];
7313 ha
->serial1
= icb
->port_name
[6];
7314 ha
->serial2
= icb
->port_name
[7];
7315 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
7316 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
7318 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
7320 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
7322 /* Set minimum login_timeout to 4 seconds. */
7323 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
7324 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
7325 if (le16_to_cpu(nv
->login_timeout
) < 4)
7326 nv
->login_timeout
= cpu_to_le16(4);
7327 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
7329 /* Set minimum RATOV to 100 tenths of a second. */
7332 ha
->loop_reset_delay
= nv
->reset_delay
;
7334 /* Link Down Timeout = 0:
7336 * When Port Down timer expires we will start returning
7337 * I/O's to OS with "DID_NO_CONNECT".
7339 * Link Down Timeout != 0:
7341 * The driver waits for the link to come up after link down
7342 * before returning I/Os to OS with "DID_NO_CONNECT".
7344 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
7345 ha
->loop_down_abort_time
=
7346 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
7348 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
7349 ha
->loop_down_abort_time
=
7350 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
7353 /* Need enough time to try and get the port back. */
7354 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
7355 if (qlport_down_retry
)
7356 ha
->port_down_retry_count
= qlport_down_retry
;
7358 /* Set login_retry_count */
7359 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
7360 if (ha
->port_down_retry_count
==
7361 le16_to_cpu(nv
->port_down_retry_count
) &&
7362 ha
->port_down_retry_count
> 3)
7363 ha
->login_retry_count
= ha
->port_down_retry_count
;
7364 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
7365 ha
->login_retry_count
= ha
->port_down_retry_count
;
7366 if (ql2xloginretrycount
)
7367 ha
->login_retry_count
= ql2xloginretrycount
;
7369 /* N2N: driver will initiate Login instead of FW */
7370 icb
->firmware_options_3
|= BIT_8
;
7373 if (!vha
->flags
.init_done
) {
7374 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
7375 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
7376 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
7377 le16_to_cpu(icb
->interrupt_delay_timer
) : 2;
7379 icb
->firmware_options_2
&= cpu_to_le32(
7380 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
7381 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
7382 ha
->zio_mode
= QLA_ZIO_MODE_6
;
7384 ql_log(ql_log_info
, vha
, 0x006f,
7385 "ZIO mode %d enabled; timer delay (%d us).\n",
7386 ha
->zio_mode
, ha
->zio_timer
* 100);
7388 icb
->firmware_options_2
|= cpu_to_le32(
7389 (uint32_t)ha
->zio_mode
);
7390 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
7394 ql_log(ql_log_warn
, vha
, 0x0070,
7395 "NVRAM configuration failed.\n");
7401 qla27xx_print_image(struct scsi_qla_host
*vha
, char *name
,
7402 struct qla27xx_image_status
*image_status
)
7404 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7405 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7407 image_status
->image_status_mask
,
7408 le16_to_cpu(image_status
->generation
),
7409 image_status
->ver_major
,
7410 image_status
->ver_minor
,
7411 image_status
->bitmap
,
7412 le32_to_cpu(image_status
->checksum
),
7413 le32_to_cpu(image_status
->signature
));
7417 qla28xx_check_aux_image_status_signature(
7418 struct qla27xx_image_status
*image_status
)
7420 ulong signature
= le32_to_cpu(image_status
->signature
);
7422 return signature
!= QLA28XX_AUX_IMG_STATUS_SIGN
;
7426 qla27xx_check_image_status_signature(struct qla27xx_image_status
*image_status
)
7428 ulong signature
= le32_to_cpu(image_status
->signature
);
7431 signature
!= QLA27XX_IMG_STATUS_SIGN
&&
7432 signature
!= QLA28XX_IMG_STATUS_SIGN
;
7436 qla27xx_image_status_checksum(struct qla27xx_image_status
*image_status
)
7438 uint32_t *p
= (void *)image_status
;
7439 uint n
= sizeof(*image_status
) / sizeof(*p
);
7443 sum
+= le32_to_cpup(p
);
7449 qla28xx_component_bitmask(struct qla27xx_image_status
*aux
, uint bitmask
)
7451 return aux
->bitmap
& bitmask
?
7452 QLA27XX_SECONDARY_IMAGE
: QLA27XX_PRIMARY_IMAGE
;
7456 qla28xx_component_status(
7457 struct active_regions
*active_regions
, struct qla27xx_image_status
*aux
)
7459 active_regions
->aux
.board_config
=
7460 qla28xx_component_bitmask(aux
, QLA28XX_AUX_IMG_BOARD_CONFIG
);
7462 active_regions
->aux
.vpd_nvram
=
7463 qla28xx_component_bitmask(aux
, QLA28XX_AUX_IMG_VPD_NVRAM
);
7465 active_regions
->aux
.npiv_config_0_1
=
7466 qla28xx_component_bitmask(aux
, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1
);
7468 active_regions
->aux
.npiv_config_2_3
=
7469 qla28xx_component_bitmask(aux
, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3
);
7473 qla27xx_compare_image_generation(
7474 struct qla27xx_image_status
*pri_image_status
,
7475 struct qla27xx_image_status
*sec_image_status
)
7477 /* calculate generation delta as uint16 (this accounts for wrap) */
7479 le16_to_cpu(pri_image_status
->generation
) -
7480 le16_to_cpu(sec_image_status
->generation
);
7482 ql_dbg(ql_dbg_init
, NULL
, 0x0180, "generation delta = %d\n", delta
);
7488 qla28xx_get_aux_images(
7489 struct scsi_qla_host
*vha
, struct active_regions
*active_regions
)
7491 struct qla_hw_data
*ha
= vha
->hw
;
7492 struct qla27xx_image_status pri_aux_image_status
, sec_aux_image_status
;
7493 bool valid_pri_image
= false, valid_sec_image
= false;
7494 bool active_pri_image
= false, active_sec_image
= false;
7496 if (!ha
->flt_region_aux_img_status_pri
) {
7497 ql_dbg(ql_dbg_init
, vha
, 0x018a, "Primary aux image not addressed\n");
7498 goto check_sec_image
;
7501 qla24xx_read_flash_data(vha
, (void *)&pri_aux_image_status
,
7502 ha
->flt_region_aux_img_status_pri
,
7503 sizeof(pri_aux_image_status
) >> 2);
7504 qla27xx_print_image(vha
, "Primary aux image", &pri_aux_image_status
);
7506 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status
)) {
7507 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7508 "Primary aux image signature (%#x) not valid\n",
7509 le32_to_cpu(pri_aux_image_status
.signature
));
7510 goto check_sec_image
;
7513 if (qla27xx_image_status_checksum(&pri_aux_image_status
)) {
7514 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7515 "Primary aux image checksum failed\n");
7516 goto check_sec_image
;
7519 valid_pri_image
= true;
7521 if (pri_aux_image_status
.image_status_mask
& 1) {
7522 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7523 "Primary aux image is active\n");
7524 active_pri_image
= true;
7528 if (!ha
->flt_region_aux_img_status_sec
) {
7529 ql_dbg(ql_dbg_init
, vha
, 0x018a,
7530 "Secondary aux image not addressed\n");
7531 goto check_valid_image
;
7534 qla24xx_read_flash_data(vha
, (void *)&sec_aux_image_status
,
7535 ha
->flt_region_aux_img_status_sec
,
7536 sizeof(sec_aux_image_status
) >> 2);
7537 qla27xx_print_image(vha
, "Secondary aux image", &sec_aux_image_status
);
7539 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status
)) {
7540 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7541 "Secondary aux image signature (%#x) not valid\n",
7542 le32_to_cpu(sec_aux_image_status
.signature
));
7543 goto check_valid_image
;
7546 if (qla27xx_image_status_checksum(&sec_aux_image_status
)) {
7547 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7548 "Secondary aux image checksum failed\n");
7549 goto check_valid_image
;
7552 valid_sec_image
= true;
7554 if (sec_aux_image_status
.image_status_mask
& 1) {
7555 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7556 "Secondary aux image is active\n");
7557 active_sec_image
= true;
7561 if (valid_pri_image
&& active_pri_image
&&
7562 valid_sec_image
&& active_sec_image
) {
7563 if (qla27xx_compare_image_generation(&pri_aux_image_status
,
7564 &sec_aux_image_status
) >= 0) {
7565 qla28xx_component_status(active_regions
,
7566 &pri_aux_image_status
);
7568 qla28xx_component_status(active_regions
,
7569 &sec_aux_image_status
);
7571 } else if (valid_pri_image
&& active_pri_image
) {
7572 qla28xx_component_status(active_regions
, &pri_aux_image_status
);
7573 } else if (valid_sec_image
&& active_sec_image
) {
7574 qla28xx_component_status(active_regions
, &sec_aux_image_status
);
7577 ql_dbg(ql_dbg_init
, vha
, 0x018f,
7578 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7579 active_regions
->aux
.board_config
,
7580 active_regions
->aux
.vpd_nvram
,
7581 active_regions
->aux
.npiv_config_0_1
,
7582 active_regions
->aux
.npiv_config_2_3
);
7586 qla27xx_get_active_image(struct scsi_qla_host
*vha
,
7587 struct active_regions
*active_regions
)
7589 struct qla_hw_data
*ha
= vha
->hw
;
7590 struct qla27xx_image_status pri_image_status
, sec_image_status
;
7591 bool valid_pri_image
= false, valid_sec_image
= false;
7592 bool active_pri_image
= false, active_sec_image
= false;
7594 if (!ha
->flt_region_img_status_pri
) {
7595 ql_dbg(ql_dbg_init
, vha
, 0x018a, "Primary image not addressed\n");
7596 goto check_sec_image
;
7599 if (qla24xx_read_flash_data(vha
, (void *)(&pri_image_status
),
7600 ha
->flt_region_img_status_pri
, sizeof(pri_image_status
) >> 2) !=
7603 goto check_sec_image
;
7605 qla27xx_print_image(vha
, "Primary image", &pri_image_status
);
7607 if (qla27xx_check_image_status_signature(&pri_image_status
)) {
7608 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7609 "Primary image signature (%#x) not valid\n",
7610 le32_to_cpu(pri_image_status
.signature
));
7611 goto check_sec_image
;
7614 if (qla27xx_image_status_checksum(&pri_image_status
)) {
7615 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7616 "Primary image checksum failed\n");
7617 goto check_sec_image
;
7620 valid_pri_image
= true;
7622 if (pri_image_status
.image_status_mask
& 1) {
7623 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7624 "Primary image is active\n");
7625 active_pri_image
= true;
7629 if (!ha
->flt_region_img_status_sec
) {
7630 ql_dbg(ql_dbg_init
, vha
, 0x018a, "Secondary image not addressed\n");
7631 goto check_valid_image
;
7634 qla24xx_read_flash_data(vha
, (uint32_t *)(&sec_image_status
),
7635 ha
->flt_region_img_status_sec
, sizeof(sec_image_status
) >> 2);
7636 qla27xx_print_image(vha
, "Secondary image", &sec_image_status
);
7638 if (qla27xx_check_image_status_signature(&sec_image_status
)) {
7639 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7640 "Secondary image signature (%#x) not valid\n",
7641 le32_to_cpu(sec_image_status
.signature
));
7642 goto check_valid_image
;
7645 if (qla27xx_image_status_checksum(&sec_image_status
)) {
7646 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7647 "Secondary image checksum failed\n");
7648 goto check_valid_image
;
7651 valid_sec_image
= true;
7653 if (sec_image_status
.image_status_mask
& 1) {
7654 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7655 "Secondary image is active\n");
7656 active_sec_image
= true;
7660 if (valid_pri_image
&& active_pri_image
)
7661 active_regions
->global
= QLA27XX_PRIMARY_IMAGE
;
7663 if (valid_sec_image
&& active_sec_image
) {
7664 if (!active_regions
->global
||
7665 qla27xx_compare_image_generation(
7666 &pri_image_status
, &sec_image_status
) < 0) {
7667 active_regions
->global
= QLA27XX_SECONDARY_IMAGE
;
7671 ql_dbg(ql_dbg_init
, vha
, 0x018f, "active image %s (%u)\n",
7672 active_regions
->global
== QLA27XX_DEFAULT_IMAGE
?
7673 "default (boot/fw)" :
7674 active_regions
->global
== QLA27XX_PRIMARY_IMAGE
?
7676 active_regions
->global
== QLA27XX_SECONDARY_IMAGE
?
7677 "secondary" : "invalid",
7678 active_regions
->global
);
7681 bool qla24xx_risc_firmware_invalid(uint32_t *dword
)
7684 !(dword
[4] | dword
[5] | dword
[6] | dword
[7]) ||
7685 !(~dword
[4] | ~dword
[5] | ~dword
[6] | ~dword
[7]);
7689 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
7693 uint templates
, segments
, fragment
;
7698 uint32_t risc_addr
, risc_size
, risc_attr
= 0;
7699 struct qla_hw_data
*ha
= vha
->hw
;
7700 struct req_que
*req
= ha
->req_q_map
[0];
7701 struct fwdt
*fwdt
= ha
->fwdt
;
7703 ql_dbg(ql_dbg_init
, vha
, 0x008b,
7704 "FW: Loading firmware from flash (%x).\n", faddr
);
7706 dcode
= (void *)req
->ring
;
7707 qla24xx_read_flash_data(vha
, dcode
, faddr
, 8);
7708 if (qla24xx_risc_firmware_invalid(dcode
)) {
7709 ql_log(ql_log_fatal
, vha
, 0x008c,
7710 "Unable to verify the integrity of flash firmware "
7712 ql_log(ql_log_fatal
, vha
, 0x008d,
7713 "Firmware data: %08x %08x %08x %08x.\n",
7714 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7716 return QLA_FUNCTION_FAILED
;
7719 dcode
= (void *)req
->ring
;
7721 segments
= FA_RISC_CODE_SEGMENTS
;
7722 for (j
= 0; j
< segments
; j
++) {
7723 ql_dbg(ql_dbg_init
, vha
, 0x008d,
7724 "-> Loading segment %u...\n", j
);
7725 qla24xx_read_flash_data(vha
, dcode
, faddr
, 10);
7726 risc_addr
= be32_to_cpu(dcode
[2]);
7727 risc_size
= be32_to_cpu(dcode
[3]);
7729 *srisc_addr
= risc_addr
;
7730 risc_attr
= be32_to_cpu(dcode
[9]);
7733 dlen
= ha
->fw_transfer_size
>> 2;
7734 for (fragment
= 0; risc_size
; fragment
++) {
7735 if (dlen
> risc_size
)
7738 ql_dbg(ql_dbg_init
, vha
, 0x008e,
7739 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7740 fragment
, risc_addr
, faddr
, dlen
);
7741 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
7742 for (i
= 0; i
< dlen
; i
++)
7743 dcode
[i
] = swab32(dcode
[i
]);
7745 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
, dlen
);
7747 ql_log(ql_log_fatal
, vha
, 0x008f,
7748 "-> Failed load firmware fragment %u.\n",
7750 return QLA_FUNCTION_FAILED
;
7759 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
7762 templates
= (risc_attr
& BIT_9
) ? 2 : 1;
7763 ql_dbg(ql_dbg_init
, vha
, 0x0160, "-> templates = %u\n", templates
);
7764 for (j
= 0; j
< templates
; j
++, fwdt
++) {
7766 vfree(fwdt
->template);
7767 fwdt
->template = NULL
;
7770 dcode
= (void *)req
->ring
;
7771 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
7772 risc_size
= be32_to_cpu(dcode
[2]);
7773 ql_dbg(ql_dbg_init
, vha
, 0x0161,
7774 "-> fwdt%u template array at %#x (%#x dwords)\n",
7775 j
, faddr
, risc_size
);
7776 if (!risc_size
|| !~risc_size
) {
7777 ql_dbg(ql_dbg_init
, vha
, 0x0162,
7778 "-> fwdt%u failed to read array\n", j
);
7782 /* skip header and ignore checksum */
7786 ql_dbg(ql_dbg_init
, vha
, 0x0163,
7787 "-> fwdt%u template allocate template %#x words...\n",
7789 fwdt
->template = vmalloc(risc_size
* sizeof(*dcode
));
7790 if (!fwdt
->template) {
7791 ql_log(ql_log_warn
, vha
, 0x0164,
7792 "-> fwdt%u failed allocate template.\n", j
);
7796 dcode
= fwdt
->template;
7797 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
7799 if (!qla27xx_fwdt_template_valid(dcode
)) {
7800 ql_log(ql_log_warn
, vha
, 0x0165,
7801 "-> fwdt%u failed template validate\n", j
);
7805 dlen
= qla27xx_fwdt_template_size(dcode
);
7806 ql_dbg(ql_dbg_init
, vha
, 0x0166,
7807 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7808 j
, dlen
, dlen
/ sizeof(*dcode
));
7809 if (dlen
> risc_size
* sizeof(*dcode
)) {
7810 ql_log(ql_log_warn
, vha
, 0x0167,
7811 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7812 j
, dlen
- risc_size
* sizeof(*dcode
));
7816 fwdt
->length
= dlen
;
7817 ql_dbg(ql_dbg_init
, vha
, 0x0168,
7818 "-> fwdt%u loaded template ok\n", j
);
7820 faddr
+= risc_size
+ 1;
7827 vfree(fwdt
->template);
7828 fwdt
->template = NULL
;
7834 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7837 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7841 uint16_t *wcode
, *fwcode
;
7842 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
7843 struct fw_blob
*blob
;
7844 struct qla_hw_data
*ha
= vha
->hw
;
7845 struct req_que
*req
= ha
->req_q_map
[0];
7847 /* Load firmware blob. */
7848 blob
= qla2x00_request_firmware(vha
);
7850 ql_log(ql_log_info
, vha
, 0x0083,
7851 "Firmware image unavailable.\n");
7852 ql_log(ql_log_info
, vha
, 0x0084,
7853 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
7854 return QLA_FUNCTION_FAILED
;
7859 wcode
= (uint16_t *)req
->ring
;
7861 fwcode
= (uint16_t *)blob
->fw
->data
;
7864 /* Validate firmware image by checking version. */
7865 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
7866 ql_log(ql_log_fatal
, vha
, 0x0085,
7867 "Unable to verify integrity of firmware image (%zd).\n",
7869 goto fail_fw_integrity
;
7871 for (i
= 0; i
< 4; i
++)
7872 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
7873 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
7874 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
7875 wcode
[2] == 0 && wcode
[3] == 0)) {
7876 ql_log(ql_log_fatal
, vha
, 0x0086,
7877 "Unable to verify integrity of firmware image.\n");
7878 ql_log(ql_log_fatal
, vha
, 0x0087,
7879 "Firmware data: %04x %04x %04x %04x.\n",
7880 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
7881 goto fail_fw_integrity
;
7885 while (*seg
&& rval
== QLA_SUCCESS
) {
7887 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
7888 risc_size
= be16_to_cpu(fwcode
[3]);
7890 /* Validate firmware image size. */
7891 fwclen
+= risc_size
* sizeof(uint16_t);
7892 if (blob
->fw
->size
< fwclen
) {
7893 ql_log(ql_log_fatal
, vha
, 0x0088,
7894 "Unable to verify integrity of firmware image "
7895 "(%zd).\n", blob
->fw
->size
);
7896 goto fail_fw_integrity
;
7900 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7901 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
7902 if (wlen
> risc_size
)
7904 ql_dbg(ql_dbg_init
, vha
, 0x0089,
7905 "Loading risc segment@ risc addr %x number of "
7906 "words 0x%x.\n", risc_addr
, wlen
);
7908 for (i
= 0; i
< wlen
; i
++)
7909 wcode
[i
] = swab16(fwcode
[i
]);
7911 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7914 ql_log(ql_log_fatal
, vha
, 0x008a,
7915 "Failed to load segment %d of firmware.\n",
7932 return QLA_FUNCTION_FAILED
;
7936 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7939 uint templates
, segments
, fragment
;
7942 uint32_t risc_addr
, risc_size
, risc_attr
= 0;
7945 struct fw_blob
*blob
;
7947 struct qla_hw_data
*ha
= vha
->hw
;
7948 struct req_que
*req
= ha
->req_q_map
[0];
7949 struct fwdt
*fwdt
= ha
->fwdt
;
7951 ql_dbg(ql_dbg_init
, vha
, 0x0090,
7952 "-> FW: Loading via request-firmware.\n");
7954 blob
= qla2x00_request_firmware(vha
);
7956 ql_log(ql_log_warn
, vha
, 0x0092,
7957 "-> Firmware file not found.\n");
7959 return QLA_FUNCTION_FAILED
;
7962 fwcode
= (void *)blob
->fw
->data
;
7964 if (qla24xx_risc_firmware_invalid(dcode
)) {
7965 ql_log(ql_log_fatal
, vha
, 0x0093,
7966 "Unable to verify integrity of firmware image (%zd).\n",
7968 ql_log(ql_log_fatal
, vha
, 0x0095,
7969 "Firmware data: %08x %08x %08x %08x.\n",
7970 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7971 return QLA_FUNCTION_FAILED
;
7974 dcode
= (void *)req
->ring
;
7976 segments
= FA_RISC_CODE_SEGMENTS
;
7977 for (j
= 0; j
< segments
; j
++) {
7978 ql_dbg(ql_dbg_init
, vha
, 0x0096,
7979 "-> Loading segment %u...\n", j
);
7980 risc_addr
= be32_to_cpu(fwcode
[2]);
7981 risc_size
= be32_to_cpu(fwcode
[3]);
7984 *srisc_addr
= risc_addr
;
7985 risc_attr
= be32_to_cpu(fwcode
[9]);
7988 dlen
= ha
->fw_transfer_size
>> 2;
7989 for (fragment
= 0; risc_size
; fragment
++) {
7990 if (dlen
> risc_size
)
7993 ql_dbg(ql_dbg_init
, vha
, 0x0097,
7994 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7995 fragment
, risc_addr
,
7996 (uint32_t)(fwcode
- (typeof(fwcode
))blob
->fw
->data
),
7999 for (i
= 0; i
< dlen
; i
++)
8000 dcode
[i
] = swab32(fwcode
[i
]);
8002 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
, dlen
);
8004 ql_log(ql_log_fatal
, vha
, 0x0098,
8005 "-> Failed load firmware fragment %u.\n",
8007 return QLA_FUNCTION_FAILED
;
8016 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
8019 templates
= (risc_attr
& BIT_9
) ? 2 : 1;
8020 ql_dbg(ql_dbg_init
, vha
, 0x0170, "-> templates = %u\n", templates
);
8021 for (j
= 0; j
< templates
; j
++, fwdt
++) {
8023 vfree(fwdt
->template);
8024 fwdt
->template = NULL
;
8027 risc_size
= be32_to_cpu(fwcode
[2]);
8028 ql_dbg(ql_dbg_init
, vha
, 0x0171,
8029 "-> fwdt%u template array at %#x (%#x dwords)\n",
8030 j
, (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
),
8032 if (!risc_size
|| !~risc_size
) {
8033 ql_dbg(ql_dbg_init
, vha
, 0x0172,
8034 "-> fwdt%u failed to read array\n", j
);
8038 /* skip header and ignore checksum */
8042 ql_dbg(ql_dbg_init
, vha
, 0x0173,
8043 "-> fwdt%u template allocate template %#x words...\n",
8045 fwdt
->template = vmalloc(risc_size
* sizeof(*dcode
));
8046 if (!fwdt
->template) {
8047 ql_log(ql_log_warn
, vha
, 0x0174,
8048 "-> fwdt%u failed allocate template.\n", j
);
8052 dcode
= fwdt
->template;
8053 for (i
= 0; i
< risc_size
; i
++)
8054 dcode
[i
] = fwcode
[i
];
8056 if (!qla27xx_fwdt_template_valid(dcode
)) {
8057 ql_log(ql_log_warn
, vha
, 0x0175,
8058 "-> fwdt%u failed template validate\n", j
);
8062 dlen
= qla27xx_fwdt_template_size(dcode
);
8063 ql_dbg(ql_dbg_init
, vha
, 0x0176,
8064 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8065 j
, dlen
, dlen
/ sizeof(*dcode
));
8066 if (dlen
> risc_size
* sizeof(*dcode
)) {
8067 ql_log(ql_log_warn
, vha
, 0x0177,
8068 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8069 j
, dlen
- risc_size
* sizeof(*dcode
));
8073 fwdt
->length
= dlen
;
8074 ql_dbg(ql_dbg_init
, vha
, 0x0178,
8075 "-> fwdt%u loaded template ok\n", j
);
8077 fwcode
+= risc_size
+ 1;
8084 vfree(fwdt
->template);
8085 fwdt
->template = NULL
;
8092 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
8096 if (ql2xfwloadbin
== 1)
8097 return qla81xx_load_risc(vha
, srisc_addr
);
8101 * 1) Firmware via request-firmware interface (.bin file).
8102 * 2) Firmware residing in flash.
8104 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
8105 if (rval
== QLA_SUCCESS
)
8108 return qla24xx_load_risc_flash(vha
, srisc_addr
,
8109 vha
->hw
->flt_region_fw
);
8113 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
8116 struct qla_hw_data
*ha
= vha
->hw
;
8117 struct active_regions active_regions
= { };
8119 if (ql2xfwloadbin
== 2)
8122 /* FW Load priority:
8123 * 1) Firmware residing in flash.
8124 * 2) Firmware via request-firmware interface (.bin file).
8125 * 3) Golden-Firmware residing in flash -- (limited operation).
8128 if (!IS_QLA27XX(ha
) && !IS_QLA28XX(ha
))
8129 goto try_primary_fw
;
8131 qla27xx_get_active_image(vha
, &active_regions
);
8133 if (active_regions
.global
!= QLA27XX_SECONDARY_IMAGE
)
8134 goto try_primary_fw
;
8136 ql_dbg(ql_dbg_init
, vha
, 0x008b,
8137 "Loading secondary firmware image.\n");
8138 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw_sec
);
8143 ql_dbg(ql_dbg_init
, vha
, 0x008b,
8144 "Loading primary firmware image.\n");
8145 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
8150 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
8151 if (!rval
|| !ha
->flt_region_gold_fw
)
8154 ql_log(ql_log_info
, vha
, 0x0099,
8155 "Attempting to fallback to golden firmware.\n");
8156 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
8160 ql_log(ql_log_info
, vha
, 0x009a, "Need firmware flash update.\n");
8161 ha
->flags
.running_gold_fw
= 1;
8166 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
8169 struct qla_hw_data
*ha
= vha
->hw
;
8171 if (ha
->flags
.pci_channel_io_perm_failure
)
8173 if (!IS_FWI2_CAPABLE(ha
))
8175 if (!ha
->fw_major_version
)
8177 if (!ha
->flags
.fw_started
)
8180 ret
= qla2x00_stop_firmware(vha
);
8181 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
8182 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
8183 ha
->isp_ops
->reset_chip(vha
);
8184 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
8186 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
8188 ql_log(ql_log_info
, vha
, 0x8015,
8189 "Attempting retry of stop-firmware command.\n");
8190 ret
= qla2x00_stop_firmware(vha
);
8194 ha
->flags
.fw_init_done
= 0;
8198 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
8200 int rval
= QLA_SUCCESS
;
8202 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
8203 struct qla_hw_data
*ha
= vha
->hw
;
8204 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
8209 rval
= qla2x00_fw_ready(base_vha
);
8211 if (rval
== QLA_SUCCESS
) {
8212 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8213 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
8216 vha
->flags
.management_server_logged_in
= 0;
8218 /* Login to SNS first */
8219 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
8221 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
8222 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
8223 ql_dbg(ql_dbg_init
, vha
, 0x0120,
8224 "Failed SNS login: loop_id=%x, rval2=%d\n",
8227 ql_dbg(ql_dbg_init
, vha
, 0x0103,
8228 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8229 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8230 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
8231 return (QLA_FUNCTION_FAILED
);
8234 atomic_set(&vha
->loop_down_timer
, 0);
8235 atomic_set(&vha
->loop_state
, LOOP_UP
);
8236 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8237 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
8238 rval
= qla2x00_loop_resync(base_vha
);
8243 /* 84XX Support **************************************************************/
8245 static LIST_HEAD(qla_cs84xx_list
);
8246 static DEFINE_MUTEX(qla_cs84xx_mutex
);
8248 static struct qla_chip_state_84xx
*
8249 qla84xx_get_chip(struct scsi_qla_host
*vha
)
8251 struct qla_chip_state_84xx
*cs84xx
;
8252 struct qla_hw_data
*ha
= vha
->hw
;
8254 mutex_lock(&qla_cs84xx_mutex
);
8256 /* Find any shared 84xx chip. */
8257 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
8258 if (cs84xx
->bus
== ha
->pdev
->bus
) {
8259 kref_get(&cs84xx
->kref
);
8264 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
8268 kref_init(&cs84xx
->kref
);
8269 spin_lock_init(&cs84xx
->access_lock
);
8270 mutex_init(&cs84xx
->fw_update_mutex
);
8271 cs84xx
->bus
= ha
->pdev
->bus
;
8273 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
8275 mutex_unlock(&qla_cs84xx_mutex
);
8280 __qla84xx_chip_release(struct kref
*kref
)
8282 struct qla_chip_state_84xx
*cs84xx
=
8283 container_of(kref
, struct qla_chip_state_84xx
, kref
);
8285 mutex_lock(&qla_cs84xx_mutex
);
8286 list_del(&cs84xx
->list
);
8287 mutex_unlock(&qla_cs84xx_mutex
);
8292 qla84xx_put_chip(struct scsi_qla_host
*vha
)
8294 struct qla_hw_data
*ha
= vha
->hw
;
8297 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
8301 qla84xx_init_chip(scsi_qla_host_t
*vha
)
8305 struct qla_hw_data
*ha
= vha
->hw
;
8307 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
8309 rval
= qla84xx_verify_chip(vha
, status
);
8311 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
8313 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
8317 /* 81XX Support **************************************************************/
8320 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
8323 struct init_cb_81xx
*icb
;
8324 struct nvram_81xx
*nv
;
8326 uint8_t *dptr1
, *dptr2
;
8329 struct qla_hw_data
*ha
= vha
->hw
;
8331 struct active_regions active_regions
= { };
8334 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
8337 /* Determine NVRAM starting address. */
8338 ha
->nvram_size
= sizeof(*nv
);
8339 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
8340 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
8341 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
8343 if (IS_QLA28XX(ha
) || IS_QLA27XX(ha
))
8344 qla28xx_get_aux_images(vha
, &active_regions
);
8346 /* Get VPD data into cache */
8347 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
8349 faddr
= ha
->flt_region_vpd
;
8350 if (IS_QLA28XX(ha
)) {
8351 if (active_regions
.aux
.vpd_nvram
== QLA27XX_SECONDARY_IMAGE
)
8352 faddr
= ha
->flt_region_vpd_sec
;
8353 ql_dbg(ql_dbg_init
, vha
, 0x0110,
8354 "Loading %s nvram image.\n",
8355 active_regions
.aux
.vpd_nvram
== QLA27XX_PRIMARY_IMAGE
?
8356 "primary" : "secondary");
8358 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, faddr
<< 2, ha
->vpd_size
);
8360 /* Get NVRAM data into cache and calculate checksum. */
8361 faddr
= ha
->flt_region_nvram
;
8362 if (IS_QLA28XX(ha
)) {
8363 if (active_regions
.aux
.vpd_nvram
== QLA27XX_SECONDARY_IMAGE
)
8364 faddr
= ha
->flt_region_nvram_sec
;
8366 ql_dbg(ql_dbg_init
, vha
, 0x0110,
8367 "Loading %s nvram image.\n",
8368 active_regions
.aux
.vpd_nvram
== QLA27XX_PRIMARY_IMAGE
?
8369 "primary" : "secondary");
8370 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, faddr
<< 2, ha
->nvram_size
);
8372 dptr
= (uint32_t *)nv
;
8373 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
8374 chksum
+= le32_to_cpu(*dptr
);
8376 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
8377 "Contents of NVRAM:\n");
8378 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
8379 nv
, ha
->nvram_size
);
8381 /* Bad NVRAM data, set defaults parameters. */
8382 if (chksum
|| memcmp("ISP ", nv
->id
, sizeof(nv
->id
)) ||
8383 le16_to_cpu(nv
->nvram_version
) < ICB_VERSION
) {
8384 /* Reset NVRAM data. */
8385 ql_log(ql_log_info
, vha
, 0x0073,
8386 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8387 chksum
, nv
->id
, le16_to_cpu(nv
->nvram_version
));
8388 ql_dump_buffer(ql_dbg_init
, vha
, 0x0073, nv
, sizeof(*nv
));
8389 ql_log(ql_log_info
, vha
, 0x0074,
8390 "Falling back to functioning (yet invalid -- WWPN) "
8394 * Set default initialization control block.
8396 memset(nv
, 0, ha
->nvram_size
);
8397 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
8398 nv
->version
= cpu_to_le16(ICB_VERSION
);
8399 nv
->frame_payload_size
= 2048;
8400 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
8401 nv
->exchange_count
= cpu_to_le16(0);
8402 nv
->port_name
[0] = 0x21;
8403 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
8404 nv
->port_name
[2] = 0x00;
8405 nv
->port_name
[3] = 0xe0;
8406 nv
->port_name
[4] = 0x8b;
8407 nv
->port_name
[5] = 0x1c;
8408 nv
->port_name
[6] = 0x55;
8409 nv
->port_name
[7] = 0x86;
8410 nv
->node_name
[0] = 0x20;
8411 nv
->node_name
[1] = 0x00;
8412 nv
->node_name
[2] = 0x00;
8413 nv
->node_name
[3] = 0xe0;
8414 nv
->node_name
[4] = 0x8b;
8415 nv
->node_name
[5] = 0x1c;
8416 nv
->node_name
[6] = 0x55;
8417 nv
->node_name
[7] = 0x86;
8418 nv
->login_retry_count
= cpu_to_le16(8);
8419 nv
->interrupt_delay_timer
= cpu_to_le16(0);
8420 nv
->login_timeout
= cpu_to_le16(0);
8421 nv
->firmware_options_1
=
8422 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
8423 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
8424 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
8425 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
8426 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
8427 nv
->efi_parameters
= cpu_to_le32(0);
8428 nv
->reset_delay
= 5;
8429 nv
->max_luns_per_target
= cpu_to_le16(128);
8430 nv
->port_down_retry_count
= cpu_to_le16(30);
8431 nv
->link_down_timeout
= cpu_to_le16(180);
8432 nv
->enode_mac
[0] = 0x00;
8433 nv
->enode_mac
[1] = 0xC0;
8434 nv
->enode_mac
[2] = 0xDD;
8435 nv
->enode_mac
[3] = 0x04;
8436 nv
->enode_mac
[4] = 0x05;
8437 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
8442 if (IS_T10_PI_CAPABLE(ha
))
8443 nv
->frame_payload_size
&= ~7;
8445 qlt_81xx_config_nvram_stage1(vha
, nv
);
8447 /* Reset Initialization control block */
8448 memset(icb
, 0, ha
->init_cb_size
);
8450 /* Copy 1st segment. */
8451 dptr1
= (uint8_t *)icb
;
8452 dptr2
= (uint8_t *)&nv
->version
;
8453 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
8455 *dptr1
++ = *dptr2
++;
8457 icb
->login_retry_count
= nv
->login_retry_count
;
8459 /* Copy 2nd segment. */
8460 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
8461 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
8462 cnt
= (uint8_t *)&icb
->reserved_5
-
8463 (uint8_t *)&icb
->interrupt_delay_timer
;
8465 *dptr1
++ = *dptr2
++;
8467 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
8468 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8469 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
8470 icb
->enode_mac
[0] = 0x00;
8471 icb
->enode_mac
[1] = 0xC0;
8472 icb
->enode_mac
[2] = 0xDD;
8473 icb
->enode_mac
[3] = 0x04;
8474 icb
->enode_mac
[4] = 0x05;
8475 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
8478 /* Use extended-initialization control block. */
8479 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
8480 ha
->frame_payload_size
= le16_to_cpu(icb
->frame_payload_size
);
8482 * Setup driver NVRAM options.
8484 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
8487 qlt_81xx_config_nvram_stage2(vha
, icb
);
8489 /* Use alternate WWN? */
8490 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
8491 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
8492 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
8495 /* Prepare nodename */
8496 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
8498 * Firmware will apply the following mask if the nodename was
8501 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
8502 icb
->node_name
[0] &= 0xF0;
8505 /* Set host adapter parameters. */
8506 ha
->flags
.disable_risc_code_load
= 0;
8507 ha
->flags
.enable_lip_reset
= 0;
8508 ha
->flags
.enable_lip_full_login
=
8509 le32_to_cpu(nv
->host_p
) & BIT_10
? 1 : 0;
8510 ha
->flags
.enable_target_reset
=
8511 le32_to_cpu(nv
->host_p
) & BIT_11
? 1 : 0;
8512 ha
->flags
.enable_led_scheme
= 0;
8513 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1 : 0;
8515 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
8516 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
8518 /* save HBA serial number */
8519 ha
->serial0
= icb
->port_name
[5];
8520 ha
->serial1
= icb
->port_name
[6];
8521 ha
->serial2
= icb
->port_name
[7];
8522 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
8523 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
8525 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
8527 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
8529 /* Set minimum login_timeout to 4 seconds. */
8530 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
8531 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
8532 if (le16_to_cpu(nv
->login_timeout
) < 4)
8533 nv
->login_timeout
= cpu_to_le16(4);
8534 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
8536 /* Set minimum RATOV to 100 tenths of a second. */
8539 ha
->loop_reset_delay
= nv
->reset_delay
;
8541 /* Link Down Timeout = 0:
8543 * When Port Down timer expires we will start returning
8544 * I/O's to OS with "DID_NO_CONNECT".
8546 * Link Down Timeout != 0:
8548 * The driver waits for the link to come up after link down
8549 * before returning I/Os to OS with "DID_NO_CONNECT".
8551 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
8552 ha
->loop_down_abort_time
=
8553 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
8555 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
8556 ha
->loop_down_abort_time
=
8557 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
8560 /* Need enough time to try and get the port back. */
8561 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
8562 if (qlport_down_retry
)
8563 ha
->port_down_retry_count
= qlport_down_retry
;
8565 /* Set login_retry_count */
8566 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
8567 if (ha
->port_down_retry_count
==
8568 le16_to_cpu(nv
->port_down_retry_count
) &&
8569 ha
->port_down_retry_count
> 3)
8570 ha
->login_retry_count
= ha
->port_down_retry_count
;
8571 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
8572 ha
->login_retry_count
= ha
->port_down_retry_count
;
8573 if (ql2xloginretrycount
)
8574 ha
->login_retry_count
= ql2xloginretrycount
;
8576 /* if not running MSI-X we need handshaking on interrupts */
8577 if (!vha
->hw
->flags
.msix_enabled
&&
8578 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
) || IS_QLA28XX(ha
)))
8579 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
8582 if (!vha
->flags
.init_done
) {
8583 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
8584 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
8585 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
8586 le16_to_cpu(icb
->interrupt_delay_timer
) : 2;
8588 icb
->firmware_options_2
&= cpu_to_le32(
8589 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
8590 vha
->flags
.process_response_queue
= 0;
8591 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
8592 ha
->zio_mode
= QLA_ZIO_MODE_6
;
8594 ql_log(ql_log_info
, vha
, 0x0075,
8595 "ZIO mode %d enabled; timer delay (%d us).\n",
8597 ha
->zio_timer
* 100);
8599 icb
->firmware_options_2
|= cpu_to_le32(
8600 (uint32_t)ha
->zio_mode
);
8601 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
8602 vha
->flags
.process_response_queue
= 1;
8605 /* enable RIDA Format2 */
8606 icb
->firmware_options_3
|= BIT_0
;
8608 /* N2N: driver will initiate Login instead of FW */
8609 icb
->firmware_options_3
|= BIT_8
;
8611 /* Determine NVMe/FCP priority for target ports */
8612 ha
->fc4_type_priority
= qla2xxx_get_fc4_priority(vha
);
8615 ql_log(ql_log_warn
, vha
, 0x0076,
8616 "NVRAM configuration failed.\n");
8622 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
8625 struct qla_hw_data
*ha
= vha
->hw
;
8626 struct scsi_qla_host
*vp
;
8627 unsigned long flags
;
8629 status
= qla2x00_init_rings(vha
);
8631 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8632 ha
->flags
.chip_reset_done
= 1;
8634 status
= qla2x00_fw_ready(vha
);
8636 /* Issue a marker after FW becomes ready. */
8637 qla2x00_marker(vha
, ha
->base_qpair
, 0, 0, MK_SYNC_ALL
);
8638 vha
->flags
.online
= 1;
8639 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8642 /* if no cable then assume it's good */
8643 if ((vha
->device_flags
& DFLG_NO_CABLE
))
8648 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8650 if (!atomic_read(&vha
->loop_down_timer
)) {
8652 * Issue marker command only when we are going
8653 * to start the I/O .
8655 vha
->marker_needed
= 1;
8658 ha
->isp_ops
->enable_intrs(ha
);
8660 ha
->isp_abort_cnt
= 0;
8661 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
8663 /* Update the firmware version */
8664 status
= qla82xx_check_md_needed(vha
);
8667 ha
->flags
.fce_enabled
= 1;
8669 fce_calc_size(ha
->fce_bufs
));
8670 rval
= qla2x00_enable_fce_trace(vha
,
8671 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
8674 ql_log(ql_log_warn
, vha
, 0x8001,
8675 "Unable to reinitialize FCE (%d).\n",
8677 ha
->flags
.fce_enabled
= 0;
8682 memset(ha
->eft
, 0, EFT_SIZE
);
8683 rval
= qla2x00_enable_eft_trace(vha
,
8684 ha
->eft_dma
, EFT_NUM_BUFFERS
);
8686 ql_log(ql_log_warn
, vha
, 0x8010,
8687 "Unable to reinitialize EFT (%d).\n",
8694 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
8695 "qla82xx_restart_isp succeeded.\n");
8697 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8698 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
8700 atomic_inc(&vp
->vref_count
);
8701 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8703 qla2x00_vp_abort_isp(vp
);
8705 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8706 atomic_dec(&vp
->vref_count
);
8709 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8712 ql_log(ql_log_warn
, vha
, 0x8016,
8713 "qla82xx_restart_isp **** FAILED ****.\n");
8720 * qla24xx_get_fcp_prio
8721 * Gets the fcp cmd priority value for the logged in port.
8722 * Looks for a match of the port descriptors within
8723 * each of the fcp prio config entries. If a match is found,
8724 * the tag (priority) value is returned.
8727 * vha = scsi host structure pointer.
8728 * fcport = port structure pointer.
8731 * non-zero (if found)
8738 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8741 uint8_t pid_match
, wwn_match
;
8743 uint32_t pid1
, pid2
;
8744 uint64_t wwn1
, wwn2
;
8745 struct qla_fcp_prio_entry
*pri_entry
;
8746 struct qla_hw_data
*ha
= vha
->hw
;
8748 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
8752 entries
= ha
->fcp_prio_cfg
->num_entries
;
8753 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
8755 for (i
= 0; i
< entries
; i
++) {
8756 pid_match
= wwn_match
= 0;
8758 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
8763 /* check source pid for a match */
8764 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
8765 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
8766 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
8767 if (pid1
== INVALID_PORT_ID
)
8769 else if (pid1
== pid2
)
8773 /* check destination pid for a match */
8774 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
8775 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
8776 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
8777 if (pid1
== INVALID_PORT_ID
)
8779 else if (pid1
== pid2
)
8783 /* check source WWN for a match */
8784 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
8785 wwn1
= wwn_to_u64(vha
->port_name
);
8786 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
8787 if (wwn2
== (uint64_t)-1)
8789 else if (wwn1
== wwn2
)
8793 /* check destination WWN for a match */
8794 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
8795 wwn1
= wwn_to_u64(fcport
->port_name
);
8796 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
8797 if (wwn2
== (uint64_t)-1)
8799 else if (wwn1
== wwn2
)
8803 if (pid_match
== 2 || wwn_match
== 2) {
8804 /* Found a matching entry */
8805 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
8806 priority
= pri_entry
->tag
;
8817 * qla24xx_update_fcport_fcp_prio
8818 * Activates fcp priority for the logged in fc port
8821 * vha = scsi host structure pointer.
8822 * fcp = port structure pointer.
8825 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8831 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8837 if (fcport
->port_type
!= FCT_TARGET
||
8838 fcport
->loop_id
== FC_NO_LOOP_ID
)
8839 return QLA_FUNCTION_FAILED
;
8841 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
8843 return QLA_FUNCTION_FAILED
;
8845 if (IS_P3P_TYPE(vha
->hw
)) {
8846 fcport
->fcp_prio
= priority
& 0xf;
8850 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
8851 if (ret
== QLA_SUCCESS
) {
8852 if (fcport
->fcp_prio
!= priority
)
8853 ql_dbg(ql_dbg_user
, vha
, 0x709e,
8854 "Updated FCP_CMND priority - value=%d loop_id=%d "
8855 "port_id=%02x%02x%02x.\n", priority
,
8856 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
8857 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
8858 fcport
->fcp_prio
= priority
& 0xf;
8860 ql_dbg(ql_dbg_user
, vha
, 0x704f,
8861 "Unable to update FCP_CMND priority - ret=0x%x for "
8862 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
8863 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
8864 fcport
->d_id
.b
.al_pa
);
8869 * qla24xx_update_all_fcp_prio
8870 * Activates fcp priority for all the logged in ports
8873 * ha = adapter block pointer.
8876 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8882 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
8887 ret
= QLA_FUNCTION_FAILED
;
8888 /* We need to set priority for all logged in ports */
8889 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
8890 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);
8895 struct qla_qpair
*qla2xxx_create_qpair(struct scsi_qla_host
*vha
, int qos
,
8896 int vp_idx
, bool startqp
)
8901 struct qla_hw_data
*ha
= vha
->hw
;
8902 uint16_t qpair_id
= 0;
8903 struct qla_qpair
*qpair
= NULL
;
8904 struct qla_msix_entry
*msix
;
8906 if (!(ha
->fw_attributes
& BIT_6
) || !ha
->flags
.msix_enabled
) {
8907 ql_log(ql_log_warn
, vha
, 0x00181,
8908 "FW/Driver is not multi-queue capable.\n");
8912 if (ql2xmqsupport
|| ql2xnvmeenable
) {
8913 qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
8914 if (qpair
== NULL
) {
8915 ql_log(ql_log_warn
, vha
, 0x0182,
8916 "Failed to allocate memory for queue pair.\n");
8920 qpair
->hw
= vha
->hw
;
8922 qpair
->qp_lock_ptr
= &qpair
->qp_lock
;
8923 spin_lock_init(&qpair
->qp_lock
);
8924 qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
8926 /* Assign available que pair id */
8927 mutex_lock(&ha
->mq_lock
);
8928 qpair_id
= find_first_zero_bit(ha
->qpair_qid_map
, ha
->max_qpairs
);
8929 if (ha
->num_qpairs
>= ha
->max_qpairs
) {
8930 mutex_unlock(&ha
->mq_lock
);
8931 ql_log(ql_log_warn
, vha
, 0x0183,
8932 "No resources to create additional q pair.\n");
8936 set_bit(qpair_id
, ha
->qpair_qid_map
);
8937 ha
->queue_pair_map
[qpair_id
] = qpair
;
8938 qpair
->id
= qpair_id
;
8939 qpair
->vp_idx
= vp_idx
;
8940 qpair
->fw_started
= ha
->flags
.fw_started
;
8941 INIT_LIST_HEAD(&qpair
->hints_list
);
8942 qpair
->chip_reset
= ha
->base_qpair
->chip_reset
;
8943 qpair
->enable_class_2
= ha
->base_qpair
->enable_class_2
;
8944 qpair
->enable_explicit_conf
=
8945 ha
->base_qpair
->enable_explicit_conf
;
8947 for (i
= 0; i
< ha
->msix_count
; i
++) {
8948 msix
= &ha
->msix_entries
[i
];
8952 ql_dbg(ql_dbg_multiq
, vha
, 0xc00f,
8953 "Vector %x selected for qpair\n", msix
->vector
);
8957 ql_log(ql_log_warn
, vha
, 0x0184,
8958 "Out of MSI-X vectors!.\n");
8962 qpair
->msix
->in_use
= 1;
8963 list_add_tail(&qpair
->qp_list_elem
, &vha
->qp_list
);
8964 qpair
->pdev
= ha
->pdev
;
8965 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
) || IS_QLA28XX(ha
))
8966 qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
8968 mutex_unlock(&ha
->mq_lock
);
8970 /* Create response queue first */
8971 rsp_id
= qla25xx_create_rsp_que(ha
, 0, 0, 0, qpair
, startqp
);
8973 ql_log(ql_log_warn
, vha
, 0x0185,
8974 "Failed to create response queue.\n");
8978 qpair
->rsp
= ha
->rsp_q_map
[rsp_id
];
8980 /* Create request queue */
8981 req_id
= qla25xx_create_req_que(ha
, 0, vp_idx
, 0, rsp_id
, qos
,
8984 ql_log(ql_log_warn
, vha
, 0x0186,
8985 "Failed to create request queue.\n");
8989 qpair
->req
= ha
->req_q_map
[req_id
];
8990 qpair
->rsp
->req
= qpair
->req
;
8991 qpair
->rsp
->qpair
= qpair
;
8992 /* init qpair to this cpu. Will adjust at run time. */
8993 qla_cpu_update(qpair
, smp_processor_id());
8995 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
8996 if (ha
->fw_attributes
& BIT_4
)
8997 qpair
->difdix_supported
= 1;
9000 qpair
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
9001 if (!qpair
->srb_mempool
) {
9002 ql_log(ql_log_warn
, vha
, 0xd036,
9003 "Failed to create srb mempool for qpair %d\n",
9008 /* Mark as online */
9011 if (!vha
->flags
.qpairs_available
)
9012 vha
->flags
.qpairs_available
= 1;
9014 ql_dbg(ql_dbg_multiq
, vha
, 0xc00d,
9015 "Request/Response queue pair created, id %d\n",
9017 ql_dbg(ql_dbg_init
, vha
, 0x0187,
9018 "Request/Response queue pair created, id %d\n",
9025 qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
9027 mutex_lock(&ha
->mq_lock
);
9028 qpair
->msix
->in_use
= 0;
9029 list_del(&qpair
->qp_list_elem
);
9030 if (list_empty(&vha
->qp_list
))
9031 vha
->flags
.qpairs_available
= 0;
9033 ha
->queue_pair_map
[qpair_id
] = NULL
;
9034 clear_bit(qpair_id
, ha
->qpair_qid_map
);
9036 mutex_unlock(&ha
->mq_lock
);
9042 int qla2xxx_delete_qpair(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
)
9044 int ret
= QLA_FUNCTION_FAILED
;
9045 struct qla_hw_data
*ha
= qpair
->hw
;
9047 qpair
->delete_in_progress
= 1;
9049 ret
= qla25xx_delete_req_que(vha
, qpair
->req
);
9050 if (ret
!= QLA_SUCCESS
)
9053 ret
= qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
9054 if (ret
!= QLA_SUCCESS
)
9057 mutex_lock(&ha
->mq_lock
);
9058 ha
->queue_pair_map
[qpair
->id
] = NULL
;
9059 clear_bit(qpair
->id
, ha
->qpair_qid_map
);
9061 list_del(&qpair
->qp_list_elem
);
9062 if (list_empty(&vha
->qp_list
)) {
9063 vha
->flags
.qpairs_available
= 0;
9064 vha
->flags
.qpairs_req_created
= 0;
9065 vha
->flags
.qpairs_rsp_created
= 0;
9067 mempool_destroy(qpair
->srb_mempool
);
9069 mutex_unlock(&ha
->mq_lock
);