141488Smckusick /* 241488Smckusick * Copyright (c) 1988 University of Utah. 341488Smckusick * Copyright (c) 1990 The Regents of the University of California. 441488Smckusick * All rights reserved. 541488Smckusick * 641488Smckusick * This code is derived from software contributed to Berkeley by 741488Smckusick * Van Jacobson of Lawrence Berkeley Laboratory and the Systems 841488Smckusick * Programming Group of the University of Utah Computer Science Department. 941488Smckusick * 1041488Smckusick * %sccs.include.redist.c% 1141488Smckusick * 1241488Smckusick * from: Utah $Hdr: sd.c 1.2 90/01/23$ 1341488Smckusick * 14*42377Smckusick * @(#)sd.c 7.2 (Berkeley) 05/25/90 1541488Smckusick */ 1641488Smckusick 1741488Smckusick /* 1841488Smckusick * SCSI CCS disk driver 1941488Smckusick */ 2041488Smckusick 2141488Smckusick #include "saio.h" 2241488Smckusick #include "samachdep.h" 2341488Smckusick 2441488Smckusick #include "../hpdev/scsireg.h" 2541488Smckusick 2641488Smckusick struct sd_softc { 2741488Smckusick char sc_retry; 2841488Smckusick char sc_alive; 2941488Smckusick short sc_blkshift; 3041488Smckusick } sd_softc[NSD]; 3141488Smckusick 3241488Smckusick int sdpartoff[] = { 3341488Smckusick 1024, 17408, 0, 17408, 3441488Smckusick 115712, 218112, 82944, 0 3541488Smckusick }; 3641488Smckusick 3741488Smckusick #define SDRETRY 2 3841488Smckusick 3941488Smckusick sdinit(unit) 4041488Smckusick register int unit; 4141488Smckusick { 4241488Smckusick register struct sd_softc *ss; 4341488Smckusick u_char stat; 4441488Smckusick int capbuf[2]; 4541488Smckusick 4641488Smckusick if (unit > NSD) 4741488Smckusick return (0); 4841488Smckusick ss = &sd_softc[unit]; 4941488Smckusick /* NB: HP6300 won't boot if next printf is removed (???) - vj */ 5041488Smckusick printf("sd%d: ", unit); 5141488Smckusick if ((stat = scsi_test_unit_rdy(unit)) == 0) { 5241488Smckusick /* drive may be doing RTZ - wait a bit */ 5341488Smckusick printf("not ready - retrying ... "); 5441488Smckusick if (stat == STS_CHECKCOND) { 5541488Smckusick DELAY(1000000); 5641488Smckusick if (scsi_test_unit_rdy(unit) == 0) { 5741488Smckusick printf("giving up.\n"); 5841488Smckusick return (0); 5941488Smckusick } 6041488Smckusick } 6141488Smckusick } 6241488Smckusick printf("unit ready.\n"); 6341488Smckusick /* 6441488Smckusick * try to get the drive block size. 6541488Smckusick */ 6641488Smckusick capbuf[0] = 0; 6741488Smckusick capbuf[1] = 0; 6841488Smckusick if (scsi_read_capacity(unit, (u_char *)capbuf, sizeof(capbuf)) != 0) { 6941488Smckusick if (capbuf[1] > DEV_BSIZE) 7041488Smckusick for (; capbuf[1] > DEV_BSIZE; capbuf[1] >>= 1) 7141488Smckusick ++ss->sc_blkshift; 7241488Smckusick } 7341488Smckusick ss->sc_alive = 1; 7441488Smckusick return (1); 7541488Smckusick } 7641488Smckusick 7741488Smckusick sdreset(unit) 7841488Smckusick { 7941488Smckusick } 8041488Smckusick 8141488Smckusick sdopen(io) 8241488Smckusick struct iob *io; 8341488Smckusick { 8441488Smckusick register int unit = io->i_unit; 8541488Smckusick register struct sd_softc *ss = &sd_softc[unit]; 8641488Smckusick struct sdinfo *ri; 8741488Smckusick 8841488Smckusick if (scsialive(unit) == 0) 8941488Smckusick _stop("scsi controller not configured"); 9041488Smckusick if (ss->sc_alive == 0) 9141488Smckusick if (sdinit(unit) == 0) 9241488Smckusick _stop("sd init failed"); 9341488Smckusick if (io->i_boff < 0 || io->i_boff > 7) 9441488Smckusick _stop("sd bad minor"); 9541488Smckusick io->i_boff = sdpartoff[io->i_boff]; 9641488Smckusick } 9741488Smckusick 9841488Smckusick sdstrategy(io, func) 9941488Smckusick register struct iob *io; 10041488Smckusick register int func; 10141488Smckusick { 10241488Smckusick register int unit = io->i_unit; 10341488Smckusick register struct sd_softc *ss = &sd_softc[unit]; 10441488Smckusick char stat; 10541488Smckusick daddr_t blk = io->i_bn >> ss->sc_blkshift; 10641488Smckusick u_int nblk = io->i_cc >> ss->sc_blkshift; 10741488Smckusick 10841488Smckusick ss->sc_retry = 0; 10941488Smckusick retry: 11041488Smckusick if (func == READ) 11141488Smckusick stat = scsi_tt_read(unit, io->i_ma, io->i_cc, blk, nblk); 11241488Smckusick else 11341488Smckusick stat = scsi_tt_write(unit, io->i_ma, io->i_cc, blk, nblk); 11441488Smckusick if (stat) { 115*42377Smckusick printf("sd(%d,?) err: 0x%x\n", unit, stat); 11641488Smckusick if (++ss->sc_retry > SDRETRY) 11741488Smckusick return(-1); 11841488Smckusick else 11941488Smckusick goto retry; 12041488Smckusick } 12141488Smckusick return(io->i_cc); 12241488Smckusick } 123