#include "../dev/up.c.SC11"
* UNIBUS disk driver with overlapped seeks and ECC recovery.
#define DELAY(N) { register int d; d = N; while (--d > 0); }
#define ushort unsigned short
ushort upcs1
; /* control and status register 1 */
short upwc
; /* word count register */
ushort upba
; /* UNIBUS address register */
ushort upda
; /* desired address register */
ushort upcs2
; /* control and status register 2 */
ushort upds
; /* drive Status */
ushort uper1
; /* error register 1 */
ushort upas
; /* attention summary */
ushort upla
; /* look ahead */
ushort updb
; /* data buffer */
ushort upmr
; /* maintenance */
ushort updt
; /* drive type */
ushort upsn
; /* serial number */
ushort upof
; /* offset register */
ushort updc
; /* desired cylinder address register */
ushort upcc
; /* current cylinder */
ushort uper2
; /* error register 2 */
ushort uper3
; /* error register 3 */
ushort upec1
; /* burst error bit position */
ushort upec2
; /* burst error bit pattern */
* Software extension to the upas register, so we can
* postpone starting SEARCH commands until the controller
* If upseek then we don't issue SEARCH commands but rather just
* settle for a SEEK to the correct cylinder.
* Constants controlling on-cylinder SEARCH usage.
* upSDIST/2 msec time needed to start transfer
* upRDIST/2 msec tolerable rotational latency when on-cylinder
* If we are no closer than upSDIST sectors and no further than upSDIST+upRDIST
* and in the driver then we take it as it is. Otherwise we do a SEARCH
* requesting an interrupt upSDIST sectors in advance.
#define _upSDIST 2 /* 1.0 msec */
#define _upRDIST 4 /* 2.0 msec */
* A is designed to be used as a root.
* B is suitable for a swap area.
* H is the primary storage area.
* On systems with RP06'es, we normally use only 291346 blocks of the H
* area, and use DEF or G to cover the rest of the drive. The C system
* covers the whole drive and can be used for pack-pack copying.
* Note: sizes here are for AMPEX drives with 815 cylinders.
* CDC drives can make the F,G, and H areas larger as they have 823 cylinders.
15884, 0, /* A=cyl 0 thru 26 */
33440, 27, /* B=cyl 27 thru 81 */
495520, 0, /* C=cyl 0 thru 814 */
15884, 562, /* D=cyl 562 thru 588 */
55936, 589, /* E=cyl 589 thru 680 */
81472, 681, /* F=cyl 681 thru 814 */
153824, 562, /* G=cyl 562 thru 814 */
291346, 82, /* H=cyl 82 thru 561 */
* The following defines are used in offset positioning
* when trying to recover disk errors, with the constants being
* +/- microinches. Note that header compare inhibit (HCI) is not
* tried (this makes sense only during read, in any case.)
* NB: Not all drives/controllers emulate all of these.
P1200
, M1200
, P1200
, M1200
,
* Each drive has a table uputab[i]. On this table are sorted the
* pending requests implementing an elevator algorithm (see dsort.c.)
* In the upustart() routine, each drive is independently advanced
* until it is on the desired cylinder for the next transfer and near
* the desired sector. The drive is then chained onto the uptab
* table, and the transfer is initiated by the upstart() routine.
* When the transfer is completed the driver reinvokes the upustart()
* routine to set up the next transfer.
struct buf rupbuf
; /* Buffer for raw i/o */
/* Drive commands, placed in upcs1 */
#define GO 01 /* Go bit, set in all commands */
#define PRESET 020 /* Preset drive at init or after errors */
#define OFFSET 014 /* Offset heads to try to recover error */
#define RTC 016 /* Return to center-line after OFFSET */
#define SEARCH 030 /* Search for cylinder+sector */
#define SEEK 04 /* Seek to cylinder */
#define RECAL 06 /* Recalibrate, needed after seek error */
#define DCLR 010 /* Drive clear, after error */
#define WCOM 060 /* Write */
#define RCOM 070 /* Read */
/* Other bits of upcs1 */
#define IE 0100 /* Controller wide interrupt enable */
#define TRE 040000 /* Transfer error */
#define RDY 0200 /* Transfer terminated */
/* Drive status bits of upds */
#define PIP 020000 /* Positioning in progress */
#define ERR 040000 /* Error has occurred, DCLR necessary */
#define VV 0100 /* Volume is valid, set by PRESET */
#define DPR 0400 /* Drive has been preset */
#define MOL 010000 /* Drive is online, heads loaded, etc */
#define DRY 0200 /* Drive ready */
#define CLR 040 /* Controller clear */
#define DCK 0100000 /* Ecc error occurred */
#define ECH 0100 /* Ecc error was unrecoverable */
#define WLE 04000 /* Attempt to write read-only drive */
/* Bits of upof; the offset bits above are also in this register */
#define FMT22 010000 /* 16 bits/word, must be always set */
int up_ubinfo
; /* Information about UBA usage saved here */
int up_wticks
; /* Ticks waiting for interrupt */
int upwstart
; /* Have started guardian */
* Queue an i/o request for a drive, checking first that it is in range.
* A unit start is issued if the drive is inactive, causing
* a SEARCH for the correct cylinder/sector. If the drive is
* already nearly on the money and the controller is not transferring
* we kick it to start the transfer.
timeout(upwatch
, (caddr_t
)0, HZ
);
xunit
= minor(bp
->b_dev
) & 077;
sz
= (sz
+511) >> 9; /* transfer size in 512 byte sectors */
(bn
= dkblock(bp
))+sz
> up_sizes
[xunit
&07].nblocks
) {
if (UPDK_N
+unit
<= UPDK_NMAX
)
dk_mspw
[UPDK_N
+unit
] = .0000020345;
bp
->b_cylin
= bn
/(NSECT
*NTRAC
) + up_sizes
[xunit
&07].cyloff
;
if (uptab
.b_actf
&& uptab
.b_active
== 0)
* Start activity on specified drive; called when drive is inactive
* and new transfer request arrives and also when upas indicates that
* a SEARCH command is complete.
register struct buf
*bp
, *dp
;
register struct device
*upaddr
= UPADDR
;
* Other drivers tend to say something like
* upaddr->upas = 1<<unit;
* here, but some controllers will cancel a command
* happens to be sitting in the cs1 if you clear the go
* bit by storing there (so the first is not safe).
* Thus we keep careful track of when we re-enable IE
* after an interrupt and do it only if we didn't issue
* a command which re-enabled it as a matter of course.
* We clear bits in upas in the interrupt routine, when
* no transfers are active.
if (unit
+UPDK_N
<= UPDK_NMAX
)
dk_busy
&= ~(1<<(unit
+UPDK_N
));
if ((bp
= dp
->b_actf
) == NULL
)
* Most controllers don't start SEARCH commands when transfers are
* in progress. In fact, some tend to get confused when given
* SEARCH'es during transfers, generating interrupts with neither
* RDY nor a bit in the upas register. Thus we defer
* until an interrupt when a transfer is pending.
if ((upaddr
->upcs2
& 07) != unit
)
* If we have changed packs or just initialized,
* then the volume will not be valid; if so, clear
* the drive, preset it and put in 16bit/word mode.
if ((upaddr
->upds
& VV
) == 0) {
upaddr
->upcs1
= IE
|DCLR
|GO
;
upaddr
->upcs1
= IE
|PRESET
|GO
;
if ((upaddr
->upds
& (DPR
|MOL
)) != (DPR
|MOL
))
* Do enough of the disk address decoding to determine
* which cylinder and sector the request is on.
* If we are on the correct cylinder and the desired sector
* lies between upSDIST and upSDIST+upRDIST sectors ahead of us, then
* we don't bother to SEARCH but just begin the transfer asap.
* Otherwise ask for a interrupt upSDIST sectors ahead.
sn
= (sn
+NSECT
-upSDIST
)%NSECT
;
goto search
; /* Not on-cylinder */
goto done
; /* Ok just to be on-cylinder */
csn
= (upaddr
->upla
>>6) - sn
- 1;
upaddr
->upcs1
= IE
|SEEK
|GO
;
upaddr
->upcs1
= IE
|SEARCH
|GO
;
* This unit is ready to go so
* link it onto the chain of ready disks.
if (uptab
.b_actf
== NULL
)
uptab
.b_actl
->b_forw
= dp
;
* Start a transfer; call from top level at spl5() or on interrupt.
register struct buf
*bp
, *dp
;
register struct device
*upaddr
;
* Pick a drive off the queue of ready drives, and
* perform the first transfer on its queue.
* Looping here is completely for the sake of drives which
* are not present and on-line, for which we completely clear the
if ((dp
= uptab
.b_actf
) == NULL
)
if ((bp
= dp
->b_actf
) == NULL
) {
uptab
.b_actf
= dp
->b_forw
;
* Mark the controller busy, and multi-part disk address.
* Select the unit on which the i/o is to take place.
unit
= minor(bp
->b_dev
) & 077;
cn
= up_sizes
[unit
&07].cyloff
;
if ((upaddr
->upcs2
& 07) != dn
)
up_ubinfo
= ubasetup(bp
, 1);
* If drive is not present and on-line, then
* get rid of this with an error and loop to get
* rid of the rest of its queued requests.
* (Then on to any other ready drives.)
if ((upaddr
->upds
& (DPR
|MOL
)) != (DPR
|MOL
)) {
printf("!DPR || !MOL, unit %d, ds %o", dn
, upaddr
->upds
);
if ((upaddr
->upds
& (DPR
|MOL
)) != (DPR
|MOL
)) {
dp
->b_actf
= bp
->av_forw
;
/* A funny place to do this ... */
printf("-- came back\n");
* If this is a retry, then with the 16'th retry we
* begin to try offsetting the heads to recover the data.
if (uptab
.b_errcnt
>= 16 && (bp
->b_flags
&B_WRITE
) == 0) {
upaddr
->upof
= up_offset
[uptab
.b_errcnt
& 017] | FMT22
;
upaddr
->upcs1
= IE
|OFFSET
|GO
;
while (upaddr
->upds
& PIP
)
* Now set up the transfer, retrieving the high
* 2 bits of the UNIBUS address from the information
* returned by ubasetup() for the cs1 register bits 8 and 9.
upaddr
->upda
= (tn
<< 8) + sn
;
upaddr
->upba
= up_ubinfo
;
upaddr
->upwc
= -bp
->b_bcount
/ sizeof (short);
cmd
= (up_ubinfo
>> 8) & 0x300;
if (bp
->b_flags
& B_READ
)
* This is a controller busy situation.
* Record in dk slot NUP+UPDK_N (after last drive)
* unless there aren't that many slots reserved for
* us in which case we record this as a drive busy
* (if there is room for that).
dk_wds
[unit
] += bp
->b_bcount
>>6;
* Handle a device interrupt.
* If the transferring drive needs attention, service it
* retrying on error or beginning next transfer.
* Service all other ready drives, calling ustart to transfer
* their blocks to the ready queue in uptab, and then restart
* the controller if there is anything to do.
register struct buf
*bp
, *dp
;
register struct device
*upaddr
= UPADDR
;
int as
= upaddr
->upas
& 0377;
* The drive is transferring, thus the hardware
* (say the designers) will only interrupt when the transfer
* completes; check for it anyways.
if ((upaddr
->upcs1
& RDY
) == 0) {
printf("!RDY: cs1 %o, ds %o, wc %d\n", upaddr
->upcs1
,
upaddr
->upds
, upaddr
->upwc
);
printf("as=%d act %d %d %d\n", as
, uptab
.b_active
,
uputab
[0].b_active
, uputab
[1].b_active
);
* Mark drive not busy, and check for an
* error condition which may have resulted from the transfer.
if (UPDK_N
+unit
<= UPDK_NMAX
)
dk_busy
&= ~(1<<(UPDK_N
+unit
));
if ((upaddr
->upcs2
& 07) != unit
)
if ((upaddr
->upds
&ERR
) || (upaddr
->upcs1
&TRE
)) {
* An error occurred, indeed. Select this unit
* to get at the drive status (a SEARCH may have
* intervened to change the selected unit), and
* wait for the command which caused the interrupt
while ((upaddr
->upds
& DRY
) == 0)
* After 28 retries (16 w/o servo offsets, and then
* 12 with servo offsets), or if we encountered
* an error because the drive is write-protected,
* give up. Print an error message on the last 2
* retries before a hard failure.
if (++uptab
.b_errcnt
> 28 || upaddr
->uper1
&WLE
)
uptab
.b_active
= 0; /* To force retry */
cs2
= (int)upaddr
->upcs2
;
deverror(bp
, (int)upaddr
->upcs2
,
* If this was a correctible ECC error, let upecc
* do the dirty work to correct it. If upecc
* starts another READ for the rest of the data
* then it returns 1 (having set uptab.b_active).
* Otherwise we are done and fall through to
if ((upaddr
->uper1
&(DCK
|ECH
))==DCK
&& upecc(upaddr
, bp
))
* Clear the drive and, every 4 retries, recalibrate
* to hopefully help clear up seek positioning problems.
upaddr
->upcs1
= TRE
|IE
|DCLR
|GO
;
if ((uptab
.b_errcnt
&07) == 4) {
upaddr
->upcs1
= RECAL
|GO
|IE
;
while(upaddr
->upds
& PIP
)
if (uptab
.b_errcnt
== 28 && cs2
&(NEM
|MXF
)) {
* If we are still noted as active, then no
* (further) retries are necessary.
* Make sure the correct unit is selected,
* return it to centerline if necessary, and mark
* this i/o complete, starting the next transfer
* on this drive with the upustart routine (if any).
if (uptab
.b_errcnt
>= 16) {
upaddr
->upcs1
= RTC
|GO
|IE
;
while (upaddr
->upds
& PIP
)
uptab
.b_actf
= dp
->b_forw
;
dp
->b_actf
= bp
->av_forw
;
bp
->b_resid
= (-upaddr
->upwc
* sizeof(short));
printf("resid %d ds %o er? %o %o %o\n",
bp
->b_resid
, upaddr
->upds
,
upaddr
->uper1
, upaddr
->uper2
, upaddr
->uper3
);
* If we have a unit with an outstanding SEARCH,
* and the hardware indicates the unit requires attention,
* the bring the drive to the ready queue.
* Finally, if the controller is not transferring
* start it if any drives are now ready to transfer.
for (unit
= 0; unit
< NUP
; unit
++)
if ((as
|oupsoftas
) & (1<<unit
)) {
if (uptab
.b_actf
&& uptab
.b_active
== 0)
physio(upstrategy
, &rupbuf
, dev
, B_READ
, minphys
);
physio(upstrategy
, &rupbuf
, dev
, B_WRITE
, minphys
);
* Correct an ECC error, and restart the i/o to complete
* the transfer if necessary. This is quite complicated because
* the transfer may be going to an odd memory address base and/or
* across a page boundary.
register struct device
*up
;
struct uba_regs
*ubp
= (struct uba_regs
*)UBA0
;
int reg
, bit
, byte
, npf
, mask
, o
, cmd
, ubaddr
;
* Npf is the number of sectors transferred before the sector
* containing the ECC error, and reg is the UBA register
* mapping (the first part of) the transfer.
* O is offset within a memory page of the first byte transferred.
npf
= btop((up
->upwc
* sizeof(short)) + bp
->b_bcount
) - 1;
reg
= btop(up_ubinfo
&0x3ffff) + npf
;
o
= (int)bp
->b_un
.b_addr
& PGOFSET
;
printf("%D ", bp
->b_blkno
+npf
);
up
->upof
= FMT22
; /* == RTC ???? */
* Flush the buffered data path, and compute the
* byte and bit position of the error. The variable i
* is the byte offset in the transfer, the variable byte
* is the offset from a page boundary in main memory.
ubp
->uba_dpr
[(up_ubinfo
>>28)&0x0f] |= BNE
;
i
= up
->upec1
- 1; /* -1 makes 0 origin */
* Correct while possible bits remain of mask. Since mask
* contains 11 bits, we continue while the bit offset is > -11.
* Also watch out for end of this block and the end of the whole
while (i
< 512 && (int)ptob(npf
)+i
< bp
->b_bcount
&& bit
> -11) {
addr
= ptob(ubp
->uba_map
[reg
+btop(byte
)].pg_pfnum
)+
putmemc(addr
, getmemc(addr
)^(mask
<<bit
));
uptab
.b_active
++; /* Either complete or continuing... */
* Have to continue the transfer... clear the drive,
* and compute the position where the transfer is to continue.
* We have completed npf+1 sectors of the transfer already;
* restart at offset o of next sector (i.e. in UBA register reg+1).
up
->upcs1
= TRE
|IE
|DCLR
|GO
;
sn
= bn
%(NSECT
*NTRAC
) + npf
+ 1;
up
->upda
= (tn
<< 8) | sn
;
ubaddr
= (int)ptob(reg
+1) + o
;
cmd
= (ubaddr
>> 8) & 0x300;
* Reset driver after UBA init.
* Cancel software state of all pending transfers
* and restart all units and the controller.
DELAY(15000000); /* give it time to self-test */
uptab
.b_actf
= uptab
.b_actl
= 0;
printf("<%d>", (up_ubinfo
>>28)&0xf);
UPADDR
->upcs2
= CLR
; /* clear controller */
for (unit
= 0; unit
< NUP
; unit
++) {
uputab
[unit
].b_active
= 0;
* Wake up every second and if an interrupt is pending
* but nothing has happened increment a counter.
* If nothing happens for 20 seconds, reset the controller
timeout(upwatch
, (caddr_t
)0, HZ
);
if (uptab
.b_active
== 0) {
for (i
= 0; i
< NUP
; i
++)
up_wticks
= 0; /* idling */
printf("LOST INTERRUPT RESET");