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 "qla_target.h"
23 * QLogic ISP2x00 Hardware Support Function Prototypes.
25 static int qla2x00_isp_firmware(scsi_qla_host_t *);
26 static int qla2x00_setup_chip(scsi_qla_host_t *);
27 static int qla2x00_fw_ready(scsi_qla_host_t *);
28 static int qla2x00_configure_hba(scsi_qla_host_t *);
29 static int qla2x00_configure_loop(scsi_qla_host_t *);
30 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
31 static int qla2x00_configure_fabric(scsi_qla_host_t *);
32 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
33 static int qla2x00_restart_isp(scsi_qla_host_t *);
35 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
36 static int qla84xx_init_chip(scsi_qla_host_t *);
37 static int qla25xx_init_queues(struct qla_hw_data *);
38 static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
39 static void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha,
40 struct event_arg *ea);
41 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
43 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
45 /* SRB Extensions ---------------------------------------------------------- */
48 qla2x00_sp_timeout(struct timer_list *t)
50 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
51 struct srb_iocb *iocb;
54 struct qla_hw_data *ha = sp->vha->hw;
56 WARN_ON_ONCE(irqs_disabled());
57 spin_lock_irqsave(&ha->hardware_lock, flags);
59 req->outstanding_cmds[sp->handle] = NULL;
60 iocb = &sp->u.iocb_cmd;
61 spin_unlock_irqrestore(&ha->hardware_lock, flags);
65 void qla2x00_sp_free(srb_t *sp)
67 struct srb_iocb *iocb = &sp->u.iocb_cmd;
69 del_timer(&iocb->timer);
73 /* Asynchronous Login/Logout Routines -------------------------------------- */
76 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
79 struct qla_hw_data *ha = vha->hw;
81 /* Firmware should use switch negotiated r_a_tov for timeout. */
82 tmo = ha->r_a_tov / 10 * 2;
84 tmo = FX00_DEF_RATOV * 2;
85 } else if (!IS_FWI2_CAPABLE(ha)) {
87 * Except for earlier ISPs where the timeout is seeded from the
88 * initialization control block.
90 tmo = ha->login_timeout;
95 static void qla24xx_abort_iocb_timeout(void *data)
98 struct srb_iocb *abt = &sp->u.iocb_cmd;
99 struct qla_qpair *qpair = sp->qpair;
104 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
105 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
106 sp->cmd_sp->handle, sp->cmd_sp->type,
107 sp->handle, sp->type);
109 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
110 "Abort timeout 2 - hdl=%x, type=%x\n",
111 sp->handle, sp->type);
113 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
114 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
115 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
117 qpair->req->outstanding_cmds[handle] = NULL;
119 /* removing the abort */
120 if (qpair->req->outstanding_cmds[handle] == sp) {
121 qpair->req->outstanding_cmds[handle] = NULL;
125 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
128 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
130 abt->u.abt.comp_status = CS_TIMEOUT;
131 sp->done(sp, QLA_OS_TIMER_EXPIRED);
134 static void qla24xx_abort_sp_done(srb_t *sp, int res)
136 struct srb_iocb *abt = &sp->u.iocb_cmd;
138 del_timer(&sp->u.iocb_cmd.timer);
139 if (sp->flags & SRB_WAKEUP_ON_COMP)
140 complete(&abt->u.abt.comp);
145 static int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
147 scsi_qla_host_t *vha = cmd_sp->vha;
148 struct srb_iocb *abt_iocb;
150 int rval = QLA_FUNCTION_FAILED;
152 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
157 abt_iocb = &sp->u.iocb_cmd;
158 sp->type = SRB_ABT_CMD;
160 sp->qpair = cmd_sp->qpair;
163 sp->flags = SRB_WAKEUP_ON_COMP;
165 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
166 init_completion(&abt_iocb->u.abt.comp);
167 /* FW can send 2 x ABTS's timeout/20s */
168 qla2x00_init_timer(sp, 42);
170 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
171 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
173 sp->done = qla24xx_abort_sp_done;
175 ql_dbg(ql_dbg_async, vha, 0x507c,
176 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
179 rval = qla2x00_start_sp(sp);
180 if (rval != QLA_SUCCESS) {
186 wait_for_completion(&abt_iocb->u.abt.comp);
187 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
188 QLA_SUCCESS : QLA_FUNCTION_FAILED;
196 qla2x00_async_iocb_timeout(void *data)
199 fc_port_t *fcport = sp->fcport;
200 struct srb_iocb *lio = &sp->u.iocb_cmd;
205 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
206 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
207 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
209 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
211 pr_info("Async-%s timeout - hdl=%x.\n",
212 sp->name, sp->handle);
217 rc = qla24xx_async_abort_cmd(sp, false);
219 /* Retry as needed. */
220 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
221 lio->u.logio.data[1] =
222 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
223 QLA_LOGIO_LOGIN_RETRIED : 0;
224 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
225 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
227 if (sp->qpair->req->outstanding_cmds[h] ==
229 sp->qpair->req->outstanding_cmds[h] =
234 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
235 sp->done(sp, QLA_FUNCTION_TIMEOUT);
239 case SRB_CT_PTHRU_CMD:
245 rc = qla24xx_async_abort_cmd(sp, false);
247 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
248 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
250 if (sp->qpair->req->outstanding_cmds[h] ==
252 sp->qpair->req->outstanding_cmds[h] =
257 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
258 sp->done(sp, QLA_FUNCTION_TIMEOUT);
263 sp->done(sp, QLA_FUNCTION_TIMEOUT);
268 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
270 struct scsi_qla_host *vha = sp->vha;
271 struct srb_iocb *lio = &sp->u.iocb_cmd;
274 ql_dbg(ql_dbg_disc, vha, 0x20dd,
275 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
277 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
279 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
280 memset(&ea, 0, sizeof(ea));
281 ea.fcport = sp->fcport;
282 ea.data[0] = lio->u.logio.data[0];
283 ea.data[1] = lio->u.logio.data[1];
284 ea.iop[0] = lio->u.logio.iop[0];
285 ea.iop[1] = lio->u.logio.iop[1];
287 qla24xx_handle_plogi_done_event(vha, &ea);
294 fcport_is_smaller(fc_port_t *fcport)
296 if (wwn_to_u64(fcport->port_name) <
297 wwn_to_u64(fcport->vha->port_name))
304 fcport_is_bigger(fc_port_t *fcport)
306 return !fcport_is_smaller(fcport);
310 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
314 struct srb_iocb *lio;
315 int rval = QLA_FUNCTION_FAILED;
317 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
318 fcport->loop_id == FC_NO_LOOP_ID) {
319 ql_log(ql_log_warn, vha, 0xffff,
320 "%s: %8phC - not sending command.\n",
321 __func__, fcport->port_name);
325 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
329 fcport->flags |= FCF_ASYNC_SENT;
330 fcport->logout_completed = 0;
332 fcport->disc_state = DSC_LOGIN_PEND;
333 sp->type = SRB_LOGIN_CMD;
335 sp->gen1 = fcport->rscn_gen;
336 sp->gen2 = fcport->login_gen;
338 lio = &sp->u.iocb_cmd;
339 lio->timeout = qla2x00_async_iocb_timeout;
340 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
342 sp->done = qla2x00_async_login_sp_done;
343 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
344 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
346 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
348 if (NVME_TARGET(vha->hw, fcport))
349 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
351 ql_dbg(ql_dbg_disc, vha, 0x2072,
352 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
353 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
354 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
355 fcport->login_retry);
357 rval = qla2x00_start_sp(sp);
358 if (rval != QLA_SUCCESS) {
359 fcport->flags |= FCF_LOGIN_NEEDED;
360 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
368 fcport->flags &= ~FCF_ASYNC_SENT;
370 fcport->flags &= ~FCF_ASYNC_ACTIVE;
374 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
376 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
377 sp->fcport->login_gen++;
378 qlt_logo_completion_handler(sp->fcport, res);
383 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
386 struct srb_iocb *lio;
387 int rval = QLA_FUNCTION_FAILED;
389 fcport->flags |= FCF_ASYNC_SENT;
390 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
394 sp->type = SRB_LOGOUT_CMD;
397 lio = &sp->u.iocb_cmd;
398 lio->timeout = qla2x00_async_iocb_timeout;
399 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
401 sp->done = qla2x00_async_logout_sp_done;
403 ql_dbg(ql_dbg_disc, vha, 0x2070,
404 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
405 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
406 fcport->d_id.b.area, fcport->d_id.b.al_pa,
409 rval = qla2x00_start_sp(sp);
410 if (rval != QLA_SUCCESS)
417 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
422 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
425 fcport->flags &= ~FCF_ASYNC_ACTIVE;
426 /* Don't re-login in target mode */
427 if (!fcport->tgt_session)
428 qla2x00_mark_device_lost(vha, fcport, 1, 0);
429 qlt_logo_completion_handler(fcport, data[0]);
432 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
434 struct srb_iocb *lio = &sp->u.iocb_cmd;
435 struct scsi_qla_host *vha = sp->vha;
437 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
438 if (!test_bit(UNLOADING, &vha->dpc_flags))
439 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
445 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
448 struct srb_iocb *lio;
451 rval = QLA_FUNCTION_FAILED;
452 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
456 sp->type = SRB_PRLO_CMD;
459 lio = &sp->u.iocb_cmd;
460 lio->timeout = qla2x00_async_iocb_timeout;
461 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
463 sp->done = qla2x00_async_prlo_sp_done;
465 ql_dbg(ql_dbg_disc, vha, 0x2070,
466 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
467 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
468 fcport->d_id.b.area, fcport->d_id.b.al_pa);
470 rval = qla2x00_start_sp(sp);
471 if (rval != QLA_SUCCESS)
479 fcport->flags &= ~FCF_ASYNC_ACTIVE;
484 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
486 struct fc_port *fcport = ea->fcport;
488 ql_dbg(ql_dbg_disc, vha, 0x20d2,
489 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
490 __func__, fcport->port_name, fcport->disc_state,
491 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
492 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
494 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
497 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
498 ql_dbg(ql_dbg_disc, vha, 0x2066,
499 "%s %8phC: adisc fail: post delete\n",
500 __func__, ea->fcport->port_name);
501 /* deleted = 0 & logout_on_delete = force fw cleanup */
503 fcport->logout_on_delete = 1;
504 qlt_schedule_sess_for_deletion(ea->fcport);
508 if (ea->fcport->disc_state == DSC_DELETE_PEND)
511 if (ea->sp->gen2 != ea->fcport->login_gen) {
512 /* target side must have changed it. */
513 ql_dbg(ql_dbg_disc, vha, 0x20d3,
514 "%s %8phC generation changed\n",
515 __func__, ea->fcport->port_name);
517 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
518 qla_rscn_replay(fcport);
519 qlt_schedule_sess_for_deletion(fcport);
523 __qla24xx_handle_gpdb_event(vha, ea);
526 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
528 struct qla_work_evt *e;
530 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
532 return QLA_FUNCTION_FAILED;
534 e->u.fcport.fcport = fcport;
535 fcport->flags |= FCF_ASYNC_ACTIVE;
536 return qla2x00_post_work(vha, e);
539 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
541 struct scsi_qla_host *vha = sp->vha;
543 struct srb_iocb *lio = &sp->u.iocb_cmd;
545 ql_dbg(ql_dbg_disc, vha, 0x2066,
546 "Async done-%s res %x %8phC\n",
547 sp->name, res, sp->fcport->port_name);
549 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
551 memset(&ea, 0, sizeof(ea));
553 ea.data[0] = lio->u.logio.data[0];
554 ea.data[1] = lio->u.logio.data[1];
555 ea.iop[0] = lio->u.logio.iop[0];
556 ea.iop[1] = lio->u.logio.iop[1];
557 ea.fcport = sp->fcport;
560 qla24xx_handle_adisc_event(vha, &ea);
566 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
570 struct srb_iocb *lio;
571 int rval = QLA_FUNCTION_FAILED;
573 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
576 fcport->flags |= FCF_ASYNC_SENT;
577 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
581 sp->type = SRB_ADISC_CMD;
584 lio = &sp->u.iocb_cmd;
585 lio->timeout = qla2x00_async_iocb_timeout;
586 sp->gen1 = fcport->rscn_gen;
587 sp->gen2 = fcport->login_gen;
588 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
590 sp->done = qla2x00_async_adisc_sp_done;
591 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
592 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
594 ql_dbg(ql_dbg_disc, vha, 0x206f,
595 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
596 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
598 rval = qla2x00_start_sp(sp);
599 if (rval != QLA_SUCCESS)
607 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
608 qla2x00_post_async_adisc_work(vha, fcport, data);
612 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
614 struct qla_hw_data *ha = vha->hw;
616 if (IS_FWI2_CAPABLE(ha))
617 return loop_id > NPH_LAST_HANDLE;
619 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
620 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
624 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
625 * @vha: adapter state pointer.
626 * @dev: port structure pointer.
629 * qla2x00 local function return status code.
634 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
637 struct qla_hw_data *ha = vha->hw;
638 unsigned long flags = 0;
642 spin_lock_irqsave(&ha->vport_slock, flags);
644 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
645 if (dev->loop_id >= LOOPID_MAP_SIZE ||
646 qla2x00_is_reserved_id(vha, dev->loop_id)) {
647 dev->loop_id = FC_NO_LOOP_ID;
648 rval = QLA_FUNCTION_FAILED;
650 set_bit(dev->loop_id, ha->loop_id_map);
652 spin_unlock_irqrestore(&ha->vport_slock, flags);
654 if (rval == QLA_SUCCESS)
655 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
656 "Assigning new loopid=%x, portid=%x.\n",
657 dev->loop_id, dev->d_id.b24);
659 ql_log(ql_log_warn, dev->vha, 0x2087,
660 "No loop_id's available, portid=%x.\n",
666 void qla2x00_clear_loop_id(fc_port_t *fcport)
668 struct qla_hw_data *ha = fcport->vha->hw;
670 if (fcport->loop_id == FC_NO_LOOP_ID ||
671 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
674 clear_bit(fcport->loop_id, ha->loop_id_map);
675 fcport->loop_id = FC_NO_LOOP_ID;
678 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
679 struct event_arg *ea)
681 fc_port_t *fcport, *conflict_fcport;
682 struct get_name_list_extended *e;
683 u16 i, n, found = 0, loop_id;
687 u8 current_login_state;
690 ql_dbg(ql_dbg_disc, vha, 0xffff,
691 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
692 __func__, fcport->port_name, fcport->disc_state,
693 fcport->fw_login_state, ea->rc,
694 fcport->login_gen, fcport->last_login_gen,
695 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
697 if (fcport->disc_state == DSC_DELETE_PEND)
700 if (ea->rc) { /* rval */
701 if (fcport->login_retry == 0) {
702 ql_dbg(ql_dbg_disc, vha, 0x20de,
703 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
704 fcport->port_name, fcport->login_retry);
709 if (fcport->last_rscn_gen != fcport->rscn_gen) {
710 qla_rscn_replay(fcport);
711 qlt_schedule_sess_for_deletion(fcport);
713 } else if (fcport->last_login_gen != fcport->login_gen) {
714 ql_dbg(ql_dbg_disc, vha, 0x20e0,
715 "%s %8phC login gen changed\n",
716 __func__, fcport->port_name);
720 n = ea->data[0] / sizeof(struct get_name_list_extended);
722 ql_dbg(ql_dbg_disc, vha, 0x20e1,
723 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
724 __func__, __LINE__, fcport->port_name, n,
725 fcport->d_id.b.domain, fcport->d_id.b.area,
726 fcport->d_id.b.al_pa, fcport->loop_id);
728 for (i = 0; i < n; i++) {
730 wwn = wwn_to_u64(e->port_name);
731 id.b.domain = e->port_id[2];
732 id.b.area = e->port_id[1];
733 id.b.al_pa = e->port_id[0];
736 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
739 if (IS_SW_RESV_ADDR(id))
744 loop_id = le16_to_cpu(e->nport_handle);
745 loop_id = (loop_id & 0x7fff);
746 if (NVME_TARGET(vha->hw, fcport))
747 current_login_state = e->current_login_state >> 4;
749 current_login_state = e->current_login_state & 0xf;
751 ql_dbg(ql_dbg_disc, vha, 0x20e2,
752 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
753 __func__, fcport->port_name,
754 e->current_login_state, fcport->fw_login_state,
755 fcport->fc4_type, id.b24, fcport->d_id.b24,
756 loop_id, fcport->loop_id);
758 switch (fcport->disc_state) {
759 case DSC_DELETE_PEND:
763 if ((id.b24 != fcport->d_id.b24 &&
765 fcport->loop_id != FC_NO_LOOP_ID) ||
766 (fcport->loop_id != FC_NO_LOOP_ID &&
767 fcport->loop_id != loop_id)) {
768 ql_dbg(ql_dbg_disc, vha, 0x20e3,
769 "%s %d %8phC post del sess\n",
770 __func__, __LINE__, fcport->port_name);
771 if (fcport->n2n_flag)
772 fcport->d_id.b24 = 0;
773 qlt_schedule_sess_for_deletion(fcport);
779 fcport->loop_id = loop_id;
780 if (fcport->n2n_flag)
781 fcport->d_id.b24 = id.b24;
783 wwn = wwn_to_u64(fcport->port_name);
784 qlt_find_sess_invalidate_other(vha, wwn,
785 id, loop_id, &conflict_fcport);
787 if (conflict_fcport) {
789 * Another share fcport share the same loop_id &
790 * nport id. Conflict fcport needs to finish
791 * cleanup before this fcport can proceed to login.
793 conflict_fcport->conflict = fcport;
794 fcport->login_pause = 1;
797 switch (vha->hw->current_topology) {
799 switch (current_login_state) {
800 case DSC_LS_PRLI_COMP:
801 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
802 vha, 0x20e4, "%s %d %8phC post gpdb\n",
803 __func__, __LINE__, fcport->port_name);
805 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
806 fcport->port_type = FCT_INITIATOR;
808 fcport->port_type = FCT_TARGET;
809 data[0] = data[1] = 0;
810 qla2x00_post_async_adisc_work(vha, fcport,
813 case DSC_LS_PORT_UNAVAIL:
815 if (fcport->loop_id == FC_NO_LOOP_ID) {
816 qla2x00_find_new_loop_id(vha, fcport);
817 fcport->fw_login_state =
820 ql_dbg(ql_dbg_disc, vha, 0x20e5,
821 "%s %d %8phC\n", __func__, __LINE__,
823 qla24xx_fcport_handle_login(vha, fcport);
828 fcport->fw_login_state = current_login_state;
830 switch (current_login_state) {
831 case DSC_LS_PRLI_PEND:
833 * In the middle of PRLI. Let it finish.
834 * Allow relogin code to recheck state again
835 * with GNL. Push disc_state back to DELETED
836 * so GNL can go out again
838 fcport->disc_state = DSC_DELETED;
840 case DSC_LS_PRLI_COMP:
841 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
842 fcport->port_type = FCT_INITIATOR;
844 fcport->port_type = FCT_TARGET;
846 data[0] = data[1] = 0;
847 qla2x00_post_async_adisc_work(vha, fcport,
850 case DSC_LS_PLOGI_COMP:
851 if (fcport_is_bigger(fcport)) {
852 /* local adapter is smaller */
853 if (fcport->loop_id != FC_NO_LOOP_ID)
854 qla2x00_clear_loop_id(fcport);
856 fcport->loop_id = loop_id;
857 qla24xx_fcport_handle_login(vha,
863 if (fcport_is_smaller(fcport)) {
864 /* local adapter is bigger */
865 if (fcport->loop_id != FC_NO_LOOP_ID)
866 qla2x00_clear_loop_id(fcport);
868 fcport->loop_id = loop_id;
869 qla24xx_fcport_handle_login(vha,
875 } /* switch (ha->current_topology) */
879 switch (vha->hw->current_topology) {
882 for (i = 0; i < n; i++) {
884 id.b.domain = e->port_id[0];
885 id.b.area = e->port_id[1];
886 id.b.al_pa = e->port_id[2];
888 loop_id = le16_to_cpu(e->nport_handle);
890 if (fcport->d_id.b24 == id.b24) {
892 qla2x00_find_fcport_by_wwpn(vha,
894 if (conflict_fcport) {
895 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
897 "%s %d %8phC post del sess\n",
899 conflict_fcport->port_name);
900 qlt_schedule_sess_for_deletion
905 * FW already picked this loop id for
908 if (fcport->loop_id == loop_id)
909 fcport->loop_id = FC_NO_LOOP_ID;
911 qla24xx_fcport_handle_login(vha, fcport);
914 fcport->disc_state = DSC_DELETED;
915 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
916 if (fcport->n2n_link_reset_cnt < 2) {
917 fcport->n2n_link_reset_cnt++;
919 * remote port is not sending PLOGI.
920 * Reset link to kick start his state
923 set_bit(N2N_LINK_RESET,
926 if (fcport->n2n_chip_reset < 1) {
927 ql_log(ql_log_info, vha, 0x705d,
928 "Chip reset to bring laser down");
929 set_bit(ISP_ABORT_NEEDED,
931 fcport->n2n_chip_reset++;
933 ql_log(ql_log_info, vha, 0x705d,
934 "Remote port %8ph is not coming back\n",
936 fcport->scan_state = 0;
939 qla2xxx_wake_dpc(vha);
942 * report port suppose to do PLOGI. Give him
943 * more time. FW will catch it.
945 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
954 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
956 struct scsi_qla_host *vha = sp->vha;
958 struct fc_port *fcport = NULL, *tf;
959 u16 i, n = 0, loop_id;
961 struct get_name_list_extended *e;
966 ql_dbg(ql_dbg_disc, vha, 0x20e7,
967 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
968 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
969 sp->u.iocb_cmd.u.mbx.in_mb[2]);
971 if (res == QLA_FUNCTION_TIMEOUT)
974 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
975 memset(&ea, 0, sizeof(ea));
979 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
980 sizeof(struct get_name_list_extended)) {
981 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
982 sizeof(struct get_name_list_extended);
983 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
986 for (i = 0; i < n; i++) {
988 loop_id = le16_to_cpu(e->nport_handle);
989 /* mask out reserve bit */
990 loop_id = (loop_id & 0x7fff);
991 set_bit(loop_id, vha->hw->loop_id_map);
992 wwn = wwn_to_u64(e->port_name);
994 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
995 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
996 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
997 e->port_id[0], e->current_login_state, e->last_login_state,
1001 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1005 if (!list_empty(&vha->gnl.fcports))
1006 list_splice_init(&vha->gnl.fcports, &h);
1007 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1009 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
1010 list_del_init(&fcport->gnl_entry);
1011 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1012 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1013 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1016 qla24xx_handle_gnl_done_event(vha, &ea);
1019 /* create new fcport if fw has knowledge of new sessions */
1020 for (i = 0; i < n; i++) {
1025 wwn = wwn_to_u64(e->port_name);
1028 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1029 if (!memcmp((u8 *)&wwn, fcport->port_name,
1036 id.b.domain = e->port_id[2];
1037 id.b.area = e->port_id[1];
1038 id.b.al_pa = e->port_id[0];
1041 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1042 ql_dbg(ql_dbg_disc, vha, 0x2065,
1043 "%s %d %8phC %06x post new sess\n",
1044 __func__, __LINE__, (u8 *)&wwn, id.b24);
1045 wwnn = wwn_to_u64(e->node_name);
1046 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1047 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
1051 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1053 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1058 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1061 struct srb_iocb *mbx;
1062 int rval = QLA_FUNCTION_FAILED;
1063 unsigned long flags;
1066 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1069 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1070 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1072 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1073 fcport->flags |= FCF_ASYNC_SENT;
1074 fcport->disc_state = DSC_GNL;
1075 fcport->last_rscn_gen = fcport->rscn_gen;
1076 fcport->last_login_gen = fcport->login_gen;
1078 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1079 if (vha->gnl.sent) {
1080 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1084 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1086 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1090 sp->type = SRB_MB_IOCB;
1091 sp->name = "gnlist";
1092 sp->gen1 = fcport->rscn_gen;
1093 sp->gen2 = fcport->login_gen;
1095 mbx = &sp->u.iocb_cmd;
1096 mbx->timeout = qla2x00_async_iocb_timeout;
1097 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1099 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1100 mb[0] = MBC_PORT_NODE_NAME_LIST;
1101 mb[1] = BIT_2 | BIT_3;
1102 mb[2] = MSW(vha->gnl.ldma);
1103 mb[3] = LSW(vha->gnl.ldma);
1104 mb[6] = MSW(MSD(vha->gnl.ldma));
1105 mb[7] = LSW(MSD(vha->gnl.ldma));
1106 mb[8] = vha->gnl.size;
1107 mb[9] = vha->vp_idx;
1109 sp->done = qla24xx_async_gnl_sp_done;
1111 ql_dbg(ql_dbg_disc, vha, 0x20da,
1112 "Async-%s - OUT WWPN %8phC hndl %x\n",
1113 sp->name, fcport->port_name, sp->handle);
1115 rval = qla2x00_start_sp(sp);
1116 if (rval != QLA_SUCCESS)
1123 fcport->flags &= ~FCF_ASYNC_SENT;
1128 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1130 struct qla_work_evt *e;
1132 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1134 return QLA_FUNCTION_FAILED;
1136 e->u.fcport.fcport = fcport;
1137 fcport->flags |= FCF_ASYNC_ACTIVE;
1138 return qla2x00_post_work(vha, e);
1141 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1143 struct scsi_qla_host *vha = sp->vha;
1144 struct qla_hw_data *ha = vha->hw;
1145 fc_port_t *fcport = sp->fcport;
1146 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1147 struct event_arg ea;
1149 ql_dbg(ql_dbg_disc, vha, 0x20db,
1150 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1151 sp->name, res, fcport->port_name, mb[1], mb[2]);
1153 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1155 if (res == QLA_FUNCTION_TIMEOUT)
1158 memset(&ea, 0, sizeof(ea));
1162 qla24xx_handle_gpdb_event(vha, &ea);
1165 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1166 sp->u.iocb_cmd.u.mbx.in_dma);
1171 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1173 struct qla_work_evt *e;
1175 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1177 return QLA_FUNCTION_FAILED;
1179 e->u.fcport.fcport = fcport;
1181 return qla2x00_post_work(vha, e);
1184 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1186 struct scsi_qla_host *vha = sp->vha;
1187 struct srb_iocb *lio = &sp->u.iocb_cmd;
1188 struct event_arg ea;
1190 ql_dbg(ql_dbg_disc, vha, 0x2129,
1191 "%s %8phC res %d \n", __func__,
1192 sp->fcport->port_name, res);
1194 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1196 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1197 memset(&ea, 0, sizeof(ea));
1198 ea.fcport = sp->fcport;
1199 ea.data[0] = lio->u.logio.data[0];
1200 ea.data[1] = lio->u.logio.data[1];
1201 ea.iop[0] = lio->u.logio.iop[0];
1202 ea.iop[1] = lio->u.logio.iop[1];
1205 qla24xx_handle_prli_done_event(vha, &ea);
1212 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1215 struct srb_iocb *lio;
1216 int rval = QLA_FUNCTION_FAILED;
1218 if (!vha->flags.online)
1221 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1222 fcport->fw_login_state == DSC_LS_PRLI_PEND)
1225 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1229 fcport->flags |= FCF_ASYNC_SENT;
1230 fcport->logout_completed = 0;
1232 sp->type = SRB_PRLI_CMD;
1235 lio = &sp->u.iocb_cmd;
1236 lio->timeout = qla2x00_async_iocb_timeout;
1237 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1239 sp->done = qla2x00_async_prli_sp_done;
1240 lio->u.logio.flags = 0;
1242 if (NVME_TARGET(vha->hw, fcport))
1243 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1245 ql_dbg(ql_dbg_disc, vha, 0x211b,
1246 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1247 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1248 fcport->login_retry, NVME_TARGET(vha->hw, fcport) ? "nvme" : "fc");
1250 rval = qla2x00_start_sp(sp);
1251 if (rval != QLA_SUCCESS) {
1252 fcport->flags |= FCF_LOGIN_NEEDED;
1253 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1261 fcport->flags &= ~FCF_ASYNC_SENT;
1265 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1267 struct qla_work_evt *e;
1269 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1271 return QLA_FUNCTION_FAILED;
1273 e->u.fcport.fcport = fcport;
1274 e->u.fcport.opt = opt;
1275 fcport->flags |= FCF_ASYNC_ACTIVE;
1276 return qla2x00_post_work(vha, e);
1279 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1282 struct srb_iocb *mbx;
1283 int rval = QLA_FUNCTION_FAILED;
1286 struct port_database_24xx *pd;
1287 struct qla_hw_data *ha = vha->hw;
1289 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1290 fcport->loop_id == FC_NO_LOOP_ID) {
1291 ql_log(ql_log_warn, vha, 0xffff,
1292 "%s: %8phC - not sending command.\n",
1293 __func__, fcport->port_name);
1297 fcport->disc_state = DSC_GPDB;
1299 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1303 fcport->flags |= FCF_ASYNC_SENT;
1304 sp->type = SRB_MB_IOCB;
1306 sp->gen1 = fcport->rscn_gen;
1307 sp->gen2 = fcport->login_gen;
1309 mbx = &sp->u.iocb_cmd;
1310 mbx->timeout = qla2x00_async_iocb_timeout;
1311 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1313 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1315 ql_log(ql_log_warn, vha, 0xd043,
1316 "Failed to allocate port database structure.\n");
1320 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1321 mb[0] = MBC_GET_PORT_DATABASE;
1322 mb[1] = fcport->loop_id;
1323 mb[2] = MSW(pd_dma);
1324 mb[3] = LSW(pd_dma);
1325 mb[6] = MSW(MSD(pd_dma));
1326 mb[7] = LSW(MSD(pd_dma));
1327 mb[9] = vha->vp_idx;
1330 mbx->u.mbx.in = (void *)pd;
1331 mbx->u.mbx.in_dma = pd_dma;
1333 sp->done = qla24xx_async_gpdb_sp_done;
1335 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1336 "Async-%s %8phC hndl %x opt %x\n",
1337 sp->name, fcport->port_name, sp->handle, opt);
1339 rval = qla2x00_start_sp(sp);
1340 if (rval != QLA_SUCCESS)
1346 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1349 fcport->flags &= ~FCF_ASYNC_SENT;
1351 qla24xx_post_gpdb_work(vha, fcport, opt);
1356 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1358 unsigned long flags;
1360 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1361 ea->fcport->login_gen++;
1362 ea->fcport->deleted = 0;
1363 ea->fcport->logout_on_delete = 1;
1365 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1366 vha->fcport_count++;
1367 ea->fcport->login_succ = 1;
1369 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1370 qla24xx_sched_upd_fcport(ea->fcport);
1371 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1372 } else if (ea->fcport->login_succ) {
1374 * We have an existing session. A late RSCN delivery
1375 * must have triggered the session to be re-validate.
1376 * Session is still valid.
1378 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1379 "%s %d %8phC session revalidate success\n",
1380 __func__, __LINE__, ea->fcport->port_name);
1381 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1383 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1387 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1389 fc_port_t *fcport = ea->fcport;
1390 struct port_database_24xx *pd;
1391 struct srb *sp = ea->sp;
1394 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1396 fcport->flags &= ~FCF_ASYNC_SENT;
1398 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1399 "%s %8phC DS %d LS %d fc4_type %x rc %d\n", __func__,
1400 fcport->port_name, fcport->disc_state, pd->current_login_state,
1401 fcport->fc4_type, ea->rc);
1403 if (fcport->disc_state == DSC_DELETE_PEND)
1406 if (NVME_TARGET(vha->hw, fcport))
1407 ls = pd->current_login_state >> 4;
1409 ls = pd->current_login_state & 0xf;
1411 if (ea->sp->gen2 != fcport->login_gen) {
1412 /* target side must have changed it. */
1414 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1415 "%s %8phC generation changed\n",
1416 __func__, fcport->port_name);
1418 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1419 qla_rscn_replay(fcport);
1420 qlt_schedule_sess_for_deletion(fcport);
1425 case PDS_PRLI_COMPLETE:
1426 __qla24xx_parse_gpdb(vha, fcport, pd);
1428 case PDS_PLOGI_PENDING:
1429 case PDS_PLOGI_COMPLETE:
1430 case PDS_PRLI_PENDING:
1431 case PDS_PRLI2_PENDING:
1432 /* Set discovery state back to GNL to Relogin attempt */
1433 if (qla_dual_mode_enabled(vha) ||
1434 qla_ini_mode_enabled(vha)) {
1435 fcport->disc_state = DSC_GNL;
1436 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1439 case PDS_LOGO_PENDING:
1440 case PDS_PORT_UNAVAILABLE:
1442 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1443 __func__, __LINE__, fcport->port_name);
1444 qlt_schedule_sess_for_deletion(fcport);
1447 __qla24xx_handle_gpdb_event(vha, ea);
1450 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1455 if (qla_tgt_mode_enabled(vha))
1458 if (qla_dual_mode_enabled(vha)) {
1459 if (N2N_TOPO(vha->hw)) {
1462 mywwn = wwn_to_u64(vha->port_name);
1463 wwn = wwn_to_u64(fcport->port_name);
1466 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1467 && time_after_eq(jiffies,
1468 fcport->plogi_nack_done_deadline))
1474 /* initiator mode */
1478 if (login && fcport->login_retry) {
1479 fcport->login_retry--;
1480 if (fcport->loop_id == FC_NO_LOOP_ID) {
1481 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1482 rc = qla2x00_find_new_loop_id(vha, fcport);
1484 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1485 "%s %d %8phC post del sess - out of loopid\n",
1486 __func__, __LINE__, fcport->port_name);
1487 fcport->scan_state = 0;
1488 qlt_schedule_sess_for_deletion(fcport);
1492 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1493 "%s %d %8phC post login\n",
1494 __func__, __LINE__, fcport->port_name);
1495 qla2x00_post_async_login_work(vha, fcport, NULL);
1499 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1505 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1506 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1507 __func__, fcport->port_name, fcport->disc_state,
1508 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1509 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1510 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1512 if (fcport->scan_state != QLA_FCPORT_FOUND)
1515 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1516 qla_dual_mode_enabled(vha) &&
1517 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1518 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1521 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1522 !N2N_TOPO(vha->hw)) {
1523 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1524 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1529 /* for pure Target Mode. Login will not be initiated */
1530 if (vha->host->active_mode == MODE_TARGET)
1533 if (fcport->flags & FCF_ASYNC_SENT) {
1534 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1538 switch (fcport->disc_state) {
1540 wwn = wwn_to_u64(fcport->node_name);
1541 switch (vha->hw->current_topology) {
1543 if (fcport_is_smaller(fcport)) {
1544 /* this adapter is bigger */
1545 if (fcport->login_retry) {
1546 if (fcport->loop_id == FC_NO_LOOP_ID) {
1547 qla2x00_find_new_loop_id(vha,
1549 fcport->fw_login_state =
1550 DSC_LS_PORT_UNAVAIL;
1552 fcport->login_retry--;
1553 qla_post_els_plogi_work(vha, fcport);
1555 ql_log(ql_log_info, vha, 0x705d,
1556 "Unable to reach remote port %8phC",
1560 qla24xx_post_gnl_work(vha, fcport);
1565 ql_dbg(ql_dbg_disc, vha, 0xffff,
1566 "%s %d %8phC post GNNID\n",
1567 __func__, __LINE__, fcport->port_name);
1568 qla24xx_post_gnnid_work(vha, fcport);
1569 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1570 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1571 "%s %d %8phC post gnl\n",
1572 __func__, __LINE__, fcport->port_name);
1573 qla24xx_post_gnl_work(vha, fcport);
1575 qla_chk_n2n_b4_login(vha, fcport);
1582 switch (vha->hw->current_topology) {
1584 if ((fcport->current_login_state & 0xf) == 0x6) {
1585 ql_dbg(ql_dbg_disc, vha, 0x2118,
1586 "%s %d %8phC post GPDB work\n",
1587 __func__, __LINE__, fcport->port_name);
1588 fcport->chip_reset =
1589 vha->hw->base_qpair->chip_reset;
1590 qla24xx_post_gpdb_work(vha, fcport, 0);
1592 ql_dbg(ql_dbg_disc, vha, 0x2118,
1593 "%s %d %8phC post %s PRLI\n",
1594 __func__, __LINE__, fcport->port_name,
1595 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1597 qla24xx_post_prli_work(vha, fcport);
1601 if (fcport->login_pause) {
1602 fcport->last_rscn_gen = fcport->rscn_gen;
1603 fcport->last_login_gen = fcport->login_gen;
1604 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1607 qla_chk_n2n_b4_login(vha, fcport);
1612 case DSC_LOGIN_FAILED:
1613 if (N2N_TOPO(vha->hw))
1614 qla_chk_n2n_b4_login(vha, fcport);
1616 qlt_schedule_sess_for_deletion(fcport);
1619 case DSC_LOGIN_COMPLETE:
1620 /* recheck login state */
1621 data[0] = data[1] = 0;
1622 qla2x00_post_async_adisc_work(vha, fcport, data);
1625 case DSC_LOGIN_PEND:
1626 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1627 qla24xx_post_prli_work(vha, fcport);
1630 case DSC_UPD_FCPORT:
1631 sec = jiffies_to_msecs(jiffies -
1632 fcport->jiffies_at_registration)/1000;
1633 if (fcport->sec_since_registration < sec && sec &&
1635 fcport->sec_since_registration = sec;
1636 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1637 "%s %8phC - Slow Rport registration(%d Sec)\n",
1638 __func__, fcport->port_name, sec);
1641 if (fcport->next_disc_state != DSC_DELETE_PEND)
1642 fcport->next_disc_state = DSC_ADISC;
1643 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1653 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1654 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1656 struct qla_work_evt *e;
1658 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1660 return QLA_FUNCTION_FAILED;
1662 e->u.new_sess.id = *id;
1663 e->u.new_sess.pla = pla;
1664 e->u.new_sess.fc4_type = fc4_type;
1665 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1667 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1669 return qla2x00_post_work(vha, e);
1672 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1675 unsigned long flags;
1677 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1679 fcport->scan_needed = 1;
1683 spin_lock_irqsave(&vha->work_lock, flags);
1684 if (vha->scan.scan_flags == 0) {
1685 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1686 vha->scan.scan_flags |= SF_QUEUED;
1687 schedule_delayed_work(&vha->scan.scan_work, 5);
1689 spin_unlock_irqrestore(&vha->work_lock, flags);
1692 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1693 struct event_arg *ea)
1695 fc_port_t *fcport = ea->fcport;
1697 if (test_bit(UNLOADING, &vha->dpc_flags))
1700 ql_dbg(ql_dbg_disc, vha, 0x2102,
1701 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1702 __func__, fcport->port_name, fcport->disc_state,
1703 fcport->fw_login_state, fcport->login_pause,
1704 fcport->deleted, fcport->conflict,
1705 fcport->last_rscn_gen, fcport->rscn_gen,
1706 fcport->last_login_gen, fcport->login_gen,
1709 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1710 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1711 __func__, __LINE__, fcport->port_name);
1712 qla24xx_post_gnl_work(vha, fcport);
1716 qla24xx_fcport_handle_login(vha, fcport);
1719 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1720 struct event_arg *ea)
1722 ql_dbg(ql_dbg_disc, vha, 0x2118,
1723 "%s %d %8phC post PRLI\n",
1724 __func__, __LINE__, ea->fcport->port_name);
1725 qla24xx_post_prli_work(vha, ea->fcport);
1729 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1730 * to be consumed by the fcport
1732 void qla_rscn_replay(fc_port_t *fcport)
1734 struct event_arg ea;
1736 switch (fcport->disc_state) {
1737 case DSC_DELETE_PEND:
1743 if (fcport->scan_needed) {
1744 memset(&ea, 0, sizeof(ea));
1745 ea.id = fcport->d_id;
1746 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1747 qla2x00_handle_rscn(fcport->vha, &ea);
1752 qla2x00_tmf_iocb_timeout(void *data)
1755 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1757 tmf->u.tmf.comp_status = CS_TIMEOUT;
1758 complete(&tmf->u.tmf.comp);
1761 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1763 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1765 complete(&tmf->u.tmf.comp);
1769 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1772 struct scsi_qla_host *vha = fcport->vha;
1773 struct srb_iocb *tm_iocb;
1775 int rval = QLA_FUNCTION_FAILED;
1777 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1781 tm_iocb = &sp->u.iocb_cmd;
1782 sp->type = SRB_TM_CMD;
1785 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1786 init_completion(&tm_iocb->u.tmf.comp);
1787 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1789 tm_iocb->u.tmf.flags = flags;
1790 tm_iocb->u.tmf.lun = lun;
1791 tm_iocb->u.tmf.data = tag;
1792 sp->done = qla2x00_tmf_sp_done;
1794 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1795 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1796 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1797 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1799 rval = qla2x00_start_sp(sp);
1800 if (rval != QLA_SUCCESS)
1802 wait_for_completion(&tm_iocb->u.tmf.comp);
1804 rval = tm_iocb->u.tmf.data;
1806 if (rval != QLA_SUCCESS) {
1807 ql_log(ql_log_warn, vha, 0x8030,
1808 "TM IOCB failed (%x).\n", rval);
1811 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1812 flags = tm_iocb->u.tmf.flags;
1813 lun = (uint16_t)tm_iocb->u.tmf.lun;
1815 /* Issue Marker IOCB */
1816 qla2x00_marker(vha, vha->hw->base_qpair,
1817 fcport->loop_id, lun,
1818 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1823 fcport->flags &= ~FCF_ASYNC_SENT;
1829 qla24xx_async_abort_command(srb_t *sp)
1831 unsigned long flags = 0;
1834 fc_port_t *fcport = sp->fcport;
1835 struct qla_qpair *qpair = sp->qpair;
1836 struct scsi_qla_host *vha = fcport->vha;
1837 struct req_que *req = qpair->req;
1839 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1840 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1841 if (req->outstanding_cmds[handle] == sp)
1844 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1846 if (handle == req->num_outstanding_cmds) {
1847 /* Command not found. */
1848 return QLA_FUNCTION_FAILED;
1850 if (sp->type == SRB_FXIOCB_DCMD)
1851 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1852 FXDISC_ABORT_IOCTL);
1854 return qla24xx_async_abort_cmd(sp, true);
1858 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1860 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
1863 switch (ea->data[0]) {
1864 case MBS_COMMAND_COMPLETE:
1865 ql_dbg(ql_dbg_disc, vha, 0x2118,
1866 "%s %d %8phC post gpdb\n",
1867 __func__, __LINE__, ea->fcport->port_name);
1869 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1870 ea->fcport->logout_on_delete = 1;
1871 ea->fcport->nvme_prli_service_param = ea->iop[0];
1872 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1873 ea->fcport->nvme_first_burst_size =
1874 (ea->iop[1] & 0xffff) * 512;
1876 ea->fcport->nvme_first_burst_size = 0;
1877 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1880 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1881 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1882 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1883 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1888 * Retry PRLI with other FC-4 type if failure occurred on dual
1891 if (NVME_FCP_TARGET(ea->fcport)) {
1892 ql_dbg(ql_dbg_disc, vha, 0x2118,
1893 "%s %d %8phC post %s prli\n",
1894 __func__, __LINE__, ea->fcport->port_name,
1895 (ea->fcport->fc4_type & FS_FC4TYPE_NVME) ?
1897 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME)
1898 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
1900 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
1903 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1904 ea->fcport->keep_nport_handle = 0;
1905 ea->fcport->logout_on_delete = 1;
1906 qlt_schedule_sess_for_deletion(ea->fcport);
1912 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1914 port_id_t cid; /* conflict Nport id */
1916 struct fc_port *conflict_fcport;
1917 unsigned long flags;
1918 struct fc_port *fcport = ea->fcport;
1920 ql_dbg(ql_dbg_disc, vha, 0xffff,
1921 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1922 __func__, fcport->port_name, fcport->disc_state,
1923 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1924 ea->sp->gen1, fcport->rscn_gen,
1925 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1927 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1928 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1929 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1930 "%s %d %8phC Remote is trying to login\n",
1931 __func__, __LINE__, fcport->port_name);
1935 if ((fcport->disc_state == DSC_DELETE_PEND) ||
1936 (fcport->disc_state == DSC_DELETED)) {
1937 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1941 if (ea->sp->gen2 != fcport->login_gen) {
1942 /* target side must have changed it. */
1943 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1944 "%s %8phC generation changed\n",
1945 __func__, fcport->port_name);
1946 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1948 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1949 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1950 "%s %8phC RSCN generation changed\n",
1951 __func__, fcport->port_name);
1952 qla_rscn_replay(fcport);
1953 qlt_schedule_sess_for_deletion(fcport);
1957 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
1960 switch (ea->data[0]) {
1961 case MBS_COMMAND_COMPLETE:
1963 * Driver must validate login state - If PRLI not complete,
1964 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1967 if (NVME_TARGET(vha->hw, ea->fcport)) {
1968 ql_dbg(ql_dbg_disc, vha, 0x2117,
1969 "%s %d %8phC post prli\n",
1970 __func__, __LINE__, ea->fcport->port_name);
1971 qla24xx_post_prli_work(vha, ea->fcport);
1973 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1974 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1975 __func__, __LINE__, ea->fcport->port_name,
1976 ea->fcport->loop_id, ea->fcport->d_id.b24);
1978 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1979 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1980 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1981 ea->fcport->logout_on_delete = 1;
1982 ea->fcport->send_els_logo = 0;
1983 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
1984 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1986 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1989 case MBS_COMMAND_ERROR:
1990 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
1991 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1993 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1994 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1995 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
1996 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1998 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2000 case MBS_LOOP_ID_USED:
2001 /* data[1] = IO PARAM 1 = nport ID */
2002 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2003 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2004 cid.b.al_pa = ea->iop[1] & 0xff;
2007 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2008 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2009 __func__, __LINE__, ea->fcport->port_name,
2010 ea->fcport->loop_id, cid.b24);
2012 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2013 ea->fcport->loop_id = FC_NO_LOOP_ID;
2014 qla24xx_post_gnl_work(vha, ea->fcport);
2016 case MBS_PORT_ID_USED:
2017 lid = ea->iop[1] & 0xffff;
2018 qlt_find_sess_invalidate_other(vha,
2019 wwn_to_u64(ea->fcport->port_name),
2020 ea->fcport->d_id, lid, &conflict_fcport);
2022 if (conflict_fcport) {
2024 * Another fcport share the same loop_id/nport id.
2025 * Conflict fcport needs to finish cleanup before this
2026 * fcport can proceed to login.
2028 conflict_fcport->conflict = ea->fcport;
2029 ea->fcport->login_pause = 1;
2031 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2032 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2033 __func__, __LINE__, ea->fcport->port_name,
2034 ea->fcport->d_id.b24, lid);
2036 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2037 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2038 __func__, __LINE__, ea->fcport->port_name,
2039 ea->fcport->d_id.b24, lid);
2041 qla2x00_clear_loop_id(ea->fcport);
2042 set_bit(lid, vha->hw->loop_id_map);
2043 ea->fcport->loop_id = lid;
2044 ea->fcport->keep_nport_handle = 0;
2045 qlt_schedule_sess_for_deletion(ea->fcport);
2053 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2056 qlt_logo_completion_handler(fcport, data[0]);
2057 fcport->login_gen++;
2058 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2062 /****************************************************************************/
2063 /* QLogic ISP2x00 Hardware Support Functions. */
2064 /****************************************************************************/
2067 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2069 int rval = QLA_SUCCESS;
2070 struct qla_hw_data *ha = vha->hw;
2071 uint32_t idc_major_ver, idc_minor_ver;
2074 qla83xx_idc_lock(vha, 0);
2076 /* SV: TODO: Assign initialization timeout from
2077 * flash-info / other param
2079 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2080 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2082 /* Set our fcoe function presence */
2083 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2084 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2085 "Error while setting DRV-Presence.\n");
2086 rval = QLA_FUNCTION_FAILED;
2090 /* Decide the reset ownership */
2091 qla83xx_reset_ownership(vha);
2094 * On first protocol driver load:
2095 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2097 * Others: Check compatibility with current IDC Major version.
2099 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2100 if (ha->flags.nic_core_reset_owner) {
2101 /* Set IDC Major version */
2102 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2103 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2105 /* Clearing IDC-Lock-Recovery register */
2106 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2107 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2109 * Clear further IDC participation if we are not compatible with
2110 * the current IDC Major Version.
2112 ql_log(ql_log_warn, vha, 0xb07d,
2113 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2114 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2115 __qla83xx_clear_drv_presence(vha);
2116 rval = QLA_FUNCTION_FAILED;
2119 /* Each function sets its supported Minor version. */
2120 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2121 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2122 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2124 if (ha->flags.nic_core_reset_owner) {
2125 memset(config, 0, sizeof(config));
2126 if (!qla81xx_get_port_config(vha, config))
2127 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2131 rval = qla83xx_idc_state_handler(vha);
2134 qla83xx_idc_unlock(vha, 0);
2140 * qla2x00_initialize_adapter
2144 * ha = adapter block pointer.
2150 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2153 struct qla_hw_data *ha = vha->hw;
2154 struct req_que *req = ha->req_q_map[0];
2155 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2157 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2158 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2160 /* Clear adapter flags. */
2161 vha->flags.online = 0;
2162 ha->flags.chip_reset_done = 0;
2163 vha->flags.reset_active = 0;
2164 ha->flags.pci_channel_io_perm_failure = 0;
2165 ha->flags.eeh_busy = 0;
2166 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2167 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2168 atomic_set(&vha->loop_state, LOOP_DOWN);
2169 vha->device_flags = DFLG_NO_CABLE;
2171 vha->flags.management_server_logged_in = 0;
2172 vha->marker_needed = 0;
2173 ha->isp_abort_cnt = 0;
2174 ha->beacon_blink_led = 0;
2176 set_bit(0, ha->req_qid_map);
2177 set_bit(0, ha->rsp_qid_map);
2179 ql_dbg(ql_dbg_init, vha, 0x0040,
2180 "Configuring PCI space...\n");
2181 rval = ha->isp_ops->pci_config(vha);
2183 ql_log(ql_log_warn, vha, 0x0044,
2184 "Unable to configure PCI space.\n");
2188 ha->isp_ops->reset_chip(vha);
2190 /* Check for secure flash support */
2191 if (IS_QLA28XX(ha)) {
2192 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2193 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2194 ha->flags.secure_adapter = 1;
2199 rval = qla2xxx_get_flash_info(vha);
2201 ql_log(ql_log_fatal, vha, 0x004f,
2202 "Unable to validate FLASH data.\n");
2206 if (IS_QLA8044(ha)) {
2207 qla8044_read_reset_template(vha);
2209 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2210 * If DONRESET_BIT0 is set, drivers should not set dev_state
2211 * to NEED_RESET. But if NEED_RESET is set, drivers should
2212 * should honor the reset. */
2213 if (ql2xdontresethba == 1)
2214 qla8044_set_idc_dontreset(vha);
2217 ha->isp_ops->get_flash_version(vha, req->ring);
2218 ql_dbg(ql_dbg_init, vha, 0x0061,
2219 "Configure NVRAM parameters...\n");
2221 /* Let priority default to FCP, can be overridden by nvram_config */
2222 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2224 ha->isp_ops->nvram_config(vha);
2226 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2227 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2228 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2230 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2231 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2233 if (ha->flags.disable_serdes) {
2234 /* Mask HBA via NVRAM settings? */
2235 ql_log(ql_log_info, vha, 0x0077,
2236 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2237 return QLA_FUNCTION_FAILED;
2240 ql_dbg(ql_dbg_init, vha, 0x0078,
2241 "Verifying loaded RISC code...\n");
2243 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2244 rval = ha->isp_ops->chip_diag(vha);
2247 rval = qla2x00_setup_chip(vha);
2252 if (IS_QLA84XX(ha)) {
2253 ha->cs84xx = qla84xx_get_chip(vha);
2255 ql_log(ql_log_warn, vha, 0x00d0,
2256 "Unable to configure ISP84XX.\n");
2257 return QLA_FUNCTION_FAILED;
2261 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2262 rval = qla2x00_init_rings(vha);
2264 /* No point in continuing if firmware initialization failed. */
2265 if (rval != QLA_SUCCESS)
2268 ha->flags.chip_reset_done = 1;
2270 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2271 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2272 rval = qla84xx_init_chip(vha);
2273 if (rval != QLA_SUCCESS) {
2274 ql_log(ql_log_warn, vha, 0x00d4,
2275 "Unable to initialize ISP84XX.\n");
2276 qla84xx_put_chip(vha);
2280 /* Load the NIC Core f/w if we are the first protocol driver. */
2281 if (IS_QLA8031(ha)) {
2282 rval = qla83xx_nic_core_fw_load(vha);
2284 ql_log(ql_log_warn, vha, 0x0124,
2285 "Error in initializing NIC Core f/w.\n");
2288 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2289 qla24xx_read_fcp_prio_cfg(vha);
2291 if (IS_P3P_TYPE(ha))
2292 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2294 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2300 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2303 * Returns 0 on success.
2306 qla2100_pci_config(scsi_qla_host_t *vha)
2309 unsigned long flags;
2310 struct qla_hw_data *ha = vha->hw;
2311 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2313 pci_set_master(ha->pdev);
2314 pci_try_set_mwi(ha->pdev);
2316 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2317 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2318 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2320 pci_disable_rom(ha->pdev);
2322 /* Get PCI bus information. */
2323 spin_lock_irqsave(&ha->hardware_lock, flags);
2324 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2325 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2331 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2334 * Returns 0 on success.
2337 qla2300_pci_config(scsi_qla_host_t *vha)
2340 unsigned long flags = 0;
2342 struct qla_hw_data *ha = vha->hw;
2343 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2345 pci_set_master(ha->pdev);
2346 pci_try_set_mwi(ha->pdev);
2348 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2349 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2351 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2352 w &= ~PCI_COMMAND_INTX_DISABLE;
2353 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2356 * If this is a 2300 card and not 2312, reset the
2357 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2358 * the 2310 also reports itself as a 2300 so we need to get the
2359 * fb revision level -- a 6 indicates it really is a 2300 and
2362 if (IS_QLA2300(ha)) {
2363 spin_lock_irqsave(&ha->hardware_lock, flags);
2366 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2367 for (cnt = 0; cnt < 30000; cnt++) {
2368 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2374 /* Select FPM registers. */
2375 WRT_REG_WORD(®->ctrl_status, 0x20);
2376 RD_REG_WORD(®->ctrl_status);
2378 /* Get the fb rev level */
2379 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2381 if (ha->fb_rev == FPM_2300)
2382 pci_clear_mwi(ha->pdev);
2384 /* Deselect FPM registers. */
2385 WRT_REG_WORD(®->ctrl_status, 0x0);
2386 RD_REG_WORD(®->ctrl_status);
2388 /* Release RISC module. */
2389 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2390 for (cnt = 0; cnt < 30000; cnt++) {
2391 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2397 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2400 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2402 pci_disable_rom(ha->pdev);
2404 /* Get PCI bus information. */
2405 spin_lock_irqsave(&ha->hardware_lock, flags);
2406 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2407 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2413 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2416 * Returns 0 on success.
2419 qla24xx_pci_config(scsi_qla_host_t *vha)
2422 unsigned long flags = 0;
2423 struct qla_hw_data *ha = vha->hw;
2424 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2426 pci_set_master(ha->pdev);
2427 pci_try_set_mwi(ha->pdev);
2429 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2430 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2431 w &= ~PCI_COMMAND_INTX_DISABLE;
2432 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2434 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2436 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2437 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2438 pcix_set_mmrbc(ha->pdev, 2048);
2440 /* PCIe -- adjust Maximum Read Request Size (2048). */
2441 if (pci_is_pcie(ha->pdev))
2442 pcie_set_readrq(ha->pdev, 4096);
2444 pci_disable_rom(ha->pdev);
2446 ha->chip_revision = ha->pdev->revision;
2448 /* Get PCI bus information. */
2449 spin_lock_irqsave(&ha->hardware_lock, flags);
2450 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2451 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2457 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2460 * Returns 0 on success.
2463 qla25xx_pci_config(scsi_qla_host_t *vha)
2466 struct qla_hw_data *ha = vha->hw;
2468 pci_set_master(ha->pdev);
2469 pci_try_set_mwi(ha->pdev);
2471 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2472 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2473 w &= ~PCI_COMMAND_INTX_DISABLE;
2474 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2476 /* PCIe -- adjust Maximum Read Request Size (2048). */
2477 if (pci_is_pcie(ha->pdev))
2478 pcie_set_readrq(ha->pdev, 4096);
2480 pci_disable_rom(ha->pdev);
2482 ha->chip_revision = ha->pdev->revision;
2488 * qla2x00_isp_firmware() - Choose firmware image.
2491 * Returns 0 on success.
2494 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2497 uint16_t loop_id, topo, sw_cap;
2498 uint8_t domain, area, al_pa;
2499 struct qla_hw_data *ha = vha->hw;
2501 /* Assume loading risc code */
2502 rval = QLA_FUNCTION_FAILED;
2504 if (ha->flags.disable_risc_code_load) {
2505 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2507 /* Verify checksum of loaded RISC code. */
2508 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2509 if (rval == QLA_SUCCESS) {
2510 /* And, verify we are not in ROM code. */
2511 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2512 &area, &domain, &topo, &sw_cap);
2517 ql_dbg(ql_dbg_init, vha, 0x007a,
2518 "**** Load RISC code ****.\n");
2524 * qla2x00_reset_chip() - Reset ISP chip.
2527 * Returns 0 on success.
2530 qla2x00_reset_chip(scsi_qla_host_t *vha)
2532 unsigned long flags = 0;
2533 struct qla_hw_data *ha = vha->hw;
2534 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2537 int rval = QLA_FUNCTION_FAILED;
2539 if (unlikely(pci_channel_offline(ha->pdev)))
2542 ha->isp_ops->disable_intrs(ha);
2544 spin_lock_irqsave(&ha->hardware_lock, flags);
2546 /* Turn off master enable */
2548 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2549 cmd &= ~PCI_COMMAND_MASTER;
2550 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2552 if (!IS_QLA2100(ha)) {
2554 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2555 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2556 for (cnt = 0; cnt < 30000; cnt++) {
2557 if ((RD_REG_WORD(®->hccr) &
2558 HCCR_RISC_PAUSE) != 0)
2563 RD_REG_WORD(®->hccr); /* PCI Posting. */
2567 /* Select FPM registers. */
2568 WRT_REG_WORD(®->ctrl_status, 0x20);
2569 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2571 /* FPM Soft Reset. */
2572 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2573 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2575 /* Toggle Fpm Reset. */
2576 if (!IS_QLA2200(ha)) {
2577 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2578 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2581 /* Select frame buffer registers. */
2582 WRT_REG_WORD(®->ctrl_status, 0x10);
2583 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2585 /* Reset frame buffer FIFOs. */
2586 if (IS_QLA2200(ha)) {
2587 WRT_FB_CMD_REG(ha, reg, 0xa000);
2588 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2590 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2592 /* Read back fb_cmd until zero or 3 seconds max */
2593 for (cnt = 0; cnt < 3000; cnt++) {
2594 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2600 /* Select RISC module registers. */
2601 WRT_REG_WORD(®->ctrl_status, 0);
2602 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2604 /* Reset RISC processor. */
2605 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2606 RD_REG_WORD(®->hccr); /* PCI Posting. */
2608 /* Release RISC processor. */
2609 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2610 RD_REG_WORD(®->hccr); /* PCI Posting. */
2613 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2614 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2616 /* Reset ISP chip. */
2617 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2619 /* Wait for RISC to recover from reset. */
2620 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2622 * It is necessary to for a delay here since the card doesn't
2623 * respond to PCI reads during a reset. On some architectures
2624 * this will result in an MCA.
2627 for (cnt = 30000; cnt; cnt--) {
2628 if ((RD_REG_WORD(®->ctrl_status) &
2629 CSR_ISP_SOFT_RESET) == 0)
2636 /* Reset RISC processor. */
2637 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2639 WRT_REG_WORD(®->semaphore, 0);
2641 /* Release RISC processor. */
2642 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2643 RD_REG_WORD(®->hccr); /* PCI Posting. */
2645 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2646 for (cnt = 0; cnt < 30000; cnt++) {
2647 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2655 /* Turn on master enable */
2656 cmd |= PCI_COMMAND_MASTER;
2657 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2659 /* Disable RISC pause on FPM parity error. */
2660 if (!IS_QLA2100(ha)) {
2661 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2662 RD_REG_WORD(®->hccr); /* PCI Posting. */
2665 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2671 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2674 * Returns 0 on success.
2677 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2679 uint16_t mb[4] = {0x1010, 0, 1, 0};
2681 if (!IS_QLA81XX(vha->hw))
2684 return qla81xx_write_mpi_register(vha, mb);
2688 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2691 * Returns 0 on success.
2694 qla24xx_reset_risc(scsi_qla_host_t *vha)
2696 unsigned long flags = 0;
2697 struct qla_hw_data *ha = vha->hw;
2698 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2701 static int abts_cnt; /* ISP abort retry counts */
2702 int rval = QLA_SUCCESS;
2704 spin_lock_irqsave(&ha->hardware_lock, flags);
2707 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2708 for (cnt = 0; cnt < 30000; cnt++) {
2709 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2715 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2716 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2718 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2719 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2720 RD_REG_DWORD(®->hccr),
2721 RD_REG_DWORD(®->ctrl_status),
2722 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2724 WRT_REG_DWORD(®->ctrl_status,
2725 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2726 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2730 /* Wait for firmware to complete NVRAM accesses. */
2731 RD_REG_WORD(®->mailbox0);
2732 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2733 rval == QLA_SUCCESS; cnt--) {
2738 rval = QLA_FUNCTION_TIMEOUT;
2741 if (rval == QLA_SUCCESS)
2742 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2744 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2745 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2746 RD_REG_DWORD(®->hccr),
2747 RD_REG_DWORD(®->mailbox0));
2749 /* Wait for soft-reset to complete. */
2750 RD_REG_DWORD(®->ctrl_status);
2751 for (cnt = 0; cnt < 60; cnt++) {
2753 if ((RD_REG_DWORD(®->ctrl_status) &
2754 CSRX_ISP_SOFT_RESET) == 0)
2759 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2760 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2762 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2763 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2764 RD_REG_DWORD(®->hccr),
2765 RD_REG_DWORD(®->ctrl_status));
2767 /* If required, do an MPI FW reset now */
2768 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2769 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2770 if (++abts_cnt < 5) {
2771 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2772 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2775 * We exhausted the ISP abort retries. We have to
2776 * set the board offline.
2779 vha->flags.online = 0;
2784 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2785 RD_REG_DWORD(®->hccr);
2787 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2788 RD_REG_DWORD(®->hccr);
2790 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2791 RD_REG_DWORD(®->hccr);
2793 RD_REG_WORD(®->mailbox0);
2794 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2795 rval == QLA_SUCCESS; cnt--) {
2800 rval = QLA_FUNCTION_TIMEOUT;
2802 if (rval == QLA_SUCCESS)
2803 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2805 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2806 "Host Risc 0x%x, mailbox0 0x%x\n",
2807 RD_REG_DWORD(®->hccr),
2808 RD_REG_WORD(®->mailbox0));
2810 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2812 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2813 "Driver in %s mode\n",
2814 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2816 if (IS_NOPOLLING_TYPE(ha))
2817 ha->isp_ops->enable_intrs(ha);
2823 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2825 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2827 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2828 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2833 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2835 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2837 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2838 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2842 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2845 uint delta_msec = 100;
2846 uint elapsed_msec = 0;
2850 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2851 vha->hw->pdev->subsystem_device != 0x0240)
2854 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2858 timeout_msec = TIMEOUT_SEMAPHORE;
2859 n = timeout_msec / delta_msec;
2861 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2862 qla25xx_read_risc_sema_reg(vha, &wd32);
2863 if (wd32 & RISC_SEMAPHORE)
2866 elapsed_msec += delta_msec;
2867 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2871 if (!(wd32 & RISC_SEMAPHORE))
2874 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2877 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2878 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2879 n = timeout_msec / delta_msec;
2881 qla25xx_read_risc_sema_reg(vha, &wd32);
2882 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2885 elapsed_msec += delta_msec;
2886 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2890 if (wd32 & RISC_SEMAPHORE_FORCE)
2891 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2896 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2903 * qla24xx_reset_chip() - Reset ISP24xx chip.
2906 * Returns 0 on success.
2909 qla24xx_reset_chip(scsi_qla_host_t *vha)
2911 struct qla_hw_data *ha = vha->hw;
2912 int rval = QLA_FUNCTION_FAILED;
2914 if (pci_channel_offline(ha->pdev) &&
2915 ha->flags.pci_channel_io_perm_failure) {
2919 ha->isp_ops->disable_intrs(ha);
2921 qla25xx_manipulate_risc_semaphore(vha);
2923 /* Perform RISC reset. */
2924 rval = qla24xx_reset_risc(vha);
2930 * qla2x00_chip_diag() - Test chip for proper operation.
2933 * Returns 0 on success.
2936 qla2x00_chip_diag(scsi_qla_host_t *vha)
2939 struct qla_hw_data *ha = vha->hw;
2940 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2941 unsigned long flags = 0;
2945 struct req_que *req = ha->req_q_map[0];
2947 /* Assume a failed state */
2948 rval = QLA_FUNCTION_FAILED;
2950 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2951 ®->flash_address);
2953 spin_lock_irqsave(&ha->hardware_lock, flags);
2955 /* Reset ISP chip. */
2956 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2959 * We need to have a delay here since the card will not respond while
2960 * in reset causing an MCA on some architectures.
2963 data = qla2x00_debounce_register(®->ctrl_status);
2964 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2966 data = RD_REG_WORD(®->ctrl_status);
2971 goto chip_diag_failed;
2973 ql_dbg(ql_dbg_init, vha, 0x007c,
2974 "Reset register cleared by chip reset.\n");
2976 /* Reset RISC processor. */
2977 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2978 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2980 /* Workaround for QLA2312 PCI parity error */
2981 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2982 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2983 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2985 data = RD_MAILBOX_REG(ha, reg, 0);
2992 goto chip_diag_failed;
2994 /* Check product ID of chip */
2995 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
2997 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2998 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2999 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3000 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3001 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3002 mb[3] != PROD_ID_3) {
3003 ql_log(ql_log_warn, vha, 0x0062,
3004 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3005 mb[1], mb[2], mb[3]);
3007 goto chip_diag_failed;
3009 ha->product_id[0] = mb[1];
3010 ha->product_id[1] = mb[2];
3011 ha->product_id[2] = mb[3];
3012 ha->product_id[3] = mb[4];
3014 /* Adjust fw RISC transfer size */
3015 if (req->length > 1024)
3016 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3018 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3021 if (IS_QLA2200(ha) &&
3022 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3023 /* Limit firmware transfer size with a 2200A */
3024 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3026 ha->device_type |= DT_ISP2200A;
3027 ha->fw_transfer_size = 128;
3030 /* Wrap Incoming Mailboxes Test. */
3031 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3033 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3034 rval = qla2x00_mbx_reg_test(vha);
3036 ql_log(ql_log_warn, vha, 0x0080,
3037 "Failed mailbox send register test.\n");
3039 /* Flag a successful rval */
3041 spin_lock_irqsave(&ha->hardware_lock, flags);
3045 ql_log(ql_log_info, vha, 0x0081,
3046 "Chip diagnostics **** FAILED ****.\n");
3048 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3054 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3057 * Returns 0 on success.
3060 qla24xx_chip_diag(scsi_qla_host_t *vha)
3063 struct qla_hw_data *ha = vha->hw;
3064 struct req_que *req = ha->req_q_map[0];
3066 if (IS_P3P_TYPE(ha))
3069 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3071 rval = qla2x00_mbx_reg_test(vha);
3073 ql_log(ql_log_warn, vha, 0x0082,
3074 "Failed mailbox send register test.\n");
3076 /* Flag a successful rval */
3084 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3089 struct qla_hw_data *ha = vha->hw;
3091 if (!IS_FWI2_CAPABLE(ha))
3094 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3095 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3099 ql_dbg(ql_dbg_init, vha, 0x00bd,
3100 "%s: FCE Mem is already allocated.\n",
3105 /* Allocate memory for Fibre Channel Event Buffer. */
3106 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3109 ql_log(ql_log_warn, vha, 0x00be,
3110 "Unable to allocate (%d KB) for FCE.\n",
3115 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3116 ha->fce_mb, &ha->fce_bufs);
3118 ql_log(ql_log_warn, vha, 0x00bf,
3119 "Unable to initialize FCE (%d).\n", rval);
3120 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3124 ql_dbg(ql_dbg_init, vha, 0x00c0,
3125 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3127 ha->flags.fce_enabled = 1;
3128 ha->fce_dma = tc_dma;
3133 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3138 struct qla_hw_data *ha = vha->hw;
3140 if (!IS_FWI2_CAPABLE(ha))
3144 ql_dbg(ql_dbg_init, vha, 0x00bd,
3145 "%s: EFT Mem is already allocated.\n",
3150 /* Allocate memory for Extended Trace Buffer. */
3151 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3154 ql_log(ql_log_warn, vha, 0x00c1,
3155 "Unable to allocate (%d KB) for EFT.\n",
3160 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3162 ql_log(ql_log_warn, vha, 0x00c2,
3163 "Unable to initialize EFT (%d).\n", rval);
3164 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3168 ql_dbg(ql_dbg_init, vha, 0x00c3,
3169 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3171 ha->eft_dma = tc_dma;
3176 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3178 qla2x00_init_fce_trace(vha);
3179 qla2x00_init_eft_trace(vha);
3183 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3185 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3186 eft_size, fce_size, mq_size;
3187 struct qla_hw_data *ha = vha->hw;
3188 struct req_que *req = ha->req_q_map[0];
3189 struct rsp_que *rsp = ha->rsp_q_map[0];
3190 struct qla2xxx_fw_dump *fw_dump;
3192 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3193 req_q_size = rsp_q_size = 0;
3195 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3196 fixed_size = sizeof(struct qla2100_fw_dump);
3197 } else if (IS_QLA23XX(ha)) {
3198 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3199 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3201 } else if (IS_FWI2_CAPABLE(ha)) {
3202 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3203 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3204 else if (IS_QLA81XX(ha))
3205 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3206 else if (IS_QLA25XX(ha))
3207 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3209 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3211 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3214 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3216 mq_size = sizeof(struct qla2xxx_mq_chain);
3218 * Allocate maximum buffer size for all queues - Q0.
3219 * Resizing must be done at end-of-dump processing.
3221 mq_size += (ha->max_req_queues - 1) *
3222 (req->length * sizeof(request_t));
3223 mq_size += (ha->max_rsp_queues - 1) *
3224 (rsp->length * sizeof(response_t));
3226 if (ha->tgt.atio_ring)
3227 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3229 qla2x00_init_fce_trace(vha);
3231 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3232 qla2x00_init_eft_trace(vha);
3234 eft_size = EFT_SIZE;
3237 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3238 struct fwdt *fwdt = ha->fwdt;
3241 for (j = 0; j < 2; j++, fwdt++) {
3242 if (!fwdt->template) {
3243 ql_dbg(ql_dbg_init, vha, 0x00ba,
3244 "-> fwdt%u no template\n", j);
3247 ql_dbg(ql_dbg_init, vha, 0x00fa,
3248 "-> fwdt%u calculating fwdump size...\n", j);
3249 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3250 vha, fwdt->template);
3251 ql_dbg(ql_dbg_init, vha, 0x00fa,
3252 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3253 j, fwdt->dump_size);
3254 dump_size += fwdt->dump_size;
3257 req_q_size = req->length * sizeof(request_t);
3258 rsp_q_size = rsp->length * sizeof(response_t);
3259 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3260 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3262 ha->chain_offset = dump_size;
3263 dump_size += mq_size + fce_size;
3264 if (ha->exchoffld_buf)
3265 dump_size += sizeof(struct qla2xxx_offld_chain) +
3267 if (ha->exlogin_buf)
3268 dump_size += sizeof(struct qla2xxx_offld_chain) +
3272 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3274 ql_dbg(ql_dbg_init, vha, 0x00c5,
3275 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3276 __func__, dump_size, ha->fw_dump_len,
3277 ha->fw_dump_alloc_len);
3279 fw_dump = vmalloc(dump_size);
3281 ql_log(ql_log_warn, vha, 0x00c4,
3282 "Unable to allocate (%d KB) for firmware dump.\n",
3285 mutex_lock(&ha->optrom_mutex);
3286 if (ha->fw_dumped) {
3287 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3289 ha->fw_dump = fw_dump;
3290 ha->fw_dump_alloc_len = dump_size;
3291 ql_dbg(ql_dbg_init, vha, 0x00c5,
3292 "Re-Allocated (%d KB) and save firmware dump.\n",
3297 ha->fw_dump = fw_dump;
3299 ha->fw_dump_len = ha->fw_dump_alloc_len =
3301 ql_dbg(ql_dbg_init, vha, 0x00c5,
3302 "Allocated (%d KB) for firmware dump.\n",
3305 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3306 mutex_unlock(&ha->optrom_mutex);
3310 ha->fw_dump->signature[0] = 'Q';
3311 ha->fw_dump->signature[1] = 'L';
3312 ha->fw_dump->signature[2] = 'G';
3313 ha->fw_dump->signature[3] = 'C';
3314 ha->fw_dump->version = htonl(1);
3316 ha->fw_dump->fixed_size = htonl(fixed_size);
3317 ha->fw_dump->mem_size = htonl(mem_size);
3318 ha->fw_dump->req_q_size = htonl(req_q_size);
3319 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3321 ha->fw_dump->eft_size = htonl(eft_size);
3322 ha->fw_dump->eft_addr_l =
3323 htonl(LSD(ha->eft_dma));
3324 ha->fw_dump->eft_addr_h =
3325 htonl(MSD(ha->eft_dma));
3327 ha->fw_dump->header_size =
3329 (struct qla2xxx_fw_dump, isp));
3331 mutex_unlock(&ha->optrom_mutex);
3337 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3339 #define MPS_MASK 0xe0
3344 if (!IS_QLA81XX(vha->hw))
3347 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3348 if (rval != QLA_SUCCESS) {
3349 ql_log(ql_log_warn, vha, 0x0105,
3350 "Unable to acquire semaphore.\n");
3354 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3355 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3356 if (rval != QLA_SUCCESS) {
3357 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3362 if (dc == (dw & MPS_MASK))
3367 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3368 if (rval != QLA_SUCCESS) {
3369 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3373 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3374 if (rval != QLA_SUCCESS) {
3375 ql_log(ql_log_warn, vha, 0x006d,
3376 "Unable to release semaphore.\n");
3384 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3386 /* Don't try to reallocate the array */
3387 if (req->outstanding_cmds)
3390 if (!IS_FWI2_CAPABLE(ha))
3391 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3393 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3394 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3396 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3399 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3403 if (!req->outstanding_cmds) {
3405 * Try to allocate a minimal size just so we can get through
3408 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3409 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3413 if (!req->outstanding_cmds) {
3414 ql_log(ql_log_fatal, NULL, 0x0126,
3415 "Failed to allocate memory for "
3416 "outstanding_cmds for req_que %p.\n", req);
3417 req->num_outstanding_cmds = 0;
3418 return QLA_FUNCTION_FAILED;
3425 #define PRINT_FIELD(_field, _flag, _str) { \
3426 if (a0->_field & _flag) {\
3432 len = snprintf(ptr, leftover, "%s", _str); \
3439 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3442 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3443 u8 str[STR_LEN], *ptr, p;
3446 memset(str, 0, STR_LEN);
3447 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3448 ql_dbg(ql_dbg_init, vha, 0x015a,
3449 "SFP MFG Name: %s\n", str);
3451 memset(str, 0, STR_LEN);
3452 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3453 ql_dbg(ql_dbg_init, vha, 0x015c,
3454 "SFP Part Name: %s\n", str);
3457 memset(str, 0, STR_LEN);
3461 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3462 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3463 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3464 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3465 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3466 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3467 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3468 ql_dbg(ql_dbg_init, vha, 0x0160,
3469 "SFP Media: %s\n", str);
3472 memset(str, 0, STR_LEN);
3476 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3477 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3478 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3479 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3480 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3481 ql_dbg(ql_dbg_init, vha, 0x0196,
3482 "SFP Link Length: %s\n", str);
3484 memset(str, 0, STR_LEN);
3488 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3489 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3490 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3491 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3492 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3493 ql_dbg(ql_dbg_init, vha, 0x016e,
3494 "SFP FC Link Tech: %s\n", str);
3497 ql_dbg(ql_dbg_init, vha, 0x016f,
3498 "SFP Distant: %d km\n", a0->length_km);
3499 if (a0->length_100m)
3500 ql_dbg(ql_dbg_init, vha, 0x0170,
3501 "SFP Distant: %d m\n", a0->length_100m*100);
3502 if (a0->length_50um_10m)
3503 ql_dbg(ql_dbg_init, vha, 0x0189,
3504 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3505 if (a0->length_62um_10m)
3506 ql_dbg(ql_dbg_init, vha, 0x018a,
3507 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3508 if (a0->length_om4_10m)
3509 ql_dbg(ql_dbg_init, vha, 0x0194,
3510 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3511 if (a0->length_om3_10m)
3512 ql_dbg(ql_dbg_init, vha, 0x0195,
3513 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3519 * QLA_SUCCESS: no action
3520 * QLA_INTERFACE_ERROR: SFP is not there.
3521 * QLA_FUNCTION_FAILED: detected New SFP
3524 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3526 int rc = QLA_SUCCESS;
3527 struct sff_8247_a0 *a;
3528 struct qla_hw_data *ha = vha->hw;
3530 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3533 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3537 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3538 qla2xxx_print_sfp_info(vha);
3540 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3542 ha->flags.detected_lr_sfp = 1;
3544 if (a->length_km > 5 || a->length_100m > 50)
3545 ha->long_range_distance = LR_DISTANCE_10K;
3547 ha->long_range_distance = LR_DISTANCE_5K;
3549 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3550 ql_dbg(ql_dbg_async, vha, 0x507b,
3551 "Detected Long Range SFP.\n");
3554 ha->flags.detected_lr_sfp = 0;
3555 if (ha->flags.using_lr_setting)
3556 ql_dbg(ql_dbg_async, vha, 0x5084,
3557 "Detected Short Range SFP.\n");
3560 if (!vha->flags.init_done)
3567 * qla2x00_setup_chip() - Load and start RISC firmware.
3570 * Returns 0 on success.
3573 qla2x00_setup_chip(scsi_qla_host_t *vha)
3576 uint32_t srisc_address = 0;
3577 struct qla_hw_data *ha = vha->hw;
3578 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3579 unsigned long flags;
3580 uint16_t fw_major_version;
3582 if (IS_P3P_TYPE(ha)) {
3583 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3584 if (rval == QLA_SUCCESS) {
3585 qla2x00_stop_firmware(vha);
3586 goto enable_82xx_npiv;
3591 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3592 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3593 spin_lock_irqsave(&ha->hardware_lock, flags);
3594 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3595 RD_REG_WORD(®->hccr);
3596 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3599 qla81xx_mpi_sync(vha);
3601 /* Load firmware sequences */
3602 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3603 if (rval == QLA_SUCCESS) {
3604 ql_dbg(ql_dbg_init, vha, 0x00c9,
3605 "Verifying Checksum of loaded RISC code.\n");
3607 rval = qla2x00_verify_checksum(vha, srisc_address);
3608 if (rval == QLA_SUCCESS) {
3609 /* Start firmware execution. */
3610 ql_dbg(ql_dbg_init, vha, 0x00ca,
3611 "Starting firmware.\n");
3614 ha->flags.exlogins_enabled = 1;
3616 if (qla_is_exch_offld_enabled(vha))
3617 ha->flags.exchoffld_enabled = 1;
3619 rval = qla2x00_execute_fw(vha, srisc_address);
3620 /* Retrieve firmware information. */
3621 if (rval == QLA_SUCCESS) {
3622 qla24xx_detect_sfp(vha);
3624 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3626 (ha->zio_mode == QLA_ZIO_MODE_6))
3627 qla27xx_set_zio_threshold(vha,
3628 ha->last_zio_threshold);
3630 rval = qla2x00_set_exlogins_buffer(vha);
3631 if (rval != QLA_SUCCESS)
3634 rval = qla2x00_set_exchoffld_buffer(vha);
3635 if (rval != QLA_SUCCESS)
3639 fw_major_version = ha->fw_major_version;
3640 if (IS_P3P_TYPE(ha))
3641 qla82xx_check_md_needed(vha);
3643 rval = qla2x00_get_fw_version(vha);
3644 if (rval != QLA_SUCCESS)
3646 ha->flags.npiv_supported = 0;
3647 if (IS_QLA2XXX_MIDTYPE(ha) &&
3648 (ha->fw_attributes & BIT_2)) {
3649 ha->flags.npiv_supported = 1;
3650 if ((!ha->max_npiv_vports) ||
3651 ((ha->max_npiv_vports + 1) %
3652 MIN_MULTI_ID_FABRIC))
3653 ha->max_npiv_vports =
3654 MIN_MULTI_ID_FABRIC - 1;
3656 qla2x00_get_resource_cnts(vha);
3659 * Allocate the array of outstanding commands
3660 * now that we know the firmware resources.
3662 rval = qla2x00_alloc_outstanding_cmds(ha,
3664 if (rval != QLA_SUCCESS)
3667 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3668 qla2x00_alloc_offload_mem(vha);
3670 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3671 qla2x00_alloc_fw_dump(vha);
3677 ql_log(ql_log_fatal, vha, 0x00cd,
3678 "ISP Firmware failed checksum.\n");
3684 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3685 /* Enable proper parity. */
3686 spin_lock_irqsave(&ha->hardware_lock, flags);
3689 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3691 /* SRAM, Instruction RAM and GP RAM parity */
3692 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3693 RD_REG_WORD(®->hccr);
3694 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3697 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3698 ha->flags.fac_supported = 1;
3699 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3702 rval = qla81xx_fac_get_sector_size(vha, &size);
3703 if (rval == QLA_SUCCESS) {
3704 ha->flags.fac_supported = 1;
3705 ha->fdt_block_size = size << 2;
3707 ql_log(ql_log_warn, vha, 0x00ce,
3708 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3709 ha->fw_major_version, ha->fw_minor_version,
3710 ha->fw_subminor_version);
3712 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3714 ha->flags.fac_supported = 0;
3721 ql_log(ql_log_fatal, vha, 0x00cf,
3722 "Setup chip ****FAILED****.\n");
3729 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3730 * @rsp: response queue
3732 * Beginning of request ring has initialization control block already built
3733 * by nvram config routine.
3735 * Returns 0 on success.
3738 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3743 rsp->ring_ptr = rsp->ring;
3744 rsp->ring_index = 0;
3745 rsp->status_srb = NULL;
3746 pkt = rsp->ring_ptr;
3747 for (cnt = 0; cnt < rsp->length; cnt++) {
3748 pkt->signature = RESPONSE_PROCESSED;
3754 * qla2x00_update_fw_options() - Read and process firmware options.
3757 * Returns 0 on success.
3760 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3762 uint16_t swing, emphasis, tx_sens, rx_sens;
3763 struct qla_hw_data *ha = vha->hw;
3765 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3766 qla2x00_get_fw_options(vha, ha->fw_options);
3768 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3771 /* Serial Link options. */
3772 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3773 "Serial link options.\n");
3774 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3775 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3777 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3778 if (ha->fw_seriallink_options[3] & BIT_2) {
3779 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3782 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3783 emphasis = (ha->fw_seriallink_options[2] &
3784 (BIT_4 | BIT_3)) >> 3;
3785 tx_sens = ha->fw_seriallink_options[0] &
3786 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3787 rx_sens = (ha->fw_seriallink_options[0] &
3788 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3789 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3790 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3793 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3794 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3795 ha->fw_options[10] |= BIT_5 |
3796 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3797 (tx_sens & (BIT_1 | BIT_0));
3800 swing = (ha->fw_seriallink_options[2] &
3801 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3802 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3803 tx_sens = ha->fw_seriallink_options[1] &
3804 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3805 rx_sens = (ha->fw_seriallink_options[1] &
3806 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3807 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3808 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3811 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3812 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3813 ha->fw_options[11] |= BIT_5 |
3814 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3815 (tx_sens & (BIT_1 | BIT_0));
3819 /* Return command IOCBs without waiting for an ABTS to complete. */
3820 ha->fw_options[3] |= BIT_13;
3823 if (ha->flags.enable_led_scheme)
3824 ha->fw_options[2] |= BIT_12;
3826 /* Detect ISP6312. */
3828 ha->fw_options[2] |= BIT_13;
3830 /* Set Retry FLOGI in case of P2P connection */
3831 if (ha->operating_mode == P2P) {
3832 ha->fw_options[2] |= BIT_3;
3833 ql_dbg(ql_dbg_disc, vha, 0x2100,
3834 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3835 __func__, ha->fw_options[2]);
3838 /* Update firmware options. */
3839 qla2x00_set_fw_options(vha, ha->fw_options);
3843 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3846 struct qla_hw_data *ha = vha->hw;
3848 if (IS_P3P_TYPE(ha))
3851 /* Hold status IOCBs until ABTS response received. */
3853 ha->fw_options[3] |= BIT_12;
3855 /* Set Retry FLOGI in case of P2P connection */
3856 if (ha->operating_mode == P2P) {
3857 ha->fw_options[2] |= BIT_3;
3858 ql_dbg(ql_dbg_disc, vha, 0x2101,
3859 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3860 __func__, ha->fw_options[2]);
3863 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3864 if (ql2xmvasynctoatio &&
3865 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3866 if (qla_tgt_mode_enabled(vha) ||
3867 qla_dual_mode_enabled(vha))
3868 ha->fw_options[2] |= BIT_11;
3870 ha->fw_options[2] &= ~BIT_11;
3873 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3876 * Tell FW to track each exchange to prevent
3877 * driver from using stale exchange.
3879 if (qla_tgt_mode_enabled(vha) ||
3880 qla_dual_mode_enabled(vha))
3881 ha->fw_options[2] |= BIT_4;
3883 ha->fw_options[2] &= ~BIT_4;
3885 /* Reserve 1/2 of emergency exchanges for ELS.*/
3886 if (qla2xuseresexchforels)
3887 ha->fw_options[2] |= BIT_8;
3889 ha->fw_options[2] &= ~BIT_8;
3892 ql_dbg(ql_dbg_init, vha, 0x00e8,
3893 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3894 __func__, ha->fw_options[1], ha->fw_options[2],
3895 ha->fw_options[3], vha->host->active_mode);
3897 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3898 qla2x00_set_fw_options(vha, ha->fw_options);
3900 /* Update Serial Link options. */
3901 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3904 rval = qla2x00_set_serdes_params(vha,
3905 le16_to_cpu(ha->fw_seriallink_options24[1]),
3906 le16_to_cpu(ha->fw_seriallink_options24[2]),
3907 le16_to_cpu(ha->fw_seriallink_options24[3]));
3908 if (rval != QLA_SUCCESS) {
3909 ql_log(ql_log_warn, vha, 0x0104,
3910 "Unable to update Serial Link options (%x).\n", rval);
3915 qla2x00_config_rings(struct scsi_qla_host *vha)
3917 struct qla_hw_data *ha = vha->hw;
3918 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3919 struct req_que *req = ha->req_q_map[0];
3920 struct rsp_que *rsp = ha->rsp_q_map[0];
3922 /* Setup ring parameters in initialization control block. */
3923 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3924 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3925 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3926 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3927 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3928 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3930 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3931 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3932 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3933 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3934 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3938 qla24xx_config_rings(struct scsi_qla_host *vha)
3940 struct qla_hw_data *ha = vha->hw;
3941 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3942 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3943 struct qla_msix_entry *msix;
3944 struct init_cb_24xx *icb;
3946 struct req_que *req = ha->req_q_map[0];
3947 struct rsp_que *rsp = ha->rsp_q_map[0];
3949 /* Setup ring parameters in initialization control block. */
3950 icb = (struct init_cb_24xx *)ha->init_cb;
3951 icb->request_q_outpointer = cpu_to_le16(0);
3952 icb->response_q_inpointer = cpu_to_le16(0);
3953 icb->request_q_length = cpu_to_le16(req->length);
3954 icb->response_q_length = cpu_to_le16(rsp->length);
3955 put_unaligned_le64(req->dma, &icb->request_q_address);
3956 put_unaligned_le64(rsp->dma, &icb->response_q_address);
3958 /* Setup ATIO queue dma pointers for target mode */
3959 icb->atio_q_inpointer = cpu_to_le16(0);
3960 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3961 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
3963 if (IS_SHADOW_REG_CAPABLE(ha))
3964 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3966 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3968 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3969 icb->rid = cpu_to_le16(rid);
3970 if (ha->flags.msix_enabled) {
3971 msix = &ha->msix_entries[1];
3972 ql_dbg(ql_dbg_init, vha, 0x0019,
3973 "Registering vector 0x%x for base que.\n",
3975 icb->msix = cpu_to_le16(msix->entry);
3977 /* Use alternate PCI bus number */
3979 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
3980 /* Use alternate PCI devfn */
3982 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
3984 /* Use Disable MSIX Handshake mode for capable adapters */
3985 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3986 (ha->flags.msix_enabled)) {
3987 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
3988 ha->flags.disable_msix_handshake = 1;
3989 ql_dbg(ql_dbg_init, vha, 0x00fe,
3990 "MSIX Handshake Disable Mode turned on.\n");
3992 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
3994 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
3996 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
3997 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
3998 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
3999 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4001 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4002 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4003 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4004 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4007 qlt_24xx_config_rings(vha);
4009 /* If the user has configured the speed, set it here */
4010 if (ha->set_data_rate) {
4011 ql_dbg(ql_dbg_init, vha, 0x00fd,
4012 "Speed set by user : %s Gbps \n",
4013 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4014 icb->firmware_options_3 = (ha->set_data_rate << 13);
4018 RD_REG_DWORD(&ioreg->hccr);
4022 * qla2x00_init_rings() - Initializes firmware.
4025 * Beginning of request ring has initialization control block already built
4026 * by nvram config routine.
4028 * Returns 0 on success.
4031 qla2x00_init_rings(scsi_qla_host_t *vha)
4034 unsigned long flags = 0;
4036 struct qla_hw_data *ha = vha->hw;
4037 struct req_que *req;
4038 struct rsp_que *rsp;
4039 struct mid_init_cb_24xx *mid_init_cb =
4040 (struct mid_init_cb_24xx *) ha->init_cb;
4042 spin_lock_irqsave(&ha->hardware_lock, flags);
4044 /* Clear outstanding commands array. */
4045 for (que = 0; que < ha->max_req_queues; que++) {
4046 req = ha->req_q_map[que];
4047 if (!req || !test_bit(que, ha->req_qid_map))
4049 req->out_ptr = (void *)(req->ring + req->length);
4051 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4052 req->outstanding_cmds[cnt] = NULL;
4054 req->current_outstanding_cmd = 1;
4056 /* Initialize firmware. */
4057 req->ring_ptr = req->ring;
4058 req->ring_index = 0;
4059 req->cnt = req->length;
4062 for (que = 0; que < ha->max_rsp_queues; que++) {
4063 rsp = ha->rsp_q_map[que];
4064 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4066 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4068 /* Initialize response queue entries */
4070 qlafx00_init_response_q_entries(rsp);
4072 qla2x00_init_response_q_entries(rsp);
4075 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4076 ha->tgt.atio_ring_index = 0;
4077 /* Initialize ATIO queue entries */
4078 qlt_init_atio_q_entries(vha);
4080 ha->isp_ops->config_rings(vha);
4082 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4084 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4086 if (IS_QLAFX00(ha)) {
4087 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4091 /* Update any ISP specific firmware options before initialization. */
4092 ha->isp_ops->update_fw_options(vha);
4094 if (ha->flags.npiv_supported) {
4095 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4096 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4097 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4100 if (IS_FWI2_CAPABLE(ha)) {
4101 mid_init_cb->options = cpu_to_le16(BIT_1);
4102 mid_init_cb->init_cb.execution_throttle =
4103 cpu_to_le16(ha->cur_fw_xcb_count);
4104 ha->flags.dport_enabled =
4105 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4106 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4107 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4108 /* FA-WWPN Status */
4109 ha->flags.fawwpn_enabled =
4110 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4111 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4112 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4115 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4118 ql_log(ql_log_fatal, vha, 0x00d2,
4119 "Init Firmware **** FAILED ****.\n");
4121 ql_dbg(ql_dbg_init, vha, 0x00d3,
4122 "Init Firmware -- success.\n");
4124 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4131 * qla2x00_fw_ready() - Waits for firmware ready.
4134 * Returns 0 on success.
4137 qla2x00_fw_ready(scsi_qla_host_t *vha)
4140 unsigned long wtime, mtime, cs84xx_time;
4141 uint16_t min_wait; /* Minimum wait time if loop is down */
4142 uint16_t wait_time; /* Wait time if loop is coming ready */
4144 struct qla_hw_data *ha = vha->hw;
4146 if (IS_QLAFX00(vha->hw))
4147 return qlafx00_fw_ready(vha);
4151 /* Time to wait for loop down */
4152 if (IS_P3P_TYPE(ha))
4158 * Firmware should take at most one RATOV to login, plus 5 seconds for
4159 * our own processing.
4161 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4162 wait_time = min_wait;
4165 /* Min wait time if loop down */
4166 mtime = jiffies + (min_wait * HZ);
4168 /* wait time before firmware ready */
4169 wtime = jiffies + (wait_time * HZ);
4171 /* Wait for ISP to finish LIP */
4172 if (!vha->flags.init_done)
4173 ql_log(ql_log_info, vha, 0x801e,
4174 "Waiting for LIP to complete.\n");
4177 memset(state, -1, sizeof(state));
4178 rval = qla2x00_get_firmware_state(vha, state);
4179 if (rval == QLA_SUCCESS) {
4180 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4181 vha->device_flags &= ~DFLG_NO_CABLE;
4183 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4184 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4185 "fw_state=%x 84xx=%x.\n", state[0],
4187 if ((state[2] & FSTATE_LOGGED_IN) &&
4188 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4189 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4190 "Sending verify iocb.\n");
4192 cs84xx_time = jiffies;
4193 rval = qla84xx_init_chip(vha);
4194 if (rval != QLA_SUCCESS) {
4197 "Init chip failed.\n");
4201 /* Add time taken to initialize. */
4202 cs84xx_time = jiffies - cs84xx_time;
4203 wtime += cs84xx_time;
4204 mtime += cs84xx_time;
4205 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4206 "Increasing wait time by %ld. "
4207 "New time %ld.\n", cs84xx_time,
4210 } else if (state[0] == FSTATE_READY) {
4211 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4212 "F/W Ready - OK.\n");
4214 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4215 &ha->login_timeout, &ha->r_a_tov);
4221 rval = QLA_FUNCTION_FAILED;
4223 if (atomic_read(&vha->loop_down_timer) &&
4224 state[0] != FSTATE_READY) {
4225 /* Loop down. Timeout on min_wait for states
4226 * other than Wait for Login.
4228 if (time_after_eq(jiffies, mtime)) {
4229 ql_log(ql_log_info, vha, 0x8038,
4230 "Cable is unplugged...\n");
4232 vha->device_flags |= DFLG_NO_CABLE;
4237 /* Mailbox cmd failed. Timeout on min_wait. */
4238 if (time_after_eq(jiffies, mtime) ||
4239 ha->flags.isp82xx_fw_hung)
4243 if (time_after_eq(jiffies, wtime))
4246 /* Delay for a while */
4250 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4251 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4252 state[1], state[2], state[3], state[4], state[5], jiffies);
4254 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4255 ql_log(ql_log_warn, vha, 0x803b,
4256 "Firmware ready **** FAILED ****.\n");
4263 * qla2x00_configure_hba
4264 * Setup adapter context.
4267 * ha = adapter state pointer.
4276 qla2x00_configure_hba(scsi_qla_host_t *vha)
4285 char connect_type[22];
4286 struct qla_hw_data *ha = vha->hw;
4287 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4289 unsigned long flags;
4291 /* Get host addresses. */
4292 rval = qla2x00_get_adapter_id(vha,
4293 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4294 if (rval != QLA_SUCCESS) {
4295 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4296 IS_CNA_CAPABLE(ha) ||
4297 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4298 ql_dbg(ql_dbg_disc, vha, 0x2008,
4299 "Loop is in a transition state.\n");
4301 ql_log(ql_log_warn, vha, 0x2009,
4302 "Unable to get host loop ID.\n");
4303 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4304 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4305 ql_log(ql_log_warn, vha, 0x1151,
4306 "Doing link init.\n");
4307 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4310 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4316 ql_log(ql_log_info, vha, 0x200a,
4317 "Cannot get topology - retrying.\n");
4318 return (QLA_FUNCTION_FAILED);
4321 vha->loop_id = loop_id;
4324 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4325 ha->operating_mode = LOOP;
4330 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4331 ha->current_topology = ISP_CFG_NL;
4332 strcpy(connect_type, "(Loop)");
4336 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4337 ha->switch_cap = sw_cap;
4338 ha->current_topology = ISP_CFG_FL;
4339 strcpy(connect_type, "(FL_Port)");
4343 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4344 ha->operating_mode = P2P;
4345 ha->current_topology = ISP_CFG_N;
4346 strcpy(connect_type, "(N_Port-to-N_Port)");
4350 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4351 ha->switch_cap = sw_cap;
4352 ha->operating_mode = P2P;
4353 ha->current_topology = ISP_CFG_F;
4354 strcpy(connect_type, "(F_Port)");
4358 ql_dbg(ql_dbg_disc, vha, 0x200f,
4359 "HBA in unknown topology %x, using NL.\n", topo);
4360 ha->current_topology = ISP_CFG_NL;
4361 strcpy(connect_type, "(Loop)");
4365 /* Save Host port and loop ID. */
4366 /* byte order - Big Endian */
4367 id.b.domain = domain;
4371 spin_lock_irqsave(&ha->hardware_lock, flags);
4372 if (!(topo == 2 && ha->flags.n2n_bigger))
4373 qlt_update_host_map(vha, id);
4374 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4376 if (!vha->flags.init_done)
4377 ql_log(ql_log_info, vha, 0x2010,
4378 "Topology - %s, Host Loop address 0x%x.\n",
4379 connect_type, vha->loop_id);
4385 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4390 uint64_t zero[2] = { 0 };
4391 struct qla_hw_data *ha = vha->hw;
4392 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4393 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4395 if (len > sizeof(zero))
4397 if (memcmp(model, &zero, len) != 0) {
4398 memcpy(ha->model_number, model, len);
4399 st = en = ha->model_number;
4402 if (*en != 0x20 && *en != 0x00)
4407 index = (ha->pdev->subsystem_device & 0xff);
4409 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4410 index < QLA_MODEL_NAMES)
4411 strlcpy(ha->model_desc,
4412 qla2x00_model_name[index * 2 + 1],
4413 sizeof(ha->model_desc));
4415 index = (ha->pdev->subsystem_device & 0xff);
4417 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4418 index < QLA_MODEL_NAMES) {
4419 strlcpy(ha->model_number,
4420 qla2x00_model_name[index * 2],
4421 sizeof(ha->model_number));
4422 strlcpy(ha->model_desc,
4423 qla2x00_model_name[index * 2 + 1],
4424 sizeof(ha->model_desc));
4426 strlcpy(ha->model_number, def,
4427 sizeof(ha->model_number));
4430 if (IS_FWI2_CAPABLE(ha))
4431 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4432 sizeof(ha->model_desc));
4435 /* On sparc systems, obtain port and node WWN from firmware
4438 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4441 struct qla_hw_data *ha = vha->hw;
4442 struct pci_dev *pdev = ha->pdev;
4443 struct device_node *dp = pci_device_to_OF_node(pdev);
4447 val = of_get_property(dp, "port-wwn", &len);
4448 if (val && len >= WWN_SIZE)
4449 memcpy(nv->port_name, val, WWN_SIZE);
4451 val = of_get_property(dp, "node-wwn", &len);
4452 if (val && len >= WWN_SIZE)
4453 memcpy(nv->node_name, val, WWN_SIZE);
4458 * NVRAM configuration for ISP 2xxx
4461 * ha = adapter block pointer.
4464 * initialization control block in response_ring
4465 * host adapters parameters in host adapter block
4471 qla2x00_nvram_config(scsi_qla_host_t *vha)
4476 uint8_t *dptr1, *dptr2;
4477 struct qla_hw_data *ha = vha->hw;
4478 init_cb_t *icb = ha->init_cb;
4479 nvram_t *nv = ha->nvram;
4480 uint8_t *ptr = ha->nvram;
4481 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4485 /* Determine NVRAM starting address. */
4486 ha->nvram_size = sizeof(*nv);
4488 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4489 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4490 ha->nvram_base = 0x80;
4492 /* Get NVRAM data and calculate checksum. */
4493 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4494 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4497 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4498 "Contents of NVRAM.\n");
4499 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4500 nv, ha->nvram_size);
4502 /* Bad NVRAM data, set defaults parameters. */
4503 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4504 nv->nvram_version < 1) {
4505 /* Reset NVRAM data. */
4506 ql_log(ql_log_warn, vha, 0x0064,
4507 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4508 chksum, nv->id, nv->nvram_version);
4509 ql_log(ql_log_warn, vha, 0x0065,
4511 "functioning (yet invalid -- WWPN) defaults.\n");
4514 * Set default initialization control block.
4516 memset(nv, 0, ha->nvram_size);
4517 nv->parameter_block_version = ICB_VERSION;
4519 if (IS_QLA23XX(ha)) {
4520 nv->firmware_options[0] = BIT_2 | BIT_1;
4521 nv->firmware_options[1] = BIT_7 | BIT_5;
4522 nv->add_firmware_options[0] = BIT_5;
4523 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4524 nv->frame_payload_size = 2048;
4525 nv->special_options[1] = BIT_7;
4526 } else if (IS_QLA2200(ha)) {
4527 nv->firmware_options[0] = BIT_2 | BIT_1;
4528 nv->firmware_options[1] = BIT_7 | BIT_5;
4529 nv->add_firmware_options[0] = BIT_5;
4530 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4531 nv->frame_payload_size = 1024;
4532 } else if (IS_QLA2100(ha)) {
4533 nv->firmware_options[0] = BIT_3 | BIT_1;
4534 nv->firmware_options[1] = BIT_5;
4535 nv->frame_payload_size = 1024;
4538 nv->max_iocb_allocation = cpu_to_le16(256);
4539 nv->execution_throttle = cpu_to_le16(16);
4540 nv->retry_count = 8;
4541 nv->retry_delay = 1;
4543 nv->port_name[0] = 33;
4544 nv->port_name[3] = 224;
4545 nv->port_name[4] = 139;
4547 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4549 nv->login_timeout = 4;
4552 * Set default host adapter parameters
4554 nv->host_p[1] = BIT_2;
4555 nv->reset_delay = 5;
4556 nv->port_down_retry_count = 8;
4557 nv->max_luns_per_target = cpu_to_le16(8);
4558 nv->link_down_timeout = 60;
4563 /* Reset Initialization control block */
4564 memset(icb, 0, ha->init_cb_size);
4567 * Setup driver NVRAM options.
4569 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4570 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4571 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4572 nv->firmware_options[1] &= ~BIT_4;
4574 if (IS_QLA23XX(ha)) {
4575 nv->firmware_options[0] |= BIT_2;
4576 nv->firmware_options[0] &= ~BIT_3;
4577 nv->special_options[0] &= ~BIT_6;
4578 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4580 if (IS_QLA2300(ha)) {
4581 if (ha->fb_rev == FPM_2310) {
4582 strcpy(ha->model_number, "QLA2310");
4584 strcpy(ha->model_number, "QLA2300");
4587 qla2x00_set_model_info(vha, nv->model_number,
4588 sizeof(nv->model_number), "QLA23xx");
4590 } else if (IS_QLA2200(ha)) {
4591 nv->firmware_options[0] |= BIT_2;
4593 * 'Point-to-point preferred, else loop' is not a safe
4594 * connection mode setting.
4596 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4598 /* Force 'loop preferred, else point-to-point'. */
4599 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4600 nv->add_firmware_options[0] |= BIT_5;
4602 strcpy(ha->model_number, "QLA22xx");
4603 } else /*if (IS_QLA2100(ha))*/ {
4604 strcpy(ha->model_number, "QLA2100");
4608 * Copy over NVRAM RISC parameter block to initialization control block.
4610 dptr1 = (uint8_t *)icb;
4611 dptr2 = (uint8_t *)&nv->parameter_block_version;
4612 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4614 *dptr1++ = *dptr2++;
4616 /* Copy 2nd half. */
4617 dptr1 = (uint8_t *)icb->add_firmware_options;
4618 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4620 *dptr1++ = *dptr2++;
4621 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4622 /* Use alternate WWN? */
4623 if (nv->host_p[1] & BIT_7) {
4624 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4625 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4628 /* Prepare nodename */
4629 if ((icb->firmware_options[1] & BIT_6) == 0) {
4631 * Firmware will apply the following mask if the nodename was
4634 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4635 icb->node_name[0] &= 0xF0;
4639 * Set host adapter parameters.
4643 * BIT_7 in the host-parameters section allows for modification to
4644 * internal driver logging.
4646 if (nv->host_p[0] & BIT_7)
4647 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4648 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4649 /* Always load RISC code on non ISP2[12]00 chips. */
4650 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4651 ha->flags.disable_risc_code_load = 0;
4652 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4653 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4654 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4655 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4656 ha->flags.disable_serdes = 0;
4658 ha->operating_mode =
4659 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4661 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4662 sizeof(ha->fw_seriallink_options));
4664 /* save HBA serial number */
4665 ha->serial0 = icb->port_name[5];
4666 ha->serial1 = icb->port_name[6];
4667 ha->serial2 = icb->port_name[7];
4668 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4669 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4671 icb->execution_throttle = cpu_to_le16(0xFFFF);
4673 ha->retry_count = nv->retry_count;
4675 /* Set minimum login_timeout to 4 seconds. */
4676 if (nv->login_timeout != ql2xlogintimeout)
4677 nv->login_timeout = ql2xlogintimeout;
4678 if (nv->login_timeout < 4)
4679 nv->login_timeout = 4;
4680 ha->login_timeout = nv->login_timeout;
4682 /* Set minimum RATOV to 100 tenths of a second. */
4685 ha->loop_reset_delay = nv->reset_delay;
4687 /* Link Down Timeout = 0:
4689 * When Port Down timer expires we will start returning
4690 * I/O's to OS with "DID_NO_CONNECT".
4692 * Link Down Timeout != 0:
4694 * The driver waits for the link to come up after link down
4695 * before returning I/Os to OS with "DID_NO_CONNECT".
4697 if (nv->link_down_timeout == 0) {
4698 ha->loop_down_abort_time =
4699 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4701 ha->link_down_timeout = nv->link_down_timeout;
4702 ha->loop_down_abort_time =
4703 (LOOP_DOWN_TIME - ha->link_down_timeout);
4707 * Need enough time to try and get the port back.
4709 ha->port_down_retry_count = nv->port_down_retry_count;
4710 if (qlport_down_retry)
4711 ha->port_down_retry_count = qlport_down_retry;
4712 /* Set login_retry_count */
4713 ha->login_retry_count = nv->retry_count;
4714 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4715 ha->port_down_retry_count > 3)
4716 ha->login_retry_count = ha->port_down_retry_count;
4717 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4718 ha->login_retry_count = ha->port_down_retry_count;
4719 if (ql2xloginretrycount)
4720 ha->login_retry_count = ql2xloginretrycount;
4722 icb->lun_enables = cpu_to_le16(0);
4723 icb->command_resource_count = 0;
4724 icb->immediate_notify_resource_count = 0;
4725 icb->timeout = cpu_to_le16(0);
4727 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4729 icb->firmware_options[0] &= ~BIT_3;
4730 icb->add_firmware_options[0] &=
4731 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4732 icb->add_firmware_options[0] |= BIT_2;
4733 icb->response_accumulation_timer = 3;
4734 icb->interrupt_delay_timer = 5;
4736 vha->flags.process_response_queue = 1;
4739 if (!vha->flags.init_done) {
4740 ha->zio_mode = icb->add_firmware_options[0] &
4741 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4742 ha->zio_timer = icb->interrupt_delay_timer ?
4743 icb->interrupt_delay_timer : 2;
4745 icb->add_firmware_options[0] &=
4746 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4747 vha->flags.process_response_queue = 0;
4748 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4749 ha->zio_mode = QLA_ZIO_MODE_6;
4751 ql_log(ql_log_info, vha, 0x0068,
4752 "ZIO mode %d enabled; timer delay (%d us).\n",
4753 ha->zio_mode, ha->zio_timer * 100);
4755 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4756 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4757 vha->flags.process_response_queue = 1;
4762 ql_log(ql_log_warn, vha, 0x0069,
4763 "NVRAM configuration failed.\n");
4769 qla2x00_rport_del(void *data)
4771 fc_port_t *fcport = data;
4772 struct fc_rport *rport;
4773 unsigned long flags;
4775 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4776 rport = fcport->drport ? fcport->drport : fcport->rport;
4777 fcport->drport = NULL;
4778 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4780 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4781 "%s %8phN. rport %p roles %x\n",
4782 __func__, fcport->port_name, rport,
4785 fc_remote_port_delete(rport);
4789 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4793 old_state = atomic_read(&fcport->state);
4794 atomic_set(&fcport->state, state);
4796 /* Don't print state transitions during initial allocation of fcport */
4797 if (old_state && old_state != state) {
4798 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4799 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4800 fcport->port_name, port_state_str[old_state],
4801 port_state_str[state], fcport->d_id.b.domain,
4802 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4807 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4809 * @flags: allocation flags
4811 * Returns a pointer to the allocated fcport, or NULL, if none available.
4814 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4818 fcport = kzalloc(sizeof(fc_port_t), flags);
4822 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4823 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4825 if (!fcport->ct_desc.ct_sns) {
4826 ql_log(ql_log_warn, vha, 0xd049,
4827 "Failed to allocate ct_sns request.\n");
4832 /* Setup fcport template structure. */
4834 fcport->port_type = FCT_UNKNOWN;
4835 fcport->loop_id = FC_NO_LOOP_ID;
4836 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4837 fcport->supported_classes = FC_COS_UNSPECIFIED;
4838 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4840 fcport->disc_state = DSC_DELETED;
4841 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4842 fcport->deleted = QLA_SESS_DELETED;
4843 fcport->login_retry = vha->hw->login_retry_count;
4844 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4845 fcport->logout_on_delete = 1;
4847 if (!fcport->ct_desc.ct_sns) {
4848 ql_log(ql_log_warn, vha, 0xd049,
4849 "Failed to allocate ct_sns request.\n");
4854 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4855 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4856 INIT_LIST_HEAD(&fcport->gnl_entry);
4857 INIT_LIST_HEAD(&fcport->list);
4863 qla2x00_free_fcport(fc_port_t *fcport)
4865 if (fcport->ct_desc.ct_sns) {
4866 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4867 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4868 fcport->ct_desc.ct_sns_dma);
4870 fcport->ct_desc.ct_sns = NULL;
4872 list_del(&fcport->list);
4873 qla2x00_clear_loop_id(fcport);
4878 * qla2x00_configure_loop
4879 * Updates Fibre Channel Device Database with what is actually on loop.
4882 * ha = adapter block pointer.
4887 * 2 = database was full and device was not configured.
4890 qla2x00_configure_loop(scsi_qla_host_t *vha)
4893 unsigned long flags, save_flags;
4894 struct qla_hw_data *ha = vha->hw;
4898 /* Get Initiator ID */
4899 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4900 rval = qla2x00_configure_hba(vha);
4901 if (rval != QLA_SUCCESS) {
4902 ql_dbg(ql_dbg_disc, vha, 0x2013,
4903 "Unable to configure HBA.\n");
4908 save_flags = flags = vha->dpc_flags;
4909 ql_dbg(ql_dbg_disc, vha, 0x2014,
4910 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4913 * If we have both an RSCN and PORT UPDATE pending then handle them
4914 * both at the same time.
4916 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4917 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4919 qla2x00_get_data_rate(vha);
4921 /* Determine what we need to do */
4922 if (ha->current_topology == ISP_CFG_FL &&
4923 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4925 set_bit(RSCN_UPDATE, &flags);
4927 } else if (ha->current_topology == ISP_CFG_F &&
4928 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4930 set_bit(RSCN_UPDATE, &flags);
4931 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4933 } else if (ha->current_topology == ISP_CFG_N) {
4934 clear_bit(RSCN_UPDATE, &flags);
4935 if (qla_tgt_mode_enabled(vha)) {
4936 /* allow the other side to start the login */
4937 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4938 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4940 } else if (ha->current_topology == ISP_CFG_NL) {
4941 clear_bit(RSCN_UPDATE, &flags);
4942 set_bit(LOCAL_LOOP_UPDATE, &flags);
4943 } else if (!vha->flags.online ||
4944 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4945 set_bit(RSCN_UPDATE, &flags);
4946 set_bit(LOCAL_LOOP_UPDATE, &flags);
4949 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4950 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4951 ql_dbg(ql_dbg_disc, vha, 0x2015,
4952 "Loop resync needed, failing.\n");
4953 rval = QLA_FUNCTION_FAILED;
4955 rval = qla2x00_configure_local_loop(vha);
4958 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4959 if (LOOP_TRANSITION(vha)) {
4960 ql_dbg(ql_dbg_disc, vha, 0x2099,
4961 "Needs RSCN update and loop transition.\n");
4962 rval = QLA_FUNCTION_FAILED;
4965 rval = qla2x00_configure_fabric(vha);
4968 if (rval == QLA_SUCCESS) {
4969 if (atomic_read(&vha->loop_down_timer) ||
4970 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4971 rval = QLA_FUNCTION_FAILED;
4973 atomic_set(&vha->loop_state, LOOP_READY);
4974 ql_dbg(ql_dbg_disc, vha, 0x2069,
4976 ha->flags.fw_init_done = 1;
4979 * Process any ATIO queue entries that came in
4980 * while we weren't online.
4982 if (qla_tgt_mode_enabled(vha) ||
4983 qla_dual_mode_enabled(vha)) {
4984 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
4985 qlt_24xx_process_atio_queue(vha, 0);
4986 spin_unlock_irqrestore(&ha->tgt.atio_lock,
4993 ql_dbg(ql_dbg_disc, vha, 0x206a,
4994 "%s *** FAILED ***.\n", __func__);
4996 ql_dbg(ql_dbg_disc, vha, 0x206b,
4997 "%s: exiting normally.\n", __func__);
5000 /* Restore state if a resync event occurred during processing */
5001 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5002 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5003 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5004 if (test_bit(RSCN_UPDATE, &save_flags)) {
5005 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5013 * qla2x00_configure_local_loop
5014 * Updates Fibre Channel Device Database with local loop devices.
5017 * ha = adapter block pointer.
5023 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5028 fc_port_t *fcport, *new_fcport;
5032 struct gid_list_info *gid;
5034 uint8_t domain, area, al_pa;
5035 struct qla_hw_data *ha = vha->hw;
5036 unsigned long flags;
5038 /* Inititae N2N login. */
5040 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5044 memset(ha->init_cb, 0, ha->init_cb_size);
5045 sz = min_t(int, sizeof(struct els_plogi_payload),
5047 rval = qla24xx_get_port_login_templ(vha,
5048 ha->init_cb_dma, (void *)ha->init_cb, sz);
5049 if (rval == QLA_SUCCESS) {
5050 bp = (uint32_t *)ha->init_cb;
5051 for (i = 0; i < sz/4 ; i++, bp++)
5052 *bp = cpu_to_be32(*bp);
5054 memcpy(&ha->plogi_els_payld.data,
5055 (void *)ha->init_cb,
5056 sizeof(ha->plogi_els_payld.data));
5057 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5059 ql_dbg(ql_dbg_init, vha, 0x00d1,
5060 "PLOGI ELS param read fail.\n");
5065 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5066 if (fcport->n2n_flag) {
5067 qla24xx_fcport_handle_login(vha, fcport);
5072 spin_lock_irqsave(&vha->work_lock, flags);
5073 vha->scan.scan_retry++;
5074 spin_unlock_irqrestore(&vha->work_lock, flags);
5076 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5077 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5078 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5084 entries = MAX_FIBRE_DEVICES_LOOP;
5086 /* Get list of logged in devices. */
5087 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5088 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5090 if (rval != QLA_SUCCESS)
5091 goto cleanup_allocation;
5093 ql_dbg(ql_dbg_disc, vha, 0x2011,
5094 "Entries in ID list (%d).\n", entries);
5095 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5096 ha->gid_list, entries * sizeof(*ha->gid_list));
5099 spin_lock_irqsave(&vha->work_lock, flags);
5100 vha->scan.scan_retry++;
5101 spin_unlock_irqrestore(&vha->work_lock, flags);
5103 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5104 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5105 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5108 vha->scan.scan_retry = 0;
5111 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5112 fcport->scan_state = QLA_FCPORT_SCAN;
5115 /* Allocate temporary fcport for any new fcports discovered. */
5116 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5117 if (new_fcport == NULL) {
5118 ql_log(ql_log_warn, vha, 0x2012,
5119 "Memory allocation failed for fcport.\n");
5120 rval = QLA_MEMORY_ALLOC_FAILED;
5121 goto cleanup_allocation;
5123 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5125 /* Add devices to port list. */
5127 for (index = 0; index < entries; index++) {
5128 domain = gid->domain;
5131 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5132 loop_id = gid->loop_id_2100;
5134 loop_id = le16_to_cpu(gid->loop_id);
5135 gid = (void *)gid + ha->gid_list_info_size;
5137 /* Bypass reserved domain fields. */
5138 if ((domain & 0xf0) == 0xf0)
5141 /* Bypass if not same domain and area of adapter. */
5142 if (area && domain && ((area != vha->d_id.b.area) ||
5143 (domain != vha->d_id.b.domain)) &&
5144 (ha->current_topology == ISP_CFG_NL))
5148 /* Bypass invalid local loop ID. */
5149 if (loop_id > LAST_LOCAL_LOOP_ID)
5152 memset(new_fcport->port_name, 0, WWN_SIZE);
5154 /* Fill in member data. */
5155 new_fcport->d_id.b.domain = domain;
5156 new_fcport->d_id.b.area = area;
5157 new_fcport->d_id.b.al_pa = al_pa;
5158 new_fcport->loop_id = loop_id;
5159 new_fcport->scan_state = QLA_FCPORT_FOUND;
5161 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5162 if (rval2 != QLA_SUCCESS) {
5163 ql_dbg(ql_dbg_disc, vha, 0x2097,
5164 "Failed to retrieve fcport information "
5165 "-- get_port_database=%x, loop_id=0x%04x.\n",
5166 rval2, new_fcport->loop_id);
5167 /* Skip retry if N2N */
5168 if (ha->current_topology != ISP_CFG_N) {
5169 ql_dbg(ql_dbg_disc, vha, 0x2105,
5170 "Scheduling resync.\n");
5171 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5176 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5177 /* Check for matching device in port list. */
5180 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5181 if (memcmp(new_fcport->port_name, fcport->port_name,
5185 fcport->flags &= ~FCF_FABRIC_DEVICE;
5186 fcport->loop_id = new_fcport->loop_id;
5187 fcport->port_type = new_fcport->port_type;
5188 fcport->d_id.b24 = new_fcport->d_id.b24;
5189 memcpy(fcport->node_name, new_fcport->node_name,
5191 fcport->scan_state = QLA_FCPORT_FOUND;
5197 /* New device, add to fcports list. */
5198 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5200 /* Allocate a new replacement fcport. */
5201 fcport = new_fcport;
5203 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5205 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5207 if (new_fcport == NULL) {
5208 ql_log(ql_log_warn, vha, 0xd031,
5209 "Failed to allocate memory for fcport.\n");
5210 rval = QLA_MEMORY_ALLOC_FAILED;
5211 goto cleanup_allocation;
5213 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5214 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5217 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5219 /* Base iIDMA settings on HBA port speed. */
5220 fcport->fp_speed = ha->link_data_rate;
5225 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5226 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5229 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5230 if ((qla_dual_mode_enabled(vha) ||
5231 qla_ini_mode_enabled(vha)) &&
5232 atomic_read(&fcport->state) == FCS_ONLINE) {
5233 qla2x00_mark_device_lost(vha, fcport,
5234 ql2xplogiabsentdevice, 0);
5235 if (fcport->loop_id != FC_NO_LOOP_ID &&
5236 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5237 fcport->port_type != FCT_INITIATOR &&
5238 fcport->port_type != FCT_BROADCAST) {
5239 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5240 "%s %d %8phC post del sess\n",
5244 qlt_schedule_sess_for_deletion(fcport);
5250 if (fcport->scan_state == QLA_FCPORT_FOUND)
5251 qla24xx_fcport_handle_login(vha, fcport);
5257 if (rval != QLA_SUCCESS) {
5258 ql_dbg(ql_dbg_disc, vha, 0x2098,
5259 "Configure local loop error exit: rval=%x.\n", rval);
5266 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5269 uint16_t mb[MAILBOX_REGISTER_COUNT];
5270 struct qla_hw_data *ha = vha->hw;
5272 if (!IS_IIDMA_CAPABLE(ha))
5275 if (atomic_read(&fcport->state) != FCS_ONLINE)
5278 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5279 fcport->fp_speed > ha->link_data_rate ||
5280 !ha->flags.gpsc_supported)
5283 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5285 if (rval != QLA_SUCCESS) {
5286 ql_dbg(ql_dbg_disc, vha, 0x2004,
5287 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5288 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5290 ql_dbg(ql_dbg_disc, vha, 0x2005,
5291 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5292 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5293 fcport->fp_speed, fcport->port_name);
5297 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5299 qla2x00_iidma_fcport(vha, fcport);
5300 qla24xx_update_fcport_fcp_prio(vha, fcport);
5303 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5305 struct qla_work_evt *e;
5307 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5309 return QLA_FUNCTION_FAILED;
5311 e->u.fcport.fcport = fcport;
5312 return qla2x00_post_work(vha, e);
5315 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5317 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5319 struct fc_rport_identifiers rport_ids;
5320 struct fc_rport *rport;
5321 unsigned long flags;
5323 if (atomic_read(&fcport->state) == FCS_ONLINE)
5326 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5327 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5328 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5329 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5330 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5331 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5333 ql_log(ql_log_warn, vha, 0x2006,
5334 "Unable to allocate fc remote port.\n");
5338 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5339 *((fc_port_t **)rport->dd_data) = fcport;
5340 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5342 rport->supported_classes = fcport->supported_classes;
5344 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5345 if (fcport->port_type == FCT_INITIATOR)
5346 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5347 if (fcport->port_type == FCT_TARGET)
5348 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5349 if (fcport->port_type & FCT_NVME_INITIATOR)
5350 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5351 if (fcport->port_type & FCT_NVME_TARGET)
5352 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5353 if (fcport->port_type & FCT_NVME_DISCOVERY)
5354 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5356 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5357 "%s %8phN. rport %p is %s mode\n",
5358 __func__, fcport->port_name, rport,
5359 (fcport->port_type == FCT_TARGET) ? "tgt" :
5360 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5362 fc_remote_port_rolechg(rport, rport_ids.roles);
5366 * qla2x00_update_fcport
5367 * Updates device on list.
5370 * ha = adapter block pointer.
5371 * fcport = port structure pointer.
5381 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5383 if (IS_SW_RESV_ADDR(fcport->d_id))
5386 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5387 __func__, fcport->port_name);
5389 fcport->disc_state = DSC_UPD_FCPORT;
5390 fcport->login_retry = vha->hw->login_retry_count;
5391 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5392 fcport->deleted = 0;
5393 fcport->logout_on_delete = 1;
5394 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5396 switch (vha->hw->current_topology) {
5399 fcport->keep_nport_handle = 1;
5405 qla2x00_iidma_fcport(vha, fcport);
5407 if (NVME_TARGET(vha->hw, fcport)) {
5408 qla_nvme_register_remote(vha, fcport);
5409 fcport->disc_state = DSC_LOGIN_COMPLETE;
5410 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5414 qla24xx_update_fcport_fcp_prio(vha, fcport);
5416 switch (vha->host->active_mode) {
5417 case MODE_INITIATOR:
5418 qla2x00_reg_remote_port(vha, fcport);
5421 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5422 !vha->vha_tgt.qla_tgt->tgt_stopped)
5423 qlt_fc_port_added(vha, fcport);
5426 qla2x00_reg_remote_port(vha, fcport);
5427 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5428 !vha->vha_tgt.qla_tgt->tgt_stopped)
5429 qlt_fc_port_added(vha, fcport);
5435 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5437 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5438 if (fcport->id_changed) {
5439 fcport->id_changed = 0;
5440 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5441 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5442 __func__, __LINE__, fcport->port_name,
5444 qla24xx_post_gfpnid_work(vha, fcport);
5446 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5447 "%s %d %8phC post gpsc fcp_cnt %d\n",
5448 __func__, __LINE__, fcport->port_name,
5450 qla24xx_post_gpsc_work(vha, fcport);
5454 fcport->disc_state = DSC_LOGIN_COMPLETE;
5457 void qla_register_fcport_fn(struct work_struct *work)
5459 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5460 u32 rscn_gen = fcport->rscn_gen;
5463 if (IS_SW_RESV_ADDR(fcport->d_id))
5466 qla2x00_update_fcport(fcport->vha, fcport);
5468 if (rscn_gen != fcport->rscn_gen) {
5469 /* RSCN(s) came in while registration */
5470 switch (fcport->next_disc_state) {
5471 case DSC_DELETE_PEND:
5472 qlt_schedule_sess_for_deletion(fcport);
5475 data[0] = data[1] = 0;
5476 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5486 * qla2x00_configure_fabric
5487 * Setup SNS devices with loop ID's.
5490 * ha = adapter block pointer.
5497 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5501 uint16_t mb[MAILBOX_REGISTER_COUNT];
5503 LIST_HEAD(new_fcports);
5504 struct qla_hw_data *ha = vha->hw;
5507 /* If FL port exists, then SNS is present */
5508 if (IS_FWI2_CAPABLE(ha))
5509 loop_id = NPH_F_PORT;
5511 loop_id = SNS_FL_PORT;
5512 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5513 if (rval != QLA_SUCCESS) {
5514 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5515 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5517 vha->device_flags &= ~SWITCH_FOUND;
5518 return (QLA_SUCCESS);
5520 vha->device_flags |= SWITCH_FOUND;
5523 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5524 rval = qla2x00_send_change_request(vha, 0x3, 0);
5525 if (rval != QLA_SUCCESS)
5526 ql_log(ql_log_warn, vha, 0x121,
5527 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5533 qla2x00_mgmt_svr_login(vha);
5536 if (ql2xfdmienable &&
5537 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5538 qla2x00_fdmi_register(vha);
5540 /* Ensure we are logged into the SNS. */
5541 loop_id = NPH_SNS_LID(ha);
5542 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5543 0xfc, mb, BIT_1|BIT_0);
5544 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5545 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5546 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5547 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5548 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5551 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5552 if (qla2x00_rft_id(vha)) {
5554 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5555 "Register FC-4 TYPE failed.\n");
5556 if (test_bit(LOOP_RESYNC_NEEDED,
5560 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5562 ql_dbg(ql_dbg_disc, vha, 0x209a,
5563 "Register FC-4 Features failed.\n");
5564 if (test_bit(LOOP_RESYNC_NEEDED,
5568 if (vha->flags.nvme_enabled) {
5569 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5570 ql_dbg(ql_dbg_disc, vha, 0x2049,
5571 "Register NVME FC Type Features failed.\n");
5574 if (qla2x00_rnn_id(vha)) {
5576 ql_dbg(ql_dbg_disc, vha, 0x2104,
5577 "Register Node Name failed.\n");
5578 if (test_bit(LOOP_RESYNC_NEEDED,
5581 } else if (qla2x00_rsnn_nn(vha)) {
5583 ql_dbg(ql_dbg_disc, vha, 0x209b,
5584 "Register Symbolic Node Name failed.\n");
5585 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5591 /* Mark the time right before querying FW for connected ports.
5592 * This process is long, asynchronous and by the time it's done,
5593 * collected information might not be accurate anymore. E.g.
5594 * disconnected port might have re-connected and a brand new
5595 * session has been created. In this case session's generation
5596 * will be newer than discovery_gen. */
5597 qlt_do_generation_tick(vha, &discovery_gen);
5599 if (USE_ASYNC_SCAN(ha)) {
5600 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5603 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5605 list_for_each_entry(fcport, &vha->vp_fcports, list)
5606 fcport->scan_state = QLA_FCPORT_SCAN;
5608 rval = qla2x00_find_all_fabric_devs(vha);
5610 if (rval != QLA_SUCCESS)
5614 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5615 qla_nvme_register_hba(vha);
5618 ql_dbg(ql_dbg_disc, vha, 0x2068,
5619 "Configure fabric error exit rval=%d.\n", rval);
5625 * qla2x00_find_all_fabric_devs
5628 * ha = adapter block pointer.
5629 * dev = database device entry pointer.
5638 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5642 fc_port_t *fcport, *new_fcport;
5647 int first_dev, last_dev;
5648 port_id_t wrap = {}, nxt_d_id;
5649 struct qla_hw_data *ha = vha->hw;
5650 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5651 unsigned long flags;
5655 /* Try GID_PT to get device list, else GAN. */
5657 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5662 ql_dbg(ql_dbg_disc, vha, 0x209c,
5663 "GID_PT allocations failed, fallback on GA_NXT.\n");
5665 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5666 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5668 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5670 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5672 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5674 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5676 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5678 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5680 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5684 /* If other queries succeeded probe for FC-4 type */
5686 qla2x00_gff_id(vha, swl);
5687 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5693 /* Allocate temporary fcport for any new fcports discovered. */
5694 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5695 if (new_fcport == NULL) {
5696 ql_log(ql_log_warn, vha, 0x209d,
5697 "Failed to allocate memory for fcport.\n");
5698 return (QLA_MEMORY_ALLOC_FAILED);
5700 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5701 /* Set start port ID scan at adapter ID. */
5705 /* Starting free loop ID. */
5706 loop_id = ha->min_external_loopid;
5707 for (; loop_id <= ha->max_loop_id; loop_id++) {
5708 if (qla2x00_is_reserved_id(vha, loop_id))
5711 if (ha->current_topology == ISP_CFG_FL &&
5712 (atomic_read(&vha->loop_down_timer) ||
5713 LOOP_TRANSITION(vha))) {
5714 atomic_set(&vha->loop_down_timer, 0);
5715 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5716 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5722 wrap.b24 = new_fcport->d_id.b24;
5724 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5725 memcpy(new_fcport->node_name,
5726 swl[swl_idx].node_name, WWN_SIZE);
5727 memcpy(new_fcport->port_name,
5728 swl[swl_idx].port_name, WWN_SIZE);
5729 memcpy(new_fcport->fabric_port_name,
5730 swl[swl_idx].fabric_port_name, WWN_SIZE);
5731 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5732 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5734 new_fcport->nvme_flag = 0;
5735 if (vha->flags.nvme_enabled &&
5736 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
5737 ql_log(ql_log_info, vha, 0x2131,
5738 "FOUND: NVME port %8phC as FC Type 28h\n",
5739 new_fcport->port_name);
5742 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5748 /* Send GA_NXT to the switch */
5749 rval = qla2x00_ga_nxt(vha, new_fcport);
5750 if (rval != QLA_SUCCESS) {
5751 ql_log(ql_log_warn, vha, 0x209e,
5752 "SNS scan failed -- assuming "
5753 "zero-entry result.\n");
5759 /* If wrap on switch device list, exit. */
5761 wrap.b24 = new_fcport->d_id.b24;
5763 } else if (new_fcport->d_id.b24 == wrap.b24) {
5764 ql_dbg(ql_dbg_disc, vha, 0x209f,
5765 "Device wrap (%02x%02x%02x).\n",
5766 new_fcport->d_id.b.domain,
5767 new_fcport->d_id.b.area,
5768 new_fcport->d_id.b.al_pa);
5772 /* Bypass if same physical adapter. */
5773 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5776 /* Bypass virtual ports of the same host. */
5777 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5780 /* Bypass if same domain and area of adapter. */
5781 if (((new_fcport->d_id.b24 & 0xffff00) ==
5782 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5786 /* Bypass reserved domain fields. */
5787 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5790 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5791 if (ql2xgffidenable &&
5792 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
5793 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5796 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5798 /* Locate matching device in database. */
5800 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5801 if (memcmp(new_fcport->port_name, fcport->port_name,
5805 fcport->scan_state = QLA_FCPORT_FOUND;
5809 /* Update port state. */
5810 memcpy(fcport->fabric_port_name,
5811 new_fcport->fabric_port_name, WWN_SIZE);
5812 fcport->fp_speed = new_fcport->fp_speed;
5815 * If address the same and state FCS_ONLINE
5816 * (or in target mode), nothing changed.
5818 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5819 (atomic_read(&fcport->state) == FCS_ONLINE ||
5820 (vha->host->active_mode == MODE_TARGET))) {
5825 * If device was not a fabric device before.
5827 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5828 fcport->d_id.b24 = new_fcport->d_id.b24;
5829 qla2x00_clear_loop_id(fcport);
5830 fcport->flags |= (FCF_FABRIC_DEVICE |
5836 * Port ID changed or device was marked to be updated;
5837 * Log it out if still logged in and mark it for
5840 if (qla_tgt_mode_enabled(base_vha)) {
5841 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5842 "port changed FC ID, %8phC"
5843 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5845 fcport->d_id.b.domain,
5846 fcport->d_id.b.area,
5847 fcport->d_id.b.al_pa,
5849 new_fcport->d_id.b.domain,
5850 new_fcport->d_id.b.area,
5851 new_fcport->d_id.b.al_pa);
5852 fcport->d_id.b24 = new_fcport->d_id.b24;
5856 fcport->d_id.b24 = new_fcport->d_id.b24;
5857 fcport->flags |= FCF_LOGIN_NEEDED;
5861 if (NVME_TARGET(vha->hw, fcport)) {
5862 if (fcport->disc_state == DSC_DELETE_PEND) {
5863 fcport->disc_state = DSC_GNL;
5864 vha->fcport_count--;
5865 fcport->login_succ = 0;
5870 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5873 /* If device was not in our fcports list, then add it. */
5874 new_fcport->scan_state = QLA_FCPORT_FOUND;
5875 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5877 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5880 /* Allocate a new replacement fcport. */
5881 nxt_d_id.b24 = new_fcport->d_id.b24;
5882 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5883 if (new_fcport == NULL) {
5884 ql_log(ql_log_warn, vha, 0xd032,
5885 "Memory allocation failed for fcport.\n");
5886 return (QLA_MEMORY_ALLOC_FAILED);
5888 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5889 new_fcport->d_id.b24 = nxt_d_id.b24;
5892 qla2x00_free_fcport(new_fcport);
5895 * Logout all previous fabric dev marked lost, except FCP2 devices.
5897 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5898 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5901 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5902 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5905 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5906 if ((qla_dual_mode_enabled(vha) ||
5907 qla_ini_mode_enabled(vha)) &&
5908 atomic_read(&fcport->state) == FCS_ONLINE) {
5909 qla2x00_mark_device_lost(vha, fcport,
5910 ql2xplogiabsentdevice, 0);
5911 if (fcport->loop_id != FC_NO_LOOP_ID &&
5912 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5913 fcport->port_type != FCT_INITIATOR &&
5914 fcport->port_type != FCT_BROADCAST) {
5915 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5916 "%s %d %8phC post del sess\n",
5919 qlt_schedule_sess_for_deletion(fcport);
5925 if (fcport->scan_state == QLA_FCPORT_FOUND)
5926 qla24xx_fcport_handle_login(vha, fcport);
5931 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5933 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5935 int loop_id = FC_NO_LOOP_ID;
5936 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5937 unsigned long flags;
5938 struct qla_hw_data *ha = vha->hw;
5940 if (vha->vp_idx == 0) {
5941 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5942 return NPH_MGMT_SERVER;
5945 /* pick id from high and work down to low */
5946 spin_lock_irqsave(&ha->vport_slock, flags);
5947 for (; lid > 0; lid--) {
5948 if (!test_bit(lid, vha->hw->loop_id_map)) {
5949 set_bit(lid, vha->hw->loop_id_map);
5954 spin_unlock_irqrestore(&ha->vport_slock, flags);
5960 * qla2x00_fabric_login
5961 * Issue fabric login command.
5964 * ha = adapter block pointer.
5965 * device = pointer to FC device type structure.
5968 * 0 - Login successfully
5970 * 2 - Initiator device
5974 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5975 uint16_t *next_loopid)
5979 uint16_t tmp_loopid;
5980 uint16_t mb[MAILBOX_REGISTER_COUNT];
5981 struct qla_hw_data *ha = vha->hw;
5987 ql_dbg(ql_dbg_disc, vha, 0x2000,
5988 "Trying Fabric Login w/loop id 0x%04x for port "
5990 fcport->loop_id, fcport->d_id.b.domain,
5991 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5993 /* Login fcport on switch. */
5994 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
5995 fcport->d_id.b.domain, fcport->d_id.b.area,
5996 fcport->d_id.b.al_pa, mb, BIT_0);
5997 if (rval != QLA_SUCCESS) {
6000 if (mb[0] == MBS_PORT_ID_USED) {
6002 * Device has another loop ID. The firmware team
6003 * recommends the driver perform an implicit login with
6004 * the specified ID again. The ID we just used is save
6005 * here so we return with an ID that can be tried by
6009 tmp_loopid = fcport->loop_id;
6010 fcport->loop_id = mb[1];
6012 ql_dbg(ql_dbg_disc, vha, 0x2001,
6013 "Fabric Login: port in use - next loop "
6014 "id=0x%04x, port id= %02x%02x%02x.\n",
6015 fcport->loop_id, fcport->d_id.b.domain,
6016 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6018 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6023 /* A retry occurred before. */
6024 *next_loopid = tmp_loopid;
6027 * No retry occurred before. Just increment the
6028 * ID value for next login.
6030 *next_loopid = (fcport->loop_id + 1);
6033 if (mb[1] & BIT_0) {
6034 fcport->port_type = FCT_INITIATOR;
6036 fcport->port_type = FCT_TARGET;
6037 if (mb[1] & BIT_1) {
6038 fcport->flags |= FCF_FCP2_DEVICE;
6043 fcport->supported_classes |= FC_COS_CLASS2;
6045 fcport->supported_classes |= FC_COS_CLASS3;
6047 if (IS_FWI2_CAPABLE(ha)) {
6050 FCF_CONF_COMP_SUPPORTED;
6055 } else if (mb[0] == MBS_LOOP_ID_USED) {
6057 * Loop ID already used, try next loop ID.
6060 rval = qla2x00_find_new_loop_id(vha, fcport);
6061 if (rval != QLA_SUCCESS) {
6062 /* Ran out of loop IDs to use */
6065 } else if (mb[0] == MBS_COMMAND_ERROR) {
6067 * Firmware possibly timed out during login. If NO
6068 * retries are left to do then the device is declared
6071 *next_loopid = fcport->loop_id;
6072 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6073 fcport->d_id.b.domain, fcport->d_id.b.area,
6074 fcport->d_id.b.al_pa);
6075 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6081 * unrecoverable / not handled error
6083 ql_dbg(ql_dbg_disc, vha, 0x2002,
6084 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6085 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6086 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6087 fcport->loop_id, jiffies);
6089 *next_loopid = fcport->loop_id;
6090 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6091 fcport->d_id.b.domain, fcport->d_id.b.area,
6092 fcport->d_id.b.al_pa);
6093 qla2x00_clear_loop_id(fcport);
6094 fcport->login_retry = 0;
6105 * qla2x00_local_device_login
6106 * Issue local device login command.
6109 * ha = adapter block pointer.
6110 * loop_id = loop id of device to login to.
6112 * Returns (Where's the #define!!!!):
6113 * 0 - Login successfully
6118 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6121 uint16_t mb[MAILBOX_REGISTER_COUNT];
6123 memset(mb, 0, sizeof(mb));
6124 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6125 if (rval == QLA_SUCCESS) {
6126 /* Interrogate mailbox registers for any errors */
6127 if (mb[0] == MBS_COMMAND_ERROR)
6129 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6130 /* device not in PCB table */
6138 * qla2x00_loop_resync
6139 * Resync with fibre channel devices.
6142 * ha = adapter block pointer.
6148 qla2x00_loop_resync(scsi_qla_host_t *vha)
6150 int rval = QLA_SUCCESS;
6153 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6154 if (vha->flags.online) {
6155 if (!(rval = qla2x00_fw_ready(vha))) {
6156 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6159 if (!IS_QLAFX00(vha->hw)) {
6161 * Issue a marker after FW becomes
6164 qla2x00_marker(vha, vha->hw->base_qpair,
6166 vha->marker_needed = 0;
6169 /* Remap devices on Loop. */
6170 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6172 if (IS_QLAFX00(vha->hw))
6173 qlafx00_configure_devices(vha);
6175 qla2x00_configure_loop(vha);
6178 } while (!atomic_read(&vha->loop_down_timer) &&
6179 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6180 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6185 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6186 return (QLA_FUNCTION_FAILED);
6189 ql_dbg(ql_dbg_disc, vha, 0x206c,
6190 "%s *** FAILED ***.\n", __func__);
6196 * qla2x00_perform_loop_resync
6197 * Description: This function will set the appropriate flags and call
6198 * qla2x00_loop_resync. If successful loop will be resynced
6199 * Arguments : scsi_qla_host_t pointer
6200 * returm : Success or Failure
6203 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6207 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6208 /*Configure the flags so that resync happens properly*/
6209 atomic_set(&ha->loop_down_timer, 0);
6210 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6211 atomic_set(&ha->loop_state, LOOP_UP);
6212 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6213 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6214 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6216 rval = qla2x00_loop_resync(ha);
6218 atomic_set(&ha->loop_state, LOOP_DEAD);
6220 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6227 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6230 struct scsi_qla_host *vha;
6231 struct qla_hw_data *ha = base_vha->hw;
6232 unsigned long flags;
6234 spin_lock_irqsave(&ha->vport_slock, flags);
6235 /* Go with deferred removal of rport references. */
6236 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6237 atomic_inc(&vha->vref_count);
6238 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6239 if (fcport->drport &&
6240 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6241 spin_unlock_irqrestore(&ha->vport_slock, flags);
6242 qla2x00_rport_del(fcport);
6244 spin_lock_irqsave(&ha->vport_slock, flags);
6247 atomic_dec(&vha->vref_count);
6248 wake_up(&vha->vref_waitq);
6250 spin_unlock_irqrestore(&ha->vport_slock, flags);
6253 /* Assumes idc_lock always held on entry */
6255 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6257 struct qla_hw_data *ha = vha->hw;
6258 uint32_t drv_presence, drv_presence_mask;
6259 uint32_t dev_part_info1, dev_part_info2, class_type;
6260 uint32_t class_type_mask = 0x3;
6261 uint16_t fcoe_other_function = 0xffff, i;
6263 if (IS_QLA8044(ha)) {
6264 drv_presence = qla8044_rd_direct(vha,
6265 QLA8044_CRB_DRV_ACTIVE_INDEX);
6266 dev_part_info1 = qla8044_rd_direct(vha,
6267 QLA8044_CRB_DEV_PART_INFO_INDEX);
6268 dev_part_info2 = qla8044_rd_direct(vha,
6269 QLA8044_CRB_DEV_PART_INFO2);
6271 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6272 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6273 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6275 for (i = 0; i < 8; i++) {
6276 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6277 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6278 (i != ha->portnum)) {
6279 fcoe_other_function = i;
6283 if (fcoe_other_function == 0xffff) {
6284 for (i = 0; i < 8; i++) {
6285 class_type = ((dev_part_info2 >> (i * 4)) &
6287 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6288 ((i + 8) != ha->portnum)) {
6289 fcoe_other_function = i + 8;
6295 * Prepare drv-presence mask based on fcoe functions present.
6296 * However consider only valid physical fcoe function numbers (0-15).
6298 drv_presence_mask = ~((1 << (ha->portnum)) |
6299 ((fcoe_other_function == 0xffff) ?
6300 0 : (1 << (fcoe_other_function))));
6302 /* We are the reset owner iff:
6303 * - No other protocol drivers present.
6304 * - This is the lowest among fcoe functions. */
6305 if (!(drv_presence & drv_presence_mask) &&
6306 (ha->portnum < fcoe_other_function)) {
6307 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6308 "This host is Reset owner.\n");
6309 ha->flags.nic_core_reset_owner = 1;
6314 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6316 int rval = QLA_SUCCESS;
6317 struct qla_hw_data *ha = vha->hw;
6320 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6321 if (rval == QLA_SUCCESS) {
6322 drv_ack |= (1 << ha->portnum);
6323 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6330 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6332 int rval = QLA_SUCCESS;
6333 struct qla_hw_data *ha = vha->hw;
6336 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6337 if (rval == QLA_SUCCESS) {
6338 drv_ack &= ~(1 << ha->portnum);
6339 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6346 qla83xx_dev_state_to_string(uint32_t dev_state)
6348 switch (dev_state) {
6349 case QLA8XXX_DEV_COLD:
6350 return "COLD/RE-INIT";
6351 case QLA8XXX_DEV_INITIALIZING:
6352 return "INITIALIZING";
6353 case QLA8XXX_DEV_READY:
6355 case QLA8XXX_DEV_NEED_RESET:
6356 return "NEED RESET";
6357 case QLA8XXX_DEV_NEED_QUIESCENT:
6358 return "NEED QUIESCENT";
6359 case QLA8XXX_DEV_FAILED:
6361 case QLA8XXX_DEV_QUIESCENT:
6368 /* Assumes idc-lock always held on entry */
6370 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6372 struct qla_hw_data *ha = vha->hw;
6373 uint32_t idc_audit_reg = 0, duration_secs = 0;
6375 switch (audit_type) {
6376 case IDC_AUDIT_TIMESTAMP:
6377 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6378 idc_audit_reg = (ha->portnum) |
6379 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6380 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6383 case IDC_AUDIT_COMPLETION:
6384 duration_secs = ((jiffies_to_msecs(jiffies) -
6385 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6386 idc_audit_reg = (ha->portnum) |
6387 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6388 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6392 ql_log(ql_log_warn, vha, 0xb078,
6393 "Invalid audit type specified.\n");
6398 /* Assumes idc_lock always held on entry */
6400 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6402 struct qla_hw_data *ha = vha->hw;
6403 uint32_t idc_control, dev_state;
6405 __qla83xx_get_idc_control(vha, &idc_control);
6406 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6407 ql_log(ql_log_info, vha, 0xb080,
6408 "NIC Core reset has been disabled. idc-control=0x%x\n",
6410 return QLA_FUNCTION_FAILED;
6413 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6414 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6415 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6416 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6417 QLA8XXX_DEV_NEED_RESET);
6418 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6419 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6421 const char *state = qla83xx_dev_state_to_string(dev_state);
6423 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6425 /* SV: XXX: Is timeout required here? */
6426 /* Wait for IDC state change READY -> NEED_RESET */
6427 while (dev_state == QLA8XXX_DEV_READY) {
6428 qla83xx_idc_unlock(vha, 0);
6430 qla83xx_idc_lock(vha, 0);
6431 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6435 /* Send IDC ack by writing to drv-ack register */
6436 __qla83xx_set_drv_ack(vha);
6442 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6444 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6448 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6450 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6454 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6456 uint32_t drv_presence = 0;
6457 struct qla_hw_data *ha = vha->hw;
6459 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6460 if (drv_presence & (1 << ha->portnum))
6463 return QLA_TEST_FAILED;
6467 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6469 int rval = QLA_SUCCESS;
6470 struct qla_hw_data *ha = vha->hw;
6472 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6473 "Entered %s().\n", __func__);
6475 if (vha->device_flags & DFLG_DEV_FAILED) {
6476 ql_log(ql_log_warn, vha, 0xb059,
6477 "Device in unrecoverable FAILED state.\n");
6478 return QLA_FUNCTION_FAILED;
6481 qla83xx_idc_lock(vha, 0);
6483 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6484 ql_log(ql_log_warn, vha, 0xb05a,
6485 "Function=0x%x has been removed from IDC participation.\n",
6487 rval = QLA_FUNCTION_FAILED;
6491 qla83xx_reset_ownership(vha);
6493 rval = qla83xx_initiating_reset(vha);
6496 * Perform reset if we are the reset-owner,
6497 * else wait till IDC state changes to READY/FAILED.
6499 if (rval == QLA_SUCCESS) {
6500 rval = qla83xx_idc_state_handler(vha);
6502 if (rval == QLA_SUCCESS)
6503 ha->flags.nic_core_hung = 0;
6504 __qla83xx_clear_drv_ack(vha);
6508 qla83xx_idc_unlock(vha, 0);
6510 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6516 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6518 struct qla_hw_data *ha = vha->hw;
6519 int rval = QLA_FUNCTION_FAILED;
6521 if (!IS_MCTP_CAPABLE(ha)) {
6522 /* This message can be removed from the final version */
6523 ql_log(ql_log_info, vha, 0x506d,
6524 "This board is not MCTP capable\n");
6528 if (!ha->mctp_dump) {
6529 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6530 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6532 if (!ha->mctp_dump) {
6533 ql_log(ql_log_warn, vha, 0x506e,
6534 "Failed to allocate memory for mctp dump\n");
6539 #define MCTP_DUMP_STR_ADDR 0x00000000
6540 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6541 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6542 if (rval != QLA_SUCCESS) {
6543 ql_log(ql_log_warn, vha, 0x506f,
6544 "Failed to capture mctp dump\n");
6546 ql_log(ql_log_info, vha, 0x5070,
6547 "Mctp dump capture for host (%ld/%p).\n",
6548 vha->host_no, ha->mctp_dump);
6549 ha->mctp_dumped = 1;
6552 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6553 ha->flags.nic_core_reset_hdlr_active = 1;
6554 rval = qla83xx_restart_nic_firmware(vha);
6556 /* NIC Core reset failed. */
6557 ql_log(ql_log_warn, vha, 0x5071,
6558 "Failed to restart nic firmware\n");
6560 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6561 "Restarted NIC firmware successfully.\n");
6562 ha->flags.nic_core_reset_hdlr_active = 0;
6570 * qla2x00_quiesce_io
6571 * Description: This function will block the new I/Os
6572 * Its not aborting any I/Os as context
6573 * is not destroyed during quiescence
6574 * Arguments: scsi_qla_host_t
6578 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6580 struct qla_hw_data *ha = vha->hw;
6581 struct scsi_qla_host *vp;
6583 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6584 "Quiescing I/O - ha=%p.\n", ha);
6586 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6587 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6588 atomic_set(&vha->loop_state, LOOP_DOWN);
6589 qla2x00_mark_all_devices_lost(vha, 0);
6590 list_for_each_entry(vp, &ha->vp_list, list)
6591 qla2x00_mark_all_devices_lost(vp, 0);
6593 if (!atomic_read(&vha->loop_down_timer))
6594 atomic_set(&vha->loop_down_timer,
6597 /* Wait for pending cmds to complete */
6598 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6603 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6605 struct qla_hw_data *ha = vha->hw;
6606 struct scsi_qla_host *vp;
6607 unsigned long flags;
6611 /* For ISP82XX, driver waits for completion of the commands.
6612 * online flag should be set.
6614 if (!(IS_P3P_TYPE(ha)))
6615 vha->flags.online = 0;
6616 ha->flags.chip_reset_done = 0;
6617 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6618 vha->qla_stats.total_isp_aborts++;
6620 ql_log(ql_log_info, vha, 0x00af,
6621 "Performing ISP error recovery - ha=%p.\n", ha);
6623 ha->flags.purge_mbox = 1;
6624 /* For ISP82XX, reset_chip is just disabling interrupts.
6625 * Driver waits for the completion of the commands.
6626 * the interrupts need to be enabled.
6628 if (!(IS_P3P_TYPE(ha)))
6629 ha->isp_ops->reset_chip(vha);
6631 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6633 ha->flags.rida_fmt2 = 0;
6634 ha->flags.n2n_ae = 0;
6635 ha->flags.lip_ae = 0;
6636 ha->current_topology = 0;
6637 ha->flags.fw_started = 0;
6638 ha->flags.fw_init_done = 0;
6640 ha->base_qpair->chip_reset = ha->chip_reset;
6641 for (i = 0; i < ha->max_qpairs; i++) {
6642 if (ha->queue_pair_map[i])
6643 ha->queue_pair_map[i]->chip_reset =
6644 ha->base_qpair->chip_reset;
6647 /* purge MBox commands */
6648 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6649 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6650 complete(&ha->mbx_intr_comp);
6654 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6655 atomic_read(&ha->num_pend_mbx_stage2) ||
6656 atomic_read(&ha->num_pend_mbx_stage1)) {
6662 ha->flags.purge_mbox = 0;
6664 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6665 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6666 atomic_set(&vha->loop_state, LOOP_DOWN);
6667 qla2x00_mark_all_devices_lost(vha, 0);
6669 spin_lock_irqsave(&ha->vport_slock, flags);
6670 list_for_each_entry(vp, &ha->vp_list, list) {
6671 atomic_inc(&vp->vref_count);
6672 spin_unlock_irqrestore(&ha->vport_slock, flags);
6674 qla2x00_mark_all_devices_lost(vp, 0);
6676 spin_lock_irqsave(&ha->vport_slock, flags);
6677 atomic_dec(&vp->vref_count);
6679 spin_unlock_irqrestore(&ha->vport_slock, flags);
6681 if (!atomic_read(&vha->loop_down_timer))
6682 atomic_set(&vha->loop_down_timer,
6686 /* Clear all async request states across all VPs. */
6687 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6688 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6689 fcport->scan_state = 0;
6691 spin_lock_irqsave(&ha->vport_slock, flags);
6692 list_for_each_entry(vp, &ha->vp_list, list) {
6693 atomic_inc(&vp->vref_count);
6694 spin_unlock_irqrestore(&ha->vport_slock, flags);
6696 list_for_each_entry(fcport, &vp->vp_fcports, list)
6697 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6699 spin_lock_irqsave(&ha->vport_slock, flags);
6700 atomic_dec(&vp->vref_count);
6702 spin_unlock_irqrestore(&ha->vport_slock, flags);
6704 if (!ha->flags.eeh_busy) {
6705 /* Make sure for ISP 82XX IO DMA is complete */
6706 if (IS_P3P_TYPE(ha)) {
6707 qla82xx_chip_reset_cleanup(vha);
6708 ql_log(ql_log_info, vha, 0x00b4,
6709 "Done chip reset cleanup.\n");
6711 /* Done waiting for pending commands.
6712 * Reset the online flag.
6714 vha->flags.online = 0;
6717 /* Requeue all commands in outstanding command list. */
6718 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6720 /* memory barrier */
6726 * Resets ISP and aborts all outstanding commands.
6729 * ha = adapter block pointer.
6735 qla2x00_abort_isp(scsi_qla_host_t *vha)
6739 struct qla_hw_data *ha = vha->hw;
6740 struct scsi_qla_host *vp;
6741 struct req_que *req = ha->req_q_map[0];
6742 unsigned long flags;
6744 if (vha->flags.online) {
6745 qla2x00_abort_isp_cleanup(vha);
6747 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6748 ha->flags.chip_reset_done = 1;
6749 vha->flags.online = 1;
6751 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6755 if (IS_QLA8031(ha)) {
6756 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6757 "Clearing fcoe driver presence.\n");
6758 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6759 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6760 "Error while clearing DRV-Presence.\n");
6763 if (unlikely(pci_channel_offline(ha->pdev) &&
6764 ha->flags.pci_channel_io_perm_failure)) {
6765 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6770 switch (vha->qlini_mode) {
6771 case QLA2XXX_INI_MODE_DISABLED:
6772 if (!qla_tgt_mode_enabled(vha))
6775 case QLA2XXX_INI_MODE_DUAL:
6776 if (!qla_dual_mode_enabled(vha))
6779 case QLA2XXX_INI_MODE_ENABLED:
6784 ha->isp_ops->get_flash_version(vha, req->ring);
6786 ha->isp_ops->nvram_config(vha);
6788 if (!qla2x00_restart_isp(vha)) {
6789 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6791 if (!atomic_read(&vha->loop_down_timer)) {
6793 * Issue marker command only when we are going
6794 * to start the I/O .
6796 vha->marker_needed = 1;
6799 vha->flags.online = 1;
6801 ha->isp_ops->enable_intrs(ha);
6803 ha->isp_abort_cnt = 0;
6804 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6806 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6807 qla2x00_get_fw_version(vha);
6809 ha->flags.fce_enabled = 1;
6811 fce_calc_size(ha->fce_bufs));
6812 rval = qla2x00_enable_fce_trace(vha,
6813 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6816 ql_log(ql_log_warn, vha, 0x8033,
6817 "Unable to reinitialize FCE "
6819 ha->flags.fce_enabled = 0;
6824 memset(ha->eft, 0, EFT_SIZE);
6825 rval = qla2x00_enable_eft_trace(vha,
6826 ha->eft_dma, EFT_NUM_BUFFERS);
6828 ql_log(ql_log_warn, vha, 0x8034,
6829 "Unable to reinitialize EFT "
6833 } else { /* failed the ISP abort */
6834 vha->flags.online = 1;
6835 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6836 if (ha->isp_abort_cnt == 0) {
6837 ql_log(ql_log_fatal, vha, 0x8035,
6838 "ISP error recover failed - "
6839 "board disabled.\n");
6841 * The next call disables the board
6844 qla2x00_abort_isp_cleanup(vha);
6845 vha->flags.online = 0;
6846 clear_bit(ISP_ABORT_RETRY,
6849 } else { /* schedule another ISP abort */
6850 ha->isp_abort_cnt--;
6851 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6852 "ISP abort - retry remaining %d.\n",
6857 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6858 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6859 "ISP error recovery - retrying (%d) "
6860 "more times.\n", ha->isp_abort_cnt);
6861 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6869 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6870 qla2x00_configure_hba(vha);
6871 spin_lock_irqsave(&ha->vport_slock, flags);
6872 list_for_each_entry(vp, &ha->vp_list, list) {
6874 atomic_inc(&vp->vref_count);
6875 spin_unlock_irqrestore(&ha->vport_slock, flags);
6877 qla2x00_vp_abort_isp(vp);
6879 spin_lock_irqsave(&ha->vport_slock, flags);
6880 atomic_dec(&vp->vref_count);
6883 spin_unlock_irqrestore(&ha->vport_slock, flags);
6885 if (IS_QLA8031(ha)) {
6886 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6887 "Setting back fcoe driver presence.\n");
6888 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6889 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6890 "Error while setting DRV-Presence.\n");
6893 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6901 * qla2x00_restart_isp
6902 * restarts the ISP after a reset
6905 * ha = adapter block pointer.
6911 qla2x00_restart_isp(scsi_qla_host_t *vha)
6914 struct qla_hw_data *ha = vha->hw;
6916 /* If firmware needs to be loaded */
6917 if (qla2x00_isp_firmware(vha)) {
6918 vha->flags.online = 0;
6919 status = ha->isp_ops->chip_diag(vha);
6921 status = qla2x00_setup_chip(vha);
6924 if (!status && !(status = qla2x00_init_rings(vha))) {
6925 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6926 ha->flags.chip_reset_done = 1;
6928 /* Initialize the queues in use */
6929 qla25xx_init_queues(ha);
6931 status = qla2x00_fw_ready(vha);
6933 /* Issue a marker after FW becomes ready. */
6934 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
6935 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6938 /* if no cable then assume it's good */
6939 if ((vha->device_flags & DFLG_NO_CABLE))
6946 qla25xx_init_queues(struct qla_hw_data *ha)
6948 struct rsp_que *rsp = NULL;
6949 struct req_que *req = NULL;
6950 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6954 for (i = 1; i < ha->max_rsp_queues; i++) {
6955 rsp = ha->rsp_q_map[i];
6956 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6957 rsp->options &= ~BIT_0;
6958 ret = qla25xx_init_rsp_que(base_vha, rsp);
6959 if (ret != QLA_SUCCESS)
6960 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6961 "%s Rsp que: %d init failed.\n",
6964 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6965 "%s Rsp que: %d inited.\n",
6969 for (i = 1; i < ha->max_req_queues; i++) {
6970 req = ha->req_q_map[i];
6971 if (req && test_bit(i, ha->req_qid_map)) {
6972 /* Clear outstanding commands array. */
6973 req->options &= ~BIT_0;
6974 ret = qla25xx_init_req_que(base_vha, req);
6975 if (ret != QLA_SUCCESS)
6976 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6977 "%s Req que: %d init failed.\n",
6980 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6981 "%s Req que: %d inited.\n",
6989 * qla2x00_reset_adapter
6993 * ha = adapter block pointer.
6996 qla2x00_reset_adapter(scsi_qla_host_t *vha)
6998 unsigned long flags = 0;
6999 struct qla_hw_data *ha = vha->hw;
7000 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7002 vha->flags.online = 0;
7003 ha->isp_ops->disable_intrs(ha);
7005 spin_lock_irqsave(&ha->hardware_lock, flags);
7006 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7007 RD_REG_WORD(®->hccr); /* PCI Posting. */
7008 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7009 RD_REG_WORD(®->hccr); /* PCI Posting. */
7010 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7016 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7018 unsigned long flags = 0;
7019 struct qla_hw_data *ha = vha->hw;
7020 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7021 int rval = QLA_SUCCESS;
7023 if (IS_P3P_TYPE(ha))
7026 vha->flags.online = 0;
7027 ha->isp_ops->disable_intrs(ha);
7029 spin_lock_irqsave(&ha->hardware_lock, flags);
7030 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7031 RD_REG_DWORD(®->hccr);
7032 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7033 RD_REG_DWORD(®->hccr);
7034 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7036 if (IS_NOPOLLING_TYPE(ha))
7037 ha->isp_ops->enable_intrs(ha);
7042 /* On sparc systems, obtain port and node WWN from firmware
7045 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7046 struct nvram_24xx *nv)
7049 struct qla_hw_data *ha = vha->hw;
7050 struct pci_dev *pdev = ha->pdev;
7051 struct device_node *dp = pci_device_to_OF_node(pdev);
7055 val = of_get_property(dp, "port-wwn", &len);
7056 if (val && len >= WWN_SIZE)
7057 memcpy(nv->port_name, val, WWN_SIZE);
7059 val = of_get_property(dp, "node-wwn", &len);
7060 if (val && len >= WWN_SIZE)
7061 memcpy(nv->node_name, val, WWN_SIZE);
7066 qla24xx_nvram_config(scsi_qla_host_t *vha)
7069 struct init_cb_24xx *icb;
7070 struct nvram_24xx *nv;
7072 uint8_t *dptr1, *dptr2;
7075 struct qla_hw_data *ha = vha->hw;
7078 icb = (struct init_cb_24xx *)ha->init_cb;
7081 /* Determine NVRAM starting address. */
7082 if (ha->port_no == 0) {
7083 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7084 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7086 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7087 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7090 ha->nvram_size = sizeof(*nv);
7091 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7093 /* Get VPD data into cache */
7094 ha->vpd = ha->nvram + VPD_OFFSET;
7095 ha->isp_ops->read_nvram(vha, ha->vpd,
7096 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7098 /* Get NVRAM data into cache and calculate checksum. */
7099 dptr = (uint32_t *)nv;
7100 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7101 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7102 chksum += le32_to_cpu(*dptr);
7104 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7105 "Contents of NVRAM\n");
7106 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7107 nv, ha->nvram_size);
7109 /* Bad NVRAM data, set defaults parameters. */
7110 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7111 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7112 /* Reset NVRAM data. */
7113 ql_log(ql_log_warn, vha, 0x006b,
7114 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7115 chksum, nv->id, nv->nvram_version);
7116 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7117 ql_log(ql_log_warn, vha, 0x006c,
7118 "Falling back to functioning (yet invalid -- WWPN) "
7122 * Set default initialization control block.
7124 memset(nv, 0, ha->nvram_size);
7125 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7126 nv->version = cpu_to_le16(ICB_VERSION);
7127 nv->frame_payload_size = 2048;
7128 nv->execution_throttle = cpu_to_le16(0xFFFF);
7129 nv->exchange_count = cpu_to_le16(0);
7130 nv->hard_address = cpu_to_le16(124);
7131 nv->port_name[0] = 0x21;
7132 nv->port_name[1] = 0x00 + ha->port_no + 1;
7133 nv->port_name[2] = 0x00;
7134 nv->port_name[3] = 0xe0;
7135 nv->port_name[4] = 0x8b;
7136 nv->port_name[5] = 0x1c;
7137 nv->port_name[6] = 0x55;
7138 nv->port_name[7] = 0x86;
7139 nv->node_name[0] = 0x20;
7140 nv->node_name[1] = 0x00;
7141 nv->node_name[2] = 0x00;
7142 nv->node_name[3] = 0xe0;
7143 nv->node_name[4] = 0x8b;
7144 nv->node_name[5] = 0x1c;
7145 nv->node_name[6] = 0x55;
7146 nv->node_name[7] = 0x86;
7147 qla24xx_nvram_wwn_from_ofw(vha, nv);
7148 nv->login_retry_count = cpu_to_le16(8);
7149 nv->interrupt_delay_timer = cpu_to_le16(0);
7150 nv->login_timeout = cpu_to_le16(0);
7151 nv->firmware_options_1 =
7152 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7153 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7154 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7155 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7156 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7157 nv->efi_parameters = cpu_to_le32(0);
7158 nv->reset_delay = 5;
7159 nv->max_luns_per_target = cpu_to_le16(128);
7160 nv->port_down_retry_count = cpu_to_le16(30);
7161 nv->link_down_timeout = cpu_to_le16(30);
7166 if (qla_tgt_mode_enabled(vha)) {
7167 /* Don't enable full login after initial LIP */
7168 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7169 /* Don't enable LIP full login for initiator */
7170 nv->host_p &= cpu_to_le32(~BIT_10);
7173 qlt_24xx_config_nvram_stage1(vha, nv);
7175 /* Reset Initialization control block */
7176 memset(icb, 0, ha->init_cb_size);
7178 /* Copy 1st segment. */
7179 dptr1 = (uint8_t *)icb;
7180 dptr2 = (uint8_t *)&nv->version;
7181 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7183 *dptr1++ = *dptr2++;
7185 icb->login_retry_count = nv->login_retry_count;
7186 icb->link_down_on_nos = nv->link_down_on_nos;
7188 /* Copy 2nd segment. */
7189 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7190 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7191 cnt = (uint8_t *)&icb->reserved_3 -
7192 (uint8_t *)&icb->interrupt_delay_timer;
7194 *dptr1++ = *dptr2++;
7195 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7197 * Setup driver NVRAM options.
7199 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7202 qlt_24xx_config_nvram_stage2(vha, icb);
7204 if (nv->host_p & cpu_to_le32(BIT_15)) {
7205 /* Use alternate WWN? */
7206 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7207 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7210 /* Prepare nodename */
7211 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7213 * Firmware will apply the following mask if the nodename was
7216 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7217 icb->node_name[0] &= 0xF0;
7220 /* Set host adapter parameters. */
7221 ha->flags.disable_risc_code_load = 0;
7222 ha->flags.enable_lip_reset = 0;
7223 ha->flags.enable_lip_full_login =
7224 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7225 ha->flags.enable_target_reset =
7226 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7227 ha->flags.enable_led_scheme = 0;
7228 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7230 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7231 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7233 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7234 sizeof(ha->fw_seriallink_options24));
7236 /* save HBA serial number */
7237 ha->serial0 = icb->port_name[5];
7238 ha->serial1 = icb->port_name[6];
7239 ha->serial2 = icb->port_name[7];
7240 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7241 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7243 icb->execution_throttle = cpu_to_le16(0xFFFF);
7245 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7247 /* Set minimum login_timeout to 4 seconds. */
7248 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7249 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7250 if (le16_to_cpu(nv->login_timeout) < 4)
7251 nv->login_timeout = cpu_to_le16(4);
7252 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7254 /* Set minimum RATOV to 100 tenths of a second. */
7257 ha->loop_reset_delay = nv->reset_delay;
7259 /* Link Down Timeout = 0:
7261 * When Port Down timer expires we will start returning
7262 * I/O's to OS with "DID_NO_CONNECT".
7264 * Link Down Timeout != 0:
7266 * The driver waits for the link to come up after link down
7267 * before returning I/Os to OS with "DID_NO_CONNECT".
7269 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7270 ha->loop_down_abort_time =
7271 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7273 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7274 ha->loop_down_abort_time =
7275 (LOOP_DOWN_TIME - ha->link_down_timeout);
7278 /* Need enough time to try and get the port back. */
7279 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7280 if (qlport_down_retry)
7281 ha->port_down_retry_count = qlport_down_retry;
7283 /* Set login_retry_count */
7284 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7285 if (ha->port_down_retry_count ==
7286 le16_to_cpu(nv->port_down_retry_count) &&
7287 ha->port_down_retry_count > 3)
7288 ha->login_retry_count = ha->port_down_retry_count;
7289 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7290 ha->login_retry_count = ha->port_down_retry_count;
7291 if (ql2xloginretrycount)
7292 ha->login_retry_count = ql2xloginretrycount;
7294 /* N2N: driver will initiate Login instead of FW */
7295 icb->firmware_options_3 |= BIT_8;
7298 if (!vha->flags.init_done) {
7299 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7300 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7301 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7302 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7304 icb->firmware_options_2 &= cpu_to_le32(
7305 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7306 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7307 ha->zio_mode = QLA_ZIO_MODE_6;
7309 ql_log(ql_log_info, vha, 0x006f,
7310 "ZIO mode %d enabled; timer delay (%d us).\n",
7311 ha->zio_mode, ha->zio_timer * 100);
7313 icb->firmware_options_2 |= cpu_to_le32(
7314 (uint32_t)ha->zio_mode);
7315 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7319 ql_log(ql_log_warn, vha, 0x0070,
7320 "NVRAM configuration failed.\n");
7326 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7327 struct qla27xx_image_status *image_status)
7329 ql_dbg(ql_dbg_init, vha, 0x018b,
7330 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7332 image_status->image_status_mask,
7333 le16_to_cpu(image_status->generation),
7334 image_status->ver_major,
7335 image_status->ver_minor,
7336 image_status->bitmap,
7337 le32_to_cpu(image_status->checksum),
7338 le32_to_cpu(image_status->signature));
7342 qla28xx_check_aux_image_status_signature(
7343 struct qla27xx_image_status *image_status)
7345 ulong signature = le32_to_cpu(image_status->signature);
7347 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7351 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7353 ulong signature = le32_to_cpu(image_status->signature);
7356 signature != QLA27XX_IMG_STATUS_SIGN &&
7357 signature != QLA28XX_IMG_STATUS_SIGN;
7361 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7363 uint32_t *p = (void *)image_status;
7364 uint n = sizeof(*image_status) / sizeof(*p);
7368 sum += le32_to_cpup(p);
7374 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7376 return aux->bitmap & bitmask ?
7377 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7381 qla28xx_component_status(
7382 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7384 active_regions->aux.board_config =
7385 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7387 active_regions->aux.vpd_nvram =
7388 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7390 active_regions->aux.npiv_config_0_1 =
7391 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7393 active_regions->aux.npiv_config_2_3 =
7394 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7398 qla27xx_compare_image_generation(
7399 struct qla27xx_image_status *pri_image_status,
7400 struct qla27xx_image_status *sec_image_status)
7402 /* calculate generation delta as uint16 (this accounts for wrap) */
7404 le16_to_cpu(pri_image_status->generation) -
7405 le16_to_cpu(sec_image_status->generation);
7407 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7413 qla28xx_get_aux_images(
7414 struct scsi_qla_host *vha, struct active_regions *active_regions)
7416 struct qla_hw_data *ha = vha->hw;
7417 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7418 bool valid_pri_image = false, valid_sec_image = false;
7419 bool active_pri_image = false, active_sec_image = false;
7421 if (!ha->flt_region_aux_img_status_pri) {
7422 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7423 goto check_sec_image;
7426 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7427 ha->flt_region_aux_img_status_pri,
7428 sizeof(pri_aux_image_status) >> 2);
7429 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7431 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7432 ql_dbg(ql_dbg_init, vha, 0x018b,
7433 "Primary aux image signature (%#x) not valid\n",
7434 le32_to_cpu(pri_aux_image_status.signature));
7435 goto check_sec_image;
7438 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7439 ql_dbg(ql_dbg_init, vha, 0x018c,
7440 "Primary aux image checksum failed\n");
7441 goto check_sec_image;
7444 valid_pri_image = true;
7446 if (pri_aux_image_status.image_status_mask & 1) {
7447 ql_dbg(ql_dbg_init, vha, 0x018d,
7448 "Primary aux image is active\n");
7449 active_pri_image = true;
7453 if (!ha->flt_region_aux_img_status_sec) {
7454 ql_dbg(ql_dbg_init, vha, 0x018a,
7455 "Secondary aux image not addressed\n");
7456 goto check_valid_image;
7459 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7460 ha->flt_region_aux_img_status_sec,
7461 sizeof(sec_aux_image_status) >> 2);
7462 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7464 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7465 ql_dbg(ql_dbg_init, vha, 0x018b,
7466 "Secondary aux image signature (%#x) not valid\n",
7467 le32_to_cpu(sec_aux_image_status.signature));
7468 goto check_valid_image;
7471 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7472 ql_dbg(ql_dbg_init, vha, 0x018c,
7473 "Secondary aux image checksum failed\n");
7474 goto check_valid_image;
7477 valid_sec_image = true;
7479 if (sec_aux_image_status.image_status_mask & 1) {
7480 ql_dbg(ql_dbg_init, vha, 0x018d,
7481 "Secondary aux image is active\n");
7482 active_sec_image = true;
7486 if (valid_pri_image && active_pri_image &&
7487 valid_sec_image && active_sec_image) {
7488 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7489 &sec_aux_image_status) >= 0) {
7490 qla28xx_component_status(active_regions,
7491 &pri_aux_image_status);
7493 qla28xx_component_status(active_regions,
7494 &sec_aux_image_status);
7496 } else if (valid_pri_image && active_pri_image) {
7497 qla28xx_component_status(active_regions, &pri_aux_image_status);
7498 } else if (valid_sec_image && active_sec_image) {
7499 qla28xx_component_status(active_regions, &sec_aux_image_status);
7502 ql_dbg(ql_dbg_init, vha, 0x018f,
7503 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7504 active_regions->aux.board_config,
7505 active_regions->aux.vpd_nvram,
7506 active_regions->aux.npiv_config_0_1,
7507 active_regions->aux.npiv_config_2_3);
7511 qla27xx_get_active_image(struct scsi_qla_host *vha,
7512 struct active_regions *active_regions)
7514 struct qla_hw_data *ha = vha->hw;
7515 struct qla27xx_image_status pri_image_status, sec_image_status;
7516 bool valid_pri_image = false, valid_sec_image = false;
7517 bool active_pri_image = false, active_sec_image = false;
7519 if (!ha->flt_region_img_status_pri) {
7520 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7521 goto check_sec_image;
7524 if (qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7525 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7528 goto check_sec_image;
7530 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7532 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7533 ql_dbg(ql_dbg_init, vha, 0x018b,
7534 "Primary image signature (%#x) not valid\n",
7535 le32_to_cpu(pri_image_status.signature));
7536 goto check_sec_image;
7539 if (qla27xx_image_status_checksum(&pri_image_status)) {
7540 ql_dbg(ql_dbg_init, vha, 0x018c,
7541 "Primary image checksum failed\n");
7542 goto check_sec_image;
7545 valid_pri_image = true;
7547 if (pri_image_status.image_status_mask & 1) {
7548 ql_dbg(ql_dbg_init, vha, 0x018d,
7549 "Primary image is active\n");
7550 active_pri_image = true;
7554 if (!ha->flt_region_img_status_sec) {
7555 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7556 goto check_valid_image;
7559 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7560 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7561 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7563 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7564 ql_dbg(ql_dbg_init, vha, 0x018b,
7565 "Secondary image signature (%#x) not valid\n",
7566 le32_to_cpu(sec_image_status.signature));
7567 goto check_valid_image;
7570 if (qla27xx_image_status_checksum(&sec_image_status)) {
7571 ql_dbg(ql_dbg_init, vha, 0x018c,
7572 "Secondary image checksum failed\n");
7573 goto check_valid_image;
7576 valid_sec_image = true;
7578 if (sec_image_status.image_status_mask & 1) {
7579 ql_dbg(ql_dbg_init, vha, 0x018d,
7580 "Secondary image is active\n");
7581 active_sec_image = true;
7585 if (valid_pri_image && active_pri_image)
7586 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7588 if (valid_sec_image && active_sec_image) {
7589 if (!active_regions->global ||
7590 qla27xx_compare_image_generation(
7591 &pri_image_status, &sec_image_status) < 0) {
7592 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7596 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7597 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7598 "default (boot/fw)" :
7599 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7601 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7602 "secondary" : "invalid",
7603 active_regions->global);
7606 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7609 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7610 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7614 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7618 uint templates, segments, fragment;
7623 uint32_t risc_addr, risc_size, risc_attr = 0;
7624 struct qla_hw_data *ha = vha->hw;
7625 struct req_que *req = ha->req_q_map[0];
7626 struct fwdt *fwdt = ha->fwdt;
7628 ql_dbg(ql_dbg_init, vha, 0x008b,
7629 "FW: Loading firmware from flash (%x).\n", faddr);
7631 dcode = (void *)req->ring;
7632 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7633 if (qla24xx_risc_firmware_invalid(dcode)) {
7634 ql_log(ql_log_fatal, vha, 0x008c,
7635 "Unable to verify the integrity of flash firmware "
7637 ql_log(ql_log_fatal, vha, 0x008d,
7638 "Firmware data: %08x %08x %08x %08x.\n",
7639 dcode[0], dcode[1], dcode[2], dcode[3]);
7641 return QLA_FUNCTION_FAILED;
7644 dcode = (void *)req->ring;
7646 segments = FA_RISC_CODE_SEGMENTS;
7647 for (j = 0; j < segments; j++) {
7648 ql_dbg(ql_dbg_init, vha, 0x008d,
7649 "-> Loading segment %u...\n", j);
7650 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7651 risc_addr = be32_to_cpu(dcode[2]);
7652 risc_size = be32_to_cpu(dcode[3]);
7654 *srisc_addr = risc_addr;
7655 risc_attr = be32_to_cpu(dcode[9]);
7658 dlen = ha->fw_transfer_size >> 2;
7659 for (fragment = 0; risc_size; fragment++) {
7660 if (dlen > risc_size)
7663 ql_dbg(ql_dbg_init, vha, 0x008e,
7664 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7665 fragment, risc_addr, faddr, dlen);
7666 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7667 for (i = 0; i < dlen; i++)
7668 dcode[i] = swab32(dcode[i]);
7670 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7672 ql_log(ql_log_fatal, vha, 0x008f,
7673 "-> Failed load firmware fragment %u.\n",
7675 return QLA_FUNCTION_FAILED;
7684 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7687 templates = (risc_attr & BIT_9) ? 2 : 1;
7688 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7689 for (j = 0; j < templates; j++, fwdt++) {
7691 vfree(fwdt->template);
7692 fwdt->template = NULL;
7695 dcode = (void *)req->ring;
7696 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7697 risc_size = be32_to_cpu(dcode[2]);
7698 ql_dbg(ql_dbg_init, vha, 0x0161,
7699 "-> fwdt%u template array at %#x (%#x dwords)\n",
7700 j, faddr, risc_size);
7701 if (!risc_size || !~risc_size) {
7702 ql_dbg(ql_dbg_init, vha, 0x0162,
7703 "-> fwdt%u failed to read array\n", j);
7707 /* skip header and ignore checksum */
7711 ql_dbg(ql_dbg_init, vha, 0x0163,
7712 "-> fwdt%u template allocate template %#x words...\n",
7714 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7715 if (!fwdt->template) {
7716 ql_log(ql_log_warn, vha, 0x0164,
7717 "-> fwdt%u failed allocate template.\n", j);
7721 dcode = fwdt->template;
7722 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7724 if (!qla27xx_fwdt_template_valid(dcode)) {
7725 ql_log(ql_log_warn, vha, 0x0165,
7726 "-> fwdt%u failed template validate\n", j);
7730 dlen = qla27xx_fwdt_template_size(dcode);
7731 ql_dbg(ql_dbg_init, vha, 0x0166,
7732 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7733 j, dlen, dlen / sizeof(*dcode));
7734 if (dlen > risc_size * sizeof(*dcode)) {
7735 ql_log(ql_log_warn, vha, 0x0167,
7736 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7737 j, dlen - risc_size * sizeof(*dcode));
7741 fwdt->length = dlen;
7742 ql_dbg(ql_dbg_init, vha, 0x0168,
7743 "-> fwdt%u loaded template ok\n", j);
7745 faddr += risc_size + 1;
7752 vfree(fwdt->template);
7753 fwdt->template = NULL;
7759 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7762 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7766 uint16_t *wcode, *fwcode;
7767 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7768 struct fw_blob *blob;
7769 struct qla_hw_data *ha = vha->hw;
7770 struct req_que *req = ha->req_q_map[0];
7772 /* Load firmware blob. */
7773 blob = qla2x00_request_firmware(vha);
7775 ql_log(ql_log_info, vha, 0x0083,
7776 "Firmware image unavailable.\n");
7777 ql_log(ql_log_info, vha, 0x0084,
7778 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7779 return QLA_FUNCTION_FAILED;
7784 wcode = (uint16_t *)req->ring;
7786 fwcode = (uint16_t *)blob->fw->data;
7789 /* Validate firmware image by checking version. */
7790 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7791 ql_log(ql_log_fatal, vha, 0x0085,
7792 "Unable to verify integrity of firmware image (%zd).\n",
7794 goto fail_fw_integrity;
7796 for (i = 0; i < 4; i++)
7797 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7798 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7799 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7800 wcode[2] == 0 && wcode[3] == 0)) {
7801 ql_log(ql_log_fatal, vha, 0x0086,
7802 "Unable to verify integrity of firmware image.\n");
7803 ql_log(ql_log_fatal, vha, 0x0087,
7804 "Firmware data: %04x %04x %04x %04x.\n",
7805 wcode[0], wcode[1], wcode[2], wcode[3]);
7806 goto fail_fw_integrity;
7810 while (*seg && rval == QLA_SUCCESS) {
7812 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7813 risc_size = be16_to_cpu(fwcode[3]);
7815 /* Validate firmware image size. */
7816 fwclen += risc_size * sizeof(uint16_t);
7817 if (blob->fw->size < fwclen) {
7818 ql_log(ql_log_fatal, vha, 0x0088,
7819 "Unable to verify integrity of firmware image "
7820 "(%zd).\n", blob->fw->size);
7821 goto fail_fw_integrity;
7825 while (risc_size > 0 && rval == QLA_SUCCESS) {
7826 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7827 if (wlen > risc_size)
7829 ql_dbg(ql_dbg_init, vha, 0x0089,
7830 "Loading risc segment@ risc addr %x number of "
7831 "words 0x%x.\n", risc_addr, wlen);
7833 for (i = 0; i < wlen; i++)
7834 wcode[i] = swab16(fwcode[i]);
7836 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7839 ql_log(ql_log_fatal, vha, 0x008a,
7840 "Failed to load segment %d of firmware.\n",
7857 return QLA_FUNCTION_FAILED;
7861 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7864 uint templates, segments, fragment;
7867 uint32_t risc_addr, risc_size, risc_attr = 0;
7870 struct fw_blob *blob;
7872 struct qla_hw_data *ha = vha->hw;
7873 struct req_que *req = ha->req_q_map[0];
7874 struct fwdt *fwdt = ha->fwdt;
7876 ql_dbg(ql_dbg_init, vha, 0x0090,
7877 "-> FW: Loading via request-firmware.\n");
7879 blob = qla2x00_request_firmware(vha);
7881 ql_log(ql_log_warn, vha, 0x0092,
7882 "-> Firmware file not found.\n");
7884 return QLA_FUNCTION_FAILED;
7887 fwcode = (void *)blob->fw->data;
7889 if (qla24xx_risc_firmware_invalid(dcode)) {
7890 ql_log(ql_log_fatal, vha, 0x0093,
7891 "Unable to verify integrity of firmware image (%zd).\n",
7893 ql_log(ql_log_fatal, vha, 0x0095,
7894 "Firmware data: %08x %08x %08x %08x.\n",
7895 dcode[0], dcode[1], dcode[2], dcode[3]);
7896 return QLA_FUNCTION_FAILED;
7899 dcode = (void *)req->ring;
7901 segments = FA_RISC_CODE_SEGMENTS;
7902 for (j = 0; j < segments; j++) {
7903 ql_dbg(ql_dbg_init, vha, 0x0096,
7904 "-> Loading segment %u...\n", j);
7905 risc_addr = be32_to_cpu(fwcode[2]);
7906 risc_size = be32_to_cpu(fwcode[3]);
7909 *srisc_addr = risc_addr;
7910 risc_attr = be32_to_cpu(fwcode[9]);
7913 dlen = ha->fw_transfer_size >> 2;
7914 for (fragment = 0; risc_size; fragment++) {
7915 if (dlen > risc_size)
7918 ql_dbg(ql_dbg_init, vha, 0x0097,
7919 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7920 fragment, risc_addr,
7921 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7924 for (i = 0; i < dlen; i++)
7925 dcode[i] = swab32(fwcode[i]);
7927 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7929 ql_log(ql_log_fatal, vha, 0x0098,
7930 "-> Failed load firmware fragment %u.\n",
7932 return QLA_FUNCTION_FAILED;
7941 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7944 templates = (risc_attr & BIT_9) ? 2 : 1;
7945 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
7946 for (j = 0; j < templates; j++, fwdt++) {
7948 vfree(fwdt->template);
7949 fwdt->template = NULL;
7952 risc_size = be32_to_cpu(fwcode[2]);
7953 ql_dbg(ql_dbg_init, vha, 0x0171,
7954 "-> fwdt%u template array at %#x (%#x dwords)\n",
7955 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
7957 if (!risc_size || !~risc_size) {
7958 ql_dbg(ql_dbg_init, vha, 0x0172,
7959 "-> fwdt%u failed to read array\n", j);
7963 /* skip header and ignore checksum */
7967 ql_dbg(ql_dbg_init, vha, 0x0173,
7968 "-> fwdt%u template allocate template %#x words...\n",
7970 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7971 if (!fwdt->template) {
7972 ql_log(ql_log_warn, vha, 0x0174,
7973 "-> fwdt%u failed allocate template.\n", j);
7977 dcode = fwdt->template;
7978 for (i = 0; i < risc_size; i++)
7979 dcode[i] = fwcode[i];
7981 if (!qla27xx_fwdt_template_valid(dcode)) {
7982 ql_log(ql_log_warn, vha, 0x0175,
7983 "-> fwdt%u failed template validate\n", j);
7987 dlen = qla27xx_fwdt_template_size(dcode);
7988 ql_dbg(ql_dbg_init, vha, 0x0176,
7989 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7990 j, dlen, dlen / sizeof(*dcode));
7991 if (dlen > risc_size * sizeof(*dcode)) {
7992 ql_log(ql_log_warn, vha, 0x0177,
7993 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7994 j, dlen - risc_size * sizeof(*dcode));
7998 fwdt->length = dlen;
7999 ql_dbg(ql_dbg_init, vha, 0x0178,
8000 "-> fwdt%u loaded template ok\n", j);
8002 fwcode += risc_size + 1;
8009 vfree(fwdt->template);
8010 fwdt->template = NULL;
8017 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8021 if (ql2xfwloadbin == 1)
8022 return qla81xx_load_risc(vha, srisc_addr);
8026 * 1) Firmware via request-firmware interface (.bin file).
8027 * 2) Firmware residing in flash.
8029 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8030 if (rval == QLA_SUCCESS)
8033 return qla24xx_load_risc_flash(vha, srisc_addr,
8034 vha->hw->flt_region_fw);
8038 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8041 struct qla_hw_data *ha = vha->hw;
8042 struct active_regions active_regions = { };
8044 if (ql2xfwloadbin == 2)
8047 /* FW Load priority:
8048 * 1) Firmware residing in flash.
8049 * 2) Firmware via request-firmware interface (.bin file).
8050 * 3) Golden-Firmware residing in flash -- (limited operation).
8053 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8054 goto try_primary_fw;
8056 qla27xx_get_active_image(vha, &active_regions);
8058 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8059 goto try_primary_fw;
8061 ql_dbg(ql_dbg_init, vha, 0x008b,
8062 "Loading secondary firmware image.\n");
8063 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8068 ql_dbg(ql_dbg_init, vha, 0x008b,
8069 "Loading primary firmware image.\n");
8070 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8075 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8076 if (!rval || !ha->flt_region_gold_fw)
8079 ql_log(ql_log_info, vha, 0x0099,
8080 "Attempting to fallback to golden firmware.\n");
8081 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8085 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8086 ha->flags.running_gold_fw = 1;
8091 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8094 struct qla_hw_data *ha = vha->hw;
8096 if (ha->flags.pci_channel_io_perm_failure)
8098 if (!IS_FWI2_CAPABLE(ha))
8100 if (!ha->fw_major_version)
8102 if (!ha->flags.fw_started)
8105 ret = qla2x00_stop_firmware(vha);
8106 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8107 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8108 ha->isp_ops->reset_chip(vha);
8109 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8111 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8113 ql_log(ql_log_info, vha, 0x8015,
8114 "Attempting retry of stop-firmware command.\n");
8115 ret = qla2x00_stop_firmware(vha);
8119 ha->flags.fw_init_done = 0;
8123 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8125 int rval = QLA_SUCCESS;
8127 uint16_t mb[MAILBOX_REGISTER_COUNT];
8128 struct qla_hw_data *ha = vha->hw;
8129 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8134 rval = qla2x00_fw_ready(base_vha);
8136 if (rval == QLA_SUCCESS) {
8137 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8138 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8141 vha->flags.management_server_logged_in = 0;
8143 /* Login to SNS first */
8144 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8146 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8147 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8148 ql_dbg(ql_dbg_init, vha, 0x0120,
8149 "Failed SNS login: loop_id=%x, rval2=%d\n",
8152 ql_dbg(ql_dbg_init, vha, 0x0103,
8153 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8154 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8155 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8156 return (QLA_FUNCTION_FAILED);
8159 atomic_set(&vha->loop_down_timer, 0);
8160 atomic_set(&vha->loop_state, LOOP_UP);
8161 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8162 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8163 rval = qla2x00_loop_resync(base_vha);
8168 /* 84XX Support **************************************************************/
8170 static LIST_HEAD(qla_cs84xx_list);
8171 static DEFINE_MUTEX(qla_cs84xx_mutex);
8173 static struct qla_chip_state_84xx *
8174 qla84xx_get_chip(struct scsi_qla_host *vha)
8176 struct qla_chip_state_84xx *cs84xx;
8177 struct qla_hw_data *ha = vha->hw;
8179 mutex_lock(&qla_cs84xx_mutex);
8181 /* Find any shared 84xx chip. */
8182 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8183 if (cs84xx->bus == ha->pdev->bus) {
8184 kref_get(&cs84xx->kref);
8189 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8193 kref_init(&cs84xx->kref);
8194 spin_lock_init(&cs84xx->access_lock);
8195 mutex_init(&cs84xx->fw_update_mutex);
8196 cs84xx->bus = ha->pdev->bus;
8198 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8200 mutex_unlock(&qla_cs84xx_mutex);
8205 __qla84xx_chip_release(struct kref *kref)
8207 struct qla_chip_state_84xx *cs84xx =
8208 container_of(kref, struct qla_chip_state_84xx, kref);
8210 mutex_lock(&qla_cs84xx_mutex);
8211 list_del(&cs84xx->list);
8212 mutex_unlock(&qla_cs84xx_mutex);
8217 qla84xx_put_chip(struct scsi_qla_host *vha)
8219 struct qla_hw_data *ha = vha->hw;
8222 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8226 qla84xx_init_chip(scsi_qla_host_t *vha)
8230 struct qla_hw_data *ha = vha->hw;
8232 mutex_lock(&ha->cs84xx->fw_update_mutex);
8234 rval = qla84xx_verify_chip(vha, status);
8236 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8238 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8242 /* 81XX Support **************************************************************/
8245 qla81xx_nvram_config(scsi_qla_host_t *vha)
8248 struct init_cb_81xx *icb;
8249 struct nvram_81xx *nv;
8251 uint8_t *dptr1, *dptr2;
8254 struct qla_hw_data *ha = vha->hw;
8256 struct active_regions active_regions = { };
8259 icb = (struct init_cb_81xx *)ha->init_cb;
8262 /* Determine NVRAM starting address. */
8263 ha->nvram_size = sizeof(*nv);
8264 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8265 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8266 ha->vpd_size = FA_VPD_SIZE_82XX;
8268 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8269 qla28xx_get_aux_images(vha, &active_regions);
8271 /* Get VPD data into cache */
8272 ha->vpd = ha->nvram + VPD_OFFSET;
8274 faddr = ha->flt_region_vpd;
8275 if (IS_QLA28XX(ha)) {
8276 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8277 faddr = ha->flt_region_vpd_sec;
8278 ql_dbg(ql_dbg_init, vha, 0x0110,
8279 "Loading %s nvram image.\n",
8280 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8281 "primary" : "secondary");
8283 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8285 /* Get NVRAM data into cache and calculate checksum. */
8286 faddr = ha->flt_region_nvram;
8287 if (IS_QLA28XX(ha)) {
8288 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8289 faddr = ha->flt_region_nvram_sec;
8291 ql_dbg(ql_dbg_init, vha, 0x0110,
8292 "Loading %s nvram image.\n",
8293 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8294 "primary" : "secondary");
8295 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8297 dptr = (uint32_t *)nv;
8298 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8299 chksum += le32_to_cpu(*dptr);
8301 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8302 "Contents of NVRAM:\n");
8303 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8304 nv, ha->nvram_size);
8306 /* Bad NVRAM data, set defaults parameters. */
8307 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8308 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8309 /* Reset NVRAM data. */
8310 ql_log(ql_log_info, vha, 0x0073,
8311 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8312 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8313 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8314 ql_log(ql_log_info, vha, 0x0074,
8315 "Falling back to functioning (yet invalid -- WWPN) "
8319 * Set default initialization control block.
8321 memset(nv, 0, ha->nvram_size);
8322 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8323 nv->version = cpu_to_le16(ICB_VERSION);
8324 nv->frame_payload_size = 2048;
8325 nv->execution_throttle = cpu_to_le16(0xFFFF);
8326 nv->exchange_count = cpu_to_le16(0);
8327 nv->port_name[0] = 0x21;
8328 nv->port_name[1] = 0x00 + ha->port_no + 1;
8329 nv->port_name[2] = 0x00;
8330 nv->port_name[3] = 0xe0;
8331 nv->port_name[4] = 0x8b;
8332 nv->port_name[5] = 0x1c;
8333 nv->port_name[6] = 0x55;
8334 nv->port_name[7] = 0x86;
8335 nv->node_name[0] = 0x20;
8336 nv->node_name[1] = 0x00;
8337 nv->node_name[2] = 0x00;
8338 nv->node_name[3] = 0xe0;
8339 nv->node_name[4] = 0x8b;
8340 nv->node_name[5] = 0x1c;
8341 nv->node_name[6] = 0x55;
8342 nv->node_name[7] = 0x86;
8343 nv->login_retry_count = cpu_to_le16(8);
8344 nv->interrupt_delay_timer = cpu_to_le16(0);
8345 nv->login_timeout = cpu_to_le16(0);
8346 nv->firmware_options_1 =
8347 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8348 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8349 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8350 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8351 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8352 nv->efi_parameters = cpu_to_le32(0);
8353 nv->reset_delay = 5;
8354 nv->max_luns_per_target = cpu_to_le16(128);
8355 nv->port_down_retry_count = cpu_to_le16(30);
8356 nv->link_down_timeout = cpu_to_le16(180);
8357 nv->enode_mac[0] = 0x00;
8358 nv->enode_mac[1] = 0xC0;
8359 nv->enode_mac[2] = 0xDD;
8360 nv->enode_mac[3] = 0x04;
8361 nv->enode_mac[4] = 0x05;
8362 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8367 if (IS_T10_PI_CAPABLE(ha))
8368 nv->frame_payload_size &= ~7;
8370 qlt_81xx_config_nvram_stage1(vha, nv);
8372 /* Reset Initialization control block */
8373 memset(icb, 0, ha->init_cb_size);
8375 /* Copy 1st segment. */
8376 dptr1 = (uint8_t *)icb;
8377 dptr2 = (uint8_t *)&nv->version;
8378 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8380 *dptr1++ = *dptr2++;
8382 icb->login_retry_count = nv->login_retry_count;
8384 /* Copy 2nd segment. */
8385 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8386 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8387 cnt = (uint8_t *)&icb->reserved_5 -
8388 (uint8_t *)&icb->interrupt_delay_timer;
8390 *dptr1++ = *dptr2++;
8392 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8393 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8394 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8395 icb->enode_mac[0] = 0x00;
8396 icb->enode_mac[1] = 0xC0;
8397 icb->enode_mac[2] = 0xDD;
8398 icb->enode_mac[3] = 0x04;
8399 icb->enode_mac[4] = 0x05;
8400 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8403 /* Use extended-initialization control block. */
8404 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8405 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8407 * Setup driver NVRAM options.
8409 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8412 qlt_81xx_config_nvram_stage2(vha, icb);
8414 /* Use alternate WWN? */
8415 if (nv->host_p & cpu_to_le32(BIT_15)) {
8416 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8417 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8420 /* Prepare nodename */
8421 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8423 * Firmware will apply the following mask if the nodename was
8426 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8427 icb->node_name[0] &= 0xF0;
8430 /* Set host adapter parameters. */
8431 ha->flags.disable_risc_code_load = 0;
8432 ha->flags.enable_lip_reset = 0;
8433 ha->flags.enable_lip_full_login =
8434 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8435 ha->flags.enable_target_reset =
8436 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8437 ha->flags.enable_led_scheme = 0;
8438 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8440 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8441 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8443 /* save HBA serial number */
8444 ha->serial0 = icb->port_name[5];
8445 ha->serial1 = icb->port_name[6];
8446 ha->serial2 = icb->port_name[7];
8447 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8448 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8450 icb->execution_throttle = cpu_to_le16(0xFFFF);
8452 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8454 /* Set minimum login_timeout to 4 seconds. */
8455 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8456 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8457 if (le16_to_cpu(nv->login_timeout) < 4)
8458 nv->login_timeout = cpu_to_le16(4);
8459 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8461 /* Set minimum RATOV to 100 tenths of a second. */
8464 ha->loop_reset_delay = nv->reset_delay;
8466 /* Link Down Timeout = 0:
8468 * When Port Down timer expires we will start returning
8469 * I/O's to OS with "DID_NO_CONNECT".
8471 * Link Down Timeout != 0:
8473 * The driver waits for the link to come up after link down
8474 * before returning I/Os to OS with "DID_NO_CONNECT".
8476 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8477 ha->loop_down_abort_time =
8478 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8480 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8481 ha->loop_down_abort_time =
8482 (LOOP_DOWN_TIME - ha->link_down_timeout);
8485 /* Need enough time to try and get the port back. */
8486 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8487 if (qlport_down_retry)
8488 ha->port_down_retry_count = qlport_down_retry;
8490 /* Set login_retry_count */
8491 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8492 if (ha->port_down_retry_count ==
8493 le16_to_cpu(nv->port_down_retry_count) &&
8494 ha->port_down_retry_count > 3)
8495 ha->login_retry_count = ha->port_down_retry_count;
8496 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8497 ha->login_retry_count = ha->port_down_retry_count;
8498 if (ql2xloginretrycount)
8499 ha->login_retry_count = ql2xloginretrycount;
8501 /* if not running MSI-X we need handshaking on interrupts */
8502 if (!vha->hw->flags.msix_enabled &&
8503 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8504 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8507 if (!vha->flags.init_done) {
8508 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8509 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8510 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8511 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8513 icb->firmware_options_2 &= cpu_to_le32(
8514 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8515 vha->flags.process_response_queue = 0;
8516 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8517 ha->zio_mode = QLA_ZIO_MODE_6;
8519 ql_log(ql_log_info, vha, 0x0075,
8520 "ZIO mode %d enabled; timer delay (%d us).\n",
8522 ha->zio_timer * 100);
8524 icb->firmware_options_2 |= cpu_to_le32(
8525 (uint32_t)ha->zio_mode);
8526 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8527 vha->flags.process_response_queue = 1;
8530 /* enable RIDA Format2 */
8531 icb->firmware_options_3 |= BIT_0;
8533 /* N2N: driver will initiate Login instead of FW */
8534 icb->firmware_options_3 |= BIT_8;
8536 /* Determine NVMe/FCP priority for target ports */
8537 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
8540 ql_log(ql_log_warn, vha, 0x0076,
8541 "NVRAM configuration failed.\n");
8547 qla82xx_restart_isp(scsi_qla_host_t *vha)
8550 struct qla_hw_data *ha = vha->hw;
8551 struct scsi_qla_host *vp;
8552 unsigned long flags;
8554 status = qla2x00_init_rings(vha);
8556 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8557 ha->flags.chip_reset_done = 1;
8559 status = qla2x00_fw_ready(vha);
8561 /* Issue a marker after FW becomes ready. */
8562 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8563 vha->flags.online = 1;
8564 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8567 /* if no cable then assume it's good */
8568 if ((vha->device_flags & DFLG_NO_CABLE))
8573 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8575 if (!atomic_read(&vha->loop_down_timer)) {
8577 * Issue marker command only when we are going
8578 * to start the I/O .
8580 vha->marker_needed = 1;
8583 ha->isp_ops->enable_intrs(ha);
8585 ha->isp_abort_cnt = 0;
8586 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8588 /* Update the firmware version */
8589 status = qla82xx_check_md_needed(vha);
8592 ha->flags.fce_enabled = 1;
8594 fce_calc_size(ha->fce_bufs));
8595 rval = qla2x00_enable_fce_trace(vha,
8596 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8599 ql_log(ql_log_warn, vha, 0x8001,
8600 "Unable to reinitialize FCE (%d).\n",
8602 ha->flags.fce_enabled = 0;
8607 memset(ha->eft, 0, EFT_SIZE);
8608 rval = qla2x00_enable_eft_trace(vha,
8609 ha->eft_dma, EFT_NUM_BUFFERS);
8611 ql_log(ql_log_warn, vha, 0x8010,
8612 "Unable to reinitialize EFT (%d).\n",
8619 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8620 "qla82xx_restart_isp succeeded.\n");
8622 spin_lock_irqsave(&ha->vport_slock, flags);
8623 list_for_each_entry(vp, &ha->vp_list, list) {
8625 atomic_inc(&vp->vref_count);
8626 spin_unlock_irqrestore(&ha->vport_slock, flags);
8628 qla2x00_vp_abort_isp(vp);
8630 spin_lock_irqsave(&ha->vport_slock, flags);
8631 atomic_dec(&vp->vref_count);
8634 spin_unlock_irqrestore(&ha->vport_slock, flags);
8637 ql_log(ql_log_warn, vha, 0x8016,
8638 "qla82xx_restart_isp **** FAILED ****.\n");
8645 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8647 struct qla_hw_data *ha = vha->hw;
8649 /* Hold status IOCBs until ABTS response received. */
8651 ha->fw_options[3] |= BIT_12;
8653 /* Set Retry FLOGI in case of P2P connection */
8654 if (ha->operating_mode == P2P) {
8655 ha->fw_options[2] |= BIT_3;
8656 ql_dbg(ql_dbg_disc, vha, 0x2103,
8657 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8658 __func__, ha->fw_options[2]);
8661 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8662 if (ql2xmvasynctoatio) {
8663 if (qla_tgt_mode_enabled(vha) ||
8664 qla_dual_mode_enabled(vha))
8665 ha->fw_options[2] |= BIT_11;
8667 ha->fw_options[2] &= ~BIT_11;
8670 if (qla_tgt_mode_enabled(vha) ||
8671 qla_dual_mode_enabled(vha)) {
8672 /* FW auto send SCSI status during */
8673 ha->fw_options[1] |= BIT_8;
8674 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8676 /* FW perform Exchange validation */
8677 ha->fw_options[2] |= BIT_4;
8679 ha->fw_options[1] &= ~BIT_8;
8680 ha->fw_options[10] &= 0x00ff;
8682 ha->fw_options[2] &= ~BIT_4;
8685 if (ql2xetsenable) {
8686 /* Enable ETS Burst. */
8687 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8688 ha->fw_options[2] |= BIT_9;
8691 ql_dbg(ql_dbg_init, vha, 0x00e9,
8692 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8693 __func__, ha->fw_options[1], ha->fw_options[2],
8694 ha->fw_options[3], vha->host->active_mode);
8696 qla2x00_set_fw_options(vha, ha->fw_options);
8700 * qla24xx_get_fcp_prio
8701 * Gets the fcp cmd priority value for the logged in port.
8702 * Looks for a match of the port descriptors within
8703 * each of the fcp prio config entries. If a match is found,
8704 * the tag (priority) value is returned.
8707 * vha = scsi host structure pointer.
8708 * fcport = port structure pointer.
8711 * non-zero (if found)
8718 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8721 uint8_t pid_match, wwn_match;
8723 uint32_t pid1, pid2;
8724 uint64_t wwn1, wwn2;
8725 struct qla_fcp_prio_entry *pri_entry;
8726 struct qla_hw_data *ha = vha->hw;
8728 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8732 entries = ha->fcp_prio_cfg->num_entries;
8733 pri_entry = &ha->fcp_prio_cfg->entry[0];
8735 for (i = 0; i < entries; i++) {
8736 pid_match = wwn_match = 0;
8738 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8743 /* check source pid for a match */
8744 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8745 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8746 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8747 if (pid1 == INVALID_PORT_ID)
8749 else if (pid1 == pid2)
8753 /* check destination pid for a match */
8754 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8755 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8756 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8757 if (pid1 == INVALID_PORT_ID)
8759 else if (pid1 == pid2)
8763 /* check source WWN for a match */
8764 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8765 wwn1 = wwn_to_u64(vha->port_name);
8766 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8767 if (wwn2 == (uint64_t)-1)
8769 else if (wwn1 == wwn2)
8773 /* check destination WWN for a match */
8774 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8775 wwn1 = wwn_to_u64(fcport->port_name);
8776 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8777 if (wwn2 == (uint64_t)-1)
8779 else if (wwn1 == wwn2)
8783 if (pid_match == 2 || wwn_match == 2) {
8784 /* Found a matching entry */
8785 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8786 priority = pri_entry->tag;
8797 * qla24xx_update_fcport_fcp_prio
8798 * Activates fcp priority for the logged in fc port
8801 * vha = scsi host structure pointer.
8802 * fcp = port structure pointer.
8805 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8811 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8817 if (fcport->port_type != FCT_TARGET ||
8818 fcport->loop_id == FC_NO_LOOP_ID)
8819 return QLA_FUNCTION_FAILED;
8821 priority = qla24xx_get_fcp_prio(vha, fcport);
8823 return QLA_FUNCTION_FAILED;
8825 if (IS_P3P_TYPE(vha->hw)) {
8826 fcport->fcp_prio = priority & 0xf;
8830 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8831 if (ret == QLA_SUCCESS) {
8832 if (fcport->fcp_prio != priority)
8833 ql_dbg(ql_dbg_user, vha, 0x709e,
8834 "Updated FCP_CMND priority - value=%d loop_id=%d "
8835 "port_id=%02x%02x%02x.\n", priority,
8836 fcport->loop_id, fcport->d_id.b.domain,
8837 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8838 fcport->fcp_prio = priority & 0xf;
8840 ql_dbg(ql_dbg_user, vha, 0x704f,
8841 "Unable to update FCP_CMND priority - ret=0x%x for "
8842 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8843 fcport->d_id.b.domain, fcport->d_id.b.area,
8844 fcport->d_id.b.al_pa);
8849 * qla24xx_update_all_fcp_prio
8850 * Activates fcp priority for all the logged in ports
8853 * ha = adapter block pointer.
8856 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8862 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8867 ret = QLA_FUNCTION_FAILED;
8868 /* We need to set priority for all logged in ports */
8869 list_for_each_entry(fcport, &vha->vp_fcports, list)
8870 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8875 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8876 int vp_idx, bool startqp)
8881 struct qla_hw_data *ha = vha->hw;
8882 uint16_t qpair_id = 0;
8883 struct qla_qpair *qpair = NULL;
8884 struct qla_msix_entry *msix;
8886 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8887 ql_log(ql_log_warn, vha, 0x00181,
8888 "FW/Driver is not multi-queue capable.\n");
8892 if (ql2xmqsupport || ql2xnvmeenable) {
8893 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8894 if (qpair == NULL) {
8895 ql_log(ql_log_warn, vha, 0x0182,
8896 "Failed to allocate memory for queue pair.\n");
8900 qpair->hw = vha->hw;
8902 qpair->qp_lock_ptr = &qpair->qp_lock;
8903 spin_lock_init(&qpair->qp_lock);
8904 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8906 /* Assign available que pair id */
8907 mutex_lock(&ha->mq_lock);
8908 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8909 if (ha->num_qpairs >= ha->max_qpairs) {
8910 mutex_unlock(&ha->mq_lock);
8911 ql_log(ql_log_warn, vha, 0x0183,
8912 "No resources to create additional q pair.\n");
8916 set_bit(qpair_id, ha->qpair_qid_map);
8917 ha->queue_pair_map[qpair_id] = qpair;
8918 qpair->id = qpair_id;
8919 qpair->vp_idx = vp_idx;
8920 qpair->fw_started = ha->flags.fw_started;
8921 INIT_LIST_HEAD(&qpair->hints_list);
8922 qpair->chip_reset = ha->base_qpair->chip_reset;
8923 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8924 qpair->enable_explicit_conf =
8925 ha->base_qpair->enable_explicit_conf;
8927 for (i = 0; i < ha->msix_count; i++) {
8928 msix = &ha->msix_entries[i];
8932 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8933 "Vector %x selected for qpair\n", msix->vector);
8937 ql_log(ql_log_warn, vha, 0x0184,
8938 "Out of MSI-X vectors!.\n");
8942 qpair->msix->in_use = 1;
8943 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8944 qpair->pdev = ha->pdev;
8945 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
8946 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8948 mutex_unlock(&ha->mq_lock);
8950 /* Create response queue first */
8951 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8953 ql_log(ql_log_warn, vha, 0x0185,
8954 "Failed to create response queue.\n");
8958 qpair->rsp = ha->rsp_q_map[rsp_id];
8960 /* Create request queue */
8961 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8964 ql_log(ql_log_warn, vha, 0x0186,
8965 "Failed to create request queue.\n");
8969 qpair->req = ha->req_q_map[req_id];
8970 qpair->rsp->req = qpair->req;
8971 qpair->rsp->qpair = qpair;
8972 /* init qpair to this cpu. Will adjust at run time. */
8973 qla_cpu_update(qpair, smp_processor_id());
8975 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8976 if (ha->fw_attributes & BIT_4)
8977 qpair->difdix_supported = 1;
8980 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8981 if (!qpair->srb_mempool) {
8982 ql_log(ql_log_warn, vha, 0xd036,
8983 "Failed to create srb mempool for qpair %d\n",
8988 /* Mark as online */
8991 if (!vha->flags.qpairs_available)
8992 vha->flags.qpairs_available = 1;
8994 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8995 "Request/Response queue pair created, id %d\n",
8997 ql_dbg(ql_dbg_init, vha, 0x0187,
8998 "Request/Response queue pair created, id %d\n",
9005 qla25xx_delete_rsp_que(vha, qpair->rsp);
9007 mutex_lock(&ha->mq_lock);
9008 qpair->msix->in_use = 0;
9009 list_del(&qpair->qp_list_elem);
9010 if (list_empty(&vha->qp_list))
9011 vha->flags.qpairs_available = 0;
9013 ha->queue_pair_map[qpair_id] = NULL;
9014 clear_bit(qpair_id, ha->qpair_qid_map);
9016 mutex_unlock(&ha->mq_lock);
9022 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9024 int ret = QLA_FUNCTION_FAILED;
9025 struct qla_hw_data *ha = qpair->hw;
9027 qpair->delete_in_progress = 1;
9029 ret = qla25xx_delete_req_que(vha, qpair->req);
9030 if (ret != QLA_SUCCESS)
9033 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9034 if (ret != QLA_SUCCESS)
9037 mutex_lock(&ha->mq_lock);
9038 ha->queue_pair_map[qpair->id] = NULL;
9039 clear_bit(qpair->id, ha->qpair_qid_map);
9041 list_del(&qpair->qp_list_elem);
9042 if (list_empty(&vha->qp_list)) {
9043 vha->flags.qpairs_available = 0;
9044 vha->flags.qpairs_req_created = 0;
9045 vha->flags.qpairs_rsp_created = 0;
9047 mempool_destroy(qpair->srb_mempool);
9049 mutex_unlock(&ha->mq_lock);