hdc9224.c revision 1.17.2.5 1 1.17.2.5 nathanw /* $NetBSD: hdc9224.c,v 1.17.2.5 2002/11/11 22:06:04 nathanw Exp $ */
2 1.17.2.2 nathanw /*
3 1.17.2.2 nathanw * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
4 1.17.2.2 nathanw * All rights reserved.
5 1.17.2.2 nathanw *
6 1.17.2.2 nathanw * This code is derived from software contributed to Ludd by Bertram Barth.
7 1.17.2.2 nathanw *
8 1.17.2.2 nathanw * Redistribution and use in source and binary forms, with or without
9 1.17.2.2 nathanw * modification, are permitted provided that the following conditions
10 1.17.2.2 nathanw * are met:
11 1.17.2.2 nathanw * 1. Redistributions of source code must retain the above copyright
12 1.17.2.2 nathanw * notice, this list of conditions and the following disclaimer.
13 1.17.2.2 nathanw * 2. Redistributions in binary form must reproduce the above copyright
14 1.17.2.2 nathanw * notice, this list of conditions and the following disclaimer in the
15 1.17.2.2 nathanw * documentation and/or other materials provided with the distribution.
16 1.17.2.2 nathanw * 3. All advertising materials mentioning features or use of this software
17 1.17.2.2 nathanw * must display the following acknowledgement:
18 1.17.2.2 nathanw * This product includes software developed at Ludd, University of
19 1.17.2.2 nathanw * Lule}, Sweden and its contributors.
20 1.17.2.2 nathanw * 4. The name of the author may not be used to endorse or promote products
21 1.17.2.2 nathanw * derived from this software without specific prior written permission
22 1.17.2.2 nathanw *
23 1.17.2.2 nathanw * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.17.2.2 nathanw * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.17.2.2 nathanw * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.17.2.2 nathanw * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.17.2.2 nathanw * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.17.2.2 nathanw * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.17.2.2 nathanw * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.17.2.2 nathanw * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.17.2.2 nathanw * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.17.2.2 nathanw * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.17.2.2 nathanw */
34 1.17.2.2 nathanw
35 1.17.2.2 nathanw /*
36 1.17.2.2 nathanw * with much help from (in alphabetical order):
37 1.17.2.2 nathanw * Jeremy
38 1.17.2.2 nathanw * Roger Ivie
39 1.17.2.2 nathanw * Rick Macklem
40 1.17.2.2 nathanw * Mike Young
41 1.17.2.2 nathanw *
42 1.17.2.2 nathanw * Rewritten by Ragge 25 Jun 2000. New features:
43 1.17.2.2 nathanw * - Uses interrupts instead of polling to signal ready.
44 1.17.2.2 nathanw * - Can cooperate with the SCSI routines WRT. the DMA area.
45 1.17.2.2 nathanw *
46 1.17.2.2 nathanw * TODO:
47 1.17.2.2 nathanw * - Floppy support missing.
48 1.17.2.2 nathanw * - Bad block forwarding missing.
49 1.17.2.2 nathanw * - Statistics collection.
50 1.17.2.2 nathanw */
51 1.17.2.2 nathanw #undef RDDEBUG
52 1.17.2.2 nathanw
53 1.17.2.2 nathanw #include <sys/param.h>
54 1.17.2.2 nathanw #include <sys/systm.h>
55 1.17.2.2 nathanw #include <sys/kernel.h>
56 1.17.2.2 nathanw #include <sys/conf.h>
57 1.17.2.2 nathanw #include <sys/file.h>
58 1.17.2.2 nathanw #include <sys/stat.h>
59 1.17.2.2 nathanw #include <sys/ioctl.h>
60 1.17.2.2 nathanw #include <sys/buf.h>
61 1.17.2.2 nathanw #include <sys/proc.h>
62 1.17.2.2 nathanw #include <sys/user.h>
63 1.17.2.2 nathanw #include <sys/device.h>
64 1.17.2.2 nathanw #include <sys/dkstat.h>
65 1.17.2.2 nathanw #include <sys/disklabel.h>
66 1.17.2.2 nathanw #include <sys/disk.h>
67 1.17.2.2 nathanw #include <sys/syslog.h>
68 1.17.2.2 nathanw #include <sys/reboot.h>
69 1.17.2.2 nathanw
70 1.17.2.2 nathanw #include <uvm/uvm_extern.h>
71 1.17.2.2 nathanw
72 1.17.2.2 nathanw #include <ufs/ufs/dinode.h> /* For BBSIZE */
73 1.17.2.2 nathanw #include <ufs/ffs/fs.h>
74 1.17.2.2 nathanw
75 1.17.2.2 nathanw #include <machine/pte.h>
76 1.17.2.2 nathanw #include <machine/sid.h>
77 1.17.2.2 nathanw #include <machine/cpu.h>
78 1.17.2.2 nathanw #include <machine/uvax.h>
79 1.17.2.2 nathanw #include <machine/ka410.h>
80 1.17.2.2 nathanw #include <machine/vsbus.h>
81 1.17.2.2 nathanw #include <machine/rpb.h>
82 1.17.2.2 nathanw #include <machine/scb.h>
83 1.17.2.2 nathanw
84 1.17.2.2 nathanw #include <dev/mscp/mscp.h> /* For DEC disk encoding */
85 1.17.2.2 nathanw
86 1.17.2.2 nathanw #include <vax/vsa/hdc9224.h>
87 1.17.2.2 nathanw
88 1.17.2.2 nathanw #include "ioconf.h"
89 1.17.2.2 nathanw #include "locators.h"
90 1.17.2.2 nathanw
91 1.17.2.2 nathanw
92 1.17.2.2 nathanw /*
93 1.17.2.2 nathanw * on-disk geometry block
94 1.17.2.2 nathanw */
95 1.17.2.2 nathanw #define _aP __attribute__ ((packed)) /* force byte-alignment */
96 1.17.2.2 nathanw struct rdgeom {
97 1.17.2.2 nathanw char mbz[10]; /* 10 bytes of zero */
98 1.17.2.2 nathanw long xbn_count _aP; /* number of XBNs */
99 1.17.2.2 nathanw long dbn_count _aP; /* number of DBNs */
100 1.17.2.2 nathanw long lbn_count _aP; /* number of LBNs (Logical-Block-Numbers) */
101 1.17.2.2 nathanw long rbn_count _aP; /* number of RBNs (Replacement-Block-Numbers) */
102 1.17.2.2 nathanw short nspt; /* number of sectors per track */
103 1.17.2.2 nathanw short ntracks; /* number of tracks */
104 1.17.2.2 nathanw short ncylinders; /* number of cylinders */
105 1.17.2.2 nathanw short precomp; /* first cylinder for write precompensation */
106 1.17.2.2 nathanw short reduced; /* first cylinder for reduced write current */
107 1.17.2.2 nathanw short seek_rate; /* seek rate or zero for buffered seeks */
108 1.17.2.2 nathanw short crc_eec; /* 0 if CRC, 1 if ECC is being used */
109 1.17.2.2 nathanw short rct; /* "replacement control table" (RCT) */
110 1.17.2.2 nathanw short rct_ncopies; /* number of copies of the RCT */
111 1.17.2.2 nathanw long media_id _aP; /* media identifier */
112 1.17.2.2 nathanw short interleave; /* sector-to-sector interleave */
113 1.17.2.2 nathanw short headskew; /* head-to-head skew */
114 1.17.2.2 nathanw short cylskew; /* cylinder-to-cylinder skew */
115 1.17.2.2 nathanw short gap0_size; /* size of GAP 0 in the MFM format */
116 1.17.2.2 nathanw short gap1_size; /* size of GAP 1 in the MFM format */
117 1.17.2.2 nathanw short gap2_size; /* size of GAP 2 in the MFM format */
118 1.17.2.2 nathanw short gap3_size; /* size of GAP 3 in the MFM format */
119 1.17.2.2 nathanw short sync_value; /* sync value used when formatting */
120 1.17.2.2 nathanw char reserved[32]; /* reserved for use by the RQDX formatter */
121 1.17.2.2 nathanw short serial_number; /* serial number */
122 1.17.2.2 nathanw #if 0 /* we don't need these 412 useless bytes ... */
123 1.17.2.2 nathanw char fill[412-2]; /* Filler bytes to the end of the block */
124 1.17.2.2 nathanw short checksum; /* checksum over the XBN */
125 1.17.2.2 nathanw #endif
126 1.17.2.2 nathanw };
127 1.17.2.2 nathanw
128 1.17.2.2 nathanw /*
129 1.17.2.2 nathanw * Software status
130 1.17.2.2 nathanw */
131 1.17.2.2 nathanw struct rdsoftc {
132 1.17.2.2 nathanw struct device sc_dev; /* must be here! (pseudo-OOP:) */
133 1.17.2.2 nathanw struct disk sc_disk; /* disklabel etc. */
134 1.17.2.2 nathanw struct rdgeom sc_xbn; /* on-disk geometry information */
135 1.17.2.2 nathanw int sc_drive; /* physical unit number */
136 1.17.2.2 nathanw };
137 1.17.2.2 nathanw
138 1.17.2.2 nathanw struct hdcsoftc {
139 1.17.2.2 nathanw struct device sc_dev; /* must be here (pseudo-OOP:) */
140 1.17.2.2 nathanw struct evcnt sc_intrcnt;
141 1.17.2.2 nathanw struct vsbus_dma sc_vd;
142 1.17.2.2 nathanw vaddr_t sc_regs; /* register addresses */
143 1.17.2.2 nathanw struct bufq_state sc_q;
144 1.17.2.2 nathanw struct buf *sc_active;
145 1.17.2.2 nathanw struct hdc9224_UDCreg sc_creg; /* (command) registers to be written */
146 1.17.2.2 nathanw struct hdc9224_UDCreg sc_sreg; /* (status) registers being read */
147 1.17.2.2 nathanw caddr_t sc_dmabase; /* */
148 1.17.2.2 nathanw int sc_dmasize;
149 1.17.2.2 nathanw caddr_t sc_bufaddr; /* Current in-core address */
150 1.17.2.2 nathanw int sc_diskblk; /* Current block on disk */
151 1.17.2.2 nathanw int sc_bytecnt; /* How much left to transfer */
152 1.17.2.2 nathanw int sc_xfer; /* Current transfer size */
153 1.17.2.2 nathanw int sc_retries;
154 1.17.2.2 nathanw volatile u_char sc_status; /* last status from interrupt */
155 1.17.2.2 nathanw char sc_intbit;
156 1.17.2.2 nathanw };
157 1.17.2.2 nathanw
158 1.17.2.2 nathanw struct hdc_attach_args {
159 1.17.2.2 nathanw int ha_drive;
160 1.17.2.2 nathanw };
161 1.17.2.2 nathanw
162 1.17.2.2 nathanw /*
163 1.17.2.2 nathanw * prototypes for (almost) all the internal routines
164 1.17.2.2 nathanw */
165 1.17.2.2 nathanw static int hdcmatch(struct device *, struct cfdata *, void *);
166 1.17.2.2 nathanw static void hdcattach(struct device *, struct device *, void *);
167 1.17.2.2 nathanw static int hdcprint(void *, const char *);
168 1.17.2.2 nathanw static int rdmatch(struct device *, struct cfdata *, void *);
169 1.17.2.2 nathanw static void rdattach(struct device *, struct device *, void *);
170 1.17.2.2 nathanw static void hdcintr(void *);
171 1.17.2.2 nathanw static int hdc_command(struct hdcsoftc *, int);
172 1.17.2.2 nathanw static void rd_readgeom(struct hdcsoftc *, struct rdsoftc *);
173 1.17.2.2 nathanw #ifdef RDDEBUG
174 1.17.2.2 nathanw static void hdc_printgeom( struct rdgeom *);
175 1.17.2.2 nathanw #endif
176 1.17.2.2 nathanw static void hdc_writeregs(struct hdcsoftc *);
177 1.17.2.2 nathanw static void hdcstart(struct hdcsoftc *, struct buf *);
178 1.17.2.2 nathanw static int hdc_rdselect(struct hdcsoftc *, int);
179 1.17.2.2 nathanw static void rdmakelabel(struct disklabel *, struct rdgeom *);
180 1.17.2.2 nathanw static void hdc_writeregs(struct hdcsoftc *);
181 1.17.2.2 nathanw static void hdc_readregs(struct hdcsoftc *);
182 1.17.2.2 nathanw static void hdc_qstart(void *);
183 1.17.2.2 nathanw
184 1.17.2.4 nathanw CFATTACH_DECL(hdc, sizeof(struct hdcsoftc),
185 1.17.2.4 nathanw hdcmatch, hdcattach, NULL, NULL);
186 1.17.2.2 nathanw
187 1.17.2.4 nathanw CFATTACH_DECL(rd, sizeof(struct rdsoftc),
188 1.17.2.4 nathanw rdmatch, rdattach, NULL, NULL);
189 1.17.2.2 nathanw
190 1.17.2.3 nathanw dev_type_open(rdopen);
191 1.17.2.3 nathanw dev_type_close(rdclose);
192 1.17.2.3 nathanw dev_type_read(rdread);
193 1.17.2.3 nathanw dev_type_write(rdwrite);
194 1.17.2.3 nathanw dev_type_ioctl(rdioctl);
195 1.17.2.3 nathanw dev_type_strategy(rdstrategy);
196 1.17.2.3 nathanw dev_type_size(rdsize);
197 1.17.2.3 nathanw
198 1.17.2.3 nathanw const struct bdevsw rd_bdevsw = {
199 1.17.2.3 nathanw rdopen, rdclose, rdstrategy, rdioctl, nulldump, rdsize, D_DISK
200 1.17.2.3 nathanw };
201 1.17.2.3 nathanw
202 1.17.2.3 nathanw const struct cdevsw rd_cdevsw = {
203 1.17.2.3 nathanw rdopen, rdclose, rdread, rdwrite, rdioctl,
204 1.17.2.5 nathanw nostop, notty, nopoll, nommap, nokqfilter, D_DISK
205 1.17.2.3 nathanw };
206 1.17.2.2 nathanw
207 1.17.2.2 nathanw /* At least 0.7 uS between register accesses */
208 1.17.2.2 nathanw static int rd_dmasize, inq = 0;
209 1.17.2.2 nathanw static int u;
210 1.17.2.2 nathanw #define WAIT asm("movl %0,%0;movl %0,%0;movl %0,%0; movl %0,%0" :: "m"(u))
211 1.17.2.2 nathanw
212 1.17.2.2 nathanw #define HDC_WREG(x) *(volatile char *)(sc->sc_regs) = (x)
213 1.17.2.2 nathanw #define HDC_RREG *(volatile char *)(sc->sc_regs)
214 1.17.2.2 nathanw #define HDC_WCMD(x) *(volatile char *)(sc->sc_regs + 4) = (x)
215 1.17.2.2 nathanw #define HDC_RSTAT *(volatile char *)(sc->sc_regs + 4)
216 1.17.2.2 nathanw
217 1.17.2.2 nathanw /*
218 1.17.2.2 nathanw * new-config's hdcmatch() is similiar to old-config's hdcprobe(),
219 1.17.2.2 nathanw * thus we probe for the existence of the controller and reset it.
220 1.17.2.2 nathanw * NB: we can't initialize the controller yet, since space for hdcsoftc
221 1.17.2.2 nathanw * is not yet allocated. Thus we do this in hdcattach()...
222 1.17.2.2 nathanw */
223 1.17.2.2 nathanw int
224 1.17.2.2 nathanw hdcmatch(struct device *parent, struct cfdata *cf, void *aux)
225 1.17.2.2 nathanw {
226 1.17.2.2 nathanw struct vsbus_attach_args *va = aux;
227 1.17.2.2 nathanw volatile char *hdc_csr = (char *)va->va_addr;
228 1.17.2.2 nathanw int i;
229 1.17.2.2 nathanw
230 1.17.2.2 nathanw u = 8; /* !!! - GCC */
231 1.17.2.2 nathanw
232 1.17.2.2 nathanw if (vax_boardtype == VAX_BTYP_49 || vax_boardtype == VAX_BTYP_46
233 1.17.2.2 nathanw || vax_boardtype == VAX_BTYP_48 || vax_boardtype == VAX_BTYP_53)
234 1.17.2.2 nathanw return 0;
235 1.17.2.2 nathanw
236 1.17.2.2 nathanw hdc_csr[4] = DKC_CMD_RESET; /* reset chip */
237 1.17.2.2 nathanw for (i = 0; i < 1000; i++) {
238 1.17.2.2 nathanw DELAY(1000);
239 1.17.2.2 nathanw if (hdc_csr[4] & DKC_ST_DONE)
240 1.17.2.2 nathanw break;
241 1.17.2.2 nathanw }
242 1.17.2.2 nathanw if (i == 100)
243 1.17.2.2 nathanw return 0; /* No response to reset */
244 1.17.2.2 nathanw
245 1.17.2.2 nathanw hdc_csr[4] = DKC_CMD_SETREGPTR|UDC_TERM;
246 1.17.2.2 nathanw WAIT;
247 1.17.2.2 nathanw hdc_csr[0] = UDC_TC_CRCPRE|UDC_TC_INTDONE;
248 1.17.2.2 nathanw WAIT;
249 1.17.2.2 nathanw hdc_csr[4] = DKC_CMD_DRDESELECT; /* Should be harmless */
250 1.17.2.2 nathanw DELAY(1000);
251 1.17.2.2 nathanw return (1);
252 1.17.2.2 nathanw }
253 1.17.2.2 nathanw
254 1.17.2.2 nathanw int
255 1.17.2.2 nathanw hdcprint(void *aux, const char *name)
256 1.17.2.2 nathanw {
257 1.17.2.2 nathanw struct hdc_attach_args *ha = aux;
258 1.17.2.2 nathanw
259 1.17.2.2 nathanw if (name)
260 1.17.2.2 nathanw printf ("RD?? at %s drive %d", name, ha->ha_drive);
261 1.17.2.2 nathanw return UNCONF;
262 1.17.2.2 nathanw }
263 1.17.2.2 nathanw
264 1.17.2.2 nathanw /*
265 1.17.2.2 nathanw * hdc_attach() probes for all possible devices
266 1.17.2.2 nathanw */
267 1.17.2.2 nathanw void
268 1.17.2.2 nathanw hdcattach(struct device *parent, struct device *self, void *aux)
269 1.17.2.2 nathanw {
270 1.17.2.2 nathanw struct vsbus_attach_args *va = aux;
271 1.17.2.2 nathanw struct hdcsoftc *sc = (void *)self;
272 1.17.2.2 nathanw struct hdc_attach_args ha;
273 1.17.2.2 nathanw int status, i;
274 1.17.2.2 nathanw
275 1.17.2.2 nathanw printf ("\n");
276 1.17.2.2 nathanw /*
277 1.17.2.2 nathanw * Get interrupt vector, enable instrumentation.
278 1.17.2.2 nathanw */
279 1.17.2.2 nathanw scb_vecalloc(va->va_cvec, hdcintr, sc, SCB_ISTACK, &sc->sc_intrcnt);
280 1.17.2.2 nathanw evcnt_attach_dynamic(&sc->sc_intrcnt, EVCNT_TYPE_INTR, NULL,
281 1.17.2.2 nathanw self->dv_xname, "intr");
282 1.17.2.2 nathanw
283 1.17.2.2 nathanw sc->sc_regs = vax_map_physmem(va->va_paddr, 1);
284 1.17.2.2 nathanw sc->sc_dmabase = (caddr_t)va->va_dmaaddr;
285 1.17.2.2 nathanw sc->sc_dmasize = va->va_dmasize;
286 1.17.2.2 nathanw sc->sc_intbit = va->va_maskno;
287 1.17.2.2 nathanw rd_dmasize = min(MAXPHYS, sc->sc_dmasize); /* Used in rd_minphys */
288 1.17.2.2 nathanw
289 1.17.2.2 nathanw sc->sc_vd.vd_go = hdc_qstart;
290 1.17.2.2 nathanw sc->sc_vd.vd_arg = sc;
291 1.17.2.2 nathanw /*
292 1.17.2.2 nathanw * Reset controller.
293 1.17.2.2 nathanw */
294 1.17.2.2 nathanw HDC_WCMD(DKC_CMD_RESET);
295 1.17.2.2 nathanw DELAY(1000);
296 1.17.2.2 nathanw status = HDC_RSTAT;
297 1.17.2.2 nathanw if (status != (DKC_ST_DONE|DKC_TC_SUCCESS)) {
298 1.17.2.2 nathanw printf("%s: RESET failed, status 0x%x\n",
299 1.17.2.2 nathanw sc->sc_dev.dv_xname, status);
300 1.17.2.2 nathanw return;
301 1.17.2.2 nathanw }
302 1.17.2.2 nathanw bufq_alloc(&sc->sc_q, BUFQ_DISKSORT|BUFQ_SORT_CYLINDER);
303 1.17.2.2 nathanw
304 1.17.2.2 nathanw /*
305 1.17.2.2 nathanw * now probe for all possible hard drives
306 1.17.2.2 nathanw */
307 1.17.2.2 nathanw for (i = 0; i < 4; i++) {
308 1.17.2.2 nathanw if (i == 2) /* Floppy, needs special handling */
309 1.17.2.2 nathanw continue;
310 1.17.2.2 nathanw HDC_WCMD(DKC_CMD_DRSELECT | i);
311 1.17.2.2 nathanw DELAY(1000);
312 1.17.2.2 nathanw status = HDC_RSTAT;
313 1.17.2.2 nathanw ha.ha_drive = i;
314 1.17.2.2 nathanw if ((status & DKC_ST_TERMCOD) == DKC_TC_SUCCESS)
315 1.17.2.2 nathanw config_found(self, (void *)&ha, hdcprint);
316 1.17.2.2 nathanw }
317 1.17.2.2 nathanw }
318 1.17.2.2 nathanw
319 1.17.2.2 nathanw /*
320 1.17.2.2 nathanw * rdmatch() probes for the existence of a RD-type disk/floppy
321 1.17.2.2 nathanw */
322 1.17.2.2 nathanw int
323 1.17.2.2 nathanw rdmatch(parent, cf, aux)
324 1.17.2.2 nathanw struct device *parent;
325 1.17.2.2 nathanw struct cfdata *cf;
326 1.17.2.2 nathanw void *aux;
327 1.17.2.2 nathanw {
328 1.17.2.2 nathanw struct hdc_attach_args *ha = aux;
329 1.17.2.2 nathanw
330 1.17.2.2 nathanw if (cf->cf_loc[HDCCF_DRIVE] != HDCCF_DRIVE_DEFAULT &&
331 1.17.2.2 nathanw cf->cf_loc[HDCCF_DRIVE] != ha->ha_drive)
332 1.17.2.2 nathanw return 0;
333 1.17.2.2 nathanw
334 1.17.2.2 nathanw if (ha->ha_drive == 2) /* Always floppy, not supported */
335 1.17.2.2 nathanw return 0;
336 1.17.2.2 nathanw
337 1.17.2.2 nathanw return 1;
338 1.17.2.2 nathanw }
339 1.17.2.2 nathanw
340 1.17.2.2 nathanw void
341 1.17.2.2 nathanw rdattach(struct device *parent, struct device *self, void *aux)
342 1.17.2.2 nathanw {
343 1.17.2.2 nathanw struct hdcsoftc *sc = (void*)parent;
344 1.17.2.2 nathanw struct rdsoftc *rd = (void*)self;
345 1.17.2.2 nathanw struct hdc_attach_args *ha = aux;
346 1.17.2.2 nathanw struct disklabel *dl;
347 1.17.2.2 nathanw char *msg;
348 1.17.2.2 nathanw
349 1.17.2.2 nathanw rd->sc_drive = ha->ha_drive;
350 1.17.2.2 nathanw /*
351 1.17.2.2 nathanw * Initialize and attach the disk structure.
352 1.17.2.2 nathanw */
353 1.17.2.2 nathanw rd->sc_disk.dk_name = rd->sc_dev.dv_xname;
354 1.17.2.2 nathanw disk_attach(&rd->sc_disk);
355 1.17.2.2 nathanw
356 1.17.2.2 nathanw /*
357 1.17.2.2 nathanw * if it's not a floppy then evaluate the on-disk geometry.
358 1.17.2.2 nathanw * if necessary correct the label...
359 1.17.2.2 nathanw */
360 1.17.2.2 nathanw rd_readgeom(sc, rd);
361 1.17.2.2 nathanw disk_printtype(rd->sc_drive, rd->sc_xbn.media_id);
362 1.17.2.2 nathanw dl = rd->sc_disk.dk_label;
363 1.17.2.2 nathanw rdmakelabel(dl, &rd->sc_xbn);
364 1.17.2.2 nathanw printf("%s", rd->sc_dev.dv_xname);
365 1.17.2.3 nathanw msg = readdisklabel(MAKEDISKDEV(cdevsw_lookup_major(&rd_cdevsw),
366 1.17.2.3 nathanw rd->sc_dev.dv_unit, RAW_PART),
367 1.17.2.3 nathanw rdstrategy, dl, NULL);
368 1.17.2.2 nathanw if (msg)
369 1.17.2.2 nathanw printf(": %s", msg);
370 1.17.2.2 nathanw printf(": size %d sectors\n", dl->d_secperunit);
371 1.17.2.2 nathanw #ifdef RDDEBUG
372 1.17.2.2 nathanw hdc_printgeom(&rd->sc_xbn);
373 1.17.2.2 nathanw #endif
374 1.17.2.2 nathanw }
375 1.17.2.2 nathanw
376 1.17.2.2 nathanw void
377 1.17.2.2 nathanw hdcintr(void *arg)
378 1.17.2.2 nathanw {
379 1.17.2.2 nathanw struct hdcsoftc *sc = arg;
380 1.17.2.2 nathanw struct buf *bp;
381 1.17.2.2 nathanw
382 1.17.2.2 nathanw sc->sc_status = HDC_RSTAT;
383 1.17.2.2 nathanw if (sc->sc_active == 0)
384 1.17.2.2 nathanw return; /* Complain? */
385 1.17.2.2 nathanw
386 1.17.2.2 nathanw if ((sc->sc_status & (DKC_ST_INTPEND|DKC_ST_DONE)) !=
387 1.17.2.2 nathanw (DKC_ST_INTPEND|DKC_ST_DONE))
388 1.17.2.2 nathanw return; /* Why spurious ints sometimes??? */
389 1.17.2.2 nathanw
390 1.17.2.2 nathanw bp = sc->sc_active;
391 1.17.2.2 nathanw sc->sc_active = 0;
392 1.17.2.2 nathanw if ((sc->sc_status & DKC_ST_TERMCOD) != DKC_TC_SUCCESS) {
393 1.17.2.2 nathanw int i;
394 1.17.2.2 nathanw u_char *g = (u_char *)&sc->sc_sreg;
395 1.17.2.2 nathanw
396 1.17.2.2 nathanw if (sc->sc_retries++ < 3) { /* Allow 3 retries */
397 1.17.2.2 nathanw hdcstart(sc, bp);
398 1.17.2.2 nathanw return;
399 1.17.2.2 nathanw }
400 1.17.2.2 nathanw printf("%s: failed, status 0x%x\n",
401 1.17.2.2 nathanw sc->sc_dev.dv_xname, sc->sc_status);
402 1.17.2.2 nathanw hdc_readregs(sc);
403 1.17.2.2 nathanw for (i = 0; i < 10; i++)
404 1.17.2.2 nathanw printf("%i: %x\n", i, g[i]);
405 1.17.2.2 nathanw bp->b_flags |= B_ERROR;
406 1.17.2.2 nathanw bp->b_error = ENXIO;
407 1.17.2.2 nathanw bp->b_resid = bp->b_bcount;
408 1.17.2.2 nathanw biodone(bp);
409 1.17.2.2 nathanw vsbus_dma_intr();
410 1.17.2.2 nathanw return;
411 1.17.2.2 nathanw }
412 1.17.2.2 nathanw
413 1.17.2.2 nathanw if (bp->b_flags & B_READ) {
414 1.17.2.2 nathanw vsbus_copytoproc(bp->b_proc, sc->sc_dmabase, sc->sc_bufaddr,
415 1.17.2.2 nathanw sc->sc_xfer);
416 1.17.2.2 nathanw }
417 1.17.2.2 nathanw sc->sc_diskblk += (sc->sc_xfer/DEV_BSIZE);
418 1.17.2.2 nathanw sc->sc_bytecnt -= sc->sc_xfer;
419 1.17.2.2 nathanw sc->sc_bufaddr += sc->sc_xfer;
420 1.17.2.2 nathanw
421 1.17.2.2 nathanw if (sc->sc_bytecnt == 0) { /* Finished transfer */
422 1.17.2.2 nathanw biodone(bp);
423 1.17.2.2 nathanw vsbus_dma_intr();
424 1.17.2.2 nathanw } else
425 1.17.2.2 nathanw hdcstart(sc, bp);
426 1.17.2.2 nathanw }
427 1.17.2.2 nathanw
428 1.17.2.2 nathanw /*
429 1.17.2.2 nathanw *
430 1.17.2.2 nathanw */
431 1.17.2.2 nathanw void
432 1.17.2.2 nathanw rdstrategy(struct buf *bp)
433 1.17.2.2 nathanw {
434 1.17.2.2 nathanw struct rdsoftc *rd;
435 1.17.2.2 nathanw struct hdcsoftc *sc;
436 1.17.2.2 nathanw struct disklabel *lp;
437 1.17.2.2 nathanw int unit, s;
438 1.17.2.2 nathanw
439 1.17.2.2 nathanw unit = DISKUNIT(bp->b_dev);
440 1.17.2.2 nathanw if (unit > rd_cd.cd_ndevs || (rd = rd_cd.cd_devs[unit]) == NULL) {
441 1.17.2.2 nathanw bp->b_error = ENXIO;
442 1.17.2.2 nathanw bp->b_flags |= B_ERROR;
443 1.17.2.2 nathanw goto done;
444 1.17.2.2 nathanw }
445 1.17.2.2 nathanw sc = (void *)rd->sc_dev.dv_parent;
446 1.17.2.2 nathanw
447 1.17.2.2 nathanw lp = rd->sc_disk.dk_label;
448 1.17.2.2 nathanw if ((bounds_check_with_label(bp, lp, 1)) <= 0)
449 1.17.2.2 nathanw goto done;
450 1.17.2.2 nathanw
451 1.17.2.2 nathanw if (bp->b_bcount == 0)
452 1.17.2.2 nathanw goto done;
453 1.17.2.2 nathanw
454 1.17.2.2 nathanw bp->b_rawblkno =
455 1.17.2.2 nathanw bp->b_blkno + lp->d_partitions[DISKPART(bp->b_dev)].p_offset;
456 1.17.2.2 nathanw bp->b_cylinder = bp->b_rawblkno / lp->d_secpercyl;
457 1.17.2.2 nathanw
458 1.17.2.2 nathanw s = splbio();
459 1.17.2.2 nathanw BUFQ_PUT(&sc->sc_q, bp);
460 1.17.2.2 nathanw if (inq == 0) {
461 1.17.2.2 nathanw inq = 1;
462 1.17.2.2 nathanw vsbus_dma_start(&sc->sc_vd);
463 1.17.2.2 nathanw }
464 1.17.2.2 nathanw splx(s);
465 1.17.2.2 nathanw return;
466 1.17.2.2 nathanw
467 1.17.2.2 nathanw done: biodone(bp);
468 1.17.2.2 nathanw }
469 1.17.2.2 nathanw
470 1.17.2.2 nathanw void
471 1.17.2.2 nathanw hdc_qstart(void *arg)
472 1.17.2.2 nathanw {
473 1.17.2.2 nathanw struct hdcsoftc *sc = arg;
474 1.17.2.2 nathanw
475 1.17.2.2 nathanw inq = 0;
476 1.17.2.2 nathanw
477 1.17.2.2 nathanw hdcstart(sc, 0);
478 1.17.2.2 nathanw if (BUFQ_PEEK(&sc->sc_q)) {
479 1.17.2.2 nathanw vsbus_dma_start(&sc->sc_vd); /* More to go */
480 1.17.2.2 nathanw inq = 1;
481 1.17.2.2 nathanw }
482 1.17.2.2 nathanw }
483 1.17.2.2 nathanw
484 1.17.2.2 nathanw void
485 1.17.2.2 nathanw hdcstart(struct hdcsoftc *sc, struct buf *ob)
486 1.17.2.2 nathanw {
487 1.17.2.2 nathanw struct hdc9224_UDCreg *p = &sc->sc_creg;
488 1.17.2.2 nathanw struct disklabel *lp;
489 1.17.2.2 nathanw struct rdsoftc *rd;
490 1.17.2.2 nathanw struct buf *bp;
491 1.17.2.2 nathanw int cn, sn, tn, bn, blks;
492 1.17.2.2 nathanw volatile char ch;
493 1.17.2.2 nathanw
494 1.17.2.2 nathanw if (sc->sc_active)
495 1.17.2.2 nathanw return; /* Already doing something */
496 1.17.2.2 nathanw
497 1.17.2.2 nathanw
498 1.17.2.2 nathanw if (ob == 0) {
499 1.17.2.2 nathanw bp = BUFQ_GET(&sc->sc_q);
500 1.17.2.2 nathanw if (bp == NULL)
501 1.17.2.2 nathanw return; /* Nothing to do */
502 1.17.2.2 nathanw sc->sc_bufaddr = bp->b_data;
503 1.17.2.2 nathanw sc->sc_diskblk = bp->b_rawblkno;
504 1.17.2.2 nathanw sc->sc_bytecnt = bp->b_bcount;
505 1.17.2.2 nathanw sc->sc_retries = 0;
506 1.17.2.2 nathanw bp->b_resid = 0;
507 1.17.2.2 nathanw } else
508 1.17.2.2 nathanw bp = ob;
509 1.17.2.2 nathanw
510 1.17.2.2 nathanw rd = rd_cd.cd_devs[DISKUNIT(bp->b_dev)];
511 1.17.2.2 nathanw hdc_rdselect(sc, rd->sc_drive);
512 1.17.2.2 nathanw sc->sc_active = bp;
513 1.17.2.2 nathanw
514 1.17.2.2 nathanw bn = sc->sc_diskblk;
515 1.17.2.2 nathanw lp = rd->sc_disk.dk_label;
516 1.17.2.2 nathanw if (bn) {
517 1.17.2.2 nathanw cn = bn / lp->d_secpercyl;
518 1.17.2.2 nathanw sn = bn % lp->d_secpercyl;
519 1.17.2.2 nathanw tn = sn / lp->d_nsectors;
520 1.17.2.2 nathanw sn = sn % lp->d_nsectors;
521 1.17.2.2 nathanw } else
522 1.17.2.2 nathanw cn = sn = tn = 0;
523 1.17.2.2 nathanw
524 1.17.2.2 nathanw cn++; /* first cylinder is reserved */
525 1.17.2.2 nathanw
526 1.17.2.2 nathanw bzero(p, sizeof(struct hdc9224_UDCreg));
527 1.17.2.2 nathanw
528 1.17.2.2 nathanw /*
529 1.17.2.2 nathanw * Tricky thing: the controller do itself only increase the sector
530 1.17.2.2 nathanw * number, not the track or cylinder number. Therefore the driver
531 1.17.2.2 nathanw * is not allowed to have transfers that crosses track boundaries.
532 1.17.2.2 nathanw */
533 1.17.2.2 nathanw blks = sc->sc_bytecnt/DEV_BSIZE;
534 1.17.2.2 nathanw if ((sn + blks) > lp->d_nsectors)
535 1.17.2.2 nathanw blks = lp->d_nsectors - sn;
536 1.17.2.2 nathanw
537 1.17.2.2 nathanw p->udc_dsect = sn;
538 1.17.2.2 nathanw p->udc_dcyl = cn & 0xff;
539 1.17.2.2 nathanw p->udc_dhead = ((cn >> 4) & 0x70) | tn;
540 1.17.2.2 nathanw p->udc_scnt = blks;
541 1.17.2.2 nathanw
542 1.17.2.2 nathanw p->udc_rtcnt = UDC_RC_RTRYCNT;
543 1.17.2.2 nathanw p->udc_mode = UDC_MD_HDD;
544 1.17.2.2 nathanw p->udc_term = UDC_TC_CRCPRE|UDC_TC_INTDONE|UDC_TC_TDELDAT|UDC_TC_TWRFLT;
545 1.17.2.2 nathanw hdc_writeregs(sc);
546 1.17.2.2 nathanw
547 1.17.2.2 nathanw /* Count up vars */
548 1.17.2.2 nathanw sc->sc_xfer = blks * DEV_BSIZE;
549 1.17.2.2 nathanw
550 1.17.2.2 nathanw ch = HDC_RSTAT; /* Avoid pending interrupts */
551 1.17.2.2 nathanw WAIT;
552 1.17.2.2 nathanw vsbus_clrintr(sc->sc_intbit); /* Clear pending int's */
553 1.17.2.2 nathanw
554 1.17.2.2 nathanw if (bp->b_flags & B_READ) {
555 1.17.2.2 nathanw HDC_WCMD(DKC_CMD_READ_HDD);
556 1.17.2.2 nathanw } else {
557 1.17.2.2 nathanw vsbus_copyfromproc(bp->b_proc, sc->sc_bufaddr, sc->sc_dmabase,
558 1.17.2.2 nathanw sc->sc_xfer);
559 1.17.2.2 nathanw HDC_WCMD(DKC_CMD_WRITE_HDD);
560 1.17.2.2 nathanw }
561 1.17.2.2 nathanw }
562 1.17.2.2 nathanw
563 1.17.2.2 nathanw void
564 1.17.2.2 nathanw rd_readgeom(struct hdcsoftc *sc, struct rdsoftc *rd)
565 1.17.2.2 nathanw {
566 1.17.2.2 nathanw struct hdc9224_UDCreg *p = &sc->sc_creg;
567 1.17.2.2 nathanw
568 1.17.2.2 nathanw hdc_rdselect(sc, rd->sc_drive); /* select drive right now */
569 1.17.2.2 nathanw
570 1.17.2.2 nathanw bzero(p, sizeof(struct hdc9224_UDCreg));
571 1.17.2.2 nathanw
572 1.17.2.2 nathanw p->udc_scnt = 1;
573 1.17.2.2 nathanw p->udc_rtcnt = UDC_RC_RTRYCNT;
574 1.17.2.2 nathanw p->udc_mode = UDC_MD_HDD;
575 1.17.2.2 nathanw p->udc_term = UDC_TC_CRCPRE|UDC_TC_INTDONE|UDC_TC_TDELDAT|UDC_TC_TWPROT;
576 1.17.2.2 nathanw hdc_writeregs(sc);
577 1.17.2.2 nathanw sc->sc_status = 0;
578 1.17.2.2 nathanw HDC_WCMD(DKC_CMD_READ_HDD|2);
579 1.17.2.2 nathanw while ((sc->sc_status & DKC_ST_INTPEND) == 0)
580 1.17.2.2 nathanw ;
581 1.17.2.2 nathanw bcopy(sc->sc_dmabase, &rd->sc_xbn, sizeof(struct rdgeom));
582 1.17.2.2 nathanw }
583 1.17.2.2 nathanw
584 1.17.2.2 nathanw #ifdef RDDEBUG
585 1.17.2.2 nathanw /*
586 1.17.2.2 nathanw * display the contents of the on-disk geometry structure
587 1.17.2.2 nathanw */
588 1.17.2.2 nathanw void
589 1.17.2.2 nathanw hdc_printgeom(p)
590 1.17.2.2 nathanw struct rdgeom *p;
591 1.17.2.2 nathanw {
592 1.17.2.2 nathanw printf ("**DiskData** XBNs: %ld, DBNs: %ld, LBNs: %ld, RBNs: %ld\n",
593 1.17.2.2 nathanw p->xbn_count, p->dbn_count, p->lbn_count, p->rbn_count);
594 1.17.2.2 nathanw printf ("sec/track: %d, tracks: %d, cyl: %d, precomp/reduced: %d/%d\n",
595 1.17.2.2 nathanw p->nspt, p->ntracks, p->ncylinders, p->precomp, p->reduced);
596 1.17.2.2 nathanw printf ("seek-rate: %d, crc/eec: %s, RCT: %d, RCT-copies: %d\n",
597 1.17.2.2 nathanw p->seek_rate, p->crc_eec?"EEC":"CRC", p->rct, p->rct_ncopies);
598 1.17.2.2 nathanw printf ("media-ID: %lx, interleave: %d, headskew: %d, cylskew: %d\n",
599 1.17.2.2 nathanw p->media_id, p->interleave, p->headskew, p->cylskew);
600 1.17.2.2 nathanw printf ("gap0: %d, gap1: %d, gap2: %d, gap3: %d, sync-value: %d\n",
601 1.17.2.2 nathanw p->gap0_size, p->gap1_size, p->gap2_size, p->gap3_size,
602 1.17.2.2 nathanw p->sync_value);
603 1.17.2.2 nathanw }
604 1.17.2.2 nathanw #endif
605 1.17.2.2 nathanw
606 1.17.2.2 nathanw /*
607 1.17.2.2 nathanw * Return the size of a partition, if known, or -1 if not.
608 1.17.2.2 nathanw */
609 1.17.2.2 nathanw int
610 1.17.2.2 nathanw rdsize(dev_t dev)
611 1.17.2.2 nathanw {
612 1.17.2.2 nathanw struct rdsoftc *rd;
613 1.17.2.2 nathanw int unit = DISKUNIT(dev);
614 1.17.2.2 nathanw int size;
615 1.17.2.2 nathanw
616 1.17.2.2 nathanw if (unit >= rd_cd.cd_ndevs || rd_cd.cd_devs[unit] == 0)
617 1.17.2.2 nathanw return -1;
618 1.17.2.2 nathanw rd = rd_cd.cd_devs[unit];
619 1.17.2.2 nathanw size = rd->sc_disk.dk_label->d_partitions[DISKPART(dev)].p_size *
620 1.17.2.2 nathanw (rd->sc_disk.dk_label->d_secsize / DEV_BSIZE);
621 1.17.2.2 nathanw
622 1.17.2.2 nathanw return (size);
623 1.17.2.2 nathanw }
624 1.17.2.2 nathanw
625 1.17.2.2 nathanw /*
626 1.17.2.2 nathanw *
627 1.17.2.2 nathanw */
628 1.17.2.2 nathanw int
629 1.17.2.2 nathanw rdopen(dev_t dev, int flag, int fmt, struct proc *p)
630 1.17.2.2 nathanw {
631 1.17.2.2 nathanw struct rdsoftc *rd;
632 1.17.2.2 nathanw int unit, part;
633 1.17.2.2 nathanw
634 1.17.2.2 nathanw unit = DISKUNIT(dev);
635 1.17.2.2 nathanw if (unit >= rd_cd.cd_ndevs)
636 1.17.2.2 nathanw return ENXIO;
637 1.17.2.2 nathanw rd = rd_cd.cd_devs[unit];
638 1.17.2.2 nathanw if (rd == 0)
639 1.17.2.2 nathanw return ENXIO;
640 1.17.2.2 nathanw
641 1.17.2.2 nathanw part = DISKPART(dev);
642 1.17.2.2 nathanw if (part >= rd->sc_disk.dk_label->d_npartitions)
643 1.17.2.2 nathanw return ENXIO;
644 1.17.2.2 nathanw
645 1.17.2.2 nathanw switch (fmt) {
646 1.17.2.2 nathanw case S_IFCHR:
647 1.17.2.2 nathanw rd->sc_disk.dk_copenmask |= (1 << part);
648 1.17.2.2 nathanw break;
649 1.17.2.2 nathanw case S_IFBLK:
650 1.17.2.2 nathanw rd->sc_disk.dk_bopenmask |= (1 << part);
651 1.17.2.2 nathanw break;
652 1.17.2.2 nathanw }
653 1.17.2.2 nathanw rd->sc_disk.dk_openmask =
654 1.17.2.2 nathanw rd->sc_disk.dk_copenmask | rd->sc_disk.dk_bopenmask;
655 1.17.2.2 nathanw
656 1.17.2.2 nathanw return 0;
657 1.17.2.2 nathanw }
658 1.17.2.2 nathanw
659 1.17.2.2 nathanw /*
660 1.17.2.2 nathanw *
661 1.17.2.2 nathanw */
662 1.17.2.2 nathanw int
663 1.17.2.2 nathanw rdclose(dev_t dev, int flag, int fmt, struct proc *p)
664 1.17.2.2 nathanw {
665 1.17.2.2 nathanw struct rdsoftc *rd;
666 1.17.2.2 nathanw int part;
667 1.17.2.2 nathanw
668 1.17.2.2 nathanw rd = rd_cd.cd_devs[DISKUNIT(dev)];
669 1.17.2.2 nathanw part = DISKPART(dev);
670 1.17.2.2 nathanw
671 1.17.2.2 nathanw switch (fmt) {
672 1.17.2.2 nathanw case S_IFCHR:
673 1.17.2.2 nathanw rd->sc_disk.dk_copenmask &= ~(1 << part);
674 1.17.2.2 nathanw break;
675 1.17.2.2 nathanw case S_IFBLK:
676 1.17.2.2 nathanw rd->sc_disk.dk_bopenmask &= ~(1 << part);
677 1.17.2.2 nathanw break;
678 1.17.2.2 nathanw }
679 1.17.2.2 nathanw rd->sc_disk.dk_openmask =
680 1.17.2.2 nathanw rd->sc_disk.dk_copenmask | rd->sc_disk.dk_bopenmask;
681 1.17.2.2 nathanw
682 1.17.2.2 nathanw return (0);
683 1.17.2.2 nathanw }
684 1.17.2.2 nathanw
685 1.17.2.2 nathanw /*
686 1.17.2.2 nathanw *
687 1.17.2.2 nathanw */
688 1.17.2.2 nathanw int
689 1.17.2.2 nathanw rdioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
690 1.17.2.2 nathanw {
691 1.17.2.2 nathanw struct rdsoftc *rd = rd_cd.cd_devs[DISKUNIT(dev)];
692 1.17.2.2 nathanw struct disklabel *lp = rd->sc_disk.dk_label;
693 1.17.2.2 nathanw int err = 0;
694 1.17.2.2 nathanw
695 1.17.2.2 nathanw switch (cmd) {
696 1.17.2.2 nathanw case DIOCGDINFO:
697 1.17.2.2 nathanw bcopy(lp, addr, sizeof (struct disklabel));
698 1.17.2.2 nathanw break;
699 1.17.2.2 nathanw
700 1.17.2.2 nathanw case DIOCGPART:
701 1.17.2.2 nathanw ((struct partinfo *)addr)->disklab = lp;
702 1.17.2.2 nathanw ((struct partinfo *)addr)->part =
703 1.17.2.2 nathanw &lp->d_partitions[DISKPART(dev)];
704 1.17.2.2 nathanw break;
705 1.17.2.2 nathanw
706 1.17.2.2 nathanw case DIOCWDINFO:
707 1.17.2.2 nathanw case DIOCSDINFO:
708 1.17.2.2 nathanw if ((flag & FWRITE) == 0)
709 1.17.2.2 nathanw return EBADF;
710 1.17.2.2 nathanw else
711 1.17.2.2 nathanw err = (cmd == DIOCSDINFO ?
712 1.17.2.2 nathanw setdisklabel(lp, (struct disklabel *)addr, 0, 0) :
713 1.17.2.2 nathanw writedisklabel(dev, rdstrategy, lp, 0));
714 1.17.2.2 nathanw break;
715 1.17.2.2 nathanw
716 1.17.2.2 nathanw case DIOCGDEFLABEL:
717 1.17.2.2 nathanw bzero(lp, sizeof(struct disklabel));
718 1.17.2.2 nathanw rdmakelabel(lp, &rd->sc_xbn);
719 1.17.2.2 nathanw break;
720 1.17.2.2 nathanw
721 1.17.2.2 nathanw case DIOCWLABEL:
722 1.17.2.2 nathanw if ((flag & FWRITE) == 0)
723 1.17.2.2 nathanw err = EBADF;
724 1.17.2.2 nathanw break;
725 1.17.2.2 nathanw
726 1.17.2.2 nathanw default:
727 1.17.2.2 nathanw err = ENOTTY;
728 1.17.2.2 nathanw }
729 1.17.2.2 nathanw return err;
730 1.17.2.2 nathanw }
731 1.17.2.2 nathanw
732 1.17.2.2 nathanw /*
733 1.17.2.2 nathanw *
734 1.17.2.2 nathanw */
735 1.17.2.2 nathanw int
736 1.17.2.2 nathanw rdread(dev_t dev, struct uio *uio, int flag)
737 1.17.2.2 nathanw {
738 1.17.2.2 nathanw return (physio (rdstrategy, NULL, dev, B_READ, minphys, uio));
739 1.17.2.2 nathanw }
740 1.17.2.2 nathanw
741 1.17.2.2 nathanw /*
742 1.17.2.2 nathanw *
743 1.17.2.2 nathanw */
744 1.17.2.2 nathanw int
745 1.17.2.2 nathanw rdwrite(dev_t dev, struct uio *uio, int flag)
746 1.17.2.2 nathanw {
747 1.17.2.2 nathanw return (physio (rdstrategy, NULL, dev, B_WRITE, minphys, uio));
748 1.17.2.2 nathanw }
749 1.17.2.2 nathanw
750 1.17.2.2 nathanw /*
751 1.17.2.2 nathanw * we have to wait 0.7 usec between two accesses to any of the
752 1.17.2.2 nathanw * dkc-registers, on a VS2000 with 1 MIPS, this is roughly one
753 1.17.2.2 nathanw * instruction. Thus the loop-overhead will be enough...
754 1.17.2.2 nathanw */
755 1.17.2.2 nathanw static void
756 1.17.2.2 nathanw hdc_readregs(struct hdcsoftc *sc)
757 1.17.2.2 nathanw {
758 1.17.2.2 nathanw int i;
759 1.17.2.2 nathanw char *p;
760 1.17.2.2 nathanw
761 1.17.2.2 nathanw HDC_WCMD(DKC_CMD_SETREGPTR);
762 1.17.2.2 nathanw WAIT;
763 1.17.2.2 nathanw p = (void*)&sc->sc_sreg;
764 1.17.2.2 nathanw for (i=0; i<10; i++) {
765 1.17.2.2 nathanw *p++ = HDC_RREG; /* dkc_reg auto-increments */
766 1.17.2.2 nathanw WAIT;
767 1.17.2.2 nathanw }
768 1.17.2.2 nathanw }
769 1.17.2.2 nathanw
770 1.17.2.2 nathanw static void
771 1.17.2.2 nathanw hdc_writeregs(struct hdcsoftc *sc)
772 1.17.2.2 nathanw {
773 1.17.2.2 nathanw int i;
774 1.17.2.2 nathanw char *p;
775 1.17.2.2 nathanw
776 1.17.2.2 nathanw HDC_WCMD(DKC_CMD_SETREGPTR);
777 1.17.2.2 nathanw p = (void*)&sc->sc_creg;
778 1.17.2.2 nathanw for (i=0; i<10; i++) {
779 1.17.2.2 nathanw HDC_WREG(*p++); /* dkc_reg auto-increments */
780 1.17.2.2 nathanw WAIT;
781 1.17.2.2 nathanw }
782 1.17.2.2 nathanw }
783 1.17.2.2 nathanw
784 1.17.2.2 nathanw /*
785 1.17.2.2 nathanw * hdc_command() issues a command and polls the intreq-register
786 1.17.2.2 nathanw * to find when command has completed
787 1.17.2.2 nathanw */
788 1.17.2.2 nathanw int
789 1.17.2.2 nathanw hdc_command(struct hdcsoftc *sc, int cmd)
790 1.17.2.2 nathanw {
791 1.17.2.2 nathanw hdc_writeregs(sc); /* write the prepared registers */
792 1.17.2.2 nathanw HDC_WCMD(cmd);
793 1.17.2.2 nathanw WAIT;
794 1.17.2.2 nathanw return (0);
795 1.17.2.2 nathanw }
796 1.17.2.2 nathanw
797 1.17.2.2 nathanw int
798 1.17.2.2 nathanw hdc_rdselect(struct hdcsoftc *sc, int unit)
799 1.17.2.2 nathanw {
800 1.17.2.2 nathanw struct hdc9224_UDCreg *p = &sc->sc_creg;
801 1.17.2.2 nathanw int error;
802 1.17.2.2 nathanw
803 1.17.2.2 nathanw /*
804 1.17.2.2 nathanw * bring "creg" in some known-to-work state and
805 1.17.2.2 nathanw * select the drive with the DRIVE SELECT command.
806 1.17.2.2 nathanw */
807 1.17.2.2 nathanw bzero(p, sizeof(struct hdc9224_UDCreg));
808 1.17.2.2 nathanw
809 1.17.2.2 nathanw p->udc_rtcnt = UDC_RC_HDD_READ;
810 1.17.2.2 nathanw p->udc_mode = UDC_MD_HDD;
811 1.17.2.2 nathanw p->udc_term = UDC_TC_HDD;
812 1.17.2.2 nathanw
813 1.17.2.2 nathanw error = hdc_command(sc, DKC_CMD_DRSEL_HDD | unit);
814 1.17.2.2 nathanw
815 1.17.2.2 nathanw return (error);
816 1.17.2.2 nathanw }
817 1.17.2.2 nathanw
818 1.17.2.2 nathanw void
819 1.17.2.2 nathanw rdmakelabel(struct disklabel *dl, struct rdgeom *g)
820 1.17.2.2 nathanw {
821 1.17.2.2 nathanw int n, p = 0;
822 1.17.2.2 nathanw
823 1.17.2.2 nathanw dl->d_bbsize = BBSIZE;
824 1.17.2.2 nathanw dl->d_sbsize = SBSIZE;
825 1.17.2.2 nathanw dl->d_typename[p++] = MSCP_MID_CHAR(2, g->media_id);
826 1.17.2.2 nathanw dl->d_typename[p++] = MSCP_MID_CHAR(1, g->media_id);
827 1.17.2.2 nathanw if (MSCP_MID_ECH(0, g->media_id))
828 1.17.2.2 nathanw dl->d_typename[p++] = MSCP_MID_CHAR(0, g->media_id);
829 1.17.2.2 nathanw n = MSCP_MID_NUM(g->media_id);
830 1.17.2.2 nathanw if (n > 99) {
831 1.17.2.2 nathanw dl->d_typename[p++] = '1';
832 1.17.2.2 nathanw n -= 100;
833 1.17.2.2 nathanw }
834 1.17.2.2 nathanw if (n > 9) {
835 1.17.2.2 nathanw dl->d_typename[p++] = (n / 10) + '0';
836 1.17.2.2 nathanw n %= 10;
837 1.17.2.2 nathanw }
838 1.17.2.2 nathanw dl->d_typename[p++] = n + '0';
839 1.17.2.2 nathanw dl->d_typename[p] = 0;
840 1.17.2.2 nathanw dl->d_type = DTYPE_MSCP; /* XXX - what to use here??? */
841 1.17.2.2 nathanw dl->d_rpm = 3600;
842 1.17.2.2 nathanw dl->d_secsize = DEV_BSIZE;
843 1.17.2.2 nathanw
844 1.17.2.2 nathanw dl->d_secperunit = g->lbn_count;
845 1.17.2.2 nathanw dl->d_nsectors = g->nspt;
846 1.17.2.2 nathanw dl->d_ntracks = g->ntracks;
847 1.17.2.2 nathanw dl->d_secpercyl = dl->d_nsectors * dl->d_ntracks;
848 1.17.2.2 nathanw dl->d_ncylinders = dl->d_secperunit / dl->d_secpercyl;
849 1.17.2.2 nathanw
850 1.17.2.2 nathanw dl->d_npartitions = MAXPARTITIONS;
851 1.17.2.2 nathanw dl->d_partitions[0].p_size = dl->d_partitions[2].p_size =
852 1.17.2.2 nathanw dl->d_secperunit;
853 1.17.2.2 nathanw dl->d_partitions[0].p_offset = dl->d_partitions[2].p_offset = 0;
854 1.17.2.2 nathanw dl->d_interleave = dl->d_headswitch = 1;
855 1.17.2.2 nathanw dl->d_magic = dl->d_magic2 = DISKMAGIC;
856 1.17.2.2 nathanw dl->d_checksum = dkcksum(dl);
857 1.17.2.2 nathanw }
858