[BACK]Return to sd.c CVS log [TXT][DIR] Up to [local] / sys / arch / hp300 / stand / common

Annotation of sys/arch/hp300/stand/common/sd.c, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: sd.c,v 1.6 2006/08/17 06:31:10 miod Exp $     */
                      2: /*     $NetBSD: sd.c,v 1.9 1996/12/21 21:34:41 thorpej Exp $   */
                      3:
                      4: /*
                      5:  * Copyright (c) 1988 University of Utah.
                      6:  * Copyright (c) 1990, 1993
                      7:  *     The Regents of the University of California.  All rights reserved.
                      8:  *
                      9:  * This code is derived from software contributed to Berkeley by
                     10:  * Van Jacobson of Lawrence Berkeley Laboratory and the Systems
                     11:  * Programming Group of the University of Utah Computer Science Department.
                     12:  *
                     13:  * Redistribution and use in source and binary forms, with or without
                     14:  * modification, are permitted provided that the following conditions
                     15:  * are met:
                     16:  * 1. Redistributions of source code must retain the above copyright
                     17:  *    notice, this list of conditions and the following disclaimer.
                     18:  * 2. Redistributions in binary form must reproduce the above copyright
                     19:  *    notice, this list of conditions and the following disclaimer in the
                     20:  *    documentation and/or other materials provided with the distribution.
                     21:  * 3. Neither the name of the University nor the names of its contributors
                     22:  *    may be used to endorse or promote products derived from this software
                     23:  *    without specific prior written permission.
                     24:  *
                     25:  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
                     26:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
                     27:  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
                     28:  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
                     29:  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
                     30:  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
                     31:  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     32:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     33:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     34:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     35:  * SUCH DAMAGE.
                     36:  *
                     37:  * from: Utah $Hdr: sd.c 1.9 92/12/21$
                     38:  *
                     39:  *     @(#)sd.c        8.1 (Berkeley) 6/10/93
                     40:  */
                     41:
                     42: /*
                     43:  * SCSI CCS disk driver
                     44:  */
                     45:
                     46: #include <sys/param.h>
                     47: #include <sys/disklabel.h>
                     48:
                     49: #include <lib/libsa/stand.h>
                     50:
                     51: #include "samachdep.h"
                     52: #include "scsireg.h"
                     53:
                     54: struct disklabel sdlabel;
                     55:
                     56: struct sdminilabel {
                     57:        u_short npart;
                     58:        u_long  offset[MAXPARTITIONS];
                     59: };
                     60:
                     61: struct sd_softc {
                     62:        int     sc_ctlr;
                     63:        int     sc_unit;
                     64:        int     sc_part;
                     65:        char    sc_retry;
                     66:        char    sc_alive;
                     67:        short   sc_blkshift;
                     68:        struct  sdminilabel sc_pinfo;
                     69: } sd_softc[NSCSI][NSD];
                     70:
                     71: #define        SDRETRY         2
                     72:
                     73: int    sdclose(struct open_file *);
                     74: int    sdgetinfo(struct sd_softc *);
                     75: int    sdinit(int, int);
                     76: int    sdopen(struct open_file *, int, int, int);
                     77: void   sdreset(int, int);
                     78: int    sdstrategy(struct sd_softc *, int, daddr_t, size_t, void *, size_t *);
                     79:
                     80: int
                     81: sdinit(int ctlr, int unit)
                     82: {
                     83:        struct sd_softc *ss = &sd_softc[ctlr][unit];
                     84:        u_char stat;
                     85:        int capbuf[2];
                     86:
                     87:        stat = scsi_test_unit_rdy(ctlr, unit);
                     88:        if (stat) {
                     89:                /* drive may be doing RTZ - wait a bit */
                     90:                if (stat == STS_CHECKCOND) {
                     91:                        DELAY(1000000);
                     92:                        stat = scsi_test_unit_rdy(ctlr, unit);
                     93:                }
                     94:                if (stat) {
                     95:                        printf("sd(%d,%d,0,0): init failed (stat=%x)\n",
                     96:                               ctlr, unit, stat);
                     97:                        return (0);
                     98:                }
                     99:        }
                    100:        /*
                    101:         * try to get the drive block size.
                    102:         */
                    103:        capbuf[0] = 0;
                    104:        capbuf[1] = 0;
                    105:        stat = scsi_read_capacity(ctlr, unit,
                    106:                                  (u_char *)capbuf, sizeof(capbuf));
                    107:        if (stat == 0) {
                    108:                if (capbuf[1] > DEV_BSIZE)
                    109:                        for (; capbuf[1] > DEV_BSIZE; capbuf[1] >>= 1)
                    110:                                ++ss->sc_blkshift;
                    111:        }
                    112:        ss->sc_alive = 1;
                    113:        return (1);
                    114: }
                    115:
                    116: void
                    117: sdreset(int ctlr, int unit)
                    118: {
                    119: }
                    120:
                    121: char io_buf[MAXBSIZE];
                    122:
                    123: int
                    124: sdgetinfo(struct sd_softc *ss)
                    125: {
                    126:        struct sdminilabel *pi = &ss->sc_pinfo;
                    127:        struct disklabel *lp = &sdlabel;
                    128:        char *msg;
                    129:        int err, savepart;
                    130:        size_t i;
                    131:
                    132:        bzero((caddr_t)lp, sizeof *lp);
                    133:        lp->d_secsize = (DEV_BSIZE << ss->sc_blkshift);
                    134:
                    135:        /* Disklabel is always from RAW_PART. */
                    136:        savepart = ss->sc_part;
                    137:        ss->sc_part = RAW_PART;
                    138:        err = sdstrategy(ss, F_READ, LABELSECTOR,
                    139:            lp->d_secsize ? lp->d_secsize : DEV_BSIZE, io_buf, &i);
                    140:        ss->sc_part = savepart;
                    141:
                    142:        if (err) {
                    143:                printf("sdgetinfo: sdstrategy error %d\n", err);
                    144:                return(0);
                    145:        }
                    146:
                    147:        msg = getdisklabel(io_buf, lp);
                    148:        if (msg) {
                    149:                printf("sd(%d,%d,%d): WARNING: %s, ",
                    150:                       ss->sc_ctlr, ss->sc_unit, ss->sc_part, msg);
                    151:                printf("defining `c' partition as entire disk\n");
                    152:                pi->npart = 3;
                    153: #ifdef CD9660_DUMMYLABEL
                    154:                pi->offset[0] = 0;
                    155:                lp->d_partitions[0].p_fstype = FS_ISO9660; /* just for kicks */
                    156: #else
                    157:                pi->offset[0] = -1;
                    158: #endif
                    159:                pi->offset[1] = -1;
                    160:                pi->offset[2] = 0;
                    161:        } else {
                    162:                pi->npart = lp->d_npartitions;
                    163:                for (i = 0; i < pi->npart; i++)
                    164:                        pi->offset[i] = lp->d_partitions[i].p_size == 0 ?
                    165:                                -1 : lp->d_partitions[i].p_offset;
                    166:        }
                    167:        return(1);
                    168: }
                    169:
                    170: int
                    171: sdopen(struct open_file *f, int ctlr, int unit, int part)
                    172: {
                    173:        struct sd_softc *ss;
                    174:
                    175: #ifdef SD_DEBUG
                    176:        if (debug)
                    177:        printf("sdopen: ctlr=%d unit=%d part=%d\n",
                    178:            ctlr, unit, part);
                    179: #endif
                    180:
                    181:        if (ctlr >= NSCSI || scsialive(ctlr) == 0)
                    182:                return (EADAPT);
                    183:        if (unit >= NSD)
                    184:                return (ECTLR);
                    185:        ss = &sd_softc[ctlr][unit];
                    186:        ss->sc_part = part;
                    187:        ss->sc_unit = unit;
                    188:        ss->sc_ctlr = ctlr;
                    189:        if (ss->sc_alive == 0) {
                    190:                if (sdinit(ctlr, unit) == 0)
                    191:                        return (ENXIO);
                    192:                if (sdgetinfo(ss) == 0)
                    193:                        return (ERDLAB);
                    194:        }
                    195:        if (part != RAW_PART &&     /* always allow RAW_PART to be opened */
                    196:            (part >= ss->sc_pinfo.npart || ss->sc_pinfo.offset[part] == -1))
                    197:                return (EPART);
                    198:        f->f_devdata = (void *)ss;
                    199:        return (0);
                    200: }
                    201:
                    202: int
                    203: sdclose(struct open_file *f)
                    204: {
                    205:        struct sd_softc *ss = f->f_devdata;
                    206:
                    207:        /*
                    208:         * Mark the disk `not alive' so that the disklabel
                    209:         * will be re-loaded at next open.
                    210:         */
                    211:        bzero(ss, sizeof(sd_softc));
                    212:        f->f_devdata = NULL;
                    213:
                    214:        return (0);
                    215: }
                    216:
                    217: int
                    218: sdstrategy(struct sd_softc *ss, int func, daddr_t dblk, size_t size,
                    219:     void *v_buf, size_t *rsize)
                    220: {
                    221:        char *buf = v_buf;
                    222:        int ctlr = ss->sc_ctlr;
                    223:        int unit = ss->sc_unit;
                    224:        u_int nblk = size >> ss->sc_blkshift;
                    225:        daddr_t blk;
                    226:        char stat;
                    227:
                    228:        if (size == 0)
                    229:                return(0);
                    230:
                    231:        /*
                    232:         * Don't do partition translation on the `raw partition'.
                    233:         */
                    234:        blk = (dblk + ((ss->sc_part == RAW_PART) ? 0 :
                    235:            ss->sc_pinfo.offset[ss->sc_part])) >> ss->sc_blkshift;
                    236:
                    237:        ss->sc_retry = 0;
                    238:
                    239: #ifdef SD_DEBUG
                    240:        if (debug)
                    241:        printf("sdstrategy(%d,%d): size=%d blk=%d nblk=%d\n",
                    242:            ctlr, unit, size, blk, nblk);
                    243: #endif
                    244:
                    245: retry:
                    246:        if (func == F_READ)
                    247:                stat = scsi_tt_read(ctlr, unit, buf, size, blk, nblk);
                    248:        else
                    249:                stat = scsi_tt_write(ctlr, unit, buf, size, blk, nblk);
                    250:        if (stat) {
                    251:                printf("sd(%d,%d,%d): block=%x, error=0x%x\n",
                    252:                       ctlr, unit, ss->sc_part, blk, stat);
                    253:                if (++ss->sc_retry > SDRETRY)
                    254:                        return(EIO);
                    255:                goto retry;
                    256:        }
                    257:        *rsize = size;
                    258:
                    259:        return(0);
                    260: }

CVSweb