xref: /titanic_50/usr/src/uts/common/sys/fdc.h (revision d2ec54f7875f7e05edd56195adbeb593c947763f)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #ifndef	_SYS_FDC_H
28 #define	_SYS_FDC_H
29 
30 #pragma ident	"%Z%%M%	%I%	%E% SMI"
31 
32 #ifdef	__cplusplus
33 extern "C" {
34 #endif
35 
36 #ifndef	OTYPCNT
37 #define	OTYPCNT	5
38 #endif
39 
40 typedef struct xlate_tbl {
41 	int	value;
42 	uchar_t	code;
43 } xlate_tbl_t;
44 
45 /*
46  * the floppy disk minor device number is interpreted as follows:
47  *
48  *	 7 6 5 4 3 2 1 0
49  * 	+---------+-----+
50  * 	|  drive  | part|
51  * 	+---------+-----+
52  * where:
53  *		drive = instance
54  *		part = partition
55  */
56 /*
57  * Macros for partition/drive from floppy device number,
58  * plus other manifest defines....
59  */
60 
61 #define	PARTITION(x)	(getminor(x) & 7)
62 #define	DRIVE(x)	(getminor(x) >> 3)
63 #define	FDUNIT(x)	((x) & 3)	/* unit on controller */
64 #define	FDCTLR(x)	((x) >> 2)	/* controller instance */
65 #define	NFDUN	4
66 
67 
68 /*
69  * Floppy drive / diskette type numbers.
70  */
71 #define	FMT_5H	  0
72 #define	FMT_5Q	  1
73 #define	FMT_5D9	  2
74 #define	FMT_5D8	  3
75 #define	FMT_5D4	  4
76 #define	FMT_5D16  5
77 #define	FMT_3E	  6
78 #define	FMT_3H	  7
79 #define	FMT_3I	  8
80 #define	FMT_3M	  9
81 #define	FMT_3D	  10
82 #define	FMT_AUTO  11
83 #define	FMT_MAX	  11
84 #define	FMT_UNKWN 11
85 
86 
87 /*
88  * Mini- and Micro- Diskettes Attributes Structure
89  */
90 struct fdattr {
91 	ushort_t fda_rotatespd;		/* rotational speed */
92 	ushort_t fda_intrlv;		/* interleave factor */
93 
94 	uchar_t fda_gapl;		/* gap 3 length */
95 	uchar_t fda_gapf;		/* gap 3 length for format */
96 };
97 
98 /*
99  * Miscellaneous
100  */
101 #define	FDWRITE	0			/* for fdrw() flag */
102 #define	FDREAD	1			/* for fdrw() flag */
103 #define	FDRDONE	86			/*  . read with no retries */
104 
105 /*
106  * Per floppy-drive / diskette state structure
107  */
108 
109 struct fdisk {
110 	struct fcu_obj	*d_obj;
111 	int		d_media;	/* drive media capacities */
112 	struct kstat 	*d_iostat;	/* pointer to iostat statistics */
113 	int		d_bpsshf;	/* shift count for bytes to sector */
114 
115 	ksema_t		d_ocsem;	/* sem for serializing opens/closes */
116 
117 	struct buf	*d_actf;	/* head of wait list */
118 	struct buf	*d_actl;	/* tail of wait list */
119 	struct buf	*d_current;	/* currently active buf */
120 	struct partition d_part[NDKMAP];	/* partitions descriptions */
121 
122 	/*
123 	 * Regular open type flags.
124 	 * Open types BLK, MNT, CHR, SWP assumed to be values 0-3.
125 	 */
126 	ulong_t	d_regopen[OTYPCNT - 1];
127 	ulong_t	d_lyropen[NDKMAP];	/* Layered open counters */
128 
129 	/*
130 	 * Exclusive open flags (per partition).
131 	 *
132 	 * The rules are that in order to open a partition exclusively,
133 	 * the partition must be completely closed already. Once any
134 	 * partition of the device is opened exclusively, no other open
135 	 * on that partition may succeed until the partition is closed.
136 	 */
137 	ulong_t		d_exclmask;	/* set to indicate exclusive open */
138 
139 	/*
140 	 * Current drive characteristics type.
141 	 * If -1, then it was set via an ioctl.  Note that a close
142 	 * and then an open loses the ioctl set characteristics.
143 	 */
144 	signed char	d_curfdtype;
145 	uchar_t		d_deffdtype;
146 
147 	uchar_t		d_bsec;		/* encoded bytes_per_sector */
148 	uchar_t		d_drate;	/* encoded data_rate */
149 	uchar_t		d_motor;	/* motor-on bit */
150 
151 	uchar_t		d_hutsrt;	/* encoded head unload & step_rate */
152 	uchar_t		d_hlt;		/* encoded head load time */
153 	uchar_t		d_dtl;		/* dtl code */
154 
155 	int	d_media_timeout;	/* media detection timeout */
156 	timeout_id_t	d_media_timeout_id; /* media detection timeout id */
157 	enum dkio_state d_media_state;	/* up-to-date media state */
158 	int		d_ejected;
159 	kcondvar_t	d_statecv;	/* condition var for media state */
160 
161 	ulong_t		d_vtoc_bootinfo[3];	/* from label */
162 	ulong_t		d_vtoc_version;
163 	time_t		d_vtoc_timestamp[NDKMAP];
164 	char		d_vtoc_volume[LEN_DKL_VVOL];
165 	char		d_vtoc_asciilabel[LEN_DKL_ASCII];
166 };
167 
168 
169 /* a place to keep some statistics on what's going on */
170 struct fdstat {
171 	/* first operations */
172 	int rd;		/* count reads */
173 	int wr;		/* count writes */
174 	int recal;	/* count recalibrates */
175 	int form;	/* count format_tracks */
176 	int other;	/* count other ops */
177 
178 	/* then errors */
179 	int reset;	/* count resets */
180 	int to;		/* count timeouts */
181 	int run;	/* count overrun/underrun */
182 	int de;		/* count data errors */
183 	int bfmt;	/* count bad format errors */
184 };
185 
186 /*
187  * floppy disk command and status block.
188  *
189  * Needed to execute a command. Since the floppy chip is
190  * single threaded with respect to having only one drive
191  * active at a time, this block of information is only
192  * valid for the length of a command and gets rewritten
193  * for each command.
194  */
195 
196 enum fxstate {
197 	FXS_START,
198 	FXS_MTRON,
199 	FXS_RCAL,
200 	FXS_DKCHGX,
201 	FXS_RESTART,
202 	FXS_RESEEK,
203 	FXS_SEEK,
204 	FXS_HDST,
205 	FXS_RDID,
206 	FXS_DOIT,
207 	FXS_DOWT,
208 	FXS_KILL,
209 	FXS_RESET,
210 	FXS_END
211 };
212 
213 enum fmtrstate {
214 	FMS_OFF,
215 	FMS_START,
216 	FMS_KILLST,
217 	FMS_ON,
218 	FMS_DELAY,
219 	FMS_IDLE
220 };
221 
222 enum fmtrinput {
223 	FMI_TIMER,
224 	FMI_STARTCMD,
225 	FMI_RSTARTCMD,
226 	FMI_DELAYCMD,
227 	FMI_IDLECMD
228 };
229 
230 struct fdcsb {
231 	struct buf *csb_bufp;	/* associated buf */
232 	ddi_dma_handle_t csb_dmahandle;
233 	int csb_handle_bound;		/* DMA handle has been bound */
234 	uint_t csb_dmacookiecnt;	/* number of DMA cookies */
235 	uint_t csb_dmacurrcookie;	/* current cookie number */
236 	uint_t csb_dmawincnt;		/* number of DMA windows */
237 	uint_t csb_dmacurrwin;		/* current DMA window */
238 	ddi_dma_cookie_t csb_dmacookie;
239 	enum fxstate csb_xstate;	/* Current execution state */
240 	enum fxstate csb_oldxs;	/* old execution state */
241 	uchar_t	csb_npcyl;	/* new physical cylinder number */
242 	uchar_t	csb_drive;	/* floppy unit number */
243 	uchar_t	csb_ncmds;	/* how many command bytes to send */
244 	uchar_t	csb_nrslts;	/* number of result bytes gotten */
245 	uchar_t	csb_opflags;	/* opflags, see below */
246 	uchar_t	csb_timer;	/* op timer, in 0.1 sec */
247 	uchar_t	csb_maxretry;	/* maximum retries this operation */
248 	uchar_t	csb_retrys;	/* how may retrys done so far */
249 	uchar_t	csb_ourtrys;	/* how may over/underrun retrys done so far */
250 	uchar_t	csb_status;	/* status returned from hwintr */
251 	uchar_t	csb_cmdstat;	/* if 0 then success, else failure */
252 	uchar_t	csb_cmd[10];	/* command to send to chip */
253 	uchar_t	csb_rslt[10];	/* results from chip */
254 };
255 
256 /*
257  * defines for csb_opflags
258  */
259 #define	CSB_OFINRPT	0x01		/* generates an interrupt */
260 #define	CSB_OFDMARD	0x02		/* uses DMA for reading */
261 #define	CSB_OFDMAWT	0x04		/* uses DMA for writing */
262 #define	CSB_OFRESLT	0x08		/* generates results */
263 #define	CSB_OFRAWIOCTL	0x10		/* raw i/o control */
264 
265 #define	CSB_CMDTO   0x01
266 #define	CSB_CMDDMA  0x03
267 #define	CSB_CMDNGNR 0x07
268 
269 
270 /*
271  * 82077AA Controller modes
272  */
273 enum fdcmode077 {
274 	FDCMODE_AT,
275 	FDCMODE_PS2,	/* not supported */
276 	FDCMODE_30
277 };
278 
279 /*
280  * Per controller data
281  */
282 
283 struct fdcntlr {
284 	kmutex_t	c_lock;		/* controller mutex */
285 	kmutex_t	c_dorlock;	/* digital_output_register mutex */
286 	kcondvar_t	c_iocv;		/* condition var for I/O done */
287 	ksema_t		c_selsem;	/* sem for select unit */
288 
289 	dev_info_t	*c_dip;
290 	int		c_number;	/* logical controller number */
291 	int		c_regbase;	/* base i/o address */
292 	int		c_dmachan;	/* DMA channel number */
293 	int		c_intprio;	/* interrupt priority */
294 	int		c_intvec;	/* interrupt vector num */
295 	int		c_chip;
296 	enum fdcmode077	c_mode;		/* 82077 controller mode */
297 
298 	ulong_t		c_flags;	/* state information */
299 	struct kstat	*c_intrstat;	/* interrupt stats pointer */
300 	struct	fdstat	fdstats;	/* statistics */
301 
302 	ddi_iblock_cookie_t c_iblock;	/* returned from ddi_add_intr */
303 	ddi_idevice_cookie_t c_idevice;	/* returned from ddi_add_intr */
304 
305 	int		c_curunit;	/* current/last selected unit */
306 	timeout_id_t	c_timeid;	/* watchdog timer id */
307 
308 	struct	fcu_obj	*c_unit[NFDUN];	/* slave on controller */
309 	timeout_id_t	c_motort[NFDUN]; /* motor timer id */
310 	enum fmtrstate	c_mtrstate[NFDUN];
311 	int		c_curpcyl[NFDUN]; /* current physical cylinder */
312 	signed char	c_sekdir[NFDUN]; /* direction of last seek */
313 
314 	struct	fdcsb	c_csb;		/* current csb */
315 
316 	/*
317 	 * floppy controller register values
318 	 */
319 	uchar_t		c_digout;
320 	uchar_t		c_drate;	/* only 82072 and 82077AA controllers */
321 	uchar_t		c_config;	/* DSR on PC/AT with 8272A */
322 	uchar_t		c_mstat;
323 	uchar_t		c_data;
324 	uchar_t		c_digin;
325 
326 	uchar_t		c_bsec;		/* encoded bytes_per_sector */
327 	uchar_t		c_hutsrt;	/* encoded head unload & step_rate */
328 	uchar_t		c_hlt;		/* encoded head load time */
329 };
330 
331 /*
332  * Controller flags
333  */
334 #define	FCFLG_BUSY	0x01	/* operation in progress */
335 #define	FCFLG_WANT	0x02	/* csb structure wanted */
336 #define	FCFLG_WAITMR	0x10	/* waiting for motor to start I/O */
337 #define	FCFLG_WAITING	0x20	/* waiting on I/O completion */
338 #define	FCFLG_TIMEOUT	0x80	/* the current operation just timed out */
339 #define	FCFLG_DSOUT	0x100	/* DENSEL ouput is in use for speed ctl */
340 #define	FCFLG_3DMODE	0x800	/* ctlr is 3D Mode capable */
341 
342 
343 /*
344  * FDC operations
345  */
346 
347 struct fcobjops {
348 	int	(*fco_start)();		/* controller start */
349 	int	(*fco_abort)();		/* controller abort */
350 	int	(*fco_getcap)();	/* capability retrieval */
351 	int	(*fco_setcap)();	/* capability establishment */
352 	int	(*fco_dkinfo)();	/* get disk controller info */
353 
354 	int	(*fco_select)();	/* select / deselect unit */
355 	int	(*fco_getchng)();	/* get media change */
356 	int	(*fco_resetchng)();	/* reset media change */
357 	int	(*fco_rcseek)();	/* recal / seek */
358 	int	(*fco_rwbuf)();		/* read /write request */
359 	int	(*fco_rw)();		/* read /write sector */
360 	int	(*fco_format)();	/* format track */
361 	int	(*fco_rwioctl)();	/* raw ioctl */
362 };
363 
364 /*
365  * FDC unit object
366  */
367 
368 struct fcu_obj {
369 	ulong_t		fj_flags;	/* state information */
370 	kmutex_t 	fj_lock;	/* unit mutex */
371 	caddr_t		fj_data;
372 	struct fd_drive *fj_drive;	/* pointer to drive characteristics */
373 	struct fd_char	*fj_chars;	/* ptr to diskette characteristics */
374 	struct fdattr	*fj_attr;	/* additional diskette attributes */
375 	dev_info_t	*fj_dip;
376 	ushort_t	fj_rotspd;	/* rotational speed */
377 	ulong_t		fj_unit;
378 	struct fcobjops *fj_ops;
379 	struct fdcntlr	*fj_fdc;
380 	ddi_iblock_cookie_t *fj_iblock;
381 };
382 
383 /* unit flags (state info) */
384 #define	FUNIT_DRVATCH		0x001	/* this is drive present */
385 #define	FUNIT_WPROT		0x004	/* diskette is read only */
386 #define	FUNIT_CHAROK		0x010	/* characteristics are known */
387 #define	FUNIT_LABELOK		0x020	/* label was read from disk */
388 #define	FUNIT_UNLABELED		0x040	/* no label using default */
389 #define	FUNIT_CHANGED		0x100	/* diskette was changed after open */
390 #define	FUNIT_CHGDET		0x200	/* diskette removal was detected */
391 #define	FUNIT_3DMODE		0x4000	/* unit is in fast speed mode */
392 #define	FUNIT_BUSY		0x8000	/* unit is busy */
393 
394 #ifdef _VPIX
395 #define	DRV_NONE	0x00
396 #define	DRV_DBL		0x01
397 #define	DRV_QUAD	0x02
398 #define	DRV_720		0x04	/* LOW_35 gets changed to this for or'ing */
399 #define	DRV_144		0x08	/* HI35 gets changed to this for or'ing */
400 
401 /* ioctl numbers used by VPIX */
402 #define	FIOC		('F'<<8)
403 #define	F_DTYP		(FIOC|60)	/* returns fd_drvtype */
404 #define	F_FCR		(FIOC|61)	/* output to Floppy Control Register */
405 #define	F_DOR		(FIOC|62)	/* output to Digital Output Register */
406 #define	F_RAW		(FIOC|63)	/* general raw controller interface */
407 #endif
408 
409 #ifdef	__cplusplus
410 }
411 #endif
412 
413 #endif	/* !_SYS_FDC_H */
414