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*34519Skarels * @(#)hp.c 7.9 (Berkeley) 05/27/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; 84*34519Skarels int error = 0; 8510334Shelge 8633545Sbostic if ((u_int)io->i_adapt >= MAXNMBA || !mbainit(io->i_adapt)) 8733545Sbostic return (EADAPT); 8833545Sbostic if ((u_int)io->i_ctlr) 8933545Sbostic return (ECTLR); 9033545Sbostic if ((u_int)unit >= MAXUNIT) 9133545Sbostic return (EUNIT); 9233545Sbostic hpaddr = (struct hpdevice *)mbadrv(io->i_adapt, unit); 9333545Sbostic sc = &hp_softc[io->i_adapt][unit]; 9433545Sbostic lp = &hplabel[io->i_adapt][unit]; 9525439Skarels if (sc->gottype == 0) { 9633545Sbostic register int i; 9710334Shelge struct iob tio; 9810334Shelge 9930547Skarels #ifndef SMALL 10025439Skarels sc->retries = RETRIES; 10125439Skarels sc->ecclim = 11; 10225439Skarels sc->debug = 0; 10330547Skarels #endif 10410647Shelge hpaddr->hpcs1 = HP_DCLR|HP_GO; /* init drive */ 10510647Shelge hpaddr->hpcs1 = HP_PRESET|HP_GO; 10630547Skarels #ifndef SMALL 10733547Sbostic if ((hpaddr->hpds & HPDS_DPR) == 0) 10833409Skarels return (ENXIO); 10930547Skarels sc->type = hpaddr->hpdt & MBDT_TYPE; 11030547Skarels if (sc->type == MBDT_ML11B) 11133409Skarels sc->type = MBDT_ML11A; 11230547Skarels if (!ML11(sc->type)) 11330547Skarels #endif 11410647Shelge hpaddr->hpof = HPOF_FMT22; 11510334Shelge /* 11630547Skarels * Read in the pack label. 11730547Skarels */ 11830547Skarels lp->d_nsectors = 32; 11930547Skarels lp->d_secpercyl = 20*32; 12030547Skarels tio = *io; 12130547Skarels tio.i_bn = LABELSECTOR; 12230547Skarels tio.i_ma = lbuf; 12330547Skarels tio.i_cc = SECTSIZ; 12430547Skarels tio.i_flgs |= F_RDDATA; 12533635Sbostic if (hpstrategy(&tio, READ) != SECTSIZ) 126*34519Skarels error = ERDLAB; 12733041Skarels dlp = (struct disklabel *)(lbuf + LABELOFFSET); 128*34519Skarels if (error == 0 && (dlp->d_magic != DISKMAGIC || 129*34519Skarels dlp->d_magic2 != DISKMAGIC)) 130*34519Skarels error = EUNLAB; 131*34519Skarels if (error == 0) 132*34519Skarels *lp = *dlp; 133*34519Skarels else 13433635Sbostic #ifdef COMPAT_42 135*34519Skarels if (hpmaptype(hpaddr, hpaddr->hpdt & MBDT_TYPE, unit, lp) == 0) 13630547Skarels #endif 137*34519Skarels return (error); 138*34519Skarels 13933041Skarels #ifndef SMALL 14030547Skarels /* 14111366Ssam * Read in the bad sector table. 14210334Shelge */ 14330547Skarels tio.i_bn = lp->d_secpercyl * lp->d_ncylinders - lp->d_nsectors; 14433545Sbostic tio.i_ma = (char *)&hpbad[io->i_adapt][unit]; 14533545Sbostic tio.i_cc = sizeof(struct dkbad); 14610334Shelge for (i = 0; i < 5; i++) { 14733545Sbostic if (hpstrategy(&tio, READ) == sizeof(struct dkbad)) 14810334Shelge break; 14910334Shelge tio.i_bn += 2; 15010334Shelge } 15110334Shelge if (i == 5) { 15233545Sbostic printf("hp: can't read bad sector table\n"); 15310334Shelge for (i = 0; i < MAXBADDESC; i++) { 15433545Sbostic hpbad[io->i_adapt][unit].bt_bad[i].bt_cyl = -1; 15533545Sbostic hpbad[io->i_adapt][unit].bt_bad[i].bt_trksec = -1; 15610334Shelge } 15725439Skarels } 15833041Skarels #endif 15925439Skarels sc->gottype = 1; 16010334Shelge } 16133545Sbostic if (io->i_part >= lp->d_npartitions || 16233545Sbostic lp->d_partitions[io->i_part].p_size == 0) 16333545Sbostic return (EPART); 16433545Sbostic io->i_boff = lp->d_partitions[io->i_part].p_offset; 16530547Skarels return (0); 16610334Shelge } 16710334Shelge 16810334Shelge hpstrategy(io, func) 16910334Shelge register struct iob *io; 17010334Shelge { 17133545Sbostic register int unit = io->i_unit; 17233545Sbostic register struct hp_softc *sc; 17333545Sbostic register struct disklabel *lp; 17433545Sbostic struct mba_regs *mba; 17533545Sbostic struct hpdevice *hpaddr; 17611366Ssam daddr_t bn, startblock; 17733409Skarels int cn, tn, sn, bytecnt, bytesleft, rv; 17833545Sbostic int er1, er2, hprecal; 17910334Shelge char *membase; 18010334Shelge 18133545Sbostic mba = mbamba(io->i_adapt); 18233545Sbostic hpaddr = (struct hpdevice *)mbadrv(io->i_adapt, unit); 18333545Sbostic sc = &hp_softc[io->i_adapt][unit]; 18433545Sbostic lp = &hplabel[io->i_adapt][unit]; 18530547Skarels #ifndef SMALL 18610334Shelge sectsiz = SECTSIZ; 18710334Shelge if ((io->i_flgs & (F_HDR|F_HCHECK)) != 0) 18810334Shelge sectsiz += HDRSIZ; 18910334Shelge if ((hpaddr->hpds & HPDS_VV) == 0) { 19010334Shelge hpaddr->hpcs1 = HP_DCLR|HP_GO; 19110334Shelge hpaddr->hpcs1 = HP_PRESET|HP_GO; 19230547Skarels if (!ML11(sc->type)) 19310334Shelge hpaddr->hpof = HPOF_FMT22; 19410334Shelge } 19510334Shelge io->i_errcnt = 0; 19625439Skarels sc->ssect = 0; 19725439Skarels rv = bytecnt = io->i_cc; 19810334Shelge membase = io->i_ma; 19910334Shelge startblock = io->i_bn; 20010608Ssam hprecal = 0; 20130547Skarels #endif 20211140Ssam 20310626Shelge restart: 20410334Shelge bn = io->i_bn; 20530547Skarels cn = bn / lp->d_secpercyl; 20630547Skarels sn = bn % lp->d_secpercyl; 20730547Skarels tn = sn / lp->d_nsectors; 20830547Skarels sn = sn % lp->d_nsectors + sc->ssect; 20910334Shelge 21010864Ssam HPWAIT(hpaddr); 21110626Shelge mba->mba_sr = -1; 21230547Skarels if (ML11(sc->type)) 21310334Shelge hpaddr->hpda = bn; 21410334Shelge else { 21510334Shelge hpaddr->hpdc = cn; 21610334Shelge hpaddr->hpda = (tn << 8) + sn; 21710334Shelge } 21830547Skarels #ifdef SMALL 21933545Sbostic mbastart(io, io->i_unit, func); /* start transfer */ 22030547Skarels HPWAIT(hpaddr); 22130547Skarels if (hpaddr->hpds & HPDS_ERR) { 22230547Skarels printf("hp error: sn [%d-%d) ds=%b er1=%b\n", 22330547Skarels bn, bn + io->i_cc/SECTSIZ, MASKREG(hpaddr->hpds), HPDS_BITS, 22430547Skarels MASKREG(hpaddr->hper1), HPER1_BITS); 22530547Skarels return (-1); 22630547Skarels } 22730547Skarels return (io->i_cc); 22830547Skarels #else 22933545Sbostic if (mbastart(io, io->i_unit, func) != 0) { /* start transfer */ 23025439Skarels rv = -1; 23125439Skarels goto done; 23225439Skarels } 23310864Ssam HPWAIT(hpaddr); 23411366Ssam /* 23511366Ssam * Successful data transfer, return. 23611366Ssam */ 23715068Skarels if ((hpaddr->hpds&HPDS_ERR) == 0 && (mba->mba_sr&MBSR_EBITS) == 0) 23815068Skarels goto done; 23910334Shelge 24011366Ssam /* 24111366Ssam * Error handling. Calculate location of error. 24211366Ssam */ 24311366Ssam bytesleft = MASKREG(mba->mba_bcr); 24411366Ssam if (bytesleft) 24511366Ssam bytesleft |= 0xffff0000; /* sxt */ 24611366Ssam bn = io->i_bn + (io->i_cc + bytesleft) / sectsiz; 24715052Skarels er1 = MASKREG(hpaddr->hper1); 24815052Skarels er2 = MASKREG(hpaddr->hper2); 24915052Skarels if (er1 & (HPER1_DCK|HPER1_ECH)) 25015052Skarels bn--; /* Error is in Prev block */ 25130547Skarels cn = bn/lp->d_secpercyl; 25230547Skarels sn = bn%lp->d_secpercyl; 25330547Skarels tn = sn/lp->d_nsectors; 25430547Skarels sn = sn%lp->d_nsectors; 25525439Skarels if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG)) { 25625439Skarels printf("hp error: sn%d (cyl,trk,sec)=(%d,%d,%d) ds=%b\n", 25725439Skarels bn, cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS); 25811366Ssam printf("er1=%b er2=%b\n", er1, HPER1_BITS, er2, HPER2_BITS); 25911366Ssam printf("bytes left: %d, of 0x%x, da 0x%x\n",-bytesleft, 26011366Ssam hpaddr->hpof, hpaddr->hpda); 26111366Ssam } 26210334Shelge if (er1 & HPER1_HCRC) { 26310334Shelge er1 &= ~(HPER1_HCE|HPER1_FER); 26410334Shelge er2 &= ~HPER2_BSE; 26525439Skarels if ((io->i_flgs&F_NBSF) == 0 && hpecc(io, BSE) == 0) 26625439Skarels goto success; 26710334Shelge } 26811140Ssam /* 26911140Ssam * Give up early if drive write locked. 27011140Ssam */ 27110334Shelge if (er1&HPER1_WLE) { 27210334Shelge printf("hp%d: write locked\n", unit); 27325439Skarels rv = -1; 27425439Skarels goto done; 27511084Ssam } 27611140Ssam /* 27725439Skarels * Skip sector handling. 27811140Ssam */ 27930547Skarels if (RM80(sc->type) && (er2 & HPER2_SSE)) { 28025439Skarels (void) hpecc(io, SSE); 28125439Skarels sc->ssect = 1; 28225439Skarels goto restart; 28311084Ssam } 28411140Ssam /* 28525439Skarels * Attempt to forward bad sectors on anything but an ML11. 28625439Skarels * Interpret format error bit as a bad block on RP06's. 28711140Ssam */ 28830547Skarels if (((er2 & HPER2_BSE) && !ML11(sc->type)) || 28930547Skarels (MASKREG(er1) == HPER1_FER && RP06(sc->type))) { 29011084Ssam if (io->i_flgs & F_NBSF) { 29133545Sbostic io->i_error = EBSE; 29210334Shelge goto hard; 29310334Shelge } 29410334Shelge if (hpecc(io, BSE) == 0) 29510334Shelge goto success; 29611084Ssam io->i_error = EBSE; 29711084Ssam goto hard; 29811084Ssam } 29911140Ssam /* 30011366Ssam * ECC correction? 30111140Ssam */ 30211084Ssam if ((er1 & (HPER1_DCK|HPER1_ECH)) == HPER1_DCK) { 30310864Ssam if (hpecc(io, ECC) == 0) 30410334Shelge goto success; 30511084Ssam io->i_error = EECC; 30625439Skarels goto hard; 30710608Ssam } 30825439Skarels 30925439Skarels /* 31025439Skarels * If a hard error, or maximum retry count 31125439Skarels * exceeded, clear controller state and 31225439Skarels * pass back error to caller. 31325439Skarels */ 31425439Skarels if (++io->i_errcnt > sc->retries || (er1 & HPER1_HARD) || 31530547Skarels (!ML11(sc->type) && (er2 & HPER2_HARD)) || 31630547Skarels (ML11(sc->type) && (io->i_errcnt >= 16))) { 31725439Skarels io->i_error = EHER; 31825439Skarels if (mba->mba_sr & (MBSR_WCKUP|MBSR_WCKLWR)) 31925439Skarels io->i_error = EWCK; 32025439Skarels hard: 32125439Skarels io->i_errblk = bn + sc->ssect; 32225439Skarels if (sc->debug & (HPF_BSEDEBUG|HPF_ECCDEBUG)) 32325439Skarels printf(" dc=%d, da=0x%x",MASKREG(hpaddr->hpdc), 32425439Skarels MASKREG(hpaddr->hpda)); 32525439Skarels else { 32625439Skarels printf("hp error: sn%d (cyl,trk,sec)=(%d,%d,%d) ds=%b \n", 32725439Skarels bn, cn, tn, sn, MASKREG(hpaddr->hpds), HPDS_BITS); 32825439Skarels printf("er1=%b er2=%b", er1, HPER1_BITS, er2, HPER2_BITS); 32925439Skarels } 33025439Skarels hpaddr->hpcs1 = HP_DCLR|HP_GO; 33125439Skarels printf("\n"); 33225439Skarels rv = -1; 33325439Skarels goto done; 33425439Skarels 33525439Skarels } 33610608Ssam /* fall thru to retry */ 33710334Shelge hpaddr->hpcs1 = HP_DCLR|HP_GO; 33810864Ssam HPWAIT(hpaddr); 33911140Ssam 34011140Ssam /* 34111140Ssam * Every fourth retry recalibrate. 34211140Ssam */ 34311366Ssam if (((io->i_errcnt & 07) == 4) ) { 34410334Shelge hpaddr->hpcs1 = HP_RECAL|HP_GO; 34515052Skarels HPWAIT(hpaddr); 34610334Shelge hpaddr->hpdc = cn; 34710334Shelge hpaddr->hpcs1 = HP_SEEK|HP_GO; 34815052Skarels HPWAIT(hpaddr); 34915052Skarels } 35010864Ssam 35115052Skarels if (io->i_errcnt >= 16 && (io->i_flgs & F_READ)) { 35210334Shelge hpaddr->hpof = hp_offset[io->i_errcnt & 017]|HPOF_FMT22; 35310334Shelge hpaddr->hpcs1 = HP_OFFSET|HP_GO; 35415052Skarels HPWAIT(hpaddr); 35510334Shelge } 35625439Skarels if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG)) 35715052Skarels printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n", 35815052Skarels io->i_bn, io->i_cc, io->i_ma, hprecal); 35925439Skarels goto restart; 36011084Ssam 36111140Ssam success: 36211140Ssam /* 36311140Ssam * On successful error recovery, bump 36411140Ssam * block number to advance to next portion 36511140Ssam * of i/o transfer. 36611140Ssam */ 36710334Shelge bn++; 36810334Shelge if ((bn-startblock) * sectsiz < bytecnt) { 36910334Shelge io->i_bn = bn; 37010334Shelge io->i_ma = membase + (io->i_bn - startblock)*sectsiz; 37110334Shelge io->i_cc = bytecnt - (io->i_bn - startblock)*sectsiz; 37225439Skarels if (sc->debug & (HPF_ECCDEBUG|HPF_BSEDEBUG)) 37311366Ssam printf("restart: bn=%d, cc=%d, ma=0x%x hprecal=%d\n", 37411366Ssam io->i_bn, io->i_cc, io->i_ma, hprecal); 37510626Shelge goto restart; 37610334Shelge } 37715068Skarels done: 37815052Skarels if (io->i_errcnt >= 16) { 37915052Skarels hpaddr->hpcs1 = HP_RTC|HP_GO; 38015052Skarels while (hpaddr->hpds & HPDS_PIP) 38115052Skarels ; 38215052Skarels } 38325439Skarels io->i_bn = startblock; /*reset i_bn to original */ 38418515Smiriam io->i_cc = bytecnt; /*reset i_cc to total count xfered*/ 38525439Skarels io->i_ma = membase; /*reset i_ma to original */ 38625439Skarels return (rv); 38730547Skarels #endif 38810334Shelge } 38910864Ssam 39030547Skarels #ifndef SMALL 39110334Shelge hpecc(io, flag) 39210334Shelge register struct iob *io; 39310334Shelge int flag; 39410334Shelge { 39533545Sbostic register int unit = io->i_unit; 39633545Sbostic register struct mba_regs *mbp; 39733545Sbostic register struct hpdevice *rp; 39833545Sbostic register struct hp_softc *sc; 39933545Sbostic register struct disklabel *lp; 40011084Ssam int npf, bn, cn, tn, sn, bcr; 40110334Shelge 40233545Sbostic mbp = mbamba(io->i_adapt); 40333545Sbostic rp = (struct hpdevice *)mbadrv(io->i_adapt, unit); 40433545Sbostic sc = &hp_softc[io->i_adapt][unit]; 40533545Sbostic lp = &hplabel[io->i_adapt][unit]; 40611366Ssam bcr = MASKREG(mbp->mba_bcr); 40711366Ssam if (bcr) 40811366Ssam bcr |= 0xffff0000; /* sxt */ 40911084Ssam npf = (bcr + io->i_cc) / sectsiz; /* # sectors read */ 41015052Skarels if (flag == ECC) 41115052Skarels npf--; /* Error is in prev block --ghg */ 41225439Skarels bn = io->i_bn + npf + sc->ssect; /* physical block #*/ 41325439Skarels if (sc->debug & HPF_ECCDEBUG) 41411366Ssam printf("bcr=%d npf=%d ssect=%d sectsiz=%d i_cc=%d\n", 41525439Skarels bcr, npf, sc->ssect, sectsiz, io->i_cc); 41611140Ssam /* 41711140Ssam * ECC correction logic. 41811140Ssam */ 41911140Ssam if (flag == ECC) { 42010334Shelge register int i; 42110334Shelge caddr_t addr; 42225439Skarels int bit, o, mask; 42310334Shelge 42410413Shelge printf("hp%d: soft ecc sn%d\n", unit, bn); 42510334Shelge mask = MASKREG(rp->hpec2); 42625439Skarels for (i = mask, bit = 0; i; i >>= 1) 42725439Skarels if (i & 1) 42825439Skarels bit++; 42925439Skarels if (bit > sc->ecclim) { 43025439Skarels printf("%d-bit error\n", bit); 43125439Skarels return (1); 43225439Skarels } 43311084Ssam i = MASKREG(rp->hpec1) - 1; /* -1 makes 0 origin */ 43410334Shelge bit = i&07; 43511366Ssam o = (i & ~07) >> 3; 43610334Shelge rp->hpcs1 = HP_DCLR | HP_GO; 43711179Ssam while (o <sectsiz && npf*sectsiz + o < io->i_cc && bit > -11) { 43811179Ssam addr = io->i_ma + (npf*sectsiz) + o; 43911179Ssam /* 44011179Ssam * No data transfer occurs with a write check, 44111179Ssam * so don't correct the resident copy of data. 44211179Ssam */ 44311366Ssam if ((io->i_flgs & (F_CHECK|F_HCHECK)) == 0) { 44425439Skarels if (sc->debug & HPF_ECCDEBUG) 44511366Ssam printf("addr=%x old=%x ", addr, 44611366Ssam (*addr & 0xff)); 44711140Ssam *addr ^= (mask << bit); 44825439Skarels if (sc->debug & HPF_ECCDEBUG) 44911366Ssam printf("new=%x\n",(*addr & 0xff)); 45011366Ssam } 45111179Ssam o++, bit -= 8; 45210334Shelge } 45311179Ssam return (0); 45411084Ssam } 45510334Shelge 45611084Ssam /* 45711084Ssam * Skip sector error. 45811084Ssam * Set skip-sector-inhibit and 45911084Ssam * read next sector 46011084Ssam */ 46111140Ssam if (flag == SSE) { 46210334Shelge rp->hpcs1 = HP_DCLR | HP_GO; 46310864Ssam HPWAIT(rp); 46410334Shelge rp->hpof |= HPOF_SSEI; 46533545Sbostic return (0); 46611140Ssam } 46710334Shelge 46811140Ssam /* 46911140Ssam * Bad block forwarding. 47011140Ssam */ 47111140Ssam if (flag == BSE) { 47210626Shelge int bbn; 47311084Ssam 47410626Shelge rp->hpcs1 = HP_DCLR | HP_GO; 47525439Skarels if (sc->debug & HPF_BSEDEBUG) 47611366Ssam printf("hpecc: BSE @ bn %d\n", bn); 47730547Skarels cn = bn / lp->d_secpercyl; 47830547Skarels sn = bn % lp->d_secpercyl; 47930547Skarels tn = sn / lp->d_nsectors; 48030547Skarels sn = sn % lp->d_nsectors; 48110626Shelge bcr += sectsiz; 48233545Sbostic if ((bbn = isbad(&hpbad[io->i_adapt][unit], cn, tn, sn)) < 0) 48311084Ssam return (1); 48430547Skarels bbn = lp->d_ncylinders * lp->d_secpercyl - lp->d_nsectors - 1 48530547Skarels - bbn; 48630547Skarels cn = bbn / lp->d_secpercyl; 48730547Skarels sn = bbn % lp->d_secpercyl; 48830547Skarels tn = sn / lp->d_nsectors; 48933409Skarels sn = sn % lp->d_nsectors; 49010626Shelge io->i_cc = sectsiz; 49130547Skarels io->i_ma += npf * sectsiz; 49225439Skarels if (sc->debug & HPF_BSEDEBUG) 49311366Ssam printf("revector to cn %d tn %d sn %d\n", cn, tn, sn); 49411366Ssam rp->hpof &= ~HPOF_SSEI; 49510626Shelge mbp->mba_sr = -1; 49610334Shelge rp->hpdc = cn; 49710334Shelge rp->hpda = (tn<<8) + sn; 49833545Sbostic mbastart(io, io->i_unit, io->i_flgs); 49911366Ssam io->i_errcnt = 0; 50010864Ssam HPWAIT(rp); 50110864Ssam return (rp->hpds&HPDS_ERR); 50210334Shelge } 50311084Ssam printf("hpecc: flag=%d\n", flag); 50411084Ssam return (1); 50510334Shelge } 50611140Ssam 50710334Shelge /*ARGSUSED*/ 50810334Shelge hpioctl(io, cmd, arg) 50910334Shelge struct iob *io; 51010334Shelge int cmd; 51110334Shelge caddr_t arg; 51210334Shelge { 51310647Shelge register unit = io->i_unit; 51433545Sbostic register struct hp_softc *sc = &hp_softc[io->i_adapt][unit]; 51533545Sbostic register struct disklabel *lp = &hplabel[io->i_adapt][unit]; 51633545Sbostic struct mba_drv *drv = mbadrv(io->i_adapt, unit); 51710334Shelge 51810334Shelge switch(cmd) { 51910334Shelge 52011366Ssam case SAIODEBUG: 52125439Skarels sc->debug = (int)arg; 52225439Skarels break; 52311366Ssam 52410334Shelge case SAIODEVDATA: 52525439Skarels if (drv->mbd_dt&MBDT_TAP) 52625439Skarels return (ECMD); 52730547Skarels *(struct disklabel *)arg = *lp; 52825439Skarels break; 52910334Shelge 53025439Skarels case SAIOGBADINFO: 53125439Skarels if (drv->mbd_dt&MBDT_TAP) 53225439Skarels return (ECMD); 53333545Sbostic *(struct dkbad *)arg = hpbad[io->i_adapt][unit]; 53425439Skarels break; 53525439Skarels 53625439Skarels case SAIOECCLIM: 53725439Skarels sc->ecclim = (int)arg; 53825439Skarels break; 53925439Skarels 54025439Skarels case SAIORETRIES: 54125439Skarels sc->retries = (int)arg; 54225439Skarels break; 54325439Skarels 54411084Ssam case SAIOSSI: /* skip-sector-inhibit */ 54511084Ssam if (drv->mbd_dt&MBDT_TAP) 54611084Ssam return (ECMD); 54711084Ssam if ((io->i_flgs&F_SSI) == 0) { 54811084Ssam /* make sure this is done once only */ 54911084Ssam io->i_flgs |= F_SSI; 55030547Skarels lp->d_nsectors++; 55130547Skarels lp->d_secpercyl += lp->d_ntracks; 55210864Ssam } 55325439Skarels break; 55410626Shelge 55511084Ssam case SAIONOSSI: /* remove skip-sector-inhibit */ 55610626Shelge if (io->i_flgs & F_SSI) { 55710626Shelge io->i_flgs &= ~F_SSI; 55810626Shelge drv->mbd_of &= ~HPOF_SSEI; 55930547Skarels lp->d_nsectors--; 56030547Skarels lp->d_secpercyl -= lp->d_ntracks; 56110626Shelge } 56225439Skarels break; 56310626Shelge 56410864Ssam case SAIOSSDEV: /* drive have skip sector? */ 56530547Skarels return (RM80(sc->type) ? 0 : ECMD); 56625439Skarels 56725439Skarels default: 56825439Skarels return (ECMD); 56910334Shelge } 57025439Skarels return (0); 57110334Shelge } 57233545Sbostic #endif /* !SMALL */ 573