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