2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
20 #include <target/target_core_base.h>
21 #include "qla_target.h"
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t
*);
27 static int qla2x00_setup_chip(scsi_qla_host_t
*);
28 static int qla2x00_fw_ready(scsi_qla_host_t
*);
29 static int qla2x00_configure_hba(scsi_qla_host_t
*);
30 static int qla2x00_configure_loop(scsi_qla_host_t
*);
31 static int qla2x00_configure_local_loop(scsi_qla_host_t
*);
32 static int qla2x00_configure_fabric(scsi_qla_host_t
*);
33 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t
*);
34 static int qla2x00_restart_isp(scsi_qla_host_t
*);
36 static struct qla_chip_state_84xx
*qla84xx_get_chip(struct scsi_qla_host
*);
37 static int qla84xx_init_chip(scsi_qla_host_t
*);
38 static int qla25xx_init_queues(struct qla_hw_data
*);
39 static int qla24xx_post_prli_work(struct scsi_qla_host
*, fc_port_t
*);
40 static void qla24xx_handle_plogi_done_event(struct scsi_qla_host
*,
42 static void qla24xx_handle_prli_done_event(struct scsi_qla_host
*,
44 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*, struct event_arg
*);
46 /* SRB Extensions ---------------------------------------------------------- */
49 qla2x00_sp_timeout(struct timer_list
*t
)
51 srb_t
*sp
= from_timer(sp
, t
, u
.iocb_cmd
.timer
);
52 struct srb_iocb
*iocb
;
53 scsi_qla_host_t
*vha
= sp
->vha
;
57 spin_lock_irqsave(&vha
->hw
->hardware_lock
, flags
);
58 req
= vha
->hw
->req_q_map
[0];
59 req
->outstanding_cmds
[sp
->handle
] = NULL
;
60 iocb
= &sp
->u
.iocb_cmd
;
62 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
66 qla2x00_sp_free(void *ptr
)
69 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
71 del_timer(&iocb
->timer
);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
78 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
81 struct qla_hw_data
*ha
= vha
->hw
;
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo
= ha
->r_a_tov
/ 10 * 2;
86 tmo
= FX00_DEF_RATOV
* 2;
87 } else if (!IS_FWI2_CAPABLE(ha
)) {
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
92 tmo
= ha
->login_timeout
;
98 qla2x00_async_iocb_timeout(void *data
)
101 fc_port_t
*fcport
= sp
->fcport
;
102 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
105 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
106 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
107 sp
->name
, sp
->handle
, fcport
->d_id
.b24
, fcport
->port_name
);
109 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
111 pr_info("Async-%s timeout - hdl=%x.\n",
112 sp
->name
, sp
->handle
);
117 /* Retry as needed. */
118 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
119 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
120 QLA_LOGIO_LOGIN_RETRIED
: 0;
121 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
124 case SRB_CT_PTHRU_CMD
:
130 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
136 qla2x00_async_login_sp_done(void *ptr
, int res
)
139 struct scsi_qla_host
*vha
= sp
->vha
;
140 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
143 ql_dbg(ql_dbg_disc
, vha
, 0x20dd,
144 "%s %8phC res %d \n", __func__
, sp
->fcport
->port_name
, res
);
146 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
148 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
149 memset(&ea
, 0, sizeof(ea
));
150 ea
.event
= FCME_PLOGI_DONE
;
151 ea
.fcport
= sp
->fcport
;
152 ea
.data
[0] = lio
->u
.logio
.data
[0];
153 ea
.data
[1] = lio
->u
.logio
.data
[1];
154 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
155 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
157 qla2x00_fcport_event_handler(vha
, &ea
);
164 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
168 struct srb_iocb
*lio
;
169 int rval
= QLA_FUNCTION_FAILED
;
171 if (!vha
->flags
.online
)
174 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
178 fcport
->flags
|= FCF_ASYNC_SENT
;
179 fcport
->logout_completed
= 0;
181 fcport
->disc_state
= DSC_LOGIN_PEND
;
182 sp
->type
= SRB_LOGIN_CMD
;
184 sp
->gen1
= fcport
->rscn_gen
;
185 sp
->gen2
= fcport
->login_gen
;
186 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
188 lio
= &sp
->u
.iocb_cmd
;
189 lio
->timeout
= qla2x00_async_iocb_timeout
;
190 sp
->done
= qla2x00_async_login_sp_done
;
191 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
193 if (fcport
->fc4f_nvme
)
194 lio
->u
.logio
.flags
|= SRB_LOGIN_SKIP_PRLI
;
196 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
197 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
198 rval
= qla2x00_start_sp(sp
);
199 if (rval
!= QLA_SUCCESS
) {
200 fcport
->flags
|= FCF_LOGIN_NEEDED
;
201 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
205 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
206 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
207 "retries=%d.\n", fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
208 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
209 fcport
->login_retry
);
214 fcport
->flags
&= ~FCF_ASYNC_SENT
;
220 qla2x00_async_logout_sp_done(void *ptr
, int res
)
224 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
225 sp
->fcport
->login_gen
++;
226 qlt_logo_completion_handler(sp
->fcport
, res
);
231 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
234 struct srb_iocb
*lio
;
235 int rval
= QLA_FUNCTION_FAILED
;
237 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
240 fcport
->flags
|= FCF_ASYNC_SENT
;
241 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
245 sp
->type
= SRB_LOGOUT_CMD
;
247 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
249 lio
= &sp
->u
.iocb_cmd
;
250 lio
->timeout
= qla2x00_async_iocb_timeout
;
251 sp
->done
= qla2x00_async_logout_sp_done
;
252 rval
= qla2x00_start_sp(sp
);
253 if (rval
!= QLA_SUCCESS
)
256 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
257 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
258 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
259 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
266 fcport
->flags
&= ~FCF_ASYNC_SENT
;
271 qla2x00_async_prlo_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
274 /* Don't re-login in target mode */
275 if (!fcport
->tgt_session
)
276 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
277 qlt_logo_completion_handler(fcport
, data
[0]);
281 qla2x00_async_prlo_sp_done(void *s
, int res
)
283 srb_t
*sp
= (srb_t
*)s
;
284 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
285 struct scsi_qla_host
*vha
= sp
->vha
;
287 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
288 qla2x00_post_async_prlo_done_work(sp
->fcport
->vha
, sp
->fcport
,
294 qla2x00_async_prlo(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
297 struct srb_iocb
*lio
;
300 rval
= QLA_FUNCTION_FAILED
;
301 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
305 sp
->type
= SRB_PRLO_CMD
;
307 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
309 lio
= &sp
->u
.iocb_cmd
;
310 lio
->timeout
= qla2x00_async_iocb_timeout
;
311 sp
->done
= qla2x00_async_prlo_sp_done
;
312 rval
= qla2x00_start_sp(sp
);
313 if (rval
!= QLA_SUCCESS
)
316 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
317 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
318 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
319 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
329 void qla24xx_handle_adisc_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
331 struct fc_port
*fcport
= ea
->fcport
;
333 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
334 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
335 __func__
, fcport
->port_name
, fcport
->disc_state
,
336 fcport
->fw_login_state
, ea
->rc
, fcport
->login_gen
, ea
->sp
->gen2
,
337 fcport
->rscn_gen
, ea
->sp
->gen1
, fcport
->loop_id
);
339 if (ea
->data
[0] != MBS_COMMAND_COMPLETE
) {
340 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
341 "%s %8phC: adisc fail: post delete\n",
342 __func__
, ea
->fcport
->port_name
);
343 qlt_schedule_sess_for_deletion(ea
->fcport
);
347 if (ea
->fcport
->disc_state
== DSC_DELETE_PEND
)
350 if (ea
->sp
->gen2
!= ea
->fcport
->login_gen
) {
351 /* target side must have changed it. */
352 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
353 "%s %8phC generation changed\n",
354 __func__
, ea
->fcport
->port_name
);
356 } else if (ea
->sp
->gen1
!= ea
->fcport
->rscn_gen
) {
357 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
358 __func__
, __LINE__
, ea
->fcport
->port_name
);
359 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
363 __qla24xx_handle_gpdb_event(vha
, ea
);
367 qla2x00_async_adisc_sp_done(void *ptr
, int res
)
370 struct scsi_qla_host
*vha
= sp
->vha
;
372 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
374 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
375 "Async done-%s res %x %8phC\n",
376 sp
->name
, res
, sp
->fcport
->port_name
);
378 memset(&ea
, 0, sizeof(ea
));
379 ea
.event
= FCME_ADISC_DONE
;
381 ea
.data
[0] = lio
->u
.logio
.data
[0];
382 ea
.data
[1] = lio
->u
.logio
.data
[1];
383 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
384 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
385 ea
.fcport
= sp
->fcport
;
388 qla2x00_fcport_event_handler(vha
, &ea
);
394 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
398 struct srb_iocb
*lio
;
401 rval
= QLA_FUNCTION_FAILED
;
402 fcport
->flags
|= FCF_ASYNC_SENT
;
403 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
407 sp
->type
= SRB_ADISC_CMD
;
409 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
411 lio
= &sp
->u
.iocb_cmd
;
412 lio
->timeout
= qla2x00_async_iocb_timeout
;
413 sp
->done
= qla2x00_async_adisc_sp_done
;
414 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
415 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
416 rval
= qla2x00_start_sp(sp
);
417 if (rval
!= QLA_SUCCESS
)
420 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
421 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
422 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
, fcport
->port_name
);
428 fcport
->flags
&= ~FCF_ASYNC_SENT
;
429 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
433 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t
*vha
,
434 struct event_arg
*ea
)
436 fc_port_t
*fcport
, *conflict_fcport
;
437 struct get_name_list_extended
*e
;
438 u16 i
, n
, found
= 0, loop_id
;
442 u8 current_login_state
;
445 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
446 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
447 __func__
, fcport
->port_name
, fcport
->disc_state
,
448 fcport
->fw_login_state
, ea
->rc
,
449 fcport
->login_gen
, fcport
->last_login_gen
,
450 fcport
->rscn_gen
, fcport
->last_rscn_gen
, vha
->loop_id
);
452 if (fcport
->disc_state
== DSC_DELETE_PEND
)
455 if (ea
->rc
) { /* rval */
456 if (fcport
->login_retry
== 0) {
457 fcport
->login_retry
= vha
->hw
->login_retry_count
;
458 ql_dbg(ql_dbg_disc
, vha
, 0x20de,
459 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
460 fcport
->port_name
, fcport
->login_retry
);
465 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
466 ql_dbg(ql_dbg_disc
, vha
, 0x20df,
467 "%s %8phC rscn gen changed rscn %d|%d \n",
468 __func__
, fcport
->port_name
,
469 fcport
->last_rscn_gen
, fcport
->rscn_gen
);
470 qla24xx_post_gidpn_work(vha
, fcport
);
472 } else if (fcport
->last_login_gen
!= fcport
->login_gen
) {
473 ql_dbg(ql_dbg_disc
, vha
, 0x20e0,
474 "%s %8phC login gen changed\n",
475 __func__
, fcport
->port_name
);
479 n
= ea
->data
[0] / sizeof(struct get_name_list_extended
);
481 ql_dbg(ql_dbg_disc
, vha
, 0x20e1,
482 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
483 __func__
, __LINE__
, fcport
->port_name
, n
,
484 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
485 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
);
487 for (i
= 0; i
< n
; i
++) {
489 wwn
= wwn_to_u64(e
->port_name
);
491 if (memcmp((u8
*)&wwn
, fcport
->port_name
, WWN_SIZE
))
495 id
.b
.domain
= e
->port_id
[2];
496 id
.b
.area
= e
->port_id
[1];
497 id
.b
.al_pa
= e
->port_id
[0];
500 loop_id
= le16_to_cpu(e
->nport_handle
);
501 loop_id
= (loop_id
& 0x7fff);
503 ql_dbg(ql_dbg_disc
, vha
, 0x20e2,
504 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
505 __func__
, fcport
->port_name
,
506 e
->current_login_state
, fcport
->fw_login_state
,
507 id
.b
.domain
, id
.b
.area
, id
.b
.al_pa
,
508 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
509 fcport
->d_id
.b
.al_pa
, loop_id
, fcport
->loop_id
);
511 if ((id
.b24
!= fcport
->d_id
.b24
) ||
512 ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
513 (fcport
->loop_id
!= loop_id
))) {
514 ql_dbg(ql_dbg_disc
, vha
, 0x20e3,
515 "%s %d %8phC post del sess\n",
516 __func__
, __LINE__
, fcport
->port_name
);
517 qlt_schedule_sess_for_deletion(fcport
);
521 fcport
->loop_id
= loop_id
;
523 wwn
= wwn_to_u64(fcport
->port_name
);
524 qlt_find_sess_invalidate_other(vha
, wwn
,
525 id
, loop_id
, &conflict_fcport
);
527 if (conflict_fcport
) {
529 * Another share fcport share the same loop_id &
530 * nport id. Conflict fcport needs to finish
531 * cleanup before this fcport can proceed to login.
533 conflict_fcport
->conflict
= fcport
;
534 fcport
->login_pause
= 1;
537 if (fcport
->fc4f_nvme
)
538 current_login_state
= e
->current_login_state
>> 4;
540 current_login_state
= e
->current_login_state
& 0xf;
542 switch (current_login_state
) {
543 case DSC_LS_PRLI_COMP
:
544 ql_dbg(ql_dbg_disc
, vha
, 0x20e4,
545 "%s %d %8phC post gpdb\n",
546 __func__
, __LINE__
, fcport
->port_name
);
548 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
549 fcport
->port_type
= FCT_INITIATOR
;
551 fcport
->port_type
= FCT_TARGET
;
553 data
[0] = data
[1] = 0;
554 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
556 case DSC_LS_PORT_UNAVAIL
:
558 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
559 qla2x00_find_new_loop_id(vha
, fcport
);
560 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
562 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
564 __func__
, __LINE__
, fcport
->port_name
);
565 qla24xx_fcport_handle_login(vha
, fcport
);
571 /* fw has no record of this port */
572 for (i
= 0; i
< n
; i
++) {
574 id
.b
.domain
= e
->port_id
[0];
575 id
.b
.area
= e
->port_id
[1];
576 id
.b
.al_pa
= e
->port_id
[2];
578 loop_id
= le16_to_cpu(e
->nport_handle
);
580 if (fcport
->d_id
.b24
== id
.b24
) {
582 qla2x00_find_fcport_by_wwpn(vha
,
584 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
585 "%s %d %8phC post del sess\n",
587 conflict_fcport
->port_name
);
588 qlt_schedule_sess_for_deletion
592 /* FW already picked this loop id for another fcport */
593 if (fcport
->loop_id
== loop_id
)
594 fcport
->loop_id
= FC_NO_LOOP_ID
;
596 qla24xx_fcport_handle_login(vha
, fcport
);
601 qla24xx_async_gnl_sp_done(void *s
, int res
)
604 struct scsi_qla_host
*vha
= sp
->vha
;
606 struct fc_port
*fcport
= NULL
, *tf
;
607 u16 i
, n
= 0, loop_id
;
609 struct get_name_list_extended
*e
;
614 ql_dbg(ql_dbg_disc
, vha
, 0x20e7,
615 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
616 sp
->name
, res
, sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1],
617 sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[2]);
619 memset(&ea
, 0, sizeof(ea
));
622 ea
.event
= FCME_GNL_DONE
;
624 if (sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] >=
625 sizeof(struct get_name_list_extended
)) {
626 n
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] /
627 sizeof(struct get_name_list_extended
);
628 ea
.data
[0] = sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1]; /* amnt xfered */
631 for (i
= 0; i
< n
; i
++) {
633 loop_id
= le16_to_cpu(e
->nport_handle
);
634 /* mask out reserve bit */
635 loop_id
= (loop_id
& 0x7fff);
636 set_bit(loop_id
, vha
->hw
->loop_id_map
);
637 wwn
= wwn_to_u64(e
->port_name
);
639 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0x20e8,
640 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
641 __func__
, (void *)&wwn
, e
->port_id
[2], e
->port_id
[1],
642 e
->port_id
[0], e
->current_login_state
, e
->last_login_state
,
646 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
651 if (!list_empty(&vha
->gnl
.fcports
))
652 list_splice_init(&vha
->gnl
.fcports
, &h
);
654 list_for_each_entry_safe(fcport
, tf
, &h
, gnl_entry
) {
655 list_del_init(&fcport
->gnl_entry
);
656 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
659 qla2x00_fcport_event_handler(vha
, &ea
);
662 /* create new fcport if fw has knowledge of new sessions */
663 for (i
= 0; i
< n
; i
++) {
668 wwn
= wwn_to_u64(e
->port_name
);
671 list_for_each_entry_safe(fcport
, tf
, &vha
->vp_fcports
, list
) {
672 if (!memcmp((u8
*)&wwn
, fcport
->port_name
,
679 id
.b
.domain
= e
->port_id
[2];
680 id
.b
.area
= e
->port_id
[1];
681 id
.b
.al_pa
= e
->port_id
[0];
684 if (!found
&& wwn
&& !IS_SW_RESV_ADDR(id
)) {
685 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
686 "%s %d %8phC %06x post new sess\n",
687 __func__
, __LINE__
, (u8
*)&wwn
, id
.b24
);
688 wwnn
= wwn_to_u64(e
->node_name
);
689 qla24xx_post_newsess_work(vha
, &id
, (u8
*)&wwn
,
690 (u8
*)&wwnn
, NULL
, FC4_TYPE_UNKNOWN
);
694 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
699 int qla24xx_async_gnl(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
702 struct srb_iocb
*mbx
;
703 int rval
= QLA_FUNCTION_FAILED
;
707 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
710 ql_dbg(ql_dbg_disc
, vha
, 0x20d9,
711 "Async-gnlist WWPN %8phC \n", fcport
->port_name
);
713 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
714 fcport
->disc_state
= DSC_GNL
;
715 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
716 fcport
->last_login_gen
= fcport
->login_gen
;
718 list_add_tail(&fcport
->gnl_entry
, &vha
->gnl
.fcports
);
720 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
724 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
726 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
730 fcport
->flags
|= FCF_ASYNC_SENT
;
731 sp
->type
= SRB_MB_IOCB
;
733 sp
->gen1
= fcport
->rscn_gen
;
734 sp
->gen2
= fcport
->login_gen
;
736 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
738 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
739 mb
[0] = MBC_PORT_NODE_NAME_LIST
;
740 mb
[1] = BIT_2
| BIT_3
;
741 mb
[2] = MSW(vha
->gnl
.ldma
);
742 mb
[3] = LSW(vha
->gnl
.ldma
);
743 mb
[6] = MSW(MSD(vha
->gnl
.ldma
));
744 mb
[7] = LSW(MSD(vha
->gnl
.ldma
));
745 mb
[8] = vha
->gnl
.size
;
748 mbx
= &sp
->u
.iocb_cmd
;
749 mbx
->timeout
= qla2x00_async_iocb_timeout
;
751 sp
->done
= qla24xx_async_gnl_sp_done
;
753 rval
= qla2x00_start_sp(sp
);
754 if (rval
!= QLA_SUCCESS
)
757 ql_dbg(ql_dbg_disc
, vha
, 0x20da,
758 "Async-%s - OUT WWPN %8phC hndl %x\n",
759 sp
->name
, fcport
->port_name
, sp
->handle
);
765 fcport
->flags
&= ~FCF_ASYNC_SENT
;
770 int qla24xx_post_gnl_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
772 struct qla_work_evt
*e
;
774 e
= qla2x00_alloc_work(vha
, QLA_EVT_GNL
);
776 return QLA_FUNCTION_FAILED
;
778 e
->u
.fcport
.fcport
= fcport
;
779 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
780 return qla2x00_post_work(vha
, e
);
784 void qla24xx_async_gpdb_sp_done(void *s
, int res
)
787 struct scsi_qla_host
*vha
= sp
->vha
;
788 struct qla_hw_data
*ha
= vha
->hw
;
789 fc_port_t
*fcport
= sp
->fcport
;
790 u16
*mb
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
;
793 ql_dbg(ql_dbg_disc
, vha
, 0x20db,
794 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
795 sp
->name
, res
, fcport
->port_name
, mb
[1], mb
[2]);
797 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
799 memset(&ea
, 0, sizeof(ea
));
800 ea
.event
= FCME_GPDB_DONE
;
804 qla2x00_fcport_event_handler(vha
, &ea
);
806 dma_pool_free(ha
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
807 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
812 static int qla24xx_post_prli_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
814 struct qla_work_evt
*e
;
816 e
= qla2x00_alloc_work(vha
, QLA_EVT_PRLI
);
818 return QLA_FUNCTION_FAILED
;
820 e
->u
.fcport
.fcport
= fcport
;
822 return qla2x00_post_work(vha
, e
);
826 qla2x00_async_prli_sp_done(void *ptr
, int res
)
829 struct scsi_qla_host
*vha
= sp
->vha
;
830 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
833 ql_dbg(ql_dbg_disc
, vha
, 0x2129,
834 "%s %8phC res %d \n", __func__
,
835 sp
->fcport
->port_name
, res
);
837 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
839 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
840 memset(&ea
, 0, sizeof(ea
));
841 ea
.event
= FCME_PRLI_DONE
;
842 ea
.fcport
= sp
->fcport
;
843 ea
.data
[0] = lio
->u
.logio
.data
[0];
844 ea
.data
[1] = lio
->u
.logio
.data
[1];
845 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
846 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
849 qla2x00_fcport_event_handler(vha
, &ea
);
856 qla24xx_async_prli(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
859 struct srb_iocb
*lio
;
860 int rval
= QLA_FUNCTION_FAILED
;
862 if (!vha
->flags
.online
)
865 if (fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
||
866 fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
||
867 fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)
870 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
874 fcport
->flags
|= FCF_ASYNC_SENT
;
875 fcport
->logout_completed
= 0;
877 sp
->type
= SRB_PRLI_CMD
;
879 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
881 lio
= &sp
->u
.iocb_cmd
;
882 lio
->timeout
= qla2x00_async_iocb_timeout
;
883 sp
->done
= qla2x00_async_prli_sp_done
;
884 lio
->u
.logio
.flags
= 0;
886 if (fcport
->fc4f_nvme
)
887 lio
->u
.logio
.flags
|= SRB_LOGIN_NVME_PRLI
;
889 rval
= qla2x00_start_sp(sp
);
890 if (rval
!= QLA_SUCCESS
) {
891 fcport
->flags
|= FCF_LOGIN_NEEDED
;
892 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
896 ql_dbg(ql_dbg_disc
, vha
, 0x211b,
897 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
898 fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
899 fcport
->d_id
.b24
, fcport
->login_retry
);
905 fcport
->flags
&= ~FCF_ASYNC_SENT
;
909 int qla24xx_post_gpdb_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
911 struct qla_work_evt
*e
;
913 e
= qla2x00_alloc_work(vha
, QLA_EVT_GPDB
);
915 return QLA_FUNCTION_FAILED
;
917 e
->u
.fcport
.fcport
= fcport
;
918 e
->u
.fcport
.opt
= opt
;
919 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
920 return qla2x00_post_work(vha
, e
);
923 int qla24xx_async_gpdb(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
926 struct srb_iocb
*mbx
;
927 int rval
= QLA_FUNCTION_FAILED
;
930 struct port_database_24xx
*pd
;
931 struct qla_hw_data
*ha
= vha
->hw
;
933 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
936 fcport
->disc_state
= DSC_GPDB
;
938 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
942 fcport
->flags
|= FCF_ASYNC_SENT
;
943 sp
->type
= SRB_MB_IOCB
;
945 sp
->gen1
= fcport
->rscn_gen
;
946 sp
->gen2
= fcport
->login_gen
;
947 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
949 pd
= dma_pool_zalloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
951 ql_log(ql_log_warn
, vha
, 0xd043,
952 "Failed to allocate port database structure.\n");
956 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
957 mb
[0] = MBC_GET_PORT_DATABASE
;
958 mb
[1] = fcport
->loop_id
;
961 mb
[6] = MSW(MSD(pd_dma
));
962 mb
[7] = LSW(MSD(pd_dma
));
966 mbx
= &sp
->u
.iocb_cmd
;
967 mbx
->timeout
= qla2x00_async_iocb_timeout
;
968 mbx
->u
.mbx
.in
= (void *)pd
;
969 mbx
->u
.mbx
.in_dma
= pd_dma
;
971 sp
->done
= qla24xx_async_gpdb_sp_done
;
973 rval
= qla2x00_start_sp(sp
);
974 if (rval
!= QLA_SUCCESS
)
977 ql_dbg(ql_dbg_disc
, vha
, 0x20dc,
978 "Async-%s %8phC hndl %x opt %x\n",
979 sp
->name
, fcport
->port_name
, sp
->handle
, opt
);
985 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
988 fcport
->flags
&= ~FCF_ASYNC_SENT
;
990 qla24xx_post_gpdb_work(vha
, fcport
, opt
);
995 void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
999 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1000 ea
->fcport
->login_gen
++;
1001 ea
->fcport
->deleted
= 0;
1002 ea
->fcport
->logout_on_delete
= 1;
1004 if (!ea
->fcport
->login_succ
&& !IS_SW_RESV_ADDR(ea
->fcport
->d_id
)) {
1005 vha
->fcport_count
++;
1006 ea
->fcport
->login_succ
= 1;
1008 if (!IS_IIDMA_CAPABLE(vha
->hw
) ||
1009 !vha
->hw
->flags
.gpsc_supported
) {
1010 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1011 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1012 __func__
, __LINE__
, ea
->fcport
->port_name
,
1015 qla24xx_post_upd_fcport_work(vha
, ea
->fcport
);
1017 if (ea
->fcport
->id_changed
) {
1018 ea
->fcport
->id_changed
= 0;
1019 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
1020 "%s %d %8phC post gfpnid fcp_cnt %d\n",
1021 __func__
, __LINE__
, ea
->fcport
->port_name
,
1023 qla24xx_post_gfpnid_work(vha
, ea
->fcport
);
1025 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
1026 "%s %d %8phC post gpsc fcp_cnt %d\n",
1027 __func__
, __LINE__
, ea
->fcport
->port_name
,
1029 qla24xx_post_gpsc_work(vha
, ea
->fcport
);
1032 } else if (ea
->fcport
->login_succ
) {
1034 * We have an existing session. A late RSCN delivery
1035 * must have triggered the session to be re-validate.
1036 * Session is still valid.
1038 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1039 "%s %d %8phC session revalidate success\n",
1040 __func__
, __LINE__
, ea
->fcport
->port_name
);
1041 ea
->fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
1043 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1047 void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1049 fc_port_t
*fcport
= ea
->fcport
;
1050 struct port_database_24xx
*pd
;
1051 struct srb
*sp
= ea
->sp
;
1053 pd
= (struct port_database_24xx
*)sp
->u
.iocb_cmd
.u
.mbx
.in
;
1055 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1057 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
1058 "%s %8phC DS %d LS %d rc %d\n", __func__
, fcport
->port_name
,
1059 fcport
->disc_state
, pd
->current_login_state
, ea
->rc
);
1061 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1064 switch (pd
->current_login_state
) {
1065 case PDS_PRLI_COMPLETE
:
1066 __qla24xx_parse_gpdb(vha
, fcport
, pd
);
1068 case PDS_PLOGI_PENDING
:
1069 case PDS_PLOGI_COMPLETE
:
1070 case PDS_PRLI_PENDING
:
1071 case PDS_PRLI2_PENDING
:
1072 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC relogin needed\n",
1073 __func__
, __LINE__
, fcport
->port_name
);
1074 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1076 case PDS_LOGO_PENDING
:
1077 case PDS_PORT_UNAVAILABLE
:
1079 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC post del sess\n",
1080 __func__
, __LINE__
, fcport
->port_name
);
1081 qlt_schedule_sess_for_deletion(fcport
);
1084 __qla24xx_handle_gpdb_event(vha
, ea
);
1087 static void qla_chk_n2n_b4_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1092 if (qla_tgt_mode_enabled(vha
))
1095 if (qla_dual_mode_enabled(vha
)) {
1096 if (N2N_TOPO(vha
->hw
)) {
1099 mywwn
= wwn_to_u64(vha
->port_name
);
1100 wwn
= wwn_to_u64(fcport
->port_name
);
1103 else if ((fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1104 && time_after_eq(jiffies
,
1105 fcport
->plogi_nack_done_deadline
))
1111 /* initiator mode */
1116 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1117 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1118 rc
= qla2x00_find_new_loop_id(vha
, fcport
);
1120 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
1121 "%s %d %8phC post del sess - out of loopid\n",
1122 __func__
, __LINE__
, fcport
->port_name
);
1123 fcport
->scan_state
= 0;
1124 qlt_schedule_sess_for_deletion(fcport
);
1128 ql_dbg(ql_dbg_disc
, vha
, 0x20bf,
1129 "%s %d %8phC post login\n",
1130 __func__
, __LINE__
, fcport
->port_name
);
1131 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
1135 int qla24xx_fcport_handle_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1140 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1141 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
1142 __func__
, fcport
->port_name
, fcport
->disc_state
,
1143 fcport
->fw_login_state
, fcport
->login_pause
, fcport
->flags
,
1144 fcport
->conflict
, fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1145 fcport
->login_gen
, fcport
->login_retry
,
1146 fcport
->loop_id
, fcport
->scan_state
);
1148 if (fcport
->login_retry
== 0)
1151 if (fcport
->scan_state
!= QLA_FCPORT_FOUND
)
1154 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1155 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1158 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1159 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1160 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1165 /* for pure Target Mode. Login will not be initiated */
1166 if (vha
->host
->active_mode
== MODE_TARGET
)
1169 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1170 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1174 fcport
->login_retry
--;
1176 switch (fcport
->disc_state
) {
1178 wwn
= wwn_to_u64(fcport
->node_name
);
1180 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1181 "%s %d %8phC post GNNID\n",
1182 __func__
, __LINE__
, fcport
->port_name
);
1183 qla24xx_post_gnnid_work(vha
, fcport
);
1184 } else if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1185 ql_dbg(ql_dbg_disc
, vha
, 0x20bd,
1186 "%s %d %8phC post gnl\n",
1187 __func__
, __LINE__
, fcport
->port_name
);
1188 qla24xx_post_gnl_work(vha
, fcport
);
1190 qla_chk_n2n_b4_login(vha
, fcport
);
1195 if (fcport
->login_pause
) {
1196 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1197 fcport
->last_login_gen
= fcport
->login_gen
;
1198 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1202 qla_chk_n2n_b4_login(vha
, fcport
);
1205 case DSC_LOGIN_FAILED
:
1206 ql_dbg(ql_dbg_disc
, vha
, 0x20d0,
1207 "%s %d %8phC post gidpn\n",
1208 __func__
, __LINE__
, fcport
->port_name
);
1209 if (N2N_TOPO(vha
->hw
))
1210 qla_chk_n2n_b4_login(vha
, fcport
);
1212 qla24xx_post_gidpn_work(vha
, fcport
);
1215 case DSC_LOGIN_COMPLETE
:
1216 /* recheck login state */
1217 ql_dbg(ql_dbg_disc
, vha
, 0x20d1,
1218 "%s %d %8phC post adisc\n",
1219 __func__
, __LINE__
, fcport
->port_name
);
1220 data
[0] = data
[1] = 0;
1221 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
1232 void qla24xx_handle_rscn_event(fc_port_t
*fcport
, struct event_arg
*ea
)
1236 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210c,
1237 "%s %8phC DS %d LS %d\n",
1238 __func__
, fcport
->port_name
, fcport
->disc_state
,
1239 fcport
->fw_login_state
);
1241 if (fcport
->flags
& FCF_ASYNC_SENT
)
1244 switch (fcport
->disc_state
) {
1246 case DSC_LOGIN_COMPLETE
:
1247 qla24xx_post_gpnid_work(fcport
->vha
, &ea
->id
);
1254 int qla24xx_post_newsess_work(struct scsi_qla_host
*vha
, port_id_t
*id
,
1255 u8
*port_name
, u8
*node_name
, void *pla
, u8 fc4_type
)
1257 struct qla_work_evt
*e
;
1258 e
= qla2x00_alloc_work(vha
, QLA_EVT_NEW_SESS
);
1260 return QLA_FUNCTION_FAILED
;
1262 e
->u
.new_sess
.id
= *id
;
1263 e
->u
.new_sess
.pla
= pla
;
1264 e
->u
.new_sess
.fc4_type
= fc4_type
;
1265 memcpy(e
->u
.new_sess
.port_name
, port_name
, WWN_SIZE
);
1267 memcpy(e
->u
.new_sess
.node_name
, node_name
, WWN_SIZE
);
1269 return qla2x00_post_work(vha
, e
);
1273 void qla24xx_handle_relogin_event(scsi_qla_host_t
*vha
,
1274 struct event_arg
*ea
)
1276 fc_port_t
*fcport
= ea
->fcport
;
1278 ql_dbg(ql_dbg_disc
, vha
, 0x2102,
1279 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1280 __func__
, fcport
->port_name
, fcport
->disc_state
,
1281 fcport
->fw_login_state
, fcport
->login_pause
,
1282 fcport
->deleted
, fcport
->conflict
,
1283 fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1284 fcport
->last_login_gen
, fcport
->login_gen
,
1287 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1288 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1291 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1292 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1293 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1298 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1299 fcport
->login_retry
++;
1300 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1304 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
1305 fcport
->login_retry
++;
1309 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
1310 ql_dbg(ql_dbg_disc
, vha
, 0x20e9, "%s %d %8phC post gidpn\n",
1311 __func__
, __LINE__
, fcport
->port_name
);
1313 qla24xx_post_gidpn_work(vha
, fcport
);
1317 qla24xx_fcport_handle_login(vha
, fcport
);
1320 void qla2x00_fcport_event_handler(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1323 uint32_t id
= 0, mask
, rid
;
1324 unsigned long flags
;
1326 switch (ea
->event
) {
1328 case FCME_GIDPN_DONE
:
1329 case FCME_GPSC_DONE
:
1330 case FCME_GPNID_DONE
:
1331 case FCME_GNNID_DONE
:
1332 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
1333 test_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))
1340 switch (ea
->event
) {
1342 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1345 qla24xx_handle_relogin_event(vha
, ea
);
1348 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1350 switch (ea
->id
.b
.rsvd_1
) {
1351 case RSCN_PORT_ADDR
:
1352 spin_lock_irqsave(&vha
->work_lock
, flags
);
1353 if (vha
->scan
.scan_flags
== 0) {
1354 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1355 "%s: schedule\n", __func__
);
1356 vha
->scan
.scan_flags
|= SF_QUEUED
;
1357 schedule_delayed_work(&vha
->scan
.scan_work
, 5);
1359 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1362 case RSCN_AREA_ADDR
:
1364 if (ea
->id
.b
.rsvd_1
== RSCN_AREA_ADDR
) {
1366 ql_dbg(ql_dbg_async
, vha
, 0x5044,
1367 "RSCN: Area 0x%06x was affected\n",
1371 ql_dbg(ql_dbg_async
, vha
, 0x507a,
1372 "RSCN: Domain 0x%06x was affected\n",
1376 rid
= ea
->id
.b24
& mask
;
1377 list_for_each_entry_safe(f
, tf
, &vha
->vp_fcports
,
1379 id
= f
->d_id
.b24
& mask
;
1382 qla24xx_handle_rscn_event(f
, ea
);
1388 ql_log(ql_log_warn
, vha
, 0xd045,
1389 "RSCN: Fabric was affected. Addr format %d\n",
1391 qla2x00_mark_all_devices_lost(vha
, 1);
1392 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1393 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1396 case FCME_GIDPN_DONE
:
1397 qla24xx_handle_gidpn_event(vha
, ea
);
1400 qla24xx_handle_gnl_done_event(vha
, ea
);
1402 case FCME_GPSC_DONE
:
1403 qla24xx_handle_gpsc_event(vha
, ea
);
1405 case FCME_PLOGI_DONE
: /* Initiator side sent LLIOCB */
1406 qla24xx_handle_plogi_done_event(vha
, ea
);
1408 case FCME_PRLI_DONE
:
1409 qla24xx_handle_prli_done_event(vha
, ea
);
1411 case FCME_GPDB_DONE
:
1412 qla24xx_handle_gpdb_event(vha
, ea
);
1414 case FCME_GPNID_DONE
:
1415 qla24xx_handle_gpnid_event(vha
, ea
);
1417 case FCME_GFFID_DONE
:
1418 qla24xx_handle_gffid_event(vha
, ea
);
1420 case FCME_ADISC_DONE
:
1421 qla24xx_handle_adisc_event(vha
, ea
);
1423 case FCME_GNNID_DONE
:
1424 qla24xx_handle_gnnid_event(vha
, ea
);
1426 case FCME_GFPNID_DONE
:
1427 qla24xx_handle_gfpnid_event(vha
, ea
);
1436 qla2x00_tmf_iocb_timeout(void *data
)
1439 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1441 tmf
->u
.tmf
.comp_status
= CS_TIMEOUT
;
1442 complete(&tmf
->u
.tmf
.comp
);
1446 qla2x00_tmf_sp_done(void *ptr
, int res
)
1449 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1451 complete(&tmf
->u
.tmf
.comp
);
1455 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
1458 struct scsi_qla_host
*vha
= fcport
->vha
;
1459 struct srb_iocb
*tm_iocb
;
1461 int rval
= QLA_FUNCTION_FAILED
;
1463 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1467 tm_iocb
= &sp
->u
.iocb_cmd
;
1468 sp
->type
= SRB_TM_CMD
;
1470 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1471 tm_iocb
->u
.tmf
.flags
= flags
;
1472 tm_iocb
->u
.tmf
.lun
= lun
;
1473 tm_iocb
->u
.tmf
.data
= tag
;
1474 sp
->done
= qla2x00_tmf_sp_done
;
1475 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
1476 init_completion(&tm_iocb
->u
.tmf
.comp
);
1478 rval
= qla2x00_start_sp(sp
);
1479 if (rval
!= QLA_SUCCESS
)
1482 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
1483 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1484 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1485 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1487 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
1489 rval
= tm_iocb
->u
.tmf
.comp_status
== CS_COMPLETE
?
1490 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1492 if ((rval
!= QLA_SUCCESS
) || tm_iocb
->u
.tmf
.data
) {
1493 ql_dbg(ql_dbg_taskm
, vha
, 0x8030,
1494 "TM IOCB failed (%x).\n", rval
);
1497 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
1498 flags
= tm_iocb
->u
.tmf
.flags
;
1499 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
1501 /* Issue Marker IOCB */
1502 qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
1503 vha
->hw
->rsp_q_map
[0], sp
->fcport
->loop_id
, lun
,
1504 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
1509 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1515 qla24xx_abort_iocb_timeout(void *data
)
1518 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1520 abt
->u
.abt
.comp_status
= CS_TIMEOUT
;
1521 complete(&abt
->u
.abt
.comp
);
1525 qla24xx_abort_sp_done(void *ptr
, int res
)
1528 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1530 complete(&abt
->u
.abt
.comp
);
1534 qla24xx_async_abort_cmd(srb_t
*cmd_sp
)
1536 scsi_qla_host_t
*vha
= cmd_sp
->vha
;
1537 fc_port_t
*fcport
= cmd_sp
->fcport
;
1538 struct srb_iocb
*abt_iocb
;
1540 int rval
= QLA_FUNCTION_FAILED
;
1542 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1546 abt_iocb
= &sp
->u
.iocb_cmd
;
1547 sp
->type
= SRB_ABT_CMD
;
1549 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1550 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
1552 if (vha
->flags
.qpairs_available
&& cmd_sp
->qpair
)
1553 abt_iocb
->u
.abt
.req_que_no
=
1554 cpu_to_le16(cmd_sp
->qpair
->req
->id
);
1556 abt_iocb
->u
.abt
.req_que_no
= cpu_to_le16(vha
->req
->id
);
1558 sp
->done
= qla24xx_abort_sp_done
;
1559 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
1560 init_completion(&abt_iocb
->u
.abt
.comp
);
1562 rval
= qla2x00_start_sp(sp
);
1563 if (rval
!= QLA_SUCCESS
)
1566 ql_dbg(ql_dbg_async
, vha
, 0x507c,
1567 "Abort command issued - hdl=%x, target_id=%x\n",
1568 cmd_sp
->handle
, fcport
->tgt_id
);
1570 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
1572 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
1573 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1582 qla24xx_async_abort_command(srb_t
*sp
)
1584 unsigned long flags
= 0;
1587 fc_port_t
*fcport
= sp
->fcport
;
1588 struct scsi_qla_host
*vha
= fcport
->vha
;
1589 struct qla_hw_data
*ha
= vha
->hw
;
1590 struct req_que
*req
= vha
->req
;
1592 if (vha
->flags
.qpairs_available
&& sp
->qpair
)
1593 req
= sp
->qpair
->req
;
1595 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1596 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
1597 if (req
->outstanding_cmds
[handle
] == sp
)
1600 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1601 if (handle
== req
->num_outstanding_cmds
) {
1602 /* Command not found. */
1603 return QLA_FUNCTION_FAILED
;
1605 if (sp
->type
== SRB_FXIOCB_DCMD
)
1606 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
1607 FXDISC_ABORT_IOCTL
);
1609 return qla24xx_async_abort_cmd(sp
);
1613 qla24xx_handle_prli_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1615 switch (ea
->data
[0]) {
1616 case MBS_COMMAND_COMPLETE
:
1617 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1618 "%s %d %8phC post gpdb\n",
1619 __func__
, __LINE__
, ea
->fcport
->port_name
);
1621 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1622 ea
->fcport
->logout_on_delete
= 1;
1623 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1626 if (ea
->fcport
->n2n_flag
) {
1627 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1628 "%s %d %8phC post fc4 prli\n",
1629 __func__
, __LINE__
, ea
->fcport
->port_name
);
1630 ea
->fcport
->fc4f_nvme
= 0;
1631 ea
->fcport
->n2n_flag
= 0;
1632 qla24xx_post_prli_work(vha
, ea
->fcport
);
1634 ql_dbg(ql_dbg_disc
, vha
, 0x2119,
1635 "%s %d %8phC unhandle event of %x\n",
1636 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[0]);
1642 qla24xx_handle_plogi_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1644 port_id_t cid
; /* conflict Nport id */
1646 struct fc_port
*conflict_fcport
;
1647 unsigned long flags
;
1648 struct fc_port
*fcport
= ea
->fcport
;
1650 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1651 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1652 __func__
, fcport
->port_name
, fcport
->disc_state
,
1653 fcport
->fw_login_state
, ea
->rc
, ea
->sp
->gen2
, fcport
->login_gen
,
1654 ea
->sp
->gen2
, fcport
->rscn_gen
|ea
->sp
->gen1
,
1655 ea
->data
[0], ea
->data
[1], ea
->iop
[0], ea
->iop
[1]);
1657 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1658 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)) {
1659 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1660 "%s %d %8phC Remote is trying to login\n",
1661 __func__
, __LINE__
, fcport
->port_name
);
1665 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1668 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1669 /* target side must have changed it. */
1670 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1671 "%s %8phC generation changed\n",
1672 __func__
, fcport
->port_name
);
1673 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1675 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1676 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
1677 __func__
, __LINE__
, fcport
->port_name
);
1678 qla24xx_post_gidpn_work(vha
, fcport
);
1682 switch (ea
->data
[0]) {
1683 case MBS_COMMAND_COMPLETE
:
1685 * Driver must validate login state - If PRLI not complete,
1686 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1689 if (ea
->fcport
->fc4f_nvme
) {
1690 ql_dbg(ql_dbg_disc
, vha
, 0x2117,
1691 "%s %d %8phC post prli\n",
1692 __func__
, __LINE__
, ea
->fcport
->port_name
);
1693 qla24xx_post_prli_work(vha
, ea
->fcport
);
1695 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1696 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1697 __func__
, __LINE__
, ea
->fcport
->port_name
,
1698 ea
->fcport
->loop_id
, ea
->fcport
->d_id
.b24
);
1700 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1701 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1702 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1703 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1704 ea
->fcport
->logout_on_delete
= 1;
1705 ea
->fcport
->send_els_logo
= 0;
1706 ea
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
1707 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1709 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1712 case MBS_COMMAND_ERROR
:
1713 ql_dbg(ql_dbg_disc
, vha
, 0x20eb, "%s %d %8phC cmd error %x\n",
1714 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[1]);
1716 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1717 ea
->fcport
->disc_state
= DSC_LOGIN_FAILED
;
1718 if (ea
->data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1719 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1721 qla2x00_mark_device_lost(vha
, ea
->fcport
, 1, 0);
1723 case MBS_LOOP_ID_USED
:
1724 /* data[1] = IO PARAM 1 = nport ID */
1725 cid
.b
.domain
= (ea
->iop
[1] >> 16) & 0xff;
1726 cid
.b
.area
= (ea
->iop
[1] >> 8) & 0xff;
1727 cid
.b
.al_pa
= ea
->iop
[1] & 0xff;
1730 ql_dbg(ql_dbg_disc
, vha
, 0x20ec,
1731 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1732 __func__
, __LINE__
, ea
->fcport
->port_name
,
1733 ea
->fcport
->loop_id
);
1735 if (IS_SW_RESV_ADDR(cid
)) {
1736 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1737 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1739 qla2x00_clear_loop_id(ea
->fcport
);
1741 qla24xx_post_gnl_work(vha
, ea
->fcport
);
1743 case MBS_PORT_ID_USED
:
1744 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1745 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1746 __func__
, __LINE__
, ea
->fcport
->port_name
,
1747 ea
->fcport
->d_id
.b
.domain
, ea
->fcport
->d_id
.b
.area
,
1748 ea
->fcport
->d_id
.b
.al_pa
);
1750 lid
= ea
->iop
[1] & 0xffff;
1751 qlt_find_sess_invalidate_other(vha
,
1752 wwn_to_u64(ea
->fcport
->port_name
),
1753 ea
->fcport
->d_id
, lid
, &conflict_fcport
);
1755 if (conflict_fcport
) {
1757 * Another fcport share the same loop_id/nport id.
1758 * Conflict fcport needs to finish cleanup before this
1759 * fcport can proceed to login.
1761 conflict_fcport
->conflict
= ea
->fcport
;
1762 ea
->fcport
->login_pause
= 1;
1764 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1765 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1766 __func__
, __LINE__
, ea
->fcport
->port_name
,
1767 ea
->fcport
->d_id
.b24
, lid
);
1768 qla2x00_clear_loop_id(ea
->fcport
);
1769 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
1771 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1772 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1773 __func__
, __LINE__
, ea
->fcport
->port_name
,
1774 ea
->fcport
->d_id
.b24
, lid
);
1776 qla2x00_clear_loop_id(ea
->fcport
);
1777 set_bit(lid
, vha
->hw
->loop_id_map
);
1778 ea
->fcport
->loop_id
= lid
;
1779 ea
->fcport
->keep_nport_handle
= 0;
1780 qlt_schedule_sess_for_deletion(ea
->fcport
);
1788 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
1791 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
1792 qlt_logo_completion_handler(fcport
, data
[0]);
1793 fcport
->login_gen
++;
1798 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
1801 if (data
[0] == MBS_COMMAND_COMPLETE
) {
1802 qla2x00_update_fcport(vha
, fcport
);
1808 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1809 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1810 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1812 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
1817 /****************************************************************************/
1818 /* QLogic ISP2x00 Hardware Support Functions. */
1819 /****************************************************************************/
1822 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
1824 int rval
= QLA_SUCCESS
;
1825 struct qla_hw_data
*ha
= vha
->hw
;
1826 uint32_t idc_major_ver
, idc_minor_ver
;
1829 qla83xx_idc_lock(vha
, 0);
1831 /* SV: TODO: Assign initialization timeout from
1832 * flash-info / other param
1834 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
1835 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
1837 /* Set our fcoe function presence */
1838 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
1839 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
1840 "Error while setting DRV-Presence.\n");
1841 rval
= QLA_FUNCTION_FAILED
;
1845 /* Decide the reset ownership */
1846 qla83xx_reset_ownership(vha
);
1849 * On first protocol driver load:
1850 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1852 * Others: Check compatibility with current IDC Major version.
1854 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
1855 if (ha
->flags
.nic_core_reset_owner
) {
1856 /* Set IDC Major version */
1857 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
1858 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
1860 /* Clearing IDC-Lock-Recovery register */
1861 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
1862 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
1864 * Clear further IDC participation if we are not compatible with
1865 * the current IDC Major Version.
1867 ql_log(ql_log_warn
, vha
, 0xb07d,
1868 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1869 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
1870 __qla83xx_clear_drv_presence(vha
);
1871 rval
= QLA_FUNCTION_FAILED
;
1874 /* Each function sets its supported Minor version. */
1875 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
1876 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
1877 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
1879 if (ha
->flags
.nic_core_reset_owner
) {
1880 memset(config
, 0, sizeof(config
));
1881 if (!qla81xx_get_port_config(vha
, config
))
1882 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
1886 rval
= qla83xx_idc_state_handler(vha
);
1889 qla83xx_idc_unlock(vha
, 0);
1895 * qla2x00_initialize_adapter
1899 * ha = adapter block pointer.
1905 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
1908 struct qla_hw_data
*ha
= vha
->hw
;
1909 struct req_que
*req
= ha
->req_q_map
[0];
1911 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
1912 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
1914 /* Clear adapter flags. */
1915 vha
->flags
.online
= 0;
1916 ha
->flags
.chip_reset_done
= 0;
1917 vha
->flags
.reset_active
= 0;
1918 ha
->flags
.pci_channel_io_perm_failure
= 0;
1919 ha
->flags
.eeh_busy
= 0;
1920 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
1921 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1922 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1923 vha
->device_flags
= DFLG_NO_CABLE
;
1925 vha
->flags
.management_server_logged_in
= 0;
1926 vha
->marker_needed
= 0;
1927 ha
->isp_abort_cnt
= 0;
1928 ha
->beacon_blink_led
= 0;
1930 set_bit(0, ha
->req_qid_map
);
1931 set_bit(0, ha
->rsp_qid_map
);
1933 ql_dbg(ql_dbg_init
, vha
, 0x0040,
1934 "Configuring PCI space...\n");
1935 rval
= ha
->isp_ops
->pci_config(vha
);
1937 ql_log(ql_log_warn
, vha
, 0x0044,
1938 "Unable to configure PCI space.\n");
1942 ha
->isp_ops
->reset_chip(vha
);
1944 rval
= qla2xxx_get_flash_info(vha
);
1946 ql_log(ql_log_fatal
, vha
, 0x004f,
1947 "Unable to validate FLASH data.\n");
1951 if (IS_QLA8044(ha
)) {
1952 qla8044_read_reset_template(vha
);
1954 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1955 * If DONRESET_BIT0 is set, drivers should not set dev_state
1956 * to NEED_RESET. But if NEED_RESET is set, drivers should
1957 * should honor the reset. */
1958 if (ql2xdontresethba
== 1)
1959 qla8044_set_idc_dontreset(vha
);
1962 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
1963 ql_dbg(ql_dbg_init
, vha
, 0x0061,
1964 "Configure NVRAM parameters...\n");
1966 ha
->isp_ops
->nvram_config(vha
);
1968 if (ha
->flags
.disable_serdes
) {
1969 /* Mask HBA via NVRAM settings? */
1970 ql_log(ql_log_info
, vha
, 0x0077,
1971 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
1972 return QLA_FUNCTION_FAILED
;
1975 ql_dbg(ql_dbg_init
, vha
, 0x0078,
1976 "Verifying loaded RISC code...\n");
1978 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
1979 rval
= ha
->isp_ops
->chip_diag(vha
);
1982 rval
= qla2x00_setup_chip(vha
);
1987 if (IS_QLA84XX(ha
)) {
1988 ha
->cs84xx
= qla84xx_get_chip(vha
);
1990 ql_log(ql_log_warn
, vha
, 0x00d0,
1991 "Unable to configure ISP84XX.\n");
1992 return QLA_FUNCTION_FAILED
;
1996 if (qla_ini_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
1997 rval
= qla2x00_init_rings(vha
);
1999 ha
->flags
.chip_reset_done
= 1;
2001 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
2002 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2003 rval
= qla84xx_init_chip(vha
);
2004 if (rval
!= QLA_SUCCESS
) {
2005 ql_log(ql_log_warn
, vha
, 0x00d4,
2006 "Unable to initialize ISP84XX.\n");
2007 qla84xx_put_chip(vha
);
2011 /* Load the NIC Core f/w if we are the first protocol driver. */
2012 if (IS_QLA8031(ha
)) {
2013 rval
= qla83xx_nic_core_fw_load(vha
);
2015 ql_log(ql_log_warn
, vha
, 0x0124,
2016 "Error in initializing NIC Core f/w.\n");
2019 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
2020 qla24xx_read_fcp_prio_cfg(vha
);
2022 if (IS_P3P_TYPE(ha
))
2023 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2025 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2031 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2034 * Returns 0 on success.
2037 qla2100_pci_config(scsi_qla_host_t
*vha
)
2040 unsigned long flags
;
2041 struct qla_hw_data
*ha
= vha
->hw
;
2042 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2044 pci_set_master(ha
->pdev
);
2045 pci_try_set_mwi(ha
->pdev
);
2047 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2048 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2049 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2051 pci_disable_rom(ha
->pdev
);
2053 /* Get PCI bus information. */
2054 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2055 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2056 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2062 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2065 * Returns 0 on success.
2068 qla2300_pci_config(scsi_qla_host_t
*vha
)
2071 unsigned long flags
= 0;
2073 struct qla_hw_data
*ha
= vha
->hw
;
2074 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2076 pci_set_master(ha
->pdev
);
2077 pci_try_set_mwi(ha
->pdev
);
2079 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2080 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2082 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2083 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2084 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2087 * If this is a 2300 card and not 2312, reset the
2088 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2089 * the 2310 also reports itself as a 2300 so we need to get the
2090 * fb revision level -- a 6 indicates it really is a 2300 and
2093 if (IS_QLA2300(ha
)) {
2094 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2097 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2098 for (cnt
= 0; cnt
< 30000; cnt
++) {
2099 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2105 /* Select FPM registers. */
2106 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2107 RD_REG_WORD(®
->ctrl_status
);
2109 /* Get the fb rev level */
2110 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
2112 if (ha
->fb_rev
== FPM_2300
)
2113 pci_clear_mwi(ha
->pdev
);
2115 /* Deselect FPM registers. */
2116 WRT_REG_WORD(®
->ctrl_status
, 0x0);
2117 RD_REG_WORD(®
->ctrl_status
);
2119 /* Release RISC module. */
2120 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2121 for (cnt
= 0; cnt
< 30000; cnt
++) {
2122 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
2128 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2131 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2133 pci_disable_rom(ha
->pdev
);
2135 /* Get PCI bus information. */
2136 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2137 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2138 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2144 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2147 * Returns 0 on success.
2150 qla24xx_pci_config(scsi_qla_host_t
*vha
)
2153 unsigned long flags
= 0;
2154 struct qla_hw_data
*ha
= vha
->hw
;
2155 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2157 pci_set_master(ha
->pdev
);
2158 pci_try_set_mwi(ha
->pdev
);
2160 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2161 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2162 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2163 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2165 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2167 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2168 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
2169 pcix_set_mmrbc(ha
->pdev
, 2048);
2171 /* PCIe -- adjust Maximum Read Request Size (2048). */
2172 if (pci_is_pcie(ha
->pdev
))
2173 pcie_set_readrq(ha
->pdev
, 4096);
2175 pci_disable_rom(ha
->pdev
);
2177 ha
->chip_revision
= ha
->pdev
->revision
;
2179 /* Get PCI bus information. */
2180 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2181 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
2182 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2188 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2191 * Returns 0 on success.
2194 qla25xx_pci_config(scsi_qla_host_t
*vha
)
2197 struct qla_hw_data
*ha
= vha
->hw
;
2199 pci_set_master(ha
->pdev
);
2200 pci_try_set_mwi(ha
->pdev
);
2202 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2203 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2204 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2205 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2207 /* PCIe -- adjust Maximum Read Request Size (2048). */
2208 if (pci_is_pcie(ha
->pdev
))
2209 pcie_set_readrq(ha
->pdev
, 4096);
2211 pci_disable_rom(ha
->pdev
);
2213 ha
->chip_revision
= ha
->pdev
->revision
;
2219 * qla2x00_isp_firmware() - Choose firmware image.
2222 * Returns 0 on success.
2225 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
2228 uint16_t loop_id
, topo
, sw_cap
;
2229 uint8_t domain
, area
, al_pa
;
2230 struct qla_hw_data
*ha
= vha
->hw
;
2232 /* Assume loading risc code */
2233 rval
= QLA_FUNCTION_FAILED
;
2235 if (ha
->flags
.disable_risc_code_load
) {
2236 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
2238 /* Verify checksum of loaded RISC code. */
2239 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
2240 if (rval
== QLA_SUCCESS
) {
2241 /* And, verify we are not in ROM code. */
2242 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
2243 &area
, &domain
, &topo
, &sw_cap
);
2248 ql_dbg(ql_dbg_init
, vha
, 0x007a,
2249 "**** Load RISC code ****.\n");
2255 * qla2x00_reset_chip() - Reset ISP chip.
2258 * Returns 0 on success.
2261 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
2263 unsigned long flags
= 0;
2264 struct qla_hw_data
*ha
= vha
->hw
;
2265 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2269 if (unlikely(pci_channel_offline(ha
->pdev
)))
2272 ha
->isp_ops
->disable_intrs(ha
);
2274 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2276 /* Turn off master enable */
2278 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
2279 cmd
&= ~PCI_COMMAND_MASTER
;
2280 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2282 if (!IS_QLA2100(ha
)) {
2284 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2285 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2286 for (cnt
= 0; cnt
< 30000; cnt
++) {
2287 if ((RD_REG_WORD(®
->hccr
) &
2288 HCCR_RISC_PAUSE
) != 0)
2293 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2297 /* Select FPM registers. */
2298 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2299 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2301 /* FPM Soft Reset. */
2302 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
2303 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2305 /* Toggle Fpm Reset. */
2306 if (!IS_QLA2200(ha
)) {
2307 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
2308 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2311 /* Select frame buffer registers. */
2312 WRT_REG_WORD(®
->ctrl_status
, 0x10);
2313 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2315 /* Reset frame buffer FIFOs. */
2316 if (IS_QLA2200(ha
)) {
2317 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
2318 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
2320 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
2322 /* Read back fb_cmd until zero or 3 seconds max */
2323 for (cnt
= 0; cnt
< 3000; cnt
++) {
2324 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
2330 /* Select RISC module registers. */
2331 WRT_REG_WORD(®
->ctrl_status
, 0);
2332 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2334 /* Reset RISC processor. */
2335 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2336 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2338 /* Release RISC processor. */
2339 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2340 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2343 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
2344 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
2346 /* Reset ISP chip. */
2347 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2349 /* Wait for RISC to recover from reset. */
2350 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2352 * It is necessary to for a delay here since the card doesn't
2353 * respond to PCI reads during a reset. On some architectures
2354 * this will result in an MCA.
2357 for (cnt
= 30000; cnt
; cnt
--) {
2358 if ((RD_REG_WORD(®
->ctrl_status
) &
2359 CSR_ISP_SOFT_RESET
) == 0)
2366 /* Reset RISC processor. */
2367 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2369 WRT_REG_WORD(®
->semaphore
, 0);
2371 /* Release RISC processor. */
2372 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2373 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2375 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2376 for (cnt
= 0; cnt
< 30000; cnt
++) {
2377 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
2385 /* Turn on master enable */
2386 cmd
|= PCI_COMMAND_MASTER
;
2387 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2389 /* Disable RISC pause on FPM parity error. */
2390 if (!IS_QLA2100(ha
)) {
2391 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
2392 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2395 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2399 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2401 * Returns 0 on success.
2404 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
2406 uint16_t mb
[4] = {0x1010, 0, 1, 0};
2408 if (!IS_QLA81XX(vha
->hw
))
2411 return qla81xx_write_mpi_register(vha
, mb
);
2415 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2418 * Returns 0 on success.
2421 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
2423 unsigned long flags
= 0;
2424 struct qla_hw_data
*ha
= vha
->hw
;
2425 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2428 static int abts_cnt
; /* ISP abort retry counts */
2429 int rval
= QLA_SUCCESS
;
2431 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2434 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2435 for (cnt
= 0; cnt
< 30000; cnt
++) {
2436 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
2442 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
))
2443 set_bit(DMA_SHUTDOWN_CMPL
, &ha
->fw_dump_cap_flags
);
2445 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017e,
2446 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2447 RD_REG_DWORD(®
->hccr
),
2448 RD_REG_DWORD(®
->ctrl_status
),
2449 (RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
));
2451 WRT_REG_DWORD(®
->ctrl_status
,
2452 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2453 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2457 /* Wait for firmware to complete NVRAM accesses. */
2458 RD_REG_WORD(®
->mailbox0
);
2459 for (cnt
= 10000; RD_REG_WORD(®
->mailbox0
) != 0 &&
2460 rval
== QLA_SUCCESS
; cnt
--) {
2465 rval
= QLA_FUNCTION_TIMEOUT
;
2468 if (rval
== QLA_SUCCESS
)
2469 set_bit(ISP_MBX_RDY
, &ha
->fw_dump_cap_flags
);
2471 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017f,
2472 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2473 RD_REG_DWORD(®
->hccr
),
2474 RD_REG_DWORD(®
->mailbox0
));
2476 /* Wait for soft-reset to complete. */
2477 RD_REG_DWORD(®
->ctrl_status
);
2478 for (cnt
= 0; cnt
< 60; cnt
++) {
2480 if ((RD_REG_DWORD(®
->ctrl_status
) &
2481 CSRX_ISP_SOFT_RESET
) == 0)
2486 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_ISP_SOFT_RESET
))
2487 set_bit(ISP_SOFT_RESET_CMPL
, &ha
->fw_dump_cap_flags
);
2489 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015d,
2490 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2491 RD_REG_DWORD(®
->hccr
),
2492 RD_REG_DWORD(®
->ctrl_status
));
2494 /* If required, do an MPI FW reset now */
2495 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
2496 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
2497 if (++abts_cnt
< 5) {
2498 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2499 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
2502 * We exhausted the ISP abort retries. We have to
2503 * set the board offline.
2506 vha
->flags
.online
= 0;
2511 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
2512 RD_REG_DWORD(®
->hccr
);
2514 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
2515 RD_REG_DWORD(®
->hccr
);
2517 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
2518 RD_REG_DWORD(®
->hccr
);
2520 RD_REG_WORD(®
->mailbox0
);
2521 for (cnt
= 60; RD_REG_WORD(®
->mailbox0
) != 0 &&
2522 rval
== QLA_SUCCESS
; cnt
--) {
2527 rval
= QLA_FUNCTION_TIMEOUT
;
2529 if (rval
== QLA_SUCCESS
)
2530 set_bit(RISC_RDY_AFT_RESET
, &ha
->fw_dump_cap_flags
);
2532 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015e,
2533 "Host Risc 0x%x, mailbox0 0x%x\n",
2534 RD_REG_DWORD(®
->hccr
),
2535 RD_REG_WORD(®
->mailbox0
));
2537 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2539 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015f,
2540 "Driver in %s mode\n",
2541 IS_NOPOLLING_TYPE(ha
) ? "Interrupt" : "Polling");
2543 if (IS_NOPOLLING_TYPE(ha
))
2544 ha
->isp_ops
->enable_intrs(ha
);
2550 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
2552 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2554 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2555 *data
= RD_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
);
2560 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
2562 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2564 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2565 WRT_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
, data
);
2569 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
2572 uint delta_msec
= 100;
2573 uint elapsed_msec
= 0;
2577 if (vha
->hw
->pdev
->subsystem_device
!= 0x0175 &&
2578 vha
->hw
->pdev
->subsystem_device
!= 0x0240)
2581 WRT_REG_DWORD(&vha
->hw
->iobase
->isp24
.hccr
, HCCRX_SET_RISC_PAUSE
);
2585 timeout_msec
= TIMEOUT_SEMAPHORE
;
2586 n
= timeout_msec
/ delta_msec
;
2588 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
2589 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2590 if (wd32
& RISC_SEMAPHORE
)
2593 elapsed_msec
+= delta_msec
;
2594 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2598 if (!(wd32
& RISC_SEMAPHORE
))
2601 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2604 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
2605 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
2606 n
= timeout_msec
/ delta_msec
;
2608 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2609 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2612 elapsed_msec
+= delta_msec
;
2613 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2617 if (wd32
& RISC_SEMAPHORE_FORCE
)
2618 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
2623 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
2630 * qla24xx_reset_chip() - Reset ISP24xx chip.
2633 * Returns 0 on success.
2636 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
2638 struct qla_hw_data
*ha
= vha
->hw
;
2640 if (pci_channel_offline(ha
->pdev
) &&
2641 ha
->flags
.pci_channel_io_perm_failure
) {
2645 ha
->isp_ops
->disable_intrs(ha
);
2647 qla25xx_manipulate_risc_semaphore(vha
);
2649 /* Perform RISC reset. */
2650 qla24xx_reset_risc(vha
);
2654 * qla2x00_chip_diag() - Test chip for proper operation.
2657 * Returns 0 on success.
2660 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
2663 struct qla_hw_data
*ha
= vha
->hw
;
2664 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2665 unsigned long flags
= 0;
2669 struct req_que
*req
= ha
->req_q_map
[0];
2671 /* Assume a failed state */
2672 rval
= QLA_FUNCTION_FAILED
;
2674 ql_dbg(ql_dbg_init
, vha
, 0x007b,
2675 "Testing device at %lx.\n", (u_long
)®
->flash_address
);
2677 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2679 /* Reset ISP chip. */
2680 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2683 * We need to have a delay here since the card will not respond while
2684 * in reset causing an MCA on some architectures.
2687 data
= qla2x00_debounce_register(®
->ctrl_status
);
2688 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
2690 data
= RD_REG_WORD(®
->ctrl_status
);
2695 goto chip_diag_failed
;
2697 ql_dbg(ql_dbg_init
, vha
, 0x007c,
2698 "Reset register cleared by chip reset.\n");
2700 /* Reset RISC processor. */
2701 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2702 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2704 /* Workaround for QLA2312 PCI parity error */
2705 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2706 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
2707 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
2709 data
= RD_MAILBOX_REG(ha
, reg
, 0);
2716 goto chip_diag_failed
;
2718 /* Check product ID of chip */
2719 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product ID of chip.\n");
2721 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
2722 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
2723 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
2724 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
2725 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
2726 mb
[3] != PROD_ID_3
) {
2727 ql_log(ql_log_warn
, vha
, 0x0062,
2728 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2729 mb
[1], mb
[2], mb
[3]);
2731 goto chip_diag_failed
;
2733 ha
->product_id
[0] = mb
[1];
2734 ha
->product_id
[1] = mb
[2];
2735 ha
->product_id
[2] = mb
[3];
2736 ha
->product_id
[3] = mb
[4];
2738 /* Adjust fw RISC transfer size */
2739 if (req
->length
> 1024)
2740 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
2742 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
2745 if (IS_QLA2200(ha
) &&
2746 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
2747 /* Limit firmware transfer size with a 2200A */
2748 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
2750 ha
->device_type
|= DT_ISP2200A
;
2751 ha
->fw_transfer_size
= 128;
2754 /* Wrap Incoming Mailboxes Test. */
2755 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2757 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
2758 rval
= qla2x00_mbx_reg_test(vha
);
2760 ql_log(ql_log_warn
, vha
, 0x0080,
2761 "Failed mailbox send register test.\n");
2763 /* Flag a successful rval */
2765 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2769 ql_log(ql_log_info
, vha
, 0x0081,
2770 "Chip diagnostics **** FAILED ****.\n");
2772 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2778 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2781 * Returns 0 on success.
2784 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
2787 struct qla_hw_data
*ha
= vha
->hw
;
2788 struct req_que
*req
= ha
->req_q_map
[0];
2790 if (IS_P3P_TYPE(ha
))
2793 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
2795 rval
= qla2x00_mbx_reg_test(vha
);
2797 ql_log(ql_log_warn
, vha
, 0x0082,
2798 "Failed mailbox send register test.\n");
2800 /* Flag a successful rval */
2808 qla2x00_alloc_offload_mem(scsi_qla_host_t
*vha
)
2813 struct qla_hw_data
*ha
= vha
->hw
;
2816 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
2817 "%s: Offload Mem is already allocated.\n",
2822 if (IS_FWI2_CAPABLE(ha
)) {
2823 /* Allocate memory for Fibre Channel Event Buffer. */
2824 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2829 dma_free_coherent(&ha
->pdev
->dev
,
2830 FCE_SIZE
, ha
->fce
, ha
->fce_dma
);
2832 /* Allocate memory for Fibre Channel Event Buffer. */
2833 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
2836 ql_log(ql_log_warn
, vha
, 0x00be,
2837 "Unable to allocate (%d KB) for FCE.\n",
2842 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
2843 ha
->fce_mb
, &ha
->fce_bufs
);
2845 ql_log(ql_log_warn
, vha
, 0x00bf,
2846 "Unable to initialize FCE (%d).\n", rval
);
2847 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
2849 ha
->flags
.fce_enabled
= 0;
2852 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
2853 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
2855 ha
->flags
.fce_enabled
= 1;
2856 ha
->fce_dma
= tc_dma
;
2861 dma_free_coherent(&ha
->pdev
->dev
,
2862 EFT_SIZE
, ha
->eft
, ha
->eft_dma
);
2864 /* Allocate memory for Extended Trace Buffer. */
2865 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
2868 ql_log(ql_log_warn
, vha
, 0x00c1,
2869 "Unable to allocate (%d KB) for EFT.\n",
2874 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
2876 ql_log(ql_log_warn
, vha
, 0x00c2,
2877 "Unable to initialize EFT (%d).\n", rval
);
2878 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
2882 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
2883 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
2885 ha
->eft_dma
= tc_dma
;
2894 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
2896 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
2897 eft_size
, fce_size
, mq_size
;
2898 struct qla_hw_data
*ha
= vha
->hw
;
2899 struct req_que
*req
= ha
->req_q_map
[0];
2900 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
2901 struct qla2xxx_fw_dump
*fw_dump
;
2903 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
2904 req_q_size
= rsp_q_size
= 0;
2906 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2907 fixed_size
= sizeof(struct qla2100_fw_dump
);
2908 } else if (IS_QLA23XX(ha
)) {
2909 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
2910 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
2912 } else if (IS_FWI2_CAPABLE(ha
)) {
2913 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))
2914 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
2915 else if (IS_QLA81XX(ha
))
2916 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
2917 else if (IS_QLA25XX(ha
))
2918 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
2920 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
2922 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
2925 if (!IS_QLA83XX(ha
) && !IS_QLA27XX(ha
))
2926 mq_size
= sizeof(struct qla2xxx_mq_chain
);
2928 * Allocate maximum buffer size for all queues.
2929 * Resizing must be done at end-of-dump processing.
2931 mq_size
+= ha
->max_req_queues
*
2932 (req
->length
* sizeof(request_t
));
2933 mq_size
+= ha
->max_rsp_queues
*
2934 (rsp
->length
* sizeof(response_t
));
2936 if (ha
->tgt
.atio_ring
)
2937 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
2938 /* Allocate memory for Fibre Channel Event Buffer. */
2939 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2943 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
2945 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
2946 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
2947 eft_size
= EFT_SIZE
;
2950 if (IS_QLA27XX(ha
)) {
2951 if (!ha
->fw_dump_template
) {
2952 ql_log(ql_log_warn
, vha
, 0x00ba,
2953 "Failed missing fwdump template\n");
2956 dump_size
= qla27xx_fwdt_calculate_dump_size(vha
);
2957 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
2958 "-> allocating fwdump (%x bytes)...\n", dump_size
);
2962 req_q_size
= req
->length
* sizeof(request_t
);
2963 rsp_q_size
= rsp
->length
* sizeof(response_t
);
2964 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
2965 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
2966 ha
->chain_offset
= dump_size
;
2967 dump_size
+= mq_size
+ fce_size
;
2969 if (ha
->exchoffld_buf
)
2970 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
2972 if (ha
->exlogin_buf
)
2973 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
2977 if (!ha
->fw_dump_len
|| dump_size
!= ha
->fw_dump_len
) {
2978 fw_dump
= vmalloc(dump_size
);
2980 ql_log(ql_log_warn
, vha
, 0x00c4,
2981 "Unable to allocate (%d KB) for firmware dump.\n",
2986 ha
->fw_dump
= fw_dump
;
2988 ha
->fw_dump_len
= dump_size
;
2989 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
2990 "Allocated (%d KB) for firmware dump.\n",
2996 ha
->fw_dump
->signature
[0] = 'Q';
2997 ha
->fw_dump
->signature
[1] = 'L';
2998 ha
->fw_dump
->signature
[2] = 'G';
2999 ha
->fw_dump
->signature
[3] = 'C';
3000 ha
->fw_dump
->version
= htonl(1);
3002 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
3003 ha
->fw_dump
->mem_size
= htonl(mem_size
);
3004 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
3005 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
3007 ha
->fw_dump
->eft_size
= htonl(eft_size
);
3008 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
3009 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
3011 ha
->fw_dump
->header_size
=
3012 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
3018 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
3020 #define MPS_MASK 0xe0
3025 if (!IS_QLA81XX(vha
->hw
))
3028 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
3029 if (rval
!= QLA_SUCCESS
) {
3030 ql_log(ql_log_warn
, vha
, 0x0105,
3031 "Unable to acquire semaphore.\n");
3035 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
3036 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
3037 if (rval
!= QLA_SUCCESS
) {
3038 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
3043 if (dc
== (dw
& MPS_MASK
))
3048 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
3049 if (rval
!= QLA_SUCCESS
) {
3050 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
3054 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
3055 if (rval
!= QLA_SUCCESS
) {
3056 ql_log(ql_log_warn
, vha
, 0x006d,
3057 "Unable to release semaphore.\n");
3065 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
3067 /* Don't try to reallocate the array */
3068 if (req
->outstanding_cmds
)
3071 if (!IS_FWI2_CAPABLE(ha
))
3072 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
3074 if (ha
->cur_fw_xcb_count
<= ha
->cur_fw_iocb_count
)
3075 req
->num_outstanding_cmds
= ha
->cur_fw_xcb_count
;
3077 req
->num_outstanding_cmds
= ha
->cur_fw_iocb_count
;
3080 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
3081 req
->num_outstanding_cmds
, GFP_KERNEL
);
3083 if (!req
->outstanding_cmds
) {
3085 * Try to allocate a minimal size just so we can get through
3088 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
3089 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
3090 req
->num_outstanding_cmds
, GFP_KERNEL
);
3092 if (!req
->outstanding_cmds
) {
3093 ql_log(ql_log_fatal
, NULL
, 0x0126,
3094 "Failed to allocate memory for "
3095 "outstanding_cmds for req_que %p.\n", req
);
3096 req
->num_outstanding_cmds
= 0;
3097 return QLA_FUNCTION_FAILED
;
3104 #define PRINT_FIELD(_field, _flag, _str) { \
3105 if (a0->_field & _flag) {\
3111 len = snprintf(ptr, leftover, "%s", _str); \
3118 static void qla2xxx_print_sfp_info(struct scsi_qla_host
*vha
)
3121 struct sff_8247_a0
*a0
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3122 u8 str
[STR_LEN
], *ptr
, p
;
3125 memset(str
, 0, STR_LEN
);
3126 snprintf(str
, SFF_VEN_NAME_LEN
+1, a0
->vendor_name
);
3127 ql_dbg(ql_dbg_init
, vha
, 0x015a,
3128 "SFP MFG Name: %s\n", str
);
3130 memset(str
, 0, STR_LEN
);
3131 snprintf(str
, SFF_PART_NAME_LEN
+1, a0
->vendor_pn
);
3132 ql_dbg(ql_dbg_init
, vha
, 0x015c,
3133 "SFP Part Name: %s\n", str
);
3136 memset(str
, 0, STR_LEN
);
3140 PRINT_FIELD(fc_med_cc9
, FC_MED_TW
, "Twin AX");
3141 PRINT_FIELD(fc_med_cc9
, FC_MED_TP
, "Twisted Pair");
3142 PRINT_FIELD(fc_med_cc9
, FC_MED_MI
, "Min Coax");
3143 PRINT_FIELD(fc_med_cc9
, FC_MED_TV
, "Video Coax");
3144 PRINT_FIELD(fc_med_cc9
, FC_MED_M6
, "MultiMode 62.5um");
3145 PRINT_FIELD(fc_med_cc9
, FC_MED_M5
, "MultiMode 50um");
3146 PRINT_FIELD(fc_med_cc9
, FC_MED_SM
, "SingleMode");
3147 ql_dbg(ql_dbg_init
, vha
, 0x0160,
3148 "SFP Media: %s\n", str
);
3151 memset(str
, 0, STR_LEN
);
3155 PRINT_FIELD(fc_ll_cc7
, FC_LL_VL
, "Very Long");
3156 PRINT_FIELD(fc_ll_cc7
, FC_LL_S
, "Short");
3157 PRINT_FIELD(fc_ll_cc7
, FC_LL_I
, "Intermediate");
3158 PRINT_FIELD(fc_ll_cc7
, FC_LL_L
, "Long");
3159 PRINT_FIELD(fc_ll_cc7
, FC_LL_M
, "Medium");
3160 ql_dbg(ql_dbg_init
, vha
, 0x0196,
3161 "SFP Link Length: %s\n", str
);
3163 memset(str
, 0, STR_LEN
);
3167 PRINT_FIELD(fc_ll_cc7
, FC_LL_SA
, "Short Wave (SA)");
3168 PRINT_FIELD(fc_ll_cc7
, FC_LL_LC
, "Long Wave(LC)");
3169 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SN
, "Short Wave (SN)");
3170 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SL
, "Short Wave (SL)");
3171 PRINT_FIELD(fc_tec_cc8
, FC_TEC_LL
, "Long Wave (LL)");
3172 ql_dbg(ql_dbg_init
, vha
, 0x016e,
3173 "SFP FC Link Tech: %s\n", str
);
3176 ql_dbg(ql_dbg_init
, vha
, 0x016f,
3177 "SFP Distant: %d km\n", a0
->length_km
);
3178 if (a0
->length_100m
)
3179 ql_dbg(ql_dbg_init
, vha
, 0x0170,
3180 "SFP Distant: %d m\n", a0
->length_100m
*100);
3181 if (a0
->length_50um_10m
)
3182 ql_dbg(ql_dbg_init
, vha
, 0x0189,
3183 "SFP Distant (WL=50um): %d m\n", a0
->length_50um_10m
* 10);
3184 if (a0
->length_62um_10m
)
3185 ql_dbg(ql_dbg_init
, vha
, 0x018a,
3186 "SFP Distant (WL=62.5um): %d m\n", a0
->length_62um_10m
* 10);
3187 if (a0
->length_om4_10m
)
3188 ql_dbg(ql_dbg_init
, vha
, 0x0194,
3189 "SFP Distant (OM4): %d m\n", a0
->length_om4_10m
* 10);
3190 if (a0
->length_om3_10m
)
3191 ql_dbg(ql_dbg_init
, vha
, 0x0195,
3192 "SFP Distant (OM3): %d m\n", a0
->length_om3_10m
* 10);
3198 * QLA_SUCCESS: no action
3199 * QLA_INTERFACE_ERROR: SFP is not there.
3200 * QLA_FUNCTION_FAILED: detected New SFP
3203 qla24xx_detect_sfp(scsi_qla_host_t
*vha
)
3205 int rc
= QLA_SUCCESS
;
3206 struct sff_8247_a0
*a
;
3207 struct qla_hw_data
*ha
= vha
->hw
;
3209 if (!AUTO_DETECT_SFP_SUPPORT(vha
))
3212 rc
= qla2x00_read_sfp_dev(vha
, NULL
, 0);
3216 a
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3217 qla2xxx_print_sfp_info(vha
);
3219 if (a
->fc_ll_cc7
& FC_LL_VL
|| a
->fc_ll_cc7
& FC_LL_L
) {
3221 ha
->flags
.detected_lr_sfp
= 1;
3223 if (a
->length_km
> 5 || a
->length_100m
> 50)
3224 ha
->long_range_distance
= LR_DISTANCE_10K
;
3226 ha
->long_range_distance
= LR_DISTANCE_5K
;
3228 if (ha
->flags
.detected_lr_sfp
!= ha
->flags
.using_lr_setting
)
3229 ql_dbg(ql_dbg_async
, vha
, 0x507b,
3230 "Detected Long Range SFP.\n");
3233 ha
->flags
.detected_lr_sfp
= 0;
3234 if (ha
->flags
.using_lr_setting
)
3235 ql_dbg(ql_dbg_async
, vha
, 0x5084,
3236 "Detected Short Range SFP.\n");
3239 if (!vha
->flags
.init_done
)
3246 * qla2x00_setup_chip() - Load and start RISC firmware.
3249 * Returns 0 on success.
3252 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
3255 uint32_t srisc_address
= 0;
3256 struct qla_hw_data
*ha
= vha
->hw
;
3257 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3258 unsigned long flags
;
3259 uint16_t fw_major_version
;
3261 if (IS_P3P_TYPE(ha
)) {
3262 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3263 if (rval
== QLA_SUCCESS
) {
3264 qla2x00_stop_firmware(vha
);
3265 goto enable_82xx_npiv
;
3270 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3271 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3272 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3273 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3274 RD_REG_WORD(®
->hccr
);
3275 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3278 qla81xx_mpi_sync(vha
);
3280 /* Load firmware sequences */
3281 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3282 if (rval
== QLA_SUCCESS
) {
3283 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
3284 "Verifying Checksum of loaded RISC code.\n");
3286 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
3287 if (rval
== QLA_SUCCESS
) {
3288 /* Start firmware execution. */
3289 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3290 "Starting firmware.\n");
3293 ha
->flags
.exlogins_enabled
= 1;
3295 if (qla_is_exch_offld_enabled(vha
))
3296 ha
->flags
.exchoffld_enabled
= 1;
3298 rval
= qla2x00_execute_fw(vha
, srisc_address
);
3299 /* Retrieve firmware information. */
3300 if (rval
== QLA_SUCCESS
) {
3301 qla24xx_detect_sfp(vha
);
3303 rval
= qla2x00_set_exlogins_buffer(vha
);
3304 if (rval
!= QLA_SUCCESS
)
3307 rval
= qla2x00_set_exchoffld_buffer(vha
);
3308 if (rval
!= QLA_SUCCESS
)
3312 fw_major_version
= ha
->fw_major_version
;
3313 if (IS_P3P_TYPE(ha
))
3314 qla82xx_check_md_needed(vha
);
3316 rval
= qla2x00_get_fw_version(vha
);
3317 if (rval
!= QLA_SUCCESS
)
3319 ha
->flags
.npiv_supported
= 0;
3320 if (IS_QLA2XXX_MIDTYPE(ha
) &&
3321 (ha
->fw_attributes
& BIT_2
)) {
3322 ha
->flags
.npiv_supported
= 1;
3323 if ((!ha
->max_npiv_vports
) ||
3324 ((ha
->max_npiv_vports
+ 1) %
3325 MIN_MULTI_ID_FABRIC
))
3326 ha
->max_npiv_vports
=
3327 MIN_MULTI_ID_FABRIC
- 1;
3329 qla2x00_get_resource_cnts(vha
);
3332 * Allocate the array of outstanding commands
3333 * now that we know the firmware resources.
3335 rval
= qla2x00_alloc_outstanding_cmds(ha
,
3337 if (rval
!= QLA_SUCCESS
)
3340 if (!fw_major_version
&& !(IS_P3P_TYPE(ha
)))
3341 qla2x00_alloc_offload_mem(vha
);
3343 if (ql2xallocfwdump
&& !(IS_P3P_TYPE(ha
)))
3344 qla2x00_alloc_fw_dump(vha
);
3350 ql_log(ql_log_fatal
, vha
, 0x00cd,
3351 "ISP Firmware failed checksum.\n");
3357 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3358 /* Enable proper parity. */
3359 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3362 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
3364 /* SRAM, Instruction RAM and GP RAM parity */
3365 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
3366 RD_REG_WORD(®
->hccr
);
3367 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3371 ha
->flags
.fac_supported
= 1;
3372 else if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
3375 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
3376 if (rval
== QLA_SUCCESS
) {
3377 ha
->flags
.fac_supported
= 1;
3378 ha
->fdt_block_size
= size
<< 2;
3380 ql_log(ql_log_warn
, vha
, 0x00ce,
3381 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3382 ha
->fw_major_version
, ha
->fw_minor_version
,
3383 ha
->fw_subminor_version
);
3385 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3386 ha
->flags
.fac_supported
= 0;
3393 ql_log(ql_log_fatal
, vha
, 0x00cf,
3394 "Setup chip ****FAILED****.\n");
3401 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3404 * Beginning of request ring has initialization control block already built
3405 * by nvram config routine.
3407 * Returns 0 on success.
3410 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
3415 rsp
->ring_ptr
= rsp
->ring
;
3416 rsp
->ring_index
= 0;
3417 rsp
->status_srb
= NULL
;
3418 pkt
= rsp
->ring_ptr
;
3419 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
3420 pkt
->signature
= RESPONSE_PROCESSED
;
3426 * qla2x00_update_fw_options() - Read and process firmware options.
3429 * Returns 0 on success.
3432 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
3434 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
3435 struct qla_hw_data
*ha
= vha
->hw
;
3437 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
3438 qla2x00_get_fw_options(vha
, ha
->fw_options
);
3440 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3443 /* Serial Link options. */
3444 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
3445 "Serial link options.\n");
3446 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
3447 (uint8_t *)&ha
->fw_seriallink_options
,
3448 sizeof(ha
->fw_seriallink_options
));
3450 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
3451 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
3452 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
3455 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
3456 emphasis
= (ha
->fw_seriallink_options
[2] &
3457 (BIT_4
| BIT_3
)) >> 3;
3458 tx_sens
= ha
->fw_seriallink_options
[0] &
3459 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3460 rx_sens
= (ha
->fw_seriallink_options
[0] &
3461 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3462 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
3463 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3466 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
3467 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3468 ha
->fw_options
[10] |= BIT_5
|
3469 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3470 (tx_sens
& (BIT_1
| BIT_0
));
3473 swing
= (ha
->fw_seriallink_options
[2] &
3474 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
3475 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
3476 tx_sens
= ha
->fw_seriallink_options
[1] &
3477 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3478 rx_sens
= (ha
->fw_seriallink_options
[1] &
3479 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3480 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
3481 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3484 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
3485 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3486 ha
->fw_options
[11] |= BIT_5
|
3487 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3488 (tx_sens
& (BIT_1
| BIT_0
));
3492 /* Return command IOCBs without waiting for an ABTS to complete. */
3493 ha
->fw_options
[3] |= BIT_13
;
3496 if (ha
->flags
.enable_led_scheme
)
3497 ha
->fw_options
[2] |= BIT_12
;
3499 /* Detect ISP6312. */
3501 ha
->fw_options
[2] |= BIT_13
;
3503 /* Set Retry FLOGI in case of P2P connection */
3504 if (ha
->operating_mode
== P2P
) {
3505 ha
->fw_options
[2] |= BIT_3
;
3506 ql_dbg(ql_dbg_disc
, vha
, 0x2100,
3507 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3508 __func__
, ha
->fw_options
[2]);
3511 /* Update firmware options. */
3512 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3516 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
3519 struct qla_hw_data
*ha
= vha
->hw
;
3521 if (IS_P3P_TYPE(ha
))
3524 /* Hold status IOCBs until ABTS response received. */
3526 ha
->fw_options
[3] |= BIT_12
;
3528 /* Set Retry FLOGI in case of P2P connection */
3529 if (ha
->operating_mode
== P2P
) {
3530 ha
->fw_options
[2] |= BIT_3
;
3531 ql_dbg(ql_dbg_disc
, vha
, 0x2101,
3532 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3533 __func__
, ha
->fw_options
[2]);
3536 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3537 if (ql2xmvasynctoatio
&&
3538 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))) {
3539 if (qla_tgt_mode_enabled(vha
) ||
3540 qla_dual_mode_enabled(vha
))
3541 ha
->fw_options
[2] |= BIT_11
;
3543 ha
->fw_options
[2] &= ~BIT_11
;
3546 if (IS_QLA25XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3548 * Tell FW to track each exchange to prevent
3549 * driver from using stale exchange.
3551 if (qla_tgt_mode_enabled(vha
) ||
3552 qla_dual_mode_enabled(vha
))
3553 ha
->fw_options
[2] |= BIT_4
;
3555 ha
->fw_options
[2] &= ~BIT_4
;
3557 /* Reserve 1/2 of emergency exchanges for ELS.*/
3558 if (qla2xuseresexchforels
)
3559 ha
->fw_options
[2] |= BIT_8
;
3561 ha
->fw_options
[2] &= ~BIT_8
;
3564 ql_dbg(ql_dbg_init
, vha
, 0x00e8,
3565 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3566 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
3567 ha
->fw_options
[3], vha
->host
->active_mode
);
3569 if (ha
->fw_options
[1] || ha
->fw_options
[2] || ha
->fw_options
[3])
3570 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3572 /* Update Serial Link options. */
3573 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
3576 rval
= qla2x00_set_serdes_params(vha
,
3577 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
3578 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
3579 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
3580 if (rval
!= QLA_SUCCESS
) {
3581 ql_log(ql_log_warn
, vha
, 0x0104,
3582 "Unable to update Serial Link options (%x).\n", rval
);
3587 qla2x00_config_rings(struct scsi_qla_host
*vha
)
3589 struct qla_hw_data
*ha
= vha
->hw
;
3590 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3591 struct req_que
*req
= ha
->req_q_map
[0];
3592 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3594 /* Setup ring parameters in initialization control block. */
3595 ha
->init_cb
->request_q_outpointer
= cpu_to_le16(0);
3596 ha
->init_cb
->response_q_inpointer
= cpu_to_le16(0);
3597 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
3598 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
3599 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3600 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3601 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3602 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3604 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
3605 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
3606 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
3607 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
3608 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
3612 qla24xx_config_rings(struct scsi_qla_host
*vha
)
3614 struct qla_hw_data
*ha
= vha
->hw
;
3615 device_reg_t
*reg
= ISP_QUE_REG(ha
, 0);
3616 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
3617 struct qla_msix_entry
*msix
;
3618 struct init_cb_24xx
*icb
;
3620 struct req_que
*req
= ha
->req_q_map
[0];
3621 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3623 /* Setup ring parameters in initialization control block. */
3624 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3625 icb
->request_q_outpointer
= cpu_to_le16(0);
3626 icb
->response_q_inpointer
= cpu_to_le16(0);
3627 icb
->request_q_length
= cpu_to_le16(req
->length
);
3628 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
3629 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3630 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3631 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3632 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3634 /* Setup ATIO queue dma pointers for target mode */
3635 icb
->atio_q_inpointer
= cpu_to_le16(0);
3636 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
3637 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
3638 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
3640 if (IS_SHADOW_REG_CAPABLE(ha
))
3641 icb
->firmware_options_2
|= cpu_to_le32(BIT_30
|BIT_29
);
3643 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3644 icb
->qos
= cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
3645 icb
->rid
= cpu_to_le16(rid
);
3646 if (ha
->flags
.msix_enabled
) {
3647 msix
= &ha
->msix_entries
[1];
3648 ql_dbg(ql_dbg_init
, vha
, 0x0019,
3649 "Registering vector 0x%x for base que.\n",
3651 icb
->msix
= cpu_to_le16(msix
->entry
);
3653 /* Use alternate PCI bus number */
3655 icb
->firmware_options_2
|= cpu_to_le32(BIT_19
);
3656 /* Use alternate PCI devfn */
3658 icb
->firmware_options_2
|= cpu_to_le32(BIT_18
);
3660 /* Use Disable MSIX Handshake mode for capable adapters */
3661 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
3662 (ha
->flags
.msix_enabled
)) {
3663 icb
->firmware_options_2
&= cpu_to_le32(~BIT_22
);
3664 ha
->flags
.disable_msix_handshake
= 1;
3665 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
3666 "MSIX Handshake Disable Mode turned on.\n");
3668 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
3670 icb
->firmware_options_2
|= cpu_to_le32(BIT_23
);
3672 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
3673 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
3674 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
3675 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
3677 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
3678 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
3679 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
3680 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
3682 qlt_24xx_config_rings(vha
);
3685 RD_REG_DWORD(&ioreg
->hccr
);
3689 * qla2x00_init_rings() - Initializes firmware.
3692 * Beginning of request ring has initialization control block already built
3693 * by nvram config routine.
3695 * Returns 0 on success.
3698 qla2x00_init_rings(scsi_qla_host_t
*vha
)
3701 unsigned long flags
= 0;
3703 struct qla_hw_data
*ha
= vha
->hw
;
3704 struct req_que
*req
;
3705 struct rsp_que
*rsp
;
3706 struct mid_init_cb_24xx
*mid_init_cb
=
3707 (struct mid_init_cb_24xx
*) ha
->init_cb
;
3709 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3711 /* Clear outstanding commands array. */
3712 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
3713 req
= ha
->req_q_map
[que
];
3714 if (!req
|| !test_bit(que
, ha
->req_qid_map
))
3716 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
3718 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
3719 req
->outstanding_cmds
[cnt
] = NULL
;
3721 req
->current_outstanding_cmd
= 1;
3723 /* Initialize firmware. */
3724 req
->ring_ptr
= req
->ring
;
3725 req
->ring_index
= 0;
3726 req
->cnt
= req
->length
;
3729 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
3730 rsp
= ha
->rsp_q_map
[que
];
3731 if (!rsp
|| !test_bit(que
, ha
->rsp_qid_map
))
3733 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
3735 /* Initialize response queue entries */
3737 qlafx00_init_response_q_entries(rsp
);
3739 qla2x00_init_response_q_entries(rsp
);
3742 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
3743 ha
->tgt
.atio_ring_index
= 0;
3744 /* Initialize ATIO queue entries */
3745 qlt_init_atio_q_entries(vha
);
3747 ha
->isp_ops
->config_rings(vha
);
3749 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3751 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
3753 if (IS_QLAFX00(ha
)) {
3754 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
3758 /* Update any ISP specific firmware options before initialization. */
3759 ha
->isp_ops
->update_fw_options(vha
);
3761 if (ha
->flags
.npiv_supported
) {
3762 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
3763 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
3764 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
3767 if (IS_FWI2_CAPABLE(ha
)) {
3768 mid_init_cb
->options
= cpu_to_le16(BIT_1
);
3769 mid_init_cb
->init_cb
.execution_throttle
=
3770 cpu_to_le16(ha
->cur_fw_xcb_count
);
3771 ha
->flags
.dport_enabled
=
3772 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_7
) != 0;
3773 ql_dbg(ql_dbg_init
, vha
, 0x0191, "DPORT Support: %s.\n",
3774 (ha
->flags
.dport_enabled
) ? "enabled" : "disabled");
3775 /* FA-WWPN Status */
3776 ha
->flags
.fawwpn_enabled
=
3777 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_6
) != 0;
3778 ql_dbg(ql_dbg_init
, vha
, 0x00bc, "FA-WWPN Support: %s.\n",
3779 (ha
->flags
.fawwpn_enabled
) ? "enabled" : "disabled");
3782 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
3785 ql_log(ql_log_fatal
, vha
, 0x00d2,
3786 "Init Firmware **** FAILED ****.\n");
3788 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
3789 "Init Firmware -- success.\n");
3797 * qla2x00_fw_ready() - Waits for firmware ready.
3800 * Returns 0 on success.
3803 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
3806 unsigned long wtime
, mtime
, cs84xx_time
;
3807 uint16_t min_wait
; /* Minimum wait time if loop is down */
3808 uint16_t wait_time
; /* Wait time if loop is coming ready */
3810 struct qla_hw_data
*ha
= vha
->hw
;
3812 if (IS_QLAFX00(vha
->hw
))
3813 return qlafx00_fw_ready(vha
);
3817 /* Time to wait for loop down */
3818 if (IS_P3P_TYPE(ha
))
3824 * Firmware should take at most one RATOV to login, plus 5 seconds for
3825 * our own processing.
3827 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
3828 wait_time
= min_wait
;
3831 /* Min wait time if loop down */
3832 mtime
= jiffies
+ (min_wait
* HZ
);
3834 /* wait time before firmware ready */
3835 wtime
= jiffies
+ (wait_time
* HZ
);
3837 /* Wait for ISP to finish LIP */
3838 if (!vha
->flags
.init_done
)
3839 ql_log(ql_log_info
, vha
, 0x801e,
3840 "Waiting for LIP to complete.\n");
3843 memset(state
, -1, sizeof(state
));
3844 rval
= qla2x00_get_firmware_state(vha
, state
);
3845 if (rval
== QLA_SUCCESS
) {
3846 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
3847 vha
->device_flags
&= ~DFLG_NO_CABLE
;
3849 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
3850 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
3851 "fw_state=%x 84xx=%x.\n", state
[0],
3853 if ((state
[2] & FSTATE_LOGGED_IN
) &&
3854 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
3855 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
3856 "Sending verify iocb.\n");
3858 cs84xx_time
= jiffies
;
3859 rval
= qla84xx_init_chip(vha
);
3860 if (rval
!= QLA_SUCCESS
) {
3863 "Init chip failed.\n");
3867 /* Add time taken to initialize. */
3868 cs84xx_time
= jiffies
- cs84xx_time
;
3869 wtime
+= cs84xx_time
;
3870 mtime
+= cs84xx_time
;
3871 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
3872 "Increasing wait time by %ld. "
3873 "New time %ld.\n", cs84xx_time
,
3876 } else if (state
[0] == FSTATE_READY
) {
3877 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
3878 "F/W Ready - OK.\n");
3880 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
3881 &ha
->login_timeout
, &ha
->r_a_tov
);
3887 rval
= QLA_FUNCTION_FAILED
;
3889 if (atomic_read(&vha
->loop_down_timer
) &&
3890 state
[0] != FSTATE_READY
) {
3891 /* Loop down. Timeout on min_wait for states
3892 * other than Wait for Login.
3894 if (time_after_eq(jiffies
, mtime
)) {
3895 ql_log(ql_log_info
, vha
, 0x8038,
3896 "Cable is unplugged...\n");
3898 vha
->device_flags
|= DFLG_NO_CABLE
;
3903 /* Mailbox cmd failed. Timeout on min_wait. */
3904 if (time_after_eq(jiffies
, mtime
) ||
3905 ha
->flags
.isp82xx_fw_hung
)
3909 if (time_after_eq(jiffies
, wtime
))
3912 /* Delay for a while */
3916 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
3917 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state
[0],
3918 state
[1], state
[2], state
[3], state
[4], state
[5], jiffies
);
3920 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
3921 ql_log(ql_log_warn
, vha
, 0x803b,
3922 "Firmware ready **** FAILED ****.\n");
3929 * qla2x00_configure_hba
3930 * Setup adapter context.
3933 * ha = adapter state pointer.
3942 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
3951 char connect_type
[22];
3952 struct qla_hw_data
*ha
= vha
->hw
;
3953 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
3955 unsigned long flags
;
3957 /* Get host addresses. */
3958 rval
= qla2x00_get_adapter_id(vha
,
3959 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
3960 if (rval
!= QLA_SUCCESS
) {
3961 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
3962 IS_CNA_CAPABLE(ha
) ||
3963 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
3964 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
3965 "Loop is in a transition state.\n");
3967 ql_log(ql_log_warn
, vha
, 0x2009,
3968 "Unable to get host loop ID.\n");
3969 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
3970 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
3971 ql_log(ql_log_warn
, vha
, 0x1151,
3972 "Doing link init.\n");
3973 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
3976 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3982 ql_log(ql_log_info
, vha
, 0x200a,
3983 "Cannot get topology - retrying.\n");
3984 return (QLA_FUNCTION_FAILED
);
3987 vha
->loop_id
= loop_id
;
3990 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
3991 ha
->operating_mode
= LOOP
;
3996 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
3997 ha
->current_topology
= ISP_CFG_NL
;
3998 strcpy(connect_type
, "(Loop)");
4002 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
4003 ha
->switch_cap
= sw_cap
;
4004 ha
->current_topology
= ISP_CFG_FL
;
4005 strcpy(connect_type
, "(FL_Port)");
4009 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
4010 ha
->operating_mode
= P2P
;
4011 ha
->current_topology
= ISP_CFG_N
;
4012 strcpy(connect_type
, "(N_Port-to-N_Port)");
4016 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
4017 ha
->switch_cap
= sw_cap
;
4018 ha
->operating_mode
= P2P
;
4019 ha
->current_topology
= ISP_CFG_F
;
4020 strcpy(connect_type
, "(F_Port)");
4024 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
4025 "HBA in unknown topology %x, using NL.\n", topo
);
4026 ha
->current_topology
= ISP_CFG_NL
;
4027 strcpy(connect_type
, "(Loop)");
4031 /* Save Host port and loop ID. */
4032 /* byte order - Big Endian */
4033 id
.b
.domain
= domain
;
4037 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4038 qlt_update_host_map(vha
, id
);
4039 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4041 if (!vha
->flags
.init_done
)
4042 ql_log(ql_log_info
, vha
, 0x2010,
4043 "Topology - %s, Host Loop address 0x%x.\n",
4044 connect_type
, vha
->loop_id
);
4050 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
4055 struct qla_hw_data
*ha
= vha
->hw
;
4056 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
4057 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
4059 if (memcmp(model
, BINZERO
, len
) != 0) {
4060 strncpy(ha
->model_number
, model
, len
);
4061 st
= en
= ha
->model_number
;
4064 if (*en
!= 0x20 && *en
!= 0x00)
4069 index
= (ha
->pdev
->subsystem_device
& 0xff);
4071 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4072 index
< QLA_MODEL_NAMES
)
4073 strncpy(ha
->model_desc
,
4074 qla2x00_model_name
[index
* 2 + 1],
4075 sizeof(ha
->model_desc
) - 1);
4077 index
= (ha
->pdev
->subsystem_device
& 0xff);
4079 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4080 index
< QLA_MODEL_NAMES
) {
4081 strcpy(ha
->model_number
,
4082 qla2x00_model_name
[index
* 2]);
4083 strncpy(ha
->model_desc
,
4084 qla2x00_model_name
[index
* 2 + 1],
4085 sizeof(ha
->model_desc
) - 1);
4087 strcpy(ha
->model_number
, def
);
4090 if (IS_FWI2_CAPABLE(ha
))
4091 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
4092 sizeof(ha
->model_desc
));
4095 /* On sparc systems, obtain port and node WWN from firmware
4098 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
4101 struct qla_hw_data
*ha
= vha
->hw
;
4102 struct pci_dev
*pdev
= ha
->pdev
;
4103 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4107 val
= of_get_property(dp
, "port-wwn", &len
);
4108 if (val
&& len
>= WWN_SIZE
)
4109 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4111 val
= of_get_property(dp
, "node-wwn", &len
);
4112 if (val
&& len
>= WWN_SIZE
)
4113 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4118 * NVRAM configuration for ISP 2xxx
4121 * ha = adapter block pointer.
4124 * initialization control block in response_ring
4125 * host adapters parameters in host adapter block
4131 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
4136 uint8_t *dptr1
, *dptr2
;
4137 struct qla_hw_data
*ha
= vha
->hw
;
4138 init_cb_t
*icb
= ha
->init_cb
;
4139 nvram_t
*nv
= ha
->nvram
;
4140 uint8_t *ptr
= ha
->nvram
;
4141 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4145 /* Determine NVRAM starting address. */
4146 ha
->nvram_size
= sizeof(nvram_t
);
4148 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
4149 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
4150 ha
->nvram_base
= 0x80;
4152 /* Get NVRAM data and calculate checksum. */
4153 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
4154 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
4157 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
4158 "Contents of NVRAM.\n");
4159 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
4160 (uint8_t *)nv
, ha
->nvram_size
);
4162 /* Bad NVRAM data, set defaults parameters. */
4163 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
4164 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
4165 /* Reset NVRAM data. */
4166 ql_log(ql_log_warn
, vha
, 0x0064,
4167 "Inconsistent NVRAM "
4168 "detected: checksum=0x%x id=%c version=0x%x.\n",
4169 chksum
, nv
->id
[0], nv
->nvram_version
);
4170 ql_log(ql_log_warn
, vha
, 0x0065,
4172 "functioning (yet invalid -- WWPN) defaults.\n");
4175 * Set default initialization control block.
4177 memset(nv
, 0, ha
->nvram_size
);
4178 nv
->parameter_block_version
= ICB_VERSION
;
4180 if (IS_QLA23XX(ha
)) {
4181 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4182 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4183 nv
->add_firmware_options
[0] = BIT_5
;
4184 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4185 nv
->frame_payload_size
= 2048;
4186 nv
->special_options
[1] = BIT_7
;
4187 } else if (IS_QLA2200(ha
)) {
4188 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4189 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4190 nv
->add_firmware_options
[0] = BIT_5
;
4191 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4192 nv
->frame_payload_size
= 1024;
4193 } else if (IS_QLA2100(ha
)) {
4194 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
4195 nv
->firmware_options
[1] = BIT_5
;
4196 nv
->frame_payload_size
= 1024;
4199 nv
->max_iocb_allocation
= cpu_to_le16(256);
4200 nv
->execution_throttle
= cpu_to_le16(16);
4201 nv
->retry_count
= 8;
4202 nv
->retry_delay
= 1;
4204 nv
->port_name
[0] = 33;
4205 nv
->port_name
[3] = 224;
4206 nv
->port_name
[4] = 139;
4208 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
4210 nv
->login_timeout
= 4;
4213 * Set default host adapter parameters
4215 nv
->host_p
[1] = BIT_2
;
4216 nv
->reset_delay
= 5;
4217 nv
->port_down_retry_count
= 8;
4218 nv
->max_luns_per_target
= cpu_to_le16(8);
4219 nv
->link_down_timeout
= 60;
4224 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4226 * The SN2 does not provide BIOS emulation which means you can't change
4227 * potentially bogus BIOS settings. Force the use of default settings
4228 * for link rate and frame size. Hope that the rest of the settings
4231 if (ia64_platform_is("sn2")) {
4232 nv
->frame_payload_size
= 2048;
4234 nv
->special_options
[1] = BIT_7
;
4238 /* Reset Initialization control block */
4239 memset(icb
, 0, ha
->init_cb_size
);
4242 * Setup driver NVRAM options.
4244 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
4245 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
4246 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
4247 nv
->firmware_options
[1] &= ~BIT_4
;
4249 if (IS_QLA23XX(ha
)) {
4250 nv
->firmware_options
[0] |= BIT_2
;
4251 nv
->firmware_options
[0] &= ~BIT_3
;
4252 nv
->special_options
[0] &= ~BIT_6
;
4253 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
4255 if (IS_QLA2300(ha
)) {
4256 if (ha
->fb_rev
== FPM_2310
) {
4257 strcpy(ha
->model_number
, "QLA2310");
4259 strcpy(ha
->model_number
, "QLA2300");
4262 qla2x00_set_model_info(vha
, nv
->model_number
,
4263 sizeof(nv
->model_number
), "QLA23xx");
4265 } else if (IS_QLA2200(ha
)) {
4266 nv
->firmware_options
[0] |= BIT_2
;
4268 * 'Point-to-point preferred, else loop' is not a safe
4269 * connection mode setting.
4271 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
4273 /* Force 'loop preferred, else point-to-point'. */
4274 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
4275 nv
->add_firmware_options
[0] |= BIT_5
;
4277 strcpy(ha
->model_number
, "QLA22xx");
4278 } else /*if (IS_QLA2100(ha))*/ {
4279 strcpy(ha
->model_number
, "QLA2100");
4283 * Copy over NVRAM RISC parameter block to initialization control block.
4285 dptr1
= (uint8_t *)icb
;
4286 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
4287 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
4289 *dptr1
++ = *dptr2
++;
4291 /* Copy 2nd half. */
4292 dptr1
= (uint8_t *)icb
->add_firmware_options
;
4293 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
4295 *dptr1
++ = *dptr2
++;
4297 /* Use alternate WWN? */
4298 if (nv
->host_p
[1] & BIT_7
) {
4299 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4300 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4303 /* Prepare nodename */
4304 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
4306 * Firmware will apply the following mask if the nodename was
4309 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4310 icb
->node_name
[0] &= 0xF0;
4314 * Set host adapter parameters.
4318 * BIT_7 in the host-parameters section allows for modification to
4319 * internal driver logging.
4321 if (nv
->host_p
[0] & BIT_7
)
4322 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
4323 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
4324 /* Always load RISC code on non ISP2[12]00 chips. */
4325 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
4326 ha
->flags
.disable_risc_code_load
= 0;
4327 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
4328 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
4329 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
4330 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
4331 ha
->flags
.disable_serdes
= 0;
4333 ha
->operating_mode
=
4334 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4336 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
4337 sizeof(ha
->fw_seriallink_options
));
4339 /* save HBA serial number */
4340 ha
->serial0
= icb
->port_name
[5];
4341 ha
->serial1
= icb
->port_name
[6];
4342 ha
->serial2
= icb
->port_name
[7];
4343 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4344 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4346 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
4348 ha
->retry_count
= nv
->retry_count
;
4350 /* Set minimum login_timeout to 4 seconds. */
4351 if (nv
->login_timeout
!= ql2xlogintimeout
)
4352 nv
->login_timeout
= ql2xlogintimeout
;
4353 if (nv
->login_timeout
< 4)
4354 nv
->login_timeout
= 4;
4355 ha
->login_timeout
= nv
->login_timeout
;
4357 /* Set minimum RATOV to 100 tenths of a second. */
4360 ha
->loop_reset_delay
= nv
->reset_delay
;
4362 /* Link Down Timeout = 0:
4364 * When Port Down timer expires we will start returning
4365 * I/O's to OS with "DID_NO_CONNECT".
4367 * Link Down Timeout != 0:
4369 * The driver waits for the link to come up after link down
4370 * before returning I/Os to OS with "DID_NO_CONNECT".
4372 if (nv
->link_down_timeout
== 0) {
4373 ha
->loop_down_abort_time
=
4374 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4376 ha
->link_down_timeout
= nv
->link_down_timeout
;
4377 ha
->loop_down_abort_time
=
4378 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4382 * Need enough time to try and get the port back.
4384 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
4385 if (qlport_down_retry
)
4386 ha
->port_down_retry_count
= qlport_down_retry
;
4387 /* Set login_retry_count */
4388 ha
->login_retry_count
= nv
->retry_count
;
4389 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
4390 ha
->port_down_retry_count
> 3)
4391 ha
->login_retry_count
= ha
->port_down_retry_count
;
4392 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4393 ha
->login_retry_count
= ha
->port_down_retry_count
;
4394 if (ql2xloginretrycount
)
4395 ha
->login_retry_count
= ql2xloginretrycount
;
4397 icb
->lun_enables
= cpu_to_le16(0);
4398 icb
->command_resource_count
= 0;
4399 icb
->immediate_notify_resource_count
= 0;
4400 icb
->timeout
= cpu_to_le16(0);
4402 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
4404 icb
->firmware_options
[0] &= ~BIT_3
;
4405 icb
->add_firmware_options
[0] &=
4406 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4407 icb
->add_firmware_options
[0] |= BIT_2
;
4408 icb
->response_accumulation_timer
= 3;
4409 icb
->interrupt_delay_timer
= 5;
4411 vha
->flags
.process_response_queue
= 1;
4414 if (!vha
->flags
.init_done
) {
4415 ha
->zio_mode
= icb
->add_firmware_options
[0] &
4416 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4417 ha
->zio_timer
= icb
->interrupt_delay_timer
?
4418 icb
->interrupt_delay_timer
: 2;
4420 icb
->add_firmware_options
[0] &=
4421 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4422 vha
->flags
.process_response_queue
= 0;
4423 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4424 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4426 ql_log(ql_log_info
, vha
, 0x0068,
4427 "ZIO mode %d enabled; timer delay (%d us).\n",
4428 ha
->zio_mode
, ha
->zio_timer
* 100);
4430 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
4431 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
4432 vha
->flags
.process_response_queue
= 1;
4437 ql_log(ql_log_warn
, vha
, 0x0069,
4438 "NVRAM configuration failed.\n");
4444 qla2x00_rport_del(void *data
)
4446 fc_port_t
*fcport
= data
;
4447 struct fc_rport
*rport
;
4448 unsigned long flags
;
4450 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
4451 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
4452 fcport
->drport
= NULL
;
4453 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
4455 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210b,
4456 "%s %8phN. rport %p roles %x\n",
4457 __func__
, fcport
->port_name
, rport
,
4460 fc_remote_port_delete(rport
);
4465 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4467 * @flags: allocation flags
4469 * Returns a pointer to the allocated fcport, or NULL, if none available.
4472 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
4476 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
4480 /* Setup fcport template structure. */
4482 fcport
->port_type
= FCT_UNKNOWN
;
4483 fcport
->loop_id
= FC_NO_LOOP_ID
;
4484 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
4485 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
4487 fcport
->ct_desc
.ct_sns
= dma_alloc_coherent(&vha
->hw
->pdev
->dev
,
4488 sizeof(struct ct_sns_pkt
), &fcport
->ct_desc
.ct_sns_dma
,
4490 fcport
->disc_state
= DSC_DELETED
;
4491 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4492 fcport
->deleted
= QLA_SESS_DELETED
;
4493 fcport
->login_retry
= vha
->hw
->login_retry_count
;
4494 fcport
->login_retry
= 5;
4495 fcport
->logout_on_delete
= 1;
4497 if (!fcport
->ct_desc
.ct_sns
) {
4498 ql_log(ql_log_warn
, vha
, 0xd049,
4499 "Failed to allocate ct_sns request.\n");
4503 INIT_WORK(&fcport
->del_work
, qla24xx_delete_sess_fn
);
4504 INIT_LIST_HEAD(&fcport
->gnl_entry
);
4505 INIT_LIST_HEAD(&fcport
->list
);
4511 qla2x00_free_fcport(fc_port_t
*fcport
)
4513 if (fcport
->ct_desc
.ct_sns
) {
4514 dma_free_coherent(&fcport
->vha
->hw
->pdev
->dev
,
4515 sizeof(struct ct_sns_pkt
), fcport
->ct_desc
.ct_sns
,
4516 fcport
->ct_desc
.ct_sns_dma
);
4518 fcport
->ct_desc
.ct_sns
= NULL
;
4524 * qla2x00_configure_loop
4525 * Updates Fibre Channel Device Database with what is actually on loop.
4528 * ha = adapter block pointer.
4533 * 2 = database was full and device was not configured.
4536 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
4539 unsigned long flags
, save_flags
;
4540 struct qla_hw_data
*ha
= vha
->hw
;
4543 /* Get Initiator ID */
4544 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
4545 rval
= qla2x00_configure_hba(vha
);
4546 if (rval
!= QLA_SUCCESS
) {
4547 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
4548 "Unable to configure HBA.\n");
4553 save_flags
= flags
= vha
->dpc_flags
;
4554 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
4555 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
4558 * If we have both an RSCN and PORT UPDATE pending then handle them
4559 * both at the same time.
4561 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4562 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4564 qla2x00_get_data_rate(vha
);
4566 /* Determine what we need to do */
4567 if (ha
->current_topology
== ISP_CFG_FL
&&
4568 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4570 set_bit(RSCN_UPDATE
, &flags
);
4572 } else if (ha
->current_topology
== ISP_CFG_F
&&
4573 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4575 set_bit(RSCN_UPDATE
, &flags
);
4576 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4578 } else if (ha
->current_topology
== ISP_CFG_N
) {
4579 clear_bit(RSCN_UPDATE
, &flags
);
4580 if (ha
->flags
.rida_fmt2
) {
4581 /* With Rida Format 2, the login is already triggered.
4582 * We know who is on the other side of the wire.
4583 * No need to login to do login to find out or drop into
4584 * qla2x00_configure_local_loop().
4586 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4587 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4589 if (qla_tgt_mode_enabled(vha
)) {
4590 /* allow the other side to start the login */
4591 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4592 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4595 } else if (ha
->current_topology
== ISP_CFG_NL
) {
4596 clear_bit(RSCN_UPDATE
, &flags
);
4597 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4598 } else if (!vha
->flags
.online
||
4599 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
4600 set_bit(RSCN_UPDATE
, &flags
);
4601 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4604 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
4605 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4606 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
4607 "Loop resync needed, failing.\n");
4608 rval
= QLA_FUNCTION_FAILED
;
4610 rval
= qla2x00_configure_local_loop(vha
);
4613 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
4614 if (LOOP_TRANSITION(vha
)) {
4615 ql_dbg(ql_dbg_disc
, vha
, 0x2099,
4616 "Needs RSCN update and loop transition.\n");
4617 rval
= QLA_FUNCTION_FAILED
;
4620 rval
= qla2x00_configure_fabric(vha
);
4623 if (rval
== QLA_SUCCESS
) {
4624 if (atomic_read(&vha
->loop_down_timer
) ||
4625 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4626 rval
= QLA_FUNCTION_FAILED
;
4628 atomic_set(&vha
->loop_state
, LOOP_READY
);
4629 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
4631 ha
->flags
.fw_init_done
= 1;
4634 * Process any ATIO queue entries that came in
4635 * while we weren't online.
4637 if (qla_tgt_mode_enabled(vha
) ||
4638 qla_dual_mode_enabled(vha
)) {
4639 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
)) {
4640 spin_lock_irqsave(&ha
->tgt
.atio_lock
,
4642 qlt_24xx_process_atio_queue(vha
, 0);
4643 spin_unlock_irqrestore(
4644 &ha
->tgt
.atio_lock
, flags
);
4646 spin_lock_irqsave(&ha
->hardware_lock
,
4648 qlt_24xx_process_atio_queue(vha
, 1);
4649 spin_unlock_irqrestore(
4650 &ha
->hardware_lock
, flags
);
4657 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
4658 "%s *** FAILED ***.\n", __func__
);
4660 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
4661 "%s: exiting normally.\n", __func__
);
4664 /* Restore state if a resync event occurred during processing */
4665 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4666 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
4667 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4668 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
4669 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4678 * Updates Fibre Channel Device Database with local loop devices.
4681 * ha = adapter block pointer.
4685 static int qla24xx_n2n_handle_login(struct scsi_qla_host
*vha
,
4688 struct qla_hw_data
*ha
= vha
->hw
;
4689 int res
= QLA_SUCCESS
, rval
;
4690 int greater_wwpn
= 0;
4693 if (ha
->current_topology
!= ISP_CFG_N
)
4696 if (wwn_to_u64(vha
->port_name
) >
4697 wwn_to_u64(vha
->n2n_port_name
)) {
4698 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
4699 "HBA WWPN is greater %llx > target %llx\n",
4700 wwn_to_u64(vha
->port_name
),
4701 wwn_to_u64(vha
->n2n_port_name
));
4703 fcport
->d_id
.b24
= vha
->n2n_id
;
4706 fcport
->loop_id
= vha
->loop_id
;
4707 fcport
->fc4f_nvme
= 0;
4710 ql_dbg(ql_dbg_disc
, vha
, 0x4001,
4711 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4712 fcport
->d_id
.b24
, vha
->loop_id
);
4714 /* Fill in member data. */
4715 if (!greater_wwpn
) {
4716 rval
= qla2x00_get_port_database(vha
, fcport
, 0);
4717 ql_dbg(ql_dbg_disc
, vha
, 0x1051,
4718 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4719 fcport
->current_login_state
, fcport
->last_login_state
,
4720 fcport
->d_id
.b24
, fcport
->loop_id
, rval
);
4722 if (((fcport
->current_login_state
& 0xf) == 0x4) ||
4723 ((fcport
->current_login_state
& 0xf) == 0x6))
4727 if (logged_in
|| greater_wwpn
) {
4728 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
4729 qla_nvme_register_hba(vha
);
4731 /* Set connected N_Port d_id */
4732 if (vha
->flags
.nvme_enabled
)
4733 fcport
->fc4f_nvme
= 1;
4735 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4736 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4737 fcport
->disc_state
= DSC_GNL
;
4738 fcport
->n2n_flag
= 1;
4740 vha
->hw
->flags
.gpsc_supported
= 0;
4743 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
4744 "%s %d PLOGI ELS %8phC\n",
4745 __func__
, __LINE__
, fcport
->port_name
);
4747 res
= qla24xx_els_dcmd2_iocb(vha
, ELS_DCMD_PLOGI
,
4748 fcport
, fcport
->d_id
);
4751 if (res
!= QLA_SUCCESS
) {
4752 ql_log(ql_log_info
, vha
, 0xd04d,
4753 "PLOGI Failed: portid=%06x - retrying\n",
4757 /* State 0x6 means FCP PRLI complete */
4758 if ((fcport
->current_login_state
& 0xf) == 0x6) {
4759 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
4760 "%s %d %8phC post GPDB work\n",
4761 __func__
, __LINE__
, fcport
->port_name
);
4762 fcport
->chip_reset
=
4763 vha
->hw
->base_qpair
->chip_reset
;
4764 qla24xx_post_gpdb_work(vha
, fcport
, 0);
4766 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
4767 "%s %d %8phC post NVMe PRLI\n",
4768 __func__
, __LINE__
, fcport
->port_name
);
4769 qla24xx_post_prli_work(vha
, fcport
);
4773 /* Wait for next database change */
4774 set_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
);
4781 * qla2x00_configure_local_loop
4782 * Updates Fibre Channel Device Database with local loop devices.
4785 * ha = adapter block pointer.
4791 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
4796 fc_port_t
*fcport
, *new_fcport
;
4802 uint8_t domain
, area
, al_pa
;
4803 struct qla_hw_data
*ha
= vha
->hw
;
4804 unsigned long flags
;
4808 entries
= MAX_FIBRE_DEVICES_LOOP
;
4810 /* Get list of logged in devices. */
4811 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
4812 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
4814 if (rval
!= QLA_SUCCESS
)
4815 goto cleanup_allocation
;
4817 ql_dbg(ql_dbg_disc
, vha
, 0x2011,
4818 "Entries in ID list (%d).\n", entries
);
4819 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
4820 (uint8_t *)ha
->gid_list
,
4821 entries
* sizeof(struct gid_list_info
));
4823 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4824 fcport
->scan_state
= QLA_FCPORT_SCAN
;
4827 /* Allocate temporary fcport for any new fcports discovered. */
4828 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4829 if (new_fcport
== NULL
) {
4830 ql_log(ql_log_warn
, vha
, 0x2012,
4831 "Memory allocation failed for fcport.\n");
4832 rval
= QLA_MEMORY_ALLOC_FAILED
;
4833 goto cleanup_allocation
;
4835 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4837 /* Inititae N2N login. */
4838 if (test_and_clear_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
)) {
4839 rval
= qla24xx_n2n_handle_login(vha
, new_fcport
);
4840 if (rval
!= QLA_SUCCESS
)
4841 goto cleanup_allocation
;
4845 /* Add devices to port list. */
4846 id_iter
= (char *)ha
->gid_list
;
4847 for (index
= 0; index
< entries
; index
++) {
4848 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
4849 area
= ((struct gid_list_info
*)id_iter
)->area
;
4850 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
4851 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
4852 loop_id
= (uint16_t)
4853 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
4855 loop_id
= le16_to_cpu(
4856 ((struct gid_list_info
*)id_iter
)->loop_id
);
4857 id_iter
+= ha
->gid_list_info_size
;
4859 /* Bypass reserved domain fields. */
4860 if ((domain
& 0xf0) == 0xf0)
4863 /* Bypass if not same domain and area of adapter. */
4864 if (area
&& domain
&&
4865 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
4868 /* Bypass invalid local loop ID. */
4869 if (loop_id
> LAST_LOCAL_LOOP_ID
)
4872 memset(new_fcport
->port_name
, 0, WWN_SIZE
);
4874 /* Fill in member data. */
4875 new_fcport
->d_id
.b
.domain
= domain
;
4876 new_fcport
->d_id
.b
.area
= area
;
4877 new_fcport
->d_id
.b
.al_pa
= al_pa
;
4878 new_fcport
->loop_id
= loop_id
;
4879 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
4881 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
4882 if (rval2
!= QLA_SUCCESS
) {
4883 ql_dbg(ql_dbg_disc
, vha
, 0x2097,
4884 "Failed to retrieve fcport information "
4885 "-- get_port_database=%x, loop_id=0x%04x.\n",
4886 rval2
, new_fcport
->loop_id
);
4887 /* Skip retry if N2N */
4888 if (ha
->current_topology
!= ISP_CFG_N
) {
4889 ql_dbg(ql_dbg_disc
, vha
, 0x2105,
4890 "Scheduling resync.\n");
4891 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4896 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4897 /* Check for matching device in port list. */
4900 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4901 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
4905 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4906 fcport
->loop_id
= new_fcport
->loop_id
;
4907 fcport
->port_type
= new_fcport
->port_type
;
4908 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
4909 memcpy(fcport
->node_name
, new_fcport
->node_name
,
4911 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4917 /* New device, add to fcports list. */
4918 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
4920 /* Allocate a new replacement fcport. */
4921 fcport
= new_fcport
;
4923 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4925 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4927 if (new_fcport
== NULL
) {
4928 ql_log(ql_log_warn
, vha
, 0xd031,
4929 "Failed to allocate memory for fcport.\n");
4930 rval
= QLA_MEMORY_ALLOC_FAILED
;
4931 goto cleanup_allocation
;
4933 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4934 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4937 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4939 /* Base iIDMA settings on HBA port speed. */
4940 fcport
->fp_speed
= ha
->link_data_rate
;
4945 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4946 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
4949 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
4950 if ((qla_dual_mode_enabled(vha
) ||
4951 qla_ini_mode_enabled(vha
)) &&
4952 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
4953 qla2x00_mark_device_lost(vha
, fcport
,
4954 ql2xplogiabsentdevice
, 0);
4955 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
4956 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
4957 fcport
->port_type
!= FCT_INITIATOR
&&
4958 fcport
->port_type
!= FCT_BROADCAST
) {
4959 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
4960 "%s %d %8phC post del sess\n",
4964 qlt_schedule_sess_for_deletion(fcport
);
4970 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
4971 qla24xx_fcport_handle_login(vha
, fcport
);
4977 if (rval
!= QLA_SUCCESS
) {
4978 ql_dbg(ql_dbg_disc
, vha
, 0x2098,
4979 "Configure local loop error exit: rval=%x.\n", rval
);
4986 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
4989 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
4990 struct qla_hw_data
*ha
= vha
->hw
;
4992 if (!IS_IIDMA_CAPABLE(ha
))
4995 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
4998 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
4999 fcport
->fp_speed
> ha
->link_data_rate
)
5002 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
5004 if (rval
!= QLA_SUCCESS
) {
5005 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
5006 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5007 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
5009 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
5010 "iIDMA adjusted to %s GB/s on %8phN.\n",
5011 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
5016 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5018 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5020 struct fc_rport_identifiers rport_ids
;
5021 struct fc_rport
*rport
;
5022 unsigned long flags
;
5024 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
5025 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
5026 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
5027 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
5028 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5029 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
5031 ql_log(ql_log_warn
, vha
, 0x2006,
5032 "Unable to allocate fc remote port.\n");
5036 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
5037 *((fc_port_t
**)rport
->dd_data
) = fcport
;
5038 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
5040 rport
->supported_classes
= fcport
->supported_classes
;
5042 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5043 if (fcport
->port_type
== FCT_INITIATOR
)
5044 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
5045 if (fcport
->port_type
== FCT_TARGET
)
5046 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
5048 ql_dbg(ql_dbg_disc
, vha
, 0x20ee,
5049 "%s %8phN. rport %p is %s mode\n",
5050 __func__
, fcport
->port_name
, rport
,
5051 (fcport
->port_type
== FCT_TARGET
) ? "tgt" : "ini");
5053 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
5057 * qla2x00_update_fcport
5058 * Updates device on list.
5061 * ha = adapter block pointer.
5062 * fcport = port structure pointer.
5072 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5076 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5079 ql_dbg(ql_dbg_disc
, vha
, 0x20ef, "%s %8phC\n",
5080 __func__
, fcport
->port_name
);
5082 if (IS_QLAFX00(vha
->hw
)) {
5083 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5086 fcport
->login_retry
= 0;
5087 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
5088 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5089 fcport
->deleted
= 0;
5090 fcport
->logout_on_delete
= 1;
5092 if (fcport
->fc4f_nvme
) {
5093 qla_nvme_register_remote(vha
, fcport
);
5097 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5098 qla2x00_iidma_fcport(vha
, fcport
);
5099 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5102 switch (vha
->host
->active_mode
) {
5103 case MODE_INITIATOR
:
5104 qla2x00_reg_remote_port(vha
, fcport
);
5107 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5108 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5109 qlt_fc_port_added(vha
, fcport
);
5112 qla2x00_reg_remote_port(vha
, fcport
);
5113 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5114 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5115 qlt_fc_port_added(vha
, fcport
);
5123 * qla2x00_configure_fabric
5124 * Setup SNS devices with loop ID's.
5127 * ha = adapter block pointer.
5134 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
5138 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5140 LIST_HEAD(new_fcports
);
5141 struct qla_hw_data
*ha
= vha
->hw
;
5144 /* If FL port exists, then SNS is present */
5145 if (IS_FWI2_CAPABLE(ha
))
5146 loop_id
= NPH_F_PORT
;
5148 loop_id
= SNS_FL_PORT
;
5149 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
5150 if (rval
!= QLA_SUCCESS
) {
5151 ql_dbg(ql_dbg_disc
, vha
, 0x20a0,
5152 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5154 vha
->device_flags
&= ~SWITCH_FOUND
;
5155 return (QLA_SUCCESS
);
5157 vha
->device_flags
|= SWITCH_FOUND
;
5160 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
5161 rval
= qla2x00_send_change_request(vha
, 0x3, 0);
5162 if (rval
!= QLA_SUCCESS
)
5163 ql_log(ql_log_warn
, vha
, 0x121,
5164 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5170 qla2x00_mgmt_svr_login(vha
);
5173 if (ql2xfdmienable
&&
5174 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
5175 qla2x00_fdmi_register(vha
);
5177 /* Ensure we are logged into the SNS. */
5178 loop_id
= NPH_SNS_LID(ha
);
5179 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
5180 0xfc, mb
, BIT_1
|BIT_0
);
5181 if (rval
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5182 ql_dbg(ql_dbg_disc
, vha
, 0x20a1,
5183 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5184 loop_id
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7], rval
);
5185 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5188 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
5189 if (qla2x00_rft_id(vha
)) {
5191 ql_dbg(ql_dbg_disc
, vha
, 0x20a2,
5192 "Register FC-4 TYPE failed.\n");
5193 if (test_bit(LOOP_RESYNC_NEEDED
,
5197 if (qla2x00_rff_id(vha
, FC4_TYPE_FCP_SCSI
)) {
5199 ql_dbg(ql_dbg_disc
, vha
, 0x209a,
5200 "Register FC-4 Features failed.\n");
5201 if (test_bit(LOOP_RESYNC_NEEDED
,
5205 if (vha
->flags
.nvme_enabled
) {
5206 if (qla2x00_rff_id(vha
, FC_TYPE_NVME
)) {
5207 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
5208 "Register NVME FC Type Features failed.\n");
5211 if (qla2x00_rnn_id(vha
)) {
5213 ql_dbg(ql_dbg_disc
, vha
, 0x2104,
5214 "Register Node Name failed.\n");
5215 if (test_bit(LOOP_RESYNC_NEEDED
,
5218 } else if (qla2x00_rsnn_nn(vha
)) {
5220 ql_dbg(ql_dbg_disc
, vha
, 0x209b,
5221 "Register Symbolic Node Name failed.\n");
5222 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5228 /* Mark the time right before querying FW for connected ports.
5229 * This process is long, asynchronous and by the time it's done,
5230 * collected information might not be accurate anymore. E.g.
5231 * disconnected port might have re-connected and a brand new
5232 * session has been created. In this case session's generation
5233 * will be newer than discovery_gen. */
5234 qlt_do_generation_tick(vha
, &discovery_gen
);
5236 if (USE_ASYNC_SCAN(ha
)) {
5238 rval
= qla24xx_async_gpnft(vha
, FC4_TYPE_FCP_SCSI
);
5240 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5242 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5243 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5245 rval
= qla2x00_find_all_fabric_devs(vha
);
5247 if (rval
!= QLA_SUCCESS
)
5251 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
5252 qla_nvme_register_hba(vha
);
5255 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
5256 "Configure fabric error exit rval=%d.\n", rval
);
5262 * qla2x00_find_all_fabric_devs
5265 * ha = adapter block pointer.
5266 * dev = database device entry pointer.
5275 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
)
5279 fc_port_t
*fcport
, *new_fcport
;
5284 int first_dev
, last_dev
;
5285 port_id_t wrap
= {}, nxt_d_id
;
5286 struct qla_hw_data
*ha
= vha
->hw
;
5287 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5288 unsigned long flags
;
5292 /* Try GID_PT to get device list, else GAN. */
5294 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
5299 ql_dbg(ql_dbg_disc
, vha
, 0x209c,
5300 "GID_PT allocations failed, fallback on GA_NXT.\n");
5302 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
5303 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
5305 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5307 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
5309 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5311 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
5313 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5315 } else if (qla2x00_gfpn_id(vha
, swl
) != QLA_SUCCESS
) {
5317 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5321 /* If other queries succeeded probe for FC-4 type */
5323 qla2x00_gff_id(vha
, swl
);
5324 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5330 /* Allocate temporary fcport for any new fcports discovered. */
5331 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5332 if (new_fcport
== NULL
) {
5333 ql_log(ql_log_warn
, vha
, 0x209d,
5334 "Failed to allocate memory for fcport.\n");
5335 return (QLA_MEMORY_ALLOC_FAILED
);
5337 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5338 /* Set start port ID scan at adapter ID. */
5342 /* Starting free loop ID. */
5343 loop_id
= ha
->min_external_loopid
;
5344 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
5345 if (qla2x00_is_reserved_id(vha
, loop_id
))
5348 if (ha
->current_topology
== ISP_CFG_FL
&&
5349 (atomic_read(&vha
->loop_down_timer
) ||
5350 LOOP_TRANSITION(vha
))) {
5351 atomic_set(&vha
->loop_down_timer
, 0);
5352 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5353 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5359 wrap
.b24
= new_fcport
->d_id
.b24
;
5361 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
5362 memcpy(new_fcport
->node_name
,
5363 swl
[swl_idx
].node_name
, WWN_SIZE
);
5364 memcpy(new_fcport
->port_name
,
5365 swl
[swl_idx
].port_name
, WWN_SIZE
);
5366 memcpy(new_fcport
->fabric_port_name
,
5367 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
5368 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
5369 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
5371 new_fcport
->nvme_flag
= 0;
5372 new_fcport
->fc4f_nvme
= 0;
5373 if (vha
->flags
.nvme_enabled
&&
5374 swl
[swl_idx
].fc4f_nvme
) {
5375 new_fcport
->fc4f_nvme
=
5376 swl
[swl_idx
].fc4f_nvme
;
5377 ql_log(ql_log_info
, vha
, 0x2131,
5378 "FOUND: NVME port %8phC as FC Type 28h\n",
5379 new_fcport
->port_name
);
5382 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
5388 /* Send GA_NXT to the switch */
5389 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
5390 if (rval
!= QLA_SUCCESS
) {
5391 ql_log(ql_log_warn
, vha
, 0x209e,
5392 "SNS scan failed -- assuming "
5393 "zero-entry result.\n");
5399 /* If wrap on switch device list, exit. */
5401 wrap
.b24
= new_fcport
->d_id
.b24
;
5403 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
5404 ql_dbg(ql_dbg_disc
, vha
, 0x209f,
5405 "Device wrap (%02x%02x%02x).\n",
5406 new_fcport
->d_id
.b
.domain
,
5407 new_fcport
->d_id
.b
.area
,
5408 new_fcport
->d_id
.b
.al_pa
);
5412 /* Bypass if same physical adapter. */
5413 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
5416 /* Bypass virtual ports of the same host. */
5417 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
5420 /* Bypass if same domain and area of adapter. */
5421 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
5422 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
5426 /* Bypass reserved domain fields. */
5427 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
5430 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5431 if (ql2xgffidenable
&&
5432 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
5433 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
5436 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5438 /* Locate matching device in database. */
5440 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5441 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5445 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5449 /* Update port state. */
5450 memcpy(fcport
->fabric_port_name
,
5451 new_fcport
->fabric_port_name
, WWN_SIZE
);
5452 fcport
->fp_speed
= new_fcport
->fp_speed
;
5455 * If address the same and state FCS_ONLINE
5456 * (or in target mode), nothing changed.
5458 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
5459 (atomic_read(&fcport
->state
) == FCS_ONLINE
||
5460 (vha
->host
->active_mode
== MODE_TARGET
))) {
5465 * If device was not a fabric device before.
5467 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
5468 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5469 qla2x00_clear_loop_id(fcport
);
5470 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
5476 * Port ID changed or device was marked to be updated;
5477 * Log it out if still logged in and mark it for
5480 if (qla_tgt_mode_enabled(base_vha
)) {
5481 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf080,
5482 "port changed FC ID, %8phC"
5483 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5485 fcport
->d_id
.b
.domain
,
5486 fcport
->d_id
.b
.area
,
5487 fcport
->d_id
.b
.al_pa
,
5489 new_fcport
->d_id
.b
.domain
,
5490 new_fcport
->d_id
.b
.area
,
5491 new_fcport
->d_id
.b
.al_pa
);
5492 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5496 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5497 fcport
->flags
|= FCF_LOGIN_NEEDED
;
5502 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5505 /* If device was not in our fcports list, then add it. */
5506 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5507 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5509 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5512 /* Allocate a new replacement fcport. */
5513 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
5514 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5515 if (new_fcport
== NULL
) {
5516 ql_log(ql_log_warn
, vha
, 0xd032,
5517 "Memory allocation failed for fcport.\n");
5518 return (QLA_MEMORY_ALLOC_FAILED
);
5520 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5521 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
5524 qla2x00_free_fcport(new_fcport
);
5527 * Logout all previous fabric dev marked lost, except FCP2 devices.
5529 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5530 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5533 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
5534 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
5537 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5538 if ((qla_dual_mode_enabled(vha
) ||
5539 qla_ini_mode_enabled(vha
)) &&
5540 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5541 qla2x00_mark_device_lost(vha
, fcport
,
5542 ql2xplogiabsentdevice
, 0);
5543 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5544 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5545 fcport
->port_type
!= FCT_INITIATOR
&&
5546 fcport
->port_type
!= FCT_BROADCAST
) {
5547 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5548 "%s %d %8phC post del sess\n",
5551 qlt_schedule_sess_for_deletion(fcport
);
5557 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5558 qla24xx_fcport_handle_login(vha
, fcport
);
5564 * qla2x00_find_new_loop_id
5565 * Scan through our port list and find a new usable loop ID.
5568 * ha: adapter state pointer.
5569 * dev: port structure pointer.
5572 * qla2x00 local function return status code.
5578 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
5581 struct qla_hw_data
*ha
= vha
->hw
;
5582 unsigned long flags
= 0;
5586 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5588 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
5590 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
5591 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
5592 dev
->loop_id
= FC_NO_LOOP_ID
;
5593 rval
= QLA_FUNCTION_FAILED
;
5595 set_bit(dev
->loop_id
, ha
->loop_id_map
);
5597 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5599 if (rval
== QLA_SUCCESS
)
5600 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
5601 "Assigning new loopid=%x, portid=%x.\n",
5602 dev
->loop_id
, dev
->d_id
.b24
);
5604 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
5605 "No loop_id's available, portid=%x.\n",
5613 * qla2x00_fabric_login
5614 * Issue fabric login command.
5617 * ha = adapter block pointer.
5618 * device = pointer to FC device type structure.
5621 * 0 - Login successfully
5623 * 2 - Initiator device
5627 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
5628 uint16_t *next_loopid
)
5632 uint16_t tmp_loopid
;
5633 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5634 struct qla_hw_data
*ha
= vha
->hw
;
5640 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
5641 "Trying Fabric Login w/loop id 0x%04x for port "
5643 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5644 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5646 /* Login fcport on switch. */
5647 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
5648 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5649 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
5650 if (rval
!= QLA_SUCCESS
) {
5653 if (mb
[0] == MBS_PORT_ID_USED
) {
5655 * Device has another loop ID. The firmware team
5656 * recommends the driver perform an implicit login with
5657 * the specified ID again. The ID we just used is save
5658 * here so we return with an ID that can be tried by
5662 tmp_loopid
= fcport
->loop_id
;
5663 fcport
->loop_id
= mb
[1];
5665 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
5666 "Fabric Login: port in use - next loop "
5667 "id=0x%04x, port id= %02x%02x%02x.\n",
5668 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5669 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5671 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
5676 /* A retry occurred before. */
5677 *next_loopid
= tmp_loopid
;
5680 * No retry occurred before. Just increment the
5681 * ID value for next login.
5683 *next_loopid
= (fcport
->loop_id
+ 1);
5686 if (mb
[1] & BIT_0
) {
5687 fcport
->port_type
= FCT_INITIATOR
;
5689 fcport
->port_type
= FCT_TARGET
;
5690 if (mb
[1] & BIT_1
) {
5691 fcport
->flags
|= FCF_FCP2_DEVICE
;
5696 fcport
->supported_classes
|= FC_COS_CLASS2
;
5698 fcport
->supported_classes
|= FC_COS_CLASS3
;
5700 if (IS_FWI2_CAPABLE(ha
)) {
5703 FCF_CONF_COMP_SUPPORTED
;
5708 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
5710 * Loop ID already used, try next loop ID.
5713 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
5714 if (rval
!= QLA_SUCCESS
) {
5715 /* Ran out of loop IDs to use */
5718 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
5720 * Firmware possibly timed out during login. If NO
5721 * retries are left to do then the device is declared
5724 *next_loopid
= fcport
->loop_id
;
5725 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5726 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5727 fcport
->d_id
.b
.al_pa
);
5728 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
5734 * unrecoverable / not handled error
5736 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
5737 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5738 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
5739 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
5740 fcport
->loop_id
, jiffies
);
5742 *next_loopid
= fcport
->loop_id
;
5743 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5744 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5745 fcport
->d_id
.b
.al_pa
);
5746 qla2x00_clear_loop_id(fcport
);
5747 fcport
->login_retry
= 0;
5758 * qla2x00_local_device_login
5759 * Issue local device login command.
5762 * ha = adapter block pointer.
5763 * loop_id = loop id of device to login to.
5765 * Returns (Where's the #define!!!!):
5766 * 0 - Login successfully
5771 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5774 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5776 memset(mb
, 0, sizeof(mb
));
5777 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
5778 if (rval
== QLA_SUCCESS
) {
5779 /* Interrogate mailbox registers for any errors */
5780 if (mb
[0] == MBS_COMMAND_ERROR
)
5782 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
5783 /* device not in PCB table */
5791 * qla2x00_loop_resync
5792 * Resync with fibre channel devices.
5795 * ha = adapter block pointer.
5801 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
5803 int rval
= QLA_SUCCESS
;
5805 struct req_que
*req
;
5806 struct rsp_que
*rsp
;
5811 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5812 if (vha
->flags
.online
) {
5813 if (!(rval
= qla2x00_fw_ready(vha
))) {
5814 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5817 if (!IS_QLAFX00(vha
->hw
)) {
5819 * Issue a marker after FW becomes
5822 qla2x00_marker(vha
, req
, rsp
, 0, 0,
5824 vha
->marker_needed
= 0;
5827 /* Remap devices on Loop. */
5828 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5830 if (IS_QLAFX00(vha
->hw
))
5831 qlafx00_configure_devices(vha
);
5833 qla2x00_configure_loop(vha
);
5836 } while (!atomic_read(&vha
->loop_down_timer
) &&
5837 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
5838 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
5843 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
5844 return (QLA_FUNCTION_FAILED
);
5847 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
5848 "%s *** FAILED ***.\n", __func__
);
5854 * qla2x00_perform_loop_resync
5855 * Description: This function will set the appropriate flags and call
5856 * qla2x00_loop_resync. If successful loop will be resynced
5857 * Arguments : scsi_qla_host_t pointer
5858 * returm : Success or Failure
5861 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
5865 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
5866 /*Configure the flags so that resync happens properly*/
5867 atomic_set(&ha
->loop_down_timer
, 0);
5868 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
5869 atomic_set(&ha
->loop_state
, LOOP_UP
);
5870 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
5871 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
5872 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
5874 rval
= qla2x00_loop_resync(ha
);
5876 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
5878 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
5885 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
5888 struct scsi_qla_host
*vha
;
5889 struct qla_hw_data
*ha
= base_vha
->hw
;
5890 unsigned long flags
;
5892 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5893 /* Go with deferred removal of rport references. */
5894 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
5895 atomic_inc(&vha
->vref_count
);
5896 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5897 if (fcport
->drport
&&
5898 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
5899 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5900 qla2x00_rport_del(fcport
);
5902 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5905 atomic_dec(&vha
->vref_count
);
5906 wake_up(&vha
->vref_waitq
);
5908 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5911 /* Assumes idc_lock always held on entry */
5913 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
5915 struct qla_hw_data
*ha
= vha
->hw
;
5916 uint32_t drv_presence
, drv_presence_mask
;
5917 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
5918 uint32_t class_type_mask
= 0x3;
5919 uint16_t fcoe_other_function
= 0xffff, i
;
5921 if (IS_QLA8044(ha
)) {
5922 drv_presence
= qla8044_rd_direct(vha
,
5923 QLA8044_CRB_DRV_ACTIVE_INDEX
);
5924 dev_part_info1
= qla8044_rd_direct(vha
,
5925 QLA8044_CRB_DEV_PART_INFO_INDEX
);
5926 dev_part_info2
= qla8044_rd_direct(vha
,
5927 QLA8044_CRB_DEV_PART_INFO2
);
5929 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
5930 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
5931 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
5933 for (i
= 0; i
< 8; i
++) {
5934 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
5935 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
5936 (i
!= ha
->portnum
)) {
5937 fcoe_other_function
= i
;
5941 if (fcoe_other_function
== 0xffff) {
5942 for (i
= 0; i
< 8; i
++) {
5943 class_type
= ((dev_part_info2
>> (i
* 4)) &
5945 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
5946 ((i
+ 8) != ha
->portnum
)) {
5947 fcoe_other_function
= i
+ 8;
5953 * Prepare drv-presence mask based on fcoe functions present.
5954 * However consider only valid physical fcoe function numbers (0-15).
5956 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
5957 ((fcoe_other_function
== 0xffff) ?
5958 0 : (1 << (fcoe_other_function
))));
5960 /* We are the reset owner iff:
5961 * - No other protocol drivers present.
5962 * - This is the lowest among fcoe functions. */
5963 if (!(drv_presence
& drv_presence_mask
) &&
5964 (ha
->portnum
< fcoe_other_function
)) {
5965 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
5966 "This host is Reset owner.\n");
5967 ha
->flags
.nic_core_reset_owner
= 1;
5972 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
5974 int rval
= QLA_SUCCESS
;
5975 struct qla_hw_data
*ha
= vha
->hw
;
5978 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
5979 if (rval
== QLA_SUCCESS
) {
5980 drv_ack
|= (1 << ha
->portnum
);
5981 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
5988 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
5990 int rval
= QLA_SUCCESS
;
5991 struct qla_hw_data
*ha
= vha
->hw
;
5994 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
5995 if (rval
== QLA_SUCCESS
) {
5996 drv_ack
&= ~(1 << ha
->portnum
);
5997 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6004 qla83xx_dev_state_to_string(uint32_t dev_state
)
6006 switch (dev_state
) {
6007 case QLA8XXX_DEV_COLD
:
6008 return "COLD/RE-INIT";
6009 case QLA8XXX_DEV_INITIALIZING
:
6010 return "INITIALIZING";
6011 case QLA8XXX_DEV_READY
:
6013 case QLA8XXX_DEV_NEED_RESET
:
6014 return "NEED RESET";
6015 case QLA8XXX_DEV_NEED_QUIESCENT
:
6016 return "NEED QUIESCENT";
6017 case QLA8XXX_DEV_FAILED
:
6019 case QLA8XXX_DEV_QUIESCENT
:
6026 /* Assumes idc-lock always held on entry */
6028 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
6030 struct qla_hw_data
*ha
= vha
->hw
;
6031 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
6033 switch (audit_type
) {
6034 case IDC_AUDIT_TIMESTAMP
:
6035 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
6036 idc_audit_reg
= (ha
->portnum
) |
6037 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
6038 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6041 case IDC_AUDIT_COMPLETION
:
6042 duration_secs
= ((jiffies_to_msecs(jiffies
) -
6043 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
6044 idc_audit_reg
= (ha
->portnum
) |
6045 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
6046 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6050 ql_log(ql_log_warn
, vha
, 0xb078,
6051 "Invalid audit type specified.\n");
6056 /* Assumes idc_lock always held on entry */
6058 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
6060 struct qla_hw_data
*ha
= vha
->hw
;
6061 uint32_t idc_control
, dev_state
;
6063 __qla83xx_get_idc_control(vha
, &idc_control
);
6064 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
6065 ql_log(ql_log_info
, vha
, 0xb080,
6066 "NIC Core reset has been disabled. idc-control=0x%x\n",
6068 return QLA_FUNCTION_FAILED
;
6071 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6072 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6073 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
6074 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
6075 QLA8XXX_DEV_NEED_RESET
);
6076 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
6077 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
6079 const char *state
= qla83xx_dev_state_to_string(dev_state
);
6080 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
6082 /* SV: XXX: Is timeout required here? */
6083 /* Wait for IDC state change READY -> NEED_RESET */
6084 while (dev_state
== QLA8XXX_DEV_READY
) {
6085 qla83xx_idc_unlock(vha
, 0);
6087 qla83xx_idc_lock(vha
, 0);
6088 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6092 /* Send IDC ack by writing to drv-ack register */
6093 __qla83xx_set_drv_ack(vha
);
6099 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
6101 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6105 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
6107 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6111 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
6113 uint32_t drv_presence
= 0;
6114 struct qla_hw_data
*ha
= vha
->hw
;
6116 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6117 if (drv_presence
& (1 << ha
->portnum
))
6120 return QLA_TEST_FAILED
;
6124 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
6126 int rval
= QLA_SUCCESS
;
6127 struct qla_hw_data
*ha
= vha
->hw
;
6129 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
6130 "Entered %s().\n", __func__
);
6132 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
6133 ql_log(ql_log_warn
, vha
, 0xb059,
6134 "Device in unrecoverable FAILED state.\n");
6135 return QLA_FUNCTION_FAILED
;
6138 qla83xx_idc_lock(vha
, 0);
6140 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
6141 ql_log(ql_log_warn
, vha
, 0xb05a,
6142 "Function=0x%x has been removed from IDC participation.\n",
6144 rval
= QLA_FUNCTION_FAILED
;
6148 qla83xx_reset_ownership(vha
);
6150 rval
= qla83xx_initiating_reset(vha
);
6153 * Perform reset if we are the reset-owner,
6154 * else wait till IDC state changes to READY/FAILED.
6156 if (rval
== QLA_SUCCESS
) {
6157 rval
= qla83xx_idc_state_handler(vha
);
6159 if (rval
== QLA_SUCCESS
)
6160 ha
->flags
.nic_core_hung
= 0;
6161 __qla83xx_clear_drv_ack(vha
);
6165 qla83xx_idc_unlock(vha
, 0);
6167 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
6173 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
6175 struct qla_hw_data
*ha
= vha
->hw
;
6176 int rval
= QLA_FUNCTION_FAILED
;
6178 if (!IS_MCTP_CAPABLE(ha
)) {
6179 /* This message can be removed from the final version */
6180 ql_log(ql_log_info
, vha
, 0x506d,
6181 "This board is not MCTP capable\n");
6185 if (!ha
->mctp_dump
) {
6186 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
6187 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
6189 if (!ha
->mctp_dump
) {
6190 ql_log(ql_log_warn
, vha
, 0x506e,
6191 "Failed to allocate memory for mctp dump\n");
6196 #define MCTP_DUMP_STR_ADDR 0x00000000
6197 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
6198 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
6199 if (rval
!= QLA_SUCCESS
) {
6200 ql_log(ql_log_warn
, vha
, 0x506f,
6201 "Failed to capture mctp dump\n");
6203 ql_log(ql_log_info
, vha
, 0x5070,
6204 "Mctp dump capture for host (%ld/%p).\n",
6205 vha
->host_no
, ha
->mctp_dump
);
6206 ha
->mctp_dumped
= 1;
6209 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
6210 ha
->flags
.nic_core_reset_hdlr_active
= 1;
6211 rval
= qla83xx_restart_nic_firmware(vha
);
6213 /* NIC Core reset failed. */
6214 ql_log(ql_log_warn
, vha
, 0x5071,
6215 "Failed to restart nic firmware\n");
6217 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
6218 "Restarted NIC firmware successfully.\n");
6219 ha
->flags
.nic_core_reset_hdlr_active
= 0;
6227 * qla2x00_quiesce_io
6228 * Description: This function will block the new I/Os
6229 * Its not aborting any I/Os as context
6230 * is not destroyed during quiescence
6231 * Arguments: scsi_qla_host_t
6235 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
6237 struct qla_hw_data
*ha
= vha
->hw
;
6238 struct scsi_qla_host
*vp
;
6240 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
6241 "Quiescing I/O - ha=%p.\n", ha
);
6243 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
6244 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6245 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6246 qla2x00_mark_all_devices_lost(vha
, 0);
6247 list_for_each_entry(vp
, &ha
->vp_list
, list
)
6248 qla2x00_mark_all_devices_lost(vp
, 0);
6250 if (!atomic_read(&vha
->loop_down_timer
))
6251 atomic_set(&vha
->loop_down_timer
,
6254 /* Wait for pending cmds to complete */
6255 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
6259 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
6261 struct qla_hw_data
*ha
= vha
->hw
;
6262 struct scsi_qla_host
*vp
;
6263 unsigned long flags
;
6267 /* For ISP82XX, driver waits for completion of the commands.
6268 * online flag should be set.
6270 if (!(IS_P3P_TYPE(ha
)))
6271 vha
->flags
.online
= 0;
6272 ha
->flags
.chip_reset_done
= 0;
6273 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6274 vha
->qla_stats
.total_isp_aborts
++;
6276 ql_log(ql_log_info
, vha
, 0x00af,
6277 "Performing ISP error recovery - ha=%p.\n", ha
);
6279 /* For ISP82XX, reset_chip is just disabling interrupts.
6280 * Driver waits for the completion of the commands.
6281 * the interrupts need to be enabled.
6283 if (!(IS_P3P_TYPE(ha
)))
6284 ha
->isp_ops
->reset_chip(vha
);
6287 ha
->flags
.rida_fmt2
= 0;
6288 ha
->flags
.n2n_ae
= 0;
6289 ha
->flags
.lip_ae
= 0;
6290 ha
->current_topology
= 0;
6291 ha
->flags
.fw_started
= 0;
6292 ha
->flags
.fw_init_done
= 0;
6293 ha
->base_qpair
->chip_reset
++;
6294 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6295 if (ha
->queue_pair_map
[i
])
6296 ha
->queue_pair_map
[i
]->chip_reset
=
6297 ha
->base_qpair
->chip_reset
;
6300 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
6301 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6302 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6303 qla2x00_mark_all_devices_lost(vha
, 0);
6305 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6306 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6307 atomic_inc(&vp
->vref_count
);
6308 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6310 qla2x00_mark_all_devices_lost(vp
, 0);
6312 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6313 atomic_dec(&vp
->vref_count
);
6315 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6317 if (!atomic_read(&vha
->loop_down_timer
))
6318 atomic_set(&vha
->loop_down_timer
,
6322 /* Clear all async request states across all VPs. */
6323 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
6324 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6325 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6326 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6327 atomic_inc(&vp
->vref_count
);
6328 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6330 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
6331 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6333 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6334 atomic_dec(&vp
->vref_count
);
6336 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6338 if (!ha
->flags
.eeh_busy
) {
6339 /* Make sure for ISP 82XX IO DMA is complete */
6340 if (IS_P3P_TYPE(ha
)) {
6341 qla82xx_chip_reset_cleanup(vha
);
6342 ql_log(ql_log_info
, vha
, 0x00b4,
6343 "Done chip reset cleanup.\n");
6345 /* Done waiting for pending commands.
6346 * Reset the online flag.
6348 vha
->flags
.online
= 0;
6351 /* Requeue all commands in outstanding command list. */
6352 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6354 /* memory barrier */
6360 * Resets ISP and aborts all outstanding commands.
6363 * ha = adapter block pointer.
6369 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
6373 struct qla_hw_data
*ha
= vha
->hw
;
6374 struct scsi_qla_host
*vp
;
6375 struct req_que
*req
= ha
->req_q_map
[0];
6376 unsigned long flags
;
6378 if (vha
->flags
.online
) {
6379 qla2x00_abort_isp_cleanup(vha
);
6381 if (IS_QLA8031(ha
)) {
6382 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
6383 "Clearing fcoe driver presence.\n");
6384 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
6385 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
6386 "Error while clearing DRV-Presence.\n");
6389 if (unlikely(pci_channel_offline(ha
->pdev
) &&
6390 ha
->flags
.pci_channel_io_perm_failure
)) {
6391 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6396 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
6398 ha
->isp_ops
->nvram_config(vha
);
6400 if (!qla2x00_restart_isp(vha
)) {
6401 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6403 if (!atomic_read(&vha
->loop_down_timer
)) {
6405 * Issue marker command only when we are going
6406 * to start the I/O .
6408 vha
->marker_needed
= 1;
6411 vha
->flags
.online
= 1;
6413 ha
->isp_ops
->enable_intrs(ha
);
6415 ha
->isp_abort_cnt
= 0;
6416 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6418 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
6419 qla2x00_get_fw_version(vha
);
6421 ha
->flags
.fce_enabled
= 1;
6423 fce_calc_size(ha
->fce_bufs
));
6424 rval
= qla2x00_enable_fce_trace(vha
,
6425 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6428 ql_log(ql_log_warn
, vha
, 0x8033,
6429 "Unable to reinitialize FCE "
6431 ha
->flags
.fce_enabled
= 0;
6436 memset(ha
->eft
, 0, EFT_SIZE
);
6437 rval
= qla2x00_enable_eft_trace(vha
,
6438 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6440 ql_log(ql_log_warn
, vha
, 0x8034,
6441 "Unable to reinitialize EFT "
6445 } else { /* failed the ISP abort */
6446 vha
->flags
.online
= 1;
6447 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
6448 if (ha
->isp_abort_cnt
== 0) {
6449 ql_log(ql_log_fatal
, vha
, 0x8035,
6450 "ISP error recover failed - "
6451 "board disabled.\n");
6453 * The next call disables the board
6456 ha
->isp_ops
->reset_adapter(vha
);
6457 vha
->flags
.online
= 0;
6458 clear_bit(ISP_ABORT_RETRY
,
6461 } else { /* schedule another ISP abort */
6462 ha
->isp_abort_cnt
--;
6463 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
6464 "ISP abort - retry remaining %d.\n",
6469 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
6470 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
6471 "ISP error recovery - retrying (%d) "
6472 "more times.\n", ha
->isp_abort_cnt
);
6473 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6481 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
6482 qla2x00_configure_hba(vha
);
6483 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6484 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6486 atomic_inc(&vp
->vref_count
);
6487 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6489 qla2x00_vp_abort_isp(vp
);
6491 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6492 atomic_dec(&vp
->vref_count
);
6495 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6497 if (IS_QLA8031(ha
)) {
6498 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
6499 "Setting back fcoe driver presence.\n");
6500 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
6501 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
6502 "Error while setting DRV-Presence.\n");
6505 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
6513 * qla2x00_restart_isp
6514 * restarts the ISP after a reset
6517 * ha = adapter block pointer.
6523 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
6526 struct qla_hw_data
*ha
= vha
->hw
;
6527 struct req_que
*req
= ha
->req_q_map
[0];
6528 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
6530 /* If firmware needs to be loaded */
6531 if (qla2x00_isp_firmware(vha
)) {
6532 vha
->flags
.online
= 0;
6533 status
= ha
->isp_ops
->chip_diag(vha
);
6535 status
= qla2x00_setup_chip(vha
);
6538 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
6539 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6540 ha
->flags
.chip_reset_done
= 1;
6542 /* Initialize the queues in use */
6543 qla25xx_init_queues(ha
);
6545 status
= qla2x00_fw_ready(vha
);
6547 /* Issue a marker after FW becomes ready. */
6548 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
6549 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6552 /* if no cable then assume it's good */
6553 if ((vha
->device_flags
& DFLG_NO_CABLE
))
6560 qla25xx_init_queues(struct qla_hw_data
*ha
)
6562 struct rsp_que
*rsp
= NULL
;
6563 struct req_que
*req
= NULL
;
6564 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
6568 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
6569 rsp
= ha
->rsp_q_map
[i
];
6570 if (rsp
&& test_bit(i
, ha
->rsp_qid_map
)) {
6571 rsp
->options
&= ~BIT_0
;
6572 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
6573 if (ret
!= QLA_SUCCESS
)
6574 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
6575 "%s Rsp que: %d init failed.\n",
6578 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
6579 "%s Rsp que: %d inited.\n",
6583 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
6584 req
= ha
->req_q_map
[i
];
6585 if (req
&& test_bit(i
, ha
->req_qid_map
)) {
6586 /* Clear outstanding commands array. */
6587 req
->options
&= ~BIT_0
;
6588 ret
= qla25xx_init_req_que(base_vha
, req
);
6589 if (ret
!= QLA_SUCCESS
)
6590 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
6591 "%s Req que: %d init failed.\n",
6594 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
6595 "%s Req que: %d inited.\n",
6603 * qla2x00_reset_adapter
6607 * ha = adapter block pointer.
6610 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
6612 unsigned long flags
= 0;
6613 struct qla_hw_data
*ha
= vha
->hw
;
6614 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
6616 vha
->flags
.online
= 0;
6617 ha
->isp_ops
->disable_intrs(ha
);
6619 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6620 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
6621 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6622 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
6623 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6624 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6628 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
6630 unsigned long flags
= 0;
6631 struct qla_hw_data
*ha
= vha
->hw
;
6632 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
6634 if (IS_P3P_TYPE(ha
))
6637 vha
->flags
.online
= 0;
6638 ha
->isp_ops
->disable_intrs(ha
);
6640 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6641 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
6642 RD_REG_DWORD(®
->hccr
);
6643 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
6644 RD_REG_DWORD(®
->hccr
);
6645 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6647 if (IS_NOPOLLING_TYPE(ha
))
6648 ha
->isp_ops
->enable_intrs(ha
);
6651 /* On sparc systems, obtain port and node WWN from firmware
6654 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
6655 struct nvram_24xx
*nv
)
6658 struct qla_hw_data
*ha
= vha
->hw
;
6659 struct pci_dev
*pdev
= ha
->pdev
;
6660 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
6664 val
= of_get_property(dp
, "port-wwn", &len
);
6665 if (val
&& len
>= WWN_SIZE
)
6666 memcpy(nv
->port_name
, val
, WWN_SIZE
);
6668 val
= of_get_property(dp
, "node-wwn", &len
);
6669 if (val
&& len
>= WWN_SIZE
)
6670 memcpy(nv
->node_name
, val
, WWN_SIZE
);
6675 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
6678 struct init_cb_24xx
*icb
;
6679 struct nvram_24xx
*nv
;
6681 uint8_t *dptr1
, *dptr2
;
6684 struct qla_hw_data
*ha
= vha
->hw
;
6687 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6690 /* Determine NVRAM starting address. */
6691 if (ha
->port_no
== 0) {
6692 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
6693 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
6695 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
6696 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
6699 ha
->nvram_size
= sizeof(struct nvram_24xx
);
6700 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
6702 /* Get VPD data into cache */
6703 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
6704 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
6705 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
6707 /* Get NVRAM data into cache and calculate checksum. */
6708 dptr
= (uint32_t *)nv
;
6709 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
6711 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
6712 chksum
+= le32_to_cpu(*dptr
);
6714 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
6715 "Contents of NVRAM\n");
6716 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
6717 (uint8_t *)nv
, ha
->nvram_size
);
6719 /* Bad NVRAM data, set defaults parameters. */
6720 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
6721 || nv
->id
[3] != ' ' ||
6722 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
6723 /* Reset NVRAM data. */
6724 ql_log(ql_log_warn
, vha
, 0x006b,
6725 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6726 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
6727 ql_log(ql_log_warn
, vha
, 0x006c,
6728 "Falling back to functioning (yet invalid -- WWPN) "
6732 * Set default initialization control block.
6734 memset(nv
, 0, ha
->nvram_size
);
6735 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
6736 nv
->version
= cpu_to_le16(ICB_VERSION
);
6737 nv
->frame_payload_size
= 2048;
6738 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
6739 nv
->exchange_count
= cpu_to_le16(0);
6740 nv
->hard_address
= cpu_to_le16(124);
6741 nv
->port_name
[0] = 0x21;
6742 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
6743 nv
->port_name
[2] = 0x00;
6744 nv
->port_name
[3] = 0xe0;
6745 nv
->port_name
[4] = 0x8b;
6746 nv
->port_name
[5] = 0x1c;
6747 nv
->port_name
[6] = 0x55;
6748 nv
->port_name
[7] = 0x86;
6749 nv
->node_name
[0] = 0x20;
6750 nv
->node_name
[1] = 0x00;
6751 nv
->node_name
[2] = 0x00;
6752 nv
->node_name
[3] = 0xe0;
6753 nv
->node_name
[4] = 0x8b;
6754 nv
->node_name
[5] = 0x1c;
6755 nv
->node_name
[6] = 0x55;
6756 nv
->node_name
[7] = 0x86;
6757 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
6758 nv
->login_retry_count
= cpu_to_le16(8);
6759 nv
->interrupt_delay_timer
= cpu_to_le16(0);
6760 nv
->login_timeout
= cpu_to_le16(0);
6761 nv
->firmware_options_1
=
6762 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
6763 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
6764 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6765 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
6766 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
6767 nv
->efi_parameters
= cpu_to_le32(0);
6768 nv
->reset_delay
= 5;
6769 nv
->max_luns_per_target
= cpu_to_le16(128);
6770 nv
->port_down_retry_count
= cpu_to_le16(30);
6771 nv
->link_down_timeout
= cpu_to_le16(30);
6776 if (qla_tgt_mode_enabled(vha
)) {
6777 /* Don't enable full login after initial LIP */
6778 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6779 /* Don't enable LIP full login for initiator */
6780 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6783 qlt_24xx_config_nvram_stage1(vha
, nv
);
6785 /* Reset Initialization control block */
6786 memset(icb
, 0, ha
->init_cb_size
);
6788 /* Copy 1st segment. */
6789 dptr1
= (uint8_t *)icb
;
6790 dptr2
= (uint8_t *)&nv
->version
;
6791 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
6793 *dptr1
++ = *dptr2
++;
6795 icb
->login_retry_count
= nv
->login_retry_count
;
6796 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
6798 /* Copy 2nd segment. */
6799 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
6800 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
6801 cnt
= (uint8_t *)&icb
->reserved_3
-
6802 (uint8_t *)&icb
->interrupt_delay_timer
;
6804 *dptr1
++ = *dptr2
++;
6807 * Setup driver NVRAM options.
6809 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
6812 qlt_24xx_config_nvram_stage2(vha
, icb
);
6814 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
6815 /* Use alternate WWN? */
6816 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
6817 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
6820 /* Prepare nodename */
6821 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
6823 * Firmware will apply the following mask if the nodename was
6826 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
6827 icb
->node_name
[0] &= 0xF0;
6830 /* Set host adapter parameters. */
6831 ha
->flags
.disable_risc_code_load
= 0;
6832 ha
->flags
.enable_lip_reset
= 0;
6833 ha
->flags
.enable_lip_full_login
=
6834 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
6835 ha
->flags
.enable_target_reset
=
6836 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
6837 ha
->flags
.enable_led_scheme
= 0;
6838 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
6840 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
6841 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
6843 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
6844 sizeof(ha
->fw_seriallink_options24
));
6846 /* save HBA serial number */
6847 ha
->serial0
= icb
->port_name
[5];
6848 ha
->serial1
= icb
->port_name
[6];
6849 ha
->serial2
= icb
->port_name
[7];
6850 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
6851 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
6853 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
6855 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
6857 /* Set minimum login_timeout to 4 seconds. */
6858 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
6859 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
6860 if (le16_to_cpu(nv
->login_timeout
) < 4)
6861 nv
->login_timeout
= cpu_to_le16(4);
6862 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
6864 /* Set minimum RATOV to 100 tenths of a second. */
6867 ha
->loop_reset_delay
= nv
->reset_delay
;
6869 /* Link Down Timeout = 0:
6871 * When Port Down timer expires we will start returning
6872 * I/O's to OS with "DID_NO_CONNECT".
6874 * Link Down Timeout != 0:
6876 * The driver waits for the link to come up after link down
6877 * before returning I/Os to OS with "DID_NO_CONNECT".
6879 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
6880 ha
->loop_down_abort_time
=
6881 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
6883 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
6884 ha
->loop_down_abort_time
=
6885 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
6888 /* Need enough time to try and get the port back. */
6889 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
6890 if (qlport_down_retry
)
6891 ha
->port_down_retry_count
= qlport_down_retry
;
6893 /* Set login_retry_count */
6894 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
6895 if (ha
->port_down_retry_count
==
6896 le16_to_cpu(nv
->port_down_retry_count
) &&
6897 ha
->port_down_retry_count
> 3)
6898 ha
->login_retry_count
= ha
->port_down_retry_count
;
6899 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
6900 ha
->login_retry_count
= ha
->port_down_retry_count
;
6901 if (ql2xloginretrycount
)
6902 ha
->login_retry_count
= ql2xloginretrycount
;
6905 if (!vha
->flags
.init_done
) {
6906 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
6907 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6908 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
6909 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
6911 icb
->firmware_options_2
&= cpu_to_le32(
6912 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
6913 vha
->flags
.process_response_queue
= 0;
6914 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
6915 ha
->zio_mode
= QLA_ZIO_MODE_6
;
6917 ql_log(ql_log_info
, vha
, 0x006f,
6918 "ZIO mode %d enabled; timer delay (%d us).\n",
6919 ha
->zio_mode
, ha
->zio_timer
* 100);
6921 icb
->firmware_options_2
|= cpu_to_le32(
6922 (uint32_t)ha
->zio_mode
);
6923 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
6924 vha
->flags
.process_response_queue
= 1;
6928 ql_log(ql_log_warn
, vha
, 0x0070,
6929 "NVRAM configuration failed.\n");
6934 uint8_t qla27xx_find_valid_image(struct scsi_qla_host
*vha
)
6936 struct qla27xx_image_status pri_image_status
, sec_image_status
;
6937 uint8_t valid_pri_image
, valid_sec_image
;
6939 uint32_t cnt
, chksum
, size
;
6940 struct qla_hw_data
*ha
= vha
->hw
;
6942 valid_pri_image
= valid_sec_image
= 1;
6943 ha
->active_image
= 0;
6944 size
= sizeof(struct qla27xx_image_status
) / sizeof(uint32_t);
6946 if (!ha
->flt_region_img_status_pri
) {
6947 valid_pri_image
= 0;
6948 goto check_sec_image
;
6951 qla24xx_read_flash_data(vha
, (uint32_t *)(&pri_image_status
),
6952 ha
->flt_region_img_status_pri
, size
);
6954 if (pri_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
6955 ql_dbg(ql_dbg_init
, vha
, 0x018b,
6956 "Primary image signature (0x%x) not valid\n",
6957 pri_image_status
.signature
);
6958 valid_pri_image
= 0;
6959 goto check_sec_image
;
6962 wptr
= (uint32_t *)(&pri_image_status
);
6965 for (chksum
= 0; cnt
--; wptr
++)
6966 chksum
+= le32_to_cpu(*wptr
);
6969 ql_dbg(ql_dbg_init
, vha
, 0x018c,
6970 "Checksum validation failed for primary image (0x%x)\n",
6972 valid_pri_image
= 0;
6976 if (!ha
->flt_region_img_status_sec
) {
6977 valid_sec_image
= 0;
6978 goto check_valid_image
;
6981 qla24xx_read_flash_data(vha
, (uint32_t *)(&sec_image_status
),
6982 ha
->flt_region_img_status_sec
, size
);
6984 if (sec_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
6985 ql_dbg(ql_dbg_init
, vha
, 0x018d,
6986 "Secondary image signature(0x%x) not valid\n",
6987 sec_image_status
.signature
);
6988 valid_sec_image
= 0;
6989 goto check_valid_image
;
6992 wptr
= (uint32_t *)(&sec_image_status
);
6994 for (chksum
= 0; cnt
--; wptr
++)
6995 chksum
+= le32_to_cpu(*wptr
);
6997 ql_dbg(ql_dbg_init
, vha
, 0x018e,
6998 "Checksum validation failed for secondary image (0x%x)\n",
7000 valid_sec_image
= 0;
7004 if (valid_pri_image
&& (pri_image_status
.image_status_mask
& 0x1))
7005 ha
->active_image
= QLA27XX_PRIMARY_IMAGE
;
7006 if (valid_sec_image
&& (sec_image_status
.image_status_mask
& 0x1)) {
7007 if (!ha
->active_image
||
7008 pri_image_status
.generation_number
<
7009 sec_image_status
.generation_number
)
7010 ha
->active_image
= QLA27XX_SECONDARY_IMAGE
;
7013 ql_dbg(ql_dbg_init
, vha
, 0x018f, "%s image\n",
7014 ha
->active_image
== 0 ? "default bootld and fw" :
7015 ha
->active_image
== 1 ? "primary" :
7016 ha
->active_image
== 2 ? "secondary" :
7019 return ha
->active_image
;
7023 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
7026 int rval
= QLA_SUCCESS
;
7027 int segments
, fragment
;
7028 uint32_t *dcode
, dlen
;
7032 struct qla_hw_data
*ha
= vha
->hw
;
7033 struct req_que
*req
= ha
->req_q_map
[0];
7035 ql_dbg(ql_dbg_init
, vha
, 0x008b,
7036 "FW: Loading firmware from flash (%x).\n", faddr
);
7040 segments
= FA_RISC_CODE_SEGMENTS
;
7041 dcode
= (uint32_t *)req
->ring
;
7044 if (IS_QLA27XX(ha
) &&
7045 qla27xx_find_valid_image(vha
) == QLA27XX_SECONDARY_IMAGE
)
7046 faddr
= ha
->flt_region_fw_sec
;
7048 /* Validate firmware image by checking version. */
7049 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
7050 for (i
= 0; i
< 4; i
++)
7051 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7052 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7053 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7054 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7056 ql_log(ql_log_fatal
, vha
, 0x008c,
7057 "Unable to verify the integrity of flash firmware "
7059 ql_log(ql_log_fatal
, vha
, 0x008d,
7060 "Firmware data: %08x %08x %08x %08x.\n",
7061 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7063 return QLA_FUNCTION_FAILED
;
7066 while (segments
&& rval
== QLA_SUCCESS
) {
7067 /* Read segment's load information. */
7068 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
7070 risc_addr
= be32_to_cpu(dcode
[2]);
7071 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7072 risc_size
= be32_to_cpu(dcode
[3]);
7075 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7076 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7077 if (dlen
> risc_size
)
7080 ql_dbg(ql_dbg_init
, vha
, 0x008e,
7081 "Loading risc segment@ risc addr %x "
7082 "number of dwords 0x%x offset 0x%x.\n",
7083 risc_addr
, dlen
, faddr
);
7085 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
7086 for (i
= 0; i
< dlen
; i
++)
7087 dcode
[i
] = swab32(dcode
[i
]);
7089 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7092 ql_log(ql_log_fatal
, vha
, 0x008f,
7093 "Failed to load segment %d of firmware.\n",
7095 return QLA_FUNCTION_FAILED
;
7108 if (!IS_QLA27XX(ha
))
7111 if (ha
->fw_dump_template
)
7112 vfree(ha
->fw_dump_template
);
7113 ha
->fw_dump_template
= NULL
;
7114 ha
->fw_dump_template_len
= 0;
7116 ql_dbg(ql_dbg_init
, vha
, 0x0161,
7117 "Loading fwdump template from %x\n", faddr
);
7118 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
7119 risc_size
= be32_to_cpu(dcode
[2]);
7120 ql_dbg(ql_dbg_init
, vha
, 0x0162,
7121 "-> array size %x dwords\n", risc_size
);
7122 if (risc_size
== 0 || risc_size
== ~0)
7123 goto default_template
;
7125 dlen
= (risc_size
- 8) * sizeof(*dcode
);
7126 ql_dbg(ql_dbg_init
, vha
, 0x0163,
7127 "-> template allocating %x bytes...\n", dlen
);
7128 ha
->fw_dump_template
= vmalloc(dlen
);
7129 if (!ha
->fw_dump_template
) {
7130 ql_log(ql_log_warn
, vha
, 0x0164,
7131 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7132 goto default_template
;
7137 dcode
= ha
->fw_dump_template
;
7138 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
7139 for (i
= 0; i
< risc_size
; i
++)
7140 dcode
[i
] = le32_to_cpu(dcode
[i
]);
7142 if (!qla27xx_fwdt_template_valid(dcode
)) {
7143 ql_log(ql_log_warn
, vha
, 0x0165,
7144 "Failed fwdump template validate\n");
7145 goto default_template
;
7148 dlen
= qla27xx_fwdt_template_size(dcode
);
7149 ql_dbg(ql_dbg_init
, vha
, 0x0166,
7150 "-> template size %x bytes\n", dlen
);
7151 if (dlen
> risc_size
* sizeof(*dcode
)) {
7152 ql_log(ql_log_warn
, vha
, 0x0167,
7153 "Failed fwdump template exceeds array by %zx bytes\n",
7154 (size_t)(dlen
- risc_size
* sizeof(*dcode
)));
7155 goto default_template
;
7157 ha
->fw_dump_template_len
= dlen
;
7161 ql_log(ql_log_warn
, vha
, 0x0168, "Using default fwdump template\n");
7162 if (ha
->fw_dump_template
)
7163 vfree(ha
->fw_dump_template
);
7164 ha
->fw_dump_template
= NULL
;
7165 ha
->fw_dump_template_len
= 0;
7167 dlen
= qla27xx_fwdt_template_default_size();
7168 ql_dbg(ql_dbg_init
, vha
, 0x0169,
7169 "-> template allocating %x bytes...\n", dlen
);
7170 ha
->fw_dump_template
= vmalloc(dlen
);
7171 if (!ha
->fw_dump_template
) {
7172 ql_log(ql_log_warn
, vha
, 0x016a,
7173 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7174 goto failed_template
;
7177 dcode
= ha
->fw_dump_template
;
7178 risc_size
= dlen
/ sizeof(*dcode
);
7179 memcpy(dcode
, qla27xx_fwdt_template_default(), dlen
);
7180 for (i
= 0; i
< risc_size
; i
++)
7181 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7183 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7184 ql_log(ql_log_warn
, vha
, 0x016b,
7185 "Failed fwdump template validate\n");
7186 goto failed_template
;
7189 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7190 ql_dbg(ql_dbg_init
, vha
, 0x016c,
7191 "-> template size %x bytes\n", dlen
);
7192 ha
->fw_dump_template_len
= dlen
;
7196 ql_log(ql_log_warn
, vha
, 0x016d, "Failed default fwdump template\n");
7197 if (ha
->fw_dump_template
)
7198 vfree(ha
->fw_dump_template
);
7199 ha
->fw_dump_template
= NULL
;
7200 ha
->fw_dump_template_len
= 0;
7204 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7207 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7211 uint16_t *wcode
, *fwcode
;
7212 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
7213 struct fw_blob
*blob
;
7214 struct qla_hw_data
*ha
= vha
->hw
;
7215 struct req_que
*req
= ha
->req_q_map
[0];
7217 /* Load firmware blob. */
7218 blob
= qla2x00_request_firmware(vha
);
7220 ql_log(ql_log_info
, vha
, 0x0083,
7221 "Firmware image unavailable.\n");
7222 ql_log(ql_log_info
, vha
, 0x0084,
7223 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
7224 return QLA_FUNCTION_FAILED
;
7229 wcode
= (uint16_t *)req
->ring
;
7231 fwcode
= (uint16_t *)blob
->fw
->data
;
7234 /* Validate firmware image by checking version. */
7235 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
7236 ql_log(ql_log_fatal
, vha
, 0x0085,
7237 "Unable to verify integrity of firmware image (%zd).\n",
7239 goto fail_fw_integrity
;
7241 for (i
= 0; i
< 4; i
++)
7242 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
7243 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
7244 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
7245 wcode
[2] == 0 && wcode
[3] == 0)) {
7246 ql_log(ql_log_fatal
, vha
, 0x0086,
7247 "Unable to verify integrity of firmware image.\n");
7248 ql_log(ql_log_fatal
, vha
, 0x0087,
7249 "Firmware data: %04x %04x %04x %04x.\n",
7250 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
7251 goto fail_fw_integrity
;
7255 while (*seg
&& rval
== QLA_SUCCESS
) {
7257 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
7258 risc_size
= be16_to_cpu(fwcode
[3]);
7260 /* Validate firmware image size. */
7261 fwclen
+= risc_size
* sizeof(uint16_t);
7262 if (blob
->fw
->size
< fwclen
) {
7263 ql_log(ql_log_fatal
, vha
, 0x0088,
7264 "Unable to verify integrity of firmware image "
7265 "(%zd).\n", blob
->fw
->size
);
7266 goto fail_fw_integrity
;
7270 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7271 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
7272 if (wlen
> risc_size
)
7274 ql_dbg(ql_dbg_init
, vha
, 0x0089,
7275 "Loading risc segment@ risc addr %x number of "
7276 "words 0x%x.\n", risc_addr
, wlen
);
7278 for (i
= 0; i
< wlen
; i
++)
7279 wcode
[i
] = swab16(fwcode
[i
]);
7281 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7284 ql_log(ql_log_fatal
, vha
, 0x008a,
7285 "Failed to load segment %d of firmware.\n",
7302 return QLA_FUNCTION_FAILED
;
7306 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7309 int segments
, fragment
;
7310 uint32_t *dcode
, dlen
;
7314 struct fw_blob
*blob
;
7315 const uint32_t *fwcode
;
7317 struct qla_hw_data
*ha
= vha
->hw
;
7318 struct req_que
*req
= ha
->req_q_map
[0];
7320 /* Load firmware blob. */
7321 blob
= qla2x00_request_firmware(vha
);
7323 ql_log(ql_log_warn
, vha
, 0x0090,
7324 "Firmware image unavailable.\n");
7325 ql_log(ql_log_warn
, vha
, 0x0091,
7326 "Firmware images can be retrieved from: "
7329 return QLA_FUNCTION_FAILED
;
7332 ql_dbg(ql_dbg_init
, vha
, 0x0092,
7333 "FW: Loading via request-firmware.\n");
7337 segments
= FA_RISC_CODE_SEGMENTS
;
7338 dcode
= (uint32_t *)req
->ring
;
7340 fwcode
= (uint32_t *)blob
->fw
->data
;
7343 /* Validate firmware image by checking version. */
7344 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
7345 ql_log(ql_log_fatal
, vha
, 0x0093,
7346 "Unable to verify integrity of firmware image (%zd).\n",
7348 return QLA_FUNCTION_FAILED
;
7350 for (i
= 0; i
< 4; i
++)
7351 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
7352 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7353 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7354 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7356 ql_log(ql_log_fatal
, vha
, 0x0094,
7357 "Unable to verify integrity of firmware image (%zd).\n",
7359 ql_log(ql_log_fatal
, vha
, 0x0095,
7360 "Firmware data: %08x %08x %08x %08x.\n",
7361 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7362 return QLA_FUNCTION_FAILED
;
7365 while (segments
&& rval
== QLA_SUCCESS
) {
7366 risc_addr
= be32_to_cpu(fwcode
[2]);
7367 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7368 risc_size
= be32_to_cpu(fwcode
[3]);
7370 /* Validate firmware image size. */
7371 fwclen
+= risc_size
* sizeof(uint32_t);
7372 if (blob
->fw
->size
< fwclen
) {
7373 ql_log(ql_log_fatal
, vha
, 0x0096,
7374 "Unable to verify integrity of firmware image "
7375 "(%zd).\n", blob
->fw
->size
);
7376 return QLA_FUNCTION_FAILED
;
7380 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7381 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7382 if (dlen
> risc_size
)
7385 ql_dbg(ql_dbg_init
, vha
, 0x0097,
7386 "Loading risc segment@ risc addr %x "
7387 "number of dwords 0x%x.\n", risc_addr
, dlen
);
7389 for (i
= 0; i
< dlen
; i
++)
7390 dcode
[i
] = swab32(fwcode
[i
]);
7392 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7395 ql_log(ql_log_fatal
, vha
, 0x0098,
7396 "Failed to load segment %d of firmware.\n",
7398 return QLA_FUNCTION_FAILED
;
7411 if (!IS_QLA27XX(ha
))
7414 if (ha
->fw_dump_template
)
7415 vfree(ha
->fw_dump_template
);
7416 ha
->fw_dump_template
= NULL
;
7417 ha
->fw_dump_template_len
= 0;
7419 ql_dbg(ql_dbg_init
, vha
, 0x171,
7420 "Loading fwdump template from %x\n",
7421 (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
));
7422 risc_size
= be32_to_cpu(fwcode
[2]);
7423 ql_dbg(ql_dbg_init
, vha
, 0x172,
7424 "-> array size %x dwords\n", risc_size
);
7425 if (risc_size
== 0 || risc_size
== ~0)
7426 goto default_template
;
7428 dlen
= (risc_size
- 8) * sizeof(*fwcode
);
7429 ql_dbg(ql_dbg_init
, vha
, 0x0173,
7430 "-> template allocating %x bytes...\n", dlen
);
7431 ha
->fw_dump_template
= vmalloc(dlen
);
7432 if (!ha
->fw_dump_template
) {
7433 ql_log(ql_log_warn
, vha
, 0x0174,
7434 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7435 goto default_template
;
7440 dcode
= ha
->fw_dump_template
;
7441 for (i
= 0; i
< risc_size
; i
++)
7442 dcode
[i
] = le32_to_cpu(fwcode
[i
]);
7444 if (!qla27xx_fwdt_template_valid(dcode
)) {
7445 ql_log(ql_log_warn
, vha
, 0x0175,
7446 "Failed fwdump template validate\n");
7447 goto default_template
;
7450 dlen
= qla27xx_fwdt_template_size(dcode
);
7451 ql_dbg(ql_dbg_init
, vha
, 0x0176,
7452 "-> template size %x bytes\n", dlen
);
7453 if (dlen
> risc_size
* sizeof(*fwcode
)) {
7454 ql_log(ql_log_warn
, vha
, 0x0177,
7455 "Failed fwdump template exceeds array by %zx bytes\n",
7456 (size_t)(dlen
- risc_size
* sizeof(*fwcode
)));
7457 goto default_template
;
7459 ha
->fw_dump_template_len
= dlen
;
7463 ql_log(ql_log_warn
, vha
, 0x0178, "Using default fwdump template\n");
7464 if (ha
->fw_dump_template
)
7465 vfree(ha
->fw_dump_template
);
7466 ha
->fw_dump_template
= NULL
;
7467 ha
->fw_dump_template_len
= 0;
7469 dlen
= qla27xx_fwdt_template_default_size();
7470 ql_dbg(ql_dbg_init
, vha
, 0x0179,
7471 "-> template allocating %x bytes...\n", dlen
);
7472 ha
->fw_dump_template
= vmalloc(dlen
);
7473 if (!ha
->fw_dump_template
) {
7474 ql_log(ql_log_warn
, vha
, 0x017a,
7475 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7476 goto failed_template
;
7479 dcode
= ha
->fw_dump_template
;
7480 risc_size
= dlen
/ sizeof(*fwcode
);
7481 fwcode
= qla27xx_fwdt_template_default();
7482 for (i
= 0; i
< risc_size
; i
++)
7483 dcode
[i
] = be32_to_cpu(fwcode
[i
]);
7485 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7486 ql_log(ql_log_warn
, vha
, 0x017b,
7487 "Failed fwdump template validate\n");
7488 goto failed_template
;
7491 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7492 ql_dbg(ql_dbg_init
, vha
, 0x017c,
7493 "-> template size %x bytes\n", dlen
);
7494 ha
->fw_dump_template_len
= dlen
;
7498 ql_log(ql_log_warn
, vha
, 0x017d, "Failed default fwdump template\n");
7499 if (ha
->fw_dump_template
)
7500 vfree(ha
->fw_dump_template
);
7501 ha
->fw_dump_template
= NULL
;
7502 ha
->fw_dump_template_len
= 0;
7507 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7511 if (ql2xfwloadbin
== 1)
7512 return qla81xx_load_risc(vha
, srisc_addr
);
7516 * 1) Firmware via request-firmware interface (.bin file).
7517 * 2) Firmware residing in flash.
7519 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7520 if (rval
== QLA_SUCCESS
)
7523 return qla24xx_load_risc_flash(vha
, srisc_addr
,
7524 vha
->hw
->flt_region_fw
);
7528 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7531 struct qla_hw_data
*ha
= vha
->hw
;
7533 if (ql2xfwloadbin
== 2)
7538 * 1) Firmware residing in flash.
7539 * 2) Firmware via request-firmware interface (.bin file).
7540 * 3) Golden-Firmware residing in flash -- limited operation.
7542 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
7543 if (rval
== QLA_SUCCESS
)
7547 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7548 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
7551 ql_log(ql_log_info
, vha
, 0x0099,
7552 "Attempting to fallback to golden firmware.\n");
7553 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
7554 if (rval
!= QLA_SUCCESS
)
7557 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
7558 ha
->flags
.running_gold_fw
= 1;
7563 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
7566 struct qla_hw_data
*ha
= vha
->hw
;
7568 if (ha
->flags
.pci_channel_io_perm_failure
)
7570 if (!IS_FWI2_CAPABLE(ha
))
7572 if (!ha
->fw_major_version
)
7574 if (!ha
->flags
.fw_started
)
7577 ret
= qla2x00_stop_firmware(vha
);
7578 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
7579 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
7580 ha
->isp_ops
->reset_chip(vha
);
7581 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
7583 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
7585 ql_log(ql_log_info
, vha
, 0x8015,
7586 "Attempting retry of stop-firmware command.\n");
7587 ret
= qla2x00_stop_firmware(vha
);
7591 ha
->flags
.fw_init_done
= 0;
7595 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
7597 int rval
= QLA_SUCCESS
;
7599 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
7600 struct qla_hw_data
*ha
= vha
->hw
;
7601 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
7602 struct req_que
*req
;
7603 struct rsp_que
*rsp
;
7608 rval
= qla2x00_fw_ready(base_vha
);
7610 req
= vha
->qpair
->req
;
7612 req
= ha
->req_q_map
[0];
7615 if (rval
== QLA_SUCCESS
) {
7616 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
7617 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
7620 vha
->flags
.management_server_logged_in
= 0;
7622 /* Login to SNS first */
7623 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
7625 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
7626 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
7627 ql_dbg(ql_dbg_init
, vha
, 0x0120,
7628 "Failed SNS login: loop_id=%x, rval2=%d\n",
7631 ql_dbg(ql_dbg_init
, vha
, 0x0103,
7632 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7633 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7634 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
7635 return (QLA_FUNCTION_FAILED
);
7638 atomic_set(&vha
->loop_down_timer
, 0);
7639 atomic_set(&vha
->loop_state
, LOOP_UP
);
7640 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
7641 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
7642 rval
= qla2x00_loop_resync(base_vha
);
7647 /* 84XX Support **************************************************************/
7649 static LIST_HEAD(qla_cs84xx_list
);
7650 static DEFINE_MUTEX(qla_cs84xx_mutex
);
7652 static struct qla_chip_state_84xx
*
7653 qla84xx_get_chip(struct scsi_qla_host
*vha
)
7655 struct qla_chip_state_84xx
*cs84xx
;
7656 struct qla_hw_data
*ha
= vha
->hw
;
7658 mutex_lock(&qla_cs84xx_mutex
);
7660 /* Find any shared 84xx chip. */
7661 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
7662 if (cs84xx
->bus
== ha
->pdev
->bus
) {
7663 kref_get(&cs84xx
->kref
);
7668 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
7672 kref_init(&cs84xx
->kref
);
7673 spin_lock_init(&cs84xx
->access_lock
);
7674 mutex_init(&cs84xx
->fw_update_mutex
);
7675 cs84xx
->bus
= ha
->pdev
->bus
;
7677 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
7679 mutex_unlock(&qla_cs84xx_mutex
);
7684 __qla84xx_chip_release(struct kref
*kref
)
7686 struct qla_chip_state_84xx
*cs84xx
=
7687 container_of(kref
, struct qla_chip_state_84xx
, kref
);
7689 mutex_lock(&qla_cs84xx_mutex
);
7690 list_del(&cs84xx
->list
);
7691 mutex_unlock(&qla_cs84xx_mutex
);
7696 qla84xx_put_chip(struct scsi_qla_host
*vha
)
7698 struct qla_hw_data
*ha
= vha
->hw
;
7700 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
7704 qla84xx_init_chip(scsi_qla_host_t
*vha
)
7708 struct qla_hw_data
*ha
= vha
->hw
;
7710 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
7712 rval
= qla84xx_verify_chip(vha
, status
);
7714 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
7716 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
7720 /* 81XX Support **************************************************************/
7723 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
7726 struct init_cb_81xx
*icb
;
7727 struct nvram_81xx
*nv
;
7729 uint8_t *dptr1
, *dptr2
;
7732 struct qla_hw_data
*ha
= vha
->hw
;
7735 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
7738 /* Determine NVRAM starting address. */
7739 ha
->nvram_size
= sizeof(struct nvram_81xx
);
7740 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
7741 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
7742 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
7744 /* Get VPD data into cache */
7745 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
7746 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
7749 /* Get NVRAM data into cache and calculate checksum. */
7750 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
7752 dptr
= (uint32_t *)nv
;
7753 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
7754 chksum
+= le32_to_cpu(*dptr
);
7756 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
7757 "Contents of NVRAM:\n");
7758 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
7759 (uint8_t *)nv
, ha
->nvram_size
);
7761 /* Bad NVRAM data, set defaults parameters. */
7762 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
7763 || nv
->id
[3] != ' ' ||
7764 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
7765 /* Reset NVRAM data. */
7766 ql_log(ql_log_info
, vha
, 0x0073,
7767 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7768 "version=0x%x.\n", chksum
, nv
->id
[0],
7769 le16_to_cpu(nv
->nvram_version
));
7770 ql_log(ql_log_info
, vha
, 0x0074,
7771 "Falling back to functioning (yet invalid -- WWPN) "
7775 * Set default initialization control block.
7777 memset(nv
, 0, ha
->nvram_size
);
7778 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
7779 nv
->version
= cpu_to_le16(ICB_VERSION
);
7780 nv
->frame_payload_size
= 2048;
7781 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
7782 nv
->exchange_count
= cpu_to_le16(0);
7783 nv
->port_name
[0] = 0x21;
7784 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
7785 nv
->port_name
[2] = 0x00;
7786 nv
->port_name
[3] = 0xe0;
7787 nv
->port_name
[4] = 0x8b;
7788 nv
->port_name
[5] = 0x1c;
7789 nv
->port_name
[6] = 0x55;
7790 nv
->port_name
[7] = 0x86;
7791 nv
->node_name
[0] = 0x20;
7792 nv
->node_name
[1] = 0x00;
7793 nv
->node_name
[2] = 0x00;
7794 nv
->node_name
[3] = 0xe0;
7795 nv
->node_name
[4] = 0x8b;
7796 nv
->node_name
[5] = 0x1c;
7797 nv
->node_name
[6] = 0x55;
7798 nv
->node_name
[7] = 0x86;
7799 nv
->login_retry_count
= cpu_to_le16(8);
7800 nv
->interrupt_delay_timer
= cpu_to_le16(0);
7801 nv
->login_timeout
= cpu_to_le16(0);
7802 nv
->firmware_options_1
=
7803 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
7804 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
7805 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
7806 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
7807 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
7808 nv
->efi_parameters
= cpu_to_le32(0);
7809 nv
->reset_delay
= 5;
7810 nv
->max_luns_per_target
= cpu_to_le16(128);
7811 nv
->port_down_retry_count
= cpu_to_le16(30);
7812 nv
->link_down_timeout
= cpu_to_le16(180);
7813 nv
->enode_mac
[0] = 0x00;
7814 nv
->enode_mac
[1] = 0xC0;
7815 nv
->enode_mac
[2] = 0xDD;
7816 nv
->enode_mac
[3] = 0x04;
7817 nv
->enode_mac
[4] = 0x05;
7818 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
7823 if (IS_T10_PI_CAPABLE(ha
))
7824 nv
->frame_payload_size
&= ~7;
7826 qlt_81xx_config_nvram_stage1(vha
, nv
);
7828 /* Reset Initialization control block */
7829 memset(icb
, 0, ha
->init_cb_size
);
7831 /* Copy 1st segment. */
7832 dptr1
= (uint8_t *)icb
;
7833 dptr2
= (uint8_t *)&nv
->version
;
7834 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
7836 *dptr1
++ = *dptr2
++;
7838 icb
->login_retry_count
= nv
->login_retry_count
;
7840 /* Copy 2nd segment. */
7841 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
7842 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
7843 cnt
= (uint8_t *)&icb
->reserved_5
-
7844 (uint8_t *)&icb
->interrupt_delay_timer
;
7846 *dptr1
++ = *dptr2
++;
7848 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
7849 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7850 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
7851 icb
->enode_mac
[0] = 0x00;
7852 icb
->enode_mac
[1] = 0xC0;
7853 icb
->enode_mac
[2] = 0xDD;
7854 icb
->enode_mac
[3] = 0x04;
7855 icb
->enode_mac
[4] = 0x05;
7856 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
7859 /* Use extended-initialization control block. */
7860 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
7863 * Setup driver NVRAM options.
7865 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
7868 qlt_81xx_config_nvram_stage2(vha
, icb
);
7870 /* Use alternate WWN? */
7871 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
7872 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
7873 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
7876 /* Prepare nodename */
7877 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
7879 * Firmware will apply the following mask if the nodename was
7882 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
7883 icb
->node_name
[0] &= 0xF0;
7886 /* Set host adapter parameters. */
7887 ha
->flags
.disable_risc_code_load
= 0;
7888 ha
->flags
.enable_lip_reset
= 0;
7889 ha
->flags
.enable_lip_full_login
=
7890 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
7891 ha
->flags
.enable_target_reset
=
7892 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
7893 ha
->flags
.enable_led_scheme
= 0;
7894 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
7896 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
7897 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
7899 /* save HBA serial number */
7900 ha
->serial0
= icb
->port_name
[5];
7901 ha
->serial1
= icb
->port_name
[6];
7902 ha
->serial2
= icb
->port_name
[7];
7903 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
7904 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
7906 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
7908 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
7910 /* Set minimum login_timeout to 4 seconds. */
7911 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
7912 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
7913 if (le16_to_cpu(nv
->login_timeout
) < 4)
7914 nv
->login_timeout
= cpu_to_le16(4);
7915 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
7917 /* Set minimum RATOV to 100 tenths of a second. */
7920 ha
->loop_reset_delay
= nv
->reset_delay
;
7922 /* Link Down Timeout = 0:
7924 * When Port Down timer expires we will start returning
7925 * I/O's to OS with "DID_NO_CONNECT".
7927 * Link Down Timeout != 0:
7929 * The driver waits for the link to come up after link down
7930 * before returning I/Os to OS with "DID_NO_CONNECT".
7932 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
7933 ha
->loop_down_abort_time
=
7934 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
7936 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
7937 ha
->loop_down_abort_time
=
7938 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
7941 /* Need enough time to try and get the port back. */
7942 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
7943 if (qlport_down_retry
)
7944 ha
->port_down_retry_count
= qlport_down_retry
;
7946 /* Set login_retry_count */
7947 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
7948 if (ha
->port_down_retry_count
==
7949 le16_to_cpu(nv
->port_down_retry_count
) &&
7950 ha
->port_down_retry_count
> 3)
7951 ha
->login_retry_count
= ha
->port_down_retry_count
;
7952 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
7953 ha
->login_retry_count
= ha
->port_down_retry_count
;
7954 if (ql2xloginretrycount
)
7955 ha
->login_retry_count
= ql2xloginretrycount
;
7957 /* if not running MSI-X we need handshaking on interrupts */
7958 if (!vha
->hw
->flags
.msix_enabled
&& (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)))
7959 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
7962 if (!vha
->flags
.init_done
) {
7963 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
7964 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
7965 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
7966 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
7968 icb
->firmware_options_2
&= cpu_to_le32(
7969 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
7970 vha
->flags
.process_response_queue
= 0;
7971 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
7972 ha
->zio_mode
= QLA_ZIO_MODE_6
;
7974 ql_log(ql_log_info
, vha
, 0x0075,
7975 "ZIO mode %d enabled; timer delay (%d us).\n",
7977 ha
->zio_timer
* 100);
7979 icb
->firmware_options_2
|= cpu_to_le32(
7980 (uint32_t)ha
->zio_mode
);
7981 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
7982 vha
->flags
.process_response_queue
= 1;
7985 /* enable RIDA Format2 */
7986 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
7987 icb
->firmware_options_3
|= BIT_0
;
7989 if (IS_QLA27XX(ha
)) {
7990 icb
->firmware_options_3
|= BIT_8
;
7991 ql_dbg(ql_log_info
, vha
, 0x0075,
7992 "Enabling direct connection.\n");
7996 ql_log(ql_log_warn
, vha
, 0x0076,
7997 "NVRAM configuration failed.\n");
8003 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
8006 struct qla_hw_data
*ha
= vha
->hw
;
8007 struct req_que
*req
= ha
->req_q_map
[0];
8008 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
8009 struct scsi_qla_host
*vp
;
8010 unsigned long flags
;
8012 status
= qla2x00_init_rings(vha
);
8014 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8015 ha
->flags
.chip_reset_done
= 1;
8017 status
= qla2x00_fw_ready(vha
);
8019 /* Issue a marker after FW becomes ready. */
8020 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
8021 vha
->flags
.online
= 1;
8022 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8025 /* if no cable then assume it's good */
8026 if ((vha
->device_flags
& DFLG_NO_CABLE
))
8031 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8033 if (!atomic_read(&vha
->loop_down_timer
)) {
8035 * Issue marker command only when we are going
8036 * to start the I/O .
8038 vha
->marker_needed
= 1;
8041 ha
->isp_ops
->enable_intrs(ha
);
8043 ha
->isp_abort_cnt
= 0;
8044 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
8046 /* Update the firmware version */
8047 status
= qla82xx_check_md_needed(vha
);
8050 ha
->flags
.fce_enabled
= 1;
8052 fce_calc_size(ha
->fce_bufs
));
8053 rval
= qla2x00_enable_fce_trace(vha
,
8054 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
8057 ql_log(ql_log_warn
, vha
, 0x8001,
8058 "Unable to reinitialize FCE (%d).\n",
8060 ha
->flags
.fce_enabled
= 0;
8065 memset(ha
->eft
, 0, EFT_SIZE
);
8066 rval
= qla2x00_enable_eft_trace(vha
,
8067 ha
->eft_dma
, EFT_NUM_BUFFERS
);
8069 ql_log(ql_log_warn
, vha
, 0x8010,
8070 "Unable to reinitialize EFT (%d).\n",
8077 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
8078 "qla82xx_restart_isp succeeded.\n");
8080 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8081 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
8083 atomic_inc(&vp
->vref_count
);
8084 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8086 qla2x00_vp_abort_isp(vp
);
8088 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8089 atomic_dec(&vp
->vref_count
);
8092 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8095 ql_log(ql_log_warn
, vha
, 0x8016,
8096 "qla82xx_restart_isp **** FAILED ****.\n");
8103 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
8105 struct qla_hw_data
*ha
= vha
->hw
;
8107 /* Hold status IOCBs until ABTS response received. */
8109 ha
->fw_options
[3] |= BIT_12
;
8111 /* Set Retry FLOGI in case of P2P connection */
8112 if (ha
->operating_mode
== P2P
) {
8113 ha
->fw_options
[2] |= BIT_3
;
8114 ql_dbg(ql_dbg_disc
, vha
, 0x2103,
8115 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8116 __func__
, ha
->fw_options
[2]);
8119 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8120 if (ql2xmvasynctoatio
) {
8121 if (qla_tgt_mode_enabled(vha
) ||
8122 qla_dual_mode_enabled(vha
))
8123 ha
->fw_options
[2] |= BIT_11
;
8125 ha
->fw_options
[2] &= ~BIT_11
;
8128 if (qla_tgt_mode_enabled(vha
) ||
8129 qla_dual_mode_enabled(vha
)) {
8130 /* FW auto send SCSI status during */
8131 ha
->fw_options
[1] |= BIT_8
;
8132 ha
->fw_options
[10] |= (u16
)SAM_STAT_BUSY
<< 8;
8134 /* FW perform Exchange validation */
8135 ha
->fw_options
[2] |= BIT_4
;
8137 ha
->fw_options
[1] &= ~BIT_8
;
8138 ha
->fw_options
[10] &= 0x00ff;
8140 ha
->fw_options
[2] &= ~BIT_4
;
8143 if (ql2xetsenable
) {
8144 /* Enable ETS Burst. */
8145 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
8146 ha
->fw_options
[2] |= BIT_9
;
8149 ql_dbg(ql_dbg_init
, vha
, 0x00e9,
8150 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8151 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
8152 ha
->fw_options
[3], vha
->host
->active_mode
);
8154 qla2x00_set_fw_options(vha
, ha
->fw_options
);
8158 * qla24xx_get_fcp_prio
8159 * Gets the fcp cmd priority value for the logged in port.
8160 * Looks for a match of the port descriptors within
8161 * each of the fcp prio config entries. If a match is found,
8162 * the tag (priority) value is returned.
8165 * vha = scsi host structure pointer.
8166 * fcport = port structure pointer.
8169 * non-zero (if found)
8176 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8179 uint8_t pid_match
, wwn_match
;
8181 uint32_t pid1
, pid2
;
8182 uint64_t wwn1
, wwn2
;
8183 struct qla_fcp_prio_entry
*pri_entry
;
8184 struct qla_hw_data
*ha
= vha
->hw
;
8186 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
8190 entries
= ha
->fcp_prio_cfg
->num_entries
;
8191 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
8193 for (i
= 0; i
< entries
; i
++) {
8194 pid_match
= wwn_match
= 0;
8196 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
8201 /* check source pid for a match */
8202 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
8203 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
8204 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
8205 if (pid1
== INVALID_PORT_ID
)
8207 else if (pid1
== pid2
)
8211 /* check destination pid for a match */
8212 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
8213 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
8214 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
8215 if (pid1
== INVALID_PORT_ID
)
8217 else if (pid1
== pid2
)
8221 /* check source WWN for a match */
8222 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
8223 wwn1
= wwn_to_u64(vha
->port_name
);
8224 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
8225 if (wwn2
== (uint64_t)-1)
8227 else if (wwn1
== wwn2
)
8231 /* check destination WWN for a match */
8232 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
8233 wwn1
= wwn_to_u64(fcport
->port_name
);
8234 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
8235 if (wwn2
== (uint64_t)-1)
8237 else if (wwn1
== wwn2
)
8241 if (pid_match
== 2 || wwn_match
== 2) {
8242 /* Found a matching entry */
8243 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
8244 priority
= pri_entry
->tag
;
8255 * qla24xx_update_fcport_fcp_prio
8256 * Activates fcp priority for the logged in fc port
8259 * vha = scsi host structure pointer.
8260 * fcp = port structure pointer.
8263 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8269 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8275 if (fcport
->port_type
!= FCT_TARGET
||
8276 fcport
->loop_id
== FC_NO_LOOP_ID
)
8277 return QLA_FUNCTION_FAILED
;
8279 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
8281 return QLA_FUNCTION_FAILED
;
8283 if (IS_P3P_TYPE(vha
->hw
)) {
8284 fcport
->fcp_prio
= priority
& 0xf;
8288 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
8289 if (ret
== QLA_SUCCESS
) {
8290 if (fcport
->fcp_prio
!= priority
)
8291 ql_dbg(ql_dbg_user
, vha
, 0x709e,
8292 "Updated FCP_CMND priority - value=%d loop_id=%d "
8293 "port_id=%02x%02x%02x.\n", priority
,
8294 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
8295 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
8296 fcport
->fcp_prio
= priority
& 0xf;
8298 ql_dbg(ql_dbg_user
, vha
, 0x704f,
8299 "Unable to update FCP_CMND priority - ret=0x%x for "
8300 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
8301 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
8302 fcport
->d_id
.b
.al_pa
);
8307 * qla24xx_update_all_fcp_prio
8308 * Activates fcp priority for all the logged in ports
8311 * ha = adapter block pointer.
8314 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8320 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
8325 ret
= QLA_FUNCTION_FAILED
;
8326 /* We need to set priority for all logged in ports */
8327 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
8328 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);
8333 struct qla_qpair
*qla2xxx_create_qpair(struct scsi_qla_host
*vha
, int qos
,
8334 int vp_idx
, bool startqp
)
8339 struct qla_hw_data
*ha
= vha
->hw
;
8340 uint16_t qpair_id
= 0;
8341 struct qla_qpair
*qpair
= NULL
;
8342 struct qla_msix_entry
*msix
;
8344 if (!(ha
->fw_attributes
& BIT_6
) || !ha
->flags
.msix_enabled
) {
8345 ql_log(ql_log_warn
, vha
, 0x00181,
8346 "FW/Driver is not multi-queue capable.\n");
8350 if (ql2xmqsupport
|| ql2xnvmeenable
) {
8351 qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
8352 if (qpair
== NULL
) {
8353 ql_log(ql_log_warn
, vha
, 0x0182,
8354 "Failed to allocate memory for queue pair.\n");
8357 memset(qpair
, 0, sizeof(struct qla_qpair
));
8359 qpair
->hw
= vha
->hw
;
8361 qpair
->qp_lock_ptr
= &qpair
->qp_lock
;
8362 spin_lock_init(&qpair
->qp_lock
);
8363 qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
8365 /* Assign available que pair id */
8366 mutex_lock(&ha
->mq_lock
);
8367 qpair_id
= find_first_zero_bit(ha
->qpair_qid_map
, ha
->max_qpairs
);
8368 if (ha
->num_qpairs
>= ha
->max_qpairs
) {
8369 mutex_unlock(&ha
->mq_lock
);
8370 ql_log(ql_log_warn
, vha
, 0x0183,
8371 "No resources to create additional q pair.\n");
8375 set_bit(qpair_id
, ha
->qpair_qid_map
);
8376 ha
->queue_pair_map
[qpair_id
] = qpair
;
8377 qpair
->id
= qpair_id
;
8378 qpair
->vp_idx
= vp_idx
;
8379 qpair
->fw_started
= ha
->flags
.fw_started
;
8380 INIT_LIST_HEAD(&qpair
->hints_list
);
8381 INIT_LIST_HEAD(&qpair
->nvme_done_list
);
8382 qpair
->chip_reset
= ha
->base_qpair
->chip_reset
;
8383 qpair
->enable_class_2
= ha
->base_qpair
->enable_class_2
;
8384 qpair
->enable_explicit_conf
=
8385 ha
->base_qpair
->enable_explicit_conf
;
8387 for (i
= 0; i
< ha
->msix_count
; i
++) {
8388 msix
= &ha
->msix_entries
[i
];
8392 ql_dbg(ql_dbg_multiq
, vha
, 0xc00f,
8393 "Vector %x selected for qpair\n", msix
->vector
);
8397 ql_log(ql_log_warn
, vha
, 0x0184,
8398 "Out of MSI-X vectors!.\n");
8402 qpair
->msix
->in_use
= 1;
8403 list_add_tail(&qpair
->qp_list_elem
, &vha
->qp_list
);
8404 qpair
->pdev
= ha
->pdev
;
8405 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
))
8406 qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
8408 mutex_unlock(&ha
->mq_lock
);
8410 /* Create response queue first */
8411 rsp_id
= qla25xx_create_rsp_que(ha
, 0, 0, 0, qpair
, startqp
);
8413 ql_log(ql_log_warn
, vha
, 0x0185,
8414 "Failed to create response queue.\n");
8418 qpair
->rsp
= ha
->rsp_q_map
[rsp_id
];
8420 /* Create request queue */
8421 req_id
= qla25xx_create_req_que(ha
, 0, vp_idx
, 0, rsp_id
, qos
,
8424 ql_log(ql_log_warn
, vha
, 0x0186,
8425 "Failed to create request queue.\n");
8429 qpair
->req
= ha
->req_q_map
[req_id
];
8430 qpair
->rsp
->req
= qpair
->req
;
8431 qpair
->rsp
->qpair
= qpair
;
8432 /* init qpair to this cpu. Will adjust at run time. */
8433 qla_cpu_update(qpair
, smp_processor_id());
8435 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
8436 if (ha
->fw_attributes
& BIT_4
)
8437 qpair
->difdix_supported
= 1;
8440 qpair
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
8441 if (!qpair
->srb_mempool
) {
8442 ql_log(ql_log_warn
, vha
, 0xd036,
8443 "Failed to create srb mempool for qpair %d\n",
8448 /* Mark as online */
8451 if (!vha
->flags
.qpairs_available
)
8452 vha
->flags
.qpairs_available
= 1;
8454 ql_dbg(ql_dbg_multiq
, vha
, 0xc00d,
8455 "Request/Response queue pair created, id %d\n",
8457 ql_dbg(ql_dbg_init
, vha
, 0x0187,
8458 "Request/Response queue pair created, id %d\n",
8465 qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8467 mutex_lock(&ha
->mq_lock
);
8468 qpair
->msix
->in_use
= 0;
8469 list_del(&qpair
->qp_list_elem
);
8470 if (list_empty(&vha
->qp_list
))
8471 vha
->flags
.qpairs_available
= 0;
8473 ha
->queue_pair_map
[qpair_id
] = NULL
;
8474 clear_bit(qpair_id
, ha
->qpair_qid_map
);
8476 mutex_unlock(&ha
->mq_lock
);
8482 int qla2xxx_delete_qpair(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
)
8484 int ret
= QLA_FUNCTION_FAILED
;
8485 struct qla_hw_data
*ha
= qpair
->hw
;
8487 qpair
->delete_in_progress
= 1;
8488 while (atomic_read(&qpair
->ref_count
))
8491 ret
= qla25xx_delete_req_que(vha
, qpair
->req
);
8492 if (ret
!= QLA_SUCCESS
)
8495 ret
= qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8496 if (ret
!= QLA_SUCCESS
)
8499 mutex_lock(&ha
->mq_lock
);
8500 ha
->queue_pair_map
[qpair
->id
] = NULL
;
8501 clear_bit(qpair
->id
, ha
->qpair_qid_map
);
8503 list_del(&qpair
->qp_list_elem
);
8504 if (list_empty(&vha
->qp_list
)) {
8505 vha
->flags
.qpairs_available
= 0;
8506 vha
->flags
.qpairs_req_created
= 0;
8507 vha
->flags
.qpairs_rsp_created
= 0;
8509 mempool_destroy(qpair
->srb_mempool
);
8511 mutex_unlock(&ha
->mq_lock
);