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;
53 scsi_qla_host_t *vha = sp->vha;
57 spin_lock_irqsave(&vha->hw->hardware_lock, flags);
58 req = vha->hw->req_q_map[0];
59 req->outstanding_cmds[sp->handle] = NULL;
60 iocb = &sp->u.iocb_cmd;
62 spin_unlock_irqrestore(&vha->hw->hardware_lock, flags);
66 qla2x00_sp_free(void *ptr)
69 struct srb_iocb *iocb = &sp->u.iocb_cmd;
71 del_timer(&iocb->timer);
75 /* Asynchronous Login/Logout Routines -------------------------------------- */
78 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
81 struct qla_hw_data *ha = vha->hw;
83 /* Firmware should use switch negotiated r_a_tov for timeout. */
84 tmo = ha->r_a_tov / 10 * 2;
86 tmo = FX00_DEF_RATOV * 2;
87 } else if (!IS_FWI2_CAPABLE(ha)) {
89 * Except for earlier ISPs where the timeout is seeded from the
90 * initialization control block.
92 tmo = ha->login_timeout;
98 qla2x00_async_iocb_timeout(void *data)
101 fc_port_t *fcport = sp->fcport;
102 struct srb_iocb *lio = &sp->u.iocb_cmd;
105 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
106 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
107 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
109 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
111 pr_info("Async-%s timeout - hdl=%x.\n",
112 sp->name, sp->handle);
117 /* Retry as needed. */
118 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
119 lio->u.logio.data[1] = lio->u.logio.flags & SRB_LOGIN_RETRIED ?
120 QLA_LOGIO_LOGIN_RETRIED : 0;
121 sp->done(sp, QLA_FUNCTION_TIMEOUT);
124 case SRB_CT_PTHRU_CMD:
130 sp->done(sp, QLA_FUNCTION_TIMEOUT);
136 qla2x00_async_login_sp_done(void *ptr, int res)
139 struct scsi_qla_host *vha = sp->vha;
140 struct srb_iocb *lio = &sp->u.iocb_cmd;
143 ql_dbg(ql_dbg_disc, vha, 0x20dd,
144 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
146 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
148 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
149 memset(&ea, 0, sizeof(ea));
150 ea.event = FCME_PLOGI_DONE;
151 ea.fcport = sp->fcport;
152 ea.data[0] = lio->u.logio.data[0];
153 ea.data[1] = lio->u.logio.data[1];
154 ea.iop[0] = lio->u.logio.iop[0];
155 ea.iop[1] = lio->u.logio.iop[1];
157 qla2x00_fcport_event_handler(vha, &ea);
164 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
168 struct srb_iocb *lio;
169 int rval = QLA_FUNCTION_FAILED;
171 if (!vha->flags.online)
174 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
178 fcport->flags |= FCF_ASYNC_SENT;
179 fcport->logout_completed = 0;
181 fcport->disc_state = DSC_LOGIN_PEND;
182 sp->type = SRB_LOGIN_CMD;
184 sp->gen1 = fcport->rscn_gen;
185 sp->gen2 = fcport->login_gen;
187 lio = &sp->u.iocb_cmd;
188 lio->timeout = qla2x00_async_iocb_timeout;
189 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
191 sp->done = qla2x00_async_login_sp_done;
192 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
194 if (fcport->fc4f_nvme)
195 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
197 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
198 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
199 rval = qla2x00_start_sp(sp);
200 if (rval != QLA_SUCCESS) {
201 fcport->flags |= FCF_LOGIN_NEEDED;
202 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
206 ql_dbg(ql_dbg_disc, vha, 0x2072,
207 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
208 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
209 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
210 fcport->login_retry);
215 fcport->flags &= ~FCF_ASYNC_SENT;
217 fcport->flags &= ~FCF_ASYNC_ACTIVE;
222 qla2x00_async_logout_sp_done(void *ptr, int res)
226 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
227 sp->fcport->login_gen++;
228 qlt_logo_completion_handler(sp->fcport, res);
233 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
236 struct srb_iocb *lio;
237 int rval = QLA_FUNCTION_FAILED;
239 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
242 fcport->flags |= FCF_ASYNC_SENT;
243 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
247 sp->type = SRB_LOGOUT_CMD;
250 lio = &sp->u.iocb_cmd;
251 lio->timeout = qla2x00_async_iocb_timeout;
252 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
254 sp->done = qla2x00_async_logout_sp_done;
255 rval = qla2x00_start_sp(sp);
256 if (rval != QLA_SUCCESS)
259 ql_dbg(ql_dbg_disc, vha, 0x2070,
260 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
261 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
262 fcport->d_id.b.area, fcport->d_id.b.al_pa,
269 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
274 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
277 fcport->flags &= ~FCF_ASYNC_ACTIVE;
278 /* Don't re-login in target mode */
279 if (!fcport->tgt_session)
280 qla2x00_mark_device_lost(vha, fcport, 1, 0);
281 qlt_logo_completion_handler(fcport, data[0]);
285 qla2x00_async_prlo_sp_done(void *s, int res)
287 srb_t *sp = (srb_t *)s;
288 struct srb_iocb *lio = &sp->u.iocb_cmd;
289 struct scsi_qla_host *vha = sp->vha;
291 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
292 if (!test_bit(UNLOADING, &vha->dpc_flags))
293 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
299 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
302 struct srb_iocb *lio;
305 rval = QLA_FUNCTION_FAILED;
306 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
310 sp->type = SRB_PRLO_CMD;
313 lio = &sp->u.iocb_cmd;
314 lio->timeout = qla2x00_async_iocb_timeout;
315 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
317 sp->done = qla2x00_async_prlo_sp_done;
318 rval = qla2x00_start_sp(sp);
319 if (rval != QLA_SUCCESS)
322 ql_dbg(ql_dbg_disc, vha, 0x2070,
323 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
324 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
325 fcport->d_id.b.area, fcport->d_id.b.al_pa);
331 fcport->flags &= ~FCF_ASYNC_ACTIVE;
336 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
338 struct fc_port *fcport = ea->fcport;
340 ql_dbg(ql_dbg_disc, vha, 0x20d2,
341 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
342 __func__, fcport->port_name, fcport->disc_state,
343 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
344 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
346 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
347 ql_dbg(ql_dbg_disc, vha, 0x2066,
348 "%s %8phC: adisc fail: post delete\n",
349 __func__, ea->fcport->port_name);
350 qlt_schedule_sess_for_deletion(ea->fcport);
354 if (ea->fcport->disc_state == DSC_DELETE_PEND)
357 if (ea->sp->gen2 != ea->fcport->login_gen) {
358 /* target side must have changed it. */
359 ql_dbg(ql_dbg_disc, vha, 0x20d3,
360 "%s %8phC generation changed\n",
361 __func__, ea->fcport->port_name);
363 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
364 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
365 __func__, __LINE__, ea->fcport->port_name);
366 qla24xx_post_gidpn_work(vha, ea->fcport);
370 __qla24xx_handle_gpdb_event(vha, ea);
374 qla2x00_async_adisc_sp_done(void *ptr, int res)
377 struct scsi_qla_host *vha = sp->vha;
379 struct srb_iocb *lio = &sp->u.iocb_cmd;
381 ql_dbg(ql_dbg_disc, vha, 0x2066,
382 "Async done-%s res %x %8phC\n",
383 sp->name, res, sp->fcport->port_name);
385 sp->fcport->flags &= ~FCF_ASYNC_SENT;
387 memset(&ea, 0, sizeof(ea));
388 ea.event = FCME_ADISC_DONE;
390 ea.data[0] = lio->u.logio.data[0];
391 ea.data[1] = lio->u.logio.data[1];
392 ea.iop[0] = lio->u.logio.iop[0];
393 ea.iop[1] = lio->u.logio.iop[1];
394 ea.fcport = sp->fcport;
397 qla2x00_fcport_event_handler(vha, &ea);
403 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
407 struct srb_iocb *lio;
410 rval = QLA_FUNCTION_FAILED;
411 fcport->flags |= FCF_ASYNC_SENT;
412 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
416 sp->type = SRB_ADISC_CMD;
419 lio = &sp->u.iocb_cmd;
420 lio->timeout = qla2x00_async_iocb_timeout;
421 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
423 sp->done = qla2x00_async_adisc_sp_done;
424 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
425 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
426 rval = qla2x00_start_sp(sp);
427 if (rval != QLA_SUCCESS)
430 ql_dbg(ql_dbg_disc, vha, 0x206f,
431 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
432 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
438 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
439 qla2x00_post_async_adisc_work(vha, fcport, data);
443 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
444 struct event_arg *ea)
446 fc_port_t *fcport, *conflict_fcport;
447 struct get_name_list_extended *e;
448 u16 i, n, found = 0, loop_id;
452 u8 current_login_state;
455 ql_dbg(ql_dbg_disc, vha, 0xffff,
456 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
457 __func__, fcport->port_name, fcport->disc_state,
458 fcport->fw_login_state, ea->rc,
459 fcport->login_gen, fcport->last_login_gen,
460 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
462 if (fcport->disc_state == DSC_DELETE_PEND)
465 if (ea->rc) { /* rval */
466 if (fcport->login_retry == 0) {
467 fcport->login_retry = vha->hw->login_retry_count;
468 ql_dbg(ql_dbg_disc, vha, 0x20de,
469 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
470 fcport->port_name, fcport->login_retry);
475 if (fcport->last_rscn_gen != fcport->rscn_gen) {
476 ql_dbg(ql_dbg_disc, vha, 0x20df,
477 "%s %8phC rscn gen changed rscn %d|%d \n",
478 __func__, fcport->port_name,
479 fcport->last_rscn_gen, fcport->rscn_gen);
480 qla24xx_post_gidpn_work(vha, fcport);
482 } else if (fcport->last_login_gen != fcport->login_gen) {
483 ql_dbg(ql_dbg_disc, vha, 0x20e0,
484 "%s %8phC login gen changed\n",
485 __func__, fcport->port_name);
489 n = ea->data[0] / sizeof(struct get_name_list_extended);
491 ql_dbg(ql_dbg_disc, vha, 0x20e1,
492 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
493 __func__, __LINE__, fcport->port_name, n,
494 fcport->d_id.b.domain, fcport->d_id.b.area,
495 fcport->d_id.b.al_pa, fcport->loop_id);
497 for (i = 0; i < n; i++) {
499 wwn = wwn_to_u64(e->port_name);
501 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
505 id.b.domain = e->port_id[2];
506 id.b.area = e->port_id[1];
507 id.b.al_pa = e->port_id[0];
510 loop_id = le16_to_cpu(e->nport_handle);
511 loop_id = (loop_id & 0x7fff);
513 ql_dbg(ql_dbg_disc, vha, 0x20e2,
514 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
515 __func__, fcport->port_name,
516 e->current_login_state, fcport->fw_login_state,
517 id.b.domain, id.b.area, id.b.al_pa,
518 fcport->d_id.b.domain, fcport->d_id.b.area,
519 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
521 if ((id.b24 != fcport->d_id.b24) ||
522 ((fcport->loop_id != FC_NO_LOOP_ID) &&
523 (fcport->loop_id != loop_id))) {
524 ql_dbg(ql_dbg_disc, vha, 0x20e3,
525 "%s %d %8phC post del sess\n",
526 __func__, __LINE__, fcport->port_name);
527 qlt_schedule_sess_for_deletion(fcport);
531 fcport->loop_id = loop_id;
533 wwn = wwn_to_u64(fcport->port_name);
534 qlt_find_sess_invalidate_other(vha, wwn,
535 id, loop_id, &conflict_fcport);
537 if (conflict_fcport) {
539 * Another share fcport share the same loop_id &
540 * nport id. Conflict fcport needs to finish
541 * cleanup before this fcport can proceed to login.
543 conflict_fcport->conflict = fcport;
544 fcport->login_pause = 1;
547 if (fcport->fc4f_nvme)
548 current_login_state = e->current_login_state >> 4;
550 current_login_state = e->current_login_state & 0xf;
552 switch (current_login_state) {
553 case DSC_LS_PRLI_COMP:
554 ql_dbg(ql_dbg_disc, vha, 0x20e4,
555 "%s %d %8phC post gpdb\n",
556 __func__, __LINE__, fcport->port_name);
558 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
559 fcport->port_type = FCT_INITIATOR;
561 fcport->port_type = FCT_TARGET;
563 data[0] = data[1] = 0;
564 qla2x00_post_async_adisc_work(vha, fcport, data);
566 case DSC_LS_PORT_UNAVAIL:
568 if (fcport->loop_id == FC_NO_LOOP_ID) {
569 qla2x00_find_new_loop_id(vha, fcport);
570 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
572 ql_dbg(ql_dbg_disc, vha, 0x20e5,
574 __func__, __LINE__, fcport->port_name);
575 qla24xx_fcport_handle_login(vha, fcport);
581 /* fw has no record of this port */
582 for (i = 0; i < n; i++) {
584 id.b.domain = e->port_id[0];
585 id.b.area = e->port_id[1];
586 id.b.al_pa = e->port_id[2];
588 loop_id = le16_to_cpu(e->nport_handle);
590 if (fcport->d_id.b24 == id.b24) {
592 qla2x00_find_fcport_by_wwpn(vha,
594 if (conflict_fcport) {
595 qlt_schedule_sess_for_deletion
597 ql_dbg(ql_dbg_disc, vha, 0x20e6,
598 "%s %d %8phC post del sess\n",
600 conflict_fcport->port_name);
604 /* FW already picked this loop id for another fcport */
605 if (fcport->loop_id == loop_id)
606 fcport->loop_id = FC_NO_LOOP_ID;
608 qla24xx_fcport_handle_login(vha, fcport);
613 qla24xx_async_gnl_sp_done(void *s, int res)
616 struct scsi_qla_host *vha = sp->vha;
618 struct fc_port *fcport = NULL, *tf;
619 u16 i, n = 0, loop_id;
621 struct get_name_list_extended *e;
626 ql_dbg(ql_dbg_disc, vha, 0x20e7,
627 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
628 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
629 sp->u.iocb_cmd.u.mbx.in_mb[2]);
631 memset(&ea, 0, sizeof(ea));
634 ea.event = FCME_GNL_DONE;
636 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
637 sizeof(struct get_name_list_extended)) {
638 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
639 sizeof(struct get_name_list_extended);
640 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
643 for (i = 0; i < n; i++) {
645 loop_id = le16_to_cpu(e->nport_handle);
646 /* mask out reserve bit */
647 loop_id = (loop_id & 0x7fff);
648 set_bit(loop_id, vha->hw->loop_id_map);
649 wwn = wwn_to_u64(e->port_name);
651 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
652 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
653 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
654 e->port_id[0], e->current_login_state, e->last_login_state,
658 spin_lock_irqsave(&vha->gnl.fcports_lock, flags);
662 if (!list_empty(&vha->gnl.fcports))
663 list_splice_init(&vha->gnl.fcports, &h);
665 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
666 list_del_init(&fcport->gnl_entry);
667 spin_lock(&vha->hw->tgt.sess_lock);
668 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
669 spin_unlock(&vha->hw->tgt.sess_lock);
672 qla2x00_fcport_event_handler(vha, &ea);
674 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
676 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
677 /* create new fcport if fw has knowledge of new sessions */
678 for (i = 0; i < n; i++) {
683 wwn = wwn_to_u64(e->port_name);
686 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
687 if (!memcmp((u8 *)&wwn, fcport->port_name,
694 id.b.domain = e->port_id[2];
695 id.b.area = e->port_id[1];
696 id.b.al_pa = e->port_id[0];
699 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
700 ql_dbg(ql_dbg_disc, vha, 0x2065,
701 "%s %d %8phC %06x post new sess\n",
702 __func__, __LINE__, (u8 *)&wwn, id.b24);
703 wwnn = wwn_to_u64(e->node_name);
704 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
705 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
709 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
714 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
717 struct srb_iocb *mbx;
718 int rval = QLA_FUNCTION_FAILED;
722 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
725 ql_dbg(ql_dbg_disc, vha, 0x20d9,
726 "Async-gnlist WWPN %8phC \n", fcport->port_name);
728 spin_lock_irqsave(&vha->gnl.fcports_lock, flags);
729 if (!list_empty(&fcport->gnl_entry)) {
730 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
735 spin_lock(&vha->hw->tgt.sess_lock);
736 fcport->disc_state = DSC_GNL;
737 fcport->last_rscn_gen = fcport->rscn_gen;
738 fcport->last_login_gen = fcport->login_gen;
739 spin_unlock(&vha->hw->tgt.sess_lock);
741 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
742 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
744 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
748 fcport->flags |= FCF_ASYNC_SENT;
749 sp->type = SRB_MB_IOCB;
751 sp->gen1 = fcport->rscn_gen;
752 sp->gen2 = fcport->login_gen;
754 mbx = &sp->u.iocb_cmd;
755 mbx->timeout = qla2x00_async_iocb_timeout;
756 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
758 mb = sp->u.iocb_cmd.u.mbx.out_mb;
759 mb[0] = MBC_PORT_NODE_NAME_LIST;
760 mb[1] = BIT_2 | BIT_3;
761 mb[2] = MSW(vha->gnl.ldma);
762 mb[3] = LSW(vha->gnl.ldma);
763 mb[6] = MSW(MSD(vha->gnl.ldma));
764 mb[7] = LSW(MSD(vha->gnl.ldma));
765 mb[8] = vha->gnl.size;
768 sp->done = qla24xx_async_gnl_sp_done;
770 rval = qla2x00_start_sp(sp);
771 if (rval != QLA_SUCCESS)
774 ql_dbg(ql_dbg_disc, vha, 0x20da,
775 "Async-%s - OUT WWPN %8phC hndl %x\n",
776 sp->name, fcport->port_name, sp->handle);
782 fcport->flags &= ~FCF_ASYNC_SENT;
787 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
789 struct qla_work_evt *e;
791 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
793 return QLA_FUNCTION_FAILED;
795 e->u.fcport.fcport = fcport;
796 fcport->flags |= FCF_ASYNC_ACTIVE;
797 return qla2x00_post_work(vha, e);
801 void qla24xx_async_gpdb_sp_done(void *s, int res)
804 struct scsi_qla_host *vha = sp->vha;
805 struct qla_hw_data *ha = vha->hw;
806 fc_port_t *fcport = sp->fcport;
807 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
810 ql_dbg(ql_dbg_disc, vha, 0x20db,
811 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
812 sp->name, res, fcport->port_name, mb[1], mb[2]);
814 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
816 memset(&ea, 0, sizeof(ea));
817 ea.event = FCME_GPDB_DONE;
821 qla2x00_fcport_event_handler(vha, &ea);
823 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
824 sp->u.iocb_cmd.u.mbx.in_dma);
829 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
831 struct qla_work_evt *e;
833 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
835 return QLA_FUNCTION_FAILED;
837 e->u.fcport.fcport = fcport;
839 return qla2x00_post_work(vha, e);
843 qla2x00_async_prli_sp_done(void *ptr, int res)
846 struct scsi_qla_host *vha = sp->vha;
847 struct srb_iocb *lio = &sp->u.iocb_cmd;
850 ql_dbg(ql_dbg_disc, vha, 0x2129,
851 "%s %8phC res %d \n", __func__,
852 sp->fcport->port_name, res);
854 sp->fcport->flags &= ~FCF_ASYNC_SENT;
856 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
857 memset(&ea, 0, sizeof(ea));
858 ea.event = FCME_PRLI_DONE;
859 ea.fcport = sp->fcport;
860 ea.data[0] = lio->u.logio.data[0];
861 ea.data[1] = lio->u.logio.data[1];
862 ea.iop[0] = lio->u.logio.iop[0];
863 ea.iop[1] = lio->u.logio.iop[1];
866 qla2x00_fcport_event_handler(vha, &ea);
873 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
876 struct srb_iocb *lio;
877 int rval = QLA_FUNCTION_FAILED;
879 if (!vha->flags.online)
882 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
883 fcport->fw_login_state == DSC_LS_PRLI_PEND)
886 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
890 fcport->flags |= FCF_ASYNC_SENT;
891 fcport->logout_completed = 0;
893 sp->type = SRB_PRLI_CMD;
896 lio = &sp->u.iocb_cmd;
897 lio->timeout = qla2x00_async_iocb_timeout;
898 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
900 sp->done = qla2x00_async_prli_sp_done;
901 lio->u.logio.flags = 0;
903 if (fcport->fc4f_nvme)
904 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
906 rval = qla2x00_start_sp(sp);
907 if (rval != QLA_SUCCESS) {
908 fcport->flags |= FCF_LOGIN_NEEDED;
909 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
913 ql_dbg(ql_dbg_disc, vha, 0x211b,
914 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
915 fcport->port_name, sp->handle, fcport->loop_id,
916 fcport->d_id.b24, fcport->login_retry);
922 fcport->flags &= ~FCF_ASYNC_SENT;
926 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
928 struct qla_work_evt *e;
930 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
932 return QLA_FUNCTION_FAILED;
934 e->u.fcport.fcport = fcport;
935 e->u.fcport.opt = opt;
936 fcport->flags |= FCF_ASYNC_ACTIVE;
937 return qla2x00_post_work(vha, e);
940 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
943 struct srb_iocb *mbx;
944 int rval = QLA_FUNCTION_FAILED;
947 struct port_database_24xx *pd;
948 struct qla_hw_data *ha = vha->hw;
950 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
953 fcport->disc_state = DSC_GPDB;
955 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
959 fcport->flags |= FCF_ASYNC_SENT;
960 sp->type = SRB_MB_IOCB;
962 sp->gen1 = fcport->rscn_gen;
963 sp->gen2 = fcport->login_gen;
965 mbx = &sp->u.iocb_cmd;
966 mbx->timeout = qla2x00_async_iocb_timeout;
967 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
969 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
971 ql_log(ql_log_warn, vha, 0xd043,
972 "Failed to allocate port database structure.\n");
976 mb = sp->u.iocb_cmd.u.mbx.out_mb;
977 mb[0] = MBC_GET_PORT_DATABASE;
978 mb[1] = fcport->loop_id;
981 mb[6] = MSW(MSD(pd_dma));
982 mb[7] = LSW(MSD(pd_dma));
986 mbx->u.mbx.in = (void *)pd;
987 mbx->u.mbx.in_dma = pd_dma;
989 sp->done = qla24xx_async_gpdb_sp_done;
991 rval = qla2x00_start_sp(sp);
992 if (rval != QLA_SUCCESS)
995 ql_dbg(ql_dbg_disc, vha, 0x20dc,
996 "Async-%s %8phC hndl %x opt %x\n",
997 sp->name, fcport->port_name, sp->handle, opt);
1003 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1006 fcport->flags &= ~FCF_ASYNC_SENT;
1008 qla24xx_post_gpdb_work(vha, fcport, opt);
1013 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1015 unsigned long flags;
1017 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1018 ea->fcport->login_gen++;
1019 ea->fcport->deleted = 0;
1020 ea->fcport->logout_on_delete = 1;
1022 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1023 vha->fcport_count++;
1024 ea->fcport->login_succ = 1;
1026 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1027 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1028 __func__, __LINE__, ea->fcport->port_name,
1030 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1031 } else if (ea->fcport->login_succ) {
1033 * We have an existing session. A late RSCN delivery
1034 * must have triggered the session to be re-validate.
1035 * Session is still valid.
1037 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1038 "%s %d %8phC session revalidate success\n",
1039 __func__, __LINE__, ea->fcport->port_name);
1040 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1042 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1046 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1048 fc_port_t *fcport = ea->fcport;
1049 struct port_database_24xx *pd;
1050 struct srb *sp = ea->sp;
1053 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1055 fcport->flags &= ~FCF_ASYNC_SENT;
1057 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1058 "%s %8phC DS %d LS %d rc %d\n", __func__, fcport->port_name,
1059 fcport->disc_state, pd->current_login_state, ea->rc);
1061 if (fcport->disc_state == DSC_DELETE_PEND)
1064 if (fcport->fc4f_nvme)
1065 ls = pd->current_login_state >> 4;
1067 ls = pd->current_login_state & 0xf;
1070 case PDS_PRLI_COMPLETE:
1071 __qla24xx_parse_gpdb(vha, fcport, pd);
1073 case PDS_PLOGI_PENDING:
1074 case PDS_PLOGI_COMPLETE:
1075 case PDS_PRLI_PENDING:
1076 case PDS_PRLI2_PENDING:
1077 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC relogin needed\n",
1078 __func__, __LINE__, fcport->port_name);
1079 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1081 case PDS_LOGO_PENDING:
1082 case PDS_PORT_UNAVAILABLE:
1084 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1085 __func__, __LINE__, fcport->port_name);
1086 qlt_schedule_sess_for_deletion(fcport);
1089 __qla24xx_handle_gpdb_event(vha, ea);
1092 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1097 if (qla_tgt_mode_enabled(vha))
1100 if (qla_dual_mode_enabled(vha)) {
1101 if (N2N_TOPO(vha->hw)) {
1104 mywwn = wwn_to_u64(vha->port_name);
1105 wwn = wwn_to_u64(fcport->port_name);
1108 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1109 && time_after_eq(jiffies,
1110 fcport->plogi_nack_done_deadline))
1116 /* initiator mode */
1121 if (fcport->loop_id == FC_NO_LOOP_ID) {
1122 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1123 rc = qla2x00_find_new_loop_id(vha, fcport);
1125 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1126 "%s %d %8phC post del sess - out of loopid\n",
1127 __func__, __LINE__, fcport->port_name);
1128 fcport->scan_state = 0;
1129 qlt_schedule_sess_for_deletion(fcport);
1133 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1134 "%s %d %8phC post login\n",
1135 __func__, __LINE__, fcport->port_name);
1136 qla2x00_post_async_login_work(vha, fcport, NULL);
1140 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1145 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1146 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
1147 __func__, fcport->port_name, fcport->disc_state,
1148 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1149 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1150 fcport->login_gen, fcport->login_retry,
1151 fcport->loop_id, fcport->scan_state);
1153 if (fcport->scan_state != QLA_FCPORT_FOUND)
1156 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1157 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1158 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1161 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1162 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1163 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1168 /* for pure Target Mode. Login will not be initiated */
1169 if (vha->host->active_mode == MODE_TARGET)
1172 if (fcport->flags & FCF_ASYNC_SENT) {
1173 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1177 if (fcport->login_retry > 0)
1178 fcport->login_retry--;
1180 switch (fcport->disc_state) {
1182 wwn = wwn_to_u64(fcport->node_name);
1184 ql_dbg(ql_dbg_disc, vha, 0xffff,
1185 "%s %d %8phC post GNNID\n",
1186 __func__, __LINE__, fcport->port_name);
1187 qla24xx_post_gnnid_work(vha, fcport);
1188 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1189 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1190 "%s %d %8phC post gnl\n",
1191 __func__, __LINE__, fcport->port_name);
1192 qla24xx_post_gnl_work(vha, fcport);
1194 qla_chk_n2n_b4_login(vha, fcport);
1199 if (fcport->login_pause) {
1200 fcport->last_rscn_gen = fcport->rscn_gen;
1201 fcport->last_login_gen = fcport->login_gen;
1202 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1206 qla_chk_n2n_b4_login(vha, fcport);
1209 case DSC_LOGIN_FAILED:
1210 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1211 "%s %d %8phC post gidpn\n",
1212 __func__, __LINE__, fcport->port_name);
1213 if (N2N_TOPO(vha->hw))
1214 qla_chk_n2n_b4_login(vha, fcport);
1216 qla24xx_post_gidpn_work(vha, fcport);
1219 case DSC_LOGIN_COMPLETE:
1220 /* recheck login state */
1221 ql_dbg(ql_dbg_disc, vha, 0x20d1,
1222 "%s %d %8phC post adisc\n",
1223 __func__, __LINE__, fcport->port_name);
1224 data[0] = data[1] = 0;
1225 qla2x00_post_async_adisc_work(vha, fcport, data);
1228 case DSC_LOGIN_PEND:
1229 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1230 qla24xx_post_prli_work(vha, fcport);
1241 void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1245 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1246 "%s %8phC DS %d LS %d\n",
1247 __func__, fcport->port_name, fcport->disc_state,
1248 fcport->fw_login_state);
1250 if (fcport->flags & FCF_ASYNC_SENT)
1253 switch (fcport->disc_state) {
1255 case DSC_LOGIN_COMPLETE:
1256 qla24xx_post_gpnid_work(fcport->vha, &ea->id);
1263 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1264 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1266 struct qla_work_evt *e;
1267 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1269 return QLA_FUNCTION_FAILED;
1271 e->u.new_sess.id = *id;
1272 e->u.new_sess.pla = pla;
1273 e->u.new_sess.fc4_type = fc4_type;
1274 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1276 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1278 return qla2x00_post_work(vha, e);
1282 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1283 struct event_arg *ea)
1285 fc_port_t *fcport = ea->fcport;
1287 ql_dbg(ql_dbg_disc, vha, 0x2102,
1288 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1289 __func__, fcport->port_name, fcport->disc_state,
1290 fcport->fw_login_state, fcport->login_pause,
1291 fcport->deleted, fcport->conflict,
1292 fcport->last_rscn_gen, fcport->rscn_gen,
1293 fcport->last_login_gen, fcport->login_gen,
1296 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1297 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1300 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1301 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1302 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1307 if (fcport->flags & FCF_ASYNC_SENT) {
1308 fcport->login_retry++;
1309 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1313 if (fcport->disc_state == DSC_DELETE_PEND) {
1314 fcport->login_retry++;
1318 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1319 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1320 __func__, __LINE__, fcport->port_name);
1322 qla24xx_post_gidpn_work(vha, fcport);
1326 qla24xx_fcport_handle_login(vha, fcport);
1329 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1332 uint32_t id = 0, mask, rid;
1333 unsigned long flags;
1336 switch (ea->event) {
1338 if (test_bit(UNLOADING, &vha->dpc_flags))
1341 qla24xx_handle_relogin_event(vha, ea);
1344 if (test_bit(UNLOADING, &vha->dpc_flags))
1346 switch (ea->id.b.rsvd_1) {
1347 case RSCN_PORT_ADDR:
1348 fcport = qla2x00_find_fcport_by_nportid
1351 fcport->rscn_rcvd = 1;
1353 spin_lock_irqsave(&vha->work_lock, flags);
1354 if (vha->scan.scan_flags == 0) {
1355 ql_dbg(ql_dbg_disc, vha, 0xffff,
1356 "%s: schedule\n", __func__);
1357 vha->scan.scan_flags |= SF_QUEUED;
1358 schedule_delayed_work(&vha->scan.scan_work, 5);
1360 spin_unlock_irqrestore(&vha->work_lock, flags);
1363 case RSCN_AREA_ADDR:
1365 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1367 ql_dbg(ql_dbg_async, vha, 0x5044,
1368 "RSCN: Area 0x%06x was affected\n",
1372 ql_dbg(ql_dbg_async, vha, 0x507a,
1373 "RSCN: Domain 0x%06x was affected\n",
1377 rid = ea->id.b24 & mask;
1378 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1380 id = f->d_id.b24 & mask;
1383 qla24xx_handle_rscn_event(f, ea);
1389 ql_log(ql_log_warn, vha, 0xd045,
1390 "RSCN: Fabric was affected. Addr format %d\n",
1392 qla2x00_mark_all_devices_lost(vha, 1);
1393 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1394 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1397 case FCME_GIDPN_DONE:
1398 qla24xx_handle_gidpn_event(vha, ea);
1401 qla24xx_handle_gnl_done_event(vha, ea);
1403 case FCME_GPSC_DONE:
1404 qla24xx_handle_gpsc_event(vha, ea);
1406 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1407 qla24xx_handle_plogi_done_event(vha, ea);
1409 case FCME_PRLI_DONE:
1410 qla24xx_handle_prli_done_event(vha, ea);
1412 case FCME_GPDB_DONE:
1413 qla24xx_handle_gpdb_event(vha, ea);
1415 case FCME_GPNID_DONE:
1416 qla24xx_handle_gpnid_event(vha, ea);
1418 case FCME_GFFID_DONE:
1419 qla24xx_handle_gffid_event(vha, ea);
1421 case FCME_ADISC_DONE:
1422 qla24xx_handle_adisc_event(vha, ea);
1424 case FCME_GNNID_DONE:
1425 qla24xx_handle_gnnid_event(vha, ea);
1427 case FCME_GFPNID_DONE:
1428 qla24xx_handle_gfpnid_event(vha, ea);
1437 qla2x00_tmf_iocb_timeout(void *data)
1440 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1442 tmf->u.tmf.comp_status = CS_TIMEOUT;
1443 complete(&tmf->u.tmf.comp);
1447 qla2x00_tmf_sp_done(void *ptr, int res)
1450 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1452 complete(&tmf->u.tmf.comp);
1456 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1459 struct scsi_qla_host *vha = fcport->vha;
1460 struct srb_iocb *tm_iocb;
1462 int rval = QLA_FUNCTION_FAILED;
1464 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1468 tm_iocb = &sp->u.iocb_cmd;
1469 sp->type = SRB_TM_CMD;
1472 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1473 init_completion(&tm_iocb->u.tmf.comp);
1474 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1476 tm_iocb->u.tmf.flags = flags;
1477 tm_iocb->u.tmf.lun = lun;
1478 tm_iocb->u.tmf.data = tag;
1479 sp->done = qla2x00_tmf_sp_done;
1481 rval = qla2x00_start_sp(sp);
1482 if (rval != QLA_SUCCESS)
1485 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1486 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1487 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1488 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1490 wait_for_completion(&tm_iocb->u.tmf.comp);
1492 rval = tm_iocb->u.tmf.data;
1494 if (rval != QLA_SUCCESS) {
1495 ql_log(ql_log_warn, vha, 0x8030,
1496 "TM IOCB failed (%x).\n", rval);
1499 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1500 flags = tm_iocb->u.tmf.flags;
1501 lun = (uint16_t)tm_iocb->u.tmf.lun;
1503 /* Issue Marker IOCB */
1504 qla2x00_marker(vha, vha->hw->req_q_map[0],
1505 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1506 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1511 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1517 qla24xx_abort_iocb_timeout(void *data)
1520 struct srb_iocb *abt = &sp->u.iocb_cmd;
1522 abt->u.abt.comp_status = CS_TIMEOUT;
1523 complete(&abt->u.abt.comp);
1527 qla24xx_abort_sp_done(void *ptr, int res)
1530 struct srb_iocb *abt = &sp->u.iocb_cmd;
1532 if (del_timer(&sp->u.iocb_cmd.timer))
1533 complete(&abt->u.abt.comp);
1537 qla24xx_async_abort_cmd(srb_t *cmd_sp)
1539 scsi_qla_host_t *vha = cmd_sp->vha;
1540 fc_port_t *fcport = cmd_sp->fcport;
1541 struct srb_iocb *abt_iocb;
1543 int rval = QLA_FUNCTION_FAILED;
1545 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1549 abt_iocb = &sp->u.iocb_cmd;
1550 sp->type = SRB_ABT_CMD;
1553 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1554 init_completion(&abt_iocb->u.abt.comp);
1555 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1557 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1559 if (vha->flags.qpairs_available && cmd_sp->qpair)
1560 abt_iocb->u.abt.req_que_no =
1561 cpu_to_le16(cmd_sp->qpair->req->id);
1563 abt_iocb->u.abt.req_que_no = cpu_to_le16(vha->req->id);
1565 sp->done = qla24xx_abort_sp_done;
1567 rval = qla2x00_start_sp(sp);
1568 if (rval != QLA_SUCCESS)
1571 ql_dbg(ql_dbg_async, vha, 0x507c,
1572 "Abort command issued - hdl=%x, target_id=%x\n",
1573 cmd_sp->handle, fcport->tgt_id);
1575 wait_for_completion(&abt_iocb->u.abt.comp);
1577 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1578 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1587 qla24xx_async_abort_command(srb_t *sp)
1589 unsigned long flags = 0;
1592 fc_port_t *fcport = sp->fcport;
1593 struct scsi_qla_host *vha = fcport->vha;
1594 struct qla_hw_data *ha = vha->hw;
1595 struct req_que *req = vha->req;
1597 if (vha->flags.qpairs_available && sp->qpair)
1598 req = sp->qpair->req;
1600 spin_lock_irqsave(&ha->hardware_lock, flags);
1601 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1602 if (req->outstanding_cmds[handle] == sp)
1605 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1606 if (handle == req->num_outstanding_cmds) {
1607 /* Command not found. */
1608 return QLA_FUNCTION_FAILED;
1610 if (sp->type == SRB_FXIOCB_DCMD)
1611 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1612 FXDISC_ABORT_IOCTL);
1614 return qla24xx_async_abort_cmd(sp);
1618 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1620 switch (ea->data[0]) {
1621 case MBS_COMMAND_COMPLETE:
1622 ql_dbg(ql_dbg_disc, vha, 0x2118,
1623 "%s %d %8phC post gpdb\n",
1624 __func__, __LINE__, ea->fcport->port_name);
1626 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1627 ea->fcport->logout_on_delete = 1;
1628 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1631 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1632 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1633 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1634 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1638 if (ea->fcport->n2n_flag) {
1639 ql_dbg(ql_dbg_disc, vha, 0x2118,
1640 "%s %d %8phC post fc4 prli\n",
1641 __func__, __LINE__, ea->fcport->port_name);
1642 ea->fcport->fc4f_nvme = 0;
1643 ea->fcport->n2n_flag = 0;
1644 qla24xx_post_prli_work(vha, ea->fcport);
1646 ql_dbg(ql_dbg_disc, vha, 0x2119,
1647 "%s %d %8phC unhandle event of %x\n",
1648 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1654 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1656 port_id_t cid; /* conflict Nport id */
1658 struct fc_port *conflict_fcport;
1659 unsigned long flags;
1660 struct fc_port *fcport = ea->fcport;
1662 ql_dbg(ql_dbg_disc, vha, 0xffff,
1663 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1664 __func__, fcport->port_name, fcport->disc_state,
1665 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1666 ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1,
1667 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1669 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1670 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1671 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1672 "%s %d %8phC Remote is trying to login\n",
1673 __func__, __LINE__, fcport->port_name);
1677 if (fcport->disc_state == DSC_DELETE_PEND)
1680 if (ea->sp->gen2 != fcport->login_gen) {
1681 /* target side must have changed it. */
1682 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1683 "%s %8phC generation changed\n",
1684 __func__, fcport->port_name);
1685 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1687 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1688 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
1689 __func__, __LINE__, fcport->port_name);
1690 qla24xx_post_gidpn_work(vha, fcport);
1694 switch (ea->data[0]) {
1695 case MBS_COMMAND_COMPLETE:
1697 * Driver must validate login state - If PRLI not complete,
1698 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1701 if (ea->fcport->fc4f_nvme) {
1702 ql_dbg(ql_dbg_disc, vha, 0x2117,
1703 "%s %d %8phC post prli\n",
1704 __func__, __LINE__, ea->fcport->port_name);
1705 qla24xx_post_prli_work(vha, ea->fcport);
1707 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1708 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1709 __func__, __LINE__, ea->fcport->port_name,
1710 ea->fcport->loop_id, ea->fcport->d_id.b24);
1712 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1713 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1714 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1715 ea->fcport->logout_on_delete = 1;
1716 ea->fcport->send_els_logo = 0;
1717 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
1718 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1720 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1723 case MBS_COMMAND_ERROR:
1724 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
1725 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1727 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1728 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1729 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
1730 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1732 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
1734 case MBS_LOOP_ID_USED:
1735 /* data[1] = IO PARAM 1 = nport ID */
1736 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1737 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1738 cid.b.al_pa = ea->iop[1] & 0xff;
1741 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1742 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1743 __func__, __LINE__, ea->fcport->port_name,
1744 ea->fcport->loop_id);
1746 if (IS_SW_RESV_ADDR(cid)) {
1747 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1748 ea->fcport->loop_id = FC_NO_LOOP_ID;
1750 qla2x00_clear_loop_id(ea->fcport);
1752 qla24xx_post_gnl_work(vha, ea->fcport);
1754 case MBS_PORT_ID_USED:
1755 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1756 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1757 __func__, __LINE__, ea->fcport->port_name,
1758 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1759 ea->fcport->d_id.b.al_pa);
1761 lid = ea->iop[1] & 0xffff;
1762 qlt_find_sess_invalidate_other(vha,
1763 wwn_to_u64(ea->fcport->port_name),
1764 ea->fcport->d_id, lid, &conflict_fcport);
1766 if (conflict_fcport) {
1768 * Another fcport share the same loop_id/nport id.
1769 * Conflict fcport needs to finish cleanup before this
1770 * fcport can proceed to login.
1772 conflict_fcport->conflict = ea->fcport;
1773 ea->fcport->login_pause = 1;
1775 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1776 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1777 __func__, __LINE__, ea->fcport->port_name,
1778 ea->fcport->d_id.b24, lid);
1779 qla2x00_clear_loop_id(ea->fcport);
1780 qla24xx_post_gidpn_work(vha, ea->fcport);
1782 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1783 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1784 __func__, __LINE__, ea->fcport->port_name,
1785 ea->fcport->d_id.b24, lid);
1787 qla2x00_clear_loop_id(ea->fcport);
1788 set_bit(lid, vha->hw->loop_id_map);
1789 ea->fcport->loop_id = lid;
1790 ea->fcport->keep_nport_handle = 0;
1791 qlt_schedule_sess_for_deletion(ea->fcport);
1799 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1802 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1803 qlt_logo_completion_handler(fcport, data[0]);
1804 fcport->login_gen++;
1805 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1810 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1813 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1814 if (data[0] == MBS_COMMAND_COMPLETE) {
1815 qla2x00_update_fcport(vha, fcport);
1821 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1822 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1824 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1829 /****************************************************************************/
1830 /* QLogic ISP2x00 Hardware Support Functions. */
1831 /****************************************************************************/
1834 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1836 int rval = QLA_SUCCESS;
1837 struct qla_hw_data *ha = vha->hw;
1838 uint32_t idc_major_ver, idc_minor_ver;
1841 qla83xx_idc_lock(vha, 0);
1843 /* SV: TODO: Assign initialization timeout from
1844 * flash-info / other param
1846 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1847 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1849 /* Set our fcoe function presence */
1850 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1851 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1852 "Error while setting DRV-Presence.\n");
1853 rval = QLA_FUNCTION_FAILED;
1857 /* Decide the reset ownership */
1858 qla83xx_reset_ownership(vha);
1861 * On first protocol driver load:
1862 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1864 * Others: Check compatibility with current IDC Major version.
1866 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1867 if (ha->flags.nic_core_reset_owner) {
1868 /* Set IDC Major version */
1869 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1870 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1872 /* Clearing IDC-Lock-Recovery register */
1873 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1874 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1876 * Clear further IDC participation if we are not compatible with
1877 * the current IDC Major Version.
1879 ql_log(ql_log_warn, vha, 0xb07d,
1880 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1881 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1882 __qla83xx_clear_drv_presence(vha);
1883 rval = QLA_FUNCTION_FAILED;
1886 /* Each function sets its supported Minor version. */
1887 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1888 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1889 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1891 if (ha->flags.nic_core_reset_owner) {
1892 memset(config, 0, sizeof(config));
1893 if (!qla81xx_get_port_config(vha, config))
1894 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1898 rval = qla83xx_idc_state_handler(vha);
1901 qla83xx_idc_unlock(vha, 0);
1907 * qla2x00_initialize_adapter
1911 * ha = adapter block pointer.
1917 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
1920 struct qla_hw_data *ha = vha->hw;
1921 struct req_que *req = ha->req_q_map[0];
1923 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1924 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1926 /* Clear adapter flags. */
1927 vha->flags.online = 0;
1928 ha->flags.chip_reset_done = 0;
1929 vha->flags.reset_active = 0;
1930 ha->flags.pci_channel_io_perm_failure = 0;
1931 ha->flags.eeh_busy = 0;
1932 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
1933 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
1934 atomic_set(&vha->loop_state, LOOP_DOWN);
1935 vha->device_flags = DFLG_NO_CABLE;
1937 vha->flags.management_server_logged_in = 0;
1938 vha->marker_needed = 0;
1939 ha->isp_abort_cnt = 0;
1940 ha->beacon_blink_led = 0;
1942 set_bit(0, ha->req_qid_map);
1943 set_bit(0, ha->rsp_qid_map);
1945 ql_dbg(ql_dbg_init, vha, 0x0040,
1946 "Configuring PCI space...\n");
1947 rval = ha->isp_ops->pci_config(vha);
1949 ql_log(ql_log_warn, vha, 0x0044,
1950 "Unable to configure PCI space.\n");
1954 ha->isp_ops->reset_chip(vha);
1956 rval = qla2xxx_get_flash_info(vha);
1958 ql_log(ql_log_fatal, vha, 0x004f,
1959 "Unable to validate FLASH data.\n");
1963 if (IS_QLA8044(ha)) {
1964 qla8044_read_reset_template(vha);
1966 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
1967 * If DONRESET_BIT0 is set, drivers should not set dev_state
1968 * to NEED_RESET. But if NEED_RESET is set, drivers should
1969 * should honor the reset. */
1970 if (ql2xdontresethba == 1)
1971 qla8044_set_idc_dontreset(vha);
1974 ha->isp_ops->get_flash_version(vha, req->ring);
1975 ql_dbg(ql_dbg_init, vha, 0x0061,
1976 "Configure NVRAM parameters...\n");
1978 ha->isp_ops->nvram_config(vha);
1980 if (ha->flags.disable_serdes) {
1981 /* Mask HBA via NVRAM settings? */
1982 ql_log(ql_log_info, vha, 0x0077,
1983 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
1984 return QLA_FUNCTION_FAILED;
1987 ql_dbg(ql_dbg_init, vha, 0x0078,
1988 "Verifying loaded RISC code...\n");
1990 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
1991 rval = ha->isp_ops->chip_diag(vha);
1994 rval = qla2x00_setup_chip(vha);
1999 if (IS_QLA84XX(ha)) {
2000 ha->cs84xx = qla84xx_get_chip(vha);
2002 ql_log(ql_log_warn, vha, 0x00d0,
2003 "Unable to configure ISP84XX.\n");
2004 return QLA_FUNCTION_FAILED;
2008 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2009 rval = qla2x00_init_rings(vha);
2011 ha->flags.chip_reset_done = 1;
2013 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2014 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2015 rval = qla84xx_init_chip(vha);
2016 if (rval != QLA_SUCCESS) {
2017 ql_log(ql_log_warn, vha, 0x00d4,
2018 "Unable to initialize ISP84XX.\n");
2019 qla84xx_put_chip(vha);
2023 /* Load the NIC Core f/w if we are the first protocol driver. */
2024 if (IS_QLA8031(ha)) {
2025 rval = qla83xx_nic_core_fw_load(vha);
2027 ql_log(ql_log_warn, vha, 0x0124,
2028 "Error in initializing NIC Core f/w.\n");
2031 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2032 qla24xx_read_fcp_prio_cfg(vha);
2034 if (IS_P3P_TYPE(ha))
2035 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2037 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2043 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2046 * Returns 0 on success.
2049 qla2100_pci_config(scsi_qla_host_t *vha)
2052 unsigned long flags;
2053 struct qla_hw_data *ha = vha->hw;
2054 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2056 pci_set_master(ha->pdev);
2057 pci_try_set_mwi(ha->pdev);
2059 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2060 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2061 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2063 pci_disable_rom(ha->pdev);
2065 /* Get PCI bus information. */
2066 spin_lock_irqsave(&ha->hardware_lock, flags);
2067 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2068 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2074 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2077 * Returns 0 on success.
2080 qla2300_pci_config(scsi_qla_host_t *vha)
2083 unsigned long flags = 0;
2085 struct qla_hw_data *ha = vha->hw;
2086 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2088 pci_set_master(ha->pdev);
2089 pci_try_set_mwi(ha->pdev);
2091 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2092 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2094 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2095 w &= ~PCI_COMMAND_INTX_DISABLE;
2096 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2099 * If this is a 2300 card and not 2312, reset the
2100 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2101 * the 2310 also reports itself as a 2300 so we need to get the
2102 * fb revision level -- a 6 indicates it really is a 2300 and
2105 if (IS_QLA2300(ha)) {
2106 spin_lock_irqsave(&ha->hardware_lock, flags);
2109 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2110 for (cnt = 0; cnt < 30000; cnt++) {
2111 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2117 /* Select FPM registers. */
2118 WRT_REG_WORD(®->ctrl_status, 0x20);
2119 RD_REG_WORD(®->ctrl_status);
2121 /* Get the fb rev level */
2122 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2124 if (ha->fb_rev == FPM_2300)
2125 pci_clear_mwi(ha->pdev);
2127 /* Deselect FPM registers. */
2128 WRT_REG_WORD(®->ctrl_status, 0x0);
2129 RD_REG_WORD(®->ctrl_status);
2131 /* Release RISC module. */
2132 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2133 for (cnt = 0; cnt < 30000; cnt++) {
2134 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2140 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2143 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2145 pci_disable_rom(ha->pdev);
2147 /* Get PCI bus information. */
2148 spin_lock_irqsave(&ha->hardware_lock, flags);
2149 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2150 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2156 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2159 * Returns 0 on success.
2162 qla24xx_pci_config(scsi_qla_host_t *vha)
2165 unsigned long flags = 0;
2166 struct qla_hw_data *ha = vha->hw;
2167 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2169 pci_set_master(ha->pdev);
2170 pci_try_set_mwi(ha->pdev);
2172 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2173 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2174 w &= ~PCI_COMMAND_INTX_DISABLE;
2175 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2177 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2179 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2180 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2181 pcix_set_mmrbc(ha->pdev, 2048);
2183 /* PCIe -- adjust Maximum Read Request Size (2048). */
2184 if (pci_is_pcie(ha->pdev))
2185 pcie_set_readrq(ha->pdev, 4096);
2187 pci_disable_rom(ha->pdev);
2189 ha->chip_revision = ha->pdev->revision;
2191 /* Get PCI bus information. */
2192 spin_lock_irqsave(&ha->hardware_lock, flags);
2193 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2194 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2200 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2203 * Returns 0 on success.
2206 qla25xx_pci_config(scsi_qla_host_t *vha)
2209 struct qla_hw_data *ha = vha->hw;
2211 pci_set_master(ha->pdev);
2212 pci_try_set_mwi(ha->pdev);
2214 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2215 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2216 w &= ~PCI_COMMAND_INTX_DISABLE;
2217 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2219 /* PCIe -- adjust Maximum Read Request Size (2048). */
2220 if (pci_is_pcie(ha->pdev))
2221 pcie_set_readrq(ha->pdev, 4096);
2223 pci_disable_rom(ha->pdev);
2225 ha->chip_revision = ha->pdev->revision;
2231 * qla2x00_isp_firmware() - Choose firmware image.
2234 * Returns 0 on success.
2237 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2240 uint16_t loop_id, topo, sw_cap;
2241 uint8_t domain, area, al_pa;
2242 struct qla_hw_data *ha = vha->hw;
2244 /* Assume loading risc code */
2245 rval = QLA_FUNCTION_FAILED;
2247 if (ha->flags.disable_risc_code_load) {
2248 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2250 /* Verify checksum of loaded RISC code. */
2251 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2252 if (rval == QLA_SUCCESS) {
2253 /* And, verify we are not in ROM code. */
2254 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2255 &area, &domain, &topo, &sw_cap);
2260 ql_dbg(ql_dbg_init, vha, 0x007a,
2261 "**** Load RISC code ****.\n");
2267 * qla2x00_reset_chip() - Reset ISP chip.
2270 * Returns 0 on success.
2273 qla2x00_reset_chip(scsi_qla_host_t *vha)
2275 unsigned long flags = 0;
2276 struct qla_hw_data *ha = vha->hw;
2277 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2281 if (unlikely(pci_channel_offline(ha->pdev)))
2284 ha->isp_ops->disable_intrs(ha);
2286 spin_lock_irqsave(&ha->hardware_lock, flags);
2288 /* Turn off master enable */
2290 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2291 cmd &= ~PCI_COMMAND_MASTER;
2292 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2294 if (!IS_QLA2100(ha)) {
2296 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2297 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2298 for (cnt = 0; cnt < 30000; cnt++) {
2299 if ((RD_REG_WORD(®->hccr) &
2300 HCCR_RISC_PAUSE) != 0)
2305 RD_REG_WORD(®->hccr); /* PCI Posting. */
2309 /* Select FPM registers. */
2310 WRT_REG_WORD(®->ctrl_status, 0x20);
2311 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2313 /* FPM Soft Reset. */
2314 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2315 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2317 /* Toggle Fpm Reset. */
2318 if (!IS_QLA2200(ha)) {
2319 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2320 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2323 /* Select frame buffer registers. */
2324 WRT_REG_WORD(®->ctrl_status, 0x10);
2325 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2327 /* Reset frame buffer FIFOs. */
2328 if (IS_QLA2200(ha)) {
2329 WRT_FB_CMD_REG(ha, reg, 0xa000);
2330 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2332 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2334 /* Read back fb_cmd until zero or 3 seconds max */
2335 for (cnt = 0; cnt < 3000; cnt++) {
2336 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2342 /* Select RISC module registers. */
2343 WRT_REG_WORD(®->ctrl_status, 0);
2344 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2346 /* Reset RISC processor. */
2347 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2348 RD_REG_WORD(®->hccr); /* PCI Posting. */
2350 /* Release RISC processor. */
2351 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2352 RD_REG_WORD(®->hccr); /* PCI Posting. */
2355 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2356 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2358 /* Reset ISP chip. */
2359 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2361 /* Wait for RISC to recover from reset. */
2362 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2364 * It is necessary to for a delay here since the card doesn't
2365 * respond to PCI reads during a reset. On some architectures
2366 * this will result in an MCA.
2369 for (cnt = 30000; cnt; cnt--) {
2370 if ((RD_REG_WORD(®->ctrl_status) &
2371 CSR_ISP_SOFT_RESET) == 0)
2378 /* Reset RISC processor. */
2379 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2381 WRT_REG_WORD(®->semaphore, 0);
2383 /* Release RISC processor. */
2384 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2385 RD_REG_WORD(®->hccr); /* PCI Posting. */
2387 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2388 for (cnt = 0; cnt < 30000; cnt++) {
2389 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2397 /* Turn on master enable */
2398 cmd |= PCI_COMMAND_MASTER;
2399 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2401 /* Disable RISC pause on FPM parity error. */
2402 if (!IS_QLA2100(ha)) {
2403 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2404 RD_REG_WORD(®->hccr); /* PCI Posting. */
2407 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2411 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2414 * Returns 0 on success.
2417 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2419 uint16_t mb[4] = {0x1010, 0, 1, 0};
2421 if (!IS_QLA81XX(vha->hw))
2424 return qla81xx_write_mpi_register(vha, mb);
2428 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2431 * Returns 0 on success.
2434 qla24xx_reset_risc(scsi_qla_host_t *vha)
2436 unsigned long flags = 0;
2437 struct qla_hw_data *ha = vha->hw;
2438 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2441 static int abts_cnt; /* ISP abort retry counts */
2442 int rval = QLA_SUCCESS;
2444 spin_lock_irqsave(&ha->hardware_lock, flags);
2447 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2448 for (cnt = 0; cnt < 30000; cnt++) {
2449 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2455 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2456 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2458 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2459 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2460 RD_REG_DWORD(®->hccr),
2461 RD_REG_DWORD(®->ctrl_status),
2462 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2464 WRT_REG_DWORD(®->ctrl_status,
2465 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2466 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2470 /* Wait for firmware to complete NVRAM accesses. */
2471 RD_REG_WORD(®->mailbox0);
2472 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2473 rval == QLA_SUCCESS; cnt--) {
2478 rval = QLA_FUNCTION_TIMEOUT;
2481 if (rval == QLA_SUCCESS)
2482 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2484 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2485 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2486 RD_REG_DWORD(®->hccr),
2487 RD_REG_DWORD(®->mailbox0));
2489 /* Wait for soft-reset to complete. */
2490 RD_REG_DWORD(®->ctrl_status);
2491 for (cnt = 0; cnt < 60; cnt++) {
2493 if ((RD_REG_DWORD(®->ctrl_status) &
2494 CSRX_ISP_SOFT_RESET) == 0)
2499 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2500 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2502 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2503 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2504 RD_REG_DWORD(®->hccr),
2505 RD_REG_DWORD(®->ctrl_status));
2507 /* If required, do an MPI FW reset now */
2508 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2509 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2510 if (++abts_cnt < 5) {
2511 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2512 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2515 * We exhausted the ISP abort retries. We have to
2516 * set the board offline.
2519 vha->flags.online = 0;
2524 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2525 RD_REG_DWORD(®->hccr);
2527 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2528 RD_REG_DWORD(®->hccr);
2530 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2531 RD_REG_DWORD(®->hccr);
2533 RD_REG_WORD(®->mailbox0);
2534 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2535 rval == QLA_SUCCESS; cnt--) {
2540 rval = QLA_FUNCTION_TIMEOUT;
2542 if (rval == QLA_SUCCESS)
2543 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2545 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2546 "Host Risc 0x%x, mailbox0 0x%x\n",
2547 RD_REG_DWORD(®->hccr),
2548 RD_REG_WORD(®->mailbox0));
2550 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2552 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2553 "Driver in %s mode\n",
2554 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2556 if (IS_NOPOLLING_TYPE(ha))
2557 ha->isp_ops->enable_intrs(ha);
2563 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2565 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2567 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2568 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2573 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2575 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2577 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2578 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2582 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2585 uint delta_msec = 100;
2586 uint elapsed_msec = 0;
2590 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2591 vha->hw->pdev->subsystem_device != 0x0240)
2594 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2598 timeout_msec = TIMEOUT_SEMAPHORE;
2599 n = timeout_msec / delta_msec;
2601 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2602 qla25xx_read_risc_sema_reg(vha, &wd32);
2603 if (wd32 & RISC_SEMAPHORE)
2606 elapsed_msec += delta_msec;
2607 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2611 if (!(wd32 & RISC_SEMAPHORE))
2614 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2617 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2618 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2619 n = timeout_msec / delta_msec;
2621 qla25xx_read_risc_sema_reg(vha, &wd32);
2622 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2625 elapsed_msec += delta_msec;
2626 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2630 if (wd32 & RISC_SEMAPHORE_FORCE)
2631 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2636 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2643 * qla24xx_reset_chip() - Reset ISP24xx chip.
2646 * Returns 0 on success.
2649 qla24xx_reset_chip(scsi_qla_host_t *vha)
2651 struct qla_hw_data *ha = vha->hw;
2653 if (pci_channel_offline(ha->pdev) &&
2654 ha->flags.pci_channel_io_perm_failure) {
2658 ha->isp_ops->disable_intrs(ha);
2660 qla25xx_manipulate_risc_semaphore(vha);
2662 /* Perform RISC reset. */
2663 qla24xx_reset_risc(vha);
2667 * qla2x00_chip_diag() - Test chip for proper operation.
2670 * Returns 0 on success.
2673 qla2x00_chip_diag(scsi_qla_host_t *vha)
2676 struct qla_hw_data *ha = vha->hw;
2677 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2678 unsigned long flags = 0;
2682 struct req_que *req = ha->req_q_map[0];
2684 /* Assume a failed state */
2685 rval = QLA_FUNCTION_FAILED;
2687 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2688 ®->flash_address);
2690 spin_lock_irqsave(&ha->hardware_lock, flags);
2692 /* Reset ISP chip. */
2693 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2696 * We need to have a delay here since the card will not respond while
2697 * in reset causing an MCA on some architectures.
2700 data = qla2x00_debounce_register(®->ctrl_status);
2701 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2703 data = RD_REG_WORD(®->ctrl_status);
2708 goto chip_diag_failed;
2710 ql_dbg(ql_dbg_init, vha, 0x007c,
2711 "Reset register cleared by chip reset.\n");
2713 /* Reset RISC processor. */
2714 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2715 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2717 /* Workaround for QLA2312 PCI parity error */
2718 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2719 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2720 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2722 data = RD_MAILBOX_REG(ha, reg, 0);
2729 goto chip_diag_failed;
2731 /* Check product ID of chip */
2732 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
2734 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2735 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2736 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2737 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2738 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2739 mb[3] != PROD_ID_3) {
2740 ql_log(ql_log_warn, vha, 0x0062,
2741 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2742 mb[1], mb[2], mb[3]);
2744 goto chip_diag_failed;
2746 ha->product_id[0] = mb[1];
2747 ha->product_id[1] = mb[2];
2748 ha->product_id[2] = mb[3];
2749 ha->product_id[3] = mb[4];
2751 /* Adjust fw RISC transfer size */
2752 if (req->length > 1024)
2753 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2755 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
2758 if (IS_QLA2200(ha) &&
2759 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2760 /* Limit firmware transfer size with a 2200A */
2761 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
2763 ha->device_type |= DT_ISP2200A;
2764 ha->fw_transfer_size = 128;
2767 /* Wrap Incoming Mailboxes Test. */
2768 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2770 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
2771 rval = qla2x00_mbx_reg_test(vha);
2773 ql_log(ql_log_warn, vha, 0x0080,
2774 "Failed mailbox send register test.\n");
2776 /* Flag a successful rval */
2778 spin_lock_irqsave(&ha->hardware_lock, flags);
2782 ql_log(ql_log_info, vha, 0x0081,
2783 "Chip diagnostics **** FAILED ****.\n");
2785 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2791 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2794 * Returns 0 on success.
2797 qla24xx_chip_diag(scsi_qla_host_t *vha)
2800 struct qla_hw_data *ha = vha->hw;
2801 struct req_que *req = ha->req_q_map[0];
2803 if (IS_P3P_TYPE(ha))
2806 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
2808 rval = qla2x00_mbx_reg_test(vha);
2810 ql_log(ql_log_warn, vha, 0x0082,
2811 "Failed mailbox send register test.\n");
2813 /* Flag a successful rval */
2821 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
2826 struct qla_hw_data *ha = vha->hw;
2829 ql_dbg(ql_dbg_init, vha, 0x00bd,
2830 "%s: Offload Mem is already allocated.\n",
2835 if (IS_FWI2_CAPABLE(ha)) {
2836 /* Allocate memory for Fibre Channel Event Buffer. */
2837 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2842 dma_free_coherent(&ha->pdev->dev,
2843 FCE_SIZE, ha->fce, ha->fce_dma);
2845 /* Allocate memory for Fibre Channel Event Buffer. */
2846 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2849 ql_log(ql_log_warn, vha, 0x00be,
2850 "Unable to allocate (%d KB) for FCE.\n",
2855 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
2856 ha->fce_mb, &ha->fce_bufs);
2858 ql_log(ql_log_warn, vha, 0x00bf,
2859 "Unable to initialize FCE (%d).\n", rval);
2860 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2862 ha->flags.fce_enabled = 0;
2865 ql_dbg(ql_dbg_init, vha, 0x00c0,
2866 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
2868 ha->flags.fce_enabled = 1;
2869 ha->fce_dma = tc_dma;
2874 dma_free_coherent(&ha->pdev->dev,
2875 EFT_SIZE, ha->eft, ha->eft_dma);
2877 /* Allocate memory for Extended Trace Buffer. */
2878 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2881 ql_log(ql_log_warn, vha, 0x00c1,
2882 "Unable to allocate (%d KB) for EFT.\n",
2887 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
2889 ql_log(ql_log_warn, vha, 0x00c2,
2890 "Unable to initialize EFT (%d).\n", rval);
2891 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2895 ql_dbg(ql_dbg_init, vha, 0x00c3,
2896 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2898 ha->eft_dma = tc_dma;
2907 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
2909 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
2910 eft_size, fce_size, mq_size;
2911 struct qla_hw_data *ha = vha->hw;
2912 struct req_que *req = ha->req_q_map[0];
2913 struct rsp_que *rsp = ha->rsp_q_map[0];
2914 struct qla2xxx_fw_dump *fw_dump;
2916 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2917 req_q_size = rsp_q_size = 0;
2919 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2920 fixed_size = sizeof(struct qla2100_fw_dump);
2921 } else if (IS_QLA23XX(ha)) {
2922 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2923 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2925 } else if (IS_FWI2_CAPABLE(ha)) {
2926 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
2927 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
2928 else if (IS_QLA81XX(ha))
2929 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
2930 else if (IS_QLA25XX(ha))
2931 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
2933 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
2935 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
2938 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
2939 mq_size = sizeof(struct qla2xxx_mq_chain);
2941 * Allocate maximum buffer size for all queues.
2942 * Resizing must be done at end-of-dump processing.
2944 mq_size += ha->max_req_queues *
2945 (req->length * sizeof(request_t));
2946 mq_size += ha->max_rsp_queues *
2947 (rsp->length * sizeof(response_t));
2949 if (ha->tgt.atio_ring)
2950 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
2951 /* Allocate memory for Fibre Channel Event Buffer. */
2952 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2956 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
2958 ql_dbg(ql_dbg_init, vha, 0x00c3,
2959 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2960 eft_size = EFT_SIZE;
2963 if (IS_QLA27XX(ha)) {
2964 if (!ha->fw_dump_template) {
2965 ql_log(ql_log_warn, vha, 0x00ba,
2966 "Failed missing fwdump template\n");
2969 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
2970 ql_dbg(ql_dbg_init, vha, 0x00fa,
2971 "-> allocating fwdump (%x bytes)...\n", dump_size);
2975 req_q_size = req->length * sizeof(request_t);
2976 rsp_q_size = rsp->length * sizeof(response_t);
2977 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
2978 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
2979 ha->chain_offset = dump_size;
2980 dump_size += mq_size + fce_size;
2982 if (ha->exchoffld_buf)
2983 dump_size += sizeof(struct qla2xxx_offld_chain) +
2985 if (ha->exlogin_buf)
2986 dump_size += sizeof(struct qla2xxx_offld_chain) +
2990 if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) {
2991 fw_dump = vmalloc(dump_size);
2993 ql_log(ql_log_warn, vha, 0x00c4,
2994 "Unable to allocate (%d KB) for firmware dump.\n",
2999 ha->fw_dump = fw_dump;
3001 ha->fw_dump_len = dump_size;
3002 ql_dbg(ql_dbg_init, vha, 0x00c5,
3003 "Allocated (%d KB) for firmware dump.\n",
3009 ha->fw_dump->signature[0] = 'Q';
3010 ha->fw_dump->signature[1] = 'L';
3011 ha->fw_dump->signature[2] = 'G';
3012 ha->fw_dump->signature[3] = 'C';
3013 ha->fw_dump->version = htonl(1);
3015 ha->fw_dump->fixed_size = htonl(fixed_size);
3016 ha->fw_dump->mem_size = htonl(mem_size);
3017 ha->fw_dump->req_q_size = htonl(req_q_size);
3018 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3020 ha->fw_dump->eft_size = htonl(eft_size);
3021 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
3022 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
3024 ha->fw_dump->header_size =
3025 htonl(offsetof(struct qla2xxx_fw_dump, isp));
3031 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3033 #define MPS_MASK 0xe0
3038 if (!IS_QLA81XX(vha->hw))
3041 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3042 if (rval != QLA_SUCCESS) {
3043 ql_log(ql_log_warn, vha, 0x0105,
3044 "Unable to acquire semaphore.\n");
3048 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3049 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3050 if (rval != QLA_SUCCESS) {
3051 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3056 if (dc == (dw & MPS_MASK))
3061 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3062 if (rval != QLA_SUCCESS) {
3063 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3067 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3068 if (rval != QLA_SUCCESS) {
3069 ql_log(ql_log_warn, vha, 0x006d,
3070 "Unable to release semaphore.\n");
3078 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3080 /* Don't try to reallocate the array */
3081 if (req->outstanding_cmds)
3084 if (!IS_FWI2_CAPABLE(ha))
3085 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3087 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3088 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3090 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3093 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3097 if (!req->outstanding_cmds) {
3099 * Try to allocate a minimal size just so we can get through
3102 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3103 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3107 if (!req->outstanding_cmds) {
3108 ql_log(ql_log_fatal, NULL, 0x0126,
3109 "Failed to allocate memory for "
3110 "outstanding_cmds for req_que %p.\n", req);
3111 req->num_outstanding_cmds = 0;
3112 return QLA_FUNCTION_FAILED;
3119 #define PRINT_FIELD(_field, _flag, _str) { \
3120 if (a0->_field & _flag) {\
3126 len = snprintf(ptr, leftover, "%s", _str); \
3133 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3136 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3137 u8 str[STR_LEN], *ptr, p;
3140 memset(str, 0, STR_LEN);
3141 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3142 ql_dbg(ql_dbg_init, vha, 0x015a,
3143 "SFP MFG Name: %s\n", str);
3145 memset(str, 0, STR_LEN);
3146 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3147 ql_dbg(ql_dbg_init, vha, 0x015c,
3148 "SFP Part Name: %s\n", str);
3151 memset(str, 0, STR_LEN);
3155 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3156 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3157 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3158 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3159 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3160 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3161 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3162 ql_dbg(ql_dbg_init, vha, 0x0160,
3163 "SFP Media: %s\n", str);
3166 memset(str, 0, STR_LEN);
3170 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3171 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3172 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3173 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3174 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3175 ql_dbg(ql_dbg_init, vha, 0x0196,
3176 "SFP Link Length: %s\n", str);
3178 memset(str, 0, STR_LEN);
3182 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3183 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3184 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3185 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3186 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3187 ql_dbg(ql_dbg_init, vha, 0x016e,
3188 "SFP FC Link Tech: %s\n", str);
3191 ql_dbg(ql_dbg_init, vha, 0x016f,
3192 "SFP Distant: %d km\n", a0->length_km);
3193 if (a0->length_100m)
3194 ql_dbg(ql_dbg_init, vha, 0x0170,
3195 "SFP Distant: %d m\n", a0->length_100m*100);
3196 if (a0->length_50um_10m)
3197 ql_dbg(ql_dbg_init, vha, 0x0189,
3198 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3199 if (a0->length_62um_10m)
3200 ql_dbg(ql_dbg_init, vha, 0x018a,
3201 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3202 if (a0->length_om4_10m)
3203 ql_dbg(ql_dbg_init, vha, 0x0194,
3204 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3205 if (a0->length_om3_10m)
3206 ql_dbg(ql_dbg_init, vha, 0x0195,
3207 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3213 * QLA_SUCCESS: no action
3214 * QLA_INTERFACE_ERROR: SFP is not there.
3215 * QLA_FUNCTION_FAILED: detected New SFP
3218 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3220 int rc = QLA_SUCCESS;
3221 struct sff_8247_a0 *a;
3222 struct qla_hw_data *ha = vha->hw;
3224 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3227 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3231 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3232 qla2xxx_print_sfp_info(vha);
3234 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3236 ha->flags.detected_lr_sfp = 1;
3238 if (a->length_km > 5 || a->length_100m > 50)
3239 ha->long_range_distance = LR_DISTANCE_10K;
3241 ha->long_range_distance = LR_DISTANCE_5K;
3243 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3244 ql_dbg(ql_dbg_async, vha, 0x507b,
3245 "Detected Long Range SFP.\n");
3248 ha->flags.detected_lr_sfp = 0;
3249 if (ha->flags.using_lr_setting)
3250 ql_dbg(ql_dbg_async, vha, 0x5084,
3251 "Detected Short Range SFP.\n");
3254 if (!vha->flags.init_done)
3261 * qla2x00_setup_chip() - Load and start RISC firmware.
3264 * Returns 0 on success.
3267 qla2x00_setup_chip(scsi_qla_host_t *vha)
3270 uint32_t srisc_address = 0;
3271 struct qla_hw_data *ha = vha->hw;
3272 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3273 unsigned long flags;
3274 uint16_t fw_major_version;
3276 if (IS_P3P_TYPE(ha)) {
3277 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3278 if (rval == QLA_SUCCESS) {
3279 qla2x00_stop_firmware(vha);
3280 goto enable_82xx_npiv;
3285 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3286 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3287 spin_lock_irqsave(&ha->hardware_lock, flags);
3288 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3289 RD_REG_WORD(®->hccr);
3290 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3293 qla81xx_mpi_sync(vha);
3295 /* Load firmware sequences */
3296 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3297 if (rval == QLA_SUCCESS) {
3298 ql_dbg(ql_dbg_init, vha, 0x00c9,
3299 "Verifying Checksum of loaded RISC code.\n");
3301 rval = qla2x00_verify_checksum(vha, srisc_address);
3302 if (rval == QLA_SUCCESS) {
3303 /* Start firmware execution. */
3304 ql_dbg(ql_dbg_init, vha, 0x00ca,
3305 "Starting firmware.\n");
3308 ha->flags.exlogins_enabled = 1;
3310 if (qla_is_exch_offld_enabled(vha))
3311 ha->flags.exchoffld_enabled = 1;
3313 rval = qla2x00_execute_fw(vha, srisc_address);
3314 /* Retrieve firmware information. */
3315 if (rval == QLA_SUCCESS) {
3316 qla24xx_detect_sfp(vha);
3318 rval = qla2x00_set_exlogins_buffer(vha);
3319 if (rval != QLA_SUCCESS)
3322 rval = qla2x00_set_exchoffld_buffer(vha);
3323 if (rval != QLA_SUCCESS)
3327 fw_major_version = ha->fw_major_version;
3328 if (IS_P3P_TYPE(ha))
3329 qla82xx_check_md_needed(vha);
3331 rval = qla2x00_get_fw_version(vha);
3332 if (rval != QLA_SUCCESS)
3334 ha->flags.npiv_supported = 0;
3335 if (IS_QLA2XXX_MIDTYPE(ha) &&
3336 (ha->fw_attributes & BIT_2)) {
3337 ha->flags.npiv_supported = 1;
3338 if ((!ha->max_npiv_vports) ||
3339 ((ha->max_npiv_vports + 1) %
3340 MIN_MULTI_ID_FABRIC))
3341 ha->max_npiv_vports =
3342 MIN_MULTI_ID_FABRIC - 1;
3344 qla2x00_get_resource_cnts(vha);
3347 * Allocate the array of outstanding commands
3348 * now that we know the firmware resources.
3350 rval = qla2x00_alloc_outstanding_cmds(ha,
3352 if (rval != QLA_SUCCESS)
3355 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3356 qla2x00_alloc_offload_mem(vha);
3358 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3359 qla2x00_alloc_fw_dump(vha);
3365 ql_log(ql_log_fatal, vha, 0x00cd,
3366 "ISP Firmware failed checksum.\n");
3372 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3373 /* Enable proper parity. */
3374 spin_lock_irqsave(&ha->hardware_lock, flags);
3377 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3379 /* SRAM, Instruction RAM and GP RAM parity */
3380 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3381 RD_REG_WORD(®->hccr);
3382 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3386 ha->flags.fac_supported = 1;
3387 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3390 rval = qla81xx_fac_get_sector_size(vha, &size);
3391 if (rval == QLA_SUCCESS) {
3392 ha->flags.fac_supported = 1;
3393 ha->fdt_block_size = size << 2;
3395 ql_log(ql_log_warn, vha, 0x00ce,
3396 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3397 ha->fw_major_version, ha->fw_minor_version,
3398 ha->fw_subminor_version);
3400 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3401 ha->flags.fac_supported = 0;
3408 ql_log(ql_log_fatal, vha, 0x00cf,
3409 "Setup chip ****FAILED****.\n");
3416 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3417 * @rsp: response queue
3419 * Beginning of request ring has initialization control block already built
3420 * by nvram config routine.
3422 * Returns 0 on success.
3425 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3430 rsp->ring_ptr = rsp->ring;
3431 rsp->ring_index = 0;
3432 rsp->status_srb = NULL;
3433 pkt = rsp->ring_ptr;
3434 for (cnt = 0; cnt < rsp->length; cnt++) {
3435 pkt->signature = RESPONSE_PROCESSED;
3441 * qla2x00_update_fw_options() - Read and process firmware options.
3444 * Returns 0 on success.
3447 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3449 uint16_t swing, emphasis, tx_sens, rx_sens;
3450 struct qla_hw_data *ha = vha->hw;
3452 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3453 qla2x00_get_fw_options(vha, ha->fw_options);
3455 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3458 /* Serial Link options. */
3459 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3460 "Serial link options.\n");
3461 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3462 (uint8_t *)&ha->fw_seriallink_options,
3463 sizeof(ha->fw_seriallink_options));
3465 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3466 if (ha->fw_seriallink_options[3] & BIT_2) {
3467 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3470 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3471 emphasis = (ha->fw_seriallink_options[2] &
3472 (BIT_4 | BIT_3)) >> 3;
3473 tx_sens = ha->fw_seriallink_options[0] &
3474 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3475 rx_sens = (ha->fw_seriallink_options[0] &
3476 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3477 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3478 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3481 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3482 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3483 ha->fw_options[10] |= BIT_5 |
3484 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3485 (tx_sens & (BIT_1 | BIT_0));
3488 swing = (ha->fw_seriallink_options[2] &
3489 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3490 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3491 tx_sens = ha->fw_seriallink_options[1] &
3492 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3493 rx_sens = (ha->fw_seriallink_options[1] &
3494 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3495 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3496 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3499 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3500 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3501 ha->fw_options[11] |= BIT_5 |
3502 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3503 (tx_sens & (BIT_1 | BIT_0));
3507 /* Return command IOCBs without waiting for an ABTS to complete. */
3508 ha->fw_options[3] |= BIT_13;
3511 if (ha->flags.enable_led_scheme)
3512 ha->fw_options[2] |= BIT_12;
3514 /* Detect ISP6312. */
3516 ha->fw_options[2] |= BIT_13;
3518 /* Set Retry FLOGI in case of P2P connection */
3519 if (ha->operating_mode == P2P) {
3520 ha->fw_options[2] |= BIT_3;
3521 ql_dbg(ql_dbg_disc, vha, 0x2100,
3522 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3523 __func__, ha->fw_options[2]);
3526 /* Update firmware options. */
3527 qla2x00_set_fw_options(vha, ha->fw_options);
3531 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3534 struct qla_hw_data *ha = vha->hw;
3536 if (IS_P3P_TYPE(ha))
3539 /* Hold status IOCBs until ABTS response received. */
3541 ha->fw_options[3] |= BIT_12;
3543 /* Set Retry FLOGI in case of P2P connection */
3544 if (ha->operating_mode == P2P) {
3545 ha->fw_options[2] |= BIT_3;
3546 ql_dbg(ql_dbg_disc, vha, 0x2101,
3547 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3548 __func__, ha->fw_options[2]);
3551 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3552 if (ql2xmvasynctoatio &&
3553 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
3554 if (qla_tgt_mode_enabled(vha) ||
3555 qla_dual_mode_enabled(vha))
3556 ha->fw_options[2] |= BIT_11;
3558 ha->fw_options[2] &= ~BIT_11;
3561 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3563 * Tell FW to track each exchange to prevent
3564 * driver from using stale exchange.
3566 if (qla_tgt_mode_enabled(vha) ||
3567 qla_dual_mode_enabled(vha))
3568 ha->fw_options[2] |= BIT_4;
3570 ha->fw_options[2] &= ~BIT_4;
3572 /* Reserve 1/2 of emergency exchanges for ELS.*/
3573 if (qla2xuseresexchforels)
3574 ha->fw_options[2] |= BIT_8;
3576 ha->fw_options[2] &= ~BIT_8;
3579 ql_dbg(ql_dbg_init, vha, 0x00e8,
3580 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3581 __func__, ha->fw_options[1], ha->fw_options[2],
3582 ha->fw_options[3], vha->host->active_mode);
3584 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3585 qla2x00_set_fw_options(vha, ha->fw_options);
3587 /* Update Serial Link options. */
3588 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3591 rval = qla2x00_set_serdes_params(vha,
3592 le16_to_cpu(ha->fw_seriallink_options24[1]),
3593 le16_to_cpu(ha->fw_seriallink_options24[2]),
3594 le16_to_cpu(ha->fw_seriallink_options24[3]));
3595 if (rval != QLA_SUCCESS) {
3596 ql_log(ql_log_warn, vha, 0x0104,
3597 "Unable to update Serial Link options (%x).\n", rval);
3602 qla2x00_config_rings(struct scsi_qla_host *vha)
3604 struct qla_hw_data *ha = vha->hw;
3605 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3606 struct req_que *req = ha->req_q_map[0];
3607 struct rsp_que *rsp = ha->rsp_q_map[0];
3609 /* Setup ring parameters in initialization control block. */
3610 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3611 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3612 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3613 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3614 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3615 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3616 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3617 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3619 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3620 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3621 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3622 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3623 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3627 qla24xx_config_rings(struct scsi_qla_host *vha)
3629 struct qla_hw_data *ha = vha->hw;
3630 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3631 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3632 struct qla_msix_entry *msix;
3633 struct init_cb_24xx *icb;
3635 struct req_que *req = ha->req_q_map[0];
3636 struct rsp_que *rsp = ha->rsp_q_map[0];
3638 /* Setup ring parameters in initialization control block. */
3639 icb = (struct init_cb_24xx *)ha->init_cb;
3640 icb->request_q_outpointer = cpu_to_le16(0);
3641 icb->response_q_inpointer = cpu_to_le16(0);
3642 icb->request_q_length = cpu_to_le16(req->length);
3643 icb->response_q_length = cpu_to_le16(rsp->length);
3644 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3645 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3646 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3647 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3649 /* Setup ATIO queue dma pointers for target mode */
3650 icb->atio_q_inpointer = cpu_to_le16(0);
3651 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3652 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3653 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3655 if (IS_SHADOW_REG_CAPABLE(ha))
3656 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3658 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3659 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3660 icb->rid = cpu_to_le16(rid);
3661 if (ha->flags.msix_enabled) {
3662 msix = &ha->msix_entries[1];
3663 ql_dbg(ql_dbg_init, vha, 0x0019,
3664 "Registering vector 0x%x for base que.\n",
3666 icb->msix = cpu_to_le16(msix->entry);
3668 /* Use alternate PCI bus number */
3670 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
3671 /* Use alternate PCI devfn */
3673 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
3675 /* Use Disable MSIX Handshake mode for capable adapters */
3676 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3677 (ha->flags.msix_enabled)) {
3678 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
3679 ha->flags.disable_msix_handshake = 1;
3680 ql_dbg(ql_dbg_init, vha, 0x00fe,
3681 "MSIX Handshake Disable Mode turned on.\n");
3683 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
3685 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
3687 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
3688 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
3689 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
3690 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
3692 WRT_REG_DWORD(®->isp24.req_q_in, 0);
3693 WRT_REG_DWORD(®->isp24.req_q_out, 0);
3694 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
3695 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
3697 qlt_24xx_config_rings(vha);
3700 RD_REG_DWORD(&ioreg->hccr);
3704 * qla2x00_init_rings() - Initializes firmware.
3707 * Beginning of request ring has initialization control block already built
3708 * by nvram config routine.
3710 * Returns 0 on success.
3713 qla2x00_init_rings(scsi_qla_host_t *vha)
3716 unsigned long flags = 0;
3718 struct qla_hw_data *ha = vha->hw;
3719 struct req_que *req;
3720 struct rsp_que *rsp;
3721 struct mid_init_cb_24xx *mid_init_cb =
3722 (struct mid_init_cb_24xx *) ha->init_cb;
3724 spin_lock_irqsave(&ha->hardware_lock, flags);
3726 /* Clear outstanding commands array. */
3727 for (que = 0; que < ha->max_req_queues; que++) {
3728 req = ha->req_q_map[que];
3729 if (!req || !test_bit(que, ha->req_qid_map))
3731 req->out_ptr = (void *)(req->ring + req->length);
3733 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
3734 req->outstanding_cmds[cnt] = NULL;
3736 req->current_outstanding_cmd = 1;
3738 /* Initialize firmware. */
3739 req->ring_ptr = req->ring;
3740 req->ring_index = 0;
3741 req->cnt = req->length;
3744 for (que = 0; que < ha->max_rsp_queues; que++) {
3745 rsp = ha->rsp_q_map[que];
3746 if (!rsp || !test_bit(que, ha->rsp_qid_map))
3748 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3750 /* Initialize response queue entries */
3752 qlafx00_init_response_q_entries(rsp);
3754 qla2x00_init_response_q_entries(rsp);
3757 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3758 ha->tgt.atio_ring_index = 0;
3759 /* Initialize ATIO queue entries */
3760 qlt_init_atio_q_entries(vha);
3762 ha->isp_ops->config_rings(vha);
3764 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3766 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3768 if (IS_QLAFX00(ha)) {
3769 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3773 /* Update any ISP specific firmware options before initialization. */
3774 ha->isp_ops->update_fw_options(vha);
3776 if (ha->flags.npiv_supported) {
3777 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
3778 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
3779 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
3782 if (IS_FWI2_CAPABLE(ha)) {
3783 mid_init_cb->options = cpu_to_le16(BIT_1);
3784 mid_init_cb->init_cb.execution_throttle =
3785 cpu_to_le16(ha->cur_fw_xcb_count);
3786 ha->flags.dport_enabled =
3787 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3788 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3789 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3790 /* FA-WWPN Status */
3791 ha->flags.fawwpn_enabled =
3792 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
3793 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
3794 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
3797 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
3800 ql_log(ql_log_fatal, vha, 0x00d2,
3801 "Init Firmware **** FAILED ****.\n");
3803 ql_dbg(ql_dbg_init, vha, 0x00d3,
3804 "Init Firmware -- success.\n");
3812 * qla2x00_fw_ready() - Waits for firmware ready.
3815 * Returns 0 on success.
3818 qla2x00_fw_ready(scsi_qla_host_t *vha)
3821 unsigned long wtime, mtime, cs84xx_time;
3822 uint16_t min_wait; /* Minimum wait time if loop is down */
3823 uint16_t wait_time; /* Wait time if loop is coming ready */
3825 struct qla_hw_data *ha = vha->hw;
3827 if (IS_QLAFX00(vha->hw))
3828 return qlafx00_fw_ready(vha);
3832 /* Time to wait for loop down */
3833 if (IS_P3P_TYPE(ha))
3839 * Firmware should take at most one RATOV to login, plus 5 seconds for
3840 * our own processing.
3842 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3843 wait_time = min_wait;
3846 /* Min wait time if loop down */
3847 mtime = jiffies + (min_wait * HZ);
3849 /* wait time before firmware ready */
3850 wtime = jiffies + (wait_time * HZ);
3852 /* Wait for ISP to finish LIP */
3853 if (!vha->flags.init_done)
3854 ql_log(ql_log_info, vha, 0x801e,
3855 "Waiting for LIP to complete.\n");
3858 memset(state, -1, sizeof(state));
3859 rval = qla2x00_get_firmware_state(vha, state);
3860 if (rval == QLA_SUCCESS) {
3861 if (state[0] < FSTATE_LOSS_OF_SYNC) {
3862 vha->device_flags &= ~DFLG_NO_CABLE;
3864 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
3865 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3866 "fw_state=%x 84xx=%x.\n", state[0],
3868 if ((state[2] & FSTATE_LOGGED_IN) &&
3869 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
3870 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3871 "Sending verify iocb.\n");
3873 cs84xx_time = jiffies;
3874 rval = qla84xx_init_chip(vha);
3875 if (rval != QLA_SUCCESS) {
3878 "Init chip failed.\n");
3882 /* Add time taken to initialize. */
3883 cs84xx_time = jiffies - cs84xx_time;
3884 wtime += cs84xx_time;
3885 mtime += cs84xx_time;
3886 ql_dbg(ql_dbg_taskm, vha, 0x8008,
3887 "Increasing wait time by %ld. "
3888 "New time %ld.\n", cs84xx_time,
3891 } else if (state[0] == FSTATE_READY) {
3892 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3893 "F/W Ready - OK.\n");
3895 qla2x00_get_retry_cnt(vha, &ha->retry_count,
3896 &ha->login_timeout, &ha->r_a_tov);
3902 rval = QLA_FUNCTION_FAILED;
3904 if (atomic_read(&vha->loop_down_timer) &&
3905 state[0] != FSTATE_READY) {
3906 /* Loop down. Timeout on min_wait for states
3907 * other than Wait for Login.
3909 if (time_after_eq(jiffies, mtime)) {
3910 ql_log(ql_log_info, vha, 0x8038,
3911 "Cable is unplugged...\n");
3913 vha->device_flags |= DFLG_NO_CABLE;
3918 /* Mailbox cmd failed. Timeout on min_wait. */
3919 if (time_after_eq(jiffies, mtime) ||
3920 ha->flags.isp82xx_fw_hung)
3924 if (time_after_eq(jiffies, wtime))
3927 /* Delay for a while */
3931 ql_dbg(ql_dbg_taskm, vha, 0x803a,
3932 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
3933 state[1], state[2], state[3], state[4], state[5], jiffies);
3935 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
3936 ql_log(ql_log_warn, vha, 0x803b,
3937 "Firmware ready **** FAILED ****.\n");
3944 * qla2x00_configure_hba
3945 * Setup adapter context.
3948 * ha = adapter state pointer.
3957 qla2x00_configure_hba(scsi_qla_host_t *vha)
3966 char connect_type[22];
3967 struct qla_hw_data *ha = vha->hw;
3968 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
3970 unsigned long flags;
3972 /* Get host addresses. */
3973 rval = qla2x00_get_adapter_id(vha,
3974 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
3975 if (rval != QLA_SUCCESS) {
3976 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
3977 IS_CNA_CAPABLE(ha) ||
3978 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
3979 ql_dbg(ql_dbg_disc, vha, 0x2008,
3980 "Loop is in a transition state.\n");
3982 ql_log(ql_log_warn, vha, 0x2009,
3983 "Unable to get host loop ID.\n");
3984 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
3985 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
3986 ql_log(ql_log_warn, vha, 0x1151,
3987 "Doing link init.\n");
3988 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
3991 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
3997 ql_log(ql_log_info, vha, 0x200a,
3998 "Cannot get topology - retrying.\n");
3999 return (QLA_FUNCTION_FAILED);
4002 vha->loop_id = loop_id;
4005 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4006 ha->operating_mode = LOOP;
4011 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4012 ha->current_topology = ISP_CFG_NL;
4013 strcpy(connect_type, "(Loop)");
4017 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4018 ha->switch_cap = sw_cap;
4019 ha->current_topology = ISP_CFG_FL;
4020 strcpy(connect_type, "(FL_Port)");
4024 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4025 ha->operating_mode = P2P;
4026 ha->current_topology = ISP_CFG_N;
4027 strcpy(connect_type, "(N_Port-to-N_Port)");
4031 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4032 ha->switch_cap = sw_cap;
4033 ha->operating_mode = P2P;
4034 ha->current_topology = ISP_CFG_F;
4035 strcpy(connect_type, "(F_Port)");
4039 ql_dbg(ql_dbg_disc, vha, 0x200f,
4040 "HBA in unknown topology %x, using NL.\n", topo);
4041 ha->current_topology = ISP_CFG_NL;
4042 strcpy(connect_type, "(Loop)");
4046 /* Save Host port and loop ID. */
4047 /* byte order - Big Endian */
4048 id.b.domain = domain;
4052 spin_lock_irqsave(&ha->hardware_lock, flags);
4053 qlt_update_host_map(vha, id);
4054 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4056 if (!vha->flags.init_done)
4057 ql_log(ql_log_info, vha, 0x2010,
4058 "Topology - %s, Host Loop address 0x%x.\n",
4059 connect_type, vha->loop_id);
4065 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4070 struct qla_hw_data *ha = vha->hw;
4071 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4072 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4074 if (memcmp(model, BINZERO, len) != 0) {
4075 strncpy(ha->model_number, model, len);
4076 st = en = ha->model_number;
4079 if (*en != 0x20 && *en != 0x00)
4084 index = (ha->pdev->subsystem_device & 0xff);
4086 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4087 index < QLA_MODEL_NAMES)
4088 strncpy(ha->model_desc,
4089 qla2x00_model_name[index * 2 + 1],
4090 sizeof(ha->model_desc) - 1);
4092 index = (ha->pdev->subsystem_device & 0xff);
4094 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4095 index < QLA_MODEL_NAMES) {
4096 strcpy(ha->model_number,
4097 qla2x00_model_name[index * 2]);
4098 strncpy(ha->model_desc,
4099 qla2x00_model_name[index * 2 + 1],
4100 sizeof(ha->model_desc) - 1);
4102 strcpy(ha->model_number, def);
4105 if (IS_FWI2_CAPABLE(ha))
4106 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4107 sizeof(ha->model_desc));
4110 /* On sparc systems, obtain port and node WWN from firmware
4113 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4116 struct qla_hw_data *ha = vha->hw;
4117 struct pci_dev *pdev = ha->pdev;
4118 struct device_node *dp = pci_device_to_OF_node(pdev);
4122 val = of_get_property(dp, "port-wwn", &len);
4123 if (val && len >= WWN_SIZE)
4124 memcpy(nv->port_name, val, WWN_SIZE);
4126 val = of_get_property(dp, "node-wwn", &len);
4127 if (val && len >= WWN_SIZE)
4128 memcpy(nv->node_name, val, WWN_SIZE);
4133 * NVRAM configuration for ISP 2xxx
4136 * ha = adapter block pointer.
4139 * initialization control block in response_ring
4140 * host adapters parameters in host adapter block
4146 qla2x00_nvram_config(scsi_qla_host_t *vha)
4151 uint8_t *dptr1, *dptr2;
4152 struct qla_hw_data *ha = vha->hw;
4153 init_cb_t *icb = ha->init_cb;
4154 nvram_t *nv = ha->nvram;
4155 uint8_t *ptr = ha->nvram;
4156 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4160 /* Determine NVRAM starting address. */
4161 ha->nvram_size = sizeof(nvram_t);
4163 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4164 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4165 ha->nvram_base = 0x80;
4167 /* Get NVRAM data and calculate checksum. */
4168 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4169 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4172 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4173 "Contents of NVRAM.\n");
4174 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4175 (uint8_t *)nv, ha->nvram_size);
4177 /* Bad NVRAM data, set defaults parameters. */
4178 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
4179 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
4180 /* Reset NVRAM data. */
4181 ql_log(ql_log_warn, vha, 0x0064,
4182 "Inconsistent NVRAM "
4183 "detected: checksum=0x%x id=%c version=0x%x.\n",
4184 chksum, nv->id[0], nv->nvram_version);
4185 ql_log(ql_log_warn, vha, 0x0065,
4187 "functioning (yet invalid -- WWPN) defaults.\n");
4190 * Set default initialization control block.
4192 memset(nv, 0, ha->nvram_size);
4193 nv->parameter_block_version = ICB_VERSION;
4195 if (IS_QLA23XX(ha)) {
4196 nv->firmware_options[0] = BIT_2 | BIT_1;
4197 nv->firmware_options[1] = BIT_7 | BIT_5;
4198 nv->add_firmware_options[0] = BIT_5;
4199 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4200 nv->frame_payload_size = 2048;
4201 nv->special_options[1] = BIT_7;
4202 } else if (IS_QLA2200(ha)) {
4203 nv->firmware_options[0] = BIT_2 | BIT_1;
4204 nv->firmware_options[1] = BIT_7 | BIT_5;
4205 nv->add_firmware_options[0] = BIT_5;
4206 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4207 nv->frame_payload_size = 1024;
4208 } else if (IS_QLA2100(ha)) {
4209 nv->firmware_options[0] = BIT_3 | BIT_1;
4210 nv->firmware_options[1] = BIT_5;
4211 nv->frame_payload_size = 1024;
4214 nv->max_iocb_allocation = cpu_to_le16(256);
4215 nv->execution_throttle = cpu_to_le16(16);
4216 nv->retry_count = 8;
4217 nv->retry_delay = 1;
4219 nv->port_name[0] = 33;
4220 nv->port_name[3] = 224;
4221 nv->port_name[4] = 139;
4223 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4225 nv->login_timeout = 4;
4228 * Set default host adapter parameters
4230 nv->host_p[1] = BIT_2;
4231 nv->reset_delay = 5;
4232 nv->port_down_retry_count = 8;
4233 nv->max_luns_per_target = cpu_to_le16(8);
4234 nv->link_down_timeout = 60;
4239 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4241 * The SN2 does not provide BIOS emulation which means you can't change
4242 * potentially bogus BIOS settings. Force the use of default settings
4243 * for link rate and frame size. Hope that the rest of the settings
4246 if (ia64_platform_is("sn2")) {
4247 nv->frame_payload_size = 2048;
4249 nv->special_options[1] = BIT_7;
4253 /* Reset Initialization control block */
4254 memset(icb, 0, ha->init_cb_size);
4257 * Setup driver NVRAM options.
4259 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4260 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4261 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4262 nv->firmware_options[1] &= ~BIT_4;
4264 if (IS_QLA23XX(ha)) {
4265 nv->firmware_options[0] |= BIT_2;
4266 nv->firmware_options[0] &= ~BIT_3;
4267 nv->special_options[0] &= ~BIT_6;
4268 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4270 if (IS_QLA2300(ha)) {
4271 if (ha->fb_rev == FPM_2310) {
4272 strcpy(ha->model_number, "QLA2310");
4274 strcpy(ha->model_number, "QLA2300");
4277 qla2x00_set_model_info(vha, nv->model_number,
4278 sizeof(nv->model_number), "QLA23xx");
4280 } else if (IS_QLA2200(ha)) {
4281 nv->firmware_options[0] |= BIT_2;
4283 * 'Point-to-point preferred, else loop' is not a safe
4284 * connection mode setting.
4286 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4288 /* Force 'loop preferred, else point-to-point'. */
4289 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4290 nv->add_firmware_options[0] |= BIT_5;
4292 strcpy(ha->model_number, "QLA22xx");
4293 } else /*if (IS_QLA2100(ha))*/ {
4294 strcpy(ha->model_number, "QLA2100");
4298 * Copy over NVRAM RISC parameter block to initialization control block.
4300 dptr1 = (uint8_t *)icb;
4301 dptr2 = (uint8_t *)&nv->parameter_block_version;
4302 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4304 *dptr1++ = *dptr2++;
4306 /* Copy 2nd half. */
4307 dptr1 = (uint8_t *)icb->add_firmware_options;
4308 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4310 *dptr1++ = *dptr2++;
4312 /* Use alternate WWN? */
4313 if (nv->host_p[1] & BIT_7) {
4314 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4315 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4318 /* Prepare nodename */
4319 if ((icb->firmware_options[1] & BIT_6) == 0) {
4321 * Firmware will apply the following mask if the nodename was
4324 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4325 icb->node_name[0] &= 0xF0;
4329 * Set host adapter parameters.
4333 * BIT_7 in the host-parameters section allows for modification to
4334 * internal driver logging.
4336 if (nv->host_p[0] & BIT_7)
4337 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4338 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4339 /* Always load RISC code on non ISP2[12]00 chips. */
4340 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4341 ha->flags.disable_risc_code_load = 0;
4342 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4343 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4344 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4345 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4346 ha->flags.disable_serdes = 0;
4348 ha->operating_mode =
4349 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4351 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4352 sizeof(ha->fw_seriallink_options));
4354 /* save HBA serial number */
4355 ha->serial0 = icb->port_name[5];
4356 ha->serial1 = icb->port_name[6];
4357 ha->serial2 = icb->port_name[7];
4358 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4359 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4361 icb->execution_throttle = cpu_to_le16(0xFFFF);
4363 ha->retry_count = nv->retry_count;
4365 /* Set minimum login_timeout to 4 seconds. */
4366 if (nv->login_timeout != ql2xlogintimeout)
4367 nv->login_timeout = ql2xlogintimeout;
4368 if (nv->login_timeout < 4)
4369 nv->login_timeout = 4;
4370 ha->login_timeout = nv->login_timeout;
4372 /* Set minimum RATOV to 100 tenths of a second. */
4375 ha->loop_reset_delay = nv->reset_delay;
4377 /* Link Down Timeout = 0:
4379 * When Port Down timer expires we will start returning
4380 * I/O's to OS with "DID_NO_CONNECT".
4382 * Link Down Timeout != 0:
4384 * The driver waits for the link to come up after link down
4385 * before returning I/Os to OS with "DID_NO_CONNECT".
4387 if (nv->link_down_timeout == 0) {
4388 ha->loop_down_abort_time =
4389 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4391 ha->link_down_timeout = nv->link_down_timeout;
4392 ha->loop_down_abort_time =
4393 (LOOP_DOWN_TIME - ha->link_down_timeout);
4397 * Need enough time to try and get the port back.
4399 ha->port_down_retry_count = nv->port_down_retry_count;
4400 if (qlport_down_retry)
4401 ha->port_down_retry_count = qlport_down_retry;
4402 /* Set login_retry_count */
4403 ha->login_retry_count = nv->retry_count;
4404 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4405 ha->port_down_retry_count > 3)
4406 ha->login_retry_count = ha->port_down_retry_count;
4407 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4408 ha->login_retry_count = ha->port_down_retry_count;
4409 if (ql2xloginretrycount)
4410 ha->login_retry_count = ql2xloginretrycount;
4412 icb->lun_enables = cpu_to_le16(0);
4413 icb->command_resource_count = 0;
4414 icb->immediate_notify_resource_count = 0;
4415 icb->timeout = cpu_to_le16(0);
4417 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4419 icb->firmware_options[0] &= ~BIT_3;
4420 icb->add_firmware_options[0] &=
4421 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4422 icb->add_firmware_options[0] |= BIT_2;
4423 icb->response_accumulation_timer = 3;
4424 icb->interrupt_delay_timer = 5;
4426 vha->flags.process_response_queue = 1;
4429 if (!vha->flags.init_done) {
4430 ha->zio_mode = icb->add_firmware_options[0] &
4431 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4432 ha->zio_timer = icb->interrupt_delay_timer ?
4433 icb->interrupt_delay_timer: 2;
4435 icb->add_firmware_options[0] &=
4436 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4437 vha->flags.process_response_queue = 0;
4438 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4439 ha->zio_mode = QLA_ZIO_MODE_6;
4441 ql_log(ql_log_info, vha, 0x0068,
4442 "ZIO mode %d enabled; timer delay (%d us).\n",
4443 ha->zio_mode, ha->zio_timer * 100);
4445 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4446 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4447 vha->flags.process_response_queue = 1;
4452 ql_log(ql_log_warn, vha, 0x0069,
4453 "NVRAM configuration failed.\n");
4459 qla2x00_rport_del(void *data)
4461 fc_port_t *fcport = data;
4462 struct fc_rport *rport;
4463 unsigned long flags;
4465 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4466 rport = fcport->drport ? fcport->drport: fcport->rport;
4467 fcport->drport = NULL;
4468 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4470 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4471 "%s %8phN. rport %p roles %x\n",
4472 __func__, fcport->port_name, rport,
4475 fc_remote_port_delete(rport);
4480 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4482 * @flags: allocation flags
4484 * Returns a pointer to the allocated fcport, or NULL, if none available.
4487 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4491 fcport = kzalloc(sizeof(fc_port_t), flags);
4495 /* Setup fcport template structure. */
4497 fcport->port_type = FCT_UNKNOWN;
4498 fcport->loop_id = FC_NO_LOOP_ID;
4499 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4500 fcport->supported_classes = FC_COS_UNSPECIFIED;
4502 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4503 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4505 fcport->disc_state = DSC_DELETED;
4506 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4507 fcport->deleted = QLA_SESS_DELETED;
4508 fcport->login_retry = vha->hw->login_retry_count;
4509 fcport->logout_on_delete = 1;
4511 if (!fcport->ct_desc.ct_sns) {
4512 ql_log(ql_log_warn, vha, 0xd049,
4513 "Failed to allocate ct_sns request.\n");
4517 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4518 INIT_LIST_HEAD(&fcport->gnl_entry);
4519 INIT_LIST_HEAD(&fcport->list);
4525 qla2x00_free_fcport(fc_port_t *fcport)
4527 if (fcport->ct_desc.ct_sns) {
4528 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4529 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4530 fcport->ct_desc.ct_sns_dma);
4532 fcport->ct_desc.ct_sns = NULL;
4538 * qla2x00_configure_loop
4539 * Updates Fibre Channel Device Database with what is actually on loop.
4542 * ha = adapter block pointer.
4547 * 2 = database was full and device was not configured.
4550 qla2x00_configure_loop(scsi_qla_host_t *vha)
4553 unsigned long flags, save_flags;
4554 struct qla_hw_data *ha = vha->hw;
4557 /* Get Initiator ID */
4558 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4559 rval = qla2x00_configure_hba(vha);
4560 if (rval != QLA_SUCCESS) {
4561 ql_dbg(ql_dbg_disc, vha, 0x2013,
4562 "Unable to configure HBA.\n");
4567 save_flags = flags = vha->dpc_flags;
4568 ql_dbg(ql_dbg_disc, vha, 0x2014,
4569 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4572 * If we have both an RSCN and PORT UPDATE pending then handle them
4573 * both at the same time.
4575 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4576 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4578 qla2x00_get_data_rate(vha);
4580 /* Determine what we need to do */
4581 if (ha->current_topology == ISP_CFG_FL &&
4582 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4584 set_bit(RSCN_UPDATE, &flags);
4586 } else if (ha->current_topology == ISP_CFG_F &&
4587 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4589 set_bit(RSCN_UPDATE, &flags);
4590 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4592 } else if (ha->current_topology == ISP_CFG_N) {
4593 clear_bit(RSCN_UPDATE, &flags);
4594 if (ha->flags.rida_fmt2) {
4595 /* With Rida Format 2, the login is already triggered.
4596 * We know who is on the other side of the wire.
4597 * No need to login to do login to find out or drop into
4598 * qla2x00_configure_local_loop().
4600 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4601 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4603 if (qla_tgt_mode_enabled(vha)) {
4604 /* allow the other side to start the login */
4605 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4606 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4609 } else if (ha->current_topology == ISP_CFG_NL) {
4610 clear_bit(RSCN_UPDATE, &flags);
4611 set_bit(LOCAL_LOOP_UPDATE, &flags);
4612 } else if (!vha->flags.online ||
4613 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4614 set_bit(RSCN_UPDATE, &flags);
4615 set_bit(LOCAL_LOOP_UPDATE, &flags);
4618 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4619 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4620 ql_dbg(ql_dbg_disc, vha, 0x2015,
4621 "Loop resync needed, failing.\n");
4622 rval = QLA_FUNCTION_FAILED;
4624 rval = qla2x00_configure_local_loop(vha);
4627 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4628 if (LOOP_TRANSITION(vha)) {
4629 ql_dbg(ql_dbg_disc, vha, 0x2099,
4630 "Needs RSCN update and loop transition.\n");
4631 rval = QLA_FUNCTION_FAILED;
4634 rval = qla2x00_configure_fabric(vha);
4637 if (rval == QLA_SUCCESS) {
4638 if (atomic_read(&vha->loop_down_timer) ||
4639 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4640 rval = QLA_FUNCTION_FAILED;
4642 atomic_set(&vha->loop_state, LOOP_READY);
4643 ql_dbg(ql_dbg_disc, vha, 0x2069,
4645 ha->flags.fw_init_done = 1;
4648 * Process any ATIO queue entries that came in
4649 * while we weren't online.
4651 if (qla_tgt_mode_enabled(vha) ||
4652 qla_dual_mode_enabled(vha)) {
4653 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4654 spin_lock_irqsave(&ha->tgt.atio_lock,
4656 qlt_24xx_process_atio_queue(vha, 0);
4657 spin_unlock_irqrestore(
4658 &ha->tgt.atio_lock, flags);
4660 spin_lock_irqsave(&ha->hardware_lock,
4662 qlt_24xx_process_atio_queue(vha, 1);
4663 spin_unlock_irqrestore(
4664 &ha->hardware_lock, flags);
4671 ql_dbg(ql_dbg_disc, vha, 0x206a,
4672 "%s *** FAILED ***.\n", __func__);
4674 ql_dbg(ql_dbg_disc, vha, 0x206b,
4675 "%s: exiting normally.\n", __func__);
4678 /* Restore state if a resync event occurred during processing */
4679 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4680 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
4681 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4682 if (test_bit(RSCN_UPDATE, &save_flags)) {
4683 set_bit(RSCN_UPDATE, &vha->dpc_flags);
4692 * Updates Fibre Channel Device Database with local loop devices.
4695 * ha = adapter block pointer.
4699 static int qla24xx_n2n_handle_login(struct scsi_qla_host *vha,
4702 struct qla_hw_data *ha = vha->hw;
4703 int res = QLA_SUCCESS, rval;
4704 int greater_wwpn = 0;
4707 if (ha->current_topology != ISP_CFG_N)
4710 if (wwn_to_u64(vha->port_name) >
4711 wwn_to_u64(vha->n2n_port_name)) {
4712 ql_dbg(ql_dbg_disc, vha, 0x2002,
4713 "HBA WWPN is greater %llx > target %llx\n",
4714 wwn_to_u64(vha->port_name),
4715 wwn_to_u64(vha->n2n_port_name));
4717 fcport->d_id.b24 = vha->n2n_id;
4720 fcport->loop_id = vha->loop_id;
4721 fcport->fc4f_nvme = 0;
4724 ql_dbg(ql_dbg_disc, vha, 0x4001,
4725 "Initiate N2N login handler: HBA port_id=%06x loopid=%d\n",
4726 fcport->d_id.b24, vha->loop_id);
4728 /* Fill in member data. */
4729 if (!greater_wwpn) {
4730 rval = qla2x00_get_port_database(vha, fcport, 0);
4731 ql_dbg(ql_dbg_disc, vha, 0x1051,
4732 "Remote login-state (%x/%x) port_id=%06x loop_id=%x, rval=%d\n",
4733 fcport->current_login_state, fcport->last_login_state,
4734 fcport->d_id.b24, fcport->loop_id, rval);
4736 if (((fcport->current_login_state & 0xf) == 0x4) ||
4737 ((fcport->current_login_state & 0xf) == 0x6))
4741 if (logged_in || greater_wwpn) {
4742 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
4743 qla_nvme_register_hba(vha);
4745 /* Set connected N_Port d_id */
4746 if (vha->flags.nvme_enabled)
4747 fcport->fc4f_nvme = 1;
4749 fcport->scan_state = QLA_FCPORT_FOUND;
4750 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4751 fcport->disc_state = DSC_GNL;
4752 fcport->n2n_flag = 1;
4754 vha->hw->flags.gpsc_supported = 0;
4757 ql_dbg(ql_dbg_disc, vha, 0x20e5,
4758 "%s %d PLOGI ELS %8phC\n",
4759 __func__, __LINE__, fcport->port_name);
4761 res = qla24xx_els_dcmd2_iocb(vha, ELS_DCMD_PLOGI,
4762 fcport, fcport->d_id);
4765 if (res != QLA_SUCCESS) {
4766 ql_log(ql_log_info, vha, 0xd04d,
4767 "PLOGI Failed: portid=%06x - retrying\n",
4771 /* State 0x6 means FCP PRLI complete */
4772 if ((fcport->current_login_state & 0xf) == 0x6) {
4773 ql_dbg(ql_dbg_disc, vha, 0x2118,
4774 "%s %d %8phC post GPDB work\n",
4775 __func__, __LINE__, fcport->port_name);
4776 fcport->chip_reset =
4777 vha->hw->base_qpair->chip_reset;
4778 qla24xx_post_gpdb_work(vha, fcport, 0);
4780 ql_dbg(ql_dbg_disc, vha, 0x2118,
4781 "%s %d %8phC post NVMe PRLI\n",
4782 __func__, __LINE__, fcport->port_name);
4783 qla24xx_post_prli_work(vha, fcport);
4787 /* Wait for next database change */
4788 set_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags);
4795 * qla2x00_configure_local_loop
4796 * Updates Fibre Channel Device Database with local loop devices.
4799 * ha = adapter block pointer.
4805 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
4810 fc_port_t *fcport, *new_fcport;
4816 uint8_t domain, area, al_pa;
4817 struct qla_hw_data *ha = vha->hw;
4818 unsigned long flags;
4822 entries = MAX_FIBRE_DEVICES_LOOP;
4824 /* Get list of logged in devices. */
4825 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
4826 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
4828 if (rval != QLA_SUCCESS)
4829 goto cleanup_allocation;
4831 ql_dbg(ql_dbg_disc, vha, 0x2011,
4832 "Entries in ID list (%d).\n", entries);
4833 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4834 (uint8_t *)ha->gid_list,
4835 entries * sizeof(struct gid_list_info));
4837 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4838 fcport->scan_state = QLA_FCPORT_SCAN;
4841 /* Allocate temporary fcport for any new fcports discovered. */
4842 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4843 if (new_fcport == NULL) {
4844 ql_log(ql_log_warn, vha, 0x2012,
4845 "Memory allocation failed for fcport.\n");
4846 rval = QLA_MEMORY_ALLOC_FAILED;
4847 goto cleanup_allocation;
4849 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4851 /* Inititae N2N login. */
4852 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
4853 rval = qla24xx_n2n_handle_login(vha, new_fcport);
4854 if (rval != QLA_SUCCESS)
4855 goto cleanup_allocation;
4859 /* Add devices to port list. */
4860 id_iter = (char *)ha->gid_list;
4861 for (index = 0; index < entries; index++) {
4862 domain = ((struct gid_list_info *)id_iter)->domain;
4863 area = ((struct gid_list_info *)id_iter)->area;
4864 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
4865 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4866 loop_id = (uint16_t)
4867 ((struct gid_list_info *)id_iter)->loop_id_2100;
4869 loop_id = le16_to_cpu(
4870 ((struct gid_list_info *)id_iter)->loop_id);
4871 id_iter += ha->gid_list_info_size;
4873 /* Bypass reserved domain fields. */
4874 if ((domain & 0xf0) == 0xf0)
4877 /* Bypass if not same domain and area of adapter. */
4878 if (area && domain &&
4879 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
4882 /* Bypass invalid local loop ID. */
4883 if (loop_id > LAST_LOCAL_LOOP_ID)
4886 memset(new_fcport->port_name, 0, WWN_SIZE);
4888 /* Fill in member data. */
4889 new_fcport->d_id.b.domain = domain;
4890 new_fcport->d_id.b.area = area;
4891 new_fcport->d_id.b.al_pa = al_pa;
4892 new_fcport->loop_id = loop_id;
4893 new_fcport->scan_state = QLA_FCPORT_FOUND;
4895 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
4896 if (rval2 != QLA_SUCCESS) {
4897 ql_dbg(ql_dbg_disc, vha, 0x2097,
4898 "Failed to retrieve fcport information "
4899 "-- get_port_database=%x, loop_id=0x%04x.\n",
4900 rval2, new_fcport->loop_id);
4901 /* Skip retry if N2N */
4902 if (ha->current_topology != ISP_CFG_N) {
4903 ql_dbg(ql_dbg_disc, vha, 0x2105,
4904 "Scheduling resync.\n");
4905 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4910 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4911 /* Check for matching device in port list. */
4914 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4915 if (memcmp(new_fcport->port_name, fcport->port_name,
4919 fcport->flags &= ~FCF_FABRIC_DEVICE;
4920 fcport->loop_id = new_fcport->loop_id;
4921 fcport->port_type = new_fcport->port_type;
4922 fcport->d_id.b24 = new_fcport->d_id.b24;
4923 memcpy(fcport->node_name, new_fcport->node_name,
4925 fcport->scan_state = QLA_FCPORT_FOUND;
4931 /* New device, add to fcports list. */
4932 list_add_tail(&new_fcport->list, &vha->vp_fcports);
4934 /* Allocate a new replacement fcport. */
4935 fcport = new_fcport;
4937 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4939 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4941 if (new_fcport == NULL) {
4942 ql_log(ql_log_warn, vha, 0xd031,
4943 "Failed to allocate memory for fcport.\n");
4944 rval = QLA_MEMORY_ALLOC_FAILED;
4945 goto cleanup_allocation;
4947 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4948 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4951 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4953 /* Base iIDMA settings on HBA port speed. */
4954 fcport->fp_speed = ha->link_data_rate;
4959 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4960 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4963 if (fcport->scan_state == QLA_FCPORT_SCAN) {
4964 if ((qla_dual_mode_enabled(vha) ||
4965 qla_ini_mode_enabled(vha)) &&
4966 atomic_read(&fcport->state) == FCS_ONLINE) {
4967 qla2x00_mark_device_lost(vha, fcport,
4968 ql2xplogiabsentdevice, 0);
4969 if (fcport->loop_id != FC_NO_LOOP_ID &&
4970 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
4971 fcport->port_type != FCT_INITIATOR &&
4972 fcport->port_type != FCT_BROADCAST) {
4973 ql_dbg(ql_dbg_disc, vha, 0x20f0,
4974 "%s %d %8phC post del sess\n",
4978 qlt_schedule_sess_for_deletion(fcport);
4984 if (fcport->scan_state == QLA_FCPORT_FOUND)
4985 qla24xx_fcport_handle_login(vha, fcport);
4991 if (rval != QLA_SUCCESS) {
4992 ql_dbg(ql_dbg_disc, vha, 0x2098,
4993 "Configure local loop error exit: rval=%x.\n", rval);
5000 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5003 uint16_t mb[MAILBOX_REGISTER_COUNT];
5004 struct qla_hw_data *ha = vha->hw;
5006 if (!IS_IIDMA_CAPABLE(ha))
5009 if (atomic_read(&fcport->state) != FCS_ONLINE)
5012 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5013 fcport->fp_speed > ha->link_data_rate ||
5014 !ha->flags.gpsc_supported)
5017 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5019 if (rval != QLA_SUCCESS) {
5020 ql_dbg(ql_dbg_disc, vha, 0x2004,
5021 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5022 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5024 ql_dbg(ql_dbg_disc, vha, 0x2005,
5025 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5026 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5027 fcport->fp_speed, fcport->port_name);
5031 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5033 qla2x00_iidma_fcport(vha, fcport);
5034 qla24xx_update_fcport_fcp_prio(vha, fcport);
5037 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5039 struct qla_work_evt *e;
5041 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5043 return QLA_FUNCTION_FAILED;
5045 e->u.fcport.fcport = fcport;
5046 return qla2x00_post_work(vha, e);
5049 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5051 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5053 struct fc_rport_identifiers rport_ids;
5054 struct fc_rport *rport;
5055 unsigned long flags;
5057 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5058 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5059 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5060 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5061 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5062 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5064 ql_log(ql_log_warn, vha, 0x2006,
5065 "Unable to allocate fc remote port.\n");
5069 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5070 *((fc_port_t **)rport->dd_data) = fcport;
5071 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5073 rport->supported_classes = fcport->supported_classes;
5075 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5076 if (fcport->port_type == FCT_INITIATOR)
5077 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
5078 if (fcport->port_type == FCT_TARGET)
5079 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
5081 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5082 "%s %8phN. rport %p is %s mode\n",
5083 __func__, fcport->port_name, rport,
5084 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
5086 fc_remote_port_rolechg(rport, rport_ids.roles);
5090 * qla2x00_update_fcport
5091 * Updates device on list.
5094 * ha = adapter block pointer.
5095 * fcport = port structure pointer.
5105 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5109 if (IS_SW_RESV_ADDR(fcport->d_id))
5112 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5113 __func__, fcport->port_name);
5115 if (IS_QLAFX00(vha->hw)) {
5116 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5118 fcport->login_retry = 0;
5119 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5120 fcport->disc_state = DSC_LOGIN_COMPLETE;
5121 fcport->deleted = 0;
5122 fcport->logout_on_delete = 1;
5123 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5126 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5127 qla2x00_iidma_fcport(vha, fcport);
5129 if (fcport->fc4f_nvme) {
5130 qla_nvme_register_remote(vha, fcport);
5134 qla24xx_update_fcport_fcp_prio(vha, fcport);
5136 switch (vha->host->active_mode) {
5137 case MODE_INITIATOR:
5138 qla2x00_reg_remote_port(vha, fcport);
5141 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5142 !vha->vha_tgt.qla_tgt->tgt_stopped)
5143 qlt_fc_port_added(vha, fcport);
5146 qla2x00_reg_remote_port(vha, fcport);
5147 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5148 !vha->vha_tgt.qla_tgt->tgt_stopped)
5149 qlt_fc_port_added(vha, fcport);
5155 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5156 if (fcport->id_changed) {
5157 fcport->id_changed = 0;
5158 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5159 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5160 __func__, __LINE__, fcport->port_name,
5162 qla24xx_post_gfpnid_work(vha, fcport);
5164 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5165 "%s %d %8phC post gpsc fcp_cnt %d\n",
5166 __func__, __LINE__, fcport->port_name,
5168 qla24xx_post_gpsc_work(vha, fcport);
5174 * qla2x00_configure_fabric
5175 * Setup SNS devices with loop ID's.
5178 * ha = adapter block pointer.
5185 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5189 uint16_t mb[MAILBOX_REGISTER_COUNT];
5191 LIST_HEAD(new_fcports);
5192 struct qla_hw_data *ha = vha->hw;
5195 /* If FL port exists, then SNS is present */
5196 if (IS_FWI2_CAPABLE(ha))
5197 loop_id = NPH_F_PORT;
5199 loop_id = SNS_FL_PORT;
5200 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5201 if (rval != QLA_SUCCESS) {
5202 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5203 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5205 vha->device_flags &= ~SWITCH_FOUND;
5206 return (QLA_SUCCESS);
5208 vha->device_flags |= SWITCH_FOUND;
5211 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5212 rval = qla2x00_send_change_request(vha, 0x3, 0);
5213 if (rval != QLA_SUCCESS)
5214 ql_log(ql_log_warn, vha, 0x121,
5215 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5221 qla2x00_mgmt_svr_login(vha);
5224 if (ql2xfdmienable &&
5225 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5226 qla2x00_fdmi_register(vha);
5228 /* Ensure we are logged into the SNS. */
5229 loop_id = NPH_SNS_LID(ha);
5230 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5231 0xfc, mb, BIT_1|BIT_0);
5232 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5233 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5234 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5235 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5236 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5239 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5240 if (qla2x00_rft_id(vha)) {
5242 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5243 "Register FC-4 TYPE failed.\n");
5244 if (test_bit(LOOP_RESYNC_NEEDED,
5248 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5250 ql_dbg(ql_dbg_disc, vha, 0x209a,
5251 "Register FC-4 Features failed.\n");
5252 if (test_bit(LOOP_RESYNC_NEEDED,
5256 if (vha->flags.nvme_enabled) {
5257 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5258 ql_dbg(ql_dbg_disc, vha, 0x2049,
5259 "Register NVME FC Type Features failed.\n");
5262 if (qla2x00_rnn_id(vha)) {
5264 ql_dbg(ql_dbg_disc, vha, 0x2104,
5265 "Register Node Name failed.\n");
5266 if (test_bit(LOOP_RESYNC_NEEDED,
5269 } else if (qla2x00_rsnn_nn(vha)) {
5271 ql_dbg(ql_dbg_disc, vha, 0x209b,
5272 "Register Symbolic Node Name failed.\n");
5273 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5279 /* Mark the time right before querying FW for connected ports.
5280 * This process is long, asynchronous and by the time it's done,
5281 * collected information might not be accurate anymore. E.g.
5282 * disconnected port might have re-connected and a brand new
5283 * session has been created. In this case session's generation
5284 * will be newer than discovery_gen. */
5285 qlt_do_generation_tick(vha, &discovery_gen);
5287 if (USE_ASYNC_SCAN(ha)) {
5288 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5291 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5293 list_for_each_entry(fcport, &vha->vp_fcports, list)
5294 fcport->scan_state = QLA_FCPORT_SCAN;
5296 rval = qla2x00_find_all_fabric_devs(vha);
5298 if (rval != QLA_SUCCESS)
5302 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5303 qla_nvme_register_hba(vha);
5306 ql_dbg(ql_dbg_disc, vha, 0x2068,
5307 "Configure fabric error exit rval=%d.\n", rval);
5313 * qla2x00_find_all_fabric_devs
5316 * ha = adapter block pointer.
5317 * dev = database device entry pointer.
5326 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5330 fc_port_t *fcport, *new_fcport;
5335 int first_dev, last_dev;
5336 port_id_t wrap = {}, nxt_d_id;
5337 struct qla_hw_data *ha = vha->hw;
5338 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5339 unsigned long flags;
5343 /* Try GID_PT to get device list, else GAN. */
5345 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5350 ql_dbg(ql_dbg_disc, vha, 0x209c,
5351 "GID_PT allocations failed, fallback on GA_NXT.\n");
5353 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5354 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5356 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5358 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5360 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5362 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5364 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5366 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5368 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5372 /* If other queries succeeded probe for FC-4 type */
5374 qla2x00_gff_id(vha, swl);
5375 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5381 /* Allocate temporary fcport for any new fcports discovered. */
5382 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5383 if (new_fcport == NULL) {
5384 ql_log(ql_log_warn, vha, 0x209d,
5385 "Failed to allocate memory for fcport.\n");
5386 return (QLA_MEMORY_ALLOC_FAILED);
5388 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5389 /* Set start port ID scan at adapter ID. */
5393 /* Starting free loop ID. */
5394 loop_id = ha->min_external_loopid;
5395 for (; loop_id <= ha->max_loop_id; loop_id++) {
5396 if (qla2x00_is_reserved_id(vha, loop_id))
5399 if (ha->current_topology == ISP_CFG_FL &&
5400 (atomic_read(&vha->loop_down_timer) ||
5401 LOOP_TRANSITION(vha))) {
5402 atomic_set(&vha->loop_down_timer, 0);
5403 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5404 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5410 wrap.b24 = new_fcport->d_id.b24;
5412 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5413 memcpy(new_fcport->node_name,
5414 swl[swl_idx].node_name, WWN_SIZE);
5415 memcpy(new_fcport->port_name,
5416 swl[swl_idx].port_name, WWN_SIZE);
5417 memcpy(new_fcport->fabric_port_name,
5418 swl[swl_idx].fabric_port_name, WWN_SIZE);
5419 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5420 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5422 new_fcport->nvme_flag = 0;
5423 new_fcport->fc4f_nvme = 0;
5424 if (vha->flags.nvme_enabled &&
5425 swl[swl_idx].fc4f_nvme) {
5426 new_fcport->fc4f_nvme =
5427 swl[swl_idx].fc4f_nvme;
5428 ql_log(ql_log_info, vha, 0x2131,
5429 "FOUND: NVME port %8phC as FC Type 28h\n",
5430 new_fcport->port_name);
5433 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5439 /* Send GA_NXT to the switch */
5440 rval = qla2x00_ga_nxt(vha, new_fcport);
5441 if (rval != QLA_SUCCESS) {
5442 ql_log(ql_log_warn, vha, 0x209e,
5443 "SNS scan failed -- assuming "
5444 "zero-entry result.\n");
5450 /* If wrap on switch device list, exit. */
5452 wrap.b24 = new_fcport->d_id.b24;
5454 } else if (new_fcport->d_id.b24 == wrap.b24) {
5455 ql_dbg(ql_dbg_disc, vha, 0x209f,
5456 "Device wrap (%02x%02x%02x).\n",
5457 new_fcport->d_id.b.domain,
5458 new_fcport->d_id.b.area,
5459 new_fcport->d_id.b.al_pa);
5463 /* Bypass if same physical adapter. */
5464 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5467 /* Bypass virtual ports of the same host. */
5468 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5471 /* Bypass if same domain and area of adapter. */
5472 if (((new_fcport->d_id.b24 & 0xffff00) ==
5473 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5477 /* Bypass reserved domain fields. */
5478 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5481 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5482 if (ql2xgffidenable &&
5483 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5484 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5487 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5489 /* Locate matching device in database. */
5491 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5492 if (memcmp(new_fcport->port_name, fcport->port_name,
5496 fcport->scan_state = QLA_FCPORT_FOUND;
5500 /* Update port state. */
5501 memcpy(fcport->fabric_port_name,
5502 new_fcport->fabric_port_name, WWN_SIZE);
5503 fcport->fp_speed = new_fcport->fp_speed;
5506 * If address the same and state FCS_ONLINE
5507 * (or in target mode), nothing changed.
5509 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5510 (atomic_read(&fcport->state) == FCS_ONLINE ||
5511 (vha->host->active_mode == MODE_TARGET))) {
5516 * If device was not a fabric device before.
5518 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5519 fcport->d_id.b24 = new_fcport->d_id.b24;
5520 qla2x00_clear_loop_id(fcport);
5521 fcport->flags |= (FCF_FABRIC_DEVICE |
5527 * Port ID changed or device was marked to be updated;
5528 * Log it out if still logged in and mark it for
5531 if (qla_tgt_mode_enabled(base_vha)) {
5532 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5533 "port changed FC ID, %8phC"
5534 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5536 fcport->d_id.b.domain,
5537 fcport->d_id.b.area,
5538 fcport->d_id.b.al_pa,
5540 new_fcport->d_id.b.domain,
5541 new_fcport->d_id.b.area,
5542 new_fcport->d_id.b.al_pa);
5543 fcport->d_id.b24 = new_fcport->d_id.b24;
5547 fcport->d_id.b24 = new_fcport->d_id.b24;
5548 fcport->flags |= FCF_LOGIN_NEEDED;
5552 if (fcport->fc4f_nvme) {
5553 if (fcport->disc_state == DSC_DELETE_PEND) {
5554 fcport->disc_state = DSC_GNL;
5555 vha->fcport_count--;
5556 fcport->login_succ = 0;
5561 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5564 /* If device was not in our fcports list, then add it. */
5565 new_fcport->scan_state = QLA_FCPORT_FOUND;
5566 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5568 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5571 /* Allocate a new replacement fcport. */
5572 nxt_d_id.b24 = new_fcport->d_id.b24;
5573 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5574 if (new_fcport == NULL) {
5575 ql_log(ql_log_warn, vha, 0xd032,
5576 "Memory allocation failed for fcport.\n");
5577 return (QLA_MEMORY_ALLOC_FAILED);
5579 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5580 new_fcport->d_id.b24 = nxt_d_id.b24;
5583 qla2x00_free_fcport(new_fcport);
5586 * Logout all previous fabric dev marked lost, except FCP2 devices.
5588 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5589 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5592 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5593 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5596 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5597 if ((qla_dual_mode_enabled(vha) ||
5598 qla_ini_mode_enabled(vha)) &&
5599 atomic_read(&fcport->state) == FCS_ONLINE) {
5600 qla2x00_mark_device_lost(vha, fcport,
5601 ql2xplogiabsentdevice, 0);
5602 if (fcport->loop_id != FC_NO_LOOP_ID &&
5603 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5604 fcport->port_type != FCT_INITIATOR &&
5605 fcport->port_type != FCT_BROADCAST) {
5606 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5607 "%s %d %8phC post del sess\n",
5610 qlt_schedule_sess_for_deletion(fcport);
5616 if (fcport->scan_state == QLA_FCPORT_FOUND)
5617 qla24xx_fcport_handle_login(vha, fcport);
5623 * qla2x00_find_new_loop_id
5624 * Scan through our port list and find a new usable loop ID.
5627 * ha: adapter state pointer.
5628 * dev: port structure pointer.
5631 * qla2x00 local function return status code.
5637 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
5640 struct qla_hw_data *ha = vha->hw;
5641 unsigned long flags = 0;
5645 spin_lock_irqsave(&ha->vport_slock, flags);
5647 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5649 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5650 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5651 dev->loop_id = FC_NO_LOOP_ID;
5652 rval = QLA_FUNCTION_FAILED;
5654 set_bit(dev->loop_id, ha->loop_id_map);
5656 spin_unlock_irqrestore(&ha->vport_slock, flags);
5658 if (rval == QLA_SUCCESS)
5659 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5660 "Assigning new loopid=%x, portid=%x.\n",
5661 dev->loop_id, dev->d_id.b24);
5663 ql_log(ql_log_warn, dev->vha, 0x2087,
5664 "No loop_id's available, portid=%x.\n",
5672 * qla2x00_fabric_login
5673 * Issue fabric login command.
5676 * ha = adapter block pointer.
5677 * device = pointer to FC device type structure.
5680 * 0 - Login successfully
5682 * 2 - Initiator device
5686 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5687 uint16_t *next_loopid)
5691 uint16_t tmp_loopid;
5692 uint16_t mb[MAILBOX_REGISTER_COUNT];
5693 struct qla_hw_data *ha = vha->hw;
5699 ql_dbg(ql_dbg_disc, vha, 0x2000,
5700 "Trying Fabric Login w/loop id 0x%04x for port "
5702 fcport->loop_id, fcport->d_id.b.domain,
5703 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5705 /* Login fcport on switch. */
5706 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
5707 fcport->d_id.b.domain, fcport->d_id.b.area,
5708 fcport->d_id.b.al_pa, mb, BIT_0);
5709 if (rval != QLA_SUCCESS) {
5712 if (mb[0] == MBS_PORT_ID_USED) {
5714 * Device has another loop ID. The firmware team
5715 * recommends the driver perform an implicit login with
5716 * the specified ID again. The ID we just used is save
5717 * here so we return with an ID that can be tried by
5721 tmp_loopid = fcport->loop_id;
5722 fcport->loop_id = mb[1];
5724 ql_dbg(ql_dbg_disc, vha, 0x2001,
5725 "Fabric Login: port in use - next loop "
5726 "id=0x%04x, port id= %02x%02x%02x.\n",
5727 fcport->loop_id, fcport->d_id.b.domain,
5728 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5730 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5735 /* A retry occurred before. */
5736 *next_loopid = tmp_loopid;
5739 * No retry occurred before. Just increment the
5740 * ID value for next login.
5742 *next_loopid = (fcport->loop_id + 1);
5745 if (mb[1] & BIT_0) {
5746 fcport->port_type = FCT_INITIATOR;
5748 fcport->port_type = FCT_TARGET;
5749 if (mb[1] & BIT_1) {
5750 fcport->flags |= FCF_FCP2_DEVICE;
5755 fcport->supported_classes |= FC_COS_CLASS2;
5757 fcport->supported_classes |= FC_COS_CLASS3;
5759 if (IS_FWI2_CAPABLE(ha)) {
5762 FCF_CONF_COMP_SUPPORTED;
5767 } else if (mb[0] == MBS_LOOP_ID_USED) {
5769 * Loop ID already used, try next loop ID.
5772 rval = qla2x00_find_new_loop_id(vha, fcport);
5773 if (rval != QLA_SUCCESS) {
5774 /* Ran out of loop IDs to use */
5777 } else if (mb[0] == MBS_COMMAND_ERROR) {
5779 * Firmware possibly timed out during login. If NO
5780 * retries are left to do then the device is declared
5783 *next_loopid = fcport->loop_id;
5784 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
5785 fcport->d_id.b.domain, fcport->d_id.b.area,
5786 fcport->d_id.b.al_pa);
5787 qla2x00_mark_device_lost(vha, fcport, 1, 0);
5793 * unrecoverable / not handled error
5795 ql_dbg(ql_dbg_disc, vha, 0x2002,
5796 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5797 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5798 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5799 fcport->loop_id, jiffies);
5801 *next_loopid = fcport->loop_id;
5802 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
5803 fcport->d_id.b.domain, fcport->d_id.b.area,
5804 fcport->d_id.b.al_pa);
5805 qla2x00_clear_loop_id(fcport);
5806 fcport->login_retry = 0;
5817 * qla2x00_local_device_login
5818 * Issue local device login command.
5821 * ha = adapter block pointer.
5822 * loop_id = loop id of device to login to.
5824 * Returns (Where's the #define!!!!):
5825 * 0 - Login successfully
5830 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
5833 uint16_t mb[MAILBOX_REGISTER_COUNT];
5835 memset(mb, 0, sizeof(mb));
5836 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
5837 if (rval == QLA_SUCCESS) {
5838 /* Interrogate mailbox registers for any errors */
5839 if (mb[0] == MBS_COMMAND_ERROR)
5841 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5842 /* device not in PCB table */
5850 * qla2x00_loop_resync
5851 * Resync with fibre channel devices.
5854 * ha = adapter block pointer.
5860 qla2x00_loop_resync(scsi_qla_host_t *vha)
5862 int rval = QLA_SUCCESS;
5864 struct req_que *req;
5865 struct rsp_que *rsp;
5870 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5871 if (vha->flags.online) {
5872 if (!(rval = qla2x00_fw_ready(vha))) {
5873 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5876 if (!IS_QLAFX00(vha->hw)) {
5878 * Issue a marker after FW becomes
5881 qla2x00_marker(vha, req, rsp, 0, 0,
5883 vha->marker_needed = 0;
5886 /* Remap devices on Loop. */
5887 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5889 if (IS_QLAFX00(vha->hw))
5890 qlafx00_configure_devices(vha);
5892 qla2x00_configure_loop(vha);
5895 } while (!atomic_read(&vha->loop_down_timer) &&
5896 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5897 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5902 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5903 return (QLA_FUNCTION_FAILED);
5906 ql_dbg(ql_dbg_disc, vha, 0x206c,
5907 "%s *** FAILED ***.\n", __func__);
5913 * qla2x00_perform_loop_resync
5914 * Description: This function will set the appropriate flags and call
5915 * qla2x00_loop_resync. If successful loop will be resynced
5916 * Arguments : scsi_qla_host_t pointer
5917 * returm : Success or Failure
5920 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5924 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5925 /*Configure the flags so that resync happens properly*/
5926 atomic_set(&ha->loop_down_timer, 0);
5927 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5928 atomic_set(&ha->loop_state, LOOP_UP);
5929 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5930 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5931 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5933 rval = qla2x00_loop_resync(ha);
5935 atomic_set(&ha->loop_state, LOOP_DEAD);
5937 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5944 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
5947 struct scsi_qla_host *vha;
5948 struct qla_hw_data *ha = base_vha->hw;
5949 unsigned long flags;
5951 spin_lock_irqsave(&ha->vport_slock, flags);
5952 /* Go with deferred removal of rport references. */
5953 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5954 atomic_inc(&vha->vref_count);
5955 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5956 if (fcport->drport &&
5957 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5958 spin_unlock_irqrestore(&ha->vport_slock, flags);
5959 qla2x00_rport_del(fcport);
5961 spin_lock_irqsave(&ha->vport_slock, flags);
5964 atomic_dec(&vha->vref_count);
5965 wake_up(&vha->vref_waitq);
5967 spin_unlock_irqrestore(&ha->vport_slock, flags);
5970 /* Assumes idc_lock always held on entry */
5972 qla83xx_reset_ownership(scsi_qla_host_t *vha)
5974 struct qla_hw_data *ha = vha->hw;
5975 uint32_t drv_presence, drv_presence_mask;
5976 uint32_t dev_part_info1, dev_part_info2, class_type;
5977 uint32_t class_type_mask = 0x3;
5978 uint16_t fcoe_other_function = 0xffff, i;
5980 if (IS_QLA8044(ha)) {
5981 drv_presence = qla8044_rd_direct(vha,
5982 QLA8044_CRB_DRV_ACTIVE_INDEX);
5983 dev_part_info1 = qla8044_rd_direct(vha,
5984 QLA8044_CRB_DEV_PART_INFO_INDEX);
5985 dev_part_info2 = qla8044_rd_direct(vha,
5986 QLA8044_CRB_DEV_PART_INFO2);
5988 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5989 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5990 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5992 for (i = 0; i < 8; i++) {
5993 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5994 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5995 (i != ha->portnum)) {
5996 fcoe_other_function = i;
6000 if (fcoe_other_function == 0xffff) {
6001 for (i = 0; i < 8; i++) {
6002 class_type = ((dev_part_info2 >> (i * 4)) &
6004 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6005 ((i + 8) != ha->portnum)) {
6006 fcoe_other_function = i + 8;
6012 * Prepare drv-presence mask based on fcoe functions present.
6013 * However consider only valid physical fcoe function numbers (0-15).
6015 drv_presence_mask = ~((1 << (ha->portnum)) |
6016 ((fcoe_other_function == 0xffff) ?
6017 0 : (1 << (fcoe_other_function))));
6019 /* We are the reset owner iff:
6020 * - No other protocol drivers present.
6021 * - This is the lowest among fcoe functions. */
6022 if (!(drv_presence & drv_presence_mask) &&
6023 (ha->portnum < fcoe_other_function)) {
6024 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6025 "This host is Reset owner.\n");
6026 ha->flags.nic_core_reset_owner = 1;
6031 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6033 int rval = QLA_SUCCESS;
6034 struct qla_hw_data *ha = vha->hw;
6037 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6038 if (rval == QLA_SUCCESS) {
6039 drv_ack |= (1 << ha->portnum);
6040 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6047 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6049 int rval = QLA_SUCCESS;
6050 struct qla_hw_data *ha = vha->hw;
6053 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6054 if (rval == QLA_SUCCESS) {
6055 drv_ack &= ~(1 << ha->portnum);
6056 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6063 qla83xx_dev_state_to_string(uint32_t dev_state)
6065 switch (dev_state) {
6066 case QLA8XXX_DEV_COLD:
6067 return "COLD/RE-INIT";
6068 case QLA8XXX_DEV_INITIALIZING:
6069 return "INITIALIZING";
6070 case QLA8XXX_DEV_READY:
6072 case QLA8XXX_DEV_NEED_RESET:
6073 return "NEED RESET";
6074 case QLA8XXX_DEV_NEED_QUIESCENT:
6075 return "NEED QUIESCENT";
6076 case QLA8XXX_DEV_FAILED:
6078 case QLA8XXX_DEV_QUIESCENT:
6085 /* Assumes idc-lock always held on entry */
6087 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6089 struct qla_hw_data *ha = vha->hw;
6090 uint32_t idc_audit_reg = 0, duration_secs = 0;
6092 switch (audit_type) {
6093 case IDC_AUDIT_TIMESTAMP:
6094 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6095 idc_audit_reg = (ha->portnum) |
6096 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6097 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6100 case IDC_AUDIT_COMPLETION:
6101 duration_secs = ((jiffies_to_msecs(jiffies) -
6102 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6103 idc_audit_reg = (ha->portnum) |
6104 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6105 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6109 ql_log(ql_log_warn, vha, 0xb078,
6110 "Invalid audit type specified.\n");
6115 /* Assumes idc_lock always held on entry */
6117 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6119 struct qla_hw_data *ha = vha->hw;
6120 uint32_t idc_control, dev_state;
6122 __qla83xx_get_idc_control(vha, &idc_control);
6123 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6124 ql_log(ql_log_info, vha, 0xb080,
6125 "NIC Core reset has been disabled. idc-control=0x%x\n",
6127 return QLA_FUNCTION_FAILED;
6130 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6131 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6132 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6133 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6134 QLA8XXX_DEV_NEED_RESET);
6135 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6136 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6138 const char *state = qla83xx_dev_state_to_string(dev_state);
6139 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6141 /* SV: XXX: Is timeout required here? */
6142 /* Wait for IDC state change READY -> NEED_RESET */
6143 while (dev_state == QLA8XXX_DEV_READY) {
6144 qla83xx_idc_unlock(vha, 0);
6146 qla83xx_idc_lock(vha, 0);
6147 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6151 /* Send IDC ack by writing to drv-ack register */
6152 __qla83xx_set_drv_ack(vha);
6158 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6160 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6164 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6166 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6170 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6172 uint32_t drv_presence = 0;
6173 struct qla_hw_data *ha = vha->hw;
6175 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6176 if (drv_presence & (1 << ha->portnum))
6179 return QLA_TEST_FAILED;
6183 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6185 int rval = QLA_SUCCESS;
6186 struct qla_hw_data *ha = vha->hw;
6188 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6189 "Entered %s().\n", __func__);
6191 if (vha->device_flags & DFLG_DEV_FAILED) {
6192 ql_log(ql_log_warn, vha, 0xb059,
6193 "Device in unrecoverable FAILED state.\n");
6194 return QLA_FUNCTION_FAILED;
6197 qla83xx_idc_lock(vha, 0);
6199 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6200 ql_log(ql_log_warn, vha, 0xb05a,
6201 "Function=0x%x has been removed from IDC participation.\n",
6203 rval = QLA_FUNCTION_FAILED;
6207 qla83xx_reset_ownership(vha);
6209 rval = qla83xx_initiating_reset(vha);
6212 * Perform reset if we are the reset-owner,
6213 * else wait till IDC state changes to READY/FAILED.
6215 if (rval == QLA_SUCCESS) {
6216 rval = qla83xx_idc_state_handler(vha);
6218 if (rval == QLA_SUCCESS)
6219 ha->flags.nic_core_hung = 0;
6220 __qla83xx_clear_drv_ack(vha);
6224 qla83xx_idc_unlock(vha, 0);
6226 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6232 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6234 struct qla_hw_data *ha = vha->hw;
6235 int rval = QLA_FUNCTION_FAILED;
6237 if (!IS_MCTP_CAPABLE(ha)) {
6238 /* This message can be removed from the final version */
6239 ql_log(ql_log_info, vha, 0x506d,
6240 "This board is not MCTP capable\n");
6244 if (!ha->mctp_dump) {
6245 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6246 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6248 if (!ha->mctp_dump) {
6249 ql_log(ql_log_warn, vha, 0x506e,
6250 "Failed to allocate memory for mctp dump\n");
6255 #define MCTP_DUMP_STR_ADDR 0x00000000
6256 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6257 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6258 if (rval != QLA_SUCCESS) {
6259 ql_log(ql_log_warn, vha, 0x506f,
6260 "Failed to capture mctp dump\n");
6262 ql_log(ql_log_info, vha, 0x5070,
6263 "Mctp dump capture for host (%ld/%p).\n",
6264 vha->host_no, ha->mctp_dump);
6265 ha->mctp_dumped = 1;
6268 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6269 ha->flags.nic_core_reset_hdlr_active = 1;
6270 rval = qla83xx_restart_nic_firmware(vha);
6272 /* NIC Core reset failed. */
6273 ql_log(ql_log_warn, vha, 0x5071,
6274 "Failed to restart nic firmware\n");
6276 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6277 "Restarted NIC firmware successfully.\n");
6278 ha->flags.nic_core_reset_hdlr_active = 0;
6286 * qla2x00_quiesce_io
6287 * Description: This function will block the new I/Os
6288 * Its not aborting any I/Os as context
6289 * is not destroyed during quiescence
6290 * Arguments: scsi_qla_host_t
6294 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6296 struct qla_hw_data *ha = vha->hw;
6297 struct scsi_qla_host *vp;
6299 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6300 "Quiescing I/O - ha=%p.\n", ha);
6302 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6303 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6304 atomic_set(&vha->loop_state, LOOP_DOWN);
6305 qla2x00_mark_all_devices_lost(vha, 0);
6306 list_for_each_entry(vp, &ha->vp_list, list)
6307 qla2x00_mark_all_devices_lost(vp, 0);
6309 if (!atomic_read(&vha->loop_down_timer))
6310 atomic_set(&vha->loop_down_timer,
6313 /* Wait for pending cmds to complete */
6314 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6318 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6320 struct qla_hw_data *ha = vha->hw;
6321 struct scsi_qla_host *vp;
6322 unsigned long flags;
6326 /* For ISP82XX, driver waits for completion of the commands.
6327 * online flag should be set.
6329 if (!(IS_P3P_TYPE(ha)))
6330 vha->flags.online = 0;
6331 ha->flags.chip_reset_done = 0;
6332 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6333 vha->qla_stats.total_isp_aborts++;
6335 ql_log(ql_log_info, vha, 0x00af,
6336 "Performing ISP error recovery - ha=%p.\n", ha);
6338 /* For ISP82XX, reset_chip is just disabling interrupts.
6339 * Driver waits for the completion of the commands.
6340 * the interrupts need to be enabled.
6342 if (!(IS_P3P_TYPE(ha)))
6343 ha->isp_ops->reset_chip(vha);
6346 ha->flags.rida_fmt2 = 0;
6347 ha->flags.n2n_ae = 0;
6348 ha->flags.lip_ae = 0;
6349 ha->current_topology = 0;
6350 ha->flags.fw_started = 0;
6351 ha->flags.fw_init_done = 0;
6352 ha->base_qpair->chip_reset++;
6353 for (i = 0; i < ha->max_qpairs; i++) {
6354 if (ha->queue_pair_map[i])
6355 ha->queue_pair_map[i]->chip_reset =
6356 ha->base_qpair->chip_reset;
6359 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6360 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6361 atomic_set(&vha->loop_state, LOOP_DOWN);
6362 qla2x00_mark_all_devices_lost(vha, 0);
6364 spin_lock_irqsave(&ha->vport_slock, flags);
6365 list_for_each_entry(vp, &ha->vp_list, list) {
6366 atomic_inc(&vp->vref_count);
6367 spin_unlock_irqrestore(&ha->vport_slock, flags);
6369 qla2x00_mark_all_devices_lost(vp, 0);
6371 spin_lock_irqsave(&ha->vport_slock, flags);
6372 atomic_dec(&vp->vref_count);
6374 spin_unlock_irqrestore(&ha->vport_slock, flags);
6376 if (!atomic_read(&vha->loop_down_timer))
6377 atomic_set(&vha->loop_down_timer,
6381 /* Clear all async request states across all VPs. */
6382 list_for_each_entry(fcport, &vha->vp_fcports, list)
6383 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6384 spin_lock_irqsave(&ha->vport_slock, flags);
6385 list_for_each_entry(vp, &ha->vp_list, list) {
6386 atomic_inc(&vp->vref_count);
6387 spin_unlock_irqrestore(&ha->vport_slock, flags);
6389 list_for_each_entry(fcport, &vp->vp_fcports, list)
6390 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6392 spin_lock_irqsave(&ha->vport_slock, flags);
6393 atomic_dec(&vp->vref_count);
6395 spin_unlock_irqrestore(&ha->vport_slock, flags);
6397 if (!ha->flags.eeh_busy) {
6398 /* Make sure for ISP 82XX IO DMA is complete */
6399 if (IS_P3P_TYPE(ha)) {
6400 qla82xx_chip_reset_cleanup(vha);
6401 ql_log(ql_log_info, vha, 0x00b4,
6402 "Done chip reset cleanup.\n");
6404 /* Done waiting for pending commands.
6405 * Reset the online flag.
6407 vha->flags.online = 0;
6410 /* Requeue all commands in outstanding command list. */
6411 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6413 /* memory barrier */
6419 * Resets ISP and aborts all outstanding commands.
6422 * ha = adapter block pointer.
6428 qla2x00_abort_isp(scsi_qla_host_t *vha)
6432 struct qla_hw_data *ha = vha->hw;
6433 struct scsi_qla_host *vp;
6434 struct req_que *req = ha->req_q_map[0];
6435 unsigned long flags;
6437 if (vha->flags.online) {
6438 qla2x00_abort_isp_cleanup(vha);
6440 if (IS_QLA8031(ha)) {
6441 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6442 "Clearing fcoe driver presence.\n");
6443 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6444 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6445 "Error while clearing DRV-Presence.\n");
6448 if (unlikely(pci_channel_offline(ha->pdev) &&
6449 ha->flags.pci_channel_io_perm_failure)) {
6450 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6455 ha->isp_ops->get_flash_version(vha, req->ring);
6457 ha->isp_ops->nvram_config(vha);
6459 if (!qla2x00_restart_isp(vha)) {
6460 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6462 if (!atomic_read(&vha->loop_down_timer)) {
6464 * Issue marker command only when we are going
6465 * to start the I/O .
6467 vha->marker_needed = 1;
6470 vha->flags.online = 1;
6472 ha->isp_ops->enable_intrs(ha);
6474 ha->isp_abort_cnt = 0;
6475 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6477 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6478 qla2x00_get_fw_version(vha);
6480 ha->flags.fce_enabled = 1;
6482 fce_calc_size(ha->fce_bufs));
6483 rval = qla2x00_enable_fce_trace(vha,
6484 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6487 ql_log(ql_log_warn, vha, 0x8033,
6488 "Unable to reinitialize FCE "
6490 ha->flags.fce_enabled = 0;
6495 memset(ha->eft, 0, EFT_SIZE);
6496 rval = qla2x00_enable_eft_trace(vha,
6497 ha->eft_dma, EFT_NUM_BUFFERS);
6499 ql_log(ql_log_warn, vha, 0x8034,
6500 "Unable to reinitialize EFT "
6504 } else { /* failed the ISP abort */
6505 vha->flags.online = 1;
6506 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6507 if (ha->isp_abort_cnt == 0) {
6508 ql_log(ql_log_fatal, vha, 0x8035,
6509 "ISP error recover failed - "
6510 "board disabled.\n");
6512 * The next call disables the board
6515 ha->isp_ops->reset_adapter(vha);
6516 vha->flags.online = 0;
6517 clear_bit(ISP_ABORT_RETRY,
6520 } else { /* schedule another ISP abort */
6521 ha->isp_abort_cnt--;
6522 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6523 "ISP abort - retry remaining %d.\n",
6528 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6529 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6530 "ISP error recovery - retrying (%d) "
6531 "more times.\n", ha->isp_abort_cnt);
6532 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6540 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6541 qla2x00_configure_hba(vha);
6542 spin_lock_irqsave(&ha->vport_slock, flags);
6543 list_for_each_entry(vp, &ha->vp_list, list) {
6545 atomic_inc(&vp->vref_count);
6546 spin_unlock_irqrestore(&ha->vport_slock, flags);
6548 qla2x00_vp_abort_isp(vp);
6550 spin_lock_irqsave(&ha->vport_slock, flags);
6551 atomic_dec(&vp->vref_count);
6554 spin_unlock_irqrestore(&ha->vport_slock, flags);
6556 if (IS_QLA8031(ha)) {
6557 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6558 "Setting back fcoe driver presence.\n");
6559 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6560 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6561 "Error while setting DRV-Presence.\n");
6564 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6572 * qla2x00_restart_isp
6573 * restarts the ISP after a reset
6576 * ha = adapter block pointer.
6582 qla2x00_restart_isp(scsi_qla_host_t *vha)
6585 struct qla_hw_data *ha = vha->hw;
6586 struct req_que *req = ha->req_q_map[0];
6587 struct rsp_que *rsp = ha->rsp_q_map[0];
6589 /* If firmware needs to be loaded */
6590 if (qla2x00_isp_firmware(vha)) {
6591 vha->flags.online = 0;
6592 status = ha->isp_ops->chip_diag(vha);
6594 status = qla2x00_setup_chip(vha);
6597 if (!status && !(status = qla2x00_init_rings(vha))) {
6598 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6599 ha->flags.chip_reset_done = 1;
6601 /* Initialize the queues in use */
6602 qla25xx_init_queues(ha);
6604 status = qla2x00_fw_ready(vha);
6606 /* Issue a marker after FW becomes ready. */
6607 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6608 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6611 /* if no cable then assume it's good */
6612 if ((vha->device_flags & DFLG_NO_CABLE))
6619 qla25xx_init_queues(struct qla_hw_data *ha)
6621 struct rsp_que *rsp = NULL;
6622 struct req_que *req = NULL;
6623 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6627 for (i = 1; i < ha->max_rsp_queues; i++) {
6628 rsp = ha->rsp_q_map[i];
6629 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6630 rsp->options &= ~BIT_0;
6631 ret = qla25xx_init_rsp_que(base_vha, rsp);
6632 if (ret != QLA_SUCCESS)
6633 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6634 "%s Rsp que: %d init failed.\n",
6637 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6638 "%s Rsp que: %d inited.\n",
6642 for (i = 1; i < ha->max_req_queues; i++) {
6643 req = ha->req_q_map[i];
6644 if (req && test_bit(i, ha->req_qid_map)) {
6645 /* Clear outstanding commands array. */
6646 req->options &= ~BIT_0;
6647 ret = qla25xx_init_req_que(base_vha, req);
6648 if (ret != QLA_SUCCESS)
6649 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6650 "%s Req que: %d init failed.\n",
6653 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6654 "%s Req que: %d inited.\n",
6662 * qla2x00_reset_adapter
6666 * ha = adapter block pointer.
6669 qla2x00_reset_adapter(scsi_qla_host_t *vha)
6671 unsigned long flags = 0;
6672 struct qla_hw_data *ha = vha->hw;
6673 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6675 vha->flags.online = 0;
6676 ha->isp_ops->disable_intrs(ha);
6678 spin_lock_irqsave(&ha->hardware_lock, flags);
6679 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
6680 RD_REG_WORD(®->hccr); /* PCI Posting. */
6681 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
6682 RD_REG_WORD(®->hccr); /* PCI Posting. */
6683 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6687 qla24xx_reset_adapter(scsi_qla_host_t *vha)
6689 unsigned long flags = 0;
6690 struct qla_hw_data *ha = vha->hw;
6691 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6693 if (IS_P3P_TYPE(ha))
6696 vha->flags.online = 0;
6697 ha->isp_ops->disable_intrs(ha);
6699 spin_lock_irqsave(&ha->hardware_lock, flags);
6700 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
6701 RD_REG_DWORD(®->hccr);
6702 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
6703 RD_REG_DWORD(®->hccr);
6704 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6706 if (IS_NOPOLLING_TYPE(ha))
6707 ha->isp_ops->enable_intrs(ha);
6710 /* On sparc systems, obtain port and node WWN from firmware
6713 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6714 struct nvram_24xx *nv)
6717 struct qla_hw_data *ha = vha->hw;
6718 struct pci_dev *pdev = ha->pdev;
6719 struct device_node *dp = pci_device_to_OF_node(pdev);
6723 val = of_get_property(dp, "port-wwn", &len);
6724 if (val && len >= WWN_SIZE)
6725 memcpy(nv->port_name, val, WWN_SIZE);
6727 val = of_get_property(dp, "node-wwn", &len);
6728 if (val && len >= WWN_SIZE)
6729 memcpy(nv->node_name, val, WWN_SIZE);
6734 qla24xx_nvram_config(scsi_qla_host_t *vha)
6737 struct init_cb_24xx *icb;
6738 struct nvram_24xx *nv;
6740 uint8_t *dptr1, *dptr2;
6743 struct qla_hw_data *ha = vha->hw;
6746 icb = (struct init_cb_24xx *)ha->init_cb;
6749 /* Determine NVRAM starting address. */
6750 if (ha->port_no == 0) {
6751 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6752 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6754 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
6755 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6758 ha->nvram_size = sizeof(struct nvram_24xx);
6759 ha->vpd_size = FA_NVRAM_VPD_SIZE;
6761 /* Get VPD data into cache */
6762 ha->vpd = ha->nvram + VPD_OFFSET;
6763 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
6764 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6766 /* Get NVRAM data into cache and calculate checksum. */
6767 dptr = (uint32_t *)nv;
6768 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
6770 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6771 chksum += le32_to_cpu(*dptr);
6773 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6774 "Contents of NVRAM\n");
6775 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6776 (uint8_t *)nv, ha->nvram_size);
6778 /* Bad NVRAM data, set defaults parameters. */
6779 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6780 || nv->id[3] != ' ' ||
6781 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
6782 /* Reset NVRAM data. */
6783 ql_log(ql_log_warn, vha, 0x006b,
6784 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6785 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6786 ql_log(ql_log_warn, vha, 0x006c,
6787 "Falling back to functioning (yet invalid -- WWPN) "
6791 * Set default initialization control block.
6793 memset(nv, 0, ha->nvram_size);
6794 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6795 nv->version = cpu_to_le16(ICB_VERSION);
6796 nv->frame_payload_size = 2048;
6797 nv->execution_throttle = cpu_to_le16(0xFFFF);
6798 nv->exchange_count = cpu_to_le16(0);
6799 nv->hard_address = cpu_to_le16(124);
6800 nv->port_name[0] = 0x21;
6801 nv->port_name[1] = 0x00 + ha->port_no + 1;
6802 nv->port_name[2] = 0x00;
6803 nv->port_name[3] = 0xe0;
6804 nv->port_name[4] = 0x8b;
6805 nv->port_name[5] = 0x1c;
6806 nv->port_name[6] = 0x55;
6807 nv->port_name[7] = 0x86;
6808 nv->node_name[0] = 0x20;
6809 nv->node_name[1] = 0x00;
6810 nv->node_name[2] = 0x00;
6811 nv->node_name[3] = 0xe0;
6812 nv->node_name[4] = 0x8b;
6813 nv->node_name[5] = 0x1c;
6814 nv->node_name[6] = 0x55;
6815 nv->node_name[7] = 0x86;
6816 qla24xx_nvram_wwn_from_ofw(vha, nv);
6817 nv->login_retry_count = cpu_to_le16(8);
6818 nv->interrupt_delay_timer = cpu_to_le16(0);
6819 nv->login_timeout = cpu_to_le16(0);
6820 nv->firmware_options_1 =
6821 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6822 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6823 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6824 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6825 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6826 nv->efi_parameters = cpu_to_le32(0);
6827 nv->reset_delay = 5;
6828 nv->max_luns_per_target = cpu_to_le16(128);
6829 nv->port_down_retry_count = cpu_to_le16(30);
6830 nv->link_down_timeout = cpu_to_le16(30);
6835 if (qla_tgt_mode_enabled(vha)) {
6836 /* Don't enable full login after initial LIP */
6837 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6838 /* Don't enable LIP full login for initiator */
6839 nv->host_p &= cpu_to_le32(~BIT_10);
6842 qlt_24xx_config_nvram_stage1(vha, nv);
6844 /* Reset Initialization control block */
6845 memset(icb, 0, ha->init_cb_size);
6847 /* Copy 1st segment. */
6848 dptr1 = (uint8_t *)icb;
6849 dptr2 = (uint8_t *)&nv->version;
6850 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6852 *dptr1++ = *dptr2++;
6854 icb->login_retry_count = nv->login_retry_count;
6855 icb->link_down_on_nos = nv->link_down_on_nos;
6857 /* Copy 2nd segment. */
6858 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6859 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6860 cnt = (uint8_t *)&icb->reserved_3 -
6861 (uint8_t *)&icb->interrupt_delay_timer;
6863 *dptr1++ = *dptr2++;
6866 * Setup driver NVRAM options.
6868 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
6871 qlt_24xx_config_nvram_stage2(vha, icb);
6873 if (nv->host_p & cpu_to_le32(BIT_15)) {
6874 /* Use alternate WWN? */
6875 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6876 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6879 /* Prepare nodename */
6880 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
6882 * Firmware will apply the following mask if the nodename was
6885 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6886 icb->node_name[0] &= 0xF0;
6889 /* Set host adapter parameters. */
6890 ha->flags.disable_risc_code_load = 0;
6891 ha->flags.enable_lip_reset = 0;
6892 ha->flags.enable_lip_full_login =
6893 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6894 ha->flags.enable_target_reset =
6895 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6896 ha->flags.enable_led_scheme = 0;
6897 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6899 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6900 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6902 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6903 sizeof(ha->fw_seriallink_options24));
6905 /* save HBA serial number */
6906 ha->serial0 = icb->port_name[5];
6907 ha->serial1 = icb->port_name[6];
6908 ha->serial2 = icb->port_name[7];
6909 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6910 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6912 icb->execution_throttle = cpu_to_le16(0xFFFF);
6914 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6916 /* Set minimum login_timeout to 4 seconds. */
6917 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6918 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6919 if (le16_to_cpu(nv->login_timeout) < 4)
6920 nv->login_timeout = cpu_to_le16(4);
6921 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6923 /* Set minimum RATOV to 100 tenths of a second. */
6926 ha->loop_reset_delay = nv->reset_delay;
6928 /* Link Down Timeout = 0:
6930 * When Port Down timer expires we will start returning
6931 * I/O's to OS with "DID_NO_CONNECT".
6933 * Link Down Timeout != 0:
6935 * The driver waits for the link to come up after link down
6936 * before returning I/Os to OS with "DID_NO_CONNECT".
6938 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6939 ha->loop_down_abort_time =
6940 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6942 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6943 ha->loop_down_abort_time =
6944 (LOOP_DOWN_TIME - ha->link_down_timeout);
6947 /* Need enough time to try and get the port back. */
6948 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6949 if (qlport_down_retry)
6950 ha->port_down_retry_count = qlport_down_retry;
6952 /* Set login_retry_count */
6953 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6954 if (ha->port_down_retry_count ==
6955 le16_to_cpu(nv->port_down_retry_count) &&
6956 ha->port_down_retry_count > 3)
6957 ha->login_retry_count = ha->port_down_retry_count;
6958 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6959 ha->login_retry_count = ha->port_down_retry_count;
6960 if (ql2xloginretrycount)
6961 ha->login_retry_count = ql2xloginretrycount;
6964 if (!vha->flags.init_done) {
6965 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6966 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6967 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6968 le16_to_cpu(icb->interrupt_delay_timer): 2;
6970 icb->firmware_options_2 &= cpu_to_le32(
6971 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6972 vha->flags.process_response_queue = 0;
6973 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6974 ha->zio_mode = QLA_ZIO_MODE_6;
6976 ql_log(ql_log_info, vha, 0x006f,
6977 "ZIO mode %d enabled; timer delay (%d us).\n",
6978 ha->zio_mode, ha->zio_timer * 100);
6980 icb->firmware_options_2 |= cpu_to_le32(
6981 (uint32_t)ha->zio_mode);
6982 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6983 vha->flags.process_response_queue = 1;
6987 ql_log(ql_log_warn, vha, 0x0070,
6988 "NVRAM configuration failed.\n");
6993 uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6995 struct qla27xx_image_status pri_image_status, sec_image_status;
6996 uint8_t valid_pri_image, valid_sec_image;
6998 uint32_t cnt, chksum, size;
6999 struct qla_hw_data *ha = vha->hw;
7001 valid_pri_image = valid_sec_image = 1;
7002 ha->active_image = 0;
7003 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
7005 if (!ha->flt_region_img_status_pri) {
7006 valid_pri_image = 0;
7007 goto check_sec_image;
7010 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
7011 ha->flt_region_img_status_pri, size);
7013 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7014 ql_dbg(ql_dbg_init, vha, 0x018b,
7015 "Primary image signature (0x%x) not valid\n",
7016 pri_image_status.signature);
7017 valid_pri_image = 0;
7018 goto check_sec_image;
7021 wptr = (uint32_t *)(&pri_image_status);
7024 for (chksum = 0; cnt--; wptr++)
7025 chksum += le32_to_cpu(*wptr);
7028 ql_dbg(ql_dbg_init, vha, 0x018c,
7029 "Checksum validation failed for primary image (0x%x)\n",
7031 valid_pri_image = 0;
7035 if (!ha->flt_region_img_status_sec) {
7036 valid_sec_image = 0;
7037 goto check_valid_image;
7040 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7041 ha->flt_region_img_status_sec, size);
7043 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7044 ql_dbg(ql_dbg_init, vha, 0x018d,
7045 "Secondary image signature(0x%x) not valid\n",
7046 sec_image_status.signature);
7047 valid_sec_image = 0;
7048 goto check_valid_image;
7051 wptr = (uint32_t *)(&sec_image_status);
7053 for (chksum = 0; cnt--; wptr++)
7054 chksum += le32_to_cpu(*wptr);
7056 ql_dbg(ql_dbg_init, vha, 0x018e,
7057 "Checksum validation failed for secondary image (0x%x)\n",
7059 valid_sec_image = 0;
7063 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
7064 ha->active_image = QLA27XX_PRIMARY_IMAGE;
7065 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
7066 if (!ha->active_image ||
7067 pri_image_status.generation_number <
7068 sec_image_status.generation_number)
7069 ha->active_image = QLA27XX_SECONDARY_IMAGE;
7072 ql_dbg(ql_dbg_init, vha, 0x018f, "%s image\n",
7073 ha->active_image == 0 ? "default bootld and fw" :
7074 ha->active_image == 1 ? "primary" :
7075 ha->active_image == 2 ? "secondary" :
7078 return ha->active_image;
7082 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7085 int rval = QLA_SUCCESS;
7086 int segments, fragment;
7087 uint32_t *dcode, dlen;
7091 struct qla_hw_data *ha = vha->hw;
7092 struct req_que *req = ha->req_q_map[0];
7094 ql_dbg(ql_dbg_init, vha, 0x008b,
7095 "FW: Loading firmware from flash (%x).\n", faddr);
7099 segments = FA_RISC_CODE_SEGMENTS;
7100 dcode = (uint32_t *)req->ring;
7103 if (IS_QLA27XX(ha) &&
7104 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
7105 faddr = ha->flt_region_fw_sec;
7107 /* Validate firmware image by checking version. */
7108 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
7109 for (i = 0; i < 4; i++)
7110 dcode[i] = be32_to_cpu(dcode[i]);
7111 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7112 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7113 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7115 ql_log(ql_log_fatal, vha, 0x008c,
7116 "Unable to verify the integrity of flash firmware "
7118 ql_log(ql_log_fatal, vha, 0x008d,
7119 "Firmware data: %08x %08x %08x %08x.\n",
7120 dcode[0], dcode[1], dcode[2], dcode[3]);
7122 return QLA_FUNCTION_FAILED;
7125 while (segments && rval == QLA_SUCCESS) {
7126 /* Read segment's load information. */
7127 qla24xx_read_flash_data(vha, dcode, faddr, 4);
7129 risc_addr = be32_to_cpu(dcode[2]);
7130 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7131 risc_size = be32_to_cpu(dcode[3]);
7134 while (risc_size > 0 && rval == QLA_SUCCESS) {
7135 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7136 if (dlen > risc_size)
7139 ql_dbg(ql_dbg_init, vha, 0x008e,
7140 "Loading risc segment@ risc addr %x "
7141 "number of dwords 0x%x offset 0x%x.\n",
7142 risc_addr, dlen, faddr);
7144 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7145 for (i = 0; i < dlen; i++)
7146 dcode[i] = swab32(dcode[i]);
7148 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7151 ql_log(ql_log_fatal, vha, 0x008f,
7152 "Failed to load segment %d of firmware.\n",
7154 return QLA_FUNCTION_FAILED;
7167 if (!IS_QLA27XX(ha))
7170 if (ha->fw_dump_template)
7171 vfree(ha->fw_dump_template);
7172 ha->fw_dump_template = NULL;
7173 ha->fw_dump_template_len = 0;
7175 ql_dbg(ql_dbg_init, vha, 0x0161,
7176 "Loading fwdump template from %x\n", faddr);
7177 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7178 risc_size = be32_to_cpu(dcode[2]);
7179 ql_dbg(ql_dbg_init, vha, 0x0162,
7180 "-> array size %x dwords\n", risc_size);
7181 if (risc_size == 0 || risc_size == ~0)
7182 goto default_template;
7184 dlen = (risc_size - 8) * sizeof(*dcode);
7185 ql_dbg(ql_dbg_init, vha, 0x0163,
7186 "-> template allocating %x bytes...\n", dlen);
7187 ha->fw_dump_template = vmalloc(dlen);
7188 if (!ha->fw_dump_template) {
7189 ql_log(ql_log_warn, vha, 0x0164,
7190 "Failed fwdump template allocate %x bytes.\n", risc_size);
7191 goto default_template;
7196 dcode = ha->fw_dump_template;
7197 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7198 for (i = 0; i < risc_size; i++)
7199 dcode[i] = le32_to_cpu(dcode[i]);
7201 if (!qla27xx_fwdt_template_valid(dcode)) {
7202 ql_log(ql_log_warn, vha, 0x0165,
7203 "Failed fwdump template validate\n");
7204 goto default_template;
7207 dlen = qla27xx_fwdt_template_size(dcode);
7208 ql_dbg(ql_dbg_init, vha, 0x0166,
7209 "-> template size %x bytes\n", dlen);
7210 if (dlen > risc_size * sizeof(*dcode)) {
7211 ql_log(ql_log_warn, vha, 0x0167,
7212 "Failed fwdump template exceeds array by %zx bytes\n",
7213 (size_t)(dlen - risc_size * sizeof(*dcode)));
7214 goto default_template;
7216 ha->fw_dump_template_len = dlen;
7220 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
7221 if (ha->fw_dump_template)
7222 vfree(ha->fw_dump_template);
7223 ha->fw_dump_template = NULL;
7224 ha->fw_dump_template_len = 0;
7226 dlen = qla27xx_fwdt_template_default_size();
7227 ql_dbg(ql_dbg_init, vha, 0x0169,
7228 "-> template allocating %x bytes...\n", dlen);
7229 ha->fw_dump_template = vmalloc(dlen);
7230 if (!ha->fw_dump_template) {
7231 ql_log(ql_log_warn, vha, 0x016a,
7232 "Failed fwdump template allocate %x bytes.\n", risc_size);
7233 goto failed_template;
7236 dcode = ha->fw_dump_template;
7237 risc_size = dlen / sizeof(*dcode);
7238 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
7239 for (i = 0; i < risc_size; i++)
7240 dcode[i] = be32_to_cpu(dcode[i]);
7242 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7243 ql_log(ql_log_warn, vha, 0x016b,
7244 "Failed fwdump template validate\n");
7245 goto failed_template;
7248 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7249 ql_dbg(ql_dbg_init, vha, 0x016c,
7250 "-> template size %x bytes\n", dlen);
7251 ha->fw_dump_template_len = dlen;
7255 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
7256 if (ha->fw_dump_template)
7257 vfree(ha->fw_dump_template);
7258 ha->fw_dump_template = NULL;
7259 ha->fw_dump_template_len = 0;
7263 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7266 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7270 uint16_t *wcode, *fwcode;
7271 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7272 struct fw_blob *blob;
7273 struct qla_hw_data *ha = vha->hw;
7274 struct req_que *req = ha->req_q_map[0];
7276 /* Load firmware blob. */
7277 blob = qla2x00_request_firmware(vha);
7279 ql_log(ql_log_info, vha, 0x0083,
7280 "Firmware image unavailable.\n");
7281 ql_log(ql_log_info, vha, 0x0084,
7282 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7283 return QLA_FUNCTION_FAILED;
7288 wcode = (uint16_t *)req->ring;
7290 fwcode = (uint16_t *)blob->fw->data;
7293 /* Validate firmware image by checking version. */
7294 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7295 ql_log(ql_log_fatal, vha, 0x0085,
7296 "Unable to verify integrity of firmware image (%zd).\n",
7298 goto fail_fw_integrity;
7300 for (i = 0; i < 4; i++)
7301 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7302 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7303 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7304 wcode[2] == 0 && wcode[3] == 0)) {
7305 ql_log(ql_log_fatal, vha, 0x0086,
7306 "Unable to verify integrity of firmware image.\n");
7307 ql_log(ql_log_fatal, vha, 0x0087,
7308 "Firmware data: %04x %04x %04x %04x.\n",
7309 wcode[0], wcode[1], wcode[2], wcode[3]);
7310 goto fail_fw_integrity;
7314 while (*seg && rval == QLA_SUCCESS) {
7316 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7317 risc_size = be16_to_cpu(fwcode[3]);
7319 /* Validate firmware image size. */
7320 fwclen += risc_size * sizeof(uint16_t);
7321 if (blob->fw->size < fwclen) {
7322 ql_log(ql_log_fatal, vha, 0x0088,
7323 "Unable to verify integrity of firmware image "
7324 "(%zd).\n", blob->fw->size);
7325 goto fail_fw_integrity;
7329 while (risc_size > 0 && rval == QLA_SUCCESS) {
7330 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7331 if (wlen > risc_size)
7333 ql_dbg(ql_dbg_init, vha, 0x0089,
7334 "Loading risc segment@ risc addr %x number of "
7335 "words 0x%x.\n", risc_addr, wlen);
7337 for (i = 0; i < wlen; i++)
7338 wcode[i] = swab16(fwcode[i]);
7340 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7343 ql_log(ql_log_fatal, vha, 0x008a,
7344 "Failed to load segment %d of firmware.\n",
7361 return QLA_FUNCTION_FAILED;
7365 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7368 int segments, fragment;
7369 uint32_t *dcode, dlen;
7373 struct fw_blob *blob;
7374 const uint32_t *fwcode;
7376 struct qla_hw_data *ha = vha->hw;
7377 struct req_que *req = ha->req_q_map[0];
7379 /* Load firmware blob. */
7380 blob = qla2x00_request_firmware(vha);
7382 ql_log(ql_log_warn, vha, 0x0090,
7383 "Firmware image unavailable.\n");
7384 ql_log(ql_log_warn, vha, 0x0091,
7385 "Firmware images can be retrieved from: "
7388 return QLA_FUNCTION_FAILED;
7391 ql_dbg(ql_dbg_init, vha, 0x0092,
7392 "FW: Loading via request-firmware.\n");
7396 segments = FA_RISC_CODE_SEGMENTS;
7397 dcode = (uint32_t *)req->ring;
7399 fwcode = (uint32_t *)blob->fw->data;
7402 /* Validate firmware image by checking version. */
7403 if (blob->fw->size < 8 * sizeof(uint32_t)) {
7404 ql_log(ql_log_fatal, vha, 0x0093,
7405 "Unable to verify integrity of firmware image (%zd).\n",
7407 return QLA_FUNCTION_FAILED;
7409 for (i = 0; i < 4; i++)
7410 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7411 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7412 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7413 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7415 ql_log(ql_log_fatal, vha, 0x0094,
7416 "Unable to verify integrity of firmware image (%zd).\n",
7418 ql_log(ql_log_fatal, vha, 0x0095,
7419 "Firmware data: %08x %08x %08x %08x.\n",
7420 dcode[0], dcode[1], dcode[2], dcode[3]);
7421 return QLA_FUNCTION_FAILED;
7424 while (segments && rval == QLA_SUCCESS) {
7425 risc_addr = be32_to_cpu(fwcode[2]);
7426 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7427 risc_size = be32_to_cpu(fwcode[3]);
7429 /* Validate firmware image size. */
7430 fwclen += risc_size * sizeof(uint32_t);
7431 if (blob->fw->size < fwclen) {
7432 ql_log(ql_log_fatal, vha, 0x0096,
7433 "Unable to verify integrity of firmware image "
7434 "(%zd).\n", blob->fw->size);
7435 return QLA_FUNCTION_FAILED;
7439 while (risc_size > 0 && rval == QLA_SUCCESS) {
7440 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7441 if (dlen > risc_size)
7444 ql_dbg(ql_dbg_init, vha, 0x0097,
7445 "Loading risc segment@ risc addr %x "
7446 "number of dwords 0x%x.\n", risc_addr, dlen);
7448 for (i = 0; i < dlen; i++)
7449 dcode[i] = swab32(fwcode[i]);
7451 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7454 ql_log(ql_log_fatal, vha, 0x0098,
7455 "Failed to load segment %d of firmware.\n",
7457 return QLA_FUNCTION_FAILED;
7470 if (!IS_QLA27XX(ha))
7473 if (ha->fw_dump_template)
7474 vfree(ha->fw_dump_template);
7475 ha->fw_dump_template = NULL;
7476 ha->fw_dump_template_len = 0;
7478 ql_dbg(ql_dbg_init, vha, 0x171,
7479 "Loading fwdump template from %x\n",
7480 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
7481 risc_size = be32_to_cpu(fwcode[2]);
7482 ql_dbg(ql_dbg_init, vha, 0x172,
7483 "-> array size %x dwords\n", risc_size);
7484 if (risc_size == 0 || risc_size == ~0)
7485 goto default_template;
7487 dlen = (risc_size - 8) * sizeof(*fwcode);
7488 ql_dbg(ql_dbg_init, vha, 0x0173,
7489 "-> template allocating %x bytes...\n", dlen);
7490 ha->fw_dump_template = vmalloc(dlen);
7491 if (!ha->fw_dump_template) {
7492 ql_log(ql_log_warn, vha, 0x0174,
7493 "Failed fwdump template allocate %x bytes.\n", risc_size);
7494 goto default_template;
7499 dcode = ha->fw_dump_template;
7500 for (i = 0; i < risc_size; i++)
7501 dcode[i] = le32_to_cpu(fwcode[i]);
7503 if (!qla27xx_fwdt_template_valid(dcode)) {
7504 ql_log(ql_log_warn, vha, 0x0175,
7505 "Failed fwdump template validate\n");
7506 goto default_template;
7509 dlen = qla27xx_fwdt_template_size(dcode);
7510 ql_dbg(ql_dbg_init, vha, 0x0176,
7511 "-> template size %x bytes\n", dlen);
7512 if (dlen > risc_size * sizeof(*fwcode)) {
7513 ql_log(ql_log_warn, vha, 0x0177,
7514 "Failed fwdump template exceeds array by %zx bytes\n",
7515 (size_t)(dlen - risc_size * sizeof(*fwcode)));
7516 goto default_template;
7518 ha->fw_dump_template_len = dlen;
7522 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7523 if (ha->fw_dump_template)
7524 vfree(ha->fw_dump_template);
7525 ha->fw_dump_template = NULL;
7526 ha->fw_dump_template_len = 0;
7528 dlen = qla27xx_fwdt_template_default_size();
7529 ql_dbg(ql_dbg_init, vha, 0x0179,
7530 "-> template allocating %x bytes...\n", dlen);
7531 ha->fw_dump_template = vmalloc(dlen);
7532 if (!ha->fw_dump_template) {
7533 ql_log(ql_log_warn, vha, 0x017a,
7534 "Failed fwdump template allocate %x bytes.\n", risc_size);
7535 goto failed_template;
7538 dcode = ha->fw_dump_template;
7539 risc_size = dlen / sizeof(*fwcode);
7540 fwcode = qla27xx_fwdt_template_default();
7541 for (i = 0; i < risc_size; i++)
7542 dcode[i] = be32_to_cpu(fwcode[i]);
7544 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7545 ql_log(ql_log_warn, vha, 0x017b,
7546 "Failed fwdump template validate\n");
7547 goto failed_template;
7550 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7551 ql_dbg(ql_dbg_init, vha, 0x017c,
7552 "-> template size %x bytes\n", dlen);
7553 ha->fw_dump_template_len = dlen;
7557 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7558 if (ha->fw_dump_template)
7559 vfree(ha->fw_dump_template);
7560 ha->fw_dump_template = NULL;
7561 ha->fw_dump_template_len = 0;
7566 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7570 if (ql2xfwloadbin == 1)
7571 return qla81xx_load_risc(vha, srisc_addr);
7575 * 1) Firmware via request-firmware interface (.bin file).
7576 * 2) Firmware residing in flash.
7578 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7579 if (rval == QLA_SUCCESS)
7582 return qla24xx_load_risc_flash(vha, srisc_addr,
7583 vha->hw->flt_region_fw);
7587 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7590 struct qla_hw_data *ha = vha->hw;
7592 if (ql2xfwloadbin == 2)
7597 * 1) Firmware residing in flash.
7598 * 2) Firmware via request-firmware interface (.bin file).
7599 * 3) Golden-Firmware residing in flash -- limited operation.
7601 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
7602 if (rval == QLA_SUCCESS)
7606 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7607 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7610 ql_log(ql_log_info, vha, 0x0099,
7611 "Attempting to fallback to golden firmware.\n");
7612 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7613 if (rval != QLA_SUCCESS)
7616 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
7617 ha->flags.running_gold_fw = 1;
7622 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
7625 struct qla_hw_data *ha = vha->hw;
7627 if (ha->flags.pci_channel_io_perm_failure)
7629 if (!IS_FWI2_CAPABLE(ha))
7631 if (!ha->fw_major_version)
7633 if (!ha->flags.fw_started)
7636 ret = qla2x00_stop_firmware(vha);
7637 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
7638 ret != QLA_INVALID_COMMAND && retries ; retries--) {
7639 ha->isp_ops->reset_chip(vha);
7640 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
7642 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
7644 ql_log(ql_log_info, vha, 0x8015,
7645 "Attempting retry of stop-firmware command.\n");
7646 ret = qla2x00_stop_firmware(vha);
7650 ha->flags.fw_init_done = 0;
7654 qla24xx_configure_vhba(scsi_qla_host_t *vha)
7656 int rval = QLA_SUCCESS;
7658 uint16_t mb[MAILBOX_REGISTER_COUNT];
7659 struct qla_hw_data *ha = vha->hw;
7660 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7661 struct req_que *req;
7662 struct rsp_que *rsp;
7667 rval = qla2x00_fw_ready(base_vha);
7669 req = vha->qpair->req;
7671 req = ha->req_q_map[0];
7674 if (rval == QLA_SUCCESS) {
7675 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7676 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
7679 vha->flags.management_server_logged_in = 0;
7681 /* Login to SNS first */
7682 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7684 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7685 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7686 ql_dbg(ql_dbg_init, vha, 0x0120,
7687 "Failed SNS login: loop_id=%x, rval2=%d\n",
7690 ql_dbg(ql_dbg_init, vha, 0x0103,
7691 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7692 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7693 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
7694 return (QLA_FUNCTION_FAILED);
7697 atomic_set(&vha->loop_down_timer, 0);
7698 atomic_set(&vha->loop_state, LOOP_UP);
7699 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7700 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7701 rval = qla2x00_loop_resync(base_vha);
7706 /* 84XX Support **************************************************************/
7708 static LIST_HEAD(qla_cs84xx_list);
7709 static DEFINE_MUTEX(qla_cs84xx_mutex);
7711 static struct qla_chip_state_84xx *
7712 qla84xx_get_chip(struct scsi_qla_host *vha)
7714 struct qla_chip_state_84xx *cs84xx;
7715 struct qla_hw_data *ha = vha->hw;
7717 mutex_lock(&qla_cs84xx_mutex);
7719 /* Find any shared 84xx chip. */
7720 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7721 if (cs84xx->bus == ha->pdev->bus) {
7722 kref_get(&cs84xx->kref);
7727 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7731 kref_init(&cs84xx->kref);
7732 spin_lock_init(&cs84xx->access_lock);
7733 mutex_init(&cs84xx->fw_update_mutex);
7734 cs84xx->bus = ha->pdev->bus;
7736 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7738 mutex_unlock(&qla_cs84xx_mutex);
7743 __qla84xx_chip_release(struct kref *kref)
7745 struct qla_chip_state_84xx *cs84xx =
7746 container_of(kref, struct qla_chip_state_84xx, kref);
7748 mutex_lock(&qla_cs84xx_mutex);
7749 list_del(&cs84xx->list);
7750 mutex_unlock(&qla_cs84xx_mutex);
7755 qla84xx_put_chip(struct scsi_qla_host *vha)
7757 struct qla_hw_data *ha = vha->hw;
7759 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7763 qla84xx_init_chip(scsi_qla_host_t *vha)
7767 struct qla_hw_data *ha = vha->hw;
7769 mutex_lock(&ha->cs84xx->fw_update_mutex);
7771 rval = qla84xx_verify_chip(vha, status);
7773 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7775 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7779 /* 81XX Support **************************************************************/
7782 qla81xx_nvram_config(scsi_qla_host_t *vha)
7785 struct init_cb_81xx *icb;
7786 struct nvram_81xx *nv;
7788 uint8_t *dptr1, *dptr2;
7791 struct qla_hw_data *ha = vha->hw;
7794 icb = (struct init_cb_81xx *)ha->init_cb;
7797 /* Determine NVRAM starting address. */
7798 ha->nvram_size = sizeof(struct nvram_81xx);
7799 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7800 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7801 ha->vpd_size = FA_VPD_SIZE_82XX;
7803 /* Get VPD data into cache */
7804 ha->vpd = ha->nvram + VPD_OFFSET;
7805 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7808 /* Get NVRAM data into cache and calculate checksum. */
7809 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
7811 dptr = (uint32_t *)nv;
7812 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7813 chksum += le32_to_cpu(*dptr);
7815 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7816 "Contents of NVRAM:\n");
7817 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7818 (uint8_t *)nv, ha->nvram_size);
7820 /* Bad NVRAM data, set defaults parameters. */
7821 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7822 || nv->id[3] != ' ' ||
7823 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
7824 /* Reset NVRAM data. */
7825 ql_log(ql_log_info, vha, 0x0073,
7826 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7827 "version=0x%x.\n", chksum, nv->id[0],
7828 le16_to_cpu(nv->nvram_version));
7829 ql_log(ql_log_info, vha, 0x0074,
7830 "Falling back to functioning (yet invalid -- WWPN) "
7834 * Set default initialization control block.
7836 memset(nv, 0, ha->nvram_size);
7837 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7838 nv->version = cpu_to_le16(ICB_VERSION);
7839 nv->frame_payload_size = 2048;
7840 nv->execution_throttle = cpu_to_le16(0xFFFF);
7841 nv->exchange_count = cpu_to_le16(0);
7842 nv->port_name[0] = 0x21;
7843 nv->port_name[1] = 0x00 + ha->port_no + 1;
7844 nv->port_name[2] = 0x00;
7845 nv->port_name[3] = 0xe0;
7846 nv->port_name[4] = 0x8b;
7847 nv->port_name[5] = 0x1c;
7848 nv->port_name[6] = 0x55;
7849 nv->port_name[7] = 0x86;
7850 nv->node_name[0] = 0x20;
7851 nv->node_name[1] = 0x00;
7852 nv->node_name[2] = 0x00;
7853 nv->node_name[3] = 0xe0;
7854 nv->node_name[4] = 0x8b;
7855 nv->node_name[5] = 0x1c;
7856 nv->node_name[6] = 0x55;
7857 nv->node_name[7] = 0x86;
7858 nv->login_retry_count = cpu_to_le16(8);
7859 nv->interrupt_delay_timer = cpu_to_le16(0);
7860 nv->login_timeout = cpu_to_le16(0);
7861 nv->firmware_options_1 =
7862 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7863 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7864 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7865 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7866 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7867 nv->efi_parameters = cpu_to_le32(0);
7868 nv->reset_delay = 5;
7869 nv->max_luns_per_target = cpu_to_le16(128);
7870 nv->port_down_retry_count = cpu_to_le16(30);
7871 nv->link_down_timeout = cpu_to_le16(180);
7872 nv->enode_mac[0] = 0x00;
7873 nv->enode_mac[1] = 0xC0;
7874 nv->enode_mac[2] = 0xDD;
7875 nv->enode_mac[3] = 0x04;
7876 nv->enode_mac[4] = 0x05;
7877 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
7882 if (IS_T10_PI_CAPABLE(ha))
7883 nv->frame_payload_size &= ~7;
7885 qlt_81xx_config_nvram_stage1(vha, nv);
7887 /* Reset Initialization control block */
7888 memset(icb, 0, ha->init_cb_size);
7890 /* Copy 1st segment. */
7891 dptr1 = (uint8_t *)icb;
7892 dptr2 = (uint8_t *)&nv->version;
7893 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7895 *dptr1++ = *dptr2++;
7897 icb->login_retry_count = nv->login_retry_count;
7899 /* Copy 2nd segment. */
7900 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7901 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7902 cnt = (uint8_t *)&icb->reserved_5 -
7903 (uint8_t *)&icb->interrupt_delay_timer;
7905 *dptr1++ = *dptr2++;
7907 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7908 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7909 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
7910 icb->enode_mac[0] = 0x00;
7911 icb->enode_mac[1] = 0xC0;
7912 icb->enode_mac[2] = 0xDD;
7913 icb->enode_mac[3] = 0x04;
7914 icb->enode_mac[4] = 0x05;
7915 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
7918 /* Use extended-initialization control block. */
7919 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7922 * Setup driver NVRAM options.
7924 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7927 qlt_81xx_config_nvram_stage2(vha, icb);
7929 /* Use alternate WWN? */
7930 if (nv->host_p & cpu_to_le32(BIT_15)) {
7931 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7932 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7935 /* Prepare nodename */
7936 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7938 * Firmware will apply the following mask if the nodename was
7941 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7942 icb->node_name[0] &= 0xF0;
7945 /* Set host adapter parameters. */
7946 ha->flags.disable_risc_code_load = 0;
7947 ha->flags.enable_lip_reset = 0;
7948 ha->flags.enable_lip_full_login =
7949 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7950 ha->flags.enable_target_reset =
7951 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7952 ha->flags.enable_led_scheme = 0;
7953 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7955 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7956 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7958 /* save HBA serial number */
7959 ha->serial0 = icb->port_name[5];
7960 ha->serial1 = icb->port_name[6];
7961 ha->serial2 = icb->port_name[7];
7962 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7963 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7965 icb->execution_throttle = cpu_to_le16(0xFFFF);
7967 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7969 /* Set minimum login_timeout to 4 seconds. */
7970 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7971 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7972 if (le16_to_cpu(nv->login_timeout) < 4)
7973 nv->login_timeout = cpu_to_le16(4);
7974 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7976 /* Set minimum RATOV to 100 tenths of a second. */
7979 ha->loop_reset_delay = nv->reset_delay;
7981 /* Link Down Timeout = 0:
7983 * When Port Down timer expires we will start returning
7984 * I/O's to OS with "DID_NO_CONNECT".
7986 * Link Down Timeout != 0:
7988 * The driver waits for the link to come up after link down
7989 * before returning I/Os to OS with "DID_NO_CONNECT".
7991 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7992 ha->loop_down_abort_time =
7993 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7995 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7996 ha->loop_down_abort_time =
7997 (LOOP_DOWN_TIME - ha->link_down_timeout);
8000 /* Need enough time to try and get the port back. */
8001 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8002 if (qlport_down_retry)
8003 ha->port_down_retry_count = qlport_down_retry;
8005 /* Set login_retry_count */
8006 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8007 if (ha->port_down_retry_count ==
8008 le16_to_cpu(nv->port_down_retry_count) &&
8009 ha->port_down_retry_count > 3)
8010 ha->login_retry_count = ha->port_down_retry_count;
8011 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8012 ha->login_retry_count = ha->port_down_retry_count;
8013 if (ql2xloginretrycount)
8014 ha->login_retry_count = ql2xloginretrycount;
8016 /* if not running MSI-X we need handshaking on interrupts */
8017 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
8018 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8021 if (!vha->flags.init_done) {
8022 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8023 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8024 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8025 le16_to_cpu(icb->interrupt_delay_timer): 2;
8027 icb->firmware_options_2 &= cpu_to_le32(
8028 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8029 vha->flags.process_response_queue = 0;
8030 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8031 ha->zio_mode = QLA_ZIO_MODE_6;
8033 ql_log(ql_log_info, vha, 0x0075,
8034 "ZIO mode %d enabled; timer delay (%d us).\n",
8036 ha->zio_timer * 100);
8038 icb->firmware_options_2 |= cpu_to_le32(
8039 (uint32_t)ha->zio_mode);
8040 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8041 vha->flags.process_response_queue = 1;
8044 /* enable RIDA Format2 */
8045 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha))
8046 icb->firmware_options_3 |= BIT_0;
8048 if (IS_QLA27XX(ha)) {
8049 icb->firmware_options_3 |= BIT_8;
8050 ql_dbg(ql_log_info, vha, 0x0075,
8051 "Enabling direct connection.\n");
8055 ql_log(ql_log_warn, vha, 0x0076,
8056 "NVRAM configuration failed.\n");
8062 qla82xx_restart_isp(scsi_qla_host_t *vha)
8065 struct qla_hw_data *ha = vha->hw;
8066 struct req_que *req = ha->req_q_map[0];
8067 struct rsp_que *rsp = ha->rsp_q_map[0];
8068 struct scsi_qla_host *vp;
8069 unsigned long flags;
8071 status = qla2x00_init_rings(vha);
8073 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8074 ha->flags.chip_reset_done = 1;
8076 status = qla2x00_fw_ready(vha);
8078 /* Issue a marker after FW becomes ready. */
8079 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
8080 vha->flags.online = 1;
8081 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8084 /* if no cable then assume it's good */
8085 if ((vha->device_flags & DFLG_NO_CABLE))
8090 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8092 if (!atomic_read(&vha->loop_down_timer)) {
8094 * Issue marker command only when we are going
8095 * to start the I/O .
8097 vha->marker_needed = 1;
8100 ha->isp_ops->enable_intrs(ha);
8102 ha->isp_abort_cnt = 0;
8103 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8105 /* Update the firmware version */
8106 status = qla82xx_check_md_needed(vha);
8109 ha->flags.fce_enabled = 1;
8111 fce_calc_size(ha->fce_bufs));
8112 rval = qla2x00_enable_fce_trace(vha,
8113 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8116 ql_log(ql_log_warn, vha, 0x8001,
8117 "Unable to reinitialize FCE (%d).\n",
8119 ha->flags.fce_enabled = 0;
8124 memset(ha->eft, 0, EFT_SIZE);
8125 rval = qla2x00_enable_eft_trace(vha,
8126 ha->eft_dma, EFT_NUM_BUFFERS);
8128 ql_log(ql_log_warn, vha, 0x8010,
8129 "Unable to reinitialize EFT (%d).\n",
8136 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8137 "qla82xx_restart_isp succeeded.\n");
8139 spin_lock_irqsave(&ha->vport_slock, flags);
8140 list_for_each_entry(vp, &ha->vp_list, list) {
8142 atomic_inc(&vp->vref_count);
8143 spin_unlock_irqrestore(&ha->vport_slock, flags);
8145 qla2x00_vp_abort_isp(vp);
8147 spin_lock_irqsave(&ha->vport_slock, flags);
8148 atomic_dec(&vp->vref_count);
8151 spin_unlock_irqrestore(&ha->vport_slock, flags);
8154 ql_log(ql_log_warn, vha, 0x8016,
8155 "qla82xx_restart_isp **** FAILED ****.\n");
8162 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8164 struct qla_hw_data *ha = vha->hw;
8166 /* Hold status IOCBs until ABTS response received. */
8168 ha->fw_options[3] |= BIT_12;
8170 /* Set Retry FLOGI in case of P2P connection */
8171 if (ha->operating_mode == P2P) {
8172 ha->fw_options[2] |= BIT_3;
8173 ql_dbg(ql_dbg_disc, vha, 0x2103,
8174 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8175 __func__, ha->fw_options[2]);
8178 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8179 if (ql2xmvasynctoatio) {
8180 if (qla_tgt_mode_enabled(vha) ||
8181 qla_dual_mode_enabled(vha))
8182 ha->fw_options[2] |= BIT_11;
8184 ha->fw_options[2] &= ~BIT_11;
8187 if (qla_tgt_mode_enabled(vha) ||
8188 qla_dual_mode_enabled(vha)) {
8189 /* FW auto send SCSI status during */
8190 ha->fw_options[1] |= BIT_8;
8191 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8193 /* FW perform Exchange validation */
8194 ha->fw_options[2] |= BIT_4;
8196 ha->fw_options[1] &= ~BIT_8;
8197 ha->fw_options[10] &= 0x00ff;
8199 ha->fw_options[2] &= ~BIT_4;
8202 if (ql2xetsenable) {
8203 /* Enable ETS Burst. */
8204 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8205 ha->fw_options[2] |= BIT_9;
8208 ql_dbg(ql_dbg_init, vha, 0x00e9,
8209 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8210 __func__, ha->fw_options[1], ha->fw_options[2],
8211 ha->fw_options[3], vha->host->active_mode);
8213 qla2x00_set_fw_options(vha, ha->fw_options);
8217 * qla24xx_get_fcp_prio
8218 * Gets the fcp cmd priority value for the logged in port.
8219 * Looks for a match of the port descriptors within
8220 * each of the fcp prio config entries. If a match is found,
8221 * the tag (priority) value is returned.
8224 * vha = scsi host structure pointer.
8225 * fcport = port structure pointer.
8228 * non-zero (if found)
8235 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8238 uint8_t pid_match, wwn_match;
8240 uint32_t pid1, pid2;
8241 uint64_t wwn1, wwn2;
8242 struct qla_fcp_prio_entry *pri_entry;
8243 struct qla_hw_data *ha = vha->hw;
8245 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8249 entries = ha->fcp_prio_cfg->num_entries;
8250 pri_entry = &ha->fcp_prio_cfg->entry[0];
8252 for (i = 0; i < entries; i++) {
8253 pid_match = wwn_match = 0;
8255 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8260 /* check source pid for a match */
8261 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8262 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8263 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8264 if (pid1 == INVALID_PORT_ID)
8266 else if (pid1 == pid2)
8270 /* check destination pid for a match */
8271 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8272 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8273 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8274 if (pid1 == INVALID_PORT_ID)
8276 else if (pid1 == pid2)
8280 /* check source WWN for a match */
8281 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8282 wwn1 = wwn_to_u64(vha->port_name);
8283 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8284 if (wwn2 == (uint64_t)-1)
8286 else if (wwn1 == wwn2)
8290 /* check destination WWN for a match */
8291 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8292 wwn1 = wwn_to_u64(fcport->port_name);
8293 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8294 if (wwn2 == (uint64_t)-1)
8296 else if (wwn1 == wwn2)
8300 if (pid_match == 2 || wwn_match == 2) {
8301 /* Found a matching entry */
8302 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8303 priority = pri_entry->tag;
8314 * qla24xx_update_fcport_fcp_prio
8315 * Activates fcp priority for the logged in fc port
8318 * vha = scsi host structure pointer.
8319 * fcp = port structure pointer.
8322 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8328 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8334 if (fcport->port_type != FCT_TARGET ||
8335 fcport->loop_id == FC_NO_LOOP_ID)
8336 return QLA_FUNCTION_FAILED;
8338 priority = qla24xx_get_fcp_prio(vha, fcport);
8340 return QLA_FUNCTION_FAILED;
8342 if (IS_P3P_TYPE(vha->hw)) {
8343 fcport->fcp_prio = priority & 0xf;
8347 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8348 if (ret == QLA_SUCCESS) {
8349 if (fcport->fcp_prio != priority)
8350 ql_dbg(ql_dbg_user, vha, 0x709e,
8351 "Updated FCP_CMND priority - value=%d loop_id=%d "
8352 "port_id=%02x%02x%02x.\n", priority,
8353 fcport->loop_id, fcport->d_id.b.domain,
8354 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8355 fcport->fcp_prio = priority & 0xf;
8357 ql_dbg(ql_dbg_user, vha, 0x704f,
8358 "Unable to update FCP_CMND priority - ret=0x%x for "
8359 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8360 fcport->d_id.b.domain, fcport->d_id.b.area,
8361 fcport->d_id.b.al_pa);
8366 * qla24xx_update_all_fcp_prio
8367 * Activates fcp priority for all the logged in ports
8370 * ha = adapter block pointer.
8373 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8379 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8384 ret = QLA_FUNCTION_FAILED;
8385 /* We need to set priority for all logged in ports */
8386 list_for_each_entry(fcport, &vha->vp_fcports, list)
8387 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8392 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8393 int vp_idx, bool startqp)
8398 struct qla_hw_data *ha = vha->hw;
8399 uint16_t qpair_id = 0;
8400 struct qla_qpair *qpair = NULL;
8401 struct qla_msix_entry *msix;
8403 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8404 ql_log(ql_log_warn, vha, 0x00181,
8405 "FW/Driver is not multi-queue capable.\n");
8409 if (ql2xmqsupport || ql2xnvmeenable) {
8410 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8411 if (qpair == NULL) {
8412 ql_log(ql_log_warn, vha, 0x0182,
8413 "Failed to allocate memory for queue pair.\n");
8416 memset(qpair, 0, sizeof(struct qla_qpair));
8418 qpair->hw = vha->hw;
8420 qpair->qp_lock_ptr = &qpair->qp_lock;
8421 spin_lock_init(&qpair->qp_lock);
8422 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8424 /* Assign available que pair id */
8425 mutex_lock(&ha->mq_lock);
8426 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8427 if (ha->num_qpairs >= ha->max_qpairs) {
8428 mutex_unlock(&ha->mq_lock);
8429 ql_log(ql_log_warn, vha, 0x0183,
8430 "No resources to create additional q pair.\n");
8434 set_bit(qpair_id, ha->qpair_qid_map);
8435 ha->queue_pair_map[qpair_id] = qpair;
8436 qpair->id = qpair_id;
8437 qpair->vp_idx = vp_idx;
8438 qpair->fw_started = ha->flags.fw_started;
8439 INIT_LIST_HEAD(&qpair->hints_list);
8440 qpair->chip_reset = ha->base_qpair->chip_reset;
8441 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8442 qpair->enable_explicit_conf =
8443 ha->base_qpair->enable_explicit_conf;
8445 for (i = 0; i < ha->msix_count; i++) {
8446 msix = &ha->msix_entries[i];
8450 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8451 "Vector %x selected for qpair\n", msix->vector);
8455 ql_log(ql_log_warn, vha, 0x0184,
8456 "Out of MSI-X vectors!.\n");
8460 qpair->msix->in_use = 1;
8461 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8462 qpair->pdev = ha->pdev;
8463 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8464 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8466 mutex_unlock(&ha->mq_lock);
8468 /* Create response queue first */
8469 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8471 ql_log(ql_log_warn, vha, 0x0185,
8472 "Failed to create response queue.\n");
8476 qpair->rsp = ha->rsp_q_map[rsp_id];
8478 /* Create request queue */
8479 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8482 ql_log(ql_log_warn, vha, 0x0186,
8483 "Failed to create request queue.\n");
8487 qpair->req = ha->req_q_map[req_id];
8488 qpair->rsp->req = qpair->req;
8489 qpair->rsp->qpair = qpair;
8490 /* init qpair to this cpu. Will adjust at run time. */
8491 qla_cpu_update(qpair, smp_processor_id());
8493 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8494 if (ha->fw_attributes & BIT_4)
8495 qpair->difdix_supported = 1;
8498 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8499 if (!qpair->srb_mempool) {
8500 ql_log(ql_log_warn, vha, 0xd036,
8501 "Failed to create srb mempool for qpair %d\n",
8506 /* Mark as online */
8509 if (!vha->flags.qpairs_available)
8510 vha->flags.qpairs_available = 1;
8512 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8513 "Request/Response queue pair created, id %d\n",
8515 ql_dbg(ql_dbg_init, vha, 0x0187,
8516 "Request/Response queue pair created, id %d\n",
8523 qla25xx_delete_rsp_que(vha, qpair->rsp);
8525 mutex_lock(&ha->mq_lock);
8526 qpair->msix->in_use = 0;
8527 list_del(&qpair->qp_list_elem);
8528 if (list_empty(&vha->qp_list))
8529 vha->flags.qpairs_available = 0;
8531 ha->queue_pair_map[qpair_id] = NULL;
8532 clear_bit(qpair_id, ha->qpair_qid_map);
8534 mutex_unlock(&ha->mq_lock);
8540 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8542 int ret = QLA_FUNCTION_FAILED;
8543 struct qla_hw_data *ha = qpair->hw;
8545 qpair->delete_in_progress = 1;
8546 while (atomic_read(&qpair->ref_count))
8549 ret = qla25xx_delete_req_que(vha, qpair->req);
8550 if (ret != QLA_SUCCESS)
8553 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8554 if (ret != QLA_SUCCESS)
8557 mutex_lock(&ha->mq_lock);
8558 ha->queue_pair_map[qpair->id] = NULL;
8559 clear_bit(qpair->id, ha->qpair_qid_map);
8561 list_del(&qpair->qp_list_elem);
8562 if (list_empty(&vha->qp_list)) {
8563 vha->flags.qpairs_available = 0;
8564 vha->flags.qpairs_req_created = 0;
8565 vha->flags.qpairs_rsp_created = 0;
8567 mempool_destroy(qpair->srb_mempool);
8569 mutex_unlock(&ha->mq_lock);