Annotation of 43BSDReno/sys/hpstand/sd.c, revision 1.1.1.1

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 is only permitted until one year after the first shipment
                     11:  * of 4.4BSD by the Regents.  Otherwise, redistribution and use in source and
                     12:  * binary forms are permitted provided that: (1) source distributions retain
                     13:  * this entire copyright notice and comment, and (2) distributions including
                     14:  * binaries display the following acknowledgement:  This product includes
                     15:  * software developed by the University of California, Berkeley and its
                     16:  * contributors'' in the documentation or other materials provided with the
                     17:  * distribution and in all advertising materials mentioning features or use
                     18:  * of this software.  Neither the name of the University nor the names of
                     19:  * its contributors may be used to endorse or promote products derived from
                     20:  * this software without specific prior written permission.
                     21:  * THIS SOFTWARE IS PROVIDED AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
                     22:  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
                     23:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
                     24:  *
                     25:  * from: Utah $Hdr: sd.c 1.2 90/01/23$
                     26:  *
                     27:  *     @(#)sd.c        7.2 (Berkeley) 5/25/90
                     28:  */
                     29: 
                     30: /*
                     31:  * SCSI CCS disk driver
                     32:  */
                     33: 
                     34: #include "saio.h"
                     35: #include "samachdep.h"
                     36: 
                     37: #include "../hpdev/scsireg.h"
                     38: 
                     39: struct sd_softc {
                     40:        char    sc_retry;
                     41:        char    sc_alive;
                     42:        short   sc_blkshift;
                     43: } sd_softc[NSD];
                     44: 
                     45: int sdpartoff[] = {
                     46:        1024,   17408,  0,      17408,
                     47:        115712, 218112, 82944,  0
                     48: };
                     49: 
                     50: #define        SDRETRY         2
                     51: 
                     52: sdinit(unit)
                     53:        register int unit;
                     54: {
                     55:        register struct sd_softc *ss;
                     56:        u_char stat;
                     57:        int capbuf[2];
                     58: 
                     59:        if (unit > NSD)
                     60:                return (0);
                     61:        ss = &sd_softc[unit];
                     62:        /* NB: HP6300 won't boot if next printf is removed (???) - vj */
                     63:        printf("sd%d: ", unit);
                     64:        if ((stat = scsi_test_unit_rdy(unit)) == 0) {
                     65:                /* drive may be doing RTZ - wait a bit */
                     66:                printf("not ready - retrying ... ");
                     67:                if (stat == STS_CHECKCOND) {
                     68:                        DELAY(1000000);
                     69:                        if (scsi_test_unit_rdy(unit) == 0) {
                     70:                                printf("giving up.\n");
                     71:                                return (0);
                     72:                        }
                     73:                }
                     74:        }
                     75:        printf("unit ready.\n");
                     76:        /*
                     77:         * try to get the drive block size.
                     78:         */
                     79:        capbuf[0] = 0;
                     80:        capbuf[1] = 0;
                     81:        if (scsi_read_capacity(unit, (u_char *)capbuf, sizeof(capbuf)) != 0) {
                     82:                if (capbuf[1] > DEV_BSIZE)
                     83:                        for (; capbuf[1] > DEV_BSIZE; capbuf[1] >>= 1)
                     84:                                ++ss->sc_blkshift;
                     85:        }
                     86:        ss->sc_alive = 1;
                     87:        return (1);
                     88: }
                     89: 
                     90: sdreset(unit)
                     91: {
                     92: }
                     93: 
                     94: sdopen(io)
                     95:        struct iob *io;
                     96: {
                     97:        register int unit = io->i_unit;
                     98:        register struct sd_softc *ss = &sd_softc[unit];
                     99:        struct sdinfo *ri;
                    100: 
                    101:        if (scsialive(unit) == 0)
                    102:                _stop("scsi controller not configured");
                    103:        if (ss->sc_alive == 0)
                    104:                if (sdinit(unit) == 0)
                    105:                        _stop("sd init failed");
                    106:        if (io->i_boff < 0 || io->i_boff > 7)
                    107:                _stop("sd bad minor");
                    108:        io->i_boff = sdpartoff[io->i_boff];
                    109: }
                    110: 
                    111: sdstrategy(io, func)
                    112:        register struct iob *io;
                    113:        register int func;
                    114: {
                    115:        register int unit = io->i_unit;
                    116:        register struct sd_softc *ss = &sd_softc[unit];
                    117:        char stat;
                    118:        daddr_t blk = io->i_bn >> ss->sc_blkshift;
                    119:        u_int nblk = io->i_cc >> ss->sc_blkshift;
                    120: 
                    121:        ss->sc_retry = 0;
                    122: retry:
                    123:        if (func == READ)
                    124:                stat = scsi_tt_read(unit, io->i_ma, io->i_cc, blk, nblk);
                    125:        else
                    126:                stat = scsi_tt_write(unit, io->i_ma, io->i_cc, blk, nblk);
                    127:        if (stat) {
                    128:                printf("sd(%d,?) err: 0x%x\n", unit, stat);
                    129:                if (++ss->sc_retry > SDRETRY)
                    130:                        return(-1);
                    131:                else
                    132:                        goto retry;
                    133:        }
                    134:        return(io->i_cc);
                    135: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.