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 del_timer(&sp->u.iocb_cmd.timer);
126 if (sp->flags & SRB_WAKEUP_ON_COMP)
127 complete(&abt->u.abt.comp);
132 static int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
134 scsi_qla_host_t *vha = cmd_sp->vha;
135 struct srb_iocb *abt_iocb;
137 int rval = QLA_FUNCTION_FAILED;
139 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
144 abt_iocb = &sp->u.iocb_cmd;
145 sp->type = SRB_ABT_CMD;
147 sp->qpair = cmd_sp->qpair;
149 sp->flags = SRB_WAKEUP_ON_COMP;
151 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
152 init_completion(&abt_iocb->u.abt.comp);
153 /* FW can send 2 x ABTS's timeout/20s */
154 qla2x00_init_timer(sp, 42);
156 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
157 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
159 sp->done = qla24xx_abort_sp_done;
161 ql_dbg(ql_dbg_async, vha, 0x507c,
162 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
165 rval = qla2x00_start_sp(sp);
166 if (rval != QLA_SUCCESS)
170 wait_for_completion(&abt_iocb->u.abt.comp);
171 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
172 QLA_SUCCESS : QLA_FUNCTION_FAILED;
184 qla2x00_async_iocb_timeout(void *data)
187 fc_port_t *fcport = sp->fcport;
188 struct srb_iocb *lio = &sp->u.iocb_cmd;
193 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
194 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
195 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
197 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
199 pr_info("Async-%s timeout - hdl=%x.\n",
200 sp->name, sp->handle);
205 rc = qla24xx_async_abort_cmd(sp, false);
207 /* Retry as needed. */
208 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
209 lio->u.logio.data[1] =
210 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
211 QLA_LOGIO_LOGIN_RETRIED : 0;
212 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
213 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
215 if (sp->qpair->req->outstanding_cmds[h] ==
217 sp->qpair->req->outstanding_cmds[h] =
222 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
223 sp->done(sp, QLA_FUNCTION_TIMEOUT);
227 case SRB_CT_PTHRU_CMD:
233 rc = qla24xx_async_abort_cmd(sp, false);
235 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
236 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
238 if (sp->qpair->req->outstanding_cmds[h] ==
240 sp->qpair->req->outstanding_cmds[h] =
245 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
246 sp->done(sp, QLA_FUNCTION_TIMEOUT);
253 qla2x00_async_login_sp_done(void *ptr, int res)
256 struct scsi_qla_host *vha = sp->vha;
257 struct srb_iocb *lio = &sp->u.iocb_cmd;
260 ql_dbg(ql_dbg_disc, vha, 0x20dd,
261 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
263 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
265 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
266 memset(&ea, 0, sizeof(ea));
267 ea.event = FCME_PLOGI_DONE;
268 ea.fcport = sp->fcport;
269 ea.data[0] = lio->u.logio.data[0];
270 ea.data[1] = lio->u.logio.data[1];
271 ea.iop[0] = lio->u.logio.iop[0];
272 ea.iop[1] = lio->u.logio.iop[1];
274 qla2x00_fcport_event_handler(vha, &ea);
281 fcport_is_smaller(fc_port_t *fcport)
283 if (wwn_to_u64(fcport->port_name) <
284 wwn_to_u64(fcport->vha->port_name))
291 fcport_is_bigger(fc_port_t *fcport)
293 return !fcport_is_smaller(fcport);
297 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
301 struct srb_iocb *lio;
302 int rval = QLA_FUNCTION_FAILED;
304 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
305 fcport->loop_id == FC_NO_LOOP_ID) {
306 ql_log(ql_log_warn, vha, 0xffff,
307 "%s: %8phC - not sending command.\n",
308 __func__, fcport->port_name);
312 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
316 fcport->flags |= FCF_ASYNC_SENT;
317 fcport->logout_completed = 0;
319 fcport->disc_state = DSC_LOGIN_PEND;
320 sp->type = SRB_LOGIN_CMD;
322 sp->gen1 = fcport->rscn_gen;
323 sp->gen2 = fcport->login_gen;
325 lio = &sp->u.iocb_cmd;
326 lio->timeout = qla2x00_async_iocb_timeout;
327 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
329 sp->done = qla2x00_async_login_sp_done;
330 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
331 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
333 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
335 if (fcport->fc4f_nvme)
336 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
338 ql_dbg(ql_dbg_disc, vha, 0x2072,
339 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
340 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
341 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
342 fcport->login_retry);
344 rval = qla2x00_start_sp(sp);
345 if (rval != QLA_SUCCESS) {
346 fcport->flags |= FCF_LOGIN_NEEDED;
347 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
355 fcport->flags &= ~FCF_ASYNC_SENT;
357 fcport->flags &= ~FCF_ASYNC_ACTIVE;
362 qla2x00_async_logout_sp_done(void *ptr, int res)
366 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
367 sp->fcport->login_gen++;
368 qlt_logo_completion_handler(sp->fcport, res);
373 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
376 struct srb_iocb *lio;
377 int rval = QLA_FUNCTION_FAILED;
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) ||
1280 fcport->loop_id == FC_NO_LOOP_ID) {
1281 ql_log(ql_log_warn, vha, 0xffff,
1282 "%s: %8phC - not sending command.\n",
1283 __func__, fcport->port_name);
1287 fcport->disc_state = DSC_GPDB;
1289 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1293 fcport->flags |= FCF_ASYNC_SENT;
1294 sp->type = SRB_MB_IOCB;
1296 sp->gen1 = fcport->rscn_gen;
1297 sp->gen2 = fcport->login_gen;
1299 mbx = &sp->u.iocb_cmd;
1300 mbx->timeout = qla2x00_async_iocb_timeout;
1301 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1303 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1305 ql_log(ql_log_warn, vha, 0xd043,
1306 "Failed to allocate port database structure.\n");
1310 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1311 mb[0] = MBC_GET_PORT_DATABASE;
1312 mb[1] = fcport->loop_id;
1313 mb[2] = MSW(pd_dma);
1314 mb[3] = LSW(pd_dma);
1315 mb[6] = MSW(MSD(pd_dma));
1316 mb[7] = LSW(MSD(pd_dma));
1317 mb[9] = vha->vp_idx;
1320 mbx->u.mbx.in = (void *)pd;
1321 mbx->u.mbx.in_dma = pd_dma;
1323 sp->done = qla24xx_async_gpdb_sp_done;
1325 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1326 "Async-%s %8phC hndl %x opt %x\n",
1327 sp->name, fcport->port_name, sp->handle, opt);
1329 rval = qla2x00_start_sp(sp);
1330 if (rval != QLA_SUCCESS)
1336 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1339 fcport->flags &= ~FCF_ASYNC_SENT;
1341 qla24xx_post_gpdb_work(vha, fcport, opt);
1346 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1348 unsigned long flags;
1350 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1351 ea->fcport->login_gen++;
1352 ea->fcport->deleted = 0;
1353 ea->fcport->logout_on_delete = 1;
1355 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1356 vha->fcport_count++;
1357 ea->fcport->login_succ = 1;
1359 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1360 qla24xx_sched_upd_fcport(ea->fcport);
1361 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1362 } else if (ea->fcport->login_succ) {
1364 * We have an existing session. A late RSCN delivery
1365 * must have triggered the session to be re-validate.
1366 * Session is still valid.
1368 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1369 "%s %d %8phC session revalidate success\n",
1370 __func__, __LINE__, ea->fcport->port_name);
1371 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1373 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1377 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1379 fc_port_t *fcport = ea->fcport;
1380 struct port_database_24xx *pd;
1381 struct srb *sp = ea->sp;
1384 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1386 fcport->flags &= ~FCF_ASYNC_SENT;
1388 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1389 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__, fcport->port_name,
1390 fcport->disc_state, pd->current_login_state, fcport->fc4f_nvme,
1393 if (fcport->disc_state == DSC_DELETE_PEND)
1396 if (fcport->fc4f_nvme)
1397 ls = pd->current_login_state >> 4;
1399 ls = pd->current_login_state & 0xf;
1401 if (ea->sp->gen2 != fcport->login_gen) {
1402 /* target side must have changed it. */
1404 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1405 "%s %8phC generation changed\n",
1406 __func__, fcport->port_name);
1408 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1409 qla_rscn_replay(fcport);
1410 qlt_schedule_sess_for_deletion(fcport);
1415 case PDS_PRLI_COMPLETE:
1416 __qla24xx_parse_gpdb(vha, fcport, pd);
1418 case PDS_PLOGI_PENDING:
1419 case PDS_PLOGI_COMPLETE:
1420 case PDS_PRLI_PENDING:
1421 case PDS_PRLI2_PENDING:
1422 /* Set discovery state back to GNL to Relogin attempt */
1423 if (qla_dual_mode_enabled(vha) ||
1424 qla_ini_mode_enabled(vha)) {
1425 fcport->disc_state = DSC_GNL;
1426 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1429 case PDS_LOGO_PENDING:
1430 case PDS_PORT_UNAVAILABLE:
1432 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1433 __func__, __LINE__, fcport->port_name);
1434 qlt_schedule_sess_for_deletion(fcport);
1437 __qla24xx_handle_gpdb_event(vha, ea);
1440 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1445 if (qla_tgt_mode_enabled(vha))
1448 if (qla_dual_mode_enabled(vha)) {
1449 if (N2N_TOPO(vha->hw)) {
1452 mywwn = wwn_to_u64(vha->port_name);
1453 wwn = wwn_to_u64(fcport->port_name);
1456 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1457 && time_after_eq(jiffies,
1458 fcport->plogi_nack_done_deadline))
1464 /* initiator mode */
1468 if (login && fcport->login_retry) {
1469 fcport->login_retry--;
1470 if (fcport->loop_id == FC_NO_LOOP_ID) {
1471 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1472 rc = qla2x00_find_new_loop_id(vha, fcport);
1474 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1475 "%s %d %8phC post del sess - out of loopid\n",
1476 __func__, __LINE__, fcport->port_name);
1477 fcport->scan_state = 0;
1478 qlt_schedule_sess_for_deletion(fcport);
1482 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1483 "%s %d %8phC post login\n",
1484 __func__, __LINE__, fcport->port_name);
1485 qla2x00_post_async_login_work(vha, fcport, NULL);
1489 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1495 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20d8,
1496 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1497 __func__, fcport->port_name, fcport->disc_state,
1498 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1499 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1500 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1502 if (fcport->scan_state != QLA_FCPORT_FOUND)
1505 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1506 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1507 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1510 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1511 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1512 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1517 /* for pure Target Mode. Login will not be initiated */
1518 if (vha->host->active_mode == MODE_TARGET)
1521 if (fcport->flags & FCF_ASYNC_SENT) {
1522 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1526 switch (fcport->disc_state) {
1528 wwn = wwn_to_u64(fcport->node_name);
1529 switch (vha->hw->current_topology) {
1531 if (fcport_is_smaller(fcport)) {
1532 /* this adapter is bigger */
1533 if (fcport->login_retry) {
1534 if (fcport->loop_id == FC_NO_LOOP_ID) {
1535 qla2x00_find_new_loop_id(vha,
1537 fcport->fw_login_state =
1538 DSC_LS_PORT_UNAVAIL;
1540 fcport->login_retry--;
1541 qla_post_els_plogi_work(vha, fcport);
1543 ql_log(ql_log_info, vha, 0x705d,
1544 "Unable to reach remote port %8phC",
1548 qla24xx_post_gnl_work(vha, fcport);
1553 ql_dbg(ql_dbg_disc, vha, 0xffff,
1554 "%s %d %8phC post GNNID\n",
1555 __func__, __LINE__, fcport->port_name);
1556 qla24xx_post_gnnid_work(vha, fcport);
1557 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1558 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1559 "%s %d %8phC post gnl\n",
1560 __func__, __LINE__, fcport->port_name);
1561 qla24xx_post_gnl_work(vha, fcport);
1563 qla_chk_n2n_b4_login(vha, fcport);
1570 switch (vha->hw->current_topology) {
1572 if ((fcport->current_login_state & 0xf) == 0x6) {
1573 ql_dbg(ql_dbg_disc, vha, 0x2118,
1574 "%s %d %8phC post GPDB work\n",
1575 __func__, __LINE__, fcport->port_name);
1576 fcport->chip_reset =
1577 vha->hw->base_qpair->chip_reset;
1578 qla24xx_post_gpdb_work(vha, fcport, 0);
1580 ql_dbg(ql_dbg_disc, vha, 0x2118,
1581 "%s %d %8phC post NVMe PRLI\n",
1582 __func__, __LINE__, fcport->port_name);
1583 qla24xx_post_prli_work(vha, fcport);
1587 if (fcport->login_pause) {
1588 fcport->last_rscn_gen = fcport->rscn_gen;
1589 fcport->last_login_gen = fcport->login_gen;
1590 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1593 qla_chk_n2n_b4_login(vha, fcport);
1598 case DSC_LOGIN_FAILED:
1599 if (N2N_TOPO(vha->hw))
1600 qla_chk_n2n_b4_login(vha, fcport);
1602 qlt_schedule_sess_for_deletion(fcport);
1605 case DSC_LOGIN_COMPLETE:
1606 /* recheck login state */
1607 data[0] = data[1] = 0;
1608 qla2x00_post_async_adisc_work(vha, fcport, data);
1611 case DSC_LOGIN_PEND:
1612 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1613 qla24xx_post_prli_work(vha, fcport);
1616 case DSC_UPD_FCPORT:
1617 sec = jiffies_to_msecs(jiffies -
1618 fcport->jiffies_at_registration)/1000;
1619 if (fcport->sec_since_registration < sec && sec &&
1621 fcport->sec_since_registration = sec;
1622 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1623 "%s %8phC - Slow Rport registration(%d Sec)\n",
1624 __func__, fcport->port_name, sec);
1627 if (fcport->next_disc_state != DSC_DELETE_PEND)
1628 fcport->next_disc_state = DSC_ADISC;
1629 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1639 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1640 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1642 struct qla_work_evt *e;
1644 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1646 return QLA_FUNCTION_FAILED;
1648 e->u.new_sess.id = *id;
1649 e->u.new_sess.pla = pla;
1650 e->u.new_sess.fc4_type = fc4_type;
1651 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1653 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1655 return qla2x00_post_work(vha, e);
1659 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1660 struct event_arg *ea)
1662 fc_port_t *fcport = ea->fcport;
1664 ql_dbg(ql_dbg_disc, vha, 0x2102,
1665 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1666 __func__, fcport->port_name, fcport->disc_state,
1667 fcport->fw_login_state, fcport->login_pause,
1668 fcport->deleted, fcport->conflict,
1669 fcport->last_rscn_gen, fcport->rscn_gen,
1670 fcport->last_login_gen, fcport->login_gen,
1673 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1674 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1677 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1678 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1679 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1684 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1685 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1686 __func__, __LINE__, fcport->port_name);
1687 qla24xx_post_gnl_work(vha, fcport);
1691 qla24xx_fcport_handle_login(vha, fcport);
1695 static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1696 struct event_arg *ea)
1698 ql_dbg(ql_dbg_disc, vha, 0x2118,
1699 "%s %d %8phC post PRLI\n",
1700 __func__, __LINE__, ea->fcport->port_name);
1701 qla24xx_post_prli_work(vha, ea->fcport);
1704 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1708 switch (ea->event) {
1710 if (test_bit(UNLOADING, &vha->dpc_flags))
1713 qla24xx_handle_relogin_event(vha, ea);
1716 if (test_bit(UNLOADING, &vha->dpc_flags))
1719 unsigned long flags;
1721 fcport = qla2x00_find_fcport_by_nportid
1724 fcport->scan_needed = 1;
1728 spin_lock_irqsave(&vha->work_lock, flags);
1729 if (vha->scan.scan_flags == 0) {
1730 ql_dbg(ql_dbg_disc, vha, 0xffff,
1731 "%s: schedule\n", __func__);
1732 vha->scan.scan_flags |= SF_QUEUED;
1733 schedule_delayed_work(&vha->scan.scan_work, 5);
1735 spin_unlock_irqrestore(&vha->work_lock, flags);
1739 qla24xx_handle_gnl_done_event(vha, ea);
1741 case FCME_GPSC_DONE:
1742 qla24xx_handle_gpsc_event(vha, ea);
1744 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1745 qla24xx_handle_plogi_done_event(vha, ea);
1747 case FCME_PRLI_DONE:
1748 qla24xx_handle_prli_done_event(vha, ea);
1750 case FCME_GPDB_DONE:
1751 qla24xx_handle_gpdb_event(vha, ea);
1753 case FCME_GPNID_DONE:
1754 qla24xx_handle_gpnid_event(vha, ea);
1756 case FCME_GFFID_DONE:
1757 qla24xx_handle_gffid_event(vha, ea);
1759 case FCME_ADISC_DONE:
1760 qla24xx_handle_adisc_event(vha, ea);
1762 case FCME_GNNID_DONE:
1763 qla24xx_handle_gnnid_event(vha, ea);
1765 case FCME_GFPNID_DONE:
1766 qla24xx_handle_gfpnid_event(vha, ea);
1768 case FCME_ELS_PLOGI_DONE:
1769 qla_handle_els_plogi_done(vha, ea);
1778 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1779 * to be consumed by the fcport
1781 void qla_rscn_replay(fc_port_t *fcport)
1783 struct event_arg ea;
1785 switch (fcport->disc_state) {
1786 case DSC_DELETE_PEND:
1792 if (fcport->scan_needed) {
1793 memset(&ea, 0, sizeof(ea));
1794 ea.event = FCME_RSCN;
1795 ea.id = fcport->d_id;
1796 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1797 qla2x00_fcport_event_handler(fcport->vha, &ea);
1802 qla2x00_tmf_iocb_timeout(void *data)
1805 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1807 tmf->u.tmf.comp_status = CS_TIMEOUT;
1808 complete(&tmf->u.tmf.comp);
1812 qla2x00_tmf_sp_done(void *ptr, int res)
1815 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1817 complete(&tmf->u.tmf.comp);
1821 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1824 struct scsi_qla_host *vha = fcport->vha;
1825 struct srb_iocb *tm_iocb;
1827 int rval = QLA_FUNCTION_FAILED;
1829 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1833 tm_iocb = &sp->u.iocb_cmd;
1834 sp->type = SRB_TM_CMD;
1837 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1838 init_completion(&tm_iocb->u.tmf.comp);
1839 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1841 tm_iocb->u.tmf.flags = flags;
1842 tm_iocb->u.tmf.lun = lun;
1843 tm_iocb->u.tmf.data = tag;
1844 sp->done = qla2x00_tmf_sp_done;
1846 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1847 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1848 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1849 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1851 rval = qla2x00_start_sp(sp);
1852 if (rval != QLA_SUCCESS)
1854 wait_for_completion(&tm_iocb->u.tmf.comp);
1856 rval = tm_iocb->u.tmf.data;
1858 if (rval != QLA_SUCCESS) {
1859 ql_log(ql_log_warn, vha, 0x8030,
1860 "TM IOCB failed (%x).\n", rval);
1863 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1864 flags = tm_iocb->u.tmf.flags;
1865 lun = (uint16_t)tm_iocb->u.tmf.lun;
1867 /* Issue Marker IOCB */
1868 qla2x00_marker(vha, vha->hw->base_qpair,
1869 fcport->loop_id, lun,
1870 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1875 fcport->flags &= ~FCF_ASYNC_SENT;
1881 qla24xx_async_abort_command(srb_t *sp)
1883 unsigned long flags = 0;
1886 fc_port_t *fcport = sp->fcport;
1887 struct qla_qpair *qpair = sp->qpair;
1888 struct scsi_qla_host *vha = fcport->vha;
1889 struct req_que *req = qpair->req;
1891 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1892 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1893 if (req->outstanding_cmds[handle] == sp)
1896 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1898 if (handle == req->num_outstanding_cmds) {
1899 /* Command not found. */
1900 return QLA_FUNCTION_FAILED;
1902 if (sp->type == SRB_FXIOCB_DCMD)
1903 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1904 FXDISC_ABORT_IOCTL);
1906 return qla24xx_async_abort_cmd(sp, true);
1910 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1912 switch (ea->data[0]) {
1913 case MBS_COMMAND_COMPLETE:
1914 ql_dbg(ql_dbg_disc, vha, 0x2118,
1915 "%s %d %8phC post gpdb\n",
1916 __func__, __LINE__, ea->fcport->port_name);
1918 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1919 ea->fcport->logout_on_delete = 1;
1920 ea->fcport->nvme_prli_service_param = ea->iop[0];
1921 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1922 ea->fcport->nvme_first_burst_size =
1923 (ea->iop[1] & 0xffff) * 512;
1925 ea->fcport->nvme_first_burst_size = 0;
1926 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1929 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1930 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1931 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1932 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1936 if (ea->fcport->n2n_flag) {
1937 ql_dbg(ql_dbg_disc, vha, 0x2118,
1938 "%s %d %8phC post fc4 prli\n",
1939 __func__, __LINE__, ea->fcport->port_name);
1940 ea->fcport->fc4f_nvme = 0;
1941 ea->fcport->n2n_flag = 0;
1942 qla24xx_post_prli_work(vha, ea->fcport);
1944 ql_dbg(ql_dbg_disc, vha, 0x2119,
1945 "%s %d %8phC unhandle event of %x\n",
1946 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1952 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1954 port_id_t cid; /* conflict Nport id */
1956 struct fc_port *conflict_fcport;
1957 unsigned long flags;
1958 struct fc_port *fcport = ea->fcport;
1960 ql_dbg(ql_dbg_disc, vha, 0xffff,
1961 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1962 __func__, fcport->port_name, fcport->disc_state,
1963 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1964 ea->sp->gen1, fcport->rscn_gen,
1965 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1967 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1968 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1969 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1970 "%s %d %8phC Remote is trying to login\n",
1971 __func__, __LINE__, fcport->port_name);
1975 if ((fcport->disc_state == DSC_DELETE_PEND) ||
1976 (fcport->disc_state == DSC_DELETED)) {
1977 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1981 if (ea->sp->gen2 != fcport->login_gen) {
1982 /* target side must have changed it. */
1983 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1984 "%s %8phC generation changed\n",
1985 __func__, fcport->port_name);
1986 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1988 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1989 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1990 "%s %8phC RSCN generation changed\n",
1991 __func__, fcport->port_name);
1992 qla_rscn_replay(fcport);
1993 qlt_schedule_sess_for_deletion(fcport);
1997 switch (ea->data[0]) {
1998 case MBS_COMMAND_COMPLETE:
2000 * Driver must validate login state - If PRLI not complete,
2001 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2004 if (ea->fcport->fc4f_nvme) {
2005 ql_dbg(ql_dbg_disc, vha, 0x2117,
2006 "%s %d %8phC post prli\n",
2007 __func__, __LINE__, ea->fcport->port_name);
2008 qla24xx_post_prli_work(vha, ea->fcport);
2010 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2011 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
2012 __func__, __LINE__, ea->fcport->port_name,
2013 ea->fcport->loop_id, ea->fcport->d_id.b24);
2015 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2016 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2017 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2018 ea->fcport->logout_on_delete = 1;
2019 ea->fcport->send_els_logo = 0;
2020 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2021 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2023 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2026 case MBS_COMMAND_ERROR:
2027 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2028 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2030 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2031 ea->fcport->disc_state = DSC_LOGIN_FAILED;
2032 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2033 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2035 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2037 case MBS_LOOP_ID_USED:
2038 /* data[1] = IO PARAM 1 = nport ID */
2039 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2040 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2041 cid.b.al_pa = ea->iop[1] & 0xff;
2044 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2045 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2046 __func__, __LINE__, ea->fcport->port_name,
2047 ea->fcport->loop_id, cid.b24);
2049 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2050 ea->fcport->loop_id = FC_NO_LOOP_ID;
2051 qla24xx_post_gnl_work(vha, ea->fcport);
2053 case MBS_PORT_ID_USED:
2054 lid = ea->iop[1] & 0xffff;
2055 qlt_find_sess_invalidate_other(vha,
2056 wwn_to_u64(ea->fcport->port_name),
2057 ea->fcport->d_id, lid, &conflict_fcport);
2059 if (conflict_fcport) {
2061 * Another fcport share the same loop_id/nport id.
2062 * Conflict fcport needs to finish cleanup before this
2063 * fcport can proceed to login.
2065 conflict_fcport->conflict = ea->fcport;
2066 ea->fcport->login_pause = 1;
2068 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2069 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2070 __func__, __LINE__, ea->fcport->port_name,
2071 ea->fcport->d_id.b24, lid);
2073 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2074 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2075 __func__, __LINE__, ea->fcport->port_name,
2076 ea->fcport->d_id.b24, lid);
2078 qla2x00_clear_loop_id(ea->fcport);
2079 set_bit(lid, vha->hw->loop_id_map);
2080 ea->fcport->loop_id = lid;
2081 ea->fcport->keep_nport_handle = 0;
2082 qlt_schedule_sess_for_deletion(ea->fcport);
2090 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2093 qlt_logo_completion_handler(fcport, data[0]);
2094 fcport->login_gen++;
2095 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2099 /****************************************************************************/
2100 /* QLogic ISP2x00 Hardware Support Functions. */
2101 /****************************************************************************/
2104 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2106 int rval = QLA_SUCCESS;
2107 struct qla_hw_data *ha = vha->hw;
2108 uint32_t idc_major_ver, idc_minor_ver;
2111 qla83xx_idc_lock(vha, 0);
2113 /* SV: TODO: Assign initialization timeout from
2114 * flash-info / other param
2116 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2117 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2119 /* Set our fcoe function presence */
2120 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2121 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2122 "Error while setting DRV-Presence.\n");
2123 rval = QLA_FUNCTION_FAILED;
2127 /* Decide the reset ownership */
2128 qla83xx_reset_ownership(vha);
2131 * On first protocol driver load:
2132 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2134 * Others: Check compatibility with current IDC Major version.
2136 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2137 if (ha->flags.nic_core_reset_owner) {
2138 /* Set IDC Major version */
2139 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2140 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2142 /* Clearing IDC-Lock-Recovery register */
2143 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2144 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2146 * Clear further IDC participation if we are not compatible with
2147 * the current IDC Major Version.
2149 ql_log(ql_log_warn, vha, 0xb07d,
2150 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2151 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2152 __qla83xx_clear_drv_presence(vha);
2153 rval = QLA_FUNCTION_FAILED;
2156 /* Each function sets its supported Minor version. */
2157 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2158 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2159 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2161 if (ha->flags.nic_core_reset_owner) {
2162 memset(config, 0, sizeof(config));
2163 if (!qla81xx_get_port_config(vha, config))
2164 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2168 rval = qla83xx_idc_state_handler(vha);
2171 qla83xx_idc_unlock(vha, 0);
2177 * qla2x00_initialize_adapter
2181 * ha = adapter block pointer.
2187 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2190 struct qla_hw_data *ha = vha->hw;
2191 struct req_que *req = ha->req_q_map[0];
2192 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2194 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2195 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2197 /* Clear adapter flags. */
2198 vha->flags.online = 0;
2199 ha->flags.chip_reset_done = 0;
2200 vha->flags.reset_active = 0;
2201 ha->flags.pci_channel_io_perm_failure = 0;
2202 ha->flags.eeh_busy = 0;
2203 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2204 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2205 atomic_set(&vha->loop_state, LOOP_DOWN);
2206 vha->device_flags = DFLG_NO_CABLE;
2208 vha->flags.management_server_logged_in = 0;
2209 vha->marker_needed = 0;
2210 ha->isp_abort_cnt = 0;
2211 ha->beacon_blink_led = 0;
2213 set_bit(0, ha->req_qid_map);
2214 set_bit(0, ha->rsp_qid_map);
2216 ql_dbg(ql_dbg_init, vha, 0x0040,
2217 "Configuring PCI space...\n");
2218 rval = ha->isp_ops->pci_config(vha);
2220 ql_log(ql_log_warn, vha, 0x0044,
2221 "Unable to configure PCI space.\n");
2225 ha->isp_ops->reset_chip(vha);
2227 /* Check for secure flash support */
2228 if (IS_QLA28XX(ha)) {
2229 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2230 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2231 ha->flags.secure_adapter = 1;
2236 rval = qla2xxx_get_flash_info(vha);
2238 ql_log(ql_log_fatal, vha, 0x004f,
2239 "Unable to validate FLASH data.\n");
2243 if (IS_QLA8044(ha)) {
2244 qla8044_read_reset_template(vha);
2246 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2247 * If DONRESET_BIT0 is set, drivers should not set dev_state
2248 * to NEED_RESET. But if NEED_RESET is set, drivers should
2249 * should honor the reset. */
2250 if (ql2xdontresethba == 1)
2251 qla8044_set_idc_dontreset(vha);
2254 ha->isp_ops->get_flash_version(vha, req->ring);
2255 ql_dbg(ql_dbg_init, vha, 0x0061,
2256 "Configure NVRAM parameters...\n");
2258 ha->isp_ops->nvram_config(vha);
2260 if (ha->flags.disable_serdes) {
2261 /* Mask HBA via NVRAM settings? */
2262 ql_log(ql_log_info, vha, 0x0077,
2263 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2264 return QLA_FUNCTION_FAILED;
2267 ql_dbg(ql_dbg_init, vha, 0x0078,
2268 "Verifying loaded RISC code...\n");
2270 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2271 rval = ha->isp_ops->chip_diag(vha);
2274 rval = qla2x00_setup_chip(vha);
2279 if (IS_QLA84XX(ha)) {
2280 ha->cs84xx = qla84xx_get_chip(vha);
2282 ql_log(ql_log_warn, vha, 0x00d0,
2283 "Unable to configure ISP84XX.\n");
2284 return QLA_FUNCTION_FAILED;
2288 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2289 rval = qla2x00_init_rings(vha);
2291 /* No point in continuing if firmware initialization failed. */
2292 if (rval != QLA_SUCCESS)
2295 ha->flags.chip_reset_done = 1;
2297 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2298 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2299 rval = qla84xx_init_chip(vha);
2300 if (rval != QLA_SUCCESS) {
2301 ql_log(ql_log_warn, vha, 0x00d4,
2302 "Unable to initialize ISP84XX.\n");
2303 qla84xx_put_chip(vha);
2307 /* Load the NIC Core f/w if we are the first protocol driver. */
2308 if (IS_QLA8031(ha)) {
2309 rval = qla83xx_nic_core_fw_load(vha);
2311 ql_log(ql_log_warn, vha, 0x0124,
2312 "Error in initializing NIC Core f/w.\n");
2315 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2316 qla24xx_read_fcp_prio_cfg(vha);
2318 if (IS_P3P_TYPE(ha))
2319 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2321 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2327 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2330 * Returns 0 on success.
2333 qla2100_pci_config(scsi_qla_host_t *vha)
2336 unsigned long flags;
2337 struct qla_hw_data *ha = vha->hw;
2338 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2340 pci_set_master(ha->pdev);
2341 pci_try_set_mwi(ha->pdev);
2343 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2344 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2345 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2347 pci_disable_rom(ha->pdev);
2349 /* Get PCI bus information. */
2350 spin_lock_irqsave(&ha->hardware_lock, flags);
2351 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2352 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2358 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2361 * Returns 0 on success.
2364 qla2300_pci_config(scsi_qla_host_t *vha)
2367 unsigned long flags = 0;
2369 struct qla_hw_data *ha = vha->hw;
2370 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2372 pci_set_master(ha->pdev);
2373 pci_try_set_mwi(ha->pdev);
2375 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2376 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2378 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2379 w &= ~PCI_COMMAND_INTX_DISABLE;
2380 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2383 * If this is a 2300 card and not 2312, reset the
2384 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2385 * the 2310 also reports itself as a 2300 so we need to get the
2386 * fb revision level -- a 6 indicates it really is a 2300 and
2389 if (IS_QLA2300(ha)) {
2390 spin_lock_irqsave(&ha->hardware_lock, flags);
2393 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2394 for (cnt = 0; cnt < 30000; cnt++) {
2395 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2401 /* Select FPM registers. */
2402 WRT_REG_WORD(®->ctrl_status, 0x20);
2403 RD_REG_WORD(®->ctrl_status);
2405 /* Get the fb rev level */
2406 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2408 if (ha->fb_rev == FPM_2300)
2409 pci_clear_mwi(ha->pdev);
2411 /* Deselect FPM registers. */
2412 WRT_REG_WORD(®->ctrl_status, 0x0);
2413 RD_REG_WORD(®->ctrl_status);
2415 /* Release RISC module. */
2416 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2417 for (cnt = 0; cnt < 30000; cnt++) {
2418 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2424 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2427 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2429 pci_disable_rom(ha->pdev);
2431 /* Get PCI bus information. */
2432 spin_lock_irqsave(&ha->hardware_lock, flags);
2433 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2434 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2440 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2443 * Returns 0 on success.
2446 qla24xx_pci_config(scsi_qla_host_t *vha)
2449 unsigned long flags = 0;
2450 struct qla_hw_data *ha = vha->hw;
2451 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2453 pci_set_master(ha->pdev);
2454 pci_try_set_mwi(ha->pdev);
2456 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2457 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2458 w &= ~PCI_COMMAND_INTX_DISABLE;
2459 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2461 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2463 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2464 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2465 pcix_set_mmrbc(ha->pdev, 2048);
2467 /* PCIe -- adjust Maximum Read Request Size (2048). */
2468 if (pci_is_pcie(ha->pdev))
2469 pcie_set_readrq(ha->pdev, 4096);
2471 pci_disable_rom(ha->pdev);
2473 ha->chip_revision = ha->pdev->revision;
2475 /* Get PCI bus information. */
2476 spin_lock_irqsave(&ha->hardware_lock, flags);
2477 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2478 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2484 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2487 * Returns 0 on success.
2490 qla25xx_pci_config(scsi_qla_host_t *vha)
2493 struct qla_hw_data *ha = vha->hw;
2495 pci_set_master(ha->pdev);
2496 pci_try_set_mwi(ha->pdev);
2498 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2499 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2500 w &= ~PCI_COMMAND_INTX_DISABLE;
2501 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2503 /* PCIe -- adjust Maximum Read Request Size (2048). */
2504 if (pci_is_pcie(ha->pdev))
2505 pcie_set_readrq(ha->pdev, 4096);
2507 pci_disable_rom(ha->pdev);
2509 ha->chip_revision = ha->pdev->revision;
2515 * qla2x00_isp_firmware() - Choose firmware image.
2518 * Returns 0 on success.
2521 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2524 uint16_t loop_id, topo, sw_cap;
2525 uint8_t domain, area, al_pa;
2526 struct qla_hw_data *ha = vha->hw;
2528 /* Assume loading risc code */
2529 rval = QLA_FUNCTION_FAILED;
2531 if (ha->flags.disable_risc_code_load) {
2532 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2534 /* Verify checksum of loaded RISC code. */
2535 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2536 if (rval == QLA_SUCCESS) {
2537 /* And, verify we are not in ROM code. */
2538 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2539 &area, &domain, &topo, &sw_cap);
2544 ql_dbg(ql_dbg_init, vha, 0x007a,
2545 "**** Load RISC code ****.\n");
2551 * qla2x00_reset_chip() - Reset ISP chip.
2554 * Returns 0 on success.
2557 qla2x00_reset_chip(scsi_qla_host_t *vha)
2559 unsigned long flags = 0;
2560 struct qla_hw_data *ha = vha->hw;
2561 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2564 int rval = QLA_FUNCTION_FAILED;
2566 if (unlikely(pci_channel_offline(ha->pdev)))
2569 ha->isp_ops->disable_intrs(ha);
2571 spin_lock_irqsave(&ha->hardware_lock, flags);
2573 /* Turn off master enable */
2575 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2576 cmd &= ~PCI_COMMAND_MASTER;
2577 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2579 if (!IS_QLA2100(ha)) {
2581 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2582 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2583 for (cnt = 0; cnt < 30000; cnt++) {
2584 if ((RD_REG_WORD(®->hccr) &
2585 HCCR_RISC_PAUSE) != 0)
2590 RD_REG_WORD(®->hccr); /* PCI Posting. */
2594 /* Select FPM registers. */
2595 WRT_REG_WORD(®->ctrl_status, 0x20);
2596 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2598 /* FPM Soft Reset. */
2599 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2600 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2602 /* Toggle Fpm Reset. */
2603 if (!IS_QLA2200(ha)) {
2604 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2605 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2608 /* Select frame buffer registers. */
2609 WRT_REG_WORD(®->ctrl_status, 0x10);
2610 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2612 /* Reset frame buffer FIFOs. */
2613 if (IS_QLA2200(ha)) {
2614 WRT_FB_CMD_REG(ha, reg, 0xa000);
2615 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2617 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2619 /* Read back fb_cmd until zero or 3 seconds max */
2620 for (cnt = 0; cnt < 3000; cnt++) {
2621 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2627 /* Select RISC module registers. */
2628 WRT_REG_WORD(®->ctrl_status, 0);
2629 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2631 /* Reset RISC processor. */
2632 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2633 RD_REG_WORD(®->hccr); /* PCI Posting. */
2635 /* Release RISC processor. */
2636 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2637 RD_REG_WORD(®->hccr); /* PCI Posting. */
2640 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2641 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2643 /* Reset ISP chip. */
2644 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2646 /* Wait for RISC to recover from reset. */
2647 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2649 * It is necessary to for a delay here since the card doesn't
2650 * respond to PCI reads during a reset. On some architectures
2651 * this will result in an MCA.
2654 for (cnt = 30000; cnt; cnt--) {
2655 if ((RD_REG_WORD(®->ctrl_status) &
2656 CSR_ISP_SOFT_RESET) == 0)
2663 /* Reset RISC processor. */
2664 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2666 WRT_REG_WORD(®->semaphore, 0);
2668 /* Release RISC processor. */
2669 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2670 RD_REG_WORD(®->hccr); /* PCI Posting. */
2672 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2673 for (cnt = 0; cnt < 30000; cnt++) {
2674 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2682 /* Turn on master enable */
2683 cmd |= PCI_COMMAND_MASTER;
2684 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2686 /* Disable RISC pause on FPM parity error. */
2687 if (!IS_QLA2100(ha)) {
2688 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2689 RD_REG_WORD(®->hccr); /* PCI Posting. */
2692 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2698 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2701 * Returns 0 on success.
2704 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2706 uint16_t mb[4] = {0x1010, 0, 1, 0};
2708 if (!IS_QLA81XX(vha->hw))
2711 return qla81xx_write_mpi_register(vha, mb);
2715 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2718 * Returns 0 on success.
2721 qla24xx_reset_risc(scsi_qla_host_t *vha)
2723 unsigned long flags = 0;
2724 struct qla_hw_data *ha = vha->hw;
2725 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2728 static int abts_cnt; /* ISP abort retry counts */
2729 int rval = QLA_SUCCESS;
2731 spin_lock_irqsave(&ha->hardware_lock, flags);
2734 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2735 for (cnt = 0; cnt < 30000; cnt++) {
2736 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2742 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2743 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2745 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2746 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2747 RD_REG_DWORD(®->hccr),
2748 RD_REG_DWORD(®->ctrl_status),
2749 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2751 WRT_REG_DWORD(®->ctrl_status,
2752 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2753 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2757 /* Wait for firmware to complete NVRAM accesses. */
2758 RD_REG_WORD(®->mailbox0);
2759 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2760 rval == QLA_SUCCESS; cnt--) {
2765 rval = QLA_FUNCTION_TIMEOUT;
2768 if (rval == QLA_SUCCESS)
2769 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2771 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2772 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2773 RD_REG_DWORD(®->hccr),
2774 RD_REG_DWORD(®->mailbox0));
2776 /* Wait for soft-reset to complete. */
2777 RD_REG_DWORD(®->ctrl_status);
2778 for (cnt = 0; cnt < 60; cnt++) {
2780 if ((RD_REG_DWORD(®->ctrl_status) &
2781 CSRX_ISP_SOFT_RESET) == 0)
2786 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2787 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2789 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2790 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2791 RD_REG_DWORD(®->hccr),
2792 RD_REG_DWORD(®->ctrl_status));
2794 /* If required, do an MPI FW reset now */
2795 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2796 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2797 if (++abts_cnt < 5) {
2798 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2799 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2802 * We exhausted the ISP abort retries. We have to
2803 * set the board offline.
2806 vha->flags.online = 0;
2811 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2812 RD_REG_DWORD(®->hccr);
2814 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2815 RD_REG_DWORD(®->hccr);
2817 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2818 RD_REG_DWORD(®->hccr);
2820 RD_REG_WORD(®->mailbox0);
2821 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2822 rval == QLA_SUCCESS; cnt--) {
2827 rval = QLA_FUNCTION_TIMEOUT;
2829 if (rval == QLA_SUCCESS)
2830 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2832 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2833 "Host Risc 0x%x, mailbox0 0x%x\n",
2834 RD_REG_DWORD(®->hccr),
2835 RD_REG_WORD(®->mailbox0));
2837 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2839 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2840 "Driver in %s mode\n",
2841 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2843 if (IS_NOPOLLING_TYPE(ha))
2844 ha->isp_ops->enable_intrs(ha);
2850 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2852 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2854 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2855 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2860 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2862 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2864 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2865 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2869 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2872 uint delta_msec = 100;
2873 uint elapsed_msec = 0;
2877 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2878 vha->hw->pdev->subsystem_device != 0x0240)
2881 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2885 timeout_msec = TIMEOUT_SEMAPHORE;
2886 n = timeout_msec / delta_msec;
2888 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2889 qla25xx_read_risc_sema_reg(vha, &wd32);
2890 if (wd32 & RISC_SEMAPHORE)
2893 elapsed_msec += delta_msec;
2894 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2898 if (!(wd32 & RISC_SEMAPHORE))
2901 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2904 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2905 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2906 n = timeout_msec / delta_msec;
2908 qla25xx_read_risc_sema_reg(vha, &wd32);
2909 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2912 elapsed_msec += delta_msec;
2913 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2917 if (wd32 & RISC_SEMAPHORE_FORCE)
2918 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2923 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2930 * qla24xx_reset_chip() - Reset ISP24xx chip.
2933 * Returns 0 on success.
2936 qla24xx_reset_chip(scsi_qla_host_t *vha)
2938 struct qla_hw_data *ha = vha->hw;
2939 int rval = QLA_FUNCTION_FAILED;
2941 if (pci_channel_offline(ha->pdev) &&
2942 ha->flags.pci_channel_io_perm_failure) {
2946 ha->isp_ops->disable_intrs(ha);
2948 qla25xx_manipulate_risc_semaphore(vha);
2950 /* Perform RISC reset. */
2951 rval = qla24xx_reset_risc(vha);
2957 * qla2x00_chip_diag() - Test chip for proper operation.
2960 * Returns 0 on success.
2963 qla2x00_chip_diag(scsi_qla_host_t *vha)
2966 struct qla_hw_data *ha = vha->hw;
2967 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2968 unsigned long flags = 0;
2972 struct req_que *req = ha->req_q_map[0];
2974 /* Assume a failed state */
2975 rval = QLA_FUNCTION_FAILED;
2977 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2978 ®->flash_address);
2980 spin_lock_irqsave(&ha->hardware_lock, flags);
2982 /* Reset ISP chip. */
2983 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2986 * We need to have a delay here since the card will not respond while
2987 * in reset causing an MCA on some architectures.
2990 data = qla2x00_debounce_register(®->ctrl_status);
2991 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2993 data = RD_REG_WORD(®->ctrl_status);
2998 goto chip_diag_failed;
3000 ql_dbg(ql_dbg_init, vha, 0x007c,
3001 "Reset register cleared by chip reset.\n");
3003 /* Reset RISC processor. */
3004 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3005 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3007 /* Workaround for QLA2312 PCI parity error */
3008 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3009 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3010 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3012 data = RD_MAILBOX_REG(ha, reg, 0);
3019 goto chip_diag_failed;
3021 /* Check product ID of chip */
3022 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3024 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3025 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3026 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3027 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3028 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3029 mb[3] != PROD_ID_3) {
3030 ql_log(ql_log_warn, vha, 0x0062,
3031 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3032 mb[1], mb[2], mb[3]);
3034 goto chip_diag_failed;
3036 ha->product_id[0] = mb[1];
3037 ha->product_id[1] = mb[2];
3038 ha->product_id[2] = mb[3];
3039 ha->product_id[3] = mb[4];
3041 /* Adjust fw RISC transfer size */
3042 if (req->length > 1024)
3043 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3045 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3048 if (IS_QLA2200(ha) &&
3049 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3050 /* Limit firmware transfer size with a 2200A */
3051 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3053 ha->device_type |= DT_ISP2200A;
3054 ha->fw_transfer_size = 128;
3057 /* Wrap Incoming Mailboxes Test. */
3058 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3060 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3061 rval = qla2x00_mbx_reg_test(vha);
3063 ql_log(ql_log_warn, vha, 0x0080,
3064 "Failed mailbox send register test.\n");
3066 /* Flag a successful rval */
3068 spin_lock_irqsave(&ha->hardware_lock, flags);
3072 ql_log(ql_log_info, vha, 0x0081,
3073 "Chip diagnostics **** FAILED ****.\n");
3075 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3081 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3084 * Returns 0 on success.
3087 qla24xx_chip_diag(scsi_qla_host_t *vha)
3090 struct qla_hw_data *ha = vha->hw;
3091 struct req_que *req = ha->req_q_map[0];
3093 if (IS_P3P_TYPE(ha))
3096 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3098 rval = qla2x00_mbx_reg_test(vha);
3100 ql_log(ql_log_warn, vha, 0x0082,
3101 "Failed mailbox send register test.\n");
3103 /* Flag a successful rval */
3111 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3116 struct qla_hw_data *ha = vha->hw;
3119 ql_dbg(ql_dbg_init, vha, 0x00bd,
3120 "%s: Offload Mem is already allocated.\n",
3125 if (IS_FWI2_CAPABLE(ha)) {
3126 /* Allocate memory for Fibre Channel Event Buffer. */
3127 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3128 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3132 dma_free_coherent(&ha->pdev->dev,
3133 FCE_SIZE, ha->fce, ha->fce_dma);
3135 /* Allocate memory for Fibre Channel Event Buffer. */
3136 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3139 ql_log(ql_log_warn, vha, 0x00be,
3140 "Unable to allocate (%d KB) for FCE.\n",
3145 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3146 ha->fce_mb, &ha->fce_bufs);
3148 ql_log(ql_log_warn, vha, 0x00bf,
3149 "Unable to initialize FCE (%d).\n", rval);
3150 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3152 ha->flags.fce_enabled = 0;
3155 ql_dbg(ql_dbg_init, vha, 0x00c0,
3156 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3158 ha->flags.fce_enabled = 1;
3159 ha->fce_dma = tc_dma;
3164 dma_free_coherent(&ha->pdev->dev,
3165 EFT_SIZE, ha->eft, ha->eft_dma);
3167 /* Allocate memory for Extended Trace Buffer. */
3168 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3171 ql_log(ql_log_warn, vha, 0x00c1,
3172 "Unable to allocate (%d KB) for EFT.\n",
3177 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3179 ql_log(ql_log_warn, vha, 0x00c2,
3180 "Unable to initialize EFT (%d).\n", rval);
3181 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3185 ql_dbg(ql_dbg_init, vha, 0x00c3,
3186 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3188 ha->eft_dma = tc_dma;
3197 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3200 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3201 eft_size, fce_size, mq_size;
3202 struct qla_hw_data *ha = vha->hw;
3203 struct req_que *req = ha->req_q_map[0];
3204 struct rsp_que *rsp = ha->rsp_q_map[0];
3205 struct qla2xxx_fw_dump *fw_dump;
3209 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3210 req_q_size = rsp_q_size = 0;
3212 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3213 fixed_size = sizeof(struct qla2100_fw_dump);
3214 } else if (IS_QLA23XX(ha)) {
3215 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3216 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3218 } else if (IS_FWI2_CAPABLE(ha)) {
3219 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3220 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3221 else if (IS_QLA81XX(ha))
3222 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3223 else if (IS_QLA25XX(ha))
3224 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3226 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3228 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3231 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3233 mq_size = sizeof(struct qla2xxx_mq_chain);
3235 * Allocate maximum buffer size for all queues - Q0.
3236 * Resizing must be done at end-of-dump processing.
3238 mq_size += (ha->max_req_queues - 1) *
3239 (req->length * sizeof(request_t));
3240 mq_size += (ha->max_rsp_queues - 1) *
3241 (rsp->length * sizeof(response_t));
3243 if (ha->tgt.atio_ring)
3244 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3245 /* Allocate memory for Fibre Channel Event Buffer. */
3246 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3247 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3250 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3253 dma_free_coherent(&ha->pdev->dev,
3254 EFT_SIZE, ha->eft, ha->eft_dma);
3256 /* Allocate memory for Extended Trace Buffer. */
3257 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3260 ql_log(ql_log_warn, vha, 0x00c1,
3261 "Unable to allocate (%d KB) for EFT.\n",
3266 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3268 ql_log(ql_log_warn, vha, 0x00c2,
3269 "Unable to initialize EFT (%d).\n", rval);
3270 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3273 ql_dbg(ql_dbg_init, vha, 0x00c3,
3274 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3275 eft_size = EFT_SIZE;
3278 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3279 struct fwdt *fwdt = ha->fwdt;
3282 for (j = 0; j < 2; j++, fwdt++) {
3283 if (!fwdt->template) {
3284 ql_log(ql_log_warn, vha, 0x00ba,
3285 "-> fwdt%u no template\n", j);
3288 ql_dbg(ql_dbg_init, vha, 0x00fa,
3289 "-> fwdt%u calculating fwdump size...\n", j);
3290 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3291 vha, fwdt->template);
3292 ql_dbg(ql_dbg_init, vha, 0x00fa,
3293 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3294 j, fwdt->dump_size);
3295 dump_size += fwdt->dump_size;
3300 req_q_size = req->length * sizeof(request_t);
3301 rsp_q_size = rsp->length * sizeof(response_t);
3302 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3303 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3304 ha->chain_offset = dump_size;
3305 dump_size += mq_size + fce_size;
3307 if (ha->exchoffld_buf)
3308 dump_size += sizeof(struct qla2xxx_offld_chain) +
3310 if (ha->exlogin_buf)
3311 dump_size += sizeof(struct qla2xxx_offld_chain) +
3315 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3317 ql_dbg(ql_dbg_init, vha, 0x00c5,
3318 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3319 __func__, dump_size, ha->fw_dump_len,
3320 ha->fw_dump_alloc_len);
3322 fw_dump = vmalloc(dump_size);
3324 ql_log(ql_log_warn, vha, 0x00c4,
3325 "Unable to allocate (%d KB) for firmware dump.\n",
3328 mutex_lock(&ha->optrom_mutex);
3329 if (ha->fw_dumped) {
3330 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3332 ha->fw_dump = fw_dump;
3333 ha->fw_dump_alloc_len = dump_size;
3334 ql_dbg(ql_dbg_init, vha, 0x00c5,
3335 "Re-Allocated (%d KB) and save firmware dump.\n",
3340 ha->fw_dump = fw_dump;
3342 ha->fw_dump_len = ha->fw_dump_alloc_len =
3344 ql_dbg(ql_dbg_init, vha, 0x00c5,
3345 "Allocated (%d KB) for firmware dump.\n",
3348 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3349 mutex_unlock(&ha->optrom_mutex);
3353 ha->fw_dump->signature[0] = 'Q';
3354 ha->fw_dump->signature[1] = 'L';
3355 ha->fw_dump->signature[2] = 'G';
3356 ha->fw_dump->signature[3] = 'C';
3357 ha->fw_dump->version = htonl(1);
3359 ha->fw_dump->fixed_size = htonl(fixed_size);
3360 ha->fw_dump->mem_size = htonl(mem_size);
3361 ha->fw_dump->req_q_size = htonl(req_q_size);
3362 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3364 ha->fw_dump->eft_size = htonl(eft_size);
3365 ha->fw_dump->eft_addr_l =
3366 htonl(LSD(ha->eft_dma));
3367 ha->fw_dump->eft_addr_h =
3368 htonl(MSD(ha->eft_dma));
3370 ha->fw_dump->header_size =
3372 (struct qla2xxx_fw_dump, isp));
3374 mutex_unlock(&ha->optrom_mutex);
3380 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3382 #define MPS_MASK 0xe0
3387 if (!IS_QLA81XX(vha->hw))
3390 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3391 if (rval != QLA_SUCCESS) {
3392 ql_log(ql_log_warn, vha, 0x0105,
3393 "Unable to acquire semaphore.\n");
3397 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3398 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3399 if (rval != QLA_SUCCESS) {
3400 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3405 if (dc == (dw & MPS_MASK))
3410 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3411 if (rval != QLA_SUCCESS) {
3412 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3416 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3417 if (rval != QLA_SUCCESS) {
3418 ql_log(ql_log_warn, vha, 0x006d,
3419 "Unable to release semaphore.\n");
3427 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3429 /* Don't try to reallocate the array */
3430 if (req->outstanding_cmds)
3433 if (!IS_FWI2_CAPABLE(ha))
3434 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3436 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3437 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3439 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3442 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3446 if (!req->outstanding_cmds) {
3448 * Try to allocate a minimal size just so we can get through
3451 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3452 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3456 if (!req->outstanding_cmds) {
3457 ql_log(ql_log_fatal, NULL, 0x0126,
3458 "Failed to allocate memory for "
3459 "outstanding_cmds for req_que %p.\n", req);
3460 req->num_outstanding_cmds = 0;
3461 return QLA_FUNCTION_FAILED;
3468 #define PRINT_FIELD(_field, _flag, _str) { \
3469 if (a0->_field & _flag) {\
3475 len = snprintf(ptr, leftover, "%s", _str); \
3482 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3485 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3486 u8 str[STR_LEN], *ptr, p;
3489 memset(str, 0, STR_LEN);
3490 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3491 ql_dbg(ql_dbg_init, vha, 0x015a,
3492 "SFP MFG Name: %s\n", str);
3494 memset(str, 0, STR_LEN);
3495 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3496 ql_dbg(ql_dbg_init, vha, 0x015c,
3497 "SFP Part Name: %s\n", str);
3500 memset(str, 0, STR_LEN);
3504 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3505 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3506 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3507 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3508 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3509 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3510 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3511 ql_dbg(ql_dbg_init, vha, 0x0160,
3512 "SFP Media: %s\n", str);
3515 memset(str, 0, STR_LEN);
3519 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3520 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3521 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3522 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3523 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3524 ql_dbg(ql_dbg_init, vha, 0x0196,
3525 "SFP Link Length: %s\n", str);
3527 memset(str, 0, STR_LEN);
3531 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3532 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3533 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3534 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3535 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3536 ql_dbg(ql_dbg_init, vha, 0x016e,
3537 "SFP FC Link Tech: %s\n", str);
3540 ql_dbg(ql_dbg_init, vha, 0x016f,
3541 "SFP Distant: %d km\n", a0->length_km);
3542 if (a0->length_100m)
3543 ql_dbg(ql_dbg_init, vha, 0x0170,
3544 "SFP Distant: %d m\n", a0->length_100m*100);
3545 if (a0->length_50um_10m)
3546 ql_dbg(ql_dbg_init, vha, 0x0189,
3547 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3548 if (a0->length_62um_10m)
3549 ql_dbg(ql_dbg_init, vha, 0x018a,
3550 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3551 if (a0->length_om4_10m)
3552 ql_dbg(ql_dbg_init, vha, 0x0194,
3553 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3554 if (a0->length_om3_10m)
3555 ql_dbg(ql_dbg_init, vha, 0x0195,
3556 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3562 * QLA_SUCCESS: no action
3563 * QLA_INTERFACE_ERROR: SFP is not there.
3564 * QLA_FUNCTION_FAILED: detected New SFP
3567 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3569 int rc = QLA_SUCCESS;
3570 struct sff_8247_a0 *a;
3571 struct qla_hw_data *ha = vha->hw;
3573 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3576 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3580 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3581 qla2xxx_print_sfp_info(vha);
3583 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3585 ha->flags.detected_lr_sfp = 1;
3587 if (a->length_km > 5 || a->length_100m > 50)
3588 ha->long_range_distance = LR_DISTANCE_10K;
3590 ha->long_range_distance = LR_DISTANCE_5K;
3592 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3593 ql_dbg(ql_dbg_async, vha, 0x507b,
3594 "Detected Long Range SFP.\n");
3597 ha->flags.detected_lr_sfp = 0;
3598 if (ha->flags.using_lr_setting)
3599 ql_dbg(ql_dbg_async, vha, 0x5084,
3600 "Detected Short Range SFP.\n");
3603 if (!vha->flags.init_done)
3610 * qla2x00_setup_chip() - Load and start RISC firmware.
3613 * Returns 0 on success.
3616 qla2x00_setup_chip(scsi_qla_host_t *vha)
3619 uint32_t srisc_address = 0;
3620 struct qla_hw_data *ha = vha->hw;
3621 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3622 unsigned long flags;
3623 uint16_t fw_major_version;
3625 if (IS_P3P_TYPE(ha)) {
3626 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3627 if (rval == QLA_SUCCESS) {
3628 qla2x00_stop_firmware(vha);
3629 goto enable_82xx_npiv;
3634 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3635 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3636 spin_lock_irqsave(&ha->hardware_lock, flags);
3637 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3638 RD_REG_WORD(®->hccr);
3639 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3642 qla81xx_mpi_sync(vha);
3644 /* Load firmware sequences */
3645 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3646 if (rval == QLA_SUCCESS) {
3647 ql_dbg(ql_dbg_init, vha, 0x00c9,
3648 "Verifying Checksum of loaded RISC code.\n");
3650 rval = qla2x00_verify_checksum(vha, srisc_address);
3651 if (rval == QLA_SUCCESS) {
3652 /* Start firmware execution. */
3653 ql_dbg(ql_dbg_init, vha, 0x00ca,
3654 "Starting firmware.\n");
3657 ha->flags.exlogins_enabled = 1;
3659 if (qla_is_exch_offld_enabled(vha))
3660 ha->flags.exchoffld_enabled = 1;
3662 rval = qla2x00_execute_fw(vha, srisc_address);
3663 /* Retrieve firmware information. */
3664 if (rval == QLA_SUCCESS) {
3665 qla24xx_detect_sfp(vha);
3667 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3669 (ha->zio_mode == QLA_ZIO_MODE_6))
3670 qla27xx_set_zio_threshold(vha,
3671 ha->last_zio_threshold);
3673 rval = qla2x00_set_exlogins_buffer(vha);
3674 if (rval != QLA_SUCCESS)
3677 rval = qla2x00_set_exchoffld_buffer(vha);
3678 if (rval != QLA_SUCCESS)
3682 fw_major_version = ha->fw_major_version;
3683 if (IS_P3P_TYPE(ha))
3684 qla82xx_check_md_needed(vha);
3686 rval = qla2x00_get_fw_version(vha);
3687 if (rval != QLA_SUCCESS)
3689 ha->flags.npiv_supported = 0;
3690 if (IS_QLA2XXX_MIDTYPE(ha) &&
3691 (ha->fw_attributes & BIT_2)) {
3692 ha->flags.npiv_supported = 1;
3693 if ((!ha->max_npiv_vports) ||
3694 ((ha->max_npiv_vports + 1) %
3695 MIN_MULTI_ID_FABRIC))
3696 ha->max_npiv_vports =
3697 MIN_MULTI_ID_FABRIC - 1;
3699 qla2x00_get_resource_cnts(vha);
3702 * Allocate the array of outstanding commands
3703 * now that we know the firmware resources.
3705 rval = qla2x00_alloc_outstanding_cmds(ha,
3707 if (rval != QLA_SUCCESS)
3710 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3711 qla2x00_alloc_offload_mem(vha);
3713 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3714 qla2x00_alloc_fw_dump(vha);
3720 ql_log(ql_log_fatal, vha, 0x00cd,
3721 "ISP Firmware failed checksum.\n");
3727 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3728 /* Enable proper parity. */
3729 spin_lock_irqsave(&ha->hardware_lock, flags);
3732 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3734 /* SRAM, Instruction RAM and GP RAM parity */
3735 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3736 RD_REG_WORD(®->hccr);
3737 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3740 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3741 ha->flags.fac_supported = 1;
3742 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3745 rval = qla81xx_fac_get_sector_size(vha, &size);
3746 if (rval == QLA_SUCCESS) {
3747 ha->flags.fac_supported = 1;
3748 ha->fdt_block_size = size << 2;
3750 ql_log(ql_log_warn, vha, 0x00ce,
3751 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3752 ha->fw_major_version, ha->fw_minor_version,
3753 ha->fw_subminor_version);
3755 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3757 ha->flags.fac_supported = 0;
3764 ql_log(ql_log_fatal, vha, 0x00cf,
3765 "Setup chip ****FAILED****.\n");
3772 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3773 * @rsp: response queue
3775 * Beginning of request ring has initialization control block already built
3776 * by nvram config routine.
3778 * Returns 0 on success.
3781 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3786 rsp->ring_ptr = rsp->ring;
3787 rsp->ring_index = 0;
3788 rsp->status_srb = NULL;
3789 pkt = rsp->ring_ptr;
3790 for (cnt = 0; cnt < rsp->length; cnt++) {
3791 pkt->signature = RESPONSE_PROCESSED;
3797 * qla2x00_update_fw_options() - Read and process firmware options.
3800 * Returns 0 on success.
3803 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3805 uint16_t swing, emphasis, tx_sens, rx_sens;
3806 struct qla_hw_data *ha = vha->hw;
3808 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3809 qla2x00_get_fw_options(vha, ha->fw_options);
3811 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3814 /* Serial Link options. */
3815 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3816 "Serial link options.\n");
3817 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3818 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3820 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3821 if (ha->fw_seriallink_options[3] & BIT_2) {
3822 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3825 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3826 emphasis = (ha->fw_seriallink_options[2] &
3827 (BIT_4 | BIT_3)) >> 3;
3828 tx_sens = ha->fw_seriallink_options[0] &
3829 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3830 rx_sens = (ha->fw_seriallink_options[0] &
3831 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3832 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3833 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3836 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3837 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3838 ha->fw_options[10] |= BIT_5 |
3839 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3840 (tx_sens & (BIT_1 | BIT_0));
3843 swing = (ha->fw_seriallink_options[2] &
3844 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3845 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3846 tx_sens = ha->fw_seriallink_options[1] &
3847 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3848 rx_sens = (ha->fw_seriallink_options[1] &
3849 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3850 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3851 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3854 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3855 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3856 ha->fw_options[11] |= BIT_5 |
3857 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3858 (tx_sens & (BIT_1 | BIT_0));
3862 /* Return command IOCBs without waiting for an ABTS to complete. */
3863 ha->fw_options[3] |= BIT_13;
3866 if (ha->flags.enable_led_scheme)
3867 ha->fw_options[2] |= BIT_12;
3869 /* Detect ISP6312. */
3871 ha->fw_options[2] |= BIT_13;
3873 /* Set Retry FLOGI in case of P2P connection */
3874 if (ha->operating_mode == P2P) {
3875 ha->fw_options[2] |= BIT_3;
3876 ql_dbg(ql_dbg_disc, vha, 0x2100,
3877 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3878 __func__, ha->fw_options[2]);
3881 /* Update firmware options. */
3882 qla2x00_set_fw_options(vha, ha->fw_options);
3886 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3889 struct qla_hw_data *ha = vha->hw;
3891 if (IS_P3P_TYPE(ha))
3894 /* Hold status IOCBs until ABTS response received. */
3896 ha->fw_options[3] |= BIT_12;
3898 /* Set Retry FLOGI in case of P2P connection */
3899 if (ha->operating_mode == P2P) {
3900 ha->fw_options[2] |= BIT_3;
3901 ql_dbg(ql_dbg_disc, vha, 0x2101,
3902 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3903 __func__, ha->fw_options[2]);
3906 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3907 if (ql2xmvasynctoatio &&
3908 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3909 if (qla_tgt_mode_enabled(vha) ||
3910 qla_dual_mode_enabled(vha))
3911 ha->fw_options[2] |= BIT_11;
3913 ha->fw_options[2] &= ~BIT_11;
3916 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3919 * Tell FW to track each exchange to prevent
3920 * driver from using stale exchange.
3922 if (qla_tgt_mode_enabled(vha) ||
3923 qla_dual_mode_enabled(vha))
3924 ha->fw_options[2] |= BIT_4;
3926 ha->fw_options[2] &= ~BIT_4;
3928 /* Reserve 1/2 of emergency exchanges for ELS.*/
3929 if (qla2xuseresexchforels)
3930 ha->fw_options[2] |= BIT_8;
3932 ha->fw_options[2] &= ~BIT_8;
3935 ql_dbg(ql_dbg_init, vha, 0x00e8,
3936 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3937 __func__, ha->fw_options[1], ha->fw_options[2],
3938 ha->fw_options[3], vha->host->active_mode);
3940 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3941 qla2x00_set_fw_options(vha, ha->fw_options);
3943 /* Update Serial Link options. */
3944 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3947 rval = qla2x00_set_serdes_params(vha,
3948 le16_to_cpu(ha->fw_seriallink_options24[1]),
3949 le16_to_cpu(ha->fw_seriallink_options24[2]),
3950 le16_to_cpu(ha->fw_seriallink_options24[3]));
3951 if (rval != QLA_SUCCESS) {
3952 ql_log(ql_log_warn, vha, 0x0104,
3953 "Unable to update Serial Link options (%x).\n", rval);
3958 qla2x00_config_rings(struct scsi_qla_host *vha)
3960 struct qla_hw_data *ha = vha->hw;
3961 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3962 struct req_que *req = ha->req_q_map[0];
3963 struct rsp_que *rsp = ha->rsp_q_map[0];
3965 /* Setup ring parameters in initialization control block. */
3966 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3967 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3968 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3969 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3970 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3971 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3973 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3974 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3975 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3976 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3977 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3981 qla24xx_config_rings(struct scsi_qla_host *vha)
3983 struct qla_hw_data *ha = vha->hw;
3984 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3985 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3986 struct qla_msix_entry *msix;
3987 struct init_cb_24xx *icb;
3989 struct req_que *req = ha->req_q_map[0];
3990 struct rsp_que *rsp = ha->rsp_q_map[0];
3992 /* Setup ring parameters in initialization control block. */
3993 icb = (struct init_cb_24xx *)ha->init_cb;
3994 icb->request_q_outpointer = cpu_to_le16(0);
3995 icb->response_q_inpointer = cpu_to_le16(0);
3996 icb->request_q_length = cpu_to_le16(req->length);
3997 icb->response_q_length = cpu_to_le16(rsp->length);
3998 put_unaligned_le64(req->dma, &icb->request_q_address);
3999 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4001 /* Setup ATIO queue dma pointers for target mode */
4002 icb->atio_q_inpointer = cpu_to_le16(0);
4003 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4004 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4006 if (IS_SHADOW_REG_CAPABLE(ha))
4007 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4009 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4011 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4012 icb->rid = cpu_to_le16(rid);
4013 if (ha->flags.msix_enabled) {
4014 msix = &ha->msix_entries[1];
4015 ql_dbg(ql_dbg_init, vha, 0x0019,
4016 "Registering vector 0x%x for base que.\n",
4018 icb->msix = cpu_to_le16(msix->entry);
4020 /* Use alternate PCI bus number */
4022 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4023 /* Use alternate PCI devfn */
4025 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4027 /* Use Disable MSIX Handshake mode for capable adapters */
4028 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4029 (ha->flags.msix_enabled)) {
4030 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4031 ha->flags.disable_msix_handshake = 1;
4032 ql_dbg(ql_dbg_init, vha, 0x00fe,
4033 "MSIX Handshake Disable Mode turned on.\n");
4035 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4037 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4039 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
4040 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
4041 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
4042 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4044 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4045 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4046 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4047 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4050 qlt_24xx_config_rings(vha);
4052 /* If the user has configured the speed, set it here */
4053 if (ha->set_data_rate) {
4054 ql_dbg(ql_dbg_init, vha, 0x00fd,
4055 "Speed set by user : %s Gbps \n",
4056 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4057 icb->firmware_options_3 = (ha->set_data_rate << 13);
4061 RD_REG_DWORD(&ioreg->hccr);
4065 * qla2x00_init_rings() - Initializes firmware.
4068 * Beginning of request ring has initialization control block already built
4069 * by nvram config routine.
4071 * Returns 0 on success.
4074 qla2x00_init_rings(scsi_qla_host_t *vha)
4077 unsigned long flags = 0;
4079 struct qla_hw_data *ha = vha->hw;
4080 struct req_que *req;
4081 struct rsp_que *rsp;
4082 struct mid_init_cb_24xx *mid_init_cb =
4083 (struct mid_init_cb_24xx *) ha->init_cb;
4085 spin_lock_irqsave(&ha->hardware_lock, flags);
4087 /* Clear outstanding commands array. */
4088 for (que = 0; que < ha->max_req_queues; que++) {
4089 req = ha->req_q_map[que];
4090 if (!req || !test_bit(que, ha->req_qid_map))
4092 req->out_ptr = (void *)(req->ring + req->length);
4094 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4095 req->outstanding_cmds[cnt] = NULL;
4097 req->current_outstanding_cmd = 1;
4099 /* Initialize firmware. */
4100 req->ring_ptr = req->ring;
4101 req->ring_index = 0;
4102 req->cnt = req->length;
4105 for (que = 0; que < ha->max_rsp_queues; que++) {
4106 rsp = ha->rsp_q_map[que];
4107 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4109 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4111 /* Initialize response queue entries */
4113 qlafx00_init_response_q_entries(rsp);
4115 qla2x00_init_response_q_entries(rsp);
4118 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4119 ha->tgt.atio_ring_index = 0;
4120 /* Initialize ATIO queue entries */
4121 qlt_init_atio_q_entries(vha);
4123 ha->isp_ops->config_rings(vha);
4125 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4127 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4129 if (IS_QLAFX00(ha)) {
4130 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4134 /* Update any ISP specific firmware options before initialization. */
4135 ha->isp_ops->update_fw_options(vha);
4137 if (ha->flags.npiv_supported) {
4138 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4139 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4140 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4143 if (IS_FWI2_CAPABLE(ha)) {
4144 mid_init_cb->options = cpu_to_le16(BIT_1);
4145 mid_init_cb->init_cb.execution_throttle =
4146 cpu_to_le16(ha->cur_fw_xcb_count);
4147 ha->flags.dport_enabled =
4148 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4149 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4150 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4151 /* FA-WWPN Status */
4152 ha->flags.fawwpn_enabled =
4153 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4154 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4155 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4158 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4161 ql_log(ql_log_fatal, vha, 0x00d2,
4162 "Init Firmware **** FAILED ****.\n");
4164 ql_dbg(ql_dbg_init, vha, 0x00d3,
4165 "Init Firmware -- success.\n");
4167 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4174 * qla2x00_fw_ready() - Waits for firmware ready.
4177 * Returns 0 on success.
4180 qla2x00_fw_ready(scsi_qla_host_t *vha)
4183 unsigned long wtime, mtime, cs84xx_time;
4184 uint16_t min_wait; /* Minimum wait time if loop is down */
4185 uint16_t wait_time; /* Wait time if loop is coming ready */
4187 struct qla_hw_data *ha = vha->hw;
4189 if (IS_QLAFX00(vha->hw))
4190 return qlafx00_fw_ready(vha);
4194 /* Time to wait for loop down */
4195 if (IS_P3P_TYPE(ha))
4201 * Firmware should take at most one RATOV to login, plus 5 seconds for
4202 * our own processing.
4204 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4205 wait_time = min_wait;
4208 /* Min wait time if loop down */
4209 mtime = jiffies + (min_wait * HZ);
4211 /* wait time before firmware ready */
4212 wtime = jiffies + (wait_time * HZ);
4214 /* Wait for ISP to finish LIP */
4215 if (!vha->flags.init_done)
4216 ql_log(ql_log_info, vha, 0x801e,
4217 "Waiting for LIP to complete.\n");
4220 memset(state, -1, sizeof(state));
4221 rval = qla2x00_get_firmware_state(vha, state);
4222 if (rval == QLA_SUCCESS) {
4223 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4224 vha->device_flags &= ~DFLG_NO_CABLE;
4226 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4227 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4228 "fw_state=%x 84xx=%x.\n", state[0],
4230 if ((state[2] & FSTATE_LOGGED_IN) &&
4231 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4232 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4233 "Sending verify iocb.\n");
4235 cs84xx_time = jiffies;
4236 rval = qla84xx_init_chip(vha);
4237 if (rval != QLA_SUCCESS) {
4240 "Init chip failed.\n");
4244 /* Add time taken to initialize. */
4245 cs84xx_time = jiffies - cs84xx_time;
4246 wtime += cs84xx_time;
4247 mtime += cs84xx_time;
4248 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4249 "Increasing wait time by %ld. "
4250 "New time %ld.\n", cs84xx_time,
4253 } else if (state[0] == FSTATE_READY) {
4254 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4255 "F/W Ready - OK.\n");
4257 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4258 &ha->login_timeout, &ha->r_a_tov);
4264 rval = QLA_FUNCTION_FAILED;
4266 if (atomic_read(&vha->loop_down_timer) &&
4267 state[0] != FSTATE_READY) {
4268 /* Loop down. Timeout on min_wait for states
4269 * other than Wait for Login.
4271 if (time_after_eq(jiffies, mtime)) {
4272 ql_log(ql_log_info, vha, 0x8038,
4273 "Cable is unplugged...\n");
4275 vha->device_flags |= DFLG_NO_CABLE;
4280 /* Mailbox cmd failed. Timeout on min_wait. */
4281 if (time_after_eq(jiffies, mtime) ||
4282 ha->flags.isp82xx_fw_hung)
4286 if (time_after_eq(jiffies, wtime))
4289 /* Delay for a while */
4293 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4294 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4295 state[1], state[2], state[3], state[4], state[5], jiffies);
4297 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4298 ql_log(ql_log_warn, vha, 0x803b,
4299 "Firmware ready **** FAILED ****.\n");
4306 * qla2x00_configure_hba
4307 * Setup adapter context.
4310 * ha = adapter state pointer.
4319 qla2x00_configure_hba(scsi_qla_host_t *vha)
4328 char connect_type[22];
4329 struct qla_hw_data *ha = vha->hw;
4330 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4332 unsigned long flags;
4334 /* Get host addresses. */
4335 rval = qla2x00_get_adapter_id(vha,
4336 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4337 if (rval != QLA_SUCCESS) {
4338 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4339 IS_CNA_CAPABLE(ha) ||
4340 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4341 ql_dbg(ql_dbg_disc, vha, 0x2008,
4342 "Loop is in a transition state.\n");
4344 ql_log(ql_log_warn, vha, 0x2009,
4345 "Unable to get host loop ID.\n");
4346 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4347 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4348 ql_log(ql_log_warn, vha, 0x1151,
4349 "Doing link init.\n");
4350 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4353 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4359 ql_log(ql_log_info, vha, 0x200a,
4360 "Cannot get topology - retrying.\n");
4361 return (QLA_FUNCTION_FAILED);
4364 vha->loop_id = loop_id;
4367 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4368 ha->operating_mode = LOOP;
4373 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4374 ha->current_topology = ISP_CFG_NL;
4375 strcpy(connect_type, "(Loop)");
4379 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4380 ha->switch_cap = sw_cap;
4381 ha->current_topology = ISP_CFG_FL;
4382 strcpy(connect_type, "(FL_Port)");
4386 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4387 ha->operating_mode = P2P;
4388 ha->current_topology = ISP_CFG_N;
4389 strcpy(connect_type, "(N_Port-to-N_Port)");
4393 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4394 ha->switch_cap = sw_cap;
4395 ha->operating_mode = P2P;
4396 ha->current_topology = ISP_CFG_F;
4397 strcpy(connect_type, "(F_Port)");
4401 ql_dbg(ql_dbg_disc, vha, 0x200f,
4402 "HBA in unknown topology %x, using NL.\n", topo);
4403 ha->current_topology = ISP_CFG_NL;
4404 strcpy(connect_type, "(Loop)");
4408 /* Save Host port and loop ID. */
4409 /* byte order - Big Endian */
4410 id.b.domain = domain;
4414 spin_lock_irqsave(&ha->hardware_lock, flags);
4415 if (!(topo == 2 && ha->flags.n2n_bigger))
4416 qlt_update_host_map(vha, id);
4417 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4419 if (!vha->flags.init_done)
4420 ql_log(ql_log_info, vha, 0x2010,
4421 "Topology - %s, Host Loop address 0x%x.\n",
4422 connect_type, vha->loop_id);
4428 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4433 uint64_t zero[2] = { 0 };
4434 struct qla_hw_data *ha = vha->hw;
4435 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4436 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4438 if (len > sizeof(zero))
4440 if (memcmp(model, &zero, len) != 0) {
4441 memcpy(ha->model_number, model, len);
4442 st = en = ha->model_number;
4445 if (*en != 0x20 && *en != 0x00)
4450 index = (ha->pdev->subsystem_device & 0xff);
4452 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4453 index < QLA_MODEL_NAMES)
4454 strlcpy(ha->model_desc,
4455 qla2x00_model_name[index * 2 + 1],
4456 sizeof(ha->model_desc));
4458 index = (ha->pdev->subsystem_device & 0xff);
4460 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4461 index < QLA_MODEL_NAMES) {
4462 strlcpy(ha->model_number,
4463 qla2x00_model_name[index * 2],
4464 sizeof(ha->model_number));
4465 strlcpy(ha->model_desc,
4466 qla2x00_model_name[index * 2 + 1],
4467 sizeof(ha->model_desc));
4469 strlcpy(ha->model_number, def,
4470 sizeof(ha->model_number));
4473 if (IS_FWI2_CAPABLE(ha))
4474 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4475 sizeof(ha->model_desc));
4478 /* On sparc systems, obtain port and node WWN from firmware
4481 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4484 struct qla_hw_data *ha = vha->hw;
4485 struct pci_dev *pdev = ha->pdev;
4486 struct device_node *dp = pci_device_to_OF_node(pdev);
4490 val = of_get_property(dp, "port-wwn", &len);
4491 if (val && len >= WWN_SIZE)
4492 memcpy(nv->port_name, val, WWN_SIZE);
4494 val = of_get_property(dp, "node-wwn", &len);
4495 if (val && len >= WWN_SIZE)
4496 memcpy(nv->node_name, val, WWN_SIZE);
4501 * NVRAM configuration for ISP 2xxx
4504 * ha = adapter block pointer.
4507 * initialization control block in response_ring
4508 * host adapters parameters in host adapter block
4514 qla2x00_nvram_config(scsi_qla_host_t *vha)
4519 uint8_t *dptr1, *dptr2;
4520 struct qla_hw_data *ha = vha->hw;
4521 init_cb_t *icb = ha->init_cb;
4522 nvram_t *nv = ha->nvram;
4523 uint8_t *ptr = ha->nvram;
4524 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4528 /* Determine NVRAM starting address. */
4529 ha->nvram_size = sizeof(*nv);
4531 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4532 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4533 ha->nvram_base = 0x80;
4535 /* Get NVRAM data and calculate checksum. */
4536 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4537 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4540 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4541 "Contents of NVRAM.\n");
4542 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4543 nv, ha->nvram_size);
4545 /* Bad NVRAM data, set defaults parameters. */
4546 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4547 nv->nvram_version < 1) {
4548 /* Reset NVRAM data. */
4549 ql_log(ql_log_warn, vha, 0x0064,
4550 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4551 chksum, nv->id, nv->nvram_version);
4552 ql_log(ql_log_warn, vha, 0x0065,
4554 "functioning (yet invalid -- WWPN) defaults.\n");
4557 * Set default initialization control block.
4559 memset(nv, 0, ha->nvram_size);
4560 nv->parameter_block_version = ICB_VERSION;
4562 if (IS_QLA23XX(ha)) {
4563 nv->firmware_options[0] = BIT_2 | BIT_1;
4564 nv->firmware_options[1] = BIT_7 | BIT_5;
4565 nv->add_firmware_options[0] = BIT_5;
4566 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4567 nv->frame_payload_size = 2048;
4568 nv->special_options[1] = BIT_7;
4569 } else if (IS_QLA2200(ha)) {
4570 nv->firmware_options[0] = BIT_2 | BIT_1;
4571 nv->firmware_options[1] = BIT_7 | BIT_5;
4572 nv->add_firmware_options[0] = BIT_5;
4573 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4574 nv->frame_payload_size = 1024;
4575 } else if (IS_QLA2100(ha)) {
4576 nv->firmware_options[0] = BIT_3 | BIT_1;
4577 nv->firmware_options[1] = BIT_5;
4578 nv->frame_payload_size = 1024;
4581 nv->max_iocb_allocation = cpu_to_le16(256);
4582 nv->execution_throttle = cpu_to_le16(16);
4583 nv->retry_count = 8;
4584 nv->retry_delay = 1;
4586 nv->port_name[0] = 33;
4587 nv->port_name[3] = 224;
4588 nv->port_name[4] = 139;
4590 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4592 nv->login_timeout = 4;
4595 * Set default host adapter parameters
4597 nv->host_p[1] = BIT_2;
4598 nv->reset_delay = 5;
4599 nv->port_down_retry_count = 8;
4600 nv->max_luns_per_target = cpu_to_le16(8);
4601 nv->link_down_timeout = 60;
4606 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4608 * The SN2 does not provide BIOS emulation which means you can't change
4609 * potentially bogus BIOS settings. Force the use of default settings
4610 * for link rate and frame size. Hope that the rest of the settings
4613 if (ia64_platform_is("sn2")) {
4614 nv->frame_payload_size = 2048;
4616 nv->special_options[1] = BIT_7;
4620 /* Reset Initialization control block */
4621 memset(icb, 0, ha->init_cb_size);
4624 * Setup driver NVRAM options.
4626 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4627 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4628 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4629 nv->firmware_options[1] &= ~BIT_4;
4631 if (IS_QLA23XX(ha)) {
4632 nv->firmware_options[0] |= BIT_2;
4633 nv->firmware_options[0] &= ~BIT_3;
4634 nv->special_options[0] &= ~BIT_6;
4635 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4637 if (IS_QLA2300(ha)) {
4638 if (ha->fb_rev == FPM_2310) {
4639 strcpy(ha->model_number, "QLA2310");
4641 strcpy(ha->model_number, "QLA2300");
4644 qla2x00_set_model_info(vha, nv->model_number,
4645 sizeof(nv->model_number), "QLA23xx");
4647 } else if (IS_QLA2200(ha)) {
4648 nv->firmware_options[0] |= BIT_2;
4650 * 'Point-to-point preferred, else loop' is not a safe
4651 * connection mode setting.
4653 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4655 /* Force 'loop preferred, else point-to-point'. */
4656 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4657 nv->add_firmware_options[0] |= BIT_5;
4659 strcpy(ha->model_number, "QLA22xx");
4660 } else /*if (IS_QLA2100(ha))*/ {
4661 strcpy(ha->model_number, "QLA2100");
4665 * Copy over NVRAM RISC parameter block to initialization control block.
4667 dptr1 = (uint8_t *)icb;
4668 dptr2 = (uint8_t *)&nv->parameter_block_version;
4669 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4671 *dptr1++ = *dptr2++;
4673 /* Copy 2nd half. */
4674 dptr1 = (uint8_t *)icb->add_firmware_options;
4675 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4677 *dptr1++ = *dptr2++;
4678 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4679 /* Use alternate WWN? */
4680 if (nv->host_p[1] & BIT_7) {
4681 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4682 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4685 /* Prepare nodename */
4686 if ((icb->firmware_options[1] & BIT_6) == 0) {
4688 * Firmware will apply the following mask if the nodename was
4691 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4692 icb->node_name[0] &= 0xF0;
4696 * Set host adapter parameters.
4700 * BIT_7 in the host-parameters section allows for modification to
4701 * internal driver logging.
4703 if (nv->host_p[0] & BIT_7)
4704 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4705 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4706 /* Always load RISC code on non ISP2[12]00 chips. */
4707 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4708 ha->flags.disable_risc_code_load = 0;
4709 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4710 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4711 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4712 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4713 ha->flags.disable_serdes = 0;
4715 ha->operating_mode =
4716 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4718 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4719 sizeof(ha->fw_seriallink_options));
4721 /* save HBA serial number */
4722 ha->serial0 = icb->port_name[5];
4723 ha->serial1 = icb->port_name[6];
4724 ha->serial2 = icb->port_name[7];
4725 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4726 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4728 icb->execution_throttle = cpu_to_le16(0xFFFF);
4730 ha->retry_count = nv->retry_count;
4732 /* Set minimum login_timeout to 4 seconds. */
4733 if (nv->login_timeout != ql2xlogintimeout)
4734 nv->login_timeout = ql2xlogintimeout;
4735 if (nv->login_timeout < 4)
4736 nv->login_timeout = 4;
4737 ha->login_timeout = nv->login_timeout;
4739 /* Set minimum RATOV to 100 tenths of a second. */
4742 ha->loop_reset_delay = nv->reset_delay;
4744 /* Link Down Timeout = 0:
4746 * When Port Down timer expires we will start returning
4747 * I/O's to OS with "DID_NO_CONNECT".
4749 * Link Down Timeout != 0:
4751 * The driver waits for the link to come up after link down
4752 * before returning I/Os to OS with "DID_NO_CONNECT".
4754 if (nv->link_down_timeout == 0) {
4755 ha->loop_down_abort_time =
4756 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4758 ha->link_down_timeout = nv->link_down_timeout;
4759 ha->loop_down_abort_time =
4760 (LOOP_DOWN_TIME - ha->link_down_timeout);
4764 * Need enough time to try and get the port back.
4766 ha->port_down_retry_count = nv->port_down_retry_count;
4767 if (qlport_down_retry)
4768 ha->port_down_retry_count = qlport_down_retry;
4769 /* Set login_retry_count */
4770 ha->login_retry_count = nv->retry_count;
4771 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4772 ha->port_down_retry_count > 3)
4773 ha->login_retry_count = ha->port_down_retry_count;
4774 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4775 ha->login_retry_count = ha->port_down_retry_count;
4776 if (ql2xloginretrycount)
4777 ha->login_retry_count = ql2xloginretrycount;
4779 icb->lun_enables = cpu_to_le16(0);
4780 icb->command_resource_count = 0;
4781 icb->immediate_notify_resource_count = 0;
4782 icb->timeout = cpu_to_le16(0);
4784 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4786 icb->firmware_options[0] &= ~BIT_3;
4787 icb->add_firmware_options[0] &=
4788 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4789 icb->add_firmware_options[0] |= BIT_2;
4790 icb->response_accumulation_timer = 3;
4791 icb->interrupt_delay_timer = 5;
4793 vha->flags.process_response_queue = 1;
4796 if (!vha->flags.init_done) {
4797 ha->zio_mode = icb->add_firmware_options[0] &
4798 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4799 ha->zio_timer = icb->interrupt_delay_timer ?
4800 icb->interrupt_delay_timer : 2;
4802 icb->add_firmware_options[0] &=
4803 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4804 vha->flags.process_response_queue = 0;
4805 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4806 ha->zio_mode = QLA_ZIO_MODE_6;
4808 ql_log(ql_log_info, vha, 0x0068,
4809 "ZIO mode %d enabled; timer delay (%d us).\n",
4810 ha->zio_mode, ha->zio_timer * 100);
4812 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4813 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4814 vha->flags.process_response_queue = 1;
4819 ql_log(ql_log_warn, vha, 0x0069,
4820 "NVRAM configuration failed.\n");
4826 qla2x00_rport_del(void *data)
4828 fc_port_t *fcport = data;
4829 struct fc_rport *rport;
4830 unsigned long flags;
4832 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4833 rport = fcport->drport ? fcport->drport : fcport->rport;
4834 fcport->drport = NULL;
4835 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4837 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4838 "%s %8phN. rport %p roles %x\n",
4839 __func__, fcport->port_name, rport,
4842 fc_remote_port_delete(rport);
4846 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4850 old_state = atomic_read(&fcport->state);
4851 atomic_set(&fcport->state, state);
4853 /* Don't print state transitions during initial allocation of fcport */
4854 if (old_state && old_state != state) {
4855 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4856 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4857 fcport->port_name, port_state_str[old_state],
4858 port_state_str[state], fcport->d_id.b.domain,
4859 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4864 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4866 * @flags: allocation flags
4868 * Returns a pointer to the allocated fcport, or NULL, if none available.
4871 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4875 fcport = kzalloc(sizeof(fc_port_t), flags);
4879 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4880 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4882 if (!fcport->ct_desc.ct_sns) {
4883 ql_log(ql_log_warn, vha, 0xd049,
4884 "Failed to allocate ct_sns request.\n");
4889 /* Setup fcport template structure. */
4891 fcport->port_type = FCT_UNKNOWN;
4892 fcport->loop_id = FC_NO_LOOP_ID;
4893 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4894 fcport->supported_classes = FC_COS_UNSPECIFIED;
4895 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4897 fcport->disc_state = DSC_DELETED;
4898 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4899 fcport->deleted = QLA_SESS_DELETED;
4900 fcport->login_retry = vha->hw->login_retry_count;
4901 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4902 fcport->logout_on_delete = 1;
4904 if (!fcport->ct_desc.ct_sns) {
4905 ql_log(ql_log_warn, vha, 0xd049,
4906 "Failed to allocate ct_sns request.\n");
4911 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4912 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4913 INIT_LIST_HEAD(&fcport->gnl_entry);
4914 INIT_LIST_HEAD(&fcport->list);
4920 qla2x00_free_fcport(fc_port_t *fcport)
4922 if (fcport->ct_desc.ct_sns) {
4923 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4924 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4925 fcport->ct_desc.ct_sns_dma);
4927 fcport->ct_desc.ct_sns = NULL;
4929 list_del(&fcport->list);
4930 qla2x00_clear_loop_id(fcport);
4935 * qla2x00_configure_loop
4936 * Updates Fibre Channel Device Database with what is actually on loop.
4939 * ha = adapter block pointer.
4944 * 2 = database was full and device was not configured.
4947 qla2x00_configure_loop(scsi_qla_host_t *vha)
4950 unsigned long flags, save_flags;
4951 struct qla_hw_data *ha = vha->hw;
4955 /* Get Initiator ID */
4956 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4957 rval = qla2x00_configure_hba(vha);
4958 if (rval != QLA_SUCCESS) {
4959 ql_dbg(ql_dbg_disc, vha, 0x2013,
4960 "Unable to configure HBA.\n");
4965 save_flags = flags = vha->dpc_flags;
4966 ql_dbg(ql_dbg_disc, vha, 0x2014,
4967 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4970 * If we have both an RSCN and PORT UPDATE pending then handle them
4971 * both at the same time.
4973 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4974 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4976 qla2x00_get_data_rate(vha);
4978 /* Determine what we need to do */
4979 if (ha->current_topology == ISP_CFG_FL &&
4980 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4982 set_bit(RSCN_UPDATE, &flags);
4984 } else if (ha->current_topology == ISP_CFG_F &&
4985 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4987 set_bit(RSCN_UPDATE, &flags);
4988 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4990 } else if (ha->current_topology == ISP_CFG_N) {
4991 clear_bit(RSCN_UPDATE, &flags);
4992 if (qla_tgt_mode_enabled(vha)) {
4993 /* allow the other side to start the login */
4994 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4995 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4997 } else if (ha->current_topology == ISP_CFG_NL) {
4998 clear_bit(RSCN_UPDATE, &flags);
4999 set_bit(LOCAL_LOOP_UPDATE, &flags);
5000 } else if (!vha->flags.online ||
5001 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5002 set_bit(RSCN_UPDATE, &flags);
5003 set_bit(LOCAL_LOOP_UPDATE, &flags);
5006 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5007 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5008 ql_dbg(ql_dbg_disc, vha, 0x2015,
5009 "Loop resync needed, failing.\n");
5010 rval = QLA_FUNCTION_FAILED;
5012 rval = qla2x00_configure_local_loop(vha);
5015 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5016 if (LOOP_TRANSITION(vha)) {
5017 ql_dbg(ql_dbg_disc, vha, 0x2099,
5018 "Needs RSCN update and loop transition.\n");
5019 rval = QLA_FUNCTION_FAILED;
5022 rval = qla2x00_configure_fabric(vha);
5025 if (rval == QLA_SUCCESS) {
5026 if (atomic_read(&vha->loop_down_timer) ||
5027 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5028 rval = QLA_FUNCTION_FAILED;
5030 atomic_set(&vha->loop_state, LOOP_READY);
5031 ql_dbg(ql_dbg_disc, vha, 0x2069,
5033 ha->flags.fw_init_done = 1;
5036 * Process any ATIO queue entries that came in
5037 * while we weren't online.
5039 if (qla_tgt_mode_enabled(vha) ||
5040 qla_dual_mode_enabled(vha)) {
5041 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5042 qlt_24xx_process_atio_queue(vha, 0);
5043 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5050 ql_dbg(ql_dbg_disc, vha, 0x206a,
5051 "%s *** FAILED ***.\n", __func__);
5053 ql_dbg(ql_dbg_disc, vha, 0x206b,
5054 "%s: exiting normally.\n", __func__);
5057 /* Restore state if a resync event occurred during processing */
5058 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5059 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5060 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5061 if (test_bit(RSCN_UPDATE, &save_flags)) {
5062 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5070 * qla2x00_configure_local_loop
5071 * Updates Fibre Channel Device Database with local loop devices.
5074 * ha = adapter block pointer.
5080 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5085 fc_port_t *fcport, *new_fcport;
5089 struct gid_list_info *gid;
5091 uint8_t domain, area, al_pa;
5092 struct qla_hw_data *ha = vha->hw;
5093 unsigned long flags;
5095 /* Inititae N2N login. */
5096 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5100 memset(ha->init_cb, 0, ha->init_cb_size);
5101 sz = min_t(int, sizeof(struct els_plogi_payload),
5103 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5104 (void *)ha->init_cb, sz);
5105 if (rval == QLA_SUCCESS) {
5106 bp = (uint32_t *)ha->init_cb;
5107 for (i = 0; i < sz/4 ; i++, bp++)
5108 *bp = cpu_to_be32(*bp);
5110 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
5111 sizeof(ha->plogi_els_payld.data));
5112 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5114 ql_dbg(ql_dbg_init, vha, 0x00d1,
5115 "PLOGI ELS param read fail.\n");
5122 entries = MAX_FIBRE_DEVICES_LOOP;
5124 /* Get list of logged in devices. */
5125 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5126 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5128 if (rval != QLA_SUCCESS)
5129 goto cleanup_allocation;
5131 ql_dbg(ql_dbg_disc, vha, 0x2011,
5132 "Entries in ID list (%d).\n", entries);
5133 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5134 ha->gid_list, entries * sizeof(*ha->gid_list));
5137 spin_lock_irqsave(&vha->work_lock, flags);
5138 vha->scan.scan_retry++;
5139 spin_unlock_irqrestore(&vha->work_lock, flags);
5141 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5142 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5143 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5146 vha->scan.scan_retry = 0;
5149 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5150 fcport->scan_state = QLA_FCPORT_SCAN;
5153 /* Allocate temporary fcport for any new fcports discovered. */
5154 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5155 if (new_fcport == NULL) {
5156 ql_log(ql_log_warn, vha, 0x2012,
5157 "Memory allocation failed for fcport.\n");
5158 rval = QLA_MEMORY_ALLOC_FAILED;
5159 goto cleanup_allocation;
5161 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5163 /* Add devices to port list. */
5165 for (index = 0; index < entries; index++) {
5166 domain = gid->domain;
5169 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5170 loop_id = gid->loop_id_2100;
5172 loop_id = le16_to_cpu(gid->loop_id);
5173 gid = (void *)gid + ha->gid_list_info_size;
5175 /* Bypass reserved domain fields. */
5176 if ((domain & 0xf0) == 0xf0)
5179 /* Bypass if not same domain and area of adapter. */
5180 if (area && domain && ((area != vha->d_id.b.area) ||
5181 (domain != vha->d_id.b.domain)) &&
5182 (ha->current_topology == ISP_CFG_NL))
5186 /* Bypass invalid local loop ID. */
5187 if (loop_id > LAST_LOCAL_LOOP_ID)
5190 memset(new_fcport->port_name, 0, WWN_SIZE);
5192 /* Fill in member data. */
5193 new_fcport->d_id.b.domain = domain;
5194 new_fcport->d_id.b.area = area;
5195 new_fcport->d_id.b.al_pa = al_pa;
5196 new_fcport->loop_id = loop_id;
5197 new_fcport->scan_state = QLA_FCPORT_FOUND;
5199 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5200 if (rval2 != QLA_SUCCESS) {
5201 ql_dbg(ql_dbg_disc, vha, 0x2097,
5202 "Failed to retrieve fcport information "
5203 "-- get_port_database=%x, loop_id=0x%04x.\n",
5204 rval2, new_fcport->loop_id);
5205 /* Skip retry if N2N */
5206 if (ha->current_topology != ISP_CFG_N) {
5207 ql_dbg(ql_dbg_disc, vha, 0x2105,
5208 "Scheduling resync.\n");
5209 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5214 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5215 /* Check for matching device in port list. */
5218 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5219 if (memcmp(new_fcport->port_name, fcport->port_name,
5223 fcport->flags &= ~FCF_FABRIC_DEVICE;
5224 fcport->loop_id = new_fcport->loop_id;
5225 fcport->port_type = new_fcport->port_type;
5226 fcport->d_id.b24 = new_fcport->d_id.b24;
5227 memcpy(fcport->node_name, new_fcport->node_name,
5229 fcport->scan_state = QLA_FCPORT_FOUND;
5235 /* New device, add to fcports list. */
5236 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5238 /* Allocate a new replacement fcport. */
5239 fcport = new_fcport;
5241 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5243 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5245 if (new_fcport == NULL) {
5246 ql_log(ql_log_warn, vha, 0xd031,
5247 "Failed to allocate memory for fcport.\n");
5248 rval = QLA_MEMORY_ALLOC_FAILED;
5249 goto cleanup_allocation;
5251 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5252 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5255 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5257 /* Base iIDMA settings on HBA port speed. */
5258 fcport->fp_speed = ha->link_data_rate;
5263 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5264 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5267 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5268 if ((qla_dual_mode_enabled(vha) ||
5269 qla_ini_mode_enabled(vha)) &&
5270 atomic_read(&fcport->state) == FCS_ONLINE) {
5271 qla2x00_mark_device_lost(vha, fcport,
5272 ql2xplogiabsentdevice, 0);
5273 if (fcport->loop_id != FC_NO_LOOP_ID &&
5274 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5275 fcport->port_type != FCT_INITIATOR &&
5276 fcport->port_type != FCT_BROADCAST) {
5277 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5278 "%s %d %8phC post del sess\n",
5282 qlt_schedule_sess_for_deletion(fcport);
5288 if (fcport->scan_state == QLA_FCPORT_FOUND)
5289 qla24xx_fcport_handle_login(vha, fcport);
5295 if (rval != QLA_SUCCESS) {
5296 ql_dbg(ql_dbg_disc, vha, 0x2098,
5297 "Configure local loop error exit: rval=%x.\n", rval);
5304 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5307 uint16_t mb[MAILBOX_REGISTER_COUNT];
5308 struct qla_hw_data *ha = vha->hw;
5310 if (!IS_IIDMA_CAPABLE(ha))
5313 if (atomic_read(&fcport->state) != FCS_ONLINE)
5316 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5317 fcport->fp_speed > ha->link_data_rate ||
5318 !ha->flags.gpsc_supported)
5321 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5323 if (rval != QLA_SUCCESS) {
5324 ql_dbg(ql_dbg_disc, vha, 0x2004,
5325 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5326 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5328 ql_dbg(ql_dbg_disc, vha, 0x2005,
5329 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5330 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5331 fcport->fp_speed, fcport->port_name);
5335 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5337 qla2x00_iidma_fcport(vha, fcport);
5338 qla24xx_update_fcport_fcp_prio(vha, fcport);
5341 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5343 struct qla_work_evt *e;
5345 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5347 return QLA_FUNCTION_FAILED;
5349 e->u.fcport.fcport = fcport;
5350 return qla2x00_post_work(vha, e);
5353 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5355 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5357 struct fc_rport_identifiers rport_ids;
5358 struct fc_rport *rport;
5359 unsigned long flags;
5361 if (atomic_read(&fcport->state) == FCS_ONLINE)
5364 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5365 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5366 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5367 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5368 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5369 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5371 ql_log(ql_log_warn, vha, 0x2006,
5372 "Unable to allocate fc remote port.\n");
5376 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5377 *((fc_port_t **)rport->dd_data) = fcport;
5378 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5380 rport->supported_classes = fcport->supported_classes;
5382 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5383 if (fcport->port_type == FCT_INITIATOR)
5384 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5385 if (fcport->port_type == FCT_TARGET)
5386 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5387 if (fcport->port_type & FCT_NVME_INITIATOR)
5388 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5389 if (fcport->port_type & FCT_NVME_TARGET)
5390 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5391 if (fcport->port_type & FCT_NVME_DISCOVERY)
5392 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5394 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5395 "%s %8phN. rport %p is %s mode\n",
5396 __func__, fcport->port_name, rport,
5397 (fcport->port_type == FCT_TARGET) ? "tgt" :
5398 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5400 fc_remote_port_rolechg(rport, rport_ids.roles);
5404 * qla2x00_update_fcport
5405 * Updates device on list.
5408 * ha = adapter block pointer.
5409 * fcport = port structure pointer.
5419 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5421 if (IS_SW_RESV_ADDR(fcport->d_id))
5424 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5425 __func__, fcport->port_name);
5427 fcport->disc_state = DSC_UPD_FCPORT;
5428 fcport->login_retry = vha->hw->login_retry_count;
5429 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5430 fcport->deleted = 0;
5431 fcport->logout_on_delete = 1;
5432 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5434 switch (vha->hw->current_topology) {
5437 fcport->keep_nport_handle = 1;
5443 qla2x00_iidma_fcport(vha, fcport);
5445 if (fcport->fc4f_nvme) {
5446 qla_nvme_register_remote(vha, fcport);
5447 fcport->disc_state = DSC_LOGIN_COMPLETE;
5448 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5452 qla24xx_update_fcport_fcp_prio(vha, fcport);
5454 switch (vha->host->active_mode) {
5455 case MODE_INITIATOR:
5456 qla2x00_reg_remote_port(vha, fcport);
5459 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5460 !vha->vha_tgt.qla_tgt->tgt_stopped)
5461 qlt_fc_port_added(vha, fcport);
5464 qla2x00_reg_remote_port(vha, fcport);
5465 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5466 !vha->vha_tgt.qla_tgt->tgt_stopped)
5467 qlt_fc_port_added(vha, fcport);
5473 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5475 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5476 if (fcport->id_changed) {
5477 fcport->id_changed = 0;
5478 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5479 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5480 __func__, __LINE__, fcport->port_name,
5482 qla24xx_post_gfpnid_work(vha, fcport);
5484 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5485 "%s %d %8phC post gpsc fcp_cnt %d\n",
5486 __func__, __LINE__, fcport->port_name,
5488 qla24xx_post_gpsc_work(vha, fcport);
5492 fcport->disc_state = DSC_LOGIN_COMPLETE;
5495 void qla_register_fcport_fn(struct work_struct *work)
5497 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5498 u32 rscn_gen = fcport->rscn_gen;
5501 if (IS_SW_RESV_ADDR(fcport->d_id))
5504 qla2x00_update_fcport(fcport->vha, fcport);
5506 if (rscn_gen != fcport->rscn_gen) {
5507 /* RSCN(s) came in while registration */
5508 switch (fcport->next_disc_state) {
5509 case DSC_DELETE_PEND:
5510 qlt_schedule_sess_for_deletion(fcport);
5513 data[0] = data[1] = 0;
5514 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5524 * qla2x00_configure_fabric
5525 * Setup SNS devices with loop ID's.
5528 * ha = adapter block pointer.
5535 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5539 uint16_t mb[MAILBOX_REGISTER_COUNT];
5541 LIST_HEAD(new_fcports);
5542 struct qla_hw_data *ha = vha->hw;
5545 /* If FL port exists, then SNS is present */
5546 if (IS_FWI2_CAPABLE(ha))
5547 loop_id = NPH_F_PORT;
5549 loop_id = SNS_FL_PORT;
5550 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5551 if (rval != QLA_SUCCESS) {
5552 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5553 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5555 vha->device_flags &= ~SWITCH_FOUND;
5556 return (QLA_SUCCESS);
5558 vha->device_flags |= SWITCH_FOUND;
5561 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5562 rval = qla2x00_send_change_request(vha, 0x3, 0);
5563 if (rval != QLA_SUCCESS)
5564 ql_log(ql_log_warn, vha, 0x121,
5565 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5571 qla2x00_mgmt_svr_login(vha);
5574 if (ql2xfdmienable &&
5575 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5576 qla2x00_fdmi_register(vha);
5578 /* Ensure we are logged into the SNS. */
5579 loop_id = NPH_SNS_LID(ha);
5580 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5581 0xfc, mb, BIT_1|BIT_0);
5582 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5583 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5584 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5585 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5586 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5589 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5590 if (qla2x00_rft_id(vha)) {
5592 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5593 "Register FC-4 TYPE failed.\n");
5594 if (test_bit(LOOP_RESYNC_NEEDED,
5598 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5600 ql_dbg(ql_dbg_disc, vha, 0x209a,
5601 "Register FC-4 Features failed.\n");
5602 if (test_bit(LOOP_RESYNC_NEEDED,
5606 if (vha->flags.nvme_enabled) {
5607 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5608 ql_dbg(ql_dbg_disc, vha, 0x2049,
5609 "Register NVME FC Type Features failed.\n");
5612 if (qla2x00_rnn_id(vha)) {
5614 ql_dbg(ql_dbg_disc, vha, 0x2104,
5615 "Register Node Name failed.\n");
5616 if (test_bit(LOOP_RESYNC_NEEDED,
5619 } else if (qla2x00_rsnn_nn(vha)) {
5621 ql_dbg(ql_dbg_disc, vha, 0x209b,
5622 "Register Symbolic Node Name failed.\n");
5623 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5629 /* Mark the time right before querying FW for connected ports.
5630 * This process is long, asynchronous and by the time it's done,
5631 * collected information might not be accurate anymore. E.g.
5632 * disconnected port might have re-connected and a brand new
5633 * session has been created. In this case session's generation
5634 * will be newer than discovery_gen. */
5635 qlt_do_generation_tick(vha, &discovery_gen);
5637 if (USE_ASYNC_SCAN(ha)) {
5638 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5641 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5643 list_for_each_entry(fcport, &vha->vp_fcports, list)
5644 fcport->scan_state = QLA_FCPORT_SCAN;
5646 rval = qla2x00_find_all_fabric_devs(vha);
5648 if (rval != QLA_SUCCESS)
5652 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5653 qla_nvme_register_hba(vha);
5656 ql_dbg(ql_dbg_disc, vha, 0x2068,
5657 "Configure fabric error exit rval=%d.\n", rval);
5663 * qla2x00_find_all_fabric_devs
5666 * ha = adapter block pointer.
5667 * dev = database device entry pointer.
5676 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5680 fc_port_t *fcport, *new_fcport;
5685 int first_dev, last_dev;
5686 port_id_t wrap = {}, nxt_d_id;
5687 struct qla_hw_data *ha = vha->hw;
5688 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5689 unsigned long flags;
5693 /* Try GID_PT to get device list, else GAN. */
5695 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5700 ql_dbg(ql_dbg_disc, vha, 0x209c,
5701 "GID_PT allocations failed, fallback on GA_NXT.\n");
5703 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5704 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5706 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5708 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5710 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5712 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5714 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5716 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5718 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5722 /* If other queries succeeded probe for FC-4 type */
5724 qla2x00_gff_id(vha, swl);
5725 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5731 /* Allocate temporary fcport for any new fcports discovered. */
5732 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5733 if (new_fcport == NULL) {
5734 ql_log(ql_log_warn, vha, 0x209d,
5735 "Failed to allocate memory for fcport.\n");
5736 return (QLA_MEMORY_ALLOC_FAILED);
5738 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5739 /* Set start port ID scan at adapter ID. */
5743 /* Starting free loop ID. */
5744 loop_id = ha->min_external_loopid;
5745 for (; loop_id <= ha->max_loop_id; loop_id++) {
5746 if (qla2x00_is_reserved_id(vha, loop_id))
5749 if (ha->current_topology == ISP_CFG_FL &&
5750 (atomic_read(&vha->loop_down_timer) ||
5751 LOOP_TRANSITION(vha))) {
5752 atomic_set(&vha->loop_down_timer, 0);
5753 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5754 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5760 wrap.b24 = new_fcport->d_id.b24;
5762 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5763 memcpy(new_fcport->node_name,
5764 swl[swl_idx].node_name, WWN_SIZE);
5765 memcpy(new_fcport->port_name,
5766 swl[swl_idx].port_name, WWN_SIZE);
5767 memcpy(new_fcport->fabric_port_name,
5768 swl[swl_idx].fabric_port_name, WWN_SIZE);
5769 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5770 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5772 new_fcport->nvme_flag = 0;
5773 new_fcport->fc4f_nvme = 0;
5774 if (vha->flags.nvme_enabled &&
5775 swl[swl_idx].fc4f_nvme) {
5776 new_fcport->fc4f_nvme =
5777 swl[swl_idx].fc4f_nvme;
5778 ql_log(ql_log_info, vha, 0x2131,
5779 "FOUND: NVME port %8phC as FC Type 28h\n",
5780 new_fcport->port_name);
5783 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5789 /* Send GA_NXT to the switch */
5790 rval = qla2x00_ga_nxt(vha, new_fcport);
5791 if (rval != QLA_SUCCESS) {
5792 ql_log(ql_log_warn, vha, 0x209e,
5793 "SNS scan failed -- assuming "
5794 "zero-entry result.\n");
5800 /* If wrap on switch device list, exit. */
5802 wrap.b24 = new_fcport->d_id.b24;
5804 } else if (new_fcport->d_id.b24 == wrap.b24) {
5805 ql_dbg(ql_dbg_disc, vha, 0x209f,
5806 "Device wrap (%02x%02x%02x).\n",
5807 new_fcport->d_id.b.domain,
5808 new_fcport->d_id.b.area,
5809 new_fcport->d_id.b.al_pa);
5813 /* Bypass if same physical adapter. */
5814 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5817 /* Bypass virtual ports of the same host. */
5818 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5821 /* Bypass if same domain and area of adapter. */
5822 if (((new_fcport->d_id.b24 & 0xffff00) ==
5823 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5827 /* Bypass reserved domain fields. */
5828 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5831 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5832 if (ql2xgffidenable &&
5833 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5834 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5837 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5839 /* Locate matching device in database. */
5841 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5842 if (memcmp(new_fcport->port_name, fcport->port_name,
5846 fcport->scan_state = QLA_FCPORT_FOUND;
5850 /* Update port state. */
5851 memcpy(fcport->fabric_port_name,
5852 new_fcport->fabric_port_name, WWN_SIZE);
5853 fcport->fp_speed = new_fcport->fp_speed;
5856 * If address the same and state FCS_ONLINE
5857 * (or in target mode), nothing changed.
5859 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5860 (atomic_read(&fcport->state) == FCS_ONLINE ||
5861 (vha->host->active_mode == MODE_TARGET))) {
5866 * If device was not a fabric device before.
5868 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5869 fcport->d_id.b24 = new_fcport->d_id.b24;
5870 qla2x00_clear_loop_id(fcport);
5871 fcport->flags |= (FCF_FABRIC_DEVICE |
5877 * Port ID changed or device was marked to be updated;
5878 * Log it out if still logged in and mark it for
5881 if (qla_tgt_mode_enabled(base_vha)) {
5882 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5883 "port changed FC ID, %8phC"
5884 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5886 fcport->d_id.b.domain,
5887 fcport->d_id.b.area,
5888 fcport->d_id.b.al_pa,
5890 new_fcport->d_id.b.domain,
5891 new_fcport->d_id.b.area,
5892 new_fcport->d_id.b.al_pa);
5893 fcport->d_id.b24 = new_fcport->d_id.b24;
5897 fcport->d_id.b24 = new_fcport->d_id.b24;
5898 fcport->flags |= FCF_LOGIN_NEEDED;
5902 if (fcport->fc4f_nvme) {
5903 if (fcport->disc_state == DSC_DELETE_PEND) {
5904 fcport->disc_state = DSC_GNL;
5905 vha->fcport_count--;
5906 fcport->login_succ = 0;
5911 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5914 /* If device was not in our fcports list, then add it. */
5915 new_fcport->scan_state = QLA_FCPORT_FOUND;
5916 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5918 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5921 /* Allocate a new replacement fcport. */
5922 nxt_d_id.b24 = new_fcport->d_id.b24;
5923 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5924 if (new_fcport == NULL) {
5925 ql_log(ql_log_warn, vha, 0xd032,
5926 "Memory allocation failed for fcport.\n");
5927 return (QLA_MEMORY_ALLOC_FAILED);
5929 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5930 new_fcport->d_id.b24 = nxt_d_id.b24;
5933 qla2x00_free_fcport(new_fcport);
5936 * Logout all previous fabric dev marked lost, except FCP2 devices.
5938 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5939 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5942 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5943 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5946 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5947 if ((qla_dual_mode_enabled(vha) ||
5948 qla_ini_mode_enabled(vha)) &&
5949 atomic_read(&fcport->state) == FCS_ONLINE) {
5950 qla2x00_mark_device_lost(vha, fcport,
5951 ql2xplogiabsentdevice, 0);
5952 if (fcport->loop_id != FC_NO_LOOP_ID &&
5953 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5954 fcport->port_type != FCT_INITIATOR &&
5955 fcport->port_type != FCT_BROADCAST) {
5956 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5957 "%s %d %8phC post del sess\n",
5960 qlt_schedule_sess_for_deletion(fcport);
5966 if (fcport->scan_state == QLA_FCPORT_FOUND)
5967 qla24xx_fcport_handle_login(vha, fcport);
5972 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5974 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5976 int loop_id = FC_NO_LOOP_ID;
5977 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5978 unsigned long flags;
5979 struct qla_hw_data *ha = vha->hw;
5981 if (vha->vp_idx == 0) {
5982 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5983 return NPH_MGMT_SERVER;
5986 /* pick id from high and work down to low */
5987 spin_lock_irqsave(&ha->vport_slock, flags);
5988 for (; lid > 0; lid--) {
5989 if (!test_bit(lid, vha->hw->loop_id_map)) {
5990 set_bit(lid, vha->hw->loop_id_map);
5995 spin_unlock_irqrestore(&ha->vport_slock, flags);
6001 * qla2x00_fabric_login
6002 * Issue fabric login command.
6005 * ha = adapter block pointer.
6006 * device = pointer to FC device type structure.
6009 * 0 - Login successfully
6011 * 2 - Initiator device
6015 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6016 uint16_t *next_loopid)
6020 uint16_t tmp_loopid;
6021 uint16_t mb[MAILBOX_REGISTER_COUNT];
6022 struct qla_hw_data *ha = vha->hw;
6028 ql_dbg(ql_dbg_disc, vha, 0x2000,
6029 "Trying Fabric Login w/loop id 0x%04x for port "
6031 fcport->loop_id, fcport->d_id.b.domain,
6032 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6034 /* Login fcport on switch. */
6035 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6036 fcport->d_id.b.domain, fcport->d_id.b.area,
6037 fcport->d_id.b.al_pa, mb, BIT_0);
6038 if (rval != QLA_SUCCESS) {
6041 if (mb[0] == MBS_PORT_ID_USED) {
6043 * Device has another loop ID. The firmware team
6044 * recommends the driver perform an implicit login with
6045 * the specified ID again. The ID we just used is save
6046 * here so we return with an ID that can be tried by
6050 tmp_loopid = fcport->loop_id;
6051 fcport->loop_id = mb[1];
6053 ql_dbg(ql_dbg_disc, vha, 0x2001,
6054 "Fabric Login: port in use - next loop "
6055 "id=0x%04x, port id= %02x%02x%02x.\n",
6056 fcport->loop_id, fcport->d_id.b.domain,
6057 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6059 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6064 /* A retry occurred before. */
6065 *next_loopid = tmp_loopid;
6068 * No retry occurred before. Just increment the
6069 * ID value for next login.
6071 *next_loopid = (fcport->loop_id + 1);
6074 if (mb[1] & BIT_0) {
6075 fcport->port_type = FCT_INITIATOR;
6077 fcport->port_type = FCT_TARGET;
6078 if (mb[1] & BIT_1) {
6079 fcport->flags |= FCF_FCP2_DEVICE;
6084 fcport->supported_classes |= FC_COS_CLASS2;
6086 fcport->supported_classes |= FC_COS_CLASS3;
6088 if (IS_FWI2_CAPABLE(ha)) {
6091 FCF_CONF_COMP_SUPPORTED;
6096 } else if (mb[0] == MBS_LOOP_ID_USED) {
6098 * Loop ID already used, try next loop ID.
6101 rval = qla2x00_find_new_loop_id(vha, fcport);
6102 if (rval != QLA_SUCCESS) {
6103 /* Ran out of loop IDs to use */
6106 } else if (mb[0] == MBS_COMMAND_ERROR) {
6108 * Firmware possibly timed out during login. If NO
6109 * retries are left to do then the device is declared
6112 *next_loopid = fcport->loop_id;
6113 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6114 fcport->d_id.b.domain, fcport->d_id.b.area,
6115 fcport->d_id.b.al_pa);
6116 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6122 * unrecoverable / not handled error
6124 ql_dbg(ql_dbg_disc, vha, 0x2002,
6125 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6126 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6127 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6128 fcport->loop_id, jiffies);
6130 *next_loopid = fcport->loop_id;
6131 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6132 fcport->d_id.b.domain, fcport->d_id.b.area,
6133 fcport->d_id.b.al_pa);
6134 qla2x00_clear_loop_id(fcport);
6135 fcport->login_retry = 0;
6146 * qla2x00_local_device_login
6147 * Issue local device login command.
6150 * ha = adapter block pointer.
6151 * loop_id = loop id of device to login to.
6153 * Returns (Where's the #define!!!!):
6154 * 0 - Login successfully
6159 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6162 uint16_t mb[MAILBOX_REGISTER_COUNT];
6164 memset(mb, 0, sizeof(mb));
6165 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6166 if (rval == QLA_SUCCESS) {
6167 /* Interrogate mailbox registers for any errors */
6168 if (mb[0] == MBS_COMMAND_ERROR)
6170 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6171 /* device not in PCB table */
6179 * qla2x00_loop_resync
6180 * Resync with fibre channel devices.
6183 * ha = adapter block pointer.
6189 qla2x00_loop_resync(scsi_qla_host_t *vha)
6191 int rval = QLA_SUCCESS;
6194 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6195 if (vha->flags.online) {
6196 if (!(rval = qla2x00_fw_ready(vha))) {
6197 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6200 if (!IS_QLAFX00(vha->hw)) {
6202 * Issue a marker after FW becomes
6205 qla2x00_marker(vha, vha->hw->base_qpair,
6207 vha->marker_needed = 0;
6210 /* Remap devices on Loop. */
6211 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6213 if (IS_QLAFX00(vha->hw))
6214 qlafx00_configure_devices(vha);
6216 qla2x00_configure_loop(vha);
6219 } while (!atomic_read(&vha->loop_down_timer) &&
6220 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6221 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6226 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6227 return (QLA_FUNCTION_FAILED);
6230 ql_dbg(ql_dbg_disc, vha, 0x206c,
6231 "%s *** FAILED ***.\n", __func__);
6237 * qla2x00_perform_loop_resync
6238 * Description: This function will set the appropriate flags and call
6239 * qla2x00_loop_resync. If successful loop will be resynced
6240 * Arguments : scsi_qla_host_t pointer
6241 * returm : Success or Failure
6244 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6248 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6249 /*Configure the flags so that resync happens properly*/
6250 atomic_set(&ha->loop_down_timer, 0);
6251 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6252 atomic_set(&ha->loop_state, LOOP_UP);
6253 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6254 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6255 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6257 rval = qla2x00_loop_resync(ha);
6259 atomic_set(&ha->loop_state, LOOP_DEAD);
6261 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6268 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6271 struct scsi_qla_host *vha;
6272 struct qla_hw_data *ha = base_vha->hw;
6273 unsigned long flags;
6275 spin_lock_irqsave(&ha->vport_slock, flags);
6276 /* Go with deferred removal of rport references. */
6277 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6278 atomic_inc(&vha->vref_count);
6279 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6280 if (fcport->drport &&
6281 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6282 spin_unlock_irqrestore(&ha->vport_slock, flags);
6283 qla2x00_rport_del(fcport);
6285 spin_lock_irqsave(&ha->vport_slock, flags);
6288 atomic_dec(&vha->vref_count);
6289 wake_up(&vha->vref_waitq);
6291 spin_unlock_irqrestore(&ha->vport_slock, flags);
6294 /* Assumes idc_lock always held on entry */
6296 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6298 struct qla_hw_data *ha = vha->hw;
6299 uint32_t drv_presence, drv_presence_mask;
6300 uint32_t dev_part_info1, dev_part_info2, class_type;
6301 uint32_t class_type_mask = 0x3;
6302 uint16_t fcoe_other_function = 0xffff, i;
6304 if (IS_QLA8044(ha)) {
6305 drv_presence = qla8044_rd_direct(vha,
6306 QLA8044_CRB_DRV_ACTIVE_INDEX);
6307 dev_part_info1 = qla8044_rd_direct(vha,
6308 QLA8044_CRB_DEV_PART_INFO_INDEX);
6309 dev_part_info2 = qla8044_rd_direct(vha,
6310 QLA8044_CRB_DEV_PART_INFO2);
6312 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6313 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6314 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6316 for (i = 0; i < 8; i++) {
6317 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6318 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6319 (i != ha->portnum)) {
6320 fcoe_other_function = i;
6324 if (fcoe_other_function == 0xffff) {
6325 for (i = 0; i < 8; i++) {
6326 class_type = ((dev_part_info2 >> (i * 4)) &
6328 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6329 ((i + 8) != ha->portnum)) {
6330 fcoe_other_function = i + 8;
6336 * Prepare drv-presence mask based on fcoe functions present.
6337 * However consider only valid physical fcoe function numbers (0-15).
6339 drv_presence_mask = ~((1 << (ha->portnum)) |
6340 ((fcoe_other_function == 0xffff) ?
6341 0 : (1 << (fcoe_other_function))));
6343 /* We are the reset owner iff:
6344 * - No other protocol drivers present.
6345 * - This is the lowest among fcoe functions. */
6346 if (!(drv_presence & drv_presence_mask) &&
6347 (ha->portnum < fcoe_other_function)) {
6348 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6349 "This host is Reset owner.\n");
6350 ha->flags.nic_core_reset_owner = 1;
6355 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6357 int rval = QLA_SUCCESS;
6358 struct qla_hw_data *ha = vha->hw;
6361 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6362 if (rval == QLA_SUCCESS) {
6363 drv_ack |= (1 << ha->portnum);
6364 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6371 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6373 int rval = QLA_SUCCESS;
6374 struct qla_hw_data *ha = vha->hw;
6377 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6378 if (rval == QLA_SUCCESS) {
6379 drv_ack &= ~(1 << ha->portnum);
6380 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6387 qla83xx_dev_state_to_string(uint32_t dev_state)
6389 switch (dev_state) {
6390 case QLA8XXX_DEV_COLD:
6391 return "COLD/RE-INIT";
6392 case QLA8XXX_DEV_INITIALIZING:
6393 return "INITIALIZING";
6394 case QLA8XXX_DEV_READY:
6396 case QLA8XXX_DEV_NEED_RESET:
6397 return "NEED RESET";
6398 case QLA8XXX_DEV_NEED_QUIESCENT:
6399 return "NEED QUIESCENT";
6400 case QLA8XXX_DEV_FAILED:
6402 case QLA8XXX_DEV_QUIESCENT:
6409 /* Assumes idc-lock always held on entry */
6411 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6413 struct qla_hw_data *ha = vha->hw;
6414 uint32_t idc_audit_reg = 0, duration_secs = 0;
6416 switch (audit_type) {
6417 case IDC_AUDIT_TIMESTAMP:
6418 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6419 idc_audit_reg = (ha->portnum) |
6420 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6421 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6424 case IDC_AUDIT_COMPLETION:
6425 duration_secs = ((jiffies_to_msecs(jiffies) -
6426 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6427 idc_audit_reg = (ha->portnum) |
6428 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6429 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6433 ql_log(ql_log_warn, vha, 0xb078,
6434 "Invalid audit type specified.\n");
6439 /* Assumes idc_lock always held on entry */
6441 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6443 struct qla_hw_data *ha = vha->hw;
6444 uint32_t idc_control, dev_state;
6446 __qla83xx_get_idc_control(vha, &idc_control);
6447 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6448 ql_log(ql_log_info, vha, 0xb080,
6449 "NIC Core reset has been disabled. idc-control=0x%x\n",
6451 return QLA_FUNCTION_FAILED;
6454 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6455 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6456 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6457 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6458 QLA8XXX_DEV_NEED_RESET);
6459 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6460 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6462 const char *state = qla83xx_dev_state_to_string(dev_state);
6464 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6466 /* SV: XXX: Is timeout required here? */
6467 /* Wait for IDC state change READY -> NEED_RESET */
6468 while (dev_state == QLA8XXX_DEV_READY) {
6469 qla83xx_idc_unlock(vha, 0);
6471 qla83xx_idc_lock(vha, 0);
6472 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6476 /* Send IDC ack by writing to drv-ack register */
6477 __qla83xx_set_drv_ack(vha);
6483 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6485 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6489 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6491 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6495 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6497 uint32_t drv_presence = 0;
6498 struct qla_hw_data *ha = vha->hw;
6500 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6501 if (drv_presence & (1 << ha->portnum))
6504 return QLA_TEST_FAILED;
6508 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6510 int rval = QLA_SUCCESS;
6511 struct qla_hw_data *ha = vha->hw;
6513 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6514 "Entered %s().\n", __func__);
6516 if (vha->device_flags & DFLG_DEV_FAILED) {
6517 ql_log(ql_log_warn, vha, 0xb059,
6518 "Device in unrecoverable FAILED state.\n");
6519 return QLA_FUNCTION_FAILED;
6522 qla83xx_idc_lock(vha, 0);
6524 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6525 ql_log(ql_log_warn, vha, 0xb05a,
6526 "Function=0x%x has been removed from IDC participation.\n",
6528 rval = QLA_FUNCTION_FAILED;
6532 qla83xx_reset_ownership(vha);
6534 rval = qla83xx_initiating_reset(vha);
6537 * Perform reset if we are the reset-owner,
6538 * else wait till IDC state changes to READY/FAILED.
6540 if (rval == QLA_SUCCESS) {
6541 rval = qla83xx_idc_state_handler(vha);
6543 if (rval == QLA_SUCCESS)
6544 ha->flags.nic_core_hung = 0;
6545 __qla83xx_clear_drv_ack(vha);
6549 qla83xx_idc_unlock(vha, 0);
6551 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6557 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6559 struct qla_hw_data *ha = vha->hw;
6560 int rval = QLA_FUNCTION_FAILED;
6562 if (!IS_MCTP_CAPABLE(ha)) {
6563 /* This message can be removed from the final version */
6564 ql_log(ql_log_info, vha, 0x506d,
6565 "This board is not MCTP capable\n");
6569 if (!ha->mctp_dump) {
6570 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6571 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6573 if (!ha->mctp_dump) {
6574 ql_log(ql_log_warn, vha, 0x506e,
6575 "Failed to allocate memory for mctp dump\n");
6580 #define MCTP_DUMP_STR_ADDR 0x00000000
6581 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6582 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6583 if (rval != QLA_SUCCESS) {
6584 ql_log(ql_log_warn, vha, 0x506f,
6585 "Failed to capture mctp dump\n");
6587 ql_log(ql_log_info, vha, 0x5070,
6588 "Mctp dump capture for host (%ld/%p).\n",
6589 vha->host_no, ha->mctp_dump);
6590 ha->mctp_dumped = 1;
6593 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6594 ha->flags.nic_core_reset_hdlr_active = 1;
6595 rval = qla83xx_restart_nic_firmware(vha);
6597 /* NIC Core reset failed. */
6598 ql_log(ql_log_warn, vha, 0x5071,
6599 "Failed to restart nic firmware\n");
6601 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6602 "Restarted NIC firmware successfully.\n");
6603 ha->flags.nic_core_reset_hdlr_active = 0;
6611 * qla2x00_quiesce_io
6612 * Description: This function will block the new I/Os
6613 * Its not aborting any I/Os as context
6614 * is not destroyed during quiescence
6615 * Arguments: scsi_qla_host_t
6619 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6621 struct qla_hw_data *ha = vha->hw;
6622 struct scsi_qla_host *vp;
6624 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6625 "Quiescing I/O - ha=%p.\n", ha);
6627 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6628 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6629 atomic_set(&vha->loop_state, LOOP_DOWN);
6630 qla2x00_mark_all_devices_lost(vha, 0);
6631 list_for_each_entry(vp, &ha->vp_list, list)
6632 qla2x00_mark_all_devices_lost(vp, 0);
6634 if (!atomic_read(&vha->loop_down_timer))
6635 atomic_set(&vha->loop_down_timer,
6638 /* Wait for pending cmds to complete */
6639 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6644 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6646 struct qla_hw_data *ha = vha->hw;
6647 struct scsi_qla_host *vp;
6648 unsigned long flags;
6652 /* For ISP82XX, driver waits for completion of the commands.
6653 * online flag should be set.
6655 if (!(IS_P3P_TYPE(ha)))
6656 vha->flags.online = 0;
6657 ha->flags.chip_reset_done = 0;
6658 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6659 vha->qla_stats.total_isp_aborts++;
6661 ql_log(ql_log_info, vha, 0x00af,
6662 "Performing ISP error recovery - ha=%p.\n", ha);
6664 ha->flags.purge_mbox = 1;
6665 /* For ISP82XX, reset_chip is just disabling interrupts.
6666 * Driver waits for the completion of the commands.
6667 * the interrupts need to be enabled.
6669 if (!(IS_P3P_TYPE(ha)))
6670 ha->isp_ops->reset_chip(vha);
6672 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6674 ha->flags.rida_fmt2 = 0;
6675 ha->flags.n2n_ae = 0;
6676 ha->flags.lip_ae = 0;
6677 ha->current_topology = 0;
6678 ha->flags.fw_started = 0;
6679 ha->flags.fw_init_done = 0;
6681 ha->base_qpair->chip_reset = ha->chip_reset;
6682 for (i = 0; i < ha->max_qpairs; i++) {
6683 if (ha->queue_pair_map[i])
6684 ha->queue_pair_map[i]->chip_reset =
6685 ha->base_qpair->chip_reset;
6688 /* purge MBox commands */
6689 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6690 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6691 complete(&ha->mbx_intr_comp);
6695 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6696 atomic_read(&ha->num_pend_mbx_stage2) ||
6697 atomic_read(&ha->num_pend_mbx_stage1)) {
6703 ha->flags.purge_mbox = 0;
6705 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6706 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6707 atomic_set(&vha->loop_state, LOOP_DOWN);
6708 qla2x00_mark_all_devices_lost(vha, 0);
6710 spin_lock_irqsave(&ha->vport_slock, flags);
6711 list_for_each_entry(vp, &ha->vp_list, list) {
6712 atomic_inc(&vp->vref_count);
6713 spin_unlock_irqrestore(&ha->vport_slock, flags);
6715 qla2x00_mark_all_devices_lost(vp, 0);
6717 spin_lock_irqsave(&ha->vport_slock, flags);
6718 atomic_dec(&vp->vref_count);
6720 spin_unlock_irqrestore(&ha->vport_slock, flags);
6722 if (!atomic_read(&vha->loop_down_timer))
6723 atomic_set(&vha->loop_down_timer,
6727 /* Clear all async request states across all VPs. */
6728 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6729 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6730 fcport->scan_state = 0;
6732 spin_lock_irqsave(&ha->vport_slock, flags);
6733 list_for_each_entry(vp, &ha->vp_list, list) {
6734 atomic_inc(&vp->vref_count);
6735 spin_unlock_irqrestore(&ha->vport_slock, flags);
6737 list_for_each_entry(fcport, &vp->vp_fcports, list)
6738 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6740 spin_lock_irqsave(&ha->vport_slock, flags);
6741 atomic_dec(&vp->vref_count);
6743 spin_unlock_irqrestore(&ha->vport_slock, flags);
6745 if (!ha->flags.eeh_busy) {
6746 /* Make sure for ISP 82XX IO DMA is complete */
6747 if (IS_P3P_TYPE(ha)) {
6748 qla82xx_chip_reset_cleanup(vha);
6749 ql_log(ql_log_info, vha, 0x00b4,
6750 "Done chip reset cleanup.\n");
6752 /* Done waiting for pending commands.
6753 * Reset the online flag.
6755 vha->flags.online = 0;
6758 /* Requeue all commands in outstanding command list. */
6759 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6761 /* memory barrier */
6767 * Resets ISP and aborts all outstanding commands.
6770 * ha = adapter block pointer.
6776 qla2x00_abort_isp(scsi_qla_host_t *vha)
6780 struct qla_hw_data *ha = vha->hw;
6781 struct scsi_qla_host *vp;
6782 struct req_que *req = ha->req_q_map[0];
6783 unsigned long flags;
6785 if (vha->flags.online) {
6786 qla2x00_abort_isp_cleanup(vha);
6788 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6789 ha->flags.chip_reset_done = 1;
6790 vha->flags.online = 1;
6792 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6796 if (IS_QLA8031(ha)) {
6797 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6798 "Clearing fcoe driver presence.\n");
6799 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6800 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6801 "Error while clearing DRV-Presence.\n");
6804 if (unlikely(pci_channel_offline(ha->pdev) &&
6805 ha->flags.pci_channel_io_perm_failure)) {
6806 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6811 switch (vha->qlini_mode) {
6812 case QLA2XXX_INI_MODE_DISABLED:
6813 if (!qla_tgt_mode_enabled(vha))
6816 case QLA2XXX_INI_MODE_DUAL:
6817 if (!qla_dual_mode_enabled(vha))
6820 case QLA2XXX_INI_MODE_ENABLED:
6825 ha->isp_ops->get_flash_version(vha, req->ring);
6827 ha->isp_ops->nvram_config(vha);
6829 if (!qla2x00_restart_isp(vha)) {
6830 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6832 if (!atomic_read(&vha->loop_down_timer)) {
6834 * Issue marker command only when we are going
6835 * to start the I/O .
6837 vha->marker_needed = 1;
6840 vha->flags.online = 1;
6842 ha->isp_ops->enable_intrs(ha);
6844 ha->isp_abort_cnt = 0;
6845 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6847 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6848 qla2x00_get_fw_version(vha);
6850 ha->flags.fce_enabled = 1;
6852 fce_calc_size(ha->fce_bufs));
6853 rval = qla2x00_enable_fce_trace(vha,
6854 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6857 ql_log(ql_log_warn, vha, 0x8033,
6858 "Unable to reinitialize FCE "
6860 ha->flags.fce_enabled = 0;
6865 memset(ha->eft, 0, EFT_SIZE);
6866 rval = qla2x00_enable_eft_trace(vha,
6867 ha->eft_dma, EFT_NUM_BUFFERS);
6869 ql_log(ql_log_warn, vha, 0x8034,
6870 "Unable to reinitialize EFT "
6874 } else { /* failed the ISP abort */
6875 vha->flags.online = 1;
6876 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6877 if (ha->isp_abort_cnt == 0) {
6878 ql_log(ql_log_fatal, vha, 0x8035,
6879 "ISP error recover failed - "
6880 "board disabled.\n");
6882 * The next call disables the board
6885 qla2x00_abort_isp_cleanup(vha);
6886 vha->flags.online = 0;
6887 clear_bit(ISP_ABORT_RETRY,
6890 } else { /* schedule another ISP abort */
6891 ha->isp_abort_cnt--;
6892 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6893 "ISP abort - retry remaining %d.\n",
6898 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6899 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6900 "ISP error recovery - retrying (%d) "
6901 "more times.\n", ha->isp_abort_cnt);
6902 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6910 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6911 qla2x00_configure_hba(vha);
6912 spin_lock_irqsave(&ha->vport_slock, flags);
6913 list_for_each_entry(vp, &ha->vp_list, list) {
6915 atomic_inc(&vp->vref_count);
6916 spin_unlock_irqrestore(&ha->vport_slock, flags);
6918 qla2x00_vp_abort_isp(vp);
6920 spin_lock_irqsave(&ha->vport_slock, flags);
6921 atomic_dec(&vp->vref_count);
6924 spin_unlock_irqrestore(&ha->vport_slock, flags);
6926 if (IS_QLA8031(ha)) {
6927 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6928 "Setting back fcoe driver presence.\n");
6929 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6930 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6931 "Error while setting DRV-Presence.\n");
6934 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6942 * qla2x00_restart_isp
6943 * restarts the ISP after a reset
6946 * ha = adapter block pointer.
6952 qla2x00_restart_isp(scsi_qla_host_t *vha)
6955 struct qla_hw_data *ha = vha->hw;
6957 /* If firmware needs to be loaded */
6958 if (qla2x00_isp_firmware(vha)) {
6959 vha->flags.online = 0;
6960 status = ha->isp_ops->chip_diag(vha);
6962 status = qla2x00_setup_chip(vha);
6965 if (!status && !(status = qla2x00_init_rings(vha))) {
6966 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6967 ha->flags.chip_reset_done = 1;
6969 /* Initialize the queues in use */
6970 qla25xx_init_queues(ha);
6972 status = qla2x00_fw_ready(vha);
6974 /* Issue a marker after FW becomes ready. */
6975 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
6976 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6979 /* if no cable then assume it's good */
6980 if ((vha->device_flags & DFLG_NO_CABLE))
6987 qla25xx_init_queues(struct qla_hw_data *ha)
6989 struct rsp_que *rsp = NULL;
6990 struct req_que *req = NULL;
6991 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6995 for (i = 1; i < ha->max_rsp_queues; i++) {
6996 rsp = ha->rsp_q_map[i];
6997 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6998 rsp->options &= ~BIT_0;
6999 ret = qla25xx_init_rsp_que(base_vha, rsp);
7000 if (ret != QLA_SUCCESS)
7001 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7002 "%s Rsp que: %d init failed.\n",
7005 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7006 "%s Rsp que: %d inited.\n",
7010 for (i = 1; i < ha->max_req_queues; i++) {
7011 req = ha->req_q_map[i];
7012 if (req && test_bit(i, ha->req_qid_map)) {
7013 /* Clear outstanding commands array. */
7014 req->options &= ~BIT_0;
7015 ret = qla25xx_init_req_que(base_vha, req);
7016 if (ret != QLA_SUCCESS)
7017 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7018 "%s Req que: %d init failed.\n",
7021 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7022 "%s Req que: %d inited.\n",
7030 * qla2x00_reset_adapter
7034 * ha = adapter block pointer.
7037 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7039 unsigned long flags = 0;
7040 struct qla_hw_data *ha = vha->hw;
7041 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7043 vha->flags.online = 0;
7044 ha->isp_ops->disable_intrs(ha);
7046 spin_lock_irqsave(&ha->hardware_lock, flags);
7047 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7048 RD_REG_WORD(®->hccr); /* PCI Posting. */
7049 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7050 RD_REG_WORD(®->hccr); /* PCI Posting. */
7051 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7057 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7059 unsigned long flags = 0;
7060 struct qla_hw_data *ha = vha->hw;
7061 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7062 int rval = QLA_SUCCESS;
7064 if (IS_P3P_TYPE(ha))
7067 vha->flags.online = 0;
7068 ha->isp_ops->disable_intrs(ha);
7070 spin_lock_irqsave(&ha->hardware_lock, flags);
7071 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7072 RD_REG_DWORD(®->hccr);
7073 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7074 RD_REG_DWORD(®->hccr);
7075 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7077 if (IS_NOPOLLING_TYPE(ha))
7078 ha->isp_ops->enable_intrs(ha);
7083 /* On sparc systems, obtain port and node WWN from firmware
7086 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7087 struct nvram_24xx *nv)
7090 struct qla_hw_data *ha = vha->hw;
7091 struct pci_dev *pdev = ha->pdev;
7092 struct device_node *dp = pci_device_to_OF_node(pdev);
7096 val = of_get_property(dp, "port-wwn", &len);
7097 if (val && len >= WWN_SIZE)
7098 memcpy(nv->port_name, val, WWN_SIZE);
7100 val = of_get_property(dp, "node-wwn", &len);
7101 if (val && len >= WWN_SIZE)
7102 memcpy(nv->node_name, val, WWN_SIZE);
7107 qla24xx_nvram_config(scsi_qla_host_t *vha)
7110 struct init_cb_24xx *icb;
7111 struct nvram_24xx *nv;
7113 uint8_t *dptr1, *dptr2;
7116 struct qla_hw_data *ha = vha->hw;
7119 icb = (struct init_cb_24xx *)ha->init_cb;
7122 /* Determine NVRAM starting address. */
7123 if (ha->port_no == 0) {
7124 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7125 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7127 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7128 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7131 ha->nvram_size = sizeof(*nv);
7132 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7134 /* Get VPD data into cache */
7135 ha->vpd = ha->nvram + VPD_OFFSET;
7136 ha->isp_ops->read_nvram(vha, ha->vpd,
7137 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7139 /* Get NVRAM data into cache and calculate checksum. */
7140 dptr = (uint32_t *)nv;
7141 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7142 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7143 chksum += le32_to_cpu(*dptr);
7145 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7146 "Contents of NVRAM\n");
7147 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7148 nv, ha->nvram_size);
7150 /* Bad NVRAM data, set defaults parameters. */
7151 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7152 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7153 /* Reset NVRAM data. */
7154 ql_log(ql_log_warn, vha, 0x006b,
7155 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7156 chksum, nv->id, nv->nvram_version);
7157 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7158 ql_log(ql_log_warn, vha, 0x006c,
7159 "Falling back to functioning (yet invalid -- WWPN) "
7163 * Set default initialization control block.
7165 memset(nv, 0, ha->nvram_size);
7166 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7167 nv->version = cpu_to_le16(ICB_VERSION);
7168 nv->frame_payload_size = 2048;
7169 nv->execution_throttle = cpu_to_le16(0xFFFF);
7170 nv->exchange_count = cpu_to_le16(0);
7171 nv->hard_address = cpu_to_le16(124);
7172 nv->port_name[0] = 0x21;
7173 nv->port_name[1] = 0x00 + ha->port_no + 1;
7174 nv->port_name[2] = 0x00;
7175 nv->port_name[3] = 0xe0;
7176 nv->port_name[4] = 0x8b;
7177 nv->port_name[5] = 0x1c;
7178 nv->port_name[6] = 0x55;
7179 nv->port_name[7] = 0x86;
7180 nv->node_name[0] = 0x20;
7181 nv->node_name[1] = 0x00;
7182 nv->node_name[2] = 0x00;
7183 nv->node_name[3] = 0xe0;
7184 nv->node_name[4] = 0x8b;
7185 nv->node_name[5] = 0x1c;
7186 nv->node_name[6] = 0x55;
7187 nv->node_name[7] = 0x86;
7188 qla24xx_nvram_wwn_from_ofw(vha, nv);
7189 nv->login_retry_count = cpu_to_le16(8);
7190 nv->interrupt_delay_timer = cpu_to_le16(0);
7191 nv->login_timeout = cpu_to_le16(0);
7192 nv->firmware_options_1 =
7193 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7194 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7195 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7196 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7197 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7198 nv->efi_parameters = cpu_to_le32(0);
7199 nv->reset_delay = 5;
7200 nv->max_luns_per_target = cpu_to_le16(128);
7201 nv->port_down_retry_count = cpu_to_le16(30);
7202 nv->link_down_timeout = cpu_to_le16(30);
7207 if (qla_tgt_mode_enabled(vha)) {
7208 /* Don't enable full login after initial LIP */
7209 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7210 /* Don't enable LIP full login for initiator */
7211 nv->host_p &= cpu_to_le32(~BIT_10);
7214 qlt_24xx_config_nvram_stage1(vha, nv);
7216 /* Reset Initialization control block */
7217 memset(icb, 0, ha->init_cb_size);
7219 /* Copy 1st segment. */
7220 dptr1 = (uint8_t *)icb;
7221 dptr2 = (uint8_t *)&nv->version;
7222 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7224 *dptr1++ = *dptr2++;
7226 icb->login_retry_count = nv->login_retry_count;
7227 icb->link_down_on_nos = nv->link_down_on_nos;
7229 /* Copy 2nd segment. */
7230 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7231 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7232 cnt = (uint8_t *)&icb->reserved_3 -
7233 (uint8_t *)&icb->interrupt_delay_timer;
7235 *dptr1++ = *dptr2++;
7236 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7238 * Setup driver NVRAM options.
7240 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7243 qlt_24xx_config_nvram_stage2(vha, icb);
7245 if (nv->host_p & cpu_to_le32(BIT_15)) {
7246 /* Use alternate WWN? */
7247 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7248 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7251 /* Prepare nodename */
7252 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7254 * Firmware will apply the following mask if the nodename was
7257 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7258 icb->node_name[0] &= 0xF0;
7261 /* Set host adapter parameters. */
7262 ha->flags.disable_risc_code_load = 0;
7263 ha->flags.enable_lip_reset = 0;
7264 ha->flags.enable_lip_full_login =
7265 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7266 ha->flags.enable_target_reset =
7267 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7268 ha->flags.enable_led_scheme = 0;
7269 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7271 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7272 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7274 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7275 sizeof(ha->fw_seriallink_options24));
7277 /* save HBA serial number */
7278 ha->serial0 = icb->port_name[5];
7279 ha->serial1 = icb->port_name[6];
7280 ha->serial2 = icb->port_name[7];
7281 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7282 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7284 icb->execution_throttle = cpu_to_le16(0xFFFF);
7286 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7288 /* Set minimum login_timeout to 4 seconds. */
7289 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7290 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7291 if (le16_to_cpu(nv->login_timeout) < 4)
7292 nv->login_timeout = cpu_to_le16(4);
7293 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7295 /* Set minimum RATOV to 100 tenths of a second. */
7298 ha->loop_reset_delay = nv->reset_delay;
7300 /* Link Down Timeout = 0:
7302 * When Port Down timer expires we will start returning
7303 * I/O's to OS with "DID_NO_CONNECT".
7305 * Link Down Timeout != 0:
7307 * The driver waits for the link to come up after link down
7308 * before returning I/Os to OS with "DID_NO_CONNECT".
7310 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7311 ha->loop_down_abort_time =
7312 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7314 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7315 ha->loop_down_abort_time =
7316 (LOOP_DOWN_TIME - ha->link_down_timeout);
7319 /* Need enough time to try and get the port back. */
7320 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7321 if (qlport_down_retry)
7322 ha->port_down_retry_count = qlport_down_retry;
7324 /* Set login_retry_count */
7325 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7326 if (ha->port_down_retry_count ==
7327 le16_to_cpu(nv->port_down_retry_count) &&
7328 ha->port_down_retry_count > 3)
7329 ha->login_retry_count = ha->port_down_retry_count;
7330 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7331 ha->login_retry_count = ha->port_down_retry_count;
7332 if (ql2xloginretrycount)
7333 ha->login_retry_count = ql2xloginretrycount;
7335 /* N2N: driver will initiate Login instead of FW */
7336 icb->firmware_options_3 |= BIT_8;
7339 if (!vha->flags.init_done) {
7340 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7341 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7342 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7343 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7345 icb->firmware_options_2 &= cpu_to_le32(
7346 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7347 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7348 ha->zio_mode = QLA_ZIO_MODE_6;
7350 ql_log(ql_log_info, vha, 0x006f,
7351 "ZIO mode %d enabled; timer delay (%d us).\n",
7352 ha->zio_mode, ha->zio_timer * 100);
7354 icb->firmware_options_2 |= cpu_to_le32(
7355 (uint32_t)ha->zio_mode);
7356 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7360 ql_log(ql_log_warn, vha, 0x0070,
7361 "NVRAM configuration failed.\n");
7367 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7368 struct qla27xx_image_status *image_status)
7370 ql_dbg(ql_dbg_init, vha, 0x018b,
7371 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7373 image_status->image_status_mask,
7374 le16_to_cpu(image_status->generation),
7375 image_status->ver_major,
7376 image_status->ver_minor,
7377 image_status->bitmap,
7378 le32_to_cpu(image_status->checksum),
7379 le32_to_cpu(image_status->signature));
7383 qla28xx_check_aux_image_status_signature(
7384 struct qla27xx_image_status *image_status)
7386 ulong signature = le32_to_cpu(image_status->signature);
7388 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7392 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7394 ulong signature = le32_to_cpu(image_status->signature);
7397 signature != QLA27XX_IMG_STATUS_SIGN &&
7398 signature != QLA28XX_IMG_STATUS_SIGN;
7402 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7404 uint32_t *p = (void *)image_status;
7405 uint n = sizeof(*image_status) / sizeof(*p);
7409 sum += le32_to_cpup(p);
7415 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7417 return aux->bitmap & bitmask ?
7418 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7422 qla28xx_component_status(
7423 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7425 active_regions->aux.board_config =
7426 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7428 active_regions->aux.vpd_nvram =
7429 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7431 active_regions->aux.npiv_config_0_1 =
7432 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7434 active_regions->aux.npiv_config_2_3 =
7435 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7439 qla27xx_compare_image_generation(
7440 struct qla27xx_image_status *pri_image_status,
7441 struct qla27xx_image_status *sec_image_status)
7443 /* calculate generation delta as uint16 (this accounts for wrap) */
7445 le16_to_cpu(pri_image_status->generation) -
7446 le16_to_cpu(sec_image_status->generation);
7448 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7454 qla28xx_get_aux_images(
7455 struct scsi_qla_host *vha, struct active_regions *active_regions)
7457 struct qla_hw_data *ha = vha->hw;
7458 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7459 bool valid_pri_image = false, valid_sec_image = false;
7460 bool active_pri_image = false, active_sec_image = false;
7462 if (!ha->flt_region_aux_img_status_pri) {
7463 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7464 goto check_sec_image;
7467 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7468 ha->flt_region_aux_img_status_pri,
7469 sizeof(pri_aux_image_status) >> 2);
7470 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7472 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7473 ql_dbg(ql_dbg_init, vha, 0x018b,
7474 "Primary aux image signature (%#x) not valid\n",
7475 le32_to_cpu(pri_aux_image_status.signature));
7476 goto check_sec_image;
7479 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7480 ql_dbg(ql_dbg_init, vha, 0x018c,
7481 "Primary aux image checksum failed\n");
7482 goto check_sec_image;
7485 valid_pri_image = true;
7487 if (pri_aux_image_status.image_status_mask & 1) {
7488 ql_dbg(ql_dbg_init, vha, 0x018d,
7489 "Primary aux image is active\n");
7490 active_pri_image = true;
7494 if (!ha->flt_region_aux_img_status_sec) {
7495 ql_dbg(ql_dbg_init, vha, 0x018a,
7496 "Secondary aux image not addressed\n");
7497 goto check_valid_image;
7500 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7501 ha->flt_region_aux_img_status_sec,
7502 sizeof(sec_aux_image_status) >> 2);
7503 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7505 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7506 ql_dbg(ql_dbg_init, vha, 0x018b,
7507 "Secondary aux image signature (%#x) not valid\n",
7508 le32_to_cpu(sec_aux_image_status.signature));
7509 goto check_valid_image;
7512 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7513 ql_dbg(ql_dbg_init, vha, 0x018c,
7514 "Secondary aux image checksum failed\n");
7515 goto check_valid_image;
7518 valid_sec_image = true;
7520 if (sec_aux_image_status.image_status_mask & 1) {
7521 ql_dbg(ql_dbg_init, vha, 0x018d,
7522 "Secondary aux image is active\n");
7523 active_sec_image = true;
7527 if (valid_pri_image && active_pri_image &&
7528 valid_sec_image && active_sec_image) {
7529 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7530 &sec_aux_image_status) >= 0) {
7531 qla28xx_component_status(active_regions,
7532 &pri_aux_image_status);
7534 qla28xx_component_status(active_regions,
7535 &sec_aux_image_status);
7537 } else if (valid_pri_image && active_pri_image) {
7538 qla28xx_component_status(active_regions, &pri_aux_image_status);
7539 } else if (valid_sec_image && active_sec_image) {
7540 qla28xx_component_status(active_regions, &sec_aux_image_status);
7543 ql_dbg(ql_dbg_init, vha, 0x018f,
7544 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7545 active_regions->aux.board_config,
7546 active_regions->aux.vpd_nvram,
7547 active_regions->aux.npiv_config_0_1,
7548 active_regions->aux.npiv_config_2_3);
7552 qla27xx_get_active_image(struct scsi_qla_host *vha,
7553 struct active_regions *active_regions)
7555 struct qla_hw_data *ha = vha->hw;
7556 struct qla27xx_image_status pri_image_status, sec_image_status;
7557 bool valid_pri_image = false, valid_sec_image = false;
7558 bool active_pri_image = false, active_sec_image = false;
7560 if (!ha->flt_region_img_status_pri) {
7561 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7562 goto check_sec_image;
7565 if (qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7566 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7569 goto check_sec_image;
7571 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7573 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7574 ql_dbg(ql_dbg_init, vha, 0x018b,
7575 "Primary image signature (%#x) not valid\n",
7576 le32_to_cpu(pri_image_status.signature));
7577 goto check_sec_image;
7580 if (qla27xx_image_status_checksum(&pri_image_status)) {
7581 ql_dbg(ql_dbg_init, vha, 0x018c,
7582 "Primary image checksum failed\n");
7583 goto check_sec_image;
7586 valid_pri_image = true;
7588 if (pri_image_status.image_status_mask & 1) {
7589 ql_dbg(ql_dbg_init, vha, 0x018d,
7590 "Primary image is active\n");
7591 active_pri_image = true;
7595 if (!ha->flt_region_img_status_sec) {
7596 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7597 goto check_valid_image;
7600 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7601 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7602 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7604 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7605 ql_dbg(ql_dbg_init, vha, 0x018b,
7606 "Secondary image signature (%#x) not valid\n",
7607 le32_to_cpu(sec_image_status.signature));
7608 goto check_valid_image;
7611 if (qla27xx_image_status_checksum(&sec_image_status)) {
7612 ql_dbg(ql_dbg_init, vha, 0x018c,
7613 "Secondary image checksum failed\n");
7614 goto check_valid_image;
7617 valid_sec_image = true;
7619 if (sec_image_status.image_status_mask & 1) {
7620 ql_dbg(ql_dbg_init, vha, 0x018d,
7621 "Secondary image is active\n");
7622 active_sec_image = true;
7626 if (valid_pri_image && active_pri_image)
7627 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7629 if (valid_sec_image && active_sec_image) {
7630 if (!active_regions->global ||
7631 qla27xx_compare_image_generation(
7632 &pri_image_status, &sec_image_status) < 0) {
7633 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7637 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7638 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7639 "default (boot/fw)" :
7640 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7642 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7643 "secondary" : "invalid",
7644 active_regions->global);
7647 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7650 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7651 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7655 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7659 uint templates, segments, fragment;
7664 uint32_t risc_addr, risc_size, risc_attr = 0;
7665 struct qla_hw_data *ha = vha->hw;
7666 struct req_que *req = ha->req_q_map[0];
7667 struct fwdt *fwdt = ha->fwdt;
7669 ql_dbg(ql_dbg_init, vha, 0x008b,
7670 "FW: Loading firmware from flash (%x).\n", faddr);
7672 dcode = (void *)req->ring;
7673 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7674 if (qla24xx_risc_firmware_invalid(dcode)) {
7675 ql_log(ql_log_fatal, vha, 0x008c,
7676 "Unable to verify the integrity of flash firmware "
7678 ql_log(ql_log_fatal, vha, 0x008d,
7679 "Firmware data: %08x %08x %08x %08x.\n",
7680 dcode[0], dcode[1], dcode[2], dcode[3]);
7682 return QLA_FUNCTION_FAILED;
7685 dcode = (void *)req->ring;
7687 segments = FA_RISC_CODE_SEGMENTS;
7688 for (j = 0; j < segments; j++) {
7689 ql_dbg(ql_dbg_init, vha, 0x008d,
7690 "-> Loading segment %u...\n", j);
7691 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7692 risc_addr = be32_to_cpu(dcode[2]);
7693 risc_size = be32_to_cpu(dcode[3]);
7695 *srisc_addr = risc_addr;
7696 risc_attr = be32_to_cpu(dcode[9]);
7699 dlen = ha->fw_transfer_size >> 2;
7700 for (fragment = 0; risc_size; fragment++) {
7701 if (dlen > risc_size)
7704 ql_dbg(ql_dbg_init, vha, 0x008e,
7705 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7706 fragment, risc_addr, faddr, dlen);
7707 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7708 for (i = 0; i < dlen; i++)
7709 dcode[i] = swab32(dcode[i]);
7711 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7713 ql_log(ql_log_fatal, vha, 0x008f,
7714 "-> Failed load firmware fragment %u.\n",
7716 return QLA_FUNCTION_FAILED;
7725 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7728 templates = (risc_attr & BIT_9) ? 2 : 1;
7729 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7730 for (j = 0; j < templates; j++, fwdt++) {
7732 vfree(fwdt->template);
7733 fwdt->template = NULL;
7736 dcode = (void *)req->ring;
7737 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7738 risc_size = be32_to_cpu(dcode[2]);
7739 ql_dbg(ql_dbg_init, vha, 0x0161,
7740 "-> fwdt%u template array at %#x (%#x dwords)\n",
7741 j, faddr, risc_size);
7742 if (!risc_size || !~risc_size) {
7743 ql_dbg(ql_dbg_init, vha, 0x0162,
7744 "-> fwdt%u failed to read array\n", j);
7748 /* skip header and ignore checksum */
7752 ql_dbg(ql_dbg_init, vha, 0x0163,
7753 "-> fwdt%u template allocate template %#x words...\n",
7755 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7756 if (!fwdt->template) {
7757 ql_log(ql_log_warn, vha, 0x0164,
7758 "-> fwdt%u failed allocate template.\n", j);
7762 dcode = fwdt->template;
7763 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7765 if (!qla27xx_fwdt_template_valid(dcode)) {
7766 ql_log(ql_log_warn, vha, 0x0165,
7767 "-> fwdt%u failed template validate\n", j);
7771 dlen = qla27xx_fwdt_template_size(dcode);
7772 ql_dbg(ql_dbg_init, vha, 0x0166,
7773 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7774 j, dlen, dlen / sizeof(*dcode));
7775 if (dlen > risc_size * sizeof(*dcode)) {
7776 ql_log(ql_log_warn, vha, 0x0167,
7777 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7778 j, dlen - risc_size * sizeof(*dcode));
7782 fwdt->length = dlen;
7783 ql_dbg(ql_dbg_init, vha, 0x0168,
7784 "-> fwdt%u loaded template ok\n", j);
7786 faddr += risc_size + 1;
7793 vfree(fwdt->template);
7794 fwdt->template = NULL;
7800 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7803 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7807 uint16_t *wcode, *fwcode;
7808 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7809 struct fw_blob *blob;
7810 struct qla_hw_data *ha = vha->hw;
7811 struct req_que *req = ha->req_q_map[0];
7813 /* Load firmware blob. */
7814 blob = qla2x00_request_firmware(vha);
7816 ql_log(ql_log_info, vha, 0x0083,
7817 "Firmware image unavailable.\n");
7818 ql_log(ql_log_info, vha, 0x0084,
7819 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7820 return QLA_FUNCTION_FAILED;
7825 wcode = (uint16_t *)req->ring;
7827 fwcode = (uint16_t *)blob->fw->data;
7830 /* Validate firmware image by checking version. */
7831 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7832 ql_log(ql_log_fatal, vha, 0x0085,
7833 "Unable to verify integrity of firmware image (%zd).\n",
7835 goto fail_fw_integrity;
7837 for (i = 0; i < 4; i++)
7838 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7839 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7840 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7841 wcode[2] == 0 && wcode[3] == 0)) {
7842 ql_log(ql_log_fatal, vha, 0x0086,
7843 "Unable to verify integrity of firmware image.\n");
7844 ql_log(ql_log_fatal, vha, 0x0087,
7845 "Firmware data: %04x %04x %04x %04x.\n",
7846 wcode[0], wcode[1], wcode[2], wcode[3]);
7847 goto fail_fw_integrity;
7851 while (*seg && rval == QLA_SUCCESS) {
7853 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7854 risc_size = be16_to_cpu(fwcode[3]);
7856 /* Validate firmware image size. */
7857 fwclen += risc_size * sizeof(uint16_t);
7858 if (blob->fw->size < fwclen) {
7859 ql_log(ql_log_fatal, vha, 0x0088,
7860 "Unable to verify integrity of firmware image "
7861 "(%zd).\n", blob->fw->size);
7862 goto fail_fw_integrity;
7866 while (risc_size > 0 && rval == QLA_SUCCESS) {
7867 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7868 if (wlen > risc_size)
7870 ql_dbg(ql_dbg_init, vha, 0x0089,
7871 "Loading risc segment@ risc addr %x number of "
7872 "words 0x%x.\n", risc_addr, wlen);
7874 for (i = 0; i < wlen; i++)
7875 wcode[i] = swab16(fwcode[i]);
7877 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7880 ql_log(ql_log_fatal, vha, 0x008a,
7881 "Failed to load segment %d of firmware.\n",
7898 return QLA_FUNCTION_FAILED;
7902 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7905 uint templates, segments, fragment;
7908 uint32_t risc_addr, risc_size, risc_attr = 0;
7911 struct fw_blob *blob;
7913 struct qla_hw_data *ha = vha->hw;
7914 struct req_que *req = ha->req_q_map[0];
7915 struct fwdt *fwdt = ha->fwdt;
7917 ql_dbg(ql_dbg_init, vha, 0x0090,
7918 "-> FW: Loading via request-firmware.\n");
7920 blob = qla2x00_request_firmware(vha);
7922 ql_log(ql_log_warn, vha, 0x0092,
7923 "-> Firmware file not found.\n");
7925 return QLA_FUNCTION_FAILED;
7928 fwcode = (void *)blob->fw->data;
7930 if (qla24xx_risc_firmware_invalid(dcode)) {
7931 ql_log(ql_log_fatal, vha, 0x0093,
7932 "Unable to verify integrity of firmware image (%zd).\n",
7934 ql_log(ql_log_fatal, vha, 0x0095,
7935 "Firmware data: %08x %08x %08x %08x.\n",
7936 dcode[0], dcode[1], dcode[2], dcode[3]);
7937 return QLA_FUNCTION_FAILED;
7940 dcode = (void *)req->ring;
7942 segments = FA_RISC_CODE_SEGMENTS;
7943 for (j = 0; j < segments; j++) {
7944 ql_dbg(ql_dbg_init, vha, 0x0096,
7945 "-> Loading segment %u...\n", j);
7946 risc_addr = be32_to_cpu(fwcode[2]);
7947 risc_size = be32_to_cpu(fwcode[3]);
7950 *srisc_addr = risc_addr;
7951 risc_attr = be32_to_cpu(fwcode[9]);
7954 dlen = ha->fw_transfer_size >> 2;
7955 for (fragment = 0; risc_size; fragment++) {
7956 if (dlen > risc_size)
7959 ql_dbg(ql_dbg_init, vha, 0x0097,
7960 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7961 fragment, risc_addr,
7962 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7965 for (i = 0; i < dlen; i++)
7966 dcode[i] = swab32(fwcode[i]);
7968 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7970 ql_log(ql_log_fatal, vha, 0x0098,
7971 "-> Failed load firmware fragment %u.\n",
7973 return QLA_FUNCTION_FAILED;
7982 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7985 templates = (risc_attr & BIT_9) ? 2 : 1;
7986 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
7987 for (j = 0; j < templates; j++, fwdt++) {
7989 vfree(fwdt->template);
7990 fwdt->template = NULL;
7993 risc_size = be32_to_cpu(fwcode[2]);
7994 ql_dbg(ql_dbg_init, vha, 0x0171,
7995 "-> fwdt%u template array at %#x (%#x dwords)\n",
7996 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
7998 if (!risc_size || !~risc_size) {
7999 ql_dbg(ql_dbg_init, vha, 0x0172,
8000 "-> fwdt%u failed to read array\n", j);
8004 /* skip header and ignore checksum */
8008 ql_dbg(ql_dbg_init, vha, 0x0173,
8009 "-> fwdt%u template allocate template %#x words...\n",
8011 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8012 if (!fwdt->template) {
8013 ql_log(ql_log_warn, vha, 0x0174,
8014 "-> fwdt%u failed allocate template.\n", j);
8018 dcode = fwdt->template;
8019 for (i = 0; i < risc_size; i++)
8020 dcode[i] = fwcode[i];
8022 if (!qla27xx_fwdt_template_valid(dcode)) {
8023 ql_log(ql_log_warn, vha, 0x0175,
8024 "-> fwdt%u failed template validate\n", j);
8028 dlen = qla27xx_fwdt_template_size(dcode);
8029 ql_dbg(ql_dbg_init, vha, 0x0176,
8030 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8031 j, dlen, dlen / sizeof(*dcode));
8032 if (dlen > risc_size * sizeof(*dcode)) {
8033 ql_log(ql_log_warn, vha, 0x0177,
8034 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8035 j, dlen - risc_size * sizeof(*dcode));
8039 fwdt->length = dlen;
8040 ql_dbg(ql_dbg_init, vha, 0x0178,
8041 "-> fwdt%u loaded template ok\n", j);
8043 fwcode += risc_size + 1;
8050 vfree(fwdt->template);
8051 fwdt->template = NULL;
8058 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8062 if (ql2xfwloadbin == 1)
8063 return qla81xx_load_risc(vha, srisc_addr);
8067 * 1) Firmware via request-firmware interface (.bin file).
8068 * 2) Firmware residing in flash.
8070 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8071 if (rval == QLA_SUCCESS)
8074 return qla24xx_load_risc_flash(vha, srisc_addr,
8075 vha->hw->flt_region_fw);
8079 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8082 struct qla_hw_data *ha = vha->hw;
8083 struct active_regions active_regions = { };
8085 if (ql2xfwloadbin == 2)
8088 /* FW Load priority:
8089 * 1) Firmware residing in flash.
8090 * 2) Firmware via request-firmware interface (.bin file).
8091 * 3) Golden-Firmware residing in flash -- (limited operation).
8094 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8095 goto try_primary_fw;
8097 qla27xx_get_active_image(vha, &active_regions);
8099 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8100 goto try_primary_fw;
8102 ql_dbg(ql_dbg_init, vha, 0x008b,
8103 "Loading secondary firmware image.\n");
8104 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8109 ql_dbg(ql_dbg_init, vha, 0x008b,
8110 "Loading primary firmware image.\n");
8111 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8116 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8117 if (!rval || !ha->flt_region_gold_fw)
8120 ql_log(ql_log_info, vha, 0x0099,
8121 "Attempting to fallback to golden firmware.\n");
8122 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8126 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8127 ha->flags.running_gold_fw = 1;
8132 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8135 struct qla_hw_data *ha = vha->hw;
8137 if (ha->flags.pci_channel_io_perm_failure)
8139 if (!IS_FWI2_CAPABLE(ha))
8141 if (!ha->fw_major_version)
8143 if (!ha->flags.fw_started)
8146 ret = qla2x00_stop_firmware(vha);
8147 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8148 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8149 ha->isp_ops->reset_chip(vha);
8150 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8152 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8154 ql_log(ql_log_info, vha, 0x8015,
8155 "Attempting retry of stop-firmware command.\n");
8156 ret = qla2x00_stop_firmware(vha);
8160 ha->flags.fw_init_done = 0;
8164 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8166 int rval = QLA_SUCCESS;
8168 uint16_t mb[MAILBOX_REGISTER_COUNT];
8169 struct qla_hw_data *ha = vha->hw;
8170 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8175 rval = qla2x00_fw_ready(base_vha);
8177 if (rval == QLA_SUCCESS) {
8178 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8179 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8182 vha->flags.management_server_logged_in = 0;
8184 /* Login to SNS first */
8185 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8187 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8188 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8189 ql_dbg(ql_dbg_init, vha, 0x0120,
8190 "Failed SNS login: loop_id=%x, rval2=%d\n",
8193 ql_dbg(ql_dbg_init, vha, 0x0103,
8194 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8195 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8196 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8197 return (QLA_FUNCTION_FAILED);
8200 atomic_set(&vha->loop_down_timer, 0);
8201 atomic_set(&vha->loop_state, LOOP_UP);
8202 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8203 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8204 rval = qla2x00_loop_resync(base_vha);
8209 /* 84XX Support **************************************************************/
8211 static LIST_HEAD(qla_cs84xx_list);
8212 static DEFINE_MUTEX(qla_cs84xx_mutex);
8214 static struct qla_chip_state_84xx *
8215 qla84xx_get_chip(struct scsi_qla_host *vha)
8217 struct qla_chip_state_84xx *cs84xx;
8218 struct qla_hw_data *ha = vha->hw;
8220 mutex_lock(&qla_cs84xx_mutex);
8222 /* Find any shared 84xx chip. */
8223 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8224 if (cs84xx->bus == ha->pdev->bus) {
8225 kref_get(&cs84xx->kref);
8230 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8234 kref_init(&cs84xx->kref);
8235 spin_lock_init(&cs84xx->access_lock);
8236 mutex_init(&cs84xx->fw_update_mutex);
8237 cs84xx->bus = ha->pdev->bus;
8239 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8241 mutex_unlock(&qla_cs84xx_mutex);
8246 __qla84xx_chip_release(struct kref *kref)
8248 struct qla_chip_state_84xx *cs84xx =
8249 container_of(kref, struct qla_chip_state_84xx, kref);
8251 mutex_lock(&qla_cs84xx_mutex);
8252 list_del(&cs84xx->list);
8253 mutex_unlock(&qla_cs84xx_mutex);
8258 qla84xx_put_chip(struct scsi_qla_host *vha)
8260 struct qla_hw_data *ha = vha->hw;
8263 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8267 qla84xx_init_chip(scsi_qla_host_t *vha)
8271 struct qla_hw_data *ha = vha->hw;
8273 mutex_lock(&ha->cs84xx->fw_update_mutex);
8275 rval = qla84xx_verify_chip(vha, status);
8277 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8279 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8283 /* 81XX Support **************************************************************/
8286 qla81xx_nvram_config(scsi_qla_host_t *vha)
8289 struct init_cb_81xx *icb;
8290 struct nvram_81xx *nv;
8292 uint8_t *dptr1, *dptr2;
8295 struct qla_hw_data *ha = vha->hw;
8297 struct active_regions active_regions = { };
8300 icb = (struct init_cb_81xx *)ha->init_cb;
8303 /* Determine NVRAM starting address. */
8304 ha->nvram_size = sizeof(*nv);
8305 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8306 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8307 ha->vpd_size = FA_VPD_SIZE_82XX;
8309 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8310 qla28xx_get_aux_images(vha, &active_regions);
8312 /* Get VPD data into cache */
8313 ha->vpd = ha->nvram + VPD_OFFSET;
8315 faddr = ha->flt_region_vpd;
8316 if (IS_QLA28XX(ha)) {
8317 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8318 faddr = ha->flt_region_vpd_sec;
8319 ql_dbg(ql_dbg_init, vha, 0x0110,
8320 "Loading %s nvram image.\n",
8321 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8322 "primary" : "secondary");
8324 qla24xx_read_flash_data(vha, ha->vpd, faddr, ha->vpd_size >> 2);
8326 /* Get NVRAM data into cache and calculate checksum. */
8327 faddr = ha->flt_region_nvram;
8328 if (IS_QLA28XX(ha)) {
8329 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8330 faddr = ha->flt_region_nvram_sec;
8332 ql_dbg(ql_dbg_init, vha, 0x0110,
8333 "Loading %s nvram image.\n",
8334 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8335 "primary" : "secondary");
8336 qla24xx_read_flash_data(vha, ha->nvram, faddr, ha->nvram_size >> 2);
8338 dptr = (uint32_t *)nv;
8339 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8340 chksum += le32_to_cpu(*dptr);
8342 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8343 "Contents of NVRAM:\n");
8344 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8345 nv, ha->nvram_size);
8347 /* Bad NVRAM data, set defaults parameters. */
8348 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8349 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8350 /* Reset NVRAM data. */
8351 ql_log(ql_log_info, vha, 0x0073,
8352 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8353 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8354 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8355 ql_log(ql_log_info, vha, 0x0074,
8356 "Falling back to functioning (yet invalid -- WWPN) "
8360 * Set default initialization control block.
8362 memset(nv, 0, ha->nvram_size);
8363 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8364 nv->version = cpu_to_le16(ICB_VERSION);
8365 nv->frame_payload_size = 2048;
8366 nv->execution_throttle = cpu_to_le16(0xFFFF);
8367 nv->exchange_count = cpu_to_le16(0);
8368 nv->port_name[0] = 0x21;
8369 nv->port_name[1] = 0x00 + ha->port_no + 1;
8370 nv->port_name[2] = 0x00;
8371 nv->port_name[3] = 0xe0;
8372 nv->port_name[4] = 0x8b;
8373 nv->port_name[5] = 0x1c;
8374 nv->port_name[6] = 0x55;
8375 nv->port_name[7] = 0x86;
8376 nv->node_name[0] = 0x20;
8377 nv->node_name[1] = 0x00;
8378 nv->node_name[2] = 0x00;
8379 nv->node_name[3] = 0xe0;
8380 nv->node_name[4] = 0x8b;
8381 nv->node_name[5] = 0x1c;
8382 nv->node_name[6] = 0x55;
8383 nv->node_name[7] = 0x86;
8384 nv->login_retry_count = cpu_to_le16(8);
8385 nv->interrupt_delay_timer = cpu_to_le16(0);
8386 nv->login_timeout = cpu_to_le16(0);
8387 nv->firmware_options_1 =
8388 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8389 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8390 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8391 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8392 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8393 nv->efi_parameters = cpu_to_le32(0);
8394 nv->reset_delay = 5;
8395 nv->max_luns_per_target = cpu_to_le16(128);
8396 nv->port_down_retry_count = cpu_to_le16(30);
8397 nv->link_down_timeout = cpu_to_le16(180);
8398 nv->enode_mac[0] = 0x00;
8399 nv->enode_mac[1] = 0xC0;
8400 nv->enode_mac[2] = 0xDD;
8401 nv->enode_mac[3] = 0x04;
8402 nv->enode_mac[4] = 0x05;
8403 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8408 if (IS_T10_PI_CAPABLE(ha))
8409 nv->frame_payload_size &= ~7;
8411 qlt_81xx_config_nvram_stage1(vha, nv);
8413 /* Reset Initialization control block */
8414 memset(icb, 0, ha->init_cb_size);
8416 /* Copy 1st segment. */
8417 dptr1 = (uint8_t *)icb;
8418 dptr2 = (uint8_t *)&nv->version;
8419 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8421 *dptr1++ = *dptr2++;
8423 icb->login_retry_count = nv->login_retry_count;
8425 /* Copy 2nd segment. */
8426 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8427 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8428 cnt = (uint8_t *)&icb->reserved_5 -
8429 (uint8_t *)&icb->interrupt_delay_timer;
8431 *dptr1++ = *dptr2++;
8433 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8434 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8435 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8436 icb->enode_mac[0] = 0x00;
8437 icb->enode_mac[1] = 0xC0;
8438 icb->enode_mac[2] = 0xDD;
8439 icb->enode_mac[3] = 0x04;
8440 icb->enode_mac[4] = 0x05;
8441 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8444 /* Use extended-initialization control block. */
8445 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8446 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8448 * Setup driver NVRAM options.
8450 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8453 qlt_81xx_config_nvram_stage2(vha, icb);
8455 /* Use alternate WWN? */
8456 if (nv->host_p & cpu_to_le32(BIT_15)) {
8457 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8458 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8461 /* Prepare nodename */
8462 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8464 * Firmware will apply the following mask if the nodename was
8467 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8468 icb->node_name[0] &= 0xF0;
8471 /* Set host adapter parameters. */
8472 ha->flags.disable_risc_code_load = 0;
8473 ha->flags.enable_lip_reset = 0;
8474 ha->flags.enable_lip_full_login =
8475 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8476 ha->flags.enable_target_reset =
8477 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8478 ha->flags.enable_led_scheme = 0;
8479 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8481 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8482 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8484 /* save HBA serial number */
8485 ha->serial0 = icb->port_name[5];
8486 ha->serial1 = icb->port_name[6];
8487 ha->serial2 = icb->port_name[7];
8488 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8489 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8491 icb->execution_throttle = cpu_to_le16(0xFFFF);
8493 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8495 /* Set minimum login_timeout to 4 seconds. */
8496 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8497 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8498 if (le16_to_cpu(nv->login_timeout) < 4)
8499 nv->login_timeout = cpu_to_le16(4);
8500 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8502 /* Set minimum RATOV to 100 tenths of a second. */
8505 ha->loop_reset_delay = nv->reset_delay;
8507 /* Link Down Timeout = 0:
8509 * When Port Down timer expires we will start returning
8510 * I/O's to OS with "DID_NO_CONNECT".
8512 * Link Down Timeout != 0:
8514 * The driver waits for the link to come up after link down
8515 * before returning I/Os to OS with "DID_NO_CONNECT".
8517 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8518 ha->loop_down_abort_time =
8519 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8521 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8522 ha->loop_down_abort_time =
8523 (LOOP_DOWN_TIME - ha->link_down_timeout);
8526 /* Need enough time to try and get the port back. */
8527 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8528 if (qlport_down_retry)
8529 ha->port_down_retry_count = qlport_down_retry;
8531 /* Set login_retry_count */
8532 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8533 if (ha->port_down_retry_count ==
8534 le16_to_cpu(nv->port_down_retry_count) &&
8535 ha->port_down_retry_count > 3)
8536 ha->login_retry_count = ha->port_down_retry_count;
8537 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8538 ha->login_retry_count = ha->port_down_retry_count;
8539 if (ql2xloginretrycount)
8540 ha->login_retry_count = ql2xloginretrycount;
8542 /* if not running MSI-X we need handshaking on interrupts */
8543 if (!vha->hw->flags.msix_enabled &&
8544 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8545 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8548 if (!vha->flags.init_done) {
8549 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8550 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8551 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8552 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8554 icb->firmware_options_2 &= cpu_to_le32(
8555 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8556 vha->flags.process_response_queue = 0;
8557 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8558 ha->zio_mode = QLA_ZIO_MODE_6;
8560 ql_log(ql_log_info, vha, 0x0075,
8561 "ZIO mode %d enabled; timer delay (%d us).\n",
8563 ha->zio_timer * 100);
8565 icb->firmware_options_2 |= cpu_to_le32(
8566 (uint32_t)ha->zio_mode);
8567 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8568 vha->flags.process_response_queue = 1;
8571 /* enable RIDA Format2 */
8572 icb->firmware_options_3 |= BIT_0;
8574 /* N2N: driver will initiate Login instead of FW */
8575 icb->firmware_options_3 |= BIT_8;
8578 ql_log(ql_log_warn, vha, 0x0076,
8579 "NVRAM configuration failed.\n");
8585 qla82xx_restart_isp(scsi_qla_host_t *vha)
8588 struct qla_hw_data *ha = vha->hw;
8589 struct scsi_qla_host *vp;
8590 unsigned long flags;
8592 status = qla2x00_init_rings(vha);
8594 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8595 ha->flags.chip_reset_done = 1;
8597 status = qla2x00_fw_ready(vha);
8599 /* Issue a marker after FW becomes ready. */
8600 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8601 vha->flags.online = 1;
8602 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8605 /* if no cable then assume it's good */
8606 if ((vha->device_flags & DFLG_NO_CABLE))
8611 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8613 if (!atomic_read(&vha->loop_down_timer)) {
8615 * Issue marker command only when we are going
8616 * to start the I/O .
8618 vha->marker_needed = 1;
8621 ha->isp_ops->enable_intrs(ha);
8623 ha->isp_abort_cnt = 0;
8624 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8626 /* Update the firmware version */
8627 status = qla82xx_check_md_needed(vha);
8630 ha->flags.fce_enabled = 1;
8632 fce_calc_size(ha->fce_bufs));
8633 rval = qla2x00_enable_fce_trace(vha,
8634 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8637 ql_log(ql_log_warn, vha, 0x8001,
8638 "Unable to reinitialize FCE (%d).\n",
8640 ha->flags.fce_enabled = 0;
8645 memset(ha->eft, 0, EFT_SIZE);
8646 rval = qla2x00_enable_eft_trace(vha,
8647 ha->eft_dma, EFT_NUM_BUFFERS);
8649 ql_log(ql_log_warn, vha, 0x8010,
8650 "Unable to reinitialize EFT (%d).\n",
8657 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8658 "qla82xx_restart_isp succeeded.\n");
8660 spin_lock_irqsave(&ha->vport_slock, flags);
8661 list_for_each_entry(vp, &ha->vp_list, list) {
8663 atomic_inc(&vp->vref_count);
8664 spin_unlock_irqrestore(&ha->vport_slock, flags);
8666 qla2x00_vp_abort_isp(vp);
8668 spin_lock_irqsave(&ha->vport_slock, flags);
8669 atomic_dec(&vp->vref_count);
8672 spin_unlock_irqrestore(&ha->vport_slock, flags);
8675 ql_log(ql_log_warn, vha, 0x8016,
8676 "qla82xx_restart_isp **** FAILED ****.\n");
8683 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8685 struct qla_hw_data *ha = vha->hw;
8687 /* Hold status IOCBs until ABTS response received. */
8689 ha->fw_options[3] |= BIT_12;
8691 /* Set Retry FLOGI in case of P2P connection */
8692 if (ha->operating_mode == P2P) {
8693 ha->fw_options[2] |= BIT_3;
8694 ql_dbg(ql_dbg_disc, vha, 0x2103,
8695 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8696 __func__, ha->fw_options[2]);
8699 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8700 if (ql2xmvasynctoatio) {
8701 if (qla_tgt_mode_enabled(vha) ||
8702 qla_dual_mode_enabled(vha))
8703 ha->fw_options[2] |= BIT_11;
8705 ha->fw_options[2] &= ~BIT_11;
8708 if (qla_tgt_mode_enabled(vha) ||
8709 qla_dual_mode_enabled(vha)) {
8710 /* FW auto send SCSI status during */
8711 ha->fw_options[1] |= BIT_8;
8712 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8714 /* FW perform Exchange validation */
8715 ha->fw_options[2] |= BIT_4;
8717 ha->fw_options[1] &= ~BIT_8;
8718 ha->fw_options[10] &= 0x00ff;
8720 ha->fw_options[2] &= ~BIT_4;
8723 if (ql2xetsenable) {
8724 /* Enable ETS Burst. */
8725 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8726 ha->fw_options[2] |= BIT_9;
8729 ql_dbg(ql_dbg_init, vha, 0x00e9,
8730 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8731 __func__, ha->fw_options[1], ha->fw_options[2],
8732 ha->fw_options[3], vha->host->active_mode);
8734 qla2x00_set_fw_options(vha, ha->fw_options);
8738 * qla24xx_get_fcp_prio
8739 * Gets the fcp cmd priority value for the logged in port.
8740 * Looks for a match of the port descriptors within
8741 * each of the fcp prio config entries. If a match is found,
8742 * the tag (priority) value is returned.
8745 * vha = scsi host structure pointer.
8746 * fcport = port structure pointer.
8749 * non-zero (if found)
8756 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8759 uint8_t pid_match, wwn_match;
8761 uint32_t pid1, pid2;
8762 uint64_t wwn1, wwn2;
8763 struct qla_fcp_prio_entry *pri_entry;
8764 struct qla_hw_data *ha = vha->hw;
8766 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8770 entries = ha->fcp_prio_cfg->num_entries;
8771 pri_entry = &ha->fcp_prio_cfg->entry[0];
8773 for (i = 0; i < entries; i++) {
8774 pid_match = wwn_match = 0;
8776 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8781 /* check source pid for a match */
8782 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8783 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8784 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8785 if (pid1 == INVALID_PORT_ID)
8787 else if (pid1 == pid2)
8791 /* check destination pid for a match */
8792 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8793 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8794 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8795 if (pid1 == INVALID_PORT_ID)
8797 else if (pid1 == pid2)
8801 /* check source WWN for a match */
8802 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8803 wwn1 = wwn_to_u64(vha->port_name);
8804 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8805 if (wwn2 == (uint64_t)-1)
8807 else if (wwn1 == wwn2)
8811 /* check destination WWN for a match */
8812 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8813 wwn1 = wwn_to_u64(fcport->port_name);
8814 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8815 if (wwn2 == (uint64_t)-1)
8817 else if (wwn1 == wwn2)
8821 if (pid_match == 2 || wwn_match == 2) {
8822 /* Found a matching entry */
8823 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8824 priority = pri_entry->tag;
8835 * qla24xx_update_fcport_fcp_prio
8836 * Activates fcp priority for the logged in fc port
8839 * vha = scsi host structure pointer.
8840 * fcp = port structure pointer.
8843 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8849 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8855 if (fcport->port_type != FCT_TARGET ||
8856 fcport->loop_id == FC_NO_LOOP_ID)
8857 return QLA_FUNCTION_FAILED;
8859 priority = qla24xx_get_fcp_prio(vha, fcport);
8861 return QLA_FUNCTION_FAILED;
8863 if (IS_P3P_TYPE(vha->hw)) {
8864 fcport->fcp_prio = priority & 0xf;
8868 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8869 if (ret == QLA_SUCCESS) {
8870 if (fcport->fcp_prio != priority)
8871 ql_dbg(ql_dbg_user, vha, 0x709e,
8872 "Updated FCP_CMND priority - value=%d loop_id=%d "
8873 "port_id=%02x%02x%02x.\n", priority,
8874 fcport->loop_id, fcport->d_id.b.domain,
8875 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8876 fcport->fcp_prio = priority & 0xf;
8878 ql_dbg(ql_dbg_user, vha, 0x704f,
8879 "Unable to update FCP_CMND priority - ret=0x%x for "
8880 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8881 fcport->d_id.b.domain, fcport->d_id.b.area,
8882 fcport->d_id.b.al_pa);
8887 * qla24xx_update_all_fcp_prio
8888 * Activates fcp priority for all the logged in ports
8891 * ha = adapter block pointer.
8894 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8900 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8905 ret = QLA_FUNCTION_FAILED;
8906 /* We need to set priority for all logged in ports */
8907 list_for_each_entry(fcport, &vha->vp_fcports, list)
8908 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8913 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8914 int vp_idx, bool startqp)
8919 struct qla_hw_data *ha = vha->hw;
8920 uint16_t qpair_id = 0;
8921 struct qla_qpair *qpair = NULL;
8922 struct qla_msix_entry *msix;
8924 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8925 ql_log(ql_log_warn, vha, 0x00181,
8926 "FW/Driver is not multi-queue capable.\n");
8930 if (ql2xmqsupport || ql2xnvmeenable) {
8931 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8932 if (qpair == NULL) {
8933 ql_log(ql_log_warn, vha, 0x0182,
8934 "Failed to allocate memory for queue pair.\n");
8938 qpair->hw = vha->hw;
8940 qpair->qp_lock_ptr = &qpair->qp_lock;
8941 spin_lock_init(&qpair->qp_lock);
8942 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8944 /* Assign available que pair id */
8945 mutex_lock(&ha->mq_lock);
8946 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8947 if (ha->num_qpairs >= ha->max_qpairs) {
8948 mutex_unlock(&ha->mq_lock);
8949 ql_log(ql_log_warn, vha, 0x0183,
8950 "No resources to create additional q pair.\n");
8954 set_bit(qpair_id, ha->qpair_qid_map);
8955 ha->queue_pair_map[qpair_id] = qpair;
8956 qpair->id = qpair_id;
8957 qpair->vp_idx = vp_idx;
8958 qpair->fw_started = ha->flags.fw_started;
8959 INIT_LIST_HEAD(&qpair->hints_list);
8960 qpair->chip_reset = ha->base_qpair->chip_reset;
8961 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8962 qpair->enable_explicit_conf =
8963 ha->base_qpair->enable_explicit_conf;
8965 for (i = 0; i < ha->msix_count; i++) {
8966 msix = &ha->msix_entries[i];
8970 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8971 "Vector %x selected for qpair\n", msix->vector);
8975 ql_log(ql_log_warn, vha, 0x0184,
8976 "Out of MSI-X vectors!.\n");
8980 qpair->msix->in_use = 1;
8981 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8982 qpair->pdev = ha->pdev;
8983 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
8984 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8986 mutex_unlock(&ha->mq_lock);
8988 /* Create response queue first */
8989 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8991 ql_log(ql_log_warn, vha, 0x0185,
8992 "Failed to create response queue.\n");
8996 qpair->rsp = ha->rsp_q_map[rsp_id];
8998 /* Create request queue */
8999 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9002 ql_log(ql_log_warn, vha, 0x0186,
9003 "Failed to create request queue.\n");
9007 qpair->req = ha->req_q_map[req_id];
9008 qpair->rsp->req = qpair->req;
9009 qpair->rsp->qpair = qpair;
9010 /* init qpair to this cpu. Will adjust at run time. */
9011 qla_cpu_update(qpair, smp_processor_id());
9013 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9014 if (ha->fw_attributes & BIT_4)
9015 qpair->difdix_supported = 1;
9018 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9019 if (!qpair->srb_mempool) {
9020 ql_log(ql_log_warn, vha, 0xd036,
9021 "Failed to create srb mempool for qpair %d\n",
9026 /* Mark as online */
9029 if (!vha->flags.qpairs_available)
9030 vha->flags.qpairs_available = 1;
9032 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9033 "Request/Response queue pair created, id %d\n",
9035 ql_dbg(ql_dbg_init, vha, 0x0187,
9036 "Request/Response queue pair created, id %d\n",
9043 qla25xx_delete_rsp_que(vha, qpair->rsp);
9045 mutex_lock(&ha->mq_lock);
9046 qpair->msix->in_use = 0;
9047 list_del(&qpair->qp_list_elem);
9048 if (list_empty(&vha->qp_list))
9049 vha->flags.qpairs_available = 0;
9051 ha->queue_pair_map[qpair_id] = NULL;
9052 clear_bit(qpair_id, ha->qpair_qid_map);
9054 mutex_unlock(&ha->mq_lock);
9060 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9062 int ret = QLA_FUNCTION_FAILED;
9063 struct qla_hw_data *ha = qpair->hw;
9065 qpair->delete_in_progress = 1;
9066 while (atomic_read(&qpair->ref_count))
9069 ret = qla25xx_delete_req_que(vha, qpair->req);
9070 if (ret != QLA_SUCCESS)
9073 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9074 if (ret != QLA_SUCCESS)
9077 mutex_lock(&ha->mq_lock);
9078 ha->queue_pair_map[qpair->id] = NULL;
9079 clear_bit(qpair->id, ha->qpair_qid_map);
9081 list_del(&qpair->qp_list_elem);
9082 if (list_empty(&vha->qp_list)) {
9083 vha->flags.qpairs_available = 0;
9084 vha->flags.qpairs_req_created = 0;
9085 vha->flags.qpairs_rsp_created = 0;
9087 mempool_destroy(qpair->srb_mempool);
9089 mutex_unlock(&ha->mq_lock);