2 * QLogic Fibre Channel HBA Driver
3 * Copyright (c) 2003-2014 QLogic Corporation
5 * See LICENSE.qla2xxx for copyright and licensing details.
10 #include <linux/delay.h>
11 #include <linux/slab.h>
12 #include <linux/vmalloc.h>
14 #include "qla_devtbl.h"
20 #include <target/target_core_base.h>
21 #include "qla_target.h"
24 * QLogic ISP2x00 Hardware Support Function Prototypes.
26 static int qla2x00_isp_firmware(scsi_qla_host_t *);
27 static int qla2x00_setup_chip(scsi_qla_host_t *);
28 static int qla2x00_fw_ready(scsi_qla_host_t *);
29 static int qla2x00_configure_hba(scsi_qla_host_t *);
30 static int qla2x00_configure_loop(scsi_qla_host_t *);
31 static int qla2x00_configure_local_loop(scsi_qla_host_t *);
32 static int qla2x00_configure_fabric(scsi_qla_host_t *);
33 static int qla2x00_find_all_fabric_devs(scsi_qla_host_t *);
34 static int qla2x00_restart_isp(scsi_qla_host_t *);
36 static struct qla_chip_state_84xx *qla84xx_get_chip(struct scsi_qla_host *);
37 static int qla84xx_init_chip(scsi_qla_host_t *);
38 static int qla25xx_init_queues(struct qla_hw_data *);
39 static int qla24xx_post_prli_work(struct scsi_qla_host*, fc_port_t *);
40 static void qla24xx_handle_plogi_done_event(struct scsi_qla_host *,
42 static void qla24xx_handle_prli_done_event(struct scsi_qla_host *,
44 static void __qla24xx_handle_gpdb_event(scsi_qla_host_t *, struct event_arg *);
46 /* SRB Extensions ---------------------------------------------------------- */
49 qla2x00_sp_timeout(struct timer_list *t)
51 srb_t *sp = from_timer(sp, t, u.iocb_cmd.timer);
52 struct srb_iocb *iocb;
55 struct qla_hw_data *ha = sp->vha->hw;
57 WARN_ON_ONCE(irqs_disabled());
58 spin_lock_irqsave(&ha->hardware_lock, flags);
60 req->outstanding_cmds[sp->handle] = NULL;
61 iocb = &sp->u.iocb_cmd;
62 spin_unlock_irqrestore(&ha->hardware_lock, flags);
66 void qla2x00_sp_free(srb_t *sp)
68 struct srb_iocb *iocb = &sp->u.iocb_cmd;
70 del_timer(&iocb->timer);
74 /* Asynchronous Login/Logout Routines -------------------------------------- */
77 qla2x00_get_async_timeout(struct scsi_qla_host *vha)
80 struct qla_hw_data *ha = vha->hw;
82 /* Firmware should use switch negotiated r_a_tov for timeout. */
83 tmo = ha->r_a_tov / 10 * 2;
85 tmo = FX00_DEF_RATOV * 2;
86 } else if (!IS_FWI2_CAPABLE(ha)) {
88 * Except for earlier ISPs where the timeout is seeded from the
89 * initialization control block.
91 tmo = ha->login_timeout;
96 static void qla24xx_abort_iocb_timeout(void *data)
99 struct srb_iocb *abt = &sp->u.iocb_cmd;
100 struct qla_qpair *qpair = sp->qpair;
104 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
105 for (handle = 1; handle < qpair->req->num_outstanding_cmds; handle++) {
106 /* removing the abort */
107 if (qpair->req->outstanding_cmds[handle] == sp) {
108 qpair->req->outstanding_cmds[handle] = NULL;
112 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
114 abt->u.abt.comp_status = CS_TIMEOUT;
115 sp->done(sp, QLA_OS_TIMER_EXPIRED);
118 static void qla24xx_abort_sp_done(srb_t *sp, int res)
120 struct srb_iocb *abt = &sp->u.iocb_cmd;
122 del_timer(&sp->u.iocb_cmd.timer);
123 if (sp->flags & SRB_WAKEUP_ON_COMP)
124 complete(&abt->u.abt.comp);
129 static int qla24xx_async_abort_cmd(srb_t *cmd_sp, bool wait)
131 scsi_qla_host_t *vha = cmd_sp->vha;
132 struct srb_iocb *abt_iocb;
134 int rval = QLA_FUNCTION_FAILED;
136 sp = qla2xxx_get_qpair_sp(cmd_sp->vha, cmd_sp->qpair, cmd_sp->fcport,
141 abt_iocb = &sp->u.iocb_cmd;
142 sp->type = SRB_ABT_CMD;
144 sp->qpair = cmd_sp->qpair;
146 sp->flags = SRB_WAKEUP_ON_COMP;
148 abt_iocb->timeout = qla24xx_abort_iocb_timeout;
149 init_completion(&abt_iocb->u.abt.comp);
150 /* FW can send 2 x ABTS's timeout/20s */
151 qla2x00_init_timer(sp, 42);
153 abt_iocb->u.abt.cmd_hndl = cmd_sp->handle;
154 abt_iocb->u.abt.req_que_no = cpu_to_le16(cmd_sp->qpair->req->id);
156 sp->done = qla24xx_abort_sp_done;
158 ql_dbg(ql_dbg_async, vha, 0x507c,
159 "Abort command issued - hdl=%x, type=%x\n", cmd_sp->handle,
162 rval = qla2x00_start_sp(sp);
163 if (rval != QLA_SUCCESS)
167 wait_for_completion(&abt_iocb->u.abt.comp);
168 rval = abt_iocb->u.abt.comp_status == CS_COMPLETE ?
169 QLA_SUCCESS : QLA_FUNCTION_FAILED;
181 qla2x00_async_iocb_timeout(void *data)
184 fc_port_t *fcport = sp->fcport;
185 struct srb_iocb *lio = &sp->u.iocb_cmd;
190 ql_dbg(ql_dbg_disc, fcport->vha, 0x2071,
191 "Async-%s timeout - hdl=%x portid=%06x %8phC.\n",
192 sp->name, sp->handle, fcport->d_id.b24, fcport->port_name);
194 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
196 pr_info("Async-%s timeout - hdl=%x.\n",
197 sp->name, sp->handle);
202 rc = qla24xx_async_abort_cmd(sp, false);
204 /* Retry as needed. */
205 lio->u.logio.data[0] = MBS_COMMAND_ERROR;
206 lio->u.logio.data[1] =
207 lio->u.logio.flags & SRB_LOGIN_RETRIED ?
208 QLA_LOGIO_LOGIN_RETRIED : 0;
209 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
210 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
212 if (sp->qpair->req->outstanding_cmds[h] ==
214 sp->qpair->req->outstanding_cmds[h] =
219 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
220 sp->done(sp, QLA_FUNCTION_TIMEOUT);
224 case SRB_CT_PTHRU_CMD:
230 rc = qla24xx_async_abort_cmd(sp, false);
232 spin_lock_irqsave(sp->qpair->qp_lock_ptr, flags);
233 for (h = 1; h < sp->qpair->req->num_outstanding_cmds;
235 if (sp->qpair->req->outstanding_cmds[h] ==
237 sp->qpair->req->outstanding_cmds[h] =
242 spin_unlock_irqrestore(sp->qpair->qp_lock_ptr, flags);
243 sp->done(sp, QLA_FUNCTION_TIMEOUT);
249 static void qla2x00_async_login_sp_done(srb_t *sp, int res)
251 struct scsi_qla_host *vha = sp->vha;
252 struct srb_iocb *lio = &sp->u.iocb_cmd;
255 ql_dbg(ql_dbg_disc, vha, 0x20dd,
256 "%s %8phC res %d \n", __func__, sp->fcport->port_name, res);
258 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
260 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
261 memset(&ea, 0, sizeof(ea));
262 ea.event = FCME_PLOGI_DONE;
263 ea.fcport = sp->fcport;
264 ea.data[0] = lio->u.logio.data[0];
265 ea.data[1] = lio->u.logio.data[1];
266 ea.iop[0] = lio->u.logio.iop[0];
267 ea.iop[1] = lio->u.logio.iop[1];
269 qla2x00_fcport_event_handler(vha, &ea);
276 fcport_is_smaller(fc_port_t *fcport)
278 if (wwn_to_u64(fcport->port_name) <
279 wwn_to_u64(fcport->vha->port_name))
286 fcport_is_bigger(fc_port_t *fcport)
288 return !fcport_is_smaller(fcport);
292 qla2x00_async_login(struct scsi_qla_host *vha, fc_port_t *fcport,
296 struct srb_iocb *lio;
297 int rval = QLA_FUNCTION_FAILED;
299 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
300 fcport->loop_id == FC_NO_LOOP_ID) {
301 ql_log(ql_log_warn, vha, 0xffff,
302 "%s: %8phC - not sending command.\n",
303 __func__, fcport->port_name);
307 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
311 fcport->flags |= FCF_ASYNC_SENT;
312 fcport->logout_completed = 0;
314 fcport->disc_state = DSC_LOGIN_PEND;
315 sp->type = SRB_LOGIN_CMD;
317 sp->gen1 = fcport->rscn_gen;
318 sp->gen2 = fcport->login_gen;
320 lio = &sp->u.iocb_cmd;
321 lio->timeout = qla2x00_async_iocb_timeout;
322 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
324 sp->done = qla2x00_async_login_sp_done;
325 if (N2N_TOPO(fcport->vha->hw) && fcport_is_bigger(fcport))
326 lio->u.logio.flags |= SRB_LOGIN_PRLI_ONLY;
328 lio->u.logio.flags |= SRB_LOGIN_COND_PLOGI;
330 if (fcport->fc4f_nvme)
331 lio->u.logio.flags |= SRB_LOGIN_SKIP_PRLI;
333 ql_dbg(ql_dbg_disc, vha, 0x2072,
334 "Async-login - %8phC hdl=%x, loopid=%x portid=%02x%02x%02x "
335 "retries=%d.\n", fcport->port_name, sp->handle, fcport->loop_id,
336 fcport->d_id.b.domain, fcport->d_id.b.area, fcport->d_id.b.al_pa,
337 fcport->login_retry);
339 rval = qla2x00_start_sp(sp);
340 if (rval != QLA_SUCCESS) {
341 fcport->flags |= FCF_LOGIN_NEEDED;
342 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
350 fcport->flags &= ~FCF_ASYNC_SENT;
352 fcport->flags &= ~FCF_ASYNC_ACTIVE;
356 static void qla2x00_async_logout_sp_done(srb_t *sp, int res)
358 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
359 sp->fcport->login_gen++;
360 qlt_logo_completion_handler(sp->fcport, res);
365 qla2x00_async_logout(struct scsi_qla_host *vha, fc_port_t *fcport)
368 struct srb_iocb *lio;
369 int rval = QLA_FUNCTION_FAILED;
371 fcport->flags |= FCF_ASYNC_SENT;
372 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
376 sp->type = SRB_LOGOUT_CMD;
379 lio = &sp->u.iocb_cmd;
380 lio->timeout = qla2x00_async_iocb_timeout;
381 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
383 sp->done = qla2x00_async_logout_sp_done;
385 ql_dbg(ql_dbg_disc, vha, 0x2070,
386 "Async-logout - hdl=%x loop-id=%x portid=%02x%02x%02x %8phC.\n",
387 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
388 fcport->d_id.b.area, fcport->d_id.b.al_pa,
391 rval = qla2x00_start_sp(sp);
392 if (rval != QLA_SUCCESS)
399 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
404 qla2x00_async_prlo_done(struct scsi_qla_host *vha, fc_port_t *fcport,
407 fcport->flags &= ~FCF_ASYNC_ACTIVE;
408 /* Don't re-login in target mode */
409 if (!fcport->tgt_session)
410 qla2x00_mark_device_lost(vha, fcport, 1, 0);
411 qlt_logo_completion_handler(fcport, data[0]);
414 static void qla2x00_async_prlo_sp_done(srb_t *sp, int res)
416 struct srb_iocb *lio = &sp->u.iocb_cmd;
417 struct scsi_qla_host *vha = sp->vha;
419 sp->fcport->flags &= ~FCF_ASYNC_ACTIVE;
420 if (!test_bit(UNLOADING, &vha->dpc_flags))
421 qla2x00_post_async_prlo_done_work(sp->fcport->vha, sp->fcport,
427 qla2x00_async_prlo(struct scsi_qla_host *vha, fc_port_t *fcport)
430 struct srb_iocb *lio;
433 rval = QLA_FUNCTION_FAILED;
434 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
438 sp->type = SRB_PRLO_CMD;
441 lio = &sp->u.iocb_cmd;
442 lio->timeout = qla2x00_async_iocb_timeout;
443 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
445 sp->done = qla2x00_async_prlo_sp_done;
447 ql_dbg(ql_dbg_disc, vha, 0x2070,
448 "Async-prlo - hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
449 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
450 fcport->d_id.b.area, fcport->d_id.b.al_pa);
452 rval = qla2x00_start_sp(sp);
453 if (rval != QLA_SUCCESS)
461 fcport->flags &= ~FCF_ASYNC_ACTIVE;
466 void qla24xx_handle_adisc_event(scsi_qla_host_t *vha, struct event_arg *ea)
468 struct fc_port *fcport = ea->fcport;
470 ql_dbg(ql_dbg_disc, vha, 0x20d2,
471 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d lid %d\n",
472 __func__, fcport->port_name, fcport->disc_state,
473 fcport->fw_login_state, ea->rc, fcport->login_gen, ea->sp->gen2,
474 fcport->rscn_gen, ea->sp->gen1, fcport->loop_id);
476 if (ea->data[0] != MBS_COMMAND_COMPLETE) {
477 ql_dbg(ql_dbg_disc, vha, 0x2066,
478 "%s %8phC: adisc fail: post delete\n",
479 __func__, ea->fcport->port_name);
480 /* deleted = 0 & logout_on_delete = force fw cleanup */
482 fcport->logout_on_delete = 1;
483 qlt_schedule_sess_for_deletion(ea->fcport);
487 if (ea->fcport->disc_state == DSC_DELETE_PEND)
490 if (ea->sp->gen2 != ea->fcport->login_gen) {
491 /* target side must have changed it. */
492 ql_dbg(ql_dbg_disc, vha, 0x20d3,
493 "%s %8phC generation changed\n",
494 __func__, ea->fcport->port_name);
496 } else if (ea->sp->gen1 != ea->fcport->rscn_gen) {
497 qla_rscn_replay(fcport);
498 qlt_schedule_sess_for_deletion(fcport);
502 __qla24xx_handle_gpdb_event(vha, ea);
505 static int qla_post_els_plogi_work(struct scsi_qla_host *vha, fc_port_t *fcport)
507 struct qla_work_evt *e;
509 e = qla2x00_alloc_work(vha, QLA_EVT_ELS_PLOGI);
511 return QLA_FUNCTION_FAILED;
513 e->u.fcport.fcport = fcport;
514 fcport->flags |= FCF_ASYNC_ACTIVE;
515 return qla2x00_post_work(vha, e);
518 static void qla2x00_async_adisc_sp_done(srb_t *sp, int res)
520 struct scsi_qla_host *vha = sp->vha;
522 struct srb_iocb *lio = &sp->u.iocb_cmd;
524 ql_dbg(ql_dbg_disc, vha, 0x2066,
525 "Async done-%s res %x %8phC\n",
526 sp->name, res, sp->fcport->port_name);
528 sp->fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
530 memset(&ea, 0, sizeof(ea));
531 ea.event = FCME_ADISC_DONE;
533 ea.data[0] = lio->u.logio.data[0];
534 ea.data[1] = lio->u.logio.data[1];
535 ea.iop[0] = lio->u.logio.iop[0];
536 ea.iop[1] = lio->u.logio.iop[1];
537 ea.fcport = sp->fcport;
540 qla2x00_fcport_event_handler(vha, &ea);
546 qla2x00_async_adisc(struct scsi_qla_host *vha, fc_port_t *fcport,
550 struct srb_iocb *lio;
551 int rval = QLA_FUNCTION_FAILED;
553 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
556 fcport->flags |= FCF_ASYNC_SENT;
557 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
561 sp->type = SRB_ADISC_CMD;
564 lio = &sp->u.iocb_cmd;
565 lio->timeout = qla2x00_async_iocb_timeout;
566 sp->gen1 = fcport->rscn_gen;
567 sp->gen2 = fcport->login_gen;
568 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
570 sp->done = qla2x00_async_adisc_sp_done;
571 if (data[1] & QLA_LOGIO_LOGIN_RETRIED)
572 lio->u.logio.flags |= SRB_LOGIN_RETRIED;
574 ql_dbg(ql_dbg_disc, vha, 0x206f,
575 "Async-adisc - hdl=%x loopid=%x portid=%06x %8phC.\n",
576 sp->handle, fcport->loop_id, fcport->d_id.b24, fcport->port_name);
578 rval = qla2x00_start_sp(sp);
579 if (rval != QLA_SUCCESS)
587 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
588 qla2x00_post_async_adisc_work(vha, fcport, data);
592 static bool qla2x00_is_reserved_id(scsi_qla_host_t *vha, uint16_t loop_id)
594 struct qla_hw_data *ha = vha->hw;
596 if (IS_FWI2_CAPABLE(ha))
597 return loop_id > NPH_LAST_HANDLE;
599 return (loop_id > ha->max_loop_id && loop_id < SNS_FIRST_LOOP_ID) ||
600 loop_id == MANAGEMENT_SERVER || loop_id == BROADCAST;
604 * qla2x00_find_new_loop_id - scan through our port list and find a new usable loop ID
605 * @vha: adapter state pointer.
606 * @dev: port structure pointer.
609 * qla2x00 local function return status code.
614 static int qla2x00_find_new_loop_id(scsi_qla_host_t *vha, fc_port_t *dev)
617 struct qla_hw_data *ha = vha->hw;
618 unsigned long flags = 0;
622 spin_lock_irqsave(&ha->vport_slock, flags);
624 dev->loop_id = find_first_zero_bit(ha->loop_id_map, LOOPID_MAP_SIZE);
625 if (dev->loop_id >= LOOPID_MAP_SIZE ||
626 qla2x00_is_reserved_id(vha, dev->loop_id)) {
627 dev->loop_id = FC_NO_LOOP_ID;
628 rval = QLA_FUNCTION_FAILED;
630 set_bit(dev->loop_id, ha->loop_id_map);
632 spin_unlock_irqrestore(&ha->vport_slock, flags);
634 if (rval == QLA_SUCCESS)
635 ql_dbg(ql_dbg_disc, dev->vha, 0x2086,
636 "Assigning new loopid=%x, portid=%x.\n",
637 dev->loop_id, dev->d_id.b24);
639 ql_log(ql_log_warn, dev->vha, 0x2087,
640 "No loop_id's available, portid=%x.\n",
646 void qla2x00_clear_loop_id(fc_port_t *fcport)
648 struct qla_hw_data *ha = fcport->vha->hw;
650 if (fcport->loop_id == FC_NO_LOOP_ID ||
651 qla2x00_is_reserved_id(fcport->vha, fcport->loop_id))
654 clear_bit(fcport->loop_id, ha->loop_id_map);
655 fcport->loop_id = FC_NO_LOOP_ID;
658 static void qla24xx_handle_gnl_done_event(scsi_qla_host_t *vha,
659 struct event_arg *ea)
661 fc_port_t *fcport, *conflict_fcport;
662 struct get_name_list_extended *e;
663 u16 i, n, found = 0, loop_id;
667 u8 current_login_state;
670 ql_dbg(ql_dbg_disc, vha, 0xffff,
671 "%s %8phC DS %d LS rc %d %d login %d|%d rscn %d|%d lid %d\n",
672 __func__, fcport->port_name, fcport->disc_state,
673 fcport->fw_login_state, ea->rc,
674 fcport->login_gen, fcport->last_login_gen,
675 fcport->rscn_gen, fcport->last_rscn_gen, vha->loop_id);
677 if (fcport->disc_state == DSC_DELETE_PEND)
680 if (ea->rc) { /* rval */
681 if (fcport->login_retry == 0) {
682 ql_dbg(ql_dbg_disc, vha, 0x20de,
683 "GNL failed Port login retry %8phN, retry cnt=%d.\n",
684 fcport->port_name, fcport->login_retry);
689 if (fcport->last_rscn_gen != fcport->rscn_gen) {
690 qla_rscn_replay(fcport);
691 qlt_schedule_sess_for_deletion(fcport);
693 } else if (fcport->last_login_gen != fcport->login_gen) {
694 ql_dbg(ql_dbg_disc, vha, 0x20e0,
695 "%s %8phC login gen changed\n",
696 __func__, fcport->port_name);
700 n = ea->data[0] / sizeof(struct get_name_list_extended);
702 ql_dbg(ql_dbg_disc, vha, 0x20e1,
703 "%s %d %8phC n %d %02x%02x%02x lid %d \n",
704 __func__, __LINE__, fcport->port_name, n,
705 fcport->d_id.b.domain, fcport->d_id.b.area,
706 fcport->d_id.b.al_pa, fcport->loop_id);
708 for (i = 0; i < n; i++) {
710 wwn = wwn_to_u64(e->port_name);
711 id.b.domain = e->port_id[2];
712 id.b.area = e->port_id[1];
713 id.b.al_pa = e->port_id[0];
716 if (memcmp((u8 *)&wwn, fcport->port_name, WWN_SIZE))
719 if (IS_SW_RESV_ADDR(id))
724 loop_id = le16_to_cpu(e->nport_handle);
725 loop_id = (loop_id & 0x7fff);
726 if (fcport->fc4f_nvme)
727 current_login_state = e->current_login_state >> 4;
729 current_login_state = e->current_login_state & 0xf;
732 ql_dbg(ql_dbg_disc, vha, 0x20e2,
733 "%s found %8phC CLS [%x|%x] nvme %d ID[%02x%02x%02x|%02x%02x%02x] lid[%d|%d]\n",
734 __func__, fcport->port_name,
735 e->current_login_state, fcport->fw_login_state,
736 fcport->fc4f_nvme, id.b.domain, id.b.area, id.b.al_pa,
737 fcport->d_id.b.domain, fcport->d_id.b.area,
738 fcport->d_id.b.al_pa, loop_id, fcport->loop_id);
740 switch (fcport->disc_state) {
741 case DSC_DELETE_PEND:
745 if ((id.b24 != fcport->d_id.b24 &&
747 (fcport->loop_id != FC_NO_LOOP_ID &&
748 fcport->loop_id != loop_id)) {
749 ql_dbg(ql_dbg_disc, vha, 0x20e3,
750 "%s %d %8phC post del sess\n",
751 __func__, __LINE__, fcport->port_name);
752 qlt_schedule_sess_for_deletion(fcport);
758 fcport->loop_id = loop_id;
760 wwn = wwn_to_u64(fcport->port_name);
761 qlt_find_sess_invalidate_other(vha, wwn,
762 id, loop_id, &conflict_fcport);
764 if (conflict_fcport) {
766 * Another share fcport share the same loop_id &
767 * nport id. Conflict fcport needs to finish
768 * cleanup before this fcport can proceed to login.
770 conflict_fcport->conflict = fcport;
771 fcport->login_pause = 1;
774 switch (vha->hw->current_topology) {
776 switch (current_login_state) {
777 case DSC_LS_PRLI_COMP:
778 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
779 vha, 0x20e4, "%s %d %8phC post gpdb\n",
780 __func__, __LINE__, fcport->port_name);
782 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
783 fcport->port_type = FCT_INITIATOR;
785 fcport->port_type = FCT_TARGET;
786 data[0] = data[1] = 0;
787 qla2x00_post_async_adisc_work(vha, fcport,
790 case DSC_LS_PORT_UNAVAIL:
792 if (fcport->loop_id == FC_NO_LOOP_ID) {
793 qla2x00_find_new_loop_id(vha, fcport);
794 fcport->fw_login_state =
797 ql_dbg(ql_dbg_disc, vha, 0x20e5,
798 "%s %d %8phC\n", __func__, __LINE__,
800 qla24xx_fcport_handle_login(vha, fcport);
805 fcport->fw_login_state = current_login_state;
807 switch (current_login_state) {
808 case DSC_LS_PRLI_COMP:
809 if ((e->prli_svc_param_word_3[0] & BIT_4) == 0)
810 fcport->port_type = FCT_INITIATOR;
812 fcport->port_type = FCT_TARGET;
814 data[0] = data[1] = 0;
815 qla2x00_post_async_adisc_work(vha, fcport,
818 case DSC_LS_PLOGI_COMP:
819 if (fcport_is_bigger(fcport)) {
820 /* local adapter is smaller */
821 if (fcport->loop_id != FC_NO_LOOP_ID)
822 qla2x00_clear_loop_id(fcport);
824 fcport->loop_id = loop_id;
825 qla24xx_fcport_handle_login(vha,
831 if (fcport_is_smaller(fcport)) {
832 /* local adapter is bigger */
833 if (fcport->loop_id != FC_NO_LOOP_ID)
834 qla2x00_clear_loop_id(fcport);
836 fcport->loop_id = loop_id;
837 qla24xx_fcport_handle_login(vha,
843 } /* switch (ha->current_topology) */
847 switch (vha->hw->current_topology) {
850 for (i = 0; i < n; i++) {
852 id.b.domain = e->port_id[0];
853 id.b.area = e->port_id[1];
854 id.b.al_pa = e->port_id[2];
856 loop_id = le16_to_cpu(e->nport_handle);
858 if (fcport->d_id.b24 == id.b24) {
860 qla2x00_find_fcport_by_wwpn(vha,
862 if (conflict_fcport) {
863 ql_dbg(ql_dbg_disc + ql_dbg_verbose,
865 "%s %d %8phC post del sess\n",
867 conflict_fcport->port_name);
868 qlt_schedule_sess_for_deletion
873 * FW already picked this loop id for
876 if (fcport->loop_id == loop_id)
877 fcport->loop_id = FC_NO_LOOP_ID;
879 qla24xx_fcport_handle_login(vha, fcport);
882 fcport->disc_state = DSC_DELETED;
883 if (time_after_eq(jiffies, fcport->dm_login_expire)) {
884 if (fcport->n2n_link_reset_cnt < 2) {
885 fcport->n2n_link_reset_cnt++;
887 * remote port is not sending PLOGI.
888 * Reset link to kick start his state
891 set_bit(N2N_LINK_RESET,
894 if (fcport->n2n_chip_reset < 1) {
895 ql_log(ql_log_info, vha, 0x705d,
896 "Chip reset to bring laser down");
897 set_bit(ISP_ABORT_NEEDED,
899 fcport->n2n_chip_reset++;
901 ql_log(ql_log_info, vha, 0x705d,
902 "Remote port %8ph is not coming back\n",
904 fcport->scan_state = 0;
907 qla2xxx_wake_dpc(vha);
910 * report port suppose to do PLOGI. Give him
911 * more time. FW will catch it.
913 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
922 static void qla24xx_async_gnl_sp_done(srb_t *sp, int res)
924 struct scsi_qla_host *vha = sp->vha;
926 struct fc_port *fcport = NULL, *tf;
927 u16 i, n = 0, loop_id;
929 struct get_name_list_extended *e;
934 ql_dbg(ql_dbg_disc, vha, 0x20e7,
935 "Async done-%s res %x mb[1]=%x mb[2]=%x \n",
936 sp->name, res, sp->u.iocb_cmd.u.mbx.in_mb[1],
937 sp->u.iocb_cmd.u.mbx.in_mb[2]);
939 if (res == QLA_FUNCTION_TIMEOUT)
942 sp->fcport->flags &= ~(FCF_ASYNC_SENT|FCF_ASYNC_ACTIVE);
943 memset(&ea, 0, sizeof(ea));
946 ea.event = FCME_GNL_DONE;
948 if (sp->u.iocb_cmd.u.mbx.in_mb[1] >=
949 sizeof(struct get_name_list_extended)) {
950 n = sp->u.iocb_cmd.u.mbx.in_mb[1] /
951 sizeof(struct get_name_list_extended);
952 ea.data[0] = sp->u.iocb_cmd.u.mbx.in_mb[1]; /* amnt xfered */
955 for (i = 0; i < n; i++) {
957 loop_id = le16_to_cpu(e->nport_handle);
958 /* mask out reserve bit */
959 loop_id = (loop_id & 0x7fff);
960 set_bit(loop_id, vha->hw->loop_id_map);
961 wwn = wwn_to_u64(e->port_name);
963 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20e8,
964 "%s %8phC %02x:%02x:%02x state %d/%d lid %x \n",
965 __func__, (void *)&wwn, e->port_id[2], e->port_id[1],
966 e->port_id[0], e->current_login_state, e->last_login_state,
970 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
974 if (!list_empty(&vha->gnl.fcports))
975 list_splice_init(&vha->gnl.fcports, &h);
976 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
978 list_for_each_entry_safe(fcport, tf, &h, gnl_entry) {
979 list_del_init(&fcport->gnl_entry);
980 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
981 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
982 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
985 qla2x00_fcport_event_handler(vha, &ea);
988 /* create new fcport if fw has knowledge of new sessions */
989 for (i = 0; i < n; i++) {
994 wwn = wwn_to_u64(e->port_name);
997 list_for_each_entry_safe(fcport, tf, &vha->vp_fcports, list) {
998 if (!memcmp((u8 *)&wwn, fcport->port_name,
1005 id.b.domain = e->port_id[2];
1006 id.b.area = e->port_id[1];
1007 id.b.al_pa = e->port_id[0];
1010 if (!found && wwn && !IS_SW_RESV_ADDR(id)) {
1011 ql_dbg(ql_dbg_disc, vha, 0x2065,
1012 "%s %d %8phC %06x post new sess\n",
1013 __func__, __LINE__, (u8 *)&wwn, id.b24);
1014 wwnn = wwn_to_u64(e->node_name);
1015 qla24xx_post_newsess_work(vha, &id, (u8 *)&wwn,
1016 (u8 *)&wwnn, NULL, FC4_TYPE_UNKNOWN);
1020 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1022 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1027 int qla24xx_async_gnl(struct scsi_qla_host *vha, fc_port_t *fcport)
1030 struct srb_iocb *mbx;
1031 int rval = QLA_FUNCTION_FAILED;
1032 unsigned long flags;
1035 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT))
1038 ql_dbg(ql_dbg_disc, vha, 0x20d9,
1039 "Async-gnlist WWPN %8phC \n", fcport->port_name);
1041 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1042 fcport->flags |= FCF_ASYNC_SENT;
1043 fcport->disc_state = DSC_GNL;
1044 fcport->last_rscn_gen = fcport->rscn_gen;
1045 fcport->last_login_gen = fcport->login_gen;
1047 list_add_tail(&fcport->gnl_entry, &vha->gnl.fcports);
1048 if (vha->gnl.sent) {
1049 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1053 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1055 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1059 sp->type = SRB_MB_IOCB;
1060 sp->name = "gnlist";
1061 sp->gen1 = fcport->rscn_gen;
1062 sp->gen2 = fcport->login_gen;
1064 mbx = &sp->u.iocb_cmd;
1065 mbx->timeout = qla2x00_async_iocb_timeout;
1066 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha)+2);
1068 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1069 mb[0] = MBC_PORT_NODE_NAME_LIST;
1070 mb[1] = BIT_2 | BIT_3;
1071 mb[2] = MSW(vha->gnl.ldma);
1072 mb[3] = LSW(vha->gnl.ldma);
1073 mb[6] = MSW(MSD(vha->gnl.ldma));
1074 mb[7] = LSW(MSD(vha->gnl.ldma));
1075 mb[8] = vha->gnl.size;
1076 mb[9] = vha->vp_idx;
1078 sp->done = qla24xx_async_gnl_sp_done;
1080 ql_dbg(ql_dbg_disc, vha, 0x20da,
1081 "Async-%s - OUT WWPN %8phC hndl %x\n",
1082 sp->name, fcport->port_name, sp->handle);
1084 rval = qla2x00_start_sp(sp);
1085 if (rval != QLA_SUCCESS)
1092 fcport->flags &= ~FCF_ASYNC_SENT;
1097 int qla24xx_post_gnl_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1099 struct qla_work_evt *e;
1101 e = qla2x00_alloc_work(vha, QLA_EVT_GNL);
1103 return QLA_FUNCTION_FAILED;
1105 e->u.fcport.fcport = fcport;
1106 fcport->flags |= FCF_ASYNC_ACTIVE;
1107 return qla2x00_post_work(vha, e);
1110 static void qla24xx_async_gpdb_sp_done(srb_t *sp, int res)
1112 struct scsi_qla_host *vha = sp->vha;
1113 struct qla_hw_data *ha = vha->hw;
1114 fc_port_t *fcport = sp->fcport;
1115 u16 *mb = sp->u.iocb_cmd.u.mbx.in_mb;
1116 struct event_arg ea;
1118 ql_dbg(ql_dbg_disc, vha, 0x20db,
1119 "Async done-%s res %x, WWPN %8phC mb[1]=%x mb[2]=%x \n",
1120 sp->name, res, fcport->port_name, mb[1], mb[2]);
1122 if (res == QLA_FUNCTION_TIMEOUT) {
1123 dma_pool_free(sp->vha->hw->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1124 sp->u.iocb_cmd.u.mbx.in_dma);
1128 fcport->flags &= ~(FCF_ASYNC_SENT | FCF_ASYNC_ACTIVE);
1129 memset(&ea, 0, sizeof(ea));
1130 ea.event = FCME_GPDB_DONE;
1134 qla2x00_fcport_event_handler(vha, &ea);
1136 dma_pool_free(ha->s_dma_pool, sp->u.iocb_cmd.u.mbx.in,
1137 sp->u.iocb_cmd.u.mbx.in_dma);
1142 static int qla24xx_post_prli_work(struct scsi_qla_host *vha, fc_port_t *fcport)
1144 struct qla_work_evt *e;
1146 e = qla2x00_alloc_work(vha, QLA_EVT_PRLI);
1148 return QLA_FUNCTION_FAILED;
1150 e->u.fcport.fcport = fcport;
1152 return qla2x00_post_work(vha, e);
1155 static void qla2x00_async_prli_sp_done(srb_t *sp, int res)
1157 struct scsi_qla_host *vha = sp->vha;
1158 struct srb_iocb *lio = &sp->u.iocb_cmd;
1159 struct event_arg ea;
1161 ql_dbg(ql_dbg_disc, vha, 0x2129,
1162 "%s %8phC res %d \n", __func__,
1163 sp->fcport->port_name, res);
1165 sp->fcport->flags &= ~FCF_ASYNC_SENT;
1167 if (!test_bit(UNLOADING, &vha->dpc_flags)) {
1168 memset(&ea, 0, sizeof(ea));
1169 ea.event = FCME_PRLI_DONE;
1170 ea.fcport = sp->fcport;
1171 ea.data[0] = lio->u.logio.data[0];
1172 ea.data[1] = lio->u.logio.data[1];
1173 ea.iop[0] = lio->u.logio.iop[0];
1174 ea.iop[1] = lio->u.logio.iop[1];
1177 qla2x00_fcport_event_handler(vha, &ea);
1184 qla24xx_async_prli(struct scsi_qla_host *vha, fc_port_t *fcport)
1187 struct srb_iocb *lio;
1188 int rval = QLA_FUNCTION_FAILED;
1190 if (!vha->flags.online)
1193 if (fcport->fw_login_state == DSC_LS_PLOGI_PEND ||
1194 fcport->fw_login_state == DSC_LS_PRLI_PEND)
1197 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1201 fcport->flags |= FCF_ASYNC_SENT;
1202 fcport->logout_completed = 0;
1204 sp->type = SRB_PRLI_CMD;
1207 lio = &sp->u.iocb_cmd;
1208 lio->timeout = qla2x00_async_iocb_timeout;
1209 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1211 sp->done = qla2x00_async_prli_sp_done;
1212 lio->u.logio.flags = 0;
1214 if (fcport->fc4f_nvme)
1215 lio->u.logio.flags |= SRB_LOGIN_NVME_PRLI;
1217 ql_dbg(ql_dbg_disc, vha, 0x211b,
1218 "Async-prli - %8phC hdl=%x, loopid=%x portid=%06x retries=%d %s.\n",
1219 fcport->port_name, sp->handle, fcport->loop_id, fcport->d_id.b24,
1220 fcport->login_retry, fcport->fc4f_nvme ? "nvme" : "fc");
1222 rval = qla2x00_start_sp(sp);
1223 if (rval != QLA_SUCCESS) {
1224 fcport->flags |= FCF_LOGIN_NEEDED;
1225 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1233 fcport->flags &= ~FCF_ASYNC_SENT;
1237 int qla24xx_post_gpdb_work(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1239 struct qla_work_evt *e;
1241 e = qla2x00_alloc_work(vha, QLA_EVT_GPDB);
1243 return QLA_FUNCTION_FAILED;
1245 e->u.fcport.fcport = fcport;
1246 e->u.fcport.opt = opt;
1247 fcport->flags |= FCF_ASYNC_ACTIVE;
1248 return qla2x00_post_work(vha, e);
1251 int qla24xx_async_gpdb(struct scsi_qla_host *vha, fc_port_t *fcport, u8 opt)
1254 struct srb_iocb *mbx;
1255 int rval = QLA_FUNCTION_FAILED;
1258 struct port_database_24xx *pd;
1259 struct qla_hw_data *ha = vha->hw;
1261 if (!vha->flags.online || (fcport->flags & FCF_ASYNC_SENT) ||
1262 fcport->loop_id == FC_NO_LOOP_ID) {
1263 ql_log(ql_log_warn, vha, 0xffff,
1264 "%s: %8phC - not sending command.\n",
1265 __func__, fcport->port_name);
1269 fcport->disc_state = DSC_GPDB;
1271 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1275 fcport->flags |= FCF_ASYNC_SENT;
1276 sp->type = SRB_MB_IOCB;
1278 sp->gen1 = fcport->rscn_gen;
1279 sp->gen2 = fcport->login_gen;
1281 mbx = &sp->u.iocb_cmd;
1282 mbx->timeout = qla2x00_async_iocb_timeout;
1283 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha) + 2);
1285 pd = dma_pool_zalloc(ha->s_dma_pool, GFP_KERNEL, &pd_dma);
1287 ql_log(ql_log_warn, vha, 0xd043,
1288 "Failed to allocate port database structure.\n");
1292 mb = sp->u.iocb_cmd.u.mbx.out_mb;
1293 mb[0] = MBC_GET_PORT_DATABASE;
1294 mb[1] = fcport->loop_id;
1295 mb[2] = MSW(pd_dma);
1296 mb[3] = LSW(pd_dma);
1297 mb[6] = MSW(MSD(pd_dma));
1298 mb[7] = LSW(MSD(pd_dma));
1299 mb[9] = vha->vp_idx;
1302 mbx->u.mbx.in = (void *)pd;
1303 mbx->u.mbx.in_dma = pd_dma;
1305 sp->done = qla24xx_async_gpdb_sp_done;
1307 ql_dbg(ql_dbg_disc, vha, 0x20dc,
1308 "Async-%s %8phC hndl %x opt %x\n",
1309 sp->name, fcport->port_name, sp->handle, opt);
1311 rval = qla2x00_start_sp(sp);
1312 if (rval != QLA_SUCCESS)
1318 dma_pool_free(ha->s_dma_pool, pd, pd_dma);
1321 fcport->flags &= ~FCF_ASYNC_SENT;
1323 qla24xx_post_gpdb_work(vha, fcport, opt);
1328 void __qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1330 unsigned long flags;
1332 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1333 ea->fcport->login_gen++;
1334 ea->fcport->deleted = 0;
1335 ea->fcport->logout_on_delete = 1;
1337 if (!ea->fcport->login_succ && !IS_SW_RESV_ADDR(ea->fcport->d_id)) {
1338 vha->fcport_count++;
1339 ea->fcport->login_succ = 1;
1341 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1342 qla24xx_sched_upd_fcport(ea->fcport);
1343 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1344 } else if (ea->fcport->login_succ) {
1346 * We have an existing session. A late RSCN delivery
1347 * must have triggered the session to be re-validate.
1348 * Session is still valid.
1350 ql_dbg(ql_dbg_disc, vha, 0x20d6,
1351 "%s %d %8phC session revalidate success\n",
1352 __func__, __LINE__, ea->fcport->port_name);
1353 ea->fcport->disc_state = DSC_LOGIN_COMPLETE;
1355 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
1359 void qla24xx_handle_gpdb_event(scsi_qla_host_t *vha, struct event_arg *ea)
1361 fc_port_t *fcport = ea->fcport;
1362 struct port_database_24xx *pd;
1363 struct srb *sp = ea->sp;
1366 pd = (struct port_database_24xx *)sp->u.iocb_cmd.u.mbx.in;
1368 fcport->flags &= ~FCF_ASYNC_SENT;
1370 ql_dbg(ql_dbg_disc, vha, 0x20d2,
1371 "%s %8phC DS %d LS %d nvme %x rc %d\n", __func__, fcport->port_name,
1372 fcport->disc_state, pd->current_login_state, fcport->fc4f_nvme,
1375 if (fcport->disc_state == DSC_DELETE_PEND)
1378 if (fcport->fc4f_nvme)
1379 ls = pd->current_login_state >> 4;
1381 ls = pd->current_login_state & 0xf;
1383 if (ea->sp->gen2 != fcport->login_gen) {
1384 /* target side must have changed it. */
1386 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1387 "%s %8phC generation changed\n",
1388 __func__, fcport->port_name);
1390 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1391 qla_rscn_replay(fcport);
1392 qlt_schedule_sess_for_deletion(fcport);
1397 case PDS_PRLI_COMPLETE:
1398 __qla24xx_parse_gpdb(vha, fcport, pd);
1400 case PDS_PLOGI_PENDING:
1401 case PDS_PLOGI_COMPLETE:
1402 case PDS_PRLI_PENDING:
1403 case PDS_PRLI2_PENDING:
1404 /* Set discovery state back to GNL to Relogin attempt */
1405 if (qla_dual_mode_enabled(vha) ||
1406 qla_ini_mode_enabled(vha)) {
1407 fcport->disc_state = DSC_GNL;
1408 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1411 case PDS_LOGO_PENDING:
1412 case PDS_PORT_UNAVAILABLE:
1414 ql_dbg(ql_dbg_disc, vha, 0x20d5, "%s %d %8phC post del sess\n",
1415 __func__, __LINE__, fcport->port_name);
1416 qlt_schedule_sess_for_deletion(fcport);
1419 __qla24xx_handle_gpdb_event(vha, ea);
1422 static void qla_chk_n2n_b4_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1427 if (qla_tgt_mode_enabled(vha))
1430 if (qla_dual_mode_enabled(vha)) {
1431 if (N2N_TOPO(vha->hw)) {
1434 mywwn = wwn_to_u64(vha->port_name);
1435 wwn = wwn_to_u64(fcport->port_name);
1438 else if ((fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1439 && time_after_eq(jiffies,
1440 fcport->plogi_nack_done_deadline))
1446 /* initiator mode */
1450 if (login && fcport->login_retry) {
1451 fcport->login_retry--;
1452 if (fcport->loop_id == FC_NO_LOOP_ID) {
1453 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
1454 rc = qla2x00_find_new_loop_id(vha, fcport);
1456 ql_dbg(ql_dbg_disc, vha, 0x20e6,
1457 "%s %d %8phC post del sess - out of loopid\n",
1458 __func__, __LINE__, fcport->port_name);
1459 fcport->scan_state = 0;
1460 qlt_schedule_sess_for_deletion(fcport);
1464 ql_dbg(ql_dbg_disc, vha, 0x20bf,
1465 "%s %d %8phC post login\n",
1466 __func__, __LINE__, fcport->port_name);
1467 qla2x00_post_async_login_work(vha, fcport, NULL);
1471 int qla24xx_fcport_handle_login(struct scsi_qla_host *vha, fc_port_t *fcport)
1477 ql_dbg(ql_dbg_disc + ql_dbg_verbose, vha, 0x20d8,
1478 "%s %8phC DS %d LS %d P %d fl %x confl %p rscn %d|%d login %d lid %d scan %d\n",
1479 __func__, fcport->port_name, fcport->disc_state,
1480 fcport->fw_login_state, fcport->login_pause, fcport->flags,
1481 fcport->conflict, fcport->last_rscn_gen, fcport->rscn_gen,
1482 fcport->login_gen, fcport->loop_id, fcport->scan_state);
1484 if (fcport->scan_state != QLA_FCPORT_FOUND)
1487 if ((fcport->loop_id != FC_NO_LOOP_ID) &&
1488 ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1489 (fcport->fw_login_state == DSC_LS_PRLI_PEND)))
1492 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1493 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1494 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1499 /* for pure Target Mode. Login will not be initiated */
1500 if (vha->host->active_mode == MODE_TARGET)
1503 if (fcport->flags & FCF_ASYNC_SENT) {
1504 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1508 switch (fcport->disc_state) {
1510 wwn = wwn_to_u64(fcport->node_name);
1511 switch (vha->hw->current_topology) {
1513 if (fcport_is_smaller(fcport)) {
1514 /* this adapter is bigger */
1515 if (fcport->login_retry) {
1516 if (fcport->loop_id == FC_NO_LOOP_ID) {
1517 qla2x00_find_new_loop_id(vha,
1519 fcport->fw_login_state =
1520 DSC_LS_PORT_UNAVAIL;
1522 fcport->login_retry--;
1523 qla_post_els_plogi_work(vha, fcport);
1525 ql_log(ql_log_info, vha, 0x705d,
1526 "Unable to reach remote port %8phC",
1530 qla24xx_post_gnl_work(vha, fcport);
1535 ql_dbg(ql_dbg_disc, vha, 0xffff,
1536 "%s %d %8phC post GNNID\n",
1537 __func__, __LINE__, fcport->port_name);
1538 qla24xx_post_gnnid_work(vha, fcport);
1539 } else if (fcport->loop_id == FC_NO_LOOP_ID) {
1540 ql_dbg(ql_dbg_disc, vha, 0x20bd,
1541 "%s %d %8phC post gnl\n",
1542 __func__, __LINE__, fcport->port_name);
1543 qla24xx_post_gnl_work(vha, fcport);
1545 qla_chk_n2n_b4_login(vha, fcport);
1552 switch (vha->hw->current_topology) {
1554 if ((fcport->current_login_state & 0xf) == 0x6) {
1555 ql_dbg(ql_dbg_disc, vha, 0x2118,
1556 "%s %d %8phC post GPDB work\n",
1557 __func__, __LINE__, fcport->port_name);
1558 fcport->chip_reset =
1559 vha->hw->base_qpair->chip_reset;
1560 qla24xx_post_gpdb_work(vha, fcport, 0);
1562 ql_dbg(ql_dbg_disc, vha, 0x2118,
1563 "%s %d %8phC post NVMe PRLI\n",
1564 __func__, __LINE__, fcport->port_name);
1565 qla24xx_post_prli_work(vha, fcport);
1569 if (fcport->login_pause) {
1570 fcport->last_rscn_gen = fcport->rscn_gen;
1571 fcport->last_login_gen = fcport->login_gen;
1572 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1575 qla_chk_n2n_b4_login(vha, fcport);
1580 case DSC_LOGIN_FAILED:
1581 if (N2N_TOPO(vha->hw))
1582 qla_chk_n2n_b4_login(vha, fcport);
1584 qlt_schedule_sess_for_deletion(fcport);
1587 case DSC_LOGIN_COMPLETE:
1588 /* recheck login state */
1589 data[0] = data[1] = 0;
1590 qla2x00_post_async_adisc_work(vha, fcport, data);
1593 case DSC_LOGIN_PEND:
1594 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP)
1595 qla24xx_post_prli_work(vha, fcport);
1598 case DSC_UPD_FCPORT:
1599 sec = jiffies_to_msecs(jiffies -
1600 fcport->jiffies_at_registration)/1000;
1601 if (fcport->sec_since_registration < sec && sec &&
1603 fcport->sec_since_registration = sec;
1604 ql_dbg(ql_dbg_disc, fcport->vha, 0xffff,
1605 "%s %8phC - Slow Rport registration(%d Sec)\n",
1606 __func__, fcport->port_name, sec);
1609 if (fcport->next_disc_state != DSC_DELETE_PEND)
1610 fcport->next_disc_state = DSC_ADISC;
1611 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1621 int qla24xx_post_newsess_work(struct scsi_qla_host *vha, port_id_t *id,
1622 u8 *port_name, u8 *node_name, void *pla, u8 fc4_type)
1624 struct qla_work_evt *e;
1626 e = qla2x00_alloc_work(vha, QLA_EVT_NEW_SESS);
1628 return QLA_FUNCTION_FAILED;
1630 e->u.new_sess.id = *id;
1631 e->u.new_sess.pla = pla;
1632 e->u.new_sess.fc4_type = fc4_type;
1633 memcpy(e->u.new_sess.port_name, port_name, WWN_SIZE);
1635 memcpy(e->u.new_sess.node_name, node_name, WWN_SIZE);
1637 return qla2x00_post_work(vha, e);
1641 void qla24xx_handle_relogin_event(scsi_qla_host_t *vha,
1642 struct event_arg *ea)
1644 fc_port_t *fcport = ea->fcport;
1646 ql_dbg(ql_dbg_disc, vha, 0x2102,
1647 "%s %8phC DS %d LS %d P %d del %d cnfl %p rscn %d|%d login %d|%d fl %x\n",
1648 __func__, fcport->port_name, fcport->disc_state,
1649 fcport->fw_login_state, fcport->login_pause,
1650 fcport->deleted, fcport->conflict,
1651 fcport->last_rscn_gen, fcport->rscn_gen,
1652 fcport->last_login_gen, fcport->login_gen,
1655 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1656 (fcport->fw_login_state == DSC_LS_PRLI_PEND))
1659 if (fcport->fw_login_state == DSC_LS_PLOGI_COMP) {
1660 if (time_before_eq(jiffies, fcport->plogi_nack_done_deadline)) {
1661 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1666 if (fcport->last_rscn_gen != fcport->rscn_gen) {
1667 ql_dbg(ql_dbg_disc, vha, 0x20e9, "%s %d %8phC post gnl\n",
1668 __func__, __LINE__, fcport->port_name);
1669 qla24xx_post_gnl_work(vha, fcport);
1673 qla24xx_fcport_handle_login(vha, fcport);
1677 static void qla_handle_els_plogi_done(scsi_qla_host_t *vha,
1678 struct event_arg *ea)
1680 ql_dbg(ql_dbg_disc, vha, 0x2118,
1681 "%s %d %8phC post PRLI\n",
1682 __func__, __LINE__, ea->fcport->port_name);
1683 qla24xx_post_prli_work(vha, ea->fcport);
1686 void qla2x00_fcport_event_handler(scsi_qla_host_t *vha, struct event_arg *ea)
1690 switch (ea->event) {
1692 if (test_bit(UNLOADING, &vha->dpc_flags))
1695 qla24xx_handle_relogin_event(vha, ea);
1698 if (test_bit(UNLOADING, &vha->dpc_flags))
1701 unsigned long flags;
1703 fcport = qla2x00_find_fcport_by_nportid
1706 fcport->scan_needed = 1;
1710 spin_lock_irqsave(&vha->work_lock, flags);
1711 if (vha->scan.scan_flags == 0) {
1712 ql_dbg(ql_dbg_disc, vha, 0xffff,
1713 "%s: schedule\n", __func__);
1714 vha->scan.scan_flags |= SF_QUEUED;
1715 schedule_delayed_work(&vha->scan.scan_work, 5);
1717 spin_unlock_irqrestore(&vha->work_lock, flags);
1721 qla24xx_handle_gnl_done_event(vha, ea);
1723 case FCME_GPSC_DONE:
1724 qla24xx_handle_gpsc_event(vha, ea);
1726 case FCME_PLOGI_DONE: /* Initiator side sent LLIOCB */
1727 qla24xx_handle_plogi_done_event(vha, ea);
1729 case FCME_PRLI_DONE:
1730 qla24xx_handle_prli_done_event(vha, ea);
1732 case FCME_GPDB_DONE:
1733 qla24xx_handle_gpdb_event(vha, ea);
1735 case FCME_GPNID_DONE:
1736 qla24xx_handle_gpnid_event(vha, ea);
1738 case FCME_GFFID_DONE:
1739 qla24xx_handle_gffid_event(vha, ea);
1741 case FCME_ADISC_DONE:
1742 qla24xx_handle_adisc_event(vha, ea);
1744 case FCME_GNNID_DONE:
1745 qla24xx_handle_gnnid_event(vha, ea);
1747 case FCME_GFPNID_DONE:
1748 qla24xx_handle_gfpnid_event(vha, ea);
1750 case FCME_ELS_PLOGI_DONE:
1751 qla_handle_els_plogi_done(vha, ea);
1760 * RSCN(s) came in for this fcport, but the RSCN(s) was not able
1761 * to be consumed by the fcport
1763 void qla_rscn_replay(fc_port_t *fcport)
1765 struct event_arg ea;
1767 switch (fcport->disc_state) {
1768 case DSC_DELETE_PEND:
1774 if (fcport->scan_needed) {
1775 memset(&ea, 0, sizeof(ea));
1776 ea.event = FCME_RSCN;
1777 ea.id = fcport->d_id;
1778 ea.id.b.rsvd_1 = RSCN_PORT_ADDR;
1779 qla2x00_fcport_event_handler(fcport->vha, &ea);
1784 qla2x00_tmf_iocb_timeout(void *data)
1787 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1789 tmf->u.tmf.comp_status = CS_TIMEOUT;
1790 complete(&tmf->u.tmf.comp);
1793 static void qla2x00_tmf_sp_done(srb_t *sp, int res)
1795 struct srb_iocb *tmf = &sp->u.iocb_cmd;
1797 complete(&tmf->u.tmf.comp);
1801 qla2x00_async_tm_cmd(fc_port_t *fcport, uint32_t flags, uint32_t lun,
1804 struct scsi_qla_host *vha = fcport->vha;
1805 struct srb_iocb *tm_iocb;
1807 int rval = QLA_FUNCTION_FAILED;
1809 sp = qla2x00_get_sp(vha, fcport, GFP_KERNEL);
1813 tm_iocb = &sp->u.iocb_cmd;
1814 sp->type = SRB_TM_CMD;
1817 tm_iocb->timeout = qla2x00_tmf_iocb_timeout;
1818 init_completion(&tm_iocb->u.tmf.comp);
1819 qla2x00_init_timer(sp, qla2x00_get_async_timeout(vha));
1821 tm_iocb->u.tmf.flags = flags;
1822 tm_iocb->u.tmf.lun = lun;
1823 tm_iocb->u.tmf.data = tag;
1824 sp->done = qla2x00_tmf_sp_done;
1826 ql_dbg(ql_dbg_taskm, vha, 0x802f,
1827 "Async-tmf hdl=%x loop-id=%x portid=%02x%02x%02x.\n",
1828 sp->handle, fcport->loop_id, fcport->d_id.b.domain,
1829 fcport->d_id.b.area, fcport->d_id.b.al_pa);
1831 rval = qla2x00_start_sp(sp);
1832 if (rval != QLA_SUCCESS)
1834 wait_for_completion(&tm_iocb->u.tmf.comp);
1836 rval = tm_iocb->u.tmf.data;
1838 if (rval != QLA_SUCCESS) {
1839 ql_log(ql_log_warn, vha, 0x8030,
1840 "TM IOCB failed (%x).\n", rval);
1843 if (!test_bit(UNLOADING, &vha->dpc_flags) && !IS_QLAFX00(vha->hw)) {
1844 flags = tm_iocb->u.tmf.flags;
1845 lun = (uint16_t)tm_iocb->u.tmf.lun;
1847 /* Issue Marker IOCB */
1848 qla2x00_marker(vha, vha->hw->base_qpair,
1849 fcport->loop_id, lun,
1850 flags == TCF_LUN_RESET ? MK_SYNC_ID_LUN : MK_SYNC_ID);
1855 fcport->flags &= ~FCF_ASYNC_SENT;
1861 qla24xx_async_abort_command(srb_t *sp)
1863 unsigned long flags = 0;
1866 fc_port_t *fcport = sp->fcport;
1867 struct qla_qpair *qpair = sp->qpair;
1868 struct scsi_qla_host *vha = fcport->vha;
1869 struct req_que *req = qpair->req;
1871 spin_lock_irqsave(qpair->qp_lock_ptr, flags);
1872 for (handle = 1; handle < req->num_outstanding_cmds; handle++) {
1873 if (req->outstanding_cmds[handle] == sp)
1876 spin_unlock_irqrestore(qpair->qp_lock_ptr, flags);
1878 if (handle == req->num_outstanding_cmds) {
1879 /* Command not found. */
1880 return QLA_FUNCTION_FAILED;
1882 if (sp->type == SRB_FXIOCB_DCMD)
1883 return qlafx00_fx_disc(vha, &vha->hw->mr.fcport,
1884 FXDISC_ABORT_IOCTL);
1886 return qla24xx_async_abort_cmd(sp, true);
1890 qla24xx_handle_prli_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1892 switch (ea->data[0]) {
1893 case MBS_COMMAND_COMPLETE:
1894 ql_dbg(ql_dbg_disc, vha, 0x2118,
1895 "%s %d %8phC post gpdb\n",
1896 __func__, __LINE__, ea->fcport->port_name);
1898 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1899 ea->fcport->logout_on_delete = 1;
1900 ea->fcport->nvme_prli_service_param = ea->iop[0];
1901 if (ea->iop[0] & NVME_PRLI_SP_FIRST_BURST)
1902 ea->fcport->nvme_first_burst_size =
1903 (ea->iop[1] & 0xffff) * 512;
1905 ea->fcport->nvme_first_burst_size = 0;
1906 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
1909 if ((ea->iop[0] == LSC_SCODE_ELS_REJECT) &&
1910 (ea->iop[1] == 0x50000)) { /* reson 5=busy expl:0x0 */
1911 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1912 ea->fcport->fw_login_state = DSC_LS_PLOGI_COMP;
1916 if (ea->fcport->n2n_flag) {
1917 ql_dbg(ql_dbg_disc, vha, 0x2118,
1918 "%s %d %8phC post fc4 prli\n",
1919 __func__, __LINE__, ea->fcport->port_name);
1920 ea->fcport->fc4f_nvme = 0;
1921 ea->fcport->n2n_flag = 0;
1922 qla24xx_post_prli_work(vha, ea->fcport);
1924 ql_dbg(ql_dbg_disc, vha, 0x2119,
1925 "%s %d %8phC unhandle event of %x\n",
1926 __func__, __LINE__, ea->fcport->port_name, ea->data[0]);
1932 qla24xx_handle_plogi_done_event(struct scsi_qla_host *vha, struct event_arg *ea)
1934 port_id_t cid; /* conflict Nport id */
1936 struct fc_port *conflict_fcport;
1937 unsigned long flags;
1938 struct fc_port *fcport = ea->fcport;
1940 ql_dbg(ql_dbg_disc, vha, 0xffff,
1941 "%s %8phC DS %d LS %d rc %d login %d|%d rscn %d|%d data %x|%x iop %x|%x\n",
1942 __func__, fcport->port_name, fcport->disc_state,
1943 fcport->fw_login_state, ea->rc, ea->sp->gen2, fcport->login_gen,
1944 ea->sp->gen1, fcport->rscn_gen,
1945 ea->data[0], ea->data[1], ea->iop[0], ea->iop[1]);
1947 if ((fcport->fw_login_state == DSC_LS_PLOGI_PEND) ||
1948 (fcport->fw_login_state == DSC_LS_PRLI_PEND)) {
1949 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1950 "%s %d %8phC Remote is trying to login\n",
1951 __func__, __LINE__, fcport->port_name);
1955 if ((fcport->disc_state == DSC_DELETE_PEND) ||
1956 (fcport->disc_state == DSC_DELETED)) {
1957 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1961 if (ea->sp->gen2 != fcport->login_gen) {
1962 /* target side must have changed it. */
1963 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1964 "%s %8phC generation changed\n",
1965 __func__, fcport->port_name);
1966 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
1968 } else if (ea->sp->gen1 != fcport->rscn_gen) {
1969 ql_dbg(ql_dbg_disc, vha, 0x20d3,
1970 "%s %8phC RSCN generation changed\n",
1971 __func__, fcport->port_name);
1972 qla_rscn_replay(fcport);
1973 qlt_schedule_sess_for_deletion(fcport);
1977 switch (ea->data[0]) {
1978 case MBS_COMMAND_COMPLETE:
1980 * Driver must validate login state - If PRLI not complete,
1981 * force a relogin attempt via implicit LOGO, PLOGI, and PRLI
1984 if (ea->fcport->fc4f_nvme) {
1985 ql_dbg(ql_dbg_disc, vha, 0x2117,
1986 "%s %d %8phC post prli\n",
1987 __func__, __LINE__, ea->fcport->port_name);
1988 qla24xx_post_prli_work(vha, ea->fcport);
1990 ql_dbg(ql_dbg_disc, vha, 0x20ea,
1991 "%s %d %8phC LoopID 0x%x in use with %06x. post gnl\n",
1992 __func__, __LINE__, ea->fcport->port_name,
1993 ea->fcport->loop_id, ea->fcport->d_id.b24);
1995 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
1996 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
1997 ea->fcport->chip_reset = vha->hw->base_qpair->chip_reset;
1998 ea->fcport->logout_on_delete = 1;
1999 ea->fcport->send_els_logo = 0;
2000 ea->fcport->fw_login_state = DSC_LS_PRLI_COMP;
2001 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
2003 qla24xx_post_gpdb_work(vha, ea->fcport, 0);
2006 case MBS_COMMAND_ERROR:
2007 ql_dbg(ql_dbg_disc, vha, 0x20eb, "%s %d %8phC cmd error %x\n",
2008 __func__, __LINE__, ea->fcport->port_name, ea->data[1]);
2010 ea->fcport->flags &= ~FCF_ASYNC_SENT;
2011 ea->fcport->disc_state = DSC_LOGIN_FAILED;
2012 if (ea->data[1] & QLA_LOGIO_LOGIN_RETRIED)
2013 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
2015 qla2x00_mark_device_lost(vha, ea->fcport, 1, 0);
2017 case MBS_LOOP_ID_USED:
2018 /* data[1] = IO PARAM 1 = nport ID */
2019 cid.b.domain = (ea->iop[1] >> 16) & 0xff;
2020 cid.b.area = (ea->iop[1] >> 8) & 0xff;
2021 cid.b.al_pa = ea->iop[1] & 0xff;
2024 ql_dbg(ql_dbg_disc, vha, 0x20ec,
2025 "%s %d %8phC lid %#x in use with pid %06x post gnl\n",
2026 __func__, __LINE__, ea->fcport->port_name,
2027 ea->fcport->loop_id, cid.b24);
2029 set_bit(ea->fcport->loop_id, vha->hw->loop_id_map);
2030 ea->fcport->loop_id = FC_NO_LOOP_ID;
2031 qla24xx_post_gnl_work(vha, ea->fcport);
2033 case MBS_PORT_ID_USED:
2034 lid = ea->iop[1] & 0xffff;
2035 qlt_find_sess_invalidate_other(vha,
2036 wwn_to_u64(ea->fcport->port_name),
2037 ea->fcport->d_id, lid, &conflict_fcport);
2039 if (conflict_fcport) {
2041 * Another fcport share the same loop_id/nport id.
2042 * Conflict fcport needs to finish cleanup before this
2043 * fcport can proceed to login.
2045 conflict_fcport->conflict = ea->fcport;
2046 ea->fcport->login_pause = 1;
2048 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2049 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. post gidpn\n",
2050 __func__, __LINE__, ea->fcport->port_name,
2051 ea->fcport->d_id.b24, lid);
2053 ql_dbg(ql_dbg_disc, vha, 0x20ed,
2054 "%s %d %8phC NPortId %06x inuse with loopid 0x%x. sched delete\n",
2055 __func__, __LINE__, ea->fcport->port_name,
2056 ea->fcport->d_id.b24, lid);
2058 qla2x00_clear_loop_id(ea->fcport);
2059 set_bit(lid, vha->hw->loop_id_map);
2060 ea->fcport->loop_id = lid;
2061 ea->fcport->keep_nport_handle = 0;
2062 qlt_schedule_sess_for_deletion(ea->fcport);
2070 qla2x00_async_logout_done(struct scsi_qla_host *vha, fc_port_t *fcport,
2073 qlt_logo_completion_handler(fcport, data[0]);
2074 fcport->login_gen++;
2075 fcport->flags &= ~FCF_ASYNC_ACTIVE;
2079 /****************************************************************************/
2080 /* QLogic ISP2x00 Hardware Support Functions. */
2081 /****************************************************************************/
2084 qla83xx_nic_core_fw_load(scsi_qla_host_t *vha)
2086 int rval = QLA_SUCCESS;
2087 struct qla_hw_data *ha = vha->hw;
2088 uint32_t idc_major_ver, idc_minor_ver;
2091 qla83xx_idc_lock(vha, 0);
2093 /* SV: TODO: Assign initialization timeout from
2094 * flash-info / other param
2096 ha->fcoe_dev_init_timeout = QLA83XX_IDC_INITIALIZATION_TIMEOUT;
2097 ha->fcoe_reset_timeout = QLA83XX_IDC_RESET_ACK_TIMEOUT;
2099 /* Set our fcoe function presence */
2100 if (__qla83xx_set_drv_presence(vha) != QLA_SUCCESS) {
2101 ql_dbg(ql_dbg_p3p, vha, 0xb077,
2102 "Error while setting DRV-Presence.\n");
2103 rval = QLA_FUNCTION_FAILED;
2107 /* Decide the reset ownership */
2108 qla83xx_reset_ownership(vha);
2111 * On first protocol driver load:
2112 * Init-Owner: Set IDC-Major-Version and Clear IDC-Lock-Recovery
2114 * Others: Check compatibility with current IDC Major version.
2116 qla83xx_rd_reg(vha, QLA83XX_IDC_MAJOR_VERSION, &idc_major_ver);
2117 if (ha->flags.nic_core_reset_owner) {
2118 /* Set IDC Major version */
2119 idc_major_ver = QLA83XX_SUPP_IDC_MAJOR_VERSION;
2120 qla83xx_wr_reg(vha, QLA83XX_IDC_MAJOR_VERSION, idc_major_ver);
2122 /* Clearing IDC-Lock-Recovery register */
2123 qla83xx_wr_reg(vha, QLA83XX_IDC_LOCK_RECOVERY, 0);
2124 } else if (idc_major_ver != QLA83XX_SUPP_IDC_MAJOR_VERSION) {
2126 * Clear further IDC participation if we are not compatible with
2127 * the current IDC Major Version.
2129 ql_log(ql_log_warn, vha, 0xb07d,
2130 "Failing load, idc_major_ver=%d, expected_major_ver=%d.\n",
2131 idc_major_ver, QLA83XX_SUPP_IDC_MAJOR_VERSION);
2132 __qla83xx_clear_drv_presence(vha);
2133 rval = QLA_FUNCTION_FAILED;
2136 /* Each function sets its supported Minor version. */
2137 qla83xx_rd_reg(vha, QLA83XX_IDC_MINOR_VERSION, &idc_minor_ver);
2138 idc_minor_ver |= (QLA83XX_SUPP_IDC_MINOR_VERSION << (ha->portnum * 2));
2139 qla83xx_wr_reg(vha, QLA83XX_IDC_MINOR_VERSION, idc_minor_ver);
2141 if (ha->flags.nic_core_reset_owner) {
2142 memset(config, 0, sizeof(config));
2143 if (!qla81xx_get_port_config(vha, config))
2144 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
2148 rval = qla83xx_idc_state_handler(vha);
2151 qla83xx_idc_unlock(vha, 0);
2157 * qla2x00_initialize_adapter
2161 * ha = adapter block pointer.
2167 qla2x00_initialize_adapter(scsi_qla_host_t *vha)
2170 struct qla_hw_data *ha = vha->hw;
2171 struct req_que *req = ha->req_q_map[0];
2172 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2174 memset(&vha->qla_stats, 0, sizeof(vha->qla_stats));
2175 memset(&vha->fc_host_stat, 0, sizeof(vha->fc_host_stat));
2177 /* Clear adapter flags. */
2178 vha->flags.online = 0;
2179 ha->flags.chip_reset_done = 0;
2180 vha->flags.reset_active = 0;
2181 ha->flags.pci_channel_io_perm_failure = 0;
2182 ha->flags.eeh_busy = 0;
2183 vha->qla_stats.jiffies_at_last_reset = get_jiffies_64();
2184 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
2185 atomic_set(&vha->loop_state, LOOP_DOWN);
2186 vha->device_flags = DFLG_NO_CABLE;
2188 vha->flags.management_server_logged_in = 0;
2189 vha->marker_needed = 0;
2190 ha->isp_abort_cnt = 0;
2191 ha->beacon_blink_led = 0;
2193 set_bit(0, ha->req_qid_map);
2194 set_bit(0, ha->rsp_qid_map);
2196 ql_dbg(ql_dbg_init, vha, 0x0040,
2197 "Configuring PCI space...\n");
2198 rval = ha->isp_ops->pci_config(vha);
2200 ql_log(ql_log_warn, vha, 0x0044,
2201 "Unable to configure PCI space.\n");
2205 ha->isp_ops->reset_chip(vha);
2207 /* Check for secure flash support */
2208 if (IS_QLA28XX(ha)) {
2209 if (RD_REG_DWORD(®->mailbox12) & BIT_0) {
2210 ql_log(ql_log_info, vha, 0xffff, "Adapter is Secure\n");
2211 ha->flags.secure_adapter = 1;
2216 rval = qla2xxx_get_flash_info(vha);
2218 ql_log(ql_log_fatal, vha, 0x004f,
2219 "Unable to validate FLASH data.\n");
2223 if (IS_QLA8044(ha)) {
2224 qla8044_read_reset_template(vha);
2226 /* NOTE: If ql2xdontresethba==1, set IDC_CTRL DONTRESET_BIT0.
2227 * If DONRESET_BIT0 is set, drivers should not set dev_state
2228 * to NEED_RESET. But if NEED_RESET is set, drivers should
2229 * should honor the reset. */
2230 if (ql2xdontresethba == 1)
2231 qla8044_set_idc_dontreset(vha);
2234 ha->isp_ops->get_flash_version(vha, req->ring);
2235 ql_dbg(ql_dbg_init, vha, 0x0061,
2236 "Configure NVRAM parameters...\n");
2238 ha->isp_ops->nvram_config(vha);
2240 if (ha->flags.disable_serdes) {
2241 /* Mask HBA via NVRAM settings? */
2242 ql_log(ql_log_info, vha, 0x0077,
2243 "Masking HBA WWPN %8phN (via NVRAM).\n", vha->port_name);
2244 return QLA_FUNCTION_FAILED;
2247 ql_dbg(ql_dbg_init, vha, 0x0078,
2248 "Verifying loaded RISC code...\n");
2250 if (qla2x00_isp_firmware(vha) != QLA_SUCCESS) {
2251 rval = ha->isp_ops->chip_diag(vha);
2254 rval = qla2x00_setup_chip(vha);
2259 if (IS_QLA84XX(ha)) {
2260 ha->cs84xx = qla84xx_get_chip(vha);
2262 ql_log(ql_log_warn, vha, 0x00d0,
2263 "Unable to configure ISP84XX.\n");
2264 return QLA_FUNCTION_FAILED;
2268 if (qla_ini_mode_enabled(vha) || qla_dual_mode_enabled(vha))
2269 rval = qla2x00_init_rings(vha);
2271 /* No point in continuing if firmware initialization failed. */
2272 if (rval != QLA_SUCCESS)
2275 ha->flags.chip_reset_done = 1;
2277 if (rval == QLA_SUCCESS && IS_QLA84XX(ha)) {
2278 /* Issue verify 84xx FW IOCB to complete 84xx initialization */
2279 rval = qla84xx_init_chip(vha);
2280 if (rval != QLA_SUCCESS) {
2281 ql_log(ql_log_warn, vha, 0x00d4,
2282 "Unable to initialize ISP84XX.\n");
2283 qla84xx_put_chip(vha);
2287 /* Load the NIC Core f/w if we are the first protocol driver. */
2288 if (IS_QLA8031(ha)) {
2289 rval = qla83xx_nic_core_fw_load(vha);
2291 ql_log(ql_log_warn, vha, 0x0124,
2292 "Error in initializing NIC Core f/w.\n");
2295 if (IS_QLA24XX_TYPE(ha) || IS_QLA25XX(ha))
2296 qla24xx_read_fcp_prio_cfg(vha);
2298 if (IS_P3P_TYPE(ha))
2299 qla82xx_set_driver_version(vha, QLA2XXX_VERSION);
2301 qla25xx_set_driver_version(vha, QLA2XXX_VERSION);
2307 * qla2100_pci_config() - Setup ISP21xx PCI configuration registers.
2310 * Returns 0 on success.
2313 qla2100_pci_config(scsi_qla_host_t *vha)
2316 unsigned long flags;
2317 struct qla_hw_data *ha = vha->hw;
2318 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2320 pci_set_master(ha->pdev);
2321 pci_try_set_mwi(ha->pdev);
2323 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2324 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2325 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2327 pci_disable_rom(ha->pdev);
2329 /* Get PCI bus information. */
2330 spin_lock_irqsave(&ha->hardware_lock, flags);
2331 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2332 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2338 * qla2300_pci_config() - Setup ISP23xx PCI configuration registers.
2341 * Returns 0 on success.
2344 qla2300_pci_config(scsi_qla_host_t *vha)
2347 unsigned long flags = 0;
2349 struct qla_hw_data *ha = vha->hw;
2350 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2352 pci_set_master(ha->pdev);
2353 pci_try_set_mwi(ha->pdev);
2355 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2356 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2358 if (IS_QLA2322(ha) || IS_QLA6322(ha))
2359 w &= ~PCI_COMMAND_INTX_DISABLE;
2360 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2363 * If this is a 2300 card and not 2312, reset the
2364 * COMMAND_INVALIDATE due to a bug in the 2300. Unfortunately,
2365 * the 2310 also reports itself as a 2300 so we need to get the
2366 * fb revision level -- a 6 indicates it really is a 2300 and
2369 if (IS_QLA2300(ha)) {
2370 spin_lock_irqsave(&ha->hardware_lock, flags);
2373 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2374 for (cnt = 0; cnt < 30000; cnt++) {
2375 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) != 0)
2381 /* Select FPM registers. */
2382 WRT_REG_WORD(®->ctrl_status, 0x20);
2383 RD_REG_WORD(®->ctrl_status);
2385 /* Get the fb rev level */
2386 ha->fb_rev = RD_FB_CMD_REG(ha, reg);
2388 if (ha->fb_rev == FPM_2300)
2389 pci_clear_mwi(ha->pdev);
2391 /* Deselect FPM registers. */
2392 WRT_REG_WORD(®->ctrl_status, 0x0);
2393 RD_REG_WORD(®->ctrl_status);
2395 /* Release RISC module. */
2396 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2397 for (cnt = 0; cnt < 30000; cnt++) {
2398 if ((RD_REG_WORD(®->hccr) & HCCR_RISC_PAUSE) == 0)
2404 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2407 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2409 pci_disable_rom(ha->pdev);
2411 /* Get PCI bus information. */
2412 spin_lock_irqsave(&ha->hardware_lock, flags);
2413 ha->pci_attr = RD_REG_WORD(®->ctrl_status);
2414 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2420 * qla24xx_pci_config() - Setup ISP24xx PCI configuration registers.
2423 * Returns 0 on success.
2426 qla24xx_pci_config(scsi_qla_host_t *vha)
2429 unsigned long flags = 0;
2430 struct qla_hw_data *ha = vha->hw;
2431 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2433 pci_set_master(ha->pdev);
2434 pci_try_set_mwi(ha->pdev);
2436 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2437 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2438 w &= ~PCI_COMMAND_INTX_DISABLE;
2439 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2441 pci_write_config_byte(ha->pdev, PCI_LATENCY_TIMER, 0x80);
2443 /* PCI-X -- adjust Maximum Memory Read Byte Count (2048). */
2444 if (pci_find_capability(ha->pdev, PCI_CAP_ID_PCIX))
2445 pcix_set_mmrbc(ha->pdev, 2048);
2447 /* PCIe -- adjust Maximum Read Request Size (2048). */
2448 if (pci_is_pcie(ha->pdev))
2449 pcie_set_readrq(ha->pdev, 4096);
2451 pci_disable_rom(ha->pdev);
2453 ha->chip_revision = ha->pdev->revision;
2455 /* Get PCI bus information. */
2456 spin_lock_irqsave(&ha->hardware_lock, flags);
2457 ha->pci_attr = RD_REG_DWORD(®->ctrl_status);
2458 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2464 * qla25xx_pci_config() - Setup ISP25xx PCI configuration registers.
2467 * Returns 0 on success.
2470 qla25xx_pci_config(scsi_qla_host_t *vha)
2473 struct qla_hw_data *ha = vha->hw;
2475 pci_set_master(ha->pdev);
2476 pci_try_set_mwi(ha->pdev);
2478 pci_read_config_word(ha->pdev, PCI_COMMAND, &w);
2479 w |= (PCI_COMMAND_PARITY | PCI_COMMAND_SERR);
2480 w &= ~PCI_COMMAND_INTX_DISABLE;
2481 pci_write_config_word(ha->pdev, PCI_COMMAND, w);
2483 /* PCIe -- adjust Maximum Read Request Size (2048). */
2484 if (pci_is_pcie(ha->pdev))
2485 pcie_set_readrq(ha->pdev, 4096);
2487 pci_disable_rom(ha->pdev);
2489 ha->chip_revision = ha->pdev->revision;
2495 * qla2x00_isp_firmware() - Choose firmware image.
2498 * Returns 0 on success.
2501 qla2x00_isp_firmware(scsi_qla_host_t *vha)
2504 uint16_t loop_id, topo, sw_cap;
2505 uint8_t domain, area, al_pa;
2506 struct qla_hw_data *ha = vha->hw;
2508 /* Assume loading risc code */
2509 rval = QLA_FUNCTION_FAILED;
2511 if (ha->flags.disable_risc_code_load) {
2512 ql_log(ql_log_info, vha, 0x0079, "RISC CODE NOT loaded.\n");
2514 /* Verify checksum of loaded RISC code. */
2515 rval = qla2x00_verify_checksum(vha, ha->fw_srisc_address);
2516 if (rval == QLA_SUCCESS) {
2517 /* And, verify we are not in ROM code. */
2518 rval = qla2x00_get_adapter_id(vha, &loop_id, &al_pa,
2519 &area, &domain, &topo, &sw_cap);
2524 ql_dbg(ql_dbg_init, vha, 0x007a,
2525 "**** Load RISC code ****.\n");
2531 * qla2x00_reset_chip() - Reset ISP chip.
2534 * Returns 0 on success.
2537 qla2x00_reset_chip(scsi_qla_host_t *vha)
2539 unsigned long flags = 0;
2540 struct qla_hw_data *ha = vha->hw;
2541 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2544 int rval = QLA_FUNCTION_FAILED;
2546 if (unlikely(pci_channel_offline(ha->pdev)))
2549 ha->isp_ops->disable_intrs(ha);
2551 spin_lock_irqsave(&ha->hardware_lock, flags);
2553 /* Turn off master enable */
2555 pci_read_config_word(ha->pdev, PCI_COMMAND, &cmd);
2556 cmd &= ~PCI_COMMAND_MASTER;
2557 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2559 if (!IS_QLA2100(ha)) {
2561 WRT_REG_WORD(®->hccr, HCCR_PAUSE_RISC);
2562 if (IS_QLA2200(ha) || IS_QLA2300(ha)) {
2563 for (cnt = 0; cnt < 30000; cnt++) {
2564 if ((RD_REG_WORD(®->hccr) &
2565 HCCR_RISC_PAUSE) != 0)
2570 RD_REG_WORD(®->hccr); /* PCI Posting. */
2574 /* Select FPM registers. */
2575 WRT_REG_WORD(®->ctrl_status, 0x20);
2576 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2578 /* FPM Soft Reset. */
2579 WRT_REG_WORD(®->fpm_diag_config, 0x100);
2580 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2582 /* Toggle Fpm Reset. */
2583 if (!IS_QLA2200(ha)) {
2584 WRT_REG_WORD(®->fpm_diag_config, 0x0);
2585 RD_REG_WORD(®->fpm_diag_config); /* PCI Posting. */
2588 /* Select frame buffer registers. */
2589 WRT_REG_WORD(®->ctrl_status, 0x10);
2590 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2592 /* Reset frame buffer FIFOs. */
2593 if (IS_QLA2200(ha)) {
2594 WRT_FB_CMD_REG(ha, reg, 0xa000);
2595 RD_FB_CMD_REG(ha, reg); /* PCI Posting. */
2597 WRT_FB_CMD_REG(ha, reg, 0x00fc);
2599 /* Read back fb_cmd until zero or 3 seconds max */
2600 for (cnt = 0; cnt < 3000; cnt++) {
2601 if ((RD_FB_CMD_REG(ha, reg) & 0xff) == 0)
2607 /* Select RISC module registers. */
2608 WRT_REG_WORD(®->ctrl_status, 0);
2609 RD_REG_WORD(®->ctrl_status); /* PCI Posting. */
2611 /* Reset RISC processor. */
2612 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2613 RD_REG_WORD(®->hccr); /* PCI Posting. */
2615 /* Release RISC processor. */
2616 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2617 RD_REG_WORD(®->hccr); /* PCI Posting. */
2620 WRT_REG_WORD(®->hccr, HCCR_CLR_RISC_INT);
2621 WRT_REG_WORD(®->hccr, HCCR_CLR_HOST_INT);
2623 /* Reset ISP chip. */
2624 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2626 /* Wait for RISC to recover from reset. */
2627 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2629 * It is necessary to for a delay here since the card doesn't
2630 * respond to PCI reads during a reset. On some architectures
2631 * this will result in an MCA.
2634 for (cnt = 30000; cnt; cnt--) {
2635 if ((RD_REG_WORD(®->ctrl_status) &
2636 CSR_ISP_SOFT_RESET) == 0)
2643 /* Reset RISC processor. */
2644 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2646 WRT_REG_WORD(®->semaphore, 0);
2648 /* Release RISC processor. */
2649 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2650 RD_REG_WORD(®->hccr); /* PCI Posting. */
2652 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2653 for (cnt = 0; cnt < 30000; cnt++) {
2654 if (RD_MAILBOX_REG(ha, reg, 0) != MBS_BUSY)
2662 /* Turn on master enable */
2663 cmd |= PCI_COMMAND_MASTER;
2664 pci_write_config_word(ha->pdev, PCI_COMMAND, cmd);
2666 /* Disable RISC pause on FPM parity error. */
2667 if (!IS_QLA2100(ha)) {
2668 WRT_REG_WORD(®->hccr, HCCR_DISABLE_PARITY_PAUSE);
2669 RD_REG_WORD(®->hccr); /* PCI Posting. */
2672 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2678 * qla81xx_reset_mpi() - Reset's MPI FW via Write MPI Register MBC.
2681 * Returns 0 on success.
2684 qla81xx_reset_mpi(scsi_qla_host_t *vha)
2686 uint16_t mb[4] = {0x1010, 0, 1, 0};
2688 if (!IS_QLA81XX(vha->hw))
2691 return qla81xx_write_mpi_register(vha, mb);
2695 * qla24xx_reset_risc() - Perform full reset of ISP24xx RISC.
2698 * Returns 0 on success.
2701 qla24xx_reset_risc(scsi_qla_host_t *vha)
2703 unsigned long flags = 0;
2704 struct qla_hw_data *ha = vha->hw;
2705 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
2708 static int abts_cnt; /* ISP abort retry counts */
2709 int rval = QLA_SUCCESS;
2711 spin_lock_irqsave(&ha->hardware_lock, flags);
2714 WRT_REG_DWORD(®->ctrl_status, CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2715 for (cnt = 0; cnt < 30000; cnt++) {
2716 if ((RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE) == 0)
2722 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE))
2723 set_bit(DMA_SHUTDOWN_CMPL, &ha->fw_dump_cap_flags);
2725 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017e,
2726 "HCCR: 0x%x, Control Status %x, DMA active status:0x%x\n",
2727 RD_REG_DWORD(®->hccr),
2728 RD_REG_DWORD(®->ctrl_status),
2729 (RD_REG_DWORD(®->ctrl_status) & CSRX_DMA_ACTIVE));
2731 WRT_REG_DWORD(®->ctrl_status,
2732 CSRX_ISP_SOFT_RESET|CSRX_DMA_SHUTDOWN|MWB_4096_BYTES);
2733 pci_read_config_word(ha->pdev, PCI_COMMAND, &wd);
2737 /* Wait for firmware to complete NVRAM accesses. */
2738 RD_REG_WORD(®->mailbox0);
2739 for (cnt = 10000; RD_REG_WORD(®->mailbox0) != 0 &&
2740 rval == QLA_SUCCESS; cnt--) {
2745 rval = QLA_FUNCTION_TIMEOUT;
2748 if (rval == QLA_SUCCESS)
2749 set_bit(ISP_MBX_RDY, &ha->fw_dump_cap_flags);
2751 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x017f,
2752 "HCCR: 0x%x, MailBox0 Status 0x%x\n",
2753 RD_REG_DWORD(®->hccr),
2754 RD_REG_DWORD(®->mailbox0));
2756 /* Wait for soft-reset to complete. */
2757 RD_REG_DWORD(®->ctrl_status);
2758 for (cnt = 0; cnt < 60; cnt++) {
2760 if ((RD_REG_DWORD(®->ctrl_status) &
2761 CSRX_ISP_SOFT_RESET) == 0)
2766 if (!(RD_REG_DWORD(®->ctrl_status) & CSRX_ISP_SOFT_RESET))
2767 set_bit(ISP_SOFT_RESET_CMPL, &ha->fw_dump_cap_flags);
2769 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015d,
2770 "HCCR: 0x%x, Soft Reset status: 0x%x\n",
2771 RD_REG_DWORD(®->hccr),
2772 RD_REG_DWORD(®->ctrl_status));
2774 /* If required, do an MPI FW reset now */
2775 if (test_and_clear_bit(MPI_RESET_NEEDED, &vha->dpc_flags)) {
2776 if (qla81xx_reset_mpi(vha) != QLA_SUCCESS) {
2777 if (++abts_cnt < 5) {
2778 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
2779 set_bit(MPI_RESET_NEEDED, &vha->dpc_flags);
2782 * We exhausted the ISP abort retries. We have to
2783 * set the board offline.
2786 vha->flags.online = 0;
2791 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
2792 RD_REG_DWORD(®->hccr);
2794 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
2795 RD_REG_DWORD(®->hccr);
2797 WRT_REG_DWORD(®->hccr, HCCRX_CLR_RISC_RESET);
2798 RD_REG_DWORD(®->hccr);
2800 RD_REG_WORD(®->mailbox0);
2801 for (cnt = 60; RD_REG_WORD(®->mailbox0) != 0 &&
2802 rval == QLA_SUCCESS; cnt--) {
2807 rval = QLA_FUNCTION_TIMEOUT;
2809 if (rval == QLA_SUCCESS)
2810 set_bit(RISC_RDY_AFT_RESET, &ha->fw_dump_cap_flags);
2812 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015e,
2813 "Host Risc 0x%x, mailbox0 0x%x\n",
2814 RD_REG_DWORD(®->hccr),
2815 RD_REG_WORD(®->mailbox0));
2817 spin_unlock_irqrestore(&ha->hardware_lock, flags);
2819 ql_dbg(ql_dbg_init + ql_dbg_verbose, vha, 0x015f,
2820 "Driver in %s mode\n",
2821 IS_NOPOLLING_TYPE(ha) ? "Interrupt" : "Polling");
2823 if (IS_NOPOLLING_TYPE(ha))
2824 ha->isp_ops->enable_intrs(ha);
2830 qla25xx_read_risc_sema_reg(scsi_qla_host_t *vha, uint32_t *data)
2832 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2834 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2835 *data = RD_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET);
2840 qla25xx_write_risc_sema_reg(scsi_qla_host_t *vha, uint32_t data)
2842 struct device_reg_24xx __iomem *reg = &vha->hw->iobase->isp24;
2844 WRT_REG_DWORD(®->iobase_addr, RISC_REGISTER_BASE_OFFSET);
2845 WRT_REG_DWORD(®->iobase_window + RISC_REGISTER_WINDOW_OFFET, data);
2849 qla25xx_manipulate_risc_semaphore(scsi_qla_host_t *vha)
2852 uint delta_msec = 100;
2853 uint elapsed_msec = 0;
2857 if (vha->hw->pdev->subsystem_device != 0x0175 &&
2858 vha->hw->pdev->subsystem_device != 0x0240)
2861 WRT_REG_DWORD(&vha->hw->iobase->isp24.hccr, HCCRX_SET_RISC_PAUSE);
2865 timeout_msec = TIMEOUT_SEMAPHORE;
2866 n = timeout_msec / delta_msec;
2868 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_SET);
2869 qla25xx_read_risc_sema_reg(vha, &wd32);
2870 if (wd32 & RISC_SEMAPHORE)
2873 elapsed_msec += delta_msec;
2874 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2878 if (!(wd32 & RISC_SEMAPHORE))
2881 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2884 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_CLR);
2885 timeout_msec = TIMEOUT_SEMAPHORE_FORCE;
2886 n = timeout_msec / delta_msec;
2888 qla25xx_read_risc_sema_reg(vha, &wd32);
2889 if (!(wd32 & RISC_SEMAPHORE_FORCE))
2892 elapsed_msec += delta_msec;
2893 if (elapsed_msec > TIMEOUT_TOTAL_ELAPSED)
2897 if (wd32 & RISC_SEMAPHORE_FORCE)
2898 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_CLR);
2903 qla25xx_write_risc_sema_reg(vha, RISC_SEMAPHORE_FORCE_SET);
2910 * qla24xx_reset_chip() - Reset ISP24xx chip.
2913 * Returns 0 on success.
2916 qla24xx_reset_chip(scsi_qla_host_t *vha)
2918 struct qla_hw_data *ha = vha->hw;
2919 int rval = QLA_FUNCTION_FAILED;
2921 if (pci_channel_offline(ha->pdev) &&
2922 ha->flags.pci_channel_io_perm_failure) {
2926 ha->isp_ops->disable_intrs(ha);
2928 qla25xx_manipulate_risc_semaphore(vha);
2930 /* Perform RISC reset. */
2931 rval = qla24xx_reset_risc(vha);
2937 * qla2x00_chip_diag() - Test chip for proper operation.
2940 * Returns 0 on success.
2943 qla2x00_chip_diag(scsi_qla_host_t *vha)
2946 struct qla_hw_data *ha = vha->hw;
2947 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
2948 unsigned long flags = 0;
2952 struct req_que *req = ha->req_q_map[0];
2954 /* Assume a failed state */
2955 rval = QLA_FUNCTION_FAILED;
2957 ql_dbg(ql_dbg_init, vha, 0x007b, "Testing device at %p.\n",
2958 ®->flash_address);
2960 spin_lock_irqsave(&ha->hardware_lock, flags);
2962 /* Reset ISP chip. */
2963 WRT_REG_WORD(®->ctrl_status, CSR_ISP_SOFT_RESET);
2966 * We need to have a delay here since the card will not respond while
2967 * in reset causing an MCA on some architectures.
2970 data = qla2x00_debounce_register(®->ctrl_status);
2971 for (cnt = 6000000 ; cnt && (data & CSR_ISP_SOFT_RESET); cnt--) {
2973 data = RD_REG_WORD(®->ctrl_status);
2978 goto chip_diag_failed;
2980 ql_dbg(ql_dbg_init, vha, 0x007c,
2981 "Reset register cleared by chip reset.\n");
2983 /* Reset RISC processor. */
2984 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
2985 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
2987 /* Workaround for QLA2312 PCI parity error */
2988 if (IS_QLA2100(ha) || IS_QLA2200(ha) || IS_QLA2300(ha)) {
2989 data = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 0));
2990 for (cnt = 6000000; cnt && (data == MBS_BUSY); cnt--) {
2992 data = RD_MAILBOX_REG(ha, reg, 0);
2999 goto chip_diag_failed;
3001 /* Check product ID of chip */
3002 ql_dbg(ql_dbg_init, vha, 0x007d, "Checking product ID of chip.\n");
3004 mb[1] = RD_MAILBOX_REG(ha, reg, 1);
3005 mb[2] = RD_MAILBOX_REG(ha, reg, 2);
3006 mb[3] = RD_MAILBOX_REG(ha, reg, 3);
3007 mb[4] = qla2x00_debounce_register(MAILBOX_REG(ha, reg, 4));
3008 if (mb[1] != PROD_ID_1 || (mb[2] != PROD_ID_2 && mb[2] != PROD_ID_2a) ||
3009 mb[3] != PROD_ID_3) {
3010 ql_log(ql_log_warn, vha, 0x0062,
3011 "Wrong product ID = 0x%x,0x%x,0x%x.\n",
3012 mb[1], mb[2], mb[3]);
3014 goto chip_diag_failed;
3016 ha->product_id[0] = mb[1];
3017 ha->product_id[1] = mb[2];
3018 ha->product_id[2] = mb[3];
3019 ha->product_id[3] = mb[4];
3021 /* Adjust fw RISC transfer size */
3022 if (req->length > 1024)
3023 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * 1024;
3025 ha->fw_transfer_size = REQUEST_ENTRY_SIZE *
3028 if (IS_QLA2200(ha) &&
3029 RD_MAILBOX_REG(ha, reg, 7) == QLA2200A_RISC_ROM_VER) {
3030 /* Limit firmware transfer size with a 2200A */
3031 ql_dbg(ql_dbg_init, vha, 0x007e, "Found QLA2200A Chip.\n");
3033 ha->device_type |= DT_ISP2200A;
3034 ha->fw_transfer_size = 128;
3037 /* Wrap Incoming Mailboxes Test. */
3038 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3040 ql_dbg(ql_dbg_init, vha, 0x007f, "Checking mailboxes.\n");
3041 rval = qla2x00_mbx_reg_test(vha);
3043 ql_log(ql_log_warn, vha, 0x0080,
3044 "Failed mailbox send register test.\n");
3046 /* Flag a successful rval */
3048 spin_lock_irqsave(&ha->hardware_lock, flags);
3052 ql_log(ql_log_info, vha, 0x0081,
3053 "Chip diagnostics **** FAILED ****.\n");
3055 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3061 * qla24xx_chip_diag() - Test ISP24xx for proper operation.
3064 * Returns 0 on success.
3067 qla24xx_chip_diag(scsi_qla_host_t *vha)
3070 struct qla_hw_data *ha = vha->hw;
3071 struct req_que *req = ha->req_q_map[0];
3073 if (IS_P3P_TYPE(ha))
3076 ha->fw_transfer_size = REQUEST_ENTRY_SIZE * req->length;
3078 rval = qla2x00_mbx_reg_test(vha);
3080 ql_log(ql_log_warn, vha, 0x0082,
3081 "Failed mailbox send register test.\n");
3083 /* Flag a successful rval */
3091 qla2x00_alloc_offload_mem(scsi_qla_host_t *vha)
3096 struct qla_hw_data *ha = vha->hw;
3099 ql_dbg(ql_dbg_init, vha, 0x00bd,
3100 "%s: Offload Mem is already allocated.\n",
3105 if (IS_FWI2_CAPABLE(ha)) {
3106 /* Allocate memory for Fibre Channel Event Buffer. */
3107 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3108 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3112 dma_free_coherent(&ha->pdev->dev,
3113 FCE_SIZE, ha->fce, ha->fce_dma);
3115 /* Allocate memory for Fibre Channel Event Buffer. */
3116 tc = dma_alloc_coherent(&ha->pdev->dev, FCE_SIZE, &tc_dma,
3119 ql_log(ql_log_warn, vha, 0x00be,
3120 "Unable to allocate (%d KB) for FCE.\n",
3125 rval = qla2x00_enable_fce_trace(vha, tc_dma, FCE_NUM_BUFFERS,
3126 ha->fce_mb, &ha->fce_bufs);
3128 ql_log(ql_log_warn, vha, 0x00bf,
3129 "Unable to initialize FCE (%d).\n", rval);
3130 dma_free_coherent(&ha->pdev->dev, FCE_SIZE, tc,
3132 ha->flags.fce_enabled = 0;
3135 ql_dbg(ql_dbg_init, vha, 0x00c0,
3136 "Allocate (%d KB) for FCE...\n", FCE_SIZE / 1024);
3138 ha->flags.fce_enabled = 1;
3139 ha->fce_dma = tc_dma;
3144 dma_free_coherent(&ha->pdev->dev,
3145 EFT_SIZE, ha->eft, ha->eft_dma);
3147 /* Allocate memory for Extended Trace Buffer. */
3148 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3151 ql_log(ql_log_warn, vha, 0x00c1,
3152 "Unable to allocate (%d KB) for EFT.\n",
3157 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3159 ql_log(ql_log_warn, vha, 0x00c2,
3160 "Unable to initialize EFT (%d).\n", rval);
3161 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3165 ql_dbg(ql_dbg_init, vha, 0x00c3,
3166 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3168 ha->eft_dma = tc_dma;
3177 qla2x00_alloc_fw_dump(scsi_qla_host_t *vha)
3180 uint32_t dump_size, fixed_size, mem_size, req_q_size, rsp_q_size,
3181 eft_size, fce_size, mq_size;
3182 struct qla_hw_data *ha = vha->hw;
3183 struct req_que *req = ha->req_q_map[0];
3184 struct rsp_que *rsp = ha->rsp_q_map[0];
3185 struct qla2xxx_fw_dump *fw_dump;
3189 dump_size = fixed_size = mem_size = eft_size = fce_size = mq_size = 0;
3190 req_q_size = rsp_q_size = 0;
3192 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
3193 fixed_size = sizeof(struct qla2100_fw_dump);
3194 } else if (IS_QLA23XX(ha)) {
3195 fixed_size = offsetof(struct qla2300_fw_dump, data_ram);
3196 mem_size = (ha->fw_memory_size - 0x11000 + 1) *
3198 } else if (IS_FWI2_CAPABLE(ha)) {
3199 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))
3200 fixed_size = offsetof(struct qla83xx_fw_dump, ext_mem);
3201 else if (IS_QLA81XX(ha))
3202 fixed_size = offsetof(struct qla81xx_fw_dump, ext_mem);
3203 else if (IS_QLA25XX(ha))
3204 fixed_size = offsetof(struct qla25xx_fw_dump, ext_mem);
3206 fixed_size = offsetof(struct qla24xx_fw_dump, ext_mem);
3208 mem_size = (ha->fw_memory_size - 0x100000 + 1) *
3211 if (!IS_QLA83XX(ha) && !IS_QLA27XX(ha) &&
3213 mq_size = sizeof(struct qla2xxx_mq_chain);
3215 * Allocate maximum buffer size for all queues - Q0.
3216 * Resizing must be done at end-of-dump processing.
3218 mq_size += (ha->max_req_queues - 1) *
3219 (req->length * sizeof(request_t));
3220 mq_size += (ha->max_rsp_queues - 1) *
3221 (rsp->length * sizeof(response_t));
3223 if (ha->tgt.atio_ring)
3224 mq_size += ha->tgt.atio_q_length * sizeof(request_t);
3225 /* Allocate memory for Fibre Channel Event Buffer. */
3226 if (!IS_QLA25XX(ha) && !IS_QLA81XX(ha) && !IS_QLA83XX(ha) &&
3227 !IS_QLA27XX(ha) && !IS_QLA28XX(ha))
3230 fce_size = sizeof(struct qla2xxx_fce_chain) + FCE_SIZE;
3233 dma_free_coherent(&ha->pdev->dev,
3234 EFT_SIZE, ha->eft, ha->eft_dma);
3236 /* Allocate memory for Extended Trace Buffer. */
3237 tc = dma_alloc_coherent(&ha->pdev->dev, EFT_SIZE, &tc_dma,
3240 ql_log(ql_log_warn, vha, 0x00c1,
3241 "Unable to allocate (%d KB) for EFT.\n",
3246 rval = qla2x00_enable_eft_trace(vha, tc_dma, EFT_NUM_BUFFERS);
3248 ql_log(ql_log_warn, vha, 0x00c2,
3249 "Unable to initialize EFT (%d).\n", rval);
3250 dma_free_coherent(&ha->pdev->dev, EFT_SIZE, tc,
3253 ql_dbg(ql_dbg_init, vha, 0x00c3,
3254 "Allocated (%d KB) EFT ...\n", EFT_SIZE / 1024);
3255 eft_size = EFT_SIZE;
3258 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3259 struct fwdt *fwdt = ha->fwdt;
3262 for (j = 0; j < 2; j++, fwdt++) {
3263 if (!fwdt->template) {
3264 ql_log(ql_log_warn, vha, 0x00ba,
3265 "-> fwdt%u no template\n", j);
3268 ql_dbg(ql_dbg_init, vha, 0x00fa,
3269 "-> fwdt%u calculating fwdump size...\n", j);
3270 fwdt->dump_size = qla27xx_fwdt_calculate_dump_size(
3271 vha, fwdt->template);
3272 ql_dbg(ql_dbg_init, vha, 0x00fa,
3273 "-> fwdt%u calculated fwdump size = %#lx bytes\n",
3274 j, fwdt->dump_size);
3275 dump_size += fwdt->dump_size;
3280 req_q_size = req->length * sizeof(request_t);
3281 rsp_q_size = rsp->length * sizeof(response_t);
3282 dump_size = offsetof(struct qla2xxx_fw_dump, isp);
3283 dump_size += fixed_size + mem_size + req_q_size + rsp_q_size + eft_size;
3284 ha->chain_offset = dump_size;
3285 dump_size += mq_size + fce_size;
3287 if (ha->exchoffld_buf)
3288 dump_size += sizeof(struct qla2xxx_offld_chain) +
3290 if (ha->exlogin_buf)
3291 dump_size += sizeof(struct qla2xxx_offld_chain) +
3295 if (!ha->fw_dump_len || dump_size > ha->fw_dump_alloc_len) {
3297 ql_dbg(ql_dbg_init, vha, 0x00c5,
3298 "%s dump_size %d fw_dump_len %d fw_dump_alloc_len %d\n",
3299 __func__, dump_size, ha->fw_dump_len,
3300 ha->fw_dump_alloc_len);
3302 fw_dump = vmalloc(dump_size);
3304 ql_log(ql_log_warn, vha, 0x00c4,
3305 "Unable to allocate (%d KB) for firmware dump.\n",
3308 mutex_lock(&ha->optrom_mutex);
3309 if (ha->fw_dumped) {
3310 memcpy(fw_dump, ha->fw_dump, ha->fw_dump_len);
3312 ha->fw_dump = fw_dump;
3313 ha->fw_dump_alloc_len = dump_size;
3314 ql_dbg(ql_dbg_init, vha, 0x00c5,
3315 "Re-Allocated (%d KB) and save firmware dump.\n",
3320 ha->fw_dump = fw_dump;
3322 ha->fw_dump_len = ha->fw_dump_alloc_len =
3324 ql_dbg(ql_dbg_init, vha, 0x00c5,
3325 "Allocated (%d KB) for firmware dump.\n",
3328 if (IS_QLA27XX(ha) || IS_QLA28XX(ha)) {
3329 mutex_unlock(&ha->optrom_mutex);
3333 ha->fw_dump->signature[0] = 'Q';
3334 ha->fw_dump->signature[1] = 'L';
3335 ha->fw_dump->signature[2] = 'G';
3336 ha->fw_dump->signature[3] = 'C';
3337 ha->fw_dump->version = htonl(1);
3339 ha->fw_dump->fixed_size = htonl(fixed_size);
3340 ha->fw_dump->mem_size = htonl(mem_size);
3341 ha->fw_dump->req_q_size = htonl(req_q_size);
3342 ha->fw_dump->rsp_q_size = htonl(rsp_q_size);
3344 ha->fw_dump->eft_size = htonl(eft_size);
3345 ha->fw_dump->eft_addr_l =
3346 htonl(LSD(ha->eft_dma));
3347 ha->fw_dump->eft_addr_h =
3348 htonl(MSD(ha->eft_dma));
3350 ha->fw_dump->header_size =
3352 (struct qla2xxx_fw_dump, isp));
3354 mutex_unlock(&ha->optrom_mutex);
3360 qla81xx_mpi_sync(scsi_qla_host_t *vha)
3362 #define MPS_MASK 0xe0
3367 if (!IS_QLA81XX(vha->hw))
3370 rval = qla2x00_write_ram_word(vha, 0x7c00, 1);
3371 if (rval != QLA_SUCCESS) {
3372 ql_log(ql_log_warn, vha, 0x0105,
3373 "Unable to acquire semaphore.\n");
3377 pci_read_config_word(vha->hw->pdev, 0x54, &dc);
3378 rval = qla2x00_read_ram_word(vha, 0x7a15, &dw);
3379 if (rval != QLA_SUCCESS) {
3380 ql_log(ql_log_warn, vha, 0x0067, "Unable to read sync.\n");
3385 if (dc == (dw & MPS_MASK))
3390 rval = qla2x00_write_ram_word(vha, 0x7a15, dw);
3391 if (rval != QLA_SUCCESS) {
3392 ql_log(ql_log_warn, vha, 0x0114, "Unable to gain sync.\n");
3396 rval = qla2x00_write_ram_word(vha, 0x7c00, 0);
3397 if (rval != QLA_SUCCESS) {
3398 ql_log(ql_log_warn, vha, 0x006d,
3399 "Unable to release semaphore.\n");
3407 qla2x00_alloc_outstanding_cmds(struct qla_hw_data *ha, struct req_que *req)
3409 /* Don't try to reallocate the array */
3410 if (req->outstanding_cmds)
3413 if (!IS_FWI2_CAPABLE(ha))
3414 req->num_outstanding_cmds = DEFAULT_OUTSTANDING_COMMANDS;
3416 if (ha->cur_fw_xcb_count <= ha->cur_fw_iocb_count)
3417 req->num_outstanding_cmds = ha->cur_fw_xcb_count;
3419 req->num_outstanding_cmds = ha->cur_fw_iocb_count;
3422 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3426 if (!req->outstanding_cmds) {
3428 * Try to allocate a minimal size just so we can get through
3431 req->num_outstanding_cmds = MIN_OUTSTANDING_COMMANDS;
3432 req->outstanding_cmds = kcalloc(req->num_outstanding_cmds,
3436 if (!req->outstanding_cmds) {
3437 ql_log(ql_log_fatal, NULL, 0x0126,
3438 "Failed to allocate memory for "
3439 "outstanding_cmds for req_que %p.\n", req);
3440 req->num_outstanding_cmds = 0;
3441 return QLA_FUNCTION_FAILED;
3448 #define PRINT_FIELD(_field, _flag, _str) { \
3449 if (a0->_field & _flag) {\
3455 len = snprintf(ptr, leftover, "%s", _str); \
3462 static void qla2xxx_print_sfp_info(struct scsi_qla_host *vha)
3465 struct sff_8247_a0 *a0 = (struct sff_8247_a0 *)vha->hw->sfp_data;
3466 u8 str[STR_LEN], *ptr, p;
3469 memset(str, 0, STR_LEN);
3470 snprintf(str, SFF_VEN_NAME_LEN+1, a0->vendor_name);
3471 ql_dbg(ql_dbg_init, vha, 0x015a,
3472 "SFP MFG Name: %s\n", str);
3474 memset(str, 0, STR_LEN);
3475 snprintf(str, SFF_PART_NAME_LEN+1, a0->vendor_pn);
3476 ql_dbg(ql_dbg_init, vha, 0x015c,
3477 "SFP Part Name: %s\n", str);
3480 memset(str, 0, STR_LEN);
3484 PRINT_FIELD(fc_med_cc9, FC_MED_TW, "Twin AX");
3485 PRINT_FIELD(fc_med_cc9, FC_MED_TP, "Twisted Pair");
3486 PRINT_FIELD(fc_med_cc9, FC_MED_MI, "Min Coax");
3487 PRINT_FIELD(fc_med_cc9, FC_MED_TV, "Video Coax");
3488 PRINT_FIELD(fc_med_cc9, FC_MED_M6, "MultiMode 62.5um");
3489 PRINT_FIELD(fc_med_cc9, FC_MED_M5, "MultiMode 50um");
3490 PRINT_FIELD(fc_med_cc9, FC_MED_SM, "SingleMode");
3491 ql_dbg(ql_dbg_init, vha, 0x0160,
3492 "SFP Media: %s\n", str);
3495 memset(str, 0, STR_LEN);
3499 PRINT_FIELD(fc_ll_cc7, FC_LL_VL, "Very Long");
3500 PRINT_FIELD(fc_ll_cc7, FC_LL_S, "Short");
3501 PRINT_FIELD(fc_ll_cc7, FC_LL_I, "Intermediate");
3502 PRINT_FIELD(fc_ll_cc7, FC_LL_L, "Long");
3503 PRINT_FIELD(fc_ll_cc7, FC_LL_M, "Medium");
3504 ql_dbg(ql_dbg_init, vha, 0x0196,
3505 "SFP Link Length: %s\n", str);
3507 memset(str, 0, STR_LEN);
3511 PRINT_FIELD(fc_ll_cc7, FC_LL_SA, "Short Wave (SA)");
3512 PRINT_FIELD(fc_ll_cc7, FC_LL_LC, "Long Wave(LC)");
3513 PRINT_FIELD(fc_tec_cc8, FC_TEC_SN, "Short Wave (SN)");
3514 PRINT_FIELD(fc_tec_cc8, FC_TEC_SL, "Short Wave (SL)");
3515 PRINT_FIELD(fc_tec_cc8, FC_TEC_LL, "Long Wave (LL)");
3516 ql_dbg(ql_dbg_init, vha, 0x016e,
3517 "SFP FC Link Tech: %s\n", str);
3520 ql_dbg(ql_dbg_init, vha, 0x016f,
3521 "SFP Distant: %d km\n", a0->length_km);
3522 if (a0->length_100m)
3523 ql_dbg(ql_dbg_init, vha, 0x0170,
3524 "SFP Distant: %d m\n", a0->length_100m*100);
3525 if (a0->length_50um_10m)
3526 ql_dbg(ql_dbg_init, vha, 0x0189,
3527 "SFP Distant (WL=50um): %d m\n", a0->length_50um_10m * 10);
3528 if (a0->length_62um_10m)
3529 ql_dbg(ql_dbg_init, vha, 0x018a,
3530 "SFP Distant (WL=62.5um): %d m\n", a0->length_62um_10m * 10);
3531 if (a0->length_om4_10m)
3532 ql_dbg(ql_dbg_init, vha, 0x0194,
3533 "SFP Distant (OM4): %d m\n", a0->length_om4_10m * 10);
3534 if (a0->length_om3_10m)
3535 ql_dbg(ql_dbg_init, vha, 0x0195,
3536 "SFP Distant (OM3): %d m\n", a0->length_om3_10m * 10);
3542 * QLA_SUCCESS: no action
3543 * QLA_INTERFACE_ERROR: SFP is not there.
3544 * QLA_FUNCTION_FAILED: detected New SFP
3547 qla24xx_detect_sfp(scsi_qla_host_t *vha)
3549 int rc = QLA_SUCCESS;
3550 struct sff_8247_a0 *a;
3551 struct qla_hw_data *ha = vha->hw;
3553 if (!AUTO_DETECT_SFP_SUPPORT(vha))
3556 rc = qla2x00_read_sfp_dev(vha, NULL, 0);
3560 a = (struct sff_8247_a0 *)vha->hw->sfp_data;
3561 qla2xxx_print_sfp_info(vha);
3563 if (a->fc_ll_cc7 & FC_LL_VL || a->fc_ll_cc7 & FC_LL_L) {
3565 ha->flags.detected_lr_sfp = 1;
3567 if (a->length_km > 5 || a->length_100m > 50)
3568 ha->long_range_distance = LR_DISTANCE_10K;
3570 ha->long_range_distance = LR_DISTANCE_5K;
3572 if (ha->flags.detected_lr_sfp != ha->flags.using_lr_setting)
3573 ql_dbg(ql_dbg_async, vha, 0x507b,
3574 "Detected Long Range SFP.\n");
3577 ha->flags.detected_lr_sfp = 0;
3578 if (ha->flags.using_lr_setting)
3579 ql_dbg(ql_dbg_async, vha, 0x5084,
3580 "Detected Short Range SFP.\n");
3583 if (!vha->flags.init_done)
3590 * qla2x00_setup_chip() - Load and start RISC firmware.
3593 * Returns 0 on success.
3596 qla2x00_setup_chip(scsi_qla_host_t *vha)
3599 uint32_t srisc_address = 0;
3600 struct qla_hw_data *ha = vha->hw;
3601 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3602 unsigned long flags;
3603 uint16_t fw_major_version;
3605 if (IS_P3P_TYPE(ha)) {
3606 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3607 if (rval == QLA_SUCCESS) {
3608 qla2x00_stop_firmware(vha);
3609 goto enable_82xx_npiv;
3614 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3615 /* Disable SRAM, Instruction RAM and GP RAM parity. */
3616 spin_lock_irqsave(&ha->hardware_lock, flags);
3617 WRT_REG_WORD(®->hccr, (HCCR_ENABLE_PARITY + 0x0));
3618 RD_REG_WORD(®->hccr);
3619 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3622 qla81xx_mpi_sync(vha);
3624 /* Load firmware sequences */
3625 rval = ha->isp_ops->load_risc(vha, &srisc_address);
3626 if (rval == QLA_SUCCESS) {
3627 ql_dbg(ql_dbg_init, vha, 0x00c9,
3628 "Verifying Checksum of loaded RISC code.\n");
3630 rval = qla2x00_verify_checksum(vha, srisc_address);
3631 if (rval == QLA_SUCCESS) {
3632 /* Start firmware execution. */
3633 ql_dbg(ql_dbg_init, vha, 0x00ca,
3634 "Starting firmware.\n");
3637 ha->flags.exlogins_enabled = 1;
3639 if (qla_is_exch_offld_enabled(vha))
3640 ha->flags.exchoffld_enabled = 1;
3642 rval = qla2x00_execute_fw(vha, srisc_address);
3643 /* Retrieve firmware information. */
3644 if (rval == QLA_SUCCESS) {
3645 qla24xx_detect_sfp(vha);
3647 if ((IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3649 (ha->zio_mode == QLA_ZIO_MODE_6))
3650 qla27xx_set_zio_threshold(vha,
3651 ha->last_zio_threshold);
3653 rval = qla2x00_set_exlogins_buffer(vha);
3654 if (rval != QLA_SUCCESS)
3657 rval = qla2x00_set_exchoffld_buffer(vha);
3658 if (rval != QLA_SUCCESS)
3662 fw_major_version = ha->fw_major_version;
3663 if (IS_P3P_TYPE(ha))
3664 qla82xx_check_md_needed(vha);
3666 rval = qla2x00_get_fw_version(vha);
3667 if (rval != QLA_SUCCESS)
3669 ha->flags.npiv_supported = 0;
3670 if (IS_QLA2XXX_MIDTYPE(ha) &&
3671 (ha->fw_attributes & BIT_2)) {
3672 ha->flags.npiv_supported = 1;
3673 if ((!ha->max_npiv_vports) ||
3674 ((ha->max_npiv_vports + 1) %
3675 MIN_MULTI_ID_FABRIC))
3676 ha->max_npiv_vports =
3677 MIN_MULTI_ID_FABRIC - 1;
3679 qla2x00_get_resource_cnts(vha);
3682 * Allocate the array of outstanding commands
3683 * now that we know the firmware resources.
3685 rval = qla2x00_alloc_outstanding_cmds(ha,
3687 if (rval != QLA_SUCCESS)
3690 if (!fw_major_version && !(IS_P3P_TYPE(ha)))
3691 qla2x00_alloc_offload_mem(vha);
3693 if (ql2xallocfwdump && !(IS_P3P_TYPE(ha)))
3694 qla2x00_alloc_fw_dump(vha);
3700 ql_log(ql_log_fatal, vha, 0x00cd,
3701 "ISP Firmware failed checksum.\n");
3707 if (!IS_FWI2_CAPABLE(ha) && !IS_QLA2100(ha) && !IS_QLA2200(ha)) {
3708 /* Enable proper parity. */
3709 spin_lock_irqsave(&ha->hardware_lock, flags);
3712 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x1);
3714 /* SRAM, Instruction RAM and GP RAM parity */
3715 WRT_REG_WORD(®->hccr, HCCR_ENABLE_PARITY + 0x7);
3716 RD_REG_WORD(®->hccr);
3717 spin_unlock_irqrestore(&ha->hardware_lock, flags);
3720 if (IS_QLA27XX(ha) || IS_QLA28XX(ha))
3721 ha->flags.fac_supported = 1;
3722 else if (rval == QLA_SUCCESS && IS_FAC_REQUIRED(ha)) {
3725 rval = qla81xx_fac_get_sector_size(vha, &size);
3726 if (rval == QLA_SUCCESS) {
3727 ha->flags.fac_supported = 1;
3728 ha->fdt_block_size = size << 2;
3730 ql_log(ql_log_warn, vha, 0x00ce,
3731 "Unsupported FAC firmware (%d.%02d.%02d).\n",
3732 ha->fw_major_version, ha->fw_minor_version,
3733 ha->fw_subminor_version);
3735 if (IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3737 ha->flags.fac_supported = 0;
3744 ql_log(ql_log_fatal, vha, 0x00cf,
3745 "Setup chip ****FAILED****.\n");
3752 * qla2x00_init_response_q_entries() - Initializes response queue entries.
3753 * @rsp: response queue
3755 * Beginning of request ring has initialization control block already built
3756 * by nvram config routine.
3758 * Returns 0 on success.
3761 qla2x00_init_response_q_entries(struct rsp_que *rsp)
3766 rsp->ring_ptr = rsp->ring;
3767 rsp->ring_index = 0;
3768 rsp->status_srb = NULL;
3769 pkt = rsp->ring_ptr;
3770 for (cnt = 0; cnt < rsp->length; cnt++) {
3771 pkt->signature = RESPONSE_PROCESSED;
3777 * qla2x00_update_fw_options() - Read and process firmware options.
3780 * Returns 0 on success.
3783 qla2x00_update_fw_options(scsi_qla_host_t *vha)
3785 uint16_t swing, emphasis, tx_sens, rx_sens;
3786 struct qla_hw_data *ha = vha->hw;
3788 memset(ha->fw_options, 0, sizeof(ha->fw_options));
3789 qla2x00_get_fw_options(vha, ha->fw_options);
3791 if (IS_QLA2100(ha) || IS_QLA2200(ha))
3794 /* Serial Link options. */
3795 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0115,
3796 "Serial link options.\n");
3797 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0109,
3798 ha->fw_seriallink_options, sizeof(ha->fw_seriallink_options));
3800 ha->fw_options[1] &= ~FO1_SET_EMPHASIS_SWING;
3801 if (ha->fw_seriallink_options[3] & BIT_2) {
3802 ha->fw_options[1] |= FO1_SET_EMPHASIS_SWING;
3805 swing = ha->fw_seriallink_options[2] & (BIT_2 | BIT_1 | BIT_0);
3806 emphasis = (ha->fw_seriallink_options[2] &
3807 (BIT_4 | BIT_3)) >> 3;
3808 tx_sens = ha->fw_seriallink_options[0] &
3809 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3810 rx_sens = (ha->fw_seriallink_options[0] &
3811 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3812 ha->fw_options[10] = (emphasis << 14) | (swing << 8);
3813 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3816 ha->fw_options[10] |= (tx_sens << 4) | rx_sens;
3817 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3818 ha->fw_options[10] |= BIT_5 |
3819 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3820 (tx_sens & (BIT_1 | BIT_0));
3823 swing = (ha->fw_seriallink_options[2] &
3824 (BIT_7 | BIT_6 | BIT_5)) >> 5;
3825 emphasis = ha->fw_seriallink_options[3] & (BIT_1 | BIT_0);
3826 tx_sens = ha->fw_seriallink_options[1] &
3827 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
3828 rx_sens = (ha->fw_seriallink_options[1] &
3829 (BIT_7 | BIT_6 | BIT_5 | BIT_4)) >> 4;
3830 ha->fw_options[11] = (emphasis << 14) | (swing << 8);
3831 if (IS_QLA2300(ha) || IS_QLA2312(ha) || IS_QLA6312(ha)) {
3834 ha->fw_options[11] |= (tx_sens << 4) | rx_sens;
3835 } else if (IS_QLA2322(ha) || IS_QLA6322(ha))
3836 ha->fw_options[11] |= BIT_5 |
3837 ((rx_sens & (BIT_1 | BIT_0)) << 2) |
3838 (tx_sens & (BIT_1 | BIT_0));
3842 /* Return command IOCBs without waiting for an ABTS to complete. */
3843 ha->fw_options[3] |= BIT_13;
3846 if (ha->flags.enable_led_scheme)
3847 ha->fw_options[2] |= BIT_12;
3849 /* Detect ISP6312. */
3851 ha->fw_options[2] |= BIT_13;
3853 /* Set Retry FLOGI in case of P2P connection */
3854 if (ha->operating_mode == P2P) {
3855 ha->fw_options[2] |= BIT_3;
3856 ql_dbg(ql_dbg_disc, vha, 0x2100,
3857 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3858 __func__, ha->fw_options[2]);
3861 /* Update firmware options. */
3862 qla2x00_set_fw_options(vha, ha->fw_options);
3866 qla24xx_update_fw_options(scsi_qla_host_t *vha)
3869 struct qla_hw_data *ha = vha->hw;
3871 if (IS_P3P_TYPE(ha))
3874 /* Hold status IOCBs until ABTS response received. */
3876 ha->fw_options[3] |= BIT_12;
3878 /* Set Retry FLOGI in case of P2P connection */
3879 if (ha->operating_mode == P2P) {
3880 ha->fw_options[2] |= BIT_3;
3881 ql_dbg(ql_dbg_disc, vha, 0x2101,
3882 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
3883 __func__, ha->fw_options[2]);
3886 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
3887 if (ql2xmvasynctoatio &&
3888 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha))) {
3889 if (qla_tgt_mode_enabled(vha) ||
3890 qla_dual_mode_enabled(vha))
3891 ha->fw_options[2] |= BIT_11;
3893 ha->fw_options[2] &= ~BIT_11;
3896 if (IS_QLA25XX(ha) || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3899 * Tell FW to track each exchange to prevent
3900 * driver from using stale exchange.
3902 if (qla_tgt_mode_enabled(vha) ||
3903 qla_dual_mode_enabled(vha))
3904 ha->fw_options[2] |= BIT_4;
3906 ha->fw_options[2] &= ~BIT_4;
3908 /* Reserve 1/2 of emergency exchanges for ELS.*/
3909 if (qla2xuseresexchforels)
3910 ha->fw_options[2] |= BIT_8;
3912 ha->fw_options[2] &= ~BIT_8;
3915 ql_dbg(ql_dbg_init, vha, 0x00e8,
3916 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
3917 __func__, ha->fw_options[1], ha->fw_options[2],
3918 ha->fw_options[3], vha->host->active_mode);
3920 if (ha->fw_options[1] || ha->fw_options[2] || ha->fw_options[3])
3921 qla2x00_set_fw_options(vha, ha->fw_options);
3923 /* Update Serial Link options. */
3924 if ((le16_to_cpu(ha->fw_seriallink_options24[0]) & BIT_0) == 0)
3927 rval = qla2x00_set_serdes_params(vha,
3928 le16_to_cpu(ha->fw_seriallink_options24[1]),
3929 le16_to_cpu(ha->fw_seriallink_options24[2]),
3930 le16_to_cpu(ha->fw_seriallink_options24[3]));
3931 if (rval != QLA_SUCCESS) {
3932 ql_log(ql_log_warn, vha, 0x0104,
3933 "Unable to update Serial Link options (%x).\n", rval);
3938 qla2x00_config_rings(struct scsi_qla_host *vha)
3940 struct qla_hw_data *ha = vha->hw;
3941 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
3942 struct req_que *req = ha->req_q_map[0];
3943 struct rsp_que *rsp = ha->rsp_q_map[0];
3945 /* Setup ring parameters in initialization control block. */
3946 ha->init_cb->request_q_outpointer = cpu_to_le16(0);
3947 ha->init_cb->response_q_inpointer = cpu_to_le16(0);
3948 ha->init_cb->request_q_length = cpu_to_le16(req->length);
3949 ha->init_cb->response_q_length = cpu_to_le16(rsp->length);
3950 put_unaligned_le64(req->dma, &ha->init_cb->request_q_address);
3951 put_unaligned_le64(rsp->dma, &ha->init_cb->response_q_address);
3953 WRT_REG_WORD(ISP_REQ_Q_IN(ha, reg), 0);
3954 WRT_REG_WORD(ISP_REQ_Q_OUT(ha, reg), 0);
3955 WRT_REG_WORD(ISP_RSP_Q_IN(ha, reg), 0);
3956 WRT_REG_WORD(ISP_RSP_Q_OUT(ha, reg), 0);
3957 RD_REG_WORD(ISP_RSP_Q_OUT(ha, reg)); /* PCI Posting. */
3961 qla24xx_config_rings(struct scsi_qla_host *vha)
3963 struct qla_hw_data *ha = vha->hw;
3964 device_reg_t *reg = ISP_QUE_REG(ha, 0);
3965 struct device_reg_2xxx __iomem *ioreg = &ha->iobase->isp;
3966 struct qla_msix_entry *msix;
3967 struct init_cb_24xx *icb;
3969 struct req_que *req = ha->req_q_map[0];
3970 struct rsp_que *rsp = ha->rsp_q_map[0];
3972 /* Setup ring parameters in initialization control block. */
3973 icb = (struct init_cb_24xx *)ha->init_cb;
3974 icb->request_q_outpointer = cpu_to_le16(0);
3975 icb->response_q_inpointer = cpu_to_le16(0);
3976 icb->request_q_length = cpu_to_le16(req->length);
3977 icb->response_q_length = cpu_to_le16(rsp->length);
3978 put_unaligned_le64(req->dma, &icb->request_q_address);
3979 put_unaligned_le64(rsp->dma, &icb->response_q_address);
3981 /* Setup ATIO queue dma pointers for target mode */
3982 icb->atio_q_inpointer = cpu_to_le16(0);
3983 icb->atio_q_length = cpu_to_le16(ha->tgt.atio_q_length);
3984 put_unaligned_le64(ha->tgt.atio_dma, &icb->atio_q_address);
3986 if (IS_SHADOW_REG_CAPABLE(ha))
3987 icb->firmware_options_2 |= cpu_to_le32(BIT_30|BIT_29);
3989 if (ha->mqenable || IS_QLA83XX(ha) || IS_QLA27XX(ha) ||
3991 icb->qos = cpu_to_le16(QLA_DEFAULT_QUE_QOS);
3992 icb->rid = cpu_to_le16(rid);
3993 if (ha->flags.msix_enabled) {
3994 msix = &ha->msix_entries[1];
3995 ql_dbg(ql_dbg_init, vha, 0x0019,
3996 "Registering vector 0x%x for base que.\n",
3998 icb->msix = cpu_to_le16(msix->entry);
4000 /* Use alternate PCI bus number */
4002 icb->firmware_options_2 |= cpu_to_le32(BIT_19);
4003 /* Use alternate PCI devfn */
4005 icb->firmware_options_2 |= cpu_to_le32(BIT_18);
4007 /* Use Disable MSIX Handshake mode for capable adapters */
4008 if ((ha->fw_attributes & BIT_6) && (IS_MSIX_NACK_CAPABLE(ha)) &&
4009 (ha->flags.msix_enabled)) {
4010 icb->firmware_options_2 &= cpu_to_le32(~BIT_22);
4011 ha->flags.disable_msix_handshake = 1;
4012 ql_dbg(ql_dbg_init, vha, 0x00fe,
4013 "MSIX Handshake Disable Mode turned on.\n");
4015 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
4017 icb->firmware_options_2 |= cpu_to_le32(BIT_23);
4019 WRT_REG_DWORD(®->isp25mq.req_q_in, 0);
4020 WRT_REG_DWORD(®->isp25mq.req_q_out, 0);
4021 WRT_REG_DWORD(®->isp25mq.rsp_q_in, 0);
4022 WRT_REG_DWORD(®->isp25mq.rsp_q_out, 0);
4024 WRT_REG_DWORD(®->isp24.req_q_in, 0);
4025 WRT_REG_DWORD(®->isp24.req_q_out, 0);
4026 WRT_REG_DWORD(®->isp24.rsp_q_in, 0);
4027 WRT_REG_DWORD(®->isp24.rsp_q_out, 0);
4030 qlt_24xx_config_rings(vha);
4032 /* If the user has configured the speed, set it here */
4033 if (ha->set_data_rate) {
4034 ql_dbg(ql_dbg_init, vha, 0x00fd,
4035 "Speed set by user : %s Gbps \n",
4036 qla2x00_get_link_speed_str(ha, ha->set_data_rate));
4037 icb->firmware_options_3 = (ha->set_data_rate << 13);
4041 RD_REG_DWORD(&ioreg->hccr);
4045 * qla2x00_init_rings() - Initializes firmware.
4048 * Beginning of request ring has initialization control block already built
4049 * by nvram config routine.
4051 * Returns 0 on success.
4054 qla2x00_init_rings(scsi_qla_host_t *vha)
4057 unsigned long flags = 0;
4059 struct qla_hw_data *ha = vha->hw;
4060 struct req_que *req;
4061 struct rsp_que *rsp;
4062 struct mid_init_cb_24xx *mid_init_cb =
4063 (struct mid_init_cb_24xx *) ha->init_cb;
4065 spin_lock_irqsave(&ha->hardware_lock, flags);
4067 /* Clear outstanding commands array. */
4068 for (que = 0; que < ha->max_req_queues; que++) {
4069 req = ha->req_q_map[que];
4070 if (!req || !test_bit(que, ha->req_qid_map))
4072 req->out_ptr = (void *)(req->ring + req->length);
4074 for (cnt = 1; cnt < req->num_outstanding_cmds; cnt++)
4075 req->outstanding_cmds[cnt] = NULL;
4077 req->current_outstanding_cmd = 1;
4079 /* Initialize firmware. */
4080 req->ring_ptr = req->ring;
4081 req->ring_index = 0;
4082 req->cnt = req->length;
4085 for (que = 0; que < ha->max_rsp_queues; que++) {
4086 rsp = ha->rsp_q_map[que];
4087 if (!rsp || !test_bit(que, ha->rsp_qid_map))
4089 rsp->in_ptr = (void *)(rsp->ring + rsp->length);
4091 /* Initialize response queue entries */
4093 qlafx00_init_response_q_entries(rsp);
4095 qla2x00_init_response_q_entries(rsp);
4098 ha->tgt.atio_ring_ptr = ha->tgt.atio_ring;
4099 ha->tgt.atio_ring_index = 0;
4100 /* Initialize ATIO queue entries */
4101 qlt_init_atio_q_entries(vha);
4103 ha->isp_ops->config_rings(vha);
4105 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4107 ql_dbg(ql_dbg_init, vha, 0x00d1, "Issue init firmware.\n");
4109 if (IS_QLAFX00(ha)) {
4110 rval = qlafx00_init_firmware(vha, ha->init_cb_size);
4114 /* Update any ISP specific firmware options before initialization. */
4115 ha->isp_ops->update_fw_options(vha);
4117 if (ha->flags.npiv_supported) {
4118 if (ha->operating_mode == LOOP && !IS_CNA_CAPABLE(ha))
4119 ha->max_npiv_vports = MIN_MULTI_ID_FABRIC - 1;
4120 mid_init_cb->count = cpu_to_le16(ha->max_npiv_vports);
4123 if (IS_FWI2_CAPABLE(ha)) {
4124 mid_init_cb->options = cpu_to_le16(BIT_1);
4125 mid_init_cb->init_cb.execution_throttle =
4126 cpu_to_le16(ha->cur_fw_xcb_count);
4127 ha->flags.dport_enabled =
4128 (mid_init_cb->init_cb.firmware_options_1 & BIT_7) != 0;
4129 ql_dbg(ql_dbg_init, vha, 0x0191, "DPORT Support: %s.\n",
4130 (ha->flags.dport_enabled) ? "enabled" : "disabled");
4131 /* FA-WWPN Status */
4132 ha->flags.fawwpn_enabled =
4133 (mid_init_cb->init_cb.firmware_options_1 & BIT_6) != 0;
4134 ql_dbg(ql_dbg_init, vha, 0x00bc, "FA-WWPN Support: %s.\n",
4135 (ha->flags.fawwpn_enabled) ? "enabled" : "disabled");
4138 rval = qla2x00_init_firmware(vha, ha->init_cb_size);
4141 ql_log(ql_log_fatal, vha, 0x00d2,
4142 "Init Firmware **** FAILED ****.\n");
4144 ql_dbg(ql_dbg_init, vha, 0x00d3,
4145 "Init Firmware -- success.\n");
4147 vha->u_ql2xexchoffld = vha->u_ql2xiniexchg = 0;
4154 * qla2x00_fw_ready() - Waits for firmware ready.
4157 * Returns 0 on success.
4160 qla2x00_fw_ready(scsi_qla_host_t *vha)
4163 unsigned long wtime, mtime, cs84xx_time;
4164 uint16_t min_wait; /* Minimum wait time if loop is down */
4165 uint16_t wait_time; /* Wait time if loop is coming ready */
4167 struct qla_hw_data *ha = vha->hw;
4169 if (IS_QLAFX00(vha->hw))
4170 return qlafx00_fw_ready(vha);
4174 /* Time to wait for loop down */
4175 if (IS_P3P_TYPE(ha))
4181 * Firmware should take at most one RATOV to login, plus 5 seconds for
4182 * our own processing.
4184 if ((wait_time = (ha->retry_count*ha->login_timeout) + 5) < min_wait) {
4185 wait_time = min_wait;
4188 /* Min wait time if loop down */
4189 mtime = jiffies + (min_wait * HZ);
4191 /* wait time before firmware ready */
4192 wtime = jiffies + (wait_time * HZ);
4194 /* Wait for ISP to finish LIP */
4195 if (!vha->flags.init_done)
4196 ql_log(ql_log_info, vha, 0x801e,
4197 "Waiting for LIP to complete.\n");
4200 memset(state, -1, sizeof(state));
4201 rval = qla2x00_get_firmware_state(vha, state);
4202 if (rval == QLA_SUCCESS) {
4203 if (state[0] < FSTATE_LOSS_OF_SYNC) {
4204 vha->device_flags &= ~DFLG_NO_CABLE;
4206 if (IS_QLA84XX(ha) && state[0] != FSTATE_READY) {
4207 ql_dbg(ql_dbg_taskm, vha, 0x801f,
4208 "fw_state=%x 84xx=%x.\n", state[0],
4210 if ((state[2] & FSTATE_LOGGED_IN) &&
4211 (state[2] & FSTATE_WAITING_FOR_VERIFY)) {
4212 ql_dbg(ql_dbg_taskm, vha, 0x8028,
4213 "Sending verify iocb.\n");
4215 cs84xx_time = jiffies;
4216 rval = qla84xx_init_chip(vha);
4217 if (rval != QLA_SUCCESS) {
4220 "Init chip failed.\n");
4224 /* Add time taken to initialize. */
4225 cs84xx_time = jiffies - cs84xx_time;
4226 wtime += cs84xx_time;
4227 mtime += cs84xx_time;
4228 ql_dbg(ql_dbg_taskm, vha, 0x8008,
4229 "Increasing wait time by %ld. "
4230 "New time %ld.\n", cs84xx_time,
4233 } else if (state[0] == FSTATE_READY) {
4234 ql_dbg(ql_dbg_taskm, vha, 0x8037,
4235 "F/W Ready - OK.\n");
4237 qla2x00_get_retry_cnt(vha, &ha->retry_count,
4238 &ha->login_timeout, &ha->r_a_tov);
4244 rval = QLA_FUNCTION_FAILED;
4246 if (atomic_read(&vha->loop_down_timer) &&
4247 state[0] != FSTATE_READY) {
4248 /* Loop down. Timeout on min_wait for states
4249 * other than Wait for Login.
4251 if (time_after_eq(jiffies, mtime)) {
4252 ql_log(ql_log_info, vha, 0x8038,
4253 "Cable is unplugged...\n");
4255 vha->device_flags |= DFLG_NO_CABLE;
4260 /* Mailbox cmd failed. Timeout on min_wait. */
4261 if (time_after_eq(jiffies, mtime) ||
4262 ha->flags.isp82xx_fw_hung)
4266 if (time_after_eq(jiffies, wtime))
4269 /* Delay for a while */
4273 ql_dbg(ql_dbg_taskm, vha, 0x803a,
4274 "fw_state=%x (%x, %x, %x, %x %x) curr time=%lx.\n", state[0],
4275 state[1], state[2], state[3], state[4], state[5], jiffies);
4277 if (rval && !(vha->device_flags & DFLG_NO_CABLE)) {
4278 ql_log(ql_log_warn, vha, 0x803b,
4279 "Firmware ready **** FAILED ****.\n");
4286 * qla2x00_configure_hba
4287 * Setup adapter context.
4290 * ha = adapter state pointer.
4299 qla2x00_configure_hba(scsi_qla_host_t *vha)
4308 char connect_type[22];
4309 struct qla_hw_data *ha = vha->hw;
4310 scsi_qla_host_t *base_vha = pci_get_drvdata(ha->pdev);
4312 unsigned long flags;
4314 /* Get host addresses. */
4315 rval = qla2x00_get_adapter_id(vha,
4316 &loop_id, &al_pa, &area, &domain, &topo, &sw_cap);
4317 if (rval != QLA_SUCCESS) {
4318 if (LOOP_TRANSITION(vha) || atomic_read(&ha->loop_down_timer) ||
4319 IS_CNA_CAPABLE(ha) ||
4320 (rval == QLA_COMMAND_ERROR && loop_id == 0x7)) {
4321 ql_dbg(ql_dbg_disc, vha, 0x2008,
4322 "Loop is in a transition state.\n");
4324 ql_log(ql_log_warn, vha, 0x2009,
4325 "Unable to get host loop ID.\n");
4326 if (IS_FWI2_CAPABLE(ha) && (vha == base_vha) &&
4327 (rval == QLA_COMMAND_ERROR && loop_id == 0x1b)) {
4328 ql_log(ql_log_warn, vha, 0x1151,
4329 "Doing link init.\n");
4330 if (qla24xx_link_initialize(vha) == QLA_SUCCESS)
4333 set_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
4339 ql_log(ql_log_info, vha, 0x200a,
4340 "Cannot get topology - retrying.\n");
4341 return (QLA_FUNCTION_FAILED);
4344 vha->loop_id = loop_id;
4347 ha->min_external_loopid = SNS_FIRST_LOOP_ID;
4348 ha->operating_mode = LOOP;
4353 ql_dbg(ql_dbg_disc, vha, 0x200b, "HBA in NL topology.\n");
4354 ha->current_topology = ISP_CFG_NL;
4355 strcpy(connect_type, "(Loop)");
4359 ql_dbg(ql_dbg_disc, vha, 0x200c, "HBA in FL topology.\n");
4360 ha->switch_cap = sw_cap;
4361 ha->current_topology = ISP_CFG_FL;
4362 strcpy(connect_type, "(FL_Port)");
4366 ql_dbg(ql_dbg_disc, vha, 0x200d, "HBA in N P2P topology.\n");
4367 ha->operating_mode = P2P;
4368 ha->current_topology = ISP_CFG_N;
4369 strcpy(connect_type, "(N_Port-to-N_Port)");
4373 ql_dbg(ql_dbg_disc, vha, 0x200e, "HBA in F P2P topology.\n");
4374 ha->switch_cap = sw_cap;
4375 ha->operating_mode = P2P;
4376 ha->current_topology = ISP_CFG_F;
4377 strcpy(connect_type, "(F_Port)");
4381 ql_dbg(ql_dbg_disc, vha, 0x200f,
4382 "HBA in unknown topology %x, using NL.\n", topo);
4383 ha->current_topology = ISP_CFG_NL;
4384 strcpy(connect_type, "(Loop)");
4388 /* Save Host port and loop ID. */
4389 /* byte order - Big Endian */
4390 id.b.domain = domain;
4394 spin_lock_irqsave(&ha->hardware_lock, flags);
4395 if (!(topo == 2 && ha->flags.n2n_bigger))
4396 qlt_update_host_map(vha, id);
4397 spin_unlock_irqrestore(&ha->hardware_lock, flags);
4399 if (!vha->flags.init_done)
4400 ql_log(ql_log_info, vha, 0x2010,
4401 "Topology - %s, Host Loop address 0x%x.\n",
4402 connect_type, vha->loop_id);
4408 qla2x00_set_model_info(scsi_qla_host_t *vha, uint8_t *model, size_t len,
4413 uint64_t zero[2] = { 0 };
4414 struct qla_hw_data *ha = vha->hw;
4415 int use_tbl = !IS_QLA24XX_TYPE(ha) && !IS_QLA25XX(ha) &&
4416 !IS_CNA_CAPABLE(ha) && !IS_QLA2031(ha);
4418 if (len > sizeof(zero))
4420 if (memcmp(model, &zero, len) != 0) {
4421 memcpy(ha->model_number, model, len);
4422 st = en = ha->model_number;
4425 if (*en != 0x20 && *en != 0x00)
4430 index = (ha->pdev->subsystem_device & 0xff);
4432 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4433 index < QLA_MODEL_NAMES)
4434 strlcpy(ha->model_desc,
4435 qla2x00_model_name[index * 2 + 1],
4436 sizeof(ha->model_desc));
4438 index = (ha->pdev->subsystem_device & 0xff);
4440 ha->pdev->subsystem_vendor == PCI_VENDOR_ID_QLOGIC &&
4441 index < QLA_MODEL_NAMES) {
4442 strlcpy(ha->model_number,
4443 qla2x00_model_name[index * 2],
4444 sizeof(ha->model_number));
4445 strlcpy(ha->model_desc,
4446 qla2x00_model_name[index * 2 + 1],
4447 sizeof(ha->model_desc));
4449 strlcpy(ha->model_number, def,
4450 sizeof(ha->model_number));
4453 if (IS_FWI2_CAPABLE(ha))
4454 qla2xxx_get_vpd_field(vha, "\x82", ha->model_desc,
4455 sizeof(ha->model_desc));
4458 /* On sparc systems, obtain port and node WWN from firmware
4461 static void qla2xxx_nvram_wwn_from_ofw(scsi_qla_host_t *vha, nvram_t *nv)
4464 struct qla_hw_data *ha = vha->hw;
4465 struct pci_dev *pdev = ha->pdev;
4466 struct device_node *dp = pci_device_to_OF_node(pdev);
4470 val = of_get_property(dp, "port-wwn", &len);
4471 if (val && len >= WWN_SIZE)
4472 memcpy(nv->port_name, val, WWN_SIZE);
4474 val = of_get_property(dp, "node-wwn", &len);
4475 if (val && len >= WWN_SIZE)
4476 memcpy(nv->node_name, val, WWN_SIZE);
4481 * NVRAM configuration for ISP 2xxx
4484 * ha = adapter block pointer.
4487 * initialization control block in response_ring
4488 * host adapters parameters in host adapter block
4494 qla2x00_nvram_config(scsi_qla_host_t *vha)
4499 uint8_t *dptr1, *dptr2;
4500 struct qla_hw_data *ha = vha->hw;
4501 init_cb_t *icb = ha->init_cb;
4502 nvram_t *nv = ha->nvram;
4503 uint8_t *ptr = ha->nvram;
4504 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
4508 /* Determine NVRAM starting address. */
4509 ha->nvram_size = sizeof(*nv);
4511 if (!IS_QLA2100(ha) && !IS_QLA2200(ha) && !IS_QLA2300(ha))
4512 if ((RD_REG_WORD(®->ctrl_status) >> 14) == 1)
4513 ha->nvram_base = 0x80;
4515 /* Get NVRAM data and calculate checksum. */
4516 ha->isp_ops->read_nvram(vha, ptr, ha->nvram_base, ha->nvram_size);
4517 for (cnt = 0, chksum = 0; cnt < ha->nvram_size; cnt++)
4520 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x010f,
4521 "Contents of NVRAM.\n");
4522 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0110,
4523 nv, ha->nvram_size);
4525 /* Bad NVRAM data, set defaults parameters. */
4526 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
4527 nv->nvram_version < 1) {
4528 /* Reset NVRAM data. */
4529 ql_log(ql_log_warn, vha, 0x0064,
4530 "Inconsistent NVRAM detected: checksum=%#x id=%.4s version=%#x.\n",
4531 chksum, nv->id, nv->nvram_version);
4532 ql_log(ql_log_warn, vha, 0x0065,
4534 "functioning (yet invalid -- WWPN) defaults.\n");
4537 * Set default initialization control block.
4539 memset(nv, 0, ha->nvram_size);
4540 nv->parameter_block_version = ICB_VERSION;
4542 if (IS_QLA23XX(ha)) {
4543 nv->firmware_options[0] = BIT_2 | BIT_1;
4544 nv->firmware_options[1] = BIT_7 | BIT_5;
4545 nv->add_firmware_options[0] = BIT_5;
4546 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4547 nv->frame_payload_size = 2048;
4548 nv->special_options[1] = BIT_7;
4549 } else if (IS_QLA2200(ha)) {
4550 nv->firmware_options[0] = BIT_2 | BIT_1;
4551 nv->firmware_options[1] = BIT_7 | BIT_5;
4552 nv->add_firmware_options[0] = BIT_5;
4553 nv->add_firmware_options[1] = BIT_5 | BIT_4;
4554 nv->frame_payload_size = 1024;
4555 } else if (IS_QLA2100(ha)) {
4556 nv->firmware_options[0] = BIT_3 | BIT_1;
4557 nv->firmware_options[1] = BIT_5;
4558 nv->frame_payload_size = 1024;
4561 nv->max_iocb_allocation = cpu_to_le16(256);
4562 nv->execution_throttle = cpu_to_le16(16);
4563 nv->retry_count = 8;
4564 nv->retry_delay = 1;
4566 nv->port_name[0] = 33;
4567 nv->port_name[3] = 224;
4568 nv->port_name[4] = 139;
4570 qla2xxx_nvram_wwn_from_ofw(vha, nv);
4572 nv->login_timeout = 4;
4575 * Set default host adapter parameters
4577 nv->host_p[1] = BIT_2;
4578 nv->reset_delay = 5;
4579 nv->port_down_retry_count = 8;
4580 nv->max_luns_per_target = cpu_to_le16(8);
4581 nv->link_down_timeout = 60;
4586 #if defined(CONFIG_IA64_GENERIC) || defined(CONFIG_IA64_SGI_SN2)
4588 * The SN2 does not provide BIOS emulation which means you can't change
4589 * potentially bogus BIOS settings. Force the use of default settings
4590 * for link rate and frame size. Hope that the rest of the settings
4593 if (ia64_platform_is("sn2")) {
4594 nv->frame_payload_size = 2048;
4596 nv->special_options[1] = BIT_7;
4600 /* Reset Initialization control block */
4601 memset(icb, 0, ha->init_cb_size);
4604 * Setup driver NVRAM options.
4606 nv->firmware_options[0] |= (BIT_6 | BIT_1);
4607 nv->firmware_options[0] &= ~(BIT_5 | BIT_4);
4608 nv->firmware_options[1] |= (BIT_5 | BIT_0);
4609 nv->firmware_options[1] &= ~BIT_4;
4611 if (IS_QLA23XX(ha)) {
4612 nv->firmware_options[0] |= BIT_2;
4613 nv->firmware_options[0] &= ~BIT_3;
4614 nv->special_options[0] &= ~BIT_6;
4615 nv->add_firmware_options[1] |= BIT_5 | BIT_4;
4617 if (IS_QLA2300(ha)) {
4618 if (ha->fb_rev == FPM_2310) {
4619 strcpy(ha->model_number, "QLA2310");
4621 strcpy(ha->model_number, "QLA2300");
4624 qla2x00_set_model_info(vha, nv->model_number,
4625 sizeof(nv->model_number), "QLA23xx");
4627 } else if (IS_QLA2200(ha)) {
4628 nv->firmware_options[0] |= BIT_2;
4630 * 'Point-to-point preferred, else loop' is not a safe
4631 * connection mode setting.
4633 if ((nv->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) ==
4635 /* Force 'loop preferred, else point-to-point'. */
4636 nv->add_firmware_options[0] &= ~(BIT_6 | BIT_5 | BIT_4);
4637 nv->add_firmware_options[0] |= BIT_5;
4639 strcpy(ha->model_number, "QLA22xx");
4640 } else /*if (IS_QLA2100(ha))*/ {
4641 strcpy(ha->model_number, "QLA2100");
4645 * Copy over NVRAM RISC parameter block to initialization control block.
4647 dptr1 = (uint8_t *)icb;
4648 dptr2 = (uint8_t *)&nv->parameter_block_version;
4649 cnt = (uint8_t *)&icb->request_q_outpointer - (uint8_t *)&icb->version;
4651 *dptr1++ = *dptr2++;
4653 /* Copy 2nd half. */
4654 dptr1 = (uint8_t *)icb->add_firmware_options;
4655 cnt = (uint8_t *)icb->reserved_3 - (uint8_t *)icb->add_firmware_options;
4657 *dptr1++ = *dptr2++;
4658 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
4659 /* Use alternate WWN? */
4660 if (nv->host_p[1] & BIT_7) {
4661 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
4662 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
4665 /* Prepare nodename */
4666 if ((icb->firmware_options[1] & BIT_6) == 0) {
4668 * Firmware will apply the following mask if the nodename was
4671 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
4672 icb->node_name[0] &= 0xF0;
4676 * Set host adapter parameters.
4680 * BIT_7 in the host-parameters section allows for modification to
4681 * internal driver logging.
4683 if (nv->host_p[0] & BIT_7)
4684 ql2xextended_error_logging = QL_DBG_DEFAULT1_MASK;
4685 ha->flags.disable_risc_code_load = ((nv->host_p[0] & BIT_4) ? 1 : 0);
4686 /* Always load RISC code on non ISP2[12]00 chips. */
4687 if (!IS_QLA2100(ha) && !IS_QLA2200(ha))
4688 ha->flags.disable_risc_code_load = 0;
4689 ha->flags.enable_lip_reset = ((nv->host_p[1] & BIT_1) ? 1 : 0);
4690 ha->flags.enable_lip_full_login = ((nv->host_p[1] & BIT_2) ? 1 : 0);
4691 ha->flags.enable_target_reset = ((nv->host_p[1] & BIT_3) ? 1 : 0);
4692 ha->flags.enable_led_scheme = (nv->special_options[1] & BIT_4) ? 1 : 0;
4693 ha->flags.disable_serdes = 0;
4695 ha->operating_mode =
4696 (icb->add_firmware_options[0] & (BIT_6 | BIT_5 | BIT_4)) >> 4;
4698 memcpy(ha->fw_seriallink_options, nv->seriallink_options,
4699 sizeof(ha->fw_seriallink_options));
4701 /* save HBA serial number */
4702 ha->serial0 = icb->port_name[5];
4703 ha->serial1 = icb->port_name[6];
4704 ha->serial2 = icb->port_name[7];
4705 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
4706 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
4708 icb->execution_throttle = cpu_to_le16(0xFFFF);
4710 ha->retry_count = nv->retry_count;
4712 /* Set minimum login_timeout to 4 seconds. */
4713 if (nv->login_timeout != ql2xlogintimeout)
4714 nv->login_timeout = ql2xlogintimeout;
4715 if (nv->login_timeout < 4)
4716 nv->login_timeout = 4;
4717 ha->login_timeout = nv->login_timeout;
4719 /* Set minimum RATOV to 100 tenths of a second. */
4722 ha->loop_reset_delay = nv->reset_delay;
4724 /* Link Down Timeout = 0:
4726 * When Port Down timer expires we will start returning
4727 * I/O's to OS with "DID_NO_CONNECT".
4729 * Link Down Timeout != 0:
4731 * The driver waits for the link to come up after link down
4732 * before returning I/Os to OS with "DID_NO_CONNECT".
4734 if (nv->link_down_timeout == 0) {
4735 ha->loop_down_abort_time =
4736 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
4738 ha->link_down_timeout = nv->link_down_timeout;
4739 ha->loop_down_abort_time =
4740 (LOOP_DOWN_TIME - ha->link_down_timeout);
4744 * Need enough time to try and get the port back.
4746 ha->port_down_retry_count = nv->port_down_retry_count;
4747 if (qlport_down_retry)
4748 ha->port_down_retry_count = qlport_down_retry;
4749 /* Set login_retry_count */
4750 ha->login_retry_count = nv->retry_count;
4751 if (ha->port_down_retry_count == nv->port_down_retry_count &&
4752 ha->port_down_retry_count > 3)
4753 ha->login_retry_count = ha->port_down_retry_count;
4754 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
4755 ha->login_retry_count = ha->port_down_retry_count;
4756 if (ql2xloginretrycount)
4757 ha->login_retry_count = ql2xloginretrycount;
4759 icb->lun_enables = cpu_to_le16(0);
4760 icb->command_resource_count = 0;
4761 icb->immediate_notify_resource_count = 0;
4762 icb->timeout = cpu_to_le16(0);
4764 if (IS_QLA2100(ha) || IS_QLA2200(ha)) {
4766 icb->firmware_options[0] &= ~BIT_3;
4767 icb->add_firmware_options[0] &=
4768 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4769 icb->add_firmware_options[0] |= BIT_2;
4770 icb->response_accumulation_timer = 3;
4771 icb->interrupt_delay_timer = 5;
4773 vha->flags.process_response_queue = 1;
4776 if (!vha->flags.init_done) {
4777 ha->zio_mode = icb->add_firmware_options[0] &
4778 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
4779 ha->zio_timer = icb->interrupt_delay_timer ?
4780 icb->interrupt_delay_timer : 2;
4782 icb->add_firmware_options[0] &=
4783 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0);
4784 vha->flags.process_response_queue = 0;
4785 if (ha->zio_mode != QLA_ZIO_DISABLED) {
4786 ha->zio_mode = QLA_ZIO_MODE_6;
4788 ql_log(ql_log_info, vha, 0x0068,
4789 "ZIO mode %d enabled; timer delay (%d us).\n",
4790 ha->zio_mode, ha->zio_timer * 100);
4792 icb->add_firmware_options[0] |= (uint8_t)ha->zio_mode;
4793 icb->interrupt_delay_timer = (uint8_t)ha->zio_timer;
4794 vha->flags.process_response_queue = 1;
4799 ql_log(ql_log_warn, vha, 0x0069,
4800 "NVRAM configuration failed.\n");
4806 qla2x00_rport_del(void *data)
4808 fc_port_t *fcport = data;
4809 struct fc_rport *rport;
4810 unsigned long flags;
4812 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
4813 rport = fcport->drport ? fcport->drport : fcport->rport;
4814 fcport->drport = NULL;
4815 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
4817 ql_dbg(ql_dbg_disc, fcport->vha, 0x210b,
4818 "%s %8phN. rport %p roles %x\n",
4819 __func__, fcport->port_name, rport,
4822 fc_remote_port_delete(rport);
4826 void qla2x00_set_fcport_state(fc_port_t *fcport, int state)
4830 old_state = atomic_read(&fcport->state);
4831 atomic_set(&fcport->state, state);
4833 /* Don't print state transitions during initial allocation of fcport */
4834 if (old_state && old_state != state) {
4835 ql_dbg(ql_dbg_disc, fcport->vha, 0x207d,
4836 "FCPort %8phC state transitioned from %s to %s - portid=%02x%02x%02x.\n",
4837 fcport->port_name, port_state_str[old_state],
4838 port_state_str[state], fcport->d_id.b.domain,
4839 fcport->d_id.b.area, fcport->d_id.b.al_pa);
4844 * qla2x00_alloc_fcport() - Allocate a generic fcport.
4846 * @flags: allocation flags
4848 * Returns a pointer to the allocated fcport, or NULL, if none available.
4851 qla2x00_alloc_fcport(scsi_qla_host_t *vha, gfp_t flags)
4855 fcport = kzalloc(sizeof(fc_port_t), flags);
4859 fcport->ct_desc.ct_sns = dma_alloc_coherent(&vha->hw->pdev->dev,
4860 sizeof(struct ct_sns_pkt), &fcport->ct_desc.ct_sns_dma,
4862 if (!fcport->ct_desc.ct_sns) {
4863 ql_log(ql_log_warn, vha, 0xd049,
4864 "Failed to allocate ct_sns request.\n");
4869 /* Setup fcport template structure. */
4871 fcport->port_type = FCT_UNKNOWN;
4872 fcport->loop_id = FC_NO_LOOP_ID;
4873 qla2x00_set_fcport_state(fcport, FCS_UNCONFIGURED);
4874 fcport->supported_classes = FC_COS_UNSPECIFIED;
4875 fcport->fp_speed = PORT_SPEED_UNKNOWN;
4877 fcport->disc_state = DSC_DELETED;
4878 fcport->fw_login_state = DSC_LS_PORT_UNAVAIL;
4879 fcport->deleted = QLA_SESS_DELETED;
4880 fcport->login_retry = vha->hw->login_retry_count;
4881 fcport->chip_reset = vha->hw->base_qpair->chip_reset;
4882 fcport->logout_on_delete = 1;
4884 if (!fcport->ct_desc.ct_sns) {
4885 ql_log(ql_log_warn, vha, 0xd049,
4886 "Failed to allocate ct_sns request.\n");
4891 INIT_WORK(&fcport->del_work, qla24xx_delete_sess_fn);
4892 INIT_WORK(&fcport->reg_work, qla_register_fcport_fn);
4893 INIT_LIST_HEAD(&fcport->gnl_entry);
4894 INIT_LIST_HEAD(&fcport->list);
4900 qla2x00_free_fcport(fc_port_t *fcport)
4902 if (fcport->ct_desc.ct_sns) {
4903 dma_free_coherent(&fcport->vha->hw->pdev->dev,
4904 sizeof(struct ct_sns_pkt), fcport->ct_desc.ct_sns,
4905 fcport->ct_desc.ct_sns_dma);
4907 fcport->ct_desc.ct_sns = NULL;
4909 list_del(&fcport->list);
4910 qla2x00_clear_loop_id(fcport);
4915 * qla2x00_configure_loop
4916 * Updates Fibre Channel Device Database with what is actually on loop.
4919 * ha = adapter block pointer.
4924 * 2 = database was full and device was not configured.
4927 qla2x00_configure_loop(scsi_qla_host_t *vha)
4930 unsigned long flags, save_flags;
4931 struct qla_hw_data *ha = vha->hw;
4935 /* Get Initiator ID */
4936 if (test_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags)) {
4937 rval = qla2x00_configure_hba(vha);
4938 if (rval != QLA_SUCCESS) {
4939 ql_dbg(ql_dbg_disc, vha, 0x2013,
4940 "Unable to configure HBA.\n");
4945 save_flags = flags = vha->dpc_flags;
4946 ql_dbg(ql_dbg_disc, vha, 0x2014,
4947 "Configure loop -- dpc flags = 0x%lx.\n", flags);
4950 * If we have both an RSCN and PORT UPDATE pending then handle them
4951 * both at the same time.
4953 clear_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
4954 clear_bit(RSCN_UPDATE, &vha->dpc_flags);
4956 qla2x00_get_data_rate(vha);
4958 /* Determine what we need to do */
4959 if (ha->current_topology == ISP_CFG_FL &&
4960 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4962 set_bit(RSCN_UPDATE, &flags);
4964 } else if (ha->current_topology == ISP_CFG_F &&
4965 (test_bit(LOCAL_LOOP_UPDATE, &flags))) {
4967 set_bit(RSCN_UPDATE, &flags);
4968 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4970 } else if (ha->current_topology == ISP_CFG_N) {
4971 clear_bit(RSCN_UPDATE, &flags);
4972 if (qla_tgt_mode_enabled(vha)) {
4973 /* allow the other side to start the login */
4974 clear_bit(LOCAL_LOOP_UPDATE, &flags);
4975 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
4977 } else if (ha->current_topology == ISP_CFG_NL) {
4978 clear_bit(RSCN_UPDATE, &flags);
4979 set_bit(LOCAL_LOOP_UPDATE, &flags);
4980 } else if (!vha->flags.online ||
4981 (test_bit(ABORT_ISP_ACTIVE, &flags))) {
4982 set_bit(RSCN_UPDATE, &flags);
4983 set_bit(LOCAL_LOOP_UPDATE, &flags);
4986 if (test_bit(LOCAL_LOOP_UPDATE, &flags)) {
4987 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
4988 ql_dbg(ql_dbg_disc, vha, 0x2015,
4989 "Loop resync needed, failing.\n");
4990 rval = QLA_FUNCTION_FAILED;
4992 rval = qla2x00_configure_local_loop(vha);
4995 if (rval == QLA_SUCCESS && test_bit(RSCN_UPDATE, &flags)) {
4996 if (LOOP_TRANSITION(vha)) {
4997 ql_dbg(ql_dbg_disc, vha, 0x2099,
4998 "Needs RSCN update and loop transition.\n");
4999 rval = QLA_FUNCTION_FAILED;
5002 rval = qla2x00_configure_fabric(vha);
5005 if (rval == QLA_SUCCESS) {
5006 if (atomic_read(&vha->loop_down_timer) ||
5007 test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5008 rval = QLA_FUNCTION_FAILED;
5010 atomic_set(&vha->loop_state, LOOP_READY);
5011 ql_dbg(ql_dbg_disc, vha, 0x2069,
5013 ha->flags.fw_init_done = 1;
5016 * Process any ATIO queue entries that came in
5017 * while we weren't online.
5019 if (qla_tgt_mode_enabled(vha) ||
5020 qla_dual_mode_enabled(vha)) {
5021 spin_lock_irqsave(&ha->tgt.atio_lock, flags);
5022 qlt_24xx_process_atio_queue(vha, 0);
5023 spin_unlock_irqrestore(&ha->tgt.atio_lock,
5030 ql_dbg(ql_dbg_disc, vha, 0x206a,
5031 "%s *** FAILED ***.\n", __func__);
5033 ql_dbg(ql_dbg_disc, vha, 0x206b,
5034 "%s: exiting normally.\n", __func__);
5037 /* Restore state if a resync event occurred during processing */
5038 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags)) {
5039 if (test_bit(LOCAL_LOOP_UPDATE, &save_flags))
5040 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5041 if (test_bit(RSCN_UPDATE, &save_flags)) {
5042 set_bit(RSCN_UPDATE, &vha->dpc_flags);
5050 * qla2x00_configure_local_loop
5051 * Updates Fibre Channel Device Database with local loop devices.
5054 * ha = adapter block pointer.
5060 qla2x00_configure_local_loop(scsi_qla_host_t *vha)
5065 fc_port_t *fcport, *new_fcport;
5069 struct gid_list_info *gid;
5071 uint8_t domain, area, al_pa;
5072 struct qla_hw_data *ha = vha->hw;
5073 unsigned long flags;
5075 /* Inititae N2N login. */
5076 if (test_and_clear_bit(N2N_LOGIN_NEEDED, &vha->dpc_flags)) {
5080 memset(ha->init_cb, 0, ha->init_cb_size);
5081 sz = min_t(int, sizeof(struct els_plogi_payload),
5083 rval = qla24xx_get_port_login_templ(vha, ha->init_cb_dma,
5084 (void *)ha->init_cb, sz);
5085 if (rval == QLA_SUCCESS) {
5086 bp = (uint32_t *)ha->init_cb;
5087 for (i = 0; i < sz/4 ; i++, bp++)
5088 *bp = cpu_to_be32(*bp);
5090 memcpy(&ha->plogi_els_payld.data, (void *)ha->init_cb,
5091 sizeof(ha->plogi_els_payld.data));
5092 set_bit(RELOGIN_NEEDED, &vha->dpc_flags);
5094 ql_dbg(ql_dbg_init, vha, 0x00d1,
5095 "PLOGI ELS param read fail.\n");
5102 entries = MAX_FIBRE_DEVICES_LOOP;
5104 /* Get list of logged in devices. */
5105 memset(ha->gid_list, 0, qla2x00_gid_list_size(ha));
5106 rval = qla2x00_get_id_list(vha, ha->gid_list, ha->gid_list_dma,
5108 if (rval != QLA_SUCCESS)
5109 goto cleanup_allocation;
5111 ql_dbg(ql_dbg_disc, vha, 0x2011,
5112 "Entries in ID list (%d).\n", entries);
5113 ql_dump_buffer(ql_dbg_disc + ql_dbg_buffer, vha, 0x2075,
5114 ha->gid_list, entries * sizeof(*ha->gid_list));
5117 spin_lock_irqsave(&vha->work_lock, flags);
5118 vha->scan.scan_retry++;
5119 spin_unlock_irqrestore(&vha->work_lock, flags);
5121 if (vha->scan.scan_retry < MAX_SCAN_RETRIES) {
5122 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5123 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5126 vha->scan.scan_retry = 0;
5129 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5130 fcport->scan_state = QLA_FCPORT_SCAN;
5133 /* Allocate temporary fcport for any new fcports discovered. */
5134 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5135 if (new_fcport == NULL) {
5136 ql_log(ql_log_warn, vha, 0x2012,
5137 "Memory allocation failed for fcport.\n");
5138 rval = QLA_MEMORY_ALLOC_FAILED;
5139 goto cleanup_allocation;
5141 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5143 /* Add devices to port list. */
5145 for (index = 0; index < entries; index++) {
5146 domain = gid->domain;
5149 if (IS_QLA2100(ha) || IS_QLA2200(ha))
5150 loop_id = gid->loop_id_2100;
5152 loop_id = le16_to_cpu(gid->loop_id);
5153 gid = (void *)gid + ha->gid_list_info_size;
5155 /* Bypass reserved domain fields. */
5156 if ((domain & 0xf0) == 0xf0)
5159 /* Bypass if not same domain and area of adapter. */
5160 if (area && domain && ((area != vha->d_id.b.area) ||
5161 (domain != vha->d_id.b.domain)) &&
5162 (ha->current_topology == ISP_CFG_NL))
5166 /* Bypass invalid local loop ID. */
5167 if (loop_id > LAST_LOCAL_LOOP_ID)
5170 memset(new_fcport->port_name, 0, WWN_SIZE);
5172 /* Fill in member data. */
5173 new_fcport->d_id.b.domain = domain;
5174 new_fcport->d_id.b.area = area;
5175 new_fcport->d_id.b.al_pa = al_pa;
5176 new_fcport->loop_id = loop_id;
5177 new_fcport->scan_state = QLA_FCPORT_FOUND;
5179 rval2 = qla2x00_get_port_database(vha, new_fcport, 0);
5180 if (rval2 != QLA_SUCCESS) {
5181 ql_dbg(ql_dbg_disc, vha, 0x2097,
5182 "Failed to retrieve fcport information "
5183 "-- get_port_database=%x, loop_id=0x%04x.\n",
5184 rval2, new_fcport->loop_id);
5185 /* Skip retry if N2N */
5186 if (ha->current_topology != ISP_CFG_N) {
5187 ql_dbg(ql_dbg_disc, vha, 0x2105,
5188 "Scheduling resync.\n");
5189 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5194 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5195 /* Check for matching device in port list. */
5198 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5199 if (memcmp(new_fcport->port_name, fcport->port_name,
5203 fcport->flags &= ~FCF_FABRIC_DEVICE;
5204 fcport->loop_id = new_fcport->loop_id;
5205 fcport->port_type = new_fcport->port_type;
5206 fcport->d_id.b24 = new_fcport->d_id.b24;
5207 memcpy(fcport->node_name, new_fcport->node_name,
5209 fcport->scan_state = QLA_FCPORT_FOUND;
5215 /* New device, add to fcports list. */
5216 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5218 /* Allocate a new replacement fcport. */
5219 fcport = new_fcport;
5221 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5223 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5225 if (new_fcport == NULL) {
5226 ql_log(ql_log_warn, vha, 0xd031,
5227 "Failed to allocate memory for fcport.\n");
5228 rval = QLA_MEMORY_ALLOC_FAILED;
5229 goto cleanup_allocation;
5231 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5232 new_fcport->flags &= ~FCF_FABRIC_DEVICE;
5235 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5237 /* Base iIDMA settings on HBA port speed. */
5238 fcport->fp_speed = ha->link_data_rate;
5243 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5244 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5247 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5248 if ((qla_dual_mode_enabled(vha) ||
5249 qla_ini_mode_enabled(vha)) &&
5250 atomic_read(&fcport->state) == FCS_ONLINE) {
5251 qla2x00_mark_device_lost(vha, fcport,
5252 ql2xplogiabsentdevice, 0);
5253 if (fcport->loop_id != FC_NO_LOOP_ID &&
5254 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5255 fcport->port_type != FCT_INITIATOR &&
5256 fcport->port_type != FCT_BROADCAST) {
5257 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5258 "%s %d %8phC post del sess\n",
5262 qlt_schedule_sess_for_deletion(fcport);
5268 if (fcport->scan_state == QLA_FCPORT_FOUND)
5269 qla24xx_fcport_handle_login(vha, fcport);
5275 if (rval != QLA_SUCCESS) {
5276 ql_dbg(ql_dbg_disc, vha, 0x2098,
5277 "Configure local loop error exit: rval=%x.\n", rval);
5284 qla2x00_iidma_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5287 uint16_t mb[MAILBOX_REGISTER_COUNT];
5288 struct qla_hw_data *ha = vha->hw;
5290 if (!IS_IIDMA_CAPABLE(ha))
5293 if (atomic_read(&fcport->state) != FCS_ONLINE)
5296 if (fcport->fp_speed == PORT_SPEED_UNKNOWN ||
5297 fcport->fp_speed > ha->link_data_rate ||
5298 !ha->flags.gpsc_supported)
5301 rval = qla2x00_set_idma_speed(vha, fcport->loop_id, fcport->fp_speed,
5303 if (rval != QLA_SUCCESS) {
5304 ql_dbg(ql_dbg_disc, vha, 0x2004,
5305 "Unable to adjust iIDMA %8phN -- %04x %x %04x %04x.\n",
5306 fcport->port_name, rval, fcport->fp_speed, mb[0], mb[1]);
5308 ql_dbg(ql_dbg_disc, vha, 0x2005,
5309 "iIDMA adjusted to %s GB/s (%X) on %8phN.\n",
5310 qla2x00_get_link_speed_str(ha, fcport->fp_speed),
5311 fcport->fp_speed, fcport->port_name);
5315 void qla_do_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5317 qla2x00_iidma_fcport(vha, fcport);
5318 qla24xx_update_fcport_fcp_prio(vha, fcport);
5321 int qla_post_iidma_work(struct scsi_qla_host *vha, fc_port_t *fcport)
5323 struct qla_work_evt *e;
5325 e = qla2x00_alloc_work(vha, QLA_EVT_IIDMA);
5327 return QLA_FUNCTION_FAILED;
5329 e->u.fcport.fcport = fcport;
5330 return qla2x00_post_work(vha, e);
5333 /* qla2x00_reg_remote_port is reserved for Initiator Mode only.*/
5335 qla2x00_reg_remote_port(scsi_qla_host_t *vha, fc_port_t *fcport)
5337 struct fc_rport_identifiers rport_ids;
5338 struct fc_rport *rport;
5339 unsigned long flags;
5341 if (atomic_read(&fcport->state) == FCS_ONLINE)
5344 rport_ids.node_name = wwn_to_u64(fcport->node_name);
5345 rport_ids.port_name = wwn_to_u64(fcport->port_name);
5346 rport_ids.port_id = fcport->d_id.b.domain << 16 |
5347 fcport->d_id.b.area << 8 | fcport->d_id.b.al_pa;
5348 rport_ids.roles = FC_RPORT_ROLE_UNKNOWN;
5349 fcport->rport = rport = fc_remote_port_add(vha->host, 0, &rport_ids);
5351 ql_log(ql_log_warn, vha, 0x2006,
5352 "Unable to allocate fc remote port.\n");
5356 spin_lock_irqsave(fcport->vha->host->host_lock, flags);
5357 *((fc_port_t **)rport->dd_data) = fcport;
5358 spin_unlock_irqrestore(fcport->vha->host->host_lock, flags);
5360 rport->supported_classes = fcport->supported_classes;
5362 rport_ids.roles = FC_PORT_ROLE_UNKNOWN;
5363 if (fcport->port_type == FCT_INITIATOR)
5364 rport_ids.roles |= FC_PORT_ROLE_FCP_INITIATOR;
5365 if (fcport->port_type == FCT_TARGET)
5366 rport_ids.roles |= FC_PORT_ROLE_FCP_TARGET;
5367 if (fcport->port_type & FCT_NVME_INITIATOR)
5368 rport_ids.roles |= FC_PORT_ROLE_NVME_INITIATOR;
5369 if (fcport->port_type & FCT_NVME_TARGET)
5370 rport_ids.roles |= FC_PORT_ROLE_NVME_TARGET;
5371 if (fcport->port_type & FCT_NVME_DISCOVERY)
5372 rport_ids.roles |= FC_PORT_ROLE_NVME_DISCOVERY;
5374 ql_dbg(ql_dbg_disc, vha, 0x20ee,
5375 "%s %8phN. rport %p is %s mode\n",
5376 __func__, fcport->port_name, rport,
5377 (fcport->port_type == FCT_TARGET) ? "tgt" :
5378 ((fcport->port_type & FCT_NVME) ? "nvme" : "ini"));
5380 fc_remote_port_rolechg(rport, rport_ids.roles);
5384 * qla2x00_update_fcport
5385 * Updates device on list.
5388 * ha = adapter block pointer.
5389 * fcport = port structure pointer.
5399 qla2x00_update_fcport(scsi_qla_host_t *vha, fc_port_t *fcport)
5401 if (IS_SW_RESV_ADDR(fcport->d_id))
5404 ql_dbg(ql_dbg_disc, vha, 0x20ef, "%s %8phC\n",
5405 __func__, fcport->port_name);
5407 fcport->disc_state = DSC_UPD_FCPORT;
5408 fcport->login_retry = vha->hw->login_retry_count;
5409 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
5410 fcport->deleted = 0;
5411 fcport->logout_on_delete = 1;
5412 fcport->n2n_chip_reset = fcport->n2n_link_reset_cnt = 0;
5414 switch (vha->hw->current_topology) {
5417 fcport->keep_nport_handle = 1;
5423 qla2x00_iidma_fcport(vha, fcport);
5425 if (fcport->fc4f_nvme) {
5426 qla_nvme_register_remote(vha, fcport);
5427 fcport->disc_state = DSC_LOGIN_COMPLETE;
5428 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5432 qla24xx_update_fcport_fcp_prio(vha, fcport);
5434 switch (vha->host->active_mode) {
5435 case MODE_INITIATOR:
5436 qla2x00_reg_remote_port(vha, fcport);
5439 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5440 !vha->vha_tgt.qla_tgt->tgt_stopped)
5441 qlt_fc_port_added(vha, fcport);
5444 qla2x00_reg_remote_port(vha, fcport);
5445 if (!vha->vha_tgt.qla_tgt->tgt_stop &&
5446 !vha->vha_tgt.qla_tgt->tgt_stopped)
5447 qlt_fc_port_added(vha, fcport);
5453 qla2x00_set_fcport_state(fcport, FCS_ONLINE);
5455 if (IS_IIDMA_CAPABLE(vha->hw) && vha->hw->flags.gpsc_supported) {
5456 if (fcport->id_changed) {
5457 fcport->id_changed = 0;
5458 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5459 "%s %d %8phC post gfpnid fcp_cnt %d\n",
5460 __func__, __LINE__, fcport->port_name,
5462 qla24xx_post_gfpnid_work(vha, fcport);
5464 ql_dbg(ql_dbg_disc, vha, 0x20d7,
5465 "%s %d %8phC post gpsc fcp_cnt %d\n",
5466 __func__, __LINE__, fcport->port_name,
5468 qla24xx_post_gpsc_work(vha, fcport);
5472 fcport->disc_state = DSC_LOGIN_COMPLETE;
5475 void qla_register_fcport_fn(struct work_struct *work)
5477 fc_port_t *fcport = container_of(work, struct fc_port, reg_work);
5478 u32 rscn_gen = fcport->rscn_gen;
5481 if (IS_SW_RESV_ADDR(fcport->d_id))
5484 qla2x00_update_fcport(fcport->vha, fcport);
5486 if (rscn_gen != fcport->rscn_gen) {
5487 /* RSCN(s) came in while registration */
5488 switch (fcport->next_disc_state) {
5489 case DSC_DELETE_PEND:
5490 qlt_schedule_sess_for_deletion(fcport);
5493 data[0] = data[1] = 0;
5494 qla2x00_post_async_adisc_work(fcport->vha, fcport,
5504 * qla2x00_configure_fabric
5505 * Setup SNS devices with loop ID's.
5508 * ha = adapter block pointer.
5515 qla2x00_configure_fabric(scsi_qla_host_t *vha)
5519 uint16_t mb[MAILBOX_REGISTER_COUNT];
5521 LIST_HEAD(new_fcports);
5522 struct qla_hw_data *ha = vha->hw;
5525 /* If FL port exists, then SNS is present */
5526 if (IS_FWI2_CAPABLE(ha))
5527 loop_id = NPH_F_PORT;
5529 loop_id = SNS_FL_PORT;
5530 rval = qla2x00_get_port_name(vha, loop_id, vha->fabric_node_name, 1);
5531 if (rval != QLA_SUCCESS) {
5532 ql_dbg(ql_dbg_disc, vha, 0x20a0,
5533 "MBX_GET_PORT_NAME failed, No FL Port.\n");
5535 vha->device_flags &= ~SWITCH_FOUND;
5536 return (QLA_SUCCESS);
5538 vha->device_flags |= SWITCH_FOUND;
5541 if (qla_tgt_mode_enabled(vha) || qla_dual_mode_enabled(vha)) {
5542 rval = qla2x00_send_change_request(vha, 0x3, 0);
5543 if (rval != QLA_SUCCESS)
5544 ql_log(ql_log_warn, vha, 0x121,
5545 "Failed to enable receiving of RSCN requests: 0x%x.\n",
5551 qla2x00_mgmt_svr_login(vha);
5554 if (ql2xfdmienable &&
5555 test_and_clear_bit(REGISTER_FDMI_NEEDED, &vha->dpc_flags))
5556 qla2x00_fdmi_register(vha);
5558 /* Ensure we are logged into the SNS. */
5559 loop_id = NPH_SNS_LID(ha);
5560 rval = ha->isp_ops->fabric_login(vha, loop_id, 0xff, 0xff,
5561 0xfc, mb, BIT_1|BIT_0);
5562 if (rval != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
5563 ql_dbg(ql_dbg_disc, vha, 0x20a1,
5564 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x mb[2]=%x mb[6]=%x mb[7]=%x (%x).\n",
5565 loop_id, mb[0], mb[1], mb[2], mb[6], mb[7], rval);
5566 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5569 if (test_and_clear_bit(REGISTER_FC4_NEEDED, &vha->dpc_flags)) {
5570 if (qla2x00_rft_id(vha)) {
5572 ql_dbg(ql_dbg_disc, vha, 0x20a2,
5573 "Register FC-4 TYPE failed.\n");
5574 if (test_bit(LOOP_RESYNC_NEEDED,
5578 if (qla2x00_rff_id(vha, FC4_TYPE_FCP_SCSI)) {
5580 ql_dbg(ql_dbg_disc, vha, 0x209a,
5581 "Register FC-4 Features failed.\n");
5582 if (test_bit(LOOP_RESYNC_NEEDED,
5586 if (vha->flags.nvme_enabled) {
5587 if (qla2x00_rff_id(vha, FC_TYPE_NVME)) {
5588 ql_dbg(ql_dbg_disc, vha, 0x2049,
5589 "Register NVME FC Type Features failed.\n");
5592 if (qla2x00_rnn_id(vha)) {
5594 ql_dbg(ql_dbg_disc, vha, 0x2104,
5595 "Register Node Name failed.\n");
5596 if (test_bit(LOOP_RESYNC_NEEDED,
5599 } else if (qla2x00_rsnn_nn(vha)) {
5601 ql_dbg(ql_dbg_disc, vha, 0x209b,
5602 "Register Symbolic Node Name failed.\n");
5603 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5609 /* Mark the time right before querying FW for connected ports.
5610 * This process is long, asynchronous and by the time it's done,
5611 * collected information might not be accurate anymore. E.g.
5612 * disconnected port might have re-connected and a brand new
5613 * session has been created. In this case session's generation
5614 * will be newer than discovery_gen. */
5615 qlt_do_generation_tick(vha, &discovery_gen);
5617 if (USE_ASYNC_SCAN(ha)) {
5618 rval = qla24xx_async_gpnft(vha, FC4_TYPE_FCP_SCSI,
5621 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5623 list_for_each_entry(fcport, &vha->vp_fcports, list)
5624 fcport->scan_state = QLA_FCPORT_SCAN;
5626 rval = qla2x00_find_all_fabric_devs(vha);
5628 if (rval != QLA_SUCCESS)
5632 if (!vha->nvme_local_port && vha->flags.nvme_enabled)
5633 qla_nvme_register_hba(vha);
5636 ql_dbg(ql_dbg_disc, vha, 0x2068,
5637 "Configure fabric error exit rval=%d.\n", rval);
5643 * qla2x00_find_all_fabric_devs
5646 * ha = adapter block pointer.
5647 * dev = database device entry pointer.
5656 qla2x00_find_all_fabric_devs(scsi_qla_host_t *vha)
5660 fc_port_t *fcport, *new_fcport;
5665 int first_dev, last_dev;
5666 port_id_t wrap = {}, nxt_d_id;
5667 struct qla_hw_data *ha = vha->hw;
5668 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
5669 unsigned long flags;
5673 /* Try GID_PT to get device list, else GAN. */
5675 ha->swl = kcalloc(ha->max_fibre_devices, sizeof(sw_info_t),
5680 ql_dbg(ql_dbg_disc, vha, 0x209c,
5681 "GID_PT allocations failed, fallback on GA_NXT.\n");
5683 memset(swl, 0, ha->max_fibre_devices * sizeof(sw_info_t));
5684 if (qla2x00_gid_pt(vha, swl) != QLA_SUCCESS) {
5686 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5688 } else if (qla2x00_gpn_id(vha, swl) != QLA_SUCCESS) {
5690 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5692 } else if (qla2x00_gnn_id(vha, swl) != QLA_SUCCESS) {
5694 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5696 } else if (qla2x00_gfpn_id(vha, swl) != QLA_SUCCESS) {
5698 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5702 /* If other queries succeeded probe for FC-4 type */
5704 qla2x00_gff_id(vha, swl);
5705 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5711 /* Allocate temporary fcport for any new fcports discovered. */
5712 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5713 if (new_fcport == NULL) {
5714 ql_log(ql_log_warn, vha, 0x209d,
5715 "Failed to allocate memory for fcport.\n");
5716 return (QLA_MEMORY_ALLOC_FAILED);
5718 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5719 /* Set start port ID scan at adapter ID. */
5723 /* Starting free loop ID. */
5724 loop_id = ha->min_external_loopid;
5725 for (; loop_id <= ha->max_loop_id; loop_id++) {
5726 if (qla2x00_is_reserved_id(vha, loop_id))
5729 if (ha->current_topology == ISP_CFG_FL &&
5730 (atomic_read(&vha->loop_down_timer) ||
5731 LOOP_TRANSITION(vha))) {
5732 atomic_set(&vha->loop_down_timer, 0);
5733 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
5734 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
5740 wrap.b24 = new_fcport->d_id.b24;
5742 new_fcport->d_id.b24 = swl[swl_idx].d_id.b24;
5743 memcpy(new_fcport->node_name,
5744 swl[swl_idx].node_name, WWN_SIZE);
5745 memcpy(new_fcport->port_name,
5746 swl[swl_idx].port_name, WWN_SIZE);
5747 memcpy(new_fcport->fabric_port_name,
5748 swl[swl_idx].fabric_port_name, WWN_SIZE);
5749 new_fcport->fp_speed = swl[swl_idx].fp_speed;
5750 new_fcport->fc4_type = swl[swl_idx].fc4_type;
5752 new_fcport->nvme_flag = 0;
5753 new_fcport->fc4f_nvme = 0;
5754 if (vha->flags.nvme_enabled &&
5755 swl[swl_idx].fc4f_nvme) {
5756 new_fcport->fc4f_nvme =
5757 swl[swl_idx].fc4f_nvme;
5758 ql_log(ql_log_info, vha, 0x2131,
5759 "FOUND: NVME port %8phC as FC Type 28h\n",
5760 new_fcport->port_name);
5763 if (swl[swl_idx].d_id.b.rsvd_1 != 0) {
5769 /* Send GA_NXT to the switch */
5770 rval = qla2x00_ga_nxt(vha, new_fcport);
5771 if (rval != QLA_SUCCESS) {
5772 ql_log(ql_log_warn, vha, 0x209e,
5773 "SNS scan failed -- assuming "
5774 "zero-entry result.\n");
5780 /* If wrap on switch device list, exit. */
5782 wrap.b24 = new_fcport->d_id.b24;
5784 } else if (new_fcport->d_id.b24 == wrap.b24) {
5785 ql_dbg(ql_dbg_disc, vha, 0x209f,
5786 "Device wrap (%02x%02x%02x).\n",
5787 new_fcport->d_id.b.domain,
5788 new_fcport->d_id.b.area,
5789 new_fcport->d_id.b.al_pa);
5793 /* Bypass if same physical adapter. */
5794 if (new_fcport->d_id.b24 == base_vha->d_id.b24)
5797 /* Bypass virtual ports of the same host. */
5798 if (qla2x00_is_a_vp_did(vha, new_fcport->d_id.b24))
5801 /* Bypass if same domain and area of adapter. */
5802 if (((new_fcport->d_id.b24 & 0xffff00) ==
5803 (vha->d_id.b24 & 0xffff00)) && ha->current_topology ==
5807 /* Bypass reserved domain fields. */
5808 if ((new_fcport->d_id.b.domain & 0xf0) == 0xf0)
5811 /* Bypass ports whose FCP-4 type is not FCP_SCSI */
5812 if (ql2xgffidenable &&
5813 (new_fcport->fc4_type != FC4_TYPE_FCP_SCSI &&
5814 new_fcport->fc4_type != FC4_TYPE_UNKNOWN))
5817 spin_lock_irqsave(&vha->hw->tgt.sess_lock, flags);
5819 /* Locate matching device in database. */
5821 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5822 if (memcmp(new_fcport->port_name, fcport->port_name,
5826 fcport->scan_state = QLA_FCPORT_FOUND;
5830 /* Update port state. */
5831 memcpy(fcport->fabric_port_name,
5832 new_fcport->fabric_port_name, WWN_SIZE);
5833 fcport->fp_speed = new_fcport->fp_speed;
5836 * If address the same and state FCS_ONLINE
5837 * (or in target mode), nothing changed.
5839 if (fcport->d_id.b24 == new_fcport->d_id.b24 &&
5840 (atomic_read(&fcport->state) == FCS_ONLINE ||
5841 (vha->host->active_mode == MODE_TARGET))) {
5846 * If device was not a fabric device before.
5848 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0) {
5849 fcport->d_id.b24 = new_fcport->d_id.b24;
5850 qla2x00_clear_loop_id(fcport);
5851 fcport->flags |= (FCF_FABRIC_DEVICE |
5857 * Port ID changed or device was marked to be updated;
5858 * Log it out if still logged in and mark it for
5861 if (qla_tgt_mode_enabled(base_vha)) {
5862 ql_dbg(ql_dbg_tgt_mgt, vha, 0xf080,
5863 "port changed FC ID, %8phC"
5864 " old %x:%x:%x (loop_id 0x%04x)-> new %x:%x:%x\n",
5866 fcport->d_id.b.domain,
5867 fcport->d_id.b.area,
5868 fcport->d_id.b.al_pa,
5870 new_fcport->d_id.b.domain,
5871 new_fcport->d_id.b.area,
5872 new_fcport->d_id.b.al_pa);
5873 fcport->d_id.b24 = new_fcport->d_id.b24;
5877 fcport->d_id.b24 = new_fcport->d_id.b24;
5878 fcport->flags |= FCF_LOGIN_NEEDED;
5882 if (fcport->fc4f_nvme) {
5883 if (fcport->disc_state == DSC_DELETE_PEND) {
5884 fcport->disc_state = DSC_GNL;
5885 vha->fcport_count--;
5886 fcport->login_succ = 0;
5891 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5894 /* If device was not in our fcports list, then add it. */
5895 new_fcport->scan_state = QLA_FCPORT_FOUND;
5896 list_add_tail(&new_fcport->list, &vha->vp_fcports);
5898 spin_unlock_irqrestore(&vha->hw->tgt.sess_lock, flags);
5901 /* Allocate a new replacement fcport. */
5902 nxt_d_id.b24 = new_fcport->d_id.b24;
5903 new_fcport = qla2x00_alloc_fcport(vha, GFP_KERNEL);
5904 if (new_fcport == NULL) {
5905 ql_log(ql_log_warn, vha, 0xd032,
5906 "Memory allocation failed for fcport.\n");
5907 return (QLA_MEMORY_ALLOC_FAILED);
5909 new_fcport->flags |= (FCF_FABRIC_DEVICE | FCF_LOGIN_NEEDED);
5910 new_fcport->d_id.b24 = nxt_d_id.b24;
5913 qla2x00_free_fcport(new_fcport);
5916 * Logout all previous fabric dev marked lost, except FCP2 devices.
5918 list_for_each_entry(fcport, &vha->vp_fcports, list) {
5919 if (test_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags))
5922 if ((fcport->flags & FCF_FABRIC_DEVICE) == 0 ||
5923 (fcport->flags & FCF_LOGIN_NEEDED) == 0)
5926 if (fcport->scan_state == QLA_FCPORT_SCAN) {
5927 if ((qla_dual_mode_enabled(vha) ||
5928 qla_ini_mode_enabled(vha)) &&
5929 atomic_read(&fcport->state) == FCS_ONLINE) {
5930 qla2x00_mark_device_lost(vha, fcport,
5931 ql2xplogiabsentdevice, 0);
5932 if (fcport->loop_id != FC_NO_LOOP_ID &&
5933 (fcport->flags & FCF_FCP2_DEVICE) == 0 &&
5934 fcport->port_type != FCT_INITIATOR &&
5935 fcport->port_type != FCT_BROADCAST) {
5936 ql_dbg(ql_dbg_disc, vha, 0x20f0,
5937 "%s %d %8phC post del sess\n",
5940 qlt_schedule_sess_for_deletion(fcport);
5946 if (fcport->scan_state == QLA_FCPORT_FOUND)
5947 qla24xx_fcport_handle_login(vha, fcport);
5952 /* FW does not set aside Loop id for MGMT Server/FFFFFAh */
5954 qla2x00_reserve_mgmt_server_loop_id(scsi_qla_host_t *vha)
5956 int loop_id = FC_NO_LOOP_ID;
5957 int lid = NPH_MGMT_SERVER - vha->vp_idx;
5958 unsigned long flags;
5959 struct qla_hw_data *ha = vha->hw;
5961 if (vha->vp_idx == 0) {
5962 set_bit(NPH_MGMT_SERVER, ha->loop_id_map);
5963 return NPH_MGMT_SERVER;
5966 /* pick id from high and work down to low */
5967 spin_lock_irqsave(&ha->vport_slock, flags);
5968 for (; lid > 0; lid--) {
5969 if (!test_bit(lid, vha->hw->loop_id_map)) {
5970 set_bit(lid, vha->hw->loop_id_map);
5975 spin_unlock_irqrestore(&ha->vport_slock, flags);
5981 * qla2x00_fabric_login
5982 * Issue fabric login command.
5985 * ha = adapter block pointer.
5986 * device = pointer to FC device type structure.
5989 * 0 - Login successfully
5991 * 2 - Initiator device
5995 qla2x00_fabric_login(scsi_qla_host_t *vha, fc_port_t *fcport,
5996 uint16_t *next_loopid)
6000 uint16_t tmp_loopid;
6001 uint16_t mb[MAILBOX_REGISTER_COUNT];
6002 struct qla_hw_data *ha = vha->hw;
6008 ql_dbg(ql_dbg_disc, vha, 0x2000,
6009 "Trying Fabric Login w/loop id 0x%04x for port "
6011 fcport->loop_id, fcport->d_id.b.domain,
6012 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6014 /* Login fcport on switch. */
6015 rval = ha->isp_ops->fabric_login(vha, fcport->loop_id,
6016 fcport->d_id.b.domain, fcport->d_id.b.area,
6017 fcport->d_id.b.al_pa, mb, BIT_0);
6018 if (rval != QLA_SUCCESS) {
6021 if (mb[0] == MBS_PORT_ID_USED) {
6023 * Device has another loop ID. The firmware team
6024 * recommends the driver perform an implicit login with
6025 * the specified ID again. The ID we just used is save
6026 * here so we return with an ID that can be tried by
6030 tmp_loopid = fcport->loop_id;
6031 fcport->loop_id = mb[1];
6033 ql_dbg(ql_dbg_disc, vha, 0x2001,
6034 "Fabric Login: port in use - next loop "
6035 "id=0x%04x, port id= %02x%02x%02x.\n",
6036 fcport->loop_id, fcport->d_id.b.domain,
6037 fcport->d_id.b.area, fcport->d_id.b.al_pa);
6039 } else if (mb[0] == MBS_COMMAND_COMPLETE) {
6044 /* A retry occurred before. */
6045 *next_loopid = tmp_loopid;
6048 * No retry occurred before. Just increment the
6049 * ID value for next login.
6051 *next_loopid = (fcport->loop_id + 1);
6054 if (mb[1] & BIT_0) {
6055 fcport->port_type = FCT_INITIATOR;
6057 fcport->port_type = FCT_TARGET;
6058 if (mb[1] & BIT_1) {
6059 fcport->flags |= FCF_FCP2_DEVICE;
6064 fcport->supported_classes |= FC_COS_CLASS2;
6066 fcport->supported_classes |= FC_COS_CLASS3;
6068 if (IS_FWI2_CAPABLE(ha)) {
6071 FCF_CONF_COMP_SUPPORTED;
6076 } else if (mb[0] == MBS_LOOP_ID_USED) {
6078 * Loop ID already used, try next loop ID.
6081 rval = qla2x00_find_new_loop_id(vha, fcport);
6082 if (rval != QLA_SUCCESS) {
6083 /* Ran out of loop IDs to use */
6086 } else if (mb[0] == MBS_COMMAND_ERROR) {
6088 * Firmware possibly timed out during login. If NO
6089 * retries are left to do then the device is declared
6092 *next_loopid = fcport->loop_id;
6093 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6094 fcport->d_id.b.domain, fcport->d_id.b.area,
6095 fcport->d_id.b.al_pa);
6096 qla2x00_mark_device_lost(vha, fcport, 1, 0);
6102 * unrecoverable / not handled error
6104 ql_dbg(ql_dbg_disc, vha, 0x2002,
6105 "Failed=%x port_id=%02x%02x%02x loop_id=%x "
6106 "jiffies=%lx.\n", mb[0], fcport->d_id.b.domain,
6107 fcport->d_id.b.area, fcport->d_id.b.al_pa,
6108 fcport->loop_id, jiffies);
6110 *next_loopid = fcport->loop_id;
6111 ha->isp_ops->fabric_logout(vha, fcport->loop_id,
6112 fcport->d_id.b.domain, fcport->d_id.b.area,
6113 fcport->d_id.b.al_pa);
6114 qla2x00_clear_loop_id(fcport);
6115 fcport->login_retry = 0;
6126 * qla2x00_local_device_login
6127 * Issue local device login command.
6130 * ha = adapter block pointer.
6131 * loop_id = loop id of device to login to.
6133 * Returns (Where's the #define!!!!):
6134 * 0 - Login successfully
6139 qla2x00_local_device_login(scsi_qla_host_t *vha, fc_port_t *fcport)
6142 uint16_t mb[MAILBOX_REGISTER_COUNT];
6144 memset(mb, 0, sizeof(mb));
6145 rval = qla2x00_login_local_device(vha, fcport, mb, BIT_0);
6146 if (rval == QLA_SUCCESS) {
6147 /* Interrogate mailbox registers for any errors */
6148 if (mb[0] == MBS_COMMAND_ERROR)
6150 else if (mb[0] == MBS_COMMAND_PARAMETER_ERROR)
6151 /* device not in PCB table */
6159 * qla2x00_loop_resync
6160 * Resync with fibre channel devices.
6163 * ha = adapter block pointer.
6169 qla2x00_loop_resync(scsi_qla_host_t *vha)
6171 int rval = QLA_SUCCESS;
6174 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6175 if (vha->flags.online) {
6176 if (!(rval = qla2x00_fw_ready(vha))) {
6177 /* Wait at most MAX_TARGET RSCNs for a stable link. */
6180 if (!IS_QLAFX00(vha->hw)) {
6182 * Issue a marker after FW becomes
6185 qla2x00_marker(vha, vha->hw->base_qpair,
6187 vha->marker_needed = 0;
6190 /* Remap devices on Loop. */
6191 clear_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6193 if (IS_QLAFX00(vha->hw))
6194 qlafx00_configure_devices(vha);
6196 qla2x00_configure_loop(vha);
6199 } while (!atomic_read(&vha->loop_down_timer) &&
6200 !(test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6201 && wait_time && (test_bit(LOOP_RESYNC_NEEDED,
6206 if (test_bit(ISP_ABORT_NEEDED, &vha->dpc_flags))
6207 return (QLA_FUNCTION_FAILED);
6210 ql_dbg(ql_dbg_disc, vha, 0x206c,
6211 "%s *** FAILED ***.\n", __func__);
6217 * qla2x00_perform_loop_resync
6218 * Description: This function will set the appropriate flags and call
6219 * qla2x00_loop_resync. If successful loop will be resynced
6220 * Arguments : scsi_qla_host_t pointer
6221 * returm : Success or Failure
6224 int qla2x00_perform_loop_resync(scsi_qla_host_t *ha)
6228 if (!test_and_set_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags)) {
6229 /*Configure the flags so that resync happens properly*/
6230 atomic_set(&ha->loop_down_timer, 0);
6231 if (!(ha->device_flags & DFLG_NO_CABLE)) {
6232 atomic_set(&ha->loop_state, LOOP_UP);
6233 set_bit(LOCAL_LOOP_UPDATE, &ha->dpc_flags);
6234 set_bit(REGISTER_FC4_NEEDED, &ha->dpc_flags);
6235 set_bit(LOOP_RESYNC_NEEDED, &ha->dpc_flags);
6237 rval = qla2x00_loop_resync(ha);
6239 atomic_set(&ha->loop_state, LOOP_DEAD);
6241 clear_bit(LOOP_RESYNC_ACTIVE, &ha->dpc_flags);
6248 qla2x00_update_fcports(scsi_qla_host_t *base_vha)
6251 struct scsi_qla_host *vha;
6252 struct qla_hw_data *ha = base_vha->hw;
6253 unsigned long flags;
6255 spin_lock_irqsave(&ha->vport_slock, flags);
6256 /* Go with deferred removal of rport references. */
6257 list_for_each_entry(vha, &base_vha->hw->vp_list, list) {
6258 atomic_inc(&vha->vref_count);
6259 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6260 if (fcport->drport &&
6261 atomic_read(&fcport->state) != FCS_UNCONFIGURED) {
6262 spin_unlock_irqrestore(&ha->vport_slock, flags);
6263 qla2x00_rport_del(fcport);
6265 spin_lock_irqsave(&ha->vport_slock, flags);
6268 atomic_dec(&vha->vref_count);
6269 wake_up(&vha->vref_waitq);
6271 spin_unlock_irqrestore(&ha->vport_slock, flags);
6274 /* Assumes idc_lock always held on entry */
6276 qla83xx_reset_ownership(scsi_qla_host_t *vha)
6278 struct qla_hw_data *ha = vha->hw;
6279 uint32_t drv_presence, drv_presence_mask;
6280 uint32_t dev_part_info1, dev_part_info2, class_type;
6281 uint32_t class_type_mask = 0x3;
6282 uint16_t fcoe_other_function = 0xffff, i;
6284 if (IS_QLA8044(ha)) {
6285 drv_presence = qla8044_rd_direct(vha,
6286 QLA8044_CRB_DRV_ACTIVE_INDEX);
6287 dev_part_info1 = qla8044_rd_direct(vha,
6288 QLA8044_CRB_DEV_PART_INFO_INDEX);
6289 dev_part_info2 = qla8044_rd_direct(vha,
6290 QLA8044_CRB_DEV_PART_INFO2);
6292 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6293 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO1, &dev_part_info1);
6294 qla83xx_rd_reg(vha, QLA83XX_DEV_PARTINFO2, &dev_part_info2);
6296 for (i = 0; i < 8; i++) {
6297 class_type = ((dev_part_info1 >> (i * 4)) & class_type_mask);
6298 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6299 (i != ha->portnum)) {
6300 fcoe_other_function = i;
6304 if (fcoe_other_function == 0xffff) {
6305 for (i = 0; i < 8; i++) {
6306 class_type = ((dev_part_info2 >> (i * 4)) &
6308 if ((class_type == QLA83XX_CLASS_TYPE_FCOE) &&
6309 ((i + 8) != ha->portnum)) {
6310 fcoe_other_function = i + 8;
6316 * Prepare drv-presence mask based on fcoe functions present.
6317 * However consider only valid physical fcoe function numbers (0-15).
6319 drv_presence_mask = ~((1 << (ha->portnum)) |
6320 ((fcoe_other_function == 0xffff) ?
6321 0 : (1 << (fcoe_other_function))));
6323 /* We are the reset owner iff:
6324 * - No other protocol drivers present.
6325 * - This is the lowest among fcoe functions. */
6326 if (!(drv_presence & drv_presence_mask) &&
6327 (ha->portnum < fcoe_other_function)) {
6328 ql_dbg(ql_dbg_p3p, vha, 0xb07f,
6329 "This host is Reset owner.\n");
6330 ha->flags.nic_core_reset_owner = 1;
6335 __qla83xx_set_drv_ack(scsi_qla_host_t *vha)
6337 int rval = QLA_SUCCESS;
6338 struct qla_hw_data *ha = vha->hw;
6341 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6342 if (rval == QLA_SUCCESS) {
6343 drv_ack |= (1 << ha->portnum);
6344 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6351 __qla83xx_clear_drv_ack(scsi_qla_host_t *vha)
6353 int rval = QLA_SUCCESS;
6354 struct qla_hw_data *ha = vha->hw;
6357 rval = qla83xx_rd_reg(vha, QLA83XX_IDC_DRIVER_ACK, &drv_ack);
6358 if (rval == QLA_SUCCESS) {
6359 drv_ack &= ~(1 << ha->portnum);
6360 rval = qla83xx_wr_reg(vha, QLA83XX_IDC_DRIVER_ACK, drv_ack);
6367 qla83xx_dev_state_to_string(uint32_t dev_state)
6369 switch (dev_state) {
6370 case QLA8XXX_DEV_COLD:
6371 return "COLD/RE-INIT";
6372 case QLA8XXX_DEV_INITIALIZING:
6373 return "INITIALIZING";
6374 case QLA8XXX_DEV_READY:
6376 case QLA8XXX_DEV_NEED_RESET:
6377 return "NEED RESET";
6378 case QLA8XXX_DEV_NEED_QUIESCENT:
6379 return "NEED QUIESCENT";
6380 case QLA8XXX_DEV_FAILED:
6382 case QLA8XXX_DEV_QUIESCENT:
6389 /* Assumes idc-lock always held on entry */
6391 qla83xx_idc_audit(scsi_qla_host_t *vha, int audit_type)
6393 struct qla_hw_data *ha = vha->hw;
6394 uint32_t idc_audit_reg = 0, duration_secs = 0;
6396 switch (audit_type) {
6397 case IDC_AUDIT_TIMESTAMP:
6398 ha->idc_audit_ts = (jiffies_to_msecs(jiffies) / 1000);
6399 idc_audit_reg = (ha->portnum) |
6400 (IDC_AUDIT_TIMESTAMP << 7) | (ha->idc_audit_ts << 8);
6401 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6404 case IDC_AUDIT_COMPLETION:
6405 duration_secs = ((jiffies_to_msecs(jiffies) -
6406 jiffies_to_msecs(ha->idc_audit_ts)) / 1000);
6407 idc_audit_reg = (ha->portnum) |
6408 (IDC_AUDIT_COMPLETION << 7) | (duration_secs << 8);
6409 qla83xx_wr_reg(vha, QLA83XX_IDC_AUDIT, idc_audit_reg);
6413 ql_log(ql_log_warn, vha, 0xb078,
6414 "Invalid audit type specified.\n");
6419 /* Assumes idc_lock always held on entry */
6421 qla83xx_initiating_reset(scsi_qla_host_t *vha)
6423 struct qla_hw_data *ha = vha->hw;
6424 uint32_t idc_control, dev_state;
6426 __qla83xx_get_idc_control(vha, &idc_control);
6427 if ((idc_control & QLA83XX_IDC_RESET_DISABLED)) {
6428 ql_log(ql_log_info, vha, 0xb080,
6429 "NIC Core reset has been disabled. idc-control=0x%x\n",
6431 return QLA_FUNCTION_FAILED;
6434 /* Set NEED-RESET iff in READY state and we are the reset-owner */
6435 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6436 if (ha->flags.nic_core_reset_owner && dev_state == QLA8XXX_DEV_READY) {
6437 qla83xx_wr_reg(vha, QLA83XX_IDC_DEV_STATE,
6438 QLA8XXX_DEV_NEED_RESET);
6439 ql_log(ql_log_info, vha, 0xb056, "HW State: NEED RESET.\n");
6440 qla83xx_idc_audit(vha, IDC_AUDIT_TIMESTAMP);
6442 const char *state = qla83xx_dev_state_to_string(dev_state);
6444 ql_log(ql_log_info, vha, 0xb057, "HW State: %s.\n", state);
6446 /* SV: XXX: Is timeout required here? */
6447 /* Wait for IDC state change READY -> NEED_RESET */
6448 while (dev_state == QLA8XXX_DEV_READY) {
6449 qla83xx_idc_unlock(vha, 0);
6451 qla83xx_idc_lock(vha, 0);
6452 qla83xx_rd_reg(vha, QLA83XX_IDC_DEV_STATE, &dev_state);
6456 /* Send IDC ack by writing to drv-ack register */
6457 __qla83xx_set_drv_ack(vha);
6463 __qla83xx_set_idc_control(scsi_qla_host_t *vha, uint32_t idc_control)
6465 return qla83xx_wr_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6469 __qla83xx_get_idc_control(scsi_qla_host_t *vha, uint32_t *idc_control)
6471 return qla83xx_rd_reg(vha, QLA83XX_IDC_CONTROL, idc_control);
6475 qla83xx_check_driver_presence(scsi_qla_host_t *vha)
6477 uint32_t drv_presence = 0;
6478 struct qla_hw_data *ha = vha->hw;
6480 qla83xx_rd_reg(vha, QLA83XX_IDC_DRV_PRESENCE, &drv_presence);
6481 if (drv_presence & (1 << ha->portnum))
6484 return QLA_TEST_FAILED;
6488 qla83xx_nic_core_reset(scsi_qla_host_t *vha)
6490 int rval = QLA_SUCCESS;
6491 struct qla_hw_data *ha = vha->hw;
6493 ql_dbg(ql_dbg_p3p, vha, 0xb058,
6494 "Entered %s().\n", __func__);
6496 if (vha->device_flags & DFLG_DEV_FAILED) {
6497 ql_log(ql_log_warn, vha, 0xb059,
6498 "Device in unrecoverable FAILED state.\n");
6499 return QLA_FUNCTION_FAILED;
6502 qla83xx_idc_lock(vha, 0);
6504 if (qla83xx_check_driver_presence(vha) != QLA_SUCCESS) {
6505 ql_log(ql_log_warn, vha, 0xb05a,
6506 "Function=0x%x has been removed from IDC participation.\n",
6508 rval = QLA_FUNCTION_FAILED;
6512 qla83xx_reset_ownership(vha);
6514 rval = qla83xx_initiating_reset(vha);
6517 * Perform reset if we are the reset-owner,
6518 * else wait till IDC state changes to READY/FAILED.
6520 if (rval == QLA_SUCCESS) {
6521 rval = qla83xx_idc_state_handler(vha);
6523 if (rval == QLA_SUCCESS)
6524 ha->flags.nic_core_hung = 0;
6525 __qla83xx_clear_drv_ack(vha);
6529 qla83xx_idc_unlock(vha, 0);
6531 ql_dbg(ql_dbg_p3p, vha, 0xb05b, "Exiting %s.\n", __func__);
6537 qla2xxx_mctp_dump(scsi_qla_host_t *vha)
6539 struct qla_hw_data *ha = vha->hw;
6540 int rval = QLA_FUNCTION_FAILED;
6542 if (!IS_MCTP_CAPABLE(ha)) {
6543 /* This message can be removed from the final version */
6544 ql_log(ql_log_info, vha, 0x506d,
6545 "This board is not MCTP capable\n");
6549 if (!ha->mctp_dump) {
6550 ha->mctp_dump = dma_alloc_coherent(&ha->pdev->dev,
6551 MCTP_DUMP_SIZE, &ha->mctp_dump_dma, GFP_KERNEL);
6553 if (!ha->mctp_dump) {
6554 ql_log(ql_log_warn, vha, 0x506e,
6555 "Failed to allocate memory for mctp dump\n");
6560 #define MCTP_DUMP_STR_ADDR 0x00000000
6561 rval = qla2x00_dump_mctp_data(vha, ha->mctp_dump_dma,
6562 MCTP_DUMP_STR_ADDR, MCTP_DUMP_SIZE/4);
6563 if (rval != QLA_SUCCESS) {
6564 ql_log(ql_log_warn, vha, 0x506f,
6565 "Failed to capture mctp dump\n");
6567 ql_log(ql_log_info, vha, 0x5070,
6568 "Mctp dump capture for host (%ld/%p).\n",
6569 vha->host_no, ha->mctp_dump);
6570 ha->mctp_dumped = 1;
6573 if (!ha->flags.nic_core_reset_hdlr_active && !ha->portnum) {
6574 ha->flags.nic_core_reset_hdlr_active = 1;
6575 rval = qla83xx_restart_nic_firmware(vha);
6577 /* NIC Core reset failed. */
6578 ql_log(ql_log_warn, vha, 0x5071,
6579 "Failed to restart nic firmware\n");
6581 ql_dbg(ql_dbg_p3p, vha, 0xb084,
6582 "Restarted NIC firmware successfully.\n");
6583 ha->flags.nic_core_reset_hdlr_active = 0;
6591 * qla2x00_quiesce_io
6592 * Description: This function will block the new I/Os
6593 * Its not aborting any I/Os as context
6594 * is not destroyed during quiescence
6595 * Arguments: scsi_qla_host_t
6599 qla2x00_quiesce_io(scsi_qla_host_t *vha)
6601 struct qla_hw_data *ha = vha->hw;
6602 struct scsi_qla_host *vp;
6604 ql_dbg(ql_dbg_dpc, vha, 0x401d,
6605 "Quiescing I/O - ha=%p.\n", ha);
6607 atomic_set(&ha->loop_down_timer, LOOP_DOWN_TIME);
6608 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6609 atomic_set(&vha->loop_state, LOOP_DOWN);
6610 qla2x00_mark_all_devices_lost(vha, 0);
6611 list_for_each_entry(vp, &ha->vp_list, list)
6612 qla2x00_mark_all_devices_lost(vp, 0);
6614 if (!atomic_read(&vha->loop_down_timer))
6615 atomic_set(&vha->loop_down_timer,
6618 /* Wait for pending cmds to complete */
6619 WARN_ON_ONCE(qla2x00_eh_wait_for_pending_commands(vha, 0, 0, WAIT_HOST)
6624 qla2x00_abort_isp_cleanup(scsi_qla_host_t *vha)
6626 struct qla_hw_data *ha = vha->hw;
6627 struct scsi_qla_host *vp;
6628 unsigned long flags;
6632 /* For ISP82XX, driver waits for completion of the commands.
6633 * online flag should be set.
6635 if (!(IS_P3P_TYPE(ha)))
6636 vha->flags.online = 0;
6637 ha->flags.chip_reset_done = 0;
6638 clear_bit(ISP_ABORT_NEEDED, &vha->dpc_flags);
6639 vha->qla_stats.total_isp_aborts++;
6641 ql_log(ql_log_info, vha, 0x00af,
6642 "Performing ISP error recovery - ha=%p.\n", ha);
6644 ha->flags.purge_mbox = 1;
6645 /* For ISP82XX, reset_chip is just disabling interrupts.
6646 * Driver waits for the completion of the commands.
6647 * the interrupts need to be enabled.
6649 if (!(IS_P3P_TYPE(ha)))
6650 ha->isp_ops->reset_chip(vha);
6652 ha->link_data_rate = PORT_SPEED_UNKNOWN;
6654 ha->flags.rida_fmt2 = 0;
6655 ha->flags.n2n_ae = 0;
6656 ha->flags.lip_ae = 0;
6657 ha->current_topology = 0;
6658 ha->flags.fw_started = 0;
6659 ha->flags.fw_init_done = 0;
6661 ha->base_qpair->chip_reset = ha->chip_reset;
6662 for (i = 0; i < ha->max_qpairs; i++) {
6663 if (ha->queue_pair_map[i])
6664 ha->queue_pair_map[i]->chip_reset =
6665 ha->base_qpair->chip_reset;
6668 /* purge MBox commands */
6669 if (atomic_read(&ha->num_pend_mbx_stage3)) {
6670 clear_bit(MBX_INTR_WAIT, &ha->mbx_cmd_flags);
6671 complete(&ha->mbx_intr_comp);
6675 while (atomic_read(&ha->num_pend_mbx_stage3) ||
6676 atomic_read(&ha->num_pend_mbx_stage2) ||
6677 atomic_read(&ha->num_pend_mbx_stage1)) {
6683 ha->flags.purge_mbox = 0;
6685 atomic_set(&vha->loop_down_timer, LOOP_DOWN_TIME);
6686 if (atomic_read(&vha->loop_state) != LOOP_DOWN) {
6687 atomic_set(&vha->loop_state, LOOP_DOWN);
6688 qla2x00_mark_all_devices_lost(vha, 0);
6690 spin_lock_irqsave(&ha->vport_slock, flags);
6691 list_for_each_entry(vp, &ha->vp_list, list) {
6692 atomic_inc(&vp->vref_count);
6693 spin_unlock_irqrestore(&ha->vport_slock, flags);
6695 qla2x00_mark_all_devices_lost(vp, 0);
6697 spin_lock_irqsave(&ha->vport_slock, flags);
6698 atomic_dec(&vp->vref_count);
6700 spin_unlock_irqrestore(&ha->vport_slock, flags);
6702 if (!atomic_read(&vha->loop_down_timer))
6703 atomic_set(&vha->loop_down_timer,
6707 /* Clear all async request states across all VPs. */
6708 list_for_each_entry(fcport, &vha->vp_fcports, list) {
6709 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6710 fcport->scan_state = 0;
6712 spin_lock_irqsave(&ha->vport_slock, flags);
6713 list_for_each_entry(vp, &ha->vp_list, list) {
6714 atomic_inc(&vp->vref_count);
6715 spin_unlock_irqrestore(&ha->vport_slock, flags);
6717 list_for_each_entry(fcport, &vp->vp_fcports, list)
6718 fcport->flags &= ~(FCF_LOGIN_NEEDED | FCF_ASYNC_SENT);
6720 spin_lock_irqsave(&ha->vport_slock, flags);
6721 atomic_dec(&vp->vref_count);
6723 spin_unlock_irqrestore(&ha->vport_slock, flags);
6725 if (!ha->flags.eeh_busy) {
6726 /* Make sure for ISP 82XX IO DMA is complete */
6727 if (IS_P3P_TYPE(ha)) {
6728 qla82xx_chip_reset_cleanup(vha);
6729 ql_log(ql_log_info, vha, 0x00b4,
6730 "Done chip reset cleanup.\n");
6732 /* Done waiting for pending commands.
6733 * Reset the online flag.
6735 vha->flags.online = 0;
6738 /* Requeue all commands in outstanding command list. */
6739 qla2x00_abort_all_cmds(vha, DID_RESET << 16);
6741 /* memory barrier */
6747 * Resets ISP and aborts all outstanding commands.
6750 * ha = adapter block pointer.
6756 qla2x00_abort_isp(scsi_qla_host_t *vha)
6760 struct qla_hw_data *ha = vha->hw;
6761 struct scsi_qla_host *vp;
6762 struct req_que *req = ha->req_q_map[0];
6763 unsigned long flags;
6765 if (vha->flags.online) {
6766 qla2x00_abort_isp_cleanup(vha);
6768 if (test_and_clear_bit(ISP_ABORT_TO_ROM, &vha->dpc_flags)) {
6769 ha->flags.chip_reset_done = 1;
6770 vha->flags.online = 1;
6772 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6776 if (IS_QLA8031(ha)) {
6777 ql_dbg(ql_dbg_p3p, vha, 0xb05c,
6778 "Clearing fcoe driver presence.\n");
6779 if (qla83xx_clear_drv_presence(vha) != QLA_SUCCESS)
6780 ql_dbg(ql_dbg_p3p, vha, 0xb073,
6781 "Error while clearing DRV-Presence.\n");
6784 if (unlikely(pci_channel_offline(ha->pdev) &&
6785 ha->flags.pci_channel_io_perm_failure)) {
6786 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6791 switch (vha->qlini_mode) {
6792 case QLA2XXX_INI_MODE_DISABLED:
6793 if (!qla_tgt_mode_enabled(vha))
6796 case QLA2XXX_INI_MODE_DUAL:
6797 if (!qla_dual_mode_enabled(vha))
6800 case QLA2XXX_INI_MODE_ENABLED:
6805 ha->isp_ops->get_flash_version(vha, req->ring);
6807 ha->isp_ops->nvram_config(vha);
6809 if (!qla2x00_restart_isp(vha)) {
6810 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6812 if (!atomic_read(&vha->loop_down_timer)) {
6814 * Issue marker command only when we are going
6815 * to start the I/O .
6817 vha->marker_needed = 1;
6820 vha->flags.online = 1;
6822 ha->isp_ops->enable_intrs(ha);
6824 ha->isp_abort_cnt = 0;
6825 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6827 if (IS_QLA81XX(ha) || IS_QLA8031(ha))
6828 qla2x00_get_fw_version(vha);
6830 ha->flags.fce_enabled = 1;
6832 fce_calc_size(ha->fce_bufs));
6833 rval = qla2x00_enable_fce_trace(vha,
6834 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
6837 ql_log(ql_log_warn, vha, 0x8033,
6838 "Unable to reinitialize FCE "
6840 ha->flags.fce_enabled = 0;
6845 memset(ha->eft, 0, EFT_SIZE);
6846 rval = qla2x00_enable_eft_trace(vha,
6847 ha->eft_dma, EFT_NUM_BUFFERS);
6849 ql_log(ql_log_warn, vha, 0x8034,
6850 "Unable to reinitialize EFT "
6854 } else { /* failed the ISP abort */
6855 vha->flags.online = 1;
6856 if (test_bit(ISP_ABORT_RETRY, &vha->dpc_flags)) {
6857 if (ha->isp_abort_cnt == 0) {
6858 ql_log(ql_log_fatal, vha, 0x8035,
6859 "ISP error recover failed - "
6860 "board disabled.\n");
6862 * The next call disables the board
6865 qla2x00_abort_isp_cleanup(vha);
6866 vha->flags.online = 0;
6867 clear_bit(ISP_ABORT_RETRY,
6870 } else { /* schedule another ISP abort */
6871 ha->isp_abort_cnt--;
6872 ql_dbg(ql_dbg_taskm, vha, 0x8020,
6873 "ISP abort - retry remaining %d.\n",
6878 ha->isp_abort_cnt = MAX_RETRIES_OF_ISP_ABORT;
6879 ql_dbg(ql_dbg_taskm, vha, 0x8021,
6880 "ISP error recovery - retrying (%d) "
6881 "more times.\n", ha->isp_abort_cnt);
6882 set_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
6890 ql_dbg(ql_dbg_taskm, vha, 0x8022, "%s succeeded.\n", __func__);
6891 qla2x00_configure_hba(vha);
6892 spin_lock_irqsave(&ha->vport_slock, flags);
6893 list_for_each_entry(vp, &ha->vp_list, list) {
6895 atomic_inc(&vp->vref_count);
6896 spin_unlock_irqrestore(&ha->vport_slock, flags);
6898 qla2x00_vp_abort_isp(vp);
6900 spin_lock_irqsave(&ha->vport_slock, flags);
6901 atomic_dec(&vp->vref_count);
6904 spin_unlock_irqrestore(&ha->vport_slock, flags);
6906 if (IS_QLA8031(ha)) {
6907 ql_dbg(ql_dbg_p3p, vha, 0xb05d,
6908 "Setting back fcoe driver presence.\n");
6909 if (qla83xx_set_drv_presence(vha) != QLA_SUCCESS)
6910 ql_dbg(ql_dbg_p3p, vha, 0xb074,
6911 "Error while setting DRV-Presence.\n");
6914 ql_log(ql_log_warn, vha, 0x8023, "%s **** FAILED ****.\n",
6922 * qla2x00_restart_isp
6923 * restarts the ISP after a reset
6926 * ha = adapter block pointer.
6932 qla2x00_restart_isp(scsi_qla_host_t *vha)
6935 struct qla_hw_data *ha = vha->hw;
6937 /* If firmware needs to be loaded */
6938 if (qla2x00_isp_firmware(vha)) {
6939 vha->flags.online = 0;
6940 status = ha->isp_ops->chip_diag(vha);
6942 status = qla2x00_setup_chip(vha);
6945 if (!status && !(status = qla2x00_init_rings(vha))) {
6946 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
6947 ha->flags.chip_reset_done = 1;
6949 /* Initialize the queues in use */
6950 qla25xx_init_queues(ha);
6952 status = qla2x00_fw_ready(vha);
6954 /* Issue a marker after FW becomes ready. */
6955 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
6956 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
6959 /* if no cable then assume it's good */
6960 if ((vha->device_flags & DFLG_NO_CABLE))
6967 qla25xx_init_queues(struct qla_hw_data *ha)
6969 struct rsp_que *rsp = NULL;
6970 struct req_que *req = NULL;
6971 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
6975 for (i = 1; i < ha->max_rsp_queues; i++) {
6976 rsp = ha->rsp_q_map[i];
6977 if (rsp && test_bit(i, ha->rsp_qid_map)) {
6978 rsp->options &= ~BIT_0;
6979 ret = qla25xx_init_rsp_que(base_vha, rsp);
6980 if (ret != QLA_SUCCESS)
6981 ql_dbg(ql_dbg_init, base_vha, 0x00ff,
6982 "%s Rsp que: %d init failed.\n",
6985 ql_dbg(ql_dbg_init, base_vha, 0x0100,
6986 "%s Rsp que: %d inited.\n",
6990 for (i = 1; i < ha->max_req_queues; i++) {
6991 req = ha->req_q_map[i];
6992 if (req && test_bit(i, ha->req_qid_map)) {
6993 /* Clear outstanding commands array. */
6994 req->options &= ~BIT_0;
6995 ret = qla25xx_init_req_que(base_vha, req);
6996 if (ret != QLA_SUCCESS)
6997 ql_dbg(ql_dbg_init, base_vha, 0x0101,
6998 "%s Req que: %d init failed.\n",
7001 ql_dbg(ql_dbg_init, base_vha, 0x0102,
7002 "%s Req que: %d inited.\n",
7010 * qla2x00_reset_adapter
7014 * ha = adapter block pointer.
7017 qla2x00_reset_adapter(scsi_qla_host_t *vha)
7019 unsigned long flags = 0;
7020 struct qla_hw_data *ha = vha->hw;
7021 struct device_reg_2xxx __iomem *reg = &ha->iobase->isp;
7023 vha->flags.online = 0;
7024 ha->isp_ops->disable_intrs(ha);
7026 spin_lock_irqsave(&ha->hardware_lock, flags);
7027 WRT_REG_WORD(®->hccr, HCCR_RESET_RISC);
7028 RD_REG_WORD(®->hccr); /* PCI Posting. */
7029 WRT_REG_WORD(®->hccr, HCCR_RELEASE_RISC);
7030 RD_REG_WORD(®->hccr); /* PCI Posting. */
7031 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7037 qla24xx_reset_adapter(scsi_qla_host_t *vha)
7039 unsigned long flags = 0;
7040 struct qla_hw_data *ha = vha->hw;
7041 struct device_reg_24xx __iomem *reg = &ha->iobase->isp24;
7042 int rval = QLA_SUCCESS;
7044 if (IS_P3P_TYPE(ha))
7047 vha->flags.online = 0;
7048 ha->isp_ops->disable_intrs(ha);
7050 spin_lock_irqsave(&ha->hardware_lock, flags);
7051 WRT_REG_DWORD(®->hccr, HCCRX_SET_RISC_RESET);
7052 RD_REG_DWORD(®->hccr);
7053 WRT_REG_DWORD(®->hccr, HCCRX_REL_RISC_PAUSE);
7054 RD_REG_DWORD(®->hccr);
7055 spin_unlock_irqrestore(&ha->hardware_lock, flags);
7057 if (IS_NOPOLLING_TYPE(ha))
7058 ha->isp_ops->enable_intrs(ha);
7063 /* On sparc systems, obtain port and node WWN from firmware
7066 static void qla24xx_nvram_wwn_from_ofw(scsi_qla_host_t *vha,
7067 struct nvram_24xx *nv)
7070 struct qla_hw_data *ha = vha->hw;
7071 struct pci_dev *pdev = ha->pdev;
7072 struct device_node *dp = pci_device_to_OF_node(pdev);
7076 val = of_get_property(dp, "port-wwn", &len);
7077 if (val && len >= WWN_SIZE)
7078 memcpy(nv->port_name, val, WWN_SIZE);
7080 val = of_get_property(dp, "node-wwn", &len);
7081 if (val && len >= WWN_SIZE)
7082 memcpy(nv->node_name, val, WWN_SIZE);
7087 qla24xx_nvram_config(scsi_qla_host_t *vha)
7090 struct init_cb_24xx *icb;
7091 struct nvram_24xx *nv;
7093 uint8_t *dptr1, *dptr2;
7096 struct qla_hw_data *ha = vha->hw;
7099 icb = (struct init_cb_24xx *)ha->init_cb;
7102 /* Determine NVRAM starting address. */
7103 if (ha->port_no == 0) {
7104 ha->nvram_base = FA_NVRAM_FUNC0_ADDR;
7105 ha->vpd_base = FA_NVRAM_VPD0_ADDR;
7107 ha->nvram_base = FA_NVRAM_FUNC1_ADDR;
7108 ha->vpd_base = FA_NVRAM_VPD1_ADDR;
7111 ha->nvram_size = sizeof(*nv);
7112 ha->vpd_size = FA_NVRAM_VPD_SIZE;
7114 /* Get VPD data into cache */
7115 ha->vpd = ha->nvram + VPD_OFFSET;
7116 ha->isp_ops->read_nvram(vha, ha->vpd,
7117 ha->nvram_base - FA_NVRAM_FUNC0_ADDR, FA_NVRAM_VPD_SIZE * 4);
7119 /* Get NVRAM data into cache and calculate checksum. */
7120 dptr = (uint32_t *)nv;
7121 ha->isp_ops->read_nvram(vha, dptr, ha->nvram_base, ha->nvram_size);
7122 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
7123 chksum += le32_to_cpu(*dptr);
7125 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x006a,
7126 "Contents of NVRAM\n");
7127 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x010d,
7128 nv, ha->nvram_size);
7130 /* Bad NVRAM data, set defaults parameters. */
7131 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
7132 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
7133 /* Reset NVRAM data. */
7134 ql_log(ql_log_warn, vha, 0x006b,
7135 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
7136 chksum, nv->id, nv->nvram_version);
7137 ql_dump_buffer(ql_dbg_init, vha, 0x006b, nv, sizeof(*nv));
7138 ql_log(ql_log_warn, vha, 0x006c,
7139 "Falling back to functioning (yet invalid -- WWPN) "
7143 * Set default initialization control block.
7145 memset(nv, 0, ha->nvram_size);
7146 nv->nvram_version = cpu_to_le16(ICB_VERSION);
7147 nv->version = cpu_to_le16(ICB_VERSION);
7148 nv->frame_payload_size = 2048;
7149 nv->execution_throttle = cpu_to_le16(0xFFFF);
7150 nv->exchange_count = cpu_to_le16(0);
7151 nv->hard_address = cpu_to_le16(124);
7152 nv->port_name[0] = 0x21;
7153 nv->port_name[1] = 0x00 + ha->port_no + 1;
7154 nv->port_name[2] = 0x00;
7155 nv->port_name[3] = 0xe0;
7156 nv->port_name[4] = 0x8b;
7157 nv->port_name[5] = 0x1c;
7158 nv->port_name[6] = 0x55;
7159 nv->port_name[7] = 0x86;
7160 nv->node_name[0] = 0x20;
7161 nv->node_name[1] = 0x00;
7162 nv->node_name[2] = 0x00;
7163 nv->node_name[3] = 0xe0;
7164 nv->node_name[4] = 0x8b;
7165 nv->node_name[5] = 0x1c;
7166 nv->node_name[6] = 0x55;
7167 nv->node_name[7] = 0x86;
7168 qla24xx_nvram_wwn_from_ofw(vha, nv);
7169 nv->login_retry_count = cpu_to_le16(8);
7170 nv->interrupt_delay_timer = cpu_to_le16(0);
7171 nv->login_timeout = cpu_to_le16(0);
7172 nv->firmware_options_1 =
7173 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
7174 nv->firmware_options_2 = cpu_to_le32(2 << 4);
7175 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
7176 nv->firmware_options_3 = cpu_to_le32(2 << 13);
7177 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
7178 nv->efi_parameters = cpu_to_le32(0);
7179 nv->reset_delay = 5;
7180 nv->max_luns_per_target = cpu_to_le16(128);
7181 nv->port_down_retry_count = cpu_to_le16(30);
7182 nv->link_down_timeout = cpu_to_le16(30);
7187 if (qla_tgt_mode_enabled(vha)) {
7188 /* Don't enable full login after initial LIP */
7189 nv->firmware_options_1 &= cpu_to_le32(~BIT_13);
7190 /* Don't enable LIP full login for initiator */
7191 nv->host_p &= cpu_to_le32(~BIT_10);
7194 qlt_24xx_config_nvram_stage1(vha, nv);
7196 /* Reset Initialization control block */
7197 memset(icb, 0, ha->init_cb_size);
7199 /* Copy 1st segment. */
7200 dptr1 = (uint8_t *)icb;
7201 dptr2 = (uint8_t *)&nv->version;
7202 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
7204 *dptr1++ = *dptr2++;
7206 icb->login_retry_count = nv->login_retry_count;
7207 icb->link_down_on_nos = nv->link_down_on_nos;
7209 /* Copy 2nd segment. */
7210 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
7211 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
7212 cnt = (uint8_t *)&icb->reserved_3 -
7213 (uint8_t *)&icb->interrupt_delay_timer;
7215 *dptr1++ = *dptr2++;
7216 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
7218 * Setup driver NVRAM options.
7220 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
7223 qlt_24xx_config_nvram_stage2(vha, icb);
7225 if (nv->host_p & cpu_to_le32(BIT_15)) {
7226 /* Use alternate WWN? */
7227 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
7228 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
7231 /* Prepare nodename */
7232 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
7234 * Firmware will apply the following mask if the nodename was
7237 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
7238 icb->node_name[0] &= 0xF0;
7241 /* Set host adapter parameters. */
7242 ha->flags.disable_risc_code_load = 0;
7243 ha->flags.enable_lip_reset = 0;
7244 ha->flags.enable_lip_full_login =
7245 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
7246 ha->flags.enable_target_reset =
7247 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
7248 ha->flags.enable_led_scheme = 0;
7249 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
7251 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
7252 (BIT_6 | BIT_5 | BIT_4)) >> 4;
7254 memcpy(ha->fw_seriallink_options24, nv->seriallink_options,
7255 sizeof(ha->fw_seriallink_options24));
7257 /* save HBA serial number */
7258 ha->serial0 = icb->port_name[5];
7259 ha->serial1 = icb->port_name[6];
7260 ha->serial2 = icb->port_name[7];
7261 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
7262 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
7264 icb->execution_throttle = cpu_to_le16(0xFFFF);
7266 ha->retry_count = le16_to_cpu(nv->login_retry_count);
7268 /* Set minimum login_timeout to 4 seconds. */
7269 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
7270 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
7271 if (le16_to_cpu(nv->login_timeout) < 4)
7272 nv->login_timeout = cpu_to_le16(4);
7273 ha->login_timeout = le16_to_cpu(nv->login_timeout);
7275 /* Set minimum RATOV to 100 tenths of a second. */
7278 ha->loop_reset_delay = nv->reset_delay;
7280 /* Link Down Timeout = 0:
7282 * When Port Down timer expires we will start returning
7283 * I/O's to OS with "DID_NO_CONNECT".
7285 * Link Down Timeout != 0:
7287 * The driver waits for the link to come up after link down
7288 * before returning I/Os to OS with "DID_NO_CONNECT".
7290 if (le16_to_cpu(nv->link_down_timeout) == 0) {
7291 ha->loop_down_abort_time =
7292 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
7294 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
7295 ha->loop_down_abort_time =
7296 (LOOP_DOWN_TIME - ha->link_down_timeout);
7299 /* Need enough time to try and get the port back. */
7300 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
7301 if (qlport_down_retry)
7302 ha->port_down_retry_count = qlport_down_retry;
7304 /* Set login_retry_count */
7305 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
7306 if (ha->port_down_retry_count ==
7307 le16_to_cpu(nv->port_down_retry_count) &&
7308 ha->port_down_retry_count > 3)
7309 ha->login_retry_count = ha->port_down_retry_count;
7310 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
7311 ha->login_retry_count = ha->port_down_retry_count;
7312 if (ql2xloginretrycount)
7313 ha->login_retry_count = ql2xloginretrycount;
7315 /* N2N: driver will initiate Login instead of FW */
7316 icb->firmware_options_3 |= BIT_8;
7319 if (!vha->flags.init_done) {
7320 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
7321 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
7322 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
7323 le16_to_cpu(icb->interrupt_delay_timer) : 2;
7325 icb->firmware_options_2 &= cpu_to_le32(
7326 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
7327 if (ha->zio_mode != QLA_ZIO_DISABLED) {
7328 ha->zio_mode = QLA_ZIO_MODE_6;
7330 ql_log(ql_log_info, vha, 0x006f,
7331 "ZIO mode %d enabled; timer delay (%d us).\n",
7332 ha->zio_mode, ha->zio_timer * 100);
7334 icb->firmware_options_2 |= cpu_to_le32(
7335 (uint32_t)ha->zio_mode);
7336 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
7340 ql_log(ql_log_warn, vha, 0x0070,
7341 "NVRAM configuration failed.\n");
7347 qla27xx_print_image(struct scsi_qla_host *vha, char *name,
7348 struct qla27xx_image_status *image_status)
7350 ql_dbg(ql_dbg_init, vha, 0x018b,
7351 "%s %s: mask=%#02x gen=%#04x ver=%u.%u map=%#01x sum=%#08x sig=%#08x\n",
7353 image_status->image_status_mask,
7354 le16_to_cpu(image_status->generation),
7355 image_status->ver_major,
7356 image_status->ver_minor,
7357 image_status->bitmap,
7358 le32_to_cpu(image_status->checksum),
7359 le32_to_cpu(image_status->signature));
7363 qla28xx_check_aux_image_status_signature(
7364 struct qla27xx_image_status *image_status)
7366 ulong signature = le32_to_cpu(image_status->signature);
7368 return signature != QLA28XX_AUX_IMG_STATUS_SIGN;
7372 qla27xx_check_image_status_signature(struct qla27xx_image_status *image_status)
7374 ulong signature = le32_to_cpu(image_status->signature);
7377 signature != QLA27XX_IMG_STATUS_SIGN &&
7378 signature != QLA28XX_IMG_STATUS_SIGN;
7382 qla27xx_image_status_checksum(struct qla27xx_image_status *image_status)
7384 uint32_t *p = (void *)image_status;
7385 uint n = sizeof(*image_status) / sizeof(*p);
7389 sum += le32_to_cpup(p);
7395 qla28xx_component_bitmask(struct qla27xx_image_status *aux, uint bitmask)
7397 return aux->bitmap & bitmask ?
7398 QLA27XX_SECONDARY_IMAGE : QLA27XX_PRIMARY_IMAGE;
7402 qla28xx_component_status(
7403 struct active_regions *active_regions, struct qla27xx_image_status *aux)
7405 active_regions->aux.board_config =
7406 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_BOARD_CONFIG);
7408 active_regions->aux.vpd_nvram =
7409 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_VPD_NVRAM);
7411 active_regions->aux.npiv_config_0_1 =
7412 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_0_1);
7414 active_regions->aux.npiv_config_2_3 =
7415 qla28xx_component_bitmask(aux, QLA28XX_AUX_IMG_NPIV_CONFIG_2_3);
7419 qla27xx_compare_image_generation(
7420 struct qla27xx_image_status *pri_image_status,
7421 struct qla27xx_image_status *sec_image_status)
7423 /* calculate generation delta as uint16 (this accounts for wrap) */
7425 le16_to_cpu(pri_image_status->generation) -
7426 le16_to_cpu(sec_image_status->generation);
7428 ql_dbg(ql_dbg_init, NULL, 0x0180, "generation delta = %d\n", delta);
7434 qla28xx_get_aux_images(
7435 struct scsi_qla_host *vha, struct active_regions *active_regions)
7437 struct qla_hw_data *ha = vha->hw;
7438 struct qla27xx_image_status pri_aux_image_status, sec_aux_image_status;
7439 bool valid_pri_image = false, valid_sec_image = false;
7440 bool active_pri_image = false, active_sec_image = false;
7442 if (!ha->flt_region_aux_img_status_pri) {
7443 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary aux image not addressed\n");
7444 goto check_sec_image;
7447 qla24xx_read_flash_data(vha, (void *)&pri_aux_image_status,
7448 ha->flt_region_aux_img_status_pri,
7449 sizeof(pri_aux_image_status) >> 2);
7450 qla27xx_print_image(vha, "Primary aux image", &pri_aux_image_status);
7452 if (qla28xx_check_aux_image_status_signature(&pri_aux_image_status)) {
7453 ql_dbg(ql_dbg_init, vha, 0x018b,
7454 "Primary aux image signature (%#x) not valid\n",
7455 le32_to_cpu(pri_aux_image_status.signature));
7456 goto check_sec_image;
7459 if (qla27xx_image_status_checksum(&pri_aux_image_status)) {
7460 ql_dbg(ql_dbg_init, vha, 0x018c,
7461 "Primary aux image checksum failed\n");
7462 goto check_sec_image;
7465 valid_pri_image = true;
7467 if (pri_aux_image_status.image_status_mask & 1) {
7468 ql_dbg(ql_dbg_init, vha, 0x018d,
7469 "Primary aux image is active\n");
7470 active_pri_image = true;
7474 if (!ha->flt_region_aux_img_status_sec) {
7475 ql_dbg(ql_dbg_init, vha, 0x018a,
7476 "Secondary aux image not addressed\n");
7477 goto check_valid_image;
7480 qla24xx_read_flash_data(vha, (void *)&sec_aux_image_status,
7481 ha->flt_region_aux_img_status_sec,
7482 sizeof(sec_aux_image_status) >> 2);
7483 qla27xx_print_image(vha, "Secondary aux image", &sec_aux_image_status);
7485 if (qla28xx_check_aux_image_status_signature(&sec_aux_image_status)) {
7486 ql_dbg(ql_dbg_init, vha, 0x018b,
7487 "Secondary aux image signature (%#x) not valid\n",
7488 le32_to_cpu(sec_aux_image_status.signature));
7489 goto check_valid_image;
7492 if (qla27xx_image_status_checksum(&sec_aux_image_status)) {
7493 ql_dbg(ql_dbg_init, vha, 0x018c,
7494 "Secondary aux image checksum failed\n");
7495 goto check_valid_image;
7498 valid_sec_image = true;
7500 if (sec_aux_image_status.image_status_mask & 1) {
7501 ql_dbg(ql_dbg_init, vha, 0x018d,
7502 "Secondary aux image is active\n");
7503 active_sec_image = true;
7507 if (valid_pri_image && active_pri_image &&
7508 valid_sec_image && active_sec_image) {
7509 if (qla27xx_compare_image_generation(&pri_aux_image_status,
7510 &sec_aux_image_status) >= 0) {
7511 qla28xx_component_status(active_regions,
7512 &pri_aux_image_status);
7514 qla28xx_component_status(active_regions,
7515 &sec_aux_image_status);
7517 } else if (valid_pri_image && active_pri_image) {
7518 qla28xx_component_status(active_regions, &pri_aux_image_status);
7519 } else if (valid_sec_image && active_sec_image) {
7520 qla28xx_component_status(active_regions, &sec_aux_image_status);
7523 ql_dbg(ql_dbg_init, vha, 0x018f,
7524 "aux images active: BCFG=%u VPD/NVR=%u NPIV0/1=%u NPIV2/3=%u\n",
7525 active_regions->aux.board_config,
7526 active_regions->aux.vpd_nvram,
7527 active_regions->aux.npiv_config_0_1,
7528 active_regions->aux.npiv_config_2_3);
7532 qla27xx_get_active_image(struct scsi_qla_host *vha,
7533 struct active_regions *active_regions)
7535 struct qla_hw_data *ha = vha->hw;
7536 struct qla27xx_image_status pri_image_status, sec_image_status;
7537 bool valid_pri_image = false, valid_sec_image = false;
7538 bool active_pri_image = false, active_sec_image = false;
7540 if (!ha->flt_region_img_status_pri) {
7541 ql_dbg(ql_dbg_init, vha, 0x018a, "Primary image not addressed\n");
7542 goto check_sec_image;
7545 if (qla24xx_read_flash_data(vha, (void *)(&pri_image_status),
7546 ha->flt_region_img_status_pri, sizeof(pri_image_status) >> 2) !=
7549 goto check_sec_image;
7551 qla27xx_print_image(vha, "Primary image", &pri_image_status);
7553 if (qla27xx_check_image_status_signature(&pri_image_status)) {
7554 ql_dbg(ql_dbg_init, vha, 0x018b,
7555 "Primary image signature (%#x) not valid\n",
7556 le32_to_cpu(pri_image_status.signature));
7557 goto check_sec_image;
7560 if (qla27xx_image_status_checksum(&pri_image_status)) {
7561 ql_dbg(ql_dbg_init, vha, 0x018c,
7562 "Primary image checksum failed\n");
7563 goto check_sec_image;
7566 valid_pri_image = true;
7568 if (pri_image_status.image_status_mask & 1) {
7569 ql_dbg(ql_dbg_init, vha, 0x018d,
7570 "Primary image is active\n");
7571 active_pri_image = true;
7575 if (!ha->flt_region_img_status_sec) {
7576 ql_dbg(ql_dbg_init, vha, 0x018a, "Secondary image not addressed\n");
7577 goto check_valid_image;
7580 qla24xx_read_flash_data(vha, (uint32_t *)(&sec_image_status),
7581 ha->flt_region_img_status_sec, sizeof(sec_image_status) >> 2);
7582 qla27xx_print_image(vha, "Secondary image", &sec_image_status);
7584 if (qla27xx_check_image_status_signature(&sec_image_status)) {
7585 ql_dbg(ql_dbg_init, vha, 0x018b,
7586 "Secondary image signature (%#x) not valid\n",
7587 le32_to_cpu(sec_image_status.signature));
7588 goto check_valid_image;
7591 if (qla27xx_image_status_checksum(&sec_image_status)) {
7592 ql_dbg(ql_dbg_init, vha, 0x018c,
7593 "Secondary image checksum failed\n");
7594 goto check_valid_image;
7597 valid_sec_image = true;
7599 if (sec_image_status.image_status_mask & 1) {
7600 ql_dbg(ql_dbg_init, vha, 0x018d,
7601 "Secondary image is active\n");
7602 active_sec_image = true;
7606 if (valid_pri_image && active_pri_image)
7607 active_regions->global = QLA27XX_PRIMARY_IMAGE;
7609 if (valid_sec_image && active_sec_image) {
7610 if (!active_regions->global ||
7611 qla27xx_compare_image_generation(
7612 &pri_image_status, &sec_image_status) < 0) {
7613 active_regions->global = QLA27XX_SECONDARY_IMAGE;
7617 ql_dbg(ql_dbg_init, vha, 0x018f, "active image %s (%u)\n",
7618 active_regions->global == QLA27XX_DEFAULT_IMAGE ?
7619 "default (boot/fw)" :
7620 active_regions->global == QLA27XX_PRIMARY_IMAGE ?
7622 active_regions->global == QLA27XX_SECONDARY_IMAGE ?
7623 "secondary" : "invalid",
7624 active_regions->global);
7627 bool qla24xx_risc_firmware_invalid(uint32_t *dword)
7630 !(dword[4] | dword[5] | dword[6] | dword[7]) ||
7631 !(~dword[4] | ~dword[5] | ~dword[6] | ~dword[7]);
7635 qla24xx_load_risc_flash(scsi_qla_host_t *vha, uint32_t *srisc_addr,
7639 uint templates, segments, fragment;
7644 uint32_t risc_addr, risc_size, risc_attr = 0;
7645 struct qla_hw_data *ha = vha->hw;
7646 struct req_que *req = ha->req_q_map[0];
7647 struct fwdt *fwdt = ha->fwdt;
7649 ql_dbg(ql_dbg_init, vha, 0x008b,
7650 "FW: Loading firmware from flash (%x).\n", faddr);
7652 dcode = (void *)req->ring;
7653 qla24xx_read_flash_data(vha, dcode, faddr, 8);
7654 if (qla24xx_risc_firmware_invalid(dcode)) {
7655 ql_log(ql_log_fatal, vha, 0x008c,
7656 "Unable to verify the integrity of flash firmware "
7658 ql_log(ql_log_fatal, vha, 0x008d,
7659 "Firmware data: %08x %08x %08x %08x.\n",
7660 dcode[0], dcode[1], dcode[2], dcode[3]);
7662 return QLA_FUNCTION_FAILED;
7665 dcode = (void *)req->ring;
7667 segments = FA_RISC_CODE_SEGMENTS;
7668 for (j = 0; j < segments; j++) {
7669 ql_dbg(ql_dbg_init, vha, 0x008d,
7670 "-> Loading segment %u...\n", j);
7671 qla24xx_read_flash_data(vha, dcode, faddr, 10);
7672 risc_addr = be32_to_cpu(dcode[2]);
7673 risc_size = be32_to_cpu(dcode[3]);
7675 *srisc_addr = risc_addr;
7676 risc_attr = be32_to_cpu(dcode[9]);
7679 dlen = ha->fw_transfer_size >> 2;
7680 for (fragment = 0; risc_size; fragment++) {
7681 if (dlen > risc_size)
7684 ql_dbg(ql_dbg_init, vha, 0x008e,
7685 "-> Loading fragment %u: %#x <- %#x (%#lx dwords)...\n",
7686 fragment, risc_addr, faddr, dlen);
7687 qla24xx_read_flash_data(vha, dcode, faddr, dlen);
7688 for (i = 0; i < dlen; i++)
7689 dcode[i] = swab32(dcode[i]);
7691 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7693 ql_log(ql_log_fatal, vha, 0x008f,
7694 "-> Failed load firmware fragment %u.\n",
7696 return QLA_FUNCTION_FAILED;
7705 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7708 templates = (risc_attr & BIT_9) ? 2 : 1;
7709 ql_dbg(ql_dbg_init, vha, 0x0160, "-> templates = %u\n", templates);
7710 for (j = 0; j < templates; j++, fwdt++) {
7712 vfree(fwdt->template);
7713 fwdt->template = NULL;
7716 dcode = (void *)req->ring;
7717 qla24xx_read_flash_data(vha, dcode, faddr, 7);
7718 risc_size = be32_to_cpu(dcode[2]);
7719 ql_dbg(ql_dbg_init, vha, 0x0161,
7720 "-> fwdt%u template array at %#x (%#x dwords)\n",
7721 j, faddr, risc_size);
7722 if (!risc_size || !~risc_size) {
7723 ql_dbg(ql_dbg_init, vha, 0x0162,
7724 "-> fwdt%u failed to read array\n", j);
7728 /* skip header and ignore checksum */
7732 ql_dbg(ql_dbg_init, vha, 0x0163,
7733 "-> fwdt%u template allocate template %#x words...\n",
7735 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7736 if (!fwdt->template) {
7737 ql_log(ql_log_warn, vha, 0x0164,
7738 "-> fwdt%u failed allocate template.\n", j);
7742 dcode = fwdt->template;
7743 qla24xx_read_flash_data(vha, dcode, faddr, risc_size);
7745 if (!qla27xx_fwdt_template_valid(dcode)) {
7746 ql_log(ql_log_warn, vha, 0x0165,
7747 "-> fwdt%u failed template validate\n", j);
7751 dlen = qla27xx_fwdt_template_size(dcode);
7752 ql_dbg(ql_dbg_init, vha, 0x0166,
7753 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
7754 j, dlen, dlen / sizeof(*dcode));
7755 if (dlen > risc_size * sizeof(*dcode)) {
7756 ql_log(ql_log_warn, vha, 0x0167,
7757 "-> fwdt%u template exceeds array (%-lu bytes)\n",
7758 j, dlen - risc_size * sizeof(*dcode));
7762 fwdt->length = dlen;
7763 ql_dbg(ql_dbg_init, vha, 0x0168,
7764 "-> fwdt%u loaded template ok\n", j);
7766 faddr += risc_size + 1;
7773 vfree(fwdt->template);
7774 fwdt->template = NULL;
7780 #define QLA_FW_URL "http://ldriver.qlogic.com/firmware/"
7783 qla2x00_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7787 uint16_t *wcode, *fwcode;
7788 uint32_t risc_addr, risc_size, fwclen, wlen, *seg;
7789 struct fw_blob *blob;
7790 struct qla_hw_data *ha = vha->hw;
7791 struct req_que *req = ha->req_q_map[0];
7793 /* Load firmware blob. */
7794 blob = qla2x00_request_firmware(vha);
7796 ql_log(ql_log_info, vha, 0x0083,
7797 "Firmware image unavailable.\n");
7798 ql_log(ql_log_info, vha, 0x0084,
7799 "Firmware images can be retrieved from: "QLA_FW_URL ".\n");
7800 return QLA_FUNCTION_FAILED;
7805 wcode = (uint16_t *)req->ring;
7807 fwcode = (uint16_t *)blob->fw->data;
7810 /* Validate firmware image by checking version. */
7811 if (blob->fw->size < 8 * sizeof(uint16_t)) {
7812 ql_log(ql_log_fatal, vha, 0x0085,
7813 "Unable to verify integrity of firmware image (%zd).\n",
7815 goto fail_fw_integrity;
7817 for (i = 0; i < 4; i++)
7818 wcode[i] = be16_to_cpu(fwcode[i + 4]);
7819 if ((wcode[0] == 0xffff && wcode[1] == 0xffff && wcode[2] == 0xffff &&
7820 wcode[3] == 0xffff) || (wcode[0] == 0 && wcode[1] == 0 &&
7821 wcode[2] == 0 && wcode[3] == 0)) {
7822 ql_log(ql_log_fatal, vha, 0x0086,
7823 "Unable to verify integrity of firmware image.\n");
7824 ql_log(ql_log_fatal, vha, 0x0087,
7825 "Firmware data: %04x %04x %04x %04x.\n",
7826 wcode[0], wcode[1], wcode[2], wcode[3]);
7827 goto fail_fw_integrity;
7831 while (*seg && rval == QLA_SUCCESS) {
7833 *srisc_addr = *srisc_addr == 0 ? *seg : *srisc_addr;
7834 risc_size = be16_to_cpu(fwcode[3]);
7836 /* Validate firmware image size. */
7837 fwclen += risc_size * sizeof(uint16_t);
7838 if (blob->fw->size < fwclen) {
7839 ql_log(ql_log_fatal, vha, 0x0088,
7840 "Unable to verify integrity of firmware image "
7841 "(%zd).\n", blob->fw->size);
7842 goto fail_fw_integrity;
7846 while (risc_size > 0 && rval == QLA_SUCCESS) {
7847 wlen = (uint16_t)(ha->fw_transfer_size >> 1);
7848 if (wlen > risc_size)
7850 ql_dbg(ql_dbg_init, vha, 0x0089,
7851 "Loading risc segment@ risc addr %x number of "
7852 "words 0x%x.\n", risc_addr, wlen);
7854 for (i = 0; i < wlen; i++)
7855 wcode[i] = swab16(fwcode[i]);
7857 rval = qla2x00_load_ram(vha, req->dma, risc_addr,
7860 ql_log(ql_log_fatal, vha, 0x008a,
7861 "Failed to load segment %d of firmware.\n",
7878 return QLA_FUNCTION_FAILED;
7882 qla24xx_load_risc_blob(scsi_qla_host_t *vha, uint32_t *srisc_addr)
7885 uint templates, segments, fragment;
7888 uint32_t risc_addr, risc_size, risc_attr = 0;
7891 struct fw_blob *blob;
7893 struct qla_hw_data *ha = vha->hw;
7894 struct req_que *req = ha->req_q_map[0];
7895 struct fwdt *fwdt = ha->fwdt;
7897 ql_dbg(ql_dbg_init, vha, 0x0090,
7898 "-> FW: Loading via request-firmware.\n");
7900 blob = qla2x00_request_firmware(vha);
7902 ql_log(ql_log_warn, vha, 0x0092,
7903 "-> Firmware file not found.\n");
7905 return QLA_FUNCTION_FAILED;
7908 fwcode = (void *)blob->fw->data;
7910 if (qla24xx_risc_firmware_invalid(dcode)) {
7911 ql_log(ql_log_fatal, vha, 0x0093,
7912 "Unable to verify integrity of firmware image (%zd).\n",
7914 ql_log(ql_log_fatal, vha, 0x0095,
7915 "Firmware data: %08x %08x %08x %08x.\n",
7916 dcode[0], dcode[1], dcode[2], dcode[3]);
7917 return QLA_FUNCTION_FAILED;
7920 dcode = (void *)req->ring;
7922 segments = FA_RISC_CODE_SEGMENTS;
7923 for (j = 0; j < segments; j++) {
7924 ql_dbg(ql_dbg_init, vha, 0x0096,
7925 "-> Loading segment %u...\n", j);
7926 risc_addr = be32_to_cpu(fwcode[2]);
7927 risc_size = be32_to_cpu(fwcode[3]);
7930 *srisc_addr = risc_addr;
7931 risc_attr = be32_to_cpu(fwcode[9]);
7934 dlen = ha->fw_transfer_size >> 2;
7935 for (fragment = 0; risc_size; fragment++) {
7936 if (dlen > risc_size)
7939 ql_dbg(ql_dbg_init, vha, 0x0097,
7940 "-> Loading fragment %u: %#x <- %#x (%#lx words)...\n",
7941 fragment, risc_addr,
7942 (uint32_t)(fwcode - (typeof(fwcode))blob->fw->data),
7945 for (i = 0; i < dlen; i++)
7946 dcode[i] = swab32(fwcode[i]);
7948 rval = qla2x00_load_ram(vha, req->dma, risc_addr, dlen);
7950 ql_log(ql_log_fatal, vha, 0x0098,
7951 "-> Failed load firmware fragment %u.\n",
7953 return QLA_FUNCTION_FAILED;
7962 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
7965 templates = (risc_attr & BIT_9) ? 2 : 1;
7966 ql_dbg(ql_dbg_init, vha, 0x0170, "-> templates = %u\n", templates);
7967 for (j = 0; j < templates; j++, fwdt++) {
7969 vfree(fwdt->template);
7970 fwdt->template = NULL;
7973 risc_size = be32_to_cpu(fwcode[2]);
7974 ql_dbg(ql_dbg_init, vha, 0x0171,
7975 "-> fwdt%u template array at %#x (%#x dwords)\n",
7976 j, (uint32_t)((void *)fwcode - (void *)blob->fw->data),
7978 if (!risc_size || !~risc_size) {
7979 ql_dbg(ql_dbg_init, vha, 0x0172,
7980 "-> fwdt%u failed to read array\n", j);
7984 /* skip header and ignore checksum */
7988 ql_dbg(ql_dbg_init, vha, 0x0173,
7989 "-> fwdt%u template allocate template %#x words...\n",
7991 fwdt->template = vmalloc(risc_size * sizeof(*dcode));
7992 if (!fwdt->template) {
7993 ql_log(ql_log_warn, vha, 0x0174,
7994 "-> fwdt%u failed allocate template.\n", j);
7998 dcode = fwdt->template;
7999 for (i = 0; i < risc_size; i++)
8000 dcode[i] = fwcode[i];
8002 if (!qla27xx_fwdt_template_valid(dcode)) {
8003 ql_log(ql_log_warn, vha, 0x0175,
8004 "-> fwdt%u failed template validate\n", j);
8008 dlen = qla27xx_fwdt_template_size(dcode);
8009 ql_dbg(ql_dbg_init, vha, 0x0176,
8010 "-> fwdt%u template size %#lx bytes (%#lx words)\n",
8011 j, dlen, dlen / sizeof(*dcode));
8012 if (dlen > risc_size * sizeof(*dcode)) {
8013 ql_log(ql_log_warn, vha, 0x0177,
8014 "-> fwdt%u template exceeds array (%-lu bytes)\n",
8015 j, dlen - risc_size * sizeof(*dcode));
8019 fwdt->length = dlen;
8020 ql_dbg(ql_dbg_init, vha, 0x0178,
8021 "-> fwdt%u loaded template ok\n", j);
8023 fwcode += risc_size + 1;
8030 vfree(fwdt->template);
8031 fwdt->template = NULL;
8038 qla24xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8042 if (ql2xfwloadbin == 1)
8043 return qla81xx_load_risc(vha, srisc_addr);
8047 * 1) Firmware via request-firmware interface (.bin file).
8048 * 2) Firmware residing in flash.
8050 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8051 if (rval == QLA_SUCCESS)
8054 return qla24xx_load_risc_flash(vha, srisc_addr,
8055 vha->hw->flt_region_fw);
8059 qla81xx_load_risc(scsi_qla_host_t *vha, uint32_t *srisc_addr)
8062 struct qla_hw_data *ha = vha->hw;
8063 struct active_regions active_regions = { };
8065 if (ql2xfwloadbin == 2)
8068 /* FW Load priority:
8069 * 1) Firmware residing in flash.
8070 * 2) Firmware via request-firmware interface (.bin file).
8071 * 3) Golden-Firmware residing in flash -- (limited operation).
8074 if (!IS_QLA27XX(ha) && !IS_QLA28XX(ha))
8075 goto try_primary_fw;
8077 qla27xx_get_active_image(vha, &active_regions);
8079 if (active_regions.global != QLA27XX_SECONDARY_IMAGE)
8080 goto try_primary_fw;
8082 ql_dbg(ql_dbg_init, vha, 0x008b,
8083 "Loading secondary firmware image.\n");
8084 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw_sec);
8089 ql_dbg(ql_dbg_init, vha, 0x008b,
8090 "Loading primary firmware image.\n");
8091 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_fw);
8096 rval = qla24xx_load_risc_blob(vha, srisc_addr);
8097 if (!rval || !ha->flt_region_gold_fw)
8100 ql_log(ql_log_info, vha, 0x0099,
8101 "Attempting to fallback to golden firmware.\n");
8102 rval = qla24xx_load_risc_flash(vha, srisc_addr, ha->flt_region_gold_fw);
8106 ql_log(ql_log_info, vha, 0x009a, "Need firmware flash update.\n");
8107 ha->flags.running_gold_fw = 1;
8112 qla2x00_try_to_stop_firmware(scsi_qla_host_t *vha)
8115 struct qla_hw_data *ha = vha->hw;
8117 if (ha->flags.pci_channel_io_perm_failure)
8119 if (!IS_FWI2_CAPABLE(ha))
8121 if (!ha->fw_major_version)
8123 if (!ha->flags.fw_started)
8126 ret = qla2x00_stop_firmware(vha);
8127 for (retries = 5; ret != QLA_SUCCESS && ret != QLA_FUNCTION_TIMEOUT &&
8128 ret != QLA_INVALID_COMMAND && retries ; retries--) {
8129 ha->isp_ops->reset_chip(vha);
8130 if (ha->isp_ops->chip_diag(vha) != QLA_SUCCESS)
8132 if (qla2x00_setup_chip(vha) != QLA_SUCCESS)
8134 ql_log(ql_log_info, vha, 0x8015,
8135 "Attempting retry of stop-firmware command.\n");
8136 ret = qla2x00_stop_firmware(vha);
8140 ha->flags.fw_init_done = 0;
8144 qla24xx_configure_vhba(scsi_qla_host_t *vha)
8146 int rval = QLA_SUCCESS;
8148 uint16_t mb[MAILBOX_REGISTER_COUNT];
8149 struct qla_hw_data *ha = vha->hw;
8150 struct scsi_qla_host *base_vha = pci_get_drvdata(ha->pdev);
8155 rval = qla2x00_fw_ready(base_vha);
8157 if (rval == QLA_SUCCESS) {
8158 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8159 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8162 vha->flags.management_server_logged_in = 0;
8164 /* Login to SNS first */
8165 rval2 = ha->isp_ops->fabric_login(vha, NPH_SNS, 0xff, 0xff, 0xfc, mb,
8167 if (rval2 != QLA_SUCCESS || mb[0] != MBS_COMMAND_COMPLETE) {
8168 if (rval2 == QLA_MEMORY_ALLOC_FAILED)
8169 ql_dbg(ql_dbg_init, vha, 0x0120,
8170 "Failed SNS login: loop_id=%x, rval2=%d\n",
8173 ql_dbg(ql_dbg_init, vha, 0x0103,
8174 "Failed SNS login: loop_id=%x mb[0]=%x mb[1]=%x "
8175 "mb[2]=%x mb[6]=%x mb[7]=%x.\n",
8176 NPH_SNS, mb[0], mb[1], mb[2], mb[6], mb[7]);
8177 return (QLA_FUNCTION_FAILED);
8180 atomic_set(&vha->loop_down_timer, 0);
8181 atomic_set(&vha->loop_state, LOOP_UP);
8182 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8183 set_bit(LOCAL_LOOP_UPDATE, &vha->dpc_flags);
8184 rval = qla2x00_loop_resync(base_vha);
8189 /* 84XX Support **************************************************************/
8191 static LIST_HEAD(qla_cs84xx_list);
8192 static DEFINE_MUTEX(qla_cs84xx_mutex);
8194 static struct qla_chip_state_84xx *
8195 qla84xx_get_chip(struct scsi_qla_host *vha)
8197 struct qla_chip_state_84xx *cs84xx;
8198 struct qla_hw_data *ha = vha->hw;
8200 mutex_lock(&qla_cs84xx_mutex);
8202 /* Find any shared 84xx chip. */
8203 list_for_each_entry(cs84xx, &qla_cs84xx_list, list) {
8204 if (cs84xx->bus == ha->pdev->bus) {
8205 kref_get(&cs84xx->kref);
8210 cs84xx = kzalloc(sizeof(*cs84xx), GFP_KERNEL);
8214 kref_init(&cs84xx->kref);
8215 spin_lock_init(&cs84xx->access_lock);
8216 mutex_init(&cs84xx->fw_update_mutex);
8217 cs84xx->bus = ha->pdev->bus;
8219 list_add_tail(&cs84xx->list, &qla_cs84xx_list);
8221 mutex_unlock(&qla_cs84xx_mutex);
8226 __qla84xx_chip_release(struct kref *kref)
8228 struct qla_chip_state_84xx *cs84xx =
8229 container_of(kref, struct qla_chip_state_84xx, kref);
8231 mutex_lock(&qla_cs84xx_mutex);
8232 list_del(&cs84xx->list);
8233 mutex_unlock(&qla_cs84xx_mutex);
8238 qla84xx_put_chip(struct scsi_qla_host *vha)
8240 struct qla_hw_data *ha = vha->hw;
8243 kref_put(&ha->cs84xx->kref, __qla84xx_chip_release);
8247 qla84xx_init_chip(scsi_qla_host_t *vha)
8251 struct qla_hw_data *ha = vha->hw;
8253 mutex_lock(&ha->cs84xx->fw_update_mutex);
8255 rval = qla84xx_verify_chip(vha, status);
8257 mutex_unlock(&ha->cs84xx->fw_update_mutex);
8259 return rval != QLA_SUCCESS || status[0] ? QLA_FUNCTION_FAILED :
8263 /* 81XX Support **************************************************************/
8266 qla81xx_nvram_config(scsi_qla_host_t *vha)
8269 struct init_cb_81xx *icb;
8270 struct nvram_81xx *nv;
8272 uint8_t *dptr1, *dptr2;
8275 struct qla_hw_data *ha = vha->hw;
8277 struct active_regions active_regions = { };
8280 icb = (struct init_cb_81xx *)ha->init_cb;
8283 /* Determine NVRAM starting address. */
8284 ha->nvram_size = sizeof(*nv);
8285 ha->vpd_size = FA_NVRAM_VPD_SIZE;
8286 if (IS_P3P_TYPE(ha) || IS_QLA8031(ha))
8287 ha->vpd_size = FA_VPD_SIZE_82XX;
8289 if (IS_QLA28XX(ha) || IS_QLA27XX(ha))
8290 qla28xx_get_aux_images(vha, &active_regions);
8292 /* Get VPD data into cache */
8293 ha->vpd = ha->nvram + VPD_OFFSET;
8295 faddr = ha->flt_region_vpd;
8296 if (IS_QLA28XX(ha)) {
8297 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8298 faddr = ha->flt_region_vpd_sec;
8299 ql_dbg(ql_dbg_init, vha, 0x0110,
8300 "Loading %s nvram image.\n",
8301 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8302 "primary" : "secondary");
8304 qla24xx_read_flash_data(vha, ha->vpd, faddr, ha->vpd_size >> 2);
8306 /* Get NVRAM data into cache and calculate checksum. */
8307 faddr = ha->flt_region_nvram;
8308 if (IS_QLA28XX(ha)) {
8309 if (active_regions.aux.vpd_nvram == QLA27XX_SECONDARY_IMAGE)
8310 faddr = ha->flt_region_nvram_sec;
8312 ql_dbg(ql_dbg_init, vha, 0x0110,
8313 "Loading %s nvram image.\n",
8314 active_regions.aux.vpd_nvram == QLA27XX_PRIMARY_IMAGE ?
8315 "primary" : "secondary");
8316 qla24xx_read_flash_data(vha, ha->nvram, faddr, ha->nvram_size >> 2);
8318 dptr = (uint32_t *)nv;
8319 for (cnt = 0, chksum = 0; cnt < ha->nvram_size >> 2; cnt++, dptr++)
8320 chksum += le32_to_cpu(*dptr);
8322 ql_dbg(ql_dbg_init + ql_dbg_buffer, vha, 0x0111,
8323 "Contents of NVRAM:\n");
8324 ql_dump_buffer(ql_dbg_init + ql_dbg_buffer, vha, 0x0112,
8325 nv, ha->nvram_size);
8327 /* Bad NVRAM data, set defaults parameters. */
8328 if (chksum || memcmp("ISP ", nv->id, sizeof(nv->id)) ||
8329 le16_to_cpu(nv->nvram_version) < ICB_VERSION) {
8330 /* Reset NVRAM data. */
8331 ql_log(ql_log_info, vha, 0x0073,
8332 "Inconsistent NVRAM checksum=%#x id=%.4s version=%#x.\n",
8333 chksum, nv->id, le16_to_cpu(nv->nvram_version));
8334 ql_dump_buffer(ql_dbg_init, vha, 0x0073, nv, sizeof(*nv));
8335 ql_log(ql_log_info, vha, 0x0074,
8336 "Falling back to functioning (yet invalid -- WWPN) "
8340 * Set default initialization control block.
8342 memset(nv, 0, ha->nvram_size);
8343 nv->nvram_version = cpu_to_le16(ICB_VERSION);
8344 nv->version = cpu_to_le16(ICB_VERSION);
8345 nv->frame_payload_size = 2048;
8346 nv->execution_throttle = cpu_to_le16(0xFFFF);
8347 nv->exchange_count = cpu_to_le16(0);
8348 nv->port_name[0] = 0x21;
8349 nv->port_name[1] = 0x00 + ha->port_no + 1;
8350 nv->port_name[2] = 0x00;
8351 nv->port_name[3] = 0xe0;
8352 nv->port_name[4] = 0x8b;
8353 nv->port_name[5] = 0x1c;
8354 nv->port_name[6] = 0x55;
8355 nv->port_name[7] = 0x86;
8356 nv->node_name[0] = 0x20;
8357 nv->node_name[1] = 0x00;
8358 nv->node_name[2] = 0x00;
8359 nv->node_name[3] = 0xe0;
8360 nv->node_name[4] = 0x8b;
8361 nv->node_name[5] = 0x1c;
8362 nv->node_name[6] = 0x55;
8363 nv->node_name[7] = 0x86;
8364 nv->login_retry_count = cpu_to_le16(8);
8365 nv->interrupt_delay_timer = cpu_to_le16(0);
8366 nv->login_timeout = cpu_to_le16(0);
8367 nv->firmware_options_1 =
8368 cpu_to_le32(BIT_14|BIT_13|BIT_2|BIT_1);
8369 nv->firmware_options_2 = cpu_to_le32(2 << 4);
8370 nv->firmware_options_2 |= cpu_to_le32(BIT_12);
8371 nv->firmware_options_3 = cpu_to_le32(2 << 13);
8372 nv->host_p = cpu_to_le32(BIT_11|BIT_10);
8373 nv->efi_parameters = cpu_to_le32(0);
8374 nv->reset_delay = 5;
8375 nv->max_luns_per_target = cpu_to_le16(128);
8376 nv->port_down_retry_count = cpu_to_le16(30);
8377 nv->link_down_timeout = cpu_to_le16(180);
8378 nv->enode_mac[0] = 0x00;
8379 nv->enode_mac[1] = 0xC0;
8380 nv->enode_mac[2] = 0xDD;
8381 nv->enode_mac[3] = 0x04;
8382 nv->enode_mac[4] = 0x05;
8383 nv->enode_mac[5] = 0x06 + ha->port_no + 1;
8388 if (IS_T10_PI_CAPABLE(ha))
8389 nv->frame_payload_size &= ~7;
8391 qlt_81xx_config_nvram_stage1(vha, nv);
8393 /* Reset Initialization control block */
8394 memset(icb, 0, ha->init_cb_size);
8396 /* Copy 1st segment. */
8397 dptr1 = (uint8_t *)icb;
8398 dptr2 = (uint8_t *)&nv->version;
8399 cnt = (uint8_t *)&icb->response_q_inpointer - (uint8_t *)&icb->version;
8401 *dptr1++ = *dptr2++;
8403 icb->login_retry_count = nv->login_retry_count;
8405 /* Copy 2nd segment. */
8406 dptr1 = (uint8_t *)&icb->interrupt_delay_timer;
8407 dptr2 = (uint8_t *)&nv->interrupt_delay_timer;
8408 cnt = (uint8_t *)&icb->reserved_5 -
8409 (uint8_t *)&icb->interrupt_delay_timer;
8411 *dptr1++ = *dptr2++;
8413 memcpy(icb->enode_mac, nv->enode_mac, sizeof(icb->enode_mac));
8414 /* Some boards (with valid NVRAMs) still have NULL enode_mac!! */
8415 if (!memcmp(icb->enode_mac, "\0\0\0\0\0\0", sizeof(icb->enode_mac))) {
8416 icb->enode_mac[0] = 0x00;
8417 icb->enode_mac[1] = 0xC0;
8418 icb->enode_mac[2] = 0xDD;
8419 icb->enode_mac[3] = 0x04;
8420 icb->enode_mac[4] = 0x05;
8421 icb->enode_mac[5] = 0x06 + ha->port_no + 1;
8424 /* Use extended-initialization control block. */
8425 memcpy(ha->ex_init_cb, &nv->ex_version, sizeof(*ha->ex_init_cb));
8426 ha->frame_payload_size = le16_to_cpu(icb->frame_payload_size);
8428 * Setup driver NVRAM options.
8430 qla2x00_set_model_info(vha, nv->model_name, sizeof(nv->model_name),
8433 qlt_81xx_config_nvram_stage2(vha, icb);
8435 /* Use alternate WWN? */
8436 if (nv->host_p & cpu_to_le32(BIT_15)) {
8437 memcpy(icb->node_name, nv->alternate_node_name, WWN_SIZE);
8438 memcpy(icb->port_name, nv->alternate_port_name, WWN_SIZE);
8441 /* Prepare nodename */
8442 if ((icb->firmware_options_1 & cpu_to_le32(BIT_14)) == 0) {
8444 * Firmware will apply the following mask if the nodename was
8447 memcpy(icb->node_name, icb->port_name, WWN_SIZE);
8448 icb->node_name[0] &= 0xF0;
8451 /* Set host adapter parameters. */
8452 ha->flags.disable_risc_code_load = 0;
8453 ha->flags.enable_lip_reset = 0;
8454 ha->flags.enable_lip_full_login =
8455 le32_to_cpu(nv->host_p) & BIT_10 ? 1 : 0;
8456 ha->flags.enable_target_reset =
8457 le32_to_cpu(nv->host_p) & BIT_11 ? 1 : 0;
8458 ha->flags.enable_led_scheme = 0;
8459 ha->flags.disable_serdes = le32_to_cpu(nv->host_p) & BIT_5 ? 1 : 0;
8461 ha->operating_mode = (le32_to_cpu(icb->firmware_options_2) &
8462 (BIT_6 | BIT_5 | BIT_4)) >> 4;
8464 /* save HBA serial number */
8465 ha->serial0 = icb->port_name[5];
8466 ha->serial1 = icb->port_name[6];
8467 ha->serial2 = icb->port_name[7];
8468 memcpy(vha->node_name, icb->node_name, WWN_SIZE);
8469 memcpy(vha->port_name, icb->port_name, WWN_SIZE);
8471 icb->execution_throttle = cpu_to_le16(0xFFFF);
8473 ha->retry_count = le16_to_cpu(nv->login_retry_count);
8475 /* Set minimum login_timeout to 4 seconds. */
8476 if (le16_to_cpu(nv->login_timeout) < ql2xlogintimeout)
8477 nv->login_timeout = cpu_to_le16(ql2xlogintimeout);
8478 if (le16_to_cpu(nv->login_timeout) < 4)
8479 nv->login_timeout = cpu_to_le16(4);
8480 ha->login_timeout = le16_to_cpu(nv->login_timeout);
8482 /* Set minimum RATOV to 100 tenths of a second. */
8485 ha->loop_reset_delay = nv->reset_delay;
8487 /* Link Down Timeout = 0:
8489 * When Port Down timer expires we will start returning
8490 * I/O's to OS with "DID_NO_CONNECT".
8492 * Link Down Timeout != 0:
8494 * The driver waits for the link to come up after link down
8495 * before returning I/Os to OS with "DID_NO_CONNECT".
8497 if (le16_to_cpu(nv->link_down_timeout) == 0) {
8498 ha->loop_down_abort_time =
8499 (LOOP_DOWN_TIME - LOOP_DOWN_TIMEOUT);
8501 ha->link_down_timeout = le16_to_cpu(nv->link_down_timeout);
8502 ha->loop_down_abort_time =
8503 (LOOP_DOWN_TIME - ha->link_down_timeout);
8506 /* Need enough time to try and get the port back. */
8507 ha->port_down_retry_count = le16_to_cpu(nv->port_down_retry_count);
8508 if (qlport_down_retry)
8509 ha->port_down_retry_count = qlport_down_retry;
8511 /* Set login_retry_count */
8512 ha->login_retry_count = le16_to_cpu(nv->login_retry_count);
8513 if (ha->port_down_retry_count ==
8514 le16_to_cpu(nv->port_down_retry_count) &&
8515 ha->port_down_retry_count > 3)
8516 ha->login_retry_count = ha->port_down_retry_count;
8517 else if (ha->port_down_retry_count > (int)ha->login_retry_count)
8518 ha->login_retry_count = ha->port_down_retry_count;
8519 if (ql2xloginretrycount)
8520 ha->login_retry_count = ql2xloginretrycount;
8522 /* if not running MSI-X we need handshaking on interrupts */
8523 if (!vha->hw->flags.msix_enabled &&
8524 (IS_QLA83XX(ha) || IS_QLA27XX(ha) || IS_QLA28XX(ha)))
8525 icb->firmware_options_2 |= cpu_to_le32(BIT_22);
8528 if (!vha->flags.init_done) {
8529 ha->zio_mode = le32_to_cpu(icb->firmware_options_2) &
8530 (BIT_3 | BIT_2 | BIT_1 | BIT_0);
8531 ha->zio_timer = le16_to_cpu(icb->interrupt_delay_timer) ?
8532 le16_to_cpu(icb->interrupt_delay_timer) : 2;
8534 icb->firmware_options_2 &= cpu_to_le32(
8535 ~(BIT_3 | BIT_2 | BIT_1 | BIT_0));
8536 vha->flags.process_response_queue = 0;
8537 if (ha->zio_mode != QLA_ZIO_DISABLED) {
8538 ha->zio_mode = QLA_ZIO_MODE_6;
8540 ql_log(ql_log_info, vha, 0x0075,
8541 "ZIO mode %d enabled; timer delay (%d us).\n",
8543 ha->zio_timer * 100);
8545 icb->firmware_options_2 |= cpu_to_le32(
8546 (uint32_t)ha->zio_mode);
8547 icb->interrupt_delay_timer = cpu_to_le16(ha->zio_timer);
8548 vha->flags.process_response_queue = 1;
8551 /* enable RIDA Format2 */
8552 icb->firmware_options_3 |= BIT_0;
8554 /* N2N: driver will initiate Login instead of FW */
8555 icb->firmware_options_3 |= BIT_8;
8558 ql_log(ql_log_warn, vha, 0x0076,
8559 "NVRAM configuration failed.\n");
8565 qla82xx_restart_isp(scsi_qla_host_t *vha)
8568 struct qla_hw_data *ha = vha->hw;
8569 struct scsi_qla_host *vp;
8570 unsigned long flags;
8572 status = qla2x00_init_rings(vha);
8574 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8575 ha->flags.chip_reset_done = 1;
8577 status = qla2x00_fw_ready(vha);
8579 /* Issue a marker after FW becomes ready. */
8580 qla2x00_marker(vha, ha->base_qpair, 0, 0, MK_SYNC_ALL);
8581 vha->flags.online = 1;
8582 set_bit(LOOP_RESYNC_NEEDED, &vha->dpc_flags);
8585 /* if no cable then assume it's good */
8586 if ((vha->device_flags & DFLG_NO_CABLE))
8591 clear_bit(RESET_MARKER_NEEDED, &vha->dpc_flags);
8593 if (!atomic_read(&vha->loop_down_timer)) {
8595 * Issue marker command only when we are going
8596 * to start the I/O .
8598 vha->marker_needed = 1;
8601 ha->isp_ops->enable_intrs(ha);
8603 ha->isp_abort_cnt = 0;
8604 clear_bit(ISP_ABORT_RETRY, &vha->dpc_flags);
8606 /* Update the firmware version */
8607 status = qla82xx_check_md_needed(vha);
8610 ha->flags.fce_enabled = 1;
8612 fce_calc_size(ha->fce_bufs));
8613 rval = qla2x00_enable_fce_trace(vha,
8614 ha->fce_dma, ha->fce_bufs, ha->fce_mb,
8617 ql_log(ql_log_warn, vha, 0x8001,
8618 "Unable to reinitialize FCE (%d).\n",
8620 ha->flags.fce_enabled = 0;
8625 memset(ha->eft, 0, EFT_SIZE);
8626 rval = qla2x00_enable_eft_trace(vha,
8627 ha->eft_dma, EFT_NUM_BUFFERS);
8629 ql_log(ql_log_warn, vha, 0x8010,
8630 "Unable to reinitialize EFT (%d).\n",
8637 ql_dbg(ql_dbg_taskm, vha, 0x8011,
8638 "qla82xx_restart_isp succeeded.\n");
8640 spin_lock_irqsave(&ha->vport_slock, flags);
8641 list_for_each_entry(vp, &ha->vp_list, list) {
8643 atomic_inc(&vp->vref_count);
8644 spin_unlock_irqrestore(&ha->vport_slock, flags);
8646 qla2x00_vp_abort_isp(vp);
8648 spin_lock_irqsave(&ha->vport_slock, flags);
8649 atomic_dec(&vp->vref_count);
8652 spin_unlock_irqrestore(&ha->vport_slock, flags);
8655 ql_log(ql_log_warn, vha, 0x8016,
8656 "qla82xx_restart_isp **** FAILED ****.\n");
8663 qla81xx_update_fw_options(scsi_qla_host_t *vha)
8665 struct qla_hw_data *ha = vha->hw;
8667 /* Hold status IOCBs until ABTS response received. */
8669 ha->fw_options[3] |= BIT_12;
8671 /* Set Retry FLOGI in case of P2P connection */
8672 if (ha->operating_mode == P2P) {
8673 ha->fw_options[2] |= BIT_3;
8674 ql_dbg(ql_dbg_disc, vha, 0x2103,
8675 "(%s): Setting FLOGI retry BIT in fw_options[2]: 0x%x\n",
8676 __func__, ha->fw_options[2]);
8679 /* Move PUREX, ABTS RX & RIDA to ATIOQ */
8680 if (ql2xmvasynctoatio) {
8681 if (qla_tgt_mode_enabled(vha) ||
8682 qla_dual_mode_enabled(vha))
8683 ha->fw_options[2] |= BIT_11;
8685 ha->fw_options[2] &= ~BIT_11;
8688 if (qla_tgt_mode_enabled(vha) ||
8689 qla_dual_mode_enabled(vha)) {
8690 /* FW auto send SCSI status during */
8691 ha->fw_options[1] |= BIT_8;
8692 ha->fw_options[10] |= (u16)SAM_STAT_BUSY << 8;
8694 /* FW perform Exchange validation */
8695 ha->fw_options[2] |= BIT_4;
8697 ha->fw_options[1] &= ~BIT_8;
8698 ha->fw_options[10] &= 0x00ff;
8700 ha->fw_options[2] &= ~BIT_4;
8703 if (ql2xetsenable) {
8704 /* Enable ETS Burst. */
8705 memset(ha->fw_options, 0, sizeof(ha->fw_options));
8706 ha->fw_options[2] |= BIT_9;
8709 ql_dbg(ql_dbg_init, vha, 0x00e9,
8710 "%s, add FW options 1-3 = 0x%04x 0x%04x 0x%04x mode %x\n",
8711 __func__, ha->fw_options[1], ha->fw_options[2],
8712 ha->fw_options[3], vha->host->active_mode);
8714 qla2x00_set_fw_options(vha, ha->fw_options);
8718 * qla24xx_get_fcp_prio
8719 * Gets the fcp cmd priority value for the logged in port.
8720 * Looks for a match of the port descriptors within
8721 * each of the fcp prio config entries. If a match is found,
8722 * the tag (priority) value is returned.
8725 * vha = scsi host structure pointer.
8726 * fcport = port structure pointer.
8729 * non-zero (if found)
8736 qla24xx_get_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8739 uint8_t pid_match, wwn_match;
8741 uint32_t pid1, pid2;
8742 uint64_t wwn1, wwn2;
8743 struct qla_fcp_prio_entry *pri_entry;
8744 struct qla_hw_data *ha = vha->hw;
8746 if (!ha->fcp_prio_cfg || !ha->flags.fcp_prio_enabled)
8750 entries = ha->fcp_prio_cfg->num_entries;
8751 pri_entry = &ha->fcp_prio_cfg->entry[0];
8753 for (i = 0; i < entries; i++) {
8754 pid_match = wwn_match = 0;
8756 if (!(pri_entry->flags & FCP_PRIO_ENTRY_VALID)) {
8761 /* check source pid for a match */
8762 if (pri_entry->flags & FCP_PRIO_ENTRY_SPID_VALID) {
8763 pid1 = pri_entry->src_pid & INVALID_PORT_ID;
8764 pid2 = vha->d_id.b24 & INVALID_PORT_ID;
8765 if (pid1 == INVALID_PORT_ID)
8767 else if (pid1 == pid2)
8771 /* check destination pid for a match */
8772 if (pri_entry->flags & FCP_PRIO_ENTRY_DPID_VALID) {
8773 pid1 = pri_entry->dst_pid & INVALID_PORT_ID;
8774 pid2 = fcport->d_id.b24 & INVALID_PORT_ID;
8775 if (pid1 == INVALID_PORT_ID)
8777 else if (pid1 == pid2)
8781 /* check source WWN for a match */
8782 if (pri_entry->flags & FCP_PRIO_ENTRY_SWWN_VALID) {
8783 wwn1 = wwn_to_u64(vha->port_name);
8784 wwn2 = wwn_to_u64(pri_entry->src_wwpn);
8785 if (wwn2 == (uint64_t)-1)
8787 else if (wwn1 == wwn2)
8791 /* check destination WWN for a match */
8792 if (pri_entry->flags & FCP_PRIO_ENTRY_DWWN_VALID) {
8793 wwn1 = wwn_to_u64(fcport->port_name);
8794 wwn2 = wwn_to_u64(pri_entry->dst_wwpn);
8795 if (wwn2 == (uint64_t)-1)
8797 else if (wwn1 == wwn2)
8801 if (pid_match == 2 || wwn_match == 2) {
8802 /* Found a matching entry */
8803 if (pri_entry->flags & FCP_PRIO_ENTRY_TAG_VALID)
8804 priority = pri_entry->tag;
8815 * qla24xx_update_fcport_fcp_prio
8816 * Activates fcp priority for the logged in fc port
8819 * vha = scsi host structure pointer.
8820 * fcp = port structure pointer.
8823 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8829 qla24xx_update_fcport_fcp_prio(scsi_qla_host_t *vha, fc_port_t *fcport)
8835 if (fcport->port_type != FCT_TARGET ||
8836 fcport->loop_id == FC_NO_LOOP_ID)
8837 return QLA_FUNCTION_FAILED;
8839 priority = qla24xx_get_fcp_prio(vha, fcport);
8841 return QLA_FUNCTION_FAILED;
8843 if (IS_P3P_TYPE(vha->hw)) {
8844 fcport->fcp_prio = priority & 0xf;
8848 ret = qla24xx_set_fcp_prio(vha, fcport->loop_id, priority, mb);
8849 if (ret == QLA_SUCCESS) {
8850 if (fcport->fcp_prio != priority)
8851 ql_dbg(ql_dbg_user, vha, 0x709e,
8852 "Updated FCP_CMND priority - value=%d loop_id=%d "
8853 "port_id=%02x%02x%02x.\n", priority,
8854 fcport->loop_id, fcport->d_id.b.domain,
8855 fcport->d_id.b.area, fcport->d_id.b.al_pa);
8856 fcport->fcp_prio = priority & 0xf;
8858 ql_dbg(ql_dbg_user, vha, 0x704f,
8859 "Unable to update FCP_CMND priority - ret=0x%x for "
8860 "loop_id=%d port_id=%02x%02x%02x.\n", ret, fcport->loop_id,
8861 fcport->d_id.b.domain, fcport->d_id.b.area,
8862 fcport->d_id.b.al_pa);
8867 * qla24xx_update_all_fcp_prio
8868 * Activates fcp priority for all the logged in ports
8871 * ha = adapter block pointer.
8874 * QLA_SUCCESS or QLA_FUNCTION_FAILED
8880 qla24xx_update_all_fcp_prio(scsi_qla_host_t *vha)
8885 ret = QLA_FUNCTION_FAILED;
8886 /* We need to set priority for all logged in ports */
8887 list_for_each_entry(fcport, &vha->vp_fcports, list)
8888 ret = qla24xx_update_fcport_fcp_prio(vha, fcport);
8893 struct qla_qpair *qla2xxx_create_qpair(struct scsi_qla_host *vha, int qos,
8894 int vp_idx, bool startqp)
8899 struct qla_hw_data *ha = vha->hw;
8900 uint16_t qpair_id = 0;
8901 struct qla_qpair *qpair = NULL;
8902 struct qla_msix_entry *msix;
8904 if (!(ha->fw_attributes & BIT_6) || !ha->flags.msix_enabled) {
8905 ql_log(ql_log_warn, vha, 0x00181,
8906 "FW/Driver is not multi-queue capable.\n");
8910 if (ql2xmqsupport || ql2xnvmeenable) {
8911 qpair = kzalloc(sizeof(struct qla_qpair), GFP_KERNEL);
8912 if (qpair == NULL) {
8913 ql_log(ql_log_warn, vha, 0x0182,
8914 "Failed to allocate memory for queue pair.\n");
8918 qpair->hw = vha->hw;
8920 qpair->qp_lock_ptr = &qpair->qp_lock;
8921 spin_lock_init(&qpair->qp_lock);
8922 qpair->use_shadow_reg = IS_SHADOW_REG_CAPABLE(ha) ? 1 : 0;
8924 /* Assign available que pair id */
8925 mutex_lock(&ha->mq_lock);
8926 qpair_id = find_first_zero_bit(ha->qpair_qid_map, ha->max_qpairs);
8927 if (ha->num_qpairs >= ha->max_qpairs) {
8928 mutex_unlock(&ha->mq_lock);
8929 ql_log(ql_log_warn, vha, 0x0183,
8930 "No resources to create additional q pair.\n");
8934 set_bit(qpair_id, ha->qpair_qid_map);
8935 ha->queue_pair_map[qpair_id] = qpair;
8936 qpair->id = qpair_id;
8937 qpair->vp_idx = vp_idx;
8938 qpair->fw_started = ha->flags.fw_started;
8939 INIT_LIST_HEAD(&qpair->hints_list);
8940 qpair->chip_reset = ha->base_qpair->chip_reset;
8941 qpair->enable_class_2 = ha->base_qpair->enable_class_2;
8942 qpair->enable_explicit_conf =
8943 ha->base_qpair->enable_explicit_conf;
8945 for (i = 0; i < ha->msix_count; i++) {
8946 msix = &ha->msix_entries[i];
8950 ql_dbg(ql_dbg_multiq, vha, 0xc00f,
8951 "Vector %x selected for qpair\n", msix->vector);
8955 ql_log(ql_log_warn, vha, 0x0184,
8956 "Out of MSI-X vectors!.\n");
8960 qpair->msix->in_use = 1;
8961 list_add_tail(&qpair->qp_list_elem, &vha->qp_list);
8962 qpair->pdev = ha->pdev;
8963 if (IS_QLA27XX(ha) || IS_QLA83XX(ha) || IS_QLA28XX(ha))
8964 qpair->reqq_start_iocbs = qla_83xx_start_iocbs;
8966 mutex_unlock(&ha->mq_lock);
8968 /* Create response queue first */
8969 rsp_id = qla25xx_create_rsp_que(ha, 0, 0, 0, qpair, startqp);
8971 ql_log(ql_log_warn, vha, 0x0185,
8972 "Failed to create response queue.\n");
8976 qpair->rsp = ha->rsp_q_map[rsp_id];
8978 /* Create request queue */
8979 req_id = qla25xx_create_req_que(ha, 0, vp_idx, 0, rsp_id, qos,
8982 ql_log(ql_log_warn, vha, 0x0186,
8983 "Failed to create request queue.\n");
8987 qpair->req = ha->req_q_map[req_id];
8988 qpair->rsp->req = qpair->req;
8989 qpair->rsp->qpair = qpair;
8990 /* init qpair to this cpu. Will adjust at run time. */
8991 qla_cpu_update(qpair, smp_processor_id());
8993 if (IS_T10_PI_CAPABLE(ha) && ql2xenabledif) {
8994 if (ha->fw_attributes & BIT_4)
8995 qpair->difdix_supported = 1;
8998 qpair->srb_mempool = mempool_create_slab_pool(SRB_MIN_REQ, srb_cachep);
8999 if (!qpair->srb_mempool) {
9000 ql_log(ql_log_warn, vha, 0xd036,
9001 "Failed to create srb mempool for qpair %d\n",
9006 /* Mark as online */
9009 if (!vha->flags.qpairs_available)
9010 vha->flags.qpairs_available = 1;
9012 ql_dbg(ql_dbg_multiq, vha, 0xc00d,
9013 "Request/Response queue pair created, id %d\n",
9015 ql_dbg(ql_dbg_init, vha, 0x0187,
9016 "Request/Response queue pair created, id %d\n",
9023 qla25xx_delete_rsp_que(vha, qpair->rsp);
9025 mutex_lock(&ha->mq_lock);
9026 qpair->msix->in_use = 0;
9027 list_del(&qpair->qp_list_elem);
9028 if (list_empty(&vha->qp_list))
9029 vha->flags.qpairs_available = 0;
9031 ha->queue_pair_map[qpair_id] = NULL;
9032 clear_bit(qpair_id, ha->qpair_qid_map);
9034 mutex_unlock(&ha->mq_lock);
9040 int qla2xxx_delete_qpair(struct scsi_qla_host *vha, struct qla_qpair *qpair)
9042 int ret = QLA_FUNCTION_FAILED;
9043 struct qla_hw_data *ha = qpair->hw;
9045 qpair->delete_in_progress = 1;
9046 while (atomic_read(&qpair->ref_count))
9049 ret = qla25xx_delete_req_que(vha, qpair->req);
9050 if (ret != QLA_SUCCESS)
9053 ret = qla25xx_delete_rsp_que(vha, qpair->rsp);
9054 if (ret != QLA_SUCCESS)
9057 mutex_lock(&ha->mq_lock);
9058 ha->queue_pair_map[qpair->id] = NULL;
9059 clear_bit(qpair->id, ha->qpair_qid_map);
9061 list_del(&qpair->qp_list_elem);
9062 if (list_empty(&vha->qp_list)) {
9063 vha->flags.qpairs_available = 0;
9064 vha->flags.qpairs_req_created = 0;
9065 vha->flags.qpairs_rsp_created = 0;
9067 mempool_destroy(qpair->srb_mempool);
9069 mutex_unlock(&ha->mq_lock);