1*41488Smckusick /* 2*41488Smckusick * Copyright (c) 1988 University of Utah. 3*41488Smckusick * Copyright (c) 1990 The Regents of the University of California. 4*41488Smckusick * All rights reserved. 5*41488Smckusick * 6*41488Smckusick * This code is derived from software contributed to Berkeley by 7*41488Smckusick * Van Jacobson of Lawrence Berkeley Laboratory and the Systems 8*41488Smckusick * Programming Group of the University of Utah Computer Science Department. 9*41488Smckusick * 10*41488Smckusick * %sccs.include.redist.c% 11*41488Smckusick * 12*41488Smckusick * from: Utah $Hdr: sd.c 1.2 90/01/23$ 13*41488Smckusick * 14*41488Smckusick * @(#)sd.c 7.1 (Berkeley) 05/08/90 15*41488Smckusick */ 16*41488Smckusick 17*41488Smckusick /* 18*41488Smckusick * SCSI CCS disk driver 19*41488Smckusick */ 20*41488Smckusick 21*41488Smckusick #include "saio.h" 22*41488Smckusick #include "samachdep.h" 23*41488Smckusick 24*41488Smckusick #include "../hpdev/scsireg.h" 25*41488Smckusick 26*41488Smckusick struct sd_softc { 27*41488Smckusick char sc_retry; 28*41488Smckusick char sc_alive; 29*41488Smckusick short sc_blkshift; 30*41488Smckusick } sd_softc[NSD]; 31*41488Smckusick 32*41488Smckusick int sdpartoff[] = { 33*41488Smckusick 1024, 17408, 0, 17408, 34*41488Smckusick 115712, 218112, 82944, 0 35*41488Smckusick }; 36*41488Smckusick 37*41488Smckusick #define SDRETRY 2 38*41488Smckusick 39*41488Smckusick sdinit(unit) 40*41488Smckusick register int unit; 41*41488Smckusick { 42*41488Smckusick register struct sd_softc *ss; 43*41488Smckusick u_char stat; 44*41488Smckusick int capbuf[2]; 45*41488Smckusick 46*41488Smckusick if (unit > NSD) 47*41488Smckusick return (0); 48*41488Smckusick ss = &sd_softc[unit]; 49*41488Smckusick /* NB: HP6300 won't boot if next printf is removed (???) - vj */ 50*41488Smckusick printf("sd%d: ", unit); 51*41488Smckusick if ((stat = scsi_test_unit_rdy(unit)) == 0) { 52*41488Smckusick /* drive may be doing RTZ - wait a bit */ 53*41488Smckusick printf("not ready - retrying ... "); 54*41488Smckusick if (stat == STS_CHECKCOND) { 55*41488Smckusick DELAY(1000000); 56*41488Smckusick if (scsi_test_unit_rdy(unit) == 0) { 57*41488Smckusick printf("giving up.\n"); 58*41488Smckusick return (0); 59*41488Smckusick } 60*41488Smckusick } 61*41488Smckusick } 62*41488Smckusick printf("unit ready.\n"); 63*41488Smckusick /* 64*41488Smckusick * try to get the drive block size. 65*41488Smckusick */ 66*41488Smckusick capbuf[0] = 0; 67*41488Smckusick capbuf[1] = 0; 68*41488Smckusick if (scsi_read_capacity(unit, (u_char *)capbuf, sizeof(capbuf)) != 0) { 69*41488Smckusick if (capbuf[1] > DEV_BSIZE) 70*41488Smckusick for (; capbuf[1] > DEV_BSIZE; capbuf[1] >>= 1) 71*41488Smckusick ++ss->sc_blkshift; 72*41488Smckusick } 73*41488Smckusick ss->sc_alive = 1; 74*41488Smckusick return (1); 75*41488Smckusick } 76*41488Smckusick 77*41488Smckusick sdreset(unit) 78*41488Smckusick { 79*41488Smckusick } 80*41488Smckusick 81*41488Smckusick sdopen(io) 82*41488Smckusick struct iob *io; 83*41488Smckusick { 84*41488Smckusick register int unit = io->i_unit; 85*41488Smckusick register struct sd_softc *ss = &sd_softc[unit]; 86*41488Smckusick struct sdinfo *ri; 87*41488Smckusick 88*41488Smckusick if (scsialive(unit) == 0) 89*41488Smckusick _stop("scsi controller not configured"); 90*41488Smckusick if (ss->sc_alive == 0) 91*41488Smckusick if (sdinit(unit) == 0) 92*41488Smckusick _stop("sd init failed"); 93*41488Smckusick if (io->i_boff < 0 || io->i_boff > 7) 94*41488Smckusick _stop("sd bad minor"); 95*41488Smckusick io->i_boff = sdpartoff[io->i_boff]; 96*41488Smckusick } 97*41488Smckusick 98*41488Smckusick sdstrategy(io, func) 99*41488Smckusick register struct iob *io; 100*41488Smckusick register int func; 101*41488Smckusick { 102*41488Smckusick register int unit = io->i_unit; 103*41488Smckusick register struct sd_softc *ss = &sd_softc[unit]; 104*41488Smckusick char stat; 105*41488Smckusick daddr_t blk = io->i_bn >> ss->sc_blkshift; 106*41488Smckusick u_int nblk = io->i_cc >> ss->sc_blkshift; 107*41488Smckusick 108*41488Smckusick ss->sc_retry = 0; 109*41488Smckusick retry: 110*41488Smckusick if (func == READ) 111*41488Smckusick stat = scsi_tt_read(unit, io->i_ma, io->i_cc, blk, nblk); 112*41488Smckusick else 113*41488Smckusick stat = scsi_tt_write(unit, io->i_ma, io->i_cc, blk, nblk); 114*41488Smckusick if (stat) { 115*41488Smckusick printf("sd(%d,?) err: 0x%x", unit, stat); 116*41488Smckusick if (++ss->sc_retry > SDRETRY) 117*41488Smckusick return(-1); 118*41488Smckusick else 119*41488Smckusick goto retry; 120*41488Smckusick } 121*41488Smckusick return(io->i_cc); 122*41488Smckusick } 123