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
;
187 lio
= &sp
->u
.iocb_cmd
;
188 lio
->timeout
= qla2x00_async_iocb_timeout
;
189 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
191 sp
->done
= qla2x00_async_login_sp_done
;
192 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
194 if (fcport
->fc4f_nvme
)
195 lio
->u
.logio
.flags
|= SRB_LOGIN_SKIP_PRLI
;
197 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
198 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
199 rval
= qla2x00_start_sp(sp
);
200 if (rval
!= QLA_SUCCESS
) {
201 fcport
->flags
|= FCF_LOGIN_NEEDED
;
202 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
206 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
207 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
208 "retries=%d.\n", fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
209 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
210 fcport
->login_retry
);
215 fcport
->flags
&= ~FCF_ASYNC_SENT
;
217 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
222 qla2x00_async_logout_sp_done(void *ptr
, int res
)
226 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
227 sp
->fcport
->login_gen
++;
228 qlt_logo_completion_handler(sp
->fcport
, res
);
233 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
236 struct srb_iocb
*lio
;
237 int rval
= QLA_FUNCTION_FAILED
;
239 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
242 fcport
->flags
|= FCF_ASYNC_SENT
;
243 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
247 sp
->type
= SRB_LOGOUT_CMD
;
250 lio
= &sp
->u
.iocb_cmd
;
251 lio
->timeout
= qla2x00_async_iocb_timeout
;
252 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
254 sp
->done
= qla2x00_async_logout_sp_done
;
255 rval
= qla2x00_start_sp(sp
);
256 if (rval
!= QLA_SUCCESS
)
259 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
260 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
261 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
262 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
269 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
274 qla2x00_async_prlo_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
277 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
278 /* Don't re-login in target mode */
279 if (!fcport
->tgt_session
)
280 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
281 qlt_logo_completion_handler(fcport
, data
[0]);
285 qla2x00_async_prlo_sp_done(void *s
, int res
)
287 srb_t
*sp
= (srb_t
*)s
;
288 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
289 struct scsi_qla_host
*vha
= sp
->vha
;
291 sp
->fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
292 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
293 qla2x00_post_async_prlo_done_work(sp
->fcport
->vha
, sp
->fcport
,
299 qla2x00_async_prlo(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
302 struct srb_iocb
*lio
;
305 rval
= QLA_FUNCTION_FAILED
;
306 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
310 sp
->type
= SRB_PRLO_CMD
;
313 lio
= &sp
->u
.iocb_cmd
;
314 lio
->timeout
= qla2x00_async_iocb_timeout
;
315 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
317 sp
->done
= qla2x00_async_prlo_sp_done
;
318 rval
= qla2x00_start_sp(sp
);
319 if (rval
!= QLA_SUCCESS
)
322 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
323 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
324 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
325 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
331 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
336 void qla24xx_handle_adisc_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
338 struct fc_port
*fcport
= ea
->fcport
;
340 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
341 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
342 __func__
, fcport
->port_name
, fcport
->disc_state
,
343 fcport
->fw_login_state
, ea
->rc
, fcport
->login_gen
, ea
->sp
->gen2
,
344 fcport
->rscn_gen
, ea
->sp
->gen1
, fcport
->loop_id
);
346 if (ea
->data
[0] != MBS_COMMAND_COMPLETE
) {
347 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
348 "%s %8phC: adisc fail: post delete\n",
349 __func__
, ea
->fcport
->port_name
);
350 qlt_schedule_sess_for_deletion(ea
->fcport
);
354 if (ea
->fcport
->disc_state
== DSC_DELETE_PEND
)
357 if (ea
->sp
->gen2
!= ea
->fcport
->login_gen
) {
358 /* target side must have changed it. */
359 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
360 "%s %8phC generation changed\n",
361 __func__
, ea
->fcport
->port_name
);
363 } else if (ea
->sp
->gen1
!= ea
->fcport
->rscn_gen
) {
364 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
365 __func__
, __LINE__
, ea
->fcport
->port_name
);
366 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
370 __qla24xx_handle_gpdb_event(vha
, ea
);
374 qla2x00_async_adisc_sp_done(void *ptr
, int res
)
377 struct scsi_qla_host
*vha
= sp
->vha
;
379 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
381 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
382 "Async done-%s res %x %8phC\n",
383 sp
->name
, res
, sp
->fcport
->port_name
);
385 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
387 memset(&ea
, 0, sizeof(ea
));
388 ea
.event
= FCME_ADISC_DONE
;
390 ea
.data
[0] = lio
->u
.logio
.data
[0];
391 ea
.data
[1] = lio
->u
.logio
.data
[1];
392 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
393 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
394 ea
.fcport
= sp
->fcport
;
397 qla2x00_fcport_event_handler(vha
, &ea
);
403 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
407 struct srb_iocb
*lio
;
410 rval
= QLA_FUNCTION_FAILED
;
411 fcport
->flags
|= FCF_ASYNC_SENT
;
412 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
416 sp
->type
= SRB_ADISC_CMD
;
419 lio
= &sp
->u
.iocb_cmd
;
420 lio
->timeout
= qla2x00_async_iocb_timeout
;
421 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
423 sp
->done
= qla2x00_async_adisc_sp_done
;
424 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
425 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
426 rval
= qla2x00_start_sp(sp
);
427 if (rval
!= QLA_SUCCESS
)
430 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
431 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
432 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
, fcport
->port_name
);
438 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
439 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
443 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t
*vha
,
444 struct event_arg
*ea
)
446 fc_port_t
*fcport
, *conflict_fcport
;
447 struct get_name_list_extended
*e
;
448 u16 i
, n
, found
= 0, loop_id
;
452 u8 current_login_state
;
455 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
456 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
457 __func__
, fcport
->port_name
, fcport
->disc_state
,
458 fcport
->fw_login_state
, ea
->rc
,
459 fcport
->login_gen
, fcport
->last_login_gen
,
460 fcport
->rscn_gen
, fcport
->last_rscn_gen
, vha
->loop_id
);
462 if (fcport
->disc_state
== DSC_DELETE_PEND
)
465 if (ea
->rc
) { /* rval */
466 if (fcport
->login_retry
== 0) {
467 fcport
->login_retry
= vha
->hw
->login_retry_count
;
468 ql_dbg(ql_dbg_disc
, vha
, 0x20de,
469 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
470 fcport
->port_name
, fcport
->login_retry
);
475 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
476 ql_dbg(ql_dbg_disc
, vha
, 0x20df,
477 "%s %8phC rscn gen changed rscn %d|%d \n",
478 __func__
, fcport
->port_name
,
479 fcport
->last_rscn_gen
, fcport
->rscn_gen
);
480 qla24xx_post_gidpn_work(vha
, fcport
);
482 } else if (fcport
->last_login_gen
!= fcport
->login_gen
) {
483 ql_dbg(ql_dbg_disc
, vha
, 0x20e0,
484 "%s %8phC login gen changed\n",
485 __func__
, fcport
->port_name
);
489 n
= ea
->data
[0] / sizeof(struct get_name_list_extended
);
491 ql_dbg(ql_dbg_disc
, vha
, 0x20e1,
492 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
493 __func__
, __LINE__
, fcport
->port_name
, n
,
494 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
495 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
);
497 for (i
= 0; i
< n
; i
++) {
499 wwn
= wwn_to_u64(e
->port_name
);
501 if (memcmp((u8
*)&wwn
, fcport
->port_name
, WWN_SIZE
))
505 id
.b
.domain
= e
->port_id
[2];
506 id
.b
.area
= e
->port_id
[1];
507 id
.b
.al_pa
= e
->port_id
[0];
510 loop_id
= le16_to_cpu(e
->nport_handle
);
511 loop_id
= (loop_id
& 0x7fff);
513 ql_dbg(ql_dbg_disc
, vha
, 0x20e2,
514 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
515 __func__
, fcport
->port_name
,
516 e
->current_login_state
, fcport
->fw_login_state
,
517 id
.b
.domain
, id
.b
.area
, id
.b
.al_pa
,
518 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
519 fcport
->d_id
.b
.al_pa
, loop_id
, fcport
->loop_id
);
521 if ((id
.b24
!= fcport
->d_id
.b24
) ||
522 ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
523 (fcport
->loop_id
!= loop_id
))) {
524 ql_dbg(ql_dbg_disc
, vha
, 0x20e3,
525 "%s %d %8phC post del sess\n",
526 __func__
, __LINE__
, fcport
->port_name
);
527 qlt_schedule_sess_for_deletion(fcport
);
531 fcport
->loop_id
= loop_id
;
533 wwn
= wwn_to_u64(fcport
->port_name
);
534 qlt_find_sess_invalidate_other(vha
, wwn
,
535 id
, loop_id
, &conflict_fcport
);
537 if (conflict_fcport
) {
539 * Another share fcport share the same loop_id &
540 * nport id. Conflict fcport needs to finish
541 * cleanup before this fcport can proceed to login.
543 conflict_fcport
->conflict
= fcport
;
544 fcport
->login_pause
= 1;
547 if (fcport
->fc4f_nvme
)
548 current_login_state
= e
->current_login_state
>> 4;
550 current_login_state
= e
->current_login_state
& 0xf;
552 switch (current_login_state
) {
553 case DSC_LS_PRLI_COMP
:
554 ql_dbg(ql_dbg_disc
, vha
, 0x20e4,
555 "%s %d %8phC post gpdb\n",
556 __func__
, __LINE__
, fcport
->port_name
);
558 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
559 fcport
->port_type
= FCT_INITIATOR
;
561 fcport
->port_type
= FCT_TARGET
;
563 data
[0] = data
[1] = 0;
564 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
566 case DSC_LS_PORT_UNAVAIL
:
568 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
569 qla2x00_find_new_loop_id(vha
, fcport
);
570 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
572 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
574 __func__
, __LINE__
, fcport
->port_name
);
575 qla24xx_fcport_handle_login(vha
, fcport
);
581 /* fw has no record of this port */
582 for (i
= 0; i
< n
; i
++) {
584 id
.b
.domain
= e
->port_id
[0];
585 id
.b
.area
= e
->port_id
[1];
586 id
.b
.al_pa
= e
->port_id
[2];
588 loop_id
= le16_to_cpu(e
->nport_handle
);
590 if (fcport
->d_id
.b24
== id
.b24
) {
592 qla2x00_find_fcport_by_wwpn(vha
,
594 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
595 "%s %d %8phC post del sess\n",
597 conflict_fcport
->port_name
);
598 qlt_schedule_sess_for_deletion
602 /* FW already picked this loop id for another fcport */
603 if (fcport
->loop_id
== loop_id
)
604 fcport
->loop_id
= FC_NO_LOOP_ID
;
606 qla24xx_fcport_handle_login(vha
, fcport
);
611 qla24xx_async_gnl_sp_done(void *s
, int res
)
614 struct scsi_qla_host
*vha
= sp
->vha
;
616 struct fc_port
*fcport
= NULL
, *tf
;
617 u16 i
, n
= 0, loop_id
;
619 struct get_name_list_extended
*e
;
624 ql_dbg(ql_dbg_disc
, vha
, 0x20e7,
625 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
626 sp
->name
, res
, sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1],
627 sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[2]);
629 memset(&ea
, 0, sizeof(ea
));
632 ea
.event
= FCME_GNL_DONE
;
634 if (sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] >=
635 sizeof(struct get_name_list_extended
)) {
636 n
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] /
637 sizeof(struct get_name_list_extended
);
638 ea
.data
[0] = sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1]; /* amnt xfered */
641 for (i
= 0; i
< n
; i
++) {
643 loop_id
= le16_to_cpu(e
->nport_handle
);
644 /* mask out reserve bit */
645 loop_id
= (loop_id
& 0x7fff);
646 set_bit(loop_id
, vha
->hw
->loop_id_map
);
647 wwn
= wwn_to_u64(e
->port_name
);
649 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0x20e8,
650 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
651 __func__
, (void *)&wwn
, e
->port_id
[2], e
->port_id
[1],
652 e
->port_id
[0], e
->current_login_state
, e
->last_login_state
,
656 spin_lock_irqsave(&vha
->gnl
.fcports_lock
, flags
);
660 if (!list_empty(&vha
->gnl
.fcports
))
661 list_splice_init(&vha
->gnl
.fcports
, &h
);
663 list_for_each_entry_safe(fcport
, tf
, &h
, gnl_entry
) {
664 list_del_init(&fcport
->gnl_entry
);
665 spin_lock(&vha
->hw
->tgt
.sess_lock
);
666 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
667 spin_unlock(&vha
->hw
->tgt
.sess_lock
);
670 qla2x00_fcport_event_handler(vha
, &ea
);
672 spin_unlock_irqrestore(&vha
->gnl
.fcports_lock
, flags
);
674 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
675 /* create new fcport if fw has knowledge of new sessions */
676 for (i
= 0; i
< n
; i
++) {
681 wwn
= wwn_to_u64(e
->port_name
);
684 list_for_each_entry_safe(fcport
, tf
, &vha
->vp_fcports
, list
) {
685 if (!memcmp((u8
*)&wwn
, fcport
->port_name
,
692 id
.b
.domain
= e
->port_id
[2];
693 id
.b
.area
= e
->port_id
[1];
694 id
.b
.al_pa
= e
->port_id
[0];
697 if (!found
&& wwn
&& !IS_SW_RESV_ADDR(id
)) {
698 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
699 "%s %d %8phC %06x post new sess\n",
700 __func__
, __LINE__
, (u8
*)&wwn
, id
.b24
);
701 wwnn
= wwn_to_u64(e
->node_name
);
702 qla24xx_post_newsess_work(vha
, &id
, (u8
*)&wwn
,
703 (u8
*)&wwnn
, NULL
, FC4_TYPE_UNKNOWN
);
707 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
712 int qla24xx_async_gnl(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
715 struct srb_iocb
*mbx
;
716 int rval
= QLA_FUNCTION_FAILED
;
720 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
723 ql_dbg(ql_dbg_disc
, vha
, 0x20d9,
724 "Async-gnlist WWPN %8phC \n", fcport
->port_name
);
726 spin_lock_irqsave(&vha
->gnl
.fcports_lock
, flags
);
727 if (!list_empty(&fcport
->gnl_entry
)) {
728 spin_unlock_irqrestore(&vha
->gnl
.fcports_lock
, flags
);
733 spin_lock(&vha
->hw
->tgt
.sess_lock
);
734 fcport
->disc_state
= DSC_GNL
;
735 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
736 fcport
->last_login_gen
= fcport
->login_gen
;
737 spin_unlock(&vha
->hw
->tgt
.sess_lock
);
739 list_add_tail(&fcport
->gnl_entry
, &vha
->gnl
.fcports
);
740 spin_unlock_irqrestore(&vha
->gnl
.fcports_lock
, flags
);
742 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
746 fcport
->flags
|= FCF_ASYNC_SENT
;
747 sp
->type
= SRB_MB_IOCB
;
749 sp
->gen1
= fcport
->rscn_gen
;
750 sp
->gen2
= fcport
->login_gen
;
752 mbx
= &sp
->u
.iocb_cmd
;
753 mbx
->timeout
= qla2x00_async_iocb_timeout
;
754 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
756 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
757 mb
[0] = MBC_PORT_NODE_NAME_LIST
;
758 mb
[1] = BIT_2
| BIT_3
;
759 mb
[2] = MSW(vha
->gnl
.ldma
);
760 mb
[3] = LSW(vha
->gnl
.ldma
);
761 mb
[6] = MSW(MSD(vha
->gnl
.ldma
));
762 mb
[7] = LSW(MSD(vha
->gnl
.ldma
));
763 mb
[8] = vha
->gnl
.size
;
766 sp
->done
= qla24xx_async_gnl_sp_done
;
768 rval
= qla2x00_start_sp(sp
);
769 if (rval
!= QLA_SUCCESS
)
772 ql_dbg(ql_dbg_disc
, vha
, 0x20da,
773 "Async-%s - OUT WWPN %8phC hndl %x\n",
774 sp
->name
, fcport
->port_name
, sp
->handle
);
780 fcport
->flags
&= ~FCF_ASYNC_SENT
;
785 int qla24xx_post_gnl_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
787 struct qla_work_evt
*e
;
789 e
= qla2x00_alloc_work(vha
, QLA_EVT_GNL
);
791 return QLA_FUNCTION_FAILED
;
793 e
->u
.fcport
.fcport
= fcport
;
794 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
795 return qla2x00_post_work(vha
, e
);
799 void qla24xx_async_gpdb_sp_done(void *s
, int res
)
802 struct scsi_qla_host
*vha
= sp
->vha
;
803 struct qla_hw_data
*ha
= vha
->hw
;
804 fc_port_t
*fcport
= sp
->fcport
;
805 u16
*mb
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
;
808 ql_dbg(ql_dbg_disc
, vha
, 0x20db,
809 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
810 sp
->name
, res
, fcport
->port_name
, mb
[1], mb
[2]);
812 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
814 memset(&ea
, 0, sizeof(ea
));
815 ea
.event
= FCME_GPDB_DONE
;
819 qla2x00_fcport_event_handler(vha
, &ea
);
821 dma_pool_free(ha
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
822 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
827 static int qla24xx_post_prli_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
829 struct qla_work_evt
*e
;
831 e
= qla2x00_alloc_work(vha
, QLA_EVT_PRLI
);
833 return QLA_FUNCTION_FAILED
;
835 e
->u
.fcport
.fcport
= fcport
;
837 return qla2x00_post_work(vha
, e
);
841 qla2x00_async_prli_sp_done(void *ptr
, int res
)
844 struct scsi_qla_host
*vha
= sp
->vha
;
845 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
848 ql_dbg(ql_dbg_disc
, vha
, 0x2129,
849 "%s %8phC res %d \n", __func__
,
850 sp
->fcport
->port_name
, res
);
852 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
854 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
855 memset(&ea
, 0, sizeof(ea
));
856 ea
.event
= FCME_PRLI_DONE
;
857 ea
.fcport
= sp
->fcport
;
858 ea
.data
[0] = lio
->u
.logio
.data
[0];
859 ea
.data
[1] = lio
->u
.logio
.data
[1];
860 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
861 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
864 qla2x00_fcport_event_handler(vha
, &ea
);
871 qla24xx_async_prli(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
874 struct srb_iocb
*lio
;
875 int rval
= QLA_FUNCTION_FAILED
;
877 if (!vha
->flags
.online
)
880 if (fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
||
881 fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)
884 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
888 fcport
->flags
|= FCF_ASYNC_SENT
;
889 fcport
->logout_completed
= 0;
891 sp
->type
= SRB_PRLI_CMD
;
894 lio
= &sp
->u
.iocb_cmd
;
895 lio
->timeout
= qla2x00_async_iocb_timeout
;
896 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
898 sp
->done
= qla2x00_async_prli_sp_done
;
899 lio
->u
.logio
.flags
= 0;
901 if (fcport
->fc4f_nvme
)
902 lio
->u
.logio
.flags
|= SRB_LOGIN_NVME_PRLI
;
904 rval
= qla2x00_start_sp(sp
);
905 if (rval
!= QLA_SUCCESS
) {
906 fcport
->flags
|= FCF_LOGIN_NEEDED
;
907 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
911 ql_dbg(ql_dbg_disc
, vha
, 0x211b,
912 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
913 fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
914 fcport
->d_id
.b24
, fcport
->login_retry
);
920 fcport
->flags
&= ~FCF_ASYNC_SENT
;
924 int qla24xx_post_gpdb_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
926 struct qla_work_evt
*e
;
928 e
= qla2x00_alloc_work(vha
, QLA_EVT_GPDB
);
930 return QLA_FUNCTION_FAILED
;
932 e
->u
.fcport
.fcport
= fcport
;
933 e
->u
.fcport
.opt
= opt
;
934 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
935 return qla2x00_post_work(vha
, e
);
938 int qla24xx_async_gpdb(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
941 struct srb_iocb
*mbx
;
942 int rval
= QLA_FUNCTION_FAILED
;
945 struct port_database_24xx
*pd
;
946 struct qla_hw_data
*ha
= vha
->hw
;
948 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
951 fcport
->disc_state
= DSC_GPDB
;
953 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
957 fcport
->flags
|= FCF_ASYNC_SENT
;
958 sp
->type
= SRB_MB_IOCB
;
960 sp
->gen1
= fcport
->rscn_gen
;
961 sp
->gen2
= fcport
->login_gen
;
963 mbx
= &sp
->u
.iocb_cmd
;
964 mbx
->timeout
= qla2x00_async_iocb_timeout
;
965 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
967 pd
= dma_pool_zalloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
969 ql_log(ql_log_warn
, vha
, 0xd043,
970 "Failed to allocate port database structure.\n");
974 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
975 mb
[0] = MBC_GET_PORT_DATABASE
;
976 mb
[1] = fcport
->loop_id
;
979 mb
[6] = MSW(MSD(pd_dma
));
980 mb
[7] = LSW(MSD(pd_dma
));
984 mbx
->u
.mbx
.in
= (void *)pd
;
985 mbx
->u
.mbx
.in_dma
= pd_dma
;
987 sp
->done
= qla24xx_async_gpdb_sp_done
;
989 rval
= qla2x00_start_sp(sp
);
990 if (rval
!= QLA_SUCCESS
)
993 ql_dbg(ql_dbg_disc
, vha
, 0x20dc,
994 "Async-%s %8phC hndl %x opt %x\n",
995 sp
->name
, fcport
->port_name
, sp
->handle
, opt
);
1001 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1004 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1006 qla24xx_post_gpdb_work(vha
, fcport
, opt
);
1011 void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1013 unsigned long flags
;
1015 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1016 ea
->fcport
->login_gen
++;
1017 ea
->fcport
->deleted
= 0;
1018 ea
->fcport
->logout_on_delete
= 1;
1020 if (!ea
->fcport
->login_succ
&& !IS_SW_RESV_ADDR(ea
->fcport
->d_id
)) {
1021 vha
->fcport_count
++;
1022 ea
->fcport
->login_succ
= 1;
1024 if (!IS_IIDMA_CAPABLE(vha
->hw
) ||
1025 !vha
->hw
->flags
.gpsc_supported
) {
1026 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1027 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1028 __func__
, __LINE__
, ea
->fcport
->port_name
,
1031 qla24xx_post_upd_fcport_work(vha
, ea
->fcport
);
1033 if (ea
->fcport
->id_changed
) {
1034 ea
->fcport
->id_changed
= 0;
1035 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
1036 "%s %d %8phC post gfpnid fcp_cnt %d\n",
1037 __func__
, __LINE__
, ea
->fcport
->port_name
,
1039 qla24xx_post_gfpnid_work(vha
, ea
->fcport
);
1041 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
1042 "%s %d %8phC post gpsc fcp_cnt %d\n",
1043 __func__
, __LINE__
, ea
->fcport
->port_name
,
1045 qla24xx_post_gpsc_work(vha
, ea
->fcport
);
1048 } else if (ea
->fcport
->login_succ
) {
1050 * We have an existing session. A late RSCN delivery
1051 * must have triggered the session to be re-validate.
1052 * Session is still valid.
1054 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1055 "%s %d %8phC session revalidate success\n",
1056 __func__
, __LINE__
, ea
->fcport
->port_name
);
1057 ea
->fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
1059 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1063 void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1065 fc_port_t
*fcport
= ea
->fcport
;
1066 struct port_database_24xx
*pd
;
1067 struct srb
*sp
= ea
->sp
;
1070 pd
= (struct port_database_24xx
*)sp
->u
.iocb_cmd
.u
.mbx
.in
;
1072 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1074 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
1075 "%s %8phC DS %d LS %d rc %d\n", __func__
, fcport
->port_name
,
1076 fcport
->disc_state
, pd
->current_login_state
, ea
->rc
);
1078 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1081 if (fcport
->fc4f_nvme
)
1082 ls
= pd
->current_login_state
>> 4;
1084 ls
= pd
->current_login_state
& 0xf;
1087 case PDS_PRLI_COMPLETE
:
1088 __qla24xx_parse_gpdb(vha
, fcport
, pd
);
1090 case PDS_PLOGI_PENDING
:
1091 case PDS_PLOGI_COMPLETE
:
1092 case PDS_PRLI_PENDING
:
1093 case PDS_PRLI2_PENDING
:
1094 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC relogin needed\n",
1095 __func__
, __LINE__
, fcport
->port_name
);
1096 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1098 case PDS_LOGO_PENDING
:
1099 case PDS_PORT_UNAVAILABLE
:
1101 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC post del sess\n",
1102 __func__
, __LINE__
, fcport
->port_name
);
1103 qlt_schedule_sess_for_deletion(fcport
);
1106 __qla24xx_handle_gpdb_event(vha
, ea
);
1109 static void qla_chk_n2n_b4_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1114 if (qla_tgt_mode_enabled(vha
))
1117 if (qla_dual_mode_enabled(vha
)) {
1118 if (N2N_TOPO(vha
->hw
)) {
1121 mywwn
= wwn_to_u64(vha
->port_name
);
1122 wwn
= wwn_to_u64(fcport
->port_name
);
1125 else if ((fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1126 && time_after_eq(jiffies
,
1127 fcport
->plogi_nack_done_deadline
))
1133 /* initiator mode */
1138 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1139 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1140 rc
= qla2x00_find_new_loop_id(vha
, fcport
);
1142 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
1143 "%s %d %8phC post del sess - out of loopid\n",
1144 __func__
, __LINE__
, fcport
->port_name
);
1145 fcport
->scan_state
= 0;
1146 qlt_schedule_sess_for_deletion(fcport
);
1150 ql_dbg(ql_dbg_disc
, vha
, 0x20bf,
1151 "%s %d %8phC post login\n",
1152 __func__
, __LINE__
, fcport
->port_name
);
1153 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
1157 int qla24xx_fcport_handle_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1162 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1163 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
1164 __func__
, fcport
->port_name
, fcport
->disc_state
,
1165 fcport
->fw_login_state
, fcport
->login_pause
, fcport
->flags
,
1166 fcport
->conflict
, fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1167 fcport
->login_gen
, fcport
->login_retry
,
1168 fcport
->loop_id
, fcport
->scan_state
);
1170 if (fcport
->login_retry
== 0)
1173 if (fcport
->scan_state
!= QLA_FCPORT_FOUND
)
1176 if ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
1177 ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1178 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)))
1181 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1182 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1183 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1188 /* for pure Target Mode. Login will not be initiated */
1189 if (vha
->host
->active_mode
== MODE_TARGET
)
1192 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1193 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1197 fcport
->login_retry
--;
1199 switch (fcport
->disc_state
) {
1201 wwn
= wwn_to_u64(fcport
->node_name
);
1203 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1204 "%s %d %8phC post GNNID\n",
1205 __func__
, __LINE__
, fcport
->port_name
);
1206 qla24xx_post_gnnid_work(vha
, fcport
);
1207 } else if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1208 ql_dbg(ql_dbg_disc
, vha
, 0x20bd,
1209 "%s %d %8phC post gnl\n",
1210 __func__
, __LINE__
, fcport
->port_name
);
1211 qla24xx_post_gnl_work(vha
, fcport
);
1213 qla_chk_n2n_b4_login(vha
, fcport
);
1218 if (fcport
->login_pause
) {
1219 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1220 fcport
->last_login_gen
= fcport
->login_gen
;
1221 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1225 qla_chk_n2n_b4_login(vha
, fcport
);
1228 case DSC_LOGIN_FAILED
:
1229 ql_dbg(ql_dbg_disc
, vha
, 0x20d0,
1230 "%s %d %8phC post gidpn\n",
1231 __func__
, __LINE__
, fcport
->port_name
);
1232 if (N2N_TOPO(vha
->hw
))
1233 qla_chk_n2n_b4_login(vha
, fcport
);
1235 qla24xx_post_gidpn_work(vha
, fcport
);
1238 case DSC_LOGIN_COMPLETE
:
1239 /* recheck login state */
1240 ql_dbg(ql_dbg_disc
, vha
, 0x20d1,
1241 "%s %d %8phC post adisc\n",
1242 __func__
, __LINE__
, fcport
->port_name
);
1243 data
[0] = data
[1] = 0;
1244 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
1247 case DSC_LOGIN_PEND
:
1248 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1249 qla24xx_post_prli_work(vha
, fcport
);
1260 void qla24xx_handle_rscn_event(fc_port_t
*fcport
, struct event_arg
*ea
)
1264 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210c,
1265 "%s %8phC DS %d LS %d\n",
1266 __func__
, fcport
->port_name
, fcport
->disc_state
,
1267 fcport
->fw_login_state
);
1269 if (fcport
->flags
& FCF_ASYNC_SENT
)
1272 switch (fcport
->disc_state
) {
1274 case DSC_LOGIN_COMPLETE
:
1275 qla24xx_post_gpnid_work(fcport
->vha
, &ea
->id
);
1282 int qla24xx_post_newsess_work(struct scsi_qla_host
*vha
, port_id_t
*id
,
1283 u8
*port_name
, u8
*node_name
, void *pla
, u8 fc4_type
)
1285 struct qla_work_evt
*e
;
1286 e
= qla2x00_alloc_work(vha
, QLA_EVT_NEW_SESS
);
1288 return QLA_FUNCTION_FAILED
;
1290 e
->u
.new_sess
.id
= *id
;
1291 e
->u
.new_sess
.pla
= pla
;
1292 e
->u
.new_sess
.fc4_type
= fc4_type
;
1293 memcpy(e
->u
.new_sess
.port_name
, port_name
, WWN_SIZE
);
1295 memcpy(e
->u
.new_sess
.node_name
, node_name
, WWN_SIZE
);
1297 return qla2x00_post_work(vha
, e
);
1301 void qla24xx_handle_relogin_event(scsi_qla_host_t
*vha
,
1302 struct event_arg
*ea
)
1304 fc_port_t
*fcport
= ea
->fcport
;
1306 ql_dbg(ql_dbg_disc
, vha
, 0x2102,
1307 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1308 __func__
, fcport
->port_name
, fcport
->disc_state
,
1309 fcport
->fw_login_state
, fcport
->login_pause
,
1310 fcport
->deleted
, fcport
->conflict
,
1311 fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1312 fcport
->last_login_gen
, fcport
->login_gen
,
1315 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1316 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1319 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1320 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1321 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1326 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1327 fcport
->login_retry
++;
1328 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1332 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
1333 fcport
->login_retry
++;
1337 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
1338 ql_dbg(ql_dbg_disc
, vha
, 0x20e9, "%s %d %8phC post gidpn\n",
1339 __func__
, __LINE__
, fcport
->port_name
);
1341 qla24xx_post_gidpn_work(vha
, fcport
);
1345 qla24xx_fcport_handle_login(vha
, fcport
);
1348 void qla2x00_fcport_event_handler(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1351 uint32_t id
= 0, mask
, rid
;
1352 unsigned long flags
;
1354 switch (ea
->event
) {
1356 case FCME_GIDPN_DONE
:
1357 case FCME_GPSC_DONE
:
1358 case FCME_GPNID_DONE
:
1359 case FCME_GNNID_DONE
:
1360 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
1361 test_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))
1368 switch (ea
->event
) {
1370 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1373 qla24xx_handle_relogin_event(vha
, ea
);
1376 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1378 switch (ea
->id
.b
.rsvd_1
) {
1379 case RSCN_PORT_ADDR
:
1380 spin_lock_irqsave(&vha
->work_lock
, flags
);
1381 if (vha
->scan
.scan_flags
== 0) {
1382 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1383 "%s: schedule\n", __func__
);
1384 vha
->scan
.scan_flags
|= SF_QUEUED
;
1385 schedule_delayed_work(&vha
->scan
.scan_work
, 5);
1387 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1390 case RSCN_AREA_ADDR
:
1392 if (ea
->id
.b
.rsvd_1
== RSCN_AREA_ADDR
) {
1394 ql_dbg(ql_dbg_async
, vha
, 0x5044,
1395 "RSCN: Area 0x%06x was affected\n",
1399 ql_dbg(ql_dbg_async
, vha
, 0x507a,
1400 "RSCN: Domain 0x%06x was affected\n",
1404 rid
= ea
->id
.b24
& mask
;
1405 list_for_each_entry_safe(f
, tf
, &vha
->vp_fcports
,
1407 id
= f
->d_id
.b24
& mask
;
1410 qla24xx_handle_rscn_event(f
, ea
);
1416 ql_log(ql_log_warn
, vha
, 0xd045,
1417 "RSCN: Fabric was affected. Addr format %d\n",
1419 qla2x00_mark_all_devices_lost(vha
, 1);
1420 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1421 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1424 case FCME_GIDPN_DONE
:
1425 qla24xx_handle_gidpn_event(vha
, ea
);
1428 qla24xx_handle_gnl_done_event(vha
, ea
);
1430 case FCME_GPSC_DONE
:
1431 qla24xx_handle_gpsc_event(vha
, ea
);
1433 case FCME_PLOGI_DONE
: /* Initiator side sent LLIOCB */
1434 qla24xx_handle_plogi_done_event(vha
, ea
);
1436 case FCME_PRLI_DONE
:
1437 qla24xx_handle_prli_done_event(vha
, ea
);
1439 case FCME_GPDB_DONE
:
1440 qla24xx_handle_gpdb_event(vha
, ea
);
1442 case FCME_GPNID_DONE
:
1443 qla24xx_handle_gpnid_event(vha
, ea
);
1445 case FCME_GFFID_DONE
:
1446 qla24xx_handle_gffid_event(vha
, ea
);
1448 case FCME_ADISC_DONE
:
1449 qla24xx_handle_adisc_event(vha
, ea
);
1451 case FCME_GNNID_DONE
:
1452 qla24xx_handle_gnnid_event(vha
, ea
);
1454 case FCME_GFPNID_DONE
:
1455 qla24xx_handle_gfpnid_event(vha
, ea
);
1464 qla2x00_tmf_iocb_timeout(void *data
)
1467 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1469 tmf
->u
.tmf
.comp_status
= CS_TIMEOUT
;
1470 complete(&tmf
->u
.tmf
.comp
);
1474 qla2x00_tmf_sp_done(void *ptr
, int res
)
1477 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1479 complete(&tmf
->u
.tmf
.comp
);
1483 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
1486 struct scsi_qla_host
*vha
= fcport
->vha
;
1487 struct srb_iocb
*tm_iocb
;
1489 int rval
= QLA_FUNCTION_FAILED
;
1491 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1495 tm_iocb
= &sp
->u
.iocb_cmd
;
1496 sp
->type
= SRB_TM_CMD
;
1499 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
1500 init_completion(&tm_iocb
->u
.tmf
.comp
);
1501 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1503 tm_iocb
->u
.tmf
.flags
= flags
;
1504 tm_iocb
->u
.tmf
.lun
= lun
;
1505 tm_iocb
->u
.tmf
.data
= tag
;
1506 sp
->done
= qla2x00_tmf_sp_done
;
1508 rval
= qla2x00_start_sp(sp
);
1509 if (rval
!= QLA_SUCCESS
)
1512 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
1513 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1514 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1515 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1517 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
1519 rval
= tm_iocb
->u
.tmf
.comp_status
== CS_COMPLETE
?
1520 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1522 if ((rval
!= QLA_SUCCESS
) || tm_iocb
->u
.tmf
.data
) {
1523 ql_dbg(ql_dbg_taskm
, vha
, 0x8030,
1524 "TM IOCB failed (%x).\n", rval
);
1527 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
1528 flags
= tm_iocb
->u
.tmf
.flags
;
1529 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
1531 /* Issue Marker IOCB */
1532 qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
1533 vha
->hw
->rsp_q_map
[0], sp
->fcport
->loop_id
, lun
,
1534 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
1539 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1545 qla24xx_abort_iocb_timeout(void *data
)
1548 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1550 abt
->u
.abt
.comp_status
= CS_TIMEOUT
;
1551 complete(&abt
->u
.abt
.comp
);
1555 qla24xx_abort_sp_done(void *ptr
, int res
)
1558 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1560 if (del_timer(&sp
->u
.iocb_cmd
.timer
))
1561 complete(&abt
->u
.abt
.comp
);
1565 qla24xx_async_abort_cmd(srb_t
*cmd_sp
)
1567 scsi_qla_host_t
*vha
= cmd_sp
->vha
;
1568 fc_port_t
*fcport
= cmd_sp
->fcport
;
1569 struct srb_iocb
*abt_iocb
;
1571 int rval
= QLA_FUNCTION_FAILED
;
1573 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1577 abt_iocb
= &sp
->u
.iocb_cmd
;
1578 sp
->type
= SRB_ABT_CMD
;
1581 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
1582 init_completion(&abt_iocb
->u
.abt
.comp
);
1583 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1585 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
1587 if (vha
->flags
.qpairs_available
&& cmd_sp
->qpair
)
1588 abt_iocb
->u
.abt
.req_que_no
=
1589 cpu_to_le16(cmd_sp
->qpair
->req
->id
);
1591 abt_iocb
->u
.abt
.req_que_no
= cpu_to_le16(vha
->req
->id
);
1593 sp
->done
= qla24xx_abort_sp_done
;
1595 rval
= qla2x00_start_sp(sp
);
1596 if (rval
!= QLA_SUCCESS
)
1599 ql_dbg(ql_dbg_async
, vha
, 0x507c,
1600 "Abort command issued - hdl=%x, target_id=%x\n",
1601 cmd_sp
->handle
, fcport
->tgt_id
);
1603 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
1605 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
1606 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1615 qla24xx_async_abort_command(srb_t
*sp
)
1617 unsigned long flags
= 0;
1620 fc_port_t
*fcport
= sp
->fcport
;
1621 struct scsi_qla_host
*vha
= fcport
->vha
;
1622 struct qla_hw_data
*ha
= vha
->hw
;
1623 struct req_que
*req
= vha
->req
;
1625 if (vha
->flags
.qpairs_available
&& sp
->qpair
)
1626 req
= sp
->qpair
->req
;
1628 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1629 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
1630 if (req
->outstanding_cmds
[handle
] == sp
)
1633 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1634 if (handle
== req
->num_outstanding_cmds
) {
1635 /* Command not found. */
1636 return QLA_FUNCTION_FAILED
;
1638 if (sp
->type
== SRB_FXIOCB_DCMD
)
1639 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
1640 FXDISC_ABORT_IOCTL
);
1642 return qla24xx_async_abort_cmd(sp
);
1646 qla24xx_handle_prli_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1648 switch (ea
->data
[0]) {
1649 case MBS_COMMAND_COMPLETE
:
1650 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1651 "%s %d %8phC post gpdb\n",
1652 __func__
, __LINE__
, ea
->fcport
->port_name
);
1654 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1655 ea
->fcport
->logout_on_delete
= 1;
1656 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1659 if ((ea
->iop
[0] == LSC_SCODE_ELS_REJECT
) &&
1660 (ea
->iop
[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1661 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1662 ea
->fcport
->fw_login_state
= DSC_LS_PLOGI_COMP
;
1666 if (ea
->fcport
->n2n_flag
) {
1667 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1668 "%s %d %8phC post fc4 prli\n",
1669 __func__
, __LINE__
, ea
->fcport
->port_name
);
1670 ea
->fcport
->fc4f_nvme
= 0;
1671 ea
->fcport
->n2n_flag
= 0;
1672 qla24xx_post_prli_work(vha
, ea
->fcport
);
1674 ql_dbg(ql_dbg_disc
, vha
, 0x2119,
1675 "%s %d %8phC unhandle event of %x\n",
1676 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[0]);
1682 qla24xx_handle_plogi_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1684 port_id_t cid
; /* conflict Nport id */
1686 struct fc_port
*conflict_fcport
;
1687 unsigned long flags
;
1688 struct fc_port
*fcport
= ea
->fcport
;
1690 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1691 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1692 __func__
, fcport
->port_name
, fcport
->disc_state
,
1693 fcport
->fw_login_state
, ea
->rc
, ea
->sp
->gen2
, fcport
->login_gen
,
1694 ea
->sp
->gen2
, fcport
->rscn_gen
|ea
->sp
->gen1
,
1695 ea
->data
[0], ea
->data
[1], ea
->iop
[0], ea
->iop
[1]);
1697 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1698 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)) {
1699 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1700 "%s %d %8phC Remote is trying to login\n",
1701 __func__
, __LINE__
, fcport
->port_name
);
1705 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1708 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1709 /* target side must have changed it. */
1710 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1711 "%s %8phC generation changed\n",
1712 __func__
, fcport
->port_name
);
1713 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1715 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1716 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
1717 __func__
, __LINE__
, fcport
->port_name
);
1718 qla24xx_post_gidpn_work(vha
, fcport
);
1722 switch (ea
->data
[0]) {
1723 case MBS_COMMAND_COMPLETE
:
1725 * Driver must validate login state - If PRLI not complete,
1726 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1729 if (ea
->fcport
->fc4f_nvme
) {
1730 ql_dbg(ql_dbg_disc
, vha
, 0x2117,
1731 "%s %d %8phC post prli\n",
1732 __func__
, __LINE__
, ea
->fcport
->port_name
);
1733 qla24xx_post_prli_work(vha
, ea
->fcport
);
1735 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1736 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1737 __func__
, __LINE__
, ea
->fcport
->port_name
,
1738 ea
->fcport
->loop_id
, ea
->fcport
->d_id
.b24
);
1740 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1741 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1742 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1743 ea
->fcport
->logout_on_delete
= 1;
1744 ea
->fcport
->send_els_logo
= 0;
1745 ea
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
1746 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1748 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1751 case MBS_COMMAND_ERROR
:
1752 ql_dbg(ql_dbg_disc
, vha
, 0x20eb, "%s %d %8phC cmd error %x\n",
1753 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[1]);
1755 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1756 ea
->fcport
->disc_state
= DSC_LOGIN_FAILED
;
1757 if (ea
->data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1758 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1760 qla2x00_mark_device_lost(vha
, ea
->fcport
, 1, 0);
1762 case MBS_LOOP_ID_USED
:
1763 /* data[1] = IO PARAM 1 = nport ID */
1764 cid
.b
.domain
= (ea
->iop
[1] >> 16) & 0xff;
1765 cid
.b
.area
= (ea
->iop
[1] >> 8) & 0xff;
1766 cid
.b
.al_pa
= ea
->iop
[1] & 0xff;
1769 ql_dbg(ql_dbg_disc
, vha
, 0x20ec,
1770 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1771 __func__
, __LINE__
, ea
->fcport
->port_name
,
1772 ea
->fcport
->loop_id
);
1774 if (IS_SW_RESV_ADDR(cid
)) {
1775 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1776 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1778 qla2x00_clear_loop_id(ea
->fcport
);
1780 qla24xx_post_gnl_work(vha
, ea
->fcport
);
1782 case MBS_PORT_ID_USED
:
1783 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1784 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1785 __func__
, __LINE__
, ea
->fcport
->port_name
,
1786 ea
->fcport
->d_id
.b
.domain
, ea
->fcport
->d_id
.b
.area
,
1787 ea
->fcport
->d_id
.b
.al_pa
);
1789 lid
= ea
->iop
[1] & 0xffff;
1790 qlt_find_sess_invalidate_other(vha
,
1791 wwn_to_u64(ea
->fcport
->port_name
),
1792 ea
->fcport
->d_id
, lid
, &conflict_fcport
);
1794 if (conflict_fcport
) {
1796 * Another fcport share the same loop_id/nport id.
1797 * Conflict fcport needs to finish cleanup before this
1798 * fcport can proceed to login.
1800 conflict_fcport
->conflict
= ea
->fcport
;
1801 ea
->fcport
->login_pause
= 1;
1803 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1804 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1805 __func__
, __LINE__
, ea
->fcport
->port_name
,
1806 ea
->fcport
->d_id
.b24
, lid
);
1807 qla2x00_clear_loop_id(ea
->fcport
);
1808 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
1810 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1811 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1812 __func__
, __LINE__
, ea
->fcport
->port_name
,
1813 ea
->fcport
->d_id
.b24
, lid
);
1815 qla2x00_clear_loop_id(ea
->fcport
);
1816 set_bit(lid
, vha
->hw
->loop_id_map
);
1817 ea
->fcport
->loop_id
= lid
;
1818 ea
->fcport
->keep_nport_handle
= 0;
1819 qlt_schedule_sess_for_deletion(ea
->fcport
);
1827 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
1830 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
1831 qlt_logo_completion_handler(fcport
, data
[0]);
1832 fcport
->login_gen
++;
1833 fcport
->flags
&= ~FCF_ASYNC_ACTIVE
;
1838 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
1841 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
1842 if (data
[0] == MBS_COMMAND_COMPLETE
) {
1843 qla2x00_update_fcport(vha
, fcport
);
1849 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1850 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1852 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
1857 /****************************************************************************/
1858 /* QLogic ISP2x00 Hardware Support Functions. */
1859 /****************************************************************************/
1862 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
1864 int rval
= QLA_SUCCESS
;
1865 struct qla_hw_data
*ha
= vha
->hw
;
1866 uint32_t idc_major_ver
, idc_minor_ver
;
1869 qla83xx_idc_lock(vha
, 0);
1871 /* SV: TODO: Assign initialization timeout from
1872 * flash-info / other param
1874 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
1875 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
1877 /* Set our fcoe function presence */
1878 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
1879 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
1880 "Error while setting DRV-Presence.\n");
1881 rval
= QLA_FUNCTION_FAILED
;
1885 /* Decide the reset ownership */
1886 qla83xx_reset_ownership(vha
);
1889 * On first protocol driver load:
1890 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1892 * Others: Check compatibility with current IDC Major version.
1894 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
1895 if (ha
->flags
.nic_core_reset_owner
) {
1896 /* Set IDC Major version */
1897 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
1898 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
1900 /* Clearing IDC-Lock-Recovery register */
1901 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
1902 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
1904 * Clear further IDC participation if we are not compatible with
1905 * the current IDC Major Version.
1907 ql_log(ql_log_warn
, vha
, 0xb07d,
1908 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1909 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
1910 __qla83xx_clear_drv_presence(vha
);
1911 rval
= QLA_FUNCTION_FAILED
;
1914 /* Each function sets its supported Minor version. */
1915 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
1916 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
1917 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
1919 if (ha
->flags
.nic_core_reset_owner
) {
1920 memset(config
, 0, sizeof(config
));
1921 if (!qla81xx_get_port_config(vha
, config
))
1922 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
1926 rval
= qla83xx_idc_state_handler(vha
);
1929 qla83xx_idc_unlock(vha
, 0);
1935 * qla2x00_initialize_adapter
1939 * ha = adapter block pointer.
1945 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
1948 struct qla_hw_data
*ha
= vha
->hw
;
1949 struct req_que
*req
= ha
->req_q_map
[0];
1951 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
1952 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
1954 /* Clear adapter flags. */
1955 vha
->flags
.online
= 0;
1956 ha
->flags
.chip_reset_done
= 0;
1957 vha
->flags
.reset_active
= 0;
1958 ha
->flags
.pci_channel_io_perm_failure
= 0;
1959 ha
->flags
.eeh_busy
= 0;
1960 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
1961 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1962 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1963 vha
->device_flags
= DFLG_NO_CABLE
;
1965 vha
->flags
.management_server_logged_in
= 0;
1966 vha
->marker_needed
= 0;
1967 ha
->isp_abort_cnt
= 0;
1968 ha
->beacon_blink_led
= 0;
1970 set_bit(0, ha
->req_qid_map
);
1971 set_bit(0, ha
->rsp_qid_map
);
1973 ql_dbg(ql_dbg_init
, vha
, 0x0040,
1974 "Configuring PCI space...\n");
1975 rval
= ha
->isp_ops
->pci_config(vha
);
1977 ql_log(ql_log_warn
, vha
, 0x0044,
1978 "Unable to configure PCI space.\n");
1982 ha
->isp_ops
->reset_chip(vha
);
1984 rval
= qla2xxx_get_flash_info(vha
);
1986 ql_log(ql_log_fatal
, vha
, 0x004f,
1987 "Unable to validate FLASH data.\n");
1991 if (IS_QLA8044(ha
)) {
1992 qla8044_read_reset_template(vha
);
1994 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1995 * If DONRESET_BIT0 is set, drivers should not set dev_state
1996 * to NEED_RESET. But if NEED_RESET is set, drivers should
1997 * should honor the reset. */
1998 if (ql2xdontresethba
== 1)
1999 qla8044_set_idc_dontreset(vha
);
2002 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
2003 ql_dbg(ql_dbg_init
, vha
, 0x0061,
2004 "Configure NVRAM parameters...\n");
2006 ha
->isp_ops
->nvram_config(vha
);
2008 if (ha
->flags
.disable_serdes
) {
2009 /* Mask HBA via NVRAM settings? */
2010 ql_log(ql_log_info
, vha
, 0x0077,
2011 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
2012 return QLA_FUNCTION_FAILED
;
2015 ql_dbg(ql_dbg_init
, vha
, 0x0078,
2016 "Verifying loaded RISC code...\n");
2018 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
2019 rval
= ha
->isp_ops
->chip_diag(vha
);
2022 rval
= qla2x00_setup_chip(vha
);
2027 if (IS_QLA84XX(ha
)) {
2028 ha
->cs84xx
= qla84xx_get_chip(vha
);
2030 ql_log(ql_log_warn
, vha
, 0x00d0,
2031 "Unable to configure ISP84XX.\n");
2032 return QLA_FUNCTION_FAILED
;
2036 if (qla_ini_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
2037 rval
= qla2x00_init_rings(vha
);
2039 ha
->flags
.chip_reset_done
= 1;
2041 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
2042 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2043 rval
= qla84xx_init_chip(vha
);
2044 if (rval
!= QLA_SUCCESS
) {
2045 ql_log(ql_log_warn
, vha
, 0x00d4,
2046 "Unable to initialize ISP84XX.\n");
2047 qla84xx_put_chip(vha
);
2051 /* Load the NIC Core f/w if we are the first protocol driver. */
2052 if (IS_QLA8031(ha
)) {
2053 rval
= qla83xx_nic_core_fw_load(vha
);
2055 ql_log(ql_log_warn
, vha
, 0x0124,
2056 "Error in initializing NIC Core f/w.\n");
2059 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
2060 qla24xx_read_fcp_prio_cfg(vha
);
2062 if (IS_P3P_TYPE(ha
))
2063 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2065 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2071 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2074 * Returns 0 on success.
2077 qla2100_pci_config(scsi_qla_host_t
*vha
)
2080 unsigned long flags
;
2081 struct qla_hw_data
*ha
= vha
->hw
;
2082 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2084 pci_set_master(ha
->pdev
);
2085 pci_try_set_mwi(ha
->pdev
);
2087 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2088 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2089 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2091 pci_disable_rom(ha
->pdev
);
2093 /* Get PCI bus information. */
2094 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2095 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2096 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2102 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2105 * Returns 0 on success.
2108 qla2300_pci_config(scsi_qla_host_t
*vha
)
2111 unsigned long flags
= 0;
2113 struct qla_hw_data
*ha
= vha
->hw
;
2114 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2116 pci_set_master(ha
->pdev
);
2117 pci_try_set_mwi(ha
->pdev
);
2119 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2120 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2122 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2123 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2124 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2127 * If this is a 2300 card and not 2312, reset the
2128 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2129 * the 2310 also reports itself as a 2300 so we need to get the
2130 * fb revision level -- a 6 indicates it really is a 2300 and
2133 if (IS_QLA2300(ha
)) {
2134 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2137 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2138 for (cnt
= 0; cnt
< 30000; cnt
++) {
2139 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2145 /* Select FPM registers. */
2146 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2147 RD_REG_WORD(®
->ctrl_status
);
2149 /* Get the fb rev level */
2150 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
2152 if (ha
->fb_rev
== FPM_2300
)
2153 pci_clear_mwi(ha
->pdev
);
2155 /* Deselect FPM registers. */
2156 WRT_REG_WORD(®
->ctrl_status
, 0x0);
2157 RD_REG_WORD(®
->ctrl_status
);
2159 /* Release RISC module. */
2160 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2161 for (cnt
= 0; cnt
< 30000; cnt
++) {
2162 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
2168 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2171 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2173 pci_disable_rom(ha
->pdev
);
2175 /* Get PCI bus information. */
2176 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2177 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2178 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2184 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2187 * Returns 0 on success.
2190 qla24xx_pci_config(scsi_qla_host_t
*vha
)
2193 unsigned long flags
= 0;
2194 struct qla_hw_data
*ha
= vha
->hw
;
2195 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2197 pci_set_master(ha
->pdev
);
2198 pci_try_set_mwi(ha
->pdev
);
2200 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2201 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2202 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2203 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2205 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2207 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2208 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
2209 pcix_set_mmrbc(ha
->pdev
, 2048);
2211 /* PCIe -- adjust Maximum Read Request Size (2048). */
2212 if (pci_is_pcie(ha
->pdev
))
2213 pcie_set_readrq(ha
->pdev
, 4096);
2215 pci_disable_rom(ha
->pdev
);
2217 ha
->chip_revision
= ha
->pdev
->revision
;
2219 /* Get PCI bus information. */
2220 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2221 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
2222 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2228 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2231 * Returns 0 on success.
2234 qla25xx_pci_config(scsi_qla_host_t
*vha
)
2237 struct qla_hw_data
*ha
= vha
->hw
;
2239 pci_set_master(ha
->pdev
);
2240 pci_try_set_mwi(ha
->pdev
);
2242 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2243 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2244 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2245 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2247 /* PCIe -- adjust Maximum Read Request Size (2048). */
2248 if (pci_is_pcie(ha
->pdev
))
2249 pcie_set_readrq(ha
->pdev
, 4096);
2251 pci_disable_rom(ha
->pdev
);
2253 ha
->chip_revision
= ha
->pdev
->revision
;
2259 * qla2x00_isp_firmware() - Choose firmware image.
2262 * Returns 0 on success.
2265 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
2268 uint16_t loop_id
, topo
, sw_cap
;
2269 uint8_t domain
, area
, al_pa
;
2270 struct qla_hw_data
*ha
= vha
->hw
;
2272 /* Assume loading risc code */
2273 rval
= QLA_FUNCTION_FAILED
;
2275 if (ha
->flags
.disable_risc_code_load
) {
2276 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
2278 /* Verify checksum of loaded RISC code. */
2279 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
2280 if (rval
== QLA_SUCCESS
) {
2281 /* And, verify we are not in ROM code. */
2282 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
2283 &area
, &domain
, &topo
, &sw_cap
);
2288 ql_dbg(ql_dbg_init
, vha
, 0x007a,
2289 "**** Load RISC code ****.\n");
2295 * qla2x00_reset_chip() - Reset ISP chip.
2298 * Returns 0 on success.
2301 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
2303 unsigned long flags
= 0;
2304 struct qla_hw_data
*ha
= vha
->hw
;
2305 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2309 if (unlikely(pci_channel_offline(ha
->pdev
)))
2312 ha
->isp_ops
->disable_intrs(ha
);
2314 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2316 /* Turn off master enable */
2318 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
2319 cmd
&= ~PCI_COMMAND_MASTER
;
2320 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2322 if (!IS_QLA2100(ha
)) {
2324 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2325 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2326 for (cnt
= 0; cnt
< 30000; cnt
++) {
2327 if ((RD_REG_WORD(®
->hccr
) &
2328 HCCR_RISC_PAUSE
) != 0)
2333 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2337 /* Select FPM registers. */
2338 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2339 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2341 /* FPM Soft Reset. */
2342 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
2343 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2345 /* Toggle Fpm Reset. */
2346 if (!IS_QLA2200(ha
)) {
2347 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
2348 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2351 /* Select frame buffer registers. */
2352 WRT_REG_WORD(®
->ctrl_status
, 0x10);
2353 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2355 /* Reset frame buffer FIFOs. */
2356 if (IS_QLA2200(ha
)) {
2357 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
2358 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
2360 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
2362 /* Read back fb_cmd until zero or 3 seconds max */
2363 for (cnt
= 0; cnt
< 3000; cnt
++) {
2364 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
2370 /* Select RISC module registers. */
2371 WRT_REG_WORD(®
->ctrl_status
, 0);
2372 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2374 /* Reset RISC processor. */
2375 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2376 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2378 /* Release RISC processor. */
2379 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2380 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2383 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
2384 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
2386 /* Reset ISP chip. */
2387 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2389 /* Wait for RISC to recover from reset. */
2390 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2392 * It is necessary to for a delay here since the card doesn't
2393 * respond to PCI reads during a reset. On some architectures
2394 * this will result in an MCA.
2397 for (cnt
= 30000; cnt
; cnt
--) {
2398 if ((RD_REG_WORD(®
->ctrl_status
) &
2399 CSR_ISP_SOFT_RESET
) == 0)
2406 /* Reset RISC processor. */
2407 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2409 WRT_REG_WORD(®
->semaphore
, 0);
2411 /* Release RISC processor. */
2412 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2413 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2415 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2416 for (cnt
= 0; cnt
< 30000; cnt
++) {
2417 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
2425 /* Turn on master enable */
2426 cmd
|= PCI_COMMAND_MASTER
;
2427 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2429 /* Disable RISC pause on FPM parity error. */
2430 if (!IS_QLA2100(ha
)) {
2431 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
2432 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2435 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2439 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2442 * Returns 0 on success.
2445 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
2447 uint16_t mb
[4] = {0x1010, 0, 1, 0};
2449 if (!IS_QLA81XX(vha
->hw
))
2452 return qla81xx_write_mpi_register(vha
, mb
);
2456 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2459 * Returns 0 on success.
2462 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
2464 unsigned long flags
= 0;
2465 struct qla_hw_data
*ha
= vha
->hw
;
2466 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2469 static int abts_cnt
; /* ISP abort retry counts */
2470 int rval
= QLA_SUCCESS
;
2472 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2475 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2476 for (cnt
= 0; cnt
< 30000; cnt
++) {
2477 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
2483 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
))
2484 set_bit(DMA_SHUTDOWN_CMPL
, &ha
->fw_dump_cap_flags
);
2486 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017e,
2487 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2488 RD_REG_DWORD(®
->hccr
),
2489 RD_REG_DWORD(®
->ctrl_status
),
2490 (RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
));
2492 WRT_REG_DWORD(®
->ctrl_status
,
2493 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2494 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2498 /* Wait for firmware to complete NVRAM accesses. */
2499 RD_REG_WORD(®
->mailbox0
);
2500 for (cnt
= 10000; RD_REG_WORD(®
->mailbox0
) != 0 &&
2501 rval
== QLA_SUCCESS
; cnt
--) {
2506 rval
= QLA_FUNCTION_TIMEOUT
;
2509 if (rval
== QLA_SUCCESS
)
2510 set_bit(ISP_MBX_RDY
, &ha
->fw_dump_cap_flags
);
2512 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017f,
2513 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2514 RD_REG_DWORD(®
->hccr
),
2515 RD_REG_DWORD(®
->mailbox0
));
2517 /* Wait for soft-reset to complete. */
2518 RD_REG_DWORD(®
->ctrl_status
);
2519 for (cnt
= 0; cnt
< 60; cnt
++) {
2521 if ((RD_REG_DWORD(®
->ctrl_status
) &
2522 CSRX_ISP_SOFT_RESET
) == 0)
2527 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_ISP_SOFT_RESET
))
2528 set_bit(ISP_SOFT_RESET_CMPL
, &ha
->fw_dump_cap_flags
);
2530 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015d,
2531 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2532 RD_REG_DWORD(®
->hccr
),
2533 RD_REG_DWORD(®
->ctrl_status
));
2535 /* If required, do an MPI FW reset now */
2536 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
2537 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
2538 if (++abts_cnt
< 5) {
2539 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2540 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
2543 * We exhausted the ISP abort retries. We have to
2544 * set the board offline.
2547 vha
->flags
.online
= 0;
2552 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
2553 RD_REG_DWORD(®
->hccr
);
2555 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
2556 RD_REG_DWORD(®
->hccr
);
2558 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
2559 RD_REG_DWORD(®
->hccr
);
2561 RD_REG_WORD(®
->mailbox0
);
2562 for (cnt
= 60; RD_REG_WORD(®
->mailbox0
) != 0 &&
2563 rval
== QLA_SUCCESS
; cnt
--) {
2568 rval
= QLA_FUNCTION_TIMEOUT
;
2570 if (rval
== QLA_SUCCESS
)
2571 set_bit(RISC_RDY_AFT_RESET
, &ha
->fw_dump_cap_flags
);
2573 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015e,
2574 "Host Risc 0x%x, mailbox0 0x%x\n",
2575 RD_REG_DWORD(®
->hccr
),
2576 RD_REG_WORD(®
->mailbox0
));
2578 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2580 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015f,
2581 "Driver in %s mode\n",
2582 IS_NOPOLLING_TYPE(ha
) ? "Interrupt" : "Polling");
2584 if (IS_NOPOLLING_TYPE(ha
))
2585 ha
->isp_ops
->enable_intrs(ha
);
2591 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
2593 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2595 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2596 *data
= RD_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
);
2601 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
2603 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2605 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2606 WRT_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
, data
);
2610 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
2613 uint delta_msec
= 100;
2614 uint elapsed_msec
= 0;
2618 if (vha
->hw
->pdev
->subsystem_device
!= 0x0175 &&
2619 vha
->hw
->pdev
->subsystem_device
!= 0x0240)
2622 WRT_REG_DWORD(&vha
->hw
->iobase
->isp24
.hccr
, HCCRX_SET_RISC_PAUSE
);
2626 timeout_msec
= TIMEOUT_SEMAPHORE
;
2627 n
= timeout_msec
/ delta_msec
;
2629 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
2630 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2631 if (wd32
& RISC_SEMAPHORE
)
2634 elapsed_msec
+= delta_msec
;
2635 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2639 if (!(wd32
& RISC_SEMAPHORE
))
2642 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2645 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
2646 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
2647 n
= timeout_msec
/ delta_msec
;
2649 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2650 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2653 elapsed_msec
+= delta_msec
;
2654 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2658 if (wd32
& RISC_SEMAPHORE_FORCE
)
2659 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
2664 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
2671 * qla24xx_reset_chip() - Reset ISP24xx chip.
2674 * Returns 0 on success.
2677 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
2679 struct qla_hw_data
*ha
= vha
->hw
;
2681 if (pci_channel_offline(ha
->pdev
) &&
2682 ha
->flags
.pci_channel_io_perm_failure
) {
2686 ha
->isp_ops
->disable_intrs(ha
);
2688 qla25xx_manipulate_risc_semaphore(vha
);
2690 /* Perform RISC reset. */
2691 qla24xx_reset_risc(vha
);
2695 * qla2x00_chip_diag() - Test chip for proper operation.
2698 * Returns 0 on success.
2701 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
2704 struct qla_hw_data
*ha
= vha
->hw
;
2705 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2706 unsigned long flags
= 0;
2710 struct req_que
*req
= ha
->req_q_map
[0];
2712 /* Assume a failed state */
2713 rval
= QLA_FUNCTION_FAILED
;
2715 ql_dbg(ql_dbg_init
, vha
, 0x007b, "Testing device at %p.\n",
2716 ®
->flash_address
);
2718 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2720 /* Reset ISP chip. */
2721 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2724 * We need to have a delay here since the card will not respond while
2725 * in reset causing an MCA on some architectures.
2728 data
= qla2x00_debounce_register(®
->ctrl_status
);
2729 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
2731 data
= RD_REG_WORD(®
->ctrl_status
);
2736 goto chip_diag_failed
;
2738 ql_dbg(ql_dbg_init
, vha
, 0x007c,
2739 "Reset register cleared by chip reset.\n");
2741 /* Reset RISC processor. */
2742 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2743 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2745 /* Workaround for QLA2312 PCI parity error */
2746 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2747 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
2748 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
2750 data
= RD_MAILBOX_REG(ha
, reg
, 0);
2757 goto chip_diag_failed
;
2759 /* Check product ID of chip */
2760 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product ID of chip.\n");
2762 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
2763 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
2764 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
2765 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
2766 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
2767 mb
[3] != PROD_ID_3
) {
2768 ql_log(ql_log_warn
, vha
, 0x0062,
2769 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2770 mb
[1], mb
[2], mb
[3]);
2772 goto chip_diag_failed
;
2774 ha
->product_id
[0] = mb
[1];
2775 ha
->product_id
[1] = mb
[2];
2776 ha
->product_id
[2] = mb
[3];
2777 ha
->product_id
[3] = mb
[4];
2779 /* Adjust fw RISC transfer size */
2780 if (req
->length
> 1024)
2781 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
2783 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
2786 if (IS_QLA2200(ha
) &&
2787 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
2788 /* Limit firmware transfer size with a 2200A */
2789 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
2791 ha
->device_type
|= DT_ISP2200A
;
2792 ha
->fw_transfer_size
= 128;
2795 /* Wrap Incoming Mailboxes Test. */
2796 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2798 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
2799 rval
= qla2x00_mbx_reg_test(vha
);
2801 ql_log(ql_log_warn
, vha
, 0x0080,
2802 "Failed mailbox send register test.\n");
2804 /* Flag a successful rval */
2806 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2810 ql_log(ql_log_info
, vha
, 0x0081,
2811 "Chip diagnostics **** FAILED ****.\n");
2813 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2819 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2822 * Returns 0 on success.
2825 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
2828 struct qla_hw_data
*ha
= vha
->hw
;
2829 struct req_que
*req
= ha
->req_q_map
[0];
2831 if (IS_P3P_TYPE(ha
))
2834 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
2836 rval
= qla2x00_mbx_reg_test(vha
);
2838 ql_log(ql_log_warn
, vha
, 0x0082,
2839 "Failed mailbox send register test.\n");
2841 /* Flag a successful rval */
2849 qla2x00_alloc_offload_mem(scsi_qla_host_t
*vha
)
2854 struct qla_hw_data
*ha
= vha
->hw
;
2857 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
2858 "%s: Offload Mem is already allocated.\n",
2863 if (IS_FWI2_CAPABLE(ha
)) {
2864 /* Allocate memory for Fibre Channel Event Buffer. */
2865 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2870 dma_free_coherent(&ha
->pdev
->dev
,
2871 FCE_SIZE
, ha
->fce
, ha
->fce_dma
);
2873 /* Allocate memory for Fibre Channel Event Buffer. */
2874 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
2877 ql_log(ql_log_warn
, vha
, 0x00be,
2878 "Unable to allocate (%d KB) for FCE.\n",
2883 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
2884 ha
->fce_mb
, &ha
->fce_bufs
);
2886 ql_log(ql_log_warn
, vha
, 0x00bf,
2887 "Unable to initialize FCE (%d).\n", rval
);
2888 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
2890 ha
->flags
.fce_enabled
= 0;
2893 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
2894 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
2896 ha
->flags
.fce_enabled
= 1;
2897 ha
->fce_dma
= tc_dma
;
2902 dma_free_coherent(&ha
->pdev
->dev
,
2903 EFT_SIZE
, ha
->eft
, ha
->eft_dma
);
2905 /* Allocate memory for Extended Trace Buffer. */
2906 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
2909 ql_log(ql_log_warn
, vha
, 0x00c1,
2910 "Unable to allocate (%d KB) for EFT.\n",
2915 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
2917 ql_log(ql_log_warn
, vha
, 0x00c2,
2918 "Unable to initialize EFT (%d).\n", rval
);
2919 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
2923 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
2924 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
2926 ha
->eft_dma
= tc_dma
;
2935 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
2937 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
2938 eft_size
, fce_size
, mq_size
;
2939 struct qla_hw_data
*ha
= vha
->hw
;
2940 struct req_que
*req
= ha
->req_q_map
[0];
2941 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
2942 struct qla2xxx_fw_dump
*fw_dump
;
2944 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
2945 req_q_size
= rsp_q_size
= 0;
2947 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2948 fixed_size
= sizeof(struct qla2100_fw_dump
);
2949 } else if (IS_QLA23XX(ha
)) {
2950 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
2951 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
2953 } else if (IS_FWI2_CAPABLE(ha
)) {
2954 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))
2955 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
2956 else if (IS_QLA81XX(ha
))
2957 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
2958 else if (IS_QLA25XX(ha
))
2959 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
2961 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
2963 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
2966 if (!IS_QLA83XX(ha
) && !IS_QLA27XX(ha
))
2967 mq_size
= sizeof(struct qla2xxx_mq_chain
);
2969 * Allocate maximum buffer size for all queues.
2970 * Resizing must be done at end-of-dump processing.
2972 mq_size
+= ha
->max_req_queues
*
2973 (req
->length
* sizeof(request_t
));
2974 mq_size
+= ha
->max_rsp_queues
*
2975 (rsp
->length
* sizeof(response_t
));
2977 if (ha
->tgt
.atio_ring
)
2978 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
2979 /* Allocate memory for Fibre Channel Event Buffer. */
2980 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2984 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
2986 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
2987 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
2988 eft_size
= EFT_SIZE
;
2991 if (IS_QLA27XX(ha
)) {
2992 if (!ha
->fw_dump_template
) {
2993 ql_log(ql_log_warn
, vha
, 0x00ba,
2994 "Failed missing fwdump template\n");
2997 dump_size
= qla27xx_fwdt_calculate_dump_size(vha
);
2998 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
2999 "-> allocating fwdump (%x bytes)...\n", dump_size
);
3003 req_q_size
= req
->length
* sizeof(request_t
);
3004 rsp_q_size
= rsp
->length
* sizeof(response_t
);
3005 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
3006 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
3007 ha
->chain_offset
= dump_size
;
3008 dump_size
+= mq_size
+ fce_size
;
3010 if (ha
->exchoffld_buf
)
3011 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3013 if (ha
->exlogin_buf
)
3014 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
3018 if (!ha
->fw_dump_len
|| dump_size
!= ha
->fw_dump_len
) {
3019 fw_dump
= vmalloc(dump_size
);
3021 ql_log(ql_log_warn
, vha
, 0x00c4,
3022 "Unable to allocate (%d KB) for firmware dump.\n",
3027 ha
->fw_dump
= fw_dump
;
3029 ha
->fw_dump_len
= dump_size
;
3030 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3031 "Allocated (%d KB) for firmware dump.\n",
3037 ha
->fw_dump
->signature
[0] = 'Q';
3038 ha
->fw_dump
->signature
[1] = 'L';
3039 ha
->fw_dump
->signature
[2] = 'G';
3040 ha
->fw_dump
->signature
[3] = 'C';
3041 ha
->fw_dump
->version
= htonl(1);
3043 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
3044 ha
->fw_dump
->mem_size
= htonl(mem_size
);
3045 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
3046 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
3048 ha
->fw_dump
->eft_size
= htonl(eft_size
);
3049 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
3050 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
3052 ha
->fw_dump
->header_size
=
3053 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
3059 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
3061 #define MPS_MASK 0xe0
3066 if (!IS_QLA81XX(vha
->hw
))
3069 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
3070 if (rval
!= QLA_SUCCESS
) {
3071 ql_log(ql_log_warn
, vha
, 0x0105,
3072 "Unable to acquire semaphore.\n");
3076 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
3077 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
3078 if (rval
!= QLA_SUCCESS
) {
3079 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
3084 if (dc
== (dw
& MPS_MASK
))
3089 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
3090 if (rval
!= QLA_SUCCESS
) {
3091 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
3095 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
3096 if (rval
!= QLA_SUCCESS
) {
3097 ql_log(ql_log_warn
, vha
, 0x006d,
3098 "Unable to release semaphore.\n");
3106 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
3108 /* Don't try to reallocate the array */
3109 if (req
->outstanding_cmds
)
3112 if (!IS_FWI2_CAPABLE(ha
))
3113 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
3115 if (ha
->cur_fw_xcb_count
<= ha
->cur_fw_iocb_count
)
3116 req
->num_outstanding_cmds
= ha
->cur_fw_xcb_count
;
3118 req
->num_outstanding_cmds
= ha
->cur_fw_iocb_count
;
3121 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
3122 req
->num_outstanding_cmds
, GFP_KERNEL
);
3124 if (!req
->outstanding_cmds
) {
3126 * Try to allocate a minimal size just so we can get through
3129 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
3130 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
3131 req
->num_outstanding_cmds
, GFP_KERNEL
);
3133 if (!req
->outstanding_cmds
) {
3134 ql_log(ql_log_fatal
, NULL
, 0x0126,
3135 "Failed to allocate memory for "
3136 "outstanding_cmds for req_que %p.\n", req
);
3137 req
->num_outstanding_cmds
= 0;
3138 return QLA_FUNCTION_FAILED
;
3145 #define PRINT_FIELD(_field, _flag, _str) { \
3146 if (a0->_field & _flag) {\
3152 len = snprintf(ptr, leftover, "%s", _str); \
3159 static void qla2xxx_print_sfp_info(struct scsi_qla_host
*vha
)
3162 struct sff_8247_a0
*a0
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3163 u8 str
[STR_LEN
], *ptr
, p
;
3166 memset(str
, 0, STR_LEN
);
3167 snprintf(str
, SFF_VEN_NAME_LEN
+1, a0
->vendor_name
);
3168 ql_dbg(ql_dbg_init
, vha
, 0x015a,
3169 "SFP MFG Name: %s\n", str
);
3171 memset(str
, 0, STR_LEN
);
3172 snprintf(str
, SFF_PART_NAME_LEN
+1, a0
->vendor_pn
);
3173 ql_dbg(ql_dbg_init
, vha
, 0x015c,
3174 "SFP Part Name: %s\n", str
);
3177 memset(str
, 0, STR_LEN
);
3181 PRINT_FIELD(fc_med_cc9
, FC_MED_TW
, "Twin AX");
3182 PRINT_FIELD(fc_med_cc9
, FC_MED_TP
, "Twisted Pair");
3183 PRINT_FIELD(fc_med_cc9
, FC_MED_MI
, "Min Coax");
3184 PRINT_FIELD(fc_med_cc9
, FC_MED_TV
, "Video Coax");
3185 PRINT_FIELD(fc_med_cc9
, FC_MED_M6
, "MultiMode 62.5um");
3186 PRINT_FIELD(fc_med_cc9
, FC_MED_M5
, "MultiMode 50um");
3187 PRINT_FIELD(fc_med_cc9
, FC_MED_SM
, "SingleMode");
3188 ql_dbg(ql_dbg_init
, vha
, 0x0160,
3189 "SFP Media: %s\n", str
);
3192 memset(str
, 0, STR_LEN
);
3196 PRINT_FIELD(fc_ll_cc7
, FC_LL_VL
, "Very Long");
3197 PRINT_FIELD(fc_ll_cc7
, FC_LL_S
, "Short");
3198 PRINT_FIELD(fc_ll_cc7
, FC_LL_I
, "Intermediate");
3199 PRINT_FIELD(fc_ll_cc7
, FC_LL_L
, "Long");
3200 PRINT_FIELD(fc_ll_cc7
, FC_LL_M
, "Medium");
3201 ql_dbg(ql_dbg_init
, vha
, 0x0196,
3202 "SFP Link Length: %s\n", str
);
3204 memset(str
, 0, STR_LEN
);
3208 PRINT_FIELD(fc_ll_cc7
, FC_LL_SA
, "Short Wave (SA)");
3209 PRINT_FIELD(fc_ll_cc7
, FC_LL_LC
, "Long Wave(LC)");
3210 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SN
, "Short Wave (SN)");
3211 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SL
, "Short Wave (SL)");
3212 PRINT_FIELD(fc_tec_cc8
, FC_TEC_LL
, "Long Wave (LL)");
3213 ql_dbg(ql_dbg_init
, vha
, 0x016e,
3214 "SFP FC Link Tech: %s\n", str
);
3217 ql_dbg(ql_dbg_init
, vha
, 0x016f,
3218 "SFP Distant: %d km\n", a0
->length_km
);
3219 if (a0
->length_100m
)
3220 ql_dbg(ql_dbg_init
, vha
, 0x0170,
3221 "SFP Distant: %d m\n", a0
->length_100m
*100);
3222 if (a0
->length_50um_10m
)
3223 ql_dbg(ql_dbg_init
, vha
, 0x0189,
3224 "SFP Distant (WL=50um): %d m\n", a0
->length_50um_10m
* 10);
3225 if (a0
->length_62um_10m
)
3226 ql_dbg(ql_dbg_init
, vha
, 0x018a,
3227 "SFP Distant (WL=62.5um): %d m\n", a0
->length_62um_10m
* 10);
3228 if (a0
->length_om4_10m
)
3229 ql_dbg(ql_dbg_init
, vha
, 0x0194,
3230 "SFP Distant (OM4): %d m\n", a0
->length_om4_10m
* 10);
3231 if (a0
->length_om3_10m
)
3232 ql_dbg(ql_dbg_init
, vha
, 0x0195,
3233 "SFP Distant (OM3): %d m\n", a0
->length_om3_10m
* 10);
3239 * QLA_SUCCESS: no action
3240 * QLA_INTERFACE_ERROR: SFP is not there.
3241 * QLA_FUNCTION_FAILED: detected New SFP
3244 qla24xx_detect_sfp(scsi_qla_host_t
*vha
)
3246 int rc
= QLA_SUCCESS
;
3247 struct sff_8247_a0
*a
;
3248 struct qla_hw_data
*ha
= vha
->hw
;
3250 if (!AUTO_DETECT_SFP_SUPPORT(vha
))
3253 rc
= qla2x00_read_sfp_dev(vha
, NULL
, 0);
3257 a
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3258 qla2xxx_print_sfp_info(vha
);
3260 if (a
->fc_ll_cc7
& FC_LL_VL
|| a
->fc_ll_cc7
& FC_LL_L
) {
3262 ha
->flags
.detected_lr_sfp
= 1;
3264 if (a
->length_km
> 5 || a
->length_100m
> 50)
3265 ha
->long_range_distance
= LR_DISTANCE_10K
;
3267 ha
->long_range_distance
= LR_DISTANCE_5K
;
3269 if (ha
->flags
.detected_lr_sfp
!= ha
->flags
.using_lr_setting
)
3270 ql_dbg(ql_dbg_async
, vha
, 0x507b,
3271 "Detected Long Range SFP.\n");
3274 ha
->flags
.detected_lr_sfp
= 0;
3275 if (ha
->flags
.using_lr_setting
)
3276 ql_dbg(ql_dbg_async
, vha
, 0x5084,
3277 "Detected Short Range SFP.\n");
3280 if (!vha
->flags
.init_done
)
3287 * qla2x00_setup_chip() - Load and start RISC firmware.
3290 * Returns 0 on success.
3293 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
3296 uint32_t srisc_address
= 0;
3297 struct qla_hw_data
*ha
= vha
->hw
;
3298 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3299 unsigned long flags
;
3300 uint16_t fw_major_version
;
3302 if (IS_P3P_TYPE(ha
)) {
3303 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3304 if (rval
== QLA_SUCCESS
) {
3305 qla2x00_stop_firmware(vha
);
3306 goto enable_82xx_npiv
;
3311 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3312 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3313 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3314 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3315 RD_REG_WORD(®
->hccr
);
3316 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3319 qla81xx_mpi_sync(vha
);
3321 /* Load firmware sequences */
3322 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3323 if (rval
== QLA_SUCCESS
) {
3324 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
3325 "Verifying Checksum of loaded RISC code.\n");
3327 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
3328 if (rval
== QLA_SUCCESS
) {
3329 /* Start firmware execution. */
3330 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3331 "Starting firmware.\n");
3334 ha
->flags
.exlogins_enabled
= 1;
3336 if (qla_is_exch_offld_enabled(vha
))
3337 ha
->flags
.exchoffld_enabled
= 1;
3339 rval
= qla2x00_execute_fw(vha
, srisc_address
);
3340 /* Retrieve firmware information. */
3341 if (rval
== QLA_SUCCESS
) {
3342 qla24xx_detect_sfp(vha
);
3344 rval
= qla2x00_set_exlogins_buffer(vha
);
3345 if (rval
!= QLA_SUCCESS
)
3348 rval
= qla2x00_set_exchoffld_buffer(vha
);
3349 if (rval
!= QLA_SUCCESS
)
3353 fw_major_version
= ha
->fw_major_version
;
3354 if (IS_P3P_TYPE(ha
))
3355 qla82xx_check_md_needed(vha
);
3357 rval
= qla2x00_get_fw_version(vha
);
3358 if (rval
!= QLA_SUCCESS
)
3360 ha
->flags
.npiv_supported
= 0;
3361 if (IS_QLA2XXX_MIDTYPE(ha
) &&
3362 (ha
->fw_attributes
& BIT_2
)) {
3363 ha
->flags
.npiv_supported
= 1;
3364 if ((!ha
->max_npiv_vports
) ||
3365 ((ha
->max_npiv_vports
+ 1) %
3366 MIN_MULTI_ID_FABRIC
))
3367 ha
->max_npiv_vports
=
3368 MIN_MULTI_ID_FABRIC
- 1;
3370 qla2x00_get_resource_cnts(vha
);
3373 * Allocate the array of outstanding commands
3374 * now that we know the firmware resources.
3376 rval
= qla2x00_alloc_outstanding_cmds(ha
,
3378 if (rval
!= QLA_SUCCESS
)
3381 if (!fw_major_version
&& !(IS_P3P_TYPE(ha
)))
3382 qla2x00_alloc_offload_mem(vha
);
3384 if (ql2xallocfwdump
&& !(IS_P3P_TYPE(ha
)))
3385 qla2x00_alloc_fw_dump(vha
);
3391 ql_log(ql_log_fatal
, vha
, 0x00cd,
3392 "ISP Firmware failed checksum.\n");
3398 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3399 /* Enable proper parity. */
3400 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3403 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
3405 /* SRAM, Instruction RAM and GP RAM parity */
3406 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
3407 RD_REG_WORD(®
->hccr
);
3408 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3412 ha
->flags
.fac_supported
= 1;
3413 else if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
3416 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
3417 if (rval
== QLA_SUCCESS
) {
3418 ha
->flags
.fac_supported
= 1;
3419 ha
->fdt_block_size
= size
<< 2;
3421 ql_log(ql_log_warn
, vha
, 0x00ce,
3422 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3423 ha
->fw_major_version
, ha
->fw_minor_version
,
3424 ha
->fw_subminor_version
);
3426 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3427 ha
->flags
.fac_supported
= 0;
3434 ql_log(ql_log_fatal
, vha
, 0x00cf,
3435 "Setup chip ****FAILED****.\n");
3442 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3443 * @rsp: response queue
3445 * Beginning of request ring has initialization control block already built
3446 * by nvram config routine.
3448 * Returns 0 on success.
3451 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
3456 rsp
->ring_ptr
= rsp
->ring
;
3457 rsp
->ring_index
= 0;
3458 rsp
->status_srb
= NULL
;
3459 pkt
= rsp
->ring_ptr
;
3460 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
3461 pkt
->signature
= RESPONSE_PROCESSED
;
3467 * qla2x00_update_fw_options() - Read and process firmware options.
3470 * Returns 0 on success.
3473 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
3475 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
3476 struct qla_hw_data
*ha
= vha
->hw
;
3478 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
3479 qla2x00_get_fw_options(vha
, ha
->fw_options
);
3481 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3484 /* Serial Link options. */
3485 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
3486 "Serial link options.\n");
3487 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
3488 (uint8_t *)&ha
->fw_seriallink_options
,
3489 sizeof(ha
->fw_seriallink_options
));
3491 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
3492 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
3493 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
3496 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
3497 emphasis
= (ha
->fw_seriallink_options
[2] &
3498 (BIT_4
| BIT_3
)) >> 3;
3499 tx_sens
= ha
->fw_seriallink_options
[0] &
3500 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3501 rx_sens
= (ha
->fw_seriallink_options
[0] &
3502 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3503 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
3504 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3507 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
3508 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3509 ha
->fw_options
[10] |= BIT_5
|
3510 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3511 (tx_sens
& (BIT_1
| BIT_0
));
3514 swing
= (ha
->fw_seriallink_options
[2] &
3515 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
3516 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
3517 tx_sens
= ha
->fw_seriallink_options
[1] &
3518 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3519 rx_sens
= (ha
->fw_seriallink_options
[1] &
3520 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3521 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
3522 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3525 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
3526 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3527 ha
->fw_options
[11] |= BIT_5
|
3528 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3529 (tx_sens
& (BIT_1
| BIT_0
));
3533 /* Return command IOCBs without waiting for an ABTS to complete. */
3534 ha
->fw_options
[3] |= BIT_13
;
3537 if (ha
->flags
.enable_led_scheme
)
3538 ha
->fw_options
[2] |= BIT_12
;
3540 /* Detect ISP6312. */
3542 ha
->fw_options
[2] |= BIT_13
;
3544 /* Set Retry FLOGI in case of P2P connection */
3545 if (ha
->operating_mode
== P2P
) {
3546 ha
->fw_options
[2] |= BIT_3
;
3547 ql_dbg(ql_dbg_disc
, vha
, 0x2100,
3548 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3549 __func__
, ha
->fw_options
[2]);
3552 /* Update firmware options. */
3553 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3557 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
3560 struct qla_hw_data
*ha
= vha
->hw
;
3562 if (IS_P3P_TYPE(ha
))
3565 /* Hold status IOCBs until ABTS response received. */
3567 ha
->fw_options
[3] |= BIT_12
;
3569 /* Set Retry FLOGI in case of P2P connection */
3570 if (ha
->operating_mode
== P2P
) {
3571 ha
->fw_options
[2] |= BIT_3
;
3572 ql_dbg(ql_dbg_disc
, vha
, 0x2101,
3573 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3574 __func__
, ha
->fw_options
[2]);
3577 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3578 if (ql2xmvasynctoatio
&&
3579 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))) {
3580 if (qla_tgt_mode_enabled(vha
) ||
3581 qla_dual_mode_enabled(vha
))
3582 ha
->fw_options
[2] |= BIT_11
;
3584 ha
->fw_options
[2] &= ~BIT_11
;
3587 if (IS_QLA25XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3589 * Tell FW to track each exchange to prevent
3590 * driver from using stale exchange.
3592 if (qla_tgt_mode_enabled(vha
) ||
3593 qla_dual_mode_enabled(vha
))
3594 ha
->fw_options
[2] |= BIT_4
;
3596 ha
->fw_options
[2] &= ~BIT_4
;
3598 /* Reserve 1/2 of emergency exchanges for ELS.*/
3599 if (qla2xuseresexchforels
)
3600 ha
->fw_options
[2] |= BIT_8
;
3602 ha
->fw_options
[2] &= ~BIT_8
;
3605 ql_dbg(ql_dbg_init
, vha
, 0x00e8,
3606 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3607 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
3608 ha
->fw_options
[3], vha
->host
->active_mode
);
3610 if (ha
->fw_options
[1] || ha
->fw_options
[2] || ha
->fw_options
[3])
3611 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3613 /* Update Serial Link options. */
3614 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
3617 rval
= qla2x00_set_serdes_params(vha
,
3618 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
3619 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
3620 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
3621 if (rval
!= QLA_SUCCESS
) {
3622 ql_log(ql_log_warn
, vha
, 0x0104,
3623 "Unable to update Serial Link options (%x).\n", rval
);
3628 qla2x00_config_rings(struct scsi_qla_host
*vha
)
3630 struct qla_hw_data
*ha
= vha
->hw
;
3631 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3632 struct req_que
*req
= ha
->req_q_map
[0];
3633 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3635 /* Setup ring parameters in initialization control block. */
3636 ha
->init_cb
->request_q_outpointer
= cpu_to_le16(0);
3637 ha
->init_cb
->response_q_inpointer
= cpu_to_le16(0);
3638 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
3639 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
3640 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3641 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3642 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3643 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3645 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
3646 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
3647 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
3648 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
3649 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
3653 qla24xx_config_rings(struct scsi_qla_host
*vha
)
3655 struct qla_hw_data
*ha
= vha
->hw
;
3656 device_reg_t
*reg
= ISP_QUE_REG(ha
, 0);
3657 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
3658 struct qla_msix_entry
*msix
;
3659 struct init_cb_24xx
*icb
;
3661 struct req_que
*req
= ha
->req_q_map
[0];
3662 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3664 /* Setup ring parameters in initialization control block. */
3665 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3666 icb
->request_q_outpointer
= cpu_to_le16(0);
3667 icb
->response_q_inpointer
= cpu_to_le16(0);
3668 icb
->request_q_length
= cpu_to_le16(req
->length
);
3669 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
3670 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3671 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3672 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3673 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3675 /* Setup ATIO queue dma pointers for target mode */
3676 icb
->atio_q_inpointer
= cpu_to_le16(0);
3677 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
3678 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
3679 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
3681 if (IS_SHADOW_REG_CAPABLE(ha
))
3682 icb
->firmware_options_2
|= cpu_to_le32(BIT_30
|BIT_29
);
3684 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3685 icb
->qos
= cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
3686 icb
->rid
= cpu_to_le16(rid
);
3687 if (ha
->flags
.msix_enabled
) {
3688 msix
= &ha
->msix_entries
[1];
3689 ql_dbg(ql_dbg_init
, vha
, 0x0019,
3690 "Registering vector 0x%x for base que.\n",
3692 icb
->msix
= cpu_to_le16(msix
->entry
);
3694 /* Use alternate PCI bus number */
3696 icb
->firmware_options_2
|= cpu_to_le32(BIT_19
);
3697 /* Use alternate PCI devfn */
3699 icb
->firmware_options_2
|= cpu_to_le32(BIT_18
);
3701 /* Use Disable MSIX Handshake mode for capable adapters */
3702 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
3703 (ha
->flags
.msix_enabled
)) {
3704 icb
->firmware_options_2
&= cpu_to_le32(~BIT_22
);
3705 ha
->flags
.disable_msix_handshake
= 1;
3706 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
3707 "MSIX Handshake Disable Mode turned on.\n");
3709 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
3711 icb
->firmware_options_2
|= cpu_to_le32(BIT_23
);
3713 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
3714 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
3715 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
3716 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
3718 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
3719 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
3720 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
3721 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
3723 qlt_24xx_config_rings(vha
);
3726 RD_REG_DWORD(&ioreg
->hccr
);
3730 * qla2x00_init_rings() - Initializes firmware.
3733 * Beginning of request ring has initialization control block already built
3734 * by nvram config routine.
3736 * Returns 0 on success.
3739 qla2x00_init_rings(scsi_qla_host_t
*vha
)
3742 unsigned long flags
= 0;
3744 struct qla_hw_data
*ha
= vha
->hw
;
3745 struct req_que
*req
;
3746 struct rsp_que
*rsp
;
3747 struct mid_init_cb_24xx
*mid_init_cb
=
3748 (struct mid_init_cb_24xx
*) ha
->init_cb
;
3750 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3752 /* Clear outstanding commands array. */
3753 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
3754 req
= ha
->req_q_map
[que
];
3755 if (!req
|| !test_bit(que
, ha
->req_qid_map
))
3757 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
3759 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
3760 req
->outstanding_cmds
[cnt
] = NULL
;
3762 req
->current_outstanding_cmd
= 1;
3764 /* Initialize firmware. */
3765 req
->ring_ptr
= req
->ring
;
3766 req
->ring_index
= 0;
3767 req
->cnt
= req
->length
;
3770 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
3771 rsp
= ha
->rsp_q_map
[que
];
3772 if (!rsp
|| !test_bit(que
, ha
->rsp_qid_map
))
3774 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
3776 /* Initialize response queue entries */
3778 qlafx00_init_response_q_entries(rsp
);
3780 qla2x00_init_response_q_entries(rsp
);
3783 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
3784 ha
->tgt
.atio_ring_index
= 0;
3785 /* Initialize ATIO queue entries */
3786 qlt_init_atio_q_entries(vha
);
3788 ha
->isp_ops
->config_rings(vha
);
3790 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3792 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
3794 if (IS_QLAFX00(ha
)) {
3795 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
3799 /* Update any ISP specific firmware options before initialization. */
3800 ha
->isp_ops
->update_fw_options(vha
);
3802 if (ha
->flags
.npiv_supported
) {
3803 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
3804 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
3805 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
3808 if (IS_FWI2_CAPABLE(ha
)) {
3809 mid_init_cb
->options
= cpu_to_le16(BIT_1
);
3810 mid_init_cb
->init_cb
.execution_throttle
=
3811 cpu_to_le16(ha
->cur_fw_xcb_count
);
3812 ha
->flags
.dport_enabled
=
3813 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_7
) != 0;
3814 ql_dbg(ql_dbg_init
, vha
, 0x0191, "DPORT Support: %s.\n",
3815 (ha
->flags
.dport_enabled
) ? "enabled" : "disabled");
3816 /* FA-WWPN Status */
3817 ha
->flags
.fawwpn_enabled
=
3818 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_6
) != 0;
3819 ql_dbg(ql_dbg_init
, vha
, 0x00bc, "FA-WWPN Support: %s.\n",
3820 (ha
->flags
.fawwpn_enabled
) ? "enabled" : "disabled");
3823 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
3826 ql_log(ql_log_fatal
, vha
, 0x00d2,
3827 "Init Firmware **** FAILED ****.\n");
3829 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
3830 "Init Firmware -- success.\n");
3838 * qla2x00_fw_ready() - Waits for firmware ready.
3841 * Returns 0 on success.
3844 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
3847 unsigned long wtime
, mtime
, cs84xx_time
;
3848 uint16_t min_wait
; /* Minimum wait time if loop is down */
3849 uint16_t wait_time
; /* Wait time if loop is coming ready */
3851 struct qla_hw_data
*ha
= vha
->hw
;
3853 if (IS_QLAFX00(vha
->hw
))
3854 return qlafx00_fw_ready(vha
);
3858 /* Time to wait for loop down */
3859 if (IS_P3P_TYPE(ha
))
3865 * Firmware should take at most one RATOV to login, plus 5 seconds for
3866 * our own processing.
3868 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
3869 wait_time
= min_wait
;
3872 /* Min wait time if loop down */
3873 mtime
= jiffies
+ (min_wait
* HZ
);
3875 /* wait time before firmware ready */
3876 wtime
= jiffies
+ (wait_time
* HZ
);
3878 /* Wait for ISP to finish LIP */
3879 if (!vha
->flags
.init_done
)
3880 ql_log(ql_log_info
, vha
, 0x801e,
3881 "Waiting for LIP to complete.\n");
3884 memset(state
, -1, sizeof(state
));
3885 rval
= qla2x00_get_firmware_state(vha
, state
);
3886 if (rval
== QLA_SUCCESS
) {
3887 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
3888 vha
->device_flags
&= ~DFLG_NO_CABLE
;
3890 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
3891 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
3892 "fw_state=%x 84xx=%x.\n", state
[0],
3894 if ((state
[2] & FSTATE_LOGGED_IN
) &&
3895 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
3896 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
3897 "Sending verify iocb.\n");
3899 cs84xx_time
= jiffies
;
3900 rval
= qla84xx_init_chip(vha
);
3901 if (rval
!= QLA_SUCCESS
) {
3904 "Init chip failed.\n");
3908 /* Add time taken to initialize. */
3909 cs84xx_time
= jiffies
- cs84xx_time
;
3910 wtime
+= cs84xx_time
;
3911 mtime
+= cs84xx_time
;
3912 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
3913 "Increasing wait time by %ld. "
3914 "New time %ld.\n", cs84xx_time
,
3917 } else if (state
[0] == FSTATE_READY
) {
3918 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
3919 "F/W Ready - OK.\n");
3921 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
3922 &ha
->login_timeout
, &ha
->r_a_tov
);
3928 rval
= QLA_FUNCTION_FAILED
;
3930 if (atomic_read(&vha
->loop_down_timer
) &&
3931 state
[0] != FSTATE_READY
) {
3932 /* Loop down. Timeout on min_wait for states
3933 * other than Wait for Login.
3935 if (time_after_eq(jiffies
, mtime
)) {
3936 ql_log(ql_log_info
, vha
, 0x8038,
3937 "Cable is unplugged...\n");
3939 vha
->device_flags
|= DFLG_NO_CABLE
;
3944 /* Mailbox cmd failed. Timeout on min_wait. */
3945 if (time_after_eq(jiffies
, mtime
) ||
3946 ha
->flags
.isp82xx_fw_hung
)
3950 if (time_after_eq(jiffies
, wtime
))
3953 /* Delay for a while */
3957 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
3958 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state
[0],
3959 state
[1], state
[2], state
[3], state
[4], state
[5], jiffies
);
3961 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
3962 ql_log(ql_log_warn
, vha
, 0x803b,
3963 "Firmware ready **** FAILED ****.\n");
3970 * qla2x00_configure_hba
3971 * Setup adapter context.
3974 * ha = adapter state pointer.
3983 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
3992 char connect_type
[22];
3993 struct qla_hw_data
*ha
= vha
->hw
;
3994 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
3996 unsigned long flags
;
3998 /* Get host addresses. */
3999 rval
= qla2x00_get_adapter_id(vha
,
4000 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
4001 if (rval
!= QLA_SUCCESS
) {
4002 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
4003 IS_CNA_CAPABLE(ha
) ||
4004 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
4005 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
4006 "Loop is in a transition state.\n");
4008 ql_log(ql_log_warn
, vha
, 0x2009,
4009 "Unable to get host loop ID.\n");
4010 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
4011 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
4012 ql_log(ql_log_warn
, vha
, 0x1151,
4013 "Doing link init.\n");
4014 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
4017 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
4023 ql_log(ql_log_info
, vha
, 0x200a,
4024 "Cannot get topology - retrying.\n");
4025 return (QLA_FUNCTION_FAILED
);
4028 vha
->loop_id
= loop_id
;
4031 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
4032 ha
->operating_mode
= LOOP
;
4037 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
4038 ha
->current_topology
= ISP_CFG_NL
;
4039 strcpy(connect_type
, "(Loop)");
4043 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
4044 ha
->switch_cap
= sw_cap
;
4045 ha
->current_topology
= ISP_CFG_FL
;
4046 strcpy(connect_type
, "(FL_Port)");
4050 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
4051 ha
->operating_mode
= P2P
;
4052 ha
->current_topology
= ISP_CFG_N
;
4053 strcpy(connect_type
, "(N_Port-to-N_Port)");
4057 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
4058 ha
->switch_cap
= sw_cap
;
4059 ha
->operating_mode
= P2P
;
4060 ha
->current_topology
= ISP_CFG_F
;
4061 strcpy(connect_type
, "(F_Port)");
4065 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
4066 "HBA in unknown topology %x, using NL.\n", topo
);
4067 ha
->current_topology
= ISP_CFG_NL
;
4068 strcpy(connect_type
, "(Loop)");
4072 /* Save Host port and loop ID. */
4073 /* byte order - Big Endian */
4074 id
.b
.domain
= domain
;
4078 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4079 qlt_update_host_map(vha
, id
);
4080 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4082 if (!vha
->flags
.init_done
)
4083 ql_log(ql_log_info
, vha
, 0x2010,
4084 "Topology - %s, Host Loop address 0x%x.\n",
4085 connect_type
, vha
->loop_id
);
4091 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
4096 struct qla_hw_data
*ha
= vha
->hw
;
4097 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
4098 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
4100 if (memcmp(model
, BINZERO
, len
) != 0) {
4101 strncpy(ha
->model_number
, model
, len
);
4102 st
= en
= ha
->model_number
;
4105 if (*en
!= 0x20 && *en
!= 0x00)
4110 index
= (ha
->pdev
->subsystem_device
& 0xff);
4112 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4113 index
< QLA_MODEL_NAMES
)
4114 strncpy(ha
->model_desc
,
4115 qla2x00_model_name
[index
* 2 + 1],
4116 sizeof(ha
->model_desc
) - 1);
4118 index
= (ha
->pdev
->subsystem_device
& 0xff);
4120 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4121 index
< QLA_MODEL_NAMES
) {
4122 strcpy(ha
->model_number
,
4123 qla2x00_model_name
[index
* 2]);
4124 strncpy(ha
->model_desc
,
4125 qla2x00_model_name
[index
* 2 + 1],
4126 sizeof(ha
->model_desc
) - 1);
4128 strcpy(ha
->model_number
, def
);
4131 if (IS_FWI2_CAPABLE(ha
))
4132 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
4133 sizeof(ha
->model_desc
));
4136 /* On sparc systems, obtain port and node WWN from firmware
4139 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
4142 struct qla_hw_data
*ha
= vha
->hw
;
4143 struct pci_dev
*pdev
= ha
->pdev
;
4144 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4148 val
= of_get_property(dp
, "port-wwn", &len
);
4149 if (val
&& len
>= WWN_SIZE
)
4150 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4152 val
= of_get_property(dp
, "node-wwn", &len
);
4153 if (val
&& len
>= WWN_SIZE
)
4154 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4159 * NVRAM configuration for ISP 2xxx
4162 * ha = adapter block pointer.
4165 * initialization control block in response_ring
4166 * host adapters parameters in host adapter block
4172 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
4177 uint8_t *dptr1
, *dptr2
;
4178 struct qla_hw_data
*ha
= vha
->hw
;
4179 init_cb_t
*icb
= ha
->init_cb
;
4180 nvram_t
*nv
= ha
->nvram
;
4181 uint8_t *ptr
= ha
->nvram
;
4182 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4186 /* Determine NVRAM starting address. */
4187 ha
->nvram_size
= sizeof(nvram_t
);
4189 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
4190 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
4191 ha
->nvram_base
= 0x80;
4193 /* Get NVRAM data and calculate checksum. */
4194 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
4195 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
4198 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
4199 "Contents of NVRAM.\n");
4200 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
4201 (uint8_t *)nv
, ha
->nvram_size
);
4203 /* Bad NVRAM data, set defaults parameters. */
4204 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
4205 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
4206 /* Reset NVRAM data. */
4207 ql_log(ql_log_warn
, vha
, 0x0064,
4208 "Inconsistent NVRAM "
4209 "detected: checksum=0x%x id=%c version=0x%x.\n",
4210 chksum
, nv
->id
[0], nv
->nvram_version
);
4211 ql_log(ql_log_warn
, vha
, 0x0065,
4213 "functioning (yet invalid -- WWPN) defaults.\n");
4216 * Set default initialization control block.
4218 memset(nv
, 0, ha
->nvram_size
);
4219 nv
->parameter_block_version
= ICB_VERSION
;
4221 if (IS_QLA23XX(ha
)) {
4222 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4223 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4224 nv
->add_firmware_options
[0] = BIT_5
;
4225 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4226 nv
->frame_payload_size
= 2048;
4227 nv
->special_options
[1] = BIT_7
;
4228 } else if (IS_QLA2200(ha
)) {
4229 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4230 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4231 nv
->add_firmware_options
[0] = BIT_5
;
4232 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4233 nv
->frame_payload_size
= 1024;
4234 } else if (IS_QLA2100(ha
)) {
4235 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
4236 nv
->firmware_options
[1] = BIT_5
;
4237 nv
->frame_payload_size
= 1024;
4240 nv
->max_iocb_allocation
= cpu_to_le16(256);
4241 nv
->execution_throttle
= cpu_to_le16(16);
4242 nv
->retry_count
= 8;
4243 nv
->retry_delay
= 1;
4245 nv
->port_name
[0] = 33;
4246 nv
->port_name
[3] = 224;
4247 nv
->port_name
[4] = 139;
4249 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
4251 nv
->login_timeout
= 4;
4254 * Set default host adapter parameters
4256 nv
->host_p
[1] = BIT_2
;
4257 nv
->reset_delay
= 5;
4258 nv
->port_down_retry_count
= 8;
4259 nv
->max_luns_per_target
= cpu_to_le16(8);
4260 nv
->link_down_timeout
= 60;
4265 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4267 * The SN2 does not provide BIOS emulation which means you can't change
4268 * potentially bogus BIOS settings. Force the use of default settings
4269 * for link rate and frame size. Hope that the rest of the settings
4272 if (ia64_platform_is("sn2")) {
4273 nv
->frame_payload_size
= 2048;
4275 nv
->special_options
[1] = BIT_7
;
4279 /* Reset Initialization control block */
4280 memset(icb
, 0, ha
->init_cb_size
);
4283 * Setup driver NVRAM options.
4285 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
4286 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
4287 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
4288 nv
->firmware_options
[1] &= ~BIT_4
;
4290 if (IS_QLA23XX(ha
)) {
4291 nv
->firmware_options
[0] |= BIT_2
;
4292 nv
->firmware_options
[0] &= ~BIT_3
;
4293 nv
->special_options
[0] &= ~BIT_6
;
4294 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
4296 if (IS_QLA2300(ha
)) {
4297 if (ha
->fb_rev
== FPM_2310
) {
4298 strcpy(ha
->model_number
, "QLA2310");
4300 strcpy(ha
->model_number
, "QLA2300");
4303 qla2x00_set_model_info(vha
, nv
->model_number
,
4304 sizeof(nv
->model_number
), "QLA23xx");
4306 } else if (IS_QLA2200(ha
)) {
4307 nv
->firmware_options
[0] |= BIT_2
;
4309 * 'Point-to-point preferred, else loop' is not a safe
4310 * connection mode setting.
4312 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
4314 /* Force 'loop preferred, else point-to-point'. */
4315 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
4316 nv
->add_firmware_options
[0] |= BIT_5
;
4318 strcpy(ha
->model_number
, "QLA22xx");
4319 } else /*if (IS_QLA2100(ha))*/ {
4320 strcpy(ha
->model_number
, "QLA2100");
4324 * Copy over NVRAM RISC parameter block to initialization control block.
4326 dptr1
= (uint8_t *)icb
;
4327 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
4328 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
4330 *dptr1
++ = *dptr2
++;
4332 /* Copy 2nd half. */
4333 dptr1
= (uint8_t *)icb
->add_firmware_options
;
4334 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
4336 *dptr1
++ = *dptr2
++;
4338 /* Use alternate WWN? */
4339 if (nv
->host_p
[1] & BIT_7
) {
4340 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4341 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4344 /* Prepare nodename */
4345 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
4347 * Firmware will apply the following mask if the nodename was
4350 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4351 icb
->node_name
[0] &= 0xF0;
4355 * Set host adapter parameters.
4359 * BIT_7 in the host-parameters section allows for modification to
4360 * internal driver logging.
4362 if (nv
->host_p
[0] & BIT_7
)
4363 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
4364 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
4365 /* Always load RISC code on non ISP2[12]00 chips. */
4366 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
4367 ha
->flags
.disable_risc_code_load
= 0;
4368 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
4369 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
4370 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
4371 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
4372 ha
->flags
.disable_serdes
= 0;
4374 ha
->operating_mode
=
4375 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4377 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
4378 sizeof(ha
->fw_seriallink_options
));
4380 /* save HBA serial number */
4381 ha
->serial0
= icb
->port_name
[5];
4382 ha
->serial1
= icb
->port_name
[6];
4383 ha
->serial2
= icb
->port_name
[7];
4384 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4385 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4387 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
4389 ha
->retry_count
= nv
->retry_count
;
4391 /* Set minimum login_timeout to 4 seconds. */
4392 if (nv
->login_timeout
!= ql2xlogintimeout
)
4393 nv
->login_timeout
= ql2xlogintimeout
;
4394 if (nv
->login_timeout
< 4)
4395 nv
->login_timeout
= 4;
4396 ha
->login_timeout
= nv
->login_timeout
;
4398 /* Set minimum RATOV to 100 tenths of a second. */
4401 ha
->loop_reset_delay
= nv
->reset_delay
;
4403 /* Link Down Timeout = 0:
4405 * When Port Down timer expires we will start returning
4406 * I/O's to OS with "DID_NO_CONNECT".
4408 * Link Down Timeout != 0:
4410 * The driver waits for the link to come up after link down
4411 * before returning I/Os to OS with "DID_NO_CONNECT".
4413 if (nv
->link_down_timeout
== 0) {
4414 ha
->loop_down_abort_time
=
4415 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4417 ha
->link_down_timeout
= nv
->link_down_timeout
;
4418 ha
->loop_down_abort_time
=
4419 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4423 * Need enough time to try and get the port back.
4425 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
4426 if (qlport_down_retry
)
4427 ha
->port_down_retry_count
= qlport_down_retry
;
4428 /* Set login_retry_count */
4429 ha
->login_retry_count
= nv
->retry_count
;
4430 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
4431 ha
->port_down_retry_count
> 3)
4432 ha
->login_retry_count
= ha
->port_down_retry_count
;
4433 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4434 ha
->login_retry_count
= ha
->port_down_retry_count
;
4435 if (ql2xloginretrycount
)
4436 ha
->login_retry_count
= ql2xloginretrycount
;
4438 icb
->lun_enables
= cpu_to_le16(0);
4439 icb
->command_resource_count
= 0;
4440 icb
->immediate_notify_resource_count
= 0;
4441 icb
->timeout
= cpu_to_le16(0);
4443 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
4445 icb
->firmware_options
[0] &= ~BIT_3
;
4446 icb
->add_firmware_options
[0] &=
4447 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4448 icb
->add_firmware_options
[0] |= BIT_2
;
4449 icb
->response_accumulation_timer
= 3;
4450 icb
->interrupt_delay_timer
= 5;
4452 vha
->flags
.process_response_queue
= 1;
4455 if (!vha
->flags
.init_done
) {
4456 ha
->zio_mode
= icb
->add_firmware_options
[0] &
4457 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4458 ha
->zio_timer
= icb
->interrupt_delay_timer
?
4459 icb
->interrupt_delay_timer
: 2;
4461 icb
->add_firmware_options
[0] &=
4462 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4463 vha
->flags
.process_response_queue
= 0;
4464 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4465 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4467 ql_log(ql_log_info
, vha
, 0x0068,
4468 "ZIO mode %d enabled; timer delay (%d us).\n",
4469 ha
->zio_mode
, ha
->zio_timer
* 100);
4471 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
4472 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
4473 vha
->flags
.process_response_queue
= 1;
4478 ql_log(ql_log_warn
, vha
, 0x0069,
4479 "NVRAM configuration failed.\n");
4485 qla2x00_rport_del(void *data
)
4487 fc_port_t
*fcport
= data
;
4488 struct fc_rport
*rport
;
4489 unsigned long flags
;
4491 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
4492 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
4493 fcport
->drport
= NULL
;
4494 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
4496 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210b,
4497 "%s %8phN. rport %p roles %x\n",
4498 __func__
, fcport
->port_name
, rport
,
4501 fc_remote_port_delete(rport
);
4506 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4508 * @flags: allocation flags
4510 * Returns a pointer to the allocated fcport, or NULL, if none available.
4513 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
4517 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
4521 /* Setup fcport template structure. */
4523 fcport
->port_type
= FCT_UNKNOWN
;
4524 fcport
->loop_id
= FC_NO_LOOP_ID
;
4525 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
4526 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
4528 fcport
->ct_desc
.ct_sns
= dma_alloc_coherent(&vha
->hw
->pdev
->dev
,
4529 sizeof(struct ct_sns_pkt
), &fcport
->ct_desc
.ct_sns_dma
,
4531 fcport
->disc_state
= DSC_DELETED
;
4532 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4533 fcport
->deleted
= QLA_SESS_DELETED
;
4534 fcport
->login_retry
= vha
->hw
->login_retry_count
;
4535 fcport
->login_retry
= 5;
4536 fcport
->logout_on_delete
= 1;
4538 if (!fcport
->ct_desc
.ct_sns
) {
4539 ql_log(ql_log_warn
, vha
, 0xd049,
4540 "Failed to allocate ct_sns request.\n");
4544 INIT_WORK(&fcport
->del_work
, qla24xx_delete_sess_fn
);
4545 INIT_LIST_HEAD(&fcport
->gnl_entry
);
4546 INIT_LIST_HEAD(&fcport
->list
);
4552 qla2x00_free_fcport(fc_port_t
*fcport
)
4554 if (fcport
->ct_desc
.ct_sns
) {
4555 dma_free_coherent(&fcport
->vha
->hw
->pdev
->dev
,
4556 sizeof(struct ct_sns_pkt
), fcport
->ct_desc
.ct_sns
,
4557 fcport
->ct_desc
.ct_sns_dma
);
4559 fcport
->ct_desc
.ct_sns
= NULL
;
4565 * qla2x00_configure_loop
4566 * Updates Fibre Channel Device Database with what is actually on loop.
4569 * ha = adapter block pointer.
4574 * 2 = database was full and device was not configured.
4577 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
4580 unsigned long flags
, save_flags
;
4581 struct qla_hw_data
*ha
= vha
->hw
;
4584 /* Get Initiator ID */
4585 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
4586 rval
= qla2x00_configure_hba(vha
);
4587 if (rval
!= QLA_SUCCESS
) {
4588 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
4589 "Unable to configure HBA.\n");
4594 save_flags
= flags
= vha
->dpc_flags
;
4595 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
4596 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
4599 * If we have both an RSCN and PORT UPDATE pending then handle them
4600 * both at the same time.
4602 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4603 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4605 qla2x00_get_data_rate(vha
);
4607 /* Determine what we need to do */
4608 if (ha
->current_topology
== ISP_CFG_FL
&&
4609 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4611 set_bit(RSCN_UPDATE
, &flags
);
4613 } else if (ha
->current_topology
== ISP_CFG_F
&&
4614 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4616 set_bit(RSCN_UPDATE
, &flags
);
4617 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4619 } else if (ha
->current_topology
== ISP_CFG_N
) {
4620 clear_bit(RSCN_UPDATE
, &flags
);
4621 if (ha
->flags
.rida_fmt2
) {
4622 /* With Rida Format 2, the login is already triggered.
4623 * We know who is on the other side of the wire.
4624 * No need to login to do login to find out or drop into
4625 * qla2x00_configure_local_loop().
4627 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4628 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4630 if (qla_tgt_mode_enabled(vha
)) {
4631 /* allow the other side to start the login */
4632 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4633 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4636 } else if (ha
->current_topology
== ISP_CFG_NL
) {
4637 clear_bit(RSCN_UPDATE
, &flags
);
4638 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4639 } else if (!vha
->flags
.online
||
4640 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
4641 set_bit(RSCN_UPDATE
, &flags
);
4642 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4645 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
4646 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4647 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
4648 "Loop resync needed, failing.\n");
4649 rval
= QLA_FUNCTION_FAILED
;
4651 rval
= qla2x00_configure_local_loop(vha
);
4654 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
4655 if (LOOP_TRANSITION(vha
)) {
4656 ql_dbg(ql_dbg_disc
, vha
, 0x2099,
4657 "Needs RSCN update and loop transition.\n");
4658 rval
= QLA_FUNCTION_FAILED
;
4661 rval
= qla2x00_configure_fabric(vha
);
4664 if (rval
== QLA_SUCCESS
) {
4665 if (atomic_read(&vha
->loop_down_timer
) ||
4666 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4667 rval
= QLA_FUNCTION_FAILED
;
4669 atomic_set(&vha
->loop_state
, LOOP_READY
);
4670 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
4672 ha
->flags
.fw_init_done
= 1;
4675 * Process any ATIO queue entries that came in
4676 * while we weren't online.
4678 if (qla_tgt_mode_enabled(vha
) ||
4679 qla_dual_mode_enabled(vha
)) {
4680 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
)) {
4681 spin_lock_irqsave(&ha
->tgt
.atio_lock
,
4683 qlt_24xx_process_atio_queue(vha
, 0);
4684 spin_unlock_irqrestore(
4685 &ha
->tgt
.atio_lock
, flags
);
4687 spin_lock_irqsave(&ha
->hardware_lock
,
4689 qlt_24xx_process_atio_queue(vha
, 1);
4690 spin_unlock_irqrestore(
4691 &ha
->hardware_lock
, flags
);
4698 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
4699 "%s *** FAILED ***.\n", __func__
);
4701 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
4702 "%s: exiting normally.\n", __func__
);
4705 /* Restore state if a resync event occurred during processing */
4706 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4707 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
4708 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4709 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
4710 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4719 * Updates Fibre Channel Device Database with local loop devices.
4722 * ha = adapter block pointer.
4726 static int qla24xx_n2n_handle_login(struct scsi_qla_host
*vha
,
4729 struct qla_hw_data
*ha
= vha
->hw
;
4730 int res
= QLA_SUCCESS
, rval
;
4731 int greater_wwpn
= 0;
4734 if (ha
->current_topology
!= ISP_CFG_N
)
4737 if (wwn_to_u64(vha
->port_name
) >
4738 wwn_to_u64(vha
->n2n_port_name
)) {
4739 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
4740 "HBA WWPN is greater %llx > target %llx\n",
4741 wwn_to_u64(vha
->port_name
),
4742 wwn_to_u64(vha
->n2n_port_name
));
4744 fcport
->d_id
.b24
= vha
->n2n_id
;
4747 fcport
->loop_id
= vha
->loop_id
;
4748 fcport
->fc4f_nvme
= 0;
4751 ql_dbg(ql_dbg_disc
, vha
, 0x4001,
4752 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4753 fcport
->d_id
.b24
, vha
->loop_id
);
4755 /* Fill in member data. */
4756 if (!greater_wwpn
) {
4757 rval
= qla2x00_get_port_database(vha
, fcport
, 0);
4758 ql_dbg(ql_dbg_disc
, vha
, 0x1051,
4759 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4760 fcport
->current_login_state
, fcport
->last_login_state
,
4761 fcport
->d_id
.b24
, fcport
->loop_id
, rval
);
4763 if (((fcport
->current_login_state
& 0xf) == 0x4) ||
4764 ((fcport
->current_login_state
& 0xf) == 0x6))
4768 if (logged_in
|| greater_wwpn
) {
4769 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
4770 qla_nvme_register_hba(vha
);
4772 /* Set connected N_Port d_id */
4773 if (vha
->flags
.nvme_enabled
)
4774 fcport
->fc4f_nvme
= 1;
4776 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4777 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4778 fcport
->disc_state
= DSC_GNL
;
4779 fcport
->n2n_flag
= 1;
4781 vha
->hw
->flags
.gpsc_supported
= 0;
4784 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
4785 "%s %d PLOGI ELS %8phC\n",
4786 __func__
, __LINE__
, fcport
->port_name
);
4788 res
= qla24xx_els_dcmd2_iocb(vha
, ELS_DCMD_PLOGI
,
4789 fcport
, fcport
->d_id
);
4792 if (res
!= QLA_SUCCESS
) {
4793 ql_log(ql_log_info
, vha
, 0xd04d,
4794 "PLOGI Failed: portid=%06x - retrying\n",
4798 /* State 0x6 means FCP PRLI complete */
4799 if ((fcport
->current_login_state
& 0xf) == 0x6) {
4800 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
4801 "%s %d %8phC post GPDB work\n",
4802 __func__
, __LINE__
, fcport
->port_name
);
4803 fcport
->chip_reset
=
4804 vha
->hw
->base_qpair
->chip_reset
;
4805 qla24xx_post_gpdb_work(vha
, fcport
, 0);
4807 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
4808 "%s %d %8phC post NVMe PRLI\n",
4809 __func__
, __LINE__
, fcport
->port_name
);
4810 qla24xx_post_prli_work(vha
, fcport
);
4814 /* Wait for next database change */
4815 set_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
);
4822 * qla2x00_configure_local_loop
4823 * Updates Fibre Channel Device Database with local loop devices.
4826 * ha = adapter block pointer.
4832 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
4837 fc_port_t
*fcport
, *new_fcport
;
4843 uint8_t domain
, area
, al_pa
;
4844 struct qla_hw_data
*ha
= vha
->hw
;
4845 unsigned long flags
;
4849 entries
= MAX_FIBRE_DEVICES_LOOP
;
4851 /* Get list of logged in devices. */
4852 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
4853 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
4855 if (rval
!= QLA_SUCCESS
)
4856 goto cleanup_allocation
;
4858 ql_dbg(ql_dbg_disc
, vha
, 0x2011,
4859 "Entries in ID list (%d).\n", entries
);
4860 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
4861 (uint8_t *)ha
->gid_list
,
4862 entries
* sizeof(struct gid_list_info
));
4864 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4865 fcport
->scan_state
= QLA_FCPORT_SCAN
;
4868 /* Allocate temporary fcport for any new fcports discovered. */
4869 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4870 if (new_fcport
== NULL
) {
4871 ql_log(ql_log_warn
, vha
, 0x2012,
4872 "Memory allocation failed for fcport.\n");
4873 rval
= QLA_MEMORY_ALLOC_FAILED
;
4874 goto cleanup_allocation
;
4876 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4878 /* Inititae N2N login. */
4879 if (test_and_clear_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
)) {
4880 rval
= qla24xx_n2n_handle_login(vha
, new_fcport
);
4881 if (rval
!= QLA_SUCCESS
)
4882 goto cleanup_allocation
;
4886 /* Add devices to port list. */
4887 id_iter
= (char *)ha
->gid_list
;
4888 for (index
= 0; index
< entries
; index
++) {
4889 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
4890 area
= ((struct gid_list_info
*)id_iter
)->area
;
4891 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
4892 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
4893 loop_id
= (uint16_t)
4894 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
4896 loop_id
= le16_to_cpu(
4897 ((struct gid_list_info
*)id_iter
)->loop_id
);
4898 id_iter
+= ha
->gid_list_info_size
;
4900 /* Bypass reserved domain fields. */
4901 if ((domain
& 0xf0) == 0xf0)
4904 /* Bypass if not same domain and area of adapter. */
4905 if (area
&& domain
&&
4906 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
4909 /* Bypass invalid local loop ID. */
4910 if (loop_id
> LAST_LOCAL_LOOP_ID
)
4913 memset(new_fcport
->port_name
, 0, WWN_SIZE
);
4915 /* Fill in member data. */
4916 new_fcport
->d_id
.b
.domain
= domain
;
4917 new_fcport
->d_id
.b
.area
= area
;
4918 new_fcport
->d_id
.b
.al_pa
= al_pa
;
4919 new_fcport
->loop_id
= loop_id
;
4920 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
4922 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
4923 if (rval2
!= QLA_SUCCESS
) {
4924 ql_dbg(ql_dbg_disc
, vha
, 0x2097,
4925 "Failed to retrieve fcport information "
4926 "-- get_port_database=%x, loop_id=0x%04x.\n",
4927 rval2
, new_fcport
->loop_id
);
4928 /* Skip retry if N2N */
4929 if (ha
->current_topology
!= ISP_CFG_N
) {
4930 ql_dbg(ql_dbg_disc
, vha
, 0x2105,
4931 "Scheduling resync.\n");
4932 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4937 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4938 /* Check for matching device in port list. */
4941 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4942 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
4946 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4947 fcport
->loop_id
= new_fcport
->loop_id
;
4948 fcport
->port_type
= new_fcport
->port_type
;
4949 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
4950 memcpy(fcport
->node_name
, new_fcport
->node_name
,
4952 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4958 /* New device, add to fcports list. */
4959 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
4961 /* Allocate a new replacement fcport. */
4962 fcport
= new_fcport
;
4964 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4966 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4968 if (new_fcport
== NULL
) {
4969 ql_log(ql_log_warn
, vha
, 0xd031,
4970 "Failed to allocate memory for fcport.\n");
4971 rval
= QLA_MEMORY_ALLOC_FAILED
;
4972 goto cleanup_allocation
;
4974 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4975 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4978 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4980 /* Base iIDMA settings on HBA port speed. */
4981 fcport
->fp_speed
= ha
->link_data_rate
;
4986 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4987 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
4990 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
4991 if ((qla_dual_mode_enabled(vha
) ||
4992 qla_ini_mode_enabled(vha
)) &&
4993 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
4994 qla2x00_mark_device_lost(vha
, fcport
,
4995 ql2xplogiabsentdevice
, 0);
4996 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
4997 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
4998 fcport
->port_type
!= FCT_INITIATOR
&&
4999 fcport
->port_type
!= FCT_BROADCAST
) {
5000 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5001 "%s %d %8phC post del sess\n",
5005 qlt_schedule_sess_for_deletion(fcport
);
5011 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5012 qla24xx_fcport_handle_login(vha
, fcport
);
5018 if (rval
!= QLA_SUCCESS
) {
5019 ql_dbg(ql_dbg_disc
, vha
, 0x2098,
5020 "Configure local loop error exit: rval=%x.\n", rval
);
5027 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5030 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5031 struct qla_hw_data
*ha
= vha
->hw
;
5033 if (!IS_IIDMA_CAPABLE(ha
))
5036 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
5039 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
5040 fcport
->fp_speed
> ha
->link_data_rate
)
5043 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
5045 if (rval
!= QLA_SUCCESS
) {
5046 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
5047 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5048 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
5050 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
5051 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5052 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
5053 fcport
->fp_speed
, fcport
->port_name
);
5057 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5059 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5061 struct fc_rport_identifiers rport_ids
;
5062 struct fc_rport
*rport
;
5063 unsigned long flags
;
5065 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
5066 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
5067 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
5068 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
5069 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5070 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
5072 ql_log(ql_log_warn
, vha
, 0x2006,
5073 "Unable to allocate fc remote port.\n");
5077 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
5078 *((fc_port_t
**)rport
->dd_data
) = fcport
;
5079 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
5081 rport
->supported_classes
= fcport
->supported_classes
;
5083 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5084 if (fcport
->port_type
== FCT_INITIATOR
)
5085 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
5086 if (fcport
->port_type
== FCT_TARGET
)
5087 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
5089 ql_dbg(ql_dbg_disc
, vha
, 0x20ee,
5090 "%s %8phN. rport %p is %s mode\n",
5091 __func__
, fcport
->port_name
, rport
,
5092 (fcport
->port_type
== FCT_TARGET
) ? "tgt" : "ini");
5094 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
5098 * qla2x00_update_fcport
5099 * Updates device on list.
5102 * ha = adapter block pointer.
5103 * fcport = port structure pointer.
5113 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5117 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5120 ql_dbg(ql_dbg_disc
, vha
, 0x20ef, "%s %8phC\n",
5121 __func__
, fcport
->port_name
);
5123 if (IS_QLAFX00(vha
->hw
)) {
5124 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5127 fcport
->login_retry
= 0;
5128 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
5129 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5130 fcport
->deleted
= 0;
5131 fcport
->logout_on_delete
= 1;
5133 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5134 qla2x00_iidma_fcport(vha
, fcport
);
5136 if (fcport
->fc4f_nvme
) {
5137 qla_nvme_register_remote(vha
, fcport
);
5141 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5144 switch (vha
->host
->active_mode
) {
5145 case MODE_INITIATOR
:
5146 qla2x00_reg_remote_port(vha
, fcport
);
5149 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5150 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5151 qlt_fc_port_added(vha
, fcport
);
5154 qla2x00_reg_remote_port(vha
, fcport
);
5155 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5156 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5157 qlt_fc_port_added(vha
, fcport
);
5165 * qla2x00_configure_fabric
5166 * Setup SNS devices with loop ID's.
5169 * ha = adapter block pointer.
5176 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
5180 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5182 LIST_HEAD(new_fcports
);
5183 struct qla_hw_data
*ha
= vha
->hw
;
5186 /* If FL port exists, then SNS is present */
5187 if (IS_FWI2_CAPABLE(ha
))
5188 loop_id
= NPH_F_PORT
;
5190 loop_id
= SNS_FL_PORT
;
5191 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
5192 if (rval
!= QLA_SUCCESS
) {
5193 ql_dbg(ql_dbg_disc
, vha
, 0x20a0,
5194 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5196 vha
->device_flags
&= ~SWITCH_FOUND
;
5197 return (QLA_SUCCESS
);
5199 vha
->device_flags
|= SWITCH_FOUND
;
5202 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
5203 rval
= qla2x00_send_change_request(vha
, 0x3, 0);
5204 if (rval
!= QLA_SUCCESS
)
5205 ql_log(ql_log_warn
, vha
, 0x121,
5206 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5212 qla2x00_mgmt_svr_login(vha
);
5215 if (ql2xfdmienable
&&
5216 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
5217 qla2x00_fdmi_register(vha
);
5219 /* Ensure we are logged into the SNS. */
5220 loop_id
= NPH_SNS_LID(ha
);
5221 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
5222 0xfc, mb
, BIT_1
|BIT_0
);
5223 if (rval
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5224 ql_dbg(ql_dbg_disc
, vha
, 0x20a1,
5225 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5226 loop_id
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7], rval
);
5227 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5230 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
5231 if (qla2x00_rft_id(vha
)) {
5233 ql_dbg(ql_dbg_disc
, vha
, 0x20a2,
5234 "Register FC-4 TYPE failed.\n");
5235 if (test_bit(LOOP_RESYNC_NEEDED
,
5239 if (qla2x00_rff_id(vha
, FC4_TYPE_FCP_SCSI
)) {
5241 ql_dbg(ql_dbg_disc
, vha
, 0x209a,
5242 "Register FC-4 Features failed.\n");
5243 if (test_bit(LOOP_RESYNC_NEEDED
,
5247 if (vha
->flags
.nvme_enabled
) {
5248 if (qla2x00_rff_id(vha
, FC_TYPE_NVME
)) {
5249 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
5250 "Register NVME FC Type Features failed.\n");
5253 if (qla2x00_rnn_id(vha
)) {
5255 ql_dbg(ql_dbg_disc
, vha
, 0x2104,
5256 "Register Node Name failed.\n");
5257 if (test_bit(LOOP_RESYNC_NEEDED
,
5260 } else if (qla2x00_rsnn_nn(vha
)) {
5262 ql_dbg(ql_dbg_disc
, vha
, 0x209b,
5263 "Register Symbolic Node Name failed.\n");
5264 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5270 /* Mark the time right before querying FW for connected ports.
5271 * This process is long, asynchronous and by the time it's done,
5272 * collected information might not be accurate anymore. E.g.
5273 * disconnected port might have re-connected and a brand new
5274 * session has been created. In this case session's generation
5275 * will be newer than discovery_gen. */
5276 qlt_do_generation_tick(vha
, &discovery_gen
);
5278 if (USE_ASYNC_SCAN(ha
)) {
5279 rval
= qla24xx_async_gpnft(vha
, FC4_TYPE_FCP_SCSI
,
5282 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5284 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5285 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5287 rval
= qla2x00_find_all_fabric_devs(vha
);
5289 if (rval
!= QLA_SUCCESS
)
5293 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
5294 qla_nvme_register_hba(vha
);
5297 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
5298 "Configure fabric error exit rval=%d.\n", rval
);
5304 * qla2x00_find_all_fabric_devs
5307 * ha = adapter block pointer.
5308 * dev = database device entry pointer.
5317 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
)
5321 fc_port_t
*fcport
, *new_fcport
;
5326 int first_dev
, last_dev
;
5327 port_id_t wrap
= {}, nxt_d_id
;
5328 struct qla_hw_data
*ha
= vha
->hw
;
5329 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5330 unsigned long flags
;
5334 /* Try GID_PT to get device list, else GAN. */
5336 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
5341 ql_dbg(ql_dbg_disc
, vha
, 0x209c,
5342 "GID_PT allocations failed, fallback on GA_NXT.\n");
5344 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
5345 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
5347 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5349 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
5351 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5353 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
5355 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5357 } else if (qla2x00_gfpn_id(vha
, swl
) != QLA_SUCCESS
) {
5359 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5363 /* If other queries succeeded probe for FC-4 type */
5365 qla2x00_gff_id(vha
, swl
);
5366 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5372 /* Allocate temporary fcport for any new fcports discovered. */
5373 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5374 if (new_fcport
== NULL
) {
5375 ql_log(ql_log_warn
, vha
, 0x209d,
5376 "Failed to allocate memory for fcport.\n");
5377 return (QLA_MEMORY_ALLOC_FAILED
);
5379 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5380 /* Set start port ID scan at adapter ID. */
5384 /* Starting free loop ID. */
5385 loop_id
= ha
->min_external_loopid
;
5386 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
5387 if (qla2x00_is_reserved_id(vha
, loop_id
))
5390 if (ha
->current_topology
== ISP_CFG_FL
&&
5391 (atomic_read(&vha
->loop_down_timer
) ||
5392 LOOP_TRANSITION(vha
))) {
5393 atomic_set(&vha
->loop_down_timer
, 0);
5394 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5395 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5401 wrap
.b24
= new_fcport
->d_id
.b24
;
5403 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
5404 memcpy(new_fcport
->node_name
,
5405 swl
[swl_idx
].node_name
, WWN_SIZE
);
5406 memcpy(new_fcport
->port_name
,
5407 swl
[swl_idx
].port_name
, WWN_SIZE
);
5408 memcpy(new_fcport
->fabric_port_name
,
5409 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
5410 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
5411 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
5413 new_fcport
->nvme_flag
= 0;
5414 new_fcport
->fc4f_nvme
= 0;
5415 if (vha
->flags
.nvme_enabled
&&
5416 swl
[swl_idx
].fc4f_nvme
) {
5417 new_fcport
->fc4f_nvme
=
5418 swl
[swl_idx
].fc4f_nvme
;
5419 ql_log(ql_log_info
, vha
, 0x2131,
5420 "FOUND: NVME port %8phC as FC Type 28h\n",
5421 new_fcport
->port_name
);
5424 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
5430 /* Send GA_NXT to the switch */
5431 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
5432 if (rval
!= QLA_SUCCESS
) {
5433 ql_log(ql_log_warn
, vha
, 0x209e,
5434 "SNS scan failed -- assuming "
5435 "zero-entry result.\n");
5441 /* If wrap on switch device list, exit. */
5443 wrap
.b24
= new_fcport
->d_id
.b24
;
5445 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
5446 ql_dbg(ql_dbg_disc
, vha
, 0x209f,
5447 "Device wrap (%02x%02x%02x).\n",
5448 new_fcport
->d_id
.b
.domain
,
5449 new_fcport
->d_id
.b
.area
,
5450 new_fcport
->d_id
.b
.al_pa
);
5454 /* Bypass if same physical adapter. */
5455 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
5458 /* Bypass virtual ports of the same host. */
5459 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
5462 /* Bypass if same domain and area of adapter. */
5463 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
5464 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
5468 /* Bypass reserved domain fields. */
5469 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
5472 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5473 if (ql2xgffidenable
&&
5474 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
5475 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
5478 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5480 /* Locate matching device in database. */
5482 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5483 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5487 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5491 /* Update port state. */
5492 memcpy(fcport
->fabric_port_name
,
5493 new_fcport
->fabric_port_name
, WWN_SIZE
);
5494 fcport
->fp_speed
= new_fcport
->fp_speed
;
5497 * If address the same and state FCS_ONLINE
5498 * (or in target mode), nothing changed.
5500 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
5501 (atomic_read(&fcport
->state
) == FCS_ONLINE
||
5502 (vha
->host
->active_mode
== MODE_TARGET
))) {
5507 * If device was not a fabric device before.
5509 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
5510 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5511 qla2x00_clear_loop_id(fcport
);
5512 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
5518 * Port ID changed or device was marked to be updated;
5519 * Log it out if still logged in and mark it for
5522 if (qla_tgt_mode_enabled(base_vha
)) {
5523 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf080,
5524 "port changed FC ID, %8phC"
5525 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5527 fcport
->d_id
.b
.domain
,
5528 fcport
->d_id
.b
.area
,
5529 fcport
->d_id
.b
.al_pa
,
5531 new_fcport
->d_id
.b
.domain
,
5532 new_fcport
->d_id
.b
.area
,
5533 new_fcport
->d_id
.b
.al_pa
);
5534 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5538 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5539 fcport
->flags
|= FCF_LOGIN_NEEDED
;
5543 if (fcport
->fc4f_nvme
) {
5544 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
5545 fcport
->disc_state
= DSC_GNL
;
5546 vha
->fcport_count
--;
5547 fcport
->login_succ
= 0;
5552 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5555 /* If device was not in our fcports list, then add it. */
5556 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5557 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5559 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5562 /* Allocate a new replacement fcport. */
5563 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
5564 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5565 if (new_fcport
== NULL
) {
5566 ql_log(ql_log_warn
, vha
, 0xd032,
5567 "Memory allocation failed for fcport.\n");
5568 return (QLA_MEMORY_ALLOC_FAILED
);
5570 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5571 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
5574 qla2x00_free_fcport(new_fcport
);
5577 * Logout all previous fabric dev marked lost, except FCP2 devices.
5579 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5580 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5583 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
5584 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
5587 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5588 if ((qla_dual_mode_enabled(vha
) ||
5589 qla_ini_mode_enabled(vha
)) &&
5590 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5591 qla2x00_mark_device_lost(vha
, fcport
,
5592 ql2xplogiabsentdevice
, 0);
5593 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5594 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5595 fcport
->port_type
!= FCT_INITIATOR
&&
5596 fcport
->port_type
!= FCT_BROADCAST
) {
5597 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5598 "%s %d %8phC post del sess\n",
5601 qlt_schedule_sess_for_deletion(fcport
);
5607 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5608 qla24xx_fcport_handle_login(vha
, fcport
);
5614 * qla2x00_find_new_loop_id
5615 * Scan through our port list and find a new usable loop ID.
5618 * ha: adapter state pointer.
5619 * dev: port structure pointer.
5622 * qla2x00 local function return status code.
5628 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
5631 struct qla_hw_data
*ha
= vha
->hw
;
5632 unsigned long flags
= 0;
5636 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5638 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
5640 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
5641 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
5642 dev
->loop_id
= FC_NO_LOOP_ID
;
5643 rval
= QLA_FUNCTION_FAILED
;
5645 set_bit(dev
->loop_id
, ha
->loop_id_map
);
5647 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5649 if (rval
== QLA_SUCCESS
)
5650 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
5651 "Assigning new loopid=%x, portid=%x.\n",
5652 dev
->loop_id
, dev
->d_id
.b24
);
5654 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
5655 "No loop_id's available, portid=%x.\n",
5663 * qla2x00_fabric_login
5664 * Issue fabric login command.
5667 * ha = adapter block pointer.
5668 * device = pointer to FC device type structure.
5671 * 0 - Login successfully
5673 * 2 - Initiator device
5677 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
5678 uint16_t *next_loopid
)
5682 uint16_t tmp_loopid
;
5683 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5684 struct qla_hw_data
*ha
= vha
->hw
;
5690 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
5691 "Trying Fabric Login w/loop id 0x%04x for port "
5693 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5694 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5696 /* Login fcport on switch. */
5697 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
5698 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5699 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
5700 if (rval
!= QLA_SUCCESS
) {
5703 if (mb
[0] == MBS_PORT_ID_USED
) {
5705 * Device has another loop ID. The firmware team
5706 * recommends the driver perform an implicit login with
5707 * the specified ID again. The ID we just used is save
5708 * here so we return with an ID that can be tried by
5712 tmp_loopid
= fcport
->loop_id
;
5713 fcport
->loop_id
= mb
[1];
5715 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
5716 "Fabric Login: port in use - next loop "
5717 "id=0x%04x, port id= %02x%02x%02x.\n",
5718 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5719 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5721 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
5726 /* A retry occurred before. */
5727 *next_loopid
= tmp_loopid
;
5730 * No retry occurred before. Just increment the
5731 * ID value for next login.
5733 *next_loopid
= (fcport
->loop_id
+ 1);
5736 if (mb
[1] & BIT_0
) {
5737 fcport
->port_type
= FCT_INITIATOR
;
5739 fcport
->port_type
= FCT_TARGET
;
5740 if (mb
[1] & BIT_1
) {
5741 fcport
->flags
|= FCF_FCP2_DEVICE
;
5746 fcport
->supported_classes
|= FC_COS_CLASS2
;
5748 fcport
->supported_classes
|= FC_COS_CLASS3
;
5750 if (IS_FWI2_CAPABLE(ha
)) {
5753 FCF_CONF_COMP_SUPPORTED
;
5758 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
5760 * Loop ID already used, try next loop ID.
5763 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
5764 if (rval
!= QLA_SUCCESS
) {
5765 /* Ran out of loop IDs to use */
5768 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
5770 * Firmware possibly timed out during login. If NO
5771 * retries are left to do then the device is declared
5774 *next_loopid
= fcport
->loop_id
;
5775 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5776 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5777 fcport
->d_id
.b
.al_pa
);
5778 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
5784 * unrecoverable / not handled error
5786 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
5787 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5788 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
5789 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
5790 fcport
->loop_id
, jiffies
);
5792 *next_loopid
= fcport
->loop_id
;
5793 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5794 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5795 fcport
->d_id
.b
.al_pa
);
5796 qla2x00_clear_loop_id(fcport
);
5797 fcport
->login_retry
= 0;
5808 * qla2x00_local_device_login
5809 * Issue local device login command.
5812 * ha = adapter block pointer.
5813 * loop_id = loop id of device to login to.
5815 * Returns (Where's the #define!!!!):
5816 * 0 - Login successfully
5821 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5824 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5826 memset(mb
, 0, sizeof(mb
));
5827 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
5828 if (rval
== QLA_SUCCESS
) {
5829 /* Interrogate mailbox registers for any errors */
5830 if (mb
[0] == MBS_COMMAND_ERROR
)
5832 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
5833 /* device not in PCB table */
5841 * qla2x00_loop_resync
5842 * Resync with fibre channel devices.
5845 * ha = adapter block pointer.
5851 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
5853 int rval
= QLA_SUCCESS
;
5855 struct req_que
*req
;
5856 struct rsp_que
*rsp
;
5861 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5862 if (vha
->flags
.online
) {
5863 if (!(rval
= qla2x00_fw_ready(vha
))) {
5864 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5867 if (!IS_QLAFX00(vha
->hw
)) {
5869 * Issue a marker after FW becomes
5872 qla2x00_marker(vha
, req
, rsp
, 0, 0,
5874 vha
->marker_needed
= 0;
5877 /* Remap devices on Loop. */
5878 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5880 if (IS_QLAFX00(vha
->hw
))
5881 qlafx00_configure_devices(vha
);
5883 qla2x00_configure_loop(vha
);
5886 } while (!atomic_read(&vha
->loop_down_timer
) &&
5887 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
5888 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
5893 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
5894 return (QLA_FUNCTION_FAILED
);
5897 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
5898 "%s *** FAILED ***.\n", __func__
);
5904 * qla2x00_perform_loop_resync
5905 * Description: This function will set the appropriate flags and call
5906 * qla2x00_loop_resync. If successful loop will be resynced
5907 * Arguments : scsi_qla_host_t pointer
5908 * returm : Success or Failure
5911 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
5915 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
5916 /*Configure the flags so that resync happens properly*/
5917 atomic_set(&ha
->loop_down_timer
, 0);
5918 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
5919 atomic_set(&ha
->loop_state
, LOOP_UP
);
5920 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
5921 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
5922 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
5924 rval
= qla2x00_loop_resync(ha
);
5926 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
5928 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
5935 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
5938 struct scsi_qla_host
*vha
;
5939 struct qla_hw_data
*ha
= base_vha
->hw
;
5940 unsigned long flags
;
5942 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5943 /* Go with deferred removal of rport references. */
5944 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
5945 atomic_inc(&vha
->vref_count
);
5946 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5947 if (fcport
->drport
&&
5948 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
5949 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5950 qla2x00_rport_del(fcport
);
5952 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5955 atomic_dec(&vha
->vref_count
);
5956 wake_up(&vha
->vref_waitq
);
5958 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5961 /* Assumes idc_lock always held on entry */
5963 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
5965 struct qla_hw_data
*ha
= vha
->hw
;
5966 uint32_t drv_presence
, drv_presence_mask
;
5967 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
5968 uint32_t class_type_mask
= 0x3;
5969 uint16_t fcoe_other_function
= 0xffff, i
;
5971 if (IS_QLA8044(ha
)) {
5972 drv_presence
= qla8044_rd_direct(vha
,
5973 QLA8044_CRB_DRV_ACTIVE_INDEX
);
5974 dev_part_info1
= qla8044_rd_direct(vha
,
5975 QLA8044_CRB_DEV_PART_INFO_INDEX
);
5976 dev_part_info2
= qla8044_rd_direct(vha
,
5977 QLA8044_CRB_DEV_PART_INFO2
);
5979 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
5980 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
5981 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
5983 for (i
= 0; i
< 8; i
++) {
5984 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
5985 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
5986 (i
!= ha
->portnum
)) {
5987 fcoe_other_function
= i
;
5991 if (fcoe_other_function
== 0xffff) {
5992 for (i
= 0; i
< 8; i
++) {
5993 class_type
= ((dev_part_info2
>> (i
* 4)) &
5995 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
5996 ((i
+ 8) != ha
->portnum
)) {
5997 fcoe_other_function
= i
+ 8;
6003 * Prepare drv-presence mask based on fcoe functions present.
6004 * However consider only valid physical fcoe function numbers (0-15).
6006 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
6007 ((fcoe_other_function
== 0xffff) ?
6008 0 : (1 << (fcoe_other_function
))));
6010 /* We are the reset owner iff:
6011 * - No other protocol drivers present.
6012 * - This is the lowest among fcoe functions. */
6013 if (!(drv_presence
& drv_presence_mask
) &&
6014 (ha
->portnum
< fcoe_other_function
)) {
6015 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
6016 "This host is Reset owner.\n");
6017 ha
->flags
.nic_core_reset_owner
= 1;
6022 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
6024 int rval
= QLA_SUCCESS
;
6025 struct qla_hw_data
*ha
= vha
->hw
;
6028 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6029 if (rval
== QLA_SUCCESS
) {
6030 drv_ack
|= (1 << ha
->portnum
);
6031 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6038 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
6040 int rval
= QLA_SUCCESS
;
6041 struct qla_hw_data
*ha
= vha
->hw
;
6044 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6045 if (rval
== QLA_SUCCESS
) {
6046 drv_ack
&= ~(1 << ha
->portnum
);
6047 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6054 qla83xx_dev_state_to_string(uint32_t dev_state
)
6056 switch (dev_state
) {
6057 case QLA8XXX_DEV_COLD
:
6058 return "COLD/RE-INIT";
6059 case QLA8XXX_DEV_INITIALIZING
:
6060 return "INITIALIZING";
6061 case QLA8XXX_DEV_READY
:
6063 case QLA8XXX_DEV_NEED_RESET
:
6064 return "NEED RESET";
6065 case QLA8XXX_DEV_NEED_QUIESCENT
:
6066 return "NEED QUIESCENT";
6067 case QLA8XXX_DEV_FAILED
:
6069 case QLA8XXX_DEV_QUIESCENT
:
6076 /* Assumes idc-lock always held on entry */
6078 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
6080 struct qla_hw_data
*ha
= vha
->hw
;
6081 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
6083 switch (audit_type
) {
6084 case IDC_AUDIT_TIMESTAMP
:
6085 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
6086 idc_audit_reg
= (ha
->portnum
) |
6087 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
6088 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6091 case IDC_AUDIT_COMPLETION
:
6092 duration_secs
= ((jiffies_to_msecs(jiffies
) -
6093 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
6094 idc_audit_reg
= (ha
->portnum
) |
6095 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
6096 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6100 ql_log(ql_log_warn
, vha
, 0xb078,
6101 "Invalid audit type specified.\n");
6106 /* Assumes idc_lock always held on entry */
6108 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
6110 struct qla_hw_data
*ha
= vha
->hw
;
6111 uint32_t idc_control
, dev_state
;
6113 __qla83xx_get_idc_control(vha
, &idc_control
);
6114 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
6115 ql_log(ql_log_info
, vha
, 0xb080,
6116 "NIC Core reset has been disabled. idc-control=0x%x\n",
6118 return QLA_FUNCTION_FAILED
;
6121 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6122 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6123 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
6124 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
6125 QLA8XXX_DEV_NEED_RESET
);
6126 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
6127 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
6129 const char *state
= qla83xx_dev_state_to_string(dev_state
);
6130 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
6132 /* SV: XXX: Is timeout required here? */
6133 /* Wait for IDC state change READY -> NEED_RESET */
6134 while (dev_state
== QLA8XXX_DEV_READY
) {
6135 qla83xx_idc_unlock(vha
, 0);
6137 qla83xx_idc_lock(vha
, 0);
6138 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6142 /* Send IDC ack by writing to drv-ack register */
6143 __qla83xx_set_drv_ack(vha
);
6149 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
6151 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6155 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
6157 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6161 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
6163 uint32_t drv_presence
= 0;
6164 struct qla_hw_data
*ha
= vha
->hw
;
6166 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6167 if (drv_presence
& (1 << ha
->portnum
))
6170 return QLA_TEST_FAILED
;
6174 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
6176 int rval
= QLA_SUCCESS
;
6177 struct qla_hw_data
*ha
= vha
->hw
;
6179 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
6180 "Entered %s().\n", __func__
);
6182 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
6183 ql_log(ql_log_warn
, vha
, 0xb059,
6184 "Device in unrecoverable FAILED state.\n");
6185 return QLA_FUNCTION_FAILED
;
6188 qla83xx_idc_lock(vha
, 0);
6190 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
6191 ql_log(ql_log_warn
, vha
, 0xb05a,
6192 "Function=0x%x has been removed from IDC participation.\n",
6194 rval
= QLA_FUNCTION_FAILED
;
6198 qla83xx_reset_ownership(vha
);
6200 rval
= qla83xx_initiating_reset(vha
);
6203 * Perform reset if we are the reset-owner,
6204 * else wait till IDC state changes to READY/FAILED.
6206 if (rval
== QLA_SUCCESS
) {
6207 rval
= qla83xx_idc_state_handler(vha
);
6209 if (rval
== QLA_SUCCESS
)
6210 ha
->flags
.nic_core_hung
= 0;
6211 __qla83xx_clear_drv_ack(vha
);
6215 qla83xx_idc_unlock(vha
, 0);
6217 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
6223 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
6225 struct qla_hw_data
*ha
= vha
->hw
;
6226 int rval
= QLA_FUNCTION_FAILED
;
6228 if (!IS_MCTP_CAPABLE(ha
)) {
6229 /* This message can be removed from the final version */
6230 ql_log(ql_log_info
, vha
, 0x506d,
6231 "This board is not MCTP capable\n");
6235 if (!ha
->mctp_dump
) {
6236 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
6237 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
6239 if (!ha
->mctp_dump
) {
6240 ql_log(ql_log_warn
, vha
, 0x506e,
6241 "Failed to allocate memory for mctp dump\n");
6246 #define MCTP_DUMP_STR_ADDR 0x00000000
6247 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
6248 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
6249 if (rval
!= QLA_SUCCESS
) {
6250 ql_log(ql_log_warn
, vha
, 0x506f,
6251 "Failed to capture mctp dump\n");
6253 ql_log(ql_log_info
, vha
, 0x5070,
6254 "Mctp dump capture for host (%ld/%p).\n",
6255 vha
->host_no
, ha
->mctp_dump
);
6256 ha
->mctp_dumped
= 1;
6259 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
6260 ha
->flags
.nic_core_reset_hdlr_active
= 1;
6261 rval
= qla83xx_restart_nic_firmware(vha
);
6263 /* NIC Core reset failed. */
6264 ql_log(ql_log_warn
, vha
, 0x5071,
6265 "Failed to restart nic firmware\n");
6267 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
6268 "Restarted NIC firmware successfully.\n");
6269 ha
->flags
.nic_core_reset_hdlr_active
= 0;
6277 * qla2x00_quiesce_io
6278 * Description: This function will block the new I/Os
6279 * Its not aborting any I/Os as context
6280 * is not destroyed during quiescence
6281 * Arguments: scsi_qla_host_t
6285 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
6287 struct qla_hw_data
*ha
= vha
->hw
;
6288 struct scsi_qla_host
*vp
;
6290 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
6291 "Quiescing I/O - ha=%p.\n", ha
);
6293 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
6294 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6295 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6296 qla2x00_mark_all_devices_lost(vha
, 0);
6297 list_for_each_entry(vp
, &ha
->vp_list
, list
)
6298 qla2x00_mark_all_devices_lost(vp
, 0);
6300 if (!atomic_read(&vha
->loop_down_timer
))
6301 atomic_set(&vha
->loop_down_timer
,
6304 /* Wait for pending cmds to complete */
6305 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
6309 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
6311 struct qla_hw_data
*ha
= vha
->hw
;
6312 struct scsi_qla_host
*vp
;
6313 unsigned long flags
;
6317 /* For ISP82XX, driver waits for completion of the commands.
6318 * online flag should be set.
6320 if (!(IS_P3P_TYPE(ha
)))
6321 vha
->flags
.online
= 0;
6322 ha
->flags
.chip_reset_done
= 0;
6323 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6324 vha
->qla_stats
.total_isp_aborts
++;
6326 ql_log(ql_log_info
, vha
, 0x00af,
6327 "Performing ISP error recovery - ha=%p.\n", ha
);
6329 /* For ISP82XX, reset_chip is just disabling interrupts.
6330 * Driver waits for the completion of the commands.
6331 * the interrupts need to be enabled.
6333 if (!(IS_P3P_TYPE(ha
)))
6334 ha
->isp_ops
->reset_chip(vha
);
6337 ha
->flags
.rida_fmt2
= 0;
6338 ha
->flags
.n2n_ae
= 0;
6339 ha
->flags
.lip_ae
= 0;
6340 ha
->current_topology
= 0;
6341 ha
->flags
.fw_started
= 0;
6342 ha
->flags
.fw_init_done
= 0;
6343 ha
->base_qpair
->chip_reset
++;
6344 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6345 if (ha
->queue_pair_map
[i
])
6346 ha
->queue_pair_map
[i
]->chip_reset
=
6347 ha
->base_qpair
->chip_reset
;
6350 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
6351 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6352 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6353 qla2x00_mark_all_devices_lost(vha
, 0);
6355 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6356 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6357 atomic_inc(&vp
->vref_count
);
6358 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6360 qla2x00_mark_all_devices_lost(vp
, 0);
6362 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6363 atomic_dec(&vp
->vref_count
);
6365 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6367 if (!atomic_read(&vha
->loop_down_timer
))
6368 atomic_set(&vha
->loop_down_timer
,
6372 /* Clear all async request states across all VPs. */
6373 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
6374 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6375 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6376 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6377 atomic_inc(&vp
->vref_count
);
6378 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6380 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
6381 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6383 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6384 atomic_dec(&vp
->vref_count
);
6386 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6388 if (!ha
->flags
.eeh_busy
) {
6389 /* Make sure for ISP 82XX IO DMA is complete */
6390 if (IS_P3P_TYPE(ha
)) {
6391 qla82xx_chip_reset_cleanup(vha
);
6392 ql_log(ql_log_info
, vha
, 0x00b4,
6393 "Done chip reset cleanup.\n");
6395 /* Done waiting for pending commands.
6396 * Reset the online flag.
6398 vha
->flags
.online
= 0;
6401 /* Requeue all commands in outstanding command list. */
6402 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6404 /* memory barrier */
6410 * Resets ISP and aborts all outstanding commands.
6413 * ha = adapter block pointer.
6419 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
6423 struct qla_hw_data
*ha
= vha
->hw
;
6424 struct scsi_qla_host
*vp
;
6425 struct req_que
*req
= ha
->req_q_map
[0];
6426 unsigned long flags
;
6428 if (vha
->flags
.online
) {
6429 qla2x00_abort_isp_cleanup(vha
);
6431 if (IS_QLA8031(ha
)) {
6432 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
6433 "Clearing fcoe driver presence.\n");
6434 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
6435 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
6436 "Error while clearing DRV-Presence.\n");
6439 if (unlikely(pci_channel_offline(ha
->pdev
) &&
6440 ha
->flags
.pci_channel_io_perm_failure
)) {
6441 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6446 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
6448 ha
->isp_ops
->nvram_config(vha
);
6450 if (!qla2x00_restart_isp(vha
)) {
6451 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6453 if (!atomic_read(&vha
->loop_down_timer
)) {
6455 * Issue marker command only when we are going
6456 * to start the I/O .
6458 vha
->marker_needed
= 1;
6461 vha
->flags
.online
= 1;
6463 ha
->isp_ops
->enable_intrs(ha
);
6465 ha
->isp_abort_cnt
= 0;
6466 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6468 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
6469 qla2x00_get_fw_version(vha
);
6471 ha
->flags
.fce_enabled
= 1;
6473 fce_calc_size(ha
->fce_bufs
));
6474 rval
= qla2x00_enable_fce_trace(vha
,
6475 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6478 ql_log(ql_log_warn
, vha
, 0x8033,
6479 "Unable to reinitialize FCE "
6481 ha
->flags
.fce_enabled
= 0;
6486 memset(ha
->eft
, 0, EFT_SIZE
);
6487 rval
= qla2x00_enable_eft_trace(vha
,
6488 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6490 ql_log(ql_log_warn
, vha
, 0x8034,
6491 "Unable to reinitialize EFT "
6495 } else { /* failed the ISP abort */
6496 vha
->flags
.online
= 1;
6497 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
6498 if (ha
->isp_abort_cnt
== 0) {
6499 ql_log(ql_log_fatal
, vha
, 0x8035,
6500 "ISP error recover failed - "
6501 "board disabled.\n");
6503 * The next call disables the board
6506 ha
->isp_ops
->reset_adapter(vha
);
6507 vha
->flags
.online
= 0;
6508 clear_bit(ISP_ABORT_RETRY
,
6511 } else { /* schedule another ISP abort */
6512 ha
->isp_abort_cnt
--;
6513 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
6514 "ISP abort - retry remaining %d.\n",
6519 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
6520 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
6521 "ISP error recovery - retrying (%d) "
6522 "more times.\n", ha
->isp_abort_cnt
);
6523 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6531 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
6532 qla2x00_configure_hba(vha
);
6533 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6534 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6536 atomic_inc(&vp
->vref_count
);
6537 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6539 qla2x00_vp_abort_isp(vp
);
6541 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6542 atomic_dec(&vp
->vref_count
);
6545 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6547 if (IS_QLA8031(ha
)) {
6548 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
6549 "Setting back fcoe driver presence.\n");
6550 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
6551 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
6552 "Error while setting DRV-Presence.\n");
6555 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
6563 * qla2x00_restart_isp
6564 * restarts the ISP after a reset
6567 * ha = adapter block pointer.
6573 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
6576 struct qla_hw_data
*ha
= vha
->hw
;
6577 struct req_que
*req
= ha
->req_q_map
[0];
6578 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
6580 /* If firmware needs to be loaded */
6581 if (qla2x00_isp_firmware(vha
)) {
6582 vha
->flags
.online
= 0;
6583 status
= ha
->isp_ops
->chip_diag(vha
);
6585 status
= qla2x00_setup_chip(vha
);
6588 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
6589 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6590 ha
->flags
.chip_reset_done
= 1;
6592 /* Initialize the queues in use */
6593 qla25xx_init_queues(ha
);
6595 status
= qla2x00_fw_ready(vha
);
6597 /* Issue a marker after FW becomes ready. */
6598 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
6599 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6602 /* if no cable then assume it's good */
6603 if ((vha
->device_flags
& DFLG_NO_CABLE
))
6610 qla25xx_init_queues(struct qla_hw_data
*ha
)
6612 struct rsp_que
*rsp
= NULL
;
6613 struct req_que
*req
= NULL
;
6614 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
6618 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
6619 rsp
= ha
->rsp_q_map
[i
];
6620 if (rsp
&& test_bit(i
, ha
->rsp_qid_map
)) {
6621 rsp
->options
&= ~BIT_0
;
6622 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
6623 if (ret
!= QLA_SUCCESS
)
6624 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
6625 "%s Rsp que: %d init failed.\n",
6628 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
6629 "%s Rsp que: %d inited.\n",
6633 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
6634 req
= ha
->req_q_map
[i
];
6635 if (req
&& test_bit(i
, ha
->req_qid_map
)) {
6636 /* Clear outstanding commands array. */
6637 req
->options
&= ~BIT_0
;
6638 ret
= qla25xx_init_req_que(base_vha
, req
);
6639 if (ret
!= QLA_SUCCESS
)
6640 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
6641 "%s Req que: %d init failed.\n",
6644 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
6645 "%s Req que: %d inited.\n",
6653 * qla2x00_reset_adapter
6657 * ha = adapter block pointer.
6660 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
6662 unsigned long flags
= 0;
6663 struct qla_hw_data
*ha
= vha
->hw
;
6664 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
6666 vha
->flags
.online
= 0;
6667 ha
->isp_ops
->disable_intrs(ha
);
6669 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6670 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
6671 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6672 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
6673 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6674 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6678 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
6680 unsigned long flags
= 0;
6681 struct qla_hw_data
*ha
= vha
->hw
;
6682 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
6684 if (IS_P3P_TYPE(ha
))
6687 vha
->flags
.online
= 0;
6688 ha
->isp_ops
->disable_intrs(ha
);
6690 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6691 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
6692 RD_REG_DWORD(®
->hccr
);
6693 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
6694 RD_REG_DWORD(®
->hccr
);
6695 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6697 if (IS_NOPOLLING_TYPE(ha
))
6698 ha
->isp_ops
->enable_intrs(ha
);
6701 /* On sparc systems, obtain port and node WWN from firmware
6704 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
6705 struct nvram_24xx
*nv
)
6708 struct qla_hw_data
*ha
= vha
->hw
;
6709 struct pci_dev
*pdev
= ha
->pdev
;
6710 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
6714 val
= of_get_property(dp
, "port-wwn", &len
);
6715 if (val
&& len
>= WWN_SIZE
)
6716 memcpy(nv
->port_name
, val
, WWN_SIZE
);
6718 val
= of_get_property(dp
, "node-wwn", &len
);
6719 if (val
&& len
>= WWN_SIZE
)
6720 memcpy(nv
->node_name
, val
, WWN_SIZE
);
6725 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
6728 struct init_cb_24xx
*icb
;
6729 struct nvram_24xx
*nv
;
6731 uint8_t *dptr1
, *dptr2
;
6734 struct qla_hw_data
*ha
= vha
->hw
;
6737 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6740 /* Determine NVRAM starting address. */
6741 if (ha
->port_no
== 0) {
6742 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
6743 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
6745 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
6746 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
6749 ha
->nvram_size
= sizeof(struct nvram_24xx
);
6750 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
6752 /* Get VPD data into cache */
6753 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
6754 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
6755 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
6757 /* Get NVRAM data into cache and calculate checksum. */
6758 dptr
= (uint32_t *)nv
;
6759 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
6761 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
6762 chksum
+= le32_to_cpu(*dptr
);
6764 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
6765 "Contents of NVRAM\n");
6766 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
6767 (uint8_t *)nv
, ha
->nvram_size
);
6769 /* Bad NVRAM data, set defaults parameters. */
6770 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
6771 || nv
->id
[3] != ' ' ||
6772 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
6773 /* Reset NVRAM data. */
6774 ql_log(ql_log_warn
, vha
, 0x006b,
6775 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6776 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
6777 ql_log(ql_log_warn
, vha
, 0x006c,
6778 "Falling back to functioning (yet invalid -- WWPN) "
6782 * Set default initialization control block.
6784 memset(nv
, 0, ha
->nvram_size
);
6785 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
6786 nv
->version
= cpu_to_le16(ICB_VERSION
);
6787 nv
->frame_payload_size
= 2048;
6788 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
6789 nv
->exchange_count
= cpu_to_le16(0);
6790 nv
->hard_address
= cpu_to_le16(124);
6791 nv
->port_name
[0] = 0x21;
6792 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
6793 nv
->port_name
[2] = 0x00;
6794 nv
->port_name
[3] = 0xe0;
6795 nv
->port_name
[4] = 0x8b;
6796 nv
->port_name
[5] = 0x1c;
6797 nv
->port_name
[6] = 0x55;
6798 nv
->port_name
[7] = 0x86;
6799 nv
->node_name
[0] = 0x20;
6800 nv
->node_name
[1] = 0x00;
6801 nv
->node_name
[2] = 0x00;
6802 nv
->node_name
[3] = 0xe0;
6803 nv
->node_name
[4] = 0x8b;
6804 nv
->node_name
[5] = 0x1c;
6805 nv
->node_name
[6] = 0x55;
6806 nv
->node_name
[7] = 0x86;
6807 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
6808 nv
->login_retry_count
= cpu_to_le16(8);
6809 nv
->interrupt_delay_timer
= cpu_to_le16(0);
6810 nv
->login_timeout
= cpu_to_le16(0);
6811 nv
->firmware_options_1
=
6812 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
6813 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
6814 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6815 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
6816 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
6817 nv
->efi_parameters
= cpu_to_le32(0);
6818 nv
->reset_delay
= 5;
6819 nv
->max_luns_per_target
= cpu_to_le16(128);
6820 nv
->port_down_retry_count
= cpu_to_le16(30);
6821 nv
->link_down_timeout
= cpu_to_le16(30);
6826 if (qla_tgt_mode_enabled(vha
)) {
6827 /* Don't enable full login after initial LIP */
6828 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6829 /* Don't enable LIP full login for initiator */
6830 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6833 qlt_24xx_config_nvram_stage1(vha
, nv
);
6835 /* Reset Initialization control block */
6836 memset(icb
, 0, ha
->init_cb_size
);
6838 /* Copy 1st segment. */
6839 dptr1
= (uint8_t *)icb
;
6840 dptr2
= (uint8_t *)&nv
->version
;
6841 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
6843 *dptr1
++ = *dptr2
++;
6845 icb
->login_retry_count
= nv
->login_retry_count
;
6846 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
6848 /* Copy 2nd segment. */
6849 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
6850 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
6851 cnt
= (uint8_t *)&icb
->reserved_3
-
6852 (uint8_t *)&icb
->interrupt_delay_timer
;
6854 *dptr1
++ = *dptr2
++;
6857 * Setup driver NVRAM options.
6859 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
6862 qlt_24xx_config_nvram_stage2(vha
, icb
);
6864 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
6865 /* Use alternate WWN? */
6866 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
6867 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
6870 /* Prepare nodename */
6871 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
6873 * Firmware will apply the following mask if the nodename was
6876 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
6877 icb
->node_name
[0] &= 0xF0;
6880 /* Set host adapter parameters. */
6881 ha
->flags
.disable_risc_code_load
= 0;
6882 ha
->flags
.enable_lip_reset
= 0;
6883 ha
->flags
.enable_lip_full_login
=
6884 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
6885 ha
->flags
.enable_target_reset
=
6886 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
6887 ha
->flags
.enable_led_scheme
= 0;
6888 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
6890 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
6891 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
6893 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
6894 sizeof(ha
->fw_seriallink_options24
));
6896 /* save HBA serial number */
6897 ha
->serial0
= icb
->port_name
[5];
6898 ha
->serial1
= icb
->port_name
[6];
6899 ha
->serial2
= icb
->port_name
[7];
6900 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
6901 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
6903 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
6905 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
6907 /* Set minimum login_timeout to 4 seconds. */
6908 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
6909 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
6910 if (le16_to_cpu(nv
->login_timeout
) < 4)
6911 nv
->login_timeout
= cpu_to_le16(4);
6912 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
6914 /* Set minimum RATOV to 100 tenths of a second. */
6917 ha
->loop_reset_delay
= nv
->reset_delay
;
6919 /* Link Down Timeout = 0:
6921 * When Port Down timer expires we will start returning
6922 * I/O's to OS with "DID_NO_CONNECT".
6924 * Link Down Timeout != 0:
6926 * The driver waits for the link to come up after link down
6927 * before returning I/Os to OS with "DID_NO_CONNECT".
6929 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
6930 ha
->loop_down_abort_time
=
6931 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
6933 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
6934 ha
->loop_down_abort_time
=
6935 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
6938 /* Need enough time to try and get the port back. */
6939 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
6940 if (qlport_down_retry
)
6941 ha
->port_down_retry_count
= qlport_down_retry
;
6943 /* Set login_retry_count */
6944 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
6945 if (ha
->port_down_retry_count
==
6946 le16_to_cpu(nv
->port_down_retry_count
) &&
6947 ha
->port_down_retry_count
> 3)
6948 ha
->login_retry_count
= ha
->port_down_retry_count
;
6949 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
6950 ha
->login_retry_count
= ha
->port_down_retry_count
;
6951 if (ql2xloginretrycount
)
6952 ha
->login_retry_count
= ql2xloginretrycount
;
6955 if (!vha
->flags
.init_done
) {
6956 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
6957 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6958 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
6959 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
6961 icb
->firmware_options_2
&= cpu_to_le32(
6962 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
6963 vha
->flags
.process_response_queue
= 0;
6964 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
6965 ha
->zio_mode
= QLA_ZIO_MODE_6
;
6967 ql_log(ql_log_info
, vha
, 0x006f,
6968 "ZIO mode %d enabled; timer delay (%d us).\n",
6969 ha
->zio_mode
, ha
->zio_timer
* 100);
6971 icb
->firmware_options_2
|= cpu_to_le32(
6972 (uint32_t)ha
->zio_mode
);
6973 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
6974 vha
->flags
.process_response_queue
= 1;
6978 ql_log(ql_log_warn
, vha
, 0x0070,
6979 "NVRAM configuration failed.\n");
6984 uint8_t qla27xx_find_valid_image(struct scsi_qla_host
*vha
)
6986 struct qla27xx_image_status pri_image_status
, sec_image_status
;
6987 uint8_t valid_pri_image
, valid_sec_image
;
6989 uint32_t cnt
, chksum
, size
;
6990 struct qla_hw_data
*ha
= vha
->hw
;
6992 valid_pri_image
= valid_sec_image
= 1;
6993 ha
->active_image
= 0;
6994 size
= sizeof(struct qla27xx_image_status
) / sizeof(uint32_t);
6996 if (!ha
->flt_region_img_status_pri
) {
6997 valid_pri_image
= 0;
6998 goto check_sec_image
;
7001 qla24xx_read_flash_data(vha
, (uint32_t *)(&pri_image_status
),
7002 ha
->flt_region_img_status_pri
, size
);
7004 if (pri_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
7005 ql_dbg(ql_dbg_init
, vha
, 0x018b,
7006 "Primary image signature (0x%x) not valid\n",
7007 pri_image_status
.signature
);
7008 valid_pri_image
= 0;
7009 goto check_sec_image
;
7012 wptr
= (uint32_t *)(&pri_image_status
);
7015 for (chksum
= 0; cnt
--; wptr
++)
7016 chksum
+= le32_to_cpu(*wptr
);
7019 ql_dbg(ql_dbg_init
, vha
, 0x018c,
7020 "Checksum validation failed for primary image (0x%x)\n",
7022 valid_pri_image
= 0;
7026 if (!ha
->flt_region_img_status_sec
) {
7027 valid_sec_image
= 0;
7028 goto check_valid_image
;
7031 qla24xx_read_flash_data(vha
, (uint32_t *)(&sec_image_status
),
7032 ha
->flt_region_img_status_sec
, size
);
7034 if (sec_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
7035 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7036 "Secondary image signature(0x%x) not valid\n",
7037 sec_image_status
.signature
);
7038 valid_sec_image
= 0;
7039 goto check_valid_image
;
7042 wptr
= (uint32_t *)(&sec_image_status
);
7044 for (chksum
= 0; cnt
--; wptr
++)
7045 chksum
+= le32_to_cpu(*wptr
);
7047 ql_dbg(ql_dbg_init
, vha
, 0x018e,
7048 "Checksum validation failed for secondary image (0x%x)\n",
7050 valid_sec_image
= 0;
7054 if (valid_pri_image
&& (pri_image_status
.image_status_mask
& 0x1))
7055 ha
->active_image
= QLA27XX_PRIMARY_IMAGE
;
7056 if (valid_sec_image
&& (sec_image_status
.image_status_mask
& 0x1)) {
7057 if (!ha
->active_image
||
7058 pri_image_status
.generation_number
<
7059 sec_image_status
.generation_number
)
7060 ha
->active_image
= QLA27XX_SECONDARY_IMAGE
;
7063 ql_dbg(ql_dbg_init
, vha
, 0x018f, "%s image\n",
7064 ha
->active_image
== 0 ? "default bootld and fw" :
7065 ha
->active_image
== 1 ? "primary" :
7066 ha
->active_image
== 2 ? "secondary" :
7069 return ha
->active_image
;
7073 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
7076 int rval
= QLA_SUCCESS
;
7077 int segments
, fragment
;
7078 uint32_t *dcode
, dlen
;
7082 struct qla_hw_data
*ha
= vha
->hw
;
7083 struct req_que
*req
= ha
->req_q_map
[0];
7085 ql_dbg(ql_dbg_init
, vha
, 0x008b,
7086 "FW: Loading firmware from flash (%x).\n", faddr
);
7090 segments
= FA_RISC_CODE_SEGMENTS
;
7091 dcode
= (uint32_t *)req
->ring
;
7094 if (IS_QLA27XX(ha
) &&
7095 qla27xx_find_valid_image(vha
) == QLA27XX_SECONDARY_IMAGE
)
7096 faddr
= ha
->flt_region_fw_sec
;
7098 /* Validate firmware image by checking version. */
7099 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
7100 for (i
= 0; i
< 4; i
++)
7101 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7102 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7103 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7104 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7106 ql_log(ql_log_fatal
, vha
, 0x008c,
7107 "Unable to verify the integrity of flash firmware "
7109 ql_log(ql_log_fatal
, vha
, 0x008d,
7110 "Firmware data: %08x %08x %08x %08x.\n",
7111 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7113 return QLA_FUNCTION_FAILED
;
7116 while (segments
&& rval
== QLA_SUCCESS
) {
7117 /* Read segment's load information. */
7118 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
7120 risc_addr
= be32_to_cpu(dcode
[2]);
7121 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7122 risc_size
= be32_to_cpu(dcode
[3]);
7125 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7126 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7127 if (dlen
> risc_size
)
7130 ql_dbg(ql_dbg_init
, vha
, 0x008e,
7131 "Loading risc segment@ risc addr %x "
7132 "number of dwords 0x%x offset 0x%x.\n",
7133 risc_addr
, dlen
, faddr
);
7135 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
7136 for (i
= 0; i
< dlen
; i
++)
7137 dcode
[i
] = swab32(dcode
[i
]);
7139 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7142 ql_log(ql_log_fatal
, vha
, 0x008f,
7143 "Failed to load segment %d of firmware.\n",
7145 return QLA_FUNCTION_FAILED
;
7158 if (!IS_QLA27XX(ha
))
7161 if (ha
->fw_dump_template
)
7162 vfree(ha
->fw_dump_template
);
7163 ha
->fw_dump_template
= NULL
;
7164 ha
->fw_dump_template_len
= 0;
7166 ql_dbg(ql_dbg_init
, vha
, 0x0161,
7167 "Loading fwdump template from %x\n", faddr
);
7168 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
7169 risc_size
= be32_to_cpu(dcode
[2]);
7170 ql_dbg(ql_dbg_init
, vha
, 0x0162,
7171 "-> array size %x dwords\n", risc_size
);
7172 if (risc_size
== 0 || risc_size
== ~0)
7173 goto default_template
;
7175 dlen
= (risc_size
- 8) * sizeof(*dcode
);
7176 ql_dbg(ql_dbg_init
, vha
, 0x0163,
7177 "-> template allocating %x bytes...\n", dlen
);
7178 ha
->fw_dump_template
= vmalloc(dlen
);
7179 if (!ha
->fw_dump_template
) {
7180 ql_log(ql_log_warn
, vha
, 0x0164,
7181 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7182 goto default_template
;
7187 dcode
= ha
->fw_dump_template
;
7188 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
7189 for (i
= 0; i
< risc_size
; i
++)
7190 dcode
[i
] = le32_to_cpu(dcode
[i
]);
7192 if (!qla27xx_fwdt_template_valid(dcode
)) {
7193 ql_log(ql_log_warn
, vha
, 0x0165,
7194 "Failed fwdump template validate\n");
7195 goto default_template
;
7198 dlen
= qla27xx_fwdt_template_size(dcode
);
7199 ql_dbg(ql_dbg_init
, vha
, 0x0166,
7200 "-> template size %x bytes\n", dlen
);
7201 if (dlen
> risc_size
* sizeof(*dcode
)) {
7202 ql_log(ql_log_warn
, vha
, 0x0167,
7203 "Failed fwdump template exceeds array by %zx bytes\n",
7204 (size_t)(dlen
- risc_size
* sizeof(*dcode
)));
7205 goto default_template
;
7207 ha
->fw_dump_template_len
= dlen
;
7211 ql_log(ql_log_warn
, vha
, 0x0168, "Using default fwdump template\n");
7212 if (ha
->fw_dump_template
)
7213 vfree(ha
->fw_dump_template
);
7214 ha
->fw_dump_template
= NULL
;
7215 ha
->fw_dump_template_len
= 0;
7217 dlen
= qla27xx_fwdt_template_default_size();
7218 ql_dbg(ql_dbg_init
, vha
, 0x0169,
7219 "-> template allocating %x bytes...\n", dlen
);
7220 ha
->fw_dump_template
= vmalloc(dlen
);
7221 if (!ha
->fw_dump_template
) {
7222 ql_log(ql_log_warn
, vha
, 0x016a,
7223 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7224 goto failed_template
;
7227 dcode
= ha
->fw_dump_template
;
7228 risc_size
= dlen
/ sizeof(*dcode
);
7229 memcpy(dcode
, qla27xx_fwdt_template_default(), dlen
);
7230 for (i
= 0; i
< risc_size
; i
++)
7231 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7233 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7234 ql_log(ql_log_warn
, vha
, 0x016b,
7235 "Failed fwdump template validate\n");
7236 goto failed_template
;
7239 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7240 ql_dbg(ql_dbg_init
, vha
, 0x016c,
7241 "-> template size %x bytes\n", dlen
);
7242 ha
->fw_dump_template_len
= dlen
;
7246 ql_log(ql_log_warn
, vha
, 0x016d, "Failed default fwdump template\n");
7247 if (ha
->fw_dump_template
)
7248 vfree(ha
->fw_dump_template
);
7249 ha
->fw_dump_template
= NULL
;
7250 ha
->fw_dump_template_len
= 0;
7254 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7257 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7261 uint16_t *wcode
, *fwcode
;
7262 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
7263 struct fw_blob
*blob
;
7264 struct qla_hw_data
*ha
= vha
->hw
;
7265 struct req_que
*req
= ha
->req_q_map
[0];
7267 /* Load firmware blob. */
7268 blob
= qla2x00_request_firmware(vha
);
7270 ql_log(ql_log_info
, vha
, 0x0083,
7271 "Firmware image unavailable.\n");
7272 ql_log(ql_log_info
, vha
, 0x0084,
7273 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
7274 return QLA_FUNCTION_FAILED
;
7279 wcode
= (uint16_t *)req
->ring
;
7281 fwcode
= (uint16_t *)blob
->fw
->data
;
7284 /* Validate firmware image by checking version. */
7285 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
7286 ql_log(ql_log_fatal
, vha
, 0x0085,
7287 "Unable to verify integrity of firmware image (%zd).\n",
7289 goto fail_fw_integrity
;
7291 for (i
= 0; i
< 4; i
++)
7292 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
7293 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
7294 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
7295 wcode
[2] == 0 && wcode
[3] == 0)) {
7296 ql_log(ql_log_fatal
, vha
, 0x0086,
7297 "Unable to verify integrity of firmware image.\n");
7298 ql_log(ql_log_fatal
, vha
, 0x0087,
7299 "Firmware data: %04x %04x %04x %04x.\n",
7300 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
7301 goto fail_fw_integrity
;
7305 while (*seg
&& rval
== QLA_SUCCESS
) {
7307 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
7308 risc_size
= be16_to_cpu(fwcode
[3]);
7310 /* Validate firmware image size. */
7311 fwclen
+= risc_size
* sizeof(uint16_t);
7312 if (blob
->fw
->size
< fwclen
) {
7313 ql_log(ql_log_fatal
, vha
, 0x0088,
7314 "Unable to verify integrity of firmware image "
7315 "(%zd).\n", blob
->fw
->size
);
7316 goto fail_fw_integrity
;
7320 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7321 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
7322 if (wlen
> risc_size
)
7324 ql_dbg(ql_dbg_init
, vha
, 0x0089,
7325 "Loading risc segment@ risc addr %x number of "
7326 "words 0x%x.\n", risc_addr
, wlen
);
7328 for (i
= 0; i
< wlen
; i
++)
7329 wcode
[i
] = swab16(fwcode
[i
]);
7331 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7334 ql_log(ql_log_fatal
, vha
, 0x008a,
7335 "Failed to load segment %d of firmware.\n",
7352 return QLA_FUNCTION_FAILED
;
7356 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7359 int segments
, fragment
;
7360 uint32_t *dcode
, dlen
;
7364 struct fw_blob
*blob
;
7365 const uint32_t *fwcode
;
7367 struct qla_hw_data
*ha
= vha
->hw
;
7368 struct req_que
*req
= ha
->req_q_map
[0];
7370 /* Load firmware blob. */
7371 blob
= qla2x00_request_firmware(vha
);
7373 ql_log(ql_log_warn
, vha
, 0x0090,
7374 "Firmware image unavailable.\n");
7375 ql_log(ql_log_warn
, vha
, 0x0091,
7376 "Firmware images can be retrieved from: "
7379 return QLA_FUNCTION_FAILED
;
7382 ql_dbg(ql_dbg_init
, vha
, 0x0092,
7383 "FW: Loading via request-firmware.\n");
7387 segments
= FA_RISC_CODE_SEGMENTS
;
7388 dcode
= (uint32_t *)req
->ring
;
7390 fwcode
= (uint32_t *)blob
->fw
->data
;
7393 /* Validate firmware image by checking version. */
7394 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
7395 ql_log(ql_log_fatal
, vha
, 0x0093,
7396 "Unable to verify integrity of firmware image (%zd).\n",
7398 return QLA_FUNCTION_FAILED
;
7400 for (i
= 0; i
< 4; i
++)
7401 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
7402 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7403 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7404 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7406 ql_log(ql_log_fatal
, vha
, 0x0094,
7407 "Unable to verify integrity of firmware image (%zd).\n",
7409 ql_log(ql_log_fatal
, vha
, 0x0095,
7410 "Firmware data: %08x %08x %08x %08x.\n",
7411 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7412 return QLA_FUNCTION_FAILED
;
7415 while (segments
&& rval
== QLA_SUCCESS
) {
7416 risc_addr
= be32_to_cpu(fwcode
[2]);
7417 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7418 risc_size
= be32_to_cpu(fwcode
[3]);
7420 /* Validate firmware image size. */
7421 fwclen
+= risc_size
* sizeof(uint32_t);
7422 if (blob
->fw
->size
< fwclen
) {
7423 ql_log(ql_log_fatal
, vha
, 0x0096,
7424 "Unable to verify integrity of firmware image "
7425 "(%zd).\n", blob
->fw
->size
);
7426 return QLA_FUNCTION_FAILED
;
7430 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7431 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7432 if (dlen
> risc_size
)
7435 ql_dbg(ql_dbg_init
, vha
, 0x0097,
7436 "Loading risc segment@ risc addr %x "
7437 "number of dwords 0x%x.\n", risc_addr
, dlen
);
7439 for (i
= 0; i
< dlen
; i
++)
7440 dcode
[i
] = swab32(fwcode
[i
]);
7442 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7445 ql_log(ql_log_fatal
, vha
, 0x0098,
7446 "Failed to load segment %d of firmware.\n",
7448 return QLA_FUNCTION_FAILED
;
7461 if (!IS_QLA27XX(ha
))
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 ql_dbg(ql_dbg_init
, vha
, 0x171,
7470 "Loading fwdump template from %x\n",
7471 (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
));
7472 risc_size
= be32_to_cpu(fwcode
[2]);
7473 ql_dbg(ql_dbg_init
, vha
, 0x172,
7474 "-> array size %x dwords\n", risc_size
);
7475 if (risc_size
== 0 || risc_size
== ~0)
7476 goto default_template
;
7478 dlen
= (risc_size
- 8) * sizeof(*fwcode
);
7479 ql_dbg(ql_dbg_init
, vha
, 0x0173,
7480 "-> template allocating %x bytes...\n", dlen
);
7481 ha
->fw_dump_template
= vmalloc(dlen
);
7482 if (!ha
->fw_dump_template
) {
7483 ql_log(ql_log_warn
, vha
, 0x0174,
7484 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7485 goto default_template
;
7490 dcode
= ha
->fw_dump_template
;
7491 for (i
= 0; i
< risc_size
; i
++)
7492 dcode
[i
] = le32_to_cpu(fwcode
[i
]);
7494 if (!qla27xx_fwdt_template_valid(dcode
)) {
7495 ql_log(ql_log_warn
, vha
, 0x0175,
7496 "Failed fwdump template validate\n");
7497 goto default_template
;
7500 dlen
= qla27xx_fwdt_template_size(dcode
);
7501 ql_dbg(ql_dbg_init
, vha
, 0x0176,
7502 "-> template size %x bytes\n", dlen
);
7503 if (dlen
> risc_size
* sizeof(*fwcode
)) {
7504 ql_log(ql_log_warn
, vha
, 0x0177,
7505 "Failed fwdump template exceeds array by %zx bytes\n",
7506 (size_t)(dlen
- risc_size
* sizeof(*fwcode
)));
7507 goto default_template
;
7509 ha
->fw_dump_template_len
= dlen
;
7513 ql_log(ql_log_warn
, vha
, 0x0178, "Using default fwdump template\n");
7514 if (ha
->fw_dump_template
)
7515 vfree(ha
->fw_dump_template
);
7516 ha
->fw_dump_template
= NULL
;
7517 ha
->fw_dump_template_len
= 0;
7519 dlen
= qla27xx_fwdt_template_default_size();
7520 ql_dbg(ql_dbg_init
, vha
, 0x0179,
7521 "-> template allocating %x bytes...\n", dlen
);
7522 ha
->fw_dump_template
= vmalloc(dlen
);
7523 if (!ha
->fw_dump_template
) {
7524 ql_log(ql_log_warn
, vha
, 0x017a,
7525 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7526 goto failed_template
;
7529 dcode
= ha
->fw_dump_template
;
7530 risc_size
= dlen
/ sizeof(*fwcode
);
7531 fwcode
= qla27xx_fwdt_template_default();
7532 for (i
= 0; i
< risc_size
; i
++)
7533 dcode
[i
] = be32_to_cpu(fwcode
[i
]);
7535 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7536 ql_log(ql_log_warn
, vha
, 0x017b,
7537 "Failed fwdump template validate\n");
7538 goto failed_template
;
7541 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7542 ql_dbg(ql_dbg_init
, vha
, 0x017c,
7543 "-> template size %x bytes\n", dlen
);
7544 ha
->fw_dump_template_len
= dlen
;
7548 ql_log(ql_log_warn
, vha
, 0x017d, "Failed default fwdump template\n");
7549 if (ha
->fw_dump_template
)
7550 vfree(ha
->fw_dump_template
);
7551 ha
->fw_dump_template
= NULL
;
7552 ha
->fw_dump_template_len
= 0;
7557 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7561 if (ql2xfwloadbin
== 1)
7562 return qla81xx_load_risc(vha
, srisc_addr
);
7566 * 1) Firmware via request-firmware interface (.bin file).
7567 * 2) Firmware residing in flash.
7569 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7570 if (rval
== QLA_SUCCESS
)
7573 return qla24xx_load_risc_flash(vha
, srisc_addr
,
7574 vha
->hw
->flt_region_fw
);
7578 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7581 struct qla_hw_data
*ha
= vha
->hw
;
7583 if (ql2xfwloadbin
== 2)
7588 * 1) Firmware residing in flash.
7589 * 2) Firmware via request-firmware interface (.bin file).
7590 * 3) Golden-Firmware residing in flash -- limited operation.
7592 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
7593 if (rval
== QLA_SUCCESS
)
7597 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7598 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
7601 ql_log(ql_log_info
, vha
, 0x0099,
7602 "Attempting to fallback to golden firmware.\n");
7603 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
7604 if (rval
!= QLA_SUCCESS
)
7607 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
7608 ha
->flags
.running_gold_fw
= 1;
7613 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
7616 struct qla_hw_data
*ha
= vha
->hw
;
7618 if (ha
->flags
.pci_channel_io_perm_failure
)
7620 if (!IS_FWI2_CAPABLE(ha
))
7622 if (!ha
->fw_major_version
)
7624 if (!ha
->flags
.fw_started
)
7627 ret
= qla2x00_stop_firmware(vha
);
7628 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
7629 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
7630 ha
->isp_ops
->reset_chip(vha
);
7631 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
7633 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
7635 ql_log(ql_log_info
, vha
, 0x8015,
7636 "Attempting retry of stop-firmware command.\n");
7637 ret
= qla2x00_stop_firmware(vha
);
7641 ha
->flags
.fw_init_done
= 0;
7645 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
7647 int rval
= QLA_SUCCESS
;
7649 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
7650 struct qla_hw_data
*ha
= vha
->hw
;
7651 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
7652 struct req_que
*req
;
7653 struct rsp_que
*rsp
;
7658 rval
= qla2x00_fw_ready(base_vha
);
7660 req
= vha
->qpair
->req
;
7662 req
= ha
->req_q_map
[0];
7665 if (rval
== QLA_SUCCESS
) {
7666 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
7667 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
7670 vha
->flags
.management_server_logged_in
= 0;
7672 /* Login to SNS first */
7673 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
7675 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
7676 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
7677 ql_dbg(ql_dbg_init
, vha
, 0x0120,
7678 "Failed SNS login: loop_id=%x, rval2=%d\n",
7681 ql_dbg(ql_dbg_init
, vha
, 0x0103,
7682 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7683 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7684 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
7685 return (QLA_FUNCTION_FAILED
);
7688 atomic_set(&vha
->loop_down_timer
, 0);
7689 atomic_set(&vha
->loop_state
, LOOP_UP
);
7690 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
7691 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
7692 rval
= qla2x00_loop_resync(base_vha
);
7697 /* 84XX Support **************************************************************/
7699 static LIST_HEAD(qla_cs84xx_list
);
7700 static DEFINE_MUTEX(qla_cs84xx_mutex
);
7702 static struct qla_chip_state_84xx
*
7703 qla84xx_get_chip(struct scsi_qla_host
*vha
)
7705 struct qla_chip_state_84xx
*cs84xx
;
7706 struct qla_hw_data
*ha
= vha
->hw
;
7708 mutex_lock(&qla_cs84xx_mutex
);
7710 /* Find any shared 84xx chip. */
7711 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
7712 if (cs84xx
->bus
== ha
->pdev
->bus
) {
7713 kref_get(&cs84xx
->kref
);
7718 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
7722 kref_init(&cs84xx
->kref
);
7723 spin_lock_init(&cs84xx
->access_lock
);
7724 mutex_init(&cs84xx
->fw_update_mutex
);
7725 cs84xx
->bus
= ha
->pdev
->bus
;
7727 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
7729 mutex_unlock(&qla_cs84xx_mutex
);
7734 __qla84xx_chip_release(struct kref
*kref
)
7736 struct qla_chip_state_84xx
*cs84xx
=
7737 container_of(kref
, struct qla_chip_state_84xx
, kref
);
7739 mutex_lock(&qla_cs84xx_mutex
);
7740 list_del(&cs84xx
->list
);
7741 mutex_unlock(&qla_cs84xx_mutex
);
7746 qla84xx_put_chip(struct scsi_qla_host
*vha
)
7748 struct qla_hw_data
*ha
= vha
->hw
;
7750 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
7754 qla84xx_init_chip(scsi_qla_host_t
*vha
)
7758 struct qla_hw_data
*ha
= vha
->hw
;
7760 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
7762 rval
= qla84xx_verify_chip(vha
, status
);
7764 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
7766 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
7770 /* 81XX Support **************************************************************/
7773 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
7776 struct init_cb_81xx
*icb
;
7777 struct nvram_81xx
*nv
;
7779 uint8_t *dptr1
, *dptr2
;
7782 struct qla_hw_data
*ha
= vha
->hw
;
7785 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
7788 /* Determine NVRAM starting address. */
7789 ha
->nvram_size
= sizeof(struct nvram_81xx
);
7790 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
7791 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
7792 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
7794 /* Get VPD data into cache */
7795 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
7796 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
7799 /* Get NVRAM data into cache and calculate checksum. */
7800 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
7802 dptr
= (uint32_t *)nv
;
7803 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
7804 chksum
+= le32_to_cpu(*dptr
);
7806 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
7807 "Contents of NVRAM:\n");
7808 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
7809 (uint8_t *)nv
, ha
->nvram_size
);
7811 /* Bad NVRAM data, set defaults parameters. */
7812 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
7813 || nv
->id
[3] != ' ' ||
7814 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
7815 /* Reset NVRAM data. */
7816 ql_log(ql_log_info
, vha
, 0x0073,
7817 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7818 "version=0x%x.\n", chksum
, nv
->id
[0],
7819 le16_to_cpu(nv
->nvram_version
));
7820 ql_log(ql_log_info
, vha
, 0x0074,
7821 "Falling back to functioning (yet invalid -- WWPN) "
7825 * Set default initialization control block.
7827 memset(nv
, 0, ha
->nvram_size
);
7828 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
7829 nv
->version
= cpu_to_le16(ICB_VERSION
);
7830 nv
->frame_payload_size
= 2048;
7831 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
7832 nv
->exchange_count
= cpu_to_le16(0);
7833 nv
->port_name
[0] = 0x21;
7834 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
7835 nv
->port_name
[2] = 0x00;
7836 nv
->port_name
[3] = 0xe0;
7837 nv
->port_name
[4] = 0x8b;
7838 nv
->port_name
[5] = 0x1c;
7839 nv
->port_name
[6] = 0x55;
7840 nv
->port_name
[7] = 0x86;
7841 nv
->node_name
[0] = 0x20;
7842 nv
->node_name
[1] = 0x00;
7843 nv
->node_name
[2] = 0x00;
7844 nv
->node_name
[3] = 0xe0;
7845 nv
->node_name
[4] = 0x8b;
7846 nv
->node_name
[5] = 0x1c;
7847 nv
->node_name
[6] = 0x55;
7848 nv
->node_name
[7] = 0x86;
7849 nv
->login_retry_count
= cpu_to_le16(8);
7850 nv
->interrupt_delay_timer
= cpu_to_le16(0);
7851 nv
->login_timeout
= cpu_to_le16(0);
7852 nv
->firmware_options_1
=
7853 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
7854 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
7855 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
7856 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
7857 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
7858 nv
->efi_parameters
= cpu_to_le32(0);
7859 nv
->reset_delay
= 5;
7860 nv
->max_luns_per_target
= cpu_to_le16(128);
7861 nv
->port_down_retry_count
= cpu_to_le16(30);
7862 nv
->link_down_timeout
= cpu_to_le16(180);
7863 nv
->enode_mac
[0] = 0x00;
7864 nv
->enode_mac
[1] = 0xC0;
7865 nv
->enode_mac
[2] = 0xDD;
7866 nv
->enode_mac
[3] = 0x04;
7867 nv
->enode_mac
[4] = 0x05;
7868 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
7873 if (IS_T10_PI_CAPABLE(ha
))
7874 nv
->frame_payload_size
&= ~7;
7876 qlt_81xx_config_nvram_stage1(vha
, nv
);
7878 /* Reset Initialization control block */
7879 memset(icb
, 0, ha
->init_cb_size
);
7881 /* Copy 1st segment. */
7882 dptr1
= (uint8_t *)icb
;
7883 dptr2
= (uint8_t *)&nv
->version
;
7884 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
7886 *dptr1
++ = *dptr2
++;
7888 icb
->login_retry_count
= nv
->login_retry_count
;
7890 /* Copy 2nd segment. */
7891 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
7892 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
7893 cnt
= (uint8_t *)&icb
->reserved_5
-
7894 (uint8_t *)&icb
->interrupt_delay_timer
;
7896 *dptr1
++ = *dptr2
++;
7898 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
7899 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7900 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
7901 icb
->enode_mac
[0] = 0x00;
7902 icb
->enode_mac
[1] = 0xC0;
7903 icb
->enode_mac
[2] = 0xDD;
7904 icb
->enode_mac
[3] = 0x04;
7905 icb
->enode_mac
[4] = 0x05;
7906 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
7909 /* Use extended-initialization control block. */
7910 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
7913 * Setup driver NVRAM options.
7915 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
7918 qlt_81xx_config_nvram_stage2(vha
, icb
);
7920 /* Use alternate WWN? */
7921 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
7922 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
7923 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
7926 /* Prepare nodename */
7927 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
7929 * Firmware will apply the following mask if the nodename was
7932 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
7933 icb
->node_name
[0] &= 0xF0;
7936 /* Set host adapter parameters. */
7937 ha
->flags
.disable_risc_code_load
= 0;
7938 ha
->flags
.enable_lip_reset
= 0;
7939 ha
->flags
.enable_lip_full_login
=
7940 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
7941 ha
->flags
.enable_target_reset
=
7942 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
7943 ha
->flags
.enable_led_scheme
= 0;
7944 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
7946 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
7947 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
7949 /* save HBA serial number */
7950 ha
->serial0
= icb
->port_name
[5];
7951 ha
->serial1
= icb
->port_name
[6];
7952 ha
->serial2
= icb
->port_name
[7];
7953 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
7954 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
7956 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
7958 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
7960 /* Set minimum login_timeout to 4 seconds. */
7961 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
7962 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
7963 if (le16_to_cpu(nv
->login_timeout
) < 4)
7964 nv
->login_timeout
= cpu_to_le16(4);
7965 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
7967 /* Set minimum RATOV to 100 tenths of a second. */
7970 ha
->loop_reset_delay
= nv
->reset_delay
;
7972 /* Link Down Timeout = 0:
7974 * When Port Down timer expires we will start returning
7975 * I/O's to OS with "DID_NO_CONNECT".
7977 * Link Down Timeout != 0:
7979 * The driver waits for the link to come up after link down
7980 * before returning I/Os to OS with "DID_NO_CONNECT".
7982 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
7983 ha
->loop_down_abort_time
=
7984 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
7986 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
7987 ha
->loop_down_abort_time
=
7988 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
7991 /* Need enough time to try and get the port back. */
7992 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
7993 if (qlport_down_retry
)
7994 ha
->port_down_retry_count
= qlport_down_retry
;
7996 /* Set login_retry_count */
7997 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
7998 if (ha
->port_down_retry_count
==
7999 le16_to_cpu(nv
->port_down_retry_count
) &&
8000 ha
->port_down_retry_count
> 3)
8001 ha
->login_retry_count
= ha
->port_down_retry_count
;
8002 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
8003 ha
->login_retry_count
= ha
->port_down_retry_count
;
8004 if (ql2xloginretrycount
)
8005 ha
->login_retry_count
= ql2xloginretrycount
;
8007 /* if not running MSI-X we need handshaking on interrupts */
8008 if (!vha
->hw
->flags
.msix_enabled
&& (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)))
8009 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
8012 if (!vha
->flags
.init_done
) {
8013 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
8014 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
8015 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
8016 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
8018 icb
->firmware_options_2
&= cpu_to_le32(
8019 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
8020 vha
->flags
.process_response_queue
= 0;
8021 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
8022 ha
->zio_mode
= QLA_ZIO_MODE_6
;
8024 ql_log(ql_log_info
, vha
, 0x0075,
8025 "ZIO mode %d enabled; timer delay (%d us).\n",
8027 ha
->zio_timer
* 100);
8029 icb
->firmware_options_2
|= cpu_to_le32(
8030 (uint32_t)ha
->zio_mode
);
8031 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
8032 vha
->flags
.process_response_queue
= 1;
8035 /* enable RIDA Format2 */
8036 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
8037 icb
->firmware_options_3
|= BIT_0
;
8039 if (IS_QLA27XX(ha
)) {
8040 icb
->firmware_options_3
|= BIT_8
;
8041 ql_dbg(ql_log_info
, vha
, 0x0075,
8042 "Enabling direct connection.\n");
8046 ql_log(ql_log_warn
, vha
, 0x0076,
8047 "NVRAM configuration failed.\n");
8053 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
8056 struct qla_hw_data
*ha
= vha
->hw
;
8057 struct req_que
*req
= ha
->req_q_map
[0];
8058 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
8059 struct scsi_qla_host
*vp
;
8060 unsigned long flags
;
8062 status
= qla2x00_init_rings(vha
);
8064 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8065 ha
->flags
.chip_reset_done
= 1;
8067 status
= qla2x00_fw_ready(vha
);
8069 /* Issue a marker after FW becomes ready. */
8070 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
8071 vha
->flags
.online
= 1;
8072 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8075 /* if no cable then assume it's good */
8076 if ((vha
->device_flags
& DFLG_NO_CABLE
))
8081 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8083 if (!atomic_read(&vha
->loop_down_timer
)) {
8085 * Issue marker command only when we are going
8086 * to start the I/O .
8088 vha
->marker_needed
= 1;
8091 ha
->isp_ops
->enable_intrs(ha
);
8093 ha
->isp_abort_cnt
= 0;
8094 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
8096 /* Update the firmware version */
8097 status
= qla82xx_check_md_needed(vha
);
8100 ha
->flags
.fce_enabled
= 1;
8102 fce_calc_size(ha
->fce_bufs
));
8103 rval
= qla2x00_enable_fce_trace(vha
,
8104 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
8107 ql_log(ql_log_warn
, vha
, 0x8001,
8108 "Unable to reinitialize FCE (%d).\n",
8110 ha
->flags
.fce_enabled
= 0;
8115 memset(ha
->eft
, 0, EFT_SIZE
);
8116 rval
= qla2x00_enable_eft_trace(vha
,
8117 ha
->eft_dma
, EFT_NUM_BUFFERS
);
8119 ql_log(ql_log_warn
, vha
, 0x8010,
8120 "Unable to reinitialize EFT (%d).\n",
8127 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
8128 "qla82xx_restart_isp succeeded.\n");
8130 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8131 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
8133 atomic_inc(&vp
->vref_count
);
8134 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8136 qla2x00_vp_abort_isp(vp
);
8138 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8139 atomic_dec(&vp
->vref_count
);
8142 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8145 ql_log(ql_log_warn
, vha
, 0x8016,
8146 "qla82xx_restart_isp **** FAILED ****.\n");
8153 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
8155 struct qla_hw_data
*ha
= vha
->hw
;
8157 /* Hold status IOCBs until ABTS response received. */
8159 ha
->fw_options
[3] |= BIT_12
;
8161 /* Set Retry FLOGI in case of P2P connection */
8162 if (ha
->operating_mode
== P2P
) {
8163 ha
->fw_options
[2] |= BIT_3
;
8164 ql_dbg(ql_dbg_disc
, vha
, 0x2103,
8165 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8166 __func__
, ha
->fw_options
[2]);
8169 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8170 if (ql2xmvasynctoatio
) {
8171 if (qla_tgt_mode_enabled(vha
) ||
8172 qla_dual_mode_enabled(vha
))
8173 ha
->fw_options
[2] |= BIT_11
;
8175 ha
->fw_options
[2] &= ~BIT_11
;
8178 if (qla_tgt_mode_enabled(vha
) ||
8179 qla_dual_mode_enabled(vha
)) {
8180 /* FW auto send SCSI status during */
8181 ha
->fw_options
[1] |= BIT_8
;
8182 ha
->fw_options
[10] |= (u16
)SAM_STAT_BUSY
<< 8;
8184 /* FW perform Exchange validation */
8185 ha
->fw_options
[2] |= BIT_4
;
8187 ha
->fw_options
[1] &= ~BIT_8
;
8188 ha
->fw_options
[10] &= 0x00ff;
8190 ha
->fw_options
[2] &= ~BIT_4
;
8193 if (ql2xetsenable
) {
8194 /* Enable ETS Burst. */
8195 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
8196 ha
->fw_options
[2] |= BIT_9
;
8199 ql_dbg(ql_dbg_init
, vha
, 0x00e9,
8200 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8201 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
8202 ha
->fw_options
[3], vha
->host
->active_mode
);
8204 qla2x00_set_fw_options(vha
, ha
->fw_options
);
8208 * qla24xx_get_fcp_prio
8209 * Gets the fcp cmd priority value for the logged in port.
8210 * Looks for a match of the port descriptors within
8211 * each of the fcp prio config entries. If a match is found,
8212 * the tag (priority) value is returned.
8215 * vha = scsi host structure pointer.
8216 * fcport = port structure pointer.
8219 * non-zero (if found)
8226 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8229 uint8_t pid_match
, wwn_match
;
8231 uint32_t pid1
, pid2
;
8232 uint64_t wwn1
, wwn2
;
8233 struct qla_fcp_prio_entry
*pri_entry
;
8234 struct qla_hw_data
*ha
= vha
->hw
;
8236 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
8240 entries
= ha
->fcp_prio_cfg
->num_entries
;
8241 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
8243 for (i
= 0; i
< entries
; i
++) {
8244 pid_match
= wwn_match
= 0;
8246 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
8251 /* check source pid for a match */
8252 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
8253 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
8254 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
8255 if (pid1
== INVALID_PORT_ID
)
8257 else if (pid1
== pid2
)
8261 /* check destination pid for a match */
8262 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
8263 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
8264 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
8265 if (pid1
== INVALID_PORT_ID
)
8267 else if (pid1
== pid2
)
8271 /* check source WWN for a match */
8272 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
8273 wwn1
= wwn_to_u64(vha
->port_name
);
8274 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
8275 if (wwn2
== (uint64_t)-1)
8277 else if (wwn1
== wwn2
)
8281 /* check destination WWN for a match */
8282 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
8283 wwn1
= wwn_to_u64(fcport
->port_name
);
8284 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
8285 if (wwn2
== (uint64_t)-1)
8287 else if (wwn1
== wwn2
)
8291 if (pid_match
== 2 || wwn_match
== 2) {
8292 /* Found a matching entry */
8293 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
8294 priority
= pri_entry
->tag
;
8305 * qla24xx_update_fcport_fcp_prio
8306 * Activates fcp priority for the logged in fc port
8309 * vha = scsi host structure pointer.
8310 * fcp = port structure pointer.
8313 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8319 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8325 if (fcport
->port_type
!= FCT_TARGET
||
8326 fcport
->loop_id
== FC_NO_LOOP_ID
)
8327 return QLA_FUNCTION_FAILED
;
8329 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
8331 return QLA_FUNCTION_FAILED
;
8333 if (IS_P3P_TYPE(vha
->hw
)) {
8334 fcport
->fcp_prio
= priority
& 0xf;
8338 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
8339 if (ret
== QLA_SUCCESS
) {
8340 if (fcport
->fcp_prio
!= priority
)
8341 ql_dbg(ql_dbg_user
, vha
, 0x709e,
8342 "Updated FCP_CMND priority - value=%d loop_id=%d "
8343 "port_id=%02x%02x%02x.\n", priority
,
8344 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
8345 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
8346 fcport
->fcp_prio
= priority
& 0xf;
8348 ql_dbg(ql_dbg_user
, vha
, 0x704f,
8349 "Unable to update FCP_CMND priority - ret=0x%x for "
8350 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
8351 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
8352 fcport
->d_id
.b
.al_pa
);
8357 * qla24xx_update_all_fcp_prio
8358 * Activates fcp priority for all the logged in ports
8361 * ha = adapter block pointer.
8364 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8370 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
8375 ret
= QLA_FUNCTION_FAILED
;
8376 /* We need to set priority for all logged in ports */
8377 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
8378 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);
8383 struct qla_qpair
*qla2xxx_create_qpair(struct scsi_qla_host
*vha
, int qos
,
8384 int vp_idx
, bool startqp
)
8389 struct qla_hw_data
*ha
= vha
->hw
;
8390 uint16_t qpair_id
= 0;
8391 struct qla_qpair
*qpair
= NULL
;
8392 struct qla_msix_entry
*msix
;
8394 if (!(ha
->fw_attributes
& BIT_6
) || !ha
->flags
.msix_enabled
) {
8395 ql_log(ql_log_warn
, vha
, 0x00181,
8396 "FW/Driver is not multi-queue capable.\n");
8400 if (ql2xmqsupport
|| ql2xnvmeenable
) {
8401 qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
8402 if (qpair
== NULL
) {
8403 ql_log(ql_log_warn
, vha
, 0x0182,
8404 "Failed to allocate memory for queue pair.\n");
8407 memset(qpair
, 0, sizeof(struct qla_qpair
));
8409 qpair
->hw
= vha
->hw
;
8411 qpair
->qp_lock_ptr
= &qpair
->qp_lock
;
8412 spin_lock_init(&qpair
->qp_lock
);
8413 qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
8415 /* Assign available que pair id */
8416 mutex_lock(&ha
->mq_lock
);
8417 qpair_id
= find_first_zero_bit(ha
->qpair_qid_map
, ha
->max_qpairs
);
8418 if (ha
->num_qpairs
>= ha
->max_qpairs
) {
8419 mutex_unlock(&ha
->mq_lock
);
8420 ql_log(ql_log_warn
, vha
, 0x0183,
8421 "No resources to create additional q pair.\n");
8425 set_bit(qpair_id
, ha
->qpair_qid_map
);
8426 ha
->queue_pair_map
[qpair_id
] = qpair
;
8427 qpair
->id
= qpair_id
;
8428 qpair
->vp_idx
= vp_idx
;
8429 qpair
->fw_started
= ha
->flags
.fw_started
;
8430 INIT_LIST_HEAD(&qpair
->hints_list
);
8431 qpair
->chip_reset
= ha
->base_qpair
->chip_reset
;
8432 qpair
->enable_class_2
= ha
->base_qpair
->enable_class_2
;
8433 qpair
->enable_explicit_conf
=
8434 ha
->base_qpair
->enable_explicit_conf
;
8436 for (i
= 0; i
< ha
->msix_count
; i
++) {
8437 msix
= &ha
->msix_entries
[i
];
8441 ql_dbg(ql_dbg_multiq
, vha
, 0xc00f,
8442 "Vector %x selected for qpair\n", msix
->vector
);
8446 ql_log(ql_log_warn
, vha
, 0x0184,
8447 "Out of MSI-X vectors!.\n");
8451 qpair
->msix
->in_use
= 1;
8452 list_add_tail(&qpair
->qp_list_elem
, &vha
->qp_list
);
8453 qpair
->pdev
= ha
->pdev
;
8454 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
))
8455 qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
8457 mutex_unlock(&ha
->mq_lock
);
8459 /* Create response queue first */
8460 rsp_id
= qla25xx_create_rsp_que(ha
, 0, 0, 0, qpair
, startqp
);
8462 ql_log(ql_log_warn
, vha
, 0x0185,
8463 "Failed to create response queue.\n");
8467 qpair
->rsp
= ha
->rsp_q_map
[rsp_id
];
8469 /* Create request queue */
8470 req_id
= qla25xx_create_req_que(ha
, 0, vp_idx
, 0, rsp_id
, qos
,
8473 ql_log(ql_log_warn
, vha
, 0x0186,
8474 "Failed to create request queue.\n");
8478 qpair
->req
= ha
->req_q_map
[req_id
];
8479 qpair
->rsp
->req
= qpair
->req
;
8480 qpair
->rsp
->qpair
= qpair
;
8481 /* init qpair to this cpu. Will adjust at run time. */
8482 qla_cpu_update(qpair
, smp_processor_id());
8484 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
8485 if (ha
->fw_attributes
& BIT_4
)
8486 qpair
->difdix_supported
= 1;
8489 qpair
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
8490 if (!qpair
->srb_mempool
) {
8491 ql_log(ql_log_warn
, vha
, 0xd036,
8492 "Failed to create srb mempool for qpair %d\n",
8497 /* Mark as online */
8500 if (!vha
->flags
.qpairs_available
)
8501 vha
->flags
.qpairs_available
= 1;
8503 ql_dbg(ql_dbg_multiq
, vha
, 0xc00d,
8504 "Request/Response queue pair created, id %d\n",
8506 ql_dbg(ql_dbg_init
, vha
, 0x0187,
8507 "Request/Response queue pair created, id %d\n",
8514 qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8516 mutex_lock(&ha
->mq_lock
);
8517 qpair
->msix
->in_use
= 0;
8518 list_del(&qpair
->qp_list_elem
);
8519 if (list_empty(&vha
->qp_list
))
8520 vha
->flags
.qpairs_available
= 0;
8522 ha
->queue_pair_map
[qpair_id
] = NULL
;
8523 clear_bit(qpair_id
, ha
->qpair_qid_map
);
8525 mutex_unlock(&ha
->mq_lock
);
8531 int qla2xxx_delete_qpair(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
)
8533 int ret
= QLA_FUNCTION_FAILED
;
8534 struct qla_hw_data
*ha
= qpair
->hw
;
8536 qpair
->delete_in_progress
= 1;
8537 while (atomic_read(&qpair
->ref_count
))
8540 ret
= qla25xx_delete_req_que(vha
, qpair
->req
);
8541 if (ret
!= QLA_SUCCESS
)
8544 ret
= qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8545 if (ret
!= QLA_SUCCESS
)
8548 mutex_lock(&ha
->mq_lock
);
8549 ha
->queue_pair_map
[qpair
->id
] = NULL
;
8550 clear_bit(qpair
->id
, ha
->qpair_qid_map
);
8552 list_del(&qpair
->qp_list_elem
);
8553 if (list_empty(&vha
->qp_list
)) {
8554 vha
->flags
.qpairs_available
= 0;
8555 vha
->flags
.qpairs_req_created
= 0;
8556 vha
->flags
.qpairs_rsp_created
= 0;
8558 mempool_destroy(qpair
->srb_mempool
);
8560 mutex_unlock(&ha
->mq_lock
);