1 /*        $NetBSD: iwm_fdvar.h,v 1.16 2020/08/10 10:59:33 rin 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  *
15  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
17  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
18  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
19  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
20  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
21  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
22  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
23  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
24  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
25  */
26 #ifndef _MAC68K_FDVAR_H
27 #define _MAC68K_FDVAR_H
28 
29 /**
30  **       Constants
31  **/
32 
33 enum {
34           IWM_MAX_DRIVE = 2,            /* Attachable drives */
35           IWM_GCR_DISK_ZONES = 5,                 /* Zones on GCR disk */
36           IWM_MAX_GCR_SECTORS = 12,     /* Max. sectors per GCR track */
37           IWM_MAX_FLOPPY_SECT = 50,     /* Larger than the highest sector */
38                                                   /* number likely to occur */
39 };
40 
41 
42 /* Physical track format codes */
43 enum {
44           IWM_GCR,            /* Apple's Group Code Recording format */
45           IWM_MFM_DD,                   /* Standard MFM on DD disk (250 KBit/s) */
46           IWM_MFM_HD                    /* Standard MFM on HD disk (500 KBit/s) */
47 };
48 
49 /* Drive softc flags */
50 enum {
51           IWM_FD_IS_OPEN      = 0x00000001,
52           IWM_FD_MOTOR_ON = 0x00000002
53 };
54 
55 /* seek() behaviour */
56 enum {
57           IWM_SEEK_VANILLA,
58           IWM_SEEK_RECAL,
59           IWM_SEEK_VERIFY
60 };
61 
62 /* I/O direction */
63 enum {
64           IWM_WRITE = 0,
65           IWM_READ
66 };
67 
68 
69 /**
70  **       Data Types
71  **/
72 
73 /*
74  * Floppy disk format information
75  *
76  * XXX How to describe ZBR here? UN*X disk drive handling -- clinging
77  *     tenaciously to the trailing edge of technology...
78  */
79 struct fdInfo {
80           short     heads;                        /* # of heads the drive has */
81           short     tracks;                       /* # of tracks per side (cyl's)         */
82           short     sectorSize;                   /* Bytes per sector */
83           short     secPerTrack;                  /* fake   */
84           short     secPerCyl;                    /* fake   */
85           short     secPerDisk;                   /* # of sectors per __disk__ */
86           short     stepRate;           /* in ms (is a software delay) */
87           short     interleave;                   /* Sector interleave */
88           short     physFormat;                   /* GCR, MFM DD, MFM HD */
89           const char          *description;
90 };
91 typedef struct fdInfo fdInfo_t;
92 
93 /*
94  * Current physical location on Sony GCR disk
95  */
96 struct diskPosition {
97           short     track;
98           short     oldTrack;
99           short     side;
100           short     sector;
101           short     maxSect;            /* Highest sector # for this track */
102 };
103 typedef struct diskPosition diskPosition_t;
104 
105 /*
106  * Zone recording scheme (per disk surface/head)
107  */
108 struct diskZone {
109           short     tracks;                       /* # of tracks per zone       */
110           short     sectPerTrack;
111           short     firstBlock;
112           short     lastBlock;
113 };
114 typedef struct diskZone diskZone_t;
115 
116 /*
117  * Arguments passed between iwmAttach() and the fd probe routines.
118  */
119 struct iwmAttachArgs {
120           fdInfo_t *driveType;                    /* Default drive parameters */
121           short     unit;                         /* Current drive # */
122 };
123 typedef struct iwmAttachArgs iwmAttachArgs_t;
124 
125 /*
126  * Software state per disk: the IWM can have max. 2 drives. Newer
127  * machines don't even have a port for an external drive.
128  *
129  */
130 struct fd_softc {
131           device_t sc_dev;              /* generic device info */
132           struct disk diskInfo;                   /* generic disk info */
133           struct bufq_state *bufQueue;  /* queue of buf's */
134           int sc_active;                          /* number of active requests */
135           struct callout motor_ch;      /* motor callout */
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           char *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           int       drives;                       /* # of attached fd's */
180           fd_softc_t *fd[IWM_MAX_DRIVE];          /* ptrs to children */
181 
182           int       state;                        /* make that an enum? */
183           u_char    modeReg;            /* Copy of IWM mode register */
184           short     maxRetries;                   /* I/O retries */
185           int       errors;
186           int       underruns;                    /* data not delivered in time */
187 };
188 typedef struct iwm_softc iwm_softc_t;
189 
190 
191 /**
192  **     Exported functions
193  **/
194 
195 /*
196  * IWM Loadable Kernel Module : Exported functions
197  */
198 #ifdef _MODULE
199 int       fdModInit(void);
200 void      fdModFree(void);
201 #endif
202 
203 int       iwmInit(void);
204 int       iwmCheckDrive(int32_t);
205 int       iwmSelectDrive(int32_t);
206 int       iwmSelectSide(int32_t);
207 int       iwmTrack00(void);
208 int       iwmSeek(int32_t);
209 
210 int     iwmReadSector(sectorHdr_t *, cylCacheSlot_t *, void *);
211 int       iwmWriteSector(sectorHdr_t *, cylCacheSlot_t *);
212 
213 int       iwmDiskEject(int32_t);                  /* drive = [0..1] */
214 int       iwmMotor(int32_t, int32_t);   /* on(1)/off(0)     */
215 
216 /*
217  * Debugging only
218  */
219 int       iwmQueryDrvFlag(int32_t, int32_t); /* reg = [0..15] */
220 
221 /* Make sure we run at splhigh when calling! */
222 int       iwmReadSectHdr(sectorHdr_t *);
223 
224 #if 0 /* XXX not yet */
225 int       iwmReadRawSector(int32_t, void *);
226 int       iwmWriteRawSector(int32_t, void *);
227 int       iwmReadRawTrack(int32_t, void *);
228 #endif
229 
230 #endif /* _MAC68K_FDVAR_H */
231