iwm_fdvar.h revision 1.4 1 /* $NetBSD: iwm_fdvar.h,v 1.4 2000/01/21 23:29:06 thorpej 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_queue bufQueue; /* queue of buf's */
136 int sc_active; /* number of active requests */
137
138 /* private stuff here */
139 /* errors & retries in current I/O job */
140 int iwmErr; /* Last IO error */
141 int ioRetries;
142 int seekRetries;
143 int sectRetries;
144 int verifyRetries;
145
146 /* hardware info */
147 int drvFlags; /* Copy of drive flags */
148 short stepDirection; /* Current step direction */
149 diskPosition_t pos; /* Physical position on disk */
150
151
152 /* drive info */
153 short unit; /* Drive # as seen by IWM */
154 short partition; /* "Partition" info {a,b,c,...} */
155 fdInfo_t *defaultType; /* default floppy format */
156 fdInfo_t *currentType; /* current floppy format */
157 int state; /* XXX */
158
159 /* data transfer info */
160 int ioDirection; /* Read/write */
161 daddr_t startBlk; /* Starting block # */
162 int bytesLeft; /* Bytes left to transfer */
163 int bytesDone; /* Bytes transferred */
164 caddr_t current_buffer; /* target of current data transfer */
165 unsigned char *cbuf; /* ptr to cylinder cache */
166 int cachedSide; /* Which head is cached? */
167 cylCacheSlot_t r_slots[IWM_MAX_GCR_SECTORS];
168 cylCacheSlot_t w_slots[IWM_MAX_GCR_SECTORS];
169 int writeLabel; /* Write access to disklabel? */
170 sectorHdr_t sHdr; /* current sector header */
171 };
172 typedef struct fd_softc fd_softc_t;
173
174 /*
175 * Software state of IWM controller
176 *
177 * SWIM/MFM mode may have some state to keep here.
178 */
179 struct iwm_softc {
180 struct device devInfo; /* generic device info */
181 int drives; /* # of attached fd's */
182 fd_softc_t *fd[IWM_MAX_DRIVE]; /* ptrs to children */
183
184 int state; /* make that an enum? */
185 u_char modeReg; /* Copy of IWM mode register */
186 short maxRetries; /* I/O retries */
187 int errors;
188 int underruns; /* data not delivered in time */
189 };
190 typedef struct iwm_softc iwm_softc_t;
191
192
193 /**
194 ** Exported functions
195 **/
196
197 /*
198 * IWM Loadable Kernel Module : Exported functions
199 */
200 #ifdef _LKM
201 int fdModInit __P((void));
202 void fdModFree __P((void));
203 #endif
204
205 /*
206 * This is the exported driver interface
207 * (bdevsw[] & cdevsw[] function prototypes)
208 *
209 * (see <sys/conf.h>
210 */
211 dev_type_open(fdopen);
212 dev_type_close(fdclose);
213 dev_type_strategy(fdstrategy);
214 dev_type_read(fdread);
215 dev_type_write(fdwrite);
216 dev_type_ioctl(fdioctl);
217 dev_type_size(fdsize);
218 dev_type_dump(fddump);
219
220
221 int iwmInit __P((void));
222 int iwmCheckDrive __P((int32_t drive));
223 int iwmSelectDrive __P((int32_t drive));
224 int iwmSelectSide __P((int32_t side));
225 int iwmTrack00 __P((void));
226 int iwmSeek __P((int32_t steps));
227
228 int iwmReadSector __P((sectorHdr_t *hdr, cylCacheSlot_t *r_slots,
229 caddr_t buf));
230 int iwmWriteSector __P((sectorHdr_t *hdr, cylCacheSlot_t *w_slots));
231
232 int iwmDiskEject __P((int32_t drive)); /* drive = [0..1] */
233 int iwmMotor __P((int32_t drive, int32_t onOff)); /* on(1)/off(0) */
234
235 /*
236 * Debugging only
237 */
238 int iwmQueryDrvFlag __P((int32_t drive, int32_t reg)); /* reg = [0..15] */
239
240 /* Make sure we run at splhigh when calling! */
241 int iwmReadSectHdr __P((sectorHdr_t *hdr));
242
243 #if 0 /* XXX not yet */
244 int iwmReadRawSector __P((int32_t ID, caddr_t buf));
245 int iwmWriteRawSector __P((int32_t ID, caddr_t buf));
246 int iwmReadRawTrack __P((int32_t mode, caddr_t buf));
247 #endif
248
249 #endif /* _MAC68K_FDVAR_H */
250