1 /* $NetBSD: rd.c,v 1.7 2006/06/25 17:37:43 tsutsui Exp $ */
4 * Copyright (c) 1982, 1990, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * the Systems Programming Group of the University of Utah Computer
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 * from: Utah Hdr: rd.c 1.20 92/12/21
37 * @(#)rd.c 8.1 (Berkeley) 7/15/93
40 * Copyright (c) 1988 University of Utah.
42 * This code is derived from software contributed to Berkeley by
43 * the Systems Programming Group of the University of Utah Computer
46 * Redistribution and use in source and binary forms, with or without
47 * modification, are permitted provided that the following conditions
49 * 1. Redistributions of source code must retain the above copyright
50 * notice, this list of conditions and the following disclaimer.
51 * 2. Redistributions in binary form must reproduce the above copyright
52 * notice, this list of conditions and the following disclaimer in the
53 * documentation and/or other materials provided with the distribution.
54 * 3. All advertising materials mentioning features or use of this software
55 * must display the following acknowledgement:
56 * This product includes software developed by the University of
57 * California, Berkeley and its contributors.
58 * 4. Neither the name of the University nor the names of its contributors
59 * may be used to endorse or promote products derived from this software
60 * without specific prior written permission.
62 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
63 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
64 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
65 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
66 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
67 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
68 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
69 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
70 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
71 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
74 * from: Utah Hdr: rd.c 1.20 92/12/21
76 * @(#)rd.c 8.1 (Berkeley) 7/15/93
80 * CS80/SS80 disk driver
82 #include <sys/param.h>
83 #include <sys/disklabel.h>
85 #include <machine/stdarg.h>
87 #include <lib/libsa/stand.h>
89 #include <hp300/dev/rdreg.h>
91 #include <hp300/stand/common/conf.h>
92 #include <hp300/stand/common/hpibvar.h>
93 #include <hp300/stand/common/samachdep.h>
95 struct rd_iocmd rd_ioc
;
96 struct rd_rscmd rd_rsc
;
97 struct rd_stat rd_stat
;
98 struct rd_ssmcmd rd_ssmc
;
100 struct disklabel rdlabel
;
104 u_long offset
[MAXPARTITIONS
];
114 struct rdminilabel sc_pinfo
;
125 static int rdinit(int, int);
126 static int rdident(int, int);
127 static void rdreset(int, int);
128 static int rdgetinfo(struct rd_softc
*);
129 static int rderror(int, int, int);
131 struct rd_softc rd_softc
[NHPIB
][NRD
];
133 struct rdidentinfo rdidentinfo
[] = {
134 { RD7946AID
, 0, 108416 },
135 { RD9134DID
, 1, 29088 },
136 { RD9134LID
, 1, 1232 },
137 { RD7912PID
, 0, 128128 },
138 { RD7914PID
, 0, 258048 },
139 { RD7958AID
, 0, 255276 },
140 { RD7957AID
, 0, 159544 },
141 { RD7933HID
, 0, 789958 },
142 { RD9134LID
, 1, 77840 },
143 { RD7936HID
, 0, 600978 },
144 { RD7937HID
, 0, 1116102 },
145 { RD7914CTID
, 0, 258048 },
146 { RD7946AID
, 0, 108416 },
147 { RD9134LID
, 1, 1232 },
148 { RD7957BID
, 0, 159894 },
149 { RD7958BID
, 0, 297108 },
150 { RD7959BID
, 0, 594216 },
151 { RD2200AID
, 0, 654948 },
152 { RD2203AID
, 0, 1309896 }
154 int numrdidentinfo
= sizeof(rdidentinfo
) / sizeof(rdidentinfo
[0]);
157 rdinit(int ctlr
, int unit
)
159 struct rd_softc
*rs
= &rd_softc
[ctlr
][unit
];
161 rs
->sc_type
= rdident(ctlr
, unit
);
169 rdreset(int ctlr
, int unit
)
173 rd_ssmc
.c_unit
= C_SUNIT(0);
174 rd_ssmc
.c_cmd
= C_SSM
;
175 rd_ssmc
.c_refm
= REF_MASK
;
176 rd_ssmc
.c_fefm
= FEF_MASK
;
177 rd_ssmc
.c_aefm
= AEF_MASK
;
178 rd_ssmc
.c_iefm
= IEF_MASK
;
179 hpibsend(ctlr
, unit
, C_CMD
, (uint8_t *)&rd_ssmc
, sizeof(rd_ssmc
));
180 hpibswait(ctlr
, unit
);
181 hpibrecv(ctlr
, unit
, C_QSTAT
, &stat
, 1);
185 rdident(int ctlr
, int unit
)
187 struct rd_describe desc
;
188 uint8_t stat
, cmd
[3];
192 id
= hpibid(ctlr
, unit
);
193 if ((id
& 0x200) == 0)
195 for (i
= 0; i
< numrdidentinfo
; i
++)
196 if (id
== rdidentinfo
[i
].ri_hwid
)
198 if (i
== numrdidentinfo
)
205 hpibsend(ctlr
, unit
, C_CMD
, cmd
, sizeof(cmd
));
206 hpibrecv(ctlr
, unit
, C_EXEC
, (uint8_t *)&desc
, 37);
207 hpibrecv(ctlr
, unit
, C_QSTAT
, &stat
, sizeof(stat
));
208 memset(name
, 0, sizeof(name
));
211 for (i
= 5; i
>= 0; i
--) {
212 name
[i
] = (n
& 0xf) + '0';
217 * Take care of a couple of anomolies:
218 * 1. 7945A and 7946A both return same HW id
219 * 2. 9122S and 9134D both return same HW id
220 * 3. 9122D and 9134L both return same HW id
222 switch (rdidentinfo
[id
].ri_hwid
) {
224 if (memcmp(name
, "079450", 6) == 0)
231 if (memcmp(name
, "091340", 6) == 0)
238 if (memcmp(name
, "091220", 6) == 0)
247 char io_buf
[MAXBSIZE
];
250 rdgetinfo(struct rd_softc
*rs
)
252 struct rdminilabel
*pi
= &rs
->sc_pinfo
;
253 struct disklabel
*lp
= &rdlabel
;
258 memset((void *)lp
, 0, sizeof *lp
);
259 lp
->d_secsize
= DEV_BSIZE
;
261 /* Disklabel is always from RAW_PART. */
262 savepart
= rs
->sc_part
;
263 rs
->sc_part
= RAW_PART
;
264 err
= rdstrategy(rs
, F_READ
, LABELSECTOR
,
265 lp
->d_secsize
? lp
->d_secsize
: DEV_BSIZE
, io_buf
, &i
);
266 rs
->sc_part
= savepart
;
269 printf("rdgetinfo: rdstrategy error %d\n", err
);
273 msg
= getdisklabel(io_buf
, lp
);
275 printf("rd(%d,%d,%d): WARNING: %s\n",
276 rs
->sc_ctlr
, rs
->sc_unit
, rs
->sc_part
, msg
);
278 pi
->offset
[0] = pi
->offset
[1] = -1;
281 pi
->npart
= lp
->d_npartitions
;
282 for (i
= 0; i
< pi
->npart
; i
++)
283 pi
->offset
[i
] = lp
->d_partitions
[i
].p_size
== 0 ?
284 -1 : lp
->d_partitions
[i
].p_offset
;
290 rdopen(struct open_file
*f
, ...)
293 int ctlr
, unit
, part
;
297 ctlr
= va_arg(ap
, int);
298 unit
= va_arg(ap
, int);
299 part
= va_arg(ap
, int);
302 if (ctlr
>= NHPIB
|| hpibalive(ctlr
) == 0)
306 rs
= &rd_softc
[ctlr
][unit
];
310 if (rs
->sc_alive
== 0) {
311 if (rdinit(ctlr
, unit
) == 0)
313 if (rdgetinfo(rs
) == 0)
316 if (part
!= RAW_PART
&& /* always allow RAW_PART to be opened */
317 (part
>= rs
->sc_pinfo
.npart
|| rs
->sc_pinfo
.offset
[part
] == -1))
319 f
->f_devdata
= (void *)rs
;
324 rdclose(struct open_file
*f
)
326 struct rd_softc
*rs
= f
->f_devdata
;
329 * Mark the disk `not alive' so that the disklabel
330 * will be re-loaded at next open.
332 memset(rs
, 0, sizeof(struct rd_softc
));
339 rdstrategy(void *devdata
, int func
, daddr_t dblk
, size_t size
, void *v_buf
,
342 uint8_t *buf
= v_buf
;
343 struct rd_softc
*rs
= devdata
;
344 int ctlr
= rs
->sc_ctlr
;
345 int unit
= rs
->sc_unit
;
353 * Don't do partition translation on the `raw partition'.
355 blk
= (dblk
+ ((rs
->sc_part
== RAW_PART
) ? 0 :
356 rs
->sc_pinfo
.offset
[rs
->sc_part
]));
359 rd_ioc
.c_unit
= C_SUNIT(0);
360 rd_ioc
.c_volume
= C_SVOL(0);
361 rd_ioc
.c_saddr
= C_SADDR
;
363 rd_ioc
.c_addr
= RDBTOS(blk
);
364 rd_ioc
.c_nop2
= C_NOP
;
365 rd_ioc
.c_slen
= C_SLEN
;
367 rd_ioc
.c_cmd
= func
== F_READ
? C_READ
: C_WRITE
;
369 hpibsend(ctlr
, unit
, C_CMD
, (uint8_t *)&rd_ioc
.c_unit
,
371 hpibswait(ctlr
, unit
);
372 hpibgo(ctlr
, unit
, C_EXEC
, buf
, size
, func
);
373 hpibswait(ctlr
, unit
);
374 hpibrecv(ctlr
, unit
, C_QSTAT
, &stat
, 1);
376 if (rderror(ctlr
, unit
, rs
->sc_part
) == 0)
378 if (++rs
->sc_retry
> RDRETRY
)
388 rderror(int ctlr
, int unit
, int part
)
392 rd_rsc
.c_unit
= C_SUNIT(0);
393 rd_rsc
.c_sram
= C_SRAM
;
394 rd_rsc
.c_ram
= C_RAM
;
395 rd_rsc
.c_cmd
= C_STATUS
;
396 hpibsend(ctlr
, unit
, C_CMD
, (uint8_t *)&rd_rsc
, sizeof(rd_rsc
));
397 hpibrecv(ctlr
, unit
, C_EXEC
, (uint8_t *)&rd_stat
, sizeof(rd_stat
));
398 hpibrecv(ctlr
, unit
, C_QSTAT
, &stat
, 1);
400 printf("rd(%d,%d,0,%d): request status fail %d\n",
401 ctlr
, unit
, part
, stat
);
404 printf("rd(%d,%d,0,%d) err: vu 0x%x",
405 ctlr
, unit
, part
, rd_stat
.c_vu
);
406 if ((rd_stat
.c_aef
& AEF_UD
) || (rd_stat
.c_ief
& (IEF_MD
|IEF_RD
)))
407 printf(", block %ld", rd_stat
.c_blk
);
408 printf(", R0x%x F0x%x A0x%x I0x%x\n",
409 rd_stat
.c_ref
, rd_stat
.c_fef
, rd_stat
.c_aef
, rd_stat
.c_ief
);