123225Smckusick /* 233409Skarels * Copyright (c) 1982, 1986 Regents of the University of California. 323225Smckusick * All rights reserved. The Berkeley software License Agreement 423225Smckusick * specifies the terms and conditions for redistribution. 523225Smckusick * 6*33547Sbostic * @(#)hp.c 7.7 (Berkeley) 02/24/88 723225Smckusick */ 810334Shelge 910334Shelge /* 1033545Sbostic * RP??/RM?? disk driver with ECC handling and bad block forwarding. 1133545Sbostic * Also supports header io operations and commands to write check 1233545Sbostic * header and data. 1310334Shelge */ 1433409Skarels #include "param.h" 1533409Skarels #include "inode.h" 1633409Skarels #include "fs.h" 1733409Skarels #include "dkbad.h" 1833409Skarels #include "disklabel.h" 1910334Shelge 2010334Shelge #include "../vax/pte.h" 2133409Skarels 2210334Shelge #include "../vaxmba/hpreg.h" 2310334Shelge #include "../vaxmba/mbareg.h" 2410334Shelge 2510334Shelge #include "saio.h" 2610334Shelge #include "savax.h" 2710334Shelge 2825439Skarels #define RETRIES 27 2925439Skarels 3010334Shelge #define MASKREG(reg) ((reg)&0xffff) 3110334Shelge 3211366Ssam #define MAXBADDESC 126 3311366Ssam #define SECTSIZ 512 /* sector size in bytes */ 3411366Ssam #define HDRSIZ 4 /* number of bytes in sector header */ 3510334Shelge 3630547Skarels char lbuf[SECTSIZ]; 3710334Shelge 3830547Skarels #define RP06(type) ((type) == MBDT_RP06 || (type) == MBDT_RP05 \ 3930547Skarels || (type) == MBDT_RP04) 4030547Skarels #define ML11(type) ((type) == MBDT_ML11A) 4130547Skarels #define RM80(type) ((type) == MBDT_RM80) 4210334Shelge 4310334Shelge u_char hp_offset[16] = { 4433545Sbostic HPOF_P400, HPOF_M400, HPOF_P400, HPOF_M400, 4533545Sbostic HPOF_P800, HPOF_M800, HPOF_P800, HPOF_M800, 4633545Sbostic HPOF_P1200, HPOF_M1200, HPOF_P1200, HPOF_M1200, 4733545Sbostic 0, 0, 0, 0, 4810334Shelge }; 4910334Shelge 5033545Sbostic #define MAXUNIT 8 5133545Sbostic struct disklabel hplabel[MAXNMBA][MAXUNIT]; 5230547Skarels #ifndef SMALL 5333545Sbostic struct dkbad hpbad[MAXNMBA][MAXUNIT]; 5430547Skarels int sectsiz; 5530547Skarels #endif 5610334Shelge 5725439Skarels struct hp_softc { 5825439Skarels char type; 5925439Skarels char gottype; 6033545Sbostic char ssect; /* 1 when on track w/skip sector */ 6125439Skarels char debug; 6225439Skarels # define HPF_BSEDEBUG 01 /* debugging bad sector forwarding */ 6325439Skarels # define HPF_ECCDEBUG 02 /* debugging ecc correction */ 6425439Skarels int ecclim; 6525439Skarels int retries; 6633545Sbostic } hp_softc[MAXNMBA][MAXUNIT]; 6711366Ssam 6810864Ssam /* 6933545Sbostic * When awaiting command completion, don't hang on to the status register 7033545Sbostic * since this ties up some controllers. 7110864Ssam */ 7211366Ssam #define HPWAIT(addr) \ 7333545Sbostic while ((((addr)->hpds)&HPDS_DRY) == 0) \ 7433545Sbostic DELAY(500); 7510864Ssam 7610334Shelge hpopen(io) 7710334Shelge register struct iob *io; 7810334Shelge { 7910334Shelge register unit = io->i_unit; 8033545Sbostic register struct hp_softc *sc; 8133545Sbostic register struct disklabel *lp; 8233545Sbostic struct hpdevice *hpaddr; 8333041Skarels struct disklabel *dlp; 8410334Shelge 8533545Sbostic if ((u_int)io->i_adapt >= MAXNMBA || !mbainit(io->i_adapt)) 8633545Sbostic return (EADAPT); 8733545Sbostic if ((u_int)io->i_ctlr) 8833545Sbostic return (ECTLR); 8933545Sbostic if ((u_int)unit >= MAXUNIT) 9033545Sbostic return (EUNIT); 9133545Sbostic hpaddr = (struct hpdevice *)mbadrv(io->i_adapt, unit); 9233545Sbostic sc = &hp_softc[io->i_adapt][unit]; 9333545Sbostic lp = &hplabel[io->i_adapt][unit]; 9425439Skarels if (sc->gottype == 0) { 9533545Sbostic register int i; 9610334Shelge struct iob tio; 9710334Shelge 9830547Skarels #ifndef SMALL 9925439Skarels sc->retries = RETRIES; 10025439Skarels sc->ecclim = 11; 10125439Skarels sc->debug = 0; 10230547Skarels #endif 10310647Shelge hpaddr->hpcs1 = HP_DCLR|HP_GO; /* init drive */ 10410647Shelge hpaddr->hpcs1 = HP_PRESET|HP_GO; 10530547Skarels #ifndef SMALL 106*33547Sbostic if ((hpaddr->hpds & HPDS_DPR) == 0) 10733409Skarels return (ENXIO); 10830547Skarels sc->type = hpaddr->hpdt & MBDT_TYPE; 10930547Skarels if (sc->type == MBDT_ML11B) 11033409Skarels sc->type = MBDT_ML11A; 11130547Skarels if (!ML11(sc->type)) 11230547Skarels #endif 11310647Shelge hpaddr->hpof = HPOF_FMT22; 11410334Shelge /* 11530547Skarels * Read in the pack label. 11630547Skarels */ 11730547Skarels lp->d_nsectors = 32; 11830547Skarels lp->d_secpercyl = 20*32; 11930547Skarels tio = *io; 12030547Skarels tio.i_bn = LABELSECTOR; 12130547Skarels tio.i_ma = lbuf; 12230547Skarels tio.i_cc = SECTSIZ; 12330547Skarels tio.i_flgs |= F_RDDATA; 12430547Skarels if (hpstrategy(&tio, READ) != SECTSIZ) { 12533545Sbostic printf("hp: can't read disk label\n"); 12630547Skarels return (EIO); 12730547Skarels } 12833041Skarels dlp = (struct disklabel *)(lbuf + LABELOFFSET); 12933041Skarels if (dlp->d_magic != DISKMAGIC || dlp->d_magic2 != DISKMAGIC) { 13030547Skarels printf("hp%d: unlabeled\n", unit); 13133409Skarels #if defined(COMPAT_42) /* && !defined(SMALL) */ 13233545Sbostic hpmaptype(hpaddr, hpaddr->hpdt & MBDT_TYPE, unit, lp); 13330547Skarels #else 13430547Skarels return (ENXIO); 13530547Skarels #endif 13633041Skarels } else 13733041Skarels *lp = *dlp; 13833041Skarels #ifndef SMALL 13930547Skarels /* 14011366Ssam * Read in the bad sector table. 14110334Shelge */ 14230547Skarels tio.i_bn = lp->d_secpercyl * lp->d_ncylinders - lp->d_nsectors; 14333545Sbostic tio.i_ma = (char *)&hpbad[io->i_adapt][unit]; 14433545Sbostic tio.i_cc = sizeof(struct dkbad); 14510334Shelge for (i = 0; i < 5; i++) { 14633545Sbostic if (hpstrategy(&tio, READ) == sizeof(struct dkbad)) 14710334Shelge break; 14810334Shelge tio.i_bn += 2; 14910334Shelge } 15010334Shelge if (i == 5) { 15133545Sbostic printf("hp: can't read bad sector table\n"); 15210334Shelge for (i = 0; i < MAXBADDESC; i++) { 15333545Sbostic hpbad[io->i_adapt][unit].bt_bad[i].bt_cyl = -1; 15433545Sbostic hpbad[io->i_adapt][unit].bt_bad[i].bt_trksec = -1; 15510334Shelge } 15625439Skarels } 15733041Skarels #endif 15825439Skarels sc->gottype = 1; 15910334Shelge } 16033545Sbostic if (io->i_part >= lp->d_npartitions || 16133545Sbostic lp->d_partitions[io->i_part].p_size == 0) 16233545Sbostic return (EPART); 16333545Sbostic io->i_boff = lp->d_partitions[io->i_part].p_offset; 16430547Skarels return (0); 16510334Shelge } 16610334Shelge 16710334Shelge hpstrategy(io, func) 16810334Shelge register struct iob *io; 16910334Shelge { 17033545Sbostic register int unit = io->i_unit; 17133545Sbostic register struct hp_softc *sc; 17233545Sbostic register struct disklabel *lp; 17333545Sbostic struct mba_regs *mba; 17433545Sbostic struct hpdevice *hpaddr; 17511366Ssam daddr_t bn, startblock; 17633409Skarels int cn, tn, sn, bytecnt, bytesleft, rv; 17733545Sbostic int er1, er2, hprecal; 17810334Shelge char *membase; 17910334Shelge 18033545Sbostic mba = mbamba(io->i_adapt); 18133545Sbostic hpaddr = (struct hpdevice *)mbadrv(io->i_adapt, unit); 18233545Sbostic sc = &hp_softc[io->i_adapt][unit]; 18333545Sbostic lp = &hplabel[io->i_adapt][unit]; 18430547Skarels #ifndef SMALL 18510334Shelge sectsiz = SECTSIZ; 18610334Shelge if ((io->i_flgs & (F_HDR|F_HCHECK)) != 0) 18710334Shelge sectsiz += HDRSIZ; 18810334Shelge if ((hpaddr->hpds & HPDS_VV) == 0) { 18910334Shelge hpaddr->hpcs1 = HP_DCLR|HP_GO; 19010334Shelge hpaddr->hpcs1 = HP_PRESET|HP_GO; 19130547Skarels if (!ML11(sc->type)) 19210334Shelge hpaddr->hpof = HPOF_FMT22; 19310334Shelge } 19410334Shelge io->i_errcnt = 0; 19525439Skarels sc->ssect = 0; 19625439Skarels rv = bytecnt = io->i_cc; 19710334Shelge membase = io->i_ma; 19810334Shelge startblock = io->i_bn; 19910608Ssam hprecal = 0; 20030547Skarels #endif 20111140Ssam 20210626Shelge restart: 20310334Shelge bn = io->i_bn; 20430547Skarels cn = bn / lp->d_secpercyl; 20530547Skarels sn = bn % lp->d_secpercyl; 20630547Skarels tn = sn / lp->d_nsectors; 20730547Skarels sn = sn % lp->d_nsectors + sc->ssect; 20810334Shelge 20910864Ssam HPWAIT(hpaddr); 21010626Shelge mba->mba_sr = -1; 21130547Skarels if (ML11(sc->type)) 21210334Shelge hpaddr->hpda = bn; 21310334Shelge else { 21410334Shelge hpaddr->hpdc = cn; 21510334Shelge hpaddr->hpda = (tn << 8) + sn; 21610334Shelge } 21730547Skarels #ifdef SMALL 21833545Sbostic mbastart(io, io->i_unit, func); /* start transfer */ 21930547Skarels HPWAIT(hpaddr); 22030547Skarels if (hpaddr->hpds & HPDS_ERR) { 22130547Skarels printf("hp error: sn [%d-%d) ds=%b er1=%b\n", 22230547Skarels bn, bn + io->i_cc/SECTSIZ, MASKREG(hpaddr->hpds), HPDS_BITS, 22330547Skarels MASKREG(hpaddr->hper1), HPER1_BITS); 22430547Skarels return (-1); 22530547Skarels } 22630547Skarels return (io->i_cc); 22730547Skarels #else 22833545Sbostic if (mbastart(io, io->i_unit, func) != 0) { /* start transfer */ 22925439Skarels rv = -1; 23025439Skarels goto done; 23125439Skarels } 23210864Ssam HPWAIT(hpaddr); 23311366Ssam /* 23411366Ssam * Successful data transfer, return. 23511366Ssam */ 23615068Skarels if ((hpaddr->hpds&HPDS_ERR) == 0 && (mba->mba_sr&MBSR_EBITS) == 0) 23715068Skarels goto done; 23810334Shelge 23911366Ssam /* 24011366Ssam * Error handling. Calculate location of error. 24111366Ssam */ 24211366Ssam bytesleft = MASKREG(mba->mba_bcr); 24311366Ssam if (bytesleft) 24411366Ssam bytesleft |= 0xffff0000; /* sxt */ 24511366Ssam bn = io->i_bn + (io->i_cc + bytesleft) / sectsiz; 24615052Skarels er1 = MASKREG(hpaddr->hper1); 24715052Skarels er2 = MASKREG(hpaddr->hper2); 24815052Skarels if (er1 & (HPER1_DCK|HPER1_ECH)) 24915052Skarels bn--; /* Error is in Prev block */ 25030547Skarels cn = bn/lp->d_secpercyl; 25130547Skarels sn = bn%lp->d_secpercyl; 25230547Skarels tn = sn/lp->d_nsectors; 25330547Skarels sn = sn%lp->d_nsectors; 25425439Skarels if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG)) { 25525439Skarels printf("hp error: sn%d (cyl,trk,sec)=(%d,%d,%d) ds=%b\n", 25625439Skarels bn, cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS); 25711366Ssam printf("er1=%b er2=%b\n", er1, HPER1_BITS, er2, HPER2_BITS); 25811366Ssam printf("bytes left: %d, of 0x%x, da 0x%x\n",-bytesleft, 25911366Ssam hpaddr->hpof, hpaddr->hpda); 26011366Ssam } 26110334Shelge if (er1 & HPER1_HCRC) { 26210334Shelge er1 &= ~(HPER1_HCE|HPER1_FER); 26310334Shelge er2 &= ~HPER2_BSE; 26425439Skarels if ((io->i_flgs&F_NBSF) == 0 && hpecc(io, BSE) == 0) 26525439Skarels goto success; 26610334Shelge } 26711140Ssam /* 26811140Ssam * Give up early if drive write locked. 26911140Ssam */ 27010334Shelge if (er1&HPER1_WLE) { 27110334Shelge printf("hp%d: write locked\n", unit); 27225439Skarels rv = -1; 27325439Skarels goto done; 27411084Ssam } 27511140Ssam /* 27625439Skarels * Skip sector handling. 27711140Ssam */ 27830547Skarels if (RM80(sc->type) && (er2 & HPER2_SSE)) { 27925439Skarels (void) hpecc(io, SSE); 28025439Skarels sc->ssect = 1; 28125439Skarels goto restart; 28211084Ssam } 28311140Ssam /* 28425439Skarels * Attempt to forward bad sectors on anything but an ML11. 28525439Skarels * Interpret format error bit as a bad block on RP06's. 28611140Ssam */ 28730547Skarels if (((er2 & HPER2_BSE) && !ML11(sc->type)) || 28830547Skarels (MASKREG(er1) == HPER1_FER && RP06(sc->type))) { 28911084Ssam if (io->i_flgs & F_NBSF) { 29033545Sbostic io->i_error = EBSE; 29110334Shelge goto hard; 29210334Shelge } 29310334Shelge if (hpecc(io, BSE) == 0) 29410334Shelge goto success; 29511084Ssam io->i_error = EBSE; 29611084Ssam goto hard; 29711084Ssam } 29811140Ssam /* 29911366Ssam * ECC correction? 30011140Ssam */ 30111084Ssam if ((er1 & (HPER1_DCK|HPER1_ECH)) == HPER1_DCK) { 30210864Ssam if (hpecc(io, ECC) == 0) 30310334Shelge goto success; 30411084Ssam io->i_error = EECC; 30525439Skarels goto hard; 30610608Ssam } 30725439Skarels 30825439Skarels /* 30925439Skarels * If a hard error, or maximum retry count 31025439Skarels * exceeded, clear controller state and 31125439Skarels * pass back error to caller. 31225439Skarels */ 31325439Skarels if (++io->i_errcnt > sc->retries || (er1 & HPER1_HARD) || 31430547Skarels (!ML11(sc->type) && (er2 & HPER2_HARD)) || 31530547Skarels (ML11(sc->type) && (io->i_errcnt >= 16))) { 31625439Skarels io->i_error = EHER; 31725439Skarels if (mba->mba_sr & (MBSR_WCKUP|MBSR_WCKLWR)) 31825439Skarels io->i_error = EWCK; 31925439Skarels hard: 32025439Skarels io->i_errblk = bn + sc->ssect; 32125439Skarels if (sc->debug & (HPF_BSEDEBUG|HPF_ECCDEBUG)) 32225439Skarels printf(" dc=%d, da=0x%x",MASKREG(hpaddr->hpdc), 32325439Skarels MASKREG(hpaddr->hpda)); 32425439Skarels else { 32525439Skarels printf("hp error: sn%d (cyl,trk,sec)=(%d,%d,%d) ds=%b \n", 32625439Skarels bn, cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS); 32725439Skarels printf("er1=%b er2=%b", er1, HPER1_BITS, er2, HPER2_BITS); 32825439Skarels } 32925439Skarels hpaddr->hpcs1 = HP_DCLR|HP_GO; 33025439Skarels printf("\n"); 33125439Skarels rv = -1; 33225439Skarels goto done; 33325439Skarels 33425439Skarels } 33510608Ssam /* fall thru to retry */ 33610334Shelge hpaddr->hpcs1 = HP_DCLR|HP_GO; 33710864Ssam HPWAIT(hpaddr); 33811140Ssam 33911140Ssam /* 34011140Ssam * Every fourth retry recalibrate. 34111140Ssam */ 34211366Ssam if (((io->i_errcnt & 07) == 4) ) { 34310334Shelge hpaddr->hpcs1 = HP_RECAL|HP_GO; 34415052Skarels HPWAIT(hpaddr); 34510334Shelge hpaddr->hpdc = cn; 34610334Shelge hpaddr->hpcs1 = HP_SEEK|HP_GO; 34715052Skarels HPWAIT(hpaddr); 34815052Skarels } 34910864Ssam 35015052Skarels if (io->i_errcnt >= 16 && (io->i_flgs & F_READ)) { 35110334Shelge hpaddr->hpof = hp_offset[io->i_errcnt & 017]|HPOF_FMT22; 35210334Shelge hpaddr->hpcs1 = HP_OFFSET|HP_GO; 35315052Skarels HPWAIT(hpaddr); 35410334Shelge } 35525439Skarels if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG)) 35615052Skarels printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n", 35715052Skarels io->i_bn, io->i_cc, io->i_ma, hprecal); 35825439Skarels goto restart; 35911084Ssam 36011140Ssam success: 36111140Ssam /* 36211140Ssam * On successful error recovery, bump 36311140Ssam * block number to advance to next portion 36411140Ssam * of i/o transfer. 36511140Ssam */ 36610334Shelge bn++; 36710334Shelge if ((bn-startblock) * sectsiz < bytecnt) { 36810334Shelge io->i_bn = bn; 36910334Shelge io->i_ma = membase + (io->i_bn - startblock)*sectsiz; 37010334Shelge io->i_cc = bytecnt - (io->i_bn - startblock)*sectsiz; 37125439Skarels if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG)) 37211366Ssam printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n", 37311366Ssam io->i_bn, io->i_cc, io->i_ma, hprecal); 37410626Shelge goto restart; 37510334Shelge } 37615068Skarels done: 37715052Skarels if (io->i_errcnt >= 16) { 37815052Skarels hpaddr->hpcs1 = HP_RTC|HP_GO; 37915052Skarels while (hpaddr->hpds & HPDS_PIP) 38015052Skarels ; 38115052Skarels } 38225439Skarels io->i_bn = startblock; /*reset i_bn to original */ 38318515Smiriam io->i_cc = bytecnt; /*reset i_cc to total count xfered*/ 38425439Skarels io->i_ma = membase; /*reset i_ma to original */ 38525439Skarels return (rv); 38630547Skarels #endif 38710334Shelge } 38810864Ssam 38930547Skarels #ifndef SMALL 39010334Shelge hpecc(io, flag) 39110334Shelge register struct iob *io; 39210334Shelge int flag; 39310334Shelge { 39433545Sbostic register int unit = io->i_unit; 39533545Sbostic register struct mba_regs *mbp; 39633545Sbostic register struct hpdevice *rp; 39733545Sbostic register struct hp_softc *sc; 39833545Sbostic register struct disklabel *lp; 39911084Ssam int npf, bn, cn, tn, sn, bcr; 40010334Shelge 40133545Sbostic mbp = mbamba(io->i_adapt); 40233545Sbostic rp = (struct hpdevice *)mbadrv(io->i_adapt, unit); 40333545Sbostic sc = &hp_softc[io->i_adapt][unit]; 40433545Sbostic lp = &hplabel[io->i_adapt][unit]; 40511366Ssam bcr = MASKREG(mbp->mba_bcr); 40611366Ssam if (bcr) 40711366Ssam bcr |= 0xffff0000; /* sxt */ 40811084Ssam npf = (bcr + io->i_cc) / sectsiz; /* # sectors read */ 40915052Skarels if (flag == ECC) 41015052Skarels npf--; /* Error is in prev block --ghg */ 41125439Skarels bn = io->i_bn + npf + sc->ssect; /* physical block #*/ 41225439Skarels if (sc->debug & HPF_ECCDEBUG) 41311366Ssam printf("bcr=%d npf=%d ssect=%d sectsiz=%d i_cc=%d\n", 41425439Skarels bcr, npf, sc->ssect, sectsiz, io->i_cc); 41511140Ssam /* 41611140Ssam * ECC correction logic. 41711140Ssam */ 41811140Ssam if (flag == ECC) { 41910334Shelge register int i; 42010334Shelge caddr_t addr; 42125439Skarels int bit, o, mask; 42210334Shelge 42310413Shelge printf("hp%d: soft ecc sn%d\n", unit, bn); 42410334Shelge mask = MASKREG(rp->hpec2); 42525439Skarels for (i = mask, bit = 0; i; i >>= 1) 42625439Skarels if (i & 1) 42725439Skarels bit++; 42825439Skarels if (bit > sc->ecclim) { 42925439Skarels printf("%d-bit error\n", bit); 43025439Skarels return (1); 43125439Skarels } 43211084Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 43310334Shelge bit = i&07; 43411366Ssam o = (i & ~07) >> 3; 43510334Shelge rp->hpcs1 = HP_DCLR | HP_GO; 43611179Ssam while (o <sectsiz && npf*sectsiz + o < io->i_cc && bit > -11) { 43711179Ssam addr = io->i_ma + (npf*sectsiz) + o; 43811179Ssam /* 43911179Ssam * No data transfer occurs with a write check, 44011179Ssam * so don't correct the resident copy of data. 44111179Ssam */ 44211366Ssam if ((io->i_flgs & (F_CHECK|F_HCHECK)) == 0) { 44325439Skarels if (sc->debug & HPF_ECCDEBUG) 44411366Ssam printf("addr=%x old=%x ", addr, 44511366Ssam (*addr & 0xff)); 44611140Ssam *addr ^= (mask << bit); 44725439Skarels if (sc->debug & HPF_ECCDEBUG) 44811366Ssam printf("new=%x\n",(*addr & 0xff)); 44911366Ssam } 45011179Ssam o++, bit -= 8; 45110334Shelge } 45211179Ssam return (0); 45311084Ssam } 45410334Shelge 45511084Ssam /* 45611084Ssam * Skip sector error. 45711084Ssam * Set skip-sector-inhibit and 45811084Ssam * read next sector 45911084Ssam */ 46011140Ssam if (flag == SSE) { 46110334Shelge rp->hpcs1 = HP_DCLR | HP_GO; 46210864Ssam HPWAIT(rp); 46310334Shelge rp->hpof |= HPOF_SSEI; 46433545Sbostic return (0); 46511140Ssam } 46610334Shelge 46711140Ssam /* 46811140Ssam * Bad block forwarding. 46911140Ssam */ 47011140Ssam if (flag == BSE) { 47110626Shelge int bbn; 47211084Ssam 47310626Shelge rp->hpcs1 = HP_DCLR | HP_GO; 47425439Skarels if (sc->debug & HPF_BSEDEBUG) 47511366Ssam printf("hpecc: BSE @ bn %d\n", bn); 47630547Skarels cn = bn / lp->d_secpercyl; 47730547Skarels sn = bn % lp->d_secpercyl; 47830547Skarels tn = sn / lp->d_nsectors; 47930547Skarels sn = sn % lp->d_nsectors; 48010626Shelge bcr += sectsiz; 48133545Sbostic if ((bbn = isbad(&hpbad[io->i_adapt][unit], cn, tn, sn)) < 0) 48211084Ssam return (1); 48330547Skarels bbn = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors - 1 48430547Skarels - bbn; 48530547Skarels cn = bbn / lp->d_secpercyl; 48630547Skarels sn = bbn % lp->d_secpercyl; 48730547Skarels tn = sn / lp->d_nsectors; 48833409Skarels sn = sn % lp->d_nsectors; 48910626Shelge io->i_cc = sectsiz; 49030547Skarels io->i_ma += npf * sectsiz; 49125439Skarels if (sc->debug & HPF_BSEDEBUG) 49211366Ssam printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 49311366Ssam rp->hpof &= ~HPOF_SSEI; 49410626Shelge mbp->mba_sr = -1; 49510334Shelge rp->hpdc = cn; 49610334Shelge rp->hpda = (tn<<8) + sn; 49733545Sbostic mbastart(io, io->i_unit, io->i_flgs); 49811366Ssam io->i_errcnt = 0; 49910864Ssam HPWAIT(rp); 50010864Ssam return (rp->hpds&HPDS_ERR); 50110334Shelge } 50211084Ssam printf("hpecc: flag=%d\n", flag); 50311084Ssam return (1); 50410334Shelge } 50511140Ssam 50610334Shelge /*ARGSUSED*/ 50710334Shelge hpioctl(io, cmd, arg) 50810334Shelge struct iob *io; 50910334Shelge int cmd; 51010334Shelge caddr_t arg; 51110334Shelge { 51210647Shelge register unit = io->i_unit; 51333545Sbostic register struct hp_softc *sc = &hp_softc[io->i_adapt][unit]; 51433545Sbostic register struct disklabel *lp = &hplabel[io->i_adapt][unit]; 51533545Sbostic struct mba_drv *drv = mbadrv(io->i_adapt, unit); 51610334Shelge 51710334Shelge switch(cmd) { 51810334Shelge 51911366Ssam case SAIODEBUG: 52025439Skarels sc->debug = (int)arg; 52125439Skarels break; 52211366Ssam 52310334Shelge case SAIODEVDATA: 52425439Skarels if (drv->mbd_dt&MBDT_TAP) 52525439Skarels return (ECMD); 52630547Skarels *(struct disklabel *)arg = *lp; 52725439Skarels break; 52810334Shelge 52925439Skarels case SAIOGBADINFO: 53025439Skarels if (drv->mbd_dt&MBDT_TAP) 53125439Skarels return (ECMD); 53233545Sbostic *(struct dkbad *)arg = hpbad[io->i_adapt][unit]; 53325439Skarels break; 53425439Skarels 53525439Skarels case SAIOECCLIM: 53625439Skarels sc->ecclim = (int)arg; 53725439Skarels break; 53825439Skarels 53925439Skarels case SAIORETRIES: 54025439Skarels sc->retries = (int)arg; 54125439Skarels break; 54225439Skarels 54311084Ssam case SAIOSSI: /* skip-sector-inhibit */ 54411084Ssam if (drv->mbd_dt&MBDT_TAP) 54511084Ssam return (ECMD); 54611084Ssam if ((io->i_flgs&F_SSI) == 0) { 54711084Ssam /* make sure this is done once only */ 54811084Ssam io->i_flgs |= F_SSI; 54930547Skarels lp->d_nsectors++; 55030547Skarels lp->d_secpercyl += lp->d_ntracks; 55110864Ssam } 55225439Skarels break; 55310626Shelge 55411084Ssam case SAIONOSSI: /* remove skip-sector-inhibit */ 55510626Shelge if (io->i_flgs & F_SSI) { 55610626Shelge io->i_flgs &= ~F_SSI; 55710626Shelge drv->mbd_of &= ~HPOF_SSEI; 55830547Skarels lp->d_nsectors--; 55930547Skarels lp->d_secpercyl -= lp->d_ntracks; 56010626Shelge } 56125439Skarels break; 56210626Shelge 56310864Ssam case SAIOSSDEV: /* drive have skip sector? */ 56430547Skarels return (RM80(sc->type) ? 0 : ECMD); 56525439Skarels 56625439Skarels default: 56725439Skarels return (ECMD); 56810334Shelge } 56925439Skarels return (0); 57010334Shelge } 57133545Sbostic #endif /* !SMALL */ 572