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)
309 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
313 fcport->flags |= FCF_ASYNC_SENT;
314 fcport->logout_completed = 0;
316 fcport->disc_state = DSC_LOGIN_PEND;
317 sp->type = SRB_LOGIN_CMD;
319 sp->gen1 = fcport->rscn_gen;
320 sp->gen2 = fcport->login_gen;
322 lio = &sp->u.iocb_cmd;
323 lio->timeout = qla2x00_async_iocb_timeout;
324 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
326 sp->done = qla2x00_async_login_sp_done;
327 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
328 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
330 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
332 if (fcport->fc4f_nvme)
333 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
335 ql_dbg(ql_dbg_disc, vha, 0x2072,
336 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
337 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
338 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
339 fcport->login_retry);
341 rval = qla2x00_start_sp(sp);
342 if (rval != QLA_SUCCESS) {
343 fcport->flags |= FCF_LOGIN_NEEDED;
344 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
352 fcport->flags &= ~FCF_ASYNC_SENT;
354 fcport->flags &= ~FCF_ASYNC_ACTIVE;
359 qla2x00_async_logout_sp_done(void *ptr, int res)
363 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
364 sp->fcport->login_gen++;
365 qlt_logo_completion_handler(sp->fcport, res);
370 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
373 struct srb_iocb *lio;
374 int rval = QLA_FUNCTION_FAILED;
376 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
379 fcport->flags |= FCF_ASYNC_SENT;
380 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
384 sp->type = SRB_LOGOUT_CMD;
387 lio = &sp->u.iocb_cmd;
388 lio->timeout = qla2x00_async_iocb_timeout;
389 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
391 sp->done = qla2x00_async_logout_sp_done;
393 ql_dbg(ql_dbg_disc, vha, 0x2070,
394 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
395 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
396 fcport->d_id.b.area, fcport->d_id.b.al_pa,
399 rval = qla2x00_start_sp(sp);
400 if (rval != QLA_SUCCESS)
407 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
412 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
415 fcport->flags &= ~FCF_ASYNC_ACTIVE;
416 /* Don't re-login in target mode */
417 if (!fcport->tgt_session)
418 qla2x00_mark_device_lost(vha, fcport, 1, 0);
419 qlt_logo_completion_handler(fcport, data[0]);
423 qla2x00_async_prlo_sp_done(void *s, int res)
425 srb_t *sp = (srb_t *)s;
426 struct srb_iocb *lio = &sp->u.iocb_cmd;
427 struct scsi_qla_host *vha = sp->vha;
429 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
430 if (!test_bit(UNLOADING, &vha->dpc_flags))
431 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
437 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
440 struct srb_iocb *lio;
443 rval = QLA_FUNCTION_FAILED;
444 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
448 sp->type = SRB_PRLO_CMD;
451 lio = &sp->u.iocb_cmd;
452 lio->timeout = qla2x00_async_iocb_timeout;
453 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
455 sp->done = qla2x00_async_prlo_sp_done;
457 ql_dbg(ql_dbg_disc, vha, 0x2070,
458 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
459 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
460 fcport->d_id.b.area, fcport->d_id.b.al_pa);
462 rval = qla2x00_start_sp(sp);
463 if (rval != QLA_SUCCESS)
471 fcport->flags &= ~FCF_ASYNC_ACTIVE;
476 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
478 struct fc_port *fcport = ea->fcport;
480 ql_dbg(ql_dbg_disc, vha, 0x20d2,
481 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
482 __func__, fcport->port_name, fcport->disc_state,
483 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
484 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
486 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
487 ql_dbg(ql_dbg_disc, vha, 0x2066,
488 "%s %8phC: adisc fail: post delete\n",
489 __func__, ea->fcport->port_name);
490 /* deleted = 0 & logout_on_delete = force fw cleanup */
492 fcport->logout_on_delete = 1;
493 qlt_schedule_sess_for_deletion(ea->fcport);
497 if (ea->fcport->disc_state == DSC_DELETE_PEND)
500 if (ea->sp->gen2 != ea->fcport->login_gen) {
501 /* target side must have changed it. */
502 ql_dbg(ql_dbg_disc, vha, 0x20d3,
503 "%s %8phC generation changed\n",
504 __func__, ea->fcport->port_name);
506 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
507 qla_rscn_replay(fcport);
508 qlt_schedule_sess_for_deletion(fcport);
512 __qla24xx_handle_gpdb_event(vha, ea);
515 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
517 struct qla_work_evt *e;
519 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
521 return QLA_FUNCTION_FAILED;
523 e->u.fcport.fcport = fcport;
524 fcport->flags |= FCF_ASYNC_ACTIVE;
525 return qla2x00_post_work(vha, e);
529 qla2x00_async_adisc_sp_done(void *ptr, int res)
532 struct scsi_qla_host *vha = sp->vha;
534 struct srb_iocb *lio = &sp->u.iocb_cmd;
536 ql_dbg(ql_dbg_disc, vha, 0x2066,
537 "Async done-%s res %x %8phC\n",
538 sp->name, res, sp->fcport->port_name);
540 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
542 memset(&ea, 0, sizeof(ea));
543 ea.event = FCME_ADISC_DONE;
545 ea.data[0] = lio->u.logio.data[0];
546 ea.data[1] = lio->u.logio.data[1];
547 ea.iop[0] = lio->u.logio.iop[0];
548 ea.iop[1] = lio->u.logio.iop[1];
549 ea.fcport = sp->fcport;
552 qla2x00_fcport_event_handler(vha, &ea);
558 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
562 struct srb_iocb *lio;
563 int rval = QLA_FUNCTION_FAILED;
565 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
568 fcport->flags |= FCF_ASYNC_SENT;
569 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
573 sp->type = SRB_ADISC_CMD;
576 lio = &sp->u.iocb_cmd;
577 lio->timeout = qla2x00_async_iocb_timeout;
578 sp->gen1 = fcport->rscn_gen;
579 sp->gen2 = fcport->login_gen;
580 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
582 sp->done = qla2x00_async_adisc_sp_done;
583 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
584 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
586 ql_dbg(ql_dbg_disc, vha, 0x206f,
587 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
588 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
590 rval = qla2x00_start_sp(sp);
591 if (rval != QLA_SUCCESS)
599 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
600 qla2x00_post_async_adisc_work(vha, fcport, data);
604 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
606 struct qla_hw_data *ha = vha->hw;
608 if (IS_FWI2_CAPABLE(ha))
609 return loop_id > NPH_LAST_HANDLE;
611 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
612 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
616 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
617 * @vha: adapter state pointer.
618 * @dev: port structure pointer.
621 * qla2x00 local function return status code.
626 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
629 struct qla_hw_data *ha = vha->hw;
630 unsigned long flags = 0;
634 spin_lock_irqsave(&ha->vport_slock, flags);
636 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
637 if (dev->loop_id >= LOOPID_MAP_SIZE ||
638 qla2x00_is_reserved_id(vha, dev->loop_id)) {
639 dev->loop_id = FC_NO_LOOP_ID;
640 rval = QLA_FUNCTION_FAILED;
642 set_bit(dev->loop_id, ha->loop_id_map);
644 spin_unlock_irqrestore(&ha->vport_slock, flags);
646 if (rval == QLA_SUCCESS)
647 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
648 "Assigning new loopid=%x, portid=%x.\n",
649 dev->loop_id, dev->d_id.b24);
651 ql_log(ql_log_warn, dev->vha, 0x2087,
652 "No loop_id's available, portid=%x.\n",
658 void qla2x00_clear_loop_id(fc_port_t *fcport)
660 struct qla_hw_data *ha = fcport->vha->hw;
662 if (fcport->loop_id == FC_NO_LOOP_ID ||
663 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
666 clear_bit(fcport->loop_id, ha->loop_id_map);
667 fcport->loop_id = FC_NO_LOOP_ID;
670 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
671 struct event_arg *ea)
673 fc_port_t *fcport, *conflict_fcport;
674 struct get_name_list_extended *e;
675 u16 i, n, found = 0, loop_id;
679 u8 current_login_state;
682 ql_dbg(ql_dbg_disc, vha, 0xffff,
683 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
684 __func__, fcport->port_name, fcport->disc_state,
685 fcport->fw_login_state, ea->rc,
686 fcport->login_gen, fcport->last_login_gen,
687 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
689 if (fcport->disc_state == DSC_DELETE_PEND)
692 if (ea->rc) { /* rval */
693 if (fcport->login_retry == 0) {
694 ql_dbg(ql_dbg_disc, vha, 0x20de,
695 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
696 fcport->port_name, fcport->login_retry);
701 if (fcport->last_rscn_gen != fcport->rscn_gen) {
702 qla_rscn_replay(fcport);
703 qlt_schedule_sess_for_deletion(fcport);
705 } else if (fcport->last_login_gen != fcport->login_gen) {
706 ql_dbg(ql_dbg_disc, vha, 0x20e0,
707 "%s %8phC login gen changed\n",
708 __func__, fcport->port_name);
712 n = ea->data[0] / sizeof(struct get_name_list_extended);
714 ql_dbg(ql_dbg_disc, vha, 0x20e1,
715 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
716 __func__, __LINE__, fcport->port_name, n,
717 fcport->d_id.b.domain, fcport->d_id.b.area,
718 fcport->d_id.b.al_pa, fcport->loop_id);
720 for (i = 0; i < n; i++) {
722 wwn = wwn_to_u64(e->port_name);
723 id.b.domain = e->port_id[2];
724 id.b.area = e->port_id[1];
725 id.b.al_pa = e->port_id[0];
728 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
731 if (IS_SW_RESV_ADDR(id))
736 loop_id = le16_to_cpu(e->nport_handle);
737 loop_id = (loop_id & 0x7fff);
738 if (fcport->fc4f_nvme)
739 current_login_state = e->current_login_state >> 4;
741 current_login_state = e->current_login_state & 0xf;
744 ql_dbg(ql_dbg_disc, vha, 0x20e2,
745 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
746 __func__, fcport->port_name,
747 e->current_login_state, fcport->fw_login_state,
748 fcport->fc4f_nvme, id.b.domain, id.b.area, id.b.al_pa,
749 fcport->d_id.b.domain, fcport->d_id.b.area,
750 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
752 switch (fcport->disc_state) {
753 case DSC_DELETE_PEND:
757 if ((id.b24 != fcport->d_id.b24 &&
759 (fcport->loop_id != FC_NO_LOOP_ID &&
760 fcport->loop_id != loop_id)) {
761 ql_dbg(ql_dbg_disc, vha, 0x20e3,
762 "%s %d %8phC post del sess\n",
763 __func__, __LINE__, fcport->port_name);
764 qlt_schedule_sess_for_deletion(fcport);
770 fcport->loop_id = loop_id;
772 wwn = wwn_to_u64(fcport->port_name);
773 qlt_find_sess_invalidate_other(vha, wwn,
774 id, loop_id, &conflict_fcport);
776 if (conflict_fcport) {
778 * Another share fcport share the same loop_id &
779 * nport id. Conflict fcport needs to finish
780 * cleanup before this fcport can proceed to login.
782 conflict_fcport->conflict = fcport;
783 fcport->login_pause = 1;
786 switch (vha->hw->current_topology) {
788 switch (current_login_state) {
789 case DSC_LS_PRLI_COMP:
790 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
791 vha, 0x20e4, "%s %d %8phC post gpdb\n",
792 __func__, __LINE__, fcport->port_name);
794 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
795 fcport->port_type = FCT_INITIATOR;
797 fcport->port_type = FCT_TARGET;
798 data[0] = data[1] = 0;
799 qla2x00_post_async_adisc_work(vha, fcport,
802 case DSC_LS_PORT_UNAVAIL:
804 if (fcport->loop_id == FC_NO_LOOP_ID) {
805 qla2x00_find_new_loop_id(vha, fcport);
806 fcport->fw_login_state =
809 ql_dbg(ql_dbg_disc, vha, 0x20e5,
810 "%s %d %8phC\n", __func__, __LINE__,
812 qla24xx_fcport_handle_login(vha, fcport);
817 fcport->fw_login_state = current_login_state;
819 switch (current_login_state) {
820 case DSC_LS_PRLI_COMP:
821 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
822 fcport->port_type = FCT_INITIATOR;
824 fcport->port_type = FCT_TARGET;
826 data[0] = data[1] = 0;
827 qla2x00_post_async_adisc_work(vha, fcport,
830 case DSC_LS_PLOGI_COMP:
831 if (fcport_is_bigger(fcport)) {
832 /* local adapter is smaller */
833 if (fcport->loop_id != FC_NO_LOOP_ID)
834 qla2x00_clear_loop_id(fcport);
836 fcport->loop_id = loop_id;
837 qla24xx_fcport_handle_login(vha,
843 if (fcport_is_smaller(fcport)) {
844 /* local adapter is bigger */
845 if (fcport->loop_id != FC_NO_LOOP_ID)
846 qla2x00_clear_loop_id(fcport);
848 fcport->loop_id = loop_id;
849 qla24xx_fcport_handle_login(vha,
855 } /* switch (ha->current_topology) */
859 switch (vha->hw->current_topology) {
862 for (i = 0; i < n; i++) {
864 id.b.domain = e->port_id[0];
865 id.b.area = e->port_id[1];
866 id.b.al_pa = e->port_id[2];
868 loop_id = le16_to_cpu(e->nport_handle);
870 if (fcport->d_id.b24 == id.b24) {
872 qla2x00_find_fcport_by_wwpn(vha,
874 if (conflict_fcport) {
875 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
877 "%s %d %8phC post del sess\n",
879 conflict_fcport->port_name);
880 qlt_schedule_sess_for_deletion
885 * FW already picked this loop id for
888 if (fcport->loop_id == loop_id)
889 fcport->loop_id = FC_NO_LOOP_ID;
891 qla24xx_fcport_handle_login(vha, fcport);
894 fcport->disc_state = DSC_DELETED;
895 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
896 if (fcport->n2n_link_reset_cnt < 2) {
897 fcport->n2n_link_reset_cnt++;
899 * remote port is not sending PLOGI.
900 * Reset link to kick start his state
903 set_bit(N2N_LINK_RESET,
906 if (fcport->n2n_chip_reset < 1) {
907 ql_log(ql_log_info, vha, 0x705d,
908 "Chip reset to bring laser down");
909 set_bit(ISP_ABORT_NEEDED,
911 fcport->n2n_chip_reset++;
913 ql_log(ql_log_info, vha, 0x705d,
914 "Remote port %8ph is not coming back\n",
916 fcport->scan_state = 0;
919 qla2xxx_wake_dpc(vha);
922 * report port suppose to do PLOGI. Give him
923 * more time. FW will catch it.
925 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
935 qla24xx_async_gnl_sp_done(void *s, int res)
938 struct scsi_qla_host *vha = sp->vha;
940 struct fc_port *fcport = NULL, *tf;
941 u16 i, n = 0, loop_id;
943 struct get_name_list_extended *e;
948 ql_dbg(ql_dbg_disc, vha, 0x20e7,
949 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
950 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
951 sp->u.iocb_cmd.u.mbx.in_mb[2]);
953 if (res == QLA_FUNCTION_TIMEOUT)
956 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
957 memset(&ea, 0, sizeof(ea));
960 ea.event = FCME_GNL_DONE;
962 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
963 sizeof(struct get_name_list_extended)) {
964 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
965 sizeof(struct get_name_list_extended);
966 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
969 for (i = 0; i < n; i++) {
971 loop_id = le16_to_cpu(e->nport_handle);
972 /* mask out reserve bit */
973 loop_id = (loop_id & 0x7fff);
974 set_bit(loop_id, vha->hw->loop_id_map);
975 wwn = wwn_to_u64(e->port_name);
977 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
978 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
979 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
980 e->port_id[0], e->current_login_state, e->last_login_state,
984 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
988 if (!list_empty(&vha->gnl.fcports))
989 list_splice_init(&vha->gnl.fcports, &h);
990 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
992 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
993 list_del_init(&fcport->gnl_entry);
994 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
995 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
996 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
999 qla2x00_fcport_event_handler(vha, &ea);
1002 /* create new fcport if fw has knowledge of new sessions */
1003 for (i = 0; i < n; i++) {
1008 wwn = wwn_to_u64(e->port_name);
1011 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1012 if (!memcmp((u8 *)&wwn, fcport->port_name,
1019 id.b.domain = e->port_id[2];
1020 id.b.area = e->port_id[1];
1021 id.b.al_pa = e->port_id[0];
1024 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1025 ql_dbg(ql_dbg_disc, vha, 0x2065,
1026 "%s %d %8phC %06x post new sess\n",
1027 __func__, __LINE__, (u8 *)&wwn, id.b24);
1028 wwnn = wwn_to_u64(e->node_name);
1029 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1030 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
1034 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1036 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1041 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1044 struct srb_iocb *mbx;
1045 int rval = QLA_FUNCTION_FAILED;
1046 unsigned long flags;
1049 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1052 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1053 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1055 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1056 fcport->flags |= FCF_ASYNC_SENT;
1057 fcport->disc_state = DSC_GNL;
1058 fcport->last_rscn_gen = fcport->rscn_gen;
1059 fcport->last_login_gen = fcport->login_gen;
1061 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1062 if (vha->gnl.sent) {
1063 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1067 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1069 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1073 sp->type = SRB_MB_IOCB;
1074 sp->name = "gnlist";
1075 sp->gen1 = fcport->rscn_gen;
1076 sp->gen2 = fcport->login_gen;
1078 mbx = &sp->u.iocb_cmd;
1079 mbx->timeout = qla2x00_async_iocb_timeout;
1080 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1082 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1083 mb[0] = MBC_PORT_NODE_NAME_LIST;
1084 mb[1] = BIT_2 | BIT_3;
1085 mb[2] = MSW(vha->gnl.ldma);
1086 mb[3] = LSW(vha->gnl.ldma);
1087 mb[6] = MSW(MSD(vha->gnl.ldma));
1088 mb[7] = LSW(MSD(vha->gnl.ldma));
1089 mb[8] = vha->gnl.size;
1090 mb[9] = vha->vp_idx;
1092 sp->done = qla24xx_async_gnl_sp_done;
1094 ql_dbg(ql_dbg_disc, vha, 0x20da,
1095 "Async-%s - OUT WWPN %8phC hndl %x\n",
1096 sp->name, fcport->port_name, sp->handle);
1098 rval = qla2x00_start_sp(sp);
1099 if (rval != QLA_SUCCESS)
1106 fcport->flags &= ~FCF_ASYNC_SENT;
1111 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1113 struct qla_work_evt *e;
1115 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1117 return QLA_FUNCTION_FAILED;
1119 e->u.fcport.fcport = fcport;
1120 fcport->flags |= FCF_ASYNC_ACTIVE;
1121 return qla2x00_post_work(vha, e);
1125 void qla24xx_async_gpdb_sp_done(void *s, int res)
1128 struct scsi_qla_host *vha = sp->vha;
1129 struct qla_hw_data *ha = vha->hw;
1130 fc_port_t *fcport = sp->fcport;
1131 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1132 struct event_arg ea;
1134 ql_dbg(ql_dbg_disc, vha, 0x20db,
1135 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1136 sp->name, res, fcport->port_name, mb[1], mb[2]);
1138 if (res == QLA_FUNCTION_TIMEOUT) {
1139 dma_pool_free(sp->vha->hw->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1140 sp->u.iocb_cmd.u.mbx.in_dma);
1144 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1145 memset(&ea, 0, sizeof(ea));
1146 ea.event = FCME_GPDB_DONE;
1150 qla2x00_fcport_event_handler(vha, &ea);
1152 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1153 sp->u.iocb_cmd.u.mbx.in_dma);
1158 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1160 struct qla_work_evt *e;
1162 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1164 return QLA_FUNCTION_FAILED;
1166 e->u.fcport.fcport = fcport;
1168 return qla2x00_post_work(vha, e);
1172 qla2x00_async_prli_sp_done(void *ptr, int res)
1175 struct scsi_qla_host *vha = sp->vha;
1176 struct srb_iocb *lio = &sp->u.iocb_cmd;
1177 struct event_arg ea;
1179 ql_dbg(ql_dbg_disc, vha, 0x2129,
1180 "%s %8phC res %d \n", __func__,
1181 sp->fcport->port_name, res);
1183 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1185 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1186 memset(&ea, 0, sizeof(ea));
1187 ea.event = FCME_PRLI_DONE;
1188 ea.fcport = sp->fcport;
1189 ea.data[0] = lio->u.logio.data[0];
1190 ea.data[1] = lio->u.logio.data[1];
1191 ea.iop[0] = lio->u.logio.iop[0];
1192 ea.iop[1] = lio->u.logio.iop[1];
1195 qla2x00_fcport_event_handler(vha, &ea);
1202 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1205 struct srb_iocb *lio;
1206 int rval = QLA_FUNCTION_FAILED;
1208 if (!vha->flags.online)
1211 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1212 fcport->fw_login_state == DSC_LS_PRLI_PEND)
1215 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1219 fcport->flags |= FCF_ASYNC_SENT;
1220 fcport->logout_completed = 0;
1222 sp->type = SRB_PRLI_CMD;
1225 lio = &sp->u.iocb_cmd;
1226 lio->timeout = qla2x00_async_iocb_timeout;
1227 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1229 sp->done = qla2x00_async_prli_sp_done;
1230 lio->u.logio.flags = 0;
1232 if (fcport->fc4f_nvme)
1233 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1235 ql_dbg(ql_dbg_disc, vha, 0x211b,
1236 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1237 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1238 fcport->login_retry, fcport->fc4f_nvme ? "nvme" : "fc");
1240 rval = qla2x00_start_sp(sp);
1241 if (rval != QLA_SUCCESS) {
1242 fcport->flags |= FCF_LOGIN_NEEDED;
1243 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1251 fcport->flags &= ~FCF_ASYNC_SENT;
1255 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1257 struct qla_work_evt *e;
1259 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1261 return QLA_FUNCTION_FAILED;
1263 e->u.fcport.fcport = fcport;
1264 e->u.fcport.opt = opt;
1265 fcport->flags |= FCF_ASYNC_ACTIVE;
1266 return qla2x00_post_work(vha, e);
1269 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1272 struct srb_iocb *mbx;
1273 int rval = QLA_FUNCTION_FAILED;
1276 struct port_database_24xx *pd;
1277 struct qla_hw_data *ha = vha->hw;
1279 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1282 fcport->disc_state = DSC_GPDB;
1284 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1288 fcport->flags |= FCF_ASYNC_SENT;
1289 sp->type = SRB_MB_IOCB;
1291 sp->gen1 = fcport->rscn_gen;
1292 sp->gen2 = fcport->login_gen;
1294 mbx = &sp->u.iocb_cmd;
1295 mbx->timeout = qla2x00_async_iocb_timeout;
1296 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1298 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1300 ql_log(ql_log_warn, vha, 0xd043,
1301 "Failed to allocate port database structure.\n");
1305 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1306 mb[0] = MBC_GET_PORT_DATABASE;
1307 mb[1] = fcport->loop_id;
1308 mb[2] = MSW(pd_dma);
1309 mb[3] = LSW(pd_dma);
1310 mb[6] = MSW(MSD(pd_dma));
1311 mb[7] = LSW(MSD(pd_dma));
1312 mb[9] = vha->vp_idx;
1315 mbx->u.mbx.in = (void *)pd;
1316 mbx->u.mbx.in_dma = pd_dma;
1318 sp->done = qla24xx_async_gpdb_sp_done;
1320 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1321 "Async-%s %8phC hndl %x opt %x\n",
1322 sp->name, fcport->port_name, sp->handle, opt);
1324 rval = qla2x00_start_sp(sp);
1325 if (rval != QLA_SUCCESS)
1331 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1334 fcport->flags &= ~FCF_ASYNC_SENT;
1336 qla24xx_post_gpdb_work(vha, fcport, opt);
1341 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1343 unsigned long flags;
1345 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1346 ea->fcport->login_gen++;
1347 ea->fcport->deleted = 0;
1348 ea->fcport->logout_on_delete = 1;
1350 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1351 vha->fcport_count++;
1352 ea->fcport->login_succ = 1;
1354 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1355 qla24xx_sched_upd_fcport(ea->fcport);
1356 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1357 } else if (ea->fcport->login_succ) {
1359 * We have an existing session. A late RSCN delivery
1360 * must have triggered the session to be re-validate.
1361 * Session is still valid.
1363 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1364 "%s %d %8phC session revalidate success\n",
1365 __func__, __LINE__, ea->fcport->port_name);
1366 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1368 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1372 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1374 fc_port_t *fcport = ea->fcport;
1375 struct port_database_24xx *pd;
1376 struct srb *sp = ea->sp;
1379 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1381 fcport->flags &= ~FCF_ASYNC_SENT;
1383 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1384 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__, fcport->port_name,
1385 fcport->disc_state, pd->current_login_state, fcport->fc4f_nvme,
1388 if (fcport->disc_state == DSC_DELETE_PEND)
1391 if (fcport->fc4f_nvme)
1392 ls = pd->current_login_state >> 4;
1394 ls = pd->current_login_state & 0xf;
1396 if (ea->sp->gen2 != fcport->login_gen) {
1397 /* target side must have changed it. */
1399 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1400 "%s %8phC generation changed\n",
1401 __func__, fcport->port_name);
1403 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1404 qla_rscn_replay(fcport);
1405 qlt_schedule_sess_for_deletion(fcport);
1410 case PDS_PRLI_COMPLETE:
1411 __qla24xx_parse_gpdb(vha, fcport, pd);
1413 case PDS_PLOGI_PENDING:
1414 case PDS_PLOGI_COMPLETE:
1415 case PDS_PRLI_PENDING:
1416 case PDS_PRLI2_PENDING:
1417 /* Set discovery state back to GNL to Relogin attempt */
1418 if (qla_dual_mode_enabled(vha) ||
1419 qla_ini_mode_enabled(vha)) {
1420 fcport->disc_state = DSC_GNL;
1421 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1424 case PDS_LOGO_PENDING:
1425 case PDS_PORT_UNAVAILABLE:
1427 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1428 __func__, __LINE__, fcport->port_name);
1429 qlt_schedule_sess_for_deletion(fcport);
1432 __qla24xx_handle_gpdb_event(vha, ea);
1435 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1440 if (qla_tgt_mode_enabled(vha))
1443 if (qla_dual_mode_enabled(vha)) {
1444 if (N2N_TOPO(vha->hw)) {
1447 mywwn = wwn_to_u64(vha->port_name);
1448 wwn = wwn_to_u64(fcport->port_name);
1451 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1452 && time_after_eq(jiffies,
1453 fcport->plogi_nack_done_deadline))
1459 /* initiator mode */
1463 if (login && fcport->login_retry) {
1464 fcport->login_retry--;
1465 if (fcport->loop_id == FC_NO_LOOP_ID) {
1466 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1467 rc = qla2x00_find_new_loop_id(vha, fcport);
1469 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1470 "%s %d %8phC post del sess - out of loopid\n",
1471 __func__, __LINE__, fcport->port_name);
1472 fcport->scan_state = 0;
1473 qlt_schedule_sess_for_deletion(fcport);
1477 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1478 "%s %d %8phC post login\n",
1479 __func__, __LINE__, fcport->port_name);
1480 qla2x00_post_async_login_work(vha, fcport, NULL);
1484 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1490 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20d8,
1491 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1492 __func__, fcport->port_name, fcport->disc_state,
1493 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1494 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1495 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1497 if (fcport->scan_state != QLA_FCPORT_FOUND)
1500 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1501 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1502 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1505 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1506 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1507 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1512 /* for pure Target Mode. Login will not be initiated */
1513 if (vha->host->active_mode == MODE_TARGET)
1516 if (fcport->flags & FCF_ASYNC_SENT) {
1517 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1521 switch (fcport->disc_state) {
1523 wwn = wwn_to_u64(fcport->node_name);
1524 switch (vha->hw->current_topology) {
1526 if (fcport_is_smaller(fcport)) {
1527 /* this adapter is bigger */
1528 if (fcport->login_retry) {
1529 if (fcport->loop_id == FC_NO_LOOP_ID) {
1530 qla2x00_find_new_loop_id(vha,
1532 fcport->fw_login_state =
1533 DSC_LS_PORT_UNAVAIL;
1535 fcport->login_retry--;
1536 qla_post_els_plogi_work(vha, fcport);
1538 ql_log(ql_log_info, vha, 0x705d,
1539 "Unable to reach remote port %8phC",
1543 qla24xx_post_gnl_work(vha, fcport);
1548 ql_dbg(ql_dbg_disc, vha, 0xffff,
1549 "%s %d %8phC post GNNID\n",
1550 __func__, __LINE__, fcport->port_name);
1551 qla24xx_post_gnnid_work(vha, fcport);
1552 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1553 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1554 "%s %d %8phC post gnl\n",
1555 __func__, __LINE__, fcport->port_name);
1556 qla24xx_post_gnl_work(vha, fcport);
1558 qla_chk_n2n_b4_login(vha, fcport);
1565 switch (vha->hw->current_topology) {
1567 if ((fcport->current_login_state & 0xf) == 0x6) {
1568 ql_dbg(ql_dbg_disc, vha, 0x2118,
1569 "%s %d %8phC post GPDB work\n",
1570 __func__, __LINE__, fcport->port_name);
1571 fcport->chip_reset =
1572 vha->hw->base_qpair->chip_reset;
1573 qla24xx_post_gpdb_work(vha, fcport, 0);
1575 ql_dbg(ql_dbg_disc, vha, 0x2118,
1576 "%s %d %8phC post NVMe PRLI\n",
1577 __func__, __LINE__, fcport->port_name);
1578 qla24xx_post_prli_work(vha, fcport);
1582 if (fcport->login_pause) {
1583 fcport->last_rscn_gen = fcport->rscn_gen;
1584 fcport->last_login_gen = fcport->login_gen;
1585 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1588 qla_chk_n2n_b4_login(vha, fcport);
1593 case DSC_LOGIN_FAILED:
1594 if (N2N_TOPO(vha->hw))
1595 qla_chk_n2n_b4_login(vha, fcport);
1597 qlt_schedule_sess_for_deletion(fcport);
1600 case DSC_LOGIN_COMPLETE:
1601 /* recheck login state */
1602 data[0] = data[1] = 0;
1603 qla2x00_post_async_adisc_work(vha, fcport, data);
1606 case DSC_LOGIN_PEND:
1607 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1608 qla24xx_post_prli_work(vha, fcport);
1611 case DSC_UPD_FCPORT:
1612 sec = jiffies_to_msecs(jiffies -
1613 fcport->jiffies_at_registration)/1000;
1614 if (fcport->sec_since_registration < sec && sec &&
1616 fcport->sec_since_registration = sec;
1617 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1618 "%s %8phC - Slow Rport registration(%d Sec)\n",
1619 __func__, fcport->port_name, sec);
1622 if (fcport->next_disc_state != DSC_DELETE_PEND)
1623 fcport->next_disc_state = DSC_ADISC;
1624 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1634 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1635 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1637 struct qla_work_evt *e;
1639 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1641 return QLA_FUNCTION_FAILED;
1643 e->u.new_sess.id = *id;
1644 e->u.new_sess.pla = pla;
1645 e->u.new_sess.fc4_type = fc4_type;
1646 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1648 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1650 return qla2x00_post_work(vha, e);
1654 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1655 struct event_arg *ea)
1657 fc_port_t *fcport = ea->fcport;
1659 ql_dbg(ql_dbg_disc, vha, 0x2102,
1660 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1661 __func__, fcport->port_name, fcport->disc_state,
1662 fcport->fw_login_state, fcport->login_pause,
1663 fcport->deleted, fcport->conflict,
1664 fcport->last_rscn_gen, fcport->rscn_gen,
1665 fcport->last_login_gen, fcport->login_gen,
1668 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1669 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1672 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1673 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1674 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1679 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1680 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1681 __func__, __LINE__, fcport->port_name);
1686 qla24xx_fcport_handle_login(vha, fcport);
1690 static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1691 struct event_arg *ea)
1693 ql_dbg(ql_dbg_disc, vha, 0x2118,
1694 "%s %d %8phC post PRLI\n",
1695 __func__, __LINE__, ea->fcport->port_name);
1696 qla24xx_post_prli_work(vha, ea->fcport);
1699 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1703 switch (ea->event) {
1705 if (test_bit(UNLOADING, &vha->dpc_flags))
1708 qla24xx_handle_relogin_event(vha, ea);
1711 if (test_bit(UNLOADING, &vha->dpc_flags))
1714 unsigned long flags;
1716 fcport = qla2x00_find_fcport_by_nportid
1719 fcport->scan_needed = 1;
1723 spin_lock_irqsave(&vha->work_lock, flags);
1724 if (vha->scan.scan_flags == 0) {
1725 ql_dbg(ql_dbg_disc, vha, 0xffff,
1726 "%s: schedule\n", __func__);
1727 vha->scan.scan_flags |= SF_QUEUED;
1728 schedule_delayed_work(&vha->scan.scan_work, 5);
1730 spin_unlock_irqrestore(&vha->work_lock, flags);
1734 qla24xx_handle_gnl_done_event(vha, ea);
1736 case FCME_GPSC_DONE:
1737 qla24xx_handle_gpsc_event(vha, ea);
1739 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1740 qla24xx_handle_plogi_done_event(vha, ea);
1742 case FCME_PRLI_DONE:
1743 qla24xx_handle_prli_done_event(vha, ea);
1745 case FCME_GPDB_DONE:
1746 qla24xx_handle_gpdb_event(vha, ea);
1748 case FCME_GPNID_DONE:
1749 qla24xx_handle_gpnid_event(vha, ea);
1751 case FCME_GFFID_DONE:
1752 qla24xx_handle_gffid_event(vha, ea);
1754 case FCME_ADISC_DONE:
1755 qla24xx_handle_adisc_event(vha, ea);
1757 case FCME_GNNID_DONE:
1758 qla24xx_handle_gnnid_event(vha, ea);
1760 case FCME_GFPNID_DONE:
1761 qla24xx_handle_gfpnid_event(vha, ea);
1763 case FCME_ELS_PLOGI_DONE:
1764 qla_handle_els_plogi_done(vha, ea);
1773 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1774 * to be consumed by the fcport
1776 void qla_rscn_replay(fc_port_t *fcport)
1778 struct event_arg ea;
1780 switch (fcport->disc_state) {
1781 case DSC_DELETE_PEND:
1787 if (fcport->scan_needed) {
1788 memset(&ea, 0, sizeof(ea));
1789 ea.event = FCME_RSCN;
1790 ea.id = fcport->d_id;
1791 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1792 qla2x00_fcport_event_handler(fcport->vha, &ea);
1797 qla2x00_tmf_iocb_timeout(void *data)
1800 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1802 tmf->u.tmf.comp_status = CS_TIMEOUT;
1803 complete(&tmf->u.tmf.comp);
1807 qla2x00_tmf_sp_done(void *ptr, int res)
1810 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1812 complete(&tmf->u.tmf.comp);
1816 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1819 struct scsi_qla_host *vha = fcport->vha;
1820 struct srb_iocb *tm_iocb;
1822 int rval = QLA_FUNCTION_FAILED;
1824 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1828 tm_iocb = &sp->u.iocb_cmd;
1829 sp->type = SRB_TM_CMD;
1832 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1833 init_completion(&tm_iocb->u.tmf.comp);
1834 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1836 tm_iocb->u.tmf.flags = flags;
1837 tm_iocb->u.tmf.lun = lun;
1838 tm_iocb->u.tmf.data = tag;
1839 sp->done = qla2x00_tmf_sp_done;
1841 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1842 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1843 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1844 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1846 rval = qla2x00_start_sp(sp);
1847 if (rval != QLA_SUCCESS)
1849 wait_for_completion(&tm_iocb->u.tmf.comp);
1851 rval = tm_iocb->u.tmf.data;
1853 if (rval != QLA_SUCCESS) {
1854 ql_log(ql_log_warn, vha, 0x8030,
1855 "TM IOCB failed (%x).\n", rval);
1858 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1859 flags = tm_iocb->u.tmf.flags;
1860 lun = (uint16_t)tm_iocb->u.tmf.lun;
1862 /* Issue Marker IOCB */
1863 qla2x00_marker(vha, vha->hw->base_qpair,
1864 fcport->loop_id, lun,
1865 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1870 fcport->flags &= ~FCF_ASYNC_SENT;
1876 qla24xx_async_abort_command(srb_t *sp)
1878 unsigned long flags = 0;
1881 fc_port_t *fcport = sp->fcport;
1882 struct qla_qpair *qpair = sp->qpair;
1883 struct scsi_qla_host *vha = fcport->vha;
1884 struct req_que *req = qpair->req;
1886 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1887 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1888 if (req->outstanding_cmds[handle] == sp)
1891 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1893 if (handle == req->num_outstanding_cmds) {
1894 /* Command not found. */
1895 return QLA_FUNCTION_FAILED;
1897 if (sp->type == SRB_FXIOCB_DCMD)
1898 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1899 FXDISC_ABORT_IOCTL);
1901 return qla24xx_async_abort_cmd(sp, true);
1905 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1907 switch (ea->data[0]) {
1908 case MBS_COMMAND_COMPLETE:
1909 ql_dbg(ql_dbg_disc, vha, 0x2118,
1910 "%s %d %8phC post gpdb\n",
1911 __func__, __LINE__, ea->fcport->port_name);
1913 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1914 ea->fcport->logout_on_delete = 1;
1915 ea->fcport->nvme_prli_service_param = ea->iop[0];
1916 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1917 ea->fcport->nvme_first_burst_size =
1918 (ea->iop[1] & 0xffff) * 512;
1920 ea->fcport->nvme_first_burst_size = 0;
1921 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1924 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1925 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1926 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1927 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1931 if (ea->fcport->n2n_flag) {
1932 ql_dbg(ql_dbg_disc, vha, 0x2118,
1933 "%s %d %8phC post fc4 prli\n",
1934 __func__, __LINE__, ea->fcport->port_name);
1935 ea->fcport->fc4f_nvme = 0;
1936 ea->fcport->n2n_flag = 0;
1937 qla24xx_post_prli_work(vha, ea->fcport);
1939 ql_dbg(ql_dbg_disc, vha, 0x2119,
1940 "%s %d %8phC unhandle event of %x\n",
1941 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1947 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1949 port_id_t cid; /* conflict Nport id */
1951 struct fc_port *conflict_fcport;
1952 unsigned long flags;
1953 struct fc_port *fcport = ea->fcport;
1955 ql_dbg(ql_dbg_disc, vha, 0xffff,
1956 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1957 __func__, fcport->port_name, fcport->disc_state,
1958 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1959 ea->sp->gen1, fcport->rscn_gen,
1960 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1962 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1963 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1964 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1965 "%s %d %8phC Remote is trying to login\n",
1966 __func__, __LINE__, fcport->port_name);
1970 if (fcport->disc_state == DSC_DELETE_PEND)
1973 if (ea->sp->gen2 != fcport->login_gen) {
1974 /* target side must have changed it. */
1975 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1976 "%s %8phC generation changed\n",
1977 __func__, fcport->port_name);
1978 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1980 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1981 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1982 "%s %8phC RSCN generation changed\n",
1983 __func__, fcport->port_name);
1984 qla_rscn_replay(fcport);
1985 qlt_schedule_sess_for_deletion(fcport);
1989 switch (ea->data[0]) {
1990 case MBS_COMMAND_COMPLETE:
1992 * Driver must validate login state - If PRLI not complete,
1993 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1996 if (ea->fcport->fc4f_nvme) {
1997 ql_dbg(ql_dbg_disc, vha, 0x2117,
1998 "%s %d %8phC post prli\n",
1999 __func__, __LINE__, ea->fcport->port_name);
2000 qla24xx_post_prli_work(vha, ea->fcport);
2002 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2003 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
2004 __func__, __LINE__, ea->fcport->port_name,
2005 ea->fcport->loop_id, ea->fcport->d_id.b24);
2007 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2008 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2009 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2010 ea->fcport->logout_on_delete = 1;
2011 ea->fcport->send_els_logo = 0;
2012 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2013 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2015 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2018 case MBS_COMMAND_ERROR:
2019 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2020 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2022 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2023 ea->fcport->disc_state = DSC_LOGIN_FAILED;
2024 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2025 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2027 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2029 case MBS_LOOP_ID_USED:
2030 /* data[1] = IO PARAM 1 = nport ID */
2031 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2032 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2033 cid.b.al_pa = ea->iop[1] & 0xff;
2036 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2037 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2038 __func__, __LINE__, ea->fcport->port_name,
2039 ea->fcport->loop_id, cid.b24);
2041 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2042 ea->fcport->loop_id = FC_NO_LOOP_ID;
2043 qla24xx_post_gnl_work(vha, ea->fcport);
2045 case MBS_PORT_ID_USED:
2046 lid = ea->iop[1] & 0xffff;
2047 qlt_find_sess_invalidate_other(vha,
2048 wwn_to_u64(ea->fcport->port_name),
2049 ea->fcport->d_id, lid, &conflict_fcport);
2051 if (conflict_fcport) {
2053 * Another fcport share the same loop_id/nport id.
2054 * Conflict fcport needs to finish cleanup before this
2055 * fcport can proceed to login.
2057 conflict_fcport->conflict = ea->fcport;
2058 ea->fcport->login_pause = 1;
2060 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2061 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2062 __func__, __LINE__, ea->fcport->port_name,
2063 ea->fcport->d_id.b24, lid);
2065 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2066 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2067 __func__, __LINE__, ea->fcport->port_name,
2068 ea->fcport->d_id.b24, lid);
2070 qla2x00_clear_loop_id(ea->fcport);
2071 set_bit(lid, vha->hw->loop_id_map);
2072 ea->fcport->loop_id = lid;
2073 ea->fcport->keep_nport_handle = 0;
2074 qlt_schedule_sess_for_deletion(ea->fcport);
2082 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2085 qlt_logo_completion_handler(fcport, data[0]);
2086 fcport->login_gen++;
2087 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2091 /****************************************************************************/
2092 /* QLogic ISP2x00 Hardware Support Functions. */
2093 /****************************************************************************/
2096 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2098 int rval = QLA_SUCCESS;
2099 struct qla_hw_data *ha = vha->hw;
2100 uint32_t idc_major_ver, idc_minor_ver;
2103 qla83xx_idc_lock(vha, 0);
2105 /* SV: TODO: Assign initialization timeout from
2106 * flash-info / other param
2108 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2109 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2111 /* Set our fcoe function presence */
2112 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2113 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2114 "Error while setting DRV-Presence.\n");
2115 rval = QLA_FUNCTION_FAILED;
2119 /* Decide the reset ownership */
2120 qla83xx_reset_ownership(vha);
2123 * On first protocol driver load:
2124 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2126 * Others: Check compatibility with current IDC Major version.
2128 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2129 if (ha->flags.nic_core_reset_owner) {
2130 /* Set IDC Major version */
2131 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2132 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2134 /* Clearing IDC-Lock-Recovery register */
2135 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2136 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2138 * Clear further IDC participation if we are not compatible with
2139 * the current IDC Major Version.
2141 ql_log(ql_log_warn, vha, 0xb07d,
2142 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2143 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2144 __qla83xx_clear_drv_presence(vha);
2145 rval = QLA_FUNCTION_FAILED;
2148 /* Each function sets its supported Minor version. */
2149 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2150 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2151 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2153 if (ha->flags.nic_core_reset_owner) {
2154 memset(config, 0, sizeof(config));
2155 if (!qla81xx_get_port_config(vha, config))
2156 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2160 rval = qla83xx_idc_state_handler(vha);
2163 qla83xx_idc_unlock(vha, 0);
2169 * qla2x00_initialize_adapter
2173 * ha = adapter block pointer.
2179 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2182 struct qla_hw_data *ha = vha->hw;
2183 struct req_que *req = ha->req_q_map[0];
2184 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2186 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2187 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2189 /* Clear adapter flags. */
2190 vha->flags.online = 0;
2191 ha->flags.chip_reset_done = 0;
2192 vha->flags.reset_active = 0;
2193 ha->flags.pci_channel_io_perm_failure = 0;
2194 ha->flags.eeh_busy = 0;
2195 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2196 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2197 atomic_set(&vha->loop_state, LOOP_DOWN);
2198 vha->device_flags = DFLG_NO_CABLE;
2200 vha->flags.management_server_logged_in = 0;
2201 vha->marker_needed = 0;
2202 ha->isp_abort_cnt = 0;
2203 ha->beacon_blink_led = 0;
2205 set_bit(0, ha->req_qid_map);
2206 set_bit(0, ha->rsp_qid_map);
2208 ql_dbg(ql_dbg_init, vha, 0x0040,
2209 "Configuring PCI space...\n");
2210 rval = ha->isp_ops->pci_config(vha);
2212 ql_log(ql_log_warn, vha, 0x0044,
2213 "Unable to configure PCI space.\n");
2217 ha->isp_ops->reset_chip(vha);
2219 /* Check for secure flash support */
2220 if (IS_QLA28XX(ha)) {
2221 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2222 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2223 ha->flags.secure_adapter = 1;
2228 rval = qla2xxx_get_flash_info(vha);
2230 ql_log(ql_log_fatal, vha, 0x004f,
2231 "Unable to validate FLASH data.\n");
2235 if (IS_QLA8044(ha)) {
2236 qla8044_read_reset_template(vha);
2238 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2239 * If DONRESET_BIT0 is set, drivers should not set dev_state
2240 * to NEED_RESET. But if NEED_RESET is set, drivers should
2241 * should honor the reset. */
2242 if (ql2xdontresethba == 1)
2243 qla8044_set_idc_dontreset(vha);
2246 ha->isp_ops->get_flash_version(vha, req->ring);
2247 ql_dbg(ql_dbg_init, vha, 0x0061,
2248 "Configure NVRAM parameters...\n");
2250 ha->isp_ops->nvram_config(vha);
2252 if (ha->flags.disable_serdes) {
2253 /* Mask HBA via NVRAM settings? */
2254 ql_log(ql_log_info, vha, 0x0077,
2255 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2256 return QLA_FUNCTION_FAILED;
2259 ql_dbg(ql_dbg_init, vha, 0x0078,
2260 "Verifying loaded RISC code...\n");
2262 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2263 rval = ha->isp_ops->chip_diag(vha);
2266 rval = qla2x00_setup_chip(vha);
2271 if (IS_QLA84XX(ha)) {
2272 ha->cs84xx = qla84xx_get_chip(vha);
2274 ql_log(ql_log_warn, vha, 0x00d0,
2275 "Unable to configure ISP84XX.\n");
2276 return QLA_FUNCTION_FAILED;
2280 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2281 rval = qla2x00_init_rings(vha);
2283 ha->flags.chip_reset_done = 1;
2285 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2286 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2287 rval = qla84xx_init_chip(vha);
2288 if (rval != QLA_SUCCESS) {
2289 ql_log(ql_log_warn, vha, 0x00d4,
2290 "Unable to initialize ISP84XX.\n");
2291 qla84xx_put_chip(vha);
2295 /* Load the NIC Core f/w if we are the first protocol driver. */
2296 if (IS_QLA8031(ha)) {
2297 rval = qla83xx_nic_core_fw_load(vha);
2299 ql_log(ql_log_warn, vha, 0x0124,
2300 "Error in initializing NIC Core f/w.\n");
2303 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2304 qla24xx_read_fcp_prio_cfg(vha);
2306 if (IS_P3P_TYPE(ha))
2307 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2309 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2315 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2318 * Returns 0 on success.
2321 qla2100_pci_config(scsi_qla_host_t *vha)
2324 unsigned long flags;
2325 struct qla_hw_data *ha = vha->hw;
2326 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2328 pci_set_master(ha->pdev);
2329 pci_try_set_mwi(ha->pdev);
2331 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2332 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2333 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2335 pci_disable_rom(ha->pdev);
2337 /* Get PCI bus information. */
2338 spin_lock_irqsave(&ha->hardware_lock, flags);
2339 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2340 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2346 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2349 * Returns 0 on success.
2352 qla2300_pci_config(scsi_qla_host_t *vha)
2355 unsigned long flags = 0;
2357 struct qla_hw_data *ha = vha->hw;
2358 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2360 pci_set_master(ha->pdev);
2361 pci_try_set_mwi(ha->pdev);
2363 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2364 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2366 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2367 w &= ~PCI_COMMAND_INTX_DISABLE;
2368 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2371 * If this is a 2300 card and not 2312, reset the
2372 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2373 * the 2310 also reports itself as a 2300 so we need to get the
2374 * fb revision level -- a 6 indicates it really is a 2300 and
2377 if (IS_QLA2300(ha)) {
2378 spin_lock_irqsave(&ha->hardware_lock, flags);
2381 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2382 for (cnt = 0; cnt < 30000; cnt++) {
2383 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2389 /* Select FPM registers. */
2390 WRT_REG_WORD(®->ctrl_status, 0x20);
2391 RD_REG_WORD(®->ctrl_status);
2393 /* Get the fb rev level */
2394 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2396 if (ha->fb_rev == FPM_2300)
2397 pci_clear_mwi(ha->pdev);
2399 /* Deselect FPM registers. */
2400 WRT_REG_WORD(®->ctrl_status, 0x0);
2401 RD_REG_WORD(®->ctrl_status);
2403 /* Release RISC module. */
2404 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2405 for (cnt = 0; cnt < 30000; cnt++) {
2406 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2412 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2415 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2417 pci_disable_rom(ha->pdev);
2419 /* Get PCI bus information. */
2420 spin_lock_irqsave(&ha->hardware_lock, flags);
2421 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2422 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2428 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2431 * Returns 0 on success.
2434 qla24xx_pci_config(scsi_qla_host_t *vha)
2437 unsigned long flags = 0;
2438 struct qla_hw_data *ha = vha->hw;
2439 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2441 pci_set_master(ha->pdev);
2442 pci_try_set_mwi(ha->pdev);
2444 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2445 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2446 w &= ~PCI_COMMAND_INTX_DISABLE;
2447 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2449 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2451 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2452 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2453 pcix_set_mmrbc(ha->pdev, 2048);
2455 /* PCIe -- adjust Maximum Read Request Size (2048). */
2456 if (pci_is_pcie(ha->pdev))
2457 pcie_set_readrq(ha->pdev, 4096);
2459 pci_disable_rom(ha->pdev);
2461 ha->chip_revision = ha->pdev->revision;
2463 /* Get PCI bus information. */
2464 spin_lock_irqsave(&ha->hardware_lock, flags);
2465 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2466 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2472 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2475 * Returns 0 on success.
2478 qla25xx_pci_config(scsi_qla_host_t *vha)
2481 struct qla_hw_data *ha = vha->hw;
2483 pci_set_master(ha->pdev);
2484 pci_try_set_mwi(ha->pdev);
2486 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2487 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2488 w &= ~PCI_COMMAND_INTX_DISABLE;
2489 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2491 /* PCIe -- adjust Maximum Read Request Size (2048). */
2492 if (pci_is_pcie(ha->pdev))
2493 pcie_set_readrq(ha->pdev, 4096);
2495 pci_disable_rom(ha->pdev);
2497 ha->chip_revision = ha->pdev->revision;
2503 * qla2x00_isp_firmware() - Choose firmware image.
2506 * Returns 0 on success.
2509 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2512 uint16_t loop_id, topo, sw_cap;
2513 uint8_t domain, area, al_pa;
2514 struct qla_hw_data *ha = vha->hw;
2516 /* Assume loading risc code */
2517 rval = QLA_FUNCTION_FAILED;
2519 if (ha->flags.disable_risc_code_load) {
2520 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2522 /* Verify checksum of loaded RISC code. */
2523 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2524 if (rval == QLA_SUCCESS) {
2525 /* And, verify we are not in ROM code. */
2526 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2527 &area, &domain, &topo, &sw_cap);
2532 ql_dbg(ql_dbg_init, vha, 0x007a,
2533 "**** Load RISC code ****.\n");
2539 * qla2x00_reset_chip() - Reset ISP chip.
2542 * Returns 0 on success.
2545 qla2x00_reset_chip(scsi_qla_host_t *vha)
2547 unsigned long flags = 0;
2548 struct qla_hw_data *ha = vha->hw;
2549 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2552 int rval = QLA_FUNCTION_FAILED;
2554 if (unlikely(pci_channel_offline(ha->pdev)))
2557 ha->isp_ops->disable_intrs(ha);
2559 spin_lock_irqsave(&ha->hardware_lock, flags);
2561 /* Turn off master enable */
2563 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2564 cmd &= ~PCI_COMMAND_MASTER;
2565 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2567 if (!IS_QLA2100(ha)) {
2569 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2570 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2571 for (cnt = 0; cnt < 30000; cnt++) {
2572 if ((RD_REG_WORD(®->hccr) &
2573 HCCR_RISC_PAUSE) != 0)
2578 RD_REG_WORD(®->hccr); /* PCI Posting. */
2582 /* Select FPM registers. */
2583 WRT_REG_WORD(®->ctrl_status, 0x20);
2584 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2586 /* FPM Soft Reset. */
2587 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2588 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2590 /* Toggle Fpm Reset. */
2591 if (!IS_QLA2200(ha)) {
2592 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2593 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2596 /* Select frame buffer registers. */
2597 WRT_REG_WORD(®->ctrl_status, 0x10);
2598 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2600 /* Reset frame buffer FIFOs. */
2601 if (IS_QLA2200(ha)) {
2602 WRT_FB_CMD_REG(ha, reg, 0xa000);
2603 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2605 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2607 /* Read back fb_cmd until zero or 3 seconds max */
2608 for (cnt = 0; cnt < 3000; cnt++) {
2609 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2615 /* Select RISC module registers. */
2616 WRT_REG_WORD(®->ctrl_status, 0);
2617 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2619 /* Reset RISC processor. */
2620 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2621 RD_REG_WORD(®->hccr); /* PCI Posting. */
2623 /* Release RISC processor. */
2624 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2625 RD_REG_WORD(®->hccr); /* PCI Posting. */
2628 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2629 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2631 /* Reset ISP chip. */
2632 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2634 /* Wait for RISC to recover from reset. */
2635 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2637 * It is necessary to for a delay here since the card doesn't
2638 * respond to PCI reads during a reset. On some architectures
2639 * this will result in an MCA.
2642 for (cnt = 30000; cnt; cnt--) {
2643 if ((RD_REG_WORD(®->ctrl_status) &
2644 CSR_ISP_SOFT_RESET) == 0)
2651 /* Reset RISC processor. */
2652 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2654 WRT_REG_WORD(®->semaphore, 0);
2656 /* Release RISC processor. */
2657 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2658 RD_REG_WORD(®->hccr); /* PCI Posting. */
2660 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2661 for (cnt = 0; cnt < 30000; cnt++) {
2662 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2670 /* Turn on master enable */
2671 cmd |= PCI_COMMAND_MASTER;
2672 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2674 /* Disable RISC pause on FPM parity error. */
2675 if (!IS_QLA2100(ha)) {
2676 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2677 RD_REG_WORD(®->hccr); /* PCI Posting. */
2680 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2686 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2689 * Returns 0 on success.
2692 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2694 uint16_t mb[4] = {0x1010, 0, 1, 0};
2696 if (!IS_QLA81XX(vha->hw))
2699 return qla81xx_write_mpi_register(vha, mb);
2703 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2706 * Returns 0 on success.
2709 qla24xx_reset_risc(scsi_qla_host_t *vha)
2711 unsigned long flags = 0;
2712 struct qla_hw_data *ha = vha->hw;
2713 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2716 static int abts_cnt; /* ISP abort retry counts */
2717 int rval = QLA_SUCCESS;
2719 spin_lock_irqsave(&ha->hardware_lock, flags);
2722 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2723 for (cnt = 0; cnt < 30000; cnt++) {
2724 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2730 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2731 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2733 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2734 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2735 RD_REG_DWORD(®->hccr),
2736 RD_REG_DWORD(®->ctrl_status),
2737 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2739 WRT_REG_DWORD(®->ctrl_status,
2740 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2741 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2745 /* Wait for firmware to complete NVRAM accesses. */
2746 RD_REG_WORD(®->mailbox0);
2747 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2748 rval == QLA_SUCCESS; cnt--) {
2753 rval = QLA_FUNCTION_TIMEOUT;
2756 if (rval == QLA_SUCCESS)
2757 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2759 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2760 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2761 RD_REG_DWORD(®->hccr),
2762 RD_REG_DWORD(®->mailbox0));
2764 /* Wait for soft-reset to complete. */
2765 RD_REG_DWORD(®->ctrl_status);
2766 for (cnt = 0; cnt < 60; cnt++) {
2768 if ((RD_REG_DWORD(®->ctrl_status) &
2769 CSRX_ISP_SOFT_RESET) == 0)
2774 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2775 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2777 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2778 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2779 RD_REG_DWORD(®->hccr),
2780 RD_REG_DWORD(®->ctrl_status));
2782 /* If required, do an MPI FW reset now */
2783 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2784 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2785 if (++abts_cnt < 5) {
2786 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2787 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2790 * We exhausted the ISP abort retries. We have to
2791 * set the board offline.
2794 vha->flags.online = 0;
2799 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2800 RD_REG_DWORD(®->hccr);
2802 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2803 RD_REG_DWORD(®->hccr);
2805 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2806 RD_REG_DWORD(®->hccr);
2808 RD_REG_WORD(®->mailbox0);
2809 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2810 rval == QLA_SUCCESS; cnt--) {
2815 rval = QLA_FUNCTION_TIMEOUT;
2817 if (rval == QLA_SUCCESS)
2818 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2820 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2821 "Host Risc 0x%x, mailbox0 0x%x\n",
2822 RD_REG_DWORD(®->hccr),
2823 RD_REG_WORD(®->mailbox0));
2825 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2827 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2828 "Driver in %s mode\n",
2829 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2831 if (IS_NOPOLLING_TYPE(ha))
2832 ha->isp_ops->enable_intrs(ha);
2838 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2840 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2842 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2843 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2848 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2850 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2852 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2853 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2857 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2860 uint delta_msec = 100;
2861 uint elapsed_msec = 0;
2865 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2866 vha->hw->pdev->subsystem_device != 0x0240)
2869 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2873 timeout_msec = TIMEOUT_SEMAPHORE;
2874 n = timeout_msec / delta_msec;
2876 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2877 qla25xx_read_risc_sema_reg(vha, &wd32);
2878 if (wd32 & RISC_SEMAPHORE)
2881 elapsed_msec += delta_msec;
2882 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2886 if (!(wd32 & RISC_SEMAPHORE))
2889 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2892 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2893 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2894 n = timeout_msec / delta_msec;
2896 qla25xx_read_risc_sema_reg(vha, &wd32);
2897 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2900 elapsed_msec += delta_msec;
2901 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2905 if (wd32 & RISC_SEMAPHORE_FORCE)
2906 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2911 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2918 * qla24xx_reset_chip() - Reset ISP24xx chip.
2921 * Returns 0 on success.
2924 qla24xx_reset_chip(scsi_qla_host_t *vha)
2926 struct qla_hw_data *ha = vha->hw;
2927 int rval = QLA_FUNCTION_FAILED;
2929 if (pci_channel_offline(ha->pdev) &&
2930 ha->flags.pci_channel_io_perm_failure) {
2934 ha->isp_ops->disable_intrs(ha);
2936 qla25xx_manipulate_risc_semaphore(vha);
2938 /* Perform RISC reset. */
2939 rval = qla24xx_reset_risc(vha);
2945 * qla2x00_chip_diag() - Test chip for proper operation.
2948 * Returns 0 on success.
2951 qla2x00_chip_diag(scsi_qla_host_t *vha)
2954 struct qla_hw_data *ha = vha->hw;
2955 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2956 unsigned long flags = 0;
2960 struct req_que *req = ha->req_q_map[0];
2962 /* Assume a failed state */
2963 rval = QLA_FUNCTION_FAILED;
2965 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2966 ®->flash_address);
2968 spin_lock_irqsave(&ha->hardware_lock, flags);
2970 /* Reset ISP chip. */
2971 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2974 * We need to have a delay here since the card will not respond while
2975 * in reset causing an MCA on some architectures.
2978 data = qla2x00_debounce_register(®->ctrl_status);
2979 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2981 data = RD_REG_WORD(®->ctrl_status);
2986 goto chip_diag_failed;
2988 ql_dbg(ql_dbg_init, vha, 0x007c,
2989 "Reset register cleared by chip reset.\n");
2991 /* Reset RISC processor. */
2992 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2993 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2995 /* Workaround for QLA2312 PCI parity error */
2996 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2997 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2998 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3000 data = RD_MAILBOX_REG(ha, reg, 0);
3007 goto chip_diag_failed;
3009 /* Check product ID of chip */
3010 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3012 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3013 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3014 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3015 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3016 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3017 mb[3] != PROD_ID_3) {
3018 ql_log(ql_log_warn, vha, 0x0062,
3019 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3020 mb[1], mb[2], mb[3]);
3022 goto chip_diag_failed;
3024 ha->product_id[0] = mb[1];
3025 ha->product_id[1] = mb[2];
3026 ha->product_id[2] = mb[3];
3027 ha->product_id[3] = mb[4];
3029 /* Adjust fw RISC transfer size */
3030 if (req->length > 1024)
3031 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3033 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3036 if (IS_QLA2200(ha) &&
3037 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3038 /* Limit firmware transfer size with a 2200A */
3039 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3041 ha->device_type |= DT_ISP2200A;
3042 ha->fw_transfer_size = 128;
3045 /* Wrap Incoming Mailboxes Test. */
3046 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3048 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3049 rval = qla2x00_mbx_reg_test(vha);
3051 ql_log(ql_log_warn, vha, 0x0080,
3052 "Failed mailbox send register test.\n");
3054 /* Flag a successful rval */
3056 spin_lock_irqsave(&ha->hardware_lock, flags);
3060 ql_log(ql_log_info, vha, 0x0081,
3061 "Chip diagnostics **** FAILED ****.\n");
3063 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3069 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3072 * Returns 0 on success.
3075 qla24xx_chip_diag(scsi_qla_host_t *vha)
3078 struct qla_hw_data *ha = vha->hw;
3079 struct req_que *req = ha->req_q_map[0];
3081 if (IS_P3P_TYPE(ha))
3084 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3086 rval = qla2x00_mbx_reg_test(vha);
3088 ql_log(ql_log_warn, vha, 0x0082,
3089 "Failed mailbox send register test.\n");
3091 /* Flag a successful rval */
3099 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3104 struct qla_hw_data *ha = vha->hw;
3107 ql_dbg(ql_dbg_init, vha, 0x00bd,
3108 "%s: Offload Mem is already allocated.\n",
3113 if (IS_FWI2_CAPABLE(ha)) {
3114 /* Allocate memory for Fibre Channel Event Buffer. */
3115 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3116 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3120 dma_free_coherent(&ha->pdev->dev,
3121 FCE_SIZE, ha->fce, ha->fce_dma);
3123 /* Allocate memory for Fibre Channel Event Buffer. */
3124 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3127 ql_log(ql_log_warn, vha, 0x00be,
3128 "Unable to allocate (%d KB) for FCE.\n",
3133 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3134 ha->fce_mb, &ha->fce_bufs);
3136 ql_log(ql_log_warn, vha, 0x00bf,
3137 "Unable to initialize FCE (%d).\n", rval);
3138 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3140 ha->flags.fce_enabled = 0;
3143 ql_dbg(ql_dbg_init, vha, 0x00c0,
3144 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3146 ha->flags.fce_enabled = 1;
3147 ha->fce_dma = tc_dma;
3152 dma_free_coherent(&ha->pdev->dev,
3153 EFT_SIZE, ha->eft, ha->eft_dma);
3155 /* Allocate memory for Extended Trace Buffer. */
3156 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3159 ql_log(ql_log_warn, vha, 0x00c1,
3160 "Unable to allocate (%d KB) for EFT.\n",
3165 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3167 ql_log(ql_log_warn, vha, 0x00c2,
3168 "Unable to initialize EFT (%d).\n", rval);
3169 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3173 ql_dbg(ql_dbg_init, vha, 0x00c3,
3174 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3176 ha->eft_dma = tc_dma;
3185 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3188 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3189 eft_size, fce_size, mq_size;
3190 struct qla_hw_data *ha = vha->hw;
3191 struct req_que *req = ha->req_q_map[0];
3192 struct rsp_que *rsp = ha->rsp_q_map[0];
3193 struct qla2xxx_fw_dump *fw_dump;
3197 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3198 req_q_size = rsp_q_size = 0;
3200 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3201 fixed_size = sizeof(struct qla2100_fw_dump);
3202 } else if (IS_QLA23XX(ha)) {
3203 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3204 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3206 } else if (IS_FWI2_CAPABLE(ha)) {
3207 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3208 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3209 else if (IS_QLA81XX(ha))
3210 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3211 else if (IS_QLA25XX(ha))
3212 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3214 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3216 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3219 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3221 mq_size = sizeof(struct qla2xxx_mq_chain);
3223 * Allocate maximum buffer size for all queues - Q0.
3224 * Resizing must be done at end-of-dump processing.
3226 mq_size += (ha->max_req_queues - 1) *
3227 (req->length * sizeof(request_t));
3228 mq_size += (ha->max_rsp_queues - 1) *
3229 (rsp->length * sizeof(response_t));
3231 if (ha->tgt.atio_ring)
3232 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3233 /* Allocate memory for Fibre Channel Event Buffer. */
3234 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3235 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3238 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3241 dma_free_coherent(&ha->pdev->dev,
3242 EFT_SIZE, ha->eft, ha->eft_dma);
3244 /* Allocate memory for Extended Trace Buffer. */
3245 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3248 ql_log(ql_log_warn, vha, 0x00c1,
3249 "Unable to allocate (%d KB) for EFT.\n",
3254 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3256 ql_log(ql_log_warn, vha, 0x00c2,
3257 "Unable to initialize EFT (%d).\n", rval);
3258 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3261 ql_dbg(ql_dbg_init, vha, 0x00c3,
3262 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3263 eft_size = EFT_SIZE;
3266 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3267 struct fwdt *fwdt = ha->fwdt;
3270 for (j = 0; j < 2; j++, fwdt++) {
3271 if (!fwdt->template) {
3272 ql_log(ql_log_warn, vha, 0x00ba,
3273 "-> fwdt%u no template\n", j);
3276 ql_dbg(ql_dbg_init, vha, 0x00fa,
3277 "-> fwdt%u calculating fwdump size...\n", j);
3278 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3279 vha, fwdt->template);
3280 ql_dbg(ql_dbg_init, vha, 0x00fa,
3281 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3282 j, fwdt->dump_size);
3283 dump_size += fwdt->dump_size;
3288 req_q_size = req->length * sizeof(request_t);
3289 rsp_q_size = rsp->length * sizeof(response_t);
3290 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3291 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3292 ha->chain_offset = dump_size;
3293 dump_size += mq_size + fce_size;
3295 if (ha->exchoffld_buf)
3296 dump_size += sizeof(struct qla2xxx_offld_chain) +
3298 if (ha->exlogin_buf)
3299 dump_size += sizeof(struct qla2xxx_offld_chain) +
3303 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3305 ql_dbg(ql_dbg_init, vha, 0x00c5,
3306 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3307 __func__, dump_size, ha->fw_dump_len,
3308 ha->fw_dump_alloc_len);
3310 fw_dump = vmalloc(dump_size);
3312 ql_log(ql_log_warn, vha, 0x00c4,
3313 "Unable to allocate (%d KB) for firmware dump.\n",
3316 mutex_lock(&ha->optrom_mutex);
3317 if (ha->fw_dumped) {
3318 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3320 ha->fw_dump = fw_dump;
3321 ha->fw_dump_alloc_len = dump_size;
3322 ql_dbg(ql_dbg_init, vha, 0x00c5,
3323 "Re-Allocated (%d KB) and save firmware dump.\n",
3328 ha->fw_dump = fw_dump;
3330 ha->fw_dump_len = ha->fw_dump_alloc_len =
3332 ql_dbg(ql_dbg_init, vha, 0x00c5,
3333 "Allocated (%d KB) for firmware dump.\n",
3336 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3337 mutex_unlock(&ha->optrom_mutex);
3341 ha->fw_dump->signature[0] = 'Q';
3342 ha->fw_dump->signature[1] = 'L';
3343 ha->fw_dump->signature[2] = 'G';
3344 ha->fw_dump->signature[3] = 'C';
3345 ha->fw_dump->version = htonl(1);
3347 ha->fw_dump->fixed_size = htonl(fixed_size);
3348 ha->fw_dump->mem_size = htonl(mem_size);
3349 ha->fw_dump->req_q_size = htonl(req_q_size);
3350 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3352 ha->fw_dump->eft_size = htonl(eft_size);
3353 ha->fw_dump->eft_addr_l =
3354 htonl(LSD(ha->eft_dma));
3355 ha->fw_dump->eft_addr_h =
3356 htonl(MSD(ha->eft_dma));
3358 ha->fw_dump->header_size =
3360 (struct qla2xxx_fw_dump, isp));
3362 mutex_unlock(&ha->optrom_mutex);
3368 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3370 #define MPS_MASK 0xe0
3375 if (!IS_QLA81XX(vha->hw))
3378 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3379 if (rval != QLA_SUCCESS) {
3380 ql_log(ql_log_warn, vha, 0x0105,
3381 "Unable to acquire semaphore.\n");
3385 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3386 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3387 if (rval != QLA_SUCCESS) {
3388 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3393 if (dc == (dw & MPS_MASK))
3398 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3399 if (rval != QLA_SUCCESS) {
3400 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3404 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3405 if (rval != QLA_SUCCESS) {
3406 ql_log(ql_log_warn, vha, 0x006d,
3407 "Unable to release semaphore.\n");
3415 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3417 /* Don't try to reallocate the array */
3418 if (req->outstanding_cmds)
3421 if (!IS_FWI2_CAPABLE(ha))
3422 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3424 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3425 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3427 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3430 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3434 if (!req->outstanding_cmds) {
3436 * Try to allocate a minimal size just so we can get through
3439 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3440 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3444 if (!req->outstanding_cmds) {
3445 ql_log(ql_log_fatal, NULL, 0x0126,
3446 "Failed to allocate memory for "
3447 "outstanding_cmds for req_que %p.\n", req);
3448 req->num_outstanding_cmds = 0;
3449 return QLA_FUNCTION_FAILED;
3456 #define PRINT_FIELD(_field, _flag, _str) { \
3457 if (a0->_field & _flag) {\
3463 len = snprintf(ptr, leftover, "%s", _str); \
3470 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3473 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3474 u8 str[STR_LEN], *ptr, p;
3477 memset(str, 0, STR_LEN);
3478 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3479 ql_dbg(ql_dbg_init, vha, 0x015a,
3480 "SFP MFG Name: %s\n", str);
3482 memset(str, 0, STR_LEN);
3483 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3484 ql_dbg(ql_dbg_init, vha, 0x015c,
3485 "SFP Part Name: %s\n", str);
3488 memset(str, 0, STR_LEN);
3492 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3493 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3494 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3495 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3496 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3497 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3498 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3499 ql_dbg(ql_dbg_init, vha, 0x0160,
3500 "SFP Media: %s\n", str);
3503 memset(str, 0, STR_LEN);
3507 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3508 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3509 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3510 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3511 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3512 ql_dbg(ql_dbg_init, vha, 0x0196,
3513 "SFP Link Length: %s\n", str);
3515 memset(str, 0, STR_LEN);
3519 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3520 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3521 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3522 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3523 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3524 ql_dbg(ql_dbg_init, vha, 0x016e,
3525 "SFP FC Link Tech: %s\n", str);
3528 ql_dbg(ql_dbg_init, vha, 0x016f,
3529 "SFP Distant: %d km\n", a0->length_km);
3530 if (a0->length_100m)
3531 ql_dbg(ql_dbg_init, vha, 0x0170,
3532 "SFP Distant: %d m\n", a0->length_100m*100);
3533 if (a0->length_50um_10m)
3534 ql_dbg(ql_dbg_init, vha, 0x0189,
3535 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3536 if (a0->length_62um_10m)
3537 ql_dbg(ql_dbg_init, vha, 0x018a,
3538 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3539 if (a0->length_om4_10m)
3540 ql_dbg(ql_dbg_init, vha, 0x0194,
3541 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3542 if (a0->length_om3_10m)
3543 ql_dbg(ql_dbg_init, vha, 0x0195,
3544 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3550 * QLA_SUCCESS: no action
3551 * QLA_INTERFACE_ERROR: SFP is not there.
3552 * QLA_FUNCTION_FAILED: detected New SFP
3555 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3557 int rc = QLA_SUCCESS;
3558 struct sff_8247_a0 *a;
3559 struct qla_hw_data *ha = vha->hw;
3561 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3564 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3568 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3569 qla2xxx_print_sfp_info(vha);
3571 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3573 ha->flags.detected_lr_sfp = 1;
3575 if (a->length_km > 5 || a->length_100m > 50)
3576 ha->long_range_distance = LR_DISTANCE_10K;
3578 ha->long_range_distance = LR_DISTANCE_5K;
3580 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3581 ql_dbg(ql_dbg_async, vha, 0x507b,
3582 "Detected Long Range SFP.\n");
3585 ha->flags.detected_lr_sfp = 0;
3586 if (ha->flags.using_lr_setting)
3587 ql_dbg(ql_dbg_async, vha, 0x5084,
3588 "Detected Short Range SFP.\n");
3591 if (!vha->flags.init_done)
3598 * qla2x00_setup_chip() - Load and start RISC firmware.
3601 * Returns 0 on success.
3604 qla2x00_setup_chip(scsi_qla_host_t *vha)
3607 uint32_t srisc_address = 0;
3608 struct qla_hw_data *ha = vha->hw;
3609 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3610 unsigned long flags;
3611 uint16_t fw_major_version;
3613 if (IS_P3P_TYPE(ha)) {
3614 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3615 if (rval == QLA_SUCCESS) {
3616 qla2x00_stop_firmware(vha);
3617 goto enable_82xx_npiv;
3622 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3623 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3624 spin_lock_irqsave(&ha->hardware_lock, flags);
3625 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3626 RD_REG_WORD(®->hccr);
3627 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3630 qla81xx_mpi_sync(vha);
3632 /* Load firmware sequences */
3633 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3634 if (rval == QLA_SUCCESS) {
3635 ql_dbg(ql_dbg_init, vha, 0x00c9,
3636 "Verifying Checksum of loaded RISC code.\n");
3638 rval = qla2x00_verify_checksum(vha, srisc_address);
3639 if (rval == QLA_SUCCESS) {
3640 /* Start firmware execution. */
3641 ql_dbg(ql_dbg_init, vha, 0x00ca,
3642 "Starting firmware.\n");
3645 ha->flags.exlogins_enabled = 1;
3647 if (qla_is_exch_offld_enabled(vha))
3648 ha->flags.exchoffld_enabled = 1;
3650 rval = qla2x00_execute_fw(vha, srisc_address);
3651 /* Retrieve firmware information. */
3652 if (rval == QLA_SUCCESS) {
3653 qla24xx_detect_sfp(vha);
3655 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3657 (ha->zio_mode == QLA_ZIO_MODE_6))
3658 qla27xx_set_zio_threshold(vha,
3659 ha->last_zio_threshold);
3661 rval = qla2x00_set_exlogins_buffer(vha);
3662 if (rval != QLA_SUCCESS)
3665 rval = qla2x00_set_exchoffld_buffer(vha);
3666 if (rval != QLA_SUCCESS)
3670 fw_major_version = ha->fw_major_version;
3671 if (IS_P3P_TYPE(ha))
3672 qla82xx_check_md_needed(vha);
3674 rval = qla2x00_get_fw_version(vha);
3675 if (rval != QLA_SUCCESS)
3677 ha->flags.npiv_supported = 0;
3678 if (IS_QLA2XXX_MIDTYPE(ha) &&
3679 (ha->fw_attributes & BIT_2)) {
3680 ha->flags.npiv_supported = 1;
3681 if ((!ha->max_npiv_vports) ||
3682 ((ha->max_npiv_vports + 1) %
3683 MIN_MULTI_ID_FABRIC))
3684 ha->max_npiv_vports =
3685 MIN_MULTI_ID_FABRIC - 1;
3687 qla2x00_get_resource_cnts(vha);
3690 * Allocate the array of outstanding commands
3691 * now that we know the firmware resources.
3693 rval = qla2x00_alloc_outstanding_cmds(ha,
3695 if (rval != QLA_SUCCESS)
3698 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3699 qla2x00_alloc_offload_mem(vha);
3701 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3702 qla2x00_alloc_fw_dump(vha);
3708 ql_log(ql_log_fatal, vha, 0x00cd,
3709 "ISP Firmware failed checksum.\n");
3715 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3716 /* Enable proper parity. */
3717 spin_lock_irqsave(&ha->hardware_lock, flags);
3720 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3722 /* SRAM, Instruction RAM and GP RAM parity */
3723 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3724 RD_REG_WORD(®->hccr);
3725 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3728 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3729 ha->flags.fac_supported = 1;
3730 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3733 rval = qla81xx_fac_get_sector_size(vha, &size);
3734 if (rval == QLA_SUCCESS) {
3735 ha->flags.fac_supported = 1;
3736 ha->fdt_block_size = size << 2;
3738 ql_log(ql_log_warn, vha, 0x00ce,
3739 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3740 ha->fw_major_version, ha->fw_minor_version,
3741 ha->fw_subminor_version);
3743 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3745 ha->flags.fac_supported = 0;
3752 ql_log(ql_log_fatal, vha, 0x00cf,
3753 "Setup chip ****FAILED****.\n");
3760 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3761 * @rsp: response queue
3763 * Beginning of request ring has initialization control block already built
3764 * by nvram config routine.
3766 * Returns 0 on success.
3769 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3774 rsp->ring_ptr = rsp->ring;
3775 rsp->ring_index = 0;
3776 rsp->status_srb = NULL;
3777 pkt = rsp->ring_ptr;
3778 for (cnt = 0; cnt < rsp->length; cnt++) {
3779 pkt->signature = RESPONSE_PROCESSED;
3785 * qla2x00_update_fw_options() - Read and process firmware options.
3788 * Returns 0 on success.
3791 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3793 uint16_t swing, emphasis, tx_sens, rx_sens;
3794 struct qla_hw_data *ha = vha->hw;
3796 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3797 qla2x00_get_fw_options(vha, ha->fw_options);
3799 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3802 /* Serial Link options. */
3803 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3804 "Serial link options.\n");
3805 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3806 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3808 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3809 if (ha->fw_seriallink_options[3] & BIT_2) {
3810 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3813 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3814 emphasis = (ha->fw_seriallink_options[2] &
3815 (BIT_4 | BIT_3)) >> 3;
3816 tx_sens = ha->fw_seriallink_options[0] &
3817 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3818 rx_sens = (ha->fw_seriallink_options[0] &
3819 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3820 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3821 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3824 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3825 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3826 ha->fw_options[10] |= BIT_5 |
3827 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3828 (tx_sens & (BIT_1 | BIT_0));
3831 swing = (ha->fw_seriallink_options[2] &
3832 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3833 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3834 tx_sens = ha->fw_seriallink_options[1] &
3835 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3836 rx_sens = (ha->fw_seriallink_options[1] &
3837 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3838 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3839 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3842 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3843 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3844 ha->fw_options[11] |= BIT_5 |
3845 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3846 (tx_sens & (BIT_1 | BIT_0));
3850 /* Return command IOCBs without waiting for an ABTS to complete. */
3851 ha->fw_options[3] |= BIT_13;
3854 if (ha->flags.enable_led_scheme)
3855 ha->fw_options[2] |= BIT_12;
3857 /* Detect ISP6312. */
3859 ha->fw_options[2] |= BIT_13;
3861 /* Set Retry FLOGI in case of P2P connection */
3862 if (ha->operating_mode == P2P) {
3863 ha->fw_options[2] |= BIT_3;
3864 ql_dbg(ql_dbg_disc, vha, 0x2100,
3865 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3866 __func__, ha->fw_options[2]);
3869 /* Update firmware options. */
3870 qla2x00_set_fw_options(vha, ha->fw_options);
3874 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3877 struct qla_hw_data *ha = vha->hw;
3879 if (IS_P3P_TYPE(ha))
3882 /* Hold status IOCBs until ABTS response received. */
3884 ha->fw_options[3] |= BIT_12;
3886 /* Set Retry FLOGI in case of P2P connection */
3887 if (ha->operating_mode == P2P) {
3888 ha->fw_options[2] |= BIT_3;
3889 ql_dbg(ql_dbg_disc, vha, 0x2101,
3890 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3891 __func__, ha->fw_options[2]);
3894 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3895 if (ql2xmvasynctoatio &&
3896 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3897 if (qla_tgt_mode_enabled(vha) ||
3898 qla_dual_mode_enabled(vha))
3899 ha->fw_options[2] |= BIT_11;
3901 ha->fw_options[2] &= ~BIT_11;
3904 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3907 * Tell FW to track each exchange to prevent
3908 * driver from using stale exchange.
3910 if (qla_tgt_mode_enabled(vha) ||
3911 qla_dual_mode_enabled(vha))
3912 ha->fw_options[2] |= BIT_4;
3914 ha->fw_options[2] &= ~BIT_4;
3916 /* Reserve 1/2 of emergency exchanges for ELS.*/
3917 if (qla2xuseresexchforels)
3918 ha->fw_options[2] |= BIT_8;
3920 ha->fw_options[2] &= ~BIT_8;
3923 ql_dbg(ql_dbg_init, vha, 0x00e8,
3924 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3925 __func__, ha->fw_options[1], ha->fw_options[2],
3926 ha->fw_options[3], vha->host->active_mode);
3928 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3929 qla2x00_set_fw_options(vha, ha->fw_options);
3931 /* Update Serial Link options. */
3932 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3935 rval = qla2x00_set_serdes_params(vha,
3936 le16_to_cpu(ha->fw_seriallink_options24[1]),
3937 le16_to_cpu(ha->fw_seriallink_options24[2]),
3938 le16_to_cpu(ha->fw_seriallink_options24[3]));
3939 if (rval != QLA_SUCCESS) {
3940 ql_log(ql_log_warn, vha, 0x0104,
3941 "Unable to update Serial Link options (%x).\n", rval);
3946 qla2x00_config_rings(struct scsi_qla_host *vha)
3948 struct qla_hw_data *ha = vha->hw;
3949 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3950 struct req_que *req = ha->req_q_map[0];
3951 struct rsp_que *rsp = ha->rsp_q_map[0];
3953 /* Setup ring parameters in initialization control block. */
3954 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3955 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3956 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3957 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3958 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3959 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3961 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3962 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3963 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3964 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3965 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3969 qla24xx_config_rings(struct scsi_qla_host *vha)
3971 struct qla_hw_data *ha = vha->hw;
3972 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3973 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3974 struct qla_msix_entry *msix;
3975 struct init_cb_24xx *icb;
3977 struct req_que *req = ha->req_q_map[0];
3978 struct rsp_que *rsp = ha->rsp_q_map[0];
3980 /* Setup ring parameters in initialization control block. */
3981 icb = (struct init_cb_24xx *)ha->init_cb;
3982 icb->request_q_outpointer = cpu_to_le16(0);
3983 icb->response_q_inpointer = cpu_to_le16(0);
3984 icb->request_q_length = cpu_to_le16(req->length);
3985 icb->response_q_length = cpu_to_le16(rsp->length);
3986 put_unaligned_le64(req->dma, &icb->request_q_address);
3987 put_unaligned_le64(rsp->dma, &icb->response_q_address);
3989 /* Setup ATIO queue dma pointers for target mode */
3990 icb->atio_q_inpointer = cpu_to_le16(0);
3991 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3992 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
3994 if (IS_SHADOW_REG_CAPABLE(ha))
3995 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3997 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3999 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4000 icb->rid = cpu_to_le16(rid);
4001 if (ha->flags.msix_enabled) {
4002 msix = &ha->msix_entries[1];
4003 ql_dbg(ql_dbg_init, vha, 0x0019,
4004 "Registering vector 0x%x for base que.\n",
4006 icb->msix = cpu_to_le16(msix->entry);
4008 /* Use alternate PCI bus number */
4010 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4011 /* Use alternate PCI devfn */
4013 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4015 /* Use Disable MSIX Handshake mode for capable adapters */
4016 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4017 (ha->flags.msix_enabled)) {
4018 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4019 ha->flags.disable_msix_handshake = 1;
4020 ql_dbg(ql_dbg_init, vha, 0x00fe,
4021 "MSIX Handshake Disable Mode turned on.\n");
4023 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4025 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4027 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
4028 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
4029 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
4030 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4032 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4033 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4034 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4035 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4038 qlt_24xx_config_rings(vha);
4040 /* If the user has configured the speed, set it here */
4041 if (ha->set_data_rate) {
4042 ql_dbg(ql_dbg_init, vha, 0x00fd,
4043 "Speed set by user : %s Gbps \n",
4044 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4045 icb->firmware_options_3 = (ha->set_data_rate << 13);
4049 RD_REG_DWORD(&ioreg->hccr);
4053 * qla2x00_init_rings() - Initializes firmware.
4056 * Beginning of request ring has initialization control block already built
4057 * by nvram config routine.
4059 * Returns 0 on success.
4062 qla2x00_init_rings(scsi_qla_host_t *vha)
4065 unsigned long flags = 0;
4067 struct qla_hw_data *ha = vha->hw;
4068 struct req_que *req;
4069 struct rsp_que *rsp;
4070 struct mid_init_cb_24xx *mid_init_cb =
4071 (struct mid_init_cb_24xx *) ha->init_cb;
4073 spin_lock_irqsave(&ha->hardware_lock, flags);
4075 /* Clear outstanding commands array. */
4076 for (que = 0; que < ha->max_req_queues; que++) {
4077 req = ha->req_q_map[que];
4078 if (!req || !test_bit(que, ha->req_qid_map))
4080 req->out_ptr = (void *)(req->ring + req->length);
4082 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4083 req->outstanding_cmds[cnt] = NULL;
4085 req->current_outstanding_cmd = 1;
4087 /* Initialize firmware. */
4088 req->ring_ptr = req->ring;
4089 req->ring_index = 0;
4090 req->cnt = req->length;
4093 for (que = 0; que < ha->max_rsp_queues; que++) {
4094 rsp = ha->rsp_q_map[que];
4095 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4097 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4099 /* Initialize response queue entries */
4101 qlafx00_init_response_q_entries(rsp);
4103 qla2x00_init_response_q_entries(rsp);
4106 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4107 ha->tgt.atio_ring_index = 0;
4108 /* Initialize ATIO queue entries */
4109 qlt_init_atio_q_entries(vha);
4111 ha->isp_ops->config_rings(vha);
4113 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4115 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4117 if (IS_QLAFX00(ha)) {
4118 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4122 /* Update any ISP specific firmware options before initialization. */
4123 ha->isp_ops->update_fw_options(vha);
4125 if (ha->flags.npiv_supported) {
4126 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4127 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4128 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4131 if (IS_FWI2_CAPABLE(ha)) {
4132 mid_init_cb->options = cpu_to_le16(BIT_1);
4133 mid_init_cb->init_cb.execution_throttle =
4134 cpu_to_le16(ha->cur_fw_xcb_count);
4135 ha->flags.dport_enabled =
4136 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4137 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4138 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4139 /* FA-WWPN Status */
4140 ha->flags.fawwpn_enabled =
4141 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4142 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4143 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4146 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4149 ql_log(ql_log_fatal, vha, 0x00d2,
4150 "Init Firmware **** FAILED ****.\n");
4152 ql_dbg(ql_dbg_init, vha, 0x00d3,
4153 "Init Firmware -- success.\n");
4155 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4162 * qla2x00_fw_ready() - Waits for firmware ready.
4165 * Returns 0 on success.
4168 qla2x00_fw_ready(scsi_qla_host_t *vha)
4171 unsigned long wtime, mtime, cs84xx_time;
4172 uint16_t min_wait; /* Minimum wait time if loop is down */
4173 uint16_t wait_time; /* Wait time if loop is coming ready */
4175 struct qla_hw_data *ha = vha->hw;
4177 if (IS_QLAFX00(vha->hw))
4178 return qlafx00_fw_ready(vha);
4182 /* Time to wait for loop down */
4183 if (IS_P3P_TYPE(ha))
4189 * Firmware should take at most one RATOV to login, plus 5 seconds for
4190 * our own processing.
4192 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4193 wait_time = min_wait;
4196 /* Min wait time if loop down */
4197 mtime = jiffies + (min_wait * HZ);
4199 /* wait time before firmware ready */
4200 wtime = jiffies + (wait_time * HZ);
4202 /* Wait for ISP to finish LIP */
4203 if (!vha->flags.init_done)
4204 ql_log(ql_log_info, vha, 0x801e,
4205 "Waiting for LIP to complete.\n");
4208 memset(state, -1, sizeof(state));
4209 rval = qla2x00_get_firmware_state(vha, state);
4210 if (rval == QLA_SUCCESS) {
4211 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4212 vha->device_flags &= ~DFLG_NO_CABLE;
4214 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4215 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4216 "fw_state=%x 84xx=%x.\n", state[0],
4218 if ((state[2] & FSTATE_LOGGED_IN) &&
4219 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4220 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4221 "Sending verify iocb.\n");
4223 cs84xx_time = jiffies;
4224 rval = qla84xx_init_chip(vha);
4225 if (rval != QLA_SUCCESS) {
4228 "Init chip failed.\n");
4232 /* Add time taken to initialize. */
4233 cs84xx_time = jiffies - cs84xx_time;
4234 wtime += cs84xx_time;
4235 mtime += cs84xx_time;
4236 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4237 "Increasing wait time by %ld. "
4238 "New time %ld.\n", cs84xx_time,
4241 } else if (state[0] == FSTATE_READY) {
4242 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4243 "F/W Ready - OK.\n");
4245 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4246 &ha->login_timeout, &ha->r_a_tov);
4252 rval = QLA_FUNCTION_FAILED;
4254 if (atomic_read(&vha->loop_down_timer) &&
4255 state[0] != FSTATE_READY) {
4256 /* Loop down. Timeout on min_wait for states
4257 * other than Wait for Login.
4259 if (time_after_eq(jiffies, mtime)) {
4260 ql_log(ql_log_info, vha, 0x8038,
4261 "Cable is unplugged...\n");
4263 vha->device_flags |= DFLG_NO_CABLE;
4268 /* Mailbox cmd failed. Timeout on min_wait. */
4269 if (time_after_eq(jiffies, mtime) ||
4270 ha->flags.isp82xx_fw_hung)
4274 if (time_after_eq(jiffies, wtime))
4277 /* Delay for a while */
4281 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4282 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4283 state[1], state[2], state[3], state[4], state[5], jiffies);
4285 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4286 ql_log(ql_log_warn, vha, 0x803b,
4287 "Firmware ready **** FAILED ****.\n");
4294 * qla2x00_configure_hba
4295 * Setup adapter context.
4298 * ha = adapter state pointer.
4307 qla2x00_configure_hba(scsi_qla_host_t *vha)
4316 char connect_type[22];
4317 struct qla_hw_data *ha = vha->hw;
4318 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4320 unsigned long flags;
4322 /* Get host addresses. */
4323 rval = qla2x00_get_adapter_id(vha,
4324 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4325 if (rval != QLA_SUCCESS) {
4326 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4327 IS_CNA_CAPABLE(ha) ||
4328 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4329 ql_dbg(ql_dbg_disc, vha, 0x2008,
4330 "Loop is in a transition state.\n");
4332 ql_log(ql_log_warn, vha, 0x2009,
4333 "Unable to get host loop ID.\n");
4334 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4335 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4336 ql_log(ql_log_warn, vha, 0x1151,
4337 "Doing link init.\n");
4338 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4341 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4347 ql_log(ql_log_info, vha, 0x200a,
4348 "Cannot get topology - retrying.\n");
4349 return (QLA_FUNCTION_FAILED);
4352 vha->loop_id = loop_id;
4355 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4356 ha->operating_mode = LOOP;
4361 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4362 ha->current_topology = ISP_CFG_NL;
4363 strcpy(connect_type, "(Loop)");
4367 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4368 ha->switch_cap = sw_cap;
4369 ha->current_topology = ISP_CFG_FL;
4370 strcpy(connect_type, "(FL_Port)");
4374 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4375 ha->operating_mode = P2P;
4376 ha->current_topology = ISP_CFG_N;
4377 strcpy(connect_type, "(N_Port-to-N_Port)");
4381 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4382 ha->switch_cap = sw_cap;
4383 ha->operating_mode = P2P;
4384 ha->current_topology = ISP_CFG_F;
4385 strcpy(connect_type, "(F_Port)");
4389 ql_dbg(ql_dbg_disc, vha, 0x200f,
4390 "HBA in unknown topology %x, using NL.\n", topo);
4391 ha->current_topology = ISP_CFG_NL;
4392 strcpy(connect_type, "(Loop)");
4396 /* Save Host port and loop ID. */
4397 /* byte order - Big Endian */
4398 id.b.domain = domain;
4402 spin_lock_irqsave(&ha->hardware_lock, flags);
4403 if (!(topo == 2 && ha->flags.n2n_bigger))
4404 qlt_update_host_map(vha, id);
4405 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4407 if (!vha->flags.init_done)
4408 ql_log(ql_log_info, vha, 0x2010,
4409 "Topology - %s, Host Loop address 0x%x.\n",
4410 connect_type, vha->loop_id);
4416 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4421 uint64_t zero[2] = { 0 };
4422 struct qla_hw_data *ha = vha->hw;
4423 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4424 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4426 if (len > sizeof(zero))
4428 if (memcmp(model, &zero, len) != 0) {
4429 strncpy(ha->model_number, model, len);
4430 st = en = ha->model_number;
4433 if (*en != 0x20 && *en != 0x00)
4438 index = (ha->pdev->subsystem_device & 0xff);
4440 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4441 index < QLA_MODEL_NAMES)
4442 strncpy(ha->model_desc,
4443 qla2x00_model_name[index * 2 + 1],
4444 sizeof(ha->model_desc) - 1);
4446 index = (ha->pdev->subsystem_device & 0xff);
4448 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4449 index < QLA_MODEL_NAMES) {
4450 strcpy(ha->model_number,
4451 qla2x00_model_name[index * 2]);
4452 strncpy(ha->model_desc,
4453 qla2x00_model_name[index * 2 + 1],
4454 sizeof(ha->model_desc) - 1);
4456 strcpy(ha->model_number, def);
4459 if (IS_FWI2_CAPABLE(ha))
4460 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4461 sizeof(ha->model_desc));
4464 /* On sparc systems, obtain port and node WWN from firmware
4467 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4470 struct qla_hw_data *ha = vha->hw;
4471 struct pci_dev *pdev = ha->pdev;
4472 struct device_node *dp = pci_device_to_OF_node(pdev);
4476 val = of_get_property(dp, "port-wwn", &len);
4477 if (val && len >= WWN_SIZE)
4478 memcpy(nv->port_name, val, WWN_SIZE);
4480 val = of_get_property(dp, "node-wwn", &len);
4481 if (val && len >= WWN_SIZE)
4482 memcpy(nv->node_name, val, WWN_SIZE);
4487 * NVRAM configuration for ISP 2xxx
4490 * ha = adapter block pointer.
4493 * initialization control block in response_ring
4494 * host adapters parameters in host adapter block
4500 qla2x00_nvram_config(scsi_qla_host_t *vha)
4505 uint8_t *dptr1, *dptr2;
4506 struct qla_hw_data *ha = vha->hw;
4507 init_cb_t *icb = ha->init_cb;
4508 nvram_t *nv = ha->nvram;
4509 uint8_t *ptr = ha->nvram;
4510 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4514 /* Determine NVRAM starting address. */
4515 ha->nvram_size = sizeof(*nv);
4517 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4518 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4519 ha->nvram_base = 0x80;
4521 /* Get NVRAM data and calculate checksum. */
4522 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4523 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4526 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4527 "Contents of NVRAM.\n");
4528 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4529 nv, ha->nvram_size);
4531 /* Bad NVRAM data, set defaults parameters. */
4532 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4533 nv->nvram_version < 1) {
4534 /* Reset NVRAM data. */
4535 ql_log(ql_log_warn, vha, 0x0064,
4536 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4537 chksum, nv->id, nv->nvram_version);
4538 ql_log(ql_log_warn, vha, 0x0065,
4540 "functioning (yet invalid -- WWPN) defaults.\n");
4543 * Set default initialization control block.
4545 memset(nv, 0, ha->nvram_size);
4546 nv->parameter_block_version = ICB_VERSION;
4548 if (IS_QLA23XX(ha)) {
4549 nv->firmware_options[0] = BIT_2 | BIT_1;
4550 nv->firmware_options[1] = BIT_7 | BIT_5;
4551 nv->add_firmware_options[0] = BIT_5;
4552 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4553 nv->frame_payload_size = 2048;
4554 nv->special_options[1] = BIT_7;
4555 } else if (IS_QLA2200(ha)) {
4556 nv->firmware_options[0] = BIT_2 | BIT_1;
4557 nv->firmware_options[1] = BIT_7 | BIT_5;
4558 nv->add_firmware_options[0] = BIT_5;
4559 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4560 nv->frame_payload_size = 1024;
4561 } else if (IS_QLA2100(ha)) {
4562 nv->firmware_options[0] = BIT_3 | BIT_1;
4563 nv->firmware_options[1] = BIT_5;
4564 nv->frame_payload_size = 1024;
4567 nv->max_iocb_allocation = cpu_to_le16(256);
4568 nv->execution_throttle = cpu_to_le16(16);
4569 nv->retry_count = 8;
4570 nv->retry_delay = 1;
4572 nv->port_name[0] = 33;
4573 nv->port_name[3] = 224;
4574 nv->port_name[4] = 139;
4576 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4578 nv->login_timeout = 4;
4581 * Set default host adapter parameters
4583 nv->host_p[1] = BIT_2;
4584 nv->reset_delay = 5;
4585 nv->port_down_retry_count = 8;
4586 nv->max_luns_per_target = cpu_to_le16(8);
4587 nv->link_down_timeout = 60;
4592 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4594 * The SN2 does not provide BIOS emulation which means you can't change
4595 * potentially bogus BIOS settings. Force the use of default settings
4596 * for link rate and frame size. Hope that the rest of the settings
4599 if (ia64_platform_is("sn2")) {
4600 nv->frame_payload_size = 2048;
4602 nv->special_options[1] = BIT_7;
4606 /* Reset Initialization control block */
4607 memset(icb, 0, ha->init_cb_size);
4610 * Setup driver NVRAM options.
4612 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4613 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4614 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4615 nv->firmware_options[1] &= ~BIT_4;
4617 if (IS_QLA23XX(ha)) {
4618 nv->firmware_options[0] |= BIT_2;
4619 nv->firmware_options[0] &= ~BIT_3;
4620 nv->special_options[0] &= ~BIT_6;
4621 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4623 if (IS_QLA2300(ha)) {
4624 if (ha->fb_rev == FPM_2310) {
4625 strcpy(ha->model_number, "QLA2310");
4627 strcpy(ha->model_number, "QLA2300");
4630 qla2x00_set_model_info(vha, nv->model_number,
4631 sizeof(nv->model_number), "QLA23xx");
4633 } else if (IS_QLA2200(ha)) {
4634 nv->firmware_options[0] |= BIT_2;
4636 * 'Point-to-point preferred, else loop' is not a safe
4637 * connection mode setting.
4639 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4641 /* Force 'loop preferred, else point-to-point'. */
4642 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4643 nv->add_firmware_options[0] |= BIT_5;
4645 strcpy(ha->model_number, "QLA22xx");
4646 } else /*if (IS_QLA2100(ha))*/ {
4647 strcpy(ha->model_number, "QLA2100");
4651 * Copy over NVRAM RISC parameter block to initialization control block.
4653 dptr1 = (uint8_t *)icb;
4654 dptr2 = (uint8_t *)&nv->parameter_block_version;
4655 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4657 *dptr1++ = *dptr2++;
4659 /* Copy 2nd half. */
4660 dptr1 = (uint8_t *)icb->add_firmware_options;
4661 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4663 *dptr1++ = *dptr2++;
4664 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4665 /* Use alternate WWN? */
4666 if (nv->host_p[1] & BIT_7) {
4667 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4668 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4671 /* Prepare nodename */
4672 if ((icb->firmware_options[1] & BIT_6) == 0) {
4674 * Firmware will apply the following mask if the nodename was
4677 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4678 icb->node_name[0] &= 0xF0;
4682 * Set host adapter parameters.
4686 * BIT_7 in the host-parameters section allows for modification to
4687 * internal driver logging.
4689 if (nv->host_p[0] & BIT_7)
4690 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4691 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4692 /* Always load RISC code on non ISP2[12]00 chips. */
4693 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4694 ha->flags.disable_risc_code_load = 0;
4695 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4696 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4697 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4698 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4699 ha->flags.disable_serdes = 0;
4701 ha->operating_mode =
4702 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4704 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4705 sizeof(ha->fw_seriallink_options));
4707 /* save HBA serial number */
4708 ha->serial0 = icb->port_name[5];
4709 ha->serial1 = icb->port_name[6];
4710 ha->serial2 = icb->port_name[7];
4711 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4712 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4714 icb->execution_throttle = cpu_to_le16(0xFFFF);
4716 ha->retry_count = nv->retry_count;
4718 /* Set minimum login_timeout to 4 seconds. */
4719 if (nv->login_timeout != ql2xlogintimeout)
4720 nv->login_timeout = ql2xlogintimeout;
4721 if (nv->login_timeout < 4)
4722 nv->login_timeout = 4;
4723 ha->login_timeout = nv->login_timeout;
4725 /* Set minimum RATOV to 100 tenths of a second. */
4728 ha->loop_reset_delay = nv->reset_delay;
4730 /* Link Down Timeout = 0:
4732 * When Port Down timer expires we will start returning
4733 * I/O's to OS with "DID_NO_CONNECT".
4735 * Link Down Timeout != 0:
4737 * The driver waits for the link to come up after link down
4738 * before returning I/Os to OS with "DID_NO_CONNECT".
4740 if (nv->link_down_timeout == 0) {
4741 ha->loop_down_abort_time =
4742 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4744 ha->link_down_timeout = nv->link_down_timeout;
4745 ha->loop_down_abort_time =
4746 (LOOP_DOWN_TIME - ha->link_down_timeout);
4750 * Need enough time to try and get the port back.
4752 ha->port_down_retry_count = nv->port_down_retry_count;
4753 if (qlport_down_retry)
4754 ha->port_down_retry_count = qlport_down_retry;
4755 /* Set login_retry_count */
4756 ha->login_retry_count = nv->retry_count;
4757 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4758 ha->port_down_retry_count > 3)
4759 ha->login_retry_count = ha->port_down_retry_count;
4760 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4761 ha->login_retry_count = ha->port_down_retry_count;
4762 if (ql2xloginretrycount)
4763 ha->login_retry_count = ql2xloginretrycount;
4765 icb->lun_enables = cpu_to_le16(0);
4766 icb->command_resource_count = 0;
4767 icb->immediate_notify_resource_count = 0;
4768 icb->timeout = cpu_to_le16(0);
4770 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4772 icb->firmware_options[0] &= ~BIT_3;
4773 icb->add_firmware_options[0] &=
4774 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4775 icb->add_firmware_options[0] |= BIT_2;
4776 icb->response_accumulation_timer = 3;
4777 icb->interrupt_delay_timer = 5;
4779 vha->flags.process_response_queue = 1;
4782 if (!vha->flags.init_done) {
4783 ha->zio_mode = icb->add_firmware_options[0] &
4784 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4785 ha->zio_timer = icb->interrupt_delay_timer ?
4786 icb->interrupt_delay_timer : 2;
4788 icb->add_firmware_options[0] &=
4789 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4790 vha->flags.process_response_queue = 0;
4791 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4792 ha->zio_mode = QLA_ZIO_MODE_6;
4794 ql_log(ql_log_info, vha, 0x0068,
4795 "ZIO mode %d enabled; timer delay (%d us).\n",
4796 ha->zio_mode, ha->zio_timer * 100);
4798 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4799 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4800 vha->flags.process_response_queue = 1;
4805 ql_log(ql_log_warn, vha, 0x0069,
4806 "NVRAM configuration failed.\n");
4812 qla2x00_rport_del(void *data)
4814 fc_port_t *fcport = data;
4815 struct fc_rport *rport;
4816 unsigned long flags;
4818 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4819 rport = fcport->drport ? fcport->drport : fcport->rport;
4820 fcport->drport = NULL;
4821 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4823 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4824 "%s %8phN. rport %p roles %x\n",
4825 __func__, fcport->port_name, rport,
4828 fc_remote_port_delete(rport);
4832 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4836 old_state = atomic_read(&fcport->state);
4837 atomic_set(&fcport->state, state);
4839 /* Don't print state transitions during initial allocation of fcport */
4840 if (old_state && old_state != state) {
4841 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4842 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4843 fcport->port_name, port_state_str[old_state],
4844 port_state_str[state], fcport->d_id.b.domain,
4845 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4850 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4852 * @flags: allocation flags
4854 * Returns a pointer to the allocated fcport, or NULL, if none available.
4857 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4861 fcport = kzalloc(sizeof(fc_port_t), flags);
4865 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4866 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4868 if (!fcport->ct_desc.ct_sns) {
4869 ql_log(ql_log_warn, vha, 0xd049,
4870 "Failed to allocate ct_sns request.\n");
4875 /* Setup fcport template structure. */
4877 fcport->port_type = FCT_UNKNOWN;
4878 fcport->loop_id = FC_NO_LOOP_ID;
4879 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4880 fcport->supported_classes = FC_COS_UNSPECIFIED;
4881 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4883 fcport->disc_state = DSC_DELETED;
4884 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4885 fcport->deleted = QLA_SESS_DELETED;
4886 fcport->login_retry = vha->hw->login_retry_count;
4887 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4888 fcport->logout_on_delete = 1;
4890 if (!fcport->ct_desc.ct_sns) {
4891 ql_log(ql_log_warn, vha, 0xd049,
4892 "Failed to allocate ct_sns request.\n");
4897 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4898 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4899 INIT_LIST_HEAD(&fcport->gnl_entry);
4900 INIT_LIST_HEAD(&fcport->list);
4906 qla2x00_free_fcport(fc_port_t *fcport)
4908 if (fcport->ct_desc.ct_sns) {
4909 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4910 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4911 fcport->ct_desc.ct_sns_dma);
4913 fcport->ct_desc.ct_sns = NULL;
4915 list_del(&fcport->list);
4916 qla2x00_clear_loop_id(fcport);
4921 * qla2x00_configure_loop
4922 * Updates Fibre Channel Device Database with what is actually on loop.
4925 * ha = adapter block pointer.
4930 * 2 = database was full and device was not configured.
4933 qla2x00_configure_loop(scsi_qla_host_t *vha)
4936 unsigned long flags, save_flags;
4937 struct qla_hw_data *ha = vha->hw;
4941 /* Get Initiator ID */
4942 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4943 rval = qla2x00_configure_hba(vha);
4944 if (rval != QLA_SUCCESS) {
4945 ql_dbg(ql_dbg_disc, vha, 0x2013,
4946 "Unable to configure HBA.\n");
4951 save_flags = flags = vha->dpc_flags;
4952 ql_dbg(ql_dbg_disc, vha, 0x2014,
4953 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4956 * If we have both an RSCN and PORT UPDATE pending then handle them
4957 * both at the same time.
4959 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4960 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4962 qla2x00_get_data_rate(vha);
4964 /* Determine what we need to do */
4965 if (ha->current_topology == ISP_CFG_FL &&
4966 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4968 set_bit(RSCN_UPDATE, &flags);
4970 } else if (ha->current_topology == ISP_CFG_F &&
4971 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4973 set_bit(RSCN_UPDATE, &flags);
4974 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4976 } else if (ha->current_topology == ISP_CFG_N) {
4977 clear_bit(RSCN_UPDATE, &flags);
4978 if (qla_tgt_mode_enabled(vha)) {
4979 /* allow the other side to start the login */
4980 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4981 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4983 } else if (ha->current_topology == ISP_CFG_NL) {
4984 clear_bit(RSCN_UPDATE, &flags);
4985 set_bit(LOCAL_LOOP_UPDATE, &flags);
4986 } else if (!vha->flags.online ||
4987 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4988 set_bit(RSCN_UPDATE, &flags);
4989 set_bit(LOCAL_LOOP_UPDATE, &flags);
4992 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4993 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4994 ql_dbg(ql_dbg_disc, vha, 0x2015,
4995 "Loop resync needed, failing.\n");
4996 rval = QLA_FUNCTION_FAILED;
4998 rval = qla2x00_configure_local_loop(vha);
5001 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5002 if (LOOP_TRANSITION(vha)) {
5003 ql_dbg(ql_dbg_disc, vha, 0x2099,
5004 "Needs RSCN update and loop transition.\n");
5005 rval = QLA_FUNCTION_FAILED;
5008 rval = qla2x00_configure_fabric(vha);
5011 if (rval == QLA_SUCCESS) {
5012 if (atomic_read(&vha->loop_down_timer) ||
5013 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5014 rval = QLA_FUNCTION_FAILED;
5016 atomic_set(&vha->loop_state, LOOP_READY);
5017 ql_dbg(ql_dbg_disc, vha, 0x2069,
5019 ha->flags.fw_init_done = 1;
5022 * Process any ATIO queue entries that came in
5023 * while we weren't online.
5025 if (qla_tgt_mode_enabled(vha) ||
5026 qla_dual_mode_enabled(vha)) {
5027 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5028 qlt_24xx_process_atio_queue(vha, 0);
5029 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5036 ql_dbg(ql_dbg_disc, vha, 0x206a,
5037 "%s *** FAILED ***.\n", __func__);
5039 ql_dbg(ql_dbg_disc, vha, 0x206b,
5040 "%s: exiting normally.\n", __func__);
5043 /* Restore state if a resync event occurred during processing */
5044 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5045 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5046 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5047 if (test_bit(RSCN_UPDATE, &save_flags)) {
5048 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5056 * qla2x00_configure_local_loop
5057 * Updates Fibre Channel Device Database with local loop devices.
5060 * ha = adapter block pointer.
5066 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5071 fc_port_t *fcport, *new_fcport;
5077 uint8_t domain, area, al_pa;
5078 struct qla_hw_data *ha = vha->hw;
5079 unsigned long flags;
5081 /* Inititae N2N login. */
5082 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5086 memset(ha->init_cb, 0, ha->init_cb_size);
5087 sz = min_t(int, sizeof(struct els_plogi_payload),
5089 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5090 (void *)ha->init_cb, sz);
5091 if (rval == QLA_SUCCESS) {
5092 bp = (uint32_t *)ha->init_cb;
5093 for (i = 0; i < sz/4 ; i++, bp++)
5094 *bp = cpu_to_be32(*bp);
5096 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
5097 sizeof(ha->plogi_els_payld.data));
5098 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5100 ql_dbg(ql_dbg_init, vha, 0x00d1,
5101 "PLOGI ELS param read fail.\n");
5108 entries = MAX_FIBRE_DEVICES_LOOP;
5110 /* Get list of logged in devices. */
5111 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5112 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5114 if (rval != QLA_SUCCESS)
5115 goto cleanup_allocation;
5117 ql_dbg(ql_dbg_disc, vha, 0x2011,
5118 "Entries in ID list (%d).\n", entries);
5119 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5120 ha->gid_list, entries * sizeof(*ha->gid_list));
5123 spin_lock_irqsave(&vha->work_lock, flags);
5124 vha->scan.scan_retry++;
5125 spin_unlock_irqrestore(&vha->work_lock, flags);
5127 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5128 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5129 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5132 vha->scan.scan_retry = 0;
5135 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5136 fcport->scan_state = QLA_FCPORT_SCAN;
5139 /* Allocate temporary fcport for any new fcports discovered. */
5140 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5141 if (new_fcport == NULL) {
5142 ql_log(ql_log_warn, vha, 0x2012,
5143 "Memory allocation failed for fcport.\n");
5144 rval = QLA_MEMORY_ALLOC_FAILED;
5145 goto cleanup_allocation;
5147 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5149 /* Add devices to port list. */
5150 id_iter = (char *)ha->gid_list;
5151 for (index = 0; index < entries; index++) {
5152 domain = ((struct gid_list_info *)id_iter)->domain;
5153 area = ((struct gid_list_info *)id_iter)->area;
5154 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
5155 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5156 loop_id = (uint16_t)
5157 ((struct gid_list_info *)id_iter)->loop_id_2100;
5159 loop_id = le16_to_cpu(
5160 ((struct gid_list_info *)id_iter)->loop_id);
5161 id_iter += ha->gid_list_info_size;
5163 /* Bypass reserved domain fields. */
5164 if ((domain & 0xf0) == 0xf0)
5167 /* Bypass if not same domain and area of adapter. */
5168 if (area && domain && ((area != vha->d_id.b.area) ||
5169 (domain != vha->d_id.b.domain)) &&
5170 (ha->current_topology == ISP_CFG_NL))
5174 /* Bypass invalid local loop ID. */
5175 if (loop_id > LAST_LOCAL_LOOP_ID)
5178 memset(new_fcport->port_name, 0, WWN_SIZE);
5180 /* Fill in member data. */
5181 new_fcport->d_id.b.domain = domain;
5182 new_fcport->d_id.b.area = area;
5183 new_fcport->d_id.b.al_pa = al_pa;
5184 new_fcport->loop_id = loop_id;
5185 new_fcport->scan_state = QLA_FCPORT_FOUND;
5187 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5188 if (rval2 != QLA_SUCCESS) {
5189 ql_dbg(ql_dbg_disc, vha, 0x2097,
5190 "Failed to retrieve fcport information "
5191 "-- get_port_database=%x, loop_id=0x%04x.\n",
5192 rval2, new_fcport->loop_id);
5193 /* Skip retry if N2N */
5194 if (ha->current_topology != ISP_CFG_N) {
5195 ql_dbg(ql_dbg_disc, vha, 0x2105,
5196 "Scheduling resync.\n");
5197 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5202 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5203 /* Check for matching device in port list. */
5206 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5207 if (memcmp(new_fcport->port_name, fcport->port_name,
5211 fcport->flags &= ~FCF_FABRIC_DEVICE;
5212 fcport->loop_id = new_fcport->loop_id;
5213 fcport->port_type = new_fcport->port_type;
5214 fcport->d_id.b24 = new_fcport->d_id.b24;
5215 memcpy(fcport->node_name, new_fcport->node_name,
5217 fcport->scan_state = QLA_FCPORT_FOUND;
5223 /* New device, add to fcports list. */
5224 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5226 /* Allocate a new replacement fcport. */
5227 fcport = new_fcport;
5229 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5231 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5233 if (new_fcport == NULL) {
5234 ql_log(ql_log_warn, vha, 0xd031,
5235 "Failed to allocate memory for fcport.\n");
5236 rval = QLA_MEMORY_ALLOC_FAILED;
5237 goto cleanup_allocation;
5239 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5240 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5243 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5245 /* Base iIDMA settings on HBA port speed. */
5246 fcport->fp_speed = ha->link_data_rate;
5251 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5252 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5255 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5256 if ((qla_dual_mode_enabled(vha) ||
5257 qla_ini_mode_enabled(vha)) &&
5258 atomic_read(&fcport->state) == FCS_ONLINE) {
5259 qla2x00_mark_device_lost(vha, fcport,
5260 ql2xplogiabsentdevice, 0);
5261 if (fcport->loop_id != FC_NO_LOOP_ID &&
5262 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5263 fcport->port_type != FCT_INITIATOR &&
5264 fcport->port_type != FCT_BROADCAST) {
5265 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5266 "%s %d %8phC post del sess\n",
5270 qlt_schedule_sess_for_deletion(fcport);
5276 if (fcport->scan_state == QLA_FCPORT_FOUND)
5277 qla24xx_fcport_handle_login(vha, fcport);
5283 if (rval != QLA_SUCCESS) {
5284 ql_dbg(ql_dbg_disc, vha, 0x2098,
5285 "Configure local loop error exit: rval=%x.\n", rval);
5292 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5295 uint16_t mb[MAILBOX_REGISTER_COUNT];
5296 struct qla_hw_data *ha = vha->hw;
5298 if (!IS_IIDMA_CAPABLE(ha))
5301 if (atomic_read(&fcport->state) != FCS_ONLINE)
5304 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5305 fcport->fp_speed > ha->link_data_rate ||
5306 !ha->flags.gpsc_supported)
5309 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5311 if (rval != QLA_SUCCESS) {
5312 ql_dbg(ql_dbg_disc, vha, 0x2004,
5313 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5314 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5316 ql_dbg(ql_dbg_disc, vha, 0x2005,
5317 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5318 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5319 fcport->fp_speed, fcport->port_name);
5323 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5325 qla2x00_iidma_fcport(vha, fcport);
5326 qla24xx_update_fcport_fcp_prio(vha, fcport);
5329 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5331 struct qla_work_evt *e;
5333 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5335 return QLA_FUNCTION_FAILED;
5337 e->u.fcport.fcport = fcport;
5338 return qla2x00_post_work(vha, e);
5341 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5343 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5345 struct fc_rport_identifiers rport_ids;
5346 struct fc_rport *rport;
5347 unsigned long flags;
5349 if (atomic_read(&fcport->state) == FCS_ONLINE)
5352 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5353 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5354 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5355 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5356 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5357 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5359 ql_log(ql_log_warn, vha, 0x2006,
5360 "Unable to allocate fc remote port.\n");
5364 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5365 *((fc_port_t **)rport->dd_data) = fcport;
5366 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5368 rport->supported_classes = fcport->supported_classes;
5370 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5371 if (fcport->port_type == FCT_INITIATOR)
5372 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5373 if (fcport->port_type == FCT_TARGET)
5374 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5375 if (fcport->port_type & FCT_NVME_INITIATOR)
5376 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5377 if (fcport->port_type & FCT_NVME_TARGET)
5378 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5379 if (fcport->port_type & FCT_NVME_DISCOVERY)
5380 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5382 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5383 "%s %8phN. rport %p is %s mode\n",
5384 __func__, fcport->port_name, rport,
5385 (fcport->port_type == FCT_TARGET) ? "tgt" :
5386 ((fcport->port_type & FCT_NVME) ? "nvme" :"ini"));
5388 fc_remote_port_rolechg(rport, rport_ids.roles);
5392 * qla2x00_update_fcport
5393 * Updates device on list.
5396 * ha = adapter block pointer.
5397 * fcport = port structure pointer.
5407 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5409 if (IS_SW_RESV_ADDR(fcport->d_id))
5412 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5413 __func__, fcport->port_name);
5415 fcport->disc_state = DSC_UPD_FCPORT;
5416 fcport->login_retry = vha->hw->login_retry_count;
5417 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5418 fcport->deleted = 0;
5419 fcport->logout_on_delete = 1;
5420 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5422 switch (vha->hw->current_topology) {
5425 fcport->keep_nport_handle = 1;
5431 qla2x00_iidma_fcport(vha, fcport);
5433 if (fcport->fc4f_nvme) {
5434 qla_nvme_register_remote(vha, fcport);
5435 fcport->disc_state = DSC_LOGIN_COMPLETE;
5436 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5440 qla24xx_update_fcport_fcp_prio(vha, fcport);
5442 switch (vha->host->active_mode) {
5443 case MODE_INITIATOR:
5444 qla2x00_reg_remote_port(vha, fcport);
5447 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5448 !vha->vha_tgt.qla_tgt->tgt_stopped)
5449 qlt_fc_port_added(vha, fcport);
5452 qla2x00_reg_remote_port(vha, fcport);
5453 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5454 !vha->vha_tgt.qla_tgt->tgt_stopped)
5455 qlt_fc_port_added(vha, fcport);
5461 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5463 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5464 if (fcport->id_changed) {
5465 fcport->id_changed = 0;
5466 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5467 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5468 __func__, __LINE__, fcport->port_name,
5470 qla24xx_post_gfpnid_work(vha, fcport);
5472 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5473 "%s %d %8phC post gpsc fcp_cnt %d\n",
5474 __func__, __LINE__, fcport->port_name,
5476 qla24xx_post_gpsc_work(vha, fcport);
5480 fcport->disc_state = DSC_LOGIN_COMPLETE;
5483 void qla_register_fcport_fn(struct work_struct *work)
5485 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5486 u32 rscn_gen = fcport->rscn_gen;
5489 if (IS_SW_RESV_ADDR(fcport->d_id))
5492 qla2x00_update_fcport(fcport->vha, fcport);
5494 if (rscn_gen != fcport->rscn_gen) {
5495 /* RSCN(s) came in while registration */
5496 switch (fcport->next_disc_state) {
5497 case DSC_DELETE_PEND:
5498 qlt_schedule_sess_for_deletion(fcport);
5501 data[0] = data[1] = 0;
5502 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5512 * qla2x00_configure_fabric
5513 * Setup SNS devices with loop ID's.
5516 * ha = adapter block pointer.
5523 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5527 uint16_t mb[MAILBOX_REGISTER_COUNT];
5529 LIST_HEAD(new_fcports);
5530 struct qla_hw_data *ha = vha->hw;
5533 /* If FL port exists, then SNS is present */
5534 if (IS_FWI2_CAPABLE(ha))
5535 loop_id = NPH_F_PORT;
5537 loop_id = SNS_FL_PORT;
5538 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5539 if (rval != QLA_SUCCESS) {
5540 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5541 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5543 vha->device_flags &= ~SWITCH_FOUND;
5544 return (QLA_SUCCESS);
5546 vha->device_flags |= SWITCH_FOUND;
5549 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5550 rval = qla2x00_send_change_request(vha, 0x3, 0);
5551 if (rval != QLA_SUCCESS)
5552 ql_log(ql_log_warn, vha, 0x121,
5553 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5559 qla2x00_mgmt_svr_login(vha);
5562 if (ql2xfdmienable &&
5563 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5564 qla2x00_fdmi_register(vha);
5566 /* Ensure we are logged into the SNS. */
5567 loop_id = NPH_SNS_LID(ha);
5568 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5569 0xfc, mb, BIT_1|BIT_0);
5570 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5571 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5572 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5573 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5574 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5577 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5578 if (qla2x00_rft_id(vha)) {
5580 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5581 "Register FC-4 TYPE failed.\n");
5582 if (test_bit(LOOP_RESYNC_NEEDED,
5586 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5588 ql_dbg(ql_dbg_disc, vha, 0x209a,
5589 "Register FC-4 Features failed.\n");
5590 if (test_bit(LOOP_RESYNC_NEEDED,
5594 if (vha->flags.nvme_enabled) {
5595 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5596 ql_dbg(ql_dbg_disc, vha, 0x2049,
5597 "Register NVME FC Type Features failed.\n");
5600 if (qla2x00_rnn_id(vha)) {
5602 ql_dbg(ql_dbg_disc, vha, 0x2104,
5603 "Register Node Name failed.\n");
5604 if (test_bit(LOOP_RESYNC_NEEDED,
5607 } else if (qla2x00_rsnn_nn(vha)) {
5609 ql_dbg(ql_dbg_disc, vha, 0x209b,
5610 "Register Symbolic Node Name failed.\n");
5611 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5617 /* Mark the time right before querying FW for connected ports.
5618 * This process is long, asynchronous and by the time it's done,
5619 * collected information might not be accurate anymore. E.g.
5620 * disconnected port might have re-connected and a brand new
5621 * session has been created. In this case session's generation
5622 * will be newer than discovery_gen. */
5623 qlt_do_generation_tick(vha, &discovery_gen);
5625 if (USE_ASYNC_SCAN(ha)) {
5626 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5629 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5631 list_for_each_entry(fcport, &vha->vp_fcports, list)
5632 fcport->scan_state = QLA_FCPORT_SCAN;
5634 rval = qla2x00_find_all_fabric_devs(vha);
5636 if (rval != QLA_SUCCESS)
5640 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5641 qla_nvme_register_hba(vha);
5644 ql_dbg(ql_dbg_disc, vha, 0x2068,
5645 "Configure fabric error exit rval=%d.\n", rval);
5651 * qla2x00_find_all_fabric_devs
5654 * ha = adapter block pointer.
5655 * dev = database device entry pointer.
5664 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5668 fc_port_t *fcport, *new_fcport;
5673 int first_dev, last_dev;
5674 port_id_t wrap = {}, nxt_d_id;
5675 struct qla_hw_data *ha = vha->hw;
5676 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5677 unsigned long flags;
5681 /* Try GID_PT to get device list, else GAN. */
5683 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5688 ql_dbg(ql_dbg_disc, vha, 0x209c,
5689 "GID_PT allocations failed, fallback on GA_NXT.\n");
5691 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5692 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5694 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5696 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5698 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5700 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5702 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5704 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5706 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5710 /* If other queries succeeded probe for FC-4 type */
5712 qla2x00_gff_id(vha, swl);
5713 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5719 /* Allocate temporary fcport for any new fcports discovered. */
5720 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5721 if (new_fcport == NULL) {
5722 ql_log(ql_log_warn, vha, 0x209d,
5723 "Failed to allocate memory for fcport.\n");
5724 return (QLA_MEMORY_ALLOC_FAILED);
5726 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5727 /* Set start port ID scan at adapter ID. */
5731 /* Starting free loop ID. */
5732 loop_id = ha->min_external_loopid;
5733 for (; loop_id <= ha->max_loop_id; loop_id++) {
5734 if (qla2x00_is_reserved_id(vha, loop_id))
5737 if (ha->current_topology == ISP_CFG_FL &&
5738 (atomic_read(&vha->loop_down_timer) ||
5739 LOOP_TRANSITION(vha))) {
5740 atomic_set(&vha->loop_down_timer, 0);
5741 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5742 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5748 wrap.b24 = new_fcport->d_id.b24;
5750 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5751 memcpy(new_fcport->node_name,
5752 swl[swl_idx].node_name, WWN_SIZE);
5753 memcpy(new_fcport->port_name,
5754 swl[swl_idx].port_name, WWN_SIZE);
5755 memcpy(new_fcport->fabric_port_name,
5756 swl[swl_idx].fabric_port_name, WWN_SIZE);
5757 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5758 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5760 new_fcport->nvme_flag = 0;
5761 new_fcport->fc4f_nvme = 0;
5762 if (vha->flags.nvme_enabled &&
5763 swl[swl_idx].fc4f_nvme) {
5764 new_fcport->fc4f_nvme =
5765 swl[swl_idx].fc4f_nvme;
5766 ql_log(ql_log_info, vha, 0x2131,
5767 "FOUND: NVME port %8phC as FC Type 28h\n",
5768 new_fcport->port_name);
5771 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5777 /* Send GA_NXT to the switch */
5778 rval = qla2x00_ga_nxt(vha, new_fcport);
5779 if (rval != QLA_SUCCESS) {
5780 ql_log(ql_log_warn, vha, 0x209e,
5781 "SNS scan failed -- assuming "
5782 "zero-entry result.\n");
5788 /* If wrap on switch device list, exit. */
5790 wrap.b24 = new_fcport->d_id.b24;
5792 } else if (new_fcport->d_id.b24 == wrap.b24) {
5793 ql_dbg(ql_dbg_disc, vha, 0x209f,
5794 "Device wrap (%02x%02x%02x).\n",
5795 new_fcport->d_id.b.domain,
5796 new_fcport->d_id.b.area,
5797 new_fcport->d_id.b.al_pa);
5801 /* Bypass if same physical adapter. */
5802 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5805 /* Bypass virtual ports of the same host. */
5806 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5809 /* Bypass if same domain and area of adapter. */
5810 if (((new_fcport->d_id.b24 & 0xffff00) ==
5811 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5815 /* Bypass reserved domain fields. */
5816 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5819 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5820 if (ql2xgffidenable &&
5821 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5822 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5825 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5827 /* Locate matching device in database. */
5829 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5830 if (memcmp(new_fcport->port_name, fcport->port_name,
5834 fcport->scan_state = QLA_FCPORT_FOUND;
5838 /* Update port state. */
5839 memcpy(fcport->fabric_port_name,
5840 new_fcport->fabric_port_name, WWN_SIZE);
5841 fcport->fp_speed = new_fcport->fp_speed;
5844 * If address the same and state FCS_ONLINE
5845 * (or in target mode), nothing changed.
5847 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5848 (atomic_read(&fcport->state) == FCS_ONLINE ||
5849 (vha->host->active_mode == MODE_TARGET))) {
5854 * If device was not a fabric device before.
5856 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5857 fcport->d_id.b24 = new_fcport->d_id.b24;
5858 qla2x00_clear_loop_id(fcport);
5859 fcport->flags |= (FCF_FABRIC_DEVICE |
5865 * Port ID changed or device was marked to be updated;
5866 * Log it out if still logged in and mark it for
5869 if (qla_tgt_mode_enabled(base_vha)) {
5870 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5871 "port changed FC ID, %8phC"
5872 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5874 fcport->d_id.b.domain,
5875 fcport->d_id.b.area,
5876 fcport->d_id.b.al_pa,
5878 new_fcport->d_id.b.domain,
5879 new_fcport->d_id.b.area,
5880 new_fcport->d_id.b.al_pa);
5881 fcport->d_id.b24 = new_fcport->d_id.b24;
5885 fcport->d_id.b24 = new_fcport->d_id.b24;
5886 fcport->flags |= FCF_LOGIN_NEEDED;
5890 if (fcport->fc4f_nvme) {
5891 if (fcport->disc_state == DSC_DELETE_PEND) {
5892 fcport->disc_state = DSC_GNL;
5893 vha->fcport_count--;
5894 fcport->login_succ = 0;
5899 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5902 /* If device was not in our fcports list, then add it. */
5903 new_fcport->scan_state = QLA_FCPORT_FOUND;
5904 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5906 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5909 /* Allocate a new replacement fcport. */
5910 nxt_d_id.b24 = new_fcport->d_id.b24;
5911 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5912 if (new_fcport == NULL) {
5913 ql_log(ql_log_warn, vha, 0xd032,
5914 "Memory allocation failed for fcport.\n");
5915 return (QLA_MEMORY_ALLOC_FAILED);
5917 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5918 new_fcport->d_id.b24 = nxt_d_id.b24;
5921 qla2x00_free_fcport(new_fcport);
5924 * Logout all previous fabric dev marked lost, except FCP2 devices.
5926 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5927 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5930 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5931 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5934 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5935 if ((qla_dual_mode_enabled(vha) ||
5936 qla_ini_mode_enabled(vha)) &&
5937 atomic_read(&fcport->state) == FCS_ONLINE) {
5938 qla2x00_mark_device_lost(vha, fcport,
5939 ql2xplogiabsentdevice, 0);
5940 if (fcport->loop_id != FC_NO_LOOP_ID &&
5941 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5942 fcport->port_type != FCT_INITIATOR &&
5943 fcport->port_type != FCT_BROADCAST) {
5944 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5945 "%s %d %8phC post del sess\n",
5948 qlt_schedule_sess_for_deletion(fcport);
5954 if (fcport->scan_state == QLA_FCPORT_FOUND)
5955 qla24xx_fcport_handle_login(vha, fcport);
5960 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5962 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5964 int loop_id = FC_NO_LOOP_ID;
5965 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5966 unsigned long flags;
5967 struct qla_hw_data *ha = vha->hw;
5969 if (vha->vp_idx == 0) {
5970 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5971 return NPH_MGMT_SERVER;
5974 /* pick id from high and work down to low */
5975 spin_lock_irqsave(&ha->vport_slock, flags);
5976 for (; lid > 0; lid--) {
5977 if (!test_bit(lid, vha->hw->loop_id_map)) {
5978 set_bit(lid, vha->hw->loop_id_map);
5983 spin_unlock_irqrestore(&ha->vport_slock, flags);
5989 * qla2x00_fabric_login
5990 * Issue fabric login command.
5993 * ha = adapter block pointer.
5994 * device = pointer to FC device type structure.
5997 * 0 - Login successfully
5999 * 2 - Initiator device
6003 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6004 uint16_t *next_loopid)
6008 uint16_t tmp_loopid;
6009 uint16_t mb[MAILBOX_REGISTER_COUNT];
6010 struct qla_hw_data *ha = vha->hw;
6016 ql_dbg(ql_dbg_disc, vha, 0x2000,
6017 "Trying Fabric Login w/loop id 0x%04x for port "
6019 fcport->loop_id, fcport->d_id.b.domain,
6020 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6022 /* Login fcport on switch. */
6023 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6024 fcport->d_id.b.domain, fcport->d_id.b.area,
6025 fcport->d_id.b.al_pa, mb, BIT_0);
6026 if (rval != QLA_SUCCESS) {
6029 if (mb[0] == MBS_PORT_ID_USED) {
6031 * Device has another loop ID. The firmware team
6032 * recommends the driver perform an implicit login with
6033 * the specified ID again. The ID we just used is save
6034 * here so we return with an ID that can be tried by
6038 tmp_loopid = fcport->loop_id;
6039 fcport->loop_id = mb[1];
6041 ql_dbg(ql_dbg_disc, vha, 0x2001,
6042 "Fabric Login: port in use - next loop "
6043 "id=0x%04x, port id= %02x%02x%02x.\n",
6044 fcport->loop_id, fcport->d_id.b.domain,
6045 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6047 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6052 /* A retry occurred before. */
6053 *next_loopid = tmp_loopid;
6056 * No retry occurred before. Just increment the
6057 * ID value for next login.
6059 *next_loopid = (fcport->loop_id + 1);
6062 if (mb[1] & BIT_0) {
6063 fcport->port_type = FCT_INITIATOR;
6065 fcport->port_type = FCT_TARGET;
6066 if (mb[1] & BIT_1) {
6067 fcport->flags |= FCF_FCP2_DEVICE;
6072 fcport->supported_classes |= FC_COS_CLASS2;
6074 fcport->supported_classes |= FC_COS_CLASS3;
6076 if (IS_FWI2_CAPABLE(ha)) {
6079 FCF_CONF_COMP_SUPPORTED;
6084 } else if (mb[0] == MBS_LOOP_ID_USED) {
6086 * Loop ID already used, try next loop ID.
6089 rval = qla2x00_find_new_loop_id(vha, fcport);
6090 if (rval != QLA_SUCCESS) {
6091 /* Ran out of loop IDs to use */
6094 } else if (mb[0] == MBS_COMMAND_ERROR) {
6096 * Firmware possibly timed out during login. If NO
6097 * retries are left to do then the device is declared
6100 *next_loopid = fcport->loop_id;
6101 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6102 fcport->d_id.b.domain, fcport->d_id.b.area,
6103 fcport->d_id.b.al_pa);
6104 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6110 * unrecoverable / not handled error
6112 ql_dbg(ql_dbg_disc, vha, 0x2002,
6113 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6114 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6115 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6116 fcport->loop_id, jiffies);
6118 *next_loopid = fcport->loop_id;
6119 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6120 fcport->d_id.b.domain, fcport->d_id.b.area,
6121 fcport->d_id.b.al_pa);
6122 qla2x00_clear_loop_id(fcport);
6123 fcport->login_retry = 0;
6134 * qla2x00_local_device_login
6135 * Issue local device login command.
6138 * ha = adapter block pointer.
6139 * loop_id = loop id of device to login to.
6141 * Returns (Where's the #define!!!!):
6142 * 0 - Login successfully
6147 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6150 uint16_t mb[MAILBOX_REGISTER_COUNT];
6152 memset(mb, 0, sizeof(mb));
6153 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6154 if (rval == QLA_SUCCESS) {
6155 /* Interrogate mailbox registers for any errors */
6156 if (mb[0] == MBS_COMMAND_ERROR)
6158 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6159 /* device not in PCB table */
6167 * qla2x00_loop_resync
6168 * Resync with fibre channel devices.
6171 * ha = adapter block pointer.
6177 qla2x00_loop_resync(scsi_qla_host_t *vha)
6179 int rval = QLA_SUCCESS;
6182 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6183 if (vha->flags.online) {
6184 if (!(rval = qla2x00_fw_ready(vha))) {
6185 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6188 if (!IS_QLAFX00(vha->hw)) {
6190 * Issue a marker after FW becomes
6193 qla2x00_marker(vha, vha->hw->base_qpair,
6195 vha->marker_needed = 0;
6198 /* Remap devices on Loop. */
6199 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6201 if (IS_QLAFX00(vha->hw))
6202 qlafx00_configure_devices(vha);
6204 qla2x00_configure_loop(vha);
6207 } while (!atomic_read(&vha->loop_down_timer) &&
6208 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6209 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6214 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6215 return (QLA_FUNCTION_FAILED);
6218 ql_dbg(ql_dbg_disc, vha, 0x206c,
6219 "%s *** FAILED ***.\n", __func__);
6225 * qla2x00_perform_loop_resync
6226 * Description: This function will set the appropriate flags and call
6227 * qla2x00_loop_resync. If successful loop will be resynced
6228 * Arguments : scsi_qla_host_t pointer
6229 * returm : Success or Failure
6232 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6236 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6237 /*Configure the flags so that resync happens properly*/
6238 atomic_set(&ha->loop_down_timer, 0);
6239 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6240 atomic_set(&ha->loop_state, LOOP_UP);
6241 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6242 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6243 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6245 rval = qla2x00_loop_resync(ha);
6247 atomic_set(&ha->loop_state, LOOP_DEAD);
6249 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6256 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6259 struct scsi_qla_host *vha;
6260 struct qla_hw_data *ha = base_vha->hw;
6261 unsigned long flags;
6263 spin_lock_irqsave(&ha->vport_slock, flags);
6264 /* Go with deferred removal of rport references. */
6265 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6266 atomic_inc(&vha->vref_count);
6267 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6268 if (fcport->drport &&
6269 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6270 spin_unlock_irqrestore(&ha->vport_slock, flags);
6271 qla2x00_rport_del(fcport);
6273 spin_lock_irqsave(&ha->vport_slock, flags);
6276 atomic_dec(&vha->vref_count);
6277 wake_up(&vha->vref_waitq);
6279 spin_unlock_irqrestore(&ha->vport_slock, flags);
6282 /* Assumes idc_lock always held on entry */
6284 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6286 struct qla_hw_data *ha = vha->hw;
6287 uint32_t drv_presence, drv_presence_mask;
6288 uint32_t dev_part_info1, dev_part_info2, class_type;
6289 uint32_t class_type_mask = 0x3;
6290 uint16_t fcoe_other_function = 0xffff, i;
6292 if (IS_QLA8044(ha)) {
6293 drv_presence = qla8044_rd_direct(vha,
6294 QLA8044_CRB_DRV_ACTIVE_INDEX);
6295 dev_part_info1 = qla8044_rd_direct(vha,
6296 QLA8044_CRB_DEV_PART_INFO_INDEX);
6297 dev_part_info2 = qla8044_rd_direct(vha,
6298 QLA8044_CRB_DEV_PART_INFO2);
6300 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6301 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6302 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6304 for (i = 0; i < 8; i++) {
6305 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6306 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6307 (i != ha->portnum)) {
6308 fcoe_other_function = i;
6312 if (fcoe_other_function == 0xffff) {
6313 for (i = 0; i < 8; i++) {
6314 class_type = ((dev_part_info2 >> (i * 4)) &
6316 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6317 ((i + 8) != ha->portnum)) {
6318 fcoe_other_function = i + 8;
6324 * Prepare drv-presence mask based on fcoe functions present.
6325 * However consider only valid physical fcoe function numbers (0-15).
6327 drv_presence_mask = ~((1 << (ha->portnum)) |
6328 ((fcoe_other_function == 0xffff) ?
6329 0 : (1 << (fcoe_other_function))));
6331 /* We are the reset owner iff:
6332 * - No other protocol drivers present.
6333 * - This is the lowest among fcoe functions. */
6334 if (!(drv_presence & drv_presence_mask) &&
6335 (ha->portnum < fcoe_other_function)) {
6336 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6337 "This host is Reset owner.\n");
6338 ha->flags.nic_core_reset_owner = 1;
6343 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6345 int rval = QLA_SUCCESS;
6346 struct qla_hw_data *ha = vha->hw;
6349 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6350 if (rval == QLA_SUCCESS) {
6351 drv_ack |= (1 << ha->portnum);
6352 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6359 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6361 int rval = QLA_SUCCESS;
6362 struct qla_hw_data *ha = vha->hw;
6365 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6366 if (rval == QLA_SUCCESS) {
6367 drv_ack &= ~(1 << ha->portnum);
6368 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6375 qla83xx_dev_state_to_string(uint32_t dev_state)
6377 switch (dev_state) {
6378 case QLA8XXX_DEV_COLD:
6379 return "COLD/RE-INIT";
6380 case QLA8XXX_DEV_INITIALIZING:
6381 return "INITIALIZING";
6382 case QLA8XXX_DEV_READY:
6384 case QLA8XXX_DEV_NEED_RESET:
6385 return "NEED RESET";
6386 case QLA8XXX_DEV_NEED_QUIESCENT:
6387 return "NEED QUIESCENT";
6388 case QLA8XXX_DEV_FAILED:
6390 case QLA8XXX_DEV_QUIESCENT:
6397 /* Assumes idc-lock always held on entry */
6399 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6401 struct qla_hw_data *ha = vha->hw;
6402 uint32_t idc_audit_reg = 0, duration_secs = 0;
6404 switch (audit_type) {
6405 case IDC_AUDIT_TIMESTAMP:
6406 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6407 idc_audit_reg = (ha->portnum) |
6408 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6409 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6412 case IDC_AUDIT_COMPLETION:
6413 duration_secs = ((jiffies_to_msecs(jiffies) -
6414 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6415 idc_audit_reg = (ha->portnum) |
6416 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6417 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6421 ql_log(ql_log_warn, vha, 0xb078,
6422 "Invalid audit type specified.\n");
6427 /* Assumes idc_lock always held on entry */
6429 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6431 struct qla_hw_data *ha = vha->hw;
6432 uint32_t idc_control, dev_state;
6434 __qla83xx_get_idc_control(vha, &idc_control);
6435 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6436 ql_log(ql_log_info, vha, 0xb080,
6437 "NIC Core reset has been disabled. idc-control=0x%x\n",
6439 return QLA_FUNCTION_FAILED;
6442 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6443 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6444 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6445 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6446 QLA8XXX_DEV_NEED_RESET);
6447 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6448 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6450 const char *state = qla83xx_dev_state_to_string(dev_state);
6452 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6454 /* SV: XXX: Is timeout required here? */
6455 /* Wait for IDC state change READY -> NEED_RESET */
6456 while (dev_state == QLA8XXX_DEV_READY) {
6457 qla83xx_idc_unlock(vha, 0);
6459 qla83xx_idc_lock(vha, 0);
6460 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6464 /* Send IDC ack by writing to drv-ack register */
6465 __qla83xx_set_drv_ack(vha);
6471 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6473 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6477 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6479 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6483 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6485 uint32_t drv_presence = 0;
6486 struct qla_hw_data *ha = vha->hw;
6488 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6489 if (drv_presence & (1 << ha->portnum))
6492 return QLA_TEST_FAILED;
6496 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6498 int rval = QLA_SUCCESS;
6499 struct qla_hw_data *ha = vha->hw;
6501 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6502 "Entered %s().\n", __func__);
6504 if (vha->device_flags & DFLG_DEV_FAILED) {
6505 ql_log(ql_log_warn, vha, 0xb059,
6506 "Device in unrecoverable FAILED state.\n");
6507 return QLA_FUNCTION_FAILED;
6510 qla83xx_idc_lock(vha, 0);
6512 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6513 ql_log(ql_log_warn, vha, 0xb05a,
6514 "Function=0x%x has been removed from IDC participation.\n",
6516 rval = QLA_FUNCTION_FAILED;
6520 qla83xx_reset_ownership(vha);
6522 rval = qla83xx_initiating_reset(vha);
6525 * Perform reset if we are the reset-owner,
6526 * else wait till IDC state changes to READY/FAILED.
6528 if (rval == QLA_SUCCESS) {
6529 rval = qla83xx_idc_state_handler(vha);
6531 if (rval == QLA_SUCCESS)
6532 ha->flags.nic_core_hung = 0;
6533 __qla83xx_clear_drv_ack(vha);
6537 qla83xx_idc_unlock(vha, 0);
6539 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6545 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6547 struct qla_hw_data *ha = vha->hw;
6548 int rval = QLA_FUNCTION_FAILED;
6550 if (!IS_MCTP_CAPABLE(ha)) {
6551 /* This message can be removed from the final version */
6552 ql_log(ql_log_info, vha, 0x506d,
6553 "This board is not MCTP capable\n");
6557 if (!ha->mctp_dump) {
6558 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6559 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6561 if (!ha->mctp_dump) {
6562 ql_log(ql_log_warn, vha, 0x506e,
6563 "Failed to allocate memory for mctp dump\n");
6568 #define MCTP_DUMP_STR_ADDR 0x00000000
6569 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6570 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6571 if (rval != QLA_SUCCESS) {
6572 ql_log(ql_log_warn, vha, 0x506f,
6573 "Failed to capture mctp dump\n");
6575 ql_log(ql_log_info, vha, 0x5070,
6576 "Mctp dump capture for host (%ld/%p).\n",
6577 vha->host_no, ha->mctp_dump);
6578 ha->mctp_dumped = 1;
6581 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6582 ha->flags.nic_core_reset_hdlr_active = 1;
6583 rval = qla83xx_restart_nic_firmware(vha);
6585 /* NIC Core reset failed. */
6586 ql_log(ql_log_warn, vha, 0x5071,
6587 "Failed to restart nic firmware\n");
6589 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6590 "Restarted NIC firmware successfully.\n");
6591 ha->flags.nic_core_reset_hdlr_active = 0;
6599 * qla2x00_quiesce_io
6600 * Description: This function will block the new I/Os
6601 * Its not aborting any I/Os as context
6602 * is not destroyed during quiescence
6603 * Arguments: scsi_qla_host_t
6607 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6609 struct qla_hw_data *ha = vha->hw;
6610 struct scsi_qla_host *vp;
6612 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6613 "Quiescing I/O - ha=%p.\n", ha);
6615 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6616 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6617 atomic_set(&vha->loop_state, LOOP_DOWN);
6618 qla2x00_mark_all_devices_lost(vha, 0);
6619 list_for_each_entry(vp, &ha->vp_list, list)
6620 qla2x00_mark_all_devices_lost(vp, 0);
6622 if (!atomic_read(&vha->loop_down_timer))
6623 atomic_set(&vha->loop_down_timer,
6626 /* Wait for pending cmds to complete */
6627 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6631 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6633 struct qla_hw_data *ha = vha->hw;
6634 struct scsi_qla_host *vp;
6635 unsigned long flags;
6639 /* For ISP82XX, driver waits for completion of the commands.
6640 * online flag should be set.
6642 if (!(IS_P3P_TYPE(ha)))
6643 vha->flags.online = 0;
6644 ha->flags.chip_reset_done = 0;
6645 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6646 vha->qla_stats.total_isp_aborts++;
6648 ql_log(ql_log_info, vha, 0x00af,
6649 "Performing ISP error recovery - ha=%p.\n", ha);
6651 ha->flags.purge_mbox = 1;
6652 /* For ISP82XX, reset_chip is just disabling interrupts.
6653 * Driver waits for the completion of the commands.
6654 * the interrupts need to be enabled.
6656 if (!(IS_P3P_TYPE(ha)))
6657 ha->isp_ops->reset_chip(vha);
6659 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6661 ha->flags.rida_fmt2 = 0;
6662 ha->flags.n2n_ae = 0;
6663 ha->flags.lip_ae = 0;
6664 ha->current_topology = 0;
6665 ha->flags.fw_started = 0;
6666 ha->flags.fw_init_done = 0;
6668 ha->base_qpair->chip_reset = ha->chip_reset;
6669 for (i = 0; i < ha->max_qpairs; i++) {
6670 if (ha->queue_pair_map[i])
6671 ha->queue_pair_map[i]->chip_reset =
6672 ha->base_qpair->chip_reset;
6675 /* purge MBox commands */
6676 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6677 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6678 complete(&ha->mbx_intr_comp);
6682 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6683 atomic_read(&ha->num_pend_mbx_stage2) ||
6684 atomic_read(&ha->num_pend_mbx_stage1)) {
6690 ha->flags.purge_mbox = 0;
6692 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6693 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6694 atomic_set(&vha->loop_state, LOOP_DOWN);
6695 qla2x00_mark_all_devices_lost(vha, 0);
6697 spin_lock_irqsave(&ha->vport_slock, flags);
6698 list_for_each_entry(vp, &ha->vp_list, list) {
6699 atomic_inc(&vp->vref_count);
6700 spin_unlock_irqrestore(&ha->vport_slock, flags);
6702 qla2x00_mark_all_devices_lost(vp, 0);
6704 spin_lock_irqsave(&ha->vport_slock, flags);
6705 atomic_dec(&vp->vref_count);
6707 spin_unlock_irqrestore(&ha->vport_slock, flags);
6709 if (!atomic_read(&vha->loop_down_timer))
6710 atomic_set(&vha->loop_down_timer,
6714 /* Clear all async request states across all VPs. */
6715 list_for_each_entry(fcport, &vha->vp_fcports, list)
6716 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6717 spin_lock_irqsave(&ha->vport_slock, flags);
6718 list_for_each_entry(vp, &ha->vp_list, list) {
6719 atomic_inc(&vp->vref_count);
6720 spin_unlock_irqrestore(&ha->vport_slock, flags);
6722 list_for_each_entry(fcport, &vp->vp_fcports, list)
6723 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6725 spin_lock_irqsave(&ha->vport_slock, flags);
6726 atomic_dec(&vp->vref_count);
6728 spin_unlock_irqrestore(&ha->vport_slock, flags);
6730 if (!ha->flags.eeh_busy) {
6731 /* Make sure for ISP 82XX IO DMA is complete */
6732 if (IS_P3P_TYPE(ha)) {
6733 qla82xx_chip_reset_cleanup(vha);
6734 ql_log(ql_log_info, vha, 0x00b4,
6735 "Done chip reset cleanup.\n");
6737 /* Done waiting for pending commands.
6738 * Reset the online flag.
6740 vha->flags.online = 0;
6743 /* Requeue all commands in outstanding command list. */
6744 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6746 /* memory barrier */
6752 * Resets ISP and aborts all outstanding commands.
6755 * ha = adapter block pointer.
6761 qla2x00_abort_isp(scsi_qla_host_t *vha)
6765 struct qla_hw_data *ha = vha->hw;
6766 struct scsi_qla_host *vp;
6767 struct req_que *req = ha->req_q_map[0];
6768 unsigned long flags;
6770 if (vha->flags.online) {
6771 qla2x00_abort_isp_cleanup(vha);
6773 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6774 ha->flags.chip_reset_done = 1;
6775 vha->flags.online = 1;
6777 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6781 if (IS_QLA8031(ha)) {
6782 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6783 "Clearing fcoe driver presence.\n");
6784 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6785 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6786 "Error while clearing DRV-Presence.\n");
6789 if (unlikely(pci_channel_offline(ha->pdev) &&
6790 ha->flags.pci_channel_io_perm_failure)) {
6791 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6796 switch (vha->qlini_mode) {
6797 case QLA2XXX_INI_MODE_DISABLED:
6798 if (!qla_tgt_mode_enabled(vha))
6801 case QLA2XXX_INI_MODE_DUAL:
6802 if (!qla_dual_mode_enabled(vha))
6805 case QLA2XXX_INI_MODE_ENABLED:
6810 ha->isp_ops->get_flash_version(vha, req->ring);
6812 ha->isp_ops->nvram_config(vha);
6814 if (!qla2x00_restart_isp(vha)) {
6815 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6817 if (!atomic_read(&vha->loop_down_timer)) {
6819 * Issue marker command only when we are going
6820 * to start the I/O .
6822 vha->marker_needed = 1;
6825 vha->flags.online = 1;
6827 ha->isp_ops->enable_intrs(ha);
6829 ha->isp_abort_cnt = 0;
6830 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6832 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6833 qla2x00_get_fw_version(vha);
6835 ha->flags.fce_enabled = 1;
6837 fce_calc_size(ha->fce_bufs));
6838 rval = qla2x00_enable_fce_trace(vha,
6839 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6842 ql_log(ql_log_warn, vha, 0x8033,
6843 "Unable to reinitialize FCE "
6845 ha->flags.fce_enabled = 0;
6850 memset(ha->eft, 0, EFT_SIZE);
6851 rval = qla2x00_enable_eft_trace(vha,
6852 ha->eft_dma, EFT_NUM_BUFFERS);
6854 ql_log(ql_log_warn, vha, 0x8034,
6855 "Unable to reinitialize EFT "
6859 } else { /* failed the ISP abort */
6860 vha->flags.online = 1;
6861 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6862 if (ha->isp_abort_cnt == 0) {
6863 ql_log(ql_log_fatal, vha, 0x8035,
6864 "ISP error recover failed - "
6865 "board disabled.\n");
6867 * The next call disables the board
6870 qla2x00_abort_isp_cleanup(vha);
6871 vha->flags.online = 0;
6872 clear_bit(ISP_ABORT_RETRY,
6875 } else { /* schedule another ISP abort */
6876 ha->isp_abort_cnt--;
6877 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6878 "ISP abort - retry remaining %d.\n",
6883 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6884 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6885 "ISP error recovery - retrying (%d) "
6886 "more times.\n", ha->isp_abort_cnt);
6887 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6895 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6896 qla2x00_configure_hba(vha);
6897 spin_lock_irqsave(&ha->vport_slock, flags);
6898 list_for_each_entry(vp, &ha->vp_list, list) {
6900 atomic_inc(&vp->vref_count);
6901 spin_unlock_irqrestore(&ha->vport_slock, flags);
6903 qla2x00_vp_abort_isp(vp);
6905 spin_lock_irqsave(&ha->vport_slock, flags);
6906 atomic_dec(&vp->vref_count);
6909 spin_unlock_irqrestore(&ha->vport_slock, flags);
6911 if (IS_QLA8031(ha)) {
6912 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6913 "Setting back fcoe driver presence.\n");
6914 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6915 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6916 "Error while setting DRV-Presence.\n");
6919 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6927 * qla2x00_restart_isp
6928 * restarts the ISP after a reset
6931 * ha = adapter block pointer.
6937 qla2x00_restart_isp(scsi_qla_host_t *vha)
6940 struct qla_hw_data *ha = vha->hw;
6942 /* If firmware needs to be loaded */
6943 if (qla2x00_isp_firmware(vha)) {
6944 vha->flags.online = 0;
6945 status = ha->isp_ops->chip_diag(vha);
6947 status = qla2x00_setup_chip(vha);
6950 if (!status && !(status = qla2x00_init_rings(vha))) {
6951 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6952 ha->flags.chip_reset_done = 1;
6954 /* Initialize the queues in use */
6955 qla25xx_init_queues(ha);
6957 status = qla2x00_fw_ready(vha);
6959 /* Issue a marker after FW becomes ready. */
6960 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
6961 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6964 /* if no cable then assume it's good */
6965 if ((vha->device_flags & DFLG_NO_CABLE))
6972 qla25xx_init_queues(struct qla_hw_data *ha)
6974 struct rsp_que *rsp = NULL;
6975 struct req_que *req = NULL;
6976 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6980 for (i = 1; i < ha->max_rsp_queues; i++) {
6981 rsp = ha->rsp_q_map[i];
6982 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6983 rsp->options &= ~BIT_0;
6984 ret = qla25xx_init_rsp_que(base_vha, rsp);
6985 if (ret != QLA_SUCCESS)
6986 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6987 "%s Rsp que: %d init failed.\n",
6990 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6991 "%s Rsp que: %d inited.\n",
6995 for (i = 1; i < ha->max_req_queues; i++) {
6996 req = ha->req_q_map[i];
6997 if (req && test_bit(i, ha->req_qid_map)) {
6998 /* Clear outstanding commands array. */
6999 req->options &= ~BIT_0;
7000 ret = qla25xx_init_req_que(base_vha, req);
7001 if (ret != QLA_SUCCESS)
7002 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7003 "%s Req que: %d init failed.\n",
7006 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7007 "%s Req que: %d inited.\n",
7015 * qla2x00_reset_adapter
7019 * ha = adapter block pointer.
7022 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7024 unsigned long flags = 0;
7025 struct qla_hw_data *ha = vha->hw;
7026 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7028 vha->flags.online = 0;
7029 ha->isp_ops->disable_intrs(ha);
7031 spin_lock_irqsave(&ha->hardware_lock, flags);
7032 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7033 RD_REG_WORD(®->hccr); /* PCI Posting. */
7034 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7035 RD_REG_WORD(®->hccr); /* PCI Posting. */
7036 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7042 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7044 unsigned long flags = 0;
7045 struct qla_hw_data *ha = vha->hw;
7046 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7047 int rval = QLA_SUCCESS;
7049 if (IS_P3P_TYPE(ha))
7052 vha->flags.online = 0;
7053 ha->isp_ops->disable_intrs(ha);
7055 spin_lock_irqsave(&ha->hardware_lock, flags);
7056 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7057 RD_REG_DWORD(®->hccr);
7058 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7059 RD_REG_DWORD(®->hccr);
7060 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7062 if (IS_NOPOLLING_TYPE(ha))
7063 ha->isp_ops->enable_intrs(ha);
7068 /* On sparc systems, obtain port and node WWN from firmware
7071 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7072 struct nvram_24xx *nv)
7075 struct qla_hw_data *ha = vha->hw;
7076 struct pci_dev *pdev = ha->pdev;
7077 struct device_node *dp = pci_device_to_OF_node(pdev);
7081 val = of_get_property(dp, "port-wwn", &len);
7082 if (val && len >= WWN_SIZE)
7083 memcpy(nv->port_name, val, WWN_SIZE);
7085 val = of_get_property(dp, "node-wwn", &len);
7086 if (val && len >= WWN_SIZE)
7087 memcpy(nv->node_name, val, WWN_SIZE);
7092 qla24xx_nvram_config(scsi_qla_host_t *vha)
7095 struct init_cb_24xx *icb;
7096 struct nvram_24xx *nv;
7098 uint8_t *dptr1, *dptr2;
7101 struct qla_hw_data *ha = vha->hw;
7104 icb = (struct init_cb_24xx *)ha->init_cb;
7107 /* Determine NVRAM starting address. */
7108 if (ha->port_no == 0) {
7109 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7110 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7112 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7113 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7116 ha->nvram_size = sizeof(*nv);
7117 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7119 /* Get VPD data into cache */
7120 ha->vpd = ha->nvram + VPD_OFFSET;
7121 ha->isp_ops->read_nvram(vha, ha->vpd,
7122 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7124 /* Get NVRAM data into cache and calculate checksum. */
7125 dptr = (uint32_t *)nv;
7126 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7127 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7128 chksum += le32_to_cpu(*dptr);
7130 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7131 "Contents of NVRAM\n");
7132 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7133 nv, ha->nvram_size);
7135 /* Bad NVRAM data, set defaults parameters. */
7136 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7137 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7138 /* Reset NVRAM data. */
7139 ql_log(ql_log_warn, vha, 0x006b,
7140 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7141 chksum, nv->id, nv->nvram_version);
7142 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7143 ql_log(ql_log_warn, vha, 0x006c,
7144 "Falling back to functioning (yet invalid -- WWPN) "
7148 * Set default initialization control block.
7150 memset(nv, 0, ha->nvram_size);
7151 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7152 nv->version = cpu_to_le16(ICB_VERSION);
7153 nv->frame_payload_size = 2048;
7154 nv->execution_throttle = cpu_to_le16(0xFFFF);
7155 nv->exchange_count = cpu_to_le16(0);
7156 nv->hard_address = cpu_to_le16(124);
7157 nv->port_name[0] = 0x21;
7158 nv->port_name[1] = 0x00 + ha->port_no + 1;
7159 nv->port_name[2] = 0x00;
7160 nv->port_name[3] = 0xe0;
7161 nv->port_name[4] = 0x8b;
7162 nv->port_name[5] = 0x1c;
7163 nv->port_name[6] = 0x55;
7164 nv->port_name[7] = 0x86;
7165 nv->node_name[0] = 0x20;
7166 nv->node_name[1] = 0x00;
7167 nv->node_name[2] = 0x00;
7168 nv->node_name[3] = 0xe0;
7169 nv->node_name[4] = 0x8b;
7170 nv->node_name[5] = 0x1c;
7171 nv->node_name[6] = 0x55;
7172 nv->node_name[7] = 0x86;
7173 qla24xx_nvram_wwn_from_ofw(vha, nv);
7174 nv->login_retry_count = cpu_to_le16(8);
7175 nv->interrupt_delay_timer = cpu_to_le16(0);
7176 nv->login_timeout = cpu_to_le16(0);
7177 nv->firmware_options_1 =
7178 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7179 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7180 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7181 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7182 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7183 nv->efi_parameters = cpu_to_le32(0);
7184 nv->reset_delay = 5;
7185 nv->max_luns_per_target = cpu_to_le16(128);
7186 nv->port_down_retry_count = cpu_to_le16(30);
7187 nv->link_down_timeout = cpu_to_le16(30);
7192 if (qla_tgt_mode_enabled(vha)) {
7193 /* Don't enable full login after initial LIP */
7194 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7195 /* Don't enable LIP full login for initiator */
7196 nv->host_p &= cpu_to_le32(~BIT_10);
7199 qlt_24xx_config_nvram_stage1(vha, nv);
7201 /* Reset Initialization control block */
7202 memset(icb, 0, ha->init_cb_size);
7204 /* Copy 1st segment. */
7205 dptr1 = (uint8_t *)icb;
7206 dptr2 = (uint8_t *)&nv->version;
7207 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7209 *dptr1++ = *dptr2++;
7211 icb->login_retry_count = nv->login_retry_count;
7212 icb->link_down_on_nos = nv->link_down_on_nos;
7214 /* Copy 2nd segment. */
7215 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7216 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7217 cnt = (uint8_t *)&icb->reserved_3 -
7218 (uint8_t *)&icb->interrupt_delay_timer;
7220 *dptr1++ = *dptr2++;
7221 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7223 * Setup driver NVRAM options.
7225 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7228 qlt_24xx_config_nvram_stage2(vha, icb);
7230 if (nv->host_p & cpu_to_le32(BIT_15)) {
7231 /* Use alternate WWN? */
7232 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7233 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7236 /* Prepare nodename */
7237 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7239 * Firmware will apply the following mask if the nodename was
7242 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7243 icb->node_name[0] &= 0xF0;
7246 /* Set host adapter parameters. */
7247 ha->flags.disable_risc_code_load = 0;
7248 ha->flags.enable_lip_reset = 0;
7249 ha->flags.enable_lip_full_login =
7250 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7251 ha->flags.enable_target_reset =
7252 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7253 ha->flags.enable_led_scheme = 0;
7254 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7256 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7257 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7259 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7260 sizeof(ha->fw_seriallink_options24));
7262 /* save HBA serial number */
7263 ha->serial0 = icb->port_name[5];
7264 ha->serial1 = icb->port_name[6];
7265 ha->serial2 = icb->port_name[7];
7266 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7267 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7269 icb->execution_throttle = cpu_to_le16(0xFFFF);
7271 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7273 /* Set minimum login_timeout to 4 seconds. */
7274 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7275 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7276 if (le16_to_cpu(nv->login_timeout) < 4)
7277 nv->login_timeout = cpu_to_le16(4);
7278 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7280 /* Set minimum RATOV to 100 tenths of a second. */
7283 ha->loop_reset_delay = nv->reset_delay;
7285 /* Link Down Timeout = 0:
7287 * When Port Down timer expires we will start returning
7288 * I/O's to OS with "DID_NO_CONNECT".
7290 * Link Down Timeout != 0:
7292 * The driver waits for the link to come up after link down
7293 * before returning I/Os to OS with "DID_NO_CONNECT".
7295 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7296 ha->loop_down_abort_time =
7297 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7299 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7300 ha->loop_down_abort_time =
7301 (LOOP_DOWN_TIME - ha->link_down_timeout);
7304 /* Need enough time to try and get the port back. */
7305 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7306 if (qlport_down_retry)
7307 ha->port_down_retry_count = qlport_down_retry;
7309 /* Set login_retry_count */
7310 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7311 if (ha->port_down_retry_count ==
7312 le16_to_cpu(nv->port_down_retry_count) &&
7313 ha->port_down_retry_count > 3)
7314 ha->login_retry_count = ha->port_down_retry_count;
7315 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7316 ha->login_retry_count = ha->port_down_retry_count;
7317 if (ql2xloginretrycount)
7318 ha->login_retry_count = ql2xloginretrycount;
7320 /* N2N: driver will initiate Login instead of FW */
7321 icb->firmware_options_3 |= BIT_8;
7324 if (!vha->flags.init_done) {
7325 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7326 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7327 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7328 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7330 icb->firmware_options_2 &= cpu_to_le32(
7331 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7332 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7333 ha->zio_mode = QLA_ZIO_MODE_6;
7335 ql_log(ql_log_info, vha, 0x006f,
7336 "ZIO mode %d enabled; timer delay (%d us).\n",
7337 ha->zio_mode, ha->zio_timer * 100);
7339 icb->firmware_options_2 |= cpu_to_le32(
7340 (uint32_t)ha->zio_mode);
7341 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7345 ql_log(ql_log_warn, vha, 0x0070,
7346 "NVRAM configuration failed.\n");
7352 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7353 struct qla27xx_image_status *image_status)
7355 ql_dbg(ql_dbg_init, vha, 0x018b,
7356 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7358 image_status->image_status_mask,
7359 le16_to_cpu(image_status->generation),
7360 image_status->ver_major,
7361 image_status->ver_minor,
7362 image_status->bitmap,
7363 le32_to_cpu(image_status->checksum),
7364 le32_to_cpu(image_status->signature));
7368 qla28xx_check_aux_image_status_signature(
7369 struct qla27xx_image_status *image_status)
7371 ulong signature = le32_to_cpu(image_status->signature);
7373 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7377 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7379 ulong signature = le32_to_cpu(image_status->signature);
7382 signature != QLA27XX_IMG_STATUS_SIGN &&
7383 signature != QLA28XX_IMG_STATUS_SIGN;
7387 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7389 uint32_t *p = (void *)image_status;
7390 uint n = sizeof(*image_status) / sizeof(*p);
7394 sum += le32_to_cpup(p);
7400 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7402 return aux->bitmap & bitmask ?
7403 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7407 qla28xx_component_status(
7408 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7410 active_regions->aux.board_config =
7411 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7413 active_regions->aux.vpd_nvram =
7414 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7416 active_regions->aux.npiv_config_0_1 =
7417 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7419 active_regions->aux.npiv_config_2_3 =
7420 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7424 qla27xx_compare_image_generation(
7425 struct qla27xx_image_status *pri_image_status,
7426 struct qla27xx_image_status *sec_image_status)
7428 /* calculate generation delta as uint16 (this accounts for wrap) */
7430 le16_to_cpu(pri_image_status->generation) -
7431 le16_to_cpu(sec_image_status->generation);
7433 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7439 qla28xx_get_aux_images(
7440 struct scsi_qla_host *vha, struct active_regions *active_regions)
7442 struct qla_hw_data *ha = vha->hw;
7443 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7444 bool valid_pri_image = false, valid_sec_image = false;
7445 bool active_pri_image = false, active_sec_image = false;
7447 if (!ha->flt_region_aux_img_status_pri) {
7448 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7449 goto check_sec_image;
7452 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7453 ha->flt_region_aux_img_status_pri,
7454 sizeof(pri_aux_image_status) >> 2);
7455 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7457 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7458 ql_dbg(ql_dbg_init, vha, 0x018b,
7459 "Primary aux image signature (%#x) not valid\n",
7460 le32_to_cpu(pri_aux_image_status.signature));
7461 goto check_sec_image;
7464 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7465 ql_dbg(ql_dbg_init, vha, 0x018c,
7466 "Primary aux image checksum failed\n");
7467 goto check_sec_image;
7470 valid_pri_image = true;
7472 if (pri_aux_image_status.image_status_mask & 1) {
7473 ql_dbg(ql_dbg_init, vha, 0x018d,
7474 "Primary aux image is active\n");
7475 active_pri_image = true;
7479 if (!ha->flt_region_aux_img_status_sec) {
7480 ql_dbg(ql_dbg_init, vha, 0x018a,
7481 "Secondary aux image not addressed\n");
7482 goto check_valid_image;
7485 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7486 ha->flt_region_aux_img_status_sec,
7487 sizeof(sec_aux_image_status) >> 2);
7488 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7490 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7491 ql_dbg(ql_dbg_init, vha, 0x018b,
7492 "Secondary aux image signature (%#x) not valid\n",
7493 le32_to_cpu(sec_aux_image_status.signature));
7494 goto check_valid_image;
7497 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7498 ql_dbg(ql_dbg_init, vha, 0x018c,
7499 "Secondary aux image checksum failed\n");
7500 goto check_valid_image;
7503 valid_sec_image = true;
7505 if (sec_aux_image_status.image_status_mask & 1) {
7506 ql_dbg(ql_dbg_init, vha, 0x018d,
7507 "Secondary aux image is active\n");
7508 active_sec_image = true;
7512 if (valid_pri_image && active_pri_image &&
7513 valid_sec_image && active_sec_image) {
7514 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7515 &sec_aux_image_status) >= 0) {
7516 qla28xx_component_status(active_regions,
7517 &pri_aux_image_status);
7519 qla28xx_component_status(active_regions,
7520 &sec_aux_image_status);
7522 } else if (valid_pri_image && active_pri_image) {
7523 qla28xx_component_status(active_regions, &pri_aux_image_status);
7524 } else if (valid_sec_image && active_sec_image) {
7525 qla28xx_component_status(active_regions, &sec_aux_image_status);
7528 ql_dbg(ql_dbg_init, vha, 0x018f,
7529 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7530 active_regions->aux.board_config,
7531 active_regions->aux.vpd_nvram,
7532 active_regions->aux.npiv_config_0_1,
7533 active_regions->aux.npiv_config_2_3);
7537 qla27xx_get_active_image(struct scsi_qla_host *vha,
7538 struct active_regions *active_regions)
7540 struct qla_hw_data *ha = vha->hw;
7541 struct qla27xx_image_status pri_image_status, sec_image_status;
7542 bool valid_pri_image = false, valid_sec_image = false;
7543 bool active_pri_image = false, active_sec_image = false;
7545 if (!ha->flt_region_img_status_pri) {
7546 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7547 goto check_sec_image;
7550 qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7551 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2);
7552 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7554 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7555 ql_dbg(ql_dbg_init, vha, 0x018b,
7556 "Primary image signature (%#x) not valid\n",
7557 le32_to_cpu(pri_image_status.signature));
7558 goto check_sec_image;
7561 if (qla27xx_image_status_checksum(&pri_image_status)) {
7562 ql_dbg(ql_dbg_init, vha, 0x018c,
7563 "Primary image checksum failed\n");
7564 goto check_sec_image;
7567 valid_pri_image = true;
7569 if (pri_image_status.image_status_mask & 1) {
7570 ql_dbg(ql_dbg_init, vha, 0x018d,
7571 "Primary image is active\n");
7572 active_pri_image = true;
7576 if (!ha->flt_region_img_status_sec) {
7577 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7578 goto check_valid_image;
7581 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7582 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7583 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7585 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7586 ql_dbg(ql_dbg_init, vha, 0x018b,
7587 "Secondary image signature (%#x) not valid\n",
7588 le32_to_cpu(sec_image_status.signature));
7589 goto check_valid_image;
7592 if (qla27xx_image_status_checksum(&sec_image_status)) {
7593 ql_dbg(ql_dbg_init, vha, 0x018c,
7594 "Secondary image checksum failed\n");
7595 goto check_valid_image;
7598 valid_sec_image = true;
7600 if (sec_image_status.image_status_mask & 1) {
7601 ql_dbg(ql_dbg_init, vha, 0x018d,
7602 "Secondary image is active\n");
7603 active_sec_image = true;
7607 if (valid_pri_image && active_pri_image)
7608 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7610 if (valid_sec_image && active_sec_image) {
7611 if (!active_regions->global ||
7612 qla27xx_compare_image_generation(
7613 &pri_image_status, &sec_image_status) < 0) {
7614 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7618 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7619 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7620 "default (boot/fw)" :
7621 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7623 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7624 "secondary" : "invalid",
7625 active_regions->global);
7628 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7631 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7632 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7636 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7640 uint templates, segments, fragment;
7645 uint32_t risc_addr, risc_size, risc_attr = 0;
7646 struct qla_hw_data *ha = vha->hw;
7647 struct req_que *req = ha->req_q_map[0];
7648 struct fwdt *fwdt = ha->fwdt;
7650 ql_dbg(ql_dbg_init, vha, 0x008b,
7651 "FW: Loading firmware from flash (%x).\n", faddr);
7653 dcode = (void *)req->ring;
7654 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7655 if (qla24xx_risc_firmware_invalid(dcode)) {
7656 ql_log(ql_log_fatal, vha, 0x008c,
7657 "Unable to verify the integrity of flash firmware "
7659 ql_log(ql_log_fatal, vha, 0x008d,
7660 "Firmware data: %08x %08x %08x %08x.\n",
7661 dcode[0], dcode[1], dcode[2], dcode[3]);
7663 return QLA_FUNCTION_FAILED;
7666 dcode = (void *)req->ring;
7668 segments = FA_RISC_CODE_SEGMENTS;
7669 for (j = 0; j < segments; j++) {
7670 ql_dbg(ql_dbg_init, vha, 0x008d,
7671 "-> Loading segment %u...\n", j);
7672 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7673 risc_addr = be32_to_cpu(dcode[2]);
7674 risc_size = be32_to_cpu(dcode[3]);
7676 *srisc_addr = risc_addr;
7677 risc_attr = be32_to_cpu(dcode[9]);
7680 dlen = ha->fw_transfer_size >> 2;
7681 for (fragment = 0; risc_size; fragment++) {
7682 if (dlen > risc_size)
7685 ql_dbg(ql_dbg_init, vha, 0x008e,
7686 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7687 fragment, risc_addr, faddr, dlen);
7688 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7689 for (i = 0; i < dlen; i++)
7690 dcode[i] = swab32(dcode[i]);
7692 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7694 ql_log(ql_log_fatal, vha, 0x008f,
7695 "-> Failed load firmware fragment %u.\n",
7697 return QLA_FUNCTION_FAILED;
7706 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7709 templates = (risc_attr & BIT_9) ? 2 : 1;
7710 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7711 for (j = 0; j < templates; j++, fwdt++) {
7713 vfree(fwdt->template);
7714 fwdt->template = NULL;
7717 dcode = (void *)req->ring;
7718 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7719 risc_size = be32_to_cpu(dcode[2]);
7720 ql_dbg(ql_dbg_init, vha, 0x0161,
7721 "-> fwdt%u template array at %#x (%#x dwords)\n",
7722 j, faddr, risc_size);
7723 if (!risc_size || !~risc_size) {
7724 ql_dbg(ql_dbg_init, vha, 0x0162,
7725 "-> fwdt%u failed to read array\n", j);
7729 /* skip header and ignore checksum */
7733 ql_dbg(ql_dbg_init, vha, 0x0163,
7734 "-> fwdt%u template allocate template %#x words...\n",
7736 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7737 if (!fwdt->template) {
7738 ql_log(ql_log_warn, vha, 0x0164,
7739 "-> fwdt%u failed allocate template.\n", j);
7743 dcode = fwdt->template;
7744 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7746 if (!qla27xx_fwdt_template_valid(dcode)) {
7747 ql_log(ql_log_warn, vha, 0x0165,
7748 "-> fwdt%u failed template validate\n", j);
7752 dlen = qla27xx_fwdt_template_size(dcode);
7753 ql_dbg(ql_dbg_init, vha, 0x0166,
7754 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7755 j, dlen, dlen / sizeof(*dcode));
7756 if (dlen > risc_size * sizeof(*dcode)) {
7757 ql_log(ql_log_warn, vha, 0x0167,
7758 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7759 j, dlen - risc_size * sizeof(*dcode));
7763 fwdt->length = dlen;
7764 ql_dbg(ql_dbg_init, vha, 0x0168,
7765 "-> fwdt%u loaded template ok\n", j);
7767 faddr += risc_size + 1;
7774 vfree(fwdt->template);
7775 fwdt->template = NULL;
7781 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7784 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7788 uint16_t *wcode, *fwcode;
7789 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7790 struct fw_blob *blob;
7791 struct qla_hw_data *ha = vha->hw;
7792 struct req_que *req = ha->req_q_map[0];
7794 /* Load firmware blob. */
7795 blob = qla2x00_request_firmware(vha);
7797 ql_log(ql_log_info, vha, 0x0083,
7798 "Firmware image unavailable.\n");
7799 ql_log(ql_log_info, vha, 0x0084,
7800 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7801 return QLA_FUNCTION_FAILED;
7806 wcode = (uint16_t *)req->ring;
7808 fwcode = (uint16_t *)blob->fw->data;
7811 /* Validate firmware image by checking version. */
7812 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7813 ql_log(ql_log_fatal, vha, 0x0085,
7814 "Unable to verify integrity of firmware image (%zd).\n",
7816 goto fail_fw_integrity;
7818 for (i = 0; i < 4; i++)
7819 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7820 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7821 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7822 wcode[2] == 0 && wcode[3] == 0)) {
7823 ql_log(ql_log_fatal, vha, 0x0086,
7824 "Unable to verify integrity of firmware image.\n");
7825 ql_log(ql_log_fatal, vha, 0x0087,
7826 "Firmware data: %04x %04x %04x %04x.\n",
7827 wcode[0], wcode[1], wcode[2], wcode[3]);
7828 goto fail_fw_integrity;
7832 while (*seg && rval == QLA_SUCCESS) {
7834 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7835 risc_size = be16_to_cpu(fwcode[3]);
7837 /* Validate firmware image size. */
7838 fwclen += risc_size * sizeof(uint16_t);
7839 if (blob->fw->size < fwclen) {
7840 ql_log(ql_log_fatal, vha, 0x0088,
7841 "Unable to verify integrity of firmware image "
7842 "(%zd).\n", blob->fw->size);
7843 goto fail_fw_integrity;
7847 while (risc_size > 0 && rval == QLA_SUCCESS) {
7848 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7849 if (wlen > risc_size)
7851 ql_dbg(ql_dbg_init, vha, 0x0089,
7852 "Loading risc segment@ risc addr %x number of "
7853 "words 0x%x.\n", risc_addr, wlen);
7855 for (i = 0; i < wlen; i++)
7856 wcode[i] = swab16(fwcode[i]);
7858 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7861 ql_log(ql_log_fatal, vha, 0x008a,
7862 "Failed to load segment %d of firmware.\n",
7879 return QLA_FUNCTION_FAILED;
7883 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7886 uint templates, segments, fragment;
7889 uint32_t risc_addr, risc_size, risc_attr = 0;
7892 struct fw_blob *blob;
7894 struct qla_hw_data *ha = vha->hw;
7895 struct req_que *req = ha->req_q_map[0];
7896 struct fwdt *fwdt = ha->fwdt;
7898 ql_dbg(ql_dbg_init, vha, 0x0090,
7899 "-> FW: Loading via request-firmware.\n");
7901 blob = qla2x00_request_firmware(vha);
7903 ql_log(ql_log_warn, vha, 0x0092,
7904 "-> Firmware file not found.\n");
7906 return QLA_FUNCTION_FAILED;
7909 fwcode = (void *)blob->fw->data;
7911 if (qla24xx_risc_firmware_invalid(dcode)) {
7912 ql_log(ql_log_fatal, vha, 0x0093,
7913 "Unable to verify integrity of firmware image (%zd).\n",
7915 ql_log(ql_log_fatal, vha, 0x0095,
7916 "Firmware data: %08x %08x %08x %08x.\n",
7917 dcode[0], dcode[1], dcode[2], dcode[3]);
7918 return QLA_FUNCTION_FAILED;
7921 dcode = (void *)req->ring;
7923 segments = FA_RISC_CODE_SEGMENTS;
7924 for (j = 0; j < segments; j++) {
7925 ql_dbg(ql_dbg_init, vha, 0x0096,
7926 "-> Loading segment %u...\n", j);
7927 risc_addr = be32_to_cpu(fwcode[2]);
7928 risc_size = be32_to_cpu(fwcode[3]);
7931 *srisc_addr = risc_addr;
7932 risc_attr = be32_to_cpu(fwcode[9]);
7935 dlen = ha->fw_transfer_size >> 2;
7936 for (fragment = 0; risc_size; fragment++) {
7937 if (dlen > risc_size)
7940 ql_dbg(ql_dbg_init, vha, 0x0097,
7941 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7942 fragment, risc_addr,
7943 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7946 for (i = 0; i < dlen; i++)
7947 dcode[i] = swab32(fwcode[i]);
7949 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7951 ql_log(ql_log_fatal, vha, 0x0098,
7952 "-> Failed load firmware fragment %u.\n",
7954 return QLA_FUNCTION_FAILED;
7963 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7966 templates = (risc_attr & BIT_9) ? 2 : 1;
7967 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
7968 for (j = 0; j < templates; j++, fwdt++) {
7970 vfree(fwdt->template);
7971 fwdt->template = NULL;
7974 risc_size = be32_to_cpu(fwcode[2]);
7975 ql_dbg(ql_dbg_init, vha, 0x0171,
7976 "-> fwdt%u template array at %#x (%#x dwords)\n",
7977 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
7979 if (!risc_size || !~risc_size) {
7980 ql_dbg(ql_dbg_init, vha, 0x0172,
7981 "-> fwdt%u failed to read array\n", j);
7985 /* skip header and ignore checksum */
7989 ql_dbg(ql_dbg_init, vha, 0x0173,
7990 "-> fwdt%u template allocate template %#x words...\n",
7992 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7993 if (!fwdt->template) {
7994 ql_log(ql_log_warn, vha, 0x0174,
7995 "-> fwdt%u failed allocate template.\n", j);
7999 dcode = fwdt->template;
8000 for (i = 0; i < risc_size; i++)
8001 dcode[i] = fwcode[i];
8003 if (!qla27xx_fwdt_template_valid(dcode)) {
8004 ql_log(ql_log_warn, vha, 0x0175,
8005 "-> fwdt%u failed template validate\n", j);
8009 dlen = qla27xx_fwdt_template_size(dcode);
8010 ql_dbg(ql_dbg_init, vha, 0x0176,
8011 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8012 j, dlen, dlen / sizeof(*dcode));
8013 if (dlen > risc_size * sizeof(*dcode)) {
8014 ql_log(ql_log_warn, vha, 0x0177,
8015 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8016 j, dlen - risc_size * sizeof(*dcode));
8020 fwdt->length = dlen;
8021 ql_dbg(ql_dbg_init, vha, 0x0178,
8022 "-> fwdt%u loaded template ok\n", j);
8024 fwcode += risc_size + 1;
8031 vfree(fwdt->template);
8032 fwdt->template = NULL;
8039 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8043 if (ql2xfwloadbin == 1)
8044 return qla81xx_load_risc(vha, srisc_addr);
8048 * 1) Firmware via request-firmware interface (.bin file).
8049 * 2) Firmware residing in flash.
8051 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8052 if (rval == QLA_SUCCESS)
8055 return qla24xx_load_risc_flash(vha, srisc_addr,
8056 vha->hw->flt_region_fw);
8060 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8063 struct qla_hw_data *ha = vha->hw;
8064 struct active_regions active_regions = { };
8066 if (ql2xfwloadbin == 2)
8069 /* FW Load priority:
8070 * 1) Firmware residing in flash.
8071 * 2) Firmware via request-firmware interface (.bin file).
8072 * 3) Golden-Firmware residing in flash -- (limited operation).
8075 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8076 goto try_primary_fw;
8078 qla27xx_get_active_image(vha, &active_regions);
8080 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8081 goto try_primary_fw;
8083 ql_dbg(ql_dbg_init, vha, 0x008b,
8084 "Loading secondary firmware image.\n");
8085 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8090 ql_dbg(ql_dbg_init, vha, 0x008b,
8091 "Loading primary firmware image.\n");
8092 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8097 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8098 if (!rval || !ha->flt_region_gold_fw)
8101 ql_log(ql_log_info, vha, 0x0099,
8102 "Attempting to fallback to golden firmware.\n");
8103 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8107 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8108 ha->flags.running_gold_fw = 1;
8113 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8116 struct qla_hw_data *ha = vha->hw;
8118 if (ha->flags.pci_channel_io_perm_failure)
8120 if (!IS_FWI2_CAPABLE(ha))
8122 if (!ha->fw_major_version)
8124 if (!ha->flags.fw_started)
8127 ret = qla2x00_stop_firmware(vha);
8128 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8129 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8130 ha->isp_ops->reset_chip(vha);
8131 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8133 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8135 ql_log(ql_log_info, vha, 0x8015,
8136 "Attempting retry of stop-firmware command.\n");
8137 ret = qla2x00_stop_firmware(vha);
8141 ha->flags.fw_init_done = 0;
8145 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8147 int rval = QLA_SUCCESS;
8149 uint16_t mb[MAILBOX_REGISTER_COUNT];
8150 struct qla_hw_data *ha = vha->hw;
8151 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8156 rval = qla2x00_fw_ready(base_vha);
8158 if (rval == QLA_SUCCESS) {
8159 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8160 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8163 vha->flags.management_server_logged_in = 0;
8165 /* Login to SNS first */
8166 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8168 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8169 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8170 ql_dbg(ql_dbg_init, vha, 0x0120,
8171 "Failed SNS login: loop_id=%x, rval2=%d\n",
8174 ql_dbg(ql_dbg_init, vha, 0x0103,
8175 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8176 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8177 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8178 return (QLA_FUNCTION_FAILED);
8181 atomic_set(&vha->loop_down_timer, 0);
8182 atomic_set(&vha->loop_state, LOOP_UP);
8183 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8184 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8185 rval = qla2x00_loop_resync(base_vha);
8190 /* 84XX Support **************************************************************/
8192 static LIST_HEAD(qla_cs84xx_list);
8193 static DEFINE_MUTEX(qla_cs84xx_mutex);
8195 static struct qla_chip_state_84xx *
8196 qla84xx_get_chip(struct scsi_qla_host *vha)
8198 struct qla_chip_state_84xx *cs84xx;
8199 struct qla_hw_data *ha = vha->hw;
8201 mutex_lock(&qla_cs84xx_mutex);
8203 /* Find any shared 84xx chip. */
8204 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8205 if (cs84xx->bus == ha->pdev->bus) {
8206 kref_get(&cs84xx->kref);
8211 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8215 kref_init(&cs84xx->kref);
8216 spin_lock_init(&cs84xx->access_lock);
8217 mutex_init(&cs84xx->fw_update_mutex);
8218 cs84xx->bus = ha->pdev->bus;
8220 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8222 mutex_unlock(&qla_cs84xx_mutex);
8227 __qla84xx_chip_release(struct kref *kref)
8229 struct qla_chip_state_84xx *cs84xx =
8230 container_of(kref, struct qla_chip_state_84xx, kref);
8232 mutex_lock(&qla_cs84xx_mutex);
8233 list_del(&cs84xx->list);
8234 mutex_unlock(&qla_cs84xx_mutex);
8239 qla84xx_put_chip(struct scsi_qla_host *vha)
8241 struct qla_hw_data *ha = vha->hw;
8244 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8248 qla84xx_init_chip(scsi_qla_host_t *vha)
8252 struct qla_hw_data *ha = vha->hw;
8254 mutex_lock(&ha->cs84xx->fw_update_mutex);
8256 rval = qla84xx_verify_chip(vha, status);
8258 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8260 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8264 /* 81XX Support **************************************************************/
8267 qla81xx_nvram_config(scsi_qla_host_t *vha)
8270 struct init_cb_81xx *icb;
8271 struct nvram_81xx *nv;
8273 uint8_t *dptr1, *dptr2;
8276 struct qla_hw_data *ha = vha->hw;
8278 struct active_regions active_regions = { };
8281 icb = (struct init_cb_81xx *)ha->init_cb;
8284 /* Determine NVRAM starting address. */
8285 ha->nvram_size = sizeof(*nv);
8286 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8287 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8288 ha->vpd_size = FA_VPD_SIZE_82XX;
8290 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8291 qla28xx_get_aux_images(vha, &active_regions);
8293 /* Get VPD data into cache */
8294 ha->vpd = ha->nvram + VPD_OFFSET;
8296 faddr = ha->flt_region_vpd;
8297 if (IS_QLA28XX(ha)) {
8298 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8299 faddr = ha->flt_region_vpd_sec;
8300 ql_dbg(ql_dbg_init, vha, 0x0110,
8301 "Loading %s nvram image.\n",
8302 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8303 "primary" : "secondary");
8305 qla24xx_read_flash_data(vha, ha->vpd, faddr, ha->vpd_size >> 2);
8307 /* Get NVRAM data into cache and calculate checksum. */
8308 faddr = ha->flt_region_nvram;
8309 if (IS_QLA28XX(ha)) {
8310 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8311 faddr = ha->flt_region_nvram_sec;
8313 ql_dbg(ql_dbg_init, vha, 0x0110,
8314 "Loading %s nvram image.\n",
8315 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8316 "primary" : "secondary");
8317 qla24xx_read_flash_data(vha, ha->nvram, faddr, ha->nvram_size >> 2);
8319 dptr = (uint32_t *)nv;
8320 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8321 chksum += le32_to_cpu(*dptr);
8323 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8324 "Contents of NVRAM:\n");
8325 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8326 nv, ha->nvram_size);
8328 /* Bad NVRAM data, set defaults parameters. */
8329 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8330 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8331 /* Reset NVRAM data. */
8332 ql_log(ql_log_info, vha, 0x0073,
8333 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8334 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8335 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8336 ql_log(ql_log_info, vha, 0x0074,
8337 "Falling back to functioning (yet invalid -- WWPN) "
8341 * Set default initialization control block.
8343 memset(nv, 0, ha->nvram_size);
8344 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8345 nv->version = cpu_to_le16(ICB_VERSION);
8346 nv->frame_payload_size = 2048;
8347 nv->execution_throttle = cpu_to_le16(0xFFFF);
8348 nv->exchange_count = cpu_to_le16(0);
8349 nv->port_name[0] = 0x21;
8350 nv->port_name[1] = 0x00 + ha->port_no + 1;
8351 nv->port_name[2] = 0x00;
8352 nv->port_name[3] = 0xe0;
8353 nv->port_name[4] = 0x8b;
8354 nv->port_name[5] = 0x1c;
8355 nv->port_name[6] = 0x55;
8356 nv->port_name[7] = 0x86;
8357 nv->node_name[0] = 0x20;
8358 nv->node_name[1] = 0x00;
8359 nv->node_name[2] = 0x00;
8360 nv->node_name[3] = 0xe0;
8361 nv->node_name[4] = 0x8b;
8362 nv->node_name[5] = 0x1c;
8363 nv->node_name[6] = 0x55;
8364 nv->node_name[7] = 0x86;
8365 nv->login_retry_count = cpu_to_le16(8);
8366 nv->interrupt_delay_timer = cpu_to_le16(0);
8367 nv->login_timeout = cpu_to_le16(0);
8368 nv->firmware_options_1 =
8369 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8370 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8371 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8372 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8373 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8374 nv->efi_parameters = cpu_to_le32(0);
8375 nv->reset_delay = 5;
8376 nv->max_luns_per_target = cpu_to_le16(128);
8377 nv->port_down_retry_count = cpu_to_le16(30);
8378 nv->link_down_timeout = cpu_to_le16(180);
8379 nv->enode_mac[0] = 0x00;
8380 nv->enode_mac[1] = 0xC0;
8381 nv->enode_mac[2] = 0xDD;
8382 nv->enode_mac[3] = 0x04;
8383 nv->enode_mac[4] = 0x05;
8384 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8389 if (IS_T10_PI_CAPABLE(ha))
8390 nv->frame_payload_size &= ~7;
8392 qlt_81xx_config_nvram_stage1(vha, nv);
8394 /* Reset Initialization control block */
8395 memset(icb, 0, ha->init_cb_size);
8397 /* Copy 1st segment. */
8398 dptr1 = (uint8_t *)icb;
8399 dptr2 = (uint8_t *)&nv->version;
8400 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8402 *dptr1++ = *dptr2++;
8404 icb->login_retry_count = nv->login_retry_count;
8406 /* Copy 2nd segment. */
8407 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8408 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8409 cnt = (uint8_t *)&icb->reserved_5 -
8410 (uint8_t *)&icb->interrupt_delay_timer;
8412 *dptr1++ = *dptr2++;
8414 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8415 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8416 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8417 icb->enode_mac[0] = 0x00;
8418 icb->enode_mac[1] = 0xC0;
8419 icb->enode_mac[2] = 0xDD;
8420 icb->enode_mac[3] = 0x04;
8421 icb->enode_mac[4] = 0x05;
8422 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8425 /* Use extended-initialization control block. */
8426 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8427 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8429 * Setup driver NVRAM options.
8431 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8434 qlt_81xx_config_nvram_stage2(vha, icb);
8436 /* Use alternate WWN? */
8437 if (nv->host_p & cpu_to_le32(BIT_15)) {
8438 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8439 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8442 /* Prepare nodename */
8443 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8445 * Firmware will apply the following mask if the nodename was
8448 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8449 icb->node_name[0] &= 0xF0;
8452 /* Set host adapter parameters. */
8453 ha->flags.disable_risc_code_load = 0;
8454 ha->flags.enable_lip_reset = 0;
8455 ha->flags.enable_lip_full_login =
8456 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8457 ha->flags.enable_target_reset =
8458 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8459 ha->flags.enable_led_scheme = 0;
8460 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8462 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8463 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8465 /* save HBA serial number */
8466 ha->serial0 = icb->port_name[5];
8467 ha->serial1 = icb->port_name[6];
8468 ha->serial2 = icb->port_name[7];
8469 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8470 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8472 icb->execution_throttle = cpu_to_le16(0xFFFF);
8474 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8476 /* Set minimum login_timeout to 4 seconds. */
8477 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8478 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8479 if (le16_to_cpu(nv->login_timeout) < 4)
8480 nv->login_timeout = cpu_to_le16(4);
8481 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8483 /* Set minimum RATOV to 100 tenths of a second. */
8486 ha->loop_reset_delay = nv->reset_delay;
8488 /* Link Down Timeout = 0:
8490 * When Port Down timer expires we will start returning
8491 * I/O's to OS with "DID_NO_CONNECT".
8493 * Link Down Timeout != 0:
8495 * The driver waits for the link to come up after link down
8496 * before returning I/Os to OS with "DID_NO_CONNECT".
8498 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8499 ha->loop_down_abort_time =
8500 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8502 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8503 ha->loop_down_abort_time =
8504 (LOOP_DOWN_TIME - ha->link_down_timeout);
8507 /* Need enough time to try and get the port back. */
8508 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8509 if (qlport_down_retry)
8510 ha->port_down_retry_count = qlport_down_retry;
8512 /* Set login_retry_count */
8513 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8514 if (ha->port_down_retry_count ==
8515 le16_to_cpu(nv->port_down_retry_count) &&
8516 ha->port_down_retry_count > 3)
8517 ha->login_retry_count = ha->port_down_retry_count;
8518 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8519 ha->login_retry_count = ha->port_down_retry_count;
8520 if (ql2xloginretrycount)
8521 ha->login_retry_count = ql2xloginretrycount;
8523 /* if not running MSI-X we need handshaking on interrupts */
8524 if (!vha->hw->flags.msix_enabled &&
8525 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8526 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8529 if (!vha->flags.init_done) {
8530 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8531 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8532 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8533 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8535 icb->firmware_options_2 &= cpu_to_le32(
8536 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8537 vha->flags.process_response_queue = 0;
8538 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8539 ha->zio_mode = QLA_ZIO_MODE_6;
8541 ql_log(ql_log_info, vha, 0x0075,
8542 "ZIO mode %d enabled; timer delay (%d us).\n",
8544 ha->zio_timer * 100);
8546 icb->firmware_options_2 |= cpu_to_le32(
8547 (uint32_t)ha->zio_mode);
8548 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8549 vha->flags.process_response_queue = 1;
8552 /* enable RIDA Format2 */
8553 icb->firmware_options_3 |= BIT_0;
8555 /* N2N: driver will initiate Login instead of FW */
8556 icb->firmware_options_3 |= BIT_8;
8559 ql_log(ql_log_warn, vha, 0x0076,
8560 "NVRAM configuration failed.\n");
8566 qla82xx_restart_isp(scsi_qla_host_t *vha)
8569 struct qla_hw_data *ha = vha->hw;
8570 struct scsi_qla_host *vp;
8571 unsigned long flags;
8573 status = qla2x00_init_rings(vha);
8575 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8576 ha->flags.chip_reset_done = 1;
8578 status = qla2x00_fw_ready(vha);
8580 /* Issue a marker after FW becomes ready. */
8581 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8582 vha->flags.online = 1;
8583 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8586 /* if no cable then assume it's good */
8587 if ((vha->device_flags & DFLG_NO_CABLE))
8592 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8594 if (!atomic_read(&vha->loop_down_timer)) {
8596 * Issue marker command only when we are going
8597 * to start the I/O .
8599 vha->marker_needed = 1;
8602 ha->isp_ops->enable_intrs(ha);
8604 ha->isp_abort_cnt = 0;
8605 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8607 /* Update the firmware version */
8608 status = qla82xx_check_md_needed(vha);
8611 ha->flags.fce_enabled = 1;
8613 fce_calc_size(ha->fce_bufs));
8614 rval = qla2x00_enable_fce_trace(vha,
8615 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8618 ql_log(ql_log_warn, vha, 0x8001,
8619 "Unable to reinitialize FCE (%d).\n",
8621 ha->flags.fce_enabled = 0;
8626 memset(ha->eft, 0, EFT_SIZE);
8627 rval = qla2x00_enable_eft_trace(vha,
8628 ha->eft_dma, EFT_NUM_BUFFERS);
8630 ql_log(ql_log_warn, vha, 0x8010,
8631 "Unable to reinitialize EFT (%d).\n",
8638 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8639 "qla82xx_restart_isp succeeded.\n");
8641 spin_lock_irqsave(&ha->vport_slock, flags);
8642 list_for_each_entry(vp, &ha->vp_list, list) {
8644 atomic_inc(&vp->vref_count);
8645 spin_unlock_irqrestore(&ha->vport_slock, flags);
8647 qla2x00_vp_abort_isp(vp);
8649 spin_lock_irqsave(&ha->vport_slock, flags);
8650 atomic_dec(&vp->vref_count);
8653 spin_unlock_irqrestore(&ha->vport_slock, flags);
8656 ql_log(ql_log_warn, vha, 0x8016,
8657 "qla82xx_restart_isp **** FAILED ****.\n");
8664 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8666 struct qla_hw_data *ha = vha->hw;
8668 /* Hold status IOCBs until ABTS response received. */
8670 ha->fw_options[3] |= BIT_12;
8672 /* Set Retry FLOGI in case of P2P connection */
8673 if (ha->operating_mode == P2P) {
8674 ha->fw_options[2] |= BIT_3;
8675 ql_dbg(ql_dbg_disc, vha, 0x2103,
8676 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8677 __func__, ha->fw_options[2]);
8680 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8681 if (ql2xmvasynctoatio) {
8682 if (qla_tgt_mode_enabled(vha) ||
8683 qla_dual_mode_enabled(vha))
8684 ha->fw_options[2] |= BIT_11;
8686 ha->fw_options[2] &= ~BIT_11;
8689 if (qla_tgt_mode_enabled(vha) ||
8690 qla_dual_mode_enabled(vha)) {
8691 /* FW auto send SCSI status during */
8692 ha->fw_options[1] |= BIT_8;
8693 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8695 /* FW perform Exchange validation */
8696 ha->fw_options[2] |= BIT_4;
8698 ha->fw_options[1] &= ~BIT_8;
8699 ha->fw_options[10] &= 0x00ff;
8701 ha->fw_options[2] &= ~BIT_4;
8704 if (ql2xetsenable) {
8705 /* Enable ETS Burst. */
8706 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8707 ha->fw_options[2] |= BIT_9;
8710 ql_dbg(ql_dbg_init, vha, 0x00e9,
8711 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8712 __func__, ha->fw_options[1], ha->fw_options[2],
8713 ha->fw_options[3], vha->host->active_mode);
8715 qla2x00_set_fw_options(vha, ha->fw_options);
8719 * qla24xx_get_fcp_prio
8720 * Gets the fcp cmd priority value for the logged in port.
8721 * Looks for a match of the port descriptors within
8722 * each of the fcp prio config entries. If a match is found,
8723 * the tag (priority) value is returned.
8726 * vha = scsi host structure pointer.
8727 * fcport = port structure pointer.
8730 * non-zero (if found)
8737 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8740 uint8_t pid_match, wwn_match;
8742 uint32_t pid1, pid2;
8743 uint64_t wwn1, wwn2;
8744 struct qla_fcp_prio_entry *pri_entry;
8745 struct qla_hw_data *ha = vha->hw;
8747 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8751 entries = ha->fcp_prio_cfg->num_entries;
8752 pri_entry = &ha->fcp_prio_cfg->entry[0];
8754 for (i = 0; i < entries; i++) {
8755 pid_match = wwn_match = 0;
8757 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8762 /* check source pid for a match */
8763 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8764 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8765 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8766 if (pid1 == INVALID_PORT_ID)
8768 else if (pid1 == pid2)
8772 /* check destination pid for a match */
8773 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8774 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8775 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8776 if (pid1 == INVALID_PORT_ID)
8778 else if (pid1 == pid2)
8782 /* check source WWN for a match */
8783 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8784 wwn1 = wwn_to_u64(vha->port_name);
8785 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8786 if (wwn2 == (uint64_t)-1)
8788 else if (wwn1 == wwn2)
8792 /* check destination WWN for a match */
8793 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8794 wwn1 = wwn_to_u64(fcport->port_name);
8795 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8796 if (wwn2 == (uint64_t)-1)
8798 else if (wwn1 == wwn2)
8802 if (pid_match == 2 || wwn_match == 2) {
8803 /* Found a matching entry */
8804 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8805 priority = pri_entry->tag;
8816 * qla24xx_update_fcport_fcp_prio
8817 * Activates fcp priority for the logged in fc port
8820 * vha = scsi host structure pointer.
8821 * fcp = port structure pointer.
8824 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8830 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8836 if (fcport->port_type != FCT_TARGET ||
8837 fcport->loop_id == FC_NO_LOOP_ID)
8838 return QLA_FUNCTION_FAILED;
8840 priority = qla24xx_get_fcp_prio(vha, fcport);
8842 return QLA_FUNCTION_FAILED;
8844 if (IS_P3P_TYPE(vha->hw)) {
8845 fcport->fcp_prio = priority & 0xf;
8849 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8850 if (ret == QLA_SUCCESS) {
8851 if (fcport->fcp_prio != priority)
8852 ql_dbg(ql_dbg_user, vha, 0x709e,
8853 "Updated FCP_CMND priority - value=%d loop_id=%d "
8854 "port_id=%02x%02x%02x.\n", priority,
8855 fcport->loop_id, fcport->d_id.b.domain,
8856 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8857 fcport->fcp_prio = priority & 0xf;
8859 ql_dbg(ql_dbg_user, vha, 0x704f,
8860 "Unable to update FCP_CMND priority - ret=0x%x for "
8861 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8862 fcport->d_id.b.domain, fcport->d_id.b.area,
8863 fcport->d_id.b.al_pa);
8868 * qla24xx_update_all_fcp_prio
8869 * Activates fcp priority for all the logged in ports
8872 * ha = adapter block pointer.
8875 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8881 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8886 ret = QLA_FUNCTION_FAILED;
8887 /* We need to set priority for all logged in ports */
8888 list_for_each_entry(fcport, &vha->vp_fcports, list)
8889 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8894 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8895 int vp_idx, bool startqp)
8900 struct qla_hw_data *ha = vha->hw;
8901 uint16_t qpair_id = 0;
8902 struct qla_qpair *qpair = NULL;
8903 struct qla_msix_entry *msix;
8905 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8906 ql_log(ql_log_warn, vha, 0x00181,
8907 "FW/Driver is not multi-queue capable.\n");
8911 if (ql2xmqsupport || ql2xnvmeenable) {
8912 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8913 if (qpair == NULL) {
8914 ql_log(ql_log_warn, vha, 0x0182,
8915 "Failed to allocate memory for queue pair.\n");
8919 qpair->hw = vha->hw;
8921 qpair->qp_lock_ptr = &qpair->qp_lock;
8922 spin_lock_init(&qpair->qp_lock);
8923 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8925 /* Assign available que pair id */
8926 mutex_lock(&ha->mq_lock);
8927 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8928 if (ha->num_qpairs >= ha->max_qpairs) {
8929 mutex_unlock(&ha->mq_lock);
8930 ql_log(ql_log_warn, vha, 0x0183,
8931 "No resources to create additional q pair.\n");
8935 set_bit(qpair_id, ha->qpair_qid_map);
8936 ha->queue_pair_map[qpair_id] = qpair;
8937 qpair->id = qpair_id;
8938 qpair->vp_idx = vp_idx;
8939 qpair->fw_started = ha->flags.fw_started;
8940 INIT_LIST_HEAD(&qpair->hints_list);
8941 qpair->chip_reset = ha->base_qpair->chip_reset;
8942 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8943 qpair->enable_explicit_conf =
8944 ha->base_qpair->enable_explicit_conf;
8946 for (i = 0; i < ha->msix_count; i++) {
8947 msix = &ha->msix_entries[i];
8951 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8952 "Vector %x selected for qpair\n", msix->vector);
8956 ql_log(ql_log_warn, vha, 0x0184,
8957 "Out of MSI-X vectors!.\n");
8961 qpair->msix->in_use = 1;
8962 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8963 qpair->pdev = ha->pdev;
8964 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
8965 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8967 mutex_unlock(&ha->mq_lock);
8969 /* Create response queue first */
8970 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8972 ql_log(ql_log_warn, vha, 0x0185,
8973 "Failed to create response queue.\n");
8977 qpair->rsp = ha->rsp_q_map[rsp_id];
8979 /* Create request queue */
8980 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8983 ql_log(ql_log_warn, vha, 0x0186,
8984 "Failed to create request queue.\n");
8988 qpair->req = ha->req_q_map[req_id];
8989 qpair->rsp->req = qpair->req;
8990 qpair->rsp->qpair = qpair;
8991 /* init qpair to this cpu. Will adjust at run time. */
8992 qla_cpu_update(qpair, smp_processor_id());
8994 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8995 if (ha->fw_attributes & BIT_4)
8996 qpair->difdix_supported = 1;
8999 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9000 if (!qpair->srb_mempool) {
9001 ql_log(ql_log_warn, vha, 0xd036,
9002 "Failed to create srb mempool for qpair %d\n",
9007 /* Mark as online */
9010 if (!vha->flags.qpairs_available)
9011 vha->flags.qpairs_available = 1;
9013 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9014 "Request/Response queue pair created, id %d\n",
9016 ql_dbg(ql_dbg_init, vha, 0x0187,
9017 "Request/Response queue pair created, id %d\n",
9024 qla25xx_delete_rsp_que(vha, qpair->rsp);
9026 mutex_lock(&ha->mq_lock);
9027 qpair->msix->in_use = 0;
9028 list_del(&qpair->qp_list_elem);
9029 if (list_empty(&vha->qp_list))
9030 vha->flags.qpairs_available = 0;
9032 ha->queue_pair_map[qpair_id] = NULL;
9033 clear_bit(qpair_id, ha->qpair_qid_map);
9035 mutex_unlock(&ha->mq_lock);
9041 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9043 int ret = QLA_FUNCTION_FAILED;
9044 struct qla_hw_data *ha = qpair->hw;
9046 qpair->delete_in_progress = 1;
9047 while (atomic_read(&qpair->ref_count))
9050 ret = qla25xx_delete_req_que(vha, qpair->req);
9051 if (ret != QLA_SUCCESS)
9054 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9055 if (ret != QLA_SUCCESS)
9058 mutex_lock(&ha->mq_lock);
9059 ha->queue_pair_map[qpair->id] = NULL;
9060 clear_bit(qpair->id, ha->qpair_qid_map);
9062 list_del(&qpair->qp_list_elem);
9063 if (list_empty(&vha->qp_list)) {
9064 vha->flags.qpairs_available = 0;
9065 vha->flags.qpairs_req_created = 0;
9066 vha->flags.qpairs_rsp_created = 0;
9068 mempool_destroy(qpair->srb_mempool);
9070 mutex_unlock(&ha->mq_lock);