xref: /original-bsd/sys/hp300/stand/rd.c (revision 86c99e39)
1 /*
2  * Copyright (c) 1988 University of Utah.
3  * Copyright (c) 1982, 1990 The Regents of the University of California.
4  * All rights reserved.
5  *
6  * This code is derived from software contributed to Berkeley by
7  * the Systems Programming Group of the University of Utah Computer
8  * Science Department.
9  *
10  * %sccs.include.redist.c%
11  *
12  * from: Utah $Hdr: rd.c 1.20 92/12/21$
13  *
14  *	@(#)rd.c	7.7 (Berkeley) 12/26/92
15  */
16 
17 /*
18  * CS80/SS80 disk driver
19  */
20 #include <sys/param.h>
21 #include <sys/disklabel.h>
22 #include <stand/saio.h>
23 #include <hp300/stand/samachdep.h>
24 
25 #include <hp300/dev/rdreg.h>
26 
27 struct	rd_iocmd rd_ioc;
28 struct	rd_rscmd rd_rsc;
29 struct	rd_stat rd_stat;
30 struct	rd_ssmcmd rd_ssmc;
31 
32 struct	disklabel rdlabel;
33 
34 struct	rdminilabel {
35 	u_short	npart;
36 	u_long	offset[MAXPARTITIONS];
37 };
38 
39 struct	rd_softc {
40 	char	sc_retry;
41 	char	sc_alive;
42 	short	sc_type;
43 	struct	rdminilabel sc_pinfo;
44 } rd_softc[NHPIB][NRD];
45 
46 #define	RDRETRY		5
47 
48 struct	rdidentinfo {
49 	short	ri_hwid;
50 	short	ri_maxunum;
51 	int	ri_nblocks;
52 } rdidentinfo[] = {
53 	{ RD7946AID,	0,	 108416 },
54 	{ RD9134DID,	1,	  29088 },
55 	{ RD9134LID,	1,	   1232 },
56 	{ RD7912PID,	0,	 128128 },
57 	{ RD7914PID,	0,	 258048 },
58 	{ RD7958AID,	0,	 255276 },
59 	{ RD7957AID,	0,	 159544 },
60 	{ RD7933HID,	0,	 789958 },
61 	{ RD9134LID,	1,	  77840 },
62 	{ RD7936HID,	0,	 600978 },
63 	{ RD7937HID,	0,	1116102 },
64 	{ RD7914CTID,	0,	 258048 },
65 	{ RD7946AID,	0,	 108416 },
66 	{ RD9134LID,	1,	   1232 },
67 	{ RD7957BID,	0,	 159894 },
68 	{ RD7958BID,	0,	 297108 },
69 	{ RD7959BID,	0,	 594216 },
70 	{ RD2200AID,	0,	 654948 },
71 	{ RD2203AID,	0,	1309896 }
72 };
73 int numrdidentinfo = sizeof(rdidentinfo) / sizeof(rdidentinfo[0]);
74 
75 rdinit(ctlr, unit)
76 	int ctlr, unit;
77 {
78 	register struct rd_softc *rs = &rd_softc[ctlr][unit];
79 	u_char stat;
80 
81 	rs->sc_type = rdident(ctlr, unit);
82 	if (rs->sc_type < 0)
83 		return (0);
84 	rs->sc_alive = 1;
85 	return (1);
86 }
87 
88 rdreset(ctlr, unit)
89 	register int ctlr, unit;
90 {
91 	u_char stat;
92 
93 	rd_ssmc.c_unit = C_SUNIT(0);
94 	rd_ssmc.c_cmd = C_SSM;
95 	rd_ssmc.c_refm = REF_MASK;
96 	rd_ssmc.c_fefm = FEF_MASK;
97 	rd_ssmc.c_aefm = AEF_MASK;
98 	rd_ssmc.c_iefm = IEF_MASK;
99 	hpibsend(ctlr, unit, C_CMD, &rd_ssmc, sizeof(rd_ssmc));
100 	hpibswait(ctlr, unit);
101 	hpibrecv(ctlr, unit, C_QSTAT, &stat, 1);
102 }
103 
104 rdident(ctlr, unit)
105 	register int ctlr, unit;
106 {
107 	struct rd_describe desc;
108 	u_char stat, cmd[3];
109 	char name[7];
110 	register int id, i;
111 
112 	id = hpibid(ctlr, unit);
113 	if ((id & 0x200) == 0)
114 		return(-1);
115 	for (i = 0; i < numrdidentinfo; i++)
116 		if (id == rdidentinfo[i].ri_hwid)
117 			break;
118 	if (i == numrdidentinfo || unit > rdidentinfo[i].ri_maxunum)
119 		return(-1);
120 	id = i;
121 	rdreset(ctlr, unit);
122 	cmd[0] = C_SUNIT(0);
123 	cmd[1] = C_SVOL(0);
124 	cmd[2] = C_DESC;
125 	hpibsend(ctlr, unit, C_CMD, cmd, sizeof(cmd));
126 	hpibrecv(ctlr, unit, C_EXEC, &desc, 37);
127 	hpibrecv(ctlr, unit, C_QSTAT, &stat, sizeof(stat));
128 	bzero(name, sizeof(name));
129 	if (!stat) {
130 		register int n = desc.d_name;
131 		for (i = 5; i >= 0; i--) {
132 			name[i] = (n & 0xf) + '0';
133 			n >>= 4;
134 		}
135 	}
136 	/*
137 	 * Take care of a couple of anomolies:
138 	 * 1. 7945A and 7946A both return same HW id
139 	 * 2. 9122S and 9134D both return same HW id
140 	 * 3. 9122D and 9134L both return same HW id
141 	 */
142 	switch (rdidentinfo[id].ri_hwid) {
143 	case RD7946AID:
144 		if (bcmp(name, "079450", 6) == 0)
145 			id = RD7945A;
146 		else
147 			id = RD7946A;
148 		break;
149 
150 	case RD9134LID:
151 		if (bcmp(name, "091340", 6) == 0)
152 			id = RD9134L;
153 		else
154 			id = RD9122D;
155 		break;
156 
157 	case RD9134DID:
158 		if (bcmp(name, "091220", 6) == 0)
159 			id = RD9122S;
160 		else
161 			id = RD9134D;
162 		break;
163 	}
164 	return(id);
165 }
166 
167 #ifdef COMPAT_NOLABEL
168 int rdcyloff[][8] = {
169 	{ 1, 143, 0, 143, 0,   0,   323, 503, },	/* 7945A */
170 	{ 1, 167, 0, 0,   0,   0,   0,   0,   },	/* 9134D */
171 	{ 0, 0,   0, 0,   0,   0,   0,   0,   },	/* 9122S */
172 	{ 0, 71,  0, 221, 292, 542, 221, 0,   },	/* 7912P */
173 	{ 1, 72,  0, 72,  362, 802, 252, 362, },	/* 7914P */
174 	{ 1, 28,  0, 140, 167, 444, 140, 721, },	/* 7933H */
175 	{ 1, 200, 0, 200, 0,   0,   450, 600, },	/* 9134L */
176 	{ 1, 105, 0, 105, 380, 736, 265, 380, },	/* 7957A */
177 	{ 1, 65,  0, 65,  257, 657, 193, 257, },	/* 7958A */
178 	{ 1, 128, 0, 128, 518, 918, 388, 518, },	/* 7957B */
179 	{ 1, 44,  0, 44,  174, 496, 131, 174, },	/* 7958B */
180 	{ 1, 44,  0, 44,  218, 1022,174, 218, },	/* 7959B */
181 	{ 1, 37,  0, 37,  183, 857, 147, 183, },	/* 2200A */
182 	{ 1, 19,  0, 94,  112, 450, 94,  788, },	/* 2203A */
183 	{ 1, 20,  0, 98,  117, 256, 98,  397, },	/* 7936H */
184 	{ 1, 11,  0, 53,  63,  217, 53,  371, },	/* 7937H */
185 };
186 
187 struct rdcompatinfo {
188 	int	nbpc;
189 	int	*cyloff;
190 } rdcompatinfo[] = {
191 	NRD7945ABPT*NRD7945ATRK, rdcyloff[0],
192 	NRD9134DBPT*NRD9134DTRK, rdcyloff[1],
193 	NRD9122SBPT*NRD9122STRK, rdcyloff[2],
194 	NRD7912PBPT*NRD7912PTRK, rdcyloff[3],
195 	NRD7914PBPT*NRD7914PTRK, rdcyloff[4],
196 	NRD7958ABPT*NRD7958ATRK, rdcyloff[8],
197 	NRD7957ABPT*NRD7957ATRK, rdcyloff[7],
198 	NRD7933HBPT*NRD7933HTRK, rdcyloff[5],
199 	NRD9134LBPT*NRD9134LTRK, rdcyloff[6],
200 	NRD7936HBPT*NRD7936HTRK, rdcyloff[14],
201 	NRD7937HBPT*NRD7937HTRK, rdcyloff[15],
202 	NRD7914PBPT*NRD7914PTRK, rdcyloff[4],
203 	NRD7945ABPT*NRD7945ATRK, rdcyloff[0],
204 	NRD9122SBPT*NRD9122STRK, rdcyloff[2],
205 	NRD7957BBPT*NRD7957BTRK, rdcyloff[9],
206 	NRD7958BBPT*NRD7958BTRK, rdcyloff[10],
207 	NRD7959BBPT*NRD7959BTRK, rdcyloff[11],
208 	NRD2200ABPT*NRD2200ATRK, rdcyloff[12],
209 	NRD2203ABPT*NRD2203ATRK, rdcyloff[13],
210 };
211 int	nrdcompatinfo = sizeof(rdcompatinfo) / sizeof(rdcompatinfo[0]);
212 #endif
213 
214 rdgetinfo(io)
215 	register struct iob *io;
216 {
217 	struct rd_softc *rs = &rd_softc[io->i_adapt][io->i_ctlr];
218 	register struct rdminilabel *pi = &rs->sc_pinfo;
219 	register struct disklabel *lp = &rdlabel;
220 	char *msg, *readdisklabel();
221 	int rdstrategy(), i;
222 
223 	bzero((caddr_t)lp, sizeof *lp);
224 	lp->d_secsize = DEV_BSIZE;
225 	msg = readdisklabel(io, rdstrategy, lp);
226 	if (msg) {
227 		printf("rd(%d,%d,%d,%d): WARNING: %s, ",
228 		       io->i_adapt, io->i_ctlr, io->i_unit, io->i_part, msg);
229 #ifdef COMPAT_NOLABEL
230 		{
231 			register struct rdcompatinfo *ci;
232 
233 			printf("using old default partitioning\n");
234 			ci = &rdcompatinfo[rs->sc_type];
235 			pi->npart = 8;
236 			for (i = 0; i < pi->npart; i++)
237 				pi->offset[i] = ci->cyloff[i] * ci->nbpc;
238 		}
239 #else
240 		printf("defining `c' partition as entire disk\n");
241 		pi->npart = 3;
242 		pi->offset[0] = pi->offset[1] = -1;
243 		pi->offset[2] = 0;
244 #endif
245 	} else {
246 		pi->npart = lp->d_npartitions;
247 		for (i = 0; i < pi->npart; i++)
248 			pi->offset[i] = lp->d_partitions[i].p_size == 0 ?
249 				-1 : lp->d_partitions[i].p_offset;
250 	}
251 	return(1);
252 }
253 
254 rdopen(io)
255 	struct iob *io;
256 {
257 	register struct rd_softc *rs;
258 	struct rdinfo *ri;
259 	int unit, ctlr, part;
260 
261 	devconvert(io);
262 
263 	ctlr = io->i_adapt;
264 	if (ctlr >= NHPIB || hpibalive(ctlr) == 0)
265 		return (EADAPT);
266 	unit = io->i_ctlr;
267 	if (unit >= NRD)
268 		return (ECTLR);
269 	rs = &rd_softc[ctlr][unit];
270 	if (rs->sc_alive == 0) {
271 		if (rdinit(ctlr, unit) == 0)
272 			return (ENXIO);
273 		if (rdgetinfo(io) == 0)
274 			return (ERDLAB);
275 	}
276 	part = io->i_part;
277 	if (part >= rs->sc_pinfo.npart || rs->sc_pinfo.offset[part] == -1)
278 		return (EPART);
279 	io->i_boff = rs->sc_pinfo.offset[part];
280 	return (0);
281 }
282 
283 rdstrategy(io, func)
284 	register struct iob *io;
285 	int func;
286 {
287 	register int ctlr = io->i_adapt;
288 	register int unit = io->i_ctlr;
289 	register struct rd_softc *rs = &rd_softc[ctlr][unit];
290 	char stat;
291 
292 	if (io->i_cc == 0)
293 		return(0);
294 
295 	rs->sc_retry = 0;
296 	rd_ioc.c_unit = C_SUNIT(0);
297 	rd_ioc.c_volume = C_SVOL(0);
298 	rd_ioc.c_saddr = C_SADDR;
299 	rd_ioc.c_hiaddr = 0;
300 	rd_ioc.c_addr = RDBTOS(io->i_bn);
301 	rd_ioc.c_nop2 = C_NOP;
302 	rd_ioc.c_slen = C_SLEN;
303 	rd_ioc.c_len = io->i_cc;
304 	rd_ioc.c_cmd = func == F_READ ? C_READ : C_WRITE;
305 retry:
306 	hpibsend(ctlr, unit, C_CMD, &rd_ioc.c_unit, sizeof(rd_ioc)-2);
307 	hpibswait(ctlr, unit);
308 	hpibgo(ctlr, unit, C_EXEC, io->i_ma, io->i_cc, func);
309 	hpibswait(ctlr, unit);
310 	hpibrecv(ctlr, unit, C_QSTAT, &stat, 1);
311 	if (stat) {
312 		if (rderror(ctlr, unit, io->i_part) == 0)
313 			return(-1);
314 		if (++rs->sc_retry > RDRETRY)
315 			return(-1);
316 		goto retry;
317 	}
318 	return(io->i_cc);
319 }
320 
321 rderror(ctlr, unit, part)
322 	register int ctlr, unit;
323 	int part;
324 {
325 	register struct rd_softc *rd = &rd_softc[ctlr][unit];
326 	char stat;
327 
328 	rd_rsc.c_unit = C_SUNIT(0);
329 	rd_rsc.c_sram = C_SRAM;
330 	rd_rsc.c_ram = C_RAM;
331 	rd_rsc.c_cmd = C_STATUS;
332 	hpibsend(ctlr, unit, C_CMD, &rd_rsc, sizeof(rd_rsc));
333 	hpibrecv(ctlr, unit, C_EXEC, &rd_stat, sizeof(rd_stat));
334 	hpibrecv(ctlr, unit, C_QSTAT, &stat, 1);
335 	if (stat) {
336 		printf("rd(%d,%d,0,%d): request status fail %d\n",
337 		       ctlr, unit, part, stat);
338 		return(0);
339 	}
340 	printf("rd(%d,%d,0,%d) err: vu 0x%x",
341 	       ctlr, unit, part, rd_stat.c_vu);
342 	if ((rd_stat.c_aef & AEF_UD) || (rd_stat.c_ief & (IEF_MD|IEF_RD)))
343 		printf(", block %d", rd_stat.c_blk);
344 	printf(", R0x%x F0x%x A0x%x I0x%x\n",
345 	       rd_stat.c_ref, rd_stat.c_fef, rd_stat.c_aef, rd_stat.c_ief);
346 	return(1);
347 }
348