--- Net2/arch/i386/stand/wd.c 2018/04/24 18:04:01 1.1 +++ Net2/arch/i386/stand/wd.c 2018/04/24 18:20:28 1.1.1.5 @@ -33,7 +33,8 @@ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * SUCH DAMAGE. * - * @(#)wd.c 7.3 (Berkeley) 5/4/91 + * from: @(#)wd.c 7.3 (Berkeley) 5/4/91 + * wd.c,v 1.3 1993/05/22 08:02:26 cgd Exp */ /* device driver for winchester disk */ @@ -45,11 +46,12 @@ #include "i386/isa/wdreg.h" #include "saio.h" -#define NWD 2 /* number of hard disk units supported, max 2 */ +#define SMALL +#define NWD 1 /* number of hard disk units supported, max 2 */ #define RETRIES 5 /* number of retries before giving up */ int noretries, wdquiet; -/*#define WDDEBUG*/ +/* #define WDDEBUG*/ #ifdef SMALL extern struct disklabel disklabel; @@ -89,6 +91,7 @@ wdopen(io) if (wdinit(io)) _stop("wd initialization error"); io->i_boff = dd->d_partitions[io->i_part].p_offset ; +/*printf("boff %d ", io->i_boff);*/ return(0); } @@ -118,6 +121,7 @@ wdstrategy(io,func) * Note: doing the conversions this way limits the partition size * to about 8 million sectors (1-8 Gb). */ +/*printf("bn%d ", io->i_bn);*/ sector = (unsigned long) io->i_bn * DEV_BSIZE / dd->d_secsize; nblocks = dd->d_partitions[partition].p_size; #ifndef SMALL @@ -138,6 +142,7 @@ wdstrategy(io,func) return(-1); } #endif + sector += io->i_boff; address = io->i_ma; while (iosize > 0) { @@ -200,6 +205,8 @@ wdio(func, unit, blknm, addr) printf("--- badblock code -> Old = %d; ", blknm); #endif + printf("--- badblock code -> Old = %d; ", + blknm); blknm = dd->d_secperunit - dd->d_nsectors - (bt_ptr - dkbad[unit].bt_bad) - 1; cylin = blknm / dd->d_secpercyl; @@ -218,6 +225,7 @@ retry: printf("sec %d sdh %x cylin %d ", sector, WDSD_IBM | (unit<<4) | (head & 0xf), cylin); #endif +/*printf("c %d h %d s %d ", cylin, head, sector);*/ outb(wdc+wd_precomp, 0xff); outb(wdc+wd_seccnt, 1); outb(wdc+wd_sector, sector); @@ -250,7 +258,7 @@ retry: if (inb(wdc+wd_status) & WDCS_ERR) goto error; #ifdef WDDEBUG -printf("+"); +printf("addr %x",addr); #endif return (0); error: @@ -258,14 +266,9 @@ error: if (++retries < RETRIES) goto retry; if (!wdquiet) -#ifdef SMALL - printf("wd%d: hard error: sector %d status %x error %x\n", unit, - blknm, inb(wdc+wd_status), erro); -#else printf("wd%d: hard %s error: sector %d status %b error %b\n", unit, opcode == WDCC_READ? "read" : "write", blknm, inb(wdc+wd_status), WDCS_BITS, erro, WDERR_BITS); -#endif return (-1); } @@ -289,36 +292,37 @@ wdinit(io) #ifdef SMALL dd = &disklabel; #else - /* reset controller */ - outb(wdc+wd_ctlr, 12); wait(10); outb(wdc+wd_ctlr, 8); - wdwait(); - dd = &wdsizes[unit]; +#endif + + /* reset controller */ + outb(wdc+wd_ctlr,6); + DELAY(1000); + outb(wdc+wd_ctlr,2); + DELAY(1000); + while(inb(wdc+wd_status) & WDCS_BUSY); /* 06 Sep 92*/ + outb(wdc+wd_ctlr,8); -tryagainrecal: /* set SDH, step rate, do restore to recalibrate drive */ +tryagainrecal: outb(wdc+wd_sdh, WDSD_IBM | (unit << 4)); wdwait(); outb(wdc+wd_command, WDCC_RESTORE | WD_STEP); wdwait(); if ((i = inb(wdc+wd_status)) & WDCS_ERR) { -/*#ifdef SMALL - printf("wd%d: recal status %x error %x\n", - unit, i, inb(wdc+wd_error)); -#else*/ printf("wd%d: recal status %b error %b\n", unit, i, WDCS_BITS, inb(wdc+wd_error), WDERR_BITS); -/*#endif*/ if (++errcnt < 10) goto tryagainrecal; return(-1); } +#ifndef SMALL /* * Some controllers require this (after a recal they * revert to a logical translation mode to compensate for * dos limitation on 10-bit cylinders -- *shudder* -wfj) - * note: cylinders *must* be fewer than or equal to 8 to + * note: heads *must* be fewer than or equal to 8 to * compensate for some IDE drives that latch this for all time. */ outb(wdc+wd_sdh, WDSD_IBM | (unit << 4) + 8 -1); @@ -349,13 +353,8 @@ retry: if (++errcnt < RETRIES) goto retry; if (!wdquiet) -/*#ifdef SMALL - printf("wd%d: reading label, status %x error %x\n", - unit, i, err); -#else*/ printf("wd%d: reading label, status %b error %b\n", unit, i, WDCS_BITS, err, WDERR_BITS); -/*#endif*/ return(-1); } @@ -381,25 +380,24 @@ retry: outb(wdc+wd_precomp, 0xff); /* force head 3 bit off */ return (0) ; } -#endif SMALL -#ifdef SMALL #ifdef WDDEBUG printf("magic %x sect %d\n", dd->d_magic, dd->d_nsectors); #endif -#endif SMALL +#endif !SMALL +/*printf("C%dH%dS%d ", dd->d_ncylinders, dd->d_ntracks, dd->d_nsectors);*/ /* now that we know the disk geometry, tell the controller */ - outb(wdc+wd_cyl_lo, dd->d_ncylinders); - outb(wdc+wd_cyl_hi, (dd->d_ncylinders)>>8); + outb(wdc+wd_cyl_lo, dd->d_ncylinders+1); + outb(wdc+wd_cyl_hi, (dd->d_ncylinders+1)>>8); outb(wdc+wd_sdh, WDSD_IBM | (unit << 4) + dd->d_ntracks-1); outb(wdc+wd_seccnt, dd->d_nsectors); outb(wdc+wd_command, 0x91); while (inb(wdc+wd_status) & WDCS_BUSY) ; dkbad[unit].bt_bad[0].bt_cyl = -1; - outb(wdc+wd_precomp, dd->d_precompcyl / 4); + if (dd->d_flags & D_BADSECT) { /* * Read bad sector table into memory. */ @@ -417,6 +415,7 @@ retry: printf("wd%d: error in bad-sector file\n", unit); dkbad[unit].bt_bad[0].bt_cyl = -1; } + } return(0); }