xref: /original-bsd/sys/tahoe/stand/vdformat/vdfmt.h (revision ab4ebc48)
1 /*	vdfmt.h	1.8	90/06/24	*/
2 
3 /*
4  * VERSAbus disk controller (vd) disk formatter.
5  */
6 #include <setjmp.h>
7 #include "tahoe/mtpr.h"
8 #include "param.h"
9 #include "buf.h"
10 #include "disklabel.h"
11 #include "time.h"
12 #include "vnode.h"
13 #include "ufs/inode.h"
14 #include "ufs/fs.h"
15 #include "tahoevba/vbaparam.h"
16 #include "tahoevba/vdreg.h"
17 
18 #include "tahoe/cp.h"
19 extern	struct cpdcb_i cpin;		/* found in cons.c */
20 
21 /*
22  * Poll console and return 1 if input is present.
23  */
24 #define	input() \
25     (uncache(&cpin.cp_hdr.cp_unit), (cpin.cp_hdr.cp_unit&CPDONE))
26 
27 /*
28  * Configuration parameters
29  */
30 #define	MAXCTLR		8		/* Maximum # of controllers */
31 #define	MAXDRIVE	16		/* Max drives per controller */
32 
33 #define NUMMAP		1		/* # Cyls in bad sector map */
34 #define	NUMMNT		1		/* # cyls for diagnostics */
35 #define	NUMREL		3		/* # Cyls in relocation area */
36 #define	NUMSYS	(NUMREL+NUMMNT+NUMMAP)	/* Total cyls used by system */
37 
38 #define	MAXTRKS		32
39 #define	MAXSECS_PER_TRK	72		/* at 512 bytes/sector */
40 #define	MAXERR		1000
41 #define	MAXTRKSIZ	((512/sizeof(long)) * MAXSECS_PER_TRK)
42 #define bytes_trk 	(lab->d_nsectors * lab->d_secsize)
43 
44 #define	HARD_ERROR \
45     (DCBS_NRDY|DCBS_IVA|DCBS_NEM|DCBS_DPE|DCBS_OAB|DCBS_WPT|DCBS_SKI|DCBS_OCYL)
46 #define DATA_ERROR \
47     (DCBS_UDE|DCBS_DCE|DCBS_DSE|DCBS_DSL|DCBS_TOP|DCBS_TOM|DCBS_CCD|\
48      DCBS_HARD|DCBS_SOFT)
49 #define HEADER_ERROR	(DCBS_HCRC|DCBS_HCE)
50 #define	NRM		(short)0
51 #define	BAD		(short)VDUF
52 #define WPT		(short)(NRM | VDWPT)
53 #define RELOC_SECTOR	(short)(VDALT)
54 #define	ALT_SECTOR	(short)(VDALT)
55 
56 typedef enum { false, true } boolean;
57 typedef enum { u_false, u_true, u_unknown } uncertain;
58 
59 /*
60  * Free bad block allocation bit map
61  */
62 typedef struct {
63 	enum { ALLOCATED, NOTALLOCATED } free_status;
64 } fmt_free;
65 
66 typedef enum { SINGLE_SECTOR, FULL_TRACK } rel_type;	/* relocation type */
67 
68 /*
69  * Error table format
70  */
71 typedef struct {
72 	dskadr	err_adr;
73 	long	err_stat;
74 } fmt_err;
75 
76 /* utilities */
77 int	to_sector();
78 int	to_track();
79 int	data_ok();
80 boolean	get_yes_no();
81 boolean	is_in_map();
82 boolean	is_formatted();
83 boolean	read_bad_sector_map();
84 dskadr	*from_sector();
85 dskadr	*from_track();
86 dskadr	*from_unix();
87 dskadr	is_relocated();
88 dskadr	*new_location();
89 
90 /*
91  * Operation table
92  */
93 typedef struct {
94 	int	(*routine)();
95 	char	*op_name;
96 	char	*op_action;
97 } op_tbl;
98 
99 #define	NUMOPS	7
100 op_tbl	operations[NUMOPS];
101 
102 /*
103  * Operation bit mask values (must match order in operations table)
104  */
105 #define	FORMAT_OP	0x01	/* Format operation bit */
106 #define	VERIFY_OP	0x02	/* Verify operation bit */
107 #define	RELOCATE_OP	0x04	/* Relocate operation bit */
108 #define	INFO_OP		0x08	/* Info operation bit */
109 #define	CORRECT_OP	0x10	/* Correct operation bit */
110 #define	PROFILE_OP	0x20	/* Profile operation bit */
111 #define	EXERCISE_OP	0x40	/* Exercise operation bit */
112 
113 extern	int format(), verify(), relocate(), info();
114 extern	int correct(), profile(), exercise();
115 
116 
117 /*
118  * Operation table type and definitions
119  */
120 typedef struct {
121 	int	op;
122 	int	numpat;
123 } op_spec;
124 op_spec	ops_to_do[MAXCTLR][MAXDRIVE];
125 
126 /*
127  * Contains all the current parameters
128  */
129 typedef enum {
130 	formatted,
131 	half_formatted,
132 	unformatted,
133 	unknown
134 } drv_stat;
135 typedef enum {
136 	fmt,
137 	vfy,
138 	rel,
139 	cor,
140 	inf,
141 	cmd,
142 	exec,
143 	prof,
144 	setup
145 } state;
146 typedef enum {
147 	sub_chk,
148 	sub_rcvr,
149 	sub_stat,
150 	sub_rel,
151 	sub_vfy,
152 	sub_fmt,
153 	sub_sk,
154 	sub_wmap
155 } substate;
156 
157 /*
158  * Different environments for setjumps
159  */
160 jmp_buf	reset_environ;	/* Use when reset is issued */
161 jmp_buf	quit_environ;	/* Use when you want to quit what your doing */
162 jmp_buf	abort_environ;	/* Use when nothing can be done to recover */
163 
164 /*
165  * Flaw map definitions and storage
166  */
167 typedef struct {
168 	short	bs_cyl;			/* Cylinder position of flaw */
169 	short	bs_trk;			/* Track position of flaw */
170 	long	bs_offset;		/* (byte) Position of flaw on track */
171 	long	bs_length;		/* Length (in bits) of flaw */
172 	dskadr	bs_alt;			/* Addr of alt sector (all 0 if none) */
173 	enum { flaw_map, scanning, operator } bs_how; /* How it was found */
174 } bs_entry ;
175 
176 struct {
177 	int		controller;
178 	int		drive;
179 	state		state;
180 	substate	substate;
181 	int		error;
182 	dskadr		daddr;
183 } cur;
184 
185 /*
186  * Controller specific information
187  */
188 typedef struct {
189 	uncertain	alive;
190 	struct	vddevice *addr;
191 	char		*name;
192 	int		type;
193 	fmt_err		*(*decode_pos)();
194 	bs_entry	*(*code_pos)();
195 } ctlr_info;
196 
197 ctlr_info	c_info[MAXCTLR];
198 ctlr_info	*C_INFO;
199 
200 /*
201  * Drive specific information
202  */
203 typedef struct {
204 	uncertain	alive;
205 	int		id;
206 	struct		disklabel label;
207 	drv_stat	condition;
208 } drive_info;
209 #define	d_traksize	d_drivedata[1]
210 #define	d_pat		d_drivedata[2]
211 
212 drive_info	d_info[MAXCTLR][MAXDRIVE];
213 drive_info	*D_INFO;
214 struct disklabel *lab;
215 
216 struct	disklabel vdproto[];
217 int	ndrives;
218 int	smddrives;
219 
220 /*
221  * Structure of the bad-sector map on the disk.
222  * The original bs_map did not have the magic number or "checksum,"
223  * thus the fudges below.
224  */
225 typedef struct {
226 	unsigned int	bs_magic;	/* magic (0x12344321) */
227 	unsigned int	bs_cksum;	/* checksum (0) */
228 	unsigned int	bs_id;		/* Pack id */
229 	unsigned int	bs_count;	/* number of known bad sectors */
230 	unsigned int	bs_max;		/* Maximum allowable bad sectors */
231 	bs_entry	list[1];
232 } bs_map;
233 
234 #define MAX_FLAWMAP(x)	(((x) - sizeof(bs_map)) / sizeof(bs_entry))
235 #define MAX_FLAWS	MAX_FLAWMAP(MAXTRKSIZ*sizeof(long))
236 #define BSMAGIC		0x12344321
237 
238 union {
239 	bs_map	Offset_bad_map;			/* offset by bs_magic+cksum */
240 #define offset_bad_map	bs_map_space.Offset_bad_map
241 	struct {
242 		unsigned int	bs_magic;
243 		unsigned int	bs_cksum;
244 		bs_map		bs_map;		/* aligned with track buffer */
245 	} Norm_bad_map;
246 #define norm_bad_map	bs_map_space.Norm_bad_map.bs_map
247 	struct {
248 		unsigned int	bs_magic;
249 		unsigned int	bs_cksum;
250 		long	track[MAXTRKSIZ];	/* disk track is read here */
251 	} space;
252 #define map_space	bs_map_space.space.track
253 } bs_map_space;
254 
255 bs_map	*bad_map;
256 
257 boolean	kill_processes;
258 int	num_controllers;
259 extern	int vdtimeout;
260 
261 /*
262  * Pattern buffers and the sort
263  */
264 fmt_free	free_tbl[NUMREL*MAXTRKS][MAXSECS_PER_TRK];
265 struct	mdcb	mdcb;		/* Master device control block */
266 struct	dcb	dcb;		/* Device control blocks */
267 
268 long	pattern_0[MAXTRKSIZ],  pattern_1[MAXTRKSIZ];
269 long	pattern_2[MAXTRKSIZ],  pattern_3[MAXTRKSIZ];
270 long	pattern_4[MAXTRKSIZ],  pattern_5[MAXTRKSIZ];
271 long	pattern_6[MAXTRKSIZ],  pattern_7[MAXTRKSIZ];
272 long	pattern_8[MAXTRKSIZ],  pattern_9[MAXTRKSIZ];
273 long	pattern_10[MAXTRKSIZ], pattern_11[MAXTRKSIZ];
274 long	pattern_12[MAXTRKSIZ], pattern_13[MAXTRKSIZ];
275 long	pattern_14[MAXTRKSIZ], pattern_15[MAXTRKSIZ];
276 
277 long	*pattern_address[16];	/* pointers to pattern_* */
278 
279 /*
280  * Double buffer for scanning existing
281  * file systems and general scratch
282  */
283 long	scratch[MAXTRKSIZ];
284 long	save[MAXTRKSIZ];
285 
286 /* XXX */
287 /*
288  * Flaw map stuff
289  */
290 typedef struct {
291 	long	flaw_sync;
292 	short	flaw_cyl;
293 	char	flaw_trk;
294 	char	flaw_sec;
295 	struct {
296 		short	flaw_offset;
297 		short	flaw_length;
298 	} flaw_pos[4];
299 	char	flaw_status;
300 	char	flaw_junk[1024]; /* Fill up 518 byte block */
301 } flaw;
302 
303 typedef struct {
304 	long		smde_sync;
305 	unsigned	adr_cyl  : 12;
306 	unsigned	adr_trk  : 8;
307 	unsigned	adr_sec  : 8;
308 	unsigned	sec_flgs : 4;
309 	unsigned	alt_cyl  : 12;
310 	unsigned	alt_trk  : 8;
311 	unsigned	alt_sec  : 8;
312 	char		smde_junk[1024];
313 } smde_hdr;
314 
315 /* for MAXTOR */
316 
317 typedef struct {
318 	unsigned long	esdi_flaw_sync;
319 	unsigned short	esdi_flaw_cyl;
320 	unsigned char	esdi_flaw_trk;
321 	unsigned char	esdi_flaw_sec;
322 	unsigned char	esdi_flags;
323 	unsigned char	esdi_ecc_1[2];
324 	unsigned char	esdi_pad_1[2];
325 	unsigned char	esdi_plo_sync[26];
326 } esdi_flaw_header;
327 
328 typedef struct {
329 	unsigned long	esdi_data_sync;
330 	unsigned char	esdi_month;
331 	unsigned char	esdi_day;
332 	unsigned char	esdi_year;
333 	unsigned char	esdi_head;
334 	unsigned char	esdi_pad_2[2];
335 	unsigned char	esdi_flaws[50][5];  /* see esdi_flaw_entry */
336 	unsigned char	esdi_ecc_2[2];
337 	unsigned char	esdi_pad_3[2];
338 	char		esdi_flaw_junk[1024]; /* Fill up block */
339 } esdi_flaw_data;
340 
341 
342 
343 typedef struct {
344 	esdi_flaw_header	esdi_header;
345 	esdi_flaw_data		esdi_data;
346 } esdi_flaw;
347 
348 
349 
350 /*
351 **  since each flaw entry is 5 bytes and this forces alignment problems we
352 ** define a structure here so that the entries can be BCOPYed into a
353 ** reasonable work area before access.
354 */
355 
356 typedef struct {
357 	unsigned short	esdi_flaw_cyl;
358 	unsigned short	esdi_flaw_offset;
359 	unsigned char	esdi_flaw_length;
360 } esdi_flaw_entry;
361 
362 #define	CDCSYNC		0x1919
363 #define	SMDSYNC		0x0019
364 #define	SMDESYNC	0x0009
365 #define	SMDE1SYNC	0x000d
366 #define	ESDISYNC	0x00fe
367 #define	ESDI1SYNC	0x00fe /* 0x00f8 */
368 
369 /* XXX */
370 
371 /*
372  * Flaw testing patterns.
373  */
374 struct	flawpat {
375 	u_int	fp_pat[16];
376 };
377