/*
* Copyright (c) 1990 The Regents of the University of California.
* All rights reserved.
*
* This code is derived from software contributed to Berkeley by
* Van Jacobson of Lawrence Berkeley Laboratory.
*
* 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. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``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 REGENTS OR CONTRIBUTORS 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.
*
* @(#)scsi.c 7.5 (Berkeley) 5/4/91
*/
/*
* Copyright (c) 1994 Michael L. Hitch
*
* This code is derived from software contributed to Berkeley by
* Van Jacobson of Lawrence Berkeley Laboratory.
*
* 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.
*
* 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.
*
* @(#)scsi.c 7.5 (Berkeley) 5/4/91
*/
/*
* SCSI delays
* In u-seconds, primarily for state changes on the SPC.
*/
#define SCI_CMD_WAIT 50000 /* wait per step of 'immediate' cmds */
#define SCI_DATA_WAIT 50000 /* wait per data in/out step */
#define SCI_INIT_WAIT 50000 /* wait per step (both) during init */
int sci_cmd_wait = SCI_CMD_WAIT;
int sci_data_wait = SCI_DATA_WAIT;
int sci_init_wait = SCI_INIT_WAIT;
int sci_no_dma = 0;
#ifdef DEBUG
#define QPRINTF(a) if (sci_debug > 1) printf a
int sci_debug = 0;
#else
#define QPRINTF(a)
#endif
/*
* default minphys routine for sci based controllers
*/
void
sci_minphys(struct buf *bp)
{
/*
* No max transfer at this level.
*/
minphys(bp);
}
/*
* used by specific sci controller
*
* it appears that the higher level code does nothing with LUN's
* so I will too. I could plug it in, however so could they
* in scsi_scsipi_cmd().
*/
void
sci_scsipi_request(struct scsipi_channel *chan, scsipi_adapter_req_t req,
void *arg)
{
struct scsipi_xfer *xs;
#ifdef DIAGNOSTIC
struct scsipi_periph *periph;
#endif
struct sci_softc *dev = device_private(chan->chan_adapter->adapt_dev);
int flags, s;
if (flags & XS_CTL_DATA_UIO)
panic("sci: scsi data uio requested");
s = splbio();
if (dev->sc_xs && flags & XS_CTL_POLL)
panic("sci_scsicmd: busy");
#ifdef DIAGNOSTIC
/*
* This should never happen as we track the resources
* in the mid-layer.
*/
if (dev->sc_xs) {
scsipi_printaddr(periph);
printf("unable to allocate scb\n");
panic("sea_scsipi_request");
}
#endif
dev->sc_xs = xs;
splx(s);
/*
* nothing is pending do it now.
*/
sci_donextcmd(dev);
return;
case ADAPTER_REQ_GROW_RESOURCES:
return;
case ADAPTER_REQ_SET_XFER_MODE:
return;
}
}
/*
* entered with dev->sc_xs pointing to the next xfer to perform
*/
void
sci_donextcmd(struct sci_softc *dev)
{
struct scsipi_xfer *xs;
struct scsipi_periph *periph;
int flags, phase, stat;
/* lets just hope it worked.. */
dev->sc_flags &= ~SCI_SELECTED;
/* XXX */
scireset (dev);
}
}
/*
* XXX Set/reset long delays.
*
* if delay == 0, reset default delays
* if delay < 0, set both delays to default long initialization values
* if delay > 0, set both delays to this value
*
* Used when a devices is expected to respond slowly (e.g. during
* initialization).
*/
void
scisetdelay(int del)
{
static int saved_cmd_wait, saved_data_wait;
/*
* select the bus, return when selected or error.
*/
int
sciselectbus(struct sci_softc *dev, u_char target, u_char our_addr)
{
register int timeo = 2500;
QPRINTF (("sciselectbus %d\n", target));
/* if we're already selected, return */
if (dev->sc_flags & SCI_SELECTED) /* XXXX */
return 1;
/*
* SCSI 'immediate' command: issue a command to some SCSI device
* and get back an 'immediate' response (i.e., do programmed xfer
* to get the response data). 'cbuf' is a buffer containing a scsi
* command of length clen bytes. 'buf' is a buffer of length 'len'
* bytes for data. The transfer direction is determined by the device
* (i.e., by the scsi bus data xfer phase). If 'len' is zero, the
* command must supply no data. 'xferphase' is the bus phase the
* caller expects to happen after the command is issued. It should
* be one of DATA_IN_PHASE, DATA_OUT_PHASE or STATUS_PHASE.
*/
int
sciicmd(struct sci_softc *dev, int target, void *cbuf, int clen, void *buf,
int len, u_char xferphase)
{
u_char phase;
int wait;
/* select the SCSI bus (it's an error if bus isn't free) */
if (sciselectbus (dev, target, dev->sc_scsi_addr))
return -1;
/*
* Wait for a phase change (or error) then let the device
* sequence us through the various SCSI phases.
*/
dev->sc_stat[0] = 0xff;
dev->sc_msg[0] = 0xff;
phase = CMD_PHASE;
while (1) {
wait = sci_cmd_wait;
while ((*dev->sci_bus_csr & (SCI_BUS_REQ|SCI_BUS_BSY)) == SCI_BUS_BSY);
/* select the SCSI bus (it's an error if bus isn't free) */
if (sciselectbus (dev, target, dev->sc_scsi_addr))
return -1;
/*
* Wait for a phase change (or error) then let the device
* sequence us through the various SCSI phases.
*/
dev->sc_stat[0] = 0xff;
dev->sc_msg[0] = 0xff;
phase = CMD_PHASE;
while (1) {
while ((*dev->sci_bus_csr & (SCI_BUS_REQ|SCI_BUS_BSY)) ==
SCI_BUS_BSY);