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;
53 WARN_ON(irqs_disabled());
54 iocb = &sp->u.iocb_cmd;
58 void qla2x00_sp_free(srb_t *sp)
60 struct srb_iocb *iocb = &sp->u.iocb_cmd;
62 del_timer(&iocb->timer);
66 /* Asynchronous Login/Logout Routines -------------------------------------- */
69 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
72 struct qla_hw_data *ha = vha->hw;
74 /* Firmware should use switch negotiated r_a_tov for timeout. */
75 tmo = ha->r_a_tov / 10 * 2;
77 tmo = FX00_DEF_RATOV * 2;
78 } else if (!IS_FWI2_CAPABLE(ha)) {
80 * Except for earlier ISPs where the timeout is seeded from the
81 * initialization control block.
83 tmo = ha->login_timeout;
88 static void qla24xx_abort_iocb_timeout(void *data)
91 struct srb_iocb *abt = &sp->u.iocb_cmd;
92 struct qla_qpair *qpair = sp->qpair;
97 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
98 "Abort timeout - cmd hdl=%x, cmd type=%x hdl=%x, type=%x\n",
99 sp->cmd_sp->handle, sp->cmd_sp->type,
100 sp->handle, sp->type);
102 ql_dbg(ql_dbg_async, sp->vha, 0x507c,
103 "Abort timeout 2 - hdl=%x, type=%x\n",
104 sp->handle, sp->type);
106 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
107 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
108 if (sp->cmd_sp && (qpair->req->outstanding_cmds[handle] ==
110 qpair->req->outstanding_cmds[handle] = NULL;
112 /* removing the abort */
113 if (qpair->req->outstanding_cmds[handle] == sp) {
114 qpair->req->outstanding_cmds[handle] = NULL;
118 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
121 sp->cmd_sp->done(sp->cmd_sp, QLA_OS_TIMER_EXPIRED);
123 abt->u.abt.comp_status = CS_TIMEOUT;
124 sp->done(sp, QLA_OS_TIMER_EXPIRED);
127 static void qla24xx_abort_sp_done(srb_t *sp, int res)
129 struct srb_iocb *abt = &sp->u.iocb_cmd;
131 del_timer(&sp->u.iocb_cmd.timer);
132 if (sp->flags & SRB_WAKEUP_ON_COMP)
133 complete(&abt->u.abt.comp);
138 int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
140 scsi_qla_host_t *vha = cmd_sp->vha;
141 struct srb_iocb *abt_iocb;
143 int rval = QLA_FUNCTION_FAILED;
145 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
150 abt_iocb = &sp->u.iocb_cmd;
151 sp->type = SRB_ABT_CMD;
153 sp->qpair = cmd_sp->qpair;
156 sp->flags = SRB_WAKEUP_ON_COMP;
158 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
159 init_completion(&abt_iocb->u.abt.comp);
160 /* FW can send 2 x ABTS's timeout/20s */
161 qla2x00_init_timer(sp, 42);
163 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
164 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
166 sp->done = qla24xx_abort_sp_done;
168 ql_dbg(ql_dbg_async, vha, 0x507c,
169 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
172 rval = qla2x00_start_sp(sp);
173 if (rval != QLA_SUCCESS) {
179 wait_for_completion(&abt_iocb->u.abt.comp);
180 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
181 QLA_SUCCESS : QLA_FUNCTION_FAILED;
189 qla2x00_async_iocb_timeout(void *data)
192 fc_port_t *fcport = sp->fcport;
193 struct srb_iocb *lio = &sp->u.iocb_cmd;
198 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
199 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
200 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
202 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
204 pr_info("Async-%s timeout - hdl=%x.\n",
205 sp->name, sp->handle);
210 rc = qla24xx_async_abort_cmd(sp, false);
212 /* Retry as needed. */
213 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
214 lio->u.logio.data[1] =
215 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
216 QLA_LOGIO_LOGIN_RETRIED : 0;
217 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
218 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
220 if (sp->qpair->req->outstanding_cmds[h] ==
222 sp->qpair->req->outstanding_cmds[h] =
227 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
228 sp->done(sp, QLA_FUNCTION_TIMEOUT);
232 case SRB_CT_PTHRU_CMD:
239 rc = qla24xx_async_abort_cmd(sp, false);
241 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
242 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
244 if (sp->qpair->req->outstanding_cmds[h] ==
246 sp->qpair->req->outstanding_cmds[h] =
251 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
252 sp->done(sp, QLA_FUNCTION_TIMEOUT);
258 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
260 struct scsi_qla_host *vha = sp->vha;
261 struct srb_iocb *lio = &sp->u.iocb_cmd;
264 ql_dbg(ql_dbg_disc, vha, 0x20dd,
265 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
267 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
269 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
270 memset(&ea, 0, sizeof(ea));
271 ea.fcport = sp->fcport;
272 ea.data[0] = lio->u.logio.data[0];
273 ea.data[1] = lio->u.logio.data[1];
274 ea.iop[0] = lio->u.logio.iop[0];
275 ea.iop[1] = lio->u.logio.iop[1];
277 qla24xx_handle_plogi_done_event(vha, &ea);
284 fcport_is_smaller(fc_port_t *fcport)
286 if (wwn_to_u64(fcport->port_name) <
287 wwn_to_u64(fcport->vha->port_name))
294 fcport_is_bigger(fc_port_t *fcport)
296 return !fcport_is_smaller(fcport);
300 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
304 struct srb_iocb *lio;
305 int rval = QLA_FUNCTION_FAILED;
307 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
308 fcport->loop_id == FC_NO_LOOP_ID) {
309 ql_log(ql_log_warn, vha, 0xffff,
310 "%s: %8phC - not sending command.\n",
311 __func__, fcport->port_name);
315 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
319 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
320 fcport->flags |= FCF_ASYNC_SENT;
321 fcport->logout_completed = 0;
323 sp->type = SRB_LOGIN_CMD;
325 sp->gen1 = fcport->rscn_gen;
326 sp->gen2 = fcport->login_gen;
328 lio = &sp->u.iocb_cmd;
329 lio->timeout = qla2x00_async_iocb_timeout;
330 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
332 sp->done = qla2x00_async_login_sp_done;
333 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
334 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
336 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
338 if (NVME_TARGET(vha->hw, fcport))
339 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
341 ql_dbg(ql_dbg_disc, vha, 0x2072,
342 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
343 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
344 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
345 fcport->login_retry);
347 rval = qla2x00_start_sp(sp);
348 if (rval != QLA_SUCCESS) {
349 fcport->flags |= FCF_LOGIN_NEEDED;
350 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
358 fcport->flags &= ~FCF_ASYNC_SENT;
360 fcport->flags &= ~FCF_ASYNC_ACTIVE;
364 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
366 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
367 sp->fcport->login_gen++;
368 qlt_logo_completion_handler(sp->fcport, res);
373 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
376 struct srb_iocb *lio;
377 int rval = QLA_FUNCTION_FAILED;
379 fcport->flags |= FCF_ASYNC_SENT;
380 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
384 sp->type = SRB_LOGOUT_CMD;
387 lio = &sp->u.iocb_cmd;
388 lio->timeout = qla2x00_async_iocb_timeout;
389 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
391 sp->done = qla2x00_async_logout_sp_done;
393 ql_dbg(ql_dbg_disc, vha, 0x2070,
394 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
395 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
396 fcport->d_id.b.area, fcport->d_id.b.al_pa,
399 rval = qla2x00_start_sp(sp);
400 if (rval != QLA_SUCCESS)
407 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
412 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
415 fcport->flags &= ~FCF_ASYNC_ACTIVE;
416 /* Don't re-login in target mode */
417 if (!fcport->tgt_session)
418 qla2x00_mark_device_lost(vha, fcport, 1);
419 qlt_logo_completion_handler(fcport, data[0]);
422 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
424 struct srb_iocb *lio = &sp->u.iocb_cmd;
425 struct scsi_qla_host *vha = sp->vha;
427 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
428 if (!test_bit(UNLOADING, &vha->dpc_flags))
429 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
435 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
438 struct srb_iocb *lio;
441 rval = QLA_FUNCTION_FAILED;
442 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
446 sp->type = SRB_PRLO_CMD;
449 lio = &sp->u.iocb_cmd;
450 lio->timeout = qla2x00_async_iocb_timeout;
451 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
453 sp->done = qla2x00_async_prlo_sp_done;
455 ql_dbg(ql_dbg_disc, vha, 0x2070,
456 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
457 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
458 fcport->d_id.b.area, fcport->d_id.b.al_pa);
460 rval = qla2x00_start_sp(sp);
461 if (rval != QLA_SUCCESS)
469 fcport->flags &= ~FCF_ASYNC_ACTIVE;
474 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
476 struct fc_port *fcport = ea->fcport;
478 ql_dbg(ql_dbg_disc, vha, 0x20d2,
479 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
480 __func__, fcport->port_name, fcport->disc_state,
481 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
482 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
484 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
487 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
488 ql_dbg(ql_dbg_disc, vha, 0x2066,
489 "%s %8phC: adisc fail: post delete\n",
490 __func__, ea->fcport->port_name);
491 /* deleted = 0 & logout_on_delete = force fw cleanup */
493 fcport->logout_on_delete = 1;
494 qlt_schedule_sess_for_deletion(ea->fcport);
498 if (ea->fcport->disc_state == DSC_DELETE_PEND)
501 if (ea->sp->gen2 != ea->fcport->login_gen) {
502 /* target side must have changed it. */
503 ql_dbg(ql_dbg_disc, vha, 0x20d3,
504 "%s %8phC generation changed\n",
505 __func__, ea->fcport->port_name);
507 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
508 qla_rscn_replay(fcport);
509 qlt_schedule_sess_for_deletion(fcport);
513 __qla24xx_handle_gpdb_event(vha, ea);
516 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
518 struct qla_work_evt *e;
520 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
522 return QLA_FUNCTION_FAILED;
524 e->u.fcport.fcport = fcport;
525 fcport->flags |= FCF_ASYNC_ACTIVE;
526 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_PEND);
527 return qla2x00_post_work(vha, e);
530 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
532 struct scsi_qla_host *vha = sp->vha;
534 struct srb_iocb *lio = &sp->u.iocb_cmd;
536 ql_dbg(ql_dbg_disc, vha, 0x2066,
537 "Async done-%s res %x %8phC\n",
538 sp->name, res, sp->fcport->port_name);
540 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
542 memset(&ea, 0, sizeof(ea));
544 ea.data[0] = lio->u.logio.data[0];
545 ea.data[1] = lio->u.logio.data[1];
546 ea.iop[0] = lio->u.logio.iop[0];
547 ea.iop[1] = lio->u.logio.iop[1];
548 ea.fcport = sp->fcport;
551 qla24xx_handle_adisc_event(vha, &ea);
557 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
561 struct srb_iocb *lio;
562 int rval = QLA_FUNCTION_FAILED;
564 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
567 fcport->flags |= FCF_ASYNC_SENT;
568 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
572 sp->type = SRB_ADISC_CMD;
575 lio = &sp->u.iocb_cmd;
576 lio->timeout = qla2x00_async_iocb_timeout;
577 sp->gen1 = fcport->rscn_gen;
578 sp->gen2 = fcport->login_gen;
579 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
581 sp->done = qla2x00_async_adisc_sp_done;
582 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
583 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
585 ql_dbg(ql_dbg_disc, vha, 0x206f,
586 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
587 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
589 rval = qla2x00_start_sp(sp);
590 if (rval != QLA_SUCCESS)
598 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
599 qla2x00_post_async_adisc_work(vha, fcport, data);
603 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
605 struct qla_hw_data *ha = vha->hw;
607 if (IS_FWI2_CAPABLE(ha))
608 return loop_id > NPH_LAST_HANDLE;
610 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
611 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
615 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
616 * @vha: adapter state pointer.
617 * @dev: port structure pointer.
620 * qla2x00 local function return status code.
625 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
628 struct qla_hw_data *ha = vha->hw;
629 unsigned long flags = 0;
633 spin_lock_irqsave(&ha->vport_slock, flags);
635 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
636 if (dev->loop_id >= LOOPID_MAP_SIZE ||
637 qla2x00_is_reserved_id(vha, dev->loop_id)) {
638 dev->loop_id = FC_NO_LOOP_ID;
639 rval = QLA_FUNCTION_FAILED;
641 set_bit(dev->loop_id, ha->loop_id_map);
643 spin_unlock_irqrestore(&ha->vport_slock, flags);
645 if (rval == QLA_SUCCESS)
646 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
647 "Assigning new loopid=%x, portid=%x.\n",
648 dev->loop_id, dev->d_id.b24);
650 ql_log(ql_log_warn, dev->vha, 0x2087,
651 "No loop_id's available, portid=%x.\n",
657 void qla2x00_clear_loop_id(fc_port_t *fcport)
659 struct qla_hw_data *ha = fcport->vha->hw;
661 if (fcport->loop_id == FC_NO_LOOP_ID ||
662 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
665 clear_bit(fcport->loop_id, ha->loop_id_map);
666 fcport->loop_id = FC_NO_LOOP_ID;
669 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
670 struct event_arg *ea)
672 fc_port_t *fcport, *conflict_fcport;
673 struct get_name_list_extended *e;
674 u16 i, n, found = 0, loop_id;
678 u8 current_login_state, nvme_cls;
681 ql_dbg(ql_dbg_disc, vha, 0xffff,
682 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
683 __func__, fcport->port_name, fcport->disc_state,
684 fcport->fw_login_state, ea->rc,
685 fcport->login_gen, fcport->last_login_gen,
686 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
688 if (fcport->disc_state == DSC_DELETE_PEND)
691 if (ea->rc) { /* rval */
692 if (fcport->login_retry == 0) {
693 ql_dbg(ql_dbg_disc, vha, 0x20de,
694 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
695 fcport->port_name, fcport->login_retry);
700 if (fcport->last_rscn_gen != fcport->rscn_gen) {
701 qla_rscn_replay(fcport);
702 qlt_schedule_sess_for_deletion(fcport);
704 } else if (fcport->last_login_gen != fcport->login_gen) {
705 ql_dbg(ql_dbg_disc, vha, 0x20e0,
706 "%s %8phC login gen changed\n",
707 __func__, fcport->port_name);
711 n = ea->data[0] / sizeof(struct get_name_list_extended);
713 ql_dbg(ql_dbg_disc, vha, 0x20e1,
714 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
715 __func__, __LINE__, fcport->port_name, n,
716 fcport->d_id.b.domain, fcport->d_id.b.area,
717 fcport->d_id.b.al_pa, fcport->loop_id);
719 for (i = 0; i < n; i++) {
721 wwn = wwn_to_u64(e->port_name);
722 id.b.domain = e->port_id[2];
723 id.b.area = e->port_id[1];
724 id.b.al_pa = e->port_id[0];
727 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
730 if (IS_SW_RESV_ADDR(id))
735 loop_id = le16_to_cpu(e->nport_handle);
736 loop_id = (loop_id & 0x7fff);
737 nvme_cls = e->current_login_state >> 4;
738 current_login_state = e->current_login_state & 0xf;
740 if (PRLI_PHASE(nvme_cls)) {
741 current_login_state = nvme_cls;
742 fcport->fc4_type &= ~FS_FC4TYPE_FCP;
743 fcport->fc4_type |= FS_FC4TYPE_NVME;
744 } else if (PRLI_PHASE(current_login_state)) {
745 fcport->fc4_type |= FS_FC4TYPE_FCP;
746 fcport->fc4_type &= ~FS_FC4TYPE_NVME;
749 ql_dbg(ql_dbg_disc, vha, 0x20e2,
750 "%s found %8phC CLS [%x|%x] fc4_type %d ID[%06x|%06x] lid[%d|%d]\n",
751 __func__, fcport->port_name,
752 e->current_login_state, fcport->fw_login_state,
753 fcport->fc4_type, id.b24, fcport->d_id.b24,
754 loop_id, fcport->loop_id);
756 switch (fcport->disc_state) {
757 case DSC_DELETE_PEND:
761 if ((id.b24 != fcport->d_id.b24 &&
763 fcport->loop_id != FC_NO_LOOP_ID) ||
764 (fcport->loop_id != FC_NO_LOOP_ID &&
765 fcport->loop_id != loop_id)) {
766 ql_dbg(ql_dbg_disc, vha, 0x20e3,
767 "%s %d %8phC post del sess\n",
768 __func__, __LINE__, fcport->port_name);
769 if (fcport->n2n_flag)
770 fcport->d_id.b24 = 0;
771 qlt_schedule_sess_for_deletion(fcport);
777 fcport->loop_id = loop_id;
778 if (fcport->n2n_flag)
779 fcport->d_id.b24 = id.b24;
781 wwn = wwn_to_u64(fcport->port_name);
782 qlt_find_sess_invalidate_other(vha, wwn,
783 id, loop_id, &conflict_fcport);
785 if (conflict_fcport) {
787 * Another share fcport share the same loop_id &
788 * nport id. Conflict fcport needs to finish
789 * cleanup before this fcport can proceed to login.
791 conflict_fcport->conflict = fcport;
792 fcport->login_pause = 1;
795 switch (vha->hw->current_topology) {
797 switch (current_login_state) {
798 case DSC_LS_PRLI_COMP:
799 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
800 vha, 0x20e4, "%s %d %8phC post gpdb\n",
801 __func__, __LINE__, fcport->port_name);
803 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
804 fcport->port_type = FCT_INITIATOR;
806 fcport->port_type = FCT_TARGET;
807 data[0] = data[1] = 0;
808 qla2x00_post_async_adisc_work(vha, fcport,
811 case DSC_LS_PORT_UNAVAIL:
813 if (fcport->loop_id == FC_NO_LOOP_ID) {
814 qla2x00_find_new_loop_id(vha, fcport);
815 fcport->fw_login_state =
818 ql_dbg(ql_dbg_disc, vha, 0x20e5,
819 "%s %d %8phC\n", __func__, __LINE__,
821 qla24xx_fcport_handle_login(vha, fcport);
826 fcport->fw_login_state = current_login_state;
828 switch (current_login_state) {
829 case DSC_LS_PRLI_PEND:
831 * In the middle of PRLI. Let it finish.
832 * Allow relogin code to recheck state again
833 * with GNL. Push disc_state back to DELETED
834 * so GNL can go out again
836 qla2x00_set_fcport_disc_state(fcport,
839 case DSC_LS_PRLI_COMP:
840 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
841 fcport->port_type = FCT_INITIATOR;
843 fcport->port_type = FCT_TARGET;
845 data[0] = data[1] = 0;
846 qla2x00_post_async_adisc_work(vha, fcport,
849 case DSC_LS_PLOGI_COMP:
850 if (fcport_is_bigger(fcport)) {
851 /* local adapter is smaller */
852 if (fcport->loop_id != FC_NO_LOOP_ID)
853 qla2x00_clear_loop_id(fcport);
855 fcport->loop_id = loop_id;
856 qla24xx_fcport_handle_login(vha,
862 if (fcport_is_smaller(fcport)) {
863 /* local adapter is bigger */
864 if (fcport->loop_id != FC_NO_LOOP_ID)
865 qla2x00_clear_loop_id(fcport);
867 fcport->loop_id = loop_id;
868 qla24xx_fcport_handle_login(vha,
874 } /* switch (ha->current_topology) */
878 switch (vha->hw->current_topology) {
881 for (i = 0; i < n; i++) {
883 id.b.domain = e->port_id[0];
884 id.b.area = e->port_id[1];
885 id.b.al_pa = e->port_id[2];
887 loop_id = le16_to_cpu(e->nport_handle);
889 if (fcport->d_id.b24 == id.b24) {
891 qla2x00_find_fcport_by_wwpn(vha,
893 if (conflict_fcport) {
894 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
896 "%s %d %8phC post del sess\n",
898 conflict_fcport->port_name);
899 qlt_schedule_sess_for_deletion
904 * FW already picked this loop id for
907 if (fcport->loop_id == loop_id)
908 fcport->loop_id = FC_NO_LOOP_ID;
910 qla24xx_fcport_handle_login(vha, fcport);
913 qla2x00_set_fcport_disc_state(fcport, DSC_DELETED);
914 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
915 if (fcport->n2n_link_reset_cnt < 2) {
916 fcport->n2n_link_reset_cnt++;
918 * remote port is not sending PLOGI.
919 * Reset link to kick start his state
922 set_bit(N2N_LINK_RESET,
925 if (fcport->n2n_chip_reset < 1) {
926 ql_log(ql_log_info, vha, 0x705d,
927 "Chip reset to bring laser down");
928 set_bit(ISP_ABORT_NEEDED,
930 fcport->n2n_chip_reset++;
932 ql_log(ql_log_info, vha, 0x705d,
933 "Remote port %8ph is not coming back\n",
935 fcport->scan_state = 0;
938 qla2xxx_wake_dpc(vha);
941 * report port suppose to do PLOGI. Give him
942 * more time. FW will catch it.
944 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
953 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
955 struct scsi_qla_host *vha = sp->vha;
957 struct fc_port *fcport = NULL, *tf;
958 u16 i, n = 0, loop_id;
960 struct get_name_list_extended *e;
965 ql_dbg(ql_dbg_disc, vha, 0x20e7,
966 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
967 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
968 sp->u.iocb_cmd.u.mbx.in_mb[2]);
970 if (res == QLA_FUNCTION_TIMEOUT)
973 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
974 memset(&ea, 0, sizeof(ea));
978 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
979 sizeof(struct get_name_list_extended)) {
980 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
981 sizeof(struct get_name_list_extended);
982 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
985 for (i = 0; i < n; i++) {
987 loop_id = le16_to_cpu(e->nport_handle);
988 /* mask out reserve bit */
989 loop_id = (loop_id & 0x7fff);
990 set_bit(loop_id, vha->hw->loop_id_map);
991 wwn = wwn_to_u64(e->port_name);
993 ql_dbg(ql_dbg_disc, vha, 0x20e8,
994 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
995 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
996 e->port_id[0], e->current_login_state, e->last_login_state,
1000 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1004 if (!list_empty(&vha->gnl.fcports))
1005 list_splice_init(&vha->gnl.fcports, &h);
1006 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1008 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
1009 list_del_init(&fcport->gnl_entry);
1010 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1011 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1012 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1015 qla24xx_handle_gnl_done_event(vha, &ea);
1018 /* create new fcport if fw has knowledge of new sessions */
1019 for (i = 0; i < n; i++) {
1024 wwn = wwn_to_u64(e->port_name);
1027 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1028 if (!memcmp((u8 *)&wwn, fcport->port_name,
1035 id.b.domain = e->port_id[2];
1036 id.b.area = e->port_id[1];
1037 id.b.al_pa = e->port_id[0];
1040 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1041 ql_dbg(ql_dbg_disc, vha, 0x2065,
1042 "%s %d %8phC %06x post new sess\n",
1043 __func__, __LINE__, (u8 *)&wwn, id.b24);
1044 wwnn = wwn_to_u64(e->node_name);
1045 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1046 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
1050 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1052 if (!list_empty(&vha->gnl.fcports)) {
1054 list_for_each_entry_safe(fcport, tf, &vha->gnl.fcports,
1056 list_del_init(&fcport->gnl_entry);
1057 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1058 if (qla24xx_post_gnl_work(vha, fcport) == QLA_SUCCESS)
1062 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1067 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1070 struct srb_iocb *mbx;
1071 int rval = QLA_FUNCTION_FAILED;
1072 unsigned long flags;
1075 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1078 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1079 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1081 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1082 fcport->flags |= FCF_ASYNC_SENT;
1083 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1084 fcport->last_rscn_gen = fcport->rscn_gen;
1085 fcport->last_login_gen = fcport->login_gen;
1087 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1088 if (vha->gnl.sent) {
1089 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1093 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1095 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1099 sp->type = SRB_MB_IOCB;
1100 sp->name = "gnlist";
1101 sp->gen1 = fcport->rscn_gen;
1102 sp->gen2 = fcport->login_gen;
1104 mbx = &sp->u.iocb_cmd;
1105 mbx->timeout = qla2x00_async_iocb_timeout;
1106 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1108 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1109 mb[0] = MBC_PORT_NODE_NAME_LIST;
1110 mb[1] = BIT_2 | BIT_3;
1111 mb[2] = MSW(vha->gnl.ldma);
1112 mb[3] = LSW(vha->gnl.ldma);
1113 mb[6] = MSW(MSD(vha->gnl.ldma));
1114 mb[7] = LSW(MSD(vha->gnl.ldma));
1115 mb[8] = vha->gnl.size;
1116 mb[9] = vha->vp_idx;
1118 sp->done = qla24xx_async_gnl_sp_done;
1120 ql_dbg(ql_dbg_disc, vha, 0x20da,
1121 "Async-%s - OUT WWPN %8phC hndl %x\n",
1122 sp->name, fcport->port_name, sp->handle);
1124 rval = qla2x00_start_sp(sp);
1125 if (rval != QLA_SUCCESS)
1133 fcport->flags &= ~(FCF_ASYNC_ACTIVE | FCF_ASYNC_SENT);
1137 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1139 struct qla_work_evt *e;
1141 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1143 return QLA_FUNCTION_FAILED;
1145 e->u.fcport.fcport = fcport;
1146 fcport->flags |= FCF_ASYNC_ACTIVE;
1147 return qla2x00_post_work(vha, e);
1150 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1152 struct scsi_qla_host *vha = sp->vha;
1153 struct qla_hw_data *ha = vha->hw;
1154 fc_port_t *fcport = sp->fcport;
1155 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1156 struct event_arg ea;
1158 ql_dbg(ql_dbg_disc, vha, 0x20db,
1159 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1160 sp->name, res, fcport->port_name, mb[1], mb[2]);
1162 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1164 if (res == QLA_FUNCTION_TIMEOUT)
1167 memset(&ea, 0, sizeof(ea));
1171 qla24xx_handle_gpdb_event(vha, &ea);
1174 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1175 sp->u.iocb_cmd.u.mbx.in_dma);
1180 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1182 struct qla_work_evt *e;
1184 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1186 return QLA_FUNCTION_FAILED;
1188 e->u.fcport.fcport = fcport;
1190 return qla2x00_post_work(vha, e);
1193 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1195 struct scsi_qla_host *vha = sp->vha;
1196 struct srb_iocb *lio = &sp->u.iocb_cmd;
1197 struct event_arg ea;
1199 ql_dbg(ql_dbg_disc, vha, 0x2129,
1200 "%s %8phC res %d \n", __func__,
1201 sp->fcport->port_name, res);
1203 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1205 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1206 memset(&ea, 0, sizeof(ea));
1207 ea.fcport = sp->fcport;
1208 ea.data[0] = lio->u.logio.data[0];
1209 ea.data[1] = lio->u.logio.data[1];
1210 ea.iop[0] = lio->u.logio.iop[0];
1211 ea.iop[1] = lio->u.logio.iop[1];
1214 qla24xx_handle_prli_done_event(vha, &ea);
1221 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1224 struct srb_iocb *lio;
1225 int rval = QLA_FUNCTION_FAILED;
1227 if (!vha->flags.online) {
1228 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1229 __func__, __LINE__, fcport->port_name);
1233 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1234 fcport->fw_login_state == DSC_LS_PRLI_PEND) &&
1235 qla_dual_mode_enabled(vha)) {
1236 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s %d %8phC exit\n",
1237 __func__, __LINE__, fcport->port_name);
1241 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1245 fcport->flags |= FCF_ASYNC_SENT;
1246 fcport->logout_completed = 0;
1248 sp->type = SRB_PRLI_CMD;
1251 lio = &sp->u.iocb_cmd;
1252 lio->timeout = qla2x00_async_iocb_timeout;
1253 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1255 sp->done = qla2x00_async_prli_sp_done;
1256 lio->u.logio.flags = 0;
1258 if (NVME_TARGET(vha->hw, fcport))
1259 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1261 ql_dbg(ql_dbg_disc, vha, 0x211b,
1262 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1263 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1264 fcport->login_retry, NVME_TARGET(vha->hw, fcport) ? "nvme" : "fc");
1266 rval = qla2x00_start_sp(sp);
1267 if (rval != QLA_SUCCESS) {
1268 fcport->flags |= FCF_LOGIN_NEEDED;
1269 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1277 fcport->flags &= ~FCF_ASYNC_SENT;
1281 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1283 struct qla_work_evt *e;
1285 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1287 return QLA_FUNCTION_FAILED;
1289 e->u.fcport.fcport = fcport;
1290 e->u.fcport.opt = opt;
1291 fcport->flags |= FCF_ASYNC_ACTIVE;
1292 return qla2x00_post_work(vha, e);
1295 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1298 struct srb_iocb *mbx;
1299 int rval = QLA_FUNCTION_FAILED;
1302 struct port_database_24xx *pd;
1303 struct qla_hw_data *ha = vha->hw;
1305 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1306 fcport->loop_id == FC_NO_LOOP_ID) {
1307 ql_log(ql_log_warn, vha, 0xffff,
1308 "%s: %8phC - not sending command.\n",
1309 __func__, fcport->port_name);
1313 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1317 qla2x00_set_fcport_disc_state(fcport, DSC_GPDB);
1319 fcport->flags |= FCF_ASYNC_SENT;
1320 sp->type = SRB_MB_IOCB;
1322 sp->gen1 = fcport->rscn_gen;
1323 sp->gen2 = fcport->login_gen;
1325 mbx = &sp->u.iocb_cmd;
1326 mbx->timeout = qla2x00_async_iocb_timeout;
1327 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1329 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1331 ql_log(ql_log_warn, vha, 0xd043,
1332 "Failed to allocate port database structure.\n");
1336 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1337 mb[0] = MBC_GET_PORT_DATABASE;
1338 mb[1] = fcport->loop_id;
1339 mb[2] = MSW(pd_dma);
1340 mb[3] = LSW(pd_dma);
1341 mb[6] = MSW(MSD(pd_dma));
1342 mb[7] = LSW(MSD(pd_dma));
1343 mb[9] = vha->vp_idx;
1346 mbx->u.mbx.in = (void *)pd;
1347 mbx->u.mbx.in_dma = pd_dma;
1349 sp->done = qla24xx_async_gpdb_sp_done;
1351 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1352 "Async-%s %8phC hndl %x opt %x\n",
1353 sp->name, fcport->port_name, sp->handle, opt);
1355 rval = qla2x00_start_sp(sp);
1356 if (rval != QLA_SUCCESS)
1362 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1365 fcport->flags &= ~FCF_ASYNC_SENT;
1367 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1368 qla24xx_post_gpdb_work(vha, fcport, opt);
1373 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1375 unsigned long flags;
1377 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1378 ea->fcport->login_gen++;
1379 ea->fcport->deleted = 0;
1380 ea->fcport->logout_on_delete = 1;
1382 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1383 vha->fcport_count++;
1384 ea->fcport->login_succ = 1;
1386 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1387 qla24xx_sched_upd_fcport(ea->fcport);
1388 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1389 } else if (ea->fcport->login_succ) {
1391 * We have an existing session. A late RSCN delivery
1392 * must have triggered the session to be re-validate.
1393 * Session is still valid.
1395 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1396 "%s %d %8phC session revalidate success\n",
1397 __func__, __LINE__, ea->fcport->port_name);
1398 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_COMPLETE);
1400 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1404 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1406 fc_port_t *fcport = ea->fcport;
1407 struct port_database_24xx *pd;
1408 struct srb *sp = ea->sp;
1411 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1413 fcport->flags &= ~FCF_ASYNC_SENT;
1415 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1416 "%s %8phC DS %d LS %d fc4_type %x rc %d\n", __func__,
1417 fcport->port_name, fcport->disc_state, pd->current_login_state,
1418 fcport->fc4_type, ea->rc);
1420 if (fcport->disc_state == DSC_DELETE_PEND)
1423 if (NVME_TARGET(vha->hw, fcport))
1424 ls = pd->current_login_state >> 4;
1426 ls = pd->current_login_state & 0xf;
1428 if (ea->sp->gen2 != fcport->login_gen) {
1429 /* target side must have changed it. */
1431 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1432 "%s %8phC generation changed\n",
1433 __func__, fcport->port_name);
1435 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1436 qla_rscn_replay(fcport);
1437 qlt_schedule_sess_for_deletion(fcport);
1442 case PDS_PRLI_COMPLETE:
1443 __qla24xx_parse_gpdb(vha, fcport, pd);
1445 case PDS_PLOGI_PENDING:
1446 case PDS_PLOGI_COMPLETE:
1447 case PDS_PRLI_PENDING:
1448 case PDS_PRLI2_PENDING:
1449 /* Set discovery state back to GNL to Relogin attempt */
1450 if (qla_dual_mode_enabled(vha) ||
1451 qla_ini_mode_enabled(vha)) {
1452 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
1453 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1456 case PDS_LOGO_PENDING:
1457 case PDS_PORT_UNAVAILABLE:
1459 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1460 __func__, __LINE__, fcport->port_name);
1461 qlt_schedule_sess_for_deletion(fcport);
1464 __qla24xx_handle_gpdb_event(vha, ea);
1467 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1472 if (qla_tgt_mode_enabled(vha))
1475 if (qla_dual_mode_enabled(vha)) {
1476 if (N2N_TOPO(vha->hw)) {
1479 mywwn = wwn_to_u64(vha->port_name);
1480 wwn = wwn_to_u64(fcport->port_name);
1483 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1484 && time_after_eq(jiffies,
1485 fcport->plogi_nack_done_deadline))
1491 /* initiator mode */
1495 if (login && fcport->login_retry) {
1496 fcport->login_retry--;
1497 if (fcport->loop_id == FC_NO_LOOP_ID) {
1498 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1499 rc = qla2x00_find_new_loop_id(vha, fcport);
1501 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1502 "%s %d %8phC post del sess - out of loopid\n",
1503 __func__, __LINE__, fcport->port_name);
1504 fcport->scan_state = 0;
1505 qlt_schedule_sess_for_deletion(fcport);
1509 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1510 "%s %d %8phC post login\n",
1511 __func__, __LINE__, fcport->port_name);
1512 qla2x00_post_async_login_work(vha, fcport, NULL);
1516 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1522 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1523 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1524 __func__, fcport->port_name, fcport->disc_state,
1525 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1526 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1527 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1529 if (fcport->scan_state != QLA_FCPORT_FOUND)
1532 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1533 qla_dual_mode_enabled(vha) &&
1534 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1535 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1538 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1539 !N2N_TOPO(vha->hw)) {
1540 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1541 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1546 /* Target won't initiate port login if fabric is present */
1547 if (vha->host->active_mode == MODE_TARGET && !N2N_TOPO(vha->hw))
1550 if (fcport->flags & FCF_ASYNC_SENT) {
1551 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1555 switch (fcport->disc_state) {
1557 wwn = wwn_to_u64(fcport->node_name);
1558 switch (vha->hw->current_topology) {
1560 if (fcport_is_smaller(fcport)) {
1561 /* this adapter is bigger */
1562 if (fcport->login_retry) {
1563 if (fcport->loop_id == FC_NO_LOOP_ID) {
1564 qla2x00_find_new_loop_id(vha,
1566 fcport->fw_login_state =
1567 DSC_LS_PORT_UNAVAIL;
1569 fcport->login_retry--;
1570 qla_post_els_plogi_work(vha, fcport);
1572 ql_log(ql_log_info, vha, 0x705d,
1573 "Unable to reach remote port %8phC",
1577 qla24xx_post_gnl_work(vha, fcport);
1582 ql_dbg(ql_dbg_disc, vha, 0xffff,
1583 "%s %d %8phC post GNNID\n",
1584 __func__, __LINE__, fcport->port_name);
1585 qla24xx_post_gnnid_work(vha, fcport);
1586 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1587 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1588 "%s %d %8phC post gnl\n",
1589 __func__, __LINE__, fcport->port_name);
1590 qla24xx_post_gnl_work(vha, fcport);
1592 qla_chk_n2n_b4_login(vha, fcport);
1599 switch (vha->hw->current_topology) {
1601 if ((fcport->current_login_state & 0xf) == 0x6) {
1602 ql_dbg(ql_dbg_disc, vha, 0x2118,
1603 "%s %d %8phC post GPDB work\n",
1604 __func__, __LINE__, fcport->port_name);
1605 fcport->chip_reset =
1606 vha->hw->base_qpair->chip_reset;
1607 qla24xx_post_gpdb_work(vha, fcport, 0);
1609 ql_dbg(ql_dbg_disc, vha, 0x2118,
1610 "%s %d %8phC post %s PRLI\n",
1611 __func__, __LINE__, fcport->port_name,
1612 NVME_TARGET(vha->hw, fcport) ? "NVME" :
1614 qla24xx_post_prli_work(vha, fcport);
1618 if (fcport->login_pause) {
1619 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1620 "%s %d %8phC exit\n",
1623 fcport->last_rscn_gen = fcport->rscn_gen;
1624 fcport->last_login_gen = fcport->login_gen;
1625 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1628 qla_chk_n2n_b4_login(vha, fcport);
1633 case DSC_LOGIN_FAILED:
1634 if (N2N_TOPO(vha->hw))
1635 qla_chk_n2n_b4_login(vha, fcport);
1637 qlt_schedule_sess_for_deletion(fcport);
1640 case DSC_LOGIN_COMPLETE:
1641 /* recheck login state */
1642 data[0] = data[1] = 0;
1643 qla2x00_post_async_adisc_work(vha, fcport, data);
1646 case DSC_LOGIN_PEND:
1647 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1648 qla24xx_post_prli_work(vha, fcport);
1651 case DSC_UPD_FCPORT:
1652 sec = jiffies_to_msecs(jiffies -
1653 fcport->jiffies_at_registration)/1000;
1654 if (fcport->sec_since_registration < sec && sec &&
1656 fcport->sec_since_registration = sec;
1657 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1658 "%s %8phC - Slow Rport registration(%d Sec)\n",
1659 __func__, fcport->port_name, sec);
1662 if (fcport->next_disc_state != DSC_DELETE_PEND)
1663 fcport->next_disc_state = DSC_ADISC;
1664 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1674 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1675 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1677 struct qla_work_evt *e;
1679 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1681 return QLA_FUNCTION_FAILED;
1683 e->u.new_sess.id = *id;
1684 e->u.new_sess.pla = pla;
1685 e->u.new_sess.fc4_type = fc4_type;
1686 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1688 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1690 return qla2x00_post_work(vha, e);
1693 void qla2x00_handle_rscn(scsi_qla_host_t *vha, struct event_arg *ea)
1696 unsigned long flags;
1698 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1700 fcport->scan_needed = 1;
1704 spin_lock_irqsave(&vha->work_lock, flags);
1705 if (vha->scan.scan_flags == 0) {
1706 ql_dbg(ql_dbg_disc, vha, 0xffff, "%s: schedule\n", __func__);
1707 vha->scan.scan_flags |= SF_QUEUED;
1708 schedule_delayed_work(&vha->scan.scan_work, 5);
1710 spin_unlock_irqrestore(&vha->work_lock, flags);
1713 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1714 struct event_arg *ea)
1716 fc_port_t *fcport = ea->fcport;
1718 if (test_bit(UNLOADING, &vha->dpc_flags))
1721 ql_dbg(ql_dbg_disc, vha, 0x2102,
1722 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1723 __func__, fcport->port_name, fcport->disc_state,
1724 fcport->fw_login_state, fcport->login_pause,
1725 fcport->deleted, fcport->conflict,
1726 fcport->last_rscn_gen, fcport->rscn_gen,
1727 fcport->last_login_gen, fcport->login_gen,
1730 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1731 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1732 __func__, __LINE__, fcport->port_name);
1733 qla24xx_post_gnl_work(vha, fcport);
1737 qla24xx_fcport_handle_login(vha, fcport);
1740 void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1741 struct event_arg *ea)
1743 /* for pure Target Mode, PRLI will not be initiated */
1744 if (vha->host->active_mode == MODE_TARGET)
1747 ql_dbg(ql_dbg_disc, vha, 0x2118,
1748 "%s %d %8phC post PRLI\n",
1749 __func__, __LINE__, ea->fcport->port_name);
1750 qla24xx_post_prli_work(vha, ea->fcport);
1754 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1755 * to be consumed by the fcport
1757 void qla_rscn_replay(fc_port_t *fcport)
1759 struct event_arg ea;
1761 switch (fcport->disc_state) {
1762 case DSC_DELETE_PEND:
1768 if (fcport->scan_needed) {
1769 memset(&ea, 0, sizeof(ea));
1770 ea.id = fcport->d_id;
1771 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1772 qla2x00_handle_rscn(fcport->vha, &ea);
1777 qla2x00_tmf_iocb_timeout(void *data)
1780 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1782 unsigned long flags;
1784 rc = qla24xx_async_abort_cmd(sp, false);
1786 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
1787 for (h = 1; h < sp->qpair->req->num_outstanding_cmds; h++) {
1788 if (sp->qpair->req->outstanding_cmds[h] == sp) {
1789 sp->qpair->req->outstanding_cmds[h] = NULL;
1793 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
1794 tmf->u.tmf.comp_status = CS_TIMEOUT;
1795 tmf->u.tmf.data = QLA_FUNCTION_FAILED;
1796 complete(&tmf->u.tmf.comp);
1800 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1802 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1804 complete(&tmf->u.tmf.comp);
1808 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1811 struct scsi_qla_host *vha = fcport->vha;
1812 struct srb_iocb *tm_iocb;
1814 int rval = QLA_FUNCTION_FAILED;
1816 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1820 tm_iocb = &sp->u.iocb_cmd;
1821 sp->type = SRB_TM_CMD;
1824 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1825 init_completion(&tm_iocb->u.tmf.comp);
1826 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1828 tm_iocb->u.tmf.flags = flags;
1829 tm_iocb->u.tmf.lun = lun;
1830 tm_iocb->u.tmf.data = tag;
1831 sp->done = qla2x00_tmf_sp_done;
1833 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1834 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1835 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1836 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1838 rval = qla2x00_start_sp(sp);
1839 if (rval != QLA_SUCCESS)
1841 wait_for_completion(&tm_iocb->u.tmf.comp);
1843 rval = tm_iocb->u.tmf.data;
1845 if (rval != QLA_SUCCESS) {
1846 ql_log(ql_log_warn, vha, 0x8030,
1847 "TM IOCB failed (%x).\n", rval);
1850 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1851 flags = tm_iocb->u.tmf.flags;
1852 lun = (uint16_t)tm_iocb->u.tmf.lun;
1854 /* Issue Marker IOCB */
1855 qla2x00_marker(vha, vha->hw->base_qpair,
1856 fcport->loop_id, lun,
1857 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1862 fcport->flags &= ~FCF_ASYNC_SENT;
1868 qla24xx_async_abort_command(srb_t *sp)
1870 unsigned long flags = 0;
1873 fc_port_t *fcport = sp->fcport;
1874 struct qla_qpair *qpair = sp->qpair;
1875 struct scsi_qla_host *vha = fcport->vha;
1876 struct req_que *req = qpair->req;
1878 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1879 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1880 if (req->outstanding_cmds[handle] == sp)
1883 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1885 if (handle == req->num_outstanding_cmds) {
1886 /* Command not found. */
1887 return QLA_FUNCTION_FAILED;
1889 if (sp->type == SRB_FXIOCB_DCMD)
1890 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1891 FXDISC_ABORT_IOCTL);
1893 return qla24xx_async_abort_cmd(sp, true);
1897 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1899 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
1902 switch (ea->data[0]) {
1903 case MBS_COMMAND_COMPLETE:
1904 ql_dbg(ql_dbg_disc, vha, 0x2118,
1905 "%s %d %8phC post gpdb\n",
1906 __func__, __LINE__, ea->fcport->port_name);
1908 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1909 ea->fcport->logout_on_delete = 1;
1910 ea->fcport->nvme_prli_service_param = ea->iop[0];
1911 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1912 ea->fcport->nvme_first_burst_size =
1913 (ea->iop[1] & 0xffff) * 512;
1915 ea->fcport->nvme_first_burst_size = 0;
1916 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1919 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1920 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1921 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1922 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1927 * Retry PRLI with other FC-4 type if failure occurred on dual
1930 if (NVME_FCP_TARGET(ea->fcport)) {
1931 ql_dbg(ql_dbg_disc, vha, 0x2118,
1932 "%s %d %8phC post %s prli\n",
1933 __func__, __LINE__, ea->fcport->port_name,
1934 (ea->fcport->fc4_type & FS_FC4TYPE_NVME) ?
1936 if (vha->hw->fc4_type_priority == FC4_PRIORITY_NVME)
1937 ea->fcport->fc4_type &= ~FS_FC4TYPE_NVME;
1939 ea->fcport->fc4_type &= ~FS_FC4TYPE_FCP;
1942 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1943 ea->fcport->keep_nport_handle = 0;
1944 ea->fcport->logout_on_delete = 1;
1945 qlt_schedule_sess_for_deletion(ea->fcport);
1951 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1953 port_id_t cid; /* conflict Nport id */
1955 struct fc_port *conflict_fcport;
1956 unsigned long flags;
1957 struct fc_port *fcport = ea->fcport;
1959 ql_dbg(ql_dbg_disc, vha, 0xffff,
1960 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1961 __func__, fcport->port_name, fcport->disc_state,
1962 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1963 ea->sp->gen1, fcport->rscn_gen,
1964 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1966 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1967 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1968 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1969 "%s %d %8phC Remote is trying to login\n",
1970 __func__, __LINE__, fcport->port_name);
1974 if ((fcport->disc_state == DSC_DELETE_PEND) ||
1975 (fcport->disc_state == DSC_DELETED)) {
1976 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1980 if (ea->sp->gen2 != fcport->login_gen) {
1981 /* target side must have changed it. */
1982 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1983 "%s %8phC generation changed\n",
1984 __func__, fcport->port_name);
1985 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1987 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1988 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1989 "%s %8phC RSCN generation changed\n",
1990 __func__, fcport->port_name);
1991 qla_rscn_replay(fcport);
1992 qlt_schedule_sess_for_deletion(fcport);
1996 WARN_ONCE(!qla2xxx_is_valid_mbs(ea->data[0]), "mbs: %#x\n",
1999 switch (ea->data[0]) {
2000 case MBS_COMMAND_COMPLETE:
2002 * Driver must validate login state - If PRLI not complete,
2003 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2006 if (NVME_TARGET(vha->hw, ea->fcport)) {
2007 ql_dbg(ql_dbg_disc, vha, 0x2117,
2008 "%s %d %8phC post prli\n",
2009 __func__, __LINE__, ea->fcport->port_name);
2010 qla24xx_post_prli_work(vha, ea->fcport);
2012 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2013 "%s %d %8phC LoopID 0x%x in use with %06x. post gpdb\n",
2014 __func__, __LINE__, ea->fcport->port_name,
2015 ea->fcport->loop_id, ea->fcport->d_id.b24);
2017 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2018 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2019 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2020 ea->fcport->logout_on_delete = 1;
2021 ea->fcport->send_els_logo = 0;
2022 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2023 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2025 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2028 case MBS_COMMAND_ERROR:
2029 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2030 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2032 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2033 qla2x00_set_fcport_disc_state(ea->fcport, DSC_LOGIN_FAILED);
2034 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2035 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2037 qla2x00_mark_device_lost(vha, ea->fcport, 1);
2039 case MBS_LOOP_ID_USED:
2040 /* data[1] = IO PARAM 1 = nport ID */
2041 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2042 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2043 cid.b.al_pa = ea->iop[1] & 0xff;
2046 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2047 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2048 __func__, __LINE__, ea->fcport->port_name,
2049 ea->fcport->loop_id, cid.b24);
2051 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2052 ea->fcport->loop_id = FC_NO_LOOP_ID;
2053 qla24xx_post_gnl_work(vha, ea->fcport);
2055 case MBS_PORT_ID_USED:
2056 lid = ea->iop[1] & 0xffff;
2057 qlt_find_sess_invalidate_other(vha,
2058 wwn_to_u64(ea->fcport->port_name),
2059 ea->fcport->d_id, lid, &conflict_fcport);
2061 if (conflict_fcport) {
2063 * Another fcport share the same loop_id/nport id.
2064 * Conflict fcport needs to finish cleanup before this
2065 * fcport can proceed to login.
2067 conflict_fcport->conflict = ea->fcport;
2068 ea->fcport->login_pause = 1;
2070 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2071 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2072 __func__, __LINE__, ea->fcport->port_name,
2073 ea->fcport->d_id.b24, lid);
2075 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2076 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2077 __func__, __LINE__, ea->fcport->port_name,
2078 ea->fcport->d_id.b24, lid);
2080 qla2x00_clear_loop_id(ea->fcport);
2081 set_bit(lid, vha->hw->loop_id_map);
2082 ea->fcport->loop_id = lid;
2083 ea->fcport->keep_nport_handle = 0;
2084 ea->fcport->logout_on_delete = 1;
2085 qlt_schedule_sess_for_deletion(ea->fcport);
2092 /****************************************************************************/
2093 /* QLogic ISP2x00 Hardware Support Functions. */
2094 /****************************************************************************/
2097 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2099 int rval = QLA_SUCCESS;
2100 struct qla_hw_data *ha = vha->hw;
2101 uint32_t idc_major_ver, idc_minor_ver;
2104 qla83xx_idc_lock(vha, 0);
2106 /* SV: TODO: Assign initialization timeout from
2107 * flash-info / other param
2109 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2110 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2112 /* Set our fcoe function presence */
2113 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2114 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2115 "Error while setting DRV-Presence.\n");
2116 rval = QLA_FUNCTION_FAILED;
2120 /* Decide the reset ownership */
2121 qla83xx_reset_ownership(vha);
2124 * On first protocol driver load:
2125 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2127 * Others: Check compatibility with current IDC Major version.
2129 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2130 if (ha->flags.nic_core_reset_owner) {
2131 /* Set IDC Major version */
2132 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2133 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2135 /* Clearing IDC-Lock-Recovery register */
2136 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2137 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2139 * Clear further IDC participation if we are not compatible with
2140 * the current IDC Major Version.
2142 ql_log(ql_log_warn, vha, 0xb07d,
2143 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2144 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2145 __qla83xx_clear_drv_presence(vha);
2146 rval = QLA_FUNCTION_FAILED;
2149 /* Each function sets its supported Minor version. */
2150 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2151 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2152 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2154 if (ha->flags.nic_core_reset_owner) {
2155 memset(config, 0, sizeof(config));
2156 if (!qla81xx_get_port_config(vha, config))
2157 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2161 rval = qla83xx_idc_state_handler(vha);
2164 qla83xx_idc_unlock(vha, 0);
2170 * qla2x00_initialize_adapter
2174 * ha = adapter block pointer.
2180 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2183 struct qla_hw_data *ha = vha->hw;
2184 struct req_que *req = ha->req_q_map[0];
2185 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2187 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2188 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2190 /* Clear adapter flags. */
2191 vha->flags.online = 0;
2192 ha->flags.chip_reset_done = 0;
2193 vha->flags.reset_active = 0;
2194 ha->flags.pci_channel_io_perm_failure = 0;
2195 ha->flags.eeh_busy = 0;
2196 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2197 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2198 atomic_set(&vha->loop_state, LOOP_DOWN);
2199 vha->device_flags = DFLG_NO_CABLE;
2201 vha->flags.management_server_logged_in = 0;
2202 vha->marker_needed = 0;
2203 ha->isp_abort_cnt = 0;
2204 ha->beacon_blink_led = 0;
2206 set_bit(0, ha->req_qid_map);
2207 set_bit(0, ha->rsp_qid_map);
2209 ql_dbg(ql_dbg_init, vha, 0x0040,
2210 "Configuring PCI space...\n");
2211 rval = ha->isp_ops->pci_config(vha);
2213 ql_log(ql_log_warn, vha, 0x0044,
2214 "Unable to configure PCI space.\n");
2218 ha->isp_ops->reset_chip(vha);
2220 /* Check for secure flash support */
2221 if (IS_QLA28XX(ha)) {
2222 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2223 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2224 ha->flags.secure_adapter = 1;
2229 rval = qla2xxx_get_flash_info(vha);
2231 ql_log(ql_log_fatal, vha, 0x004f,
2232 "Unable to validate FLASH data.\n");
2236 if (IS_QLA8044(ha)) {
2237 qla8044_read_reset_template(vha);
2239 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2240 * If DONRESET_BIT0 is set, drivers should not set dev_state
2241 * to NEED_RESET. But if NEED_RESET is set, drivers should
2242 * should honor the reset. */
2243 if (ql2xdontresethba == 1)
2244 qla8044_set_idc_dontreset(vha);
2247 ha->isp_ops->get_flash_version(vha, req->ring);
2248 ql_dbg(ql_dbg_init, vha, 0x0061,
2249 "Configure NVRAM parameters...\n");
2251 /* Let priority default to FCP, can be overridden by nvram_config */
2252 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2254 ha->isp_ops->nvram_config(vha);
2256 if (ha->fc4_type_priority != FC4_PRIORITY_FCP &&
2257 ha->fc4_type_priority != FC4_PRIORITY_NVME)
2258 ha->fc4_type_priority = FC4_PRIORITY_FCP;
2260 ql_log(ql_log_info, vha, 0xffff, "FC4 priority set to %s\n",
2261 ha->fc4_type_priority == FC4_PRIORITY_FCP ? "FCP" : "NVMe");
2263 if (ha->flags.disable_serdes) {
2264 /* Mask HBA via NVRAM settings? */
2265 ql_log(ql_log_info, vha, 0x0077,
2266 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2267 return QLA_FUNCTION_FAILED;
2270 ql_dbg(ql_dbg_init, vha, 0x0078,
2271 "Verifying loaded RISC code...\n");
2273 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2274 rval = ha->isp_ops->chip_diag(vha);
2277 rval = qla2x00_setup_chip(vha);
2282 if (IS_QLA84XX(ha)) {
2283 ha->cs84xx = qla84xx_get_chip(vha);
2285 ql_log(ql_log_warn, vha, 0x00d0,
2286 "Unable to configure ISP84XX.\n");
2287 return QLA_FUNCTION_FAILED;
2291 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2292 rval = qla2x00_init_rings(vha);
2294 /* No point in continuing if firmware initialization failed. */
2295 if (rval != QLA_SUCCESS)
2298 ha->flags.chip_reset_done = 1;
2300 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2301 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2302 rval = qla84xx_init_chip(vha);
2303 if (rval != QLA_SUCCESS) {
2304 ql_log(ql_log_warn, vha, 0x00d4,
2305 "Unable to initialize ISP84XX.\n");
2306 qla84xx_put_chip(vha);
2310 /* Load the NIC Core f/w if we are the first protocol driver. */
2311 if (IS_QLA8031(ha)) {
2312 rval = qla83xx_nic_core_fw_load(vha);
2314 ql_log(ql_log_warn, vha, 0x0124,
2315 "Error in initializing NIC Core f/w.\n");
2318 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2319 qla24xx_read_fcp_prio_cfg(vha);
2321 if (IS_P3P_TYPE(ha))
2322 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2324 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2330 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2333 * Returns 0 on success.
2336 qla2100_pci_config(scsi_qla_host_t *vha)
2339 unsigned long flags;
2340 struct qla_hw_data *ha = vha->hw;
2341 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2343 pci_set_master(ha->pdev);
2344 pci_try_set_mwi(ha->pdev);
2346 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2347 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2348 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2350 pci_disable_rom(ha->pdev);
2352 /* Get PCI bus information. */
2353 spin_lock_irqsave(&ha->hardware_lock, flags);
2354 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2355 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2361 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2364 * Returns 0 on success.
2367 qla2300_pci_config(scsi_qla_host_t *vha)
2370 unsigned long flags = 0;
2372 struct qla_hw_data *ha = vha->hw;
2373 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2375 pci_set_master(ha->pdev);
2376 pci_try_set_mwi(ha->pdev);
2378 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2379 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2381 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2382 w &= ~PCI_COMMAND_INTX_DISABLE;
2383 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2386 * If this is a 2300 card and not 2312, reset the
2387 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2388 * the 2310 also reports itself as a 2300 so we need to get the
2389 * fb revision level -- a 6 indicates it really is a 2300 and
2392 if (IS_QLA2300(ha)) {
2393 spin_lock_irqsave(&ha->hardware_lock, flags);
2396 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2397 for (cnt = 0; cnt < 30000; cnt++) {
2398 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2404 /* Select FPM registers. */
2405 WRT_REG_WORD(®->ctrl_status, 0x20);
2406 RD_REG_WORD(®->ctrl_status);
2408 /* Get the fb rev level */
2409 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2411 if (ha->fb_rev == FPM_2300)
2412 pci_clear_mwi(ha->pdev);
2414 /* Deselect FPM registers. */
2415 WRT_REG_WORD(®->ctrl_status, 0x0);
2416 RD_REG_WORD(®->ctrl_status);
2418 /* Release RISC module. */
2419 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2420 for (cnt = 0; cnt < 30000; cnt++) {
2421 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2427 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2430 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2432 pci_disable_rom(ha->pdev);
2434 /* Get PCI bus information. */
2435 spin_lock_irqsave(&ha->hardware_lock, flags);
2436 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2437 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2443 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2446 * Returns 0 on success.
2449 qla24xx_pci_config(scsi_qla_host_t *vha)
2452 unsigned long flags = 0;
2453 struct qla_hw_data *ha = vha->hw;
2454 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2456 pci_set_master(ha->pdev);
2457 pci_try_set_mwi(ha->pdev);
2459 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2460 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2461 w &= ~PCI_COMMAND_INTX_DISABLE;
2462 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2464 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2466 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2467 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2468 pcix_set_mmrbc(ha->pdev, 2048);
2470 /* PCIe -- adjust Maximum Read Request Size (2048). */
2471 if (pci_is_pcie(ha->pdev))
2472 pcie_set_readrq(ha->pdev, 4096);
2474 pci_disable_rom(ha->pdev);
2476 ha->chip_revision = ha->pdev->revision;
2478 /* Get PCI bus information. */
2479 spin_lock_irqsave(&ha->hardware_lock, flags);
2480 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2481 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2487 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2490 * Returns 0 on success.
2493 qla25xx_pci_config(scsi_qla_host_t *vha)
2496 struct qla_hw_data *ha = vha->hw;
2498 pci_set_master(ha->pdev);
2499 pci_try_set_mwi(ha->pdev);
2501 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2502 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2503 w &= ~PCI_COMMAND_INTX_DISABLE;
2504 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2506 /* PCIe -- adjust Maximum Read Request Size (2048). */
2507 if (pci_is_pcie(ha->pdev))
2508 pcie_set_readrq(ha->pdev, 4096);
2510 pci_disable_rom(ha->pdev);
2512 ha->chip_revision = ha->pdev->revision;
2518 * qla2x00_isp_firmware() - Choose firmware image.
2521 * Returns 0 on success.
2524 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2527 uint16_t loop_id, topo, sw_cap;
2528 uint8_t domain, area, al_pa;
2529 struct qla_hw_data *ha = vha->hw;
2531 /* Assume loading risc code */
2532 rval = QLA_FUNCTION_FAILED;
2534 if (ha->flags.disable_risc_code_load) {
2535 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2537 /* Verify checksum of loaded RISC code. */
2538 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2539 if (rval == QLA_SUCCESS) {
2540 /* And, verify we are not in ROM code. */
2541 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2542 &area, &domain, &topo, &sw_cap);
2547 ql_dbg(ql_dbg_init, vha, 0x007a,
2548 "**** Load RISC code ****.\n");
2554 * qla2x00_reset_chip() - Reset ISP chip.
2557 * Returns 0 on success.
2560 qla2x00_reset_chip(scsi_qla_host_t *vha)
2562 unsigned long flags = 0;
2563 struct qla_hw_data *ha = vha->hw;
2564 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2567 int rval = QLA_FUNCTION_FAILED;
2569 if (unlikely(pci_channel_offline(ha->pdev)))
2572 ha->isp_ops->disable_intrs(ha);
2574 spin_lock_irqsave(&ha->hardware_lock, flags);
2576 /* Turn off master enable */
2578 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2579 cmd &= ~PCI_COMMAND_MASTER;
2580 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2582 if (!IS_QLA2100(ha)) {
2584 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2585 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2586 for (cnt = 0; cnt < 30000; cnt++) {
2587 if ((RD_REG_WORD(®->hccr) &
2588 HCCR_RISC_PAUSE) != 0)
2593 RD_REG_WORD(®->hccr); /* PCI Posting. */
2597 /* Select FPM registers. */
2598 WRT_REG_WORD(®->ctrl_status, 0x20);
2599 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2601 /* FPM Soft Reset. */
2602 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2603 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2605 /* Toggle Fpm Reset. */
2606 if (!IS_QLA2200(ha)) {
2607 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2608 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2611 /* Select frame buffer registers. */
2612 WRT_REG_WORD(®->ctrl_status, 0x10);
2613 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2615 /* Reset frame buffer FIFOs. */
2616 if (IS_QLA2200(ha)) {
2617 WRT_FB_CMD_REG(ha, reg, 0xa000);
2618 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2620 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2622 /* Read back fb_cmd until zero or 3 seconds max */
2623 for (cnt = 0; cnt < 3000; cnt++) {
2624 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2630 /* Select RISC module registers. */
2631 WRT_REG_WORD(®->ctrl_status, 0);
2632 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2634 /* Reset RISC processor. */
2635 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2636 RD_REG_WORD(®->hccr); /* PCI Posting. */
2638 /* Release RISC processor. */
2639 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2640 RD_REG_WORD(®->hccr); /* PCI Posting. */
2643 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2644 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2646 /* Reset ISP chip. */
2647 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2649 /* Wait for RISC to recover from reset. */
2650 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2652 * It is necessary to for a delay here since the card doesn't
2653 * respond to PCI reads during a reset. On some architectures
2654 * this will result in an MCA.
2657 for (cnt = 30000; cnt; cnt--) {
2658 if ((RD_REG_WORD(®->ctrl_status) &
2659 CSR_ISP_SOFT_RESET) == 0)
2666 /* Reset RISC processor. */
2667 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2669 WRT_REG_WORD(®->semaphore, 0);
2671 /* Release RISC processor. */
2672 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2673 RD_REG_WORD(®->hccr); /* PCI Posting. */
2675 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2676 for (cnt = 0; cnt < 30000; cnt++) {
2677 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2685 /* Turn on master enable */
2686 cmd |= PCI_COMMAND_MASTER;
2687 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2689 /* Disable RISC pause on FPM parity error. */
2690 if (!IS_QLA2100(ha)) {
2691 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2692 RD_REG_WORD(®->hccr); /* PCI Posting. */
2695 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2701 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2704 * Returns 0 on success.
2707 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2709 uint16_t mb[4] = {0x1010, 0, 1, 0};
2711 if (!IS_QLA81XX(vha->hw))
2714 return qla81xx_write_mpi_register(vha, mb);
2718 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2721 * Returns 0 on success.
2724 qla24xx_reset_risc(scsi_qla_host_t *vha)
2726 unsigned long flags = 0;
2727 struct qla_hw_data *ha = vha->hw;
2728 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2731 static int abts_cnt; /* ISP abort retry counts */
2732 int rval = QLA_SUCCESS;
2734 spin_lock_irqsave(&ha->hardware_lock, flags);
2737 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2738 for (cnt = 0; cnt < 30000; cnt++) {
2739 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2745 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2746 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2748 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2749 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2750 RD_REG_DWORD(®->hccr),
2751 RD_REG_DWORD(®->ctrl_status),
2752 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2754 WRT_REG_DWORD(®->ctrl_status,
2755 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2756 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2760 /* Wait for firmware to complete NVRAM accesses. */
2761 RD_REG_WORD(®->mailbox0);
2762 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2763 rval == QLA_SUCCESS; cnt--) {
2768 rval = QLA_FUNCTION_TIMEOUT;
2771 if (rval == QLA_SUCCESS)
2772 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2774 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2775 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2776 RD_REG_DWORD(®->hccr),
2777 RD_REG_DWORD(®->mailbox0));
2779 /* Wait for soft-reset to complete. */
2780 RD_REG_DWORD(®->ctrl_status);
2781 for (cnt = 0; cnt < 60; cnt++) {
2783 if ((RD_REG_DWORD(®->ctrl_status) &
2784 CSRX_ISP_SOFT_RESET) == 0)
2789 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2790 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2792 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2793 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2794 RD_REG_DWORD(®->hccr),
2795 RD_REG_DWORD(®->ctrl_status));
2797 /* If required, do an MPI FW reset now */
2798 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2799 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2800 if (++abts_cnt < 5) {
2801 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2802 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2805 * We exhausted the ISP abort retries. We have to
2806 * set the board offline.
2809 vha->flags.online = 0;
2814 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2815 RD_REG_DWORD(®->hccr);
2817 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2818 RD_REG_DWORD(®->hccr);
2820 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2821 RD_REG_DWORD(®->hccr);
2823 RD_REG_WORD(®->mailbox0);
2824 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2825 rval == QLA_SUCCESS; cnt--) {
2830 rval = QLA_FUNCTION_TIMEOUT;
2832 if (rval == QLA_SUCCESS)
2833 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2835 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2836 "Host Risc 0x%x, mailbox0 0x%x\n",
2837 RD_REG_DWORD(®->hccr),
2838 RD_REG_WORD(®->mailbox0));
2840 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2842 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2843 "Driver in %s mode\n",
2844 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2846 if (IS_NOPOLLING_TYPE(ha))
2847 ha->isp_ops->enable_intrs(ha);
2853 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2855 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2857 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2858 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2863 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2865 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2867 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2868 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2872 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2875 uint delta_msec = 100;
2876 uint elapsed_msec = 0;
2880 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2881 vha->hw->pdev->subsystem_device != 0x0240)
2884 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2888 timeout_msec = TIMEOUT_SEMAPHORE;
2889 n = timeout_msec / delta_msec;
2891 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2892 qla25xx_read_risc_sema_reg(vha, &wd32);
2893 if (wd32 & RISC_SEMAPHORE)
2896 elapsed_msec += delta_msec;
2897 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2901 if (!(wd32 & RISC_SEMAPHORE))
2904 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2907 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2908 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2909 n = timeout_msec / delta_msec;
2911 qla25xx_read_risc_sema_reg(vha, &wd32);
2912 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2915 elapsed_msec += delta_msec;
2916 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2920 if (wd32 & RISC_SEMAPHORE_FORCE)
2921 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2926 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2933 * qla24xx_reset_chip() - Reset ISP24xx chip.
2936 * Returns 0 on success.
2939 qla24xx_reset_chip(scsi_qla_host_t *vha)
2941 struct qla_hw_data *ha = vha->hw;
2942 int rval = QLA_FUNCTION_FAILED;
2944 if (pci_channel_offline(ha->pdev) &&
2945 ha->flags.pci_channel_io_perm_failure) {
2949 ha->isp_ops->disable_intrs(ha);
2951 qla25xx_manipulate_risc_semaphore(vha);
2953 /* Perform RISC reset. */
2954 rval = qla24xx_reset_risc(vha);
2960 * qla2x00_chip_diag() - Test chip for proper operation.
2963 * Returns 0 on success.
2966 qla2x00_chip_diag(scsi_qla_host_t *vha)
2969 struct qla_hw_data *ha = vha->hw;
2970 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2971 unsigned long flags = 0;
2975 struct req_que *req = ha->req_q_map[0];
2977 /* Assume a failed state */
2978 rval = QLA_FUNCTION_FAILED;
2980 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2981 ®->flash_address);
2983 spin_lock_irqsave(&ha->hardware_lock, flags);
2985 /* Reset ISP chip. */
2986 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2989 * We need to have a delay here since the card will not respond while
2990 * in reset causing an MCA on some architectures.
2993 data = qla2x00_debounce_register(®->ctrl_status);
2994 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2996 data = RD_REG_WORD(®->ctrl_status);
3001 goto chip_diag_failed;
3003 ql_dbg(ql_dbg_init, vha, 0x007c,
3004 "Reset register cleared by chip reset.\n");
3006 /* Reset RISC processor. */
3007 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3008 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3010 /* Workaround for QLA2312 PCI parity error */
3011 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3012 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3013 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3015 data = RD_MAILBOX_REG(ha, reg, 0);
3022 goto chip_diag_failed;
3024 /* Check product ID of chip */
3025 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3027 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3028 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3029 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3030 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3031 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3032 mb[3] != PROD_ID_3) {
3033 ql_log(ql_log_warn, vha, 0x0062,
3034 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3035 mb[1], mb[2], mb[3]);
3037 goto chip_diag_failed;
3039 ha->product_id[0] = mb[1];
3040 ha->product_id[1] = mb[2];
3041 ha->product_id[2] = mb[3];
3042 ha->product_id[3] = mb[4];
3044 /* Adjust fw RISC transfer size */
3045 if (req->length > 1024)
3046 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3048 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3051 if (IS_QLA2200(ha) &&
3052 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3053 /* Limit firmware transfer size with a 2200A */
3054 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3056 ha->device_type |= DT_ISP2200A;
3057 ha->fw_transfer_size = 128;
3060 /* Wrap Incoming Mailboxes Test. */
3061 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3063 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3064 rval = qla2x00_mbx_reg_test(vha);
3066 ql_log(ql_log_warn, vha, 0x0080,
3067 "Failed mailbox send register test.\n");
3069 /* Flag a successful rval */
3071 spin_lock_irqsave(&ha->hardware_lock, flags);
3075 ql_log(ql_log_info, vha, 0x0081,
3076 "Chip diagnostics **** FAILED ****.\n");
3078 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3084 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3087 * Returns 0 on success.
3090 qla24xx_chip_diag(scsi_qla_host_t *vha)
3093 struct qla_hw_data *ha = vha->hw;
3094 struct req_que *req = ha->req_q_map[0];
3096 if (IS_P3P_TYPE(ha))
3099 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3101 rval = qla2x00_mbx_reg_test(vha);
3103 ql_log(ql_log_warn, vha, 0x0082,
3104 "Failed mailbox send register test.\n");
3106 /* Flag a successful rval */
3114 qla2x00_init_fce_trace(scsi_qla_host_t *vha)
3119 struct qla_hw_data *ha = vha->hw;
3121 if (!IS_FWI2_CAPABLE(ha))
3124 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3125 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3129 ql_dbg(ql_dbg_init, vha, 0x00bd,
3130 "%s: FCE Mem is already allocated.\n",
3135 /* Allocate memory for Fibre Channel Event Buffer. */
3136 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3139 ql_log(ql_log_warn, vha, 0x00be,
3140 "Unable to allocate (%d KB) for FCE.\n",
3145 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3146 ha->fce_mb, &ha->fce_bufs);
3148 ql_log(ql_log_warn, vha, 0x00bf,
3149 "Unable to initialize FCE (%d).\n", rval);
3150 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc, tc_dma);
3154 ql_dbg(ql_dbg_init, vha, 0x00c0,
3155 "Allocated (%d KB) for FCE...\n", FCE_SIZE / 1024);
3157 ha->flags.fce_enabled = 1;
3158 ha->fce_dma = tc_dma;
3163 qla2x00_init_eft_trace(scsi_qla_host_t *vha)
3168 struct qla_hw_data *ha = vha->hw;
3170 if (!IS_FWI2_CAPABLE(ha))
3174 ql_dbg(ql_dbg_init, vha, 0x00bd,
3175 "%s: EFT Mem is already allocated.\n",
3180 /* Allocate memory for Extended Trace Buffer. */
3181 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3184 ql_log(ql_log_warn, vha, 0x00c1,
3185 "Unable to allocate (%d KB) for EFT.\n",
3190 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3192 ql_log(ql_log_warn, vha, 0x00c2,
3193 "Unable to initialize EFT (%d).\n", rval);
3194 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc, tc_dma);
3198 ql_dbg(ql_dbg_init, vha, 0x00c3,
3199 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3201 ha->eft_dma = tc_dma;
3206 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3208 qla2x00_init_fce_trace(vha);
3209 qla2x00_init_eft_trace(vha);
3213 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3215 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3216 eft_size, fce_size, mq_size;
3217 struct qla_hw_data *ha = vha->hw;
3218 struct req_que *req = ha->req_q_map[0];
3219 struct rsp_que *rsp = ha->rsp_q_map[0];
3220 struct qla2xxx_fw_dump *fw_dump;
3222 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3223 req_q_size = rsp_q_size = 0;
3225 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3226 fixed_size = sizeof(struct qla2100_fw_dump);
3227 } else if (IS_QLA23XX(ha)) {
3228 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3229 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3231 } else if (IS_FWI2_CAPABLE(ha)) {
3232 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3233 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3234 else if (IS_QLA81XX(ha))
3235 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3236 else if (IS_QLA25XX(ha))
3237 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3239 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3241 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3244 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3246 mq_size = sizeof(struct qla2xxx_mq_chain);
3248 * Allocate maximum buffer size for all queues - Q0.
3249 * Resizing must be done at end-of-dump processing.
3251 mq_size += (ha->max_req_queues - 1) *
3252 (req->length * sizeof(request_t));
3253 mq_size += (ha->max_rsp_queues - 1) *
3254 (rsp->length * sizeof(response_t));
3256 if (ha->tgt.atio_ring)
3257 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3259 qla2x00_init_fce_trace(vha);
3261 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3262 qla2x00_init_eft_trace(vha);
3264 eft_size = EFT_SIZE;
3267 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3268 struct fwdt *fwdt = ha->fwdt;
3271 for (j = 0; j < 2; j++, fwdt++) {
3272 if (!fwdt->template) {
3273 ql_dbg(ql_dbg_init, vha, 0x00ba,
3274 "-> fwdt%u no template\n", j);
3277 ql_dbg(ql_dbg_init, vha, 0x00fa,
3278 "-> fwdt%u calculating fwdump size...\n", j);
3279 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3280 vha, fwdt->template);
3281 ql_dbg(ql_dbg_init, vha, 0x00fa,
3282 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3283 j, fwdt->dump_size);
3284 dump_size += fwdt->dump_size;
3287 req_q_size = req->length * sizeof(request_t);
3288 rsp_q_size = rsp->length * sizeof(response_t);
3289 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3290 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size
3292 ha->chain_offset = dump_size;
3293 dump_size += mq_size + fce_size;
3294 if (ha->exchoffld_buf)
3295 dump_size += sizeof(struct qla2xxx_offld_chain) +
3297 if (ha->exlogin_buf)
3298 dump_size += sizeof(struct qla2xxx_offld_chain) +
3302 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3304 ql_dbg(ql_dbg_init, vha, 0x00c5,
3305 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3306 __func__, dump_size, ha->fw_dump_len,
3307 ha->fw_dump_alloc_len);
3309 fw_dump = vmalloc(dump_size);
3311 ql_log(ql_log_warn, vha, 0x00c4,
3312 "Unable to allocate (%d KB) for firmware dump.\n",
3315 mutex_lock(&ha->optrom_mutex);
3316 if (ha->fw_dumped) {
3317 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3319 ha->fw_dump = fw_dump;
3320 ha->fw_dump_alloc_len = dump_size;
3321 ql_dbg(ql_dbg_init, vha, 0x00c5,
3322 "Re-Allocated (%d KB) and save firmware dump.\n",
3327 ha->fw_dump = fw_dump;
3329 ha->fw_dump_len = ha->fw_dump_alloc_len =
3331 ql_dbg(ql_dbg_init, vha, 0x00c5,
3332 "Allocated (%d KB) for firmware dump.\n",
3335 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3336 mutex_unlock(&ha->optrom_mutex);
3340 ha->fw_dump->signature[0] = 'Q';
3341 ha->fw_dump->signature[1] = 'L';
3342 ha->fw_dump->signature[2] = 'G';
3343 ha->fw_dump->signature[3] = 'C';
3344 ha->fw_dump->version = htonl(1);
3346 ha->fw_dump->fixed_size = htonl(fixed_size);
3347 ha->fw_dump->mem_size = htonl(mem_size);
3348 ha->fw_dump->req_q_size = htonl(req_q_size);
3349 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3351 ha->fw_dump->eft_size = htonl(eft_size);
3352 ha->fw_dump->eft_addr_l =
3353 htonl(LSD(ha->eft_dma));
3354 ha->fw_dump->eft_addr_h =
3355 htonl(MSD(ha->eft_dma));
3357 ha->fw_dump->header_size =
3359 (struct qla2xxx_fw_dump, isp));
3361 mutex_unlock(&ha->optrom_mutex);
3367 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3369 #define MPS_MASK 0xe0
3374 if (!IS_QLA81XX(vha->hw))
3377 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3378 if (rval != QLA_SUCCESS) {
3379 ql_log(ql_log_warn, vha, 0x0105,
3380 "Unable to acquire semaphore.\n");
3384 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3385 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3386 if (rval != QLA_SUCCESS) {
3387 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3392 if (dc == (dw & MPS_MASK))
3397 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3398 if (rval != QLA_SUCCESS) {
3399 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3403 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3404 if (rval != QLA_SUCCESS) {
3405 ql_log(ql_log_warn, vha, 0x006d,
3406 "Unable to release semaphore.\n");
3414 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3416 /* Don't try to reallocate the array */
3417 if (req->outstanding_cmds)
3420 if (!IS_FWI2_CAPABLE(ha))
3421 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3423 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3424 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3426 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3429 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3433 if (!req->outstanding_cmds) {
3435 * Try to allocate a minimal size just so we can get through
3438 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3439 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3443 if (!req->outstanding_cmds) {
3444 ql_log(ql_log_fatal, NULL, 0x0126,
3445 "Failed to allocate memory for "
3446 "outstanding_cmds for req_que %p.\n", req);
3447 req->num_outstanding_cmds = 0;
3448 return QLA_FUNCTION_FAILED;
3455 #define PRINT_FIELD(_field, _flag, _str) { \
3456 if (a0->_field & _flag) {\
3462 len = snprintf(ptr, leftover, "%s", _str); \
3469 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3472 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3473 u8 str[STR_LEN], *ptr, p;
3476 memset(str, 0, STR_LEN);
3477 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3478 ql_dbg(ql_dbg_init, vha, 0x015a,
3479 "SFP MFG Name: %s\n", str);
3481 memset(str, 0, STR_LEN);
3482 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3483 ql_dbg(ql_dbg_init, vha, 0x015c,
3484 "SFP Part Name: %s\n", str);
3487 memset(str, 0, STR_LEN);
3491 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3492 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3493 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3494 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3495 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3496 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3497 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3498 ql_dbg(ql_dbg_init, vha, 0x0160,
3499 "SFP Media: %s\n", str);
3502 memset(str, 0, STR_LEN);
3506 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3507 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3508 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3509 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3510 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3511 ql_dbg(ql_dbg_init, vha, 0x0196,
3512 "SFP Link Length: %s\n", str);
3514 memset(str, 0, STR_LEN);
3518 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3519 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3520 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3521 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3522 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3523 ql_dbg(ql_dbg_init, vha, 0x016e,
3524 "SFP FC Link Tech: %s\n", str);
3527 ql_dbg(ql_dbg_init, vha, 0x016f,
3528 "SFP Distant: %d km\n", a0->length_km);
3529 if (a0->length_100m)
3530 ql_dbg(ql_dbg_init, vha, 0x0170,
3531 "SFP Distant: %d m\n", a0->length_100m*100);
3532 if (a0->length_50um_10m)
3533 ql_dbg(ql_dbg_init, vha, 0x0189,
3534 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3535 if (a0->length_62um_10m)
3536 ql_dbg(ql_dbg_init, vha, 0x018a,
3537 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3538 if (a0->length_om4_10m)
3539 ql_dbg(ql_dbg_init, vha, 0x0194,
3540 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3541 if (a0->length_om3_10m)
3542 ql_dbg(ql_dbg_init, vha, 0x0195,
3543 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3549 * QLA_SUCCESS: no action
3550 * QLA_INTERFACE_ERROR: SFP is not there.
3551 * QLA_FUNCTION_FAILED: detected New SFP
3554 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3556 int rc = QLA_SUCCESS;
3557 struct sff_8247_a0 *a;
3558 struct qla_hw_data *ha = vha->hw;
3560 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3563 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3567 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3568 qla2xxx_print_sfp_info(vha);
3570 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3572 ha->flags.detected_lr_sfp = 1;
3574 if (a->length_km > 5 || a->length_100m > 50)
3575 ha->long_range_distance = LR_DISTANCE_10K;
3577 ha->long_range_distance = LR_DISTANCE_5K;
3579 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3580 ql_dbg(ql_dbg_async, vha, 0x507b,
3581 "Detected Long Range SFP.\n");
3584 ha->flags.detected_lr_sfp = 0;
3585 if (ha->flags.using_lr_setting)
3586 ql_dbg(ql_dbg_async, vha, 0x5084,
3587 "Detected Short Range SFP.\n");
3590 if (!vha->flags.init_done)
3597 * qla2x00_setup_chip() - Load and start RISC firmware.
3600 * Returns 0 on success.
3603 qla2x00_setup_chip(scsi_qla_host_t *vha)
3606 uint32_t srisc_address = 0;
3607 struct qla_hw_data *ha = vha->hw;
3608 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3609 unsigned long flags;
3610 uint16_t fw_major_version;
3612 if (IS_P3P_TYPE(ha)) {
3613 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3614 if (rval == QLA_SUCCESS) {
3615 qla2x00_stop_firmware(vha);
3616 goto enable_82xx_npiv;
3621 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3622 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3623 spin_lock_irqsave(&ha->hardware_lock, flags);
3624 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3625 RD_REG_WORD(®->hccr);
3626 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3629 qla81xx_mpi_sync(vha);
3631 /* Load firmware sequences */
3632 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3633 if (rval == QLA_SUCCESS) {
3634 ql_dbg(ql_dbg_init, vha, 0x00c9,
3635 "Verifying Checksum of loaded RISC code.\n");
3637 rval = qla2x00_verify_checksum(vha, srisc_address);
3638 if (rval == QLA_SUCCESS) {
3639 /* Start firmware execution. */
3640 ql_dbg(ql_dbg_init, vha, 0x00ca,
3641 "Starting firmware.\n");
3644 ha->flags.exlogins_enabled = 1;
3646 if (qla_is_exch_offld_enabled(vha))
3647 ha->flags.exchoffld_enabled = 1;
3649 rval = qla2x00_execute_fw(vha, srisc_address);
3650 /* Retrieve firmware information. */
3651 if (rval == QLA_SUCCESS) {
3652 qla24xx_detect_sfp(vha);
3654 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3656 (ha->zio_mode == QLA_ZIO_MODE_6))
3657 qla27xx_set_zio_threshold(vha,
3658 ha->last_zio_threshold);
3660 rval = qla2x00_set_exlogins_buffer(vha);
3661 if (rval != QLA_SUCCESS)
3664 rval = qla2x00_set_exchoffld_buffer(vha);
3665 if (rval != QLA_SUCCESS)
3669 fw_major_version = ha->fw_major_version;
3670 if (IS_P3P_TYPE(ha))
3671 qla82xx_check_md_needed(vha);
3673 rval = qla2x00_get_fw_version(vha);
3674 if (rval != QLA_SUCCESS)
3676 ha->flags.npiv_supported = 0;
3677 if (IS_QLA2XXX_MIDTYPE(ha) &&
3678 (ha->fw_attributes & BIT_2)) {
3679 ha->flags.npiv_supported = 1;
3680 if ((!ha->max_npiv_vports) ||
3681 ((ha->max_npiv_vports + 1) %
3682 MIN_MULTI_ID_FABRIC))
3683 ha->max_npiv_vports =
3684 MIN_MULTI_ID_FABRIC - 1;
3686 qla2x00_get_resource_cnts(vha);
3689 * Allocate the array of outstanding commands
3690 * now that we know the firmware resources.
3692 rval = qla2x00_alloc_outstanding_cmds(ha,
3694 if (rval != QLA_SUCCESS)
3697 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3698 qla2x00_alloc_offload_mem(vha);
3700 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3701 qla2x00_alloc_fw_dump(vha);
3707 ql_log(ql_log_fatal, vha, 0x00cd,
3708 "ISP Firmware failed checksum.\n");
3714 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3715 /* Enable proper parity. */
3716 spin_lock_irqsave(&ha->hardware_lock, flags);
3719 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3721 /* SRAM, Instruction RAM and GP RAM parity */
3722 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3723 RD_REG_WORD(®->hccr);
3724 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3727 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3728 ha->flags.fac_supported = 1;
3729 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3732 rval = qla81xx_fac_get_sector_size(vha, &size);
3733 if (rval == QLA_SUCCESS) {
3734 ha->flags.fac_supported = 1;
3735 ha->fdt_block_size = size << 2;
3737 ql_log(ql_log_warn, vha, 0x00ce,
3738 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3739 ha->fw_major_version, ha->fw_minor_version,
3740 ha->fw_subminor_version);
3742 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3744 ha->flags.fac_supported = 0;
3751 ql_log(ql_log_fatal, vha, 0x00cf,
3752 "Setup chip ****FAILED****.\n");
3759 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3760 * @rsp: response queue
3762 * Beginning of request ring has initialization control block already built
3763 * by nvram config routine.
3765 * Returns 0 on success.
3768 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3773 rsp->ring_ptr = rsp->ring;
3774 rsp->ring_index = 0;
3775 rsp->status_srb = NULL;
3776 pkt = rsp->ring_ptr;
3777 for (cnt = 0; cnt < rsp->length; cnt++) {
3778 pkt->signature = RESPONSE_PROCESSED;
3784 * qla2x00_update_fw_options() - Read and process firmware options.
3787 * Returns 0 on success.
3790 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3792 uint16_t swing, emphasis, tx_sens, rx_sens;
3793 struct qla_hw_data *ha = vha->hw;
3795 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3796 qla2x00_get_fw_options(vha, ha->fw_options);
3798 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3801 /* Serial Link options. */
3802 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3803 "Serial link options.\n");
3804 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3805 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3807 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3808 if (ha->fw_seriallink_options[3] & BIT_2) {
3809 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3812 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3813 emphasis = (ha->fw_seriallink_options[2] &
3814 (BIT_4 | BIT_3)) >> 3;
3815 tx_sens = ha->fw_seriallink_options[0] &
3816 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3817 rx_sens = (ha->fw_seriallink_options[0] &
3818 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3819 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3820 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3823 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3824 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3825 ha->fw_options[10] |= BIT_5 |
3826 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3827 (tx_sens & (BIT_1 | BIT_0));
3830 swing = (ha->fw_seriallink_options[2] &
3831 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3832 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3833 tx_sens = ha->fw_seriallink_options[1] &
3834 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3835 rx_sens = (ha->fw_seriallink_options[1] &
3836 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3837 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3838 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3841 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3842 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3843 ha->fw_options[11] |= BIT_5 |
3844 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3845 (tx_sens & (BIT_1 | BIT_0));
3849 /* Return command IOCBs without waiting for an ABTS to complete. */
3850 ha->fw_options[3] |= BIT_13;
3853 if (ha->flags.enable_led_scheme)
3854 ha->fw_options[2] |= BIT_12;
3856 /* Detect ISP6312. */
3858 ha->fw_options[2] |= BIT_13;
3860 /* Set Retry FLOGI in case of P2P connection */
3861 if (ha->operating_mode == P2P) {
3862 ha->fw_options[2] |= BIT_3;
3863 ql_dbg(ql_dbg_disc, vha, 0x2100,
3864 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3865 __func__, ha->fw_options[2]);
3868 /* Update firmware options. */
3869 qla2x00_set_fw_options(vha, ha->fw_options);
3873 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3876 struct qla_hw_data *ha = vha->hw;
3878 if (IS_P3P_TYPE(ha))
3881 /* Hold status IOCBs until ABTS response received. */
3883 ha->fw_options[3] |= BIT_12;
3885 /* Set Retry FLOGI in case of P2P connection */
3886 if (ha->operating_mode == P2P) {
3887 ha->fw_options[2] |= BIT_3;
3888 ql_dbg(ql_dbg_disc, vha, 0x2101,
3889 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3890 __func__, ha->fw_options[2]);
3893 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3894 if (ql2xmvasynctoatio &&
3895 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3896 if (qla_tgt_mode_enabled(vha) ||
3897 qla_dual_mode_enabled(vha))
3898 ha->fw_options[2] |= BIT_11;
3900 ha->fw_options[2] &= ~BIT_11;
3903 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3906 * Tell FW to track each exchange to prevent
3907 * driver from using stale exchange.
3909 if (qla_tgt_mode_enabled(vha) ||
3910 qla_dual_mode_enabled(vha))
3911 ha->fw_options[2] |= BIT_4;
3913 ha->fw_options[2] &= ~BIT_4;
3915 /* Reserve 1/2 of emergency exchanges for ELS.*/
3916 if (qla2xuseresexchforels)
3917 ha->fw_options[2] |= BIT_8;
3919 ha->fw_options[2] &= ~BIT_8;
3922 ql_dbg(ql_dbg_init, vha, 0x00e8,
3923 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3924 __func__, ha->fw_options[1], ha->fw_options[2],
3925 ha->fw_options[3], vha->host->active_mode);
3927 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3928 qla2x00_set_fw_options(vha, ha->fw_options);
3930 /* Update Serial Link options. */
3931 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3934 rval = qla2x00_set_serdes_params(vha,
3935 le16_to_cpu(ha->fw_seriallink_options24[1]),
3936 le16_to_cpu(ha->fw_seriallink_options24[2]),
3937 le16_to_cpu(ha->fw_seriallink_options24[3]));
3938 if (rval != QLA_SUCCESS) {
3939 ql_log(ql_log_warn, vha, 0x0104,
3940 "Unable to update Serial Link options (%x).\n", rval);
3945 qla2x00_config_rings(struct scsi_qla_host *vha)
3947 struct qla_hw_data *ha = vha->hw;
3948 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3949 struct req_que *req = ha->req_q_map[0];
3950 struct rsp_que *rsp = ha->rsp_q_map[0];
3952 /* Setup ring parameters in initialization control block. */
3953 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3954 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3955 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3956 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3957 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3958 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3960 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3961 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3962 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3963 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3964 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3968 qla24xx_config_rings(struct scsi_qla_host *vha)
3970 struct qla_hw_data *ha = vha->hw;
3971 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3972 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3973 struct qla_msix_entry *msix;
3974 struct init_cb_24xx *icb;
3976 struct req_que *req = ha->req_q_map[0];
3977 struct rsp_que *rsp = ha->rsp_q_map[0];
3979 /* Setup ring parameters in initialization control block. */
3980 icb = (struct init_cb_24xx *)ha->init_cb;
3981 icb->request_q_outpointer = cpu_to_le16(0);
3982 icb->response_q_inpointer = cpu_to_le16(0);
3983 icb->request_q_length = cpu_to_le16(req->length);
3984 icb->response_q_length = cpu_to_le16(rsp->length);
3985 put_unaligned_le64(req->dma, &icb->request_q_address);
3986 put_unaligned_le64(rsp->dma, &icb->response_q_address);
3988 /* Setup ATIO queue dma pointers for target mode */
3989 icb->atio_q_inpointer = cpu_to_le16(0);
3990 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3991 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
3993 if (IS_SHADOW_REG_CAPABLE(ha))
3994 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3996 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3998 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3999 icb->rid = cpu_to_le16(rid);
4000 if (ha->flags.msix_enabled) {
4001 msix = &ha->msix_entries[1];
4002 ql_dbg(ql_dbg_init, vha, 0x0019,
4003 "Registering vector 0x%x for base que.\n",
4005 icb->msix = cpu_to_le16(msix->entry);
4007 /* Use alternate PCI bus number */
4009 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4010 /* Use alternate PCI devfn */
4012 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4014 /* Use Disable MSIX Handshake mode for capable adapters */
4015 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4016 (ha->flags.msix_enabled)) {
4017 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4018 ha->flags.disable_msix_handshake = 1;
4019 ql_dbg(ql_dbg_init, vha, 0x00fe,
4020 "MSIX Handshake Disable Mode turned on.\n");
4022 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4024 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4026 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
4027 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
4028 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
4029 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4031 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4032 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4033 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4034 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4037 qlt_24xx_config_rings(vha);
4039 /* If the user has configured the speed, set it here */
4040 if (ha->set_data_rate) {
4041 ql_dbg(ql_dbg_init, vha, 0x00fd,
4042 "Speed set by user : %s Gbps \n",
4043 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4044 icb->firmware_options_3 = (ha->set_data_rate << 13);
4048 RD_REG_DWORD(&ioreg->hccr);
4052 * qla2x00_init_rings() - Initializes firmware.
4055 * Beginning of request ring has initialization control block already built
4056 * by nvram config routine.
4058 * Returns 0 on success.
4061 qla2x00_init_rings(scsi_qla_host_t *vha)
4064 unsigned long flags = 0;
4066 struct qla_hw_data *ha = vha->hw;
4067 struct req_que *req;
4068 struct rsp_que *rsp;
4069 struct mid_init_cb_24xx *mid_init_cb =
4070 (struct mid_init_cb_24xx *) ha->init_cb;
4072 spin_lock_irqsave(&ha->hardware_lock, flags);
4074 /* Clear outstanding commands array. */
4075 for (que = 0; que < ha->max_req_queues; que++) {
4076 req = ha->req_q_map[que];
4077 if (!req || !test_bit(que, ha->req_qid_map))
4079 req->out_ptr = (void *)(req->ring + req->length);
4081 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4082 req->outstanding_cmds[cnt] = NULL;
4084 req->current_outstanding_cmd = 1;
4086 /* Initialize firmware. */
4087 req->ring_ptr = req->ring;
4088 req->ring_index = 0;
4089 req->cnt = req->length;
4092 for (que = 0; que < ha->max_rsp_queues; que++) {
4093 rsp = ha->rsp_q_map[que];
4094 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4096 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4098 /* Initialize response queue entries */
4100 qlafx00_init_response_q_entries(rsp);
4102 qla2x00_init_response_q_entries(rsp);
4105 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4106 ha->tgt.atio_ring_index = 0;
4107 /* Initialize ATIO queue entries */
4108 qlt_init_atio_q_entries(vha);
4110 ha->isp_ops->config_rings(vha);
4112 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4114 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4116 if (IS_QLAFX00(ha)) {
4117 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4121 /* Update any ISP specific firmware options before initialization. */
4122 ha->isp_ops->update_fw_options(vha);
4124 if (ha->flags.npiv_supported) {
4125 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4126 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4127 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4130 if (IS_FWI2_CAPABLE(ha)) {
4131 mid_init_cb->options = cpu_to_le16(BIT_1);
4132 mid_init_cb->init_cb.execution_throttle =
4133 cpu_to_le16(ha->cur_fw_xcb_count);
4134 ha->flags.dport_enabled =
4135 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4136 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4137 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4138 /* FA-WWPN Status */
4139 ha->flags.fawwpn_enabled =
4140 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4141 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4142 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4145 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4148 ql_log(ql_log_fatal, vha, 0x00d2,
4149 "Init Firmware **** FAILED ****.\n");
4151 ql_dbg(ql_dbg_init, vha, 0x00d3,
4152 "Init Firmware -- success.\n");
4154 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4161 * qla2x00_fw_ready() - Waits for firmware ready.
4164 * Returns 0 on success.
4167 qla2x00_fw_ready(scsi_qla_host_t *vha)
4170 unsigned long wtime, mtime, cs84xx_time;
4171 uint16_t min_wait; /* Minimum wait time if loop is down */
4172 uint16_t wait_time; /* Wait time if loop is coming ready */
4174 struct qla_hw_data *ha = vha->hw;
4176 if (IS_QLAFX00(vha->hw))
4177 return qlafx00_fw_ready(vha);
4181 /* Time to wait for loop down */
4182 if (IS_P3P_TYPE(ha))
4188 * Firmware should take at most one RATOV to login, plus 5 seconds for
4189 * our own processing.
4191 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4192 wait_time = min_wait;
4195 /* Min wait time if loop down */
4196 mtime = jiffies + (min_wait * HZ);
4198 /* wait time before firmware ready */
4199 wtime = jiffies + (wait_time * HZ);
4201 /* Wait for ISP to finish LIP */
4202 if (!vha->flags.init_done)
4203 ql_log(ql_log_info, vha, 0x801e,
4204 "Waiting for LIP to complete.\n");
4207 memset(state, -1, sizeof(state));
4208 rval = qla2x00_get_firmware_state(vha, state);
4209 if (rval == QLA_SUCCESS) {
4210 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4211 vha->device_flags &= ~DFLG_NO_CABLE;
4213 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4214 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4215 "fw_state=%x 84xx=%x.\n", state[0],
4217 if ((state[2] & FSTATE_LOGGED_IN) &&
4218 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4219 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4220 "Sending verify iocb.\n");
4222 cs84xx_time = jiffies;
4223 rval = qla84xx_init_chip(vha);
4224 if (rval != QLA_SUCCESS) {
4227 "Init chip failed.\n");
4231 /* Add time taken to initialize. */
4232 cs84xx_time = jiffies - cs84xx_time;
4233 wtime += cs84xx_time;
4234 mtime += cs84xx_time;
4235 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4236 "Increasing wait time by %ld. "
4237 "New time %ld.\n", cs84xx_time,
4240 } else if (state[0] == FSTATE_READY) {
4241 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4242 "F/W Ready - OK.\n");
4244 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4245 &ha->login_timeout, &ha->r_a_tov);
4251 rval = QLA_FUNCTION_FAILED;
4253 if (atomic_read(&vha->loop_down_timer) &&
4254 state[0] != FSTATE_READY) {
4255 /* Loop down. Timeout on min_wait for states
4256 * other than Wait for Login.
4258 if (time_after_eq(jiffies, mtime)) {
4259 ql_log(ql_log_info, vha, 0x8038,
4260 "Cable is unplugged...\n");
4262 vha->device_flags |= DFLG_NO_CABLE;
4267 /* Mailbox cmd failed. Timeout on min_wait. */
4268 if (time_after_eq(jiffies, mtime) ||
4269 ha->flags.isp82xx_fw_hung)
4273 if (time_after_eq(jiffies, wtime))
4276 /* Delay for a while */
4280 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4281 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4282 state[1], state[2], state[3], state[4], state[5], jiffies);
4284 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4285 ql_log(ql_log_warn, vha, 0x803b,
4286 "Firmware ready **** FAILED ****.\n");
4293 * qla2x00_configure_hba
4294 * Setup adapter context.
4297 * ha = adapter state pointer.
4306 qla2x00_configure_hba(scsi_qla_host_t *vha)
4315 char connect_type[22];
4316 struct qla_hw_data *ha = vha->hw;
4317 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4319 unsigned long flags;
4321 /* Get host addresses. */
4322 rval = qla2x00_get_adapter_id(vha,
4323 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4324 if (rval != QLA_SUCCESS) {
4325 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4326 IS_CNA_CAPABLE(ha) ||
4327 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4328 ql_dbg(ql_dbg_disc, vha, 0x2008,
4329 "Loop is in a transition state.\n");
4331 ql_log(ql_log_warn, vha, 0x2009,
4332 "Unable to get host loop ID.\n");
4333 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4334 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4335 ql_log(ql_log_warn, vha, 0x1151,
4336 "Doing link init.\n");
4337 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4340 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4346 ql_log(ql_log_info, vha, 0x200a,
4347 "Cannot get topology - retrying.\n");
4348 return (QLA_FUNCTION_FAILED);
4351 vha->loop_id = loop_id;
4354 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4355 ha->operating_mode = LOOP;
4360 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4361 ha->current_topology = ISP_CFG_NL;
4362 strcpy(connect_type, "(Loop)");
4366 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4367 ha->switch_cap = sw_cap;
4368 ha->current_topology = ISP_CFG_FL;
4369 strcpy(connect_type, "(FL_Port)");
4373 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4374 ha->operating_mode = P2P;
4375 ha->current_topology = ISP_CFG_N;
4376 strcpy(connect_type, "(N_Port-to-N_Port)");
4380 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4381 ha->switch_cap = sw_cap;
4382 ha->operating_mode = P2P;
4383 ha->current_topology = ISP_CFG_F;
4384 strcpy(connect_type, "(F_Port)");
4388 ql_dbg(ql_dbg_disc, vha, 0x200f,
4389 "HBA in unknown topology %x, using NL.\n", topo);
4390 ha->current_topology = ISP_CFG_NL;
4391 strcpy(connect_type, "(Loop)");
4395 /* Save Host port and loop ID. */
4396 /* byte order - Big Endian */
4397 id.b.domain = domain;
4401 spin_lock_irqsave(&ha->hardware_lock, flags);
4402 if (!(topo == 2 && ha->flags.n2n_bigger))
4403 qlt_update_host_map(vha, id);
4404 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4406 if (!vha->flags.init_done)
4407 ql_log(ql_log_info, vha, 0x2010,
4408 "Topology - %s, Host Loop address 0x%x.\n",
4409 connect_type, vha->loop_id);
4415 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4420 uint64_t zero[2] = { 0 };
4421 struct qla_hw_data *ha = vha->hw;
4422 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4423 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4425 if (len > sizeof(zero))
4427 if (memcmp(model, &zero, len) != 0) {
4428 memcpy(ha->model_number, model, len);
4429 st = en = ha->model_number;
4432 if (*en != 0x20 && *en != 0x00)
4437 index = (ha->pdev->subsystem_device & 0xff);
4439 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4440 index < QLA_MODEL_NAMES)
4441 strlcpy(ha->model_desc,
4442 qla2x00_model_name[index * 2 + 1],
4443 sizeof(ha->model_desc));
4445 index = (ha->pdev->subsystem_device & 0xff);
4447 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4448 index < QLA_MODEL_NAMES) {
4449 strlcpy(ha->model_number,
4450 qla2x00_model_name[index * 2],
4451 sizeof(ha->model_number));
4452 strlcpy(ha->model_desc,
4453 qla2x00_model_name[index * 2 + 1],
4454 sizeof(ha->model_desc));
4456 strlcpy(ha->model_number, def,
4457 sizeof(ha->model_number));
4460 if (IS_FWI2_CAPABLE(ha))
4461 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4462 sizeof(ha->model_desc));
4465 /* On sparc systems, obtain port and node WWN from firmware
4468 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4471 struct qla_hw_data *ha = vha->hw;
4472 struct pci_dev *pdev = ha->pdev;
4473 struct device_node *dp = pci_device_to_OF_node(pdev);
4477 val = of_get_property(dp, "port-wwn", &len);
4478 if (val && len >= WWN_SIZE)
4479 memcpy(nv->port_name, val, WWN_SIZE);
4481 val = of_get_property(dp, "node-wwn", &len);
4482 if (val && len >= WWN_SIZE)
4483 memcpy(nv->node_name, val, WWN_SIZE);
4488 * NVRAM configuration for ISP 2xxx
4491 * ha = adapter block pointer.
4494 * initialization control block in response_ring
4495 * host adapters parameters in host adapter block
4501 qla2x00_nvram_config(scsi_qla_host_t *vha)
4506 uint8_t *dptr1, *dptr2;
4507 struct qla_hw_data *ha = vha->hw;
4508 init_cb_t *icb = ha->init_cb;
4509 nvram_t *nv = ha->nvram;
4510 uint8_t *ptr = ha->nvram;
4511 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4515 /* Determine NVRAM starting address. */
4516 ha->nvram_size = sizeof(*nv);
4518 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4519 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4520 ha->nvram_base = 0x80;
4522 /* Get NVRAM data and calculate checksum. */
4523 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4524 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4527 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4528 "Contents of NVRAM.\n");
4529 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4530 nv, ha->nvram_size);
4532 /* Bad NVRAM data, set defaults parameters. */
4533 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4534 nv->nvram_version < 1) {
4535 /* Reset NVRAM data. */
4536 ql_log(ql_log_warn, vha, 0x0064,
4537 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4538 chksum, nv->id, nv->nvram_version);
4539 ql_log(ql_log_warn, vha, 0x0065,
4541 "functioning (yet invalid -- WWPN) defaults.\n");
4544 * Set default initialization control block.
4546 memset(nv, 0, ha->nvram_size);
4547 nv->parameter_block_version = ICB_VERSION;
4549 if (IS_QLA23XX(ha)) {
4550 nv->firmware_options[0] = BIT_2 | BIT_1;
4551 nv->firmware_options[1] = BIT_7 | BIT_5;
4552 nv->add_firmware_options[0] = BIT_5;
4553 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4554 nv->frame_payload_size = 2048;
4555 nv->special_options[1] = BIT_7;
4556 } else if (IS_QLA2200(ha)) {
4557 nv->firmware_options[0] = BIT_2 | BIT_1;
4558 nv->firmware_options[1] = BIT_7 | BIT_5;
4559 nv->add_firmware_options[0] = BIT_5;
4560 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4561 nv->frame_payload_size = 1024;
4562 } else if (IS_QLA2100(ha)) {
4563 nv->firmware_options[0] = BIT_3 | BIT_1;
4564 nv->firmware_options[1] = BIT_5;
4565 nv->frame_payload_size = 1024;
4568 nv->max_iocb_allocation = cpu_to_le16(256);
4569 nv->execution_throttle = cpu_to_le16(16);
4570 nv->retry_count = 8;
4571 nv->retry_delay = 1;
4573 nv->port_name[0] = 33;
4574 nv->port_name[3] = 224;
4575 nv->port_name[4] = 139;
4577 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4579 nv->login_timeout = 4;
4582 * Set default host adapter parameters
4584 nv->host_p[1] = BIT_2;
4585 nv->reset_delay = 5;
4586 nv->port_down_retry_count = 8;
4587 nv->max_luns_per_target = cpu_to_le16(8);
4588 nv->link_down_timeout = 60;
4593 /* Reset Initialization control block */
4594 memset(icb, 0, ha->init_cb_size);
4597 * Setup driver NVRAM options.
4599 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4600 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4601 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4602 nv->firmware_options[1] &= ~BIT_4;
4604 if (IS_QLA23XX(ha)) {
4605 nv->firmware_options[0] |= BIT_2;
4606 nv->firmware_options[0] &= ~BIT_3;
4607 nv->special_options[0] &= ~BIT_6;
4608 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4610 if (IS_QLA2300(ha)) {
4611 if (ha->fb_rev == FPM_2310) {
4612 strcpy(ha->model_number, "QLA2310");
4614 strcpy(ha->model_number, "QLA2300");
4617 qla2x00_set_model_info(vha, nv->model_number,
4618 sizeof(nv->model_number), "QLA23xx");
4620 } else if (IS_QLA2200(ha)) {
4621 nv->firmware_options[0] |= BIT_2;
4623 * 'Point-to-point preferred, else loop' is not a safe
4624 * connection mode setting.
4626 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4628 /* Force 'loop preferred, else point-to-point'. */
4629 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4630 nv->add_firmware_options[0] |= BIT_5;
4632 strcpy(ha->model_number, "QLA22xx");
4633 } else /*if (IS_QLA2100(ha))*/ {
4634 strcpy(ha->model_number, "QLA2100");
4638 * Copy over NVRAM RISC parameter block to initialization control block.
4640 dptr1 = (uint8_t *)icb;
4641 dptr2 = (uint8_t *)&nv->parameter_block_version;
4642 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4644 *dptr1++ = *dptr2++;
4646 /* Copy 2nd half. */
4647 dptr1 = (uint8_t *)icb->add_firmware_options;
4648 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4650 *dptr1++ = *dptr2++;
4651 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4652 /* Use alternate WWN? */
4653 if (nv->host_p[1] & BIT_7) {
4654 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4655 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4658 /* Prepare nodename */
4659 if ((icb->firmware_options[1] & BIT_6) == 0) {
4661 * Firmware will apply the following mask if the nodename was
4664 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4665 icb->node_name[0] &= 0xF0;
4669 * Set host adapter parameters.
4673 * BIT_7 in the host-parameters section allows for modification to
4674 * internal driver logging.
4676 if (nv->host_p[0] & BIT_7)
4677 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4678 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4679 /* Always load RISC code on non ISP2[12]00 chips. */
4680 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4681 ha->flags.disable_risc_code_load = 0;
4682 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4683 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4684 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4685 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4686 ha->flags.disable_serdes = 0;
4688 ha->operating_mode =
4689 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4691 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4692 sizeof(ha->fw_seriallink_options));
4694 /* save HBA serial number */
4695 ha->serial0 = icb->port_name[5];
4696 ha->serial1 = icb->port_name[6];
4697 ha->serial2 = icb->port_name[7];
4698 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4699 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4701 icb->execution_throttle = cpu_to_le16(0xFFFF);
4703 ha->retry_count = nv->retry_count;
4705 /* Set minimum login_timeout to 4 seconds. */
4706 if (nv->login_timeout != ql2xlogintimeout)
4707 nv->login_timeout = ql2xlogintimeout;
4708 if (nv->login_timeout < 4)
4709 nv->login_timeout = 4;
4710 ha->login_timeout = nv->login_timeout;
4712 /* Set minimum RATOV to 100 tenths of a second. */
4715 ha->loop_reset_delay = nv->reset_delay;
4717 /* Link Down Timeout = 0:
4719 * When Port Down timer expires we will start returning
4720 * I/O's to OS with "DID_NO_CONNECT".
4722 * Link Down Timeout != 0:
4724 * The driver waits for the link to come up after link down
4725 * before returning I/Os to OS with "DID_NO_CONNECT".
4727 if (nv->link_down_timeout == 0) {
4728 ha->loop_down_abort_time =
4729 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4731 ha->link_down_timeout = nv->link_down_timeout;
4732 ha->loop_down_abort_time =
4733 (LOOP_DOWN_TIME - ha->link_down_timeout);
4737 * Need enough time to try and get the port back.
4739 ha->port_down_retry_count = nv->port_down_retry_count;
4740 if (qlport_down_retry)
4741 ha->port_down_retry_count = qlport_down_retry;
4742 /* Set login_retry_count */
4743 ha->login_retry_count = nv->retry_count;
4744 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4745 ha->port_down_retry_count > 3)
4746 ha->login_retry_count = ha->port_down_retry_count;
4747 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4748 ha->login_retry_count = ha->port_down_retry_count;
4749 if (ql2xloginretrycount)
4750 ha->login_retry_count = ql2xloginretrycount;
4752 icb->lun_enables = cpu_to_le16(0);
4753 icb->command_resource_count = 0;
4754 icb->immediate_notify_resource_count = 0;
4755 icb->timeout = cpu_to_le16(0);
4757 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4759 icb->firmware_options[0] &= ~BIT_3;
4760 icb->add_firmware_options[0] &=
4761 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4762 icb->add_firmware_options[0] |= BIT_2;
4763 icb->response_accumulation_timer = 3;
4764 icb->interrupt_delay_timer = 5;
4766 vha->flags.process_response_queue = 1;
4769 if (!vha->flags.init_done) {
4770 ha->zio_mode = icb->add_firmware_options[0] &
4771 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4772 ha->zio_timer = icb->interrupt_delay_timer ?
4773 icb->interrupt_delay_timer : 2;
4775 icb->add_firmware_options[0] &=
4776 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4777 vha->flags.process_response_queue = 0;
4778 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4779 ha->zio_mode = QLA_ZIO_MODE_6;
4781 ql_log(ql_log_info, vha, 0x0068,
4782 "ZIO mode %d enabled; timer delay (%d us).\n",
4783 ha->zio_mode, ha->zio_timer * 100);
4785 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4786 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4787 vha->flags.process_response_queue = 1;
4792 ql_log(ql_log_warn, vha, 0x0069,
4793 "NVRAM configuration failed.\n");
4799 qla2x00_rport_del(void *data)
4801 fc_port_t *fcport = data;
4802 struct fc_rport *rport;
4803 unsigned long flags;
4805 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4806 rport = fcport->drport ? fcport->drport : fcport->rport;
4807 fcport->drport = NULL;
4808 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4810 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4811 "%s %8phN. rport %p roles %x\n",
4812 __func__, fcport->port_name, rport,
4815 fc_remote_port_delete(rport);
4819 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4823 old_state = atomic_read(&fcport->state);
4824 atomic_set(&fcport->state, state);
4826 /* Don't print state transitions during initial allocation of fcport */
4827 if (old_state && old_state != state) {
4828 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4829 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4830 fcport->port_name, port_state_str[old_state],
4831 port_state_str[state], fcport->d_id.b.domain,
4832 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4837 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4839 * @flags: allocation flags
4841 * Returns a pointer to the allocated fcport, or NULL, if none available.
4844 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4848 fcport = kzalloc(sizeof(fc_port_t), flags);
4852 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4853 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4855 if (!fcport->ct_desc.ct_sns) {
4856 ql_log(ql_log_warn, vha, 0xd049,
4857 "Failed to allocate ct_sns request.\n");
4862 /* Setup fcport template structure. */
4864 fcport->port_type = FCT_UNKNOWN;
4865 fcport->loop_id = FC_NO_LOOP_ID;
4866 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4867 fcport->supported_classes = FC_COS_UNSPECIFIED;
4868 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4870 fcport->disc_state = DSC_DELETED;
4871 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4872 fcport->deleted = QLA_SESS_DELETED;
4873 fcport->login_retry = vha->hw->login_retry_count;
4874 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4875 fcport->logout_on_delete = 1;
4877 if (!fcport->ct_desc.ct_sns) {
4878 ql_log(ql_log_warn, vha, 0xd049,
4879 "Failed to allocate ct_sns request.\n");
4884 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4885 INIT_WORK(&fcport->free_work, qlt_free_session_done);
4886 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4887 INIT_LIST_HEAD(&fcport->gnl_entry);
4888 INIT_LIST_HEAD(&fcport->list);
4894 qla2x00_free_fcport(fc_port_t *fcport)
4896 if (fcport->ct_desc.ct_sns) {
4897 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4898 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4899 fcport->ct_desc.ct_sns_dma);
4901 fcport->ct_desc.ct_sns = NULL;
4903 list_del(&fcport->list);
4904 qla2x00_clear_loop_id(fcport);
4909 * qla2x00_configure_loop
4910 * Updates Fibre Channel Device Database with what is actually on loop.
4913 * ha = adapter block pointer.
4918 * 2 = database was full and device was not configured.
4921 qla2x00_configure_loop(scsi_qla_host_t *vha)
4924 unsigned long flags, save_flags;
4925 struct qla_hw_data *ha = vha->hw;
4929 /* Get Initiator ID */
4930 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4931 rval = qla2x00_configure_hba(vha);
4932 if (rval != QLA_SUCCESS) {
4933 ql_dbg(ql_dbg_disc, vha, 0x2013,
4934 "Unable to configure HBA.\n");
4939 save_flags = flags = vha->dpc_flags;
4940 ql_dbg(ql_dbg_disc, vha, 0x2014,
4941 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4944 * If we have both an RSCN and PORT UPDATE pending then handle them
4945 * both at the same time.
4947 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4948 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4950 qla2x00_get_data_rate(vha);
4952 /* Determine what we need to do */
4953 if ((ha->current_topology == ISP_CFG_FL ||
4954 ha->current_topology == ISP_CFG_F) &&
4955 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4957 set_bit(RSCN_UPDATE, &flags);
4958 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4960 } else if (ha->current_topology == ISP_CFG_NL ||
4961 ha->current_topology == ISP_CFG_N) {
4962 clear_bit(RSCN_UPDATE, &flags);
4963 set_bit(LOCAL_LOOP_UPDATE, &flags);
4964 } else if (!vha->flags.online ||
4965 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4966 set_bit(RSCN_UPDATE, &flags);
4967 set_bit(LOCAL_LOOP_UPDATE, &flags);
4970 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4971 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4972 ql_dbg(ql_dbg_disc, vha, 0x2015,
4973 "Loop resync needed, failing.\n");
4974 rval = QLA_FUNCTION_FAILED;
4976 rval = qla2x00_configure_local_loop(vha);
4979 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4980 if (LOOP_TRANSITION(vha)) {
4981 ql_dbg(ql_dbg_disc, vha, 0x2099,
4982 "Needs RSCN update and loop transition.\n");
4983 rval = QLA_FUNCTION_FAILED;
4986 rval = qla2x00_configure_fabric(vha);
4989 if (rval == QLA_SUCCESS) {
4990 if (atomic_read(&vha->loop_down_timer) ||
4991 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4992 rval = QLA_FUNCTION_FAILED;
4994 atomic_set(&vha->loop_state, LOOP_READY);
4995 ql_dbg(ql_dbg_disc, vha, 0x2069,
4997 ha->flags.fw_init_done = 1;
5000 * Process any ATIO queue entries that came in
5001 * while we weren't online.
5003 if (qla_tgt_mode_enabled(vha) ||
5004 qla_dual_mode_enabled(vha)) {
5005 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5006 qlt_24xx_process_atio_queue(vha, 0);
5007 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5014 ql_dbg(ql_dbg_disc, vha, 0x206a,
5015 "%s *** FAILED ***.\n", __func__);
5017 ql_dbg(ql_dbg_disc, vha, 0x206b,
5018 "%s: exiting normally.\n", __func__);
5021 /* Restore state if a resync event occurred during processing */
5022 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5023 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5024 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5025 if (test_bit(RSCN_UPDATE, &save_flags)) {
5026 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5034 * qla2x00_configure_local_loop
5035 * Updates Fibre Channel Device Database with local loop devices.
5038 * ha = adapter block pointer.
5044 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5049 fc_port_t *fcport, *new_fcport;
5053 struct gid_list_info *gid;
5055 uint8_t domain, area, al_pa;
5056 struct qla_hw_data *ha = vha->hw;
5057 unsigned long flags;
5059 /* Inititae N2N login. */
5061 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5065 memset(ha->init_cb, 0, ha->init_cb_size);
5066 sz = min_t(int, sizeof(struct els_plogi_payload),
5068 rval = qla24xx_get_port_login_templ(vha,
5069 ha->init_cb_dma, (void *)ha->init_cb, sz);
5070 if (rval == QLA_SUCCESS) {
5071 bp = (uint32_t *)ha->init_cb;
5072 for (i = 0; i < sz/4 ; i++, bp++)
5073 *bp = cpu_to_be32(*bp);
5075 memcpy(&ha->plogi_els_payld.data,
5076 (void *)ha->init_cb,
5077 sizeof(ha->plogi_els_payld.data));
5079 ql_dbg(ql_dbg_init, vha, 0x00d1,
5080 "PLOGI ELS param read fail.\n");
5085 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5086 if (fcport->n2n_flag) {
5087 qla24xx_fcport_handle_login(vha, fcport);
5092 spin_lock_irqsave(&vha->work_lock, flags);
5093 vha->scan.scan_retry++;
5094 spin_unlock_irqrestore(&vha->work_lock, flags);
5096 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5097 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5098 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5104 entries = MAX_FIBRE_DEVICES_LOOP;
5106 /* Get list of logged in devices. */
5107 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5108 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5110 if (rval != QLA_SUCCESS)
5113 ql_dbg(ql_dbg_disc, vha, 0x2011,
5114 "Entries in ID list (%d).\n", entries);
5115 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5116 ha->gid_list, entries * sizeof(*ha->gid_list));
5119 spin_lock_irqsave(&vha->work_lock, flags);
5120 vha->scan.scan_retry++;
5121 spin_unlock_irqrestore(&vha->work_lock, flags);
5123 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5124 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5125 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5128 vha->scan.scan_retry = 0;
5131 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5132 fcport->scan_state = QLA_FCPORT_SCAN;
5135 /* Allocate temporary fcport for any new fcports discovered. */
5136 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5137 if (new_fcport == NULL) {
5138 ql_log(ql_log_warn, vha, 0x2012,
5139 "Memory allocation failed for fcport.\n");
5140 rval = QLA_MEMORY_ALLOC_FAILED;
5143 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5145 /* Add devices to port list. */
5147 for (index = 0; index < entries; index++) {
5148 domain = gid->domain;
5151 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5152 loop_id = gid->loop_id_2100;
5154 loop_id = le16_to_cpu(gid->loop_id);
5155 gid = (void *)gid + ha->gid_list_info_size;
5157 /* Bypass reserved domain fields. */
5158 if ((domain & 0xf0) == 0xf0)
5161 /* Bypass if not same domain and area of adapter. */
5162 if (area && domain && ((area != vha->d_id.b.area) ||
5163 (domain != vha->d_id.b.domain)) &&
5164 (ha->current_topology == ISP_CFG_NL))
5168 /* Bypass invalid local loop ID. */
5169 if (loop_id > LAST_LOCAL_LOOP_ID)
5172 memset(new_fcport->port_name, 0, WWN_SIZE);
5174 /* Fill in member data. */
5175 new_fcport->d_id.b.domain = domain;
5176 new_fcport->d_id.b.area = area;
5177 new_fcport->d_id.b.al_pa = al_pa;
5178 new_fcport->loop_id = loop_id;
5179 new_fcport->scan_state = QLA_FCPORT_FOUND;
5181 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5182 if (rval2 != QLA_SUCCESS) {
5183 ql_dbg(ql_dbg_disc, vha, 0x2097,
5184 "Failed to retrieve fcport information "
5185 "-- get_port_database=%x, loop_id=0x%04x.\n",
5186 rval2, new_fcport->loop_id);
5187 /* Skip retry if N2N */
5188 if (ha->current_topology != ISP_CFG_N) {
5189 ql_dbg(ql_dbg_disc, vha, 0x2105,
5190 "Scheduling resync.\n");
5191 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5196 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5197 /* Check for matching device in port list. */
5200 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5201 if (memcmp(new_fcport->port_name, fcport->port_name,
5205 fcport->flags &= ~FCF_FABRIC_DEVICE;
5206 fcport->loop_id = new_fcport->loop_id;
5207 fcport->port_type = new_fcport->port_type;
5208 fcport->d_id.b24 = new_fcport->d_id.b24;
5209 memcpy(fcport->node_name, new_fcport->node_name,
5211 fcport->scan_state = QLA_FCPORT_FOUND;
5217 /* New device, add to fcports list. */
5218 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5220 /* Allocate a new replacement fcport. */
5221 fcport = new_fcport;
5223 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5225 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5227 if (new_fcport == NULL) {
5228 ql_log(ql_log_warn, vha, 0xd031,
5229 "Failed to allocate memory for fcport.\n");
5230 rval = QLA_MEMORY_ALLOC_FAILED;
5233 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5234 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5237 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5239 /* Base iIDMA settings on HBA port speed. */
5240 fcport->fp_speed = ha->link_data_rate;
5245 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5246 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5249 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5250 if ((qla_dual_mode_enabled(vha) ||
5251 qla_ini_mode_enabled(vha)) &&
5252 atomic_read(&fcport->state) == FCS_ONLINE) {
5253 qla2x00_mark_device_lost(vha, fcport,
5254 ql2xplogiabsentdevice);
5255 if (fcport->loop_id != FC_NO_LOOP_ID &&
5256 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5257 fcport->port_type != FCT_INITIATOR &&
5258 fcport->port_type != FCT_BROADCAST) {
5259 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5260 "%s %d %8phC post del sess\n",
5264 qlt_schedule_sess_for_deletion(fcport);
5270 if (fcport->scan_state == QLA_FCPORT_FOUND)
5271 qla24xx_fcport_handle_login(vha, fcport);
5274 qla2x00_free_fcport(new_fcport);
5279 ql_dbg(ql_dbg_disc, vha, 0x2098,
5280 "Configure local loop error exit: rval=%x.\n", rval);
5285 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5288 uint16_t mb[MAILBOX_REGISTER_COUNT];
5289 struct qla_hw_data *ha = vha->hw;
5291 if (!IS_IIDMA_CAPABLE(ha))
5294 if (atomic_read(&fcport->state) != FCS_ONLINE)
5297 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5298 fcport->fp_speed > ha->link_data_rate ||
5299 !ha->flags.gpsc_supported)
5302 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5304 if (rval != QLA_SUCCESS) {
5305 ql_dbg(ql_dbg_disc, vha, 0x2004,
5306 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5307 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5309 ql_dbg(ql_dbg_disc, vha, 0x2005,
5310 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5311 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5312 fcport->fp_speed, fcport->port_name);
5316 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5318 qla2x00_iidma_fcport(vha, fcport);
5319 qla24xx_update_fcport_fcp_prio(vha, fcport);
5322 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5324 struct qla_work_evt *e;
5326 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5328 return QLA_FUNCTION_FAILED;
5330 e->u.fcport.fcport = fcport;
5331 return qla2x00_post_work(vha, e);
5334 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5336 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5338 struct fc_rport_identifiers rport_ids;
5339 struct fc_rport *rport;
5340 unsigned long flags;
5342 if (atomic_read(&fcport->state) == FCS_ONLINE)
5345 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5346 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5347 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5348 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5349 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5350 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5352 ql_log(ql_log_warn, vha, 0x2006,
5353 "Unable to allocate fc remote port.\n");
5357 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5358 *((fc_port_t **)rport->dd_data) = fcport;
5359 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5361 rport->supported_classes = fcport->supported_classes;
5363 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5364 if (fcport->port_type == FCT_INITIATOR)
5365 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5366 if (fcport->port_type == FCT_TARGET)
5367 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5368 if (fcport->port_type & FCT_NVME_INITIATOR)
5369 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5370 if (fcport->port_type & FCT_NVME_TARGET)
5371 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5372 if (fcport->port_type & FCT_NVME_DISCOVERY)
5373 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5375 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5376 "%s %8phN. rport %p is %s mode\n",
5377 __func__, fcport->port_name, rport,
5378 (fcport->port_type == FCT_TARGET) ? "tgt" :
5379 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5381 fc_remote_port_rolechg(rport, rport_ids.roles);
5385 * qla2x00_update_fcport
5386 * Updates device on list.
5389 * ha = adapter block pointer.
5390 * fcport = port structure pointer.
5400 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5402 if (IS_SW_RESV_ADDR(fcport->d_id))
5405 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5406 __func__, fcport->port_name);
5408 qla2x00_set_fcport_disc_state(fcport, DSC_UPD_FCPORT);
5409 fcport->login_retry = vha->hw->login_retry_count;
5410 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5411 fcport->deleted = 0;
5412 if (vha->hw->current_topology == ISP_CFG_NL)
5413 fcport->logout_on_delete = 0;
5415 fcport->logout_on_delete = 1;
5416 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5418 switch (vha->hw->current_topology) {
5421 fcport->keep_nport_handle = 1;
5427 qla2x00_iidma_fcport(vha, fcport);
5429 if (NVME_TARGET(vha->hw, fcport)) {
5430 qla_nvme_register_remote(vha, fcport);
5431 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5432 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5436 qla24xx_update_fcport_fcp_prio(vha, fcport);
5438 switch (vha->host->active_mode) {
5439 case MODE_INITIATOR:
5440 qla2x00_reg_remote_port(vha, fcport);
5443 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5444 !vha->vha_tgt.qla_tgt->tgt_stopped)
5445 qlt_fc_port_added(vha, fcport);
5448 qla2x00_reg_remote_port(vha, fcport);
5449 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5450 !vha->vha_tgt.qla_tgt->tgt_stopped)
5451 qlt_fc_port_added(vha, fcport);
5457 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5459 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5460 if (fcport->id_changed) {
5461 fcport->id_changed = 0;
5462 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5463 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5464 __func__, __LINE__, fcport->port_name,
5466 qla24xx_post_gfpnid_work(vha, fcport);
5468 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5469 "%s %d %8phC post gpsc fcp_cnt %d\n",
5470 __func__, __LINE__, fcport->port_name,
5472 qla24xx_post_gpsc_work(vha, fcport);
5476 qla2x00_set_fcport_disc_state(fcport, DSC_LOGIN_COMPLETE);
5479 void qla_register_fcport_fn(struct work_struct *work)
5481 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5482 u32 rscn_gen = fcport->rscn_gen;
5485 if (IS_SW_RESV_ADDR(fcport->d_id))
5488 qla2x00_update_fcport(fcport->vha, fcport);
5490 if (rscn_gen != fcport->rscn_gen) {
5491 /* RSCN(s) came in while registration */
5492 switch (fcport->next_disc_state) {
5493 case DSC_DELETE_PEND:
5494 qlt_schedule_sess_for_deletion(fcport);
5497 data[0] = data[1] = 0;
5498 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5508 * qla2x00_configure_fabric
5509 * Setup SNS devices with loop ID's.
5512 * ha = adapter block pointer.
5519 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5523 uint16_t mb[MAILBOX_REGISTER_COUNT];
5525 LIST_HEAD(new_fcports);
5526 struct qla_hw_data *ha = vha->hw;
5529 /* If FL port exists, then SNS is present */
5530 if (IS_FWI2_CAPABLE(ha))
5531 loop_id = NPH_F_PORT;
5533 loop_id = SNS_FL_PORT;
5534 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5535 if (rval != QLA_SUCCESS) {
5536 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5537 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5539 vha->device_flags &= ~SWITCH_FOUND;
5540 return (QLA_SUCCESS);
5542 vha->device_flags |= SWITCH_FOUND;
5545 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5546 rval = qla2x00_send_change_request(vha, 0x3, 0);
5547 if (rval != QLA_SUCCESS)
5548 ql_log(ql_log_warn, vha, 0x121,
5549 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5555 qla2x00_mgmt_svr_login(vha);
5558 if (ql2xfdmienable &&
5559 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5560 qla2x00_fdmi_register(vha);
5562 /* Ensure we are logged into the SNS. */
5563 loop_id = NPH_SNS_LID(ha);
5564 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5565 0xfc, mb, BIT_1|BIT_0);
5566 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5567 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5568 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5569 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5570 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5573 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5574 if (qla2x00_rft_id(vha)) {
5576 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5577 "Register FC-4 TYPE failed.\n");
5578 if (test_bit(LOOP_RESYNC_NEEDED,
5582 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5584 ql_dbg(ql_dbg_disc, vha, 0x209a,
5585 "Register FC-4 Features failed.\n");
5586 if (test_bit(LOOP_RESYNC_NEEDED,
5590 if (vha->flags.nvme_enabled) {
5591 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5592 ql_dbg(ql_dbg_disc, vha, 0x2049,
5593 "Register NVME FC Type Features failed.\n");
5596 if (qla2x00_rnn_id(vha)) {
5598 ql_dbg(ql_dbg_disc, vha, 0x2104,
5599 "Register Node Name failed.\n");
5600 if (test_bit(LOOP_RESYNC_NEEDED,
5603 } else if (qla2x00_rsnn_nn(vha)) {
5605 ql_dbg(ql_dbg_disc, vha, 0x209b,
5606 "Register Symbolic Node Name failed.\n");
5607 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5613 /* Mark the time right before querying FW for connected ports.
5614 * This process is long, asynchronous and by the time it's done,
5615 * collected information might not be accurate anymore. E.g.
5616 * disconnected port might have re-connected and a brand new
5617 * session has been created. In this case session's generation
5618 * will be newer than discovery_gen. */
5619 qlt_do_generation_tick(vha, &discovery_gen);
5621 if (USE_ASYNC_SCAN(ha)) {
5622 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5625 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5627 list_for_each_entry(fcport, &vha->vp_fcports, list)
5628 fcport->scan_state = QLA_FCPORT_SCAN;
5630 rval = qla2x00_find_all_fabric_devs(vha);
5632 if (rval != QLA_SUCCESS)
5636 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5637 qla_nvme_register_hba(vha);
5640 ql_dbg(ql_dbg_disc, vha, 0x2068,
5641 "Configure fabric error exit rval=%d.\n", rval);
5647 * qla2x00_find_all_fabric_devs
5650 * ha = adapter block pointer.
5651 * dev = database device entry pointer.
5660 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5664 fc_port_t *fcport, *new_fcport;
5669 int first_dev, last_dev;
5670 port_id_t wrap = {}, nxt_d_id;
5671 struct qla_hw_data *ha = vha->hw;
5672 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5673 unsigned long flags;
5677 /* Try GID_PT to get device list, else GAN. */
5679 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5684 ql_dbg(ql_dbg_disc, vha, 0x209c,
5685 "GID_PT allocations failed, fallback on GA_NXT.\n");
5687 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5688 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5690 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5692 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5694 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5696 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5698 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5700 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5702 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5706 /* If other queries succeeded probe for FC-4 type */
5708 qla2x00_gff_id(vha, swl);
5709 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5715 /* Allocate temporary fcport for any new fcports discovered. */
5716 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5717 if (new_fcport == NULL) {
5718 ql_log(ql_log_warn, vha, 0x209d,
5719 "Failed to allocate memory for fcport.\n");
5720 return (QLA_MEMORY_ALLOC_FAILED);
5722 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5723 /* Set start port ID scan at adapter ID. */
5727 /* Starting free loop ID. */
5728 loop_id = ha->min_external_loopid;
5729 for (; loop_id <= ha->max_loop_id; loop_id++) {
5730 if (qla2x00_is_reserved_id(vha, loop_id))
5733 if (ha->current_topology == ISP_CFG_FL &&
5734 (atomic_read(&vha->loop_down_timer) ||
5735 LOOP_TRANSITION(vha))) {
5736 atomic_set(&vha->loop_down_timer, 0);
5737 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5738 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5744 wrap.b24 = new_fcport->d_id.b24;
5746 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5747 memcpy(new_fcport->node_name,
5748 swl[swl_idx].node_name, WWN_SIZE);
5749 memcpy(new_fcport->port_name,
5750 swl[swl_idx].port_name, WWN_SIZE);
5751 memcpy(new_fcport->fabric_port_name,
5752 swl[swl_idx].fabric_port_name, WWN_SIZE);
5753 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5754 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5756 new_fcport->nvme_flag = 0;
5757 if (vha->flags.nvme_enabled &&
5758 swl[swl_idx].fc4_type & FS_FC4TYPE_NVME) {
5759 ql_log(ql_log_info, vha, 0x2131,
5760 "FOUND: NVME port %8phC as FC Type 28h\n",
5761 new_fcport->port_name);
5764 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5770 /* Send GA_NXT to the switch */
5771 rval = qla2x00_ga_nxt(vha, new_fcport);
5772 if (rval != QLA_SUCCESS) {
5773 ql_log(ql_log_warn, vha, 0x209e,
5774 "SNS scan failed -- assuming "
5775 "zero-entry result.\n");
5781 /* If wrap on switch device list, exit. */
5783 wrap.b24 = new_fcport->d_id.b24;
5785 } else if (new_fcport->d_id.b24 == wrap.b24) {
5786 ql_dbg(ql_dbg_disc, vha, 0x209f,
5787 "Device wrap (%02x%02x%02x).\n",
5788 new_fcport->d_id.b.domain,
5789 new_fcport->d_id.b.area,
5790 new_fcport->d_id.b.al_pa);
5794 /* Bypass if same physical adapter. */
5795 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5798 /* Bypass virtual ports of the same host. */
5799 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5802 /* Bypass if same domain and area of adapter. */
5803 if (((new_fcport->d_id.b24 & 0xffff00) ==
5804 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5808 /* Bypass reserved domain fields. */
5809 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5812 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5813 if (ql2xgffidenable &&
5814 (!(new_fcport->fc4_type & FS_FC4TYPE_FCP) &&
5815 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5818 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5820 /* Locate matching device in database. */
5822 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5823 if (memcmp(new_fcport->port_name, fcport->port_name,
5827 fcport->scan_state = QLA_FCPORT_FOUND;
5831 /* Update port state. */
5832 memcpy(fcport->fabric_port_name,
5833 new_fcport->fabric_port_name, WWN_SIZE);
5834 fcport->fp_speed = new_fcport->fp_speed;
5837 * If address the same and state FCS_ONLINE
5838 * (or in target mode), nothing changed.
5840 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5841 (atomic_read(&fcport->state) == FCS_ONLINE ||
5842 (vha->host->active_mode == MODE_TARGET))) {
5847 * If device was not a fabric device before.
5849 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5850 fcport->d_id.b24 = new_fcport->d_id.b24;
5851 qla2x00_clear_loop_id(fcport);
5852 fcport->flags |= (FCF_FABRIC_DEVICE |
5858 * Port ID changed or device was marked to be updated;
5859 * Log it out if still logged in and mark it for
5862 if (qla_tgt_mode_enabled(base_vha)) {
5863 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5864 "port changed FC ID, %8phC"
5865 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5867 fcport->d_id.b.domain,
5868 fcport->d_id.b.area,
5869 fcport->d_id.b.al_pa,
5871 new_fcport->d_id.b.domain,
5872 new_fcport->d_id.b.area,
5873 new_fcport->d_id.b.al_pa);
5874 fcport->d_id.b24 = new_fcport->d_id.b24;
5878 fcport->d_id.b24 = new_fcport->d_id.b24;
5879 fcport->flags |= FCF_LOGIN_NEEDED;
5883 if (NVME_TARGET(vha->hw, fcport)) {
5884 if (fcport->disc_state == DSC_DELETE_PEND) {
5885 qla2x00_set_fcport_disc_state(fcport, DSC_GNL);
5886 vha->fcport_count--;
5887 fcport->login_succ = 0;
5892 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5895 /* If device was not in our fcports list, then add it. */
5896 new_fcport->scan_state = QLA_FCPORT_FOUND;
5897 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5899 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5902 /* Allocate a new replacement fcport. */
5903 nxt_d_id.b24 = new_fcport->d_id.b24;
5904 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5905 if (new_fcport == NULL) {
5906 ql_log(ql_log_warn, vha, 0xd032,
5907 "Memory allocation failed for fcport.\n");
5908 return (QLA_MEMORY_ALLOC_FAILED);
5910 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5911 new_fcport->d_id.b24 = nxt_d_id.b24;
5914 qla2x00_free_fcport(new_fcport);
5917 * Logout all previous fabric dev marked lost, except FCP2 devices.
5919 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5920 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5923 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0)
5926 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5927 if ((qla_dual_mode_enabled(vha) ||
5928 qla_ini_mode_enabled(vha)) &&
5929 atomic_read(&fcport->state) == FCS_ONLINE) {
5930 qla2x00_mark_device_lost(vha, fcport,
5931 ql2xplogiabsentdevice);
5932 if (fcport->loop_id != FC_NO_LOOP_ID &&
5933 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5934 fcport->port_type != FCT_INITIATOR &&
5935 fcport->port_type != FCT_BROADCAST) {
5936 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5937 "%s %d %8phC post del sess\n",
5940 qlt_schedule_sess_for_deletion(fcport);
5946 if (fcport->scan_state == QLA_FCPORT_FOUND &&
5947 (fcport->flags & FCF_LOGIN_NEEDED) != 0)
5948 qla24xx_fcport_handle_login(vha, fcport);
5953 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5955 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5957 int loop_id = FC_NO_LOOP_ID;
5958 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5959 unsigned long flags;
5960 struct qla_hw_data *ha = vha->hw;
5962 if (vha->vp_idx == 0) {
5963 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5964 return NPH_MGMT_SERVER;
5967 /* pick id from high and work down to low */
5968 spin_lock_irqsave(&ha->vport_slock, flags);
5969 for (; lid > 0; lid--) {
5970 if (!test_bit(lid, vha->hw->loop_id_map)) {
5971 set_bit(lid, vha->hw->loop_id_map);
5976 spin_unlock_irqrestore(&ha->vport_slock, flags);
5982 * qla2x00_fabric_login
5983 * Issue fabric login command.
5986 * ha = adapter block pointer.
5987 * device = pointer to FC device type structure.
5990 * 0 - Login successfully
5992 * 2 - Initiator device
5996 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5997 uint16_t *next_loopid)
6001 uint16_t tmp_loopid;
6002 uint16_t mb[MAILBOX_REGISTER_COUNT];
6003 struct qla_hw_data *ha = vha->hw;
6009 ql_dbg(ql_dbg_disc, vha, 0x2000,
6010 "Trying Fabric Login w/loop id 0x%04x for port "
6012 fcport->loop_id, fcport->d_id.b.domain,
6013 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6015 /* Login fcport on switch. */
6016 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6017 fcport->d_id.b.domain, fcport->d_id.b.area,
6018 fcport->d_id.b.al_pa, mb, BIT_0);
6019 if (rval != QLA_SUCCESS) {
6022 if (mb[0] == MBS_PORT_ID_USED) {
6024 * Device has another loop ID. The firmware team
6025 * recommends the driver perform an implicit login with
6026 * the specified ID again. The ID we just used is save
6027 * here so we return with an ID that can be tried by
6031 tmp_loopid = fcport->loop_id;
6032 fcport->loop_id = mb[1];
6034 ql_dbg(ql_dbg_disc, vha, 0x2001,
6035 "Fabric Login: port in use - next loop "
6036 "id=0x%04x, port id= %02x%02x%02x.\n",
6037 fcport->loop_id, fcport->d_id.b.domain,
6038 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6040 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6045 /* A retry occurred before. */
6046 *next_loopid = tmp_loopid;
6049 * No retry occurred before. Just increment the
6050 * ID value for next login.
6052 *next_loopid = (fcport->loop_id + 1);
6055 if (mb[1] & BIT_0) {
6056 fcport->port_type = FCT_INITIATOR;
6058 fcport->port_type = FCT_TARGET;
6059 if (mb[1] & BIT_1) {
6060 fcport->flags |= FCF_FCP2_DEVICE;
6065 fcport->supported_classes |= FC_COS_CLASS2;
6067 fcport->supported_classes |= FC_COS_CLASS3;
6069 if (IS_FWI2_CAPABLE(ha)) {
6072 FCF_CONF_COMP_SUPPORTED;
6077 } else if (mb[0] == MBS_LOOP_ID_USED) {
6079 * Loop ID already used, try next loop ID.
6082 rval = qla2x00_find_new_loop_id(vha, fcport);
6083 if (rval != QLA_SUCCESS) {
6084 /* Ran out of loop IDs to use */
6087 } else if (mb[0] == MBS_COMMAND_ERROR) {
6089 * Firmware possibly timed out during login. If NO
6090 * retries are left to do then the device is declared
6093 *next_loopid = fcport->loop_id;
6094 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6095 fcport->d_id.b.domain, fcport->d_id.b.area,
6096 fcport->d_id.b.al_pa);
6097 qla2x00_mark_device_lost(vha, fcport, 1);
6103 * unrecoverable / not handled error
6105 ql_dbg(ql_dbg_disc, vha, 0x2002,
6106 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6107 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6108 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6109 fcport->loop_id, jiffies);
6111 *next_loopid = fcport->loop_id;
6112 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6113 fcport->d_id.b.domain, fcport->d_id.b.area,
6114 fcport->d_id.b.al_pa);
6115 qla2x00_clear_loop_id(fcport);
6116 fcport->login_retry = 0;
6127 * qla2x00_local_device_login
6128 * Issue local device login command.
6131 * ha = adapter block pointer.
6132 * loop_id = loop id of device to login to.
6134 * Returns (Where's the #define!!!!):
6135 * 0 - Login successfully
6140 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6143 uint16_t mb[MAILBOX_REGISTER_COUNT];
6145 memset(mb, 0, sizeof(mb));
6146 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6147 if (rval == QLA_SUCCESS) {
6148 /* Interrogate mailbox registers for any errors */
6149 if (mb[0] == MBS_COMMAND_ERROR)
6151 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6152 /* device not in PCB table */
6160 * qla2x00_loop_resync
6161 * Resync with fibre channel devices.
6164 * ha = adapter block pointer.
6170 qla2x00_loop_resync(scsi_qla_host_t *vha)
6172 int rval = QLA_SUCCESS;
6175 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6176 if (vha->flags.online) {
6177 if (!(rval = qla2x00_fw_ready(vha))) {
6178 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6181 if (!IS_QLAFX00(vha->hw)) {
6183 * Issue a marker after FW becomes
6186 qla2x00_marker(vha, vha->hw->base_qpair,
6188 vha->marker_needed = 0;
6191 /* Remap devices on Loop. */
6192 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6194 if (IS_QLAFX00(vha->hw))
6195 qlafx00_configure_devices(vha);
6197 qla2x00_configure_loop(vha);
6200 } while (!atomic_read(&vha->loop_down_timer) &&
6201 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6202 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6207 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6208 return (QLA_FUNCTION_FAILED);
6211 ql_dbg(ql_dbg_disc, vha, 0x206c,
6212 "%s *** FAILED ***.\n", __func__);
6218 * qla2x00_perform_loop_resync
6219 * Description: This function will set the appropriate flags and call
6220 * qla2x00_loop_resync. If successful loop will be resynced
6221 * Arguments : scsi_qla_host_t pointer
6222 * returm : Success or Failure
6225 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6229 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6230 /*Configure the flags so that resync happens properly*/
6231 atomic_set(&ha->loop_down_timer, 0);
6232 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6233 atomic_set(&ha->loop_state, LOOP_UP);
6234 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6235 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6236 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6238 rval = qla2x00_loop_resync(ha);
6240 atomic_set(&ha->loop_state, LOOP_DEAD);
6242 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6249 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6252 struct scsi_qla_host *vha;
6253 struct qla_hw_data *ha = base_vha->hw;
6254 unsigned long flags;
6256 spin_lock_irqsave(&ha->vport_slock, flags);
6257 /* Go with deferred removal of rport references. */
6258 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6259 atomic_inc(&vha->vref_count);
6260 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6261 if (fcport->drport &&
6262 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6263 spin_unlock_irqrestore(&ha->vport_slock, flags);
6264 qla2x00_rport_del(fcport);
6266 spin_lock_irqsave(&ha->vport_slock, flags);
6269 atomic_dec(&vha->vref_count);
6270 wake_up(&vha->vref_waitq);
6272 spin_unlock_irqrestore(&ha->vport_slock, flags);
6275 /* Assumes idc_lock always held on entry */
6277 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6279 struct qla_hw_data *ha = vha->hw;
6280 uint32_t drv_presence, drv_presence_mask;
6281 uint32_t dev_part_info1, dev_part_info2, class_type;
6282 uint32_t class_type_mask = 0x3;
6283 uint16_t fcoe_other_function = 0xffff, i;
6285 if (IS_QLA8044(ha)) {
6286 drv_presence = qla8044_rd_direct(vha,
6287 QLA8044_CRB_DRV_ACTIVE_INDEX);
6288 dev_part_info1 = qla8044_rd_direct(vha,
6289 QLA8044_CRB_DEV_PART_INFO_INDEX);
6290 dev_part_info2 = qla8044_rd_direct(vha,
6291 QLA8044_CRB_DEV_PART_INFO2);
6293 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6294 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6295 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6297 for (i = 0; i < 8; i++) {
6298 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6299 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6300 (i != ha->portnum)) {
6301 fcoe_other_function = i;
6305 if (fcoe_other_function == 0xffff) {
6306 for (i = 0; i < 8; i++) {
6307 class_type = ((dev_part_info2 >> (i * 4)) &
6309 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6310 ((i + 8) != ha->portnum)) {
6311 fcoe_other_function = i + 8;
6317 * Prepare drv-presence mask based on fcoe functions present.
6318 * However consider only valid physical fcoe function numbers (0-15).
6320 drv_presence_mask = ~((1 << (ha->portnum)) |
6321 ((fcoe_other_function == 0xffff) ?
6322 0 : (1 << (fcoe_other_function))));
6324 /* We are the reset owner iff:
6325 * - No other protocol drivers present.
6326 * - This is the lowest among fcoe functions. */
6327 if (!(drv_presence & drv_presence_mask) &&
6328 (ha->portnum < fcoe_other_function)) {
6329 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6330 "This host is Reset owner.\n");
6331 ha->flags.nic_core_reset_owner = 1;
6336 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6338 int rval = QLA_SUCCESS;
6339 struct qla_hw_data *ha = vha->hw;
6342 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6343 if (rval == QLA_SUCCESS) {
6344 drv_ack |= (1 << ha->portnum);
6345 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6352 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6354 int rval = QLA_SUCCESS;
6355 struct qla_hw_data *ha = vha->hw;
6358 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6359 if (rval == QLA_SUCCESS) {
6360 drv_ack &= ~(1 << ha->portnum);
6361 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6368 qla83xx_dev_state_to_string(uint32_t dev_state)
6370 switch (dev_state) {
6371 case QLA8XXX_DEV_COLD:
6372 return "COLD/RE-INIT";
6373 case QLA8XXX_DEV_INITIALIZING:
6374 return "INITIALIZING";
6375 case QLA8XXX_DEV_READY:
6377 case QLA8XXX_DEV_NEED_RESET:
6378 return "NEED RESET";
6379 case QLA8XXX_DEV_NEED_QUIESCENT:
6380 return "NEED QUIESCENT";
6381 case QLA8XXX_DEV_FAILED:
6383 case QLA8XXX_DEV_QUIESCENT:
6390 /* Assumes idc-lock always held on entry */
6392 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6394 struct qla_hw_data *ha = vha->hw;
6395 uint32_t idc_audit_reg = 0, duration_secs = 0;
6397 switch (audit_type) {
6398 case IDC_AUDIT_TIMESTAMP:
6399 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6400 idc_audit_reg = (ha->portnum) |
6401 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6402 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6405 case IDC_AUDIT_COMPLETION:
6406 duration_secs = ((jiffies_to_msecs(jiffies) -
6407 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6408 idc_audit_reg = (ha->portnum) |
6409 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6410 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6414 ql_log(ql_log_warn, vha, 0xb078,
6415 "Invalid audit type specified.\n");
6420 /* Assumes idc_lock always held on entry */
6422 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6424 struct qla_hw_data *ha = vha->hw;
6425 uint32_t idc_control, dev_state;
6427 __qla83xx_get_idc_control(vha, &idc_control);
6428 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6429 ql_log(ql_log_info, vha, 0xb080,
6430 "NIC Core reset has been disabled. idc-control=0x%x\n",
6432 return QLA_FUNCTION_FAILED;
6435 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6436 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6437 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6438 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6439 QLA8XXX_DEV_NEED_RESET);
6440 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6441 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6443 const char *state = qla83xx_dev_state_to_string(dev_state);
6445 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6447 /* SV: XXX: Is timeout required here? */
6448 /* Wait for IDC state change READY -> NEED_RESET */
6449 while (dev_state == QLA8XXX_DEV_READY) {
6450 qla83xx_idc_unlock(vha, 0);
6452 qla83xx_idc_lock(vha, 0);
6453 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6457 /* Send IDC ack by writing to drv-ack register */
6458 __qla83xx_set_drv_ack(vha);
6464 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6466 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6470 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6472 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6476 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6478 uint32_t drv_presence = 0;
6479 struct qla_hw_data *ha = vha->hw;
6481 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6482 if (drv_presence & (1 << ha->portnum))
6485 return QLA_TEST_FAILED;
6489 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6491 int rval = QLA_SUCCESS;
6492 struct qla_hw_data *ha = vha->hw;
6494 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6495 "Entered %s().\n", __func__);
6497 if (vha->device_flags & DFLG_DEV_FAILED) {
6498 ql_log(ql_log_warn, vha, 0xb059,
6499 "Device in unrecoverable FAILED state.\n");
6500 return QLA_FUNCTION_FAILED;
6503 qla83xx_idc_lock(vha, 0);
6505 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6506 ql_log(ql_log_warn, vha, 0xb05a,
6507 "Function=0x%x has been removed from IDC participation.\n",
6509 rval = QLA_FUNCTION_FAILED;
6513 qla83xx_reset_ownership(vha);
6515 rval = qla83xx_initiating_reset(vha);
6518 * Perform reset if we are the reset-owner,
6519 * else wait till IDC state changes to READY/FAILED.
6521 if (rval == QLA_SUCCESS) {
6522 rval = qla83xx_idc_state_handler(vha);
6524 if (rval == QLA_SUCCESS)
6525 ha->flags.nic_core_hung = 0;
6526 __qla83xx_clear_drv_ack(vha);
6530 qla83xx_idc_unlock(vha, 0);
6532 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6538 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6540 struct qla_hw_data *ha = vha->hw;
6541 int rval = QLA_FUNCTION_FAILED;
6543 if (!IS_MCTP_CAPABLE(ha)) {
6544 /* This message can be removed from the final version */
6545 ql_log(ql_log_info, vha, 0x506d,
6546 "This board is not MCTP capable\n");
6550 if (!ha->mctp_dump) {
6551 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6552 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6554 if (!ha->mctp_dump) {
6555 ql_log(ql_log_warn, vha, 0x506e,
6556 "Failed to allocate memory for mctp dump\n");
6561 #define MCTP_DUMP_STR_ADDR 0x00000000
6562 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6563 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6564 if (rval != QLA_SUCCESS) {
6565 ql_log(ql_log_warn, vha, 0x506f,
6566 "Failed to capture mctp dump\n");
6568 ql_log(ql_log_info, vha, 0x5070,
6569 "Mctp dump capture for host (%ld/%p).\n",
6570 vha->host_no, ha->mctp_dump);
6571 ha->mctp_dumped = 1;
6574 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6575 ha->flags.nic_core_reset_hdlr_active = 1;
6576 rval = qla83xx_restart_nic_firmware(vha);
6578 /* NIC Core reset failed. */
6579 ql_log(ql_log_warn, vha, 0x5071,
6580 "Failed to restart nic firmware\n");
6582 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6583 "Restarted NIC firmware successfully.\n");
6584 ha->flags.nic_core_reset_hdlr_active = 0;
6592 * qla2x00_quiesce_io
6593 * Description: This function will block the new I/Os
6594 * Its not aborting any I/Os as context
6595 * is not destroyed during quiescence
6596 * Arguments: scsi_qla_host_t
6600 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6602 struct qla_hw_data *ha = vha->hw;
6603 struct scsi_qla_host *vp;
6605 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6606 "Quiescing I/O - ha=%p.\n", ha);
6608 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6609 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6610 atomic_set(&vha->loop_state, LOOP_DOWN);
6611 qla2x00_mark_all_devices_lost(vha);
6612 list_for_each_entry(vp, &ha->vp_list, list)
6613 qla2x00_mark_all_devices_lost(vp);
6615 if (!atomic_read(&vha->loop_down_timer))
6616 atomic_set(&vha->loop_down_timer,
6619 /* Wait for pending cmds to complete */
6620 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6625 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6627 struct qla_hw_data *ha = vha->hw;
6628 struct scsi_qla_host *vp;
6629 unsigned long flags;
6633 /* For ISP82XX, driver waits for completion of the commands.
6634 * online flag should be set.
6636 if (!(IS_P3P_TYPE(ha)))
6637 vha->flags.online = 0;
6638 ha->flags.chip_reset_done = 0;
6639 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6640 vha->qla_stats.total_isp_aborts++;
6642 ql_log(ql_log_info, vha, 0x00af,
6643 "Performing ISP error recovery - ha=%p.\n", ha);
6645 ha->flags.purge_mbox = 1;
6646 /* For ISP82XX, reset_chip is just disabling interrupts.
6647 * Driver waits for the completion of the commands.
6648 * the interrupts need to be enabled.
6650 if (!(IS_P3P_TYPE(ha)))
6651 ha->isp_ops->reset_chip(vha);
6653 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6655 ha->flags.rida_fmt2 = 0;
6656 ha->flags.n2n_ae = 0;
6657 ha->flags.lip_ae = 0;
6658 ha->current_topology = 0;
6659 ha->flags.fw_started = 0;
6660 ha->flags.fw_init_done = 0;
6662 ha->base_qpair->chip_reset = ha->chip_reset;
6663 for (i = 0; i < ha->max_qpairs; i++) {
6664 if (ha->queue_pair_map[i])
6665 ha->queue_pair_map[i]->chip_reset =
6666 ha->base_qpair->chip_reset;
6669 /* purge MBox commands */
6670 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6671 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6672 complete(&ha->mbx_intr_comp);
6676 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6677 atomic_read(&ha->num_pend_mbx_stage2) ||
6678 atomic_read(&ha->num_pend_mbx_stage1)) {
6684 ha->flags.purge_mbox = 0;
6686 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6687 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6688 atomic_set(&vha->loop_state, LOOP_DOWN);
6689 qla2x00_mark_all_devices_lost(vha);
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 qla2x00_mark_all_devices_lost(vp);
6698 spin_lock_irqsave(&ha->vport_slock, flags);
6699 atomic_dec(&vp->vref_count);
6701 spin_unlock_irqrestore(&ha->vport_slock, flags);
6703 if (!atomic_read(&vha->loop_down_timer))
6704 atomic_set(&vha->loop_down_timer,
6708 /* Clear all async request states across all VPs. */
6709 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6710 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6711 fcport->scan_state = 0;
6713 spin_lock_irqsave(&ha->vport_slock, flags);
6714 list_for_each_entry(vp, &ha->vp_list, list) {
6715 atomic_inc(&vp->vref_count);
6716 spin_unlock_irqrestore(&ha->vport_slock, flags);
6718 list_for_each_entry(fcport, &vp->vp_fcports, list)
6719 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6721 spin_lock_irqsave(&ha->vport_slock, flags);
6722 atomic_dec(&vp->vref_count);
6724 spin_unlock_irqrestore(&ha->vport_slock, flags);
6726 if (!ha->flags.eeh_busy) {
6727 /* Make sure for ISP 82XX IO DMA is complete */
6728 if (IS_P3P_TYPE(ha)) {
6729 qla82xx_chip_reset_cleanup(vha);
6730 ql_log(ql_log_info, vha, 0x00b4,
6731 "Done chip reset cleanup.\n");
6733 /* Done waiting for pending commands.
6734 * Reset the online flag.
6736 vha->flags.online = 0;
6739 /* Requeue all commands in outstanding command list. */
6740 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6742 /* memory barrier */
6748 * Resets ISP and aborts all outstanding commands.
6751 * ha = adapter block pointer.
6757 qla2x00_abort_isp(scsi_qla_host_t *vha)
6761 struct qla_hw_data *ha = vha->hw;
6762 struct scsi_qla_host *vp;
6763 struct req_que *req = ha->req_q_map[0];
6764 unsigned long flags;
6766 if (vha->flags.online) {
6767 qla2x00_abort_isp_cleanup(vha);
6769 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6770 ha->flags.chip_reset_done = 1;
6771 vha->flags.online = 1;
6773 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6777 if (IS_QLA8031(ha)) {
6778 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6779 "Clearing fcoe driver presence.\n");
6780 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6781 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6782 "Error while clearing DRV-Presence.\n");
6785 if (unlikely(pci_channel_offline(ha->pdev) &&
6786 ha->flags.pci_channel_io_perm_failure)) {
6787 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6792 switch (vha->qlini_mode) {
6793 case QLA2XXX_INI_MODE_DISABLED:
6794 if (!qla_tgt_mode_enabled(vha))
6797 case QLA2XXX_INI_MODE_DUAL:
6798 if (!qla_dual_mode_enabled(vha))
6801 case QLA2XXX_INI_MODE_ENABLED:
6806 ha->isp_ops->get_flash_version(vha, req->ring);
6808 ha->isp_ops->nvram_config(vha);
6810 if (!qla2x00_restart_isp(vha)) {
6811 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6813 if (!atomic_read(&vha->loop_down_timer)) {
6815 * Issue marker command only when we are going
6816 * to start the I/O .
6818 vha->marker_needed = 1;
6821 vha->flags.online = 1;
6823 ha->isp_ops->enable_intrs(ha);
6825 ha->isp_abort_cnt = 0;
6826 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6828 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6829 qla2x00_get_fw_version(vha);
6831 ha->flags.fce_enabled = 1;
6833 fce_calc_size(ha->fce_bufs));
6834 rval = qla2x00_enable_fce_trace(vha,
6835 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6838 ql_log(ql_log_warn, vha, 0x8033,
6839 "Unable to reinitialize FCE "
6841 ha->flags.fce_enabled = 0;
6846 memset(ha->eft, 0, EFT_SIZE);
6847 rval = qla2x00_enable_eft_trace(vha,
6848 ha->eft_dma, EFT_NUM_BUFFERS);
6850 ql_log(ql_log_warn, vha, 0x8034,
6851 "Unable to reinitialize EFT "
6855 } else { /* failed the ISP abort */
6856 vha->flags.online = 1;
6857 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6858 if (ha->isp_abort_cnt == 0) {
6859 ql_log(ql_log_fatal, vha, 0x8035,
6860 "ISP error recover failed - "
6861 "board disabled.\n");
6863 * The next call disables the board
6866 qla2x00_abort_isp_cleanup(vha);
6867 vha->flags.online = 0;
6868 clear_bit(ISP_ABORT_RETRY,
6871 } else { /* schedule another ISP abort */
6872 ha->isp_abort_cnt--;
6873 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6874 "ISP abort - retry remaining %d.\n",
6879 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6880 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6881 "ISP error recovery - retrying (%d) "
6882 "more times.\n", ha->isp_abort_cnt);
6883 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6891 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6892 qla2x00_configure_hba(vha);
6893 spin_lock_irqsave(&ha->vport_slock, flags);
6894 list_for_each_entry(vp, &ha->vp_list, list) {
6896 atomic_inc(&vp->vref_count);
6897 spin_unlock_irqrestore(&ha->vport_slock, flags);
6899 qla2x00_vp_abort_isp(vp);
6901 spin_lock_irqsave(&ha->vport_slock, flags);
6902 atomic_dec(&vp->vref_count);
6905 spin_unlock_irqrestore(&ha->vport_slock, flags);
6907 if (IS_QLA8031(ha)) {
6908 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6909 "Setting back fcoe driver presence.\n");
6910 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6911 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6912 "Error while setting DRV-Presence.\n");
6915 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6923 * qla2x00_restart_isp
6924 * restarts the ISP after a reset
6927 * ha = adapter block pointer.
6933 qla2x00_restart_isp(scsi_qla_host_t *vha)
6936 struct qla_hw_data *ha = vha->hw;
6938 /* If firmware needs to be loaded */
6939 if (qla2x00_isp_firmware(vha)) {
6940 vha->flags.online = 0;
6941 status = ha->isp_ops->chip_diag(vha);
6943 status = qla2x00_setup_chip(vha);
6946 if (!status && !(status = qla2x00_init_rings(vha))) {
6947 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6948 ha->flags.chip_reset_done = 1;
6950 /* Initialize the queues in use */
6951 qla25xx_init_queues(ha);
6953 status = qla2x00_fw_ready(vha);
6955 /* Issue a marker after FW becomes ready. */
6956 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
6957 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6960 /* if no cable then assume it's good */
6961 if ((vha->device_flags & DFLG_NO_CABLE))
6968 qla25xx_init_queues(struct qla_hw_data *ha)
6970 struct rsp_que *rsp = NULL;
6971 struct req_que *req = NULL;
6972 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6976 for (i = 1; i < ha->max_rsp_queues; i++) {
6977 rsp = ha->rsp_q_map[i];
6978 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6979 rsp->options &= ~BIT_0;
6980 ret = qla25xx_init_rsp_que(base_vha, rsp);
6981 if (ret != QLA_SUCCESS)
6982 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6983 "%s Rsp que: %d init failed.\n",
6986 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6987 "%s Rsp que: %d inited.\n",
6991 for (i = 1; i < ha->max_req_queues; i++) {
6992 req = ha->req_q_map[i];
6993 if (req && test_bit(i, ha->req_qid_map)) {
6994 /* Clear outstanding commands array. */
6995 req->options &= ~BIT_0;
6996 ret = qla25xx_init_req_que(base_vha, req);
6997 if (ret != QLA_SUCCESS)
6998 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6999 "%s Req que: %d init failed.\n",
7002 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7003 "%s Req que: %d inited.\n",
7011 * qla2x00_reset_adapter
7015 * ha = adapter block pointer.
7018 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7020 unsigned long flags = 0;
7021 struct qla_hw_data *ha = vha->hw;
7022 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7024 vha->flags.online = 0;
7025 ha->isp_ops->disable_intrs(ha);
7027 spin_lock_irqsave(&ha->hardware_lock, flags);
7028 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7029 RD_REG_WORD(®->hccr); /* PCI Posting. */
7030 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7031 RD_REG_WORD(®->hccr); /* PCI Posting. */
7032 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7038 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7040 unsigned long flags = 0;
7041 struct qla_hw_data *ha = vha->hw;
7042 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7043 int rval = QLA_SUCCESS;
7045 if (IS_P3P_TYPE(ha))
7048 vha->flags.online = 0;
7049 ha->isp_ops->disable_intrs(ha);
7051 spin_lock_irqsave(&ha->hardware_lock, flags);
7052 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7053 RD_REG_DWORD(®->hccr);
7054 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7055 RD_REG_DWORD(®->hccr);
7056 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7058 if (IS_NOPOLLING_TYPE(ha))
7059 ha->isp_ops->enable_intrs(ha);
7064 /* On sparc systems, obtain port and node WWN from firmware
7067 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7068 struct nvram_24xx *nv)
7071 struct qla_hw_data *ha = vha->hw;
7072 struct pci_dev *pdev = ha->pdev;
7073 struct device_node *dp = pci_device_to_OF_node(pdev);
7077 val = of_get_property(dp, "port-wwn", &len);
7078 if (val && len >= WWN_SIZE)
7079 memcpy(nv->port_name, val, WWN_SIZE);
7081 val = of_get_property(dp, "node-wwn", &len);
7082 if (val && len >= WWN_SIZE)
7083 memcpy(nv->node_name, val, WWN_SIZE);
7088 qla24xx_nvram_config(scsi_qla_host_t *vha)
7091 struct init_cb_24xx *icb;
7092 struct nvram_24xx *nv;
7094 uint8_t *dptr1, *dptr2;
7097 struct qla_hw_data *ha = vha->hw;
7100 icb = (struct init_cb_24xx *)ha->init_cb;
7103 /* Determine NVRAM starting address. */
7104 if (ha->port_no == 0) {
7105 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7106 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7108 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7109 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7112 ha->nvram_size = sizeof(*nv);
7113 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7115 /* Get VPD data into cache */
7116 ha->vpd = ha->nvram + VPD_OFFSET;
7117 ha->isp_ops->read_nvram(vha, ha->vpd,
7118 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7120 /* Get NVRAM data into cache and calculate checksum. */
7121 dptr = (uint32_t *)nv;
7122 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7123 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7124 chksum += le32_to_cpu(*dptr);
7126 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7127 "Contents of NVRAM\n");
7128 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7129 nv, ha->nvram_size);
7131 /* Bad NVRAM data, set defaults parameters. */
7132 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7133 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7134 /* Reset NVRAM data. */
7135 ql_log(ql_log_warn, vha, 0x006b,
7136 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7137 chksum, nv->id, nv->nvram_version);
7138 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7139 ql_log(ql_log_warn, vha, 0x006c,
7140 "Falling back to functioning (yet invalid -- WWPN) "
7144 * Set default initialization control block.
7146 memset(nv, 0, ha->nvram_size);
7147 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7148 nv->version = cpu_to_le16(ICB_VERSION);
7149 nv->frame_payload_size = 2048;
7150 nv->execution_throttle = cpu_to_le16(0xFFFF);
7151 nv->exchange_count = cpu_to_le16(0);
7152 nv->hard_address = cpu_to_le16(124);
7153 nv->port_name[0] = 0x21;
7154 nv->port_name[1] = 0x00 + ha->port_no + 1;
7155 nv->port_name[2] = 0x00;
7156 nv->port_name[3] = 0xe0;
7157 nv->port_name[4] = 0x8b;
7158 nv->port_name[5] = 0x1c;
7159 nv->port_name[6] = 0x55;
7160 nv->port_name[7] = 0x86;
7161 nv->node_name[0] = 0x20;
7162 nv->node_name[1] = 0x00;
7163 nv->node_name[2] = 0x00;
7164 nv->node_name[3] = 0xe0;
7165 nv->node_name[4] = 0x8b;
7166 nv->node_name[5] = 0x1c;
7167 nv->node_name[6] = 0x55;
7168 nv->node_name[7] = 0x86;
7169 qla24xx_nvram_wwn_from_ofw(vha, nv);
7170 nv->login_retry_count = cpu_to_le16(8);
7171 nv->interrupt_delay_timer = cpu_to_le16(0);
7172 nv->login_timeout = cpu_to_le16(0);
7173 nv->firmware_options_1 =
7174 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7175 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7176 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7177 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7178 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7179 nv->efi_parameters = cpu_to_le32(0);
7180 nv->reset_delay = 5;
7181 nv->max_luns_per_target = cpu_to_le16(128);
7182 nv->port_down_retry_count = cpu_to_le16(30);
7183 nv->link_down_timeout = cpu_to_le16(30);
7188 if (qla_tgt_mode_enabled(vha)) {
7189 /* Don't enable full login after initial LIP */
7190 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7191 /* Don't enable LIP full login for initiator */
7192 nv->host_p &= cpu_to_le32(~BIT_10);
7195 qlt_24xx_config_nvram_stage1(vha, nv);
7197 /* Reset Initialization control block */
7198 memset(icb, 0, ha->init_cb_size);
7200 /* Copy 1st segment. */
7201 dptr1 = (uint8_t *)icb;
7202 dptr2 = (uint8_t *)&nv->version;
7203 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7205 *dptr1++ = *dptr2++;
7207 icb->login_retry_count = nv->login_retry_count;
7208 icb->link_down_on_nos = nv->link_down_on_nos;
7210 /* Copy 2nd segment. */
7211 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7212 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7213 cnt = (uint8_t *)&icb->reserved_3 -
7214 (uint8_t *)&icb->interrupt_delay_timer;
7216 *dptr1++ = *dptr2++;
7217 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7219 * Setup driver NVRAM options.
7221 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7224 qlt_24xx_config_nvram_stage2(vha, icb);
7226 if (nv->host_p & cpu_to_le32(BIT_15)) {
7227 /* Use alternate WWN? */
7228 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7229 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7232 /* Prepare nodename */
7233 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7235 * Firmware will apply the following mask if the nodename was
7238 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7239 icb->node_name[0] &= 0xF0;
7242 /* Set host adapter parameters. */
7243 ha->flags.disable_risc_code_load = 0;
7244 ha->flags.enable_lip_reset = 0;
7245 ha->flags.enable_lip_full_login =
7246 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7247 ha->flags.enable_target_reset =
7248 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7249 ha->flags.enable_led_scheme = 0;
7250 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7252 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7253 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7255 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7256 sizeof(ha->fw_seriallink_options24));
7258 /* save HBA serial number */
7259 ha->serial0 = icb->port_name[5];
7260 ha->serial1 = icb->port_name[6];
7261 ha->serial2 = icb->port_name[7];
7262 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7263 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7265 icb->execution_throttle = cpu_to_le16(0xFFFF);
7267 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7269 /* Set minimum login_timeout to 4 seconds. */
7270 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7271 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7272 if (le16_to_cpu(nv->login_timeout) < 4)
7273 nv->login_timeout = cpu_to_le16(4);
7274 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7276 /* Set minimum RATOV to 100 tenths of a second. */
7279 ha->loop_reset_delay = nv->reset_delay;
7281 /* Link Down Timeout = 0:
7283 * When Port Down timer expires we will start returning
7284 * I/O's to OS with "DID_NO_CONNECT".
7286 * Link Down Timeout != 0:
7288 * The driver waits for the link to come up after link down
7289 * before returning I/Os to OS with "DID_NO_CONNECT".
7291 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7292 ha->loop_down_abort_time =
7293 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7295 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7296 ha->loop_down_abort_time =
7297 (LOOP_DOWN_TIME - ha->link_down_timeout);
7300 /* Need enough time to try and get the port back. */
7301 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7302 if (qlport_down_retry)
7303 ha->port_down_retry_count = qlport_down_retry;
7305 /* Set login_retry_count */
7306 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7307 if (ha->port_down_retry_count ==
7308 le16_to_cpu(nv->port_down_retry_count) &&
7309 ha->port_down_retry_count > 3)
7310 ha->login_retry_count = ha->port_down_retry_count;
7311 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7312 ha->login_retry_count = ha->port_down_retry_count;
7313 if (ql2xloginretrycount)
7314 ha->login_retry_count = ql2xloginretrycount;
7316 /* N2N: driver will initiate Login instead of FW */
7317 icb->firmware_options_3 |= BIT_8;
7320 if (!vha->flags.init_done) {
7321 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7322 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7323 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7324 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7326 icb->firmware_options_2 &= cpu_to_le32(
7327 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7328 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7329 ha->zio_mode = QLA_ZIO_MODE_6;
7331 ql_log(ql_log_info, vha, 0x006f,
7332 "ZIO mode %d enabled; timer delay (%d us).\n",
7333 ha->zio_mode, ha->zio_timer * 100);
7335 icb->firmware_options_2 |= cpu_to_le32(
7336 (uint32_t)ha->zio_mode);
7337 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7341 ql_log(ql_log_warn, vha, 0x0070,
7342 "NVRAM configuration failed.\n");
7348 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7349 struct qla27xx_image_status *image_status)
7351 ql_dbg(ql_dbg_init, vha, 0x018b,
7352 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7354 image_status->image_status_mask,
7355 le16_to_cpu(image_status->generation),
7356 image_status->ver_major,
7357 image_status->ver_minor,
7358 image_status->bitmap,
7359 le32_to_cpu(image_status->checksum),
7360 le32_to_cpu(image_status->signature));
7364 qla28xx_check_aux_image_status_signature(
7365 struct qla27xx_image_status *image_status)
7367 ulong signature = le32_to_cpu(image_status->signature);
7369 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7373 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7375 ulong signature = le32_to_cpu(image_status->signature);
7378 signature != QLA27XX_IMG_STATUS_SIGN &&
7379 signature != QLA28XX_IMG_STATUS_SIGN;
7383 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7385 uint32_t *p = (void *)image_status;
7386 uint n = sizeof(*image_status) / sizeof(*p);
7390 sum += le32_to_cpup(p);
7396 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7398 return aux->bitmap & bitmask ?
7399 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7403 qla28xx_component_status(
7404 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7406 active_regions->aux.board_config =
7407 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7409 active_regions->aux.vpd_nvram =
7410 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7412 active_regions->aux.npiv_config_0_1 =
7413 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7415 active_regions->aux.npiv_config_2_3 =
7416 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7420 qla27xx_compare_image_generation(
7421 struct qla27xx_image_status *pri_image_status,
7422 struct qla27xx_image_status *sec_image_status)
7424 /* calculate generation delta as uint16 (this accounts for wrap) */
7426 le16_to_cpu(pri_image_status->generation) -
7427 le16_to_cpu(sec_image_status->generation);
7429 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7435 qla28xx_get_aux_images(
7436 struct scsi_qla_host *vha, struct active_regions *active_regions)
7438 struct qla_hw_data *ha = vha->hw;
7439 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7440 bool valid_pri_image = false, valid_sec_image = false;
7441 bool active_pri_image = false, active_sec_image = false;
7443 if (!ha->flt_region_aux_img_status_pri) {
7444 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7445 goto check_sec_image;
7448 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7449 ha->flt_region_aux_img_status_pri,
7450 sizeof(pri_aux_image_status) >> 2);
7451 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7453 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7454 ql_dbg(ql_dbg_init, vha, 0x018b,
7455 "Primary aux image signature (%#x) not valid\n",
7456 le32_to_cpu(pri_aux_image_status.signature));
7457 goto check_sec_image;
7460 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7461 ql_dbg(ql_dbg_init, vha, 0x018c,
7462 "Primary aux image checksum failed\n");
7463 goto check_sec_image;
7466 valid_pri_image = true;
7468 if (pri_aux_image_status.image_status_mask & 1) {
7469 ql_dbg(ql_dbg_init, vha, 0x018d,
7470 "Primary aux image is active\n");
7471 active_pri_image = true;
7475 if (!ha->flt_region_aux_img_status_sec) {
7476 ql_dbg(ql_dbg_init, vha, 0x018a,
7477 "Secondary aux image not addressed\n");
7478 goto check_valid_image;
7481 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7482 ha->flt_region_aux_img_status_sec,
7483 sizeof(sec_aux_image_status) >> 2);
7484 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7486 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7487 ql_dbg(ql_dbg_init, vha, 0x018b,
7488 "Secondary aux image signature (%#x) not valid\n",
7489 le32_to_cpu(sec_aux_image_status.signature));
7490 goto check_valid_image;
7493 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7494 ql_dbg(ql_dbg_init, vha, 0x018c,
7495 "Secondary aux image checksum failed\n");
7496 goto check_valid_image;
7499 valid_sec_image = true;
7501 if (sec_aux_image_status.image_status_mask & 1) {
7502 ql_dbg(ql_dbg_init, vha, 0x018d,
7503 "Secondary aux image is active\n");
7504 active_sec_image = true;
7508 if (valid_pri_image && active_pri_image &&
7509 valid_sec_image && active_sec_image) {
7510 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7511 &sec_aux_image_status) >= 0) {
7512 qla28xx_component_status(active_regions,
7513 &pri_aux_image_status);
7515 qla28xx_component_status(active_regions,
7516 &sec_aux_image_status);
7518 } else if (valid_pri_image && active_pri_image) {
7519 qla28xx_component_status(active_regions, &pri_aux_image_status);
7520 } else if (valid_sec_image && active_sec_image) {
7521 qla28xx_component_status(active_regions, &sec_aux_image_status);
7524 ql_dbg(ql_dbg_init, vha, 0x018f,
7525 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7526 active_regions->aux.board_config,
7527 active_regions->aux.vpd_nvram,
7528 active_regions->aux.npiv_config_0_1,
7529 active_regions->aux.npiv_config_2_3);
7533 qla27xx_get_active_image(struct scsi_qla_host *vha,
7534 struct active_regions *active_regions)
7536 struct qla_hw_data *ha = vha->hw;
7537 struct qla27xx_image_status pri_image_status, sec_image_status;
7538 bool valid_pri_image = false, valid_sec_image = false;
7539 bool active_pri_image = false, active_sec_image = false;
7541 if (!ha->flt_region_img_status_pri) {
7542 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7543 goto check_sec_image;
7546 if (qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7547 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7550 goto check_sec_image;
7552 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7554 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7555 ql_dbg(ql_dbg_init, vha, 0x018b,
7556 "Primary image signature (%#x) not valid\n",
7557 le32_to_cpu(pri_image_status.signature));
7558 goto check_sec_image;
7561 if (qla27xx_image_status_checksum(&pri_image_status)) {
7562 ql_dbg(ql_dbg_init, vha, 0x018c,
7563 "Primary image checksum failed\n");
7564 goto check_sec_image;
7567 valid_pri_image = true;
7569 if (pri_image_status.image_status_mask & 1) {
7570 ql_dbg(ql_dbg_init, vha, 0x018d,
7571 "Primary image is active\n");
7572 active_pri_image = true;
7576 if (!ha->flt_region_img_status_sec) {
7577 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7578 goto check_valid_image;
7581 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7582 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7583 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7585 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7586 ql_dbg(ql_dbg_init, vha, 0x018b,
7587 "Secondary image signature (%#x) not valid\n",
7588 le32_to_cpu(sec_image_status.signature));
7589 goto check_valid_image;
7592 if (qla27xx_image_status_checksum(&sec_image_status)) {
7593 ql_dbg(ql_dbg_init, vha, 0x018c,
7594 "Secondary image checksum failed\n");
7595 goto check_valid_image;
7598 valid_sec_image = true;
7600 if (sec_image_status.image_status_mask & 1) {
7601 ql_dbg(ql_dbg_init, vha, 0x018d,
7602 "Secondary image is active\n");
7603 active_sec_image = true;
7607 if (valid_pri_image && active_pri_image)
7608 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7610 if (valid_sec_image && active_sec_image) {
7611 if (!active_regions->global ||
7612 qla27xx_compare_image_generation(
7613 &pri_image_status, &sec_image_status) < 0) {
7614 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7618 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7619 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7620 "default (boot/fw)" :
7621 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7623 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7624 "secondary" : "invalid",
7625 active_regions->global);
7628 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7631 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7632 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7636 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7640 uint templates, segments, fragment;
7645 uint32_t risc_addr, risc_size, risc_attr = 0;
7646 struct qla_hw_data *ha = vha->hw;
7647 struct req_que *req = ha->req_q_map[0];
7648 struct fwdt *fwdt = ha->fwdt;
7650 ql_dbg(ql_dbg_init, vha, 0x008b,
7651 "FW: Loading firmware from flash (%x).\n", faddr);
7653 dcode = (void *)req->ring;
7654 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7655 if (qla24xx_risc_firmware_invalid(dcode)) {
7656 ql_log(ql_log_fatal, vha, 0x008c,
7657 "Unable to verify the integrity of flash firmware "
7659 ql_log(ql_log_fatal, vha, 0x008d,
7660 "Firmware data: %08x %08x %08x %08x.\n",
7661 dcode[0], dcode[1], dcode[2], dcode[3]);
7663 return QLA_FUNCTION_FAILED;
7666 dcode = (void *)req->ring;
7668 segments = FA_RISC_CODE_SEGMENTS;
7669 for (j = 0; j < segments; j++) {
7670 ql_dbg(ql_dbg_init, vha, 0x008d,
7671 "-> Loading segment %u...\n", j);
7672 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7673 risc_addr = be32_to_cpu(dcode[2]);
7674 risc_size = be32_to_cpu(dcode[3]);
7676 *srisc_addr = risc_addr;
7677 risc_attr = be32_to_cpu(dcode[9]);
7680 dlen = ha->fw_transfer_size >> 2;
7681 for (fragment = 0; risc_size; fragment++) {
7682 if (dlen > risc_size)
7685 ql_dbg(ql_dbg_init, vha, 0x008e,
7686 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7687 fragment, risc_addr, faddr, dlen);
7688 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7689 for (i = 0; i < dlen; i++)
7690 dcode[i] = swab32(dcode[i]);
7692 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7694 ql_log(ql_log_fatal, vha, 0x008f,
7695 "-> Failed load firmware fragment %u.\n",
7697 return QLA_FUNCTION_FAILED;
7706 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7709 templates = (risc_attr & BIT_9) ? 2 : 1;
7710 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7711 for (j = 0; j < templates; j++, fwdt++) {
7713 vfree(fwdt->template);
7714 fwdt->template = NULL;
7717 dcode = (void *)req->ring;
7718 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7719 risc_size = be32_to_cpu(dcode[2]);
7720 ql_dbg(ql_dbg_init, vha, 0x0161,
7721 "-> fwdt%u template array at %#x (%#x dwords)\n",
7722 j, faddr, risc_size);
7723 if (!risc_size || !~risc_size) {
7724 ql_dbg(ql_dbg_init, vha, 0x0162,
7725 "-> fwdt%u failed to read array\n", j);
7729 /* skip header and ignore checksum */
7733 ql_dbg(ql_dbg_init, vha, 0x0163,
7734 "-> fwdt%u template allocate template %#x words...\n",
7736 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7737 if (!fwdt->template) {
7738 ql_log(ql_log_warn, vha, 0x0164,
7739 "-> fwdt%u failed allocate template.\n", j);
7743 dcode = fwdt->template;
7744 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7746 if (!qla27xx_fwdt_template_valid(dcode)) {
7747 ql_log(ql_log_warn, vha, 0x0165,
7748 "-> fwdt%u failed template validate\n", j);
7752 dlen = qla27xx_fwdt_template_size(dcode);
7753 ql_dbg(ql_dbg_init, vha, 0x0166,
7754 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7755 j, dlen, dlen / sizeof(*dcode));
7756 if (dlen > risc_size * sizeof(*dcode)) {
7757 ql_log(ql_log_warn, vha, 0x0167,
7758 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7759 j, dlen - risc_size * sizeof(*dcode));
7763 fwdt->length = dlen;
7764 ql_dbg(ql_dbg_init, vha, 0x0168,
7765 "-> fwdt%u loaded template ok\n", j);
7767 faddr += risc_size + 1;
7774 vfree(fwdt->template);
7775 fwdt->template = NULL;
7781 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7784 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7788 uint16_t *wcode, *fwcode;
7789 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7790 struct fw_blob *blob;
7791 struct qla_hw_data *ha = vha->hw;
7792 struct req_que *req = ha->req_q_map[0];
7794 /* Load firmware blob. */
7795 blob = qla2x00_request_firmware(vha);
7797 ql_log(ql_log_info, vha, 0x0083,
7798 "Firmware image unavailable.\n");
7799 ql_log(ql_log_info, vha, 0x0084,
7800 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7801 return QLA_FUNCTION_FAILED;
7806 wcode = (uint16_t *)req->ring;
7808 fwcode = (uint16_t *)blob->fw->data;
7811 /* Validate firmware image by checking version. */
7812 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7813 ql_log(ql_log_fatal, vha, 0x0085,
7814 "Unable to verify integrity of firmware image (%zd).\n",
7816 goto fail_fw_integrity;
7818 for (i = 0; i < 4; i++)
7819 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7820 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7821 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7822 wcode[2] == 0 && wcode[3] == 0)) {
7823 ql_log(ql_log_fatal, vha, 0x0086,
7824 "Unable to verify integrity of firmware image.\n");
7825 ql_log(ql_log_fatal, vha, 0x0087,
7826 "Firmware data: %04x %04x %04x %04x.\n",
7827 wcode[0], wcode[1], wcode[2], wcode[3]);
7828 goto fail_fw_integrity;
7832 while (*seg && rval == QLA_SUCCESS) {
7834 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7835 risc_size = be16_to_cpu(fwcode[3]);
7837 /* Validate firmware image size. */
7838 fwclen += risc_size * sizeof(uint16_t);
7839 if (blob->fw->size < fwclen) {
7840 ql_log(ql_log_fatal, vha, 0x0088,
7841 "Unable to verify integrity of firmware image "
7842 "(%zd).\n", blob->fw->size);
7843 goto fail_fw_integrity;
7847 while (risc_size > 0 && rval == QLA_SUCCESS) {
7848 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7849 if (wlen > risc_size)
7851 ql_dbg(ql_dbg_init, vha, 0x0089,
7852 "Loading risc segment@ risc addr %x number of "
7853 "words 0x%x.\n", risc_addr, wlen);
7855 for (i = 0; i < wlen; i++)
7856 wcode[i] = swab16(fwcode[i]);
7858 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7861 ql_log(ql_log_fatal, vha, 0x008a,
7862 "Failed to load segment %d of firmware.\n",
7879 return QLA_FUNCTION_FAILED;
7883 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7886 uint templates, segments, fragment;
7889 uint32_t risc_addr, risc_size, risc_attr = 0;
7892 struct fw_blob *blob;
7894 struct qla_hw_data *ha = vha->hw;
7895 struct req_que *req = ha->req_q_map[0];
7896 struct fwdt *fwdt = ha->fwdt;
7898 ql_dbg(ql_dbg_init, vha, 0x0090,
7899 "-> FW: Loading via request-firmware.\n");
7901 blob = qla2x00_request_firmware(vha);
7903 ql_log(ql_log_warn, vha, 0x0092,
7904 "-> Firmware file not found.\n");
7906 return QLA_FUNCTION_FAILED;
7909 fwcode = (void *)blob->fw->data;
7911 if (qla24xx_risc_firmware_invalid(dcode)) {
7912 ql_log(ql_log_fatal, vha, 0x0093,
7913 "Unable to verify integrity of firmware image (%zd).\n",
7915 ql_log(ql_log_fatal, vha, 0x0095,
7916 "Firmware data: %08x %08x %08x %08x.\n",
7917 dcode[0], dcode[1], dcode[2], dcode[3]);
7918 return QLA_FUNCTION_FAILED;
7921 dcode = (void *)req->ring;
7923 segments = FA_RISC_CODE_SEGMENTS;
7924 for (j = 0; j < segments; j++) {
7925 ql_dbg(ql_dbg_init, vha, 0x0096,
7926 "-> Loading segment %u...\n", j);
7927 risc_addr = be32_to_cpu(fwcode[2]);
7928 risc_size = be32_to_cpu(fwcode[3]);
7931 *srisc_addr = risc_addr;
7932 risc_attr = be32_to_cpu(fwcode[9]);
7935 dlen = ha->fw_transfer_size >> 2;
7936 for (fragment = 0; risc_size; fragment++) {
7937 if (dlen > risc_size)
7940 ql_dbg(ql_dbg_init, vha, 0x0097,
7941 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7942 fragment, risc_addr,
7943 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7946 for (i = 0; i < dlen; i++)
7947 dcode[i] = swab32(fwcode[i]);
7949 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7951 ql_log(ql_log_fatal, vha, 0x0098,
7952 "-> Failed load firmware fragment %u.\n",
7954 return QLA_FUNCTION_FAILED;
7963 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7966 templates = (risc_attr & BIT_9) ? 2 : 1;
7967 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
7968 for (j = 0; j < templates; j++, fwdt++) {
7970 vfree(fwdt->template);
7971 fwdt->template = NULL;
7974 risc_size = be32_to_cpu(fwcode[2]);
7975 ql_dbg(ql_dbg_init, vha, 0x0171,
7976 "-> fwdt%u template array at %#x (%#x dwords)\n",
7977 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
7979 if (!risc_size || !~risc_size) {
7980 ql_dbg(ql_dbg_init, vha, 0x0172,
7981 "-> fwdt%u failed to read array\n", j);
7985 /* skip header and ignore checksum */
7989 ql_dbg(ql_dbg_init, vha, 0x0173,
7990 "-> fwdt%u template allocate template %#x words...\n",
7992 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7993 if (!fwdt->template) {
7994 ql_log(ql_log_warn, vha, 0x0174,
7995 "-> fwdt%u failed allocate template.\n", j);
7999 dcode = fwdt->template;
8000 for (i = 0; i < risc_size; i++)
8001 dcode[i] = fwcode[i];
8003 if (!qla27xx_fwdt_template_valid(dcode)) {
8004 ql_log(ql_log_warn, vha, 0x0175,
8005 "-> fwdt%u failed template validate\n", j);
8009 dlen = qla27xx_fwdt_template_size(dcode);
8010 ql_dbg(ql_dbg_init, vha, 0x0176,
8011 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8012 j, dlen, dlen / sizeof(*dcode));
8013 if (dlen > risc_size * sizeof(*dcode)) {
8014 ql_log(ql_log_warn, vha, 0x0177,
8015 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8016 j, dlen - risc_size * sizeof(*dcode));
8020 fwdt->length = dlen;
8021 ql_dbg(ql_dbg_init, vha, 0x0178,
8022 "-> fwdt%u loaded template ok\n", j);
8024 fwcode += risc_size + 1;
8031 vfree(fwdt->template);
8032 fwdt->template = NULL;
8039 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8043 if (ql2xfwloadbin == 1)
8044 return qla81xx_load_risc(vha, srisc_addr);
8048 * 1) Firmware via request-firmware interface (.bin file).
8049 * 2) Firmware residing in flash.
8051 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8052 if (rval == QLA_SUCCESS)
8055 return qla24xx_load_risc_flash(vha, srisc_addr,
8056 vha->hw->flt_region_fw);
8060 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8063 struct qla_hw_data *ha = vha->hw;
8064 struct active_regions active_regions = { };
8066 if (ql2xfwloadbin == 2)
8069 /* FW Load priority:
8070 * 1) Firmware residing in flash.
8071 * 2) Firmware via request-firmware interface (.bin file).
8072 * 3) Golden-Firmware residing in flash -- (limited operation).
8075 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8076 goto try_primary_fw;
8078 qla27xx_get_active_image(vha, &active_regions);
8080 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8081 goto try_primary_fw;
8083 ql_dbg(ql_dbg_init, vha, 0x008b,
8084 "Loading secondary firmware image.\n");
8085 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8090 ql_dbg(ql_dbg_init, vha, 0x008b,
8091 "Loading primary firmware image.\n");
8092 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8097 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8098 if (!rval || !ha->flt_region_gold_fw)
8101 ql_log(ql_log_info, vha, 0x0099,
8102 "Attempting to fallback to golden firmware.\n");
8103 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8107 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8108 ha->flags.running_gold_fw = 1;
8113 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8116 struct qla_hw_data *ha = vha->hw;
8118 if (ha->flags.pci_channel_io_perm_failure)
8120 if (!IS_FWI2_CAPABLE(ha))
8122 if (!ha->fw_major_version)
8124 if (!ha->flags.fw_started)
8127 ret = qla2x00_stop_firmware(vha);
8128 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8129 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8130 ha->isp_ops->reset_chip(vha);
8131 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8133 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8135 ql_log(ql_log_info, vha, 0x8015,
8136 "Attempting retry of stop-firmware command.\n");
8137 ret = qla2x00_stop_firmware(vha);
8141 ha->flags.fw_init_done = 0;
8145 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8147 int rval = QLA_SUCCESS;
8149 uint16_t mb[MAILBOX_REGISTER_COUNT];
8150 struct qla_hw_data *ha = vha->hw;
8151 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8156 rval = qla2x00_fw_ready(base_vha);
8158 if (rval == QLA_SUCCESS) {
8159 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8160 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8163 vha->flags.management_server_logged_in = 0;
8165 /* Login to SNS first */
8166 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8168 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8169 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8170 ql_dbg(ql_dbg_init, vha, 0x0120,
8171 "Failed SNS login: loop_id=%x, rval2=%d\n",
8174 ql_dbg(ql_dbg_init, vha, 0x0103,
8175 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8176 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8177 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8178 return (QLA_FUNCTION_FAILED);
8181 atomic_set(&vha->loop_down_timer, 0);
8182 atomic_set(&vha->loop_state, LOOP_UP);
8183 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8184 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8185 rval = qla2x00_loop_resync(base_vha);
8190 /* 84XX Support **************************************************************/
8192 static LIST_HEAD(qla_cs84xx_list);
8193 static DEFINE_MUTEX(qla_cs84xx_mutex);
8195 static struct qla_chip_state_84xx *
8196 qla84xx_get_chip(struct scsi_qla_host *vha)
8198 struct qla_chip_state_84xx *cs84xx;
8199 struct qla_hw_data *ha = vha->hw;
8201 mutex_lock(&qla_cs84xx_mutex);
8203 /* Find any shared 84xx chip. */
8204 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8205 if (cs84xx->bus == ha->pdev->bus) {
8206 kref_get(&cs84xx->kref);
8211 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8215 kref_init(&cs84xx->kref);
8216 spin_lock_init(&cs84xx->access_lock);
8217 mutex_init(&cs84xx->fw_update_mutex);
8218 cs84xx->bus = ha->pdev->bus;
8220 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8222 mutex_unlock(&qla_cs84xx_mutex);
8227 __qla84xx_chip_release(struct kref *kref)
8229 struct qla_chip_state_84xx *cs84xx =
8230 container_of(kref, struct qla_chip_state_84xx, kref);
8232 mutex_lock(&qla_cs84xx_mutex);
8233 list_del(&cs84xx->list);
8234 mutex_unlock(&qla_cs84xx_mutex);
8239 qla84xx_put_chip(struct scsi_qla_host *vha)
8241 struct qla_hw_data *ha = vha->hw;
8244 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8248 qla84xx_init_chip(scsi_qla_host_t *vha)
8252 struct qla_hw_data *ha = vha->hw;
8254 mutex_lock(&ha->cs84xx->fw_update_mutex);
8256 rval = qla84xx_verify_chip(vha, status);
8258 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8260 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8264 /* 81XX Support **************************************************************/
8267 qla81xx_nvram_config(scsi_qla_host_t *vha)
8270 struct init_cb_81xx *icb;
8271 struct nvram_81xx *nv;
8273 uint8_t *dptr1, *dptr2;
8276 struct qla_hw_data *ha = vha->hw;
8278 struct active_regions active_regions = { };
8281 icb = (struct init_cb_81xx *)ha->init_cb;
8284 /* Determine NVRAM starting address. */
8285 ha->nvram_size = sizeof(*nv);
8286 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8287 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8288 ha->vpd_size = FA_VPD_SIZE_82XX;
8290 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8291 qla28xx_get_aux_images(vha, &active_regions);
8293 /* Get VPD data into cache */
8294 ha->vpd = ha->nvram + VPD_OFFSET;
8296 faddr = ha->flt_region_vpd;
8297 if (IS_QLA28XX(ha)) {
8298 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8299 faddr = ha->flt_region_vpd_sec;
8300 ql_dbg(ql_dbg_init, vha, 0x0110,
8301 "Loading %s nvram image.\n",
8302 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8303 "primary" : "secondary");
8305 ha->isp_ops->read_optrom(vha, ha->vpd, faddr << 2, ha->vpd_size);
8307 /* Get NVRAM data into cache and calculate checksum. */
8308 faddr = ha->flt_region_nvram;
8309 if (IS_QLA28XX(ha)) {
8310 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8311 faddr = ha->flt_region_nvram_sec;
8313 ql_dbg(ql_dbg_init, vha, 0x0110,
8314 "Loading %s nvram image.\n",
8315 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8316 "primary" : "secondary");
8317 ha->isp_ops->read_optrom(vha, ha->nvram, faddr << 2, ha->nvram_size);
8319 dptr = (uint32_t *)nv;
8320 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8321 chksum += le32_to_cpu(*dptr);
8323 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8324 "Contents of NVRAM:\n");
8325 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8326 nv, ha->nvram_size);
8328 /* Bad NVRAM data, set defaults parameters. */
8329 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8330 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8331 /* Reset NVRAM data. */
8332 ql_log(ql_log_info, vha, 0x0073,
8333 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8334 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8335 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8336 ql_log(ql_log_info, vha, 0x0074,
8337 "Falling back to functioning (yet invalid -- WWPN) "
8341 * Set default initialization control block.
8343 memset(nv, 0, ha->nvram_size);
8344 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8345 nv->version = cpu_to_le16(ICB_VERSION);
8346 nv->frame_payload_size = 2048;
8347 nv->execution_throttle = cpu_to_le16(0xFFFF);
8348 nv->exchange_count = cpu_to_le16(0);
8349 nv->port_name[0] = 0x21;
8350 nv->port_name[1] = 0x00 + ha->port_no + 1;
8351 nv->port_name[2] = 0x00;
8352 nv->port_name[3] = 0xe0;
8353 nv->port_name[4] = 0x8b;
8354 nv->port_name[5] = 0x1c;
8355 nv->port_name[6] = 0x55;
8356 nv->port_name[7] = 0x86;
8357 nv->node_name[0] = 0x20;
8358 nv->node_name[1] = 0x00;
8359 nv->node_name[2] = 0x00;
8360 nv->node_name[3] = 0xe0;
8361 nv->node_name[4] = 0x8b;
8362 nv->node_name[5] = 0x1c;
8363 nv->node_name[6] = 0x55;
8364 nv->node_name[7] = 0x86;
8365 nv->login_retry_count = cpu_to_le16(8);
8366 nv->interrupt_delay_timer = cpu_to_le16(0);
8367 nv->login_timeout = cpu_to_le16(0);
8368 nv->firmware_options_1 =
8369 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8370 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8371 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8372 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8373 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8374 nv->efi_parameters = cpu_to_le32(0);
8375 nv->reset_delay = 5;
8376 nv->max_luns_per_target = cpu_to_le16(128);
8377 nv->port_down_retry_count = cpu_to_le16(30);
8378 nv->link_down_timeout = cpu_to_le16(180);
8379 nv->enode_mac[0] = 0x00;
8380 nv->enode_mac[1] = 0xC0;
8381 nv->enode_mac[2] = 0xDD;
8382 nv->enode_mac[3] = 0x04;
8383 nv->enode_mac[4] = 0x05;
8384 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8389 if (IS_T10_PI_CAPABLE(ha))
8390 nv->frame_payload_size &= ~7;
8392 qlt_81xx_config_nvram_stage1(vha, nv);
8394 /* Reset Initialization control block */
8395 memset(icb, 0, ha->init_cb_size);
8397 /* Copy 1st segment. */
8398 dptr1 = (uint8_t *)icb;
8399 dptr2 = (uint8_t *)&nv->version;
8400 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8402 *dptr1++ = *dptr2++;
8404 icb->login_retry_count = nv->login_retry_count;
8406 /* Copy 2nd segment. */
8407 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8408 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8409 cnt = (uint8_t *)&icb->reserved_5 -
8410 (uint8_t *)&icb->interrupt_delay_timer;
8412 *dptr1++ = *dptr2++;
8414 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8415 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8416 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8417 icb->enode_mac[0] = 0x00;
8418 icb->enode_mac[1] = 0xC0;
8419 icb->enode_mac[2] = 0xDD;
8420 icb->enode_mac[3] = 0x04;
8421 icb->enode_mac[4] = 0x05;
8422 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8425 /* Use extended-initialization control block. */
8426 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8427 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8429 * Setup driver NVRAM options.
8431 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8434 qlt_81xx_config_nvram_stage2(vha, icb);
8436 /* Use alternate WWN? */
8437 if (nv->host_p & cpu_to_le32(BIT_15)) {
8438 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8439 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8442 /* Prepare nodename */
8443 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8445 * Firmware will apply the following mask if the nodename was
8448 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8449 icb->node_name[0] &= 0xF0;
8452 /* Set host adapter parameters. */
8453 ha->flags.disable_risc_code_load = 0;
8454 ha->flags.enable_lip_reset = 0;
8455 ha->flags.enable_lip_full_login =
8456 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8457 ha->flags.enable_target_reset =
8458 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8459 ha->flags.enable_led_scheme = 0;
8460 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8462 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8463 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8465 /* save HBA serial number */
8466 ha->serial0 = icb->port_name[5];
8467 ha->serial1 = icb->port_name[6];
8468 ha->serial2 = icb->port_name[7];
8469 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8470 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8472 icb->execution_throttle = cpu_to_le16(0xFFFF);
8474 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8476 /* Set minimum login_timeout to 4 seconds. */
8477 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8478 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8479 if (le16_to_cpu(nv->login_timeout) < 4)
8480 nv->login_timeout = cpu_to_le16(4);
8481 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8483 /* Set minimum RATOV to 100 tenths of a second. */
8486 ha->loop_reset_delay = nv->reset_delay;
8488 /* Link Down Timeout = 0:
8490 * When Port Down timer expires we will start returning
8491 * I/O's to OS with "DID_NO_CONNECT".
8493 * Link Down Timeout != 0:
8495 * The driver waits for the link to come up after link down
8496 * before returning I/Os to OS with "DID_NO_CONNECT".
8498 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8499 ha->loop_down_abort_time =
8500 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8502 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8503 ha->loop_down_abort_time =
8504 (LOOP_DOWN_TIME - ha->link_down_timeout);
8507 /* Need enough time to try and get the port back. */
8508 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8509 if (qlport_down_retry)
8510 ha->port_down_retry_count = qlport_down_retry;
8512 /* Set login_retry_count */
8513 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8514 if (ha->port_down_retry_count ==
8515 le16_to_cpu(nv->port_down_retry_count) &&
8516 ha->port_down_retry_count > 3)
8517 ha->login_retry_count = ha->port_down_retry_count;
8518 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8519 ha->login_retry_count = ha->port_down_retry_count;
8520 if (ql2xloginretrycount)
8521 ha->login_retry_count = ql2xloginretrycount;
8523 /* if not running MSI-X we need handshaking on interrupts */
8524 if (!vha->hw->flags.msix_enabled &&
8525 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8526 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8529 if (!vha->flags.init_done) {
8530 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8531 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8532 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8533 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8535 icb->firmware_options_2 &= cpu_to_le32(
8536 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8537 vha->flags.process_response_queue = 0;
8538 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8539 ha->zio_mode = QLA_ZIO_MODE_6;
8541 ql_log(ql_log_info, vha, 0x0075,
8542 "ZIO mode %d enabled; timer delay (%d us).\n",
8544 ha->zio_timer * 100);
8546 icb->firmware_options_2 |= cpu_to_le32(
8547 (uint32_t)ha->zio_mode);
8548 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8549 vha->flags.process_response_queue = 1;
8552 /* enable RIDA Format2 */
8553 icb->firmware_options_3 |= BIT_0;
8555 /* N2N: driver will initiate Login instead of FW */
8556 icb->firmware_options_3 |= BIT_8;
8558 /* Determine NVMe/FCP priority for target ports */
8559 ha->fc4_type_priority = qla2xxx_get_fc4_priority(vha);
8562 ql_log(ql_log_warn, vha, 0x0076,
8563 "NVRAM configuration failed.\n");
8569 qla82xx_restart_isp(scsi_qla_host_t *vha)
8572 struct qla_hw_data *ha = vha->hw;
8573 struct scsi_qla_host *vp;
8574 unsigned long flags;
8576 status = qla2x00_init_rings(vha);
8578 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8579 ha->flags.chip_reset_done = 1;
8581 status = qla2x00_fw_ready(vha);
8583 /* Issue a marker after FW becomes ready. */
8584 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8585 vha->flags.online = 1;
8586 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8589 /* if no cable then assume it's good */
8590 if ((vha->device_flags & DFLG_NO_CABLE))
8595 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8597 if (!atomic_read(&vha->loop_down_timer)) {
8599 * Issue marker command only when we are going
8600 * to start the I/O .
8602 vha->marker_needed = 1;
8605 ha->isp_ops->enable_intrs(ha);
8607 ha->isp_abort_cnt = 0;
8608 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8610 /* Update the firmware version */
8611 status = qla82xx_check_md_needed(vha);
8614 ha->flags.fce_enabled = 1;
8616 fce_calc_size(ha->fce_bufs));
8617 rval = qla2x00_enable_fce_trace(vha,
8618 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8621 ql_log(ql_log_warn, vha, 0x8001,
8622 "Unable to reinitialize FCE (%d).\n",
8624 ha->flags.fce_enabled = 0;
8629 memset(ha->eft, 0, EFT_SIZE);
8630 rval = qla2x00_enable_eft_trace(vha,
8631 ha->eft_dma, EFT_NUM_BUFFERS);
8633 ql_log(ql_log_warn, vha, 0x8010,
8634 "Unable to reinitialize EFT (%d).\n",
8641 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8642 "qla82xx_restart_isp succeeded.\n");
8644 spin_lock_irqsave(&ha->vport_slock, flags);
8645 list_for_each_entry(vp, &ha->vp_list, list) {
8647 atomic_inc(&vp->vref_count);
8648 spin_unlock_irqrestore(&ha->vport_slock, flags);
8650 qla2x00_vp_abort_isp(vp);
8652 spin_lock_irqsave(&ha->vport_slock, flags);
8653 atomic_dec(&vp->vref_count);
8656 spin_unlock_irqrestore(&ha->vport_slock, flags);
8659 ql_log(ql_log_warn, vha, 0x8016,
8660 "qla82xx_restart_isp **** FAILED ****.\n");
8667 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8669 struct qla_hw_data *ha = vha->hw;
8671 /* Hold status IOCBs until ABTS response received. */
8673 ha->fw_options[3] |= BIT_12;
8675 /* Set Retry FLOGI in case of P2P connection */
8676 if (ha->operating_mode == P2P) {
8677 ha->fw_options[2] |= BIT_3;
8678 ql_dbg(ql_dbg_disc, vha, 0x2103,
8679 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8680 __func__, ha->fw_options[2]);
8683 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8684 if (ql2xmvasynctoatio) {
8685 if (qla_tgt_mode_enabled(vha) ||
8686 qla_dual_mode_enabled(vha))
8687 ha->fw_options[2] |= BIT_11;
8689 ha->fw_options[2] &= ~BIT_11;
8692 if (qla_tgt_mode_enabled(vha) ||
8693 qla_dual_mode_enabled(vha)) {
8694 /* FW auto send SCSI status during */
8695 ha->fw_options[1] |= BIT_8;
8696 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8698 /* FW perform Exchange validation */
8699 ha->fw_options[2] |= BIT_4;
8701 ha->fw_options[1] &= ~BIT_8;
8702 ha->fw_options[10] &= 0x00ff;
8704 ha->fw_options[2] &= ~BIT_4;
8707 if (ql2xetsenable) {
8708 /* Enable ETS Burst. */
8709 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8710 ha->fw_options[2] |= BIT_9;
8713 ql_dbg(ql_dbg_init, vha, 0x00e9,
8714 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8715 __func__, ha->fw_options[1], ha->fw_options[2],
8716 ha->fw_options[3], vha->host->active_mode);
8718 qla2x00_set_fw_options(vha, ha->fw_options);
8722 * qla24xx_get_fcp_prio
8723 * Gets the fcp cmd priority value for the logged in port.
8724 * Looks for a match of the port descriptors within
8725 * each of the fcp prio config entries. If a match is found,
8726 * the tag (priority) value is returned.
8729 * vha = scsi host structure pointer.
8730 * fcport = port structure pointer.
8733 * non-zero (if found)
8740 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8743 uint8_t pid_match, wwn_match;
8745 uint32_t pid1, pid2;
8746 uint64_t wwn1, wwn2;
8747 struct qla_fcp_prio_entry *pri_entry;
8748 struct qla_hw_data *ha = vha->hw;
8750 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8754 entries = ha->fcp_prio_cfg->num_entries;
8755 pri_entry = &ha->fcp_prio_cfg->entry[0];
8757 for (i = 0; i < entries; i++) {
8758 pid_match = wwn_match = 0;
8760 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8765 /* check source pid for a match */
8766 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8767 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8768 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8769 if (pid1 == INVALID_PORT_ID)
8771 else if (pid1 == pid2)
8775 /* check destination pid for a match */
8776 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8777 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8778 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8779 if (pid1 == INVALID_PORT_ID)
8781 else if (pid1 == pid2)
8785 /* check source WWN for a match */
8786 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8787 wwn1 = wwn_to_u64(vha->port_name);
8788 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8789 if (wwn2 == (uint64_t)-1)
8791 else if (wwn1 == wwn2)
8795 /* check destination WWN for a match */
8796 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8797 wwn1 = wwn_to_u64(fcport->port_name);
8798 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8799 if (wwn2 == (uint64_t)-1)
8801 else if (wwn1 == wwn2)
8805 if (pid_match == 2 || wwn_match == 2) {
8806 /* Found a matching entry */
8807 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8808 priority = pri_entry->tag;
8819 * qla24xx_update_fcport_fcp_prio
8820 * Activates fcp priority for the logged in fc port
8823 * vha = scsi host structure pointer.
8824 * fcp = port structure pointer.
8827 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8833 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8839 if (fcport->port_type != FCT_TARGET ||
8840 fcport->loop_id == FC_NO_LOOP_ID)
8841 return QLA_FUNCTION_FAILED;
8843 priority = qla24xx_get_fcp_prio(vha, fcport);
8845 return QLA_FUNCTION_FAILED;
8847 if (IS_P3P_TYPE(vha->hw)) {
8848 fcport->fcp_prio = priority & 0xf;
8852 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8853 if (ret == QLA_SUCCESS) {
8854 if (fcport->fcp_prio != priority)
8855 ql_dbg(ql_dbg_user, vha, 0x709e,
8856 "Updated FCP_CMND priority - value=%d loop_id=%d "
8857 "port_id=%02x%02x%02x.\n", priority,
8858 fcport->loop_id, fcport->d_id.b.domain,
8859 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8860 fcport->fcp_prio = priority & 0xf;
8862 ql_dbg(ql_dbg_user, vha, 0x704f,
8863 "Unable to update FCP_CMND priority - ret=0x%x for "
8864 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8865 fcport->d_id.b.domain, fcport->d_id.b.area,
8866 fcport->d_id.b.al_pa);
8871 * qla24xx_update_all_fcp_prio
8872 * Activates fcp priority for all the logged in ports
8875 * ha = adapter block pointer.
8878 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8884 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8889 ret = QLA_FUNCTION_FAILED;
8890 /* We need to set priority for all logged in ports */
8891 list_for_each_entry(fcport, &vha->vp_fcports, list)
8892 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8897 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8898 int vp_idx, bool startqp)
8903 struct qla_hw_data *ha = vha->hw;
8904 uint16_t qpair_id = 0;
8905 struct qla_qpair *qpair = NULL;
8906 struct qla_msix_entry *msix;
8908 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8909 ql_log(ql_log_warn, vha, 0x00181,
8910 "FW/Driver is not multi-queue capable.\n");
8914 if (ql2xmqsupport || ql2xnvmeenable) {
8915 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8916 if (qpair == NULL) {
8917 ql_log(ql_log_warn, vha, 0x0182,
8918 "Failed to allocate memory for queue pair.\n");
8922 qpair->hw = vha->hw;
8924 qpair->qp_lock_ptr = &qpair->qp_lock;
8925 spin_lock_init(&qpair->qp_lock);
8926 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8928 /* Assign available que pair id */
8929 mutex_lock(&ha->mq_lock);
8930 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8931 if (ha->num_qpairs >= ha->max_qpairs) {
8932 mutex_unlock(&ha->mq_lock);
8933 ql_log(ql_log_warn, vha, 0x0183,
8934 "No resources to create additional q pair.\n");
8938 set_bit(qpair_id, ha->qpair_qid_map);
8939 ha->queue_pair_map[qpair_id] = qpair;
8940 qpair->id = qpair_id;
8941 qpair->vp_idx = vp_idx;
8942 qpair->fw_started = ha->flags.fw_started;
8943 INIT_LIST_HEAD(&qpair->hints_list);
8944 qpair->chip_reset = ha->base_qpair->chip_reset;
8945 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8946 qpair->enable_explicit_conf =
8947 ha->base_qpair->enable_explicit_conf;
8949 for (i = 0; i < ha->msix_count; i++) {
8950 msix = &ha->msix_entries[i];
8954 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8955 "Vector %x selected for qpair\n", msix->vector);
8959 ql_log(ql_log_warn, vha, 0x0184,
8960 "Out of MSI-X vectors!.\n");
8964 qpair->msix->in_use = 1;
8965 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8966 qpair->pdev = ha->pdev;
8967 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
8968 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8970 mutex_unlock(&ha->mq_lock);
8972 /* Create response queue first */
8973 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8975 ql_log(ql_log_warn, vha, 0x0185,
8976 "Failed to create response queue.\n");
8980 qpair->rsp = ha->rsp_q_map[rsp_id];
8982 /* Create request queue */
8983 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8986 ql_log(ql_log_warn, vha, 0x0186,
8987 "Failed to create request queue.\n");
8991 qpair->req = ha->req_q_map[req_id];
8992 qpair->rsp->req = qpair->req;
8993 qpair->rsp->qpair = qpair;
8994 /* init qpair to this cpu. Will adjust at run time. */
8995 qla_cpu_update(qpair, smp_processor_id());
8997 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8998 if (ha->fw_attributes & BIT_4)
8999 qpair->difdix_supported = 1;
9002 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9003 if (!qpair->srb_mempool) {
9004 ql_log(ql_log_warn, vha, 0xd036,
9005 "Failed to create srb mempool for qpair %d\n",
9010 /* Mark as online */
9013 if (!vha->flags.qpairs_available)
9014 vha->flags.qpairs_available = 1;
9016 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9017 "Request/Response queue pair created, id %d\n",
9019 ql_dbg(ql_dbg_init, vha, 0x0187,
9020 "Request/Response queue pair created, id %d\n",
9027 qla25xx_delete_rsp_que(vha, qpair->rsp);
9029 mutex_lock(&ha->mq_lock);
9030 qpair->msix->in_use = 0;
9031 list_del(&qpair->qp_list_elem);
9032 if (list_empty(&vha->qp_list))
9033 vha->flags.qpairs_available = 0;
9035 ha->queue_pair_map[qpair_id] = NULL;
9036 clear_bit(qpair_id, ha->qpair_qid_map);
9038 mutex_unlock(&ha->mq_lock);
9044 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9046 int ret = QLA_FUNCTION_FAILED;
9047 struct qla_hw_data *ha = qpair->hw;
9049 qpair->delete_in_progress = 1;
9051 ret = qla25xx_delete_req_que(vha, qpair->req);
9052 if (ret != QLA_SUCCESS)
9055 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9056 if (ret != QLA_SUCCESS)
9059 mutex_lock(&ha->mq_lock);
9060 ha->queue_pair_map[qpair->id] = NULL;
9061 clear_bit(qpair->id, ha->qpair_qid_map);
9063 list_del(&qpair->qp_list_elem);
9064 if (list_empty(&vha->qp_list)) {
9065 vha->flags.qpairs_available = 0;
9066 vha->flags.qpairs_req_created = 0;
9067 vha->flags.qpairs_rsp_created = 0;
9069 mempool_destroy(qpair->srb_mempool);
9071 mutex_unlock(&ha->mq_lock);