* RX02 floppy disk device driver
* -- WARNING, NOT THOROUGHLY TESTED --
#include "../machine/pte.h"
#include "../vax/nexus.h"
#include "../vaxuba/ubavar.h"
#include "../vaxuba/ubareg.h"
#include "../vaxuba/rxreg.h"
/* per-controller data */
int rxc_state
; /* controller state */
#define RXS_READ 1 /* read started */
#define RXS_EMPTY 2 /* empty started */
#define RXS_FILL 3 /* fill started */
#define RXS_WRITE 4 /* write started */
#define RXS_FORMAT 5 /* format started */
#define RXS_RDSTAT 6 /* status read started */
#define RXS_RDERR 7 /* error read started */
#define RXS_IDLE 8 /* device is idle */
u_short rxc_rxcs
; /* extended error status */
#define RX_MAXTIMEOUT 30 /* # seconds to wait before giving up */
struct buf rrxbuf
[NRX
]; /* buffers for raw I/O */
struct buf erxbuf
[NRX
]; /* buffers for reading error status */
struct buf rxutab
[NRX
]; /* per drive buffer queue heads */
int sc_flags
; /* drive status flags */
#define RXF_DBLDEN 0x01 /* use double density */
#define RXF_DIRECT 0x02 /* use direct sector mapping */
#define RXF_TRKZERO 0x04 /* start mapping on track 0 */
#define RXF_DEVTYPE 0x07 /* density and mapping flags */
#define RXF_OPEN 0x10 /* open */
#define RXF_DDMK 0x20 /* deleted-data mark detected */
#define RXF_USEWDDS 0x40 /* write deleted-data sector */
int sc_csbits
; /* constant bits for CS register */
int sc_tocnt
; /* for watchdog routine */
caddr_t sc_uaddr
; /* save orig. unibus address while */
/* doing multisector transfers */
long sc_bcnt
; /* save total transfer count for */
/* multisector transfers */
short rxxt
[4]; /* error code dump from controller */
/* End of per-drive data */
struct uba_device
*rxdinfo
[NRX
];
struct uba_ctlr
*rxminfo
[NFX
];
int rxprobe(), rxslave(), rxattach(), rxdgo(), rxintr(), rxwatch(), rxphys();
u_short rxstd
[] = { 0177170, 0177150, 0 };
struct uba_driver fxdriver
=
{ rxprobe
, rxslave
, rxattach
, rxdgo
, rxstd
, "rx", rxdinfo
, "fx", rxminfo
};
#define RXUNIT(dev) (minor(dev)>>3)
#define MASKREG(reg) (reg&0xffff)
/* constants related to floppy data capacity */
#define RXSECS 2002 /* # sectors on a floppy */
#define DDSTATE (sc->sc_flags&RXF_DBLDEN)
#define NBPS (DDSTATE ? 256 : 128) /* # bytes per sector */
#define NWPS (DDSTATE ? 128 : 64) /* # words per sector */
#define RXSIZE (DDSTATE ? 512512 : 256256) /* # bytes per disk */
#define SECSHFT (DDSTATE ? 8 : 7) /* # bits to shift for sctr # */
#define SECMASK (DDSTATE ? 0xff : 0x7f) /* shifted-out bits of offset */
#define B_CTRL 0x80000000 /* control (format) request */
register int br
, cvec
; /* value-result */
struct rxdevice
*rxaddr
= (struct rxdevice
*)reg
;
br
= 0; cvec
= br
; br
= cvec
;
return (sizeof (*rxaddr
));
return (ui
->ui_slave
== 0 || ui
->ui_slave
== 1);
register int unit
= RXUNIT(dev
);
register struct rx_softc
*sc
;
register struct uba_device
*ui
;
register struct rxdevice
*rxaddr
;
if (unit
>= NRX
|| (ui
= rxdinfo
[unit
]) == 0 || ui
->ui_alive
== 0)
if (sc
->sc_flags
& RXF_OPEN
)
sc
->sc_flags
= RXF_OPEN
| (minor(dev
) & RXF_DEVTYPE
);
sc
->sc_csbits
|= ui
->ui_slave
== 0 ? RX_DRV0
: RX_DRV1
;
sc
->sc_csbits
|= minor(dev
) & RXF_DBLDEN
? RX_DDEN
: RX_SDEN
;
rxaddr
= (struct rxdevice
*)rxminfo
[unit
]->um_addr
;
if (rxaddr
->rxcs
== 0x800) {
* If the drive subsystem has been powered down,
* the rx211 controller must be initialized.
rxreset(rxminfo
[unit
]->um_ubanum
);
register struct rx_softc
*sc
= &rx_softc
[RXUNIT(dev
)];
sc
->sc_flags
&= ~RXF_OPEN
;
register struct uba_ctlr
*um
;
int s
, unit
= RXUNIT(bp
->b_dev
);
if (ui
== 0 || ui
->ui_alive
== 0)
if (bp
->b_blkno
< 0 || (bp
->b_blkno
* DEV_BSIZE
) > RXSIZE
)
dp
= &rxutab
[ui
->ui_unit
];
bp
->b_resid
= bp
->b_bcount
;
sc
->sc_uaddr
= bp
->b_un
.b_addr
;
sc
->sc_bcnt
= bp
->b_bcount
;
bad
: bp
->b_flags
|= B_ERROR
;
* Put this unit on the ready queue for the controller,
* unless it is already there.
register struct uba_device
*ui
;
dp
= &rxutab
[ui
->ui_unit
];
if (um
->um_tab
.b_actf
== NULL
)
um
->um_tab
.b_actl
->b_forw
= dp
;
* Sector mapping routine.
* Two independent sets of choices are available:
* (a) The first logical sector may either be on track 1 or track 0.
* (b) The sectors on a track may either be taken in 2-for-1 interleaved
* This gives a total of four possible mapping schemes.
* Physical tracks on the RX02 are numbered 0-76. Physical sectors on
* each track are numbered 1-26.
* When interleaving is used, sectors on the first logical track are
* taken in the order 1, 3, 5, ..., 25, 2, 4, 6, ..., 26. A skew of
* six sectors per track is also used (to allow time for the heads to
* move); hence, the sectors on the second logical track are taken in
* the order 7, 9, 11, ..., 25, 1, 3, 5, 8, 10, 12, ..., 26, 2, 4, 6;
* the third logical track starts with sector 13; and so on.
* When the mapping starts with track 1, track 0 is the last logical
* track, and this track is always handled directly (without inter-
* leaving), even when the rest of the disk is interleaved. (This is
* still compatible with DEC RT-11, which does not use track 0 at all.)
rxmap(bp
, psector
, ptrack
)
register int lt
, ls
, ptoff
;
struct rx_softc
*sc
= &rx_softc
[RXUNIT(bp
->b_dev
)];
ls
= ( bp
->b_blkno
* DEV_BSIZE
+ ( sc
->sc_bcnt
- bp
->b_resid
)) / NBPS
;
* The "physical track offset" (ptoff) takes the
* starting physical track (0 or 1) and the desired
* interleaving into account. If lt+ptoff >= 77,
* then interleaving is not performed.
if (sc
->sc_flags
&RXF_DIRECT
)
if (!sc
->sc_flags
&RXF_TRKZERO
)
ls
= ((ls
<< 1) + (ls
>= 13) + (6*lt
)) % 26;
*ptrack
= (lt
+ ptoff
) % 77;
* Controller start routine
register struct uba_ctlr
*um
;
register struct rxdevice
*rxaddr
;
register struct rx_ctlr
*rxc
;
register struct rx_softc
*sc
;
if ((dp
= um
->um_tab
.b_actf
) == NULL
)
if ((bp
= dp
->b_actf
) == NULL
) {
um
->um_tab
.b_actf
= dp
->b_forw
;
unit
= RXUNIT(bp
->b_dev
);
rxaddr
= (struct rxdevice
*)um
->um_addr
;
rxc
= &rx_ctlr
[um
->um_ctlr
];
bp
->b_bcount
= bp
->b_resid
;
rxtimo(bp
->b_dev
); /* start watchdog */
if (bp
->b_flags
&B_CTRL
) { /* format */
rxc
->rxc_state
= RXS_FORMAT
;
rxaddr
->rxcs
= RX_FORMAT
| sc
->sc_csbits
;
while ((rxaddr
->rxcs
&RX_TREQ
) == 0)
if (bp
->b_flags
&B_READ
) { /* read */
rxmap(bp
, §or
, &track
);
rxc
->rxc_state
= RXS_READ
;
rxaddr
->rxcs
= RX_READ
| sc
->sc_csbits
;
printf("rxstart/r: tr=%d, sc=%d, bl=%d, cnt=%d\n",
track
, sector
, bp
->b_blkno
, bp
->b_bcount
);
while ((rxaddr
->rxcs
&RX_TREQ
) == 0)
rxaddr
->rxdb
= (u_short
)sector
;
while ((rxaddr
->rxcs
&RX_TREQ
) == 0)
rxaddr
->rxdb
= (u_short
)track
;
rxc
->rxc_state
= RXS_FILL
; /* write */
(void) ubago(rxdinfo
[unit
]);
register struct rxdevice
*rxaddr
= (struct rxdevice
*)um
->um_addr
;
int ubinfo
= um
->um_ubinfo
;
struct buf
*bp
= um
->um_tab
.b_actf
->b_actf
;
struct rx_softc
*sc
= &rx_softc
[RXUNIT(bp
->b_dev
)];
struct rx_ctlr
*rxc
= &rx_ctlr
[um
->um_ctlr
];
rxaddr
->rxcs
= um
->um_cmd
| ((ubinfo
& 0x30000) >> 4) | sc
->sc_csbits
;
if (rxc
->rxc_state
!= RXS_RDERR
) {
while ((rxaddr
->rxcs
&RX_TREQ
) == 0)
rxaddr
->rxdb
= bp
->b_bcount
>> 1;
while ((rxaddr
->rxcs
&RX_TREQ
) == 0)
int unit
= RXUNIT(dev
), sector
, track
;
struct uba_ctlr
*um
= rxminfo
[unit
];
register struct rxdevice
*rxaddr
;
register struct buf
*bp
, *dp
;
register struct rx_softc
*sc
= &rx_softc
[unit
];
struct uba_device
*ui
= rxdinfo
[unit
];
register struct rx_ctlr
*rxc
;
if (!um
->um_tab
.b_active
)
rxaddr
= (struct rxdevice
*)um
->um_addr
;
rxc
= &rx_ctlr
[um
->um_ctlr
];
printf("rxintr: dev=%d, state=0x%x, status=0x%x\n",
unit
, rxc
->rxc_state
, rxaddr
->rxcs
);
if ((rxaddr
->rxcs
& RX_ERR
) &&
rxc
->rxc_state
!= RXS_RDSTAT
&& rxc
->rxc_state
!= RXS_RDERR
)
switch (rxc
->rxc_state
) {
* Incomplete commands. Perform next step
* and return. Note that b_active is set on
* entrance and, therefore, also on exit.
if (rxaddr
->rxdb
& RXES_DDMARK
)
sc
->sc_flags
|= RXF_DDMK
;
sc
->sc_flags
&= ~RXF_DDMK
;
rxc
->rxc_state
= RXS_EMPTY
;
rxc
->rxc_state
= RXS_WRITE
;
if (sc
->sc_flags
& RXF_USEWDDS
) {
rxaddr
->rxcs
= RX_WDDS
| sc
->sc_csbits
;
sc
->sc_flags
&= ~RXF_USEWDDS
;
rxaddr
->rxcs
= RX_WRITE
| sc
->sc_csbits
;
while ((rxaddr
->rxcs
&RX_TREQ
) == 0)
rxmap(bp
, §or
, &track
);
while ((rxaddr
->rxcs
&RX_TREQ
) == 0)
* Possibly completed command.
if (rxaddr
->rxdb
&RXES_READY
)
rxmap(bp
, §or
, &track
);
printf("rx%d: hard error, lsn%d (trk %d psec %d) ",
unit
, bp
->b_blkno
* (NBPS
/ DEV_BSIZE
),
printf("cs=%b, db=%b, err=%x\n", MASKREG(er
->rxcs
),
RXCS_BITS
, MASKREG(er
->rxdb
), RXES_BITS
,
printf("errstatus: 0x%x, 0x%x, 0x%x, 0x%x\n", er
->rxxt
[0],
er
->rxxt
[1], er
->rxxt
[2], er
->rxxt
[3]);
printf("rx%d: state %d (reset)\n", unit
, rxc
->rxc_state
);
* (a) Give up now if a format (ioctl) was in progress, or if a
* density error was detected.
* (b) Retry up to nine times if a CRC (data) error was detected,
* then give up if the error persists.
* (c) In all other cases, reinitialize the drive and try the
* operation once more before giving up.
if (rxc
->rxc_state
== RXS_FORMAT
|| (rxaddr
->rxdb
&RXES_DENERR
))
if (rxaddr
->rxdb
& RXES_CRCERR
) {
if (++bp
->b_errcnt
>= 10)
/* no way to get an interrupt for "init done", so just wait */
while ((rxaddr
->rxdb
&RX_DONE
) == 0)
* In case we already have UNIBUS resources, give
* them back since we reallocate things in rxstart.
* Also, the active flag must be reset, otherwise rxstart
* will refuse to restart the transfer
* Density errors are not noted on the console since the
* only way to determine the density of an unknown disk
* is to try one density or the other at random and see
* which one doesn't give a density error.
if (rxaddr
->rxdb
& RXES_DENERR
) {
rxc
->rxc_state
= RXS_RDSTAT
;
rxaddr
->rxcs
= RX_RDSTAT
| sc
->sc_csbits
;
* A hard error (other than not ready or density) has occurred.
* Read the extended error status information.
* Before doing this, save the current CS and DB register values,
* because the read error status operation may modify them.
* Insert buffer with request at the head of the queue.
bp
->b_un
.b_addr
= (caddr_t
)er
->rxxt
;
bp
->b_bcount
= sizeof (er
->rxxt
);
bp
->b_flags
&= ~(B_DIRTY
|B_UAREA
|B_PHYS
|B_PAGET
);
if (um
->um_tab
.b_actf
->b_actf
== NULL
)
um
->um_tab
.b_actf
->b_actl
= bp
;
bp
->b_forw
= um
->um_tab
.b_actf
->b_actf
;
um
->um_tab
.b_actf
->b_actf
= bp
;
rxc
->rxc_state
= RXS_RDERR
;
if ((bp
->b_resid
-= NBPS
) > 0) {
bp
->b_un
.b_addr
= sc
->sc_uaddr
;
bp
->b_bcount
= sc
->sc_bcnt
;
rxc
->rxc_state
= RXS_IDLE
;
um
->um_tab
.b_actf
= dp
->b_forw
;
dp
->b_actf
= bp
->av_forw
;
* If this controller has more work to do,
struct rx_softc
*sc
= &rx_softc
[RXUNIT(bp
->b_dev
)];
register struct rx_softc
*sc
= &rx_softc
[RXUNIT(dev
)];
if (sc
->sc_flags
& RXF_OPEN
)
timeout(rxtimo
, (caddr_t
)dev
, hz
);
if (++sc
->sc_tocnt
< RX_MAXTIMEOUT
)
printf("rx: timeout dev 0x%x\n", dev
);
register struct uba_ctlr
*um
;
register struct rxdevice
*rxaddr
;
for (ctlr
= 0; ctlr
< NFX
; ctlr
++) {
if ((um
= rxminfo
[ctlr
]) == 0 || um
->um_ubanum
!= uban
||
rx_ctlr
[ctlr
].rxc_state
= RXS_IDLE
;
rxaddr
= (struct rxdevice
*)um
->um_addr
;
while ((rxaddr
->rxdb
&RX_DONE
) == 0)
* make the world believe this is a
struct rx_softc
*sc
= &rx_softc
[unit
];
if (uio
->uio_offset
+ uio
->uio_resid
> RXSIZE
)
if (uio
->uio_offset
< 0 || (uio
->uio_offset
& SECMASK
) != 0)
return (physio(rxstrategy
, &rrxbuf
[unit
], dev
, B_READ
, minphys
, uio
));
struct rx_softc
*sc
= &rx_softc
[unit
];
if (uio
->uio_offset
+ uio
->uio_resid
> RXSIZE
)
if (uio
->uio_offset
< 0 || (uio
->uio_offset
& SECMASK
) != 0)
return(physio(rxstrategy
, &rrxbuf
[unit
], dev
, B_WRITE
, minphys
, uio
));
* processes three kinds of requests:
* (1) Set density (i.e., format the diskette) according to
* that specified by the open device.
* (2) Arrange for the next sector to be written with a deleted-
* (3) Report whether the last sector read had a deleted-data mark
* (by returning with an EIO error code if it did).
* Requests relating to deleted-data marks can be handled right here.
* A "set density" (format) request, however, must additionally be
* processed through "rxstart", just like a read or write request.
rxioctl(dev
, cmd
, data
, flag
)
struct rx_softc
*sc
= &rx_softc
[unit
];
sc
->sc_flags
|= RXF_USEWDDS
;
*(int *)data
= sc
->sc_flags
& RXF_DDMK
;
* Initiate a format command.
struct rx_softc
*sc
= &rx_softc
[unit
];
while (bp
->b_flags
& B_BUSY
)
bp
->b_flags
= B_BUSY
| B_CTRL
;
sc
->sc_flags
= RXS_FORMAT
;
if (bp
->b_flags
& B_ERROR
)