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 strncpy(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 strncpy(ha->model_desc,
4455 qla2x00_model_name[index * 2 + 1],
4456 sizeof(ha->model_desc) - 1);
4458 index = (ha->pdev->subsystem_device & 0xff);
4460 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4461 index < QLA_MODEL_NAMES) {
4462 strcpy(ha->model_number,
4463 qla2x00_model_name[index * 2]);
4464 strncpy(ha->model_desc,
4465 qla2x00_model_name[index * 2 + 1],
4466 sizeof(ha->model_desc) - 1);
4468 strcpy(ha->model_number, def);
4471 if (IS_FWI2_CAPABLE(ha))
4472 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4473 sizeof(ha->model_desc));
4476 /* On sparc systems, obtain port and node WWN from firmware
4479 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4482 struct qla_hw_data *ha = vha->hw;
4483 struct pci_dev *pdev = ha->pdev;
4484 struct device_node *dp = pci_device_to_OF_node(pdev);
4488 val = of_get_property(dp, "port-wwn", &len);
4489 if (val && len >= WWN_SIZE)
4490 memcpy(nv->port_name, val, WWN_SIZE);
4492 val = of_get_property(dp, "node-wwn", &len);
4493 if (val && len >= WWN_SIZE)
4494 memcpy(nv->node_name, val, WWN_SIZE);
4499 * NVRAM configuration for ISP 2xxx
4502 * ha = adapter block pointer.
4505 * initialization control block in response_ring
4506 * host adapters parameters in host adapter block
4512 qla2x00_nvram_config(scsi_qla_host_t *vha)
4517 uint8_t *dptr1, *dptr2;
4518 struct qla_hw_data *ha = vha->hw;
4519 init_cb_t *icb = ha->init_cb;
4520 nvram_t *nv = ha->nvram;
4521 uint8_t *ptr = ha->nvram;
4522 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4526 /* Determine NVRAM starting address. */
4527 ha->nvram_size = sizeof(*nv);
4529 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4530 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4531 ha->nvram_base = 0x80;
4533 /* Get NVRAM data and calculate checksum. */
4534 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4535 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4538 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4539 "Contents of NVRAM.\n");
4540 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4541 nv, ha->nvram_size);
4543 /* Bad NVRAM data, set defaults parameters. */
4544 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4545 nv->nvram_version < 1) {
4546 /* Reset NVRAM data. */
4547 ql_log(ql_log_warn, vha, 0x0064,
4548 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4549 chksum, nv->id, nv->nvram_version);
4550 ql_log(ql_log_warn, vha, 0x0065,
4552 "functioning (yet invalid -- WWPN) defaults.\n");
4555 * Set default initialization control block.
4557 memset(nv, 0, ha->nvram_size);
4558 nv->parameter_block_version = ICB_VERSION;
4560 if (IS_QLA23XX(ha)) {
4561 nv->firmware_options[0] = BIT_2 | BIT_1;
4562 nv->firmware_options[1] = BIT_7 | BIT_5;
4563 nv->add_firmware_options[0] = BIT_5;
4564 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4565 nv->frame_payload_size = 2048;
4566 nv->special_options[1] = BIT_7;
4567 } else if (IS_QLA2200(ha)) {
4568 nv->firmware_options[0] = BIT_2 | BIT_1;
4569 nv->firmware_options[1] = BIT_7 | BIT_5;
4570 nv->add_firmware_options[0] = BIT_5;
4571 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4572 nv->frame_payload_size = 1024;
4573 } else if (IS_QLA2100(ha)) {
4574 nv->firmware_options[0] = BIT_3 | BIT_1;
4575 nv->firmware_options[1] = BIT_5;
4576 nv->frame_payload_size = 1024;
4579 nv->max_iocb_allocation = cpu_to_le16(256);
4580 nv->execution_throttle = cpu_to_le16(16);
4581 nv->retry_count = 8;
4582 nv->retry_delay = 1;
4584 nv->port_name[0] = 33;
4585 nv->port_name[3] = 224;
4586 nv->port_name[4] = 139;
4588 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4590 nv->login_timeout = 4;
4593 * Set default host adapter parameters
4595 nv->host_p[1] = BIT_2;
4596 nv->reset_delay = 5;
4597 nv->port_down_retry_count = 8;
4598 nv->max_luns_per_target = cpu_to_le16(8);
4599 nv->link_down_timeout = 60;
4604 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4606 * The SN2 does not provide BIOS emulation which means you can't change
4607 * potentially bogus BIOS settings. Force the use of default settings
4608 * for link rate and frame size. Hope that the rest of the settings
4611 if (ia64_platform_is("sn2")) {
4612 nv->frame_payload_size = 2048;
4614 nv->special_options[1] = BIT_7;
4618 /* Reset Initialization control block */
4619 memset(icb, 0, ha->init_cb_size);
4622 * Setup driver NVRAM options.
4624 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4625 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4626 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4627 nv->firmware_options[1] &= ~BIT_4;
4629 if (IS_QLA23XX(ha)) {
4630 nv->firmware_options[0] |= BIT_2;
4631 nv->firmware_options[0] &= ~BIT_3;
4632 nv->special_options[0] &= ~BIT_6;
4633 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4635 if (IS_QLA2300(ha)) {
4636 if (ha->fb_rev == FPM_2310) {
4637 strcpy(ha->model_number, "QLA2310");
4639 strcpy(ha->model_number, "QLA2300");
4642 qla2x00_set_model_info(vha, nv->model_number,
4643 sizeof(nv->model_number), "QLA23xx");
4645 } else if (IS_QLA2200(ha)) {
4646 nv->firmware_options[0] |= BIT_2;
4648 * 'Point-to-point preferred, else loop' is not a safe
4649 * connection mode setting.
4651 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4653 /* Force 'loop preferred, else point-to-point'. */
4654 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4655 nv->add_firmware_options[0] |= BIT_5;
4657 strcpy(ha->model_number, "QLA22xx");
4658 } else /*if (IS_QLA2100(ha))*/ {
4659 strcpy(ha->model_number, "QLA2100");
4663 * Copy over NVRAM RISC parameter block to initialization control block.
4665 dptr1 = (uint8_t *)icb;
4666 dptr2 = (uint8_t *)&nv->parameter_block_version;
4667 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4669 *dptr1++ = *dptr2++;
4671 /* Copy 2nd half. */
4672 dptr1 = (uint8_t *)icb->add_firmware_options;
4673 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4675 *dptr1++ = *dptr2++;
4676 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4677 /* Use alternate WWN? */
4678 if (nv->host_p[1] & BIT_7) {
4679 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4680 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4683 /* Prepare nodename */
4684 if ((icb->firmware_options[1] & BIT_6) == 0) {
4686 * Firmware will apply the following mask if the nodename was
4689 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4690 icb->node_name[0] &= 0xF0;
4694 * Set host adapter parameters.
4698 * BIT_7 in the host-parameters section allows for modification to
4699 * internal driver logging.
4701 if (nv->host_p[0] & BIT_7)
4702 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4703 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4704 /* Always load RISC code on non ISP2[12]00 chips. */
4705 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4706 ha->flags.disable_risc_code_load = 0;
4707 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4708 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4709 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4710 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4711 ha->flags.disable_serdes = 0;
4713 ha->operating_mode =
4714 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4716 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4717 sizeof(ha->fw_seriallink_options));
4719 /* save HBA serial number */
4720 ha->serial0 = icb->port_name[5];
4721 ha->serial1 = icb->port_name[6];
4722 ha->serial2 = icb->port_name[7];
4723 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4724 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4726 icb->execution_throttle = cpu_to_le16(0xFFFF);
4728 ha->retry_count = nv->retry_count;
4730 /* Set minimum login_timeout to 4 seconds. */
4731 if (nv->login_timeout != ql2xlogintimeout)
4732 nv->login_timeout = ql2xlogintimeout;
4733 if (nv->login_timeout < 4)
4734 nv->login_timeout = 4;
4735 ha->login_timeout = nv->login_timeout;
4737 /* Set minimum RATOV to 100 tenths of a second. */
4740 ha->loop_reset_delay = nv->reset_delay;
4742 /* Link Down Timeout = 0:
4744 * When Port Down timer expires we will start returning
4745 * I/O's to OS with "DID_NO_CONNECT".
4747 * Link Down Timeout != 0:
4749 * The driver waits for the link to come up after link down
4750 * before returning I/Os to OS with "DID_NO_CONNECT".
4752 if (nv->link_down_timeout == 0) {
4753 ha->loop_down_abort_time =
4754 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4756 ha->link_down_timeout = nv->link_down_timeout;
4757 ha->loop_down_abort_time =
4758 (LOOP_DOWN_TIME - ha->link_down_timeout);
4762 * Need enough time to try and get the port back.
4764 ha->port_down_retry_count = nv->port_down_retry_count;
4765 if (qlport_down_retry)
4766 ha->port_down_retry_count = qlport_down_retry;
4767 /* Set login_retry_count */
4768 ha->login_retry_count = nv->retry_count;
4769 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4770 ha->port_down_retry_count > 3)
4771 ha->login_retry_count = ha->port_down_retry_count;
4772 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4773 ha->login_retry_count = ha->port_down_retry_count;
4774 if (ql2xloginretrycount)
4775 ha->login_retry_count = ql2xloginretrycount;
4777 icb->lun_enables = cpu_to_le16(0);
4778 icb->command_resource_count = 0;
4779 icb->immediate_notify_resource_count = 0;
4780 icb->timeout = cpu_to_le16(0);
4782 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4784 icb->firmware_options[0] &= ~BIT_3;
4785 icb->add_firmware_options[0] &=
4786 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4787 icb->add_firmware_options[0] |= BIT_2;
4788 icb->response_accumulation_timer = 3;
4789 icb->interrupt_delay_timer = 5;
4791 vha->flags.process_response_queue = 1;
4794 if (!vha->flags.init_done) {
4795 ha->zio_mode = icb->add_firmware_options[0] &
4796 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4797 ha->zio_timer = icb->interrupt_delay_timer ?
4798 icb->interrupt_delay_timer : 2;
4800 icb->add_firmware_options[0] &=
4801 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4802 vha->flags.process_response_queue = 0;
4803 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4804 ha->zio_mode = QLA_ZIO_MODE_6;
4806 ql_log(ql_log_info, vha, 0x0068,
4807 "ZIO mode %d enabled; timer delay (%d us).\n",
4808 ha->zio_mode, ha->zio_timer * 100);
4810 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4811 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4812 vha->flags.process_response_queue = 1;
4817 ql_log(ql_log_warn, vha, 0x0069,
4818 "NVRAM configuration failed.\n");
4824 qla2x00_rport_del(void *data)
4826 fc_port_t *fcport = data;
4827 struct fc_rport *rport;
4828 unsigned long flags;
4830 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4831 rport = fcport->drport ? fcport->drport : fcport->rport;
4832 fcport->drport = NULL;
4833 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4835 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4836 "%s %8phN. rport %p roles %x\n",
4837 __func__, fcport->port_name, rport,
4840 fc_remote_port_delete(rport);
4844 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4848 old_state = atomic_read(&fcport->state);
4849 atomic_set(&fcport->state, state);
4851 /* Don't print state transitions during initial allocation of fcport */
4852 if (old_state && old_state != state) {
4853 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4854 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4855 fcport->port_name, port_state_str[old_state],
4856 port_state_str[state], fcport->d_id.b.domain,
4857 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4862 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4864 * @flags: allocation flags
4866 * Returns a pointer to the allocated fcport, or NULL, if none available.
4869 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4873 fcport = kzalloc(sizeof(fc_port_t), flags);
4877 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4878 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4880 if (!fcport->ct_desc.ct_sns) {
4881 ql_log(ql_log_warn, vha, 0xd049,
4882 "Failed to allocate ct_sns request.\n");
4887 /* Setup fcport template structure. */
4889 fcport->port_type = FCT_UNKNOWN;
4890 fcport->loop_id = FC_NO_LOOP_ID;
4891 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4892 fcport->supported_classes = FC_COS_UNSPECIFIED;
4893 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4895 fcport->disc_state = DSC_DELETED;
4896 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4897 fcport->deleted = QLA_SESS_DELETED;
4898 fcport->login_retry = vha->hw->login_retry_count;
4899 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4900 fcport->logout_on_delete = 1;
4902 if (!fcport->ct_desc.ct_sns) {
4903 ql_log(ql_log_warn, vha, 0xd049,
4904 "Failed to allocate ct_sns request.\n");
4909 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4910 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4911 INIT_LIST_HEAD(&fcport->gnl_entry);
4912 INIT_LIST_HEAD(&fcport->list);
4918 qla2x00_free_fcport(fc_port_t *fcport)
4920 if (fcport->ct_desc.ct_sns) {
4921 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4922 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4923 fcport->ct_desc.ct_sns_dma);
4925 fcport->ct_desc.ct_sns = NULL;
4927 list_del(&fcport->list);
4928 qla2x00_clear_loop_id(fcport);
4933 * qla2x00_configure_loop
4934 * Updates Fibre Channel Device Database with what is actually on loop.
4937 * ha = adapter block pointer.
4942 * 2 = database was full and device was not configured.
4945 qla2x00_configure_loop(scsi_qla_host_t *vha)
4948 unsigned long flags, save_flags;
4949 struct qla_hw_data *ha = vha->hw;
4953 /* Get Initiator ID */
4954 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4955 rval = qla2x00_configure_hba(vha);
4956 if (rval != QLA_SUCCESS) {
4957 ql_dbg(ql_dbg_disc, vha, 0x2013,
4958 "Unable to configure HBA.\n");
4963 save_flags = flags = vha->dpc_flags;
4964 ql_dbg(ql_dbg_disc, vha, 0x2014,
4965 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4968 * If we have both an RSCN and PORT UPDATE pending then handle them
4969 * both at the same time.
4971 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4972 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4974 qla2x00_get_data_rate(vha);
4976 /* Determine what we need to do */
4977 if (ha->current_topology == ISP_CFG_FL &&
4978 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4980 set_bit(RSCN_UPDATE, &flags);
4982 } else if (ha->current_topology == ISP_CFG_F &&
4983 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4985 set_bit(RSCN_UPDATE, &flags);
4986 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4988 } else if (ha->current_topology == ISP_CFG_N) {
4989 clear_bit(RSCN_UPDATE, &flags);
4990 if (qla_tgt_mode_enabled(vha)) {
4991 /* allow the other side to start the login */
4992 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4993 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4995 } else if (ha->current_topology == ISP_CFG_NL) {
4996 clear_bit(RSCN_UPDATE, &flags);
4997 set_bit(LOCAL_LOOP_UPDATE, &flags);
4998 } else if (!vha->flags.online ||
4999 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5000 set_bit(RSCN_UPDATE, &flags);
5001 set_bit(LOCAL_LOOP_UPDATE, &flags);
5004 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5005 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5006 ql_dbg(ql_dbg_disc, vha, 0x2015,
5007 "Loop resync needed, failing.\n");
5008 rval = QLA_FUNCTION_FAILED;
5010 rval = qla2x00_configure_local_loop(vha);
5013 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5014 if (LOOP_TRANSITION(vha)) {
5015 ql_dbg(ql_dbg_disc, vha, 0x2099,
5016 "Needs RSCN update and loop transition.\n");
5017 rval = QLA_FUNCTION_FAILED;
5020 rval = qla2x00_configure_fabric(vha);
5023 if (rval == QLA_SUCCESS) {
5024 if (atomic_read(&vha->loop_down_timer) ||
5025 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5026 rval = QLA_FUNCTION_FAILED;
5028 atomic_set(&vha->loop_state, LOOP_READY);
5029 ql_dbg(ql_dbg_disc, vha, 0x2069,
5031 ha->flags.fw_init_done = 1;
5034 * Process any ATIO queue entries that came in
5035 * while we weren't online.
5037 if (qla_tgt_mode_enabled(vha) ||
5038 qla_dual_mode_enabled(vha)) {
5039 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5040 qlt_24xx_process_atio_queue(vha, 0);
5041 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5048 ql_dbg(ql_dbg_disc, vha, 0x206a,
5049 "%s *** FAILED ***.\n", __func__);
5051 ql_dbg(ql_dbg_disc, vha, 0x206b,
5052 "%s: exiting normally.\n", __func__);
5055 /* Restore state if a resync event occurred during processing */
5056 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5057 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5058 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5059 if (test_bit(RSCN_UPDATE, &save_flags)) {
5060 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5068 * qla2x00_configure_local_loop
5069 * Updates Fibre Channel Device Database with local loop devices.
5072 * ha = adapter block pointer.
5078 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5083 fc_port_t *fcport, *new_fcport;
5087 struct gid_list_info *gid;
5089 uint8_t domain, area, al_pa;
5090 struct qla_hw_data *ha = vha->hw;
5091 unsigned long flags;
5093 /* Inititae N2N login. */
5094 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5098 memset(ha->init_cb, 0, ha->init_cb_size);
5099 sz = min_t(int, sizeof(struct els_plogi_payload),
5101 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5102 (void *)ha->init_cb, sz);
5103 if (rval == QLA_SUCCESS) {
5104 bp = (uint32_t *)ha->init_cb;
5105 for (i = 0; i < sz/4 ; i++, bp++)
5106 *bp = cpu_to_be32(*bp);
5108 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
5109 sizeof(ha->plogi_els_payld.data));
5110 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5112 ql_dbg(ql_dbg_init, vha, 0x00d1,
5113 "PLOGI ELS param read fail.\n");
5120 entries = MAX_FIBRE_DEVICES_LOOP;
5122 /* Get list of logged in devices. */
5123 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5124 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5126 if (rval != QLA_SUCCESS)
5127 goto cleanup_allocation;
5129 ql_dbg(ql_dbg_disc, vha, 0x2011,
5130 "Entries in ID list (%d).\n", entries);
5131 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5132 ha->gid_list, entries * sizeof(*ha->gid_list));
5135 spin_lock_irqsave(&vha->work_lock, flags);
5136 vha->scan.scan_retry++;
5137 spin_unlock_irqrestore(&vha->work_lock, flags);
5139 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5140 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5141 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5144 vha->scan.scan_retry = 0;
5147 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5148 fcport->scan_state = QLA_FCPORT_SCAN;
5151 /* Allocate temporary fcport for any new fcports discovered. */
5152 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5153 if (new_fcport == NULL) {
5154 ql_log(ql_log_warn, vha, 0x2012,
5155 "Memory allocation failed for fcport.\n");
5156 rval = QLA_MEMORY_ALLOC_FAILED;
5157 goto cleanup_allocation;
5159 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5161 /* Add devices to port list. */
5163 for (index = 0; index < entries; index++) {
5164 domain = gid->domain;
5167 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5168 loop_id = gid->loop_id_2100;
5170 loop_id = le16_to_cpu(gid->loop_id);
5171 gid = (void *)gid + ha->gid_list_info_size;
5173 /* Bypass reserved domain fields. */
5174 if ((domain & 0xf0) == 0xf0)
5177 /* Bypass if not same domain and area of adapter. */
5178 if (area && domain && ((area != vha->d_id.b.area) ||
5179 (domain != vha->d_id.b.domain)) &&
5180 (ha->current_topology == ISP_CFG_NL))
5184 /* Bypass invalid local loop ID. */
5185 if (loop_id > LAST_LOCAL_LOOP_ID)
5188 memset(new_fcport->port_name, 0, WWN_SIZE);
5190 /* Fill in member data. */
5191 new_fcport->d_id.b.domain = domain;
5192 new_fcport->d_id.b.area = area;
5193 new_fcport->d_id.b.al_pa = al_pa;
5194 new_fcport->loop_id = loop_id;
5195 new_fcport->scan_state = QLA_FCPORT_FOUND;
5197 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5198 if (rval2 != QLA_SUCCESS) {
5199 ql_dbg(ql_dbg_disc, vha, 0x2097,
5200 "Failed to retrieve fcport information "
5201 "-- get_port_database=%x, loop_id=0x%04x.\n",
5202 rval2, new_fcport->loop_id);
5203 /* Skip retry if N2N */
5204 if (ha->current_topology != ISP_CFG_N) {
5205 ql_dbg(ql_dbg_disc, vha, 0x2105,
5206 "Scheduling resync.\n");
5207 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5212 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5213 /* Check for matching device in port list. */
5216 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5217 if (memcmp(new_fcport->port_name, fcport->port_name,
5221 fcport->flags &= ~FCF_FABRIC_DEVICE;
5222 fcport->loop_id = new_fcport->loop_id;
5223 fcport->port_type = new_fcport->port_type;
5224 fcport->d_id.b24 = new_fcport->d_id.b24;
5225 memcpy(fcport->node_name, new_fcport->node_name,
5227 fcport->scan_state = QLA_FCPORT_FOUND;
5233 /* New device, add to fcports list. */
5234 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5236 /* Allocate a new replacement fcport. */
5237 fcport = new_fcport;
5239 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5241 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5243 if (new_fcport == NULL) {
5244 ql_log(ql_log_warn, vha, 0xd031,
5245 "Failed to allocate memory for fcport.\n");
5246 rval = QLA_MEMORY_ALLOC_FAILED;
5247 goto cleanup_allocation;
5249 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5250 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5253 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5255 /* Base iIDMA settings on HBA port speed. */
5256 fcport->fp_speed = ha->link_data_rate;
5261 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5262 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5265 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5266 if ((qla_dual_mode_enabled(vha) ||
5267 qla_ini_mode_enabled(vha)) &&
5268 atomic_read(&fcport->state) == FCS_ONLINE) {
5269 qla2x00_mark_device_lost(vha, fcport,
5270 ql2xplogiabsentdevice, 0);
5271 if (fcport->loop_id != FC_NO_LOOP_ID &&
5272 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5273 fcport->port_type != FCT_INITIATOR &&
5274 fcport->port_type != FCT_BROADCAST) {
5275 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5276 "%s %d %8phC post del sess\n",
5280 qlt_schedule_sess_for_deletion(fcport);
5286 if (fcport->scan_state == QLA_FCPORT_FOUND)
5287 qla24xx_fcport_handle_login(vha, fcport);
5293 if (rval != QLA_SUCCESS) {
5294 ql_dbg(ql_dbg_disc, vha, 0x2098,
5295 "Configure local loop error exit: rval=%x.\n", rval);
5302 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5305 uint16_t mb[MAILBOX_REGISTER_COUNT];
5306 struct qla_hw_data *ha = vha->hw;
5308 if (!IS_IIDMA_CAPABLE(ha))
5311 if (atomic_read(&fcport->state) != FCS_ONLINE)
5314 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5315 fcport->fp_speed > ha->link_data_rate ||
5316 !ha->flags.gpsc_supported)
5319 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5321 if (rval != QLA_SUCCESS) {
5322 ql_dbg(ql_dbg_disc, vha, 0x2004,
5323 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5324 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5326 ql_dbg(ql_dbg_disc, vha, 0x2005,
5327 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5328 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5329 fcport->fp_speed, fcport->port_name);
5333 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5335 qla2x00_iidma_fcport(vha, fcport);
5336 qla24xx_update_fcport_fcp_prio(vha, fcport);
5339 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5341 struct qla_work_evt *e;
5343 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5345 return QLA_FUNCTION_FAILED;
5347 e->u.fcport.fcport = fcport;
5348 return qla2x00_post_work(vha, e);
5351 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5353 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5355 struct fc_rport_identifiers rport_ids;
5356 struct fc_rport *rport;
5357 unsigned long flags;
5359 if (atomic_read(&fcport->state) == FCS_ONLINE)
5362 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5363 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5364 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5365 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5366 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5367 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5369 ql_log(ql_log_warn, vha, 0x2006,
5370 "Unable to allocate fc remote port.\n");
5374 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5375 *((fc_port_t **)rport->dd_data) = fcport;
5376 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5378 rport->supported_classes = fcport->supported_classes;
5380 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5381 if (fcport->port_type == FCT_INITIATOR)
5382 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5383 if (fcport->port_type == FCT_TARGET)
5384 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5385 if (fcport->port_type & FCT_NVME_INITIATOR)
5386 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5387 if (fcport->port_type & FCT_NVME_TARGET)
5388 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5389 if (fcport->port_type & FCT_NVME_DISCOVERY)
5390 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5392 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5393 "%s %8phN. rport %p is %s mode\n",
5394 __func__, fcport->port_name, rport,
5395 (fcport->port_type == FCT_TARGET) ? "tgt" :
5396 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5398 fc_remote_port_rolechg(rport, rport_ids.roles);
5402 * qla2x00_update_fcport
5403 * Updates device on list.
5406 * ha = adapter block pointer.
5407 * fcport = port structure pointer.
5417 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5419 if (IS_SW_RESV_ADDR(fcport->d_id))
5422 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5423 __func__, fcport->port_name);
5425 fcport->disc_state = DSC_UPD_FCPORT;
5426 fcport->login_retry = vha->hw->login_retry_count;
5427 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5428 fcport->deleted = 0;
5429 fcport->logout_on_delete = 1;
5430 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5432 switch (vha->hw->current_topology) {
5435 fcport->keep_nport_handle = 1;
5441 qla2x00_iidma_fcport(vha, fcport);
5443 if (fcport->fc4f_nvme) {
5444 qla_nvme_register_remote(vha, fcport);
5445 fcport->disc_state = DSC_LOGIN_COMPLETE;
5446 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5450 qla24xx_update_fcport_fcp_prio(vha, fcport);
5452 switch (vha->host->active_mode) {
5453 case MODE_INITIATOR:
5454 qla2x00_reg_remote_port(vha, fcport);
5457 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5458 !vha->vha_tgt.qla_tgt->tgt_stopped)
5459 qlt_fc_port_added(vha, fcport);
5462 qla2x00_reg_remote_port(vha, fcport);
5463 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5464 !vha->vha_tgt.qla_tgt->tgt_stopped)
5465 qlt_fc_port_added(vha, fcport);
5471 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5473 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5474 if (fcport->id_changed) {
5475 fcport->id_changed = 0;
5476 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5477 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5478 __func__, __LINE__, fcport->port_name,
5480 qla24xx_post_gfpnid_work(vha, fcport);
5482 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5483 "%s %d %8phC post gpsc fcp_cnt %d\n",
5484 __func__, __LINE__, fcport->port_name,
5486 qla24xx_post_gpsc_work(vha, fcport);
5490 fcport->disc_state = DSC_LOGIN_COMPLETE;
5493 void qla_register_fcport_fn(struct work_struct *work)
5495 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5496 u32 rscn_gen = fcport->rscn_gen;
5499 if (IS_SW_RESV_ADDR(fcport->d_id))
5502 qla2x00_update_fcport(fcport->vha, fcport);
5504 if (rscn_gen != fcport->rscn_gen) {
5505 /* RSCN(s) came in while registration */
5506 switch (fcport->next_disc_state) {
5507 case DSC_DELETE_PEND:
5508 qlt_schedule_sess_for_deletion(fcport);
5511 data[0] = data[1] = 0;
5512 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5522 * qla2x00_configure_fabric
5523 * Setup SNS devices with loop ID's.
5526 * ha = adapter block pointer.
5533 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5537 uint16_t mb[MAILBOX_REGISTER_COUNT];
5539 LIST_HEAD(new_fcports);
5540 struct qla_hw_data *ha = vha->hw;
5543 /* If FL port exists, then SNS is present */
5544 if (IS_FWI2_CAPABLE(ha))
5545 loop_id = NPH_F_PORT;
5547 loop_id = SNS_FL_PORT;
5548 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5549 if (rval != QLA_SUCCESS) {
5550 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5551 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5553 vha->device_flags &= ~SWITCH_FOUND;
5554 return (QLA_SUCCESS);
5556 vha->device_flags |= SWITCH_FOUND;
5559 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5560 rval = qla2x00_send_change_request(vha, 0x3, 0);
5561 if (rval != QLA_SUCCESS)
5562 ql_log(ql_log_warn, vha, 0x121,
5563 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5569 qla2x00_mgmt_svr_login(vha);
5572 if (ql2xfdmienable &&
5573 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5574 qla2x00_fdmi_register(vha);
5576 /* Ensure we are logged into the SNS. */
5577 loop_id = NPH_SNS_LID(ha);
5578 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5579 0xfc, mb, BIT_1|BIT_0);
5580 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5581 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5582 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5583 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5584 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5587 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5588 if (qla2x00_rft_id(vha)) {
5590 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5591 "Register FC-4 TYPE failed.\n");
5592 if (test_bit(LOOP_RESYNC_NEEDED,
5596 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5598 ql_dbg(ql_dbg_disc, vha, 0x209a,
5599 "Register FC-4 Features failed.\n");
5600 if (test_bit(LOOP_RESYNC_NEEDED,
5604 if (vha->flags.nvme_enabled) {
5605 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5606 ql_dbg(ql_dbg_disc, vha, 0x2049,
5607 "Register NVME FC Type Features failed.\n");
5610 if (qla2x00_rnn_id(vha)) {
5612 ql_dbg(ql_dbg_disc, vha, 0x2104,
5613 "Register Node Name failed.\n");
5614 if (test_bit(LOOP_RESYNC_NEEDED,
5617 } else if (qla2x00_rsnn_nn(vha)) {
5619 ql_dbg(ql_dbg_disc, vha, 0x209b,
5620 "Register Symbolic Node Name failed.\n");
5621 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5627 /* Mark the time right before querying FW for connected ports.
5628 * This process is long, asynchronous and by the time it's done,
5629 * collected information might not be accurate anymore. E.g.
5630 * disconnected port might have re-connected and a brand new
5631 * session has been created. In this case session's generation
5632 * will be newer than discovery_gen. */
5633 qlt_do_generation_tick(vha, &discovery_gen);
5635 if (USE_ASYNC_SCAN(ha)) {
5636 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5639 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5641 list_for_each_entry(fcport, &vha->vp_fcports, list)
5642 fcport->scan_state = QLA_FCPORT_SCAN;
5644 rval = qla2x00_find_all_fabric_devs(vha);
5646 if (rval != QLA_SUCCESS)
5650 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5651 qla_nvme_register_hba(vha);
5654 ql_dbg(ql_dbg_disc, vha, 0x2068,
5655 "Configure fabric error exit rval=%d.\n", rval);
5661 * qla2x00_find_all_fabric_devs
5664 * ha = adapter block pointer.
5665 * dev = database device entry pointer.
5674 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5678 fc_port_t *fcport, *new_fcport;
5683 int first_dev, last_dev;
5684 port_id_t wrap = {}, nxt_d_id;
5685 struct qla_hw_data *ha = vha->hw;
5686 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5687 unsigned long flags;
5691 /* Try GID_PT to get device list, else GAN. */
5693 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5698 ql_dbg(ql_dbg_disc, vha, 0x209c,
5699 "GID_PT allocations failed, fallback on GA_NXT.\n");
5701 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5702 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5704 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5706 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5708 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5710 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5712 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5714 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5716 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5720 /* If other queries succeeded probe for FC-4 type */
5722 qla2x00_gff_id(vha, swl);
5723 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5729 /* Allocate temporary fcport for any new fcports discovered. */
5730 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5731 if (new_fcport == NULL) {
5732 ql_log(ql_log_warn, vha, 0x209d,
5733 "Failed to allocate memory for fcport.\n");
5734 return (QLA_MEMORY_ALLOC_FAILED);
5736 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5737 /* Set start port ID scan at adapter ID. */
5741 /* Starting free loop ID. */
5742 loop_id = ha->min_external_loopid;
5743 for (; loop_id <= ha->max_loop_id; loop_id++) {
5744 if (qla2x00_is_reserved_id(vha, loop_id))
5747 if (ha->current_topology == ISP_CFG_FL &&
5748 (atomic_read(&vha->loop_down_timer) ||
5749 LOOP_TRANSITION(vha))) {
5750 atomic_set(&vha->loop_down_timer, 0);
5751 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5752 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5758 wrap.b24 = new_fcport->d_id.b24;
5760 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5761 memcpy(new_fcport->node_name,
5762 swl[swl_idx].node_name, WWN_SIZE);
5763 memcpy(new_fcport->port_name,
5764 swl[swl_idx].port_name, WWN_SIZE);
5765 memcpy(new_fcport->fabric_port_name,
5766 swl[swl_idx].fabric_port_name, WWN_SIZE);
5767 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5768 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5770 new_fcport->nvme_flag = 0;
5771 new_fcport->fc4f_nvme = 0;
5772 if (vha->flags.nvme_enabled &&
5773 swl[swl_idx].fc4f_nvme) {
5774 new_fcport->fc4f_nvme =
5775 swl[swl_idx].fc4f_nvme;
5776 ql_log(ql_log_info, vha, 0x2131,
5777 "FOUND: NVME port %8phC as FC Type 28h\n",
5778 new_fcport->port_name);
5781 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5787 /* Send GA_NXT to the switch */
5788 rval = qla2x00_ga_nxt(vha, new_fcport);
5789 if (rval != QLA_SUCCESS) {
5790 ql_log(ql_log_warn, vha, 0x209e,
5791 "SNS scan failed -- assuming "
5792 "zero-entry result.\n");
5798 /* If wrap on switch device list, exit. */
5800 wrap.b24 = new_fcport->d_id.b24;
5802 } else if (new_fcport->d_id.b24 == wrap.b24) {
5803 ql_dbg(ql_dbg_disc, vha, 0x209f,
5804 "Device wrap (%02x%02x%02x).\n",
5805 new_fcport->d_id.b.domain,
5806 new_fcport->d_id.b.area,
5807 new_fcport->d_id.b.al_pa);
5811 /* Bypass if same physical adapter. */
5812 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5815 /* Bypass virtual ports of the same host. */
5816 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5819 /* Bypass if same domain and area of adapter. */
5820 if (((new_fcport->d_id.b24 & 0xffff00) ==
5821 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5825 /* Bypass reserved domain fields. */
5826 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5829 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5830 if (ql2xgffidenable &&
5831 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5832 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5835 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5837 /* Locate matching device in database. */
5839 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5840 if (memcmp(new_fcport->port_name, fcport->port_name,
5844 fcport->scan_state = QLA_FCPORT_FOUND;
5848 /* Update port state. */
5849 memcpy(fcport->fabric_port_name,
5850 new_fcport->fabric_port_name, WWN_SIZE);
5851 fcport->fp_speed = new_fcport->fp_speed;
5854 * If address the same and state FCS_ONLINE
5855 * (or in target mode), nothing changed.
5857 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5858 (atomic_read(&fcport->state) == FCS_ONLINE ||
5859 (vha->host->active_mode == MODE_TARGET))) {
5864 * If device was not a fabric device before.
5866 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5867 fcport->d_id.b24 = new_fcport->d_id.b24;
5868 qla2x00_clear_loop_id(fcport);
5869 fcport->flags |= (FCF_FABRIC_DEVICE |
5875 * Port ID changed or device was marked to be updated;
5876 * Log it out if still logged in and mark it for
5879 if (qla_tgt_mode_enabled(base_vha)) {
5880 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5881 "port changed FC ID, %8phC"
5882 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5884 fcport->d_id.b.domain,
5885 fcport->d_id.b.area,
5886 fcport->d_id.b.al_pa,
5888 new_fcport->d_id.b.domain,
5889 new_fcport->d_id.b.area,
5890 new_fcport->d_id.b.al_pa);
5891 fcport->d_id.b24 = new_fcport->d_id.b24;
5895 fcport->d_id.b24 = new_fcport->d_id.b24;
5896 fcport->flags |= FCF_LOGIN_NEEDED;
5900 if (fcport->fc4f_nvme) {
5901 if (fcport->disc_state == DSC_DELETE_PEND) {
5902 fcport->disc_state = DSC_GNL;
5903 vha->fcport_count--;
5904 fcport->login_succ = 0;
5909 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5912 /* If device was not in our fcports list, then add it. */
5913 new_fcport->scan_state = QLA_FCPORT_FOUND;
5914 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5916 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5919 /* Allocate a new replacement fcport. */
5920 nxt_d_id.b24 = new_fcport->d_id.b24;
5921 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5922 if (new_fcport == NULL) {
5923 ql_log(ql_log_warn, vha, 0xd032,
5924 "Memory allocation failed for fcport.\n");
5925 return (QLA_MEMORY_ALLOC_FAILED);
5927 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5928 new_fcport->d_id.b24 = nxt_d_id.b24;
5931 qla2x00_free_fcport(new_fcport);
5934 * Logout all previous fabric dev marked lost, except FCP2 devices.
5936 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5937 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5940 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5941 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5944 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5945 if ((qla_dual_mode_enabled(vha) ||
5946 qla_ini_mode_enabled(vha)) &&
5947 atomic_read(&fcport->state) == FCS_ONLINE) {
5948 qla2x00_mark_device_lost(vha, fcport,
5949 ql2xplogiabsentdevice, 0);
5950 if (fcport->loop_id != FC_NO_LOOP_ID &&
5951 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5952 fcport->port_type != FCT_INITIATOR &&
5953 fcport->port_type != FCT_BROADCAST) {
5954 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5955 "%s %d %8phC post del sess\n",
5958 qlt_schedule_sess_for_deletion(fcport);
5964 if (fcport->scan_state == QLA_FCPORT_FOUND)
5965 qla24xx_fcport_handle_login(vha, fcport);
5970 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5972 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5974 int loop_id = FC_NO_LOOP_ID;
5975 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5976 unsigned long flags;
5977 struct qla_hw_data *ha = vha->hw;
5979 if (vha->vp_idx == 0) {
5980 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5981 return NPH_MGMT_SERVER;
5984 /* pick id from high and work down to low */
5985 spin_lock_irqsave(&ha->vport_slock, flags);
5986 for (; lid > 0; lid--) {
5987 if (!test_bit(lid, vha->hw->loop_id_map)) {
5988 set_bit(lid, vha->hw->loop_id_map);
5993 spin_unlock_irqrestore(&ha->vport_slock, flags);
5999 * qla2x00_fabric_login
6000 * Issue fabric login command.
6003 * ha = adapter block pointer.
6004 * device = pointer to FC device type structure.
6007 * 0 - Login successfully
6009 * 2 - Initiator device
6013 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6014 uint16_t *next_loopid)
6018 uint16_t tmp_loopid;
6019 uint16_t mb[MAILBOX_REGISTER_COUNT];
6020 struct qla_hw_data *ha = vha->hw;
6026 ql_dbg(ql_dbg_disc, vha, 0x2000,
6027 "Trying Fabric Login w/loop id 0x%04x for port "
6029 fcport->loop_id, fcport->d_id.b.domain,
6030 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6032 /* Login fcport on switch. */
6033 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6034 fcport->d_id.b.domain, fcport->d_id.b.area,
6035 fcport->d_id.b.al_pa, mb, BIT_0);
6036 if (rval != QLA_SUCCESS) {
6039 if (mb[0] == MBS_PORT_ID_USED) {
6041 * Device has another loop ID. The firmware team
6042 * recommends the driver perform an implicit login with
6043 * the specified ID again. The ID we just used is save
6044 * here so we return with an ID that can be tried by
6048 tmp_loopid = fcport->loop_id;
6049 fcport->loop_id = mb[1];
6051 ql_dbg(ql_dbg_disc, vha, 0x2001,
6052 "Fabric Login: port in use - next loop "
6053 "id=0x%04x, port id= %02x%02x%02x.\n",
6054 fcport->loop_id, fcport->d_id.b.domain,
6055 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6057 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6062 /* A retry occurred before. */
6063 *next_loopid = tmp_loopid;
6066 * No retry occurred before. Just increment the
6067 * ID value for next login.
6069 *next_loopid = (fcport->loop_id + 1);
6072 if (mb[1] & BIT_0) {
6073 fcport->port_type = FCT_INITIATOR;
6075 fcport->port_type = FCT_TARGET;
6076 if (mb[1] & BIT_1) {
6077 fcport->flags |= FCF_FCP2_DEVICE;
6082 fcport->supported_classes |= FC_COS_CLASS2;
6084 fcport->supported_classes |= FC_COS_CLASS3;
6086 if (IS_FWI2_CAPABLE(ha)) {
6089 FCF_CONF_COMP_SUPPORTED;
6094 } else if (mb[0] == MBS_LOOP_ID_USED) {
6096 * Loop ID already used, try next loop ID.
6099 rval = qla2x00_find_new_loop_id(vha, fcport);
6100 if (rval != QLA_SUCCESS) {
6101 /* Ran out of loop IDs to use */
6104 } else if (mb[0] == MBS_COMMAND_ERROR) {
6106 * Firmware possibly timed out during login. If NO
6107 * retries are left to do then the device is declared
6110 *next_loopid = fcport->loop_id;
6111 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6112 fcport->d_id.b.domain, fcport->d_id.b.area,
6113 fcport->d_id.b.al_pa);
6114 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6120 * unrecoverable / not handled error
6122 ql_dbg(ql_dbg_disc, vha, 0x2002,
6123 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6124 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6125 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6126 fcport->loop_id, jiffies);
6128 *next_loopid = fcport->loop_id;
6129 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6130 fcport->d_id.b.domain, fcport->d_id.b.area,
6131 fcport->d_id.b.al_pa);
6132 qla2x00_clear_loop_id(fcport);
6133 fcport->login_retry = 0;
6144 * qla2x00_local_device_login
6145 * Issue local device login command.
6148 * ha = adapter block pointer.
6149 * loop_id = loop id of device to login to.
6151 * Returns (Where's the #define!!!!):
6152 * 0 - Login successfully
6157 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6160 uint16_t mb[MAILBOX_REGISTER_COUNT];
6162 memset(mb, 0, sizeof(mb));
6163 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6164 if (rval == QLA_SUCCESS) {
6165 /* Interrogate mailbox registers for any errors */
6166 if (mb[0] == MBS_COMMAND_ERROR)
6168 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6169 /* device not in PCB table */
6177 * qla2x00_loop_resync
6178 * Resync with fibre channel devices.
6181 * ha = adapter block pointer.
6187 qla2x00_loop_resync(scsi_qla_host_t *vha)
6189 int rval = QLA_SUCCESS;
6192 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6193 if (vha->flags.online) {
6194 if (!(rval = qla2x00_fw_ready(vha))) {
6195 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6198 if (!IS_QLAFX00(vha->hw)) {
6200 * Issue a marker after FW becomes
6203 qla2x00_marker(vha, vha->hw->base_qpair,
6205 vha->marker_needed = 0;
6208 /* Remap devices on Loop. */
6209 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6211 if (IS_QLAFX00(vha->hw))
6212 qlafx00_configure_devices(vha);
6214 qla2x00_configure_loop(vha);
6217 } while (!atomic_read(&vha->loop_down_timer) &&
6218 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6219 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6224 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6225 return (QLA_FUNCTION_FAILED);
6228 ql_dbg(ql_dbg_disc, vha, 0x206c,
6229 "%s *** FAILED ***.\n", __func__);
6235 * qla2x00_perform_loop_resync
6236 * Description: This function will set the appropriate flags and call
6237 * qla2x00_loop_resync. If successful loop will be resynced
6238 * Arguments : scsi_qla_host_t pointer
6239 * returm : Success or Failure
6242 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6246 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6247 /*Configure the flags so that resync happens properly*/
6248 atomic_set(&ha->loop_down_timer, 0);
6249 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6250 atomic_set(&ha->loop_state, LOOP_UP);
6251 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6252 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6253 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6255 rval = qla2x00_loop_resync(ha);
6257 atomic_set(&ha->loop_state, LOOP_DEAD);
6259 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6266 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6269 struct scsi_qla_host *vha;
6270 struct qla_hw_data *ha = base_vha->hw;
6271 unsigned long flags;
6273 spin_lock_irqsave(&ha->vport_slock, flags);
6274 /* Go with deferred removal of rport references. */
6275 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6276 atomic_inc(&vha->vref_count);
6277 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6278 if (fcport->drport &&
6279 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6280 spin_unlock_irqrestore(&ha->vport_slock, flags);
6281 qla2x00_rport_del(fcport);
6283 spin_lock_irqsave(&ha->vport_slock, flags);
6286 atomic_dec(&vha->vref_count);
6287 wake_up(&vha->vref_waitq);
6289 spin_unlock_irqrestore(&ha->vport_slock, flags);
6292 /* Assumes idc_lock always held on entry */
6294 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6296 struct qla_hw_data *ha = vha->hw;
6297 uint32_t drv_presence, drv_presence_mask;
6298 uint32_t dev_part_info1, dev_part_info2, class_type;
6299 uint32_t class_type_mask = 0x3;
6300 uint16_t fcoe_other_function = 0xffff, i;
6302 if (IS_QLA8044(ha)) {
6303 drv_presence = qla8044_rd_direct(vha,
6304 QLA8044_CRB_DRV_ACTIVE_INDEX);
6305 dev_part_info1 = qla8044_rd_direct(vha,
6306 QLA8044_CRB_DEV_PART_INFO_INDEX);
6307 dev_part_info2 = qla8044_rd_direct(vha,
6308 QLA8044_CRB_DEV_PART_INFO2);
6310 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6311 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6312 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6314 for (i = 0; i < 8; i++) {
6315 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6316 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6317 (i != ha->portnum)) {
6318 fcoe_other_function = i;
6322 if (fcoe_other_function == 0xffff) {
6323 for (i = 0; i < 8; i++) {
6324 class_type = ((dev_part_info2 >> (i * 4)) &
6326 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6327 ((i + 8) != ha->portnum)) {
6328 fcoe_other_function = i + 8;
6334 * Prepare drv-presence mask based on fcoe functions present.
6335 * However consider only valid physical fcoe function numbers (0-15).
6337 drv_presence_mask = ~((1 << (ha->portnum)) |
6338 ((fcoe_other_function == 0xffff) ?
6339 0 : (1 << (fcoe_other_function))));
6341 /* We are the reset owner iff:
6342 * - No other protocol drivers present.
6343 * - This is the lowest among fcoe functions. */
6344 if (!(drv_presence & drv_presence_mask) &&
6345 (ha->portnum < fcoe_other_function)) {
6346 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6347 "This host is Reset owner.\n");
6348 ha->flags.nic_core_reset_owner = 1;
6353 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6355 int rval = QLA_SUCCESS;
6356 struct qla_hw_data *ha = vha->hw;
6359 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6360 if (rval == QLA_SUCCESS) {
6361 drv_ack |= (1 << ha->portnum);
6362 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6369 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6371 int rval = QLA_SUCCESS;
6372 struct qla_hw_data *ha = vha->hw;
6375 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6376 if (rval == QLA_SUCCESS) {
6377 drv_ack &= ~(1 << ha->portnum);
6378 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6385 qla83xx_dev_state_to_string(uint32_t dev_state)
6387 switch (dev_state) {
6388 case QLA8XXX_DEV_COLD:
6389 return "COLD/RE-INIT";
6390 case QLA8XXX_DEV_INITIALIZING:
6391 return "INITIALIZING";
6392 case QLA8XXX_DEV_READY:
6394 case QLA8XXX_DEV_NEED_RESET:
6395 return "NEED RESET";
6396 case QLA8XXX_DEV_NEED_QUIESCENT:
6397 return "NEED QUIESCENT";
6398 case QLA8XXX_DEV_FAILED:
6400 case QLA8XXX_DEV_QUIESCENT:
6407 /* Assumes idc-lock always held on entry */
6409 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6411 struct qla_hw_data *ha = vha->hw;
6412 uint32_t idc_audit_reg = 0, duration_secs = 0;
6414 switch (audit_type) {
6415 case IDC_AUDIT_TIMESTAMP:
6416 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6417 idc_audit_reg = (ha->portnum) |
6418 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6419 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6422 case IDC_AUDIT_COMPLETION:
6423 duration_secs = ((jiffies_to_msecs(jiffies) -
6424 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6425 idc_audit_reg = (ha->portnum) |
6426 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6427 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6431 ql_log(ql_log_warn, vha, 0xb078,
6432 "Invalid audit type specified.\n");
6437 /* Assumes idc_lock always held on entry */
6439 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6441 struct qla_hw_data *ha = vha->hw;
6442 uint32_t idc_control, dev_state;
6444 __qla83xx_get_idc_control(vha, &idc_control);
6445 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6446 ql_log(ql_log_info, vha, 0xb080,
6447 "NIC Core reset has been disabled. idc-control=0x%x\n",
6449 return QLA_FUNCTION_FAILED;
6452 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6453 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6454 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6455 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6456 QLA8XXX_DEV_NEED_RESET);
6457 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6458 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6460 const char *state = qla83xx_dev_state_to_string(dev_state);
6462 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6464 /* SV: XXX: Is timeout required here? */
6465 /* Wait for IDC state change READY -> NEED_RESET */
6466 while (dev_state == QLA8XXX_DEV_READY) {
6467 qla83xx_idc_unlock(vha, 0);
6469 qla83xx_idc_lock(vha, 0);
6470 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6474 /* Send IDC ack by writing to drv-ack register */
6475 __qla83xx_set_drv_ack(vha);
6481 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6483 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6487 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6489 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6493 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6495 uint32_t drv_presence = 0;
6496 struct qla_hw_data *ha = vha->hw;
6498 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6499 if (drv_presence & (1 << ha->portnum))
6502 return QLA_TEST_FAILED;
6506 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6508 int rval = QLA_SUCCESS;
6509 struct qla_hw_data *ha = vha->hw;
6511 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6512 "Entered %s().\n", __func__);
6514 if (vha->device_flags & DFLG_DEV_FAILED) {
6515 ql_log(ql_log_warn, vha, 0xb059,
6516 "Device in unrecoverable FAILED state.\n");
6517 return QLA_FUNCTION_FAILED;
6520 qla83xx_idc_lock(vha, 0);
6522 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6523 ql_log(ql_log_warn, vha, 0xb05a,
6524 "Function=0x%x has been removed from IDC participation.\n",
6526 rval = QLA_FUNCTION_FAILED;
6530 qla83xx_reset_ownership(vha);
6532 rval = qla83xx_initiating_reset(vha);
6535 * Perform reset if we are the reset-owner,
6536 * else wait till IDC state changes to READY/FAILED.
6538 if (rval == QLA_SUCCESS) {
6539 rval = qla83xx_idc_state_handler(vha);
6541 if (rval == QLA_SUCCESS)
6542 ha->flags.nic_core_hung = 0;
6543 __qla83xx_clear_drv_ack(vha);
6547 qla83xx_idc_unlock(vha, 0);
6549 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6555 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6557 struct qla_hw_data *ha = vha->hw;
6558 int rval = QLA_FUNCTION_FAILED;
6560 if (!IS_MCTP_CAPABLE(ha)) {
6561 /* This message can be removed from the final version */
6562 ql_log(ql_log_info, vha, 0x506d,
6563 "This board is not MCTP capable\n");
6567 if (!ha->mctp_dump) {
6568 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6569 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6571 if (!ha->mctp_dump) {
6572 ql_log(ql_log_warn, vha, 0x506e,
6573 "Failed to allocate memory for mctp dump\n");
6578 #define MCTP_DUMP_STR_ADDR 0x00000000
6579 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6580 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6581 if (rval != QLA_SUCCESS) {
6582 ql_log(ql_log_warn, vha, 0x506f,
6583 "Failed to capture mctp dump\n");
6585 ql_log(ql_log_info, vha, 0x5070,
6586 "Mctp dump capture for host (%ld/%p).\n",
6587 vha->host_no, ha->mctp_dump);
6588 ha->mctp_dumped = 1;
6591 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6592 ha->flags.nic_core_reset_hdlr_active = 1;
6593 rval = qla83xx_restart_nic_firmware(vha);
6595 /* NIC Core reset failed. */
6596 ql_log(ql_log_warn, vha, 0x5071,
6597 "Failed to restart nic firmware\n");
6599 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6600 "Restarted NIC firmware successfully.\n");
6601 ha->flags.nic_core_reset_hdlr_active = 0;
6609 * qla2x00_quiesce_io
6610 * Description: This function will block the new I/Os
6611 * Its not aborting any I/Os as context
6612 * is not destroyed during quiescence
6613 * Arguments: scsi_qla_host_t
6617 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6619 struct qla_hw_data *ha = vha->hw;
6620 struct scsi_qla_host *vp;
6622 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6623 "Quiescing I/O - ha=%p.\n", ha);
6625 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6626 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6627 atomic_set(&vha->loop_state, LOOP_DOWN);
6628 qla2x00_mark_all_devices_lost(vha, 0);
6629 list_for_each_entry(vp, &ha->vp_list, list)
6630 qla2x00_mark_all_devices_lost(vp, 0);
6632 if (!atomic_read(&vha->loop_down_timer))
6633 atomic_set(&vha->loop_down_timer,
6636 /* Wait for pending cmds to complete */
6637 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6641 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6643 struct qla_hw_data *ha = vha->hw;
6644 struct scsi_qla_host *vp;
6645 unsigned long flags;
6649 /* For ISP82XX, driver waits for completion of the commands.
6650 * online flag should be set.
6652 if (!(IS_P3P_TYPE(ha)))
6653 vha->flags.online = 0;
6654 ha->flags.chip_reset_done = 0;
6655 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6656 vha->qla_stats.total_isp_aborts++;
6658 ql_log(ql_log_info, vha, 0x00af,
6659 "Performing ISP error recovery - ha=%p.\n", ha);
6661 ha->flags.purge_mbox = 1;
6662 /* For ISP82XX, reset_chip is just disabling interrupts.
6663 * Driver waits for the completion of the commands.
6664 * the interrupts need to be enabled.
6666 if (!(IS_P3P_TYPE(ha)))
6667 ha->isp_ops->reset_chip(vha);
6669 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6671 ha->flags.rida_fmt2 = 0;
6672 ha->flags.n2n_ae = 0;
6673 ha->flags.lip_ae = 0;
6674 ha->current_topology = 0;
6675 ha->flags.fw_started = 0;
6676 ha->flags.fw_init_done = 0;
6678 ha->base_qpair->chip_reset = ha->chip_reset;
6679 for (i = 0; i < ha->max_qpairs; i++) {
6680 if (ha->queue_pair_map[i])
6681 ha->queue_pair_map[i]->chip_reset =
6682 ha->base_qpair->chip_reset;
6685 /* purge MBox commands */
6686 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6687 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6688 complete(&ha->mbx_intr_comp);
6692 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6693 atomic_read(&ha->num_pend_mbx_stage2) ||
6694 atomic_read(&ha->num_pend_mbx_stage1)) {
6700 ha->flags.purge_mbox = 0;
6702 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6703 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6704 atomic_set(&vha->loop_state, LOOP_DOWN);
6705 qla2x00_mark_all_devices_lost(vha, 0);
6707 spin_lock_irqsave(&ha->vport_slock, flags);
6708 list_for_each_entry(vp, &ha->vp_list, list) {
6709 atomic_inc(&vp->vref_count);
6710 spin_unlock_irqrestore(&ha->vport_slock, flags);
6712 qla2x00_mark_all_devices_lost(vp, 0);
6714 spin_lock_irqsave(&ha->vport_slock, flags);
6715 atomic_dec(&vp->vref_count);
6717 spin_unlock_irqrestore(&ha->vport_slock, flags);
6719 if (!atomic_read(&vha->loop_down_timer))
6720 atomic_set(&vha->loop_down_timer,
6724 /* Clear all async request states across all VPs. */
6725 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6726 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6727 fcport->scan_state = 0;
6729 spin_lock_irqsave(&ha->vport_slock, flags);
6730 list_for_each_entry(vp, &ha->vp_list, list) {
6731 atomic_inc(&vp->vref_count);
6732 spin_unlock_irqrestore(&ha->vport_slock, flags);
6734 list_for_each_entry(fcport, &vp->vp_fcports, list)
6735 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6737 spin_lock_irqsave(&ha->vport_slock, flags);
6738 atomic_dec(&vp->vref_count);
6740 spin_unlock_irqrestore(&ha->vport_slock, flags);
6742 if (!ha->flags.eeh_busy) {
6743 /* Make sure for ISP 82XX IO DMA is complete */
6744 if (IS_P3P_TYPE(ha)) {
6745 qla82xx_chip_reset_cleanup(vha);
6746 ql_log(ql_log_info, vha, 0x00b4,
6747 "Done chip reset cleanup.\n");
6749 /* Done waiting for pending commands.
6750 * Reset the online flag.
6752 vha->flags.online = 0;
6755 /* Requeue all commands in outstanding command list. */
6756 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6758 /* memory barrier */
6764 * Resets ISP and aborts all outstanding commands.
6767 * ha = adapter block pointer.
6773 qla2x00_abort_isp(scsi_qla_host_t *vha)
6777 struct qla_hw_data *ha = vha->hw;
6778 struct scsi_qla_host *vp;
6779 struct req_que *req = ha->req_q_map[0];
6780 unsigned long flags;
6782 if (vha->flags.online) {
6783 qla2x00_abort_isp_cleanup(vha);
6785 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6786 ha->flags.chip_reset_done = 1;
6787 vha->flags.online = 1;
6789 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6793 if (IS_QLA8031(ha)) {
6794 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6795 "Clearing fcoe driver presence.\n");
6796 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6797 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6798 "Error while clearing DRV-Presence.\n");
6801 if (unlikely(pci_channel_offline(ha->pdev) &&
6802 ha->flags.pci_channel_io_perm_failure)) {
6803 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6808 switch (vha->qlini_mode) {
6809 case QLA2XXX_INI_MODE_DISABLED:
6810 if (!qla_tgt_mode_enabled(vha))
6813 case QLA2XXX_INI_MODE_DUAL:
6814 if (!qla_dual_mode_enabled(vha))
6817 case QLA2XXX_INI_MODE_ENABLED:
6822 ha->isp_ops->get_flash_version(vha, req->ring);
6824 ha->isp_ops->nvram_config(vha);
6826 if (!qla2x00_restart_isp(vha)) {
6827 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6829 if (!atomic_read(&vha->loop_down_timer)) {
6831 * Issue marker command only when we are going
6832 * to start the I/O .
6834 vha->marker_needed = 1;
6837 vha->flags.online = 1;
6839 ha->isp_ops->enable_intrs(ha);
6841 ha->isp_abort_cnt = 0;
6842 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6844 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6845 qla2x00_get_fw_version(vha);
6847 ha->flags.fce_enabled = 1;
6849 fce_calc_size(ha->fce_bufs));
6850 rval = qla2x00_enable_fce_trace(vha,
6851 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6854 ql_log(ql_log_warn, vha, 0x8033,
6855 "Unable to reinitialize FCE "
6857 ha->flags.fce_enabled = 0;
6862 memset(ha->eft, 0, EFT_SIZE);
6863 rval = qla2x00_enable_eft_trace(vha,
6864 ha->eft_dma, EFT_NUM_BUFFERS);
6866 ql_log(ql_log_warn, vha, 0x8034,
6867 "Unable to reinitialize EFT "
6871 } else { /* failed the ISP abort */
6872 vha->flags.online = 1;
6873 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6874 if (ha->isp_abort_cnt == 0) {
6875 ql_log(ql_log_fatal, vha, 0x8035,
6876 "ISP error recover failed - "
6877 "board disabled.\n");
6879 * The next call disables the board
6882 qla2x00_abort_isp_cleanup(vha);
6883 vha->flags.online = 0;
6884 clear_bit(ISP_ABORT_RETRY,
6887 } else { /* schedule another ISP abort */
6888 ha->isp_abort_cnt--;
6889 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6890 "ISP abort - retry remaining %d.\n",
6895 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6896 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6897 "ISP error recovery - retrying (%d) "
6898 "more times.\n", ha->isp_abort_cnt);
6899 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6907 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6908 qla2x00_configure_hba(vha);
6909 spin_lock_irqsave(&ha->vport_slock, flags);
6910 list_for_each_entry(vp, &ha->vp_list, list) {
6912 atomic_inc(&vp->vref_count);
6913 spin_unlock_irqrestore(&ha->vport_slock, flags);
6915 qla2x00_vp_abort_isp(vp);
6917 spin_lock_irqsave(&ha->vport_slock, flags);
6918 atomic_dec(&vp->vref_count);
6921 spin_unlock_irqrestore(&ha->vport_slock, flags);
6923 if (IS_QLA8031(ha)) {
6924 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6925 "Setting back fcoe driver presence.\n");
6926 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6927 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6928 "Error while setting DRV-Presence.\n");
6931 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6939 * qla2x00_restart_isp
6940 * restarts the ISP after a reset
6943 * ha = adapter block pointer.
6949 qla2x00_restart_isp(scsi_qla_host_t *vha)
6952 struct qla_hw_data *ha = vha->hw;
6954 /* If firmware needs to be loaded */
6955 if (qla2x00_isp_firmware(vha)) {
6956 vha->flags.online = 0;
6957 status = ha->isp_ops->chip_diag(vha);
6959 status = qla2x00_setup_chip(vha);
6962 if (!status && !(status = qla2x00_init_rings(vha))) {
6963 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6964 ha->flags.chip_reset_done = 1;
6966 /* Initialize the queues in use */
6967 qla25xx_init_queues(ha);
6969 status = qla2x00_fw_ready(vha);
6971 /* Issue a marker after FW becomes ready. */
6972 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
6973 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6976 /* if no cable then assume it's good */
6977 if ((vha->device_flags & DFLG_NO_CABLE))
6984 qla25xx_init_queues(struct qla_hw_data *ha)
6986 struct rsp_que *rsp = NULL;
6987 struct req_que *req = NULL;
6988 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6992 for (i = 1; i < ha->max_rsp_queues; i++) {
6993 rsp = ha->rsp_q_map[i];
6994 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6995 rsp->options &= ~BIT_0;
6996 ret = qla25xx_init_rsp_que(base_vha, rsp);
6997 if (ret != QLA_SUCCESS)
6998 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6999 "%s Rsp que: %d init failed.\n",
7002 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7003 "%s Rsp que: %d inited.\n",
7007 for (i = 1; i < ha->max_req_queues; i++) {
7008 req = ha->req_q_map[i];
7009 if (req && test_bit(i, ha->req_qid_map)) {
7010 /* Clear outstanding commands array. */
7011 req->options &= ~BIT_0;
7012 ret = qla25xx_init_req_que(base_vha, req);
7013 if (ret != QLA_SUCCESS)
7014 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7015 "%s Req que: %d init failed.\n",
7018 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7019 "%s Req que: %d inited.\n",
7027 * qla2x00_reset_adapter
7031 * ha = adapter block pointer.
7034 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7036 unsigned long flags = 0;
7037 struct qla_hw_data *ha = vha->hw;
7038 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7040 vha->flags.online = 0;
7041 ha->isp_ops->disable_intrs(ha);
7043 spin_lock_irqsave(&ha->hardware_lock, flags);
7044 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7045 RD_REG_WORD(®->hccr); /* PCI Posting. */
7046 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7047 RD_REG_WORD(®->hccr); /* PCI Posting. */
7048 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7054 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7056 unsigned long flags = 0;
7057 struct qla_hw_data *ha = vha->hw;
7058 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7059 int rval = QLA_SUCCESS;
7061 if (IS_P3P_TYPE(ha))
7064 vha->flags.online = 0;
7065 ha->isp_ops->disable_intrs(ha);
7067 spin_lock_irqsave(&ha->hardware_lock, flags);
7068 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7069 RD_REG_DWORD(®->hccr);
7070 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7071 RD_REG_DWORD(®->hccr);
7072 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7074 if (IS_NOPOLLING_TYPE(ha))
7075 ha->isp_ops->enable_intrs(ha);
7080 /* On sparc systems, obtain port and node WWN from firmware
7083 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7084 struct nvram_24xx *nv)
7087 struct qla_hw_data *ha = vha->hw;
7088 struct pci_dev *pdev = ha->pdev;
7089 struct device_node *dp = pci_device_to_OF_node(pdev);
7093 val = of_get_property(dp, "port-wwn", &len);
7094 if (val && len >= WWN_SIZE)
7095 memcpy(nv->port_name, val, WWN_SIZE);
7097 val = of_get_property(dp, "node-wwn", &len);
7098 if (val && len >= WWN_SIZE)
7099 memcpy(nv->node_name, val, WWN_SIZE);
7104 qla24xx_nvram_config(scsi_qla_host_t *vha)
7107 struct init_cb_24xx *icb;
7108 struct nvram_24xx *nv;
7110 uint8_t *dptr1, *dptr2;
7113 struct qla_hw_data *ha = vha->hw;
7116 icb = (struct init_cb_24xx *)ha->init_cb;
7119 /* Determine NVRAM starting address. */
7120 if (ha->port_no == 0) {
7121 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7122 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7124 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7125 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7128 ha->nvram_size = sizeof(*nv);
7129 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7131 /* Get VPD data into cache */
7132 ha->vpd = ha->nvram + VPD_OFFSET;
7133 ha->isp_ops->read_nvram(vha, ha->vpd,
7134 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7136 /* Get NVRAM data into cache and calculate checksum. */
7137 dptr = (uint32_t *)nv;
7138 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7139 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7140 chksum += le32_to_cpu(*dptr);
7142 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7143 "Contents of NVRAM\n");
7144 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7145 nv, ha->nvram_size);
7147 /* Bad NVRAM data, set defaults parameters. */
7148 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7149 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7150 /* Reset NVRAM data. */
7151 ql_log(ql_log_warn, vha, 0x006b,
7152 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7153 chksum, nv->id, nv->nvram_version);
7154 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7155 ql_log(ql_log_warn, vha, 0x006c,
7156 "Falling back to functioning (yet invalid -- WWPN) "
7160 * Set default initialization control block.
7162 memset(nv, 0, ha->nvram_size);
7163 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7164 nv->version = cpu_to_le16(ICB_VERSION);
7165 nv->frame_payload_size = 2048;
7166 nv->execution_throttle = cpu_to_le16(0xFFFF);
7167 nv->exchange_count = cpu_to_le16(0);
7168 nv->hard_address = cpu_to_le16(124);
7169 nv->port_name[0] = 0x21;
7170 nv->port_name[1] = 0x00 + ha->port_no + 1;
7171 nv->port_name[2] = 0x00;
7172 nv->port_name[3] = 0xe0;
7173 nv->port_name[4] = 0x8b;
7174 nv->port_name[5] = 0x1c;
7175 nv->port_name[6] = 0x55;
7176 nv->port_name[7] = 0x86;
7177 nv->node_name[0] = 0x20;
7178 nv->node_name[1] = 0x00;
7179 nv->node_name[2] = 0x00;
7180 nv->node_name[3] = 0xe0;
7181 nv->node_name[4] = 0x8b;
7182 nv->node_name[5] = 0x1c;
7183 nv->node_name[6] = 0x55;
7184 nv->node_name[7] = 0x86;
7185 qla24xx_nvram_wwn_from_ofw(vha, nv);
7186 nv->login_retry_count = cpu_to_le16(8);
7187 nv->interrupt_delay_timer = cpu_to_le16(0);
7188 nv->login_timeout = cpu_to_le16(0);
7189 nv->firmware_options_1 =
7190 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7191 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7192 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7193 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7194 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7195 nv->efi_parameters = cpu_to_le32(0);
7196 nv->reset_delay = 5;
7197 nv->max_luns_per_target = cpu_to_le16(128);
7198 nv->port_down_retry_count = cpu_to_le16(30);
7199 nv->link_down_timeout = cpu_to_le16(30);
7204 if (qla_tgt_mode_enabled(vha)) {
7205 /* Don't enable full login after initial LIP */
7206 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7207 /* Don't enable LIP full login for initiator */
7208 nv->host_p &= cpu_to_le32(~BIT_10);
7211 qlt_24xx_config_nvram_stage1(vha, nv);
7213 /* Reset Initialization control block */
7214 memset(icb, 0, ha->init_cb_size);
7216 /* Copy 1st segment. */
7217 dptr1 = (uint8_t *)icb;
7218 dptr2 = (uint8_t *)&nv->version;
7219 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7221 *dptr1++ = *dptr2++;
7223 icb->login_retry_count = nv->login_retry_count;
7224 icb->link_down_on_nos = nv->link_down_on_nos;
7226 /* Copy 2nd segment. */
7227 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7228 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7229 cnt = (uint8_t *)&icb->reserved_3 -
7230 (uint8_t *)&icb->interrupt_delay_timer;
7232 *dptr1++ = *dptr2++;
7233 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7235 * Setup driver NVRAM options.
7237 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7240 qlt_24xx_config_nvram_stage2(vha, icb);
7242 if (nv->host_p & cpu_to_le32(BIT_15)) {
7243 /* Use alternate WWN? */
7244 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7245 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7248 /* Prepare nodename */
7249 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7251 * Firmware will apply the following mask if the nodename was
7254 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7255 icb->node_name[0] &= 0xF0;
7258 /* Set host adapter parameters. */
7259 ha->flags.disable_risc_code_load = 0;
7260 ha->flags.enable_lip_reset = 0;
7261 ha->flags.enable_lip_full_login =
7262 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7263 ha->flags.enable_target_reset =
7264 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7265 ha->flags.enable_led_scheme = 0;
7266 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7268 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7269 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7271 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7272 sizeof(ha->fw_seriallink_options24));
7274 /* save HBA serial number */
7275 ha->serial0 = icb->port_name[5];
7276 ha->serial1 = icb->port_name[6];
7277 ha->serial2 = icb->port_name[7];
7278 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7279 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7281 icb->execution_throttle = cpu_to_le16(0xFFFF);
7283 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7285 /* Set minimum login_timeout to 4 seconds. */
7286 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7287 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7288 if (le16_to_cpu(nv->login_timeout) < 4)
7289 nv->login_timeout = cpu_to_le16(4);
7290 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7292 /* Set minimum RATOV to 100 tenths of a second. */
7295 ha->loop_reset_delay = nv->reset_delay;
7297 /* Link Down Timeout = 0:
7299 * When Port Down timer expires we will start returning
7300 * I/O's to OS with "DID_NO_CONNECT".
7302 * Link Down Timeout != 0:
7304 * The driver waits for the link to come up after link down
7305 * before returning I/Os to OS with "DID_NO_CONNECT".
7307 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7308 ha->loop_down_abort_time =
7309 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7311 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7312 ha->loop_down_abort_time =
7313 (LOOP_DOWN_TIME - ha->link_down_timeout);
7316 /* Need enough time to try and get the port back. */
7317 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7318 if (qlport_down_retry)
7319 ha->port_down_retry_count = qlport_down_retry;
7321 /* Set login_retry_count */
7322 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7323 if (ha->port_down_retry_count ==
7324 le16_to_cpu(nv->port_down_retry_count) &&
7325 ha->port_down_retry_count > 3)
7326 ha->login_retry_count = ha->port_down_retry_count;
7327 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7328 ha->login_retry_count = ha->port_down_retry_count;
7329 if (ql2xloginretrycount)
7330 ha->login_retry_count = ql2xloginretrycount;
7332 /* N2N: driver will initiate Login instead of FW */
7333 icb->firmware_options_3 |= BIT_8;
7336 if (!vha->flags.init_done) {
7337 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7338 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7339 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7340 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7342 icb->firmware_options_2 &= cpu_to_le32(
7343 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7344 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7345 ha->zio_mode = QLA_ZIO_MODE_6;
7347 ql_log(ql_log_info, vha, 0x006f,
7348 "ZIO mode %d enabled; timer delay (%d us).\n",
7349 ha->zio_mode, ha->zio_timer * 100);
7351 icb->firmware_options_2 |= cpu_to_le32(
7352 (uint32_t)ha->zio_mode);
7353 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7357 ql_log(ql_log_warn, vha, 0x0070,
7358 "NVRAM configuration failed.\n");
7364 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7365 struct qla27xx_image_status *image_status)
7367 ql_dbg(ql_dbg_init, vha, 0x018b,
7368 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7370 image_status->image_status_mask,
7371 le16_to_cpu(image_status->generation),
7372 image_status->ver_major,
7373 image_status->ver_minor,
7374 image_status->bitmap,
7375 le32_to_cpu(image_status->checksum),
7376 le32_to_cpu(image_status->signature));
7380 qla28xx_check_aux_image_status_signature(
7381 struct qla27xx_image_status *image_status)
7383 ulong signature = le32_to_cpu(image_status->signature);
7385 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7389 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7391 ulong signature = le32_to_cpu(image_status->signature);
7394 signature != QLA27XX_IMG_STATUS_SIGN &&
7395 signature != QLA28XX_IMG_STATUS_SIGN;
7399 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7401 uint32_t *p = (void *)image_status;
7402 uint n = sizeof(*image_status) / sizeof(*p);
7406 sum += le32_to_cpup(p);
7412 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7414 return aux->bitmap & bitmask ?
7415 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7419 qla28xx_component_status(
7420 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7422 active_regions->aux.board_config =
7423 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7425 active_regions->aux.vpd_nvram =
7426 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7428 active_regions->aux.npiv_config_0_1 =
7429 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7431 active_regions->aux.npiv_config_2_3 =
7432 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7436 qla27xx_compare_image_generation(
7437 struct qla27xx_image_status *pri_image_status,
7438 struct qla27xx_image_status *sec_image_status)
7440 /* calculate generation delta as uint16 (this accounts for wrap) */
7442 le16_to_cpu(pri_image_status->generation) -
7443 le16_to_cpu(sec_image_status->generation);
7445 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7451 qla28xx_get_aux_images(
7452 struct scsi_qla_host *vha, struct active_regions *active_regions)
7454 struct qla_hw_data *ha = vha->hw;
7455 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7456 bool valid_pri_image = false, valid_sec_image = false;
7457 bool active_pri_image = false, active_sec_image = false;
7459 if (!ha->flt_region_aux_img_status_pri) {
7460 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7461 goto check_sec_image;
7464 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7465 ha->flt_region_aux_img_status_pri,
7466 sizeof(pri_aux_image_status) >> 2);
7467 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7469 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7470 ql_dbg(ql_dbg_init, vha, 0x018b,
7471 "Primary aux image signature (%#x) not valid\n",
7472 le32_to_cpu(pri_aux_image_status.signature));
7473 goto check_sec_image;
7476 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7477 ql_dbg(ql_dbg_init, vha, 0x018c,
7478 "Primary aux image checksum failed\n");
7479 goto check_sec_image;
7482 valid_pri_image = true;
7484 if (pri_aux_image_status.image_status_mask & 1) {
7485 ql_dbg(ql_dbg_init, vha, 0x018d,
7486 "Primary aux image is active\n");
7487 active_pri_image = true;
7491 if (!ha->flt_region_aux_img_status_sec) {
7492 ql_dbg(ql_dbg_init, vha, 0x018a,
7493 "Secondary aux image not addressed\n");
7494 goto check_valid_image;
7497 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7498 ha->flt_region_aux_img_status_sec,
7499 sizeof(sec_aux_image_status) >> 2);
7500 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7502 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7503 ql_dbg(ql_dbg_init, vha, 0x018b,
7504 "Secondary aux image signature (%#x) not valid\n",
7505 le32_to_cpu(sec_aux_image_status.signature));
7506 goto check_valid_image;
7509 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7510 ql_dbg(ql_dbg_init, vha, 0x018c,
7511 "Secondary aux image checksum failed\n");
7512 goto check_valid_image;
7515 valid_sec_image = true;
7517 if (sec_aux_image_status.image_status_mask & 1) {
7518 ql_dbg(ql_dbg_init, vha, 0x018d,
7519 "Secondary aux image is active\n");
7520 active_sec_image = true;
7524 if (valid_pri_image && active_pri_image &&
7525 valid_sec_image && active_sec_image) {
7526 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7527 &sec_aux_image_status) >= 0) {
7528 qla28xx_component_status(active_regions,
7529 &pri_aux_image_status);
7531 qla28xx_component_status(active_regions,
7532 &sec_aux_image_status);
7534 } else if (valid_pri_image && active_pri_image) {
7535 qla28xx_component_status(active_regions, &pri_aux_image_status);
7536 } else if (valid_sec_image && active_sec_image) {
7537 qla28xx_component_status(active_regions, &sec_aux_image_status);
7540 ql_dbg(ql_dbg_init, vha, 0x018f,
7541 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7542 active_regions->aux.board_config,
7543 active_regions->aux.vpd_nvram,
7544 active_regions->aux.npiv_config_0_1,
7545 active_regions->aux.npiv_config_2_3);
7549 qla27xx_get_active_image(struct scsi_qla_host *vha,
7550 struct active_regions *active_regions)
7552 struct qla_hw_data *ha = vha->hw;
7553 struct qla27xx_image_status pri_image_status, sec_image_status;
7554 bool valid_pri_image = false, valid_sec_image = false;
7555 bool active_pri_image = false, active_sec_image = false;
7557 if (!ha->flt_region_img_status_pri) {
7558 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7559 goto check_sec_image;
7562 qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7563 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2);
7564 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7566 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7567 ql_dbg(ql_dbg_init, vha, 0x018b,
7568 "Primary image signature (%#x) not valid\n",
7569 le32_to_cpu(pri_image_status.signature));
7570 goto check_sec_image;
7573 if (qla27xx_image_status_checksum(&pri_image_status)) {
7574 ql_dbg(ql_dbg_init, vha, 0x018c,
7575 "Primary image checksum failed\n");
7576 goto check_sec_image;
7579 valid_pri_image = true;
7581 if (pri_image_status.image_status_mask & 1) {
7582 ql_dbg(ql_dbg_init, vha, 0x018d,
7583 "Primary image is active\n");
7584 active_pri_image = true;
7588 if (!ha->flt_region_img_status_sec) {
7589 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7590 goto check_valid_image;
7593 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7594 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7595 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7597 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7598 ql_dbg(ql_dbg_init, vha, 0x018b,
7599 "Secondary image signature (%#x) not valid\n",
7600 le32_to_cpu(sec_image_status.signature));
7601 goto check_valid_image;
7604 if (qla27xx_image_status_checksum(&sec_image_status)) {
7605 ql_dbg(ql_dbg_init, vha, 0x018c,
7606 "Secondary image checksum failed\n");
7607 goto check_valid_image;
7610 valid_sec_image = true;
7612 if (sec_image_status.image_status_mask & 1) {
7613 ql_dbg(ql_dbg_init, vha, 0x018d,
7614 "Secondary image is active\n");
7615 active_sec_image = true;
7619 if (valid_pri_image && active_pri_image)
7620 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7622 if (valid_sec_image && active_sec_image) {
7623 if (!active_regions->global ||
7624 qla27xx_compare_image_generation(
7625 &pri_image_status, &sec_image_status) < 0) {
7626 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7630 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7631 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7632 "default (boot/fw)" :
7633 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7635 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7636 "secondary" : "invalid",
7637 active_regions->global);
7640 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7643 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7644 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7648 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7652 uint templates, segments, fragment;
7657 uint32_t risc_addr, risc_size, risc_attr = 0;
7658 struct qla_hw_data *ha = vha->hw;
7659 struct req_que *req = ha->req_q_map[0];
7660 struct fwdt *fwdt = ha->fwdt;
7662 ql_dbg(ql_dbg_init, vha, 0x008b,
7663 "FW: Loading firmware from flash (%x).\n", faddr);
7665 dcode = (void *)req->ring;
7666 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7667 if (qla24xx_risc_firmware_invalid(dcode)) {
7668 ql_log(ql_log_fatal, vha, 0x008c,
7669 "Unable to verify the integrity of flash firmware "
7671 ql_log(ql_log_fatal, vha, 0x008d,
7672 "Firmware data: %08x %08x %08x %08x.\n",
7673 dcode[0], dcode[1], dcode[2], dcode[3]);
7675 return QLA_FUNCTION_FAILED;
7678 dcode = (void *)req->ring;
7680 segments = FA_RISC_CODE_SEGMENTS;
7681 for (j = 0; j < segments; j++) {
7682 ql_dbg(ql_dbg_init, vha, 0x008d,
7683 "-> Loading segment %u...\n", j);
7684 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7685 risc_addr = be32_to_cpu(dcode[2]);
7686 risc_size = be32_to_cpu(dcode[3]);
7688 *srisc_addr = risc_addr;
7689 risc_attr = be32_to_cpu(dcode[9]);
7692 dlen = ha->fw_transfer_size >> 2;
7693 for (fragment = 0; risc_size; fragment++) {
7694 if (dlen > risc_size)
7697 ql_dbg(ql_dbg_init, vha, 0x008e,
7698 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7699 fragment, risc_addr, faddr, dlen);
7700 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7701 for (i = 0; i < dlen; i++)
7702 dcode[i] = swab32(dcode[i]);
7704 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7706 ql_log(ql_log_fatal, vha, 0x008f,
7707 "-> Failed load firmware fragment %u.\n",
7709 return QLA_FUNCTION_FAILED;
7718 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7721 templates = (risc_attr & BIT_9) ? 2 : 1;
7722 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7723 for (j = 0; j < templates; j++, fwdt++) {
7725 vfree(fwdt->template);
7726 fwdt->template = NULL;
7729 dcode = (void *)req->ring;
7730 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7731 risc_size = be32_to_cpu(dcode[2]);
7732 ql_dbg(ql_dbg_init, vha, 0x0161,
7733 "-> fwdt%u template array at %#x (%#x dwords)\n",
7734 j, faddr, risc_size);
7735 if (!risc_size || !~risc_size) {
7736 ql_dbg(ql_dbg_init, vha, 0x0162,
7737 "-> fwdt%u failed to read array\n", j);
7741 /* skip header and ignore checksum */
7745 ql_dbg(ql_dbg_init, vha, 0x0163,
7746 "-> fwdt%u template allocate template %#x words...\n",
7748 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7749 if (!fwdt->template) {
7750 ql_log(ql_log_warn, vha, 0x0164,
7751 "-> fwdt%u failed allocate template.\n", j);
7755 dcode = fwdt->template;
7756 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7758 if (!qla27xx_fwdt_template_valid(dcode)) {
7759 ql_log(ql_log_warn, vha, 0x0165,
7760 "-> fwdt%u failed template validate\n", j);
7764 dlen = qla27xx_fwdt_template_size(dcode);
7765 ql_dbg(ql_dbg_init, vha, 0x0166,
7766 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7767 j, dlen, dlen / sizeof(*dcode));
7768 if (dlen > risc_size * sizeof(*dcode)) {
7769 ql_log(ql_log_warn, vha, 0x0167,
7770 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7771 j, dlen - risc_size * sizeof(*dcode));
7775 fwdt->length = dlen;
7776 ql_dbg(ql_dbg_init, vha, 0x0168,
7777 "-> fwdt%u loaded template ok\n", j);
7779 faddr += risc_size + 1;
7786 vfree(fwdt->template);
7787 fwdt->template = NULL;
7793 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7796 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7800 uint16_t *wcode, *fwcode;
7801 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7802 struct fw_blob *blob;
7803 struct qla_hw_data *ha = vha->hw;
7804 struct req_que *req = ha->req_q_map[0];
7806 /* Load firmware blob. */
7807 blob = qla2x00_request_firmware(vha);
7809 ql_log(ql_log_info, vha, 0x0083,
7810 "Firmware image unavailable.\n");
7811 ql_log(ql_log_info, vha, 0x0084,
7812 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7813 return QLA_FUNCTION_FAILED;
7818 wcode = (uint16_t *)req->ring;
7820 fwcode = (uint16_t *)blob->fw->data;
7823 /* Validate firmware image by checking version. */
7824 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7825 ql_log(ql_log_fatal, vha, 0x0085,
7826 "Unable to verify integrity of firmware image (%zd).\n",
7828 goto fail_fw_integrity;
7830 for (i = 0; i < 4; i++)
7831 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7832 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7833 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7834 wcode[2] == 0 && wcode[3] == 0)) {
7835 ql_log(ql_log_fatal, vha, 0x0086,
7836 "Unable to verify integrity of firmware image.\n");
7837 ql_log(ql_log_fatal, vha, 0x0087,
7838 "Firmware data: %04x %04x %04x %04x.\n",
7839 wcode[0], wcode[1], wcode[2], wcode[3]);
7840 goto fail_fw_integrity;
7844 while (*seg && rval == QLA_SUCCESS) {
7846 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7847 risc_size = be16_to_cpu(fwcode[3]);
7849 /* Validate firmware image size. */
7850 fwclen += risc_size * sizeof(uint16_t);
7851 if (blob->fw->size < fwclen) {
7852 ql_log(ql_log_fatal, vha, 0x0088,
7853 "Unable to verify integrity of firmware image "
7854 "(%zd).\n", blob->fw->size);
7855 goto fail_fw_integrity;
7859 while (risc_size > 0 && rval == QLA_SUCCESS) {
7860 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7861 if (wlen > risc_size)
7863 ql_dbg(ql_dbg_init, vha, 0x0089,
7864 "Loading risc segment@ risc addr %x number of "
7865 "words 0x%x.\n", risc_addr, wlen);
7867 for (i = 0; i < wlen; i++)
7868 wcode[i] = swab16(fwcode[i]);
7870 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7873 ql_log(ql_log_fatal, vha, 0x008a,
7874 "Failed to load segment %d of firmware.\n",
7891 return QLA_FUNCTION_FAILED;
7895 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7898 uint templates, segments, fragment;
7901 uint32_t risc_addr, risc_size, risc_attr = 0;
7904 struct fw_blob *blob;
7906 struct qla_hw_data *ha = vha->hw;
7907 struct req_que *req = ha->req_q_map[0];
7908 struct fwdt *fwdt = ha->fwdt;
7910 ql_dbg(ql_dbg_init, vha, 0x0090,
7911 "-> FW: Loading via request-firmware.\n");
7913 blob = qla2x00_request_firmware(vha);
7915 ql_log(ql_log_warn, vha, 0x0092,
7916 "-> Firmware file not found.\n");
7918 return QLA_FUNCTION_FAILED;
7921 fwcode = (void *)blob->fw->data;
7923 if (qla24xx_risc_firmware_invalid(dcode)) {
7924 ql_log(ql_log_fatal, vha, 0x0093,
7925 "Unable to verify integrity of firmware image (%zd).\n",
7927 ql_log(ql_log_fatal, vha, 0x0095,
7928 "Firmware data: %08x %08x %08x %08x.\n",
7929 dcode[0], dcode[1], dcode[2], dcode[3]);
7930 return QLA_FUNCTION_FAILED;
7933 dcode = (void *)req->ring;
7935 segments = FA_RISC_CODE_SEGMENTS;
7936 for (j = 0; j < segments; j++) {
7937 ql_dbg(ql_dbg_init, vha, 0x0096,
7938 "-> Loading segment %u...\n", j);
7939 risc_addr = be32_to_cpu(fwcode[2]);
7940 risc_size = be32_to_cpu(fwcode[3]);
7943 *srisc_addr = risc_addr;
7944 risc_attr = be32_to_cpu(fwcode[9]);
7947 dlen = ha->fw_transfer_size >> 2;
7948 for (fragment = 0; risc_size; fragment++) {
7949 if (dlen > risc_size)
7952 ql_dbg(ql_dbg_init, vha, 0x0097,
7953 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7954 fragment, risc_addr,
7955 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7958 for (i = 0; i < dlen; i++)
7959 dcode[i] = swab32(fwcode[i]);
7961 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7963 ql_log(ql_log_fatal, vha, 0x0098,
7964 "-> Failed load firmware fragment %u.\n",
7966 return QLA_FUNCTION_FAILED;
7975 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7978 templates = (risc_attr & BIT_9) ? 2 : 1;
7979 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
7980 for (j = 0; j < templates; j++, fwdt++) {
7982 vfree(fwdt->template);
7983 fwdt->template = NULL;
7986 risc_size = be32_to_cpu(fwcode[2]);
7987 ql_dbg(ql_dbg_init, vha, 0x0171,
7988 "-> fwdt%u template array at %#x (%#x dwords)\n",
7989 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
7991 if (!risc_size || !~risc_size) {
7992 ql_dbg(ql_dbg_init, vha, 0x0172,
7993 "-> fwdt%u failed to read array\n", j);
7997 /* skip header and ignore checksum */
8001 ql_dbg(ql_dbg_init, vha, 0x0173,
8002 "-> fwdt%u template allocate template %#x words...\n",
8004 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8005 if (!fwdt->template) {
8006 ql_log(ql_log_warn, vha, 0x0174,
8007 "-> fwdt%u failed allocate template.\n", j);
8011 dcode = fwdt->template;
8012 for (i = 0; i < risc_size; i++)
8013 dcode[i] = fwcode[i];
8015 if (!qla27xx_fwdt_template_valid(dcode)) {
8016 ql_log(ql_log_warn, vha, 0x0175,
8017 "-> fwdt%u failed template validate\n", j);
8021 dlen = qla27xx_fwdt_template_size(dcode);
8022 ql_dbg(ql_dbg_init, vha, 0x0176,
8023 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8024 j, dlen, dlen / sizeof(*dcode));
8025 if (dlen > risc_size * sizeof(*dcode)) {
8026 ql_log(ql_log_warn, vha, 0x0177,
8027 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8028 j, dlen - risc_size * sizeof(*dcode));
8032 fwdt->length = dlen;
8033 ql_dbg(ql_dbg_init, vha, 0x0178,
8034 "-> fwdt%u loaded template ok\n", j);
8036 fwcode += risc_size + 1;
8043 vfree(fwdt->template);
8044 fwdt->template = NULL;
8051 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8055 if (ql2xfwloadbin == 1)
8056 return qla81xx_load_risc(vha, srisc_addr);
8060 * 1) Firmware via request-firmware interface (.bin file).
8061 * 2) Firmware residing in flash.
8063 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8064 if (rval == QLA_SUCCESS)
8067 return qla24xx_load_risc_flash(vha, srisc_addr,
8068 vha->hw->flt_region_fw);
8072 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8075 struct qla_hw_data *ha = vha->hw;
8076 struct active_regions active_regions = { };
8078 if (ql2xfwloadbin == 2)
8081 /* FW Load priority:
8082 * 1) Firmware residing in flash.
8083 * 2) Firmware via request-firmware interface (.bin file).
8084 * 3) Golden-Firmware residing in flash -- (limited operation).
8087 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8088 goto try_primary_fw;
8090 qla27xx_get_active_image(vha, &active_regions);
8092 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8093 goto try_primary_fw;
8095 ql_dbg(ql_dbg_init, vha, 0x008b,
8096 "Loading secondary firmware image.\n");
8097 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8102 ql_dbg(ql_dbg_init, vha, 0x008b,
8103 "Loading primary firmware image.\n");
8104 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8109 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8110 if (!rval || !ha->flt_region_gold_fw)
8113 ql_log(ql_log_info, vha, 0x0099,
8114 "Attempting to fallback to golden firmware.\n");
8115 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8119 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8120 ha->flags.running_gold_fw = 1;
8125 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8128 struct qla_hw_data *ha = vha->hw;
8130 if (ha->flags.pci_channel_io_perm_failure)
8132 if (!IS_FWI2_CAPABLE(ha))
8134 if (!ha->fw_major_version)
8136 if (!ha->flags.fw_started)
8139 ret = qla2x00_stop_firmware(vha);
8140 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8141 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8142 ha->isp_ops->reset_chip(vha);
8143 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8145 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8147 ql_log(ql_log_info, vha, 0x8015,
8148 "Attempting retry of stop-firmware command.\n");
8149 ret = qla2x00_stop_firmware(vha);
8153 ha->flags.fw_init_done = 0;
8157 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8159 int rval = QLA_SUCCESS;
8161 uint16_t mb[MAILBOX_REGISTER_COUNT];
8162 struct qla_hw_data *ha = vha->hw;
8163 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8168 rval = qla2x00_fw_ready(base_vha);
8170 if (rval == QLA_SUCCESS) {
8171 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8172 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8175 vha->flags.management_server_logged_in = 0;
8177 /* Login to SNS first */
8178 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8180 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8181 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8182 ql_dbg(ql_dbg_init, vha, 0x0120,
8183 "Failed SNS login: loop_id=%x, rval2=%d\n",
8186 ql_dbg(ql_dbg_init, vha, 0x0103,
8187 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8188 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8189 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8190 return (QLA_FUNCTION_FAILED);
8193 atomic_set(&vha->loop_down_timer, 0);
8194 atomic_set(&vha->loop_state, LOOP_UP);
8195 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8196 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8197 rval = qla2x00_loop_resync(base_vha);
8202 /* 84XX Support **************************************************************/
8204 static LIST_HEAD(qla_cs84xx_list);
8205 static DEFINE_MUTEX(qla_cs84xx_mutex);
8207 static struct qla_chip_state_84xx *
8208 qla84xx_get_chip(struct scsi_qla_host *vha)
8210 struct qla_chip_state_84xx *cs84xx;
8211 struct qla_hw_data *ha = vha->hw;
8213 mutex_lock(&qla_cs84xx_mutex);
8215 /* Find any shared 84xx chip. */
8216 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8217 if (cs84xx->bus == ha->pdev->bus) {
8218 kref_get(&cs84xx->kref);
8223 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8227 kref_init(&cs84xx->kref);
8228 spin_lock_init(&cs84xx->access_lock);
8229 mutex_init(&cs84xx->fw_update_mutex);
8230 cs84xx->bus = ha->pdev->bus;
8232 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8234 mutex_unlock(&qla_cs84xx_mutex);
8239 __qla84xx_chip_release(struct kref *kref)
8241 struct qla_chip_state_84xx *cs84xx =
8242 container_of(kref, struct qla_chip_state_84xx, kref);
8244 mutex_lock(&qla_cs84xx_mutex);
8245 list_del(&cs84xx->list);
8246 mutex_unlock(&qla_cs84xx_mutex);
8251 qla84xx_put_chip(struct scsi_qla_host *vha)
8253 struct qla_hw_data *ha = vha->hw;
8256 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8260 qla84xx_init_chip(scsi_qla_host_t *vha)
8264 struct qla_hw_data *ha = vha->hw;
8266 mutex_lock(&ha->cs84xx->fw_update_mutex);
8268 rval = qla84xx_verify_chip(vha, status);
8270 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8272 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8276 /* 81XX Support **************************************************************/
8279 qla81xx_nvram_config(scsi_qla_host_t *vha)
8282 struct init_cb_81xx *icb;
8283 struct nvram_81xx *nv;
8285 uint8_t *dptr1, *dptr2;
8288 struct qla_hw_data *ha = vha->hw;
8290 struct active_regions active_regions = { };
8293 icb = (struct init_cb_81xx *)ha->init_cb;
8296 /* Determine NVRAM starting address. */
8297 ha->nvram_size = sizeof(*nv);
8298 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8299 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8300 ha->vpd_size = FA_VPD_SIZE_82XX;
8302 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8303 qla28xx_get_aux_images(vha, &active_regions);
8305 /* Get VPD data into cache */
8306 ha->vpd = ha->nvram + VPD_OFFSET;
8308 faddr = ha->flt_region_vpd;
8309 if (IS_QLA28XX(ha)) {
8310 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8311 faddr = ha->flt_region_vpd_sec;
8312 ql_dbg(ql_dbg_init, vha, 0x0110,
8313 "Loading %s nvram image.\n",
8314 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8315 "primary" : "secondary");
8317 qla24xx_read_flash_data(vha, ha->vpd, faddr, ha->vpd_size >> 2);
8319 /* Get NVRAM data into cache and calculate checksum. */
8320 faddr = ha->flt_region_nvram;
8321 if (IS_QLA28XX(ha)) {
8322 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8323 faddr = ha->flt_region_nvram_sec;
8325 ql_dbg(ql_dbg_init, vha, 0x0110,
8326 "Loading %s nvram image.\n",
8327 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8328 "primary" : "secondary");
8329 qla24xx_read_flash_data(vha, ha->nvram, faddr, ha->nvram_size >> 2);
8331 dptr = (uint32_t *)nv;
8332 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8333 chksum += le32_to_cpu(*dptr);
8335 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8336 "Contents of NVRAM:\n");
8337 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8338 nv, ha->nvram_size);
8340 /* Bad NVRAM data, set defaults parameters. */
8341 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8342 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8343 /* Reset NVRAM data. */
8344 ql_log(ql_log_info, vha, 0x0073,
8345 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8346 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8347 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8348 ql_log(ql_log_info, vha, 0x0074,
8349 "Falling back to functioning (yet invalid -- WWPN) "
8353 * Set default initialization control block.
8355 memset(nv, 0, ha->nvram_size);
8356 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8357 nv->version = cpu_to_le16(ICB_VERSION);
8358 nv->frame_payload_size = 2048;
8359 nv->execution_throttle = cpu_to_le16(0xFFFF);
8360 nv->exchange_count = cpu_to_le16(0);
8361 nv->port_name[0] = 0x21;
8362 nv->port_name[1] = 0x00 + ha->port_no + 1;
8363 nv->port_name[2] = 0x00;
8364 nv->port_name[3] = 0xe0;
8365 nv->port_name[4] = 0x8b;
8366 nv->port_name[5] = 0x1c;
8367 nv->port_name[6] = 0x55;
8368 nv->port_name[7] = 0x86;
8369 nv->node_name[0] = 0x20;
8370 nv->node_name[1] = 0x00;
8371 nv->node_name[2] = 0x00;
8372 nv->node_name[3] = 0xe0;
8373 nv->node_name[4] = 0x8b;
8374 nv->node_name[5] = 0x1c;
8375 nv->node_name[6] = 0x55;
8376 nv->node_name[7] = 0x86;
8377 nv->login_retry_count = cpu_to_le16(8);
8378 nv->interrupt_delay_timer = cpu_to_le16(0);
8379 nv->login_timeout = cpu_to_le16(0);
8380 nv->firmware_options_1 =
8381 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8382 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8383 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8384 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8385 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8386 nv->efi_parameters = cpu_to_le32(0);
8387 nv->reset_delay = 5;
8388 nv->max_luns_per_target = cpu_to_le16(128);
8389 nv->port_down_retry_count = cpu_to_le16(30);
8390 nv->link_down_timeout = cpu_to_le16(180);
8391 nv->enode_mac[0] = 0x00;
8392 nv->enode_mac[1] = 0xC0;
8393 nv->enode_mac[2] = 0xDD;
8394 nv->enode_mac[3] = 0x04;
8395 nv->enode_mac[4] = 0x05;
8396 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8401 if (IS_T10_PI_CAPABLE(ha))
8402 nv->frame_payload_size &= ~7;
8404 qlt_81xx_config_nvram_stage1(vha, nv);
8406 /* Reset Initialization control block */
8407 memset(icb, 0, ha->init_cb_size);
8409 /* Copy 1st segment. */
8410 dptr1 = (uint8_t *)icb;
8411 dptr2 = (uint8_t *)&nv->version;
8412 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8414 *dptr1++ = *dptr2++;
8416 icb->login_retry_count = nv->login_retry_count;
8418 /* Copy 2nd segment. */
8419 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8420 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8421 cnt = (uint8_t *)&icb->reserved_5 -
8422 (uint8_t *)&icb->interrupt_delay_timer;
8424 *dptr1++ = *dptr2++;
8426 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8427 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8428 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8429 icb->enode_mac[0] = 0x00;
8430 icb->enode_mac[1] = 0xC0;
8431 icb->enode_mac[2] = 0xDD;
8432 icb->enode_mac[3] = 0x04;
8433 icb->enode_mac[4] = 0x05;
8434 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8437 /* Use extended-initialization control block. */
8438 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8439 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8441 * Setup driver NVRAM options.
8443 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8446 qlt_81xx_config_nvram_stage2(vha, icb);
8448 /* Use alternate WWN? */
8449 if (nv->host_p & cpu_to_le32(BIT_15)) {
8450 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8451 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8454 /* Prepare nodename */
8455 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8457 * Firmware will apply the following mask if the nodename was
8460 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8461 icb->node_name[0] &= 0xF0;
8464 /* Set host adapter parameters. */
8465 ha->flags.disable_risc_code_load = 0;
8466 ha->flags.enable_lip_reset = 0;
8467 ha->flags.enable_lip_full_login =
8468 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8469 ha->flags.enable_target_reset =
8470 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8471 ha->flags.enable_led_scheme = 0;
8472 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8474 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8475 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8477 /* save HBA serial number */
8478 ha->serial0 = icb->port_name[5];
8479 ha->serial1 = icb->port_name[6];
8480 ha->serial2 = icb->port_name[7];
8481 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8482 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8484 icb->execution_throttle = cpu_to_le16(0xFFFF);
8486 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8488 /* Set minimum login_timeout to 4 seconds. */
8489 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8490 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8491 if (le16_to_cpu(nv->login_timeout) < 4)
8492 nv->login_timeout = cpu_to_le16(4);
8493 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8495 /* Set minimum RATOV to 100 tenths of a second. */
8498 ha->loop_reset_delay = nv->reset_delay;
8500 /* Link Down Timeout = 0:
8502 * When Port Down timer expires we will start returning
8503 * I/O's to OS with "DID_NO_CONNECT".
8505 * Link Down Timeout != 0:
8507 * The driver waits for the link to come up after link down
8508 * before returning I/Os to OS with "DID_NO_CONNECT".
8510 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8511 ha->loop_down_abort_time =
8512 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8514 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8515 ha->loop_down_abort_time =
8516 (LOOP_DOWN_TIME - ha->link_down_timeout);
8519 /* Need enough time to try and get the port back. */
8520 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8521 if (qlport_down_retry)
8522 ha->port_down_retry_count = qlport_down_retry;
8524 /* Set login_retry_count */
8525 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8526 if (ha->port_down_retry_count ==
8527 le16_to_cpu(nv->port_down_retry_count) &&
8528 ha->port_down_retry_count > 3)
8529 ha->login_retry_count = ha->port_down_retry_count;
8530 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8531 ha->login_retry_count = ha->port_down_retry_count;
8532 if (ql2xloginretrycount)
8533 ha->login_retry_count = ql2xloginretrycount;
8535 /* if not running MSI-X we need handshaking on interrupts */
8536 if (!vha->hw->flags.msix_enabled &&
8537 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8538 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8541 if (!vha->flags.init_done) {
8542 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8543 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8544 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8545 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8547 icb->firmware_options_2 &= cpu_to_le32(
8548 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8549 vha->flags.process_response_queue = 0;
8550 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8551 ha->zio_mode = QLA_ZIO_MODE_6;
8553 ql_log(ql_log_info, vha, 0x0075,
8554 "ZIO mode %d enabled; timer delay (%d us).\n",
8556 ha->zio_timer * 100);
8558 icb->firmware_options_2 |= cpu_to_le32(
8559 (uint32_t)ha->zio_mode);
8560 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8561 vha->flags.process_response_queue = 1;
8564 /* enable RIDA Format2 */
8565 icb->firmware_options_3 |= BIT_0;
8567 /* N2N: driver will initiate Login instead of FW */
8568 icb->firmware_options_3 |= BIT_8;
8571 ql_log(ql_log_warn, vha, 0x0076,
8572 "NVRAM configuration failed.\n");
8578 qla82xx_restart_isp(scsi_qla_host_t *vha)
8581 struct qla_hw_data *ha = vha->hw;
8582 struct scsi_qla_host *vp;
8583 unsigned long flags;
8585 status = qla2x00_init_rings(vha);
8587 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8588 ha->flags.chip_reset_done = 1;
8590 status = qla2x00_fw_ready(vha);
8592 /* Issue a marker after FW becomes ready. */
8593 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8594 vha->flags.online = 1;
8595 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8598 /* if no cable then assume it's good */
8599 if ((vha->device_flags & DFLG_NO_CABLE))
8604 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8606 if (!atomic_read(&vha->loop_down_timer)) {
8608 * Issue marker command only when we are going
8609 * to start the I/O .
8611 vha->marker_needed = 1;
8614 ha->isp_ops->enable_intrs(ha);
8616 ha->isp_abort_cnt = 0;
8617 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8619 /* Update the firmware version */
8620 status = qla82xx_check_md_needed(vha);
8623 ha->flags.fce_enabled = 1;
8625 fce_calc_size(ha->fce_bufs));
8626 rval = qla2x00_enable_fce_trace(vha,
8627 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8630 ql_log(ql_log_warn, vha, 0x8001,
8631 "Unable to reinitialize FCE (%d).\n",
8633 ha->flags.fce_enabled = 0;
8638 memset(ha->eft, 0, EFT_SIZE);
8639 rval = qla2x00_enable_eft_trace(vha,
8640 ha->eft_dma, EFT_NUM_BUFFERS);
8642 ql_log(ql_log_warn, vha, 0x8010,
8643 "Unable to reinitialize EFT (%d).\n",
8650 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8651 "qla82xx_restart_isp succeeded.\n");
8653 spin_lock_irqsave(&ha->vport_slock, flags);
8654 list_for_each_entry(vp, &ha->vp_list, list) {
8656 atomic_inc(&vp->vref_count);
8657 spin_unlock_irqrestore(&ha->vport_slock, flags);
8659 qla2x00_vp_abort_isp(vp);
8661 spin_lock_irqsave(&ha->vport_slock, flags);
8662 atomic_dec(&vp->vref_count);
8665 spin_unlock_irqrestore(&ha->vport_slock, flags);
8668 ql_log(ql_log_warn, vha, 0x8016,
8669 "qla82xx_restart_isp **** FAILED ****.\n");
8676 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8678 struct qla_hw_data *ha = vha->hw;
8680 /* Hold status IOCBs until ABTS response received. */
8682 ha->fw_options[3] |= BIT_12;
8684 /* Set Retry FLOGI in case of P2P connection */
8685 if (ha->operating_mode == P2P) {
8686 ha->fw_options[2] |= BIT_3;
8687 ql_dbg(ql_dbg_disc, vha, 0x2103,
8688 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8689 __func__, ha->fw_options[2]);
8692 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8693 if (ql2xmvasynctoatio) {
8694 if (qla_tgt_mode_enabled(vha) ||
8695 qla_dual_mode_enabled(vha))
8696 ha->fw_options[2] |= BIT_11;
8698 ha->fw_options[2] &= ~BIT_11;
8701 if (qla_tgt_mode_enabled(vha) ||
8702 qla_dual_mode_enabled(vha)) {
8703 /* FW auto send SCSI status during */
8704 ha->fw_options[1] |= BIT_8;
8705 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8707 /* FW perform Exchange validation */
8708 ha->fw_options[2] |= BIT_4;
8710 ha->fw_options[1] &= ~BIT_8;
8711 ha->fw_options[10] &= 0x00ff;
8713 ha->fw_options[2] &= ~BIT_4;
8716 if (ql2xetsenable) {
8717 /* Enable ETS Burst. */
8718 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8719 ha->fw_options[2] |= BIT_9;
8722 ql_dbg(ql_dbg_init, vha, 0x00e9,
8723 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8724 __func__, ha->fw_options[1], ha->fw_options[2],
8725 ha->fw_options[3], vha->host->active_mode);
8727 qla2x00_set_fw_options(vha, ha->fw_options);
8731 * qla24xx_get_fcp_prio
8732 * Gets the fcp cmd priority value for the logged in port.
8733 * Looks for a match of the port descriptors within
8734 * each of the fcp prio config entries. If a match is found,
8735 * the tag (priority) value is returned.
8738 * vha = scsi host structure pointer.
8739 * fcport = port structure pointer.
8742 * non-zero (if found)
8749 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8752 uint8_t pid_match, wwn_match;
8754 uint32_t pid1, pid2;
8755 uint64_t wwn1, wwn2;
8756 struct qla_fcp_prio_entry *pri_entry;
8757 struct qla_hw_data *ha = vha->hw;
8759 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8763 entries = ha->fcp_prio_cfg->num_entries;
8764 pri_entry = &ha->fcp_prio_cfg->entry[0];
8766 for (i = 0; i < entries; i++) {
8767 pid_match = wwn_match = 0;
8769 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8774 /* check source pid for a match */
8775 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8776 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8777 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8778 if (pid1 == INVALID_PORT_ID)
8780 else if (pid1 == pid2)
8784 /* check destination pid for a match */
8785 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8786 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8787 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8788 if (pid1 == INVALID_PORT_ID)
8790 else if (pid1 == pid2)
8794 /* check source WWN for a match */
8795 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8796 wwn1 = wwn_to_u64(vha->port_name);
8797 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8798 if (wwn2 == (uint64_t)-1)
8800 else if (wwn1 == wwn2)
8804 /* check destination WWN for a match */
8805 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8806 wwn1 = wwn_to_u64(fcport->port_name);
8807 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8808 if (wwn2 == (uint64_t)-1)
8810 else if (wwn1 == wwn2)
8814 if (pid_match == 2 || wwn_match == 2) {
8815 /* Found a matching entry */
8816 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8817 priority = pri_entry->tag;
8828 * qla24xx_update_fcport_fcp_prio
8829 * Activates fcp priority for the logged in fc port
8832 * vha = scsi host structure pointer.
8833 * fcp = port structure pointer.
8836 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8842 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8848 if (fcport->port_type != FCT_TARGET ||
8849 fcport->loop_id == FC_NO_LOOP_ID)
8850 return QLA_FUNCTION_FAILED;
8852 priority = qla24xx_get_fcp_prio(vha, fcport);
8854 return QLA_FUNCTION_FAILED;
8856 if (IS_P3P_TYPE(vha->hw)) {
8857 fcport->fcp_prio = priority & 0xf;
8861 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8862 if (ret == QLA_SUCCESS) {
8863 if (fcport->fcp_prio != priority)
8864 ql_dbg(ql_dbg_user, vha, 0x709e,
8865 "Updated FCP_CMND priority - value=%d loop_id=%d "
8866 "port_id=%02x%02x%02x.\n", priority,
8867 fcport->loop_id, fcport->d_id.b.domain,
8868 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8869 fcport->fcp_prio = priority & 0xf;
8871 ql_dbg(ql_dbg_user, vha, 0x704f,
8872 "Unable to update FCP_CMND priority - ret=0x%x for "
8873 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8874 fcport->d_id.b.domain, fcport->d_id.b.area,
8875 fcport->d_id.b.al_pa);
8880 * qla24xx_update_all_fcp_prio
8881 * Activates fcp priority for all the logged in ports
8884 * ha = adapter block pointer.
8887 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8893 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8898 ret = QLA_FUNCTION_FAILED;
8899 /* We need to set priority for all logged in ports */
8900 list_for_each_entry(fcport, &vha->vp_fcports, list)
8901 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8906 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8907 int vp_idx, bool startqp)
8912 struct qla_hw_data *ha = vha->hw;
8913 uint16_t qpair_id = 0;
8914 struct qla_qpair *qpair = NULL;
8915 struct qla_msix_entry *msix;
8917 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8918 ql_log(ql_log_warn, vha, 0x00181,
8919 "FW/Driver is not multi-queue capable.\n");
8923 if (ql2xmqsupport || ql2xnvmeenable) {
8924 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8925 if (qpair == NULL) {
8926 ql_log(ql_log_warn, vha, 0x0182,
8927 "Failed to allocate memory for queue pair.\n");
8931 qpair->hw = vha->hw;
8933 qpair->qp_lock_ptr = &qpair->qp_lock;
8934 spin_lock_init(&qpair->qp_lock);
8935 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8937 /* Assign available que pair id */
8938 mutex_lock(&ha->mq_lock);
8939 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8940 if (ha->num_qpairs >= ha->max_qpairs) {
8941 mutex_unlock(&ha->mq_lock);
8942 ql_log(ql_log_warn, vha, 0x0183,
8943 "No resources to create additional q pair.\n");
8947 set_bit(qpair_id, ha->qpair_qid_map);
8948 ha->queue_pair_map[qpair_id] = qpair;
8949 qpair->id = qpair_id;
8950 qpair->vp_idx = vp_idx;
8951 qpair->fw_started = ha->flags.fw_started;
8952 INIT_LIST_HEAD(&qpair->hints_list);
8953 qpair->chip_reset = ha->base_qpair->chip_reset;
8954 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8955 qpair->enable_explicit_conf =
8956 ha->base_qpair->enable_explicit_conf;
8958 for (i = 0; i < ha->msix_count; i++) {
8959 msix = &ha->msix_entries[i];
8963 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8964 "Vector %x selected for qpair\n", msix->vector);
8968 ql_log(ql_log_warn, vha, 0x0184,
8969 "Out of MSI-X vectors!.\n");
8973 qpair->msix->in_use = 1;
8974 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8975 qpair->pdev = ha->pdev;
8976 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
8977 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8979 mutex_unlock(&ha->mq_lock);
8981 /* Create response queue first */
8982 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8984 ql_log(ql_log_warn, vha, 0x0185,
8985 "Failed to create response queue.\n");
8989 qpair->rsp = ha->rsp_q_map[rsp_id];
8991 /* Create request queue */
8992 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8995 ql_log(ql_log_warn, vha, 0x0186,
8996 "Failed to create request queue.\n");
9000 qpair->req = ha->req_q_map[req_id];
9001 qpair->rsp->req = qpair->req;
9002 qpair->rsp->qpair = qpair;
9003 /* init qpair to this cpu. Will adjust at run time. */
9004 qla_cpu_update(qpair, smp_processor_id());
9006 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9007 if (ha->fw_attributes & BIT_4)
9008 qpair->difdix_supported = 1;
9011 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9012 if (!qpair->srb_mempool) {
9013 ql_log(ql_log_warn, vha, 0xd036,
9014 "Failed to create srb mempool for qpair %d\n",
9019 /* Mark as online */
9022 if (!vha->flags.qpairs_available)
9023 vha->flags.qpairs_available = 1;
9025 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9026 "Request/Response queue pair created, id %d\n",
9028 ql_dbg(ql_dbg_init, vha, 0x0187,
9029 "Request/Response queue pair created, id %d\n",
9036 qla25xx_delete_rsp_que(vha, qpair->rsp);
9038 mutex_lock(&ha->mq_lock);
9039 qpair->msix->in_use = 0;
9040 list_del(&qpair->qp_list_elem);
9041 if (list_empty(&vha->qp_list))
9042 vha->flags.qpairs_available = 0;
9044 ha->queue_pair_map[qpair_id] = NULL;
9045 clear_bit(qpair_id, ha->qpair_qid_map);
9047 mutex_unlock(&ha->mq_lock);
9053 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9055 int ret = QLA_FUNCTION_FAILED;
9056 struct qla_hw_data *ha = qpair->hw;
9058 qpair->delete_in_progress = 1;
9059 while (atomic_read(&qpair->ref_count))
9062 ret = qla25xx_delete_req_que(vha, qpair->req);
9063 if (ret != QLA_SUCCESS)
9066 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9067 if (ret != QLA_SUCCESS)
9070 mutex_lock(&ha->mq_lock);
9071 ha->queue_pair_map[qpair->id] = NULL;
9072 clear_bit(qpair->id, ha->qpair_qid_map);
9074 list_del(&qpair->qp_list_elem);
9075 if (list_empty(&vha->qp_list)) {
9076 vha->flags.qpairs_available = 0;
9077 vha->flags.qpairs_req_created = 0;
9078 vha->flags.qpairs_rsp_created = 0;
9080 mempool_destroy(qpair->srb_mempool);
9082 mutex_unlock(&ha->mq_lock);