hdc9224.c revision 1.4 1 1.4 christos /* $NetBSD: hdc9224.c,v 1.4 1996/10/13 03:36:11 christos Exp $ */
2 1.1 ragge /*
3 1.1 ragge * Copyright (c) 1996 Ludd, University of Lule}, Sweden.
4 1.1 ragge * All rights reserved.
5 1.1 ragge *
6 1.1 ragge * This code is derived from software contributed to Ludd by Bertram Barth.
7 1.1 ragge *
8 1.1 ragge * Redistribution and use in source and binary forms, with or without
9 1.1 ragge * modification, are permitted provided that the following conditions
10 1.1 ragge * are met:
11 1.1 ragge * 1. Redistributions of source code must retain the above copyright
12 1.1 ragge * notice, this list of conditions and the following disclaimer.
13 1.1 ragge * 2. Redistributions in binary form must reproduce the above copyright
14 1.1 ragge * notice, this list of conditions and the following disclaimer in the
15 1.1 ragge * documentation and/or other materials provided with the distribution.
16 1.1 ragge * 3. All advertising materials mentioning features or use of this software
17 1.1 ragge * must display the following acknowledgement:
18 1.1 ragge * This product includes software developed at Ludd, University of
19 1.1 ragge * Lule}, Sweden and its contributors.
20 1.1 ragge * 4. The name of the author may not be used to endorse or promote products
21 1.1 ragge * derived from this software without specific prior written permission
22 1.1 ragge *
23 1.1 ragge * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
24 1.1 ragge * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
25 1.1 ragge * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
26 1.1 ragge * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
27 1.1 ragge * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
28 1.1 ragge * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
29 1.1 ragge * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
30 1.1 ragge * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
31 1.1 ragge * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
32 1.1 ragge * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
33 1.1 ragge */
34 1.1 ragge
35 1.1 ragge /*
36 1.1 ragge * with much help from (in alphabetical order):
37 1.1 ragge * Jeremy
38 1.1 ragge * Roger Ivie
39 1.1 ragge * Rick Macklem
40 1.1 ragge * Mike Young
41 1.1 ragge */
42 1.1 ragge
43 1.1 ragge /* #define DEBUG /* */
44 1.1 ragge /* #define TRACE /* */
45 1.1 ragge static int haveLock = 0;
46 1.1 ragge static int keepLock = 0;
47 1.1 ragge
48 1.1 ragge #define F_READ 11
49 1.1 ragge #define F_WRITE 12
50 1.1 ragge
51 1.1 ragge #define trace(x)
52 1.1 ragge #define debug(x)
53 1.1 ragge
54 1.1 ragge #include "hdc.h"
55 1.1 ragge #if NHDC > 0
56 1.1 ragge
57 1.1 ragge #include <sys/param.h>
58 1.1 ragge #include <sys/systm.h>
59 1.1 ragge #include <sys/kernel.h>
60 1.1 ragge #include <sys/conf.h>
61 1.1 ragge #include <sys/file.h>
62 1.1 ragge #include <sys/stat.h>
63 1.1 ragge #include <sys/ioctl.h>
64 1.1 ragge #include <sys/buf.h>
65 1.1 ragge #include <sys/proc.h>
66 1.1 ragge #include <sys/user.h>
67 1.1 ragge #include <sys/map.h>
68 1.1 ragge #include <sys/device.h>
69 1.1 ragge #include <sys/dkstat.h>
70 1.1 ragge #include <sys/disklabel.h>
71 1.1 ragge #include <sys/disk.h>
72 1.1 ragge #include <sys/syslog.h>
73 1.1 ragge
74 1.1 ragge #include <machine/pte.h>
75 1.1 ragge #include <machine/sid.h>
76 1.1 ragge #include <machine/cpu.h>
77 1.1 ragge #include <machine/uvax.h>
78 1.1 ragge #include <machine/ka410.h>
79 1.1 ragge #include <machine/vsbus.h>
80 1.1 ragge
81 1.1 ragge #include <vax/vsa/hdc9224.h>
82 1.1 ragge
83 1.1 ragge
84 1.1 ragge /*
85 1.1 ragge * some definitions
86 1.1 ragge */
87 1.1 ragge #define CTLRNAME "hdc"
88 1.1 ragge #define UNITNAME "rd"
89 1.1 ragge #define HDC_PRI LOG_INFO
90 1.1 ragge
91 1.1 ragge /* Bits in minor device */
92 1.1 ragge #define HDCUNIT(dev) DISKUNIT(dev)
93 1.1 ragge #define HDCPART(dev) DISKPART(dev)
94 1.1 ragge #define HDCCTLR(dev) 0
95 1.1 ragge #define HDCLABELDEV(dev) (MAKEDISKDEV(major(dev),HDCUNIT(dev),RAW_PART))
96 1.1 ragge
97 1.1 ragge #define MAX_WAIT (1000*1000) /* # of loop-instructions in seconds */
98 1.1 ragge
99 1.1 ragge
100 1.1 ragge /*
101 1.1 ragge * on-disk geometry block
102 1.1 ragge */
103 1.1 ragge #define _aP __attribute__ ((packed)) /* force byte-alignment */
104 1.1 ragge struct rdgeom {
105 1.1 ragge char mbz[10]; /* 10 bytes of zero */
106 1.1 ragge long xbn_count _aP; /* number of XBNs */
107 1.1 ragge long dbn_count _aP; /* number of DBNs */
108 1.1 ragge long lbn_count _aP; /* number of LBNs (Logical-Block-Numbers) */
109 1.1 ragge long rbn_count _aP; /* number of RBNs (Replacement-Block-Numbers) */
110 1.1 ragge short nspt; /* number of sectors per track */
111 1.1 ragge short ntracks; /* number of tracks */
112 1.1 ragge short ncylinders; /* number of cylinders */
113 1.1 ragge short precomp; /* first cylinder for write precompensation */
114 1.1 ragge short reduced; /* first cylinder for reduced write current */
115 1.1 ragge short seek_rate; /* seek rate or zero for buffered seeks */
116 1.1 ragge short crc_eec; /* 0 if CRC is being used or 1 if ECC is being used */
117 1.1 ragge short rct; /* "replacement control table" (RCT) */
118 1.1 ragge short rct_ncopies; /* number of copies of the RCT */
119 1.1 ragge long media_id _aP; /* media identifier */
120 1.1 ragge short interleave; /* sector-to-sector interleave */
121 1.1 ragge short headskew; /* head-to-head skew */
122 1.1 ragge short cylskew; /* cylinder-to-cylinder skew */
123 1.1 ragge short gap0_size; /* size of GAP 0 in the MFM format */
124 1.1 ragge short gap1_size; /* size of GAP 1 in the MFM format */
125 1.1 ragge short gap2_size; /* size of GAP 2 in the MFM format */
126 1.1 ragge short gap3_size; /* size of GAP 3 in the MFM format */
127 1.1 ragge short sync_value; /* sync value used to start a track when formatting */
128 1.1 ragge char reserved[32]; /* reserved for use by the RQDX1/2/3 formatter */
129 1.1 ragge short serial_number; /* serial number */
130 1.1 ragge #if 0 /* we don't need these 412 useless bytes ... */
131 1.1 ragge char fill[412-2]; /* Filler bytes to the end of the block */
132 1.1 ragge short checksum; /* checksum over the XBN */
133 1.1 ragge #endif
134 1.1 ragge };
135 1.1 ragge
136 1.1 ragge /*
137 1.1 ragge * Software status
138 1.1 ragge */
139 1.1 ragge struct rdsoftc {
140 1.1 ragge struct device sc_dev; /* must be here! (pseudo-OOP:) */
141 1.1 ragge struct disk sc_dk; /* disklabel etc. */
142 1.1 ragge struct rdgeom sc_xbn; /* on-disk geometry information */
143 1.1 ragge struct rdparams {
144 1.1 ragge u_short cylinders; /* number of cylinders */
145 1.1 ragge u_char heads; /* number of heads (tracks) */
146 1.1 ragge u_char sectors; /* number of sectors/track */
147 1.1 ragge u_long diskblks; /* number of sectors/disk */
148 1.1 ragge u_long disklbns; /* number of available sectors */
149 1.1 ragge u_long blksize; /* number of bytes/sector */
150 1.1 ragge u_long diskbytes; /* number of bytes/disk */
151 1.1 ragge char diskname[8];
152 1.1 ragge } sc_param;
153 1.1 ragge int sc_drive; /* physical unit number */
154 1.1 ragge int sc_flags;
155 1.1 ragge int sc_state;
156 1.1 ragge int sc_mode;
157 1.1 ragge };
158 1.1 ragge
159 1.1 ragge struct hdcsoftc {
160 1.1 ragge struct device sc_dev; /* must be here (pseudo-OOP:) */
161 1.1 ragge struct hdc9224_DKCreg *sc_dkc; /* I/O address of the controller */
162 1.1 ragge struct hdc9224_UDCreg sc_creg; /* (command) registers to be written */
163 1.1 ragge struct hdc9224_UDCreg sc_sreg; /* (status) registers being read */
164 1.1 ragge struct confargs *sc_cfargs; /* remember args being probed with */
165 1.1 ragge char *sc_dmabase; /* */
166 1.1 ragge long sc_dmasize; /* */
167 1.1 ragge long sc_ioaddr; /* unmapped I/O address */
168 1.1 ragge long sc_ivec; /* interrupt vector address */
169 1.1 ragge short sc_ibit; /* bit-value in interrupt register */
170 1.1 ragge short sc_status; /* copy of status register */
171 1.1 ragge short sc_state;
172 1.1 ragge short sc_flags;
173 1.1 ragge short sc_errors;
174 1.1 ragge };
175 1.1 ragge
176 1.1 ragge /*
177 1.1 ragge * Device definition for (new) autoconfiguration.
178 1.1 ragge */
179 1.1 ragge int hdcmatch __P((struct device *parent, void *cfdata, void *aux));
180 1.1 ragge void hdcattach __P((struct device *parent, struct device *self, void *aux));
181 1.2 cgd int hdcprint __P((void *aux, const char *name));
182 1.1 ragge
183 1.1 ragge struct cfdriver hdc_cd = {
184 1.1 ragge NULL, "hdc", DV_DULL
185 1.1 ragge };
186 1.1 ragge struct cfattach hdc_ca = {
187 1.1 ragge sizeof(struct hdcsoftc), hdcmatch, hdcattach
188 1.1 ragge };
189 1.1 ragge
190 1.1 ragge int rdmatch __P((struct device *parent, void *cfdata, void *aux));
191 1.1 ragge void rdattach __P((struct device *parent, struct device *self, void *aux));
192 1.2 cgd int rdprint __P((void *aux, const char *name));
193 1.1 ragge void rdstrategy __P((struct buf *bp));
194 1.1 ragge
195 1.1 ragge struct cfdriver rd_cd = {
196 1.1 ragge NULL, "rd", DV_DISK
197 1.1 ragge };
198 1.1 ragge struct cfattach rd_ca = {
199 1.1 ragge sizeof(struct rdsoftc), rdmatch, rdattach
200 1.1 ragge };
201 1.1 ragge
202 1.1 ragge struct dkdriver rddkdriver = { rdstrategy };
203 1.1 ragge
204 1.1 ragge /*
205 1.1 ragge * prototypes for (almost) all the internal routines
206 1.1 ragge */
207 1.1 ragge int hdc_reset __P((struct hdcsoftc *sc));
208 1.1 ragge int hdc_select __P((struct hdcsoftc *sc, int drive));
209 1.1 ragge int hdc_command __P((struct hdcsoftc *sc, int cmd));
210 1.1 ragge
211 1.1 ragge int hdc_getdata __P((struct hdcsoftc *hdc, struct rdsoftc *rd, int drive));
212 1.1 ragge int hdc_getlabel __P((struct hdcsoftc *hdc, struct rdsoftc *rd, int drive));
213 1.1 ragge
214 1.1 ragge void rdgetlabel __P((struct rdsoftc *sc));
215 1.1 ragge
216 1.1 ragge /*
217 1.1 ragge * new-config's hdcmatch() is similiar to old-config's hdcprobe(),
218 1.1 ragge * thus we probe for the existence of the controller and reset it.
219 1.1 ragge * NB: we can't initialize the controller yet, since space for hdcsoftc
220 1.1 ragge * is not yet allocated. Thus we do this in hdcattach()...
221 1.1 ragge */
222 1.1 ragge int
223 1.1 ragge hdcmatch(parent, match, aux)
224 1.1 ragge struct device *parent;
225 1.1 ragge void *match, *aux;
226 1.1 ragge {
227 1.1 ragge struct cfdata *cf = match;
228 1.1 ragge struct confargs *ca = aux;
229 1.1 ragge
230 1.1 ragge trace(("hdcmatch(0x%x, %d, %s)\n", parent, cf->cf_unit, ca->ca_name));
231 1.1 ragge
232 1.1 ragge if (strcmp(ca->ca_name, "hdc") &&
233 1.1 ragge strcmp(ca->ca_name, "hdc9224") &&
234 1.1 ragge strcmp(ca->ca_name, "HDC9224"))
235 1.1 ragge return (0);
236 1.1 ragge
237 1.1 ragge /*
238 1.1 ragge * only(?) VS2000/KA410 has exactly one HDC9224 controller
239 1.1 ragge */
240 1.1 ragge if (vax_boardtype != VAX_BTYP_410) {
241 1.4 christos printf ("unexpected boardtype 0x%x in hdcmatch()\n",
242 1.1 ragge vax_boardtype);
243 1.1 ragge return (0);
244 1.1 ragge }
245 1.1 ragge if (cf->cf_unit != 0)
246 1.1 ragge return (0);
247 1.1 ragge
248 1.1 ragge return (1);
249 1.1 ragge }
250 1.1 ragge
251 1.1 ragge struct hdc_attach_args {
252 1.1 ragge int ha_drive;
253 1.1 ragge };
254 1.1 ragge
255 1.1 ragge int
256 1.1 ragge rdprint(aux, name)
257 1.1 ragge void *aux;
258 1.2 cgd const char *name;
259 1.1 ragge {
260 1.1 ragge struct hdc_attach_args *ha = aux;
261 1.1 ragge
262 1.1 ragge trace(("rdprint(%d, %s)\n", ha->ha_drive, name));
263 1.1 ragge
264 1.1 ragge if (!name)
265 1.4 christos printf (" drive %d", ha->ha_drive);
266 1.1 ragge return (QUIET);
267 1.1 ragge }
268 1.1 ragge
269 1.1 ragge /*
270 1.1 ragge * hdc_attach() probes for all possible devices
271 1.1 ragge */
272 1.1 ragge void
273 1.1 ragge hdcattach(parent, self, aux)
274 1.1 ragge struct device *parent, *self;
275 1.1 ragge void *aux;
276 1.1 ragge {
277 1.1 ragge struct hdcsoftc *sc = (void*)self;
278 1.1 ragge struct confargs *ca = aux;
279 1.1 ragge struct hdc_attach_args ha;
280 1.1 ragge
281 1.1 ragge trace(("hdcattach(0x%x, 0x%x, %s)\n", parent, self, ca->ca_name));
282 1.1 ragge
283 1.4 christos printf ("\n");
284 1.1 ragge /*
285 1.1 ragge * first reset/initialize the controller
286 1.1 ragge */
287 1.1 ragge sc->sc_cfargs = ca;
288 1.1 ragge
289 1.1 ragge sc->sc_ioaddr = ca->ca_ioaddr;
290 1.1 ragge sc->sc_dkc = (void*)uvax_phys2virt(sc->sc_ioaddr);
291 1.1 ragge sc->sc_ibit = ca->ca_intbit;
292 1.1 ragge sc->sc_ivec = ca->ca_intvec;
293 1.1 ragge sc->sc_status = 0;
294 1.1 ragge sc->sc_state = 0;
295 1.1 ragge sc->sc_flags = 0;
296 1.1 ragge sc->sc_errors = 0;
297 1.1 ragge
298 1.1 ragge sc->sc_dkc = (void*)uvax_phys2virt(KA410_DKC_BASE);
299 1.1 ragge sc->sc_dmabase = (void*)uvax_phys2virt(KA410_DMA_BASE);
300 1.1 ragge sc->sc_dmasize = KA410_DMA_SIZE;
301 1.1 ragge
302 1.1 ragge if (hdc_reset(sc) != 0) {
303 1.1 ragge delay(500*1000); /* wait .5 seconds */
304 1.1 ragge if (hdc_reset(sc) != 0)
305 1.4 christos printf ("problems with hdc_reset()...\n");
306 1.1 ragge }
307 1.1 ragge
308 1.1 ragge /*
309 1.1 ragge * now probe for all possible disks
310 1.1 ragge */
311 1.1 ragge for (ha.ha_drive=0; ha.ha_drive<3; ha.ha_drive++)
312 1.1 ragge (void)config_found(self, (void*)&ha, rdprint);
313 1.1 ragge
314 1.1 ragge #ifdef notyet
315 1.1 ragge /*
316 1.1 ragge * now that probing is done, we can register and enable interrupts
317 1.1 ragge */
318 1.1 ragge vsbus_intr_register(XXX);
319 1.1 ragge vsbus_intr_enable(XXX);
320 1.1 ragge #endif
321 1.1 ragge }
322 1.1 ragge
323 1.1 ragge /*
324 1.1 ragge * rdmatch() probes for the existence of a RD-type disk/floppy
325 1.1 ragge */
326 1.1 ragge int
327 1.1 ragge rdmatch(parent, match, aux)
328 1.1 ragge struct device *parent;
329 1.1 ragge void *match, *aux;
330 1.1 ragge {
331 1.1 ragge struct hdcsoftc *hdc = (void*)parent;
332 1.1 ragge struct cfdata *cf = match;
333 1.1 ragge struct hdc_attach_args *ha = aux;
334 1.1 ragge int drive = ha->ha_drive;
335 1.1 ragge int res;
336 1.1 ragge
337 1.1 ragge trace(("rdmatch(%d, %d)\n", cf->cf_unit, drive));
338 1.1 ragge
339 1.1 ragge if (cf->cf_unit != ha->ha_drive)
340 1.1 ragge return (0);
341 1.1 ragge
342 1.1 ragge switch (drive) {
343 1.1 ragge case 0:
344 1.1 ragge case 1:
345 1.1 ragge case 2:
346 1.1 ragge res = hdc_select(hdc, drive);
347 1.1 ragge break;
348 1.1 ragge default:
349 1.4 christos printf ("rdmatch: invalid unit-number %d\n", drive);
350 1.1 ragge return (0);
351 1.1 ragge }
352 1.1 ragge
353 1.1 ragge debug (("cstat: %x dstat: %x\n", hdc->sc_sreg.udc_cstat,
354 1.1 ragge hdc->sc_sreg.udc_dstat));
355 1.1 ragge if (drive == 1)
356 1.1 ragge return (0); /* XXX */
357 1.1 ragge
358 1.1 ragge return (1);
359 1.1 ragge }
360 1.1 ragge
361 1.1 ragge void
362 1.1 ragge rdattach(parent, self, aux)
363 1.1 ragge struct device *parent, *self;
364 1.1 ragge void *aux;
365 1.1 ragge {
366 1.1 ragge struct hdcsoftc *hdc = (void*)parent;
367 1.1 ragge struct rdsoftc *rd = (void*)self;
368 1.1 ragge struct hdc_attach_args *ha = aux;
369 1.1 ragge struct rdparams *rp = &rd->sc_param;
370 1.1 ragge
371 1.1 ragge trace(("rdattach(%d)\n", ha->ha_drive));
372 1.1 ragge
373 1.1 ragge rd->sc_drive = ha->ha_drive;
374 1.1 ragge /*
375 1.1 ragge * Initialize and attach the disk structure.
376 1.1 ragge */
377 1.1 ragge rd->sc_dk.dk_driver = &rddkdriver;
378 1.1 ragge rd->sc_dk.dk_name = rd->sc_dev.dv_xname;
379 1.1 ragge disk_attach(&rd->sc_dk);
380 1.1 ragge /*
381 1.1 ragge * if it's not a floppy then evaluate the on-disk geometry.
382 1.1 ragge * if neccessary correct the label...
383 1.1 ragge */
384 1.4 christos printf("\n%s: ", rd->sc_dev.dv_xname);
385 1.1 ragge if (rd->sc_drive == 2) {
386 1.4 christos printf("floppy (RX33)\n");
387 1.1 ragge }
388 1.1 ragge else {
389 1.1 ragge hdc_getdata(hdc, rd, rd->sc_drive);
390 1.4 christos printf("%s, %d MB, %d LBN, %d cyl, %d head, %d sect/track\n",
391 1.1 ragge rp->diskname, rp->diskblks/2048, rp->disklbns,
392 1.1 ragge rp->cylinders, rp->heads, rp->sectors);
393 1.1 ragge }
394 1.1 ragge }
395 1.1 ragge
396 1.1 ragge /*
397 1.1 ragge * Read/write routine for a buffer. For now we poll the controller,
398 1.1 ragge * thus this routine waits for the transfer to complete.
399 1.1 ragge */
400 1.1 ragge void
401 1.1 ragge rdstrategy(bp)
402 1.1 ragge struct buf *bp;
403 1.1 ragge {
404 1.1 ragge struct rdsoftc *rd = rd_cd.cd_devs[HDCUNIT(bp->b_dev)];
405 1.1 ragge struct hdcsoftc *hdc = (void *)rd->sc_dev.dv_parent;
406 1.1 ragge struct partition *p;
407 1.1 ragge int blkno, i, s;
408 1.1 ragge
409 1.1 ragge trace (("rdstrategy(#%d/%d)\n", bp->b_blkno, bp->b_bcount));
410 1.1 ragge
411 1.1 ragge /* XXX should make some checks... */
412 1.1 ragge
413 1.1 ragge /*
414 1.1 ragge * If it's a null transfer, return immediatly
415 1.1 ragge */
416 1.1 ragge if (bp->b_bcount == 0)
417 1.1 ragge goto done;
418 1.1 ragge
419 1.1 ragge /*
420 1.1 ragge * what follows now should not be here but in rdstart...
421 1.1 ragge */
422 1.1 ragge /*------------------------------*/
423 1.1 ragge blkno = bp->b_blkno / (rd->sc_dk.dk_label->d_secsize / DEV_BSIZE);
424 1.1 ragge if (HDCPART(bp->b_dev) != RAW_PART) {
425 1.1 ragge p = &rd->sc_dk.dk_label->d_partitions[HDCPART(bp->b_dev)];
426 1.1 ragge blkno += p->p_offset;
427 1.1 ragge }
428 1.1 ragge /* nblks = howmany(bp->b_bcount, sd->sc_dk.dk_label->d_secsize); */
429 1.1 ragge
430 1.1 ragge if (hdc_strategy(hdc, rd, HDCUNIT(bp->b_dev),
431 1.1 ragge ((bp->b_flags & B_READ) ? F_READ : F_WRITE),
432 1.1 ragge blkno, bp->b_bcount, bp->b_data) == 0)
433 1.1 ragge goto done;
434 1.1 ragge /*------------------------------*/
435 1.1 ragge bad:
436 1.1 ragge bp->b_flags |= B_ERROR;
437 1.1 ragge done:
438 1.1 ragge /*
439 1.1 ragge * Correctly set the buf to indicate a completed xfer
440 1.1 ragge */
441 1.1 ragge bp->b_resid = 0; /* ??? bertram */
442 1.1 ragge biodone(bp);
443 1.1 ragge }
444 1.1 ragge
445 1.1 ragge int
446 1.1 ragge hdc_strategy(hdc, rd, unit, func, dblk, size, buf)
447 1.1 ragge struct hdcsoftc *hdc;
448 1.1 ragge struct rdsoftc *rd;
449 1.1 ragge int unit;
450 1.1 ragge int func;
451 1.1 ragge int dblk;
452 1.1 ragge int size;
453 1.1 ragge char *buf;
454 1.1 ragge {
455 1.1 ragge struct hdc9224_UDCreg *p = &hdc->sc_creg;
456 1.1 ragge struct disklabel *lp = rd->sc_dk.dk_label;
457 1.1 ragge int sect, head, cyl;
458 1.1 ragge int scount;
459 1.1 ragge int cmd, res = 0;
460 1.1 ragge
461 1.1 ragge trace (("hdc_strategy(%d, %d, %d, %d, 0x%x)\n",
462 1.1 ragge unit, func, dblk, size, buf));
463 1.1 ragge
464 1.1 ragge hdc_select(hdc, unit); /* select drive right now */
465 1.1 ragge
466 1.1 ragge if (unit != 2 && dblk == -1) { /* read the on-disk geometry */
467 1.1 ragge
468 1.1 ragge p->udc_dma7 = 0;
469 1.1 ragge p->udc_dma15 = 0;
470 1.1 ragge p->udc_dma23 = 0;
471 1.1 ragge
472 1.1 ragge p->udc_dsect = 0;
473 1.1 ragge p->udc_dhead = 0;
474 1.1 ragge p->udc_dcyl = 0;
475 1.1 ragge
476 1.1 ragge p->udc_scnt = size/512;
477 1.1 ragge p->udc_rtcnt = 0xF0;
478 1.1 ragge p->udc_mode = 0xC0;
479 1.1 ragge p->udc_term = 0xB4;
480 1.1 ragge
481 1.1 ragge vsbus_lockDMA(hdc->sc_cfargs); /* bertram XXX */
482 1.1 ragge haveLock = 1;
483 1.1 ragge keepLock = 1;
484 1.1 ragge
485 1.1 ragge #ifdef PARANOID
486 1.1 ragge bzero (hdc->sc_dmabase, size); /* clear disk buffer */
487 1.1 ragge #endif
488 1.1 ragge cmd = 0x5C | 0x03; /* bypass bad sectors */
489 1.1 ragge cmd = 0x5C | 0x01; /* terminate if bad sector */
490 1.1 ragge
491 1.1 ragge res = hdc_command (hdc, cmd);
492 1.1 ragge /* hold the locking ! */
493 1.1 ragge bcopy (hdc->sc_dmabase, buf, size); /* copy to buf */
494 1.1 ragge /* now release the locking */
495 1.1 ragge
496 1.1 ragge vsbus_unlockDMA(hdc->sc_cfargs);
497 1.1 ragge haveLock = 0;
498 1.1 ragge keepLock = 0;
499 1.1 ragge
500 1.1 ragge return (res);
501 1.1 ragge }
502 1.1 ragge
503 1.1 ragge scount = size / 512;
504 1.1 ragge while (scount) {
505 1.1 ragge /*
506 1.1 ragge * prepare drive/operation parameter
507 1.1 ragge */
508 1.1 ragge cyl = dblk / lp->d_secpercyl;
509 1.1 ragge sect = dblk % lp->d_secpercyl;
510 1.1 ragge head = sect / lp->d_nsectors;
511 1.1 ragge sect = sect % lp->d_nsectors;
512 1.1 ragge if (unit == 2)
513 1.1 ragge sect++;
514 1.1 ragge else
515 1.1 ragge cyl++; /* first cylinder is reserved */
516 1.1 ragge
517 1.1 ragge size = 512 * min(scount, lp->d_nsectors - sect);
518 1.1 ragge
519 1.1 ragge debug (("hdc_strategy: block #%d ==> s/t/c=%d/%d/%d (%d/%d)\n",
520 1.1 ragge dblk, sect, head, cyl, scount, size));
521 1.1 ragge
522 1.1 ragge /*
523 1.1 ragge * now initialize the register values ...
524 1.1 ragge */
525 1.1 ragge p->udc_dma7 = 0;
526 1.1 ragge p->udc_dma15 = 0;
527 1.1 ragge p->udc_dma23 = 0;
528 1.1 ragge
529 1.1 ragge p->udc_dsect = sect;
530 1.1 ragge head |= (cyl >> 4) & 0x70;
531 1.1 ragge p->udc_dhead = head;
532 1.1 ragge p->udc_dcyl = cyl;
533 1.1 ragge
534 1.1 ragge p->udc_scnt = size/512;
535 1.1 ragge
536 1.1 ragge if (unit == 2) { /* floppy */
537 1.1 ragge p->udc_rtcnt = 0xF2;
538 1.1 ragge p->udc_mode = 0x81; /* RX33 with RX50 media */
539 1.1 ragge p->udc_mode = 0x82; /* RX33 with RX33 media */
540 1.1 ragge p->udc_term = 0xB4;
541 1.1 ragge } else { /* disk */
542 1.1 ragge p->udc_rtcnt = 0xF0;
543 1.1 ragge p->udc_mode = 0xC0;
544 1.1 ragge p->udc_term = 0xB4;
545 1.1 ragge }
546 1.1 ragge
547 1.1 ragge vsbus_lockDMA(hdc->sc_cfargs);
548 1.1 ragge haveLock = 1;
549 1.1 ragge keepLock = 1;
550 1.1 ragge
551 1.1 ragge if (func == F_WRITE) {
552 1.1 ragge bcopy (buf, hdc->sc_dmabase, size); /* copy from buf */
553 1.1 ragge cmd = 0xA0 | (unit==2 ? 1 : 0);
554 1.1 ragge res = hdc_command (hdc, cmd);
555 1.1 ragge }
556 1.1 ragge else {
557 1.1 ragge #ifdef PARANOID
558 1.1 ragge bzero (hdc->sc_dmabase, size); /* clear disk buffer */
559 1.1 ragge #endif
560 1.1 ragge cmd = 0x5C | 0x03; /* bypass bad sectors */
561 1.1 ragge cmd = 0x5C | 0x01; /* terminate if bad sector */
562 1.1 ragge res = hdc_command (hdc, cmd);
563 1.1 ragge bcopy (hdc->sc_dmabase, buf, size); /* copy to buf */
564 1.1 ragge }
565 1.1 ragge
566 1.1 ragge vsbus_unlockDMA(hdc->sc_cfargs);
567 1.1 ragge haveLock = 0;
568 1.1 ragge keepLock = 0;
569 1.1 ragge
570 1.1 ragge scount -= size/512;
571 1.1 ragge dblk += size/512;
572 1.1 ragge buf += size;
573 1.1 ragge }
574 1.1 ragge
575 1.1 ragge if (unit != 2) /* deselect drive, if not floppy */
576 1.1 ragge hdc_command (hdc, DKC_CMD_DRDESELECT);
577 1.1 ragge
578 1.1 ragge return 0;
579 1.1 ragge }
580 1.1 ragge
581 1.1 ragge char hdc_iobuf[17*512]; /* we won't need more */
582 1.1 ragge
583 1.1 ragge #ifdef DEBUG
584 1.1 ragge /*
585 1.1 ragge * display the contents of the on-disk geometry structure
586 1.1 ragge */
587 1.1 ragge int
588 1.1 ragge hdc_printgeom(p)
589 1.1 ragge struct rdgeom *p;
590 1.1 ragge {
591 1.1 ragge char dname[8];
592 1.1 ragge hdc_mid2str(p->media_id, dname);
593 1.1 ragge
594 1.4 christos printf ("**DiskData** XBNs: %d, DBNs: %d, LBNs: %d, RBNs: %d\n",
595 1.1 ragge p->xbn_count, p->dbn_count, p->lbn_count, p->rbn_count);
596 1.4 christos printf ("sec/track: %d, tracks: %d, cyl: %d, precomp/reduced: %d/%d\n",
597 1.1 ragge p->nspt, p->ntracks, p->ncylinders, p->precomp, p->reduced);
598 1.4 christos printf ("seek-rate: %d, crc/eec: %s, RCT: %d, RCT-copies: %d\n",
599 1.1 ragge p->seek_rate, p->crc_eec?"EEC":"CRC", p->rct, p->rct_ncopies);
600 1.4 christos printf ("media-ID: %s, interleave: %d, headskew: %d, cylskew: %d\n",
601 1.1 ragge dname, p->interleave, p->headskew, p->cylskew);
602 1.4 christos printf ("gap0: %d, gap1: %d, gap2: %d, gap3: %d, sync-value: %d\n",
603 1.1 ragge p->gap0_size, p->gap1_size, p->gap2_size, p->gap3_size,
604 1.1 ragge p->sync_value);
605 1.1 ragge }
606 1.1 ragge #endif
607 1.1 ragge
608 1.1 ragge /*
609 1.1 ragge * Convert media_id to string/name (encoding is documented in mscp.h)
610 1.1 ragge */
611 1.1 ragge int
612 1.1 ragge hdc_mid2str(media_id, name)
613 1.1 ragge long media_id;
614 1.1 ragge char *name;
615 1.1 ragge {
616 1.1 ragge struct { /* For RD32 this struct holds: */
617 1.1 ragge u_long mt:7; /* number in name: 0x20 == 32 */
618 1.1 ragge u_long a2:5; /* ' ' encoded as 0x0 */
619 1.1 ragge u_long a1:5; /* 'D' encoded with base '@' */
620 1.1 ragge u_long a0:5; /* 'R' encoded with base '@' */
621 1.1 ragge u_long d1:5; /* 'U' encoded with base '@' */
622 1.1 ragge u_long d0:5; /* 'D' encoded with base '@' */
623 1.1 ragge } *p = (void*)&media_id;
624 1.1 ragge
625 1.1 ragge #define MIDCHR(x) (x ? x + '@' : ' ')
626 1.1 ragge
627 1.4 christos sprintf (name, "%c%c%d", MIDCHR(p->a0), MIDCHR(p->a1), p->mt);
628 1.1 ragge }
629 1.1 ragge
630 1.1 ragge int
631 1.1 ragge hdc_getdata(hdc, rd, unit)
632 1.1 ragge struct hdcsoftc *hdc;
633 1.1 ragge struct rdsoftc *rd;
634 1.1 ragge int unit;
635 1.1 ragge {
636 1.1 ragge struct disklabel *lp = rd->sc_dk.dk_label;
637 1.1 ragge struct rdparams *rp = &rd->sc_param;
638 1.1 ragge int res;
639 1.1 ragge
640 1.1 ragge trace (("hdc_getdata(%d)\n", unit));
641 1.1 ragge
642 1.1 ragge bzero(rd->sc_dk.dk_label, sizeof(struct disklabel));
643 1.1 ragge bzero(rd->sc_dk.dk_cpulabel, sizeof(struct cpu_disklabel));
644 1.1 ragge
645 1.1 ragge if (unit == 2) {
646 1.1 ragge lp->d_secsize = DEV_BSIZE;
647 1.1 ragge lp->d_ntracks = 2;
648 1.1 ragge lp->d_nsectors = 15;
649 1.1 ragge lp->d_ncylinders = 80;
650 1.1 ragge lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
651 1.1 ragge
652 1.1 ragge return (0);
653 1.1 ragge }
654 1.1 ragge
655 1.1 ragge res = hdc_strategy(hdc, rd, unit, F_READ, -1, 4096, hdc_iobuf);
656 1.1 ragge bcopy (hdc_iobuf, &rd->sc_xbn, sizeof(struct rdgeom));
657 1.1 ragge #ifdef DEBUG
658 1.1 ragge hdc_printgeom(&rd->sc_xbn);
659 1.1 ragge #endif
660 1.1 ragge lp->d_secsize = DEV_BSIZE;
661 1.1 ragge lp->d_ntracks = rd->sc_xbn.ntracks;
662 1.1 ragge lp->d_nsectors = rd->sc_xbn.nspt;
663 1.1 ragge lp->d_ncylinders = rd->sc_xbn.ncylinders;
664 1.1 ragge lp->d_secpercyl = lp->d_ntracks * lp->d_nsectors;
665 1.1 ragge
666 1.1 ragge rp->cylinders = rd->sc_xbn.ncylinders;
667 1.1 ragge rp->heads = rd->sc_xbn.ntracks;
668 1.1 ragge rp->sectors = rd->sc_xbn.nspt;
669 1.1 ragge rp->diskblks = rp->cylinders * rp->heads * rp->sectors;
670 1.1 ragge rp->disklbns = rd->sc_xbn.lbn_count;
671 1.1 ragge rp->blksize = DEV_BSIZE;
672 1.1 ragge rp->diskbytes = rp->disklbns * rp->blksize;
673 1.1 ragge hdc_mid2str(rd->sc_xbn.media_id, rp->diskname);
674 1.1 ragge
675 1.1 ragge return (0);
676 1.1 ragge }
677 1.1 ragge
678 1.1 ragge int
679 1.1 ragge hdc_getlabel(hdc, rd, unit)
680 1.1 ragge struct hdcsoftc *hdc;
681 1.1 ragge struct rdsoftc *rd;
682 1.1 ragge int unit;
683 1.1 ragge {
684 1.1 ragge struct disklabel *lp = rd->sc_dk.dk_label;
685 1.1 ragge struct disklabel *xp = (void*)(hdc_iobuf + 64);
686 1.1 ragge int res;
687 1.1 ragge
688 1.1 ragge trace (("hdc_getlabel(%d)\n", unit));
689 1.1 ragge
690 1.1 ragge #define LBL_CHECK(x) if (xp->x != lp->x) { \
691 1.4 christos printf ("%d-->%d\n", xp->x, lp->x); \
692 1.1 ragge xp->x = lp->x; \
693 1.1 ragge }
694 1.1 ragge res = hdc_strategy(hdc, rd, unit, F_READ, 0, DEV_BSIZE, hdc_iobuf);
695 1.1 ragge LBL_CHECK(d_secsize);
696 1.1 ragge LBL_CHECK(d_ntracks);
697 1.1 ragge LBL_CHECK(d_nsectors);
698 1.1 ragge LBL_CHECK(d_ncylinders);
699 1.1 ragge LBL_CHECK(d_secpercyl);
700 1.1 ragge bcopy(xp, lp, sizeof(struct disklabel));
701 1.1 ragge
702 1.1 ragge return (0);
703 1.1 ragge }
704 1.1 ragge
705 1.1 ragge /*
706 1.1 ragge * Return the size of a partition, if known, or -1 if not.
707 1.1 ragge */
708 1.1 ragge hdcsize(dev)
709 1.1 ragge dev_t dev;
710 1.1 ragge {
711 1.1 ragge int unit = HDCUNIT(dev);
712 1.1 ragge int part = HDCPART(dev);
713 1.1 ragge struct rdsoftc *rd = rd_cd.cd_devs[unit];
714 1.1 ragge int size;
715 1.1 ragge
716 1.1 ragge trace (("hdcsize(%x == %d/%d)\n", dev, unit, part));
717 1.1 ragge
718 1.1 ragge if (hdcopen(dev, 0, S_IFBLK) != 0)
719 1.1 ragge return (-1);
720 1.1 ragge #if 0
721 1.1 ragge if (rd->sc_dk.dk_label->d_partitions[part].p_fstype != FS_SWAP)
722 1.1 ragge size = -1;
723 1.1 ragge else
724 1.1 ragge #endif
725 1.1 ragge size = rd->sc_dk.dk_label->d_partitions[part].p_size;
726 1.1 ragge if (hdcclose(dev, 0, S_IFBLK) != 0)
727 1.1 ragge return (-1);
728 1.1 ragge debug (("hdcsize: size=%d\n", size));
729 1.1 ragge return (size);
730 1.1 ragge }
731 1.1 ragge
732 1.1 ragge /*
733 1.1 ragge *
734 1.1 ragge */
735 1.1 ragge int
736 1.1 ragge hdcopen (dev, flag, fmt)
737 1.1 ragge dev_t dev;
738 1.1 ragge int flag;
739 1.1 ragge int fmt;
740 1.1 ragge {
741 1.1 ragge int unit = HDCUNIT(dev);
742 1.1 ragge int part = HDCPART(dev);
743 1.1 ragge struct hdcsoftc *hdc;
744 1.1 ragge struct rdsoftc *rd;
745 1.1 ragge int res, error;
746 1.1 ragge
747 1.1 ragge trace (("hdcopen(0x%x = %d/%d)\n", dev, unit, part));
748 1.1 ragge
749 1.1 ragge if (unit >= rd_cd.cd_ndevs) {
750 1.4 christos printf ("hdcopen: invalid unit %d\n", unit);
751 1.1 ragge return ENXIO;
752 1.1 ragge }
753 1.1 ragge rd = rd_cd.cd_devs[unit];
754 1.1 ragge if (!rd) {
755 1.4 christos printf("hdcopen: null-pointer in rdsoftc.\n");
756 1.1 ragge return (ENXIO);
757 1.1 ragge }
758 1.1 ragge hdc = (void *)rd->sc_dev.dv_parent;
759 1.1 ragge
760 1.1 ragge /* XXX here's much more to do! XXX */
761 1.1 ragge
762 1.1 ragge hdc_getdata (hdc, rd, unit);
763 1.1 ragge hdc_getlabel (hdc, rd, unit);
764 1.1 ragge
765 1.1 ragge return (0);
766 1.1 ragge }
767 1.1 ragge
768 1.1 ragge /*
769 1.1 ragge *
770 1.1 ragge */
771 1.1 ragge int
772 1.1 ragge hdcclose (dev, flag)
773 1.1 ragge dev_t dev;
774 1.1 ragge int flag;
775 1.1 ragge {
776 1.1 ragge trace (("hdcclose()\n"));
777 1.1 ragge return (0);
778 1.1 ragge }
779 1.1 ragge
780 1.1 ragge /*
781 1.1 ragge *
782 1.1 ragge */
783 1.1 ragge void
784 1.1 ragge hdcstrategy(bp)
785 1.1 ragge register struct buf *bp;
786 1.1 ragge {
787 1.1 ragge trace (("hdcstrategy()\n"));
788 1.1 ragge rdstrategy(bp);
789 1.1 ragge debug (("hdcstrategy done.\n"));
790 1.1 ragge }
791 1.1 ragge
792 1.1 ragge /*
793 1.1 ragge *
794 1.1 ragge */
795 1.1 ragge int
796 1.1 ragge hdcioctl(dev, cmd, data, flag, p)
797 1.1 ragge dev_t dev;
798 1.1 ragge int cmd;
799 1.1 ragge caddr_t data; /* aka: addr */
800 1.1 ragge int flag;
801 1.1 ragge struct proc *p;
802 1.1 ragge {
803 1.1 ragge struct rdsoftc *rd = rd_cd.cd_devs[HDCUNIT(dev)];
804 1.1 ragge struct hdcsoftc *hdc = (void *)rd->sc_dev.dv_parent;
805 1.1 ragge int error;
806 1.1 ragge
807 1.1 ragge trace (("hdcioctl(%x, %x)\n", dev, cmd));
808 1.1 ragge
809 1.1 ragge /*
810 1.1 ragge * If the device is not valid.. abandon ship
811 1.1 ragge */
812 1.1 ragge /* XXX */
813 1.1 ragge
814 1.1 ragge switch (cmd) {
815 1.1 ragge case DIOCGDINFO:
816 1.1 ragge *(struct disklabel *)data = *(rd->sc_dk.dk_label);
817 1.1 ragge return (0);
818 1.1 ragge
819 1.1 ragge case DIOCGPART:
820 1.1 ragge ((struct partinfo *)data)->disklab = rd->sc_dk.dk_label;
821 1.1 ragge ((struct partinfo *)data)->part =
822 1.1 ragge &rd->sc_dk.dk_label->d_partitions[HDCPART(dev)];
823 1.1 ragge return (0);
824 1.1 ragge
825 1.1 ragge case DIOCWDINFO:
826 1.1 ragge case DIOCSDINFO:
827 1.1 ragge /* XXX
828 1.1 ragge if ((flag & FWRITE) == 0)
829 1.1 ragge return EBADF;
830 1.1 ragge
831 1.1 ragge if ((error = sdlock(sd)) != 0)
832 1.1 ragge return error;
833 1.1 ragge sd->flags |= SDF_LABELLING;
834 1.1 ragge */
835 1.1 ragge error = setdisklabel(rd->sc_dk.dk_label,
836 1.1 ragge (struct disklabel *)data, 0, rd->sc_dk.dk_cpulabel);
837 1.1 ragge if (error == 0) {
838 1.1 ragge if (cmd == DIOCWDINFO)
839 1.1 ragge error = writedisklabel(HDCLABELDEV(dev),
840 1.1 ragge rdstrategy, rd->sc_dk.dk_label,
841 1.1 ragge rd->sc_dk.dk_cpulabel);
842 1.1 ragge }
843 1.1 ragge /* XXX
844 1.1 ragge sd->flags &= ~SDF_LABELLING;
845 1.1 ragge sdunlock(sd);
846 1.1 ragge */
847 1.1 ragge return (error);
848 1.1 ragge
849 1.1 ragge case DIOCWLABEL:
850 1.1 ragge if ((flag & FWRITE) == 0)
851 1.1 ragge return (EBADF);
852 1.1 ragge /* XXX
853 1.1 ragge if (*(int *)data)
854 1.1 ragge sd->flags |= SDF_WLABEL;
855 1.1 ragge else
856 1.1 ragge sd->flags &= ~SDF_WLABEL;
857 1.1 ragge */
858 1.1 ragge return (0);
859 1.1 ragge
860 1.1 ragge default:
861 1.1 ragge if (HDCPART(dev) != RAW_PART)
862 1.1 ragge return ENOTTY;
863 1.4 christos printf ("IOCTL %x not implemented.\n", cmd);
864 1.1 ragge return (-1);
865 1.1 ragge }
866 1.1 ragge }
867 1.1 ragge
868 1.1 ragge /*
869 1.1 ragge *
870 1.1 ragge */
871 1.1 ragge int
872 1.1 ragge hdcintr()
873 1.1 ragge {
874 1.1 ragge trace (("hdcintr()\n"));
875 1.1 ragge }
876 1.1 ragge
877 1.1 ragge /*
878 1.1 ragge *
879 1.1 ragge */
880 1.1 ragge int
881 1.1 ragge hdcread (dev, uio)
882 1.1 ragge dev_t dev;
883 1.1 ragge struct uio *uio;
884 1.1 ragge {
885 1.1 ragge trace (("hdcread()\n"));
886 1.1 ragge return (physio (hdcstrategy, NULL, dev, B_READ, minphys, uio));
887 1.1 ragge }
888 1.1 ragge
889 1.1 ragge /*
890 1.1 ragge *
891 1.1 ragge */
892 1.1 ragge int
893 1.1 ragge hdcwrite (dev, uio)
894 1.1 ragge dev_t dev;
895 1.1 ragge struct uio *uio;
896 1.1 ragge {
897 1.1 ragge trace (("hdcwrite()\n"));
898 1.1 ragge return (physio (hdcstrategy, NULL, dev, B_WRITE, minphys, uio));
899 1.1 ragge }
900 1.1 ragge
901 1.1 ragge /*
902 1.1 ragge *
903 1.1 ragge */
904 1.1 ragge int
905 1.1 ragge hdcdump(dev)
906 1.1 ragge dev_t dev;
907 1.1 ragge {
908 1.1 ragge trace (("hdcdump (%x)\n", dev));
909 1.1 ragge }
910 1.1 ragge
911 1.1 ragge /*
912 1.1 ragge * we have to wait 0.7 usec between two accesses to any of the
913 1.1 ragge * dkc-registers, on a VS2000 with 1 MIPS, this is roughly one
914 1.1 ragge * instruction. Thus the loop-overhead will be enough...
915 1.1 ragge */
916 1.1 ragge void
917 1.1 ragge hdc_readregs(sc)
918 1.1 ragge struct hdcsoftc *sc;
919 1.1 ragge {
920 1.1 ragge int i;
921 1.1 ragge char *p;
922 1.1 ragge
923 1.1 ragge trace(("hdc_readregs()\n"));
924 1.1 ragge
925 1.1 ragge sc->sc_dkc->dkc_cmd = 0x40; /* set internal counter to zero */
926 1.1 ragge p = (void*)&sc->sc_sreg;
927 1.1 ragge for (i=0; i<10; i++)
928 1.1 ragge *p++ = sc->sc_dkc->dkc_reg; /* dkc_reg auto-increments */
929 1.1 ragge }
930 1.1 ragge
931 1.1 ragge void
932 1.1 ragge hdc_writeregs(sc)
933 1.1 ragge struct hdcsoftc *sc;
934 1.1 ragge {
935 1.1 ragge int i;
936 1.1 ragge char *p;
937 1.1 ragge
938 1.1 ragge trace(("hdc_writeregs()\n"));
939 1.1 ragge
940 1.1 ragge sc->sc_dkc->dkc_cmd = 0x40; /* set internal counter to zero */
941 1.1 ragge p = (void*)&sc->sc_creg;
942 1.1 ragge for (i=0; i<10; i++)
943 1.1 ragge sc->sc_dkc->dkc_reg = *p++; /* dkc_reg auto-increments */
944 1.1 ragge }
945 1.1 ragge
946 1.1 ragge /*
947 1.1 ragge * hdc_command() issues a command and polls the intreq-register
948 1.1 ragge * to find when command has completed
949 1.1 ragge */
950 1.1 ragge int
951 1.1 ragge hdc_command(sc, cmd)
952 1.1 ragge struct hdcsoftc *sc;
953 1.1 ragge int cmd;
954 1.1 ragge {
955 1.1 ragge volatile u_char *intreq = (void*)uvax_phys2virt(KA410_INTREQ);
956 1.1 ragge volatile u_char *intclr = (void*)uvax_phys2virt(KA410_INTCLR);
957 1.1 ragge volatile u_char *intmsk = (void*)uvax_phys2virt(KA410_INTMSK);
958 1.1 ragge int i, c;
959 1.1 ragge
960 1.1 ragge trace (("hdc_command(%x)\n", cmd));
961 1.1 ragge debug (("intr-state: %x %x %x\n", *intreq, *intclr, *intmsk));
962 1.1 ragge
963 1.1 ragge if (!haveLock) {
964 1.1 ragge vsbus_lockDMA(sc->sc_cfargs);
965 1.1 ragge haveLock = 1;
966 1.1 ragge }
967 1.1 ragge
968 1.1 ragge hdc_writeregs(sc); /* write the prepared registers */
969 1.1 ragge *intclr = INTR_DC; /* clear any old interrupt */
970 1.1 ragge sc->sc_dkc->dkc_cmd = cmd; /* issue the command */
971 1.1 ragge for (i=0; i<MAX_WAIT; i++) {
972 1.1 ragge if ((c = *intreq) & INTR_DC)
973 1.1 ragge break;
974 1.1 ragge }
975 1.1 ragge if ((c & INTR_DC) == 0) {
976 1.4 christos printf ("hdc_command: timeout in command 0x%x\n", cmd);
977 1.1 ragge }
978 1.1 ragge hdc_readregs(sc); /* read the status registers */
979 1.1 ragge sc->sc_status = sc->sc_dkc->dkc_stat;
980 1.1 ragge
981 1.1 ragge if (!keepLock) {
982 1.1 ragge vsbus_unlockDMA(sc->sc_cfargs);
983 1.1 ragge haveLock = 0;
984 1.1 ragge }
985 1.1 ragge
986 1.1 ragge if (sc->sc_status != DKC_ST_DONE|DKC_TC_SUCCESS) {
987 1.4 christos printf ("command 0x%x completed with status 0x%x\n",
988 1.1 ragge cmd, sc->sc_status);
989 1.1 ragge return (-1);
990 1.1 ragge }
991 1.1 ragge return (0);
992 1.1 ragge }
993 1.1 ragge
994 1.1 ragge /*
995 1.1 ragge * writing zero into the command-register will reset the controller.
996 1.1 ragge * This will not interrupt data-transfer commands!
997 1.1 ragge * Also no interrupt is generated, thus we don't use hdc_command()
998 1.1 ragge */
999 1.1 ragge int
1000 1.1 ragge hdc_reset(sc)
1001 1.1 ragge struct hdcsoftc *sc;
1002 1.1 ragge {
1003 1.1 ragge trace (("hdc_reset()\n"));
1004 1.1 ragge
1005 1.1 ragge sc->sc_dkc->dkc_cmd = DKC_CMD_RESET; /* issue RESET command */
1006 1.1 ragge hdc_readregs(sc); /* read the status registers */
1007 1.1 ragge sc->sc_status = sc->sc_dkc->dkc_stat;
1008 1.1 ragge if (sc->sc_status != DKC_ST_DONE|DKC_TC_SUCCESS) {
1009 1.4 christos printf ("RESET command completed with status 0x%x\n",
1010 1.1 ragge sc->sc_status);
1011 1.1 ragge return (-1);
1012 1.1 ragge }
1013 1.1 ragge return (0);
1014 1.1 ragge }
1015 1.1 ragge
1016 1.1 ragge int
1017 1.1 ragge hdc_rxselect(sc, unit)
1018 1.1 ragge struct hdcsoftc *sc;
1019 1.1 ragge int unit;
1020 1.1 ragge {
1021 1.1 ragge register struct hdc9224_UDCreg *p = &sc->sc_creg;
1022 1.1 ragge register struct hdc9224_UDCreg *q = &sc->sc_sreg;
1023 1.1 ragge int error;
1024 1.1 ragge
1025 1.1 ragge /*
1026 1.1 ragge * bring command-regs in some known-to-work state and
1027 1.1 ragge * select the drive with the DRIVE SELECT command.
1028 1.1 ragge */
1029 1.1 ragge p->udc_dma7 = 0;
1030 1.1 ragge p->udc_dma15 = 0;
1031 1.1 ragge p->udc_dma23 = 0;
1032 1.1 ragge p->udc_dsect = 1; /* sectors are numbered 1..15 !!! */
1033 1.1 ragge p->udc_dhead = 0;
1034 1.1 ragge p->udc_dcyl = 0;
1035 1.1 ragge p->udc_scnt = 0;
1036 1.1 ragge
1037 1.1 ragge p->udc_rtcnt = UDC_RC_RX33READ;
1038 1.1 ragge p->udc_mode = UDC_MD_RX33;
1039 1.1 ragge p->udc_term = UDC_TC_FDD;
1040 1.1 ragge
1041 1.1 ragge /*
1042 1.1 ragge * this is ...
1043 1.1 ragge */
1044 1.1 ragge error = hdc_command (sc, DKC_CMD_DRSEL_RX33 | unit);
1045 1.1 ragge
1046 1.1 ragge if ((error != 0) || (q->udc_dstat & UDC_DS_READY == 0)) {
1047 1.4 christos printf("\nfloppy-drive not ready (new floppy inserted?)\n\n");
1048 1.1 ragge p->udc_rtcnt &= ~UDC_RC_INVRDY; /* clear INVRDY-flag */
1049 1.1 ragge error = hdc_command(sc, DKC_CMD_DRSEL_RX33 | unit);
1050 1.1 ragge if ((error != 0) || (q->udc_dstat & UDC_DS_READY == 0)) {
1051 1.4 christos printf("diskette not ready(1): %x/%x\n", error, q->udc_dstat);
1052 1.4 christos printf("floppy-drive offline?\n");
1053 1.1 ragge return (-1);
1054 1.1 ragge }
1055 1.1 ragge
1056 1.1 ragge if (q->udc_dstat & UDC_DS_TRK00) /* if track-0 */
1057 1.1 ragge error = hdc_command(sc, DKC_CMD_STEPIN_FDD); /* step inwards */
1058 1.1 ragge else /* else */
1059 1.1 ragge error = hdc_command(sc, DKC_CMD_STEPOUT_FDD); /* step outwards */
1060 1.1 ragge
1061 1.1 ragge if ((error != 0) || (q->udc_dstat & UDC_DS_READY == 1)) {
1062 1.4 christos printf("diskette not ready(2): %x/%x\n", error, q->udc_dstat);
1063 1.4 christos printf("No floppy inserted or drive offline\n");
1064 1.1 ragge /* return (-1); */
1065 1.1 ragge }
1066 1.1 ragge
1067 1.1 ragge p->udc_rtcnt |= UDC_RC_INVRDY;
1068 1.1 ragge error = hdc_command(sc, DKC_CMD_DRSEL_RX33 | unit);
1069 1.1 ragge if ((error != 0) || (q->udc_dstat & UDC_DS_READY == 0)) {
1070 1.4 christos printf("diskette not ready(3): %x/%x\n", error, q->udc_dstat);
1071 1.4 christos printf("no floppy inserted or floppy-door open\n");
1072 1.1 ragge return(-1);
1073 1.1 ragge }
1074 1.4 christos printf("floppy-drive reselected.\n");
1075 1.1 ragge }
1076 1.1 ragge if (error)
1077 1.1 ragge error = hdc_command (sc, DKC_CMD_DRSEL_RX33 | unit);
1078 1.1 ragge
1079 1.1 ragge return (error);
1080 1.1 ragge }
1081 1.1 ragge
1082 1.1 ragge int
1083 1.1 ragge hdc_rdselect(sc, unit)
1084 1.1 ragge struct hdcsoftc *sc;
1085 1.1 ragge int unit;
1086 1.1 ragge {
1087 1.1 ragge register struct hdc9224_UDCreg *p = &sc->sc_creg;
1088 1.1 ragge register struct hdc9224_UDCreg *q = &sc->sc_sreg;
1089 1.1 ragge int error;
1090 1.1 ragge
1091 1.1 ragge /*
1092 1.1 ragge * bring "creg" in some known-to-work state and
1093 1.1 ragge * select the drive with the DRIVE SELECT command.
1094 1.1 ragge */
1095 1.1 ragge p->udc_dma7 = 0;
1096 1.1 ragge p->udc_dma15 = 0;
1097 1.1 ragge p->udc_dma23 = 0;
1098 1.1 ragge p->udc_dsect = 0; /* sectors are numbered 0..16 */
1099 1.1 ragge p->udc_dhead = 0;
1100 1.1 ragge p->udc_dcyl = 0;
1101 1.1 ragge p->udc_scnt = 0;
1102 1.1 ragge
1103 1.1 ragge p->udc_rtcnt = UDC_RC_HDD_READ;
1104 1.1 ragge p->udc_mode = UDC_MD_HDD;
1105 1.1 ragge p->udc_term = UDC_TC_HDD;
1106 1.1 ragge
1107 1.1 ragge error = hdc_command (sc, DKC_CMD_DRSEL_HDD | unit);
1108 1.1 ragge if (error)
1109 1.1 ragge error = hdc_command (sc, DKC_CMD_DRSEL_HDD | unit);
1110 1.1 ragge
1111 1.1 ragge return (error);
1112 1.1 ragge }
1113 1.1 ragge
1114 1.1 ragge /*
1115 1.1 ragge * bring command-regs into some known-to-work state and select
1116 1.1 ragge * the drive with the DRIVE SELECT command.
1117 1.1 ragge */
1118 1.1 ragge int
1119 1.1 ragge hdc_select(sc, unit)
1120 1.1 ragge struct hdcsoftc *sc;
1121 1.1 ragge int unit;
1122 1.1 ragge {
1123 1.1 ragge int error;
1124 1.1 ragge
1125 1.1 ragge trace (("hdc_select(%x,%d)\n", sc, unit));
1126 1.1 ragge
1127 1.1 ragge switch (unit) {
1128 1.1 ragge case 0:
1129 1.1 ragge case 1:
1130 1.1 ragge error = hdc_rdselect(sc, unit);
1131 1.1 ragge break;
1132 1.1 ragge case 2:
1133 1.1 ragge error = hdc_rxselect(sc, unit);
1134 1.1 ragge /* bertram: delay ??? XXX */
1135 1.1 ragge break;
1136 1.1 ragge default:
1137 1.4 christos printf("invalid unit %d in hdc_select()\n", unit);
1138 1.1 ragge error = -1;
1139 1.1 ragge }
1140 1.1 ragge
1141 1.1 ragge return (error);
1142 1.1 ragge }
1143 1.1 ragge
1144 1.1 ragge #endif /* NHDC > 0 */
1145