fdcio.h revision 78856
1877Sache/*
276588Sjoerg * Copyright (C) 1992-1994,2001 by Joerg Wunsch, Dresden
31019Sache * All rights reserved.
4877Sache *
51019Sache * Redistribution and use in source and binary forms, with or without
61019Sache * modification, are permitted provided that the following conditions
71019Sache * are met:
81019Sache * 1. Redistributions of source code must retain the above copyright
91019Sache *    notice, this list of conditions and the following disclaimer.
101019Sache * 2. Redistributions in binary form must reproduce the above copyright
111019Sache *    notice, this list of conditions and the following disclaimer in the
121019Sache *    documentation and/or other materials provided with the distribution.
13877Sache *
142838Sdg * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY
152838Sdg * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
162838Sdg * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
172838Sdg * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE
182838Sdg * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
192838Sdg * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
202838Sdg * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
212838Sdg * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
222838Sdg * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
232838Sdg * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
242838Sdg * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
252838Sdg * DAMAGE.
261817Sdg *
2750477Speter * $FreeBSD: head/sys/sys/fdcio.h 78856 2001-06-26 22:16:30Z joerg $
28877Sache */
29877Sache
3018444Sbde#ifndef	_MACHINE_IOCTL_FD_H_
3118444Sbde#define	_MACHINE_IOCTL_FD_H_
32877Sache
3355205Speter#ifndef _KERNEL
34877Sache#include <sys/types.h>
3518444Sbde#endif
3618444Sbde#include <sys/ioccom.h>
37877Sache
38877Sache#define FD_FORMAT_VERSION 110	/* used to validate before formatting */
39877Sache#define FD_MAX_NSEC 36		/* highest known number of spt - allow for */
40877Sache				/* 2.88 MB drives */
41877Sache
42877Sachestruct fd_formb {
43877Sache	int format_version;	/* == FD_FORMAT_VERSION */
44877Sache	int cyl, head;
45877Sache	int transfer_rate;	/* fdreg.h: FDC_???KBPS */
46877Sache
47877Sache	union {
48877Sache		struct fd_form_data {
49877Sache			/*
50877Sache			 * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS
5113765Smpp			 * it is hardware-dependent since it exactly
52877Sache			 * matches the byte sequence to write to FDC
53877Sache			 * during its `format track' operation
54877Sache			 */
55877Sache			u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */
56877Sache			u_char nsecs;	/* must be <= FD_MAX_NSEC */
57877Sache			u_char gaplen;	/* GAP 3 length; usually 84 */
58877Sache			u_char fillbyte; /* usually 0xf6 */
59877Sache			struct fd_idfield_data {
60877Sache				/*
61877Sache				 * data to write into id fields;
62877Sache				 * for obscure formats, they mustn't match
63877Sache				 * the real values (but mostly do)
64877Sache				 */
65877Sache				u_char cylno;	/* 0 thru 79 (or 39) */
66877Sache				u_char headno;	/* 0, or 1 */
67877Sache				u_char secno;	/* starting at 1! */
68877Sache				u_char secsize;	/* usually 2 */
69877Sache			} idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */
70877Sache		} structured;
71877Sache		u_char raw[1];	/* to have continuous indexed access */
72877Sache	} format_info;
73877Sache};
74877Sache
75877Sache/* make life easier */
76877Sache# define fd_formb_secshift   format_info.structured.secshift
77877Sache# define fd_formb_nsecs      format_info.structured.nsecs
78877Sache# define fd_formb_gaplen     format_info.structured.gaplen
79877Sache# define fd_formb_fillbyte   format_info.structured.fillbyte
80877Sache/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */
81877Sache# define fd_formb_cylno(i)   format_info.structured.idfields[i].cylno
82877Sache# define fd_formb_headno(i)  format_info.structured.idfields[i].headno
83877Sache# define fd_formb_secno(i)   format_info.structured.idfields[i].secno
84877Sache# define fd_formb_secsize(i) format_info.structured.idfields[i].secsize
85877Sache
86877Sachestruct fd_type {
87877Sache	int	sectrac;		/* sectors per track         */
88877Sache	int	secsize;		/* size code for sectors     */
89877Sache	int	datalen;		/* data len when secsize = 0 */
90877Sache	int	gap;			/* gap len between sectors   */
91877Sache	int	tracks;			/* total num of tracks       */
92877Sache	int	size;			/* size of disk in sectors   */
93877Sache	int	steptrac;		/* steps per cylinder        */
94877Sache	int	trans;			/* transfer speed code       */
95877Sache	int	heads;			/* number of heads	     */
96891Sache	int     f_gap;                  /* format gap len            */
97891Sache	int     f_inter;                /* format interleave factor  */
98877Sache};
99877Sache
10076588Sjoergstruct fdc_status {
10176588Sjoerg	u_int	status[7];
10276588Sjoerg};
10376588Sjoerg
10478856Sjoerg/*
10578856Sjoerg * cyl and head are being passed into ioctl(FD_READID)
10678856Sjoerg * all four fields are being returned
10778856Sjoerg */
10878856Sjoergstruct fdc_readid {
10978856Sjoerg	u_char	cyl;		/* C - 0...79 */
11078856Sjoerg	u_char	head;		/* H - 0...1 */
11178856Sjoerg	u_char	sec;		/* R - 1...n */
11278856Sjoerg	u_char	secshift;	/* N - log2(secsize / 128) */
11378856Sjoerg};
11478856Sjoerg
115877Sache#define FD_FORM   _IOW('F', 61, struct fd_formb) /* format a track */
116877Sache#define FD_GTYPE  _IOR('F', 62, struct fd_type)  /* get drive type */
1172838Sdg#define FD_STYPE  _IOW('F', 63, struct fd_type)  /* set drive type */
118877Sache
1192838Sdg#define FD_GOPTS  _IOR('F', 64, int) /* drive options, see below */
1202838Sdg#define FD_SOPTS  _IOW('F', 65, int)
1212838Sdg
1224009Sjoerg#define FD_DEBUG  _IOW('F', 66, int)
1234009Sjoerg
12476588Sjoerg#define FD_CLRERR _IO('F', 67)	/* clear error counter */
1252838Sdg
12678856Sjoerg#define FD_READID _IOWR('F', 68, struct fdc_readid) /* read ID field */
12778856Sjoerg
1283095Sjoerg/*
12976588Sjoerg * Obtain NE765 status registers.  Only successful if there is
13076588Sjoerg * a valid status stored in fdc->status[].
13176588Sjoerg */
13276588Sjoerg#define FD_GSTAT  _IOR('F', 68, struct fdc_status)
13376588Sjoerg
13476588Sjoerg/* Options for FD_GOPTS/FD_SOPTS, cleared on device close */
13576588Sjoerg#define FDOPT_NORETRY 0x0001	/* no retries on failure */
13676588Sjoerg#define FDOPT_NOERRLOG 0x002	/* no "hard error" kernel log messages */
13776588Sjoerg#define FDOPT_NOERROR 0x0004	/* do not indicate errors, caller will use
13876588Sjoerg				   FD_GSTAT in order to obtain status */
13976588Sjoerg
14076588Sjoerg/*
1413095Sjoerg * The following definitions duplicate those in sys/i386/isa/fdreg.h
1423095Sjoerg * They are here since their values are to be used in the above
1433095Sjoerg * structure when formatting a floppy. For very obvious reasons, both
1443095Sjoerg * definitions must match ;-)
1453095Sjoerg */
1463095Sjoerg#ifndef FDC_500KBPS
1473095Sjoerg#define	FDC_500KBPS	0x00	/* 500KBPS MFM drive transfer rate */
1483095Sjoerg#define	FDC_300KBPS	0x01	/* 300KBPS MFM drive transfer rate */
1493095Sjoerg#define	FDC_250KBPS	0x02	/* 250KBPS MFM drive transfer rate */
1503095Sjoerg#define	FDC_125KBPS	0x03	/* 125KBPS FM drive transfer rate */
1513095Sjoerg				/* for some controllers 1MPBS instead */
1523095Sjoerg#endif /* FDC_500KBPS */
1533095Sjoerg
15418444Sbde#endif /* !_MACHINE_IOCTL_FD_H_ */
155