|
|
1.1 ! root 1: /* ! 2: * Copyright (c) 1988 University of Utah. ! 3: * Copyright (c) 1990 The Regents of the University of California. ! 4: * All rights reserved. ! 5: * ! 6: * This code is derived from software contributed to Berkeley by ! 7: * Van Jacobson of Lawrence Berkeley Laboratory and the Systems ! 8: * Programming Group of the University of Utah Computer Science Department. ! 9: * ! 10: * Redistribution and use in source and binary forms, with or without ! 11: * modification, are permitted provided that the following conditions ! 12: * are met: ! 13: * 1. Redistributions of source code must retain the above copyright ! 14: * notice, this list of conditions and the following disclaimer. ! 15: * 2. Redistributions in binary form must reproduce the above copyright ! 16: * notice, this list of conditions and the following disclaimer in the ! 17: * documentation and/or other materials provided with the distribution. ! 18: * 3. All advertising materials mentioning features or use of this software ! 19: * must display the following acknowledgement: ! 20: * This product includes software developed by the University of ! 21: * California, Berkeley and its contributors. ! 22: * 4. Neither the name of the University nor the names of its contributors ! 23: * may be used to endorse or promote products derived from this software ! 24: * without specific prior written permission. ! 25: * ! 26: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND ! 27: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE ! 28: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ! 29: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE ! 30: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL ! 31: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS ! 32: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) ! 33: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT ! 34: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY ! 35: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ! 36: * SUCH DAMAGE. ! 37: * ! 38: * from: Utah $Hdr: sd.c 1.2 90/01/23$ ! 39: * ! 40: * @(#)sd.c 7.4 (Berkeley) 5/5/91 ! 41: */ ! 42: ! 43: /* ! 44: * SCSI CCS disk driver ! 45: */ ! 46: ! 47: #include <sys/param.h> ! 48: #include "saio.h" ! 49: #include "samachdep.h" ! 50: ! 51: #include "../dev/scsireg.h" ! 52: ! 53: struct sd_softc { ! 54: char sc_retry; ! 55: char sc_alive; ! 56: short sc_blkshift; ! 57: } sd_softc[NSD]; ! 58: ! 59: int sdpartoff[] = { ! 60: 1024, 17408, 0, 17408, ! 61: 115712, 218112, 82944, 0 ! 62: }; ! 63: ! 64: #define SDRETRY 2 ! 65: ! 66: sdinit(unit) ! 67: register int unit; ! 68: { ! 69: register struct sd_softc *ss; ! 70: u_char stat; ! 71: int capbuf[2]; ! 72: ! 73: if (unit > NSD) ! 74: return (0); ! 75: ss = &sd_softc[unit]; ! 76: /* NB: HP6300 won't boot if next printf is removed (???) - vj */ ! 77: printf("sd%d: ", unit); ! 78: if ((stat = scsi_test_unit_rdy(unit)) == 0) { ! 79: /* drive may be doing RTZ - wait a bit */ ! 80: printf("not ready - retrying ... "); ! 81: if (stat == STS_CHECKCOND) { ! 82: DELAY(1000000); ! 83: if (scsi_test_unit_rdy(unit) == 0) { ! 84: printf("giving up.\n"); ! 85: return (0); ! 86: } ! 87: } ! 88: } ! 89: printf("unit ready.\n"); ! 90: /* ! 91: * try to get the drive block size. ! 92: */ ! 93: capbuf[0] = 0; ! 94: capbuf[1] = 0; ! 95: if (scsi_read_capacity(unit, (u_char *)capbuf, sizeof(capbuf)) != 0) { ! 96: if (capbuf[1] > DEV_BSIZE) ! 97: for (; capbuf[1] > DEV_BSIZE; capbuf[1] >>= 1) ! 98: ++ss->sc_blkshift; ! 99: } ! 100: ss->sc_alive = 1; ! 101: return (1); ! 102: } ! 103: ! 104: sdreset(unit) ! 105: { ! 106: } ! 107: ! 108: sdopen(io) ! 109: struct iob *io; ! 110: { ! 111: register int unit = io->i_unit; ! 112: register struct sd_softc *ss = &sd_softc[unit]; ! 113: struct sdinfo *ri; ! 114: ! 115: if (scsialive(unit) == 0) ! 116: _stop("scsi controller not configured"); ! 117: if (ss->sc_alive == 0) ! 118: if (sdinit(unit) == 0) ! 119: _stop("sd init failed"); ! 120: if (io->i_boff < 0 || io->i_boff > 7) ! 121: _stop("sd bad minor"); ! 122: io->i_boff = sdpartoff[io->i_boff]; ! 123: } ! 124: ! 125: sdstrategy(io, func) ! 126: register struct iob *io; ! 127: register int func; ! 128: { ! 129: register int unit = io->i_unit; ! 130: register struct sd_softc *ss = &sd_softc[unit]; ! 131: char stat; ! 132: daddr_t blk = io->i_bn >> ss->sc_blkshift; ! 133: u_int nblk = io->i_cc >> ss->sc_blkshift; ! 134: ! 135: ss->sc_retry = 0; ! 136: retry: ! 137: if (func == F_READ) ! 138: stat = scsi_tt_read(unit, io->i_ma, io->i_cc, blk, nblk); ! 139: else ! 140: stat = scsi_tt_write(unit, io->i_ma, io->i_cc, blk, nblk); ! 141: if (stat) { ! 142: printf("sd(%d,?) err: 0x%x\n", unit, stat); ! 143: if (++ss->sc_retry > SDRETRY) ! 144: return(-1); ! 145: else ! 146: goto retry; ! 147: } ! 148: return(io->i_cc); ! 149: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.