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;
55 struct qla_hw_data *ha = sp->vha->hw;
57 WARN_ON_ONCE(irqs_disabled());
58 spin_lock_irqsave(&ha->hardware_lock, flags);
60 req->outstanding_cmds[sp->handle] = NULL;
61 iocb = &sp->u.iocb_cmd;
62 spin_unlock_irqrestore(&ha->hardware_lock, flags);
67 qla2x00_sp_free(void *ptr)
70 struct srb_iocb *iocb = &sp->u.iocb_cmd;
72 del_timer(&iocb->timer);
76 /* Asynchronous Login/Logout Routines -------------------------------------- */
79 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
82 struct qla_hw_data *ha = vha->hw;
84 /* Firmware should use switch negotiated r_a_tov for timeout. */
85 tmo = ha->r_a_tov / 10 * 2;
87 tmo = FX00_DEF_RATOV * 2;
88 } else if (!IS_FWI2_CAPABLE(ha)) {
90 * Except for earlier ISPs where the timeout is seeded from the
91 * initialization control block.
93 tmo = ha->login_timeout;
99 qla2x00_async_iocb_timeout(void *data)
102 fc_port_t *fcport = sp->fcport;
103 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);
120 rc = qla24xx_async_abort_cmd(sp, false);
122 /* Retry as needed. */
123 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
124 lio->u.logio.data[1] =
125 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
126 QLA_LOGIO_LOGIN_RETRIED : 0;
127 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
128 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
130 if (sp->qpair->req->outstanding_cmds[h] ==
132 sp->qpair->req->outstanding_cmds[h] =
137 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
138 sp->done(sp, QLA_FUNCTION_TIMEOUT);
142 case SRB_CT_PTHRU_CMD:
148 rc = qla24xx_async_abort_cmd(sp, false);
150 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
151 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
153 if (sp->qpair->req->outstanding_cmds[h] ==
155 sp->qpair->req->outstanding_cmds[h] =
160 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
161 sp->done(sp, QLA_FUNCTION_TIMEOUT);
168 qla2x00_async_login_sp_done(void *ptr, int res)
171 struct scsi_qla_host *vha = sp->vha;
172 struct srb_iocb *lio = &sp->u.iocb_cmd;
175 ql_dbg(ql_dbg_disc, vha, 0x20dd,
176 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
178 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
180 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
181 memset(&ea, 0, sizeof(ea));
182 ea.event = FCME_PLOGI_DONE;
183 ea.fcport = sp->fcport;
184 ea.data[0] = lio->u.logio.data[0];
185 ea.data[1] = lio->u.logio.data[1];
186 ea.iop[0] = lio->u.logio.iop[0];
187 ea.iop[1] = lio->u.logio.iop[1];
189 qla2x00_fcport_event_handler(vha, &ea);
196 fcport_is_smaller(fc_port_t *fcport)
198 if (wwn_to_u64(fcport->port_name) <
199 wwn_to_u64(fcport->vha->port_name))
206 fcport_is_bigger(fc_port_t *fcport)
208 return !fcport_is_smaller(fcport);
212 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
216 struct srb_iocb *lio;
217 int rval = QLA_FUNCTION_FAILED;
219 if (!vha->flags.online)
222 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
226 fcport->flags |= FCF_ASYNC_SENT;
227 fcport->logout_completed = 0;
229 fcport->disc_state = DSC_LOGIN_PEND;
230 sp->type = SRB_LOGIN_CMD;
232 sp->gen1 = fcport->rscn_gen;
233 sp->gen2 = fcport->login_gen;
235 lio = &sp->u.iocb_cmd;
236 lio->timeout = qla2x00_async_iocb_timeout;
237 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
239 sp->done = qla2x00_async_login_sp_done;
240 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
241 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
243 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
245 if (fcport->fc4f_nvme)
246 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
248 ql_dbg(ql_dbg_disc, vha, 0x2072,
249 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
250 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
251 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
252 fcport->login_retry);
254 rval = qla2x00_start_sp(sp);
255 if (rval != QLA_SUCCESS) {
256 fcport->flags |= FCF_LOGIN_NEEDED;
257 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
265 fcport->flags &= ~FCF_ASYNC_SENT;
267 fcport->flags &= ~FCF_ASYNC_ACTIVE;
272 qla2x00_async_logout_sp_done(void *ptr, int res)
276 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
277 sp->fcport->login_gen++;
278 qlt_logo_completion_handler(sp->fcport, res);
283 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
286 struct srb_iocb *lio;
287 int rval = QLA_FUNCTION_FAILED;
289 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
292 fcport->flags |= FCF_ASYNC_SENT;
293 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
297 sp->type = SRB_LOGOUT_CMD;
300 lio = &sp->u.iocb_cmd;
301 lio->timeout = qla2x00_async_iocb_timeout;
302 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
304 sp->done = qla2x00_async_logout_sp_done;
306 ql_dbg(ql_dbg_disc, vha, 0x2070,
307 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
308 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
309 fcport->d_id.b.area, fcport->d_id.b.al_pa,
312 rval = qla2x00_start_sp(sp);
313 if (rval != QLA_SUCCESS)
320 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
325 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
328 fcport->flags &= ~FCF_ASYNC_ACTIVE;
329 /* Don't re-login in target mode */
330 if (!fcport->tgt_session)
331 qla2x00_mark_device_lost(vha, fcport, 1, 0);
332 qlt_logo_completion_handler(fcport, data[0]);
336 qla2x00_async_prlo_sp_done(void *s, int res)
338 srb_t *sp = (srb_t *)s;
339 struct srb_iocb *lio = &sp->u.iocb_cmd;
340 struct scsi_qla_host *vha = sp->vha;
342 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
343 if (!test_bit(UNLOADING, &vha->dpc_flags))
344 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
350 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
353 struct srb_iocb *lio;
356 rval = QLA_FUNCTION_FAILED;
357 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
361 sp->type = SRB_PRLO_CMD;
364 lio = &sp->u.iocb_cmd;
365 lio->timeout = qla2x00_async_iocb_timeout;
366 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
368 sp->done = qla2x00_async_prlo_sp_done;
369 rval = qla2x00_start_sp(sp);
370 if (rval != QLA_SUCCESS)
373 ql_dbg(ql_dbg_disc, vha, 0x2070,
374 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
375 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
376 fcport->d_id.b.area, fcport->d_id.b.al_pa);
382 fcport->flags &= ~FCF_ASYNC_ACTIVE;
387 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
389 struct fc_port *fcport = ea->fcport;
391 ql_dbg(ql_dbg_disc, vha, 0x20d2,
392 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
393 __func__, fcport->port_name, fcport->disc_state,
394 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
395 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
397 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
398 ql_dbg(ql_dbg_disc, vha, 0x2066,
399 "%s %8phC: adisc fail: post delete\n",
400 __func__, ea->fcport->port_name);
401 /* deleted = 0 & logout_on_delete = force fw cleanup */
403 fcport->logout_on_delete = 1;
404 qlt_schedule_sess_for_deletion(ea->fcport);
408 if (ea->fcport->disc_state == DSC_DELETE_PEND)
411 if (ea->sp->gen2 != ea->fcport->login_gen) {
412 /* target side must have changed it. */
413 ql_dbg(ql_dbg_disc, vha, 0x20d3,
414 "%s %8phC generation changed\n",
415 __func__, ea->fcport->port_name);
417 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
418 qla_rscn_replay(fcport);
419 qlt_schedule_sess_for_deletion(fcport);
423 __qla24xx_handle_gpdb_event(vha, ea);
426 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
428 struct qla_work_evt *e;
430 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
432 return QLA_FUNCTION_FAILED;
434 e->u.fcport.fcport = fcport;
435 fcport->flags |= FCF_ASYNC_ACTIVE;
436 return qla2x00_post_work(vha, e);
440 qla2x00_async_adisc_sp_done(void *ptr, int res)
443 struct scsi_qla_host *vha = sp->vha;
445 struct srb_iocb *lio = &sp->u.iocb_cmd;
447 ql_dbg(ql_dbg_disc, vha, 0x2066,
448 "Async done-%s res %x %8phC\n",
449 sp->name, res, sp->fcport->port_name);
451 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
453 memset(&ea, 0, sizeof(ea));
454 ea.event = FCME_ADISC_DONE;
456 ea.data[0] = lio->u.logio.data[0];
457 ea.data[1] = lio->u.logio.data[1];
458 ea.iop[0] = lio->u.logio.iop[0];
459 ea.iop[1] = lio->u.logio.iop[1];
460 ea.fcport = sp->fcport;
463 qla2x00_fcport_event_handler(vha, &ea);
469 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
473 struct srb_iocb *lio;
476 rval = QLA_FUNCTION_FAILED;
477 fcport->flags |= FCF_ASYNC_SENT;
478 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
482 sp->type = SRB_ADISC_CMD;
485 lio = &sp->u.iocb_cmd;
486 lio->timeout = qla2x00_async_iocb_timeout;
487 sp->gen1 = fcport->rscn_gen;
488 sp->gen2 = fcport->login_gen;
489 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
491 sp->done = qla2x00_async_adisc_sp_done;
492 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
493 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
495 ql_dbg(ql_dbg_disc, vha, 0x206f,
496 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
497 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
499 rval = qla2x00_start_sp(sp);
500 if (rval != QLA_SUCCESS)
508 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
509 qla2x00_post_async_adisc_work(vha, fcport, data);
513 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
514 struct event_arg *ea)
516 fc_port_t *fcport, *conflict_fcport;
517 struct get_name_list_extended *e;
518 u16 i, n, found = 0, loop_id;
522 u8 current_login_state;
525 ql_dbg(ql_dbg_disc, vha, 0xffff,
526 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
527 __func__, fcport->port_name, fcport->disc_state,
528 fcport->fw_login_state, ea->rc,
529 fcport->login_gen, fcport->last_login_gen,
530 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
532 if (fcport->disc_state == DSC_DELETE_PEND)
535 if (ea->rc) { /* rval */
536 if (fcport->login_retry == 0) {
537 ql_dbg(ql_dbg_disc, vha, 0x20de,
538 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
539 fcport->port_name, fcport->login_retry);
544 if (fcport->last_rscn_gen != fcport->rscn_gen) {
545 qla_rscn_replay(fcport);
546 qlt_schedule_sess_for_deletion(fcport);
548 } else if (fcport->last_login_gen != fcport->login_gen) {
549 ql_dbg(ql_dbg_disc, vha, 0x20e0,
550 "%s %8phC login gen changed\n",
551 __func__, fcport->port_name);
555 n = ea->data[0] / sizeof(struct get_name_list_extended);
557 ql_dbg(ql_dbg_disc, vha, 0x20e1,
558 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
559 __func__, __LINE__, fcport->port_name, n,
560 fcport->d_id.b.domain, fcport->d_id.b.area,
561 fcport->d_id.b.al_pa, fcport->loop_id);
563 for (i = 0; i < n; i++) {
565 wwn = wwn_to_u64(e->port_name);
566 id.b.domain = e->port_id[2];
567 id.b.area = e->port_id[1];
568 id.b.al_pa = e->port_id[0];
571 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
574 if (IS_SW_RESV_ADDR(id))
579 loop_id = le16_to_cpu(e->nport_handle);
580 loop_id = (loop_id & 0x7fff);
581 if (fcport->fc4f_nvme)
582 current_login_state = e->current_login_state >> 4;
584 current_login_state = e->current_login_state & 0xf;
587 ql_dbg(ql_dbg_disc, vha, 0x20e2,
588 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
589 __func__, fcport->port_name,
590 e->current_login_state, fcport->fw_login_state,
591 fcport->fc4f_nvme, id.b.domain, id.b.area, id.b.al_pa,
592 fcport->d_id.b.domain, fcport->d_id.b.area,
593 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
595 switch (fcport->disc_state) {
596 case DSC_DELETE_PEND:
600 if ((id.b24 != fcport->d_id.b24 &&
602 (fcport->loop_id != FC_NO_LOOP_ID &&
603 fcport->loop_id != loop_id)) {
604 ql_dbg(ql_dbg_disc, vha, 0x20e3,
605 "%s %d %8phC post del sess\n",
606 __func__, __LINE__, fcport->port_name);
607 qlt_schedule_sess_for_deletion(fcport);
613 fcport->loop_id = loop_id;
615 wwn = wwn_to_u64(fcport->port_name);
616 qlt_find_sess_invalidate_other(vha, wwn,
617 id, loop_id, &conflict_fcport);
619 if (conflict_fcport) {
621 * Another share fcport share the same loop_id &
622 * nport id. Conflict fcport needs to finish
623 * cleanup before this fcport can proceed to login.
625 conflict_fcport->conflict = fcport;
626 fcport->login_pause = 1;
629 switch (vha->hw->current_topology) {
631 switch (current_login_state) {
632 case DSC_LS_PRLI_COMP:
633 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
634 vha, 0x20e4, "%s %d %8phC post gpdb\n",
635 __func__, __LINE__, fcport->port_name);
637 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
638 fcport->port_type = FCT_INITIATOR;
640 fcport->port_type = FCT_TARGET;
641 data[0] = data[1] = 0;
642 qla2x00_post_async_adisc_work(vha, fcport,
645 case DSC_LS_PORT_UNAVAIL:
647 if (fcport->loop_id != FC_NO_LOOP_ID)
648 qla2x00_clear_loop_id(fcport);
650 fcport->loop_id = loop_id;
651 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
652 qla24xx_fcport_handle_login(vha, fcport);
657 fcport->fw_login_state = current_login_state;
659 switch (current_login_state) {
660 case DSC_LS_PRLI_COMP:
661 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
662 fcport->port_type = FCT_INITIATOR;
664 fcport->port_type = FCT_TARGET;
666 data[0] = data[1] = 0;
667 qla2x00_post_async_adisc_work(vha, fcport,
670 case DSC_LS_PLOGI_COMP:
671 if (fcport_is_bigger(fcport)) {
672 /* local adapter is smaller */
673 if (fcport->loop_id != FC_NO_LOOP_ID)
674 qla2x00_clear_loop_id(fcport);
676 fcport->loop_id = loop_id;
677 qla24xx_fcport_handle_login(vha,
683 if (fcport_is_smaller(fcport)) {
684 /* local adapter is bigger */
685 if (fcport->loop_id != FC_NO_LOOP_ID)
686 qla2x00_clear_loop_id(fcport);
688 fcport->loop_id = loop_id;
689 qla24xx_fcport_handle_login(vha,
695 } /* switch (ha->current_topology) */
699 switch (vha->hw->current_topology) {
702 for (i = 0; i < n; i++) {
704 id.b.domain = e->port_id[0];
705 id.b.area = e->port_id[1];
706 id.b.al_pa = e->port_id[2];
708 loop_id = le16_to_cpu(e->nport_handle);
710 if (fcport->d_id.b24 == id.b24) {
712 qla2x00_find_fcport_by_wwpn(vha,
714 if (conflict_fcport) {
715 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
717 "%s %d %8phC post del sess\n",
719 conflict_fcport->port_name);
720 qlt_schedule_sess_for_deletion
725 * FW already picked this loop id for
728 if (fcport->loop_id == loop_id)
729 fcport->loop_id = FC_NO_LOOP_ID;
731 qla24xx_fcport_handle_login(vha, fcport);
734 fcport->disc_state = DSC_DELETED;
735 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
736 if (fcport->n2n_link_reset_cnt < 2) {
737 fcport->n2n_link_reset_cnt++;
739 * remote port is not sending PLOGI.
740 * Reset link to kick start his state
743 set_bit(N2N_LINK_RESET,
746 if (fcport->n2n_chip_reset < 1) {
747 ql_log(ql_log_info, vha, 0x705d,
748 "Chip reset to bring laser down");
749 set_bit(ISP_ABORT_NEEDED,
751 fcport->n2n_chip_reset++;
753 ql_log(ql_log_info, vha, 0x705d,
754 "Remote port %8ph is not coming back\n",
756 fcport->scan_state = 0;
759 qla2xxx_wake_dpc(vha);
762 * report port suppose to do PLOGI. Give him
763 * more time. FW will catch it.
765 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
775 qla24xx_async_gnl_sp_done(void *s, int res)
778 struct scsi_qla_host *vha = sp->vha;
780 struct fc_port *fcport = NULL, *tf;
781 u16 i, n = 0, loop_id;
783 struct get_name_list_extended *e;
788 ql_dbg(ql_dbg_disc, vha, 0x20e7,
789 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
790 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
791 sp->u.iocb_cmd.u.mbx.in_mb[2]);
793 if (res == QLA_FUNCTION_TIMEOUT)
796 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
797 memset(&ea, 0, sizeof(ea));
800 ea.event = FCME_GNL_DONE;
802 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
803 sizeof(struct get_name_list_extended)) {
804 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
805 sizeof(struct get_name_list_extended);
806 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
809 for (i = 0; i < n; i++) {
811 loop_id = le16_to_cpu(e->nport_handle);
812 /* mask out reserve bit */
813 loop_id = (loop_id & 0x7fff);
814 set_bit(loop_id, vha->hw->loop_id_map);
815 wwn = wwn_to_u64(e->port_name);
817 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
818 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
819 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
820 e->port_id[0], e->current_login_state, e->last_login_state,
824 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
828 if (!list_empty(&vha->gnl.fcports))
829 list_splice_init(&vha->gnl.fcports, &h);
830 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
832 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
833 list_del_init(&fcport->gnl_entry);
834 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
835 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
836 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
839 qla2x00_fcport_event_handler(vha, &ea);
842 /* create new fcport if fw has knowledge of new sessions */
843 for (i = 0; i < n; i++) {
848 wwn = wwn_to_u64(e->port_name);
851 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
852 if (!memcmp((u8 *)&wwn, fcport->port_name,
859 id.b.domain = e->port_id[2];
860 id.b.area = e->port_id[1];
861 id.b.al_pa = e->port_id[0];
864 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
865 ql_dbg(ql_dbg_disc, vha, 0x2065,
866 "%s %d %8phC %06x post new sess\n",
867 __func__, __LINE__, (u8 *)&wwn, id.b24);
868 wwnn = wwn_to_u64(e->node_name);
869 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
870 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
874 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
876 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
881 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
884 struct srb_iocb *mbx;
885 int rval = QLA_FUNCTION_FAILED;
889 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
892 ql_dbg(ql_dbg_disc, vha, 0x20d9,
893 "Async-gnlist WWPN %8phC \n", fcport->port_name);
895 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
896 fcport->flags |= FCF_ASYNC_SENT;
897 fcport->disc_state = DSC_GNL;
898 fcport->last_rscn_gen = fcport->rscn_gen;
899 fcport->last_login_gen = fcport->login_gen;
901 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
903 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
907 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
909 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
913 sp->type = SRB_MB_IOCB;
915 sp->gen1 = fcport->rscn_gen;
916 sp->gen2 = fcport->login_gen;
918 mbx = &sp->u.iocb_cmd;
919 mbx->timeout = qla2x00_async_iocb_timeout;
920 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
922 mb = sp->u.iocb_cmd.u.mbx.out_mb;
923 mb[0] = MBC_PORT_NODE_NAME_LIST;
924 mb[1] = BIT_2 | BIT_3;
925 mb[2] = MSW(vha->gnl.ldma);
926 mb[3] = LSW(vha->gnl.ldma);
927 mb[6] = MSW(MSD(vha->gnl.ldma));
928 mb[7] = LSW(MSD(vha->gnl.ldma));
929 mb[8] = vha->gnl.size;
932 sp->done = qla24xx_async_gnl_sp_done;
934 rval = qla2x00_start_sp(sp);
935 if (rval != QLA_SUCCESS)
938 ql_dbg(ql_dbg_disc, vha, 0x20da,
939 "Async-%s - OUT WWPN %8phC hndl %x\n",
940 sp->name, fcport->port_name, sp->handle);
946 fcport->flags &= ~FCF_ASYNC_SENT;
951 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
953 struct qla_work_evt *e;
955 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
957 return QLA_FUNCTION_FAILED;
959 e->u.fcport.fcport = fcport;
960 fcport->flags |= FCF_ASYNC_ACTIVE;
961 return qla2x00_post_work(vha, e);
965 void qla24xx_async_gpdb_sp_done(void *s, int res)
968 struct scsi_qla_host *vha = sp->vha;
969 struct qla_hw_data *ha = vha->hw;
970 fc_port_t *fcport = sp->fcport;
971 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
974 ql_dbg(ql_dbg_disc, vha, 0x20db,
975 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
976 sp->name, res, fcport->port_name, mb[1], mb[2]);
978 if (res == QLA_FUNCTION_TIMEOUT) {
979 dma_pool_free(sp->vha->hw->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
980 sp->u.iocb_cmd.u.mbx.in_dma);
984 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
985 memset(&ea, 0, sizeof(ea));
986 ea.event = FCME_GPDB_DONE;
990 qla2x00_fcport_event_handler(vha, &ea);
992 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
993 sp->u.iocb_cmd.u.mbx.in_dma);
998 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1000 struct qla_work_evt *e;
1002 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1004 return QLA_FUNCTION_FAILED;
1006 e->u.fcport.fcport = fcport;
1008 return qla2x00_post_work(vha, e);
1012 qla2x00_async_prli_sp_done(void *ptr, int res)
1015 struct scsi_qla_host *vha = sp->vha;
1016 struct srb_iocb *lio = &sp->u.iocb_cmd;
1017 struct event_arg ea;
1019 ql_dbg(ql_dbg_disc, vha, 0x2129,
1020 "%s %8phC res %d \n", __func__,
1021 sp->fcport->port_name, res);
1023 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1025 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1026 memset(&ea, 0, sizeof(ea));
1027 ea.event = FCME_PRLI_DONE;
1028 ea.fcport = sp->fcport;
1029 ea.data[0] = lio->u.logio.data[0];
1030 ea.data[1] = lio->u.logio.data[1];
1031 ea.iop[0] = lio->u.logio.iop[0];
1032 ea.iop[1] = lio->u.logio.iop[1];
1035 qla2x00_fcport_event_handler(vha, &ea);
1042 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1045 struct srb_iocb *lio;
1046 int rval = QLA_FUNCTION_FAILED;
1048 if (!vha->flags.online)
1051 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1052 fcport->fw_login_state == DSC_LS_PRLI_PEND)
1055 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1059 fcport->flags |= FCF_ASYNC_SENT;
1060 fcport->logout_completed = 0;
1062 sp->type = SRB_PRLI_CMD;
1065 lio = &sp->u.iocb_cmd;
1066 lio->timeout = qla2x00_async_iocb_timeout;
1067 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1069 sp->done = qla2x00_async_prli_sp_done;
1070 lio->u.logio.flags = 0;
1072 if (fcport->fc4f_nvme)
1073 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1075 rval = qla2x00_start_sp(sp);
1076 if (rval != QLA_SUCCESS) {
1077 fcport->flags |= FCF_LOGIN_NEEDED;
1078 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1082 ql_dbg(ql_dbg_disc, vha, 0x211b,
1083 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1084 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1085 fcport->login_retry, fcport->fc4f_nvme ? "nvme" : "fc");
1091 fcport->flags &= ~FCF_ASYNC_SENT;
1095 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1097 struct qla_work_evt *e;
1099 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1101 return QLA_FUNCTION_FAILED;
1103 e->u.fcport.fcport = fcport;
1104 e->u.fcport.opt = opt;
1105 fcport->flags |= FCF_ASYNC_ACTIVE;
1106 return qla2x00_post_work(vha, e);
1109 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1112 struct srb_iocb *mbx;
1113 int rval = QLA_FUNCTION_FAILED;
1116 struct port_database_24xx *pd;
1117 struct qla_hw_data *ha = vha->hw;
1119 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1122 fcport->disc_state = DSC_GPDB;
1124 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1128 fcport->flags |= FCF_ASYNC_SENT;
1129 sp->type = SRB_MB_IOCB;
1131 sp->gen1 = fcport->rscn_gen;
1132 sp->gen2 = fcport->login_gen;
1134 mbx = &sp->u.iocb_cmd;
1135 mbx->timeout = qla2x00_async_iocb_timeout;
1136 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1138 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1140 ql_log(ql_log_warn, vha, 0xd043,
1141 "Failed to allocate port database structure.\n");
1145 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1146 mb[0] = MBC_GET_PORT_DATABASE;
1147 mb[1] = fcport->loop_id;
1148 mb[2] = MSW(pd_dma);
1149 mb[3] = LSW(pd_dma);
1150 mb[6] = MSW(MSD(pd_dma));
1151 mb[7] = LSW(MSD(pd_dma));
1152 mb[9] = vha->vp_idx;
1155 mbx->u.mbx.in = (void *)pd;
1156 mbx->u.mbx.in_dma = pd_dma;
1158 sp->done = qla24xx_async_gpdb_sp_done;
1160 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1161 "Async-%s %8phC hndl %x opt %x\n",
1162 sp->name, fcport->port_name, sp->handle, opt);
1164 rval = qla2x00_start_sp(sp);
1165 if (rval != QLA_SUCCESS)
1171 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1174 fcport->flags &= ~FCF_ASYNC_SENT;
1176 qla24xx_post_gpdb_work(vha, fcport, opt);
1181 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1183 unsigned long flags;
1185 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1186 ea->fcport->login_gen++;
1187 ea->fcport->deleted = 0;
1188 ea->fcport->logout_on_delete = 1;
1190 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1191 vha->fcport_count++;
1192 ea->fcport->login_succ = 1;
1194 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1195 qla24xx_sched_upd_fcport(ea->fcport);
1196 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1197 } else if (ea->fcport->login_succ) {
1199 * We have an existing session. A late RSCN delivery
1200 * must have triggered the session to be re-validate.
1201 * Session is still valid.
1203 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1204 "%s %d %8phC session revalidate success\n",
1205 __func__, __LINE__, ea->fcport->port_name);
1206 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1208 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1212 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1214 fc_port_t *fcport = ea->fcport;
1215 struct port_database_24xx *pd;
1216 struct srb *sp = ea->sp;
1219 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1221 fcport->flags &= ~FCF_ASYNC_SENT;
1223 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1224 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__, fcport->port_name,
1225 fcport->disc_state, pd->current_login_state, fcport->fc4f_nvme,
1228 if (fcport->disc_state == DSC_DELETE_PEND)
1231 if (fcport->fc4f_nvme)
1232 ls = pd->current_login_state >> 4;
1234 ls = pd->current_login_state & 0xf;
1236 if (ea->sp->gen2 != fcport->login_gen) {
1237 /* target side must have changed it. */
1239 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1240 "%s %8phC generation changed\n",
1241 __func__, fcport->port_name);
1243 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1244 qla_rscn_replay(fcport);
1245 qlt_schedule_sess_for_deletion(fcport);
1250 case PDS_PRLI_COMPLETE:
1251 __qla24xx_parse_gpdb(vha, fcport, pd);
1253 case PDS_PLOGI_PENDING:
1254 case PDS_PLOGI_COMPLETE:
1255 case PDS_PRLI_PENDING:
1256 case PDS_PRLI2_PENDING:
1257 /* Set discovery state back to GNL to Relogin attempt */
1258 if (qla_dual_mode_enabled(vha) ||
1259 qla_ini_mode_enabled(vha)) {
1260 fcport->disc_state = DSC_GNL;
1261 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1264 case PDS_LOGO_PENDING:
1265 case PDS_PORT_UNAVAILABLE:
1267 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1268 __func__, __LINE__, fcport->port_name);
1269 qlt_schedule_sess_for_deletion(fcport);
1272 __qla24xx_handle_gpdb_event(vha, ea);
1275 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1280 if (qla_tgt_mode_enabled(vha))
1283 if (qla_dual_mode_enabled(vha)) {
1284 if (N2N_TOPO(vha->hw)) {
1287 mywwn = wwn_to_u64(vha->port_name);
1288 wwn = wwn_to_u64(fcport->port_name);
1291 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1292 && time_after_eq(jiffies,
1293 fcport->plogi_nack_done_deadline))
1299 /* initiator mode */
1303 if (login && fcport->login_retry) {
1304 fcport->login_retry--;
1305 if (fcport->loop_id == FC_NO_LOOP_ID) {
1306 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1307 rc = qla2x00_find_new_loop_id(vha, fcport);
1309 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1310 "%s %d %8phC post del sess - out of loopid\n",
1311 __func__, __LINE__, fcport->port_name);
1312 fcport->scan_state = 0;
1313 qlt_schedule_sess_for_deletion(fcport);
1317 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1318 "%s %d %8phC post login\n",
1319 __func__, __LINE__, fcport->port_name);
1320 qla2x00_post_async_login_work(vha, fcport, NULL);
1324 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1330 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20d8,
1331 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1332 __func__, fcport->port_name, fcport->disc_state,
1333 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1334 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1335 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1337 if (fcport->scan_state != QLA_FCPORT_FOUND)
1340 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1341 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1342 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1345 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1346 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1347 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1352 /* for pure Target Mode. Login will not be initiated */
1353 if (vha->host->active_mode == MODE_TARGET)
1356 if (fcport->flags & FCF_ASYNC_SENT) {
1357 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1361 switch (fcport->disc_state) {
1363 wwn = wwn_to_u64(fcport->node_name);
1364 switch (vha->hw->current_topology) {
1366 if (fcport_is_smaller(fcport)) {
1367 /* this adapter is bigger */
1368 if (fcport->login_retry) {
1369 if (fcport->loop_id == FC_NO_LOOP_ID) {
1370 qla2x00_find_new_loop_id(vha,
1372 fcport->fw_login_state =
1373 DSC_LS_PORT_UNAVAIL;
1375 fcport->login_retry--;
1376 qla_post_els_plogi_work(vha, fcport);
1378 ql_log(ql_log_info, vha, 0x705d,
1379 "Unable to reach remote port %8phC",
1383 qla24xx_post_gnl_work(vha, fcport);
1388 ql_dbg(ql_dbg_disc, vha, 0xffff,
1389 "%s %d %8phC post GNNID\n",
1390 __func__, __LINE__, fcport->port_name);
1391 qla24xx_post_gnnid_work(vha, fcport);
1392 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1393 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1394 "%s %d %8phC post gnl\n",
1395 __func__, __LINE__, fcport->port_name);
1396 qla24xx_post_gnl_work(vha, fcport);
1398 qla_chk_n2n_b4_login(vha, fcport);
1405 switch (vha->hw->current_topology) {
1407 if ((fcport->current_login_state & 0xf) == 0x6) {
1408 ql_dbg(ql_dbg_disc, vha, 0x2118,
1409 "%s %d %8phC post GPDB work\n",
1410 __func__, __LINE__, fcport->port_name);
1411 fcport->chip_reset =
1412 vha->hw->base_qpair->chip_reset;
1413 qla24xx_post_gpdb_work(vha, fcport, 0);
1415 ql_dbg(ql_dbg_disc, vha, 0x2118,
1416 "%s %d %8phC post NVMe PRLI\n",
1417 __func__, __LINE__, fcport->port_name);
1418 qla24xx_post_prli_work(vha, fcport);
1422 if (fcport->login_pause) {
1423 fcport->last_rscn_gen = fcport->rscn_gen;
1424 fcport->last_login_gen = fcport->login_gen;
1425 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1428 qla_chk_n2n_b4_login(vha, fcport);
1433 case DSC_LOGIN_FAILED:
1434 if (N2N_TOPO(vha->hw))
1435 qla_chk_n2n_b4_login(vha, fcport);
1437 qlt_schedule_sess_for_deletion(fcport);
1440 case DSC_LOGIN_COMPLETE:
1441 /* recheck login state */
1442 data[0] = data[1] = 0;
1443 qla2x00_post_async_adisc_work(vha, fcport, data);
1446 case DSC_LOGIN_PEND:
1447 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1448 qla24xx_post_prli_work(vha, fcport);
1451 case DSC_UPD_FCPORT:
1452 sec = jiffies_to_msecs(jiffies -
1453 fcport->jiffies_at_registration)/1000;
1454 if (fcport->sec_since_registration < sec && sec &&
1456 fcport->sec_since_registration = sec;
1457 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1458 "%s %8phC - Slow Rport registration(%d Sec)\n",
1459 __func__, fcport->port_name, sec);
1462 if (fcport->next_disc_state != DSC_DELETE_PEND)
1463 fcport->next_disc_state = DSC_ADISC;
1464 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1475 void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1479 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1480 "%s %8phC DS %d LS %d\n",
1481 __func__, fcport->port_name, fcport->disc_state,
1482 fcport->fw_login_state);
1484 if (fcport->flags & FCF_ASYNC_SENT)
1487 switch (fcport->disc_state) {
1489 case DSC_LOGIN_COMPLETE:
1490 qla24xx_post_gpnid_work(fcport->vha, &ea->id);
1497 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1498 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1500 struct qla_work_evt *e;
1501 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1503 return QLA_FUNCTION_FAILED;
1505 e->u.new_sess.id = *id;
1506 e->u.new_sess.pla = pla;
1507 e->u.new_sess.fc4_type = fc4_type;
1508 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1510 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1512 return qla2x00_post_work(vha, e);
1516 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1517 struct event_arg *ea)
1519 fc_port_t *fcport = ea->fcport;
1521 ql_dbg(ql_dbg_disc, vha, 0x2102,
1522 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1523 __func__, fcport->port_name, fcport->disc_state,
1524 fcport->fw_login_state, fcport->login_pause,
1525 fcport->deleted, fcport->conflict,
1526 fcport->last_rscn_gen, fcport->rscn_gen,
1527 fcport->last_login_gen, fcport->login_gen,
1530 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1531 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1534 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1535 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1536 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1541 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1542 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1543 __func__, __LINE__, fcport->port_name);
1548 qla24xx_fcport_handle_login(vha, fcport);
1552 static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1553 struct event_arg *ea)
1555 ql_dbg(ql_dbg_disc, vha, 0x2118,
1556 "%s %d %8phC post PRLI\n",
1557 __func__, __LINE__, ea->fcport->port_name);
1558 qla24xx_post_prli_work(vha, ea->fcport);
1561 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1564 uint32_t id = 0, mask, rid;
1567 switch (ea->event) {
1569 if (test_bit(UNLOADING, &vha->dpc_flags))
1572 qla24xx_handle_relogin_event(vha, ea);
1575 if (test_bit(UNLOADING, &vha->dpc_flags))
1577 switch (ea->id.b.rsvd_1) {
1578 case RSCN_PORT_ADDR:
1580 #if defined BIGSCAN & BIGSCAN > 0
1582 unsigned long flags;
1583 fcport = qla2x00_find_fcport_by_nportid
1586 fcport->scan_needed = 1;
1590 spin_lock_irqsave(&vha->work_lock, flags);
1591 if (vha->scan.scan_flags == 0) {
1592 ql_dbg(ql_dbg_disc, vha, 0xffff,
1593 "%s: schedule\n", __func__);
1594 vha->scan.scan_flags |= SF_QUEUED;
1595 schedule_delayed_work(&vha->scan.scan_work, 5);
1597 spin_unlock_irqrestore(&vha->work_lock, flags);
1602 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1605 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1607 ql_log(ql_log_warn, vha, 0xd044,
1608 "RSCN GPNID work failed %06x\n",
1612 ea->fcport = fcport;
1613 fcport->scan_needed = 1;
1614 qla24xx_handle_rscn_event(fcport, ea);
1619 case RSCN_AREA_ADDR:
1621 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1623 ql_dbg(ql_dbg_async, vha, 0x5044,
1624 "RSCN: Area 0x%06x was affected\n",
1628 ql_dbg(ql_dbg_async, vha, 0x507a,
1629 "RSCN: Domain 0x%06x was affected\n",
1633 rid = ea->id.b24 & mask;
1634 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1636 id = f->d_id.b24 & mask;
1639 qla24xx_handle_rscn_event(f, ea);
1645 ql_log(ql_log_warn, vha, 0xd045,
1646 "RSCN: Fabric was affected. Addr format %d\n",
1648 qla2x00_mark_all_devices_lost(vha, 1);
1649 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1650 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1654 qla24xx_handle_gnl_done_event(vha, ea);
1656 case FCME_GPSC_DONE:
1657 qla24xx_handle_gpsc_event(vha, ea);
1659 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1660 qla24xx_handle_plogi_done_event(vha, ea);
1662 case FCME_PRLI_DONE:
1663 qla24xx_handle_prli_done_event(vha, ea);
1665 case FCME_GPDB_DONE:
1666 qla24xx_handle_gpdb_event(vha, ea);
1668 case FCME_GPNID_DONE:
1669 qla24xx_handle_gpnid_event(vha, ea);
1671 case FCME_GFFID_DONE:
1672 qla24xx_handle_gffid_event(vha, ea);
1674 case FCME_ADISC_DONE:
1675 qla24xx_handle_adisc_event(vha, ea);
1677 case FCME_GNNID_DONE:
1678 qla24xx_handle_gnnid_event(vha, ea);
1680 case FCME_GFPNID_DONE:
1681 qla24xx_handle_gfpnid_event(vha, ea);
1683 case FCME_ELS_PLOGI_DONE:
1684 qla_handle_els_plogi_done(vha, ea);
1693 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1694 * to be consumed by the fcport
1696 void qla_rscn_replay(fc_port_t *fcport)
1698 struct event_arg ea;
1700 switch (fcport->disc_state) {
1701 case DSC_DELETE_PEND:
1707 if (fcport->scan_needed) {
1708 memset(&ea, 0, sizeof(ea));
1709 ea.event = FCME_RSCN;
1710 ea.id = fcport->d_id;
1711 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1712 #if defined BIGSCAN & BIGSCAN > 0
1713 qla2x00_fcport_event_handler(fcport->vha, &ea);
1715 qla24xx_post_gpnid_work(fcport->vha, &ea.id);
1721 qla2x00_tmf_iocb_timeout(void *data)
1724 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1726 tmf->u.tmf.comp_status = CS_TIMEOUT;
1727 complete(&tmf->u.tmf.comp);
1731 qla2x00_tmf_sp_done(void *ptr, int res)
1734 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1736 complete(&tmf->u.tmf.comp);
1740 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1743 struct scsi_qla_host *vha = fcport->vha;
1744 struct srb_iocb *tm_iocb;
1746 int rval = QLA_FUNCTION_FAILED;
1748 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1752 tm_iocb = &sp->u.iocb_cmd;
1753 sp->type = SRB_TM_CMD;
1756 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1757 init_completion(&tm_iocb->u.tmf.comp);
1758 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1760 tm_iocb->u.tmf.flags = flags;
1761 tm_iocb->u.tmf.lun = lun;
1762 tm_iocb->u.tmf.data = tag;
1763 sp->done = qla2x00_tmf_sp_done;
1765 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1766 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1767 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1768 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1770 rval = qla2x00_start_sp(sp);
1771 if (rval != QLA_SUCCESS)
1773 wait_for_completion(&tm_iocb->u.tmf.comp);
1775 rval = tm_iocb->u.tmf.data;
1777 if (rval != QLA_SUCCESS) {
1778 ql_log(ql_log_warn, vha, 0x8030,
1779 "TM IOCB failed (%x).\n", rval);
1782 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1783 flags = tm_iocb->u.tmf.flags;
1784 lun = (uint16_t)tm_iocb->u.tmf.lun;
1786 /* Issue Marker IOCB */
1787 qla2x00_marker(vha, vha->hw->req_q_map[0],
1788 vha->hw->rsp_q_map[0], fcport->loop_id, lun,
1789 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1794 fcport->flags &= ~FCF_ASYNC_SENT;
1800 qla24xx_abort_iocb_timeout(void *data)
1803 struct srb_iocb *abt = &sp->u.iocb_cmd;
1805 abt->u.abt.comp_status = CS_TIMEOUT;
1806 sp->done(sp, QLA_FUNCTION_TIMEOUT);
1810 qla24xx_abort_sp_done(void *ptr, int res)
1813 struct srb_iocb *abt = &sp->u.iocb_cmd;
1815 if (del_timer(&sp->u.iocb_cmd.timer)) {
1816 if (sp->flags & SRB_WAKEUP_ON_COMP)
1817 complete(&abt->u.abt.comp);
1824 qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
1826 scsi_qla_host_t *vha = cmd_sp->vha;
1827 struct srb_iocb *abt_iocb;
1829 int rval = QLA_FUNCTION_FAILED;
1831 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
1836 abt_iocb = &sp->u.iocb_cmd;
1837 sp->type = SRB_ABT_CMD;
1839 sp->qpair = cmd_sp->qpair;
1841 sp->flags = SRB_WAKEUP_ON_COMP;
1843 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1844 init_completion(&abt_iocb->u.abt.comp);
1845 /* FW can send 2 x ABTS's timeout/20s */
1846 qla2x00_init_timer(sp, 42);
1848 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1849 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
1851 sp->done = qla24xx_abort_sp_done;
1853 ql_dbg(ql_dbg_async, vha, 0x507c,
1854 "Abort command issued - hdl=%x, type=%x\n",
1855 cmd_sp->handle, cmd_sp->type);
1857 rval = qla2x00_start_sp(sp);
1858 if (rval != QLA_SUCCESS)
1862 wait_for_completion(&abt_iocb->u.abt.comp);
1863 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1864 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1876 qla24xx_async_abort_command(srb_t *sp)
1878 unsigned long flags = 0;
1881 fc_port_t *fcport = sp->fcport;
1882 struct qla_qpair *qpair = sp->qpair;
1883 struct scsi_qla_host *vha = fcport->vha;
1884 struct req_que *req = qpair->req;
1886 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1887 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1888 if (req->outstanding_cmds[handle] == sp)
1891 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1893 if (handle == req->num_outstanding_cmds) {
1894 /* Command not found. */
1895 return QLA_FUNCTION_FAILED;
1897 if (sp->type == SRB_FXIOCB_DCMD)
1898 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1899 FXDISC_ABORT_IOCTL);
1901 return qla24xx_async_abort_cmd(sp, true);
1905 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1907 switch (ea->data[0]) {
1908 case MBS_COMMAND_COMPLETE:
1909 ql_dbg(ql_dbg_disc, vha, 0x2118,
1910 "%s %d %8phC post gpdb\n",
1911 __func__, __LINE__, ea->fcport->port_name);
1913 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1914 ea->fcport->logout_on_delete = 1;
1915 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1918 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1919 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1920 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1921 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1925 if (ea->fcport->n2n_flag) {
1926 ql_dbg(ql_dbg_disc, vha, 0x2118,
1927 "%s %d %8phC post fc4 prli\n",
1928 __func__, __LINE__, ea->fcport->port_name);
1929 ea->fcport->fc4f_nvme = 0;
1930 ea->fcport->n2n_flag = 0;
1931 qla24xx_post_prli_work(vha, ea->fcport);
1933 ql_dbg(ql_dbg_disc, vha, 0x2119,
1934 "%s %d %8phC unhandle event of %x\n",
1935 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1941 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1943 port_id_t cid; /* conflict Nport id */
1945 struct fc_port *conflict_fcport;
1946 unsigned long flags;
1947 struct fc_port *fcport = ea->fcport;
1949 ql_dbg(ql_dbg_disc, vha, 0xffff,
1950 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1951 __func__, fcport->port_name, fcport->disc_state,
1952 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1953 ea->sp->gen1, fcport->rscn_gen,
1954 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1956 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1957 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1958 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1959 "%s %d %8phC Remote is trying to login\n",
1960 __func__, __LINE__, fcport->port_name);
1964 if (fcport->disc_state == DSC_DELETE_PEND)
1967 if (ea->sp->gen2 != fcport->login_gen) {
1968 /* target side must have changed it. */
1969 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1970 "%s %8phC generation changed\n",
1971 __func__, fcport->port_name);
1972 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1974 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1975 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1976 "%s %8phC RSCN generation changed\n",
1977 __func__, fcport->port_name);
1978 qla_rscn_replay(fcport);
1979 qlt_schedule_sess_for_deletion(fcport);
1983 switch (ea->data[0]) {
1984 case MBS_COMMAND_COMPLETE:
1986 * Driver must validate login state - If PRLI not complete,
1987 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1990 if (ea->fcport->fc4f_nvme) {
1991 ql_dbg(ql_dbg_disc, vha, 0x2117,
1992 "%s %d %8phC post prli\n",
1993 __func__, __LINE__, ea->fcport->port_name);
1994 qla24xx_post_prli_work(vha, ea->fcport);
1996 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1997 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1998 __func__, __LINE__, ea->fcport->port_name,
1999 ea->fcport->loop_id, ea->fcport->d_id.b24);
2001 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2002 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2003 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2004 ea->fcport->logout_on_delete = 1;
2005 ea->fcport->send_els_logo = 0;
2006 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2007 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2009 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2012 case MBS_COMMAND_ERROR:
2013 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2014 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2016 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2017 ea->fcport->disc_state = DSC_LOGIN_FAILED;
2018 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2019 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2021 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2023 case MBS_LOOP_ID_USED:
2024 /* data[1] = IO PARAM 1 = nport ID */
2025 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2026 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2027 cid.b.al_pa = ea->iop[1] & 0xff;
2030 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2031 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2032 __func__, __LINE__, ea->fcport->port_name,
2033 ea->fcport->loop_id, cid.b24);
2035 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2036 ea->fcport->loop_id = FC_NO_LOOP_ID;
2037 qla24xx_post_gnl_work(vha, ea->fcport);
2039 case MBS_PORT_ID_USED:
2040 lid = ea->iop[1] & 0xffff;
2041 qlt_find_sess_invalidate_other(vha,
2042 wwn_to_u64(ea->fcport->port_name),
2043 ea->fcport->d_id, lid, &conflict_fcport);
2045 if (conflict_fcport) {
2047 * Another fcport share the same loop_id/nport id.
2048 * Conflict fcport needs to finish cleanup before this
2049 * fcport can proceed to login.
2051 conflict_fcport->conflict = ea->fcport;
2052 ea->fcport->login_pause = 1;
2054 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2055 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2056 __func__, __LINE__, ea->fcport->port_name,
2057 ea->fcport->d_id.b24, lid);
2059 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2060 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2061 __func__, __LINE__, ea->fcport->port_name,
2062 ea->fcport->d_id.b24, lid);
2064 qla2x00_clear_loop_id(ea->fcport);
2065 set_bit(lid, vha->hw->loop_id_map);
2066 ea->fcport->loop_id = lid;
2067 ea->fcport->keep_nport_handle = 0;
2068 qlt_schedule_sess_for_deletion(ea->fcport);
2076 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2079 qlt_logo_completion_handler(fcport, data[0]);
2080 fcport->login_gen++;
2081 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2085 /****************************************************************************/
2086 /* QLogic ISP2x00 Hardware Support Functions. */
2087 /****************************************************************************/
2090 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2092 int rval = QLA_SUCCESS;
2093 struct qla_hw_data *ha = vha->hw;
2094 uint32_t idc_major_ver, idc_minor_ver;
2097 qla83xx_idc_lock(vha, 0);
2099 /* SV: TODO: Assign initialization timeout from
2100 * flash-info / other param
2102 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2103 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2105 /* Set our fcoe function presence */
2106 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2107 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2108 "Error while setting DRV-Presence.\n");
2109 rval = QLA_FUNCTION_FAILED;
2113 /* Decide the reset ownership */
2114 qla83xx_reset_ownership(vha);
2117 * On first protocol driver load:
2118 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2120 * Others: Check compatibility with current IDC Major version.
2122 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2123 if (ha->flags.nic_core_reset_owner) {
2124 /* Set IDC Major version */
2125 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2126 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2128 /* Clearing IDC-Lock-Recovery register */
2129 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2130 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2132 * Clear further IDC participation if we are not compatible with
2133 * the current IDC Major Version.
2135 ql_log(ql_log_warn, vha, 0xb07d,
2136 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2137 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2138 __qla83xx_clear_drv_presence(vha);
2139 rval = QLA_FUNCTION_FAILED;
2142 /* Each function sets its supported Minor version. */
2143 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2144 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2145 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2147 if (ha->flags.nic_core_reset_owner) {
2148 memset(config, 0, sizeof(config));
2149 if (!qla81xx_get_port_config(vha, config))
2150 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2154 rval = qla83xx_idc_state_handler(vha);
2157 qla83xx_idc_unlock(vha, 0);
2163 * qla2x00_initialize_adapter
2167 * ha = adapter block pointer.
2173 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2176 struct qla_hw_data *ha = vha->hw;
2177 struct req_que *req = ha->req_q_map[0];
2179 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2180 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2182 /* Clear adapter flags. */
2183 vha->flags.online = 0;
2184 ha->flags.chip_reset_done = 0;
2185 vha->flags.reset_active = 0;
2186 ha->flags.pci_channel_io_perm_failure = 0;
2187 ha->flags.eeh_busy = 0;
2188 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2189 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2190 atomic_set(&vha->loop_state, LOOP_DOWN);
2191 vha->device_flags = DFLG_NO_CABLE;
2193 vha->flags.management_server_logged_in = 0;
2194 vha->marker_needed = 0;
2195 ha->isp_abort_cnt = 0;
2196 ha->beacon_blink_led = 0;
2198 set_bit(0, ha->req_qid_map);
2199 set_bit(0, ha->rsp_qid_map);
2201 ql_dbg(ql_dbg_init, vha, 0x0040,
2202 "Configuring PCI space...\n");
2203 rval = ha->isp_ops->pci_config(vha);
2205 ql_log(ql_log_warn, vha, 0x0044,
2206 "Unable to configure PCI space.\n");
2210 ha->isp_ops->reset_chip(vha);
2212 rval = qla2xxx_get_flash_info(vha);
2214 ql_log(ql_log_fatal, vha, 0x004f,
2215 "Unable to validate FLASH data.\n");
2219 if (IS_QLA8044(ha)) {
2220 qla8044_read_reset_template(vha);
2222 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2223 * If DONRESET_BIT0 is set, drivers should not set dev_state
2224 * to NEED_RESET. But if NEED_RESET is set, drivers should
2225 * should honor the reset. */
2226 if (ql2xdontresethba == 1)
2227 qla8044_set_idc_dontreset(vha);
2230 ha->isp_ops->get_flash_version(vha, req->ring);
2231 ql_dbg(ql_dbg_init, vha, 0x0061,
2232 "Configure NVRAM parameters...\n");
2234 ha->isp_ops->nvram_config(vha);
2236 if (ha->flags.disable_serdes) {
2237 /* Mask HBA via NVRAM settings? */
2238 ql_log(ql_log_info, vha, 0x0077,
2239 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2240 return QLA_FUNCTION_FAILED;
2243 ql_dbg(ql_dbg_init, vha, 0x0078,
2244 "Verifying loaded RISC code...\n");
2246 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2247 rval = ha->isp_ops->chip_diag(vha);
2250 rval = qla2x00_setup_chip(vha);
2255 if (IS_QLA84XX(ha)) {
2256 ha->cs84xx = qla84xx_get_chip(vha);
2258 ql_log(ql_log_warn, vha, 0x00d0,
2259 "Unable to configure ISP84XX.\n");
2260 return QLA_FUNCTION_FAILED;
2264 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2265 rval = qla2x00_init_rings(vha);
2267 ha->flags.chip_reset_done = 1;
2269 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2270 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2271 rval = qla84xx_init_chip(vha);
2272 if (rval != QLA_SUCCESS) {
2273 ql_log(ql_log_warn, vha, 0x00d4,
2274 "Unable to initialize ISP84XX.\n");
2275 qla84xx_put_chip(vha);
2279 /* Load the NIC Core f/w if we are the first protocol driver. */
2280 if (IS_QLA8031(ha)) {
2281 rval = qla83xx_nic_core_fw_load(vha);
2283 ql_log(ql_log_warn, vha, 0x0124,
2284 "Error in initializing NIC Core f/w.\n");
2287 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2288 qla24xx_read_fcp_prio_cfg(vha);
2290 if (IS_P3P_TYPE(ha))
2291 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2293 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2299 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2302 * Returns 0 on success.
2305 qla2100_pci_config(scsi_qla_host_t *vha)
2308 unsigned long flags;
2309 struct qla_hw_data *ha = vha->hw;
2310 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2312 pci_set_master(ha->pdev);
2313 pci_try_set_mwi(ha->pdev);
2315 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2316 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2317 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2319 pci_disable_rom(ha->pdev);
2321 /* Get PCI bus information. */
2322 spin_lock_irqsave(&ha->hardware_lock, flags);
2323 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2324 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2330 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2333 * Returns 0 on success.
2336 qla2300_pci_config(scsi_qla_host_t *vha)
2339 unsigned long flags = 0;
2341 struct qla_hw_data *ha = vha->hw;
2342 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2344 pci_set_master(ha->pdev);
2345 pci_try_set_mwi(ha->pdev);
2347 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2348 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2350 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2351 w &= ~PCI_COMMAND_INTX_DISABLE;
2352 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2355 * If this is a 2300 card and not 2312, reset the
2356 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2357 * the 2310 also reports itself as a 2300 so we need to get the
2358 * fb revision level -- a 6 indicates it really is a 2300 and
2361 if (IS_QLA2300(ha)) {
2362 spin_lock_irqsave(&ha->hardware_lock, flags);
2365 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2366 for (cnt = 0; cnt < 30000; cnt++) {
2367 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2373 /* Select FPM registers. */
2374 WRT_REG_WORD(®->ctrl_status, 0x20);
2375 RD_REG_WORD(®->ctrl_status);
2377 /* Get the fb rev level */
2378 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2380 if (ha->fb_rev == FPM_2300)
2381 pci_clear_mwi(ha->pdev);
2383 /* Deselect FPM registers. */
2384 WRT_REG_WORD(®->ctrl_status, 0x0);
2385 RD_REG_WORD(®->ctrl_status);
2387 /* Release RISC module. */
2388 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2389 for (cnt = 0; cnt < 30000; cnt++) {
2390 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2396 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2399 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2401 pci_disable_rom(ha->pdev);
2403 /* Get PCI bus information. */
2404 spin_lock_irqsave(&ha->hardware_lock, flags);
2405 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2406 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2412 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2415 * Returns 0 on success.
2418 qla24xx_pci_config(scsi_qla_host_t *vha)
2421 unsigned long flags = 0;
2422 struct qla_hw_data *ha = vha->hw;
2423 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2425 pci_set_master(ha->pdev);
2426 pci_try_set_mwi(ha->pdev);
2428 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2429 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2430 w &= ~PCI_COMMAND_INTX_DISABLE;
2431 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2433 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2435 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2436 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2437 pcix_set_mmrbc(ha->pdev, 2048);
2439 /* PCIe -- adjust Maximum Read Request Size (2048). */
2440 if (pci_is_pcie(ha->pdev))
2441 pcie_set_readrq(ha->pdev, 4096);
2443 pci_disable_rom(ha->pdev);
2445 ha->chip_revision = ha->pdev->revision;
2447 /* Get PCI bus information. */
2448 spin_lock_irqsave(&ha->hardware_lock, flags);
2449 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2450 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2456 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2459 * Returns 0 on success.
2462 qla25xx_pci_config(scsi_qla_host_t *vha)
2465 struct qla_hw_data *ha = vha->hw;
2467 pci_set_master(ha->pdev);
2468 pci_try_set_mwi(ha->pdev);
2470 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2471 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2472 w &= ~PCI_COMMAND_INTX_DISABLE;
2473 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2475 /* PCIe -- adjust Maximum Read Request Size (2048). */
2476 if (pci_is_pcie(ha->pdev))
2477 pcie_set_readrq(ha->pdev, 4096);
2479 pci_disable_rom(ha->pdev);
2481 ha->chip_revision = ha->pdev->revision;
2487 * qla2x00_isp_firmware() - Choose firmware image.
2490 * Returns 0 on success.
2493 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2496 uint16_t loop_id, topo, sw_cap;
2497 uint8_t domain, area, al_pa;
2498 struct qla_hw_data *ha = vha->hw;
2500 /* Assume loading risc code */
2501 rval = QLA_FUNCTION_FAILED;
2503 if (ha->flags.disable_risc_code_load) {
2504 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2506 /* Verify checksum of loaded RISC code. */
2507 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2508 if (rval == QLA_SUCCESS) {
2509 /* And, verify we are not in ROM code. */
2510 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2511 &area, &domain, &topo, &sw_cap);
2516 ql_dbg(ql_dbg_init, vha, 0x007a,
2517 "**** Load RISC code ****.\n");
2523 * qla2x00_reset_chip() - Reset ISP chip.
2526 * Returns 0 on success.
2529 qla2x00_reset_chip(scsi_qla_host_t *vha)
2531 unsigned long flags = 0;
2532 struct qla_hw_data *ha = vha->hw;
2533 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2537 if (unlikely(pci_channel_offline(ha->pdev)))
2540 ha->isp_ops->disable_intrs(ha);
2542 spin_lock_irqsave(&ha->hardware_lock, flags);
2544 /* Turn off master enable */
2546 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2547 cmd &= ~PCI_COMMAND_MASTER;
2548 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2550 if (!IS_QLA2100(ha)) {
2552 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2553 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2554 for (cnt = 0; cnt < 30000; cnt++) {
2555 if ((RD_REG_WORD(®->hccr) &
2556 HCCR_RISC_PAUSE) != 0)
2561 RD_REG_WORD(®->hccr); /* PCI Posting. */
2565 /* Select FPM registers. */
2566 WRT_REG_WORD(®->ctrl_status, 0x20);
2567 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2569 /* FPM Soft Reset. */
2570 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2571 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2573 /* Toggle Fpm Reset. */
2574 if (!IS_QLA2200(ha)) {
2575 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2576 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2579 /* Select frame buffer registers. */
2580 WRT_REG_WORD(®->ctrl_status, 0x10);
2581 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2583 /* Reset frame buffer FIFOs. */
2584 if (IS_QLA2200(ha)) {
2585 WRT_FB_CMD_REG(ha, reg, 0xa000);
2586 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2588 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2590 /* Read back fb_cmd until zero or 3 seconds max */
2591 for (cnt = 0; cnt < 3000; cnt++) {
2592 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2598 /* Select RISC module registers. */
2599 WRT_REG_WORD(®->ctrl_status, 0);
2600 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2602 /* Reset RISC processor. */
2603 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2604 RD_REG_WORD(®->hccr); /* PCI Posting. */
2606 /* Release RISC processor. */
2607 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2608 RD_REG_WORD(®->hccr); /* PCI Posting. */
2611 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2612 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2614 /* Reset ISP chip. */
2615 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2617 /* Wait for RISC to recover from reset. */
2618 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2620 * It is necessary to for a delay here since the card doesn't
2621 * respond to PCI reads during a reset. On some architectures
2622 * this will result in an MCA.
2625 for (cnt = 30000; cnt; cnt--) {
2626 if ((RD_REG_WORD(®->ctrl_status) &
2627 CSR_ISP_SOFT_RESET) == 0)
2634 /* Reset RISC processor. */
2635 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2637 WRT_REG_WORD(®->semaphore, 0);
2639 /* Release RISC processor. */
2640 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2641 RD_REG_WORD(®->hccr); /* PCI Posting. */
2643 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2644 for (cnt = 0; cnt < 30000; cnt++) {
2645 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2653 /* Turn on master enable */
2654 cmd |= PCI_COMMAND_MASTER;
2655 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2657 /* Disable RISC pause on FPM parity error. */
2658 if (!IS_QLA2100(ha)) {
2659 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2660 RD_REG_WORD(®->hccr); /* PCI Posting. */
2663 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2667 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2670 * Returns 0 on success.
2673 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2675 uint16_t mb[4] = {0x1010, 0, 1, 0};
2677 if (!IS_QLA81XX(vha->hw))
2680 return qla81xx_write_mpi_register(vha, mb);
2684 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2687 * Returns 0 on success.
2690 qla24xx_reset_risc(scsi_qla_host_t *vha)
2692 unsigned long flags = 0;
2693 struct qla_hw_data *ha = vha->hw;
2694 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2697 static int abts_cnt; /* ISP abort retry counts */
2698 int rval = QLA_SUCCESS;
2700 spin_lock_irqsave(&ha->hardware_lock, flags);
2703 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2704 for (cnt = 0; cnt < 30000; cnt++) {
2705 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2711 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2712 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2714 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2715 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2716 RD_REG_DWORD(®->hccr),
2717 RD_REG_DWORD(®->ctrl_status),
2718 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2720 WRT_REG_DWORD(®->ctrl_status,
2721 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2722 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2726 /* Wait for firmware to complete NVRAM accesses. */
2727 RD_REG_WORD(®->mailbox0);
2728 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2729 rval == QLA_SUCCESS; cnt--) {
2734 rval = QLA_FUNCTION_TIMEOUT;
2737 if (rval == QLA_SUCCESS)
2738 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2740 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2741 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2742 RD_REG_DWORD(®->hccr),
2743 RD_REG_DWORD(®->mailbox0));
2745 /* Wait for soft-reset to complete. */
2746 RD_REG_DWORD(®->ctrl_status);
2747 for (cnt = 0; cnt < 60; cnt++) {
2749 if ((RD_REG_DWORD(®->ctrl_status) &
2750 CSRX_ISP_SOFT_RESET) == 0)
2755 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2756 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2758 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2759 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2760 RD_REG_DWORD(®->hccr),
2761 RD_REG_DWORD(®->ctrl_status));
2763 /* If required, do an MPI FW reset now */
2764 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2765 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2766 if (++abts_cnt < 5) {
2767 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2768 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2771 * We exhausted the ISP abort retries. We have to
2772 * set the board offline.
2775 vha->flags.online = 0;
2780 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2781 RD_REG_DWORD(®->hccr);
2783 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2784 RD_REG_DWORD(®->hccr);
2786 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2787 RD_REG_DWORD(®->hccr);
2789 RD_REG_WORD(®->mailbox0);
2790 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2791 rval == QLA_SUCCESS; cnt--) {
2796 rval = QLA_FUNCTION_TIMEOUT;
2798 if (rval == QLA_SUCCESS)
2799 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2801 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2802 "Host Risc 0x%x, mailbox0 0x%x\n",
2803 RD_REG_DWORD(®->hccr),
2804 RD_REG_WORD(®->mailbox0));
2806 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2808 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2809 "Driver in %s mode\n",
2810 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2812 if (IS_NOPOLLING_TYPE(ha))
2813 ha->isp_ops->enable_intrs(ha);
2819 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2821 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2823 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2824 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2829 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2831 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2833 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2834 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2838 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2841 uint delta_msec = 100;
2842 uint elapsed_msec = 0;
2846 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2847 vha->hw->pdev->subsystem_device != 0x0240)
2850 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2854 timeout_msec = TIMEOUT_SEMAPHORE;
2855 n = timeout_msec / delta_msec;
2857 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2858 qla25xx_read_risc_sema_reg(vha, &wd32);
2859 if (wd32 & RISC_SEMAPHORE)
2862 elapsed_msec += delta_msec;
2863 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2867 if (!(wd32 & RISC_SEMAPHORE))
2870 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2873 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2874 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2875 n = timeout_msec / delta_msec;
2877 qla25xx_read_risc_sema_reg(vha, &wd32);
2878 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2881 elapsed_msec += delta_msec;
2882 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2886 if (wd32 & RISC_SEMAPHORE_FORCE)
2887 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2892 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2899 * qla24xx_reset_chip() - Reset ISP24xx chip.
2902 * Returns 0 on success.
2905 qla24xx_reset_chip(scsi_qla_host_t *vha)
2907 struct qla_hw_data *ha = vha->hw;
2909 if (pci_channel_offline(ha->pdev) &&
2910 ha->flags.pci_channel_io_perm_failure) {
2914 ha->isp_ops->disable_intrs(ha);
2916 qla25xx_manipulate_risc_semaphore(vha);
2918 /* Perform RISC reset. */
2919 qla24xx_reset_risc(vha);
2923 * qla2x00_chip_diag() - Test chip for proper operation.
2926 * Returns 0 on success.
2929 qla2x00_chip_diag(scsi_qla_host_t *vha)
2932 struct qla_hw_data *ha = vha->hw;
2933 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2934 unsigned long flags = 0;
2938 struct req_que *req = ha->req_q_map[0];
2940 /* Assume a failed state */
2941 rval = QLA_FUNCTION_FAILED;
2943 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2944 ®->flash_address);
2946 spin_lock_irqsave(&ha->hardware_lock, flags);
2948 /* Reset ISP chip. */
2949 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2952 * We need to have a delay here since the card will not respond while
2953 * in reset causing an MCA on some architectures.
2956 data = qla2x00_debounce_register(®->ctrl_status);
2957 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2959 data = RD_REG_WORD(®->ctrl_status);
2964 goto chip_diag_failed;
2966 ql_dbg(ql_dbg_init, vha, 0x007c,
2967 "Reset register cleared by chip reset.\n");
2969 /* Reset RISC processor. */
2970 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2971 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2973 /* Workaround for QLA2312 PCI parity error */
2974 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2975 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2976 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2978 data = RD_MAILBOX_REG(ha, reg, 0);
2985 goto chip_diag_failed;
2987 /* Check product ID of chip */
2988 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
2990 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2991 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2992 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2993 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2994 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2995 mb[3] != PROD_ID_3) {
2996 ql_log(ql_log_warn, vha, 0x0062,
2997 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2998 mb[1], mb[2], mb[3]);
3000 goto chip_diag_failed;
3002 ha->product_id[0] = mb[1];
3003 ha->product_id[1] = mb[2];
3004 ha->product_id[2] = mb[3];
3005 ha->product_id[3] = mb[4];
3007 /* Adjust fw RISC transfer size */
3008 if (req->length > 1024)
3009 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3011 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3014 if (IS_QLA2200(ha) &&
3015 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3016 /* Limit firmware transfer size with a 2200A */
3017 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3019 ha->device_type |= DT_ISP2200A;
3020 ha->fw_transfer_size = 128;
3023 /* Wrap Incoming Mailboxes Test. */
3024 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3026 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3027 rval = qla2x00_mbx_reg_test(vha);
3029 ql_log(ql_log_warn, vha, 0x0080,
3030 "Failed mailbox send register test.\n");
3032 /* Flag a successful rval */
3034 spin_lock_irqsave(&ha->hardware_lock, flags);
3038 ql_log(ql_log_info, vha, 0x0081,
3039 "Chip diagnostics **** FAILED ****.\n");
3041 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3047 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3050 * Returns 0 on success.
3053 qla24xx_chip_diag(scsi_qla_host_t *vha)
3056 struct qla_hw_data *ha = vha->hw;
3057 struct req_que *req = ha->req_q_map[0];
3059 if (IS_P3P_TYPE(ha))
3062 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3064 rval = qla2x00_mbx_reg_test(vha);
3066 ql_log(ql_log_warn, vha, 0x0082,
3067 "Failed mailbox send register test.\n");
3069 /* Flag a successful rval */
3077 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3082 struct qla_hw_data *ha = vha->hw;
3085 ql_dbg(ql_dbg_init, vha, 0x00bd,
3086 "%s: Offload Mem is already allocated.\n",
3091 if (IS_FWI2_CAPABLE(ha)) {
3092 /* Allocate memory for Fibre Channel Event Buffer. */
3093 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3098 dma_free_coherent(&ha->pdev->dev,
3099 FCE_SIZE, ha->fce, ha->fce_dma);
3101 /* Allocate memory for Fibre Channel Event Buffer. */
3102 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3105 ql_log(ql_log_warn, vha, 0x00be,
3106 "Unable to allocate (%d KB) for FCE.\n",
3111 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3112 ha->fce_mb, &ha->fce_bufs);
3114 ql_log(ql_log_warn, vha, 0x00bf,
3115 "Unable to initialize FCE (%d).\n", rval);
3116 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3118 ha->flags.fce_enabled = 0;
3121 ql_dbg(ql_dbg_init, vha, 0x00c0,
3122 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3124 ha->flags.fce_enabled = 1;
3125 ha->fce_dma = tc_dma;
3130 dma_free_coherent(&ha->pdev->dev,
3131 EFT_SIZE, ha->eft, ha->eft_dma);
3133 /* Allocate memory for Extended Trace Buffer. */
3134 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3137 ql_log(ql_log_warn, vha, 0x00c1,
3138 "Unable to allocate (%d KB) for EFT.\n",
3143 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3145 ql_log(ql_log_warn, vha, 0x00c2,
3146 "Unable to initialize EFT (%d).\n", rval);
3147 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3151 ql_dbg(ql_dbg_init, vha, 0x00c3,
3152 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3154 ha->eft_dma = tc_dma;
3163 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3165 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3166 eft_size, fce_size, mq_size;
3167 struct qla_hw_data *ha = vha->hw;
3168 struct req_que *req = ha->req_q_map[0];
3169 struct rsp_que *rsp = ha->rsp_q_map[0];
3170 struct qla2xxx_fw_dump *fw_dump;
3172 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3173 req_q_size = rsp_q_size = 0;
3175 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3176 fixed_size = sizeof(struct qla2100_fw_dump);
3177 } else if (IS_QLA23XX(ha)) {
3178 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3179 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3181 } else if (IS_FWI2_CAPABLE(ha)) {
3182 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
3183 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3184 else if (IS_QLA81XX(ha))
3185 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3186 else if (IS_QLA25XX(ha))
3187 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3189 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3191 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3194 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
3195 mq_size = sizeof(struct qla2xxx_mq_chain);
3197 * Allocate maximum buffer size for all queues.
3198 * Resizing must be done at end-of-dump processing.
3200 mq_size += ha->max_req_queues *
3201 (req->length * sizeof(request_t));
3202 mq_size += ha->max_rsp_queues *
3203 (rsp->length * sizeof(response_t));
3205 if (ha->tgt.atio_ring)
3206 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3207 /* Allocate memory for Fibre Channel Event Buffer. */
3208 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3212 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3214 ql_dbg(ql_dbg_init, vha, 0x00c3,
3215 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3216 eft_size = EFT_SIZE;
3219 if (IS_QLA27XX(ha)) {
3220 if (!ha->fw_dump_template) {
3221 ql_log(ql_log_warn, vha, 0x00ba,
3222 "Failed missing fwdump template\n");
3225 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
3226 ql_dbg(ql_dbg_init, vha, 0x00fa,
3227 "-> allocating fwdump (%x bytes)...\n", dump_size);
3231 req_q_size = req->length * sizeof(request_t);
3232 rsp_q_size = rsp->length * sizeof(response_t);
3233 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3234 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3235 ha->chain_offset = dump_size;
3236 dump_size += mq_size + fce_size;
3238 if (ha->exchoffld_buf)
3239 dump_size += sizeof(struct qla2xxx_offld_chain) +
3241 if (ha->exlogin_buf)
3242 dump_size += sizeof(struct qla2xxx_offld_chain) +
3246 if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) {
3247 fw_dump = vmalloc(dump_size);
3249 ql_log(ql_log_warn, vha, 0x00c4,
3250 "Unable to allocate (%d KB) for firmware dump.\n",
3255 ha->fw_dump = fw_dump;
3257 ha->fw_dump_len = dump_size;
3258 ql_dbg(ql_dbg_init, vha, 0x00c5,
3259 "Allocated (%d KB) for firmware dump.\n",
3265 ha->fw_dump->signature[0] = 'Q';
3266 ha->fw_dump->signature[1] = 'L';
3267 ha->fw_dump->signature[2] = 'G';
3268 ha->fw_dump->signature[3] = 'C';
3269 ha->fw_dump->version = htonl(1);
3271 ha->fw_dump->fixed_size = htonl(fixed_size);
3272 ha->fw_dump->mem_size = htonl(mem_size);
3273 ha->fw_dump->req_q_size = htonl(req_q_size);
3274 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3276 ha->fw_dump->eft_size = htonl(eft_size);
3277 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
3278 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
3280 ha->fw_dump->header_size =
3281 htonl(offsetof(struct qla2xxx_fw_dump, isp));
3287 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3289 #define MPS_MASK 0xe0
3294 if (!IS_QLA81XX(vha->hw))
3297 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3298 if (rval != QLA_SUCCESS) {
3299 ql_log(ql_log_warn, vha, 0x0105,
3300 "Unable to acquire semaphore.\n");
3304 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3305 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3306 if (rval != QLA_SUCCESS) {
3307 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3312 if (dc == (dw & MPS_MASK))
3317 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3318 if (rval != QLA_SUCCESS) {
3319 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3323 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3324 if (rval != QLA_SUCCESS) {
3325 ql_log(ql_log_warn, vha, 0x006d,
3326 "Unable to release semaphore.\n");
3334 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3336 /* Don't try to reallocate the array */
3337 if (req->outstanding_cmds)
3340 if (!IS_FWI2_CAPABLE(ha))
3341 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3343 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3344 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3346 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3349 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3353 if (!req->outstanding_cmds) {
3355 * Try to allocate a minimal size just so we can get through
3358 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3359 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3363 if (!req->outstanding_cmds) {
3364 ql_log(ql_log_fatal, NULL, 0x0126,
3365 "Failed to allocate memory for "
3366 "outstanding_cmds for req_que %p.\n", req);
3367 req->num_outstanding_cmds = 0;
3368 return QLA_FUNCTION_FAILED;
3375 #define PRINT_FIELD(_field, _flag, _str) { \
3376 if (a0->_field & _flag) {\
3382 len = snprintf(ptr, leftover, "%s", _str); \
3389 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3392 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3393 u8 str[STR_LEN], *ptr, p;
3396 memset(str, 0, STR_LEN);
3397 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3398 ql_dbg(ql_dbg_init, vha, 0x015a,
3399 "SFP MFG Name: %s\n", str);
3401 memset(str, 0, STR_LEN);
3402 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3403 ql_dbg(ql_dbg_init, vha, 0x015c,
3404 "SFP Part Name: %s\n", str);
3407 memset(str, 0, STR_LEN);
3411 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3412 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3413 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3414 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3415 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3416 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3417 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3418 ql_dbg(ql_dbg_init, vha, 0x0160,
3419 "SFP Media: %s\n", str);
3422 memset(str, 0, STR_LEN);
3426 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3427 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3428 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3429 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3430 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3431 ql_dbg(ql_dbg_init, vha, 0x0196,
3432 "SFP Link Length: %s\n", str);
3434 memset(str, 0, STR_LEN);
3438 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3439 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3440 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3441 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3442 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3443 ql_dbg(ql_dbg_init, vha, 0x016e,
3444 "SFP FC Link Tech: %s\n", str);
3447 ql_dbg(ql_dbg_init, vha, 0x016f,
3448 "SFP Distant: %d km\n", a0->length_km);
3449 if (a0->length_100m)
3450 ql_dbg(ql_dbg_init, vha, 0x0170,
3451 "SFP Distant: %d m\n", a0->length_100m*100);
3452 if (a0->length_50um_10m)
3453 ql_dbg(ql_dbg_init, vha, 0x0189,
3454 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3455 if (a0->length_62um_10m)
3456 ql_dbg(ql_dbg_init, vha, 0x018a,
3457 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3458 if (a0->length_om4_10m)
3459 ql_dbg(ql_dbg_init, vha, 0x0194,
3460 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3461 if (a0->length_om3_10m)
3462 ql_dbg(ql_dbg_init, vha, 0x0195,
3463 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3469 * QLA_SUCCESS: no action
3470 * QLA_INTERFACE_ERROR: SFP is not there.
3471 * QLA_FUNCTION_FAILED: detected New SFP
3474 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3476 int rc = QLA_SUCCESS;
3477 struct sff_8247_a0 *a;
3478 struct qla_hw_data *ha = vha->hw;
3480 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3483 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3487 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3488 qla2xxx_print_sfp_info(vha);
3490 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3492 ha->flags.detected_lr_sfp = 1;
3494 if (a->length_km > 5 || a->length_100m > 50)
3495 ha->long_range_distance = LR_DISTANCE_10K;
3497 ha->long_range_distance = LR_DISTANCE_5K;
3499 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3500 ql_dbg(ql_dbg_async, vha, 0x507b,
3501 "Detected Long Range SFP.\n");
3504 ha->flags.detected_lr_sfp = 0;
3505 if (ha->flags.using_lr_setting)
3506 ql_dbg(ql_dbg_async, vha, 0x5084,
3507 "Detected Short Range SFP.\n");
3510 if (!vha->flags.init_done)
3517 * qla2x00_setup_chip() - Load and start RISC firmware.
3520 * Returns 0 on success.
3523 qla2x00_setup_chip(scsi_qla_host_t *vha)
3526 uint32_t srisc_address = 0;
3527 struct qla_hw_data *ha = vha->hw;
3528 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3529 unsigned long flags;
3530 uint16_t fw_major_version;
3532 if (IS_P3P_TYPE(ha)) {
3533 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3534 if (rval == QLA_SUCCESS) {
3535 qla2x00_stop_firmware(vha);
3536 goto enable_82xx_npiv;
3541 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3542 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3543 spin_lock_irqsave(&ha->hardware_lock, flags);
3544 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3545 RD_REG_WORD(®->hccr);
3546 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3549 qla81xx_mpi_sync(vha);
3551 /* Load firmware sequences */
3552 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3553 if (rval == QLA_SUCCESS) {
3554 ql_dbg(ql_dbg_init, vha, 0x00c9,
3555 "Verifying Checksum of loaded RISC code.\n");
3557 rval = qla2x00_verify_checksum(vha, srisc_address);
3558 if (rval == QLA_SUCCESS) {
3559 /* Start firmware execution. */
3560 ql_dbg(ql_dbg_init, vha, 0x00ca,
3561 "Starting firmware.\n");
3564 ha->flags.exlogins_enabled = 1;
3566 if (qla_is_exch_offld_enabled(vha))
3567 ha->flags.exchoffld_enabled = 1;
3569 rval = qla2x00_execute_fw(vha, srisc_address);
3570 /* Retrieve firmware information. */
3571 if (rval == QLA_SUCCESS) {
3572 qla24xx_detect_sfp(vha);
3574 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) &&
3575 (ha->zio_mode == QLA_ZIO_MODE_6))
3576 qla27xx_set_zio_threshold(vha,
3577 ha->last_zio_threshold);
3579 rval = qla2x00_set_exlogins_buffer(vha);
3580 if (rval != QLA_SUCCESS)
3583 rval = qla2x00_set_exchoffld_buffer(vha);
3584 if (rval != QLA_SUCCESS)
3588 fw_major_version = ha->fw_major_version;
3589 if (IS_P3P_TYPE(ha))
3590 qla82xx_check_md_needed(vha);
3592 rval = qla2x00_get_fw_version(vha);
3593 if (rval != QLA_SUCCESS)
3595 ha->flags.npiv_supported = 0;
3596 if (IS_QLA2XXX_MIDTYPE(ha) &&
3597 (ha->fw_attributes & BIT_2)) {
3598 ha->flags.npiv_supported = 1;
3599 if ((!ha->max_npiv_vports) ||
3600 ((ha->max_npiv_vports + 1) %
3601 MIN_MULTI_ID_FABRIC))
3602 ha->max_npiv_vports =
3603 MIN_MULTI_ID_FABRIC - 1;
3605 qla2x00_get_resource_cnts(vha);
3608 * Allocate the array of outstanding commands
3609 * now that we know the firmware resources.
3611 rval = qla2x00_alloc_outstanding_cmds(ha,
3613 if (rval != QLA_SUCCESS)
3616 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3617 qla2x00_alloc_offload_mem(vha);
3619 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3620 qla2x00_alloc_fw_dump(vha);
3626 ql_log(ql_log_fatal, vha, 0x00cd,
3627 "ISP Firmware failed checksum.\n");
3633 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3634 /* Enable proper parity. */
3635 spin_lock_irqsave(&ha->hardware_lock, flags);
3638 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3640 /* SRAM, Instruction RAM and GP RAM parity */
3641 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3642 RD_REG_WORD(®->hccr);
3643 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3647 ha->flags.fac_supported = 1;
3648 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3651 rval = qla81xx_fac_get_sector_size(vha, &size);
3652 if (rval == QLA_SUCCESS) {
3653 ha->flags.fac_supported = 1;
3654 ha->fdt_block_size = size << 2;
3656 ql_log(ql_log_warn, vha, 0x00ce,
3657 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3658 ha->fw_major_version, ha->fw_minor_version,
3659 ha->fw_subminor_version);
3661 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3662 ha->flags.fac_supported = 0;
3669 ql_log(ql_log_fatal, vha, 0x00cf,
3670 "Setup chip ****FAILED****.\n");
3677 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3678 * @rsp: response queue
3680 * Beginning of request ring has initialization control block already built
3681 * by nvram config routine.
3683 * Returns 0 on success.
3686 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3691 rsp->ring_ptr = rsp->ring;
3692 rsp->ring_index = 0;
3693 rsp->status_srb = NULL;
3694 pkt = rsp->ring_ptr;
3695 for (cnt = 0; cnt < rsp->length; cnt++) {
3696 pkt->signature = RESPONSE_PROCESSED;
3702 * qla2x00_update_fw_options() - Read and process firmware options.
3705 * Returns 0 on success.
3708 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3710 uint16_t swing, emphasis, tx_sens, rx_sens;
3711 struct qla_hw_data *ha = vha->hw;
3713 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3714 qla2x00_get_fw_options(vha, ha->fw_options);
3716 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3719 /* Serial Link options. */
3720 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3721 "Serial link options.\n");
3722 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3723 (uint8_t *)&ha->fw_seriallink_options,
3724 sizeof(ha->fw_seriallink_options));
3726 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3727 if (ha->fw_seriallink_options[3] & BIT_2) {
3728 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3731 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3732 emphasis = (ha->fw_seriallink_options[2] &
3733 (BIT_4 | BIT_3)) >> 3;
3734 tx_sens = ha->fw_seriallink_options[0] &
3735 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3736 rx_sens = (ha->fw_seriallink_options[0] &
3737 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3738 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3739 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3742 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3743 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3744 ha->fw_options[10] |= BIT_5 |
3745 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3746 (tx_sens & (BIT_1 | BIT_0));
3749 swing = (ha->fw_seriallink_options[2] &
3750 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3751 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3752 tx_sens = ha->fw_seriallink_options[1] &
3753 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3754 rx_sens = (ha->fw_seriallink_options[1] &
3755 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3756 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3757 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3760 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3761 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3762 ha->fw_options[11] |= BIT_5 |
3763 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3764 (tx_sens & (BIT_1 | BIT_0));
3768 /* Return command IOCBs without waiting for an ABTS to complete. */
3769 ha->fw_options[3] |= BIT_13;
3772 if (ha->flags.enable_led_scheme)
3773 ha->fw_options[2] |= BIT_12;
3775 /* Detect ISP6312. */
3777 ha->fw_options[2] |= BIT_13;
3779 /* Set Retry FLOGI in case of P2P connection */
3780 if (ha->operating_mode == P2P) {
3781 ha->fw_options[2] |= BIT_3;
3782 ql_dbg(ql_dbg_disc, vha, 0x2100,
3783 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3784 __func__, ha->fw_options[2]);
3787 /* Update firmware options. */
3788 qla2x00_set_fw_options(vha, ha->fw_options);
3792 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3795 struct qla_hw_data *ha = vha->hw;
3797 if (IS_P3P_TYPE(ha))
3800 /* Hold status IOCBs until ABTS response received. */
3802 ha->fw_options[3] |= BIT_12;
3804 /* Set Retry FLOGI in case of P2P connection */
3805 if (ha->operating_mode == P2P) {
3806 ha->fw_options[2] |= BIT_3;
3807 ql_dbg(ql_dbg_disc, vha, 0x2101,
3808 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3809 __func__, ha->fw_options[2]);
3812 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3813 if (ql2xmvasynctoatio &&
3814 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
3815 if (qla_tgt_mode_enabled(vha) ||
3816 qla_dual_mode_enabled(vha))
3817 ha->fw_options[2] |= BIT_11;
3819 ha->fw_options[2] &= ~BIT_11;
3822 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3824 * Tell FW to track each exchange to prevent
3825 * driver from using stale exchange.
3827 if (qla_tgt_mode_enabled(vha) ||
3828 qla_dual_mode_enabled(vha))
3829 ha->fw_options[2] |= BIT_4;
3831 ha->fw_options[2] &= ~BIT_4;
3833 /* Reserve 1/2 of emergency exchanges for ELS.*/
3834 if (qla2xuseresexchforels)
3835 ha->fw_options[2] |= BIT_8;
3837 ha->fw_options[2] &= ~BIT_8;
3840 ql_dbg(ql_dbg_init, vha, 0x00e8,
3841 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3842 __func__, ha->fw_options[1], ha->fw_options[2],
3843 ha->fw_options[3], vha->host->active_mode);
3845 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3846 qla2x00_set_fw_options(vha, ha->fw_options);
3848 /* Update Serial Link options. */
3849 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3852 rval = qla2x00_set_serdes_params(vha,
3853 le16_to_cpu(ha->fw_seriallink_options24[1]),
3854 le16_to_cpu(ha->fw_seriallink_options24[2]),
3855 le16_to_cpu(ha->fw_seriallink_options24[3]));
3856 if (rval != QLA_SUCCESS) {
3857 ql_log(ql_log_warn, vha, 0x0104,
3858 "Unable to update Serial Link options (%x).\n", rval);
3863 qla2x00_config_rings(struct scsi_qla_host *vha)
3865 struct qla_hw_data *ha = vha->hw;
3866 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3867 struct req_que *req = ha->req_q_map[0];
3868 struct rsp_que *rsp = ha->rsp_q_map[0];
3870 /* Setup ring parameters in initialization control block. */
3871 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3872 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3873 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3874 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3875 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3876 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3877 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3878 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3880 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3881 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3882 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3883 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3884 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3888 qla24xx_config_rings(struct scsi_qla_host *vha)
3890 struct qla_hw_data *ha = vha->hw;
3891 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3892 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3893 struct qla_msix_entry *msix;
3894 struct init_cb_24xx *icb;
3896 struct req_que *req = ha->req_q_map[0];
3897 struct rsp_que *rsp = ha->rsp_q_map[0];
3899 /* Setup ring parameters in initialization control block. */
3900 icb = (struct init_cb_24xx *)ha->init_cb;
3901 icb->request_q_outpointer = cpu_to_le16(0);
3902 icb->response_q_inpointer = cpu_to_le16(0);
3903 icb->request_q_length = cpu_to_le16(req->length);
3904 icb->response_q_length = cpu_to_le16(rsp->length);
3905 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3906 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3907 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3908 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3910 /* Setup ATIO queue dma pointers for target mode */
3911 icb->atio_q_inpointer = cpu_to_le16(0);
3912 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3913 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3914 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3916 if (IS_SHADOW_REG_CAPABLE(ha))
3917 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3919 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3920 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3921 icb->rid = cpu_to_le16(rid);
3922 if (ha->flags.msix_enabled) {
3923 msix = &ha->msix_entries[1];
3924 ql_dbg(ql_dbg_init, vha, 0x0019,
3925 "Registering vector 0x%x for base que.\n",
3927 icb->msix = cpu_to_le16(msix->entry);
3929 /* Use alternate PCI bus number */
3931 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
3932 /* Use alternate PCI devfn */
3934 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
3936 /* Use Disable MSIX Handshake mode for capable adapters */
3937 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3938 (ha->flags.msix_enabled)) {
3939 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
3940 ha->flags.disable_msix_handshake = 1;
3941 ql_dbg(ql_dbg_init, vha, 0x00fe,
3942 "MSIX Handshake Disable Mode turned on.\n");
3944 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
3946 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
3948 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
3949 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
3950 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
3951 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
3953 WRT_REG_DWORD(®->isp24.req_q_in, 0);
3954 WRT_REG_DWORD(®->isp24.req_q_out, 0);
3955 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
3956 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
3958 qlt_24xx_config_rings(vha);
3961 RD_REG_DWORD(&ioreg->hccr);
3965 * qla2x00_init_rings() - Initializes firmware.
3968 * Beginning of request ring has initialization control block already built
3969 * by nvram config routine.
3971 * Returns 0 on success.
3974 qla2x00_init_rings(scsi_qla_host_t *vha)
3977 unsigned long flags = 0;
3979 struct qla_hw_data *ha = vha->hw;
3980 struct req_que *req;
3981 struct rsp_que *rsp;
3982 struct mid_init_cb_24xx *mid_init_cb =
3983 (struct mid_init_cb_24xx *) ha->init_cb;
3985 spin_lock_irqsave(&ha->hardware_lock, flags);
3987 /* Clear outstanding commands array. */
3988 for (que = 0; que < ha->max_req_queues; que++) {
3989 req = ha->req_q_map[que];
3990 if (!req || !test_bit(que, ha->req_qid_map))
3992 req->out_ptr = (void *)(req->ring + req->length);
3994 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
3995 req->outstanding_cmds[cnt] = NULL;
3997 req->current_outstanding_cmd = 1;
3999 /* Initialize firmware. */
4000 req->ring_ptr = req->ring;
4001 req->ring_index = 0;
4002 req->cnt = req->length;
4005 for (que = 0; que < ha->max_rsp_queues; que++) {
4006 rsp = ha->rsp_q_map[que];
4007 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4009 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4011 /* Initialize response queue entries */
4013 qlafx00_init_response_q_entries(rsp);
4015 qla2x00_init_response_q_entries(rsp);
4018 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4019 ha->tgt.atio_ring_index = 0;
4020 /* Initialize ATIO queue entries */
4021 qlt_init_atio_q_entries(vha);
4023 ha->isp_ops->config_rings(vha);
4025 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4027 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4029 if (IS_QLAFX00(ha)) {
4030 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4034 /* Update any ISP specific firmware options before initialization. */
4035 ha->isp_ops->update_fw_options(vha);
4037 if (ha->flags.npiv_supported) {
4038 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4039 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4040 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4043 if (IS_FWI2_CAPABLE(ha)) {
4044 mid_init_cb->options = cpu_to_le16(BIT_1);
4045 mid_init_cb->init_cb.execution_throttle =
4046 cpu_to_le16(ha->cur_fw_xcb_count);
4047 ha->flags.dport_enabled =
4048 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4049 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4050 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4051 /* FA-WWPN Status */
4052 ha->flags.fawwpn_enabled =
4053 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4054 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4055 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4058 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4061 ql_log(ql_log_fatal, vha, 0x00d2,
4062 "Init Firmware **** FAILED ****.\n");
4064 ql_dbg(ql_dbg_init, vha, 0x00d3,
4065 "Init Firmware -- success.\n");
4067 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4074 * qla2x00_fw_ready() - Waits for firmware ready.
4077 * Returns 0 on success.
4080 qla2x00_fw_ready(scsi_qla_host_t *vha)
4083 unsigned long wtime, mtime, cs84xx_time;
4084 uint16_t min_wait; /* Minimum wait time if loop is down */
4085 uint16_t wait_time; /* Wait time if loop is coming ready */
4087 struct qla_hw_data *ha = vha->hw;
4089 if (IS_QLAFX00(vha->hw))
4090 return qlafx00_fw_ready(vha);
4094 /* Time to wait for loop down */
4095 if (IS_P3P_TYPE(ha))
4101 * Firmware should take at most one RATOV to login, plus 5 seconds for
4102 * our own processing.
4104 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4105 wait_time = min_wait;
4108 /* Min wait time if loop down */
4109 mtime = jiffies + (min_wait * HZ);
4111 /* wait time before firmware ready */
4112 wtime = jiffies + (wait_time * HZ);
4114 /* Wait for ISP to finish LIP */
4115 if (!vha->flags.init_done)
4116 ql_log(ql_log_info, vha, 0x801e,
4117 "Waiting for LIP to complete.\n");
4120 memset(state, -1, sizeof(state));
4121 rval = qla2x00_get_firmware_state(vha, state);
4122 if (rval == QLA_SUCCESS) {
4123 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4124 vha->device_flags &= ~DFLG_NO_CABLE;
4126 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4127 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4128 "fw_state=%x 84xx=%x.\n", state[0],
4130 if ((state[2] & FSTATE_LOGGED_IN) &&
4131 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4132 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4133 "Sending verify iocb.\n");
4135 cs84xx_time = jiffies;
4136 rval = qla84xx_init_chip(vha);
4137 if (rval != QLA_SUCCESS) {
4140 "Init chip failed.\n");
4144 /* Add time taken to initialize. */
4145 cs84xx_time = jiffies - cs84xx_time;
4146 wtime += cs84xx_time;
4147 mtime += cs84xx_time;
4148 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4149 "Increasing wait time by %ld. "
4150 "New time %ld.\n", cs84xx_time,
4153 } else if (state[0] == FSTATE_READY) {
4154 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4155 "F/W Ready - OK.\n");
4157 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4158 &ha->login_timeout, &ha->r_a_tov);
4164 rval = QLA_FUNCTION_FAILED;
4166 if (atomic_read(&vha->loop_down_timer) &&
4167 state[0] != FSTATE_READY) {
4168 /* Loop down. Timeout on min_wait for states
4169 * other than Wait for Login.
4171 if (time_after_eq(jiffies, mtime)) {
4172 ql_log(ql_log_info, vha, 0x8038,
4173 "Cable is unplugged...\n");
4175 vha->device_flags |= DFLG_NO_CABLE;
4180 /* Mailbox cmd failed. Timeout on min_wait. */
4181 if (time_after_eq(jiffies, mtime) ||
4182 ha->flags.isp82xx_fw_hung)
4186 if (time_after_eq(jiffies, wtime))
4189 /* Delay for a while */
4193 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4194 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4195 state[1], state[2], state[3], state[4], state[5], jiffies);
4197 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4198 ql_log(ql_log_warn, vha, 0x803b,
4199 "Firmware ready **** FAILED ****.\n");
4206 * qla2x00_configure_hba
4207 * Setup adapter context.
4210 * ha = adapter state pointer.
4219 qla2x00_configure_hba(scsi_qla_host_t *vha)
4228 char connect_type[22];
4229 struct qla_hw_data *ha = vha->hw;
4230 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4232 unsigned long flags;
4234 /* Get host addresses. */
4235 rval = qla2x00_get_adapter_id(vha,
4236 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4237 if (rval != QLA_SUCCESS) {
4238 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4239 IS_CNA_CAPABLE(ha) ||
4240 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4241 ql_dbg(ql_dbg_disc, vha, 0x2008,
4242 "Loop is in a transition state.\n");
4244 ql_log(ql_log_warn, vha, 0x2009,
4245 "Unable to get host loop ID.\n");
4246 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4247 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4248 ql_log(ql_log_warn, vha, 0x1151,
4249 "Doing link init.\n");
4250 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4253 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4259 ql_log(ql_log_info, vha, 0x200a,
4260 "Cannot get topology - retrying.\n");
4261 return (QLA_FUNCTION_FAILED);
4264 vha->loop_id = loop_id;
4267 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4268 ha->operating_mode = LOOP;
4273 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4274 ha->current_topology = ISP_CFG_NL;
4275 strcpy(connect_type, "(Loop)");
4279 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4280 ha->switch_cap = sw_cap;
4281 ha->current_topology = ISP_CFG_FL;
4282 strcpy(connect_type, "(FL_Port)");
4286 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4287 ha->operating_mode = P2P;
4288 ha->current_topology = ISP_CFG_N;
4289 strcpy(connect_type, "(N_Port-to-N_Port)");
4293 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4294 ha->switch_cap = sw_cap;
4295 ha->operating_mode = P2P;
4296 ha->current_topology = ISP_CFG_F;
4297 strcpy(connect_type, "(F_Port)");
4301 ql_dbg(ql_dbg_disc, vha, 0x200f,
4302 "HBA in unknown topology %x, using NL.\n", topo);
4303 ha->current_topology = ISP_CFG_NL;
4304 strcpy(connect_type, "(Loop)");
4308 /* Save Host port and loop ID. */
4309 /* byte order - Big Endian */
4310 id.b.domain = domain;
4314 spin_lock_irqsave(&ha->hardware_lock, flags);
4315 if (!(topo == 2 && ha->flags.n2n_bigger))
4316 qlt_update_host_map(vha, id);
4317 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4319 if (!vha->flags.init_done)
4320 ql_log(ql_log_info, vha, 0x2010,
4321 "Topology - %s, Host Loop address 0x%x.\n",
4322 connect_type, vha->loop_id);
4328 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4333 struct qla_hw_data *ha = vha->hw;
4334 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4335 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4337 if (memcmp(model, BINZERO, len) != 0) {
4338 strncpy(ha->model_number, model, len);
4339 st = en = ha->model_number;
4342 if (*en != 0x20 && *en != 0x00)
4347 index = (ha->pdev->subsystem_device & 0xff);
4349 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4350 index < QLA_MODEL_NAMES)
4351 strncpy(ha->model_desc,
4352 qla2x00_model_name[index * 2 + 1],
4353 sizeof(ha->model_desc) - 1);
4355 index = (ha->pdev->subsystem_device & 0xff);
4357 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4358 index < QLA_MODEL_NAMES) {
4359 strcpy(ha->model_number,
4360 qla2x00_model_name[index * 2]);
4361 strncpy(ha->model_desc,
4362 qla2x00_model_name[index * 2 + 1],
4363 sizeof(ha->model_desc) - 1);
4365 strcpy(ha->model_number, def);
4368 if (IS_FWI2_CAPABLE(ha))
4369 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4370 sizeof(ha->model_desc));
4373 /* On sparc systems, obtain port and node WWN from firmware
4376 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4379 struct qla_hw_data *ha = vha->hw;
4380 struct pci_dev *pdev = ha->pdev;
4381 struct device_node *dp = pci_device_to_OF_node(pdev);
4385 val = of_get_property(dp, "port-wwn", &len);
4386 if (val && len >= WWN_SIZE)
4387 memcpy(nv->port_name, val, WWN_SIZE);
4389 val = of_get_property(dp, "node-wwn", &len);
4390 if (val && len >= WWN_SIZE)
4391 memcpy(nv->node_name, val, WWN_SIZE);
4396 * NVRAM configuration for ISP 2xxx
4399 * ha = adapter block pointer.
4402 * initialization control block in response_ring
4403 * host adapters parameters in host adapter block
4409 qla2x00_nvram_config(scsi_qla_host_t *vha)
4414 uint8_t *dptr1, *dptr2;
4415 struct qla_hw_data *ha = vha->hw;
4416 init_cb_t *icb = ha->init_cb;
4417 nvram_t *nv = ha->nvram;
4418 uint8_t *ptr = ha->nvram;
4419 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4423 /* Determine NVRAM starting address. */
4424 ha->nvram_size = sizeof(nvram_t);
4426 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4427 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4428 ha->nvram_base = 0x80;
4430 /* Get NVRAM data and calculate checksum. */
4431 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4432 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4435 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4436 "Contents of NVRAM.\n");
4437 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4438 (uint8_t *)nv, ha->nvram_size);
4440 /* Bad NVRAM data, set defaults parameters. */
4441 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
4442 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
4443 /* Reset NVRAM data. */
4444 ql_log(ql_log_warn, vha, 0x0064,
4445 "Inconsistent NVRAM "
4446 "detected: checksum=0x%x id=%c version=0x%x.\n",
4447 chksum, nv->id[0], nv->nvram_version);
4448 ql_log(ql_log_warn, vha, 0x0065,
4450 "functioning (yet invalid -- WWPN) defaults.\n");
4453 * Set default initialization control block.
4455 memset(nv, 0, ha->nvram_size);
4456 nv->parameter_block_version = ICB_VERSION;
4458 if (IS_QLA23XX(ha)) {
4459 nv->firmware_options[0] = BIT_2 | BIT_1;
4460 nv->firmware_options[1] = BIT_7 | BIT_5;
4461 nv->add_firmware_options[0] = BIT_5;
4462 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4463 nv->frame_payload_size = 2048;
4464 nv->special_options[1] = BIT_7;
4465 } else if (IS_QLA2200(ha)) {
4466 nv->firmware_options[0] = BIT_2 | BIT_1;
4467 nv->firmware_options[1] = BIT_7 | BIT_5;
4468 nv->add_firmware_options[0] = BIT_5;
4469 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4470 nv->frame_payload_size = 1024;
4471 } else if (IS_QLA2100(ha)) {
4472 nv->firmware_options[0] = BIT_3 | BIT_1;
4473 nv->firmware_options[1] = BIT_5;
4474 nv->frame_payload_size = 1024;
4477 nv->max_iocb_allocation = cpu_to_le16(256);
4478 nv->execution_throttle = cpu_to_le16(16);
4479 nv->retry_count = 8;
4480 nv->retry_delay = 1;
4482 nv->port_name[0] = 33;
4483 nv->port_name[3] = 224;
4484 nv->port_name[4] = 139;
4486 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4488 nv->login_timeout = 4;
4491 * Set default host adapter parameters
4493 nv->host_p[1] = BIT_2;
4494 nv->reset_delay = 5;
4495 nv->port_down_retry_count = 8;
4496 nv->max_luns_per_target = cpu_to_le16(8);
4497 nv->link_down_timeout = 60;
4502 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4504 * The SN2 does not provide BIOS emulation which means you can't change
4505 * potentially bogus BIOS settings. Force the use of default settings
4506 * for link rate and frame size. Hope that the rest of the settings
4509 if (ia64_platform_is("sn2")) {
4510 nv->frame_payload_size = 2048;
4512 nv->special_options[1] = BIT_7;
4516 /* Reset Initialization control block */
4517 memset(icb, 0, ha->init_cb_size);
4520 * Setup driver NVRAM options.
4522 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4523 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4524 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4525 nv->firmware_options[1] &= ~BIT_4;
4527 if (IS_QLA23XX(ha)) {
4528 nv->firmware_options[0] |= BIT_2;
4529 nv->firmware_options[0] &= ~BIT_3;
4530 nv->special_options[0] &= ~BIT_6;
4531 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4533 if (IS_QLA2300(ha)) {
4534 if (ha->fb_rev == FPM_2310) {
4535 strcpy(ha->model_number, "QLA2310");
4537 strcpy(ha->model_number, "QLA2300");
4540 qla2x00_set_model_info(vha, nv->model_number,
4541 sizeof(nv->model_number), "QLA23xx");
4543 } else if (IS_QLA2200(ha)) {
4544 nv->firmware_options[0] |= BIT_2;
4546 * 'Point-to-point preferred, else loop' is not a safe
4547 * connection mode setting.
4549 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4551 /* Force 'loop preferred, else point-to-point'. */
4552 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4553 nv->add_firmware_options[0] |= BIT_5;
4555 strcpy(ha->model_number, "QLA22xx");
4556 } else /*if (IS_QLA2100(ha))*/ {
4557 strcpy(ha->model_number, "QLA2100");
4561 * Copy over NVRAM RISC parameter block to initialization control block.
4563 dptr1 = (uint8_t *)icb;
4564 dptr2 = (uint8_t *)&nv->parameter_block_version;
4565 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4567 *dptr1++ = *dptr2++;
4569 /* Copy 2nd half. */
4570 dptr1 = (uint8_t *)icb->add_firmware_options;
4571 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4573 *dptr1++ = *dptr2++;
4574 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4575 /* Use alternate WWN? */
4576 if (nv->host_p[1] & BIT_7) {
4577 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4578 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4581 /* Prepare nodename */
4582 if ((icb->firmware_options[1] & BIT_6) == 0) {
4584 * Firmware will apply the following mask if the nodename was
4587 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4588 icb->node_name[0] &= 0xF0;
4592 * Set host adapter parameters.
4596 * BIT_7 in the host-parameters section allows for modification to
4597 * internal driver logging.
4599 if (nv->host_p[0] & BIT_7)
4600 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4601 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4602 /* Always load RISC code on non ISP2[12]00 chips. */
4603 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4604 ha->flags.disable_risc_code_load = 0;
4605 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4606 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4607 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4608 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4609 ha->flags.disable_serdes = 0;
4611 ha->operating_mode =
4612 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4614 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4615 sizeof(ha->fw_seriallink_options));
4617 /* save HBA serial number */
4618 ha->serial0 = icb->port_name[5];
4619 ha->serial1 = icb->port_name[6];
4620 ha->serial2 = icb->port_name[7];
4621 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4622 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4624 icb->execution_throttle = cpu_to_le16(0xFFFF);
4626 ha->retry_count = nv->retry_count;
4628 /* Set minimum login_timeout to 4 seconds. */
4629 if (nv->login_timeout != ql2xlogintimeout)
4630 nv->login_timeout = ql2xlogintimeout;
4631 if (nv->login_timeout < 4)
4632 nv->login_timeout = 4;
4633 ha->login_timeout = nv->login_timeout;
4635 /* Set minimum RATOV to 100 tenths of a second. */
4638 ha->loop_reset_delay = nv->reset_delay;
4640 /* Link Down Timeout = 0:
4642 * When Port Down timer expires we will start returning
4643 * I/O's to OS with "DID_NO_CONNECT".
4645 * Link Down Timeout != 0:
4647 * The driver waits for the link to come up after link down
4648 * before returning I/Os to OS with "DID_NO_CONNECT".
4650 if (nv->link_down_timeout == 0) {
4651 ha->loop_down_abort_time =
4652 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4654 ha->link_down_timeout = nv->link_down_timeout;
4655 ha->loop_down_abort_time =
4656 (LOOP_DOWN_TIME - ha->link_down_timeout);
4660 * Need enough time to try and get the port back.
4662 ha->port_down_retry_count = nv->port_down_retry_count;
4663 if (qlport_down_retry)
4664 ha->port_down_retry_count = qlport_down_retry;
4665 /* Set login_retry_count */
4666 ha->login_retry_count = nv->retry_count;
4667 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4668 ha->port_down_retry_count > 3)
4669 ha->login_retry_count = ha->port_down_retry_count;
4670 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4671 ha->login_retry_count = ha->port_down_retry_count;
4672 if (ql2xloginretrycount)
4673 ha->login_retry_count = ql2xloginretrycount;
4675 icb->lun_enables = cpu_to_le16(0);
4676 icb->command_resource_count = 0;
4677 icb->immediate_notify_resource_count = 0;
4678 icb->timeout = cpu_to_le16(0);
4680 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4682 icb->firmware_options[0] &= ~BIT_3;
4683 icb->add_firmware_options[0] &=
4684 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4685 icb->add_firmware_options[0] |= BIT_2;
4686 icb->response_accumulation_timer = 3;
4687 icb->interrupt_delay_timer = 5;
4689 vha->flags.process_response_queue = 1;
4692 if (!vha->flags.init_done) {
4693 ha->zio_mode = icb->add_firmware_options[0] &
4694 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4695 ha->zio_timer = icb->interrupt_delay_timer ?
4696 icb->interrupt_delay_timer: 2;
4698 icb->add_firmware_options[0] &=
4699 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4700 vha->flags.process_response_queue = 0;
4701 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4702 ha->zio_mode = QLA_ZIO_MODE_6;
4704 ql_log(ql_log_info, vha, 0x0068,
4705 "ZIO mode %d enabled; timer delay (%d us).\n",
4706 ha->zio_mode, ha->zio_timer * 100);
4708 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4709 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4710 vha->flags.process_response_queue = 1;
4715 ql_log(ql_log_warn, vha, 0x0069,
4716 "NVRAM configuration failed.\n");
4722 qla2x00_rport_del(void *data)
4724 fc_port_t *fcport = data;
4725 struct fc_rport *rport;
4726 unsigned long flags;
4728 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4729 rport = fcport->drport ? fcport->drport: fcport->rport;
4730 fcport->drport = NULL;
4731 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4733 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4734 "%s %8phN. rport %p roles %x\n",
4735 __func__, fcport->port_name, rport,
4738 fc_remote_port_delete(rport);
4743 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4745 * @flags: allocation flags
4747 * Returns a pointer to the allocated fcport, or NULL, if none available.
4750 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4754 fcport = kzalloc(sizeof(fc_port_t), flags);
4758 /* Setup fcport template structure. */
4760 fcport->port_type = FCT_UNKNOWN;
4761 fcport->loop_id = FC_NO_LOOP_ID;
4762 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4763 fcport->supported_classes = FC_COS_UNSPECIFIED;
4764 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4766 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4767 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4769 fcport->disc_state = DSC_DELETED;
4770 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4771 fcport->deleted = QLA_SESS_DELETED;
4772 fcport->login_retry = vha->hw->login_retry_count;
4773 fcport->logout_on_delete = 1;
4775 if (!fcport->ct_desc.ct_sns) {
4776 ql_log(ql_log_warn, vha, 0xd049,
4777 "Failed to allocate ct_sns request.\n");
4781 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4782 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4783 INIT_LIST_HEAD(&fcport->gnl_entry);
4784 INIT_LIST_HEAD(&fcport->list);
4790 qla2x00_free_fcport(fc_port_t *fcport)
4792 if (fcport->ct_desc.ct_sns) {
4793 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4794 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4795 fcport->ct_desc.ct_sns_dma);
4797 fcport->ct_desc.ct_sns = NULL;
4803 * qla2x00_configure_loop
4804 * Updates Fibre Channel Device Database with what is actually on loop.
4807 * ha = adapter block pointer.
4812 * 2 = database was full and device was not configured.
4815 qla2x00_configure_loop(scsi_qla_host_t *vha)
4818 unsigned long flags, save_flags;
4819 struct qla_hw_data *ha = vha->hw;
4822 /* Get Initiator ID */
4823 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4824 rval = qla2x00_configure_hba(vha);
4825 if (rval != QLA_SUCCESS) {
4826 ql_dbg(ql_dbg_disc, vha, 0x2013,
4827 "Unable to configure HBA.\n");
4832 save_flags = flags = vha->dpc_flags;
4833 ql_dbg(ql_dbg_disc, vha, 0x2014,
4834 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4837 * If we have both an RSCN and PORT UPDATE pending then handle them
4838 * both at the same time.
4840 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4841 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4843 qla2x00_get_data_rate(vha);
4845 /* Determine what we need to do */
4846 if (ha->current_topology == ISP_CFG_FL &&
4847 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4849 set_bit(RSCN_UPDATE, &flags);
4851 } else if (ha->current_topology == ISP_CFG_F &&
4852 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4854 set_bit(RSCN_UPDATE, &flags);
4855 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4857 } else if (ha->current_topology == ISP_CFG_N) {
4858 clear_bit(RSCN_UPDATE, &flags);
4859 if (qla_tgt_mode_enabled(vha)) {
4860 /* allow the other side to start the login */
4861 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4862 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4864 } else if (ha->current_topology == ISP_CFG_NL) {
4865 clear_bit(RSCN_UPDATE, &flags);
4866 set_bit(LOCAL_LOOP_UPDATE, &flags);
4867 } else if (!vha->flags.online ||
4868 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4869 set_bit(RSCN_UPDATE, &flags);
4870 set_bit(LOCAL_LOOP_UPDATE, &flags);
4873 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4874 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4875 ql_dbg(ql_dbg_disc, vha, 0x2015,
4876 "Loop resync needed, failing.\n");
4877 rval = QLA_FUNCTION_FAILED;
4879 rval = qla2x00_configure_local_loop(vha);
4882 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4883 if (LOOP_TRANSITION(vha)) {
4884 ql_dbg(ql_dbg_disc, vha, 0x2099,
4885 "Needs RSCN update and loop transition.\n");
4886 rval = QLA_FUNCTION_FAILED;
4889 rval = qla2x00_configure_fabric(vha);
4892 if (rval == QLA_SUCCESS) {
4893 if (atomic_read(&vha->loop_down_timer) ||
4894 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4895 rval = QLA_FUNCTION_FAILED;
4897 atomic_set(&vha->loop_state, LOOP_READY);
4898 ql_dbg(ql_dbg_disc, vha, 0x2069,
4900 ha->flags.fw_init_done = 1;
4903 * Process any ATIO queue entries that came in
4904 * while we weren't online.
4906 if (qla_tgt_mode_enabled(vha) ||
4907 qla_dual_mode_enabled(vha)) {
4908 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
4909 qlt_24xx_process_atio_queue(vha, 0);
4910 spin_unlock_irqrestore(&ha->tgt.atio_lock,
4917 ql_dbg(ql_dbg_disc, vha, 0x206a,
4918 "%s *** FAILED ***.\n", __func__);
4920 ql_dbg(ql_dbg_disc, vha, 0x206b,
4921 "%s: exiting normally.\n", __func__);
4924 /* Restore state if a resync event occurred during processing */
4925 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4926 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
4927 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4928 if (test_bit(RSCN_UPDATE, &save_flags)) {
4929 set_bit(RSCN_UPDATE, &vha->dpc_flags);
4937 * qla2x00_configure_local_loop
4938 * Updates Fibre Channel Device Database with local loop devices.
4941 * ha = adapter block pointer.
4947 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
4952 fc_port_t *fcport, *new_fcport;
4958 uint8_t domain, area, al_pa;
4959 struct qla_hw_data *ha = vha->hw;
4960 unsigned long flags;
4962 /* Inititae N2N login. */
4963 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4967 memset(ha->init_cb, 0, ha->init_cb_size);
4968 sz = min_t(int, sizeof(struct els_plogi_payload),
4970 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
4971 (void *)ha->init_cb, sz);
4972 if (rval == QLA_SUCCESS) {
4973 bp = (uint32_t *)ha->init_cb;
4974 for (i = 0; i < sz/4 ; i++, bp++)
4975 *bp = cpu_to_be32(*bp);
4977 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
4978 sizeof(ha->plogi_els_payld.data));
4979 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4981 ql_dbg(ql_dbg_init, vha, 0x00d1,
4982 "PLOGI ELS param read fail.\n");
4989 entries = MAX_FIBRE_DEVICES_LOOP;
4991 /* Get list of logged in devices. */
4992 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
4993 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
4995 if (rval != QLA_SUCCESS)
4996 goto cleanup_allocation;
4998 ql_dbg(ql_dbg_disc, vha, 0x2011,
4999 "Entries in ID list (%d).\n", entries);
5000 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5001 (uint8_t *)ha->gid_list,
5002 entries * sizeof(struct gid_list_info));
5005 spin_lock_irqsave(&vha->work_lock, flags);
5006 vha->scan.scan_retry++;
5007 spin_unlock_irqrestore(&vha->work_lock, flags);
5009 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5010 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5011 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5014 vha->scan.scan_retry = 0;
5017 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5018 fcport->scan_state = QLA_FCPORT_SCAN;
5021 /* Allocate temporary fcport for any new fcports discovered. */
5022 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5023 if (new_fcport == NULL) {
5024 ql_log(ql_log_warn, vha, 0x2012,
5025 "Memory allocation failed for fcport.\n");
5026 rval = QLA_MEMORY_ALLOC_FAILED;
5027 goto cleanup_allocation;
5029 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5031 /* Add devices to port list. */
5032 id_iter = (char *)ha->gid_list;
5033 for (index = 0; index < entries; index++) {
5034 domain = ((struct gid_list_info *)id_iter)->domain;
5035 area = ((struct gid_list_info *)id_iter)->area;
5036 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
5037 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5038 loop_id = (uint16_t)
5039 ((struct gid_list_info *)id_iter)->loop_id_2100;
5041 loop_id = le16_to_cpu(
5042 ((struct gid_list_info *)id_iter)->loop_id);
5043 id_iter += ha->gid_list_info_size;
5045 /* Bypass reserved domain fields. */
5046 if ((domain & 0xf0) == 0xf0)
5049 /* Bypass if not same domain and area of adapter. */
5050 if (area && domain &&
5051 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
5054 /* Bypass invalid local loop ID. */
5055 if (loop_id > LAST_LOCAL_LOOP_ID)
5058 memset(new_fcport->port_name, 0, WWN_SIZE);
5060 /* Fill in member data. */
5061 new_fcport->d_id.b.domain = domain;
5062 new_fcport->d_id.b.area = area;
5063 new_fcport->d_id.b.al_pa = al_pa;
5064 new_fcport->loop_id = loop_id;
5065 new_fcport->scan_state = QLA_FCPORT_FOUND;
5067 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5068 if (rval2 != QLA_SUCCESS) {
5069 ql_dbg(ql_dbg_disc, vha, 0x2097,
5070 "Failed to retrieve fcport information "
5071 "-- get_port_database=%x, loop_id=0x%04x.\n",
5072 rval2, new_fcport->loop_id);
5073 /* Skip retry if N2N */
5074 if (ha->current_topology != ISP_CFG_N) {
5075 ql_dbg(ql_dbg_disc, vha, 0x2105,
5076 "Scheduling resync.\n");
5077 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5082 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5083 /* Check for matching device in port list. */
5086 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5087 if (memcmp(new_fcport->port_name, fcport->port_name,
5091 fcport->flags &= ~FCF_FABRIC_DEVICE;
5092 fcport->loop_id = new_fcport->loop_id;
5093 fcport->port_type = new_fcport->port_type;
5094 fcport->d_id.b24 = new_fcport->d_id.b24;
5095 memcpy(fcport->node_name, new_fcport->node_name,
5097 fcport->scan_state = QLA_FCPORT_FOUND;
5103 /* New device, add to fcports list. */
5104 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5106 /* Allocate a new replacement fcport. */
5107 fcport = new_fcport;
5109 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5111 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5113 if (new_fcport == NULL) {
5114 ql_log(ql_log_warn, vha, 0xd031,
5115 "Failed to allocate memory for fcport.\n");
5116 rval = QLA_MEMORY_ALLOC_FAILED;
5117 goto cleanup_allocation;
5119 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5120 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5123 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5125 /* Base iIDMA settings on HBA port speed. */
5126 fcport->fp_speed = ha->link_data_rate;
5131 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5132 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5135 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5136 if ((qla_dual_mode_enabled(vha) ||
5137 qla_ini_mode_enabled(vha)) &&
5138 atomic_read(&fcport->state) == FCS_ONLINE) {
5139 qla2x00_mark_device_lost(vha, fcport,
5140 ql2xplogiabsentdevice, 0);
5141 if (fcport->loop_id != FC_NO_LOOP_ID &&
5142 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5143 fcport->port_type != FCT_INITIATOR &&
5144 fcport->port_type != FCT_BROADCAST) {
5145 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5146 "%s %d %8phC post del sess\n",
5150 qlt_schedule_sess_for_deletion(fcport);
5156 if (fcport->scan_state == QLA_FCPORT_FOUND)
5157 qla24xx_fcport_handle_login(vha, fcport);
5163 if (rval != QLA_SUCCESS) {
5164 ql_dbg(ql_dbg_disc, vha, 0x2098,
5165 "Configure local loop error exit: rval=%x.\n", rval);
5172 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5175 uint16_t mb[MAILBOX_REGISTER_COUNT];
5176 struct qla_hw_data *ha = vha->hw;
5178 if (!IS_IIDMA_CAPABLE(ha))
5181 if (atomic_read(&fcport->state) != FCS_ONLINE)
5184 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5185 fcport->fp_speed > ha->link_data_rate ||
5186 !ha->flags.gpsc_supported)
5189 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5191 if (rval != QLA_SUCCESS) {
5192 ql_dbg(ql_dbg_disc, vha, 0x2004,
5193 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5194 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5196 ql_dbg(ql_dbg_disc, vha, 0x2005,
5197 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5198 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5199 fcport->fp_speed, fcport->port_name);
5203 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5205 qla2x00_iidma_fcport(vha, fcport);
5206 qla24xx_update_fcport_fcp_prio(vha, fcport);
5209 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5211 struct qla_work_evt *e;
5213 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5215 return QLA_FUNCTION_FAILED;
5217 e->u.fcport.fcport = fcport;
5218 return qla2x00_post_work(vha, e);
5221 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5223 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5225 struct fc_rport_identifiers rport_ids;
5226 struct fc_rport *rport;
5227 unsigned long flags;
5229 if (atomic_read(&fcport->state) == FCS_ONLINE)
5232 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5233 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5234 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5235 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5236 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5237 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5239 ql_log(ql_log_warn, vha, 0x2006,
5240 "Unable to allocate fc remote port.\n");
5244 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5245 *((fc_port_t **)rport->dd_data) = fcport;
5246 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5248 rport->supported_classes = fcport->supported_classes;
5250 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5251 if (fcport->port_type == FCT_INITIATOR)
5252 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
5253 if (fcport->port_type == FCT_TARGET)
5254 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
5256 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5257 "%s %8phN. rport %p is %s mode\n",
5258 __func__, fcport->port_name, rport,
5259 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
5261 fc_remote_port_rolechg(rport, rport_ids.roles);
5265 * qla2x00_update_fcport
5266 * Updates device on list.
5269 * ha = adapter block pointer.
5270 * fcport = port structure pointer.
5280 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5282 if (IS_SW_RESV_ADDR(fcport->d_id))
5285 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5286 __func__, fcport->port_name);
5288 fcport->disc_state = DSC_UPD_FCPORT;
5289 fcport->login_retry = vha->hw->login_retry_count;
5290 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5291 fcport->deleted = 0;
5292 fcport->logout_on_delete = 1;
5293 fcport->login_retry = vha->hw->login_retry_count;
5294 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5296 switch (vha->hw->current_topology) {
5299 fcport->keep_nport_handle = 1;
5305 qla2x00_iidma_fcport(vha, fcport);
5307 if (fcport->fc4f_nvme) {
5308 qla_nvme_register_remote(vha, fcport);
5309 fcport->disc_state = DSC_LOGIN_COMPLETE;
5310 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5314 qla24xx_update_fcport_fcp_prio(vha, fcport);
5316 switch (vha->host->active_mode) {
5317 case MODE_INITIATOR:
5318 qla2x00_reg_remote_port(vha, fcport);
5321 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5322 !vha->vha_tgt.qla_tgt->tgt_stopped)
5323 qlt_fc_port_added(vha, fcport);
5326 qla2x00_reg_remote_port(vha, fcport);
5327 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5328 !vha->vha_tgt.qla_tgt->tgt_stopped)
5329 qlt_fc_port_added(vha, fcport);
5335 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5337 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5338 if (fcport->id_changed) {
5339 fcport->id_changed = 0;
5340 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5341 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5342 __func__, __LINE__, fcport->port_name,
5344 qla24xx_post_gfpnid_work(vha, fcport);
5346 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5347 "%s %d %8phC post gpsc fcp_cnt %d\n",
5348 __func__, __LINE__, fcport->port_name,
5350 qla24xx_post_gpsc_work(vha, fcport);
5354 fcport->disc_state = DSC_LOGIN_COMPLETE;
5357 void qla_register_fcport_fn(struct work_struct *work)
5359 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5360 u32 rscn_gen = fcport->rscn_gen;
5363 if (IS_SW_RESV_ADDR(fcport->d_id))
5366 qla2x00_update_fcport(fcport->vha, fcport);
5368 if (rscn_gen != fcport->rscn_gen) {
5369 /* RSCN(s) came in while registration */
5370 switch (fcport->next_disc_state) {
5371 case DSC_DELETE_PEND:
5372 qlt_schedule_sess_for_deletion(fcport);
5375 data[0] = data[1] = 0;
5376 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5386 * qla2x00_configure_fabric
5387 * Setup SNS devices with loop ID's.
5390 * ha = adapter block pointer.
5397 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5401 uint16_t mb[MAILBOX_REGISTER_COUNT];
5403 LIST_HEAD(new_fcports);
5404 struct qla_hw_data *ha = vha->hw;
5407 /* If FL port exists, then SNS is present */
5408 if (IS_FWI2_CAPABLE(ha))
5409 loop_id = NPH_F_PORT;
5411 loop_id = SNS_FL_PORT;
5412 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5413 if (rval != QLA_SUCCESS) {
5414 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5415 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5417 vha->device_flags &= ~SWITCH_FOUND;
5418 return (QLA_SUCCESS);
5420 vha->device_flags |= SWITCH_FOUND;
5423 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5424 rval = qla2x00_send_change_request(vha, 0x3, 0);
5425 if (rval != QLA_SUCCESS)
5426 ql_log(ql_log_warn, vha, 0x121,
5427 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5433 qla2x00_mgmt_svr_login(vha);
5436 if (ql2xfdmienable &&
5437 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5438 qla2x00_fdmi_register(vha);
5440 /* Ensure we are logged into the SNS. */
5441 loop_id = NPH_SNS_LID(ha);
5442 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5443 0xfc, mb, BIT_1|BIT_0);
5444 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5445 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5446 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5447 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5448 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5451 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5452 if (qla2x00_rft_id(vha)) {
5454 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5455 "Register FC-4 TYPE failed.\n");
5456 if (test_bit(LOOP_RESYNC_NEEDED,
5460 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5462 ql_dbg(ql_dbg_disc, vha, 0x209a,
5463 "Register FC-4 Features failed.\n");
5464 if (test_bit(LOOP_RESYNC_NEEDED,
5468 if (vha->flags.nvme_enabled) {
5469 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5470 ql_dbg(ql_dbg_disc, vha, 0x2049,
5471 "Register NVME FC Type Features failed.\n");
5474 if (qla2x00_rnn_id(vha)) {
5476 ql_dbg(ql_dbg_disc, vha, 0x2104,
5477 "Register Node Name failed.\n");
5478 if (test_bit(LOOP_RESYNC_NEEDED,
5481 } else if (qla2x00_rsnn_nn(vha)) {
5483 ql_dbg(ql_dbg_disc, vha, 0x209b,
5484 "Register Symbolic Node Name failed.\n");
5485 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5491 /* Mark the time right before querying FW for connected ports.
5492 * This process is long, asynchronous and by the time it's done,
5493 * collected information might not be accurate anymore. E.g.
5494 * disconnected port might have re-connected and a brand new
5495 * session has been created. In this case session's generation
5496 * will be newer than discovery_gen. */
5497 qlt_do_generation_tick(vha, &discovery_gen);
5499 if (USE_ASYNC_SCAN(ha)) {
5500 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5503 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5505 list_for_each_entry(fcport, &vha->vp_fcports, list)
5506 fcport->scan_state = QLA_FCPORT_SCAN;
5508 rval = qla2x00_find_all_fabric_devs(vha);
5510 if (rval != QLA_SUCCESS)
5514 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5515 qla_nvme_register_hba(vha);
5518 ql_dbg(ql_dbg_disc, vha, 0x2068,
5519 "Configure fabric error exit rval=%d.\n", rval);
5525 * qla2x00_find_all_fabric_devs
5528 * ha = adapter block pointer.
5529 * dev = database device entry pointer.
5538 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5542 fc_port_t *fcport, *new_fcport;
5547 int first_dev, last_dev;
5548 port_id_t wrap = {}, nxt_d_id;
5549 struct qla_hw_data *ha = vha->hw;
5550 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5551 unsigned long flags;
5555 /* Try GID_PT to get device list, else GAN. */
5557 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5562 ql_dbg(ql_dbg_disc, vha, 0x209c,
5563 "GID_PT allocations failed, fallback on GA_NXT.\n");
5565 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5566 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5568 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5570 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5572 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5574 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5576 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5578 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5580 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5584 /* If other queries succeeded probe for FC-4 type */
5586 qla2x00_gff_id(vha, swl);
5587 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5593 /* Allocate temporary fcport for any new fcports discovered. */
5594 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5595 if (new_fcport == NULL) {
5596 ql_log(ql_log_warn, vha, 0x209d,
5597 "Failed to allocate memory for fcport.\n");
5598 return (QLA_MEMORY_ALLOC_FAILED);
5600 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5601 /* Set start port ID scan at adapter ID. */
5605 /* Starting free loop ID. */
5606 loop_id = ha->min_external_loopid;
5607 for (; loop_id <= ha->max_loop_id; loop_id++) {
5608 if (qla2x00_is_reserved_id(vha, loop_id))
5611 if (ha->current_topology == ISP_CFG_FL &&
5612 (atomic_read(&vha->loop_down_timer) ||
5613 LOOP_TRANSITION(vha))) {
5614 atomic_set(&vha->loop_down_timer, 0);
5615 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5616 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5622 wrap.b24 = new_fcport->d_id.b24;
5624 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5625 memcpy(new_fcport->node_name,
5626 swl[swl_idx].node_name, WWN_SIZE);
5627 memcpy(new_fcport->port_name,
5628 swl[swl_idx].port_name, WWN_SIZE);
5629 memcpy(new_fcport->fabric_port_name,
5630 swl[swl_idx].fabric_port_name, WWN_SIZE);
5631 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5632 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5634 new_fcport->nvme_flag = 0;
5635 new_fcport->fc4f_nvme = 0;
5636 if (vha->flags.nvme_enabled &&
5637 swl[swl_idx].fc4f_nvme) {
5638 new_fcport->fc4f_nvme =
5639 swl[swl_idx].fc4f_nvme;
5640 ql_log(ql_log_info, vha, 0x2131,
5641 "FOUND: NVME port %8phC as FC Type 28h\n",
5642 new_fcport->port_name);
5645 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5651 /* Send GA_NXT to the switch */
5652 rval = qla2x00_ga_nxt(vha, new_fcport);
5653 if (rval != QLA_SUCCESS) {
5654 ql_log(ql_log_warn, vha, 0x209e,
5655 "SNS scan failed -- assuming "
5656 "zero-entry result.\n");
5662 /* If wrap on switch device list, exit. */
5664 wrap.b24 = new_fcport->d_id.b24;
5666 } else if (new_fcport->d_id.b24 == wrap.b24) {
5667 ql_dbg(ql_dbg_disc, vha, 0x209f,
5668 "Device wrap (%02x%02x%02x).\n",
5669 new_fcport->d_id.b.domain,
5670 new_fcport->d_id.b.area,
5671 new_fcport->d_id.b.al_pa);
5675 /* Bypass if same physical adapter. */
5676 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5679 /* Bypass virtual ports of the same host. */
5680 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5683 /* Bypass if same domain and area of adapter. */
5684 if (((new_fcport->d_id.b24 & 0xffff00) ==
5685 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5689 /* Bypass reserved domain fields. */
5690 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5693 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5694 if (ql2xgffidenable &&
5695 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5696 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5699 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5701 /* Locate matching device in database. */
5703 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5704 if (memcmp(new_fcport->port_name, fcport->port_name,
5708 fcport->scan_state = QLA_FCPORT_FOUND;
5712 /* Update port state. */
5713 memcpy(fcport->fabric_port_name,
5714 new_fcport->fabric_port_name, WWN_SIZE);
5715 fcport->fp_speed = new_fcport->fp_speed;
5718 * If address the same and state FCS_ONLINE
5719 * (or in target mode), nothing changed.
5721 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5722 (atomic_read(&fcport->state) == FCS_ONLINE ||
5723 (vha->host->active_mode == MODE_TARGET))) {
5728 * If device was not a fabric device before.
5730 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5731 fcport->d_id.b24 = new_fcport->d_id.b24;
5732 qla2x00_clear_loop_id(fcport);
5733 fcport->flags |= (FCF_FABRIC_DEVICE |
5739 * Port ID changed or device was marked to be updated;
5740 * Log it out if still logged in and mark it for
5743 if (qla_tgt_mode_enabled(base_vha)) {
5744 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5745 "port changed FC ID, %8phC"
5746 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5748 fcport->d_id.b.domain,
5749 fcport->d_id.b.area,
5750 fcport->d_id.b.al_pa,
5752 new_fcport->d_id.b.domain,
5753 new_fcport->d_id.b.area,
5754 new_fcport->d_id.b.al_pa);
5755 fcport->d_id.b24 = new_fcport->d_id.b24;
5759 fcport->d_id.b24 = new_fcport->d_id.b24;
5760 fcport->flags |= FCF_LOGIN_NEEDED;
5764 if (fcport->fc4f_nvme) {
5765 if (fcport->disc_state == DSC_DELETE_PEND) {
5766 fcport->disc_state = DSC_GNL;
5767 vha->fcport_count--;
5768 fcport->login_succ = 0;
5773 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5776 /* If device was not in our fcports list, then add it. */
5777 new_fcport->scan_state = QLA_FCPORT_FOUND;
5778 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5780 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5783 /* Allocate a new replacement fcport. */
5784 nxt_d_id.b24 = new_fcport->d_id.b24;
5785 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5786 if (new_fcport == NULL) {
5787 ql_log(ql_log_warn, vha, 0xd032,
5788 "Memory allocation failed for fcport.\n");
5789 return (QLA_MEMORY_ALLOC_FAILED);
5791 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5792 new_fcport->d_id.b24 = nxt_d_id.b24;
5795 qla2x00_free_fcport(new_fcport);
5798 * Logout all previous fabric dev marked lost, except FCP2 devices.
5800 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5801 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5804 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5805 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5808 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5809 if ((qla_dual_mode_enabled(vha) ||
5810 qla_ini_mode_enabled(vha)) &&
5811 atomic_read(&fcport->state) == FCS_ONLINE) {
5812 qla2x00_mark_device_lost(vha, fcport,
5813 ql2xplogiabsentdevice, 0);
5814 if (fcport->loop_id != FC_NO_LOOP_ID &&
5815 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5816 fcport->port_type != FCT_INITIATOR &&
5817 fcport->port_type != FCT_BROADCAST) {
5818 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5819 "%s %d %8phC post del sess\n",
5822 qlt_schedule_sess_for_deletion(fcport);
5828 if (fcport->scan_state == QLA_FCPORT_FOUND)
5829 qla24xx_fcport_handle_login(vha, fcport);
5835 * qla2x00_find_new_loop_id
5836 * Scan through our port list and find a new usable loop ID.
5839 * ha: adapter state pointer.
5840 * dev: port structure pointer.
5843 * qla2x00 local function return status code.
5849 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
5852 struct qla_hw_data *ha = vha->hw;
5853 unsigned long flags = 0;
5857 spin_lock_irqsave(&ha->vport_slock, flags);
5859 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5861 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5862 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5863 dev->loop_id = FC_NO_LOOP_ID;
5864 rval = QLA_FUNCTION_FAILED;
5866 set_bit(dev->loop_id, ha->loop_id_map);
5868 spin_unlock_irqrestore(&ha->vport_slock, flags);
5870 if (rval == QLA_SUCCESS)
5871 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5872 "Assigning new loopid=%x, portid=%x.\n",
5873 dev->loop_id, dev->d_id.b24);
5875 ql_log(ql_log_warn, dev->vha, 0x2087,
5876 "No loop_id's available, portid=%x.\n",
5883 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5885 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5887 int loop_id = FC_NO_LOOP_ID;
5888 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5889 unsigned long flags;
5890 struct qla_hw_data *ha = vha->hw;
5892 if (vha->vp_idx == 0) {
5893 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5894 return NPH_MGMT_SERVER;
5897 /* pick id from high and work down to low */
5898 spin_lock_irqsave(&ha->vport_slock, flags);
5899 for (; lid > 0; lid--) {
5900 if (!test_bit(lid, vha->hw->loop_id_map)) {
5901 set_bit(lid, vha->hw->loop_id_map);
5906 spin_unlock_irqrestore(&ha->vport_slock, flags);
5912 * qla2x00_fabric_login
5913 * Issue fabric login command.
5916 * ha = adapter block pointer.
5917 * device = pointer to FC device type structure.
5920 * 0 - Login successfully
5922 * 2 - Initiator device
5926 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5927 uint16_t *next_loopid)
5931 uint16_t tmp_loopid;
5932 uint16_t mb[MAILBOX_REGISTER_COUNT];
5933 struct qla_hw_data *ha = vha->hw;
5939 ql_dbg(ql_dbg_disc, vha, 0x2000,
5940 "Trying Fabric Login w/loop id 0x%04x for port "
5942 fcport->loop_id, fcport->d_id.b.domain,
5943 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5945 /* Login fcport on switch. */
5946 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
5947 fcport->d_id.b.domain, fcport->d_id.b.area,
5948 fcport->d_id.b.al_pa, mb, BIT_0);
5949 if (rval != QLA_SUCCESS) {
5952 if (mb[0] == MBS_PORT_ID_USED) {
5954 * Device has another loop ID. The firmware team
5955 * recommends the driver perform an implicit login with
5956 * the specified ID again. The ID we just used is save
5957 * here so we return with an ID that can be tried by
5961 tmp_loopid = fcport->loop_id;
5962 fcport->loop_id = mb[1];
5964 ql_dbg(ql_dbg_disc, vha, 0x2001,
5965 "Fabric Login: port in use - next loop "
5966 "id=0x%04x, port id= %02x%02x%02x.\n",
5967 fcport->loop_id, fcport->d_id.b.domain,
5968 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5970 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5975 /* A retry occurred before. */
5976 *next_loopid = tmp_loopid;
5979 * No retry occurred before. Just increment the
5980 * ID value for next login.
5982 *next_loopid = (fcport->loop_id + 1);
5985 if (mb[1] & BIT_0) {
5986 fcport->port_type = FCT_INITIATOR;
5988 fcport->port_type = FCT_TARGET;
5989 if (mb[1] & BIT_1) {
5990 fcport->flags |= FCF_FCP2_DEVICE;
5995 fcport->supported_classes |= FC_COS_CLASS2;
5997 fcport->supported_classes |= FC_COS_CLASS3;
5999 if (IS_FWI2_CAPABLE(ha)) {
6002 FCF_CONF_COMP_SUPPORTED;
6007 } else if (mb[0] == MBS_LOOP_ID_USED) {
6009 * Loop ID already used, try next loop ID.
6012 rval = qla2x00_find_new_loop_id(vha, fcport);
6013 if (rval != QLA_SUCCESS) {
6014 /* Ran out of loop IDs to use */
6017 } else if (mb[0] == MBS_COMMAND_ERROR) {
6019 * Firmware possibly timed out during login. If NO
6020 * retries are left to do then the device is declared
6023 *next_loopid = fcport->loop_id;
6024 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6025 fcport->d_id.b.domain, fcport->d_id.b.area,
6026 fcport->d_id.b.al_pa);
6027 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6033 * unrecoverable / not handled error
6035 ql_dbg(ql_dbg_disc, vha, 0x2002,
6036 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6037 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6038 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6039 fcport->loop_id, jiffies);
6041 *next_loopid = fcport->loop_id;
6042 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6043 fcport->d_id.b.domain, fcport->d_id.b.area,
6044 fcport->d_id.b.al_pa);
6045 qla2x00_clear_loop_id(fcport);
6046 fcport->login_retry = 0;
6057 * qla2x00_local_device_login
6058 * Issue local device login command.
6061 * ha = adapter block pointer.
6062 * loop_id = loop id of device to login to.
6064 * Returns (Where's the #define!!!!):
6065 * 0 - Login successfully
6070 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6073 uint16_t mb[MAILBOX_REGISTER_COUNT];
6075 memset(mb, 0, sizeof(mb));
6076 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6077 if (rval == QLA_SUCCESS) {
6078 /* Interrogate mailbox registers for any errors */
6079 if (mb[0] == MBS_COMMAND_ERROR)
6081 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6082 /* device not in PCB table */
6090 * qla2x00_loop_resync
6091 * Resync with fibre channel devices.
6094 * ha = adapter block pointer.
6100 qla2x00_loop_resync(scsi_qla_host_t *vha)
6102 int rval = QLA_SUCCESS;
6104 struct req_que *req;
6105 struct rsp_que *rsp;
6110 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6111 if (vha->flags.online) {
6112 if (!(rval = qla2x00_fw_ready(vha))) {
6113 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6116 if (!IS_QLAFX00(vha->hw)) {
6118 * Issue a marker after FW becomes
6121 qla2x00_marker(vha, req, rsp, 0, 0,
6123 vha->marker_needed = 0;
6126 /* Remap devices on Loop. */
6127 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6129 if (IS_QLAFX00(vha->hw))
6130 qlafx00_configure_devices(vha);
6132 qla2x00_configure_loop(vha);
6135 } while (!atomic_read(&vha->loop_down_timer) &&
6136 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6137 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6142 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6143 return (QLA_FUNCTION_FAILED);
6146 ql_dbg(ql_dbg_disc, vha, 0x206c,
6147 "%s *** FAILED ***.\n", __func__);
6153 * qla2x00_perform_loop_resync
6154 * Description: This function will set the appropriate flags and call
6155 * qla2x00_loop_resync. If successful loop will be resynced
6156 * Arguments : scsi_qla_host_t pointer
6157 * returm : Success or Failure
6160 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6164 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6165 /*Configure the flags so that resync happens properly*/
6166 atomic_set(&ha->loop_down_timer, 0);
6167 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6168 atomic_set(&ha->loop_state, LOOP_UP);
6169 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6170 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6171 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6173 rval = qla2x00_loop_resync(ha);
6175 atomic_set(&ha->loop_state, LOOP_DEAD);
6177 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6184 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6187 struct scsi_qla_host *vha;
6188 struct qla_hw_data *ha = base_vha->hw;
6189 unsigned long flags;
6191 spin_lock_irqsave(&ha->vport_slock, flags);
6192 /* Go with deferred removal of rport references. */
6193 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6194 atomic_inc(&vha->vref_count);
6195 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6196 if (fcport->drport &&
6197 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6198 spin_unlock_irqrestore(&ha->vport_slock, flags);
6199 qla2x00_rport_del(fcport);
6201 spin_lock_irqsave(&ha->vport_slock, flags);
6204 atomic_dec(&vha->vref_count);
6205 wake_up(&vha->vref_waitq);
6207 spin_unlock_irqrestore(&ha->vport_slock, flags);
6210 /* Assumes idc_lock always held on entry */
6212 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6214 struct qla_hw_data *ha = vha->hw;
6215 uint32_t drv_presence, drv_presence_mask;
6216 uint32_t dev_part_info1, dev_part_info2, class_type;
6217 uint32_t class_type_mask = 0x3;
6218 uint16_t fcoe_other_function = 0xffff, i;
6220 if (IS_QLA8044(ha)) {
6221 drv_presence = qla8044_rd_direct(vha,
6222 QLA8044_CRB_DRV_ACTIVE_INDEX);
6223 dev_part_info1 = qla8044_rd_direct(vha,
6224 QLA8044_CRB_DEV_PART_INFO_INDEX);
6225 dev_part_info2 = qla8044_rd_direct(vha,
6226 QLA8044_CRB_DEV_PART_INFO2);
6228 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6229 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6230 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6232 for (i = 0; i < 8; i++) {
6233 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6234 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6235 (i != ha->portnum)) {
6236 fcoe_other_function = i;
6240 if (fcoe_other_function == 0xffff) {
6241 for (i = 0; i < 8; i++) {
6242 class_type = ((dev_part_info2 >> (i * 4)) &
6244 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6245 ((i + 8) != ha->portnum)) {
6246 fcoe_other_function = i + 8;
6252 * Prepare drv-presence mask based on fcoe functions present.
6253 * However consider only valid physical fcoe function numbers (0-15).
6255 drv_presence_mask = ~((1 << (ha->portnum)) |
6256 ((fcoe_other_function == 0xffff) ?
6257 0 : (1 << (fcoe_other_function))));
6259 /* We are the reset owner iff:
6260 * - No other protocol drivers present.
6261 * - This is the lowest among fcoe functions. */
6262 if (!(drv_presence & drv_presence_mask) &&
6263 (ha->portnum < fcoe_other_function)) {
6264 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6265 "This host is Reset owner.\n");
6266 ha->flags.nic_core_reset_owner = 1;
6271 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6273 int rval = QLA_SUCCESS;
6274 struct qla_hw_data *ha = vha->hw;
6277 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6278 if (rval == QLA_SUCCESS) {
6279 drv_ack |= (1 << ha->portnum);
6280 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6287 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6289 int rval = QLA_SUCCESS;
6290 struct qla_hw_data *ha = vha->hw;
6293 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6294 if (rval == QLA_SUCCESS) {
6295 drv_ack &= ~(1 << ha->portnum);
6296 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6303 qla83xx_dev_state_to_string(uint32_t dev_state)
6305 switch (dev_state) {
6306 case QLA8XXX_DEV_COLD:
6307 return "COLD/RE-INIT";
6308 case QLA8XXX_DEV_INITIALIZING:
6309 return "INITIALIZING";
6310 case QLA8XXX_DEV_READY:
6312 case QLA8XXX_DEV_NEED_RESET:
6313 return "NEED RESET";
6314 case QLA8XXX_DEV_NEED_QUIESCENT:
6315 return "NEED QUIESCENT";
6316 case QLA8XXX_DEV_FAILED:
6318 case QLA8XXX_DEV_QUIESCENT:
6325 /* Assumes idc-lock always held on entry */
6327 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6329 struct qla_hw_data *ha = vha->hw;
6330 uint32_t idc_audit_reg = 0, duration_secs = 0;
6332 switch (audit_type) {
6333 case IDC_AUDIT_TIMESTAMP:
6334 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6335 idc_audit_reg = (ha->portnum) |
6336 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6337 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6340 case IDC_AUDIT_COMPLETION:
6341 duration_secs = ((jiffies_to_msecs(jiffies) -
6342 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6343 idc_audit_reg = (ha->portnum) |
6344 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6345 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6349 ql_log(ql_log_warn, vha, 0xb078,
6350 "Invalid audit type specified.\n");
6355 /* Assumes idc_lock always held on entry */
6357 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6359 struct qla_hw_data *ha = vha->hw;
6360 uint32_t idc_control, dev_state;
6362 __qla83xx_get_idc_control(vha, &idc_control);
6363 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6364 ql_log(ql_log_info, vha, 0xb080,
6365 "NIC Core reset has been disabled. idc-control=0x%x\n",
6367 return QLA_FUNCTION_FAILED;
6370 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6371 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6372 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6373 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6374 QLA8XXX_DEV_NEED_RESET);
6375 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6376 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6378 const char *state = qla83xx_dev_state_to_string(dev_state);
6379 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6381 /* SV: XXX: Is timeout required here? */
6382 /* Wait for IDC state change READY -> NEED_RESET */
6383 while (dev_state == QLA8XXX_DEV_READY) {
6384 qla83xx_idc_unlock(vha, 0);
6386 qla83xx_idc_lock(vha, 0);
6387 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6391 /* Send IDC ack by writing to drv-ack register */
6392 __qla83xx_set_drv_ack(vha);
6398 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6400 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6404 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6406 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6410 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6412 uint32_t drv_presence = 0;
6413 struct qla_hw_data *ha = vha->hw;
6415 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6416 if (drv_presence & (1 << ha->portnum))
6419 return QLA_TEST_FAILED;
6423 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6425 int rval = QLA_SUCCESS;
6426 struct qla_hw_data *ha = vha->hw;
6428 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6429 "Entered %s().\n", __func__);
6431 if (vha->device_flags & DFLG_DEV_FAILED) {
6432 ql_log(ql_log_warn, vha, 0xb059,
6433 "Device in unrecoverable FAILED state.\n");
6434 return QLA_FUNCTION_FAILED;
6437 qla83xx_idc_lock(vha, 0);
6439 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6440 ql_log(ql_log_warn, vha, 0xb05a,
6441 "Function=0x%x has been removed from IDC participation.\n",
6443 rval = QLA_FUNCTION_FAILED;
6447 qla83xx_reset_ownership(vha);
6449 rval = qla83xx_initiating_reset(vha);
6452 * Perform reset if we are the reset-owner,
6453 * else wait till IDC state changes to READY/FAILED.
6455 if (rval == QLA_SUCCESS) {
6456 rval = qla83xx_idc_state_handler(vha);
6458 if (rval == QLA_SUCCESS)
6459 ha->flags.nic_core_hung = 0;
6460 __qla83xx_clear_drv_ack(vha);
6464 qla83xx_idc_unlock(vha, 0);
6466 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6472 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6474 struct qla_hw_data *ha = vha->hw;
6475 int rval = QLA_FUNCTION_FAILED;
6477 if (!IS_MCTP_CAPABLE(ha)) {
6478 /* This message can be removed from the final version */
6479 ql_log(ql_log_info, vha, 0x506d,
6480 "This board is not MCTP capable\n");
6484 if (!ha->mctp_dump) {
6485 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6486 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6488 if (!ha->mctp_dump) {
6489 ql_log(ql_log_warn, vha, 0x506e,
6490 "Failed to allocate memory for mctp dump\n");
6495 #define MCTP_DUMP_STR_ADDR 0x00000000
6496 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6497 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6498 if (rval != QLA_SUCCESS) {
6499 ql_log(ql_log_warn, vha, 0x506f,
6500 "Failed to capture mctp dump\n");
6502 ql_log(ql_log_info, vha, 0x5070,
6503 "Mctp dump capture for host (%ld/%p).\n",
6504 vha->host_no, ha->mctp_dump);
6505 ha->mctp_dumped = 1;
6508 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6509 ha->flags.nic_core_reset_hdlr_active = 1;
6510 rval = qla83xx_restart_nic_firmware(vha);
6512 /* NIC Core reset failed. */
6513 ql_log(ql_log_warn, vha, 0x5071,
6514 "Failed to restart nic firmware\n");
6516 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6517 "Restarted NIC firmware successfully.\n");
6518 ha->flags.nic_core_reset_hdlr_active = 0;
6526 * qla2x00_quiesce_io
6527 * Description: This function will block the new I/Os
6528 * Its not aborting any I/Os as context
6529 * is not destroyed during quiescence
6530 * Arguments: scsi_qla_host_t
6534 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6536 struct qla_hw_data *ha = vha->hw;
6537 struct scsi_qla_host *vp;
6539 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6540 "Quiescing I/O - ha=%p.\n", ha);
6542 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6543 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6544 atomic_set(&vha->loop_state, LOOP_DOWN);
6545 qla2x00_mark_all_devices_lost(vha, 0);
6546 list_for_each_entry(vp, &ha->vp_list, list)
6547 qla2x00_mark_all_devices_lost(vp, 0);
6549 if (!atomic_read(&vha->loop_down_timer))
6550 atomic_set(&vha->loop_down_timer,
6553 /* Wait for pending cmds to complete */
6554 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6558 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6560 struct qla_hw_data *ha = vha->hw;
6561 struct scsi_qla_host *vp;
6562 unsigned long flags;
6566 /* For ISP82XX, driver waits for completion of the commands.
6567 * online flag should be set.
6569 if (!(IS_P3P_TYPE(ha)))
6570 vha->flags.online = 0;
6571 ha->flags.chip_reset_done = 0;
6572 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6573 vha->qla_stats.total_isp_aborts++;
6575 ql_log(ql_log_info, vha, 0x00af,
6576 "Performing ISP error recovery - ha=%p.\n", ha);
6578 ha->flags.purge_mbox = 1;
6579 /* For ISP82XX, reset_chip is just disabling interrupts.
6580 * Driver waits for the completion of the commands.
6581 * the interrupts need to be enabled.
6583 if (!(IS_P3P_TYPE(ha)))
6584 ha->isp_ops->reset_chip(vha);
6586 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6588 ha->flags.rida_fmt2 = 0;
6589 ha->flags.n2n_ae = 0;
6590 ha->flags.lip_ae = 0;
6591 ha->current_topology = 0;
6592 ha->flags.fw_started = 0;
6593 ha->flags.fw_init_done = 0;
6595 ha->base_qpair->chip_reset = ha->chip_reset;
6596 for (i = 0; i < ha->max_qpairs; i++) {
6597 if (ha->queue_pair_map[i])
6598 ha->queue_pair_map[i]->chip_reset =
6599 ha->base_qpair->chip_reset;
6602 /* purge MBox commands */
6603 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6604 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6605 complete(&ha->mbx_intr_comp);
6609 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6610 atomic_read(&ha->num_pend_mbx_stage2) ||
6611 atomic_read(&ha->num_pend_mbx_stage1)) {
6617 ha->flags.purge_mbox = 0;
6619 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6620 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6621 atomic_set(&vha->loop_state, LOOP_DOWN);
6622 qla2x00_mark_all_devices_lost(vha, 0);
6624 spin_lock_irqsave(&ha->vport_slock, flags);
6625 list_for_each_entry(vp, &ha->vp_list, list) {
6626 atomic_inc(&vp->vref_count);
6627 spin_unlock_irqrestore(&ha->vport_slock, flags);
6629 qla2x00_mark_all_devices_lost(vp, 0);
6631 spin_lock_irqsave(&ha->vport_slock, flags);
6632 atomic_dec(&vp->vref_count);
6634 spin_unlock_irqrestore(&ha->vport_slock, flags);
6636 if (!atomic_read(&vha->loop_down_timer))
6637 atomic_set(&vha->loop_down_timer,
6641 /* Clear all async request states across all VPs. */
6642 list_for_each_entry(fcport, &vha->vp_fcports, list)
6643 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6644 spin_lock_irqsave(&ha->vport_slock, flags);
6645 list_for_each_entry(vp, &ha->vp_list, list) {
6646 atomic_inc(&vp->vref_count);
6647 spin_unlock_irqrestore(&ha->vport_slock, flags);
6649 list_for_each_entry(fcport, &vp->vp_fcports, list)
6650 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6652 spin_lock_irqsave(&ha->vport_slock, flags);
6653 atomic_dec(&vp->vref_count);
6655 spin_unlock_irqrestore(&ha->vport_slock, flags);
6657 if (!ha->flags.eeh_busy) {
6658 /* Make sure for ISP 82XX IO DMA is complete */
6659 if (IS_P3P_TYPE(ha)) {
6660 qla82xx_chip_reset_cleanup(vha);
6661 ql_log(ql_log_info, vha, 0x00b4,
6662 "Done chip reset cleanup.\n");
6664 /* Done waiting for pending commands.
6665 * Reset the online flag.
6667 vha->flags.online = 0;
6670 /* Requeue all commands in outstanding command list. */
6671 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6673 /* memory barrier */
6679 * Resets ISP and aborts all outstanding commands.
6682 * ha = adapter block pointer.
6688 qla2x00_abort_isp(scsi_qla_host_t *vha)
6692 struct qla_hw_data *ha = vha->hw;
6693 struct scsi_qla_host *vp;
6694 struct req_que *req = ha->req_q_map[0];
6695 unsigned long flags;
6697 if (vha->flags.online) {
6698 qla2x00_abort_isp_cleanup(vha);
6700 if (IS_QLA8031(ha)) {
6701 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6702 "Clearing fcoe driver presence.\n");
6703 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6704 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6705 "Error while clearing DRV-Presence.\n");
6708 if (unlikely(pci_channel_offline(ha->pdev) &&
6709 ha->flags.pci_channel_io_perm_failure)) {
6710 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6715 switch (vha->qlini_mode) {
6716 case QLA2XXX_INI_MODE_DISABLED:
6717 if (!qla_tgt_mode_enabled(vha))
6720 case QLA2XXX_INI_MODE_DUAL:
6721 if (!qla_dual_mode_enabled(vha))
6724 case QLA2XXX_INI_MODE_ENABLED:
6729 ha->isp_ops->get_flash_version(vha, req->ring);
6731 ha->isp_ops->nvram_config(vha);
6733 if (!qla2x00_restart_isp(vha)) {
6734 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6736 if (!atomic_read(&vha->loop_down_timer)) {
6738 * Issue marker command only when we are going
6739 * to start the I/O .
6741 vha->marker_needed = 1;
6744 vha->flags.online = 1;
6746 ha->isp_ops->enable_intrs(ha);
6748 ha->isp_abort_cnt = 0;
6749 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6751 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6752 qla2x00_get_fw_version(vha);
6754 ha->flags.fce_enabled = 1;
6756 fce_calc_size(ha->fce_bufs));
6757 rval = qla2x00_enable_fce_trace(vha,
6758 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6761 ql_log(ql_log_warn, vha, 0x8033,
6762 "Unable to reinitialize FCE "
6764 ha->flags.fce_enabled = 0;
6769 memset(ha->eft, 0, EFT_SIZE);
6770 rval = qla2x00_enable_eft_trace(vha,
6771 ha->eft_dma, EFT_NUM_BUFFERS);
6773 ql_log(ql_log_warn, vha, 0x8034,
6774 "Unable to reinitialize EFT "
6778 } else { /* failed the ISP abort */
6779 vha->flags.online = 1;
6780 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6781 if (ha->isp_abort_cnt == 0) {
6782 ql_log(ql_log_fatal, vha, 0x8035,
6783 "ISP error recover failed - "
6784 "board disabled.\n");
6786 * The next call disables the board
6789 qla2x00_abort_isp_cleanup(vha);
6790 vha->flags.online = 0;
6791 clear_bit(ISP_ABORT_RETRY,
6794 } else { /* schedule another ISP abort */
6795 ha->isp_abort_cnt--;
6796 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6797 "ISP abort - retry remaining %d.\n",
6802 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6803 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6804 "ISP error recovery - retrying (%d) "
6805 "more times.\n", ha->isp_abort_cnt);
6806 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6814 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6815 qla2x00_configure_hba(vha);
6816 spin_lock_irqsave(&ha->vport_slock, flags);
6817 list_for_each_entry(vp, &ha->vp_list, list) {
6819 atomic_inc(&vp->vref_count);
6820 spin_unlock_irqrestore(&ha->vport_slock, flags);
6822 qla2x00_vp_abort_isp(vp);
6824 spin_lock_irqsave(&ha->vport_slock, flags);
6825 atomic_dec(&vp->vref_count);
6828 spin_unlock_irqrestore(&ha->vport_slock, flags);
6830 if (IS_QLA8031(ha)) {
6831 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6832 "Setting back fcoe driver presence.\n");
6833 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6834 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6835 "Error while setting DRV-Presence.\n");
6838 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6846 * qla2x00_restart_isp
6847 * restarts the ISP after a reset
6850 * ha = adapter block pointer.
6856 qla2x00_restart_isp(scsi_qla_host_t *vha)
6859 struct qla_hw_data *ha = vha->hw;
6860 struct req_que *req = ha->req_q_map[0];
6861 struct rsp_que *rsp = ha->rsp_q_map[0];
6863 /* If firmware needs to be loaded */
6864 if (qla2x00_isp_firmware(vha)) {
6865 vha->flags.online = 0;
6866 status = ha->isp_ops->chip_diag(vha);
6868 status = qla2x00_setup_chip(vha);
6871 if (!status && !(status = qla2x00_init_rings(vha))) {
6872 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6873 ha->flags.chip_reset_done = 1;
6875 /* Initialize the queues in use */
6876 qla25xx_init_queues(ha);
6878 status = qla2x00_fw_ready(vha);
6880 /* Issue a marker after FW becomes ready. */
6881 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6882 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6885 /* if no cable then assume it's good */
6886 if ((vha->device_flags & DFLG_NO_CABLE))
6893 qla25xx_init_queues(struct qla_hw_data *ha)
6895 struct rsp_que *rsp = NULL;
6896 struct req_que *req = NULL;
6897 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6901 for (i = 1; i < ha->max_rsp_queues; i++) {
6902 rsp = ha->rsp_q_map[i];
6903 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6904 rsp->options &= ~BIT_0;
6905 ret = qla25xx_init_rsp_que(base_vha, rsp);
6906 if (ret != QLA_SUCCESS)
6907 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6908 "%s Rsp que: %d init failed.\n",
6911 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6912 "%s Rsp que: %d inited.\n",
6916 for (i = 1; i < ha->max_req_queues; i++) {
6917 req = ha->req_q_map[i];
6918 if (req && test_bit(i, ha->req_qid_map)) {
6919 /* Clear outstanding commands array. */
6920 req->options &= ~BIT_0;
6921 ret = qla25xx_init_req_que(base_vha, req);
6922 if (ret != QLA_SUCCESS)
6923 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6924 "%s Req que: %d init failed.\n",
6927 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6928 "%s Req que: %d inited.\n",
6936 * qla2x00_reset_adapter
6940 * ha = adapter block pointer.
6943 qla2x00_reset_adapter(scsi_qla_host_t *vha)
6945 unsigned long flags = 0;
6946 struct qla_hw_data *ha = vha->hw;
6947 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6949 vha->flags.online = 0;
6950 ha->isp_ops->disable_intrs(ha);
6952 spin_lock_irqsave(&ha->hardware_lock, flags);
6953 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
6954 RD_REG_WORD(®->hccr); /* PCI Posting. */
6955 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
6956 RD_REG_WORD(®->hccr); /* PCI Posting. */
6957 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6961 qla24xx_reset_adapter(scsi_qla_host_t *vha)
6963 unsigned long flags = 0;
6964 struct qla_hw_data *ha = vha->hw;
6965 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6967 if (IS_P3P_TYPE(ha))
6970 vha->flags.online = 0;
6971 ha->isp_ops->disable_intrs(ha);
6973 spin_lock_irqsave(&ha->hardware_lock, flags);
6974 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
6975 RD_REG_DWORD(®->hccr);
6976 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
6977 RD_REG_DWORD(®->hccr);
6978 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6980 if (IS_NOPOLLING_TYPE(ha))
6981 ha->isp_ops->enable_intrs(ha);
6984 /* On sparc systems, obtain port and node WWN from firmware
6987 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6988 struct nvram_24xx *nv)
6991 struct qla_hw_data *ha = vha->hw;
6992 struct pci_dev *pdev = ha->pdev;
6993 struct device_node *dp = pci_device_to_OF_node(pdev);
6997 val = of_get_property(dp, "port-wwn", &len);
6998 if (val && len >= WWN_SIZE)
6999 memcpy(nv->port_name, val, WWN_SIZE);
7001 val = of_get_property(dp, "node-wwn", &len);
7002 if (val && len >= WWN_SIZE)
7003 memcpy(nv->node_name, val, WWN_SIZE);
7008 qla24xx_nvram_config(scsi_qla_host_t *vha)
7011 struct init_cb_24xx *icb;
7012 struct nvram_24xx *nv;
7014 uint8_t *dptr1, *dptr2;
7017 struct qla_hw_data *ha = vha->hw;
7020 icb = (struct init_cb_24xx *)ha->init_cb;
7023 /* Determine NVRAM starting address. */
7024 if (ha->port_no == 0) {
7025 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7026 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7028 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7029 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7032 ha->nvram_size = sizeof(struct nvram_24xx);
7033 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7035 /* Get VPD data into cache */
7036 ha->vpd = ha->nvram + VPD_OFFSET;
7037 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
7038 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7040 /* Get NVRAM data into cache and calculate checksum. */
7041 dptr = (uint32_t *)nv;
7042 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
7044 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7045 chksum += le32_to_cpu(*dptr);
7047 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7048 "Contents of NVRAM\n");
7049 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7050 (uint8_t *)nv, ha->nvram_size);
7052 /* Bad NVRAM data, set defaults parameters. */
7053 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7054 || nv->id[3] != ' ' ||
7055 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
7056 /* Reset NVRAM data. */
7057 ql_log(ql_log_warn, vha, 0x006b,
7058 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7059 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
7060 ql_log(ql_log_warn, vha, 0x006c,
7061 "Falling back to functioning (yet invalid -- WWPN) "
7065 * Set default initialization control block.
7067 memset(nv, 0, ha->nvram_size);
7068 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7069 nv->version = cpu_to_le16(ICB_VERSION);
7070 nv->frame_payload_size = 2048;
7071 nv->execution_throttle = cpu_to_le16(0xFFFF);
7072 nv->exchange_count = cpu_to_le16(0);
7073 nv->hard_address = cpu_to_le16(124);
7074 nv->port_name[0] = 0x21;
7075 nv->port_name[1] = 0x00 + ha->port_no + 1;
7076 nv->port_name[2] = 0x00;
7077 nv->port_name[3] = 0xe0;
7078 nv->port_name[4] = 0x8b;
7079 nv->port_name[5] = 0x1c;
7080 nv->port_name[6] = 0x55;
7081 nv->port_name[7] = 0x86;
7082 nv->node_name[0] = 0x20;
7083 nv->node_name[1] = 0x00;
7084 nv->node_name[2] = 0x00;
7085 nv->node_name[3] = 0xe0;
7086 nv->node_name[4] = 0x8b;
7087 nv->node_name[5] = 0x1c;
7088 nv->node_name[6] = 0x55;
7089 nv->node_name[7] = 0x86;
7090 qla24xx_nvram_wwn_from_ofw(vha, nv);
7091 nv->login_retry_count = cpu_to_le16(8);
7092 nv->interrupt_delay_timer = cpu_to_le16(0);
7093 nv->login_timeout = cpu_to_le16(0);
7094 nv->firmware_options_1 =
7095 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7096 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7097 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7098 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7099 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7100 nv->efi_parameters = cpu_to_le32(0);
7101 nv->reset_delay = 5;
7102 nv->max_luns_per_target = cpu_to_le16(128);
7103 nv->port_down_retry_count = cpu_to_le16(30);
7104 nv->link_down_timeout = cpu_to_le16(30);
7109 if (qla_tgt_mode_enabled(vha)) {
7110 /* Don't enable full login after initial LIP */
7111 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7112 /* Don't enable LIP full login for initiator */
7113 nv->host_p &= cpu_to_le32(~BIT_10);
7116 qlt_24xx_config_nvram_stage1(vha, nv);
7118 /* Reset Initialization control block */
7119 memset(icb, 0, ha->init_cb_size);
7121 /* Copy 1st segment. */
7122 dptr1 = (uint8_t *)icb;
7123 dptr2 = (uint8_t *)&nv->version;
7124 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7126 *dptr1++ = *dptr2++;
7128 icb->login_retry_count = nv->login_retry_count;
7129 icb->link_down_on_nos = nv->link_down_on_nos;
7131 /* Copy 2nd segment. */
7132 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7133 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7134 cnt = (uint8_t *)&icb->reserved_3 -
7135 (uint8_t *)&icb->interrupt_delay_timer;
7137 *dptr1++ = *dptr2++;
7138 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7140 * Setup driver NVRAM options.
7142 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7145 qlt_24xx_config_nvram_stage2(vha, icb);
7147 if (nv->host_p & cpu_to_le32(BIT_15)) {
7148 /* Use alternate WWN? */
7149 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7150 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7153 /* Prepare nodename */
7154 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7156 * Firmware will apply the following mask if the nodename was
7159 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7160 icb->node_name[0] &= 0xF0;
7163 /* Set host adapter parameters. */
7164 ha->flags.disable_risc_code_load = 0;
7165 ha->flags.enable_lip_reset = 0;
7166 ha->flags.enable_lip_full_login =
7167 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7168 ha->flags.enable_target_reset =
7169 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7170 ha->flags.enable_led_scheme = 0;
7171 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7173 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7174 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7176 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7177 sizeof(ha->fw_seriallink_options24));
7179 /* save HBA serial number */
7180 ha->serial0 = icb->port_name[5];
7181 ha->serial1 = icb->port_name[6];
7182 ha->serial2 = icb->port_name[7];
7183 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7184 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7186 icb->execution_throttle = cpu_to_le16(0xFFFF);
7188 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7190 /* Set minimum login_timeout to 4 seconds. */
7191 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7192 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7193 if (le16_to_cpu(nv->login_timeout) < 4)
7194 nv->login_timeout = cpu_to_le16(4);
7195 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7197 /* Set minimum RATOV to 100 tenths of a second. */
7200 ha->loop_reset_delay = nv->reset_delay;
7202 /* Link Down Timeout = 0:
7204 * When Port Down timer expires we will start returning
7205 * I/O's to OS with "DID_NO_CONNECT".
7207 * Link Down Timeout != 0:
7209 * The driver waits for the link to come up after link down
7210 * before returning I/Os to OS with "DID_NO_CONNECT".
7212 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7213 ha->loop_down_abort_time =
7214 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7216 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7217 ha->loop_down_abort_time =
7218 (LOOP_DOWN_TIME - ha->link_down_timeout);
7221 /* Need enough time to try and get the port back. */
7222 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7223 if (qlport_down_retry)
7224 ha->port_down_retry_count = qlport_down_retry;
7226 /* Set login_retry_count */
7227 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7228 if (ha->port_down_retry_count ==
7229 le16_to_cpu(nv->port_down_retry_count) &&
7230 ha->port_down_retry_count > 3)
7231 ha->login_retry_count = ha->port_down_retry_count;
7232 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7233 ha->login_retry_count = ha->port_down_retry_count;
7234 if (ql2xloginretrycount)
7235 ha->login_retry_count = ql2xloginretrycount;
7237 /* N2N: driver will initiate Login instead of FW */
7238 icb->firmware_options_3 |= BIT_8;
7241 if (!vha->flags.init_done) {
7242 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7243 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7244 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7245 le16_to_cpu(icb->interrupt_delay_timer): 2;
7247 icb->firmware_options_2 &= cpu_to_le32(
7248 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7249 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7250 ha->zio_mode = QLA_ZIO_MODE_6;
7252 ql_log(ql_log_info, vha, 0x006f,
7253 "ZIO mode %d enabled; timer delay (%d us).\n",
7254 ha->zio_mode, ha->zio_timer * 100);
7256 icb->firmware_options_2 |= cpu_to_le32(
7257 (uint32_t)ha->zio_mode);
7258 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7262 ql_log(ql_log_warn, vha, 0x0070,
7263 "NVRAM configuration failed.\n");
7268 uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
7270 struct qla27xx_image_status pri_image_status, sec_image_status;
7271 uint8_t valid_pri_image, valid_sec_image;
7273 uint32_t cnt, chksum, size;
7274 struct qla_hw_data *ha = vha->hw;
7276 valid_pri_image = valid_sec_image = 1;
7277 ha->active_image = 0;
7278 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
7280 if (!ha->flt_region_img_status_pri) {
7281 valid_pri_image = 0;
7282 goto check_sec_image;
7285 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
7286 ha->flt_region_img_status_pri, size);
7288 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7289 ql_dbg(ql_dbg_init, vha, 0x018b,
7290 "Primary image signature (0x%x) not valid\n",
7291 pri_image_status.signature);
7292 valid_pri_image = 0;
7293 goto check_sec_image;
7296 wptr = (uint32_t *)(&pri_image_status);
7299 for (chksum = 0; cnt--; wptr++)
7300 chksum += le32_to_cpu(*wptr);
7303 ql_dbg(ql_dbg_init, vha, 0x018c,
7304 "Checksum validation failed for primary image (0x%x)\n",
7306 valid_pri_image = 0;
7310 if (!ha->flt_region_img_status_sec) {
7311 valid_sec_image = 0;
7312 goto check_valid_image;
7315 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7316 ha->flt_region_img_status_sec, size);
7318 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7319 ql_dbg(ql_dbg_init, vha, 0x018d,
7320 "Secondary image signature(0x%x) not valid\n",
7321 sec_image_status.signature);
7322 valid_sec_image = 0;
7323 goto check_valid_image;
7326 wptr = (uint32_t *)(&sec_image_status);
7328 for (chksum = 0; cnt--; wptr++)
7329 chksum += le32_to_cpu(*wptr);
7331 ql_dbg(ql_dbg_init, vha, 0x018e,
7332 "Checksum validation failed for secondary image (0x%x)\n",
7334 valid_sec_image = 0;
7338 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
7339 ha->active_image = QLA27XX_PRIMARY_IMAGE;
7340 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
7341 if (!ha->active_image ||
7342 pri_image_status.generation_number <
7343 sec_image_status.generation_number)
7344 ha->active_image = QLA27XX_SECONDARY_IMAGE;
7347 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x018f, "%s image\n",
7348 ha->active_image == 0 ? "default bootld and fw" :
7349 ha->active_image == 1 ? "primary" :
7350 ha->active_image == 2 ? "secondary" :
7353 return ha->active_image;
7357 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7360 int rval = QLA_SUCCESS;
7361 int segments, fragment;
7362 uint32_t *dcode, dlen;
7366 struct qla_hw_data *ha = vha->hw;
7367 struct req_que *req = ha->req_q_map[0];
7369 ql_dbg(ql_dbg_init, vha, 0x008b,
7370 "FW: Loading firmware from flash (%x).\n", faddr);
7374 segments = FA_RISC_CODE_SEGMENTS;
7375 dcode = (uint32_t *)req->ring;
7378 if (IS_QLA27XX(ha) &&
7379 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
7380 faddr = ha->flt_region_fw_sec;
7382 /* Validate firmware image by checking version. */
7383 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
7384 for (i = 0; i < 4; i++)
7385 dcode[i] = be32_to_cpu(dcode[i]);
7386 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7387 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7388 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7390 ql_log(ql_log_fatal, vha, 0x008c,
7391 "Unable to verify the integrity of flash firmware "
7393 ql_log(ql_log_fatal, vha, 0x008d,
7394 "Firmware data: %08x %08x %08x %08x.\n",
7395 dcode[0], dcode[1], dcode[2], dcode[3]);
7397 return QLA_FUNCTION_FAILED;
7400 while (segments && rval == QLA_SUCCESS) {
7401 /* Read segment's load information. */
7402 qla24xx_read_flash_data(vha, dcode, faddr, 4);
7404 risc_addr = be32_to_cpu(dcode[2]);
7405 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7406 risc_size = be32_to_cpu(dcode[3]);
7409 while (risc_size > 0 && rval == QLA_SUCCESS) {
7410 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7411 if (dlen > risc_size)
7414 ql_dbg(ql_dbg_init, vha, 0x008e,
7415 "Loading risc segment@ risc addr %x "
7416 "number of dwords 0x%x offset 0x%x.\n",
7417 risc_addr, dlen, faddr);
7419 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7420 for (i = 0; i < dlen; i++)
7421 dcode[i] = swab32(dcode[i]);
7423 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7426 ql_log(ql_log_fatal, vha, 0x008f,
7427 "Failed to load segment %d of firmware.\n",
7429 return QLA_FUNCTION_FAILED;
7442 if (!IS_QLA27XX(ha))
7445 if (ha->fw_dump_template)
7446 vfree(ha->fw_dump_template);
7447 ha->fw_dump_template = NULL;
7448 ha->fw_dump_template_len = 0;
7450 ql_dbg(ql_dbg_init, vha, 0x0161,
7451 "Loading fwdump template from %x\n", faddr);
7452 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7453 risc_size = be32_to_cpu(dcode[2]);
7454 ql_dbg(ql_dbg_init, vha, 0x0162,
7455 "-> array size %x dwords\n", risc_size);
7456 if (risc_size == 0 || risc_size == ~0)
7457 goto default_template;
7459 dlen = (risc_size - 8) * sizeof(*dcode);
7460 ql_dbg(ql_dbg_init, vha, 0x0163,
7461 "-> template allocating %x bytes...\n", dlen);
7462 ha->fw_dump_template = vmalloc(dlen);
7463 if (!ha->fw_dump_template) {
7464 ql_log(ql_log_warn, vha, 0x0164,
7465 "Failed fwdump template allocate %x bytes.\n", risc_size);
7466 goto default_template;
7471 dcode = ha->fw_dump_template;
7472 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7473 for (i = 0; i < risc_size; i++)
7474 dcode[i] = le32_to_cpu(dcode[i]);
7476 if (!qla27xx_fwdt_template_valid(dcode)) {
7477 ql_log(ql_log_warn, vha, 0x0165,
7478 "Failed fwdump template validate\n");
7479 goto default_template;
7482 dlen = qla27xx_fwdt_template_size(dcode);
7483 ql_dbg(ql_dbg_init, vha, 0x0166,
7484 "-> template size %x bytes\n", dlen);
7485 if (dlen > risc_size * sizeof(*dcode)) {
7486 ql_log(ql_log_warn, vha, 0x0167,
7487 "Failed fwdump template exceeds array by %zx bytes\n",
7488 (size_t)(dlen - risc_size * sizeof(*dcode)));
7489 goto default_template;
7491 ha->fw_dump_template_len = dlen;
7495 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
7496 if (ha->fw_dump_template)
7497 vfree(ha->fw_dump_template);
7498 ha->fw_dump_template = NULL;
7499 ha->fw_dump_template_len = 0;
7501 dlen = qla27xx_fwdt_template_default_size();
7502 ql_dbg(ql_dbg_init, vha, 0x0169,
7503 "-> template allocating %x bytes...\n", dlen);
7504 ha->fw_dump_template = vmalloc(dlen);
7505 if (!ha->fw_dump_template) {
7506 ql_log(ql_log_warn, vha, 0x016a,
7507 "Failed fwdump template allocate %x bytes.\n", risc_size);
7508 goto failed_template;
7511 dcode = ha->fw_dump_template;
7512 risc_size = dlen / sizeof(*dcode);
7513 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
7514 for (i = 0; i < risc_size; i++)
7515 dcode[i] = be32_to_cpu(dcode[i]);
7517 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7518 ql_log(ql_log_warn, vha, 0x016b,
7519 "Failed fwdump template validate\n");
7520 goto failed_template;
7523 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7524 ql_dbg(ql_dbg_init, vha, 0x016c,
7525 "-> template size %x bytes\n", dlen);
7526 ha->fw_dump_template_len = dlen;
7530 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
7531 if (ha->fw_dump_template)
7532 vfree(ha->fw_dump_template);
7533 ha->fw_dump_template = NULL;
7534 ha->fw_dump_template_len = 0;
7538 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7541 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7545 uint16_t *wcode, *fwcode;
7546 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7547 struct fw_blob *blob;
7548 struct qla_hw_data *ha = vha->hw;
7549 struct req_que *req = ha->req_q_map[0];
7551 /* Load firmware blob. */
7552 blob = qla2x00_request_firmware(vha);
7554 ql_log(ql_log_info, vha, 0x0083,
7555 "Firmware image unavailable.\n");
7556 ql_log(ql_log_info, vha, 0x0084,
7557 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7558 return QLA_FUNCTION_FAILED;
7563 wcode = (uint16_t *)req->ring;
7565 fwcode = (uint16_t *)blob->fw->data;
7568 /* Validate firmware image by checking version. */
7569 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7570 ql_log(ql_log_fatal, vha, 0x0085,
7571 "Unable to verify integrity of firmware image (%zd).\n",
7573 goto fail_fw_integrity;
7575 for (i = 0; i < 4; i++)
7576 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7577 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7578 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7579 wcode[2] == 0 && wcode[3] == 0)) {
7580 ql_log(ql_log_fatal, vha, 0x0086,
7581 "Unable to verify integrity of firmware image.\n");
7582 ql_log(ql_log_fatal, vha, 0x0087,
7583 "Firmware data: %04x %04x %04x %04x.\n",
7584 wcode[0], wcode[1], wcode[2], wcode[3]);
7585 goto fail_fw_integrity;
7589 while (*seg && rval == QLA_SUCCESS) {
7591 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7592 risc_size = be16_to_cpu(fwcode[3]);
7594 /* Validate firmware image size. */
7595 fwclen += risc_size * sizeof(uint16_t);
7596 if (blob->fw->size < fwclen) {
7597 ql_log(ql_log_fatal, vha, 0x0088,
7598 "Unable to verify integrity of firmware image "
7599 "(%zd).\n", blob->fw->size);
7600 goto fail_fw_integrity;
7604 while (risc_size > 0 && rval == QLA_SUCCESS) {
7605 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7606 if (wlen > risc_size)
7608 ql_dbg(ql_dbg_init, vha, 0x0089,
7609 "Loading risc segment@ risc addr %x number of "
7610 "words 0x%x.\n", risc_addr, wlen);
7612 for (i = 0; i < wlen; i++)
7613 wcode[i] = swab16(fwcode[i]);
7615 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7618 ql_log(ql_log_fatal, vha, 0x008a,
7619 "Failed to load segment %d of firmware.\n",
7636 return QLA_FUNCTION_FAILED;
7640 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7643 int segments, fragment;
7644 uint32_t *dcode, dlen;
7648 struct fw_blob *blob;
7649 const uint32_t *fwcode;
7651 struct qla_hw_data *ha = vha->hw;
7652 struct req_que *req = ha->req_q_map[0];
7654 /* Load firmware blob. */
7655 blob = qla2x00_request_firmware(vha);
7657 ql_log(ql_log_warn, vha, 0x0090,
7658 "Firmware image unavailable.\n");
7659 ql_log(ql_log_warn, vha, 0x0091,
7660 "Firmware images can be retrieved from: "
7663 return QLA_FUNCTION_FAILED;
7666 ql_dbg(ql_dbg_init, vha, 0x0092,
7667 "FW: Loading via request-firmware.\n");
7671 segments = FA_RISC_CODE_SEGMENTS;
7672 dcode = (uint32_t *)req->ring;
7674 fwcode = (uint32_t *)blob->fw->data;
7677 /* Validate firmware image by checking version. */
7678 if (blob->fw->size < 8 * sizeof(uint32_t)) {
7679 ql_log(ql_log_fatal, vha, 0x0093,
7680 "Unable to verify integrity of firmware image (%zd).\n",
7682 return QLA_FUNCTION_FAILED;
7684 for (i = 0; i < 4; i++)
7685 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7686 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7687 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7688 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7690 ql_log(ql_log_fatal, vha, 0x0094,
7691 "Unable to verify integrity of firmware image (%zd).\n",
7693 ql_log(ql_log_fatal, vha, 0x0095,
7694 "Firmware data: %08x %08x %08x %08x.\n",
7695 dcode[0], dcode[1], dcode[2], dcode[3]);
7696 return QLA_FUNCTION_FAILED;
7699 while (segments && rval == QLA_SUCCESS) {
7700 risc_addr = be32_to_cpu(fwcode[2]);
7701 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7702 risc_size = be32_to_cpu(fwcode[3]);
7704 /* Validate firmware image size. */
7705 fwclen += risc_size * sizeof(uint32_t);
7706 if (blob->fw->size < fwclen) {
7707 ql_log(ql_log_fatal, vha, 0x0096,
7708 "Unable to verify integrity of firmware image "
7709 "(%zd).\n", blob->fw->size);
7710 return QLA_FUNCTION_FAILED;
7714 while (risc_size > 0 && rval == QLA_SUCCESS) {
7715 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7716 if (dlen > risc_size)
7719 ql_dbg(ql_dbg_init, vha, 0x0097,
7720 "Loading risc segment@ risc addr %x "
7721 "number of dwords 0x%x.\n", risc_addr, dlen);
7723 for (i = 0; i < dlen; i++)
7724 dcode[i] = swab32(fwcode[i]);
7726 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7729 ql_log(ql_log_fatal, vha, 0x0098,
7730 "Failed to load segment %d of firmware.\n",
7732 return QLA_FUNCTION_FAILED;
7745 if (!IS_QLA27XX(ha))
7748 if (ha->fw_dump_template)
7749 vfree(ha->fw_dump_template);
7750 ha->fw_dump_template = NULL;
7751 ha->fw_dump_template_len = 0;
7753 ql_dbg(ql_dbg_init, vha, 0x171,
7754 "Loading fwdump template from %x\n",
7755 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
7756 risc_size = be32_to_cpu(fwcode[2]);
7757 ql_dbg(ql_dbg_init, vha, 0x172,
7758 "-> array size %x dwords\n", risc_size);
7759 if (risc_size == 0 || risc_size == ~0)
7760 goto default_template;
7762 dlen = (risc_size - 8) * sizeof(*fwcode);
7763 ql_dbg(ql_dbg_init, vha, 0x0173,
7764 "-> template allocating %x bytes...\n", dlen);
7765 ha->fw_dump_template = vmalloc(dlen);
7766 if (!ha->fw_dump_template) {
7767 ql_log(ql_log_warn, vha, 0x0174,
7768 "Failed fwdump template allocate %x bytes.\n", risc_size);
7769 goto default_template;
7774 dcode = ha->fw_dump_template;
7775 for (i = 0; i < risc_size; i++)
7776 dcode[i] = le32_to_cpu(fwcode[i]);
7778 if (!qla27xx_fwdt_template_valid(dcode)) {
7779 ql_log(ql_log_warn, vha, 0x0175,
7780 "Failed fwdump template validate\n");
7781 goto default_template;
7784 dlen = qla27xx_fwdt_template_size(dcode);
7785 ql_dbg(ql_dbg_init, vha, 0x0176,
7786 "-> template size %x bytes\n", dlen);
7787 if (dlen > risc_size * sizeof(*fwcode)) {
7788 ql_log(ql_log_warn, vha, 0x0177,
7789 "Failed fwdump template exceeds array by %zx bytes\n",
7790 (size_t)(dlen - risc_size * sizeof(*fwcode)));
7791 goto default_template;
7793 ha->fw_dump_template_len = dlen;
7797 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7798 if (ha->fw_dump_template)
7799 vfree(ha->fw_dump_template);
7800 ha->fw_dump_template = NULL;
7801 ha->fw_dump_template_len = 0;
7803 dlen = qla27xx_fwdt_template_default_size();
7804 ql_dbg(ql_dbg_init, vha, 0x0179,
7805 "-> template allocating %x bytes...\n", dlen);
7806 ha->fw_dump_template = vmalloc(dlen);
7807 if (!ha->fw_dump_template) {
7808 ql_log(ql_log_warn, vha, 0x017a,
7809 "Failed fwdump template allocate %x bytes.\n", risc_size);
7810 goto failed_template;
7813 dcode = ha->fw_dump_template;
7814 risc_size = dlen / sizeof(*fwcode);
7815 fwcode = qla27xx_fwdt_template_default();
7816 for (i = 0; i < risc_size; i++)
7817 dcode[i] = be32_to_cpu(fwcode[i]);
7819 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7820 ql_log(ql_log_warn, vha, 0x017b,
7821 "Failed fwdump template validate\n");
7822 goto failed_template;
7825 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7826 ql_dbg(ql_dbg_init, vha, 0x017c,
7827 "-> template size %x bytes\n", dlen);
7828 ha->fw_dump_template_len = dlen;
7832 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7833 if (ha->fw_dump_template)
7834 vfree(ha->fw_dump_template);
7835 ha->fw_dump_template = NULL;
7836 ha->fw_dump_template_len = 0;
7841 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7845 if (ql2xfwloadbin == 1)
7846 return qla81xx_load_risc(vha, srisc_addr);
7850 * 1) Firmware via request-firmware interface (.bin file).
7851 * 2) Firmware residing in flash.
7853 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7854 if (rval == QLA_SUCCESS)
7857 return qla24xx_load_risc_flash(vha, srisc_addr,
7858 vha->hw->flt_region_fw);
7862 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7865 struct qla_hw_data *ha = vha->hw;
7867 if (ql2xfwloadbin == 2)
7872 * 1) Firmware residing in flash.
7873 * 2) Firmware via request-firmware interface (.bin file).
7874 * 3) Golden-Firmware residing in flash -- limited operation.
7876 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
7877 if (rval == QLA_SUCCESS)
7881 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7882 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7885 ql_log(ql_log_info, vha, 0x0099,
7886 "Attempting to fallback to golden firmware.\n");
7887 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7888 if (rval != QLA_SUCCESS)
7891 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
7892 ha->flags.running_gold_fw = 1;
7897 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
7900 struct qla_hw_data *ha = vha->hw;
7902 if (ha->flags.pci_channel_io_perm_failure)
7904 if (!IS_FWI2_CAPABLE(ha))
7906 if (!ha->fw_major_version)
7908 if (!ha->flags.fw_started)
7911 ret = qla2x00_stop_firmware(vha);
7912 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
7913 ret != QLA_INVALID_COMMAND && retries ; retries--) {
7914 ha->isp_ops->reset_chip(vha);
7915 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
7917 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
7919 ql_log(ql_log_info, vha, 0x8015,
7920 "Attempting retry of stop-firmware command.\n");
7921 ret = qla2x00_stop_firmware(vha);
7925 ha->flags.fw_init_done = 0;
7929 qla24xx_configure_vhba(scsi_qla_host_t *vha)
7931 int rval = QLA_SUCCESS;
7933 uint16_t mb[MAILBOX_REGISTER_COUNT];
7934 struct qla_hw_data *ha = vha->hw;
7935 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7936 struct req_que *req;
7937 struct rsp_que *rsp;
7942 rval = qla2x00_fw_ready(base_vha);
7944 req = vha->qpair->req;
7946 req = ha->req_q_map[0];
7949 if (rval == QLA_SUCCESS) {
7950 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7951 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
7954 vha->flags.management_server_logged_in = 0;
7956 /* Login to SNS first */
7957 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7959 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7960 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7961 ql_dbg(ql_dbg_init, vha, 0x0120,
7962 "Failed SNS login: loop_id=%x, rval2=%d\n",
7965 ql_dbg(ql_dbg_init, vha, 0x0103,
7966 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7967 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7968 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
7969 return (QLA_FUNCTION_FAILED);
7972 atomic_set(&vha->loop_down_timer, 0);
7973 atomic_set(&vha->loop_state, LOOP_UP);
7974 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7975 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7976 rval = qla2x00_loop_resync(base_vha);
7981 /* 84XX Support **************************************************************/
7983 static LIST_HEAD(qla_cs84xx_list);
7984 static DEFINE_MUTEX(qla_cs84xx_mutex);
7986 static struct qla_chip_state_84xx *
7987 qla84xx_get_chip(struct scsi_qla_host *vha)
7989 struct qla_chip_state_84xx *cs84xx;
7990 struct qla_hw_data *ha = vha->hw;
7992 mutex_lock(&qla_cs84xx_mutex);
7994 /* Find any shared 84xx chip. */
7995 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7996 if (cs84xx->bus == ha->pdev->bus) {
7997 kref_get(&cs84xx->kref);
8002 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8006 kref_init(&cs84xx->kref);
8007 spin_lock_init(&cs84xx->access_lock);
8008 mutex_init(&cs84xx->fw_update_mutex);
8009 cs84xx->bus = ha->pdev->bus;
8011 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8013 mutex_unlock(&qla_cs84xx_mutex);
8018 __qla84xx_chip_release(struct kref *kref)
8020 struct qla_chip_state_84xx *cs84xx =
8021 container_of(kref, struct qla_chip_state_84xx, kref);
8023 mutex_lock(&qla_cs84xx_mutex);
8024 list_del(&cs84xx->list);
8025 mutex_unlock(&qla_cs84xx_mutex);
8030 qla84xx_put_chip(struct scsi_qla_host *vha)
8032 struct qla_hw_data *ha = vha->hw;
8034 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8038 qla84xx_init_chip(scsi_qla_host_t *vha)
8042 struct qla_hw_data *ha = vha->hw;
8044 mutex_lock(&ha->cs84xx->fw_update_mutex);
8046 rval = qla84xx_verify_chip(vha, status);
8048 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8050 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
8054 /* 81XX Support **************************************************************/
8057 qla81xx_nvram_config(scsi_qla_host_t *vha)
8060 struct init_cb_81xx *icb;
8061 struct nvram_81xx *nv;
8063 uint8_t *dptr1, *dptr2;
8066 struct qla_hw_data *ha = vha->hw;
8069 icb = (struct init_cb_81xx *)ha->init_cb;
8072 /* Determine NVRAM starting address. */
8073 ha->nvram_size = sizeof(struct nvram_81xx);
8074 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8075 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8076 ha->vpd_size = FA_VPD_SIZE_82XX;
8078 /* Get VPD data into cache */
8079 ha->vpd = ha->nvram + VPD_OFFSET;
8080 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
8083 /* Get NVRAM data into cache and calculate checksum. */
8084 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
8086 dptr = (uint32_t *)nv;
8087 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8088 chksum += le32_to_cpu(*dptr);
8090 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8091 "Contents of NVRAM:\n");
8092 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8093 (uint8_t *)nv, ha->nvram_size);
8095 /* Bad NVRAM data, set defaults parameters. */
8096 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
8097 || nv->id[3] != ' ' ||
8098 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
8099 /* Reset NVRAM data. */
8100 ql_log(ql_log_info, vha, 0x0073,
8101 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
8102 "version=0x%x.\n", chksum, nv->id[0],
8103 le16_to_cpu(nv->nvram_version));
8104 ql_log(ql_log_info, vha, 0x0074,
8105 "Falling back to functioning (yet invalid -- WWPN) "
8109 * Set default initialization control block.
8111 memset(nv, 0, ha->nvram_size);
8112 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8113 nv->version = cpu_to_le16(ICB_VERSION);
8114 nv->frame_payload_size = 2048;
8115 nv->execution_throttle = cpu_to_le16(0xFFFF);
8116 nv->exchange_count = cpu_to_le16(0);
8117 nv->port_name[0] = 0x21;
8118 nv->port_name[1] = 0x00 + ha->port_no + 1;
8119 nv->port_name[2] = 0x00;
8120 nv->port_name[3] = 0xe0;
8121 nv->port_name[4] = 0x8b;
8122 nv->port_name[5] = 0x1c;
8123 nv->port_name[6] = 0x55;
8124 nv->port_name[7] = 0x86;
8125 nv->node_name[0] = 0x20;
8126 nv->node_name[1] = 0x00;
8127 nv->node_name[2] = 0x00;
8128 nv->node_name[3] = 0xe0;
8129 nv->node_name[4] = 0x8b;
8130 nv->node_name[5] = 0x1c;
8131 nv->node_name[6] = 0x55;
8132 nv->node_name[7] = 0x86;
8133 nv->login_retry_count = cpu_to_le16(8);
8134 nv->interrupt_delay_timer = cpu_to_le16(0);
8135 nv->login_timeout = cpu_to_le16(0);
8136 nv->firmware_options_1 =
8137 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8138 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8139 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8140 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8141 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8142 nv->efi_parameters = cpu_to_le32(0);
8143 nv->reset_delay = 5;
8144 nv->max_luns_per_target = cpu_to_le16(128);
8145 nv->port_down_retry_count = cpu_to_le16(30);
8146 nv->link_down_timeout = cpu_to_le16(180);
8147 nv->enode_mac[0] = 0x00;
8148 nv->enode_mac[1] = 0xC0;
8149 nv->enode_mac[2] = 0xDD;
8150 nv->enode_mac[3] = 0x04;
8151 nv->enode_mac[4] = 0x05;
8152 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8157 if (IS_T10_PI_CAPABLE(ha))
8158 nv->frame_payload_size &= ~7;
8160 qlt_81xx_config_nvram_stage1(vha, nv);
8162 /* Reset Initialization control block */
8163 memset(icb, 0, ha->init_cb_size);
8165 /* Copy 1st segment. */
8166 dptr1 = (uint8_t *)icb;
8167 dptr2 = (uint8_t *)&nv->version;
8168 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8170 *dptr1++ = *dptr2++;
8172 icb->login_retry_count = nv->login_retry_count;
8174 /* Copy 2nd segment. */
8175 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8176 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8177 cnt = (uint8_t *)&icb->reserved_5 -
8178 (uint8_t *)&icb->interrupt_delay_timer;
8180 *dptr1++ = *dptr2++;
8182 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8183 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8184 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8185 icb->enode_mac[0] = 0x00;
8186 icb->enode_mac[1] = 0xC0;
8187 icb->enode_mac[2] = 0xDD;
8188 icb->enode_mac[3] = 0x04;
8189 icb->enode_mac[4] = 0x05;
8190 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8193 /* Use extended-initialization control block. */
8194 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8195 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8197 * Setup driver NVRAM options.
8199 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8202 qlt_81xx_config_nvram_stage2(vha, icb);
8204 /* Use alternate WWN? */
8205 if (nv->host_p & cpu_to_le32(BIT_15)) {
8206 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8207 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8210 /* Prepare nodename */
8211 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8213 * Firmware will apply the following mask if the nodename was
8216 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8217 icb->node_name[0] &= 0xF0;
8220 /* Set host adapter parameters. */
8221 ha->flags.disable_risc_code_load = 0;
8222 ha->flags.enable_lip_reset = 0;
8223 ha->flags.enable_lip_full_login =
8224 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
8225 ha->flags.enable_target_reset =
8226 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
8227 ha->flags.enable_led_scheme = 0;
8228 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
8230 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8231 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8233 /* save HBA serial number */
8234 ha->serial0 = icb->port_name[5];
8235 ha->serial1 = icb->port_name[6];
8236 ha->serial2 = icb->port_name[7];
8237 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8238 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8240 icb->execution_throttle = cpu_to_le16(0xFFFF);
8242 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8244 /* Set minimum login_timeout to 4 seconds. */
8245 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8246 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8247 if (le16_to_cpu(nv->login_timeout) < 4)
8248 nv->login_timeout = cpu_to_le16(4);
8249 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8251 /* Set minimum RATOV to 100 tenths of a second. */
8254 ha->loop_reset_delay = nv->reset_delay;
8256 /* Link Down Timeout = 0:
8258 * When Port Down timer expires we will start returning
8259 * I/O's to OS with "DID_NO_CONNECT".
8261 * Link Down Timeout != 0:
8263 * The driver waits for the link to come up after link down
8264 * before returning I/Os to OS with "DID_NO_CONNECT".
8266 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8267 ha->loop_down_abort_time =
8268 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8270 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8271 ha->loop_down_abort_time =
8272 (LOOP_DOWN_TIME - ha->link_down_timeout);
8275 /* Need enough time to try and get the port back. */
8276 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8277 if (qlport_down_retry)
8278 ha->port_down_retry_count = qlport_down_retry;
8280 /* Set login_retry_count */
8281 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8282 if (ha->port_down_retry_count ==
8283 le16_to_cpu(nv->port_down_retry_count) &&
8284 ha->port_down_retry_count > 3)
8285 ha->login_retry_count = ha->port_down_retry_count;
8286 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8287 ha->login_retry_count = ha->port_down_retry_count;
8288 if (ql2xloginretrycount)
8289 ha->login_retry_count = ql2xloginretrycount;
8291 /* if not running MSI-X we need handshaking on interrupts */
8292 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
8293 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8296 if (!vha->flags.init_done) {
8297 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8298 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8299 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8300 le16_to_cpu(icb->interrupt_delay_timer): 2;
8302 icb->firmware_options_2 &= cpu_to_le32(
8303 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8304 vha->flags.process_response_queue = 0;
8305 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8306 ha->zio_mode = QLA_ZIO_MODE_6;
8308 ql_log(ql_log_info, vha, 0x0075,
8309 "ZIO mode %d enabled; timer delay (%d us).\n",
8311 ha->zio_timer * 100);
8313 icb->firmware_options_2 |= cpu_to_le32(
8314 (uint32_t)ha->zio_mode);
8315 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8316 vha->flags.process_response_queue = 1;
8319 /* enable RIDA Format2 */
8320 icb->firmware_options_3 |= BIT_0;
8322 /* N2N: driver will initiate Login instead of FW */
8323 icb->firmware_options_3 |= BIT_8;
8325 if (IS_QLA27XX(ha)) {
8326 icb->firmware_options_3 |= BIT_8;
8327 ql_dbg(ql_log_info, vha, 0x0075,
8328 "Enabling direct connection.\n");
8332 ql_log(ql_log_warn, vha, 0x0076,
8333 "NVRAM configuration failed.\n");
8339 qla82xx_restart_isp(scsi_qla_host_t *vha)
8342 struct qla_hw_data *ha = vha->hw;
8343 struct req_que *req = ha->req_q_map[0];
8344 struct rsp_que *rsp = ha->rsp_q_map[0];
8345 struct scsi_qla_host *vp;
8346 unsigned long flags;
8348 status = qla2x00_init_rings(vha);
8350 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8351 ha->flags.chip_reset_done = 1;
8353 status = qla2x00_fw_ready(vha);
8355 /* Issue a marker after FW becomes ready. */
8356 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
8357 vha->flags.online = 1;
8358 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8361 /* if no cable then assume it's good */
8362 if ((vha->device_flags & DFLG_NO_CABLE))
8367 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8369 if (!atomic_read(&vha->loop_down_timer)) {
8371 * Issue marker command only when we are going
8372 * to start the I/O .
8374 vha->marker_needed = 1;
8377 ha->isp_ops->enable_intrs(ha);
8379 ha->isp_abort_cnt = 0;
8380 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8382 /* Update the firmware version */
8383 status = qla82xx_check_md_needed(vha);
8386 ha->flags.fce_enabled = 1;
8388 fce_calc_size(ha->fce_bufs));
8389 rval = qla2x00_enable_fce_trace(vha,
8390 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8393 ql_log(ql_log_warn, vha, 0x8001,
8394 "Unable to reinitialize FCE (%d).\n",
8396 ha->flags.fce_enabled = 0;
8401 memset(ha->eft, 0, EFT_SIZE);
8402 rval = qla2x00_enable_eft_trace(vha,
8403 ha->eft_dma, EFT_NUM_BUFFERS);
8405 ql_log(ql_log_warn, vha, 0x8010,
8406 "Unable to reinitialize EFT (%d).\n",
8413 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8414 "qla82xx_restart_isp succeeded.\n");
8416 spin_lock_irqsave(&ha->vport_slock, flags);
8417 list_for_each_entry(vp, &ha->vp_list, list) {
8419 atomic_inc(&vp->vref_count);
8420 spin_unlock_irqrestore(&ha->vport_slock, flags);
8422 qla2x00_vp_abort_isp(vp);
8424 spin_lock_irqsave(&ha->vport_slock, flags);
8425 atomic_dec(&vp->vref_count);
8428 spin_unlock_irqrestore(&ha->vport_slock, flags);
8431 ql_log(ql_log_warn, vha, 0x8016,
8432 "qla82xx_restart_isp **** FAILED ****.\n");
8439 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8441 struct qla_hw_data *ha = vha->hw;
8443 /* Hold status IOCBs until ABTS response received. */
8445 ha->fw_options[3] |= BIT_12;
8447 /* Set Retry FLOGI in case of P2P connection */
8448 if (ha->operating_mode == P2P) {
8449 ha->fw_options[2] |= BIT_3;
8450 ql_dbg(ql_dbg_disc, vha, 0x2103,
8451 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8452 __func__, ha->fw_options[2]);
8455 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8456 if (ql2xmvasynctoatio) {
8457 if (qla_tgt_mode_enabled(vha) ||
8458 qla_dual_mode_enabled(vha))
8459 ha->fw_options[2] |= BIT_11;
8461 ha->fw_options[2] &= ~BIT_11;
8464 if (qla_tgt_mode_enabled(vha) ||
8465 qla_dual_mode_enabled(vha)) {
8466 /* FW auto send SCSI status during */
8467 ha->fw_options[1] |= BIT_8;
8468 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8470 /* FW perform Exchange validation */
8471 ha->fw_options[2] |= BIT_4;
8473 ha->fw_options[1] &= ~BIT_8;
8474 ha->fw_options[10] &= 0x00ff;
8476 ha->fw_options[2] &= ~BIT_4;
8479 if (ql2xetsenable) {
8480 /* Enable ETS Burst. */
8481 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8482 ha->fw_options[2] |= BIT_9;
8485 ql_dbg(ql_dbg_init, vha, 0x00e9,
8486 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8487 __func__, ha->fw_options[1], ha->fw_options[2],
8488 ha->fw_options[3], vha->host->active_mode);
8490 qla2x00_set_fw_options(vha, ha->fw_options);
8494 * qla24xx_get_fcp_prio
8495 * Gets the fcp cmd priority value for the logged in port.
8496 * Looks for a match of the port descriptors within
8497 * each of the fcp prio config entries. If a match is found,
8498 * the tag (priority) value is returned.
8501 * vha = scsi host structure pointer.
8502 * fcport = port structure pointer.
8505 * non-zero (if found)
8512 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8515 uint8_t pid_match, wwn_match;
8517 uint32_t pid1, pid2;
8518 uint64_t wwn1, wwn2;
8519 struct qla_fcp_prio_entry *pri_entry;
8520 struct qla_hw_data *ha = vha->hw;
8522 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8526 entries = ha->fcp_prio_cfg->num_entries;
8527 pri_entry = &ha->fcp_prio_cfg->entry[0];
8529 for (i = 0; i < entries; i++) {
8530 pid_match = wwn_match = 0;
8532 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8537 /* check source pid for a match */
8538 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8539 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8540 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8541 if (pid1 == INVALID_PORT_ID)
8543 else if (pid1 == pid2)
8547 /* check destination pid for a match */
8548 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8549 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8550 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8551 if (pid1 == INVALID_PORT_ID)
8553 else if (pid1 == pid2)
8557 /* check source WWN for a match */
8558 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8559 wwn1 = wwn_to_u64(vha->port_name);
8560 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8561 if (wwn2 == (uint64_t)-1)
8563 else if (wwn1 == wwn2)
8567 /* check destination WWN for a match */
8568 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8569 wwn1 = wwn_to_u64(fcport->port_name);
8570 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8571 if (wwn2 == (uint64_t)-1)
8573 else if (wwn1 == wwn2)
8577 if (pid_match == 2 || wwn_match == 2) {
8578 /* Found a matching entry */
8579 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8580 priority = pri_entry->tag;
8591 * qla24xx_update_fcport_fcp_prio
8592 * Activates fcp priority for the logged in fc port
8595 * vha = scsi host structure pointer.
8596 * fcp = port structure pointer.
8599 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8605 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8611 if (fcport->port_type != FCT_TARGET ||
8612 fcport->loop_id == FC_NO_LOOP_ID)
8613 return QLA_FUNCTION_FAILED;
8615 priority = qla24xx_get_fcp_prio(vha, fcport);
8617 return QLA_FUNCTION_FAILED;
8619 if (IS_P3P_TYPE(vha->hw)) {
8620 fcport->fcp_prio = priority & 0xf;
8624 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8625 if (ret == QLA_SUCCESS) {
8626 if (fcport->fcp_prio != priority)
8627 ql_dbg(ql_dbg_user, vha, 0x709e,
8628 "Updated FCP_CMND priority - value=%d loop_id=%d "
8629 "port_id=%02x%02x%02x.\n", priority,
8630 fcport->loop_id, fcport->d_id.b.domain,
8631 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8632 fcport->fcp_prio = priority & 0xf;
8634 ql_dbg(ql_dbg_user, vha, 0x704f,
8635 "Unable to update FCP_CMND priority - ret=0x%x for "
8636 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8637 fcport->d_id.b.domain, fcport->d_id.b.area,
8638 fcport->d_id.b.al_pa);
8643 * qla24xx_update_all_fcp_prio
8644 * Activates fcp priority for all the logged in ports
8647 * ha = adapter block pointer.
8650 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8656 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8661 ret = QLA_FUNCTION_FAILED;
8662 /* We need to set priority for all logged in ports */
8663 list_for_each_entry(fcport, &vha->vp_fcports, list)
8664 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8669 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8670 int vp_idx, bool startqp)
8675 struct qla_hw_data *ha = vha->hw;
8676 uint16_t qpair_id = 0;
8677 struct qla_qpair *qpair = NULL;
8678 struct qla_msix_entry *msix;
8680 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8681 ql_log(ql_log_warn, vha, 0x00181,
8682 "FW/Driver is not multi-queue capable.\n");
8686 if (ql2xmqsupport || ql2xnvmeenable) {
8687 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8688 if (qpair == NULL) {
8689 ql_log(ql_log_warn, vha, 0x0182,
8690 "Failed to allocate memory for queue pair.\n");
8693 memset(qpair, 0, sizeof(struct qla_qpair));
8695 qpair->hw = vha->hw;
8697 qpair->qp_lock_ptr = &qpair->qp_lock;
8698 spin_lock_init(&qpair->qp_lock);
8699 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8701 /* Assign available que pair id */
8702 mutex_lock(&ha->mq_lock);
8703 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8704 if (ha->num_qpairs >= ha->max_qpairs) {
8705 mutex_unlock(&ha->mq_lock);
8706 ql_log(ql_log_warn, vha, 0x0183,
8707 "No resources to create additional q pair.\n");
8711 set_bit(qpair_id, ha->qpair_qid_map);
8712 ha->queue_pair_map[qpair_id] = qpair;
8713 qpair->id = qpair_id;
8714 qpair->vp_idx = vp_idx;
8715 qpair->fw_started = ha->flags.fw_started;
8716 INIT_LIST_HEAD(&qpair->hints_list);
8717 qpair->chip_reset = ha->base_qpair->chip_reset;
8718 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8719 qpair->enable_explicit_conf =
8720 ha->base_qpair->enable_explicit_conf;
8722 for (i = 0; i < ha->msix_count; i++) {
8723 msix = &ha->msix_entries[i];
8727 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8728 "Vector %x selected for qpair\n", msix->vector);
8732 ql_log(ql_log_warn, vha, 0x0184,
8733 "Out of MSI-X vectors!.\n");
8737 qpair->msix->in_use = 1;
8738 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8739 qpair->pdev = ha->pdev;
8740 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8741 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8743 mutex_unlock(&ha->mq_lock);
8745 /* Create response queue first */
8746 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8748 ql_log(ql_log_warn, vha, 0x0185,
8749 "Failed to create response queue.\n");
8753 qpair->rsp = ha->rsp_q_map[rsp_id];
8755 /* Create request queue */
8756 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8759 ql_log(ql_log_warn, vha, 0x0186,
8760 "Failed to create request queue.\n");
8764 qpair->req = ha->req_q_map[req_id];
8765 qpair->rsp->req = qpair->req;
8766 qpair->rsp->qpair = qpair;
8767 /* init qpair to this cpu. Will adjust at run time. */
8768 qla_cpu_update(qpair, smp_processor_id());
8770 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8771 if (ha->fw_attributes & BIT_4)
8772 qpair->difdix_supported = 1;
8775 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8776 if (!qpair->srb_mempool) {
8777 ql_log(ql_log_warn, vha, 0xd036,
8778 "Failed to create srb mempool for qpair %d\n",
8783 /* Mark as online */
8786 if (!vha->flags.qpairs_available)
8787 vha->flags.qpairs_available = 1;
8789 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8790 "Request/Response queue pair created, id %d\n",
8792 ql_dbg(ql_dbg_init, vha, 0x0187,
8793 "Request/Response queue pair created, id %d\n",
8800 qla25xx_delete_rsp_que(vha, qpair->rsp);
8802 mutex_lock(&ha->mq_lock);
8803 qpair->msix->in_use = 0;
8804 list_del(&qpair->qp_list_elem);
8805 if (list_empty(&vha->qp_list))
8806 vha->flags.qpairs_available = 0;
8808 ha->queue_pair_map[qpair_id] = NULL;
8809 clear_bit(qpair_id, ha->qpair_qid_map);
8811 mutex_unlock(&ha->mq_lock);
8817 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8819 int ret = QLA_FUNCTION_FAILED;
8820 struct qla_hw_data *ha = qpair->hw;
8822 qpair->delete_in_progress = 1;
8823 while (atomic_read(&qpair->ref_count))
8826 ret = qla25xx_delete_req_que(vha, qpair->req);
8827 if (ret != QLA_SUCCESS)
8830 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8831 if (ret != QLA_SUCCESS)
8834 mutex_lock(&ha->mq_lock);
8835 ha->queue_pair_map[qpair->id] = NULL;
8836 clear_bit(qpair->id, ha->qpair_qid_map);
8838 list_del(&qpair->qp_list_elem);
8839 if (list_empty(&vha->qp_list)) {
8840 vha->flags.qpairs_available = 0;
8841 vha->flags.qpairs_req_created = 0;
8842 vha->flags.qpairs_rsp_created = 0;
8844 mempool_destroy(qpair->srb_mempool);
8846 mutex_unlock(&ha->mq_lock);