2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
20 #include <target/target_core_base.h>
21 #include "qla_target.h"
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static int qla2x00_fw_ready(scsi_qla_host_t *);
29 static int qla2x00_configure_hba(scsi_qla_host_t *);
30 static int qla2x00_configure_loop(scsi_qla_host_t *);
31 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
32 static int qla2x00_configure_fabric(scsi_qla_host_t *);
33 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
34 static int qla2x00_restart_isp(scsi_qla_host_t *);
36 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
37 static int qla84xx_init_chip(scsi_qla_host_t *);
38 static int qla25xx_init_queues(struct qla_hw_data *);
39 static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
40 static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *,
42 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
44 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
46 /* SRB Extensions ---------------------------------------------------------- */
49 qla2x00_sp_timeout(struct timer_list *t)
51 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
52 struct srb_iocb *iocb;
55 struct qla_hw_data *ha = sp->vha->hw;
57 WARN_ON_ONCE(irqs_disabled());
58 spin_lock_irqsave(&ha->hardware_lock, flags);
60 req->outstanding_cmds[sp->handle] = NULL;
61 iocb = &sp->u.iocb_cmd;
62 spin_unlock_irqrestore(&ha->hardware_lock, flags);
67 qla2x00_sp_free(void *ptr)
70 struct srb_iocb *iocb = &sp->u.iocb_cmd;
72 del_timer(&iocb->timer);
76 /* Asynchronous Login/Logout Routines -------------------------------------- */
79 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
82 struct qla_hw_data *ha = vha->hw;
84 /* Firmware should use switch negotiated r_a_tov for timeout. */
85 tmo = ha->r_a_tov / 10 * 2;
87 tmo = FX00_DEF_RATOV * 2;
88 } else if (!IS_FWI2_CAPABLE(ha)) {
90 * Except for earlier ISPs where the timeout is seeded from the
91 * initialization control block.
93 tmo = ha->login_timeout;
98 static void qla24xx_abort_iocb_timeout(void *data)
101 struct srb_iocb *abt = &sp->u.iocb_cmd;
103 abt->u.abt.comp_status = CS_TIMEOUT;
104 sp->done(sp, QLA_FUNCTION_TIMEOUT);
107 static void qla24xx_abort_sp_done(void *ptr, int res)
110 struct srb_iocb *abt = &sp->u.iocb_cmd;
112 if (del_timer(&sp->u.iocb_cmd.timer)) {
113 if (sp->flags & SRB_WAKEUP_ON_COMP)
114 complete(&abt->u.abt.comp);
120 static int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
122 scsi_qla_host_t *vha = cmd_sp->vha;
123 struct srb_iocb *abt_iocb;
125 int rval = QLA_FUNCTION_FAILED;
127 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
132 abt_iocb = &sp->u.iocb_cmd;
133 sp->type = SRB_ABT_CMD;
135 sp->qpair = cmd_sp->qpair;
137 sp->flags = SRB_WAKEUP_ON_COMP;
139 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
140 init_completion(&abt_iocb->u.abt.comp);
141 /* FW can send 2 x ABTS's timeout/20s */
142 qla2x00_init_timer(sp, 42);
144 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
145 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
147 sp->done = qla24xx_abort_sp_done;
149 ql_dbg(ql_dbg_async, vha, 0x507c,
150 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
153 rval = qla2x00_start_sp(sp);
154 if (rval != QLA_SUCCESS)
158 wait_for_completion(&abt_iocb->u.abt.comp);
159 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
160 QLA_SUCCESS : QLA_FUNCTION_FAILED;
172 qla2x00_async_iocb_timeout(void *data)
175 fc_port_t *fcport = sp->fcport;
176 struct srb_iocb *lio = &sp->u.iocb_cmd;
181 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
182 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
183 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
185 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
187 pr_info("Async-%s timeout - hdl=%x.\n",
188 sp->name, sp->handle);
193 rc = qla24xx_async_abort_cmd(sp, false);
195 /* Retry as needed. */
196 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
197 lio->u.logio.data[1] =
198 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
199 QLA_LOGIO_LOGIN_RETRIED : 0;
200 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
201 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
203 if (sp->qpair->req->outstanding_cmds[h] ==
205 sp->qpair->req->outstanding_cmds[h] =
210 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
211 sp->done(sp, QLA_FUNCTION_TIMEOUT);
215 case SRB_CT_PTHRU_CMD:
221 rc = qla24xx_async_abort_cmd(sp, false);
223 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
224 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
226 if (sp->qpair->req->outstanding_cmds[h] ==
228 sp->qpair->req->outstanding_cmds[h] =
233 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
234 sp->done(sp, QLA_FUNCTION_TIMEOUT);
241 qla2x00_async_login_sp_done(void *ptr, int res)
244 struct scsi_qla_host *vha = sp->vha;
245 struct srb_iocb *lio = &sp->u.iocb_cmd;
248 ql_dbg(ql_dbg_disc, vha, 0x20dd,
249 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
251 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
253 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
254 memset(&ea, 0, sizeof(ea));
255 ea.event = FCME_PLOGI_DONE;
256 ea.fcport = sp->fcport;
257 ea.data[0] = lio->u.logio.data[0];
258 ea.data[1] = lio->u.logio.data[1];
259 ea.iop[0] = lio->u.logio.iop[0];
260 ea.iop[1] = lio->u.logio.iop[1];
262 qla2x00_fcport_event_handler(vha, &ea);
269 fcport_is_smaller(fc_port_t *fcport)
271 if (wwn_to_u64(fcport->port_name) <
272 wwn_to_u64(fcport->vha->port_name))
279 fcport_is_bigger(fc_port_t *fcport)
281 return !fcport_is_smaller(fcport);
285 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
289 struct srb_iocb *lio;
290 int rval = QLA_FUNCTION_FAILED;
292 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
293 fcport->loop_id == FC_NO_LOOP_ID) {
294 ql_log(ql_log_warn, vha, 0xffff,
295 "%s: %8phC - not sending command.\n",
296 __func__, fcport->port_name);
300 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
304 fcport->flags |= FCF_ASYNC_SENT;
305 fcport->logout_completed = 0;
307 fcport->disc_state = DSC_LOGIN_PEND;
308 sp->type = SRB_LOGIN_CMD;
310 sp->gen1 = fcport->rscn_gen;
311 sp->gen2 = fcport->login_gen;
313 lio = &sp->u.iocb_cmd;
314 lio->timeout = qla2x00_async_iocb_timeout;
315 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
317 sp->done = qla2x00_async_login_sp_done;
318 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
319 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
321 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
323 if (fcport->fc4f_nvme)
324 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
326 ql_dbg(ql_dbg_disc, vha, 0x2072,
327 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
328 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
329 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
330 fcport->login_retry);
332 rval = qla2x00_start_sp(sp);
333 if (rval != QLA_SUCCESS) {
334 fcport->flags |= FCF_LOGIN_NEEDED;
335 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
343 fcport->flags &= ~FCF_ASYNC_SENT;
345 fcport->flags &= ~FCF_ASYNC_ACTIVE;
350 qla2x00_async_logout_sp_done(void *ptr, int res)
354 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
355 sp->fcport->login_gen++;
356 qlt_logo_completion_handler(sp->fcport, res);
361 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
364 struct srb_iocb *lio;
365 int rval = QLA_FUNCTION_FAILED;
367 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
370 fcport->flags |= FCF_ASYNC_SENT;
371 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
375 sp->type = SRB_LOGOUT_CMD;
378 lio = &sp->u.iocb_cmd;
379 lio->timeout = qla2x00_async_iocb_timeout;
380 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
382 sp->done = qla2x00_async_logout_sp_done;
384 ql_dbg(ql_dbg_disc, vha, 0x2070,
385 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
386 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
387 fcport->d_id.b.area, fcport->d_id.b.al_pa,
390 rval = qla2x00_start_sp(sp);
391 if (rval != QLA_SUCCESS)
398 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
403 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
406 fcport->flags &= ~FCF_ASYNC_ACTIVE;
407 /* Don't re-login in target mode */
408 if (!fcport->tgt_session)
409 qla2x00_mark_device_lost(vha, fcport, 1, 0);
410 qlt_logo_completion_handler(fcport, data[0]);
414 qla2x00_async_prlo_sp_done(void *s, int res)
416 srb_t *sp = (srb_t *)s;
417 struct srb_iocb *lio = &sp->u.iocb_cmd;
418 struct scsi_qla_host *vha = sp->vha;
420 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
421 if (!test_bit(UNLOADING, &vha->dpc_flags))
422 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
428 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
431 struct srb_iocb *lio;
434 rval = QLA_FUNCTION_FAILED;
435 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
439 sp->type = SRB_PRLO_CMD;
442 lio = &sp->u.iocb_cmd;
443 lio->timeout = qla2x00_async_iocb_timeout;
444 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
446 sp->done = qla2x00_async_prlo_sp_done;
448 ql_dbg(ql_dbg_disc, vha, 0x2070,
449 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
450 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
451 fcport->d_id.b.area, fcport->d_id.b.al_pa);
453 rval = qla2x00_start_sp(sp);
454 if (rval != QLA_SUCCESS)
462 fcport->flags &= ~FCF_ASYNC_ACTIVE;
467 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
469 struct fc_port *fcport = ea->fcport;
471 ql_dbg(ql_dbg_disc, vha, 0x20d2,
472 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
473 __func__, fcport->port_name, fcport->disc_state,
474 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
475 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
477 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
478 ql_dbg(ql_dbg_disc, vha, 0x2066,
479 "%s %8phC: adisc fail: post delete\n",
480 __func__, ea->fcport->port_name);
481 /* deleted = 0 & logout_on_delete = force fw cleanup */
483 fcport->logout_on_delete = 1;
484 qlt_schedule_sess_for_deletion(ea->fcport);
488 if (ea->fcport->disc_state == DSC_DELETE_PEND)
491 if (ea->sp->gen2 != ea->fcport->login_gen) {
492 /* target side must have changed it. */
493 ql_dbg(ql_dbg_disc, vha, 0x20d3,
494 "%s %8phC generation changed\n",
495 __func__, ea->fcport->port_name);
497 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
498 qla_rscn_replay(fcport);
499 qlt_schedule_sess_for_deletion(fcport);
503 __qla24xx_handle_gpdb_event(vha, ea);
506 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
508 struct qla_work_evt *e;
510 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
512 return QLA_FUNCTION_FAILED;
514 e->u.fcport.fcport = fcport;
515 fcport->flags |= FCF_ASYNC_ACTIVE;
516 return qla2x00_post_work(vha, e);
520 qla2x00_async_adisc_sp_done(void *ptr, int res)
523 struct scsi_qla_host *vha = sp->vha;
525 struct srb_iocb *lio = &sp->u.iocb_cmd;
527 ql_dbg(ql_dbg_disc, vha, 0x2066,
528 "Async done-%s res %x %8phC\n",
529 sp->name, res, sp->fcport->port_name);
531 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
533 memset(&ea, 0, sizeof(ea));
534 ea.event = FCME_ADISC_DONE;
536 ea.data[0] = lio->u.logio.data[0];
537 ea.data[1] = lio->u.logio.data[1];
538 ea.iop[0] = lio->u.logio.iop[0];
539 ea.iop[1] = lio->u.logio.iop[1];
540 ea.fcport = sp->fcport;
543 qla2x00_fcport_event_handler(vha, &ea);
549 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
553 struct srb_iocb *lio;
554 int rval = QLA_FUNCTION_FAILED;
556 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
559 fcport->flags |= FCF_ASYNC_SENT;
560 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
564 sp->type = SRB_ADISC_CMD;
567 lio = &sp->u.iocb_cmd;
568 lio->timeout = qla2x00_async_iocb_timeout;
569 sp->gen1 = fcport->rscn_gen;
570 sp->gen2 = fcport->login_gen;
571 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
573 sp->done = qla2x00_async_adisc_sp_done;
574 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
575 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
577 ql_dbg(ql_dbg_disc, vha, 0x206f,
578 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
579 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
581 rval = qla2x00_start_sp(sp);
582 if (rval != QLA_SUCCESS)
590 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
591 qla2x00_post_async_adisc_work(vha, fcport, data);
595 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
597 struct qla_hw_data *ha = vha->hw;
599 if (IS_FWI2_CAPABLE(ha))
600 return loop_id > NPH_LAST_HANDLE;
602 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
603 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
607 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
608 * @vha: adapter state pointer.
609 * @dev: port structure pointer.
612 * qla2x00 local function return status code.
617 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
620 struct qla_hw_data *ha = vha->hw;
621 unsigned long flags = 0;
625 spin_lock_irqsave(&ha->vport_slock, flags);
627 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
628 if (dev->loop_id >= LOOPID_MAP_SIZE ||
629 qla2x00_is_reserved_id(vha, dev->loop_id)) {
630 dev->loop_id = FC_NO_LOOP_ID;
631 rval = QLA_FUNCTION_FAILED;
633 set_bit(dev->loop_id, ha->loop_id_map);
635 spin_unlock_irqrestore(&ha->vport_slock, flags);
637 if (rval == QLA_SUCCESS)
638 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
639 "Assigning new loopid=%x, portid=%x.\n",
640 dev->loop_id, dev->d_id.b24);
642 ql_log(ql_log_warn, dev->vha, 0x2087,
643 "No loop_id's available, portid=%x.\n",
649 void qla2x00_clear_loop_id(fc_port_t *fcport)
651 struct qla_hw_data *ha = fcport->vha->hw;
653 if (fcport->loop_id == FC_NO_LOOP_ID ||
654 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
657 clear_bit(fcport->loop_id, ha->loop_id_map);
658 fcport->loop_id = FC_NO_LOOP_ID;
661 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
662 struct event_arg *ea)
664 fc_port_t *fcport, *conflict_fcport;
665 struct get_name_list_extended *e;
666 u16 i, n, found = 0, loop_id;
670 u8 current_login_state;
673 ql_dbg(ql_dbg_disc, vha, 0xffff,
674 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
675 __func__, fcport->port_name, fcport->disc_state,
676 fcport->fw_login_state, ea->rc,
677 fcport->login_gen, fcport->last_login_gen,
678 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
680 if (fcport->disc_state == DSC_DELETE_PEND)
683 if (ea->rc) { /* rval */
684 if (fcport->login_retry == 0) {
685 ql_dbg(ql_dbg_disc, vha, 0x20de,
686 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
687 fcport->port_name, fcport->login_retry);
692 if (fcport->last_rscn_gen != fcport->rscn_gen) {
693 qla_rscn_replay(fcport);
694 qlt_schedule_sess_for_deletion(fcport);
696 } else if (fcport->last_login_gen != fcport->login_gen) {
697 ql_dbg(ql_dbg_disc, vha, 0x20e0,
698 "%s %8phC login gen changed\n",
699 __func__, fcport->port_name);
703 n = ea->data[0] / sizeof(struct get_name_list_extended);
705 ql_dbg(ql_dbg_disc, vha, 0x20e1,
706 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
707 __func__, __LINE__, fcport->port_name, n,
708 fcport->d_id.b.domain, fcport->d_id.b.area,
709 fcport->d_id.b.al_pa, fcport->loop_id);
711 for (i = 0; i < n; i++) {
713 wwn = wwn_to_u64(e->port_name);
714 id.b.domain = e->port_id[2];
715 id.b.area = e->port_id[1];
716 id.b.al_pa = e->port_id[0];
719 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
722 if (IS_SW_RESV_ADDR(id))
727 loop_id = le16_to_cpu(e->nport_handle);
728 loop_id = (loop_id & 0x7fff);
729 if (fcport->fc4f_nvme)
730 current_login_state = e->current_login_state >> 4;
732 current_login_state = e->current_login_state & 0xf;
735 ql_dbg(ql_dbg_disc, vha, 0x20e2,
736 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
737 __func__, fcport->port_name,
738 e->current_login_state, fcport->fw_login_state,
739 fcport->fc4f_nvme, id.b.domain, id.b.area, id.b.al_pa,
740 fcport->d_id.b.domain, fcport->d_id.b.area,
741 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
743 switch (fcport->disc_state) {
744 case DSC_DELETE_PEND:
748 if ((id.b24 != fcport->d_id.b24 &&
750 fcport->loop_id != FC_NO_LOOP_ID) ||
751 (fcport->loop_id != FC_NO_LOOP_ID &&
752 fcport->loop_id != loop_id)) {
753 ql_dbg(ql_dbg_disc, vha, 0x20e3,
754 "%s %d %8phC post del sess\n",
755 __func__, __LINE__, fcport->port_name);
756 if (fcport->n2n_flag)
757 fcport->d_id.b24 = 0;
758 qlt_schedule_sess_for_deletion(fcport);
764 fcport->loop_id = loop_id;
765 if (fcport->n2n_flag)
766 fcport->d_id.b24 = id.b24;
768 wwn = wwn_to_u64(fcport->port_name);
769 qlt_find_sess_invalidate_other(vha, wwn,
770 id, loop_id, &conflict_fcport);
772 if (conflict_fcport) {
774 * Another share fcport share the same loop_id &
775 * nport id. Conflict fcport needs to finish
776 * cleanup before this fcport can proceed to login.
778 conflict_fcport->conflict = fcport;
779 fcport->login_pause = 1;
782 switch (vha->hw->current_topology) {
784 switch (current_login_state) {
785 case DSC_LS_PRLI_COMP:
786 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
787 vha, 0x20e4, "%s %d %8phC post gpdb\n",
788 __func__, __LINE__, fcport->port_name);
790 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
791 fcport->port_type = FCT_INITIATOR;
793 fcport->port_type = FCT_TARGET;
794 data[0] = data[1] = 0;
795 qla2x00_post_async_adisc_work(vha, fcport,
798 case DSC_LS_PORT_UNAVAIL:
800 if (fcport->loop_id == FC_NO_LOOP_ID) {
801 qla2x00_find_new_loop_id(vha, fcport);
802 fcport->fw_login_state =
805 ql_dbg(ql_dbg_disc, vha, 0x20e5,
806 "%s %d %8phC\n", __func__, __LINE__,
808 qla24xx_fcport_handle_login(vha, fcport);
813 fcport->fw_login_state = current_login_state;
815 switch (current_login_state) {
816 case DSC_LS_PRLI_COMP:
817 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
818 fcport->port_type = FCT_INITIATOR;
820 fcport->port_type = FCT_TARGET;
822 data[0] = data[1] = 0;
823 qla2x00_post_async_adisc_work(vha, fcport,
826 case DSC_LS_PLOGI_COMP:
827 if (fcport_is_bigger(fcport)) {
828 /* local adapter is smaller */
829 if (fcport->loop_id != FC_NO_LOOP_ID)
830 qla2x00_clear_loop_id(fcport);
832 fcport->loop_id = loop_id;
833 qla24xx_fcport_handle_login(vha,
839 if (fcport_is_smaller(fcport)) {
840 /* local adapter is bigger */
841 if (fcport->loop_id != FC_NO_LOOP_ID)
842 qla2x00_clear_loop_id(fcport);
844 fcport->loop_id = loop_id;
845 qla24xx_fcport_handle_login(vha,
851 } /* switch (ha->current_topology) */
855 switch (vha->hw->current_topology) {
858 for (i = 0; i < n; i++) {
860 id.b.domain = e->port_id[0];
861 id.b.area = e->port_id[1];
862 id.b.al_pa = e->port_id[2];
864 loop_id = le16_to_cpu(e->nport_handle);
866 if (fcport->d_id.b24 == id.b24) {
868 qla2x00_find_fcport_by_wwpn(vha,
870 if (conflict_fcport) {
871 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
873 "%s %d %8phC post del sess\n",
875 conflict_fcport->port_name);
876 qlt_schedule_sess_for_deletion
881 * FW already picked this loop id for
884 if (fcport->loop_id == loop_id)
885 fcport->loop_id = FC_NO_LOOP_ID;
887 qla24xx_fcport_handle_login(vha, fcport);
890 fcport->disc_state = DSC_DELETED;
891 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
892 if (fcport->n2n_link_reset_cnt < 2) {
893 fcport->n2n_link_reset_cnt++;
895 * remote port is not sending PLOGI.
896 * Reset link to kick start his state
899 set_bit(N2N_LINK_RESET,
902 if (fcport->n2n_chip_reset < 1) {
903 ql_log(ql_log_info, vha, 0x705d,
904 "Chip reset to bring laser down");
905 set_bit(ISP_ABORT_NEEDED,
907 fcport->n2n_chip_reset++;
909 ql_log(ql_log_info, vha, 0x705d,
910 "Remote port %8ph is not coming back\n",
912 fcport->scan_state = 0;
915 qla2xxx_wake_dpc(vha);
918 * report port suppose to do PLOGI. Give him
919 * more time. FW will catch it.
921 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
931 qla24xx_async_gnl_sp_done(void *s, int res)
934 struct scsi_qla_host *vha = sp->vha;
936 struct fc_port *fcport = NULL, *tf;
937 u16 i, n = 0, loop_id;
939 struct get_name_list_extended *e;
944 ql_dbg(ql_dbg_disc, vha, 0x20e7,
945 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
946 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
947 sp->u.iocb_cmd.u.mbx.in_mb[2]);
949 if (res == QLA_FUNCTION_TIMEOUT)
952 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
953 memset(&ea, 0, sizeof(ea));
956 ea.event = FCME_GNL_DONE;
958 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
959 sizeof(struct get_name_list_extended)) {
960 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
961 sizeof(struct get_name_list_extended);
962 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
965 for (i = 0; i < n; i++) {
967 loop_id = le16_to_cpu(e->nport_handle);
968 /* mask out reserve bit */
969 loop_id = (loop_id & 0x7fff);
970 set_bit(loop_id, vha->hw->loop_id_map);
971 wwn = wwn_to_u64(e->port_name);
973 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
974 "%s %8phC %02x:%02x:%02x CLS %x/%x lid %x \n",
975 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
976 e->port_id[0], e->current_login_state, e->last_login_state,
980 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
984 if (!list_empty(&vha->gnl.fcports))
985 list_splice_init(&vha->gnl.fcports, &h);
986 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
988 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
989 list_del_init(&fcport->gnl_entry);
990 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
991 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
992 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
995 qla2x00_fcport_event_handler(vha, &ea);
998 /* create new fcport if fw has knowledge of new sessions */
999 for (i = 0; i < n; i++) {
1004 wwn = wwn_to_u64(e->port_name);
1007 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
1008 if (!memcmp((u8 *)&wwn, fcport->port_name,
1015 id.b.domain = e->port_id[2];
1016 id.b.area = e->port_id[1];
1017 id.b.al_pa = e->port_id[0];
1020 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1021 ql_dbg(ql_dbg_disc, vha, 0x2065,
1022 "%s %d %8phC %06x post new sess\n",
1023 __func__, __LINE__, (u8 *)&wwn, id.b24);
1024 wwnn = wwn_to_u64(e->node_name);
1025 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1026 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
1030 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1032 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1037 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1040 struct srb_iocb *mbx;
1041 int rval = QLA_FUNCTION_FAILED;
1042 unsigned long flags;
1045 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1048 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1049 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1051 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1052 fcport->flags |= FCF_ASYNC_SENT;
1053 fcport->disc_state = DSC_GNL;
1054 fcport->last_rscn_gen = fcport->rscn_gen;
1055 fcport->last_login_gen = fcport->login_gen;
1057 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1058 if (vha->gnl.sent) {
1059 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1063 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1065 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1069 sp->type = SRB_MB_IOCB;
1070 sp->name = "gnlist";
1071 sp->gen1 = fcport->rscn_gen;
1072 sp->gen2 = fcport->login_gen;
1074 mbx = &sp->u.iocb_cmd;
1075 mbx->timeout = qla2x00_async_iocb_timeout;
1076 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1078 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1079 mb[0] = MBC_PORT_NODE_NAME_LIST;
1080 mb[1] = BIT_2 | BIT_3;
1081 mb[2] = MSW(vha->gnl.ldma);
1082 mb[3] = LSW(vha->gnl.ldma);
1083 mb[6] = MSW(MSD(vha->gnl.ldma));
1084 mb[7] = LSW(MSD(vha->gnl.ldma));
1085 mb[8] = vha->gnl.size;
1086 mb[9] = vha->vp_idx;
1088 sp->done = qla24xx_async_gnl_sp_done;
1090 ql_dbg(ql_dbg_disc, vha, 0x20da,
1091 "Async-%s - OUT WWPN %8phC hndl %x\n",
1092 sp->name, fcport->port_name, sp->handle);
1094 rval = qla2x00_start_sp(sp);
1095 if (rval != QLA_SUCCESS)
1102 fcport->flags &= ~FCF_ASYNC_SENT;
1107 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1109 struct qla_work_evt *e;
1111 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1113 return QLA_FUNCTION_FAILED;
1115 e->u.fcport.fcport = fcport;
1116 fcport->flags |= FCF_ASYNC_ACTIVE;
1117 return qla2x00_post_work(vha, e);
1121 void qla24xx_async_gpdb_sp_done(void *s, int res)
1124 struct scsi_qla_host *vha = sp->vha;
1125 struct qla_hw_data *ha = vha->hw;
1126 fc_port_t *fcport = sp->fcport;
1127 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1128 struct event_arg ea;
1130 ql_dbg(ql_dbg_disc, vha, 0x20db,
1131 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1132 sp->name, res, fcport->port_name, mb[1], mb[2]);
1134 if (res == QLA_FUNCTION_TIMEOUT) {
1135 dma_pool_free(sp->vha->hw->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1136 sp->u.iocb_cmd.u.mbx.in_dma);
1140 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1141 memset(&ea, 0, sizeof(ea));
1142 ea.event = FCME_GPDB_DONE;
1146 qla2x00_fcport_event_handler(vha, &ea);
1148 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1149 sp->u.iocb_cmd.u.mbx.in_dma);
1154 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1156 struct qla_work_evt *e;
1158 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1160 return QLA_FUNCTION_FAILED;
1162 e->u.fcport.fcport = fcport;
1164 return qla2x00_post_work(vha, e);
1168 qla2x00_async_prli_sp_done(void *ptr, int res)
1171 struct scsi_qla_host *vha = sp->vha;
1172 struct srb_iocb *lio = &sp->u.iocb_cmd;
1173 struct event_arg ea;
1175 ql_dbg(ql_dbg_disc, vha, 0x2129,
1176 "%s %8phC res %d \n", __func__,
1177 sp->fcport->port_name, res);
1179 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1181 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1182 memset(&ea, 0, sizeof(ea));
1183 ea.event = FCME_PRLI_DONE;
1184 ea.fcport = sp->fcport;
1185 ea.data[0] = lio->u.logio.data[0];
1186 ea.data[1] = lio->u.logio.data[1];
1187 ea.iop[0] = lio->u.logio.iop[0];
1188 ea.iop[1] = lio->u.logio.iop[1];
1191 qla2x00_fcport_event_handler(vha, &ea);
1198 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1201 struct srb_iocb *lio;
1202 int rval = QLA_FUNCTION_FAILED;
1204 if (!vha->flags.online)
1207 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1208 fcport->fw_login_state == DSC_LS_PRLI_PEND)
1211 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1215 fcport->flags |= FCF_ASYNC_SENT;
1216 fcport->logout_completed = 0;
1218 sp->type = SRB_PRLI_CMD;
1221 lio = &sp->u.iocb_cmd;
1222 lio->timeout = qla2x00_async_iocb_timeout;
1223 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1225 sp->done = qla2x00_async_prli_sp_done;
1226 lio->u.logio.flags = 0;
1228 if (fcport->fc4f_nvme)
1229 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1231 ql_dbg(ql_dbg_disc, vha, 0x211b,
1232 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1233 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1234 fcport->login_retry, fcport->fc4f_nvme ? "nvme" : "fc");
1236 rval = qla2x00_start_sp(sp);
1237 if (rval != QLA_SUCCESS) {
1238 fcport->flags |= FCF_LOGIN_NEEDED;
1239 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1247 fcport->flags &= ~FCF_ASYNC_SENT;
1251 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1253 struct qla_work_evt *e;
1255 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1257 return QLA_FUNCTION_FAILED;
1259 e->u.fcport.fcport = fcport;
1260 e->u.fcport.opt = opt;
1261 fcport->flags |= FCF_ASYNC_ACTIVE;
1262 return qla2x00_post_work(vha, e);
1265 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1268 struct srb_iocb *mbx;
1269 int rval = QLA_FUNCTION_FAILED;
1272 struct port_database_24xx *pd;
1273 struct qla_hw_data *ha = vha->hw;
1275 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1276 fcport->loop_id == FC_NO_LOOP_ID) {
1277 ql_log(ql_log_warn, vha, 0xffff,
1278 "%s: %8phC - not sending command.\n",
1279 __func__, fcport->port_name);
1283 fcport->disc_state = DSC_GPDB;
1285 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1289 fcport->flags |= FCF_ASYNC_SENT;
1290 sp->type = SRB_MB_IOCB;
1292 sp->gen1 = fcport->rscn_gen;
1293 sp->gen2 = fcport->login_gen;
1295 mbx = &sp->u.iocb_cmd;
1296 mbx->timeout = qla2x00_async_iocb_timeout;
1297 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1299 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1301 ql_log(ql_log_warn, vha, 0xd043,
1302 "Failed to allocate port database structure.\n");
1306 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1307 mb[0] = MBC_GET_PORT_DATABASE;
1308 mb[1] = fcport->loop_id;
1309 mb[2] = MSW(pd_dma);
1310 mb[3] = LSW(pd_dma);
1311 mb[6] = MSW(MSD(pd_dma));
1312 mb[7] = LSW(MSD(pd_dma));
1313 mb[9] = vha->vp_idx;
1316 mbx->u.mbx.in = (void *)pd;
1317 mbx->u.mbx.in_dma = pd_dma;
1319 sp->done = qla24xx_async_gpdb_sp_done;
1321 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1322 "Async-%s %8phC hndl %x opt %x\n",
1323 sp->name, fcport->port_name, sp->handle, opt);
1325 rval = qla2x00_start_sp(sp);
1326 if (rval != QLA_SUCCESS)
1332 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1335 fcport->flags &= ~FCF_ASYNC_SENT;
1337 qla24xx_post_gpdb_work(vha, fcport, opt);
1342 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1344 unsigned long flags;
1346 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1347 ea->fcport->login_gen++;
1348 ea->fcport->deleted = 0;
1349 ea->fcport->logout_on_delete = 1;
1351 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1352 vha->fcport_count++;
1353 ea->fcport->login_succ = 1;
1355 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1356 qla24xx_sched_upd_fcport(ea->fcport);
1357 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1358 } else if (ea->fcport->login_succ) {
1360 * We have an existing session. A late RSCN delivery
1361 * must have triggered the session to be re-validate.
1362 * Session is still valid.
1364 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1365 "%s %d %8phC session revalidate success\n",
1366 __func__, __LINE__, ea->fcport->port_name);
1367 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1369 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1373 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1375 fc_port_t *fcport = ea->fcport;
1376 struct port_database_24xx *pd;
1377 struct srb *sp = ea->sp;
1380 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1382 fcport->flags &= ~FCF_ASYNC_SENT;
1384 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1385 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__, fcport->port_name,
1386 fcport->disc_state, pd->current_login_state, fcport->fc4f_nvme,
1389 if (fcport->disc_state == DSC_DELETE_PEND)
1392 if (fcport->fc4f_nvme)
1393 ls = pd->current_login_state >> 4;
1395 ls = pd->current_login_state & 0xf;
1397 if (ea->sp->gen2 != fcport->login_gen) {
1398 /* target side must have changed it. */
1400 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1401 "%s %8phC generation changed\n",
1402 __func__, fcport->port_name);
1404 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1405 qla_rscn_replay(fcport);
1406 qlt_schedule_sess_for_deletion(fcport);
1411 case PDS_PRLI_COMPLETE:
1412 __qla24xx_parse_gpdb(vha, fcport, pd);
1414 case PDS_PLOGI_PENDING:
1415 case PDS_PLOGI_COMPLETE:
1416 case PDS_PRLI_PENDING:
1417 case PDS_PRLI2_PENDING:
1418 /* Set discovery state back to GNL to Relogin attempt */
1419 if (qla_dual_mode_enabled(vha) ||
1420 qla_ini_mode_enabled(vha)) {
1421 fcport->disc_state = DSC_GNL;
1422 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1425 case PDS_LOGO_PENDING:
1426 case PDS_PORT_UNAVAILABLE:
1428 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1429 __func__, __LINE__, fcport->port_name);
1430 qlt_schedule_sess_for_deletion(fcport);
1433 __qla24xx_handle_gpdb_event(vha, ea);
1436 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1441 if (qla_tgt_mode_enabled(vha))
1444 if (qla_dual_mode_enabled(vha)) {
1445 if (N2N_TOPO(vha->hw)) {
1448 mywwn = wwn_to_u64(vha->port_name);
1449 wwn = wwn_to_u64(fcport->port_name);
1452 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1453 && time_after_eq(jiffies,
1454 fcport->plogi_nack_done_deadline))
1460 /* initiator mode */
1464 if (login && fcport->login_retry) {
1465 fcport->login_retry--;
1466 if (fcport->loop_id == FC_NO_LOOP_ID) {
1467 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1468 rc = qla2x00_find_new_loop_id(vha, fcport);
1470 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1471 "%s %d %8phC post del sess - out of loopid\n",
1472 __func__, __LINE__, fcport->port_name);
1473 fcport->scan_state = 0;
1474 qlt_schedule_sess_for_deletion(fcport);
1478 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1479 "%s %d %8phC post login\n",
1480 __func__, __LINE__, fcport->port_name);
1481 qla2x00_post_async_login_work(vha, fcport, NULL);
1485 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1491 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20d8,
1492 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1493 __func__, fcport->port_name, fcport->disc_state,
1494 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1495 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1496 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1498 if (fcport->scan_state != QLA_FCPORT_FOUND)
1501 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1502 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1503 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1506 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP &&
1507 !N2N_TOPO(vha->hw)) {
1508 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1509 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1514 /* for pure Target Mode. Login will not be initiated */
1515 if (vha->host->active_mode == MODE_TARGET)
1518 if (fcport->flags & FCF_ASYNC_SENT) {
1519 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1523 switch (fcport->disc_state) {
1525 wwn = wwn_to_u64(fcport->node_name);
1526 switch (vha->hw->current_topology) {
1528 if (fcport_is_smaller(fcport)) {
1529 /* this adapter is bigger */
1530 if (fcport->login_retry) {
1531 if (fcport->loop_id == FC_NO_LOOP_ID) {
1532 qla2x00_find_new_loop_id(vha,
1534 fcport->fw_login_state =
1535 DSC_LS_PORT_UNAVAIL;
1537 fcport->login_retry--;
1538 qla_post_els_plogi_work(vha, fcport);
1540 ql_log(ql_log_info, vha, 0x705d,
1541 "Unable to reach remote port %8phC",
1545 qla24xx_post_gnl_work(vha, fcport);
1550 ql_dbg(ql_dbg_disc, vha, 0xffff,
1551 "%s %d %8phC post GNNID\n",
1552 __func__, __LINE__, fcport->port_name);
1553 qla24xx_post_gnnid_work(vha, fcport);
1554 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1555 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1556 "%s %d %8phC post gnl\n",
1557 __func__, __LINE__, fcport->port_name);
1558 qla24xx_post_gnl_work(vha, fcport);
1560 qla_chk_n2n_b4_login(vha, fcport);
1567 switch (vha->hw->current_topology) {
1569 if ((fcport->current_login_state & 0xf) == 0x6) {
1570 ql_dbg(ql_dbg_disc, vha, 0x2118,
1571 "%s %d %8phC post GPDB work\n",
1572 __func__, __LINE__, fcport->port_name);
1573 fcport->chip_reset =
1574 vha->hw->base_qpair->chip_reset;
1575 qla24xx_post_gpdb_work(vha, fcport, 0);
1577 ql_dbg(ql_dbg_disc, vha, 0x2118,
1578 "%s %d %8phC post %s PRLI\n",
1579 __func__, __LINE__, fcport->port_name,
1580 fcport->fc4f_nvme ? "NVME" : "FC");
1581 qla24xx_post_prli_work(vha, fcport);
1585 if (fcport->login_pause) {
1586 fcport->last_rscn_gen = fcport->rscn_gen;
1587 fcport->last_login_gen = fcport->login_gen;
1588 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1591 qla_chk_n2n_b4_login(vha, fcport);
1596 case DSC_LOGIN_FAILED:
1597 if (N2N_TOPO(vha->hw))
1598 qla_chk_n2n_b4_login(vha, fcport);
1600 qlt_schedule_sess_for_deletion(fcport);
1603 case DSC_LOGIN_COMPLETE:
1604 /* recheck login state */
1605 data[0] = data[1] = 0;
1606 qla2x00_post_async_adisc_work(vha, fcport, data);
1609 case DSC_LOGIN_PEND:
1610 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1611 qla24xx_post_prli_work(vha, fcport);
1614 case DSC_UPD_FCPORT:
1615 sec = jiffies_to_msecs(jiffies -
1616 fcport->jiffies_at_registration)/1000;
1617 if (fcport->sec_since_registration < sec && sec &&
1619 fcport->sec_since_registration = sec;
1620 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1621 "%s %8phC - Slow Rport registration(%d Sec)\n",
1622 __func__, fcport->port_name, sec);
1625 if (fcport->next_disc_state != DSC_DELETE_PEND)
1626 fcport->next_disc_state = DSC_ADISC;
1627 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1637 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1638 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1640 struct qla_work_evt *e;
1642 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1644 return QLA_FUNCTION_FAILED;
1646 e->u.new_sess.id = *id;
1647 e->u.new_sess.pla = pla;
1648 e->u.new_sess.fc4_type = fc4_type;
1649 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1651 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1653 return qla2x00_post_work(vha, e);
1657 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1658 struct event_arg *ea)
1660 fc_port_t *fcport = ea->fcport;
1662 ql_dbg(ql_dbg_disc, vha, 0x2102,
1663 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1664 __func__, fcport->port_name, fcport->disc_state,
1665 fcport->fw_login_state, fcport->login_pause,
1666 fcport->deleted, fcport->conflict,
1667 fcport->last_rscn_gen, fcport->rscn_gen,
1668 fcport->last_login_gen, fcport->login_gen,
1671 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1672 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1675 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1676 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1677 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1682 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1683 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1684 __func__, __LINE__, fcport->port_name);
1689 qla24xx_fcport_handle_login(vha, fcport);
1693 static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1694 struct event_arg *ea)
1696 ql_dbg(ql_dbg_disc, vha, 0x2118,
1697 "%s %d %8phC post PRLI\n",
1698 __func__, __LINE__, ea->fcport->port_name);
1699 qla24xx_post_prli_work(vha, ea->fcport);
1702 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1706 switch (ea->event) {
1708 if (test_bit(UNLOADING, &vha->dpc_flags))
1711 qla24xx_handle_relogin_event(vha, ea);
1714 if (test_bit(UNLOADING, &vha->dpc_flags))
1717 unsigned long flags;
1719 fcport = qla2x00_find_fcport_by_nportid
1722 fcport->scan_needed = 1;
1726 spin_lock_irqsave(&vha->work_lock, flags);
1727 if (vha->scan.scan_flags == 0) {
1728 ql_dbg(ql_dbg_disc, vha, 0xffff,
1729 "%s: schedule\n", __func__);
1730 vha->scan.scan_flags |= SF_QUEUED;
1731 schedule_delayed_work(&vha->scan.scan_work, 5);
1733 spin_unlock_irqrestore(&vha->work_lock, flags);
1737 qla24xx_handle_gnl_done_event(vha, ea);
1739 case FCME_GPSC_DONE:
1740 qla24xx_handle_gpsc_event(vha, ea);
1742 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1743 qla24xx_handle_plogi_done_event(vha, ea);
1745 case FCME_PRLI_DONE:
1746 qla24xx_handle_prli_done_event(vha, ea);
1748 case FCME_GPDB_DONE:
1749 qla24xx_handle_gpdb_event(vha, ea);
1751 case FCME_GPNID_DONE:
1752 qla24xx_handle_gpnid_event(vha, ea);
1754 case FCME_GFFID_DONE:
1755 qla24xx_handle_gffid_event(vha, ea);
1757 case FCME_ADISC_DONE:
1758 qla24xx_handle_adisc_event(vha, ea);
1760 case FCME_GNNID_DONE:
1761 qla24xx_handle_gnnid_event(vha, ea);
1763 case FCME_GFPNID_DONE:
1764 qla24xx_handle_gfpnid_event(vha, ea);
1766 case FCME_ELS_PLOGI_DONE:
1767 qla_handle_els_plogi_done(vha, ea);
1776 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1777 * to be consumed by the fcport
1779 void qla_rscn_replay(fc_port_t *fcport)
1781 struct event_arg ea;
1783 switch (fcport->disc_state) {
1784 case DSC_DELETE_PEND:
1790 if (fcport->scan_needed) {
1791 memset(&ea, 0, sizeof(ea));
1792 ea.event = FCME_RSCN;
1793 ea.id = fcport->d_id;
1794 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1795 qla2x00_fcport_event_handler(fcport->vha, &ea);
1800 qla2x00_tmf_iocb_timeout(void *data)
1803 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1805 tmf->u.tmf.comp_status = CS_TIMEOUT;
1806 complete(&tmf->u.tmf.comp);
1810 qla2x00_tmf_sp_done(void *ptr, int res)
1813 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1815 complete(&tmf->u.tmf.comp);
1819 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1822 struct scsi_qla_host *vha = fcport->vha;
1823 struct srb_iocb *tm_iocb;
1825 int rval = QLA_FUNCTION_FAILED;
1827 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1831 tm_iocb = &sp->u.iocb_cmd;
1832 sp->type = SRB_TM_CMD;
1835 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1836 init_completion(&tm_iocb->u.tmf.comp);
1837 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1839 tm_iocb->u.tmf.flags = flags;
1840 tm_iocb->u.tmf.lun = lun;
1841 tm_iocb->u.tmf.data = tag;
1842 sp->done = qla2x00_tmf_sp_done;
1844 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1845 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1846 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1847 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1849 rval = qla2x00_start_sp(sp);
1850 if (rval != QLA_SUCCESS)
1852 wait_for_completion(&tm_iocb->u.tmf.comp);
1854 rval = tm_iocb->u.tmf.data;
1856 if (rval != QLA_SUCCESS) {
1857 ql_log(ql_log_warn, vha, 0x8030,
1858 "TM IOCB failed (%x).\n", rval);
1861 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1862 flags = tm_iocb->u.tmf.flags;
1863 lun = (uint16_t)tm_iocb->u.tmf.lun;
1865 /* Issue Marker IOCB */
1866 qla2x00_marker(vha, vha->hw->base_qpair,
1867 fcport->loop_id, lun,
1868 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1873 fcport->flags &= ~FCF_ASYNC_SENT;
1879 qla24xx_async_abort_command(srb_t *sp)
1881 unsigned long flags = 0;
1884 fc_port_t *fcport = sp->fcport;
1885 struct qla_qpair *qpair = sp->qpair;
1886 struct scsi_qla_host *vha = fcport->vha;
1887 struct req_que *req = qpair->req;
1889 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1890 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1891 if (req->outstanding_cmds[handle] == sp)
1894 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1896 if (handle == req->num_outstanding_cmds) {
1897 /* Command not found. */
1898 return QLA_FUNCTION_FAILED;
1900 if (sp->type == SRB_FXIOCB_DCMD)
1901 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1902 FXDISC_ABORT_IOCTL);
1904 return qla24xx_async_abort_cmd(sp, true);
1908 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1910 switch (ea->data[0]) {
1911 case MBS_COMMAND_COMPLETE:
1912 ql_dbg(ql_dbg_disc, vha, 0x2118,
1913 "%s %d %8phC post gpdb\n",
1914 __func__, __LINE__, ea->fcport->port_name);
1916 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1917 ea->fcport->logout_on_delete = 1;
1918 ea->fcport->nvme_prli_service_param = ea->iop[0];
1919 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1920 ea->fcport->nvme_first_burst_size =
1921 (ea->iop[1] & 0xffff) * 512;
1923 ea->fcport->nvme_first_burst_size = 0;
1924 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1927 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1928 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1929 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1930 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1934 if (ea->fcport->fc4f_nvme) {
1935 ql_dbg(ql_dbg_disc, vha, 0x2118,
1936 "%s %d %8phC post fc4 prli\n",
1937 __func__, __LINE__, ea->fcport->port_name);
1938 ea->fcport->fc4f_nvme = 0;
1939 qla24xx_post_prli_work(vha, ea->fcport);
1943 /* at this point both PRLI NVME & PRLI FCP failed */
1944 if (N2N_TOPO(vha->hw)) {
1945 if (ea->fcport->n2n_link_reset_cnt < 3) {
1946 ea->fcport->n2n_link_reset_cnt++;
1948 * remote port is not sending Plogi. Reset
1949 * link to kick start his state machine
1951 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
1953 ql_log(ql_log_warn, vha, 0x2119,
1954 "%s %d %8phC Unable to reconnect\n",
1955 __func__, __LINE__, ea->fcport->port_name);
1959 * switch connect. login failed. Take connection
1960 * down and allow relogin to retrigger
1962 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1963 ea->fcport->keep_nport_handle = 0;
1964 qlt_schedule_sess_for_deletion(ea->fcport);
1971 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1973 port_id_t cid; /* conflict Nport id */
1975 struct fc_port *conflict_fcport;
1976 unsigned long flags;
1977 struct fc_port *fcport = ea->fcport;
1979 ql_dbg(ql_dbg_disc, vha, 0xffff,
1980 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1981 __func__, fcport->port_name, fcport->disc_state,
1982 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1983 ea->sp->gen1, fcport->rscn_gen,
1984 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1986 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1987 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1988 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1989 "%s %d %8phC Remote is trying to login\n",
1990 __func__, __LINE__, fcport->port_name);
1994 if ((fcport->disc_state == DSC_DELETE_PEND) ||
1995 (fcport->disc_state == DSC_DELETED)) {
1996 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2000 if (ea->sp->gen2 != fcport->login_gen) {
2001 /* target side must have changed it. */
2002 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2003 "%s %8phC generation changed\n",
2004 __func__, fcport->port_name);
2005 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2007 } else if (ea->sp->gen1 != fcport->rscn_gen) {
2008 ql_dbg(ql_dbg_disc, vha, 0x20d3,
2009 "%s %8phC RSCN generation changed\n",
2010 __func__, fcport->port_name);
2011 qla_rscn_replay(fcport);
2012 qlt_schedule_sess_for_deletion(fcport);
2016 switch (ea->data[0]) {
2017 case MBS_COMMAND_COMPLETE:
2019 * Driver must validate login state - If PRLI not complete,
2020 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
2023 if (ea->fcport->fc4f_nvme) {
2024 ql_dbg(ql_dbg_disc, vha, 0x2117,
2025 "%s %d %8phC post prli\n",
2026 __func__, __LINE__, ea->fcport->port_name);
2027 qla24xx_post_prli_work(vha, ea->fcport);
2029 ql_dbg(ql_dbg_disc, vha, 0x20ea,
2030 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
2031 __func__, __LINE__, ea->fcport->port_name,
2032 ea->fcport->loop_id, ea->fcport->d_id.b24);
2034 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2035 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2036 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2037 ea->fcport->logout_on_delete = 1;
2038 ea->fcport->send_els_logo = 0;
2039 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2040 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2042 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2045 case MBS_COMMAND_ERROR:
2046 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2047 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2049 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2050 ea->fcport->disc_state = DSC_LOGIN_FAILED;
2051 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2052 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2054 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2056 case MBS_LOOP_ID_USED:
2057 /* data[1] = IO PARAM 1 = nport ID */
2058 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2059 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2060 cid.b.al_pa = ea->iop[1] & 0xff;
2063 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2064 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2065 __func__, __LINE__, ea->fcport->port_name,
2066 ea->fcport->loop_id, cid.b24);
2068 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2069 ea->fcport->loop_id = FC_NO_LOOP_ID;
2070 qla24xx_post_gnl_work(vha, ea->fcport);
2072 case MBS_PORT_ID_USED:
2073 lid = ea->iop[1] & 0xffff;
2074 qlt_find_sess_invalidate_other(vha,
2075 wwn_to_u64(ea->fcport->port_name),
2076 ea->fcport->d_id, lid, &conflict_fcport);
2078 if (conflict_fcport) {
2080 * Another fcport share the same loop_id/nport id.
2081 * Conflict fcport needs to finish cleanup before this
2082 * fcport can proceed to login.
2084 conflict_fcport->conflict = ea->fcport;
2085 ea->fcport->login_pause = 1;
2087 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2088 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2089 __func__, __LINE__, ea->fcport->port_name,
2090 ea->fcport->d_id.b24, lid);
2092 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2093 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2094 __func__, __LINE__, ea->fcport->port_name,
2095 ea->fcport->d_id.b24, lid);
2097 qla2x00_clear_loop_id(ea->fcport);
2098 set_bit(lid, vha->hw->loop_id_map);
2099 ea->fcport->loop_id = lid;
2100 ea->fcport->keep_nport_handle = 0;
2101 qlt_schedule_sess_for_deletion(ea->fcport);
2109 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2112 qlt_logo_completion_handler(fcport, data[0]);
2113 fcport->login_gen++;
2114 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2118 /****************************************************************************/
2119 /* QLogic ISP2x00 Hardware Support Functions. */
2120 /****************************************************************************/
2123 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2125 int rval = QLA_SUCCESS;
2126 struct qla_hw_data *ha = vha->hw;
2127 uint32_t idc_major_ver, idc_minor_ver;
2130 qla83xx_idc_lock(vha, 0);
2132 /* SV: TODO: Assign initialization timeout from
2133 * flash-info / other param
2135 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2136 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2138 /* Set our fcoe function presence */
2139 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2140 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2141 "Error while setting DRV-Presence.\n");
2142 rval = QLA_FUNCTION_FAILED;
2146 /* Decide the reset ownership */
2147 qla83xx_reset_ownership(vha);
2150 * On first protocol driver load:
2151 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2153 * Others: Check compatibility with current IDC Major version.
2155 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2156 if (ha->flags.nic_core_reset_owner) {
2157 /* Set IDC Major version */
2158 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2159 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2161 /* Clearing IDC-Lock-Recovery register */
2162 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2163 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2165 * Clear further IDC participation if we are not compatible with
2166 * the current IDC Major Version.
2168 ql_log(ql_log_warn, vha, 0xb07d,
2169 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2170 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2171 __qla83xx_clear_drv_presence(vha);
2172 rval = QLA_FUNCTION_FAILED;
2175 /* Each function sets its supported Minor version. */
2176 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2177 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2178 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2180 if (ha->flags.nic_core_reset_owner) {
2181 memset(config, 0, sizeof(config));
2182 if (!qla81xx_get_port_config(vha, config))
2183 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2187 rval = qla83xx_idc_state_handler(vha);
2190 qla83xx_idc_unlock(vha, 0);
2196 * qla2x00_initialize_adapter
2200 * ha = adapter block pointer.
2206 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2209 struct qla_hw_data *ha = vha->hw;
2210 struct req_que *req = ha->req_q_map[0];
2211 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2213 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2214 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2216 /* Clear adapter flags. */
2217 vha->flags.online = 0;
2218 ha->flags.chip_reset_done = 0;
2219 vha->flags.reset_active = 0;
2220 ha->flags.pci_channel_io_perm_failure = 0;
2221 ha->flags.eeh_busy = 0;
2222 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2223 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2224 atomic_set(&vha->loop_state, LOOP_DOWN);
2225 vha->device_flags = DFLG_NO_CABLE;
2227 vha->flags.management_server_logged_in = 0;
2228 vha->marker_needed = 0;
2229 ha->isp_abort_cnt = 0;
2230 ha->beacon_blink_led = 0;
2232 set_bit(0, ha->req_qid_map);
2233 set_bit(0, ha->rsp_qid_map);
2235 ql_dbg(ql_dbg_init, vha, 0x0040,
2236 "Configuring PCI space...\n");
2237 rval = ha->isp_ops->pci_config(vha);
2239 ql_log(ql_log_warn, vha, 0x0044,
2240 "Unable to configure PCI space.\n");
2244 ha->isp_ops->reset_chip(vha);
2246 /* Check for secure flash support */
2247 if (IS_QLA28XX(ha)) {
2248 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2249 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2250 ha->flags.secure_adapter = 1;
2255 rval = qla2xxx_get_flash_info(vha);
2257 ql_log(ql_log_fatal, vha, 0x004f,
2258 "Unable to validate FLASH data.\n");
2262 if (IS_QLA8044(ha)) {
2263 qla8044_read_reset_template(vha);
2265 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2266 * If DONRESET_BIT0 is set, drivers should not set dev_state
2267 * to NEED_RESET. But if NEED_RESET is set, drivers should
2268 * should honor the reset. */
2269 if (ql2xdontresethba == 1)
2270 qla8044_set_idc_dontreset(vha);
2273 ha->isp_ops->get_flash_version(vha, req->ring);
2274 ql_dbg(ql_dbg_init, vha, 0x0061,
2275 "Configure NVRAM parameters...\n");
2277 ha->isp_ops->nvram_config(vha);
2279 if (ha->flags.disable_serdes) {
2280 /* Mask HBA via NVRAM settings? */
2281 ql_log(ql_log_info, vha, 0x0077,
2282 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2283 return QLA_FUNCTION_FAILED;
2286 ql_dbg(ql_dbg_init, vha, 0x0078,
2287 "Verifying loaded RISC code...\n");
2289 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2290 rval = ha->isp_ops->chip_diag(vha);
2293 rval = qla2x00_setup_chip(vha);
2298 if (IS_QLA84XX(ha)) {
2299 ha->cs84xx = qla84xx_get_chip(vha);
2301 ql_log(ql_log_warn, vha, 0x00d0,
2302 "Unable to configure ISP84XX.\n");
2303 return QLA_FUNCTION_FAILED;
2307 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2308 rval = qla2x00_init_rings(vha);
2310 ha->flags.chip_reset_done = 1;
2312 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2313 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2314 rval = qla84xx_init_chip(vha);
2315 if (rval != QLA_SUCCESS) {
2316 ql_log(ql_log_warn, vha, 0x00d4,
2317 "Unable to initialize ISP84XX.\n");
2318 qla84xx_put_chip(vha);
2322 /* Load the NIC Core f/w if we are the first protocol driver. */
2323 if (IS_QLA8031(ha)) {
2324 rval = qla83xx_nic_core_fw_load(vha);
2326 ql_log(ql_log_warn, vha, 0x0124,
2327 "Error in initializing NIC Core f/w.\n");
2330 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2331 qla24xx_read_fcp_prio_cfg(vha);
2333 if (IS_P3P_TYPE(ha))
2334 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2336 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2342 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2345 * Returns 0 on success.
2348 qla2100_pci_config(scsi_qla_host_t *vha)
2351 unsigned long flags;
2352 struct qla_hw_data *ha = vha->hw;
2353 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2355 pci_set_master(ha->pdev);
2356 pci_try_set_mwi(ha->pdev);
2358 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2359 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2360 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2362 pci_disable_rom(ha->pdev);
2364 /* Get PCI bus information. */
2365 spin_lock_irqsave(&ha->hardware_lock, flags);
2366 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2367 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2373 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2376 * Returns 0 on success.
2379 qla2300_pci_config(scsi_qla_host_t *vha)
2382 unsigned long flags = 0;
2384 struct qla_hw_data *ha = vha->hw;
2385 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2387 pci_set_master(ha->pdev);
2388 pci_try_set_mwi(ha->pdev);
2390 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2391 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2393 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2394 w &= ~PCI_COMMAND_INTX_DISABLE;
2395 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2398 * If this is a 2300 card and not 2312, reset the
2399 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2400 * the 2310 also reports itself as a 2300 so we need to get the
2401 * fb revision level -- a 6 indicates it really is a 2300 and
2404 if (IS_QLA2300(ha)) {
2405 spin_lock_irqsave(&ha->hardware_lock, flags);
2408 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2409 for (cnt = 0; cnt < 30000; cnt++) {
2410 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2416 /* Select FPM registers. */
2417 WRT_REG_WORD(®->ctrl_status, 0x20);
2418 RD_REG_WORD(®->ctrl_status);
2420 /* Get the fb rev level */
2421 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2423 if (ha->fb_rev == FPM_2300)
2424 pci_clear_mwi(ha->pdev);
2426 /* Deselect FPM registers. */
2427 WRT_REG_WORD(®->ctrl_status, 0x0);
2428 RD_REG_WORD(®->ctrl_status);
2430 /* Release RISC module. */
2431 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2432 for (cnt = 0; cnt < 30000; cnt++) {
2433 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2439 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2442 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2444 pci_disable_rom(ha->pdev);
2446 /* Get PCI bus information. */
2447 spin_lock_irqsave(&ha->hardware_lock, flags);
2448 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2449 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2455 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2458 * Returns 0 on success.
2461 qla24xx_pci_config(scsi_qla_host_t *vha)
2464 unsigned long flags = 0;
2465 struct qla_hw_data *ha = vha->hw;
2466 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2468 pci_set_master(ha->pdev);
2469 pci_try_set_mwi(ha->pdev);
2471 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2472 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2473 w &= ~PCI_COMMAND_INTX_DISABLE;
2474 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2476 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2478 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2479 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2480 pcix_set_mmrbc(ha->pdev, 2048);
2482 /* PCIe -- adjust Maximum Read Request Size (2048). */
2483 if (pci_is_pcie(ha->pdev))
2484 pcie_set_readrq(ha->pdev, 4096);
2486 pci_disable_rom(ha->pdev);
2488 ha->chip_revision = ha->pdev->revision;
2490 /* Get PCI bus information. */
2491 spin_lock_irqsave(&ha->hardware_lock, flags);
2492 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2493 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2499 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2502 * Returns 0 on success.
2505 qla25xx_pci_config(scsi_qla_host_t *vha)
2508 struct qla_hw_data *ha = vha->hw;
2510 pci_set_master(ha->pdev);
2511 pci_try_set_mwi(ha->pdev);
2513 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2514 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2515 w &= ~PCI_COMMAND_INTX_DISABLE;
2516 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2518 /* PCIe -- adjust Maximum Read Request Size (2048). */
2519 if (pci_is_pcie(ha->pdev))
2520 pcie_set_readrq(ha->pdev, 4096);
2522 pci_disable_rom(ha->pdev);
2524 ha->chip_revision = ha->pdev->revision;
2530 * qla2x00_isp_firmware() - Choose firmware image.
2533 * Returns 0 on success.
2536 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2539 uint16_t loop_id, topo, sw_cap;
2540 uint8_t domain, area, al_pa;
2541 struct qla_hw_data *ha = vha->hw;
2543 /* Assume loading risc code */
2544 rval = QLA_FUNCTION_FAILED;
2546 if (ha->flags.disable_risc_code_load) {
2547 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2549 /* Verify checksum of loaded RISC code. */
2550 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2551 if (rval == QLA_SUCCESS) {
2552 /* And, verify we are not in ROM code. */
2553 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2554 &area, &domain, &topo, &sw_cap);
2559 ql_dbg(ql_dbg_init, vha, 0x007a,
2560 "**** Load RISC code ****.\n");
2566 * qla2x00_reset_chip() - Reset ISP chip.
2569 * Returns 0 on success.
2572 qla2x00_reset_chip(scsi_qla_host_t *vha)
2574 unsigned long flags = 0;
2575 struct qla_hw_data *ha = vha->hw;
2576 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2579 int rval = QLA_FUNCTION_FAILED;
2581 if (unlikely(pci_channel_offline(ha->pdev)))
2584 ha->isp_ops->disable_intrs(ha);
2586 spin_lock_irqsave(&ha->hardware_lock, flags);
2588 /* Turn off master enable */
2590 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2591 cmd &= ~PCI_COMMAND_MASTER;
2592 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2594 if (!IS_QLA2100(ha)) {
2596 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2597 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2598 for (cnt = 0; cnt < 30000; cnt++) {
2599 if ((RD_REG_WORD(®->hccr) &
2600 HCCR_RISC_PAUSE) != 0)
2605 RD_REG_WORD(®->hccr); /* PCI Posting. */
2609 /* Select FPM registers. */
2610 WRT_REG_WORD(®->ctrl_status, 0x20);
2611 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2613 /* FPM Soft Reset. */
2614 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2615 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2617 /* Toggle Fpm Reset. */
2618 if (!IS_QLA2200(ha)) {
2619 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2620 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2623 /* Select frame buffer registers. */
2624 WRT_REG_WORD(®->ctrl_status, 0x10);
2625 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2627 /* Reset frame buffer FIFOs. */
2628 if (IS_QLA2200(ha)) {
2629 WRT_FB_CMD_REG(ha, reg, 0xa000);
2630 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2632 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2634 /* Read back fb_cmd until zero or 3 seconds max */
2635 for (cnt = 0; cnt < 3000; cnt++) {
2636 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2642 /* Select RISC module registers. */
2643 WRT_REG_WORD(®->ctrl_status, 0);
2644 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2646 /* Reset RISC processor. */
2647 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2648 RD_REG_WORD(®->hccr); /* PCI Posting. */
2650 /* Release RISC processor. */
2651 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2652 RD_REG_WORD(®->hccr); /* PCI Posting. */
2655 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2656 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2658 /* Reset ISP chip. */
2659 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2661 /* Wait for RISC to recover from reset. */
2662 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2664 * It is necessary to for a delay here since the card doesn't
2665 * respond to PCI reads during a reset. On some architectures
2666 * this will result in an MCA.
2669 for (cnt = 30000; cnt; cnt--) {
2670 if ((RD_REG_WORD(®->ctrl_status) &
2671 CSR_ISP_SOFT_RESET) == 0)
2678 /* Reset RISC processor. */
2679 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2681 WRT_REG_WORD(®->semaphore, 0);
2683 /* Release RISC processor. */
2684 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2685 RD_REG_WORD(®->hccr); /* PCI Posting. */
2687 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2688 for (cnt = 0; cnt < 30000; cnt++) {
2689 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2697 /* Turn on master enable */
2698 cmd |= PCI_COMMAND_MASTER;
2699 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2701 /* Disable RISC pause on FPM parity error. */
2702 if (!IS_QLA2100(ha)) {
2703 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2704 RD_REG_WORD(®->hccr); /* PCI Posting. */
2707 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2713 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2716 * Returns 0 on success.
2719 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2721 uint16_t mb[4] = {0x1010, 0, 1, 0};
2723 if (!IS_QLA81XX(vha->hw))
2726 return qla81xx_write_mpi_register(vha, mb);
2730 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2733 * Returns 0 on success.
2736 qla24xx_reset_risc(scsi_qla_host_t *vha)
2738 unsigned long flags = 0;
2739 struct qla_hw_data *ha = vha->hw;
2740 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2743 static int abts_cnt; /* ISP abort retry counts */
2744 int rval = QLA_SUCCESS;
2746 spin_lock_irqsave(&ha->hardware_lock, flags);
2749 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2750 for (cnt = 0; cnt < 30000; cnt++) {
2751 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2757 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2758 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2760 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2761 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2762 RD_REG_DWORD(®->hccr),
2763 RD_REG_DWORD(®->ctrl_status),
2764 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2766 WRT_REG_DWORD(®->ctrl_status,
2767 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2768 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2772 /* Wait for firmware to complete NVRAM accesses. */
2773 RD_REG_WORD(®->mailbox0);
2774 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2775 rval == QLA_SUCCESS; cnt--) {
2780 rval = QLA_FUNCTION_TIMEOUT;
2783 if (rval == QLA_SUCCESS)
2784 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2786 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2787 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2788 RD_REG_DWORD(®->hccr),
2789 RD_REG_DWORD(®->mailbox0));
2791 /* Wait for soft-reset to complete. */
2792 RD_REG_DWORD(®->ctrl_status);
2793 for (cnt = 0; cnt < 60; cnt++) {
2795 if ((RD_REG_DWORD(®->ctrl_status) &
2796 CSRX_ISP_SOFT_RESET) == 0)
2801 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2802 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2804 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2805 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2806 RD_REG_DWORD(®->hccr),
2807 RD_REG_DWORD(®->ctrl_status));
2809 /* If required, do an MPI FW reset now */
2810 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2811 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2812 if (++abts_cnt < 5) {
2813 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2814 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2817 * We exhausted the ISP abort retries. We have to
2818 * set the board offline.
2821 vha->flags.online = 0;
2826 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2827 RD_REG_DWORD(®->hccr);
2829 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2830 RD_REG_DWORD(®->hccr);
2832 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2833 RD_REG_DWORD(®->hccr);
2835 RD_REG_WORD(®->mailbox0);
2836 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2837 rval == QLA_SUCCESS; cnt--) {
2842 rval = QLA_FUNCTION_TIMEOUT;
2844 if (rval == QLA_SUCCESS)
2845 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2847 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2848 "Host Risc 0x%x, mailbox0 0x%x\n",
2849 RD_REG_DWORD(®->hccr),
2850 RD_REG_WORD(®->mailbox0));
2852 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2854 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2855 "Driver in %s mode\n",
2856 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2858 if (IS_NOPOLLING_TYPE(ha))
2859 ha->isp_ops->enable_intrs(ha);
2865 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2867 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2869 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2870 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2875 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2877 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2879 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2880 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2884 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2887 uint delta_msec = 100;
2888 uint elapsed_msec = 0;
2892 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2893 vha->hw->pdev->subsystem_device != 0x0240)
2896 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2900 timeout_msec = TIMEOUT_SEMAPHORE;
2901 n = timeout_msec / delta_msec;
2903 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2904 qla25xx_read_risc_sema_reg(vha, &wd32);
2905 if (wd32 & RISC_SEMAPHORE)
2908 elapsed_msec += delta_msec;
2909 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2913 if (!(wd32 & RISC_SEMAPHORE))
2916 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2919 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2920 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2921 n = timeout_msec / delta_msec;
2923 qla25xx_read_risc_sema_reg(vha, &wd32);
2924 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2927 elapsed_msec += delta_msec;
2928 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2932 if (wd32 & RISC_SEMAPHORE_FORCE)
2933 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2938 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2945 * qla24xx_reset_chip() - Reset ISP24xx chip.
2948 * Returns 0 on success.
2951 qla24xx_reset_chip(scsi_qla_host_t *vha)
2953 struct qla_hw_data *ha = vha->hw;
2954 int rval = QLA_FUNCTION_FAILED;
2956 if (pci_channel_offline(ha->pdev) &&
2957 ha->flags.pci_channel_io_perm_failure) {
2961 ha->isp_ops->disable_intrs(ha);
2963 qla25xx_manipulate_risc_semaphore(vha);
2965 /* Perform RISC reset. */
2966 rval = qla24xx_reset_risc(vha);
2972 * qla2x00_chip_diag() - Test chip for proper operation.
2975 * Returns 0 on success.
2978 qla2x00_chip_diag(scsi_qla_host_t *vha)
2981 struct qla_hw_data *ha = vha->hw;
2982 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2983 unsigned long flags = 0;
2987 struct req_que *req = ha->req_q_map[0];
2989 /* Assume a failed state */
2990 rval = QLA_FUNCTION_FAILED;
2992 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2993 ®->flash_address);
2995 spin_lock_irqsave(&ha->hardware_lock, flags);
2997 /* Reset ISP chip. */
2998 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
3001 * We need to have a delay here since the card will not respond while
3002 * in reset causing an MCA on some architectures.
3005 data = qla2x00_debounce_register(®->ctrl_status);
3006 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
3008 data = RD_REG_WORD(®->ctrl_status);
3013 goto chip_diag_failed;
3015 ql_dbg(ql_dbg_init, vha, 0x007c,
3016 "Reset register cleared by chip reset.\n");
3018 /* Reset RISC processor. */
3019 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
3020 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
3022 /* Workaround for QLA2312 PCI parity error */
3023 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
3024 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
3025 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
3027 data = RD_MAILBOX_REG(ha, reg, 0);
3034 goto chip_diag_failed;
3036 /* Check product ID of chip */
3037 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3039 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3040 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3041 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3042 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3043 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3044 mb[3] != PROD_ID_3) {
3045 ql_log(ql_log_warn, vha, 0x0062,
3046 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3047 mb[1], mb[2], mb[3]);
3049 goto chip_diag_failed;
3051 ha->product_id[0] = mb[1];
3052 ha->product_id[1] = mb[2];
3053 ha->product_id[2] = mb[3];
3054 ha->product_id[3] = mb[4];
3056 /* Adjust fw RISC transfer size */
3057 if (req->length > 1024)
3058 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3060 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3063 if (IS_QLA2200(ha) &&
3064 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3065 /* Limit firmware transfer size with a 2200A */
3066 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3068 ha->device_type |= DT_ISP2200A;
3069 ha->fw_transfer_size = 128;
3072 /* Wrap Incoming Mailboxes Test. */
3073 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3075 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3076 rval = qla2x00_mbx_reg_test(vha);
3078 ql_log(ql_log_warn, vha, 0x0080,
3079 "Failed mailbox send register test.\n");
3081 /* Flag a successful rval */
3083 spin_lock_irqsave(&ha->hardware_lock, flags);
3087 ql_log(ql_log_info, vha, 0x0081,
3088 "Chip diagnostics **** FAILED ****.\n");
3090 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3096 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3099 * Returns 0 on success.
3102 qla24xx_chip_diag(scsi_qla_host_t *vha)
3105 struct qla_hw_data *ha = vha->hw;
3106 struct req_que *req = ha->req_q_map[0];
3108 if (IS_P3P_TYPE(ha))
3111 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3113 rval = qla2x00_mbx_reg_test(vha);
3115 ql_log(ql_log_warn, vha, 0x0082,
3116 "Failed mailbox send register test.\n");
3118 /* Flag a successful rval */
3126 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3131 struct qla_hw_data *ha = vha->hw;
3134 ql_dbg(ql_dbg_init, vha, 0x00bd,
3135 "%s: Offload Mem is already allocated.\n",
3140 if (IS_FWI2_CAPABLE(ha)) {
3141 /* Allocate memory for Fibre Channel Event Buffer. */
3142 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3143 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3147 dma_free_coherent(&ha->pdev->dev,
3148 FCE_SIZE, ha->fce, ha->fce_dma);
3150 /* Allocate memory for Fibre Channel Event Buffer. */
3151 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3154 ql_log(ql_log_warn, vha, 0x00be,
3155 "Unable to allocate (%d KB) for FCE.\n",
3160 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3161 ha->fce_mb, &ha->fce_bufs);
3163 ql_log(ql_log_warn, vha, 0x00bf,
3164 "Unable to initialize FCE (%d).\n", rval);
3165 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3167 ha->flags.fce_enabled = 0;
3170 ql_dbg(ql_dbg_init, vha, 0x00c0,
3171 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3173 ha->flags.fce_enabled = 1;
3174 ha->fce_dma = tc_dma;
3179 dma_free_coherent(&ha->pdev->dev,
3180 EFT_SIZE, ha->eft, ha->eft_dma);
3182 /* Allocate memory for Extended Trace Buffer. */
3183 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3186 ql_log(ql_log_warn, vha, 0x00c1,
3187 "Unable to allocate (%d KB) for EFT.\n",
3192 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3194 ql_log(ql_log_warn, vha, 0x00c2,
3195 "Unable to initialize EFT (%d).\n", rval);
3196 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3200 ql_dbg(ql_dbg_init, vha, 0x00c3,
3201 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3203 ha->eft_dma = tc_dma;
3212 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;
3224 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3225 req_q_size = rsp_q_size = 0;
3227 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3228 fixed_size = sizeof(struct qla2100_fw_dump);
3229 } else if (IS_QLA23XX(ha)) {
3230 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3231 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3233 } else if (IS_FWI2_CAPABLE(ha)) {
3234 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3235 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3236 else if (IS_QLA81XX(ha))
3237 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3238 else if (IS_QLA25XX(ha))
3239 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3241 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3243 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3246 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3248 mq_size = sizeof(struct qla2xxx_mq_chain);
3250 * Allocate maximum buffer size for all queues - Q0.
3251 * Resizing must be done at end-of-dump processing.
3253 mq_size += (ha->max_req_queues - 1) *
3254 (req->length * sizeof(request_t));
3255 mq_size += (ha->max_rsp_queues - 1) *
3256 (rsp->length * sizeof(response_t));
3258 if (ha->tgt.atio_ring)
3259 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3260 /* Allocate memory for Fibre Channel Event Buffer. */
3261 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3262 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3265 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3268 dma_free_coherent(&ha->pdev->dev,
3269 EFT_SIZE, ha->eft, ha->eft_dma);
3271 /* Allocate memory for Extended Trace Buffer. */
3272 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3275 ql_log(ql_log_warn, vha, 0x00c1,
3276 "Unable to allocate (%d KB) for EFT.\n",
3281 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3283 ql_log(ql_log_warn, vha, 0x00c2,
3284 "Unable to initialize EFT (%d).\n", rval);
3285 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3288 ql_dbg(ql_dbg_init, vha, 0x00c3,
3289 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3290 eft_size = EFT_SIZE;
3293 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3294 struct fwdt *fwdt = ha->fwdt;
3297 for (j = 0; j < 2; j++, fwdt++) {
3298 if (!fwdt->template) {
3299 ql_dbg(ql_dbg_init, vha, 0x00ba,
3300 "-> fwdt%u no template\n", j);
3303 ql_dbg(ql_dbg_init, vha, 0x00fa,
3304 "-> fwdt%u calculating fwdump size...\n", j);
3305 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3306 vha, fwdt->template);
3307 ql_dbg(ql_dbg_init, vha, 0x00fa,
3308 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3309 j, fwdt->dump_size);
3310 dump_size += fwdt->dump_size;
3315 req_q_size = req->length * sizeof(request_t);
3316 rsp_q_size = rsp->length * sizeof(response_t);
3317 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3318 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3319 ha->chain_offset = dump_size;
3320 dump_size += mq_size + fce_size;
3322 if (ha->exchoffld_buf)
3323 dump_size += sizeof(struct qla2xxx_offld_chain) +
3325 if (ha->exlogin_buf)
3326 dump_size += sizeof(struct qla2xxx_offld_chain) +
3330 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3332 ql_dbg(ql_dbg_init, vha, 0x00c5,
3333 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3334 __func__, dump_size, ha->fw_dump_len,
3335 ha->fw_dump_alloc_len);
3337 fw_dump = vmalloc(dump_size);
3339 ql_log(ql_log_warn, vha, 0x00c4,
3340 "Unable to allocate (%d KB) for firmware dump.\n",
3343 mutex_lock(&ha->optrom_mutex);
3344 if (ha->fw_dumped) {
3345 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3347 ha->fw_dump = fw_dump;
3348 ha->fw_dump_alloc_len = dump_size;
3349 ql_dbg(ql_dbg_init, vha, 0x00c5,
3350 "Re-Allocated (%d KB) and save firmware dump.\n",
3355 ha->fw_dump = fw_dump;
3357 ha->fw_dump_len = ha->fw_dump_alloc_len =
3359 ql_dbg(ql_dbg_init, vha, 0x00c5,
3360 "Allocated (%d KB) for firmware dump.\n",
3363 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3364 mutex_unlock(&ha->optrom_mutex);
3368 ha->fw_dump->signature[0] = 'Q';
3369 ha->fw_dump->signature[1] = 'L';
3370 ha->fw_dump->signature[2] = 'G';
3371 ha->fw_dump->signature[3] = 'C';
3372 ha->fw_dump->version = htonl(1);
3374 ha->fw_dump->fixed_size = htonl(fixed_size);
3375 ha->fw_dump->mem_size = htonl(mem_size);
3376 ha->fw_dump->req_q_size = htonl(req_q_size);
3377 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3379 ha->fw_dump->eft_size = htonl(eft_size);
3380 ha->fw_dump->eft_addr_l =
3381 htonl(LSD(ha->eft_dma));
3382 ha->fw_dump->eft_addr_h =
3383 htonl(MSD(ha->eft_dma));
3385 ha->fw_dump->header_size =
3387 (struct qla2xxx_fw_dump, isp));
3389 mutex_unlock(&ha->optrom_mutex);
3395 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3397 #define MPS_MASK 0xe0
3402 if (!IS_QLA81XX(vha->hw))
3405 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3406 if (rval != QLA_SUCCESS) {
3407 ql_log(ql_log_warn, vha, 0x0105,
3408 "Unable to acquire semaphore.\n");
3412 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3413 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3414 if (rval != QLA_SUCCESS) {
3415 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3420 if (dc == (dw & MPS_MASK))
3425 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3426 if (rval != QLA_SUCCESS) {
3427 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3431 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3432 if (rval != QLA_SUCCESS) {
3433 ql_log(ql_log_warn, vha, 0x006d,
3434 "Unable to release semaphore.\n");
3442 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3444 /* Don't try to reallocate the array */
3445 if (req->outstanding_cmds)
3448 if (!IS_FWI2_CAPABLE(ha))
3449 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3451 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3452 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3454 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3457 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3461 if (!req->outstanding_cmds) {
3463 * Try to allocate a minimal size just so we can get through
3466 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3467 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3471 if (!req->outstanding_cmds) {
3472 ql_log(ql_log_fatal, NULL, 0x0126,
3473 "Failed to allocate memory for "
3474 "outstanding_cmds for req_que %p.\n", req);
3475 req->num_outstanding_cmds = 0;
3476 return QLA_FUNCTION_FAILED;
3483 #define PRINT_FIELD(_field, _flag, _str) { \
3484 if (a0->_field & _flag) {\
3490 len = snprintf(ptr, leftover, "%s", _str); \
3497 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3500 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3501 u8 str[STR_LEN], *ptr, p;
3504 memset(str, 0, STR_LEN);
3505 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3506 ql_dbg(ql_dbg_init, vha, 0x015a,
3507 "SFP MFG Name: %s\n", str);
3509 memset(str, 0, STR_LEN);
3510 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3511 ql_dbg(ql_dbg_init, vha, 0x015c,
3512 "SFP Part Name: %s\n", str);
3515 memset(str, 0, STR_LEN);
3519 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3520 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3521 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3522 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3523 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3524 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3525 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3526 ql_dbg(ql_dbg_init, vha, 0x0160,
3527 "SFP Media: %s\n", str);
3530 memset(str, 0, STR_LEN);
3534 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3535 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3536 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3537 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3538 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3539 ql_dbg(ql_dbg_init, vha, 0x0196,
3540 "SFP Link Length: %s\n", str);
3542 memset(str, 0, STR_LEN);
3546 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3547 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3548 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3549 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3550 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3551 ql_dbg(ql_dbg_init, vha, 0x016e,
3552 "SFP FC Link Tech: %s\n", str);
3555 ql_dbg(ql_dbg_init, vha, 0x016f,
3556 "SFP Distant: %d km\n", a0->length_km);
3557 if (a0->length_100m)
3558 ql_dbg(ql_dbg_init, vha, 0x0170,
3559 "SFP Distant: %d m\n", a0->length_100m*100);
3560 if (a0->length_50um_10m)
3561 ql_dbg(ql_dbg_init, vha, 0x0189,
3562 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3563 if (a0->length_62um_10m)
3564 ql_dbg(ql_dbg_init, vha, 0x018a,
3565 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3566 if (a0->length_om4_10m)
3567 ql_dbg(ql_dbg_init, vha, 0x0194,
3568 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3569 if (a0->length_om3_10m)
3570 ql_dbg(ql_dbg_init, vha, 0x0195,
3571 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3577 * QLA_SUCCESS: no action
3578 * QLA_INTERFACE_ERROR: SFP is not there.
3579 * QLA_FUNCTION_FAILED: detected New SFP
3582 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3584 int rc = QLA_SUCCESS;
3585 struct sff_8247_a0 *a;
3586 struct qla_hw_data *ha = vha->hw;
3588 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3591 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3595 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3596 qla2xxx_print_sfp_info(vha);
3598 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3600 ha->flags.detected_lr_sfp = 1;
3602 if (a->length_km > 5 || a->length_100m > 50)
3603 ha->long_range_distance = LR_DISTANCE_10K;
3605 ha->long_range_distance = LR_DISTANCE_5K;
3607 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3608 ql_dbg(ql_dbg_async, vha, 0x507b,
3609 "Detected Long Range SFP.\n");
3612 ha->flags.detected_lr_sfp = 0;
3613 if (ha->flags.using_lr_setting)
3614 ql_dbg(ql_dbg_async, vha, 0x5084,
3615 "Detected Short Range SFP.\n");
3618 if (!vha->flags.init_done)
3625 * qla2x00_setup_chip() - Load and start RISC firmware.
3628 * Returns 0 on success.
3631 qla2x00_setup_chip(scsi_qla_host_t *vha)
3634 uint32_t srisc_address = 0;
3635 struct qla_hw_data *ha = vha->hw;
3636 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3637 unsigned long flags;
3638 uint16_t fw_major_version;
3640 if (IS_P3P_TYPE(ha)) {
3641 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3642 if (rval == QLA_SUCCESS) {
3643 qla2x00_stop_firmware(vha);
3644 goto enable_82xx_npiv;
3649 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3650 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3651 spin_lock_irqsave(&ha->hardware_lock, flags);
3652 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3653 RD_REG_WORD(®->hccr);
3654 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3657 qla81xx_mpi_sync(vha);
3659 /* Load firmware sequences */
3660 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3661 if (rval == QLA_SUCCESS) {
3662 ql_dbg(ql_dbg_init, vha, 0x00c9,
3663 "Verifying Checksum of loaded RISC code.\n");
3665 rval = qla2x00_verify_checksum(vha, srisc_address);
3666 if (rval == QLA_SUCCESS) {
3667 /* Start firmware execution. */
3668 ql_dbg(ql_dbg_init, vha, 0x00ca,
3669 "Starting firmware.\n");
3672 ha->flags.exlogins_enabled = 1;
3674 if (qla_is_exch_offld_enabled(vha))
3675 ha->flags.exchoffld_enabled = 1;
3677 rval = qla2x00_execute_fw(vha, srisc_address);
3678 /* Retrieve firmware information. */
3679 if (rval == QLA_SUCCESS) {
3680 qla24xx_detect_sfp(vha);
3682 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3684 (ha->zio_mode == QLA_ZIO_MODE_6))
3685 qla27xx_set_zio_threshold(vha,
3686 ha->last_zio_threshold);
3688 rval = qla2x00_set_exlogins_buffer(vha);
3689 if (rval != QLA_SUCCESS)
3692 rval = qla2x00_set_exchoffld_buffer(vha);
3693 if (rval != QLA_SUCCESS)
3697 fw_major_version = ha->fw_major_version;
3698 if (IS_P3P_TYPE(ha))
3699 qla82xx_check_md_needed(vha);
3701 rval = qla2x00_get_fw_version(vha);
3702 if (rval != QLA_SUCCESS)
3704 ha->flags.npiv_supported = 0;
3705 if (IS_QLA2XXX_MIDTYPE(ha) &&
3706 (ha->fw_attributes & BIT_2)) {
3707 ha->flags.npiv_supported = 1;
3708 if ((!ha->max_npiv_vports) ||
3709 ((ha->max_npiv_vports + 1) %
3710 MIN_MULTI_ID_FABRIC))
3711 ha->max_npiv_vports =
3712 MIN_MULTI_ID_FABRIC - 1;
3714 qla2x00_get_resource_cnts(vha);
3717 * Allocate the array of outstanding commands
3718 * now that we know the firmware resources.
3720 rval = qla2x00_alloc_outstanding_cmds(ha,
3722 if (rval != QLA_SUCCESS)
3725 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3726 qla2x00_alloc_offload_mem(vha);
3728 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3729 qla2x00_alloc_fw_dump(vha);
3735 ql_log(ql_log_fatal, vha, 0x00cd,
3736 "ISP Firmware failed checksum.\n");
3742 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3743 /* Enable proper parity. */
3744 spin_lock_irqsave(&ha->hardware_lock, flags);
3747 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3749 /* SRAM, Instruction RAM and GP RAM parity */
3750 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3751 RD_REG_WORD(®->hccr);
3752 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3755 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3756 ha->flags.fac_supported = 1;
3757 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3760 rval = qla81xx_fac_get_sector_size(vha, &size);
3761 if (rval == QLA_SUCCESS) {
3762 ha->flags.fac_supported = 1;
3763 ha->fdt_block_size = size << 2;
3765 ql_log(ql_log_warn, vha, 0x00ce,
3766 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3767 ha->fw_major_version, ha->fw_minor_version,
3768 ha->fw_subminor_version);
3770 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3772 ha->flags.fac_supported = 0;
3779 ql_log(ql_log_fatal, vha, 0x00cf,
3780 "Setup chip ****FAILED****.\n");
3787 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3788 * @rsp: response queue
3790 * Beginning of request ring has initialization control block already built
3791 * by nvram config routine.
3793 * Returns 0 on success.
3796 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3801 rsp->ring_ptr = rsp->ring;
3802 rsp->ring_index = 0;
3803 rsp->status_srb = NULL;
3804 pkt = rsp->ring_ptr;
3805 for (cnt = 0; cnt < rsp->length; cnt++) {
3806 pkt->signature = RESPONSE_PROCESSED;
3812 * qla2x00_update_fw_options() - Read and process firmware options.
3815 * Returns 0 on success.
3818 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3820 uint16_t swing, emphasis, tx_sens, rx_sens;
3821 struct qla_hw_data *ha = vha->hw;
3823 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3824 qla2x00_get_fw_options(vha, ha->fw_options);
3826 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3829 /* Serial Link options. */
3830 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3831 "Serial link options.\n");
3832 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3833 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3835 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3836 if (ha->fw_seriallink_options[3] & BIT_2) {
3837 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3840 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3841 emphasis = (ha->fw_seriallink_options[2] &
3842 (BIT_4 | BIT_3)) >> 3;
3843 tx_sens = ha->fw_seriallink_options[0] &
3844 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3845 rx_sens = (ha->fw_seriallink_options[0] &
3846 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3847 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3848 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3851 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3852 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3853 ha->fw_options[10] |= BIT_5 |
3854 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3855 (tx_sens & (BIT_1 | BIT_0));
3858 swing = (ha->fw_seriallink_options[2] &
3859 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3860 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3861 tx_sens = ha->fw_seriallink_options[1] &
3862 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3863 rx_sens = (ha->fw_seriallink_options[1] &
3864 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3865 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3866 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3869 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3870 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3871 ha->fw_options[11] |= BIT_5 |
3872 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3873 (tx_sens & (BIT_1 | BIT_0));
3877 /* Return command IOCBs without waiting for an ABTS to complete. */
3878 ha->fw_options[3] |= BIT_13;
3881 if (ha->flags.enable_led_scheme)
3882 ha->fw_options[2] |= BIT_12;
3884 /* Detect ISP6312. */
3886 ha->fw_options[2] |= BIT_13;
3888 /* Set Retry FLOGI in case of P2P connection */
3889 if (ha->operating_mode == P2P) {
3890 ha->fw_options[2] |= BIT_3;
3891 ql_dbg(ql_dbg_disc, vha, 0x2100,
3892 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3893 __func__, ha->fw_options[2]);
3896 /* Update firmware options. */
3897 qla2x00_set_fw_options(vha, ha->fw_options);
3901 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3904 struct qla_hw_data *ha = vha->hw;
3906 if (IS_P3P_TYPE(ha))
3909 /* Hold status IOCBs until ABTS response received. */
3911 ha->fw_options[3] |= BIT_12;
3913 /* Set Retry FLOGI in case of P2P connection */
3914 if (ha->operating_mode == P2P) {
3915 ha->fw_options[2] |= BIT_3;
3916 ql_dbg(ql_dbg_disc, vha, 0x2101,
3917 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3918 __func__, ha->fw_options[2]);
3921 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3922 if (ql2xmvasynctoatio &&
3923 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3924 if (qla_tgt_mode_enabled(vha) ||
3925 qla_dual_mode_enabled(vha))
3926 ha->fw_options[2] |= BIT_11;
3928 ha->fw_options[2] &= ~BIT_11;
3931 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3934 * Tell FW to track each exchange to prevent
3935 * driver from using stale exchange.
3937 if (qla_tgt_mode_enabled(vha) ||
3938 qla_dual_mode_enabled(vha))
3939 ha->fw_options[2] |= BIT_4;
3941 ha->fw_options[2] &= ~BIT_4;
3943 /* Reserve 1/2 of emergency exchanges for ELS.*/
3944 if (qla2xuseresexchforels)
3945 ha->fw_options[2] |= BIT_8;
3947 ha->fw_options[2] &= ~BIT_8;
3950 ql_dbg(ql_dbg_init, vha, 0x00e8,
3951 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3952 __func__, ha->fw_options[1], ha->fw_options[2],
3953 ha->fw_options[3], vha->host->active_mode);
3955 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3956 qla2x00_set_fw_options(vha, ha->fw_options);
3958 /* Update Serial Link options. */
3959 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3962 rval = qla2x00_set_serdes_params(vha,
3963 le16_to_cpu(ha->fw_seriallink_options24[1]),
3964 le16_to_cpu(ha->fw_seriallink_options24[2]),
3965 le16_to_cpu(ha->fw_seriallink_options24[3]));
3966 if (rval != QLA_SUCCESS) {
3967 ql_log(ql_log_warn, vha, 0x0104,
3968 "Unable to update Serial Link options (%x).\n", rval);
3973 qla2x00_config_rings(struct scsi_qla_host *vha)
3975 struct qla_hw_data *ha = vha->hw;
3976 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3977 struct req_que *req = ha->req_q_map[0];
3978 struct rsp_que *rsp = ha->rsp_q_map[0];
3980 /* Setup ring parameters in initialization control block. */
3981 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3982 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3983 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3984 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3985 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3986 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3988 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3989 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3990 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3991 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3992 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3996 qla24xx_config_rings(struct scsi_qla_host *vha)
3998 struct qla_hw_data *ha = vha->hw;
3999 device_reg_t *reg = ISP_QUE_REG(ha, 0);
4000 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
4001 struct qla_msix_entry *msix;
4002 struct init_cb_24xx *icb;
4004 struct req_que *req = ha->req_q_map[0];
4005 struct rsp_que *rsp = ha->rsp_q_map[0];
4007 /* Setup ring parameters in initialization control block. */
4008 icb = (struct init_cb_24xx *)ha->init_cb;
4009 icb->request_q_outpointer = cpu_to_le16(0);
4010 icb->response_q_inpointer = cpu_to_le16(0);
4011 icb->request_q_length = cpu_to_le16(req->length);
4012 icb->response_q_length = cpu_to_le16(rsp->length);
4013 put_unaligned_le64(req->dma, &icb->request_q_address);
4014 put_unaligned_le64(rsp->dma, &icb->response_q_address);
4016 /* Setup ATIO queue dma pointers for target mode */
4017 icb->atio_q_inpointer = cpu_to_le16(0);
4018 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
4019 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
4021 if (IS_SHADOW_REG_CAPABLE(ha))
4022 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
4024 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
4026 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
4027 icb->rid = cpu_to_le16(rid);
4028 if (ha->flags.msix_enabled) {
4029 msix = &ha->msix_entries[1];
4030 ql_dbg(ql_dbg_init, vha, 0x0019,
4031 "Registering vector 0x%x for base que.\n",
4033 icb->msix = cpu_to_le16(msix->entry);
4035 /* Use alternate PCI bus number */
4037 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4038 /* Use alternate PCI devfn */
4040 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4042 /* Use Disable MSIX Handshake mode for capable adapters */
4043 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4044 (ha->flags.msix_enabled)) {
4045 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4046 ha->flags.disable_msix_handshake = 1;
4047 ql_dbg(ql_dbg_init, vha, 0x00fe,
4048 "MSIX Handshake Disable Mode turned on.\n");
4050 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4052 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4054 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
4055 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
4056 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
4057 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4059 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4060 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4061 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4062 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4065 qlt_24xx_config_rings(vha);
4067 /* If the user has configured the speed, set it here */
4068 if (ha->set_data_rate) {
4069 ql_dbg(ql_dbg_init, vha, 0x00fd,
4070 "Speed set by user : %s Gbps \n",
4071 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4072 icb->firmware_options_3 = (ha->set_data_rate << 13);
4076 RD_REG_DWORD(&ioreg->hccr);
4080 * qla2x00_init_rings() - Initializes firmware.
4083 * Beginning of request ring has initialization control block already built
4084 * by nvram config routine.
4086 * Returns 0 on success.
4089 qla2x00_init_rings(scsi_qla_host_t *vha)
4092 unsigned long flags = 0;
4094 struct qla_hw_data *ha = vha->hw;
4095 struct req_que *req;
4096 struct rsp_que *rsp;
4097 struct mid_init_cb_24xx *mid_init_cb =
4098 (struct mid_init_cb_24xx *) ha->init_cb;
4100 spin_lock_irqsave(&ha->hardware_lock, flags);
4102 /* Clear outstanding commands array. */
4103 for (que = 0; que < ha->max_req_queues; que++) {
4104 req = ha->req_q_map[que];
4105 if (!req || !test_bit(que, ha->req_qid_map))
4107 req->out_ptr = (void *)(req->ring + req->length);
4109 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4110 req->outstanding_cmds[cnt] = NULL;
4112 req->current_outstanding_cmd = 1;
4114 /* Initialize firmware. */
4115 req->ring_ptr = req->ring;
4116 req->ring_index = 0;
4117 req->cnt = req->length;
4120 for (que = 0; que < ha->max_rsp_queues; que++) {
4121 rsp = ha->rsp_q_map[que];
4122 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4124 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4126 /* Initialize response queue entries */
4128 qlafx00_init_response_q_entries(rsp);
4130 qla2x00_init_response_q_entries(rsp);
4133 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4134 ha->tgt.atio_ring_index = 0;
4135 /* Initialize ATIO queue entries */
4136 qlt_init_atio_q_entries(vha);
4138 ha->isp_ops->config_rings(vha);
4140 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4142 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4144 if (IS_QLAFX00(ha)) {
4145 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4149 /* Update any ISP specific firmware options before initialization. */
4150 ha->isp_ops->update_fw_options(vha);
4152 if (ha->flags.npiv_supported) {
4153 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4154 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4155 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4158 if (IS_FWI2_CAPABLE(ha)) {
4159 mid_init_cb->options = cpu_to_le16(BIT_1);
4160 mid_init_cb->init_cb.execution_throttle =
4161 cpu_to_le16(ha->cur_fw_xcb_count);
4162 ha->flags.dport_enabled =
4163 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4164 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4165 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4166 /* FA-WWPN Status */
4167 ha->flags.fawwpn_enabled =
4168 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4169 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4170 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4173 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4176 ql_log(ql_log_fatal, vha, 0x00d2,
4177 "Init Firmware **** FAILED ****.\n");
4179 ql_dbg(ql_dbg_init, vha, 0x00d3,
4180 "Init Firmware -- success.\n");
4182 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4189 * qla2x00_fw_ready() - Waits for firmware ready.
4192 * Returns 0 on success.
4195 qla2x00_fw_ready(scsi_qla_host_t *vha)
4198 unsigned long wtime, mtime, cs84xx_time;
4199 uint16_t min_wait; /* Minimum wait time if loop is down */
4200 uint16_t wait_time; /* Wait time if loop is coming ready */
4202 struct qla_hw_data *ha = vha->hw;
4204 if (IS_QLAFX00(vha->hw))
4205 return qlafx00_fw_ready(vha);
4209 /* Time to wait for loop down */
4210 if (IS_P3P_TYPE(ha))
4216 * Firmware should take at most one RATOV to login, plus 5 seconds for
4217 * our own processing.
4219 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4220 wait_time = min_wait;
4223 /* Min wait time if loop down */
4224 mtime = jiffies + (min_wait * HZ);
4226 /* wait time before firmware ready */
4227 wtime = jiffies + (wait_time * HZ);
4229 /* Wait for ISP to finish LIP */
4230 if (!vha->flags.init_done)
4231 ql_log(ql_log_info, vha, 0x801e,
4232 "Waiting for LIP to complete.\n");
4235 memset(state, -1, sizeof(state));
4236 rval = qla2x00_get_firmware_state(vha, state);
4237 if (rval == QLA_SUCCESS) {
4238 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4239 vha->device_flags &= ~DFLG_NO_CABLE;
4241 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4242 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4243 "fw_state=%x 84xx=%x.\n", state[0],
4245 if ((state[2] & FSTATE_LOGGED_IN) &&
4246 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4247 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4248 "Sending verify iocb.\n");
4250 cs84xx_time = jiffies;
4251 rval = qla84xx_init_chip(vha);
4252 if (rval != QLA_SUCCESS) {
4255 "Init chip failed.\n");
4259 /* Add time taken to initialize. */
4260 cs84xx_time = jiffies - cs84xx_time;
4261 wtime += cs84xx_time;
4262 mtime += cs84xx_time;
4263 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4264 "Increasing wait time by %ld. "
4265 "New time %ld.\n", cs84xx_time,
4268 } else if (state[0] == FSTATE_READY) {
4269 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4270 "F/W Ready - OK.\n");
4272 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4273 &ha->login_timeout, &ha->r_a_tov);
4279 rval = QLA_FUNCTION_FAILED;
4281 if (atomic_read(&vha->loop_down_timer) &&
4282 state[0] != FSTATE_READY) {
4283 /* Loop down. Timeout on min_wait for states
4284 * other than Wait for Login.
4286 if (time_after_eq(jiffies, mtime)) {
4287 ql_log(ql_log_info, vha, 0x8038,
4288 "Cable is unplugged...\n");
4290 vha->device_flags |= DFLG_NO_CABLE;
4295 /* Mailbox cmd failed. Timeout on min_wait. */
4296 if (time_after_eq(jiffies, mtime) ||
4297 ha->flags.isp82xx_fw_hung)
4301 if (time_after_eq(jiffies, wtime))
4304 /* Delay for a while */
4308 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4309 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4310 state[1], state[2], state[3], state[4], state[5], jiffies);
4312 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4313 ql_log(ql_log_warn, vha, 0x803b,
4314 "Firmware ready **** FAILED ****.\n");
4321 * qla2x00_configure_hba
4322 * Setup adapter context.
4325 * ha = adapter state pointer.
4334 qla2x00_configure_hba(scsi_qla_host_t *vha)
4343 char connect_type[22];
4344 struct qla_hw_data *ha = vha->hw;
4345 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4347 unsigned long flags;
4349 /* Get host addresses. */
4350 rval = qla2x00_get_adapter_id(vha,
4351 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4352 if (rval != QLA_SUCCESS) {
4353 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4354 IS_CNA_CAPABLE(ha) ||
4355 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4356 ql_dbg(ql_dbg_disc, vha, 0x2008,
4357 "Loop is in a transition state.\n");
4359 ql_log(ql_log_warn, vha, 0x2009,
4360 "Unable to get host loop ID.\n");
4361 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4362 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4363 ql_log(ql_log_warn, vha, 0x1151,
4364 "Doing link init.\n");
4365 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4368 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4374 ql_log(ql_log_info, vha, 0x200a,
4375 "Cannot get topology - retrying.\n");
4376 return (QLA_FUNCTION_FAILED);
4379 vha->loop_id = loop_id;
4382 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4383 ha->operating_mode = LOOP;
4388 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4389 ha->current_topology = ISP_CFG_NL;
4390 strcpy(connect_type, "(Loop)");
4394 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4395 ha->switch_cap = sw_cap;
4396 ha->current_topology = ISP_CFG_FL;
4397 strcpy(connect_type, "(FL_Port)");
4401 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4402 ha->operating_mode = P2P;
4403 ha->current_topology = ISP_CFG_N;
4404 strcpy(connect_type, "(N_Port-to-N_Port)");
4408 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4409 ha->switch_cap = sw_cap;
4410 ha->operating_mode = P2P;
4411 ha->current_topology = ISP_CFG_F;
4412 strcpy(connect_type, "(F_Port)");
4416 ql_dbg(ql_dbg_disc, vha, 0x200f,
4417 "HBA in unknown topology %x, using NL.\n", topo);
4418 ha->current_topology = ISP_CFG_NL;
4419 strcpy(connect_type, "(Loop)");
4423 /* Save Host port and loop ID. */
4424 /* byte order - Big Endian */
4425 id.b.domain = domain;
4429 spin_lock_irqsave(&ha->hardware_lock, flags);
4430 if (!(topo == 2 && ha->flags.n2n_bigger))
4431 qlt_update_host_map(vha, id);
4432 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4434 if (!vha->flags.init_done)
4435 ql_log(ql_log_info, vha, 0x2010,
4436 "Topology - %s, Host Loop address 0x%x.\n",
4437 connect_type, vha->loop_id);
4443 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4448 uint64_t zero[2] = { 0 };
4449 struct qla_hw_data *ha = vha->hw;
4450 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4451 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4453 if (len > sizeof(zero))
4455 if (memcmp(model, &zero, len) != 0) {
4456 strncpy(ha->model_number, model, len);
4457 st = en = ha->model_number;
4460 if (*en != 0x20 && *en != 0x00)
4465 index = (ha->pdev->subsystem_device & 0xff);
4467 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4468 index < QLA_MODEL_NAMES)
4469 strncpy(ha->model_desc,
4470 qla2x00_model_name[index * 2 + 1],
4471 sizeof(ha->model_desc) - 1);
4473 index = (ha->pdev->subsystem_device & 0xff);
4475 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4476 index < QLA_MODEL_NAMES) {
4477 strcpy(ha->model_number,
4478 qla2x00_model_name[index * 2]);
4479 strncpy(ha->model_desc,
4480 qla2x00_model_name[index * 2 + 1],
4481 sizeof(ha->model_desc) - 1);
4483 strcpy(ha->model_number, def);
4486 if (IS_FWI2_CAPABLE(ha))
4487 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4488 sizeof(ha->model_desc));
4491 /* On sparc systems, obtain port and node WWN from firmware
4494 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4497 struct qla_hw_data *ha = vha->hw;
4498 struct pci_dev *pdev = ha->pdev;
4499 struct device_node *dp = pci_device_to_OF_node(pdev);
4503 val = of_get_property(dp, "port-wwn", &len);
4504 if (val && len >= WWN_SIZE)
4505 memcpy(nv->port_name, val, WWN_SIZE);
4507 val = of_get_property(dp, "node-wwn", &len);
4508 if (val && len >= WWN_SIZE)
4509 memcpy(nv->node_name, val, WWN_SIZE);
4514 * NVRAM configuration for ISP 2xxx
4517 * ha = adapter block pointer.
4520 * initialization control block in response_ring
4521 * host adapters parameters in host adapter block
4527 qla2x00_nvram_config(scsi_qla_host_t *vha)
4532 uint8_t *dptr1, *dptr2;
4533 struct qla_hw_data *ha = vha->hw;
4534 init_cb_t *icb = ha->init_cb;
4535 nvram_t *nv = ha->nvram;
4536 uint8_t *ptr = ha->nvram;
4537 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4541 /* Determine NVRAM starting address. */
4542 ha->nvram_size = sizeof(*nv);
4544 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4545 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4546 ha->nvram_base = 0x80;
4548 /* Get NVRAM data and calculate checksum. */
4549 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4550 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4553 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4554 "Contents of NVRAM.\n");
4555 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4556 nv, ha->nvram_size);
4558 /* Bad NVRAM data, set defaults parameters. */
4559 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4560 nv->nvram_version < 1) {
4561 /* Reset NVRAM data. */
4562 ql_log(ql_log_warn, vha, 0x0064,
4563 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4564 chksum, nv->id, nv->nvram_version);
4565 ql_log(ql_log_warn, vha, 0x0065,
4567 "functioning (yet invalid -- WWPN) defaults.\n");
4570 * Set default initialization control block.
4572 memset(nv, 0, ha->nvram_size);
4573 nv->parameter_block_version = ICB_VERSION;
4575 if (IS_QLA23XX(ha)) {
4576 nv->firmware_options[0] = BIT_2 | BIT_1;
4577 nv->firmware_options[1] = BIT_7 | BIT_5;
4578 nv->add_firmware_options[0] = BIT_5;
4579 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4580 nv->frame_payload_size = 2048;
4581 nv->special_options[1] = BIT_7;
4582 } else if (IS_QLA2200(ha)) {
4583 nv->firmware_options[0] = BIT_2 | BIT_1;
4584 nv->firmware_options[1] = BIT_7 | BIT_5;
4585 nv->add_firmware_options[0] = BIT_5;
4586 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4587 nv->frame_payload_size = 1024;
4588 } else if (IS_QLA2100(ha)) {
4589 nv->firmware_options[0] = BIT_3 | BIT_1;
4590 nv->firmware_options[1] = BIT_5;
4591 nv->frame_payload_size = 1024;
4594 nv->max_iocb_allocation = cpu_to_le16(256);
4595 nv->execution_throttle = cpu_to_le16(16);
4596 nv->retry_count = 8;
4597 nv->retry_delay = 1;
4599 nv->port_name[0] = 33;
4600 nv->port_name[3] = 224;
4601 nv->port_name[4] = 139;
4603 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4605 nv->login_timeout = 4;
4608 * Set default host adapter parameters
4610 nv->host_p[1] = BIT_2;
4611 nv->reset_delay = 5;
4612 nv->port_down_retry_count = 8;
4613 nv->max_luns_per_target = cpu_to_le16(8);
4614 nv->link_down_timeout = 60;
4619 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4621 * The SN2 does not provide BIOS emulation which means you can't change
4622 * potentially bogus BIOS settings. Force the use of default settings
4623 * for link rate and frame size. Hope that the rest of the settings
4626 if (ia64_platform_is("sn2")) {
4627 nv->frame_payload_size = 2048;
4629 nv->special_options[1] = BIT_7;
4633 /* Reset Initialization control block */
4634 memset(icb, 0, ha->init_cb_size);
4637 * Setup driver NVRAM options.
4639 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4640 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4641 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4642 nv->firmware_options[1] &= ~BIT_4;
4644 if (IS_QLA23XX(ha)) {
4645 nv->firmware_options[0] |= BIT_2;
4646 nv->firmware_options[0] &= ~BIT_3;
4647 nv->special_options[0] &= ~BIT_6;
4648 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4650 if (IS_QLA2300(ha)) {
4651 if (ha->fb_rev == FPM_2310) {
4652 strcpy(ha->model_number, "QLA2310");
4654 strcpy(ha->model_number, "QLA2300");
4657 qla2x00_set_model_info(vha, nv->model_number,
4658 sizeof(nv->model_number), "QLA23xx");
4660 } else if (IS_QLA2200(ha)) {
4661 nv->firmware_options[0] |= BIT_2;
4663 * 'Point-to-point preferred, else loop' is not a safe
4664 * connection mode setting.
4666 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4668 /* Force 'loop preferred, else point-to-point'. */
4669 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4670 nv->add_firmware_options[0] |= BIT_5;
4672 strcpy(ha->model_number, "QLA22xx");
4673 } else /*if (IS_QLA2100(ha))*/ {
4674 strcpy(ha->model_number, "QLA2100");
4678 * Copy over NVRAM RISC parameter block to initialization control block.
4680 dptr1 = (uint8_t *)icb;
4681 dptr2 = (uint8_t *)&nv->parameter_block_version;
4682 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4684 *dptr1++ = *dptr2++;
4686 /* Copy 2nd half. */
4687 dptr1 = (uint8_t *)icb->add_firmware_options;
4688 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4690 *dptr1++ = *dptr2++;
4691 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4692 /* Use alternate WWN? */
4693 if (nv->host_p[1] & BIT_7) {
4694 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4695 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4698 /* Prepare nodename */
4699 if ((icb->firmware_options[1] & BIT_6) == 0) {
4701 * Firmware will apply the following mask if the nodename was
4704 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4705 icb->node_name[0] &= 0xF0;
4709 * Set host adapter parameters.
4713 * BIT_7 in the host-parameters section allows for modification to
4714 * internal driver logging.
4716 if (nv->host_p[0] & BIT_7)
4717 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4718 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4719 /* Always load RISC code on non ISP2[12]00 chips. */
4720 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4721 ha->flags.disable_risc_code_load = 0;
4722 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4723 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4724 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4725 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4726 ha->flags.disable_serdes = 0;
4728 ha->operating_mode =
4729 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4731 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4732 sizeof(ha->fw_seriallink_options));
4734 /* save HBA serial number */
4735 ha->serial0 = icb->port_name[5];
4736 ha->serial1 = icb->port_name[6];
4737 ha->serial2 = icb->port_name[7];
4738 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4739 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4741 icb->execution_throttle = cpu_to_le16(0xFFFF);
4743 ha->retry_count = nv->retry_count;
4745 /* Set minimum login_timeout to 4 seconds. */
4746 if (nv->login_timeout != ql2xlogintimeout)
4747 nv->login_timeout = ql2xlogintimeout;
4748 if (nv->login_timeout < 4)
4749 nv->login_timeout = 4;
4750 ha->login_timeout = nv->login_timeout;
4752 /* Set minimum RATOV to 100 tenths of a second. */
4755 ha->loop_reset_delay = nv->reset_delay;
4757 /* Link Down Timeout = 0:
4759 * When Port Down timer expires we will start returning
4760 * I/O's to OS with "DID_NO_CONNECT".
4762 * Link Down Timeout != 0:
4764 * The driver waits for the link to come up after link down
4765 * before returning I/Os to OS with "DID_NO_CONNECT".
4767 if (nv->link_down_timeout == 0) {
4768 ha->loop_down_abort_time =
4769 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4771 ha->link_down_timeout = nv->link_down_timeout;
4772 ha->loop_down_abort_time =
4773 (LOOP_DOWN_TIME - ha->link_down_timeout);
4777 * Need enough time to try and get the port back.
4779 ha->port_down_retry_count = nv->port_down_retry_count;
4780 if (qlport_down_retry)
4781 ha->port_down_retry_count = qlport_down_retry;
4782 /* Set login_retry_count */
4783 ha->login_retry_count = nv->retry_count;
4784 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4785 ha->port_down_retry_count > 3)
4786 ha->login_retry_count = ha->port_down_retry_count;
4787 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4788 ha->login_retry_count = ha->port_down_retry_count;
4789 if (ql2xloginretrycount)
4790 ha->login_retry_count = ql2xloginretrycount;
4792 icb->lun_enables = cpu_to_le16(0);
4793 icb->command_resource_count = 0;
4794 icb->immediate_notify_resource_count = 0;
4795 icb->timeout = cpu_to_le16(0);
4797 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4799 icb->firmware_options[0] &= ~BIT_3;
4800 icb->add_firmware_options[0] &=
4801 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4802 icb->add_firmware_options[0] |= BIT_2;
4803 icb->response_accumulation_timer = 3;
4804 icb->interrupt_delay_timer = 5;
4806 vha->flags.process_response_queue = 1;
4809 if (!vha->flags.init_done) {
4810 ha->zio_mode = icb->add_firmware_options[0] &
4811 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4812 ha->zio_timer = icb->interrupt_delay_timer ?
4813 icb->interrupt_delay_timer : 2;
4815 icb->add_firmware_options[0] &=
4816 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4817 vha->flags.process_response_queue = 0;
4818 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4819 ha->zio_mode = QLA_ZIO_MODE_6;
4821 ql_log(ql_log_info, vha, 0x0068,
4822 "ZIO mode %d enabled; timer delay (%d us).\n",
4823 ha->zio_mode, ha->zio_timer * 100);
4825 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4826 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4827 vha->flags.process_response_queue = 1;
4832 ql_log(ql_log_warn, vha, 0x0069,
4833 "NVRAM configuration failed.\n");
4839 qla2x00_rport_del(void *data)
4841 fc_port_t *fcport = data;
4842 struct fc_rport *rport;
4843 unsigned long flags;
4845 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4846 rport = fcport->drport ? fcport->drport : fcport->rport;
4847 fcport->drport = NULL;
4848 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4850 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4851 "%s %8phN. rport %p roles %x\n",
4852 __func__, fcport->port_name, rport,
4855 fc_remote_port_delete(rport);
4859 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4863 old_state = atomic_read(&fcport->state);
4864 atomic_set(&fcport->state, state);
4866 /* Don't print state transitions during initial allocation of fcport */
4867 if (old_state && old_state != state) {
4868 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4869 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4870 fcport->port_name, port_state_str[old_state],
4871 port_state_str[state], fcport->d_id.b.domain,
4872 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4877 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4879 * @flags: allocation flags
4881 * Returns a pointer to the allocated fcport, or NULL, if none available.
4884 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4888 fcport = kzalloc(sizeof(fc_port_t), flags);
4892 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4893 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4895 if (!fcport->ct_desc.ct_sns) {
4896 ql_log(ql_log_warn, vha, 0xd049,
4897 "Failed to allocate ct_sns request.\n");
4902 /* Setup fcport template structure. */
4904 fcport->port_type = FCT_UNKNOWN;
4905 fcport->loop_id = FC_NO_LOOP_ID;
4906 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4907 fcport->supported_classes = FC_COS_UNSPECIFIED;
4908 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4910 fcport->disc_state = DSC_DELETED;
4911 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4912 fcport->deleted = QLA_SESS_DELETED;
4913 fcport->login_retry = vha->hw->login_retry_count;
4914 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4915 fcport->logout_on_delete = 1;
4917 if (!fcport->ct_desc.ct_sns) {
4918 ql_log(ql_log_warn, vha, 0xd049,
4919 "Failed to allocate ct_sns request.\n");
4924 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4925 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4926 INIT_LIST_HEAD(&fcport->gnl_entry);
4927 INIT_LIST_HEAD(&fcport->list);
4933 qla2x00_free_fcport(fc_port_t *fcport)
4935 if (fcport->ct_desc.ct_sns) {
4936 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4937 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4938 fcport->ct_desc.ct_sns_dma);
4940 fcport->ct_desc.ct_sns = NULL;
4942 list_del(&fcport->list);
4943 qla2x00_clear_loop_id(fcport);
4948 * qla2x00_configure_loop
4949 * Updates Fibre Channel Device Database with what is actually on loop.
4952 * ha = adapter block pointer.
4957 * 2 = database was full and device was not configured.
4960 qla2x00_configure_loop(scsi_qla_host_t *vha)
4963 unsigned long flags, save_flags;
4964 struct qla_hw_data *ha = vha->hw;
4968 /* Get Initiator ID */
4969 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4970 rval = qla2x00_configure_hba(vha);
4971 if (rval != QLA_SUCCESS) {
4972 ql_dbg(ql_dbg_disc, vha, 0x2013,
4973 "Unable to configure HBA.\n");
4978 save_flags = flags = vha->dpc_flags;
4979 ql_dbg(ql_dbg_disc, vha, 0x2014,
4980 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4983 * If we have both an RSCN and PORT UPDATE pending then handle them
4984 * both at the same time.
4986 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4987 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4989 qla2x00_get_data_rate(vha);
4991 /* Determine what we need to do */
4992 if (ha->current_topology == ISP_CFG_FL &&
4993 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4995 set_bit(RSCN_UPDATE, &flags);
4997 } else if (ha->current_topology == ISP_CFG_F &&
4998 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
5000 set_bit(RSCN_UPDATE, &flags);
5001 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5003 } else if (ha->current_topology == ISP_CFG_N) {
5004 clear_bit(RSCN_UPDATE, &flags);
5005 if (qla_tgt_mode_enabled(vha)) {
5006 /* allow the other side to start the login */
5007 clear_bit(LOCAL_LOOP_UPDATE, &flags);
5008 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5010 } else if (ha->current_topology == ISP_CFG_NL) {
5011 clear_bit(RSCN_UPDATE, &flags);
5012 set_bit(LOCAL_LOOP_UPDATE, &flags);
5013 } else if (!vha->flags.online ||
5014 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
5015 set_bit(RSCN_UPDATE, &flags);
5016 set_bit(LOCAL_LOOP_UPDATE, &flags);
5019 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
5020 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5021 ql_dbg(ql_dbg_disc, vha, 0x2015,
5022 "Loop resync needed, failing.\n");
5023 rval = QLA_FUNCTION_FAILED;
5025 rval = qla2x00_configure_local_loop(vha);
5028 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
5029 if (LOOP_TRANSITION(vha)) {
5030 ql_dbg(ql_dbg_disc, vha, 0x2099,
5031 "Needs RSCN update and loop transition.\n");
5032 rval = QLA_FUNCTION_FAILED;
5035 rval = qla2x00_configure_fabric(vha);
5038 if (rval == QLA_SUCCESS) {
5039 if (atomic_read(&vha->loop_down_timer) ||
5040 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5041 rval = QLA_FUNCTION_FAILED;
5043 atomic_set(&vha->loop_state, LOOP_READY);
5044 ql_dbg(ql_dbg_disc, vha, 0x2069,
5046 ha->flags.fw_init_done = 1;
5049 * Process any ATIO queue entries that came in
5050 * while we weren't online.
5052 if (qla_tgt_mode_enabled(vha) ||
5053 qla_dual_mode_enabled(vha)) {
5054 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5055 qlt_24xx_process_atio_queue(vha, 0);
5056 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5063 ql_dbg(ql_dbg_disc, vha, 0x206a,
5064 "%s *** FAILED ***.\n", __func__);
5066 ql_dbg(ql_dbg_disc, vha, 0x206b,
5067 "%s: exiting normally.\n", __func__);
5070 /* Restore state if a resync event occurred during processing */
5071 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5072 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5073 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5074 if (test_bit(RSCN_UPDATE, &save_flags)) {
5075 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5083 * qla2x00_configure_local_loop
5084 * Updates Fibre Channel Device Database with local loop devices.
5087 * ha = adapter block pointer.
5093 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5098 fc_port_t *fcport, *new_fcport;
5104 uint8_t domain, area, al_pa;
5105 struct qla_hw_data *ha = vha->hw;
5106 unsigned long flags;
5108 /* Inititae N2N login. */
5110 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5114 memset(ha->init_cb, 0, ha->init_cb_size);
5115 sz = min_t(int, sizeof(struct els_plogi_payload),
5117 rval = qla24xx_get_port_login_templ(vha,
5118 ha->init_cb_dma, (void *)ha->init_cb, sz);
5119 if (rval == QLA_SUCCESS) {
5120 bp = (uint32_t *)ha->init_cb;
5121 for (i = 0; i < sz/4 ; i++, bp++)
5122 *bp = cpu_to_be32(*bp);
5124 memcpy(&ha->plogi_els_payld.data,
5125 (void *)ha->init_cb,
5126 sizeof(ha->plogi_els_payld.data));
5127 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5129 ql_dbg(ql_dbg_init, vha, 0x00d1,
5130 "PLOGI ELS param read fail.\n");
5135 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5136 if (fcport->n2n_flag) {
5137 qla24xx_fcport_handle_login(vha, fcport);
5142 spin_lock_irqsave(&vha->work_lock, flags);
5143 vha->scan.scan_retry++;
5144 spin_unlock_irqrestore(&vha->work_lock, flags);
5146 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5147 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5148 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5154 entries = MAX_FIBRE_DEVICES_LOOP;
5156 /* Get list of logged in devices. */
5157 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5158 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5160 if (rval != QLA_SUCCESS)
5161 goto cleanup_allocation;
5163 ql_dbg(ql_dbg_disc, vha, 0x2011,
5164 "Entries in ID list (%d).\n", entries);
5165 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5166 ha->gid_list, entries * sizeof(*ha->gid_list));
5169 spin_lock_irqsave(&vha->work_lock, flags);
5170 vha->scan.scan_retry++;
5171 spin_unlock_irqrestore(&vha->work_lock, flags);
5173 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5174 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5175 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5178 vha->scan.scan_retry = 0;
5181 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5182 fcport->scan_state = QLA_FCPORT_SCAN;
5185 /* Allocate temporary fcport for any new fcports discovered. */
5186 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5187 if (new_fcport == NULL) {
5188 ql_log(ql_log_warn, vha, 0x2012,
5189 "Memory allocation failed for fcport.\n");
5190 rval = QLA_MEMORY_ALLOC_FAILED;
5191 goto cleanup_allocation;
5193 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5195 /* Add devices to port list. */
5196 id_iter = (char *)ha->gid_list;
5197 for (index = 0; index < entries; index++) {
5198 domain = ((struct gid_list_info *)id_iter)->domain;
5199 area = ((struct gid_list_info *)id_iter)->area;
5200 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
5201 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5202 loop_id = (uint16_t)
5203 ((struct gid_list_info *)id_iter)->loop_id_2100;
5205 loop_id = le16_to_cpu(
5206 ((struct gid_list_info *)id_iter)->loop_id);
5207 id_iter += ha->gid_list_info_size;
5209 /* Bypass reserved domain fields. */
5210 if ((domain & 0xf0) == 0xf0)
5213 /* Bypass if not same domain and area of adapter. */
5214 if (area && domain && ((area != vha->d_id.b.area) ||
5215 (domain != vha->d_id.b.domain)) &&
5216 (ha->current_topology == ISP_CFG_NL))
5220 /* Bypass invalid local loop ID. */
5221 if (loop_id > LAST_LOCAL_LOOP_ID)
5224 memset(new_fcport->port_name, 0, WWN_SIZE);
5226 /* Fill in member data. */
5227 new_fcport->d_id.b.domain = domain;
5228 new_fcport->d_id.b.area = area;
5229 new_fcport->d_id.b.al_pa = al_pa;
5230 new_fcport->loop_id = loop_id;
5231 new_fcport->scan_state = QLA_FCPORT_FOUND;
5233 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5234 if (rval2 != QLA_SUCCESS) {
5235 ql_dbg(ql_dbg_disc, vha, 0x2097,
5236 "Failed to retrieve fcport information "
5237 "-- get_port_database=%x, loop_id=0x%04x.\n",
5238 rval2, new_fcport->loop_id);
5239 /* Skip retry if N2N */
5240 if (ha->current_topology != ISP_CFG_N) {
5241 ql_dbg(ql_dbg_disc, vha, 0x2105,
5242 "Scheduling resync.\n");
5243 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5248 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5249 /* Check for matching device in port list. */
5252 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5253 if (memcmp(new_fcport->port_name, fcport->port_name,
5257 fcport->flags &= ~FCF_FABRIC_DEVICE;
5258 fcport->loop_id = new_fcport->loop_id;
5259 fcport->port_type = new_fcport->port_type;
5260 fcport->d_id.b24 = new_fcport->d_id.b24;
5261 memcpy(fcport->node_name, new_fcport->node_name,
5263 fcport->scan_state = QLA_FCPORT_FOUND;
5269 /* New device, add to fcports list. */
5270 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5272 /* Allocate a new replacement fcport. */
5273 fcport = new_fcport;
5275 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5277 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5279 if (new_fcport == NULL) {
5280 ql_log(ql_log_warn, vha, 0xd031,
5281 "Failed to allocate memory for fcport.\n");
5282 rval = QLA_MEMORY_ALLOC_FAILED;
5283 goto cleanup_allocation;
5285 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5286 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5289 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5291 /* Base iIDMA settings on HBA port speed. */
5292 fcport->fp_speed = ha->link_data_rate;
5297 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5298 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5301 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5302 if ((qla_dual_mode_enabled(vha) ||
5303 qla_ini_mode_enabled(vha)) &&
5304 atomic_read(&fcport->state) == FCS_ONLINE) {
5305 qla2x00_mark_device_lost(vha, fcport,
5306 ql2xplogiabsentdevice, 0);
5307 if (fcport->loop_id != FC_NO_LOOP_ID &&
5308 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5309 fcport->port_type != FCT_INITIATOR &&
5310 fcport->port_type != FCT_BROADCAST) {
5311 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5312 "%s %d %8phC post del sess\n",
5316 qlt_schedule_sess_for_deletion(fcport);
5322 if (fcport->scan_state == QLA_FCPORT_FOUND)
5323 qla24xx_fcport_handle_login(vha, fcport);
5329 if (rval != QLA_SUCCESS) {
5330 ql_dbg(ql_dbg_disc, vha, 0x2098,
5331 "Configure local loop error exit: rval=%x.\n", rval);
5338 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5341 uint16_t mb[MAILBOX_REGISTER_COUNT];
5342 struct qla_hw_data *ha = vha->hw;
5344 if (!IS_IIDMA_CAPABLE(ha))
5347 if (atomic_read(&fcport->state) != FCS_ONLINE)
5350 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5351 fcport->fp_speed > ha->link_data_rate ||
5352 !ha->flags.gpsc_supported)
5355 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5357 if (rval != QLA_SUCCESS) {
5358 ql_dbg(ql_dbg_disc, vha, 0x2004,
5359 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5360 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5362 ql_dbg(ql_dbg_disc, vha, 0x2005,
5363 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5364 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5365 fcport->fp_speed, fcport->port_name);
5369 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5371 qla2x00_iidma_fcport(vha, fcport);
5372 qla24xx_update_fcport_fcp_prio(vha, fcport);
5375 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5377 struct qla_work_evt *e;
5379 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5381 return QLA_FUNCTION_FAILED;
5383 e->u.fcport.fcport = fcport;
5384 return qla2x00_post_work(vha, e);
5387 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5389 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5391 struct fc_rport_identifiers rport_ids;
5392 struct fc_rport *rport;
5393 unsigned long flags;
5395 if (atomic_read(&fcport->state) == FCS_ONLINE)
5398 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5399 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5400 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5401 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5402 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5403 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5405 ql_log(ql_log_warn, vha, 0x2006,
5406 "Unable to allocate fc remote port.\n");
5410 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5411 *((fc_port_t **)rport->dd_data) = fcport;
5412 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5414 rport->supported_classes = fcport->supported_classes;
5416 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5417 if (fcport->port_type == FCT_INITIATOR)
5418 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5419 if (fcport->port_type == FCT_TARGET)
5420 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5421 if (fcport->port_type & FCT_NVME_INITIATOR)
5422 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5423 if (fcport->port_type & FCT_NVME_TARGET)
5424 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5425 if (fcport->port_type & FCT_NVME_DISCOVERY)
5426 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5428 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5429 "%s %8phN. rport %p is %s mode\n",
5430 __func__, fcport->port_name, rport,
5431 (fcport->port_type == FCT_TARGET) ? "tgt" :
5432 ((fcport->port_type & FCT_NVME) ? "nvme" :"ini"));
5434 fc_remote_port_rolechg(rport, rport_ids.roles);
5438 * qla2x00_update_fcport
5439 * Updates device on list.
5442 * ha = adapter block pointer.
5443 * fcport = port structure pointer.
5453 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5455 if (IS_SW_RESV_ADDR(fcport->d_id))
5458 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5459 __func__, fcport->port_name);
5461 fcport->disc_state = DSC_UPD_FCPORT;
5462 fcport->login_retry = vha->hw->login_retry_count;
5463 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5464 fcport->deleted = 0;
5465 fcport->logout_on_delete = 1;
5466 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5468 switch (vha->hw->current_topology) {
5471 fcport->keep_nport_handle = 1;
5477 qla2x00_iidma_fcport(vha, fcport);
5479 if (fcport->fc4f_nvme) {
5480 qla_nvme_register_remote(vha, fcport);
5481 fcport->disc_state = DSC_LOGIN_COMPLETE;
5482 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5486 qla24xx_update_fcport_fcp_prio(vha, fcport);
5488 switch (vha->host->active_mode) {
5489 case MODE_INITIATOR:
5490 qla2x00_reg_remote_port(vha, fcport);
5493 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5494 !vha->vha_tgt.qla_tgt->tgt_stopped)
5495 qlt_fc_port_added(vha, fcport);
5498 qla2x00_reg_remote_port(vha, fcport);
5499 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5500 !vha->vha_tgt.qla_tgt->tgt_stopped)
5501 qlt_fc_port_added(vha, fcport);
5507 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5509 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5510 if (fcport->id_changed) {
5511 fcport->id_changed = 0;
5512 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5513 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5514 __func__, __LINE__, fcport->port_name,
5516 qla24xx_post_gfpnid_work(vha, fcport);
5518 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5519 "%s %d %8phC post gpsc fcp_cnt %d\n",
5520 __func__, __LINE__, fcport->port_name,
5522 qla24xx_post_gpsc_work(vha, fcport);
5526 fcport->disc_state = DSC_LOGIN_COMPLETE;
5529 void qla_register_fcport_fn(struct work_struct *work)
5531 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5532 u32 rscn_gen = fcport->rscn_gen;
5535 if (IS_SW_RESV_ADDR(fcport->d_id))
5538 qla2x00_update_fcport(fcport->vha, fcport);
5540 if (rscn_gen != fcport->rscn_gen) {
5541 /* RSCN(s) came in while registration */
5542 switch (fcport->next_disc_state) {
5543 case DSC_DELETE_PEND:
5544 qlt_schedule_sess_for_deletion(fcport);
5547 data[0] = data[1] = 0;
5548 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5558 * qla2x00_configure_fabric
5559 * Setup SNS devices with loop ID's.
5562 * ha = adapter block pointer.
5569 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5573 uint16_t mb[MAILBOX_REGISTER_COUNT];
5575 LIST_HEAD(new_fcports);
5576 struct qla_hw_data *ha = vha->hw;
5579 /* If FL port exists, then SNS is present */
5580 if (IS_FWI2_CAPABLE(ha))
5581 loop_id = NPH_F_PORT;
5583 loop_id = SNS_FL_PORT;
5584 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5585 if (rval != QLA_SUCCESS) {
5586 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5587 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5589 vha->device_flags &= ~SWITCH_FOUND;
5590 return (QLA_SUCCESS);
5592 vha->device_flags |= SWITCH_FOUND;
5595 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5596 rval = qla2x00_send_change_request(vha, 0x3, 0);
5597 if (rval != QLA_SUCCESS)
5598 ql_log(ql_log_warn, vha, 0x121,
5599 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5605 qla2x00_mgmt_svr_login(vha);
5608 if (ql2xfdmienable &&
5609 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5610 qla2x00_fdmi_register(vha);
5612 /* Ensure we are logged into the SNS. */
5613 loop_id = NPH_SNS_LID(ha);
5614 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5615 0xfc, mb, BIT_1|BIT_0);
5616 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5617 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5618 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5619 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5620 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5623 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5624 if (qla2x00_rft_id(vha)) {
5626 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5627 "Register FC-4 TYPE failed.\n");
5628 if (test_bit(LOOP_RESYNC_NEEDED,
5632 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5634 ql_dbg(ql_dbg_disc, vha, 0x209a,
5635 "Register FC-4 Features failed.\n");
5636 if (test_bit(LOOP_RESYNC_NEEDED,
5640 if (vha->flags.nvme_enabled) {
5641 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5642 ql_dbg(ql_dbg_disc, vha, 0x2049,
5643 "Register NVME FC Type Features failed.\n");
5646 if (qla2x00_rnn_id(vha)) {
5648 ql_dbg(ql_dbg_disc, vha, 0x2104,
5649 "Register Node Name failed.\n");
5650 if (test_bit(LOOP_RESYNC_NEEDED,
5653 } else if (qla2x00_rsnn_nn(vha)) {
5655 ql_dbg(ql_dbg_disc, vha, 0x209b,
5656 "Register Symbolic Node Name failed.\n");
5657 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5663 /* Mark the time right before querying FW for connected ports.
5664 * This process is long, asynchronous and by the time it's done,
5665 * collected information might not be accurate anymore. E.g.
5666 * disconnected port might have re-connected and a brand new
5667 * session has been created. In this case session's generation
5668 * will be newer than discovery_gen. */
5669 qlt_do_generation_tick(vha, &discovery_gen);
5671 if (USE_ASYNC_SCAN(ha)) {
5672 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5675 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5677 list_for_each_entry(fcport, &vha->vp_fcports, list)
5678 fcport->scan_state = QLA_FCPORT_SCAN;
5680 rval = qla2x00_find_all_fabric_devs(vha);
5682 if (rval != QLA_SUCCESS)
5686 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5687 qla_nvme_register_hba(vha);
5690 ql_dbg(ql_dbg_disc, vha, 0x2068,
5691 "Configure fabric error exit rval=%d.\n", rval);
5697 * qla2x00_find_all_fabric_devs
5700 * ha = adapter block pointer.
5701 * dev = database device entry pointer.
5710 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5714 fc_port_t *fcport, *new_fcport;
5719 int first_dev, last_dev;
5720 port_id_t wrap = {}, nxt_d_id;
5721 struct qla_hw_data *ha = vha->hw;
5722 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5723 unsigned long flags;
5727 /* Try GID_PT to get device list, else GAN. */
5729 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5734 ql_dbg(ql_dbg_disc, vha, 0x209c,
5735 "GID_PT allocations failed, fallback on GA_NXT.\n");
5737 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5738 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5740 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5742 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5744 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5746 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5748 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5750 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5752 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5756 /* If other queries succeeded probe for FC-4 type */
5758 qla2x00_gff_id(vha, swl);
5759 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5765 /* Allocate temporary fcport for any new fcports discovered. */
5766 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5767 if (new_fcport == NULL) {
5768 ql_log(ql_log_warn, vha, 0x209d,
5769 "Failed to allocate memory for fcport.\n");
5770 return (QLA_MEMORY_ALLOC_FAILED);
5772 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5773 /* Set start port ID scan at adapter ID. */
5777 /* Starting free loop ID. */
5778 loop_id = ha->min_external_loopid;
5779 for (; loop_id <= ha->max_loop_id; loop_id++) {
5780 if (qla2x00_is_reserved_id(vha, loop_id))
5783 if (ha->current_topology == ISP_CFG_FL &&
5784 (atomic_read(&vha->loop_down_timer) ||
5785 LOOP_TRANSITION(vha))) {
5786 atomic_set(&vha->loop_down_timer, 0);
5787 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5788 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5794 wrap.b24 = new_fcport->d_id.b24;
5796 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5797 memcpy(new_fcport->node_name,
5798 swl[swl_idx].node_name, WWN_SIZE);
5799 memcpy(new_fcport->port_name,
5800 swl[swl_idx].port_name, WWN_SIZE);
5801 memcpy(new_fcport->fabric_port_name,
5802 swl[swl_idx].fabric_port_name, WWN_SIZE);
5803 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5804 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5806 new_fcport->nvme_flag = 0;
5807 new_fcport->fc4f_nvme = 0;
5808 if (vha->flags.nvme_enabled &&
5809 swl[swl_idx].fc4f_nvme) {
5810 new_fcport->fc4f_nvme =
5811 swl[swl_idx].fc4f_nvme;
5812 ql_log(ql_log_info, vha, 0x2131,
5813 "FOUND: NVME port %8phC as FC Type 28h\n",
5814 new_fcport->port_name);
5817 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5823 /* Send GA_NXT to the switch */
5824 rval = qla2x00_ga_nxt(vha, new_fcport);
5825 if (rval != QLA_SUCCESS) {
5826 ql_log(ql_log_warn, vha, 0x209e,
5827 "SNS scan failed -- assuming "
5828 "zero-entry result.\n");
5834 /* If wrap on switch device list, exit. */
5836 wrap.b24 = new_fcport->d_id.b24;
5838 } else if (new_fcport->d_id.b24 == wrap.b24) {
5839 ql_dbg(ql_dbg_disc, vha, 0x209f,
5840 "Device wrap (%02x%02x%02x).\n",
5841 new_fcport->d_id.b.domain,
5842 new_fcport->d_id.b.area,
5843 new_fcport->d_id.b.al_pa);
5847 /* Bypass if same physical adapter. */
5848 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5851 /* Bypass virtual ports of the same host. */
5852 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5855 /* Bypass if same domain and area of adapter. */
5856 if (((new_fcport->d_id.b24 & 0xffff00) ==
5857 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5861 /* Bypass reserved domain fields. */
5862 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5865 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5866 if (ql2xgffidenable &&
5867 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5868 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5871 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5873 /* Locate matching device in database. */
5875 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5876 if (memcmp(new_fcport->port_name, fcport->port_name,
5880 fcport->scan_state = QLA_FCPORT_FOUND;
5884 /* Update port state. */
5885 memcpy(fcport->fabric_port_name,
5886 new_fcport->fabric_port_name, WWN_SIZE);
5887 fcport->fp_speed = new_fcport->fp_speed;
5890 * If address the same and state FCS_ONLINE
5891 * (or in target mode), nothing changed.
5893 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5894 (atomic_read(&fcport->state) == FCS_ONLINE ||
5895 (vha->host->active_mode == MODE_TARGET))) {
5900 * If device was not a fabric device before.
5902 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5903 fcport->d_id.b24 = new_fcport->d_id.b24;
5904 qla2x00_clear_loop_id(fcport);
5905 fcport->flags |= (FCF_FABRIC_DEVICE |
5911 * Port ID changed or device was marked to be updated;
5912 * Log it out if still logged in and mark it for
5915 if (qla_tgt_mode_enabled(base_vha)) {
5916 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5917 "port changed FC ID, %8phC"
5918 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5920 fcport->d_id.b.domain,
5921 fcport->d_id.b.area,
5922 fcport->d_id.b.al_pa,
5924 new_fcport->d_id.b.domain,
5925 new_fcport->d_id.b.area,
5926 new_fcport->d_id.b.al_pa);
5927 fcport->d_id.b24 = new_fcport->d_id.b24;
5931 fcport->d_id.b24 = new_fcport->d_id.b24;
5932 fcport->flags |= FCF_LOGIN_NEEDED;
5936 if (fcport->fc4f_nvme) {
5937 if (fcport->disc_state == DSC_DELETE_PEND) {
5938 fcport->disc_state = DSC_GNL;
5939 vha->fcport_count--;
5940 fcport->login_succ = 0;
5945 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5948 /* If device was not in our fcports list, then add it. */
5949 new_fcport->scan_state = QLA_FCPORT_FOUND;
5950 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5952 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5955 /* Allocate a new replacement fcport. */
5956 nxt_d_id.b24 = new_fcport->d_id.b24;
5957 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5958 if (new_fcport == NULL) {
5959 ql_log(ql_log_warn, vha, 0xd032,
5960 "Memory allocation failed for fcport.\n");
5961 return (QLA_MEMORY_ALLOC_FAILED);
5963 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5964 new_fcport->d_id.b24 = nxt_d_id.b24;
5967 qla2x00_free_fcport(new_fcport);
5970 * Logout all previous fabric dev marked lost, except FCP2 devices.
5972 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5973 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5976 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5977 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5980 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5981 if ((qla_dual_mode_enabled(vha) ||
5982 qla_ini_mode_enabled(vha)) &&
5983 atomic_read(&fcport->state) == FCS_ONLINE) {
5984 qla2x00_mark_device_lost(vha, fcport,
5985 ql2xplogiabsentdevice, 0);
5986 if (fcport->loop_id != FC_NO_LOOP_ID &&
5987 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5988 fcport->port_type != FCT_INITIATOR &&
5989 fcport->port_type != FCT_BROADCAST) {
5990 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5991 "%s %d %8phC post del sess\n",
5994 qlt_schedule_sess_for_deletion(fcport);
6000 if (fcport->scan_state == QLA_FCPORT_FOUND)
6001 qla24xx_fcport_handle_login(vha, fcport);
6006 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
6008 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
6010 int loop_id = FC_NO_LOOP_ID;
6011 int lid = NPH_MGMT_SERVER - vha->vp_idx;
6012 unsigned long flags;
6013 struct qla_hw_data *ha = vha->hw;
6015 if (vha->vp_idx == 0) {
6016 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
6017 return NPH_MGMT_SERVER;
6020 /* pick id from high and work down to low */
6021 spin_lock_irqsave(&ha->vport_slock, flags);
6022 for (; lid > 0; lid--) {
6023 if (!test_bit(lid, vha->hw->loop_id_map)) {
6024 set_bit(lid, vha->hw->loop_id_map);
6029 spin_unlock_irqrestore(&ha->vport_slock, flags);
6035 * qla2x00_fabric_login
6036 * Issue fabric login command.
6039 * ha = adapter block pointer.
6040 * device = pointer to FC device type structure.
6043 * 0 - Login successfully
6045 * 2 - Initiator device
6049 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
6050 uint16_t *next_loopid)
6054 uint16_t tmp_loopid;
6055 uint16_t mb[MAILBOX_REGISTER_COUNT];
6056 struct qla_hw_data *ha = vha->hw;
6062 ql_dbg(ql_dbg_disc, vha, 0x2000,
6063 "Trying Fabric Login w/loop id 0x%04x for port "
6065 fcport->loop_id, fcport->d_id.b.domain,
6066 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6068 /* Login fcport on switch. */
6069 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6070 fcport->d_id.b.domain, fcport->d_id.b.area,
6071 fcport->d_id.b.al_pa, mb, BIT_0);
6072 if (rval != QLA_SUCCESS) {
6075 if (mb[0] == MBS_PORT_ID_USED) {
6077 * Device has another loop ID. The firmware team
6078 * recommends the driver perform an implicit login with
6079 * the specified ID again. The ID we just used is save
6080 * here so we return with an ID that can be tried by
6084 tmp_loopid = fcport->loop_id;
6085 fcport->loop_id = mb[1];
6087 ql_dbg(ql_dbg_disc, vha, 0x2001,
6088 "Fabric Login: port in use - next loop "
6089 "id=0x%04x, port id= %02x%02x%02x.\n",
6090 fcport->loop_id, fcport->d_id.b.domain,
6091 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6093 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6098 /* A retry occurred before. */
6099 *next_loopid = tmp_loopid;
6102 * No retry occurred before. Just increment the
6103 * ID value for next login.
6105 *next_loopid = (fcport->loop_id + 1);
6108 if (mb[1] & BIT_0) {
6109 fcport->port_type = FCT_INITIATOR;
6111 fcport->port_type = FCT_TARGET;
6112 if (mb[1] & BIT_1) {
6113 fcport->flags |= FCF_FCP2_DEVICE;
6118 fcport->supported_classes |= FC_COS_CLASS2;
6120 fcport->supported_classes |= FC_COS_CLASS3;
6122 if (IS_FWI2_CAPABLE(ha)) {
6125 FCF_CONF_COMP_SUPPORTED;
6130 } else if (mb[0] == MBS_LOOP_ID_USED) {
6132 * Loop ID already used, try next loop ID.
6135 rval = qla2x00_find_new_loop_id(vha, fcport);
6136 if (rval != QLA_SUCCESS) {
6137 /* Ran out of loop IDs to use */
6140 } else if (mb[0] == MBS_COMMAND_ERROR) {
6142 * Firmware possibly timed out during login. If NO
6143 * retries are left to do then the device is declared
6146 *next_loopid = fcport->loop_id;
6147 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6148 fcport->d_id.b.domain, fcport->d_id.b.area,
6149 fcport->d_id.b.al_pa);
6150 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6156 * unrecoverable / not handled error
6158 ql_dbg(ql_dbg_disc, vha, 0x2002,
6159 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6160 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6161 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6162 fcport->loop_id, jiffies);
6164 *next_loopid = fcport->loop_id;
6165 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6166 fcport->d_id.b.domain, fcport->d_id.b.area,
6167 fcport->d_id.b.al_pa);
6168 qla2x00_clear_loop_id(fcport);
6169 fcport->login_retry = 0;
6180 * qla2x00_local_device_login
6181 * Issue local device login command.
6184 * ha = adapter block pointer.
6185 * loop_id = loop id of device to login to.
6187 * Returns (Where's the #define!!!!):
6188 * 0 - Login successfully
6193 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6196 uint16_t mb[MAILBOX_REGISTER_COUNT];
6198 memset(mb, 0, sizeof(mb));
6199 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6200 if (rval == QLA_SUCCESS) {
6201 /* Interrogate mailbox registers for any errors */
6202 if (mb[0] == MBS_COMMAND_ERROR)
6204 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6205 /* device not in PCB table */
6213 * qla2x00_loop_resync
6214 * Resync with fibre channel devices.
6217 * ha = adapter block pointer.
6223 qla2x00_loop_resync(scsi_qla_host_t *vha)
6225 int rval = QLA_SUCCESS;
6228 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6229 if (vha->flags.online) {
6230 if (!(rval = qla2x00_fw_ready(vha))) {
6231 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6234 if (!IS_QLAFX00(vha->hw)) {
6236 * Issue a marker after FW becomes
6239 qla2x00_marker(vha, vha->hw->base_qpair,
6241 vha->marker_needed = 0;
6244 /* Remap devices on Loop. */
6245 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6247 if (IS_QLAFX00(vha->hw))
6248 qlafx00_configure_devices(vha);
6250 qla2x00_configure_loop(vha);
6253 } while (!atomic_read(&vha->loop_down_timer) &&
6254 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6255 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6260 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6261 return (QLA_FUNCTION_FAILED);
6264 ql_dbg(ql_dbg_disc, vha, 0x206c,
6265 "%s *** FAILED ***.\n", __func__);
6271 * qla2x00_perform_loop_resync
6272 * Description: This function will set the appropriate flags and call
6273 * qla2x00_loop_resync. If successful loop will be resynced
6274 * Arguments : scsi_qla_host_t pointer
6275 * returm : Success or Failure
6278 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6282 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6283 /*Configure the flags so that resync happens properly*/
6284 atomic_set(&ha->loop_down_timer, 0);
6285 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6286 atomic_set(&ha->loop_state, LOOP_UP);
6287 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6288 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6289 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6291 rval = qla2x00_loop_resync(ha);
6293 atomic_set(&ha->loop_state, LOOP_DEAD);
6295 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6302 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6305 struct scsi_qla_host *vha;
6306 struct qla_hw_data *ha = base_vha->hw;
6307 unsigned long flags;
6309 spin_lock_irqsave(&ha->vport_slock, flags);
6310 /* Go with deferred removal of rport references. */
6311 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6312 atomic_inc(&vha->vref_count);
6313 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6314 if (fcport->drport &&
6315 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6316 spin_unlock_irqrestore(&ha->vport_slock, flags);
6317 qla2x00_rport_del(fcport);
6319 spin_lock_irqsave(&ha->vport_slock, flags);
6322 atomic_dec(&vha->vref_count);
6323 wake_up(&vha->vref_waitq);
6325 spin_unlock_irqrestore(&ha->vport_slock, flags);
6328 /* Assumes idc_lock always held on entry */
6330 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6332 struct qla_hw_data *ha = vha->hw;
6333 uint32_t drv_presence, drv_presence_mask;
6334 uint32_t dev_part_info1, dev_part_info2, class_type;
6335 uint32_t class_type_mask = 0x3;
6336 uint16_t fcoe_other_function = 0xffff, i;
6338 if (IS_QLA8044(ha)) {
6339 drv_presence = qla8044_rd_direct(vha,
6340 QLA8044_CRB_DRV_ACTIVE_INDEX);
6341 dev_part_info1 = qla8044_rd_direct(vha,
6342 QLA8044_CRB_DEV_PART_INFO_INDEX);
6343 dev_part_info2 = qla8044_rd_direct(vha,
6344 QLA8044_CRB_DEV_PART_INFO2);
6346 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6347 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6348 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6350 for (i = 0; i < 8; i++) {
6351 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6352 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6353 (i != ha->portnum)) {
6354 fcoe_other_function = i;
6358 if (fcoe_other_function == 0xffff) {
6359 for (i = 0; i < 8; i++) {
6360 class_type = ((dev_part_info2 >> (i * 4)) &
6362 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6363 ((i + 8) != ha->portnum)) {
6364 fcoe_other_function = i + 8;
6370 * Prepare drv-presence mask based on fcoe functions present.
6371 * However consider only valid physical fcoe function numbers (0-15).
6373 drv_presence_mask = ~((1 << (ha->portnum)) |
6374 ((fcoe_other_function == 0xffff) ?
6375 0 : (1 << (fcoe_other_function))));
6377 /* We are the reset owner iff:
6378 * - No other protocol drivers present.
6379 * - This is the lowest among fcoe functions. */
6380 if (!(drv_presence & drv_presence_mask) &&
6381 (ha->portnum < fcoe_other_function)) {
6382 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6383 "This host is Reset owner.\n");
6384 ha->flags.nic_core_reset_owner = 1;
6389 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6391 int rval = QLA_SUCCESS;
6392 struct qla_hw_data *ha = vha->hw;
6395 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6396 if (rval == QLA_SUCCESS) {
6397 drv_ack |= (1 << ha->portnum);
6398 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6405 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6407 int rval = QLA_SUCCESS;
6408 struct qla_hw_data *ha = vha->hw;
6411 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6412 if (rval == QLA_SUCCESS) {
6413 drv_ack &= ~(1 << ha->portnum);
6414 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6421 qla83xx_dev_state_to_string(uint32_t dev_state)
6423 switch (dev_state) {
6424 case QLA8XXX_DEV_COLD:
6425 return "COLD/RE-INIT";
6426 case QLA8XXX_DEV_INITIALIZING:
6427 return "INITIALIZING";
6428 case QLA8XXX_DEV_READY:
6430 case QLA8XXX_DEV_NEED_RESET:
6431 return "NEED RESET";
6432 case QLA8XXX_DEV_NEED_QUIESCENT:
6433 return "NEED QUIESCENT";
6434 case QLA8XXX_DEV_FAILED:
6436 case QLA8XXX_DEV_QUIESCENT:
6443 /* Assumes idc-lock always held on entry */
6445 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6447 struct qla_hw_data *ha = vha->hw;
6448 uint32_t idc_audit_reg = 0, duration_secs = 0;
6450 switch (audit_type) {
6451 case IDC_AUDIT_TIMESTAMP:
6452 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6453 idc_audit_reg = (ha->portnum) |
6454 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6455 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6458 case IDC_AUDIT_COMPLETION:
6459 duration_secs = ((jiffies_to_msecs(jiffies) -
6460 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6461 idc_audit_reg = (ha->portnum) |
6462 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6463 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6467 ql_log(ql_log_warn, vha, 0xb078,
6468 "Invalid audit type specified.\n");
6473 /* Assumes idc_lock always held on entry */
6475 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6477 struct qla_hw_data *ha = vha->hw;
6478 uint32_t idc_control, dev_state;
6480 __qla83xx_get_idc_control(vha, &idc_control);
6481 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6482 ql_log(ql_log_info, vha, 0xb080,
6483 "NIC Core reset has been disabled. idc-control=0x%x\n",
6485 return QLA_FUNCTION_FAILED;
6488 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6489 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6490 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6491 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6492 QLA8XXX_DEV_NEED_RESET);
6493 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6494 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6496 const char *state = qla83xx_dev_state_to_string(dev_state);
6498 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6500 /* SV: XXX: Is timeout required here? */
6501 /* Wait for IDC state change READY -> NEED_RESET */
6502 while (dev_state == QLA8XXX_DEV_READY) {
6503 qla83xx_idc_unlock(vha, 0);
6505 qla83xx_idc_lock(vha, 0);
6506 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6510 /* Send IDC ack by writing to drv-ack register */
6511 __qla83xx_set_drv_ack(vha);
6517 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6519 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6523 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6525 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6529 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6531 uint32_t drv_presence = 0;
6532 struct qla_hw_data *ha = vha->hw;
6534 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6535 if (drv_presence & (1 << ha->portnum))
6538 return QLA_TEST_FAILED;
6542 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6544 int rval = QLA_SUCCESS;
6545 struct qla_hw_data *ha = vha->hw;
6547 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6548 "Entered %s().\n", __func__);
6550 if (vha->device_flags & DFLG_DEV_FAILED) {
6551 ql_log(ql_log_warn, vha, 0xb059,
6552 "Device in unrecoverable FAILED state.\n");
6553 return QLA_FUNCTION_FAILED;
6556 qla83xx_idc_lock(vha, 0);
6558 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6559 ql_log(ql_log_warn, vha, 0xb05a,
6560 "Function=0x%x has been removed from IDC participation.\n",
6562 rval = QLA_FUNCTION_FAILED;
6566 qla83xx_reset_ownership(vha);
6568 rval = qla83xx_initiating_reset(vha);
6571 * Perform reset if we are the reset-owner,
6572 * else wait till IDC state changes to READY/FAILED.
6574 if (rval == QLA_SUCCESS) {
6575 rval = qla83xx_idc_state_handler(vha);
6577 if (rval == QLA_SUCCESS)
6578 ha->flags.nic_core_hung = 0;
6579 __qla83xx_clear_drv_ack(vha);
6583 qla83xx_idc_unlock(vha, 0);
6585 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6591 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6593 struct qla_hw_data *ha = vha->hw;
6594 int rval = QLA_FUNCTION_FAILED;
6596 if (!IS_MCTP_CAPABLE(ha)) {
6597 /* This message can be removed from the final version */
6598 ql_log(ql_log_info, vha, 0x506d,
6599 "This board is not MCTP capable\n");
6603 if (!ha->mctp_dump) {
6604 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6605 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6607 if (!ha->mctp_dump) {
6608 ql_log(ql_log_warn, vha, 0x506e,
6609 "Failed to allocate memory for mctp dump\n");
6614 #define MCTP_DUMP_STR_ADDR 0x00000000
6615 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6616 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6617 if (rval != QLA_SUCCESS) {
6618 ql_log(ql_log_warn, vha, 0x506f,
6619 "Failed to capture mctp dump\n");
6621 ql_log(ql_log_info, vha, 0x5070,
6622 "Mctp dump capture for host (%ld/%p).\n",
6623 vha->host_no, ha->mctp_dump);
6624 ha->mctp_dumped = 1;
6627 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6628 ha->flags.nic_core_reset_hdlr_active = 1;
6629 rval = qla83xx_restart_nic_firmware(vha);
6631 /* NIC Core reset failed. */
6632 ql_log(ql_log_warn, vha, 0x5071,
6633 "Failed to restart nic firmware\n");
6635 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6636 "Restarted NIC firmware successfully.\n");
6637 ha->flags.nic_core_reset_hdlr_active = 0;
6645 * qla2x00_quiesce_io
6646 * Description: This function will block the new I/Os
6647 * Its not aborting any I/Os as context
6648 * is not destroyed during quiescence
6649 * Arguments: scsi_qla_host_t
6653 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6655 struct qla_hw_data *ha = vha->hw;
6656 struct scsi_qla_host *vp;
6658 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6659 "Quiescing I/O - ha=%p.\n", ha);
6661 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6662 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6663 atomic_set(&vha->loop_state, LOOP_DOWN);
6664 qla2x00_mark_all_devices_lost(vha, 0);
6665 list_for_each_entry(vp, &ha->vp_list, list)
6666 qla2x00_mark_all_devices_lost(vp, 0);
6668 if (!atomic_read(&vha->loop_down_timer))
6669 atomic_set(&vha->loop_down_timer,
6672 /* Wait for pending cmds to complete */
6673 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6677 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6679 struct qla_hw_data *ha = vha->hw;
6680 struct scsi_qla_host *vp;
6681 unsigned long flags;
6685 /* For ISP82XX, driver waits for completion of the commands.
6686 * online flag should be set.
6688 if (!(IS_P3P_TYPE(ha)))
6689 vha->flags.online = 0;
6690 ha->flags.chip_reset_done = 0;
6691 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6692 vha->qla_stats.total_isp_aborts++;
6694 ql_log(ql_log_info, vha, 0x00af,
6695 "Performing ISP error recovery - ha=%p.\n", ha);
6697 ha->flags.purge_mbox = 1;
6698 /* For ISP82XX, reset_chip is just disabling interrupts.
6699 * Driver waits for the completion of the commands.
6700 * the interrupts need to be enabled.
6702 if (!(IS_P3P_TYPE(ha)))
6703 ha->isp_ops->reset_chip(vha);
6705 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6707 ha->flags.rida_fmt2 = 0;
6708 ha->flags.n2n_ae = 0;
6709 ha->flags.lip_ae = 0;
6710 ha->current_topology = 0;
6711 ha->flags.fw_started = 0;
6712 ha->flags.fw_init_done = 0;
6714 ha->base_qpair->chip_reset = ha->chip_reset;
6715 for (i = 0; i < ha->max_qpairs; i++) {
6716 if (ha->queue_pair_map[i])
6717 ha->queue_pair_map[i]->chip_reset =
6718 ha->base_qpair->chip_reset;
6721 /* purge MBox commands */
6722 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6723 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6724 complete(&ha->mbx_intr_comp);
6728 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6729 atomic_read(&ha->num_pend_mbx_stage2) ||
6730 atomic_read(&ha->num_pend_mbx_stage1)) {
6736 ha->flags.purge_mbox = 0;
6738 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6739 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6740 atomic_set(&vha->loop_state, LOOP_DOWN);
6741 qla2x00_mark_all_devices_lost(vha, 0);
6743 spin_lock_irqsave(&ha->vport_slock, flags);
6744 list_for_each_entry(vp, &ha->vp_list, list) {
6745 atomic_inc(&vp->vref_count);
6746 spin_unlock_irqrestore(&ha->vport_slock, flags);
6748 qla2x00_mark_all_devices_lost(vp, 0);
6750 spin_lock_irqsave(&ha->vport_slock, flags);
6751 atomic_dec(&vp->vref_count);
6753 spin_unlock_irqrestore(&ha->vport_slock, flags);
6755 if (!atomic_read(&vha->loop_down_timer))
6756 atomic_set(&vha->loop_down_timer,
6760 /* Clear all async request states across all VPs. */
6761 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6762 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6763 fcport->scan_state = 0;
6765 spin_lock_irqsave(&ha->vport_slock, flags);
6766 list_for_each_entry(vp, &ha->vp_list, list) {
6767 atomic_inc(&vp->vref_count);
6768 spin_unlock_irqrestore(&ha->vport_slock, flags);
6770 list_for_each_entry(fcport, &vp->vp_fcports, list)
6771 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6773 spin_lock_irqsave(&ha->vport_slock, flags);
6774 atomic_dec(&vp->vref_count);
6776 spin_unlock_irqrestore(&ha->vport_slock, flags);
6778 if (!ha->flags.eeh_busy) {
6779 /* Make sure for ISP 82XX IO DMA is complete */
6780 if (IS_P3P_TYPE(ha)) {
6781 qla82xx_chip_reset_cleanup(vha);
6782 ql_log(ql_log_info, vha, 0x00b4,
6783 "Done chip reset cleanup.\n");
6785 /* Done waiting for pending commands.
6786 * Reset the online flag.
6788 vha->flags.online = 0;
6791 /* Requeue all commands in outstanding command list. */
6792 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6794 /* memory barrier */
6800 * Resets ISP and aborts all outstanding commands.
6803 * ha = adapter block pointer.
6809 qla2x00_abort_isp(scsi_qla_host_t *vha)
6813 struct qla_hw_data *ha = vha->hw;
6814 struct scsi_qla_host *vp;
6815 struct req_que *req = ha->req_q_map[0];
6816 unsigned long flags;
6818 if (vha->flags.online) {
6819 qla2x00_abort_isp_cleanup(vha);
6821 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6822 ha->flags.chip_reset_done = 1;
6823 vha->flags.online = 1;
6825 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6829 if (IS_QLA8031(ha)) {
6830 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6831 "Clearing fcoe driver presence.\n");
6832 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6833 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6834 "Error while clearing DRV-Presence.\n");
6837 if (unlikely(pci_channel_offline(ha->pdev) &&
6838 ha->flags.pci_channel_io_perm_failure)) {
6839 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6844 switch (vha->qlini_mode) {
6845 case QLA2XXX_INI_MODE_DISABLED:
6846 if (!qla_tgt_mode_enabled(vha))
6849 case QLA2XXX_INI_MODE_DUAL:
6850 if (!qla_dual_mode_enabled(vha))
6853 case QLA2XXX_INI_MODE_ENABLED:
6858 ha->isp_ops->get_flash_version(vha, req->ring);
6860 ha->isp_ops->nvram_config(vha);
6862 if (!qla2x00_restart_isp(vha)) {
6863 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6865 if (!atomic_read(&vha->loop_down_timer)) {
6867 * Issue marker command only when we are going
6868 * to start the I/O .
6870 vha->marker_needed = 1;
6873 vha->flags.online = 1;
6875 ha->isp_ops->enable_intrs(ha);
6877 ha->isp_abort_cnt = 0;
6878 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6880 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6881 qla2x00_get_fw_version(vha);
6883 ha->flags.fce_enabled = 1;
6885 fce_calc_size(ha->fce_bufs));
6886 rval = qla2x00_enable_fce_trace(vha,
6887 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6890 ql_log(ql_log_warn, vha, 0x8033,
6891 "Unable to reinitialize FCE "
6893 ha->flags.fce_enabled = 0;
6898 memset(ha->eft, 0, EFT_SIZE);
6899 rval = qla2x00_enable_eft_trace(vha,
6900 ha->eft_dma, EFT_NUM_BUFFERS);
6902 ql_log(ql_log_warn, vha, 0x8034,
6903 "Unable to reinitialize EFT "
6907 } else { /* failed the ISP abort */
6908 vha->flags.online = 1;
6909 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6910 if (ha->isp_abort_cnt == 0) {
6911 ql_log(ql_log_fatal, vha, 0x8035,
6912 "ISP error recover failed - "
6913 "board disabled.\n");
6915 * The next call disables the board
6918 qla2x00_abort_isp_cleanup(vha);
6919 vha->flags.online = 0;
6920 clear_bit(ISP_ABORT_RETRY,
6923 } else { /* schedule another ISP abort */
6924 ha->isp_abort_cnt--;
6925 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6926 "ISP abort - retry remaining %d.\n",
6931 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6932 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6933 "ISP error recovery - retrying (%d) "
6934 "more times.\n", ha->isp_abort_cnt);
6935 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6943 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6944 qla2x00_configure_hba(vha);
6945 spin_lock_irqsave(&ha->vport_slock, flags);
6946 list_for_each_entry(vp, &ha->vp_list, list) {
6948 atomic_inc(&vp->vref_count);
6949 spin_unlock_irqrestore(&ha->vport_slock, flags);
6951 qla2x00_vp_abort_isp(vp);
6953 spin_lock_irqsave(&ha->vport_slock, flags);
6954 atomic_dec(&vp->vref_count);
6957 spin_unlock_irqrestore(&ha->vport_slock, flags);
6959 if (IS_QLA8031(ha)) {
6960 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6961 "Setting back fcoe driver presence.\n");
6962 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6963 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6964 "Error while setting DRV-Presence.\n");
6967 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6975 * qla2x00_restart_isp
6976 * restarts the ISP after a reset
6979 * ha = adapter block pointer.
6985 qla2x00_restart_isp(scsi_qla_host_t *vha)
6988 struct qla_hw_data *ha = vha->hw;
6990 /* If firmware needs to be loaded */
6991 if (qla2x00_isp_firmware(vha)) {
6992 vha->flags.online = 0;
6993 status = ha->isp_ops->chip_diag(vha);
6995 status = qla2x00_setup_chip(vha);
6998 if (!status && !(status = qla2x00_init_rings(vha))) {
6999 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7000 ha->flags.chip_reset_done = 1;
7002 /* Initialize the queues in use */
7003 qla25xx_init_queues(ha);
7005 status = qla2x00_fw_ready(vha);
7007 /* Issue a marker after FW becomes ready. */
7008 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
7009 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7012 /* if no cable then assume it's good */
7013 if ((vha->device_flags & DFLG_NO_CABLE))
7020 qla25xx_init_queues(struct qla_hw_data *ha)
7022 struct rsp_que *rsp = NULL;
7023 struct req_que *req = NULL;
7024 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7028 for (i = 1; i < ha->max_rsp_queues; i++) {
7029 rsp = ha->rsp_q_map[i];
7030 if (rsp && test_bit(i, ha->rsp_qid_map)) {
7031 rsp->options &= ~BIT_0;
7032 ret = qla25xx_init_rsp_que(base_vha, rsp);
7033 if (ret != QLA_SUCCESS)
7034 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
7035 "%s Rsp que: %d init failed.\n",
7038 ql_dbg(ql_dbg_init, base_vha, 0x0100,
7039 "%s Rsp que: %d inited.\n",
7043 for (i = 1; i < ha->max_req_queues; i++) {
7044 req = ha->req_q_map[i];
7045 if (req && test_bit(i, ha->req_qid_map)) {
7046 /* Clear outstanding commands array. */
7047 req->options &= ~BIT_0;
7048 ret = qla25xx_init_req_que(base_vha, req);
7049 if (ret != QLA_SUCCESS)
7050 ql_dbg(ql_dbg_init, base_vha, 0x0101,
7051 "%s Req que: %d init failed.\n",
7054 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7055 "%s Req que: %d inited.\n",
7063 * qla2x00_reset_adapter
7067 * ha = adapter block pointer.
7070 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7072 unsigned long flags = 0;
7073 struct qla_hw_data *ha = vha->hw;
7074 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7076 vha->flags.online = 0;
7077 ha->isp_ops->disable_intrs(ha);
7079 spin_lock_irqsave(&ha->hardware_lock, flags);
7080 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7081 RD_REG_WORD(®->hccr); /* PCI Posting. */
7082 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7083 RD_REG_WORD(®->hccr); /* PCI Posting. */
7084 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7090 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7092 unsigned long flags = 0;
7093 struct qla_hw_data *ha = vha->hw;
7094 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7095 int rval = QLA_SUCCESS;
7097 if (IS_P3P_TYPE(ha))
7100 vha->flags.online = 0;
7101 ha->isp_ops->disable_intrs(ha);
7103 spin_lock_irqsave(&ha->hardware_lock, flags);
7104 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7105 RD_REG_DWORD(®->hccr);
7106 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7107 RD_REG_DWORD(®->hccr);
7108 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7110 if (IS_NOPOLLING_TYPE(ha))
7111 ha->isp_ops->enable_intrs(ha);
7116 /* On sparc systems, obtain port and node WWN from firmware
7119 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7120 struct nvram_24xx *nv)
7123 struct qla_hw_data *ha = vha->hw;
7124 struct pci_dev *pdev = ha->pdev;
7125 struct device_node *dp = pci_device_to_OF_node(pdev);
7129 val = of_get_property(dp, "port-wwn", &len);
7130 if (val && len >= WWN_SIZE)
7131 memcpy(nv->port_name, val, WWN_SIZE);
7133 val = of_get_property(dp, "node-wwn", &len);
7134 if (val && len >= WWN_SIZE)
7135 memcpy(nv->node_name, val, WWN_SIZE);
7140 qla24xx_nvram_config(scsi_qla_host_t *vha)
7143 struct init_cb_24xx *icb;
7144 struct nvram_24xx *nv;
7146 uint8_t *dptr1, *dptr2;
7149 struct qla_hw_data *ha = vha->hw;
7152 icb = (struct init_cb_24xx *)ha->init_cb;
7155 /* Determine NVRAM starting address. */
7156 if (ha->port_no == 0) {
7157 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7158 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7160 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7161 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7164 ha->nvram_size = sizeof(*nv);
7165 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7167 /* Get VPD data into cache */
7168 ha->vpd = ha->nvram + VPD_OFFSET;
7169 ha->isp_ops->read_nvram(vha, ha->vpd,
7170 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7172 /* Get NVRAM data into cache and calculate checksum. */
7173 dptr = (uint32_t *)nv;
7174 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7175 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7176 chksum += le32_to_cpu(*dptr);
7178 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7179 "Contents of NVRAM\n");
7180 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7181 nv, ha->nvram_size);
7183 /* Bad NVRAM data, set defaults parameters. */
7184 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7185 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7186 /* Reset NVRAM data. */
7187 ql_log(ql_log_warn, vha, 0x006b,
7188 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7189 chksum, nv->id, nv->nvram_version);
7190 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7191 ql_log(ql_log_warn, vha, 0x006c,
7192 "Falling back to functioning (yet invalid -- WWPN) "
7196 * Set default initialization control block.
7198 memset(nv, 0, ha->nvram_size);
7199 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7200 nv->version = cpu_to_le16(ICB_VERSION);
7201 nv->frame_payload_size = 2048;
7202 nv->execution_throttle = cpu_to_le16(0xFFFF);
7203 nv->exchange_count = cpu_to_le16(0);
7204 nv->hard_address = cpu_to_le16(124);
7205 nv->port_name[0] = 0x21;
7206 nv->port_name[1] = 0x00 + ha->port_no + 1;
7207 nv->port_name[2] = 0x00;
7208 nv->port_name[3] = 0xe0;
7209 nv->port_name[4] = 0x8b;
7210 nv->port_name[5] = 0x1c;
7211 nv->port_name[6] = 0x55;
7212 nv->port_name[7] = 0x86;
7213 nv->node_name[0] = 0x20;
7214 nv->node_name[1] = 0x00;
7215 nv->node_name[2] = 0x00;
7216 nv->node_name[3] = 0xe0;
7217 nv->node_name[4] = 0x8b;
7218 nv->node_name[5] = 0x1c;
7219 nv->node_name[6] = 0x55;
7220 nv->node_name[7] = 0x86;
7221 qla24xx_nvram_wwn_from_ofw(vha, nv);
7222 nv->login_retry_count = cpu_to_le16(8);
7223 nv->interrupt_delay_timer = cpu_to_le16(0);
7224 nv->login_timeout = cpu_to_le16(0);
7225 nv->firmware_options_1 =
7226 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7227 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7228 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7229 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7230 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7231 nv->efi_parameters = cpu_to_le32(0);
7232 nv->reset_delay = 5;
7233 nv->max_luns_per_target = cpu_to_le16(128);
7234 nv->port_down_retry_count = cpu_to_le16(30);
7235 nv->link_down_timeout = cpu_to_le16(30);
7240 if (qla_tgt_mode_enabled(vha)) {
7241 /* Don't enable full login after initial LIP */
7242 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7243 /* Don't enable LIP full login for initiator */
7244 nv->host_p &= cpu_to_le32(~BIT_10);
7247 qlt_24xx_config_nvram_stage1(vha, nv);
7249 /* Reset Initialization control block */
7250 memset(icb, 0, ha->init_cb_size);
7252 /* Copy 1st segment. */
7253 dptr1 = (uint8_t *)icb;
7254 dptr2 = (uint8_t *)&nv->version;
7255 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7257 *dptr1++ = *dptr2++;
7259 icb->login_retry_count = nv->login_retry_count;
7260 icb->link_down_on_nos = nv->link_down_on_nos;
7262 /* Copy 2nd segment. */
7263 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7264 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7265 cnt = (uint8_t *)&icb->reserved_3 -
7266 (uint8_t *)&icb->interrupt_delay_timer;
7268 *dptr1++ = *dptr2++;
7269 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7271 * Setup driver NVRAM options.
7273 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7276 qlt_24xx_config_nvram_stage2(vha, icb);
7278 if (nv->host_p & cpu_to_le32(BIT_15)) {
7279 /* Use alternate WWN? */
7280 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7281 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7284 /* Prepare nodename */
7285 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7287 * Firmware will apply the following mask if the nodename was
7290 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7291 icb->node_name[0] &= 0xF0;
7294 /* Set host adapter parameters. */
7295 ha->flags.disable_risc_code_load = 0;
7296 ha->flags.enable_lip_reset = 0;
7297 ha->flags.enable_lip_full_login =
7298 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7299 ha->flags.enable_target_reset =
7300 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7301 ha->flags.enable_led_scheme = 0;
7302 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7304 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7305 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7307 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7308 sizeof(ha->fw_seriallink_options24));
7310 /* save HBA serial number */
7311 ha->serial0 = icb->port_name[5];
7312 ha->serial1 = icb->port_name[6];
7313 ha->serial2 = icb->port_name[7];
7314 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7315 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7317 icb->execution_throttle = cpu_to_le16(0xFFFF);
7319 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7321 /* Set minimum login_timeout to 4 seconds. */
7322 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7323 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7324 if (le16_to_cpu(nv->login_timeout) < 4)
7325 nv->login_timeout = cpu_to_le16(4);
7326 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7328 /* Set minimum RATOV to 100 tenths of a second. */
7331 ha->loop_reset_delay = nv->reset_delay;
7333 /* Link Down Timeout = 0:
7335 * When Port Down timer expires we will start returning
7336 * I/O's to OS with "DID_NO_CONNECT".
7338 * Link Down Timeout != 0:
7340 * The driver waits for the link to come up after link down
7341 * before returning I/Os to OS with "DID_NO_CONNECT".
7343 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7344 ha->loop_down_abort_time =
7345 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7347 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7348 ha->loop_down_abort_time =
7349 (LOOP_DOWN_TIME - ha->link_down_timeout);
7352 /* Need enough time to try and get the port back. */
7353 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7354 if (qlport_down_retry)
7355 ha->port_down_retry_count = qlport_down_retry;
7357 /* Set login_retry_count */
7358 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7359 if (ha->port_down_retry_count ==
7360 le16_to_cpu(nv->port_down_retry_count) &&
7361 ha->port_down_retry_count > 3)
7362 ha->login_retry_count = ha->port_down_retry_count;
7363 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7364 ha->login_retry_count = ha->port_down_retry_count;
7365 if (ql2xloginretrycount)
7366 ha->login_retry_count = ql2xloginretrycount;
7368 /* N2N: driver will initiate Login instead of FW */
7369 icb->firmware_options_3 |= BIT_8;
7372 if (!vha->flags.init_done) {
7373 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7374 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7375 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7376 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7378 icb->firmware_options_2 &= cpu_to_le32(
7379 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7380 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7381 ha->zio_mode = QLA_ZIO_MODE_6;
7383 ql_log(ql_log_info, vha, 0x006f,
7384 "ZIO mode %d enabled; timer delay (%d us).\n",
7385 ha->zio_mode, ha->zio_timer * 100);
7387 icb->firmware_options_2 |= cpu_to_le32(
7388 (uint32_t)ha->zio_mode);
7389 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7393 ql_log(ql_log_warn, vha, 0x0070,
7394 "NVRAM configuration failed.\n");
7400 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7401 struct qla27xx_image_status *image_status)
7403 ql_dbg(ql_dbg_init, vha, 0x018b,
7404 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7406 image_status->image_status_mask,
7407 le16_to_cpu(image_status->generation),
7408 image_status->ver_major,
7409 image_status->ver_minor,
7410 image_status->bitmap,
7411 le32_to_cpu(image_status->checksum),
7412 le32_to_cpu(image_status->signature));
7416 qla28xx_check_aux_image_status_signature(
7417 struct qla27xx_image_status *image_status)
7419 ulong signature = le32_to_cpu(image_status->signature);
7421 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7425 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7427 ulong signature = le32_to_cpu(image_status->signature);
7430 signature != QLA27XX_IMG_STATUS_SIGN &&
7431 signature != QLA28XX_IMG_STATUS_SIGN;
7435 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7437 uint32_t *p = (void *)image_status;
7438 uint n = sizeof(*image_status) / sizeof(*p);
7442 sum += le32_to_cpup(p);
7448 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7450 return aux->bitmap & bitmask ?
7451 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7455 qla28xx_component_status(
7456 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7458 active_regions->aux.board_config =
7459 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7461 active_regions->aux.vpd_nvram =
7462 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7464 active_regions->aux.npiv_config_0_1 =
7465 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7467 active_regions->aux.npiv_config_2_3 =
7468 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7472 qla27xx_compare_image_generation(
7473 struct qla27xx_image_status *pri_image_status,
7474 struct qla27xx_image_status *sec_image_status)
7476 /* calculate generation delta as uint16 (this accounts for wrap) */
7478 le16_to_cpu(pri_image_status->generation) -
7479 le16_to_cpu(sec_image_status->generation);
7481 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7487 qla28xx_get_aux_images(
7488 struct scsi_qla_host *vha, struct active_regions *active_regions)
7490 struct qla_hw_data *ha = vha->hw;
7491 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7492 bool valid_pri_image = false, valid_sec_image = false;
7493 bool active_pri_image = false, active_sec_image = false;
7495 if (!ha->flt_region_aux_img_status_pri) {
7496 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7497 goto check_sec_image;
7500 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7501 ha->flt_region_aux_img_status_pri,
7502 sizeof(pri_aux_image_status) >> 2);
7503 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7505 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7506 ql_dbg(ql_dbg_init, vha, 0x018b,
7507 "Primary aux image signature (%#x) not valid\n",
7508 le32_to_cpu(pri_aux_image_status.signature));
7509 goto check_sec_image;
7512 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7513 ql_dbg(ql_dbg_init, vha, 0x018c,
7514 "Primary aux image checksum failed\n");
7515 goto check_sec_image;
7518 valid_pri_image = true;
7520 if (pri_aux_image_status.image_status_mask & 1) {
7521 ql_dbg(ql_dbg_init, vha, 0x018d,
7522 "Primary aux image is active\n");
7523 active_pri_image = true;
7527 if (!ha->flt_region_aux_img_status_sec) {
7528 ql_dbg(ql_dbg_init, vha, 0x018a,
7529 "Secondary aux image not addressed\n");
7530 goto check_valid_image;
7533 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7534 ha->flt_region_aux_img_status_sec,
7535 sizeof(sec_aux_image_status) >> 2);
7536 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7538 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7539 ql_dbg(ql_dbg_init, vha, 0x018b,
7540 "Secondary aux image signature (%#x) not valid\n",
7541 le32_to_cpu(sec_aux_image_status.signature));
7542 goto check_valid_image;
7545 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7546 ql_dbg(ql_dbg_init, vha, 0x018c,
7547 "Secondary aux image checksum failed\n");
7548 goto check_valid_image;
7551 valid_sec_image = true;
7553 if (sec_aux_image_status.image_status_mask & 1) {
7554 ql_dbg(ql_dbg_init, vha, 0x018d,
7555 "Secondary aux image is active\n");
7556 active_sec_image = true;
7560 if (valid_pri_image && active_pri_image &&
7561 valid_sec_image && active_sec_image) {
7562 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7563 &sec_aux_image_status) >= 0) {
7564 qla28xx_component_status(active_regions,
7565 &pri_aux_image_status);
7567 qla28xx_component_status(active_regions,
7568 &sec_aux_image_status);
7570 } else if (valid_pri_image && active_pri_image) {
7571 qla28xx_component_status(active_regions, &pri_aux_image_status);
7572 } else if (valid_sec_image && active_sec_image) {
7573 qla28xx_component_status(active_regions, &sec_aux_image_status);
7576 ql_dbg(ql_dbg_init, vha, 0x018f,
7577 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7578 active_regions->aux.board_config,
7579 active_regions->aux.vpd_nvram,
7580 active_regions->aux.npiv_config_0_1,
7581 active_regions->aux.npiv_config_2_3);
7585 qla27xx_get_active_image(struct scsi_qla_host *vha,
7586 struct active_regions *active_regions)
7588 struct qla_hw_data *ha = vha->hw;
7589 struct qla27xx_image_status pri_image_status, sec_image_status;
7590 bool valid_pri_image = false, valid_sec_image = false;
7591 bool active_pri_image = false, active_sec_image = false;
7593 if (!ha->flt_region_img_status_pri) {
7594 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7595 goto check_sec_image;
7598 qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7599 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2);
7600 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7602 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7603 ql_dbg(ql_dbg_init, vha, 0x018b,
7604 "Primary image signature (%#x) not valid\n",
7605 le32_to_cpu(pri_image_status.signature));
7606 goto check_sec_image;
7609 if (qla27xx_image_status_checksum(&pri_image_status)) {
7610 ql_dbg(ql_dbg_init, vha, 0x018c,
7611 "Primary image checksum failed\n");
7612 goto check_sec_image;
7615 valid_pri_image = true;
7617 if (pri_image_status.image_status_mask & 1) {
7618 ql_dbg(ql_dbg_init, vha, 0x018d,
7619 "Primary image is active\n");
7620 active_pri_image = true;
7624 if (!ha->flt_region_img_status_sec) {
7625 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7626 goto check_valid_image;
7629 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7630 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7631 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7633 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7634 ql_dbg(ql_dbg_init, vha, 0x018b,
7635 "Secondary image signature (%#x) not valid\n",
7636 le32_to_cpu(sec_image_status.signature));
7637 goto check_valid_image;
7640 if (qla27xx_image_status_checksum(&sec_image_status)) {
7641 ql_dbg(ql_dbg_init, vha, 0x018c,
7642 "Secondary image checksum failed\n");
7643 goto check_valid_image;
7646 valid_sec_image = true;
7648 if (sec_image_status.image_status_mask & 1) {
7649 ql_dbg(ql_dbg_init, vha, 0x018d,
7650 "Secondary image is active\n");
7651 active_sec_image = true;
7655 if (valid_pri_image && active_pri_image)
7656 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7658 if (valid_sec_image && active_sec_image) {
7659 if (!active_regions->global ||
7660 qla27xx_compare_image_generation(
7661 &pri_image_status, &sec_image_status) < 0) {
7662 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7666 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7667 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7668 "default (boot/fw)" :
7669 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7671 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7672 "secondary" : "invalid",
7673 active_regions->global);
7676 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7679 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7680 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7684 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7688 uint templates, segments, fragment;
7693 uint32_t risc_addr, risc_size, risc_attr = 0;
7694 struct qla_hw_data *ha = vha->hw;
7695 struct req_que *req = ha->req_q_map[0];
7696 struct fwdt *fwdt = ha->fwdt;
7698 ql_dbg(ql_dbg_init, vha, 0x008b,
7699 "FW: Loading firmware from flash (%x).\n", faddr);
7701 dcode = (void *)req->ring;
7702 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7703 if (qla24xx_risc_firmware_invalid(dcode)) {
7704 ql_log(ql_log_fatal, vha, 0x008c,
7705 "Unable to verify the integrity of flash firmware "
7707 ql_log(ql_log_fatal, vha, 0x008d,
7708 "Firmware data: %08x %08x %08x %08x.\n",
7709 dcode[0], dcode[1], dcode[2], dcode[3]);
7711 return QLA_FUNCTION_FAILED;
7714 dcode = (void *)req->ring;
7716 segments = FA_RISC_CODE_SEGMENTS;
7717 for (j = 0; j < segments; j++) {
7718 ql_dbg(ql_dbg_init, vha, 0x008d,
7719 "-> Loading segment %u...\n", j);
7720 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7721 risc_addr = be32_to_cpu(dcode[2]);
7722 risc_size = be32_to_cpu(dcode[3]);
7724 *srisc_addr = risc_addr;
7725 risc_attr = be32_to_cpu(dcode[9]);
7728 dlen = ha->fw_transfer_size >> 2;
7729 for (fragment = 0; risc_size; fragment++) {
7730 if (dlen > risc_size)
7733 ql_dbg(ql_dbg_init, vha, 0x008e,
7734 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7735 fragment, risc_addr, faddr, dlen);
7736 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7737 for (i = 0; i < dlen; i++)
7738 dcode[i] = swab32(dcode[i]);
7740 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7742 ql_log(ql_log_fatal, vha, 0x008f,
7743 "-> Failed load firmware fragment %u.\n",
7745 return QLA_FUNCTION_FAILED;
7754 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7757 templates = (risc_attr & BIT_9) ? 2 : 1;
7758 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7759 for (j = 0; j < templates; j++, fwdt++) {
7761 vfree(fwdt->template);
7762 fwdt->template = NULL;
7765 dcode = (void *)req->ring;
7766 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7767 risc_size = be32_to_cpu(dcode[2]);
7768 ql_dbg(ql_dbg_init, vha, 0x0161,
7769 "-> fwdt%u template array at %#x (%#x dwords)\n",
7770 j, faddr, risc_size);
7771 if (!risc_size || !~risc_size) {
7772 ql_dbg(ql_dbg_init, vha, 0x0162,
7773 "-> fwdt%u failed to read array\n", j);
7777 /* skip header and ignore checksum */
7781 ql_dbg(ql_dbg_init, vha, 0x0163,
7782 "-> fwdt%u template allocate template %#x words...\n",
7784 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7785 if (!fwdt->template) {
7786 ql_log(ql_log_warn, vha, 0x0164,
7787 "-> fwdt%u failed allocate template.\n", j);
7791 dcode = fwdt->template;
7792 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7794 if (!qla27xx_fwdt_template_valid(dcode)) {
7795 ql_log(ql_log_warn, vha, 0x0165,
7796 "-> fwdt%u failed template validate\n", j);
7800 dlen = qla27xx_fwdt_template_size(dcode);
7801 ql_dbg(ql_dbg_init, vha, 0x0166,
7802 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7803 j, dlen, dlen / sizeof(*dcode));
7804 if (dlen > risc_size * sizeof(*dcode)) {
7805 ql_log(ql_log_warn, vha, 0x0167,
7806 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7807 j, dlen - risc_size * sizeof(*dcode));
7811 fwdt->length = dlen;
7812 ql_dbg(ql_dbg_init, vha, 0x0168,
7813 "-> fwdt%u loaded template ok\n", j);
7815 faddr += risc_size + 1;
7822 vfree(fwdt->template);
7823 fwdt->template = NULL;
7829 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7832 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7836 uint16_t *wcode, *fwcode;
7837 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7838 struct fw_blob *blob;
7839 struct qla_hw_data *ha = vha->hw;
7840 struct req_que *req = ha->req_q_map[0];
7842 /* Load firmware blob. */
7843 blob = qla2x00_request_firmware(vha);
7845 ql_log(ql_log_info, vha, 0x0083,
7846 "Firmware image unavailable.\n");
7847 ql_log(ql_log_info, vha, 0x0084,
7848 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7849 return QLA_FUNCTION_FAILED;
7854 wcode = (uint16_t *)req->ring;
7856 fwcode = (uint16_t *)blob->fw->data;
7859 /* Validate firmware image by checking version. */
7860 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7861 ql_log(ql_log_fatal, vha, 0x0085,
7862 "Unable to verify integrity of firmware image (%zd).\n",
7864 goto fail_fw_integrity;
7866 for (i = 0; i < 4; i++)
7867 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7868 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7869 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7870 wcode[2] == 0 && wcode[3] == 0)) {
7871 ql_log(ql_log_fatal, vha, 0x0086,
7872 "Unable to verify integrity of firmware image.\n");
7873 ql_log(ql_log_fatal, vha, 0x0087,
7874 "Firmware data: %04x %04x %04x %04x.\n",
7875 wcode[0], wcode[1], wcode[2], wcode[3]);
7876 goto fail_fw_integrity;
7880 while (*seg && rval == QLA_SUCCESS) {
7882 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7883 risc_size = be16_to_cpu(fwcode[3]);
7885 /* Validate firmware image size. */
7886 fwclen += risc_size * sizeof(uint16_t);
7887 if (blob->fw->size < fwclen) {
7888 ql_log(ql_log_fatal, vha, 0x0088,
7889 "Unable to verify integrity of firmware image "
7890 "(%zd).\n", blob->fw->size);
7891 goto fail_fw_integrity;
7895 while (risc_size > 0 && rval == QLA_SUCCESS) {
7896 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7897 if (wlen > risc_size)
7899 ql_dbg(ql_dbg_init, vha, 0x0089,
7900 "Loading risc segment@ risc addr %x number of "
7901 "words 0x%x.\n", risc_addr, wlen);
7903 for (i = 0; i < wlen; i++)
7904 wcode[i] = swab16(fwcode[i]);
7906 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7909 ql_log(ql_log_fatal, vha, 0x008a,
7910 "Failed to load segment %d of firmware.\n",
7927 return QLA_FUNCTION_FAILED;
7931 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7934 uint templates, segments, fragment;
7937 uint32_t risc_addr, risc_size, risc_attr = 0;
7940 struct fw_blob *blob;
7942 struct qla_hw_data *ha = vha->hw;
7943 struct req_que *req = ha->req_q_map[0];
7944 struct fwdt *fwdt = ha->fwdt;
7946 ql_dbg(ql_dbg_init, vha, 0x0090,
7947 "-> FW: Loading via request-firmware.\n");
7949 blob = qla2x00_request_firmware(vha);
7951 ql_log(ql_log_warn, vha, 0x0092,
7952 "-> Firmware file not found.\n");
7954 return QLA_FUNCTION_FAILED;
7957 fwcode = (void *)blob->fw->data;
7959 if (qla24xx_risc_firmware_invalid(dcode)) {
7960 ql_log(ql_log_fatal, vha, 0x0093,
7961 "Unable to verify integrity of firmware image (%zd).\n",
7963 ql_log(ql_log_fatal, vha, 0x0095,
7964 "Firmware data: %08x %08x %08x %08x.\n",
7965 dcode[0], dcode[1], dcode[2], dcode[3]);
7966 return QLA_FUNCTION_FAILED;
7969 dcode = (void *)req->ring;
7971 segments = FA_RISC_CODE_SEGMENTS;
7972 for (j = 0; j < segments; j++) {
7973 ql_dbg(ql_dbg_init, vha, 0x0096,
7974 "-> Loading segment %u...\n", j);
7975 risc_addr = be32_to_cpu(fwcode[2]);
7976 risc_size = be32_to_cpu(fwcode[3]);
7979 *srisc_addr = risc_addr;
7980 risc_attr = be32_to_cpu(fwcode[9]);
7983 dlen = ha->fw_transfer_size >> 2;
7984 for (fragment = 0; risc_size; fragment++) {
7985 if (dlen > risc_size)
7988 ql_dbg(ql_dbg_init, vha, 0x0097,
7989 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7990 fragment, risc_addr,
7991 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7994 for (i = 0; i < dlen; i++)
7995 dcode[i] = swab32(fwcode[i]);
7997 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7999 ql_log(ql_log_fatal, vha, 0x0098,
8000 "-> Failed load firmware fragment %u.\n",
8002 return QLA_FUNCTION_FAILED;
8011 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8014 templates = (risc_attr & BIT_9) ? 2 : 1;
8015 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
8016 for (j = 0; j < templates; j++, fwdt++) {
8018 vfree(fwdt->template);
8019 fwdt->template = NULL;
8022 risc_size = be32_to_cpu(fwcode[2]);
8023 ql_dbg(ql_dbg_init, vha, 0x0171,
8024 "-> fwdt%u template array at %#x (%#x dwords)\n",
8025 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
8027 if (!risc_size || !~risc_size) {
8028 ql_dbg(ql_dbg_init, vha, 0x0172,
8029 "-> fwdt%u failed to read array\n", j);
8033 /* skip header and ignore checksum */
8037 ql_dbg(ql_dbg_init, vha, 0x0173,
8038 "-> fwdt%u template allocate template %#x words...\n",
8040 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
8041 if (!fwdt->template) {
8042 ql_log(ql_log_warn, vha, 0x0174,
8043 "-> fwdt%u failed allocate template.\n", j);
8047 dcode = fwdt->template;
8048 for (i = 0; i < risc_size; i++)
8049 dcode[i] = fwcode[i];
8051 if (!qla27xx_fwdt_template_valid(dcode)) {
8052 ql_log(ql_log_warn, vha, 0x0175,
8053 "-> fwdt%u failed template validate\n", j);
8057 dlen = qla27xx_fwdt_template_size(dcode);
8058 ql_dbg(ql_dbg_init, vha, 0x0176,
8059 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8060 j, dlen, dlen / sizeof(*dcode));
8061 if (dlen > risc_size * sizeof(*dcode)) {
8062 ql_log(ql_log_warn, vha, 0x0177,
8063 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8064 j, dlen - risc_size * sizeof(*dcode));
8068 fwdt->length = dlen;
8069 ql_dbg(ql_dbg_init, vha, 0x0178,
8070 "-> fwdt%u loaded template ok\n", j);
8072 fwcode += risc_size + 1;
8079 vfree(fwdt->template);
8080 fwdt->template = NULL;
8087 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8091 if (ql2xfwloadbin == 1)
8092 return qla81xx_load_risc(vha, srisc_addr);
8096 * 1) Firmware via request-firmware interface (.bin file).
8097 * 2) Firmware residing in flash.
8099 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8100 if (rval == QLA_SUCCESS)
8103 return qla24xx_load_risc_flash(vha, srisc_addr,
8104 vha->hw->flt_region_fw);
8108 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8111 struct qla_hw_data *ha = vha->hw;
8112 struct active_regions active_regions = { };
8114 if (ql2xfwloadbin == 2)
8117 /* FW Load priority:
8118 * 1) Firmware residing in flash.
8119 * 2) Firmware via request-firmware interface (.bin file).
8120 * 3) Golden-Firmware residing in flash -- (limited operation).
8123 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8124 goto try_primary_fw;
8126 qla27xx_get_active_image(vha, &active_regions);
8128 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8129 goto try_primary_fw;
8131 ql_dbg(ql_dbg_init, vha, 0x008b,
8132 "Loading secondary firmware image.\n");
8133 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8138 ql_dbg(ql_dbg_init, vha, 0x008b,
8139 "Loading primary firmware image.\n");
8140 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8145 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8146 if (!rval || !ha->flt_region_gold_fw)
8149 ql_log(ql_log_info, vha, 0x0099,
8150 "Attempting to fallback to golden firmware.\n");
8151 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8155 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8156 ha->flags.running_gold_fw = 1;
8161 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8164 struct qla_hw_data *ha = vha->hw;
8166 if (ha->flags.pci_channel_io_perm_failure)
8168 if (!IS_FWI2_CAPABLE(ha))
8170 if (!ha->fw_major_version)
8172 if (!ha->flags.fw_started)
8175 ret = qla2x00_stop_firmware(vha);
8176 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8177 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8178 ha->isp_ops->reset_chip(vha);
8179 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8181 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8183 ql_log(ql_log_info, vha, 0x8015,
8184 "Attempting retry of stop-firmware command.\n");
8185 ret = qla2x00_stop_firmware(vha);
8189 ha->flags.fw_init_done = 0;
8193 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8195 int rval = QLA_SUCCESS;
8197 uint16_t mb[MAILBOX_REGISTER_COUNT];
8198 struct qla_hw_data *ha = vha->hw;
8199 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8204 rval = qla2x00_fw_ready(base_vha);
8206 if (rval == QLA_SUCCESS) {
8207 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8208 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8211 vha->flags.management_server_logged_in = 0;
8213 /* Login to SNS first */
8214 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8216 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8217 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8218 ql_dbg(ql_dbg_init, vha, 0x0120,
8219 "Failed SNS login: loop_id=%x, rval2=%d\n",
8222 ql_dbg(ql_dbg_init, vha, 0x0103,
8223 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8224 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8225 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8226 return (QLA_FUNCTION_FAILED);
8229 atomic_set(&vha->loop_down_timer, 0);
8230 atomic_set(&vha->loop_state, LOOP_UP);
8231 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8232 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8233 rval = qla2x00_loop_resync(base_vha);
8238 /* 84XX Support **************************************************************/
8240 static LIST_HEAD(qla_cs84xx_list);
8241 static DEFINE_MUTEX(qla_cs84xx_mutex);
8243 static struct qla_chip_state_84xx *
8244 qla84xx_get_chip(struct scsi_qla_host *vha)
8246 struct qla_chip_state_84xx *cs84xx;
8247 struct qla_hw_data *ha = vha->hw;
8249 mutex_lock(&qla_cs84xx_mutex);
8251 /* Find any shared 84xx chip. */
8252 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8253 if (cs84xx->bus == ha->pdev->bus) {
8254 kref_get(&cs84xx->kref);
8259 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8263 kref_init(&cs84xx->kref);
8264 spin_lock_init(&cs84xx->access_lock);
8265 mutex_init(&cs84xx->fw_update_mutex);
8266 cs84xx->bus = ha->pdev->bus;
8268 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8270 mutex_unlock(&qla_cs84xx_mutex);
8275 __qla84xx_chip_release(struct kref *kref)
8277 struct qla_chip_state_84xx *cs84xx =
8278 container_of(kref, struct qla_chip_state_84xx, kref);
8280 mutex_lock(&qla_cs84xx_mutex);
8281 list_del(&cs84xx->list);
8282 mutex_unlock(&qla_cs84xx_mutex);
8287 qla84xx_put_chip(struct scsi_qla_host *vha)
8289 struct qla_hw_data *ha = vha->hw;
8292 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8296 qla84xx_init_chip(scsi_qla_host_t *vha)
8300 struct qla_hw_data *ha = vha->hw;
8302 mutex_lock(&ha->cs84xx->fw_update_mutex);
8304 rval = qla84xx_verify_chip(vha, status);
8306 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8308 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8312 /* 81XX Support **************************************************************/
8315 qla81xx_nvram_config(scsi_qla_host_t *vha)
8318 struct init_cb_81xx *icb;
8319 struct nvram_81xx *nv;
8321 uint8_t *dptr1, *dptr2;
8324 struct qla_hw_data *ha = vha->hw;
8326 struct active_regions active_regions = { };
8329 icb = (struct init_cb_81xx *)ha->init_cb;
8332 /* Determine NVRAM starting address. */
8333 ha->nvram_size = sizeof(*nv);
8334 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8335 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8336 ha->vpd_size = FA_VPD_SIZE_82XX;
8338 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8339 qla28xx_get_aux_images(vha, &active_regions);
8341 /* Get VPD data into cache */
8342 ha->vpd = ha->nvram + VPD_OFFSET;
8344 faddr = ha->flt_region_vpd;
8345 if (IS_QLA28XX(ha)) {
8346 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8347 faddr = ha->flt_region_vpd_sec;
8348 ql_dbg(ql_dbg_init, vha, 0x0110,
8349 "Loading %s nvram image.\n",
8350 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8351 "primary" : "secondary");
8353 qla24xx_read_flash_data(vha, ha->vpd, faddr, ha->vpd_size >> 2);
8355 /* Get NVRAM data into cache and calculate checksum. */
8356 faddr = ha->flt_region_nvram;
8357 if (IS_QLA28XX(ha)) {
8358 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8359 faddr = ha->flt_region_nvram_sec;
8361 ql_dbg(ql_dbg_init, vha, 0x0110,
8362 "Loading %s nvram image.\n",
8363 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8364 "primary" : "secondary");
8365 qla24xx_read_flash_data(vha, ha->nvram, faddr, ha->nvram_size >> 2);
8367 dptr = (uint32_t *)nv;
8368 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8369 chksum += le32_to_cpu(*dptr);
8371 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8372 "Contents of NVRAM:\n");
8373 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8374 nv, ha->nvram_size);
8376 /* Bad NVRAM data, set defaults parameters. */
8377 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8378 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8379 /* Reset NVRAM data. */
8380 ql_log(ql_log_info, vha, 0x0073,
8381 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8382 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8383 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8384 ql_log(ql_log_info, vha, 0x0074,
8385 "Falling back to functioning (yet invalid -- WWPN) "
8389 * Set default initialization control block.
8391 memset(nv, 0, ha->nvram_size);
8392 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8393 nv->version = cpu_to_le16(ICB_VERSION);
8394 nv->frame_payload_size = 2048;
8395 nv->execution_throttle = cpu_to_le16(0xFFFF);
8396 nv->exchange_count = cpu_to_le16(0);
8397 nv->port_name[0] = 0x21;
8398 nv->port_name[1] = 0x00 + ha->port_no + 1;
8399 nv->port_name[2] = 0x00;
8400 nv->port_name[3] = 0xe0;
8401 nv->port_name[4] = 0x8b;
8402 nv->port_name[5] = 0x1c;
8403 nv->port_name[6] = 0x55;
8404 nv->port_name[7] = 0x86;
8405 nv->node_name[0] = 0x20;
8406 nv->node_name[1] = 0x00;
8407 nv->node_name[2] = 0x00;
8408 nv->node_name[3] = 0xe0;
8409 nv->node_name[4] = 0x8b;
8410 nv->node_name[5] = 0x1c;
8411 nv->node_name[6] = 0x55;
8412 nv->node_name[7] = 0x86;
8413 nv->login_retry_count = cpu_to_le16(8);
8414 nv->interrupt_delay_timer = cpu_to_le16(0);
8415 nv->login_timeout = cpu_to_le16(0);
8416 nv->firmware_options_1 =
8417 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8418 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8419 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8420 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8421 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8422 nv->efi_parameters = cpu_to_le32(0);
8423 nv->reset_delay = 5;
8424 nv->max_luns_per_target = cpu_to_le16(128);
8425 nv->port_down_retry_count = cpu_to_le16(30);
8426 nv->link_down_timeout = cpu_to_le16(180);
8427 nv->enode_mac[0] = 0x00;
8428 nv->enode_mac[1] = 0xC0;
8429 nv->enode_mac[2] = 0xDD;
8430 nv->enode_mac[3] = 0x04;
8431 nv->enode_mac[4] = 0x05;
8432 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8437 if (IS_T10_PI_CAPABLE(ha))
8438 nv->frame_payload_size &= ~7;
8440 qlt_81xx_config_nvram_stage1(vha, nv);
8442 /* Reset Initialization control block */
8443 memset(icb, 0, ha->init_cb_size);
8445 /* Copy 1st segment. */
8446 dptr1 = (uint8_t *)icb;
8447 dptr2 = (uint8_t *)&nv->version;
8448 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8450 *dptr1++ = *dptr2++;
8452 icb->login_retry_count = nv->login_retry_count;
8454 /* Copy 2nd segment. */
8455 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8456 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8457 cnt = (uint8_t *)&icb->reserved_5 -
8458 (uint8_t *)&icb->interrupt_delay_timer;
8460 *dptr1++ = *dptr2++;
8462 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8463 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8464 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8465 icb->enode_mac[0] = 0x00;
8466 icb->enode_mac[1] = 0xC0;
8467 icb->enode_mac[2] = 0xDD;
8468 icb->enode_mac[3] = 0x04;
8469 icb->enode_mac[4] = 0x05;
8470 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8473 /* Use extended-initialization control block. */
8474 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8475 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8477 * Setup driver NVRAM options.
8479 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8482 qlt_81xx_config_nvram_stage2(vha, icb);
8484 /* Use alternate WWN? */
8485 if (nv->host_p & cpu_to_le32(BIT_15)) {
8486 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8487 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8490 /* Prepare nodename */
8491 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8493 * Firmware will apply the following mask if the nodename was
8496 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8497 icb->node_name[0] &= 0xF0;
8500 /* Set host adapter parameters. */
8501 ha->flags.disable_risc_code_load = 0;
8502 ha->flags.enable_lip_reset = 0;
8503 ha->flags.enable_lip_full_login =
8504 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8505 ha->flags.enable_target_reset =
8506 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8507 ha->flags.enable_led_scheme = 0;
8508 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8510 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8511 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8513 /* save HBA serial number */
8514 ha->serial0 = icb->port_name[5];
8515 ha->serial1 = icb->port_name[6];
8516 ha->serial2 = icb->port_name[7];
8517 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8518 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8520 icb->execution_throttle = cpu_to_le16(0xFFFF);
8522 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8524 /* Set minimum login_timeout to 4 seconds. */
8525 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8526 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8527 if (le16_to_cpu(nv->login_timeout) < 4)
8528 nv->login_timeout = cpu_to_le16(4);
8529 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8531 /* Set minimum RATOV to 100 tenths of a second. */
8534 ha->loop_reset_delay = nv->reset_delay;
8536 /* Link Down Timeout = 0:
8538 * When Port Down timer expires we will start returning
8539 * I/O's to OS with "DID_NO_CONNECT".
8541 * Link Down Timeout != 0:
8543 * The driver waits for the link to come up after link down
8544 * before returning I/Os to OS with "DID_NO_CONNECT".
8546 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8547 ha->loop_down_abort_time =
8548 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8550 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8551 ha->loop_down_abort_time =
8552 (LOOP_DOWN_TIME - ha->link_down_timeout);
8555 /* Need enough time to try and get the port back. */
8556 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8557 if (qlport_down_retry)
8558 ha->port_down_retry_count = qlport_down_retry;
8560 /* Set login_retry_count */
8561 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8562 if (ha->port_down_retry_count ==
8563 le16_to_cpu(nv->port_down_retry_count) &&
8564 ha->port_down_retry_count > 3)
8565 ha->login_retry_count = ha->port_down_retry_count;
8566 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8567 ha->login_retry_count = ha->port_down_retry_count;
8568 if (ql2xloginretrycount)
8569 ha->login_retry_count = ql2xloginretrycount;
8571 /* if not running MSI-X we need handshaking on interrupts */
8572 if (!vha->hw->flags.msix_enabled &&
8573 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8574 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8577 if (!vha->flags.init_done) {
8578 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8579 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8580 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8581 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8583 icb->firmware_options_2 &= cpu_to_le32(
8584 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8585 vha->flags.process_response_queue = 0;
8586 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8587 ha->zio_mode = QLA_ZIO_MODE_6;
8589 ql_log(ql_log_info, vha, 0x0075,
8590 "ZIO mode %d enabled; timer delay (%d us).\n",
8592 ha->zio_timer * 100);
8594 icb->firmware_options_2 |= cpu_to_le32(
8595 (uint32_t)ha->zio_mode);
8596 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8597 vha->flags.process_response_queue = 1;
8600 /* enable RIDA Format2 */
8601 icb->firmware_options_3 |= BIT_0;
8603 /* N2N: driver will initiate Login instead of FW */
8604 icb->firmware_options_3 |= BIT_8;
8607 ql_log(ql_log_warn, vha, 0x0076,
8608 "NVRAM configuration failed.\n");
8614 qla82xx_restart_isp(scsi_qla_host_t *vha)
8617 struct qla_hw_data *ha = vha->hw;
8618 struct scsi_qla_host *vp;
8619 unsigned long flags;
8621 status = qla2x00_init_rings(vha);
8623 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8624 ha->flags.chip_reset_done = 1;
8626 status = qla2x00_fw_ready(vha);
8628 /* Issue a marker after FW becomes ready. */
8629 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8630 vha->flags.online = 1;
8631 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8634 /* if no cable then assume it's good */
8635 if ((vha->device_flags & DFLG_NO_CABLE))
8640 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8642 if (!atomic_read(&vha->loop_down_timer)) {
8644 * Issue marker command only when we are going
8645 * to start the I/O .
8647 vha->marker_needed = 1;
8650 ha->isp_ops->enable_intrs(ha);
8652 ha->isp_abort_cnt = 0;
8653 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8655 /* Update the firmware version */
8656 status = qla82xx_check_md_needed(vha);
8659 ha->flags.fce_enabled = 1;
8661 fce_calc_size(ha->fce_bufs));
8662 rval = qla2x00_enable_fce_trace(vha,
8663 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8666 ql_log(ql_log_warn, vha, 0x8001,
8667 "Unable to reinitialize FCE (%d).\n",
8669 ha->flags.fce_enabled = 0;
8674 memset(ha->eft, 0, EFT_SIZE);
8675 rval = qla2x00_enable_eft_trace(vha,
8676 ha->eft_dma, EFT_NUM_BUFFERS);
8678 ql_log(ql_log_warn, vha, 0x8010,
8679 "Unable to reinitialize EFT (%d).\n",
8686 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8687 "qla82xx_restart_isp succeeded.\n");
8689 spin_lock_irqsave(&ha->vport_slock, flags);
8690 list_for_each_entry(vp, &ha->vp_list, list) {
8692 atomic_inc(&vp->vref_count);
8693 spin_unlock_irqrestore(&ha->vport_slock, flags);
8695 qla2x00_vp_abort_isp(vp);
8697 spin_lock_irqsave(&ha->vport_slock, flags);
8698 atomic_dec(&vp->vref_count);
8701 spin_unlock_irqrestore(&ha->vport_slock, flags);
8704 ql_log(ql_log_warn, vha, 0x8016,
8705 "qla82xx_restart_isp **** FAILED ****.\n");
8712 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8714 struct qla_hw_data *ha = vha->hw;
8716 /* Hold status IOCBs until ABTS response received. */
8718 ha->fw_options[3] |= BIT_12;
8720 /* Set Retry FLOGI in case of P2P connection */
8721 if (ha->operating_mode == P2P) {
8722 ha->fw_options[2] |= BIT_3;
8723 ql_dbg(ql_dbg_disc, vha, 0x2103,
8724 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8725 __func__, ha->fw_options[2]);
8728 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8729 if (ql2xmvasynctoatio) {
8730 if (qla_tgt_mode_enabled(vha) ||
8731 qla_dual_mode_enabled(vha))
8732 ha->fw_options[2] |= BIT_11;
8734 ha->fw_options[2] &= ~BIT_11;
8737 if (qla_tgt_mode_enabled(vha) ||
8738 qla_dual_mode_enabled(vha)) {
8739 /* FW auto send SCSI status during */
8740 ha->fw_options[1] |= BIT_8;
8741 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8743 /* FW perform Exchange validation */
8744 ha->fw_options[2] |= BIT_4;
8746 ha->fw_options[1] &= ~BIT_8;
8747 ha->fw_options[10] &= 0x00ff;
8749 ha->fw_options[2] &= ~BIT_4;
8752 if (ql2xetsenable) {
8753 /* Enable ETS Burst. */
8754 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8755 ha->fw_options[2] |= BIT_9;
8758 ql_dbg(ql_dbg_init, vha, 0x00e9,
8759 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8760 __func__, ha->fw_options[1], ha->fw_options[2],
8761 ha->fw_options[3], vha->host->active_mode);
8763 qla2x00_set_fw_options(vha, ha->fw_options);
8767 * qla24xx_get_fcp_prio
8768 * Gets the fcp cmd priority value for the logged in port.
8769 * Looks for a match of the port descriptors within
8770 * each of the fcp prio config entries. If a match is found,
8771 * the tag (priority) value is returned.
8774 * vha = scsi host structure pointer.
8775 * fcport = port structure pointer.
8778 * non-zero (if found)
8785 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8788 uint8_t pid_match, wwn_match;
8790 uint32_t pid1, pid2;
8791 uint64_t wwn1, wwn2;
8792 struct qla_fcp_prio_entry *pri_entry;
8793 struct qla_hw_data *ha = vha->hw;
8795 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8799 entries = ha->fcp_prio_cfg->num_entries;
8800 pri_entry = &ha->fcp_prio_cfg->entry[0];
8802 for (i = 0; i < entries; i++) {
8803 pid_match = wwn_match = 0;
8805 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8810 /* check source pid for a match */
8811 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8812 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8813 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8814 if (pid1 == INVALID_PORT_ID)
8816 else if (pid1 == pid2)
8820 /* check destination pid for a match */
8821 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8822 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8823 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8824 if (pid1 == INVALID_PORT_ID)
8826 else if (pid1 == pid2)
8830 /* check source WWN for a match */
8831 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8832 wwn1 = wwn_to_u64(vha->port_name);
8833 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8834 if (wwn2 == (uint64_t)-1)
8836 else if (wwn1 == wwn2)
8840 /* check destination WWN for a match */
8841 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8842 wwn1 = wwn_to_u64(fcport->port_name);
8843 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8844 if (wwn2 == (uint64_t)-1)
8846 else if (wwn1 == wwn2)
8850 if (pid_match == 2 || wwn_match == 2) {
8851 /* Found a matching entry */
8852 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8853 priority = pri_entry->tag;
8864 * qla24xx_update_fcport_fcp_prio
8865 * Activates fcp priority for the logged in fc port
8868 * vha = scsi host structure pointer.
8869 * fcp = port structure pointer.
8872 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8878 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8884 if (fcport->port_type != FCT_TARGET ||
8885 fcport->loop_id == FC_NO_LOOP_ID)
8886 return QLA_FUNCTION_FAILED;
8888 priority = qla24xx_get_fcp_prio(vha, fcport);
8890 return QLA_FUNCTION_FAILED;
8892 if (IS_P3P_TYPE(vha->hw)) {
8893 fcport->fcp_prio = priority & 0xf;
8897 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8898 if (ret == QLA_SUCCESS) {
8899 if (fcport->fcp_prio != priority)
8900 ql_dbg(ql_dbg_user, vha, 0x709e,
8901 "Updated FCP_CMND priority - value=%d loop_id=%d "
8902 "port_id=%02x%02x%02x.\n", priority,
8903 fcport->loop_id, fcport->d_id.b.domain,
8904 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8905 fcport->fcp_prio = priority & 0xf;
8907 ql_dbg(ql_dbg_user, vha, 0x704f,
8908 "Unable to update FCP_CMND priority - ret=0x%x for "
8909 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8910 fcport->d_id.b.domain, fcport->d_id.b.area,
8911 fcport->d_id.b.al_pa);
8916 * qla24xx_update_all_fcp_prio
8917 * Activates fcp priority for all the logged in ports
8920 * ha = adapter block pointer.
8923 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8929 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8934 ret = QLA_FUNCTION_FAILED;
8935 /* We need to set priority for all logged in ports */
8936 list_for_each_entry(fcport, &vha->vp_fcports, list)
8937 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8942 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8943 int vp_idx, bool startqp)
8948 struct qla_hw_data *ha = vha->hw;
8949 uint16_t qpair_id = 0;
8950 struct qla_qpair *qpair = NULL;
8951 struct qla_msix_entry *msix;
8953 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8954 ql_log(ql_log_warn, vha, 0x00181,
8955 "FW/Driver is not multi-queue capable.\n");
8959 if (ql2xmqsupport || ql2xnvmeenable) {
8960 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8961 if (qpair == NULL) {
8962 ql_log(ql_log_warn, vha, 0x0182,
8963 "Failed to allocate memory for queue pair.\n");
8967 qpair->hw = vha->hw;
8969 qpair->qp_lock_ptr = &qpair->qp_lock;
8970 spin_lock_init(&qpair->qp_lock);
8971 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8973 /* Assign available que pair id */
8974 mutex_lock(&ha->mq_lock);
8975 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8976 if (ha->num_qpairs >= ha->max_qpairs) {
8977 mutex_unlock(&ha->mq_lock);
8978 ql_log(ql_log_warn, vha, 0x0183,
8979 "No resources to create additional q pair.\n");
8983 set_bit(qpair_id, ha->qpair_qid_map);
8984 ha->queue_pair_map[qpair_id] = qpair;
8985 qpair->id = qpair_id;
8986 qpair->vp_idx = vp_idx;
8987 qpair->fw_started = ha->flags.fw_started;
8988 INIT_LIST_HEAD(&qpair->hints_list);
8989 qpair->chip_reset = ha->base_qpair->chip_reset;
8990 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8991 qpair->enable_explicit_conf =
8992 ha->base_qpair->enable_explicit_conf;
8994 for (i = 0; i < ha->msix_count; i++) {
8995 msix = &ha->msix_entries[i];
8999 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
9000 "Vector %x selected for qpair\n", msix->vector);
9004 ql_log(ql_log_warn, vha, 0x0184,
9005 "Out of MSI-X vectors!.\n");
9009 qpair->msix->in_use = 1;
9010 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
9011 qpair->pdev = ha->pdev;
9012 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
9013 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
9015 mutex_unlock(&ha->mq_lock);
9017 /* Create response queue first */
9018 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
9020 ql_log(ql_log_warn, vha, 0x0185,
9021 "Failed to create response queue.\n");
9025 qpair->rsp = ha->rsp_q_map[rsp_id];
9027 /* Create request queue */
9028 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
9031 ql_log(ql_log_warn, vha, 0x0186,
9032 "Failed to create request queue.\n");
9036 qpair->req = ha->req_q_map[req_id];
9037 qpair->rsp->req = qpair->req;
9038 qpair->rsp->qpair = qpair;
9039 /* init qpair to this cpu. Will adjust at run time. */
9040 qla_cpu_update(qpair, smp_processor_id());
9042 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
9043 if (ha->fw_attributes & BIT_4)
9044 qpair->difdix_supported = 1;
9047 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
9048 if (!qpair->srb_mempool) {
9049 ql_log(ql_log_warn, vha, 0xd036,
9050 "Failed to create srb mempool for qpair %d\n",
9055 /* Mark as online */
9058 if (!vha->flags.qpairs_available)
9059 vha->flags.qpairs_available = 1;
9061 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9062 "Request/Response queue pair created, id %d\n",
9064 ql_dbg(ql_dbg_init, vha, 0x0187,
9065 "Request/Response queue pair created, id %d\n",
9072 qla25xx_delete_rsp_que(vha, qpair->rsp);
9074 mutex_lock(&ha->mq_lock);
9075 qpair->msix->in_use = 0;
9076 list_del(&qpair->qp_list_elem);
9077 if (list_empty(&vha->qp_list))
9078 vha->flags.qpairs_available = 0;
9080 ha->queue_pair_map[qpair_id] = NULL;
9081 clear_bit(qpair_id, ha->qpair_qid_map);
9083 mutex_unlock(&ha->mq_lock);
9089 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9091 int ret = QLA_FUNCTION_FAILED;
9092 struct qla_hw_data *ha = qpair->hw;
9094 qpair->delete_in_progress = 1;
9095 while (atomic_read(&qpair->ref_count))
9098 ret = qla25xx_delete_req_que(vha, qpair->req);
9099 if (ret != QLA_SUCCESS)
9102 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9103 if (ret != QLA_SUCCESS)
9106 mutex_lock(&ha->mq_lock);
9107 ha->queue_pair_map[qpair->id] = NULL;
9108 clear_bit(qpair->id, ha->qpair_qid_map);
9110 list_del(&qpair->qp_list_elem);
9111 if (list_empty(&vha->qp_list)) {
9112 vha->flags.qpairs_available = 0;
9113 vha->flags.qpairs_req_created = 0;
9114 vha->flags.qpairs_rsp_created = 0;
9116 mempool_destroy(qpair->srb_mempool);
9118 mutex_unlock(&ha->mq_lock);