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;
98 static void qla24xx_abort_iocb_timeout(void *data)
101 struct srb_iocb *abt = &sp->u.iocb_cmd;
102 struct qla_qpair *qpair = sp->qpair;
106 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
107 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
108 /* removing the abort */
109 if (qpair->req->outstanding_cmds[handle] == sp) {
110 qpair->req->outstanding_cmds[handle] = NULL;
114 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
116 abt->u.abt.comp_status = CS_TIMEOUT;
117 sp->done(sp, QLA_OS_TIMER_EXPIRED);
120 static void qla24xx_abort_sp_done(void *ptr, int res)
123 struct srb_iocb *abt = &sp->u.iocb_cmd;
125 if ((res == QLA_OS_TIMER_EXPIRED) ||
126 del_timer(&sp->u.iocb_cmd.timer)) {
127 if (sp->flags & SRB_WAKEUP_ON_COMP)
128 complete(&abt->u.abt.comp);
134 static int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
136 scsi_qla_host_t *vha = cmd_sp->vha;
137 struct srb_iocb *abt_iocb;
139 int rval = QLA_FUNCTION_FAILED;
141 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
146 abt_iocb = &sp->u.iocb_cmd;
147 sp->type = SRB_ABT_CMD;
149 sp->qpair = cmd_sp->qpair;
151 sp->flags = SRB_WAKEUP_ON_COMP;
153 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
154 init_completion(&abt_iocb->u.abt.comp);
155 /* FW can send 2 x ABTS's timeout/20s */
156 qla2x00_init_timer(sp, 42);
158 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
159 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
161 sp->done = qla24xx_abort_sp_done;
163 ql_dbg(ql_dbg_async, vha, 0x507c,
164 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
167 rval = qla2x00_start_sp(sp);
168 if (rval != QLA_SUCCESS)
172 wait_for_completion(&abt_iocb->u.abt.comp);
173 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
174 QLA_SUCCESS : QLA_FUNCTION_FAILED;
186 qla2x00_async_iocb_timeout(void *data)
189 fc_port_t *fcport = sp->fcport;
190 struct srb_iocb *lio = &sp->u.iocb_cmd;
195 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
196 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
197 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
199 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
201 pr_info("Async-%s timeout - hdl=%x.\n",
202 sp->name, sp->handle);
207 rc = qla24xx_async_abort_cmd(sp, false);
209 /* Retry as needed. */
210 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
211 lio->u.logio.data[1] =
212 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
213 QLA_LOGIO_LOGIN_RETRIED : 0;
214 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
215 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
217 if (sp->qpair->req->outstanding_cmds[h] ==
219 sp->qpair->req->outstanding_cmds[h] =
224 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
225 sp->done(sp, QLA_FUNCTION_TIMEOUT);
229 case SRB_CT_PTHRU_CMD:
235 rc = qla24xx_async_abort_cmd(sp, false);
237 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
238 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
240 if (sp->qpair->req->outstanding_cmds[h] ==
242 sp->qpair->req->outstanding_cmds[h] =
247 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
248 sp->done(sp, QLA_FUNCTION_TIMEOUT);
255 qla2x00_async_login_sp_done(void *ptr, int res)
258 struct scsi_qla_host *vha = sp->vha;
259 struct srb_iocb *lio = &sp->u.iocb_cmd;
262 ql_dbg(ql_dbg_disc, vha, 0x20dd,
263 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
265 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
267 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
268 memset(&ea, 0, sizeof(ea));
269 ea.event = FCME_PLOGI_DONE;
270 ea.fcport = sp->fcport;
271 ea.data[0] = lio->u.logio.data[0];
272 ea.data[1] = lio->u.logio.data[1];
273 ea.iop[0] = lio->u.logio.iop[0];
274 ea.iop[1] = lio->u.logio.iop[1];
276 qla2x00_fcport_event_handler(vha, &ea);
283 fcport_is_smaller(fc_port_t *fcport)
285 if (wwn_to_u64(fcport->port_name) <
286 wwn_to_u64(fcport->vha->port_name))
293 fcport_is_bigger(fc_port_t *fcport)
295 return !fcport_is_smaller(fcport);
299 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
303 struct srb_iocb *lio;
304 int rval = QLA_FUNCTION_FAILED;
306 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
307 fcport->loop_id == FC_NO_LOOP_ID) {
308 ql_log(ql_log_warn, vha, 0xffff,
309 "%s: %8phC - not sending command.\n",
310 __func__, fcport->port_name);
314 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
318 fcport->flags |= FCF_ASYNC_SENT;
319 fcport->logout_completed = 0;
321 fcport->disc_state = DSC_LOGIN_PEND;
322 sp->type = SRB_LOGIN_CMD;
324 sp->gen1 = fcport->rscn_gen;
325 sp->gen2 = fcport->login_gen;
327 lio = &sp->u.iocb_cmd;
328 lio->timeout = qla2x00_async_iocb_timeout;
329 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
331 sp->done = qla2x00_async_login_sp_done;
332 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
333 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
335 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
337 if (fcport->fc4f_nvme)
338 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
340 ql_dbg(ql_dbg_disc, vha, 0x2072,
341 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
342 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
343 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
344 fcport->login_retry);
346 rval = qla2x00_start_sp(sp);
347 if (rval != QLA_SUCCESS) {
348 fcport->flags |= FCF_LOGIN_NEEDED;
349 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
357 fcport->flags &= ~FCF_ASYNC_SENT;
359 fcport->flags &= ~FCF_ASYNC_ACTIVE;
364 qla2x00_async_logout_sp_done(void *ptr, int res)
368 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
369 sp->fcport->login_gen++;
370 qlt_logo_completion_handler(sp->fcport, res);
375 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
378 struct srb_iocb *lio;
379 int rval = QLA_FUNCTION_FAILED;
381 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
384 fcport->flags |= FCF_ASYNC_SENT;
385 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
389 sp->type = SRB_LOGOUT_CMD;
392 lio = &sp->u.iocb_cmd;
393 lio->timeout = qla2x00_async_iocb_timeout;
394 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
396 sp->done = qla2x00_async_logout_sp_done;
398 ql_dbg(ql_dbg_disc, vha, 0x2070,
399 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
400 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
401 fcport->d_id.b.area, fcport->d_id.b.al_pa,
404 rval = qla2x00_start_sp(sp);
405 if (rval != QLA_SUCCESS)
412 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
417 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
420 fcport->flags &= ~FCF_ASYNC_ACTIVE;
421 /* Don't re-login in target mode */
422 if (!fcport->tgt_session)
423 qla2x00_mark_device_lost(vha, fcport, 1, 0);
424 qlt_logo_completion_handler(fcport, data[0]);
428 qla2x00_async_prlo_sp_done(void *s, int res)
430 srb_t *sp = (srb_t *)s;
431 struct srb_iocb *lio = &sp->u.iocb_cmd;
432 struct scsi_qla_host *vha = sp->vha;
434 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
435 if (!test_bit(UNLOADING, &vha->dpc_flags))
436 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
442 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
445 struct srb_iocb *lio;
448 rval = QLA_FUNCTION_FAILED;
449 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
453 sp->type = SRB_PRLO_CMD;
456 lio = &sp->u.iocb_cmd;
457 lio->timeout = qla2x00_async_iocb_timeout;
458 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
460 sp->done = qla2x00_async_prlo_sp_done;
462 ql_dbg(ql_dbg_disc, vha, 0x2070,
463 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
464 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
465 fcport->d_id.b.area, fcport->d_id.b.al_pa);
467 rval = qla2x00_start_sp(sp);
468 if (rval != QLA_SUCCESS)
476 fcport->flags &= ~FCF_ASYNC_ACTIVE;
481 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
483 struct fc_port *fcport = ea->fcport;
485 ql_dbg(ql_dbg_disc, vha, 0x20d2,
486 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
487 __func__, fcport->port_name, fcport->disc_state,
488 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
489 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
491 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
492 ql_dbg(ql_dbg_disc, vha, 0x2066,
493 "%s %8phC: adisc fail: post delete\n",
494 __func__, ea->fcport->port_name);
495 /* deleted = 0 & logout_on_delete = force fw cleanup */
497 fcport->logout_on_delete = 1;
498 qlt_schedule_sess_for_deletion(ea->fcport);
502 if (ea->fcport->disc_state == DSC_DELETE_PEND)
505 if (ea->sp->gen2 != ea->fcport->login_gen) {
506 /* target side must have changed it. */
507 ql_dbg(ql_dbg_disc, vha, 0x20d3,
508 "%s %8phC generation changed\n",
509 __func__, ea->fcport->port_name);
511 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
512 qla_rscn_replay(fcport);
513 qlt_schedule_sess_for_deletion(fcport);
517 __qla24xx_handle_gpdb_event(vha, ea);
520 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
522 struct qla_work_evt *e;
524 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
526 return QLA_FUNCTION_FAILED;
528 e->u.fcport.fcport = fcport;
529 fcport->flags |= FCF_ASYNC_ACTIVE;
530 return qla2x00_post_work(vha, e);
534 qla2x00_async_adisc_sp_done(void *ptr, int res)
537 struct scsi_qla_host *vha = sp->vha;
539 struct srb_iocb *lio = &sp->u.iocb_cmd;
541 ql_dbg(ql_dbg_disc, vha, 0x2066,
542 "Async done-%s res %x %8phC\n",
543 sp->name, res, sp->fcport->port_name);
545 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
547 memset(&ea, 0, sizeof(ea));
548 ea.event = FCME_ADISC_DONE;
550 ea.data[0] = lio->u.logio.data[0];
551 ea.data[1] = lio->u.logio.data[1];
552 ea.iop[0] = lio->u.logio.iop[0];
553 ea.iop[1] = lio->u.logio.iop[1];
554 ea.fcport = sp->fcport;
557 qla2x00_fcport_event_handler(vha, &ea);
563 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
567 struct srb_iocb *lio;
568 int rval = QLA_FUNCTION_FAILED;
570 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
573 fcport->flags |= FCF_ASYNC_SENT;
574 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
578 sp->type = SRB_ADISC_CMD;
581 lio = &sp->u.iocb_cmd;
582 lio->timeout = qla2x00_async_iocb_timeout;
583 sp->gen1 = fcport->rscn_gen;
584 sp->gen2 = fcport->login_gen;
585 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
587 sp->done = qla2x00_async_adisc_sp_done;
588 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
589 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
591 ql_dbg(ql_dbg_disc, vha, 0x206f,
592 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
593 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
595 rval = qla2x00_start_sp(sp);
596 if (rval != QLA_SUCCESS)
604 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
605 qla2x00_post_async_adisc_work(vha, fcport, data);
609 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
611 struct qla_hw_data *ha = vha->hw;
613 if (IS_FWI2_CAPABLE(ha))
614 return loop_id > NPH_LAST_HANDLE;
616 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
617 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
621 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
622 * @vha: adapter state pointer.
623 * @dev: port structure pointer.
626 * qla2x00 local function return status code.
631 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
634 struct qla_hw_data *ha = vha->hw;
635 unsigned long flags = 0;
639 spin_lock_irqsave(&ha->vport_slock, flags);
641 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
642 if (dev->loop_id >= LOOPID_MAP_SIZE ||
643 qla2x00_is_reserved_id(vha, dev->loop_id)) {
644 dev->loop_id = FC_NO_LOOP_ID;
645 rval = QLA_FUNCTION_FAILED;
647 set_bit(dev->loop_id, ha->loop_id_map);
649 spin_unlock_irqrestore(&ha->vport_slock, flags);
651 if (rval == QLA_SUCCESS)
652 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
653 "Assigning new loopid=%x, portid=%x.\n",
654 dev->loop_id, dev->d_id.b24);
656 ql_log(ql_log_warn, dev->vha, 0x2087,
657 "No loop_id's available, portid=%x.\n",
663 void qla2x00_clear_loop_id(fc_port_t *fcport)
665 struct qla_hw_data *ha = fcport->vha->hw;
667 if (fcport->loop_id == FC_NO_LOOP_ID ||
668 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
671 clear_bit(fcport->loop_id, ha->loop_id_map);
672 fcport->loop_id = FC_NO_LOOP_ID;
675 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
676 struct event_arg *ea)
678 fc_port_t *fcport, *conflict_fcport;
679 struct get_name_list_extended *e;
680 u16 i, n, found = 0, loop_id;
684 u8 current_login_state;
687 ql_dbg(ql_dbg_disc, vha, 0xffff,
688 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
689 __func__, fcport->port_name, fcport->disc_state,
690 fcport->fw_login_state, ea->rc,
691 fcport->login_gen, fcport->last_login_gen,
692 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
694 if (fcport->disc_state == DSC_DELETE_PEND)
697 if (ea->rc) { /* rval */
698 if (fcport->login_retry == 0) {
699 ql_dbg(ql_dbg_disc, vha, 0x20de,
700 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
701 fcport->port_name, fcport->login_retry);
706 if (fcport->last_rscn_gen != fcport->rscn_gen) {
707 qla_rscn_replay(fcport);
708 qlt_schedule_sess_for_deletion(fcport);
710 } else if (fcport->last_login_gen != fcport->login_gen) {
711 ql_dbg(ql_dbg_disc, vha, 0x20e0,
712 "%s %8phC login gen changed\n",
713 __func__, fcport->port_name);
717 n = ea->data[0] / sizeof(struct get_name_list_extended);
719 ql_dbg(ql_dbg_disc, vha, 0x20e1,
720 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
721 __func__, __LINE__, fcport->port_name, n,
722 fcport->d_id.b.domain, fcport->d_id.b.area,
723 fcport->d_id.b.al_pa, fcport->loop_id);
725 for (i = 0; i < n; i++) {
727 wwn = wwn_to_u64(e->port_name);
728 id.b.domain = e->port_id[2];
729 id.b.area = e->port_id[1];
730 id.b.al_pa = e->port_id[0];
733 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
736 if (IS_SW_RESV_ADDR(id))
741 loop_id = le16_to_cpu(e->nport_handle);
742 loop_id = (loop_id & 0x7fff);
743 if (fcport->fc4f_nvme)
744 current_login_state = e->current_login_state >> 4;
746 current_login_state = e->current_login_state & 0xf;
749 ql_dbg(ql_dbg_disc, vha, 0x20e2,
750 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
751 __func__, fcport->port_name,
752 e->current_login_state, fcport->fw_login_state,
753 fcport->fc4f_nvme, id.b.domain, id.b.area, id.b.al_pa,
754 fcport->d_id.b.domain, fcport->d_id.b.area,
755 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
757 switch (fcport->disc_state) {
758 case DSC_DELETE_PEND:
762 if ((id.b24 != fcport->d_id.b24 &&
764 (fcport->loop_id != FC_NO_LOOP_ID &&
765 fcport->loop_id != loop_id)) {
766 ql_dbg(ql_dbg_disc, vha, 0x20e3,
767 "%s %d %8phC post del sess\n",
768 __func__, __LINE__, fcport->port_name);
769 qlt_schedule_sess_for_deletion(fcport);
775 fcport->loop_id = loop_id;
777 wwn = wwn_to_u64(fcport->port_name);
778 qlt_find_sess_invalidate_other(vha, wwn,
779 id, loop_id, &conflict_fcport);
781 if (conflict_fcport) {
783 * Another share fcport share the same loop_id &
784 * nport id. Conflict fcport needs to finish
785 * cleanup before this fcport can proceed to login.
787 conflict_fcport->conflict = fcport;
788 fcport->login_pause = 1;
791 switch (vha->hw->current_topology) {
793 switch (current_login_state) {
794 case DSC_LS_PRLI_COMP:
795 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
796 vha, 0x20e4, "%s %d %8phC post gpdb\n",
797 __func__, __LINE__, fcport->port_name);
799 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
800 fcport->port_type = FCT_INITIATOR;
802 fcport->port_type = FCT_TARGET;
803 data[0] = data[1] = 0;
804 qla2x00_post_async_adisc_work(vha, fcport,
807 case DSC_LS_PORT_UNAVAIL:
809 if (fcport->loop_id == FC_NO_LOOP_ID) {
810 qla2x00_find_new_loop_id(vha, fcport);
811 fcport->fw_login_state =
814 ql_dbg(ql_dbg_disc, vha, 0x20e5,
815 "%s %d %8phC\n", __func__, __LINE__,
817 qla24xx_fcport_handle_login(vha, fcport);
822 fcport->fw_login_state = current_login_state;
824 switch (current_login_state) {
825 case DSC_LS_PRLI_COMP:
826 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
827 fcport->port_type = FCT_INITIATOR;
829 fcport->port_type = FCT_TARGET;
831 data[0] = data[1] = 0;
832 qla2x00_post_async_adisc_work(vha, fcport,
835 case DSC_LS_PLOGI_COMP:
836 if (fcport_is_bigger(fcport)) {
837 /* local adapter is smaller */
838 if (fcport->loop_id != FC_NO_LOOP_ID)
839 qla2x00_clear_loop_id(fcport);
841 fcport->loop_id = loop_id;
842 qla24xx_fcport_handle_login(vha,
848 if (fcport_is_smaller(fcport)) {
849 /* local adapter is bigger */
850 if (fcport->loop_id != FC_NO_LOOP_ID)
851 qla2x00_clear_loop_id(fcport);
853 fcport->loop_id = loop_id;
854 qla24xx_fcport_handle_login(vha,
860 } /* switch (ha->current_topology) */
864 switch (vha->hw->current_topology) {
867 for (i = 0; i < n; i++) {
869 id.b.domain = e->port_id[0];
870 id.b.area = e->port_id[1];
871 id.b.al_pa = e->port_id[2];
873 loop_id = le16_to_cpu(e->nport_handle);
875 if (fcport->d_id.b24 == id.b24) {
877 qla2x00_find_fcport_by_wwpn(vha,
879 if (conflict_fcport) {
880 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
882 "%s %d %8phC post del sess\n",
884 conflict_fcport->port_name);
885 qlt_schedule_sess_for_deletion
890 * FW already picked this loop id for
893 if (fcport->loop_id == loop_id)
894 fcport->loop_id = FC_NO_LOOP_ID;
896 qla24xx_fcport_handle_login(vha, fcport);
899 fcport->disc_state = DSC_DELETED;
900 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
901 if (fcport->n2n_link_reset_cnt < 2) {
902 fcport->n2n_link_reset_cnt++;
904 * remote port is not sending PLOGI.
905 * Reset link to kick start his state
908 set_bit(N2N_LINK_RESET,
911 if (fcport->n2n_chip_reset < 1) {
912 ql_log(ql_log_info, vha, 0x705d,
913 "Chip reset to bring laser down");
914 set_bit(ISP_ABORT_NEEDED,
916 fcport->n2n_chip_reset++;
918 ql_log(ql_log_info, vha, 0x705d,
919 "Remote port %8ph is not coming back\n",
921 fcport->scan_state = 0;
924 qla2xxx_wake_dpc(vha);
927 * report port suppose to do PLOGI. Give him
928 * more time. FW will catch it.
930 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
940 qla24xx_async_gnl_sp_done(void *s, int res)
943 struct scsi_qla_host *vha = sp->vha;
945 struct fc_port *fcport = NULL, *tf;
946 u16 i, n = 0, loop_id;
948 struct get_name_list_extended *e;
953 ql_dbg(ql_dbg_disc, vha, 0x20e7,
954 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
955 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
956 sp->u.iocb_cmd.u.mbx.in_mb[2]);
958 if (res == QLA_FUNCTION_TIMEOUT)
961 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
962 memset(&ea, 0, sizeof(ea));
965 ea.event = FCME_GNL_DONE;
967 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
968 sizeof(struct get_name_list_extended)) {
969 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
970 sizeof(struct get_name_list_extended);
971 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
974 for (i = 0; i < n; i++) {
976 loop_id = le16_to_cpu(e->nport_handle);
977 /* mask out reserve bit */
978 loop_id = (loop_id & 0x7fff);
979 set_bit(loop_id, vha->hw->loop_id_map);
980 wwn = wwn_to_u64(e->port_name);
982 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
983 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
984 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
985 e->port_id[0], e->current_login_state, e->last_login_state,
989 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
993 if (!list_empty(&vha->gnl.fcports))
994 list_splice_init(&vha->gnl.fcports, &h);
995 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
997 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
998 list_del_init(&fcport->gnl_entry);
999 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1000 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1001 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1004 qla2x00_fcport_event_handler(vha, &ea);
1007 /* create new fcport if fw has knowledge of new sessions */
1008 for (i = 0; i < n; i++) {
1013 wwn = wwn_to_u64(e->port_name);
1016 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1017 if (!memcmp((u8 *)&wwn, fcport->port_name,
1024 id.b.domain = e->port_id[2];
1025 id.b.area = e->port_id[1];
1026 id.b.al_pa = e->port_id[0];
1029 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1030 ql_dbg(ql_dbg_disc, vha, 0x2065,
1031 "%s %d %8phC %06x post new sess\n",
1032 __func__, __LINE__, (u8 *)&wwn, id.b24);
1033 wwnn = wwn_to_u64(e->node_name);
1034 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1035 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
1039 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1041 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1046 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1049 struct srb_iocb *mbx;
1050 int rval = QLA_FUNCTION_FAILED;
1051 unsigned long flags;
1054 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1057 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1058 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1060 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1061 fcport->flags |= FCF_ASYNC_SENT;
1062 fcport->disc_state = DSC_GNL;
1063 fcport->last_rscn_gen = fcport->rscn_gen;
1064 fcport->last_login_gen = fcport->login_gen;
1066 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1067 if (vha->gnl.sent) {
1068 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1072 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1074 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1078 sp->type = SRB_MB_IOCB;
1079 sp->name = "gnlist";
1080 sp->gen1 = fcport->rscn_gen;
1081 sp->gen2 = fcport->login_gen;
1083 mbx = &sp->u.iocb_cmd;
1084 mbx->timeout = qla2x00_async_iocb_timeout;
1085 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1087 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1088 mb[0] = MBC_PORT_NODE_NAME_LIST;
1089 mb[1] = BIT_2 | BIT_3;
1090 mb[2] = MSW(vha->gnl.ldma);
1091 mb[3] = LSW(vha->gnl.ldma);
1092 mb[6] = MSW(MSD(vha->gnl.ldma));
1093 mb[7] = LSW(MSD(vha->gnl.ldma));
1094 mb[8] = vha->gnl.size;
1095 mb[9] = vha->vp_idx;
1097 sp->done = qla24xx_async_gnl_sp_done;
1099 ql_dbg(ql_dbg_disc, vha, 0x20da,
1100 "Async-%s - OUT WWPN %8phC hndl %x\n",
1101 sp->name, fcport->port_name, sp->handle);
1103 rval = qla2x00_start_sp(sp);
1104 if (rval != QLA_SUCCESS)
1111 fcport->flags &= ~FCF_ASYNC_SENT;
1116 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1118 struct qla_work_evt *e;
1120 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1122 return QLA_FUNCTION_FAILED;
1124 e->u.fcport.fcport = fcport;
1125 fcport->flags |= FCF_ASYNC_ACTIVE;
1126 return qla2x00_post_work(vha, e);
1130 void qla24xx_async_gpdb_sp_done(void *s, int res)
1133 struct scsi_qla_host *vha = sp->vha;
1134 struct qla_hw_data *ha = vha->hw;
1135 fc_port_t *fcport = sp->fcport;
1136 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1137 struct event_arg ea;
1139 ql_dbg(ql_dbg_disc, vha, 0x20db,
1140 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1141 sp->name, res, fcport->port_name, mb[1], mb[2]);
1143 if (res == QLA_FUNCTION_TIMEOUT) {
1144 dma_pool_free(sp->vha->hw->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1145 sp->u.iocb_cmd.u.mbx.in_dma);
1149 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1150 memset(&ea, 0, sizeof(ea));
1151 ea.event = FCME_GPDB_DONE;
1155 qla2x00_fcport_event_handler(vha, &ea);
1157 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1158 sp->u.iocb_cmd.u.mbx.in_dma);
1163 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1165 struct qla_work_evt *e;
1167 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1169 return QLA_FUNCTION_FAILED;
1171 e->u.fcport.fcport = fcport;
1173 return qla2x00_post_work(vha, e);
1177 qla2x00_async_prli_sp_done(void *ptr, int res)
1180 struct scsi_qla_host *vha = sp->vha;
1181 struct srb_iocb *lio = &sp->u.iocb_cmd;
1182 struct event_arg ea;
1184 ql_dbg(ql_dbg_disc, vha, 0x2129,
1185 "%s %8phC res %d \n", __func__,
1186 sp->fcport->port_name, res);
1188 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1190 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1191 memset(&ea, 0, sizeof(ea));
1192 ea.event = FCME_PRLI_DONE;
1193 ea.fcport = sp->fcport;
1194 ea.data[0] = lio->u.logio.data[0];
1195 ea.data[1] = lio->u.logio.data[1];
1196 ea.iop[0] = lio->u.logio.iop[0];
1197 ea.iop[1] = lio->u.logio.iop[1];
1200 qla2x00_fcport_event_handler(vha, &ea);
1207 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1210 struct srb_iocb *lio;
1211 int rval = QLA_FUNCTION_FAILED;
1213 if (!vha->flags.online)
1216 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1217 fcport->fw_login_state == DSC_LS_PRLI_PEND)
1220 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1224 fcport->flags |= FCF_ASYNC_SENT;
1225 fcport->logout_completed = 0;
1227 sp->type = SRB_PRLI_CMD;
1230 lio = &sp->u.iocb_cmd;
1231 lio->timeout = qla2x00_async_iocb_timeout;
1232 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1234 sp->done = qla2x00_async_prli_sp_done;
1235 lio->u.logio.flags = 0;
1237 if (fcport->fc4f_nvme)
1238 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1240 ql_dbg(ql_dbg_disc, vha, 0x211b,
1241 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1242 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1243 fcport->login_retry, fcport->fc4f_nvme ? "nvme" : "fc");
1245 rval = qla2x00_start_sp(sp);
1246 if (rval != QLA_SUCCESS) {
1247 fcport->flags |= FCF_LOGIN_NEEDED;
1248 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1256 fcport->flags &= ~FCF_ASYNC_SENT;
1260 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1262 struct qla_work_evt *e;
1264 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1266 return QLA_FUNCTION_FAILED;
1268 e->u.fcport.fcport = fcport;
1269 e->u.fcport.opt = opt;
1270 fcport->flags |= FCF_ASYNC_ACTIVE;
1271 return qla2x00_post_work(vha, e);
1274 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1277 struct srb_iocb *mbx;
1278 int rval = QLA_FUNCTION_FAILED;
1281 struct port_database_24xx *pd;
1282 struct qla_hw_data *ha = vha->hw;
1284 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1285 fcport->loop_id == FC_NO_LOOP_ID) {
1286 ql_log(ql_log_warn, vha, 0xffff,
1287 "%s: %8phC - not sending command.\n",
1288 __func__, fcport->port_name);
1292 fcport->disc_state = DSC_GPDB;
1294 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1298 fcport->flags |= FCF_ASYNC_SENT;
1299 sp->type = SRB_MB_IOCB;
1301 sp->gen1 = fcport->rscn_gen;
1302 sp->gen2 = fcport->login_gen;
1304 mbx = &sp->u.iocb_cmd;
1305 mbx->timeout = qla2x00_async_iocb_timeout;
1306 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1308 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1310 ql_log(ql_log_warn, vha, 0xd043,
1311 "Failed to allocate port database structure.\n");
1315 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1316 mb[0] = MBC_GET_PORT_DATABASE;
1317 mb[1] = fcport->loop_id;
1318 mb[2] = MSW(pd_dma);
1319 mb[3] = LSW(pd_dma);
1320 mb[6] = MSW(MSD(pd_dma));
1321 mb[7] = LSW(MSD(pd_dma));
1322 mb[9] = vha->vp_idx;
1325 mbx->u.mbx.in = (void *)pd;
1326 mbx->u.mbx.in_dma = pd_dma;
1328 sp->done = qla24xx_async_gpdb_sp_done;
1330 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1331 "Async-%s %8phC hndl %x opt %x\n",
1332 sp->name, fcport->port_name, sp->handle, opt);
1334 rval = qla2x00_start_sp(sp);
1335 if (rval != QLA_SUCCESS)
1341 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1344 fcport->flags &= ~FCF_ASYNC_SENT;
1346 qla24xx_post_gpdb_work(vha, fcport, opt);
1351 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1353 unsigned long flags;
1355 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1356 ea->fcport->login_gen++;
1357 ea->fcport->deleted = 0;
1358 ea->fcport->logout_on_delete = 1;
1360 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1361 vha->fcport_count++;
1362 ea->fcport->login_succ = 1;
1364 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1365 qla24xx_sched_upd_fcport(ea->fcport);
1366 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1367 } else if (ea->fcport->login_succ) {
1369 * We have an existing session. A late RSCN delivery
1370 * must have triggered the session to be re-validate.
1371 * Session is still valid.
1373 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1374 "%s %d %8phC session revalidate success\n",
1375 __func__, __LINE__, ea->fcport->port_name);
1376 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1378 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1382 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1384 fc_port_t *fcport = ea->fcport;
1385 struct port_database_24xx *pd;
1386 struct srb *sp = ea->sp;
1389 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1391 fcport->flags &= ~FCF_ASYNC_SENT;
1393 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1394 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__, fcport->port_name,
1395 fcport->disc_state, pd->current_login_state, fcport->fc4f_nvme,
1398 if (fcport->disc_state == DSC_DELETE_PEND)
1401 if (fcport->fc4f_nvme)
1402 ls = pd->current_login_state >> 4;
1404 ls = pd->current_login_state & 0xf;
1406 if (ea->sp->gen2 != fcport->login_gen) {
1407 /* target side must have changed it. */
1409 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1410 "%s %8phC generation changed\n",
1411 __func__, fcport->port_name);
1413 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1414 qla_rscn_replay(fcport);
1415 qlt_schedule_sess_for_deletion(fcport);
1420 case PDS_PRLI_COMPLETE:
1421 __qla24xx_parse_gpdb(vha, fcport, pd);
1423 case PDS_PLOGI_PENDING:
1424 case PDS_PLOGI_COMPLETE:
1425 case PDS_PRLI_PENDING:
1426 case PDS_PRLI2_PENDING:
1427 /* Set discovery state back to GNL to Relogin attempt */
1428 if (qla_dual_mode_enabled(vha) ||
1429 qla_ini_mode_enabled(vha)) {
1430 fcport->disc_state = DSC_GNL;
1431 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1434 case PDS_LOGO_PENDING:
1435 case PDS_PORT_UNAVAILABLE:
1437 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1438 __func__, __LINE__, fcport->port_name);
1439 qlt_schedule_sess_for_deletion(fcport);
1442 __qla24xx_handle_gpdb_event(vha, ea);
1445 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1450 if (qla_tgt_mode_enabled(vha))
1453 if (qla_dual_mode_enabled(vha)) {
1454 if (N2N_TOPO(vha->hw)) {
1457 mywwn = wwn_to_u64(vha->port_name);
1458 wwn = wwn_to_u64(fcport->port_name);
1461 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1462 && time_after_eq(jiffies,
1463 fcport->plogi_nack_done_deadline))
1469 /* initiator mode */
1473 if (login && fcport->login_retry) {
1474 fcport->login_retry--;
1475 if (fcport->loop_id == FC_NO_LOOP_ID) {
1476 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1477 rc = qla2x00_find_new_loop_id(vha, fcport);
1479 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1480 "%s %d %8phC post del sess - out of loopid\n",
1481 __func__, __LINE__, fcport->port_name);
1482 fcport->scan_state = 0;
1483 qlt_schedule_sess_for_deletion(fcport);
1487 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1488 "%s %d %8phC post login\n",
1489 __func__, __LINE__, fcport->port_name);
1490 qla2x00_post_async_login_work(vha, fcport, NULL);
1494 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1500 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20d8,
1501 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1502 __func__, fcport->port_name, fcport->disc_state,
1503 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1504 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1505 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1507 if (fcport->scan_state != QLA_FCPORT_FOUND)
1510 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1511 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1512 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1515 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1516 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1517 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1522 /* for pure Target Mode. Login will not be initiated */
1523 if (vha->host->active_mode == MODE_TARGET)
1526 if (fcport->flags & FCF_ASYNC_SENT) {
1527 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1531 switch (fcport->disc_state) {
1533 wwn = wwn_to_u64(fcport->node_name);
1534 switch (vha->hw->current_topology) {
1536 if (fcport_is_smaller(fcport)) {
1537 /* this adapter is bigger */
1538 if (fcport->login_retry) {
1539 if (fcport->loop_id == FC_NO_LOOP_ID) {
1540 qla2x00_find_new_loop_id(vha,
1542 fcport->fw_login_state =
1543 DSC_LS_PORT_UNAVAIL;
1545 fcport->login_retry--;
1546 qla_post_els_plogi_work(vha, fcport);
1548 ql_log(ql_log_info, vha, 0x705d,
1549 "Unable to reach remote port %8phC",
1553 qla24xx_post_gnl_work(vha, fcport);
1558 ql_dbg(ql_dbg_disc, vha, 0xffff,
1559 "%s %d %8phC post GNNID\n",
1560 __func__, __LINE__, fcport->port_name);
1561 qla24xx_post_gnnid_work(vha, fcport);
1562 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1563 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1564 "%s %d %8phC post gnl\n",
1565 __func__, __LINE__, fcport->port_name);
1566 qla24xx_post_gnl_work(vha, fcport);
1568 qla_chk_n2n_b4_login(vha, fcport);
1575 switch (vha->hw->current_topology) {
1577 if ((fcport->current_login_state & 0xf) == 0x6) {
1578 ql_dbg(ql_dbg_disc, vha, 0x2118,
1579 "%s %d %8phC post GPDB work\n",
1580 __func__, __LINE__, fcport->port_name);
1581 fcport->chip_reset =
1582 vha->hw->base_qpair->chip_reset;
1583 qla24xx_post_gpdb_work(vha, fcport, 0);
1585 ql_dbg(ql_dbg_disc, vha, 0x2118,
1586 "%s %d %8phC post NVMe PRLI\n",
1587 __func__, __LINE__, fcport->port_name);
1588 qla24xx_post_prli_work(vha, fcport);
1592 if (fcport->login_pause) {
1593 fcport->last_rscn_gen = fcport->rscn_gen;
1594 fcport->last_login_gen = fcport->login_gen;
1595 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1598 qla_chk_n2n_b4_login(vha, fcport);
1603 case DSC_LOGIN_FAILED:
1604 if (N2N_TOPO(vha->hw))
1605 qla_chk_n2n_b4_login(vha, fcport);
1607 qlt_schedule_sess_for_deletion(fcport);
1610 case DSC_LOGIN_COMPLETE:
1611 /* recheck login state */
1612 data[0] = data[1] = 0;
1613 qla2x00_post_async_adisc_work(vha, fcport, data);
1616 case DSC_LOGIN_PEND:
1617 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1618 qla24xx_post_prli_work(vha, fcport);
1621 case DSC_UPD_FCPORT:
1622 sec = jiffies_to_msecs(jiffies -
1623 fcport->jiffies_at_registration)/1000;
1624 if (fcport->sec_since_registration < sec && sec &&
1626 fcport->sec_since_registration = sec;
1627 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1628 "%s %8phC - Slow Rport registration(%d Sec)\n",
1629 __func__, fcport->port_name, sec);
1632 if (fcport->next_disc_state != DSC_DELETE_PEND)
1633 fcport->next_disc_state = DSC_ADISC;
1634 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1644 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1645 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1647 struct qla_work_evt *e;
1649 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1651 return QLA_FUNCTION_FAILED;
1653 e->u.new_sess.id = *id;
1654 e->u.new_sess.pla = pla;
1655 e->u.new_sess.fc4_type = fc4_type;
1656 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1658 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1660 return qla2x00_post_work(vha, e);
1664 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1665 struct event_arg *ea)
1667 fc_port_t *fcport = ea->fcport;
1669 ql_dbg(ql_dbg_disc, vha, 0x2102,
1670 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1671 __func__, fcport->port_name, fcport->disc_state,
1672 fcport->fw_login_state, fcport->login_pause,
1673 fcport->deleted, fcport->conflict,
1674 fcport->last_rscn_gen, fcport->rscn_gen,
1675 fcport->last_login_gen, fcport->login_gen,
1678 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1679 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1682 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1683 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1684 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1689 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1690 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1691 __func__, __LINE__, fcport->port_name);
1692 qla24xx_post_gnl_work(vha, fcport);
1696 qla24xx_fcport_handle_login(vha, fcport);
1700 static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1701 struct event_arg *ea)
1703 ql_dbg(ql_dbg_disc, vha, 0x2118,
1704 "%s %d %8phC post PRLI\n",
1705 __func__, __LINE__, ea->fcport->port_name);
1706 qla24xx_post_prli_work(vha, ea->fcport);
1709 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1713 switch (ea->event) {
1715 if (test_bit(UNLOADING, &vha->dpc_flags))
1718 qla24xx_handle_relogin_event(vha, ea);
1721 if (test_bit(UNLOADING, &vha->dpc_flags))
1724 unsigned long flags;
1726 fcport = qla2x00_find_fcport_by_nportid
1729 fcport->scan_needed = 1;
1733 spin_lock_irqsave(&vha->work_lock, flags);
1734 if (vha->scan.scan_flags == 0) {
1735 ql_dbg(ql_dbg_disc, vha, 0xffff,
1736 "%s: schedule\n", __func__);
1737 vha->scan.scan_flags |= SF_QUEUED;
1738 schedule_delayed_work(&vha->scan.scan_work, 5);
1740 spin_unlock_irqrestore(&vha->work_lock, flags);
1744 qla24xx_handle_gnl_done_event(vha, ea);
1746 case FCME_GPSC_DONE:
1747 qla24xx_handle_gpsc_event(vha, ea);
1749 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1750 qla24xx_handle_plogi_done_event(vha, ea);
1752 case FCME_PRLI_DONE:
1753 qla24xx_handle_prli_done_event(vha, ea);
1755 case FCME_GPDB_DONE:
1756 qla24xx_handle_gpdb_event(vha, ea);
1758 case FCME_GPNID_DONE:
1759 qla24xx_handle_gpnid_event(vha, ea);
1761 case FCME_GFFID_DONE:
1762 qla24xx_handle_gffid_event(vha, ea);
1764 case FCME_ADISC_DONE:
1765 qla24xx_handle_adisc_event(vha, ea);
1767 case FCME_GNNID_DONE:
1768 qla24xx_handle_gnnid_event(vha, ea);
1770 case FCME_GFPNID_DONE:
1771 qla24xx_handle_gfpnid_event(vha, ea);
1773 case FCME_ELS_PLOGI_DONE:
1774 qla_handle_els_plogi_done(vha, ea);
1783 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1784 * to be consumed by the fcport
1786 void qla_rscn_replay(fc_port_t *fcport)
1788 struct event_arg ea;
1790 switch (fcport->disc_state) {
1791 case DSC_DELETE_PEND:
1797 if (fcport->scan_needed) {
1798 memset(&ea, 0, sizeof(ea));
1799 ea.event = FCME_RSCN;
1800 ea.id = fcport->d_id;
1801 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1802 qla2x00_fcport_event_handler(fcport->vha, &ea);
1807 qla2x00_tmf_iocb_timeout(void *data)
1810 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1812 tmf->u.tmf.comp_status = CS_TIMEOUT;
1813 complete(&tmf->u.tmf.comp);
1817 qla2x00_tmf_sp_done(void *ptr, int res)
1820 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1822 complete(&tmf->u.tmf.comp);
1826 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1829 struct scsi_qla_host *vha = fcport->vha;
1830 struct srb_iocb *tm_iocb;
1832 int rval = QLA_FUNCTION_FAILED;
1834 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1838 tm_iocb = &sp->u.iocb_cmd;
1839 sp->type = SRB_TM_CMD;
1842 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1843 init_completion(&tm_iocb->u.tmf.comp);
1844 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1846 tm_iocb->u.tmf.flags = flags;
1847 tm_iocb->u.tmf.lun = lun;
1848 tm_iocb->u.tmf.data = tag;
1849 sp->done = qla2x00_tmf_sp_done;
1851 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1852 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1853 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1854 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1856 rval = qla2x00_start_sp(sp);
1857 if (rval != QLA_SUCCESS)
1859 wait_for_completion(&tm_iocb->u.tmf.comp);
1861 rval = tm_iocb->u.tmf.data;
1863 if (rval != QLA_SUCCESS) {
1864 ql_log(ql_log_warn, vha, 0x8030,
1865 "TM IOCB failed (%x).\n", rval);
1868 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1869 flags = tm_iocb->u.tmf.flags;
1870 lun = (uint16_t)tm_iocb->u.tmf.lun;
1872 /* Issue Marker IOCB */
1873 qla2x00_marker(vha, vha->hw->base_qpair,
1874 fcport->loop_id, lun,
1875 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1880 fcport->flags &= ~FCF_ASYNC_SENT;
1886 qla24xx_async_abort_command(srb_t *sp)
1888 unsigned long flags = 0;
1891 fc_port_t *fcport = sp->fcport;
1892 struct qla_qpair *qpair = sp->qpair;
1893 struct scsi_qla_host *vha = fcport->vha;
1894 struct req_que *req = qpair->req;
1896 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1897 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1898 if (req->outstanding_cmds[handle] == sp)
1901 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1903 if (handle == req->num_outstanding_cmds) {
1904 /* Command not found. */
1905 return QLA_FUNCTION_FAILED;
1907 if (sp->type == SRB_FXIOCB_DCMD)
1908 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1909 FXDISC_ABORT_IOCTL);
1911 return qla24xx_async_abort_cmd(sp, true);
1915 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1917 switch (ea->data[0]) {
1918 case MBS_COMMAND_COMPLETE:
1919 ql_dbg(ql_dbg_disc, vha, 0x2118,
1920 "%s %d %8phC post gpdb\n",
1921 __func__, __LINE__, ea->fcport->port_name);
1923 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1924 ea->fcport->logout_on_delete = 1;
1925 ea->fcport->nvme_prli_service_param = ea->iop[0];
1926 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1927 ea->fcport->nvme_first_burst_size =
1928 (ea->iop[1] & 0xffff) * 512;
1930 ea->fcport->nvme_first_burst_size = 0;
1931 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1934 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1935 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1936 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1937 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1941 if (ea->fcport->n2n_flag) {
1942 ql_dbg(ql_dbg_disc, vha, 0x2118,
1943 "%s %d %8phC post fc4 prli\n",
1944 __func__, __LINE__, ea->fcport->port_name);
1945 ea->fcport->fc4f_nvme = 0;
1946 ea->fcport->n2n_flag = 0;
1947 qla24xx_post_prli_work(vha, ea->fcport);
1949 ql_dbg(ql_dbg_disc, vha, 0x2119,
1950 "%s %d %8phC unhandle event of %x\n",
1951 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1957 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1959 port_id_t cid; /* conflict Nport id */
1961 struct fc_port *conflict_fcport;
1962 unsigned long flags;
1963 struct fc_port *fcport = ea->fcport;
1965 ql_dbg(ql_dbg_disc, vha, 0xffff,
1966 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1967 __func__, fcport->port_name, fcport->disc_state,
1968 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1969 ea->sp->gen1, fcport->rscn_gen,
1970 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1972 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1973 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1974 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1975 "%s %d %8phC Remote is trying to login\n",
1976 __func__, __LINE__, fcport->port_name);
1980 if ((fcport->disc_state == DSC_DELETE_PEND) ||
1981 (fcport->disc_state == DSC_DELETED)) {
1982 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1986 if (ea->sp->gen2 != fcport->login_gen) {
1987 /* target side must have changed it. */
1988 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1989 "%s %8phC generation changed\n",
1990 __func__, fcport->port_name);
1991 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1993 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1994 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1995 "%s %8phC RSCN generation changed\n",
1996 __func__, fcport->port_name);
1997 qla_rscn_replay(fcport);
1998 qlt_schedule_sess_for_deletion(fcport);
2002 switch (ea->data[0]) {
2003 case MBS_COMMAND_COMPLETE:
2005 * Driver must validate login state - If PRLI not complete,
2006 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2009 if (ea->fcport->fc4f_nvme) {
2010 ql_dbg(ql_dbg_disc, vha, 0x2117,
2011 "%s %d %8phC post prli\n",
2012 __func__, __LINE__, ea->fcport->port_name);
2013 qla24xx_post_prli_work(vha, ea->fcport);
2015 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2016 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
2017 __func__, __LINE__, ea->fcport->port_name,
2018 ea->fcport->loop_id, ea->fcport->d_id.b24);
2020 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2021 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2022 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2023 ea->fcport->logout_on_delete = 1;
2024 ea->fcport->send_els_logo = 0;
2025 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2026 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2028 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2031 case MBS_COMMAND_ERROR:
2032 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2033 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2035 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2036 ea->fcport->disc_state = DSC_LOGIN_FAILED;
2037 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2038 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2040 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2042 case MBS_LOOP_ID_USED:
2043 /* data[1] = IO PARAM 1 = nport ID */
2044 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2045 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2046 cid.b.al_pa = ea->iop[1] & 0xff;
2049 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2050 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2051 __func__, __LINE__, ea->fcport->port_name,
2052 ea->fcport->loop_id, cid.b24);
2054 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2055 ea->fcport->loop_id = FC_NO_LOOP_ID;
2056 qla24xx_post_gnl_work(vha, ea->fcport);
2058 case MBS_PORT_ID_USED:
2059 lid = ea->iop[1] & 0xffff;
2060 qlt_find_sess_invalidate_other(vha,
2061 wwn_to_u64(ea->fcport->port_name),
2062 ea->fcport->d_id, lid, &conflict_fcport);
2064 if (conflict_fcport) {
2066 * Another fcport share the same loop_id/nport id.
2067 * Conflict fcport needs to finish cleanup before this
2068 * fcport can proceed to login.
2070 conflict_fcport->conflict = ea->fcport;
2071 ea->fcport->login_pause = 1;
2073 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2074 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2075 __func__, __LINE__, ea->fcport->port_name,
2076 ea->fcport->d_id.b24, lid);
2078 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2079 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2080 __func__, __LINE__, ea->fcport->port_name,
2081 ea->fcport->d_id.b24, lid);
2083 qla2x00_clear_loop_id(ea->fcport);
2084 set_bit(lid, vha->hw->loop_id_map);
2085 ea->fcport->loop_id = lid;
2086 ea->fcport->keep_nport_handle = 0;
2087 qlt_schedule_sess_for_deletion(ea->fcport);
2095 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2098 qlt_logo_completion_handler(fcport, data[0]);
2099 fcport->login_gen++;
2100 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2104 /****************************************************************************/
2105 /* QLogic ISP2x00 Hardware Support Functions. */
2106 /****************************************************************************/
2109 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2111 int rval = QLA_SUCCESS;
2112 struct qla_hw_data *ha = vha->hw;
2113 uint32_t idc_major_ver, idc_minor_ver;
2116 qla83xx_idc_lock(vha, 0);
2118 /* SV: TODO: Assign initialization timeout from
2119 * flash-info / other param
2121 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2122 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2124 /* Set our fcoe function presence */
2125 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2126 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2127 "Error while setting DRV-Presence.\n");
2128 rval = QLA_FUNCTION_FAILED;
2132 /* Decide the reset ownership */
2133 qla83xx_reset_ownership(vha);
2136 * On first protocol driver load:
2137 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2139 * Others: Check compatibility with current IDC Major version.
2141 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2142 if (ha->flags.nic_core_reset_owner) {
2143 /* Set IDC Major version */
2144 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2145 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2147 /* Clearing IDC-Lock-Recovery register */
2148 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2149 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2151 * Clear further IDC participation if we are not compatible with
2152 * the current IDC Major Version.
2154 ql_log(ql_log_warn, vha, 0xb07d,
2155 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2156 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2157 __qla83xx_clear_drv_presence(vha);
2158 rval = QLA_FUNCTION_FAILED;
2161 /* Each function sets its supported Minor version. */
2162 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2163 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2164 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2166 if (ha->flags.nic_core_reset_owner) {
2167 memset(config, 0, sizeof(config));
2168 if (!qla81xx_get_port_config(vha, config))
2169 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2173 rval = qla83xx_idc_state_handler(vha);
2176 qla83xx_idc_unlock(vha, 0);
2182 * qla2x00_initialize_adapter
2186 * ha = adapter block pointer.
2192 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2195 struct qla_hw_data *ha = vha->hw;
2196 struct req_que *req = ha->req_q_map[0];
2197 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2199 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2200 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2202 /* Clear adapter flags. */
2203 vha->flags.online = 0;
2204 ha->flags.chip_reset_done = 0;
2205 vha->flags.reset_active = 0;
2206 ha->flags.pci_channel_io_perm_failure = 0;
2207 ha->flags.eeh_busy = 0;
2208 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2209 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2210 atomic_set(&vha->loop_state, LOOP_DOWN);
2211 vha->device_flags = DFLG_NO_CABLE;
2213 vha->flags.management_server_logged_in = 0;
2214 vha->marker_needed = 0;
2215 ha->isp_abort_cnt = 0;
2216 ha->beacon_blink_led = 0;
2218 set_bit(0, ha->req_qid_map);
2219 set_bit(0, ha->rsp_qid_map);
2221 ql_dbg(ql_dbg_init, vha, 0x0040,
2222 "Configuring PCI space...\n");
2223 rval = ha->isp_ops->pci_config(vha);
2225 ql_log(ql_log_warn, vha, 0x0044,
2226 "Unable to configure PCI space.\n");
2230 ha->isp_ops->reset_chip(vha);
2232 /* Check for secure flash support */
2233 if (IS_QLA28XX(ha)) {
2234 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2235 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2236 ha->flags.secure_adapter = 1;
2241 rval = qla2xxx_get_flash_info(vha);
2243 ql_log(ql_log_fatal, vha, 0x004f,
2244 "Unable to validate FLASH data.\n");
2248 if (IS_QLA8044(ha)) {
2249 qla8044_read_reset_template(vha);
2251 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2252 * If DONRESET_BIT0 is set, drivers should not set dev_state
2253 * to NEED_RESET. But if NEED_RESET is set, drivers should
2254 * should honor the reset. */
2255 if (ql2xdontresethba == 1)
2256 qla8044_set_idc_dontreset(vha);
2259 ha->isp_ops->get_flash_version(vha, req->ring);
2260 ql_dbg(ql_dbg_init, vha, 0x0061,
2261 "Configure NVRAM parameters...\n");
2263 ha->isp_ops->nvram_config(vha);
2265 if (ha->flags.disable_serdes) {
2266 /* Mask HBA via NVRAM settings? */
2267 ql_log(ql_log_info, vha, 0x0077,
2268 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2269 return QLA_FUNCTION_FAILED;
2272 ql_dbg(ql_dbg_init, vha, 0x0078,
2273 "Verifying loaded RISC code...\n");
2275 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2276 rval = ha->isp_ops->chip_diag(vha);
2279 rval = qla2x00_setup_chip(vha);
2284 if (IS_QLA84XX(ha)) {
2285 ha->cs84xx = qla84xx_get_chip(vha);
2287 ql_log(ql_log_warn, vha, 0x00d0,
2288 "Unable to configure ISP84XX.\n");
2289 return QLA_FUNCTION_FAILED;
2293 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2294 rval = qla2x00_init_rings(vha);
2296 /* No point in continuing if firmware initialization failed. */
2297 if (rval != QLA_SUCCESS)
2300 ha->flags.chip_reset_done = 1;
2302 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2303 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2304 rval = qla84xx_init_chip(vha);
2305 if (rval != QLA_SUCCESS) {
2306 ql_log(ql_log_warn, vha, 0x00d4,
2307 "Unable to initialize ISP84XX.\n");
2308 qla84xx_put_chip(vha);
2312 /* Load the NIC Core f/w if we are the first protocol driver. */
2313 if (IS_QLA8031(ha)) {
2314 rval = qla83xx_nic_core_fw_load(vha);
2316 ql_log(ql_log_warn, vha, 0x0124,
2317 "Error in initializing NIC Core f/w.\n");
2320 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2321 qla24xx_read_fcp_prio_cfg(vha);
2323 if (IS_P3P_TYPE(ha))
2324 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2326 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2332 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2335 * Returns 0 on success.
2338 qla2100_pci_config(scsi_qla_host_t *vha)
2341 unsigned long flags;
2342 struct qla_hw_data *ha = vha->hw;
2343 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2345 pci_set_master(ha->pdev);
2346 pci_try_set_mwi(ha->pdev);
2348 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2349 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2350 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2352 pci_disable_rom(ha->pdev);
2354 /* Get PCI bus information. */
2355 spin_lock_irqsave(&ha->hardware_lock, flags);
2356 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2357 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2363 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2366 * Returns 0 on success.
2369 qla2300_pci_config(scsi_qla_host_t *vha)
2372 unsigned long flags = 0;
2374 struct qla_hw_data *ha = vha->hw;
2375 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2377 pci_set_master(ha->pdev);
2378 pci_try_set_mwi(ha->pdev);
2380 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2381 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2383 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2384 w &= ~PCI_COMMAND_INTX_DISABLE;
2385 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2388 * If this is a 2300 card and not 2312, reset the
2389 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2390 * the 2310 also reports itself as a 2300 so we need to get the
2391 * fb revision level -- a 6 indicates it really is a 2300 and
2394 if (IS_QLA2300(ha)) {
2395 spin_lock_irqsave(&ha->hardware_lock, flags);
2398 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2399 for (cnt = 0; cnt < 30000; cnt++) {
2400 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2406 /* Select FPM registers. */
2407 WRT_REG_WORD(®->ctrl_status, 0x20);
2408 RD_REG_WORD(®->ctrl_status);
2410 /* Get the fb rev level */
2411 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2413 if (ha->fb_rev == FPM_2300)
2414 pci_clear_mwi(ha->pdev);
2416 /* Deselect FPM registers. */
2417 WRT_REG_WORD(®->ctrl_status, 0x0);
2418 RD_REG_WORD(®->ctrl_status);
2420 /* Release RISC module. */
2421 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2422 for (cnt = 0; cnt < 30000; cnt++) {
2423 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2429 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2432 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2434 pci_disable_rom(ha->pdev);
2436 /* Get PCI bus information. */
2437 spin_lock_irqsave(&ha->hardware_lock, flags);
2438 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2439 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2445 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2448 * Returns 0 on success.
2451 qla24xx_pci_config(scsi_qla_host_t *vha)
2454 unsigned long flags = 0;
2455 struct qla_hw_data *ha = vha->hw;
2456 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2458 pci_set_master(ha->pdev);
2459 pci_try_set_mwi(ha->pdev);
2461 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2462 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2463 w &= ~PCI_COMMAND_INTX_DISABLE;
2464 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2466 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2468 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2469 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2470 pcix_set_mmrbc(ha->pdev, 2048);
2472 /* PCIe -- adjust Maximum Read Request Size (2048). */
2473 if (pci_is_pcie(ha->pdev))
2474 pcie_set_readrq(ha->pdev, 4096);
2476 pci_disable_rom(ha->pdev);
2478 ha->chip_revision = ha->pdev->revision;
2480 /* Get PCI bus information. */
2481 spin_lock_irqsave(&ha->hardware_lock, flags);
2482 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2483 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2489 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2492 * Returns 0 on success.
2495 qla25xx_pci_config(scsi_qla_host_t *vha)
2498 struct qla_hw_data *ha = vha->hw;
2500 pci_set_master(ha->pdev);
2501 pci_try_set_mwi(ha->pdev);
2503 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2504 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2505 w &= ~PCI_COMMAND_INTX_DISABLE;
2506 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2508 /* PCIe -- adjust Maximum Read Request Size (2048). */
2509 if (pci_is_pcie(ha->pdev))
2510 pcie_set_readrq(ha->pdev, 4096);
2512 pci_disable_rom(ha->pdev);
2514 ha->chip_revision = ha->pdev->revision;
2520 * qla2x00_isp_firmware() - Choose firmware image.
2523 * Returns 0 on success.
2526 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2529 uint16_t loop_id, topo, sw_cap;
2530 uint8_t domain, area, al_pa;
2531 struct qla_hw_data *ha = vha->hw;
2533 /* Assume loading risc code */
2534 rval = QLA_FUNCTION_FAILED;
2536 if (ha->flags.disable_risc_code_load) {
2537 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2539 /* Verify checksum of loaded RISC code. */
2540 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2541 if (rval == QLA_SUCCESS) {
2542 /* And, verify we are not in ROM code. */
2543 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2544 &area, &domain, &topo, &sw_cap);
2549 ql_dbg(ql_dbg_init, vha, 0x007a,
2550 "**** Load RISC code ****.\n");
2556 * qla2x00_reset_chip() - Reset ISP chip.
2559 * Returns 0 on success.
2562 qla2x00_reset_chip(scsi_qla_host_t *vha)
2564 unsigned long flags = 0;
2565 struct qla_hw_data *ha = vha->hw;
2566 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2569 int rval = QLA_FUNCTION_FAILED;
2571 if (unlikely(pci_channel_offline(ha->pdev)))
2574 ha->isp_ops->disable_intrs(ha);
2576 spin_lock_irqsave(&ha->hardware_lock, flags);
2578 /* Turn off master enable */
2580 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2581 cmd &= ~PCI_COMMAND_MASTER;
2582 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2584 if (!IS_QLA2100(ha)) {
2586 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2587 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2588 for (cnt = 0; cnt < 30000; cnt++) {
2589 if ((RD_REG_WORD(®->hccr) &
2590 HCCR_RISC_PAUSE) != 0)
2595 RD_REG_WORD(®->hccr); /* PCI Posting. */
2599 /* Select FPM registers. */
2600 WRT_REG_WORD(®->ctrl_status, 0x20);
2601 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2603 /* FPM Soft Reset. */
2604 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2605 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2607 /* Toggle Fpm Reset. */
2608 if (!IS_QLA2200(ha)) {
2609 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2610 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2613 /* Select frame buffer registers. */
2614 WRT_REG_WORD(®->ctrl_status, 0x10);
2615 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2617 /* Reset frame buffer FIFOs. */
2618 if (IS_QLA2200(ha)) {
2619 WRT_FB_CMD_REG(ha, reg, 0xa000);
2620 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2622 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2624 /* Read back fb_cmd until zero or 3 seconds max */
2625 for (cnt = 0; cnt < 3000; cnt++) {
2626 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2632 /* Select RISC module registers. */
2633 WRT_REG_WORD(®->ctrl_status, 0);
2634 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2636 /* Reset RISC processor. */
2637 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2638 RD_REG_WORD(®->hccr); /* PCI Posting. */
2640 /* Release RISC processor. */
2641 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2642 RD_REG_WORD(®->hccr); /* PCI Posting. */
2645 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2646 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2648 /* Reset ISP chip. */
2649 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2651 /* Wait for RISC to recover from reset. */
2652 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2654 * It is necessary to for a delay here since the card doesn't
2655 * respond to PCI reads during a reset. On some architectures
2656 * this will result in an MCA.
2659 for (cnt = 30000; cnt; cnt--) {
2660 if ((RD_REG_WORD(®->ctrl_status) &
2661 CSR_ISP_SOFT_RESET) == 0)
2668 /* Reset RISC processor. */
2669 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2671 WRT_REG_WORD(®->semaphore, 0);
2673 /* Release RISC processor. */
2674 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2675 RD_REG_WORD(®->hccr); /* PCI Posting. */
2677 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2678 for (cnt = 0; cnt < 30000; cnt++) {
2679 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2687 /* Turn on master enable */
2688 cmd |= PCI_COMMAND_MASTER;
2689 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2691 /* Disable RISC pause on FPM parity error. */
2692 if (!IS_QLA2100(ha)) {
2693 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2694 RD_REG_WORD(®->hccr); /* PCI Posting. */
2697 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2703 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2706 * Returns 0 on success.
2709 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2711 uint16_t mb[4] = {0x1010, 0, 1, 0};
2713 if (!IS_QLA81XX(vha->hw))
2716 return qla81xx_write_mpi_register(vha, mb);
2720 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2723 * Returns 0 on success.
2726 qla24xx_reset_risc(scsi_qla_host_t *vha)
2728 unsigned long flags = 0;
2729 struct qla_hw_data *ha = vha->hw;
2730 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2733 static int abts_cnt; /* ISP abort retry counts */
2734 int rval = QLA_SUCCESS;
2736 spin_lock_irqsave(&ha->hardware_lock, flags);
2739 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2740 for (cnt = 0; cnt < 30000; cnt++) {
2741 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2747 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2748 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2750 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2751 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2752 RD_REG_DWORD(®->hccr),
2753 RD_REG_DWORD(®->ctrl_status),
2754 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2756 WRT_REG_DWORD(®->ctrl_status,
2757 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2758 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2762 /* Wait for firmware to complete NVRAM accesses. */
2763 RD_REG_WORD(®->mailbox0);
2764 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2765 rval == QLA_SUCCESS; cnt--) {
2770 rval = QLA_FUNCTION_TIMEOUT;
2773 if (rval == QLA_SUCCESS)
2774 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2776 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2777 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2778 RD_REG_DWORD(®->hccr),
2779 RD_REG_DWORD(®->mailbox0));
2781 /* Wait for soft-reset to complete. */
2782 RD_REG_DWORD(®->ctrl_status);
2783 for (cnt = 0; cnt < 60; cnt++) {
2785 if ((RD_REG_DWORD(®->ctrl_status) &
2786 CSRX_ISP_SOFT_RESET) == 0)
2791 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2792 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2794 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2795 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2796 RD_REG_DWORD(®->hccr),
2797 RD_REG_DWORD(®->ctrl_status));
2799 /* If required, do an MPI FW reset now */
2800 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2801 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2802 if (++abts_cnt < 5) {
2803 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2804 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2807 * We exhausted the ISP abort retries. We have to
2808 * set the board offline.
2811 vha->flags.online = 0;
2816 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2817 RD_REG_DWORD(®->hccr);
2819 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2820 RD_REG_DWORD(®->hccr);
2822 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2823 RD_REG_DWORD(®->hccr);
2825 RD_REG_WORD(®->mailbox0);
2826 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2827 rval == QLA_SUCCESS; cnt--) {
2832 rval = QLA_FUNCTION_TIMEOUT;
2834 if (rval == QLA_SUCCESS)
2835 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2837 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2838 "Host Risc 0x%x, mailbox0 0x%x\n",
2839 RD_REG_DWORD(®->hccr),
2840 RD_REG_WORD(®->mailbox0));
2842 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2844 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2845 "Driver in %s mode\n",
2846 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2848 if (IS_NOPOLLING_TYPE(ha))
2849 ha->isp_ops->enable_intrs(ha);
2855 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2857 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2859 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2860 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2865 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2867 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2869 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2870 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2874 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2877 uint delta_msec = 100;
2878 uint elapsed_msec = 0;
2882 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2883 vha->hw->pdev->subsystem_device != 0x0240)
2886 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2890 timeout_msec = TIMEOUT_SEMAPHORE;
2891 n = timeout_msec / delta_msec;
2893 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2894 qla25xx_read_risc_sema_reg(vha, &wd32);
2895 if (wd32 & RISC_SEMAPHORE)
2898 elapsed_msec += delta_msec;
2899 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2903 if (!(wd32 & RISC_SEMAPHORE))
2906 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2909 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2910 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2911 n = timeout_msec / delta_msec;
2913 qla25xx_read_risc_sema_reg(vha, &wd32);
2914 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2917 elapsed_msec += delta_msec;
2918 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2922 if (wd32 & RISC_SEMAPHORE_FORCE)
2923 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2928 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2935 * qla24xx_reset_chip() - Reset ISP24xx chip.
2938 * Returns 0 on success.
2941 qla24xx_reset_chip(scsi_qla_host_t *vha)
2943 struct qla_hw_data *ha = vha->hw;
2944 int rval = QLA_FUNCTION_FAILED;
2946 if (pci_channel_offline(ha->pdev) &&
2947 ha->flags.pci_channel_io_perm_failure) {
2951 ha->isp_ops->disable_intrs(ha);
2953 qla25xx_manipulate_risc_semaphore(vha);
2955 /* Perform RISC reset. */
2956 rval = qla24xx_reset_risc(vha);
2962 * qla2x00_chip_diag() - Test chip for proper operation.
2965 * Returns 0 on success.
2968 qla2x00_chip_diag(scsi_qla_host_t *vha)
2971 struct qla_hw_data *ha = vha->hw;
2972 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2973 unsigned long flags = 0;
2977 struct req_que *req = ha->req_q_map[0];
2979 /* Assume a failed state */
2980 rval = QLA_FUNCTION_FAILED;
2982 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2983 ®->flash_address);
2985 spin_lock_irqsave(&ha->hardware_lock, flags);
2987 /* Reset ISP chip. */
2988 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2991 * We need to have a delay here since the card will not respond while
2992 * in reset causing an MCA on some architectures.
2995 data = qla2x00_debounce_register(®->ctrl_status);
2996 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2998 data = RD_REG_WORD(®->ctrl_status);
3003 goto chip_diag_failed;
3005 ql_dbg(ql_dbg_init, vha, 0x007c,
3006 "Reset register cleared by chip reset.\n");
3008 /* Reset RISC processor. */
3009 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3010 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3012 /* Workaround for QLA2312 PCI parity error */
3013 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3014 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3015 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3017 data = RD_MAILBOX_REG(ha, reg, 0);
3024 goto chip_diag_failed;
3026 /* Check product ID of chip */
3027 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3029 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3030 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3031 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3032 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3033 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3034 mb[3] != PROD_ID_3) {
3035 ql_log(ql_log_warn, vha, 0x0062,
3036 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3037 mb[1], mb[2], mb[3]);
3039 goto chip_diag_failed;
3041 ha->product_id[0] = mb[1];
3042 ha->product_id[1] = mb[2];
3043 ha->product_id[2] = mb[3];
3044 ha->product_id[3] = mb[4];
3046 /* Adjust fw RISC transfer size */
3047 if (req->length > 1024)
3048 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3050 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3053 if (IS_QLA2200(ha) &&
3054 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3055 /* Limit firmware transfer size with a 2200A */
3056 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3058 ha->device_type |= DT_ISP2200A;
3059 ha->fw_transfer_size = 128;
3062 /* Wrap Incoming Mailboxes Test. */
3063 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3065 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3066 rval = qla2x00_mbx_reg_test(vha);
3068 ql_log(ql_log_warn, vha, 0x0080,
3069 "Failed mailbox send register test.\n");
3071 /* Flag a successful rval */
3073 spin_lock_irqsave(&ha->hardware_lock, flags);
3077 ql_log(ql_log_info, vha, 0x0081,
3078 "Chip diagnostics **** FAILED ****.\n");
3080 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3086 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3089 * Returns 0 on success.
3092 qla24xx_chip_diag(scsi_qla_host_t *vha)
3095 struct qla_hw_data *ha = vha->hw;
3096 struct req_que *req = ha->req_q_map[0];
3098 if (IS_P3P_TYPE(ha))
3101 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3103 rval = qla2x00_mbx_reg_test(vha);
3105 ql_log(ql_log_warn, vha, 0x0082,
3106 "Failed mailbox send register test.\n");
3108 /* Flag a successful rval */
3116 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3121 struct qla_hw_data *ha = vha->hw;
3124 ql_dbg(ql_dbg_init, vha, 0x00bd,
3125 "%s: Offload Mem is already allocated.\n",
3130 if (IS_FWI2_CAPABLE(ha)) {
3131 /* Allocate memory for Fibre Channel Event Buffer. */
3132 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3133 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3137 dma_free_coherent(&ha->pdev->dev,
3138 FCE_SIZE, ha->fce, ha->fce_dma);
3140 /* Allocate memory for Fibre Channel Event Buffer. */
3141 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3144 ql_log(ql_log_warn, vha, 0x00be,
3145 "Unable to allocate (%d KB) for FCE.\n",
3150 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3151 ha->fce_mb, &ha->fce_bufs);
3153 ql_log(ql_log_warn, vha, 0x00bf,
3154 "Unable to initialize FCE (%d).\n", rval);
3155 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3157 ha->flags.fce_enabled = 0;
3160 ql_dbg(ql_dbg_init, vha, 0x00c0,
3161 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3163 ha->flags.fce_enabled = 1;
3164 ha->fce_dma = tc_dma;
3169 dma_free_coherent(&ha->pdev->dev,
3170 EFT_SIZE, ha->eft, ha->eft_dma);
3172 /* Allocate memory for Extended Trace Buffer. */
3173 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3176 ql_log(ql_log_warn, vha, 0x00c1,
3177 "Unable to allocate (%d KB) for EFT.\n",
3182 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3184 ql_log(ql_log_warn, vha, 0x00c2,
3185 "Unable to initialize EFT (%d).\n", rval);
3186 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3190 ql_dbg(ql_dbg_init, vha, 0x00c3,
3191 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3193 ha->eft_dma = tc_dma;
3202 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3205 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3206 eft_size, fce_size, mq_size;
3207 struct qla_hw_data *ha = vha->hw;
3208 struct req_que *req = ha->req_q_map[0];
3209 struct rsp_que *rsp = ha->rsp_q_map[0];
3210 struct qla2xxx_fw_dump *fw_dump;
3214 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3215 req_q_size = rsp_q_size = 0;
3217 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3218 fixed_size = sizeof(struct qla2100_fw_dump);
3219 } else if (IS_QLA23XX(ha)) {
3220 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3221 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3223 } else if (IS_FWI2_CAPABLE(ha)) {
3224 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3225 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3226 else if (IS_QLA81XX(ha))
3227 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3228 else if (IS_QLA25XX(ha))
3229 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3231 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3233 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3236 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3238 mq_size = sizeof(struct qla2xxx_mq_chain);
3240 * Allocate maximum buffer size for all queues - Q0.
3241 * Resizing must be done at end-of-dump processing.
3243 mq_size += (ha->max_req_queues - 1) *
3244 (req->length * sizeof(request_t));
3245 mq_size += (ha->max_rsp_queues - 1) *
3246 (rsp->length * sizeof(response_t));
3248 if (ha->tgt.atio_ring)
3249 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3250 /* Allocate memory for Fibre Channel Event Buffer. */
3251 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3252 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3255 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3258 dma_free_coherent(&ha->pdev->dev,
3259 EFT_SIZE, ha->eft, ha->eft_dma);
3261 /* Allocate memory for Extended Trace Buffer. */
3262 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3265 ql_log(ql_log_warn, vha, 0x00c1,
3266 "Unable to allocate (%d KB) for EFT.\n",
3271 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3273 ql_log(ql_log_warn, vha, 0x00c2,
3274 "Unable to initialize EFT (%d).\n", rval);
3275 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3278 ql_dbg(ql_dbg_init, vha, 0x00c3,
3279 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3280 eft_size = EFT_SIZE;
3283 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3284 struct fwdt *fwdt = ha->fwdt;
3287 for (j = 0; j < 2; j++, fwdt++) {
3288 if (!fwdt->template) {
3289 ql_log(ql_log_warn, vha, 0x00ba,
3290 "-> fwdt%u no template\n", j);
3293 ql_dbg(ql_dbg_init, vha, 0x00fa,
3294 "-> fwdt%u calculating fwdump size...\n", j);
3295 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3296 vha, fwdt->template);
3297 ql_dbg(ql_dbg_init, vha, 0x00fa,
3298 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3299 j, fwdt->dump_size);
3300 dump_size += fwdt->dump_size;
3305 req_q_size = req->length * sizeof(request_t);
3306 rsp_q_size = rsp->length * sizeof(response_t);
3307 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3308 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3309 ha->chain_offset = dump_size;
3310 dump_size += mq_size + fce_size;
3312 if (ha->exchoffld_buf)
3313 dump_size += sizeof(struct qla2xxx_offld_chain) +
3315 if (ha->exlogin_buf)
3316 dump_size += sizeof(struct qla2xxx_offld_chain) +
3320 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3322 ql_dbg(ql_dbg_init, vha, 0x00c5,
3323 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3324 __func__, dump_size, ha->fw_dump_len,
3325 ha->fw_dump_alloc_len);
3327 fw_dump = vmalloc(dump_size);
3329 ql_log(ql_log_warn, vha, 0x00c4,
3330 "Unable to allocate (%d KB) for firmware dump.\n",
3333 mutex_lock(&ha->optrom_mutex);
3334 if (ha->fw_dumped) {
3335 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3337 ha->fw_dump = fw_dump;
3338 ha->fw_dump_alloc_len = dump_size;
3339 ql_dbg(ql_dbg_init, vha, 0x00c5,
3340 "Re-Allocated (%d KB) and save firmware dump.\n",
3345 ha->fw_dump = fw_dump;
3347 ha->fw_dump_len = ha->fw_dump_alloc_len =
3349 ql_dbg(ql_dbg_init, vha, 0x00c5,
3350 "Allocated (%d KB) for firmware dump.\n",
3353 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3354 mutex_unlock(&ha->optrom_mutex);
3358 ha->fw_dump->signature[0] = 'Q';
3359 ha->fw_dump->signature[1] = 'L';
3360 ha->fw_dump->signature[2] = 'G';
3361 ha->fw_dump->signature[3] = 'C';
3362 ha->fw_dump->version = htonl(1);
3364 ha->fw_dump->fixed_size = htonl(fixed_size);
3365 ha->fw_dump->mem_size = htonl(mem_size);
3366 ha->fw_dump->req_q_size = htonl(req_q_size);
3367 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3369 ha->fw_dump->eft_size = htonl(eft_size);
3370 ha->fw_dump->eft_addr_l =
3371 htonl(LSD(ha->eft_dma));
3372 ha->fw_dump->eft_addr_h =
3373 htonl(MSD(ha->eft_dma));
3375 ha->fw_dump->header_size =
3377 (struct qla2xxx_fw_dump, isp));
3379 mutex_unlock(&ha->optrom_mutex);
3385 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3387 #define MPS_MASK 0xe0
3392 if (!IS_QLA81XX(vha->hw))
3395 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3396 if (rval != QLA_SUCCESS) {
3397 ql_log(ql_log_warn, vha, 0x0105,
3398 "Unable to acquire semaphore.\n");
3402 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3403 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3404 if (rval != QLA_SUCCESS) {
3405 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3410 if (dc == (dw & MPS_MASK))
3415 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3416 if (rval != QLA_SUCCESS) {
3417 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3421 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3422 if (rval != QLA_SUCCESS) {
3423 ql_log(ql_log_warn, vha, 0x006d,
3424 "Unable to release semaphore.\n");
3432 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3434 /* Don't try to reallocate the array */
3435 if (req->outstanding_cmds)
3438 if (!IS_FWI2_CAPABLE(ha))
3439 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3441 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3442 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3444 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3447 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3451 if (!req->outstanding_cmds) {
3453 * Try to allocate a minimal size just so we can get through
3456 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3457 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3461 if (!req->outstanding_cmds) {
3462 ql_log(ql_log_fatal, NULL, 0x0126,
3463 "Failed to allocate memory for "
3464 "outstanding_cmds for req_que %p.\n", req);
3465 req->num_outstanding_cmds = 0;
3466 return QLA_FUNCTION_FAILED;
3473 #define PRINT_FIELD(_field, _flag, _str) { \
3474 if (a0->_field & _flag) {\
3480 len = snprintf(ptr, leftover, "%s", _str); \
3487 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3490 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3491 u8 str[STR_LEN], *ptr, p;
3494 memset(str, 0, STR_LEN);
3495 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3496 ql_dbg(ql_dbg_init, vha, 0x015a,
3497 "SFP MFG Name: %s\n", str);
3499 memset(str, 0, STR_LEN);
3500 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3501 ql_dbg(ql_dbg_init, vha, 0x015c,
3502 "SFP Part Name: %s\n", str);
3505 memset(str, 0, STR_LEN);
3509 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3510 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3511 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3512 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3513 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3514 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3515 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3516 ql_dbg(ql_dbg_init, vha, 0x0160,
3517 "SFP Media: %s\n", str);
3520 memset(str, 0, STR_LEN);
3524 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3525 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3526 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3527 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3528 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3529 ql_dbg(ql_dbg_init, vha, 0x0196,
3530 "SFP Link Length: %s\n", str);
3532 memset(str, 0, STR_LEN);
3536 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3537 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3538 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3539 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3540 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3541 ql_dbg(ql_dbg_init, vha, 0x016e,
3542 "SFP FC Link Tech: %s\n", str);
3545 ql_dbg(ql_dbg_init, vha, 0x016f,
3546 "SFP Distant: %d km\n", a0->length_km);
3547 if (a0->length_100m)
3548 ql_dbg(ql_dbg_init, vha, 0x0170,
3549 "SFP Distant: %d m\n", a0->length_100m*100);
3550 if (a0->length_50um_10m)
3551 ql_dbg(ql_dbg_init, vha, 0x0189,
3552 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3553 if (a0->length_62um_10m)
3554 ql_dbg(ql_dbg_init, vha, 0x018a,
3555 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3556 if (a0->length_om4_10m)
3557 ql_dbg(ql_dbg_init, vha, 0x0194,
3558 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3559 if (a0->length_om3_10m)
3560 ql_dbg(ql_dbg_init, vha, 0x0195,
3561 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3567 * QLA_SUCCESS: no action
3568 * QLA_INTERFACE_ERROR: SFP is not there.
3569 * QLA_FUNCTION_FAILED: detected New SFP
3572 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3574 int rc = QLA_SUCCESS;
3575 struct sff_8247_a0 *a;
3576 struct qla_hw_data *ha = vha->hw;
3578 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3581 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3585 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3586 qla2xxx_print_sfp_info(vha);
3588 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3590 ha->flags.detected_lr_sfp = 1;
3592 if (a->length_km > 5 || a->length_100m > 50)
3593 ha->long_range_distance = LR_DISTANCE_10K;
3595 ha->long_range_distance = LR_DISTANCE_5K;
3597 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3598 ql_dbg(ql_dbg_async, vha, 0x507b,
3599 "Detected Long Range SFP.\n");
3602 ha->flags.detected_lr_sfp = 0;
3603 if (ha->flags.using_lr_setting)
3604 ql_dbg(ql_dbg_async, vha, 0x5084,
3605 "Detected Short Range SFP.\n");
3608 if (!vha->flags.init_done)
3615 * qla2x00_setup_chip() - Load and start RISC firmware.
3618 * Returns 0 on success.
3621 qla2x00_setup_chip(scsi_qla_host_t *vha)
3624 uint32_t srisc_address = 0;
3625 struct qla_hw_data *ha = vha->hw;
3626 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3627 unsigned long flags;
3628 uint16_t fw_major_version;
3630 if (IS_P3P_TYPE(ha)) {
3631 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3632 if (rval == QLA_SUCCESS) {
3633 qla2x00_stop_firmware(vha);
3634 goto enable_82xx_npiv;
3639 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3640 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3641 spin_lock_irqsave(&ha->hardware_lock, flags);
3642 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3643 RD_REG_WORD(®->hccr);
3644 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3647 qla81xx_mpi_sync(vha);
3649 /* Load firmware sequences */
3650 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3651 if (rval == QLA_SUCCESS) {
3652 ql_dbg(ql_dbg_init, vha, 0x00c9,
3653 "Verifying Checksum of loaded RISC code.\n");
3655 rval = qla2x00_verify_checksum(vha, srisc_address);
3656 if (rval == QLA_SUCCESS) {
3657 /* Start firmware execution. */
3658 ql_dbg(ql_dbg_init, vha, 0x00ca,
3659 "Starting firmware.\n");
3662 ha->flags.exlogins_enabled = 1;
3664 if (qla_is_exch_offld_enabled(vha))
3665 ha->flags.exchoffld_enabled = 1;
3667 rval = qla2x00_execute_fw(vha, srisc_address);
3668 /* Retrieve firmware information. */
3669 if (rval == QLA_SUCCESS) {
3670 qla24xx_detect_sfp(vha);
3672 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3674 (ha->zio_mode == QLA_ZIO_MODE_6))
3675 qla27xx_set_zio_threshold(vha,
3676 ha->last_zio_threshold);
3678 rval = qla2x00_set_exlogins_buffer(vha);
3679 if (rval != QLA_SUCCESS)
3682 rval = qla2x00_set_exchoffld_buffer(vha);
3683 if (rval != QLA_SUCCESS)
3687 fw_major_version = ha->fw_major_version;
3688 if (IS_P3P_TYPE(ha))
3689 qla82xx_check_md_needed(vha);
3691 rval = qla2x00_get_fw_version(vha);
3692 if (rval != QLA_SUCCESS)
3694 ha->flags.npiv_supported = 0;
3695 if (IS_QLA2XXX_MIDTYPE(ha) &&
3696 (ha->fw_attributes & BIT_2)) {
3697 ha->flags.npiv_supported = 1;
3698 if ((!ha->max_npiv_vports) ||
3699 ((ha->max_npiv_vports + 1) %
3700 MIN_MULTI_ID_FABRIC))
3701 ha->max_npiv_vports =
3702 MIN_MULTI_ID_FABRIC - 1;
3704 qla2x00_get_resource_cnts(vha);
3707 * Allocate the array of outstanding commands
3708 * now that we know the firmware resources.
3710 rval = qla2x00_alloc_outstanding_cmds(ha,
3712 if (rval != QLA_SUCCESS)
3715 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3716 qla2x00_alloc_offload_mem(vha);
3718 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3719 qla2x00_alloc_fw_dump(vha);
3725 ql_log(ql_log_fatal, vha, 0x00cd,
3726 "ISP Firmware failed checksum.\n");
3732 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3733 /* Enable proper parity. */
3734 spin_lock_irqsave(&ha->hardware_lock, flags);
3737 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3739 /* SRAM, Instruction RAM and GP RAM parity */
3740 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3741 RD_REG_WORD(®->hccr);
3742 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3745 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3746 ha->flags.fac_supported = 1;
3747 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3750 rval = qla81xx_fac_get_sector_size(vha, &size);
3751 if (rval == QLA_SUCCESS) {
3752 ha->flags.fac_supported = 1;
3753 ha->fdt_block_size = size << 2;
3755 ql_log(ql_log_warn, vha, 0x00ce,
3756 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3757 ha->fw_major_version, ha->fw_minor_version,
3758 ha->fw_subminor_version);
3760 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3762 ha->flags.fac_supported = 0;
3769 ql_log(ql_log_fatal, vha, 0x00cf,
3770 "Setup chip ****FAILED****.\n");
3777 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3778 * @rsp: response queue
3780 * Beginning of request ring has initialization control block already built
3781 * by nvram config routine.
3783 * Returns 0 on success.
3786 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3791 rsp->ring_ptr = rsp->ring;
3792 rsp->ring_index = 0;
3793 rsp->status_srb = NULL;
3794 pkt = rsp->ring_ptr;
3795 for (cnt = 0; cnt < rsp->length; cnt++) {
3796 pkt->signature = RESPONSE_PROCESSED;
3802 * qla2x00_update_fw_options() - Read and process firmware options.
3805 * Returns 0 on success.
3808 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3810 uint16_t swing, emphasis, tx_sens, rx_sens;
3811 struct qla_hw_data *ha = vha->hw;
3813 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3814 qla2x00_get_fw_options(vha, ha->fw_options);
3816 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3819 /* Serial Link options. */
3820 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3821 "Serial link options.\n");
3822 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3823 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3825 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3826 if (ha->fw_seriallink_options[3] & BIT_2) {
3827 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3830 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3831 emphasis = (ha->fw_seriallink_options[2] &
3832 (BIT_4 | BIT_3)) >> 3;
3833 tx_sens = ha->fw_seriallink_options[0] &
3834 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3835 rx_sens = (ha->fw_seriallink_options[0] &
3836 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3837 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3838 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3841 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3842 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3843 ha->fw_options[10] |= BIT_5 |
3844 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3845 (tx_sens & (BIT_1 | BIT_0));
3848 swing = (ha->fw_seriallink_options[2] &
3849 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3850 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3851 tx_sens = ha->fw_seriallink_options[1] &
3852 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3853 rx_sens = (ha->fw_seriallink_options[1] &
3854 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3855 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3856 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3859 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3860 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3861 ha->fw_options[11] |= BIT_5 |
3862 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3863 (tx_sens & (BIT_1 | BIT_0));
3867 /* Return command IOCBs without waiting for an ABTS to complete. */
3868 ha->fw_options[3] |= BIT_13;
3871 if (ha->flags.enable_led_scheme)
3872 ha->fw_options[2] |= BIT_12;
3874 /* Detect ISP6312. */
3876 ha->fw_options[2] |= BIT_13;
3878 /* Set Retry FLOGI in case of P2P connection */
3879 if (ha->operating_mode == P2P) {
3880 ha->fw_options[2] |= BIT_3;
3881 ql_dbg(ql_dbg_disc, vha, 0x2100,
3882 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3883 __func__, ha->fw_options[2]);
3886 /* Update firmware options. */
3887 qla2x00_set_fw_options(vha, ha->fw_options);
3891 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3894 struct qla_hw_data *ha = vha->hw;
3896 if (IS_P3P_TYPE(ha))
3899 /* Hold status IOCBs until ABTS response received. */
3901 ha->fw_options[3] |= BIT_12;
3903 /* Set Retry FLOGI in case of P2P connection */
3904 if (ha->operating_mode == P2P) {
3905 ha->fw_options[2] |= BIT_3;
3906 ql_dbg(ql_dbg_disc, vha, 0x2101,
3907 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3908 __func__, ha->fw_options[2]);
3911 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3912 if (ql2xmvasynctoatio &&
3913 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3914 if (qla_tgt_mode_enabled(vha) ||
3915 qla_dual_mode_enabled(vha))
3916 ha->fw_options[2] |= BIT_11;
3918 ha->fw_options[2] &= ~BIT_11;
3921 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3924 * Tell FW to track each exchange to prevent
3925 * driver from using stale exchange.
3927 if (qla_tgt_mode_enabled(vha) ||
3928 qla_dual_mode_enabled(vha))
3929 ha->fw_options[2] |= BIT_4;
3931 ha->fw_options[2] &= ~BIT_4;
3933 /* Reserve 1/2 of emergency exchanges for ELS.*/
3934 if (qla2xuseresexchforels)
3935 ha->fw_options[2] |= BIT_8;
3937 ha->fw_options[2] &= ~BIT_8;
3940 ql_dbg(ql_dbg_init, vha, 0x00e8,
3941 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3942 __func__, ha->fw_options[1], ha->fw_options[2],
3943 ha->fw_options[3], vha->host->active_mode);
3945 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3946 qla2x00_set_fw_options(vha, ha->fw_options);
3948 /* Update Serial Link options. */
3949 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3952 rval = qla2x00_set_serdes_params(vha,
3953 le16_to_cpu(ha->fw_seriallink_options24[1]),
3954 le16_to_cpu(ha->fw_seriallink_options24[2]),
3955 le16_to_cpu(ha->fw_seriallink_options24[3]));
3956 if (rval != QLA_SUCCESS) {
3957 ql_log(ql_log_warn, vha, 0x0104,
3958 "Unable to update Serial Link options (%x).\n", rval);
3963 qla2x00_config_rings(struct scsi_qla_host *vha)
3965 struct qla_hw_data *ha = vha->hw;
3966 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3967 struct req_que *req = ha->req_q_map[0];
3968 struct rsp_que *rsp = ha->rsp_q_map[0];
3970 /* Setup ring parameters in initialization control block. */
3971 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3972 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3973 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3974 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3975 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3976 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3978 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3979 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3980 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3981 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3982 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3986 qla24xx_config_rings(struct scsi_qla_host *vha)
3988 struct qla_hw_data *ha = vha->hw;
3989 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3990 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3991 struct qla_msix_entry *msix;
3992 struct init_cb_24xx *icb;
3994 struct req_que *req = ha->req_q_map[0];
3995 struct rsp_que *rsp = ha->rsp_q_map[0];
3997 /* Setup ring parameters in initialization control block. */
3998 icb = (struct init_cb_24xx *)ha->init_cb;
3999 icb->request_q_outpointer = cpu_to_le16(0);
4000 icb->response_q_inpointer = cpu_to_le16(0);
4001 icb->request_q_length = cpu_to_le16(req->length);
4002 icb->response_q_length = cpu_to_le16(rsp->length);
4003 put_unaligned_le64(req->dma, &icb->request_q_address);
4004 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4006 /* Setup ATIO queue dma pointers for target mode */
4007 icb->atio_q_inpointer = cpu_to_le16(0);
4008 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4009 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4011 if (IS_SHADOW_REG_CAPABLE(ha))
4012 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4014 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4016 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4017 icb->rid = cpu_to_le16(rid);
4018 if (ha->flags.msix_enabled) {
4019 msix = &ha->msix_entries[1];
4020 ql_dbg(ql_dbg_init, vha, 0x0019,
4021 "Registering vector 0x%x for base que.\n",
4023 icb->msix = cpu_to_le16(msix->entry);
4025 /* Use alternate PCI bus number */
4027 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4028 /* Use alternate PCI devfn */
4030 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4032 /* Use Disable MSIX Handshake mode for capable adapters */
4033 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4034 (ha->flags.msix_enabled)) {
4035 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4036 ha->flags.disable_msix_handshake = 1;
4037 ql_dbg(ql_dbg_init, vha, 0x00fe,
4038 "MSIX Handshake Disable Mode turned on.\n");
4040 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4042 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4044 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
4045 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
4046 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
4047 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4049 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4050 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4051 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4052 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4055 qlt_24xx_config_rings(vha);
4057 /* If the user has configured the speed, set it here */
4058 if (ha->set_data_rate) {
4059 ql_dbg(ql_dbg_init, vha, 0x00fd,
4060 "Speed set by user : %s Gbps \n",
4061 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4062 icb->firmware_options_3 = (ha->set_data_rate << 13);
4066 RD_REG_DWORD(&ioreg->hccr);
4070 * qla2x00_init_rings() - Initializes firmware.
4073 * Beginning of request ring has initialization control block already built
4074 * by nvram config routine.
4076 * Returns 0 on success.
4079 qla2x00_init_rings(scsi_qla_host_t *vha)
4082 unsigned long flags = 0;
4084 struct qla_hw_data *ha = vha->hw;
4085 struct req_que *req;
4086 struct rsp_que *rsp;
4087 struct mid_init_cb_24xx *mid_init_cb =
4088 (struct mid_init_cb_24xx *) ha->init_cb;
4090 spin_lock_irqsave(&ha->hardware_lock, flags);
4092 /* Clear outstanding commands array. */
4093 for (que = 0; que < ha->max_req_queues; que++) {
4094 req = ha->req_q_map[que];
4095 if (!req || !test_bit(que, ha->req_qid_map))
4097 req->out_ptr = (void *)(req->ring + req->length);
4099 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4100 req->outstanding_cmds[cnt] = NULL;
4102 req->current_outstanding_cmd = 1;
4104 /* Initialize firmware. */
4105 req->ring_ptr = req->ring;
4106 req->ring_index = 0;
4107 req->cnt = req->length;
4110 for (que = 0; que < ha->max_rsp_queues; que++) {
4111 rsp = ha->rsp_q_map[que];
4112 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4114 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4116 /* Initialize response queue entries */
4118 qlafx00_init_response_q_entries(rsp);
4120 qla2x00_init_response_q_entries(rsp);
4123 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4124 ha->tgt.atio_ring_index = 0;
4125 /* Initialize ATIO queue entries */
4126 qlt_init_atio_q_entries(vha);
4128 ha->isp_ops->config_rings(vha);
4130 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4132 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4134 if (IS_QLAFX00(ha)) {
4135 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4139 /* Update any ISP specific firmware options before initialization. */
4140 ha->isp_ops->update_fw_options(vha);
4142 if (ha->flags.npiv_supported) {
4143 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4144 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4145 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4148 if (IS_FWI2_CAPABLE(ha)) {
4149 mid_init_cb->options = cpu_to_le16(BIT_1);
4150 mid_init_cb->init_cb.execution_throttle =
4151 cpu_to_le16(ha->cur_fw_xcb_count);
4152 ha->flags.dport_enabled =
4153 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4154 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4155 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4156 /* FA-WWPN Status */
4157 ha->flags.fawwpn_enabled =
4158 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4159 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4160 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4163 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4166 ql_log(ql_log_fatal, vha, 0x00d2,
4167 "Init Firmware **** FAILED ****.\n");
4169 ql_dbg(ql_dbg_init, vha, 0x00d3,
4170 "Init Firmware -- success.\n");
4172 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4179 * qla2x00_fw_ready() - Waits for firmware ready.
4182 * Returns 0 on success.
4185 qla2x00_fw_ready(scsi_qla_host_t *vha)
4188 unsigned long wtime, mtime, cs84xx_time;
4189 uint16_t min_wait; /* Minimum wait time if loop is down */
4190 uint16_t wait_time; /* Wait time if loop is coming ready */
4192 struct qla_hw_data *ha = vha->hw;
4194 if (IS_QLAFX00(vha->hw))
4195 return qlafx00_fw_ready(vha);
4199 /* Time to wait for loop down */
4200 if (IS_P3P_TYPE(ha))
4206 * Firmware should take at most one RATOV to login, plus 5 seconds for
4207 * our own processing.
4209 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4210 wait_time = min_wait;
4213 /* Min wait time if loop down */
4214 mtime = jiffies + (min_wait * HZ);
4216 /* wait time before firmware ready */
4217 wtime = jiffies + (wait_time * HZ);
4219 /* Wait for ISP to finish LIP */
4220 if (!vha->flags.init_done)
4221 ql_log(ql_log_info, vha, 0x801e,
4222 "Waiting for LIP to complete.\n");
4225 memset(state, -1, sizeof(state));
4226 rval = qla2x00_get_firmware_state(vha, state);
4227 if (rval == QLA_SUCCESS) {
4228 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4229 vha->device_flags &= ~DFLG_NO_CABLE;
4231 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4232 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4233 "fw_state=%x 84xx=%x.\n", state[0],
4235 if ((state[2] & FSTATE_LOGGED_IN) &&
4236 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4237 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4238 "Sending verify iocb.\n");
4240 cs84xx_time = jiffies;
4241 rval = qla84xx_init_chip(vha);
4242 if (rval != QLA_SUCCESS) {
4245 "Init chip failed.\n");
4249 /* Add time taken to initialize. */
4250 cs84xx_time = jiffies - cs84xx_time;
4251 wtime += cs84xx_time;
4252 mtime += cs84xx_time;
4253 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4254 "Increasing wait time by %ld. "
4255 "New time %ld.\n", cs84xx_time,
4258 } else if (state[0] == FSTATE_READY) {
4259 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4260 "F/W Ready - OK.\n");
4262 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4263 &ha->login_timeout, &ha->r_a_tov);
4269 rval = QLA_FUNCTION_FAILED;
4271 if (atomic_read(&vha->loop_down_timer) &&
4272 state[0] != FSTATE_READY) {
4273 /* Loop down. Timeout on min_wait for states
4274 * other than Wait for Login.
4276 if (time_after_eq(jiffies, mtime)) {
4277 ql_log(ql_log_info, vha, 0x8038,
4278 "Cable is unplugged...\n");
4280 vha->device_flags |= DFLG_NO_CABLE;
4285 /* Mailbox cmd failed. Timeout on min_wait. */
4286 if (time_after_eq(jiffies, mtime) ||
4287 ha->flags.isp82xx_fw_hung)
4291 if (time_after_eq(jiffies, wtime))
4294 /* Delay for a while */
4298 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4299 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4300 state[1], state[2], state[3], state[4], state[5], jiffies);
4302 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4303 ql_log(ql_log_warn, vha, 0x803b,
4304 "Firmware ready **** FAILED ****.\n");
4311 * qla2x00_configure_hba
4312 * Setup adapter context.
4315 * ha = adapter state pointer.
4324 qla2x00_configure_hba(scsi_qla_host_t *vha)
4333 char connect_type[22];
4334 struct qla_hw_data *ha = vha->hw;
4335 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4337 unsigned long flags;
4339 /* Get host addresses. */
4340 rval = qla2x00_get_adapter_id(vha,
4341 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4342 if (rval != QLA_SUCCESS) {
4343 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4344 IS_CNA_CAPABLE(ha) ||
4345 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4346 ql_dbg(ql_dbg_disc, vha, 0x2008,
4347 "Loop is in a transition state.\n");
4349 ql_log(ql_log_warn, vha, 0x2009,
4350 "Unable to get host loop ID.\n");
4351 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4352 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4353 ql_log(ql_log_warn, vha, 0x1151,
4354 "Doing link init.\n");
4355 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4358 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4364 ql_log(ql_log_info, vha, 0x200a,
4365 "Cannot get topology - retrying.\n");
4366 return (QLA_FUNCTION_FAILED);
4369 vha->loop_id = loop_id;
4372 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4373 ha->operating_mode = LOOP;
4378 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4379 ha->current_topology = ISP_CFG_NL;
4380 strcpy(connect_type, "(Loop)");
4384 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4385 ha->switch_cap = sw_cap;
4386 ha->current_topology = ISP_CFG_FL;
4387 strcpy(connect_type, "(FL_Port)");
4391 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4392 ha->operating_mode = P2P;
4393 ha->current_topology = ISP_CFG_N;
4394 strcpy(connect_type, "(N_Port-to-N_Port)");
4398 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4399 ha->switch_cap = sw_cap;
4400 ha->operating_mode = P2P;
4401 ha->current_topology = ISP_CFG_F;
4402 strcpy(connect_type, "(F_Port)");
4406 ql_dbg(ql_dbg_disc, vha, 0x200f,
4407 "HBA in unknown topology %x, using NL.\n", topo);
4408 ha->current_topology = ISP_CFG_NL;
4409 strcpy(connect_type, "(Loop)");
4413 /* Save Host port and loop ID. */
4414 /* byte order - Big Endian */
4415 id.b.domain = domain;
4419 spin_lock_irqsave(&ha->hardware_lock, flags);
4420 if (!(topo == 2 && ha->flags.n2n_bigger))
4421 qlt_update_host_map(vha, id);
4422 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4424 if (!vha->flags.init_done)
4425 ql_log(ql_log_info, vha, 0x2010,
4426 "Topology - %s, Host Loop address 0x%x.\n",
4427 connect_type, vha->loop_id);
4433 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4438 uint64_t zero[2] = { 0 };
4439 struct qla_hw_data *ha = vha->hw;
4440 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4441 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4443 if (len > sizeof(zero))
4445 if (memcmp(model, &zero, len) != 0) {
4446 strncpy(ha->model_number, model, len);
4447 st = en = ha->model_number;
4450 if (*en != 0x20 && *en != 0x00)
4455 index = (ha->pdev->subsystem_device & 0xff);
4457 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4458 index < QLA_MODEL_NAMES)
4459 strncpy(ha->model_desc,
4460 qla2x00_model_name[index * 2 + 1],
4461 sizeof(ha->model_desc) - 1);
4463 index = (ha->pdev->subsystem_device & 0xff);
4465 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4466 index < QLA_MODEL_NAMES) {
4467 strcpy(ha->model_number,
4468 qla2x00_model_name[index * 2]);
4469 strncpy(ha->model_desc,
4470 qla2x00_model_name[index * 2 + 1],
4471 sizeof(ha->model_desc) - 1);
4473 strcpy(ha->model_number, def);
4476 if (IS_FWI2_CAPABLE(ha))
4477 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4478 sizeof(ha->model_desc));
4481 /* On sparc systems, obtain port and node WWN from firmware
4484 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4487 struct qla_hw_data *ha = vha->hw;
4488 struct pci_dev *pdev = ha->pdev;
4489 struct device_node *dp = pci_device_to_OF_node(pdev);
4493 val = of_get_property(dp, "port-wwn", &len);
4494 if (val && len >= WWN_SIZE)
4495 memcpy(nv->port_name, val, WWN_SIZE);
4497 val = of_get_property(dp, "node-wwn", &len);
4498 if (val && len >= WWN_SIZE)
4499 memcpy(nv->node_name, val, WWN_SIZE);
4504 * NVRAM configuration for ISP 2xxx
4507 * ha = adapter block pointer.
4510 * initialization control block in response_ring
4511 * host adapters parameters in host adapter block
4517 qla2x00_nvram_config(scsi_qla_host_t *vha)
4522 uint8_t *dptr1, *dptr2;
4523 struct qla_hw_data *ha = vha->hw;
4524 init_cb_t *icb = ha->init_cb;
4525 nvram_t *nv = ha->nvram;
4526 uint8_t *ptr = ha->nvram;
4527 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4531 /* Determine NVRAM starting address. */
4532 ha->nvram_size = sizeof(*nv);
4534 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4535 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4536 ha->nvram_base = 0x80;
4538 /* Get NVRAM data and calculate checksum. */
4539 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4540 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4543 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4544 "Contents of NVRAM.\n");
4545 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4546 nv, ha->nvram_size);
4548 /* Bad NVRAM data, set defaults parameters. */
4549 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4550 nv->nvram_version < 1) {
4551 /* Reset NVRAM data. */
4552 ql_log(ql_log_warn, vha, 0x0064,
4553 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4554 chksum, nv->id, nv->nvram_version);
4555 ql_log(ql_log_warn, vha, 0x0065,
4557 "functioning (yet invalid -- WWPN) defaults.\n");
4560 * Set default initialization control block.
4562 memset(nv, 0, ha->nvram_size);
4563 nv->parameter_block_version = ICB_VERSION;
4565 if (IS_QLA23XX(ha)) {
4566 nv->firmware_options[0] = BIT_2 | BIT_1;
4567 nv->firmware_options[1] = BIT_7 | BIT_5;
4568 nv->add_firmware_options[0] = BIT_5;
4569 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4570 nv->frame_payload_size = 2048;
4571 nv->special_options[1] = BIT_7;
4572 } else if (IS_QLA2200(ha)) {
4573 nv->firmware_options[0] = BIT_2 | BIT_1;
4574 nv->firmware_options[1] = BIT_7 | BIT_5;
4575 nv->add_firmware_options[0] = BIT_5;
4576 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4577 nv->frame_payload_size = 1024;
4578 } else if (IS_QLA2100(ha)) {
4579 nv->firmware_options[0] = BIT_3 | BIT_1;
4580 nv->firmware_options[1] = BIT_5;
4581 nv->frame_payload_size = 1024;
4584 nv->max_iocb_allocation = cpu_to_le16(256);
4585 nv->execution_throttle = cpu_to_le16(16);
4586 nv->retry_count = 8;
4587 nv->retry_delay = 1;
4589 nv->port_name[0] = 33;
4590 nv->port_name[3] = 224;
4591 nv->port_name[4] = 139;
4593 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4595 nv->login_timeout = 4;
4598 * Set default host adapter parameters
4600 nv->host_p[1] = BIT_2;
4601 nv->reset_delay = 5;
4602 nv->port_down_retry_count = 8;
4603 nv->max_luns_per_target = cpu_to_le16(8);
4604 nv->link_down_timeout = 60;
4609 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4611 * The SN2 does not provide BIOS emulation which means you can't change
4612 * potentially bogus BIOS settings. Force the use of default settings
4613 * for link rate and frame size. Hope that the rest of the settings
4616 if (ia64_platform_is("sn2")) {
4617 nv->frame_payload_size = 2048;
4619 nv->special_options[1] = BIT_7;
4623 /* Reset Initialization control block */
4624 memset(icb, 0, ha->init_cb_size);
4627 * Setup driver NVRAM options.
4629 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4630 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4631 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4632 nv->firmware_options[1] &= ~BIT_4;
4634 if (IS_QLA23XX(ha)) {
4635 nv->firmware_options[0] |= BIT_2;
4636 nv->firmware_options[0] &= ~BIT_3;
4637 nv->special_options[0] &= ~BIT_6;
4638 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4640 if (IS_QLA2300(ha)) {
4641 if (ha->fb_rev == FPM_2310) {
4642 strcpy(ha->model_number, "QLA2310");
4644 strcpy(ha->model_number, "QLA2300");
4647 qla2x00_set_model_info(vha, nv->model_number,
4648 sizeof(nv->model_number), "QLA23xx");
4650 } else if (IS_QLA2200(ha)) {
4651 nv->firmware_options[0] |= BIT_2;
4653 * 'Point-to-point preferred, else loop' is not a safe
4654 * connection mode setting.
4656 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4658 /* Force 'loop preferred, else point-to-point'. */
4659 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4660 nv->add_firmware_options[0] |= BIT_5;
4662 strcpy(ha->model_number, "QLA22xx");
4663 } else /*if (IS_QLA2100(ha))*/ {
4664 strcpy(ha->model_number, "QLA2100");
4668 * Copy over NVRAM RISC parameter block to initialization control block.
4670 dptr1 = (uint8_t *)icb;
4671 dptr2 = (uint8_t *)&nv->parameter_block_version;
4672 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4674 *dptr1++ = *dptr2++;
4676 /* Copy 2nd half. */
4677 dptr1 = (uint8_t *)icb->add_firmware_options;
4678 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4680 *dptr1++ = *dptr2++;
4681 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4682 /* Use alternate WWN? */
4683 if (nv->host_p[1] & BIT_7) {
4684 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4685 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4688 /* Prepare nodename */
4689 if ((icb->firmware_options[1] & BIT_6) == 0) {
4691 * Firmware will apply the following mask if the nodename was
4694 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4695 icb->node_name[0] &= 0xF0;
4699 * Set host adapter parameters.
4703 * BIT_7 in the host-parameters section allows for modification to
4704 * internal driver logging.
4706 if (nv->host_p[0] & BIT_7)
4707 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4708 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4709 /* Always load RISC code on non ISP2[12]00 chips. */
4710 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4711 ha->flags.disable_risc_code_load = 0;
4712 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4713 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4714 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4715 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4716 ha->flags.disable_serdes = 0;
4718 ha->operating_mode =
4719 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4721 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4722 sizeof(ha->fw_seriallink_options));
4724 /* save HBA serial number */
4725 ha->serial0 = icb->port_name[5];
4726 ha->serial1 = icb->port_name[6];
4727 ha->serial2 = icb->port_name[7];
4728 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4729 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4731 icb->execution_throttle = cpu_to_le16(0xFFFF);
4733 ha->retry_count = nv->retry_count;
4735 /* Set minimum login_timeout to 4 seconds. */
4736 if (nv->login_timeout != ql2xlogintimeout)
4737 nv->login_timeout = ql2xlogintimeout;
4738 if (nv->login_timeout < 4)
4739 nv->login_timeout = 4;
4740 ha->login_timeout = nv->login_timeout;
4742 /* Set minimum RATOV to 100 tenths of a second. */
4745 ha->loop_reset_delay = nv->reset_delay;
4747 /* Link Down Timeout = 0:
4749 * When Port Down timer expires we will start returning
4750 * I/O's to OS with "DID_NO_CONNECT".
4752 * Link Down Timeout != 0:
4754 * The driver waits for the link to come up after link down
4755 * before returning I/Os to OS with "DID_NO_CONNECT".
4757 if (nv->link_down_timeout == 0) {
4758 ha->loop_down_abort_time =
4759 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4761 ha->link_down_timeout = nv->link_down_timeout;
4762 ha->loop_down_abort_time =
4763 (LOOP_DOWN_TIME - ha->link_down_timeout);
4767 * Need enough time to try and get the port back.
4769 ha->port_down_retry_count = nv->port_down_retry_count;
4770 if (qlport_down_retry)
4771 ha->port_down_retry_count = qlport_down_retry;
4772 /* Set login_retry_count */
4773 ha->login_retry_count = nv->retry_count;
4774 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4775 ha->port_down_retry_count > 3)
4776 ha->login_retry_count = ha->port_down_retry_count;
4777 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4778 ha->login_retry_count = ha->port_down_retry_count;
4779 if (ql2xloginretrycount)
4780 ha->login_retry_count = ql2xloginretrycount;
4782 icb->lun_enables = cpu_to_le16(0);
4783 icb->command_resource_count = 0;
4784 icb->immediate_notify_resource_count = 0;
4785 icb->timeout = cpu_to_le16(0);
4787 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4789 icb->firmware_options[0] &= ~BIT_3;
4790 icb->add_firmware_options[0] &=
4791 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4792 icb->add_firmware_options[0] |= BIT_2;
4793 icb->response_accumulation_timer = 3;
4794 icb->interrupt_delay_timer = 5;
4796 vha->flags.process_response_queue = 1;
4799 if (!vha->flags.init_done) {
4800 ha->zio_mode = icb->add_firmware_options[0] &
4801 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4802 ha->zio_timer = icb->interrupt_delay_timer ?
4803 icb->interrupt_delay_timer : 2;
4805 icb->add_firmware_options[0] &=
4806 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4807 vha->flags.process_response_queue = 0;
4808 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4809 ha->zio_mode = QLA_ZIO_MODE_6;
4811 ql_log(ql_log_info, vha, 0x0068,
4812 "ZIO mode %d enabled; timer delay (%d us).\n",
4813 ha->zio_mode, ha->zio_timer * 100);
4815 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4816 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4817 vha->flags.process_response_queue = 1;
4822 ql_log(ql_log_warn, vha, 0x0069,
4823 "NVRAM configuration failed.\n");
4829 qla2x00_rport_del(void *data)
4831 fc_port_t *fcport = data;
4832 struct fc_rport *rport;
4833 unsigned long flags;
4835 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4836 rport = fcport->drport ? fcport->drport : fcport->rport;
4837 fcport->drport = NULL;
4838 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4840 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4841 "%s %8phN. rport %p roles %x\n",
4842 __func__, fcport->port_name, rport,
4845 fc_remote_port_delete(rport);
4849 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4853 old_state = atomic_read(&fcport->state);
4854 atomic_set(&fcport->state, state);
4856 /* Don't print state transitions during initial allocation of fcport */
4857 if (old_state && old_state != state) {
4858 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4859 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4860 fcport->port_name, port_state_str[old_state],
4861 port_state_str[state], fcport->d_id.b.domain,
4862 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4867 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4869 * @flags: allocation flags
4871 * Returns a pointer to the allocated fcport, or NULL, if none available.
4874 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4878 fcport = kzalloc(sizeof(fc_port_t), flags);
4882 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4883 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4885 if (!fcport->ct_desc.ct_sns) {
4886 ql_log(ql_log_warn, vha, 0xd049,
4887 "Failed to allocate ct_sns request.\n");
4892 /* Setup fcport template structure. */
4894 fcport->port_type = FCT_UNKNOWN;
4895 fcport->loop_id = FC_NO_LOOP_ID;
4896 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4897 fcport->supported_classes = FC_COS_UNSPECIFIED;
4898 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4900 fcport->disc_state = DSC_DELETED;
4901 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4902 fcport->deleted = QLA_SESS_DELETED;
4903 fcport->login_retry = vha->hw->login_retry_count;
4904 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4905 fcport->logout_on_delete = 1;
4907 if (!fcport->ct_desc.ct_sns) {
4908 ql_log(ql_log_warn, vha, 0xd049,
4909 "Failed to allocate ct_sns request.\n");
4914 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4915 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4916 INIT_LIST_HEAD(&fcport->gnl_entry);
4917 INIT_LIST_HEAD(&fcport->list);
4923 qla2x00_free_fcport(fc_port_t *fcport)
4925 if (fcport->ct_desc.ct_sns) {
4926 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4927 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4928 fcport->ct_desc.ct_sns_dma);
4930 fcport->ct_desc.ct_sns = NULL;
4932 list_del(&fcport->list);
4933 qla2x00_clear_loop_id(fcport);
4938 * qla2x00_configure_loop
4939 * Updates Fibre Channel Device Database with what is actually on loop.
4942 * ha = adapter block pointer.
4947 * 2 = database was full and device was not configured.
4950 qla2x00_configure_loop(scsi_qla_host_t *vha)
4953 unsigned long flags, save_flags;
4954 struct qla_hw_data *ha = vha->hw;
4958 /* Get Initiator ID */
4959 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4960 rval = qla2x00_configure_hba(vha);
4961 if (rval != QLA_SUCCESS) {
4962 ql_dbg(ql_dbg_disc, vha, 0x2013,
4963 "Unable to configure HBA.\n");
4968 save_flags = flags = vha->dpc_flags;
4969 ql_dbg(ql_dbg_disc, vha, 0x2014,
4970 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4973 * If we have both an RSCN and PORT UPDATE pending then handle them
4974 * both at the same time.
4976 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4977 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4979 qla2x00_get_data_rate(vha);
4981 /* Determine what we need to do */
4982 if (ha->current_topology == ISP_CFG_FL &&
4983 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4985 set_bit(RSCN_UPDATE, &flags);
4987 } else if (ha->current_topology == ISP_CFG_F &&
4988 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4990 set_bit(RSCN_UPDATE, &flags);
4991 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4993 } else if (ha->current_topology == ISP_CFG_N) {
4994 clear_bit(RSCN_UPDATE, &flags);
4995 if (qla_tgt_mode_enabled(vha)) {
4996 /* allow the other side to start the login */
4997 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4998 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5000 } else if (ha->current_topology == ISP_CFG_NL) {
5001 clear_bit(RSCN_UPDATE, &flags);
5002 set_bit(LOCAL_LOOP_UPDATE, &flags);
5003 } else if (!vha->flags.online ||
5004 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5005 set_bit(RSCN_UPDATE, &flags);
5006 set_bit(LOCAL_LOOP_UPDATE, &flags);
5009 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5010 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5011 ql_dbg(ql_dbg_disc, vha, 0x2015,
5012 "Loop resync needed, failing.\n");
5013 rval = QLA_FUNCTION_FAILED;
5015 rval = qla2x00_configure_local_loop(vha);
5018 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5019 if (LOOP_TRANSITION(vha)) {
5020 ql_dbg(ql_dbg_disc, vha, 0x2099,
5021 "Needs RSCN update and loop transition.\n");
5022 rval = QLA_FUNCTION_FAILED;
5025 rval = qla2x00_configure_fabric(vha);
5028 if (rval == QLA_SUCCESS) {
5029 if (atomic_read(&vha->loop_down_timer) ||
5030 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5031 rval = QLA_FUNCTION_FAILED;
5033 atomic_set(&vha->loop_state, LOOP_READY);
5034 ql_dbg(ql_dbg_disc, vha, 0x2069,
5036 ha->flags.fw_init_done = 1;
5039 * Process any ATIO queue entries that came in
5040 * while we weren't online.
5042 if (qla_tgt_mode_enabled(vha) ||
5043 qla_dual_mode_enabled(vha)) {
5044 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5045 qlt_24xx_process_atio_queue(vha, 0);
5046 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5053 ql_dbg(ql_dbg_disc, vha, 0x206a,
5054 "%s *** FAILED ***.\n", __func__);
5056 ql_dbg(ql_dbg_disc, vha, 0x206b,
5057 "%s: exiting normally.\n", __func__);
5060 /* Restore state if a resync event occurred during processing */
5061 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5062 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5063 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5064 if (test_bit(RSCN_UPDATE, &save_flags)) {
5065 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5073 * qla2x00_configure_local_loop
5074 * Updates Fibre Channel Device Database with local loop devices.
5077 * ha = adapter block pointer.
5083 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5088 fc_port_t *fcport, *new_fcport;
5094 uint8_t domain, area, al_pa;
5095 struct qla_hw_data *ha = vha->hw;
5096 unsigned long flags;
5098 /* Inititae N2N login. */
5099 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5103 memset(ha->init_cb, 0, ha->init_cb_size);
5104 sz = min_t(int, sizeof(struct els_plogi_payload),
5106 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5107 (void *)ha->init_cb, sz);
5108 if (rval == QLA_SUCCESS) {
5109 bp = (uint32_t *)ha->init_cb;
5110 for (i = 0; i < sz/4 ; i++, bp++)
5111 *bp = cpu_to_be32(*bp);
5113 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
5114 sizeof(ha->plogi_els_payld.data));
5115 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5117 ql_dbg(ql_dbg_init, vha, 0x00d1,
5118 "PLOGI ELS param read fail.\n");
5125 entries = MAX_FIBRE_DEVICES_LOOP;
5127 /* Get list of logged in devices. */
5128 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5129 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5131 if (rval != QLA_SUCCESS)
5132 goto cleanup_allocation;
5134 ql_dbg(ql_dbg_disc, vha, 0x2011,
5135 "Entries in ID list (%d).\n", entries);
5136 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5137 ha->gid_list, entries * sizeof(*ha->gid_list));
5140 spin_lock_irqsave(&vha->work_lock, flags);
5141 vha->scan.scan_retry++;
5142 spin_unlock_irqrestore(&vha->work_lock, flags);
5144 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5145 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5146 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5149 vha->scan.scan_retry = 0;
5152 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5153 fcport->scan_state = QLA_FCPORT_SCAN;
5156 /* Allocate temporary fcport for any new fcports discovered. */
5157 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5158 if (new_fcport == NULL) {
5159 ql_log(ql_log_warn, vha, 0x2012,
5160 "Memory allocation failed for fcport.\n");
5161 rval = QLA_MEMORY_ALLOC_FAILED;
5162 goto cleanup_allocation;
5164 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5166 /* Add devices to port list. */
5167 id_iter = (char *)ha->gid_list;
5168 for (index = 0; index < entries; index++) {
5169 domain = ((struct gid_list_info *)id_iter)->domain;
5170 area = ((struct gid_list_info *)id_iter)->area;
5171 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
5172 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5173 loop_id = (uint16_t)
5174 ((struct gid_list_info *)id_iter)->loop_id_2100;
5176 loop_id = le16_to_cpu(
5177 ((struct gid_list_info *)id_iter)->loop_id);
5178 id_iter += ha->gid_list_info_size;
5180 /* Bypass reserved domain fields. */
5181 if ((domain & 0xf0) == 0xf0)
5184 /* Bypass if not same domain and area of adapter. */
5185 if (area && domain && ((area != vha->d_id.b.area) ||
5186 (domain != vha->d_id.b.domain)) &&
5187 (ha->current_topology == ISP_CFG_NL))
5191 /* Bypass invalid local loop ID. */
5192 if (loop_id > LAST_LOCAL_LOOP_ID)
5195 memset(new_fcport->port_name, 0, WWN_SIZE);
5197 /* Fill in member data. */
5198 new_fcport->d_id.b.domain = domain;
5199 new_fcport->d_id.b.area = area;
5200 new_fcport->d_id.b.al_pa = al_pa;
5201 new_fcport->loop_id = loop_id;
5202 new_fcport->scan_state = QLA_FCPORT_FOUND;
5204 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5205 if (rval2 != QLA_SUCCESS) {
5206 ql_dbg(ql_dbg_disc, vha, 0x2097,
5207 "Failed to retrieve fcport information "
5208 "-- get_port_database=%x, loop_id=0x%04x.\n",
5209 rval2, new_fcport->loop_id);
5210 /* Skip retry if N2N */
5211 if (ha->current_topology != ISP_CFG_N) {
5212 ql_dbg(ql_dbg_disc, vha, 0x2105,
5213 "Scheduling resync.\n");
5214 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5219 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5220 /* Check for matching device in port list. */
5223 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5224 if (memcmp(new_fcport->port_name, fcport->port_name,
5228 fcport->flags &= ~FCF_FABRIC_DEVICE;
5229 fcport->loop_id = new_fcport->loop_id;
5230 fcport->port_type = new_fcport->port_type;
5231 fcport->d_id.b24 = new_fcport->d_id.b24;
5232 memcpy(fcport->node_name, new_fcport->node_name,
5234 fcport->scan_state = QLA_FCPORT_FOUND;
5240 /* New device, add to fcports list. */
5241 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5243 /* Allocate a new replacement fcport. */
5244 fcport = new_fcport;
5246 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5248 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5250 if (new_fcport == NULL) {
5251 ql_log(ql_log_warn, vha, 0xd031,
5252 "Failed to allocate memory for fcport.\n");
5253 rval = QLA_MEMORY_ALLOC_FAILED;
5254 goto cleanup_allocation;
5256 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5257 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5260 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5262 /* Base iIDMA settings on HBA port speed. */
5263 fcport->fp_speed = ha->link_data_rate;
5268 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5269 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5272 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5273 if ((qla_dual_mode_enabled(vha) ||
5274 qla_ini_mode_enabled(vha)) &&
5275 atomic_read(&fcport->state) == FCS_ONLINE) {
5276 qla2x00_mark_device_lost(vha, fcport,
5277 ql2xplogiabsentdevice, 0);
5278 if (fcport->loop_id != FC_NO_LOOP_ID &&
5279 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5280 fcport->port_type != FCT_INITIATOR &&
5281 fcport->port_type != FCT_BROADCAST) {
5282 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5283 "%s %d %8phC post del sess\n",
5287 qlt_schedule_sess_for_deletion(fcport);
5293 if (fcport->scan_state == QLA_FCPORT_FOUND)
5294 qla24xx_fcport_handle_login(vha, fcport);
5300 if (rval != QLA_SUCCESS) {
5301 ql_dbg(ql_dbg_disc, vha, 0x2098,
5302 "Configure local loop error exit: rval=%x.\n", rval);
5309 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5312 uint16_t mb[MAILBOX_REGISTER_COUNT];
5313 struct qla_hw_data *ha = vha->hw;
5315 if (!IS_IIDMA_CAPABLE(ha))
5318 if (atomic_read(&fcport->state) != FCS_ONLINE)
5321 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5322 fcport->fp_speed > ha->link_data_rate ||
5323 !ha->flags.gpsc_supported)
5326 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5328 if (rval != QLA_SUCCESS) {
5329 ql_dbg(ql_dbg_disc, vha, 0x2004,
5330 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5331 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5333 ql_dbg(ql_dbg_disc, vha, 0x2005,
5334 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5335 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5336 fcport->fp_speed, fcport->port_name);
5340 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5342 qla2x00_iidma_fcport(vha, fcport);
5343 qla24xx_update_fcport_fcp_prio(vha, fcport);
5346 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5348 struct qla_work_evt *e;
5350 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5352 return QLA_FUNCTION_FAILED;
5354 e->u.fcport.fcport = fcport;
5355 return qla2x00_post_work(vha, e);
5358 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5360 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5362 struct fc_rport_identifiers rport_ids;
5363 struct fc_rport *rport;
5364 unsigned long flags;
5366 if (atomic_read(&fcport->state) == FCS_ONLINE)
5369 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5370 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5371 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5372 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5373 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5374 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5376 ql_log(ql_log_warn, vha, 0x2006,
5377 "Unable to allocate fc remote port.\n");
5381 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5382 *((fc_port_t **)rport->dd_data) = fcport;
5383 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5385 rport->supported_classes = fcport->supported_classes;
5387 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5388 if (fcport->port_type == FCT_INITIATOR)
5389 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5390 if (fcport->port_type == FCT_TARGET)
5391 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5392 if (fcport->port_type & FCT_NVME_INITIATOR)
5393 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5394 if (fcport->port_type & FCT_NVME_TARGET)
5395 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5396 if (fcport->port_type & FCT_NVME_DISCOVERY)
5397 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5399 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5400 "%s %8phN. rport %p is %s mode\n",
5401 __func__, fcport->port_name, rport,
5402 (fcport->port_type == FCT_TARGET) ? "tgt" :
5403 ((fcport->port_type & FCT_NVME) ? "nvme" :"ini"));
5405 fc_remote_port_rolechg(rport, rport_ids.roles);
5409 * qla2x00_update_fcport
5410 * Updates device on list.
5413 * ha = adapter block pointer.
5414 * fcport = port structure pointer.
5424 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5426 if (IS_SW_RESV_ADDR(fcport->d_id))
5429 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5430 __func__, fcport->port_name);
5432 fcport->disc_state = DSC_UPD_FCPORT;
5433 fcport->login_retry = vha->hw->login_retry_count;
5434 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5435 fcport->deleted = 0;
5436 fcport->logout_on_delete = 1;
5437 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5439 switch (vha->hw->current_topology) {
5442 fcport->keep_nport_handle = 1;
5448 qla2x00_iidma_fcport(vha, fcport);
5450 if (fcport->fc4f_nvme) {
5451 qla_nvme_register_remote(vha, fcport);
5452 fcport->disc_state = DSC_LOGIN_COMPLETE;
5453 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5457 qla24xx_update_fcport_fcp_prio(vha, fcport);
5459 switch (vha->host->active_mode) {
5460 case MODE_INITIATOR:
5461 qla2x00_reg_remote_port(vha, fcport);
5464 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5465 !vha->vha_tgt.qla_tgt->tgt_stopped)
5466 qlt_fc_port_added(vha, fcport);
5469 qla2x00_reg_remote_port(vha, fcport);
5470 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5471 !vha->vha_tgt.qla_tgt->tgt_stopped)
5472 qlt_fc_port_added(vha, fcport);
5478 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5480 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5481 if (fcport->id_changed) {
5482 fcport->id_changed = 0;
5483 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5484 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5485 __func__, __LINE__, fcport->port_name,
5487 qla24xx_post_gfpnid_work(vha, fcport);
5489 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5490 "%s %d %8phC post gpsc fcp_cnt %d\n",
5491 __func__, __LINE__, fcport->port_name,
5493 qla24xx_post_gpsc_work(vha, fcport);
5497 fcport->disc_state = DSC_LOGIN_COMPLETE;
5500 void qla_register_fcport_fn(struct work_struct *work)
5502 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5503 u32 rscn_gen = fcport->rscn_gen;
5506 if (IS_SW_RESV_ADDR(fcport->d_id))
5509 qla2x00_update_fcport(fcport->vha, fcport);
5511 if (rscn_gen != fcport->rscn_gen) {
5512 /* RSCN(s) came in while registration */
5513 switch (fcport->next_disc_state) {
5514 case DSC_DELETE_PEND:
5515 qlt_schedule_sess_for_deletion(fcport);
5518 data[0] = data[1] = 0;
5519 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5529 * qla2x00_configure_fabric
5530 * Setup SNS devices with loop ID's.
5533 * ha = adapter block pointer.
5540 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5544 uint16_t mb[MAILBOX_REGISTER_COUNT];
5546 LIST_HEAD(new_fcports);
5547 struct qla_hw_data *ha = vha->hw;
5550 /* If FL port exists, then SNS is present */
5551 if (IS_FWI2_CAPABLE(ha))
5552 loop_id = NPH_F_PORT;
5554 loop_id = SNS_FL_PORT;
5555 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5556 if (rval != QLA_SUCCESS) {
5557 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5558 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5560 vha->device_flags &= ~SWITCH_FOUND;
5561 return (QLA_SUCCESS);
5563 vha->device_flags |= SWITCH_FOUND;
5566 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5567 rval = qla2x00_send_change_request(vha, 0x3, 0);
5568 if (rval != QLA_SUCCESS)
5569 ql_log(ql_log_warn, vha, 0x121,
5570 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5576 qla2x00_mgmt_svr_login(vha);
5579 if (ql2xfdmienable &&
5580 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5581 qla2x00_fdmi_register(vha);
5583 /* Ensure we are logged into the SNS. */
5584 loop_id = NPH_SNS_LID(ha);
5585 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5586 0xfc, mb, BIT_1|BIT_0);
5587 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5588 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5589 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5590 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5591 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5594 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5595 if (qla2x00_rft_id(vha)) {
5597 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5598 "Register FC-4 TYPE failed.\n");
5599 if (test_bit(LOOP_RESYNC_NEEDED,
5603 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5605 ql_dbg(ql_dbg_disc, vha, 0x209a,
5606 "Register FC-4 Features failed.\n");
5607 if (test_bit(LOOP_RESYNC_NEEDED,
5611 if (vha->flags.nvme_enabled) {
5612 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5613 ql_dbg(ql_dbg_disc, vha, 0x2049,
5614 "Register NVME FC Type Features failed.\n");
5617 if (qla2x00_rnn_id(vha)) {
5619 ql_dbg(ql_dbg_disc, vha, 0x2104,
5620 "Register Node Name failed.\n");
5621 if (test_bit(LOOP_RESYNC_NEEDED,
5624 } else if (qla2x00_rsnn_nn(vha)) {
5626 ql_dbg(ql_dbg_disc, vha, 0x209b,
5627 "Register Symbolic Node Name failed.\n");
5628 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5634 /* Mark the time right before querying FW for connected ports.
5635 * This process is long, asynchronous and by the time it's done,
5636 * collected information might not be accurate anymore. E.g.
5637 * disconnected port might have re-connected and a brand new
5638 * session has been created. In this case session's generation
5639 * will be newer than discovery_gen. */
5640 qlt_do_generation_tick(vha, &discovery_gen);
5642 if (USE_ASYNC_SCAN(ha)) {
5643 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5646 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5648 list_for_each_entry(fcport, &vha->vp_fcports, list)
5649 fcport->scan_state = QLA_FCPORT_SCAN;
5651 rval = qla2x00_find_all_fabric_devs(vha);
5653 if (rval != QLA_SUCCESS)
5657 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5658 qla_nvme_register_hba(vha);
5661 ql_dbg(ql_dbg_disc, vha, 0x2068,
5662 "Configure fabric error exit rval=%d.\n", rval);
5668 * qla2x00_find_all_fabric_devs
5671 * ha = adapter block pointer.
5672 * dev = database device entry pointer.
5681 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5685 fc_port_t *fcport, *new_fcport;
5690 int first_dev, last_dev;
5691 port_id_t wrap = {}, nxt_d_id;
5692 struct qla_hw_data *ha = vha->hw;
5693 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5694 unsigned long flags;
5698 /* Try GID_PT to get device list, else GAN. */
5700 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5705 ql_dbg(ql_dbg_disc, vha, 0x209c,
5706 "GID_PT allocations failed, fallback on GA_NXT.\n");
5708 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5709 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5711 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5713 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5715 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5717 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5719 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5721 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5723 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5727 /* If other queries succeeded probe for FC-4 type */
5729 qla2x00_gff_id(vha, swl);
5730 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5736 /* Allocate temporary fcport for any new fcports discovered. */
5737 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5738 if (new_fcport == NULL) {
5739 ql_log(ql_log_warn, vha, 0x209d,
5740 "Failed to allocate memory for fcport.\n");
5741 return (QLA_MEMORY_ALLOC_FAILED);
5743 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5744 /* Set start port ID scan at adapter ID. */
5748 /* Starting free loop ID. */
5749 loop_id = ha->min_external_loopid;
5750 for (; loop_id <= ha->max_loop_id; loop_id++) {
5751 if (qla2x00_is_reserved_id(vha, loop_id))
5754 if (ha->current_topology == ISP_CFG_FL &&
5755 (atomic_read(&vha->loop_down_timer) ||
5756 LOOP_TRANSITION(vha))) {
5757 atomic_set(&vha->loop_down_timer, 0);
5758 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5759 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5765 wrap.b24 = new_fcport->d_id.b24;
5767 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5768 memcpy(new_fcport->node_name,
5769 swl[swl_idx].node_name, WWN_SIZE);
5770 memcpy(new_fcport->port_name,
5771 swl[swl_idx].port_name, WWN_SIZE);
5772 memcpy(new_fcport->fabric_port_name,
5773 swl[swl_idx].fabric_port_name, WWN_SIZE);
5774 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5775 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5777 new_fcport->nvme_flag = 0;
5778 new_fcport->fc4f_nvme = 0;
5779 if (vha->flags.nvme_enabled &&
5780 swl[swl_idx].fc4f_nvme) {
5781 new_fcport->fc4f_nvme =
5782 swl[swl_idx].fc4f_nvme;
5783 ql_log(ql_log_info, vha, 0x2131,
5784 "FOUND: NVME port %8phC as FC Type 28h\n",
5785 new_fcport->port_name);
5788 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5794 /* Send GA_NXT to the switch */
5795 rval = qla2x00_ga_nxt(vha, new_fcport);
5796 if (rval != QLA_SUCCESS) {
5797 ql_log(ql_log_warn, vha, 0x209e,
5798 "SNS scan failed -- assuming "
5799 "zero-entry result.\n");
5805 /* If wrap on switch device list, exit. */
5807 wrap.b24 = new_fcport->d_id.b24;
5809 } else if (new_fcport->d_id.b24 == wrap.b24) {
5810 ql_dbg(ql_dbg_disc, vha, 0x209f,
5811 "Device wrap (%02x%02x%02x).\n",
5812 new_fcport->d_id.b.domain,
5813 new_fcport->d_id.b.area,
5814 new_fcport->d_id.b.al_pa);
5818 /* Bypass if same physical adapter. */
5819 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5822 /* Bypass virtual ports of the same host. */
5823 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5826 /* Bypass if same domain and area of adapter. */
5827 if (((new_fcport->d_id.b24 & 0xffff00) ==
5828 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5832 /* Bypass reserved domain fields. */
5833 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5836 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5837 if (ql2xgffidenable &&
5838 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5839 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5842 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5844 /* Locate matching device in database. */
5846 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5847 if (memcmp(new_fcport->port_name, fcport->port_name,
5851 fcport->scan_state = QLA_FCPORT_FOUND;
5855 /* Update port state. */
5856 memcpy(fcport->fabric_port_name,
5857 new_fcport->fabric_port_name, WWN_SIZE);
5858 fcport->fp_speed = new_fcport->fp_speed;
5861 * If address the same and state FCS_ONLINE
5862 * (or in target mode), nothing changed.
5864 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5865 (atomic_read(&fcport->state) == FCS_ONLINE ||
5866 (vha->host->active_mode == MODE_TARGET))) {
5871 * If device was not a fabric device before.
5873 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5874 fcport->d_id.b24 = new_fcport->d_id.b24;
5875 qla2x00_clear_loop_id(fcport);
5876 fcport->flags |= (FCF_FABRIC_DEVICE |
5882 * Port ID changed or device was marked to be updated;
5883 * Log it out if still logged in and mark it for
5886 if (qla_tgt_mode_enabled(base_vha)) {
5887 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5888 "port changed FC ID, %8phC"
5889 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5891 fcport->d_id.b.domain,
5892 fcport->d_id.b.area,
5893 fcport->d_id.b.al_pa,
5895 new_fcport->d_id.b.domain,
5896 new_fcport->d_id.b.area,
5897 new_fcport->d_id.b.al_pa);
5898 fcport->d_id.b24 = new_fcport->d_id.b24;
5902 fcport->d_id.b24 = new_fcport->d_id.b24;
5903 fcport->flags |= FCF_LOGIN_NEEDED;
5907 if (fcport->fc4f_nvme) {
5908 if (fcport->disc_state == DSC_DELETE_PEND) {
5909 fcport->disc_state = DSC_GNL;
5910 vha->fcport_count--;
5911 fcport->login_succ = 0;
5916 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5919 /* If device was not in our fcports list, then add it. */
5920 new_fcport->scan_state = QLA_FCPORT_FOUND;
5921 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5923 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5926 /* Allocate a new replacement fcport. */
5927 nxt_d_id.b24 = new_fcport->d_id.b24;
5928 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5929 if (new_fcport == NULL) {
5930 ql_log(ql_log_warn, vha, 0xd032,
5931 "Memory allocation failed for fcport.\n");
5932 return (QLA_MEMORY_ALLOC_FAILED);
5934 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5935 new_fcport->d_id.b24 = nxt_d_id.b24;
5938 qla2x00_free_fcport(new_fcport);
5941 * Logout all previous fabric dev marked lost, except FCP2 devices.
5943 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5944 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5947 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5948 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5951 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5952 if ((qla_dual_mode_enabled(vha) ||
5953 qla_ini_mode_enabled(vha)) &&
5954 atomic_read(&fcport->state) == FCS_ONLINE) {
5955 qla2x00_mark_device_lost(vha, fcport,
5956 ql2xplogiabsentdevice, 0);
5957 if (fcport->loop_id != FC_NO_LOOP_ID &&
5958 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5959 fcport->port_type != FCT_INITIATOR &&
5960 fcport->port_type != FCT_BROADCAST) {
5961 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5962 "%s %d %8phC post del sess\n",
5965 qlt_schedule_sess_for_deletion(fcport);
5971 if (fcport->scan_state == QLA_FCPORT_FOUND)
5972 qla24xx_fcport_handle_login(vha, fcport);
5977 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5979 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5981 int loop_id = FC_NO_LOOP_ID;
5982 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5983 unsigned long flags;
5984 struct qla_hw_data *ha = vha->hw;
5986 if (vha->vp_idx == 0) {
5987 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5988 return NPH_MGMT_SERVER;
5991 /* pick id from high and work down to low */
5992 spin_lock_irqsave(&ha->vport_slock, flags);
5993 for (; lid > 0; lid--) {
5994 if (!test_bit(lid, vha->hw->loop_id_map)) {
5995 set_bit(lid, vha->hw->loop_id_map);
6000 spin_unlock_irqrestore(&ha->vport_slock, flags);
6006 * qla2x00_fabric_login
6007 * Issue fabric login command.
6010 * ha = adapter block pointer.
6011 * device = pointer to FC device type structure.
6014 * 0 - Login successfully
6016 * 2 - Initiator device
6020 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6021 uint16_t *next_loopid)
6025 uint16_t tmp_loopid;
6026 uint16_t mb[MAILBOX_REGISTER_COUNT];
6027 struct qla_hw_data *ha = vha->hw;
6033 ql_dbg(ql_dbg_disc, vha, 0x2000,
6034 "Trying Fabric Login w/loop id 0x%04x for port "
6036 fcport->loop_id, fcport->d_id.b.domain,
6037 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6039 /* Login fcport on switch. */
6040 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6041 fcport->d_id.b.domain, fcport->d_id.b.area,
6042 fcport->d_id.b.al_pa, mb, BIT_0);
6043 if (rval != QLA_SUCCESS) {
6046 if (mb[0] == MBS_PORT_ID_USED) {
6048 * Device has another loop ID. The firmware team
6049 * recommends the driver perform an implicit login with
6050 * the specified ID again. The ID we just used is save
6051 * here so we return with an ID that can be tried by
6055 tmp_loopid = fcport->loop_id;
6056 fcport->loop_id = mb[1];
6058 ql_dbg(ql_dbg_disc, vha, 0x2001,
6059 "Fabric Login: port in use - next loop "
6060 "id=0x%04x, port id= %02x%02x%02x.\n",
6061 fcport->loop_id, fcport->d_id.b.domain,
6062 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6064 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6069 /* A retry occurred before. */
6070 *next_loopid = tmp_loopid;
6073 * No retry occurred before. Just increment the
6074 * ID value for next login.
6076 *next_loopid = (fcport->loop_id + 1);
6079 if (mb[1] & BIT_0) {
6080 fcport->port_type = FCT_INITIATOR;
6082 fcport->port_type = FCT_TARGET;
6083 if (mb[1] & BIT_1) {
6084 fcport->flags |= FCF_FCP2_DEVICE;
6089 fcport->supported_classes |= FC_COS_CLASS2;
6091 fcport->supported_classes |= FC_COS_CLASS3;
6093 if (IS_FWI2_CAPABLE(ha)) {
6096 FCF_CONF_COMP_SUPPORTED;
6101 } else if (mb[0] == MBS_LOOP_ID_USED) {
6103 * Loop ID already used, try next loop ID.
6106 rval = qla2x00_find_new_loop_id(vha, fcport);
6107 if (rval != QLA_SUCCESS) {
6108 /* Ran out of loop IDs to use */
6111 } else if (mb[0] == MBS_COMMAND_ERROR) {
6113 * Firmware possibly timed out during login. If NO
6114 * retries are left to do then the device is declared
6117 *next_loopid = fcport->loop_id;
6118 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6119 fcport->d_id.b.domain, fcport->d_id.b.area,
6120 fcport->d_id.b.al_pa);
6121 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6127 * unrecoverable / not handled error
6129 ql_dbg(ql_dbg_disc, vha, 0x2002,
6130 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6131 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6132 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6133 fcport->loop_id, jiffies);
6135 *next_loopid = fcport->loop_id;
6136 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6137 fcport->d_id.b.domain, fcport->d_id.b.area,
6138 fcport->d_id.b.al_pa);
6139 qla2x00_clear_loop_id(fcport);
6140 fcport->login_retry = 0;
6151 * qla2x00_local_device_login
6152 * Issue local device login command.
6155 * ha = adapter block pointer.
6156 * loop_id = loop id of device to login to.
6158 * Returns (Where's the #define!!!!):
6159 * 0 - Login successfully
6164 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6167 uint16_t mb[MAILBOX_REGISTER_COUNT];
6169 memset(mb, 0, sizeof(mb));
6170 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6171 if (rval == QLA_SUCCESS) {
6172 /* Interrogate mailbox registers for any errors */
6173 if (mb[0] == MBS_COMMAND_ERROR)
6175 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6176 /* device not in PCB table */
6184 * qla2x00_loop_resync
6185 * Resync with fibre channel devices.
6188 * ha = adapter block pointer.
6194 qla2x00_loop_resync(scsi_qla_host_t *vha)
6196 int rval = QLA_SUCCESS;
6199 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6200 if (vha->flags.online) {
6201 if (!(rval = qla2x00_fw_ready(vha))) {
6202 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6205 if (!IS_QLAFX00(vha->hw)) {
6207 * Issue a marker after FW becomes
6210 qla2x00_marker(vha, vha->hw->base_qpair,
6212 vha->marker_needed = 0;
6215 /* Remap devices on Loop. */
6216 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6218 if (IS_QLAFX00(vha->hw))
6219 qlafx00_configure_devices(vha);
6221 qla2x00_configure_loop(vha);
6224 } while (!atomic_read(&vha->loop_down_timer) &&
6225 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6226 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6231 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6232 return (QLA_FUNCTION_FAILED);
6235 ql_dbg(ql_dbg_disc, vha, 0x206c,
6236 "%s *** FAILED ***.\n", __func__);
6242 * qla2x00_perform_loop_resync
6243 * Description: This function will set the appropriate flags and call
6244 * qla2x00_loop_resync. If successful loop will be resynced
6245 * Arguments : scsi_qla_host_t pointer
6246 * returm : Success or Failure
6249 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6253 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6254 /*Configure the flags so that resync happens properly*/
6255 atomic_set(&ha->loop_down_timer, 0);
6256 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6257 atomic_set(&ha->loop_state, LOOP_UP);
6258 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6259 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6260 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6262 rval = qla2x00_loop_resync(ha);
6264 atomic_set(&ha->loop_state, LOOP_DEAD);
6266 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6273 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6276 struct scsi_qla_host *vha;
6277 struct qla_hw_data *ha = base_vha->hw;
6278 unsigned long flags;
6280 spin_lock_irqsave(&ha->vport_slock, flags);
6281 /* Go with deferred removal of rport references. */
6282 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6283 atomic_inc(&vha->vref_count);
6284 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6285 if (fcport->drport &&
6286 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6287 spin_unlock_irqrestore(&ha->vport_slock, flags);
6288 qla2x00_rport_del(fcport);
6290 spin_lock_irqsave(&ha->vport_slock, flags);
6293 atomic_dec(&vha->vref_count);
6294 wake_up(&vha->vref_waitq);
6296 spin_unlock_irqrestore(&ha->vport_slock, flags);
6299 /* Assumes idc_lock always held on entry */
6301 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6303 struct qla_hw_data *ha = vha->hw;
6304 uint32_t drv_presence, drv_presence_mask;
6305 uint32_t dev_part_info1, dev_part_info2, class_type;
6306 uint32_t class_type_mask = 0x3;
6307 uint16_t fcoe_other_function = 0xffff, i;
6309 if (IS_QLA8044(ha)) {
6310 drv_presence = qla8044_rd_direct(vha,
6311 QLA8044_CRB_DRV_ACTIVE_INDEX);
6312 dev_part_info1 = qla8044_rd_direct(vha,
6313 QLA8044_CRB_DEV_PART_INFO_INDEX);
6314 dev_part_info2 = qla8044_rd_direct(vha,
6315 QLA8044_CRB_DEV_PART_INFO2);
6317 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6318 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6319 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6321 for (i = 0; i < 8; i++) {
6322 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6323 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6324 (i != ha->portnum)) {
6325 fcoe_other_function = i;
6329 if (fcoe_other_function == 0xffff) {
6330 for (i = 0; i < 8; i++) {
6331 class_type = ((dev_part_info2 >> (i * 4)) &
6333 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6334 ((i + 8) != ha->portnum)) {
6335 fcoe_other_function = i + 8;
6341 * Prepare drv-presence mask based on fcoe functions present.
6342 * However consider only valid physical fcoe function numbers (0-15).
6344 drv_presence_mask = ~((1 << (ha->portnum)) |
6345 ((fcoe_other_function == 0xffff) ?
6346 0 : (1 << (fcoe_other_function))));
6348 /* We are the reset owner iff:
6349 * - No other protocol drivers present.
6350 * - This is the lowest among fcoe functions. */
6351 if (!(drv_presence & drv_presence_mask) &&
6352 (ha->portnum < fcoe_other_function)) {
6353 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6354 "This host is Reset owner.\n");
6355 ha->flags.nic_core_reset_owner = 1;
6360 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6362 int rval = QLA_SUCCESS;
6363 struct qla_hw_data *ha = vha->hw;
6366 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6367 if (rval == QLA_SUCCESS) {
6368 drv_ack |= (1 << ha->portnum);
6369 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6376 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6378 int rval = QLA_SUCCESS;
6379 struct qla_hw_data *ha = vha->hw;
6382 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6383 if (rval == QLA_SUCCESS) {
6384 drv_ack &= ~(1 << ha->portnum);
6385 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6392 qla83xx_dev_state_to_string(uint32_t dev_state)
6394 switch (dev_state) {
6395 case QLA8XXX_DEV_COLD:
6396 return "COLD/RE-INIT";
6397 case QLA8XXX_DEV_INITIALIZING:
6398 return "INITIALIZING";
6399 case QLA8XXX_DEV_READY:
6401 case QLA8XXX_DEV_NEED_RESET:
6402 return "NEED RESET";
6403 case QLA8XXX_DEV_NEED_QUIESCENT:
6404 return "NEED QUIESCENT";
6405 case QLA8XXX_DEV_FAILED:
6407 case QLA8XXX_DEV_QUIESCENT:
6414 /* Assumes idc-lock always held on entry */
6416 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6418 struct qla_hw_data *ha = vha->hw;
6419 uint32_t idc_audit_reg = 0, duration_secs = 0;
6421 switch (audit_type) {
6422 case IDC_AUDIT_TIMESTAMP:
6423 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6424 idc_audit_reg = (ha->portnum) |
6425 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6426 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6429 case IDC_AUDIT_COMPLETION:
6430 duration_secs = ((jiffies_to_msecs(jiffies) -
6431 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6432 idc_audit_reg = (ha->portnum) |
6433 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6434 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6438 ql_log(ql_log_warn, vha, 0xb078,
6439 "Invalid audit type specified.\n");
6444 /* Assumes idc_lock always held on entry */
6446 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6448 struct qla_hw_data *ha = vha->hw;
6449 uint32_t idc_control, dev_state;
6451 __qla83xx_get_idc_control(vha, &idc_control);
6452 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6453 ql_log(ql_log_info, vha, 0xb080,
6454 "NIC Core reset has been disabled. idc-control=0x%x\n",
6456 return QLA_FUNCTION_FAILED;
6459 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6460 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6461 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6462 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6463 QLA8XXX_DEV_NEED_RESET);
6464 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6465 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6467 const char *state = qla83xx_dev_state_to_string(dev_state);
6469 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6471 /* SV: XXX: Is timeout required here? */
6472 /* Wait for IDC state change READY -> NEED_RESET */
6473 while (dev_state == QLA8XXX_DEV_READY) {
6474 qla83xx_idc_unlock(vha, 0);
6476 qla83xx_idc_lock(vha, 0);
6477 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6481 /* Send IDC ack by writing to drv-ack register */
6482 __qla83xx_set_drv_ack(vha);
6488 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6490 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6494 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6496 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6500 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6502 uint32_t drv_presence = 0;
6503 struct qla_hw_data *ha = vha->hw;
6505 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6506 if (drv_presence & (1 << ha->portnum))
6509 return QLA_TEST_FAILED;
6513 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6515 int rval = QLA_SUCCESS;
6516 struct qla_hw_data *ha = vha->hw;
6518 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6519 "Entered %s().\n", __func__);
6521 if (vha->device_flags & DFLG_DEV_FAILED) {
6522 ql_log(ql_log_warn, vha, 0xb059,
6523 "Device in unrecoverable FAILED state.\n");
6524 return QLA_FUNCTION_FAILED;
6527 qla83xx_idc_lock(vha, 0);
6529 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6530 ql_log(ql_log_warn, vha, 0xb05a,
6531 "Function=0x%x has been removed from IDC participation.\n",
6533 rval = QLA_FUNCTION_FAILED;
6537 qla83xx_reset_ownership(vha);
6539 rval = qla83xx_initiating_reset(vha);
6542 * Perform reset if we are the reset-owner,
6543 * else wait till IDC state changes to READY/FAILED.
6545 if (rval == QLA_SUCCESS) {
6546 rval = qla83xx_idc_state_handler(vha);
6548 if (rval == QLA_SUCCESS)
6549 ha->flags.nic_core_hung = 0;
6550 __qla83xx_clear_drv_ack(vha);
6554 qla83xx_idc_unlock(vha, 0);
6556 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6562 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6564 struct qla_hw_data *ha = vha->hw;
6565 int rval = QLA_FUNCTION_FAILED;
6567 if (!IS_MCTP_CAPABLE(ha)) {
6568 /* This message can be removed from the final version */
6569 ql_log(ql_log_info, vha, 0x506d,
6570 "This board is not MCTP capable\n");
6574 if (!ha->mctp_dump) {
6575 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6576 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6578 if (!ha->mctp_dump) {
6579 ql_log(ql_log_warn, vha, 0x506e,
6580 "Failed to allocate memory for mctp dump\n");
6585 #define MCTP_DUMP_STR_ADDR 0x00000000
6586 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6587 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6588 if (rval != QLA_SUCCESS) {
6589 ql_log(ql_log_warn, vha, 0x506f,
6590 "Failed to capture mctp dump\n");
6592 ql_log(ql_log_info, vha, 0x5070,
6593 "Mctp dump capture for host (%ld/%p).\n",
6594 vha->host_no, ha->mctp_dump);
6595 ha->mctp_dumped = 1;
6598 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6599 ha->flags.nic_core_reset_hdlr_active = 1;
6600 rval = qla83xx_restart_nic_firmware(vha);
6602 /* NIC Core reset failed. */
6603 ql_log(ql_log_warn, vha, 0x5071,
6604 "Failed to restart nic firmware\n");
6606 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6607 "Restarted NIC firmware successfully.\n");
6608 ha->flags.nic_core_reset_hdlr_active = 0;
6616 * qla2x00_quiesce_io
6617 * Description: This function will block the new I/Os
6618 * Its not aborting any I/Os as context
6619 * is not destroyed during quiescence
6620 * Arguments: scsi_qla_host_t
6624 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6626 struct qla_hw_data *ha = vha->hw;
6627 struct scsi_qla_host *vp;
6629 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6630 "Quiescing I/O - ha=%p.\n", ha);
6632 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6633 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6634 atomic_set(&vha->loop_state, LOOP_DOWN);
6635 qla2x00_mark_all_devices_lost(vha, 0);
6636 list_for_each_entry(vp, &ha->vp_list, list)
6637 qla2x00_mark_all_devices_lost(vp, 0);
6639 if (!atomic_read(&vha->loop_down_timer))
6640 atomic_set(&vha->loop_down_timer,
6643 /* Wait for pending cmds to complete */
6644 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6648 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6650 struct qla_hw_data *ha = vha->hw;
6651 struct scsi_qla_host *vp;
6652 unsigned long flags;
6656 /* For ISP82XX, driver waits for completion of the commands.
6657 * online flag should be set.
6659 if (!(IS_P3P_TYPE(ha)))
6660 vha->flags.online = 0;
6661 ha->flags.chip_reset_done = 0;
6662 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6663 vha->qla_stats.total_isp_aborts++;
6665 ql_log(ql_log_info, vha, 0x00af,
6666 "Performing ISP error recovery - ha=%p.\n", ha);
6668 ha->flags.purge_mbox = 1;
6669 /* For ISP82XX, reset_chip is just disabling interrupts.
6670 * Driver waits for the completion of the commands.
6671 * the interrupts need to be enabled.
6673 if (!(IS_P3P_TYPE(ha)))
6674 ha->isp_ops->reset_chip(vha);
6676 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6678 ha->flags.rida_fmt2 = 0;
6679 ha->flags.n2n_ae = 0;
6680 ha->flags.lip_ae = 0;
6681 ha->current_topology = 0;
6682 ha->flags.fw_started = 0;
6683 ha->flags.fw_init_done = 0;
6685 ha->base_qpair->chip_reset = ha->chip_reset;
6686 for (i = 0; i < ha->max_qpairs; i++) {
6687 if (ha->queue_pair_map[i])
6688 ha->queue_pair_map[i]->chip_reset =
6689 ha->base_qpair->chip_reset;
6692 /* purge MBox commands */
6693 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6694 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6695 complete(&ha->mbx_intr_comp);
6699 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6700 atomic_read(&ha->num_pend_mbx_stage2) ||
6701 atomic_read(&ha->num_pend_mbx_stage1)) {
6707 ha->flags.purge_mbox = 0;
6709 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6710 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6711 atomic_set(&vha->loop_state, LOOP_DOWN);
6712 qla2x00_mark_all_devices_lost(vha, 0);
6714 spin_lock_irqsave(&ha->vport_slock, flags);
6715 list_for_each_entry(vp, &ha->vp_list, list) {
6716 atomic_inc(&vp->vref_count);
6717 spin_unlock_irqrestore(&ha->vport_slock, flags);
6719 qla2x00_mark_all_devices_lost(vp, 0);
6721 spin_lock_irqsave(&ha->vport_slock, flags);
6722 atomic_dec(&vp->vref_count);
6724 spin_unlock_irqrestore(&ha->vport_slock, flags);
6726 if (!atomic_read(&vha->loop_down_timer))
6727 atomic_set(&vha->loop_down_timer,
6731 /* Clear all async request states across all VPs. */
6732 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6733 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6734 fcport->scan_state = 0;
6736 spin_lock_irqsave(&ha->vport_slock, flags);
6737 list_for_each_entry(vp, &ha->vp_list, list) {
6738 atomic_inc(&vp->vref_count);
6739 spin_unlock_irqrestore(&ha->vport_slock, flags);
6741 list_for_each_entry(fcport, &vp->vp_fcports, list)
6742 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6744 spin_lock_irqsave(&ha->vport_slock, flags);
6745 atomic_dec(&vp->vref_count);
6747 spin_unlock_irqrestore(&ha->vport_slock, flags);
6749 if (!ha->flags.eeh_busy) {
6750 /* Make sure for ISP 82XX IO DMA is complete */
6751 if (IS_P3P_TYPE(ha)) {
6752 qla82xx_chip_reset_cleanup(vha);
6753 ql_log(ql_log_info, vha, 0x00b4,
6754 "Done chip reset cleanup.\n");
6756 /* Done waiting for pending commands.
6757 * Reset the online flag.
6759 vha->flags.online = 0;
6762 /* Requeue all commands in outstanding command list. */
6763 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6765 /* memory barrier */
6771 * Resets ISP and aborts all outstanding commands.
6774 * ha = adapter block pointer.
6780 qla2x00_abort_isp(scsi_qla_host_t *vha)
6784 struct qla_hw_data *ha = vha->hw;
6785 struct scsi_qla_host *vp;
6786 struct req_que *req = ha->req_q_map[0];
6787 unsigned long flags;
6789 if (vha->flags.online) {
6790 qla2x00_abort_isp_cleanup(vha);
6792 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6793 ha->flags.chip_reset_done = 1;
6794 vha->flags.online = 1;
6796 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6800 if (IS_QLA8031(ha)) {
6801 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6802 "Clearing fcoe driver presence.\n");
6803 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6804 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6805 "Error while clearing DRV-Presence.\n");
6808 if (unlikely(pci_channel_offline(ha->pdev) &&
6809 ha->flags.pci_channel_io_perm_failure)) {
6810 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6815 switch (vha->qlini_mode) {
6816 case QLA2XXX_INI_MODE_DISABLED:
6817 if (!qla_tgt_mode_enabled(vha))
6820 case QLA2XXX_INI_MODE_DUAL:
6821 if (!qla_dual_mode_enabled(vha))
6824 case QLA2XXX_INI_MODE_ENABLED:
6829 ha->isp_ops->get_flash_version(vha, req->ring);
6831 ha->isp_ops->nvram_config(vha);
6833 if (!qla2x00_restart_isp(vha)) {
6834 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6836 if (!atomic_read(&vha->loop_down_timer)) {
6838 * Issue marker command only when we are going
6839 * to start the I/O .
6841 vha->marker_needed = 1;
6844 vha->flags.online = 1;
6846 ha->isp_ops->enable_intrs(ha);
6848 ha->isp_abort_cnt = 0;
6849 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6851 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6852 qla2x00_get_fw_version(vha);
6854 ha->flags.fce_enabled = 1;
6856 fce_calc_size(ha->fce_bufs));
6857 rval = qla2x00_enable_fce_trace(vha,
6858 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6861 ql_log(ql_log_warn, vha, 0x8033,
6862 "Unable to reinitialize FCE "
6864 ha->flags.fce_enabled = 0;
6869 memset(ha->eft, 0, EFT_SIZE);
6870 rval = qla2x00_enable_eft_trace(vha,
6871 ha->eft_dma, EFT_NUM_BUFFERS);
6873 ql_log(ql_log_warn, vha, 0x8034,
6874 "Unable to reinitialize EFT "
6878 } else { /* failed the ISP abort */
6879 vha->flags.online = 1;
6880 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6881 if (ha->isp_abort_cnt == 0) {
6882 ql_log(ql_log_fatal, vha, 0x8035,
6883 "ISP error recover failed - "
6884 "board disabled.\n");
6886 * The next call disables the board
6889 qla2x00_abort_isp_cleanup(vha);
6890 vha->flags.online = 0;
6891 clear_bit(ISP_ABORT_RETRY,
6894 } else { /* schedule another ISP abort */
6895 ha->isp_abort_cnt--;
6896 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6897 "ISP abort - retry remaining %d.\n",
6902 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6903 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6904 "ISP error recovery - retrying (%d) "
6905 "more times.\n", ha->isp_abort_cnt);
6906 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6914 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6915 qla2x00_configure_hba(vha);
6916 spin_lock_irqsave(&ha->vport_slock, flags);
6917 list_for_each_entry(vp, &ha->vp_list, list) {
6919 atomic_inc(&vp->vref_count);
6920 spin_unlock_irqrestore(&ha->vport_slock, flags);
6922 qla2x00_vp_abort_isp(vp);
6924 spin_lock_irqsave(&ha->vport_slock, flags);
6925 atomic_dec(&vp->vref_count);
6928 spin_unlock_irqrestore(&ha->vport_slock, flags);
6930 if (IS_QLA8031(ha)) {
6931 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6932 "Setting back fcoe driver presence.\n");
6933 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6934 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6935 "Error while setting DRV-Presence.\n");
6938 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6946 * qla2x00_restart_isp
6947 * restarts the ISP after a reset
6950 * ha = adapter block pointer.
6956 qla2x00_restart_isp(scsi_qla_host_t *vha)
6959 struct qla_hw_data *ha = vha->hw;
6961 /* If firmware needs to be loaded */
6962 if (qla2x00_isp_firmware(vha)) {
6963 vha->flags.online = 0;
6964 status = ha->isp_ops->chip_diag(vha);
6966 status = qla2x00_setup_chip(vha);
6969 if (!status && !(status = qla2x00_init_rings(vha))) {
6970 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6971 ha->flags.chip_reset_done = 1;
6973 /* Initialize the queues in use */
6974 qla25xx_init_queues(ha);
6976 status = qla2x00_fw_ready(vha);
6978 /* Issue a marker after FW becomes ready. */
6979 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
6980 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6983 /* if no cable then assume it's good */
6984 if ((vha->device_flags & DFLG_NO_CABLE))
6991 qla25xx_init_queues(struct qla_hw_data *ha)
6993 struct rsp_que *rsp = NULL;
6994 struct req_que *req = NULL;
6995 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6999 for (i = 1; i < ha->max_rsp_queues; i++) {
7000 rsp = ha->rsp_q_map[i];
7001 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7002 rsp->options &= ~BIT_0;
7003 ret = qla25xx_init_rsp_que(base_vha, rsp);
7004 if (ret != QLA_SUCCESS)
7005 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7006 "%s Rsp que: %d init failed.\n",
7009 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7010 "%s Rsp que: %d inited.\n",
7014 for (i = 1; i < ha->max_req_queues; i++) {
7015 req = ha->req_q_map[i];
7016 if (req && test_bit(i, ha->req_qid_map)) {
7017 /* Clear outstanding commands array. */
7018 req->options &= ~BIT_0;
7019 ret = qla25xx_init_req_que(base_vha, req);
7020 if (ret != QLA_SUCCESS)
7021 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7022 "%s Req que: %d init failed.\n",
7025 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7026 "%s Req que: %d inited.\n",
7034 * qla2x00_reset_adapter
7038 * ha = adapter block pointer.
7041 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7043 unsigned long flags = 0;
7044 struct qla_hw_data *ha = vha->hw;
7045 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7047 vha->flags.online = 0;
7048 ha->isp_ops->disable_intrs(ha);
7050 spin_lock_irqsave(&ha->hardware_lock, flags);
7051 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7052 RD_REG_WORD(®->hccr); /* PCI Posting. */
7053 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7054 RD_REG_WORD(®->hccr); /* PCI Posting. */
7055 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7061 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7063 unsigned long flags = 0;
7064 struct qla_hw_data *ha = vha->hw;
7065 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7066 int rval = QLA_SUCCESS;
7068 if (IS_P3P_TYPE(ha))
7071 vha->flags.online = 0;
7072 ha->isp_ops->disable_intrs(ha);
7074 spin_lock_irqsave(&ha->hardware_lock, flags);
7075 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7076 RD_REG_DWORD(®->hccr);
7077 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7078 RD_REG_DWORD(®->hccr);
7079 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7081 if (IS_NOPOLLING_TYPE(ha))
7082 ha->isp_ops->enable_intrs(ha);
7087 /* On sparc systems, obtain port and node WWN from firmware
7090 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7091 struct nvram_24xx *nv)
7094 struct qla_hw_data *ha = vha->hw;
7095 struct pci_dev *pdev = ha->pdev;
7096 struct device_node *dp = pci_device_to_OF_node(pdev);
7100 val = of_get_property(dp, "port-wwn", &len);
7101 if (val && len >= WWN_SIZE)
7102 memcpy(nv->port_name, val, WWN_SIZE);
7104 val = of_get_property(dp, "node-wwn", &len);
7105 if (val && len >= WWN_SIZE)
7106 memcpy(nv->node_name, val, WWN_SIZE);
7111 qla24xx_nvram_config(scsi_qla_host_t *vha)
7114 struct init_cb_24xx *icb;
7115 struct nvram_24xx *nv;
7117 uint8_t *dptr1, *dptr2;
7120 struct qla_hw_data *ha = vha->hw;
7123 icb = (struct init_cb_24xx *)ha->init_cb;
7126 /* Determine NVRAM starting address. */
7127 if (ha->port_no == 0) {
7128 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7129 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7131 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7132 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7135 ha->nvram_size = sizeof(*nv);
7136 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7138 /* Get VPD data into cache */
7139 ha->vpd = ha->nvram + VPD_OFFSET;
7140 ha->isp_ops->read_nvram(vha, ha->vpd,
7141 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7143 /* Get NVRAM data into cache and calculate checksum. */
7144 dptr = (uint32_t *)nv;
7145 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7146 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7147 chksum += le32_to_cpu(*dptr);
7149 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7150 "Contents of NVRAM\n");
7151 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7152 nv, ha->nvram_size);
7154 /* Bad NVRAM data, set defaults parameters. */
7155 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7156 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7157 /* Reset NVRAM data. */
7158 ql_log(ql_log_warn, vha, 0x006b,
7159 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7160 chksum, nv->id, nv->nvram_version);
7161 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7162 ql_log(ql_log_warn, vha, 0x006c,
7163 "Falling back to functioning (yet invalid -- WWPN) "
7167 * Set default initialization control block.
7169 memset(nv, 0, ha->nvram_size);
7170 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7171 nv->version = cpu_to_le16(ICB_VERSION);
7172 nv->frame_payload_size = 2048;
7173 nv->execution_throttle = cpu_to_le16(0xFFFF);
7174 nv->exchange_count = cpu_to_le16(0);
7175 nv->hard_address = cpu_to_le16(124);
7176 nv->port_name[0] = 0x21;
7177 nv->port_name[1] = 0x00 + ha->port_no + 1;
7178 nv->port_name[2] = 0x00;
7179 nv->port_name[3] = 0xe0;
7180 nv->port_name[4] = 0x8b;
7181 nv->port_name[5] = 0x1c;
7182 nv->port_name[6] = 0x55;
7183 nv->port_name[7] = 0x86;
7184 nv->node_name[0] = 0x20;
7185 nv->node_name[1] = 0x00;
7186 nv->node_name[2] = 0x00;
7187 nv->node_name[3] = 0xe0;
7188 nv->node_name[4] = 0x8b;
7189 nv->node_name[5] = 0x1c;
7190 nv->node_name[6] = 0x55;
7191 nv->node_name[7] = 0x86;
7192 qla24xx_nvram_wwn_from_ofw(vha, nv);
7193 nv->login_retry_count = cpu_to_le16(8);
7194 nv->interrupt_delay_timer = cpu_to_le16(0);
7195 nv->login_timeout = cpu_to_le16(0);
7196 nv->firmware_options_1 =
7197 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7198 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7199 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7200 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7201 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7202 nv->efi_parameters = cpu_to_le32(0);
7203 nv->reset_delay = 5;
7204 nv->max_luns_per_target = cpu_to_le16(128);
7205 nv->port_down_retry_count = cpu_to_le16(30);
7206 nv->link_down_timeout = cpu_to_le16(30);
7211 if (qla_tgt_mode_enabled(vha)) {
7212 /* Don't enable full login after initial LIP */
7213 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7214 /* Don't enable LIP full login for initiator */
7215 nv->host_p &= cpu_to_le32(~BIT_10);
7218 qlt_24xx_config_nvram_stage1(vha, nv);
7220 /* Reset Initialization control block */
7221 memset(icb, 0, ha->init_cb_size);
7223 /* Copy 1st segment. */
7224 dptr1 = (uint8_t *)icb;
7225 dptr2 = (uint8_t *)&nv->version;
7226 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7228 *dptr1++ = *dptr2++;
7230 icb->login_retry_count = nv->login_retry_count;
7231 icb->link_down_on_nos = nv->link_down_on_nos;
7233 /* Copy 2nd segment. */
7234 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7235 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7236 cnt = (uint8_t *)&icb->reserved_3 -
7237 (uint8_t *)&icb->interrupt_delay_timer;
7239 *dptr1++ = *dptr2++;
7240 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7242 * Setup driver NVRAM options.
7244 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7247 qlt_24xx_config_nvram_stage2(vha, icb);
7249 if (nv->host_p & cpu_to_le32(BIT_15)) {
7250 /* Use alternate WWN? */
7251 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7252 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7255 /* Prepare nodename */
7256 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7258 * Firmware will apply the following mask if the nodename was
7261 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7262 icb->node_name[0] &= 0xF0;
7265 /* Set host adapter parameters. */
7266 ha->flags.disable_risc_code_load = 0;
7267 ha->flags.enable_lip_reset = 0;
7268 ha->flags.enable_lip_full_login =
7269 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7270 ha->flags.enable_target_reset =
7271 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7272 ha->flags.enable_led_scheme = 0;
7273 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7275 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7276 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7278 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7279 sizeof(ha->fw_seriallink_options24));
7281 /* save HBA serial number */
7282 ha->serial0 = icb->port_name[5];
7283 ha->serial1 = icb->port_name[6];
7284 ha->serial2 = icb->port_name[7];
7285 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7286 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7288 icb->execution_throttle = cpu_to_le16(0xFFFF);
7290 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7292 /* Set minimum login_timeout to 4 seconds. */
7293 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7294 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7295 if (le16_to_cpu(nv->login_timeout) < 4)
7296 nv->login_timeout = cpu_to_le16(4);
7297 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7299 /* Set minimum RATOV to 100 tenths of a second. */
7302 ha->loop_reset_delay = nv->reset_delay;
7304 /* Link Down Timeout = 0:
7306 * When Port Down timer expires we will start returning
7307 * I/O's to OS with "DID_NO_CONNECT".
7309 * Link Down Timeout != 0:
7311 * The driver waits for the link to come up after link down
7312 * before returning I/Os to OS with "DID_NO_CONNECT".
7314 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7315 ha->loop_down_abort_time =
7316 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7318 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7319 ha->loop_down_abort_time =
7320 (LOOP_DOWN_TIME - ha->link_down_timeout);
7323 /* Need enough time to try and get the port back. */
7324 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7325 if (qlport_down_retry)
7326 ha->port_down_retry_count = qlport_down_retry;
7328 /* Set login_retry_count */
7329 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7330 if (ha->port_down_retry_count ==
7331 le16_to_cpu(nv->port_down_retry_count) &&
7332 ha->port_down_retry_count > 3)
7333 ha->login_retry_count = ha->port_down_retry_count;
7334 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7335 ha->login_retry_count = ha->port_down_retry_count;
7336 if (ql2xloginretrycount)
7337 ha->login_retry_count = ql2xloginretrycount;
7339 /* N2N: driver will initiate Login instead of FW */
7340 icb->firmware_options_3 |= BIT_8;
7343 if (!vha->flags.init_done) {
7344 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7345 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7346 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7347 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7349 icb->firmware_options_2 &= cpu_to_le32(
7350 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7351 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7352 ha->zio_mode = QLA_ZIO_MODE_6;
7354 ql_log(ql_log_info, vha, 0x006f,
7355 "ZIO mode %d enabled; timer delay (%d us).\n",
7356 ha->zio_mode, ha->zio_timer * 100);
7358 icb->firmware_options_2 |= cpu_to_le32(
7359 (uint32_t)ha->zio_mode);
7360 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7364 ql_log(ql_log_warn, vha, 0x0070,
7365 "NVRAM configuration failed.\n");
7371 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7372 struct qla27xx_image_status *image_status)
7374 ql_dbg(ql_dbg_init, vha, 0x018b,
7375 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7377 image_status->image_status_mask,
7378 le16_to_cpu(image_status->generation),
7379 image_status->ver_major,
7380 image_status->ver_minor,
7381 image_status->bitmap,
7382 le32_to_cpu(image_status->checksum),
7383 le32_to_cpu(image_status->signature));
7387 qla28xx_check_aux_image_status_signature(
7388 struct qla27xx_image_status *image_status)
7390 ulong signature = le32_to_cpu(image_status->signature);
7392 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7396 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7398 ulong signature = le32_to_cpu(image_status->signature);
7401 signature != QLA27XX_IMG_STATUS_SIGN &&
7402 signature != QLA28XX_IMG_STATUS_SIGN;
7406 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7408 uint32_t *p = (void *)image_status;
7409 uint n = sizeof(*image_status) / sizeof(*p);
7413 sum += le32_to_cpup(p);
7419 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7421 return aux->bitmap & bitmask ?
7422 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7426 qla28xx_component_status(
7427 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7429 active_regions->aux.board_config =
7430 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7432 active_regions->aux.vpd_nvram =
7433 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7435 active_regions->aux.npiv_config_0_1 =
7436 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7438 active_regions->aux.npiv_config_2_3 =
7439 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7443 qla27xx_compare_image_generation(
7444 struct qla27xx_image_status *pri_image_status,
7445 struct qla27xx_image_status *sec_image_status)
7447 /* calculate generation delta as uint16 (this accounts for wrap) */
7449 le16_to_cpu(pri_image_status->generation) -
7450 le16_to_cpu(sec_image_status->generation);
7452 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7458 qla28xx_get_aux_images(
7459 struct scsi_qla_host *vha, struct active_regions *active_regions)
7461 struct qla_hw_data *ha = vha->hw;
7462 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7463 bool valid_pri_image = false, valid_sec_image = false;
7464 bool active_pri_image = false, active_sec_image = false;
7466 if (!ha->flt_region_aux_img_status_pri) {
7467 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7468 goto check_sec_image;
7471 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7472 ha->flt_region_aux_img_status_pri,
7473 sizeof(pri_aux_image_status) >> 2);
7474 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7476 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7477 ql_dbg(ql_dbg_init, vha, 0x018b,
7478 "Primary aux image signature (%#x) not valid\n",
7479 le32_to_cpu(pri_aux_image_status.signature));
7480 goto check_sec_image;
7483 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7484 ql_dbg(ql_dbg_init, vha, 0x018c,
7485 "Primary aux image checksum failed\n");
7486 goto check_sec_image;
7489 valid_pri_image = true;
7491 if (pri_aux_image_status.image_status_mask & 1) {
7492 ql_dbg(ql_dbg_init, vha, 0x018d,
7493 "Primary aux image is active\n");
7494 active_pri_image = true;
7498 if (!ha->flt_region_aux_img_status_sec) {
7499 ql_dbg(ql_dbg_init, vha, 0x018a,
7500 "Secondary aux image not addressed\n");
7501 goto check_valid_image;
7504 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7505 ha->flt_region_aux_img_status_sec,
7506 sizeof(sec_aux_image_status) >> 2);
7507 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7509 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7510 ql_dbg(ql_dbg_init, vha, 0x018b,
7511 "Secondary aux image signature (%#x) not valid\n",
7512 le32_to_cpu(sec_aux_image_status.signature));
7513 goto check_valid_image;
7516 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7517 ql_dbg(ql_dbg_init, vha, 0x018c,
7518 "Secondary aux image checksum failed\n");
7519 goto check_valid_image;
7522 valid_sec_image = true;
7524 if (sec_aux_image_status.image_status_mask & 1) {
7525 ql_dbg(ql_dbg_init, vha, 0x018d,
7526 "Secondary aux image is active\n");
7527 active_sec_image = true;
7531 if (valid_pri_image && active_pri_image &&
7532 valid_sec_image && active_sec_image) {
7533 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7534 &sec_aux_image_status) >= 0) {
7535 qla28xx_component_status(active_regions,
7536 &pri_aux_image_status);
7538 qla28xx_component_status(active_regions,
7539 &sec_aux_image_status);
7541 } else if (valid_pri_image && active_pri_image) {
7542 qla28xx_component_status(active_regions, &pri_aux_image_status);
7543 } else if (valid_sec_image && active_sec_image) {
7544 qla28xx_component_status(active_regions, &sec_aux_image_status);
7547 ql_dbg(ql_dbg_init, vha, 0x018f,
7548 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7549 active_regions->aux.board_config,
7550 active_regions->aux.vpd_nvram,
7551 active_regions->aux.npiv_config_0_1,
7552 active_regions->aux.npiv_config_2_3);
7556 qla27xx_get_active_image(struct scsi_qla_host *vha,
7557 struct active_regions *active_regions)
7559 struct qla_hw_data *ha = vha->hw;
7560 struct qla27xx_image_status pri_image_status, sec_image_status;
7561 bool valid_pri_image = false, valid_sec_image = false;
7562 bool active_pri_image = false, active_sec_image = false;
7564 if (!ha->flt_region_img_status_pri) {
7565 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7566 goto check_sec_image;
7569 qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7570 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2);
7571 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7573 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7574 ql_dbg(ql_dbg_init, vha, 0x018b,
7575 "Primary image signature (%#x) not valid\n",
7576 le32_to_cpu(pri_image_status.signature));
7577 goto check_sec_image;
7580 if (qla27xx_image_status_checksum(&pri_image_status)) {
7581 ql_dbg(ql_dbg_init, vha, 0x018c,
7582 "Primary image checksum failed\n");
7583 goto check_sec_image;
7586 valid_pri_image = true;
7588 if (pri_image_status.image_status_mask & 1) {
7589 ql_dbg(ql_dbg_init, vha, 0x018d,
7590 "Primary image is active\n");
7591 active_pri_image = true;
7595 if (!ha->flt_region_img_status_sec) {
7596 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7597 goto check_valid_image;
7600 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7601 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7602 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7604 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7605 ql_dbg(ql_dbg_init, vha, 0x018b,
7606 "Secondary image signature (%#x) not valid\n",
7607 le32_to_cpu(sec_image_status.signature));
7608 goto check_valid_image;
7611 if (qla27xx_image_status_checksum(&sec_image_status)) {
7612 ql_dbg(ql_dbg_init, vha, 0x018c,
7613 "Secondary image checksum failed\n");
7614 goto check_valid_image;
7617 valid_sec_image = true;
7619 if (sec_image_status.image_status_mask & 1) {
7620 ql_dbg(ql_dbg_init, vha, 0x018d,
7621 "Secondary image is active\n");
7622 active_sec_image = true;
7626 if (valid_pri_image && active_pri_image)
7627 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7629 if (valid_sec_image && active_sec_image) {
7630 if (!active_regions->global ||
7631 qla27xx_compare_image_generation(
7632 &pri_image_status, &sec_image_status) < 0) {
7633 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7637 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7638 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7639 "default (boot/fw)" :
7640 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7642 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7643 "secondary" : "invalid",
7644 active_regions->global);
7647 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7650 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7651 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7655 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7659 uint templates, segments, fragment;
7664 uint32_t risc_addr, risc_size, risc_attr = 0;
7665 struct qla_hw_data *ha = vha->hw;
7666 struct req_que *req = ha->req_q_map[0];
7667 struct fwdt *fwdt = ha->fwdt;
7669 ql_dbg(ql_dbg_init, vha, 0x008b,
7670 "FW: Loading firmware from flash (%x).\n", faddr);
7672 dcode = (void *)req->ring;
7673 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7674 if (qla24xx_risc_firmware_invalid(dcode)) {
7675 ql_log(ql_log_fatal, vha, 0x008c,
7676 "Unable to verify the integrity of flash firmware "
7678 ql_log(ql_log_fatal, vha, 0x008d,
7679 "Firmware data: %08x %08x %08x %08x.\n",
7680 dcode[0], dcode[1], dcode[2], dcode[3]);
7682 return QLA_FUNCTION_FAILED;
7685 dcode = (void *)req->ring;
7687 segments = FA_RISC_CODE_SEGMENTS;
7688 for (j = 0; j < segments; j++) {
7689 ql_dbg(ql_dbg_init, vha, 0x008d,
7690 "-> Loading segment %u...\n", j);
7691 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7692 risc_addr = be32_to_cpu(dcode[2]);
7693 risc_size = be32_to_cpu(dcode[3]);
7695 *srisc_addr = risc_addr;
7696 risc_attr = be32_to_cpu(dcode[9]);
7699 dlen = ha->fw_transfer_size >> 2;
7700 for (fragment = 0; risc_size; fragment++) {
7701 if (dlen > risc_size)
7704 ql_dbg(ql_dbg_init, vha, 0x008e,
7705 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7706 fragment, risc_addr, faddr, dlen);
7707 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7708 for (i = 0; i < dlen; i++)
7709 dcode[i] = swab32(dcode[i]);
7711 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7713 ql_log(ql_log_fatal, vha, 0x008f,
7714 "-> Failed load firmware fragment %u.\n",
7716 return QLA_FUNCTION_FAILED;
7725 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7728 templates = (risc_attr & BIT_9) ? 2 : 1;
7729 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7730 for (j = 0; j < templates; j++, fwdt++) {
7732 vfree(fwdt->template);
7733 fwdt->template = NULL;
7736 dcode = (void *)req->ring;
7737 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7738 risc_size = be32_to_cpu(dcode[2]);
7739 ql_dbg(ql_dbg_init, vha, 0x0161,
7740 "-> fwdt%u template array at %#x (%#x dwords)\n",
7741 j, faddr, risc_size);
7742 if (!risc_size || !~risc_size) {
7743 ql_dbg(ql_dbg_init, vha, 0x0162,
7744 "-> fwdt%u failed to read array\n", j);
7748 /* skip header and ignore checksum */
7752 ql_dbg(ql_dbg_init, vha, 0x0163,
7753 "-> fwdt%u template allocate template %#x words...\n",
7755 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7756 if (!fwdt->template) {
7757 ql_log(ql_log_warn, vha, 0x0164,
7758 "-> fwdt%u failed allocate template.\n", j);
7762 dcode = fwdt->template;
7763 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7765 if (!qla27xx_fwdt_template_valid(dcode)) {
7766 ql_log(ql_log_warn, vha, 0x0165,
7767 "-> fwdt%u failed template validate\n", j);
7771 dlen = qla27xx_fwdt_template_size(dcode);
7772 ql_dbg(ql_dbg_init, vha, 0x0166,
7773 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7774 j, dlen, dlen / sizeof(*dcode));
7775 if (dlen > risc_size * sizeof(*dcode)) {
7776 ql_log(ql_log_warn, vha, 0x0167,
7777 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7778 j, dlen - risc_size * sizeof(*dcode));
7782 fwdt->length = dlen;
7783 ql_dbg(ql_dbg_init, vha, 0x0168,
7784 "-> fwdt%u loaded template ok\n", j);
7786 faddr += risc_size + 1;
7793 vfree(fwdt->template);
7794 fwdt->template = NULL;
7800 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7803 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7807 uint16_t *wcode, *fwcode;
7808 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7809 struct fw_blob *blob;
7810 struct qla_hw_data *ha = vha->hw;
7811 struct req_que *req = ha->req_q_map[0];
7813 /* Load firmware blob. */
7814 blob = qla2x00_request_firmware(vha);
7816 ql_log(ql_log_info, vha, 0x0083,
7817 "Firmware image unavailable.\n");
7818 ql_log(ql_log_info, vha, 0x0084,
7819 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7820 return QLA_FUNCTION_FAILED;
7825 wcode = (uint16_t *)req->ring;
7827 fwcode = (uint16_t *)blob->fw->data;
7830 /* Validate firmware image by checking version. */
7831 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7832 ql_log(ql_log_fatal, vha, 0x0085,
7833 "Unable to verify integrity of firmware image (%zd).\n",
7835 goto fail_fw_integrity;
7837 for (i = 0; i < 4; i++)
7838 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7839 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7840 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7841 wcode[2] == 0 && wcode[3] == 0)) {
7842 ql_log(ql_log_fatal, vha, 0x0086,
7843 "Unable to verify integrity of firmware image.\n");
7844 ql_log(ql_log_fatal, vha, 0x0087,
7845 "Firmware data: %04x %04x %04x %04x.\n",
7846 wcode[0], wcode[1], wcode[2], wcode[3]);
7847 goto fail_fw_integrity;
7851 while (*seg && rval == QLA_SUCCESS) {
7853 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7854 risc_size = be16_to_cpu(fwcode[3]);
7856 /* Validate firmware image size. */
7857 fwclen += risc_size * sizeof(uint16_t);
7858 if (blob->fw->size < fwclen) {
7859 ql_log(ql_log_fatal, vha, 0x0088,
7860 "Unable to verify integrity of firmware image "
7861 "(%zd).\n", blob->fw->size);
7862 goto fail_fw_integrity;
7866 while (risc_size > 0 && rval == QLA_SUCCESS) {
7867 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7868 if (wlen > risc_size)
7870 ql_dbg(ql_dbg_init, vha, 0x0089,
7871 "Loading risc segment@ risc addr %x number of "
7872 "words 0x%x.\n", risc_addr, wlen);
7874 for (i = 0; i < wlen; i++)
7875 wcode[i] = swab16(fwcode[i]);
7877 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7880 ql_log(ql_log_fatal, vha, 0x008a,
7881 "Failed to load segment %d of firmware.\n",
7898 return QLA_FUNCTION_FAILED;
7902 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7905 uint templates, segments, fragment;
7908 uint32_t risc_addr, risc_size, risc_attr = 0;
7911 struct fw_blob *blob;
7913 struct qla_hw_data *ha = vha->hw;
7914 struct req_que *req = ha->req_q_map[0];
7915 struct fwdt *fwdt = ha->fwdt;
7917 ql_dbg(ql_dbg_init, vha, 0x0090,
7918 "-> FW: Loading via request-firmware.\n");
7920 blob = qla2x00_request_firmware(vha);
7922 ql_log(ql_log_warn, vha, 0x0092,
7923 "-> Firmware file not found.\n");
7925 return QLA_FUNCTION_FAILED;
7928 fwcode = (void *)blob->fw->data;
7930 if (qla24xx_risc_firmware_invalid(dcode)) {
7931 ql_log(ql_log_fatal, vha, 0x0093,
7932 "Unable to verify integrity of firmware image (%zd).\n",
7934 ql_log(ql_log_fatal, vha, 0x0095,
7935 "Firmware data: %08x %08x %08x %08x.\n",
7936 dcode[0], dcode[1], dcode[2], dcode[3]);
7937 return QLA_FUNCTION_FAILED;
7940 dcode = (void *)req->ring;
7942 segments = FA_RISC_CODE_SEGMENTS;
7943 for (j = 0; j < segments; j++) {
7944 ql_dbg(ql_dbg_init, vha, 0x0096,
7945 "-> Loading segment %u...\n", j);
7946 risc_addr = be32_to_cpu(fwcode[2]);
7947 risc_size = be32_to_cpu(fwcode[3]);
7950 *srisc_addr = risc_addr;
7951 risc_attr = be32_to_cpu(fwcode[9]);
7954 dlen = ha->fw_transfer_size >> 2;
7955 for (fragment = 0; risc_size; fragment++) {
7956 if (dlen > risc_size)
7959 ql_dbg(ql_dbg_init, vha, 0x0097,
7960 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7961 fragment, risc_addr,
7962 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7965 for (i = 0; i < dlen; i++)
7966 dcode[i] = swab32(fwcode[i]);
7968 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7970 ql_log(ql_log_fatal, vha, 0x0098,
7971 "-> Failed load firmware fragment %u.\n",
7973 return QLA_FUNCTION_FAILED;
7982 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7985 templates = (risc_attr & BIT_9) ? 2 : 1;
7986 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
7987 for (j = 0; j < templates; j++, fwdt++) {
7989 vfree(fwdt->template);
7990 fwdt->template = NULL;
7993 risc_size = be32_to_cpu(fwcode[2]);
7994 ql_dbg(ql_dbg_init, vha, 0x0171,
7995 "-> fwdt%u template array at %#x (%#x dwords)\n",
7996 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
7998 if (!risc_size || !~risc_size) {
7999 ql_dbg(ql_dbg_init, vha, 0x0172,
8000 "-> fwdt%u failed to read array\n", j);
8004 /* skip header and ignore checksum */
8008 ql_dbg(ql_dbg_init, vha, 0x0173,
8009 "-> fwdt%u template allocate template %#x words...\n",
8011 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8012 if (!fwdt->template) {
8013 ql_log(ql_log_warn, vha, 0x0174,
8014 "-> fwdt%u failed allocate template.\n", j);
8018 dcode = fwdt->template;
8019 for (i = 0; i < risc_size; i++)
8020 dcode[i] = fwcode[i];
8022 if (!qla27xx_fwdt_template_valid(dcode)) {
8023 ql_log(ql_log_warn, vha, 0x0175,
8024 "-> fwdt%u failed template validate\n", j);
8028 dlen = qla27xx_fwdt_template_size(dcode);
8029 ql_dbg(ql_dbg_init, vha, 0x0176,
8030 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8031 j, dlen, dlen / sizeof(*dcode));
8032 if (dlen > risc_size * sizeof(*dcode)) {
8033 ql_log(ql_log_warn, vha, 0x0177,
8034 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8035 j, dlen - risc_size * sizeof(*dcode));
8039 fwdt->length = dlen;
8040 ql_dbg(ql_dbg_init, vha, 0x0178,
8041 "-> fwdt%u loaded template ok\n", j);
8043 fwcode += risc_size + 1;
8050 vfree(fwdt->template);
8051 fwdt->template = NULL;
8058 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8062 if (ql2xfwloadbin == 1)
8063 return qla81xx_load_risc(vha, srisc_addr);
8067 * 1) Firmware via request-firmware interface (.bin file).
8068 * 2) Firmware residing in flash.
8070 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8071 if (rval == QLA_SUCCESS)
8074 return qla24xx_load_risc_flash(vha, srisc_addr,
8075 vha->hw->flt_region_fw);
8079 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8082 struct qla_hw_data *ha = vha->hw;
8083 struct active_regions active_regions = { };
8085 if (ql2xfwloadbin == 2)
8088 /* FW Load priority:
8089 * 1) Firmware residing in flash.
8090 * 2) Firmware via request-firmware interface (.bin file).
8091 * 3) Golden-Firmware residing in flash -- (limited operation).
8094 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8095 goto try_primary_fw;
8097 qla27xx_get_active_image(vha, &active_regions);
8099 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8100 goto try_primary_fw;
8102 ql_dbg(ql_dbg_init, vha, 0x008b,
8103 "Loading secondary firmware image.\n");
8104 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8109 ql_dbg(ql_dbg_init, vha, 0x008b,
8110 "Loading primary firmware image.\n");
8111 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8116 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8117 if (!rval || !ha->flt_region_gold_fw)
8120 ql_log(ql_log_info, vha, 0x0099,
8121 "Attempting to fallback to golden firmware.\n");
8122 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8126 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8127 ha->flags.running_gold_fw = 1;
8132 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8135 struct qla_hw_data *ha = vha->hw;
8137 if (ha->flags.pci_channel_io_perm_failure)
8139 if (!IS_FWI2_CAPABLE(ha))
8141 if (!ha->fw_major_version)
8143 if (!ha->flags.fw_started)
8146 ret = qla2x00_stop_firmware(vha);
8147 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8148 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8149 ha->isp_ops->reset_chip(vha);
8150 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8152 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8154 ql_log(ql_log_info, vha, 0x8015,
8155 "Attempting retry of stop-firmware command.\n");
8156 ret = qla2x00_stop_firmware(vha);
8160 ha->flags.fw_init_done = 0;
8164 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8166 int rval = QLA_SUCCESS;
8168 uint16_t mb[MAILBOX_REGISTER_COUNT];
8169 struct qla_hw_data *ha = vha->hw;
8170 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8175 rval = qla2x00_fw_ready(base_vha);
8177 if (rval == QLA_SUCCESS) {
8178 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8179 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8182 vha->flags.management_server_logged_in = 0;
8184 /* Login to SNS first */
8185 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8187 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8188 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8189 ql_dbg(ql_dbg_init, vha, 0x0120,
8190 "Failed SNS login: loop_id=%x, rval2=%d\n",
8193 ql_dbg(ql_dbg_init, vha, 0x0103,
8194 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8195 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8196 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8197 return (QLA_FUNCTION_FAILED);
8200 atomic_set(&vha->loop_down_timer, 0);
8201 atomic_set(&vha->loop_state, LOOP_UP);
8202 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8203 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8204 rval = qla2x00_loop_resync(base_vha);
8209 /* 84XX Support **************************************************************/
8211 static LIST_HEAD(qla_cs84xx_list);
8212 static DEFINE_MUTEX(qla_cs84xx_mutex);
8214 static struct qla_chip_state_84xx *
8215 qla84xx_get_chip(struct scsi_qla_host *vha)
8217 struct qla_chip_state_84xx *cs84xx;
8218 struct qla_hw_data *ha = vha->hw;
8220 mutex_lock(&qla_cs84xx_mutex);
8222 /* Find any shared 84xx chip. */
8223 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8224 if (cs84xx->bus == ha->pdev->bus) {
8225 kref_get(&cs84xx->kref);
8230 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8234 kref_init(&cs84xx->kref);
8235 spin_lock_init(&cs84xx->access_lock);
8236 mutex_init(&cs84xx->fw_update_mutex);
8237 cs84xx->bus = ha->pdev->bus;
8239 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8241 mutex_unlock(&qla_cs84xx_mutex);
8246 __qla84xx_chip_release(struct kref *kref)
8248 struct qla_chip_state_84xx *cs84xx =
8249 container_of(kref, struct qla_chip_state_84xx, kref);
8251 mutex_lock(&qla_cs84xx_mutex);
8252 list_del(&cs84xx->list);
8253 mutex_unlock(&qla_cs84xx_mutex);
8258 qla84xx_put_chip(struct scsi_qla_host *vha)
8260 struct qla_hw_data *ha = vha->hw;
8263 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8267 qla84xx_init_chip(scsi_qla_host_t *vha)
8271 struct qla_hw_data *ha = vha->hw;
8273 mutex_lock(&ha->cs84xx->fw_update_mutex);
8275 rval = qla84xx_verify_chip(vha, status);
8277 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8279 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8283 /* 81XX Support **************************************************************/
8286 qla81xx_nvram_config(scsi_qla_host_t *vha)
8289 struct init_cb_81xx *icb;
8290 struct nvram_81xx *nv;
8292 uint8_t *dptr1, *dptr2;
8295 struct qla_hw_data *ha = vha->hw;
8297 struct active_regions active_regions = { };
8300 icb = (struct init_cb_81xx *)ha->init_cb;
8303 /* Determine NVRAM starting address. */
8304 ha->nvram_size = sizeof(*nv);
8305 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8306 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8307 ha->vpd_size = FA_VPD_SIZE_82XX;
8309 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8310 qla28xx_get_aux_images(vha, &active_regions);
8312 /* Get VPD data into cache */
8313 ha->vpd = ha->nvram + VPD_OFFSET;
8315 faddr = ha->flt_region_vpd;
8316 if (IS_QLA28XX(ha)) {
8317 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8318 faddr = ha->flt_region_vpd_sec;
8319 ql_dbg(ql_dbg_init, vha, 0x0110,
8320 "Loading %s nvram image.\n",
8321 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8322 "primary" : "secondary");
8324 qla24xx_read_flash_data(vha, ha->vpd, faddr, ha->vpd_size >> 2);
8326 /* Get NVRAM data into cache and calculate checksum. */
8327 faddr = ha->flt_region_nvram;
8328 if (IS_QLA28XX(ha)) {
8329 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8330 faddr = ha->flt_region_nvram_sec;
8332 ql_dbg(ql_dbg_init, vha, 0x0110,
8333 "Loading %s nvram image.\n",
8334 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8335 "primary" : "secondary");
8336 qla24xx_read_flash_data(vha, ha->nvram, faddr, ha->nvram_size >> 2);
8338 dptr = (uint32_t *)nv;
8339 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8340 chksum += le32_to_cpu(*dptr);
8342 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8343 "Contents of NVRAM:\n");
8344 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8345 nv, ha->nvram_size);
8347 /* Bad NVRAM data, set defaults parameters. */
8348 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8349 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8350 /* Reset NVRAM data. */
8351 ql_log(ql_log_info, vha, 0x0073,
8352 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8353 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8354 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8355 ql_log(ql_log_info, vha, 0x0074,
8356 "Falling back to functioning (yet invalid -- WWPN) "
8360 * Set default initialization control block.
8362 memset(nv, 0, ha->nvram_size);
8363 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8364 nv->version = cpu_to_le16(ICB_VERSION);
8365 nv->frame_payload_size = 2048;
8366 nv->execution_throttle = cpu_to_le16(0xFFFF);
8367 nv->exchange_count = cpu_to_le16(0);
8368 nv->port_name[0] = 0x21;
8369 nv->port_name[1] = 0x00 + ha->port_no + 1;
8370 nv->port_name[2] = 0x00;
8371 nv->port_name[3] = 0xe0;
8372 nv->port_name[4] = 0x8b;
8373 nv->port_name[5] = 0x1c;
8374 nv->port_name[6] = 0x55;
8375 nv->port_name[7] = 0x86;
8376 nv->node_name[0] = 0x20;
8377 nv->node_name[1] = 0x00;
8378 nv->node_name[2] = 0x00;
8379 nv->node_name[3] = 0xe0;
8380 nv->node_name[4] = 0x8b;
8381 nv->node_name[5] = 0x1c;
8382 nv->node_name[6] = 0x55;
8383 nv->node_name[7] = 0x86;
8384 nv->login_retry_count = cpu_to_le16(8);
8385 nv->interrupt_delay_timer = cpu_to_le16(0);
8386 nv->login_timeout = cpu_to_le16(0);
8387 nv->firmware_options_1 =
8388 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8389 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8390 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8391 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8392 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8393 nv->efi_parameters = cpu_to_le32(0);
8394 nv->reset_delay = 5;
8395 nv->max_luns_per_target = cpu_to_le16(128);
8396 nv->port_down_retry_count = cpu_to_le16(30);
8397 nv->link_down_timeout = cpu_to_le16(180);
8398 nv->enode_mac[0] = 0x00;
8399 nv->enode_mac[1] = 0xC0;
8400 nv->enode_mac[2] = 0xDD;
8401 nv->enode_mac[3] = 0x04;
8402 nv->enode_mac[4] = 0x05;
8403 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8408 if (IS_T10_PI_CAPABLE(ha))
8409 nv->frame_payload_size &= ~7;
8411 qlt_81xx_config_nvram_stage1(vha, nv);
8413 /* Reset Initialization control block */
8414 memset(icb, 0, ha->init_cb_size);
8416 /* Copy 1st segment. */
8417 dptr1 = (uint8_t *)icb;
8418 dptr2 = (uint8_t *)&nv->version;
8419 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8421 *dptr1++ = *dptr2++;
8423 icb->login_retry_count = nv->login_retry_count;
8425 /* Copy 2nd segment. */
8426 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8427 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8428 cnt = (uint8_t *)&icb->reserved_5 -
8429 (uint8_t *)&icb->interrupt_delay_timer;
8431 *dptr1++ = *dptr2++;
8433 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8434 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8435 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8436 icb->enode_mac[0] = 0x00;
8437 icb->enode_mac[1] = 0xC0;
8438 icb->enode_mac[2] = 0xDD;
8439 icb->enode_mac[3] = 0x04;
8440 icb->enode_mac[4] = 0x05;
8441 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8444 /* Use extended-initialization control block. */
8445 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8446 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8448 * Setup driver NVRAM options.
8450 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8453 qlt_81xx_config_nvram_stage2(vha, icb);
8455 /* Use alternate WWN? */
8456 if (nv->host_p & cpu_to_le32(BIT_15)) {
8457 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8458 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8461 /* Prepare nodename */
8462 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8464 * Firmware will apply the following mask if the nodename was
8467 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8468 icb->node_name[0] &= 0xF0;
8471 /* Set host adapter parameters. */
8472 ha->flags.disable_risc_code_load = 0;
8473 ha->flags.enable_lip_reset = 0;
8474 ha->flags.enable_lip_full_login =
8475 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8476 ha->flags.enable_target_reset =
8477 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8478 ha->flags.enable_led_scheme = 0;
8479 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8481 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8482 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8484 /* save HBA serial number */
8485 ha->serial0 = icb->port_name[5];
8486 ha->serial1 = icb->port_name[6];
8487 ha->serial2 = icb->port_name[7];
8488 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8489 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8491 icb->execution_throttle = cpu_to_le16(0xFFFF);
8493 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8495 /* Set minimum login_timeout to 4 seconds. */
8496 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8497 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8498 if (le16_to_cpu(nv->login_timeout) < 4)
8499 nv->login_timeout = cpu_to_le16(4);
8500 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8502 /* Set minimum RATOV to 100 tenths of a second. */
8505 ha->loop_reset_delay = nv->reset_delay;
8507 /* Link Down Timeout = 0:
8509 * When Port Down timer expires we will start returning
8510 * I/O's to OS with "DID_NO_CONNECT".
8512 * Link Down Timeout != 0:
8514 * The driver waits for the link to come up after link down
8515 * before returning I/Os to OS with "DID_NO_CONNECT".
8517 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8518 ha->loop_down_abort_time =
8519 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8521 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8522 ha->loop_down_abort_time =
8523 (LOOP_DOWN_TIME - ha->link_down_timeout);
8526 /* Need enough time to try and get the port back. */
8527 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8528 if (qlport_down_retry)
8529 ha->port_down_retry_count = qlport_down_retry;
8531 /* Set login_retry_count */
8532 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8533 if (ha->port_down_retry_count ==
8534 le16_to_cpu(nv->port_down_retry_count) &&
8535 ha->port_down_retry_count > 3)
8536 ha->login_retry_count = ha->port_down_retry_count;
8537 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8538 ha->login_retry_count = ha->port_down_retry_count;
8539 if (ql2xloginretrycount)
8540 ha->login_retry_count = ql2xloginretrycount;
8542 /* if not running MSI-X we need handshaking on interrupts */
8543 if (!vha->hw->flags.msix_enabled &&
8544 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8545 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8548 if (!vha->flags.init_done) {
8549 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8550 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8551 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8552 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8554 icb->firmware_options_2 &= cpu_to_le32(
8555 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8556 vha->flags.process_response_queue = 0;
8557 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8558 ha->zio_mode = QLA_ZIO_MODE_6;
8560 ql_log(ql_log_info, vha, 0x0075,
8561 "ZIO mode %d enabled; timer delay (%d us).\n",
8563 ha->zio_timer * 100);
8565 icb->firmware_options_2 |= cpu_to_le32(
8566 (uint32_t)ha->zio_mode);
8567 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8568 vha->flags.process_response_queue = 1;
8571 /* enable RIDA Format2 */
8572 icb->firmware_options_3 |= BIT_0;
8574 /* N2N: driver will initiate Login instead of FW */
8575 icb->firmware_options_3 |= BIT_8;
8578 ql_log(ql_log_warn, vha, 0x0076,
8579 "NVRAM configuration failed.\n");
8585 qla82xx_restart_isp(scsi_qla_host_t *vha)
8588 struct qla_hw_data *ha = vha->hw;
8589 struct scsi_qla_host *vp;
8590 unsigned long flags;
8592 status = qla2x00_init_rings(vha);
8594 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8595 ha->flags.chip_reset_done = 1;
8597 status = qla2x00_fw_ready(vha);
8599 /* Issue a marker after FW becomes ready. */
8600 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8601 vha->flags.online = 1;
8602 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8605 /* if no cable then assume it's good */
8606 if ((vha->device_flags & DFLG_NO_CABLE))
8611 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8613 if (!atomic_read(&vha->loop_down_timer)) {
8615 * Issue marker command only when we are going
8616 * to start the I/O .
8618 vha->marker_needed = 1;
8621 ha->isp_ops->enable_intrs(ha);
8623 ha->isp_abort_cnt = 0;
8624 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8626 /* Update the firmware version */
8627 status = qla82xx_check_md_needed(vha);
8630 ha->flags.fce_enabled = 1;
8632 fce_calc_size(ha->fce_bufs));
8633 rval = qla2x00_enable_fce_trace(vha,
8634 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8637 ql_log(ql_log_warn, vha, 0x8001,
8638 "Unable to reinitialize FCE (%d).\n",
8640 ha->flags.fce_enabled = 0;
8645 memset(ha->eft, 0, EFT_SIZE);
8646 rval = qla2x00_enable_eft_trace(vha,
8647 ha->eft_dma, EFT_NUM_BUFFERS);
8649 ql_log(ql_log_warn, vha, 0x8010,
8650 "Unable to reinitialize EFT (%d).\n",
8657 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8658 "qla82xx_restart_isp succeeded.\n");
8660 spin_lock_irqsave(&ha->vport_slock, flags);
8661 list_for_each_entry(vp, &ha->vp_list, list) {
8663 atomic_inc(&vp->vref_count);
8664 spin_unlock_irqrestore(&ha->vport_slock, flags);
8666 qla2x00_vp_abort_isp(vp);
8668 spin_lock_irqsave(&ha->vport_slock, flags);
8669 atomic_dec(&vp->vref_count);
8672 spin_unlock_irqrestore(&ha->vport_slock, flags);
8675 ql_log(ql_log_warn, vha, 0x8016,
8676 "qla82xx_restart_isp **** FAILED ****.\n");
8683 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8685 struct qla_hw_data *ha = vha->hw;
8687 /* Hold status IOCBs until ABTS response received. */
8689 ha->fw_options[3] |= BIT_12;
8691 /* Set Retry FLOGI in case of P2P connection */
8692 if (ha->operating_mode == P2P) {
8693 ha->fw_options[2] |= BIT_3;
8694 ql_dbg(ql_dbg_disc, vha, 0x2103,
8695 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8696 __func__, ha->fw_options[2]);
8699 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8700 if (ql2xmvasynctoatio) {
8701 if (qla_tgt_mode_enabled(vha) ||
8702 qla_dual_mode_enabled(vha))
8703 ha->fw_options[2] |= BIT_11;
8705 ha->fw_options[2] &= ~BIT_11;
8708 if (qla_tgt_mode_enabled(vha) ||
8709 qla_dual_mode_enabled(vha)) {
8710 /* FW auto send SCSI status during */
8711 ha->fw_options[1] |= BIT_8;
8712 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8714 /* FW perform Exchange validation */
8715 ha->fw_options[2] |= BIT_4;
8717 ha->fw_options[1] &= ~BIT_8;
8718 ha->fw_options[10] &= 0x00ff;
8720 ha->fw_options[2] &= ~BIT_4;
8723 if (ql2xetsenable) {
8724 /* Enable ETS Burst. */
8725 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8726 ha->fw_options[2] |= BIT_9;
8729 ql_dbg(ql_dbg_init, vha, 0x00e9,
8730 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8731 __func__, ha->fw_options[1], ha->fw_options[2],
8732 ha->fw_options[3], vha->host->active_mode);
8734 qla2x00_set_fw_options(vha, ha->fw_options);
8738 * qla24xx_get_fcp_prio
8739 * Gets the fcp cmd priority value for the logged in port.
8740 * Looks for a match of the port descriptors within
8741 * each of the fcp prio config entries. If a match is found,
8742 * the tag (priority) value is returned.
8745 * vha = scsi host structure pointer.
8746 * fcport = port structure pointer.
8749 * non-zero (if found)
8756 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8759 uint8_t pid_match, wwn_match;
8761 uint32_t pid1, pid2;
8762 uint64_t wwn1, wwn2;
8763 struct qla_fcp_prio_entry *pri_entry;
8764 struct qla_hw_data *ha = vha->hw;
8766 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8770 entries = ha->fcp_prio_cfg->num_entries;
8771 pri_entry = &ha->fcp_prio_cfg->entry[0];
8773 for (i = 0; i < entries; i++) {
8774 pid_match = wwn_match = 0;
8776 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8781 /* check source pid for a match */
8782 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8783 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8784 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8785 if (pid1 == INVALID_PORT_ID)
8787 else if (pid1 == pid2)
8791 /* check destination pid for a match */
8792 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8793 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8794 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8795 if (pid1 == INVALID_PORT_ID)
8797 else if (pid1 == pid2)
8801 /* check source WWN for a match */
8802 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8803 wwn1 = wwn_to_u64(vha->port_name);
8804 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8805 if (wwn2 == (uint64_t)-1)
8807 else if (wwn1 == wwn2)
8811 /* check destination WWN for a match */
8812 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8813 wwn1 = wwn_to_u64(fcport->port_name);
8814 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8815 if (wwn2 == (uint64_t)-1)
8817 else if (wwn1 == wwn2)
8821 if (pid_match == 2 || wwn_match == 2) {
8822 /* Found a matching entry */
8823 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8824 priority = pri_entry->tag;
8835 * qla24xx_update_fcport_fcp_prio
8836 * Activates fcp priority for the logged in fc port
8839 * vha = scsi host structure pointer.
8840 * fcp = port structure pointer.
8843 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8849 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8855 if (fcport->port_type != FCT_TARGET ||
8856 fcport->loop_id == FC_NO_LOOP_ID)
8857 return QLA_FUNCTION_FAILED;
8859 priority = qla24xx_get_fcp_prio(vha, fcport);
8861 return QLA_FUNCTION_FAILED;
8863 if (IS_P3P_TYPE(vha->hw)) {
8864 fcport->fcp_prio = priority & 0xf;
8868 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8869 if (ret == QLA_SUCCESS) {
8870 if (fcport->fcp_prio != priority)
8871 ql_dbg(ql_dbg_user, vha, 0x709e,
8872 "Updated FCP_CMND priority - value=%d loop_id=%d "
8873 "port_id=%02x%02x%02x.\n", priority,
8874 fcport->loop_id, fcport->d_id.b.domain,
8875 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8876 fcport->fcp_prio = priority & 0xf;
8878 ql_dbg(ql_dbg_user, vha, 0x704f,
8879 "Unable to update FCP_CMND priority - ret=0x%x for "
8880 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8881 fcport->d_id.b.domain, fcport->d_id.b.area,
8882 fcport->d_id.b.al_pa);
8887 * qla24xx_update_all_fcp_prio
8888 * Activates fcp priority for all the logged in ports
8891 * ha = adapter block pointer.
8894 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8900 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8905 ret = QLA_FUNCTION_FAILED;
8906 /* We need to set priority for all logged in ports */
8907 list_for_each_entry(fcport, &vha->vp_fcports, list)
8908 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8913 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8914 int vp_idx, bool startqp)
8919 struct qla_hw_data *ha = vha->hw;
8920 uint16_t qpair_id = 0;
8921 struct qla_qpair *qpair = NULL;
8922 struct qla_msix_entry *msix;
8924 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8925 ql_log(ql_log_warn, vha, 0x00181,
8926 "FW/Driver is not multi-queue capable.\n");
8930 if (ql2xmqsupport || ql2xnvmeenable) {
8931 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8932 if (qpair == NULL) {
8933 ql_log(ql_log_warn, vha, 0x0182,
8934 "Failed to allocate memory for queue pair.\n");
8938 qpair->hw = vha->hw;
8940 qpair->qp_lock_ptr = &qpair->qp_lock;
8941 spin_lock_init(&qpair->qp_lock);
8942 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8944 /* Assign available que pair id */
8945 mutex_lock(&ha->mq_lock);
8946 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8947 if (ha->num_qpairs >= ha->max_qpairs) {
8948 mutex_unlock(&ha->mq_lock);
8949 ql_log(ql_log_warn, vha, 0x0183,
8950 "No resources to create additional q pair.\n");
8954 set_bit(qpair_id, ha->qpair_qid_map);
8955 ha->queue_pair_map[qpair_id] = qpair;
8956 qpair->id = qpair_id;
8957 qpair->vp_idx = vp_idx;
8958 qpair->fw_started = ha->flags.fw_started;
8959 INIT_LIST_HEAD(&qpair->hints_list);
8960 qpair->chip_reset = ha->base_qpair->chip_reset;
8961 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8962 qpair->enable_explicit_conf =
8963 ha->base_qpair->enable_explicit_conf;
8965 for (i = 0; i < ha->msix_count; i++) {
8966 msix = &ha->msix_entries[i];
8970 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8971 "Vector %x selected for qpair\n", msix->vector);
8975 ql_log(ql_log_warn, vha, 0x0184,
8976 "Out of MSI-X vectors!.\n");
8980 qpair->msix->in_use = 1;
8981 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8982 qpair->pdev = ha->pdev;
8983 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
8984 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8986 mutex_unlock(&ha->mq_lock);
8988 /* Create response queue first */
8989 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8991 ql_log(ql_log_warn, vha, 0x0185,
8992 "Failed to create response queue.\n");
8996 qpair->rsp = ha->rsp_q_map[rsp_id];
8998 /* Create request queue */
8999 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9002 ql_log(ql_log_warn, vha, 0x0186,
9003 "Failed to create request queue.\n");
9007 qpair->req = ha->req_q_map[req_id];
9008 qpair->rsp->req = qpair->req;
9009 qpair->rsp->qpair = qpair;
9010 /* init qpair to this cpu. Will adjust at run time. */
9011 qla_cpu_update(qpair, smp_processor_id());
9013 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9014 if (ha->fw_attributes & BIT_4)
9015 qpair->difdix_supported = 1;
9018 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9019 if (!qpair->srb_mempool) {
9020 ql_log(ql_log_warn, vha, 0xd036,
9021 "Failed to create srb mempool for qpair %d\n",
9026 /* Mark as online */
9029 if (!vha->flags.qpairs_available)
9030 vha->flags.qpairs_available = 1;
9032 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9033 "Request/Response queue pair created, id %d\n",
9035 ql_dbg(ql_dbg_init, vha, 0x0187,
9036 "Request/Response queue pair created, id %d\n",
9043 qla25xx_delete_rsp_que(vha, qpair->rsp);
9045 mutex_lock(&ha->mq_lock);
9046 qpair->msix->in_use = 0;
9047 list_del(&qpair->qp_list_elem);
9048 if (list_empty(&vha->qp_list))
9049 vha->flags.qpairs_available = 0;
9051 ha->queue_pair_map[qpair_id] = NULL;
9052 clear_bit(qpair_id, ha->qpair_qid_map);
9054 mutex_unlock(&ha->mq_lock);
9060 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9062 int ret = QLA_FUNCTION_FAILED;
9063 struct qla_hw_data *ha = qpair->hw;
9065 qpair->delete_in_progress = 1;
9066 while (atomic_read(&qpair->ref_count))
9069 ret = qla25xx_delete_req_que(vha, qpair->req);
9070 if (ret != QLA_SUCCESS)
9073 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9074 if (ret != QLA_SUCCESS)
9077 mutex_lock(&ha->mq_lock);
9078 ha->queue_pair_map[qpair->id] = NULL;
9079 clear_bit(qpair->id, ha->qpair_qid_map);
9081 list_del(&qpair->qp_list_elem);
9082 if (list_empty(&vha->qp_list)) {
9083 vha->flags.qpairs_available = 0;
9084 vha->flags.qpairs_req_created = 0;
9085 vha->flags.qpairs_rsp_created = 0;
9087 mempool_destroy(qpair->srb_mempool);
9089 mutex_unlock(&ha->mq_lock);