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 fcport_is_smaller(fc_port_t *fcport)
166 if (wwn_to_u64(fcport->port_name) <
167 wwn_to_u64(fcport->vha->port_name))
174 fcport_is_bigger(fc_port_t *fcport)
176 return !fcport_is_smaller(fcport);
180 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
184 struct srb_iocb *lio;
185 int rval = QLA_FUNCTION_FAILED;
187 if (!vha->flags.online)
190 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
194 fcport->flags |= FCF_ASYNC_SENT;
195 fcport->logout_completed = 0;
197 fcport->disc_state = DSC_LOGIN_PEND;
198 sp->type = SRB_LOGIN_CMD;
200 sp->gen1 = fcport->rscn_gen;
201 sp->gen2 = fcport->login_gen;
203 lio = &sp->u.iocb_cmd;
204 lio->timeout = qla2x00_async_iocb_timeout;
205 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
207 sp->done = qla2x00_async_login_sp_done;
208 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport)) {
209 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
211 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
213 if (fcport->fc4f_nvme)
214 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
218 rval = qla2x00_start_sp(sp);
219 if (rval != QLA_SUCCESS) {
220 fcport->flags |= FCF_LOGIN_NEEDED;
221 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
225 ql_dbg(ql_dbg_disc, vha, 0x2072,
226 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
227 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
228 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
229 fcport->login_retry);
234 fcport->flags &= ~FCF_ASYNC_SENT;
236 fcport->flags &= ~FCF_ASYNC_ACTIVE;
241 qla2x00_async_logout_sp_done(void *ptr, int res)
245 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
246 sp->fcport->login_gen++;
247 qlt_logo_completion_handler(sp->fcport, res);
252 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
255 struct srb_iocb *lio;
256 int rval = QLA_FUNCTION_FAILED;
258 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
261 fcport->flags |= FCF_ASYNC_SENT;
262 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
266 sp->type = SRB_LOGOUT_CMD;
269 lio = &sp->u.iocb_cmd;
270 lio->timeout = qla2x00_async_iocb_timeout;
271 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
273 sp->done = qla2x00_async_logout_sp_done;
274 rval = qla2x00_start_sp(sp);
275 if (rval != QLA_SUCCESS)
278 ql_dbg(ql_dbg_disc, vha, 0x2070,
279 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
280 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
281 fcport->d_id.b.area, fcport->d_id.b.al_pa,
288 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
293 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
296 fcport->flags &= ~FCF_ASYNC_ACTIVE;
297 /* Don't re-login in target mode */
298 if (!fcport->tgt_session)
299 qla2x00_mark_device_lost(vha, fcport, 1, 0);
300 qlt_logo_completion_handler(fcport, data[0]);
304 qla2x00_async_prlo_sp_done(void *s, int res)
306 srb_t *sp = (srb_t *)s;
307 struct srb_iocb *lio = &sp->u.iocb_cmd;
308 struct scsi_qla_host *vha = sp->vha;
310 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
311 if (!test_bit(UNLOADING, &vha->dpc_flags))
312 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
318 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
321 struct srb_iocb *lio;
324 rval = QLA_FUNCTION_FAILED;
325 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
329 sp->type = SRB_PRLO_CMD;
332 lio = &sp->u.iocb_cmd;
333 lio->timeout = qla2x00_async_iocb_timeout;
334 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
336 sp->done = qla2x00_async_prlo_sp_done;
337 rval = qla2x00_start_sp(sp);
338 if (rval != QLA_SUCCESS)
341 ql_dbg(ql_dbg_disc, vha, 0x2070,
342 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
343 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
344 fcport->d_id.b.area, fcport->d_id.b.al_pa);
350 fcport->flags &= ~FCF_ASYNC_ACTIVE;
355 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
357 struct fc_port *fcport = ea->fcport;
359 ql_dbg(ql_dbg_disc, vha, 0x20d2,
360 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
361 __func__, fcport->port_name, fcport->disc_state,
362 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
363 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
365 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
366 ql_dbg(ql_dbg_disc, vha, 0x2066,
367 "%s %8phC: adisc fail: post delete\n",
368 __func__, ea->fcport->port_name);
369 qlt_schedule_sess_for_deletion(ea->fcport);
373 if (ea->fcport->disc_state == DSC_DELETE_PEND)
376 if (ea->sp->gen2 != ea->fcport->login_gen) {
377 /* target side must have changed it. */
378 ql_dbg(ql_dbg_disc, vha, 0x20d3,
379 "%s %8phC generation changed\n",
380 __func__, ea->fcport->port_name);
382 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
383 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
384 __func__, __LINE__, ea->fcport->port_name);
385 qla24xx_post_gidpn_work(vha, ea->fcport);
389 __qla24xx_handle_gpdb_event(vha, ea);
393 qla2x00_async_adisc_sp_done(void *ptr, int res)
396 struct scsi_qla_host *vha = sp->vha;
398 struct srb_iocb *lio = &sp->u.iocb_cmd;
400 ql_dbg(ql_dbg_disc, vha, 0x2066,
401 "Async done-%s res %x %8phC\n",
402 sp->name, res, sp->fcport->port_name);
404 sp->fcport->flags &= ~FCF_ASYNC_SENT;
406 memset(&ea, 0, sizeof(ea));
407 ea.event = FCME_ADISC_DONE;
409 ea.data[0] = lio->u.logio.data[0];
410 ea.data[1] = lio->u.logio.data[1];
411 ea.iop[0] = lio->u.logio.iop[0];
412 ea.iop[1] = lio->u.logio.iop[1];
413 ea.fcport = sp->fcport;
416 qla2x00_fcport_event_handler(vha, &ea);
422 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
426 struct srb_iocb *lio;
429 rval = QLA_FUNCTION_FAILED;
430 fcport->flags |= FCF_ASYNC_SENT;
431 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
435 sp->type = SRB_ADISC_CMD;
438 lio = &sp->u.iocb_cmd;
439 lio->timeout = qla2x00_async_iocb_timeout;
440 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
442 sp->done = qla2x00_async_adisc_sp_done;
443 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
444 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
445 rval = qla2x00_start_sp(sp);
446 if (rval != QLA_SUCCESS)
449 ql_dbg(ql_dbg_disc, vha, 0x206f,
450 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
451 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
457 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
458 qla2x00_post_async_adisc_work(vha, fcport, data);
462 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
463 struct event_arg *ea)
465 fc_port_t *fcport, *conflict_fcport;
466 struct get_name_list_extended *e;
467 u16 i, n, found = 0, loop_id;
471 u8 current_login_state;
474 ql_dbg(ql_dbg_disc, vha, 0xffff,
475 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
476 __func__, fcport->port_name, fcport->disc_state,
477 fcport->fw_login_state, ea->rc,
478 fcport->login_gen, fcport->last_login_gen,
479 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
481 if (fcport->disc_state == DSC_DELETE_PEND)
484 if (ea->rc) { /* rval */
485 if (fcport->login_retry == 0) {
486 ql_dbg(ql_dbg_disc, vha, 0x20de,
487 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
488 fcport->port_name, fcport->login_retry);
493 if (fcport->last_rscn_gen != fcport->rscn_gen) {
494 ql_dbg(ql_dbg_disc, vha, 0x20df,
495 "%s %8phC rscn gen changed rscn %d|%d \n",
496 __func__, fcport->port_name,
497 fcport->last_rscn_gen, fcport->rscn_gen);
498 qla24xx_post_gidpn_work(vha, fcport);
500 } else if (fcport->last_login_gen != fcport->login_gen) {
501 ql_dbg(ql_dbg_disc, vha, 0x20e0,
502 "%s %8phC login gen changed\n",
503 __func__, fcport->port_name);
507 n = ea->data[0] / sizeof(struct get_name_list_extended);
509 ql_dbg(ql_dbg_disc, vha, 0x20e1,
510 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
511 __func__, __LINE__, fcport->port_name, n,
512 fcport->d_id.b.domain, fcport->d_id.b.area,
513 fcport->d_id.b.al_pa, fcport->loop_id);
515 for (i = 0; i < n; i++) {
517 wwn = wwn_to_u64(e->port_name);
518 id.b.domain = e->port_id[2];
519 id.b.area = e->port_id[1];
520 id.b.al_pa = e->port_id[0];
523 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
526 if (IS_SW_RESV_ADDR(id))
531 loop_id = le16_to_cpu(e->nport_handle);
532 loop_id = (loop_id & 0x7fff);
534 ql_dbg(ql_dbg_disc, vha, 0x20e2,
535 "%s found %8phC CLS [%d|%d] ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
536 __func__, fcport->port_name,
537 e->current_login_state, fcport->fw_login_state,
538 id.b.domain, id.b.area, id.b.al_pa,
539 fcport->d_id.b.domain, fcport->d_id.b.area,
540 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
542 switch (fcport->disc_state) {
543 case DSC_DELETE_PEND:
547 if ((id.b24 != fcport->d_id.b24) ||
548 ((fcport->loop_id != FC_NO_LOOP_ID) &&
549 (fcport->loop_id != loop_id))) {
550 qlt_schedule_sess_for_deletion(fcport);
556 fcport->loop_id = loop_id;
558 wwn = wwn_to_u64(fcport->port_name);
559 qlt_find_sess_invalidate_other(vha, wwn,
560 id, loop_id, &conflict_fcport);
562 if (conflict_fcport) {
564 * Another share fcport share the same loop_id &
565 * nport id. Conflict fcport needs to finish
566 * cleanup before this fcport can proceed to login.
568 conflict_fcport->conflict = fcport;
569 fcport->login_pause = 1;
572 if (fcport->fc4f_nvme)
573 current_login_state = e->current_login_state >> 4;
575 current_login_state = e->current_login_state & 0xf;
577 switch (vha->hw->current_topology) {
579 switch (current_login_state) {
580 case DSC_LS_PRLI_COMP:
581 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
582 vha, 0x20e4, "%s %d %8phC post gpdb\n",
583 __func__, __LINE__, fcport->port_name);
585 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
586 fcport->port_type = FCT_INITIATOR;
588 fcport->port_type = FCT_TARGET;
589 data[0] = data[1] = 0;
590 qla2x00_post_async_adisc_work(vha, fcport,
593 case DSC_LS_PORT_UNAVAIL:
595 if (fcport->loop_id != FC_NO_LOOP_ID)
596 qla2x00_clear_loop_id(fcport);
598 fcport->loop_id = loop_id;
599 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
600 qla24xx_fcport_handle_login(vha, fcport);
605 switch (current_login_state) {
606 case DSC_LS_PRLI_COMP:
607 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
608 fcport->port_type = FCT_INITIATOR;
610 fcport->port_type = FCT_TARGET;
612 data[0] = data[1] = 0;
613 qla2x00_post_async_adisc_work(vha, fcport,
616 case DSC_LS_PLOGI_COMP:
617 if (fcport_is_bigger(fcport)) {
618 /* local adapter is smaller */
619 if (fcport->loop_id != FC_NO_LOOP_ID)
620 qla2x00_clear_loop_id(fcport);
622 fcport->loop_id = loop_id;
623 qla24xx_fcport_handle_login(vha,
629 if (fcport_is_smaller(fcport)) {
630 /* local adapter is bigger */
631 if (fcport->loop_id != FC_NO_LOOP_ID)
632 qla2x00_clear_loop_id(fcport);
634 fcport->loop_id = loop_id;
635 qla24xx_fcport_handle_login(vha,
641 } /* switch (ha->current_topology) */
645 switch (vha->hw->current_topology) {
648 for (i = 0; i < n; i++) {
650 id.b.domain = e->port_id[0];
651 id.b.area = e->port_id[1];
652 id.b.al_pa = e->port_id[2];
654 loop_id = le16_to_cpu(e->nport_handle);
656 if (fcport->d_id.b24 == id.b24) {
658 qla2x00_find_fcport_by_wwpn(vha,
660 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
662 "%s %d %8phC post del sess\n",
664 conflict_fcport->port_name);
665 qlt_schedule_sess_for_deletion
669 * FW already picked this loop id for
672 if (fcport->loop_id == loop_id)
673 fcport->loop_id = FC_NO_LOOP_ID;
675 qla24xx_fcport_handle_login(vha, fcport);
679 * FW handles the initial login for n2n.
680 * Do link reinit to trigger this auto login.
682 set_bit(N2N_LINK_RESET, &vha->dpc_flags);
683 qla2xxx_wake_dpc(vha);
692 qla24xx_async_gnl_sp_done(void *s, int res)
695 struct scsi_qla_host *vha = sp->vha;
697 struct fc_port *fcport = NULL, *tf;
698 u16 i, n = 0, loop_id;
700 struct get_name_list_extended *e;
705 ql_dbg(ql_dbg_disc, vha, 0x20e7,
706 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
707 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
708 sp->u.iocb_cmd.u.mbx.in_mb[2]);
710 memset(&ea, 0, sizeof(ea));
713 ea.event = FCME_GNL_DONE;
715 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
716 sizeof(struct get_name_list_extended)) {
717 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
718 sizeof(struct get_name_list_extended);
719 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
722 for (i = 0; i < n; i++) {
724 loop_id = le16_to_cpu(e->nport_handle);
725 /* mask out reserve bit */
726 loop_id = (loop_id & 0x7fff);
727 set_bit(loop_id, vha->hw->loop_id_map);
728 wwn = wwn_to_u64(e->port_name);
730 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
731 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
732 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
733 e->port_id[0], e->current_login_state, e->last_login_state,
737 spin_lock_irqsave(&vha->gnl.fcports_lock, flags);
741 if (!list_empty(&vha->gnl.fcports))
742 list_splice_init(&vha->gnl.fcports, &h);
744 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
745 list_del_init(&fcport->gnl_entry);
746 spin_lock(&vha->hw->tgt.sess_lock);
747 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
748 spin_unlock(&vha->hw->tgt.sess_lock);
751 qla2x00_fcport_event_handler(vha, &ea);
753 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
755 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
756 /* create new fcport if fw has knowledge of new sessions */
757 for (i = 0; i < n; i++) {
762 wwn = wwn_to_u64(e->port_name);
765 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
766 if (!memcmp((u8 *)&wwn, fcport->port_name,
773 id.b.domain = e->port_id[2];
774 id.b.area = e->port_id[1];
775 id.b.al_pa = e->port_id[0];
778 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
779 ql_dbg(ql_dbg_disc, vha, 0x2065,
780 "%s %d %8phC %06x post new sess\n",
781 __func__, __LINE__, (u8 *)&wwn, id.b24);
782 wwnn = wwn_to_u64(e->node_name);
783 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
784 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
788 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
793 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
796 struct srb_iocb *mbx;
797 int rval = QLA_FUNCTION_FAILED;
801 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
804 ql_dbg(ql_dbg_disc, vha, 0x20d9,
805 "Async-gnlist WWPN %8phC \n", fcport->port_name);
807 spin_lock_irqsave(&vha->gnl.fcports_lock, flags);
808 if (!list_empty(&fcport->gnl_entry)) {
809 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
814 spin_lock(&vha->hw->tgt.sess_lock);
815 fcport->disc_state = DSC_GNL;
816 fcport->last_rscn_gen = fcport->rscn_gen;
817 fcport->last_login_gen = fcport->login_gen;
818 spin_unlock(&vha->hw->tgt.sess_lock);
820 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
821 spin_unlock_irqrestore(&vha->gnl.fcports_lock, flags);
823 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
827 fcport->flags |= FCF_ASYNC_SENT;
828 sp->type = SRB_MB_IOCB;
830 sp->gen1 = fcport->rscn_gen;
831 sp->gen2 = fcport->login_gen;
833 mbx = &sp->u.iocb_cmd;
834 mbx->timeout = qla2x00_async_iocb_timeout;
835 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
837 mb = sp->u.iocb_cmd.u.mbx.out_mb;
838 mb[0] = MBC_PORT_NODE_NAME_LIST;
839 mb[1] = BIT_2 | BIT_3;
840 mb[2] = MSW(vha->gnl.ldma);
841 mb[3] = LSW(vha->gnl.ldma);
842 mb[6] = MSW(MSD(vha->gnl.ldma));
843 mb[7] = LSW(MSD(vha->gnl.ldma));
844 mb[8] = vha->gnl.size;
847 sp->done = qla24xx_async_gnl_sp_done;
849 rval = qla2x00_start_sp(sp);
850 if (rval != QLA_SUCCESS)
853 ql_dbg(ql_dbg_disc, vha, 0x20da,
854 "Async-%s - OUT WWPN %8phC hndl %x\n",
855 sp->name, fcport->port_name, sp->handle);
861 fcport->flags &= ~FCF_ASYNC_SENT;
866 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
868 struct qla_work_evt *e;
870 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
872 return QLA_FUNCTION_FAILED;
874 e->u.fcport.fcport = fcport;
875 fcport->flags |= FCF_ASYNC_ACTIVE;
876 return qla2x00_post_work(vha, e);
880 void qla24xx_async_gpdb_sp_done(void *s, int res)
883 struct scsi_qla_host *vha = sp->vha;
884 struct qla_hw_data *ha = vha->hw;
885 fc_port_t *fcport = sp->fcport;
886 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
889 ql_dbg(ql_dbg_disc, vha, 0x20db,
890 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
891 sp->name, res, fcport->port_name, mb[1], mb[2]);
893 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
895 memset(&ea, 0, sizeof(ea));
896 ea.event = FCME_GPDB_DONE;
900 qla2x00_fcport_event_handler(vha, &ea);
902 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
903 sp->u.iocb_cmd.u.mbx.in_dma);
908 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
910 struct qla_work_evt *e;
912 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
914 return QLA_FUNCTION_FAILED;
916 e->u.fcport.fcport = fcport;
918 return qla2x00_post_work(vha, e);
922 qla2x00_async_prli_sp_done(void *ptr, int res)
925 struct scsi_qla_host *vha = sp->vha;
926 struct srb_iocb *lio = &sp->u.iocb_cmd;
929 ql_dbg(ql_dbg_disc, vha, 0x2129,
930 "%s %8phC res %d \n", __func__,
931 sp->fcport->port_name, res);
933 sp->fcport->flags &= ~FCF_ASYNC_SENT;
935 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
936 memset(&ea, 0, sizeof(ea));
937 ea.event = FCME_PRLI_DONE;
938 ea.fcport = sp->fcport;
939 ea.data[0] = lio->u.logio.data[0];
940 ea.data[1] = lio->u.logio.data[1];
941 ea.iop[0] = lio->u.logio.iop[0];
942 ea.iop[1] = lio->u.logio.iop[1];
945 qla2x00_fcport_event_handler(vha, &ea);
952 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
955 struct srb_iocb *lio;
956 int rval = QLA_FUNCTION_FAILED;
958 if (!vha->flags.online)
961 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
962 fcport->fw_login_state == DSC_LS_PRLI_PEND)
965 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
969 fcport->flags |= FCF_ASYNC_SENT;
970 fcport->logout_completed = 0;
972 sp->type = SRB_PRLI_CMD;
975 lio = &sp->u.iocb_cmd;
976 lio->timeout = qla2x00_async_iocb_timeout;
977 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
979 sp->done = qla2x00_async_prli_sp_done;
980 lio->u.logio.flags = 0;
982 if (fcport->fc4f_nvme)
983 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
985 rval = qla2x00_start_sp(sp);
986 if (rval != QLA_SUCCESS) {
987 fcport->flags |= FCF_LOGIN_NEEDED;
988 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
992 ql_dbg(ql_dbg_disc, vha, 0x211b,
993 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d.\n",
994 fcport->port_name, sp->handle, fcport->loop_id,
995 fcport->d_id.b24, fcport->login_retry);
1001 fcport->flags &= ~FCF_ASYNC_SENT;
1005 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1007 struct qla_work_evt *e;
1009 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1011 return QLA_FUNCTION_FAILED;
1013 e->u.fcport.fcport = fcport;
1014 e->u.fcport.opt = opt;
1015 fcport->flags |= FCF_ASYNC_ACTIVE;
1016 return qla2x00_post_work(vha, e);
1019 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1022 struct srb_iocb *mbx;
1023 int rval = QLA_FUNCTION_FAILED;
1026 struct port_database_24xx *pd;
1027 struct qla_hw_data *ha = vha->hw;
1029 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1032 fcport->disc_state = DSC_GPDB;
1034 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1038 fcport->flags |= FCF_ASYNC_SENT;
1039 sp->type = SRB_MB_IOCB;
1041 sp->gen1 = fcport->rscn_gen;
1042 sp->gen2 = fcport->login_gen;
1044 mbx = &sp->u.iocb_cmd;
1045 mbx->timeout = qla2x00_async_iocb_timeout;
1046 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1048 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1050 ql_log(ql_log_warn, vha, 0xd043,
1051 "Failed to allocate port database structure.\n");
1055 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1056 mb[0] = MBC_GET_PORT_DATABASE;
1057 mb[1] = fcport->loop_id;
1058 mb[2] = MSW(pd_dma);
1059 mb[3] = LSW(pd_dma);
1060 mb[6] = MSW(MSD(pd_dma));
1061 mb[7] = LSW(MSD(pd_dma));
1062 mb[9] = vha->vp_idx;
1065 mbx->u.mbx.in = (void *)pd;
1066 mbx->u.mbx.in_dma = pd_dma;
1068 sp->done = qla24xx_async_gpdb_sp_done;
1070 rval = qla2x00_start_sp(sp);
1071 if (rval != QLA_SUCCESS)
1074 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1075 "Async-%s %8phC hndl %x opt %x\n",
1076 sp->name, fcport->port_name, sp->handle, opt);
1082 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1085 fcport->flags &= ~FCF_ASYNC_SENT;
1087 qla24xx_post_gpdb_work(vha, fcport, opt);
1092 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1094 unsigned long flags;
1096 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1097 ea->fcport->login_gen++;
1098 ea->fcport->deleted = 0;
1099 ea->fcport->logout_on_delete = 1;
1101 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1102 vha->fcport_count++;
1103 ea->fcport->login_succ = 1;
1105 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1106 "%s %d %8phC post upd_fcport fcp_cnt %d\n",
1107 __func__, __LINE__, ea->fcport->port_name,
1109 qla24xx_post_upd_fcport_work(vha, ea->fcport);
1110 } else if (ea->fcport->login_succ) {
1112 * We have an existing session. A late RSCN delivery
1113 * must have triggered the session to be re-validate.
1114 * Session is still valid.
1116 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1117 "%s %d %8phC session revalidate success\n",
1118 __func__, __LINE__, ea->fcport->port_name);
1119 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1121 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1125 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1127 fc_port_t *fcport = ea->fcport;
1128 struct port_database_24xx *pd;
1129 struct srb *sp = ea->sp;
1132 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1134 fcport->flags &= ~FCF_ASYNC_SENT;
1136 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1137 "%s %8phC DS %d LS %d rc %d\n", __func__, fcport->port_name,
1138 fcport->disc_state, pd->current_login_state, ea->rc);
1140 if (fcport->disc_state == DSC_DELETE_PEND)
1143 if (fcport->fc4f_nvme)
1144 ls = pd->current_login_state >> 4;
1146 ls = pd->current_login_state & 0xf;
1149 case PDS_PRLI_COMPLETE:
1150 __qla24xx_parse_gpdb(vha, fcport, pd);
1152 case PDS_PLOGI_PENDING:
1153 case PDS_PLOGI_COMPLETE:
1154 case PDS_PRLI_PENDING:
1155 case PDS_PRLI2_PENDING:
1156 /* Set discovery state back to GNL to Relogin attempt */
1157 if (qla_dual_mode_enabled(vha) ||
1158 qla_ini_mode_enabled(vha)) {
1159 fcport->disc_state = DSC_GNL;
1160 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1163 case PDS_LOGO_PENDING:
1164 case PDS_PORT_UNAVAILABLE:
1166 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1167 __func__, __LINE__, fcport->port_name);
1168 qlt_schedule_sess_for_deletion(fcport);
1171 __qla24xx_handle_gpdb_event(vha, ea);
1174 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1179 if (qla_tgt_mode_enabled(vha))
1182 if (qla_dual_mode_enabled(vha)) {
1183 if (N2N_TOPO(vha->hw)) {
1186 mywwn = wwn_to_u64(vha->port_name);
1187 wwn = wwn_to_u64(fcport->port_name);
1190 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1191 && time_after_eq(jiffies,
1192 fcport->plogi_nack_done_deadline))
1198 /* initiator mode */
1203 if (fcport->loop_id == FC_NO_LOOP_ID) {
1204 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1205 rc = qla2x00_find_new_loop_id(vha, fcport);
1207 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1208 "%s %d %8phC post del sess - out of loopid\n",
1209 __func__, __LINE__, fcport->port_name);
1210 fcport->scan_state = 0;
1211 qlt_schedule_sess_for_deletion(fcport);
1215 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1216 "%s %d %8phC post login\n",
1217 __func__, __LINE__, fcport->port_name);
1218 qla2x00_post_async_login_work(vha, fcport, NULL);
1222 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1227 ql_dbg(ql_dbg_disc, vha, 0x20d8,
1228 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d retry %d lid %d scan %d\n",
1229 __func__, fcport->port_name, fcport->disc_state,
1230 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1231 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1232 fcport->login_gen, fcport->login_retry,
1233 fcport->loop_id, fcport->scan_state);
1235 if (fcport->scan_state != QLA_FCPORT_FOUND)
1238 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1239 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1240 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1243 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1244 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1245 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1250 /* for pure Target Mode. Login will not be initiated */
1251 if (vha->host->active_mode == MODE_TARGET)
1254 if (fcport->flags & FCF_ASYNC_SENT) {
1255 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1260 switch (fcport->disc_state) {
1262 fcport->login_retry--;
1263 wwn = wwn_to_u64(fcport->node_name);
1265 ql_dbg(ql_dbg_disc, vha, 0xffff,
1266 "%s %d %8phC post GNNID\n",
1267 __func__, __LINE__, fcport->port_name);
1268 qla24xx_post_gnnid_work(vha, fcport);
1269 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1270 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1271 "%s %d %8phC post gnl\n",
1272 __func__, __LINE__, fcport->port_name);
1273 qla24xx_post_gnl_work(vha, fcport);
1275 fcport->login_retry--;
1276 qla_chk_n2n_b4_login(vha, fcport);
1281 if (fcport->login_pause) {
1282 fcport->last_rscn_gen = fcport->rscn_gen;
1283 fcport->last_login_gen = fcport->login_gen;
1284 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1288 qla_chk_n2n_b4_login(vha, fcport);
1291 case DSC_LOGIN_FAILED:
1292 fcport->login_retry--;
1293 ql_dbg(ql_dbg_disc, vha, 0x20d0,
1294 "%s %d %8phC post gidpn\n",
1295 __func__, __LINE__, fcport->port_name);
1296 if (N2N_TOPO(vha->hw))
1297 qla_chk_n2n_b4_login(vha, fcport);
1299 qla24xx_post_gidpn_work(vha, fcport);
1302 case DSC_LOGIN_COMPLETE:
1303 /* recheck login state */
1304 ql_dbg(ql_dbg_disc, vha, 0x20d1,
1305 "%s %d %8phC post adisc\n",
1306 __func__, __LINE__, fcport->port_name);
1307 fcport->login_retry--;
1308 data[0] = data[1] = 0;
1309 qla2x00_post_async_adisc_work(vha, fcport, data);
1312 case DSC_LOGIN_PEND:
1313 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1314 qla24xx_post_prli_work(vha, fcport);
1325 void qla24xx_handle_rscn_event(fc_port_t *fcport, struct event_arg *ea)
1329 ql_dbg(ql_dbg_disc, fcport->vha, 0x210c,
1330 "%s %8phC DS %d LS %d\n",
1331 __func__, fcport->port_name, fcport->disc_state,
1332 fcport->fw_login_state);
1334 if (fcport->flags & FCF_ASYNC_SENT)
1337 switch (fcport->disc_state) {
1339 case DSC_LOGIN_COMPLETE:
1340 qla24xx_post_gpnid_work(fcport->vha, &ea->id);
1347 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1348 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1350 struct qla_work_evt *e;
1351 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1353 return QLA_FUNCTION_FAILED;
1355 e->u.new_sess.id = *id;
1356 e->u.new_sess.pla = pla;
1357 e->u.new_sess.fc4_type = fc4_type;
1358 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1360 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1362 return qla2x00_post_work(vha, e);
1366 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1367 struct event_arg *ea)
1369 fc_port_t *fcport = ea->fcport;
1371 ql_dbg(ql_dbg_disc, vha, 0x2102,
1372 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1373 __func__, fcport->port_name, fcport->disc_state,
1374 fcport->fw_login_state, fcport->login_pause,
1375 fcport->deleted, fcport->conflict,
1376 fcport->last_rscn_gen, fcport->rscn_gen,
1377 fcport->last_login_gen, fcport->login_gen,
1380 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1381 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1384 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1385 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1386 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1391 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1392 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gidpn\n",
1393 __func__, __LINE__, fcport->port_name);
1395 qla24xx_post_gidpn_work(vha, fcport);
1399 qla24xx_fcport_handle_login(vha, fcport);
1402 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1405 uint32_t id = 0, mask, rid;
1406 unsigned long flags;
1409 switch (ea->event) {
1411 if (test_bit(UNLOADING, &vha->dpc_flags))
1414 qla24xx_handle_relogin_event(vha, ea);
1417 if (test_bit(UNLOADING, &vha->dpc_flags))
1419 switch (ea->id.b.rsvd_1) {
1420 case RSCN_PORT_ADDR:
1421 fcport = qla2x00_find_fcport_by_nportid
1424 fcport->rscn_rcvd = 1;
1426 spin_lock_irqsave(&vha->work_lock, flags);
1427 if (vha->scan.scan_flags == 0) {
1428 ql_dbg(ql_dbg_disc, vha, 0xffff,
1429 "%s: schedule\n", __func__);
1430 vha->scan.scan_flags |= SF_QUEUED;
1431 schedule_delayed_work(&vha->scan.scan_work, 5);
1433 spin_unlock_irqrestore(&vha->work_lock, flags);
1436 case RSCN_AREA_ADDR:
1438 if (ea->id.b.rsvd_1 == RSCN_AREA_ADDR) {
1440 ql_dbg(ql_dbg_async, vha, 0x5044,
1441 "RSCN: Area 0x%06x was affected\n",
1445 ql_dbg(ql_dbg_async, vha, 0x507a,
1446 "RSCN: Domain 0x%06x was affected\n",
1450 rid = ea->id.b24 & mask;
1451 list_for_each_entry_safe(f, tf, &vha->vp_fcports,
1453 id = f->d_id.b24 & mask;
1456 qla24xx_handle_rscn_event(f, ea);
1462 ql_log(ql_log_warn, vha, 0xd045,
1463 "RSCN: Fabric was affected. Addr format %d\n",
1465 qla2x00_mark_all_devices_lost(vha, 1);
1466 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
1467 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
1470 case FCME_GIDPN_DONE:
1471 qla24xx_handle_gidpn_event(vha, ea);
1474 qla24xx_handle_gnl_done_event(vha, ea);
1476 case FCME_GPSC_DONE:
1477 qla24xx_handle_gpsc_event(vha, ea);
1479 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1480 qla24xx_handle_plogi_done_event(vha, ea);
1482 case FCME_PRLI_DONE:
1483 qla24xx_handle_prli_done_event(vha, ea);
1485 case FCME_GPDB_DONE:
1486 qla24xx_handle_gpdb_event(vha, ea);
1488 case FCME_GPNID_DONE:
1489 qla24xx_handle_gpnid_event(vha, ea);
1491 case FCME_GFFID_DONE:
1492 qla24xx_handle_gffid_event(vha, ea);
1494 case FCME_ADISC_DONE:
1495 qla24xx_handle_adisc_event(vha, ea);
1497 case FCME_GNNID_DONE:
1498 qla24xx_handle_gnnid_event(vha, ea);
1500 case FCME_GFPNID_DONE:
1501 qla24xx_handle_gfpnid_event(vha, ea);
1510 qla2x00_tmf_iocb_timeout(void *data)
1513 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1515 tmf->u.tmf.comp_status = CS_TIMEOUT;
1516 complete(&tmf->u.tmf.comp);
1520 qla2x00_tmf_sp_done(void *ptr, int res)
1523 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1525 complete(&tmf->u.tmf.comp);
1529 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1532 struct scsi_qla_host *vha = fcport->vha;
1533 struct srb_iocb *tm_iocb;
1535 int rval = QLA_FUNCTION_FAILED;
1537 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1541 tm_iocb = &sp->u.iocb_cmd;
1542 sp->type = SRB_TM_CMD;
1545 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1546 init_completion(&tm_iocb->u.tmf.comp);
1547 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1549 tm_iocb->u.tmf.flags = flags;
1550 tm_iocb->u.tmf.lun = lun;
1551 tm_iocb->u.tmf.data = tag;
1552 sp->done = qla2x00_tmf_sp_done;
1554 rval = qla2x00_start_sp(sp);
1555 if (rval != QLA_SUCCESS)
1558 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1559 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1560 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1561 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1563 wait_for_completion(&tm_iocb->u.tmf.comp);
1565 rval = tm_iocb->u.tmf.comp_status == CS_COMPLETE ?
1566 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1568 if ((rval != QLA_SUCCESS) || tm_iocb->u.tmf.data) {
1569 ql_dbg(ql_dbg_taskm, vha, 0x8030,
1570 "TM IOCB failed (%x).\n", rval);
1573 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1574 flags = tm_iocb->u.tmf.flags;
1575 lun = (uint16_t)tm_iocb->u.tmf.lun;
1577 /* Issue Marker IOCB */
1578 qla2x00_marker(vha, vha->hw->req_q_map[0],
1579 vha->hw->rsp_q_map[0], sp->fcport->loop_id, lun,
1580 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1585 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1591 qla24xx_abort_iocb_timeout(void *data)
1594 struct srb_iocb *abt = &sp->u.iocb_cmd;
1596 abt->u.abt.comp_status = CS_TIMEOUT;
1597 complete(&abt->u.abt.comp);
1601 qla24xx_abort_sp_done(void *ptr, int res)
1604 struct srb_iocb *abt = &sp->u.iocb_cmd;
1606 if (del_timer(&sp->u.iocb_cmd.timer))
1607 complete(&abt->u.abt.comp);
1611 qla24xx_async_abort_cmd(srb_t *cmd_sp)
1613 scsi_qla_host_t *vha = cmd_sp->vha;
1614 fc_port_t *fcport = cmd_sp->fcport;
1615 struct srb_iocb *abt_iocb;
1617 int rval = QLA_FUNCTION_FAILED;
1619 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1623 abt_iocb = &sp->u.iocb_cmd;
1624 sp->type = SRB_ABT_CMD;
1627 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
1628 init_completion(&abt_iocb->u.abt.comp);
1629 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1631 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
1633 if (vha->flags.qpairs_available && cmd_sp->qpair)
1634 abt_iocb->u.abt.req_que_no =
1635 cpu_to_le16(cmd_sp->qpair->req->id);
1637 abt_iocb->u.abt.req_que_no = cpu_to_le16(vha->req->id);
1639 sp->done = qla24xx_abort_sp_done;
1641 rval = qla2x00_start_sp(sp);
1642 if (rval != QLA_SUCCESS)
1645 ql_dbg(ql_dbg_async, vha, 0x507c,
1646 "Abort command issued - hdl=%x, target_id=%x\n",
1647 cmd_sp->handle, fcport->tgt_id);
1649 wait_for_completion(&abt_iocb->u.abt.comp);
1651 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
1652 QLA_SUCCESS : QLA_FUNCTION_FAILED;
1661 qla24xx_async_abort_command(srb_t *sp)
1663 unsigned long flags = 0;
1666 fc_port_t *fcport = sp->fcport;
1667 struct scsi_qla_host *vha = fcport->vha;
1668 struct qla_hw_data *ha = vha->hw;
1669 struct req_que *req = vha->req;
1671 if (vha->flags.qpairs_available && sp->qpair)
1672 req = sp->qpair->req;
1674 spin_lock_irqsave(&ha->hardware_lock, flags);
1675 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1676 if (req->outstanding_cmds[handle] == sp)
1679 spin_unlock_irqrestore(&ha->hardware_lock, flags);
1680 if (handle == req->num_outstanding_cmds) {
1681 /* Command not found. */
1682 return QLA_FUNCTION_FAILED;
1684 if (sp->type == SRB_FXIOCB_DCMD)
1685 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1686 FXDISC_ABORT_IOCTL);
1688 return qla24xx_async_abort_cmd(sp);
1692 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1694 switch (ea->data[0]) {
1695 case MBS_COMMAND_COMPLETE:
1696 ql_dbg(ql_dbg_disc, vha, 0x2118,
1697 "%s %d %8phC post gpdb\n",
1698 __func__, __LINE__, ea->fcport->port_name);
1700 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1701 ea->fcport->logout_on_delete = 1;
1702 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1705 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1706 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1707 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1708 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1712 if (ea->fcport->n2n_flag) {
1713 ql_dbg(ql_dbg_disc, vha, 0x2118,
1714 "%s %d %8phC post fc4 prli\n",
1715 __func__, __LINE__, ea->fcport->port_name);
1716 ea->fcport->fc4f_nvme = 0;
1717 ea->fcport->n2n_flag = 0;
1718 qla24xx_post_prli_work(vha, ea->fcport);
1720 ql_dbg(ql_dbg_disc, vha, 0x2119,
1721 "%s %d %8phC unhandle event of %x\n",
1722 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1728 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1730 port_id_t cid; /* conflict Nport id */
1732 struct fc_port *conflict_fcport;
1733 unsigned long flags;
1734 struct fc_port *fcport = ea->fcport;
1736 ql_dbg(ql_dbg_disc, vha, 0xffff,
1737 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1738 __func__, fcport->port_name, fcport->disc_state,
1739 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1740 ea->sp->gen2, fcport->rscn_gen|ea->sp->gen1,
1741 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1743 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1744 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1745 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1746 "%s %d %8phC Remote is trying to login\n",
1747 __func__, __LINE__, fcport->port_name);
1751 if (fcport->disc_state == DSC_DELETE_PEND)
1754 if (ea->sp->gen2 != fcport->login_gen) {
1755 /* target side must have changed it. */
1756 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1757 "%s %8phC generation changed\n",
1758 __func__, fcport->port_name);
1759 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1761 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1762 ql_dbg(ql_dbg_disc, vha, 0x20d4, "%s %d %8phC post gidpn\n",
1763 __func__, __LINE__, fcport->port_name);
1764 qla24xx_post_gidpn_work(vha, fcport);
1768 switch (ea->data[0]) {
1769 case MBS_COMMAND_COMPLETE:
1771 * Driver must validate login state - If PRLI not complete,
1772 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1775 if (ea->fcport->fc4f_nvme) {
1776 ql_dbg(ql_dbg_disc, vha, 0x2117,
1777 "%s %d %8phC post prli\n",
1778 __func__, __LINE__, ea->fcport->port_name);
1779 qla24xx_post_prli_work(vha, ea->fcport);
1781 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1782 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1783 __func__, __LINE__, ea->fcport->port_name,
1784 ea->fcport->loop_id, ea->fcport->d_id.b24);
1786 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1787 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1788 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1789 ea->fcport->logout_on_delete = 1;
1790 ea->fcport->send_els_logo = 0;
1791 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
1792 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1794 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1797 case MBS_COMMAND_ERROR:
1798 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
1799 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
1801 ea->fcport->flags &= ~FCF_ASYNC_SENT;
1802 ea->fcport->disc_state = DSC_LOGIN_FAILED;
1803 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
1804 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1806 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
1808 case MBS_LOOP_ID_USED:
1809 /* data[1] = IO PARAM 1 = nport ID */
1810 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
1811 cid.b.area = (ea->iop[1] >> 8) & 0xff;
1812 cid.b.al_pa = ea->iop[1] & 0xff;
1815 ql_dbg(ql_dbg_disc, vha, 0x20ec,
1816 "%s %d %8phC LoopID 0x%x in use post gnl\n",
1817 __func__, __LINE__, ea->fcport->port_name,
1818 ea->fcport->loop_id);
1820 if (IS_SW_RESV_ADDR(cid)) {
1821 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1822 ea->fcport->loop_id = FC_NO_LOOP_ID;
1824 qla2x00_clear_loop_id(ea->fcport);
1826 qla24xx_post_gnl_work(vha, ea->fcport);
1828 case MBS_PORT_ID_USED:
1829 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1830 "%s %d %8phC NPortId %02x%02x%02x inuse post gidpn\n",
1831 __func__, __LINE__, ea->fcport->port_name,
1832 ea->fcport->d_id.b.domain, ea->fcport->d_id.b.area,
1833 ea->fcport->d_id.b.al_pa);
1835 lid = ea->iop[1] & 0xffff;
1836 qlt_find_sess_invalidate_other(vha,
1837 wwn_to_u64(ea->fcport->port_name),
1838 ea->fcport->d_id, lid, &conflict_fcport);
1840 if (conflict_fcport) {
1842 * Another fcport share the same loop_id/nport id.
1843 * Conflict fcport needs to finish cleanup before this
1844 * fcport can proceed to login.
1846 conflict_fcport->conflict = ea->fcport;
1847 ea->fcport->login_pause = 1;
1849 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1850 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
1851 __func__, __LINE__, ea->fcport->port_name,
1852 ea->fcport->d_id.b24, lid);
1853 qla2x00_clear_loop_id(ea->fcport);
1854 qla24xx_post_gidpn_work(vha, ea->fcport);
1856 ql_dbg(ql_dbg_disc, vha, 0x20ed,
1857 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
1858 __func__, __LINE__, ea->fcport->port_name,
1859 ea->fcport->d_id.b24, lid);
1861 qla2x00_clear_loop_id(ea->fcport);
1862 set_bit(lid, vha->hw->loop_id_map);
1863 ea->fcport->loop_id = lid;
1864 ea->fcport->keep_nport_handle = 0;
1865 qlt_schedule_sess_for_deletion(ea->fcport);
1873 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1876 qlt_logo_completion_handler(fcport, data[0]);
1877 fcport->login_gen++;
1878 fcport->flags &= ~FCF_ASYNC_ACTIVE;
1883 qla2x00_async_adisc_done(struct scsi_qla_host *vha, fc_port_t *fcport,
1886 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1887 if (data[0] == MBS_COMMAND_COMPLETE) {
1888 qla2x00_update_fcport(vha, fcport);
1894 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
1895 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1897 qla2x00_mark_device_lost(vha, fcport, 1, 0);
1902 /****************************************************************************/
1903 /* QLogic ISP2x00 Hardware Support Functions. */
1904 /****************************************************************************/
1907 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
1909 int rval = QLA_SUCCESS;
1910 struct qla_hw_data *ha = vha->hw;
1911 uint32_t idc_major_ver, idc_minor_ver;
1914 qla83xx_idc_lock(vha, 0);
1916 /* SV: TODO: Assign initialization timeout from
1917 * flash-info / other param
1919 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
1920 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
1922 /* Set our fcoe function presence */
1923 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
1924 ql_dbg(ql_dbg_p3p, vha, 0xb077,
1925 "Error while setting DRV-Presence.\n");
1926 rval = QLA_FUNCTION_FAILED;
1930 /* Decide the reset ownership */
1931 qla83xx_reset_ownership(vha);
1934 * On first protocol driver load:
1935 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
1937 * Others: Check compatibility with current IDC Major version.
1939 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
1940 if (ha->flags.nic_core_reset_owner) {
1941 /* Set IDC Major version */
1942 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
1943 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
1945 /* Clearing IDC-Lock-Recovery register */
1946 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
1947 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
1949 * Clear further IDC participation if we are not compatible with
1950 * the current IDC Major Version.
1952 ql_log(ql_log_warn, vha, 0xb07d,
1953 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
1954 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
1955 __qla83xx_clear_drv_presence(vha);
1956 rval = QLA_FUNCTION_FAILED;
1959 /* Each function sets its supported Minor version. */
1960 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
1961 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
1962 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
1964 if (ha->flags.nic_core_reset_owner) {
1965 memset(config, 0, sizeof(config));
1966 if (!qla81xx_get_port_config(vha, config))
1967 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
1971 rval = qla83xx_idc_state_handler(vha);
1974 qla83xx_idc_unlock(vha, 0);
1980 * qla2x00_initialize_adapter
1984 * ha = adapter block pointer.
1990 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
1993 struct qla_hw_data *ha = vha->hw;
1994 struct req_que *req = ha->req_q_map[0];
1996 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
1997 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
1999 /* Clear adapter flags. */
2000 vha->flags.online = 0;
2001 ha->flags.chip_reset_done = 0;
2002 vha->flags.reset_active = 0;
2003 ha->flags.pci_channel_io_perm_failure = 0;
2004 ha->flags.eeh_busy = 0;
2005 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2006 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2007 atomic_set(&vha->loop_state, LOOP_DOWN);
2008 vha->device_flags = DFLG_NO_CABLE;
2010 vha->flags.management_server_logged_in = 0;
2011 vha->marker_needed = 0;
2012 ha->isp_abort_cnt = 0;
2013 ha->beacon_blink_led = 0;
2015 set_bit(0, ha->req_qid_map);
2016 set_bit(0, ha->rsp_qid_map);
2018 ql_dbg(ql_dbg_init, vha, 0x0040,
2019 "Configuring PCI space...\n");
2020 rval = ha->isp_ops->pci_config(vha);
2022 ql_log(ql_log_warn, vha, 0x0044,
2023 "Unable to configure PCI space.\n");
2027 ha->isp_ops->reset_chip(vha);
2029 rval = qla2xxx_get_flash_info(vha);
2031 ql_log(ql_log_fatal, vha, 0x004f,
2032 "Unable to validate FLASH data.\n");
2036 if (IS_QLA8044(ha)) {
2037 qla8044_read_reset_template(vha);
2039 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2040 * If DONRESET_BIT0 is set, drivers should not set dev_state
2041 * to NEED_RESET. But if NEED_RESET is set, drivers should
2042 * should honor the reset. */
2043 if (ql2xdontresethba == 1)
2044 qla8044_set_idc_dontreset(vha);
2047 ha->isp_ops->get_flash_version(vha, req->ring);
2048 ql_dbg(ql_dbg_init, vha, 0x0061,
2049 "Configure NVRAM parameters...\n");
2051 ha->isp_ops->nvram_config(vha);
2053 if (ha->flags.disable_serdes) {
2054 /* Mask HBA via NVRAM settings? */
2055 ql_log(ql_log_info, vha, 0x0077,
2056 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2057 return QLA_FUNCTION_FAILED;
2060 ql_dbg(ql_dbg_init, vha, 0x0078,
2061 "Verifying loaded RISC code...\n");
2063 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2064 rval = ha->isp_ops->chip_diag(vha);
2067 rval = qla2x00_setup_chip(vha);
2072 if (IS_QLA84XX(ha)) {
2073 ha->cs84xx = qla84xx_get_chip(vha);
2075 ql_log(ql_log_warn, vha, 0x00d0,
2076 "Unable to configure ISP84XX.\n");
2077 return QLA_FUNCTION_FAILED;
2081 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2082 rval = qla2x00_init_rings(vha);
2084 ha->flags.chip_reset_done = 1;
2086 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2087 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2088 rval = qla84xx_init_chip(vha);
2089 if (rval != QLA_SUCCESS) {
2090 ql_log(ql_log_warn, vha, 0x00d4,
2091 "Unable to initialize ISP84XX.\n");
2092 qla84xx_put_chip(vha);
2096 /* Load the NIC Core f/w if we are the first protocol driver. */
2097 if (IS_QLA8031(ha)) {
2098 rval = qla83xx_nic_core_fw_load(vha);
2100 ql_log(ql_log_warn, vha, 0x0124,
2101 "Error in initializing NIC Core f/w.\n");
2104 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2105 qla24xx_read_fcp_prio_cfg(vha);
2107 if (IS_P3P_TYPE(ha))
2108 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2110 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2116 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2119 * Returns 0 on success.
2122 qla2100_pci_config(scsi_qla_host_t *vha)
2125 unsigned long flags;
2126 struct qla_hw_data *ha = vha->hw;
2127 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2129 pci_set_master(ha->pdev);
2130 pci_try_set_mwi(ha->pdev);
2132 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2133 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2134 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2136 pci_disable_rom(ha->pdev);
2138 /* Get PCI bus information. */
2139 spin_lock_irqsave(&ha->hardware_lock, flags);
2140 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2141 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2147 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2150 * Returns 0 on success.
2153 qla2300_pci_config(scsi_qla_host_t *vha)
2156 unsigned long flags = 0;
2158 struct qla_hw_data *ha = vha->hw;
2159 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2161 pci_set_master(ha->pdev);
2162 pci_try_set_mwi(ha->pdev);
2164 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2165 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2167 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2168 w &= ~PCI_COMMAND_INTX_DISABLE;
2169 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2172 * If this is a 2300 card and not 2312, reset the
2173 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2174 * the 2310 also reports itself as a 2300 so we need to get the
2175 * fb revision level -- a 6 indicates it really is a 2300 and
2178 if (IS_QLA2300(ha)) {
2179 spin_lock_irqsave(&ha->hardware_lock, flags);
2182 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2183 for (cnt = 0; cnt < 30000; cnt++) {
2184 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2190 /* Select FPM registers. */
2191 WRT_REG_WORD(®->ctrl_status, 0x20);
2192 RD_REG_WORD(®->ctrl_status);
2194 /* Get the fb rev level */
2195 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2197 if (ha->fb_rev == FPM_2300)
2198 pci_clear_mwi(ha->pdev);
2200 /* Deselect FPM registers. */
2201 WRT_REG_WORD(®->ctrl_status, 0x0);
2202 RD_REG_WORD(®->ctrl_status);
2204 /* Release RISC module. */
2205 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2206 for (cnt = 0; cnt < 30000; cnt++) {
2207 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2213 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2216 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2218 pci_disable_rom(ha->pdev);
2220 /* Get PCI bus information. */
2221 spin_lock_irqsave(&ha->hardware_lock, flags);
2222 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2223 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2229 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2232 * Returns 0 on success.
2235 qla24xx_pci_config(scsi_qla_host_t *vha)
2238 unsigned long flags = 0;
2239 struct qla_hw_data *ha = vha->hw;
2240 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2242 pci_set_master(ha->pdev);
2243 pci_try_set_mwi(ha->pdev);
2245 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2246 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2247 w &= ~PCI_COMMAND_INTX_DISABLE;
2248 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2250 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2252 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2253 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2254 pcix_set_mmrbc(ha->pdev, 2048);
2256 /* PCIe -- adjust Maximum Read Request Size (2048). */
2257 if (pci_is_pcie(ha->pdev))
2258 pcie_set_readrq(ha->pdev, 4096);
2260 pci_disable_rom(ha->pdev);
2262 ha->chip_revision = ha->pdev->revision;
2264 /* Get PCI bus information. */
2265 spin_lock_irqsave(&ha->hardware_lock, flags);
2266 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2267 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2273 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2276 * Returns 0 on success.
2279 qla25xx_pci_config(scsi_qla_host_t *vha)
2282 struct qla_hw_data *ha = vha->hw;
2284 pci_set_master(ha->pdev);
2285 pci_try_set_mwi(ha->pdev);
2287 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2288 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2289 w &= ~PCI_COMMAND_INTX_DISABLE;
2290 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2292 /* PCIe -- adjust Maximum Read Request Size (2048). */
2293 if (pci_is_pcie(ha->pdev))
2294 pcie_set_readrq(ha->pdev, 4096);
2296 pci_disable_rom(ha->pdev);
2298 ha->chip_revision = ha->pdev->revision;
2304 * qla2x00_isp_firmware() - Choose firmware image.
2307 * Returns 0 on success.
2310 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2313 uint16_t loop_id, topo, sw_cap;
2314 uint8_t domain, area, al_pa;
2315 struct qla_hw_data *ha = vha->hw;
2317 /* Assume loading risc code */
2318 rval = QLA_FUNCTION_FAILED;
2320 if (ha->flags.disable_risc_code_load) {
2321 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2323 /* Verify checksum of loaded RISC code. */
2324 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2325 if (rval == QLA_SUCCESS) {
2326 /* And, verify we are not in ROM code. */
2327 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2328 &area, &domain, &topo, &sw_cap);
2333 ql_dbg(ql_dbg_init, vha, 0x007a,
2334 "**** Load RISC code ****.\n");
2340 * qla2x00_reset_chip() - Reset ISP chip.
2343 * Returns 0 on success.
2346 qla2x00_reset_chip(scsi_qla_host_t *vha)
2348 unsigned long flags = 0;
2349 struct qla_hw_data *ha = vha->hw;
2350 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2354 if (unlikely(pci_channel_offline(ha->pdev)))
2357 ha->isp_ops->disable_intrs(ha);
2359 spin_lock_irqsave(&ha->hardware_lock, flags);
2361 /* Turn off master enable */
2363 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2364 cmd &= ~PCI_COMMAND_MASTER;
2365 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2367 if (!IS_QLA2100(ha)) {
2369 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2370 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2371 for (cnt = 0; cnt < 30000; cnt++) {
2372 if ((RD_REG_WORD(®->hccr) &
2373 HCCR_RISC_PAUSE) != 0)
2378 RD_REG_WORD(®->hccr); /* PCI Posting. */
2382 /* Select FPM registers. */
2383 WRT_REG_WORD(®->ctrl_status, 0x20);
2384 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2386 /* FPM Soft Reset. */
2387 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2388 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2390 /* Toggle Fpm Reset. */
2391 if (!IS_QLA2200(ha)) {
2392 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2393 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2396 /* Select frame buffer registers. */
2397 WRT_REG_WORD(®->ctrl_status, 0x10);
2398 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2400 /* Reset frame buffer FIFOs. */
2401 if (IS_QLA2200(ha)) {
2402 WRT_FB_CMD_REG(ha, reg, 0xa000);
2403 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2405 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2407 /* Read back fb_cmd until zero or 3 seconds max */
2408 for (cnt = 0; cnt < 3000; cnt++) {
2409 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2415 /* Select RISC module registers. */
2416 WRT_REG_WORD(®->ctrl_status, 0);
2417 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2419 /* Reset RISC processor. */
2420 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2421 RD_REG_WORD(®->hccr); /* PCI Posting. */
2423 /* Release RISC processor. */
2424 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2425 RD_REG_WORD(®->hccr); /* PCI Posting. */
2428 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2429 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2431 /* Reset ISP chip. */
2432 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2434 /* Wait for RISC to recover from reset. */
2435 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2437 * It is necessary to for a delay here since the card doesn't
2438 * respond to PCI reads during a reset. On some architectures
2439 * this will result in an MCA.
2442 for (cnt = 30000; cnt; cnt--) {
2443 if ((RD_REG_WORD(®->ctrl_status) &
2444 CSR_ISP_SOFT_RESET) == 0)
2451 /* Reset RISC processor. */
2452 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2454 WRT_REG_WORD(®->semaphore, 0);
2456 /* Release RISC processor. */
2457 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2458 RD_REG_WORD(®->hccr); /* PCI Posting. */
2460 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2461 for (cnt = 0; cnt < 30000; cnt++) {
2462 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2470 /* Turn on master enable */
2471 cmd |= PCI_COMMAND_MASTER;
2472 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2474 /* Disable RISC pause on FPM parity error. */
2475 if (!IS_QLA2100(ha)) {
2476 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2477 RD_REG_WORD(®->hccr); /* PCI Posting. */
2480 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2484 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2487 * Returns 0 on success.
2490 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2492 uint16_t mb[4] = {0x1010, 0, 1, 0};
2494 if (!IS_QLA81XX(vha->hw))
2497 return qla81xx_write_mpi_register(vha, mb);
2501 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2504 * Returns 0 on success.
2507 qla24xx_reset_risc(scsi_qla_host_t *vha)
2509 unsigned long flags = 0;
2510 struct qla_hw_data *ha = vha->hw;
2511 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2514 static int abts_cnt; /* ISP abort retry counts */
2515 int rval = QLA_SUCCESS;
2517 spin_lock_irqsave(&ha->hardware_lock, flags);
2520 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2521 for (cnt = 0; cnt < 30000; cnt++) {
2522 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2528 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2529 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2531 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2532 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2533 RD_REG_DWORD(®->hccr),
2534 RD_REG_DWORD(®->ctrl_status),
2535 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2537 WRT_REG_DWORD(®->ctrl_status,
2538 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2539 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2543 /* Wait for firmware to complete NVRAM accesses. */
2544 RD_REG_WORD(®->mailbox0);
2545 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2546 rval == QLA_SUCCESS; cnt--) {
2551 rval = QLA_FUNCTION_TIMEOUT;
2554 if (rval == QLA_SUCCESS)
2555 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2557 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2558 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2559 RD_REG_DWORD(®->hccr),
2560 RD_REG_DWORD(®->mailbox0));
2562 /* Wait for soft-reset to complete. */
2563 RD_REG_DWORD(®->ctrl_status);
2564 for (cnt = 0; cnt < 60; cnt++) {
2566 if ((RD_REG_DWORD(®->ctrl_status) &
2567 CSRX_ISP_SOFT_RESET) == 0)
2572 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2573 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2575 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2576 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2577 RD_REG_DWORD(®->hccr),
2578 RD_REG_DWORD(®->ctrl_status));
2580 /* If required, do an MPI FW reset now */
2581 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2582 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2583 if (++abts_cnt < 5) {
2584 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2585 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2588 * We exhausted the ISP abort retries. We have to
2589 * set the board offline.
2592 vha->flags.online = 0;
2597 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2598 RD_REG_DWORD(®->hccr);
2600 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2601 RD_REG_DWORD(®->hccr);
2603 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2604 RD_REG_DWORD(®->hccr);
2606 RD_REG_WORD(®->mailbox0);
2607 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2608 rval == QLA_SUCCESS; cnt--) {
2613 rval = QLA_FUNCTION_TIMEOUT;
2615 if (rval == QLA_SUCCESS)
2616 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2618 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2619 "Host Risc 0x%x, mailbox0 0x%x\n",
2620 RD_REG_DWORD(®->hccr),
2621 RD_REG_WORD(®->mailbox0));
2623 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2625 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2626 "Driver in %s mode\n",
2627 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2629 if (IS_NOPOLLING_TYPE(ha))
2630 ha->isp_ops->enable_intrs(ha);
2636 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2638 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2640 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2641 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2646 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2648 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2650 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2651 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2655 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2658 uint delta_msec = 100;
2659 uint elapsed_msec = 0;
2663 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2664 vha->hw->pdev->subsystem_device != 0x0240)
2667 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2671 timeout_msec = TIMEOUT_SEMAPHORE;
2672 n = timeout_msec / delta_msec;
2674 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2675 qla25xx_read_risc_sema_reg(vha, &wd32);
2676 if (wd32 & RISC_SEMAPHORE)
2679 elapsed_msec += delta_msec;
2680 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2684 if (!(wd32 & RISC_SEMAPHORE))
2687 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2690 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2691 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2692 n = timeout_msec / delta_msec;
2694 qla25xx_read_risc_sema_reg(vha, &wd32);
2695 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2698 elapsed_msec += delta_msec;
2699 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2703 if (wd32 & RISC_SEMAPHORE_FORCE)
2704 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2709 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2716 * qla24xx_reset_chip() - Reset ISP24xx chip.
2719 * Returns 0 on success.
2722 qla24xx_reset_chip(scsi_qla_host_t *vha)
2724 struct qla_hw_data *ha = vha->hw;
2726 if (pci_channel_offline(ha->pdev) &&
2727 ha->flags.pci_channel_io_perm_failure) {
2731 ha->isp_ops->disable_intrs(ha);
2733 qla25xx_manipulate_risc_semaphore(vha);
2735 /* Perform RISC reset. */
2736 qla24xx_reset_risc(vha);
2740 * qla2x00_chip_diag() - Test chip for proper operation.
2743 * Returns 0 on success.
2746 qla2x00_chip_diag(scsi_qla_host_t *vha)
2749 struct qla_hw_data *ha = vha->hw;
2750 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2751 unsigned long flags = 0;
2755 struct req_que *req = ha->req_q_map[0];
2757 /* Assume a failed state */
2758 rval = QLA_FUNCTION_FAILED;
2760 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2761 ®->flash_address);
2763 spin_lock_irqsave(&ha->hardware_lock, flags);
2765 /* Reset ISP chip. */
2766 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2769 * We need to have a delay here since the card will not respond while
2770 * in reset causing an MCA on some architectures.
2773 data = qla2x00_debounce_register(®->ctrl_status);
2774 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2776 data = RD_REG_WORD(®->ctrl_status);
2781 goto chip_diag_failed;
2783 ql_dbg(ql_dbg_init, vha, 0x007c,
2784 "Reset register cleared by chip reset.\n");
2786 /* Reset RISC processor. */
2787 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2788 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2790 /* Workaround for QLA2312 PCI parity error */
2791 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2792 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2793 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2795 data = RD_MAILBOX_REG(ha, reg, 0);
2802 goto chip_diag_failed;
2804 /* Check product ID of chip */
2805 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
2807 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
2808 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
2809 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
2810 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
2811 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
2812 mb[3] != PROD_ID_3) {
2813 ql_log(ql_log_warn, vha, 0x0062,
2814 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
2815 mb[1], mb[2], mb[3]);
2817 goto chip_diag_failed;
2819 ha->product_id[0] = mb[1];
2820 ha->product_id[1] = mb[2];
2821 ha->product_id[2] = mb[3];
2822 ha->product_id[3] = mb[4];
2824 /* Adjust fw RISC transfer size */
2825 if (req->length > 1024)
2826 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
2828 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
2831 if (IS_QLA2200(ha) &&
2832 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
2833 /* Limit firmware transfer size with a 2200A */
2834 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
2836 ha->device_type |= DT_ISP2200A;
2837 ha->fw_transfer_size = 128;
2840 /* Wrap Incoming Mailboxes Test. */
2841 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2843 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
2844 rval = qla2x00_mbx_reg_test(vha);
2846 ql_log(ql_log_warn, vha, 0x0080,
2847 "Failed mailbox send register test.\n");
2849 /* Flag a successful rval */
2851 spin_lock_irqsave(&ha->hardware_lock, flags);
2855 ql_log(ql_log_info, vha, 0x0081,
2856 "Chip diagnostics **** FAILED ****.\n");
2858 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2864 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
2867 * Returns 0 on success.
2870 qla24xx_chip_diag(scsi_qla_host_t *vha)
2873 struct qla_hw_data *ha = vha->hw;
2874 struct req_que *req = ha->req_q_map[0];
2876 if (IS_P3P_TYPE(ha))
2879 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
2881 rval = qla2x00_mbx_reg_test(vha);
2883 ql_log(ql_log_warn, vha, 0x0082,
2884 "Failed mailbox send register test.\n");
2886 /* Flag a successful rval */
2894 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
2899 struct qla_hw_data *ha = vha->hw;
2902 ql_dbg(ql_dbg_init, vha, 0x00bd,
2903 "%s: Offload Mem is already allocated.\n",
2908 if (IS_FWI2_CAPABLE(ha)) {
2909 /* Allocate memory for Fibre Channel Event Buffer. */
2910 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
2915 dma_free_coherent(&ha->pdev->dev,
2916 FCE_SIZE, ha->fce, ha->fce_dma);
2918 /* Allocate memory for Fibre Channel Event Buffer. */
2919 tc = dma_zalloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
2922 ql_log(ql_log_warn, vha, 0x00be,
2923 "Unable to allocate (%d KB) for FCE.\n",
2928 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
2929 ha->fce_mb, &ha->fce_bufs);
2931 ql_log(ql_log_warn, vha, 0x00bf,
2932 "Unable to initialize FCE (%d).\n", rval);
2933 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
2935 ha->flags.fce_enabled = 0;
2938 ql_dbg(ql_dbg_init, vha, 0x00c0,
2939 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
2941 ha->flags.fce_enabled = 1;
2942 ha->fce_dma = tc_dma;
2947 dma_free_coherent(&ha->pdev->dev,
2948 EFT_SIZE, ha->eft, ha->eft_dma);
2950 /* Allocate memory for Extended Trace Buffer. */
2951 tc = dma_zalloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
2954 ql_log(ql_log_warn, vha, 0x00c1,
2955 "Unable to allocate (%d KB) for EFT.\n",
2960 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
2962 ql_log(ql_log_warn, vha, 0x00c2,
2963 "Unable to initialize EFT (%d).\n", rval);
2964 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
2968 ql_dbg(ql_dbg_init, vha, 0x00c3,
2969 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
2971 ha->eft_dma = tc_dma;
2980 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
2982 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
2983 eft_size, fce_size, mq_size;
2984 struct qla_hw_data *ha = vha->hw;
2985 struct req_que *req = ha->req_q_map[0];
2986 struct rsp_que *rsp = ha->rsp_q_map[0];
2987 struct qla2xxx_fw_dump *fw_dump;
2989 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
2990 req_q_size = rsp_q_size = 0;
2992 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
2993 fixed_size = sizeof(struct qla2100_fw_dump);
2994 } else if (IS_QLA23XX(ha)) {
2995 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
2996 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
2998 } else if (IS_FWI2_CAPABLE(ha)) {
2999 if (IS_QLA83XX(ha) || IS_QLA27XX(ha))
3000 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3001 else if (IS_QLA81XX(ha))
3002 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3003 else if (IS_QLA25XX(ha))
3004 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3006 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3008 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3011 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha))
3012 mq_size = sizeof(struct qla2xxx_mq_chain);
3014 * Allocate maximum buffer size for all queues.
3015 * Resizing must be done at end-of-dump processing.
3017 mq_size += ha->max_req_queues *
3018 (req->length * sizeof(request_t));
3019 mq_size += ha->max_rsp_queues *
3020 (rsp->length * sizeof(response_t));
3022 if (ha->tgt.atio_ring)
3023 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3024 /* Allocate memory for Fibre Channel Event Buffer. */
3025 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3029 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3031 ql_dbg(ql_dbg_init, vha, 0x00c3,
3032 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3033 eft_size = EFT_SIZE;
3036 if (IS_QLA27XX(ha)) {
3037 if (!ha->fw_dump_template) {
3038 ql_log(ql_log_warn, vha, 0x00ba,
3039 "Failed missing fwdump template\n");
3042 dump_size = qla27xx_fwdt_calculate_dump_size(vha);
3043 ql_dbg(ql_dbg_init, vha, 0x00fa,
3044 "-> allocating fwdump (%x bytes)...\n", dump_size);
3048 req_q_size = req->length * sizeof(request_t);
3049 rsp_q_size = rsp->length * sizeof(response_t);
3050 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3051 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3052 ha->chain_offset = dump_size;
3053 dump_size += mq_size + fce_size;
3055 if (ha->exchoffld_buf)
3056 dump_size += sizeof(struct qla2xxx_offld_chain) +
3058 if (ha->exlogin_buf)
3059 dump_size += sizeof(struct qla2xxx_offld_chain) +
3063 if (!ha->fw_dump_len || dump_size != ha->fw_dump_len) {
3064 fw_dump = vmalloc(dump_size);
3066 ql_log(ql_log_warn, vha, 0x00c4,
3067 "Unable to allocate (%d KB) for firmware dump.\n",
3072 ha->fw_dump = fw_dump;
3074 ha->fw_dump_len = dump_size;
3075 ql_dbg(ql_dbg_init, vha, 0x00c5,
3076 "Allocated (%d KB) for firmware dump.\n",
3082 ha->fw_dump->signature[0] = 'Q';
3083 ha->fw_dump->signature[1] = 'L';
3084 ha->fw_dump->signature[2] = 'G';
3085 ha->fw_dump->signature[3] = 'C';
3086 ha->fw_dump->version = htonl(1);
3088 ha->fw_dump->fixed_size = htonl(fixed_size);
3089 ha->fw_dump->mem_size = htonl(mem_size);
3090 ha->fw_dump->req_q_size = htonl(req_q_size);
3091 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3093 ha->fw_dump->eft_size = htonl(eft_size);
3094 ha->fw_dump->eft_addr_l = htonl(LSD(ha->eft_dma));
3095 ha->fw_dump->eft_addr_h = htonl(MSD(ha->eft_dma));
3097 ha->fw_dump->header_size =
3098 htonl(offsetof(struct qla2xxx_fw_dump, isp));
3104 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3106 #define MPS_MASK 0xe0
3111 if (!IS_QLA81XX(vha->hw))
3114 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3115 if (rval != QLA_SUCCESS) {
3116 ql_log(ql_log_warn, vha, 0x0105,
3117 "Unable to acquire semaphore.\n");
3121 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3122 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3123 if (rval != QLA_SUCCESS) {
3124 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3129 if (dc == (dw & MPS_MASK))
3134 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3135 if (rval != QLA_SUCCESS) {
3136 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3140 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3141 if (rval != QLA_SUCCESS) {
3142 ql_log(ql_log_warn, vha, 0x006d,
3143 "Unable to release semaphore.\n");
3151 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3153 /* Don't try to reallocate the array */
3154 if (req->outstanding_cmds)
3157 if (!IS_FWI2_CAPABLE(ha))
3158 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3160 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3161 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3163 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3166 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3170 if (!req->outstanding_cmds) {
3172 * Try to allocate a minimal size just so we can get through
3175 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3176 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3180 if (!req->outstanding_cmds) {
3181 ql_log(ql_log_fatal, NULL, 0x0126,
3182 "Failed to allocate memory for "
3183 "outstanding_cmds for req_que %p.\n", req);
3184 req->num_outstanding_cmds = 0;
3185 return QLA_FUNCTION_FAILED;
3192 #define PRINT_FIELD(_field, _flag, _str) { \
3193 if (a0->_field & _flag) {\
3199 len = snprintf(ptr, leftover, "%s", _str); \
3206 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3209 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3210 u8 str[STR_LEN], *ptr, p;
3213 memset(str, 0, STR_LEN);
3214 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3215 ql_dbg(ql_dbg_init, vha, 0x015a,
3216 "SFP MFG Name: %s\n", str);
3218 memset(str, 0, STR_LEN);
3219 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3220 ql_dbg(ql_dbg_init, vha, 0x015c,
3221 "SFP Part Name: %s\n", str);
3224 memset(str, 0, STR_LEN);
3228 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3229 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3230 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3231 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3232 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3233 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3234 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3235 ql_dbg(ql_dbg_init, vha, 0x0160,
3236 "SFP Media: %s\n", str);
3239 memset(str, 0, STR_LEN);
3243 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3244 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3245 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3246 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3247 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3248 ql_dbg(ql_dbg_init, vha, 0x0196,
3249 "SFP Link Length: %s\n", str);
3251 memset(str, 0, STR_LEN);
3255 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3256 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3257 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3258 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3259 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3260 ql_dbg(ql_dbg_init, vha, 0x016e,
3261 "SFP FC Link Tech: %s\n", str);
3264 ql_dbg(ql_dbg_init, vha, 0x016f,
3265 "SFP Distant: %d km\n", a0->length_km);
3266 if (a0->length_100m)
3267 ql_dbg(ql_dbg_init, vha, 0x0170,
3268 "SFP Distant: %d m\n", a0->length_100m*100);
3269 if (a0->length_50um_10m)
3270 ql_dbg(ql_dbg_init, vha, 0x0189,
3271 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3272 if (a0->length_62um_10m)
3273 ql_dbg(ql_dbg_init, vha, 0x018a,
3274 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3275 if (a0->length_om4_10m)
3276 ql_dbg(ql_dbg_init, vha, 0x0194,
3277 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3278 if (a0->length_om3_10m)
3279 ql_dbg(ql_dbg_init, vha, 0x0195,
3280 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3286 * QLA_SUCCESS: no action
3287 * QLA_INTERFACE_ERROR: SFP is not there.
3288 * QLA_FUNCTION_FAILED: detected New SFP
3291 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3293 int rc = QLA_SUCCESS;
3294 struct sff_8247_a0 *a;
3295 struct qla_hw_data *ha = vha->hw;
3297 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3300 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3304 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3305 qla2xxx_print_sfp_info(vha);
3307 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3309 ha->flags.detected_lr_sfp = 1;
3311 if (a->length_km > 5 || a->length_100m > 50)
3312 ha->long_range_distance = LR_DISTANCE_10K;
3314 ha->long_range_distance = LR_DISTANCE_5K;
3316 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3317 ql_dbg(ql_dbg_async, vha, 0x507b,
3318 "Detected Long Range SFP.\n");
3321 ha->flags.detected_lr_sfp = 0;
3322 if (ha->flags.using_lr_setting)
3323 ql_dbg(ql_dbg_async, vha, 0x5084,
3324 "Detected Short Range SFP.\n");
3327 if (!vha->flags.init_done)
3334 * qla2x00_setup_chip() - Load and start RISC firmware.
3337 * Returns 0 on success.
3340 qla2x00_setup_chip(scsi_qla_host_t *vha)
3343 uint32_t srisc_address = 0;
3344 struct qla_hw_data *ha = vha->hw;
3345 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3346 unsigned long flags;
3347 uint16_t fw_major_version;
3349 if (IS_P3P_TYPE(ha)) {
3350 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3351 if (rval == QLA_SUCCESS) {
3352 qla2x00_stop_firmware(vha);
3353 goto enable_82xx_npiv;
3358 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3359 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3360 spin_lock_irqsave(&ha->hardware_lock, flags);
3361 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3362 RD_REG_WORD(®->hccr);
3363 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3366 qla81xx_mpi_sync(vha);
3368 /* Load firmware sequences */
3369 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3370 if (rval == QLA_SUCCESS) {
3371 ql_dbg(ql_dbg_init, vha, 0x00c9,
3372 "Verifying Checksum of loaded RISC code.\n");
3374 rval = qla2x00_verify_checksum(vha, srisc_address);
3375 if (rval == QLA_SUCCESS) {
3376 /* Start firmware execution. */
3377 ql_dbg(ql_dbg_init, vha, 0x00ca,
3378 "Starting firmware.\n");
3381 ha->flags.exlogins_enabled = 1;
3383 if (qla_is_exch_offld_enabled(vha))
3384 ha->flags.exchoffld_enabled = 1;
3386 rval = qla2x00_execute_fw(vha, srisc_address);
3387 /* Retrieve firmware information. */
3388 if (rval == QLA_SUCCESS) {
3389 qla24xx_detect_sfp(vha);
3391 rval = qla2x00_set_exlogins_buffer(vha);
3392 if (rval != QLA_SUCCESS)
3395 rval = qla2x00_set_exchoffld_buffer(vha);
3396 if (rval != QLA_SUCCESS)
3400 fw_major_version = ha->fw_major_version;
3401 if (IS_P3P_TYPE(ha))
3402 qla82xx_check_md_needed(vha);
3404 rval = qla2x00_get_fw_version(vha);
3405 if (rval != QLA_SUCCESS)
3407 ha->flags.npiv_supported = 0;
3408 if (IS_QLA2XXX_MIDTYPE(ha) &&
3409 (ha->fw_attributes & BIT_2)) {
3410 ha->flags.npiv_supported = 1;
3411 if ((!ha->max_npiv_vports) ||
3412 ((ha->max_npiv_vports + 1) %
3413 MIN_MULTI_ID_FABRIC))
3414 ha->max_npiv_vports =
3415 MIN_MULTI_ID_FABRIC - 1;
3417 qla2x00_get_resource_cnts(vha);
3420 * Allocate the array of outstanding commands
3421 * now that we know the firmware resources.
3423 rval = qla2x00_alloc_outstanding_cmds(ha,
3425 if (rval != QLA_SUCCESS)
3428 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3429 qla2x00_alloc_offload_mem(vha);
3431 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3432 qla2x00_alloc_fw_dump(vha);
3438 ql_log(ql_log_fatal, vha, 0x00cd,
3439 "ISP Firmware failed checksum.\n");
3445 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3446 /* Enable proper parity. */
3447 spin_lock_irqsave(&ha->hardware_lock, flags);
3450 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3452 /* SRAM, Instruction RAM and GP RAM parity */
3453 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3454 RD_REG_WORD(®->hccr);
3455 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3459 ha->flags.fac_supported = 1;
3460 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3463 rval = qla81xx_fac_get_sector_size(vha, &size);
3464 if (rval == QLA_SUCCESS) {
3465 ha->flags.fac_supported = 1;
3466 ha->fdt_block_size = size << 2;
3468 ql_log(ql_log_warn, vha, 0x00ce,
3469 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3470 ha->fw_major_version, ha->fw_minor_version,
3471 ha->fw_subminor_version);
3473 if (IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3474 ha->flags.fac_supported = 0;
3481 ql_log(ql_log_fatal, vha, 0x00cf,
3482 "Setup chip ****FAILED****.\n");
3489 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3490 * @rsp: response queue
3492 * Beginning of request ring has initialization control block already built
3493 * by nvram config routine.
3495 * Returns 0 on success.
3498 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3503 rsp->ring_ptr = rsp->ring;
3504 rsp->ring_index = 0;
3505 rsp->status_srb = NULL;
3506 pkt = rsp->ring_ptr;
3507 for (cnt = 0; cnt < rsp->length; cnt++) {
3508 pkt->signature = RESPONSE_PROCESSED;
3514 * qla2x00_update_fw_options() - Read and process firmware options.
3517 * Returns 0 on success.
3520 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3522 uint16_t swing, emphasis, tx_sens, rx_sens;
3523 struct qla_hw_data *ha = vha->hw;
3525 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3526 qla2x00_get_fw_options(vha, ha->fw_options);
3528 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3531 /* Serial Link options. */
3532 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3533 "Serial link options.\n");
3534 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3535 (uint8_t *)&ha->fw_seriallink_options,
3536 sizeof(ha->fw_seriallink_options));
3538 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3539 if (ha->fw_seriallink_options[3] & BIT_2) {
3540 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3543 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3544 emphasis = (ha->fw_seriallink_options[2] &
3545 (BIT_4 | BIT_3)) >> 3;
3546 tx_sens = ha->fw_seriallink_options[0] &
3547 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3548 rx_sens = (ha->fw_seriallink_options[0] &
3549 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3550 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3551 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3554 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3555 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3556 ha->fw_options[10] |= BIT_5 |
3557 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3558 (tx_sens & (BIT_1 | BIT_0));
3561 swing = (ha->fw_seriallink_options[2] &
3562 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3563 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3564 tx_sens = ha->fw_seriallink_options[1] &
3565 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3566 rx_sens = (ha->fw_seriallink_options[1] &
3567 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3568 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3569 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3572 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3573 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3574 ha->fw_options[11] |= BIT_5 |
3575 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3576 (tx_sens & (BIT_1 | BIT_0));
3580 /* Return command IOCBs without waiting for an ABTS to complete. */
3581 ha->fw_options[3] |= BIT_13;
3584 if (ha->flags.enable_led_scheme)
3585 ha->fw_options[2] |= BIT_12;
3587 /* Detect ISP6312. */
3589 ha->fw_options[2] |= BIT_13;
3591 /* Set Retry FLOGI in case of P2P connection */
3592 if (ha->operating_mode == P2P) {
3593 ha->fw_options[2] |= BIT_3;
3594 ql_dbg(ql_dbg_disc, vha, 0x2100,
3595 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3596 __func__, ha->fw_options[2]);
3599 /* Update firmware options. */
3600 qla2x00_set_fw_options(vha, ha->fw_options);
3604 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3607 struct qla_hw_data *ha = vha->hw;
3609 if (IS_P3P_TYPE(ha))
3612 /* Hold status IOCBs until ABTS response received. */
3614 ha->fw_options[3] |= BIT_12;
3616 /* Set Retry FLOGI in case of P2P connection */
3617 if (ha->operating_mode == P2P) {
3618 ha->fw_options[2] |= BIT_3;
3619 ql_dbg(ql_dbg_disc, vha, 0x2101,
3620 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3621 __func__, ha->fw_options[2]);
3624 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3625 if (ql2xmvasynctoatio &&
3626 (IS_QLA83XX(ha) || IS_QLA27XX(ha))) {
3627 if (qla_tgt_mode_enabled(vha) ||
3628 qla_dual_mode_enabled(vha))
3629 ha->fw_options[2] |= BIT_11;
3631 ha->fw_options[2] &= ~BIT_11;
3634 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3636 * Tell FW to track each exchange to prevent
3637 * driver from using stale exchange.
3639 if (qla_tgt_mode_enabled(vha) ||
3640 qla_dual_mode_enabled(vha))
3641 ha->fw_options[2] |= BIT_4;
3643 ha->fw_options[2] &= ~BIT_4;
3645 /* Reserve 1/2 of emergency exchanges for ELS.*/
3646 if (qla2xuseresexchforels)
3647 ha->fw_options[2] |= BIT_8;
3649 ha->fw_options[2] &= ~BIT_8;
3652 ql_dbg(ql_dbg_init, vha, 0x00e8,
3653 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3654 __func__, ha->fw_options[1], ha->fw_options[2],
3655 ha->fw_options[3], vha->host->active_mode);
3657 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3658 qla2x00_set_fw_options(vha, ha->fw_options);
3660 /* Update Serial Link options. */
3661 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3664 rval = qla2x00_set_serdes_params(vha,
3665 le16_to_cpu(ha->fw_seriallink_options24[1]),
3666 le16_to_cpu(ha->fw_seriallink_options24[2]),
3667 le16_to_cpu(ha->fw_seriallink_options24[3]));
3668 if (rval != QLA_SUCCESS) {
3669 ql_log(ql_log_warn, vha, 0x0104,
3670 "Unable to update Serial Link options (%x).\n", rval);
3675 qla2x00_config_rings(struct scsi_qla_host *vha)
3677 struct qla_hw_data *ha = vha->hw;
3678 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3679 struct req_que *req = ha->req_q_map[0];
3680 struct rsp_que *rsp = ha->rsp_q_map[0];
3682 /* Setup ring parameters in initialization control block. */
3683 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3684 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3685 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3686 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3687 ha->init_cb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3688 ha->init_cb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3689 ha->init_cb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3690 ha->init_cb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3692 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3693 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3694 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3695 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3696 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3700 qla24xx_config_rings(struct scsi_qla_host *vha)
3702 struct qla_hw_data *ha = vha->hw;
3703 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3704 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3705 struct qla_msix_entry *msix;
3706 struct init_cb_24xx *icb;
3708 struct req_que *req = ha->req_q_map[0];
3709 struct rsp_que *rsp = ha->rsp_q_map[0];
3711 /* Setup ring parameters in initialization control block. */
3712 icb = (struct init_cb_24xx *)ha->init_cb;
3713 icb->request_q_outpointer = cpu_to_le16(0);
3714 icb->response_q_inpointer = cpu_to_le16(0);
3715 icb->request_q_length = cpu_to_le16(req->length);
3716 icb->response_q_length = cpu_to_le16(rsp->length);
3717 icb->request_q_address[0] = cpu_to_le32(LSD(req->dma));
3718 icb->request_q_address[1] = cpu_to_le32(MSD(req->dma));
3719 icb->response_q_address[0] = cpu_to_le32(LSD(rsp->dma));
3720 icb->response_q_address[1] = cpu_to_le32(MSD(rsp->dma));
3722 /* Setup ATIO queue dma pointers for target mode */
3723 icb->atio_q_inpointer = cpu_to_le16(0);
3724 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3725 icb->atio_q_address[0] = cpu_to_le32(LSD(ha->tgt.atio_dma));
3726 icb->atio_q_address[1] = cpu_to_le32(MSD(ha->tgt.atio_dma));
3728 if (IS_SHADOW_REG_CAPABLE(ha))
3729 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3731 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha)) {
3732 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3733 icb->rid = cpu_to_le16(rid);
3734 if (ha->flags.msix_enabled) {
3735 msix = &ha->msix_entries[1];
3736 ql_dbg(ql_dbg_init, vha, 0x0019,
3737 "Registering vector 0x%x for base que.\n",
3739 icb->msix = cpu_to_le16(msix->entry);
3741 /* Use alternate PCI bus number */
3743 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
3744 /* Use alternate PCI devfn */
3746 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
3748 /* Use Disable MSIX Handshake mode for capable adapters */
3749 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
3750 (ha->flags.msix_enabled)) {
3751 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
3752 ha->flags.disable_msix_handshake = 1;
3753 ql_dbg(ql_dbg_init, vha, 0x00fe,
3754 "MSIX Handshake Disable Mode turned on.\n");
3756 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
3758 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
3760 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
3761 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
3762 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
3763 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
3765 WRT_REG_DWORD(®->isp24.req_q_in, 0);
3766 WRT_REG_DWORD(®->isp24.req_q_out, 0);
3767 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
3768 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
3770 qlt_24xx_config_rings(vha);
3773 RD_REG_DWORD(&ioreg->hccr);
3777 * qla2x00_init_rings() - Initializes firmware.
3780 * Beginning of request ring has initialization control block already built
3781 * by nvram config routine.
3783 * Returns 0 on success.
3786 qla2x00_init_rings(scsi_qla_host_t *vha)
3789 unsigned long flags = 0;
3791 struct qla_hw_data *ha = vha->hw;
3792 struct req_que *req;
3793 struct rsp_que *rsp;
3794 struct mid_init_cb_24xx *mid_init_cb =
3795 (struct mid_init_cb_24xx *) ha->init_cb;
3797 spin_lock_irqsave(&ha->hardware_lock, flags);
3799 /* Clear outstanding commands array. */
3800 for (que = 0; que < ha->max_req_queues; que++) {
3801 req = ha->req_q_map[que];
3802 if (!req || !test_bit(que, ha->req_qid_map))
3804 req->out_ptr = (void *)(req->ring + req->length);
3806 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
3807 req->outstanding_cmds[cnt] = NULL;
3809 req->current_outstanding_cmd = 1;
3811 /* Initialize firmware. */
3812 req->ring_ptr = req->ring;
3813 req->ring_index = 0;
3814 req->cnt = req->length;
3817 for (que = 0; que < ha->max_rsp_queues; que++) {
3818 rsp = ha->rsp_q_map[que];
3819 if (!rsp || !test_bit(que, ha->rsp_qid_map))
3821 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
3823 /* Initialize response queue entries */
3825 qlafx00_init_response_q_entries(rsp);
3827 qla2x00_init_response_q_entries(rsp);
3830 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
3831 ha->tgt.atio_ring_index = 0;
3832 /* Initialize ATIO queue entries */
3833 qlt_init_atio_q_entries(vha);
3835 ha->isp_ops->config_rings(vha);
3837 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3839 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
3841 if (IS_QLAFX00(ha)) {
3842 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
3846 /* Update any ISP specific firmware options before initialization. */
3847 ha->isp_ops->update_fw_options(vha);
3849 if (ha->flags.npiv_supported) {
3850 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
3851 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
3852 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
3855 if (IS_FWI2_CAPABLE(ha)) {
3856 mid_init_cb->options = cpu_to_le16(BIT_1);
3857 mid_init_cb->init_cb.execution_throttle =
3858 cpu_to_le16(ha->cur_fw_xcb_count);
3859 ha->flags.dport_enabled =
3860 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
3861 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
3862 (ha->flags.dport_enabled) ? "enabled" : "disabled");
3863 /* FA-WWPN Status */
3864 ha->flags.fawwpn_enabled =
3865 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
3866 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
3867 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
3870 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
3873 ql_log(ql_log_fatal, vha, 0x00d2,
3874 "Init Firmware **** FAILED ****.\n");
3876 ql_dbg(ql_dbg_init, vha, 0x00d3,
3877 "Init Firmware -- success.\n");
3885 * qla2x00_fw_ready() - Waits for firmware ready.
3888 * Returns 0 on success.
3891 qla2x00_fw_ready(scsi_qla_host_t *vha)
3894 unsigned long wtime, mtime, cs84xx_time;
3895 uint16_t min_wait; /* Minimum wait time if loop is down */
3896 uint16_t wait_time; /* Wait time if loop is coming ready */
3898 struct qla_hw_data *ha = vha->hw;
3900 if (IS_QLAFX00(vha->hw))
3901 return qlafx00_fw_ready(vha);
3905 /* Time to wait for loop down */
3906 if (IS_P3P_TYPE(ha))
3912 * Firmware should take at most one RATOV to login, plus 5 seconds for
3913 * our own processing.
3915 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
3916 wait_time = min_wait;
3919 /* Min wait time if loop down */
3920 mtime = jiffies + (min_wait * HZ);
3922 /* wait time before firmware ready */
3923 wtime = jiffies + (wait_time * HZ);
3925 /* Wait for ISP to finish LIP */
3926 if (!vha->flags.init_done)
3927 ql_log(ql_log_info, vha, 0x801e,
3928 "Waiting for LIP to complete.\n");
3931 memset(state, -1, sizeof(state));
3932 rval = qla2x00_get_firmware_state(vha, state);
3933 if (rval == QLA_SUCCESS) {
3934 if (state[0] < FSTATE_LOSS_OF_SYNC) {
3935 vha->device_flags &= ~DFLG_NO_CABLE;
3937 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
3938 ql_dbg(ql_dbg_taskm, vha, 0x801f,
3939 "fw_state=%x 84xx=%x.\n", state[0],
3941 if ((state[2] & FSTATE_LOGGED_IN) &&
3942 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
3943 ql_dbg(ql_dbg_taskm, vha, 0x8028,
3944 "Sending verify iocb.\n");
3946 cs84xx_time = jiffies;
3947 rval = qla84xx_init_chip(vha);
3948 if (rval != QLA_SUCCESS) {
3951 "Init chip failed.\n");
3955 /* Add time taken to initialize. */
3956 cs84xx_time = jiffies - cs84xx_time;
3957 wtime += cs84xx_time;
3958 mtime += cs84xx_time;
3959 ql_dbg(ql_dbg_taskm, vha, 0x8008,
3960 "Increasing wait time by %ld. "
3961 "New time %ld.\n", cs84xx_time,
3964 } else if (state[0] == FSTATE_READY) {
3965 ql_dbg(ql_dbg_taskm, vha, 0x8037,
3966 "F/W Ready - OK.\n");
3968 qla2x00_get_retry_cnt(vha, &ha->retry_count,
3969 &ha->login_timeout, &ha->r_a_tov);
3975 rval = QLA_FUNCTION_FAILED;
3977 if (atomic_read(&vha->loop_down_timer) &&
3978 state[0] != FSTATE_READY) {
3979 /* Loop down. Timeout on min_wait for states
3980 * other than Wait for Login.
3982 if (time_after_eq(jiffies, mtime)) {
3983 ql_log(ql_log_info, vha, 0x8038,
3984 "Cable is unplugged...\n");
3986 vha->device_flags |= DFLG_NO_CABLE;
3991 /* Mailbox cmd failed. Timeout on min_wait. */
3992 if (time_after_eq(jiffies, mtime) ||
3993 ha->flags.isp82xx_fw_hung)
3997 if (time_after_eq(jiffies, wtime))
4000 /* Delay for a while */
4004 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4005 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4006 state[1], state[2], state[3], state[4], state[5], jiffies);
4008 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4009 ql_log(ql_log_warn, vha, 0x803b,
4010 "Firmware ready **** FAILED ****.\n");
4017 * qla2x00_configure_hba
4018 * Setup adapter context.
4021 * ha = adapter state pointer.
4030 qla2x00_configure_hba(scsi_qla_host_t *vha)
4039 char connect_type[22];
4040 struct qla_hw_data *ha = vha->hw;
4041 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4043 unsigned long flags;
4045 /* Get host addresses. */
4046 rval = qla2x00_get_adapter_id(vha,
4047 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4048 if (rval != QLA_SUCCESS) {
4049 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4050 IS_CNA_CAPABLE(ha) ||
4051 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4052 ql_dbg(ql_dbg_disc, vha, 0x2008,
4053 "Loop is in a transition state.\n");
4055 ql_log(ql_log_warn, vha, 0x2009,
4056 "Unable to get host loop ID.\n");
4057 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4058 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4059 ql_log(ql_log_warn, vha, 0x1151,
4060 "Doing link init.\n");
4061 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4064 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4070 ql_log(ql_log_info, vha, 0x200a,
4071 "Cannot get topology - retrying.\n");
4072 return (QLA_FUNCTION_FAILED);
4075 vha->loop_id = loop_id;
4078 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4079 ha->operating_mode = LOOP;
4084 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4085 ha->current_topology = ISP_CFG_NL;
4086 strcpy(connect_type, "(Loop)");
4090 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4091 ha->switch_cap = sw_cap;
4092 ha->current_topology = ISP_CFG_FL;
4093 strcpy(connect_type, "(FL_Port)");
4097 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4098 ha->operating_mode = P2P;
4099 ha->current_topology = ISP_CFG_N;
4100 strcpy(connect_type, "(N_Port-to-N_Port)");
4104 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4105 ha->switch_cap = sw_cap;
4106 ha->operating_mode = P2P;
4107 ha->current_topology = ISP_CFG_F;
4108 strcpy(connect_type, "(F_Port)");
4112 ql_dbg(ql_dbg_disc, vha, 0x200f,
4113 "HBA in unknown topology %x, using NL.\n", topo);
4114 ha->current_topology = ISP_CFG_NL;
4115 strcpy(connect_type, "(Loop)");
4119 /* Save Host port and loop ID. */
4120 /* byte order - Big Endian */
4121 id.b.domain = domain;
4125 spin_lock_irqsave(&ha->hardware_lock, flags);
4126 qlt_update_host_map(vha, id);
4127 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4129 if (!vha->flags.init_done)
4130 ql_log(ql_log_info, vha, 0x2010,
4131 "Topology - %s, Host Loop address 0x%x.\n",
4132 connect_type, vha->loop_id);
4138 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4143 struct qla_hw_data *ha = vha->hw;
4144 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4145 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4147 if (memcmp(model, BINZERO, len) != 0) {
4148 strncpy(ha->model_number, model, len);
4149 st = en = ha->model_number;
4152 if (*en != 0x20 && *en != 0x00)
4157 index = (ha->pdev->subsystem_device & 0xff);
4159 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4160 index < QLA_MODEL_NAMES)
4161 strncpy(ha->model_desc,
4162 qla2x00_model_name[index * 2 + 1],
4163 sizeof(ha->model_desc) - 1);
4165 index = (ha->pdev->subsystem_device & 0xff);
4167 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4168 index < QLA_MODEL_NAMES) {
4169 strcpy(ha->model_number,
4170 qla2x00_model_name[index * 2]);
4171 strncpy(ha->model_desc,
4172 qla2x00_model_name[index * 2 + 1],
4173 sizeof(ha->model_desc) - 1);
4175 strcpy(ha->model_number, def);
4178 if (IS_FWI2_CAPABLE(ha))
4179 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4180 sizeof(ha->model_desc));
4183 /* On sparc systems, obtain port and node WWN from firmware
4186 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4189 struct qla_hw_data *ha = vha->hw;
4190 struct pci_dev *pdev = ha->pdev;
4191 struct device_node *dp = pci_device_to_OF_node(pdev);
4195 val = of_get_property(dp, "port-wwn", &len);
4196 if (val && len >= WWN_SIZE)
4197 memcpy(nv->port_name, val, WWN_SIZE);
4199 val = of_get_property(dp, "node-wwn", &len);
4200 if (val && len >= WWN_SIZE)
4201 memcpy(nv->node_name, val, WWN_SIZE);
4206 * NVRAM configuration for ISP 2xxx
4209 * ha = adapter block pointer.
4212 * initialization control block in response_ring
4213 * host adapters parameters in host adapter block
4219 qla2x00_nvram_config(scsi_qla_host_t *vha)
4224 uint8_t *dptr1, *dptr2;
4225 struct qla_hw_data *ha = vha->hw;
4226 init_cb_t *icb = ha->init_cb;
4227 nvram_t *nv = ha->nvram;
4228 uint8_t *ptr = ha->nvram;
4229 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4233 /* Determine NVRAM starting address. */
4234 ha->nvram_size = sizeof(nvram_t);
4236 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4237 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4238 ha->nvram_base = 0x80;
4240 /* Get NVRAM data and calculate checksum. */
4241 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4242 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4245 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4246 "Contents of NVRAM.\n");
4247 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4248 (uint8_t *)nv, ha->nvram_size);
4250 /* Bad NVRAM data, set defaults parameters. */
4251 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' ||
4252 nv->id[2] != 'P' || nv->id[3] != ' ' || nv->nvram_version < 1) {
4253 /* Reset NVRAM data. */
4254 ql_log(ql_log_warn, vha, 0x0064,
4255 "Inconsistent NVRAM "
4256 "detected: checksum=0x%x id=%c version=0x%x.\n",
4257 chksum, nv->id[0], nv->nvram_version);
4258 ql_log(ql_log_warn, vha, 0x0065,
4260 "functioning (yet invalid -- WWPN) defaults.\n");
4263 * Set default initialization control block.
4265 memset(nv, 0, ha->nvram_size);
4266 nv->parameter_block_version = ICB_VERSION;
4268 if (IS_QLA23XX(ha)) {
4269 nv->firmware_options[0] = BIT_2 | BIT_1;
4270 nv->firmware_options[1] = BIT_7 | BIT_5;
4271 nv->add_firmware_options[0] = BIT_5;
4272 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4273 nv->frame_payload_size = 2048;
4274 nv->special_options[1] = BIT_7;
4275 } else if (IS_QLA2200(ha)) {
4276 nv->firmware_options[0] = BIT_2 | BIT_1;
4277 nv->firmware_options[1] = BIT_7 | BIT_5;
4278 nv->add_firmware_options[0] = BIT_5;
4279 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4280 nv->frame_payload_size = 1024;
4281 } else if (IS_QLA2100(ha)) {
4282 nv->firmware_options[0] = BIT_3 | BIT_1;
4283 nv->firmware_options[1] = BIT_5;
4284 nv->frame_payload_size = 1024;
4287 nv->max_iocb_allocation = cpu_to_le16(256);
4288 nv->execution_throttle = cpu_to_le16(16);
4289 nv->retry_count = 8;
4290 nv->retry_delay = 1;
4292 nv->port_name[0] = 33;
4293 nv->port_name[3] = 224;
4294 nv->port_name[4] = 139;
4296 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4298 nv->login_timeout = 4;
4301 * Set default host adapter parameters
4303 nv->host_p[1] = BIT_2;
4304 nv->reset_delay = 5;
4305 nv->port_down_retry_count = 8;
4306 nv->max_luns_per_target = cpu_to_le16(8);
4307 nv->link_down_timeout = 60;
4312 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4314 * The SN2 does not provide BIOS emulation which means you can't change
4315 * potentially bogus BIOS settings. Force the use of default settings
4316 * for link rate and frame size. Hope that the rest of the settings
4319 if (ia64_platform_is("sn2")) {
4320 nv->frame_payload_size = 2048;
4322 nv->special_options[1] = BIT_7;
4326 /* Reset Initialization control block */
4327 memset(icb, 0, ha->init_cb_size);
4330 * Setup driver NVRAM options.
4332 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4333 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4334 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4335 nv->firmware_options[1] &= ~BIT_4;
4337 if (IS_QLA23XX(ha)) {
4338 nv->firmware_options[0] |= BIT_2;
4339 nv->firmware_options[0] &= ~BIT_3;
4340 nv->special_options[0] &= ~BIT_6;
4341 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4343 if (IS_QLA2300(ha)) {
4344 if (ha->fb_rev == FPM_2310) {
4345 strcpy(ha->model_number, "QLA2310");
4347 strcpy(ha->model_number, "QLA2300");
4350 qla2x00_set_model_info(vha, nv->model_number,
4351 sizeof(nv->model_number), "QLA23xx");
4353 } else if (IS_QLA2200(ha)) {
4354 nv->firmware_options[0] |= BIT_2;
4356 * 'Point-to-point preferred, else loop' is not a safe
4357 * connection mode setting.
4359 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4361 /* Force 'loop preferred, else point-to-point'. */
4362 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4363 nv->add_firmware_options[0] |= BIT_5;
4365 strcpy(ha->model_number, "QLA22xx");
4366 } else /*if (IS_QLA2100(ha))*/ {
4367 strcpy(ha->model_number, "QLA2100");
4371 * Copy over NVRAM RISC parameter block to initialization control block.
4373 dptr1 = (uint8_t *)icb;
4374 dptr2 = (uint8_t *)&nv->parameter_block_version;
4375 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4377 *dptr1++ = *dptr2++;
4379 /* Copy 2nd half. */
4380 dptr1 = (uint8_t *)icb->add_firmware_options;
4381 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4383 *dptr1++ = *dptr2++;
4385 /* Use alternate WWN? */
4386 if (nv->host_p[1] & BIT_7) {
4387 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4388 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4391 /* Prepare nodename */
4392 if ((icb->firmware_options[1] & BIT_6) == 0) {
4394 * Firmware will apply the following mask if the nodename was
4397 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4398 icb->node_name[0] &= 0xF0;
4402 * Set host adapter parameters.
4406 * BIT_7 in the host-parameters section allows for modification to
4407 * internal driver logging.
4409 if (nv->host_p[0] & BIT_7)
4410 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4411 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4412 /* Always load RISC code on non ISP2[12]00 chips. */
4413 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4414 ha->flags.disable_risc_code_load = 0;
4415 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4416 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4417 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4418 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4419 ha->flags.disable_serdes = 0;
4421 ha->operating_mode =
4422 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4424 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4425 sizeof(ha->fw_seriallink_options));
4427 /* save HBA serial number */
4428 ha->serial0 = icb->port_name[5];
4429 ha->serial1 = icb->port_name[6];
4430 ha->serial2 = icb->port_name[7];
4431 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4432 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4434 icb->execution_throttle = cpu_to_le16(0xFFFF);
4436 ha->retry_count = nv->retry_count;
4438 /* Set minimum login_timeout to 4 seconds. */
4439 if (nv->login_timeout != ql2xlogintimeout)
4440 nv->login_timeout = ql2xlogintimeout;
4441 if (nv->login_timeout < 4)
4442 nv->login_timeout = 4;
4443 ha->login_timeout = nv->login_timeout;
4445 /* Set minimum RATOV to 100 tenths of a second. */
4448 ha->loop_reset_delay = nv->reset_delay;
4450 /* Link Down Timeout = 0:
4452 * When Port Down timer expires we will start returning
4453 * I/O's to OS with "DID_NO_CONNECT".
4455 * Link Down Timeout != 0:
4457 * The driver waits for the link to come up after link down
4458 * before returning I/Os to OS with "DID_NO_CONNECT".
4460 if (nv->link_down_timeout == 0) {
4461 ha->loop_down_abort_time =
4462 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4464 ha->link_down_timeout = nv->link_down_timeout;
4465 ha->loop_down_abort_time =
4466 (LOOP_DOWN_TIME - ha->link_down_timeout);
4470 * Need enough time to try and get the port back.
4472 ha->port_down_retry_count = nv->port_down_retry_count;
4473 if (qlport_down_retry)
4474 ha->port_down_retry_count = qlport_down_retry;
4475 /* Set login_retry_count */
4476 ha->login_retry_count = nv->retry_count;
4477 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4478 ha->port_down_retry_count > 3)
4479 ha->login_retry_count = ha->port_down_retry_count;
4480 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4481 ha->login_retry_count = ha->port_down_retry_count;
4482 if (ql2xloginretrycount)
4483 ha->login_retry_count = ql2xloginretrycount;
4485 icb->lun_enables = cpu_to_le16(0);
4486 icb->command_resource_count = 0;
4487 icb->immediate_notify_resource_count = 0;
4488 icb->timeout = cpu_to_le16(0);
4490 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4492 icb->firmware_options[0] &= ~BIT_3;
4493 icb->add_firmware_options[0] &=
4494 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4495 icb->add_firmware_options[0] |= BIT_2;
4496 icb->response_accumulation_timer = 3;
4497 icb->interrupt_delay_timer = 5;
4499 vha->flags.process_response_queue = 1;
4502 if (!vha->flags.init_done) {
4503 ha->zio_mode = icb->add_firmware_options[0] &
4504 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4505 ha->zio_timer = icb->interrupt_delay_timer ?
4506 icb->interrupt_delay_timer: 2;
4508 icb->add_firmware_options[0] &=
4509 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4510 vha->flags.process_response_queue = 0;
4511 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4512 ha->zio_mode = QLA_ZIO_MODE_6;
4514 ql_log(ql_log_info, vha, 0x0068,
4515 "ZIO mode %d enabled; timer delay (%d us).\n",
4516 ha->zio_mode, ha->zio_timer * 100);
4518 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4519 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4520 vha->flags.process_response_queue = 1;
4525 ql_log(ql_log_warn, vha, 0x0069,
4526 "NVRAM configuration failed.\n");
4532 qla2x00_rport_del(void *data)
4534 fc_port_t *fcport = data;
4535 struct fc_rport *rport;
4536 unsigned long flags;
4538 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4539 rport = fcport->drport ? fcport->drport: fcport->rport;
4540 fcport->drport = NULL;
4541 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4543 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4544 "%s %8phN. rport %p roles %x\n",
4545 __func__, fcport->port_name, rport,
4548 fc_remote_port_delete(rport);
4553 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4555 * @flags: allocation flags
4557 * Returns a pointer to the allocated fcport, or NULL, if none available.
4560 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4564 fcport = kzalloc(sizeof(fc_port_t), flags);
4568 /* Setup fcport template structure. */
4570 fcport->port_type = FCT_UNKNOWN;
4571 fcport->loop_id = FC_NO_LOOP_ID;
4572 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4573 fcport->supported_classes = FC_COS_UNSPECIFIED;
4575 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4576 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4578 fcport->disc_state = DSC_DELETED;
4579 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4580 fcport->deleted = QLA_SESS_DELETED;
4581 fcport->login_retry = vha->hw->login_retry_count;
4582 fcport->logout_on_delete = 1;
4584 if (!fcport->ct_desc.ct_sns) {
4585 ql_log(ql_log_warn, vha, 0xd049,
4586 "Failed to allocate ct_sns request.\n");
4590 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4591 INIT_LIST_HEAD(&fcport->gnl_entry);
4592 INIT_LIST_HEAD(&fcport->list);
4598 qla2x00_free_fcport(fc_port_t *fcport)
4600 if (fcport->ct_desc.ct_sns) {
4601 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4602 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4603 fcport->ct_desc.ct_sns_dma);
4605 fcport->ct_desc.ct_sns = NULL;
4611 * qla2x00_configure_loop
4612 * Updates Fibre Channel Device Database with what is actually on loop.
4615 * ha = adapter block pointer.
4620 * 2 = database was full and device was not configured.
4623 qla2x00_configure_loop(scsi_qla_host_t *vha)
4626 unsigned long flags, save_flags;
4627 struct qla_hw_data *ha = vha->hw;
4630 /* Get Initiator ID */
4631 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4632 rval = qla2x00_configure_hba(vha);
4633 if (rval != QLA_SUCCESS) {
4634 ql_dbg(ql_dbg_disc, vha, 0x2013,
4635 "Unable to configure HBA.\n");
4640 save_flags = flags = vha->dpc_flags;
4641 ql_dbg(ql_dbg_disc, vha, 0x2014,
4642 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4645 * If we have both an RSCN and PORT UPDATE pending then handle them
4646 * both at the same time.
4648 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4649 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4651 qla2x00_get_data_rate(vha);
4653 /* Determine what we need to do */
4654 if (ha->current_topology == ISP_CFG_FL &&
4655 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4657 set_bit(RSCN_UPDATE, &flags);
4659 } else if (ha->current_topology == ISP_CFG_F &&
4660 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4662 set_bit(RSCN_UPDATE, &flags);
4663 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4665 } else if (ha->current_topology == ISP_CFG_N) {
4666 clear_bit(RSCN_UPDATE, &flags);
4667 if (qla_tgt_mode_enabled(vha)) {
4668 /* allow the other side to start the login */
4669 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4670 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4672 } else if (ha->current_topology == ISP_CFG_NL) {
4673 clear_bit(RSCN_UPDATE, &flags);
4674 set_bit(LOCAL_LOOP_UPDATE, &flags);
4675 } else if (!vha->flags.online ||
4676 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4677 set_bit(RSCN_UPDATE, &flags);
4678 set_bit(LOCAL_LOOP_UPDATE, &flags);
4681 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4682 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4683 ql_dbg(ql_dbg_disc, vha, 0x2015,
4684 "Loop resync needed, failing.\n");
4685 rval = QLA_FUNCTION_FAILED;
4687 rval = qla2x00_configure_local_loop(vha);
4690 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4691 if (LOOP_TRANSITION(vha)) {
4692 ql_dbg(ql_dbg_disc, vha, 0x2099,
4693 "Needs RSCN update and loop transition.\n");
4694 rval = QLA_FUNCTION_FAILED;
4697 rval = qla2x00_configure_fabric(vha);
4700 if (rval == QLA_SUCCESS) {
4701 if (atomic_read(&vha->loop_down_timer) ||
4702 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4703 rval = QLA_FUNCTION_FAILED;
4705 atomic_set(&vha->loop_state, LOOP_READY);
4706 ql_dbg(ql_dbg_disc, vha, 0x2069,
4708 ha->flags.fw_init_done = 1;
4711 * Process any ATIO queue entries that came in
4712 * while we weren't online.
4714 if (qla_tgt_mode_enabled(vha) ||
4715 qla_dual_mode_enabled(vha)) {
4716 if (IS_QLA27XX(ha) || IS_QLA83XX(ha)) {
4717 spin_lock_irqsave(&ha->tgt.atio_lock,
4719 qlt_24xx_process_atio_queue(vha, 0);
4720 spin_unlock_irqrestore(
4721 &ha->tgt.atio_lock, flags);
4723 spin_lock_irqsave(&ha->hardware_lock,
4725 qlt_24xx_process_atio_queue(vha, 1);
4726 spin_unlock_irqrestore(
4727 &ha->hardware_lock, flags);
4734 ql_dbg(ql_dbg_disc, vha, 0x206a,
4735 "%s *** FAILED ***.\n", __func__);
4737 ql_dbg(ql_dbg_disc, vha, 0x206b,
4738 "%s: exiting normally.\n", __func__);
4741 /* Restore state if a resync event occurred during processing */
4742 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4743 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
4744 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4745 if (test_bit(RSCN_UPDATE, &save_flags)) {
4746 set_bit(RSCN_UPDATE, &vha->dpc_flags);
4754 * qla2x00_configure_local_loop
4755 * Updates Fibre Channel Device Database with local loop devices.
4758 * ha = adapter block pointer.
4764 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
4769 fc_port_t *fcport, *new_fcport;
4775 uint8_t domain, area, al_pa;
4776 struct qla_hw_data *ha = vha->hw;
4777 unsigned long flags;
4781 entries = MAX_FIBRE_DEVICES_LOOP;
4783 /* Get list of logged in devices. */
4784 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
4785 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
4787 if (rval != QLA_SUCCESS)
4788 goto cleanup_allocation;
4790 ql_dbg(ql_dbg_disc, vha, 0x2011,
4791 "Entries in ID list (%d).\n", entries);
4792 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
4793 (uint8_t *)ha->gid_list,
4794 entries * sizeof(struct gid_list_info));
4796 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4797 fcport->scan_state = QLA_FCPORT_SCAN;
4800 /* Allocate temporary fcport for any new fcports discovered. */
4801 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4802 if (new_fcport == NULL) {
4803 ql_log(ql_log_warn, vha, 0x2012,
4804 "Memory allocation failed for fcport.\n");
4805 rval = QLA_MEMORY_ALLOC_FAILED;
4806 goto cleanup_allocation;
4808 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4810 /* Add devices to port list. */
4811 id_iter = (char *)ha->gid_list;
4812 for (index = 0; index < entries; index++) {
4813 domain = ((struct gid_list_info *)id_iter)->domain;
4814 area = ((struct gid_list_info *)id_iter)->area;
4815 al_pa = ((struct gid_list_info *)id_iter)->al_pa;
4816 if (IS_QLA2100(ha) || IS_QLA2200(ha))
4817 loop_id = (uint16_t)
4818 ((struct gid_list_info *)id_iter)->loop_id_2100;
4820 loop_id = le16_to_cpu(
4821 ((struct gid_list_info *)id_iter)->loop_id);
4822 id_iter += ha->gid_list_info_size;
4824 /* Bypass reserved domain fields. */
4825 if ((domain & 0xf0) == 0xf0)
4828 /* Bypass if not same domain and area of adapter. */
4829 if (area && domain &&
4830 (area != vha->d_id.b.area || domain != vha->d_id.b.domain))
4833 /* Bypass invalid local loop ID. */
4834 if (loop_id > LAST_LOCAL_LOOP_ID)
4837 memset(new_fcport->port_name, 0, WWN_SIZE);
4839 /* Fill in member data. */
4840 new_fcport->d_id.b.domain = domain;
4841 new_fcport->d_id.b.area = area;
4842 new_fcport->d_id.b.al_pa = al_pa;
4843 new_fcport->loop_id = loop_id;
4844 new_fcport->scan_state = QLA_FCPORT_FOUND;
4846 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
4847 if (rval2 != QLA_SUCCESS) {
4848 ql_dbg(ql_dbg_disc, vha, 0x2097,
4849 "Failed to retrieve fcport information "
4850 "-- get_port_database=%x, loop_id=0x%04x.\n",
4851 rval2, new_fcport->loop_id);
4852 /* Skip retry if N2N */
4853 if (ha->current_topology != ISP_CFG_N) {
4854 ql_dbg(ql_dbg_disc, vha, 0x2105,
4855 "Scheduling resync.\n");
4856 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
4861 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4862 /* Check for matching device in port list. */
4865 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4866 if (memcmp(new_fcport->port_name, fcport->port_name,
4870 fcport->flags &= ~FCF_FABRIC_DEVICE;
4871 fcport->loop_id = new_fcport->loop_id;
4872 fcport->port_type = new_fcport->port_type;
4873 fcport->d_id.b24 = new_fcport->d_id.b24;
4874 memcpy(fcport->node_name, new_fcport->node_name,
4876 fcport->scan_state = QLA_FCPORT_FOUND;
4882 /* New device, add to fcports list. */
4883 list_add_tail(&new_fcport->list, &vha->vp_fcports);
4885 /* Allocate a new replacement fcport. */
4886 fcport = new_fcport;
4888 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4890 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
4892 if (new_fcport == NULL) {
4893 ql_log(ql_log_warn, vha, 0xd031,
4894 "Failed to allocate memory for fcport.\n");
4895 rval = QLA_MEMORY_ALLOC_FAILED;
4896 goto cleanup_allocation;
4898 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
4899 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
4902 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
4904 /* Base iIDMA settings on HBA port speed. */
4905 fcport->fp_speed = ha->link_data_rate;
4910 list_for_each_entry(fcport, &vha->vp_fcports, list) {
4911 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
4914 if (fcport->scan_state == QLA_FCPORT_SCAN) {
4915 if ((qla_dual_mode_enabled(vha) ||
4916 qla_ini_mode_enabled(vha)) &&
4917 atomic_read(&fcport->state) == FCS_ONLINE) {
4918 qla2x00_mark_device_lost(vha, fcport,
4919 ql2xplogiabsentdevice, 0);
4920 if (fcport->loop_id != FC_NO_LOOP_ID &&
4921 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
4922 fcport->port_type != FCT_INITIATOR &&
4923 fcport->port_type != FCT_BROADCAST) {
4924 ql_dbg(ql_dbg_disc, vha, 0x20f0,
4925 "%s %d %8phC post del sess\n",
4929 qlt_schedule_sess_for_deletion(fcport);
4935 if (fcport->scan_state == QLA_FCPORT_FOUND)
4936 qla24xx_fcport_handle_login(vha, fcport);
4942 if (rval != QLA_SUCCESS) {
4943 ql_dbg(ql_dbg_disc, vha, 0x2098,
4944 "Configure local loop error exit: rval=%x.\n", rval);
4951 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
4954 uint16_t mb[MAILBOX_REGISTER_COUNT];
4955 struct qla_hw_data *ha = vha->hw;
4957 if (!IS_IIDMA_CAPABLE(ha))
4960 if (atomic_read(&fcport->state) != FCS_ONLINE)
4963 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
4964 fcport->fp_speed > ha->link_data_rate ||
4965 !ha->flags.gpsc_supported)
4968 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
4970 if (rval != QLA_SUCCESS) {
4971 ql_dbg(ql_dbg_disc, vha, 0x2004,
4972 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
4973 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
4975 ql_dbg(ql_dbg_disc, vha, 0x2005,
4976 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
4977 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
4978 fcport->fp_speed, fcport->port_name);
4982 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4984 qla2x00_iidma_fcport(vha, fcport);
4985 qla24xx_update_fcport_fcp_prio(vha, fcport);
4988 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
4990 struct qla_work_evt *e;
4992 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
4994 return QLA_FUNCTION_FAILED;
4996 e->u.fcport.fcport = fcport;
4997 return qla2x00_post_work(vha, e);
5000 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5002 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5004 struct fc_rport_identifiers rport_ids;
5005 struct fc_rport *rport;
5006 unsigned long flags;
5008 if (atomic_read(&fcport->state) == FCS_ONLINE)
5011 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5012 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5013 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5014 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5015 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5016 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5018 ql_log(ql_log_warn, vha, 0x2006,
5019 "Unable to allocate fc remote port.\n");
5023 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5024 *((fc_port_t **)rport->dd_data) = fcport;
5025 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5027 rport->supported_classes = fcport->supported_classes;
5029 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5030 if (fcport->port_type == FCT_INITIATOR)
5031 rport_ids.roles |= FC_RPORT_ROLE_FCP_INITIATOR;
5032 if (fcport->port_type == FCT_TARGET)
5033 rport_ids.roles |= FC_RPORT_ROLE_FCP_TARGET;
5035 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5036 "%s %8phN. rport %p is %s mode\n",
5037 __func__, fcport->port_name, rport,
5038 (fcport->port_type == FCT_TARGET) ? "tgt" : "ini");
5040 fc_remote_port_rolechg(rport, rport_ids.roles);
5044 * qla2x00_update_fcport
5045 * Updates device on list.
5048 * ha = adapter block pointer.
5049 * fcport = port structure pointer.
5059 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5063 if (IS_SW_RESV_ADDR(fcport->d_id))
5066 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5067 fcport->disc_state = DSC_LOGIN_COMPLETE;
5068 fcport->deleted = 0;
5069 fcport->logout_on_delete = 1;
5070 fcport->login_retry = vha->hw->login_retry_count;
5072 qla2x00_iidma_fcport(vha, fcport);
5074 if (fcport->fc4f_nvme) {
5075 qla_nvme_register_remote(vha, fcport);
5076 fcport->disc_state = DSC_LOGIN_COMPLETE;
5077 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5081 qla24xx_update_fcport_fcp_prio(vha, fcport);
5083 switch (vha->host->active_mode) {
5084 case MODE_INITIATOR:
5085 qla2x00_reg_remote_port(vha, fcport);
5088 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5089 !vha->vha_tgt.qla_tgt->tgt_stopped)
5090 qlt_fc_port_added(vha, fcport);
5093 qla2x00_reg_remote_port(vha, fcport);
5094 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5095 !vha->vha_tgt.qla_tgt->tgt_stopped)
5096 qlt_fc_port_added(vha, fcport);
5102 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5103 if (fcport->id_changed) {
5104 fcport->id_changed = 0;
5105 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5106 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5107 __func__, __LINE__, fcport->port_name,
5109 qla24xx_post_gfpnid_work(vha, fcport);
5111 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5112 "%s %d %8phC post gpsc fcp_cnt %d\n",
5113 __func__, __LINE__, fcport->port_name,
5115 qla24xx_post_gpsc_work(vha, fcport);
5118 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5122 * qla2x00_configure_fabric
5123 * Setup SNS devices with loop ID's.
5126 * ha = adapter block pointer.
5133 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5137 uint16_t mb[MAILBOX_REGISTER_COUNT];
5139 LIST_HEAD(new_fcports);
5140 struct qla_hw_data *ha = vha->hw;
5143 /* If FL port exists, then SNS is present */
5144 if (IS_FWI2_CAPABLE(ha))
5145 loop_id = NPH_F_PORT;
5147 loop_id = SNS_FL_PORT;
5148 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5149 if (rval != QLA_SUCCESS) {
5150 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5151 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5153 vha->device_flags &= ~SWITCH_FOUND;
5154 return (QLA_SUCCESS);
5156 vha->device_flags |= SWITCH_FOUND;
5159 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5160 rval = qla2x00_send_change_request(vha, 0x3, 0);
5161 if (rval != QLA_SUCCESS)
5162 ql_log(ql_log_warn, vha, 0x121,
5163 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5169 qla2x00_mgmt_svr_login(vha);
5172 if (ql2xfdmienable &&
5173 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5174 qla2x00_fdmi_register(vha);
5176 /* Ensure we are logged into the SNS. */
5177 loop_id = NPH_SNS_LID(ha);
5178 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5179 0xfc, mb, BIT_1|BIT_0);
5180 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5181 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5182 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5183 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5184 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5187 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5188 if (qla2x00_rft_id(vha)) {
5190 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5191 "Register FC-4 TYPE failed.\n");
5192 if (test_bit(LOOP_RESYNC_NEEDED,
5196 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5198 ql_dbg(ql_dbg_disc, vha, 0x209a,
5199 "Register FC-4 Features failed.\n");
5200 if (test_bit(LOOP_RESYNC_NEEDED,
5204 if (vha->flags.nvme_enabled) {
5205 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5206 ql_dbg(ql_dbg_disc, vha, 0x2049,
5207 "Register NVME FC Type Features failed.\n");
5210 if (qla2x00_rnn_id(vha)) {
5212 ql_dbg(ql_dbg_disc, vha, 0x2104,
5213 "Register Node Name failed.\n");
5214 if (test_bit(LOOP_RESYNC_NEEDED,
5217 } else if (qla2x00_rsnn_nn(vha)) {
5219 ql_dbg(ql_dbg_disc, vha, 0x209b,
5220 "Register Symbolic Node Name failed.\n");
5221 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5227 /* Mark the time right before querying FW for connected ports.
5228 * This process is long, asynchronous and by the time it's done,
5229 * collected information might not be accurate anymore. E.g.
5230 * disconnected port might have re-connected and a brand new
5231 * session has been created. In this case session's generation
5232 * will be newer than discovery_gen. */
5233 qlt_do_generation_tick(vha, &discovery_gen);
5235 if (USE_ASYNC_SCAN(ha)) {
5236 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5239 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5241 list_for_each_entry(fcport, &vha->vp_fcports, list)
5242 fcport->scan_state = QLA_FCPORT_SCAN;
5244 rval = qla2x00_find_all_fabric_devs(vha);
5246 if (rval != QLA_SUCCESS)
5250 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5251 qla_nvme_register_hba(vha);
5254 ql_dbg(ql_dbg_disc, vha, 0x2068,
5255 "Configure fabric error exit rval=%d.\n", rval);
5261 * qla2x00_find_all_fabric_devs
5264 * ha = adapter block pointer.
5265 * dev = database device entry pointer.
5274 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5278 fc_port_t *fcport, *new_fcport;
5283 int first_dev, last_dev;
5284 port_id_t wrap = {}, nxt_d_id;
5285 struct qla_hw_data *ha = vha->hw;
5286 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5287 unsigned long flags;
5291 /* Try GID_PT to get device list, else GAN. */
5293 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5298 ql_dbg(ql_dbg_disc, vha, 0x209c,
5299 "GID_PT allocations failed, fallback on GA_NXT.\n");
5301 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5302 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5304 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5306 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5308 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5310 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5312 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5314 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5316 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5320 /* If other queries succeeded probe for FC-4 type */
5322 qla2x00_gff_id(vha, swl);
5323 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5329 /* Allocate temporary fcport for any new fcports discovered. */
5330 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5331 if (new_fcport == NULL) {
5332 ql_log(ql_log_warn, vha, 0x209d,
5333 "Failed to allocate memory for fcport.\n");
5334 return (QLA_MEMORY_ALLOC_FAILED);
5336 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5337 /* Set start port ID scan at adapter ID. */
5341 /* Starting free loop ID. */
5342 loop_id = ha->min_external_loopid;
5343 for (; loop_id <= ha->max_loop_id; loop_id++) {
5344 if (qla2x00_is_reserved_id(vha, loop_id))
5347 if (ha->current_topology == ISP_CFG_FL &&
5348 (atomic_read(&vha->loop_down_timer) ||
5349 LOOP_TRANSITION(vha))) {
5350 atomic_set(&vha->loop_down_timer, 0);
5351 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5352 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5358 wrap.b24 = new_fcport->d_id.b24;
5360 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5361 memcpy(new_fcport->node_name,
5362 swl[swl_idx].node_name, WWN_SIZE);
5363 memcpy(new_fcport->port_name,
5364 swl[swl_idx].port_name, WWN_SIZE);
5365 memcpy(new_fcport->fabric_port_name,
5366 swl[swl_idx].fabric_port_name, WWN_SIZE);
5367 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5368 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5370 new_fcport->nvme_flag = 0;
5371 new_fcport->fc4f_nvme = 0;
5372 if (vha->flags.nvme_enabled &&
5373 swl[swl_idx].fc4f_nvme) {
5374 new_fcport->fc4f_nvme =
5375 swl[swl_idx].fc4f_nvme;
5376 ql_log(ql_log_info, vha, 0x2131,
5377 "FOUND: NVME port %8phC as FC Type 28h\n",
5378 new_fcport->port_name);
5381 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5387 /* Send GA_NXT to the switch */
5388 rval = qla2x00_ga_nxt(vha, new_fcport);
5389 if (rval != QLA_SUCCESS) {
5390 ql_log(ql_log_warn, vha, 0x209e,
5391 "SNS scan failed -- assuming "
5392 "zero-entry result.\n");
5398 /* If wrap on switch device list, exit. */
5400 wrap.b24 = new_fcport->d_id.b24;
5402 } else if (new_fcport->d_id.b24 == wrap.b24) {
5403 ql_dbg(ql_dbg_disc, vha, 0x209f,
5404 "Device wrap (%02x%02x%02x).\n",
5405 new_fcport->d_id.b.domain,
5406 new_fcport->d_id.b.area,
5407 new_fcport->d_id.b.al_pa);
5411 /* Bypass if same physical adapter. */
5412 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5415 /* Bypass virtual ports of the same host. */
5416 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5419 /* Bypass if same domain and area of adapter. */
5420 if (((new_fcport->d_id.b24 & 0xffff00) ==
5421 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5425 /* Bypass reserved domain fields. */
5426 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5429 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5430 if (ql2xgffidenable &&
5431 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5432 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5435 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5437 /* Locate matching device in database. */
5439 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5440 if (memcmp(new_fcport->port_name, fcport->port_name,
5444 fcport->scan_state = QLA_FCPORT_FOUND;
5448 /* Update port state. */
5449 memcpy(fcport->fabric_port_name,
5450 new_fcport->fabric_port_name, WWN_SIZE);
5451 fcport->fp_speed = new_fcport->fp_speed;
5454 * If address the same and state FCS_ONLINE
5455 * (or in target mode), nothing changed.
5457 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5458 (atomic_read(&fcport->state) == FCS_ONLINE ||
5459 (vha->host->active_mode == MODE_TARGET))) {
5464 * If device was not a fabric device before.
5466 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5467 fcport->d_id.b24 = new_fcport->d_id.b24;
5468 qla2x00_clear_loop_id(fcport);
5469 fcport->flags |= (FCF_FABRIC_DEVICE |
5475 * Port ID changed or device was marked to be updated;
5476 * Log it out if still logged in and mark it for
5479 if (qla_tgt_mode_enabled(base_vha)) {
5480 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5481 "port changed FC ID, %8phC"
5482 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5484 fcport->d_id.b.domain,
5485 fcport->d_id.b.area,
5486 fcport->d_id.b.al_pa,
5488 new_fcport->d_id.b.domain,
5489 new_fcport->d_id.b.area,
5490 new_fcport->d_id.b.al_pa);
5491 fcport->d_id.b24 = new_fcport->d_id.b24;
5495 fcport->d_id.b24 = new_fcport->d_id.b24;
5496 fcport->flags |= FCF_LOGIN_NEEDED;
5500 if (fcport->fc4f_nvme) {
5501 if (fcport->disc_state == DSC_DELETE_PEND) {
5502 fcport->disc_state = DSC_GNL;
5503 vha->fcport_count--;
5504 fcport->login_succ = 0;
5509 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5512 /* If device was not in our fcports list, then add it. */
5513 new_fcport->scan_state = QLA_FCPORT_FOUND;
5514 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5516 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5519 /* Allocate a new replacement fcport. */
5520 nxt_d_id.b24 = new_fcport->d_id.b24;
5521 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5522 if (new_fcport == NULL) {
5523 ql_log(ql_log_warn, vha, 0xd032,
5524 "Memory allocation failed for fcport.\n");
5525 return (QLA_MEMORY_ALLOC_FAILED);
5527 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5528 new_fcport->d_id.b24 = nxt_d_id.b24;
5531 qla2x00_free_fcport(new_fcport);
5534 * Logout all previous fabric dev marked lost, except FCP2 devices.
5536 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5537 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5540 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5541 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5544 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5545 if ((qla_dual_mode_enabled(vha) ||
5546 qla_ini_mode_enabled(vha)) &&
5547 atomic_read(&fcport->state) == FCS_ONLINE) {
5548 qla2x00_mark_device_lost(vha, fcport,
5549 ql2xplogiabsentdevice, 0);
5550 if (fcport->loop_id != FC_NO_LOOP_ID &&
5551 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5552 fcport->port_type != FCT_INITIATOR &&
5553 fcport->port_type != FCT_BROADCAST) {
5554 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5555 "%s %d %8phC post del sess\n",
5558 qlt_schedule_sess_for_deletion(fcport);
5564 if (fcport->scan_state == QLA_FCPORT_FOUND)
5565 qla24xx_fcport_handle_login(vha, fcport);
5571 * qla2x00_find_new_loop_id
5572 * Scan through our port list and find a new usable loop ID.
5575 * ha: adapter state pointer.
5576 * dev: port structure pointer.
5579 * qla2x00 local function return status code.
5585 qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
5588 struct qla_hw_data *ha = vha->hw;
5589 unsigned long flags = 0;
5593 spin_lock_irqsave(&ha->vport_slock, flags);
5595 dev->loop_id = find_first_zero_bit(ha->loop_id_map,
5597 if (dev->loop_id >= LOOPID_MAP_SIZE ||
5598 qla2x00_is_reserved_id(vha, dev->loop_id)) {
5599 dev->loop_id = FC_NO_LOOP_ID;
5600 rval = QLA_FUNCTION_FAILED;
5602 set_bit(dev->loop_id, ha->loop_id_map);
5604 spin_unlock_irqrestore(&ha->vport_slock, flags);
5606 if (rval == QLA_SUCCESS)
5607 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
5608 "Assigning new loopid=%x, portid=%x.\n",
5609 dev->loop_id, dev->d_id.b24);
5611 ql_log(ql_log_warn, dev->vha, 0x2087,
5612 "No loop_id's available, portid=%x.\n",
5619 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5621 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5623 int loop_id = FC_NO_LOOP_ID;
5624 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5625 unsigned long flags;
5626 struct qla_hw_data *ha = vha->hw;
5628 if (vha->vp_idx == 0) {
5629 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5630 return NPH_MGMT_SERVER;
5633 /* pick id from high and work down to low */
5634 spin_lock_irqsave(&ha->vport_slock, flags);
5635 for (; lid > 0; lid--) {
5636 if (!test_bit(lid, vha->hw->loop_id_map)) {
5637 set_bit(lid, vha->hw->loop_id_map);
5642 spin_unlock_irqrestore(&ha->vport_slock, flags);
5648 * qla2x00_fabric_login
5649 * Issue fabric login command.
5652 * ha = adapter block pointer.
5653 * device = pointer to FC device type structure.
5656 * 0 - Login successfully
5658 * 2 - Initiator device
5662 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5663 uint16_t *next_loopid)
5667 uint16_t tmp_loopid;
5668 uint16_t mb[MAILBOX_REGISTER_COUNT];
5669 struct qla_hw_data *ha = vha->hw;
5675 ql_dbg(ql_dbg_disc, vha, 0x2000,
5676 "Trying Fabric Login w/loop id 0x%04x for port "
5678 fcport->loop_id, fcport->d_id.b.domain,
5679 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5681 /* Login fcport on switch. */
5682 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
5683 fcport->d_id.b.domain, fcport->d_id.b.area,
5684 fcport->d_id.b.al_pa, mb, BIT_0);
5685 if (rval != QLA_SUCCESS) {
5688 if (mb[0] == MBS_PORT_ID_USED) {
5690 * Device has another loop ID. The firmware team
5691 * recommends the driver perform an implicit login with
5692 * the specified ID again. The ID we just used is save
5693 * here so we return with an ID that can be tried by
5697 tmp_loopid = fcport->loop_id;
5698 fcport->loop_id = mb[1];
5700 ql_dbg(ql_dbg_disc, vha, 0x2001,
5701 "Fabric Login: port in use - next loop "
5702 "id=0x%04x, port id= %02x%02x%02x.\n",
5703 fcport->loop_id, fcport->d_id.b.domain,
5704 fcport->d_id.b.area, fcport->d_id.b.al_pa);
5706 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
5711 /* A retry occurred before. */
5712 *next_loopid = tmp_loopid;
5715 * No retry occurred before. Just increment the
5716 * ID value for next login.
5718 *next_loopid = (fcport->loop_id + 1);
5721 if (mb[1] & BIT_0) {
5722 fcport->port_type = FCT_INITIATOR;
5724 fcport->port_type = FCT_TARGET;
5725 if (mb[1] & BIT_1) {
5726 fcport->flags |= FCF_FCP2_DEVICE;
5731 fcport->supported_classes |= FC_COS_CLASS2;
5733 fcport->supported_classes |= FC_COS_CLASS3;
5735 if (IS_FWI2_CAPABLE(ha)) {
5738 FCF_CONF_COMP_SUPPORTED;
5743 } else if (mb[0] == MBS_LOOP_ID_USED) {
5745 * Loop ID already used, try next loop ID.
5748 rval = qla2x00_find_new_loop_id(vha, fcport);
5749 if (rval != QLA_SUCCESS) {
5750 /* Ran out of loop IDs to use */
5753 } else if (mb[0] == MBS_COMMAND_ERROR) {
5755 * Firmware possibly timed out during login. If NO
5756 * retries are left to do then the device is declared
5759 *next_loopid = fcport->loop_id;
5760 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
5761 fcport->d_id.b.domain, fcport->d_id.b.area,
5762 fcport->d_id.b.al_pa);
5763 qla2x00_mark_device_lost(vha, fcport, 1, 0);
5769 * unrecoverable / not handled error
5771 ql_dbg(ql_dbg_disc, vha, 0x2002,
5772 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
5773 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
5774 fcport->d_id.b.area, fcport->d_id.b.al_pa,
5775 fcport->loop_id, jiffies);
5777 *next_loopid = fcport->loop_id;
5778 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
5779 fcport->d_id.b.domain, fcport->d_id.b.area,
5780 fcport->d_id.b.al_pa);
5781 qla2x00_clear_loop_id(fcport);
5782 fcport->login_retry = 0;
5793 * qla2x00_local_device_login
5794 * Issue local device login command.
5797 * ha = adapter block pointer.
5798 * loop_id = loop id of device to login to.
5800 * Returns (Where's the #define!!!!):
5801 * 0 - Login successfully
5806 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
5809 uint16_t mb[MAILBOX_REGISTER_COUNT];
5811 memset(mb, 0, sizeof(mb));
5812 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
5813 if (rval == QLA_SUCCESS) {
5814 /* Interrogate mailbox registers for any errors */
5815 if (mb[0] == MBS_COMMAND_ERROR)
5817 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
5818 /* device not in PCB table */
5826 * qla2x00_loop_resync
5827 * Resync with fibre channel devices.
5830 * ha = adapter block pointer.
5836 qla2x00_loop_resync(scsi_qla_host_t *vha)
5838 int rval = QLA_SUCCESS;
5840 struct req_que *req;
5841 struct rsp_que *rsp;
5846 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
5847 if (vha->flags.online) {
5848 if (!(rval = qla2x00_fw_ready(vha))) {
5849 /* Wait at most MAX_TARGET RSCNs for a stable link. */
5852 if (!IS_QLAFX00(vha->hw)) {
5854 * Issue a marker after FW becomes
5857 qla2x00_marker(vha, req, rsp, 0, 0,
5859 vha->marker_needed = 0;
5862 /* Remap devices on Loop. */
5863 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5865 if (IS_QLAFX00(vha->hw))
5866 qlafx00_configure_devices(vha);
5868 qla2x00_configure_loop(vha);
5871 } while (!atomic_read(&vha->loop_down_timer) &&
5872 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5873 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
5878 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
5879 return (QLA_FUNCTION_FAILED);
5882 ql_dbg(ql_dbg_disc, vha, 0x206c,
5883 "%s *** FAILED ***.\n", __func__);
5889 * qla2x00_perform_loop_resync
5890 * Description: This function will set the appropriate flags and call
5891 * qla2x00_loop_resync. If successful loop will be resynced
5892 * Arguments : scsi_qla_host_t pointer
5893 * returm : Success or Failure
5896 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
5900 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
5901 /*Configure the flags so that resync happens properly*/
5902 atomic_set(&ha->loop_down_timer, 0);
5903 if (!(ha->device_flags & DFLG_NO_CABLE)) {
5904 atomic_set(&ha->loop_state, LOOP_UP);
5905 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
5906 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
5907 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
5909 rval = qla2x00_loop_resync(ha);
5911 atomic_set(&ha->loop_state, LOOP_DEAD);
5913 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
5920 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
5923 struct scsi_qla_host *vha;
5924 struct qla_hw_data *ha = base_vha->hw;
5925 unsigned long flags;
5927 spin_lock_irqsave(&ha->vport_slock, flags);
5928 /* Go with deferred removal of rport references. */
5929 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
5930 atomic_inc(&vha->vref_count);
5931 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5932 if (fcport->drport &&
5933 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
5934 spin_unlock_irqrestore(&ha->vport_slock, flags);
5935 qla2x00_rport_del(fcport);
5937 spin_lock_irqsave(&ha->vport_slock, flags);
5940 atomic_dec(&vha->vref_count);
5941 wake_up(&vha->vref_waitq);
5943 spin_unlock_irqrestore(&ha->vport_slock, flags);
5946 /* Assumes idc_lock always held on entry */
5948 qla83xx_reset_ownership(scsi_qla_host_t *vha)
5950 struct qla_hw_data *ha = vha->hw;
5951 uint32_t drv_presence, drv_presence_mask;
5952 uint32_t dev_part_info1, dev_part_info2, class_type;
5953 uint32_t class_type_mask = 0x3;
5954 uint16_t fcoe_other_function = 0xffff, i;
5956 if (IS_QLA8044(ha)) {
5957 drv_presence = qla8044_rd_direct(vha,
5958 QLA8044_CRB_DRV_ACTIVE_INDEX);
5959 dev_part_info1 = qla8044_rd_direct(vha,
5960 QLA8044_CRB_DEV_PART_INFO_INDEX);
5961 dev_part_info2 = qla8044_rd_direct(vha,
5962 QLA8044_CRB_DEV_PART_INFO2);
5964 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
5965 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
5966 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
5968 for (i = 0; i < 8; i++) {
5969 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
5970 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5971 (i != ha->portnum)) {
5972 fcoe_other_function = i;
5976 if (fcoe_other_function == 0xffff) {
5977 for (i = 0; i < 8; i++) {
5978 class_type = ((dev_part_info2 >> (i * 4)) &
5980 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
5981 ((i + 8) != ha->portnum)) {
5982 fcoe_other_function = i + 8;
5988 * Prepare drv-presence mask based on fcoe functions present.
5989 * However consider only valid physical fcoe function numbers (0-15).
5991 drv_presence_mask = ~((1 << (ha->portnum)) |
5992 ((fcoe_other_function == 0xffff) ?
5993 0 : (1 << (fcoe_other_function))));
5995 /* We are the reset owner iff:
5996 * - No other protocol drivers present.
5997 * - This is the lowest among fcoe functions. */
5998 if (!(drv_presence & drv_presence_mask) &&
5999 (ha->portnum < fcoe_other_function)) {
6000 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6001 "This host is Reset owner.\n");
6002 ha->flags.nic_core_reset_owner = 1;
6007 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6009 int rval = QLA_SUCCESS;
6010 struct qla_hw_data *ha = vha->hw;
6013 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6014 if (rval == QLA_SUCCESS) {
6015 drv_ack |= (1 << ha->portnum);
6016 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6023 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6025 int rval = QLA_SUCCESS;
6026 struct qla_hw_data *ha = vha->hw;
6029 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6030 if (rval == QLA_SUCCESS) {
6031 drv_ack &= ~(1 << ha->portnum);
6032 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6039 qla83xx_dev_state_to_string(uint32_t dev_state)
6041 switch (dev_state) {
6042 case QLA8XXX_DEV_COLD:
6043 return "COLD/RE-INIT";
6044 case QLA8XXX_DEV_INITIALIZING:
6045 return "INITIALIZING";
6046 case QLA8XXX_DEV_READY:
6048 case QLA8XXX_DEV_NEED_RESET:
6049 return "NEED RESET";
6050 case QLA8XXX_DEV_NEED_QUIESCENT:
6051 return "NEED QUIESCENT";
6052 case QLA8XXX_DEV_FAILED:
6054 case QLA8XXX_DEV_QUIESCENT:
6061 /* Assumes idc-lock always held on entry */
6063 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6065 struct qla_hw_data *ha = vha->hw;
6066 uint32_t idc_audit_reg = 0, duration_secs = 0;
6068 switch (audit_type) {
6069 case IDC_AUDIT_TIMESTAMP:
6070 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6071 idc_audit_reg = (ha->portnum) |
6072 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6073 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6076 case IDC_AUDIT_COMPLETION:
6077 duration_secs = ((jiffies_to_msecs(jiffies) -
6078 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6079 idc_audit_reg = (ha->portnum) |
6080 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6081 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6085 ql_log(ql_log_warn, vha, 0xb078,
6086 "Invalid audit type specified.\n");
6091 /* Assumes idc_lock always held on entry */
6093 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6095 struct qla_hw_data *ha = vha->hw;
6096 uint32_t idc_control, dev_state;
6098 __qla83xx_get_idc_control(vha, &idc_control);
6099 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6100 ql_log(ql_log_info, vha, 0xb080,
6101 "NIC Core reset has been disabled. idc-control=0x%x\n",
6103 return QLA_FUNCTION_FAILED;
6106 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6107 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6108 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6109 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6110 QLA8XXX_DEV_NEED_RESET);
6111 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6112 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6114 const char *state = qla83xx_dev_state_to_string(dev_state);
6115 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6117 /* SV: XXX: Is timeout required here? */
6118 /* Wait for IDC state change READY -> NEED_RESET */
6119 while (dev_state == QLA8XXX_DEV_READY) {
6120 qla83xx_idc_unlock(vha, 0);
6122 qla83xx_idc_lock(vha, 0);
6123 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6127 /* Send IDC ack by writing to drv-ack register */
6128 __qla83xx_set_drv_ack(vha);
6134 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6136 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6140 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6142 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6146 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6148 uint32_t drv_presence = 0;
6149 struct qla_hw_data *ha = vha->hw;
6151 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6152 if (drv_presence & (1 << ha->portnum))
6155 return QLA_TEST_FAILED;
6159 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6161 int rval = QLA_SUCCESS;
6162 struct qla_hw_data *ha = vha->hw;
6164 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6165 "Entered %s().\n", __func__);
6167 if (vha->device_flags & DFLG_DEV_FAILED) {
6168 ql_log(ql_log_warn, vha, 0xb059,
6169 "Device in unrecoverable FAILED state.\n");
6170 return QLA_FUNCTION_FAILED;
6173 qla83xx_idc_lock(vha, 0);
6175 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6176 ql_log(ql_log_warn, vha, 0xb05a,
6177 "Function=0x%x has been removed from IDC participation.\n",
6179 rval = QLA_FUNCTION_FAILED;
6183 qla83xx_reset_ownership(vha);
6185 rval = qla83xx_initiating_reset(vha);
6188 * Perform reset if we are the reset-owner,
6189 * else wait till IDC state changes to READY/FAILED.
6191 if (rval == QLA_SUCCESS) {
6192 rval = qla83xx_idc_state_handler(vha);
6194 if (rval == QLA_SUCCESS)
6195 ha->flags.nic_core_hung = 0;
6196 __qla83xx_clear_drv_ack(vha);
6200 qla83xx_idc_unlock(vha, 0);
6202 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6208 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6210 struct qla_hw_data *ha = vha->hw;
6211 int rval = QLA_FUNCTION_FAILED;
6213 if (!IS_MCTP_CAPABLE(ha)) {
6214 /* This message can be removed from the final version */
6215 ql_log(ql_log_info, vha, 0x506d,
6216 "This board is not MCTP capable\n");
6220 if (!ha->mctp_dump) {
6221 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6222 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6224 if (!ha->mctp_dump) {
6225 ql_log(ql_log_warn, vha, 0x506e,
6226 "Failed to allocate memory for mctp dump\n");
6231 #define MCTP_DUMP_STR_ADDR 0x00000000
6232 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6233 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6234 if (rval != QLA_SUCCESS) {
6235 ql_log(ql_log_warn, vha, 0x506f,
6236 "Failed to capture mctp dump\n");
6238 ql_log(ql_log_info, vha, 0x5070,
6239 "Mctp dump capture for host (%ld/%p).\n",
6240 vha->host_no, ha->mctp_dump);
6241 ha->mctp_dumped = 1;
6244 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6245 ha->flags.nic_core_reset_hdlr_active = 1;
6246 rval = qla83xx_restart_nic_firmware(vha);
6248 /* NIC Core reset failed. */
6249 ql_log(ql_log_warn, vha, 0x5071,
6250 "Failed to restart nic firmware\n");
6252 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6253 "Restarted NIC firmware successfully.\n");
6254 ha->flags.nic_core_reset_hdlr_active = 0;
6262 * qla2x00_quiesce_io
6263 * Description: This function will block the new I/Os
6264 * Its not aborting any I/Os as context
6265 * is not destroyed during quiescence
6266 * Arguments: scsi_qla_host_t
6270 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6272 struct qla_hw_data *ha = vha->hw;
6273 struct scsi_qla_host *vp;
6275 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6276 "Quiescing I/O - ha=%p.\n", ha);
6278 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6279 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6280 atomic_set(&vha->loop_state, LOOP_DOWN);
6281 qla2x00_mark_all_devices_lost(vha, 0);
6282 list_for_each_entry(vp, &ha->vp_list, list)
6283 qla2x00_mark_all_devices_lost(vp, 0);
6285 if (!atomic_read(&vha->loop_down_timer))
6286 atomic_set(&vha->loop_down_timer,
6289 /* Wait for pending cmds to complete */
6290 qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST);
6294 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6296 struct qla_hw_data *ha = vha->hw;
6297 struct scsi_qla_host *vp;
6298 unsigned long flags;
6302 /* For ISP82XX, driver waits for completion of the commands.
6303 * online flag should be set.
6305 if (!(IS_P3P_TYPE(ha)))
6306 vha->flags.online = 0;
6307 ha->flags.chip_reset_done = 0;
6308 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6309 vha->qla_stats.total_isp_aborts++;
6311 ql_log(ql_log_info, vha, 0x00af,
6312 "Performing ISP error recovery - ha=%p.\n", ha);
6314 ha->flags.purge_mbox = 1;
6315 /* For ISP82XX, reset_chip is just disabling interrupts.
6316 * Driver waits for the completion of the commands.
6317 * the interrupts need to be enabled.
6319 if (!(IS_P3P_TYPE(ha)))
6320 ha->isp_ops->reset_chip(vha);
6323 ha->flags.rida_fmt2 = 0;
6324 ha->flags.n2n_ae = 0;
6325 ha->flags.lip_ae = 0;
6326 ha->current_topology = 0;
6327 ha->flags.fw_started = 0;
6328 ha->flags.fw_init_done = 0;
6330 ha->base_qpair->chip_reset = ha->chip_reset;
6331 for (i = 0; i < ha->max_qpairs; i++) {
6332 if (ha->queue_pair_map[i])
6333 ha->queue_pair_map[i]->chip_reset =
6334 ha->base_qpair->chip_reset;
6337 /* purge MBox commands */
6338 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6339 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6340 complete(&ha->mbx_intr_comp);
6344 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6345 atomic_read(&ha->num_pend_mbx_stage2) ||
6346 atomic_read(&ha->num_pend_mbx_stage1)) {
6352 ha->flags.purge_mbox = 0;
6354 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6355 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6356 atomic_set(&vha->loop_state, LOOP_DOWN);
6357 qla2x00_mark_all_devices_lost(vha, 0);
6359 spin_lock_irqsave(&ha->vport_slock, flags);
6360 list_for_each_entry(vp, &ha->vp_list, list) {
6361 atomic_inc(&vp->vref_count);
6362 spin_unlock_irqrestore(&ha->vport_slock, flags);
6364 qla2x00_mark_all_devices_lost(vp, 0);
6366 spin_lock_irqsave(&ha->vport_slock, flags);
6367 atomic_dec(&vp->vref_count);
6369 spin_unlock_irqrestore(&ha->vport_slock, flags);
6371 if (!atomic_read(&vha->loop_down_timer))
6372 atomic_set(&vha->loop_down_timer,
6376 /* Clear all async request states across all VPs. */
6377 list_for_each_entry(fcport, &vha->vp_fcports, list)
6378 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6379 spin_lock_irqsave(&ha->vport_slock, flags);
6380 list_for_each_entry(vp, &ha->vp_list, list) {
6381 atomic_inc(&vp->vref_count);
6382 spin_unlock_irqrestore(&ha->vport_slock, flags);
6384 list_for_each_entry(fcport, &vp->vp_fcports, list)
6385 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6387 spin_lock_irqsave(&ha->vport_slock, flags);
6388 atomic_dec(&vp->vref_count);
6390 spin_unlock_irqrestore(&ha->vport_slock, flags);
6392 if (!ha->flags.eeh_busy) {
6393 /* Make sure for ISP 82XX IO DMA is complete */
6394 if (IS_P3P_TYPE(ha)) {
6395 qla82xx_chip_reset_cleanup(vha);
6396 ql_log(ql_log_info, vha, 0x00b4,
6397 "Done chip reset cleanup.\n");
6399 /* Done waiting for pending commands.
6400 * Reset the online flag.
6402 vha->flags.online = 0;
6405 /* Requeue all commands in outstanding command list. */
6406 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6408 /* memory barrier */
6414 * Resets ISP and aborts all outstanding commands.
6417 * ha = adapter block pointer.
6423 qla2x00_abort_isp(scsi_qla_host_t *vha)
6427 struct qla_hw_data *ha = vha->hw;
6428 struct scsi_qla_host *vp;
6429 struct req_que *req = ha->req_q_map[0];
6430 unsigned long flags;
6432 if (vha->flags.online) {
6433 qla2x00_abort_isp_cleanup(vha);
6435 if (IS_QLA8031(ha)) {
6436 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6437 "Clearing fcoe driver presence.\n");
6438 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6439 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6440 "Error while clearing DRV-Presence.\n");
6443 if (unlikely(pci_channel_offline(ha->pdev) &&
6444 ha->flags.pci_channel_io_perm_failure)) {
6445 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6450 ha->isp_ops->get_flash_version(vha, req->ring);
6452 ha->isp_ops->nvram_config(vha);
6454 if (!qla2x00_restart_isp(vha)) {
6455 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6457 if (!atomic_read(&vha->loop_down_timer)) {
6459 * Issue marker command only when we are going
6460 * to start the I/O .
6462 vha->marker_needed = 1;
6465 vha->flags.online = 1;
6467 ha->isp_ops->enable_intrs(ha);
6469 ha->isp_abort_cnt = 0;
6470 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6472 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6473 qla2x00_get_fw_version(vha);
6475 ha->flags.fce_enabled = 1;
6477 fce_calc_size(ha->fce_bufs));
6478 rval = qla2x00_enable_fce_trace(vha,
6479 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6482 ql_log(ql_log_warn, vha, 0x8033,
6483 "Unable to reinitialize FCE "
6485 ha->flags.fce_enabled = 0;
6490 memset(ha->eft, 0, EFT_SIZE);
6491 rval = qla2x00_enable_eft_trace(vha,
6492 ha->eft_dma, EFT_NUM_BUFFERS);
6494 ql_log(ql_log_warn, vha, 0x8034,
6495 "Unable to reinitialize EFT "
6499 } else { /* failed the ISP abort */
6500 vha->flags.online = 1;
6501 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6502 if (ha->isp_abort_cnt == 0) {
6503 ql_log(ql_log_fatal, vha, 0x8035,
6504 "ISP error recover failed - "
6505 "board disabled.\n");
6507 * The next call disables the board
6510 ha->isp_ops->reset_adapter(vha);
6511 vha->flags.online = 0;
6512 clear_bit(ISP_ABORT_RETRY,
6515 } else { /* schedule another ISP abort */
6516 ha->isp_abort_cnt--;
6517 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6518 "ISP abort - retry remaining %d.\n",
6523 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6524 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6525 "ISP error recovery - retrying (%d) "
6526 "more times.\n", ha->isp_abort_cnt);
6527 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6535 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6536 qla2x00_configure_hba(vha);
6537 spin_lock_irqsave(&ha->vport_slock, flags);
6538 list_for_each_entry(vp, &ha->vp_list, list) {
6540 atomic_inc(&vp->vref_count);
6541 spin_unlock_irqrestore(&ha->vport_slock, flags);
6543 qla2x00_vp_abort_isp(vp);
6545 spin_lock_irqsave(&ha->vport_slock, flags);
6546 atomic_dec(&vp->vref_count);
6549 spin_unlock_irqrestore(&ha->vport_slock, flags);
6551 if (IS_QLA8031(ha)) {
6552 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6553 "Setting back fcoe driver presence.\n");
6554 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6555 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6556 "Error while setting DRV-Presence.\n");
6559 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6567 * qla2x00_restart_isp
6568 * restarts the ISP after a reset
6571 * ha = adapter block pointer.
6577 qla2x00_restart_isp(scsi_qla_host_t *vha)
6580 struct qla_hw_data *ha = vha->hw;
6581 struct req_que *req = ha->req_q_map[0];
6582 struct rsp_que *rsp = ha->rsp_q_map[0];
6584 /* If firmware needs to be loaded */
6585 if (qla2x00_isp_firmware(vha)) {
6586 vha->flags.online = 0;
6587 status = ha->isp_ops->chip_diag(vha);
6589 status = qla2x00_setup_chip(vha);
6592 if (!status && !(status = qla2x00_init_rings(vha))) {
6593 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6594 ha->flags.chip_reset_done = 1;
6596 /* Initialize the queues in use */
6597 qla25xx_init_queues(ha);
6599 status = qla2x00_fw_ready(vha);
6601 /* Issue a marker after FW becomes ready. */
6602 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
6603 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6606 /* if no cable then assume it's good */
6607 if ((vha->device_flags & DFLG_NO_CABLE))
6614 qla25xx_init_queues(struct qla_hw_data *ha)
6616 struct rsp_que *rsp = NULL;
6617 struct req_que *req = NULL;
6618 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6622 for (i = 1; i < ha->max_rsp_queues; i++) {
6623 rsp = ha->rsp_q_map[i];
6624 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6625 rsp->options &= ~BIT_0;
6626 ret = qla25xx_init_rsp_que(base_vha, rsp);
6627 if (ret != QLA_SUCCESS)
6628 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6629 "%s Rsp que: %d init failed.\n",
6632 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6633 "%s Rsp que: %d inited.\n",
6637 for (i = 1; i < ha->max_req_queues; i++) {
6638 req = ha->req_q_map[i];
6639 if (req && test_bit(i, ha->req_qid_map)) {
6640 /* Clear outstanding commands array. */
6641 req->options &= ~BIT_0;
6642 ret = qla25xx_init_req_que(base_vha, req);
6643 if (ret != QLA_SUCCESS)
6644 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6645 "%s Req que: %d init failed.\n",
6648 ql_dbg(ql_dbg_init, base_vha, 0x0102,
6649 "%s Req que: %d inited.\n",
6657 * qla2x00_reset_adapter
6661 * ha = adapter block pointer.
6664 qla2x00_reset_adapter(scsi_qla_host_t *vha)
6666 unsigned long flags = 0;
6667 struct qla_hw_data *ha = vha->hw;
6668 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
6670 vha->flags.online = 0;
6671 ha->isp_ops->disable_intrs(ha);
6673 spin_lock_irqsave(&ha->hardware_lock, flags);
6674 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
6675 RD_REG_WORD(®->hccr); /* PCI Posting. */
6676 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
6677 RD_REG_WORD(®->hccr); /* PCI Posting. */
6678 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6682 qla24xx_reset_adapter(scsi_qla_host_t *vha)
6684 unsigned long flags = 0;
6685 struct qla_hw_data *ha = vha->hw;
6686 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
6688 if (IS_P3P_TYPE(ha))
6691 vha->flags.online = 0;
6692 ha->isp_ops->disable_intrs(ha);
6694 spin_lock_irqsave(&ha->hardware_lock, flags);
6695 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
6696 RD_REG_DWORD(®->hccr);
6697 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
6698 RD_REG_DWORD(®->hccr);
6699 spin_unlock_irqrestore(&ha->hardware_lock, flags);
6701 if (IS_NOPOLLING_TYPE(ha))
6702 ha->isp_ops->enable_intrs(ha);
6705 /* On sparc systems, obtain port and node WWN from firmware
6708 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
6709 struct nvram_24xx *nv)
6712 struct qla_hw_data *ha = vha->hw;
6713 struct pci_dev *pdev = ha->pdev;
6714 struct device_node *dp = pci_device_to_OF_node(pdev);
6718 val = of_get_property(dp, "port-wwn", &len);
6719 if (val && len >= WWN_SIZE)
6720 memcpy(nv->port_name, val, WWN_SIZE);
6722 val = of_get_property(dp, "node-wwn", &len);
6723 if (val && len >= WWN_SIZE)
6724 memcpy(nv->node_name, val, WWN_SIZE);
6729 qla24xx_nvram_config(scsi_qla_host_t *vha)
6732 struct init_cb_24xx *icb;
6733 struct nvram_24xx *nv;
6735 uint8_t *dptr1, *dptr2;
6738 struct qla_hw_data *ha = vha->hw;
6741 icb = (struct init_cb_24xx *)ha->init_cb;
6744 /* Determine NVRAM starting address. */
6745 if (ha->port_no == 0) {
6746 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
6747 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
6749 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
6750 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
6753 ha->nvram_size = sizeof(struct nvram_24xx);
6754 ha->vpd_size = FA_NVRAM_VPD_SIZE;
6756 /* Get VPD data into cache */
6757 ha->vpd = ha->nvram + VPD_OFFSET;
6758 ha->isp_ops->read_nvram(vha, (uint8_t *)ha->vpd,
6759 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
6761 /* Get NVRAM data into cache and calculate checksum. */
6762 dptr = (uint32_t *)nv;
6763 ha->isp_ops->read_nvram(vha, (uint8_t *)dptr, ha->nvram_base,
6765 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
6766 chksum += le32_to_cpu(*dptr);
6768 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
6769 "Contents of NVRAM\n");
6770 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
6771 (uint8_t *)nv, ha->nvram_size);
6773 /* Bad NVRAM data, set defaults parameters. */
6774 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
6775 || nv->id[3] != ' ' ||
6776 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
6777 /* Reset NVRAM data. */
6778 ql_log(ql_log_warn, vha, 0x006b,
6779 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
6780 "version=0x%x.\n", chksum, nv->id[0], nv->nvram_version);
6781 ql_log(ql_log_warn, vha, 0x006c,
6782 "Falling back to functioning (yet invalid -- WWPN) "
6786 * Set default initialization control block.
6788 memset(nv, 0, ha->nvram_size);
6789 nv->nvram_version = cpu_to_le16(ICB_VERSION);
6790 nv->version = cpu_to_le16(ICB_VERSION);
6791 nv->frame_payload_size = 2048;
6792 nv->execution_throttle = cpu_to_le16(0xFFFF);
6793 nv->exchange_count = cpu_to_le16(0);
6794 nv->hard_address = cpu_to_le16(124);
6795 nv->port_name[0] = 0x21;
6796 nv->port_name[1] = 0x00 + ha->port_no + 1;
6797 nv->port_name[2] = 0x00;
6798 nv->port_name[3] = 0xe0;
6799 nv->port_name[4] = 0x8b;
6800 nv->port_name[5] = 0x1c;
6801 nv->port_name[6] = 0x55;
6802 nv->port_name[7] = 0x86;
6803 nv->node_name[0] = 0x20;
6804 nv->node_name[1] = 0x00;
6805 nv->node_name[2] = 0x00;
6806 nv->node_name[3] = 0xe0;
6807 nv->node_name[4] = 0x8b;
6808 nv->node_name[5] = 0x1c;
6809 nv->node_name[6] = 0x55;
6810 nv->node_name[7] = 0x86;
6811 qla24xx_nvram_wwn_from_ofw(vha, nv);
6812 nv->login_retry_count = cpu_to_le16(8);
6813 nv->interrupt_delay_timer = cpu_to_le16(0);
6814 nv->login_timeout = cpu_to_le16(0);
6815 nv->firmware_options_1 =
6816 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
6817 nv->firmware_options_2 = cpu_to_le32(2 << 4);
6818 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
6819 nv->firmware_options_3 = cpu_to_le32(2 << 13);
6820 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
6821 nv->efi_parameters = cpu_to_le32(0);
6822 nv->reset_delay = 5;
6823 nv->max_luns_per_target = cpu_to_le16(128);
6824 nv->port_down_retry_count = cpu_to_le16(30);
6825 nv->link_down_timeout = cpu_to_le16(30);
6830 if (qla_tgt_mode_enabled(vha)) {
6831 /* Don't enable full login after initial LIP */
6832 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
6833 /* Don't enable LIP full login for initiator */
6834 nv->host_p &= cpu_to_le32(~BIT_10);
6837 qlt_24xx_config_nvram_stage1(vha, nv);
6839 /* Reset Initialization control block */
6840 memset(icb, 0, ha->init_cb_size);
6842 /* Copy 1st segment. */
6843 dptr1 = (uint8_t *)icb;
6844 dptr2 = (uint8_t *)&nv->version;
6845 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
6847 *dptr1++ = *dptr2++;
6849 icb->login_retry_count = nv->login_retry_count;
6850 icb->link_down_on_nos = nv->link_down_on_nos;
6852 /* Copy 2nd segment. */
6853 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
6854 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
6855 cnt = (uint8_t *)&icb->reserved_3 -
6856 (uint8_t *)&icb->interrupt_delay_timer;
6858 *dptr1++ = *dptr2++;
6861 * Setup driver NVRAM options.
6863 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
6866 qlt_24xx_config_nvram_stage2(vha, icb);
6868 if (nv->host_p & cpu_to_le32(BIT_15)) {
6869 /* Use alternate WWN? */
6870 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
6871 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
6874 /* Prepare nodename */
6875 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
6877 * Firmware will apply the following mask if the nodename was
6880 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
6881 icb->node_name[0] &= 0xF0;
6884 /* Set host adapter parameters. */
6885 ha->flags.disable_risc_code_load = 0;
6886 ha->flags.enable_lip_reset = 0;
6887 ha->flags.enable_lip_full_login =
6888 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
6889 ha->flags.enable_target_reset =
6890 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
6891 ha->flags.enable_led_scheme = 0;
6892 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
6894 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
6895 (BIT_6 | BIT_5 | BIT_4)) >> 4;
6897 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
6898 sizeof(ha->fw_seriallink_options24));
6900 /* save HBA serial number */
6901 ha->serial0 = icb->port_name[5];
6902 ha->serial1 = icb->port_name[6];
6903 ha->serial2 = icb->port_name[7];
6904 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
6905 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
6907 icb->execution_throttle = cpu_to_le16(0xFFFF);
6909 ha->retry_count = le16_to_cpu(nv->login_retry_count);
6911 /* Set minimum login_timeout to 4 seconds. */
6912 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
6913 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
6914 if (le16_to_cpu(nv->login_timeout) < 4)
6915 nv->login_timeout = cpu_to_le16(4);
6916 ha->login_timeout = le16_to_cpu(nv->login_timeout);
6918 /* Set minimum RATOV to 100 tenths of a second. */
6921 ha->loop_reset_delay = nv->reset_delay;
6923 /* Link Down Timeout = 0:
6925 * When Port Down timer expires we will start returning
6926 * I/O's to OS with "DID_NO_CONNECT".
6928 * Link Down Timeout != 0:
6930 * The driver waits for the link to come up after link down
6931 * before returning I/Os to OS with "DID_NO_CONNECT".
6933 if (le16_to_cpu(nv->link_down_timeout) == 0) {
6934 ha->loop_down_abort_time =
6935 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
6937 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
6938 ha->loop_down_abort_time =
6939 (LOOP_DOWN_TIME - ha->link_down_timeout);
6942 /* Need enough time to try and get the port back. */
6943 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
6944 if (qlport_down_retry)
6945 ha->port_down_retry_count = qlport_down_retry;
6947 /* Set login_retry_count */
6948 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
6949 if (ha->port_down_retry_count ==
6950 le16_to_cpu(nv->port_down_retry_count) &&
6951 ha->port_down_retry_count > 3)
6952 ha->login_retry_count = ha->port_down_retry_count;
6953 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
6954 ha->login_retry_count = ha->port_down_retry_count;
6955 if (ql2xloginretrycount)
6956 ha->login_retry_count = ql2xloginretrycount;
6959 if (!vha->flags.init_done) {
6960 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
6961 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
6962 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
6963 le16_to_cpu(icb->interrupt_delay_timer): 2;
6965 icb->firmware_options_2 &= cpu_to_le32(
6966 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
6967 vha->flags.process_response_queue = 0;
6968 if (ha->zio_mode != QLA_ZIO_DISABLED) {
6969 ha->zio_mode = QLA_ZIO_MODE_6;
6971 ql_log(ql_log_info, vha, 0x006f,
6972 "ZIO mode %d enabled; timer delay (%d us).\n",
6973 ha->zio_mode, ha->zio_timer * 100);
6975 icb->firmware_options_2 |= cpu_to_le32(
6976 (uint32_t)ha->zio_mode);
6977 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
6978 vha->flags.process_response_queue = 1;
6982 ql_log(ql_log_warn, vha, 0x0070,
6983 "NVRAM configuration failed.\n");
6988 uint8_t qla27xx_find_valid_image(struct scsi_qla_host *vha)
6990 struct qla27xx_image_status pri_image_status, sec_image_status;
6991 uint8_t valid_pri_image, valid_sec_image;
6993 uint32_t cnt, chksum, size;
6994 struct qla_hw_data *ha = vha->hw;
6996 valid_pri_image = valid_sec_image = 1;
6997 ha->active_image = 0;
6998 size = sizeof(struct qla27xx_image_status) / sizeof(uint32_t);
7000 if (!ha->flt_region_img_status_pri) {
7001 valid_pri_image = 0;
7002 goto check_sec_image;
7005 qla24xx_read_flash_data(vha, (uint32_t *)(&pri_image_status),
7006 ha->flt_region_img_status_pri, size);
7008 if (pri_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7009 ql_dbg(ql_dbg_init, vha, 0x018b,
7010 "Primary image signature (0x%x) not valid\n",
7011 pri_image_status.signature);
7012 valid_pri_image = 0;
7013 goto check_sec_image;
7016 wptr = (uint32_t *)(&pri_image_status);
7019 for (chksum = 0; cnt--; wptr++)
7020 chksum += le32_to_cpu(*wptr);
7023 ql_dbg(ql_dbg_init, vha, 0x018c,
7024 "Checksum validation failed for primary image (0x%x)\n",
7026 valid_pri_image = 0;
7030 if (!ha->flt_region_img_status_sec) {
7031 valid_sec_image = 0;
7032 goto check_valid_image;
7035 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7036 ha->flt_region_img_status_sec, size);
7038 if (sec_image_status.signature != QLA27XX_IMG_STATUS_SIGN) {
7039 ql_dbg(ql_dbg_init, vha, 0x018d,
7040 "Secondary image signature(0x%x) not valid\n",
7041 sec_image_status.signature);
7042 valid_sec_image = 0;
7043 goto check_valid_image;
7046 wptr = (uint32_t *)(&sec_image_status);
7048 for (chksum = 0; cnt--; wptr++)
7049 chksum += le32_to_cpu(*wptr);
7051 ql_dbg(ql_dbg_init, vha, 0x018e,
7052 "Checksum validation failed for secondary image (0x%x)\n",
7054 valid_sec_image = 0;
7058 if (valid_pri_image && (pri_image_status.image_status_mask & 0x1))
7059 ha->active_image = QLA27XX_PRIMARY_IMAGE;
7060 if (valid_sec_image && (sec_image_status.image_status_mask & 0x1)) {
7061 if (!ha->active_image ||
7062 pri_image_status.generation_number <
7063 sec_image_status.generation_number)
7064 ha->active_image = QLA27XX_SECONDARY_IMAGE;
7067 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x018f, "%s image\n",
7068 ha->active_image == 0 ? "default bootld and fw" :
7069 ha->active_image == 1 ? "primary" :
7070 ha->active_image == 2 ? "secondary" :
7073 return ha->active_image;
7077 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7080 int rval = QLA_SUCCESS;
7081 int segments, fragment;
7082 uint32_t *dcode, dlen;
7086 struct qla_hw_data *ha = vha->hw;
7087 struct req_que *req = ha->req_q_map[0];
7089 ql_dbg(ql_dbg_init, vha, 0x008b,
7090 "FW: Loading firmware from flash (%x).\n", faddr);
7094 segments = FA_RISC_CODE_SEGMENTS;
7095 dcode = (uint32_t *)req->ring;
7098 if (IS_QLA27XX(ha) &&
7099 qla27xx_find_valid_image(vha) == QLA27XX_SECONDARY_IMAGE)
7100 faddr = ha->flt_region_fw_sec;
7102 /* Validate firmware image by checking version. */
7103 qla24xx_read_flash_data(vha, dcode, faddr + 4, 4);
7104 for (i = 0; i < 4; i++)
7105 dcode[i] = be32_to_cpu(dcode[i]);
7106 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7107 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7108 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7110 ql_log(ql_log_fatal, vha, 0x008c,
7111 "Unable to verify the integrity of flash firmware "
7113 ql_log(ql_log_fatal, vha, 0x008d,
7114 "Firmware data: %08x %08x %08x %08x.\n",
7115 dcode[0], dcode[1], dcode[2], dcode[3]);
7117 return QLA_FUNCTION_FAILED;
7120 while (segments && rval == QLA_SUCCESS) {
7121 /* Read segment's load information. */
7122 qla24xx_read_flash_data(vha, dcode, faddr, 4);
7124 risc_addr = be32_to_cpu(dcode[2]);
7125 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7126 risc_size = be32_to_cpu(dcode[3]);
7129 while (risc_size > 0 && rval == QLA_SUCCESS) {
7130 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7131 if (dlen > risc_size)
7134 ql_dbg(ql_dbg_init, vha, 0x008e,
7135 "Loading risc segment@ risc addr %x "
7136 "number of dwords 0x%x offset 0x%x.\n",
7137 risc_addr, dlen, faddr);
7139 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7140 for (i = 0; i < dlen; i++)
7141 dcode[i] = swab32(dcode[i]);
7143 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7146 ql_log(ql_log_fatal, vha, 0x008f,
7147 "Failed to load segment %d of firmware.\n",
7149 return QLA_FUNCTION_FAILED;
7162 if (!IS_QLA27XX(ha))
7165 if (ha->fw_dump_template)
7166 vfree(ha->fw_dump_template);
7167 ha->fw_dump_template = NULL;
7168 ha->fw_dump_template_len = 0;
7170 ql_dbg(ql_dbg_init, vha, 0x0161,
7171 "Loading fwdump template from %x\n", faddr);
7172 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7173 risc_size = be32_to_cpu(dcode[2]);
7174 ql_dbg(ql_dbg_init, vha, 0x0162,
7175 "-> array size %x dwords\n", risc_size);
7176 if (risc_size == 0 || risc_size == ~0)
7177 goto default_template;
7179 dlen = (risc_size - 8) * sizeof(*dcode);
7180 ql_dbg(ql_dbg_init, vha, 0x0163,
7181 "-> template allocating %x bytes...\n", dlen);
7182 ha->fw_dump_template = vmalloc(dlen);
7183 if (!ha->fw_dump_template) {
7184 ql_log(ql_log_warn, vha, 0x0164,
7185 "Failed fwdump template allocate %x bytes.\n", risc_size);
7186 goto default_template;
7191 dcode = ha->fw_dump_template;
7192 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7193 for (i = 0; i < risc_size; i++)
7194 dcode[i] = le32_to_cpu(dcode[i]);
7196 if (!qla27xx_fwdt_template_valid(dcode)) {
7197 ql_log(ql_log_warn, vha, 0x0165,
7198 "Failed fwdump template validate\n");
7199 goto default_template;
7202 dlen = qla27xx_fwdt_template_size(dcode);
7203 ql_dbg(ql_dbg_init, vha, 0x0166,
7204 "-> template size %x bytes\n", dlen);
7205 if (dlen > risc_size * sizeof(*dcode)) {
7206 ql_log(ql_log_warn, vha, 0x0167,
7207 "Failed fwdump template exceeds array by %zx bytes\n",
7208 (size_t)(dlen - risc_size * sizeof(*dcode)));
7209 goto default_template;
7211 ha->fw_dump_template_len = dlen;
7215 ql_log(ql_log_warn, vha, 0x0168, "Using default fwdump template\n");
7216 if (ha->fw_dump_template)
7217 vfree(ha->fw_dump_template);
7218 ha->fw_dump_template = NULL;
7219 ha->fw_dump_template_len = 0;
7221 dlen = qla27xx_fwdt_template_default_size();
7222 ql_dbg(ql_dbg_init, vha, 0x0169,
7223 "-> template allocating %x bytes...\n", dlen);
7224 ha->fw_dump_template = vmalloc(dlen);
7225 if (!ha->fw_dump_template) {
7226 ql_log(ql_log_warn, vha, 0x016a,
7227 "Failed fwdump template allocate %x bytes.\n", risc_size);
7228 goto failed_template;
7231 dcode = ha->fw_dump_template;
7232 risc_size = dlen / sizeof(*dcode);
7233 memcpy(dcode, qla27xx_fwdt_template_default(), dlen);
7234 for (i = 0; i < risc_size; i++)
7235 dcode[i] = be32_to_cpu(dcode[i]);
7237 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7238 ql_log(ql_log_warn, vha, 0x016b,
7239 "Failed fwdump template validate\n");
7240 goto failed_template;
7243 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7244 ql_dbg(ql_dbg_init, vha, 0x016c,
7245 "-> template size %x bytes\n", dlen);
7246 ha->fw_dump_template_len = dlen;
7250 ql_log(ql_log_warn, vha, 0x016d, "Failed default fwdump template\n");
7251 if (ha->fw_dump_template)
7252 vfree(ha->fw_dump_template);
7253 ha->fw_dump_template = NULL;
7254 ha->fw_dump_template_len = 0;
7258 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7261 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7265 uint16_t *wcode, *fwcode;
7266 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7267 struct fw_blob *blob;
7268 struct qla_hw_data *ha = vha->hw;
7269 struct req_que *req = ha->req_q_map[0];
7271 /* Load firmware blob. */
7272 blob = qla2x00_request_firmware(vha);
7274 ql_log(ql_log_info, vha, 0x0083,
7275 "Firmware image unavailable.\n");
7276 ql_log(ql_log_info, vha, 0x0084,
7277 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7278 return QLA_FUNCTION_FAILED;
7283 wcode = (uint16_t *)req->ring;
7285 fwcode = (uint16_t *)blob->fw->data;
7288 /* Validate firmware image by checking version. */
7289 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7290 ql_log(ql_log_fatal, vha, 0x0085,
7291 "Unable to verify integrity of firmware image (%zd).\n",
7293 goto fail_fw_integrity;
7295 for (i = 0; i < 4; i++)
7296 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7297 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7298 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7299 wcode[2] == 0 && wcode[3] == 0)) {
7300 ql_log(ql_log_fatal, vha, 0x0086,
7301 "Unable to verify integrity of firmware image.\n");
7302 ql_log(ql_log_fatal, vha, 0x0087,
7303 "Firmware data: %04x %04x %04x %04x.\n",
7304 wcode[0], wcode[1], wcode[2], wcode[3]);
7305 goto fail_fw_integrity;
7309 while (*seg && rval == QLA_SUCCESS) {
7311 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7312 risc_size = be16_to_cpu(fwcode[3]);
7314 /* Validate firmware image size. */
7315 fwclen += risc_size * sizeof(uint16_t);
7316 if (blob->fw->size < fwclen) {
7317 ql_log(ql_log_fatal, vha, 0x0088,
7318 "Unable to verify integrity of firmware image "
7319 "(%zd).\n", blob->fw->size);
7320 goto fail_fw_integrity;
7324 while (risc_size > 0 && rval == QLA_SUCCESS) {
7325 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7326 if (wlen > risc_size)
7328 ql_dbg(ql_dbg_init, vha, 0x0089,
7329 "Loading risc segment@ risc addr %x number of "
7330 "words 0x%x.\n", risc_addr, wlen);
7332 for (i = 0; i < wlen; i++)
7333 wcode[i] = swab16(fwcode[i]);
7335 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7338 ql_log(ql_log_fatal, vha, 0x008a,
7339 "Failed to load segment %d of firmware.\n",
7356 return QLA_FUNCTION_FAILED;
7360 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7363 int segments, fragment;
7364 uint32_t *dcode, dlen;
7368 struct fw_blob *blob;
7369 const uint32_t *fwcode;
7371 struct qla_hw_data *ha = vha->hw;
7372 struct req_que *req = ha->req_q_map[0];
7374 /* Load firmware blob. */
7375 blob = qla2x00_request_firmware(vha);
7377 ql_log(ql_log_warn, vha, 0x0090,
7378 "Firmware image unavailable.\n");
7379 ql_log(ql_log_warn, vha, 0x0091,
7380 "Firmware images can be retrieved from: "
7383 return QLA_FUNCTION_FAILED;
7386 ql_dbg(ql_dbg_init, vha, 0x0092,
7387 "FW: Loading via request-firmware.\n");
7391 segments = FA_RISC_CODE_SEGMENTS;
7392 dcode = (uint32_t *)req->ring;
7394 fwcode = (uint32_t *)blob->fw->data;
7397 /* Validate firmware image by checking version. */
7398 if (blob->fw->size < 8 * sizeof(uint32_t)) {
7399 ql_log(ql_log_fatal, vha, 0x0093,
7400 "Unable to verify integrity of firmware image (%zd).\n",
7402 return QLA_FUNCTION_FAILED;
7404 for (i = 0; i < 4; i++)
7405 dcode[i] = be32_to_cpu(fwcode[i + 4]);
7406 if ((dcode[0] == 0xffffffff && dcode[1] == 0xffffffff &&
7407 dcode[2] == 0xffffffff && dcode[3] == 0xffffffff) ||
7408 (dcode[0] == 0 && dcode[1] == 0 && dcode[2] == 0 &&
7410 ql_log(ql_log_fatal, vha, 0x0094,
7411 "Unable to verify integrity of firmware image (%zd).\n",
7413 ql_log(ql_log_fatal, vha, 0x0095,
7414 "Firmware data: %08x %08x %08x %08x.\n",
7415 dcode[0], dcode[1], dcode[2], dcode[3]);
7416 return QLA_FUNCTION_FAILED;
7419 while (segments && rval == QLA_SUCCESS) {
7420 risc_addr = be32_to_cpu(fwcode[2]);
7421 *srisc_addr = *srisc_addr == 0 ? risc_addr : *srisc_addr;
7422 risc_size = be32_to_cpu(fwcode[3]);
7424 /* Validate firmware image size. */
7425 fwclen += risc_size * sizeof(uint32_t);
7426 if (blob->fw->size < fwclen) {
7427 ql_log(ql_log_fatal, vha, 0x0096,
7428 "Unable to verify integrity of firmware image "
7429 "(%zd).\n", blob->fw->size);
7430 return QLA_FUNCTION_FAILED;
7434 while (risc_size > 0 && rval == QLA_SUCCESS) {
7435 dlen = (uint32_t)(ha->fw_transfer_size >> 2);
7436 if (dlen > risc_size)
7439 ql_dbg(ql_dbg_init, vha, 0x0097,
7440 "Loading risc segment@ risc addr %x "
7441 "number of dwords 0x%x.\n", risc_addr, dlen);
7443 for (i = 0; i < dlen; i++)
7444 dcode[i] = swab32(fwcode[i]);
7446 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7449 ql_log(ql_log_fatal, vha, 0x0098,
7450 "Failed to load segment %d of firmware.\n",
7452 return QLA_FUNCTION_FAILED;
7465 if (!IS_QLA27XX(ha))
7468 if (ha->fw_dump_template)
7469 vfree(ha->fw_dump_template);
7470 ha->fw_dump_template = NULL;
7471 ha->fw_dump_template_len = 0;
7473 ql_dbg(ql_dbg_init, vha, 0x171,
7474 "Loading fwdump template from %x\n",
7475 (uint32_t)((void *)fwcode - (void *)blob->fw->data));
7476 risc_size = be32_to_cpu(fwcode[2]);
7477 ql_dbg(ql_dbg_init, vha, 0x172,
7478 "-> array size %x dwords\n", risc_size);
7479 if (risc_size == 0 || risc_size == ~0)
7480 goto default_template;
7482 dlen = (risc_size - 8) * sizeof(*fwcode);
7483 ql_dbg(ql_dbg_init, vha, 0x0173,
7484 "-> template allocating %x bytes...\n", dlen);
7485 ha->fw_dump_template = vmalloc(dlen);
7486 if (!ha->fw_dump_template) {
7487 ql_log(ql_log_warn, vha, 0x0174,
7488 "Failed fwdump template allocate %x bytes.\n", risc_size);
7489 goto default_template;
7494 dcode = ha->fw_dump_template;
7495 for (i = 0; i < risc_size; i++)
7496 dcode[i] = le32_to_cpu(fwcode[i]);
7498 if (!qla27xx_fwdt_template_valid(dcode)) {
7499 ql_log(ql_log_warn, vha, 0x0175,
7500 "Failed fwdump template validate\n");
7501 goto default_template;
7504 dlen = qla27xx_fwdt_template_size(dcode);
7505 ql_dbg(ql_dbg_init, vha, 0x0176,
7506 "-> template size %x bytes\n", dlen);
7507 if (dlen > risc_size * sizeof(*fwcode)) {
7508 ql_log(ql_log_warn, vha, 0x0177,
7509 "Failed fwdump template exceeds array by %zx bytes\n",
7510 (size_t)(dlen - risc_size * sizeof(*fwcode)));
7511 goto default_template;
7513 ha->fw_dump_template_len = dlen;
7517 ql_log(ql_log_warn, vha, 0x0178, "Using default fwdump template\n");
7518 if (ha->fw_dump_template)
7519 vfree(ha->fw_dump_template);
7520 ha->fw_dump_template = NULL;
7521 ha->fw_dump_template_len = 0;
7523 dlen = qla27xx_fwdt_template_default_size();
7524 ql_dbg(ql_dbg_init, vha, 0x0179,
7525 "-> template allocating %x bytes...\n", dlen);
7526 ha->fw_dump_template = vmalloc(dlen);
7527 if (!ha->fw_dump_template) {
7528 ql_log(ql_log_warn, vha, 0x017a,
7529 "Failed fwdump template allocate %x bytes.\n", risc_size);
7530 goto failed_template;
7533 dcode = ha->fw_dump_template;
7534 risc_size = dlen / sizeof(*fwcode);
7535 fwcode = qla27xx_fwdt_template_default();
7536 for (i = 0; i < risc_size; i++)
7537 dcode[i] = be32_to_cpu(fwcode[i]);
7539 if (!qla27xx_fwdt_template_valid(ha->fw_dump_template)) {
7540 ql_log(ql_log_warn, vha, 0x017b,
7541 "Failed fwdump template validate\n");
7542 goto failed_template;
7545 dlen = qla27xx_fwdt_template_size(ha->fw_dump_template);
7546 ql_dbg(ql_dbg_init, vha, 0x017c,
7547 "-> template size %x bytes\n", dlen);
7548 ha->fw_dump_template_len = dlen;
7552 ql_log(ql_log_warn, vha, 0x017d, "Failed default fwdump template\n");
7553 if (ha->fw_dump_template)
7554 vfree(ha->fw_dump_template);
7555 ha->fw_dump_template = NULL;
7556 ha->fw_dump_template_len = 0;
7561 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7565 if (ql2xfwloadbin == 1)
7566 return qla81xx_load_risc(vha, srisc_addr);
7570 * 1) Firmware via request-firmware interface (.bin file).
7571 * 2) Firmware residing in flash.
7573 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7574 if (rval == QLA_SUCCESS)
7577 return qla24xx_load_risc_flash(vha, srisc_addr,
7578 vha->hw->flt_region_fw);
7582 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7585 struct qla_hw_data *ha = vha->hw;
7587 if (ql2xfwloadbin == 2)
7592 * 1) Firmware residing in flash.
7593 * 2) Firmware via request-firmware interface (.bin file).
7594 * 3) Golden-Firmware residing in flash -- limited operation.
7596 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
7597 if (rval == QLA_SUCCESS)
7601 rval = qla24xx_load_risc_blob(vha, srisc_addr);
7602 if (rval == QLA_SUCCESS || !ha->flt_region_gold_fw)
7605 ql_log(ql_log_info, vha, 0x0099,
7606 "Attempting to fallback to golden firmware.\n");
7607 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
7608 if (rval != QLA_SUCCESS)
7611 ql_log(ql_log_info, vha, 0x009a, "Update operational firmware.\n");
7612 ha->flags.running_gold_fw = 1;
7617 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
7620 struct qla_hw_data *ha = vha->hw;
7622 if (ha->flags.pci_channel_io_perm_failure)
7624 if (!IS_FWI2_CAPABLE(ha))
7626 if (!ha->fw_major_version)
7628 if (!ha->flags.fw_started)
7631 ret = qla2x00_stop_firmware(vha);
7632 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
7633 ret != QLA_INVALID_COMMAND && retries ; retries--) {
7634 ha->isp_ops->reset_chip(vha);
7635 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
7637 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
7639 ql_log(ql_log_info, vha, 0x8015,
7640 "Attempting retry of stop-firmware command.\n");
7641 ret = qla2x00_stop_firmware(vha);
7645 ha->flags.fw_init_done = 0;
7649 qla24xx_configure_vhba(scsi_qla_host_t *vha)
7651 int rval = QLA_SUCCESS;
7653 uint16_t mb[MAILBOX_REGISTER_COUNT];
7654 struct qla_hw_data *ha = vha->hw;
7655 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
7656 struct req_que *req;
7657 struct rsp_que *rsp;
7662 rval = qla2x00_fw_ready(base_vha);
7664 req = vha->qpair->req;
7666 req = ha->req_q_map[0];
7669 if (rval == QLA_SUCCESS) {
7670 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
7671 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
7674 vha->flags.management_server_logged_in = 0;
7676 /* Login to SNS first */
7677 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
7679 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
7680 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
7681 ql_dbg(ql_dbg_init, vha, 0x0120,
7682 "Failed SNS login: loop_id=%x, rval2=%d\n",
7685 ql_dbg(ql_dbg_init, vha, 0x0103,
7686 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
7687 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
7688 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
7689 return (QLA_FUNCTION_FAILED);
7692 atomic_set(&vha->loop_down_timer, 0);
7693 atomic_set(&vha->loop_state, LOOP_UP);
7694 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
7695 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
7696 rval = qla2x00_loop_resync(base_vha);
7701 /* 84XX Support **************************************************************/
7703 static LIST_HEAD(qla_cs84xx_list);
7704 static DEFINE_MUTEX(qla_cs84xx_mutex);
7706 static struct qla_chip_state_84xx *
7707 qla84xx_get_chip(struct scsi_qla_host *vha)
7709 struct qla_chip_state_84xx *cs84xx;
7710 struct qla_hw_data *ha = vha->hw;
7712 mutex_lock(&qla_cs84xx_mutex);
7714 /* Find any shared 84xx chip. */
7715 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
7716 if (cs84xx->bus == ha->pdev->bus) {
7717 kref_get(&cs84xx->kref);
7722 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
7726 kref_init(&cs84xx->kref);
7727 spin_lock_init(&cs84xx->access_lock);
7728 mutex_init(&cs84xx->fw_update_mutex);
7729 cs84xx->bus = ha->pdev->bus;
7731 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
7733 mutex_unlock(&qla_cs84xx_mutex);
7738 __qla84xx_chip_release(struct kref *kref)
7740 struct qla_chip_state_84xx *cs84xx =
7741 container_of(kref, struct qla_chip_state_84xx, kref);
7743 mutex_lock(&qla_cs84xx_mutex);
7744 list_del(&cs84xx->list);
7745 mutex_unlock(&qla_cs84xx_mutex);
7750 qla84xx_put_chip(struct scsi_qla_host *vha)
7752 struct qla_hw_data *ha = vha->hw;
7754 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
7758 qla84xx_init_chip(scsi_qla_host_t *vha)
7762 struct qla_hw_data *ha = vha->hw;
7764 mutex_lock(&ha->cs84xx->fw_update_mutex);
7766 rval = qla84xx_verify_chip(vha, status);
7768 mutex_unlock(&ha->cs84xx->fw_update_mutex);
7770 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED:
7774 /* 81XX Support **************************************************************/
7777 qla81xx_nvram_config(scsi_qla_host_t *vha)
7780 struct init_cb_81xx *icb;
7781 struct nvram_81xx *nv;
7783 uint8_t *dptr1, *dptr2;
7786 struct qla_hw_data *ha = vha->hw;
7789 icb = (struct init_cb_81xx *)ha->init_cb;
7792 /* Determine NVRAM starting address. */
7793 ha->nvram_size = sizeof(struct nvram_81xx);
7794 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7795 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
7796 ha->vpd_size = FA_VPD_SIZE_82XX;
7798 /* Get VPD data into cache */
7799 ha->vpd = ha->nvram + VPD_OFFSET;
7800 ha->isp_ops->read_optrom(vha, ha->vpd, ha->flt_region_vpd << 2,
7803 /* Get NVRAM data into cache and calculate checksum. */
7804 ha->isp_ops->read_optrom(vha, ha->nvram, ha->flt_region_nvram << 2,
7806 dptr = (uint32_t *)nv;
7807 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7808 chksum += le32_to_cpu(*dptr);
7810 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
7811 "Contents of NVRAM:\n");
7812 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
7813 (uint8_t *)nv, ha->nvram_size);
7815 /* Bad NVRAM data, set defaults parameters. */
7816 if (chksum || nv->id[0] != 'I' || nv->id[1] != 'S' || nv->id[2] != 'P'
7817 || nv->id[3] != ' ' ||
7818 nv->nvram_version < cpu_to_le16(ICB_VERSION)) {
7819 /* Reset NVRAM data. */
7820 ql_log(ql_log_info, vha, 0x0073,
7821 "Inconsistent NVRAM detected: checksum=0x%x id=%c "
7822 "version=0x%x.\n", chksum, nv->id[0],
7823 le16_to_cpu(nv->nvram_version));
7824 ql_log(ql_log_info, vha, 0x0074,
7825 "Falling back to functioning (yet invalid -- WWPN) "
7829 * Set default initialization control block.
7831 memset(nv, 0, ha->nvram_size);
7832 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7833 nv->version = cpu_to_le16(ICB_VERSION);
7834 nv->frame_payload_size = 2048;
7835 nv->execution_throttle = cpu_to_le16(0xFFFF);
7836 nv->exchange_count = cpu_to_le16(0);
7837 nv->port_name[0] = 0x21;
7838 nv->port_name[1] = 0x00 + ha->port_no + 1;
7839 nv->port_name[2] = 0x00;
7840 nv->port_name[3] = 0xe0;
7841 nv->port_name[4] = 0x8b;
7842 nv->port_name[5] = 0x1c;
7843 nv->port_name[6] = 0x55;
7844 nv->port_name[7] = 0x86;
7845 nv->node_name[0] = 0x20;
7846 nv->node_name[1] = 0x00;
7847 nv->node_name[2] = 0x00;
7848 nv->node_name[3] = 0xe0;
7849 nv->node_name[4] = 0x8b;
7850 nv->node_name[5] = 0x1c;
7851 nv->node_name[6] = 0x55;
7852 nv->node_name[7] = 0x86;
7853 nv->login_retry_count = cpu_to_le16(8);
7854 nv->interrupt_delay_timer = cpu_to_le16(0);
7855 nv->login_timeout = cpu_to_le16(0);
7856 nv->firmware_options_1 =
7857 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7858 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7859 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7860 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7861 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7862 nv->efi_parameters = cpu_to_le32(0);
7863 nv->reset_delay = 5;
7864 nv->max_luns_per_target = cpu_to_le16(128);
7865 nv->port_down_retry_count = cpu_to_le16(30);
7866 nv->link_down_timeout = cpu_to_le16(180);
7867 nv->enode_mac[0] = 0x00;
7868 nv->enode_mac[1] = 0xC0;
7869 nv->enode_mac[2] = 0xDD;
7870 nv->enode_mac[3] = 0x04;
7871 nv->enode_mac[4] = 0x05;
7872 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
7877 if (IS_T10_PI_CAPABLE(ha))
7878 nv->frame_payload_size &= ~7;
7880 qlt_81xx_config_nvram_stage1(vha, nv);
7882 /* Reset Initialization control block */
7883 memset(icb, 0, ha->init_cb_size);
7885 /* Copy 1st segment. */
7886 dptr1 = (uint8_t *)icb;
7887 dptr2 = (uint8_t *)&nv->version;
7888 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7890 *dptr1++ = *dptr2++;
7892 icb->login_retry_count = nv->login_retry_count;
7894 /* Copy 2nd segment. */
7895 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7896 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7897 cnt = (uint8_t *)&icb->reserved_5 -
7898 (uint8_t *)&icb->interrupt_delay_timer;
7900 *dptr1++ = *dptr2++;
7902 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
7903 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
7904 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
7905 icb->enode_mac[0] = 0x00;
7906 icb->enode_mac[1] = 0xC0;
7907 icb->enode_mac[2] = 0xDD;
7908 icb->enode_mac[3] = 0x04;
7909 icb->enode_mac[4] = 0x05;
7910 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
7913 /* Use extended-initialization control block. */
7914 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
7917 * Setup driver NVRAM options.
7919 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7922 qlt_81xx_config_nvram_stage2(vha, icb);
7924 /* Use alternate WWN? */
7925 if (nv->host_p & cpu_to_le32(BIT_15)) {
7926 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7927 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7930 /* Prepare nodename */
7931 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7933 * Firmware will apply the following mask if the nodename was
7936 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7937 icb->node_name[0] &= 0xF0;
7940 /* Set host adapter parameters. */
7941 ha->flags.disable_risc_code_load = 0;
7942 ha->flags.enable_lip_reset = 0;
7943 ha->flags.enable_lip_full_login =
7944 le32_to_cpu(nv->host_p) & BIT_10 ? 1: 0;
7945 ha->flags.enable_target_reset =
7946 le32_to_cpu(nv->host_p) & BIT_11 ? 1: 0;
7947 ha->flags.enable_led_scheme = 0;
7948 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1: 0;
7950 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7951 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7953 /* save HBA serial number */
7954 ha->serial0 = icb->port_name[5];
7955 ha->serial1 = icb->port_name[6];
7956 ha->serial2 = icb->port_name[7];
7957 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7958 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7960 icb->execution_throttle = cpu_to_le16(0xFFFF);
7962 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7964 /* Set minimum login_timeout to 4 seconds. */
7965 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7966 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7967 if (le16_to_cpu(nv->login_timeout) < 4)
7968 nv->login_timeout = cpu_to_le16(4);
7969 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7971 /* Set minimum RATOV to 100 tenths of a second. */
7974 ha->loop_reset_delay = nv->reset_delay;
7976 /* Link Down Timeout = 0:
7978 * When Port Down timer expires we will start returning
7979 * I/O's to OS with "DID_NO_CONNECT".
7981 * Link Down Timeout != 0:
7983 * The driver waits for the link to come up after link down
7984 * before returning I/Os to OS with "DID_NO_CONNECT".
7986 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7987 ha->loop_down_abort_time =
7988 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7990 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7991 ha->loop_down_abort_time =
7992 (LOOP_DOWN_TIME - ha->link_down_timeout);
7995 /* Need enough time to try and get the port back. */
7996 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7997 if (qlport_down_retry)
7998 ha->port_down_retry_count = qlport_down_retry;
8000 /* Set login_retry_count */
8001 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8002 if (ha->port_down_retry_count ==
8003 le16_to_cpu(nv->port_down_retry_count) &&
8004 ha->port_down_retry_count > 3)
8005 ha->login_retry_count = ha->port_down_retry_count;
8006 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8007 ha->login_retry_count = ha->port_down_retry_count;
8008 if (ql2xloginretrycount)
8009 ha->login_retry_count = ql2xloginretrycount;
8011 /* if not running MSI-X we need handshaking on interrupts */
8012 if (!vha->hw->flags.msix_enabled && (IS_QLA83XX(ha) || IS_QLA27XX(ha)))
8013 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8016 if (!vha->flags.init_done) {
8017 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8018 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8019 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8020 le16_to_cpu(icb->interrupt_delay_timer): 2;
8022 icb->firmware_options_2 &= cpu_to_le32(
8023 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8024 vha->flags.process_response_queue = 0;
8025 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8026 ha->zio_mode = QLA_ZIO_MODE_6;
8028 ql_log(ql_log_info, vha, 0x0075,
8029 "ZIO mode %d enabled; timer delay (%d us).\n",
8031 ha->zio_timer * 100);
8033 icb->firmware_options_2 |= cpu_to_le32(
8034 (uint32_t)ha->zio_mode);
8035 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8036 vha->flags.process_response_queue = 1;
8039 /* enable RIDA Format2 */
8040 icb->firmware_options_3 |= BIT_0;
8042 if (IS_QLA27XX(ha)) {
8043 icb->firmware_options_3 |= BIT_8;
8044 ql_dbg(ql_log_info, vha, 0x0075,
8045 "Enabling direct connection.\n");
8049 ql_log(ql_log_warn, vha, 0x0076,
8050 "NVRAM configuration failed.\n");
8056 qla82xx_restart_isp(scsi_qla_host_t *vha)
8059 struct qla_hw_data *ha = vha->hw;
8060 struct req_que *req = ha->req_q_map[0];
8061 struct rsp_que *rsp = ha->rsp_q_map[0];
8062 struct scsi_qla_host *vp;
8063 unsigned long flags;
8065 status = qla2x00_init_rings(vha);
8067 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8068 ha->flags.chip_reset_done = 1;
8070 status = qla2x00_fw_ready(vha);
8072 /* Issue a marker after FW becomes ready. */
8073 qla2x00_marker(vha, req, rsp, 0, 0, MK_SYNC_ALL);
8074 vha->flags.online = 1;
8075 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8078 /* if no cable then assume it's good */
8079 if ((vha->device_flags & DFLG_NO_CABLE))
8084 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8086 if (!atomic_read(&vha->loop_down_timer)) {
8088 * Issue marker command only when we are going
8089 * to start the I/O .
8091 vha->marker_needed = 1;
8094 ha->isp_ops->enable_intrs(ha);
8096 ha->isp_abort_cnt = 0;
8097 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8099 /* Update the firmware version */
8100 status = qla82xx_check_md_needed(vha);
8103 ha->flags.fce_enabled = 1;
8105 fce_calc_size(ha->fce_bufs));
8106 rval = qla2x00_enable_fce_trace(vha,
8107 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8110 ql_log(ql_log_warn, vha, 0x8001,
8111 "Unable to reinitialize FCE (%d).\n",
8113 ha->flags.fce_enabled = 0;
8118 memset(ha->eft, 0, EFT_SIZE);
8119 rval = qla2x00_enable_eft_trace(vha,
8120 ha->eft_dma, EFT_NUM_BUFFERS);
8122 ql_log(ql_log_warn, vha, 0x8010,
8123 "Unable to reinitialize EFT (%d).\n",
8130 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8131 "qla82xx_restart_isp succeeded.\n");
8133 spin_lock_irqsave(&ha->vport_slock, flags);
8134 list_for_each_entry(vp, &ha->vp_list, list) {
8136 atomic_inc(&vp->vref_count);
8137 spin_unlock_irqrestore(&ha->vport_slock, flags);
8139 qla2x00_vp_abort_isp(vp);
8141 spin_lock_irqsave(&ha->vport_slock, flags);
8142 atomic_dec(&vp->vref_count);
8145 spin_unlock_irqrestore(&ha->vport_slock, flags);
8148 ql_log(ql_log_warn, vha, 0x8016,
8149 "qla82xx_restart_isp **** FAILED ****.\n");
8156 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8158 struct qla_hw_data *ha = vha->hw;
8160 /* Hold status IOCBs until ABTS response received. */
8162 ha->fw_options[3] |= BIT_12;
8164 /* Set Retry FLOGI in case of P2P connection */
8165 if (ha->operating_mode == P2P) {
8166 ha->fw_options[2] |= BIT_3;
8167 ql_dbg(ql_dbg_disc, vha, 0x2103,
8168 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8169 __func__, ha->fw_options[2]);
8172 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8173 if (ql2xmvasynctoatio) {
8174 if (qla_tgt_mode_enabled(vha) ||
8175 qla_dual_mode_enabled(vha))
8176 ha->fw_options[2] |= BIT_11;
8178 ha->fw_options[2] &= ~BIT_11;
8181 if (qla_tgt_mode_enabled(vha) ||
8182 qla_dual_mode_enabled(vha)) {
8183 /* FW auto send SCSI status during */
8184 ha->fw_options[1] |= BIT_8;
8185 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8187 /* FW perform Exchange validation */
8188 ha->fw_options[2] |= BIT_4;
8190 ha->fw_options[1] &= ~BIT_8;
8191 ha->fw_options[10] &= 0x00ff;
8193 ha->fw_options[2] &= ~BIT_4;
8196 if (ql2xetsenable) {
8197 /* Enable ETS Burst. */
8198 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8199 ha->fw_options[2] |= BIT_9;
8202 ql_dbg(ql_dbg_init, vha, 0x00e9,
8203 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8204 __func__, ha->fw_options[1], ha->fw_options[2],
8205 ha->fw_options[3], vha->host->active_mode);
8207 qla2x00_set_fw_options(vha, ha->fw_options);
8211 * qla24xx_get_fcp_prio
8212 * Gets the fcp cmd priority value for the logged in port.
8213 * Looks for a match of the port descriptors within
8214 * each of the fcp prio config entries. If a match is found,
8215 * the tag (priority) value is returned.
8218 * vha = scsi host structure pointer.
8219 * fcport = port structure pointer.
8222 * non-zero (if found)
8229 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8232 uint8_t pid_match, wwn_match;
8234 uint32_t pid1, pid2;
8235 uint64_t wwn1, wwn2;
8236 struct qla_fcp_prio_entry *pri_entry;
8237 struct qla_hw_data *ha = vha->hw;
8239 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8243 entries = ha->fcp_prio_cfg->num_entries;
8244 pri_entry = &ha->fcp_prio_cfg->entry[0];
8246 for (i = 0; i < entries; i++) {
8247 pid_match = wwn_match = 0;
8249 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8254 /* check source pid for a match */
8255 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8256 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8257 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8258 if (pid1 == INVALID_PORT_ID)
8260 else if (pid1 == pid2)
8264 /* check destination pid for a match */
8265 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8266 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8267 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8268 if (pid1 == INVALID_PORT_ID)
8270 else if (pid1 == pid2)
8274 /* check source WWN for a match */
8275 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8276 wwn1 = wwn_to_u64(vha->port_name);
8277 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8278 if (wwn2 == (uint64_t)-1)
8280 else if (wwn1 == wwn2)
8284 /* check destination WWN for a match */
8285 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8286 wwn1 = wwn_to_u64(fcport->port_name);
8287 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8288 if (wwn2 == (uint64_t)-1)
8290 else if (wwn1 == wwn2)
8294 if (pid_match == 2 || wwn_match == 2) {
8295 /* Found a matching entry */
8296 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8297 priority = pri_entry->tag;
8308 * qla24xx_update_fcport_fcp_prio
8309 * Activates fcp priority for the logged in fc port
8312 * vha = scsi host structure pointer.
8313 * fcp = port structure pointer.
8316 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8322 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8328 if (fcport->port_type != FCT_TARGET ||
8329 fcport->loop_id == FC_NO_LOOP_ID)
8330 return QLA_FUNCTION_FAILED;
8332 priority = qla24xx_get_fcp_prio(vha, fcport);
8334 return QLA_FUNCTION_FAILED;
8336 if (IS_P3P_TYPE(vha->hw)) {
8337 fcport->fcp_prio = priority & 0xf;
8341 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8342 if (ret == QLA_SUCCESS) {
8343 if (fcport->fcp_prio != priority)
8344 ql_dbg(ql_dbg_user, vha, 0x709e,
8345 "Updated FCP_CMND priority - value=%d loop_id=%d "
8346 "port_id=%02x%02x%02x.\n", priority,
8347 fcport->loop_id, fcport->d_id.b.domain,
8348 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8349 fcport->fcp_prio = priority & 0xf;
8351 ql_dbg(ql_dbg_user, vha, 0x704f,
8352 "Unable to update FCP_CMND priority - ret=0x%x for "
8353 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8354 fcport->d_id.b.domain, fcport->d_id.b.area,
8355 fcport->d_id.b.al_pa);
8360 * qla24xx_update_all_fcp_prio
8361 * Activates fcp priority for all the logged in ports
8364 * ha = adapter block pointer.
8367 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8373 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8378 ret = QLA_FUNCTION_FAILED;
8379 /* We need to set priority for all logged in ports */
8380 list_for_each_entry(fcport, &vha->vp_fcports, list)
8381 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8386 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8387 int vp_idx, bool startqp)
8392 struct qla_hw_data *ha = vha->hw;
8393 uint16_t qpair_id = 0;
8394 struct qla_qpair *qpair = NULL;
8395 struct qla_msix_entry *msix;
8397 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8398 ql_log(ql_log_warn, vha, 0x00181,
8399 "FW/Driver is not multi-queue capable.\n");
8403 if (ql2xmqsupport || ql2xnvmeenable) {
8404 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8405 if (qpair == NULL) {
8406 ql_log(ql_log_warn, vha, 0x0182,
8407 "Failed to allocate memory for queue pair.\n");
8410 memset(qpair, 0, sizeof(struct qla_qpair));
8412 qpair->hw = vha->hw;
8414 qpair->qp_lock_ptr = &qpair->qp_lock;
8415 spin_lock_init(&qpair->qp_lock);
8416 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8418 /* Assign available que pair id */
8419 mutex_lock(&ha->mq_lock);
8420 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8421 if (ha->num_qpairs >= ha->max_qpairs) {
8422 mutex_unlock(&ha->mq_lock);
8423 ql_log(ql_log_warn, vha, 0x0183,
8424 "No resources to create additional q pair.\n");
8428 set_bit(qpair_id, ha->qpair_qid_map);
8429 ha->queue_pair_map[qpair_id] = qpair;
8430 qpair->id = qpair_id;
8431 qpair->vp_idx = vp_idx;
8432 qpair->fw_started = ha->flags.fw_started;
8433 INIT_LIST_HEAD(&qpair->hints_list);
8434 qpair->chip_reset = ha->base_qpair->chip_reset;
8435 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8436 qpair->enable_explicit_conf =
8437 ha->base_qpair->enable_explicit_conf;
8439 for (i = 0; i < ha->msix_count; i++) {
8440 msix = &ha->msix_entries[i];
8444 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8445 "Vector %x selected for qpair\n", msix->vector);
8449 ql_log(ql_log_warn, vha, 0x0184,
8450 "Out of MSI-X vectors!.\n");
8454 qpair->msix->in_use = 1;
8455 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8456 qpair->pdev = ha->pdev;
8457 if (IS_QLA27XX(ha) || IS_QLA83XX(ha))
8458 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8460 mutex_unlock(&ha->mq_lock);
8462 /* Create response queue first */
8463 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8465 ql_log(ql_log_warn, vha, 0x0185,
8466 "Failed to create response queue.\n");
8470 qpair->rsp = ha->rsp_q_map[rsp_id];
8472 /* Create request queue */
8473 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8476 ql_log(ql_log_warn, vha, 0x0186,
8477 "Failed to create request queue.\n");
8481 qpair->req = ha->req_q_map[req_id];
8482 qpair->rsp->req = qpair->req;
8483 qpair->rsp->qpair = qpair;
8484 /* init qpair to this cpu. Will adjust at run time. */
8485 qla_cpu_update(qpair, smp_processor_id());
8487 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8488 if (ha->fw_attributes & BIT_4)
8489 qpair->difdix_supported = 1;
8492 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8493 if (!qpair->srb_mempool) {
8494 ql_log(ql_log_warn, vha, 0xd036,
8495 "Failed to create srb mempool for qpair %d\n",
8500 /* Mark as online */
8503 if (!vha->flags.qpairs_available)
8504 vha->flags.qpairs_available = 1;
8506 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
8507 "Request/Response queue pair created, id %d\n",
8509 ql_dbg(ql_dbg_init, vha, 0x0187,
8510 "Request/Response queue pair created, id %d\n",
8517 qla25xx_delete_rsp_que(vha, qpair->rsp);
8519 mutex_lock(&ha->mq_lock);
8520 qpair->msix->in_use = 0;
8521 list_del(&qpair->qp_list_elem);
8522 if (list_empty(&vha->qp_list))
8523 vha->flags.qpairs_available = 0;
8525 ha->queue_pair_map[qpair_id] = NULL;
8526 clear_bit(qpair_id, ha->qpair_qid_map);
8528 mutex_unlock(&ha->mq_lock);
8534 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
8536 int ret = QLA_FUNCTION_FAILED;
8537 struct qla_hw_data *ha = qpair->hw;
8539 qpair->delete_in_progress = 1;
8540 while (atomic_read(&qpair->ref_count))
8543 ret = qla25xx_delete_req_que(vha, qpair->req);
8544 if (ret != QLA_SUCCESS)
8547 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
8548 if (ret != QLA_SUCCESS)
8551 mutex_lock(&ha->mq_lock);
8552 ha->queue_pair_map[qpair->id] = NULL;
8553 clear_bit(qpair->id, ha->qpair_qid_map);
8555 list_del(&qpair->qp_list_elem);
8556 if (list_empty(&vha->qp_list)) {
8557 vha->flags.qpairs_available = 0;
8558 vha->flags.qpairs_req_created = 0;
8559 vha->flags.qpairs_rsp_created = 0;
8561 mempool_destroy(qpair->srb_mempool);
8563 mutex_unlock(&ha->mq_lock);