1: /*
2: * Copyright (c) 1986 Regents of the University of California.
3: * All rights reserved. The Berkeley software License Agreement
4: * specifies the terms and conditions for redistribution.
5: *
6: * @(#)rk.c 1.5 (2.11BSD GTE) 1997/1/18
7: */
8:
9: /*
10: * RK05 device drive
11: */
12:
13: #include "rk.h"
14:
15: #if NRK > 0
16: #include "param.h"
17: #include "systm.h"
18: #include "buf.h"
19: #include "conf.h"
20: #include "user.h"
21: #include "dk.h"
22: #include "rkreg.h"
23: #include "syslog.h"
24: #include "map.h"
25: #include "uba.h"
26:
27: #define NRKBLK 4872 /* Number of blocks per drive */
28:
29: struct rkdevice *RKADDR;
30:
31: struct buf rktab;
32:
33: #define rkunit(dev) minor(dev)
34:
35: #ifdef UCB_METER
36: static int rk_dkn = -1; /* number for iostat */
37: #endif
38:
39: #ifdef SOFUB_MAP
40: static int rksoftmap = -1; /* -1 = OK to check for softmap
41: * 0 = Never use softmap
42: * 1 = Always use softmap
43: */
44: #endif
45:
46: rkattach(addr, unit)
47: struct rkdevice *addr;
48: {
49: #ifdef UCB_METER
50: if (rk_dkn < 0)
51: dk_alloc(&rk_dkn, 1, "rk", 25L * 12L * 256L);
52: #endif
53:
54: if (unit != 0)
55: return(0);
56: #ifdef SOFUB_MAP
57: if (!ubmap && rksoftmap == -1)
58: rksoftmap = 1;
59: #endif
60: RKADDR = addr;
61: return(1);
62: }
63:
64: rkopen(dev, flag)
65: dev_t dev;
66: int flag;
67: {
68: register int unit = rkunit(dev);
69:
70: if (unit >= NRK || !RKADDR)
71: return (ENXIO);
72: return (0);
73: }
74:
75: rkstrategy(bp)
76: register struct buf *bp;
77: {
78: register int s;
79: register int unit;
80:
81: unit = rkunit(bp->b_dev);
82: if (unit >= NRK || !RKADDR) {
83: bp->b_error = ENXIO;
84: goto bad;
85: }
86: if (bp->b_blkno >= NRKBLK) {
87: bp->b_error = EINVAL;
88: bad: bp->b_flags |= B_ERROR;
89: iodone(bp);
90: return;
91: }
92: #ifdef SOFUB_MAP
93: if (rksoftmap == 1)
94: {
95: if (sofub_alloc(bp) == 0)
96: return;
97: }
98: else
99: #endif
100: mapalloc(bp);
101: bp->av_forw = (struct buf *)NULL;
102: s = splbio();
103: if(rktab.b_actf == NULL)
104: rktab.b_actf = bp;
105: else
106: rktab.b_actl->av_forw = bp;
107: rktab.b_actl = bp;
108: if(rktab.b_active == NULL)
109: rkstart();
110: splx(s);
111: }
112:
113: rkstart()
114: {
115: register struct rkdevice *rkaddr = RKADDR;
116: register struct buf *bp;
117: register com;
118: daddr_t bn;
119: int dn, cn, sn;
120:
121: if ((bp = rktab.b_actf) == NULL)
122: return;
123: rktab.b_active++;
124: bn = bp->b_blkno;
125: dn = minor(bp->b_dev);
126: cn = bn / 12;
127: sn = bn % 12;
128: rkaddr->rkda = (dn << 13) | (cn << 4) | sn;
129: rkaddr->rkba = bp->b_un.b_addr;
130: rkaddr->rkwc = -(bp->b_bcount >> 1);
131: com = ((bp->b_xmem & 3) << 4) | RKCS_IDE | RKCS_GO;
132: if(bp->b_flags & B_READ)
133: com |= RKCS_RCOM;
134: else
135: com |= RKCS_WCOM;
136: rkaddr->rkcs = com;
137:
138: #ifdef UCB_METER
139: if (rk_dkn >= 0) {
140: dk_busy |= 1<<rk_dkn;
141: dk_seek[rk_dkn]++;
142: dk_wds[rk_dkn] += bp->b_bcount>>6;
143: }
144: #endif
145: }
146:
147: rkintr()
148: {
149: register struct rkdevice *rkaddr = RKADDR;
150: register struct buf *bp;
151:
152: if (rktab.b_active == NULL)
153: return;
154: #ifdef UCB_METER
155: if (rk_dkn >= 0)
156: dk_busy &= ~(1<<rk_dkn);
157: #endif
158: bp = rktab.b_actf;
159: rktab.b_active = NULL;
160: if (rkaddr->rkcs & RKCS_ERR) {
161: while ((rkaddr->rkcs & RKCS_RDY) == 0)
162: ;
163: if (rkaddr->rker & RKER_WLO)
164: /*
165: * Give up on write locked devices
166: * immediately.
167: */
168: uprintf("rk%d: write locked\n", minor(bp->b_dev));
169: else
170: {
171: harderr(bp, "rk");
172: log(LOG_NOTICE,"er=%b ds=%b\n", rkaddr->rker, RKER_BITS,
173: rkaddr->rkds, RK_BITS);
174: rkaddr->rkcs = RKCS_RESET | RKCS_GO;
175: while((rkaddr->rkcs & RKCS_RDY) == 0)
176: ;
177: if (++rktab.b_errcnt <= 10) {
178: rkstart();
179: return;
180: }
181: }
182: bp->b_flags |= B_ERROR;
183: }
184: rktab.b_errcnt = 0;
185: rktab.b_actf = bp->av_forw;
186: bp->b_resid = -(rkaddr->rkwc << 1);
187: #ifdef SOFUB_MAP
188: if (rksoftmap == 1)
189: sofub_relse(bp, bp->b_bcount - bp->b_resid);
190: #endif
191: iodone(bp);
192: rkstart();
193: }
194:
195: /*
196: * Hack - no one is using these anyhow, especially for swapping.
197: */
198: daddr_t
199: rksize(dev)
200: dev_t dev;
201: {
202: return(NRKBLK);
203: }
204: #endif NRK
Defined functions
Defined variables
rktab
defined in line
31; used 13 times
Defined macros