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;
99 qla2x00_async_iocb_timeout(void *data)
102 fc_port_t *fcport = sp->fcport;
103 struct srb_iocb *lio = &sp->u.iocb_cmd;
108 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
109 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
110 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
112 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
114 pr_info("Async-%s timeout - hdl=%x.\n",
115 sp->name, sp->handle);
120 rc = qla24xx_async_abort_cmd(sp, false);
122 /* Retry as needed. */
123 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
124 lio->u.logio.data[1] =
125 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
126 QLA_LOGIO_LOGIN_RETRIED : 0;
127 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
128 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
130 if (sp->qpair->req->outstanding_cmds[h] ==
132 sp->qpair->req->outstanding_cmds[h] =
137 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
138 sp->done(sp, QLA_FUNCTION_TIMEOUT);
142 case SRB_CT_PTHRU_CMD:
148 rc = qla24xx_async_abort_cmd(sp, false);
150 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
151 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
153 if (sp->qpair->req->outstanding_cmds[h] ==
155 sp->qpair->req->outstanding_cmds[h] =
160 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
161 sp->done(sp, QLA_FUNCTION_TIMEOUT);
168 qla2x00_async_login_sp_done(void *ptr, int res)
171 struct scsi_qla_host *vha = sp->vha;
172 struct srb_iocb *lio = &sp->u.iocb_cmd;
175 ql_dbg(ql_dbg_disc, vha, 0x20dd,
176 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
178 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
180 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
181 memset(&ea, 0, sizeof(ea));
182 ea.event = FCME_PLOGI_DONE;
183 ea.fcport = sp->fcport;
184 ea.data[0] = lio->u.logio.data[0];
185 ea.data[1] = lio->u.logio.data[1];
186 ea.iop[0] = lio->u.logio.iop[0];
187 ea.iop[1] = lio->u.logio.iop[1];
189 qla2x00_fcport_event_handler(vha, &ea);
196 fcport_is_smaller(fc_port_t *fcport)
198 if (wwn_to_u64(fcport->port_name) <
199 wwn_to_u64(fcport->vha->port_name))
206 fcport_is_bigger(fc_port_t *fcport)
208 return !fcport_is_smaller(fcport);
212 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
216 struct srb_iocb *lio;
217 int rval = QLA_FUNCTION_FAILED;
219 if (!vha->flags.online)
222 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
226 fcport->flags |= FCF_ASYNC_SENT;
227 fcport->logout_completed = 0;
229 fcport->disc_state = DSC_LOGIN_PEND;
230 sp->type = SRB_LOGIN_CMD;
232 sp->gen1 = fcport->rscn_gen;
233 sp->gen2 = fcport->login_gen;
235 lio = &sp->u.iocb_cmd;
236 lio->timeout = qla2x00_async_iocb_timeout;
237 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
239 sp->done = qla2x00_async_login_sp_done;
240 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) {
241 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
243 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
245 if (fcport->fc4f_nvme)
246 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
250 ql_dbg(ql_dbg_disc, vha, 0x2072,
251 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
252 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
253 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
254 fcport->login_retry);
256 rval = qla2x00_start_sp(sp);
257 if (rval != QLA_SUCCESS) {
258 fcport->flags |= FCF_LOGIN_NEEDED;
259 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
267 fcport->flags &= ~FCF_ASYNC_SENT;
269 fcport->flags &= ~FCF_ASYNC_ACTIVE;
274 qla2x00_async_logout_sp_done(void *ptr, int res)
278 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
279 sp->fcport->login_gen++;
280 qlt_logo_completion_handler(sp->fcport, res);
285 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
288 struct srb_iocb *lio;
289 int rval = QLA_FUNCTION_FAILED;
291 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
294 fcport->flags |= FCF_ASYNC_SENT;
295 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
299 sp->type = SRB_LOGOUT_CMD;
302 lio = &sp->u.iocb_cmd;
303 lio->timeout = qla2x00_async_iocb_timeout;
304 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
306 sp->done = qla2x00_async_logout_sp_done;
308 ql_dbg(ql_dbg_disc, vha, 0x2070,
309 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
310 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
311 fcport->d_id.b.area, fcport->d_id.b.al_pa,
314 rval = qla2x00_start_sp(sp);
315 if (rval != QLA_SUCCESS)
322 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
327 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
330 fcport->flags &= ~FCF_ASYNC_ACTIVE;
331 /* Don't re-login in target mode */
332 if (!fcport->tgt_session)
333 qla2x00_mark_device_lost(vha, fcport, 1, 0);
334 qlt_logo_completion_handler(fcport, data[0]);
338 qla2x00_async_prlo_sp_done(void *s, int res)
340 srb_t *sp = (srb_t *)s;
341 struct srb_iocb *lio = &sp->u.iocb_cmd;
342 struct scsi_qla_host *vha = sp->vha;
344 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
345 if (!test_bit(UNLOADING, &vha->dpc_flags))
346 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
352 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
355 struct srb_iocb *lio;
358 rval = QLA_FUNCTION_FAILED;
359 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
363 sp->type = SRB_PRLO_CMD;
366 lio = &sp->u.iocb_cmd;
367 lio->timeout = qla2x00_async_iocb_timeout;
368 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
370 sp->done = qla2x00_async_prlo_sp_done;
371 rval = qla2x00_start_sp(sp);
372 if (rval != QLA_SUCCESS)
375 ql_dbg(ql_dbg_disc, vha, 0x2070,
376 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
377 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
378 fcport->d_id.b.area, fcport->d_id.b.al_pa);
384 fcport->flags &= ~FCF_ASYNC_ACTIVE;
389 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
391 struct fc_port *fcport = ea->fcport;
393 ql_dbg(ql_dbg_disc, vha, 0x20d2,
394 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
395 __func__, fcport->port_name, fcport->disc_state,
396 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
397 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
399 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
400 ql_dbg(ql_dbg_disc, vha, 0x2066,
401 "%s %8phC: adisc fail: post delete\n",
402 __func__, ea->fcport->port_name);
403 /* deleted = 0 & logout_on_delete = force fw cleanup */
405 fcport->logout_on_delete = 1;
406 qlt_schedule_sess_for_deletion(ea->fcport);
410 if (ea->fcport->disc_state == DSC_DELETE_PEND)
413 if (ea->sp->gen2 != ea->fcport->login_gen) {
414 /* target side must have changed it. */
415 ql_dbg(ql_dbg_disc, vha, 0x20d3,
416 "%s %8phC generation changed\n",
417 __func__, ea->fcport->port_name);
419 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
420 qla_rscn_replay(fcport);
421 qlt_schedule_sess_for_deletion(fcport);
425 __qla24xx_handle_gpdb_event(vha, ea);
428 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
430 struct qla_work_evt *e;
432 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
434 return QLA_FUNCTION_FAILED;
436 e->u.fcport.fcport = fcport;
437 fcport->flags |= FCF_ASYNC_ACTIVE;
438 return qla2x00_post_work(vha, e);
442 qla2x00_async_adisc_sp_done(void *ptr, int res)
445 struct scsi_qla_host *vha = sp->vha;
447 struct srb_iocb *lio = &sp->u.iocb_cmd;
449 ql_dbg(ql_dbg_disc, vha, 0x2066,
450 "Async done-%s res %x %8phC\n",
451 sp->name, res, sp->fcport->port_name);
453 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
455 memset(&ea, 0, sizeof(ea));
456 ea.event = FCME_ADISC_DONE;
458 ea.data[0] = lio->u.logio.data[0];
459 ea.data[1] = lio->u.logio.data[1];
460 ea.iop[0] = lio->u.logio.iop[0];
461 ea.iop[1] = lio->u.logio.iop[1];
462 ea.fcport = sp->fcport;
465 qla2x00_fcport_event_handler(vha, &ea);
471 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
475 struct srb_iocb *lio;
478 rval = QLA_FUNCTION_FAILED;
479 fcport->flags |= FCF_ASYNC_SENT;
480 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
484 sp->type = SRB_ADISC_CMD;
487 lio = &sp->u.iocb_cmd;
488 lio->timeout = qla2x00_async_iocb_timeout;
489 sp->gen1 = fcport->rscn_gen;
490 sp->gen2 = fcport->login_gen;
491 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
493 sp->done = qla2x00_async_adisc_sp_done;
494 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
495 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
497 ql_dbg(ql_dbg_disc, vha, 0x206f,
498 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
499 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
501 rval = qla2x00_start_sp(sp);
502 if (rval != QLA_SUCCESS)
510 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
511 qla2x00_post_async_adisc_work(vha, fcport, data);
515 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
516 struct event_arg *ea)
518 fc_port_t *fcport, *conflict_fcport;
519 struct get_name_list_extended *e;
520 u16 i, n, found = 0, loop_id;
524 u8 current_login_state;
527 ql_dbg(ql_dbg_disc, vha, 0xffff,
528 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
529 __func__, fcport->port_name, fcport->disc_state,
530 fcport->fw_login_state, ea->rc,
531 fcport->login_gen, fcport->last_login_gen,
532 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
534 if (fcport->disc_state == DSC_DELETE_PEND)
537 if (ea->rc) { /* rval */
538 if (fcport->login_retry == 0) {
539 ql_dbg(ql_dbg_disc, vha, 0x20de,
540 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
541 fcport->port_name, fcport->login_retry);
546 if (fcport->last_rscn_gen != fcport->rscn_gen) {
547 qla_rscn_replay(fcport);
548 qlt_schedule_sess_for_deletion(fcport);
550 } else if (fcport->last_login_gen != fcport->login_gen) {
551 ql_dbg(ql_dbg_disc, vha, 0x20e0,
552 "%s %8phC login gen changed\n",
553 __func__, fcport->port_name);
557 n = ea->data[0] / sizeof(struct get_name_list_extended);
559 ql_dbg(ql_dbg_disc, vha, 0x20e1,
560 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
561 __func__, __LINE__, fcport->port_name, n,
562 fcport->d_id.b.domain, fcport->d_id.b.area,
563 fcport->d_id.b.al_pa, fcport->loop_id);
565 for (i = 0; i < n; i++) {
567 wwn = wwn_to_u64(e->port_name);
568 id.b.domain = e->port_id[2];
569 id.b.area = e->port_id[1];
570 id.b.al_pa = e->port_id[0];
573 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
576 if (IS_SW_RESV_ADDR(id))
581 loop_id = le16_to_cpu(e->nport_handle);
582 loop_id = (loop_id & 0x7fff);
583 if (fcport->fc4f_nvme)
584 current_login_state = e->current_login_state >> 4;
586 current_login_state = e->current_login_state & 0xf;
589 ql_dbg(ql_dbg_disc, vha, 0x20e2,
590 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
591 __func__, fcport->port_name,
592 e->current_login_state, fcport->fw_login_state,
593 fcport->fc4f_nvme, id.b.domain, id.b.area, id.b.al_pa,
594 fcport->d_id.b.domain, fcport->d_id.b.area,
595 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
597 switch (fcport->disc_state) {
598 case DSC_DELETE_PEND:
602 if ((id.b24 != fcport->d_id.b24 &&
604 (fcport->loop_id != FC_NO_LOOP_ID &&
605 fcport->loop_id != loop_id)) {
606 ql_dbg(ql_dbg_disc, vha, 0x20e3,
607 "%s %d %8phC post del sess\n",
608 __func__, __LINE__, fcport->port_name);
609 qlt_schedule_sess_for_deletion(fcport);
615 fcport->loop_id = loop_id;
617 wwn = wwn_to_u64(fcport->port_name);
618 qlt_find_sess_invalidate_other(vha, wwn,
619 id, loop_id, &conflict_fcport);
621 if (conflict_fcport) {
623 * Another share fcport share the same loop_id &
624 * nport id. Conflict fcport needs to finish
625 * cleanup before this fcport can proceed to login.
627 conflict_fcport->conflict = fcport;
628 fcport->login_pause = 1;
631 switch (vha->hw->current_topology) {
633 switch (current_login_state) {
634 case DSC_LS_PRLI_COMP:
635 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
636 vha, 0x20e4, "%s %d %8phC post gpdb\n",
637 __func__, __LINE__, fcport->port_name);
639 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
640 fcport->port_type = FCT_INITIATOR;
642 fcport->port_type = FCT_TARGET;
643 data[0] = data[1] = 0;
644 qla2x00_post_async_adisc_work(vha, fcport,
647 case DSC_LS_PORT_UNAVAIL:
649 if (fcport->loop_id != FC_NO_LOOP_ID)
650 qla2x00_clear_loop_id(fcport);
652 fcport->loop_id = loop_id;
653 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
654 qla24xx_fcport_handle_login(vha, fcport);
659 fcport->fw_login_state = current_login_state;
661 switch (current_login_state) {
662 case DSC_LS_PRLI_COMP:
663 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
664 fcport->port_type = FCT_INITIATOR;
666 fcport->port_type = FCT_TARGET;
668 data[0] = data[1] = 0;
669 qla2x00_post_async_adisc_work(vha, fcport,
672 case DSC_LS_PLOGI_COMP:
673 if (fcport_is_bigger(fcport)) {
674 /* local adapter is smaller */
675 if (fcport->loop_id != FC_NO_LOOP_ID)
676 qla2x00_clear_loop_id(fcport);
678 fcport->loop_id = loop_id;
679 qla24xx_fcport_handle_login(vha,
685 if (fcport_is_smaller(fcport)) {
686 /* local adapter is bigger */
687 if (fcport->loop_id != FC_NO_LOOP_ID)
688 qla2x00_clear_loop_id(fcport);
690 fcport->loop_id = loop_id;
691 qla24xx_fcport_handle_login(vha,
697 } /* switch (ha->current_topology) */
701 switch (vha->hw->current_topology) {
704 for (i = 0; i < n; i++) {
706 id.b.domain = e->port_id[0];
707 id.b.area = e->port_id[1];
708 id.b.al_pa = e->port_id[2];
710 loop_id = le16_to_cpu(e->nport_handle);
712 if (fcport->d_id.b24 == id.b24) {
714 qla2x00_find_fcport_by_wwpn(vha,
716 if (conflict_fcport) {
717 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
719 "%s %d %8phC post del sess\n",
721 conflict_fcport->port_name);
722 qlt_schedule_sess_for_deletion
727 * FW already picked this loop id for
730 if (fcport->loop_id == loop_id)
731 fcport->loop_id = FC_NO_LOOP_ID;
733 qla24xx_fcport_handle_login(vha, fcport);
736 fcport->disc_state = DSC_DELETED;
737 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
738 if (fcport->n2n_link_reset_cnt < 2) {
739 fcport->n2n_link_reset_cnt++;
741 * remote port is not sending PLOGI.
742 * Reset link to kick start his state
745 set_bit(N2N_LINK_RESET,
748 if (fcport->n2n_chip_reset < 1) {
749 ql_log(ql_log_info, vha, 0x705d,
750 "Chip reset to bring laser down");
751 set_bit(ISP_ABORT_NEEDED,
753 fcport->n2n_chip_reset++;
755 ql_log(ql_log_info, vha, 0x705d,
756 "Remote port %8ph is not coming back\n",
758 fcport->scan_state = 0;
761 qla2xxx_wake_dpc(vha);
764 * report port suppose to do PLOGI. Give him
765 * more time. FW will catch it.
767 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
777 qla24xx_async_gnl_sp_done(void *s, int res)
780 struct scsi_qla_host *vha = sp->vha;
782 struct fc_port *fcport = NULL, *tf;
783 u16 i, n = 0, loop_id;
785 struct get_name_list_extended *e;
790 ql_dbg(ql_dbg_disc, vha, 0x20e7,
791 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
792 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
793 sp->u.iocb_cmd.u.mbx.in_mb[2]);
795 if (res == QLA_FUNCTION_TIMEOUT)
798 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
799 memset(&ea, 0, sizeof(ea));
802 ea.event = FCME_GNL_DONE;
804 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
805 sizeof(struct get_name_list_extended)) {
806 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
807 sizeof(struct get_name_list_extended);
808 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
811 for (i = 0; i < n; i++) {
813 loop_id = le16_to_cpu(e->nport_handle);
814 /* mask out reserve bit */
815 loop_id = (loop_id & 0x7fff);
816 set_bit(loop_id, vha->hw->loop_id_map);
817 wwn = wwn_to_u64(e->port_name);
819 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
820 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
821 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
822 e->port_id[0], e->current_login_state, e->last_login_state,
826 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
830 if (!list_empty(&vha->gnl.fcports))
831 list_splice_init(&vha->gnl.fcports, &h);
832 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
834 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
835 list_del_init(&fcport->gnl_entry);
836 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
837 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
838 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
841 qla2x00_fcport_event_handler(vha, &ea);
844 /* create new fcport if fw has knowledge of new sessions */
845 for (i = 0; i < n; i++) {
850 wwn = wwn_to_u64(e->port_name);
853 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
854 if (!memcmp((u8 *)&wwn, fcport->port_name,
861 id.b.domain = e->port_id[2];
862 id.b.area = e->port_id[1];
863 id.b.al_pa = e->port_id[0];
866 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
867 ql_dbg(ql_dbg_disc, vha, 0x2065,
868 "%s %d %8phC %06x post new sess\n",
869 __func__, __LINE__, (u8 *)&wwn, id.b24);
870 wwnn = wwn_to_u64(e->node_name);
871 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
872 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
876 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
878 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
883 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
886 struct srb_iocb *mbx;
887 int rval = QLA_FUNCTION_FAILED;
891 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
894 ql_dbg(ql_dbg_disc, vha, 0x20d9,
895 "Async-gnlist WWPN %8phC \n", fcport->port_name);
897 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
898 fcport->flags |= FCF_ASYNC_SENT;
899 fcport->disc_state = DSC_GNL;
900 fcport->last_rscn_gen = fcport->rscn_gen;
901 fcport->last_login_gen = fcport->login_gen;
903 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
905 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
909 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
911 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
915 sp->type = SRB_MB_IOCB;
917 sp->gen1 = fcport->rscn_gen;
918 sp->gen2 = fcport->login_gen;
920 mbx = &sp->u.iocb_cmd;
921 mbx->timeout = qla2x00_async_iocb_timeout;
922 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
924 mb = sp->u.iocb_cmd.u.mbx.out_mb;
925 mb[0] = MBC_PORT_NODE_NAME_LIST;
926 mb[1] = BIT_2 | BIT_3;
927 mb[2] = MSW(vha->gnl.ldma);
928 mb[3] = LSW(vha->gnl.ldma);
929 mb[6] = MSW(MSD(vha->gnl.ldma));
930 mb[7] = LSW(MSD(vha->gnl.ldma));
931 mb[8] = vha->gnl.size;
934 sp->done = qla24xx_async_gnl_sp_done;
936 rval = qla2x00_start_sp(sp);
937 if (rval != QLA_SUCCESS)
940 ql_dbg(ql_dbg_disc, vha, 0x20da,
941 "Async-%s - OUT WWPN %8phC hndl %x\n",
942 sp->name, fcport->port_name, sp->handle);
948 fcport->flags &= ~FCF_ASYNC_SENT;
953 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
955 struct qla_work_evt *e;
957 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
959 return QLA_FUNCTION_FAILED;
961 e->u.fcport.fcport = fcport;
962 fcport->flags |= FCF_ASYNC_ACTIVE;
963 return qla2x00_post_work(vha, e);
967 void qla24xx_async_gpdb_sp_done(void *s, int res)
970 struct scsi_qla_host *vha = sp->vha;
971 struct qla_hw_data *ha = vha->hw;
972 fc_port_t *fcport = sp->fcport;
973 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
976 ql_dbg(ql_dbg_disc, vha, 0x20db,
977 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
978 sp->name, res, fcport->port_name, mb[1], mb[2]);
980 if (res == QLA_FUNCTION_TIMEOUT) {
981 dma_pool_free(sp->vha->hw->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
982 sp->u.iocb_cmd.u.mbx.in_dma);
986 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
987 memset(&ea, 0, sizeof(ea));
988 ea.event = FCME_GPDB_DONE;
992 qla2x00_fcport_event_handler(vha, &ea);
994 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
995 sp->u.iocb_cmd.u.mbx.in_dma);
1000 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1002 struct qla_work_evt *e;
1004 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1006 return QLA_FUNCTION_FAILED;
1008 e->u.fcport.fcport = fcport;
1010 return qla2x00_post_work(vha, e);
1014 qla2x00_async_prli_sp_done(void *ptr, int res)
1017 struct scsi_qla_host *vha = sp->vha;
1018 struct srb_iocb *lio = &sp->u.iocb_cmd;
1019 struct event_arg ea;
1021 ql_dbg(ql_dbg_disc, vha, 0x2129,
1022 "%s %8phC res %d \n", __func__,
1023 sp->fcport->port_name, res);
1025 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1027 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1028 memset(&ea, 0, sizeof(ea));
1029 ea.event = FCME_PRLI_DONE;
1030 ea.fcport = sp->fcport;
1031 ea.data[0] = lio->u.logio.data[0];
1032 ea.data[1] = lio->u.logio.data[1];
1033 ea.iop[0] = lio->u.logio.iop[0];
1034 ea.iop[1] = lio->u.logio.iop[1];
1037 qla2x00_fcport_event_handler(vha, &ea);
1044 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1047 struct srb_iocb *lio;
1048 int rval = QLA_FUNCTION_FAILED;
1050 if (!vha->flags.online)
1053 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1054 fcport->fw_login_state == DSC_LS_PRLI_PEND)
1057 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1061 fcport->flags |= FCF_ASYNC_SENT;
1062 fcport->logout_completed = 0;
1064 sp->type = SRB_PRLI_CMD;
1067 lio = &sp->u.iocb_cmd;
1068 lio->timeout = qla2x00_async_iocb_timeout;
1069 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1071 sp->done = qla2x00_async_prli_sp_done;
1072 lio->u.logio.flags = 0;
1074 if (fcport->fc4f_nvme)
1075 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1077 rval = qla2x00_start_sp(sp);
1078 if (rval != QLA_SUCCESS) {
1079 fcport->flags |= FCF_LOGIN_NEEDED;
1080 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1084 ql_dbg(ql_dbg_disc, vha, 0x211b,
1085 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1086 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1087 fcport->login_retry, fcport->fc4f_nvme ? "nvme" : "fc");
1093 fcport->flags &= ~FCF_ASYNC_SENT;
1097 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1099 struct qla_work_evt *e;
1101 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1103 return QLA_FUNCTION_FAILED;
1105 e->u.fcport.fcport = fcport;
1106 e->u.fcport.opt = opt;
1107 fcport->flags |= FCF_ASYNC_ACTIVE;
1108 return qla2x00_post_work(vha, e);
1111 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1114 struct srb_iocb *mbx;
1115 int rval = QLA_FUNCTION_FAILED;
1118 struct port_database_24xx *pd;
1119 struct qla_hw_data *ha = vha->hw;
1121 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1124 fcport->disc_state = DSC_GPDB;
1126 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1130 fcport->flags |= FCF_ASYNC_SENT;
1131 sp->type = SRB_MB_IOCB;
1133 sp->gen1 = fcport->rscn_gen;
1134 sp->gen2 = fcport->login_gen;
1136 mbx = &sp->u.iocb_cmd;
1137 mbx->timeout = qla2x00_async_iocb_timeout;
1138 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1140 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1142 ql_log(ql_log_warn, vha, 0xd043,
1143 "Failed to allocate port database structure.\n");
1147 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1148 mb[0] = MBC_GET_PORT_DATABASE;
1149 mb[1] = fcport->loop_id;
1150 mb[2] = MSW(pd_dma);
1151 mb[3] = LSW(pd_dma);
1152 mb[6] = MSW(MSD(pd_dma));
1153 mb[7] = LSW(MSD(pd_dma));
1154 mb[9] = vha->vp_idx;
1157 mbx->u.mbx.in = (void *)pd;
1158 mbx->u.mbx.in_dma = pd_dma;
1160 sp->done = qla24xx_async_gpdb_sp_done;
1162 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1163 "Async-%s %8phC hndl %x opt %x\n",
1164 sp->name, fcport->port_name, sp->handle, opt);
1166 rval = qla2x00_start_sp(sp);
1167 if (rval != QLA_SUCCESS)
1173 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1176 fcport->flags &= ~FCF_ASYNC_SENT;
1178 qla24xx_post_gpdb_work(vha, fcport, opt);
1183 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1185 unsigned long flags;
1187 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1188 ea->fcport->login_gen++;
1189 ea->fcport->deleted = 0;
1190 ea->fcport->logout_on_delete = 1;
1192 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1193 vha->fcport_count++;
1194 ea->fcport->login_succ = 1;
1196 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1197 qla24xx_sched_upd_fcport(ea->fcport);
1198 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1199 } else if (ea->fcport->login_succ) {
1201 * We have an existing session. A late RSCN delivery
1202 * must have triggered the session to be re-validate.
1203 * Session is still valid.
1205 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1206 "%s %d %8phC session revalidate success\n",
1207 __func__, __LINE__, ea->fcport->port_name);
1208 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1210 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1214 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1216 fc_port_t *fcport = ea->fcport;
1217 struct port_database_24xx *pd;
1218 struct srb *sp = ea->sp;
1221 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1223 fcport->flags &= ~FCF_ASYNC_SENT;
1225 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1226 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__, fcport->port_name,
1227 fcport->disc_state, pd->current_login_state, fcport->fc4f_nvme,
1230 if (fcport->disc_state == DSC_DELETE_PEND)
1233 if (fcport->fc4f_nvme)
1234 ls = pd->current_login_state >> 4;
1236 ls = pd->current_login_state & 0xf;
1238 if (ea->sp->gen2 != fcport->login_gen) {
1239 /* target side must have changed it. */
1241 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1242 "%s %8phC generation changed\n",
1243 __func__, fcport->port_name);
1245 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1246 qla_rscn_replay(fcport);
1247 qlt_schedule_sess_for_deletion(fcport);
1252 case PDS_PRLI_COMPLETE:
1253 __qla24xx_parse_gpdb(vha, fcport, pd);
1255 case PDS_PLOGI_PENDING:
1256 case PDS_PLOGI_COMPLETE:
1257 case PDS_PRLI_PENDING:
1258 case PDS_PRLI2_PENDING:
1259 /* Set discovery state back to GNL to Relogin attempt */
1260 if (qla_dual_mode_enabled(vha) ||
1261 qla_ini_mode_enabled(vha)) {
1262 fcport->disc_state = DSC_GNL;
1263 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1266 case PDS_LOGO_PENDING:
1267 case PDS_PORT_UNAVAILABLE:
1269 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1270 __func__, __LINE__, fcport->port_name);
1271 qlt_schedule_sess_for_deletion(fcport);
1274 __qla24xx_handle_gpdb_event(vha, ea);
1277 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1282 if (qla_tgt_mode_enabled(vha))
1285 if (qla_dual_mode_enabled(vha)) {
1286 if (N2N_TOPO(vha->hw)) {
1289 mywwn = wwn_to_u64(vha->port_name);
1290 wwn = wwn_to_u64(fcport->port_name);
1293 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1294 && time_after_eq(jiffies,
1295 fcport->plogi_nack_done_deadline))
1301 /* initiator mode */
1305 if (login && fcport->login_retry) {
1306 fcport->login_retry--;
1307 if (fcport->loop_id == FC_NO_LOOP_ID) {
1308 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1309 rc = qla2x00_find_new_loop_id(vha, fcport);
1311 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1312 "%s %d %8phC post del sess - out of loopid\n",
1313 __func__, __LINE__, fcport->port_name);
1314 fcport->scan_state = 0;
1315 qlt_schedule_sess_for_deletion(fcport);
1319 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1320 "%s %d %8phC post login\n",
1321 __func__, __LINE__, fcport->port_name);
1322 qla2x00_post_async_login_work(vha, fcport, NULL);
1326 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1332 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20d8,
1333 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1334 __func__, fcport->port_name, fcport->disc_state,
1335 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1336 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1337 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1339 if (fcport->scan_state != QLA_FCPORT_FOUND)
1342 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1343 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1344 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1347 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1348 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1349 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1354 /* for pure Target Mode. Login will not be initiated */
1355 if (vha->host->active_mode == MODE_TARGET)
1358 if (fcport->flags & FCF_ASYNC_SENT) {
1359 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1363 switch (fcport->disc_state) {
1365 wwn = wwn_to_u64(fcport->node_name);
1366 switch (vha->hw->current_topology) {
1368 if (fcport_is_smaller(fcport)) {
1369 /* this adapter is bigger */
1370 if (fcport->login_retry) {
1371 if (fcport->loop_id == FC_NO_LOOP_ID) {
1372 qla2x00_find_new_loop_id(vha,
1374 fcport->fw_login_state =
1375 DSC_LS_PORT_UNAVAIL;
1377 fcport->login_retry--;
1378 qla_post_els_plogi_work(vha, fcport);
1380 ql_log(ql_log_info, vha, 0x705d,
1381 "Unable to reach remote port %8phC",
1385 qla24xx_post_gnl_work(vha, fcport);
1390 ql_dbg(ql_dbg_disc, vha, 0xffff,
1391 "%s %d %8phC post GNNID\n",
1392 __func__, __LINE__, fcport->port_name);
1393 qla24xx_post_gnnid_work(vha, fcport);
1394 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1395 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1396 "%s %d %8phC post gnl\n",
1397 __func__, __LINE__, fcport->port_name);
1398 qla24xx_post_gnl_work(vha, fcport);
1400 qla_chk_n2n_b4_login(vha, fcport);
1407 switch (vha->hw->current_topology) {
1409 if ((fcport->current_login_state & 0xf) == 0x6) {
1410 ql_dbg(ql_dbg_disc, vha, 0x2118,
1411 "%s %d %8phC post GPDB work\n",
1412 __func__, __LINE__, fcport->port_name);
1413 fcport->chip_reset =
1414 vha->hw->base_qpair->chip_reset;
1415 qla24xx_post_gpdb_work(vha, fcport, 0);
1417 ql_dbg(ql_dbg_disc, vha, 0x2118,
1418 "%s %d %8phC post NVMe PRLI\n",
1419 __func__, __LINE__, fcport->port_name);
1420 qla24xx_post_prli_work(vha, fcport);
1424 if (fcport->login_pause) {
1425 fcport->last_rscn_gen = fcport->rscn_gen;
1426 fcport->last_login_gen = fcport->login_gen;
1427 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1430 qla_chk_n2n_b4_login(vha, fcport);
1435 case DSC_LOGIN_FAILED:
1436 if (N2N_TOPO(vha->hw))
1437 qla_chk_n2n_b4_login(vha, fcport);
1439 qlt_schedule_sess_for_deletion(fcport);
1442 case DSC_LOGIN_COMPLETE:
1443 /* recheck login state */
1444 data[0] = data[1] = 0;
1445 qla2x00_post_async_adisc_work(vha, fcport, data);
1448 case DSC_LOGIN_PEND:
1449 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1450 qla24xx_post_prli_work(vha, fcport);
1453 case DSC_UPD_FCPORT:
1454 sec = jiffies_to_msecs(jiffies -
1455 fcport->jiffies_at_registration)/1000;
1456 if (fcport->sec_since_registration < sec && sec &&
1458 fcport->sec_since_registration = sec;
1459 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1460 "%s %8phC - Slow Rport registration(%d Sec)\n",
1461 __func__, fcport->port_name, sec);
1464 if (fcport->next_disc_state != DSC_DELETE_PEND)
1465 fcport->next_disc_state = DSC_ADISC;
1466 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1477 void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1481 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1482 "%s %8phC DS %d LS %d\n",
1483 __func__, fcport->port_name, fcport->disc_state,
1484 fcport->fw_login_state);
1486 if (fcport->flags & FCF_ASYNC_SENT)
1489 switch (fcport->disc_state) {
1491 case DSC_LOGIN_COMPLETE:
1492 qla24xx_post_gpnid_work(fcport->vha, &ea->id);
1499 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1500 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1502 struct qla_work_evt *e;
1503 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1505 return QLA_FUNCTION_FAILED;
1507 e->u.new_sess.id = *id;
1508 e->u.new_sess.pla = pla;
1509 e->u.new_sess.fc4_type = fc4_type;
1510 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1512 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1514 return qla2x00_post_work(vha, e);
1518 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1519 struct event_arg *ea)
1521 fc_port_t *fcport = ea->fcport;
1523 ql_dbg(ql_dbg_disc, vha, 0x2102,
1524 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1525 __func__, fcport->port_name, fcport->disc_state,
1526 fcport->fw_login_state, fcport->login_pause,
1527 fcport->deleted, fcport->conflict,
1528 fcport->last_rscn_gen, fcport->rscn_gen,
1529 fcport->last_login_gen, fcport->login_gen,
1532 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1533 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1536 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1537 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1538 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1543 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1544 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1545 __func__, __LINE__, fcport->port_name);
1550 qla24xx_fcport_handle_login(vha, fcport);
1554 static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1555 struct event_arg *ea)
1557 ql_dbg(ql_dbg_disc, vha, 0x2118,
1558 "%s %d %8phC post PRLI\n",
1559 __func__, __LINE__, ea->fcport->port_name);
1560 qla24xx_post_prli_work(vha, ea->fcport);
1563 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1566 uint32_t id = 0, mask, rid;
1569 switch (ea->event) {
1571 if (test_bit(UNLOADING, &vha->dpc_flags))
1574 qla24xx_handle_relogin_event(vha, ea);
1577 if (test_bit(UNLOADING, &vha->dpc_flags))
1579 switch (ea->id.b.rsvd_1) {
1580 case RSCN_PORT_ADDR:
1582 #if defined BIGSCAN & BIGSCAN > 0
1584 unsigned long flags;
1585 fcport = qla2x00_find_fcport_by_nportid
1588 fcport->scan_needed = 1;
1592 spin_lock_irqsave(&vha->work_lock, flags);
1593 if (vha->scan.scan_flags == 0) {
1594 ql_dbg(ql_dbg_disc, vha, 0xffff,
1595 "%s: schedule\n", __func__);
1596 vha->scan.scan_flags |= SF_QUEUED;
1597 schedule_delayed_work(&vha->scan.scan_work, 5);
1599 spin_unlock_irqrestore(&vha->work_lock, flags);
1604 fcport = qla2x00_find_fcport_by_nportid(vha, &ea->id, 1);
1607 rc = qla24xx_post_gpnid_work(vha, &ea->id);
1609 ql_log(ql_log_warn, vha, 0xd044,
1610 "RSCN GPNID work failed %06x\n",
1614 ea->fcport = fcport;
1615 fcport->scan_needed = 1;
1616 qla24xx_handle_rscn_event(fcport, ea);
1621 case RSCN_AREA_ADDR:
1623 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1625 ql_dbg(ql_dbg_async, vha, 0x5044,
1626 "RSCN: Area 0x%06x was affected\n",
1630 ql_dbg(ql_dbg_async, vha, 0x507a,
1631 "RSCN: Domain 0x%06x was affected\n",
1635 rid = ea->id.b24 & mask;
1636 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1638 id = f->d_id.b24 & mask;
1641 qla24xx_handle_rscn_event(f, ea);
1647 ql_log(ql_log_warn, vha, 0xd045,
1648 "RSCN: Fabric was affected. Addr format %d\n",
1650 qla2x00_mark_all_devices_lost(vha, 1);
1651 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1652 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1656 qla24xx_handle_gnl_done_event(vha, ea);
1658 case FCME_GPSC_DONE:
1659 qla24xx_handle_gpsc_event(vha, ea);
1661 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1662 qla24xx_handle_plogi_done_event(vha, ea);
1664 case FCME_PRLI_DONE:
1665 qla24xx_handle_prli_done_event(vha, ea);
1667 case FCME_GPDB_DONE:
1668 qla24xx_handle_gpdb_event(vha, ea);
1670 case FCME_GPNID_DONE:
1671 qla24xx_handle_gpnid_event(vha, ea);
1673 case FCME_GFFID_DONE:
1674 qla24xx_handle_gffid_event(vha, ea);
1676 case FCME_ADISC_DONE:
1677 qla24xx_handle_adisc_event(vha, ea);
1679 case FCME_GNNID_DONE:
1680 qla24xx_handle_gnnid_event(vha, ea);
1682 case FCME_GFPNID_DONE:
1683 qla24xx_handle_gfpnid_event(vha, ea);
1685 case FCME_ELS_PLOGI_DONE:
1686 qla_handle_els_plogi_done(vha, ea);
1695 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1696 * to be consumed by the fcport
1698 void qla_rscn_replay(fc_port_t *fcport)
1700 struct event_arg ea;
1702 switch (fcport->disc_state) {
1703 case DSC_DELETE_PEND:
1709 if (fcport->scan_needed) {
1710 memset(&ea, 0, sizeof(ea));
1711 ea.event = FCME_RSCN;
1712 ea.id = fcport->d_id;
1713 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1714 #if defined BIGSCAN & BIGSCAN > 0
1715 qla2x00_fcport_event_handler(fcport->vha, &ea);
1717 qla24xx_post_gpnid_work(fcport->vha, &ea.id);
1723 qla2x00_tmf_iocb_timeout(void *data)
1726 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1728 tmf->u.tmf.comp_status = CS_TIMEOUT;
1729 complete(&tmf->u.tmf.comp);
1733 qla2x00_tmf_sp_done(void *ptr, int res)
1736 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1738 complete(&tmf->u.tmf.comp);
1742 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1745 struct scsi_qla_host *vha = fcport->vha;
1746 struct srb_iocb *tm_iocb;
1748 int rval = QLA_FUNCTION_FAILED;
1750 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1754 tm_iocb = &sp->u.iocb_cmd;
1755 sp->type = SRB_TM_CMD;
1758 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1759 init_completion(&tm_iocb->u.tmf.comp);
1760 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1762 tm_iocb->u.tmf.flags = flags;
1763 tm_iocb->u.tmf.lun = lun;
1764 tm_iocb->u.tmf.data = tag;
1765 sp->done = qla2x00_tmf_sp_done;
1767 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1768 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1769 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1770 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1772 rval = qla2x00_start_sp(sp);
1773 if (rval != QLA_SUCCESS)
1775 wait_for_completion(&tm_iocb->u.tmf.comp);
1777 rval = tm_iocb->u.tmf.data;
1779 if (rval != QLA_SUCCESS) {
1780 ql_log(ql_log_warn, vha, 0x8030,
1781 "TM IOCB failed (%x).\n", rval);
1784 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1785 flags = tm_iocb->u.tmf.flags;
1786 lun = (uint16_t)tm_iocb->u.tmf.lun;
1788 /* Issue Marker IOCB */
1789 qla2x00_marker(vha, vha->hw->req_q_map[0],
1790 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1791 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1796 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1802 qla24xx_abort_iocb_timeout(void *data)
1805 struct srb_iocb *abt = &sp->u.iocb_cmd;
1807 abt->u.abt.comp_status = CS_TIMEOUT;
1808 sp->done(sp, QLA_FUNCTION_TIMEOUT);
1812 qla24xx_abort_sp_done(void *ptr, int res)
1815 struct srb_iocb *abt = &sp->u.iocb_cmd;
1817 if (del_timer(&sp->u.iocb_cmd.timer)) {
1818 if (sp->flags & SRB_WAKEUP_ON_COMP)
1819 complete(&abt->u.abt.comp);
1826 qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
1828 scsi_qla_host_t *vha = cmd_sp->vha;
1829 struct srb_iocb *abt_iocb;
1831 int rval = QLA_FUNCTION_FAILED;
1833 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
1838 abt_iocb = &sp->u.iocb_cmd;
1839 sp->type = SRB_ABT_CMD;
1841 sp->qpair = cmd_sp->qpair;
1843 sp->flags = SRB_WAKEUP_ON_COMP;
1845 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1846 init_completion(&abt_iocb->u.abt.comp);
1847 /* FW can send 2 x ABTS's timeout/20s */
1848 qla2x00_init_timer(sp, 42);
1850 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1851 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
1853 sp->done = qla24xx_abort_sp_done;
1855 ql_dbg(ql_dbg_async, vha, 0x507c,
1856 "Abort command issued - hdl=%x, type=%x\n",
1857 cmd_sp->handle, cmd_sp->type);
1859 rval = qla2x00_start_sp(sp);
1860 if (rval != QLA_SUCCESS)
1864 wait_for_completion(&abt_iocb->u.abt.comp);
1865 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1866 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1878 qla24xx_async_abort_command(srb_t *sp)
1880 unsigned long flags = 0;
1883 fc_port_t *fcport = sp->fcport;
1884 struct qla_qpair *qpair = sp->qpair;
1885 struct scsi_qla_host *vha = fcport->vha;
1886 struct req_que *req = qpair->req;
1888 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1889 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1890 if (req->outstanding_cmds[handle] == sp)
1893 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1895 if (handle == req->num_outstanding_cmds) {
1896 /* Command not found. */
1897 return QLA_FUNCTION_FAILED;
1899 if (sp->type == SRB_FXIOCB_DCMD)
1900 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1901 FXDISC_ABORT_IOCTL);
1903 return qla24xx_async_abort_cmd(sp, true);
1907 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1909 switch (ea->data[0]) {
1910 case MBS_COMMAND_COMPLETE:
1911 ql_dbg(ql_dbg_disc, vha, 0x2118,
1912 "%s %d %8phC post gpdb\n",
1913 __func__, __LINE__, ea->fcport->port_name);
1915 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1916 ea->fcport->logout_on_delete = 1;
1917 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1920 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1921 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1922 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1923 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1927 if (ea->fcport->n2n_flag) {
1928 ql_dbg(ql_dbg_disc, vha, 0x2118,
1929 "%s %d %8phC post fc4 prli\n",
1930 __func__, __LINE__, ea->fcport->port_name);
1931 ea->fcport->fc4f_nvme = 0;
1932 ea->fcport->n2n_flag = 0;
1933 qla24xx_post_prli_work(vha, ea->fcport);
1935 ql_dbg(ql_dbg_disc, vha, 0x2119,
1936 "%s %d %8phC unhandle event of %x\n",
1937 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1943 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1945 port_id_t cid; /* conflict Nport id */
1947 struct fc_port *conflict_fcport;
1948 unsigned long flags;
1949 struct fc_port *fcport = ea->fcport;
1951 ql_dbg(ql_dbg_disc, vha, 0xffff,
1952 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1953 __func__, fcport->port_name, fcport->disc_state,
1954 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1955 ea->sp->gen1, fcport->rscn_gen,
1956 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1958 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1959 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1960 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1961 "%s %d %8phC Remote is trying to login\n",
1962 __func__, __LINE__, fcport->port_name);
1966 if (fcport->disc_state == DSC_DELETE_PEND)
1969 if (ea->sp->gen2 != fcport->login_gen) {
1970 /* target side must have changed it. */
1971 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1972 "%s %8phC generation changed\n",
1973 __func__, fcport->port_name);
1974 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1976 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1977 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1978 "%s %8phC RSCN generation changed\n",
1979 __func__, fcport->port_name);
1980 qla_rscn_replay(fcport);
1981 qlt_schedule_sess_for_deletion(fcport);
1985 switch (ea->data[0]) {
1986 case MBS_COMMAND_COMPLETE:
1988 * Driver must validate login state - If PRLI not complete,
1989 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1992 if (ea->fcport->fc4f_nvme) {
1993 ql_dbg(ql_dbg_disc, vha, 0x2117,
1994 "%s %d %8phC post prli\n",
1995 __func__, __LINE__, ea->fcport->port_name);
1996 qla24xx_post_prli_work(vha, ea->fcport);
1998 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1999 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
2000 __func__, __LINE__, ea->fcport->port_name,
2001 ea->fcport->loop_id, ea->fcport->d_id.b24);
2003 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2004 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
2005 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
2006 ea->fcport->logout_on_delete = 1;
2007 ea->fcport->send_els_logo = 0;
2008 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2009 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2011 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2014 case MBS_COMMAND_ERROR:
2015 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2016 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2018 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2019 ea->fcport->disc_state = DSC_LOGIN_FAILED;
2020 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2021 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2023 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2025 case MBS_LOOP_ID_USED:
2026 /* data[1] = IO PARAM 1 = nport ID */
2027 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2028 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2029 cid.b.al_pa = ea->iop[1] & 0xff;
2032 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2033 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2034 __func__, __LINE__, ea->fcport->port_name,
2035 ea->fcport->loop_id, cid.b24);
2037 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2038 ea->fcport->loop_id = FC_NO_LOOP_ID;
2039 qla24xx_post_gnl_work(vha, ea->fcport);
2041 case MBS_PORT_ID_USED:
2042 lid = ea->iop[1] & 0xffff;
2043 qlt_find_sess_invalidate_other(vha,
2044 wwn_to_u64(ea->fcport->port_name),
2045 ea->fcport->d_id, lid, &conflict_fcport);
2047 if (conflict_fcport) {
2049 * Another fcport share the same loop_id/nport id.
2050 * Conflict fcport needs to finish cleanup before this
2051 * fcport can proceed to login.
2053 conflict_fcport->conflict = ea->fcport;
2054 ea->fcport->login_pause = 1;
2056 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2057 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2058 __func__, __LINE__, ea->fcport->port_name,
2059 ea->fcport->d_id.b24, lid);
2061 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2062 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2063 __func__, __LINE__, ea->fcport->port_name,
2064 ea->fcport->d_id.b24, lid);
2066 qla2x00_clear_loop_id(ea->fcport);
2067 set_bit(lid, vha->hw->loop_id_map);
2068 ea->fcport->loop_id = lid;
2069 ea->fcport->keep_nport_handle = 0;
2070 qlt_schedule_sess_for_deletion(ea->fcport);
2078 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2081 qlt_logo_completion_handler(fcport, data[0]);
2082 fcport->login_gen++;
2083 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2087 /****************************************************************************/
2088 /* QLogic ISP2x00 Hardware Support Functions. */
2089 /****************************************************************************/
2092 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2094 int rval = QLA_SUCCESS;
2095 struct qla_hw_data *ha = vha->hw;
2096 uint32_t idc_major_ver, idc_minor_ver;
2099 qla83xx_idc_lock(vha, 0);
2101 /* SV: TODO: Assign initialization timeout from
2102 * flash-info / other param
2104 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2105 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2107 /* Set our fcoe function presence */
2108 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2109 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2110 "Error while setting DRV-Presence.\n");
2111 rval = QLA_FUNCTION_FAILED;
2115 /* Decide the reset ownership */
2116 qla83xx_reset_ownership(vha);
2119 * On first protocol driver load:
2120 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2122 * Others: Check compatibility with current IDC Major version.
2124 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2125 if (ha->flags.nic_core_reset_owner) {
2126 /* Set IDC Major version */
2127 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2128 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2130 /* Clearing IDC-Lock-Recovery register */
2131 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2132 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2134 * Clear further IDC participation if we are not compatible with
2135 * the current IDC Major Version.
2137 ql_log(ql_log_warn, vha, 0xb07d,
2138 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2139 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2140 __qla83xx_clear_drv_presence(vha);
2141 rval = QLA_FUNCTION_FAILED;
2144 /* Each function sets its supported Minor version. */
2145 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2146 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2147 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2149 if (ha->flags.nic_core_reset_owner) {
2150 memset(config, 0, sizeof(config));
2151 if (!qla81xx_get_port_config(vha, config))
2152 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2156 rval = qla83xx_idc_state_handler(vha);
2159 qla83xx_idc_unlock(vha, 0);
2165 * qla2x00_initialize_adapter
2169 * ha = adapter block pointer.
2175 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2178 struct qla_hw_data *ha = vha->hw;
2179 struct req_que *req = ha->req_q_map[0];
2181 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2182 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2184 /* Clear adapter flags. */
2185 vha->flags.online = 0;
2186 ha->flags.chip_reset_done = 0;
2187 vha->flags.reset_active = 0;
2188 ha->flags.pci_channel_io_perm_failure = 0;
2189 ha->flags.eeh_busy = 0;
2190 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2191 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2192 atomic_set(&vha->loop_state, LOOP_DOWN);
2193 vha->device_flags = DFLG_NO_CABLE;
2195 vha->flags.management_server_logged_in = 0;
2196 vha->marker_needed = 0;
2197 ha->isp_abort_cnt = 0;
2198 ha->beacon_blink_led = 0;
2200 set_bit(0, ha->req_qid_map);
2201 set_bit(0, ha->rsp_qid_map);
2203 ql_dbg(ql_dbg_init, vha, 0x0040,
2204 "Configuring PCI space...\n");
2205 rval = ha->isp_ops->pci_config(vha);
2207 ql_log(ql_log_warn, vha, 0x0044,
2208 "Unable to configure PCI space.\n");
2212 ha->isp_ops->reset_chip(vha);
2214 rval = qla2xxx_get_flash_info(vha);
2216 ql_log(ql_log_fatal, vha, 0x004f,
2217 "Unable to validate FLASH data.\n");
2221 if (IS_QLA8044(ha)) {
2222 qla8044_read_reset_template(vha);
2224 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2225 * If DONRESET_BIT0 is set, drivers should not set dev_state
2226 * to NEED_RESET. But if NEED_RESET is set, drivers should
2227 * should honor the reset. */
2228 if (ql2xdontresethba == 1)
2229 qla8044_set_idc_dontreset(vha);
2232 ha->isp_ops->get_flash_version(vha, req->ring);
2233 ql_dbg(ql_dbg_init, vha, 0x0061,
2234 "Configure NVRAM parameters...\n");
2236 ha->isp_ops->nvram_config(vha);
2238 if (ha->flags.disable_serdes) {
2239 /* Mask HBA via NVRAM settings? */
2240 ql_log(ql_log_info, vha, 0x0077,
2241 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2242 return QLA_FUNCTION_FAILED;
2245 ql_dbg(ql_dbg_init, vha, 0x0078,
2246 "Verifying loaded RISC code...\n");
2248 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2249 rval = ha->isp_ops->chip_diag(vha);
2252 rval = qla2x00_setup_chip(vha);
2257 if (IS_QLA84XX(ha)) {
2258 ha->cs84xx = qla84xx_get_chip(vha);
2260 ql_log(ql_log_warn, vha, 0x00d0,
2261 "Unable to configure ISP84XX.\n");
2262 return QLA_FUNCTION_FAILED;
2266 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2267 rval = qla2x00_init_rings(vha);
2269 ha->flags.chip_reset_done = 1;
2271 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2272 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2273 rval = qla84xx_init_chip(vha);
2274 if (rval != QLA_SUCCESS) {
2275 ql_log(ql_log_warn, vha, 0x00d4,
2276 "Unable to initialize ISP84XX.\n");
2277 qla84xx_put_chip(vha);
2281 /* Load the NIC Core f/w if we are the first protocol driver. */
2282 if (IS_QLA8031(ha)) {
2283 rval = qla83xx_nic_core_fw_load(vha);
2285 ql_log(ql_log_warn, vha, 0x0124,
2286 "Error in initializing NIC Core f/w.\n");
2289 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2290 qla24xx_read_fcp_prio_cfg(vha);
2292 if (IS_P3P_TYPE(ha))
2293 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2295 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2301 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2304 * Returns 0 on success.
2307 qla2100_pci_config(scsi_qla_host_t *vha)
2310 unsigned long flags;
2311 struct qla_hw_data *ha = vha->hw;
2312 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2314 pci_set_master(ha->pdev);
2315 pci_try_set_mwi(ha->pdev);
2317 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2318 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2319 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2321 pci_disable_rom(ha->pdev);
2323 /* Get PCI bus information. */
2324 spin_lock_irqsave(&ha->hardware_lock, flags);
2325 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2326 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2332 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2335 * Returns 0 on success.
2338 qla2300_pci_config(scsi_qla_host_t *vha)
2341 unsigned long flags = 0;
2343 struct qla_hw_data *ha = vha->hw;
2344 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2346 pci_set_master(ha->pdev);
2347 pci_try_set_mwi(ha->pdev);
2349 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2350 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2352 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2353 w &= ~PCI_COMMAND_INTX_DISABLE;
2354 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2357 * If this is a 2300 card and not 2312, reset the
2358 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2359 * the 2310 also reports itself as a 2300 so we need to get the
2360 * fb revision level -- a 6 indicates it really is a 2300 and
2363 if (IS_QLA2300(ha)) {
2364 spin_lock_irqsave(&ha->hardware_lock, flags);
2367 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2368 for (cnt = 0; cnt < 30000; cnt++) {
2369 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2375 /* Select FPM registers. */
2376 WRT_REG_WORD(®->ctrl_status, 0x20);
2377 RD_REG_WORD(®->ctrl_status);
2379 /* Get the fb rev level */
2380 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2382 if (ha->fb_rev == FPM_2300)
2383 pci_clear_mwi(ha->pdev);
2385 /* Deselect FPM registers. */
2386 WRT_REG_WORD(®->ctrl_status, 0x0);
2387 RD_REG_WORD(®->ctrl_status);
2389 /* Release RISC module. */
2390 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2391 for (cnt = 0; cnt < 30000; cnt++) {
2392 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2398 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2401 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2403 pci_disable_rom(ha->pdev);
2405 /* Get PCI bus information. */
2406 spin_lock_irqsave(&ha->hardware_lock, flags);
2407 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2408 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2414 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2417 * Returns 0 on success.
2420 qla24xx_pci_config(scsi_qla_host_t *vha)
2423 unsigned long flags = 0;
2424 struct qla_hw_data *ha = vha->hw;
2425 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2427 pci_set_master(ha->pdev);
2428 pci_try_set_mwi(ha->pdev);
2430 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2431 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2432 w &= ~PCI_COMMAND_INTX_DISABLE;
2433 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2435 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2437 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2438 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2439 pcix_set_mmrbc(ha->pdev, 2048);
2441 /* PCIe -- adjust Maximum Read Request Size (2048). */
2442 if (pci_is_pcie(ha->pdev))
2443 pcie_set_readrq(ha->pdev, 4096);
2445 pci_disable_rom(ha->pdev);
2447 ha->chip_revision = ha->pdev->revision;
2449 /* Get PCI bus information. */
2450 spin_lock_irqsave(&ha->hardware_lock, flags);
2451 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2452 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2458 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2461 * Returns 0 on success.
2464 qla25xx_pci_config(scsi_qla_host_t *vha)
2467 struct qla_hw_data *ha = vha->hw;
2469 pci_set_master(ha->pdev);
2470 pci_try_set_mwi(ha->pdev);
2472 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2473 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2474 w &= ~PCI_COMMAND_INTX_DISABLE;
2475 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2477 /* PCIe -- adjust Maximum Read Request Size (2048). */
2478 if (pci_is_pcie(ha->pdev))
2479 pcie_set_readrq(ha->pdev, 4096);
2481 pci_disable_rom(ha->pdev);
2483 ha->chip_revision = ha->pdev->revision;
2489 * qla2x00_isp_firmware() - Choose firmware image.
2492 * Returns 0 on success.
2495 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2498 uint16_t loop_id, topo, sw_cap;
2499 uint8_t domain, area, al_pa;
2500 struct qla_hw_data *ha = vha->hw;
2502 /* Assume loading risc code */
2503 rval = QLA_FUNCTION_FAILED;
2505 if (ha->flags.disable_risc_code_load) {
2506 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2508 /* Verify checksum of loaded RISC code. */
2509 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2510 if (rval == QLA_SUCCESS) {
2511 /* And, verify we are not in ROM code. */
2512 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2513 &area, &domain, &topo, &sw_cap);
2518 ql_dbg(ql_dbg_init, vha, 0x007a,
2519 "**** Load RISC code ****.\n");
2525 * qla2x00_reset_chip() - Reset ISP chip.
2528 * Returns 0 on success.
2531 qla2x00_reset_chip(scsi_qla_host_t *vha)
2533 unsigned long flags = 0;
2534 struct qla_hw_data *ha = vha->hw;
2535 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2539 if (unlikely(pci_channel_offline(ha->pdev)))
2542 ha->isp_ops->disable_intrs(ha);
2544 spin_lock_irqsave(&ha->hardware_lock, flags);
2546 /* Turn off master enable */
2548 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2549 cmd &= ~PCI_COMMAND_MASTER;
2550 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2552 if (!IS_QLA2100(ha)) {
2554 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2555 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2556 for (cnt = 0; cnt < 30000; cnt++) {
2557 if ((RD_REG_WORD(®->hccr) &
2558 HCCR_RISC_PAUSE) != 0)
2563 RD_REG_WORD(®->hccr); /* PCI Posting. */
2567 /* Select FPM registers. */
2568 WRT_REG_WORD(®->ctrl_status, 0x20);
2569 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2571 /* FPM Soft Reset. */
2572 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2573 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2575 /* Toggle Fpm Reset. */
2576 if (!IS_QLA2200(ha)) {
2577 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2578 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2581 /* Select frame buffer registers. */
2582 WRT_REG_WORD(®->ctrl_status, 0x10);
2583 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2585 /* Reset frame buffer FIFOs. */
2586 if (IS_QLA2200(ha)) {
2587 WRT_FB_CMD_REG(ha, reg, 0xa000);
2588 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2590 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2592 /* Read back fb_cmd until zero or 3 seconds max */
2593 for (cnt = 0; cnt < 3000; cnt++) {
2594 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2600 /* Select RISC module registers. */
2601 WRT_REG_WORD(®->ctrl_status, 0);
2602 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2604 /* Reset RISC processor. */
2605 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2606 RD_REG_WORD(®->hccr); /* PCI Posting. */
2608 /* Release RISC processor. */
2609 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2610 RD_REG_WORD(®->hccr); /* PCI Posting. */
2613 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2614 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2616 /* Reset ISP chip. */
2617 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2619 /* Wait for RISC to recover from reset. */
2620 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2622 * It is necessary to for a delay here since the card doesn't
2623 * respond to PCI reads during a reset. On some architectures
2624 * this will result in an MCA.
2627 for (cnt = 30000; cnt; cnt--) {
2628 if ((RD_REG_WORD(®->ctrl_status) &
2629 CSR_ISP_SOFT_RESET) == 0)
2636 /* Reset RISC processor. */
2637 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2639 WRT_REG_WORD(®->semaphore, 0);
2641 /* Release RISC processor. */
2642 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2643 RD_REG_WORD(®->hccr); /* PCI Posting. */
2645 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2646 for (cnt = 0; cnt < 30000; cnt++) {
2647 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2655 /* Turn on master enable */
2656 cmd |= PCI_COMMAND_MASTER;
2657 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2659 /* Disable RISC pause on FPM parity error. */
2660 if (!IS_QLA2100(ha)) {
2661 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2662 RD_REG_WORD(®->hccr); /* PCI Posting. */
2665 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2669 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2672 * Returns 0 on success.
2675 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2677 uint16_t mb[4] = {0x1010, 0, 1, 0};
2679 if (!IS_QLA81XX(vha->hw))
2682 return qla81xx_write_mpi_register(vha, mb);
2686 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2689 * Returns 0 on success.
2692 qla24xx_reset_risc(scsi_qla_host_t *vha)
2694 unsigned long flags = 0;
2695 struct qla_hw_data *ha = vha->hw;
2696 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2699 static int abts_cnt; /* ISP abort retry counts */
2700 int rval = QLA_SUCCESS;
2702 spin_lock_irqsave(&ha->hardware_lock, flags);
2705 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2706 for (cnt = 0; cnt < 30000; cnt++) {
2707 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2713 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2714 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2716 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2717 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2718 RD_REG_DWORD(®->hccr),
2719 RD_REG_DWORD(®->ctrl_status),
2720 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2722 WRT_REG_DWORD(®->ctrl_status,
2723 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2724 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2728 /* Wait for firmware to complete NVRAM accesses. */
2729 RD_REG_WORD(®->mailbox0);
2730 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2731 rval == QLA_SUCCESS; cnt--) {
2736 rval = QLA_FUNCTION_TIMEOUT;
2739 if (rval == QLA_SUCCESS)
2740 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2742 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2743 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2744 RD_REG_DWORD(®->hccr),
2745 RD_REG_DWORD(®->mailbox0));
2747 /* Wait for soft-reset to complete. */
2748 RD_REG_DWORD(®->ctrl_status);
2749 for (cnt = 0; cnt < 60; cnt++) {
2751 if ((RD_REG_DWORD(®->ctrl_status) &
2752 CSRX_ISP_SOFT_RESET) == 0)
2757 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2758 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2760 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2761 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2762 RD_REG_DWORD(®->hccr),
2763 RD_REG_DWORD(®->ctrl_status));
2765 /* If required, do an MPI FW reset now */
2766 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2767 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2768 if (++abts_cnt < 5) {
2769 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2770 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2773 * We exhausted the ISP abort retries. We have to
2774 * set the board offline.
2777 vha->flags.online = 0;
2782 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2783 RD_REG_DWORD(®->hccr);
2785 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2786 RD_REG_DWORD(®->hccr);
2788 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2789 RD_REG_DWORD(®->hccr);
2791 RD_REG_WORD(®->mailbox0);
2792 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2793 rval == QLA_SUCCESS; cnt--) {
2798 rval = QLA_FUNCTION_TIMEOUT;
2800 if (rval == QLA_SUCCESS)
2801 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2803 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2804 "Host Risc 0x%x, mailbox0 0x%x\n",
2805 RD_REG_DWORD(®->hccr),
2806 RD_REG_WORD(®->mailbox0));
2808 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2810 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2811 "Driver in %s mode\n",
2812 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2814 if (IS_NOPOLLING_TYPE(ha))
2815 ha->isp_ops->enable_intrs(ha);
2821 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2823 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2825 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2826 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2831 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2833 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2835 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2836 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2840 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2843 uint delta_msec = 100;
2844 uint elapsed_msec = 0;
2848 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2849 vha->hw->pdev->subsystem_device != 0x0240)
2852 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2856 timeout_msec = TIMEOUT_SEMAPHORE;
2857 n = timeout_msec / delta_msec;
2859 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2860 qla25xx_read_risc_sema_reg(vha, &wd32);
2861 if (wd32 & RISC_SEMAPHORE)
2864 elapsed_msec += delta_msec;
2865 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2869 if (!(wd32 & RISC_SEMAPHORE))
2872 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2875 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2876 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2877 n = timeout_msec / delta_msec;
2879 qla25xx_read_risc_sema_reg(vha, &wd32);
2880 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2883 elapsed_msec += delta_msec;
2884 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2888 if (wd32 & RISC_SEMAPHORE_FORCE)
2889 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2894 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2901 * qla24xx_reset_chip() - Reset ISP24xx chip.
2904 * Returns 0 on success.
2907 qla24xx_reset_chip(scsi_qla_host_t *vha)
2909 struct qla_hw_data *ha = vha->hw;
2911 if (pci_channel_offline(ha->pdev) &&
2912 ha->flags.pci_channel_io_perm_failure) {
2916 ha->isp_ops->disable_intrs(ha);
2918 qla25xx_manipulate_risc_semaphore(vha);
2920 /* Perform RISC reset. */
2921 qla24xx_reset_risc(vha);
2925 * qla2x00_chip_diag() - Test chip for proper operation.
2928 * Returns 0 on success.
2931 qla2x00_chip_diag(scsi_qla_host_t *vha)
2934 struct qla_hw_data *ha = vha->hw;
2935 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2936 unsigned long flags = 0;
2940 struct req_que *req = ha->req_q_map[0];
2942 /* Assume a failed state */
2943 rval = QLA_FUNCTION_FAILED;
2945 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2946 ®->flash_address);
2948 spin_lock_irqsave(&ha->hardware_lock, flags);
2950 /* Reset ISP chip. */
2951 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2954 * We need to have a delay here since the card will not respond while
2955 * in reset causing an MCA on some architectures.
2958 data = qla2x00_debounce_register(®->ctrl_status);
2959 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2961 data = RD_REG_WORD(®->ctrl_status);
2966 goto chip_diag_failed;
2968 ql_dbg(ql_dbg_init, vha, 0x007c,
2969 "Reset register cleared by chip reset.\n");
2971 /* Reset RISC processor. */
2972 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2973 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2975 /* Workaround for QLA2312 PCI parity error */
2976 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2977 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2978 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2980 data = RD_MAILBOX_REG(ha, reg, 0);
2987 goto chip_diag_failed;
2989 /* Check product ID of chip */
2990 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
2992 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2993 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2994 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2995 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2996 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2997 mb[3] != PROD_ID_3) {
2998 ql_log(ql_log_warn, vha, 0x0062,
2999 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3000 mb[1], mb[2], mb[3]);
3002 goto chip_diag_failed;
3004 ha->product_id[0] = mb[1];
3005 ha->product_id[1] = mb[2];
3006 ha->product_id[2] = mb[3];
3007 ha->product_id[3] = mb[4];
3009 /* Adjust fw RISC transfer size */
3010 if (req->length > 1024)
3011 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3013 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3016 if (IS_QLA2200(ha) &&
3017 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3018 /* Limit firmware transfer size with a 2200A */
3019 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3021 ha->device_type |= DT_ISP2200A;
3022 ha->fw_transfer_size = 128;
3025 /* Wrap Incoming Mailboxes Test. */
3026 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3028 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3029 rval = qla2x00_mbx_reg_test(vha);
3031 ql_log(ql_log_warn, vha, 0x0080,
3032 "Failed mailbox send register test.\n");
3034 /* Flag a successful rval */
3036 spin_lock_irqsave(&ha->hardware_lock, flags);
3040 ql_log(ql_log_info, vha, 0x0081,
3041 "Chip diagnostics **** FAILED ****.\n");
3043 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3049 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3052 * Returns 0 on success.
3055 qla24xx_chip_diag(scsi_qla_host_t *vha)
3058 struct qla_hw_data *ha = vha->hw;
3059 struct req_que *req = ha->req_q_map[0];
3061 if (IS_P3P_TYPE(ha))
3064 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3066 rval = qla2x00_mbx_reg_test(vha);
3068 ql_log(ql_log_warn, vha, 0x0082,
3069 "Failed mailbox send register test.\n");
3071 /* Flag a successful rval */
3079 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3084 struct qla_hw_data *ha = vha->hw;
3087 ql_dbg(ql_dbg_init, vha, 0x00bd,
3088 "%s: Offload Mem is already allocated.\n",
3093 if (IS_FWI2_CAPABLE(ha)) {
3094 /* Allocate memory for Fibre Channel Event Buffer. */
3095 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3100 dma_free_coherent(&ha->pdev->dev,
3101 FCE_SIZE, ha->fce, ha->fce_dma);
3103 /* Allocate memory for Fibre Channel Event Buffer. */
3104 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3107 ql_log(ql_log_warn, vha, 0x00be,
3108 "Unable to allocate (%d KB) for FCE.\n",
3113 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3114 ha->fce_mb, &ha->fce_bufs);
3116 ql_log(ql_log_warn, vha, 0x00bf,
3117 "Unable to initialize FCE (%d).\n", rval);
3118 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3120 ha->flags.fce_enabled = 0;
3123 ql_dbg(ql_dbg_init, vha, 0x00c0,
3124 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3126 ha->flags.fce_enabled = 1;
3127 ha->fce_dma = tc_dma;
3132 dma_free_coherent(&ha->pdev->dev,
3133 EFT_SIZE, ha->eft, ha->eft_dma);
3135 /* Allocate memory for Extended Trace Buffer. */
3136 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3139 ql_log(ql_log_warn, vha, 0x00c1,
3140 "Unable to allocate (%d KB) for EFT.\n",
3145 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3147 ql_log(ql_log_warn, vha, 0x00c2,
3148 "Unable to initialize EFT (%d).\n", rval);
3149 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3153 ql_dbg(ql_dbg_init, vha, 0x00c3,
3154 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3156 ha->eft_dma = tc_dma;
3165 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3167 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3168 eft_size, fce_size, mq_size;
3169 struct qla_hw_data *ha = vha->hw;
3170 struct req_que *req = ha->req_q_map[0];
3171 struct rsp_que *rsp = ha->rsp_q_map[0];
3172 struct qla2xxx_fw_dump *fw_dump;
3174 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3175 req_q_size = rsp_q_size = 0;
3177 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3178 fixed_size = sizeof(struct qla2100_fw_dump);
3179 } else if (IS_QLA23XX(ha)) {
3180 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3181 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3183 } else if (IS_FWI2_CAPABLE(ha)) {
3184 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
3185 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3186 else if (IS_QLA81XX(ha))
3187 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3188 else if (IS_QLA25XX(ha))
3189 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3191 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3193 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3196 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
3197 mq_size = sizeof(struct qla2xxx_mq_chain);
3199 * Allocate maximum buffer size for all queues.
3200 * Resizing must be done at end-of-dump processing.
3202 mq_size += ha->max_req_queues *
3203 (req->length * sizeof(request_t));
3204 mq_size += ha->max_rsp_queues *
3205 (rsp->length * sizeof(response_t));
3207 if (ha->tgt.atio_ring)
3208 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3209 /* Allocate memory for Fibre Channel Event Buffer. */
3210 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3214 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3216 ql_dbg(ql_dbg_init, vha, 0x00c3,
3217 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3218 eft_size = EFT_SIZE;
3221 if (IS_QLA27XX(ha)) {
3222 if (!ha->fw_dump_template) {
3223 ql_log(ql_log_warn, vha, 0x00ba,
3224 "Failed missing fwdump template\n");
3227 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
3228 ql_dbg(ql_dbg_init, vha, 0x00fa,
3229 "-> allocating fwdump (%x bytes)...\n", dump_size);
3233 req_q_size = req->length * sizeof(request_t);
3234 rsp_q_size = rsp->length * sizeof(response_t);
3235 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3236 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3237 ha->chain_offset = dump_size;
3238 dump_size += mq_size + fce_size;
3240 if (ha->exchoffld_buf)
3241 dump_size += sizeof(struct qla2xxx_offld_chain) +
3243 if (ha->exlogin_buf)
3244 dump_size += sizeof(struct qla2xxx_offld_chain) +
3248 if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) {
3249 fw_dump = vmalloc(dump_size);
3251 ql_log(ql_log_warn, vha, 0x00c4,
3252 "Unable to allocate (%d KB) for firmware dump.\n",
3257 ha->fw_dump = fw_dump;
3259 ha->fw_dump_len = dump_size;
3260 ql_dbg(ql_dbg_init, vha, 0x00c5,
3261 "Allocated (%d KB) for firmware dump.\n",
3267 ha->fw_dump->signature[0] = 'Q';
3268 ha->fw_dump->signature[1] = 'L';
3269 ha->fw_dump->signature[2] = 'G';
3270 ha->fw_dump->signature[3] = 'C';
3271 ha->fw_dump->version = htonl(1);
3273 ha->fw_dump->fixed_size = htonl(fixed_size);
3274 ha->fw_dump->mem_size = htonl(mem_size);
3275 ha->fw_dump->req_q_size = htonl(req_q_size);
3276 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3278 ha->fw_dump->eft_size = htonl(eft_size);
3279 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
3280 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
3282 ha->fw_dump->header_size =
3283 htonl(offsetof(struct qla2xxx_fw_dump, isp));
3289 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3291 #define MPS_MASK 0xe0
3296 if (!IS_QLA81XX(vha->hw))
3299 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3300 if (rval != QLA_SUCCESS) {
3301 ql_log(ql_log_warn, vha, 0x0105,
3302 "Unable to acquire semaphore.\n");
3306 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3307 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3308 if (rval != QLA_SUCCESS) {
3309 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3314 if (dc == (dw & MPS_MASK))
3319 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3320 if (rval != QLA_SUCCESS) {
3321 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3325 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3326 if (rval != QLA_SUCCESS) {
3327 ql_log(ql_log_warn, vha, 0x006d,
3328 "Unable to release semaphore.\n");
3336 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3338 /* Don't try to reallocate the array */
3339 if (req->outstanding_cmds)
3342 if (!IS_FWI2_CAPABLE(ha))
3343 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3345 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3346 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3348 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3351 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3355 if (!req->outstanding_cmds) {
3357 * Try to allocate a minimal size just so we can get through
3360 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3361 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3365 if (!req->outstanding_cmds) {
3366 ql_log(ql_log_fatal, NULL, 0x0126,
3367 "Failed to allocate memory for "
3368 "outstanding_cmds for req_que %p.\n", req);
3369 req->num_outstanding_cmds = 0;
3370 return QLA_FUNCTION_FAILED;
3377 #define PRINT_FIELD(_field, _flag, _str) { \
3378 if (a0->_field & _flag) {\
3384 len = snprintf(ptr, leftover, "%s", _str); \
3391 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3394 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3395 u8 str[STR_LEN], *ptr, p;
3398 memset(str, 0, STR_LEN);
3399 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3400 ql_dbg(ql_dbg_init, vha, 0x015a,
3401 "SFP MFG Name: %s\n", str);
3403 memset(str, 0, STR_LEN);
3404 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3405 ql_dbg(ql_dbg_init, vha, 0x015c,
3406 "SFP Part Name: %s\n", str);
3409 memset(str, 0, STR_LEN);
3413 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3414 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3415 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3416 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3417 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3418 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3419 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3420 ql_dbg(ql_dbg_init, vha, 0x0160,
3421 "SFP Media: %s\n", str);
3424 memset(str, 0, STR_LEN);
3428 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3429 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3430 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3431 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3432 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3433 ql_dbg(ql_dbg_init, vha, 0x0196,
3434 "SFP Link Length: %s\n", str);
3436 memset(str, 0, STR_LEN);
3440 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3441 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3442 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3443 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3444 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3445 ql_dbg(ql_dbg_init, vha, 0x016e,
3446 "SFP FC Link Tech: %s\n", str);
3449 ql_dbg(ql_dbg_init, vha, 0x016f,
3450 "SFP Distant: %d km\n", a0->length_km);
3451 if (a0->length_100m)
3452 ql_dbg(ql_dbg_init, vha, 0x0170,
3453 "SFP Distant: %d m\n", a0->length_100m*100);
3454 if (a0->length_50um_10m)
3455 ql_dbg(ql_dbg_init, vha, 0x0189,
3456 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3457 if (a0->length_62um_10m)
3458 ql_dbg(ql_dbg_init, vha, 0x018a,
3459 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3460 if (a0->length_om4_10m)
3461 ql_dbg(ql_dbg_init, vha, 0x0194,
3462 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3463 if (a0->length_om3_10m)
3464 ql_dbg(ql_dbg_init, vha, 0x0195,
3465 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3471 * QLA_SUCCESS: no action
3472 * QLA_INTERFACE_ERROR: SFP is not there.
3473 * QLA_FUNCTION_FAILED: detected New SFP
3476 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3478 int rc = QLA_SUCCESS;
3479 struct sff_8247_a0 *a;
3480 struct qla_hw_data *ha = vha->hw;
3482 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3485 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3489 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3490 qla2xxx_print_sfp_info(vha);
3492 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3494 ha->flags.detected_lr_sfp = 1;
3496 if (a->length_km > 5 || a->length_100m > 50)
3497 ha->long_range_distance = LR_DISTANCE_10K;
3499 ha->long_range_distance = LR_DISTANCE_5K;
3501 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3502 ql_dbg(ql_dbg_async, vha, 0x507b,
3503 "Detected Long Range SFP.\n");
3506 ha->flags.detected_lr_sfp = 0;
3507 if (ha->flags.using_lr_setting)
3508 ql_dbg(ql_dbg_async, vha, 0x5084,
3509 "Detected Short Range SFP.\n");
3512 if (!vha->flags.init_done)
3519 * qla2x00_setup_chip() - Load and start RISC firmware.
3522 * Returns 0 on success.
3525 qla2x00_setup_chip(scsi_qla_host_t *vha)
3528 uint32_t srisc_address = 0;
3529 struct qla_hw_data *ha = vha->hw;
3530 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3531 unsigned long flags;
3532 uint16_t fw_major_version;
3534 if (IS_P3P_TYPE(ha)) {
3535 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3536 if (rval == QLA_SUCCESS) {
3537 qla2x00_stop_firmware(vha);
3538 goto enable_82xx_npiv;
3543 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3544 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3545 spin_lock_irqsave(&ha->hardware_lock, flags);
3546 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3547 RD_REG_WORD(®->hccr);
3548 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3551 qla81xx_mpi_sync(vha);
3553 /* Load firmware sequences */
3554 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3555 if (rval == QLA_SUCCESS) {
3556 ql_dbg(ql_dbg_init, vha, 0x00c9,
3557 "Verifying Checksum of loaded RISC code.\n");
3559 rval = qla2x00_verify_checksum(vha, srisc_address);
3560 if (rval == QLA_SUCCESS) {
3561 /* Start firmware execution. */
3562 ql_dbg(ql_dbg_init, vha, 0x00ca,
3563 "Starting firmware.\n");
3566 ha->flags.exlogins_enabled = 1;
3568 if (qla_is_exch_offld_enabled(vha))
3569 ha->flags.exchoffld_enabled = 1;
3571 rval = qla2x00_execute_fw(vha, srisc_address);
3572 /* Retrieve firmware information. */
3573 if (rval == QLA_SUCCESS) {
3574 qla24xx_detect_sfp(vha);
3576 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha)) &&
3577 (ha->zio_mode == QLA_ZIO_MODE_6))
3578 qla27xx_set_zio_threshold(vha,
3579 ha->last_zio_threshold);
3581 rval = qla2x00_set_exlogins_buffer(vha);
3582 if (rval != QLA_SUCCESS)
3585 rval = qla2x00_set_exchoffld_buffer(vha);
3586 if (rval != QLA_SUCCESS)
3590 fw_major_version = ha->fw_major_version;
3591 if (IS_P3P_TYPE(ha))
3592 qla82xx_check_md_needed(vha);
3594 rval = qla2x00_get_fw_version(vha);
3595 if (rval != QLA_SUCCESS)
3597 ha->flags.npiv_supported = 0;
3598 if (IS_QLA2XXX_MIDTYPE(ha) &&
3599 (ha->fw_attributes & BIT_2)) {
3600 ha->flags.npiv_supported = 1;
3601 if ((!ha->max_npiv_vports) ||
3602 ((ha->max_npiv_vports + 1) %
3603 MIN_MULTI_ID_FABRIC))
3604 ha->max_npiv_vports =
3605 MIN_MULTI_ID_FABRIC - 1;
3607 qla2x00_get_resource_cnts(vha);
3610 * Allocate the array of outstanding commands
3611 * now that we know the firmware resources.
3613 rval = qla2x00_alloc_outstanding_cmds(ha,
3615 if (rval != QLA_SUCCESS)
3618 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3619 qla2x00_alloc_offload_mem(vha);
3621 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3622 qla2x00_alloc_fw_dump(vha);
3628 ql_log(ql_log_fatal, vha, 0x00cd,
3629 "ISP Firmware failed checksum.\n");
3635 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3636 /* Enable proper parity. */
3637 spin_lock_irqsave(&ha->hardware_lock, flags);
3640 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3642 /* SRAM, Instruction RAM and GP RAM parity */
3643 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3644 RD_REG_WORD(®->hccr);
3645 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3649 ha->flags.fac_supported = 1;
3650 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3653 rval = qla81xx_fac_get_sector_size(vha, &size);
3654 if (rval == QLA_SUCCESS) {
3655 ha->flags.fac_supported = 1;
3656 ha->fdt_block_size = size << 2;
3658 ql_log(ql_log_warn, vha, 0x00ce,
3659 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3660 ha->fw_major_version, ha->fw_minor_version,
3661 ha->fw_subminor_version);
3663 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3664 ha->flags.fac_supported = 0;
3671 ql_log(ql_log_fatal, vha, 0x00cf,
3672 "Setup chip ****FAILED****.\n");
3679 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3680 * @rsp: response queue
3682 * Beginning of request ring has initialization control block already built
3683 * by nvram config routine.
3685 * Returns 0 on success.
3688 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3693 rsp->ring_ptr = rsp->ring;
3694 rsp->ring_index = 0;
3695 rsp->status_srb = NULL;
3696 pkt = rsp->ring_ptr;
3697 for (cnt = 0; cnt < rsp->length; cnt++) {
3698 pkt->signature = RESPONSE_PROCESSED;
3704 * qla2x00_update_fw_options() - Read and process firmware options.
3707 * Returns 0 on success.
3710 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3712 uint16_t swing, emphasis, tx_sens, rx_sens;
3713 struct qla_hw_data *ha = vha->hw;
3715 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3716 qla2x00_get_fw_options(vha, ha->fw_options);
3718 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3721 /* Serial Link options. */
3722 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3723 "Serial link options.\n");
3724 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3725 (uint8_t *)&ha->fw_seriallink_options,
3726 sizeof(ha->fw_seriallink_options));
3728 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3729 if (ha->fw_seriallink_options[3] & BIT_2) {
3730 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3733 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3734 emphasis = (ha->fw_seriallink_options[2] &
3735 (BIT_4 | BIT_3)) >> 3;
3736 tx_sens = ha->fw_seriallink_options[0] &
3737 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3738 rx_sens = (ha->fw_seriallink_options[0] &
3739 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3740 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3741 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3744 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3745 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3746 ha->fw_options[10] |= BIT_5 |
3747 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3748 (tx_sens & (BIT_1 | BIT_0));
3751 swing = (ha->fw_seriallink_options[2] &
3752 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3753 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3754 tx_sens = ha->fw_seriallink_options[1] &
3755 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3756 rx_sens = (ha->fw_seriallink_options[1] &
3757 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3758 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3759 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3762 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3763 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3764 ha->fw_options[11] |= BIT_5 |
3765 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3766 (tx_sens & (BIT_1 | BIT_0));
3770 /* Return command IOCBs without waiting for an ABTS to complete. */
3771 ha->fw_options[3] |= BIT_13;
3774 if (ha->flags.enable_led_scheme)
3775 ha->fw_options[2] |= BIT_12;
3777 /* Detect ISP6312. */
3779 ha->fw_options[2] |= BIT_13;
3781 /* Set Retry FLOGI in case of P2P connection */
3782 if (ha->operating_mode == P2P) {
3783 ha->fw_options[2] |= BIT_3;
3784 ql_dbg(ql_dbg_disc, vha, 0x2100,
3785 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3786 __func__, ha->fw_options[2]);
3789 /* Update firmware options. */
3790 qla2x00_set_fw_options(vha, ha->fw_options);
3794 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3797 struct qla_hw_data *ha = vha->hw;
3799 if (IS_P3P_TYPE(ha))
3802 /* Hold status IOCBs until ABTS response received. */
3804 ha->fw_options[3] |= BIT_12;
3806 /* Set Retry FLOGI in case of P2P connection */
3807 if (ha->operating_mode == P2P) {
3808 ha->fw_options[2] |= BIT_3;
3809 ql_dbg(ql_dbg_disc, vha, 0x2101,
3810 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3811 __func__, ha->fw_options[2]);
3814 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3815 if (ql2xmvasynctoatio &&
3816 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
3817 if (qla_tgt_mode_enabled(vha) ||
3818 qla_dual_mode_enabled(vha))
3819 ha->fw_options[2] |= BIT_11;
3821 ha->fw_options[2] &= ~BIT_11;
3824 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3826 * Tell FW to track each exchange to prevent
3827 * driver from using stale exchange.
3829 if (qla_tgt_mode_enabled(vha) ||
3830 qla_dual_mode_enabled(vha))
3831 ha->fw_options[2] |= BIT_4;
3833 ha->fw_options[2] &= ~BIT_4;
3835 /* Reserve 1/2 of emergency exchanges for ELS.*/
3836 if (qla2xuseresexchforels)
3837 ha->fw_options[2] |= BIT_8;
3839 ha->fw_options[2] &= ~BIT_8;
3842 ql_dbg(ql_dbg_init, vha, 0x00e8,
3843 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3844 __func__, ha->fw_options[1], ha->fw_options[2],
3845 ha->fw_options[3], vha->host->active_mode);
3847 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3848 qla2x00_set_fw_options(vha, ha->fw_options);
3850 /* Update Serial Link options. */
3851 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3854 rval = qla2x00_set_serdes_params(vha,
3855 le16_to_cpu(ha->fw_seriallink_options24[1]),
3856 le16_to_cpu(ha->fw_seriallink_options24[2]),
3857 le16_to_cpu(ha->fw_seriallink_options24[3]));
3858 if (rval != QLA_SUCCESS) {
3859 ql_log(ql_log_warn, vha, 0x0104,
3860 "Unable to update Serial Link options (%x).\n", rval);
3865 qla2x00_config_rings(struct scsi_qla_host *vha)
3867 struct qla_hw_data *ha = vha->hw;
3868 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3869 struct req_que *req = ha->req_q_map[0];
3870 struct rsp_que *rsp = ha->rsp_q_map[0];
3872 /* Setup ring parameters in initialization control block. */
3873 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3874 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3875 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3876 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3877 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3878 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3879 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3880 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3882 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3883 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3884 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3885 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3886 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3890 qla24xx_config_rings(struct scsi_qla_host *vha)
3892 struct qla_hw_data *ha = vha->hw;
3893 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3894 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3895 struct qla_msix_entry *msix;
3896 struct init_cb_24xx *icb;
3898 struct req_que *req = ha->req_q_map[0];
3899 struct rsp_que *rsp = ha->rsp_q_map[0];
3901 /* Setup ring parameters in initialization control block. */
3902 icb = (struct init_cb_24xx *)ha->init_cb;
3903 icb->request_q_outpointer = cpu_to_le16(0);
3904 icb->response_q_inpointer = cpu_to_le16(0);
3905 icb->request_q_length = cpu_to_le16(req->length);
3906 icb->response_q_length = cpu_to_le16(rsp->length);
3907 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3908 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3909 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3910 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3912 /* Setup ATIO queue dma pointers for target mode */
3913 icb->atio_q_inpointer = cpu_to_le16(0);
3914 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3915 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3916 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3918 if (IS_SHADOW_REG_CAPABLE(ha))
3919 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3921 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3922 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3923 icb->rid = cpu_to_le16(rid);
3924 if (ha->flags.msix_enabled) {
3925 msix = &ha->msix_entries[1];
3926 ql_dbg(ql_dbg_init, vha, 0x0019,
3927 "Registering vector 0x%x for base que.\n",
3929 icb->msix = cpu_to_le16(msix->entry);
3931 /* Use alternate PCI bus number */
3933 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
3934 /* Use alternate PCI devfn */
3936 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
3938 /* Use Disable MSIX Handshake mode for capable adapters */
3939 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3940 (ha->flags.msix_enabled)) {
3941 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
3942 ha->flags.disable_msix_handshake = 1;
3943 ql_dbg(ql_dbg_init, vha, 0x00fe,
3944 "MSIX Handshake Disable Mode turned on.\n");
3946 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
3948 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
3950 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
3951 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
3952 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
3953 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
3955 WRT_REG_DWORD(®->isp24.req_q_in, 0);
3956 WRT_REG_DWORD(®->isp24.req_q_out, 0);
3957 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
3958 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
3960 qlt_24xx_config_rings(vha);
3963 RD_REG_DWORD(&ioreg->hccr);
3967 * qla2x00_init_rings() - Initializes firmware.
3970 * Beginning of request ring has initialization control block already built
3971 * by nvram config routine.
3973 * Returns 0 on success.
3976 qla2x00_init_rings(scsi_qla_host_t *vha)
3979 unsigned long flags = 0;
3981 struct qla_hw_data *ha = vha->hw;
3982 struct req_que *req;
3983 struct rsp_que *rsp;
3984 struct mid_init_cb_24xx *mid_init_cb =
3985 (struct mid_init_cb_24xx *) ha->init_cb;
3987 spin_lock_irqsave(&ha->hardware_lock, flags);
3989 /* Clear outstanding commands array. */
3990 for (que = 0; que < ha->max_req_queues; que++) {
3991 req = ha->req_q_map[que];
3992 if (!req || !test_bit(que, ha->req_qid_map))
3994 req->out_ptr = (void *)(req->ring + req->length);
3996 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
3997 req->outstanding_cmds[cnt] = NULL;
3999 req->current_outstanding_cmd = 1;
4001 /* Initialize firmware. */
4002 req->ring_ptr = req->ring;
4003 req->ring_index = 0;
4004 req->cnt = req->length;
4007 for (que = 0; que < ha->max_rsp_queues; que++) {
4008 rsp = ha->rsp_q_map[que];
4009 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4011 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4013 /* Initialize response queue entries */
4015 qlafx00_init_response_q_entries(rsp);
4017 qla2x00_init_response_q_entries(rsp);
4020 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4021 ha->tgt.atio_ring_index = 0;
4022 /* Initialize ATIO queue entries */
4023 qlt_init_atio_q_entries(vha);
4025 ha->isp_ops->config_rings(vha);
4027 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4029 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4031 if (IS_QLAFX00(ha)) {
4032 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4036 /* Update any ISP specific firmware options before initialization. */
4037 ha->isp_ops->update_fw_options(vha);
4039 if (ha->flags.npiv_supported) {
4040 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4041 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4042 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4045 if (IS_FWI2_CAPABLE(ha)) {
4046 mid_init_cb->options = cpu_to_le16(BIT_1);
4047 mid_init_cb->init_cb.execution_throttle =
4048 cpu_to_le16(ha->cur_fw_xcb_count);
4049 ha->flags.dport_enabled =
4050 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4051 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4052 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4053 /* FA-WWPN Status */
4054 ha->flags.fawwpn_enabled =
4055 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4056 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4057 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4060 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4063 ql_log(ql_log_fatal, vha, 0x00d2,
4064 "Init Firmware **** FAILED ****.\n");
4066 ql_dbg(ql_dbg_init, vha, 0x00d3,
4067 "Init Firmware -- success.\n");
4069 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4076 * qla2x00_fw_ready() - Waits for firmware ready.
4079 * Returns 0 on success.
4082 qla2x00_fw_ready(scsi_qla_host_t *vha)
4085 unsigned long wtime, mtime, cs84xx_time;
4086 uint16_t min_wait; /* Minimum wait time if loop is down */
4087 uint16_t wait_time; /* Wait time if loop is coming ready */
4089 struct qla_hw_data *ha = vha->hw;
4091 if (IS_QLAFX00(vha->hw))
4092 return qlafx00_fw_ready(vha);
4096 /* Time to wait for loop down */
4097 if (IS_P3P_TYPE(ha))
4103 * Firmware should take at most one RATOV to login, plus 5 seconds for
4104 * our own processing.
4106 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4107 wait_time = min_wait;
4110 /* Min wait time if loop down */
4111 mtime = jiffies + (min_wait * HZ);
4113 /* wait time before firmware ready */
4114 wtime = jiffies + (wait_time * HZ);
4116 /* Wait for ISP to finish LIP */
4117 if (!vha->flags.init_done)
4118 ql_log(ql_log_info, vha, 0x801e,
4119 "Waiting for LIP to complete.\n");
4122 memset(state, -1, sizeof(state));
4123 rval = qla2x00_get_firmware_state(vha, state);
4124 if (rval == QLA_SUCCESS) {
4125 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4126 vha->device_flags &= ~DFLG_NO_CABLE;
4128 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4129 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4130 "fw_state=%x 84xx=%x.\n", state[0],
4132 if ((state[2] & FSTATE_LOGGED_IN) &&
4133 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4134 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4135 "Sending verify iocb.\n");
4137 cs84xx_time = jiffies;
4138 rval = qla84xx_init_chip(vha);
4139 if (rval != QLA_SUCCESS) {
4142 "Init chip failed.\n");
4146 /* Add time taken to initialize. */
4147 cs84xx_time = jiffies - cs84xx_time;
4148 wtime += cs84xx_time;
4149 mtime += cs84xx_time;
4150 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4151 "Increasing wait time by %ld. "
4152 "New time %ld.\n", cs84xx_time,
4155 } else if (state[0] == FSTATE_READY) {
4156 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4157 "F/W Ready - OK.\n");
4159 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4160 &ha->login_timeout, &ha->r_a_tov);
4166 rval = QLA_FUNCTION_FAILED;
4168 if (atomic_read(&vha->loop_down_timer) &&
4169 state[0] != FSTATE_READY) {
4170 /* Loop down. Timeout on min_wait for states
4171 * other than Wait for Login.
4173 if (time_after_eq(jiffies, mtime)) {
4174 ql_log(ql_log_info, vha, 0x8038,
4175 "Cable is unplugged...\n");
4177 vha->device_flags |= DFLG_NO_CABLE;
4182 /* Mailbox cmd failed. Timeout on min_wait. */
4183 if (time_after_eq(jiffies, mtime) ||
4184 ha->flags.isp82xx_fw_hung)
4188 if (time_after_eq(jiffies, wtime))
4191 /* Delay for a while */
4195 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4196 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4197 state[1], state[2], state[3], state[4], state[5], jiffies);
4199 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4200 ql_log(ql_log_warn, vha, 0x803b,
4201 "Firmware ready **** FAILED ****.\n");
4208 * qla2x00_configure_hba
4209 * Setup adapter context.
4212 * ha = adapter state pointer.
4221 qla2x00_configure_hba(scsi_qla_host_t *vha)
4230 char connect_type[22];
4231 struct qla_hw_data *ha = vha->hw;
4232 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4234 unsigned long flags;
4236 /* Get host addresses. */
4237 rval = qla2x00_get_adapter_id(vha,
4238 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4239 if (rval != QLA_SUCCESS) {
4240 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4241 IS_CNA_CAPABLE(ha) ||
4242 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4243 ql_dbg(ql_dbg_disc, vha, 0x2008,
4244 "Loop is in a transition state.\n");
4246 ql_log(ql_log_warn, vha, 0x2009,
4247 "Unable to get host loop ID.\n");
4248 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4249 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4250 ql_log(ql_log_warn, vha, 0x1151,
4251 "Doing link init.\n");
4252 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4255 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4261 ql_log(ql_log_info, vha, 0x200a,
4262 "Cannot get topology - retrying.\n");
4263 return (QLA_FUNCTION_FAILED);
4266 vha->loop_id = loop_id;
4269 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4270 ha->operating_mode = LOOP;
4275 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4276 ha->current_topology = ISP_CFG_NL;
4277 strcpy(connect_type, "(Loop)");
4281 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4282 ha->switch_cap = sw_cap;
4283 ha->current_topology = ISP_CFG_FL;
4284 strcpy(connect_type, "(FL_Port)");
4288 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4289 ha->operating_mode = P2P;
4290 ha->current_topology = ISP_CFG_N;
4291 strcpy(connect_type, "(N_Port-to-N_Port)");
4295 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4296 ha->switch_cap = sw_cap;
4297 ha->operating_mode = P2P;
4298 ha->current_topology = ISP_CFG_F;
4299 strcpy(connect_type, "(F_Port)");
4303 ql_dbg(ql_dbg_disc, vha, 0x200f,
4304 "HBA in unknown topology %x, using NL.\n", topo);
4305 ha->current_topology = ISP_CFG_NL;
4306 strcpy(connect_type, "(Loop)");
4310 /* Save Host port and loop ID. */
4311 /* byte order - Big Endian */
4312 id.b.domain = domain;
4316 spin_lock_irqsave(&ha->hardware_lock, flags);
4317 if (!(topo == 2 && ha->flags.n2n_bigger))
4318 qlt_update_host_map(vha, id);
4319 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4321 if (!vha->flags.init_done)
4322 ql_log(ql_log_info, vha, 0x2010,
4323 "Topology - %s, Host Loop address 0x%x.\n",
4324 connect_type, vha->loop_id);
4330 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4335 struct qla_hw_data *ha = vha->hw;
4336 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4337 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4339 if (memcmp(model, BINZERO, len) != 0) {
4340 strncpy(ha->model_number, model, len);
4341 st = en = ha->model_number;
4344 if (*en != 0x20 && *en != 0x00)
4349 index = (ha->pdev->subsystem_device & 0xff);
4351 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4352 index < QLA_MODEL_NAMES)
4353 strncpy(ha->model_desc,
4354 qla2x00_model_name[index * 2 + 1],
4355 sizeof(ha->model_desc) - 1);
4357 index = (ha->pdev->subsystem_device & 0xff);
4359 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4360 index < QLA_MODEL_NAMES) {
4361 strcpy(ha->model_number,
4362 qla2x00_model_name[index * 2]);
4363 strncpy(ha->model_desc,
4364 qla2x00_model_name[index * 2 + 1],
4365 sizeof(ha->model_desc) - 1);
4367 strcpy(ha->model_number, def);
4370 if (IS_FWI2_CAPABLE(ha))
4371 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4372 sizeof(ha->model_desc));
4375 /* On sparc systems, obtain port and node WWN from firmware
4378 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4381 struct qla_hw_data *ha = vha->hw;
4382 struct pci_dev *pdev = ha->pdev;
4383 struct device_node *dp = pci_device_to_OF_node(pdev);
4387 val = of_get_property(dp, "port-wwn", &len);
4388 if (val && len >= WWN_SIZE)
4389 memcpy(nv->port_name, val, WWN_SIZE);
4391 val = of_get_property(dp, "node-wwn", &len);
4392 if (val && len >= WWN_SIZE)
4393 memcpy(nv->node_name, val, WWN_SIZE);
4398 * NVRAM configuration for ISP 2xxx
4401 * ha = adapter block pointer.
4404 * initialization control block in response_ring
4405 * host adapters parameters in host adapter block
4411 qla2x00_nvram_config(scsi_qla_host_t *vha)
4416 uint8_t *dptr1, *dptr2;
4417 struct qla_hw_data *ha = vha->hw;
4418 init_cb_t *icb = ha->init_cb;
4419 nvram_t *nv = ha->nvram;
4420 uint8_t *ptr = ha->nvram;
4421 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4425 /* Determine NVRAM starting address. */
4426 ha->nvram_size = sizeof(nvram_t);
4428 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4429 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4430 ha->nvram_base = 0x80;
4432 /* Get NVRAM data and calculate checksum. */
4433 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4434 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4437 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4438 "Contents of NVRAM.\n");
4439 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4440 (uint8_t *)nv, ha->nvram_size);
4442 /* Bad NVRAM data, set defaults parameters. */
4443 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
4444 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
4445 /* Reset NVRAM data. */
4446 ql_log(ql_log_warn, vha, 0x0064,
4447 "Inconsistent NVRAM "
4448 "detected: checksum=0x%x id=%c version=0x%x.\n",
4449 chksum, nv->id[0], nv->nvram_version);
4450 ql_log(ql_log_warn, vha, 0x0065,
4452 "functioning (yet invalid -- WWPN) defaults.\n");
4455 * Set default initialization control block.
4457 memset(nv, 0, ha->nvram_size);
4458 nv->parameter_block_version = ICB_VERSION;
4460 if (IS_QLA23XX(ha)) {
4461 nv->firmware_options[0] = BIT_2 | BIT_1;
4462 nv->firmware_options[1] = BIT_7 | BIT_5;
4463 nv->add_firmware_options[0] = BIT_5;
4464 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4465 nv->frame_payload_size = 2048;
4466 nv->special_options[1] = BIT_7;
4467 } else if (IS_QLA2200(ha)) {
4468 nv->firmware_options[0] = BIT_2 | BIT_1;
4469 nv->firmware_options[1] = BIT_7 | BIT_5;
4470 nv->add_firmware_options[0] = BIT_5;
4471 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4472 nv->frame_payload_size = 1024;
4473 } else if (IS_QLA2100(ha)) {
4474 nv->firmware_options[0] = BIT_3 | BIT_1;
4475 nv->firmware_options[1] = BIT_5;
4476 nv->frame_payload_size = 1024;
4479 nv->max_iocb_allocation = cpu_to_le16(256);
4480 nv->execution_throttle = cpu_to_le16(16);
4481 nv->retry_count = 8;
4482 nv->retry_delay = 1;
4484 nv->port_name[0] = 33;
4485 nv->port_name[3] = 224;
4486 nv->port_name[4] = 139;
4488 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4490 nv->login_timeout = 4;
4493 * Set default host adapter parameters
4495 nv->host_p[1] = BIT_2;
4496 nv->reset_delay = 5;
4497 nv->port_down_retry_count = 8;
4498 nv->max_luns_per_target = cpu_to_le16(8);
4499 nv->link_down_timeout = 60;
4504 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4506 * The SN2 does not provide BIOS emulation which means you can't change
4507 * potentially bogus BIOS settings. Force the use of default settings
4508 * for link rate and frame size. Hope that the rest of the settings
4511 if (ia64_platform_is("sn2")) {
4512 nv->frame_payload_size = 2048;
4514 nv->special_options[1] = BIT_7;
4518 /* Reset Initialization control block */
4519 memset(icb, 0, ha->init_cb_size);
4522 * Setup driver NVRAM options.
4524 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4525 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4526 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4527 nv->firmware_options[1] &= ~BIT_4;
4529 if (IS_QLA23XX(ha)) {
4530 nv->firmware_options[0] |= BIT_2;
4531 nv->firmware_options[0] &= ~BIT_3;
4532 nv->special_options[0] &= ~BIT_6;
4533 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4535 if (IS_QLA2300(ha)) {
4536 if (ha->fb_rev == FPM_2310) {
4537 strcpy(ha->model_number, "QLA2310");
4539 strcpy(ha->model_number, "QLA2300");
4542 qla2x00_set_model_info(vha, nv->model_number,
4543 sizeof(nv->model_number), "QLA23xx");
4545 } else if (IS_QLA2200(ha)) {
4546 nv->firmware_options[0] |= BIT_2;
4548 * 'Point-to-point preferred, else loop' is not a safe
4549 * connection mode setting.
4551 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4553 /* Force 'loop preferred, else point-to-point'. */
4554 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4555 nv->add_firmware_options[0] |= BIT_5;
4557 strcpy(ha->model_number, "QLA22xx");
4558 } else /*if (IS_QLA2100(ha))*/ {
4559 strcpy(ha->model_number, "QLA2100");
4563 * Copy over NVRAM RISC parameter block to initialization control block.
4565 dptr1 = (uint8_t *)icb;
4566 dptr2 = (uint8_t *)&nv->parameter_block_version;
4567 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4569 *dptr1++ = *dptr2++;
4571 /* Copy 2nd half. */
4572 dptr1 = (uint8_t *)icb->add_firmware_options;
4573 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4575 *dptr1++ = *dptr2++;
4576 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4577 /* Use alternate WWN? */
4578 if (nv->host_p[1] & BIT_7) {
4579 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4580 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4583 /* Prepare nodename */
4584 if ((icb->firmware_options[1] & BIT_6) == 0) {
4586 * Firmware will apply the following mask if the nodename was
4589 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4590 icb->node_name[0] &= 0xF0;
4594 * Set host adapter parameters.
4598 * BIT_7 in the host-parameters section allows for modification to
4599 * internal driver logging.
4601 if (nv->host_p[0] & BIT_7)
4602 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4603 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4604 /* Always load RISC code on non ISP2[12]00 chips. */
4605 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4606 ha->flags.disable_risc_code_load = 0;
4607 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4608 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4609 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4610 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4611 ha->flags.disable_serdes = 0;
4613 ha->operating_mode =
4614 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4616 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4617 sizeof(ha->fw_seriallink_options));
4619 /* save HBA serial number */
4620 ha->serial0 = icb->port_name[5];
4621 ha->serial1 = icb->port_name[6];
4622 ha->serial2 = icb->port_name[7];
4623 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4624 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4626 icb->execution_throttle = cpu_to_le16(0xFFFF);
4628 ha->retry_count = nv->retry_count;
4630 /* Set minimum login_timeout to 4 seconds. */
4631 if (nv->login_timeout != ql2xlogintimeout)
4632 nv->login_timeout = ql2xlogintimeout;
4633 if (nv->login_timeout < 4)
4634 nv->login_timeout = 4;
4635 ha->login_timeout = nv->login_timeout;
4637 /* Set minimum RATOV to 100 tenths of a second. */
4640 ha->loop_reset_delay = nv->reset_delay;
4642 /* Link Down Timeout = 0:
4644 * When Port Down timer expires we will start returning
4645 * I/O's to OS with "DID_NO_CONNECT".
4647 * Link Down Timeout != 0:
4649 * The driver waits for the link to come up after link down
4650 * before returning I/Os to OS with "DID_NO_CONNECT".
4652 if (nv->link_down_timeout == 0) {
4653 ha->loop_down_abort_time =
4654 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4656 ha->link_down_timeout = nv->link_down_timeout;
4657 ha->loop_down_abort_time =
4658 (LOOP_DOWN_TIME - ha->link_down_timeout);
4662 * Need enough time to try and get the port back.
4664 ha->port_down_retry_count = nv->port_down_retry_count;
4665 if (qlport_down_retry)
4666 ha->port_down_retry_count = qlport_down_retry;
4667 /* Set login_retry_count */
4668 ha->login_retry_count = nv->retry_count;
4669 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4670 ha->port_down_retry_count > 3)
4671 ha->login_retry_count = ha->port_down_retry_count;
4672 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4673 ha->login_retry_count = ha->port_down_retry_count;
4674 if (ql2xloginretrycount)
4675 ha->login_retry_count = ql2xloginretrycount;
4677 icb->lun_enables = cpu_to_le16(0);
4678 icb->command_resource_count = 0;
4679 icb->immediate_notify_resource_count = 0;
4680 icb->timeout = cpu_to_le16(0);
4682 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4684 icb->firmware_options[0] &= ~BIT_3;
4685 icb->add_firmware_options[0] &=
4686 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4687 icb->add_firmware_options[0] |= BIT_2;
4688 icb->response_accumulation_timer = 3;
4689 icb->interrupt_delay_timer = 5;
4691 vha->flags.process_response_queue = 1;
4694 if (!vha->flags.init_done) {
4695 ha->zio_mode = icb->add_firmware_options[0] &
4696 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4697 ha->zio_timer = icb->interrupt_delay_timer ?
4698 icb->interrupt_delay_timer: 2;
4700 icb->add_firmware_options[0] &=
4701 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4702 vha->flags.process_response_queue = 0;
4703 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4704 ha->zio_mode = QLA_ZIO_MODE_6;
4706 ql_log(ql_log_info, vha, 0x0068,
4707 "ZIO mode %d enabled; timer delay (%d us).\n",
4708 ha->zio_mode, ha->zio_timer * 100);
4710 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4711 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4712 vha->flags.process_response_queue = 1;
4717 ql_log(ql_log_warn, vha, 0x0069,
4718 "NVRAM configuration failed.\n");
4724 qla2x00_rport_del(void *data)
4726 fc_port_t *fcport = data;
4727 struct fc_rport *rport;
4728 unsigned long flags;
4730 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4731 rport = fcport->drport ? fcport->drport: fcport->rport;
4732 fcport->drport = NULL;
4733 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4735 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4736 "%s %8phN. rport %p roles %x\n",
4737 __func__, fcport->port_name, rport,
4740 fc_remote_port_delete(rport);
4745 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4747 * @flags: allocation flags
4749 * Returns a pointer to the allocated fcport, or NULL, if none available.
4752 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4756 fcport = kzalloc(sizeof(fc_port_t), flags);
4760 /* Setup fcport template structure. */
4762 fcport->port_type = FCT_UNKNOWN;
4763 fcport->loop_id = FC_NO_LOOP_ID;
4764 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4765 fcport->supported_classes = FC_COS_UNSPECIFIED;
4767 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4768 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4770 fcport->disc_state = DSC_DELETED;
4771 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4772 fcport->deleted = QLA_SESS_DELETED;
4773 fcport->login_retry = vha->hw->login_retry_count;
4774 fcport->logout_on_delete = 1;
4776 if (!fcport->ct_desc.ct_sns) {
4777 ql_log(ql_log_warn, vha, 0xd049,
4778 "Failed to allocate ct_sns request.\n");
4782 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4783 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4784 INIT_LIST_HEAD(&fcport->gnl_entry);
4785 INIT_LIST_HEAD(&fcport->list);
4791 qla2x00_free_fcport(fc_port_t *fcport)
4793 if (fcport->ct_desc.ct_sns) {
4794 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4795 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4796 fcport->ct_desc.ct_sns_dma);
4798 fcport->ct_desc.ct_sns = NULL;
4804 * qla2x00_configure_loop
4805 * Updates Fibre Channel Device Database with what is actually on loop.
4808 * ha = adapter block pointer.
4813 * 2 = database was full and device was not configured.
4816 qla2x00_configure_loop(scsi_qla_host_t *vha)
4819 unsigned long flags, save_flags;
4820 struct qla_hw_data *ha = vha->hw;
4823 /* Get Initiator ID */
4824 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4825 rval = qla2x00_configure_hba(vha);
4826 if (rval != QLA_SUCCESS) {
4827 ql_dbg(ql_dbg_disc, vha, 0x2013,
4828 "Unable to configure HBA.\n");
4833 save_flags = flags = vha->dpc_flags;
4834 ql_dbg(ql_dbg_disc, vha, 0x2014,
4835 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4838 * If we have both an RSCN and PORT UPDATE pending then handle them
4839 * both at the same time.
4841 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4842 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4844 qla2x00_get_data_rate(vha);
4846 /* Determine what we need to do */
4847 if (ha->current_topology == ISP_CFG_FL &&
4848 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4850 set_bit(RSCN_UPDATE, &flags);
4852 } else if (ha->current_topology == ISP_CFG_F &&
4853 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4855 set_bit(RSCN_UPDATE, &flags);
4856 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4858 } else if (ha->current_topology == ISP_CFG_N) {
4859 clear_bit(RSCN_UPDATE, &flags);
4860 if (qla_tgt_mode_enabled(vha)) {
4861 /* allow the other side to start the login */
4862 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4863 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4865 } else if (ha->current_topology == ISP_CFG_NL) {
4866 clear_bit(RSCN_UPDATE, &flags);
4867 set_bit(LOCAL_LOOP_UPDATE, &flags);
4868 } else if (!vha->flags.online ||
4869 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4870 set_bit(RSCN_UPDATE, &flags);
4871 set_bit(LOCAL_LOOP_UPDATE, &flags);
4874 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4875 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4876 ql_dbg(ql_dbg_disc, vha, 0x2015,
4877 "Loop resync needed, failing.\n");
4878 rval = QLA_FUNCTION_FAILED;
4880 rval = qla2x00_configure_local_loop(vha);
4883 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4884 if (LOOP_TRANSITION(vha)) {
4885 ql_dbg(ql_dbg_disc, vha, 0x2099,
4886 "Needs RSCN update and loop transition.\n");
4887 rval = QLA_FUNCTION_FAILED;
4890 rval = qla2x00_configure_fabric(vha);
4893 if (rval == QLA_SUCCESS) {
4894 if (atomic_read(&vha->loop_down_timer) ||
4895 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4896 rval = QLA_FUNCTION_FAILED;
4898 atomic_set(&vha->loop_state, LOOP_READY);
4899 ql_dbg(ql_dbg_disc, vha, 0x2069,
4901 ha->flags.fw_init_done = 1;
4904 * Process any ATIO queue entries that came in
4905 * while we weren't online.
4907 if (qla_tgt_mode_enabled(vha) ||
4908 qla_dual_mode_enabled(vha)) {
4909 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
4910 qlt_24xx_process_atio_queue(vha, 0);
4911 spin_unlock_irqrestore(&ha->tgt.atio_lock,
4918 ql_dbg(ql_dbg_disc, vha, 0x206a,
4919 "%s *** FAILED ***.\n", __func__);
4921 ql_dbg(ql_dbg_disc, vha, 0x206b,
4922 "%s: exiting normally.\n", __func__);
4925 /* Restore state if a resync event occurred during processing */
4926 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4927 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
4928 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4929 if (test_bit(RSCN_UPDATE, &save_flags)) {
4930 set_bit(RSCN_UPDATE, &vha->dpc_flags);
4938 * qla2x00_configure_local_loop
4939 * Updates Fibre Channel Device Database with local loop devices.
4942 * ha = adapter block pointer.
4948 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
4953 fc_port_t *fcport, *new_fcport;
4959 uint8_t domain, area, al_pa;
4960 struct qla_hw_data *ha = vha->hw;
4961 unsigned long flags;
4963 /* Inititae N2N login. */
4964 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4968 memset(ha->init_cb, 0, ha->init_cb_size);
4969 sz = min_t(int, sizeof(struct els_plogi_payload),
4971 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
4972 (void *)ha->init_cb, sz);
4973 if (rval == QLA_SUCCESS) {
4974 bp = (uint32_t *)ha->init_cb;
4975 for (i = 0; i < sz/4 ; i++, bp++)
4976 *bp = cpu_to_be32(*bp);
4978 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
4979 sizeof(ha->plogi_els_payld.data));
4980 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4982 ql_dbg(ql_dbg_init, vha, 0x00d1,
4983 "PLOGI ELS param read fail.\n");
4990 entries = MAX_FIBRE_DEVICES_LOOP;
4992 /* Get list of logged in devices. */
4993 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
4994 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
4996 if (rval != QLA_SUCCESS)
4997 goto cleanup_allocation;
4999 ql_dbg(ql_dbg_disc, vha, 0x2011,
5000 "Entries in ID list (%d).\n", entries);
5001 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5002 (uint8_t *)ha->gid_list,
5003 entries * sizeof(struct gid_list_info));
5006 spin_lock_irqsave(&vha->work_lock, flags);
5007 vha->scan.scan_retry++;
5008 spin_unlock_irqrestore(&vha->work_lock, flags);
5010 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5011 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5012 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5015 vha->scan.scan_retry = 0;
5018 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5019 fcport->scan_state = QLA_FCPORT_SCAN;
5022 /* Allocate temporary fcport for any new fcports discovered. */
5023 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5024 if (new_fcport == NULL) {
5025 ql_log(ql_log_warn, vha, 0x2012,
5026 "Memory allocation failed for fcport.\n");
5027 rval = QLA_MEMORY_ALLOC_FAILED;
5028 goto cleanup_allocation;
5030 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5032 /* Add devices to port list. */
5033 id_iter = (char *)ha->gid_list;
5034 for (index = 0; index < entries; index++) {
5035 domain = ((struct gid_list_info *)id_iter)->domain;
5036 area = ((struct gid_list_info *)id_iter)->area;
5037 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
5038 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5039 loop_id = (uint16_t)
5040 ((struct gid_list_info *)id_iter)->loop_id_2100;
5042 loop_id = le16_to_cpu(
5043 ((struct gid_list_info *)id_iter)->loop_id);
5044 id_iter += ha->gid_list_info_size;
5046 /* Bypass reserved domain fields. */
5047 if ((domain & 0xf0) == 0xf0)
5050 /* Bypass if not same domain and area of adapter. */
5051 if (area && domain &&
5052 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
5055 /* Bypass invalid local loop ID. */
5056 if (loop_id > LAST_LOCAL_LOOP_ID)
5059 memset(new_fcport->port_name, 0, WWN_SIZE);
5061 /* Fill in member data. */
5062 new_fcport->d_id.b.domain = domain;
5063 new_fcport->d_id.b.area = area;
5064 new_fcport->d_id.b.al_pa = al_pa;
5065 new_fcport->loop_id = loop_id;
5066 new_fcport->scan_state = QLA_FCPORT_FOUND;
5068 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5069 if (rval2 != QLA_SUCCESS) {
5070 ql_dbg(ql_dbg_disc, vha, 0x2097,
5071 "Failed to retrieve fcport information "
5072 "-- get_port_database=%x, loop_id=0x%04x.\n",
5073 rval2, new_fcport->loop_id);
5074 /* Skip retry if N2N */
5075 if (ha->current_topology != ISP_CFG_N) {
5076 ql_dbg(ql_dbg_disc, vha, 0x2105,
5077 "Scheduling resync.\n");
5078 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5083 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5084 /* Check for matching device in port list. */
5087 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5088 if (memcmp(new_fcport->port_name, fcport->port_name,
5092 fcport->flags &= ~FCF_FABRIC_DEVICE;
5093 fcport->loop_id = new_fcport->loop_id;
5094 fcport->port_type = new_fcport->port_type;
5095 fcport->d_id.b24 = new_fcport->d_id.b24;
5096 memcpy(fcport->node_name, new_fcport->node_name,
5098 fcport->scan_state = QLA_FCPORT_FOUND;
5104 /* New device, add to fcports list. */
5105 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5107 /* Allocate a new replacement fcport. */
5108 fcport = new_fcport;
5110 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5112 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5114 if (new_fcport == NULL) {
5115 ql_log(ql_log_warn, vha, 0xd031,
5116 "Failed to allocate memory for fcport.\n");
5117 rval = QLA_MEMORY_ALLOC_FAILED;
5118 goto cleanup_allocation;
5120 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5121 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5124 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5126 /* Base iIDMA settings on HBA port speed. */
5127 fcport->fp_speed = ha->link_data_rate;
5132 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5133 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5136 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5137 if ((qla_dual_mode_enabled(vha) ||
5138 qla_ini_mode_enabled(vha)) &&
5139 atomic_read(&fcport->state) == FCS_ONLINE) {
5140 qla2x00_mark_device_lost(vha, fcport,
5141 ql2xplogiabsentdevice, 0);
5142 if (fcport->loop_id != FC_NO_LOOP_ID &&
5143 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5144 fcport->port_type != FCT_INITIATOR &&
5145 fcport->port_type != FCT_BROADCAST) {
5146 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5147 "%s %d %8phC post del sess\n",
5151 qlt_schedule_sess_for_deletion(fcport);
5157 if (fcport->scan_state == QLA_FCPORT_FOUND)
5158 qla24xx_fcport_handle_login(vha, fcport);
5164 if (rval != QLA_SUCCESS) {
5165 ql_dbg(ql_dbg_disc, vha, 0x2098,
5166 "Configure local loop error exit: rval=%x.\n", rval);
5173 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5176 uint16_t mb[MAILBOX_REGISTER_COUNT];
5177 struct qla_hw_data *ha = vha->hw;
5179 if (!IS_IIDMA_CAPABLE(ha))
5182 if (atomic_read(&fcport->state) != FCS_ONLINE)
5185 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5186 fcport->fp_speed > ha->link_data_rate ||
5187 !ha->flags.gpsc_supported)
5190 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5192 if (rval != QLA_SUCCESS) {
5193 ql_dbg(ql_dbg_disc, vha, 0x2004,
5194 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5195 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5197 ql_dbg(ql_dbg_disc, vha, 0x2005,
5198 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5199 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5200 fcport->fp_speed, fcport->port_name);
5204 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5206 qla2x00_iidma_fcport(vha, fcport);
5207 qla24xx_update_fcport_fcp_prio(vha, fcport);
5210 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5212 struct qla_work_evt *e;
5214 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5216 return QLA_FUNCTION_FAILED;
5218 e->u.fcport.fcport = fcport;
5219 return qla2x00_post_work(vha, e);
5222 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5224 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5226 struct fc_rport_identifiers rport_ids;
5227 struct fc_rport *rport;
5228 unsigned long flags;
5230 if (atomic_read(&fcport->state) == FCS_ONLINE)
5233 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5234 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5235 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5236 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5237 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5238 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5240 ql_log(ql_log_warn, vha, 0x2006,
5241 "Unable to allocate fc remote port.\n");
5245 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5246 *((fc_port_t **)rport->dd_data) = fcport;
5247 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5249 rport->supported_classes = fcport->supported_classes;
5251 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5252 if (fcport->port_type == FCT_INITIATOR)
5253 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
5254 if (fcport->port_type == FCT_TARGET)
5255 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
5257 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5258 "%s %8phN. rport %p is %s mode\n",
5259 __func__, fcport->port_name, rport,
5260 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
5262 fc_remote_port_rolechg(rport, rport_ids.roles);
5266 * qla2x00_update_fcport
5267 * Updates device on list.
5270 * ha = adapter block pointer.
5271 * fcport = port structure pointer.
5281 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5283 if (IS_SW_RESV_ADDR(fcport->d_id))
5286 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5287 __func__, fcport->port_name);
5289 fcport->disc_state = DSC_UPD_FCPORT;
5290 fcport->login_retry = vha->hw->login_retry_count;
5291 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5292 fcport->deleted = 0;
5293 fcport->logout_on_delete = 1;
5294 fcport->login_retry = vha->hw->login_retry_count;
5295 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5297 switch (vha->hw->current_topology) {
5300 fcport->keep_nport_handle = 1;
5306 qla2x00_iidma_fcport(vha, fcport);
5308 if (fcport->fc4f_nvme) {
5309 qla_nvme_register_remote(vha, fcport);
5310 fcport->disc_state = DSC_LOGIN_COMPLETE;
5311 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5315 qla24xx_update_fcport_fcp_prio(vha, fcport);
5317 switch (vha->host->active_mode) {
5318 case MODE_INITIATOR:
5319 qla2x00_reg_remote_port(vha, fcport);
5322 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5323 !vha->vha_tgt.qla_tgt->tgt_stopped)
5324 qlt_fc_port_added(vha, fcport);
5327 qla2x00_reg_remote_port(vha, fcport);
5328 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5329 !vha->vha_tgt.qla_tgt->tgt_stopped)
5330 qlt_fc_port_added(vha, fcport);
5336 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5338 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5339 if (fcport->id_changed) {
5340 fcport->id_changed = 0;
5341 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5342 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5343 __func__, __LINE__, fcport->port_name,
5345 qla24xx_post_gfpnid_work(vha, fcport);
5347 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5348 "%s %d %8phC post gpsc fcp_cnt %d\n",
5349 __func__, __LINE__, fcport->port_name,
5351 qla24xx_post_gpsc_work(vha, fcport);
5355 fcport->disc_state = DSC_LOGIN_COMPLETE;
5358 void qla_register_fcport_fn(struct work_struct *work)
5360 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5361 u32 rscn_gen = fcport->rscn_gen;
5364 if (IS_SW_RESV_ADDR(fcport->d_id))
5367 qla2x00_update_fcport(fcport->vha, fcport);
5369 if (rscn_gen != fcport->rscn_gen) {
5370 /* RSCN(s) came in while registration */
5371 switch (fcport->next_disc_state) {
5372 case DSC_DELETE_PEND:
5373 qlt_schedule_sess_for_deletion(fcport);
5376 data[0] = data[1] = 0;
5377 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5387 * qla2x00_configure_fabric
5388 * Setup SNS devices with loop ID's.
5391 * ha = adapter block pointer.
5398 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5402 uint16_t mb[MAILBOX_REGISTER_COUNT];
5404 LIST_HEAD(new_fcports);
5405 struct qla_hw_data *ha = vha->hw;
5408 /* If FL port exists, then SNS is present */
5409 if (IS_FWI2_CAPABLE(ha))
5410 loop_id = NPH_F_PORT;
5412 loop_id = SNS_FL_PORT;
5413 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5414 if (rval != QLA_SUCCESS) {
5415 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5416 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5418 vha->device_flags &= ~SWITCH_FOUND;
5419 return (QLA_SUCCESS);
5421 vha->device_flags |= SWITCH_FOUND;
5424 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5425 rval = qla2x00_send_change_request(vha, 0x3, 0);
5426 if (rval != QLA_SUCCESS)
5427 ql_log(ql_log_warn, vha, 0x121,
5428 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5434 qla2x00_mgmt_svr_login(vha);
5437 if (ql2xfdmienable &&
5438 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5439 qla2x00_fdmi_register(vha);
5441 /* Ensure we are logged into the SNS. */
5442 loop_id = NPH_SNS_LID(ha);
5443 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5444 0xfc, mb, BIT_1|BIT_0);
5445 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5446 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5447 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5448 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5449 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5452 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5453 if (qla2x00_rft_id(vha)) {
5455 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5456 "Register FC-4 TYPE failed.\n");
5457 if (test_bit(LOOP_RESYNC_NEEDED,
5461 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5463 ql_dbg(ql_dbg_disc, vha, 0x209a,
5464 "Register FC-4 Features failed.\n");
5465 if (test_bit(LOOP_RESYNC_NEEDED,
5469 if (vha->flags.nvme_enabled) {
5470 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5471 ql_dbg(ql_dbg_disc, vha, 0x2049,
5472 "Register NVME FC Type Features failed.\n");
5475 if (qla2x00_rnn_id(vha)) {
5477 ql_dbg(ql_dbg_disc, vha, 0x2104,
5478 "Register Node Name failed.\n");
5479 if (test_bit(LOOP_RESYNC_NEEDED,
5482 } else if (qla2x00_rsnn_nn(vha)) {
5484 ql_dbg(ql_dbg_disc, vha, 0x209b,
5485 "Register Symbolic Node Name failed.\n");
5486 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5492 /* Mark the time right before querying FW for connected ports.
5493 * This process is long, asynchronous and by the time it's done,
5494 * collected information might not be accurate anymore. E.g.
5495 * disconnected port might have re-connected and a brand new
5496 * session has been created. In this case session's generation
5497 * will be newer than discovery_gen. */
5498 qlt_do_generation_tick(vha, &discovery_gen);
5500 if (USE_ASYNC_SCAN(ha)) {
5501 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5504 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5506 list_for_each_entry(fcport, &vha->vp_fcports, list)
5507 fcport->scan_state = QLA_FCPORT_SCAN;
5509 rval = qla2x00_find_all_fabric_devs(vha);
5511 if (rval != QLA_SUCCESS)
5515 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5516 qla_nvme_register_hba(vha);
5519 ql_dbg(ql_dbg_disc, vha, 0x2068,
5520 "Configure fabric error exit rval=%d.\n", rval);
5526 * qla2x00_find_all_fabric_devs
5529 * ha = adapter block pointer.
5530 * dev = database device entry pointer.
5539 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5543 fc_port_t *fcport, *new_fcport;
5548 int first_dev, last_dev;
5549 port_id_t wrap = {}, nxt_d_id;
5550 struct qla_hw_data *ha = vha->hw;
5551 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5552 unsigned long flags;
5556 /* Try GID_PT to get device list, else GAN. */
5558 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5563 ql_dbg(ql_dbg_disc, vha, 0x209c,
5564 "GID_PT allocations failed, fallback on GA_NXT.\n");
5566 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5567 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5569 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5571 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5573 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5575 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5577 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5579 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5581 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5585 /* If other queries succeeded probe for FC-4 type */
5587 qla2x00_gff_id(vha, swl);
5588 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5594 /* Allocate temporary fcport for any new fcports discovered. */
5595 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5596 if (new_fcport == NULL) {
5597 ql_log(ql_log_warn, vha, 0x209d,
5598 "Failed to allocate memory for fcport.\n");
5599 return (QLA_MEMORY_ALLOC_FAILED);
5601 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5602 /* Set start port ID scan at adapter ID. */
5606 /* Starting free loop ID. */
5607 loop_id = ha->min_external_loopid;
5608 for (; loop_id <= ha->max_loop_id; loop_id++) {
5609 if (qla2x00_is_reserved_id(vha, loop_id))
5612 if (ha->current_topology == ISP_CFG_FL &&
5613 (atomic_read(&vha->loop_down_timer) ||
5614 LOOP_TRANSITION(vha))) {
5615 atomic_set(&vha->loop_down_timer, 0);
5616 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5617 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5623 wrap.b24 = new_fcport->d_id.b24;
5625 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5626 memcpy(new_fcport->node_name,
5627 swl[swl_idx].node_name, WWN_SIZE);
5628 memcpy(new_fcport->port_name,
5629 swl[swl_idx].port_name, WWN_SIZE);
5630 memcpy(new_fcport->fabric_port_name,
5631 swl[swl_idx].fabric_port_name, WWN_SIZE);
5632 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5633 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5635 new_fcport->nvme_flag = 0;
5636 new_fcport->fc4f_nvme = 0;
5637 if (vha->flags.nvme_enabled &&
5638 swl[swl_idx].fc4f_nvme) {
5639 new_fcport->fc4f_nvme =
5640 swl[swl_idx].fc4f_nvme;
5641 ql_log(ql_log_info, vha, 0x2131,
5642 "FOUND: NVME port %8phC as FC Type 28h\n",
5643 new_fcport->port_name);
5646 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5652 /* Send GA_NXT to the switch */
5653 rval = qla2x00_ga_nxt(vha, new_fcport);
5654 if (rval != QLA_SUCCESS) {
5655 ql_log(ql_log_warn, vha, 0x209e,
5656 "SNS scan failed -- assuming "
5657 "zero-entry result.\n");
5663 /* If wrap on switch device list, exit. */
5665 wrap.b24 = new_fcport->d_id.b24;
5667 } else if (new_fcport->d_id.b24 == wrap.b24) {
5668 ql_dbg(ql_dbg_disc, vha, 0x209f,
5669 "Device wrap (%02x%02x%02x).\n",
5670 new_fcport->d_id.b.domain,
5671 new_fcport->d_id.b.area,
5672 new_fcport->d_id.b.al_pa);
5676 /* Bypass if same physical adapter. */
5677 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5680 /* Bypass virtual ports of the same host. */
5681 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5684 /* Bypass if same domain and area of adapter. */
5685 if (((new_fcport->d_id.b24 & 0xffff00) ==
5686 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5690 /* Bypass reserved domain fields. */
5691 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5694 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5695 if (ql2xgffidenable &&
5696 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5697 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5700 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5702 /* Locate matching device in database. */
5704 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5705 if (memcmp(new_fcport->port_name, fcport->port_name,
5709 fcport->scan_state = QLA_FCPORT_FOUND;
5713 /* Update port state. */
5714 memcpy(fcport->fabric_port_name,
5715 new_fcport->fabric_port_name, WWN_SIZE);
5716 fcport->fp_speed = new_fcport->fp_speed;
5719 * If address the same and state FCS_ONLINE
5720 * (or in target mode), nothing changed.
5722 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5723 (atomic_read(&fcport->state) == FCS_ONLINE ||
5724 (vha->host->active_mode == MODE_TARGET))) {
5729 * If device was not a fabric device before.
5731 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5732 fcport->d_id.b24 = new_fcport->d_id.b24;
5733 qla2x00_clear_loop_id(fcport);
5734 fcport->flags |= (FCF_FABRIC_DEVICE |
5740 * Port ID changed or device was marked to be updated;
5741 * Log it out if still logged in and mark it for
5744 if (qla_tgt_mode_enabled(base_vha)) {
5745 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5746 "port changed FC ID, %8phC"
5747 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5749 fcport->d_id.b.domain,
5750 fcport->d_id.b.area,
5751 fcport->d_id.b.al_pa,
5753 new_fcport->d_id.b.domain,
5754 new_fcport->d_id.b.area,
5755 new_fcport->d_id.b.al_pa);
5756 fcport->d_id.b24 = new_fcport->d_id.b24;
5760 fcport->d_id.b24 = new_fcport->d_id.b24;
5761 fcport->flags |= FCF_LOGIN_NEEDED;
5765 if (fcport->fc4f_nvme) {
5766 if (fcport->disc_state == DSC_DELETE_PEND) {
5767 fcport->disc_state = DSC_GNL;
5768 vha->fcport_count--;
5769 fcport->login_succ = 0;
5774 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5777 /* If device was not in our fcports list, then add it. */
5778 new_fcport->scan_state = QLA_FCPORT_FOUND;
5779 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5781 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5784 /* Allocate a new replacement fcport. */
5785 nxt_d_id.b24 = new_fcport->d_id.b24;
5786 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5787 if (new_fcport == NULL) {
5788 ql_log(ql_log_warn, vha, 0xd032,
5789 "Memory allocation failed for fcport.\n");
5790 return (QLA_MEMORY_ALLOC_FAILED);
5792 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5793 new_fcport->d_id.b24 = nxt_d_id.b24;
5796 qla2x00_free_fcport(new_fcport);
5799 * Logout all previous fabric dev marked lost, except FCP2 devices.
5801 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5802 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5805 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5806 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5809 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5810 if ((qla_dual_mode_enabled(vha) ||
5811 qla_ini_mode_enabled(vha)) &&
5812 atomic_read(&fcport->state) == FCS_ONLINE) {
5813 qla2x00_mark_device_lost(vha, fcport,
5814 ql2xplogiabsentdevice, 0);
5815 if (fcport->loop_id != FC_NO_LOOP_ID &&
5816 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5817 fcport->port_type != FCT_INITIATOR &&
5818 fcport->port_type != FCT_BROADCAST) {
5819 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5820 "%s %d %8phC post del sess\n",
5823 qlt_schedule_sess_for_deletion(fcport);
5829 if (fcport->scan_state == QLA_FCPORT_FOUND)
5830 qla24xx_fcport_handle_login(vha, fcport);
5836 * qla2x00_find_new_loop_id
5837 * Scan through our port list and find a new usable loop ID.
5840 * ha: adapter state pointer.
5841 * dev: port structure pointer.
5844 * qla2x00 local function return status code.
5850 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
5853 struct qla_hw_data *ha = vha->hw;
5854 unsigned long flags = 0;
5858 spin_lock_irqsave(&ha->vport_slock, flags);
5860 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5862 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5863 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5864 dev->loop_id = FC_NO_LOOP_ID;
5865 rval = QLA_FUNCTION_FAILED;
5867 set_bit(dev->loop_id, ha->loop_id_map);
5869 spin_unlock_irqrestore(&ha->vport_slock, flags);
5871 if (rval == QLA_SUCCESS)
5872 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5873 "Assigning new loopid=%x, portid=%x.\n",
5874 dev->loop_id, dev->d_id.b24);
5876 ql_log(ql_log_warn, dev->vha, 0x2087,
5877 "No loop_id's available, portid=%x.\n",
5884 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5886 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5888 int loop_id = FC_NO_LOOP_ID;
5889 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5890 unsigned long flags;
5891 struct qla_hw_data *ha = vha->hw;
5893 if (vha->vp_idx == 0) {
5894 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5895 return NPH_MGMT_SERVER;
5898 /* pick id from high and work down to low */
5899 spin_lock_irqsave(&ha->vport_slock, flags);
5900 for (; lid > 0; lid--) {
5901 if (!test_bit(lid, vha->hw->loop_id_map)) {
5902 set_bit(lid, vha->hw->loop_id_map);
5907 spin_unlock_irqrestore(&ha->vport_slock, flags);
5913 * qla2x00_fabric_login
5914 * Issue fabric login command.
5917 * ha = adapter block pointer.
5918 * device = pointer to FC device type structure.
5921 * 0 - Login successfully
5923 * 2 - Initiator device
5927 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5928 uint16_t *next_loopid)
5932 uint16_t tmp_loopid;
5933 uint16_t mb[MAILBOX_REGISTER_COUNT];
5934 struct qla_hw_data *ha = vha->hw;
5940 ql_dbg(ql_dbg_disc, vha, 0x2000,
5941 "Trying Fabric Login w/loop id 0x%04x for port "
5943 fcport->loop_id, fcport->d_id.b.domain,
5944 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5946 /* Login fcport on switch. */
5947 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
5948 fcport->d_id.b.domain, fcport->d_id.b.area,
5949 fcport->d_id.b.al_pa, mb, BIT_0);
5950 if (rval != QLA_SUCCESS) {
5953 if (mb[0] == MBS_PORT_ID_USED) {
5955 * Device has another loop ID. The firmware team
5956 * recommends the driver perform an implicit login with
5957 * the specified ID again. The ID we just used is save
5958 * here so we return with an ID that can be tried by
5962 tmp_loopid = fcport->loop_id;
5963 fcport->loop_id = mb[1];
5965 ql_dbg(ql_dbg_disc, vha, 0x2001,
5966 "Fabric Login: port in use - next loop "
5967 "id=0x%04x, port id= %02x%02x%02x.\n",
5968 fcport->loop_id, fcport->d_id.b.domain,
5969 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5971 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5976 /* A retry occurred before. */
5977 *next_loopid = tmp_loopid;
5980 * No retry occurred before. Just increment the
5981 * ID value for next login.
5983 *next_loopid = (fcport->loop_id + 1);
5986 if (mb[1] & BIT_0) {
5987 fcport->port_type = FCT_INITIATOR;
5989 fcport->port_type = FCT_TARGET;
5990 if (mb[1] & BIT_1) {
5991 fcport->flags |= FCF_FCP2_DEVICE;
5996 fcport->supported_classes |= FC_COS_CLASS2;
5998 fcport->supported_classes |= FC_COS_CLASS3;
6000 if (IS_FWI2_CAPABLE(ha)) {
6003 FCF_CONF_COMP_SUPPORTED;
6008 } else if (mb[0] == MBS_LOOP_ID_USED) {
6010 * Loop ID already used, try next loop ID.
6013 rval = qla2x00_find_new_loop_id(vha, fcport);
6014 if (rval != QLA_SUCCESS) {
6015 /* Ran out of loop IDs to use */
6018 } else if (mb[0] == MBS_COMMAND_ERROR) {
6020 * Firmware possibly timed out during login. If NO
6021 * retries are left to do then the device is declared
6024 *next_loopid = fcport->loop_id;
6025 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6026 fcport->d_id.b.domain, fcport->d_id.b.area,
6027 fcport->d_id.b.al_pa);
6028 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6034 * unrecoverable / not handled error
6036 ql_dbg(ql_dbg_disc, vha, 0x2002,
6037 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6038 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6039 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6040 fcport->loop_id, jiffies);
6042 *next_loopid = fcport->loop_id;
6043 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6044 fcport->d_id.b.domain, fcport->d_id.b.area,
6045 fcport->d_id.b.al_pa);
6046 qla2x00_clear_loop_id(fcport);
6047 fcport->login_retry = 0;
6058 * qla2x00_local_device_login
6059 * Issue local device login command.
6062 * ha = adapter block pointer.
6063 * loop_id = loop id of device to login to.
6065 * Returns (Where's the #define!!!!):
6066 * 0 - Login successfully
6071 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6074 uint16_t mb[MAILBOX_REGISTER_COUNT];
6076 memset(mb, 0, sizeof(mb));
6077 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6078 if (rval == QLA_SUCCESS) {
6079 /* Interrogate mailbox registers for any errors */
6080 if (mb[0] == MBS_COMMAND_ERROR)
6082 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6083 /* device not in PCB table */
6091 * qla2x00_loop_resync
6092 * Resync with fibre channel devices.
6095 * ha = adapter block pointer.
6101 qla2x00_loop_resync(scsi_qla_host_t *vha)
6103 int rval = QLA_SUCCESS;
6105 struct req_que *req;
6106 struct rsp_que *rsp;
6111 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6112 if (vha->flags.online) {
6113 if (!(rval = qla2x00_fw_ready(vha))) {
6114 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6117 if (!IS_QLAFX00(vha->hw)) {
6119 * Issue a marker after FW becomes
6122 qla2x00_marker(vha, req, rsp, 0, 0,
6124 vha->marker_needed = 0;
6127 /* Remap devices on Loop. */
6128 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6130 if (IS_QLAFX00(vha->hw))
6131 qlafx00_configure_devices(vha);
6133 qla2x00_configure_loop(vha);
6136 } while (!atomic_read(&vha->loop_down_timer) &&
6137 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6138 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6143 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6144 return (QLA_FUNCTION_FAILED);
6147 ql_dbg(ql_dbg_disc, vha, 0x206c,
6148 "%s *** FAILED ***.\n", __func__);
6154 * qla2x00_perform_loop_resync
6155 * Description: This function will set the appropriate flags and call
6156 * qla2x00_loop_resync. If successful loop will be resynced
6157 * Arguments : scsi_qla_host_t pointer
6158 * returm : Success or Failure
6161 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6165 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6166 /*Configure the flags so that resync happens properly*/
6167 atomic_set(&ha->loop_down_timer, 0);
6168 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6169 atomic_set(&ha->loop_state, LOOP_UP);
6170 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6171 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6172 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6174 rval = qla2x00_loop_resync(ha);
6176 atomic_set(&ha->loop_state, LOOP_DEAD);
6178 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6185 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6188 struct scsi_qla_host *vha;
6189 struct qla_hw_data *ha = base_vha->hw;
6190 unsigned long flags;
6192 spin_lock_irqsave(&ha->vport_slock, flags);
6193 /* Go with deferred removal of rport references. */
6194 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6195 atomic_inc(&vha->vref_count);
6196 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6197 if (fcport->drport &&
6198 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6199 spin_unlock_irqrestore(&ha->vport_slock, flags);
6200 qla2x00_rport_del(fcport);
6202 spin_lock_irqsave(&ha->vport_slock, flags);
6205 atomic_dec(&vha->vref_count);
6206 wake_up(&vha->vref_waitq);
6208 spin_unlock_irqrestore(&ha->vport_slock, flags);
6211 /* Assumes idc_lock always held on entry */
6213 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6215 struct qla_hw_data *ha = vha->hw;
6216 uint32_t drv_presence, drv_presence_mask;
6217 uint32_t dev_part_info1, dev_part_info2, class_type;
6218 uint32_t class_type_mask = 0x3;
6219 uint16_t fcoe_other_function = 0xffff, i;
6221 if (IS_QLA8044(ha)) {
6222 drv_presence = qla8044_rd_direct(vha,
6223 QLA8044_CRB_DRV_ACTIVE_INDEX);
6224 dev_part_info1 = qla8044_rd_direct(vha,
6225 QLA8044_CRB_DEV_PART_INFO_INDEX);
6226 dev_part_info2 = qla8044_rd_direct(vha,
6227 QLA8044_CRB_DEV_PART_INFO2);
6229 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6230 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6231 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6233 for (i = 0; i < 8; i++) {
6234 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6235 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6236 (i != ha->portnum)) {
6237 fcoe_other_function = i;
6241 if (fcoe_other_function == 0xffff) {
6242 for (i = 0; i < 8; i++) {
6243 class_type = ((dev_part_info2 >> (i * 4)) &
6245 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6246 ((i + 8) != ha->portnum)) {
6247 fcoe_other_function = i + 8;
6253 * Prepare drv-presence mask based on fcoe functions present.
6254 * However consider only valid physical fcoe function numbers (0-15).
6256 drv_presence_mask = ~((1 << (ha->portnum)) |
6257 ((fcoe_other_function == 0xffff) ?
6258 0 : (1 << (fcoe_other_function))));
6260 /* We are the reset owner iff:
6261 * - No other protocol drivers present.
6262 * - This is the lowest among fcoe functions. */
6263 if (!(drv_presence & drv_presence_mask) &&
6264 (ha->portnum < fcoe_other_function)) {
6265 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6266 "This host is Reset owner.\n");
6267 ha->flags.nic_core_reset_owner = 1;
6272 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6274 int rval = QLA_SUCCESS;
6275 struct qla_hw_data *ha = vha->hw;
6278 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6279 if (rval == QLA_SUCCESS) {
6280 drv_ack |= (1 << ha->portnum);
6281 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6288 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6290 int rval = QLA_SUCCESS;
6291 struct qla_hw_data *ha = vha->hw;
6294 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6295 if (rval == QLA_SUCCESS) {
6296 drv_ack &= ~(1 << ha->portnum);
6297 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6304 qla83xx_dev_state_to_string(uint32_t dev_state)
6306 switch (dev_state) {
6307 case QLA8XXX_DEV_COLD:
6308 return "COLD/RE-INIT";
6309 case QLA8XXX_DEV_INITIALIZING:
6310 return "INITIALIZING";
6311 case QLA8XXX_DEV_READY:
6313 case QLA8XXX_DEV_NEED_RESET:
6314 return "NEED RESET";
6315 case QLA8XXX_DEV_NEED_QUIESCENT:
6316 return "NEED QUIESCENT";
6317 case QLA8XXX_DEV_FAILED:
6319 case QLA8XXX_DEV_QUIESCENT:
6326 /* Assumes idc-lock always held on entry */
6328 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6330 struct qla_hw_data *ha = vha->hw;
6331 uint32_t idc_audit_reg = 0, duration_secs = 0;
6333 switch (audit_type) {
6334 case IDC_AUDIT_TIMESTAMP:
6335 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6336 idc_audit_reg = (ha->portnum) |
6337 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6338 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6341 case IDC_AUDIT_COMPLETION:
6342 duration_secs = ((jiffies_to_msecs(jiffies) -
6343 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6344 idc_audit_reg = (ha->portnum) |
6345 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6346 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6350 ql_log(ql_log_warn, vha, 0xb078,
6351 "Invalid audit type specified.\n");
6356 /* Assumes idc_lock always held on entry */
6358 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6360 struct qla_hw_data *ha = vha->hw;
6361 uint32_t idc_control, dev_state;
6363 __qla83xx_get_idc_control(vha, &idc_control);
6364 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6365 ql_log(ql_log_info, vha, 0xb080,
6366 "NIC Core reset has been disabled. idc-control=0x%x\n",
6368 return QLA_FUNCTION_FAILED;
6371 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6372 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6373 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6374 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6375 QLA8XXX_DEV_NEED_RESET);
6376 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6377 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6379 const char *state = qla83xx_dev_state_to_string(dev_state);
6380 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6382 /* SV: XXX: Is timeout required here? */
6383 /* Wait for IDC state change READY -> NEED_RESET */
6384 while (dev_state == QLA8XXX_DEV_READY) {
6385 qla83xx_idc_unlock(vha, 0);
6387 qla83xx_idc_lock(vha, 0);
6388 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6392 /* Send IDC ack by writing to drv-ack register */
6393 __qla83xx_set_drv_ack(vha);
6399 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6401 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6405 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6407 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6411 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6413 uint32_t drv_presence = 0;
6414 struct qla_hw_data *ha = vha->hw;
6416 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6417 if (drv_presence & (1 << ha->portnum))
6420 return QLA_TEST_FAILED;
6424 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6426 int rval = QLA_SUCCESS;
6427 struct qla_hw_data *ha = vha->hw;
6429 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6430 "Entered %s().\n", __func__);
6432 if (vha->device_flags & DFLG_DEV_FAILED) {
6433 ql_log(ql_log_warn, vha, 0xb059,
6434 "Device in unrecoverable FAILED state.\n");
6435 return QLA_FUNCTION_FAILED;
6438 qla83xx_idc_lock(vha, 0);
6440 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6441 ql_log(ql_log_warn, vha, 0xb05a,
6442 "Function=0x%x has been removed from IDC participation.\n",
6444 rval = QLA_FUNCTION_FAILED;
6448 qla83xx_reset_ownership(vha);
6450 rval = qla83xx_initiating_reset(vha);
6453 * Perform reset if we are the reset-owner,
6454 * else wait till IDC state changes to READY/FAILED.
6456 if (rval == QLA_SUCCESS) {
6457 rval = qla83xx_idc_state_handler(vha);
6459 if (rval == QLA_SUCCESS)
6460 ha->flags.nic_core_hung = 0;
6461 __qla83xx_clear_drv_ack(vha);
6465 qla83xx_idc_unlock(vha, 0);
6467 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6473 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6475 struct qla_hw_data *ha = vha->hw;
6476 int rval = QLA_FUNCTION_FAILED;
6478 if (!IS_MCTP_CAPABLE(ha)) {
6479 /* This message can be removed from the final version */
6480 ql_log(ql_log_info, vha, 0x506d,
6481 "This board is not MCTP capable\n");
6485 if (!ha->mctp_dump) {
6486 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6487 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6489 if (!ha->mctp_dump) {
6490 ql_log(ql_log_warn, vha, 0x506e,
6491 "Failed to allocate memory for mctp dump\n");
6496 #define MCTP_DUMP_STR_ADDR 0x00000000
6497 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6498 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6499 if (rval != QLA_SUCCESS) {
6500 ql_log(ql_log_warn, vha, 0x506f,
6501 "Failed to capture mctp dump\n");
6503 ql_log(ql_log_info, vha, 0x5070,
6504 "Mctp dump capture for host (%ld/%p).\n",
6505 vha->host_no, ha->mctp_dump);
6506 ha->mctp_dumped = 1;
6509 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6510 ha->flags.nic_core_reset_hdlr_active = 1;
6511 rval = qla83xx_restart_nic_firmware(vha);
6513 /* NIC Core reset failed. */
6514 ql_log(ql_log_warn, vha, 0x5071,
6515 "Failed to restart nic firmware\n");
6517 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6518 "Restarted NIC firmware successfully.\n");
6519 ha->flags.nic_core_reset_hdlr_active = 0;
6527 * qla2x00_quiesce_io
6528 * Description: This function will block the new I/Os
6529 * Its not aborting any I/Os as context
6530 * is not destroyed during quiescence
6531 * Arguments: scsi_qla_host_t
6535 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6537 struct qla_hw_data *ha = vha->hw;
6538 struct scsi_qla_host *vp;
6540 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6541 "Quiescing I/O - ha=%p.\n", ha);
6543 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6544 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6545 atomic_set(&vha->loop_state, LOOP_DOWN);
6546 qla2x00_mark_all_devices_lost(vha, 0);
6547 list_for_each_entry(vp, &ha->vp_list, list)
6548 qla2x00_mark_all_devices_lost(vp, 0);
6550 if (!atomic_read(&vha->loop_down_timer))
6551 atomic_set(&vha->loop_down_timer,
6554 /* Wait for pending cmds to complete */
6555 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6559 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6561 struct qla_hw_data *ha = vha->hw;
6562 struct scsi_qla_host *vp;
6563 unsigned long flags;
6567 /* For ISP82XX, driver waits for completion of the commands.
6568 * online flag should be set.
6570 if (!(IS_P3P_TYPE(ha)))
6571 vha->flags.online = 0;
6572 ha->flags.chip_reset_done = 0;
6573 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6574 vha->qla_stats.total_isp_aborts++;
6576 ql_log(ql_log_info, vha, 0x00af,
6577 "Performing ISP error recovery - ha=%p.\n", ha);
6579 ha->flags.purge_mbox = 1;
6580 /* For ISP82XX, reset_chip is just disabling interrupts.
6581 * Driver waits for the completion of the commands.
6582 * the interrupts need to be enabled.
6584 if (!(IS_P3P_TYPE(ha)))
6585 ha->isp_ops->reset_chip(vha);
6587 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6589 ha->flags.rida_fmt2 = 0;
6590 ha->flags.n2n_ae = 0;
6591 ha->flags.lip_ae = 0;
6592 ha->current_topology = 0;
6593 ha->flags.fw_started = 0;
6594 ha->flags.fw_init_done = 0;
6596 ha->base_qpair->chip_reset = ha->chip_reset;
6597 for (i = 0; i < ha->max_qpairs; i++) {
6598 if (ha->queue_pair_map[i])
6599 ha->queue_pair_map[i]->chip_reset =
6600 ha->base_qpair->chip_reset;
6603 /* purge MBox commands */
6604 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6605 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6606 complete(&ha->mbx_intr_comp);
6610 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6611 atomic_read(&ha->num_pend_mbx_stage2) ||
6612 atomic_read(&ha->num_pend_mbx_stage1)) {
6618 ha->flags.purge_mbox = 0;
6620 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6621 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6622 atomic_set(&vha->loop_state, LOOP_DOWN);
6623 qla2x00_mark_all_devices_lost(vha, 0);
6625 spin_lock_irqsave(&ha->vport_slock, flags);
6626 list_for_each_entry(vp, &ha->vp_list, list) {
6627 atomic_inc(&vp->vref_count);
6628 spin_unlock_irqrestore(&ha->vport_slock, flags);
6630 qla2x00_mark_all_devices_lost(vp, 0);
6632 spin_lock_irqsave(&ha->vport_slock, flags);
6633 atomic_dec(&vp->vref_count);
6635 spin_unlock_irqrestore(&ha->vport_slock, flags);
6637 if (!atomic_read(&vha->loop_down_timer))
6638 atomic_set(&vha->loop_down_timer,
6642 /* Clear all async request states across all VPs. */
6643 list_for_each_entry(fcport, &vha->vp_fcports, list)
6644 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6645 spin_lock_irqsave(&ha->vport_slock, flags);
6646 list_for_each_entry(vp, &ha->vp_list, list) {
6647 atomic_inc(&vp->vref_count);
6648 spin_unlock_irqrestore(&ha->vport_slock, flags);
6650 list_for_each_entry(fcport, &vp->vp_fcports, list)
6651 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6653 spin_lock_irqsave(&ha->vport_slock, flags);
6654 atomic_dec(&vp->vref_count);
6656 spin_unlock_irqrestore(&ha->vport_slock, flags);
6658 if (!ha->flags.eeh_busy) {
6659 /* Make sure for ISP 82XX IO DMA is complete */
6660 if (IS_P3P_TYPE(ha)) {
6661 qla82xx_chip_reset_cleanup(vha);
6662 ql_log(ql_log_info, vha, 0x00b4,
6663 "Done chip reset cleanup.\n");
6665 /* Done waiting for pending commands.
6666 * Reset the online flag.
6668 vha->flags.online = 0;
6671 /* Requeue all commands in outstanding command list. */
6672 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6674 /* memory barrier */
6680 * Resets ISP and aborts all outstanding commands.
6683 * ha = adapter block pointer.
6689 qla2x00_abort_isp(scsi_qla_host_t *vha)
6693 struct qla_hw_data *ha = vha->hw;
6694 struct scsi_qla_host *vp;
6695 struct req_que *req = ha->req_q_map[0];
6696 unsigned long flags;
6698 if (vha->flags.online) {
6699 qla2x00_abort_isp_cleanup(vha);
6701 if (IS_QLA8031(ha)) {
6702 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6703 "Clearing fcoe driver presence.\n");
6704 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6705 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6706 "Error while clearing DRV-Presence.\n");
6709 if (unlikely(pci_channel_offline(ha->pdev) &&
6710 ha->flags.pci_channel_io_perm_failure)) {
6711 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6716 switch (vha->qlini_mode) {
6717 case QLA2XXX_INI_MODE_DISABLED:
6718 if (!qla_tgt_mode_enabled(vha))
6721 case QLA2XXX_INI_MODE_DUAL:
6722 if (!qla_dual_mode_enabled(vha))
6725 case QLA2XXX_INI_MODE_ENABLED:
6730 ha->isp_ops->get_flash_version(vha, req->ring);
6732 ha->isp_ops->nvram_config(vha);
6734 if (!qla2x00_restart_isp(vha)) {
6735 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6737 if (!atomic_read(&vha->loop_down_timer)) {
6739 * Issue marker command only when we are going
6740 * to start the I/O .
6742 vha->marker_needed = 1;
6745 vha->flags.online = 1;
6747 ha->isp_ops->enable_intrs(ha);
6749 ha->isp_abort_cnt = 0;
6750 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6752 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6753 qla2x00_get_fw_version(vha);
6755 ha->flags.fce_enabled = 1;
6757 fce_calc_size(ha->fce_bufs));
6758 rval = qla2x00_enable_fce_trace(vha,
6759 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6762 ql_log(ql_log_warn, vha, 0x8033,
6763 "Unable to reinitialize FCE "
6765 ha->flags.fce_enabled = 0;
6770 memset(ha->eft, 0, EFT_SIZE);
6771 rval = qla2x00_enable_eft_trace(vha,
6772 ha->eft_dma, EFT_NUM_BUFFERS);
6774 ql_log(ql_log_warn, vha, 0x8034,
6775 "Unable to reinitialize EFT "
6779 } else { /* failed the ISP abort */
6780 vha->flags.online = 1;
6781 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6782 if (ha->isp_abort_cnt == 0) {
6783 ql_log(ql_log_fatal, vha, 0x8035,
6784 "ISP error recover failed - "
6785 "board disabled.\n");
6787 * The next call disables the board
6790 qla2x00_abort_isp_cleanup(vha);
6791 vha->flags.online = 0;
6792 clear_bit(ISP_ABORT_RETRY,
6795 } else { /* schedule another ISP abort */
6796 ha->isp_abort_cnt--;
6797 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6798 "ISP abort - retry remaining %d.\n",
6803 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6804 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6805 "ISP error recovery - retrying (%d) "
6806 "more times.\n", ha->isp_abort_cnt);
6807 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6815 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6816 qla2x00_configure_hba(vha);
6817 spin_lock_irqsave(&ha->vport_slock, flags);
6818 list_for_each_entry(vp, &ha->vp_list, list) {
6820 atomic_inc(&vp->vref_count);
6821 spin_unlock_irqrestore(&ha->vport_slock, flags);
6823 qla2x00_vp_abort_isp(vp);
6825 spin_lock_irqsave(&ha->vport_slock, flags);
6826 atomic_dec(&vp->vref_count);
6829 spin_unlock_irqrestore(&ha->vport_slock, flags);
6831 if (IS_QLA8031(ha)) {
6832 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6833 "Setting back fcoe driver presence.\n");
6834 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6835 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6836 "Error while setting DRV-Presence.\n");
6839 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6847 * qla2x00_restart_isp
6848 * restarts the ISP after a reset
6851 * ha = adapter block pointer.
6857 qla2x00_restart_isp(scsi_qla_host_t *vha)
6860 struct qla_hw_data *ha = vha->hw;
6861 struct req_que *req = ha->req_q_map[0];
6862 struct rsp_que *rsp = ha->rsp_q_map[0];
6864 /* If firmware needs to be loaded */
6865 if (qla2x00_isp_firmware(vha)) {
6866 vha->flags.online = 0;
6867 status = ha->isp_ops->chip_diag(vha);
6869 status = qla2x00_setup_chip(vha);
6872 if (!status && !(status = qla2x00_init_rings(vha))) {
6873 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6874 ha->flags.chip_reset_done = 1;
6876 /* Initialize the queues in use */
6877 qla25xx_init_queues(ha);
6879 status = qla2x00_fw_ready(vha);
6881 /* Issue a marker after FW becomes ready. */
6882 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6883 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6886 /* if no cable then assume it's good */
6887 if ((vha->device_flags & DFLG_NO_CABLE))
6894 qla25xx_init_queues(struct qla_hw_data *ha)
6896 struct rsp_que *rsp = NULL;
6897 struct req_que *req = NULL;
6898 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6902 for (i = 1; i < ha->max_rsp_queues; i++) {
6903 rsp = ha->rsp_q_map[i];
6904 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6905 rsp->options &= ~BIT_0;
6906 ret = qla25xx_init_rsp_que(base_vha, rsp);
6907 if (ret != QLA_SUCCESS)
6908 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6909 "%s Rsp que: %d init failed.\n",
6912 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6913 "%s Rsp que: %d inited.\n",
6917 for (i = 1; i < ha->max_req_queues; i++) {
6918 req = ha->req_q_map[i];
6919 if (req && test_bit(i, ha->req_qid_map)) {
6920 /* Clear outstanding commands array. */
6921 req->options &= ~BIT_0;
6922 ret = qla25xx_init_req_que(base_vha, req);
6923 if (ret != QLA_SUCCESS)
6924 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6925 "%s Req que: %d init failed.\n",
6928 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6929 "%s Req que: %d inited.\n",
6937 * qla2x00_reset_adapter
6941 * ha = adapter block pointer.
6944 qla2x00_reset_adapter(scsi_qla_host_t *vha)
6946 unsigned long flags = 0;
6947 struct qla_hw_data *ha = vha->hw;
6948 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6950 vha->flags.online = 0;
6951 ha->isp_ops->disable_intrs(ha);
6953 spin_lock_irqsave(&ha->hardware_lock, flags);
6954 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
6955 RD_REG_WORD(®->hccr); /* PCI Posting. */
6956 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
6957 RD_REG_WORD(®->hccr); /* PCI Posting. */
6958 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6962 qla24xx_reset_adapter(scsi_qla_host_t *vha)
6964 unsigned long flags = 0;
6965 struct qla_hw_data *ha = vha->hw;
6966 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6968 if (IS_P3P_TYPE(ha))
6971 vha->flags.online = 0;
6972 ha->isp_ops->disable_intrs(ha);
6974 spin_lock_irqsave(&ha->hardware_lock, flags);
6975 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
6976 RD_REG_DWORD(®->hccr);
6977 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
6978 RD_REG_DWORD(®->hccr);
6979 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6981 if (IS_NOPOLLING_TYPE(ha))
6982 ha->isp_ops->enable_intrs(ha);
6985 /* On sparc systems, obtain port and node WWN from firmware
6988 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6989 struct nvram_24xx *nv)
6992 struct qla_hw_data *ha = vha->hw;
6993 struct pci_dev *pdev = ha->pdev;
6994 struct device_node *dp = pci_device_to_OF_node(pdev);
6998 val = of_get_property(dp, "port-wwn", &len);
6999 if (val && len >= WWN_SIZE)
7000 memcpy(nv->port_name, val, WWN_SIZE);
7002 val = of_get_property(dp, "node-wwn", &len);
7003 if (val && len >= WWN_SIZE)
7004 memcpy(nv->node_name, val, WWN_SIZE);
7009 qla24xx_nvram_config(scsi_qla_host_t *vha)
7012 struct init_cb_24xx *icb;
7013 struct nvram_24xx *nv;
7015 uint8_t *dptr1, *dptr2;
7018 struct qla_hw_data *ha = vha->hw;
7021 icb = (struct init_cb_24xx *)ha->init_cb;
7024 /* Determine NVRAM starting address. */
7025 if (ha->port_no == 0) {
7026 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7027 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7029 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7030 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7033 ha->nvram_size = sizeof(struct nvram_24xx);
7034 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7036 /* Get VPD data into cache */
7037 ha->vpd = ha->nvram + VPD_OFFSET;
7038 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
7039 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7041 /* Get NVRAM data into cache and calculate checksum. */
7042 dptr = (uint32_t *)nv;
7043 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
7045 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7046 chksum += le32_to_cpu(*dptr);
7048 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7049 "Contents of NVRAM\n");
7050 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7051 (uint8_t *)nv, ha->nvram_size);
7053 /* Bad NVRAM data, set defaults parameters. */
7054 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7055 || nv->id[3] != ' ' ||
7056 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
7057 /* Reset NVRAM data. */
7058 ql_log(ql_log_warn, vha, 0x006b,
7059 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7060 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
7061 ql_log(ql_log_warn, vha, 0x006c,
7062 "Falling back to functioning (yet invalid -- WWPN) "
7066 * Set default initialization control block.
7068 memset(nv, 0, ha->nvram_size);
7069 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7070 nv->version = cpu_to_le16(ICB_VERSION);
7071 nv->frame_payload_size = 2048;
7072 nv->execution_throttle = cpu_to_le16(0xFFFF);
7073 nv->exchange_count = cpu_to_le16(0);
7074 nv->hard_address = cpu_to_le16(124);
7075 nv->port_name[0] = 0x21;
7076 nv->port_name[1] = 0x00 + ha->port_no + 1;
7077 nv->port_name[2] = 0x00;
7078 nv->port_name[3] = 0xe0;
7079 nv->port_name[4] = 0x8b;
7080 nv->port_name[5] = 0x1c;
7081 nv->port_name[6] = 0x55;
7082 nv->port_name[7] = 0x86;
7083 nv->node_name[0] = 0x20;
7084 nv->node_name[1] = 0x00;
7085 nv->node_name[2] = 0x00;
7086 nv->node_name[3] = 0xe0;
7087 nv->node_name[4] = 0x8b;
7088 nv->node_name[5] = 0x1c;
7089 nv->node_name[6] = 0x55;
7090 nv->node_name[7] = 0x86;
7091 qla24xx_nvram_wwn_from_ofw(vha, nv);
7092 nv->login_retry_count = cpu_to_le16(8);
7093 nv->interrupt_delay_timer = cpu_to_le16(0);
7094 nv->login_timeout = cpu_to_le16(0);
7095 nv->firmware_options_1 =
7096 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7097 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7098 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7099 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7100 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7101 nv->efi_parameters = cpu_to_le32(0);
7102 nv->reset_delay = 5;
7103 nv->max_luns_per_target = cpu_to_le16(128);
7104 nv->port_down_retry_count = cpu_to_le16(30);
7105 nv->link_down_timeout = cpu_to_le16(30);
7110 if (qla_tgt_mode_enabled(vha)) {
7111 /* Don't enable full login after initial LIP */
7112 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7113 /* Don't enable LIP full login for initiator */
7114 nv->host_p &= cpu_to_le32(~BIT_10);
7117 qlt_24xx_config_nvram_stage1(vha, nv);
7119 /* Reset Initialization control block */
7120 memset(icb, 0, ha->init_cb_size);
7122 /* Copy 1st segment. */
7123 dptr1 = (uint8_t *)icb;
7124 dptr2 = (uint8_t *)&nv->version;
7125 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7127 *dptr1++ = *dptr2++;
7129 icb->login_retry_count = nv->login_retry_count;
7130 icb->link_down_on_nos = nv->link_down_on_nos;
7132 /* Copy 2nd segment. */
7133 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7134 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7135 cnt = (uint8_t *)&icb->reserved_3 -
7136 (uint8_t *)&icb->interrupt_delay_timer;
7138 *dptr1++ = *dptr2++;
7139 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7141 * Setup driver NVRAM options.
7143 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7146 qlt_24xx_config_nvram_stage2(vha, icb);
7148 if (nv->host_p & cpu_to_le32(BIT_15)) {
7149 /* Use alternate WWN? */
7150 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7151 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7154 /* Prepare nodename */
7155 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7157 * Firmware will apply the following mask if the nodename was
7160 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7161 icb->node_name[0] &= 0xF0;
7164 /* Set host adapter parameters. */
7165 ha->flags.disable_risc_code_load = 0;
7166 ha->flags.enable_lip_reset = 0;
7167 ha->flags.enable_lip_full_login =
7168 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7169 ha->flags.enable_target_reset =
7170 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7171 ha->flags.enable_led_scheme = 0;
7172 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7174 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7175 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7177 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7178 sizeof(ha->fw_seriallink_options24));
7180 /* save HBA serial number */
7181 ha->serial0 = icb->port_name[5];
7182 ha->serial1 = icb->port_name[6];
7183 ha->serial2 = icb->port_name[7];
7184 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7185 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7187 icb->execution_throttle = cpu_to_le16(0xFFFF);
7189 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7191 /* Set minimum login_timeout to 4 seconds. */
7192 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7193 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7194 if (le16_to_cpu(nv->login_timeout) < 4)
7195 nv->login_timeout = cpu_to_le16(4);
7196 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7198 /* Set minimum RATOV to 100 tenths of a second. */
7201 ha->loop_reset_delay = nv->reset_delay;
7203 /* Link Down Timeout = 0:
7205 * When Port Down timer expires we will start returning
7206 * I/O's to OS with "DID_NO_CONNECT".
7208 * Link Down Timeout != 0:
7210 * The driver waits for the link to come up after link down
7211 * before returning I/Os to OS with "DID_NO_CONNECT".
7213 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7214 ha->loop_down_abort_time =
7215 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7217 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7218 ha->loop_down_abort_time =
7219 (LOOP_DOWN_TIME - ha->link_down_timeout);
7222 /* Need enough time to try and get the port back. */
7223 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7224 if (qlport_down_retry)
7225 ha->port_down_retry_count = qlport_down_retry;
7227 /* Set login_retry_count */
7228 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7229 if (ha->port_down_retry_count ==
7230 le16_to_cpu(nv->port_down_retry_count) &&
7231 ha->port_down_retry_count > 3)
7232 ha->login_retry_count = ha->port_down_retry_count;
7233 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7234 ha->login_retry_count = ha->port_down_retry_count;
7235 if (ql2xloginretrycount)
7236 ha->login_retry_count = ql2xloginretrycount;
7238 /* N2N: driver will initiate Login instead of FW */
7239 icb->firmware_options_3 |= BIT_8;
7242 if (!vha->flags.init_done) {
7243 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7244 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7245 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7246 le16_to_cpu(icb->interrupt_delay_timer): 2;
7248 icb->firmware_options_2 &= cpu_to_le32(
7249 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7250 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7251 ha->zio_mode = QLA_ZIO_MODE_6;
7253 ql_log(ql_log_info, vha, 0x006f,
7254 "ZIO mode %d enabled; timer delay (%d us).\n",
7255 ha->zio_mode, ha->zio_timer * 100);
7257 icb->firmware_options_2 |= cpu_to_le32(
7258 (uint32_t)ha->zio_mode);
7259 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7263 ql_log(ql_log_warn, vha, 0x0070,
7264 "NVRAM configuration failed.\n");
7269 uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
7271 struct qla27xx_image_status pri_image_status, sec_image_status;
7272 uint8_t valid_pri_image, valid_sec_image;
7274 uint32_t cnt, chksum, size;
7275 struct qla_hw_data *ha = vha->hw;
7277 valid_pri_image = valid_sec_image = 1;
7278 ha->active_image = 0;
7279 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
7281 if (!ha->flt_region_img_status_pri) {
7282 valid_pri_image = 0;
7283 goto check_sec_image;
7286 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
7287 ha->flt_region_img_status_pri, size);
7289 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7290 ql_dbg(ql_dbg_init, vha, 0x018b,
7291 "Primary image signature (0x%x) not valid\n",
7292 pri_image_status.signature);
7293 valid_pri_image = 0;
7294 goto check_sec_image;
7297 wptr = (uint32_t *)(&pri_image_status);
7300 for (chksum = 0; cnt--; wptr++)
7301 chksum += le32_to_cpu(*wptr);
7304 ql_dbg(ql_dbg_init, vha, 0x018c,
7305 "Checksum validation failed for primary image (0x%x)\n",
7307 valid_pri_image = 0;
7311 if (!ha->flt_region_img_status_sec) {
7312 valid_sec_image = 0;
7313 goto check_valid_image;
7316 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7317 ha->flt_region_img_status_sec, size);
7319 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7320 ql_dbg(ql_dbg_init, vha, 0x018d,
7321 "Secondary image signature(0x%x) not valid\n",
7322 sec_image_status.signature);
7323 valid_sec_image = 0;
7324 goto check_valid_image;
7327 wptr = (uint32_t *)(&sec_image_status);
7329 for (chksum = 0; cnt--; wptr++)
7330 chksum += le32_to_cpu(*wptr);
7332 ql_dbg(ql_dbg_init, vha, 0x018e,
7333 "Checksum validation failed for secondary image (0x%x)\n",
7335 valid_sec_image = 0;
7339 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
7340 ha->active_image = QLA27XX_PRIMARY_IMAGE;
7341 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
7342 if (!ha->active_image ||
7343 pri_image_status.generation_number <
7344 sec_image_status.generation_number)
7345 ha->active_image = QLA27XX_SECONDARY_IMAGE;
7348 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x018f, "%s image\n",
7349 ha->active_image == 0 ? "default bootld and fw" :
7350 ha->active_image == 1 ? "primary" :
7351 ha->active_image == 2 ? "secondary" :
7354 return ha->active_image;
7358 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7361 int rval = QLA_SUCCESS;
7362 int segments, fragment;
7363 uint32_t *dcode, dlen;
7367 struct qla_hw_data *ha = vha->hw;
7368 struct req_que *req = ha->req_q_map[0];
7370 ql_dbg(ql_dbg_init, vha, 0x008b,
7371 "FW: Loading firmware from flash (%x).\n", faddr);
7375 segments = FA_RISC_CODE_SEGMENTS;
7376 dcode = (uint32_t *)req->ring;
7379 if (IS_QLA27XX(ha) &&
7380 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
7381 faddr = ha->flt_region_fw_sec;
7383 /* Validate firmware image by checking version. */
7384 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
7385 for (i = 0; i < 4; i++)
7386 dcode[i] = be32_to_cpu(dcode[i]);
7387 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7388 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7389 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7391 ql_log(ql_log_fatal, vha, 0x008c,
7392 "Unable to verify the integrity of flash firmware "
7394 ql_log(ql_log_fatal, vha, 0x008d,
7395 "Firmware data: %08x %08x %08x %08x.\n",
7396 dcode[0], dcode[1], dcode[2], dcode[3]);
7398 return QLA_FUNCTION_FAILED;
7401 while (segments && rval == QLA_SUCCESS) {
7402 /* Read segment's load information. */
7403 qla24xx_read_flash_data(vha, dcode, faddr, 4);
7405 risc_addr = be32_to_cpu(dcode[2]);
7406 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7407 risc_size = be32_to_cpu(dcode[3]);
7410 while (risc_size > 0 && rval == QLA_SUCCESS) {
7411 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7412 if (dlen > risc_size)
7415 ql_dbg(ql_dbg_init, vha, 0x008e,
7416 "Loading risc segment@ risc addr %x "
7417 "number of dwords 0x%x offset 0x%x.\n",
7418 risc_addr, dlen, faddr);
7420 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7421 for (i = 0; i < dlen; i++)
7422 dcode[i] = swab32(dcode[i]);
7424 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7427 ql_log(ql_log_fatal, vha, 0x008f,
7428 "Failed to load segment %d of firmware.\n",
7430 return QLA_FUNCTION_FAILED;
7443 if (!IS_QLA27XX(ha))
7446 if (ha->fw_dump_template)
7447 vfree(ha->fw_dump_template);
7448 ha->fw_dump_template = NULL;
7449 ha->fw_dump_template_len = 0;
7451 ql_dbg(ql_dbg_init, vha, 0x0161,
7452 "Loading fwdump template from %x\n", faddr);
7453 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7454 risc_size = be32_to_cpu(dcode[2]);
7455 ql_dbg(ql_dbg_init, vha, 0x0162,
7456 "-> array size %x dwords\n", risc_size);
7457 if (risc_size == 0 || risc_size == ~0)
7458 goto default_template;
7460 dlen = (risc_size - 8) * sizeof(*dcode);
7461 ql_dbg(ql_dbg_init, vha, 0x0163,
7462 "-> template allocating %x bytes...\n", dlen);
7463 ha->fw_dump_template = vmalloc(dlen);
7464 if (!ha->fw_dump_template) {
7465 ql_log(ql_log_warn, vha, 0x0164,
7466 "Failed fwdump template allocate %x bytes.\n", risc_size);
7467 goto default_template;
7472 dcode = ha->fw_dump_template;
7473 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7474 for (i = 0; i < risc_size; i++)
7475 dcode[i] = le32_to_cpu(dcode[i]);
7477 if (!qla27xx_fwdt_template_valid(dcode)) {
7478 ql_log(ql_log_warn, vha, 0x0165,
7479 "Failed fwdump template validate\n");
7480 goto default_template;
7483 dlen = qla27xx_fwdt_template_size(dcode);
7484 ql_dbg(ql_dbg_init, vha, 0x0166,
7485 "-> template size %x bytes\n", dlen);
7486 if (dlen > risc_size * sizeof(*dcode)) {
7487 ql_log(ql_log_warn, vha, 0x0167,
7488 "Failed fwdump template exceeds array by %zx bytes\n",
7489 (size_t)(dlen - risc_size * sizeof(*dcode)));
7490 goto default_template;
7492 ha->fw_dump_template_len = dlen;
7496 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
7497 if (ha->fw_dump_template)
7498 vfree(ha->fw_dump_template);
7499 ha->fw_dump_template = NULL;
7500 ha->fw_dump_template_len = 0;
7502 dlen = qla27xx_fwdt_template_default_size();
7503 ql_dbg(ql_dbg_init, vha, 0x0169,
7504 "-> template allocating %x bytes...\n", dlen);
7505 ha->fw_dump_template = vmalloc(dlen);
7506 if (!ha->fw_dump_template) {
7507 ql_log(ql_log_warn, vha, 0x016a,
7508 "Failed fwdump template allocate %x bytes.\n", risc_size);
7509 goto failed_template;
7512 dcode = ha->fw_dump_template;
7513 risc_size = dlen / sizeof(*dcode);
7514 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
7515 for (i = 0; i < risc_size; i++)
7516 dcode[i] = be32_to_cpu(dcode[i]);
7518 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7519 ql_log(ql_log_warn, vha, 0x016b,
7520 "Failed fwdump template validate\n");
7521 goto failed_template;
7524 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7525 ql_dbg(ql_dbg_init, vha, 0x016c,
7526 "-> template size %x bytes\n", dlen);
7527 ha->fw_dump_template_len = dlen;
7531 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
7532 if (ha->fw_dump_template)
7533 vfree(ha->fw_dump_template);
7534 ha->fw_dump_template = NULL;
7535 ha->fw_dump_template_len = 0;
7539 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7542 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7546 uint16_t *wcode, *fwcode;
7547 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7548 struct fw_blob *blob;
7549 struct qla_hw_data *ha = vha->hw;
7550 struct req_que *req = ha->req_q_map[0];
7552 /* Load firmware blob. */
7553 blob = qla2x00_request_firmware(vha);
7555 ql_log(ql_log_info, vha, 0x0083,
7556 "Firmware image unavailable.\n");
7557 ql_log(ql_log_info, vha, 0x0084,
7558 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7559 return QLA_FUNCTION_FAILED;
7564 wcode = (uint16_t *)req->ring;
7566 fwcode = (uint16_t *)blob->fw->data;
7569 /* Validate firmware image by checking version. */
7570 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7571 ql_log(ql_log_fatal, vha, 0x0085,
7572 "Unable to verify integrity of firmware image (%zd).\n",
7574 goto fail_fw_integrity;
7576 for (i = 0; i < 4; i++)
7577 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7578 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7579 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7580 wcode[2] == 0 && wcode[3] == 0)) {
7581 ql_log(ql_log_fatal, vha, 0x0086,
7582 "Unable to verify integrity of firmware image.\n");
7583 ql_log(ql_log_fatal, vha, 0x0087,
7584 "Firmware data: %04x %04x %04x %04x.\n",
7585 wcode[0], wcode[1], wcode[2], wcode[3]);
7586 goto fail_fw_integrity;
7590 while (*seg && rval == QLA_SUCCESS) {
7592 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7593 risc_size = be16_to_cpu(fwcode[3]);
7595 /* Validate firmware image size. */
7596 fwclen += risc_size * sizeof(uint16_t);
7597 if (blob->fw->size < fwclen) {
7598 ql_log(ql_log_fatal, vha, 0x0088,
7599 "Unable to verify integrity of firmware image "
7600 "(%zd).\n", blob->fw->size);
7601 goto fail_fw_integrity;
7605 while (risc_size > 0 && rval == QLA_SUCCESS) {
7606 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7607 if (wlen > risc_size)
7609 ql_dbg(ql_dbg_init, vha, 0x0089,
7610 "Loading risc segment@ risc addr %x number of "
7611 "words 0x%x.\n", risc_addr, wlen);
7613 for (i = 0; i < wlen; i++)
7614 wcode[i] = swab16(fwcode[i]);
7616 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7619 ql_log(ql_log_fatal, vha, 0x008a,
7620 "Failed to load segment %d of firmware.\n",
7637 return QLA_FUNCTION_FAILED;
7641 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7644 int segments, fragment;
7645 uint32_t *dcode, dlen;
7649 struct fw_blob *blob;
7650 const uint32_t *fwcode;
7652 struct qla_hw_data *ha = vha->hw;
7653 struct req_que *req = ha->req_q_map[0];
7655 /* Load firmware blob. */
7656 blob = qla2x00_request_firmware(vha);
7658 ql_log(ql_log_warn, vha, 0x0090,
7659 "Firmware image unavailable.\n");
7660 ql_log(ql_log_warn, vha, 0x0091,
7661 "Firmware images can be retrieved from: "
7664 return QLA_FUNCTION_FAILED;
7667 ql_dbg(ql_dbg_init, vha, 0x0092,
7668 "FW: Loading via request-firmware.\n");
7672 segments = FA_RISC_CODE_SEGMENTS;
7673 dcode = (uint32_t *)req->ring;
7675 fwcode = (uint32_t *)blob->fw->data;
7678 /* Validate firmware image by checking version. */
7679 if (blob->fw->size < 8 * sizeof(uint32_t)) {
7680 ql_log(ql_log_fatal, vha, 0x0093,
7681 "Unable to verify integrity of firmware image (%zd).\n",
7683 return QLA_FUNCTION_FAILED;
7685 for (i = 0; i < 4; i++)
7686 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7687 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7688 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7689 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7691 ql_log(ql_log_fatal, vha, 0x0094,
7692 "Unable to verify integrity of firmware image (%zd).\n",
7694 ql_log(ql_log_fatal, vha, 0x0095,
7695 "Firmware data: %08x %08x %08x %08x.\n",
7696 dcode[0], dcode[1], dcode[2], dcode[3]);
7697 return QLA_FUNCTION_FAILED;
7700 while (segments && rval == QLA_SUCCESS) {
7701 risc_addr = be32_to_cpu(fwcode[2]);
7702 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7703 risc_size = be32_to_cpu(fwcode[3]);
7705 /* Validate firmware image size. */
7706 fwclen += risc_size * sizeof(uint32_t);
7707 if (blob->fw->size < fwclen) {
7708 ql_log(ql_log_fatal, vha, 0x0096,
7709 "Unable to verify integrity of firmware image "
7710 "(%zd).\n", blob->fw->size);
7711 return QLA_FUNCTION_FAILED;
7715 while (risc_size > 0 && rval == QLA_SUCCESS) {
7716 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7717 if (dlen > risc_size)
7720 ql_dbg(ql_dbg_init, vha, 0x0097,
7721 "Loading risc segment@ risc addr %x "
7722 "number of dwords 0x%x.\n", risc_addr, dlen);
7724 for (i = 0; i < dlen; i++)
7725 dcode[i] = swab32(fwcode[i]);
7727 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7730 ql_log(ql_log_fatal, vha, 0x0098,
7731 "Failed to load segment %d of firmware.\n",
7733 return QLA_FUNCTION_FAILED;
7746 if (!IS_QLA27XX(ha))
7749 if (ha->fw_dump_template)
7750 vfree(ha->fw_dump_template);
7751 ha->fw_dump_template = NULL;
7752 ha->fw_dump_template_len = 0;
7754 ql_dbg(ql_dbg_init, vha, 0x171,
7755 "Loading fwdump template from %x\n",
7756 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
7757 risc_size = be32_to_cpu(fwcode[2]);
7758 ql_dbg(ql_dbg_init, vha, 0x172,
7759 "-> array size %x dwords\n", risc_size);
7760 if (risc_size == 0 || risc_size == ~0)
7761 goto default_template;
7763 dlen = (risc_size - 8) * sizeof(*fwcode);
7764 ql_dbg(ql_dbg_init, vha, 0x0173,
7765 "-> template allocating %x bytes...\n", dlen);
7766 ha->fw_dump_template = vmalloc(dlen);
7767 if (!ha->fw_dump_template) {
7768 ql_log(ql_log_warn, vha, 0x0174,
7769 "Failed fwdump template allocate %x bytes.\n", risc_size);
7770 goto default_template;
7775 dcode = ha->fw_dump_template;
7776 for (i = 0; i < risc_size; i++)
7777 dcode[i] = le32_to_cpu(fwcode[i]);
7779 if (!qla27xx_fwdt_template_valid(dcode)) {
7780 ql_log(ql_log_warn, vha, 0x0175,
7781 "Failed fwdump template validate\n");
7782 goto default_template;
7785 dlen = qla27xx_fwdt_template_size(dcode);
7786 ql_dbg(ql_dbg_init, vha, 0x0176,
7787 "-> template size %x bytes\n", dlen);
7788 if (dlen > risc_size * sizeof(*fwcode)) {
7789 ql_log(ql_log_warn, vha, 0x0177,
7790 "Failed fwdump template exceeds array by %zx bytes\n",
7791 (size_t)(dlen - risc_size * sizeof(*fwcode)));
7792 goto default_template;
7794 ha->fw_dump_template_len = dlen;
7798 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7799 if (ha->fw_dump_template)
7800 vfree(ha->fw_dump_template);
7801 ha->fw_dump_template = NULL;
7802 ha->fw_dump_template_len = 0;
7804 dlen = qla27xx_fwdt_template_default_size();
7805 ql_dbg(ql_dbg_init, vha, 0x0179,
7806 "-> template allocating %x bytes...\n", dlen);
7807 ha->fw_dump_template = vmalloc(dlen);
7808 if (!ha->fw_dump_template) {
7809 ql_log(ql_log_warn, vha, 0x017a,
7810 "Failed fwdump template allocate %x bytes.\n", risc_size);
7811 goto failed_template;
7814 dcode = ha->fw_dump_template;
7815 risc_size = dlen / sizeof(*fwcode);
7816 fwcode = qla27xx_fwdt_template_default();
7817 for (i = 0; i < risc_size; i++)
7818 dcode[i] = be32_to_cpu(fwcode[i]);
7820 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7821 ql_log(ql_log_warn, vha, 0x017b,
7822 "Failed fwdump template validate\n");
7823 goto failed_template;
7826 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7827 ql_dbg(ql_dbg_init, vha, 0x017c,
7828 "-> template size %x bytes\n", dlen);
7829 ha->fw_dump_template_len = dlen;
7833 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7834 if (ha->fw_dump_template)
7835 vfree(ha->fw_dump_template);
7836 ha->fw_dump_template = NULL;
7837 ha->fw_dump_template_len = 0;
7842 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7846 if (ql2xfwloadbin == 1)
7847 return qla81xx_load_risc(vha, srisc_addr);
7851 * 1) Firmware via request-firmware interface (.bin file).
7852 * 2) Firmware residing in flash.
7854 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7855 if (rval == QLA_SUCCESS)
7858 return qla24xx_load_risc_flash(vha, srisc_addr,
7859 vha->hw->flt_region_fw);
7863 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7866 struct qla_hw_data *ha = vha->hw;
7868 if (ql2xfwloadbin == 2)
7873 * 1) Firmware residing in flash.
7874 * 2) Firmware via request-firmware interface (.bin file).
7875 * 3) Golden-Firmware residing in flash -- limited operation.
7877 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
7878 if (rval == QLA_SUCCESS)
7882 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7883 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7886 ql_log(ql_log_info, vha, 0x0099,
7887 "Attempting to fallback to golden firmware.\n");
7888 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7889 if (rval != QLA_SUCCESS)
7892 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
7893 ha->flags.running_gold_fw = 1;
7898 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
7901 struct qla_hw_data *ha = vha->hw;
7903 if (ha->flags.pci_channel_io_perm_failure)
7905 if (!IS_FWI2_CAPABLE(ha))
7907 if (!ha->fw_major_version)
7909 if (!ha->flags.fw_started)
7912 ret = qla2x00_stop_firmware(vha);
7913 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
7914 ret != QLA_INVALID_COMMAND && retries ; retries--) {
7915 ha->isp_ops->reset_chip(vha);
7916 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
7918 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
7920 ql_log(ql_log_info, vha, 0x8015,
7921 "Attempting retry of stop-firmware command.\n");
7922 ret = qla2x00_stop_firmware(vha);
7926 ha->flags.fw_init_done = 0;
7930 qla24xx_configure_vhba(scsi_qla_host_t *vha)
7932 int rval = QLA_SUCCESS;
7934 uint16_t mb[MAILBOX_REGISTER_COUNT];
7935 struct qla_hw_data *ha = vha->hw;
7936 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7937 struct req_que *req;
7938 struct rsp_que *rsp;
7943 rval = qla2x00_fw_ready(base_vha);
7945 req = vha->qpair->req;
7947 req = ha->req_q_map[0];
7950 if (rval == QLA_SUCCESS) {
7951 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7952 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
7955 vha->flags.management_server_logged_in = 0;
7957 /* Login to SNS first */
7958 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7960 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7961 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7962 ql_dbg(ql_dbg_init, vha, 0x0120,
7963 "Failed SNS login: loop_id=%x, rval2=%d\n",
7966 ql_dbg(ql_dbg_init, vha, 0x0103,
7967 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7968 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7969 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
7970 return (QLA_FUNCTION_FAILED);
7973 atomic_set(&vha->loop_down_timer, 0);
7974 atomic_set(&vha->loop_state, LOOP_UP);
7975 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7976 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7977 rval = qla2x00_loop_resync(base_vha);
7982 /* 84XX Support **************************************************************/
7984 static LIST_HEAD(qla_cs84xx_list);
7985 static DEFINE_MUTEX(qla_cs84xx_mutex);
7987 static struct qla_chip_state_84xx *
7988 qla84xx_get_chip(struct scsi_qla_host *vha)
7990 struct qla_chip_state_84xx *cs84xx;
7991 struct qla_hw_data *ha = vha->hw;
7993 mutex_lock(&qla_cs84xx_mutex);
7995 /* Find any shared 84xx chip. */
7996 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7997 if (cs84xx->bus == ha->pdev->bus) {
7998 kref_get(&cs84xx->kref);
8003 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8007 kref_init(&cs84xx->kref);
8008 spin_lock_init(&cs84xx->access_lock);
8009 mutex_init(&cs84xx->fw_update_mutex);
8010 cs84xx->bus = ha->pdev->bus;
8012 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8014 mutex_unlock(&qla_cs84xx_mutex);
8019 __qla84xx_chip_release(struct kref *kref)
8021 struct qla_chip_state_84xx *cs84xx =
8022 container_of(kref, struct qla_chip_state_84xx, kref);
8024 mutex_lock(&qla_cs84xx_mutex);
8025 list_del(&cs84xx->list);
8026 mutex_unlock(&qla_cs84xx_mutex);
8031 qla84xx_put_chip(struct scsi_qla_host *vha)
8033 struct qla_hw_data *ha = vha->hw;
8035 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8039 qla84xx_init_chip(scsi_qla_host_t *vha)
8043 struct qla_hw_data *ha = vha->hw;
8045 mutex_lock(&ha->cs84xx->fw_update_mutex);
8047 rval = qla84xx_verify_chip(vha, status);
8049 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8051 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
8055 /* 81XX Support **************************************************************/
8058 qla81xx_nvram_config(scsi_qla_host_t *vha)
8061 struct init_cb_81xx *icb;
8062 struct nvram_81xx *nv;
8064 uint8_t *dptr1, *dptr2;
8067 struct qla_hw_data *ha = vha->hw;
8070 icb = (struct init_cb_81xx *)ha->init_cb;
8073 /* Determine NVRAM starting address. */
8074 ha->nvram_size = sizeof(struct nvram_81xx);
8075 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8076 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8077 ha->vpd_size = FA_VPD_SIZE_82XX;
8079 /* Get VPD data into cache */
8080 ha->vpd = ha->nvram + VPD_OFFSET;
8081 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
8084 /* Get NVRAM data into cache and calculate checksum. */
8085 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
8087 dptr = (uint32_t *)nv;
8088 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8089 chksum += le32_to_cpu(*dptr);
8091 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8092 "Contents of NVRAM:\n");
8093 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8094 (uint8_t *)nv, ha->nvram_size);
8096 /* Bad NVRAM data, set defaults parameters. */
8097 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
8098 || nv->id[3] != ' ' ||
8099 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
8100 /* Reset NVRAM data. */
8101 ql_log(ql_log_info, vha, 0x0073,
8102 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
8103 "version=0x%x.\n", chksum, nv->id[0],
8104 le16_to_cpu(nv->nvram_version));
8105 ql_log(ql_log_info, vha, 0x0074,
8106 "Falling back to functioning (yet invalid -- WWPN) "
8110 * Set default initialization control block.
8112 memset(nv, 0, ha->nvram_size);
8113 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8114 nv->version = cpu_to_le16(ICB_VERSION);
8115 nv->frame_payload_size = 2048;
8116 nv->execution_throttle = cpu_to_le16(0xFFFF);
8117 nv->exchange_count = cpu_to_le16(0);
8118 nv->port_name[0] = 0x21;
8119 nv->port_name[1] = 0x00 + ha->port_no + 1;
8120 nv->port_name[2] = 0x00;
8121 nv->port_name[3] = 0xe0;
8122 nv->port_name[4] = 0x8b;
8123 nv->port_name[5] = 0x1c;
8124 nv->port_name[6] = 0x55;
8125 nv->port_name[7] = 0x86;
8126 nv->node_name[0] = 0x20;
8127 nv->node_name[1] = 0x00;
8128 nv->node_name[2] = 0x00;
8129 nv->node_name[3] = 0xe0;
8130 nv->node_name[4] = 0x8b;
8131 nv->node_name[5] = 0x1c;
8132 nv->node_name[6] = 0x55;
8133 nv->node_name[7] = 0x86;
8134 nv->login_retry_count = cpu_to_le16(8);
8135 nv->interrupt_delay_timer = cpu_to_le16(0);
8136 nv->login_timeout = cpu_to_le16(0);
8137 nv->firmware_options_1 =
8138 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8139 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8140 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8141 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8142 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8143 nv->efi_parameters = cpu_to_le32(0);
8144 nv->reset_delay = 5;
8145 nv->max_luns_per_target = cpu_to_le16(128);
8146 nv->port_down_retry_count = cpu_to_le16(30);
8147 nv->link_down_timeout = cpu_to_le16(180);
8148 nv->enode_mac[0] = 0x00;
8149 nv->enode_mac[1] = 0xC0;
8150 nv->enode_mac[2] = 0xDD;
8151 nv->enode_mac[3] = 0x04;
8152 nv->enode_mac[4] = 0x05;
8153 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8158 if (IS_T10_PI_CAPABLE(ha))
8159 nv->frame_payload_size &= ~7;
8161 qlt_81xx_config_nvram_stage1(vha, nv);
8163 /* Reset Initialization control block */
8164 memset(icb, 0, ha->init_cb_size);
8166 /* Copy 1st segment. */
8167 dptr1 = (uint8_t *)icb;
8168 dptr2 = (uint8_t *)&nv->version;
8169 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8171 *dptr1++ = *dptr2++;
8173 icb->login_retry_count = nv->login_retry_count;
8175 /* Copy 2nd segment. */
8176 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8177 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8178 cnt = (uint8_t *)&icb->reserved_5 -
8179 (uint8_t *)&icb->interrupt_delay_timer;
8181 *dptr1++ = *dptr2++;
8183 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8184 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8185 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8186 icb->enode_mac[0] = 0x00;
8187 icb->enode_mac[1] = 0xC0;
8188 icb->enode_mac[2] = 0xDD;
8189 icb->enode_mac[3] = 0x04;
8190 icb->enode_mac[4] = 0x05;
8191 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8194 /* Use extended-initialization control block. */
8195 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8196 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8198 * Setup driver NVRAM options.
8200 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8203 qlt_81xx_config_nvram_stage2(vha, icb);
8205 /* Use alternate WWN? */
8206 if (nv->host_p & cpu_to_le32(BIT_15)) {
8207 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8208 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8211 /* Prepare nodename */
8212 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8214 * Firmware will apply the following mask if the nodename was
8217 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8218 icb->node_name[0] &= 0xF0;
8221 /* Set host adapter parameters. */
8222 ha->flags.disable_risc_code_load = 0;
8223 ha->flags.enable_lip_reset = 0;
8224 ha->flags.enable_lip_full_login =
8225 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
8226 ha->flags.enable_target_reset =
8227 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
8228 ha->flags.enable_led_scheme = 0;
8229 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
8231 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8232 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8234 /* save HBA serial number */
8235 ha->serial0 = icb->port_name[5];
8236 ha->serial1 = icb->port_name[6];
8237 ha->serial2 = icb->port_name[7];
8238 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8239 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8241 icb->execution_throttle = cpu_to_le16(0xFFFF);
8243 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8245 /* Set minimum login_timeout to 4 seconds. */
8246 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8247 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8248 if (le16_to_cpu(nv->login_timeout) < 4)
8249 nv->login_timeout = cpu_to_le16(4);
8250 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8252 /* Set minimum RATOV to 100 tenths of a second. */
8255 ha->loop_reset_delay = nv->reset_delay;
8257 /* Link Down Timeout = 0:
8259 * When Port Down timer expires we will start returning
8260 * I/O's to OS with "DID_NO_CONNECT".
8262 * Link Down Timeout != 0:
8264 * The driver waits for the link to come up after link down
8265 * before returning I/Os to OS with "DID_NO_CONNECT".
8267 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8268 ha->loop_down_abort_time =
8269 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8271 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8272 ha->loop_down_abort_time =
8273 (LOOP_DOWN_TIME - ha->link_down_timeout);
8276 /* Need enough time to try and get the port back. */
8277 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8278 if (qlport_down_retry)
8279 ha->port_down_retry_count = qlport_down_retry;
8281 /* Set login_retry_count */
8282 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8283 if (ha->port_down_retry_count ==
8284 le16_to_cpu(nv->port_down_retry_count) &&
8285 ha->port_down_retry_count > 3)
8286 ha->login_retry_count = ha->port_down_retry_count;
8287 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8288 ha->login_retry_count = ha->port_down_retry_count;
8289 if (ql2xloginretrycount)
8290 ha->login_retry_count = ql2xloginretrycount;
8292 /* if not running MSI-X we need handshaking on interrupts */
8293 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
8294 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8297 if (!vha->flags.init_done) {
8298 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8299 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8300 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8301 le16_to_cpu(icb->interrupt_delay_timer): 2;
8303 icb->firmware_options_2 &= cpu_to_le32(
8304 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8305 vha->flags.process_response_queue = 0;
8306 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8307 ha->zio_mode = QLA_ZIO_MODE_6;
8309 ql_log(ql_log_info, vha, 0x0075,
8310 "ZIO mode %d enabled; timer delay (%d us).\n",
8312 ha->zio_timer * 100);
8314 icb->firmware_options_2 |= cpu_to_le32(
8315 (uint32_t)ha->zio_mode);
8316 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8317 vha->flags.process_response_queue = 1;
8320 /* enable RIDA Format2 */
8321 icb->firmware_options_3 |= BIT_0;
8323 /* N2N: driver will initiate Login instead of FW */
8324 icb->firmware_options_3 |= BIT_8;
8326 if (IS_QLA27XX(ha)) {
8327 icb->firmware_options_3 |= BIT_8;
8328 ql_dbg(ql_log_info, vha, 0x0075,
8329 "Enabling direct connection.\n");
8333 ql_log(ql_log_warn, vha, 0x0076,
8334 "NVRAM configuration failed.\n");
8340 qla82xx_restart_isp(scsi_qla_host_t *vha)
8343 struct qla_hw_data *ha = vha->hw;
8344 struct req_que *req = ha->req_q_map[0];
8345 struct rsp_que *rsp = ha->rsp_q_map[0];
8346 struct scsi_qla_host *vp;
8347 unsigned long flags;
8349 status = qla2x00_init_rings(vha);
8351 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8352 ha->flags.chip_reset_done = 1;
8354 status = qla2x00_fw_ready(vha);
8356 /* Issue a marker after FW becomes ready. */
8357 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
8358 vha->flags.online = 1;
8359 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8362 /* if no cable then assume it's good */
8363 if ((vha->device_flags & DFLG_NO_CABLE))
8368 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8370 if (!atomic_read(&vha->loop_down_timer)) {
8372 * Issue marker command only when we are going
8373 * to start the I/O .
8375 vha->marker_needed = 1;
8378 ha->isp_ops->enable_intrs(ha);
8380 ha->isp_abort_cnt = 0;
8381 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8383 /* Update the firmware version */
8384 status = qla82xx_check_md_needed(vha);
8387 ha->flags.fce_enabled = 1;
8389 fce_calc_size(ha->fce_bufs));
8390 rval = qla2x00_enable_fce_trace(vha,
8391 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8394 ql_log(ql_log_warn, vha, 0x8001,
8395 "Unable to reinitialize FCE (%d).\n",
8397 ha->flags.fce_enabled = 0;
8402 memset(ha->eft, 0, EFT_SIZE);
8403 rval = qla2x00_enable_eft_trace(vha,
8404 ha->eft_dma, EFT_NUM_BUFFERS);
8406 ql_log(ql_log_warn, vha, 0x8010,
8407 "Unable to reinitialize EFT (%d).\n",
8414 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8415 "qla82xx_restart_isp succeeded.\n");
8417 spin_lock_irqsave(&ha->vport_slock, flags);
8418 list_for_each_entry(vp, &ha->vp_list, list) {
8420 atomic_inc(&vp->vref_count);
8421 spin_unlock_irqrestore(&ha->vport_slock, flags);
8423 qla2x00_vp_abort_isp(vp);
8425 spin_lock_irqsave(&ha->vport_slock, flags);
8426 atomic_dec(&vp->vref_count);
8429 spin_unlock_irqrestore(&ha->vport_slock, flags);
8432 ql_log(ql_log_warn, vha, 0x8016,
8433 "qla82xx_restart_isp **** FAILED ****.\n");
8440 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8442 struct qla_hw_data *ha = vha->hw;
8444 /* Hold status IOCBs until ABTS response received. */
8446 ha->fw_options[3] |= BIT_12;
8448 /* Set Retry FLOGI in case of P2P connection */
8449 if (ha->operating_mode == P2P) {
8450 ha->fw_options[2] |= BIT_3;
8451 ql_dbg(ql_dbg_disc, vha, 0x2103,
8452 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8453 __func__, ha->fw_options[2]);
8456 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8457 if (ql2xmvasynctoatio) {
8458 if (qla_tgt_mode_enabled(vha) ||
8459 qla_dual_mode_enabled(vha))
8460 ha->fw_options[2] |= BIT_11;
8462 ha->fw_options[2] &= ~BIT_11;
8465 if (qla_tgt_mode_enabled(vha) ||
8466 qla_dual_mode_enabled(vha)) {
8467 /* FW auto send SCSI status during */
8468 ha->fw_options[1] |= BIT_8;
8469 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8471 /* FW perform Exchange validation */
8472 ha->fw_options[2] |= BIT_4;
8474 ha->fw_options[1] &= ~BIT_8;
8475 ha->fw_options[10] &= 0x00ff;
8477 ha->fw_options[2] &= ~BIT_4;
8480 if (ql2xetsenable) {
8481 /* Enable ETS Burst. */
8482 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8483 ha->fw_options[2] |= BIT_9;
8486 ql_dbg(ql_dbg_init, vha, 0x00e9,
8487 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8488 __func__, ha->fw_options[1], ha->fw_options[2],
8489 ha->fw_options[3], vha->host->active_mode);
8491 qla2x00_set_fw_options(vha, ha->fw_options);
8495 * qla24xx_get_fcp_prio
8496 * Gets the fcp cmd priority value for the logged in port.
8497 * Looks for a match of the port descriptors within
8498 * each of the fcp prio config entries. If a match is found,
8499 * the tag (priority) value is returned.
8502 * vha = scsi host structure pointer.
8503 * fcport = port structure pointer.
8506 * non-zero (if found)
8513 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8516 uint8_t pid_match, wwn_match;
8518 uint32_t pid1, pid2;
8519 uint64_t wwn1, wwn2;
8520 struct qla_fcp_prio_entry *pri_entry;
8521 struct qla_hw_data *ha = vha->hw;
8523 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8527 entries = ha->fcp_prio_cfg->num_entries;
8528 pri_entry = &ha->fcp_prio_cfg->entry[0];
8530 for (i = 0; i < entries; i++) {
8531 pid_match = wwn_match = 0;
8533 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8538 /* check source pid for a match */
8539 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8540 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8541 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8542 if (pid1 == INVALID_PORT_ID)
8544 else if (pid1 == pid2)
8548 /* check destination pid for a match */
8549 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8550 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8551 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8552 if (pid1 == INVALID_PORT_ID)
8554 else if (pid1 == pid2)
8558 /* check source WWN for a match */
8559 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8560 wwn1 = wwn_to_u64(vha->port_name);
8561 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8562 if (wwn2 == (uint64_t)-1)
8564 else if (wwn1 == wwn2)
8568 /* check destination WWN for a match */
8569 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8570 wwn1 = wwn_to_u64(fcport->port_name);
8571 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8572 if (wwn2 == (uint64_t)-1)
8574 else if (wwn1 == wwn2)
8578 if (pid_match == 2 || wwn_match == 2) {
8579 /* Found a matching entry */
8580 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8581 priority = pri_entry->tag;
8592 * qla24xx_update_fcport_fcp_prio
8593 * Activates fcp priority for the logged in fc port
8596 * vha = scsi host structure pointer.
8597 * fcp = port structure pointer.
8600 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8606 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8612 if (fcport->port_type != FCT_TARGET ||
8613 fcport->loop_id == FC_NO_LOOP_ID)
8614 return QLA_FUNCTION_FAILED;
8616 priority = qla24xx_get_fcp_prio(vha, fcport);
8618 return QLA_FUNCTION_FAILED;
8620 if (IS_P3P_TYPE(vha->hw)) {
8621 fcport->fcp_prio = priority & 0xf;
8625 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8626 if (ret == QLA_SUCCESS) {
8627 if (fcport->fcp_prio != priority)
8628 ql_dbg(ql_dbg_user, vha, 0x709e,
8629 "Updated FCP_CMND priority - value=%d loop_id=%d "
8630 "port_id=%02x%02x%02x.\n", priority,
8631 fcport->loop_id, fcport->d_id.b.domain,
8632 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8633 fcport->fcp_prio = priority & 0xf;
8635 ql_dbg(ql_dbg_user, vha, 0x704f,
8636 "Unable to update FCP_CMND priority - ret=0x%x for "
8637 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8638 fcport->d_id.b.domain, fcport->d_id.b.area,
8639 fcport->d_id.b.al_pa);
8644 * qla24xx_update_all_fcp_prio
8645 * Activates fcp priority for all the logged in ports
8648 * ha = adapter block pointer.
8651 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8657 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8662 ret = QLA_FUNCTION_FAILED;
8663 /* We need to set priority for all logged in ports */
8664 list_for_each_entry(fcport, &vha->vp_fcports, list)
8665 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8670 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8671 int vp_idx, bool startqp)
8676 struct qla_hw_data *ha = vha->hw;
8677 uint16_t qpair_id = 0;
8678 struct qla_qpair *qpair = NULL;
8679 struct qla_msix_entry *msix;
8681 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8682 ql_log(ql_log_warn, vha, 0x00181,
8683 "FW/Driver is not multi-queue capable.\n");
8687 if (ql2xmqsupport || ql2xnvmeenable) {
8688 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8689 if (qpair == NULL) {
8690 ql_log(ql_log_warn, vha, 0x0182,
8691 "Failed to allocate memory for queue pair.\n");
8694 memset(qpair, 0, sizeof(struct qla_qpair));
8696 qpair->hw = vha->hw;
8698 qpair->qp_lock_ptr = &qpair->qp_lock;
8699 spin_lock_init(&qpair->qp_lock);
8700 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8702 /* Assign available que pair id */
8703 mutex_lock(&ha->mq_lock);
8704 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8705 if (ha->num_qpairs >= ha->max_qpairs) {
8706 mutex_unlock(&ha->mq_lock);
8707 ql_log(ql_log_warn, vha, 0x0183,
8708 "No resources to create additional q pair.\n");
8712 set_bit(qpair_id, ha->qpair_qid_map);
8713 ha->queue_pair_map[qpair_id] = qpair;
8714 qpair->id = qpair_id;
8715 qpair->vp_idx = vp_idx;
8716 qpair->fw_started = ha->flags.fw_started;
8717 INIT_LIST_HEAD(&qpair->hints_list);
8718 qpair->chip_reset = ha->base_qpair->chip_reset;
8719 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8720 qpair->enable_explicit_conf =
8721 ha->base_qpair->enable_explicit_conf;
8723 for (i = 0; i < ha->msix_count; i++) {
8724 msix = &ha->msix_entries[i];
8728 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8729 "Vector %x selected for qpair\n", msix->vector);
8733 ql_log(ql_log_warn, vha, 0x0184,
8734 "Out of MSI-X vectors!.\n");
8738 qpair->msix->in_use = 1;
8739 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8740 qpair->pdev = ha->pdev;
8741 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8742 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8744 mutex_unlock(&ha->mq_lock);
8746 /* Create response queue first */
8747 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8749 ql_log(ql_log_warn, vha, 0x0185,
8750 "Failed to create response queue.\n");
8754 qpair->rsp = ha->rsp_q_map[rsp_id];
8756 /* Create request queue */
8757 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8760 ql_log(ql_log_warn, vha, 0x0186,
8761 "Failed to create request queue.\n");
8765 qpair->req = ha->req_q_map[req_id];
8766 qpair->rsp->req = qpair->req;
8767 qpair->rsp->qpair = qpair;
8768 /* init qpair to this cpu. Will adjust at run time. */
8769 qla_cpu_update(qpair, smp_processor_id());
8771 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8772 if (ha->fw_attributes & BIT_4)
8773 qpair->difdix_supported = 1;
8776 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8777 if (!qpair->srb_mempool) {
8778 ql_log(ql_log_warn, vha, 0xd036,
8779 "Failed to create srb mempool for qpair %d\n",
8784 /* Mark as online */
8787 if (!vha->flags.qpairs_available)
8788 vha->flags.qpairs_available = 1;
8790 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8791 "Request/Response queue pair created, id %d\n",
8793 ql_dbg(ql_dbg_init, vha, 0x0187,
8794 "Request/Response queue pair created, id %d\n",
8801 qla25xx_delete_rsp_que(vha, qpair->rsp);
8803 mutex_lock(&ha->mq_lock);
8804 qpair->msix->in_use = 0;
8805 list_del(&qpair->qp_list_elem);
8806 if (list_empty(&vha->qp_list))
8807 vha->flags.qpairs_available = 0;
8809 ha->queue_pair_map[qpair_id] = NULL;
8810 clear_bit(qpair_id, ha->qpair_qid_map);
8812 mutex_unlock(&ha->mq_lock);
8818 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8820 int ret = QLA_FUNCTION_FAILED;
8821 struct qla_hw_data *ha = qpair->hw;
8823 qpair->delete_in_progress = 1;
8824 while (atomic_read(&qpair->ref_count))
8827 ret = qla25xx_delete_req_que(vha, qpair->req);
8828 if (ret != QLA_SUCCESS)
8831 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8832 if (ret != QLA_SUCCESS)
8835 mutex_lock(&ha->mq_lock);
8836 ha->queue_pair_map[qpair->id] = NULL;
8837 clear_bit(qpair->id, ha->qpair_qid_map);
8839 list_del(&qpair->qp_list_elem);
8840 if (list_empty(&vha->qp_list)) {
8841 vha->flags.qpairs_available = 0;
8842 vha->flags.qpairs_req_created = 0;
8843 vha->flags.qpairs_rsp_created = 0;
8845 mempool_destroy(qpair->srb_mempool);
8847 mutex_unlock(&ha->mq_lock);