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 if (sp
->type
!= SRB_ELS_DCMD
)
64 spin_unlock_irqrestore(&vha
->hw
->hardware_lock
, flags
);
68 qla2x00_sp_free(void *ptr
)
71 struct srb_iocb
*iocb
= &sp
->u
.iocb_cmd
;
73 del_timer(&iocb
->timer
);
77 /* Asynchronous Login/Logout Routines -------------------------------------- */
80 qla2x00_get_async_timeout(struct scsi_qla_host
*vha
)
83 struct qla_hw_data
*ha
= vha
->hw
;
85 /* Firmware should use switch negotiated r_a_tov for timeout. */
86 tmo
= ha
->r_a_tov
/ 10 * 2;
88 tmo
= FX00_DEF_RATOV
* 2;
89 } else if (!IS_FWI2_CAPABLE(ha
)) {
91 * Except for earlier ISPs where the timeout is seeded from the
92 * initialization control block.
94 tmo
= ha
->login_timeout
;
100 qla2x00_async_iocb_timeout(void *data
)
103 fc_port_t
*fcport
= sp
->fcport
;
104 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
108 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x2071,
109 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
110 sp
->name
, sp
->handle
, fcport
->d_id
.b24
, fcport
->port_name
);
112 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
114 pr_info("Async-%s timeout - hdl=%x.\n",
115 sp
->name
, sp
->handle
);
122 /* Retry as needed. */
123 lio
->u
.logio
.data
[0] = MBS_COMMAND_ERROR
;
124 lio
->u
.logio
.data
[1] = lio
->u
.logio
.flags
& SRB_LOGIN_RETRIED
?
125 QLA_LOGIO_LOGIN_RETRIED
: 0;
126 memset(&ea
, 0, sizeof(ea
));
127 ea
.event
= FCME_PLOGI_DONE
;
128 ea
.fcport
= sp
->fcport
;
129 ea
.data
[0] = lio
->u
.logio
.data
[0];
130 ea
.data
[1] = lio
->u
.logio
.data
[1];
132 qla24xx_handle_plogi_done_event(fcport
->vha
, &ea
);
137 qlt_logo_completion_handler(fcport
, QLA_FUNCTION_TIMEOUT
);
139 case SRB_CT_PTHRU_CMD
:
145 sp
->done(sp
, QLA_FUNCTION_TIMEOUT
);
151 qla2x00_async_login_sp_done(void *ptr
, int res
)
154 struct scsi_qla_host
*vha
= sp
->vha
;
155 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
158 ql_dbg(ql_dbg_disc
, vha
, 0x20dd,
159 "%s %8phC res %d \n", __func__
, sp
->fcport
->port_name
, res
);
161 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
163 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
164 memset(&ea
, 0, sizeof(ea
));
165 ea
.event
= FCME_PLOGI_DONE
;
166 ea
.fcport
= sp
->fcport
;
167 ea
.data
[0] = lio
->u
.logio
.data
[0];
168 ea
.data
[1] = lio
->u
.logio
.data
[1];
169 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
170 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
172 qla2x00_fcport_event_handler(vha
, &ea
);
179 qla2x00_async_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
183 struct srb_iocb
*lio
;
184 int rval
= QLA_FUNCTION_FAILED
;
186 if (!vha
->flags
.online
)
189 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
193 fcport
->flags
|= FCF_ASYNC_SENT
;
194 fcport
->logout_completed
= 0;
196 fcport
->disc_state
= DSC_LOGIN_PEND
;
197 sp
->type
= SRB_LOGIN_CMD
;
199 sp
->gen1
= fcport
->rscn_gen
;
200 sp
->gen2
= fcport
->login_gen
;
201 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
203 lio
= &sp
->u
.iocb_cmd
;
204 lio
->timeout
= qla2x00_async_iocb_timeout
;
205 sp
->done
= qla2x00_async_login_sp_done
;
206 lio
->u
.logio
.flags
|= SRB_LOGIN_COND_PLOGI
;
208 if (fcport
->fc4f_nvme
)
209 lio
->u
.logio
.flags
|= SRB_LOGIN_SKIP_PRLI
;
211 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
212 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
213 rval
= qla2x00_start_sp(sp
);
214 if (rval
!= QLA_SUCCESS
) {
215 fcport
->flags
|= FCF_LOGIN_NEEDED
;
216 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
220 ql_dbg(ql_dbg_disc
, vha
, 0x2072,
221 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
222 "retries=%d.\n", fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
223 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
224 fcport
->login_retry
);
229 fcport
->flags
&= ~FCF_ASYNC_SENT
;
235 qla2x00_async_logout_sp_done(void *ptr
, int res
)
238 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
240 sp
->fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
241 if (!test_bit(UNLOADING
, &sp
->vha
->dpc_flags
))
242 qla2x00_post_async_logout_done_work(sp
->vha
, sp
->fcport
,
248 qla2x00_async_logout(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
251 struct srb_iocb
*lio
;
252 int rval
= QLA_FUNCTION_FAILED
;
254 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
257 fcport
->flags
|= FCF_ASYNC_SENT
;
258 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
262 sp
->type
= SRB_LOGOUT_CMD
;
264 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
266 lio
= &sp
->u
.iocb_cmd
;
267 lio
->timeout
= qla2x00_async_iocb_timeout
;
268 sp
->done
= qla2x00_async_logout_sp_done
;
269 rval
= qla2x00_start_sp(sp
);
270 if (rval
!= QLA_SUCCESS
)
273 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
274 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
275 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
276 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
283 fcport
->flags
&= ~FCF_ASYNC_SENT
;
288 qla2x00_async_prlo_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
291 /* Don't re-login in target mode */
292 if (!fcport
->tgt_session
)
293 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
294 qlt_logo_completion_handler(fcport
, data
[0]);
298 qla2x00_async_prlo_sp_done(void *s
, int res
)
300 srb_t
*sp
= (srb_t
*)s
;
301 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
302 struct scsi_qla_host
*vha
= sp
->vha
;
304 if (!test_bit(UNLOADING
, &vha
->dpc_flags
))
305 qla2x00_post_async_prlo_done_work(sp
->fcport
->vha
, sp
->fcport
,
311 qla2x00_async_prlo(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
314 struct srb_iocb
*lio
;
317 rval
= QLA_FUNCTION_FAILED
;
318 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
322 sp
->type
= SRB_PRLO_CMD
;
324 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
326 lio
= &sp
->u
.iocb_cmd
;
327 lio
->timeout
= qla2x00_async_iocb_timeout
;
328 sp
->done
= qla2x00_async_prlo_sp_done
;
329 rval
= qla2x00_start_sp(sp
);
330 if (rval
!= QLA_SUCCESS
)
333 ql_dbg(ql_dbg_disc
, vha
, 0x2070,
334 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
335 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
336 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
346 void qla24xx_handle_adisc_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
348 struct fc_port
*fcport
= ea
->fcport
;
350 ql_dbg(ql_dbg_disc
, vha
, 0x20d2,
351 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
352 __func__
, fcport
->port_name
, fcport
->disc_state
,
353 fcport
->fw_login_state
, ea
->rc
, fcport
->login_gen
, ea
->sp
->gen2
,
354 fcport
->rscn_gen
, ea
->sp
->gen1
, fcport
->loop_id
);
356 if (ea
->data
[0] != MBS_COMMAND_COMPLETE
) {
357 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
358 "%s %8phC: adisc fail: post delete\n",
359 __func__
, ea
->fcport
->port_name
);
360 qlt_schedule_sess_for_deletion(ea
->fcport
);
364 if (ea
->fcport
->disc_state
== DSC_DELETE_PEND
)
367 if (ea
->sp
->gen2
!= ea
->fcport
->login_gen
) {
368 /* target side must have changed it. */
369 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
370 "%s %8phC generation changed\n",
371 __func__
, ea
->fcport
->port_name
);
373 } else if (ea
->sp
->gen1
!= ea
->fcport
->rscn_gen
) {
374 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
375 __func__
, __LINE__
, ea
->fcport
->port_name
);
376 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
380 __qla24xx_handle_gpdb_event(vha
, ea
);
384 qla2x00_async_adisc_sp_done(void *ptr
, int res
)
387 struct scsi_qla_host
*vha
= sp
->vha
;
389 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
391 ql_dbg(ql_dbg_disc
, vha
, 0x2066,
392 "Async done-%s res %x %8phC\n",
393 sp
->name
, res
, sp
->fcport
->port_name
);
395 memset(&ea
, 0, sizeof(ea
));
396 ea
.event
= FCME_ADISC_DONE
;
398 ea
.data
[0] = lio
->u
.logio
.data
[0];
399 ea
.data
[1] = lio
->u
.logio
.data
[1];
400 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
401 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
402 ea
.fcport
= sp
->fcport
;
405 qla2x00_fcport_event_handler(vha
, &ea
);
411 qla2x00_async_adisc(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
415 struct srb_iocb
*lio
;
418 rval
= QLA_FUNCTION_FAILED
;
419 fcport
->flags
|= FCF_ASYNC_SENT
;
420 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
424 sp
->type
= SRB_ADISC_CMD
;
426 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
428 lio
= &sp
->u
.iocb_cmd
;
429 lio
->timeout
= qla2x00_async_iocb_timeout
;
430 sp
->done
= qla2x00_async_adisc_sp_done
;
431 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
432 lio
->u
.logio
.flags
|= SRB_LOGIN_RETRIED
;
433 rval
= qla2x00_start_sp(sp
);
434 if (rval
!= QLA_SUCCESS
)
437 ql_dbg(ql_dbg_disc
, vha
, 0x206f,
438 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
439 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b24
, fcport
->port_name
);
445 fcport
->flags
&= ~FCF_ASYNC_SENT
;
446 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
450 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t
*vha
,
451 struct event_arg
*ea
)
453 fc_port_t
*fcport
, *conflict_fcport
;
454 struct get_name_list_extended
*e
;
455 u16 i
, n
, found
= 0, loop_id
;
459 u8 current_login_state
;
462 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
463 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
464 __func__
, fcport
->port_name
, fcport
->disc_state
,
465 fcport
->fw_login_state
, ea
->rc
,
466 fcport
->login_gen
, fcport
->last_login_gen
,
467 fcport
->rscn_gen
, fcport
->last_rscn_gen
, vha
->loop_id
);
469 if (fcport
->disc_state
== DSC_DELETE_PEND
)
472 if (ea
->rc
) { /* rval */
473 if (fcport
->login_retry
== 0) {
474 fcport
->login_retry
= vha
->hw
->login_retry_count
;
475 ql_dbg(ql_dbg_disc
, vha
, 0x20de,
476 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
477 fcport
->port_name
, fcport
->login_retry
);
482 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
483 ql_dbg(ql_dbg_disc
, vha
, 0x20df,
484 "%s %8phC rscn gen changed rscn %d|%d \n",
485 __func__
, fcport
->port_name
,
486 fcport
->last_rscn_gen
, fcport
->rscn_gen
);
487 qla24xx_post_gidpn_work(vha
, fcport
);
489 } else if (fcport
->last_login_gen
!= fcport
->login_gen
) {
490 ql_dbg(ql_dbg_disc
, vha
, 0x20e0,
491 "%s %8phC login gen changed\n",
492 __func__
, fcport
->port_name
);
496 n
= ea
->data
[0] / sizeof(struct get_name_list_extended
);
498 ql_dbg(ql_dbg_disc
, vha
, 0x20e1,
499 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
500 __func__
, __LINE__
, fcport
->port_name
, n
,
501 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
502 fcport
->d_id
.b
.al_pa
, fcport
->loop_id
);
504 for (i
= 0; i
< n
; i
++) {
506 wwn
= wwn_to_u64(e
->port_name
);
508 if (memcmp((u8
*)&wwn
, fcport
->port_name
, WWN_SIZE
))
512 id
.b
.domain
= e
->port_id
[2];
513 id
.b
.area
= e
->port_id
[1];
514 id
.b
.al_pa
= e
->port_id
[0];
517 loop_id
= le16_to_cpu(e
->nport_handle
);
518 loop_id
= (loop_id
& 0x7fff);
520 ql_dbg(ql_dbg_disc
, vha
, 0x20e2,
521 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
522 __func__
, fcport
->port_name
,
523 e
->current_login_state
, fcport
->fw_login_state
,
524 id
.b
.domain
, id
.b
.area
, id
.b
.al_pa
,
525 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
526 fcport
->d_id
.b
.al_pa
, loop_id
, fcport
->loop_id
);
528 if ((id
.b24
!= fcport
->d_id
.b24
) ||
529 ((fcport
->loop_id
!= FC_NO_LOOP_ID
) &&
530 (fcport
->loop_id
!= loop_id
))) {
531 ql_dbg(ql_dbg_disc
, vha
, 0x20e3,
532 "%s %d %8phC post del sess\n",
533 __func__
, __LINE__
, fcport
->port_name
);
534 qlt_schedule_sess_for_deletion(fcport
);
538 fcport
->loop_id
= loop_id
;
540 wwn
= wwn_to_u64(fcport
->port_name
);
541 qlt_find_sess_invalidate_other(vha
, wwn
,
542 id
, loop_id
, &conflict_fcport
);
544 if (conflict_fcport
) {
546 * Another share fcport share the same loop_id &
547 * nport id. Conflict fcport needs to finish
548 * cleanup before this fcport can proceed to login.
550 conflict_fcport
->conflict
= fcport
;
551 fcport
->login_pause
= 1;
554 if (fcport
->fc4f_nvme
)
555 current_login_state
= e
->current_login_state
>> 4;
557 current_login_state
= e
->current_login_state
& 0xf;
559 switch (current_login_state
) {
560 case DSC_LS_PRLI_COMP
:
561 ql_dbg(ql_dbg_disc
, vha
, 0x20e4,
562 "%s %d %8phC post gpdb\n",
563 __func__
, __LINE__
, fcport
->port_name
);
565 if ((e
->prli_svc_param_word_3
[0] & BIT_4
) == 0)
566 fcport
->port_type
= FCT_INITIATOR
;
568 fcport
->port_type
= FCT_TARGET
;
570 data
[0] = data
[1] = 0;
571 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
573 case DSC_LS_PORT_UNAVAIL
:
575 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
576 qla2x00_find_new_loop_id(vha
, fcport
);
577 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
579 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
581 __func__
, __LINE__
, fcport
->port_name
);
582 qla24xx_fcport_handle_login(vha
, fcport
);
588 /* fw has no record of this port */
589 for (i
= 0; i
< n
; i
++) {
591 id
.b
.domain
= e
->port_id
[0];
592 id
.b
.area
= e
->port_id
[1];
593 id
.b
.al_pa
= e
->port_id
[2];
595 loop_id
= le16_to_cpu(e
->nport_handle
);
597 if (fcport
->d_id
.b24
== id
.b24
) {
599 qla2x00_find_fcport_by_wwpn(vha
,
601 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
602 "%s %d %8phC post del sess\n",
604 conflict_fcport
->port_name
);
605 qlt_schedule_sess_for_deletion
609 /* FW already picked this loop id for another fcport */
610 if (fcport
->loop_id
== loop_id
)
611 fcport
->loop_id
= FC_NO_LOOP_ID
;
613 qla24xx_fcport_handle_login(vha
, fcport
);
618 qla24xx_async_gnl_sp_done(void *s
, int res
)
621 struct scsi_qla_host
*vha
= sp
->vha
;
623 struct fc_port
*fcport
= NULL
, *tf
;
624 u16 i
, n
= 0, loop_id
;
626 struct get_name_list_extended
*e
;
631 ql_dbg(ql_dbg_disc
, vha
, 0x20e7,
632 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
633 sp
->name
, res
, sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1],
634 sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[2]);
636 memset(&ea
, 0, sizeof(ea
));
639 ea
.event
= FCME_GNL_DONE
;
641 if (sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] >=
642 sizeof(struct get_name_list_extended
)) {
643 n
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1] /
644 sizeof(struct get_name_list_extended
);
645 ea
.data
[0] = sp
->u
.iocb_cmd
.u
.mbx
.in_mb
[1]; /* amnt xfered */
648 for (i
= 0; i
< n
; i
++) {
650 loop_id
= le16_to_cpu(e
->nport_handle
);
651 /* mask out reserve bit */
652 loop_id
= (loop_id
& 0x7fff);
653 set_bit(loop_id
, vha
->hw
->loop_id_map
);
654 wwn
= wwn_to_u64(e
->port_name
);
656 ql_dbg(ql_dbg_disc
+ ql_dbg_verbose
, vha
, 0x20e8,
657 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
658 __func__
, (void *)&wwn
, e
->port_id
[2], e
->port_id
[1],
659 e
->port_id
[0], e
->current_login_state
, e
->last_login_state
,
663 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
668 if (!list_empty(&vha
->gnl
.fcports
))
669 list_splice_init(&vha
->gnl
.fcports
, &h
);
671 list_for_each_entry_safe(fcport
, tf
, &h
, gnl_entry
) {
672 list_del_init(&fcport
->gnl_entry
);
673 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
676 qla2x00_fcport_event_handler(vha
, &ea
);
679 /* create new fcport if fw has knowledge of new sessions */
680 for (i
= 0; i
< n
; i
++) {
685 wwn
= wwn_to_u64(e
->port_name
);
688 list_for_each_entry_safe(fcport
, tf
, &vha
->vp_fcports
, list
) {
689 if (!memcmp((u8
*)&wwn
, fcport
->port_name
,
696 id
.b
.domain
= e
->port_id
[2];
697 id
.b
.area
= e
->port_id
[1];
698 id
.b
.al_pa
= e
->port_id
[0];
701 if (!found
&& wwn
&& !IS_SW_RESV_ADDR(id
)) {
702 ql_dbg(ql_dbg_disc
, vha
, 0x2065,
703 "%s %d %8phC %06x post new sess\n",
704 __func__
, __LINE__
, (u8
*)&wwn
, id
.b24
);
705 wwnn
= wwn_to_u64(e
->node_name
);
706 qla24xx_post_newsess_work(vha
, &id
, (u8
*)&wwn
,
707 (u8
*)&wwnn
, NULL
, FC4_TYPE_UNKNOWN
);
711 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
716 int qla24xx_async_gnl(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
719 struct srb_iocb
*mbx
;
720 int rval
= QLA_FUNCTION_FAILED
;
724 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
727 ql_dbg(ql_dbg_disc
, vha
, 0x20d9,
728 "Async-gnlist WWPN %8phC \n", fcport
->port_name
);
730 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
731 fcport
->disc_state
= DSC_GNL
;
732 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
733 fcport
->last_login_gen
= fcport
->login_gen
;
735 list_add_tail(&fcport
->gnl_entry
, &vha
->gnl
.fcports
);
737 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
741 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
743 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
747 fcport
->flags
|= FCF_ASYNC_SENT
;
748 sp
->type
= SRB_MB_IOCB
;
750 sp
->gen1
= fcport
->rscn_gen
;
751 sp
->gen2
= fcport
->login_gen
;
753 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
)+2);
755 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
756 mb
[0] = MBC_PORT_NODE_NAME_LIST
;
757 mb
[1] = BIT_2
| BIT_3
;
758 mb
[2] = MSW(vha
->gnl
.ldma
);
759 mb
[3] = LSW(vha
->gnl
.ldma
);
760 mb
[6] = MSW(MSD(vha
->gnl
.ldma
));
761 mb
[7] = LSW(MSD(vha
->gnl
.ldma
));
762 mb
[8] = vha
->gnl
.size
;
765 mbx
= &sp
->u
.iocb_cmd
;
766 mbx
->timeout
= qla2x00_async_iocb_timeout
;
768 sp
->done
= qla24xx_async_gnl_sp_done
;
770 rval
= qla2x00_start_sp(sp
);
771 if (rval
!= QLA_SUCCESS
)
774 ql_dbg(ql_dbg_disc
, vha
, 0x20da,
775 "Async-%s - OUT WWPN %8phC hndl %x\n",
776 sp
->name
, fcport
->port_name
, sp
->handle
);
782 fcport
->flags
&= ~FCF_ASYNC_SENT
;
787 int qla24xx_post_gnl_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
789 struct qla_work_evt
*e
;
791 e
= qla2x00_alloc_work(vha
, QLA_EVT_GNL
);
793 return QLA_FUNCTION_FAILED
;
795 e
->u
.fcport
.fcport
= fcport
;
796 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
797 return qla2x00_post_work(vha
, e
);
801 void qla24xx_async_gpdb_sp_done(void *s
, int res
)
804 struct scsi_qla_host
*vha
= sp
->vha
;
805 struct qla_hw_data
*ha
= vha
->hw
;
806 fc_port_t
*fcport
= sp
->fcport
;
807 u16
*mb
= sp
->u
.iocb_cmd
.u
.mbx
.in_mb
;
810 ql_dbg(ql_dbg_disc
, vha
, 0x20db,
811 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
812 sp
->name
, res
, fcport
->port_name
, mb
[1], mb
[2]);
814 fcport
->flags
&= ~(FCF_ASYNC_SENT
| FCF_ASYNC_ACTIVE
);
816 memset(&ea
, 0, sizeof(ea
));
817 ea
.event
= FCME_GPDB_DONE
;
821 qla2x00_fcport_event_handler(vha
, &ea
);
823 dma_pool_free(ha
->s_dma_pool
, sp
->u
.iocb_cmd
.u
.mbx
.in
,
824 sp
->u
.iocb_cmd
.u
.mbx
.in_dma
);
829 static int qla24xx_post_prli_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
831 struct qla_work_evt
*e
;
833 e
= qla2x00_alloc_work(vha
, QLA_EVT_PRLI
);
835 return QLA_FUNCTION_FAILED
;
837 e
->u
.fcport
.fcport
= fcport
;
839 return qla2x00_post_work(vha
, e
);
843 qla2x00_async_prli_sp_done(void *ptr
, int res
)
846 struct scsi_qla_host
*vha
= sp
->vha
;
847 struct srb_iocb
*lio
= &sp
->u
.iocb_cmd
;
850 ql_dbg(ql_dbg_disc
, vha
, 0x2129,
851 "%s %8phC res %d \n", __func__
,
852 sp
->fcport
->port_name
, res
);
854 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
856 if (!test_bit(UNLOADING
, &vha
->dpc_flags
)) {
857 memset(&ea
, 0, sizeof(ea
));
858 ea
.event
= FCME_PRLI_DONE
;
859 ea
.fcport
= sp
->fcport
;
860 ea
.data
[0] = lio
->u
.logio
.data
[0];
861 ea
.data
[1] = lio
->u
.logio
.data
[1];
862 ea
.iop
[0] = lio
->u
.logio
.iop
[0];
863 ea
.iop
[1] = lio
->u
.logio
.iop
[1];
866 qla2x00_fcport_event_handler(vha
, &ea
);
873 qla24xx_async_prli(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
876 struct srb_iocb
*lio
;
877 int rval
= QLA_FUNCTION_FAILED
;
879 if (!vha
->flags
.online
)
882 if (fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
||
883 fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
||
884 fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)
887 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
891 fcport
->flags
|= FCF_ASYNC_SENT
;
892 fcport
->logout_completed
= 0;
894 sp
->type
= SRB_PRLI_CMD
;
896 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
898 lio
= &sp
->u
.iocb_cmd
;
899 lio
->timeout
= qla2x00_async_iocb_timeout
;
900 sp
->done
= qla2x00_async_prli_sp_done
;
901 lio
->u
.logio
.flags
= 0;
903 if (fcport
->fc4f_nvme
)
904 lio
->u
.logio
.flags
|= SRB_LOGIN_NVME_PRLI
;
906 rval
= qla2x00_start_sp(sp
);
907 if (rval
!= QLA_SUCCESS
) {
908 fcport
->flags
|= FCF_LOGIN_NEEDED
;
909 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
913 ql_dbg(ql_dbg_disc
, vha
, 0x211b,
914 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
915 fcport
->port_name
, sp
->handle
, fcport
->loop_id
,
916 fcport
->d_id
.b24
, fcport
->login_retry
);
922 fcport
->flags
&= ~FCF_ASYNC_SENT
;
926 int qla24xx_post_gpdb_work(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
928 struct qla_work_evt
*e
;
930 e
= qla2x00_alloc_work(vha
, QLA_EVT_GPDB
);
932 return QLA_FUNCTION_FAILED
;
934 e
->u
.fcport
.fcport
= fcport
;
935 e
->u
.fcport
.opt
= opt
;
936 fcport
->flags
|= FCF_ASYNC_ACTIVE
;
937 return qla2x00_post_work(vha
, e
);
940 int qla24xx_async_gpdb(struct scsi_qla_host
*vha
, fc_port_t
*fcport
, u8 opt
)
943 struct srb_iocb
*mbx
;
944 int rval
= QLA_FUNCTION_FAILED
;
947 struct port_database_24xx
*pd
;
948 struct qla_hw_data
*ha
= vha
->hw
;
950 if (!vha
->flags
.online
|| (fcport
->flags
& FCF_ASYNC_SENT
))
953 fcport
->disc_state
= DSC_GPDB
;
955 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
959 fcport
->flags
|= FCF_ASYNC_SENT
;
960 sp
->type
= SRB_MB_IOCB
;
962 sp
->gen1
= fcport
->rscn_gen
;
963 sp
->gen2
= fcport
->login_gen
;
964 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
) + 2);
966 pd
= dma_pool_zalloc(ha
->s_dma_pool
, GFP_KERNEL
, &pd_dma
);
968 ql_log(ql_log_warn
, vha
, 0xd043,
969 "Failed to allocate port database structure.\n");
973 mb
= sp
->u
.iocb_cmd
.u
.mbx
.out_mb
;
974 mb
[0] = MBC_GET_PORT_DATABASE
;
975 mb
[1] = fcport
->loop_id
;
978 mb
[6] = MSW(MSD(pd_dma
));
979 mb
[7] = LSW(MSD(pd_dma
));
983 mbx
= &sp
->u
.iocb_cmd
;
984 mbx
->timeout
= qla2x00_async_iocb_timeout
;
985 mbx
->u
.mbx
.in
= (void *)pd
;
986 mbx
->u
.mbx
.in_dma
= pd_dma
;
988 sp
->done
= qla24xx_async_gpdb_sp_done
;
990 rval
= qla2x00_start_sp(sp
);
991 if (rval
!= QLA_SUCCESS
)
994 ql_dbg(ql_dbg_disc
, vha
, 0x20dc,
995 "Async-%s %8phC hndl %x opt %x\n",
996 sp
->name
, fcport
->port_name
, sp
->handle
, opt
);
1002 dma_pool_free(ha
->s_dma_pool
, pd
, pd_dma
);
1005 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1007 qla24xx_post_gpdb_work(vha
, fcport
, opt
);
1012 void __qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1014 unsigned long flags
;
1016 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1017 ea
->fcport
->login_gen
++;
1018 ea
->fcport
->deleted
= 0;
1019 ea
->fcport
->logout_on_delete
= 1;
1021 if (!ea
->fcport
->login_succ
&& !IS_SW_RESV_ADDR(ea
->fcport
->d_id
)) {
1022 vha
->fcport_count
++;
1023 ea
->fcport
->login_succ
= 1;
1025 if (!IS_IIDMA_CAPABLE(vha
->hw
) ||
1026 !vha
->hw
->flags
.gpsc_supported
) {
1027 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1028 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1029 __func__
, __LINE__
, ea
->fcport
->port_name
,
1032 qla24xx_post_upd_fcport_work(vha
, ea
->fcport
);
1034 if (ea
->fcport
->id_changed
) {
1035 ea
->fcport
->id_changed
= 0;
1036 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
1037 "%s %d %8phC post gfpnid fcp_cnt %d\n",
1038 __func__
, __LINE__
, ea
->fcport
->port_name
,
1040 qla24xx_post_gfpnid_work(vha
, ea
->fcport
);
1042 ql_dbg(ql_dbg_disc
, vha
, 0x20d7,
1043 "%s %d %8phC post gpsc fcp_cnt %d\n",
1044 __func__
, __LINE__
, ea
->fcport
->port_name
,
1046 qla24xx_post_gpsc_work(vha
, ea
->fcport
);
1049 } else if (ea
->fcport
->login_succ
) {
1051 * We have an existing session. A late RSCN delivery
1052 * must have triggered the session to be re-validate.
1053 * Session is still valid.
1055 ql_dbg(ql_dbg_disc
, vha
, 0x20d6,
1056 "%s %d %8phC session revalidate success\n",
1057 __func__
, __LINE__
, ea
->fcport
->port_name
);
1058 ea
->fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
1060 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1064 void qla24xx_handle_gpdb_event(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1066 fc_port_t
*fcport
= ea
->fcport
;
1067 struct port_database_24xx
*pd
;
1068 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 switch (pd
->current_login_state
) {
1082 case PDS_PRLI_COMPLETE
:
1083 __qla24xx_parse_gpdb(vha
, fcport
, pd
);
1085 case PDS_PLOGI_PENDING
:
1086 case PDS_PLOGI_COMPLETE
:
1087 case PDS_PRLI_PENDING
:
1088 case PDS_PRLI2_PENDING
:
1089 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC relogin needed\n",
1090 __func__
, __LINE__
, fcport
->port_name
);
1091 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1093 case PDS_LOGO_PENDING
:
1094 case PDS_PORT_UNAVAILABLE
:
1096 ql_dbg(ql_dbg_disc
, vha
, 0x20d5, "%s %d %8phC post del sess\n",
1097 __func__
, __LINE__
, fcport
->port_name
);
1098 qlt_schedule_sess_for_deletion(fcport
);
1101 __qla24xx_handle_gpdb_event(vha
, ea
);
1104 static void qla_chk_n2n_b4_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1109 if (qla_tgt_mode_enabled(vha
))
1112 if (qla_dual_mode_enabled(vha
)) {
1113 if (N2N_TOPO(vha
->hw
)) {
1116 mywwn
= wwn_to_u64(vha
->port_name
);
1117 wwn
= wwn_to_u64(fcport
->port_name
);
1120 else if ((fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
)
1121 && time_after_eq(jiffies
,
1122 fcport
->plogi_nack_done_deadline
))
1128 /* initiator mode */
1133 if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1134 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
1135 rc
= qla2x00_find_new_loop_id(vha
, fcport
);
1137 ql_dbg(ql_dbg_disc
, vha
, 0x20e6,
1138 "%s %d %8phC post del sess - out of loopid\n",
1139 __func__
, __LINE__
, fcport
->port_name
);
1140 fcport
->scan_state
= 0;
1141 qlt_schedule_sess_for_deletion(fcport
);
1145 ql_dbg(ql_dbg_disc
, vha
, 0x20bf,
1146 "%s %d %8phC post login\n",
1147 __func__
, __LINE__
, fcport
->port_name
);
1148 qla2x00_post_async_login_work(vha
, fcport
, NULL
);
1152 int qla24xx_fcport_handle_login(struct scsi_qla_host
*vha
, fc_port_t
*fcport
)
1157 ql_dbg(ql_dbg_disc
, vha
, 0x20d8,
1158 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
1159 __func__
, fcport
->port_name
, fcport
->disc_state
,
1160 fcport
->fw_login_state
, fcport
->login_pause
, fcport
->flags
,
1161 fcport
->conflict
, fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1162 fcport
->login_gen
, fcport
->login_retry
,
1163 fcport
->loop_id
, fcport
->scan_state
);
1165 if (fcport
->login_retry
== 0)
1168 if (fcport
->scan_state
!= QLA_FCPORT_FOUND
)
1171 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1172 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1175 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1176 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1177 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1182 /* for pure Target Mode. Login will not be initiated */
1183 if (vha
->host
->active_mode
== MODE_TARGET
)
1186 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1187 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1191 fcport
->login_retry
--;
1193 switch (fcport
->disc_state
) {
1195 wwn
= wwn_to_u64(fcport
->node_name
);
1197 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1198 "%s %d %8phC post GNNID\n",
1199 __func__
, __LINE__
, fcport
->port_name
);
1200 qla24xx_post_gnnid_work(vha
, fcport
);
1201 } else if (fcport
->loop_id
== FC_NO_LOOP_ID
) {
1202 ql_dbg(ql_dbg_disc
, vha
, 0x20bd,
1203 "%s %d %8phC post gnl\n",
1204 __func__
, __LINE__
, fcport
->port_name
);
1205 qla24xx_post_gnl_work(vha
, fcport
);
1207 qla_chk_n2n_b4_login(vha
, fcport
);
1212 if (fcport
->login_pause
) {
1213 fcport
->last_rscn_gen
= fcport
->rscn_gen
;
1214 fcport
->last_login_gen
= fcport
->login_gen
;
1215 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1219 qla_chk_n2n_b4_login(vha
, fcport
);
1222 case DSC_LOGIN_FAILED
:
1223 ql_dbg(ql_dbg_disc
, vha
, 0x20d0,
1224 "%s %d %8phC post gidpn\n",
1225 __func__
, __LINE__
, fcport
->port_name
);
1226 if (N2N_TOPO(vha
->hw
))
1227 qla_chk_n2n_b4_login(vha
, fcport
);
1229 qla24xx_post_gidpn_work(vha
, fcport
);
1232 case DSC_LOGIN_COMPLETE
:
1233 /* recheck login state */
1234 ql_dbg(ql_dbg_disc
, vha
, 0x20d1,
1235 "%s %d %8phC post adisc\n",
1236 __func__
, __LINE__
, fcport
->port_name
);
1237 data
[0] = data
[1] = 0;
1238 qla2x00_post_async_adisc_work(vha
, fcport
, data
);
1249 void qla24xx_handle_rscn_event(fc_port_t
*fcport
, struct event_arg
*ea
)
1253 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210c,
1254 "%s %8phC DS %d LS %d\n",
1255 __func__
, fcport
->port_name
, fcport
->disc_state
,
1256 fcport
->fw_login_state
);
1258 if (fcport
->flags
& FCF_ASYNC_SENT
)
1261 switch (fcport
->disc_state
) {
1263 case DSC_LOGIN_COMPLETE
:
1264 qla24xx_post_gpnid_work(fcport
->vha
, &ea
->id
);
1271 int qla24xx_post_newsess_work(struct scsi_qla_host
*vha
, port_id_t
*id
,
1272 u8
*port_name
, u8
*node_name
, void *pla
, u8 fc4_type
)
1274 struct qla_work_evt
*e
;
1275 e
= qla2x00_alloc_work(vha
, QLA_EVT_NEW_SESS
);
1277 return QLA_FUNCTION_FAILED
;
1279 e
->u
.new_sess
.id
= *id
;
1280 e
->u
.new_sess
.pla
= pla
;
1281 e
->u
.new_sess
.fc4_type
= fc4_type
;
1282 memcpy(e
->u
.new_sess
.port_name
, port_name
, WWN_SIZE
);
1284 memcpy(e
->u
.new_sess
.node_name
, node_name
, WWN_SIZE
);
1286 return qla2x00_post_work(vha
, e
);
1290 void qla24xx_handle_relogin_event(scsi_qla_host_t
*vha
,
1291 struct event_arg
*ea
)
1293 fc_port_t
*fcport
= ea
->fcport
;
1295 ql_dbg(ql_dbg_disc
, vha
, 0x2102,
1296 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1297 __func__
, fcport
->port_name
, fcport
->disc_state
,
1298 fcport
->fw_login_state
, fcport
->login_pause
,
1299 fcport
->deleted
, fcport
->conflict
,
1300 fcport
->last_rscn_gen
, fcport
->rscn_gen
,
1301 fcport
->last_login_gen
, fcport
->login_gen
,
1304 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1305 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
))
1308 if (fcport
->fw_login_state
== DSC_LS_PLOGI_COMP
) {
1309 if (time_before_eq(jiffies
, fcport
->plogi_nack_done_deadline
)) {
1310 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1315 if (fcport
->flags
& FCF_ASYNC_SENT
) {
1316 fcport
->login_retry
++;
1317 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1321 if (fcport
->disc_state
== DSC_DELETE_PEND
) {
1322 fcport
->login_retry
++;
1326 if (fcport
->last_rscn_gen
!= fcport
->rscn_gen
) {
1327 ql_dbg(ql_dbg_disc
, vha
, 0x20e9, "%s %d %8phC post gidpn\n",
1328 __func__
, __LINE__
, fcport
->port_name
);
1330 qla24xx_post_gidpn_work(vha
, fcport
);
1334 qla24xx_fcport_handle_login(vha
, fcport
);
1337 void qla2x00_fcport_event_handler(scsi_qla_host_t
*vha
, struct event_arg
*ea
)
1340 uint32_t id
= 0, mask
, rid
;
1341 unsigned long flags
;
1343 switch (ea
->event
) {
1345 case FCME_GIDPN_DONE
:
1346 case FCME_GPSC_DONE
:
1347 case FCME_GPNID_DONE
:
1348 case FCME_GNNID_DONE
:
1349 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
) ||
1350 test_bit(LOOP_RESYNC_ACTIVE
, &vha
->dpc_flags
))
1357 switch (ea
->event
) {
1359 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1362 qla24xx_handle_relogin_event(vha
, ea
);
1365 if (test_bit(UNLOADING
, &vha
->dpc_flags
))
1367 switch (ea
->id
.b
.rsvd_1
) {
1368 case RSCN_PORT_ADDR
:
1369 spin_lock_irqsave(&vha
->work_lock
, flags
);
1370 if (vha
->scan
.scan_flags
== 0) {
1371 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1372 "%s: schedule\n", __func__
);
1373 vha
->scan
.scan_flags
|= SF_QUEUED
;
1374 schedule_delayed_work(&vha
->scan
.scan_work
, 5);
1376 spin_unlock_irqrestore(&vha
->work_lock
, flags
);
1379 case RSCN_AREA_ADDR
:
1381 if (ea
->id
.b
.rsvd_1
== RSCN_AREA_ADDR
) {
1383 ql_dbg(ql_dbg_async
, vha
, 0x5044,
1384 "RSCN: Area 0x%06x was affected\n",
1388 ql_dbg(ql_dbg_async
, vha
, 0x507a,
1389 "RSCN: Domain 0x%06x was affected\n",
1393 rid
= ea
->id
.b24
& mask
;
1394 list_for_each_entry_safe(f
, tf
, &vha
->vp_fcports
,
1396 id
= f
->d_id
.b24
& mask
;
1399 qla24xx_handle_rscn_event(f
, ea
);
1405 ql_log(ql_log_warn
, vha
, 0xd045,
1406 "RSCN: Fabric was affected. Addr format %d\n",
1408 qla2x00_mark_all_devices_lost(vha
, 1);
1409 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
1410 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
1413 case FCME_GIDPN_DONE
:
1414 qla24xx_handle_gidpn_event(vha
, ea
);
1417 qla24xx_handle_gnl_done_event(vha
, ea
);
1419 case FCME_GPSC_DONE
:
1420 qla24xx_handle_gpsc_event(vha
, ea
);
1422 case FCME_PLOGI_DONE
: /* Initiator side sent LLIOCB */
1423 qla24xx_handle_plogi_done_event(vha
, ea
);
1425 case FCME_PRLI_DONE
:
1426 qla24xx_handle_prli_done_event(vha
, ea
);
1428 case FCME_GPDB_DONE
:
1429 qla24xx_handle_gpdb_event(vha
, ea
);
1431 case FCME_GPNID_DONE
:
1432 qla24xx_handle_gpnid_event(vha
, ea
);
1434 case FCME_GFFID_DONE
:
1435 qla24xx_handle_gffid_event(vha
, ea
);
1437 case FCME_ADISC_DONE
:
1438 qla24xx_handle_adisc_event(vha
, ea
);
1440 case FCME_GNNID_DONE
:
1441 qla24xx_handle_gnnid_event(vha
, ea
);
1443 case FCME_GFPNID_DONE
:
1444 qla24xx_handle_gfpnid_event(vha
, ea
);
1453 qla2x00_tmf_iocb_timeout(void *data
)
1456 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1458 tmf
->u
.tmf
.comp_status
= CS_TIMEOUT
;
1459 complete(&tmf
->u
.tmf
.comp
);
1463 qla2x00_tmf_sp_done(void *ptr
, int res
)
1466 struct srb_iocb
*tmf
= &sp
->u
.iocb_cmd
;
1468 complete(&tmf
->u
.tmf
.comp
);
1472 qla2x00_async_tm_cmd(fc_port_t
*fcport
, uint32_t flags
, uint32_t lun
,
1475 struct scsi_qla_host
*vha
= fcport
->vha
;
1476 struct srb_iocb
*tm_iocb
;
1478 int rval
= QLA_FUNCTION_FAILED
;
1480 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1484 tm_iocb
= &sp
->u
.iocb_cmd
;
1485 sp
->type
= SRB_TM_CMD
;
1487 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1488 tm_iocb
->u
.tmf
.flags
= flags
;
1489 tm_iocb
->u
.tmf
.lun
= lun
;
1490 tm_iocb
->u
.tmf
.data
= tag
;
1491 sp
->done
= qla2x00_tmf_sp_done
;
1492 tm_iocb
->timeout
= qla2x00_tmf_iocb_timeout
;
1493 init_completion(&tm_iocb
->u
.tmf
.comp
);
1495 rval
= qla2x00_start_sp(sp
);
1496 if (rval
!= QLA_SUCCESS
)
1499 ql_dbg(ql_dbg_taskm
, vha
, 0x802f,
1500 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1501 sp
->handle
, fcport
->loop_id
, fcport
->d_id
.b
.domain
,
1502 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
1504 wait_for_completion(&tm_iocb
->u
.tmf
.comp
);
1506 rval
= tm_iocb
->u
.tmf
.comp_status
== CS_COMPLETE
?
1507 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1509 if ((rval
!= QLA_SUCCESS
) || tm_iocb
->u
.tmf
.data
) {
1510 ql_dbg(ql_dbg_taskm
, vha
, 0x8030,
1511 "TM IOCB failed (%x).\n", rval
);
1514 if (!test_bit(UNLOADING
, &vha
->dpc_flags
) && !IS_QLAFX00(vha
->hw
)) {
1515 flags
= tm_iocb
->u
.tmf
.flags
;
1516 lun
= (uint16_t)tm_iocb
->u
.tmf
.lun
;
1518 /* Issue Marker IOCB */
1519 qla2x00_marker(vha
, vha
->hw
->req_q_map
[0],
1520 vha
->hw
->rsp_q_map
[0], sp
->fcport
->loop_id
, lun
,
1521 flags
== TCF_LUN_RESET
? MK_SYNC_ID_LUN
: MK_SYNC_ID
);
1526 sp
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1532 qla24xx_abort_iocb_timeout(void *data
)
1535 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1537 abt
->u
.abt
.comp_status
= CS_TIMEOUT
;
1538 complete(&abt
->u
.abt
.comp
);
1542 qla24xx_abort_sp_done(void *ptr
, int res
)
1545 struct srb_iocb
*abt
= &sp
->u
.iocb_cmd
;
1547 complete(&abt
->u
.abt
.comp
);
1551 qla24xx_async_abort_cmd(srb_t
*cmd_sp
)
1553 scsi_qla_host_t
*vha
= cmd_sp
->vha
;
1554 fc_port_t
*fcport
= cmd_sp
->fcport
;
1555 struct srb_iocb
*abt_iocb
;
1557 int rval
= QLA_FUNCTION_FAILED
;
1559 sp
= qla2x00_get_sp(vha
, fcport
, GFP_KERNEL
);
1563 abt_iocb
= &sp
->u
.iocb_cmd
;
1564 sp
->type
= SRB_ABT_CMD
;
1566 qla2x00_init_timer(sp
, qla2x00_get_async_timeout(vha
));
1567 abt_iocb
->u
.abt
.cmd_hndl
= cmd_sp
->handle
;
1569 if (vha
->flags
.qpairs_available
&& cmd_sp
->qpair
)
1570 abt_iocb
->u
.abt
.req_que_no
=
1571 cpu_to_le16(cmd_sp
->qpair
->req
->id
);
1573 abt_iocb
->u
.abt
.req_que_no
= cpu_to_le16(vha
->req
->id
);
1575 sp
->done
= qla24xx_abort_sp_done
;
1576 abt_iocb
->timeout
= qla24xx_abort_iocb_timeout
;
1577 init_completion(&abt_iocb
->u
.abt
.comp
);
1579 rval
= qla2x00_start_sp(sp
);
1580 if (rval
!= QLA_SUCCESS
)
1583 ql_dbg(ql_dbg_async
, vha
, 0x507c,
1584 "Abort command issued - hdl=%x, target_id=%x\n",
1585 cmd_sp
->handle
, fcport
->tgt_id
);
1587 wait_for_completion(&abt_iocb
->u
.abt
.comp
);
1589 rval
= abt_iocb
->u
.abt
.comp_status
== CS_COMPLETE
?
1590 QLA_SUCCESS
: QLA_FUNCTION_FAILED
;
1599 qla24xx_async_abort_command(srb_t
*sp
)
1601 unsigned long flags
= 0;
1604 fc_port_t
*fcport
= sp
->fcport
;
1605 struct scsi_qla_host
*vha
= fcport
->vha
;
1606 struct qla_hw_data
*ha
= vha
->hw
;
1607 struct req_que
*req
= vha
->req
;
1609 if (vha
->flags
.qpairs_available
&& sp
->qpair
)
1610 req
= sp
->qpair
->req
;
1612 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
1613 for (handle
= 1; handle
< req
->num_outstanding_cmds
; handle
++) {
1614 if (req
->outstanding_cmds
[handle
] == sp
)
1617 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
1618 if (handle
== req
->num_outstanding_cmds
) {
1619 /* Command not found. */
1620 return QLA_FUNCTION_FAILED
;
1622 if (sp
->type
== SRB_FXIOCB_DCMD
)
1623 return qlafx00_fx_disc(vha
, &vha
->hw
->mr
.fcport
,
1624 FXDISC_ABORT_IOCTL
);
1626 return qla24xx_async_abort_cmd(sp
);
1630 qla24xx_handle_prli_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1632 switch (ea
->data
[0]) {
1633 case MBS_COMMAND_COMPLETE
:
1634 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1635 "%s %d %8phC post gpdb\n",
1636 __func__
, __LINE__
, ea
->fcport
->port_name
);
1638 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1639 ea
->fcport
->logout_on_delete
= 1;
1640 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1643 if (ea
->fcport
->n2n_flag
) {
1644 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
1645 "%s %d %8phC post fc4 prli\n",
1646 __func__
, __LINE__
, ea
->fcport
->port_name
);
1647 ea
->fcport
->fc4f_nvme
= 0;
1648 ea
->fcport
->n2n_flag
= 0;
1649 qla24xx_post_prli_work(vha
, ea
->fcport
);
1651 ql_dbg(ql_dbg_disc
, vha
, 0x2119,
1652 "%s %d %8phC unhandle event of %x\n",
1653 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[0]);
1659 qla24xx_handle_plogi_done_event(struct scsi_qla_host
*vha
, struct event_arg
*ea
)
1661 port_id_t cid
; /* conflict Nport id */
1663 struct fc_port
*conflict_fcport
;
1664 unsigned long flags
;
1665 struct fc_port
*fcport
= ea
->fcport
;
1667 ql_dbg(ql_dbg_disc
, vha
, 0xffff,
1668 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1669 __func__
, fcport
->port_name
, fcport
->disc_state
,
1670 fcport
->fw_login_state
, ea
->rc
, ea
->sp
->gen2
, fcport
->login_gen
,
1671 ea
->sp
->gen2
, fcport
->rscn_gen
|ea
->sp
->gen1
,
1672 ea
->data
[0], ea
->data
[1], ea
->iop
[0], ea
->iop
[1]);
1674 if ((fcport
->fw_login_state
== DSC_LS_PLOGI_PEND
) ||
1675 (fcport
->fw_login_state
== DSC_LS_PRLI_PEND
)) {
1676 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1677 "%s %d %8phC Remote is trying to login\n",
1678 __func__
, __LINE__
, fcport
->port_name
);
1682 if (fcport
->disc_state
== DSC_DELETE_PEND
)
1685 if (ea
->sp
->gen2
!= fcport
->login_gen
) {
1686 /* target side must have changed it. */
1687 ql_dbg(ql_dbg_disc
, vha
, 0x20d3,
1688 "%s %8phC generation changed\n",
1689 __func__
, fcport
->port_name
);
1690 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1692 } else if (ea
->sp
->gen1
!= fcport
->rscn_gen
) {
1693 ql_dbg(ql_dbg_disc
, vha
, 0x20d4, "%s %d %8phC post gidpn\n",
1694 __func__
, __LINE__
, fcport
->port_name
);
1695 qla24xx_post_gidpn_work(vha
, fcport
);
1699 switch (ea
->data
[0]) {
1700 case MBS_COMMAND_COMPLETE
:
1702 * Driver must validate login state - If PRLI not complete,
1703 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1706 if (ea
->fcport
->fc4f_nvme
) {
1707 ql_dbg(ql_dbg_disc
, vha
, 0x2117,
1708 "%s %d %8phC post prli\n",
1709 __func__
, __LINE__
, ea
->fcport
->port_name
);
1710 qla24xx_post_prli_work(vha
, ea
->fcport
);
1712 ql_dbg(ql_dbg_disc
, vha
, 0x20ea,
1713 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1714 __func__
, __LINE__
, ea
->fcport
->port_name
,
1715 ea
->fcport
->loop_id
, ea
->fcport
->d_id
.b24
);
1717 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1718 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
1719 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1720 ea
->fcport
->chip_reset
= vha
->hw
->base_qpair
->chip_reset
;
1721 ea
->fcport
->logout_on_delete
= 1;
1722 ea
->fcport
->send_els_logo
= 0;
1723 ea
->fcport
->fw_login_state
= DSC_LS_PRLI_COMP
;
1724 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
1726 qla24xx_post_gpdb_work(vha
, ea
->fcport
, 0);
1729 case MBS_COMMAND_ERROR
:
1730 ql_dbg(ql_dbg_disc
, vha
, 0x20eb, "%s %d %8phC cmd error %x\n",
1731 __func__
, __LINE__
, ea
->fcport
->port_name
, ea
->data
[1]);
1733 ea
->fcport
->flags
&= ~FCF_ASYNC_SENT
;
1734 ea
->fcport
->disc_state
= DSC_LOGIN_FAILED
;
1735 if (ea
->data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1736 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1738 qla2x00_mark_device_lost(vha
, ea
->fcport
, 1, 0);
1740 case MBS_LOOP_ID_USED
:
1741 /* data[1] = IO PARAM 1 = nport ID */
1742 cid
.b
.domain
= (ea
->iop
[1] >> 16) & 0xff;
1743 cid
.b
.area
= (ea
->iop
[1] >> 8) & 0xff;
1744 cid
.b
.al_pa
= ea
->iop
[1] & 0xff;
1747 ql_dbg(ql_dbg_disc
, vha
, 0x20ec,
1748 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1749 __func__
, __LINE__
, ea
->fcport
->port_name
,
1750 ea
->fcport
->loop_id
);
1752 if (IS_SW_RESV_ADDR(cid
)) {
1753 set_bit(ea
->fcport
->loop_id
, vha
->hw
->loop_id_map
);
1754 ea
->fcport
->loop_id
= FC_NO_LOOP_ID
;
1756 qla2x00_clear_loop_id(ea
->fcport
);
1758 qla24xx_post_gnl_work(vha
, ea
->fcport
);
1760 case MBS_PORT_ID_USED
:
1761 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1762 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1763 __func__
, __LINE__
, ea
->fcport
->port_name
,
1764 ea
->fcport
->d_id
.b
.domain
, ea
->fcport
->d_id
.b
.area
,
1765 ea
->fcport
->d_id
.b
.al_pa
);
1767 lid
= ea
->iop
[1] & 0xffff;
1768 qlt_find_sess_invalidate_other(vha
,
1769 wwn_to_u64(ea
->fcport
->port_name
),
1770 ea
->fcport
->d_id
, lid
, &conflict_fcport
);
1772 if (conflict_fcport
) {
1774 * Another fcport share the same loop_id/nport id.
1775 * Conflict fcport needs to finish cleanup before this
1776 * fcport can proceed to login.
1778 conflict_fcport
->conflict
= ea
->fcport
;
1779 ea
->fcport
->login_pause
= 1;
1781 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1782 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1783 __func__
, __LINE__
, ea
->fcport
->port_name
,
1784 ea
->fcport
->d_id
.b24
, lid
);
1785 qla2x00_clear_loop_id(ea
->fcport
);
1786 qla24xx_post_gidpn_work(vha
, ea
->fcport
);
1788 ql_dbg(ql_dbg_disc
, vha
, 0x20ed,
1789 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1790 __func__
, __LINE__
, ea
->fcport
->port_name
,
1791 ea
->fcport
->d_id
.b24
, lid
);
1793 qla2x00_clear_loop_id(ea
->fcport
);
1794 set_bit(lid
, vha
->hw
->loop_id_map
);
1795 ea
->fcport
->loop_id
= lid
;
1796 ea
->fcport
->keep_nport_handle
= 0;
1797 qlt_schedule_sess_for_deletion(ea
->fcport
);
1805 qla2x00_async_logout_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
1808 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
1809 qlt_logo_completion_handler(fcport
, data
[0]);
1810 fcport
->login_gen
++;
1815 qla2x00_async_adisc_done(struct scsi_qla_host
*vha
, fc_port_t
*fcport
,
1818 if (data
[0] == MBS_COMMAND_COMPLETE
) {
1819 qla2x00_update_fcport(vha
, fcport
);
1825 fcport
->flags
&= ~FCF_ASYNC_SENT
;
1826 if (data
[1] & QLA_LOGIO_LOGIN_RETRIED
)
1827 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
1829 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
1834 /****************************************************************************/
1835 /* QLogic ISP2x00 Hardware Support Functions. */
1836 /****************************************************************************/
1839 qla83xx_nic_core_fw_load(scsi_qla_host_t
*vha
)
1841 int rval
= QLA_SUCCESS
;
1842 struct qla_hw_data
*ha
= vha
->hw
;
1843 uint32_t idc_major_ver
, idc_minor_ver
;
1846 qla83xx_idc_lock(vha
, 0);
1848 /* SV: TODO: Assign initialization timeout from
1849 * flash-info / other param
1851 ha
->fcoe_dev_init_timeout
= QLA83XX_IDC_INITIALIZATION_TIMEOUT
;
1852 ha
->fcoe_reset_timeout
= QLA83XX_IDC_RESET_ACK_TIMEOUT
;
1854 /* Set our fcoe function presence */
1855 if (__qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
) {
1856 ql_dbg(ql_dbg_p3p
, vha
, 0xb077,
1857 "Error while setting DRV-Presence.\n");
1858 rval
= QLA_FUNCTION_FAILED
;
1862 /* Decide the reset ownership */
1863 qla83xx_reset_ownership(vha
);
1866 * On first protocol driver load:
1867 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1869 * Others: Check compatibility with current IDC Major version.
1871 qla83xx_rd_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, &idc_major_ver
);
1872 if (ha
->flags
.nic_core_reset_owner
) {
1873 /* Set IDC Major version */
1874 idc_major_ver
= QLA83XX_SUPP_IDC_MAJOR_VERSION
;
1875 qla83xx_wr_reg(vha
, QLA83XX_IDC_MAJOR_VERSION
, idc_major_ver
);
1877 /* Clearing IDC-Lock-Recovery register */
1878 qla83xx_wr_reg(vha
, QLA83XX_IDC_LOCK_RECOVERY
, 0);
1879 } else if (idc_major_ver
!= QLA83XX_SUPP_IDC_MAJOR_VERSION
) {
1881 * Clear further IDC participation if we are not compatible with
1882 * the current IDC Major Version.
1884 ql_log(ql_log_warn
, vha
, 0xb07d,
1885 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1886 idc_major_ver
, QLA83XX_SUPP_IDC_MAJOR_VERSION
);
1887 __qla83xx_clear_drv_presence(vha
);
1888 rval
= QLA_FUNCTION_FAILED
;
1891 /* Each function sets its supported Minor version. */
1892 qla83xx_rd_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, &idc_minor_ver
);
1893 idc_minor_ver
|= (QLA83XX_SUPP_IDC_MINOR_VERSION
<< (ha
->portnum
* 2));
1894 qla83xx_wr_reg(vha
, QLA83XX_IDC_MINOR_VERSION
, idc_minor_ver
);
1896 if (ha
->flags
.nic_core_reset_owner
) {
1897 memset(config
, 0, sizeof(config
));
1898 if (!qla81xx_get_port_config(vha
, config
))
1899 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
1903 rval
= qla83xx_idc_state_handler(vha
);
1906 qla83xx_idc_unlock(vha
, 0);
1912 * qla2x00_initialize_adapter
1916 * ha = adapter block pointer.
1922 qla2x00_initialize_adapter(scsi_qla_host_t
*vha
)
1925 struct qla_hw_data
*ha
= vha
->hw
;
1926 struct req_que
*req
= ha
->req_q_map
[0];
1928 memset(&vha
->qla_stats
, 0, sizeof(vha
->qla_stats
));
1929 memset(&vha
->fc_host_stat
, 0, sizeof(vha
->fc_host_stat
));
1931 /* Clear adapter flags. */
1932 vha
->flags
.online
= 0;
1933 ha
->flags
.chip_reset_done
= 0;
1934 vha
->flags
.reset_active
= 0;
1935 ha
->flags
.pci_channel_io_perm_failure
= 0;
1936 ha
->flags
.eeh_busy
= 0;
1937 vha
->qla_stats
.jiffies_at_last_reset
= get_jiffies_64();
1938 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
1939 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
1940 vha
->device_flags
= DFLG_NO_CABLE
;
1942 vha
->flags
.management_server_logged_in
= 0;
1943 vha
->marker_needed
= 0;
1944 ha
->isp_abort_cnt
= 0;
1945 ha
->beacon_blink_led
= 0;
1947 set_bit(0, ha
->req_qid_map
);
1948 set_bit(0, ha
->rsp_qid_map
);
1950 ql_dbg(ql_dbg_init
, vha
, 0x0040,
1951 "Configuring PCI space...\n");
1952 rval
= ha
->isp_ops
->pci_config(vha
);
1954 ql_log(ql_log_warn
, vha
, 0x0044,
1955 "Unable to configure PCI space.\n");
1959 ha
->isp_ops
->reset_chip(vha
);
1961 rval
= qla2xxx_get_flash_info(vha
);
1963 ql_log(ql_log_fatal
, vha
, 0x004f,
1964 "Unable to validate FLASH data.\n");
1968 if (IS_QLA8044(ha
)) {
1969 qla8044_read_reset_template(vha
);
1971 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1972 * If DONRESET_BIT0 is set, drivers should not set dev_state
1973 * to NEED_RESET. But if NEED_RESET is set, drivers should
1974 * should honor the reset. */
1975 if (ql2xdontresethba
== 1)
1976 qla8044_set_idc_dontreset(vha
);
1979 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
1980 ql_dbg(ql_dbg_init
, vha
, 0x0061,
1981 "Configure NVRAM parameters...\n");
1983 ha
->isp_ops
->nvram_config(vha
);
1985 if (ha
->flags
.disable_serdes
) {
1986 /* Mask HBA via NVRAM settings? */
1987 ql_log(ql_log_info
, vha
, 0x0077,
1988 "Masking HBA WWPN %8phN (via NVRAM).\n", vha
->port_name
);
1989 return QLA_FUNCTION_FAILED
;
1992 ql_dbg(ql_dbg_init
, vha
, 0x0078,
1993 "Verifying loaded RISC code...\n");
1995 if (qla2x00_isp_firmware(vha
) != QLA_SUCCESS
) {
1996 rval
= ha
->isp_ops
->chip_diag(vha
);
1999 rval
= qla2x00_setup_chip(vha
);
2004 if (IS_QLA84XX(ha
)) {
2005 ha
->cs84xx
= qla84xx_get_chip(vha
);
2007 ql_log(ql_log_warn
, vha
, 0x00d0,
2008 "Unable to configure ISP84XX.\n");
2009 return QLA_FUNCTION_FAILED
;
2013 if (qla_ini_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
2014 rval
= qla2x00_init_rings(vha
);
2016 ha
->flags
.chip_reset_done
= 1;
2018 if (rval
== QLA_SUCCESS
&& IS_QLA84XX(ha
)) {
2019 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2020 rval
= qla84xx_init_chip(vha
);
2021 if (rval
!= QLA_SUCCESS
) {
2022 ql_log(ql_log_warn
, vha
, 0x00d4,
2023 "Unable to initialize ISP84XX.\n");
2024 qla84xx_put_chip(vha
);
2028 /* Load the NIC Core f/w if we are the first protocol driver. */
2029 if (IS_QLA8031(ha
)) {
2030 rval
= qla83xx_nic_core_fw_load(vha
);
2032 ql_log(ql_log_warn
, vha
, 0x0124,
2033 "Error in initializing NIC Core f/w.\n");
2036 if (IS_QLA24XX_TYPE(ha
) || IS_QLA25XX(ha
))
2037 qla24xx_read_fcp_prio_cfg(vha
);
2039 if (IS_P3P_TYPE(ha
))
2040 qla82xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2042 qla25xx_set_driver_version(vha
, QLA2XXX_VERSION
);
2048 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2051 * Returns 0 on success.
2054 qla2100_pci_config(scsi_qla_host_t
*vha
)
2057 unsigned long flags
;
2058 struct qla_hw_data
*ha
= vha
->hw
;
2059 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2061 pci_set_master(ha
->pdev
);
2062 pci_try_set_mwi(ha
->pdev
);
2064 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2065 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2066 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2068 pci_disable_rom(ha
->pdev
);
2070 /* Get PCI bus information. */
2071 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2072 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2073 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2079 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2082 * Returns 0 on success.
2085 qla2300_pci_config(scsi_qla_host_t
*vha
)
2088 unsigned long flags
= 0;
2090 struct qla_hw_data
*ha
= vha
->hw
;
2091 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2093 pci_set_master(ha
->pdev
);
2094 pci_try_set_mwi(ha
->pdev
);
2096 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2097 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2099 if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
2100 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2101 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2104 * If this is a 2300 card and not 2312, reset the
2105 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2106 * the 2310 also reports itself as a 2300 so we need to get the
2107 * fb revision level -- a 6 indicates it really is a 2300 and
2110 if (IS_QLA2300(ha
)) {
2111 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2114 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2115 for (cnt
= 0; cnt
< 30000; cnt
++) {
2116 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) != 0)
2122 /* Select FPM registers. */
2123 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2124 RD_REG_WORD(®
->ctrl_status
);
2126 /* Get the fb rev level */
2127 ha
->fb_rev
= RD_FB_CMD_REG(ha
, reg
);
2129 if (ha
->fb_rev
== FPM_2300
)
2130 pci_clear_mwi(ha
->pdev
);
2132 /* Deselect FPM registers. */
2133 WRT_REG_WORD(®
->ctrl_status
, 0x0);
2134 RD_REG_WORD(®
->ctrl_status
);
2136 /* Release RISC module. */
2137 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2138 for (cnt
= 0; cnt
< 30000; cnt
++) {
2139 if ((RD_REG_WORD(®
->hccr
) & HCCR_RISC_PAUSE
) == 0)
2145 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2148 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2150 pci_disable_rom(ha
->pdev
);
2152 /* Get PCI bus information. */
2153 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2154 ha
->pci_attr
= RD_REG_WORD(®
->ctrl_status
);
2155 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2161 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2164 * Returns 0 on success.
2167 qla24xx_pci_config(scsi_qla_host_t
*vha
)
2170 unsigned long flags
= 0;
2171 struct qla_hw_data
*ha
= vha
->hw
;
2172 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2174 pci_set_master(ha
->pdev
);
2175 pci_try_set_mwi(ha
->pdev
);
2177 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2178 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2179 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2180 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2182 pci_write_config_byte(ha
->pdev
, PCI_LATENCY_TIMER
, 0x80);
2184 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2185 if (pci_find_capability(ha
->pdev
, PCI_CAP_ID_PCIX
))
2186 pcix_set_mmrbc(ha
->pdev
, 2048);
2188 /* PCIe -- adjust Maximum Read Request Size (2048). */
2189 if (pci_is_pcie(ha
->pdev
))
2190 pcie_set_readrq(ha
->pdev
, 4096);
2192 pci_disable_rom(ha
->pdev
);
2194 ha
->chip_revision
= ha
->pdev
->revision
;
2196 /* Get PCI bus information. */
2197 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2198 ha
->pci_attr
= RD_REG_DWORD(®
->ctrl_status
);
2199 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2205 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2208 * Returns 0 on success.
2211 qla25xx_pci_config(scsi_qla_host_t
*vha
)
2214 struct qla_hw_data
*ha
= vha
->hw
;
2216 pci_set_master(ha
->pdev
);
2217 pci_try_set_mwi(ha
->pdev
);
2219 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &w
);
2220 w
|= (PCI_COMMAND_PARITY
| PCI_COMMAND_SERR
);
2221 w
&= ~PCI_COMMAND_INTX_DISABLE
;
2222 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, w
);
2224 /* PCIe -- adjust Maximum Read Request Size (2048). */
2225 if (pci_is_pcie(ha
->pdev
))
2226 pcie_set_readrq(ha
->pdev
, 4096);
2228 pci_disable_rom(ha
->pdev
);
2230 ha
->chip_revision
= ha
->pdev
->revision
;
2236 * qla2x00_isp_firmware() - Choose firmware image.
2239 * Returns 0 on success.
2242 qla2x00_isp_firmware(scsi_qla_host_t
*vha
)
2245 uint16_t loop_id
, topo
, sw_cap
;
2246 uint8_t domain
, area
, al_pa
;
2247 struct qla_hw_data
*ha
= vha
->hw
;
2249 /* Assume loading risc code */
2250 rval
= QLA_FUNCTION_FAILED
;
2252 if (ha
->flags
.disable_risc_code_load
) {
2253 ql_log(ql_log_info
, vha
, 0x0079, "RISC CODE NOT loaded.\n");
2255 /* Verify checksum of loaded RISC code. */
2256 rval
= qla2x00_verify_checksum(vha
, ha
->fw_srisc_address
);
2257 if (rval
== QLA_SUCCESS
) {
2258 /* And, verify we are not in ROM code. */
2259 rval
= qla2x00_get_adapter_id(vha
, &loop_id
, &al_pa
,
2260 &area
, &domain
, &topo
, &sw_cap
);
2265 ql_dbg(ql_dbg_init
, vha
, 0x007a,
2266 "**** Load RISC code ****.\n");
2272 * qla2x00_reset_chip() - Reset ISP chip.
2275 * Returns 0 on success.
2278 qla2x00_reset_chip(scsi_qla_host_t
*vha
)
2280 unsigned long flags
= 0;
2281 struct qla_hw_data
*ha
= vha
->hw
;
2282 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2286 if (unlikely(pci_channel_offline(ha
->pdev
)))
2289 ha
->isp_ops
->disable_intrs(ha
);
2291 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2293 /* Turn off master enable */
2295 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &cmd
);
2296 cmd
&= ~PCI_COMMAND_MASTER
;
2297 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2299 if (!IS_QLA2100(ha
)) {
2301 WRT_REG_WORD(®
->hccr
, HCCR_PAUSE_RISC
);
2302 if (IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2303 for (cnt
= 0; cnt
< 30000; cnt
++) {
2304 if ((RD_REG_WORD(®
->hccr
) &
2305 HCCR_RISC_PAUSE
) != 0)
2310 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2314 /* Select FPM registers. */
2315 WRT_REG_WORD(®
->ctrl_status
, 0x20);
2316 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2318 /* FPM Soft Reset. */
2319 WRT_REG_WORD(®
->fpm_diag_config
, 0x100);
2320 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2322 /* Toggle Fpm Reset. */
2323 if (!IS_QLA2200(ha
)) {
2324 WRT_REG_WORD(®
->fpm_diag_config
, 0x0);
2325 RD_REG_WORD(®
->fpm_diag_config
); /* PCI Posting. */
2328 /* Select frame buffer registers. */
2329 WRT_REG_WORD(®
->ctrl_status
, 0x10);
2330 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2332 /* Reset frame buffer FIFOs. */
2333 if (IS_QLA2200(ha
)) {
2334 WRT_FB_CMD_REG(ha
, reg
, 0xa000);
2335 RD_FB_CMD_REG(ha
, reg
); /* PCI Posting. */
2337 WRT_FB_CMD_REG(ha
, reg
, 0x00fc);
2339 /* Read back fb_cmd until zero or 3 seconds max */
2340 for (cnt
= 0; cnt
< 3000; cnt
++) {
2341 if ((RD_FB_CMD_REG(ha
, reg
) & 0xff) == 0)
2347 /* Select RISC module registers. */
2348 WRT_REG_WORD(®
->ctrl_status
, 0);
2349 RD_REG_WORD(®
->ctrl_status
); /* PCI Posting. */
2351 /* Reset RISC processor. */
2352 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2353 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2355 /* Release RISC processor. */
2356 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2357 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2360 WRT_REG_WORD(®
->hccr
, HCCR_CLR_RISC_INT
);
2361 WRT_REG_WORD(®
->hccr
, HCCR_CLR_HOST_INT
);
2363 /* Reset ISP chip. */
2364 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2366 /* Wait for RISC to recover from reset. */
2367 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2369 * It is necessary to for a delay here since the card doesn't
2370 * respond to PCI reads during a reset. On some architectures
2371 * this will result in an MCA.
2374 for (cnt
= 30000; cnt
; cnt
--) {
2375 if ((RD_REG_WORD(®
->ctrl_status
) &
2376 CSR_ISP_SOFT_RESET
) == 0)
2383 /* Reset RISC processor. */
2384 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2386 WRT_REG_WORD(®
->semaphore
, 0);
2388 /* Release RISC processor. */
2389 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2390 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2392 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2393 for (cnt
= 0; cnt
< 30000; cnt
++) {
2394 if (RD_MAILBOX_REG(ha
, reg
, 0) != MBS_BUSY
)
2402 /* Turn on master enable */
2403 cmd
|= PCI_COMMAND_MASTER
;
2404 pci_write_config_word(ha
->pdev
, PCI_COMMAND
, cmd
);
2406 /* Disable RISC pause on FPM parity error. */
2407 if (!IS_QLA2100(ha
)) {
2408 WRT_REG_WORD(®
->hccr
, HCCR_DISABLE_PARITY_PAUSE
);
2409 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
2412 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2416 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2418 * Returns 0 on success.
2421 qla81xx_reset_mpi(scsi_qla_host_t
*vha
)
2423 uint16_t mb
[4] = {0x1010, 0, 1, 0};
2425 if (!IS_QLA81XX(vha
->hw
))
2428 return qla81xx_write_mpi_register(vha
, mb
);
2432 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2435 * Returns 0 on success.
2438 qla24xx_reset_risc(scsi_qla_host_t
*vha
)
2440 unsigned long flags
= 0;
2441 struct qla_hw_data
*ha
= vha
->hw
;
2442 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
2445 static int abts_cnt
; /* ISP abort retry counts */
2446 int rval
= QLA_SUCCESS
;
2448 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2451 WRT_REG_DWORD(®
->ctrl_status
, CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2452 for (cnt
= 0; cnt
< 30000; cnt
++) {
2453 if ((RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
) == 0)
2459 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
))
2460 set_bit(DMA_SHUTDOWN_CMPL
, &ha
->fw_dump_cap_flags
);
2462 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017e,
2463 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2464 RD_REG_DWORD(®
->hccr
),
2465 RD_REG_DWORD(®
->ctrl_status
),
2466 (RD_REG_DWORD(®
->ctrl_status
) & CSRX_DMA_ACTIVE
));
2468 WRT_REG_DWORD(®
->ctrl_status
,
2469 CSRX_ISP_SOFT_RESET
|CSRX_DMA_SHUTDOWN
|MWB_4096_BYTES
);
2470 pci_read_config_word(ha
->pdev
, PCI_COMMAND
, &wd
);
2474 /* Wait for firmware to complete NVRAM accesses. */
2475 RD_REG_WORD(®
->mailbox0
);
2476 for (cnt
= 10000; RD_REG_WORD(®
->mailbox0
) != 0 &&
2477 rval
== QLA_SUCCESS
; cnt
--) {
2482 rval
= QLA_FUNCTION_TIMEOUT
;
2485 if (rval
== QLA_SUCCESS
)
2486 set_bit(ISP_MBX_RDY
, &ha
->fw_dump_cap_flags
);
2488 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x017f,
2489 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2490 RD_REG_DWORD(®
->hccr
),
2491 RD_REG_DWORD(®
->mailbox0
));
2493 /* Wait for soft-reset to complete. */
2494 RD_REG_DWORD(®
->ctrl_status
);
2495 for (cnt
= 0; cnt
< 60; cnt
++) {
2497 if ((RD_REG_DWORD(®
->ctrl_status
) &
2498 CSRX_ISP_SOFT_RESET
) == 0)
2503 if (!(RD_REG_DWORD(®
->ctrl_status
) & CSRX_ISP_SOFT_RESET
))
2504 set_bit(ISP_SOFT_RESET_CMPL
, &ha
->fw_dump_cap_flags
);
2506 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015d,
2507 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2508 RD_REG_DWORD(®
->hccr
),
2509 RD_REG_DWORD(®
->ctrl_status
));
2511 /* If required, do an MPI FW reset now */
2512 if (test_and_clear_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
)) {
2513 if (qla81xx_reset_mpi(vha
) != QLA_SUCCESS
) {
2514 if (++abts_cnt
< 5) {
2515 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
2516 set_bit(MPI_RESET_NEEDED
, &vha
->dpc_flags
);
2519 * We exhausted the ISP abort retries. We have to
2520 * set the board offline.
2523 vha
->flags
.online
= 0;
2528 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
2529 RD_REG_DWORD(®
->hccr
);
2531 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
2532 RD_REG_DWORD(®
->hccr
);
2534 WRT_REG_DWORD(®
->hccr
, HCCRX_CLR_RISC_RESET
);
2535 RD_REG_DWORD(®
->hccr
);
2537 RD_REG_WORD(®
->mailbox0
);
2538 for (cnt
= 60; RD_REG_WORD(®
->mailbox0
) != 0 &&
2539 rval
== QLA_SUCCESS
; cnt
--) {
2544 rval
= QLA_FUNCTION_TIMEOUT
;
2546 if (rval
== QLA_SUCCESS
)
2547 set_bit(RISC_RDY_AFT_RESET
, &ha
->fw_dump_cap_flags
);
2549 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015e,
2550 "Host Risc 0x%x, mailbox0 0x%x\n",
2551 RD_REG_DWORD(®
->hccr
),
2552 RD_REG_WORD(®
->mailbox0
));
2554 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2556 ql_dbg(ql_dbg_init
+ ql_dbg_verbose
, vha
, 0x015f,
2557 "Driver in %s mode\n",
2558 IS_NOPOLLING_TYPE(ha
) ? "Interrupt" : "Polling");
2560 if (IS_NOPOLLING_TYPE(ha
))
2561 ha
->isp_ops
->enable_intrs(ha
);
2567 qla25xx_read_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t *data
)
2569 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2571 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2572 *data
= RD_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
);
2577 qla25xx_write_risc_sema_reg(scsi_qla_host_t
*vha
, uint32_t data
)
2579 struct device_reg_24xx __iomem
*reg
= &vha
->hw
->iobase
->isp24
;
2581 WRT_REG_DWORD(®
->iobase_addr
, RISC_REGISTER_BASE_OFFSET
);
2582 WRT_REG_DWORD(®
->iobase_window
+ RISC_REGISTER_WINDOW_OFFET
, data
);
2586 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t
*vha
)
2589 uint delta_msec
= 100;
2590 uint elapsed_msec
= 0;
2594 if (vha
->hw
->pdev
->subsystem_device
!= 0x0175 &&
2595 vha
->hw
->pdev
->subsystem_device
!= 0x0240)
2598 WRT_REG_DWORD(&vha
->hw
->iobase
->isp24
.hccr
, HCCRX_SET_RISC_PAUSE
);
2602 timeout_msec
= TIMEOUT_SEMAPHORE
;
2603 n
= timeout_msec
/ delta_msec
;
2605 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_SET
);
2606 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2607 if (wd32
& RISC_SEMAPHORE
)
2610 elapsed_msec
+= delta_msec
;
2611 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2615 if (!(wd32
& RISC_SEMAPHORE
))
2618 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2621 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_CLR
);
2622 timeout_msec
= TIMEOUT_SEMAPHORE_FORCE
;
2623 n
= timeout_msec
/ delta_msec
;
2625 qla25xx_read_risc_sema_reg(vha
, &wd32
);
2626 if (!(wd32
& RISC_SEMAPHORE_FORCE
))
2629 elapsed_msec
+= delta_msec
;
2630 if (elapsed_msec
> TIMEOUT_TOTAL_ELAPSED
)
2634 if (wd32
& RISC_SEMAPHORE_FORCE
)
2635 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_CLR
);
2640 qla25xx_write_risc_sema_reg(vha
, RISC_SEMAPHORE_FORCE_SET
);
2647 * qla24xx_reset_chip() - Reset ISP24xx chip.
2650 * Returns 0 on success.
2653 qla24xx_reset_chip(scsi_qla_host_t
*vha
)
2655 struct qla_hw_data
*ha
= vha
->hw
;
2657 if (pci_channel_offline(ha
->pdev
) &&
2658 ha
->flags
.pci_channel_io_perm_failure
) {
2662 ha
->isp_ops
->disable_intrs(ha
);
2664 qla25xx_manipulate_risc_semaphore(vha
);
2666 /* Perform RISC reset. */
2667 qla24xx_reset_risc(vha
);
2671 * qla2x00_chip_diag() - Test chip for proper operation.
2674 * Returns 0 on success.
2677 qla2x00_chip_diag(scsi_qla_host_t
*vha
)
2680 struct qla_hw_data
*ha
= vha
->hw
;
2681 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
2682 unsigned long flags
= 0;
2686 struct req_que
*req
= ha
->req_q_map
[0];
2688 /* Assume a failed state */
2689 rval
= QLA_FUNCTION_FAILED
;
2691 ql_dbg(ql_dbg_init
, vha
, 0x007b,
2692 "Testing device at %lx.\n", (u_long
)®
->flash_address
);
2694 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2696 /* Reset ISP chip. */
2697 WRT_REG_WORD(®
->ctrl_status
, CSR_ISP_SOFT_RESET
);
2700 * We need to have a delay here since the card will not respond while
2701 * in reset causing an MCA on some architectures.
2704 data
= qla2x00_debounce_register(®
->ctrl_status
);
2705 for (cnt
= 6000000 ; cnt
&& (data
& CSR_ISP_SOFT_RESET
); cnt
--) {
2707 data
= RD_REG_WORD(®
->ctrl_status
);
2712 goto chip_diag_failed
;
2714 ql_dbg(ql_dbg_init
, vha
, 0x007c,
2715 "Reset register cleared by chip reset.\n");
2717 /* Reset RISC processor. */
2718 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
2719 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
2721 /* Workaround for QLA2312 PCI parity error */
2722 if (IS_QLA2100(ha
) || IS_QLA2200(ha
) || IS_QLA2300(ha
)) {
2723 data
= qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 0));
2724 for (cnt
= 6000000; cnt
&& (data
== MBS_BUSY
); cnt
--) {
2726 data
= RD_MAILBOX_REG(ha
, reg
, 0);
2733 goto chip_diag_failed
;
2735 /* Check product ID of chip */
2736 ql_dbg(ql_dbg_init
, vha
, 0x007d, "Checking product ID of chip.\n");
2738 mb
[1] = RD_MAILBOX_REG(ha
, reg
, 1);
2739 mb
[2] = RD_MAILBOX_REG(ha
, reg
, 2);
2740 mb
[3] = RD_MAILBOX_REG(ha
, reg
, 3);
2741 mb
[4] = qla2x00_debounce_register(MAILBOX_REG(ha
, reg
, 4));
2742 if (mb
[1] != PROD_ID_1
|| (mb
[2] != PROD_ID_2
&& mb
[2] != PROD_ID_2a
) ||
2743 mb
[3] != PROD_ID_3
) {
2744 ql_log(ql_log_warn
, vha
, 0x0062,
2745 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2746 mb
[1], mb
[2], mb
[3]);
2748 goto chip_diag_failed
;
2750 ha
->product_id
[0] = mb
[1];
2751 ha
->product_id
[1] = mb
[2];
2752 ha
->product_id
[2] = mb
[3];
2753 ha
->product_id
[3] = mb
[4];
2755 /* Adjust fw RISC transfer size */
2756 if (req
->length
> 1024)
2757 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* 1024;
2759 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
*
2762 if (IS_QLA2200(ha
) &&
2763 RD_MAILBOX_REG(ha
, reg
, 7) == QLA2200A_RISC_ROM_VER
) {
2764 /* Limit firmware transfer size with a 2200A */
2765 ql_dbg(ql_dbg_init
, vha
, 0x007e, "Found QLA2200A Chip.\n");
2767 ha
->device_type
|= DT_ISP2200A
;
2768 ha
->fw_transfer_size
= 128;
2771 /* Wrap Incoming Mailboxes Test. */
2772 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2774 ql_dbg(ql_dbg_init
, vha
, 0x007f, "Checking mailboxes.\n");
2775 rval
= qla2x00_mbx_reg_test(vha
);
2777 ql_log(ql_log_warn
, vha
, 0x0080,
2778 "Failed mailbox send register test.\n");
2780 /* Flag a successful rval */
2782 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
2786 ql_log(ql_log_info
, vha
, 0x0081,
2787 "Chip diagnostics **** FAILED ****.\n");
2789 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
2795 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2798 * Returns 0 on success.
2801 qla24xx_chip_diag(scsi_qla_host_t
*vha
)
2804 struct qla_hw_data
*ha
= vha
->hw
;
2805 struct req_que
*req
= ha
->req_q_map
[0];
2807 if (IS_P3P_TYPE(ha
))
2810 ha
->fw_transfer_size
= REQUEST_ENTRY_SIZE
* req
->length
;
2812 rval
= qla2x00_mbx_reg_test(vha
);
2814 ql_log(ql_log_warn
, vha
, 0x0082,
2815 "Failed mailbox send register test.\n");
2817 /* Flag a successful rval */
2825 qla2x00_alloc_offload_mem(scsi_qla_host_t
*vha
)
2830 struct qla_hw_data
*ha
= vha
->hw
;
2833 ql_dbg(ql_dbg_init
, vha
, 0x00bd,
2834 "%s: Offload Mem is already allocated.\n",
2839 if (IS_FWI2_CAPABLE(ha
)) {
2840 /* Allocate memory for Fibre Channel Event Buffer. */
2841 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2846 dma_free_coherent(&ha
->pdev
->dev
,
2847 FCE_SIZE
, ha
->fce
, ha
->fce_dma
);
2849 /* Allocate memory for Fibre Channel Event Buffer. */
2850 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, FCE_SIZE
, &tc_dma
,
2853 ql_log(ql_log_warn
, vha
, 0x00be,
2854 "Unable to allocate (%d KB) for FCE.\n",
2859 rval
= qla2x00_enable_fce_trace(vha
, tc_dma
, FCE_NUM_BUFFERS
,
2860 ha
->fce_mb
, &ha
->fce_bufs
);
2862 ql_log(ql_log_warn
, vha
, 0x00bf,
2863 "Unable to initialize FCE (%d).\n", rval
);
2864 dma_free_coherent(&ha
->pdev
->dev
, FCE_SIZE
, tc
,
2866 ha
->flags
.fce_enabled
= 0;
2869 ql_dbg(ql_dbg_init
, vha
, 0x00c0,
2870 "Allocate (%d KB) for FCE...\n", FCE_SIZE
/ 1024);
2872 ha
->flags
.fce_enabled
= 1;
2873 ha
->fce_dma
= tc_dma
;
2878 dma_free_coherent(&ha
->pdev
->dev
,
2879 EFT_SIZE
, ha
->eft
, ha
->eft_dma
);
2881 /* Allocate memory for Extended Trace Buffer. */
2882 tc
= dma_zalloc_coherent(&ha
->pdev
->dev
, EFT_SIZE
, &tc_dma
,
2885 ql_log(ql_log_warn
, vha
, 0x00c1,
2886 "Unable to allocate (%d KB) for EFT.\n",
2891 rval
= qla2x00_enable_eft_trace(vha
, tc_dma
, EFT_NUM_BUFFERS
);
2893 ql_log(ql_log_warn
, vha
, 0x00c2,
2894 "Unable to initialize EFT (%d).\n", rval
);
2895 dma_free_coherent(&ha
->pdev
->dev
, EFT_SIZE
, tc
,
2899 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
2900 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
2902 ha
->eft_dma
= tc_dma
;
2911 qla2x00_alloc_fw_dump(scsi_qla_host_t
*vha
)
2913 uint32_t dump_size
, fixed_size
, mem_size
, req_q_size
, rsp_q_size
,
2914 eft_size
, fce_size
, mq_size
;
2915 struct qla_hw_data
*ha
= vha
->hw
;
2916 struct req_que
*req
= ha
->req_q_map
[0];
2917 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
2918 struct qla2xxx_fw_dump
*fw_dump
;
2920 dump_size
= fixed_size
= mem_size
= eft_size
= fce_size
= mq_size
= 0;
2921 req_q_size
= rsp_q_size
= 0;
2923 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
2924 fixed_size
= sizeof(struct qla2100_fw_dump
);
2925 } else if (IS_QLA23XX(ha
)) {
2926 fixed_size
= offsetof(struct qla2300_fw_dump
, data_ram
);
2927 mem_size
= (ha
->fw_memory_size
- 0x11000 + 1) *
2929 } else if (IS_FWI2_CAPABLE(ha
)) {
2930 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))
2931 fixed_size
= offsetof(struct qla83xx_fw_dump
, ext_mem
);
2932 else if (IS_QLA81XX(ha
))
2933 fixed_size
= offsetof(struct qla81xx_fw_dump
, ext_mem
);
2934 else if (IS_QLA25XX(ha
))
2935 fixed_size
= offsetof(struct qla25xx_fw_dump
, ext_mem
);
2937 fixed_size
= offsetof(struct qla24xx_fw_dump
, ext_mem
);
2939 mem_size
= (ha
->fw_memory_size
- 0x100000 + 1) *
2942 if (!IS_QLA83XX(ha
) && !IS_QLA27XX(ha
))
2943 mq_size
= sizeof(struct qla2xxx_mq_chain
);
2945 * Allocate maximum buffer size for all queues.
2946 * Resizing must be done at end-of-dump processing.
2948 mq_size
+= ha
->max_req_queues
*
2949 (req
->length
* sizeof(request_t
));
2950 mq_size
+= ha
->max_rsp_queues
*
2951 (rsp
->length
* sizeof(response_t
));
2953 if (ha
->tgt
.atio_ring
)
2954 mq_size
+= ha
->tgt
.atio_q_length
* sizeof(request_t
);
2955 /* Allocate memory for Fibre Channel Event Buffer. */
2956 if (!IS_QLA25XX(ha
) && !IS_QLA81XX(ha
) && !IS_QLA83XX(ha
) &&
2960 fce_size
= sizeof(struct qla2xxx_fce_chain
) + FCE_SIZE
;
2962 ql_dbg(ql_dbg_init
, vha
, 0x00c3,
2963 "Allocated (%d KB) EFT ...\n", EFT_SIZE
/ 1024);
2964 eft_size
= EFT_SIZE
;
2967 if (IS_QLA27XX(ha
)) {
2968 if (!ha
->fw_dump_template
) {
2969 ql_log(ql_log_warn
, vha
, 0x00ba,
2970 "Failed missing fwdump template\n");
2973 dump_size
= qla27xx_fwdt_calculate_dump_size(vha
);
2974 ql_dbg(ql_dbg_init
, vha
, 0x00fa,
2975 "-> allocating fwdump (%x bytes)...\n", dump_size
);
2979 req_q_size
= req
->length
* sizeof(request_t
);
2980 rsp_q_size
= rsp
->length
* sizeof(response_t
);
2981 dump_size
= offsetof(struct qla2xxx_fw_dump
, isp
);
2982 dump_size
+= fixed_size
+ mem_size
+ req_q_size
+ rsp_q_size
+ eft_size
;
2983 ha
->chain_offset
= dump_size
;
2984 dump_size
+= mq_size
+ fce_size
;
2986 if (ha
->exchoffld_buf
)
2987 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
2989 if (ha
->exlogin_buf
)
2990 dump_size
+= sizeof(struct qla2xxx_offld_chain
) +
2994 if (!ha
->fw_dump_len
|| dump_size
!= ha
->fw_dump_len
) {
2995 fw_dump
= vmalloc(dump_size
);
2997 ql_log(ql_log_warn
, vha
, 0x00c4,
2998 "Unable to allocate (%d KB) for firmware dump.\n",
3003 ha
->fw_dump
= fw_dump
;
3005 ha
->fw_dump_len
= dump_size
;
3006 ql_dbg(ql_dbg_init
, vha
, 0x00c5,
3007 "Allocated (%d KB) for firmware dump.\n",
3013 ha
->fw_dump
->signature
[0] = 'Q';
3014 ha
->fw_dump
->signature
[1] = 'L';
3015 ha
->fw_dump
->signature
[2] = 'G';
3016 ha
->fw_dump
->signature
[3] = 'C';
3017 ha
->fw_dump
->version
= htonl(1);
3019 ha
->fw_dump
->fixed_size
= htonl(fixed_size
);
3020 ha
->fw_dump
->mem_size
= htonl(mem_size
);
3021 ha
->fw_dump
->req_q_size
= htonl(req_q_size
);
3022 ha
->fw_dump
->rsp_q_size
= htonl(rsp_q_size
);
3024 ha
->fw_dump
->eft_size
= htonl(eft_size
);
3025 ha
->fw_dump
->eft_addr_l
= htonl(LSD(ha
->eft_dma
));
3026 ha
->fw_dump
->eft_addr_h
= htonl(MSD(ha
->eft_dma
));
3028 ha
->fw_dump
->header_size
=
3029 htonl(offsetof(struct qla2xxx_fw_dump
, isp
));
3035 qla81xx_mpi_sync(scsi_qla_host_t
*vha
)
3037 #define MPS_MASK 0xe0
3042 if (!IS_QLA81XX(vha
->hw
))
3045 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 1);
3046 if (rval
!= QLA_SUCCESS
) {
3047 ql_log(ql_log_warn
, vha
, 0x0105,
3048 "Unable to acquire semaphore.\n");
3052 pci_read_config_word(vha
->hw
->pdev
, 0x54, &dc
);
3053 rval
= qla2x00_read_ram_word(vha
, 0x7a15, &dw
);
3054 if (rval
!= QLA_SUCCESS
) {
3055 ql_log(ql_log_warn
, vha
, 0x0067, "Unable to read sync.\n");
3060 if (dc
== (dw
& MPS_MASK
))
3065 rval
= qla2x00_write_ram_word(vha
, 0x7a15, dw
);
3066 if (rval
!= QLA_SUCCESS
) {
3067 ql_log(ql_log_warn
, vha
, 0x0114, "Unable to gain sync.\n");
3071 rval
= qla2x00_write_ram_word(vha
, 0x7c00, 0);
3072 if (rval
!= QLA_SUCCESS
) {
3073 ql_log(ql_log_warn
, vha
, 0x006d,
3074 "Unable to release semaphore.\n");
3082 qla2x00_alloc_outstanding_cmds(struct qla_hw_data
*ha
, struct req_que
*req
)
3084 /* Don't try to reallocate the array */
3085 if (req
->outstanding_cmds
)
3088 if (!IS_FWI2_CAPABLE(ha
))
3089 req
->num_outstanding_cmds
= DEFAULT_OUTSTANDING_COMMANDS
;
3091 if (ha
->cur_fw_xcb_count
<= ha
->cur_fw_iocb_count
)
3092 req
->num_outstanding_cmds
= ha
->cur_fw_xcb_count
;
3094 req
->num_outstanding_cmds
= ha
->cur_fw_iocb_count
;
3097 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
3098 req
->num_outstanding_cmds
, GFP_KERNEL
);
3100 if (!req
->outstanding_cmds
) {
3102 * Try to allocate a minimal size just so we can get through
3105 req
->num_outstanding_cmds
= MIN_OUTSTANDING_COMMANDS
;
3106 req
->outstanding_cmds
= kzalloc(sizeof(srb_t
*) *
3107 req
->num_outstanding_cmds
, GFP_KERNEL
);
3109 if (!req
->outstanding_cmds
) {
3110 ql_log(ql_log_fatal
, NULL
, 0x0126,
3111 "Failed to allocate memory for "
3112 "outstanding_cmds for req_que %p.\n", req
);
3113 req
->num_outstanding_cmds
= 0;
3114 return QLA_FUNCTION_FAILED
;
3121 #define PRINT_FIELD(_field, _flag, _str) { \
3122 if (a0->_field & _flag) {\
3128 len = snprintf(ptr, leftover, "%s", _str); \
3135 static void qla2xxx_print_sfp_info(struct scsi_qla_host
*vha
)
3138 struct sff_8247_a0
*a0
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3139 u8 str
[STR_LEN
], *ptr
, p
;
3142 memset(str
, 0, STR_LEN
);
3143 snprintf(str
, SFF_VEN_NAME_LEN
+1, a0
->vendor_name
);
3144 ql_dbg(ql_dbg_init
, vha
, 0x015a,
3145 "SFP MFG Name: %s\n", str
);
3147 memset(str
, 0, STR_LEN
);
3148 snprintf(str
, SFF_PART_NAME_LEN
+1, a0
->vendor_pn
);
3149 ql_dbg(ql_dbg_init
, vha
, 0x015c,
3150 "SFP Part Name: %s\n", str
);
3153 memset(str
, 0, STR_LEN
);
3157 PRINT_FIELD(fc_med_cc9
, FC_MED_TW
, "Twin AX");
3158 PRINT_FIELD(fc_med_cc9
, FC_MED_TP
, "Twisted Pair");
3159 PRINT_FIELD(fc_med_cc9
, FC_MED_MI
, "Min Coax");
3160 PRINT_FIELD(fc_med_cc9
, FC_MED_TV
, "Video Coax");
3161 PRINT_FIELD(fc_med_cc9
, FC_MED_M6
, "MultiMode 62.5um");
3162 PRINT_FIELD(fc_med_cc9
, FC_MED_M5
, "MultiMode 50um");
3163 PRINT_FIELD(fc_med_cc9
, FC_MED_SM
, "SingleMode");
3164 ql_dbg(ql_dbg_init
, vha
, 0x0160,
3165 "SFP Media: %s\n", str
);
3168 memset(str
, 0, STR_LEN
);
3172 PRINT_FIELD(fc_ll_cc7
, FC_LL_VL
, "Very Long");
3173 PRINT_FIELD(fc_ll_cc7
, FC_LL_S
, "Short");
3174 PRINT_FIELD(fc_ll_cc7
, FC_LL_I
, "Intermediate");
3175 PRINT_FIELD(fc_ll_cc7
, FC_LL_L
, "Long");
3176 PRINT_FIELD(fc_ll_cc7
, FC_LL_M
, "Medium");
3177 ql_dbg(ql_dbg_init
, vha
, 0x0196,
3178 "SFP Link Length: %s\n", str
);
3180 memset(str
, 0, STR_LEN
);
3184 PRINT_FIELD(fc_ll_cc7
, FC_LL_SA
, "Short Wave (SA)");
3185 PRINT_FIELD(fc_ll_cc7
, FC_LL_LC
, "Long Wave(LC)");
3186 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SN
, "Short Wave (SN)");
3187 PRINT_FIELD(fc_tec_cc8
, FC_TEC_SL
, "Short Wave (SL)");
3188 PRINT_FIELD(fc_tec_cc8
, FC_TEC_LL
, "Long Wave (LL)");
3189 ql_dbg(ql_dbg_init
, vha
, 0x016e,
3190 "SFP FC Link Tech: %s\n", str
);
3193 ql_dbg(ql_dbg_init
, vha
, 0x016f,
3194 "SFP Distant: %d km\n", a0
->length_km
);
3195 if (a0
->length_100m
)
3196 ql_dbg(ql_dbg_init
, vha
, 0x0170,
3197 "SFP Distant: %d m\n", a0
->length_100m
*100);
3198 if (a0
->length_50um_10m
)
3199 ql_dbg(ql_dbg_init
, vha
, 0x0189,
3200 "SFP Distant (WL=50um): %d m\n", a0
->length_50um_10m
* 10);
3201 if (a0
->length_62um_10m
)
3202 ql_dbg(ql_dbg_init
, vha
, 0x018a,
3203 "SFP Distant (WL=62.5um): %d m\n", a0
->length_62um_10m
* 10);
3204 if (a0
->length_om4_10m
)
3205 ql_dbg(ql_dbg_init
, vha
, 0x0194,
3206 "SFP Distant (OM4): %d m\n", a0
->length_om4_10m
* 10);
3207 if (a0
->length_om3_10m
)
3208 ql_dbg(ql_dbg_init
, vha
, 0x0195,
3209 "SFP Distant (OM3): %d m\n", a0
->length_om3_10m
* 10);
3215 * QLA_SUCCESS: no action
3216 * QLA_INTERFACE_ERROR: SFP is not there.
3217 * QLA_FUNCTION_FAILED: detected New SFP
3220 qla24xx_detect_sfp(scsi_qla_host_t
*vha
)
3222 int rc
= QLA_SUCCESS
;
3223 struct sff_8247_a0
*a
;
3224 struct qla_hw_data
*ha
= vha
->hw
;
3226 if (!AUTO_DETECT_SFP_SUPPORT(vha
))
3229 rc
= qla2x00_read_sfp_dev(vha
, NULL
, 0);
3233 a
= (struct sff_8247_a0
*)vha
->hw
->sfp_data
;
3234 qla2xxx_print_sfp_info(vha
);
3236 if (a
->fc_ll_cc7
& FC_LL_VL
|| a
->fc_ll_cc7
& FC_LL_L
) {
3238 ha
->flags
.detected_lr_sfp
= 1;
3240 if (a
->length_km
> 5 || a
->length_100m
> 50)
3241 ha
->long_range_distance
= LR_DISTANCE_10K
;
3243 ha
->long_range_distance
= LR_DISTANCE_5K
;
3245 if (ha
->flags
.detected_lr_sfp
!= ha
->flags
.using_lr_setting
)
3246 ql_dbg(ql_dbg_async
, vha
, 0x507b,
3247 "Detected Long Range SFP.\n");
3250 ha
->flags
.detected_lr_sfp
= 0;
3251 if (ha
->flags
.using_lr_setting
)
3252 ql_dbg(ql_dbg_async
, vha
, 0x5084,
3253 "Detected Short Range SFP.\n");
3256 if (!vha
->flags
.init_done
)
3263 * qla2x00_setup_chip() - Load and start RISC firmware.
3266 * Returns 0 on success.
3269 qla2x00_setup_chip(scsi_qla_host_t
*vha
)
3272 uint32_t srisc_address
= 0;
3273 struct qla_hw_data
*ha
= vha
->hw
;
3274 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3275 unsigned long flags
;
3276 uint16_t fw_major_version
;
3278 if (IS_P3P_TYPE(ha
)) {
3279 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3280 if (rval
== QLA_SUCCESS
) {
3281 qla2x00_stop_firmware(vha
);
3282 goto enable_82xx_npiv
;
3287 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3288 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3289 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3290 WRT_REG_WORD(®
->hccr
, (HCCR_ENABLE_PARITY
+ 0x0));
3291 RD_REG_WORD(®
->hccr
);
3292 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3295 qla81xx_mpi_sync(vha
);
3297 /* Load firmware sequences */
3298 rval
= ha
->isp_ops
->load_risc(vha
, &srisc_address
);
3299 if (rval
== QLA_SUCCESS
) {
3300 ql_dbg(ql_dbg_init
, vha
, 0x00c9,
3301 "Verifying Checksum of loaded RISC code.\n");
3303 rval
= qla2x00_verify_checksum(vha
, srisc_address
);
3304 if (rval
== QLA_SUCCESS
) {
3305 /* Start firmware execution. */
3306 ql_dbg(ql_dbg_init
, vha
, 0x00ca,
3307 "Starting firmware.\n");
3310 ha
->flags
.exlogins_enabled
= 1;
3312 if (qla_is_exch_offld_enabled(vha
))
3313 ha
->flags
.exchoffld_enabled
= 1;
3315 rval
= qla2x00_execute_fw(vha
, srisc_address
);
3316 /* Retrieve firmware information. */
3317 if (rval
== QLA_SUCCESS
) {
3318 qla24xx_detect_sfp(vha
);
3320 rval
= qla2x00_set_exlogins_buffer(vha
);
3321 if (rval
!= QLA_SUCCESS
)
3324 rval
= qla2x00_set_exchoffld_buffer(vha
);
3325 if (rval
!= QLA_SUCCESS
)
3329 fw_major_version
= ha
->fw_major_version
;
3330 if (IS_P3P_TYPE(ha
))
3331 qla82xx_check_md_needed(vha
);
3333 rval
= qla2x00_get_fw_version(vha
);
3334 if (rval
!= QLA_SUCCESS
)
3336 ha
->flags
.npiv_supported
= 0;
3337 if (IS_QLA2XXX_MIDTYPE(ha
) &&
3338 (ha
->fw_attributes
& BIT_2
)) {
3339 ha
->flags
.npiv_supported
= 1;
3340 if ((!ha
->max_npiv_vports
) ||
3341 ((ha
->max_npiv_vports
+ 1) %
3342 MIN_MULTI_ID_FABRIC
))
3343 ha
->max_npiv_vports
=
3344 MIN_MULTI_ID_FABRIC
- 1;
3346 qla2x00_get_resource_cnts(vha
);
3349 * Allocate the array of outstanding commands
3350 * now that we know the firmware resources.
3352 rval
= qla2x00_alloc_outstanding_cmds(ha
,
3354 if (rval
!= QLA_SUCCESS
)
3357 if (!fw_major_version
&& !(IS_P3P_TYPE(ha
)))
3358 qla2x00_alloc_offload_mem(vha
);
3360 if (ql2xallocfwdump
&& !(IS_P3P_TYPE(ha
)))
3361 qla2x00_alloc_fw_dump(vha
);
3367 ql_log(ql_log_fatal
, vha
, 0x00cd,
3368 "ISP Firmware failed checksum.\n");
3374 if (!IS_FWI2_CAPABLE(ha
) && !IS_QLA2100(ha
) && !IS_QLA2200(ha
)) {
3375 /* Enable proper parity. */
3376 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3379 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x1);
3381 /* SRAM, Instruction RAM and GP RAM parity */
3382 WRT_REG_WORD(®
->hccr
, HCCR_ENABLE_PARITY
+ 0x7);
3383 RD_REG_WORD(®
->hccr
);
3384 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3388 ha
->flags
.fac_supported
= 1;
3389 else if (rval
== QLA_SUCCESS
&& IS_FAC_REQUIRED(ha
)) {
3392 rval
= qla81xx_fac_get_sector_size(vha
, &size
);
3393 if (rval
== QLA_SUCCESS
) {
3394 ha
->flags
.fac_supported
= 1;
3395 ha
->fdt_block_size
= size
<< 2;
3397 ql_log(ql_log_warn
, vha
, 0x00ce,
3398 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3399 ha
->fw_major_version
, ha
->fw_minor_version
,
3400 ha
->fw_subminor_version
);
3402 if (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3403 ha
->flags
.fac_supported
= 0;
3410 ql_log(ql_log_fatal
, vha
, 0x00cf,
3411 "Setup chip ****FAILED****.\n");
3418 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3421 * Beginning of request ring has initialization control block already built
3422 * by nvram config routine.
3424 * Returns 0 on success.
3427 qla2x00_init_response_q_entries(struct rsp_que
*rsp
)
3432 rsp
->ring_ptr
= rsp
->ring
;
3433 rsp
->ring_index
= 0;
3434 rsp
->status_srb
= NULL
;
3435 pkt
= rsp
->ring_ptr
;
3436 for (cnt
= 0; cnt
< rsp
->length
; cnt
++) {
3437 pkt
->signature
= RESPONSE_PROCESSED
;
3443 * qla2x00_update_fw_options() - Read and process firmware options.
3446 * Returns 0 on success.
3449 qla2x00_update_fw_options(scsi_qla_host_t
*vha
)
3451 uint16_t swing
, emphasis
, tx_sens
, rx_sens
;
3452 struct qla_hw_data
*ha
= vha
->hw
;
3454 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
3455 qla2x00_get_fw_options(vha
, ha
->fw_options
);
3457 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
3460 /* Serial Link options. */
3461 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0115,
3462 "Serial link options.\n");
3463 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0109,
3464 (uint8_t *)&ha
->fw_seriallink_options
,
3465 sizeof(ha
->fw_seriallink_options
));
3467 ha
->fw_options
[1] &= ~FO1_SET_EMPHASIS_SWING
;
3468 if (ha
->fw_seriallink_options
[3] & BIT_2
) {
3469 ha
->fw_options
[1] |= FO1_SET_EMPHASIS_SWING
;
3472 swing
= ha
->fw_seriallink_options
[2] & (BIT_2
| BIT_1
| BIT_0
);
3473 emphasis
= (ha
->fw_seriallink_options
[2] &
3474 (BIT_4
| BIT_3
)) >> 3;
3475 tx_sens
= ha
->fw_seriallink_options
[0] &
3476 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3477 rx_sens
= (ha
->fw_seriallink_options
[0] &
3478 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3479 ha
->fw_options
[10] = (emphasis
<< 14) | (swing
<< 8);
3480 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3483 ha
->fw_options
[10] |= (tx_sens
<< 4) | rx_sens
;
3484 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3485 ha
->fw_options
[10] |= BIT_5
|
3486 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3487 (tx_sens
& (BIT_1
| BIT_0
));
3490 swing
= (ha
->fw_seriallink_options
[2] &
3491 (BIT_7
| BIT_6
| BIT_5
)) >> 5;
3492 emphasis
= ha
->fw_seriallink_options
[3] & (BIT_1
| BIT_0
);
3493 tx_sens
= ha
->fw_seriallink_options
[1] &
3494 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
3495 rx_sens
= (ha
->fw_seriallink_options
[1] &
3496 (BIT_7
| BIT_6
| BIT_5
| BIT_4
)) >> 4;
3497 ha
->fw_options
[11] = (emphasis
<< 14) | (swing
<< 8);
3498 if (IS_QLA2300(ha
) || IS_QLA2312(ha
) || IS_QLA6312(ha
)) {
3501 ha
->fw_options
[11] |= (tx_sens
<< 4) | rx_sens
;
3502 } else if (IS_QLA2322(ha
) || IS_QLA6322(ha
))
3503 ha
->fw_options
[11] |= BIT_5
|
3504 ((rx_sens
& (BIT_1
| BIT_0
)) << 2) |
3505 (tx_sens
& (BIT_1
| BIT_0
));
3509 /* Return command IOCBs without waiting for an ABTS to complete. */
3510 ha
->fw_options
[3] |= BIT_13
;
3513 if (ha
->flags
.enable_led_scheme
)
3514 ha
->fw_options
[2] |= BIT_12
;
3516 /* Detect ISP6312. */
3518 ha
->fw_options
[2] |= BIT_13
;
3520 /* Set Retry FLOGI in case of P2P connection */
3521 if (ha
->operating_mode
== P2P
) {
3522 ha
->fw_options
[2] |= BIT_3
;
3523 ql_dbg(ql_dbg_disc
, vha
, 0x2100,
3524 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3525 __func__
, ha
->fw_options
[2]);
3528 /* Update firmware options. */
3529 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3533 qla24xx_update_fw_options(scsi_qla_host_t
*vha
)
3536 struct qla_hw_data
*ha
= vha
->hw
;
3538 if (IS_P3P_TYPE(ha
))
3541 /* Hold status IOCBs until ABTS response received. */
3543 ha
->fw_options
[3] |= BIT_12
;
3545 /* Set Retry FLOGI in case of P2P connection */
3546 if (ha
->operating_mode
== P2P
) {
3547 ha
->fw_options
[2] |= BIT_3
;
3548 ql_dbg(ql_dbg_disc
, vha
, 0x2101,
3549 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3550 __func__
, ha
->fw_options
[2]);
3553 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3554 if (ql2xmvasynctoatio
&&
3555 (IS_QLA83XX(ha
) || IS_QLA27XX(ha
))) {
3556 if (qla_tgt_mode_enabled(vha
) ||
3557 qla_dual_mode_enabled(vha
))
3558 ha
->fw_options
[2] |= BIT_11
;
3560 ha
->fw_options
[2] &= ~BIT_11
;
3563 if (IS_QLA25XX(ha
) || IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3565 * Tell FW to track each exchange to prevent
3566 * driver from using stale exchange.
3568 if (qla_tgt_mode_enabled(vha
) ||
3569 qla_dual_mode_enabled(vha
))
3570 ha
->fw_options
[2] |= BIT_4
;
3572 ha
->fw_options
[2] &= ~BIT_4
;
3574 /* Reserve 1/2 of emergency exchanges for ELS.*/
3575 if (qla2xuseresexchforels
)
3576 ha
->fw_options
[2] |= BIT_8
;
3578 ha
->fw_options
[2] &= ~BIT_8
;
3581 ql_dbg(ql_dbg_init
, vha
, 0x00e8,
3582 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3583 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
3584 ha
->fw_options
[3], vha
->host
->active_mode
);
3586 if (ha
->fw_options
[1] || ha
->fw_options
[2] || ha
->fw_options
[3])
3587 qla2x00_set_fw_options(vha
, ha
->fw_options
);
3589 /* Update Serial Link options. */
3590 if ((le16_to_cpu(ha
->fw_seriallink_options24
[0]) & BIT_0
) == 0)
3593 rval
= qla2x00_set_serdes_params(vha
,
3594 le16_to_cpu(ha
->fw_seriallink_options24
[1]),
3595 le16_to_cpu(ha
->fw_seriallink_options24
[2]),
3596 le16_to_cpu(ha
->fw_seriallink_options24
[3]));
3597 if (rval
!= QLA_SUCCESS
) {
3598 ql_log(ql_log_warn
, vha
, 0x0104,
3599 "Unable to update Serial Link options (%x).\n", rval
);
3604 qla2x00_config_rings(struct scsi_qla_host
*vha
)
3606 struct qla_hw_data
*ha
= vha
->hw
;
3607 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
3608 struct req_que
*req
= ha
->req_q_map
[0];
3609 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3611 /* Setup ring parameters in initialization control block. */
3612 ha
->init_cb
->request_q_outpointer
= cpu_to_le16(0);
3613 ha
->init_cb
->response_q_inpointer
= cpu_to_le16(0);
3614 ha
->init_cb
->request_q_length
= cpu_to_le16(req
->length
);
3615 ha
->init_cb
->response_q_length
= cpu_to_le16(rsp
->length
);
3616 ha
->init_cb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3617 ha
->init_cb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3618 ha
->init_cb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3619 ha
->init_cb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3621 WRT_REG_WORD(ISP_REQ_Q_IN(ha
, reg
), 0);
3622 WRT_REG_WORD(ISP_REQ_Q_OUT(ha
, reg
), 0);
3623 WRT_REG_WORD(ISP_RSP_Q_IN(ha
, reg
), 0);
3624 WRT_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
), 0);
3625 RD_REG_WORD(ISP_RSP_Q_OUT(ha
, reg
)); /* PCI Posting. */
3629 qla24xx_config_rings(struct scsi_qla_host
*vha
)
3631 struct qla_hw_data
*ha
= vha
->hw
;
3632 device_reg_t
*reg
= ISP_QUE_REG(ha
, 0);
3633 struct device_reg_2xxx __iomem
*ioreg
= &ha
->iobase
->isp
;
3634 struct qla_msix_entry
*msix
;
3635 struct init_cb_24xx
*icb
;
3637 struct req_que
*req
= ha
->req_q_map
[0];
3638 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
3640 /* Setup ring parameters in initialization control block. */
3641 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
3642 icb
->request_q_outpointer
= cpu_to_le16(0);
3643 icb
->response_q_inpointer
= cpu_to_le16(0);
3644 icb
->request_q_length
= cpu_to_le16(req
->length
);
3645 icb
->response_q_length
= cpu_to_le16(rsp
->length
);
3646 icb
->request_q_address
[0] = cpu_to_le32(LSD(req
->dma
));
3647 icb
->request_q_address
[1] = cpu_to_le32(MSD(req
->dma
));
3648 icb
->response_q_address
[0] = cpu_to_le32(LSD(rsp
->dma
));
3649 icb
->response_q_address
[1] = cpu_to_le32(MSD(rsp
->dma
));
3651 /* Setup ATIO queue dma pointers for target mode */
3652 icb
->atio_q_inpointer
= cpu_to_le16(0);
3653 icb
->atio_q_length
= cpu_to_le16(ha
->tgt
.atio_q_length
);
3654 icb
->atio_q_address
[0] = cpu_to_le32(LSD(ha
->tgt
.atio_dma
));
3655 icb
->atio_q_address
[1] = cpu_to_le32(MSD(ha
->tgt
.atio_dma
));
3657 if (IS_SHADOW_REG_CAPABLE(ha
))
3658 icb
->firmware_options_2
|= cpu_to_le32(BIT_30
|BIT_29
);
3660 if (ha
->mqenable
|| IS_QLA83XX(ha
) || IS_QLA27XX(ha
)) {
3661 icb
->qos
= cpu_to_le16(QLA_DEFAULT_QUE_QOS
);
3662 icb
->rid
= cpu_to_le16(rid
);
3663 if (ha
->flags
.msix_enabled
) {
3664 msix
= &ha
->msix_entries
[1];
3665 ql_dbg(ql_dbg_init
, vha
, 0x0019,
3666 "Registering vector 0x%x for base que.\n",
3668 icb
->msix
= cpu_to_le16(msix
->entry
);
3670 /* Use alternate PCI bus number */
3672 icb
->firmware_options_2
|= cpu_to_le32(BIT_19
);
3673 /* Use alternate PCI devfn */
3675 icb
->firmware_options_2
|= cpu_to_le32(BIT_18
);
3677 /* Use Disable MSIX Handshake mode for capable adapters */
3678 if ((ha
->fw_attributes
& BIT_6
) && (IS_MSIX_NACK_CAPABLE(ha
)) &&
3679 (ha
->flags
.msix_enabled
)) {
3680 icb
->firmware_options_2
&= cpu_to_le32(~BIT_22
);
3681 ha
->flags
.disable_msix_handshake
= 1;
3682 ql_dbg(ql_dbg_init
, vha
, 0x00fe,
3683 "MSIX Handshake Disable Mode turned on.\n");
3685 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
3687 icb
->firmware_options_2
|= cpu_to_le32(BIT_23
);
3689 WRT_REG_DWORD(®
->isp25mq
.req_q_in
, 0);
3690 WRT_REG_DWORD(®
->isp25mq
.req_q_out
, 0);
3691 WRT_REG_DWORD(®
->isp25mq
.rsp_q_in
, 0);
3692 WRT_REG_DWORD(®
->isp25mq
.rsp_q_out
, 0);
3694 WRT_REG_DWORD(®
->isp24
.req_q_in
, 0);
3695 WRT_REG_DWORD(®
->isp24
.req_q_out
, 0);
3696 WRT_REG_DWORD(®
->isp24
.rsp_q_in
, 0);
3697 WRT_REG_DWORD(®
->isp24
.rsp_q_out
, 0);
3699 qlt_24xx_config_rings(vha
);
3702 RD_REG_DWORD(&ioreg
->hccr
);
3706 * qla2x00_init_rings() - Initializes firmware.
3709 * Beginning of request ring has initialization control block already built
3710 * by nvram config routine.
3712 * Returns 0 on success.
3715 qla2x00_init_rings(scsi_qla_host_t
*vha
)
3718 unsigned long flags
= 0;
3720 struct qla_hw_data
*ha
= vha
->hw
;
3721 struct req_que
*req
;
3722 struct rsp_que
*rsp
;
3723 struct mid_init_cb_24xx
*mid_init_cb
=
3724 (struct mid_init_cb_24xx
*) ha
->init_cb
;
3726 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
3728 /* Clear outstanding commands array. */
3729 for (que
= 0; que
< ha
->max_req_queues
; que
++) {
3730 req
= ha
->req_q_map
[que
];
3731 if (!req
|| !test_bit(que
, ha
->req_qid_map
))
3733 req
->out_ptr
= (void *)(req
->ring
+ req
->length
);
3735 for (cnt
= 1; cnt
< req
->num_outstanding_cmds
; cnt
++)
3736 req
->outstanding_cmds
[cnt
] = NULL
;
3738 req
->current_outstanding_cmd
= 1;
3740 /* Initialize firmware. */
3741 req
->ring_ptr
= req
->ring
;
3742 req
->ring_index
= 0;
3743 req
->cnt
= req
->length
;
3746 for (que
= 0; que
< ha
->max_rsp_queues
; que
++) {
3747 rsp
= ha
->rsp_q_map
[que
];
3748 if (!rsp
|| !test_bit(que
, ha
->rsp_qid_map
))
3750 rsp
->in_ptr
= (void *)(rsp
->ring
+ rsp
->length
);
3752 /* Initialize response queue entries */
3754 qlafx00_init_response_q_entries(rsp
);
3756 qla2x00_init_response_q_entries(rsp
);
3759 ha
->tgt
.atio_ring_ptr
= ha
->tgt
.atio_ring
;
3760 ha
->tgt
.atio_ring_index
= 0;
3761 /* Initialize ATIO queue entries */
3762 qlt_init_atio_q_entries(vha
);
3764 ha
->isp_ops
->config_rings(vha
);
3766 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
3768 ql_dbg(ql_dbg_init
, vha
, 0x00d1, "Issue init firmware.\n");
3770 if (IS_QLAFX00(ha
)) {
3771 rval
= qlafx00_init_firmware(vha
, ha
->init_cb_size
);
3775 /* Update any ISP specific firmware options before initialization. */
3776 ha
->isp_ops
->update_fw_options(vha
);
3778 if (ha
->flags
.npiv_supported
) {
3779 if (ha
->operating_mode
== LOOP
&& !IS_CNA_CAPABLE(ha
))
3780 ha
->max_npiv_vports
= MIN_MULTI_ID_FABRIC
- 1;
3781 mid_init_cb
->count
= cpu_to_le16(ha
->max_npiv_vports
);
3784 if (IS_FWI2_CAPABLE(ha
)) {
3785 mid_init_cb
->options
= cpu_to_le16(BIT_1
);
3786 mid_init_cb
->init_cb
.execution_throttle
=
3787 cpu_to_le16(ha
->cur_fw_xcb_count
);
3788 ha
->flags
.dport_enabled
=
3789 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_7
) != 0;
3790 ql_dbg(ql_dbg_init
, vha
, 0x0191, "DPORT Support: %s.\n",
3791 (ha
->flags
.dport_enabled
) ? "enabled" : "disabled");
3792 /* FA-WWPN Status */
3793 ha
->flags
.fawwpn_enabled
=
3794 (mid_init_cb
->init_cb
.firmware_options_1
& BIT_6
) != 0;
3795 ql_dbg(ql_dbg_init
, vha
, 0x00bc, "FA-WWPN Support: %s.\n",
3796 (ha
->flags
.fawwpn_enabled
) ? "enabled" : "disabled");
3799 rval
= qla2x00_init_firmware(vha
, ha
->init_cb_size
);
3802 ql_log(ql_log_fatal
, vha
, 0x00d2,
3803 "Init Firmware **** FAILED ****.\n");
3805 ql_dbg(ql_dbg_init
, vha
, 0x00d3,
3806 "Init Firmware -- success.\n");
3814 * qla2x00_fw_ready() - Waits for firmware ready.
3817 * Returns 0 on success.
3820 qla2x00_fw_ready(scsi_qla_host_t
*vha
)
3823 unsigned long wtime
, mtime
, cs84xx_time
;
3824 uint16_t min_wait
; /* Minimum wait time if loop is down */
3825 uint16_t wait_time
; /* Wait time if loop is coming ready */
3827 struct qla_hw_data
*ha
= vha
->hw
;
3829 if (IS_QLAFX00(vha
->hw
))
3830 return qlafx00_fw_ready(vha
);
3834 /* Time to wait for loop down */
3835 if (IS_P3P_TYPE(ha
))
3841 * Firmware should take at most one RATOV to login, plus 5 seconds for
3842 * our own processing.
3844 if ((wait_time
= (ha
->retry_count
*ha
->login_timeout
) + 5) < min_wait
) {
3845 wait_time
= min_wait
;
3848 /* Min wait time if loop down */
3849 mtime
= jiffies
+ (min_wait
* HZ
);
3851 /* wait time before firmware ready */
3852 wtime
= jiffies
+ (wait_time
* HZ
);
3854 /* Wait for ISP to finish LIP */
3855 if (!vha
->flags
.init_done
)
3856 ql_log(ql_log_info
, vha
, 0x801e,
3857 "Waiting for LIP to complete.\n");
3860 memset(state
, -1, sizeof(state
));
3861 rval
= qla2x00_get_firmware_state(vha
, state
);
3862 if (rval
== QLA_SUCCESS
) {
3863 if (state
[0] < FSTATE_LOSS_OF_SYNC
) {
3864 vha
->device_flags
&= ~DFLG_NO_CABLE
;
3866 if (IS_QLA84XX(ha
) && state
[0] != FSTATE_READY
) {
3867 ql_dbg(ql_dbg_taskm
, vha
, 0x801f,
3868 "fw_state=%x 84xx=%x.\n", state
[0],
3870 if ((state
[2] & FSTATE_LOGGED_IN
) &&
3871 (state
[2] & FSTATE_WAITING_FOR_VERIFY
)) {
3872 ql_dbg(ql_dbg_taskm
, vha
, 0x8028,
3873 "Sending verify iocb.\n");
3875 cs84xx_time
= jiffies
;
3876 rval
= qla84xx_init_chip(vha
);
3877 if (rval
!= QLA_SUCCESS
) {
3880 "Init chip failed.\n");
3884 /* Add time taken to initialize. */
3885 cs84xx_time
= jiffies
- cs84xx_time
;
3886 wtime
+= cs84xx_time
;
3887 mtime
+= cs84xx_time
;
3888 ql_dbg(ql_dbg_taskm
, vha
, 0x8008,
3889 "Increasing wait time by %ld. "
3890 "New time %ld.\n", cs84xx_time
,
3893 } else if (state
[0] == FSTATE_READY
) {
3894 ql_dbg(ql_dbg_taskm
, vha
, 0x8037,
3895 "F/W Ready - OK.\n");
3897 qla2x00_get_retry_cnt(vha
, &ha
->retry_count
,
3898 &ha
->login_timeout
, &ha
->r_a_tov
);
3904 rval
= QLA_FUNCTION_FAILED
;
3906 if (atomic_read(&vha
->loop_down_timer
) &&
3907 state
[0] != FSTATE_READY
) {
3908 /* Loop down. Timeout on min_wait for states
3909 * other than Wait for Login.
3911 if (time_after_eq(jiffies
, mtime
)) {
3912 ql_log(ql_log_info
, vha
, 0x8038,
3913 "Cable is unplugged...\n");
3915 vha
->device_flags
|= DFLG_NO_CABLE
;
3920 /* Mailbox cmd failed. Timeout on min_wait. */
3921 if (time_after_eq(jiffies
, mtime
) ||
3922 ha
->flags
.isp82xx_fw_hung
)
3926 if (time_after_eq(jiffies
, wtime
))
3929 /* Delay for a while */
3933 ql_dbg(ql_dbg_taskm
, vha
, 0x803a,
3934 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state
[0],
3935 state
[1], state
[2], state
[3], state
[4], state
[5], jiffies
);
3937 if (rval
&& !(vha
->device_flags
& DFLG_NO_CABLE
)) {
3938 ql_log(ql_log_warn
, vha
, 0x803b,
3939 "Firmware ready **** FAILED ****.\n");
3946 * qla2x00_configure_hba
3947 * Setup adapter context.
3950 * ha = adapter state pointer.
3959 qla2x00_configure_hba(scsi_qla_host_t
*vha
)
3968 char connect_type
[22];
3969 struct qla_hw_data
*ha
= vha
->hw
;
3970 scsi_qla_host_t
*base_vha
= pci_get_drvdata(ha
->pdev
);
3972 unsigned long flags
;
3974 /* Get host addresses. */
3975 rval
= qla2x00_get_adapter_id(vha
,
3976 &loop_id
, &al_pa
, &area
, &domain
, &topo
, &sw_cap
);
3977 if (rval
!= QLA_SUCCESS
) {
3978 if (LOOP_TRANSITION(vha
) || atomic_read(&ha
->loop_down_timer
) ||
3979 IS_CNA_CAPABLE(ha
) ||
3980 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x7)) {
3981 ql_dbg(ql_dbg_disc
, vha
, 0x2008,
3982 "Loop is in a transition state.\n");
3984 ql_log(ql_log_warn
, vha
, 0x2009,
3985 "Unable to get host loop ID.\n");
3986 if (IS_FWI2_CAPABLE(ha
) && (vha
== base_vha
) &&
3987 (rval
== QLA_COMMAND_ERROR
&& loop_id
== 0x1b)) {
3988 ql_log(ql_log_warn
, vha
, 0x1151,
3989 "Doing link init.\n");
3990 if (qla24xx_link_initialize(vha
) == QLA_SUCCESS
)
3993 set_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
3999 ql_log(ql_log_info
, vha
, 0x200a,
4000 "Cannot get topology - retrying.\n");
4001 return (QLA_FUNCTION_FAILED
);
4004 vha
->loop_id
= loop_id
;
4007 ha
->min_external_loopid
= SNS_FIRST_LOOP_ID
;
4008 ha
->operating_mode
= LOOP
;
4013 ql_dbg(ql_dbg_disc
, vha
, 0x200b, "HBA in NL topology.\n");
4014 ha
->current_topology
= ISP_CFG_NL
;
4015 strcpy(connect_type
, "(Loop)");
4019 ql_dbg(ql_dbg_disc
, vha
, 0x200c, "HBA in FL topology.\n");
4020 ha
->switch_cap
= sw_cap
;
4021 ha
->current_topology
= ISP_CFG_FL
;
4022 strcpy(connect_type
, "(FL_Port)");
4026 ql_dbg(ql_dbg_disc
, vha
, 0x200d, "HBA in N P2P topology.\n");
4027 ha
->operating_mode
= P2P
;
4028 ha
->current_topology
= ISP_CFG_N
;
4029 strcpy(connect_type
, "(N_Port-to-N_Port)");
4033 ql_dbg(ql_dbg_disc
, vha
, 0x200e, "HBA in F P2P topology.\n");
4034 ha
->switch_cap
= sw_cap
;
4035 ha
->operating_mode
= P2P
;
4036 ha
->current_topology
= ISP_CFG_F
;
4037 strcpy(connect_type
, "(F_Port)");
4041 ql_dbg(ql_dbg_disc
, vha
, 0x200f,
4042 "HBA in unknown topology %x, using NL.\n", topo
);
4043 ha
->current_topology
= ISP_CFG_NL
;
4044 strcpy(connect_type
, "(Loop)");
4048 /* Save Host port and loop ID. */
4049 /* byte order - Big Endian */
4050 id
.b
.domain
= domain
;
4054 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
4055 qlt_update_host_map(vha
, id
);
4056 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
4058 if (!vha
->flags
.init_done
)
4059 ql_log(ql_log_info
, vha
, 0x2010,
4060 "Topology - %s, Host Loop address 0x%x.\n",
4061 connect_type
, vha
->loop_id
);
4067 qla2x00_set_model_info(scsi_qla_host_t
*vha
, uint8_t *model
, size_t len
,
4072 struct qla_hw_data
*ha
= vha
->hw
;
4073 int use_tbl
= !IS_QLA24XX_TYPE(ha
) && !IS_QLA25XX(ha
) &&
4074 !IS_CNA_CAPABLE(ha
) && !IS_QLA2031(ha
);
4076 if (memcmp(model
, BINZERO
, len
) != 0) {
4077 strncpy(ha
->model_number
, model
, len
);
4078 st
= en
= ha
->model_number
;
4081 if (*en
!= 0x20 && *en
!= 0x00)
4086 index
= (ha
->pdev
->subsystem_device
& 0xff);
4088 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4089 index
< QLA_MODEL_NAMES
)
4090 strncpy(ha
->model_desc
,
4091 qla2x00_model_name
[index
* 2 + 1],
4092 sizeof(ha
->model_desc
) - 1);
4094 index
= (ha
->pdev
->subsystem_device
& 0xff);
4096 ha
->pdev
->subsystem_vendor
== PCI_VENDOR_ID_QLOGIC
&&
4097 index
< QLA_MODEL_NAMES
) {
4098 strcpy(ha
->model_number
,
4099 qla2x00_model_name
[index
* 2]);
4100 strncpy(ha
->model_desc
,
4101 qla2x00_model_name
[index
* 2 + 1],
4102 sizeof(ha
->model_desc
) - 1);
4104 strcpy(ha
->model_number
, def
);
4107 if (IS_FWI2_CAPABLE(ha
))
4108 qla2xxx_get_vpd_field(vha
, "\x82", ha
->model_desc
,
4109 sizeof(ha
->model_desc
));
4112 /* On sparc systems, obtain port and node WWN from firmware
4115 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
, nvram_t
*nv
)
4118 struct qla_hw_data
*ha
= vha
->hw
;
4119 struct pci_dev
*pdev
= ha
->pdev
;
4120 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
4124 val
= of_get_property(dp
, "port-wwn", &len
);
4125 if (val
&& len
>= WWN_SIZE
)
4126 memcpy(nv
->port_name
, val
, WWN_SIZE
);
4128 val
= of_get_property(dp
, "node-wwn", &len
);
4129 if (val
&& len
>= WWN_SIZE
)
4130 memcpy(nv
->node_name
, val
, WWN_SIZE
);
4135 * NVRAM configuration for ISP 2xxx
4138 * ha = adapter block pointer.
4141 * initialization control block in response_ring
4142 * host adapters parameters in host adapter block
4148 qla2x00_nvram_config(scsi_qla_host_t
*vha
)
4153 uint8_t *dptr1
, *dptr2
;
4154 struct qla_hw_data
*ha
= vha
->hw
;
4155 init_cb_t
*icb
= ha
->init_cb
;
4156 nvram_t
*nv
= ha
->nvram
;
4157 uint8_t *ptr
= ha
->nvram
;
4158 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
4162 /* Determine NVRAM starting address. */
4163 ha
->nvram_size
= sizeof(nvram_t
);
4165 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
) && !IS_QLA2300(ha
))
4166 if ((RD_REG_WORD(®
->ctrl_status
) >> 14) == 1)
4167 ha
->nvram_base
= 0x80;
4169 /* Get NVRAM data and calculate checksum. */
4170 ha
->isp_ops
->read_nvram(vha
, ptr
, ha
->nvram_base
, ha
->nvram_size
);
4171 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
; cnt
++)
4174 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010f,
4175 "Contents of NVRAM.\n");
4176 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0110,
4177 (uint8_t *)nv
, ha
->nvram_size
);
4179 /* Bad NVRAM data, set defaults parameters. */
4180 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' ||
4181 nv
->id
[2] != 'P' || nv
->id
[3] != ' ' || nv
->nvram_version
< 1) {
4182 /* Reset NVRAM data. */
4183 ql_log(ql_log_warn
, vha
, 0x0064,
4184 "Inconsistent NVRAM "
4185 "detected: checksum=0x%x id=%c version=0x%x.\n",
4186 chksum
, nv
->id
[0], nv
->nvram_version
);
4187 ql_log(ql_log_warn
, vha
, 0x0065,
4189 "functioning (yet invalid -- WWPN) defaults.\n");
4192 * Set default initialization control block.
4194 memset(nv
, 0, ha
->nvram_size
);
4195 nv
->parameter_block_version
= ICB_VERSION
;
4197 if (IS_QLA23XX(ha
)) {
4198 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4199 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4200 nv
->add_firmware_options
[0] = BIT_5
;
4201 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4202 nv
->frame_payload_size
= 2048;
4203 nv
->special_options
[1] = BIT_7
;
4204 } else if (IS_QLA2200(ha
)) {
4205 nv
->firmware_options
[0] = BIT_2
| BIT_1
;
4206 nv
->firmware_options
[1] = BIT_7
| BIT_5
;
4207 nv
->add_firmware_options
[0] = BIT_5
;
4208 nv
->add_firmware_options
[1] = BIT_5
| BIT_4
;
4209 nv
->frame_payload_size
= 1024;
4210 } else if (IS_QLA2100(ha
)) {
4211 nv
->firmware_options
[0] = BIT_3
| BIT_1
;
4212 nv
->firmware_options
[1] = BIT_5
;
4213 nv
->frame_payload_size
= 1024;
4216 nv
->max_iocb_allocation
= cpu_to_le16(256);
4217 nv
->execution_throttle
= cpu_to_le16(16);
4218 nv
->retry_count
= 8;
4219 nv
->retry_delay
= 1;
4221 nv
->port_name
[0] = 33;
4222 nv
->port_name
[3] = 224;
4223 nv
->port_name
[4] = 139;
4225 qla2xxx_nvram_wwn_from_ofw(vha
, nv
);
4227 nv
->login_timeout
= 4;
4230 * Set default host adapter parameters
4232 nv
->host_p
[1] = BIT_2
;
4233 nv
->reset_delay
= 5;
4234 nv
->port_down_retry_count
= 8;
4235 nv
->max_luns_per_target
= cpu_to_le16(8);
4236 nv
->link_down_timeout
= 60;
4241 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4243 * The SN2 does not provide BIOS emulation which means you can't change
4244 * potentially bogus BIOS settings. Force the use of default settings
4245 * for link rate and frame size. Hope that the rest of the settings
4248 if (ia64_platform_is("sn2")) {
4249 nv
->frame_payload_size
= 2048;
4251 nv
->special_options
[1] = BIT_7
;
4255 /* Reset Initialization control block */
4256 memset(icb
, 0, ha
->init_cb_size
);
4259 * Setup driver NVRAM options.
4261 nv
->firmware_options
[0] |= (BIT_6
| BIT_1
);
4262 nv
->firmware_options
[0] &= ~(BIT_5
| BIT_4
);
4263 nv
->firmware_options
[1] |= (BIT_5
| BIT_0
);
4264 nv
->firmware_options
[1] &= ~BIT_4
;
4266 if (IS_QLA23XX(ha
)) {
4267 nv
->firmware_options
[0] |= BIT_2
;
4268 nv
->firmware_options
[0] &= ~BIT_3
;
4269 nv
->special_options
[0] &= ~BIT_6
;
4270 nv
->add_firmware_options
[1] |= BIT_5
| BIT_4
;
4272 if (IS_QLA2300(ha
)) {
4273 if (ha
->fb_rev
== FPM_2310
) {
4274 strcpy(ha
->model_number
, "QLA2310");
4276 strcpy(ha
->model_number
, "QLA2300");
4279 qla2x00_set_model_info(vha
, nv
->model_number
,
4280 sizeof(nv
->model_number
), "QLA23xx");
4282 } else if (IS_QLA2200(ha
)) {
4283 nv
->firmware_options
[0] |= BIT_2
;
4285 * 'Point-to-point preferred, else loop' is not a safe
4286 * connection mode setting.
4288 if ((nv
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) ==
4290 /* Force 'loop preferred, else point-to-point'. */
4291 nv
->add_firmware_options
[0] &= ~(BIT_6
| BIT_5
| BIT_4
);
4292 nv
->add_firmware_options
[0] |= BIT_5
;
4294 strcpy(ha
->model_number
, "QLA22xx");
4295 } else /*if (IS_QLA2100(ha))*/ {
4296 strcpy(ha
->model_number
, "QLA2100");
4300 * Copy over NVRAM RISC parameter block to initialization control block.
4302 dptr1
= (uint8_t *)icb
;
4303 dptr2
= (uint8_t *)&nv
->parameter_block_version
;
4304 cnt
= (uint8_t *)&icb
->request_q_outpointer
- (uint8_t *)&icb
->version
;
4306 *dptr1
++ = *dptr2
++;
4308 /* Copy 2nd half. */
4309 dptr1
= (uint8_t *)icb
->add_firmware_options
;
4310 cnt
= (uint8_t *)icb
->reserved_3
- (uint8_t *)icb
->add_firmware_options
;
4312 *dptr1
++ = *dptr2
++;
4314 /* Use alternate WWN? */
4315 if (nv
->host_p
[1] & BIT_7
) {
4316 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
4317 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
4320 /* Prepare nodename */
4321 if ((icb
->firmware_options
[1] & BIT_6
) == 0) {
4323 * Firmware will apply the following mask if the nodename was
4326 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
4327 icb
->node_name
[0] &= 0xF0;
4331 * Set host adapter parameters.
4335 * BIT_7 in the host-parameters section allows for modification to
4336 * internal driver logging.
4338 if (nv
->host_p
[0] & BIT_7
)
4339 ql2xextended_error_logging
= QL_DBG_DEFAULT1_MASK
;
4340 ha
->flags
.disable_risc_code_load
= ((nv
->host_p
[0] & BIT_4
) ? 1 : 0);
4341 /* Always load RISC code on non ISP2[12]00 chips. */
4342 if (!IS_QLA2100(ha
) && !IS_QLA2200(ha
))
4343 ha
->flags
.disable_risc_code_load
= 0;
4344 ha
->flags
.enable_lip_reset
= ((nv
->host_p
[1] & BIT_1
) ? 1 : 0);
4345 ha
->flags
.enable_lip_full_login
= ((nv
->host_p
[1] & BIT_2
) ? 1 : 0);
4346 ha
->flags
.enable_target_reset
= ((nv
->host_p
[1] & BIT_3
) ? 1 : 0);
4347 ha
->flags
.enable_led_scheme
= (nv
->special_options
[1] & BIT_4
) ? 1 : 0;
4348 ha
->flags
.disable_serdes
= 0;
4350 ha
->operating_mode
=
4351 (icb
->add_firmware_options
[0] & (BIT_6
| BIT_5
| BIT_4
)) >> 4;
4353 memcpy(ha
->fw_seriallink_options
, nv
->seriallink_options
,
4354 sizeof(ha
->fw_seriallink_options
));
4356 /* save HBA serial number */
4357 ha
->serial0
= icb
->port_name
[5];
4358 ha
->serial1
= icb
->port_name
[6];
4359 ha
->serial2
= icb
->port_name
[7];
4360 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
4361 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
4363 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
4365 ha
->retry_count
= nv
->retry_count
;
4367 /* Set minimum login_timeout to 4 seconds. */
4368 if (nv
->login_timeout
!= ql2xlogintimeout
)
4369 nv
->login_timeout
= ql2xlogintimeout
;
4370 if (nv
->login_timeout
< 4)
4371 nv
->login_timeout
= 4;
4372 ha
->login_timeout
= nv
->login_timeout
;
4374 /* Set minimum RATOV to 100 tenths of a second. */
4377 ha
->loop_reset_delay
= nv
->reset_delay
;
4379 /* Link Down Timeout = 0:
4381 * When Port Down timer expires we will start returning
4382 * I/O's to OS with "DID_NO_CONNECT".
4384 * Link Down Timeout != 0:
4386 * The driver waits for the link to come up after link down
4387 * before returning I/Os to OS with "DID_NO_CONNECT".
4389 if (nv
->link_down_timeout
== 0) {
4390 ha
->loop_down_abort_time
=
4391 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
4393 ha
->link_down_timeout
= nv
->link_down_timeout
;
4394 ha
->loop_down_abort_time
=
4395 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
4399 * Need enough time to try and get the port back.
4401 ha
->port_down_retry_count
= nv
->port_down_retry_count
;
4402 if (qlport_down_retry
)
4403 ha
->port_down_retry_count
= qlport_down_retry
;
4404 /* Set login_retry_count */
4405 ha
->login_retry_count
= nv
->retry_count
;
4406 if (ha
->port_down_retry_count
== nv
->port_down_retry_count
&&
4407 ha
->port_down_retry_count
> 3)
4408 ha
->login_retry_count
= ha
->port_down_retry_count
;
4409 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
4410 ha
->login_retry_count
= ha
->port_down_retry_count
;
4411 if (ql2xloginretrycount
)
4412 ha
->login_retry_count
= ql2xloginretrycount
;
4414 icb
->lun_enables
= cpu_to_le16(0);
4415 icb
->command_resource_count
= 0;
4416 icb
->immediate_notify_resource_count
= 0;
4417 icb
->timeout
= cpu_to_le16(0);
4419 if (IS_QLA2100(ha
) || IS_QLA2200(ha
)) {
4421 icb
->firmware_options
[0] &= ~BIT_3
;
4422 icb
->add_firmware_options
[0] &=
4423 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4424 icb
->add_firmware_options
[0] |= BIT_2
;
4425 icb
->response_accumulation_timer
= 3;
4426 icb
->interrupt_delay_timer
= 5;
4428 vha
->flags
.process_response_queue
= 1;
4431 if (!vha
->flags
.init_done
) {
4432 ha
->zio_mode
= icb
->add_firmware_options
[0] &
4433 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4434 ha
->zio_timer
= icb
->interrupt_delay_timer
?
4435 icb
->interrupt_delay_timer
: 2;
4437 icb
->add_firmware_options
[0] &=
4438 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
);
4439 vha
->flags
.process_response_queue
= 0;
4440 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
4441 ha
->zio_mode
= QLA_ZIO_MODE_6
;
4443 ql_log(ql_log_info
, vha
, 0x0068,
4444 "ZIO mode %d enabled; timer delay (%d us).\n",
4445 ha
->zio_mode
, ha
->zio_timer
* 100);
4447 icb
->add_firmware_options
[0] |= (uint8_t)ha
->zio_mode
;
4448 icb
->interrupt_delay_timer
= (uint8_t)ha
->zio_timer
;
4449 vha
->flags
.process_response_queue
= 1;
4454 ql_log(ql_log_warn
, vha
, 0x0069,
4455 "NVRAM configuration failed.\n");
4461 qla2x00_rport_del(void *data
)
4463 fc_port_t
*fcport
= data
;
4464 struct fc_rport
*rport
;
4465 unsigned long flags
;
4467 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
4468 rport
= fcport
->drport
? fcport
->drport
: fcport
->rport
;
4469 fcport
->drport
= NULL
;
4470 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
4472 ql_dbg(ql_dbg_disc
, fcport
->vha
, 0x210b,
4473 "%s %8phN. rport %p roles %x\n",
4474 __func__
, fcport
->port_name
, rport
,
4477 fc_remote_port_delete(rport
);
4482 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4484 * @flags: allocation flags
4486 * Returns a pointer to the allocated fcport, or NULL, if none available.
4489 qla2x00_alloc_fcport(scsi_qla_host_t
*vha
, gfp_t flags
)
4493 fcport
= kzalloc(sizeof(fc_port_t
), flags
);
4497 /* Setup fcport template structure. */
4499 fcport
->port_type
= FCT_UNKNOWN
;
4500 fcport
->loop_id
= FC_NO_LOOP_ID
;
4501 qla2x00_set_fcport_state(fcport
, FCS_UNCONFIGURED
);
4502 fcport
->supported_classes
= FC_COS_UNSPECIFIED
;
4504 fcport
->ct_desc
.ct_sns
= dma_alloc_coherent(&vha
->hw
->pdev
->dev
,
4505 sizeof(struct ct_sns_pkt
), &fcport
->ct_desc
.ct_sns_dma
,
4507 fcport
->disc_state
= DSC_DELETED
;
4508 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4509 fcport
->deleted
= QLA_SESS_DELETED
;
4510 fcport
->login_retry
= vha
->hw
->login_retry_count
;
4511 fcport
->login_retry
= 5;
4512 fcport
->logout_on_delete
= 1;
4514 if (!fcport
->ct_desc
.ct_sns
) {
4515 ql_log(ql_log_warn
, vha
, 0xd049,
4516 "Failed to allocate ct_sns request.\n");
4520 INIT_WORK(&fcport
->del_work
, qla24xx_delete_sess_fn
);
4521 INIT_LIST_HEAD(&fcport
->gnl_entry
);
4522 INIT_LIST_HEAD(&fcport
->list
);
4528 qla2x00_free_fcport(fc_port_t
*fcport
)
4530 if (fcport
->ct_desc
.ct_sns
) {
4531 dma_free_coherent(&fcport
->vha
->hw
->pdev
->dev
,
4532 sizeof(struct ct_sns_pkt
), fcport
->ct_desc
.ct_sns
,
4533 fcport
->ct_desc
.ct_sns_dma
);
4535 fcport
->ct_desc
.ct_sns
= NULL
;
4541 * qla2x00_configure_loop
4542 * Updates Fibre Channel Device Database with what is actually on loop.
4545 * ha = adapter block pointer.
4550 * 2 = database was full and device was not configured.
4553 qla2x00_configure_loop(scsi_qla_host_t
*vha
)
4556 unsigned long flags
, save_flags
;
4557 struct qla_hw_data
*ha
= vha
->hw
;
4560 /* Get Initiator ID */
4561 if (test_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
)) {
4562 rval
= qla2x00_configure_hba(vha
);
4563 if (rval
!= QLA_SUCCESS
) {
4564 ql_dbg(ql_dbg_disc
, vha
, 0x2013,
4565 "Unable to configure HBA.\n");
4570 save_flags
= flags
= vha
->dpc_flags
;
4571 ql_dbg(ql_dbg_disc
, vha
, 0x2014,
4572 "Configure loop -- dpc flags = 0x%lx.\n", flags
);
4575 * If we have both an RSCN and PORT UPDATE pending then handle them
4576 * both at the same time.
4578 clear_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4579 clear_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4581 qla2x00_get_data_rate(vha
);
4583 /* Determine what we need to do */
4584 if (ha
->current_topology
== ISP_CFG_FL
&&
4585 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4587 set_bit(RSCN_UPDATE
, &flags
);
4589 } else if (ha
->current_topology
== ISP_CFG_F
&&
4590 (test_bit(LOCAL_LOOP_UPDATE
, &flags
))) {
4592 set_bit(RSCN_UPDATE
, &flags
);
4593 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4595 } else if (ha
->current_topology
== ISP_CFG_N
) {
4596 clear_bit(RSCN_UPDATE
, &flags
);
4597 if (ha
->flags
.rida_fmt2
) {
4598 /* With Rida Format 2, the login is already triggered.
4599 * We know who is on the other side of the wire.
4600 * No need to login to do login to find out or drop into
4601 * qla2x00_configure_local_loop().
4603 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4604 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4606 if (qla_tgt_mode_enabled(vha
)) {
4607 /* allow the other side to start the login */
4608 clear_bit(LOCAL_LOOP_UPDATE
, &flags
);
4609 set_bit(RELOGIN_NEEDED
, &vha
->dpc_flags
);
4612 } else if (ha
->current_topology
== ISP_CFG_NL
) {
4613 clear_bit(RSCN_UPDATE
, &flags
);
4614 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4615 } else if (!vha
->flags
.online
||
4616 (test_bit(ABORT_ISP_ACTIVE
, &flags
))) {
4617 set_bit(RSCN_UPDATE
, &flags
);
4618 set_bit(LOCAL_LOOP_UPDATE
, &flags
);
4621 if (test_bit(LOCAL_LOOP_UPDATE
, &flags
)) {
4622 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4623 ql_dbg(ql_dbg_disc
, vha
, 0x2015,
4624 "Loop resync needed, failing.\n");
4625 rval
= QLA_FUNCTION_FAILED
;
4627 rval
= qla2x00_configure_local_loop(vha
);
4630 if (rval
== QLA_SUCCESS
&& test_bit(RSCN_UPDATE
, &flags
)) {
4631 if (LOOP_TRANSITION(vha
)) {
4632 ql_dbg(ql_dbg_disc
, vha
, 0x2099,
4633 "Needs RSCN update and loop transition.\n");
4634 rval
= QLA_FUNCTION_FAILED
;
4637 rval
= qla2x00_configure_fabric(vha
);
4640 if (rval
== QLA_SUCCESS
) {
4641 if (atomic_read(&vha
->loop_down_timer
) ||
4642 test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4643 rval
= QLA_FUNCTION_FAILED
;
4645 atomic_set(&vha
->loop_state
, LOOP_READY
);
4646 ql_dbg(ql_dbg_disc
, vha
, 0x2069,
4648 ha
->flags
.fw_init_done
= 1;
4651 * Process any ATIO queue entries that came in
4652 * while we weren't online.
4654 if (qla_tgt_mode_enabled(vha
) ||
4655 qla_dual_mode_enabled(vha
)) {
4656 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
)) {
4657 spin_lock_irqsave(&ha
->tgt
.atio_lock
,
4659 qlt_24xx_process_atio_queue(vha
, 0);
4660 spin_unlock_irqrestore(
4661 &ha
->tgt
.atio_lock
, flags
);
4663 spin_lock_irqsave(&ha
->hardware_lock
,
4665 qlt_24xx_process_atio_queue(vha
, 1);
4666 spin_unlock_irqrestore(
4667 &ha
->hardware_lock
, flags
);
4674 ql_dbg(ql_dbg_disc
, vha
, 0x206a,
4675 "%s *** FAILED ***.\n", __func__
);
4677 ql_dbg(ql_dbg_disc
, vha
, 0x206b,
4678 "%s: exiting normally.\n", __func__
);
4681 /* Restore state if a resync event occurred during processing */
4682 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
)) {
4683 if (test_bit(LOCAL_LOOP_UPDATE
, &save_flags
))
4684 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
4685 if (test_bit(RSCN_UPDATE
, &save_flags
)) {
4686 set_bit(RSCN_UPDATE
, &vha
->dpc_flags
);
4695 * Updates Fibre Channel Device Database with local loop devices.
4698 * ha = adapter block pointer.
4702 static int qla24xx_n2n_handle_login(struct scsi_qla_host
*vha
,
4705 struct qla_hw_data
*ha
= vha
->hw
;
4706 int res
= QLA_SUCCESS
, rval
;
4707 int greater_wwpn
= 0;
4710 if (ha
->current_topology
!= ISP_CFG_N
)
4713 if (wwn_to_u64(vha
->port_name
) >
4714 wwn_to_u64(vha
->n2n_port_name
)) {
4715 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
4716 "HBA WWPN is greater %llx > target %llx\n",
4717 wwn_to_u64(vha
->port_name
),
4718 wwn_to_u64(vha
->n2n_port_name
));
4720 fcport
->d_id
.b24
= vha
->n2n_id
;
4723 fcport
->loop_id
= vha
->loop_id
;
4724 fcport
->fc4f_nvme
= 0;
4727 ql_dbg(ql_dbg_disc
, vha
, 0x4001,
4728 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4729 fcport
->d_id
.b24
, vha
->loop_id
);
4731 /* Fill in member data. */
4732 if (!greater_wwpn
) {
4733 rval
= qla2x00_get_port_database(vha
, fcport
, 0);
4734 ql_dbg(ql_dbg_disc
, vha
, 0x1051,
4735 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4736 fcport
->current_login_state
, fcport
->last_login_state
,
4737 fcport
->d_id
.b24
, fcport
->loop_id
, rval
);
4739 if (((fcport
->current_login_state
& 0xf) == 0x4) ||
4740 ((fcport
->current_login_state
& 0xf) == 0x6))
4744 if (logged_in
|| greater_wwpn
) {
4745 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
4746 qla_nvme_register_hba(vha
);
4748 /* Set connected N_Port d_id */
4749 if (vha
->flags
.nvme_enabled
)
4750 fcport
->fc4f_nvme
= 1;
4752 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4753 fcport
->fw_login_state
= DSC_LS_PORT_UNAVAIL
;
4754 fcport
->disc_state
= DSC_GNL
;
4755 fcport
->n2n_flag
= 1;
4757 vha
->hw
->flags
.gpsc_supported
= 0;
4760 ql_dbg(ql_dbg_disc
, vha
, 0x20e5,
4761 "%s %d PLOGI ELS %8phC\n",
4762 __func__
, __LINE__
, fcport
->port_name
);
4764 res
= qla24xx_els_dcmd2_iocb(vha
, ELS_DCMD_PLOGI
,
4765 fcport
, fcport
->d_id
);
4768 if (res
!= QLA_SUCCESS
) {
4769 ql_log(ql_log_info
, vha
, 0xd04d,
4770 "PLOGI Failed: portid=%06x - retrying\n",
4774 /* State 0x6 means FCP PRLI complete */
4775 if ((fcport
->current_login_state
& 0xf) == 0x6) {
4776 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
4777 "%s %d %8phC post GPDB work\n",
4778 __func__
, __LINE__
, fcport
->port_name
);
4779 fcport
->chip_reset
=
4780 vha
->hw
->base_qpair
->chip_reset
;
4781 qla24xx_post_gpdb_work(vha
, fcport
, 0);
4783 ql_dbg(ql_dbg_disc
, vha
, 0x2118,
4784 "%s %d %8phC post NVMe PRLI\n",
4785 __func__
, __LINE__
, fcport
->port_name
);
4786 qla24xx_post_prli_work(vha
, fcport
);
4790 /* Wait for next database change */
4791 set_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
);
4798 * qla2x00_configure_local_loop
4799 * Updates Fibre Channel Device Database with local loop devices.
4802 * ha = adapter block pointer.
4808 qla2x00_configure_local_loop(scsi_qla_host_t
*vha
)
4813 fc_port_t
*fcport
, *new_fcport
;
4819 uint8_t domain
, area
, al_pa
;
4820 struct qla_hw_data
*ha
= vha
->hw
;
4821 unsigned long flags
;
4825 entries
= MAX_FIBRE_DEVICES_LOOP
;
4827 /* Get list of logged in devices. */
4828 memset(ha
->gid_list
, 0, qla2x00_gid_list_size(ha
));
4829 rval
= qla2x00_get_id_list(vha
, ha
->gid_list
, ha
->gid_list_dma
,
4831 if (rval
!= QLA_SUCCESS
)
4832 goto cleanup_allocation
;
4834 ql_dbg(ql_dbg_disc
, vha
, 0x2011,
4835 "Entries in ID list (%d).\n", entries
);
4836 ql_dump_buffer(ql_dbg_disc
+ ql_dbg_buffer
, vha
, 0x2075,
4837 (uint8_t *)ha
->gid_list
,
4838 entries
* sizeof(struct gid_list_info
));
4840 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4841 fcport
->scan_state
= QLA_FCPORT_SCAN
;
4844 /* Allocate temporary fcport for any new fcports discovered. */
4845 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4846 if (new_fcport
== NULL
) {
4847 ql_log(ql_log_warn
, vha
, 0x2012,
4848 "Memory allocation failed for fcport.\n");
4849 rval
= QLA_MEMORY_ALLOC_FAILED
;
4850 goto cleanup_allocation
;
4852 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4854 /* Inititae N2N login. */
4855 if (test_and_clear_bit(N2N_LOGIN_NEEDED
, &vha
->dpc_flags
)) {
4856 rval
= qla24xx_n2n_handle_login(vha
, new_fcport
);
4857 if (rval
!= QLA_SUCCESS
)
4858 goto cleanup_allocation
;
4862 /* Add devices to port list. */
4863 id_iter
= (char *)ha
->gid_list
;
4864 for (index
= 0; index
< entries
; index
++) {
4865 domain
= ((struct gid_list_info
*)id_iter
)->domain
;
4866 area
= ((struct gid_list_info
*)id_iter
)->area
;
4867 al_pa
= ((struct gid_list_info
*)id_iter
)->al_pa
;
4868 if (IS_QLA2100(ha
) || IS_QLA2200(ha
))
4869 loop_id
= (uint16_t)
4870 ((struct gid_list_info
*)id_iter
)->loop_id_2100
;
4872 loop_id
= le16_to_cpu(
4873 ((struct gid_list_info
*)id_iter
)->loop_id
);
4874 id_iter
+= ha
->gid_list_info_size
;
4876 /* Bypass reserved domain fields. */
4877 if ((domain
& 0xf0) == 0xf0)
4880 /* Bypass if not same domain and area of adapter. */
4881 if (area
&& domain
&&
4882 (area
!= vha
->d_id
.b
.area
|| domain
!= vha
->d_id
.b
.domain
))
4885 /* Bypass invalid local loop ID. */
4886 if (loop_id
> LAST_LOCAL_LOOP_ID
)
4889 memset(new_fcport
->port_name
, 0, WWN_SIZE
);
4891 /* Fill in member data. */
4892 new_fcport
->d_id
.b
.domain
= domain
;
4893 new_fcport
->d_id
.b
.area
= area
;
4894 new_fcport
->d_id
.b
.al_pa
= al_pa
;
4895 new_fcport
->loop_id
= loop_id
;
4896 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
4898 rval2
= qla2x00_get_port_database(vha
, new_fcport
, 0);
4899 if (rval2
!= QLA_SUCCESS
) {
4900 ql_dbg(ql_dbg_disc
, vha
, 0x2097,
4901 "Failed to retrieve fcport information "
4902 "-- get_port_database=%x, loop_id=0x%04x.\n",
4903 rval2
, new_fcport
->loop_id
);
4904 /* Skip retry if N2N */
4905 if (ha
->current_topology
!= ISP_CFG_N
) {
4906 ql_dbg(ql_dbg_disc
, vha
, 0x2105,
4907 "Scheduling resync.\n");
4908 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
4913 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4914 /* Check for matching device in port list. */
4917 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4918 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
4922 fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4923 fcport
->loop_id
= new_fcport
->loop_id
;
4924 fcport
->port_type
= new_fcport
->port_type
;
4925 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
4926 memcpy(fcport
->node_name
, new_fcport
->node_name
,
4928 fcport
->scan_state
= QLA_FCPORT_FOUND
;
4934 /* New device, add to fcports list. */
4935 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
4937 /* Allocate a new replacement fcport. */
4938 fcport
= new_fcport
;
4940 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4942 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
4944 if (new_fcport
== NULL
) {
4945 ql_log(ql_log_warn
, vha
, 0xd031,
4946 "Failed to allocate memory for fcport.\n");
4947 rval
= QLA_MEMORY_ALLOC_FAILED
;
4948 goto cleanup_allocation
;
4950 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
4951 new_fcport
->flags
&= ~FCF_FABRIC_DEVICE
;
4954 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
4956 /* Base iIDMA settings on HBA port speed. */
4957 fcport
->fp_speed
= ha
->link_data_rate
;
4962 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
4963 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
4966 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
4967 if ((qla_dual_mode_enabled(vha
) ||
4968 qla_ini_mode_enabled(vha
)) &&
4969 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
4970 qla2x00_mark_device_lost(vha
, fcport
,
4971 ql2xplogiabsentdevice
, 0);
4972 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
4973 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
4974 fcport
->port_type
!= FCT_INITIATOR
&&
4975 fcport
->port_type
!= FCT_BROADCAST
) {
4976 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
4977 "%s %d %8phC post del sess\n",
4981 qlt_schedule_sess_for_deletion(fcport
);
4987 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
4988 qla24xx_fcport_handle_login(vha
, fcport
);
4994 if (rval
!= QLA_SUCCESS
) {
4995 ql_dbg(ql_dbg_disc
, vha
, 0x2098,
4996 "Configure local loop error exit: rval=%x.\n", rval
);
5003 qla2x00_iidma_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5006 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5007 struct qla_hw_data
*ha
= vha
->hw
;
5009 if (!IS_IIDMA_CAPABLE(ha
))
5012 if (atomic_read(&fcport
->state
) != FCS_ONLINE
)
5015 if (fcport
->fp_speed
== PORT_SPEED_UNKNOWN
||
5016 fcport
->fp_speed
> ha
->link_data_rate
)
5019 rval
= qla2x00_set_idma_speed(vha
, fcport
->loop_id
, fcport
->fp_speed
,
5021 if (rval
!= QLA_SUCCESS
) {
5022 ql_dbg(ql_dbg_disc
, vha
, 0x2004,
5023 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5024 fcport
->port_name
, rval
, fcport
->fp_speed
, mb
[0], mb
[1]);
5026 ql_dbg(ql_dbg_disc
, vha
, 0x2005,
5027 "iIDMA adjusted to %s GB/s on %8phN.\n",
5028 qla2x00_get_link_speed_str(ha
, fcport
->fp_speed
),
5033 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5035 qla2x00_reg_remote_port(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5037 struct fc_rport_identifiers rport_ids
;
5038 struct fc_rport
*rport
;
5039 unsigned long flags
;
5041 rport_ids
.node_name
= wwn_to_u64(fcport
->node_name
);
5042 rport_ids
.port_name
= wwn_to_u64(fcport
->port_name
);
5043 rport_ids
.port_id
= fcport
->d_id
.b
.domain
<< 16 |
5044 fcport
->d_id
.b
.area
<< 8 | fcport
->d_id
.b
.al_pa
;
5045 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5046 fcport
->rport
= rport
= fc_remote_port_add(vha
->host
, 0, &rport_ids
);
5048 ql_log(ql_log_warn
, vha
, 0x2006,
5049 "Unable to allocate fc remote port.\n");
5053 spin_lock_irqsave(fcport
->vha
->host
->host_lock
, flags
);
5054 *((fc_port_t
**)rport
->dd_data
) = fcport
;
5055 spin_unlock_irqrestore(fcport
->vha
->host
->host_lock
, flags
);
5057 rport
->supported_classes
= fcport
->supported_classes
;
5059 rport_ids
.roles
= FC_RPORT_ROLE_UNKNOWN
;
5060 if (fcport
->port_type
== FCT_INITIATOR
)
5061 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_INITIATOR
;
5062 if (fcport
->port_type
== FCT_TARGET
)
5063 rport_ids
.roles
|= FC_RPORT_ROLE_FCP_TARGET
;
5065 ql_dbg(ql_dbg_disc
, vha
, 0x20ee,
5066 "%s %8phN. rport %p is %s mode\n",
5067 __func__
, fcport
->port_name
, rport
,
5068 (fcport
->port_type
== FCT_TARGET
) ? "tgt" : "ini");
5070 fc_remote_port_rolechg(rport
, rport_ids
.roles
);
5074 * qla2x00_update_fcport
5075 * Updates device on list.
5078 * ha = adapter block pointer.
5079 * fcport = port structure pointer.
5089 qla2x00_update_fcport(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5093 if (IS_SW_RESV_ADDR(fcport
->d_id
))
5096 ql_dbg(ql_dbg_disc
, vha
, 0x20ef, "%s %8phC\n",
5097 __func__
, fcport
->port_name
);
5099 if (IS_QLAFX00(vha
->hw
)) {
5100 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5103 fcport
->login_retry
= 0;
5104 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
5105 fcport
->disc_state
= DSC_LOGIN_COMPLETE
;
5106 fcport
->deleted
= 0;
5107 fcport
->logout_on_delete
= 1;
5109 if (fcport
->fc4f_nvme
) {
5110 qla_nvme_register_remote(vha
, fcport
);
5114 qla2x00_set_fcport_state(fcport
, FCS_ONLINE
);
5115 qla2x00_iidma_fcport(vha
, fcport
);
5116 qla24xx_update_fcport_fcp_prio(vha
, fcport
);
5119 switch (vha
->host
->active_mode
) {
5120 case MODE_INITIATOR
:
5121 qla2x00_reg_remote_port(vha
, fcport
);
5124 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5125 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5126 qlt_fc_port_added(vha
, fcport
);
5129 qla2x00_reg_remote_port(vha
, fcport
);
5130 if (!vha
->vha_tgt
.qla_tgt
->tgt_stop
&&
5131 !vha
->vha_tgt
.qla_tgt
->tgt_stopped
)
5132 qlt_fc_port_added(vha
, fcport
);
5140 * qla2x00_configure_fabric
5141 * Setup SNS devices with loop ID's.
5144 * ha = adapter block pointer.
5151 qla2x00_configure_fabric(scsi_qla_host_t
*vha
)
5155 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5157 LIST_HEAD(new_fcports
);
5158 struct qla_hw_data
*ha
= vha
->hw
;
5161 /* If FL port exists, then SNS is present */
5162 if (IS_FWI2_CAPABLE(ha
))
5163 loop_id
= NPH_F_PORT
;
5165 loop_id
= SNS_FL_PORT
;
5166 rval
= qla2x00_get_port_name(vha
, loop_id
, vha
->fabric_node_name
, 1);
5167 if (rval
!= QLA_SUCCESS
) {
5168 ql_dbg(ql_dbg_disc
, vha
, 0x20a0,
5169 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5171 vha
->device_flags
&= ~SWITCH_FOUND
;
5172 return (QLA_SUCCESS
);
5174 vha
->device_flags
|= SWITCH_FOUND
;
5177 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
)) {
5178 rval
= qla2x00_send_change_request(vha
, 0x3, 0);
5179 if (rval
!= QLA_SUCCESS
)
5180 ql_log(ql_log_warn
, vha
, 0x121,
5181 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5187 qla2x00_mgmt_svr_login(vha
);
5190 if (ql2xfdmienable
&&
5191 test_and_clear_bit(REGISTER_FDMI_NEEDED
, &vha
->dpc_flags
))
5192 qla2x00_fdmi_register(vha
);
5194 /* Ensure we are logged into the SNS. */
5195 loop_id
= NPH_SNS_LID(ha
);
5196 rval
= ha
->isp_ops
->fabric_login(vha
, loop_id
, 0xff, 0xff,
5197 0xfc, mb
, BIT_1
|BIT_0
);
5198 if (rval
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
5199 ql_dbg(ql_dbg_disc
, vha
, 0x20a1,
5200 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5201 loop_id
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7], rval
);
5202 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5205 if (test_and_clear_bit(REGISTER_FC4_NEEDED
, &vha
->dpc_flags
)) {
5206 if (qla2x00_rft_id(vha
)) {
5208 ql_dbg(ql_dbg_disc
, vha
, 0x20a2,
5209 "Register FC-4 TYPE failed.\n");
5210 if (test_bit(LOOP_RESYNC_NEEDED
,
5214 if (qla2x00_rff_id(vha
, FC4_TYPE_FCP_SCSI
)) {
5216 ql_dbg(ql_dbg_disc
, vha
, 0x209a,
5217 "Register FC-4 Features failed.\n");
5218 if (test_bit(LOOP_RESYNC_NEEDED
,
5222 if (vha
->flags
.nvme_enabled
) {
5223 if (qla2x00_rff_id(vha
, FC_TYPE_NVME
)) {
5224 ql_dbg(ql_dbg_disc
, vha
, 0x2049,
5225 "Register NVME FC Type Features failed.\n");
5228 if (qla2x00_rnn_id(vha
)) {
5230 ql_dbg(ql_dbg_disc
, vha
, 0x2104,
5231 "Register Node Name failed.\n");
5232 if (test_bit(LOOP_RESYNC_NEEDED
,
5235 } else if (qla2x00_rsnn_nn(vha
)) {
5237 ql_dbg(ql_dbg_disc
, vha
, 0x209b,
5238 "Register Symbolic Node Name failed.\n");
5239 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5245 /* Mark the time right before querying FW for connected ports.
5246 * This process is long, asynchronous and by the time it's done,
5247 * collected information might not be accurate anymore. E.g.
5248 * disconnected port might have re-connected and a brand new
5249 * session has been created. In this case session's generation
5250 * will be newer than discovery_gen. */
5251 qlt_do_generation_tick(vha
, &discovery_gen
);
5253 if (USE_ASYNC_SCAN(ha
)) {
5255 rval
= qla24xx_async_gpnft(vha
, FC4_TYPE_FCP_SCSI
);
5257 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5259 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
5260 fcport
->scan_state
= QLA_FCPORT_SCAN
;
5262 rval
= qla2x00_find_all_fabric_devs(vha
);
5264 if (rval
!= QLA_SUCCESS
)
5268 if (!vha
->nvme_local_port
&& vha
->flags
.nvme_enabled
)
5269 qla_nvme_register_hba(vha
);
5272 ql_dbg(ql_dbg_disc
, vha
, 0x2068,
5273 "Configure fabric error exit rval=%d.\n", rval
);
5279 * qla2x00_find_all_fabric_devs
5282 * ha = adapter block pointer.
5283 * dev = database device entry pointer.
5292 qla2x00_find_all_fabric_devs(scsi_qla_host_t
*vha
)
5296 fc_port_t
*fcport
, *new_fcport
;
5301 int first_dev
, last_dev
;
5302 port_id_t wrap
= {}, nxt_d_id
;
5303 struct qla_hw_data
*ha
= vha
->hw
;
5304 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
5305 unsigned long flags
;
5309 /* Try GID_PT to get device list, else GAN. */
5311 ha
->swl
= kcalloc(ha
->max_fibre_devices
, sizeof(sw_info_t
),
5316 ql_dbg(ql_dbg_disc
, vha
, 0x209c,
5317 "GID_PT allocations failed, fallback on GA_NXT.\n");
5319 memset(swl
, 0, ha
->max_fibre_devices
* sizeof(sw_info_t
));
5320 if (qla2x00_gid_pt(vha
, swl
) != QLA_SUCCESS
) {
5322 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5324 } else if (qla2x00_gpn_id(vha
, swl
) != QLA_SUCCESS
) {
5326 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5328 } else if (qla2x00_gnn_id(vha
, swl
) != QLA_SUCCESS
) {
5330 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5332 } else if (qla2x00_gfpn_id(vha
, swl
) != QLA_SUCCESS
) {
5334 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5338 /* If other queries succeeded probe for FC-4 type */
5340 qla2x00_gff_id(vha
, swl
);
5341 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5347 /* Allocate temporary fcport for any new fcports discovered. */
5348 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5349 if (new_fcport
== NULL
) {
5350 ql_log(ql_log_warn
, vha
, 0x209d,
5351 "Failed to allocate memory for fcport.\n");
5352 return (QLA_MEMORY_ALLOC_FAILED
);
5354 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5355 /* Set start port ID scan at adapter ID. */
5359 /* Starting free loop ID. */
5360 loop_id
= ha
->min_external_loopid
;
5361 for (; loop_id
<= ha
->max_loop_id
; loop_id
++) {
5362 if (qla2x00_is_reserved_id(vha
, loop_id
))
5365 if (ha
->current_topology
== ISP_CFG_FL
&&
5366 (atomic_read(&vha
->loop_down_timer
) ||
5367 LOOP_TRANSITION(vha
))) {
5368 atomic_set(&vha
->loop_down_timer
, 0);
5369 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5370 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
5376 wrap
.b24
= new_fcport
->d_id
.b24
;
5378 new_fcport
->d_id
.b24
= swl
[swl_idx
].d_id
.b24
;
5379 memcpy(new_fcport
->node_name
,
5380 swl
[swl_idx
].node_name
, WWN_SIZE
);
5381 memcpy(new_fcport
->port_name
,
5382 swl
[swl_idx
].port_name
, WWN_SIZE
);
5383 memcpy(new_fcport
->fabric_port_name
,
5384 swl
[swl_idx
].fabric_port_name
, WWN_SIZE
);
5385 new_fcport
->fp_speed
= swl
[swl_idx
].fp_speed
;
5386 new_fcport
->fc4_type
= swl
[swl_idx
].fc4_type
;
5388 new_fcport
->nvme_flag
= 0;
5389 new_fcport
->fc4f_nvme
= 0;
5390 if (vha
->flags
.nvme_enabled
&&
5391 swl
[swl_idx
].fc4f_nvme
) {
5392 new_fcport
->fc4f_nvme
=
5393 swl
[swl_idx
].fc4f_nvme
;
5394 ql_log(ql_log_info
, vha
, 0x2131,
5395 "FOUND: NVME port %8phC as FC Type 28h\n",
5396 new_fcport
->port_name
);
5399 if (swl
[swl_idx
].d_id
.b
.rsvd_1
!= 0) {
5405 /* Send GA_NXT to the switch */
5406 rval
= qla2x00_ga_nxt(vha
, new_fcport
);
5407 if (rval
!= QLA_SUCCESS
) {
5408 ql_log(ql_log_warn
, vha
, 0x209e,
5409 "SNS scan failed -- assuming "
5410 "zero-entry result.\n");
5416 /* If wrap on switch device list, exit. */
5418 wrap
.b24
= new_fcport
->d_id
.b24
;
5420 } else if (new_fcport
->d_id
.b24
== wrap
.b24
) {
5421 ql_dbg(ql_dbg_disc
, vha
, 0x209f,
5422 "Device wrap (%02x%02x%02x).\n",
5423 new_fcport
->d_id
.b
.domain
,
5424 new_fcport
->d_id
.b
.area
,
5425 new_fcport
->d_id
.b
.al_pa
);
5429 /* Bypass if same physical adapter. */
5430 if (new_fcport
->d_id
.b24
== base_vha
->d_id
.b24
)
5433 /* Bypass virtual ports of the same host. */
5434 if (qla2x00_is_a_vp_did(vha
, new_fcport
->d_id
.b24
))
5437 /* Bypass if same domain and area of adapter. */
5438 if (((new_fcport
->d_id
.b24
& 0xffff00) ==
5439 (vha
->d_id
.b24
& 0xffff00)) && ha
->current_topology
==
5443 /* Bypass reserved domain fields. */
5444 if ((new_fcport
->d_id
.b
.domain
& 0xf0) == 0xf0)
5447 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5448 if (ql2xgffidenable
&&
5449 (new_fcport
->fc4_type
!= FC4_TYPE_FCP_SCSI
&&
5450 new_fcport
->fc4_type
!= FC4_TYPE_UNKNOWN
))
5453 spin_lock_irqsave(&vha
->hw
->tgt
.sess_lock
, flags
);
5455 /* Locate matching device in database. */
5457 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5458 if (memcmp(new_fcport
->port_name
, fcport
->port_name
,
5462 fcport
->scan_state
= QLA_FCPORT_FOUND
;
5466 /* Update port state. */
5467 memcpy(fcport
->fabric_port_name
,
5468 new_fcport
->fabric_port_name
, WWN_SIZE
);
5469 fcport
->fp_speed
= new_fcport
->fp_speed
;
5472 * If address the same and state FCS_ONLINE
5473 * (or in target mode), nothing changed.
5475 if (fcport
->d_id
.b24
== new_fcport
->d_id
.b24
&&
5476 (atomic_read(&fcport
->state
) == FCS_ONLINE
||
5477 (vha
->host
->active_mode
== MODE_TARGET
))) {
5482 * If device was not a fabric device before.
5484 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0) {
5485 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5486 qla2x00_clear_loop_id(fcport
);
5487 fcport
->flags
|= (FCF_FABRIC_DEVICE
|
5493 * Port ID changed or device was marked to be updated;
5494 * Log it out if still logged in and mark it for
5497 if (qla_tgt_mode_enabled(base_vha
)) {
5498 ql_dbg(ql_dbg_tgt_mgt
, vha
, 0xf080,
5499 "port changed FC ID, %8phC"
5500 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5502 fcport
->d_id
.b
.domain
,
5503 fcport
->d_id
.b
.area
,
5504 fcport
->d_id
.b
.al_pa
,
5506 new_fcport
->d_id
.b
.domain
,
5507 new_fcport
->d_id
.b
.area
,
5508 new_fcport
->d_id
.b
.al_pa
);
5509 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5513 fcport
->d_id
.b24
= new_fcport
->d_id
.b24
;
5514 fcport
->flags
|= FCF_LOGIN_NEEDED
;
5519 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5522 /* If device was not in our fcports list, then add it. */
5523 new_fcport
->scan_state
= QLA_FCPORT_FOUND
;
5524 list_add_tail(&new_fcport
->list
, &vha
->vp_fcports
);
5526 spin_unlock_irqrestore(&vha
->hw
->tgt
.sess_lock
, flags
);
5529 /* Allocate a new replacement fcport. */
5530 nxt_d_id
.b24
= new_fcport
->d_id
.b24
;
5531 new_fcport
= qla2x00_alloc_fcport(vha
, GFP_KERNEL
);
5532 if (new_fcport
== NULL
) {
5533 ql_log(ql_log_warn
, vha
, 0xd032,
5534 "Memory allocation failed for fcport.\n");
5535 return (QLA_MEMORY_ALLOC_FAILED
);
5537 new_fcport
->flags
|= (FCF_FABRIC_DEVICE
| FCF_LOGIN_NEEDED
);
5538 new_fcport
->d_id
.b24
= nxt_d_id
.b24
;
5541 qla2x00_free_fcport(new_fcport
);
5544 * Logout all previous fabric dev marked lost, except FCP2 devices.
5546 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5547 if (test_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
))
5550 if ((fcport
->flags
& FCF_FABRIC_DEVICE
) == 0 ||
5551 (fcport
->flags
& FCF_LOGIN_NEEDED
) == 0)
5554 if (fcport
->scan_state
== QLA_FCPORT_SCAN
) {
5555 if ((qla_dual_mode_enabled(vha
) ||
5556 qla_ini_mode_enabled(vha
)) &&
5557 atomic_read(&fcport
->state
) == FCS_ONLINE
) {
5558 qla2x00_mark_device_lost(vha
, fcport
,
5559 ql2xplogiabsentdevice
, 0);
5560 if (fcport
->loop_id
!= FC_NO_LOOP_ID
&&
5561 (fcport
->flags
& FCF_FCP2_DEVICE
) == 0 &&
5562 fcport
->port_type
!= FCT_INITIATOR
&&
5563 fcport
->port_type
!= FCT_BROADCAST
) {
5564 ql_dbg(ql_dbg_disc
, vha
, 0x20f0,
5565 "%s %d %8phC post del sess\n",
5568 qlt_schedule_sess_for_deletion(fcport
);
5574 if (fcport
->scan_state
== QLA_FCPORT_FOUND
)
5575 qla24xx_fcport_handle_login(vha
, fcport
);
5581 * qla2x00_find_new_loop_id
5582 * Scan through our port list and find a new usable loop ID.
5585 * ha: adapter state pointer.
5586 * dev: port structure pointer.
5589 * qla2x00 local function return status code.
5595 qla2x00_find_new_loop_id(scsi_qla_host_t
*vha
, fc_port_t
*dev
)
5598 struct qla_hw_data
*ha
= vha
->hw
;
5599 unsigned long flags
= 0;
5603 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5605 dev
->loop_id
= find_first_zero_bit(ha
->loop_id_map
,
5607 if (dev
->loop_id
>= LOOPID_MAP_SIZE
||
5608 qla2x00_is_reserved_id(vha
, dev
->loop_id
)) {
5609 dev
->loop_id
= FC_NO_LOOP_ID
;
5610 rval
= QLA_FUNCTION_FAILED
;
5612 set_bit(dev
->loop_id
, ha
->loop_id_map
);
5614 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5616 if (rval
== QLA_SUCCESS
)
5617 ql_dbg(ql_dbg_disc
, dev
->vha
, 0x2086,
5618 "Assigning new loopid=%x, portid=%x.\n",
5619 dev
->loop_id
, dev
->d_id
.b24
);
5621 ql_log(ql_log_warn
, dev
->vha
, 0x2087,
5622 "No loop_id's available, portid=%x.\n",
5630 * qla2x00_fabric_login
5631 * Issue fabric login command.
5634 * ha = adapter block pointer.
5635 * device = pointer to FC device type structure.
5638 * 0 - Login successfully
5640 * 2 - Initiator device
5644 qla2x00_fabric_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
,
5645 uint16_t *next_loopid
)
5649 uint16_t tmp_loopid
;
5650 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5651 struct qla_hw_data
*ha
= vha
->hw
;
5657 ql_dbg(ql_dbg_disc
, vha
, 0x2000,
5658 "Trying Fabric Login w/loop id 0x%04x for port "
5660 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5661 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5663 /* Login fcport on switch. */
5664 rval
= ha
->isp_ops
->fabric_login(vha
, fcport
->loop_id
,
5665 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5666 fcport
->d_id
.b
.al_pa
, mb
, BIT_0
);
5667 if (rval
!= QLA_SUCCESS
) {
5670 if (mb
[0] == MBS_PORT_ID_USED
) {
5672 * Device has another loop ID. The firmware team
5673 * recommends the driver perform an implicit login with
5674 * the specified ID again. The ID we just used is save
5675 * here so we return with an ID that can be tried by
5679 tmp_loopid
= fcport
->loop_id
;
5680 fcport
->loop_id
= mb
[1];
5682 ql_dbg(ql_dbg_disc
, vha
, 0x2001,
5683 "Fabric Login: port in use - next loop "
5684 "id=0x%04x, port id= %02x%02x%02x.\n",
5685 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
5686 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
5688 } else if (mb
[0] == MBS_COMMAND_COMPLETE
) {
5693 /* A retry occurred before. */
5694 *next_loopid
= tmp_loopid
;
5697 * No retry occurred before. Just increment the
5698 * ID value for next login.
5700 *next_loopid
= (fcport
->loop_id
+ 1);
5703 if (mb
[1] & BIT_0
) {
5704 fcport
->port_type
= FCT_INITIATOR
;
5706 fcport
->port_type
= FCT_TARGET
;
5707 if (mb
[1] & BIT_1
) {
5708 fcport
->flags
|= FCF_FCP2_DEVICE
;
5713 fcport
->supported_classes
|= FC_COS_CLASS2
;
5715 fcport
->supported_classes
|= FC_COS_CLASS3
;
5717 if (IS_FWI2_CAPABLE(ha
)) {
5720 FCF_CONF_COMP_SUPPORTED
;
5725 } else if (mb
[0] == MBS_LOOP_ID_USED
) {
5727 * Loop ID already used, try next loop ID.
5730 rval
= qla2x00_find_new_loop_id(vha
, fcport
);
5731 if (rval
!= QLA_SUCCESS
) {
5732 /* Ran out of loop IDs to use */
5735 } else if (mb
[0] == MBS_COMMAND_ERROR
) {
5737 * Firmware possibly timed out during login. If NO
5738 * retries are left to do then the device is declared
5741 *next_loopid
= fcport
->loop_id
;
5742 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5743 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5744 fcport
->d_id
.b
.al_pa
);
5745 qla2x00_mark_device_lost(vha
, fcport
, 1, 0);
5751 * unrecoverable / not handled error
5753 ql_dbg(ql_dbg_disc
, vha
, 0x2002,
5754 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5755 "jiffies=%lx.\n", mb
[0], fcport
->d_id
.b
.domain
,
5756 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
,
5757 fcport
->loop_id
, jiffies
);
5759 *next_loopid
= fcport
->loop_id
;
5760 ha
->isp_ops
->fabric_logout(vha
, fcport
->loop_id
,
5761 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
5762 fcport
->d_id
.b
.al_pa
);
5763 qla2x00_clear_loop_id(fcport
);
5764 fcport
->login_retry
= 0;
5775 * qla2x00_local_device_login
5776 * Issue local device login command.
5779 * ha = adapter block pointer.
5780 * loop_id = loop id of device to login to.
5782 * Returns (Where's the #define!!!!):
5783 * 0 - Login successfully
5788 qla2x00_local_device_login(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
5791 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
5793 memset(mb
, 0, sizeof(mb
));
5794 rval
= qla2x00_login_local_device(vha
, fcport
, mb
, BIT_0
);
5795 if (rval
== QLA_SUCCESS
) {
5796 /* Interrogate mailbox registers for any errors */
5797 if (mb
[0] == MBS_COMMAND_ERROR
)
5799 else if (mb
[0] == MBS_COMMAND_PARAMETER_ERROR
)
5800 /* device not in PCB table */
5808 * qla2x00_loop_resync
5809 * Resync with fibre channel devices.
5812 * ha = adapter block pointer.
5818 qla2x00_loop_resync(scsi_qla_host_t
*vha
)
5820 int rval
= QLA_SUCCESS
;
5822 struct req_que
*req
;
5823 struct rsp_que
*rsp
;
5828 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
5829 if (vha
->flags
.online
) {
5830 if (!(rval
= qla2x00_fw_ready(vha
))) {
5831 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5834 if (!IS_QLAFX00(vha
->hw
)) {
5836 * Issue a marker after FW becomes
5839 qla2x00_marker(vha
, req
, rsp
, 0, 0,
5841 vha
->marker_needed
= 0;
5844 /* Remap devices on Loop. */
5845 clear_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
5847 if (IS_QLAFX00(vha
->hw
))
5848 qlafx00_configure_devices(vha
);
5850 qla2x00_configure_loop(vha
);
5853 } while (!atomic_read(&vha
->loop_down_timer
) &&
5854 !(test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
5855 && wait_time
&& (test_bit(LOOP_RESYNC_NEEDED
,
5860 if (test_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
))
5861 return (QLA_FUNCTION_FAILED
);
5864 ql_dbg(ql_dbg_disc
, vha
, 0x206c,
5865 "%s *** FAILED ***.\n", __func__
);
5871 * qla2x00_perform_loop_resync
5872 * Description: This function will set the appropriate flags and call
5873 * qla2x00_loop_resync. If successful loop will be resynced
5874 * Arguments : scsi_qla_host_t pointer
5875 * returm : Success or Failure
5878 int qla2x00_perform_loop_resync(scsi_qla_host_t
*ha
)
5882 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
)) {
5883 /*Configure the flags so that resync happens properly*/
5884 atomic_set(&ha
->loop_down_timer
, 0);
5885 if (!(ha
->device_flags
& DFLG_NO_CABLE
)) {
5886 atomic_set(&ha
->loop_state
, LOOP_UP
);
5887 set_bit(LOCAL_LOOP_UPDATE
, &ha
->dpc_flags
);
5888 set_bit(REGISTER_FC4_NEEDED
, &ha
->dpc_flags
);
5889 set_bit(LOOP_RESYNC_NEEDED
, &ha
->dpc_flags
);
5891 rval
= qla2x00_loop_resync(ha
);
5893 atomic_set(&ha
->loop_state
, LOOP_DEAD
);
5895 clear_bit(LOOP_RESYNC_ACTIVE
, &ha
->dpc_flags
);
5902 qla2x00_update_fcports(scsi_qla_host_t
*base_vha
)
5905 struct scsi_qla_host
*vha
;
5906 struct qla_hw_data
*ha
= base_vha
->hw
;
5907 unsigned long flags
;
5909 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5910 /* Go with deferred removal of rport references. */
5911 list_for_each_entry(vha
, &base_vha
->hw
->vp_list
, list
) {
5912 atomic_inc(&vha
->vref_count
);
5913 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
) {
5914 if (fcport
->drport
&&
5915 atomic_read(&fcport
->state
) != FCS_UNCONFIGURED
) {
5916 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5917 qla2x00_rport_del(fcport
);
5919 spin_lock_irqsave(&ha
->vport_slock
, flags
);
5922 atomic_dec(&vha
->vref_count
);
5923 wake_up(&vha
->vref_waitq
);
5925 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
5928 /* Assumes idc_lock always held on entry */
5930 qla83xx_reset_ownership(scsi_qla_host_t
*vha
)
5932 struct qla_hw_data
*ha
= vha
->hw
;
5933 uint32_t drv_presence
, drv_presence_mask
;
5934 uint32_t dev_part_info1
, dev_part_info2
, class_type
;
5935 uint32_t class_type_mask
= 0x3;
5936 uint16_t fcoe_other_function
= 0xffff, i
;
5938 if (IS_QLA8044(ha
)) {
5939 drv_presence
= qla8044_rd_direct(vha
,
5940 QLA8044_CRB_DRV_ACTIVE_INDEX
);
5941 dev_part_info1
= qla8044_rd_direct(vha
,
5942 QLA8044_CRB_DEV_PART_INFO_INDEX
);
5943 dev_part_info2
= qla8044_rd_direct(vha
,
5944 QLA8044_CRB_DEV_PART_INFO2
);
5946 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
5947 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO1
, &dev_part_info1
);
5948 qla83xx_rd_reg(vha
, QLA83XX_DEV_PARTINFO2
, &dev_part_info2
);
5950 for (i
= 0; i
< 8; i
++) {
5951 class_type
= ((dev_part_info1
>> (i
* 4)) & class_type_mask
);
5952 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
5953 (i
!= ha
->portnum
)) {
5954 fcoe_other_function
= i
;
5958 if (fcoe_other_function
== 0xffff) {
5959 for (i
= 0; i
< 8; i
++) {
5960 class_type
= ((dev_part_info2
>> (i
* 4)) &
5962 if ((class_type
== QLA83XX_CLASS_TYPE_FCOE
) &&
5963 ((i
+ 8) != ha
->portnum
)) {
5964 fcoe_other_function
= i
+ 8;
5970 * Prepare drv-presence mask based on fcoe functions present.
5971 * However consider only valid physical fcoe function numbers (0-15).
5973 drv_presence_mask
= ~((1 << (ha
->portnum
)) |
5974 ((fcoe_other_function
== 0xffff) ?
5975 0 : (1 << (fcoe_other_function
))));
5977 /* We are the reset owner iff:
5978 * - No other protocol drivers present.
5979 * - This is the lowest among fcoe functions. */
5980 if (!(drv_presence
& drv_presence_mask
) &&
5981 (ha
->portnum
< fcoe_other_function
)) {
5982 ql_dbg(ql_dbg_p3p
, vha
, 0xb07f,
5983 "This host is Reset owner.\n");
5984 ha
->flags
.nic_core_reset_owner
= 1;
5989 __qla83xx_set_drv_ack(scsi_qla_host_t
*vha
)
5991 int rval
= QLA_SUCCESS
;
5992 struct qla_hw_data
*ha
= vha
->hw
;
5995 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
5996 if (rval
== QLA_SUCCESS
) {
5997 drv_ack
|= (1 << ha
->portnum
);
5998 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6005 __qla83xx_clear_drv_ack(scsi_qla_host_t
*vha
)
6007 int rval
= QLA_SUCCESS
;
6008 struct qla_hw_data
*ha
= vha
->hw
;
6011 rval
= qla83xx_rd_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, &drv_ack
);
6012 if (rval
== QLA_SUCCESS
) {
6013 drv_ack
&= ~(1 << ha
->portnum
);
6014 rval
= qla83xx_wr_reg(vha
, QLA83XX_IDC_DRIVER_ACK
, drv_ack
);
6021 qla83xx_dev_state_to_string(uint32_t dev_state
)
6023 switch (dev_state
) {
6024 case QLA8XXX_DEV_COLD
:
6025 return "COLD/RE-INIT";
6026 case QLA8XXX_DEV_INITIALIZING
:
6027 return "INITIALIZING";
6028 case QLA8XXX_DEV_READY
:
6030 case QLA8XXX_DEV_NEED_RESET
:
6031 return "NEED RESET";
6032 case QLA8XXX_DEV_NEED_QUIESCENT
:
6033 return "NEED QUIESCENT";
6034 case QLA8XXX_DEV_FAILED
:
6036 case QLA8XXX_DEV_QUIESCENT
:
6043 /* Assumes idc-lock always held on entry */
6045 qla83xx_idc_audit(scsi_qla_host_t
*vha
, int audit_type
)
6047 struct qla_hw_data
*ha
= vha
->hw
;
6048 uint32_t idc_audit_reg
= 0, duration_secs
= 0;
6050 switch (audit_type
) {
6051 case IDC_AUDIT_TIMESTAMP
:
6052 ha
->idc_audit_ts
= (jiffies_to_msecs(jiffies
) / 1000);
6053 idc_audit_reg
= (ha
->portnum
) |
6054 (IDC_AUDIT_TIMESTAMP
<< 7) | (ha
->idc_audit_ts
<< 8);
6055 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6058 case IDC_AUDIT_COMPLETION
:
6059 duration_secs
= ((jiffies_to_msecs(jiffies
) -
6060 jiffies_to_msecs(ha
->idc_audit_ts
)) / 1000);
6061 idc_audit_reg
= (ha
->portnum
) |
6062 (IDC_AUDIT_COMPLETION
<< 7) | (duration_secs
<< 8);
6063 qla83xx_wr_reg(vha
, QLA83XX_IDC_AUDIT
, idc_audit_reg
);
6067 ql_log(ql_log_warn
, vha
, 0xb078,
6068 "Invalid audit type specified.\n");
6073 /* Assumes idc_lock always held on entry */
6075 qla83xx_initiating_reset(scsi_qla_host_t
*vha
)
6077 struct qla_hw_data
*ha
= vha
->hw
;
6078 uint32_t idc_control
, dev_state
;
6080 __qla83xx_get_idc_control(vha
, &idc_control
);
6081 if ((idc_control
& QLA83XX_IDC_RESET_DISABLED
)) {
6082 ql_log(ql_log_info
, vha
, 0xb080,
6083 "NIC Core reset has been disabled. idc-control=0x%x\n",
6085 return QLA_FUNCTION_FAILED
;
6088 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6089 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6090 if (ha
->flags
.nic_core_reset_owner
&& dev_state
== QLA8XXX_DEV_READY
) {
6091 qla83xx_wr_reg(vha
, QLA83XX_IDC_DEV_STATE
,
6092 QLA8XXX_DEV_NEED_RESET
);
6093 ql_log(ql_log_info
, vha
, 0xb056, "HW State: NEED RESET.\n");
6094 qla83xx_idc_audit(vha
, IDC_AUDIT_TIMESTAMP
);
6096 const char *state
= qla83xx_dev_state_to_string(dev_state
);
6097 ql_log(ql_log_info
, vha
, 0xb057, "HW State: %s.\n", state
);
6099 /* SV: XXX: Is timeout required here? */
6100 /* Wait for IDC state change READY -> NEED_RESET */
6101 while (dev_state
== QLA8XXX_DEV_READY
) {
6102 qla83xx_idc_unlock(vha
, 0);
6104 qla83xx_idc_lock(vha
, 0);
6105 qla83xx_rd_reg(vha
, QLA83XX_IDC_DEV_STATE
, &dev_state
);
6109 /* Send IDC ack by writing to drv-ack register */
6110 __qla83xx_set_drv_ack(vha
);
6116 __qla83xx_set_idc_control(scsi_qla_host_t
*vha
, uint32_t idc_control
)
6118 return qla83xx_wr_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6122 __qla83xx_get_idc_control(scsi_qla_host_t
*vha
, uint32_t *idc_control
)
6124 return qla83xx_rd_reg(vha
, QLA83XX_IDC_CONTROL
, idc_control
);
6128 qla83xx_check_driver_presence(scsi_qla_host_t
*vha
)
6130 uint32_t drv_presence
= 0;
6131 struct qla_hw_data
*ha
= vha
->hw
;
6133 qla83xx_rd_reg(vha
, QLA83XX_IDC_DRV_PRESENCE
, &drv_presence
);
6134 if (drv_presence
& (1 << ha
->portnum
))
6137 return QLA_TEST_FAILED
;
6141 qla83xx_nic_core_reset(scsi_qla_host_t
*vha
)
6143 int rval
= QLA_SUCCESS
;
6144 struct qla_hw_data
*ha
= vha
->hw
;
6146 ql_dbg(ql_dbg_p3p
, vha
, 0xb058,
6147 "Entered %s().\n", __func__
);
6149 if (vha
->device_flags
& DFLG_DEV_FAILED
) {
6150 ql_log(ql_log_warn
, vha
, 0xb059,
6151 "Device in unrecoverable FAILED state.\n");
6152 return QLA_FUNCTION_FAILED
;
6155 qla83xx_idc_lock(vha
, 0);
6157 if (qla83xx_check_driver_presence(vha
) != QLA_SUCCESS
) {
6158 ql_log(ql_log_warn
, vha
, 0xb05a,
6159 "Function=0x%x has been removed from IDC participation.\n",
6161 rval
= QLA_FUNCTION_FAILED
;
6165 qla83xx_reset_ownership(vha
);
6167 rval
= qla83xx_initiating_reset(vha
);
6170 * Perform reset if we are the reset-owner,
6171 * else wait till IDC state changes to READY/FAILED.
6173 if (rval
== QLA_SUCCESS
) {
6174 rval
= qla83xx_idc_state_handler(vha
);
6176 if (rval
== QLA_SUCCESS
)
6177 ha
->flags
.nic_core_hung
= 0;
6178 __qla83xx_clear_drv_ack(vha
);
6182 qla83xx_idc_unlock(vha
, 0);
6184 ql_dbg(ql_dbg_p3p
, vha
, 0xb05b, "Exiting %s.\n", __func__
);
6190 qla2xxx_mctp_dump(scsi_qla_host_t
*vha
)
6192 struct qla_hw_data
*ha
= vha
->hw
;
6193 int rval
= QLA_FUNCTION_FAILED
;
6195 if (!IS_MCTP_CAPABLE(ha
)) {
6196 /* This message can be removed from the final version */
6197 ql_log(ql_log_info
, vha
, 0x506d,
6198 "This board is not MCTP capable\n");
6202 if (!ha
->mctp_dump
) {
6203 ha
->mctp_dump
= dma_alloc_coherent(&ha
->pdev
->dev
,
6204 MCTP_DUMP_SIZE
, &ha
->mctp_dump_dma
, GFP_KERNEL
);
6206 if (!ha
->mctp_dump
) {
6207 ql_log(ql_log_warn
, vha
, 0x506e,
6208 "Failed to allocate memory for mctp dump\n");
6213 #define MCTP_DUMP_STR_ADDR 0x00000000
6214 rval
= qla2x00_dump_mctp_data(vha
, ha
->mctp_dump_dma
,
6215 MCTP_DUMP_STR_ADDR
, MCTP_DUMP_SIZE
/4);
6216 if (rval
!= QLA_SUCCESS
) {
6217 ql_log(ql_log_warn
, vha
, 0x506f,
6218 "Failed to capture mctp dump\n");
6220 ql_log(ql_log_info
, vha
, 0x5070,
6221 "Mctp dump capture for host (%ld/%p).\n",
6222 vha
->host_no
, ha
->mctp_dump
);
6223 ha
->mctp_dumped
= 1;
6226 if (!ha
->flags
.nic_core_reset_hdlr_active
&& !ha
->portnum
) {
6227 ha
->flags
.nic_core_reset_hdlr_active
= 1;
6228 rval
= qla83xx_restart_nic_firmware(vha
);
6230 /* NIC Core reset failed. */
6231 ql_log(ql_log_warn
, vha
, 0x5071,
6232 "Failed to restart nic firmware\n");
6234 ql_dbg(ql_dbg_p3p
, vha
, 0xb084,
6235 "Restarted NIC firmware successfully.\n");
6236 ha
->flags
.nic_core_reset_hdlr_active
= 0;
6244 * qla2x00_quiesce_io
6245 * Description: This function will block the new I/Os
6246 * Its not aborting any I/Os as context
6247 * is not destroyed during quiescence
6248 * Arguments: scsi_qla_host_t
6252 qla2x00_quiesce_io(scsi_qla_host_t
*vha
)
6254 struct qla_hw_data
*ha
= vha
->hw
;
6255 struct scsi_qla_host
*vp
;
6257 ql_dbg(ql_dbg_dpc
, vha
, 0x401d,
6258 "Quiescing I/O - ha=%p.\n", ha
);
6260 atomic_set(&ha
->loop_down_timer
, LOOP_DOWN_TIME
);
6261 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6262 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6263 qla2x00_mark_all_devices_lost(vha
, 0);
6264 list_for_each_entry(vp
, &ha
->vp_list
, list
)
6265 qla2x00_mark_all_devices_lost(vp
, 0);
6267 if (!atomic_read(&vha
->loop_down_timer
))
6268 atomic_set(&vha
->loop_down_timer
,
6271 /* Wait for pending cmds to complete */
6272 qla2x00_eh_wait_for_pending_commands(vha
, 0, 0, WAIT_HOST
);
6276 qla2x00_abort_isp_cleanup(scsi_qla_host_t
*vha
)
6278 struct qla_hw_data
*ha
= vha
->hw
;
6279 struct scsi_qla_host
*vp
;
6280 unsigned long flags
;
6284 /* For ISP82XX, driver waits for completion of the commands.
6285 * online flag should be set.
6287 if (!(IS_P3P_TYPE(ha
)))
6288 vha
->flags
.online
= 0;
6289 ha
->flags
.chip_reset_done
= 0;
6290 clear_bit(ISP_ABORT_NEEDED
, &vha
->dpc_flags
);
6291 vha
->qla_stats
.total_isp_aborts
++;
6293 ql_log(ql_log_info
, vha
, 0x00af,
6294 "Performing ISP error recovery - ha=%p.\n", ha
);
6296 /* For ISP82XX, reset_chip is just disabling interrupts.
6297 * Driver waits for the completion of the commands.
6298 * the interrupts need to be enabled.
6300 if (!(IS_P3P_TYPE(ha
)))
6301 ha
->isp_ops
->reset_chip(vha
);
6304 ha
->flags
.rida_fmt2
= 0;
6305 ha
->flags
.n2n_ae
= 0;
6306 ha
->flags
.lip_ae
= 0;
6307 ha
->current_topology
= 0;
6308 ha
->flags
.fw_started
= 0;
6309 ha
->flags
.fw_init_done
= 0;
6310 ha
->base_qpair
->chip_reset
++;
6311 for (i
= 0; i
< ha
->max_qpairs
; i
++) {
6312 if (ha
->queue_pair_map
[i
])
6313 ha
->queue_pair_map
[i
]->chip_reset
=
6314 ha
->base_qpair
->chip_reset
;
6317 atomic_set(&vha
->loop_down_timer
, LOOP_DOWN_TIME
);
6318 if (atomic_read(&vha
->loop_state
) != LOOP_DOWN
) {
6319 atomic_set(&vha
->loop_state
, LOOP_DOWN
);
6320 qla2x00_mark_all_devices_lost(vha
, 0);
6322 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6323 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6324 atomic_inc(&vp
->vref_count
);
6325 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6327 qla2x00_mark_all_devices_lost(vp
, 0);
6329 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6330 atomic_dec(&vp
->vref_count
);
6332 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6334 if (!atomic_read(&vha
->loop_down_timer
))
6335 atomic_set(&vha
->loop_down_timer
,
6339 /* Clear all async request states across all VPs. */
6340 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
6341 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6342 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6343 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6344 atomic_inc(&vp
->vref_count
);
6345 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6347 list_for_each_entry(fcport
, &vp
->vp_fcports
, list
)
6348 fcport
->flags
&= ~(FCF_LOGIN_NEEDED
| FCF_ASYNC_SENT
);
6350 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6351 atomic_dec(&vp
->vref_count
);
6353 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6355 if (!ha
->flags
.eeh_busy
) {
6356 /* Make sure for ISP 82XX IO DMA is complete */
6357 if (IS_P3P_TYPE(ha
)) {
6358 qla82xx_chip_reset_cleanup(vha
);
6359 ql_log(ql_log_info
, vha
, 0x00b4,
6360 "Done chip reset cleanup.\n");
6362 /* Done waiting for pending commands.
6363 * Reset the online flag.
6365 vha
->flags
.online
= 0;
6368 /* Requeue all commands in outstanding command list. */
6369 qla2x00_abort_all_cmds(vha
, DID_RESET
<< 16);
6371 /* memory barrier */
6377 * Resets ISP and aborts all outstanding commands.
6380 * ha = adapter block pointer.
6386 qla2x00_abort_isp(scsi_qla_host_t
*vha
)
6390 struct qla_hw_data
*ha
= vha
->hw
;
6391 struct scsi_qla_host
*vp
;
6392 struct req_que
*req
= ha
->req_q_map
[0];
6393 unsigned long flags
;
6395 if (vha
->flags
.online
) {
6396 qla2x00_abort_isp_cleanup(vha
);
6398 if (IS_QLA8031(ha
)) {
6399 ql_dbg(ql_dbg_p3p
, vha
, 0xb05c,
6400 "Clearing fcoe driver presence.\n");
6401 if (qla83xx_clear_drv_presence(vha
) != QLA_SUCCESS
)
6402 ql_dbg(ql_dbg_p3p
, vha
, 0xb073,
6403 "Error while clearing DRV-Presence.\n");
6406 if (unlikely(pci_channel_offline(ha
->pdev
) &&
6407 ha
->flags
.pci_channel_io_perm_failure
)) {
6408 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6413 ha
->isp_ops
->get_flash_version(vha
, req
->ring
);
6415 ha
->isp_ops
->nvram_config(vha
);
6417 if (!qla2x00_restart_isp(vha
)) {
6418 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6420 if (!atomic_read(&vha
->loop_down_timer
)) {
6422 * Issue marker command only when we are going
6423 * to start the I/O .
6425 vha
->marker_needed
= 1;
6428 vha
->flags
.online
= 1;
6430 ha
->isp_ops
->enable_intrs(ha
);
6432 ha
->isp_abort_cnt
= 0;
6433 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6435 if (IS_QLA81XX(ha
) || IS_QLA8031(ha
))
6436 qla2x00_get_fw_version(vha
);
6438 ha
->flags
.fce_enabled
= 1;
6440 fce_calc_size(ha
->fce_bufs
));
6441 rval
= qla2x00_enable_fce_trace(vha
,
6442 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
6445 ql_log(ql_log_warn
, vha
, 0x8033,
6446 "Unable to reinitialize FCE "
6448 ha
->flags
.fce_enabled
= 0;
6453 memset(ha
->eft
, 0, EFT_SIZE
);
6454 rval
= qla2x00_enable_eft_trace(vha
,
6455 ha
->eft_dma
, EFT_NUM_BUFFERS
);
6457 ql_log(ql_log_warn
, vha
, 0x8034,
6458 "Unable to reinitialize EFT "
6462 } else { /* failed the ISP abort */
6463 vha
->flags
.online
= 1;
6464 if (test_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
)) {
6465 if (ha
->isp_abort_cnt
== 0) {
6466 ql_log(ql_log_fatal
, vha
, 0x8035,
6467 "ISP error recover failed - "
6468 "board disabled.\n");
6470 * The next call disables the board
6473 ha
->isp_ops
->reset_adapter(vha
);
6474 vha
->flags
.online
= 0;
6475 clear_bit(ISP_ABORT_RETRY
,
6478 } else { /* schedule another ISP abort */
6479 ha
->isp_abort_cnt
--;
6480 ql_dbg(ql_dbg_taskm
, vha
, 0x8020,
6481 "ISP abort - retry remaining %d.\n",
6486 ha
->isp_abort_cnt
= MAX_RETRIES_OF_ISP_ABORT
;
6487 ql_dbg(ql_dbg_taskm
, vha
, 0x8021,
6488 "ISP error recovery - retrying (%d) "
6489 "more times.\n", ha
->isp_abort_cnt
);
6490 set_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
6498 ql_dbg(ql_dbg_taskm
, vha
, 0x8022, "%s succeeded.\n", __func__
);
6499 qla2x00_configure_hba(vha
);
6500 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6501 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
6503 atomic_inc(&vp
->vref_count
);
6504 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6506 qla2x00_vp_abort_isp(vp
);
6508 spin_lock_irqsave(&ha
->vport_slock
, flags
);
6509 atomic_dec(&vp
->vref_count
);
6512 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
6514 if (IS_QLA8031(ha
)) {
6515 ql_dbg(ql_dbg_p3p
, vha
, 0xb05d,
6516 "Setting back fcoe driver presence.\n");
6517 if (qla83xx_set_drv_presence(vha
) != QLA_SUCCESS
)
6518 ql_dbg(ql_dbg_p3p
, vha
, 0xb074,
6519 "Error while setting DRV-Presence.\n");
6522 ql_log(ql_log_warn
, vha
, 0x8023, "%s **** FAILED ****.\n",
6530 * qla2x00_restart_isp
6531 * restarts the ISP after a reset
6534 * ha = adapter block pointer.
6540 qla2x00_restart_isp(scsi_qla_host_t
*vha
)
6543 struct qla_hw_data
*ha
= vha
->hw
;
6544 struct req_que
*req
= ha
->req_q_map
[0];
6545 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
6547 /* If firmware needs to be loaded */
6548 if (qla2x00_isp_firmware(vha
)) {
6549 vha
->flags
.online
= 0;
6550 status
= ha
->isp_ops
->chip_diag(vha
);
6552 status
= qla2x00_setup_chip(vha
);
6555 if (!status
&& !(status
= qla2x00_init_rings(vha
))) {
6556 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
6557 ha
->flags
.chip_reset_done
= 1;
6559 /* Initialize the queues in use */
6560 qla25xx_init_queues(ha
);
6562 status
= qla2x00_fw_ready(vha
);
6564 /* Issue a marker after FW becomes ready. */
6565 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
6566 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
6569 /* if no cable then assume it's good */
6570 if ((vha
->device_flags
& DFLG_NO_CABLE
))
6577 qla25xx_init_queues(struct qla_hw_data
*ha
)
6579 struct rsp_que
*rsp
= NULL
;
6580 struct req_que
*req
= NULL
;
6581 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
6585 for (i
= 1; i
< ha
->max_rsp_queues
; i
++) {
6586 rsp
= ha
->rsp_q_map
[i
];
6587 if (rsp
&& test_bit(i
, ha
->rsp_qid_map
)) {
6588 rsp
->options
&= ~BIT_0
;
6589 ret
= qla25xx_init_rsp_que(base_vha
, rsp
);
6590 if (ret
!= QLA_SUCCESS
)
6591 ql_dbg(ql_dbg_init
, base_vha
, 0x00ff,
6592 "%s Rsp que: %d init failed.\n",
6595 ql_dbg(ql_dbg_init
, base_vha
, 0x0100,
6596 "%s Rsp que: %d inited.\n",
6600 for (i
= 1; i
< ha
->max_req_queues
; i
++) {
6601 req
= ha
->req_q_map
[i
];
6602 if (req
&& test_bit(i
, ha
->req_qid_map
)) {
6603 /* Clear outstanding commands array. */
6604 req
->options
&= ~BIT_0
;
6605 ret
= qla25xx_init_req_que(base_vha
, req
);
6606 if (ret
!= QLA_SUCCESS
)
6607 ql_dbg(ql_dbg_init
, base_vha
, 0x0101,
6608 "%s Req que: %d init failed.\n",
6611 ql_dbg(ql_dbg_init
, base_vha
, 0x0102,
6612 "%s Req que: %d inited.\n",
6620 * qla2x00_reset_adapter
6624 * ha = adapter block pointer.
6627 qla2x00_reset_adapter(scsi_qla_host_t
*vha
)
6629 unsigned long flags
= 0;
6630 struct qla_hw_data
*ha
= vha
->hw
;
6631 struct device_reg_2xxx __iomem
*reg
= &ha
->iobase
->isp
;
6633 vha
->flags
.online
= 0;
6634 ha
->isp_ops
->disable_intrs(ha
);
6636 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6637 WRT_REG_WORD(®
->hccr
, HCCR_RESET_RISC
);
6638 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6639 WRT_REG_WORD(®
->hccr
, HCCR_RELEASE_RISC
);
6640 RD_REG_WORD(®
->hccr
); /* PCI Posting. */
6641 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6645 qla24xx_reset_adapter(scsi_qla_host_t
*vha
)
6647 unsigned long flags
= 0;
6648 struct qla_hw_data
*ha
= vha
->hw
;
6649 struct device_reg_24xx __iomem
*reg
= &ha
->iobase
->isp24
;
6651 if (IS_P3P_TYPE(ha
))
6654 vha
->flags
.online
= 0;
6655 ha
->isp_ops
->disable_intrs(ha
);
6657 spin_lock_irqsave(&ha
->hardware_lock
, flags
);
6658 WRT_REG_DWORD(®
->hccr
, HCCRX_SET_RISC_RESET
);
6659 RD_REG_DWORD(®
->hccr
);
6660 WRT_REG_DWORD(®
->hccr
, HCCRX_REL_RISC_PAUSE
);
6661 RD_REG_DWORD(®
->hccr
);
6662 spin_unlock_irqrestore(&ha
->hardware_lock
, flags
);
6664 if (IS_NOPOLLING_TYPE(ha
))
6665 ha
->isp_ops
->enable_intrs(ha
);
6668 /* On sparc systems, obtain port and node WWN from firmware
6671 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t
*vha
,
6672 struct nvram_24xx
*nv
)
6675 struct qla_hw_data
*ha
= vha
->hw
;
6676 struct pci_dev
*pdev
= ha
->pdev
;
6677 struct device_node
*dp
= pci_device_to_OF_node(pdev
);
6681 val
= of_get_property(dp
, "port-wwn", &len
);
6682 if (val
&& len
>= WWN_SIZE
)
6683 memcpy(nv
->port_name
, val
, WWN_SIZE
);
6685 val
= of_get_property(dp
, "node-wwn", &len
);
6686 if (val
&& len
>= WWN_SIZE
)
6687 memcpy(nv
->node_name
, val
, WWN_SIZE
);
6692 qla24xx_nvram_config(scsi_qla_host_t
*vha
)
6695 struct init_cb_24xx
*icb
;
6696 struct nvram_24xx
*nv
;
6698 uint8_t *dptr1
, *dptr2
;
6701 struct qla_hw_data
*ha
= vha
->hw
;
6704 icb
= (struct init_cb_24xx
*)ha
->init_cb
;
6707 /* Determine NVRAM starting address. */
6708 if (ha
->port_no
== 0) {
6709 ha
->nvram_base
= FA_NVRAM_FUNC0_ADDR
;
6710 ha
->vpd_base
= FA_NVRAM_VPD0_ADDR
;
6712 ha
->nvram_base
= FA_NVRAM_FUNC1_ADDR
;
6713 ha
->vpd_base
= FA_NVRAM_VPD1_ADDR
;
6716 ha
->nvram_size
= sizeof(struct nvram_24xx
);
6717 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
6719 /* Get VPD data into cache */
6720 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
6721 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)ha
->vpd
,
6722 ha
->nvram_base
- FA_NVRAM_FUNC0_ADDR
, FA_NVRAM_VPD_SIZE
* 4);
6724 /* Get NVRAM data into cache and calculate checksum. */
6725 dptr
= (uint32_t *)nv
;
6726 ha
->isp_ops
->read_nvram(vha
, (uint8_t *)dptr
, ha
->nvram_base
,
6728 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
6729 chksum
+= le32_to_cpu(*dptr
);
6731 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x006a,
6732 "Contents of NVRAM\n");
6733 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x010d,
6734 (uint8_t *)nv
, ha
->nvram_size
);
6736 /* Bad NVRAM data, set defaults parameters. */
6737 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
6738 || nv
->id
[3] != ' ' ||
6739 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
6740 /* Reset NVRAM data. */
6741 ql_log(ql_log_warn
, vha
, 0x006b,
6742 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6743 "version=0x%x.\n", chksum
, nv
->id
[0], nv
->nvram_version
);
6744 ql_log(ql_log_warn
, vha
, 0x006c,
6745 "Falling back to functioning (yet invalid -- WWPN) "
6749 * Set default initialization control block.
6751 memset(nv
, 0, ha
->nvram_size
);
6752 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
6753 nv
->version
= cpu_to_le16(ICB_VERSION
);
6754 nv
->frame_payload_size
= 2048;
6755 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
6756 nv
->exchange_count
= cpu_to_le16(0);
6757 nv
->hard_address
= cpu_to_le16(124);
6758 nv
->port_name
[0] = 0x21;
6759 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
6760 nv
->port_name
[2] = 0x00;
6761 nv
->port_name
[3] = 0xe0;
6762 nv
->port_name
[4] = 0x8b;
6763 nv
->port_name
[5] = 0x1c;
6764 nv
->port_name
[6] = 0x55;
6765 nv
->port_name
[7] = 0x86;
6766 nv
->node_name
[0] = 0x20;
6767 nv
->node_name
[1] = 0x00;
6768 nv
->node_name
[2] = 0x00;
6769 nv
->node_name
[3] = 0xe0;
6770 nv
->node_name
[4] = 0x8b;
6771 nv
->node_name
[5] = 0x1c;
6772 nv
->node_name
[6] = 0x55;
6773 nv
->node_name
[7] = 0x86;
6774 qla24xx_nvram_wwn_from_ofw(vha
, nv
);
6775 nv
->login_retry_count
= cpu_to_le16(8);
6776 nv
->interrupt_delay_timer
= cpu_to_le16(0);
6777 nv
->login_timeout
= cpu_to_le16(0);
6778 nv
->firmware_options_1
=
6779 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
6780 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
6781 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
6782 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
6783 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
6784 nv
->efi_parameters
= cpu_to_le32(0);
6785 nv
->reset_delay
= 5;
6786 nv
->max_luns_per_target
= cpu_to_le16(128);
6787 nv
->port_down_retry_count
= cpu_to_le16(30);
6788 nv
->link_down_timeout
= cpu_to_le16(30);
6793 if (qla_tgt_mode_enabled(vha
)) {
6794 /* Don't enable full login after initial LIP */
6795 nv
->firmware_options_1
&= cpu_to_le32(~BIT_13
);
6796 /* Don't enable LIP full login for initiator */
6797 nv
->host_p
&= cpu_to_le32(~BIT_10
);
6800 qlt_24xx_config_nvram_stage1(vha
, nv
);
6802 /* Reset Initialization control block */
6803 memset(icb
, 0, ha
->init_cb_size
);
6805 /* Copy 1st segment. */
6806 dptr1
= (uint8_t *)icb
;
6807 dptr2
= (uint8_t *)&nv
->version
;
6808 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
6810 *dptr1
++ = *dptr2
++;
6812 icb
->login_retry_count
= nv
->login_retry_count
;
6813 icb
->link_down_on_nos
= nv
->link_down_on_nos
;
6815 /* Copy 2nd segment. */
6816 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
6817 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
6818 cnt
= (uint8_t *)&icb
->reserved_3
-
6819 (uint8_t *)&icb
->interrupt_delay_timer
;
6821 *dptr1
++ = *dptr2
++;
6824 * Setup driver NVRAM options.
6826 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
6829 qlt_24xx_config_nvram_stage2(vha
, icb
);
6831 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
6832 /* Use alternate WWN? */
6833 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
6834 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
6837 /* Prepare nodename */
6838 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
6840 * Firmware will apply the following mask if the nodename was
6843 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
6844 icb
->node_name
[0] &= 0xF0;
6847 /* Set host adapter parameters. */
6848 ha
->flags
.disable_risc_code_load
= 0;
6849 ha
->flags
.enable_lip_reset
= 0;
6850 ha
->flags
.enable_lip_full_login
=
6851 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
6852 ha
->flags
.enable_target_reset
=
6853 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
6854 ha
->flags
.enable_led_scheme
= 0;
6855 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
6857 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
6858 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
6860 memcpy(ha
->fw_seriallink_options24
, nv
->seriallink_options
,
6861 sizeof(ha
->fw_seriallink_options24
));
6863 /* save HBA serial number */
6864 ha
->serial0
= icb
->port_name
[5];
6865 ha
->serial1
= icb
->port_name
[6];
6866 ha
->serial2
= icb
->port_name
[7];
6867 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
6868 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
6870 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
6872 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
6874 /* Set minimum login_timeout to 4 seconds. */
6875 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
6876 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
6877 if (le16_to_cpu(nv
->login_timeout
) < 4)
6878 nv
->login_timeout
= cpu_to_le16(4);
6879 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
6881 /* Set minimum RATOV to 100 tenths of a second. */
6884 ha
->loop_reset_delay
= nv
->reset_delay
;
6886 /* Link Down Timeout = 0:
6888 * When Port Down timer expires we will start returning
6889 * I/O's to OS with "DID_NO_CONNECT".
6891 * Link Down Timeout != 0:
6893 * The driver waits for the link to come up after link down
6894 * before returning I/Os to OS with "DID_NO_CONNECT".
6896 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
6897 ha
->loop_down_abort_time
=
6898 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
6900 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
6901 ha
->loop_down_abort_time
=
6902 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
6905 /* Need enough time to try and get the port back. */
6906 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
6907 if (qlport_down_retry
)
6908 ha
->port_down_retry_count
= qlport_down_retry
;
6910 /* Set login_retry_count */
6911 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
6912 if (ha
->port_down_retry_count
==
6913 le16_to_cpu(nv
->port_down_retry_count
) &&
6914 ha
->port_down_retry_count
> 3)
6915 ha
->login_retry_count
= ha
->port_down_retry_count
;
6916 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
6917 ha
->login_retry_count
= ha
->port_down_retry_count
;
6918 if (ql2xloginretrycount
)
6919 ha
->login_retry_count
= ql2xloginretrycount
;
6922 if (!vha
->flags
.init_done
) {
6923 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
6924 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
6925 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
6926 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
6928 icb
->firmware_options_2
&= cpu_to_le32(
6929 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
6930 vha
->flags
.process_response_queue
= 0;
6931 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
6932 ha
->zio_mode
= QLA_ZIO_MODE_6
;
6934 ql_log(ql_log_info
, vha
, 0x006f,
6935 "ZIO mode %d enabled; timer delay (%d us).\n",
6936 ha
->zio_mode
, ha
->zio_timer
* 100);
6938 icb
->firmware_options_2
|= cpu_to_le32(
6939 (uint32_t)ha
->zio_mode
);
6940 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
6941 vha
->flags
.process_response_queue
= 1;
6945 ql_log(ql_log_warn
, vha
, 0x0070,
6946 "NVRAM configuration failed.\n");
6951 uint8_t qla27xx_find_valid_image(struct scsi_qla_host
*vha
)
6953 struct qla27xx_image_status pri_image_status
, sec_image_status
;
6954 uint8_t valid_pri_image
, valid_sec_image
;
6956 uint32_t cnt
, chksum
, size
;
6957 struct qla_hw_data
*ha
= vha
->hw
;
6959 valid_pri_image
= valid_sec_image
= 1;
6960 ha
->active_image
= 0;
6961 size
= sizeof(struct qla27xx_image_status
) / sizeof(uint32_t);
6963 if (!ha
->flt_region_img_status_pri
) {
6964 valid_pri_image
= 0;
6965 goto check_sec_image
;
6968 qla24xx_read_flash_data(vha
, (uint32_t *)(&pri_image_status
),
6969 ha
->flt_region_img_status_pri
, size
);
6971 if (pri_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
6972 ql_dbg(ql_dbg_init
, vha
, 0x018b,
6973 "Primary image signature (0x%x) not valid\n",
6974 pri_image_status
.signature
);
6975 valid_pri_image
= 0;
6976 goto check_sec_image
;
6979 wptr
= (uint32_t *)(&pri_image_status
);
6982 for (chksum
= 0; cnt
--; wptr
++)
6983 chksum
+= le32_to_cpu(*wptr
);
6986 ql_dbg(ql_dbg_init
, vha
, 0x018c,
6987 "Checksum validation failed for primary image (0x%x)\n",
6989 valid_pri_image
= 0;
6993 if (!ha
->flt_region_img_status_sec
) {
6994 valid_sec_image
= 0;
6995 goto check_valid_image
;
6998 qla24xx_read_flash_data(vha
, (uint32_t *)(&sec_image_status
),
6999 ha
->flt_region_img_status_sec
, size
);
7001 if (sec_image_status
.signature
!= QLA27XX_IMG_STATUS_SIGN
) {
7002 ql_dbg(ql_dbg_init
, vha
, 0x018d,
7003 "Secondary image signature(0x%x) not valid\n",
7004 sec_image_status
.signature
);
7005 valid_sec_image
= 0;
7006 goto check_valid_image
;
7009 wptr
= (uint32_t *)(&sec_image_status
);
7011 for (chksum
= 0; cnt
--; wptr
++)
7012 chksum
+= le32_to_cpu(*wptr
);
7014 ql_dbg(ql_dbg_init
, vha
, 0x018e,
7015 "Checksum validation failed for secondary image (0x%x)\n",
7017 valid_sec_image
= 0;
7021 if (valid_pri_image
&& (pri_image_status
.image_status_mask
& 0x1))
7022 ha
->active_image
= QLA27XX_PRIMARY_IMAGE
;
7023 if (valid_sec_image
&& (sec_image_status
.image_status_mask
& 0x1)) {
7024 if (!ha
->active_image
||
7025 pri_image_status
.generation_number
<
7026 sec_image_status
.generation_number
)
7027 ha
->active_image
= QLA27XX_SECONDARY_IMAGE
;
7030 ql_dbg(ql_dbg_init
, vha
, 0x018f, "%s image\n",
7031 ha
->active_image
== 0 ? "default bootld and fw" :
7032 ha
->active_image
== 1 ? "primary" :
7033 ha
->active_image
== 2 ? "secondary" :
7036 return ha
->active_image
;
7040 qla24xx_load_risc_flash(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
,
7043 int rval
= QLA_SUCCESS
;
7044 int segments
, fragment
;
7045 uint32_t *dcode
, dlen
;
7049 struct qla_hw_data
*ha
= vha
->hw
;
7050 struct req_que
*req
= ha
->req_q_map
[0];
7052 ql_dbg(ql_dbg_init
, vha
, 0x008b,
7053 "FW: Loading firmware from flash (%x).\n", faddr
);
7057 segments
= FA_RISC_CODE_SEGMENTS
;
7058 dcode
= (uint32_t *)req
->ring
;
7061 if (IS_QLA27XX(ha
) &&
7062 qla27xx_find_valid_image(vha
) == QLA27XX_SECONDARY_IMAGE
)
7063 faddr
= ha
->flt_region_fw_sec
;
7065 /* Validate firmware image by checking version. */
7066 qla24xx_read_flash_data(vha
, dcode
, faddr
+ 4, 4);
7067 for (i
= 0; i
< 4; i
++)
7068 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7069 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7070 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7071 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7073 ql_log(ql_log_fatal
, vha
, 0x008c,
7074 "Unable to verify the integrity of flash firmware "
7076 ql_log(ql_log_fatal
, vha
, 0x008d,
7077 "Firmware data: %08x %08x %08x %08x.\n",
7078 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7080 return QLA_FUNCTION_FAILED
;
7083 while (segments
&& rval
== QLA_SUCCESS
) {
7084 /* Read segment's load information. */
7085 qla24xx_read_flash_data(vha
, dcode
, faddr
, 4);
7087 risc_addr
= be32_to_cpu(dcode
[2]);
7088 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7089 risc_size
= be32_to_cpu(dcode
[3]);
7092 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7093 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7094 if (dlen
> risc_size
)
7097 ql_dbg(ql_dbg_init
, vha
, 0x008e,
7098 "Loading risc segment@ risc addr %x "
7099 "number of dwords 0x%x offset 0x%x.\n",
7100 risc_addr
, dlen
, faddr
);
7102 qla24xx_read_flash_data(vha
, dcode
, faddr
, dlen
);
7103 for (i
= 0; i
< dlen
; i
++)
7104 dcode
[i
] = swab32(dcode
[i
]);
7106 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7109 ql_log(ql_log_fatal
, vha
, 0x008f,
7110 "Failed to load segment %d of firmware.\n",
7112 return QLA_FUNCTION_FAILED
;
7125 if (!IS_QLA27XX(ha
))
7128 if (ha
->fw_dump_template
)
7129 vfree(ha
->fw_dump_template
);
7130 ha
->fw_dump_template
= NULL
;
7131 ha
->fw_dump_template_len
= 0;
7133 ql_dbg(ql_dbg_init
, vha
, 0x0161,
7134 "Loading fwdump template from %x\n", faddr
);
7135 qla24xx_read_flash_data(vha
, dcode
, faddr
, 7);
7136 risc_size
= be32_to_cpu(dcode
[2]);
7137 ql_dbg(ql_dbg_init
, vha
, 0x0162,
7138 "-> array size %x dwords\n", risc_size
);
7139 if (risc_size
== 0 || risc_size
== ~0)
7140 goto default_template
;
7142 dlen
= (risc_size
- 8) * sizeof(*dcode
);
7143 ql_dbg(ql_dbg_init
, vha
, 0x0163,
7144 "-> template allocating %x bytes...\n", dlen
);
7145 ha
->fw_dump_template
= vmalloc(dlen
);
7146 if (!ha
->fw_dump_template
) {
7147 ql_log(ql_log_warn
, vha
, 0x0164,
7148 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7149 goto default_template
;
7154 dcode
= ha
->fw_dump_template
;
7155 qla24xx_read_flash_data(vha
, dcode
, faddr
, risc_size
);
7156 for (i
= 0; i
< risc_size
; i
++)
7157 dcode
[i
] = le32_to_cpu(dcode
[i
]);
7159 if (!qla27xx_fwdt_template_valid(dcode
)) {
7160 ql_log(ql_log_warn
, vha
, 0x0165,
7161 "Failed fwdump template validate\n");
7162 goto default_template
;
7165 dlen
= qla27xx_fwdt_template_size(dcode
);
7166 ql_dbg(ql_dbg_init
, vha
, 0x0166,
7167 "-> template size %x bytes\n", dlen
);
7168 if (dlen
> risc_size
* sizeof(*dcode
)) {
7169 ql_log(ql_log_warn
, vha
, 0x0167,
7170 "Failed fwdump template exceeds array by %zx bytes\n",
7171 (size_t)(dlen
- risc_size
* sizeof(*dcode
)));
7172 goto default_template
;
7174 ha
->fw_dump_template_len
= dlen
;
7178 ql_log(ql_log_warn
, vha
, 0x0168, "Using default fwdump template\n");
7179 if (ha
->fw_dump_template
)
7180 vfree(ha
->fw_dump_template
);
7181 ha
->fw_dump_template
= NULL
;
7182 ha
->fw_dump_template_len
= 0;
7184 dlen
= qla27xx_fwdt_template_default_size();
7185 ql_dbg(ql_dbg_init
, vha
, 0x0169,
7186 "-> template allocating %x bytes...\n", dlen
);
7187 ha
->fw_dump_template
= vmalloc(dlen
);
7188 if (!ha
->fw_dump_template
) {
7189 ql_log(ql_log_warn
, vha
, 0x016a,
7190 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7191 goto failed_template
;
7194 dcode
= ha
->fw_dump_template
;
7195 risc_size
= dlen
/ sizeof(*dcode
);
7196 memcpy(dcode
, qla27xx_fwdt_template_default(), dlen
);
7197 for (i
= 0; i
< risc_size
; i
++)
7198 dcode
[i
] = be32_to_cpu(dcode
[i
]);
7200 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7201 ql_log(ql_log_warn
, vha
, 0x016b,
7202 "Failed fwdump template validate\n");
7203 goto failed_template
;
7206 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7207 ql_dbg(ql_dbg_init
, vha
, 0x016c,
7208 "-> template size %x bytes\n", dlen
);
7209 ha
->fw_dump_template_len
= dlen
;
7213 ql_log(ql_log_warn
, vha
, 0x016d, "Failed default fwdump template\n");
7214 if (ha
->fw_dump_template
)
7215 vfree(ha
->fw_dump_template
);
7216 ha
->fw_dump_template
= NULL
;
7217 ha
->fw_dump_template_len
= 0;
7221 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7224 qla2x00_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7228 uint16_t *wcode
, *fwcode
;
7229 uint32_t risc_addr
, risc_size
, fwclen
, wlen
, *seg
;
7230 struct fw_blob
*blob
;
7231 struct qla_hw_data
*ha
= vha
->hw
;
7232 struct req_que
*req
= ha
->req_q_map
[0];
7234 /* Load firmware blob. */
7235 blob
= qla2x00_request_firmware(vha
);
7237 ql_log(ql_log_info
, vha
, 0x0083,
7238 "Firmware image unavailable.\n");
7239 ql_log(ql_log_info
, vha
, 0x0084,
7240 "Firmware images can be retrieved from: "QLA_FW_URL
".\n");
7241 return QLA_FUNCTION_FAILED
;
7246 wcode
= (uint16_t *)req
->ring
;
7248 fwcode
= (uint16_t *)blob
->fw
->data
;
7251 /* Validate firmware image by checking version. */
7252 if (blob
->fw
->size
< 8 * sizeof(uint16_t)) {
7253 ql_log(ql_log_fatal
, vha
, 0x0085,
7254 "Unable to verify integrity of firmware image (%zd).\n",
7256 goto fail_fw_integrity
;
7258 for (i
= 0; i
< 4; i
++)
7259 wcode
[i
] = be16_to_cpu(fwcode
[i
+ 4]);
7260 if ((wcode
[0] == 0xffff && wcode
[1] == 0xffff && wcode
[2] == 0xffff &&
7261 wcode
[3] == 0xffff) || (wcode
[0] == 0 && wcode
[1] == 0 &&
7262 wcode
[2] == 0 && wcode
[3] == 0)) {
7263 ql_log(ql_log_fatal
, vha
, 0x0086,
7264 "Unable to verify integrity of firmware image.\n");
7265 ql_log(ql_log_fatal
, vha
, 0x0087,
7266 "Firmware data: %04x %04x %04x %04x.\n",
7267 wcode
[0], wcode
[1], wcode
[2], wcode
[3]);
7268 goto fail_fw_integrity
;
7272 while (*seg
&& rval
== QLA_SUCCESS
) {
7274 *srisc_addr
= *srisc_addr
== 0 ? *seg
: *srisc_addr
;
7275 risc_size
= be16_to_cpu(fwcode
[3]);
7277 /* Validate firmware image size. */
7278 fwclen
+= risc_size
* sizeof(uint16_t);
7279 if (blob
->fw
->size
< fwclen
) {
7280 ql_log(ql_log_fatal
, vha
, 0x0088,
7281 "Unable to verify integrity of firmware image "
7282 "(%zd).\n", blob
->fw
->size
);
7283 goto fail_fw_integrity
;
7287 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7288 wlen
= (uint16_t)(ha
->fw_transfer_size
>> 1);
7289 if (wlen
> risc_size
)
7291 ql_dbg(ql_dbg_init
, vha
, 0x0089,
7292 "Loading risc segment@ risc addr %x number of "
7293 "words 0x%x.\n", risc_addr
, wlen
);
7295 for (i
= 0; i
< wlen
; i
++)
7296 wcode
[i
] = swab16(fwcode
[i
]);
7298 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7301 ql_log(ql_log_fatal
, vha
, 0x008a,
7302 "Failed to load segment %d of firmware.\n",
7319 return QLA_FUNCTION_FAILED
;
7323 qla24xx_load_risc_blob(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7326 int segments
, fragment
;
7327 uint32_t *dcode
, dlen
;
7331 struct fw_blob
*blob
;
7332 const uint32_t *fwcode
;
7334 struct qla_hw_data
*ha
= vha
->hw
;
7335 struct req_que
*req
= ha
->req_q_map
[0];
7337 /* Load firmware blob. */
7338 blob
= qla2x00_request_firmware(vha
);
7340 ql_log(ql_log_warn
, vha
, 0x0090,
7341 "Firmware image unavailable.\n");
7342 ql_log(ql_log_warn
, vha
, 0x0091,
7343 "Firmware images can be retrieved from: "
7346 return QLA_FUNCTION_FAILED
;
7349 ql_dbg(ql_dbg_init
, vha
, 0x0092,
7350 "FW: Loading via request-firmware.\n");
7354 segments
= FA_RISC_CODE_SEGMENTS
;
7355 dcode
= (uint32_t *)req
->ring
;
7357 fwcode
= (uint32_t *)blob
->fw
->data
;
7360 /* Validate firmware image by checking version. */
7361 if (blob
->fw
->size
< 8 * sizeof(uint32_t)) {
7362 ql_log(ql_log_fatal
, vha
, 0x0093,
7363 "Unable to verify integrity of firmware image (%zd).\n",
7365 return QLA_FUNCTION_FAILED
;
7367 for (i
= 0; i
< 4; i
++)
7368 dcode
[i
] = be32_to_cpu(fwcode
[i
+ 4]);
7369 if ((dcode
[0] == 0xffffffff && dcode
[1] == 0xffffffff &&
7370 dcode
[2] == 0xffffffff && dcode
[3] == 0xffffffff) ||
7371 (dcode
[0] == 0 && dcode
[1] == 0 && dcode
[2] == 0 &&
7373 ql_log(ql_log_fatal
, vha
, 0x0094,
7374 "Unable to verify integrity of firmware image (%zd).\n",
7376 ql_log(ql_log_fatal
, vha
, 0x0095,
7377 "Firmware data: %08x %08x %08x %08x.\n",
7378 dcode
[0], dcode
[1], dcode
[2], dcode
[3]);
7379 return QLA_FUNCTION_FAILED
;
7382 while (segments
&& rval
== QLA_SUCCESS
) {
7383 risc_addr
= be32_to_cpu(fwcode
[2]);
7384 *srisc_addr
= *srisc_addr
== 0 ? risc_addr
: *srisc_addr
;
7385 risc_size
= be32_to_cpu(fwcode
[3]);
7387 /* Validate firmware image size. */
7388 fwclen
+= risc_size
* sizeof(uint32_t);
7389 if (blob
->fw
->size
< fwclen
) {
7390 ql_log(ql_log_fatal
, vha
, 0x0096,
7391 "Unable to verify integrity of firmware image "
7392 "(%zd).\n", blob
->fw
->size
);
7393 return QLA_FUNCTION_FAILED
;
7397 while (risc_size
> 0 && rval
== QLA_SUCCESS
) {
7398 dlen
= (uint32_t)(ha
->fw_transfer_size
>> 2);
7399 if (dlen
> risc_size
)
7402 ql_dbg(ql_dbg_init
, vha
, 0x0097,
7403 "Loading risc segment@ risc addr %x "
7404 "number of dwords 0x%x.\n", risc_addr
, dlen
);
7406 for (i
= 0; i
< dlen
; i
++)
7407 dcode
[i
] = swab32(fwcode
[i
]);
7409 rval
= qla2x00_load_ram(vha
, req
->dma
, risc_addr
,
7412 ql_log(ql_log_fatal
, vha
, 0x0098,
7413 "Failed to load segment %d of firmware.\n",
7415 return QLA_FUNCTION_FAILED
;
7428 if (!IS_QLA27XX(ha
))
7431 if (ha
->fw_dump_template
)
7432 vfree(ha
->fw_dump_template
);
7433 ha
->fw_dump_template
= NULL
;
7434 ha
->fw_dump_template_len
= 0;
7436 ql_dbg(ql_dbg_init
, vha
, 0x171,
7437 "Loading fwdump template from %x\n",
7438 (uint32_t)((void *)fwcode
- (void *)blob
->fw
->data
));
7439 risc_size
= be32_to_cpu(fwcode
[2]);
7440 ql_dbg(ql_dbg_init
, vha
, 0x172,
7441 "-> array size %x dwords\n", risc_size
);
7442 if (risc_size
== 0 || risc_size
== ~0)
7443 goto default_template
;
7445 dlen
= (risc_size
- 8) * sizeof(*fwcode
);
7446 ql_dbg(ql_dbg_init
, vha
, 0x0173,
7447 "-> template allocating %x bytes...\n", dlen
);
7448 ha
->fw_dump_template
= vmalloc(dlen
);
7449 if (!ha
->fw_dump_template
) {
7450 ql_log(ql_log_warn
, vha
, 0x0174,
7451 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7452 goto default_template
;
7457 dcode
= ha
->fw_dump_template
;
7458 for (i
= 0; i
< risc_size
; i
++)
7459 dcode
[i
] = le32_to_cpu(fwcode
[i
]);
7461 if (!qla27xx_fwdt_template_valid(dcode
)) {
7462 ql_log(ql_log_warn
, vha
, 0x0175,
7463 "Failed fwdump template validate\n");
7464 goto default_template
;
7467 dlen
= qla27xx_fwdt_template_size(dcode
);
7468 ql_dbg(ql_dbg_init
, vha
, 0x0176,
7469 "-> template size %x bytes\n", dlen
);
7470 if (dlen
> risc_size
* sizeof(*fwcode
)) {
7471 ql_log(ql_log_warn
, vha
, 0x0177,
7472 "Failed fwdump template exceeds array by %zx bytes\n",
7473 (size_t)(dlen
- risc_size
* sizeof(*fwcode
)));
7474 goto default_template
;
7476 ha
->fw_dump_template_len
= dlen
;
7480 ql_log(ql_log_warn
, vha
, 0x0178, "Using default fwdump template\n");
7481 if (ha
->fw_dump_template
)
7482 vfree(ha
->fw_dump_template
);
7483 ha
->fw_dump_template
= NULL
;
7484 ha
->fw_dump_template_len
= 0;
7486 dlen
= qla27xx_fwdt_template_default_size();
7487 ql_dbg(ql_dbg_init
, vha
, 0x0179,
7488 "-> template allocating %x bytes...\n", dlen
);
7489 ha
->fw_dump_template
= vmalloc(dlen
);
7490 if (!ha
->fw_dump_template
) {
7491 ql_log(ql_log_warn
, vha
, 0x017a,
7492 "Failed fwdump template allocate %x bytes.\n", risc_size
);
7493 goto failed_template
;
7496 dcode
= ha
->fw_dump_template
;
7497 risc_size
= dlen
/ sizeof(*fwcode
);
7498 fwcode
= qla27xx_fwdt_template_default();
7499 for (i
= 0; i
< risc_size
; i
++)
7500 dcode
[i
] = be32_to_cpu(fwcode
[i
]);
7502 if (!qla27xx_fwdt_template_valid(ha
->fw_dump_template
)) {
7503 ql_log(ql_log_warn
, vha
, 0x017b,
7504 "Failed fwdump template validate\n");
7505 goto failed_template
;
7508 dlen
= qla27xx_fwdt_template_size(ha
->fw_dump_template
);
7509 ql_dbg(ql_dbg_init
, vha
, 0x017c,
7510 "-> template size %x bytes\n", dlen
);
7511 ha
->fw_dump_template_len
= dlen
;
7515 ql_log(ql_log_warn
, vha
, 0x017d, "Failed default fwdump template\n");
7516 if (ha
->fw_dump_template
)
7517 vfree(ha
->fw_dump_template
);
7518 ha
->fw_dump_template
= NULL
;
7519 ha
->fw_dump_template_len
= 0;
7524 qla24xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7528 if (ql2xfwloadbin
== 1)
7529 return qla81xx_load_risc(vha
, srisc_addr
);
7533 * 1) Firmware via request-firmware interface (.bin file).
7534 * 2) Firmware residing in flash.
7536 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7537 if (rval
== QLA_SUCCESS
)
7540 return qla24xx_load_risc_flash(vha
, srisc_addr
,
7541 vha
->hw
->flt_region_fw
);
7545 qla81xx_load_risc(scsi_qla_host_t
*vha
, uint32_t *srisc_addr
)
7548 struct qla_hw_data
*ha
= vha
->hw
;
7550 if (ql2xfwloadbin
== 2)
7555 * 1) Firmware residing in flash.
7556 * 2) Firmware via request-firmware interface (.bin file).
7557 * 3) Golden-Firmware residing in flash -- limited operation.
7559 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_fw
);
7560 if (rval
== QLA_SUCCESS
)
7564 rval
= qla24xx_load_risc_blob(vha
, srisc_addr
);
7565 if (rval
== QLA_SUCCESS
|| !ha
->flt_region_gold_fw
)
7568 ql_log(ql_log_info
, vha
, 0x0099,
7569 "Attempting to fallback to golden firmware.\n");
7570 rval
= qla24xx_load_risc_flash(vha
, srisc_addr
, ha
->flt_region_gold_fw
);
7571 if (rval
!= QLA_SUCCESS
)
7574 ql_log(ql_log_info
, vha
, 0x009a, "Update operational firmware.\n");
7575 ha
->flags
.running_gold_fw
= 1;
7580 qla2x00_try_to_stop_firmware(scsi_qla_host_t
*vha
)
7583 struct qla_hw_data
*ha
= vha
->hw
;
7585 if (ha
->flags
.pci_channel_io_perm_failure
)
7587 if (!IS_FWI2_CAPABLE(ha
))
7589 if (!ha
->fw_major_version
)
7591 if (!ha
->flags
.fw_started
)
7594 ret
= qla2x00_stop_firmware(vha
);
7595 for (retries
= 5; ret
!= QLA_SUCCESS
&& ret
!= QLA_FUNCTION_TIMEOUT
&&
7596 ret
!= QLA_INVALID_COMMAND
&& retries
; retries
--) {
7597 ha
->isp_ops
->reset_chip(vha
);
7598 if (ha
->isp_ops
->chip_diag(vha
) != QLA_SUCCESS
)
7600 if (qla2x00_setup_chip(vha
) != QLA_SUCCESS
)
7602 ql_log(ql_log_info
, vha
, 0x8015,
7603 "Attempting retry of stop-firmware command.\n");
7604 ret
= qla2x00_stop_firmware(vha
);
7608 ha
->flags
.fw_init_done
= 0;
7612 qla24xx_configure_vhba(scsi_qla_host_t
*vha
)
7614 int rval
= QLA_SUCCESS
;
7616 uint16_t mb
[MAILBOX_REGISTER_COUNT
];
7617 struct qla_hw_data
*ha
= vha
->hw
;
7618 struct scsi_qla_host
*base_vha
= pci_get_drvdata(ha
->pdev
);
7619 struct req_que
*req
;
7620 struct rsp_que
*rsp
;
7625 rval
= qla2x00_fw_ready(base_vha
);
7627 req
= vha
->qpair
->req
;
7629 req
= ha
->req_q_map
[0];
7632 if (rval
== QLA_SUCCESS
) {
7633 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
7634 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
7637 vha
->flags
.management_server_logged_in
= 0;
7639 /* Login to SNS first */
7640 rval2
= ha
->isp_ops
->fabric_login(vha
, NPH_SNS
, 0xff, 0xff, 0xfc, mb
,
7642 if (rval2
!= QLA_SUCCESS
|| mb
[0] != MBS_COMMAND_COMPLETE
) {
7643 if (rval2
== QLA_MEMORY_ALLOC_FAILED
)
7644 ql_dbg(ql_dbg_init
, vha
, 0x0120,
7645 "Failed SNS login: loop_id=%x, rval2=%d\n",
7648 ql_dbg(ql_dbg_init
, vha
, 0x0103,
7649 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7650 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7651 NPH_SNS
, mb
[0], mb
[1], mb
[2], mb
[6], mb
[7]);
7652 return (QLA_FUNCTION_FAILED
);
7655 atomic_set(&vha
->loop_down_timer
, 0);
7656 atomic_set(&vha
->loop_state
, LOOP_UP
);
7657 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
7658 set_bit(LOCAL_LOOP_UPDATE
, &vha
->dpc_flags
);
7659 rval
= qla2x00_loop_resync(base_vha
);
7664 /* 84XX Support **************************************************************/
7666 static LIST_HEAD(qla_cs84xx_list
);
7667 static DEFINE_MUTEX(qla_cs84xx_mutex
);
7669 static struct qla_chip_state_84xx
*
7670 qla84xx_get_chip(struct scsi_qla_host
*vha
)
7672 struct qla_chip_state_84xx
*cs84xx
;
7673 struct qla_hw_data
*ha
= vha
->hw
;
7675 mutex_lock(&qla_cs84xx_mutex
);
7677 /* Find any shared 84xx chip. */
7678 list_for_each_entry(cs84xx
, &qla_cs84xx_list
, list
) {
7679 if (cs84xx
->bus
== ha
->pdev
->bus
) {
7680 kref_get(&cs84xx
->kref
);
7685 cs84xx
= kzalloc(sizeof(*cs84xx
), GFP_KERNEL
);
7689 kref_init(&cs84xx
->kref
);
7690 spin_lock_init(&cs84xx
->access_lock
);
7691 mutex_init(&cs84xx
->fw_update_mutex
);
7692 cs84xx
->bus
= ha
->pdev
->bus
;
7694 list_add_tail(&cs84xx
->list
, &qla_cs84xx_list
);
7696 mutex_unlock(&qla_cs84xx_mutex
);
7701 __qla84xx_chip_release(struct kref
*kref
)
7703 struct qla_chip_state_84xx
*cs84xx
=
7704 container_of(kref
, struct qla_chip_state_84xx
, kref
);
7706 mutex_lock(&qla_cs84xx_mutex
);
7707 list_del(&cs84xx
->list
);
7708 mutex_unlock(&qla_cs84xx_mutex
);
7713 qla84xx_put_chip(struct scsi_qla_host
*vha
)
7715 struct qla_hw_data
*ha
= vha
->hw
;
7717 kref_put(&ha
->cs84xx
->kref
, __qla84xx_chip_release
);
7721 qla84xx_init_chip(scsi_qla_host_t
*vha
)
7725 struct qla_hw_data
*ha
= vha
->hw
;
7727 mutex_lock(&ha
->cs84xx
->fw_update_mutex
);
7729 rval
= qla84xx_verify_chip(vha
, status
);
7731 mutex_unlock(&ha
->cs84xx
->fw_update_mutex
);
7733 return rval
!= QLA_SUCCESS
|| status
[0] ? QLA_FUNCTION_FAILED
:
7737 /* 81XX Support **************************************************************/
7740 qla81xx_nvram_config(scsi_qla_host_t
*vha
)
7743 struct init_cb_81xx
*icb
;
7744 struct nvram_81xx
*nv
;
7746 uint8_t *dptr1
, *dptr2
;
7749 struct qla_hw_data
*ha
= vha
->hw
;
7752 icb
= (struct init_cb_81xx
*)ha
->init_cb
;
7755 /* Determine NVRAM starting address. */
7756 ha
->nvram_size
= sizeof(struct nvram_81xx
);
7757 ha
->vpd_size
= FA_NVRAM_VPD_SIZE
;
7758 if (IS_P3P_TYPE(ha
) || IS_QLA8031(ha
))
7759 ha
->vpd_size
= FA_VPD_SIZE_82XX
;
7761 /* Get VPD data into cache */
7762 ha
->vpd
= ha
->nvram
+ VPD_OFFSET
;
7763 ha
->isp_ops
->read_optrom(vha
, ha
->vpd
, ha
->flt_region_vpd
<< 2,
7766 /* Get NVRAM data into cache and calculate checksum. */
7767 ha
->isp_ops
->read_optrom(vha
, ha
->nvram
, ha
->flt_region_nvram
<< 2,
7769 dptr
= (uint32_t *)nv
;
7770 for (cnt
= 0, chksum
= 0; cnt
< ha
->nvram_size
>> 2; cnt
++, dptr
++)
7771 chksum
+= le32_to_cpu(*dptr
);
7773 ql_dbg(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0111,
7774 "Contents of NVRAM:\n");
7775 ql_dump_buffer(ql_dbg_init
+ ql_dbg_buffer
, vha
, 0x0112,
7776 (uint8_t *)nv
, ha
->nvram_size
);
7778 /* Bad NVRAM data, set defaults parameters. */
7779 if (chksum
|| nv
->id
[0] != 'I' || nv
->id
[1] != 'S' || nv
->id
[2] != 'P'
7780 || nv
->id
[3] != ' ' ||
7781 nv
->nvram_version
< cpu_to_le16(ICB_VERSION
)) {
7782 /* Reset NVRAM data. */
7783 ql_log(ql_log_info
, vha
, 0x0073,
7784 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7785 "version=0x%x.\n", chksum
, nv
->id
[0],
7786 le16_to_cpu(nv
->nvram_version
));
7787 ql_log(ql_log_info
, vha
, 0x0074,
7788 "Falling back to functioning (yet invalid -- WWPN) "
7792 * Set default initialization control block.
7794 memset(nv
, 0, ha
->nvram_size
);
7795 nv
->nvram_version
= cpu_to_le16(ICB_VERSION
);
7796 nv
->version
= cpu_to_le16(ICB_VERSION
);
7797 nv
->frame_payload_size
= 2048;
7798 nv
->execution_throttle
= cpu_to_le16(0xFFFF);
7799 nv
->exchange_count
= cpu_to_le16(0);
7800 nv
->port_name
[0] = 0x21;
7801 nv
->port_name
[1] = 0x00 + ha
->port_no
+ 1;
7802 nv
->port_name
[2] = 0x00;
7803 nv
->port_name
[3] = 0xe0;
7804 nv
->port_name
[4] = 0x8b;
7805 nv
->port_name
[5] = 0x1c;
7806 nv
->port_name
[6] = 0x55;
7807 nv
->port_name
[7] = 0x86;
7808 nv
->node_name
[0] = 0x20;
7809 nv
->node_name
[1] = 0x00;
7810 nv
->node_name
[2] = 0x00;
7811 nv
->node_name
[3] = 0xe0;
7812 nv
->node_name
[4] = 0x8b;
7813 nv
->node_name
[5] = 0x1c;
7814 nv
->node_name
[6] = 0x55;
7815 nv
->node_name
[7] = 0x86;
7816 nv
->login_retry_count
= cpu_to_le16(8);
7817 nv
->interrupt_delay_timer
= cpu_to_le16(0);
7818 nv
->login_timeout
= cpu_to_le16(0);
7819 nv
->firmware_options_1
=
7820 cpu_to_le32(BIT_14
|BIT_13
|BIT_2
|BIT_1
);
7821 nv
->firmware_options_2
= cpu_to_le32(2 << 4);
7822 nv
->firmware_options_2
|= cpu_to_le32(BIT_12
);
7823 nv
->firmware_options_3
= cpu_to_le32(2 << 13);
7824 nv
->host_p
= cpu_to_le32(BIT_11
|BIT_10
);
7825 nv
->efi_parameters
= cpu_to_le32(0);
7826 nv
->reset_delay
= 5;
7827 nv
->max_luns_per_target
= cpu_to_le16(128);
7828 nv
->port_down_retry_count
= cpu_to_le16(30);
7829 nv
->link_down_timeout
= cpu_to_le16(180);
7830 nv
->enode_mac
[0] = 0x00;
7831 nv
->enode_mac
[1] = 0xC0;
7832 nv
->enode_mac
[2] = 0xDD;
7833 nv
->enode_mac
[3] = 0x04;
7834 nv
->enode_mac
[4] = 0x05;
7835 nv
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
7840 if (IS_T10_PI_CAPABLE(ha
))
7841 nv
->frame_payload_size
&= ~7;
7843 qlt_81xx_config_nvram_stage1(vha
, nv
);
7845 /* Reset Initialization control block */
7846 memset(icb
, 0, ha
->init_cb_size
);
7848 /* Copy 1st segment. */
7849 dptr1
= (uint8_t *)icb
;
7850 dptr2
= (uint8_t *)&nv
->version
;
7851 cnt
= (uint8_t *)&icb
->response_q_inpointer
- (uint8_t *)&icb
->version
;
7853 *dptr1
++ = *dptr2
++;
7855 icb
->login_retry_count
= nv
->login_retry_count
;
7857 /* Copy 2nd segment. */
7858 dptr1
= (uint8_t *)&icb
->interrupt_delay_timer
;
7859 dptr2
= (uint8_t *)&nv
->interrupt_delay_timer
;
7860 cnt
= (uint8_t *)&icb
->reserved_5
-
7861 (uint8_t *)&icb
->interrupt_delay_timer
;
7863 *dptr1
++ = *dptr2
++;
7865 memcpy(icb
->enode_mac
, nv
->enode_mac
, sizeof(icb
->enode_mac
));
7866 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7867 if (!memcmp(icb
->enode_mac
, "\0\0\0\0\0\0", sizeof(icb
->enode_mac
))) {
7868 icb
->enode_mac
[0] = 0x00;
7869 icb
->enode_mac
[1] = 0xC0;
7870 icb
->enode_mac
[2] = 0xDD;
7871 icb
->enode_mac
[3] = 0x04;
7872 icb
->enode_mac
[4] = 0x05;
7873 icb
->enode_mac
[5] = 0x06 + ha
->port_no
+ 1;
7876 /* Use extended-initialization control block. */
7877 memcpy(ha
->ex_init_cb
, &nv
->ex_version
, sizeof(*ha
->ex_init_cb
));
7880 * Setup driver NVRAM options.
7882 qla2x00_set_model_info(vha
, nv
->model_name
, sizeof(nv
->model_name
),
7885 qlt_81xx_config_nvram_stage2(vha
, icb
);
7887 /* Use alternate WWN? */
7888 if (nv
->host_p
& cpu_to_le32(BIT_15
)) {
7889 memcpy(icb
->node_name
, nv
->alternate_node_name
, WWN_SIZE
);
7890 memcpy(icb
->port_name
, nv
->alternate_port_name
, WWN_SIZE
);
7893 /* Prepare nodename */
7894 if ((icb
->firmware_options_1
& cpu_to_le32(BIT_14
)) == 0) {
7896 * Firmware will apply the following mask if the nodename was
7899 memcpy(icb
->node_name
, icb
->port_name
, WWN_SIZE
);
7900 icb
->node_name
[0] &= 0xF0;
7903 /* Set host adapter parameters. */
7904 ha
->flags
.disable_risc_code_load
= 0;
7905 ha
->flags
.enable_lip_reset
= 0;
7906 ha
->flags
.enable_lip_full_login
=
7907 le32_to_cpu(nv
->host_p
) & BIT_10
? 1: 0;
7908 ha
->flags
.enable_target_reset
=
7909 le32_to_cpu(nv
->host_p
) & BIT_11
? 1: 0;
7910 ha
->flags
.enable_led_scheme
= 0;
7911 ha
->flags
.disable_serdes
= le32_to_cpu(nv
->host_p
) & BIT_5
? 1: 0;
7913 ha
->operating_mode
= (le32_to_cpu(icb
->firmware_options_2
) &
7914 (BIT_6
| BIT_5
| BIT_4
)) >> 4;
7916 /* save HBA serial number */
7917 ha
->serial0
= icb
->port_name
[5];
7918 ha
->serial1
= icb
->port_name
[6];
7919 ha
->serial2
= icb
->port_name
[7];
7920 memcpy(vha
->node_name
, icb
->node_name
, WWN_SIZE
);
7921 memcpy(vha
->port_name
, icb
->port_name
, WWN_SIZE
);
7923 icb
->execution_throttle
= cpu_to_le16(0xFFFF);
7925 ha
->retry_count
= le16_to_cpu(nv
->login_retry_count
);
7927 /* Set minimum login_timeout to 4 seconds. */
7928 if (le16_to_cpu(nv
->login_timeout
) < ql2xlogintimeout
)
7929 nv
->login_timeout
= cpu_to_le16(ql2xlogintimeout
);
7930 if (le16_to_cpu(nv
->login_timeout
) < 4)
7931 nv
->login_timeout
= cpu_to_le16(4);
7932 ha
->login_timeout
= le16_to_cpu(nv
->login_timeout
);
7934 /* Set minimum RATOV to 100 tenths of a second. */
7937 ha
->loop_reset_delay
= nv
->reset_delay
;
7939 /* Link Down Timeout = 0:
7941 * When Port Down timer expires we will start returning
7942 * I/O's to OS with "DID_NO_CONNECT".
7944 * Link Down Timeout != 0:
7946 * The driver waits for the link to come up after link down
7947 * before returning I/Os to OS with "DID_NO_CONNECT".
7949 if (le16_to_cpu(nv
->link_down_timeout
) == 0) {
7950 ha
->loop_down_abort_time
=
7951 (LOOP_DOWN_TIME
- LOOP_DOWN_TIMEOUT
);
7953 ha
->link_down_timeout
= le16_to_cpu(nv
->link_down_timeout
);
7954 ha
->loop_down_abort_time
=
7955 (LOOP_DOWN_TIME
- ha
->link_down_timeout
);
7958 /* Need enough time to try and get the port back. */
7959 ha
->port_down_retry_count
= le16_to_cpu(nv
->port_down_retry_count
);
7960 if (qlport_down_retry
)
7961 ha
->port_down_retry_count
= qlport_down_retry
;
7963 /* Set login_retry_count */
7964 ha
->login_retry_count
= le16_to_cpu(nv
->login_retry_count
);
7965 if (ha
->port_down_retry_count
==
7966 le16_to_cpu(nv
->port_down_retry_count
) &&
7967 ha
->port_down_retry_count
> 3)
7968 ha
->login_retry_count
= ha
->port_down_retry_count
;
7969 else if (ha
->port_down_retry_count
> (int)ha
->login_retry_count
)
7970 ha
->login_retry_count
= ha
->port_down_retry_count
;
7971 if (ql2xloginretrycount
)
7972 ha
->login_retry_count
= ql2xloginretrycount
;
7974 /* if not running MSI-X we need handshaking on interrupts */
7975 if (!vha
->hw
->flags
.msix_enabled
&& (IS_QLA83XX(ha
) || IS_QLA27XX(ha
)))
7976 icb
->firmware_options_2
|= cpu_to_le32(BIT_22
);
7979 if (!vha
->flags
.init_done
) {
7980 ha
->zio_mode
= le32_to_cpu(icb
->firmware_options_2
) &
7981 (BIT_3
| BIT_2
| BIT_1
| BIT_0
);
7982 ha
->zio_timer
= le16_to_cpu(icb
->interrupt_delay_timer
) ?
7983 le16_to_cpu(icb
->interrupt_delay_timer
): 2;
7985 icb
->firmware_options_2
&= cpu_to_le32(
7986 ~(BIT_3
| BIT_2
| BIT_1
| BIT_0
));
7987 vha
->flags
.process_response_queue
= 0;
7988 if (ha
->zio_mode
!= QLA_ZIO_DISABLED
) {
7989 ha
->zio_mode
= QLA_ZIO_MODE_6
;
7991 ql_log(ql_log_info
, vha
, 0x0075,
7992 "ZIO mode %d enabled; timer delay (%d us).\n",
7994 ha
->zio_timer
* 100);
7996 icb
->firmware_options_2
|= cpu_to_le32(
7997 (uint32_t)ha
->zio_mode
);
7998 icb
->interrupt_delay_timer
= cpu_to_le16(ha
->zio_timer
);
7999 vha
->flags
.process_response_queue
= 1;
8002 /* enable RIDA Format2 */
8003 if (qla_tgt_mode_enabled(vha
) || qla_dual_mode_enabled(vha
))
8004 icb
->firmware_options_3
|= BIT_0
;
8006 if (IS_QLA27XX(ha
)) {
8007 icb
->firmware_options_3
|= BIT_8
;
8008 ql_dbg(ql_log_info
, vha
, 0x0075,
8009 "Enabling direct connection.\n");
8013 ql_log(ql_log_warn
, vha
, 0x0076,
8014 "NVRAM configuration failed.\n");
8020 qla82xx_restart_isp(scsi_qla_host_t
*vha
)
8023 struct qla_hw_data
*ha
= vha
->hw
;
8024 struct req_que
*req
= ha
->req_q_map
[0];
8025 struct rsp_que
*rsp
= ha
->rsp_q_map
[0];
8026 struct scsi_qla_host
*vp
;
8027 unsigned long flags
;
8029 status
= qla2x00_init_rings(vha
);
8031 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8032 ha
->flags
.chip_reset_done
= 1;
8034 status
= qla2x00_fw_ready(vha
);
8036 /* Issue a marker after FW becomes ready. */
8037 qla2x00_marker(vha
, req
, rsp
, 0, 0, MK_SYNC_ALL
);
8038 vha
->flags
.online
= 1;
8039 set_bit(LOOP_RESYNC_NEEDED
, &vha
->dpc_flags
);
8042 /* if no cable then assume it's good */
8043 if ((vha
->device_flags
& DFLG_NO_CABLE
))
8048 clear_bit(RESET_MARKER_NEEDED
, &vha
->dpc_flags
);
8050 if (!atomic_read(&vha
->loop_down_timer
)) {
8052 * Issue marker command only when we are going
8053 * to start the I/O .
8055 vha
->marker_needed
= 1;
8058 ha
->isp_ops
->enable_intrs(ha
);
8060 ha
->isp_abort_cnt
= 0;
8061 clear_bit(ISP_ABORT_RETRY
, &vha
->dpc_flags
);
8063 /* Update the firmware version */
8064 status
= qla82xx_check_md_needed(vha
);
8067 ha
->flags
.fce_enabled
= 1;
8069 fce_calc_size(ha
->fce_bufs
));
8070 rval
= qla2x00_enable_fce_trace(vha
,
8071 ha
->fce_dma
, ha
->fce_bufs
, ha
->fce_mb
,
8074 ql_log(ql_log_warn
, vha
, 0x8001,
8075 "Unable to reinitialize FCE (%d).\n",
8077 ha
->flags
.fce_enabled
= 0;
8082 memset(ha
->eft
, 0, EFT_SIZE
);
8083 rval
= qla2x00_enable_eft_trace(vha
,
8084 ha
->eft_dma
, EFT_NUM_BUFFERS
);
8086 ql_log(ql_log_warn
, vha
, 0x8010,
8087 "Unable to reinitialize EFT (%d).\n",
8094 ql_dbg(ql_dbg_taskm
, vha
, 0x8011,
8095 "qla82xx_restart_isp succeeded.\n");
8097 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8098 list_for_each_entry(vp
, &ha
->vp_list
, list
) {
8100 atomic_inc(&vp
->vref_count
);
8101 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8103 qla2x00_vp_abort_isp(vp
);
8105 spin_lock_irqsave(&ha
->vport_slock
, flags
);
8106 atomic_dec(&vp
->vref_count
);
8109 spin_unlock_irqrestore(&ha
->vport_slock
, flags
);
8112 ql_log(ql_log_warn
, vha
, 0x8016,
8113 "qla82xx_restart_isp **** FAILED ****.\n");
8120 qla81xx_update_fw_options(scsi_qla_host_t
*vha
)
8122 struct qla_hw_data
*ha
= vha
->hw
;
8124 /* Hold status IOCBs until ABTS response received. */
8126 ha
->fw_options
[3] |= BIT_12
;
8128 /* Set Retry FLOGI in case of P2P connection */
8129 if (ha
->operating_mode
== P2P
) {
8130 ha
->fw_options
[2] |= BIT_3
;
8131 ql_dbg(ql_dbg_disc
, vha
, 0x2103,
8132 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8133 __func__
, ha
->fw_options
[2]);
8136 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8137 if (ql2xmvasynctoatio
) {
8138 if (qla_tgt_mode_enabled(vha
) ||
8139 qla_dual_mode_enabled(vha
))
8140 ha
->fw_options
[2] |= BIT_11
;
8142 ha
->fw_options
[2] &= ~BIT_11
;
8145 if (qla_tgt_mode_enabled(vha
) ||
8146 qla_dual_mode_enabled(vha
)) {
8147 /* FW auto send SCSI status during */
8148 ha
->fw_options
[1] |= BIT_8
;
8149 ha
->fw_options
[10] |= (u16
)SAM_STAT_BUSY
<< 8;
8151 /* FW perform Exchange validation */
8152 ha
->fw_options
[2] |= BIT_4
;
8154 ha
->fw_options
[1] &= ~BIT_8
;
8155 ha
->fw_options
[10] &= 0x00ff;
8157 ha
->fw_options
[2] &= ~BIT_4
;
8160 if (ql2xetsenable
) {
8161 /* Enable ETS Burst. */
8162 memset(ha
->fw_options
, 0, sizeof(ha
->fw_options
));
8163 ha
->fw_options
[2] |= BIT_9
;
8166 ql_dbg(ql_dbg_init
, vha
, 0x00e9,
8167 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8168 __func__
, ha
->fw_options
[1], ha
->fw_options
[2],
8169 ha
->fw_options
[3], vha
->host
->active_mode
);
8171 qla2x00_set_fw_options(vha
, ha
->fw_options
);
8175 * qla24xx_get_fcp_prio
8176 * Gets the fcp cmd priority value for the logged in port.
8177 * Looks for a match of the port descriptors within
8178 * each of the fcp prio config entries. If a match is found,
8179 * the tag (priority) value is returned.
8182 * vha = scsi host structure pointer.
8183 * fcport = port structure pointer.
8186 * non-zero (if found)
8193 qla24xx_get_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8196 uint8_t pid_match
, wwn_match
;
8198 uint32_t pid1
, pid2
;
8199 uint64_t wwn1
, wwn2
;
8200 struct qla_fcp_prio_entry
*pri_entry
;
8201 struct qla_hw_data
*ha
= vha
->hw
;
8203 if (!ha
->fcp_prio_cfg
|| !ha
->flags
.fcp_prio_enabled
)
8207 entries
= ha
->fcp_prio_cfg
->num_entries
;
8208 pri_entry
= &ha
->fcp_prio_cfg
->entry
[0];
8210 for (i
= 0; i
< entries
; i
++) {
8211 pid_match
= wwn_match
= 0;
8213 if (!(pri_entry
->flags
& FCP_PRIO_ENTRY_VALID
)) {
8218 /* check source pid for a match */
8219 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SPID_VALID
) {
8220 pid1
= pri_entry
->src_pid
& INVALID_PORT_ID
;
8221 pid2
= vha
->d_id
.b24
& INVALID_PORT_ID
;
8222 if (pid1
== INVALID_PORT_ID
)
8224 else if (pid1
== pid2
)
8228 /* check destination pid for a match */
8229 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DPID_VALID
) {
8230 pid1
= pri_entry
->dst_pid
& INVALID_PORT_ID
;
8231 pid2
= fcport
->d_id
.b24
& INVALID_PORT_ID
;
8232 if (pid1
== INVALID_PORT_ID
)
8234 else if (pid1
== pid2
)
8238 /* check source WWN for a match */
8239 if (pri_entry
->flags
& FCP_PRIO_ENTRY_SWWN_VALID
) {
8240 wwn1
= wwn_to_u64(vha
->port_name
);
8241 wwn2
= wwn_to_u64(pri_entry
->src_wwpn
);
8242 if (wwn2
== (uint64_t)-1)
8244 else if (wwn1
== wwn2
)
8248 /* check destination WWN for a match */
8249 if (pri_entry
->flags
& FCP_PRIO_ENTRY_DWWN_VALID
) {
8250 wwn1
= wwn_to_u64(fcport
->port_name
);
8251 wwn2
= wwn_to_u64(pri_entry
->dst_wwpn
);
8252 if (wwn2
== (uint64_t)-1)
8254 else if (wwn1
== wwn2
)
8258 if (pid_match
== 2 || wwn_match
== 2) {
8259 /* Found a matching entry */
8260 if (pri_entry
->flags
& FCP_PRIO_ENTRY_TAG_VALID
)
8261 priority
= pri_entry
->tag
;
8272 * qla24xx_update_fcport_fcp_prio
8273 * Activates fcp priority for the logged in fc port
8276 * vha = scsi host structure pointer.
8277 * fcp = port structure pointer.
8280 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8286 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t
*vha
, fc_port_t
*fcport
)
8292 if (fcport
->port_type
!= FCT_TARGET
||
8293 fcport
->loop_id
== FC_NO_LOOP_ID
)
8294 return QLA_FUNCTION_FAILED
;
8296 priority
= qla24xx_get_fcp_prio(vha
, fcport
);
8298 return QLA_FUNCTION_FAILED
;
8300 if (IS_P3P_TYPE(vha
->hw
)) {
8301 fcport
->fcp_prio
= priority
& 0xf;
8305 ret
= qla24xx_set_fcp_prio(vha
, fcport
->loop_id
, priority
, mb
);
8306 if (ret
== QLA_SUCCESS
) {
8307 if (fcport
->fcp_prio
!= priority
)
8308 ql_dbg(ql_dbg_user
, vha
, 0x709e,
8309 "Updated FCP_CMND priority - value=%d loop_id=%d "
8310 "port_id=%02x%02x%02x.\n", priority
,
8311 fcport
->loop_id
, fcport
->d_id
.b
.domain
,
8312 fcport
->d_id
.b
.area
, fcport
->d_id
.b
.al_pa
);
8313 fcport
->fcp_prio
= priority
& 0xf;
8315 ql_dbg(ql_dbg_user
, vha
, 0x704f,
8316 "Unable to update FCP_CMND priority - ret=0x%x for "
8317 "loop_id=%d port_id=%02x%02x%02x.\n", ret
, fcport
->loop_id
,
8318 fcport
->d_id
.b
.domain
, fcport
->d_id
.b
.area
,
8319 fcport
->d_id
.b
.al_pa
);
8324 * qla24xx_update_all_fcp_prio
8325 * Activates fcp priority for all the logged in ports
8328 * ha = adapter block pointer.
8331 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8337 qla24xx_update_all_fcp_prio(scsi_qla_host_t
*vha
)
8342 ret
= QLA_FUNCTION_FAILED
;
8343 /* We need to set priority for all logged in ports */
8344 list_for_each_entry(fcport
, &vha
->vp_fcports
, list
)
8345 ret
= qla24xx_update_fcport_fcp_prio(vha
, fcport
);
8350 struct qla_qpair
*qla2xxx_create_qpair(struct scsi_qla_host
*vha
, int qos
,
8351 int vp_idx
, bool startqp
)
8356 struct qla_hw_data
*ha
= vha
->hw
;
8357 uint16_t qpair_id
= 0;
8358 struct qla_qpair
*qpair
= NULL
;
8359 struct qla_msix_entry
*msix
;
8361 if (!(ha
->fw_attributes
& BIT_6
) || !ha
->flags
.msix_enabled
) {
8362 ql_log(ql_log_warn
, vha
, 0x00181,
8363 "FW/Driver is not multi-queue capable.\n");
8367 if (ql2xmqsupport
|| ql2xnvmeenable
) {
8368 qpair
= kzalloc(sizeof(struct qla_qpair
), GFP_KERNEL
);
8369 if (qpair
== NULL
) {
8370 ql_log(ql_log_warn
, vha
, 0x0182,
8371 "Failed to allocate memory for queue pair.\n");
8374 memset(qpair
, 0, sizeof(struct qla_qpair
));
8376 qpair
->hw
= vha
->hw
;
8378 qpair
->qp_lock_ptr
= &qpair
->qp_lock
;
8379 spin_lock_init(&qpair
->qp_lock
);
8380 qpair
->use_shadow_reg
= IS_SHADOW_REG_CAPABLE(ha
) ? 1 : 0;
8382 /* Assign available que pair id */
8383 mutex_lock(&ha
->mq_lock
);
8384 qpair_id
= find_first_zero_bit(ha
->qpair_qid_map
, ha
->max_qpairs
);
8385 if (ha
->num_qpairs
>= ha
->max_qpairs
) {
8386 mutex_unlock(&ha
->mq_lock
);
8387 ql_log(ql_log_warn
, vha
, 0x0183,
8388 "No resources to create additional q pair.\n");
8392 set_bit(qpair_id
, ha
->qpair_qid_map
);
8393 ha
->queue_pair_map
[qpair_id
] = qpair
;
8394 qpair
->id
= qpair_id
;
8395 qpair
->vp_idx
= vp_idx
;
8396 qpair
->fw_started
= ha
->flags
.fw_started
;
8397 INIT_LIST_HEAD(&qpair
->hints_list
);
8398 INIT_LIST_HEAD(&qpair
->nvme_done_list
);
8399 qpair
->chip_reset
= ha
->base_qpair
->chip_reset
;
8400 qpair
->enable_class_2
= ha
->base_qpair
->enable_class_2
;
8401 qpair
->enable_explicit_conf
=
8402 ha
->base_qpair
->enable_explicit_conf
;
8404 for (i
= 0; i
< ha
->msix_count
; i
++) {
8405 msix
= &ha
->msix_entries
[i
];
8409 ql_dbg(ql_dbg_multiq
, vha
, 0xc00f,
8410 "Vector %x selected for qpair\n", msix
->vector
);
8414 ql_log(ql_log_warn
, vha
, 0x0184,
8415 "Out of MSI-X vectors!.\n");
8419 qpair
->msix
->in_use
= 1;
8420 list_add_tail(&qpair
->qp_list_elem
, &vha
->qp_list
);
8421 qpair
->pdev
= ha
->pdev
;
8422 if (IS_QLA27XX(ha
) || IS_QLA83XX(ha
))
8423 qpair
->reqq_start_iocbs
= qla_83xx_start_iocbs
;
8425 mutex_unlock(&ha
->mq_lock
);
8427 /* Create response queue first */
8428 rsp_id
= qla25xx_create_rsp_que(ha
, 0, 0, 0, qpair
, startqp
);
8430 ql_log(ql_log_warn
, vha
, 0x0185,
8431 "Failed to create response queue.\n");
8435 qpair
->rsp
= ha
->rsp_q_map
[rsp_id
];
8437 /* Create request queue */
8438 req_id
= qla25xx_create_req_que(ha
, 0, vp_idx
, 0, rsp_id
, qos
,
8441 ql_log(ql_log_warn
, vha
, 0x0186,
8442 "Failed to create request queue.\n");
8446 qpair
->req
= ha
->req_q_map
[req_id
];
8447 qpair
->rsp
->req
= qpair
->req
;
8448 qpair
->rsp
->qpair
= qpair
;
8449 /* init qpair to this cpu. Will adjust at run time. */
8450 qla_cpu_update(qpair
, smp_processor_id());
8452 if (IS_T10_PI_CAPABLE(ha
) && ql2xenabledif
) {
8453 if (ha
->fw_attributes
& BIT_4
)
8454 qpair
->difdix_supported
= 1;
8457 qpair
->srb_mempool
= mempool_create_slab_pool(SRB_MIN_REQ
, srb_cachep
);
8458 if (!qpair
->srb_mempool
) {
8459 ql_log(ql_log_warn
, vha
, 0xd036,
8460 "Failed to create srb mempool for qpair %d\n",
8465 /* Mark as online */
8468 if (!vha
->flags
.qpairs_available
)
8469 vha
->flags
.qpairs_available
= 1;
8471 ql_dbg(ql_dbg_multiq
, vha
, 0xc00d,
8472 "Request/Response queue pair created, id %d\n",
8474 ql_dbg(ql_dbg_init
, vha
, 0x0187,
8475 "Request/Response queue pair created, id %d\n",
8482 qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8484 mutex_lock(&ha
->mq_lock
);
8485 qpair
->msix
->in_use
= 0;
8486 list_del(&qpair
->qp_list_elem
);
8487 if (list_empty(&vha
->qp_list
))
8488 vha
->flags
.qpairs_available
= 0;
8490 ha
->queue_pair_map
[qpair_id
] = NULL
;
8491 clear_bit(qpair_id
, ha
->qpair_qid_map
);
8493 mutex_unlock(&ha
->mq_lock
);
8499 int qla2xxx_delete_qpair(struct scsi_qla_host
*vha
, struct qla_qpair
*qpair
)
8501 int ret
= QLA_FUNCTION_FAILED
;
8502 struct qla_hw_data
*ha
= qpair
->hw
;
8504 qpair
->delete_in_progress
= 1;
8505 while (atomic_read(&qpair
->ref_count
))
8508 ret
= qla25xx_delete_req_que(vha
, qpair
->req
);
8509 if (ret
!= QLA_SUCCESS
)
8512 ret
= qla25xx_delete_rsp_que(vha
, qpair
->rsp
);
8513 if (ret
!= QLA_SUCCESS
)
8516 mutex_lock(&ha
->mq_lock
);
8517 ha
->queue_pair_map
[qpair
->id
] = NULL
;
8518 clear_bit(qpair
->id
, ha
->qpair_qid_map
);
8520 list_del(&qpair
->qp_list_elem
);
8521 if (list_empty(&vha
->qp_list
)) {
8522 vha
->flags
.qpairs_available
= 0;
8523 vha
->flags
.qpairs_req_created
= 0;
8524 vha
->flags
.qpairs_rsp_created
= 0;
8526 mempool_destroy(qpair
->srb_mempool
);
8528 mutex_unlock(&ha
->mq_lock
);