/* $NetBSD: isp_netbsd.c,v 1.99 2024/02/09 22:08:34 andvar Exp $ */
/*
* Platform (NetBSD) dependent common attachment code for Qlogic adapters.
*/
/*
* Copyright (C) 1997, 1998, 1999 National Aeronautics & Space Administration
* All rights reserved.
*
* Additional Copyright (C) 2000-2007 by Matthew Jacob
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. The name of the author may not be used to endorse or promote products
* derived from this software without specific prior written permission
*
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
/*
* Set a timeout for the watchdogging of a command.
*
* The dimensional analysis is
*
* milliseconds * (seconds/millisecond) * (ticks/second) = ticks
*
* =
*
* (milliseconds / 1000) * hz = ticks
*
*
* For timeouts less than 1 second, we'll get zero. Because of this, and
* because we want to establish *our* timeout to be longer than what the
* firmware might do, we just add 3 seconds at the back end.
*/
#define _XT(xs) ((((xs)->timeout/1000) * hz) + (3 * hz))
static const char *roles[4] = {
"(none)", "Target", "Initiator", "Target/Initiator"
};
static const char prom3[] =
"PortID %#06x Departed from Target %u because of %s";
int isp_change_is_bad = 0; /* "changed" devices are bad */
int isp_quickboot_time = 15; /* don't wait more than N secs for loop up */
static int isp_fabric_hysteresis = 5;
#define isp_change_is_bad 0
/*
* Complete attachment of hardware, include subdevices.
*/
/*
* And attach children (if any).
*/
for (i = 0; i < isp->isp_osinfo.adapter.adapt_nchannels; i++) {
config_found(self, &isp->isp_osinfo.chan[i], scsiprint,
CFARGS_NONE);
}
}
ISP_LOCK(isp);
if (isp->isp_state < ISP_RUNSTATE) {
ISP_DISABLE_INTS(isp);
isp_init(isp);
if (isp->isp_state != ISP_INITSTATE) {
ISP_ENABLE_INTS(isp);
ISP_UNLOCK(isp);
isp_prt(isp, ISP_LOGERR, "isp not at init state");
XS_SETERR(xs, HBA_BOTCH);
scsipi_done(xs);
return;
}
isp->isp_state = ISP_RUNSTATE;
ISP_ENABLE_INTS(isp);
}
chan = XS_CHANNEL(xs);
/*
* Handle the case of a FC card where the FC thread hasn't
* fired up yet and we don't yet have a known loop state.
*/
if (IS_FC(isp) && (FCPARAM(isp, chan)->isp_fwstate != FW_READY ||
FCPARAM(isp, chan)->isp_loopstate != LOOP_READY) &&
isp->isp_osinfo.thread == NULL) {
ombi = isp->isp_osinfo.mbox_sleep_ok != 0;
int delay_time;
if (xs->xs_control & XS_CTL_POLL) {
isp->isp_osinfo.mbox_sleep_ok = 0;
}
/*
* If no other error occurred but we didn't finish
* something bad happened, so abort the command.
*/
if (XS_CMD_DONE_P(xs) == 0) {
if (isp_control(isp, ISPCTL_ABORT_CMD, xs)) {
isp_reinit(isp, 0);
}
if (XS_NOERR(xs)) {
isp_prt(isp, ISP_LOGERR, "polled command timed out");
XS_SETERR(xs, HBA_BOTCH);
}
}
scsipi_done(xs);
}
void
isp_done(XS_T *xs)
{
if (XS_CMD_WDOG_P(xs) == 0) {
struct ispsoftc *isp = XS_ISP(xs);
callout_stop(&xs->xs_callout);
if (XS_CMD_GRACE_P(xs)) {
isp_prt(isp, ISP_LOGDEBUG1,
"finished command on borrowed time");
}
XS_CMD_S_CLEAR(xs);
/*
* Fixup- if we get a QFULL, we need
* to set XS_BUSY as the error.
*/
if (xs->status == SCSI_QUEUE_FULL) {
xs->error = XS_BUSY;
}
if (isp->isp_osinfo.paused) {
int i;
isp->isp_osinfo.paused = 0;
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"THAW QUEUES @ LINE %d", __LINE__);
for (i = 0; i < isp->isp_nchan; i++) {
scsipi_channel_timed_thaw(&isp->isp_osinfo.chan[i]);
}
}
if (xs->error == XS_DRIVER_STUFFUP) {
isp_prt(isp, ISP_LOGERR,
"BOTCHED cmd for %d.%d.%d cmd %#x datalen %ld",
XS_CHANNEL(xs), XS_TGT(xs), XS_LUN(xs),
XS_CDBP(xs)[0], (long) XS_XFRLEN(xs));
}
scsipi_done(xs);
}
}
ISP_ILOCK(isp);
sok = isp->isp_osinfo.mbox_sleep_ok;
isp->isp_osinfo.mbox_sleep_ok = 0;
/*
* We've decided this command is dead. Make sure we're not trying
* to kill a command that's already dead by getting its handle and
* and seeing whether it's still alive.
*/
handle = isp_find_handle(isp, xs);
if (handle) {
uint32_t isr;
uint16_t mbox, sema;
if (XS_CMD_DONE_P(xs)) {
isp_prt(isp, ISP_LOGDEBUG1,
"watchdog found done cmd (handle %#x)", handle);
goto out;
}
if (ISP_READ_ISR(isp, &isr, &sema, &mbox)) {
isp_intr(isp, isr, sema, mbox);
}
if (XS_CMD_DONE_P(xs)) {
isp_prt(isp, ISP_LOGDEBUG1,
"watchdog cleanup for handle %#x", handle);
XS_CMD_C_WDOG(xs);
isp_done(xs);
} else if (XS_CMD_GRACE_P(xs)) {
isp_prt(isp, ISP_LOGDEBUG1,
"watchdog timeout for handle %#x", handle);
/*
* Make sure the command is *really* dead before we
* release the handle (and DMA resources) for reuse.
*/
(void) isp_control(isp, ISPCTL_ABORT_CMD, arg);
/*
* After this point, the command is really dead.
*/
if (XS_XFRLEN(xs)) {
ISP_DMAFREE(isp, xs, handle);
}
isp_destroy_handle(isp, handle);
XS_SETERR(xs, XS_TIMEOUT);
XS_CMD_S_CLEAR(xs);
isp_done(xs);
} else {
void *qe;
isp_marker_t local, *mp = &local;
isp_prt(isp, ISP_LOGDEBUG2,
"possible command timeout on handle %x", handle);
XS_CMD_C_WDOG(xs);
callout_reset(&xs->xs_callout, hz, isp_dog, xs);
qe = isp_getrqentry(isp);
if (qe == NULL)
goto out;
XS_CMD_S_GRACE(xs);
ISP_MEMZERO((void *) mp, sizeof (*mp));
mp->mrk_header.rqs_entry_count = 1;
mp->mrk_header.rqs_entry_type = RQSTYPE_MARKER;
mp->mrk_modifier = SYNC_ALL;
mp->mrk_target = XS_CHANNEL(xs) << 7;
isp_put_marker(isp, mp, qe);
ISP_SYNC_REQUEST(isp);
}
} else {
isp_prt(isp, ISP_LOGDEBUG0, "watchdog with no command");
}
out:
isp->isp_osinfo.mbox_sleep_ok = sok;
ISP_IUNLOCK(isp);
}
/*
* Gone Device Timer Function- when we have decided that a device has gone
* away, we wait a specific period of time prior to telling the OS it has
* gone away.
*
* This timer function fires once a second and then scans the port database
* for devices that are marked dead but still have a virtual target assigned.
* We decrement a counter for that port database entry, and when it hits zero,
* we tell the OS the device has gone away.
*/
static void
isp_gdt(void *arg)
{
ispsoftc_t *isp = arg;
fcportdb_t *lp;
int dbidx, tgt, more_to_do = 0;
/*
* Loop Down Timer Function- when loop goes down, a timer is started and
* and after it expires we come here and take all probational devices that
* the OS knows about and the tell the OS that they've gone away.
*
* We don't clear the devices out of our port database because, when loop
* come back up, we have to do some actual cleanup with the chip at that
* point (implicit PLOGO, e.g., to get the chip's port database state right).
*/
static void
isp_ldt(void *arg)
{
ispsoftc_t *isp = arg;
fcportdb_t *lp;
int dbidx, tgt;
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "Loop Down Timer expired");
ISP_LOCK(isp);
/*
* Notify to the OS all targets who we now consider have departed.
*/
for (dbidx = 0; dbidx < MAX_FC_TARG; dbidx++) {
lp = &FCPARAM(isp, 0)->portdb[dbidx];
if (lp->state != FC_PORTDB_STATE_PROBATIONAL) {
continue;
}
if (lp->dev_map_idx == 0) {
continue;
}
/*
* XXX: CLEAN UP AND COMPLETE ANY PENDING COMMANDS FIRST!
*/
/*
* Mark that we've announced that this device is gone....
*/
lp->reserved = 1;
/*
* but *don't* change the state of the entry. Just clear
* any target id stuff and announce to CAM that the
* device is gone. This way any necessary PLOGO stuff
* will happen when loop comes back up.
*/
/*
* The loop down timer has expired. Wake up the kthread
* to notice that fact (or make it false).
*/
isp->isp_osinfo.loop_down_time = isp->isp_osinfo.loop_down_limit+1;
wakeup(&isp->isp_osinfo.thread);
ISP_UNLOCK(isp);
}
static void
isp_make_here(ispsoftc_t *isp, int tgt)
{
isp_prt(isp, ISP_LOGINFO, "target %d has arrived", tgt);
}
static void
isp_make_gone(ispsoftc_t *isp, int tgt)
{
isp_prt(isp, ISP_LOGINFO, "target %d has departed", tgt);
}
static void
isp_fc_worker(void *arg)
{
ispsoftc_t *isp = arg;
int slp = 0;
int chan = 0;
int s = splbio();
/*
* The first loop is for our usage where we have yet to have
* gotten good fibre channel state.
*/
while (isp->isp_osinfo.thread != NULL) {
int sok, lb, lim;
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "checking FC state");
sok = isp->isp_osinfo.mbox_sleep_ok;
isp->isp_osinfo.mbox_sleep_ok = 1;
lb = isp_fc_runstate(isp, chan, 250000);
isp->isp_osinfo.mbox_sleep_ok = sok;
if (lb) {
/*
* Increment loop down time by the last sleep interval
*/
isp->isp_osinfo.loop_down_time += slp;
if (lb < 0) {
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"FC loop not up (down count %d)",
isp->isp_osinfo.loop_down_time);
} else {
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"FC got to %d (down count %d)",
lb, isp->isp_osinfo.loop_down_time);
}
/*
* If we've never seen loop up and we've waited longer
* than quickboot time, or we've seen loop up but we've
* waited longer than loop_down_limit, give up and go
* to sleep until loop comes up.
*/
if (FCPARAM(isp, 0)->loop_seen_once == 0) {
lim = isp_quickboot_time;
} else {
lim = isp->isp_osinfo.loop_down_limit;
}
if (isp->isp_osinfo.loop_down_time >= lim) {
/*
* If we're now past our limit, release
* the queues and let them come in and
* either get HBA_SELTIMEOUT or cause
* another freeze.
*/
isp->isp_osinfo.blocked = 1;
slp = 0;
} else if (isp->isp_osinfo.loop_down_time < 10) {
slp = 1;
} else if (isp->isp_osinfo.loop_down_time < 30) {
slp = 5;
} else if (isp->isp_osinfo.loop_down_time < 60) {
slp = 10;
} else if (isp->isp_osinfo.loop_down_time < 120) {
slp = 20;
} else {
slp = 30;
}
} else {
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"FC state OK");
isp->isp_osinfo.loop_down_time = 0;
slp = 0;
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"THAW QUEUES @ LINE %d", __LINE__);
scsipi_channel_thaw(&isp->isp_osinfo.chan[chan], 1);
}
/*
* If we'd frozen the queues, unfreeze them now so that
* we can start getting commands. If the FC state isn't
* okay yet, they'll hit that in isp_start which will
* freeze the queues again.
*/
if (isp->isp_osinfo.blocked) {
isp->isp_osinfo.blocked = 0;
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"THAW QUEUES @ LINE %d", __LINE__);
scsipi_channel_thaw(&isp->isp_osinfo.chan[chan], 1);
}
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0, "sleep time %d", slp);
tsleep(&isp->isp_osinfo.thread, PRIBIO, "ispf", slp * hz);
/*
* If slp is zero, we're waking up for the first time after
* things have been okay. In this case, we set a deferral state
* for all commands and delay hysteresis seconds before starting
* the FC state evaluation. This gives the loop/fabric a chance
* to settle.
*/
if (slp == 0 && isp_fabric_hysteresis) {
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"sleep hysteresis tick time %d",
isp_fabric_hysteresis * hz);
(void) tsleep(&isp_fabric_hysteresis, PRIBIO, "ispT",
(isp_fabric_hysteresis * hz));
}
}
splx(s);
/* In case parent is waiting for us to exit. */
wakeup(&isp->isp_osinfo.thread);
kthread_exit(0);
}
/*
* Free any associated resources prior to decommissioning and
* set the card to a known state (so it doesn't wake up and kick
* us when we aren't expecting it to).
*
* Locks are held before coming here.
*/
void
isp_uninit(struct ispsoftc *isp)
{
isp_lock(isp);
/*
* Leave with interrupts disabled.
*/
ISP_DISABLE_INTS(isp);
isp_unlock(isp);
}
if ((flags & DPARM_SYNC) && xm.xm_period && xm.xm_offset)
xm.xm_mode |= PERIPH_CAP_SYNC;
if (flags & DPARM_WIDE)
xm.xm_mode |= PERIPH_CAP_WIDE16;
if (flags & DPARM_TQING)
xm.xm_mode |= PERIPH_CAP_TQING;
scsipi_async_event(&isp->isp_osinfo.chan[bus],
ASYNC_EVENT_XFER_MODE, &xm);
break;
}
/* FALLTHROUGH */
case ISPASYNC_BUS_RESET:
va_start(ap, cmd);
bus = va_arg(ap, int);
va_end(ap);
isp_prt(isp, ISP_LOGINFO, "SCSI bus %d reset detected", bus);
scsipi_async_event(&isp->isp_osinfo.chan[bus],
ASYNC_EVENT_RESET, NULL);
break;
case ISPASYNC_LIP:
if (msg == NULL) {
msg = "LIP Received";
}
/* FALLTHROUGH */
case ISPASYNC_LOOP_RESET:
if (msg == NULL) {
msg = "LOOP Reset Received";
}
/* FALLTHROUGH */
case ISPASYNC_LOOP_DOWN:
if (msg == NULL) {
msg = "Loop DOWN";
}
va_start(ap, cmd);
bus = va_arg(ap, int);
va_end(ap);
/*
* Don't do queue freezes or blockage until we have the
* thread running and interrupts that can unfreeze/unblock us.
*/
if (isp->isp_osinfo.mbox_sleep_ok &&
isp->isp_osinfo.blocked == 0 &&
isp->isp_osinfo.thread) {
isp->isp_osinfo.blocked = 1;
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"FREEZE QUEUES @ LINE %d", __LINE__);
scsipi_channel_freeze(&isp->isp_osinfo.chan[bus], 1);
if (callout_pending(&isp->isp_osinfo.ldt) == 0) {
callout_schedule(&isp->isp_osinfo.ldt,
isp->isp_osinfo.loop_down_limit * hz);
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"Starting Loop Down Timer");
}
}
isp_prt(isp, ISP_LOGINFO, "%s", msg);
break;
case ISPASYNC_LOOP_UP:
/*
* Let the subsequent ISPASYNC_CHANGE_NOTIFY invoke
* the FC worker thread. When the FC worker thread
* is done, let *it* call scsipi_channel_thaw...
*/
isp_prt(isp, ISP_LOGINFO, "Loop UP");
break;
case ISPASYNC_DEV_ARRIVED:
va_start(ap, cmd);
bus = va_arg(ap, int);
lp = va_arg(ap, fcportdb_t *);
va_end(ap);
lp->reserved = 0;
if ((FCPARAM(isp, bus)->role & ISP_ROLE_INITIATOR) &&
(lp->roles & (SVC3_TGT_ROLE >> SVC3_ROLE_SHIFT))) {
int dbidx = lp - FCPARAM(isp, bus)->portdb;
int i;
for (i = 0; i < MAX_FC_TARG; i++) {
if (i >= FL_ID && i <= SNS_ID) {
continue;
}
if (FCPARAM(isp, bus)->isp_dev_map[i] == 0) {
break;
}
}
if (i < MAX_FC_TARG) {
FCPARAM(isp, bus)->isp_dev_map[i] = dbidx + 1;
lp->dev_map_idx = i + 1;
} else {
isp_prt(isp, ISP_LOGWARN, "out of target ids");
isp_dump_portdb(isp, bus);
}
}
if (lp->dev_map_idx) {
tgt = lp->dev_map_idx - 1;
isp_prt(isp, ISP_LOGCONFIG, prom2,
lp->portid, lp->handle,
roles[lp->roles], "arrived at", tgt,
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
isp_make_here(isp, tgt);
} else {
isp_prt(isp, ISP_LOGCONFIG, prom,
lp->portid, lp->handle,
roles[lp->roles], "arrived",
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
}
break;
case ISPASYNC_DEV_CHANGED:
va_start(ap, cmd);
bus = va_arg(ap, int);
lp = va_arg(ap, fcportdb_t *);
va_end(ap);
if (isp_change_is_bad) {
lp->state = FC_PORTDB_STATE_NIL;
if (lp->dev_map_idx) {
tgt = lp->dev_map_idx - 1;
FCPARAM(isp, bus)->isp_dev_map[tgt] = 0;
lp->dev_map_idx = 0;
isp_prt(isp, ISP_LOGCONFIG, prom3,
lp->portid, tgt, "change is bad");
isp_make_gone(isp, tgt);
} else {
isp_prt(isp, ISP_LOGCONFIG, prom,
lp->portid, lp->handle,
roles[lp->roles],
"changed and departed",
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
}
} else {
lp->portid = lp->new_portid;
lp->roles = lp->new_roles;
if (lp->dev_map_idx) {
int t = lp->dev_map_idx - 1;
FCPARAM(isp, bus)->isp_dev_map[t] =
(lp - FCPARAM(isp, bus)->portdb) + 1;
tgt = lp->dev_map_idx - 1;
isp_prt(isp, ISP_LOGCONFIG, prom2,
lp->portid, lp->handle,
roles[lp->roles], "changed at", tgt,
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
} else {
isp_prt(isp, ISP_LOGCONFIG, prom,
lp->portid, lp->handle,
roles[lp->roles], "changed",
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
}
}
break;
case ISPASYNC_DEV_STAYED:
va_start(ap, cmd);
bus = va_arg(ap, int);
lp = va_arg(ap, fcportdb_t *);
va_end(ap);
if (lp->dev_map_idx) {
tgt = lp->dev_map_idx - 1;
isp_prt(isp, ISP_LOGCONFIG, prom2,
lp->portid, lp->handle,
roles[lp->roles], "stayed at", tgt,
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
} else {
isp_prt(isp, ISP_LOGCONFIG, prom,
lp->portid, lp->handle,
roles[lp->roles], "stayed",
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
}
break;
case ISPASYNC_DEV_GONE:
va_start(ap, cmd);
bus = va_arg(ap, int);
lp = va_arg(ap, fcportdb_t *);
va_end(ap);
/*
* If this has a virtual target and we haven't marked it
* that we're going to have isp_gdt tell the OS it's gone,
* set the isp_gdt timer running on it.
*
* If it isn't marked that isp_gdt is going to get rid of it,
* announce that it's gone.
*/
if (lp->dev_map_idx && lp->reserved == 0) {
lp->reserved = 1;
lp->new_reserved = isp->isp_osinfo.gone_device_time;
lp->state = FC_PORTDB_STATE_ZOMBIE;
if (isp->isp_osinfo.gdt_running == 0) {
isp->isp_osinfo.gdt_running = 1;
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"starting Gone Device Timer");
callout_schedule(&isp->isp_osinfo.gdt, hz);
}
tgt = lp->dev_map_idx - 1;
isp_prt(isp, ISP_LOGCONFIG, prom2,
lp->portid, lp->handle,
roles[lp->roles], "gone zombie at", tgt,
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
} else if (lp->reserved == 0) {
isp_prt(isp, ISP_LOGCONFIG, prom,
lp->portid, lp->handle,
roles[lp->roles], "departed",
(uint32_t) (lp->node_wwn >> 32),
(uint32_t) lp->node_wwn,
(uint32_t) (lp->port_wwn >> 32),
(uint32_t) lp->port_wwn);
}
break;
case ISPASYNC_CHANGE_NOTIFY:
{
int opt;
if (opt == ISPASYNC_CHANGE_PDB) {
msg = "Port Database Changed";
} else if (opt == ISPASYNC_CHANGE_SNS) {
msg = "Name Server Database Changed";
} else {
msg = "Other Change Notify";
}
/*
* If the loop down timer is running, cancel it.
*/
if (callout_pending(&isp->isp_osinfo.ldt)) {
callout_stop(&isp->isp_osinfo.ldt);
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"Stopping Loop Down Timer");
}
isp_prt(isp, ISP_LOGINFO, "%s", msg);
/*
* We can set blocked here because we know it's now okay
* to try and run isp_fc_runstate (in order to build loop
* state). But we don't try and freeze the midlayer's queue
* if we have no thread that we can wake to later unfreeze
* it.
*/
if (isp->isp_osinfo.blocked == 0) {
isp->isp_osinfo.blocked = 1;
if (isp->isp_osinfo.thread) {
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"FREEZE QUEUES @ LINE %d", __LINE__);
scsipi_channel_freeze(&isp->isp_osinfo.chan[bus], 1);
}
}
/*
* Note that we have work for the thread to do, and
* if the thread is here already, wake it up.
*/
if (isp->isp_osinfo.thread) {
wakeup(&isp->isp_osinfo.thread);
} else {
isp_prt(isp, ISP_LOGDEBUG1, "no FC thread yet");
}
break;
}
case ISPASYNC_FW_CRASH:
{
uint16_t mbox1;
mbox1 = ISP_READ(isp, OUTMAILBOX1);
if (IS_DUALBUS(isp)) {
bus = ISP_READ(isp, OUTMAILBOX6);
} else {
bus = 0;
}
isp_prt(isp, ISP_LOGERR,
"Internal Firmware Error on bus %d @ RISC Address %#x",
bus, mbox1);
if (IS_FC(isp)) {
if (isp->isp_osinfo.blocked == 0) {
isp->isp_osinfo.blocked = 1;
isp_prt(isp, ISP_LOGSANCFG|ISP_LOGDEBUG0,
"FREEZE QUEUES @ LINE %d", __LINE__);
scsipi_channel_freeze(&isp->isp_osinfo.chan[bus], 1);
}
}
mbox1 = isp->isp_osinfo.mbox_sleep_ok;
isp->isp_osinfo.mbox_sleep_ok = 0;
isp_reinit(isp, 0);
isp->isp_osinfo.mbox_sleep_ok = mbox1;
isp_async(isp, ISPASYNC_FW_RESTARTED, NULL);
break;
}
default:
break;
}
}