fdcio.h revision 274024
1139823Simp/*-
2241610Sglebius * Copyright (C) 1992-1994,2001 by Joerg Wunsch, Dresden
3130933Sbrooks * All rights reserved.
4130933Sbrooks *
5130933Sbrooks * Redistribution and use in source and binary forms, with or without
6130933Sbrooks * modification, are permitted provided that the following conditions
7130933Sbrooks * are met:
8130933Sbrooks * 1. Redistributions of source code must retain the above copyright
9130933Sbrooks *    notice, this list of conditions and the following disclaimer.
10130933Sbrooks * 2. Redistributions in binary form must reproduce the above copyright
11130933Sbrooks *    notice, this list of conditions and the following disclaimer in the
12130933Sbrooks *    documentation and/or other materials provided with the distribution.
13130933Sbrooks *
14130933Sbrooks * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY
15130933Sbrooks * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16130933Sbrooks * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17130933Sbrooks * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE
18130933Sbrooks * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19130933Sbrooks * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20130933Sbrooks * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21130933Sbrooks * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22130933Sbrooks * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23130933Sbrooks * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
24130933Sbrooks * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25130933Sbrooks * DAMAGE.
26130933Sbrooks *
27130933Sbrooks * $FreeBSD: stable/10/sys/sys/fdcio.h 274024 2014-11-03 10:26:29Z nyan $
28130933Sbrooks */
29130933Sbrooks
30130933Sbrooks#ifndef	_MACHINE_IOCTL_FD_H_
31130933Sbrooks#define	_MACHINE_IOCTL_FD_H_
32130933Sbrooks
33130933Sbrooks#ifndef _KERNEL
34130933Sbrooks#include <sys/types.h>
35130933Sbrooks#endif
36152779Sru#include <sys/ioccom.h>
37130933Sbrooks
38130933Sbrooks#define FD_FORMAT_VERSION 110	/* used to validate before formatting */
39130933Sbrooks#define FD_MAX_NSEC 36		/* highest known number of spt - allow for */
40130933Sbrooks				/* 2.88 MB drives */
41130933Sbrooks
42130933Sbrooksstruct fd_formb {
43130933Sbrooks	int format_version;	/* == FD_FORMAT_VERSION */
44130933Sbrooks	int cyl, head;
45130933Sbrooks	int transfer_rate;	/* FDC_???KBPS */
46130933Sbrooks
47130933Sbrooks	struct fd_form_data {
48130933Sbrooks		/*
49191816Szec		 * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS
50130933Sbrooks		 * it is hardware-dependent since it exactly
51241610Sglebius		 * matches the byte sequence to write to FDC
52241610Sglebius		 * during its `format track' operation
53241610Sglebius		 */
54241610Sglebius		u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */
55241610Sglebius		u_char nsecs;	/* must be <= FD_MAX_NSEC */
56241610Sglebius		u_char gaplen;	/* GAP 3 length; usually 84 */
57241610Sglebius		u_char fillbyte; /* usually 0xf6 */
58241610Sglebius		struct fd_idfield_data {
59241610Sglebius			/*
60241610Sglebius			 * data to write into id fields;
61241610Sglebius			 * for obscure formats, they mustn't match
62241610Sglebius			 * the real values (but mostly do)
63241610Sglebius			 */
64241610Sglebius			u_char cylno;	/* 0 thru 79 (or 39) */
65241610Sglebius			u_char headno;	/* 0, or 1 */
66241610Sglebius			u_char secno;	/* starting at 1! */
67241610Sglebius			u_char secsize;	/* usually 2 */
68241610Sglebius		} idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */
69241610Sglebius	} format_info;
70241610Sglebius};
71241610Sglebius
72241610Sglebius/* make life easier */
73241610Sglebius# define fd_formb_secshift   format_info.secshift
74241610Sglebius# define fd_formb_nsecs      format_info.nsecs
75241610Sglebius# define fd_formb_gaplen     format_info.gaplen
76241610Sglebius# define fd_formb_fillbyte   format_info.fillbyte
77241610Sglebius/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */
78241610Sglebius# define fd_formb_cylno(i)   format_info.idfields[i].cylno
79241610Sglebius# define fd_formb_headno(i)  format_info.idfields[i].headno
80241610Sglebius# define fd_formb_secno(i)   format_info.idfields[i].secno
81241610Sglebius# define fd_formb_secsize(i) format_info.idfields[i].secsize
82241610Sglebius
83241610Sglebiusstruct fd_type {
84241610Sglebius	int	sectrac;		/* sectors per track         */
85241610Sglebius	int	secsize;		/* size code for sectors     */
86241610Sglebius	int	datalen;		/* data len when secsize = 0 */
87241610Sglebius	int	gap;			/* gap len between sectors   */
88241610Sglebius	int	tracks;			/* total number of cylinders */
89241610Sglebius	int	size;			/* size of disk in sectors   */
90241610Sglebius	int	trans;			/* transfer speed code       */
91241610Sglebius	int	heads;			/* number of heads	     */
92241610Sglebius	int     f_gap;                  /* format gap len            */
93241610Sglebius	int     f_inter;                /* format interleave factor  */
94241610Sglebius	int	offset_side2;		/* offset of sectors on side2 */
95241610Sglebius	int	flags;			/* misc. features */
96241610Sglebius#define FL_MFM		0x0001		/* MFM recording */
97152209Sthompsa#define FL_2STEP	0x0002		/* 2 steps between cylinders */
98160195Ssam#define FL_PERPND	0x0004		/* perpendicular recording */
99160195Ssam#define FL_AUTO		0x0008		/* autodetect format */
100130933Sbrooks};
101241610Sglebius
102241610Sglebiusstruct fdc_status {
103241610Sglebius	u_int	status[7];
104241610Sglebius};
105130933Sbrooks
106215701Sdim/*
107195699Srwatson * cyl and head are being passed into ioctl(FD_READID)
108130933Sbrooks * all four fields are being returned
109195727Srwatson */
110195727Srwatsonstruct fdc_readid {
111195699Srwatson	u_char	cyl;		/* C - 0...79 */
112130933Sbrooks	u_char	head;		/* H - 0...1 */
113130933Sbrooks	u_char	sec;		/* R - 1...n */
114130933Sbrooks	u_char	secshift;	/* N - log2(secsize / 128) */
115130933Sbrooks};
116130933Sbrooks
117130933Sbrooks/*
118130933Sbrooks * Diskette drive type, basically the same as stored in RTC on ISA
119130933Sbrooks * machines (see /sys/isa/rtc.h), but right-shifted by four bits.
120130933Sbrooks */
121130933Sbrooksenum fd_drivetype {
122130933Sbrooks	FDT_NONE, FDT_360K, FDT_12M, FDT_720K, FDT_144M, FDT_288M_1,
123130933Sbrooks	FDT_288M
124130933Sbrooks};
125130933Sbrooks
126130933Sbrooks
127130933Sbrooks#define FD_FORM   _IOW('F', 61, struct fd_formb) /* format a track */
128130933Sbrooks#define FD_GTYPE  _IOR('F', 62, struct fd_type)  /* get drive type */
129130933Sbrooks#define FD_STYPE  _IOW('F', 63, struct fd_type)  /* set drive type */
130130933Sbrooks
131130933Sbrooks#define FD_GOPTS  _IOR('F', 64, int) /* drive options, see below */
132130933Sbrooks#define FD_SOPTS  _IOW('F', 65, int)
133130933Sbrooks
134130933Sbrooks#ifdef PC98
135130933Sbrooks#define FD_DEBUG  _IOW('F', 66, int)
136130933Sbrooks#endif
137130933Sbrooks
138130933Sbrooks#define FD_CLRERR _IO('F', 67)	/* clear error counter */
139130933Sbrooks
140130933Sbrooks#define FD_READID _IOWR('F', 68, struct fdc_readid) /* read ID field */
141130933Sbrooks
142130933Sbrooks/*
143130933Sbrooks * Obtain NE765 status registers.  Only successful if there is
144130933Sbrooks * a valid status stored in fdc->status[].
145130933Sbrooks */
146130933Sbrooks#define FD_GSTAT  _IOR('F', 69, struct fdc_status)
147130933Sbrooks
148130933Sbrooks#define FD_GDTYPE _IOR('F', 70, enum fd_drivetype) /* obtain drive type */
149130933Sbrooks
150130933Sbrooks/* Options for FD_GOPTS/FD_SOPTS, cleared on device close */
151132470Smlaier#define FDOPT_NORETRY 0x0001	/* no retries on failure */
152132470Smlaier#define FDOPT_NOERRLOG 0x002	/* no "hard error" kernel log messages */
153132470Smlaier#define FDOPT_NOERROR 0x0004	/* do not indicate errors, caller will use
154130933Sbrooks				   FD_GSTAT in order to obtain status */
155130933Sbrooks#ifdef PC98
156130933Sbrooks#define FDOPT_AUTOSEL 0x8000	/* read/only option: device performs media
157152209Sthompsa				 * autoselection */
158152209Sthompsa#endif
159152209Sthompsa
160152209Sthompsa/*
161152209Sthompsa * Transfer rate definitions.  Used in the structures above.  They
162141616Sphk * represent the hardware encoding of bits 0 and 1 of the FDC control
163130933Sbrooks * register when writing to the register.
164195837Srwatson * Transfer rates for FM encoding are half the values listed here
165195837Srwatson * (but we currently don't support FM encoding).
166192669Szec */
167192669Szec#define	FDC_500KBPS	0x00	/* 500KBPS MFM drive transfer rate */
168192669Szec#define	FDC_300KBPS	0x01	/* 300KBPS MFM drive transfer rate */
169192669Szec#define	FDC_250KBPS	0x02	/* 250KBPS MFM drive transfer rate */
170192669Szec#define	FDC_1MBPS	0x03	/* 1MPBS MFM drive transfer rate */
171130933Sbrooks
172130933Sbrooks/*
173130933Sbrooks * Parameters for common formats
174192669Szec *
175130933Sbrooks * See struct fd_type for layout.
176130933Sbrooks * XXX: Field 'size' must be calculated.
177130933Sbrooks * XXX: Fields 'f_inter' and 'offset_side2' are unused by kernel.
178130933Sbrooks *
179152209Sthompsa * XXX: These should really go in a /etc/floppycap colon separated file
180130933Sbrooks * XXX: but the kernel needs some of them for proper defaults and it would
181130933Sbrooks * XXX: should have been done 20 years ago to make sense.
182160195Ssam */
183130933Sbrooks#ifdef PC98
184130933Sbrooks#define FDF_3_1440 18,2,0xFF,0x1B,80,0,2,2,0x54,1,0,FL_MFM
185130933Sbrooks#define FDF_3_1200 15,2,0xFF,0x1B,80,0,0,2,0x54,1,0,FL_MFM
186130933Sbrooks#define FDF_3_720   9,2,0xFF,0x20,80,0,1,2,0x50,1,0,FL_MFM
187130933Sbrooks#define FDF_3_360   9,2,0xFF,0x20,40,0,1,2,0x50,1,0,FL_MFM|FL_2STEP
188241610Sglebius#define FDF_3_640   8,2,0xFF,0x2A,80,0,1,2,0x50,1,0,FL_MFM
189241610Sglebius#define FDF_3_1230  8,3,0xFF,0x35,77,0,0,2,0x74,1,0,FL_MFM
190241610Sglebius#define FDF_5_1200 15,2,0xFF,0x1B,80,0,0,2,0x54,1,0,FL_MFM
191241610Sglebius#define FDF_5_720   9,2,0xFF,0x20,80,0,1,2,0x50,1,0,FL_MFM
192241610Sglebius#define FDF_5_360   9,2,0xFF,0x20,40,0,1,2,0x50,1,0,FL_MFM|FL_2STEP
193241610Sglebius#define FDF_5_640   8,2,0xFF,0x2A,80,0,1,2,0x50,1,0,FL_MFM
194241610Sglebius#define FDF_5_1230  8,3,0xFF,0x35,77,0,0,2,0x74,1,0,FL_MFM
195130933Sbrooks#else /* PC98 */
196192669Szec#define FDF_3_2880 36,2,0xFF,0x1B,80,0,FDC_1MBPS,002,0x4C,1,1,FL_MFM|FL_PERPND
197192669Szec#define FDF_3_1722 21,2,0xFF,0x04,82,0,FDC_500KBPS,2,0x0C,2,0,FL_MFM
198192669Szec#define FDF_3_1476 18,2,0xFF,0x1B,82,0,FDC_500KBPS,2,0x6C,1,0,FL_MFM
199241610Sglebius#define FDF_3_1440 18,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x6C,1,0,FL_MFM
200241610Sglebius#define FDF_3_1200 15,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x54,1,0,FL_MFM
201241610Sglebius#define FDF_3_820  10,2,0xFF,0x10,82,0,FDC_250KBPS,2,0x2e,1,0,FL_MFM
202241610Sglebius#define FDF_3_800  10,2,0xFF,0x10,80,0,FDC_250KBPS,2,0x2e,1,0,FL_MFM
203241610Sglebius#define FDF_3_720   9,2,0xFF,0x20,80,0,FDC_250KBPS,2,0x50,1,0,FL_MFM
204241610Sglebius#define FDF_5_1480 18,2,0xFF,0x02,82,0,FDC_500KBPS,2,0x02,2,0,FL_MFM
205241610Sglebius#define FDF_5_1440 18,2,0xFF,0x02,80,0,FDC_500KBPS,2,0x02,2,0,FL_MFM
206241610Sglebius#define FDF_5_1230  8,3,0xFF,0x35,77,0,FDC_500KBPS,2,0x74,1,0,FL_MFM
207192669Szec#define FDF_5_1200 15,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x54,1,0,FL_MFM
208192669Szec#define FDF_5_820  10,2,0xFF,0x10,82,0,FDC_300KBPS,2,0x2e,1,0,FL_MFM
209192669Szec#define FDF_5_800  10,2,0xFF,0x10,80,0,FDC_300KBPS,2,0x2e,1,0,FL_MFM
210130933Sbrooks#define FDF_5_720   9,2,0xFF,0x20,80,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
211130933Sbrooks#define FDF_5_640   8,2,0xFF,0x2A,80,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
212130933Sbrooks#define FDF_5_360   9,2,0xFF,0x23,40,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
213130933Sbrooks/* XXX:                      0x2a ? */
214130933Sbrooks#endif
215160195Ssam
216152209Sthompsa#endif /* !_MACHINE_IOCTL_FD_H_ */
217152209Sthompsa