1/*-
2 * Copyright (C) 1992-1994,2001 by Joerg Wunsch, Dresden
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in the
12 *    documentation and/or other materials provided with the distribution.
13 *
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR(S) ``AS IS'' AND ANY
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
17 * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE AUTHOR(S) BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
19 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
20 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
21 * BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
22 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE
24 * USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH
25 * DAMAGE.
26 *
27 * $FreeBSD$
28 */
29
30#ifndef	_MACHINE_IOCTL_FD_H_
31#define	_MACHINE_IOCTL_FD_H_
32
33#ifndef _KERNEL
34#include <sys/types.h>
35#endif
36#include <sys/ioccom.h>
37
38#define FD_FORMAT_VERSION 110	/* used to validate before formatting */
39#define FD_MAX_NSEC 36		/* highest known number of spt - allow for */
40				/* 2.88 MB drives */
41
42struct fd_formb {
43	int format_version;	/* == FD_FORMAT_VERSION */
44	int cyl, head;
45	int transfer_rate;	/* FDC_???KBPS */
46
47	struct fd_form_data {
48		/*
49		 * DO NOT CHANGE THE LAYOUT OF THIS STRUCTS
50		 * it is hardware-dependent since it exactly
51		 * matches the byte sequence to write to FDC
52		 * during its `format track' operation
53		 */
54		u_char secshift; /* 0 -> 128, ...; usually 2 -> 512 */
55		u_char nsecs;	/* must be <= FD_MAX_NSEC */
56		u_char gaplen;	/* GAP 3 length; usually 84 */
57		u_char fillbyte; /* usually 0xf6 */
58		struct fd_idfield_data {
59			/*
60			 * data to write into id fields;
61			 * for obscure formats, they mustn't match
62			 * the real values (but mostly do)
63			 */
64			u_char cylno;	/* 0 thru 79 (or 39) */
65			u_char headno;	/* 0, or 1 */
66			u_char secno;	/* starting at 1! */
67			u_char secsize;	/* usually 2 */
68		} idfields[FD_MAX_NSEC]; /* 0 <= idx < nsecs used */
69	} format_info;
70};
71
72/* make life easier */
73# define fd_formb_secshift   format_info.secshift
74# define fd_formb_nsecs      format_info.nsecs
75# define fd_formb_gaplen     format_info.gaplen
76# define fd_formb_fillbyte   format_info.fillbyte
77/* these data must be filled in for(i = 0; i < fd_formb_nsecs; i++) */
78# define fd_formb_cylno(i)   format_info.idfields[i].cylno
79# define fd_formb_headno(i)  format_info.idfields[i].headno
80# define fd_formb_secno(i)   format_info.idfields[i].secno
81# define fd_formb_secsize(i) format_info.idfields[i].secsize
82
83struct fd_type {
84	int	sectrac;		/* sectors per track         */
85	int	secsize;		/* size code for sectors     */
86	int	datalen;		/* data len when secsize = 0 */
87	int	gap;			/* gap len between sectors   */
88	int	tracks;			/* total number of cylinders */
89	int	size;			/* size of disk in sectors   */
90	int	trans;			/* transfer speed code       */
91	int	heads;			/* number of heads	     */
92	int     f_gap;                  /* format gap len            */
93	int     f_inter;                /* format interleave factor  */
94	int	offset_side2;		/* offset of sectors on side2 */
95	int	flags;			/* misc. features */
96#define FL_MFM		0x0001		/* MFM recording */
97#define FL_2STEP	0x0002		/* 2 steps between cylinders */
98#define FL_PERPND	0x0004		/* perpendicular recording */
99#define FL_AUTO		0x0008		/* autodetect format */
100};
101
102struct fdc_status {
103	u_int	status[7];
104};
105
106/*
107 * cyl and head are being passed into ioctl(FD_READID)
108 * all four fields are being returned
109 */
110struct fdc_readid {
111	u_char	cyl;		/* C - 0...79 */
112	u_char	head;		/* H - 0...1 */
113	u_char	sec;		/* R - 1...n */
114	u_char	secshift;	/* N - log2(secsize / 128) */
115};
116
117/*
118 * Diskette drive type, basically the same as stored in RTC on ISA
119 * machines (see /sys/isa/rtc.h), but right-shifted by four bits.
120 */
121enum fd_drivetype {
122	FDT_NONE, FDT_360K, FDT_12M, FDT_720K, FDT_144M, FDT_288M_1,
123	FDT_288M
124};
125
126
127#define FD_FORM   _IOW('F', 61, struct fd_formb) /* format a track */
128#define FD_GTYPE  _IOR('F', 62, struct fd_type)  /* get drive type */
129#define FD_STYPE  _IOW('F', 63, struct fd_type)  /* set drive type */
130
131#define FD_GOPTS  _IOR('F', 64, int) /* drive options, see below */
132#define FD_SOPTS  _IOW('F', 65, int)
133
134#ifdef PC98
135#define FD_DEBUG  _IOW('F', 66, int)
136#endif
137
138#define FD_CLRERR _IO('F', 67)	/* clear error counter */
139
140#define FD_READID _IOWR('F', 68, struct fdc_readid) /* read ID field */
141
142/*
143 * Obtain NE765 status registers.  Only successful if there is
144 * a valid status stored in fdc->status[].
145 */
146#define FD_GSTAT  _IOR('F', 69, struct fdc_status)
147
148#define FD_GDTYPE _IOR('F', 70, enum fd_drivetype) /* obtain drive type */
149
150/* Options for FD_GOPTS/FD_SOPTS, cleared on device close */
151#define FDOPT_NORETRY 0x0001	/* no retries on failure */
152#define FDOPT_NOERRLOG 0x002	/* no "hard error" kernel log messages */
153#define FDOPT_NOERROR 0x0004	/* do not indicate errors, caller will use
154				   FD_GSTAT in order to obtain status */
155#ifdef PC98
156#define FDOPT_AUTOSEL 0x8000	/* read/only option: device performs media
157				 * autoselection */
158#endif
159
160/*
161 * Transfer rate definitions.  Used in the structures above.  They
162 * represent the hardware encoding of bits 0 and 1 of the FDC control
163 * register when writing to the register.
164 * Transfer rates for FM encoding are half the values listed here
165 * (but we currently don't support FM encoding).
166 */
167#define	FDC_500KBPS	0x00	/* 500KBPS MFM drive transfer rate */
168#define	FDC_300KBPS	0x01	/* 300KBPS MFM drive transfer rate */
169#define	FDC_250KBPS	0x02	/* 250KBPS MFM drive transfer rate */
170#define	FDC_1MBPS	0x03	/* 1MPBS MFM drive transfer rate */
171
172/*
173 * Parameters for common formats
174 *
175 * See struct fd_type for layout.
176 * XXX: Field 'size' must be calculated.
177 * XXX: Fields 'f_inter' and 'offset_side2' are unused by kernel.
178 *
179 * XXX: These should really go in a /etc/floppycap colon separated file
180 * XXX: but the kernel needs some of them for proper defaults and it would
181 * XXX: should have been done 20 years ago to make sense.
182 */
183#ifdef PC98
184#define FDF_3_1722 21,2,0xFF,0x04,82,0,2,2,0x0C,2,0,FL_MFM
185#define FDF_3_1476 18,2,0xFF,0x1B,82,0,2,2,0x54,1,0,FL_MFM
186#define FDF_3_1440 18,2,0xFF,0x1B,80,0,2,2,0x54,1,0,FL_MFM
187#define FDF_3_1200 15,2,0xFF,0x1B,80,0,0,2,0x54,1,0,FL_MFM
188#define FDF_3_820  10,2,0xFF,0x10,82,0,1,2,0x30,1,0,FL_MFM
189#define FDF_3_800  10,2,0xFF,0x10,80,0,1,2,0x30,1,0,FL_MFM
190#define FDF_3_720   9,2,0xFF,0x20,80,0,1,2,0x50,1,0,FL_MFM
191#define FDF_3_360   9,2,0xFF,0x20,40,0,1,2,0x50,1,0,FL_MFM|FL_2STEP
192#define FDF_3_640   8,2,0xFF,0x2A,80,0,1,2,0x50,1,0,FL_MFM
193#define FDF_3_1230  8,3,0xFF,0x35,77,0,0,2,0x74,1,0,FL_MFM
194#define FDF_3_1280  8,3,0xFF,0x35,80,0,0,2,0x74,1,0,FL_MFM
195#define FDF_3_1480  9,3,0xFF,0x35,82,0,0,2,0x47,1,0,FL_MFM
196#define FDF_3_1640 10,3,0xFF,0x1B,82,0,2,2,0x54,1,0,FL_MFM
197#define FDF_5_1200 15,2,0xFF,0x1B,80,0,0,2,0x54,1,0,FL_MFM
198#define FDF_5_820  10,2,0xFF,0x10,82,0,1,2,0x30,1,0,FL_MFM
199#define FDF_5_800  10,2,0xFF,0x10,80,0,1,2,0x30,1,0,FL_MFM
200#define FDF_5_720   9,2,0xFF,0x20,80,0,1,2,0x50,1,0,FL_MFM
201#define FDF_5_360   9,2,0xFF,0x20,40,0,1,2,0x50,1,0,FL_MFM|FL_2STEP
202#define FDF_5_640   8,2,0xFF,0x2A,80,0,1,2,0x50,1,0,FL_MFM
203#define FDF_5_1230  8,3,0xFF,0x35,77,0,0,2,0x74,1,0,FL_MFM
204#define FDF_5_1280  8,3,0xFF,0x35,80,0,0,2,0x74,1,0,FL_MFM
205#else /* PC98 */
206#define FDF_3_2880 36,2,0xFF,0x1B,80,0,FDC_1MBPS,002,0x4C,1,1,FL_MFM|FL_PERPND
207#define FDF_3_1722 21,2,0xFF,0x04,82,0,FDC_500KBPS,2,0x0C,2,0,FL_MFM
208#define FDF_3_1476 18,2,0xFF,0x1B,82,0,FDC_500KBPS,2,0x6C,1,0,FL_MFM
209#define FDF_3_1440 18,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x6C,1,0,FL_MFM
210#define FDF_3_1200 15,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x54,1,0,FL_MFM
211#define FDF_3_820  10,2,0xFF,0x10,82,0,FDC_250KBPS,2,0x2e,1,0,FL_MFM
212#define FDF_3_800  10,2,0xFF,0x10,80,0,FDC_250KBPS,2,0x2e,1,0,FL_MFM
213#define FDF_3_720   9,2,0xFF,0x20,80,0,FDC_250KBPS,2,0x50,1,0,FL_MFM
214#define FDF_5_1480 18,2,0xFF,0x02,82,0,FDC_500KBPS,2,0x02,2,0,FL_MFM
215#define FDF_5_1440 18,2,0xFF,0x02,80,0,FDC_500KBPS,2,0x02,2,0,FL_MFM
216#define FDF_5_1230  8,3,0xFF,0x35,77,0,FDC_500KBPS,2,0x74,1,0,FL_MFM
217#define FDF_5_1200 15,2,0xFF,0x1B,80,0,FDC_500KBPS,2,0x54,1,0,FL_MFM
218#define FDF_5_820  10,2,0xFF,0x10,82,0,FDC_300KBPS,2,0x2e,1,0,FL_MFM
219#define FDF_5_800  10,2,0xFF,0x10,80,0,FDC_300KBPS,2,0x2e,1,0,FL_MFM
220#define FDF_5_720   9,2,0xFF,0x20,80,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
221#define FDF_5_640   8,2,0xFF,0x2A,80,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
222#define FDF_5_360   9,2,0xFF,0x23,40,0,FDC_300KBPS,2,0x50,1,0,FL_MFM
223/* XXX:                      0x2a ? */
224#endif
225
226#endif /* !_MACHINE_IOCTL_FD_H_ */
227