diff options
author | Miod Vallat <miod@cvs.openbsd.org> | 2013-10-09 20:03:06 +0000 |
---|---|---|
committer | Miod Vallat <miod@cvs.openbsd.org> | 2013-10-09 20:03:06 +0000 |
commit | 7884dce5d51b889fc93398546431e8667dc9f687 (patch) | |
tree | 027d647b08ffa470102368f5e9cac75e1bbbb9e1 /sys/arch/aviion | |
parent | c2347d6919b2b1594eda105eebab6fd9ffd9a1f1 (diff) |
Move common SCSI defines and structs to their own header, to eventually allow
SCSI tape support.
Drop sync negotiation from oosiop code, we can run without it.
Diffstat (limited to 'sys/arch/aviion')
-rw-r--r-- | sys/arch/aviion/stand/boot/oosiop.c | 182 | ||||
-rw-r--r-- | sys/arch/aviion/stand/boot/scsi.h | 89 | ||||
-rw-r--r-- | sys/arch/aviion/stand/boot/sd.c | 25 |
3 files changed, 110 insertions, 186 deletions
diff --git a/sys/arch/aviion/stand/boot/oosiop.c b/sys/arch/aviion/stand/boot/oosiop.c index 71fbf226a77..32091c7f732 100644 --- a/sys/arch/aviion/stand/boot/oosiop.c +++ b/sys/arch/aviion/stand/boot/oosiop.c @@ -1,6 +1,7 @@ -/* $OpenBSD: oosiop.c,v 1.1 2013/10/08 21:55:21 miod Exp $ */ -/* $OpenBSD: oosiop.c,v 1.1 2013/10/08 21:55:21 miod Exp $ */ -/* $NetBSD: oosiop.c,v 1.4 2003/10/29 17:45:55 tsutsui Exp $ */ +/* $OpenBSD: oosiop.c,v 1.2 2013/10/09 20:03:05 miod Exp $ */ +/* OpenBSD: oosiop.c,v 1.20 2013/10/09 18:22:06 miod Exp */ +/* OpenBSD: oosiopvar.h,v 1.5 2011/04/03 12:42:36 krw Exp */ +/* $NetBSD: oosiop.c,v 1.4 2003/10/29 17:45:55 tsutsui Exp $ */ /* $NetBSD: oosiopvar.h,v 1.2 2003/05/03 18:11:23 wiz Exp $ */ /* @@ -35,20 +36,7 @@ #include <stand.h> #include "libsa.h" -#include <scsi/scsi_all.h> -#include <scsi/scsiconf.h> -#define SCSI_DATA_IN 1 -#define SCSI_DATA_OUT 2 -#define ITSDONE 4 -#define XS_NOERROR 0 -#define XS_SENSE 1 -#define XS_DRIVER_STUFFUP 2 -#define XS_SELTIMEOUT 3 -#define XS_TIMEOUT 4 -#define XS_BUSY 5 -#define XS_RESET 8 - -#include <scsi/scsi_message.h> +#include "scsi.h" #include <dev/ic/oosiopreg.h> @@ -94,17 +82,6 @@ struct oosiop_cb { #define CBF_SELTOUT 0x01 /* Selection timeout */ #define CBF_TIMEOUT 0x02 /* Command timeout */ -struct oosiop_target { - struct oosiop_cb *nexus; - int flags; - u_int8_t scf; /* synchronous clock divisor */ - u_int8_t sxfer; /* synchronous period and offset */ -}; - -/* target flags */ -#define TGTF_SYNCNEG 0x01 /* Trigger synchronous negotiation */ -#define TGTF_WAITSDTR 0x02 /* Waiting SDTR from target */ - struct oosiop_softc { uint32_t sc_baseaddr; uint32_t *sc_scr; /* ptr to script memory */ @@ -116,14 +93,13 @@ struct oosiop_softc { int sc_freq; /* SCLK frequency */ int sc_ccf; /* asynchronous divisor (*10) */ u_int8_t sc_dcntl; - u_int8_t sc_minperiod; int sc_pending; - struct oosiop_target sc_tgt; struct oosiop_xfer sc_xfer; struct oosiop_cb sc_cb; + struct oosiop_cb *sc_nexus; struct oosiop_cb *sc_curcb; /* current command */ uint32_t sc_reselbuf; /* msgin buffer for reselection */ @@ -164,8 +140,7 @@ void oosiop_setup_dma(struct oosiop_softc *); void oosiop_flush_fifo(struct oosiop_softc *); void oosiop_clear_fifo(struct oosiop_softc *); void oosiop_phasemismatch(struct oosiop_softc *); -void oosiop_setup_syncxfer(struct oosiop_softc *); -void oosiop_set_syncparam(struct oosiop_softc *, int, int, int); +static __inline void oosiop_setup_syncxfer(struct oosiop_softc *); void oosiop_done(struct oosiop_softc *, struct oosiop_cb *); void oosiop_reset(struct oosiop_softc *); void oosiop_reset_bus(struct oosiop_softc *); @@ -178,36 +153,6 @@ void oosiop_processintr(struct oosiop_softc *, u_int8_t); #define DATAIN_TRAP 0xdead0001 #define DATAOUT_TRAP 0xdead0002 -/* Possible TP and SCF conbination */ -static const struct { - u_int8_t tp; - u_int8_t scf; -} synctbl[] = { - {0, 1}, /* SCLK / 4.0 */ - {1, 1}, /* SCLK / 5.0 */ - {2, 1}, /* SCLK / 6.0 */ - {3, 1}, /* SCLK / 7.0 */ - {1, 2}, /* SCLK / 7.5 */ - {4, 1}, /* SCLK / 8.0 */ - {5, 1}, /* SCLK / 9.0 */ - {6, 1}, /* SCLK / 10.0 */ - {3, 2}, /* SCLK / 10.5 */ - {7, 1}, /* SCLK / 11.0 */ - {4, 2}, /* SCLK / 12.0 */ - {5, 2}, /* SCLK / 13.5 */ - {3, 3}, /* SCLK / 14.0 */ - {6, 2}, /* SCLK / 15.0 */ - {4, 3}, /* SCLK / 16.0 */ - {7, 2}, /* SCLK / 16.5 */ - {5, 3}, /* SCLK / 18.0 */ - {6, 3}, /* SCLK / 20.0 */ - {7, 3} /* SCLK / 22.0 */ -}; -#define NSYNCTBL (sizeof(synctbl) / sizeof(synctbl[0])) - -#define oosiop_period(sc, tp, scf) \ - (((1000000000 / (sc)->sc_freq) * (tp) * (scf)) / 40) - void * oosiop_attach(uint32_t addr, int id, int lun) { @@ -246,10 +191,6 @@ oosiop_attach(uint32_t addr, int id, int lun) sc->sc_dcntl = OOSIOP_DCNTL_CF_3; } - sc->sc_minperiod = oosiop_period(sc, 4, sc->sc_ccf); - if (sc->sc_minperiod < 25) - sc->sc_minperiod = 25; /* limit to 10MB/s */ - sc->sc_cb.xfer = &sc->sc_xfer; sc->sc_reselbuf = (uint32_t)&sc->sc_xfer.msgin; @@ -527,9 +468,6 @@ oosiop_phasemismatch(struct oosiop_softc *sc) sstat1 = oosiop_read_1(sc, OOSIOP_SSTAT1); if (sstat1 & OOSIOP_SSTAT1_OLF) dbc++; - if ((sc->sc_tgt.sxfer != 0) && - (sstat1 & OOSIOP_SSTAT1_ORF) != 0) - dbc++; oosiop_clear_fifo(sc); } else { @@ -548,41 +486,10 @@ oosiop_phasemismatch(struct oosiop_softc *sc) } } -void +static __inline void oosiop_setup_syncxfer(struct oosiop_softc *sc) { - oosiop_write_1(sc, OOSIOP_SXFER, sc->sc_tgt.sxfer); -} - -void -oosiop_set_syncparam(struct oosiop_softc *sc, int id, int period, int offset) -{ - int i, p; - - printf("ncsc: target %d now using 8 bit ", id); - - if (offset == 0) { - /* Asynchronous */ - sc->sc_tgt.scf = 0; - sc->sc_tgt.sxfer = 0; - printf("asynchronous"); - } else { - /* Synchronous */ - for (i = 4; i < 12; i++) { - p = oosiop_period(sc, i, sc->sc_ccf); - if (p >= period) - break; - } - if (i == 12) { - printf("ncsc: target %d period too large\n", id); - i = 11; /* XXX */ - } - sc->sc_tgt.scf = 0; - sc->sc_tgt.sxfer = ((i - 4) << 4) | offset; - /* XXX print actual ns period... */ - printf(" synchronous"); - } - printf(" xfers\n"); + oosiop_write_1(sc, OOSIOP_SXFER, 0); } int @@ -650,18 +557,6 @@ oosiop_setup(struct oosiop_softc *sc, struct oosiop_cb *cb) xfer->msgout[0] = MSG_IDENTIFY(cb->lun, (((struct scsi_generic *)cb->cmdbuf)->opcode != REQUEST_SENSE)); cb->msgoutlen = 1; - - if (sc->sc_tgt.flags & TGTF_SYNCNEG) { - /* Send SDTR */ - xfer->msgout[1] = MSG_EXTENDED; - xfer->msgout[2] = MSG_EXT_SDTR_LEN; - xfer->msgout[3] = MSG_EXT_SDTR; - xfer->msgout[4] = sc->sc_minperiod; - xfer->msgout[5] = OOSIOP_MAX_OFFSET; - cb->msgoutlen = 6; - sc->sc_tgt.flags &= ~TGTF_SYNCNEG; - sc->sc_tgt.flags |= TGTF_WAITSDTR; - } } void @@ -700,7 +595,7 @@ oosiop_done(struct oosiop_softc *sc, struct oosiop_cb *cb) if (cb == sc->sc_curcb) sc->sc_curcb = NULL; - sc->sc_tgt.nexus = NULL; + sc->sc_nexus = NULL; } void @@ -739,11 +634,6 @@ oosiop_reset(struct oosiop_softc *sc) oosiop_write_1(sc, OOSIOP_DIEN, OOSIOP_DIEN_ABRT | OOSIOP_DIEN_SSI | OOSIOP_DIEN_SIR | OOSIOP_DIEN_WTD | OOSIOP_DIEN_IID); - - /* Set target state to asynchronous */ - sc->sc_tgt.flags = 0; - sc->sc_tgt.scf = 0; - sc->sc_tgt.sxfer = 0; } void @@ -755,10 +645,10 @@ oosiop_reset_bus(struct oosiop_softc *sc) oosiop_write_1(sc, OOSIOP_SCNTL1, 0); /* Remove all nexuses */ - if (sc->sc_tgt.nexus) { - sc->sc_tgt.nexus->xfer->status = + if (sc->sc_nexus) { + sc->sc_nexus->xfer->status = SCSI_OOSIOP_NOSTATUS; /* XXX */ - oosiop_done(sc, sc->sc_tgt.nexus); + oosiop_done(sc, sc->sc_nexus); } sc->sc_curcb = NULL; @@ -872,7 +762,7 @@ oosiop_processintr(struct oosiop_softc *sc, u_int8_t istat) if (sc->sc_nextdsp == Ent_wait_reselect && sc->sc_pending != 0) { sc->sc_pending = 0; cb = sc->sc_curcb = &sc->sc_cb; - sc->sc_tgt.nexus = cb; + sc->sc_nexus = cb; oosiop_setup_dma(sc); oosiop_setup_syncxfer(sc); sc->sc_nextdsp = Ent_start_select; @@ -929,14 +819,14 @@ oosiop_scriptintr(struct oosiop_softc *sc) if (cb) { /* Current command was lost arbitration */ - sc->sc_tgt.nexus = NULL; + sc->sc_nexus = NULL; sc->sc_curcb = NULL; } break; case A_int_res_id: - cb = sc->sc_tgt.nexus; + cb = sc->sc_nexus; resmsg = oosiop_read_1(sc, OOSIOP_SFBR); if (MSG_ISIDENTIFY(resmsg) && cb && (resmsg & MSG_IDENTIFY_LUNMASK) == cb->lun) { @@ -1000,40 +890,6 @@ oosiop_msgin(struct oosiop_softc *sc, struct oosiop_cb *cb) msgout = 0; switch (xfer->msgin[0]) { - case MSG_EXTENDED: - switch (xfer->msgin[2]) { - case MSG_EXT_SDTR: - if (sc->sc_tgt.flags & TGTF_WAITSDTR) { - /* Host initiated SDTR */ - sc->sc_tgt.flags &= ~TGTF_WAITSDTR; - } else { - /* Target initiated SDTR */ - if (xfer->msgin[3] < sc->sc_minperiod) - xfer->msgin[3] = sc->sc_minperiod; - if (xfer->msgin[4] > OOSIOP_MAX_OFFSET) - xfer->msgin[4] = OOSIOP_MAX_OFFSET; - xfer->msgout[0] = MSG_EXTENDED; - xfer->msgout[1] = MSG_EXT_SDTR_LEN; - xfer->msgout[2] = MSG_EXT_SDTR; - xfer->msgout[3] = xfer->msgin[3]; - xfer->msgout[4] = xfer->msgin[4]; - cb->msgoutlen = 5; - msgout = 1; - } - oosiop_set_syncparam(sc, cb->id, (int)xfer->msgin[3], - (int)xfer->msgin[4]); - oosiop_setup_syncxfer(sc); - break; - - default: - /* Reject message */ - xfer->msgout[0] = MSG_MESSAGE_REJECT; - cb->msgoutlen = 1; - msgout = 1; - break; - } - break; - case MSG_SAVEDATAPOINTER: cb->savedp = cb->curdp; break; @@ -1046,12 +902,6 @@ oosiop_msgin(struct oosiop_softc *sc, struct oosiop_cb *cb) break; case MSG_MESSAGE_REJECT: - if (sc->sc_tgt.flags & TGTF_WAITSDTR) { - /* SDTR rejected */ - sc->sc_tgt.flags &= ~TGTF_WAITSDTR; - oosiop_set_syncparam(sc, cb->id, 0, 0); - oosiop_setup_syncxfer(sc); - } break; default: diff --git a/sys/arch/aviion/stand/boot/scsi.h b/sys/arch/aviion/stand/boot/scsi.h new file mode 100644 index 00000000000..a5952a23d08 --- /dev/null +++ b/sys/arch/aviion/stand/boot/scsi.h @@ -0,0 +1,89 @@ +/* $OpenBSD: scsi.h,v 1.1 2013/10/09 20:03:05 miod Exp $ */ + +#include <scsi/scsi_all.h> +#include <scsi/scsiconf.h> + +/* + * The following are defines from <scsi/scsiconf.h> not available to + * !_KERNEL code, under the following licence terms: + */ + +/* OpenBSD: scsiconf.h,v 1.157 2013/09/27 11:43:19 krw Exp */ +/* $NetBSD: scsiconf.h,v 1.35 1997/04/02 02:29:38 mycroft Exp $ */ + +/* + * Copyright (c) 1993, 1994, 1995 Charles Hannum. 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. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Charles Hannum. + * 4. 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. + */ + +/* + * Originally written by Julian Elischer (julian@tfs.com) + * for TRW Financial Systems for use under the MACH(2.5) operating system. + * + * TRW Financial Systems, in accordance with their agreement with Carnegie + * Mellon University, makes this software available to CMU to distribute + * or use in any manner that they see fit as long as this message is kept with + * the software. For this reason TFS also grants any other persons or + * organisations permission to use or modify this software. + * + * TFS supplies this software to be publicly redistributed + * on the understanding that TFS is not responsible for the correct + * functioning of this software in any circumstances. + * + * Ported to run under 386BSD by Julian Elischer (julian@tfs.com) Sept 1992 + */ + +#define ITSDONE 0x00008 /* the transfer is as done as it gets */ +#define SCSI_DATA_IN 0x00800 /* expect data to come INTO memory */ +#define SCSI_DATA_OUT 0x01000 /* expect data to flow OUT of memory */ + +#define XS_NOERROR 0 /* there is no error, (sense is invalid) */ +#define XS_SENSE 1 /* Check the returned sense for the error */ +#define XS_DRIVER_STUFFUP 2 /* Driver failed to perform operation */ +#define XS_SELTIMEOUT 3 /* The device timed out.. turned off? */ +#define XS_TIMEOUT 4 /* The Timeout reported was caught by SW */ +#define XS_BUSY 5 /* The device busy, try again later? */ +#define XS_SHORTSENSE 6 /* Check the ATAPI sense for the error */ +#define XS_RESET 8 /* bus was reset; possible retry command */ +#define XS_NO_CCB 9 /* device should requeue io and retry */ + +#define TEST_READY_RETRIES 5 + +#define SCSI_RETRIES 4 + +#include <scsi/scsi_message.h> + +struct scsi_private { + void *scsicookie; + int (*scsicmd)(void *, void *, size_t, void *, size_t, size_t *); + void (*scsidetach)(void *); + + struct disklabel label; + int part; +}; + +#include "oosiop.h" diff --git a/sys/arch/aviion/stand/boot/sd.c b/sys/arch/aviion/stand/boot/sd.c index f004eef3771..92da668de69 100644 --- a/sys/arch/aviion/stand/boot/sd.c +++ b/sys/arch/aviion/stand/boot/sd.c @@ -1,4 +1,4 @@ -/* $OpenBSD: sd.c,v 1.1 2013/10/08 21:55:21 miod Exp $ */ +/* $OpenBSD: sd.c,v 1.2 2013/10/09 20:03:05 miod Exp $ */ /* * Copyright (c) 2013 Miodrag Vallat. @@ -21,26 +21,10 @@ #include <sys/param.h> #include <stand.h> -#include <scsi/scsiconf.h> -#define TEST_READY_RETRIES 5 -#include <scsi/scsi_all.h> -#include <scsi/scsi_disk.h> - #include <sys/disklabel.h> -#include "oosiop.h" - -#define paddr_t uint32_t -#define vaddr_t uint32_t -#define vsize_t size_t - -struct scsi_private { - void *scsicookie; - int (*scsicmd)(void *, void *, size_t, void *, size_t, size_t *); - void (*scsidetach)(void *); - - struct disklabel label; -}; +#include "scsi.h" +#include <scsi/scsi_disk.h> static int sdtur(struct scsi_private *priv) @@ -115,6 +99,7 @@ sdopen(struct open_file *f, const char *ctrlname, int ctrl, int unit, int lun, priv = (struct scsi_private *)f->f_devdata; memset(priv, 0, sizeof(struct scsi_private)); + priv->part = part; /* XXX provide default based upon system type */ if (*ctrlname == '\0') @@ -174,7 +159,7 @@ sdstrategy(void *devdata, int rw, daddr32_t blk, size_t size, void *buf, if (rw != F_READ) return EROFS; - blk += priv->label.d_partitions[0 /* XXX part */].p_offset; + blk += priv->label.d_partitions[priv->part].p_offset; return sdread(priv, blk, size, buf, rsize) != 0 ? EIO : 0; } |