summaryrefslogtreecommitdiff
path: root/sys/arch/atari/dev
diff options
context:
space:
mode:
authortsutsui <tsutsui@NetBSD.org>2010-04-07 13:53:05 +0000
committertsutsui <tsutsui@NetBSD.org>2010-04-07 13:53:05 +0000
commit8f12100ec0a9fc88dfcbff149c227209da25ae8d (patch)
tree7bac6a7dd0026c80944e33821cc3dac047718cab /sys/arch/atari/dev
parent863ed02e2e0fb09b1187f5d43097ee7ed0ed989f (diff)
Misc KNF.
Diffstat (limited to 'sys/arch/atari/dev')
-rw-r--r--sys/arch/atari/dev/fd.c678
1 files changed, 346 insertions, 332 deletions
diff --git a/sys/arch/atari/dev/fd.c b/sys/arch/atari/dev/fd.c
index 20d25524ad7..d642f18250c 100644
--- a/sys/arch/atari/dev/fd.c
+++ b/sys/arch/atari/dev/fd.c
@@ -1,4 +1,4 @@
-/* $NetBSD: fd.c,v 1.74 2010/04/07 13:14:23 tsutsui Exp $ */
+/* $NetBSD: fd.c,v 1.75 2010/04/07 13:53:05 tsutsui Exp $ */
/*
* Copyright (c) 1995 Leo Weppelman.
@@ -44,7 +44,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.74 2010/04/07 13:14:23 tsutsui Exp $");
+__KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.75 2010/04/07 13:53:05 tsutsui Exp $");
#include <sys/param.h>
#include <sys/systm.h>
@@ -72,6 +72,8 @@ __KERNEL_RCSID(0, "$NetBSD: fd.c,v 1.74 2010/04/07 13:14:23 tsutsui Exp $");
#include <atari/dev/ym2149reg.h>
#include <atari/dev/fdreg.h>
+#include "ioconf.h"
+
/*
* Be verbose for debugging
*/
@@ -121,9 +123,9 @@ static short motoron = 0; /* motor is spinning */
static short nopens = 0; /* Number of opens executed */
static short fd_state = FLP_IDLE; /* Current driver state */
-static int lock_stat= 0; /* DMA locking status */
+static int lock_stat = 0; /* DMA locking status */
static short fd_cmd = 0; /* command being executed */
-static const char *fd_error= NULL; /* error from fd_xfer_ok() */
+static const char *fd_error = NULL; /* error from fd_xfer_ok() */
/*
* Private per device data
@@ -142,11 +144,11 @@ struct fd_softc {
short flags; /* misc flags */
short part; /* Current open partition */
int sector; /* logical sector for I/O */
- char *io_data; /* KVA for data transfer */
+ uint8_t *io_data; /* KVA for data transfer */
int io_bytes; /* bytes left for I/O */
int io_dir; /* B_READ/B_WRITE */
int errcnt; /* current error count */
- u_char *bounceb; /* Bounce buffer */
+ uint8_t *bounceb; /* Bounce buffer */
};
@@ -217,26 +219,34 @@ static int fdselect(int, int, int);
static void fddeselect(void);
static void fdmoff(struct fd_softc *);
-static inline u_char read_fdreg(u_short);
+static u_short rd_cfg_switch(void);
+
+static inline uint8_t read_fdreg(u_short);
static inline void write_fdreg(u_short, u_short);
-static inline u_char read_dmastat(void);
+static inline uint8_t read_dmastat(void);
-static inline u_char read_fdreg(u_short regno)
+static inline
+uint8_t read_fdreg(u_short regno)
{
+
DMA->dma_mode = regno;
- return(DMA->dma_data);
+ return DMA->dma_data;
}
-static inline void write_fdreg(u_short regno, u_short val)
+static inline
+void write_fdreg(u_short regno, u_short val)
{
+
DMA->dma_mode = regno;
DMA->dma_data = val;
}
-static inline u_char read_dmastat(void)
+static inline
+uint8_t read_dmastat(void)
{
+
DMA->dma_mode = FDC_CS | DMA_SCREG;
- return(DMA->dma_stat);
+ return DMA->dma_stat;
}
/*
@@ -246,10 +256,11 @@ static inline u_char read_dmastat(void)
* Note: This location _must_ be read as an u_short. Failure to do so
* will return garbage!
*/
-static u_short rd_cfg_switch(void);
-static u_short rd_cfg_switch(void)
+static u_short
+rd_cfg_switch(void)
{
- return(*((volatile u_short *)AD_CFG_SWITCH));
+
+ return *(volatile u_short *)AD_CFG_SWITCH;
}
/*
@@ -261,8 +272,6 @@ static u_short rd_cfg_switch(void)
/*
* Autoconfig stuff....
*/
-extern struct cfdriver fd_cd;
-
static int fdcmatch(device_t, cfdata_t, void *);
static int fdcprint(void *, const char *);
static void fdcattach(device_t, device_t, void *);
@@ -282,25 +291,25 @@ const struct cdevsw fd_cdevsw = {
static int
fdcmatch(device_t parent, cfdata_t match, void *aux)
{
- static int fdc_matched = 0;
+ static int fdc_matched = 0;
/* Match only once */
- if(strcmp("fdc", aux) || fdc_matched)
- return(0);
+ if (strcmp("fdc", aux) || fdc_matched)
+ return 0;
fdc_matched = 1;
- return(1);
+ return 1;
}
static void
fdcattach(device_t parent, device_t self, void *aux)
{
struct fd_softc fdsoftc;
- int i, nfound, first_found;
+ int i, nfound, first_found;
nfound = first_found = 0;
printf("\n");
fddeselect();
- for(i = 0; i < NR_DRIVES; i++) {
+ for (i = 0; i < NR_DRIVES; i++) {
/*
* Test if unit is present
@@ -308,18 +317,18 @@ fdcattach(device_t parent, device_t self, void *aux)
fdsoftc.unit = i;
fdsoftc.flags = 0;
st_dmagrab((dma_farg)fdcint, (dma_farg)fdtestdrv, &fdsoftc,
- &lock_stat, 0);
+ &lock_stat, 0);
st_dmafree(&fdsoftc, &lock_stat);
- if(!(fdsoftc.flags & FLPF_NOTRESP)) {
- if(!nfound)
+ if ((fdsoftc.flags & FLPF_NOTRESP) == 0) {
+ if (nfound == 0)
first_found = i;
nfound++;
- config_found(self, (void*)i, fdcprint);
+ config_found(self, (void *)i, fdcprint);
}
}
- if(nfound) {
+ if (nfound != 0) {
struct fd_softc *fdsc =
device_lookup_private(&fd_cd, first_found);
@@ -335,7 +344,7 @@ fdcattach(device_t parent, device_t self, void *aux)
* enable disk related interrupts
*/
MFP->mf_ierb |= IB_DINT;
- MFP->mf_iprb = (u_int8_t)~IB_DINT;
+ MFP->mf_iprb = (uint8_t)~IB_DINT;
MFP->mf_imrb |= IB_DINT;
}
}
@@ -343,10 +352,11 @@ fdcattach(device_t parent, device_t self, void *aux)
static int
fdcprint(void *aux, const char *pnp)
{
+
if (pnp != NULL)
aprint_normal("fd%d at %s:", (int)aux, pnp);
- return(UNCONF);
+ return UNCONF;
}
static int fdmatch(device_t, cfdata_t, void *);
@@ -357,12 +367,11 @@ struct dkdriver fddkdriver = { fdstrategy };
CFATTACH_DECL_NEW(fd, sizeof(struct fd_softc),
fdmatch, fdattach, NULL, NULL);
-extern struct cfdriver fd_cd;
-
static int
fdmatch(device_t parent, cfdata_t match, void *aux)
{
- return(1);
+
+ return 1;
}
static void
@@ -386,8 +395,8 @@ fdattach(device_t parent, device_t self, void *aux)
type = &fdtypes[def_type];
aprint_normal(": %s %d cyl, %d head, %d sec\n", type->descr,
- type->nblocks / (type->nsectors * type->nheads), type->nheads,
- type->nsectors);
+ type->nblocks / (type->nsectors * type->nheads), type->nheads,
+ type->nsectors);
/*
* Initialize and attach the disk structure.
@@ -403,35 +412,33 @@ fdioctl(dev_t dev, u_long cmd, void * addr, int flag, struct lwp *l)
sc = device_lookup_private(&fd_cd, DISKUNIT(dev));
- if((sc->flags & FLPF_HAVELAB) == 0)
- return(EBADF);
-
- switch(cmd) {
- case DIOCSBAD:
- return(EINVAL);
- case DIOCGDINFO:
- *(struct disklabel *)addr = *(sc->dkdev.dk_label);
- return(0);
- case DIOCGPART:
- ((struct partinfo *)addr)->disklab =
- sc->dkdev.dk_label;
- ((struct partinfo *)addr)->part =
- &sc->dkdev.dk_label->d_partitions[RAW_PART];
- return(0);
+ if ((sc->flags & FLPF_HAVELAB) == 0)
+ return EBADF;
+
+ switch (cmd) {
+ case DIOCSBAD:
+ return EINVAL;
+ case DIOCGDINFO:
+ *(struct disklabel *)addr = *(sc->dkdev.dk_label);
+ return 0;
+ case DIOCGPART:
+ ((struct partinfo *)addr)->disklab = sc->dkdev.dk_label;
+ ((struct partinfo *)addr)->part =
+ &sc->dkdev.dk_label->d_partitions[RAW_PART];
+ return 0;
#ifdef notyet /* XXX LWP */
- case DIOCSRETRIES:
- case DIOCSSTEP:
- case DIOCSDINFO:
- case DIOCWDINFO:
- case DIOCWLABEL:
- break;
+ case DIOCSRETRIES:
+ case DIOCSSTEP:
+ case DIOCSDINFO:
+ case DIOCWDINFO:
+ case DIOCWLABEL:
+ break;
#endif /* notyet */
- case DIOCGDEFLABEL:
- fdgetdefaultlabel(sc, (struct disklabel *)addr,
- RAW_PART);
- return(0);
+ case DIOCGDEFLABEL:
+ fdgetdefaultlabel(sc, (struct disklabel *)addr, RAW_PART);
+ return 0;
}
- return(ENOTTY);
+ return ENOTTY;
}
/*
@@ -446,23 +453,23 @@ int
fdopen(dev_t dev, int flags, int devtype, struct lwp *l)
{
struct fd_softc *sc;
- int sps;
+ int s;
#ifdef FLP_DEBUG
printf("fdopen dev=0x%x\n", dev);
#endif
- if(FLP_TYPE(dev) >= NR_TYPES)
- return(ENXIO);
+ if (FLP_TYPE(dev) >= NR_TYPES)
+ return ENXIO;
- if((sc = device_lookup_private(&fd_cd, DISKUNIT(dev))) == NULL)
- return(ENXIO);
+ if ((sc = device_lookup_private(&fd_cd, DISKUNIT(dev))) == NULL)
+ return ENXIO;
/*
* If no floppy currently open, reset the controller and select
* floppy type.
*/
- if(!nopens) {
+ if (nopens == 0) {
#ifdef FLP_DEBUG
printf("fdopen device not yet open\n");
@@ -475,17 +482,17 @@ fdopen(dev_t dev, int flags, int devtype, struct lwp *l)
/*
* Sleep while other process is opening the device
*/
- sps = splbio();
- while(sc->flags & FLPF_INOPEN)
+ s = splbio();
+ while (sc->flags & FLPF_INOPEN)
tsleep((void *)sc, PRIBIO, "fdopen", 0);
- splx(sps);
+ splx(s);
- if(!(sc->flags & FLPF_ISOPEN)) {
+ if((sc->flags & FLPF_ISOPEN) == 0) {
/*
* Initialise some driver values.
*/
- int type;
- void *addr;
+ int type;
+ void *addr;
type = FLP_TYPE(dev);
@@ -499,46 +506,46 @@ fdopen(dev_t dev, int flags, int devtype, struct lwp *l)
sc->curtrk = INV_TRK;
sc->sector = 0;
sc->errcnt = 0;
- sc->bounceb = (u_char*)alloc_stmem(SECTOR_SIZE, &addr);
- if(sc->bounceb == NULL)
- return(ENOMEM); /* XXX */
+ sc->bounceb = alloc_stmem(SECTOR_SIZE, &addr);
+ if (sc->bounceb == NULL)
+ return ENOMEM; /* XXX */
/*
* Go get write protect + loaded status
*/
sc->flags |= FLPF_INOPEN|FLPF_GETSTAT;
- sps = splbio();
+ s = splbio();
st_dmagrab((dma_farg)fdcint, (dma_farg)fdstatus, sc,
- &lock_stat, 0);
- while(sc->flags & FLPF_GETSTAT)
+ &lock_stat, 0);
+ while ((sc->flags & FLPF_GETSTAT) != 0)
tsleep((void *)sc, PRIBIO, "fdopen", 0);
- splx(sps);
+ splx(s);
wakeup((void *)sc);
- if((sc->flags & FLPF_WRTPROT) && (flags & FWRITE)) {
+ if ((sc->flags & FLPF_WRTPROT) != 0 &&
+ (flags & FWRITE) != 0) {
sc->flags = 0;
- return(EPERM);
+ return EPERM;
}
- if(sc->flags & FLPF_EMPTY) {
+ if ((sc->flags & FLPF_EMPTY) != 0) {
sc->flags = 0;
- return(ENXIO);
+ return ENXIO;
}
sc->flags &= ~(FLPF_INOPEN|FLPF_GETSTAT);
sc->flags |= FLPF_ISOPEN;
- }
- else {
+ } else {
/*
* Multiply opens are granted when accessing the same type of
* floppy (eq. the same partition).
*/
- if(sc->density != fdtypes[DISKPART(dev)].density)
- return(ENXIO); /* XXX temporarely out of business */
+ if (sc->density != fdtypes[DISKPART(dev)].density)
+ return ENXIO; /* XXX temporarely out of business */
}
fdgetdisklabel(sc, dev);
#ifdef FLP_DEBUG
printf("fdopen open succeeded on type %d\n", sc->part);
#endif
- return (0);
+ return 0;
}
int
@@ -554,15 +561,15 @@ fdclose(dev_t dev, int flags, int devtype, struct lwp *l)
#ifdef FLP_DEBUG
printf("Closed floppy device -- nopens: %d\n", nopens);
#endif
- return(0);
+ return 0;
}
void
fdstrategy(struct buf *bp)
{
- struct fd_softc *sc;
+ struct fd_softc *sc;
struct disklabel *lp;
- int sps, sz;
+ int s, sz;
sc = device_lookup_private(&fd_cd, DISKUNIT(bp->b_dev));
@@ -578,7 +585,7 @@ fdstrategy(struct buf *bp)
bp->b_error = EIO;
goto done;
}
- if (bp->b_blkno < 0 || (bp->b_bcount % SECTOR_SIZE)) {
+ if (bp->b_blkno < 0 || (bp->b_bcount % SECTOR_SIZE) != 0) {
bp->b_error = EINVAL;
goto done;
}
@@ -598,7 +605,8 @@ fdstrategy(struct buf *bp)
/* Trucate it */
if (bp->b_flags & B_RAW)
bp->b_bcount = sz << DEV_BSHIFT;
- else bp->b_bcount = sz * lp->d_secsize;
+ else
+ bp->b_bcount = sz * lp->d_secsize;
}
/* No partition translation. */
@@ -607,16 +615,16 @@ fdstrategy(struct buf *bp)
/*
* queue the buf and kick the low level code
*/
- sps = splbio();
+ s = splbio();
bufq_put(sc->bufq, bp); /* XXX disksort_cylinder */
if (!lock_stat) {
if (fd_state & FLP_MON)
callout_stop(&sc->sc_motor_ch);
fd_state = FLP_IDLE;
st_dmagrab((dma_farg)fdcint, (dma_farg)fdstart, sc,
- &lock_stat, 0);
+ &lock_stat, 0);
}
- splx(sps);
+ splx(s);
return;
done:
@@ -627,13 +635,15 @@ done:
int
fdread(dev_t dev, struct uio *uio, int flags)
{
- return(physio(fdstrategy, NULL, dev, B_READ, fdminphys, uio));
+
+ return physio(fdstrategy, NULL, dev, B_READ, fdminphys, uio);
}
int
fdwrite(dev_t dev, struct uio *uio, int flags)
{
- return(physio(fdstrategy, NULL, dev, B_WRITE, fdminphys, uio));
+
+ return physio(fdstrategy, NULL, dev, B_WRITE, fdminphys, uio);
}
/*
@@ -642,6 +652,7 @@ fdwrite(dev_t dev, struct uio *uio, int flags)
static void
fdstatus(struct fd_softc *sc)
{
+
#ifdef FLP_DEBUG
printf("fdstatus\n");
#endif
@@ -659,7 +670,7 @@ fdstatus(struct fd_softc *sc)
static void
fdstart(struct fd_softc *sc)
{
- struct buf *bp;
+ struct buf *bp;
bp = bufq_peek(sc->bufq);
sc->sector = bp->b_blkno; /* Start sector for I/O */
@@ -683,9 +694,9 @@ fdstart(struct fd_softc *sc)
static void
fddone(register struct fd_softc *sc)
{
- struct buf *bp;
+ struct buf *bp;
struct fd_softc *sc1;
- int i, sps;
+ int i, s;
/*
* Give others a chance to use the DMA.
@@ -693,19 +704,19 @@ fddone(register struct fd_softc *sc)
st_dmafree(sc, &lock_stat);
- if(fd_state != FLP_STAT) {
+ if (fd_state != FLP_STAT) {
/*
* Finish current transaction.
*/
- sps = splbio();
+ s = splbio();
bp = bufq_get(sc->bufq);
if (bp == NULL)
panic("fddone");
- splx(sps);
+ splx(s);
#ifdef FLP_DEBUG
- printf("fddone: unit: %d, buf: %p, resid: %d\n",sc->unit,bp,
- sc->io_bytes);
+ printf("fddone: unit: %d, buf: %p, resid: %d\n",sc->unit, bp,
+ sc->io_bytes);
#endif
bp->b_resid = sc->io_bytes;
@@ -716,20 +727,20 @@ fddone(register struct fd_softc *sc)
}
fd_state = FLP_MON;
- if(lock_stat)
+ if (lock_stat)
return; /* XXX Is this possible? */
/*
* Find a new transaction on round-robin basis.
*/
- for(i = sc->unit + 1; ;i++) {
- if(i >= fd_cd.cd_ndevs)
+ for (i = sc->unit + 1;; i++) {
+ if (i >= fd_cd.cd_ndevs)
i = 0;
- if((sc1 = device_lookup_private(&fd_cd, i)) == NULL)
+ if ((sc1 = device_lookup_private(&fd_cd, i)) == NULL)
continue;
if (bufq_peek(sc1->bufq) != NULL)
break;
- if(i == sc->unit) {
+ if (i == sc->unit) {
callout_reset(&sc->sc_motor_ch, FLP_MONDELAY,
(FPV)fdmotoroff, sc);
#ifdef FLP_DEBUG
@@ -748,7 +759,8 @@ fddone(register struct fd_softc *sc)
static int
fdselect(int drive, int head, int dense)
{
- int i, spinning;
+ int i, spinning;
+
#ifdef FLP_DEBUG
printf("fdselect: drive=%d, head=%d, dense=%d\n", drive, head, dense);
#endif
@@ -756,26 +768,27 @@ fdselect(int drive, int head, int dense)
spinning = motoron;
motoron = 1;
- switch(dense) {
- case FLP_DD:
- DMA->dma_drvmode = 0;
- break;
- case FLP_HD:
- DMA->dma_drvmode = (FDC_HDSET|FDC_HDSIG);
- break;
- default:
- panic("fdselect: unknown density code");
+ switch (dense) {
+ case FLP_DD:
+ DMA->dma_drvmode = 0;
+ break;
+ case FLP_HD:
+ DMA->dma_drvmode = (FDC_HDSET|FDC_HDSIG);
+ break;
+ default:
+ panic("fdselect: unknown density code");
}
- if(i != selected) {
+ if (i != selected) {
selected = i;
ym2149_fd_select((i ^ PA_FDSEL));
}
- return(spinning);
+ return spinning;
}
static void
fddeselect(void)
{
+
ym2149_fd_select(PA_FDSEL);
motoron = selected = 0;
DMA->dma_drvmode = 0;
@@ -800,13 +813,13 @@ fddeselect(void)
static void
fd_xfer(struct fd_softc *sc)
{
- register int head;
- register int track, sector, hbit;
- u_long phys_addr;
+ int head;
+ int track, sector, hbit;
+ paddr_t phys_addr;
head = track = 0;
- switch(fd_state) {
- case FLP_XFER:
+ switch (fd_state) {
+ case FLP_XFER:
/*
* Calculate head/track values
*/
@@ -814,18 +827,18 @@ fd_xfer(struct fd_softc *sc)
head = track % sc->nheads;
track = track / sc->nheads;
#ifdef FLP_DEBUG
- printf("fd_xfer: sector:%d,head:%d,track:%d\n", sc->sector,head,
- track);
+ printf("fd_xfer: sector:%d,head:%d,track:%d\n",
+ sc->sector, head, track);
#endif
break;
- case FLP_STAT:
+ case FLP_STAT:
/*
* FLP_STAT only wants to recalibrate
*/
sc->curtrk = INV_TRK;
break;
- default:
+ default:
panic("fd_xfer: wrong state (0x%x)", fd_state);
}
@@ -834,7 +847,7 @@ fd_xfer(struct fd_softc *sc)
*/
hbit = fdselect(sc->unit, head, sc->density) ? HBIT : 0;
- if(sc->curtrk == INV_TRK) {
+ if (sc->curtrk == INV_TRK) {
/*
* Recalibrate, since we lost track of head positioning.
* The floppy disk controller has no way of determining its
@@ -863,7 +876,7 @@ fd_xfer(struct fd_softc *sc)
* Issue a SEEK command on the indicated drive unless the arm is
* already positioned on the correct track.
*/
- if(track != sc->curtrk) {
+ if (track != sc->curtrk) {
sc->curtrk = track; /* be optimistic */
write_fdreg(FDC_DR, track);
write_fdreg(FDC_CS, SEEK|RATE6|VBIT|hbit);
@@ -871,7 +884,8 @@ fd_xfer(struct fd_softc *sc)
(FPV)fdmotoroff, sc);
fd_cmd = SEEK;
#ifdef FLP_DEBUG
- printf("fd_xfer:Seek to track %d on drive %d\n",track,sc->unit);
+ printf("fd_xfer:Seek to track %d on drive %d\n",
+ track, sc->unit);
#endif
return;
}
@@ -884,13 +898,13 @@ fd_xfer(struct fd_softc *sc)
write_fdreg(FDC_SR, sector);
- phys_addr = (u_long)kvtop(sc->io_data);
- if(phys_addr >= FDC_MAX_DMA_AD) {
+ phys_addr = (paddr_t)kvtop(sc->io_data);
+ if (phys_addr >= FDC_MAX_DMA_AD) {
/*
* We _must_ bounce this address
*/
- phys_addr = (u_long)kvtop(sc->bounceb);
- if(sc->io_dir == B_WRITE)
+ phys_addr = (paddr_t)kvtop(sc->bounceb);
+ if (sc->io_dir == B_WRITE)
memcpy(sc->bounceb, sc->io_data, SECTOR_SIZE);
sc->flags |= FLPF_BOUNCE;
}
@@ -900,13 +914,12 @@ fd_xfer(struct fd_softc *sc)
printf("fd_xfer:Start io (io_addr:%lx)\n", (u_long)kvtop(sc->io_data));
#endif
- if(sc->io_dir == B_READ) {
+ if (sc->io_dir == B_READ) {
/* Issue the command */
st_dmacomm(DMA_FDC | DMA_SCREG, 1);
write_fdreg(FDC_CS, F_READ|hbit);
fd_cmd = F_READ;
- }
- else {
+ } else {
/* Issue the command */
st_dmacomm(DMA_WRBIT | DMA_FDC | DMA_SCREG, 1);
write_fdreg(DMA_WRBIT | FDC_CS, F_WRITE|hbit|EBIT|PBIT);
@@ -927,7 +940,7 @@ fd_xfer(struct fd_softc *sc)
static void
fdcint(struct fd_softc *sc)
{
- struct buf *bp;
+ struct buf *bp;
#ifdef FLP_DEBUG
printf("fdcint: unit = %d\n", sc->unit);
@@ -938,72 +951,74 @@ fdcint(struct fd_softc *sc)
*/
callout_stop(&sc->sc_motor_ch);
- switch(fd_xfer_ok(sc)) {
- case X_ERROR :
- if(++(sc->errcnt) < MAX_ERRORS) {
- /*
- * Command failed but still retries left.
- */
- break;
- }
- /* FALL THROUGH */
- case X_FAIL :
+ switch (fd_xfer_ok(sc)) {
+ case X_ERROR:
+ if (++sc->errcnt < MAX_ERRORS) {
/*
- * Non recoverable error. Fall back to motor-on
- * idle-state.
+ * Command failed but still retries left.
*/
- if(fd_error != NULL) {
- printf("Floppy error: %s\n", fd_error);
- fd_error = NULL;
- }
+ break;
+ }
+ /* FALL THROUGH */
+ case X_FAIL:
+ /*
+ * Non recoverable error. Fall back to motor-on
+ * idle-state.
+ */
+ if (fd_error != NULL) {
+ printf("Floppy error: %s\n", fd_error);
+ fd_error = NULL;
+ }
- if(fd_state == FLP_STAT) {
- sc->flags |= FLPF_EMPTY;
- sc->flags &= ~FLPF_GETSTAT;
- wakeup((void *)sc);
- fddone(sc);
- return;
- }
+ if (fd_state == FLP_STAT) {
+ sc->flags |= FLPF_EMPTY;
+ sc->flags &= ~FLPF_GETSTAT;
+ wakeup((void *)sc);
+ fddone(sc);
+ return;
+ }
- bp = bufq_peek(sc->bufq);
+ bp = bufq_peek(sc->bufq);
- bp->b_error = EIO;
- fd_state = FLP_MON;
+ bp->b_error = EIO;
+ fd_state = FLP_MON;
- break;
- case X_AGAIN:
- /*
- * Start next part of state machine.
- */
- break;
- case X_OK:
- /*
- * Command ok and finished. Reset error-counter.
- * If there are no more bytes to transfer fall back
- * to motor-on idle state.
- */
- sc->errcnt = 0;
-
- if(fd_state == FLP_STAT) {
- sc->flags &= ~FLPF_GETSTAT;
- wakeup((void *)sc);
- fddone(sc);
- return;
- }
-
- if((sc->flags & FLPF_BOUNCE) && (sc->io_dir == B_READ))
- memcpy(sc->io_data, sc->bounceb, SECTOR_SIZE);
- sc->flags &= ~FLPF_BOUNCE;
-
- sc->sector++;
- sc->io_data += SECTOR_SIZE;
- sc->io_bytes -= SECTOR_SIZE;
- if(sc->io_bytes <= 0)
- fd_state = FLP_MON;
+ break;
+ case X_AGAIN:
+ /*
+ * Start next part of state machine.
+ */
+ break;
+ case X_OK:
+ /*
+ * Command ok and finished. Reset error-counter.
+ * If there are no more bytes to transfer fall back
+ * to motor-on idle state.
+ */
+ sc->errcnt = 0;
+
+ if (fd_state == FLP_STAT) {
+ sc->flags &= ~FLPF_GETSTAT;
+ wakeup((void *)sc);
+ fddone(sc);
+ return;
+ }
+
+ if ((sc->flags & FLPF_BOUNCE) != 0 &&
+ sc->io_dir == B_READ)
+ memcpy(sc->io_data, sc->bounceb, SECTOR_SIZE);
+ sc->flags &= ~FLPF_BOUNCE;
+
+ sc->sector++;
+ sc->io_data += SECTOR_SIZE;
+ sc->io_bytes -= SECTOR_SIZE;
+ if (sc->io_bytes <= 0)
+ fd_state = FLP_MON;
}
- if(fd_state == FLP_MON)
+ if (fd_state == FLP_MON)
fddone(sc);
- else fd_xfer(sc);
+ else
+ fd_xfer(sc);
}
/*
@@ -1020,96 +1035,96 @@ fdcint(struct fd_softc *sc)
static int
fd_xfer_ok(register struct fd_softc *sc)
{
- register int status;
+ int status;
#ifdef FLP_DEBUG
printf("fd_xfer_ok: cmd: 0x%x, state: 0x%x\n", fd_cmd, fd_state);
#endif
- switch(fd_cmd) {
- case IRUPT:
- /*
- * Timeout. Force a recalibrate before we try again.
- */
- status = read_fdreg(FDC_CS);
+ switch (fd_cmd) {
+ case IRUPT:
+ /*
+ * Timeout. Force a recalibrate before we try again.
+ */
+ status = read_fdreg(FDC_CS);
- fd_error = "Timeout";
- sc->curtrk = INV_TRK;
- return(X_ERROR);
- case F_READ:
- /*
- * Test for DMA error
- */
- status = read_dmastat();
- if(!(status & DMAOK)) {
- fd_error = "DMA error";
- return(X_ERROR);
- }
- /*
- * Get controller status and check for errors.
- */
- status = read_fdreg(FDC_CS);
- if(status & (RNF | CRCERR | LD_T00)) {
- fd_error = "Read error";
- if(status & RNF)
- sc->curtrk = INV_TRK;
- return(X_ERROR);
- }
- break;
- case F_WRITE:
- /*
- * Test for DMA error
- */
- status = read_dmastat();
- if(!(status & DMAOK)) {
- fd_error = "DMA error";
- return(X_ERROR);
- }
- /*
- * Get controller status and check for errors.
- */
- status = read_fdreg(FDC_CS);
- if(status & WRI_PRO) {
- fd_error = "Write protected";
- return(X_FAIL);
- }
- if(status & (RNF | CRCERR | LD_T00)) {
- fd_error = "Write error";
+ fd_error = "Timeout";
+ sc->curtrk = INV_TRK;
+ return X_ERROR;
+ case F_READ:
+ /*
+ * Test for DMA error
+ */
+ status = read_dmastat();
+ if ((status & DMAOK) == 0) {
+ fd_error = "DMA error";
+ return X_ERROR;
+ }
+ /*
+ * Get controller status and check for errors.
+ */
+ status = read_fdreg(FDC_CS);
+ if ((status & (RNF | CRCERR | LD_T00)) != 0) {
+ fd_error = "Read error";
+ if ((status & RNF) != 0)
sc->curtrk = INV_TRK;
- return(X_ERROR);
- }
+ return X_ERROR;
+ }
+ break;
+ case F_WRITE:
+ /*
+ * Test for DMA error
+ */
+ status = read_dmastat();
+ if ((status & DMAOK) == 0) {
+ fd_error = "DMA error";
+ return X_ERROR;
+ }
+ /*
+ * Get controller status and check for errors.
+ */
+ status = read_fdreg(FDC_CS);
+ if ((status & WRI_PRO) != 0) {
+ fd_error = "Write protected";
+ return X_FAIL;
+ }
+ if ((status & (RNF | CRCERR | LD_T00)) != 0) {
+ fd_error = "Write error";
+ sc->curtrk = INV_TRK;
+ return X_ERROR;
+ }
+ break;
+ case SEEK:
+ status = read_fdreg(FDC_CS);
+ if ((status & (RNF | CRCERR)) != 0) {
+ fd_error = "Seek error";
+ sc->curtrk = INV_TRK;
+ return X_ERROR;
+ }
+ return X_AGAIN;
+ case RESTORE:
+ /*
+ * Determine if the recalibration succeeded.
+ */
+ status = read_fdreg(FDC_CS);
+ if ((status & RNF) != 0) {
+ fd_error = "Recalibrate error";
+ /* reset controller */
+ write_fdreg(FDC_CS, IRUPT);
+ sc->curtrk = INV_TRK;
+ return X_ERROR;
+ }
+ sc->curtrk = 0;
+ if (fd_state == FLP_STAT) {
+ if ((status & WRI_PRO) != 0)
+ sc->flags |= FLPF_WRTPROT;
break;
- case SEEK:
- status = read_fdreg(FDC_CS);
- if(status & (RNF | CRCERR)) {
- fd_error = "Seek error";
- sc->curtrk = INV_TRK;
- return(X_ERROR);
- }
- return(X_AGAIN);
- case RESTORE:
- /*
- * Determine if the recalibration succeeded.
- */
- status = read_fdreg(FDC_CS);
- if(status & RNF) {
- fd_error = "Recalibrate error";
- /* reset controller */
- write_fdreg(FDC_CS, IRUPT);
- sc->curtrk = INV_TRK;
- return(X_ERROR);
- }
- sc->curtrk = 0;
- if(fd_state == FLP_STAT) {
- if(status & WRI_PRO)
- sc->flags |= FLPF_WRTPROT;
- break;
- }
- return(X_AGAIN);
- default:
- fd_error = "Driver error: fd_xfer_ok : Unknown state";
- return(X_FAIL);
+ }
+ return X_AGAIN;
+ default:
+ fd_error = "Driver error: fd_xfer_ok : Unknown state";
+ return X_FAIL;
}
- return(X_OK);
+ return X_OK;
}
/*
@@ -1118,50 +1133,50 @@ fd_xfer_ok(register struct fd_softc *sc)
static void
fdmotoroff(struct fd_softc *sc)
{
- int sps;
+ int s;
/*
* Get at harware interrupt level
*/
- sps = splbio();
+ s = splbio();
#if FLP_DEBUG
printf("fdmotoroff, state = 0x%x\n", fd_state);
#endif
- switch(fd_state) {
- case FLP_STAT :
- case FLP_XFER :
- /*
- * Timeout during a transfer; cancel transaction
- * set command to 'IRUPT'.
- * A drive-interrupt is simulated to trigger the state
- * machine.
- */
- /*
- * Cancel current transaction
- */
- fd_cmd = IRUPT;
- write_fdreg(FDC_CS, IRUPT);
- delay(20);
- (void)read_fdreg(FDC_CS);
- write_fdreg(FDC_CS, RESTORE);
- break;
+ switch (fd_state) {
+ case FLP_STAT:
+ case FLP_XFER:
+ /*
+ * Timeout during a transfer; cancel transaction
+ * set command to 'IRUPT'.
+ * A drive-interrupt is simulated to trigger the state
+ * machine.
+ */
+ /*
+ * Cancel current transaction
+ */
+ fd_cmd = IRUPT;
+ write_fdreg(FDC_CS, IRUPT);
+ delay(20);
+ (void)read_fdreg(FDC_CS);
+ write_fdreg(FDC_CS, RESTORE);
+ break;
- case FLP_MON :
- /*
- * Turn motor off.
- */
- if(selected) {
- int tmp;
+ case FLP_MON:
+ /*
+ * Turn motor off.
+ */
+ if (selected) {
+ int tmp;
- st_dmagrab((dma_farg)fdcint, (dma_farg)fdmoff,
- sc, &tmp, 0);
- }
- else fd_state = FLP_IDLE;
- break;
+ st_dmagrab((dma_farg)fdcint, (dma_farg)fdmoff, sc,
+ &tmp, 0);
+ } else
+ fd_state = FLP_IDLE;
+ break;
}
- splx(sps);
+ splx(s);
}
/*
@@ -1171,9 +1186,9 @@ static void
fdminphys(struct buf *bp)
{
struct fd_softc *sc;
- int sec, toff, tsz;
+ int sec, toff, tsz;
- if((sc = device_lookup_private(&fd_cd, DISKUNIT(bp->b_dev))) == NULL)
+ if ((sc = device_lookup_private(&fd_cd, DISKUNIT(bp->b_dev))) == NULL)
panic("fdminphys: couldn't get softc");
sec = bp->b_blkno % (sc->nsectors * sc->nheads);
@@ -1212,12 +1227,11 @@ fdmoff(struct fd_softc *fdsoftc)
if ((fd_state == FLP_MON) && selected) {
tmp = read_fdreg(FDC_CS);
- if (!(tmp & MOTORON)) {
+ if ((tmp & MOTORON) == 0) {
fddeselect();
fd_state = FLP_IDLE;
- }
- else
- callout_reset(&fdsoftc->sc_motor_ch, 10*FLP_MONDELAY,
+ } else
+ callout_reset(&fdsoftc->sc_motor_ch, 10 * FLP_MONDELAY,
(FPV)fdmotoroff, fdsoftc);
}
st_dmafree(fdsoftc, &tmp);
@@ -1231,7 +1245,7 @@ fdmoff(struct fd_softc *fdsoftc)
static void
fdtestdrv(struct fd_softc *fdsoftc)
{
- int status;
+ int status;
/*
* Select the right unit and head.
@@ -1246,12 +1260,12 @@ fdtestdrv(struct fd_softc *fdsoftc)
delay(2000000);
status = read_fdreg(FDC_CS);
- if(status & (RNF|BUSY)) {
+ if ((status & (RNF|BUSY)) != 0) {
write_fdreg(FDC_CS, IRUPT); /* reset controller */
delay(40);
}
- if(!(status & LD_T00))
+ if ((status & LD_T00) == 0)
fdsoftc->flags |= FLPF_NOTRESP;
fddeselect();
@@ -1293,14 +1307,14 @@ fdgetdefaultlabel(struct fd_softc *sc, struct disklabel *lp, int part)
static int
fdgetdisklabel(struct fd_softc *sc, dev_t dev)
{
- struct disklabel *lp;
- int part;
+ struct disklabel *lp;
+ int part;
/*
* If we already got one, get out.
*/
- if(sc->flags & FLPF_HAVELAB)
- return(0);
+ if ((sc->flags & FLPF_HAVELAB) != 0)
+ return 0;
#ifdef FLP_DEBUG
printf("fdgetdisklabel()\n");
@@ -1309,7 +1323,7 @@ fdgetdisklabel(struct fd_softc *sc, dev_t dev)
part = RAW_PART;
lp = sc->dkdev.dk_label;
fdgetdefaultlabel(sc, lp, part);
- sc->flags |= FLPF_HAVELAB;
+ sc->flags |= FLPF_HAVELAB;
- return(0);
+ return 0;
}