Annotation of Net2/arch/hp300/stand/rd.c, revision 1.1.1.2

1.1       root        1: /*
                      2:  * Copyright (c) 1988 University of Utah.
                      3:  * Copyright (c) 1982, 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:  * the Systems Programming Group of the University of Utah Computer
                      8:  * 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: rd.c 1.14 89/02/27$
                     39:  *
1.1.1.2 ! root       40:  *     from: @(#)rd.c  7.3 (Berkeley) 5/5/91
        !            41:  *     rd.c,v 1.2 1993/05/22 07:59:16 cgd Exp
1.1       root       42:  */
                     43: 
                     44: /*
                     45:  * CS80/SS80 disk driver
                     46:  */
                     47: #include <sys/param.h>
                     48: #include "saio.h"
                     49: #include "samachdep.h"
                     50: 
                     51: #include "../dev/rdreg.h"
                     52: 
                     53: struct rd_iocmd rd_ioc;
                     54: struct rd_rscmd rd_rsc;
                     55: struct rd_stat rd_stat;
                     56: struct rd_ssmcmd rd_ssmc;
                     57: 
                     58: struct rd_softc {
                     59:        char    sc_retry;
                     60:        char    sc_alive;
                     61:        short   sc_type;
                     62: } rd_softc[NRD];
                     63: 
                     64: #define        RDRETRY         5
                     65: 
                     66: int rdcyloff[][8] = {
                     67:        { 1, 143, 0, 143, 0,   0,   323, 503, },        /* 7945A */
                     68:        { 1, 167, 0, 0,   0,   0,   0,   0,   },        /* 9134D */
                     69:        { 0, 0,   0, 0,   0,   0,   0,   0,   },        /* 9122S */
                     70:        { 0, 71,  0, 221, 292, 542, 221, 0,   },        /* 7912P */
                     71:        { 1, 72,  0, 72,  362, 802, 252, 362, },        /* 7914P */
                     72:        { 1, 28,  0, 140, 167, 444, 140, 721, },        /* 7933H */
                     73:        { 1, 200, 0, 200, 0,   0,   450, 600, },        /* 9134L */
                     74:        { 1, 105, 0, 105, 380, 736, 265, 380, },        /* 7957A */
                     75:        { 1, 65,  0, 65,  257, 657, 193, 257, },        /* 7958A */
                     76:        { 1, 128, 0, 128, 518, 918, 388, 518, },        /* 7957B */
                     77:        { 1, 44,  0, 44,  174, 496, 131, 174, },        /* 7958B */
                     78:        { 1, 44,  0, 44,  218, 918, 174, 218, },        /* 7959B */
                     79:        { 1, 20,  0, 98,  117, 256, 98,  397, },        /* 7936H */
                     80:        { 1, 11,  0, 53,  63,  217, 53,  371, },        /* 7937H */
                     81: };
                     82: 
                     83: struct rdinfo {
                     84:        int     nbpc;
                     85:        int     hwid;
                     86:        int     *cyloff;
                     87: } rdinfo[] = {
                     88:        NRD7945ABPT*NRD7945ATRK, RD7946AID, rdcyloff[0],
                     89:        NRD9134DBPT*NRD9134DTRK, RD9134DID, rdcyloff[1],
                     90:        NRD9122SBPT*NRD9122STRK, RD9134LID, rdcyloff[2],
                     91:        NRD7912PBPT*NRD7912PTRK, RD7912PID, rdcyloff[3],
                     92:        NRD7914PBPT*NRD7914PTRK, RD7914PID, rdcyloff[4],
                     93:        NRD7958ABPT*NRD7958ATRK, RD7958AID, rdcyloff[8],
                     94:        NRD7957ABPT*NRD7957ATRK, RD7957AID, rdcyloff[7],
                     95:        NRD7933HBPT*NRD7933HTRK, RD7933HID, rdcyloff[5],
                     96:        NRD9134LBPT*NRD9134LTRK, RD9134LID, rdcyloff[6],
                     97:        NRD7936HBPT*NRD7936HTRK, RD7936HID, rdcyloff[12],
                     98:        NRD7937HBPT*NRD7937HTRK, RD7937HID, rdcyloff[13],
                     99:        NRD7914PBPT*NRD7914PTRK, RD7914CTID,rdcyloff[4],
                    100:        NRD7945ABPT*NRD7945ATRK, RD7946AID, rdcyloff[0],
                    101:        NRD9122SBPT*NRD9122STRK, RD9134LID, rdcyloff[2],
                    102:        NRD7957BBPT*NRD7957BTRK, RD7957BID, rdcyloff[9],
                    103:        NRD7958BBPT*NRD7958BTRK, RD7958BID, rdcyloff[10],
                    104:        NRD7959BBPT*NRD7959BTRK, RD7959BID, rdcyloff[11],
                    105: };
                    106: int    nrdinfo = sizeof(rdinfo) / sizeof(rdinfo[0]);
                    107:                                        
                    108: rdinit(unit)
                    109:        register int unit;
                    110: {
                    111:        register struct rd_softc *rs;
                    112:        u_char stat;
                    113: 
                    114:        if (unit > NRD)
                    115:                return (0);
                    116:        rs = &rd_softc[unit];
                    117:        rs->sc_type = rdident(unit);
                    118:        if (rs->sc_type < 0)
                    119:                return (0);
                    120:        rs->sc_alive = 1;
                    121:        return (1);
                    122: }
                    123: 
                    124: rdreset(unit)
                    125: {
                    126:        u_char stat;
                    127: 
                    128:        rd_ssmc.c_unit = C_SUNIT(0);
                    129:        rd_ssmc.c_cmd = C_SSM;
                    130:        rd_ssmc.c_refm = REF_MASK;
                    131:        rd_ssmc.c_fefm = FEF_MASK;
                    132:        rd_ssmc.c_aefm = AEF_MASK;
                    133:        rd_ssmc.c_iefm = IEF_MASK;
                    134:        hpibsend(unit, C_CMD, &rd_ssmc, sizeof(rd_ssmc));
                    135:        hpibswait(unit);
                    136:        hpibrecv(unit, C_QSTAT, &stat, 1);
                    137: }
                    138: 
                    139: rdident(unit)
                    140: {
                    141:        struct rd_describe desc;
                    142:        u_char stat, cmd[3];
                    143:        char name[7];
                    144:        register int id, i;
                    145: 
                    146:        id = hpibid(unit);
                    147:        if ((id & 0x200) == 0)
                    148:                return(-1);
                    149:        for (i = 0; i < nrdinfo; i++)
                    150:                if (id == rdinfo[i].hwid)
                    151:                        break;
                    152:        if (i == nrdinfo)
                    153:                return(-1);
                    154:        id = i;
                    155:        rdreset(unit);
                    156:        cmd[0] = C_SUNIT(0);
                    157:        cmd[1] = C_SVOL(0);
                    158:        cmd[2] = C_DESC;
                    159:        hpibsend(unit, C_CMD, cmd, sizeof(cmd));
                    160:        hpibrecv(unit, C_EXEC, &desc, 37);
                    161:        hpibrecv(unit, C_QSTAT, &stat, sizeof(stat));
                    162:        bzero(name, sizeof(name));
                    163:        if (!stat) {
                    164:                register int n = desc.d_name;
                    165:                for (i = 5; i >= 0; i--) {
                    166:                        name[i] = (n & 0xf) + '0';
                    167:                        n >>= 4;
                    168:                }
                    169:        }
                    170:        /*
                    171:         * Take care of a couple of anomolies:
                    172:         * 1. 7945A and 7946A both return same HW id
                    173:         * 2. 9122S and 9134D both return same HW id
                    174:         * 3. 9122D and 9134L both return same HW id
                    175:         */
                    176:        switch (rdinfo[id].hwid) {
                    177:        case RD7946AID:
                    178:                if (bcmp(name, "079450", 6) == 0)
                    179:                        id = RD7945A;
                    180:                else
                    181:                        id = RD7946A;
                    182:                break;
                    183: 
                    184:        case RD9134LID:
                    185:                if (bcmp(name, "091340", 6) == 0)
                    186:                        id = RD9134L;
                    187:                else
                    188:                        id = RD9122D;
                    189:                break;
                    190: 
                    191:        case RD9134DID:
                    192:                if (bcmp(name, "091220", 6) == 0)
                    193:                        id = RD9122S;
                    194:                else
                    195:                        id = RD9134D;
                    196:                break;
                    197:        }
                    198:        return(id);
                    199: }
                    200: 
                    201: rdopen(io)
                    202:        struct iob *io;
                    203: {
                    204:        register int unit = io->i_unit;
                    205:        register struct rd_softc *rs = &rd_softc[unit];
                    206:        struct rdinfo *ri;
                    207: 
                    208:        if (hpibalive(unit) == 0)
                    209:                _stop("rd controller not configured");
                    210:        if (rs->sc_alive == 0)
                    211:                if (rdinit(unit) == 0)
                    212:                        _stop("rd init failed");
                    213:        if (io->i_boff < 0 || io->i_boff > 7)
                    214:                _stop("rd bad minor");
                    215:        ri = &rdinfo[rs->sc_type];
                    216:        io->i_boff = ri->cyloff[io->i_boff] * ri->nbpc;
                    217: }
                    218: 
                    219: rdstrategy(io, func)
                    220:        register struct iob *io;
                    221:        register int func;
                    222: {
                    223:        register int unit = io->i_unit;
                    224:        register struct rd_softc *rs = &rd_softc[unit];
                    225:        char stat;
                    226: 
                    227:        rs->sc_retry = 0;
                    228:        rd_ioc.c_unit = C_SUNIT(0);
                    229:        rd_ioc.c_volume = C_SVOL(0);
                    230:        rd_ioc.c_saddr = C_SADDR;
                    231:        rd_ioc.c_hiaddr = 0;
                    232:        rd_ioc.c_addr = RDBTOS(io->i_bn);
                    233:        rd_ioc.c_nop2 = C_NOP;
                    234:        rd_ioc.c_slen = C_SLEN;
                    235:        rd_ioc.c_len = io->i_cc;
                    236:        rd_ioc.c_cmd = func == F_READ ? C_READ : C_WRITE;
                    237: retry:
                    238:        hpibsend(unit, C_CMD, &rd_ioc.c_unit, sizeof(rd_ioc)-2);
                    239:        hpibswait(unit);
                    240:        hpibgo(unit, C_EXEC, io->i_ma, io->i_cc, func);
                    241:        hpibswait(unit);
                    242:        hpibrecv(unit, C_QSTAT, &stat, 1);
                    243:        if (stat) {
                    244:                if (rderror(unit) == 0)
                    245:                        return(-1);
                    246:                if (++rs->sc_retry > RDRETRY)
                    247:                        return(-1);
                    248:                else
                    249:                        goto retry;
                    250:        }
                    251:        return(io->i_cc);
                    252: }
                    253: 
                    254: rderror(unit)
                    255:        register int unit;
                    256: {
                    257:        register struct rd_softc *rd = &rd_softc[unit];
                    258:        char stat;
                    259: 
                    260:        rd_rsc.c_unit = C_SUNIT(0);
                    261:        rd_rsc.c_sram = C_SRAM;
                    262:        rd_rsc.c_ram = C_RAM;
                    263:        rd_rsc.c_cmd = C_STATUS;
                    264:        hpibsend(unit, C_CMD, &rd_rsc, sizeof(rd_rsc));
                    265:        hpibrecv(unit, C_EXEC, &rd_stat, sizeof(rd_stat));
                    266:        hpibrecv(unit, C_QSTAT, &stat, 1);
                    267:        if (stat) {
                    268:                printf("rd(%d,?): request status fail %d\n", unit, stat);
                    269:                return(0);
                    270:        }
                    271:        printf("rd(%d,?) err: vu 0x%x", unit, rd_stat.c_vu);
                    272:        if ((rd_stat.c_aef & AEF_UD) || (rd_stat.c_ief & (IEF_MD|IEF_RD)))
                    273:                printf(", block %d", rd_stat.c_blk);
                    274:        printf(", R0x%x F0x%x A0x%x I0x%x\n",
                    275:               rd_stat.c_ref, rd_stat.c_fef, rd_stat.c_aef, rd_stat.c_ief);
                    276:        return(1);
                    277: }

unix.superglobalmegacorp.com

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