iwm_fdvar.h revision 1.3 1 /* $NetBSD: iwm_fdvar.h,v 1.3 1999/03/27 05:45:20 scottr Exp $ */
2
3 /*
4 * Copyright (c) 1997, 1998 Hauke Fath. All rights reserved.
5 *
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
8 * are met:
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 */
28 #ifndef _MAC68K_FDVAR_H
29 #define _MAC68K_FDVAR_H
30
31 /**
32 ** Constants
33 **/
34
35 enum {
36 IWM_MAX_DRIVE = 2, /* Attachable drives */
37 IWM_GCR_DISK_ZONES = 5, /* Zones on GCR disk */
38 IWM_MAX_GCR_SECTORS = 12, /* Max. sectors per GCR track */
39 IWM_MAX_FLOPPY_SECT = 50, /* Larger than the highest sector */
40 /* number likely to occur */
41 };
42
43
44 /* Physical track format codes */
45 enum {
46 IWM_GCR, /* Apple's Group Code Recording format */
47 IWM_MFM_DD, /* Standard MFM on DD disk (250 KBit/s) */
48 IWM_MFM_HD /* Standard MFM on HD disk (500 KBit/s) */
49 };
50
51 /* Drive softc flags */
52 enum {
53 IWM_FD_IS_OPEN = 0x00000001,
54 IWM_FD_MOTOR_ON = 0x00000002
55 };
56
57 /* seek() behaviour */
58 enum {
59 IWM_SEEK_VANILLA,
60 IWM_SEEK_RECAL,
61 IWM_SEEK_VERIFY
62 };
63
64 /* I/O direction */
65 enum {
66 IWM_WRITE = 0,
67 IWM_READ
68 };
69
70
71 /**
72 ** Data Types
73 **/
74
75 /*
76 * Floppy disk format information
77 *
78 * XXX How to describe ZBR here? UN*X disk drive handling -- clinging
79 * tenaciously to the trailing edge of technology...
80 */
81 struct fdInfo {
82 short heads; /* # of heads the drive has */
83 short tracks; /* # of tracks per side (cyl's) */
84 short sectorSize; /* Bytes per sector */
85 short secPerTrack; /* fake */
86 short secPerCyl; /* fake */
87 short secPerDisk; /* # of sectors per __disk__ */
88 short stepRate; /* in ms (is a software delay) */
89 short interleave; /* Sector interleave */
90 short physFormat; /* GCR, MFM DD, MFM HD */
91 char *description;
92 };
93 typedef struct fdInfo fdInfo_t;
94
95 /*
96 * Current physical location on Sony GCR disk
97 */
98 struct diskPosition {
99 short track;
100 short oldTrack;
101 short side;
102 short sector;
103 short maxSect; /* Highest sector # for this track */
104 };
105 typedef struct diskPosition diskPosition_t;
106
107 /*
108 * Zone recording scheme (per disk surface/head)
109 */
110 struct diskZone {
111 short tracks; /* # of tracks per zone */
112 short sectPerTrack;
113 short firstBlock;
114 short lastBlock;
115 };
116 typedef struct diskZone diskZone_t;
117
118 /*
119 * Arguments passed between iwmAttach() and the fd probe routines.
120 */
121 struct iwmAttachArgs {
122 fdInfo_t *driveType; /* Default drive parameters */
123 short unit; /* Current drive # */
124 };
125 typedef struct iwmAttachArgs iwmAttachArgs_t;
126
127 /*
128 * Software state per disk: the IWM can have max. 2 drives. Newer
129 * machines don't even have a port for an external drive.
130 *
131 */
132 struct fd_softc {
133 struct device devInfo; /* generic device info */
134 struct disk diskInfo; /* generic disk info */
135 struct buf bufQueue; /* queue of buf's */
136
137 /* private stuff here */
138 /* errors & retries in current I/O job */
139 int iwmErr; /* Last IO error */
140 int ioRetries;
141 int seekRetries;
142 int sectRetries;
143 int verifyRetries;
144
145 /* hardware info */
146 int drvFlags; /* Copy of drive flags */
147 short stepDirection; /* Current step direction */
148 diskPosition_t pos; /* Physical position on disk */
149
150
151 /* drive info */
152 short unit; /* Drive # as seen by IWM */
153 short partition; /* "Partition" info {a,b,c,...} */
154 fdInfo_t *defaultType; /* default floppy format */
155 fdInfo_t *currentType; /* current floppy format */
156 int state; /* XXX */
157
158 /* data transfer info */
159 int ioDirection; /* Read/write */
160 daddr_t startBlk; /* Starting block # */
161 int bytesLeft; /* Bytes left to transfer */
162 int bytesDone; /* Bytes transferred */
163 caddr_t current_buffer; /* target of current data transfer */
164 unsigned char *cbuf; /* ptr to cylinder cache */
165 int cachedSide; /* Which head is cached? */
166 cylCacheSlot_t r_slots[IWM_MAX_GCR_SECTORS];
167 cylCacheSlot_t w_slots[IWM_MAX_GCR_SECTORS];
168 int writeLabel; /* Write access to disklabel? */
169 sectorHdr_t sHdr; /* current sector header */
170 };
171 typedef struct fd_softc fd_softc_t;
172
173 /*
174 * Software state of IWM controller
175 *
176 * SWIM/MFM mode may have some state to keep here.
177 */
178 struct iwm_softc {
179 struct device devInfo; /* generic device info */
180 int drives; /* # of attached fd's */
181 fd_softc_t *fd[IWM_MAX_DRIVE]; /* ptrs to children */
182
183 int state; /* make that an enum? */
184 u_char modeReg; /* Copy of IWM mode register */
185 short maxRetries; /* I/O retries */
186 int errors;
187 int underruns; /* data not delivered in time */
188 };
189 typedef struct iwm_softc iwm_softc_t;
190
191
192 /**
193 ** Exported functions
194 **/
195
196 /*
197 * IWM Loadable Kernel Module : Exported functions
198 */
199 #ifdef _LKM
200 int fdModInit __P((void));
201 void fdModFree __P((void));
202 #endif
203
204 /*
205 * This is the exported driver interface
206 * (bdevsw[] & cdevsw[] function prototypes)
207 *
208 * (see <sys/conf.h>
209 */
210 dev_type_open(fdopen);
211 dev_type_close(fdclose);
212 dev_type_strategy(fdstrategy);
213 dev_type_read(fdread);
214 dev_type_write(fdwrite);
215 dev_type_ioctl(fdioctl);
216 dev_type_size(fdsize);
217 dev_type_dump(fddump);
218
219
220 int iwmInit __P((void));
221 int iwmCheckDrive __P((int32_t drive));
222 int iwmSelectDrive __P((int32_t drive));
223 int iwmSelectSide __P((int32_t side));
224 int iwmTrack00 __P((void));
225 int iwmSeek __P((int32_t steps));
226
227 int iwmReadSector __P((sectorHdr_t *hdr, cylCacheSlot_t *r_slots,
228 caddr_t buf));
229 int iwmWriteSector __P((sectorHdr_t *hdr, cylCacheSlot_t *w_slots));
230
231 int iwmDiskEject __P((int32_t drive)); /* drive = [0..1] */
232 int iwmMotor __P((int32_t drive, int32_t onOff)); /* on(1)/off(0) */
233
234 /*
235 * Debugging only
236 */
237 int iwmQueryDrvFlag __P((int32_t drive, int32_t reg)); /* reg = [0..15] */
238
239 /* Make sure we run at splhigh when calling! */
240 int iwmReadSectHdr __P((sectorHdr_t *hdr));
241
242 #if 0 /* XXX not yet */
243 int iwmReadRawSector __P((int32_t ID, caddr_t buf));
244 int iwmWriteRawSector __P((int32_t ID, caddr_t buf));
245 int iwmReadRawTrack __P((int32_t mode, caddr_t buf));
246 #endif
247
248 #endif /* _MAC68K_FDVAR_H */
249