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;
103 abt->u.abt.comp_status = CS_TIMEOUT;
104 sp->done(sp, QLA_FUNCTION_TIMEOUT);
107 static void qla24xx_abort_sp_done(void *ptr, int res)
110 struct srb_iocb *abt = &sp->u.iocb_cmd;
112 if (del_timer(&sp->u.iocb_cmd.timer)) {
113 if (sp->flags & SRB_WAKEUP_ON_COMP)
114 complete(&abt->u.abt.comp);
120 static int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
122 scsi_qla_host_t *vha = cmd_sp->vha;
123 struct srb_iocb *abt_iocb;
125 int rval = QLA_FUNCTION_FAILED;
127 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
132 abt_iocb = &sp->u.iocb_cmd;
133 sp->type = SRB_ABT_CMD;
135 sp->qpair = cmd_sp->qpair;
137 sp->flags = SRB_WAKEUP_ON_COMP;
139 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
140 init_completion(&abt_iocb->u.abt.comp);
141 /* FW can send 2 x ABTS's timeout/20s */
142 qla2x00_init_timer(sp, 42);
144 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
145 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
147 sp->done = qla24xx_abort_sp_done;
149 ql_dbg(ql_dbg_async, vha, 0x507c,
150 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
153 rval = qla2x00_start_sp(sp);
154 if (rval != QLA_SUCCESS)
158 wait_for_completion(&abt_iocb->u.abt.comp);
159 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
160 QLA_SUCCESS : QLA_FUNCTION_FAILED;
172 qla2x00_async_iocb_timeout(void *data)
175 fc_port_t *fcport = sp->fcport;
176 struct srb_iocb *lio = &sp->u.iocb_cmd;
181 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
182 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
183 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
185 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
187 pr_info("Async-%s timeout - hdl=%x.\n",
188 sp->name, sp->handle);
193 rc = qla24xx_async_abort_cmd(sp, false);
195 /* Retry as needed. */
196 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
197 lio->u.logio.data[1] =
198 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
199 QLA_LOGIO_LOGIN_RETRIED : 0;
200 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
201 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
203 if (sp->qpair->req->outstanding_cmds[h] ==
205 sp->qpair->req->outstanding_cmds[h] =
210 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
211 sp->done(sp, QLA_FUNCTION_TIMEOUT);
215 case SRB_CT_PTHRU_CMD:
221 rc = qla24xx_async_abort_cmd(sp, false);
223 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
224 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
226 if (sp->qpair->req->outstanding_cmds[h] ==
228 sp->qpair->req->outstanding_cmds[h] =
233 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
234 sp->done(sp, QLA_FUNCTION_TIMEOUT);
241 qla2x00_async_login_sp_done(void *ptr, int res)
244 struct scsi_qla_host *vha = sp->vha;
245 struct srb_iocb *lio = &sp->u.iocb_cmd;
248 ql_dbg(ql_dbg_disc, vha, 0x20dd,
249 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
251 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
253 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
254 memset(&ea, 0, sizeof(ea));
255 ea.event = FCME_PLOGI_DONE;
256 ea.fcport = sp->fcport;
257 ea.data[0] = lio->u.logio.data[0];
258 ea.data[1] = lio->u.logio.data[1];
259 ea.iop[0] = lio->u.logio.iop[0];
260 ea.iop[1] = lio->u.logio.iop[1];
262 qla2x00_fcport_event_handler(vha, &ea);
269 fcport_is_smaller(fc_port_t *fcport)
271 if (wwn_to_u64(fcport->port_name) <
272 wwn_to_u64(fcport->vha->port_name))
279 fcport_is_bigger(fc_port_t *fcport)
281 return !fcport_is_smaller(fcport);
285 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
289 struct srb_iocb *lio;
290 int rval = QLA_FUNCTION_FAILED;
292 if (!vha->flags.online)
295 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
299 fcport->flags |= FCF_ASYNC_SENT;
300 fcport->logout_completed = 0;
302 fcport->disc_state = DSC_LOGIN_PEND;
303 sp->type = SRB_LOGIN_CMD;
305 sp->gen1 = fcport->rscn_gen;
306 sp->gen2 = fcport->login_gen;
308 lio = &sp->u.iocb_cmd;
309 lio->timeout = qla2x00_async_iocb_timeout;
310 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
312 sp->done = qla2x00_async_login_sp_done;
313 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
314 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
316 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
318 if (fcport->fc4f_nvme)
319 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
321 ql_dbg(ql_dbg_disc, vha, 0x2072,
322 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
323 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
324 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
325 fcport->login_retry);
327 rval = qla2x00_start_sp(sp);
328 if (rval != QLA_SUCCESS) {
329 fcport->flags |= FCF_LOGIN_NEEDED;
330 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
338 fcport->flags &= ~FCF_ASYNC_SENT;
340 fcport->flags &= ~FCF_ASYNC_ACTIVE;
345 qla2x00_async_logout_sp_done(void *ptr, int res)
349 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
350 sp->fcport->login_gen++;
351 qlt_logo_completion_handler(sp->fcport, res);
356 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
359 struct srb_iocb *lio;
360 int rval = QLA_FUNCTION_FAILED;
362 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
365 fcport->flags |= FCF_ASYNC_SENT;
366 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
370 sp->type = SRB_LOGOUT_CMD;
373 lio = &sp->u.iocb_cmd;
374 lio->timeout = qla2x00_async_iocb_timeout;
375 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
377 sp->done = qla2x00_async_logout_sp_done;
379 ql_dbg(ql_dbg_disc, vha, 0x2070,
380 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
381 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
382 fcport->d_id.b.area, fcport->d_id.b.al_pa,
385 rval = qla2x00_start_sp(sp);
386 if (rval != QLA_SUCCESS)
393 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
398 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
401 fcport->flags &= ~FCF_ASYNC_ACTIVE;
402 /* Don't re-login in target mode */
403 if (!fcport->tgt_session)
404 qla2x00_mark_device_lost(vha, fcport, 1, 0);
405 qlt_logo_completion_handler(fcport, data[0]);
409 qla2x00_async_prlo_sp_done(void *s, int res)
411 srb_t *sp = (srb_t *)s;
412 struct srb_iocb *lio = &sp->u.iocb_cmd;
413 struct scsi_qla_host *vha = sp->vha;
415 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
416 if (!test_bit(UNLOADING, &vha->dpc_flags))
417 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
423 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
426 struct srb_iocb *lio;
429 rval = QLA_FUNCTION_FAILED;
430 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
434 sp->type = SRB_PRLO_CMD;
437 lio = &sp->u.iocb_cmd;
438 lio->timeout = qla2x00_async_iocb_timeout;
439 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
441 sp->done = qla2x00_async_prlo_sp_done;
443 ql_dbg(ql_dbg_disc, vha, 0x2070,
444 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
445 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
446 fcport->d_id.b.area, fcport->d_id.b.al_pa);
448 rval = qla2x00_start_sp(sp);
449 if (rval != QLA_SUCCESS)
457 fcport->flags &= ~FCF_ASYNC_ACTIVE;
462 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
464 struct fc_port *fcport = ea->fcport;
466 ql_dbg(ql_dbg_disc, vha, 0x20d2,
467 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
468 __func__, fcport->port_name, fcport->disc_state,
469 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
470 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
472 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
473 ql_dbg(ql_dbg_disc, vha, 0x2066,
474 "%s %8phC: adisc fail: post delete\n",
475 __func__, ea->fcport->port_name);
476 /* deleted = 0 & logout_on_delete = force fw cleanup */
478 fcport->logout_on_delete = 1;
479 qlt_schedule_sess_for_deletion(ea->fcport);
483 if (ea->fcport->disc_state == DSC_DELETE_PEND)
486 if (ea->sp->gen2 != ea->fcport->login_gen) {
487 /* target side must have changed it. */
488 ql_dbg(ql_dbg_disc, vha, 0x20d3,
489 "%s %8phC generation changed\n",
490 __func__, ea->fcport->port_name);
492 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
493 qla_rscn_replay(fcport);
494 qlt_schedule_sess_for_deletion(fcport);
498 __qla24xx_handle_gpdb_event(vha, ea);
501 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
503 struct qla_work_evt *e;
505 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
507 return QLA_FUNCTION_FAILED;
509 e->u.fcport.fcport = fcport;
510 fcport->flags |= FCF_ASYNC_ACTIVE;
511 return qla2x00_post_work(vha, e);
515 qla2x00_async_adisc_sp_done(void *ptr, int res)
518 struct scsi_qla_host *vha = sp->vha;
520 struct srb_iocb *lio = &sp->u.iocb_cmd;
522 ql_dbg(ql_dbg_disc, vha, 0x2066,
523 "Async done-%s res %x %8phC\n",
524 sp->name, res, sp->fcport->port_name);
526 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
528 memset(&ea, 0, sizeof(ea));
529 ea.event = FCME_ADISC_DONE;
531 ea.data[0] = lio->u.logio.data[0];
532 ea.data[1] = lio->u.logio.data[1];
533 ea.iop[0] = lio->u.logio.iop[0];
534 ea.iop[1] = lio->u.logio.iop[1];
535 ea.fcport = sp->fcport;
538 qla2x00_fcport_event_handler(vha, &ea);
544 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
548 struct srb_iocb *lio;
549 int rval = QLA_FUNCTION_FAILED;
551 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
554 fcport->flags |= FCF_ASYNC_SENT;
555 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
559 sp->type = SRB_ADISC_CMD;
562 lio = &sp->u.iocb_cmd;
563 lio->timeout = qla2x00_async_iocb_timeout;
564 sp->gen1 = fcport->rscn_gen;
565 sp->gen2 = fcport->login_gen;
566 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
568 sp->done = qla2x00_async_adisc_sp_done;
569 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
570 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
572 ql_dbg(ql_dbg_disc, vha, 0x206f,
573 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
574 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
576 rval = qla2x00_start_sp(sp);
577 if (rval != QLA_SUCCESS)
585 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
586 qla2x00_post_async_adisc_work(vha, fcport, data);
590 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
592 struct qla_hw_data *ha = vha->hw;
594 if (IS_FWI2_CAPABLE(ha))
595 return loop_id > NPH_LAST_HANDLE;
597 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
598 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
602 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
603 * @vha: adapter state pointer.
604 * @dev: port structure pointer.
607 * qla2x00 local function return status code.
612 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
615 struct qla_hw_data *ha = vha->hw;
616 unsigned long flags = 0;
620 spin_lock_irqsave(&ha->vport_slock, flags);
622 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
623 if (dev->loop_id >= LOOPID_MAP_SIZE ||
624 qla2x00_is_reserved_id(vha, dev->loop_id)) {
625 dev->loop_id = FC_NO_LOOP_ID;
626 rval = QLA_FUNCTION_FAILED;
628 set_bit(dev->loop_id, ha->loop_id_map);
630 spin_unlock_irqrestore(&ha->vport_slock, flags);
632 if (rval == QLA_SUCCESS)
633 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
634 "Assigning new loopid=%x, portid=%x.\n",
635 dev->loop_id, dev->d_id.b24);
637 ql_log(ql_log_warn, dev->vha, 0x2087,
638 "No loop_id's available, portid=%x.\n",
644 void qla2x00_clear_loop_id(fc_port_t *fcport)
646 struct qla_hw_data *ha = fcport->vha->hw;
648 if (fcport->loop_id == FC_NO_LOOP_ID ||
649 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
652 clear_bit(fcport->loop_id, ha->loop_id_map);
653 fcport->loop_id = FC_NO_LOOP_ID;
656 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
657 struct event_arg *ea)
659 fc_port_t *fcport, *conflict_fcport;
660 struct get_name_list_extended *e;
661 u16 i, n, found = 0, loop_id;
665 u8 current_login_state;
668 ql_dbg(ql_dbg_disc, vha, 0xffff,
669 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
670 __func__, fcport->port_name, fcport->disc_state,
671 fcport->fw_login_state, ea->rc,
672 fcport->login_gen, fcport->last_login_gen,
673 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
675 if (fcport->disc_state == DSC_DELETE_PEND)
678 if (ea->rc) { /* rval */
679 if (fcport->login_retry == 0) {
680 ql_dbg(ql_dbg_disc, vha, 0x20de,
681 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
682 fcport->port_name, fcport->login_retry);
687 if (fcport->last_rscn_gen != fcport->rscn_gen) {
688 qla_rscn_replay(fcport);
689 qlt_schedule_sess_for_deletion(fcport);
691 } else if (fcport->last_login_gen != fcport->login_gen) {
692 ql_dbg(ql_dbg_disc, vha, 0x20e0,
693 "%s %8phC login gen changed\n",
694 __func__, fcport->port_name);
698 n = ea->data[0] / sizeof(struct get_name_list_extended);
700 ql_dbg(ql_dbg_disc, vha, 0x20e1,
701 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
702 __func__, __LINE__, fcport->port_name, n,
703 fcport->d_id.b.domain, fcport->d_id.b.area,
704 fcport->d_id.b.al_pa, fcport->loop_id);
706 for (i = 0; i < n; i++) {
708 wwn = wwn_to_u64(e->port_name);
709 id.b.domain = e->port_id[2];
710 id.b.area = e->port_id[1];
711 id.b.al_pa = e->port_id[0];
714 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
717 if (IS_SW_RESV_ADDR(id))
722 loop_id = le16_to_cpu(e->nport_handle);
723 loop_id = (loop_id & 0x7fff);
724 if (fcport->fc4f_nvme)
725 current_login_state = e->current_login_state >> 4;
727 current_login_state = e->current_login_state & 0xf;
730 ql_dbg(ql_dbg_disc, vha, 0x20e2,
731 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
732 __func__, fcport->port_name,
733 e->current_login_state, fcport->fw_login_state,
734 fcport->fc4f_nvme, id.b.domain, id.b.area, id.b.al_pa,
735 fcport->d_id.b.domain, fcport->d_id.b.area,
736 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
738 switch (fcport->disc_state) {
739 case DSC_DELETE_PEND:
743 if ((id.b24 != fcport->d_id.b24 &&
745 (fcport->loop_id != FC_NO_LOOP_ID &&
746 fcport->loop_id != loop_id)) {
747 ql_dbg(ql_dbg_disc, vha, 0x20e3,
748 "%s %d %8phC post del sess\n",
749 __func__, __LINE__, fcport->port_name);
750 qlt_schedule_sess_for_deletion(fcport);
756 fcport->loop_id = loop_id;
758 wwn = wwn_to_u64(fcport->port_name);
759 qlt_find_sess_invalidate_other(vha, wwn,
760 id, loop_id, &conflict_fcport);
762 if (conflict_fcport) {
764 * Another share fcport share the same loop_id &
765 * nport id. Conflict fcport needs to finish
766 * cleanup before this fcport can proceed to login.
768 conflict_fcport->conflict = fcport;
769 fcport->login_pause = 1;
772 switch (vha->hw->current_topology) {
774 switch (current_login_state) {
775 case DSC_LS_PRLI_COMP:
776 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
777 vha, 0x20e4, "%s %d %8phC post gpdb\n",
778 __func__, __LINE__, fcport->port_name);
780 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
781 fcport->port_type = FCT_INITIATOR;
783 fcport->port_type = FCT_TARGET;
784 data[0] = data[1] = 0;
785 qla2x00_post_async_adisc_work(vha, fcport,
788 case DSC_LS_PORT_UNAVAIL:
790 if (fcport->loop_id == FC_NO_LOOP_ID) {
791 qla2x00_find_new_loop_id(vha, fcport);
792 fcport->fw_login_state =
795 ql_dbg(ql_dbg_disc, vha, 0x20e5,
796 "%s %d %8phC\n", __func__, __LINE__,
798 qla24xx_fcport_handle_login(vha, fcport);
803 fcport->fw_login_state = current_login_state;
805 switch (current_login_state) {
806 case DSC_LS_PRLI_COMP:
807 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
808 fcport->port_type = FCT_INITIATOR;
810 fcport->port_type = FCT_TARGET;
812 data[0] = data[1] = 0;
813 qla2x00_post_async_adisc_work(vha, fcport,
816 case DSC_LS_PLOGI_COMP:
817 if (fcport_is_bigger(fcport)) {
818 /* local adapter is smaller */
819 if (fcport->loop_id != FC_NO_LOOP_ID)
820 qla2x00_clear_loop_id(fcport);
822 fcport->loop_id = loop_id;
823 qla24xx_fcport_handle_login(vha,
829 if (fcport_is_smaller(fcport)) {
830 /* local adapter is bigger */
831 if (fcport->loop_id != FC_NO_LOOP_ID)
832 qla2x00_clear_loop_id(fcport);
834 fcport->loop_id = loop_id;
835 qla24xx_fcport_handle_login(vha,
841 } /* switch (ha->current_topology) */
845 switch (vha->hw->current_topology) {
848 for (i = 0; i < n; i++) {
850 id.b.domain = e->port_id[0];
851 id.b.area = e->port_id[1];
852 id.b.al_pa = e->port_id[2];
854 loop_id = le16_to_cpu(e->nport_handle);
856 if (fcport->d_id.b24 == id.b24) {
858 qla2x00_find_fcport_by_wwpn(vha,
860 if (conflict_fcport) {
861 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
863 "%s %d %8phC post del sess\n",
865 conflict_fcport->port_name);
866 qlt_schedule_sess_for_deletion
871 * FW already picked this loop id for
874 if (fcport->loop_id == loop_id)
875 fcport->loop_id = FC_NO_LOOP_ID;
877 qla24xx_fcport_handle_login(vha, fcport);
880 fcport->disc_state = DSC_DELETED;
881 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
882 if (fcport->n2n_link_reset_cnt < 2) {
883 fcport->n2n_link_reset_cnt++;
885 * remote port is not sending PLOGI.
886 * Reset link to kick start his state
889 set_bit(N2N_LINK_RESET,
892 if (fcport->n2n_chip_reset < 1) {
893 ql_log(ql_log_info, vha, 0x705d,
894 "Chip reset to bring laser down");
895 set_bit(ISP_ABORT_NEEDED,
897 fcport->n2n_chip_reset++;
899 ql_log(ql_log_info, vha, 0x705d,
900 "Remote port %8ph is not coming back\n",
902 fcport->scan_state = 0;
905 qla2xxx_wake_dpc(vha);
908 * report port suppose to do PLOGI. Give him
909 * more time. FW will catch it.
911 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
921 qla24xx_async_gnl_sp_done(void *s, int res)
924 struct scsi_qla_host *vha = sp->vha;
926 struct fc_port *fcport = NULL, *tf;
927 u16 i, n = 0, loop_id;
929 struct get_name_list_extended *e;
934 ql_dbg(ql_dbg_disc, vha, 0x20e7,
935 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
936 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
937 sp->u.iocb_cmd.u.mbx.in_mb[2]);
939 if (res == QLA_FUNCTION_TIMEOUT)
942 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
943 memset(&ea, 0, sizeof(ea));
946 ea.event = FCME_GNL_DONE;
948 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
949 sizeof(struct get_name_list_extended)) {
950 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
951 sizeof(struct get_name_list_extended);
952 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
955 for (i = 0; i < n; i++) {
957 loop_id = le16_to_cpu(e->nport_handle);
958 /* mask out reserve bit */
959 loop_id = (loop_id & 0x7fff);
960 set_bit(loop_id, vha->hw->loop_id_map);
961 wwn = wwn_to_u64(e->port_name);
963 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
964 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
965 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
966 e->port_id[0], e->current_login_state, e->last_login_state,
970 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
974 if (!list_empty(&vha->gnl.fcports))
975 list_splice_init(&vha->gnl.fcports, &h);
976 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
978 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
979 list_del_init(&fcport->gnl_entry);
980 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
981 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
982 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
985 qla2x00_fcport_event_handler(vha, &ea);
988 /* create new fcport if fw has knowledge of new sessions */
989 for (i = 0; i < n; i++) {
994 wwn = wwn_to_u64(e->port_name);
997 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
998 if (!memcmp((u8 *)&wwn, fcport->port_name,
1005 id.b.domain = e->port_id[2];
1006 id.b.area = e->port_id[1];
1007 id.b.al_pa = e->port_id[0];
1010 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1011 ql_dbg(ql_dbg_disc, vha, 0x2065,
1012 "%s %d %8phC %06x post new sess\n",
1013 __func__, __LINE__, (u8 *)&wwn, id.b24);
1014 wwnn = wwn_to_u64(e->node_name);
1015 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1016 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
1020 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1022 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1027 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1030 struct srb_iocb *mbx;
1031 int rval = QLA_FUNCTION_FAILED;
1032 unsigned long flags;
1035 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1038 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1039 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1041 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1042 fcport->flags |= FCF_ASYNC_SENT;
1043 fcport->disc_state = DSC_GNL;
1044 fcport->last_rscn_gen = fcport->rscn_gen;
1045 fcport->last_login_gen = fcport->login_gen;
1047 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1048 if (vha->gnl.sent) {
1049 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1053 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1055 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1059 sp->type = SRB_MB_IOCB;
1060 sp->name = "gnlist";
1061 sp->gen1 = fcport->rscn_gen;
1062 sp->gen2 = fcport->login_gen;
1064 mbx = &sp->u.iocb_cmd;
1065 mbx->timeout = qla2x00_async_iocb_timeout;
1066 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1068 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1069 mb[0] = MBC_PORT_NODE_NAME_LIST;
1070 mb[1] = BIT_2 | BIT_3;
1071 mb[2] = MSW(vha->gnl.ldma);
1072 mb[3] = LSW(vha->gnl.ldma);
1073 mb[6] = MSW(MSD(vha->gnl.ldma));
1074 mb[7] = LSW(MSD(vha->gnl.ldma));
1075 mb[8] = vha->gnl.size;
1076 mb[9] = vha->vp_idx;
1078 sp->done = qla24xx_async_gnl_sp_done;
1080 ql_dbg(ql_dbg_disc, vha, 0x20da,
1081 "Async-%s - OUT WWPN %8phC hndl %x\n",
1082 sp->name, fcport->port_name, sp->handle);
1084 rval = qla2x00_start_sp(sp);
1085 if (rval != QLA_SUCCESS)
1092 fcport->flags &= ~FCF_ASYNC_SENT;
1097 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1099 struct qla_work_evt *e;
1101 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1103 return QLA_FUNCTION_FAILED;
1105 e->u.fcport.fcport = fcport;
1106 fcport->flags |= FCF_ASYNC_ACTIVE;
1107 return qla2x00_post_work(vha, e);
1111 void qla24xx_async_gpdb_sp_done(void *s, int res)
1114 struct scsi_qla_host *vha = sp->vha;
1115 struct qla_hw_data *ha = vha->hw;
1116 fc_port_t *fcport = sp->fcport;
1117 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1118 struct event_arg ea;
1120 ql_dbg(ql_dbg_disc, vha, 0x20db,
1121 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1122 sp->name, res, fcport->port_name, mb[1], mb[2]);
1124 if (res == QLA_FUNCTION_TIMEOUT) {
1125 dma_pool_free(sp->vha->hw->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1126 sp->u.iocb_cmd.u.mbx.in_dma);
1130 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1131 memset(&ea, 0, sizeof(ea));
1132 ea.event = FCME_GPDB_DONE;
1136 qla2x00_fcport_event_handler(vha, &ea);
1138 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1139 sp->u.iocb_cmd.u.mbx.in_dma);
1144 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1146 struct qla_work_evt *e;
1148 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1150 return QLA_FUNCTION_FAILED;
1152 e->u.fcport.fcport = fcport;
1154 return qla2x00_post_work(vha, e);
1158 qla2x00_async_prli_sp_done(void *ptr, int res)
1161 struct scsi_qla_host *vha = sp->vha;
1162 struct srb_iocb *lio = &sp->u.iocb_cmd;
1163 struct event_arg ea;
1165 ql_dbg(ql_dbg_disc, vha, 0x2129,
1166 "%s %8phC res %d \n", __func__,
1167 sp->fcport->port_name, res);
1169 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1171 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1172 memset(&ea, 0, sizeof(ea));
1173 ea.event = FCME_PRLI_DONE;
1174 ea.fcport = sp->fcport;
1175 ea.data[0] = lio->u.logio.data[0];
1176 ea.data[1] = lio->u.logio.data[1];
1177 ea.iop[0] = lio->u.logio.iop[0];
1178 ea.iop[1] = lio->u.logio.iop[1];
1181 qla2x00_fcport_event_handler(vha, &ea);
1188 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1191 struct srb_iocb *lio;
1192 int rval = QLA_FUNCTION_FAILED;
1194 if (!vha->flags.online)
1197 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1198 fcport->fw_login_state == DSC_LS_PRLI_PEND)
1201 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1205 fcport->flags |= FCF_ASYNC_SENT;
1206 fcport->logout_completed = 0;
1208 sp->type = SRB_PRLI_CMD;
1211 lio = &sp->u.iocb_cmd;
1212 lio->timeout = qla2x00_async_iocb_timeout;
1213 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1215 sp->done = qla2x00_async_prli_sp_done;
1216 lio->u.logio.flags = 0;
1218 if (fcport->fc4f_nvme)
1219 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1221 ql_dbg(ql_dbg_disc, vha, 0x211b,
1222 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1223 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1224 fcport->login_retry, fcport->fc4f_nvme ? "nvme" : "fc");
1226 rval = qla2x00_start_sp(sp);
1227 if (rval != QLA_SUCCESS) {
1228 fcport->flags |= FCF_LOGIN_NEEDED;
1229 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1237 fcport->flags &= ~FCF_ASYNC_SENT;
1241 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1243 struct qla_work_evt *e;
1245 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1247 return QLA_FUNCTION_FAILED;
1249 e->u.fcport.fcport = fcport;
1250 e->u.fcport.opt = opt;
1251 fcport->flags |= FCF_ASYNC_ACTIVE;
1252 return qla2x00_post_work(vha, e);
1255 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1258 struct srb_iocb *mbx;
1259 int rval = QLA_FUNCTION_FAILED;
1262 struct port_database_24xx *pd;
1263 struct qla_hw_data *ha = vha->hw;
1265 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1268 fcport->disc_state = DSC_GPDB;
1270 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1274 fcport->flags |= FCF_ASYNC_SENT;
1275 sp->type = SRB_MB_IOCB;
1277 sp->gen1 = fcport->rscn_gen;
1278 sp->gen2 = fcport->login_gen;
1280 mbx = &sp->u.iocb_cmd;
1281 mbx->timeout = qla2x00_async_iocb_timeout;
1282 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1284 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1286 ql_log(ql_log_warn, vha, 0xd043,
1287 "Failed to allocate port database structure.\n");
1291 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1292 mb[0] = MBC_GET_PORT_DATABASE;
1293 mb[1] = fcport->loop_id;
1294 mb[2] = MSW(pd_dma);
1295 mb[3] = LSW(pd_dma);
1296 mb[6] = MSW(MSD(pd_dma));
1297 mb[7] = LSW(MSD(pd_dma));
1298 mb[9] = vha->vp_idx;
1301 mbx->u.mbx.in = (void *)pd;
1302 mbx->u.mbx.in_dma = pd_dma;
1304 sp->done = qla24xx_async_gpdb_sp_done;
1306 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1307 "Async-%s %8phC hndl %x opt %x\n",
1308 sp->name, fcport->port_name, sp->handle, opt);
1310 rval = qla2x00_start_sp(sp);
1311 if (rval != QLA_SUCCESS)
1317 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1320 fcport->flags &= ~FCF_ASYNC_SENT;
1322 qla24xx_post_gpdb_work(vha, fcport, opt);
1327 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1329 unsigned long flags;
1331 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1332 ea->fcport->login_gen++;
1333 ea->fcport->deleted = 0;
1334 ea->fcport->logout_on_delete = 1;
1336 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1337 vha->fcport_count++;
1338 ea->fcport->login_succ = 1;
1340 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1341 qla24xx_sched_upd_fcport(ea->fcport);
1342 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1343 } else if (ea->fcport->login_succ) {
1345 * We have an existing session. A late RSCN delivery
1346 * must have triggered the session to be re-validate.
1347 * Session is still valid.
1349 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1350 "%s %d %8phC session revalidate success\n",
1351 __func__, __LINE__, ea->fcport->port_name);
1352 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1354 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1358 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1360 fc_port_t *fcport = ea->fcport;
1361 struct port_database_24xx *pd;
1362 struct srb *sp = ea->sp;
1365 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1367 fcport->flags &= ~FCF_ASYNC_SENT;
1369 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1370 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__, fcport->port_name,
1371 fcport->disc_state, pd->current_login_state, fcport->fc4f_nvme,
1374 if (fcport->disc_state == DSC_DELETE_PEND)
1377 if (fcport->fc4f_nvme)
1378 ls = pd->current_login_state >> 4;
1380 ls = pd->current_login_state & 0xf;
1382 if (ea->sp->gen2 != fcport->login_gen) {
1383 /* target side must have changed it. */
1385 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1386 "%s %8phC generation changed\n",
1387 __func__, fcport->port_name);
1389 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1390 qla_rscn_replay(fcport);
1391 qlt_schedule_sess_for_deletion(fcport);
1396 case PDS_PRLI_COMPLETE:
1397 __qla24xx_parse_gpdb(vha, fcport, pd);
1399 case PDS_PLOGI_PENDING:
1400 case PDS_PLOGI_COMPLETE:
1401 case PDS_PRLI_PENDING:
1402 case PDS_PRLI2_PENDING:
1403 /* Set discovery state back to GNL to Relogin attempt */
1404 if (qla_dual_mode_enabled(vha) ||
1405 qla_ini_mode_enabled(vha)) {
1406 fcport->disc_state = DSC_GNL;
1407 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1410 case PDS_LOGO_PENDING:
1411 case PDS_PORT_UNAVAILABLE:
1413 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1414 __func__, __LINE__, fcport->port_name);
1415 qlt_schedule_sess_for_deletion(fcport);
1418 __qla24xx_handle_gpdb_event(vha, ea);
1421 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1426 if (qla_tgt_mode_enabled(vha))
1429 if (qla_dual_mode_enabled(vha)) {
1430 if (N2N_TOPO(vha->hw)) {
1433 mywwn = wwn_to_u64(vha->port_name);
1434 wwn = wwn_to_u64(fcport->port_name);
1437 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1438 && time_after_eq(jiffies,
1439 fcport->plogi_nack_done_deadline))
1445 /* initiator mode */
1449 if (login && fcport->login_retry) {
1450 fcport->login_retry--;
1451 if (fcport->loop_id == FC_NO_LOOP_ID) {
1452 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1453 rc = qla2x00_find_new_loop_id(vha, fcport);
1455 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1456 "%s %d %8phC post del sess - out of loopid\n",
1457 __func__, __LINE__, fcport->port_name);
1458 fcport->scan_state = 0;
1459 qlt_schedule_sess_for_deletion(fcport);
1463 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1464 "%s %d %8phC post login\n",
1465 __func__, __LINE__, fcport->port_name);
1466 qla2x00_post_async_login_work(vha, fcport, NULL);
1470 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1476 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20d8,
1477 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1478 __func__, fcport->port_name, fcport->disc_state,
1479 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1480 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1481 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1483 if (fcport->scan_state != QLA_FCPORT_FOUND)
1486 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1487 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1488 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1491 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1492 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1493 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1498 /* for pure Target Mode. Login will not be initiated */
1499 if (vha->host->active_mode == MODE_TARGET)
1502 if (fcport->flags & FCF_ASYNC_SENT) {
1503 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1507 switch (fcport->disc_state) {
1509 wwn = wwn_to_u64(fcport->node_name);
1510 switch (vha->hw->current_topology) {
1512 if (fcport_is_smaller(fcport)) {
1513 /* this adapter is bigger */
1514 if (fcport->login_retry) {
1515 if (fcport->loop_id == FC_NO_LOOP_ID) {
1516 qla2x00_find_new_loop_id(vha,
1518 fcport->fw_login_state =
1519 DSC_LS_PORT_UNAVAIL;
1521 fcport->login_retry--;
1522 qla_post_els_plogi_work(vha, fcport);
1524 ql_log(ql_log_info, vha, 0x705d,
1525 "Unable to reach remote port %8phC",
1529 qla24xx_post_gnl_work(vha, fcport);
1534 ql_dbg(ql_dbg_disc, vha, 0xffff,
1535 "%s %d %8phC post GNNID\n",
1536 __func__, __LINE__, fcport->port_name);
1537 qla24xx_post_gnnid_work(vha, fcport);
1538 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1539 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1540 "%s %d %8phC post gnl\n",
1541 __func__, __LINE__, fcport->port_name);
1542 qla24xx_post_gnl_work(vha, fcport);
1544 qla_chk_n2n_b4_login(vha, fcport);
1551 switch (vha->hw->current_topology) {
1553 if ((fcport->current_login_state & 0xf) == 0x6) {
1554 ql_dbg(ql_dbg_disc, vha, 0x2118,
1555 "%s %d %8phC post GPDB work\n",
1556 __func__, __LINE__, fcport->port_name);
1557 fcport->chip_reset =
1558 vha->hw->base_qpair->chip_reset;
1559 qla24xx_post_gpdb_work(vha, fcport, 0);
1561 ql_dbg(ql_dbg_disc, vha, 0x2118,
1562 "%s %d %8phC post NVMe PRLI\n",
1563 __func__, __LINE__, fcport->port_name);
1564 qla24xx_post_prli_work(vha, fcport);
1568 if (fcport->login_pause) {
1569 fcport->last_rscn_gen = fcport->rscn_gen;
1570 fcport->last_login_gen = fcport->login_gen;
1571 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1574 qla_chk_n2n_b4_login(vha, fcport);
1579 case DSC_LOGIN_FAILED:
1580 if (N2N_TOPO(vha->hw))
1581 qla_chk_n2n_b4_login(vha, fcport);
1583 qlt_schedule_sess_for_deletion(fcport);
1586 case DSC_LOGIN_COMPLETE:
1587 /* recheck login state */
1588 data[0] = data[1] = 0;
1589 qla2x00_post_async_adisc_work(vha, fcport, data);
1592 case DSC_LOGIN_PEND:
1593 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1594 qla24xx_post_prli_work(vha, fcport);
1597 case DSC_UPD_FCPORT:
1598 sec = jiffies_to_msecs(jiffies -
1599 fcport->jiffies_at_registration)/1000;
1600 if (fcport->sec_since_registration < sec && sec &&
1602 fcport->sec_since_registration = sec;
1603 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1604 "%s %8phC - Slow Rport registration(%d Sec)\n",
1605 __func__, fcport->port_name, sec);
1608 if (fcport->next_disc_state != DSC_DELETE_PEND)
1609 fcport->next_disc_state = DSC_ADISC;
1610 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1620 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1621 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1623 struct qla_work_evt *e;
1625 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1627 return QLA_FUNCTION_FAILED;
1629 e->u.new_sess.id = *id;
1630 e->u.new_sess.pla = pla;
1631 e->u.new_sess.fc4_type = fc4_type;
1632 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1634 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1636 return qla2x00_post_work(vha, e);
1640 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1641 struct event_arg *ea)
1643 fc_port_t *fcport = ea->fcport;
1645 ql_dbg(ql_dbg_disc, vha, 0x2102,
1646 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1647 __func__, fcport->port_name, fcport->disc_state,
1648 fcport->fw_login_state, fcport->login_pause,
1649 fcport->deleted, fcport->conflict,
1650 fcport->last_rscn_gen, fcport->rscn_gen,
1651 fcport->last_login_gen, fcport->login_gen,
1654 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1655 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1658 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1659 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1660 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1665 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1666 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1667 __func__, __LINE__, fcport->port_name);
1672 qla24xx_fcport_handle_login(vha, fcport);
1676 static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1677 struct event_arg *ea)
1679 ql_dbg(ql_dbg_disc, vha, 0x2118,
1680 "%s %d %8phC post PRLI\n",
1681 __func__, __LINE__, ea->fcport->port_name);
1682 qla24xx_post_prli_work(vha, ea->fcport);
1685 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1689 switch (ea->event) {
1691 if (test_bit(UNLOADING, &vha->dpc_flags))
1694 qla24xx_handle_relogin_event(vha, ea);
1697 if (test_bit(UNLOADING, &vha->dpc_flags))
1700 unsigned long flags;
1702 fcport = qla2x00_find_fcport_by_nportid
1705 fcport->scan_needed = 1;
1709 spin_lock_irqsave(&vha->work_lock, flags);
1710 if (vha->scan.scan_flags == 0) {
1711 ql_dbg(ql_dbg_disc, vha, 0xffff,
1712 "%s: schedule\n", __func__);
1713 vha->scan.scan_flags |= SF_QUEUED;
1714 schedule_delayed_work(&vha->scan.scan_work, 5);
1716 spin_unlock_irqrestore(&vha->work_lock, flags);
1720 qla24xx_handle_gnl_done_event(vha, ea);
1722 case FCME_GPSC_DONE:
1723 qla24xx_handle_gpsc_event(vha, ea);
1725 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1726 qla24xx_handle_plogi_done_event(vha, ea);
1728 case FCME_PRLI_DONE:
1729 qla24xx_handle_prli_done_event(vha, ea);
1731 case FCME_GPDB_DONE:
1732 qla24xx_handle_gpdb_event(vha, ea);
1734 case FCME_GPNID_DONE:
1735 qla24xx_handle_gpnid_event(vha, ea);
1737 case FCME_GFFID_DONE:
1738 qla24xx_handle_gffid_event(vha, ea);
1740 case FCME_ADISC_DONE:
1741 qla24xx_handle_adisc_event(vha, ea);
1743 case FCME_GNNID_DONE:
1744 qla24xx_handle_gnnid_event(vha, ea);
1746 case FCME_GFPNID_DONE:
1747 qla24xx_handle_gfpnid_event(vha, ea);
1749 case FCME_ELS_PLOGI_DONE:
1750 qla_handle_els_plogi_done(vha, ea);
1759 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1760 * to be consumed by the fcport
1762 void qla_rscn_replay(fc_port_t *fcport)
1764 struct event_arg ea;
1766 switch (fcport->disc_state) {
1767 case DSC_DELETE_PEND:
1773 if (fcport->scan_needed) {
1774 memset(&ea, 0, sizeof(ea));
1775 ea.event = FCME_RSCN;
1776 ea.id = fcport->d_id;
1777 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1778 qla2x00_fcport_event_handler(fcport->vha, &ea);
1783 qla2x00_tmf_iocb_timeout(void *data)
1786 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1788 tmf->u.tmf.comp_status = CS_TIMEOUT;
1789 complete(&tmf->u.tmf.comp);
1793 qla2x00_tmf_sp_done(void *ptr, int res)
1796 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1798 complete(&tmf->u.tmf.comp);
1802 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1805 struct scsi_qla_host *vha = fcport->vha;
1806 struct srb_iocb *tm_iocb;
1808 int rval = QLA_FUNCTION_FAILED;
1810 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1814 tm_iocb = &sp->u.iocb_cmd;
1815 sp->type = SRB_TM_CMD;
1818 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1819 init_completion(&tm_iocb->u.tmf.comp);
1820 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1822 tm_iocb->u.tmf.flags = flags;
1823 tm_iocb->u.tmf.lun = lun;
1824 tm_iocb->u.tmf.data = tag;
1825 sp->done = qla2x00_tmf_sp_done;
1827 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1828 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1829 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1830 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1832 rval = qla2x00_start_sp(sp);
1833 if (rval != QLA_SUCCESS)
1835 wait_for_completion(&tm_iocb->u.tmf.comp);
1837 rval = tm_iocb->u.tmf.data;
1839 if (rval != QLA_SUCCESS) {
1840 ql_log(ql_log_warn, vha, 0x8030,
1841 "TM IOCB failed (%x).\n", rval);
1844 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1845 flags = tm_iocb->u.tmf.flags;
1846 lun = (uint16_t)tm_iocb->u.tmf.lun;
1848 /* Issue Marker IOCB */
1849 qla2x00_marker(vha, vha->hw->base_qpair,
1850 fcport->loop_id, lun,
1851 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1856 fcport->flags &= ~FCF_ASYNC_SENT;
1862 qla24xx_async_abort_command(srb_t *sp)
1864 unsigned long flags = 0;
1867 fc_port_t *fcport = sp->fcport;
1868 struct qla_qpair *qpair = sp->qpair;
1869 struct scsi_qla_host *vha = fcport->vha;
1870 struct req_que *req = qpair->req;
1872 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1873 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1874 if (req->outstanding_cmds[handle] == sp)
1877 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1879 if (handle == req->num_outstanding_cmds) {
1880 /* Command not found. */
1881 return QLA_FUNCTION_FAILED;
1883 if (sp->type == SRB_FXIOCB_DCMD)
1884 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1885 FXDISC_ABORT_IOCTL);
1887 return qla24xx_async_abort_cmd(sp, true);
1891 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1893 switch (ea->data[0]) {
1894 case MBS_COMMAND_COMPLETE:
1895 ql_dbg(ql_dbg_disc, vha, 0x2118,
1896 "%s %d %8phC post gpdb\n",
1897 __func__, __LINE__, ea->fcport->port_name);
1899 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1900 ea->fcport->logout_on_delete = 1;
1901 ea->fcport->nvme_prli_service_param = ea->iop[0];
1902 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1903 ea->fcport->nvme_first_burst_size =
1904 (ea->iop[1] & 0xffff) * 512;
1906 ea->fcport->nvme_first_burst_size = 0;
1907 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1910 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1911 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1912 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1913 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1917 if (ea->fcport->n2n_flag) {
1918 ql_dbg(ql_dbg_disc, vha, 0x2118,
1919 "%s %d %8phC post fc4 prli\n",
1920 __func__, __LINE__, ea->fcport->port_name);
1921 ea->fcport->fc4f_nvme = 0;
1922 ea->fcport->n2n_flag = 0;
1923 qla24xx_post_prli_work(vha, ea->fcport);
1925 ql_dbg(ql_dbg_disc, vha, 0x2119,
1926 "%s %d %8phC unhandle event of %x\n",
1927 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1933 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1935 port_id_t cid; /* conflict Nport id */
1937 struct fc_port *conflict_fcport;
1938 unsigned long flags;
1939 struct fc_port *fcport = ea->fcport;
1941 ql_dbg(ql_dbg_disc, vha, 0xffff,
1942 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1943 __func__, fcport->port_name, fcport->disc_state,
1944 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1945 ea->sp->gen1, fcport->rscn_gen,
1946 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1948 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1949 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1950 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1951 "%s %d %8phC Remote is trying to login\n",
1952 __func__, __LINE__, fcport->port_name);
1956 if (fcport->disc_state == DSC_DELETE_PEND)
1959 if (ea->sp->gen2 != fcport->login_gen) {
1960 /* target side must have changed it. */
1961 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1962 "%s %8phC generation changed\n",
1963 __func__, fcport->port_name);
1964 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1966 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1967 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1968 "%s %8phC RSCN generation changed\n",
1969 __func__, fcport->port_name);
1970 qla_rscn_replay(fcport);
1971 qlt_schedule_sess_for_deletion(fcport);
1975 switch (ea->data[0]) {
1976 case MBS_COMMAND_COMPLETE:
1978 * Driver must validate login state - If PRLI not complete,
1979 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1982 if (ea->fcport->fc4f_nvme) {
1983 ql_dbg(ql_dbg_disc, vha, 0x2117,
1984 "%s %d %8phC post prli\n",
1985 __func__, __LINE__, ea->fcport->port_name);
1986 qla24xx_post_prli_work(vha, ea->fcport);
1988 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1989 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1990 __func__, __LINE__, ea->fcport->port_name,
1991 ea->fcport->loop_id, ea->fcport->d_id.b24);
1993 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1994 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1995 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1996 ea->fcport->logout_on_delete = 1;
1997 ea->fcport->send_els_logo = 0;
1998 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
1999 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2001 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2004 case MBS_COMMAND_ERROR:
2005 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2006 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2008 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2009 ea->fcport->disc_state = DSC_LOGIN_FAILED;
2010 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2011 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2013 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2015 case MBS_LOOP_ID_USED:
2016 /* data[1] = IO PARAM 1 = nport ID */
2017 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2018 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2019 cid.b.al_pa = ea->iop[1] & 0xff;
2022 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2023 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2024 __func__, __LINE__, ea->fcport->port_name,
2025 ea->fcport->loop_id, cid.b24);
2027 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2028 ea->fcport->loop_id = FC_NO_LOOP_ID;
2029 qla24xx_post_gnl_work(vha, ea->fcport);
2031 case MBS_PORT_ID_USED:
2032 lid = ea->iop[1] & 0xffff;
2033 qlt_find_sess_invalidate_other(vha,
2034 wwn_to_u64(ea->fcport->port_name),
2035 ea->fcport->d_id, lid, &conflict_fcport);
2037 if (conflict_fcport) {
2039 * Another fcport share the same loop_id/nport id.
2040 * Conflict fcport needs to finish cleanup before this
2041 * fcport can proceed to login.
2043 conflict_fcport->conflict = ea->fcport;
2044 ea->fcport->login_pause = 1;
2046 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2047 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2048 __func__, __LINE__, ea->fcport->port_name,
2049 ea->fcport->d_id.b24, lid);
2051 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2052 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2053 __func__, __LINE__, ea->fcport->port_name,
2054 ea->fcport->d_id.b24, lid);
2056 qla2x00_clear_loop_id(ea->fcport);
2057 set_bit(lid, vha->hw->loop_id_map);
2058 ea->fcport->loop_id = lid;
2059 ea->fcport->keep_nport_handle = 0;
2060 qlt_schedule_sess_for_deletion(ea->fcport);
2068 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2071 qlt_logo_completion_handler(fcport, data[0]);
2072 fcport->login_gen++;
2073 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2077 /****************************************************************************/
2078 /* QLogic ISP2x00 Hardware Support Functions. */
2079 /****************************************************************************/
2082 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2084 int rval = QLA_SUCCESS;
2085 struct qla_hw_data *ha = vha->hw;
2086 uint32_t idc_major_ver, idc_minor_ver;
2089 qla83xx_idc_lock(vha, 0);
2091 /* SV: TODO: Assign initialization timeout from
2092 * flash-info / other param
2094 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2095 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2097 /* Set our fcoe function presence */
2098 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2099 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2100 "Error while setting DRV-Presence.\n");
2101 rval = QLA_FUNCTION_FAILED;
2105 /* Decide the reset ownership */
2106 qla83xx_reset_ownership(vha);
2109 * On first protocol driver load:
2110 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2112 * Others: Check compatibility with current IDC Major version.
2114 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2115 if (ha->flags.nic_core_reset_owner) {
2116 /* Set IDC Major version */
2117 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2118 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2120 /* Clearing IDC-Lock-Recovery register */
2121 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2122 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2124 * Clear further IDC participation if we are not compatible with
2125 * the current IDC Major Version.
2127 ql_log(ql_log_warn, vha, 0xb07d,
2128 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2129 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2130 __qla83xx_clear_drv_presence(vha);
2131 rval = QLA_FUNCTION_FAILED;
2134 /* Each function sets its supported Minor version. */
2135 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2136 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2137 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2139 if (ha->flags.nic_core_reset_owner) {
2140 memset(config, 0, sizeof(config));
2141 if (!qla81xx_get_port_config(vha, config))
2142 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2146 rval = qla83xx_idc_state_handler(vha);
2149 qla83xx_idc_unlock(vha, 0);
2155 * qla2x00_initialize_adapter
2159 * ha = adapter block pointer.
2165 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2168 struct qla_hw_data *ha = vha->hw;
2169 struct req_que *req = ha->req_q_map[0];
2170 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2172 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2173 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2175 /* Clear adapter flags. */
2176 vha->flags.online = 0;
2177 ha->flags.chip_reset_done = 0;
2178 vha->flags.reset_active = 0;
2179 ha->flags.pci_channel_io_perm_failure = 0;
2180 ha->flags.eeh_busy = 0;
2181 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2182 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2183 atomic_set(&vha->loop_state, LOOP_DOWN);
2184 vha->device_flags = DFLG_NO_CABLE;
2186 vha->flags.management_server_logged_in = 0;
2187 vha->marker_needed = 0;
2188 ha->isp_abort_cnt = 0;
2189 ha->beacon_blink_led = 0;
2191 set_bit(0, ha->req_qid_map);
2192 set_bit(0, ha->rsp_qid_map);
2194 ql_dbg(ql_dbg_init, vha, 0x0040,
2195 "Configuring PCI space...\n");
2196 rval = ha->isp_ops->pci_config(vha);
2198 ql_log(ql_log_warn, vha, 0x0044,
2199 "Unable to configure PCI space.\n");
2203 ha->isp_ops->reset_chip(vha);
2205 /* Check for secure flash support */
2206 if (IS_QLA28XX(ha)) {
2207 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2208 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2209 ha->flags.secure_adapter = 1;
2214 rval = qla2xxx_get_flash_info(vha);
2216 ql_log(ql_log_fatal, vha, 0x004f,
2217 "Unable to validate FLASH data.\n");
2221 if (IS_QLA8044(ha)) {
2222 qla8044_read_reset_template(vha);
2224 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2225 * If DONRESET_BIT0 is set, drivers should not set dev_state
2226 * to NEED_RESET. But if NEED_RESET is set, drivers should
2227 * should honor the reset. */
2228 if (ql2xdontresethba == 1)
2229 qla8044_set_idc_dontreset(vha);
2232 ha->isp_ops->get_flash_version(vha, req->ring);
2233 ql_dbg(ql_dbg_init, vha, 0x0061,
2234 "Configure NVRAM parameters...\n");
2236 ha->isp_ops->nvram_config(vha);
2238 if (ha->flags.disable_serdes) {
2239 /* Mask HBA via NVRAM settings? */
2240 ql_log(ql_log_info, vha, 0x0077,
2241 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2242 return QLA_FUNCTION_FAILED;
2245 ql_dbg(ql_dbg_init, vha, 0x0078,
2246 "Verifying loaded RISC code...\n");
2248 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2249 rval = ha->isp_ops->chip_diag(vha);
2252 rval = qla2x00_setup_chip(vha);
2257 if (IS_QLA84XX(ha)) {
2258 ha->cs84xx = qla84xx_get_chip(vha);
2260 ql_log(ql_log_warn, vha, 0x00d0,
2261 "Unable to configure ISP84XX.\n");
2262 return QLA_FUNCTION_FAILED;
2266 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2267 rval = qla2x00_init_rings(vha);
2269 ha->flags.chip_reset_done = 1;
2271 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2272 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2273 rval = qla84xx_init_chip(vha);
2274 if (rval != QLA_SUCCESS) {
2275 ql_log(ql_log_warn, vha, 0x00d4,
2276 "Unable to initialize ISP84XX.\n");
2277 qla84xx_put_chip(vha);
2281 /* Load the NIC Core f/w if we are the first protocol driver. */
2282 if (IS_QLA8031(ha)) {
2283 rval = qla83xx_nic_core_fw_load(vha);
2285 ql_log(ql_log_warn, vha, 0x0124,
2286 "Error in initializing NIC Core f/w.\n");
2289 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2290 qla24xx_read_fcp_prio_cfg(vha);
2292 if (IS_P3P_TYPE(ha))
2293 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2295 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2301 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2304 * Returns 0 on success.
2307 qla2100_pci_config(scsi_qla_host_t *vha)
2310 unsigned long flags;
2311 struct qla_hw_data *ha = vha->hw;
2312 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2314 pci_set_master(ha->pdev);
2315 pci_try_set_mwi(ha->pdev);
2317 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2318 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2319 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2321 pci_disable_rom(ha->pdev);
2323 /* Get PCI bus information. */
2324 spin_lock_irqsave(&ha->hardware_lock, flags);
2325 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2326 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2332 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2335 * Returns 0 on success.
2338 qla2300_pci_config(scsi_qla_host_t *vha)
2341 unsigned long flags = 0;
2343 struct qla_hw_data *ha = vha->hw;
2344 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2346 pci_set_master(ha->pdev);
2347 pci_try_set_mwi(ha->pdev);
2349 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2350 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2352 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2353 w &= ~PCI_COMMAND_INTX_DISABLE;
2354 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2357 * If this is a 2300 card and not 2312, reset the
2358 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2359 * the 2310 also reports itself as a 2300 so we need to get the
2360 * fb revision level -- a 6 indicates it really is a 2300 and
2363 if (IS_QLA2300(ha)) {
2364 spin_lock_irqsave(&ha->hardware_lock, flags);
2367 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2368 for (cnt = 0; cnt < 30000; cnt++) {
2369 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2375 /* Select FPM registers. */
2376 WRT_REG_WORD(®->ctrl_status, 0x20);
2377 RD_REG_WORD(®->ctrl_status);
2379 /* Get the fb rev level */
2380 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2382 if (ha->fb_rev == FPM_2300)
2383 pci_clear_mwi(ha->pdev);
2385 /* Deselect FPM registers. */
2386 WRT_REG_WORD(®->ctrl_status, 0x0);
2387 RD_REG_WORD(®->ctrl_status);
2389 /* Release RISC module. */
2390 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2391 for (cnt = 0; cnt < 30000; cnt++) {
2392 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2398 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2401 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2403 pci_disable_rom(ha->pdev);
2405 /* Get PCI bus information. */
2406 spin_lock_irqsave(&ha->hardware_lock, flags);
2407 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2408 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2414 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2417 * Returns 0 on success.
2420 qla24xx_pci_config(scsi_qla_host_t *vha)
2423 unsigned long flags = 0;
2424 struct qla_hw_data *ha = vha->hw;
2425 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2427 pci_set_master(ha->pdev);
2428 pci_try_set_mwi(ha->pdev);
2430 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2431 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2432 w &= ~PCI_COMMAND_INTX_DISABLE;
2433 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2435 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2437 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2438 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2439 pcix_set_mmrbc(ha->pdev, 2048);
2441 /* PCIe -- adjust Maximum Read Request Size (2048). */
2442 if (pci_is_pcie(ha->pdev))
2443 pcie_set_readrq(ha->pdev, 4096);
2445 pci_disable_rom(ha->pdev);
2447 ha->chip_revision = ha->pdev->revision;
2449 /* Get PCI bus information. */
2450 spin_lock_irqsave(&ha->hardware_lock, flags);
2451 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2452 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2458 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2461 * Returns 0 on success.
2464 qla25xx_pci_config(scsi_qla_host_t *vha)
2467 struct qla_hw_data *ha = vha->hw;
2469 pci_set_master(ha->pdev);
2470 pci_try_set_mwi(ha->pdev);
2472 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2473 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2474 w &= ~PCI_COMMAND_INTX_DISABLE;
2475 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2477 /* PCIe -- adjust Maximum Read Request Size (2048). */
2478 if (pci_is_pcie(ha->pdev))
2479 pcie_set_readrq(ha->pdev, 4096);
2481 pci_disable_rom(ha->pdev);
2483 ha->chip_revision = ha->pdev->revision;
2489 * qla2x00_isp_firmware() - Choose firmware image.
2492 * Returns 0 on success.
2495 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2498 uint16_t loop_id, topo, sw_cap;
2499 uint8_t domain, area, al_pa;
2500 struct qla_hw_data *ha = vha->hw;
2502 /* Assume loading risc code */
2503 rval = QLA_FUNCTION_FAILED;
2505 if (ha->flags.disable_risc_code_load) {
2506 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2508 /* Verify checksum of loaded RISC code. */
2509 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2510 if (rval == QLA_SUCCESS) {
2511 /* And, verify we are not in ROM code. */
2512 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2513 &area, &domain, &topo, &sw_cap);
2518 ql_dbg(ql_dbg_init, vha, 0x007a,
2519 "**** Load RISC code ****.\n");
2525 * qla2x00_reset_chip() - Reset ISP chip.
2528 * Returns 0 on success.
2531 qla2x00_reset_chip(scsi_qla_host_t *vha)
2533 unsigned long flags = 0;
2534 struct qla_hw_data *ha = vha->hw;
2535 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2538 int rval = QLA_FUNCTION_FAILED;
2540 if (unlikely(pci_channel_offline(ha->pdev)))
2543 ha->isp_ops->disable_intrs(ha);
2545 spin_lock_irqsave(&ha->hardware_lock, flags);
2547 /* Turn off master enable */
2549 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2550 cmd &= ~PCI_COMMAND_MASTER;
2551 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2553 if (!IS_QLA2100(ha)) {
2555 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2556 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2557 for (cnt = 0; cnt < 30000; cnt++) {
2558 if ((RD_REG_WORD(®->hccr) &
2559 HCCR_RISC_PAUSE) != 0)
2564 RD_REG_WORD(®->hccr); /* PCI Posting. */
2568 /* Select FPM registers. */
2569 WRT_REG_WORD(®->ctrl_status, 0x20);
2570 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2572 /* FPM Soft Reset. */
2573 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2574 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2576 /* Toggle Fpm Reset. */
2577 if (!IS_QLA2200(ha)) {
2578 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2579 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2582 /* Select frame buffer registers. */
2583 WRT_REG_WORD(®->ctrl_status, 0x10);
2584 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2586 /* Reset frame buffer FIFOs. */
2587 if (IS_QLA2200(ha)) {
2588 WRT_FB_CMD_REG(ha, reg, 0xa000);
2589 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2591 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2593 /* Read back fb_cmd until zero or 3 seconds max */
2594 for (cnt = 0; cnt < 3000; cnt++) {
2595 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2601 /* Select RISC module registers. */
2602 WRT_REG_WORD(®->ctrl_status, 0);
2603 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2605 /* Reset RISC processor. */
2606 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2607 RD_REG_WORD(®->hccr); /* PCI Posting. */
2609 /* Release RISC processor. */
2610 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2611 RD_REG_WORD(®->hccr); /* PCI Posting. */
2614 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2615 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2617 /* Reset ISP chip. */
2618 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2620 /* Wait for RISC to recover from reset. */
2621 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2623 * It is necessary to for a delay here since the card doesn't
2624 * respond to PCI reads during a reset. On some architectures
2625 * this will result in an MCA.
2628 for (cnt = 30000; cnt; cnt--) {
2629 if ((RD_REG_WORD(®->ctrl_status) &
2630 CSR_ISP_SOFT_RESET) == 0)
2637 /* Reset RISC processor. */
2638 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2640 WRT_REG_WORD(®->semaphore, 0);
2642 /* Release RISC processor. */
2643 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2644 RD_REG_WORD(®->hccr); /* PCI Posting. */
2646 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2647 for (cnt = 0; cnt < 30000; cnt++) {
2648 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2656 /* Turn on master enable */
2657 cmd |= PCI_COMMAND_MASTER;
2658 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2660 /* Disable RISC pause on FPM parity error. */
2661 if (!IS_QLA2100(ha)) {
2662 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2663 RD_REG_WORD(®->hccr); /* PCI Posting. */
2666 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2672 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2675 * Returns 0 on success.
2678 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2680 uint16_t mb[4] = {0x1010, 0, 1, 0};
2682 if (!IS_QLA81XX(vha->hw))
2685 return qla81xx_write_mpi_register(vha, mb);
2689 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2692 * Returns 0 on success.
2695 qla24xx_reset_risc(scsi_qla_host_t *vha)
2697 unsigned long flags = 0;
2698 struct qla_hw_data *ha = vha->hw;
2699 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2702 static int abts_cnt; /* ISP abort retry counts */
2703 int rval = QLA_SUCCESS;
2705 spin_lock_irqsave(&ha->hardware_lock, flags);
2708 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2709 for (cnt = 0; cnt < 30000; cnt++) {
2710 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2716 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2717 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2719 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2720 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2721 RD_REG_DWORD(®->hccr),
2722 RD_REG_DWORD(®->ctrl_status),
2723 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2725 WRT_REG_DWORD(®->ctrl_status,
2726 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2727 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2731 /* Wait for firmware to complete NVRAM accesses. */
2732 RD_REG_WORD(®->mailbox0);
2733 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2734 rval == QLA_SUCCESS; cnt--) {
2739 rval = QLA_FUNCTION_TIMEOUT;
2742 if (rval == QLA_SUCCESS)
2743 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2745 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2746 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2747 RD_REG_DWORD(®->hccr),
2748 RD_REG_DWORD(®->mailbox0));
2750 /* Wait for soft-reset to complete. */
2751 RD_REG_DWORD(®->ctrl_status);
2752 for (cnt = 0; cnt < 60; cnt++) {
2754 if ((RD_REG_DWORD(®->ctrl_status) &
2755 CSRX_ISP_SOFT_RESET) == 0)
2760 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2761 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2763 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2764 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2765 RD_REG_DWORD(®->hccr),
2766 RD_REG_DWORD(®->ctrl_status));
2768 /* If required, do an MPI FW reset now */
2769 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2770 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2771 if (++abts_cnt < 5) {
2772 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2773 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2776 * We exhausted the ISP abort retries. We have to
2777 * set the board offline.
2780 vha->flags.online = 0;
2785 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2786 RD_REG_DWORD(®->hccr);
2788 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2789 RD_REG_DWORD(®->hccr);
2791 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2792 RD_REG_DWORD(®->hccr);
2794 RD_REG_WORD(®->mailbox0);
2795 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2796 rval == QLA_SUCCESS; cnt--) {
2801 rval = QLA_FUNCTION_TIMEOUT;
2803 if (rval == QLA_SUCCESS)
2804 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2806 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2807 "Host Risc 0x%x, mailbox0 0x%x\n",
2808 RD_REG_DWORD(®->hccr),
2809 RD_REG_WORD(®->mailbox0));
2811 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2813 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2814 "Driver in %s mode\n",
2815 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2817 if (IS_NOPOLLING_TYPE(ha))
2818 ha->isp_ops->enable_intrs(ha);
2824 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2826 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2828 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2829 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2834 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2836 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2838 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2839 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2843 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2846 uint delta_msec = 100;
2847 uint elapsed_msec = 0;
2851 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2852 vha->hw->pdev->subsystem_device != 0x0240)
2855 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2859 timeout_msec = TIMEOUT_SEMAPHORE;
2860 n = timeout_msec / delta_msec;
2862 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2863 qla25xx_read_risc_sema_reg(vha, &wd32);
2864 if (wd32 & RISC_SEMAPHORE)
2867 elapsed_msec += delta_msec;
2868 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2872 if (!(wd32 & RISC_SEMAPHORE))
2875 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2878 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2879 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2880 n = timeout_msec / delta_msec;
2882 qla25xx_read_risc_sema_reg(vha, &wd32);
2883 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2886 elapsed_msec += delta_msec;
2887 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2891 if (wd32 & RISC_SEMAPHORE_FORCE)
2892 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2897 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2904 * qla24xx_reset_chip() - Reset ISP24xx chip.
2907 * Returns 0 on success.
2910 qla24xx_reset_chip(scsi_qla_host_t *vha)
2912 struct qla_hw_data *ha = vha->hw;
2913 int rval = QLA_FUNCTION_FAILED;
2915 if (pci_channel_offline(ha->pdev) &&
2916 ha->flags.pci_channel_io_perm_failure) {
2920 ha->isp_ops->disable_intrs(ha);
2922 qla25xx_manipulate_risc_semaphore(vha);
2924 /* Perform RISC reset. */
2925 rval = qla24xx_reset_risc(vha);
2931 * qla2x00_chip_diag() - Test chip for proper operation.
2934 * Returns 0 on success.
2937 qla2x00_chip_diag(scsi_qla_host_t *vha)
2940 struct qla_hw_data *ha = vha->hw;
2941 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2942 unsigned long flags = 0;
2946 struct req_que *req = ha->req_q_map[0];
2948 /* Assume a failed state */
2949 rval = QLA_FUNCTION_FAILED;
2951 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2952 ®->flash_address);
2954 spin_lock_irqsave(&ha->hardware_lock, flags);
2956 /* Reset ISP chip. */
2957 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2960 * We need to have a delay here since the card will not respond while
2961 * in reset causing an MCA on some architectures.
2964 data = qla2x00_debounce_register(®->ctrl_status);
2965 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2967 data = RD_REG_WORD(®->ctrl_status);
2972 goto chip_diag_failed;
2974 ql_dbg(ql_dbg_init, vha, 0x007c,
2975 "Reset register cleared by chip reset.\n");
2977 /* Reset RISC processor. */
2978 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2979 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2981 /* Workaround for QLA2312 PCI parity error */
2982 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2983 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2984 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2986 data = RD_MAILBOX_REG(ha, reg, 0);
2993 goto chip_diag_failed;
2995 /* Check product ID of chip */
2996 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
2998 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2999 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3000 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3001 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3002 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3003 mb[3] != PROD_ID_3) {
3004 ql_log(ql_log_warn, vha, 0x0062,
3005 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3006 mb[1], mb[2], mb[3]);
3008 goto chip_diag_failed;
3010 ha->product_id[0] = mb[1];
3011 ha->product_id[1] = mb[2];
3012 ha->product_id[2] = mb[3];
3013 ha->product_id[3] = mb[4];
3015 /* Adjust fw RISC transfer size */
3016 if (req->length > 1024)
3017 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3019 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3022 if (IS_QLA2200(ha) &&
3023 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3024 /* Limit firmware transfer size with a 2200A */
3025 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3027 ha->device_type |= DT_ISP2200A;
3028 ha->fw_transfer_size = 128;
3031 /* Wrap Incoming Mailboxes Test. */
3032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3034 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3035 rval = qla2x00_mbx_reg_test(vha);
3037 ql_log(ql_log_warn, vha, 0x0080,
3038 "Failed mailbox send register test.\n");
3040 /* Flag a successful rval */
3042 spin_lock_irqsave(&ha->hardware_lock, flags);
3046 ql_log(ql_log_info, vha, 0x0081,
3047 "Chip diagnostics **** FAILED ****.\n");
3049 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3055 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3058 * Returns 0 on success.
3061 qla24xx_chip_diag(scsi_qla_host_t *vha)
3064 struct qla_hw_data *ha = vha->hw;
3065 struct req_que *req = ha->req_q_map[0];
3067 if (IS_P3P_TYPE(ha))
3070 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3072 rval = qla2x00_mbx_reg_test(vha);
3074 ql_log(ql_log_warn, vha, 0x0082,
3075 "Failed mailbox send register test.\n");
3077 /* Flag a successful rval */
3085 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3090 struct qla_hw_data *ha = vha->hw;
3093 ql_dbg(ql_dbg_init, vha, 0x00bd,
3094 "%s: Offload Mem is already allocated.\n",
3099 if (IS_FWI2_CAPABLE(ha)) {
3100 /* Allocate memory for Fibre Channel Event Buffer. */
3101 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3102 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3106 dma_free_coherent(&ha->pdev->dev,
3107 FCE_SIZE, ha->fce, ha->fce_dma);
3109 /* Allocate memory for Fibre Channel Event Buffer. */
3110 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3113 ql_log(ql_log_warn, vha, 0x00be,
3114 "Unable to allocate (%d KB) for FCE.\n",
3119 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3120 ha->fce_mb, &ha->fce_bufs);
3122 ql_log(ql_log_warn, vha, 0x00bf,
3123 "Unable to initialize FCE (%d).\n", rval);
3124 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3126 ha->flags.fce_enabled = 0;
3129 ql_dbg(ql_dbg_init, vha, 0x00c0,
3130 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3132 ha->flags.fce_enabled = 1;
3133 ha->fce_dma = tc_dma;
3138 dma_free_coherent(&ha->pdev->dev,
3139 EFT_SIZE, ha->eft, ha->eft_dma);
3141 /* Allocate memory for Extended Trace Buffer. */
3142 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3145 ql_log(ql_log_warn, vha, 0x00c1,
3146 "Unable to allocate (%d KB) for EFT.\n",
3151 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3153 ql_log(ql_log_warn, vha, 0x00c2,
3154 "Unable to initialize EFT (%d).\n", rval);
3155 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3159 ql_dbg(ql_dbg_init, vha, 0x00c3,
3160 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3162 ha->eft_dma = tc_dma;
3171 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3174 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3175 eft_size, fce_size, mq_size;
3176 struct qla_hw_data *ha = vha->hw;
3177 struct req_que *req = ha->req_q_map[0];
3178 struct rsp_que *rsp = ha->rsp_q_map[0];
3179 struct qla2xxx_fw_dump *fw_dump;
3183 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3184 req_q_size = rsp_q_size = 0;
3186 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3187 fixed_size = sizeof(struct qla2100_fw_dump);
3188 } else if (IS_QLA23XX(ha)) {
3189 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3190 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3192 } else if (IS_FWI2_CAPABLE(ha)) {
3193 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3194 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3195 else if (IS_QLA81XX(ha))
3196 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3197 else if (IS_QLA25XX(ha))
3198 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3200 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3202 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3205 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3207 mq_size = sizeof(struct qla2xxx_mq_chain);
3209 * Allocate maximum buffer size for all queues - Q0.
3210 * Resizing must be done at end-of-dump processing.
3212 mq_size += (ha->max_req_queues - 1) *
3213 (req->length * sizeof(request_t));
3214 mq_size += (ha->max_rsp_queues - 1) *
3215 (rsp->length * sizeof(response_t));
3217 if (ha->tgt.atio_ring)
3218 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3219 /* Allocate memory for Fibre Channel Event Buffer. */
3220 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3221 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3224 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3227 dma_free_coherent(&ha->pdev->dev,
3228 EFT_SIZE, ha->eft, ha->eft_dma);
3230 /* Allocate memory for Extended Trace Buffer. */
3231 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3234 ql_log(ql_log_warn, vha, 0x00c1,
3235 "Unable to allocate (%d KB) for EFT.\n",
3240 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3242 ql_log(ql_log_warn, vha, 0x00c2,
3243 "Unable to initialize EFT (%d).\n", rval);
3244 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3247 ql_dbg(ql_dbg_init, vha, 0x00c3,
3248 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3249 eft_size = EFT_SIZE;
3252 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3253 struct fwdt *fwdt = ha->fwdt;
3256 for (j = 0; j < 2; j++, fwdt++) {
3257 if (!fwdt->template) {
3258 ql_log(ql_log_warn, vha, 0x00ba,
3259 "-> fwdt%u no template\n", j);
3262 ql_dbg(ql_dbg_init, vha, 0x00fa,
3263 "-> fwdt%u calculating fwdump size...\n", j);
3264 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3265 vha, fwdt->template);
3266 ql_dbg(ql_dbg_init, vha, 0x00fa,
3267 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3268 j, fwdt->dump_size);
3269 dump_size += fwdt->dump_size;
3274 req_q_size = req->length * sizeof(request_t);
3275 rsp_q_size = rsp->length * sizeof(response_t);
3276 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3277 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3278 ha->chain_offset = dump_size;
3279 dump_size += mq_size + fce_size;
3281 if (ha->exchoffld_buf)
3282 dump_size += sizeof(struct qla2xxx_offld_chain) +
3284 if (ha->exlogin_buf)
3285 dump_size += sizeof(struct qla2xxx_offld_chain) +
3289 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3291 ql_dbg(ql_dbg_init, vha, 0x00c5,
3292 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3293 __func__, dump_size, ha->fw_dump_len,
3294 ha->fw_dump_alloc_len);
3296 fw_dump = vmalloc(dump_size);
3298 ql_log(ql_log_warn, vha, 0x00c4,
3299 "Unable to allocate (%d KB) for firmware dump.\n",
3302 mutex_lock(&ha->optrom_mutex);
3303 if (ha->fw_dumped) {
3304 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3306 ha->fw_dump = fw_dump;
3307 ha->fw_dump_alloc_len = dump_size;
3308 ql_dbg(ql_dbg_init, vha, 0x00c5,
3309 "Re-Allocated (%d KB) and save firmware dump.\n",
3314 ha->fw_dump = fw_dump;
3316 ha->fw_dump_len = ha->fw_dump_alloc_len =
3318 ql_dbg(ql_dbg_init, vha, 0x00c5,
3319 "Allocated (%d KB) for firmware dump.\n",
3322 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3323 mutex_unlock(&ha->optrom_mutex);
3327 ha->fw_dump->signature[0] = 'Q';
3328 ha->fw_dump->signature[1] = 'L';
3329 ha->fw_dump->signature[2] = 'G';
3330 ha->fw_dump->signature[3] = 'C';
3331 ha->fw_dump->version = htonl(1);
3333 ha->fw_dump->fixed_size = htonl(fixed_size);
3334 ha->fw_dump->mem_size = htonl(mem_size);
3335 ha->fw_dump->req_q_size = htonl(req_q_size);
3336 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3338 ha->fw_dump->eft_size = htonl(eft_size);
3339 ha->fw_dump->eft_addr_l =
3340 htonl(LSD(ha->eft_dma));
3341 ha->fw_dump->eft_addr_h =
3342 htonl(MSD(ha->eft_dma));
3344 ha->fw_dump->header_size =
3346 (struct qla2xxx_fw_dump, isp));
3348 mutex_unlock(&ha->optrom_mutex);
3354 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3356 #define MPS_MASK 0xe0
3361 if (!IS_QLA81XX(vha->hw))
3364 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3365 if (rval != QLA_SUCCESS) {
3366 ql_log(ql_log_warn, vha, 0x0105,
3367 "Unable to acquire semaphore.\n");
3371 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3372 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3373 if (rval != QLA_SUCCESS) {
3374 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3379 if (dc == (dw & MPS_MASK))
3384 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3385 if (rval != QLA_SUCCESS) {
3386 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3390 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3391 if (rval != QLA_SUCCESS) {
3392 ql_log(ql_log_warn, vha, 0x006d,
3393 "Unable to release semaphore.\n");
3401 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3403 /* Don't try to reallocate the array */
3404 if (req->outstanding_cmds)
3407 if (!IS_FWI2_CAPABLE(ha))
3408 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3410 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3411 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3413 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3416 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3420 if (!req->outstanding_cmds) {
3422 * Try to allocate a minimal size just so we can get through
3425 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3426 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3430 if (!req->outstanding_cmds) {
3431 ql_log(ql_log_fatal, NULL, 0x0126,
3432 "Failed to allocate memory for "
3433 "outstanding_cmds for req_que %p.\n", req);
3434 req->num_outstanding_cmds = 0;
3435 return QLA_FUNCTION_FAILED;
3442 #define PRINT_FIELD(_field, _flag, _str) { \
3443 if (a0->_field & _flag) {\
3449 len = snprintf(ptr, leftover, "%s", _str); \
3456 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3459 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3460 u8 str[STR_LEN], *ptr, p;
3463 memset(str, 0, STR_LEN);
3464 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3465 ql_dbg(ql_dbg_init, vha, 0x015a,
3466 "SFP MFG Name: %s\n", str);
3468 memset(str, 0, STR_LEN);
3469 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3470 ql_dbg(ql_dbg_init, vha, 0x015c,
3471 "SFP Part Name: %s\n", str);
3474 memset(str, 0, STR_LEN);
3478 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3479 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3480 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3481 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3482 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3483 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3484 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3485 ql_dbg(ql_dbg_init, vha, 0x0160,
3486 "SFP Media: %s\n", str);
3489 memset(str, 0, STR_LEN);
3493 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3494 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3495 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3496 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3497 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3498 ql_dbg(ql_dbg_init, vha, 0x0196,
3499 "SFP Link Length: %s\n", str);
3501 memset(str, 0, STR_LEN);
3505 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3506 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3507 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3508 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3509 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3510 ql_dbg(ql_dbg_init, vha, 0x016e,
3511 "SFP FC Link Tech: %s\n", str);
3514 ql_dbg(ql_dbg_init, vha, 0x016f,
3515 "SFP Distant: %d km\n", a0->length_km);
3516 if (a0->length_100m)
3517 ql_dbg(ql_dbg_init, vha, 0x0170,
3518 "SFP Distant: %d m\n", a0->length_100m*100);
3519 if (a0->length_50um_10m)
3520 ql_dbg(ql_dbg_init, vha, 0x0189,
3521 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3522 if (a0->length_62um_10m)
3523 ql_dbg(ql_dbg_init, vha, 0x018a,
3524 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3525 if (a0->length_om4_10m)
3526 ql_dbg(ql_dbg_init, vha, 0x0194,
3527 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3528 if (a0->length_om3_10m)
3529 ql_dbg(ql_dbg_init, vha, 0x0195,
3530 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3536 * QLA_SUCCESS: no action
3537 * QLA_INTERFACE_ERROR: SFP is not there.
3538 * QLA_FUNCTION_FAILED: detected New SFP
3541 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3543 int rc = QLA_SUCCESS;
3544 struct sff_8247_a0 *a;
3545 struct qla_hw_data *ha = vha->hw;
3547 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3550 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3554 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3555 qla2xxx_print_sfp_info(vha);
3557 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3559 ha->flags.detected_lr_sfp = 1;
3561 if (a->length_km > 5 || a->length_100m > 50)
3562 ha->long_range_distance = LR_DISTANCE_10K;
3564 ha->long_range_distance = LR_DISTANCE_5K;
3566 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3567 ql_dbg(ql_dbg_async, vha, 0x507b,
3568 "Detected Long Range SFP.\n");
3571 ha->flags.detected_lr_sfp = 0;
3572 if (ha->flags.using_lr_setting)
3573 ql_dbg(ql_dbg_async, vha, 0x5084,
3574 "Detected Short Range SFP.\n");
3577 if (!vha->flags.init_done)
3584 * qla2x00_setup_chip() - Load and start RISC firmware.
3587 * Returns 0 on success.
3590 qla2x00_setup_chip(scsi_qla_host_t *vha)
3593 uint32_t srisc_address = 0;
3594 struct qla_hw_data *ha = vha->hw;
3595 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3596 unsigned long flags;
3597 uint16_t fw_major_version;
3599 if (IS_P3P_TYPE(ha)) {
3600 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3601 if (rval == QLA_SUCCESS) {
3602 qla2x00_stop_firmware(vha);
3603 goto enable_82xx_npiv;
3608 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3609 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3610 spin_lock_irqsave(&ha->hardware_lock, flags);
3611 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3612 RD_REG_WORD(®->hccr);
3613 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3616 qla81xx_mpi_sync(vha);
3618 /* Load firmware sequences */
3619 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3620 if (rval == QLA_SUCCESS) {
3621 ql_dbg(ql_dbg_init, vha, 0x00c9,
3622 "Verifying Checksum of loaded RISC code.\n");
3624 rval = qla2x00_verify_checksum(vha, srisc_address);
3625 if (rval == QLA_SUCCESS) {
3626 /* Start firmware execution. */
3627 ql_dbg(ql_dbg_init, vha, 0x00ca,
3628 "Starting firmware.\n");
3631 ha->flags.exlogins_enabled = 1;
3633 if (qla_is_exch_offld_enabled(vha))
3634 ha->flags.exchoffld_enabled = 1;
3636 rval = qla2x00_execute_fw(vha, srisc_address);
3637 /* Retrieve firmware information. */
3638 if (rval == QLA_SUCCESS) {
3639 qla24xx_detect_sfp(vha);
3641 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3643 (ha->zio_mode == QLA_ZIO_MODE_6))
3644 qla27xx_set_zio_threshold(vha,
3645 ha->last_zio_threshold);
3647 rval = qla2x00_set_exlogins_buffer(vha);
3648 if (rval != QLA_SUCCESS)
3651 rval = qla2x00_set_exchoffld_buffer(vha);
3652 if (rval != QLA_SUCCESS)
3656 fw_major_version = ha->fw_major_version;
3657 if (IS_P3P_TYPE(ha))
3658 qla82xx_check_md_needed(vha);
3660 rval = qla2x00_get_fw_version(vha);
3661 if (rval != QLA_SUCCESS)
3663 ha->flags.npiv_supported = 0;
3664 if (IS_QLA2XXX_MIDTYPE(ha) &&
3665 (ha->fw_attributes & BIT_2)) {
3666 ha->flags.npiv_supported = 1;
3667 if ((!ha->max_npiv_vports) ||
3668 ((ha->max_npiv_vports + 1) %
3669 MIN_MULTI_ID_FABRIC))
3670 ha->max_npiv_vports =
3671 MIN_MULTI_ID_FABRIC - 1;
3673 qla2x00_get_resource_cnts(vha);
3676 * Allocate the array of outstanding commands
3677 * now that we know the firmware resources.
3679 rval = qla2x00_alloc_outstanding_cmds(ha,
3681 if (rval != QLA_SUCCESS)
3684 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3685 qla2x00_alloc_offload_mem(vha);
3687 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3688 qla2x00_alloc_fw_dump(vha);
3694 ql_log(ql_log_fatal, vha, 0x00cd,
3695 "ISP Firmware failed checksum.\n");
3701 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3702 /* Enable proper parity. */
3703 spin_lock_irqsave(&ha->hardware_lock, flags);
3706 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3708 /* SRAM, Instruction RAM and GP RAM parity */
3709 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3710 RD_REG_WORD(®->hccr);
3711 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3714 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3715 ha->flags.fac_supported = 1;
3716 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3719 rval = qla81xx_fac_get_sector_size(vha, &size);
3720 if (rval == QLA_SUCCESS) {
3721 ha->flags.fac_supported = 1;
3722 ha->fdt_block_size = size << 2;
3724 ql_log(ql_log_warn, vha, 0x00ce,
3725 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3726 ha->fw_major_version, ha->fw_minor_version,
3727 ha->fw_subminor_version);
3729 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3731 ha->flags.fac_supported = 0;
3738 ql_log(ql_log_fatal, vha, 0x00cf,
3739 "Setup chip ****FAILED****.\n");
3746 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3747 * @rsp: response queue
3749 * Beginning of request ring has initialization control block already built
3750 * by nvram config routine.
3752 * Returns 0 on success.
3755 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3760 rsp->ring_ptr = rsp->ring;
3761 rsp->ring_index = 0;
3762 rsp->status_srb = NULL;
3763 pkt = rsp->ring_ptr;
3764 for (cnt = 0; cnt < rsp->length; cnt++) {
3765 pkt->signature = RESPONSE_PROCESSED;
3771 * qla2x00_update_fw_options() - Read and process firmware options.
3774 * Returns 0 on success.
3777 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3779 uint16_t swing, emphasis, tx_sens, rx_sens;
3780 struct qla_hw_data *ha = vha->hw;
3782 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3783 qla2x00_get_fw_options(vha, ha->fw_options);
3785 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3788 /* Serial Link options. */
3789 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3790 "Serial link options.\n");
3791 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3792 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3794 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3795 if (ha->fw_seriallink_options[3] & BIT_2) {
3796 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3799 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3800 emphasis = (ha->fw_seriallink_options[2] &
3801 (BIT_4 | BIT_3)) >> 3;
3802 tx_sens = ha->fw_seriallink_options[0] &
3803 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3804 rx_sens = (ha->fw_seriallink_options[0] &
3805 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3806 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3807 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3810 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3811 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3812 ha->fw_options[10] |= BIT_5 |
3813 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3814 (tx_sens & (BIT_1 | BIT_0));
3817 swing = (ha->fw_seriallink_options[2] &
3818 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3819 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3820 tx_sens = ha->fw_seriallink_options[1] &
3821 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3822 rx_sens = (ha->fw_seriallink_options[1] &
3823 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3824 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3825 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3828 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3829 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3830 ha->fw_options[11] |= BIT_5 |
3831 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3832 (tx_sens & (BIT_1 | BIT_0));
3836 /* Return command IOCBs without waiting for an ABTS to complete. */
3837 ha->fw_options[3] |= BIT_13;
3840 if (ha->flags.enable_led_scheme)
3841 ha->fw_options[2] |= BIT_12;
3843 /* Detect ISP6312. */
3845 ha->fw_options[2] |= BIT_13;
3847 /* Set Retry FLOGI in case of P2P connection */
3848 if (ha->operating_mode == P2P) {
3849 ha->fw_options[2] |= BIT_3;
3850 ql_dbg(ql_dbg_disc, vha, 0x2100,
3851 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3852 __func__, ha->fw_options[2]);
3855 /* Update firmware options. */
3856 qla2x00_set_fw_options(vha, ha->fw_options);
3860 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3863 struct qla_hw_data *ha = vha->hw;
3865 if (IS_P3P_TYPE(ha))
3868 /* Hold status IOCBs until ABTS response received. */
3870 ha->fw_options[3] |= BIT_12;
3872 /* Set Retry FLOGI in case of P2P connection */
3873 if (ha->operating_mode == P2P) {
3874 ha->fw_options[2] |= BIT_3;
3875 ql_dbg(ql_dbg_disc, vha, 0x2101,
3876 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3877 __func__, ha->fw_options[2]);
3880 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3881 if (ql2xmvasynctoatio &&
3882 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3883 if (qla_tgt_mode_enabled(vha) ||
3884 qla_dual_mode_enabled(vha))
3885 ha->fw_options[2] |= BIT_11;
3887 ha->fw_options[2] &= ~BIT_11;
3890 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3893 * Tell FW to track each exchange to prevent
3894 * driver from using stale exchange.
3896 if (qla_tgt_mode_enabled(vha) ||
3897 qla_dual_mode_enabled(vha))
3898 ha->fw_options[2] |= BIT_4;
3900 ha->fw_options[2] &= ~BIT_4;
3902 /* Reserve 1/2 of emergency exchanges for ELS.*/
3903 if (qla2xuseresexchforels)
3904 ha->fw_options[2] |= BIT_8;
3906 ha->fw_options[2] &= ~BIT_8;
3909 ql_dbg(ql_dbg_init, vha, 0x00e8,
3910 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3911 __func__, ha->fw_options[1], ha->fw_options[2],
3912 ha->fw_options[3], vha->host->active_mode);
3914 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3915 qla2x00_set_fw_options(vha, ha->fw_options);
3917 /* Update Serial Link options. */
3918 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3921 rval = qla2x00_set_serdes_params(vha,
3922 le16_to_cpu(ha->fw_seriallink_options24[1]),
3923 le16_to_cpu(ha->fw_seriallink_options24[2]),
3924 le16_to_cpu(ha->fw_seriallink_options24[3]));
3925 if (rval != QLA_SUCCESS) {
3926 ql_log(ql_log_warn, vha, 0x0104,
3927 "Unable to update Serial Link options (%x).\n", rval);
3932 qla2x00_config_rings(struct scsi_qla_host *vha)
3934 struct qla_hw_data *ha = vha->hw;
3935 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3936 struct req_que *req = ha->req_q_map[0];
3937 struct rsp_que *rsp = ha->rsp_q_map[0];
3939 /* Setup ring parameters in initialization control block. */
3940 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3941 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3942 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3943 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3944 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3945 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3947 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3948 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3949 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3950 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3951 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3955 qla24xx_config_rings(struct scsi_qla_host *vha)
3957 struct qla_hw_data *ha = vha->hw;
3958 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3959 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3960 struct qla_msix_entry *msix;
3961 struct init_cb_24xx *icb;
3963 struct req_que *req = ha->req_q_map[0];
3964 struct rsp_que *rsp = ha->rsp_q_map[0];
3966 /* Setup ring parameters in initialization control block. */
3967 icb = (struct init_cb_24xx *)ha->init_cb;
3968 icb->request_q_outpointer = cpu_to_le16(0);
3969 icb->response_q_inpointer = cpu_to_le16(0);
3970 icb->request_q_length = cpu_to_le16(req->length);
3971 icb->response_q_length = cpu_to_le16(rsp->length);
3972 put_unaligned_le64(req->dma, &icb->request_q_address);
3973 put_unaligned_le64(rsp->dma, &icb->response_q_address);
3975 /* Setup ATIO queue dma pointers for target mode */
3976 icb->atio_q_inpointer = cpu_to_le16(0);
3977 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3978 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
3980 if (IS_SHADOW_REG_CAPABLE(ha))
3981 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3983 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3985 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3986 icb->rid = cpu_to_le16(rid);
3987 if (ha->flags.msix_enabled) {
3988 msix = &ha->msix_entries[1];
3989 ql_dbg(ql_dbg_init, vha, 0x0019,
3990 "Registering vector 0x%x for base que.\n",
3992 icb->msix = cpu_to_le16(msix->entry);
3994 /* Use alternate PCI bus number */
3996 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
3997 /* Use alternate PCI devfn */
3999 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4001 /* Use Disable MSIX Handshake mode for capable adapters */
4002 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4003 (ha->flags.msix_enabled)) {
4004 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4005 ha->flags.disable_msix_handshake = 1;
4006 ql_dbg(ql_dbg_init, vha, 0x00fe,
4007 "MSIX Handshake Disable Mode turned on.\n");
4009 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4011 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4013 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
4014 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
4015 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
4016 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4018 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4019 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4020 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4021 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4024 qlt_24xx_config_rings(vha);
4026 /* If the user has configured the speed, set it here */
4027 if (ha->set_data_rate) {
4028 ql_dbg(ql_dbg_init, vha, 0x00fd,
4029 "Speed set by user : %s Gbps \n",
4030 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4031 icb->firmware_options_3 = (ha->set_data_rate << 13);
4035 RD_REG_DWORD(&ioreg->hccr);
4039 * qla2x00_init_rings() - Initializes firmware.
4042 * Beginning of request ring has initialization control block already built
4043 * by nvram config routine.
4045 * Returns 0 on success.
4048 qla2x00_init_rings(scsi_qla_host_t *vha)
4051 unsigned long flags = 0;
4053 struct qla_hw_data *ha = vha->hw;
4054 struct req_que *req;
4055 struct rsp_que *rsp;
4056 struct mid_init_cb_24xx *mid_init_cb =
4057 (struct mid_init_cb_24xx *) ha->init_cb;
4059 spin_lock_irqsave(&ha->hardware_lock, flags);
4061 /* Clear outstanding commands array. */
4062 for (que = 0; que < ha->max_req_queues; que++) {
4063 req = ha->req_q_map[que];
4064 if (!req || !test_bit(que, ha->req_qid_map))
4066 req->out_ptr = (void *)(req->ring + req->length);
4068 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4069 req->outstanding_cmds[cnt] = NULL;
4071 req->current_outstanding_cmd = 1;
4073 /* Initialize firmware. */
4074 req->ring_ptr = req->ring;
4075 req->ring_index = 0;
4076 req->cnt = req->length;
4079 for (que = 0; que < ha->max_rsp_queues; que++) {
4080 rsp = ha->rsp_q_map[que];
4081 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4083 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4085 /* Initialize response queue entries */
4087 qlafx00_init_response_q_entries(rsp);
4089 qla2x00_init_response_q_entries(rsp);
4092 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4093 ha->tgt.atio_ring_index = 0;
4094 /* Initialize ATIO queue entries */
4095 qlt_init_atio_q_entries(vha);
4097 ha->isp_ops->config_rings(vha);
4099 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4101 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4103 if (IS_QLAFX00(ha)) {
4104 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4108 /* Update any ISP specific firmware options before initialization. */
4109 ha->isp_ops->update_fw_options(vha);
4111 if (ha->flags.npiv_supported) {
4112 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4113 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4114 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4117 if (IS_FWI2_CAPABLE(ha)) {
4118 mid_init_cb->options = cpu_to_le16(BIT_1);
4119 mid_init_cb->init_cb.execution_throttle =
4120 cpu_to_le16(ha->cur_fw_xcb_count);
4121 ha->flags.dport_enabled =
4122 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4123 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4124 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4125 /* FA-WWPN Status */
4126 ha->flags.fawwpn_enabled =
4127 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4128 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4129 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4132 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4135 ql_log(ql_log_fatal, vha, 0x00d2,
4136 "Init Firmware **** FAILED ****.\n");
4138 ql_dbg(ql_dbg_init, vha, 0x00d3,
4139 "Init Firmware -- success.\n");
4141 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4148 * qla2x00_fw_ready() - Waits for firmware ready.
4151 * Returns 0 on success.
4154 qla2x00_fw_ready(scsi_qla_host_t *vha)
4157 unsigned long wtime, mtime, cs84xx_time;
4158 uint16_t min_wait; /* Minimum wait time if loop is down */
4159 uint16_t wait_time; /* Wait time if loop is coming ready */
4161 struct qla_hw_data *ha = vha->hw;
4163 if (IS_QLAFX00(vha->hw))
4164 return qlafx00_fw_ready(vha);
4168 /* Time to wait for loop down */
4169 if (IS_P3P_TYPE(ha))
4175 * Firmware should take at most one RATOV to login, plus 5 seconds for
4176 * our own processing.
4178 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4179 wait_time = min_wait;
4182 /* Min wait time if loop down */
4183 mtime = jiffies + (min_wait * HZ);
4185 /* wait time before firmware ready */
4186 wtime = jiffies + (wait_time * HZ);
4188 /* Wait for ISP to finish LIP */
4189 if (!vha->flags.init_done)
4190 ql_log(ql_log_info, vha, 0x801e,
4191 "Waiting for LIP to complete.\n");
4194 memset(state, -1, sizeof(state));
4195 rval = qla2x00_get_firmware_state(vha, state);
4196 if (rval == QLA_SUCCESS) {
4197 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4198 vha->device_flags &= ~DFLG_NO_CABLE;
4200 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4201 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4202 "fw_state=%x 84xx=%x.\n", state[0],
4204 if ((state[2] & FSTATE_LOGGED_IN) &&
4205 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4206 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4207 "Sending verify iocb.\n");
4209 cs84xx_time = jiffies;
4210 rval = qla84xx_init_chip(vha);
4211 if (rval != QLA_SUCCESS) {
4214 "Init chip failed.\n");
4218 /* Add time taken to initialize. */
4219 cs84xx_time = jiffies - cs84xx_time;
4220 wtime += cs84xx_time;
4221 mtime += cs84xx_time;
4222 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4223 "Increasing wait time by %ld. "
4224 "New time %ld.\n", cs84xx_time,
4227 } else if (state[0] == FSTATE_READY) {
4228 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4229 "F/W Ready - OK.\n");
4231 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4232 &ha->login_timeout, &ha->r_a_tov);
4238 rval = QLA_FUNCTION_FAILED;
4240 if (atomic_read(&vha->loop_down_timer) &&
4241 state[0] != FSTATE_READY) {
4242 /* Loop down. Timeout on min_wait for states
4243 * other than Wait for Login.
4245 if (time_after_eq(jiffies, mtime)) {
4246 ql_log(ql_log_info, vha, 0x8038,
4247 "Cable is unplugged...\n");
4249 vha->device_flags |= DFLG_NO_CABLE;
4254 /* Mailbox cmd failed. Timeout on min_wait. */
4255 if (time_after_eq(jiffies, mtime) ||
4256 ha->flags.isp82xx_fw_hung)
4260 if (time_after_eq(jiffies, wtime))
4263 /* Delay for a while */
4267 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4268 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4269 state[1], state[2], state[3], state[4], state[5], jiffies);
4271 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4272 ql_log(ql_log_warn, vha, 0x803b,
4273 "Firmware ready **** FAILED ****.\n");
4280 * qla2x00_configure_hba
4281 * Setup adapter context.
4284 * ha = adapter state pointer.
4293 qla2x00_configure_hba(scsi_qla_host_t *vha)
4302 char connect_type[22];
4303 struct qla_hw_data *ha = vha->hw;
4304 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4306 unsigned long flags;
4308 /* Get host addresses. */
4309 rval = qla2x00_get_adapter_id(vha,
4310 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4311 if (rval != QLA_SUCCESS) {
4312 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4313 IS_CNA_CAPABLE(ha) ||
4314 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4315 ql_dbg(ql_dbg_disc, vha, 0x2008,
4316 "Loop is in a transition state.\n");
4318 ql_log(ql_log_warn, vha, 0x2009,
4319 "Unable to get host loop ID.\n");
4320 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4321 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4322 ql_log(ql_log_warn, vha, 0x1151,
4323 "Doing link init.\n");
4324 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4327 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4333 ql_log(ql_log_info, vha, 0x200a,
4334 "Cannot get topology - retrying.\n");
4335 return (QLA_FUNCTION_FAILED);
4338 vha->loop_id = loop_id;
4341 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4342 ha->operating_mode = LOOP;
4347 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4348 ha->current_topology = ISP_CFG_NL;
4349 strcpy(connect_type, "(Loop)");
4353 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4354 ha->switch_cap = sw_cap;
4355 ha->current_topology = ISP_CFG_FL;
4356 strcpy(connect_type, "(FL_Port)");
4360 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4361 ha->operating_mode = P2P;
4362 ha->current_topology = ISP_CFG_N;
4363 strcpy(connect_type, "(N_Port-to-N_Port)");
4367 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4368 ha->switch_cap = sw_cap;
4369 ha->operating_mode = P2P;
4370 ha->current_topology = ISP_CFG_F;
4371 strcpy(connect_type, "(F_Port)");
4375 ql_dbg(ql_dbg_disc, vha, 0x200f,
4376 "HBA in unknown topology %x, using NL.\n", topo);
4377 ha->current_topology = ISP_CFG_NL;
4378 strcpy(connect_type, "(Loop)");
4382 /* Save Host port and loop ID. */
4383 /* byte order - Big Endian */
4384 id.b.domain = domain;
4388 spin_lock_irqsave(&ha->hardware_lock, flags);
4389 if (!(topo == 2 && ha->flags.n2n_bigger))
4390 qlt_update_host_map(vha, id);
4391 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4393 if (!vha->flags.init_done)
4394 ql_log(ql_log_info, vha, 0x2010,
4395 "Topology - %s, Host Loop address 0x%x.\n",
4396 connect_type, vha->loop_id);
4402 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4407 uint64_t zero[2] = { 0 };
4408 struct qla_hw_data *ha = vha->hw;
4409 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4410 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4412 if (len > sizeof(zero))
4414 if (memcmp(model, &zero, len) != 0) {
4415 strncpy(ha->model_number, model, len);
4416 st = en = ha->model_number;
4419 if (*en != 0x20 && *en != 0x00)
4424 index = (ha->pdev->subsystem_device & 0xff);
4426 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4427 index < QLA_MODEL_NAMES)
4428 strncpy(ha->model_desc,
4429 qla2x00_model_name[index * 2 + 1],
4430 sizeof(ha->model_desc) - 1);
4432 index = (ha->pdev->subsystem_device & 0xff);
4434 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4435 index < QLA_MODEL_NAMES) {
4436 strcpy(ha->model_number,
4437 qla2x00_model_name[index * 2]);
4438 strncpy(ha->model_desc,
4439 qla2x00_model_name[index * 2 + 1],
4440 sizeof(ha->model_desc) - 1);
4442 strcpy(ha->model_number, def);
4445 if (IS_FWI2_CAPABLE(ha))
4446 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4447 sizeof(ha->model_desc));
4450 /* On sparc systems, obtain port and node WWN from firmware
4453 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4456 struct qla_hw_data *ha = vha->hw;
4457 struct pci_dev *pdev = ha->pdev;
4458 struct device_node *dp = pci_device_to_OF_node(pdev);
4462 val = of_get_property(dp, "port-wwn", &len);
4463 if (val && len >= WWN_SIZE)
4464 memcpy(nv->port_name, val, WWN_SIZE);
4466 val = of_get_property(dp, "node-wwn", &len);
4467 if (val && len >= WWN_SIZE)
4468 memcpy(nv->node_name, val, WWN_SIZE);
4473 * NVRAM configuration for ISP 2xxx
4476 * ha = adapter block pointer.
4479 * initialization control block in response_ring
4480 * host adapters parameters in host adapter block
4486 qla2x00_nvram_config(scsi_qla_host_t *vha)
4491 uint8_t *dptr1, *dptr2;
4492 struct qla_hw_data *ha = vha->hw;
4493 init_cb_t *icb = ha->init_cb;
4494 nvram_t *nv = ha->nvram;
4495 uint8_t *ptr = ha->nvram;
4496 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4500 /* Determine NVRAM starting address. */
4501 ha->nvram_size = sizeof(*nv);
4503 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4504 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4505 ha->nvram_base = 0x80;
4507 /* Get NVRAM data and calculate checksum. */
4508 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4509 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4512 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4513 "Contents of NVRAM.\n");
4514 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4515 nv, ha->nvram_size);
4517 /* Bad NVRAM data, set defaults parameters. */
4518 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4519 nv->nvram_version < 1) {
4520 /* Reset NVRAM data. */
4521 ql_log(ql_log_warn, vha, 0x0064,
4522 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4523 chksum, nv->id, nv->nvram_version);
4524 ql_log(ql_log_warn, vha, 0x0065,
4526 "functioning (yet invalid -- WWPN) defaults.\n");
4529 * Set default initialization control block.
4531 memset(nv, 0, ha->nvram_size);
4532 nv->parameter_block_version = ICB_VERSION;
4534 if (IS_QLA23XX(ha)) {
4535 nv->firmware_options[0] = BIT_2 | BIT_1;
4536 nv->firmware_options[1] = BIT_7 | BIT_5;
4537 nv->add_firmware_options[0] = BIT_5;
4538 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4539 nv->frame_payload_size = 2048;
4540 nv->special_options[1] = BIT_7;
4541 } else if (IS_QLA2200(ha)) {
4542 nv->firmware_options[0] = BIT_2 | BIT_1;
4543 nv->firmware_options[1] = BIT_7 | BIT_5;
4544 nv->add_firmware_options[0] = BIT_5;
4545 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4546 nv->frame_payload_size = 1024;
4547 } else if (IS_QLA2100(ha)) {
4548 nv->firmware_options[0] = BIT_3 | BIT_1;
4549 nv->firmware_options[1] = BIT_5;
4550 nv->frame_payload_size = 1024;
4553 nv->max_iocb_allocation = cpu_to_le16(256);
4554 nv->execution_throttle = cpu_to_le16(16);
4555 nv->retry_count = 8;
4556 nv->retry_delay = 1;
4558 nv->port_name[0] = 33;
4559 nv->port_name[3] = 224;
4560 nv->port_name[4] = 139;
4562 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4564 nv->login_timeout = 4;
4567 * Set default host adapter parameters
4569 nv->host_p[1] = BIT_2;
4570 nv->reset_delay = 5;
4571 nv->port_down_retry_count = 8;
4572 nv->max_luns_per_target = cpu_to_le16(8);
4573 nv->link_down_timeout = 60;
4578 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4580 * The SN2 does not provide BIOS emulation which means you can't change
4581 * potentially bogus BIOS settings. Force the use of default settings
4582 * for link rate and frame size. Hope that the rest of the settings
4585 if (ia64_platform_is("sn2")) {
4586 nv->frame_payload_size = 2048;
4588 nv->special_options[1] = BIT_7;
4592 /* Reset Initialization control block */
4593 memset(icb, 0, ha->init_cb_size);
4596 * Setup driver NVRAM options.
4598 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4599 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4600 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4601 nv->firmware_options[1] &= ~BIT_4;
4603 if (IS_QLA23XX(ha)) {
4604 nv->firmware_options[0] |= BIT_2;
4605 nv->firmware_options[0] &= ~BIT_3;
4606 nv->special_options[0] &= ~BIT_6;
4607 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4609 if (IS_QLA2300(ha)) {
4610 if (ha->fb_rev == FPM_2310) {
4611 strcpy(ha->model_number, "QLA2310");
4613 strcpy(ha->model_number, "QLA2300");
4616 qla2x00_set_model_info(vha, nv->model_number,
4617 sizeof(nv->model_number), "QLA23xx");
4619 } else if (IS_QLA2200(ha)) {
4620 nv->firmware_options[0] |= BIT_2;
4622 * 'Point-to-point preferred, else loop' is not a safe
4623 * connection mode setting.
4625 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4627 /* Force 'loop preferred, else point-to-point'. */
4628 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4629 nv->add_firmware_options[0] |= BIT_5;
4631 strcpy(ha->model_number, "QLA22xx");
4632 } else /*if (IS_QLA2100(ha))*/ {
4633 strcpy(ha->model_number, "QLA2100");
4637 * Copy over NVRAM RISC parameter block to initialization control block.
4639 dptr1 = (uint8_t *)icb;
4640 dptr2 = (uint8_t *)&nv->parameter_block_version;
4641 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4643 *dptr1++ = *dptr2++;
4645 /* Copy 2nd half. */
4646 dptr1 = (uint8_t *)icb->add_firmware_options;
4647 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4649 *dptr1++ = *dptr2++;
4650 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4651 /* Use alternate WWN? */
4652 if (nv->host_p[1] & BIT_7) {
4653 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4654 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4657 /* Prepare nodename */
4658 if ((icb->firmware_options[1] & BIT_6) == 0) {
4660 * Firmware will apply the following mask if the nodename was
4663 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4664 icb->node_name[0] &= 0xF0;
4668 * Set host adapter parameters.
4672 * BIT_7 in the host-parameters section allows for modification to
4673 * internal driver logging.
4675 if (nv->host_p[0] & BIT_7)
4676 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4677 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4678 /* Always load RISC code on non ISP2[12]00 chips. */
4679 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4680 ha->flags.disable_risc_code_load = 0;
4681 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4682 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4683 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4684 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4685 ha->flags.disable_serdes = 0;
4687 ha->operating_mode =
4688 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4690 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4691 sizeof(ha->fw_seriallink_options));
4693 /* save HBA serial number */
4694 ha->serial0 = icb->port_name[5];
4695 ha->serial1 = icb->port_name[6];
4696 ha->serial2 = icb->port_name[7];
4697 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4698 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4700 icb->execution_throttle = cpu_to_le16(0xFFFF);
4702 ha->retry_count = nv->retry_count;
4704 /* Set minimum login_timeout to 4 seconds. */
4705 if (nv->login_timeout != ql2xlogintimeout)
4706 nv->login_timeout = ql2xlogintimeout;
4707 if (nv->login_timeout < 4)
4708 nv->login_timeout = 4;
4709 ha->login_timeout = nv->login_timeout;
4711 /* Set minimum RATOV to 100 tenths of a second. */
4714 ha->loop_reset_delay = nv->reset_delay;
4716 /* Link Down Timeout = 0:
4718 * When Port Down timer expires we will start returning
4719 * I/O's to OS with "DID_NO_CONNECT".
4721 * Link Down Timeout != 0:
4723 * The driver waits for the link to come up after link down
4724 * before returning I/Os to OS with "DID_NO_CONNECT".
4726 if (nv->link_down_timeout == 0) {
4727 ha->loop_down_abort_time =
4728 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4730 ha->link_down_timeout = nv->link_down_timeout;
4731 ha->loop_down_abort_time =
4732 (LOOP_DOWN_TIME - ha->link_down_timeout);
4736 * Need enough time to try and get the port back.
4738 ha->port_down_retry_count = nv->port_down_retry_count;
4739 if (qlport_down_retry)
4740 ha->port_down_retry_count = qlport_down_retry;
4741 /* Set login_retry_count */
4742 ha->login_retry_count = nv->retry_count;
4743 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4744 ha->port_down_retry_count > 3)
4745 ha->login_retry_count = ha->port_down_retry_count;
4746 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4747 ha->login_retry_count = ha->port_down_retry_count;
4748 if (ql2xloginretrycount)
4749 ha->login_retry_count = ql2xloginretrycount;
4751 icb->lun_enables = cpu_to_le16(0);
4752 icb->command_resource_count = 0;
4753 icb->immediate_notify_resource_count = 0;
4754 icb->timeout = cpu_to_le16(0);
4756 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4758 icb->firmware_options[0] &= ~BIT_3;
4759 icb->add_firmware_options[0] &=
4760 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4761 icb->add_firmware_options[0] |= BIT_2;
4762 icb->response_accumulation_timer = 3;
4763 icb->interrupt_delay_timer = 5;
4765 vha->flags.process_response_queue = 1;
4768 if (!vha->flags.init_done) {
4769 ha->zio_mode = icb->add_firmware_options[0] &
4770 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4771 ha->zio_timer = icb->interrupt_delay_timer ?
4772 icb->interrupt_delay_timer : 2;
4774 icb->add_firmware_options[0] &=
4775 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4776 vha->flags.process_response_queue = 0;
4777 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4778 ha->zio_mode = QLA_ZIO_MODE_6;
4780 ql_log(ql_log_info, vha, 0x0068,
4781 "ZIO mode %d enabled; timer delay (%d us).\n",
4782 ha->zio_mode, ha->zio_timer * 100);
4784 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4785 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4786 vha->flags.process_response_queue = 1;
4791 ql_log(ql_log_warn, vha, 0x0069,
4792 "NVRAM configuration failed.\n");
4798 qla2x00_rport_del(void *data)
4800 fc_port_t *fcport = data;
4801 struct fc_rport *rport;
4802 unsigned long flags;
4804 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4805 rport = fcport->drport ? fcport->drport : fcport->rport;
4806 fcport->drport = NULL;
4807 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4809 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4810 "%s %8phN. rport %p roles %x\n",
4811 __func__, fcport->port_name, rport,
4814 fc_remote_port_delete(rport);
4818 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4822 old_state = atomic_read(&fcport->state);
4823 atomic_set(&fcport->state, state);
4825 /* Don't print state transitions during initial allocation of fcport */
4826 if (old_state && old_state != state) {
4827 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4828 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4829 fcport->port_name, port_state_str[old_state],
4830 port_state_str[state], fcport->d_id.b.domain,
4831 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4836 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4838 * @flags: allocation flags
4840 * Returns a pointer to the allocated fcport, or NULL, if none available.
4843 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4847 fcport = kzalloc(sizeof(fc_port_t), flags);
4851 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4852 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4854 if (!fcport->ct_desc.ct_sns) {
4855 ql_log(ql_log_warn, vha, 0xd049,
4856 "Failed to allocate ct_sns request.\n");
4861 /* Setup fcport template structure. */
4863 fcport->port_type = FCT_UNKNOWN;
4864 fcport->loop_id = FC_NO_LOOP_ID;
4865 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4866 fcport->supported_classes = FC_COS_UNSPECIFIED;
4867 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4869 fcport->disc_state = DSC_DELETED;
4870 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4871 fcport->deleted = QLA_SESS_DELETED;
4872 fcport->login_retry = vha->hw->login_retry_count;
4873 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4874 fcport->logout_on_delete = 1;
4876 if (!fcport->ct_desc.ct_sns) {
4877 ql_log(ql_log_warn, vha, 0xd049,
4878 "Failed to allocate ct_sns request.\n");
4883 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4884 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4885 INIT_LIST_HEAD(&fcport->gnl_entry);
4886 INIT_LIST_HEAD(&fcport->list);
4892 qla2x00_free_fcport(fc_port_t *fcport)
4894 if (fcport->ct_desc.ct_sns) {
4895 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4896 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4897 fcport->ct_desc.ct_sns_dma);
4899 fcport->ct_desc.ct_sns = NULL;
4901 list_del(&fcport->list);
4902 qla2x00_clear_loop_id(fcport);
4907 * qla2x00_configure_loop
4908 * Updates Fibre Channel Device Database with what is actually on loop.
4911 * ha = adapter block pointer.
4916 * 2 = database was full and device was not configured.
4919 qla2x00_configure_loop(scsi_qla_host_t *vha)
4922 unsigned long flags, save_flags;
4923 struct qla_hw_data *ha = vha->hw;
4927 /* Get Initiator ID */
4928 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4929 rval = qla2x00_configure_hba(vha);
4930 if (rval != QLA_SUCCESS) {
4931 ql_dbg(ql_dbg_disc, vha, 0x2013,
4932 "Unable to configure HBA.\n");
4937 save_flags = flags = vha->dpc_flags;
4938 ql_dbg(ql_dbg_disc, vha, 0x2014,
4939 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4942 * If we have both an RSCN and PORT UPDATE pending then handle them
4943 * both at the same time.
4945 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4946 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4948 qla2x00_get_data_rate(vha);
4950 /* Determine what we need to do */
4951 if (ha->current_topology == ISP_CFG_FL &&
4952 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4954 set_bit(RSCN_UPDATE, &flags);
4956 } else if (ha->current_topology == ISP_CFG_F &&
4957 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4959 set_bit(RSCN_UPDATE, &flags);
4960 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4962 } else if (ha->current_topology == ISP_CFG_N) {
4963 clear_bit(RSCN_UPDATE, &flags);
4964 if (qla_tgt_mode_enabled(vha)) {
4965 /* allow the other side to start the login */
4966 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4967 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4969 } else if (ha->current_topology == ISP_CFG_NL) {
4970 clear_bit(RSCN_UPDATE, &flags);
4971 set_bit(LOCAL_LOOP_UPDATE, &flags);
4972 } else if (!vha->flags.online ||
4973 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4974 set_bit(RSCN_UPDATE, &flags);
4975 set_bit(LOCAL_LOOP_UPDATE, &flags);
4978 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4979 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4980 ql_dbg(ql_dbg_disc, vha, 0x2015,
4981 "Loop resync needed, failing.\n");
4982 rval = QLA_FUNCTION_FAILED;
4984 rval = qla2x00_configure_local_loop(vha);
4987 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4988 if (LOOP_TRANSITION(vha)) {
4989 ql_dbg(ql_dbg_disc, vha, 0x2099,
4990 "Needs RSCN update and loop transition.\n");
4991 rval = QLA_FUNCTION_FAILED;
4994 rval = qla2x00_configure_fabric(vha);
4997 if (rval == QLA_SUCCESS) {
4998 if (atomic_read(&vha->loop_down_timer) ||
4999 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5000 rval = QLA_FUNCTION_FAILED;
5002 atomic_set(&vha->loop_state, LOOP_READY);
5003 ql_dbg(ql_dbg_disc, vha, 0x2069,
5005 ha->flags.fw_init_done = 1;
5008 * Process any ATIO queue entries that came in
5009 * while we weren't online.
5011 if (qla_tgt_mode_enabled(vha) ||
5012 qla_dual_mode_enabled(vha)) {
5013 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5014 qlt_24xx_process_atio_queue(vha, 0);
5015 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5022 ql_dbg(ql_dbg_disc, vha, 0x206a,
5023 "%s *** FAILED ***.\n", __func__);
5025 ql_dbg(ql_dbg_disc, vha, 0x206b,
5026 "%s: exiting normally.\n", __func__);
5029 /* Restore state if a resync event occurred during processing */
5030 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5031 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5032 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5033 if (test_bit(RSCN_UPDATE, &save_flags)) {
5034 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5042 * qla2x00_configure_local_loop
5043 * Updates Fibre Channel Device Database with local loop devices.
5046 * ha = adapter block pointer.
5052 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5057 fc_port_t *fcport, *new_fcport;
5063 uint8_t domain, area, al_pa;
5064 struct qla_hw_data *ha = vha->hw;
5065 unsigned long flags;
5067 /* Inititae N2N login. */
5068 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5072 memset(ha->init_cb, 0, ha->init_cb_size);
5073 sz = min_t(int, sizeof(struct els_plogi_payload),
5075 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5076 (void *)ha->init_cb, sz);
5077 if (rval == QLA_SUCCESS) {
5078 bp = (uint32_t *)ha->init_cb;
5079 for (i = 0; i < sz/4 ; i++, bp++)
5080 *bp = cpu_to_be32(*bp);
5082 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
5083 sizeof(ha->plogi_els_payld.data));
5084 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5086 ql_dbg(ql_dbg_init, vha, 0x00d1,
5087 "PLOGI ELS param read fail.\n");
5094 entries = MAX_FIBRE_DEVICES_LOOP;
5096 /* Get list of logged in devices. */
5097 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5098 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5100 if (rval != QLA_SUCCESS)
5101 goto cleanup_allocation;
5103 ql_dbg(ql_dbg_disc, vha, 0x2011,
5104 "Entries in ID list (%d).\n", entries);
5105 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5106 ha->gid_list, entries * sizeof(*ha->gid_list));
5109 spin_lock_irqsave(&vha->work_lock, flags);
5110 vha->scan.scan_retry++;
5111 spin_unlock_irqrestore(&vha->work_lock, flags);
5113 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5114 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5115 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5118 vha->scan.scan_retry = 0;
5121 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5122 fcport->scan_state = QLA_FCPORT_SCAN;
5125 /* Allocate temporary fcport for any new fcports discovered. */
5126 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5127 if (new_fcport == NULL) {
5128 ql_log(ql_log_warn, vha, 0x2012,
5129 "Memory allocation failed for fcport.\n");
5130 rval = QLA_MEMORY_ALLOC_FAILED;
5131 goto cleanup_allocation;
5133 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5135 /* Add devices to port list. */
5136 id_iter = (char *)ha->gid_list;
5137 for (index = 0; index < entries; index++) {
5138 domain = ((struct gid_list_info *)id_iter)->domain;
5139 area = ((struct gid_list_info *)id_iter)->area;
5140 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
5141 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5142 loop_id = (uint16_t)
5143 ((struct gid_list_info *)id_iter)->loop_id_2100;
5145 loop_id = le16_to_cpu(
5146 ((struct gid_list_info *)id_iter)->loop_id);
5147 id_iter += ha->gid_list_info_size;
5149 /* Bypass reserved domain fields. */
5150 if ((domain & 0xf0) == 0xf0)
5153 /* Bypass if not same domain and area of adapter. */
5154 if (area && domain && ((area != vha->d_id.b.area) ||
5155 (domain != vha->d_id.b.domain)) &&
5156 (ha->current_topology == ISP_CFG_NL))
5160 /* Bypass invalid local loop ID. */
5161 if (loop_id > LAST_LOCAL_LOOP_ID)
5164 memset(new_fcport->port_name, 0, WWN_SIZE);
5166 /* Fill in member data. */
5167 new_fcport->d_id.b.domain = domain;
5168 new_fcport->d_id.b.area = area;
5169 new_fcport->d_id.b.al_pa = al_pa;
5170 new_fcport->loop_id = loop_id;
5171 new_fcport->scan_state = QLA_FCPORT_FOUND;
5173 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5174 if (rval2 != QLA_SUCCESS) {
5175 ql_dbg(ql_dbg_disc, vha, 0x2097,
5176 "Failed to retrieve fcport information "
5177 "-- get_port_database=%x, loop_id=0x%04x.\n",
5178 rval2, new_fcport->loop_id);
5179 /* Skip retry if N2N */
5180 if (ha->current_topology != ISP_CFG_N) {
5181 ql_dbg(ql_dbg_disc, vha, 0x2105,
5182 "Scheduling resync.\n");
5183 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5188 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5189 /* Check for matching device in port list. */
5192 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5193 if (memcmp(new_fcport->port_name, fcport->port_name,
5197 fcport->flags &= ~FCF_FABRIC_DEVICE;
5198 fcport->loop_id = new_fcport->loop_id;
5199 fcport->port_type = new_fcport->port_type;
5200 fcport->d_id.b24 = new_fcport->d_id.b24;
5201 memcpy(fcport->node_name, new_fcport->node_name,
5203 fcport->scan_state = QLA_FCPORT_FOUND;
5209 /* New device, add to fcports list. */
5210 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5212 /* Allocate a new replacement fcport. */
5213 fcport = new_fcport;
5215 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5217 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5219 if (new_fcport == NULL) {
5220 ql_log(ql_log_warn, vha, 0xd031,
5221 "Failed to allocate memory for fcport.\n");
5222 rval = QLA_MEMORY_ALLOC_FAILED;
5223 goto cleanup_allocation;
5225 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5226 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5229 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5231 /* Base iIDMA settings on HBA port speed. */
5232 fcport->fp_speed = ha->link_data_rate;
5237 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5238 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5241 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5242 if ((qla_dual_mode_enabled(vha) ||
5243 qla_ini_mode_enabled(vha)) &&
5244 atomic_read(&fcport->state) == FCS_ONLINE) {
5245 qla2x00_mark_device_lost(vha, fcport,
5246 ql2xplogiabsentdevice, 0);
5247 if (fcport->loop_id != FC_NO_LOOP_ID &&
5248 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5249 fcport->port_type != FCT_INITIATOR &&
5250 fcport->port_type != FCT_BROADCAST) {
5251 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5252 "%s %d %8phC post del sess\n",
5256 qlt_schedule_sess_for_deletion(fcport);
5262 if (fcport->scan_state == QLA_FCPORT_FOUND)
5263 qla24xx_fcport_handle_login(vha, fcport);
5269 if (rval != QLA_SUCCESS) {
5270 ql_dbg(ql_dbg_disc, vha, 0x2098,
5271 "Configure local loop error exit: rval=%x.\n", rval);
5278 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5281 uint16_t mb[MAILBOX_REGISTER_COUNT];
5282 struct qla_hw_data *ha = vha->hw;
5284 if (!IS_IIDMA_CAPABLE(ha))
5287 if (atomic_read(&fcport->state) != FCS_ONLINE)
5290 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5291 fcport->fp_speed > ha->link_data_rate ||
5292 !ha->flags.gpsc_supported)
5295 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5297 if (rval != QLA_SUCCESS) {
5298 ql_dbg(ql_dbg_disc, vha, 0x2004,
5299 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5300 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5302 ql_dbg(ql_dbg_disc, vha, 0x2005,
5303 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5304 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5305 fcport->fp_speed, fcport->port_name);
5309 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5311 qla2x00_iidma_fcport(vha, fcport);
5312 qla24xx_update_fcport_fcp_prio(vha, fcport);
5315 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5317 struct qla_work_evt *e;
5319 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5321 return QLA_FUNCTION_FAILED;
5323 e->u.fcport.fcport = fcport;
5324 return qla2x00_post_work(vha, e);
5327 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5329 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5331 struct fc_rport_identifiers rport_ids;
5332 struct fc_rport *rport;
5333 unsigned long flags;
5335 if (atomic_read(&fcport->state) == FCS_ONLINE)
5338 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5339 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5340 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5341 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5342 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5343 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5345 ql_log(ql_log_warn, vha, 0x2006,
5346 "Unable to allocate fc remote port.\n");
5350 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5351 *((fc_port_t **)rport->dd_data) = fcport;
5352 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5354 rport->supported_classes = fcport->supported_classes;
5356 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5357 if (fcport->port_type == FCT_INITIATOR)
5358 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5359 if (fcport->port_type == FCT_TARGET)
5360 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5361 if (fcport->port_type & FCT_NVME_INITIATOR)
5362 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5363 if (fcport->port_type & FCT_NVME_TARGET)
5364 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5365 if (fcport->port_type & FCT_NVME_DISCOVERY)
5366 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5368 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5369 "%s %8phN. rport %p is %s mode\n",
5370 __func__, fcport->port_name, rport,
5371 (fcport->port_type == FCT_TARGET) ? "tgt" :
5372 ((fcport->port_type & FCT_NVME) ? "nvme" :"ini"));
5374 fc_remote_port_rolechg(rport, rport_ids.roles);
5378 * qla2x00_update_fcport
5379 * Updates device on list.
5382 * ha = adapter block pointer.
5383 * fcport = port structure pointer.
5393 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5395 if (IS_SW_RESV_ADDR(fcport->d_id))
5398 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5399 __func__, fcport->port_name);
5401 fcport->disc_state = DSC_UPD_FCPORT;
5402 fcport->login_retry = vha->hw->login_retry_count;
5403 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5404 fcport->deleted = 0;
5405 fcport->logout_on_delete = 1;
5406 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5408 switch (vha->hw->current_topology) {
5411 fcport->keep_nport_handle = 1;
5417 qla2x00_iidma_fcport(vha, fcport);
5419 if (fcport->fc4f_nvme) {
5420 qla_nvme_register_remote(vha, fcport);
5421 fcport->disc_state = DSC_LOGIN_COMPLETE;
5422 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5426 qla24xx_update_fcport_fcp_prio(vha, fcport);
5428 switch (vha->host->active_mode) {
5429 case MODE_INITIATOR:
5430 qla2x00_reg_remote_port(vha, fcport);
5433 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5434 !vha->vha_tgt.qla_tgt->tgt_stopped)
5435 qlt_fc_port_added(vha, fcport);
5438 qla2x00_reg_remote_port(vha, fcport);
5439 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5440 !vha->vha_tgt.qla_tgt->tgt_stopped)
5441 qlt_fc_port_added(vha, fcport);
5447 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5449 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5450 if (fcport->id_changed) {
5451 fcport->id_changed = 0;
5452 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5453 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5454 __func__, __LINE__, fcport->port_name,
5456 qla24xx_post_gfpnid_work(vha, fcport);
5458 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5459 "%s %d %8phC post gpsc fcp_cnt %d\n",
5460 __func__, __LINE__, fcport->port_name,
5462 qla24xx_post_gpsc_work(vha, fcport);
5466 fcport->disc_state = DSC_LOGIN_COMPLETE;
5469 void qla_register_fcport_fn(struct work_struct *work)
5471 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5472 u32 rscn_gen = fcport->rscn_gen;
5475 if (IS_SW_RESV_ADDR(fcport->d_id))
5478 qla2x00_update_fcport(fcport->vha, fcport);
5480 if (rscn_gen != fcport->rscn_gen) {
5481 /* RSCN(s) came in while registration */
5482 switch (fcport->next_disc_state) {
5483 case DSC_DELETE_PEND:
5484 qlt_schedule_sess_for_deletion(fcport);
5487 data[0] = data[1] = 0;
5488 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5498 * qla2x00_configure_fabric
5499 * Setup SNS devices with loop ID's.
5502 * ha = adapter block pointer.
5509 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5513 uint16_t mb[MAILBOX_REGISTER_COUNT];
5515 LIST_HEAD(new_fcports);
5516 struct qla_hw_data *ha = vha->hw;
5519 /* If FL port exists, then SNS is present */
5520 if (IS_FWI2_CAPABLE(ha))
5521 loop_id = NPH_F_PORT;
5523 loop_id = SNS_FL_PORT;
5524 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5525 if (rval != QLA_SUCCESS) {
5526 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5527 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5529 vha->device_flags &= ~SWITCH_FOUND;
5530 return (QLA_SUCCESS);
5532 vha->device_flags |= SWITCH_FOUND;
5535 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5536 rval = qla2x00_send_change_request(vha, 0x3, 0);
5537 if (rval != QLA_SUCCESS)
5538 ql_log(ql_log_warn, vha, 0x121,
5539 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5545 qla2x00_mgmt_svr_login(vha);
5548 if (ql2xfdmienable &&
5549 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5550 qla2x00_fdmi_register(vha);
5552 /* Ensure we are logged into the SNS. */
5553 loop_id = NPH_SNS_LID(ha);
5554 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5555 0xfc, mb, BIT_1|BIT_0);
5556 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5557 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5558 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5559 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5560 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5563 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5564 if (qla2x00_rft_id(vha)) {
5566 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5567 "Register FC-4 TYPE failed.\n");
5568 if (test_bit(LOOP_RESYNC_NEEDED,
5572 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5574 ql_dbg(ql_dbg_disc, vha, 0x209a,
5575 "Register FC-4 Features failed.\n");
5576 if (test_bit(LOOP_RESYNC_NEEDED,
5580 if (vha->flags.nvme_enabled) {
5581 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5582 ql_dbg(ql_dbg_disc, vha, 0x2049,
5583 "Register NVME FC Type Features failed.\n");
5586 if (qla2x00_rnn_id(vha)) {
5588 ql_dbg(ql_dbg_disc, vha, 0x2104,
5589 "Register Node Name failed.\n");
5590 if (test_bit(LOOP_RESYNC_NEEDED,
5593 } else if (qla2x00_rsnn_nn(vha)) {
5595 ql_dbg(ql_dbg_disc, vha, 0x209b,
5596 "Register Symbolic Node Name failed.\n");
5597 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5603 /* Mark the time right before querying FW for connected ports.
5604 * This process is long, asynchronous and by the time it's done,
5605 * collected information might not be accurate anymore. E.g.
5606 * disconnected port might have re-connected and a brand new
5607 * session has been created. In this case session's generation
5608 * will be newer than discovery_gen. */
5609 qlt_do_generation_tick(vha, &discovery_gen);
5611 if (USE_ASYNC_SCAN(ha)) {
5612 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5615 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5617 list_for_each_entry(fcport, &vha->vp_fcports, list)
5618 fcport->scan_state = QLA_FCPORT_SCAN;
5620 rval = qla2x00_find_all_fabric_devs(vha);
5622 if (rval != QLA_SUCCESS)
5626 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5627 qla_nvme_register_hba(vha);
5630 ql_dbg(ql_dbg_disc, vha, 0x2068,
5631 "Configure fabric error exit rval=%d.\n", rval);
5637 * qla2x00_find_all_fabric_devs
5640 * ha = adapter block pointer.
5641 * dev = database device entry pointer.
5650 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5654 fc_port_t *fcport, *new_fcport;
5659 int first_dev, last_dev;
5660 port_id_t wrap = {}, nxt_d_id;
5661 struct qla_hw_data *ha = vha->hw;
5662 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5663 unsigned long flags;
5667 /* Try GID_PT to get device list, else GAN. */
5669 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5674 ql_dbg(ql_dbg_disc, vha, 0x209c,
5675 "GID_PT allocations failed, fallback on GA_NXT.\n");
5677 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5678 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5680 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5682 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5684 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5686 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5688 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5690 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5692 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5696 /* If other queries succeeded probe for FC-4 type */
5698 qla2x00_gff_id(vha, swl);
5699 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5705 /* Allocate temporary fcport for any new fcports discovered. */
5706 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5707 if (new_fcport == NULL) {
5708 ql_log(ql_log_warn, vha, 0x209d,
5709 "Failed to allocate memory for fcport.\n");
5710 return (QLA_MEMORY_ALLOC_FAILED);
5712 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5713 /* Set start port ID scan at adapter ID. */
5717 /* Starting free loop ID. */
5718 loop_id = ha->min_external_loopid;
5719 for (; loop_id <= ha->max_loop_id; loop_id++) {
5720 if (qla2x00_is_reserved_id(vha, loop_id))
5723 if (ha->current_topology == ISP_CFG_FL &&
5724 (atomic_read(&vha->loop_down_timer) ||
5725 LOOP_TRANSITION(vha))) {
5726 atomic_set(&vha->loop_down_timer, 0);
5727 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5728 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5734 wrap.b24 = new_fcport->d_id.b24;
5736 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5737 memcpy(new_fcport->node_name,
5738 swl[swl_idx].node_name, WWN_SIZE);
5739 memcpy(new_fcport->port_name,
5740 swl[swl_idx].port_name, WWN_SIZE);
5741 memcpy(new_fcport->fabric_port_name,
5742 swl[swl_idx].fabric_port_name, WWN_SIZE);
5743 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5744 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5746 new_fcport->nvme_flag = 0;
5747 new_fcport->fc4f_nvme = 0;
5748 if (vha->flags.nvme_enabled &&
5749 swl[swl_idx].fc4f_nvme) {
5750 new_fcport->fc4f_nvme =
5751 swl[swl_idx].fc4f_nvme;
5752 ql_log(ql_log_info, vha, 0x2131,
5753 "FOUND: NVME port %8phC as FC Type 28h\n",
5754 new_fcport->port_name);
5757 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5763 /* Send GA_NXT to the switch */
5764 rval = qla2x00_ga_nxt(vha, new_fcport);
5765 if (rval != QLA_SUCCESS) {
5766 ql_log(ql_log_warn, vha, 0x209e,
5767 "SNS scan failed -- assuming "
5768 "zero-entry result.\n");
5774 /* If wrap on switch device list, exit. */
5776 wrap.b24 = new_fcport->d_id.b24;
5778 } else if (new_fcport->d_id.b24 == wrap.b24) {
5779 ql_dbg(ql_dbg_disc, vha, 0x209f,
5780 "Device wrap (%02x%02x%02x).\n",
5781 new_fcport->d_id.b.domain,
5782 new_fcport->d_id.b.area,
5783 new_fcport->d_id.b.al_pa);
5787 /* Bypass if same physical adapter. */
5788 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5791 /* Bypass virtual ports of the same host. */
5792 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5795 /* Bypass if same domain and area of adapter. */
5796 if (((new_fcport->d_id.b24 & 0xffff00) ==
5797 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5801 /* Bypass reserved domain fields. */
5802 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5805 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5806 if (ql2xgffidenable &&
5807 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5808 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5811 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5813 /* Locate matching device in database. */
5815 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5816 if (memcmp(new_fcport->port_name, fcport->port_name,
5820 fcport->scan_state = QLA_FCPORT_FOUND;
5824 /* Update port state. */
5825 memcpy(fcport->fabric_port_name,
5826 new_fcport->fabric_port_name, WWN_SIZE);
5827 fcport->fp_speed = new_fcport->fp_speed;
5830 * If address the same and state FCS_ONLINE
5831 * (or in target mode), nothing changed.
5833 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5834 (atomic_read(&fcport->state) == FCS_ONLINE ||
5835 (vha->host->active_mode == MODE_TARGET))) {
5840 * If device was not a fabric device before.
5842 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5843 fcport->d_id.b24 = new_fcport->d_id.b24;
5844 qla2x00_clear_loop_id(fcport);
5845 fcport->flags |= (FCF_FABRIC_DEVICE |
5851 * Port ID changed or device was marked to be updated;
5852 * Log it out if still logged in and mark it for
5855 if (qla_tgt_mode_enabled(base_vha)) {
5856 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5857 "port changed FC ID, %8phC"
5858 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5860 fcport->d_id.b.domain,
5861 fcport->d_id.b.area,
5862 fcport->d_id.b.al_pa,
5864 new_fcport->d_id.b.domain,
5865 new_fcport->d_id.b.area,
5866 new_fcport->d_id.b.al_pa);
5867 fcport->d_id.b24 = new_fcport->d_id.b24;
5871 fcport->d_id.b24 = new_fcport->d_id.b24;
5872 fcport->flags |= FCF_LOGIN_NEEDED;
5876 if (fcport->fc4f_nvme) {
5877 if (fcport->disc_state == DSC_DELETE_PEND) {
5878 fcport->disc_state = DSC_GNL;
5879 vha->fcport_count--;
5880 fcport->login_succ = 0;
5885 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5888 /* If device was not in our fcports list, then add it. */
5889 new_fcport->scan_state = QLA_FCPORT_FOUND;
5890 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5892 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5895 /* Allocate a new replacement fcport. */
5896 nxt_d_id.b24 = new_fcport->d_id.b24;
5897 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5898 if (new_fcport == NULL) {
5899 ql_log(ql_log_warn, vha, 0xd032,
5900 "Memory allocation failed for fcport.\n");
5901 return (QLA_MEMORY_ALLOC_FAILED);
5903 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5904 new_fcport->d_id.b24 = nxt_d_id.b24;
5907 qla2x00_free_fcport(new_fcport);
5910 * Logout all previous fabric dev marked lost, except FCP2 devices.
5912 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5913 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5916 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5917 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5920 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5921 if ((qla_dual_mode_enabled(vha) ||
5922 qla_ini_mode_enabled(vha)) &&
5923 atomic_read(&fcport->state) == FCS_ONLINE) {
5924 qla2x00_mark_device_lost(vha, fcport,
5925 ql2xplogiabsentdevice, 0);
5926 if (fcport->loop_id != FC_NO_LOOP_ID &&
5927 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5928 fcport->port_type != FCT_INITIATOR &&
5929 fcport->port_type != FCT_BROADCAST) {
5930 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5931 "%s %d %8phC post del sess\n",
5934 qlt_schedule_sess_for_deletion(fcport);
5940 if (fcport->scan_state == QLA_FCPORT_FOUND)
5941 qla24xx_fcport_handle_login(vha, fcport);
5946 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5948 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5950 int loop_id = FC_NO_LOOP_ID;
5951 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5952 unsigned long flags;
5953 struct qla_hw_data *ha = vha->hw;
5955 if (vha->vp_idx == 0) {
5956 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5957 return NPH_MGMT_SERVER;
5960 /* pick id from high and work down to low */
5961 spin_lock_irqsave(&ha->vport_slock, flags);
5962 for (; lid > 0; lid--) {
5963 if (!test_bit(lid, vha->hw->loop_id_map)) {
5964 set_bit(lid, vha->hw->loop_id_map);
5969 spin_unlock_irqrestore(&ha->vport_slock, flags);
5975 * qla2x00_fabric_login
5976 * Issue fabric login command.
5979 * ha = adapter block pointer.
5980 * device = pointer to FC device type structure.
5983 * 0 - Login successfully
5985 * 2 - Initiator device
5989 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5990 uint16_t *next_loopid)
5994 uint16_t tmp_loopid;
5995 uint16_t mb[MAILBOX_REGISTER_COUNT];
5996 struct qla_hw_data *ha = vha->hw;
6002 ql_dbg(ql_dbg_disc, vha, 0x2000,
6003 "Trying Fabric Login w/loop id 0x%04x for port "
6005 fcport->loop_id, fcport->d_id.b.domain,
6006 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6008 /* Login fcport on switch. */
6009 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6010 fcport->d_id.b.domain, fcport->d_id.b.area,
6011 fcport->d_id.b.al_pa, mb, BIT_0);
6012 if (rval != QLA_SUCCESS) {
6015 if (mb[0] == MBS_PORT_ID_USED) {
6017 * Device has another loop ID. The firmware team
6018 * recommends the driver perform an implicit login with
6019 * the specified ID again. The ID we just used is save
6020 * here so we return with an ID that can be tried by
6024 tmp_loopid = fcport->loop_id;
6025 fcport->loop_id = mb[1];
6027 ql_dbg(ql_dbg_disc, vha, 0x2001,
6028 "Fabric Login: port in use - next loop "
6029 "id=0x%04x, port id= %02x%02x%02x.\n",
6030 fcport->loop_id, fcport->d_id.b.domain,
6031 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6033 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6038 /* A retry occurred before. */
6039 *next_loopid = tmp_loopid;
6042 * No retry occurred before. Just increment the
6043 * ID value for next login.
6045 *next_loopid = (fcport->loop_id + 1);
6048 if (mb[1] & BIT_0) {
6049 fcport->port_type = FCT_INITIATOR;
6051 fcport->port_type = FCT_TARGET;
6052 if (mb[1] & BIT_1) {
6053 fcport->flags |= FCF_FCP2_DEVICE;
6058 fcport->supported_classes |= FC_COS_CLASS2;
6060 fcport->supported_classes |= FC_COS_CLASS3;
6062 if (IS_FWI2_CAPABLE(ha)) {
6065 FCF_CONF_COMP_SUPPORTED;
6070 } else if (mb[0] == MBS_LOOP_ID_USED) {
6072 * Loop ID already used, try next loop ID.
6075 rval = qla2x00_find_new_loop_id(vha, fcport);
6076 if (rval != QLA_SUCCESS) {
6077 /* Ran out of loop IDs to use */
6080 } else if (mb[0] == MBS_COMMAND_ERROR) {
6082 * Firmware possibly timed out during login. If NO
6083 * retries are left to do then the device is declared
6086 *next_loopid = fcport->loop_id;
6087 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6088 fcport->d_id.b.domain, fcport->d_id.b.area,
6089 fcport->d_id.b.al_pa);
6090 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6096 * unrecoverable / not handled error
6098 ql_dbg(ql_dbg_disc, vha, 0x2002,
6099 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6100 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6101 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6102 fcport->loop_id, jiffies);
6104 *next_loopid = fcport->loop_id;
6105 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6106 fcport->d_id.b.domain, fcport->d_id.b.area,
6107 fcport->d_id.b.al_pa);
6108 qla2x00_clear_loop_id(fcport);
6109 fcport->login_retry = 0;
6120 * qla2x00_local_device_login
6121 * Issue local device login command.
6124 * ha = adapter block pointer.
6125 * loop_id = loop id of device to login to.
6127 * Returns (Where's the #define!!!!):
6128 * 0 - Login successfully
6133 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6136 uint16_t mb[MAILBOX_REGISTER_COUNT];
6138 memset(mb, 0, sizeof(mb));
6139 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6140 if (rval == QLA_SUCCESS) {
6141 /* Interrogate mailbox registers for any errors */
6142 if (mb[0] == MBS_COMMAND_ERROR)
6144 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6145 /* device not in PCB table */
6153 * qla2x00_loop_resync
6154 * Resync with fibre channel devices.
6157 * ha = adapter block pointer.
6163 qla2x00_loop_resync(scsi_qla_host_t *vha)
6165 int rval = QLA_SUCCESS;
6168 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6169 if (vha->flags.online) {
6170 if (!(rval = qla2x00_fw_ready(vha))) {
6171 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6174 if (!IS_QLAFX00(vha->hw)) {
6176 * Issue a marker after FW becomes
6179 qla2x00_marker(vha, vha->hw->base_qpair,
6181 vha->marker_needed = 0;
6184 /* Remap devices on Loop. */
6185 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6187 if (IS_QLAFX00(vha->hw))
6188 qlafx00_configure_devices(vha);
6190 qla2x00_configure_loop(vha);
6193 } while (!atomic_read(&vha->loop_down_timer) &&
6194 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6195 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6200 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6201 return (QLA_FUNCTION_FAILED);
6204 ql_dbg(ql_dbg_disc, vha, 0x206c,
6205 "%s *** FAILED ***.\n", __func__);
6211 * qla2x00_perform_loop_resync
6212 * Description: This function will set the appropriate flags and call
6213 * qla2x00_loop_resync. If successful loop will be resynced
6214 * Arguments : scsi_qla_host_t pointer
6215 * returm : Success or Failure
6218 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6222 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6223 /*Configure the flags so that resync happens properly*/
6224 atomic_set(&ha->loop_down_timer, 0);
6225 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6226 atomic_set(&ha->loop_state, LOOP_UP);
6227 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6228 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6229 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6231 rval = qla2x00_loop_resync(ha);
6233 atomic_set(&ha->loop_state, LOOP_DEAD);
6235 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6242 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6245 struct scsi_qla_host *vha;
6246 struct qla_hw_data *ha = base_vha->hw;
6247 unsigned long flags;
6249 spin_lock_irqsave(&ha->vport_slock, flags);
6250 /* Go with deferred removal of rport references. */
6251 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6252 atomic_inc(&vha->vref_count);
6253 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6254 if (fcport->drport &&
6255 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6256 spin_unlock_irqrestore(&ha->vport_slock, flags);
6257 qla2x00_rport_del(fcport);
6259 spin_lock_irqsave(&ha->vport_slock, flags);
6262 atomic_dec(&vha->vref_count);
6263 wake_up(&vha->vref_waitq);
6265 spin_unlock_irqrestore(&ha->vport_slock, flags);
6268 /* Assumes idc_lock always held on entry */
6270 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6272 struct qla_hw_data *ha = vha->hw;
6273 uint32_t drv_presence, drv_presence_mask;
6274 uint32_t dev_part_info1, dev_part_info2, class_type;
6275 uint32_t class_type_mask = 0x3;
6276 uint16_t fcoe_other_function = 0xffff, i;
6278 if (IS_QLA8044(ha)) {
6279 drv_presence = qla8044_rd_direct(vha,
6280 QLA8044_CRB_DRV_ACTIVE_INDEX);
6281 dev_part_info1 = qla8044_rd_direct(vha,
6282 QLA8044_CRB_DEV_PART_INFO_INDEX);
6283 dev_part_info2 = qla8044_rd_direct(vha,
6284 QLA8044_CRB_DEV_PART_INFO2);
6286 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6287 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6288 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6290 for (i = 0; i < 8; i++) {
6291 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6292 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6293 (i != ha->portnum)) {
6294 fcoe_other_function = i;
6298 if (fcoe_other_function == 0xffff) {
6299 for (i = 0; i < 8; i++) {
6300 class_type = ((dev_part_info2 >> (i * 4)) &
6302 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6303 ((i + 8) != ha->portnum)) {
6304 fcoe_other_function = i + 8;
6310 * Prepare drv-presence mask based on fcoe functions present.
6311 * However consider only valid physical fcoe function numbers (0-15).
6313 drv_presence_mask = ~((1 << (ha->portnum)) |
6314 ((fcoe_other_function == 0xffff) ?
6315 0 : (1 << (fcoe_other_function))));
6317 /* We are the reset owner iff:
6318 * - No other protocol drivers present.
6319 * - This is the lowest among fcoe functions. */
6320 if (!(drv_presence & drv_presence_mask) &&
6321 (ha->portnum < fcoe_other_function)) {
6322 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6323 "This host is Reset owner.\n");
6324 ha->flags.nic_core_reset_owner = 1;
6329 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6331 int rval = QLA_SUCCESS;
6332 struct qla_hw_data *ha = vha->hw;
6335 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6336 if (rval == QLA_SUCCESS) {
6337 drv_ack |= (1 << ha->portnum);
6338 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6345 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6347 int rval = QLA_SUCCESS;
6348 struct qla_hw_data *ha = vha->hw;
6351 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6352 if (rval == QLA_SUCCESS) {
6353 drv_ack &= ~(1 << ha->portnum);
6354 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6361 qla83xx_dev_state_to_string(uint32_t dev_state)
6363 switch (dev_state) {
6364 case QLA8XXX_DEV_COLD:
6365 return "COLD/RE-INIT";
6366 case QLA8XXX_DEV_INITIALIZING:
6367 return "INITIALIZING";
6368 case QLA8XXX_DEV_READY:
6370 case QLA8XXX_DEV_NEED_RESET:
6371 return "NEED RESET";
6372 case QLA8XXX_DEV_NEED_QUIESCENT:
6373 return "NEED QUIESCENT";
6374 case QLA8XXX_DEV_FAILED:
6376 case QLA8XXX_DEV_QUIESCENT:
6383 /* Assumes idc-lock always held on entry */
6385 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6387 struct qla_hw_data *ha = vha->hw;
6388 uint32_t idc_audit_reg = 0, duration_secs = 0;
6390 switch (audit_type) {
6391 case IDC_AUDIT_TIMESTAMP:
6392 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6393 idc_audit_reg = (ha->portnum) |
6394 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6395 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6398 case IDC_AUDIT_COMPLETION:
6399 duration_secs = ((jiffies_to_msecs(jiffies) -
6400 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6401 idc_audit_reg = (ha->portnum) |
6402 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6403 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6407 ql_log(ql_log_warn, vha, 0xb078,
6408 "Invalid audit type specified.\n");
6413 /* Assumes idc_lock always held on entry */
6415 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6417 struct qla_hw_data *ha = vha->hw;
6418 uint32_t idc_control, dev_state;
6420 __qla83xx_get_idc_control(vha, &idc_control);
6421 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6422 ql_log(ql_log_info, vha, 0xb080,
6423 "NIC Core reset has been disabled. idc-control=0x%x\n",
6425 return QLA_FUNCTION_FAILED;
6428 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6429 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6430 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6431 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6432 QLA8XXX_DEV_NEED_RESET);
6433 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6434 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6436 const char *state = qla83xx_dev_state_to_string(dev_state);
6438 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6440 /* SV: XXX: Is timeout required here? */
6441 /* Wait for IDC state change READY -> NEED_RESET */
6442 while (dev_state == QLA8XXX_DEV_READY) {
6443 qla83xx_idc_unlock(vha, 0);
6445 qla83xx_idc_lock(vha, 0);
6446 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6450 /* Send IDC ack by writing to drv-ack register */
6451 __qla83xx_set_drv_ack(vha);
6457 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6459 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6463 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6465 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6469 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6471 uint32_t drv_presence = 0;
6472 struct qla_hw_data *ha = vha->hw;
6474 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6475 if (drv_presence & (1 << ha->portnum))
6478 return QLA_TEST_FAILED;
6482 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6484 int rval = QLA_SUCCESS;
6485 struct qla_hw_data *ha = vha->hw;
6487 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6488 "Entered %s().\n", __func__);
6490 if (vha->device_flags & DFLG_DEV_FAILED) {
6491 ql_log(ql_log_warn, vha, 0xb059,
6492 "Device in unrecoverable FAILED state.\n");
6493 return QLA_FUNCTION_FAILED;
6496 qla83xx_idc_lock(vha, 0);
6498 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6499 ql_log(ql_log_warn, vha, 0xb05a,
6500 "Function=0x%x has been removed from IDC participation.\n",
6502 rval = QLA_FUNCTION_FAILED;
6506 qla83xx_reset_ownership(vha);
6508 rval = qla83xx_initiating_reset(vha);
6511 * Perform reset if we are the reset-owner,
6512 * else wait till IDC state changes to READY/FAILED.
6514 if (rval == QLA_SUCCESS) {
6515 rval = qla83xx_idc_state_handler(vha);
6517 if (rval == QLA_SUCCESS)
6518 ha->flags.nic_core_hung = 0;
6519 __qla83xx_clear_drv_ack(vha);
6523 qla83xx_idc_unlock(vha, 0);
6525 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6531 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6533 struct qla_hw_data *ha = vha->hw;
6534 int rval = QLA_FUNCTION_FAILED;
6536 if (!IS_MCTP_CAPABLE(ha)) {
6537 /* This message can be removed from the final version */
6538 ql_log(ql_log_info, vha, 0x506d,
6539 "This board is not MCTP capable\n");
6543 if (!ha->mctp_dump) {
6544 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6545 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6547 if (!ha->mctp_dump) {
6548 ql_log(ql_log_warn, vha, 0x506e,
6549 "Failed to allocate memory for mctp dump\n");
6554 #define MCTP_DUMP_STR_ADDR 0x00000000
6555 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6556 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6557 if (rval != QLA_SUCCESS) {
6558 ql_log(ql_log_warn, vha, 0x506f,
6559 "Failed to capture mctp dump\n");
6561 ql_log(ql_log_info, vha, 0x5070,
6562 "Mctp dump capture for host (%ld/%p).\n",
6563 vha->host_no, ha->mctp_dump);
6564 ha->mctp_dumped = 1;
6567 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6568 ha->flags.nic_core_reset_hdlr_active = 1;
6569 rval = qla83xx_restart_nic_firmware(vha);
6571 /* NIC Core reset failed. */
6572 ql_log(ql_log_warn, vha, 0x5071,
6573 "Failed to restart nic firmware\n");
6575 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6576 "Restarted NIC firmware successfully.\n");
6577 ha->flags.nic_core_reset_hdlr_active = 0;
6585 * qla2x00_quiesce_io
6586 * Description: This function will block the new I/Os
6587 * Its not aborting any I/Os as context
6588 * is not destroyed during quiescence
6589 * Arguments: scsi_qla_host_t
6593 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6595 struct qla_hw_data *ha = vha->hw;
6596 struct scsi_qla_host *vp;
6598 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6599 "Quiescing I/O - ha=%p.\n", ha);
6601 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6602 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6603 atomic_set(&vha->loop_state, LOOP_DOWN);
6604 qla2x00_mark_all_devices_lost(vha, 0);
6605 list_for_each_entry(vp, &ha->vp_list, list)
6606 qla2x00_mark_all_devices_lost(vp, 0);
6608 if (!atomic_read(&vha->loop_down_timer))
6609 atomic_set(&vha->loop_down_timer,
6612 /* Wait for pending cmds to complete */
6613 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6617 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6619 struct qla_hw_data *ha = vha->hw;
6620 struct scsi_qla_host *vp;
6621 unsigned long flags;
6625 /* For ISP82XX, driver waits for completion of the commands.
6626 * online flag should be set.
6628 if (!(IS_P3P_TYPE(ha)))
6629 vha->flags.online = 0;
6630 ha->flags.chip_reset_done = 0;
6631 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6632 vha->qla_stats.total_isp_aborts++;
6634 ql_log(ql_log_info, vha, 0x00af,
6635 "Performing ISP error recovery - ha=%p.\n", ha);
6637 ha->flags.purge_mbox = 1;
6638 /* For ISP82XX, reset_chip is just disabling interrupts.
6639 * Driver waits for the completion of the commands.
6640 * the interrupts need to be enabled.
6642 if (!(IS_P3P_TYPE(ha)))
6643 ha->isp_ops->reset_chip(vha);
6645 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6647 ha->flags.rida_fmt2 = 0;
6648 ha->flags.n2n_ae = 0;
6649 ha->flags.lip_ae = 0;
6650 ha->current_topology = 0;
6651 ha->flags.fw_started = 0;
6652 ha->flags.fw_init_done = 0;
6654 ha->base_qpair->chip_reset = ha->chip_reset;
6655 for (i = 0; i < ha->max_qpairs; i++) {
6656 if (ha->queue_pair_map[i])
6657 ha->queue_pair_map[i]->chip_reset =
6658 ha->base_qpair->chip_reset;
6661 /* purge MBox commands */
6662 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6663 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6664 complete(&ha->mbx_intr_comp);
6668 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6669 atomic_read(&ha->num_pend_mbx_stage2) ||
6670 atomic_read(&ha->num_pend_mbx_stage1)) {
6676 ha->flags.purge_mbox = 0;
6678 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6679 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6680 atomic_set(&vha->loop_state, LOOP_DOWN);
6681 qla2x00_mark_all_devices_lost(vha, 0);
6683 spin_lock_irqsave(&ha->vport_slock, flags);
6684 list_for_each_entry(vp, &ha->vp_list, list) {
6685 atomic_inc(&vp->vref_count);
6686 spin_unlock_irqrestore(&ha->vport_slock, flags);
6688 qla2x00_mark_all_devices_lost(vp, 0);
6690 spin_lock_irqsave(&ha->vport_slock, flags);
6691 atomic_dec(&vp->vref_count);
6693 spin_unlock_irqrestore(&ha->vport_slock, flags);
6695 if (!atomic_read(&vha->loop_down_timer))
6696 atomic_set(&vha->loop_down_timer,
6700 /* Clear all async request states across all VPs. */
6701 list_for_each_entry(fcport, &vha->vp_fcports, list)
6702 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6703 spin_lock_irqsave(&ha->vport_slock, flags);
6704 list_for_each_entry(vp, &ha->vp_list, list) {
6705 atomic_inc(&vp->vref_count);
6706 spin_unlock_irqrestore(&ha->vport_slock, flags);
6708 list_for_each_entry(fcport, &vp->vp_fcports, list)
6709 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6711 spin_lock_irqsave(&ha->vport_slock, flags);
6712 atomic_dec(&vp->vref_count);
6714 spin_unlock_irqrestore(&ha->vport_slock, flags);
6716 if (!ha->flags.eeh_busy) {
6717 /* Make sure for ISP 82XX IO DMA is complete */
6718 if (IS_P3P_TYPE(ha)) {
6719 qla82xx_chip_reset_cleanup(vha);
6720 ql_log(ql_log_info, vha, 0x00b4,
6721 "Done chip reset cleanup.\n");
6723 /* Done waiting for pending commands.
6724 * Reset the online flag.
6726 vha->flags.online = 0;
6729 /* Requeue all commands in outstanding command list. */
6730 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6732 /* memory barrier */
6738 * Resets ISP and aborts all outstanding commands.
6741 * ha = adapter block pointer.
6747 qla2x00_abort_isp(scsi_qla_host_t *vha)
6751 struct qla_hw_data *ha = vha->hw;
6752 struct scsi_qla_host *vp;
6753 struct req_que *req = ha->req_q_map[0];
6754 unsigned long flags;
6756 if (vha->flags.online) {
6757 qla2x00_abort_isp_cleanup(vha);
6759 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6760 ha->flags.chip_reset_done = 1;
6761 vha->flags.online = 1;
6763 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6767 if (IS_QLA8031(ha)) {
6768 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6769 "Clearing fcoe driver presence.\n");
6770 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6771 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6772 "Error while clearing DRV-Presence.\n");
6775 if (unlikely(pci_channel_offline(ha->pdev) &&
6776 ha->flags.pci_channel_io_perm_failure)) {
6777 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6782 switch (vha->qlini_mode) {
6783 case QLA2XXX_INI_MODE_DISABLED:
6784 if (!qla_tgt_mode_enabled(vha))
6787 case QLA2XXX_INI_MODE_DUAL:
6788 if (!qla_dual_mode_enabled(vha))
6791 case QLA2XXX_INI_MODE_ENABLED:
6796 ha->isp_ops->get_flash_version(vha, req->ring);
6798 ha->isp_ops->nvram_config(vha);
6800 if (!qla2x00_restart_isp(vha)) {
6801 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6803 if (!atomic_read(&vha->loop_down_timer)) {
6805 * Issue marker command only when we are going
6806 * to start the I/O .
6808 vha->marker_needed = 1;
6811 vha->flags.online = 1;
6813 ha->isp_ops->enable_intrs(ha);
6815 ha->isp_abort_cnt = 0;
6816 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6818 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6819 qla2x00_get_fw_version(vha);
6821 ha->flags.fce_enabled = 1;
6823 fce_calc_size(ha->fce_bufs));
6824 rval = qla2x00_enable_fce_trace(vha,
6825 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6828 ql_log(ql_log_warn, vha, 0x8033,
6829 "Unable to reinitialize FCE "
6831 ha->flags.fce_enabled = 0;
6836 memset(ha->eft, 0, EFT_SIZE);
6837 rval = qla2x00_enable_eft_trace(vha,
6838 ha->eft_dma, EFT_NUM_BUFFERS);
6840 ql_log(ql_log_warn, vha, 0x8034,
6841 "Unable to reinitialize EFT "
6845 } else { /* failed the ISP abort */
6846 vha->flags.online = 1;
6847 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6848 if (ha->isp_abort_cnt == 0) {
6849 ql_log(ql_log_fatal, vha, 0x8035,
6850 "ISP error recover failed - "
6851 "board disabled.\n");
6853 * The next call disables the board
6856 qla2x00_abort_isp_cleanup(vha);
6857 vha->flags.online = 0;
6858 clear_bit(ISP_ABORT_RETRY,
6861 } else { /* schedule another ISP abort */
6862 ha->isp_abort_cnt--;
6863 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6864 "ISP abort - retry remaining %d.\n",
6869 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6870 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6871 "ISP error recovery - retrying (%d) "
6872 "more times.\n", ha->isp_abort_cnt);
6873 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6881 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6882 qla2x00_configure_hba(vha);
6883 spin_lock_irqsave(&ha->vport_slock, flags);
6884 list_for_each_entry(vp, &ha->vp_list, list) {
6886 atomic_inc(&vp->vref_count);
6887 spin_unlock_irqrestore(&ha->vport_slock, flags);
6889 qla2x00_vp_abort_isp(vp);
6891 spin_lock_irqsave(&ha->vport_slock, flags);
6892 atomic_dec(&vp->vref_count);
6895 spin_unlock_irqrestore(&ha->vport_slock, flags);
6897 if (IS_QLA8031(ha)) {
6898 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6899 "Setting back fcoe driver presence.\n");
6900 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6901 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6902 "Error while setting DRV-Presence.\n");
6905 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6913 * qla2x00_restart_isp
6914 * restarts the ISP after a reset
6917 * ha = adapter block pointer.
6923 qla2x00_restart_isp(scsi_qla_host_t *vha)
6926 struct qla_hw_data *ha = vha->hw;
6928 /* If firmware needs to be loaded */
6929 if (qla2x00_isp_firmware(vha)) {
6930 vha->flags.online = 0;
6931 status = ha->isp_ops->chip_diag(vha);
6933 status = qla2x00_setup_chip(vha);
6936 if (!status && !(status = qla2x00_init_rings(vha))) {
6937 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6938 ha->flags.chip_reset_done = 1;
6940 /* Initialize the queues in use */
6941 qla25xx_init_queues(ha);
6943 status = qla2x00_fw_ready(vha);
6945 /* Issue a marker after FW becomes ready. */
6946 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
6947 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6950 /* if no cable then assume it's good */
6951 if ((vha->device_flags & DFLG_NO_CABLE))
6958 qla25xx_init_queues(struct qla_hw_data *ha)
6960 struct rsp_que *rsp = NULL;
6961 struct req_que *req = NULL;
6962 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6966 for (i = 1; i < ha->max_rsp_queues; i++) {
6967 rsp = ha->rsp_q_map[i];
6968 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6969 rsp->options &= ~BIT_0;
6970 ret = qla25xx_init_rsp_que(base_vha, rsp);
6971 if (ret != QLA_SUCCESS)
6972 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6973 "%s Rsp que: %d init failed.\n",
6976 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6977 "%s Rsp que: %d inited.\n",
6981 for (i = 1; i < ha->max_req_queues; i++) {
6982 req = ha->req_q_map[i];
6983 if (req && test_bit(i, ha->req_qid_map)) {
6984 /* Clear outstanding commands array. */
6985 req->options &= ~BIT_0;
6986 ret = qla25xx_init_req_que(base_vha, req);
6987 if (ret != QLA_SUCCESS)
6988 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6989 "%s Req que: %d init failed.\n",
6992 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6993 "%s Req que: %d inited.\n",
7001 * qla2x00_reset_adapter
7005 * ha = adapter block pointer.
7008 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7010 unsigned long flags = 0;
7011 struct qla_hw_data *ha = vha->hw;
7012 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7014 vha->flags.online = 0;
7015 ha->isp_ops->disable_intrs(ha);
7017 spin_lock_irqsave(&ha->hardware_lock, flags);
7018 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7019 RD_REG_WORD(®->hccr); /* PCI Posting. */
7020 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7021 RD_REG_WORD(®->hccr); /* PCI Posting. */
7022 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7028 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7030 unsigned long flags = 0;
7031 struct qla_hw_data *ha = vha->hw;
7032 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7033 int rval = QLA_SUCCESS;
7035 if (IS_P3P_TYPE(ha))
7038 vha->flags.online = 0;
7039 ha->isp_ops->disable_intrs(ha);
7041 spin_lock_irqsave(&ha->hardware_lock, flags);
7042 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7043 RD_REG_DWORD(®->hccr);
7044 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7045 RD_REG_DWORD(®->hccr);
7046 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7048 if (IS_NOPOLLING_TYPE(ha))
7049 ha->isp_ops->enable_intrs(ha);
7054 /* On sparc systems, obtain port and node WWN from firmware
7057 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7058 struct nvram_24xx *nv)
7061 struct qla_hw_data *ha = vha->hw;
7062 struct pci_dev *pdev = ha->pdev;
7063 struct device_node *dp = pci_device_to_OF_node(pdev);
7067 val = of_get_property(dp, "port-wwn", &len);
7068 if (val && len >= WWN_SIZE)
7069 memcpy(nv->port_name, val, WWN_SIZE);
7071 val = of_get_property(dp, "node-wwn", &len);
7072 if (val && len >= WWN_SIZE)
7073 memcpy(nv->node_name, val, WWN_SIZE);
7078 qla24xx_nvram_config(scsi_qla_host_t *vha)
7081 struct init_cb_24xx *icb;
7082 struct nvram_24xx *nv;
7084 uint8_t *dptr1, *dptr2;
7087 struct qla_hw_data *ha = vha->hw;
7090 icb = (struct init_cb_24xx *)ha->init_cb;
7093 /* Determine NVRAM starting address. */
7094 if (ha->port_no == 0) {
7095 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7096 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7098 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7099 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7102 ha->nvram_size = sizeof(*nv);
7103 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7105 /* Get VPD data into cache */
7106 ha->vpd = ha->nvram + VPD_OFFSET;
7107 ha->isp_ops->read_nvram(vha, ha->vpd,
7108 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7110 /* Get NVRAM data into cache and calculate checksum. */
7111 dptr = (uint32_t *)nv;
7112 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7113 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7114 chksum += le32_to_cpu(*dptr);
7116 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7117 "Contents of NVRAM\n");
7118 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7119 nv, ha->nvram_size);
7121 /* Bad NVRAM data, set defaults parameters. */
7122 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7123 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7124 /* Reset NVRAM data. */
7125 ql_log(ql_log_warn, vha, 0x006b,
7126 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7127 chksum, nv->id, nv->nvram_version);
7128 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7129 ql_log(ql_log_warn, vha, 0x006c,
7130 "Falling back to functioning (yet invalid -- WWPN) "
7134 * Set default initialization control block.
7136 memset(nv, 0, ha->nvram_size);
7137 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7138 nv->version = cpu_to_le16(ICB_VERSION);
7139 nv->frame_payload_size = 2048;
7140 nv->execution_throttle = cpu_to_le16(0xFFFF);
7141 nv->exchange_count = cpu_to_le16(0);
7142 nv->hard_address = cpu_to_le16(124);
7143 nv->port_name[0] = 0x21;
7144 nv->port_name[1] = 0x00 + ha->port_no + 1;
7145 nv->port_name[2] = 0x00;
7146 nv->port_name[3] = 0xe0;
7147 nv->port_name[4] = 0x8b;
7148 nv->port_name[5] = 0x1c;
7149 nv->port_name[6] = 0x55;
7150 nv->port_name[7] = 0x86;
7151 nv->node_name[0] = 0x20;
7152 nv->node_name[1] = 0x00;
7153 nv->node_name[2] = 0x00;
7154 nv->node_name[3] = 0xe0;
7155 nv->node_name[4] = 0x8b;
7156 nv->node_name[5] = 0x1c;
7157 nv->node_name[6] = 0x55;
7158 nv->node_name[7] = 0x86;
7159 qla24xx_nvram_wwn_from_ofw(vha, nv);
7160 nv->login_retry_count = cpu_to_le16(8);
7161 nv->interrupt_delay_timer = cpu_to_le16(0);
7162 nv->login_timeout = cpu_to_le16(0);
7163 nv->firmware_options_1 =
7164 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7165 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7166 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7167 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7168 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7169 nv->efi_parameters = cpu_to_le32(0);
7170 nv->reset_delay = 5;
7171 nv->max_luns_per_target = cpu_to_le16(128);
7172 nv->port_down_retry_count = cpu_to_le16(30);
7173 nv->link_down_timeout = cpu_to_le16(30);
7178 if (qla_tgt_mode_enabled(vha)) {
7179 /* Don't enable full login after initial LIP */
7180 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7181 /* Don't enable LIP full login for initiator */
7182 nv->host_p &= cpu_to_le32(~BIT_10);
7185 qlt_24xx_config_nvram_stage1(vha, nv);
7187 /* Reset Initialization control block */
7188 memset(icb, 0, ha->init_cb_size);
7190 /* Copy 1st segment. */
7191 dptr1 = (uint8_t *)icb;
7192 dptr2 = (uint8_t *)&nv->version;
7193 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7195 *dptr1++ = *dptr2++;
7197 icb->login_retry_count = nv->login_retry_count;
7198 icb->link_down_on_nos = nv->link_down_on_nos;
7200 /* Copy 2nd segment. */
7201 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7202 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7203 cnt = (uint8_t *)&icb->reserved_3 -
7204 (uint8_t *)&icb->interrupt_delay_timer;
7206 *dptr1++ = *dptr2++;
7207 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7209 * Setup driver NVRAM options.
7211 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7214 qlt_24xx_config_nvram_stage2(vha, icb);
7216 if (nv->host_p & cpu_to_le32(BIT_15)) {
7217 /* Use alternate WWN? */
7218 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7219 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7222 /* Prepare nodename */
7223 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7225 * Firmware will apply the following mask if the nodename was
7228 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7229 icb->node_name[0] &= 0xF0;
7232 /* Set host adapter parameters. */
7233 ha->flags.disable_risc_code_load = 0;
7234 ha->flags.enable_lip_reset = 0;
7235 ha->flags.enable_lip_full_login =
7236 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7237 ha->flags.enable_target_reset =
7238 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7239 ha->flags.enable_led_scheme = 0;
7240 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7242 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7243 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7245 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7246 sizeof(ha->fw_seriallink_options24));
7248 /* save HBA serial number */
7249 ha->serial0 = icb->port_name[5];
7250 ha->serial1 = icb->port_name[6];
7251 ha->serial2 = icb->port_name[7];
7252 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7253 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7255 icb->execution_throttle = cpu_to_le16(0xFFFF);
7257 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7259 /* Set minimum login_timeout to 4 seconds. */
7260 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7261 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7262 if (le16_to_cpu(nv->login_timeout) < 4)
7263 nv->login_timeout = cpu_to_le16(4);
7264 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7266 /* Set minimum RATOV to 100 tenths of a second. */
7269 ha->loop_reset_delay = nv->reset_delay;
7271 /* Link Down Timeout = 0:
7273 * When Port Down timer expires we will start returning
7274 * I/O's to OS with "DID_NO_CONNECT".
7276 * Link Down Timeout != 0:
7278 * The driver waits for the link to come up after link down
7279 * before returning I/Os to OS with "DID_NO_CONNECT".
7281 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7282 ha->loop_down_abort_time =
7283 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7285 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7286 ha->loop_down_abort_time =
7287 (LOOP_DOWN_TIME - ha->link_down_timeout);
7290 /* Need enough time to try and get the port back. */
7291 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7292 if (qlport_down_retry)
7293 ha->port_down_retry_count = qlport_down_retry;
7295 /* Set login_retry_count */
7296 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7297 if (ha->port_down_retry_count ==
7298 le16_to_cpu(nv->port_down_retry_count) &&
7299 ha->port_down_retry_count > 3)
7300 ha->login_retry_count = ha->port_down_retry_count;
7301 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7302 ha->login_retry_count = ha->port_down_retry_count;
7303 if (ql2xloginretrycount)
7304 ha->login_retry_count = ql2xloginretrycount;
7306 /* N2N: driver will initiate Login instead of FW */
7307 icb->firmware_options_3 |= BIT_8;
7310 if (!vha->flags.init_done) {
7311 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7312 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7313 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7314 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7316 icb->firmware_options_2 &= cpu_to_le32(
7317 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7318 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7319 ha->zio_mode = QLA_ZIO_MODE_6;
7321 ql_log(ql_log_info, vha, 0x006f,
7322 "ZIO mode %d enabled; timer delay (%d us).\n",
7323 ha->zio_mode, ha->zio_timer * 100);
7325 icb->firmware_options_2 |= cpu_to_le32(
7326 (uint32_t)ha->zio_mode);
7327 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7331 ql_log(ql_log_warn, vha, 0x0070,
7332 "NVRAM configuration failed.\n");
7338 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7339 struct qla27xx_image_status *image_status)
7341 ql_dbg(ql_dbg_init, vha, 0x018b,
7342 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7344 image_status->image_status_mask,
7345 le16_to_cpu(image_status->generation),
7346 image_status->ver_major,
7347 image_status->ver_minor,
7348 image_status->bitmap,
7349 le32_to_cpu(image_status->checksum),
7350 le32_to_cpu(image_status->signature));
7354 qla28xx_check_aux_image_status_signature(
7355 struct qla27xx_image_status *image_status)
7357 ulong signature = le32_to_cpu(image_status->signature);
7359 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7363 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7365 ulong signature = le32_to_cpu(image_status->signature);
7368 signature != QLA27XX_IMG_STATUS_SIGN &&
7369 signature != QLA28XX_IMG_STATUS_SIGN;
7373 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7375 uint32_t *p = (void *)image_status;
7376 uint n = sizeof(*image_status) / sizeof(*p);
7380 sum += le32_to_cpup(p);
7386 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7388 return aux->bitmap & bitmask ?
7389 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7393 qla28xx_component_status(
7394 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7396 active_regions->aux.board_config =
7397 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7399 active_regions->aux.vpd_nvram =
7400 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7402 active_regions->aux.npiv_config_0_1 =
7403 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7405 active_regions->aux.npiv_config_2_3 =
7406 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7410 qla27xx_compare_image_generation(
7411 struct qla27xx_image_status *pri_image_status,
7412 struct qla27xx_image_status *sec_image_status)
7414 /* calculate generation delta as uint16 (this accounts for wrap) */
7416 le16_to_cpu(pri_image_status->generation) -
7417 le16_to_cpu(sec_image_status->generation);
7419 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7425 qla28xx_get_aux_images(
7426 struct scsi_qla_host *vha, struct active_regions *active_regions)
7428 struct qla_hw_data *ha = vha->hw;
7429 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7430 bool valid_pri_image = false, valid_sec_image = false;
7431 bool active_pri_image = false, active_sec_image = false;
7433 if (!ha->flt_region_aux_img_status_pri) {
7434 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7435 goto check_sec_image;
7438 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7439 ha->flt_region_aux_img_status_pri,
7440 sizeof(pri_aux_image_status) >> 2);
7441 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7443 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7444 ql_dbg(ql_dbg_init, vha, 0x018b,
7445 "Primary aux image signature (%#x) not valid\n",
7446 le32_to_cpu(pri_aux_image_status.signature));
7447 goto check_sec_image;
7450 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7451 ql_dbg(ql_dbg_init, vha, 0x018c,
7452 "Primary aux image checksum failed\n");
7453 goto check_sec_image;
7456 valid_pri_image = true;
7458 if (pri_aux_image_status.image_status_mask & 1) {
7459 ql_dbg(ql_dbg_init, vha, 0x018d,
7460 "Primary aux image is active\n");
7461 active_pri_image = true;
7465 if (!ha->flt_region_aux_img_status_sec) {
7466 ql_dbg(ql_dbg_init, vha, 0x018a,
7467 "Secondary aux image not addressed\n");
7468 goto check_valid_image;
7471 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7472 ha->flt_region_aux_img_status_sec,
7473 sizeof(sec_aux_image_status) >> 2);
7474 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7476 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7477 ql_dbg(ql_dbg_init, vha, 0x018b,
7478 "Secondary aux image signature (%#x) not valid\n",
7479 le32_to_cpu(sec_aux_image_status.signature));
7480 goto check_valid_image;
7483 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7484 ql_dbg(ql_dbg_init, vha, 0x018c,
7485 "Secondary aux image checksum failed\n");
7486 goto check_valid_image;
7489 valid_sec_image = true;
7491 if (sec_aux_image_status.image_status_mask & 1) {
7492 ql_dbg(ql_dbg_init, vha, 0x018d,
7493 "Secondary aux image is active\n");
7494 active_sec_image = true;
7498 if (valid_pri_image && active_pri_image &&
7499 valid_sec_image && active_sec_image) {
7500 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7501 &sec_aux_image_status) >= 0) {
7502 qla28xx_component_status(active_regions,
7503 &pri_aux_image_status);
7505 qla28xx_component_status(active_regions,
7506 &sec_aux_image_status);
7508 } else if (valid_pri_image && active_pri_image) {
7509 qla28xx_component_status(active_regions, &pri_aux_image_status);
7510 } else if (valid_sec_image && active_sec_image) {
7511 qla28xx_component_status(active_regions, &sec_aux_image_status);
7514 ql_dbg(ql_dbg_init, vha, 0x018f,
7515 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7516 active_regions->aux.board_config,
7517 active_regions->aux.vpd_nvram,
7518 active_regions->aux.npiv_config_0_1,
7519 active_regions->aux.npiv_config_2_3);
7523 qla27xx_get_active_image(struct scsi_qla_host *vha,
7524 struct active_regions *active_regions)
7526 struct qla_hw_data *ha = vha->hw;
7527 struct qla27xx_image_status pri_image_status, sec_image_status;
7528 bool valid_pri_image = false, valid_sec_image = false;
7529 bool active_pri_image = false, active_sec_image = false;
7531 if (!ha->flt_region_img_status_pri) {
7532 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7533 goto check_sec_image;
7536 qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7537 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2);
7538 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7540 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7541 ql_dbg(ql_dbg_init, vha, 0x018b,
7542 "Primary image signature (%#x) not valid\n",
7543 le32_to_cpu(pri_image_status.signature));
7544 goto check_sec_image;
7547 if (qla27xx_image_status_checksum(&pri_image_status)) {
7548 ql_dbg(ql_dbg_init, vha, 0x018c,
7549 "Primary image checksum failed\n");
7550 goto check_sec_image;
7553 valid_pri_image = true;
7555 if (pri_image_status.image_status_mask & 1) {
7556 ql_dbg(ql_dbg_init, vha, 0x018d,
7557 "Primary image is active\n");
7558 active_pri_image = true;
7562 if (!ha->flt_region_img_status_sec) {
7563 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7564 goto check_valid_image;
7567 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7568 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7569 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7571 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7572 ql_dbg(ql_dbg_init, vha, 0x018b,
7573 "Secondary image signature (%#x) not valid\n",
7574 le32_to_cpu(sec_image_status.signature));
7575 goto check_valid_image;
7578 if (qla27xx_image_status_checksum(&sec_image_status)) {
7579 ql_dbg(ql_dbg_init, vha, 0x018c,
7580 "Secondary image checksum failed\n");
7581 goto check_valid_image;
7584 valid_sec_image = true;
7586 if (sec_image_status.image_status_mask & 1) {
7587 ql_dbg(ql_dbg_init, vha, 0x018d,
7588 "Secondary image is active\n");
7589 active_sec_image = true;
7593 if (valid_pri_image && active_pri_image)
7594 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7596 if (valid_sec_image && active_sec_image) {
7597 if (!active_regions->global ||
7598 qla27xx_compare_image_generation(
7599 &pri_image_status, &sec_image_status) < 0) {
7600 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7604 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7605 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7606 "default (boot/fw)" :
7607 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7609 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7610 "secondary" : "invalid",
7611 active_regions->global);
7614 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7617 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7618 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7622 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7626 uint templates, segments, fragment;
7631 uint32_t risc_addr, risc_size, risc_attr = 0;
7632 struct qla_hw_data *ha = vha->hw;
7633 struct req_que *req = ha->req_q_map[0];
7634 struct fwdt *fwdt = ha->fwdt;
7636 ql_dbg(ql_dbg_init, vha, 0x008b,
7637 "FW: Loading firmware from flash (%x).\n", faddr);
7639 dcode = (void *)req->ring;
7640 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7641 if (qla24xx_risc_firmware_invalid(dcode)) {
7642 ql_log(ql_log_fatal, vha, 0x008c,
7643 "Unable to verify the integrity of flash firmware "
7645 ql_log(ql_log_fatal, vha, 0x008d,
7646 "Firmware data: %08x %08x %08x %08x.\n",
7647 dcode[0], dcode[1], dcode[2], dcode[3]);
7649 return QLA_FUNCTION_FAILED;
7652 dcode = (void *)req->ring;
7654 segments = FA_RISC_CODE_SEGMENTS;
7655 for (j = 0; j < segments; j++) {
7656 ql_dbg(ql_dbg_init, vha, 0x008d,
7657 "-> Loading segment %u...\n", j);
7658 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7659 risc_addr = be32_to_cpu(dcode[2]);
7660 risc_size = be32_to_cpu(dcode[3]);
7662 *srisc_addr = risc_addr;
7663 risc_attr = be32_to_cpu(dcode[9]);
7666 dlen = ha->fw_transfer_size >> 2;
7667 for (fragment = 0; risc_size; fragment++) {
7668 if (dlen > risc_size)
7671 ql_dbg(ql_dbg_init, vha, 0x008e,
7672 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7673 fragment, risc_addr, faddr, dlen);
7674 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7675 for (i = 0; i < dlen; i++)
7676 dcode[i] = swab32(dcode[i]);
7678 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7680 ql_log(ql_log_fatal, vha, 0x008f,
7681 "-> Failed load firmware fragment %u.\n",
7683 return QLA_FUNCTION_FAILED;
7692 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7695 templates = (risc_attr & BIT_9) ? 2 : 1;
7696 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7697 for (j = 0; j < templates; j++, fwdt++) {
7699 vfree(fwdt->template);
7700 fwdt->template = NULL;
7703 dcode = (void *)req->ring;
7704 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7705 risc_size = be32_to_cpu(dcode[2]);
7706 ql_dbg(ql_dbg_init, vha, 0x0161,
7707 "-> fwdt%u template array at %#x (%#x dwords)\n",
7708 j, faddr, risc_size);
7709 if (!risc_size || !~risc_size) {
7710 ql_dbg(ql_dbg_init, vha, 0x0162,
7711 "-> fwdt%u failed to read array\n", j);
7715 /* skip header and ignore checksum */
7719 ql_dbg(ql_dbg_init, vha, 0x0163,
7720 "-> fwdt%u template allocate template %#x words...\n",
7722 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7723 if (!fwdt->template) {
7724 ql_log(ql_log_warn, vha, 0x0164,
7725 "-> fwdt%u failed allocate template.\n", j);
7729 dcode = fwdt->template;
7730 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7732 if (!qla27xx_fwdt_template_valid(dcode)) {
7733 ql_log(ql_log_warn, vha, 0x0165,
7734 "-> fwdt%u failed template validate\n", j);
7738 dlen = qla27xx_fwdt_template_size(dcode);
7739 ql_dbg(ql_dbg_init, vha, 0x0166,
7740 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7741 j, dlen, dlen / sizeof(*dcode));
7742 if (dlen > risc_size * sizeof(*dcode)) {
7743 ql_log(ql_log_warn, vha, 0x0167,
7744 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7745 j, dlen - risc_size * sizeof(*dcode));
7749 fwdt->length = dlen;
7750 ql_dbg(ql_dbg_init, vha, 0x0168,
7751 "-> fwdt%u loaded template ok\n", j);
7753 faddr += risc_size + 1;
7760 vfree(fwdt->template);
7761 fwdt->template = NULL;
7767 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7770 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7774 uint16_t *wcode, *fwcode;
7775 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7776 struct fw_blob *blob;
7777 struct qla_hw_data *ha = vha->hw;
7778 struct req_que *req = ha->req_q_map[0];
7780 /* Load firmware blob. */
7781 blob = qla2x00_request_firmware(vha);
7783 ql_log(ql_log_info, vha, 0x0083,
7784 "Firmware image unavailable.\n");
7785 ql_log(ql_log_info, vha, 0x0084,
7786 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7787 return QLA_FUNCTION_FAILED;
7792 wcode = (uint16_t *)req->ring;
7794 fwcode = (uint16_t *)blob->fw->data;
7797 /* Validate firmware image by checking version. */
7798 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7799 ql_log(ql_log_fatal, vha, 0x0085,
7800 "Unable to verify integrity of firmware image (%zd).\n",
7802 goto fail_fw_integrity;
7804 for (i = 0; i < 4; i++)
7805 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7806 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7807 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7808 wcode[2] == 0 && wcode[3] == 0)) {
7809 ql_log(ql_log_fatal, vha, 0x0086,
7810 "Unable to verify integrity of firmware image.\n");
7811 ql_log(ql_log_fatal, vha, 0x0087,
7812 "Firmware data: %04x %04x %04x %04x.\n",
7813 wcode[0], wcode[1], wcode[2], wcode[3]);
7814 goto fail_fw_integrity;
7818 while (*seg && rval == QLA_SUCCESS) {
7820 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7821 risc_size = be16_to_cpu(fwcode[3]);
7823 /* Validate firmware image size. */
7824 fwclen += risc_size * sizeof(uint16_t);
7825 if (blob->fw->size < fwclen) {
7826 ql_log(ql_log_fatal, vha, 0x0088,
7827 "Unable to verify integrity of firmware image "
7828 "(%zd).\n", blob->fw->size);
7829 goto fail_fw_integrity;
7833 while (risc_size > 0 && rval == QLA_SUCCESS) {
7834 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7835 if (wlen > risc_size)
7837 ql_dbg(ql_dbg_init, vha, 0x0089,
7838 "Loading risc segment@ risc addr %x number of "
7839 "words 0x%x.\n", risc_addr, wlen);
7841 for (i = 0; i < wlen; i++)
7842 wcode[i] = swab16(fwcode[i]);
7844 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7847 ql_log(ql_log_fatal, vha, 0x008a,
7848 "Failed to load segment %d of firmware.\n",
7865 return QLA_FUNCTION_FAILED;
7869 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7872 uint templates, segments, fragment;
7875 uint32_t risc_addr, risc_size, risc_attr = 0;
7878 struct fw_blob *blob;
7880 struct qla_hw_data *ha = vha->hw;
7881 struct req_que *req = ha->req_q_map[0];
7882 struct fwdt *fwdt = ha->fwdt;
7884 ql_dbg(ql_dbg_init, vha, 0x0090,
7885 "-> FW: Loading via request-firmware.\n");
7887 blob = qla2x00_request_firmware(vha);
7889 ql_log(ql_log_warn, vha, 0x0092,
7890 "-> Firmware file not found.\n");
7892 return QLA_FUNCTION_FAILED;
7895 fwcode = (void *)blob->fw->data;
7897 if (qla24xx_risc_firmware_invalid(dcode)) {
7898 ql_log(ql_log_fatal, vha, 0x0093,
7899 "Unable to verify integrity of firmware image (%zd).\n",
7901 ql_log(ql_log_fatal, vha, 0x0095,
7902 "Firmware data: %08x %08x %08x %08x.\n",
7903 dcode[0], dcode[1], dcode[2], dcode[3]);
7904 return QLA_FUNCTION_FAILED;
7907 dcode = (void *)req->ring;
7909 segments = FA_RISC_CODE_SEGMENTS;
7910 for (j = 0; j < segments; j++) {
7911 ql_dbg(ql_dbg_init, vha, 0x0096,
7912 "-> Loading segment %u...\n", j);
7913 risc_addr = be32_to_cpu(fwcode[2]);
7914 risc_size = be32_to_cpu(fwcode[3]);
7917 *srisc_addr = risc_addr;
7918 risc_attr = be32_to_cpu(fwcode[9]);
7921 dlen = ha->fw_transfer_size >> 2;
7922 for (fragment = 0; risc_size; fragment++) {
7923 if (dlen > risc_size)
7926 ql_dbg(ql_dbg_init, vha, 0x0097,
7927 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7928 fragment, risc_addr,
7929 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7932 for (i = 0; i < dlen; i++)
7933 dcode[i] = swab32(fwcode[i]);
7935 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7937 ql_log(ql_log_fatal, vha, 0x0098,
7938 "-> Failed load firmware fragment %u.\n",
7940 return QLA_FUNCTION_FAILED;
7949 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7952 templates = (risc_attr & BIT_9) ? 2 : 1;
7953 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
7954 for (j = 0; j < templates; j++, fwdt++) {
7956 vfree(fwdt->template);
7957 fwdt->template = NULL;
7960 risc_size = be32_to_cpu(fwcode[2]);
7961 ql_dbg(ql_dbg_init, vha, 0x0171,
7962 "-> fwdt%u template array at %#x (%#x dwords)\n",
7963 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
7965 if (!risc_size || !~risc_size) {
7966 ql_dbg(ql_dbg_init, vha, 0x0172,
7967 "-> fwdt%u failed to read array\n", j);
7971 /* skip header and ignore checksum */
7975 ql_dbg(ql_dbg_init, vha, 0x0173,
7976 "-> fwdt%u template allocate template %#x words...\n",
7978 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7979 if (!fwdt->template) {
7980 ql_log(ql_log_warn, vha, 0x0174,
7981 "-> fwdt%u failed allocate template.\n", j);
7985 dcode = fwdt->template;
7986 for (i = 0; i < risc_size; i++)
7987 dcode[i] = fwcode[i];
7989 if (!qla27xx_fwdt_template_valid(dcode)) {
7990 ql_log(ql_log_warn, vha, 0x0175,
7991 "-> fwdt%u failed template validate\n", j);
7995 dlen = qla27xx_fwdt_template_size(dcode);
7996 ql_dbg(ql_dbg_init, vha, 0x0176,
7997 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7998 j, dlen, dlen / sizeof(*dcode));
7999 if (dlen > risc_size * sizeof(*dcode)) {
8000 ql_log(ql_log_warn, vha, 0x0177,
8001 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8002 j, dlen - risc_size * sizeof(*dcode));
8006 fwdt->length = dlen;
8007 ql_dbg(ql_dbg_init, vha, 0x0178,
8008 "-> fwdt%u loaded template ok\n", j);
8010 fwcode += risc_size + 1;
8017 vfree(fwdt->template);
8018 fwdt->template = NULL;
8025 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8029 if (ql2xfwloadbin == 1)
8030 return qla81xx_load_risc(vha, srisc_addr);
8034 * 1) Firmware via request-firmware interface (.bin file).
8035 * 2) Firmware residing in flash.
8037 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8038 if (rval == QLA_SUCCESS)
8041 return qla24xx_load_risc_flash(vha, srisc_addr,
8042 vha->hw->flt_region_fw);
8046 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8049 struct qla_hw_data *ha = vha->hw;
8050 struct active_regions active_regions = { };
8052 if (ql2xfwloadbin == 2)
8055 /* FW Load priority:
8056 * 1) Firmware residing in flash.
8057 * 2) Firmware via request-firmware interface (.bin file).
8058 * 3) Golden-Firmware residing in flash -- (limited operation).
8061 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8062 goto try_primary_fw;
8064 qla27xx_get_active_image(vha, &active_regions);
8066 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8067 goto try_primary_fw;
8069 ql_dbg(ql_dbg_init, vha, 0x008b,
8070 "Loading secondary firmware image.\n");
8071 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8076 ql_dbg(ql_dbg_init, vha, 0x008b,
8077 "Loading primary firmware image.\n");
8078 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8083 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8084 if (!rval || !ha->flt_region_gold_fw)
8087 ql_log(ql_log_info, vha, 0x0099,
8088 "Attempting to fallback to golden firmware.\n");
8089 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8093 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8094 ha->flags.running_gold_fw = 1;
8099 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8102 struct qla_hw_data *ha = vha->hw;
8104 if (ha->flags.pci_channel_io_perm_failure)
8106 if (!IS_FWI2_CAPABLE(ha))
8108 if (!ha->fw_major_version)
8110 if (!ha->flags.fw_started)
8113 ret = qla2x00_stop_firmware(vha);
8114 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8115 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8116 ha->isp_ops->reset_chip(vha);
8117 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8119 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8121 ql_log(ql_log_info, vha, 0x8015,
8122 "Attempting retry of stop-firmware command.\n");
8123 ret = qla2x00_stop_firmware(vha);
8127 ha->flags.fw_init_done = 0;
8131 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8133 int rval = QLA_SUCCESS;
8135 uint16_t mb[MAILBOX_REGISTER_COUNT];
8136 struct qla_hw_data *ha = vha->hw;
8137 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8142 rval = qla2x00_fw_ready(base_vha);
8144 if (rval == QLA_SUCCESS) {
8145 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8146 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8149 vha->flags.management_server_logged_in = 0;
8151 /* Login to SNS first */
8152 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8154 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8155 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8156 ql_dbg(ql_dbg_init, vha, 0x0120,
8157 "Failed SNS login: loop_id=%x, rval2=%d\n",
8160 ql_dbg(ql_dbg_init, vha, 0x0103,
8161 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8162 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8163 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8164 return (QLA_FUNCTION_FAILED);
8167 atomic_set(&vha->loop_down_timer, 0);
8168 atomic_set(&vha->loop_state, LOOP_UP);
8169 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8170 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8171 rval = qla2x00_loop_resync(base_vha);
8176 /* 84XX Support **************************************************************/
8178 static LIST_HEAD(qla_cs84xx_list);
8179 static DEFINE_MUTEX(qla_cs84xx_mutex);
8181 static struct qla_chip_state_84xx *
8182 qla84xx_get_chip(struct scsi_qla_host *vha)
8184 struct qla_chip_state_84xx *cs84xx;
8185 struct qla_hw_data *ha = vha->hw;
8187 mutex_lock(&qla_cs84xx_mutex);
8189 /* Find any shared 84xx chip. */
8190 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8191 if (cs84xx->bus == ha->pdev->bus) {
8192 kref_get(&cs84xx->kref);
8197 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8201 kref_init(&cs84xx->kref);
8202 spin_lock_init(&cs84xx->access_lock);
8203 mutex_init(&cs84xx->fw_update_mutex);
8204 cs84xx->bus = ha->pdev->bus;
8206 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8208 mutex_unlock(&qla_cs84xx_mutex);
8213 __qla84xx_chip_release(struct kref *kref)
8215 struct qla_chip_state_84xx *cs84xx =
8216 container_of(kref, struct qla_chip_state_84xx, kref);
8218 mutex_lock(&qla_cs84xx_mutex);
8219 list_del(&cs84xx->list);
8220 mutex_unlock(&qla_cs84xx_mutex);
8225 qla84xx_put_chip(struct scsi_qla_host *vha)
8227 struct qla_hw_data *ha = vha->hw;
8230 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8234 qla84xx_init_chip(scsi_qla_host_t *vha)
8238 struct qla_hw_data *ha = vha->hw;
8240 mutex_lock(&ha->cs84xx->fw_update_mutex);
8242 rval = qla84xx_verify_chip(vha, status);
8244 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8246 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8250 /* 81XX Support **************************************************************/
8253 qla81xx_nvram_config(scsi_qla_host_t *vha)
8256 struct init_cb_81xx *icb;
8257 struct nvram_81xx *nv;
8259 uint8_t *dptr1, *dptr2;
8262 struct qla_hw_data *ha = vha->hw;
8264 struct active_regions active_regions = { };
8267 icb = (struct init_cb_81xx *)ha->init_cb;
8270 /* Determine NVRAM starting address. */
8271 ha->nvram_size = sizeof(*nv);
8272 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8273 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8274 ha->vpd_size = FA_VPD_SIZE_82XX;
8276 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8277 qla28xx_get_aux_images(vha, &active_regions);
8279 /* Get VPD data into cache */
8280 ha->vpd = ha->nvram + VPD_OFFSET;
8282 faddr = ha->flt_region_vpd;
8283 if (IS_QLA28XX(ha)) {
8284 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8285 faddr = ha->flt_region_vpd_sec;
8286 ql_dbg(ql_dbg_init, vha, 0x0110,
8287 "Loading %s nvram image.\n",
8288 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8289 "primary" : "secondary");
8291 qla24xx_read_flash_data(vha, ha->vpd, faddr, ha->vpd_size >> 2);
8293 /* Get NVRAM data into cache and calculate checksum. */
8294 faddr = ha->flt_region_nvram;
8295 if (IS_QLA28XX(ha)) {
8296 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8297 faddr = ha->flt_region_nvram_sec;
8299 ql_dbg(ql_dbg_init, vha, 0x0110,
8300 "Loading %s nvram image.\n",
8301 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8302 "primary" : "secondary");
8303 qla24xx_read_flash_data(vha, ha->nvram, faddr, ha->nvram_size >> 2);
8305 dptr = (uint32_t *)nv;
8306 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8307 chksum += le32_to_cpu(*dptr);
8309 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8310 "Contents of NVRAM:\n");
8311 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8312 nv, ha->nvram_size);
8314 /* Bad NVRAM data, set defaults parameters. */
8315 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8316 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8317 /* Reset NVRAM data. */
8318 ql_log(ql_log_info, vha, 0x0073,
8319 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8320 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8321 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8322 ql_log(ql_log_info, vha, 0x0074,
8323 "Falling back to functioning (yet invalid -- WWPN) "
8327 * Set default initialization control block.
8329 memset(nv, 0, ha->nvram_size);
8330 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8331 nv->version = cpu_to_le16(ICB_VERSION);
8332 nv->frame_payload_size = 2048;
8333 nv->execution_throttle = cpu_to_le16(0xFFFF);
8334 nv->exchange_count = cpu_to_le16(0);
8335 nv->port_name[0] = 0x21;
8336 nv->port_name[1] = 0x00 + ha->port_no + 1;
8337 nv->port_name[2] = 0x00;
8338 nv->port_name[3] = 0xe0;
8339 nv->port_name[4] = 0x8b;
8340 nv->port_name[5] = 0x1c;
8341 nv->port_name[6] = 0x55;
8342 nv->port_name[7] = 0x86;
8343 nv->node_name[0] = 0x20;
8344 nv->node_name[1] = 0x00;
8345 nv->node_name[2] = 0x00;
8346 nv->node_name[3] = 0xe0;
8347 nv->node_name[4] = 0x8b;
8348 nv->node_name[5] = 0x1c;
8349 nv->node_name[6] = 0x55;
8350 nv->node_name[7] = 0x86;
8351 nv->login_retry_count = cpu_to_le16(8);
8352 nv->interrupt_delay_timer = cpu_to_le16(0);
8353 nv->login_timeout = cpu_to_le16(0);
8354 nv->firmware_options_1 =
8355 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8356 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8357 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8358 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8359 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8360 nv->efi_parameters = cpu_to_le32(0);
8361 nv->reset_delay = 5;
8362 nv->max_luns_per_target = cpu_to_le16(128);
8363 nv->port_down_retry_count = cpu_to_le16(30);
8364 nv->link_down_timeout = cpu_to_le16(180);
8365 nv->enode_mac[0] = 0x00;
8366 nv->enode_mac[1] = 0xC0;
8367 nv->enode_mac[2] = 0xDD;
8368 nv->enode_mac[3] = 0x04;
8369 nv->enode_mac[4] = 0x05;
8370 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8375 if (IS_T10_PI_CAPABLE(ha))
8376 nv->frame_payload_size &= ~7;
8378 qlt_81xx_config_nvram_stage1(vha, nv);
8380 /* Reset Initialization control block */
8381 memset(icb, 0, ha->init_cb_size);
8383 /* Copy 1st segment. */
8384 dptr1 = (uint8_t *)icb;
8385 dptr2 = (uint8_t *)&nv->version;
8386 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8388 *dptr1++ = *dptr2++;
8390 icb->login_retry_count = nv->login_retry_count;
8392 /* Copy 2nd segment. */
8393 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8394 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8395 cnt = (uint8_t *)&icb->reserved_5 -
8396 (uint8_t *)&icb->interrupt_delay_timer;
8398 *dptr1++ = *dptr2++;
8400 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8401 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8402 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8403 icb->enode_mac[0] = 0x00;
8404 icb->enode_mac[1] = 0xC0;
8405 icb->enode_mac[2] = 0xDD;
8406 icb->enode_mac[3] = 0x04;
8407 icb->enode_mac[4] = 0x05;
8408 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8411 /* Use extended-initialization control block. */
8412 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8413 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8415 * Setup driver NVRAM options.
8417 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8420 qlt_81xx_config_nvram_stage2(vha, icb);
8422 /* Use alternate WWN? */
8423 if (nv->host_p & cpu_to_le32(BIT_15)) {
8424 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8425 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8428 /* Prepare nodename */
8429 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8431 * Firmware will apply the following mask if the nodename was
8434 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8435 icb->node_name[0] &= 0xF0;
8438 /* Set host adapter parameters. */
8439 ha->flags.disable_risc_code_load = 0;
8440 ha->flags.enable_lip_reset = 0;
8441 ha->flags.enable_lip_full_login =
8442 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8443 ha->flags.enable_target_reset =
8444 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8445 ha->flags.enable_led_scheme = 0;
8446 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8448 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8449 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8451 /* save HBA serial number */
8452 ha->serial0 = icb->port_name[5];
8453 ha->serial1 = icb->port_name[6];
8454 ha->serial2 = icb->port_name[7];
8455 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8456 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8458 icb->execution_throttle = cpu_to_le16(0xFFFF);
8460 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8462 /* Set minimum login_timeout to 4 seconds. */
8463 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8464 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8465 if (le16_to_cpu(nv->login_timeout) < 4)
8466 nv->login_timeout = cpu_to_le16(4);
8467 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8469 /* Set minimum RATOV to 100 tenths of a second. */
8472 ha->loop_reset_delay = nv->reset_delay;
8474 /* Link Down Timeout = 0:
8476 * When Port Down timer expires we will start returning
8477 * I/O's to OS with "DID_NO_CONNECT".
8479 * Link Down Timeout != 0:
8481 * The driver waits for the link to come up after link down
8482 * before returning I/Os to OS with "DID_NO_CONNECT".
8484 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8485 ha->loop_down_abort_time =
8486 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8488 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8489 ha->loop_down_abort_time =
8490 (LOOP_DOWN_TIME - ha->link_down_timeout);
8493 /* Need enough time to try and get the port back. */
8494 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8495 if (qlport_down_retry)
8496 ha->port_down_retry_count = qlport_down_retry;
8498 /* Set login_retry_count */
8499 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8500 if (ha->port_down_retry_count ==
8501 le16_to_cpu(nv->port_down_retry_count) &&
8502 ha->port_down_retry_count > 3)
8503 ha->login_retry_count = ha->port_down_retry_count;
8504 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8505 ha->login_retry_count = ha->port_down_retry_count;
8506 if (ql2xloginretrycount)
8507 ha->login_retry_count = ql2xloginretrycount;
8509 /* if not running MSI-X we need handshaking on interrupts */
8510 if (!vha->hw->flags.msix_enabled &&
8511 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8512 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8515 if (!vha->flags.init_done) {
8516 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8517 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8518 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8519 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8521 icb->firmware_options_2 &= cpu_to_le32(
8522 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8523 vha->flags.process_response_queue = 0;
8524 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8525 ha->zio_mode = QLA_ZIO_MODE_6;
8527 ql_log(ql_log_info, vha, 0x0075,
8528 "ZIO mode %d enabled; timer delay (%d us).\n",
8530 ha->zio_timer * 100);
8532 icb->firmware_options_2 |= cpu_to_le32(
8533 (uint32_t)ha->zio_mode);
8534 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8535 vha->flags.process_response_queue = 1;
8538 /* enable RIDA Format2 */
8539 icb->firmware_options_3 |= BIT_0;
8541 /* N2N: driver will initiate Login instead of FW */
8542 icb->firmware_options_3 |= BIT_8;
8545 ql_log(ql_log_warn, vha, 0x0076,
8546 "NVRAM configuration failed.\n");
8552 qla82xx_restart_isp(scsi_qla_host_t *vha)
8555 struct qla_hw_data *ha = vha->hw;
8556 struct scsi_qla_host *vp;
8557 unsigned long flags;
8559 status = qla2x00_init_rings(vha);
8561 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8562 ha->flags.chip_reset_done = 1;
8564 status = qla2x00_fw_ready(vha);
8566 /* Issue a marker after FW becomes ready. */
8567 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8568 vha->flags.online = 1;
8569 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8572 /* if no cable then assume it's good */
8573 if ((vha->device_flags & DFLG_NO_CABLE))
8578 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8580 if (!atomic_read(&vha->loop_down_timer)) {
8582 * Issue marker command only when we are going
8583 * to start the I/O .
8585 vha->marker_needed = 1;
8588 ha->isp_ops->enable_intrs(ha);
8590 ha->isp_abort_cnt = 0;
8591 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8593 /* Update the firmware version */
8594 status = qla82xx_check_md_needed(vha);
8597 ha->flags.fce_enabled = 1;
8599 fce_calc_size(ha->fce_bufs));
8600 rval = qla2x00_enable_fce_trace(vha,
8601 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8604 ql_log(ql_log_warn, vha, 0x8001,
8605 "Unable to reinitialize FCE (%d).\n",
8607 ha->flags.fce_enabled = 0;
8612 memset(ha->eft, 0, EFT_SIZE);
8613 rval = qla2x00_enable_eft_trace(vha,
8614 ha->eft_dma, EFT_NUM_BUFFERS);
8616 ql_log(ql_log_warn, vha, 0x8010,
8617 "Unable to reinitialize EFT (%d).\n",
8624 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8625 "qla82xx_restart_isp succeeded.\n");
8627 spin_lock_irqsave(&ha->vport_slock, flags);
8628 list_for_each_entry(vp, &ha->vp_list, list) {
8630 atomic_inc(&vp->vref_count);
8631 spin_unlock_irqrestore(&ha->vport_slock, flags);
8633 qla2x00_vp_abort_isp(vp);
8635 spin_lock_irqsave(&ha->vport_slock, flags);
8636 atomic_dec(&vp->vref_count);
8639 spin_unlock_irqrestore(&ha->vport_slock, flags);
8642 ql_log(ql_log_warn, vha, 0x8016,
8643 "qla82xx_restart_isp **** FAILED ****.\n");
8650 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8652 struct qla_hw_data *ha = vha->hw;
8654 /* Hold status IOCBs until ABTS response received. */
8656 ha->fw_options[3] |= BIT_12;
8658 /* Set Retry FLOGI in case of P2P connection */
8659 if (ha->operating_mode == P2P) {
8660 ha->fw_options[2] |= BIT_3;
8661 ql_dbg(ql_dbg_disc, vha, 0x2103,
8662 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8663 __func__, ha->fw_options[2]);
8666 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8667 if (ql2xmvasynctoatio) {
8668 if (qla_tgt_mode_enabled(vha) ||
8669 qla_dual_mode_enabled(vha))
8670 ha->fw_options[2] |= BIT_11;
8672 ha->fw_options[2] &= ~BIT_11;
8675 if (qla_tgt_mode_enabled(vha) ||
8676 qla_dual_mode_enabled(vha)) {
8677 /* FW auto send SCSI status during */
8678 ha->fw_options[1] |= BIT_8;
8679 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8681 /* FW perform Exchange validation */
8682 ha->fw_options[2] |= BIT_4;
8684 ha->fw_options[1] &= ~BIT_8;
8685 ha->fw_options[10] &= 0x00ff;
8687 ha->fw_options[2] &= ~BIT_4;
8690 if (ql2xetsenable) {
8691 /* Enable ETS Burst. */
8692 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8693 ha->fw_options[2] |= BIT_9;
8696 ql_dbg(ql_dbg_init, vha, 0x00e9,
8697 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8698 __func__, ha->fw_options[1], ha->fw_options[2],
8699 ha->fw_options[3], vha->host->active_mode);
8701 qla2x00_set_fw_options(vha, ha->fw_options);
8705 * qla24xx_get_fcp_prio
8706 * Gets the fcp cmd priority value for the logged in port.
8707 * Looks for a match of the port descriptors within
8708 * each of the fcp prio config entries. If a match is found,
8709 * the tag (priority) value is returned.
8712 * vha = scsi host structure pointer.
8713 * fcport = port structure pointer.
8716 * non-zero (if found)
8723 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8726 uint8_t pid_match, wwn_match;
8728 uint32_t pid1, pid2;
8729 uint64_t wwn1, wwn2;
8730 struct qla_fcp_prio_entry *pri_entry;
8731 struct qla_hw_data *ha = vha->hw;
8733 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8737 entries = ha->fcp_prio_cfg->num_entries;
8738 pri_entry = &ha->fcp_prio_cfg->entry[0];
8740 for (i = 0; i < entries; i++) {
8741 pid_match = wwn_match = 0;
8743 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8748 /* check source pid for a match */
8749 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8750 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8751 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8752 if (pid1 == INVALID_PORT_ID)
8754 else if (pid1 == pid2)
8758 /* check destination pid for a match */
8759 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8760 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8761 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8762 if (pid1 == INVALID_PORT_ID)
8764 else if (pid1 == pid2)
8768 /* check source WWN for a match */
8769 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8770 wwn1 = wwn_to_u64(vha->port_name);
8771 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8772 if (wwn2 == (uint64_t)-1)
8774 else if (wwn1 == wwn2)
8778 /* check destination WWN for a match */
8779 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8780 wwn1 = wwn_to_u64(fcport->port_name);
8781 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8782 if (wwn2 == (uint64_t)-1)
8784 else if (wwn1 == wwn2)
8788 if (pid_match == 2 || wwn_match == 2) {
8789 /* Found a matching entry */
8790 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8791 priority = pri_entry->tag;
8802 * qla24xx_update_fcport_fcp_prio
8803 * Activates fcp priority for the logged in fc port
8806 * vha = scsi host structure pointer.
8807 * fcp = port structure pointer.
8810 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8816 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8822 if (fcport->port_type != FCT_TARGET ||
8823 fcport->loop_id == FC_NO_LOOP_ID)
8824 return QLA_FUNCTION_FAILED;
8826 priority = qla24xx_get_fcp_prio(vha, fcport);
8828 return QLA_FUNCTION_FAILED;
8830 if (IS_P3P_TYPE(vha->hw)) {
8831 fcport->fcp_prio = priority & 0xf;
8835 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8836 if (ret == QLA_SUCCESS) {
8837 if (fcport->fcp_prio != priority)
8838 ql_dbg(ql_dbg_user, vha, 0x709e,
8839 "Updated FCP_CMND priority - value=%d loop_id=%d "
8840 "port_id=%02x%02x%02x.\n", priority,
8841 fcport->loop_id, fcport->d_id.b.domain,
8842 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8843 fcport->fcp_prio = priority & 0xf;
8845 ql_dbg(ql_dbg_user, vha, 0x704f,
8846 "Unable to update FCP_CMND priority - ret=0x%x for "
8847 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8848 fcport->d_id.b.domain, fcport->d_id.b.area,
8849 fcport->d_id.b.al_pa);
8854 * qla24xx_update_all_fcp_prio
8855 * Activates fcp priority for all the logged in ports
8858 * ha = adapter block pointer.
8861 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8867 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8872 ret = QLA_FUNCTION_FAILED;
8873 /* We need to set priority for all logged in ports */
8874 list_for_each_entry(fcport, &vha->vp_fcports, list)
8875 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8880 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8881 int vp_idx, bool startqp)
8886 struct qla_hw_data *ha = vha->hw;
8887 uint16_t qpair_id = 0;
8888 struct qla_qpair *qpair = NULL;
8889 struct qla_msix_entry *msix;
8891 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8892 ql_log(ql_log_warn, vha, 0x00181,
8893 "FW/Driver is not multi-queue capable.\n");
8897 if (ql2xmqsupport || ql2xnvmeenable) {
8898 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8899 if (qpair == NULL) {
8900 ql_log(ql_log_warn, vha, 0x0182,
8901 "Failed to allocate memory for queue pair.\n");
8905 qpair->hw = vha->hw;
8907 qpair->qp_lock_ptr = &qpair->qp_lock;
8908 spin_lock_init(&qpair->qp_lock);
8909 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8911 /* Assign available que pair id */
8912 mutex_lock(&ha->mq_lock);
8913 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8914 if (ha->num_qpairs >= ha->max_qpairs) {
8915 mutex_unlock(&ha->mq_lock);
8916 ql_log(ql_log_warn, vha, 0x0183,
8917 "No resources to create additional q pair.\n");
8921 set_bit(qpair_id, ha->qpair_qid_map);
8922 ha->queue_pair_map[qpair_id] = qpair;
8923 qpair->id = qpair_id;
8924 qpair->vp_idx = vp_idx;
8925 qpair->fw_started = ha->flags.fw_started;
8926 INIT_LIST_HEAD(&qpair->hints_list);
8927 qpair->chip_reset = ha->base_qpair->chip_reset;
8928 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8929 qpair->enable_explicit_conf =
8930 ha->base_qpair->enable_explicit_conf;
8932 for (i = 0; i < ha->msix_count; i++) {
8933 msix = &ha->msix_entries[i];
8937 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8938 "Vector %x selected for qpair\n", msix->vector);
8942 ql_log(ql_log_warn, vha, 0x0184,
8943 "Out of MSI-X vectors!.\n");
8947 qpair->msix->in_use = 1;
8948 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8949 qpair->pdev = ha->pdev;
8950 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
8951 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8953 mutex_unlock(&ha->mq_lock);
8955 /* Create response queue first */
8956 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8958 ql_log(ql_log_warn, vha, 0x0185,
8959 "Failed to create response queue.\n");
8963 qpair->rsp = ha->rsp_q_map[rsp_id];
8965 /* Create request queue */
8966 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8969 ql_log(ql_log_warn, vha, 0x0186,
8970 "Failed to create request queue.\n");
8974 qpair->req = ha->req_q_map[req_id];
8975 qpair->rsp->req = qpair->req;
8976 qpair->rsp->qpair = qpair;
8977 /* init qpair to this cpu. Will adjust at run time. */
8978 qla_cpu_update(qpair, smp_processor_id());
8980 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8981 if (ha->fw_attributes & BIT_4)
8982 qpair->difdix_supported = 1;
8985 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8986 if (!qpair->srb_mempool) {
8987 ql_log(ql_log_warn, vha, 0xd036,
8988 "Failed to create srb mempool for qpair %d\n",
8993 /* Mark as online */
8996 if (!vha->flags.qpairs_available)
8997 vha->flags.qpairs_available = 1;
8999 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9000 "Request/Response queue pair created, id %d\n",
9002 ql_dbg(ql_dbg_init, vha, 0x0187,
9003 "Request/Response queue pair created, id %d\n",
9010 qla25xx_delete_rsp_que(vha, qpair->rsp);
9012 mutex_lock(&ha->mq_lock);
9013 qpair->msix->in_use = 0;
9014 list_del(&qpair->qp_list_elem);
9015 if (list_empty(&vha->qp_list))
9016 vha->flags.qpairs_available = 0;
9018 ha->queue_pair_map[qpair_id] = NULL;
9019 clear_bit(qpair_id, ha->qpair_qid_map);
9021 mutex_unlock(&ha->mq_lock);
9027 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9029 int ret = QLA_FUNCTION_FAILED;
9030 struct qla_hw_data *ha = qpair->hw;
9032 qpair->delete_in_progress = 1;
9033 while (atomic_read(&qpair->ref_count))
9036 ret = qla25xx_delete_req_que(vha, qpair->req);
9037 if (ret != QLA_SUCCESS)
9040 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9041 if (ret != QLA_SUCCESS)
9044 mutex_lock(&ha->mq_lock);
9045 ha->queue_pair_map[qpair->id] = NULL;
9046 clear_bit(qpair->id, ha->qpair_qid_map);
9048 list_del(&qpair->qp_list_elem);
9049 if (list_empty(&vha->qp_list)) {
9050 vha->flags.qpairs_available = 0;
9051 vha->flags.qpairs_req_created = 0;
9052 vha->flags.qpairs_rsp_created = 0;
9054 mempool_destroy(qpair->srb_mempool);
9056 mutex_unlock(&ha->mq_lock);