| [2] | 1 | #ifndef _LINUX_FD_H |
|---|
| 2 | #define _LINUX_FD_H |
|---|
| 3 | |
|---|
| 4 | #include <linux/ioctl.h> |
|---|
| 5 | |
|---|
| 6 | /* New file layout: Now the ioctl definitions immediately follow the |
|---|
| 7 | * definitions of the structures that they use */ |
|---|
| 8 | |
|---|
| 9 | /* |
|---|
| 10 | * Geometry |
|---|
| 11 | */ |
|---|
| 12 | struct floppy_struct { |
|---|
| 13 | unsigned int size, /* nr of sectors total */ |
|---|
| 14 | sect, /* sectors per track */ |
|---|
| 15 | head, /* nr of heads */ |
|---|
| 16 | track, /* nr of tracks */ |
|---|
| 17 | stretch; /* !=0 means double track steps */ |
|---|
| 18 | #define FD_STRETCH 1 |
|---|
| 19 | #define FD_SWAPSIDES 2 |
|---|
| 20 | #define FD_ZEROBASED 4 |
|---|
| 21 | |
|---|
| 22 | unsigned char gap, /* gap1 size */ |
|---|
| 23 | |
|---|
| 24 | rate, /* data rate. |= 0x40 for perpendicular */ |
|---|
| 25 | #define FD_2M 0x4 |
|---|
| 26 | #define FD_SIZECODEMASK 0x38 |
|---|
| 27 | #define FD_SIZECODE(floppy) (((((floppy)->rate&FD_SIZECODEMASK)>> 3)+ 2) %8) |
|---|
| 28 | #define FD_SECTSIZE(floppy) ( (floppy)->rate & FD_2M ? \ |
|---|
| 29 | 512 : 128 << FD_SIZECODE(floppy) ) |
|---|
| 30 | #define FD_PERP 0x40 |
|---|
| 31 | |
|---|
| 32 | spec1, /* stepping rate, head unload time */ |
|---|
| 33 | fmt_gap; /* gap2 size */ |
|---|
| 34 | const char * name; /* used only for predefined formats */ |
|---|
| 35 | }; |
|---|
| 36 | |
|---|
| 37 | |
|---|
| 38 | /* commands needing write access have 0x40 set */ |
|---|
| 39 | /* commands needing super user access have 0x80 set */ |
|---|
| 40 | |
|---|
| 41 | #define FDCLRPRM _IO(2, 0x41) |
|---|
| 42 | /* clear user-defined parameters */ |
|---|
| 43 | |
|---|
| 44 | #define FDSETPRM _IOW(2, 0x42, struct floppy_struct) |
|---|
| 45 | #define FDSETMEDIAPRM FDSETPRM |
|---|
| 46 | /* set user-defined parameters for current media */ |
|---|
| 47 | |
|---|
| 48 | #define FDDEFPRM _IOW(2, 0x43, struct floppy_struct) |
|---|
| 49 | #define FDGETPRM _IOR(2, 0x04, struct floppy_struct) |
|---|
| 50 | #define FDDEFMEDIAPRM FDDEFPRM |
|---|
| 51 | #define FDGETMEDIAPRM FDGETPRM |
|---|
| 52 | /* set/get disk parameters */ |
|---|
| 53 | |
|---|
| 54 | |
|---|
| 55 | #define FDMSGON _IO(2,0x45) |
|---|
| 56 | #define FDMSGOFF _IO(2,0x46) |
|---|
| 57 | /* issue/don't issue kernel messages on media type change */ |
|---|
| 58 | |
|---|
| 59 | |
|---|
| 60 | /* |
|---|
| 61 | * Formatting (obsolete) |
|---|
| 62 | */ |
|---|
| 63 | #define FD_FILL_BYTE 0xF6 /* format fill byte. */ |
|---|
| 64 | |
|---|
| 65 | struct format_descr { |
|---|
| 66 | unsigned int device,head,track; |
|---|
| 67 | }; |
|---|
| 68 | |
|---|
| 69 | #define FDFMTBEG _IO(2,0x47) |
|---|
| 70 | /* begin formatting a disk */ |
|---|
| 71 | #define FDFMTTRK _IOW(2,0x48, struct format_descr) |
|---|
| 72 | /* format the specified track */ |
|---|
| 73 | #define FDFMTEND _IO(2,0x49) |
|---|
| 74 | /* end formatting a disk */ |
|---|
| 75 | |
|---|
| 76 | |
|---|
| 77 | /* |
|---|
| 78 | * Error thresholds |
|---|
| 79 | */ |
|---|
| 80 | struct floppy_max_errors { |
|---|
| 81 | unsigned int |
|---|
| 82 | abort, /* number of errors to be reached before aborting */ |
|---|
| 83 | read_track, /* maximal number of errors permitted to read an |
|---|
| 84 | * entire track at once */ |
|---|
| 85 | reset, /* maximal number of errors before a reset is tried */ |
|---|
| 86 | recal, /* maximal number of errors before a recalibrate is |
|---|
| 87 | * tried */ |
|---|
| 88 | |
|---|
| 89 | /* |
|---|
| 90 | * Threshold for reporting FDC errors to the console. |
|---|
| 91 | * Setting this to zero may flood your screen when using |
|---|
| 92 | * ultra cheap floppies ;-) |
|---|
| 93 | */ |
|---|
| 94 | reporting; |
|---|
| 95 | |
|---|
| 96 | }; |
|---|
| 97 | |
|---|
| 98 | #define FDSETEMSGTRESH _IO(2,0x4a) |
|---|
| 99 | /* set fdc error reporting threshold */ |
|---|
| 100 | |
|---|
| 101 | #define FDFLUSH _IO(2,0x4b) |
|---|
| 102 | /* flush buffers for media; either for verifying media, or for |
|---|
| 103 | * handling a media change without closing the file descriptor */ |
|---|
| 104 | |
|---|
| 105 | #define FDSETMAXERRS _IOW(2, 0x4c, struct floppy_max_errors) |
|---|
| 106 | #define FDGETMAXERRS _IOR(2, 0x0e, struct floppy_max_errors) |
|---|
| 107 | /* set/get abortion and read_track threshold. See also floppy_drive_params |
|---|
| 108 | * structure */ |
|---|
| 109 | |
|---|
| 110 | |
|---|
| 111 | typedef char floppy_drive_name[16]; |
|---|
| 112 | #define FDGETDRVTYP _IOR(2, 0x0f, floppy_drive_name) |
|---|
| 113 | /* get drive type: 5 1/4 or 3 1/2 */ |
|---|
| 114 | |
|---|
| 115 | |
|---|
| 116 | /* |
|---|
| 117 | * Drive parameters (user modifiable) |
|---|
| 118 | */ |
|---|
| 119 | struct floppy_drive_params { |
|---|
| 120 | signed char cmos; /* CMOS type */ |
|---|
| 121 | |
|---|
| 122 | /* Spec2 is (HLD<<1 | ND), where HLD is head load time (1=2ms, 2=4 ms |
|---|
| 123 | * etc) and ND is set means no DMA. Hardcoded to 6 (HLD=6ms, use DMA). |
|---|
| 124 | */ |
|---|
| 125 | unsigned long max_dtr; /* Step rate, usec */ |
|---|
| 126 | unsigned long hlt; /* Head load/settle time, msec */ |
|---|
| 127 | unsigned long hut; /* Head unload time (remnant of |
|---|
| 128 | * 8" drives) */ |
|---|
| 129 | unsigned long srt; /* Step rate, usec */ |
|---|
| 130 | |
|---|
| 131 | unsigned long spinup; /* time needed for spinup (expressed |
|---|
| 132 | * in jiffies) */ |
|---|
| 133 | unsigned long spindown; /* timeout needed for spindown */ |
|---|
| 134 | unsigned char spindown_offset; /* decides in which position the disk |
|---|
| 135 | * will stop */ |
|---|
| 136 | unsigned char select_delay; /* delay to wait after select */ |
|---|
| 137 | unsigned char rps; /* rotations per second */ |
|---|
| 138 | unsigned char tracks; /* maximum number of tracks */ |
|---|
| 139 | unsigned long timeout; /* timeout for interrupt requests */ |
|---|
| 140 | |
|---|
| 141 | unsigned char interleave_sect; /* if there are more sectors, use |
|---|
| 142 | * interleave */ |
|---|
| 143 | |
|---|
| 144 | struct floppy_max_errors max_errors; |
|---|
| 145 | |
|---|
| 146 | char flags; /* various flags, including ftd_msg */ |
|---|
| 147 | /* |
|---|
| 148 | * Announce successful media type detection and media information loss after |
|---|
| 149 | * disk changes. |
|---|
| 150 | * Also used to enable/disable printing of overrun warnings. |
|---|
| 151 | */ |
|---|
| 152 | |
|---|
| 153 | #define FTD_MSG 0x10 |
|---|
| 154 | #define FD_BROKEN_DCL 0x20 |
|---|
| 155 | #define FD_DEBUG 0x02 |
|---|
| 156 | #define FD_SILENT_DCL_CLEAR 0x4 |
|---|
| 157 | #define FD_INVERTED_DCL 0x80 /* must be 0x80, because of hardware |
|---|
| 158 | considerations */ |
|---|
| 159 | |
|---|
| 160 | char read_track; /* use readtrack during probing? */ |
|---|
| 161 | |
|---|
| 162 | /* |
|---|
| 163 | * Auto-detection. Each drive type has eight formats which are |
|---|
| 164 | * used in succession to try to read the disk. If the FDC cannot lock onto |
|---|
| 165 | * the disk, the next format is tried. This uses the variable 'probing'. |
|---|
| 166 | */ |
|---|
| 167 | short autodetect[8]; /* autodetected formats */ |
|---|
| 168 | |
|---|
| 169 | int checkfreq; /* how often should the drive be checked for disk |
|---|
| 170 | * changes */ |
|---|
| 171 | int native_format; /* native format of this drive */ |
|---|
| 172 | }; |
|---|
| 173 | |
|---|
| 174 | enum { |
|---|
| 175 | FD_NEED_TWADDLE_BIT, /* more magic */ |
|---|
| 176 | FD_VERIFY_BIT, /* inquire for write protection */ |
|---|
| 177 | FD_DISK_NEWCHANGE_BIT, /* change detected, and no action undertaken yet |
|---|
| 178 | * to clear media change status */ |
|---|
| 179 | FD_UNUSED_BIT, |
|---|
| 180 | FD_DISK_CHANGED_BIT, /* disk has been changed since last i/o */ |
|---|
| 181 | FD_DISK_WRITABLE_BIT /* disk is writable */ |
|---|
| 182 | }; |
|---|
| 183 | |
|---|
| 184 | #define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params) |
|---|
| 185 | #define FDGETDRVPRM _IOR(2, 0x11, struct floppy_drive_params) |
|---|
| 186 | /* set/get drive parameters */ |
|---|
| 187 | |
|---|
| 188 | |
|---|
| 189 | /* |
|---|
| 190 | * Current drive state (not directly modifiable by user, readonly) |
|---|
| 191 | */ |
|---|
| 192 | struct floppy_drive_struct { |
|---|
| 193 | unsigned long flags; |
|---|
| 194 | /* values for these flags */ |
|---|
| 195 | #define FD_NEED_TWADDLE (1 << FD_NEED_TWADDLE_BIT) |
|---|
| 196 | #define FD_VERIFY (1 << FD_VERIFY_BIT) |
|---|
| 197 | #define FD_DISK_NEWCHANGE (1 << FD_DISK_NEWCHANGE_BIT) |
|---|
| 198 | #define FD_DISK_CHANGED (1 << FD_DISK_CHANGED_BIT) |
|---|
| 199 | #define FD_DISK_WRITABLE (1 << FD_DISK_WRITABLE_BIT) |
|---|
| 200 | |
|---|
| 201 | unsigned long spinup_date; |
|---|
| 202 | unsigned long select_date; |
|---|
| 203 | unsigned long first_read_date; |
|---|
| 204 | short probed_format; |
|---|
| 205 | short track; /* current track */ |
|---|
| 206 | short maxblock; /* id of highest block read */ |
|---|
| 207 | short maxtrack; /* id of highest half track read */ |
|---|
| 208 | int generation; /* how many diskchanges? */ |
|---|
| 209 | |
|---|
| 210 | /* |
|---|
| 211 | * (User-provided) media information is _not_ discarded after a media change |
|---|
| 212 | * if the corresponding keep_data flag is non-zero. Positive values are |
|---|
| 213 | * decremented after each probe. |
|---|
| 214 | */ |
|---|
| 215 | int keep_data; |
|---|
| 216 | |
|---|
| 217 | /* Prevent "aliased" accesses. */ |
|---|
| 218 | int fd_ref; |
|---|
| 219 | int fd_device; |
|---|
| 220 | unsigned long last_checked; /* when was the drive last checked for a disk |
|---|
| 221 | * change? */ |
|---|
| 222 | |
|---|
| 223 | char *dmabuf; |
|---|
| 224 | int bufblocks; |
|---|
| 225 | }; |
|---|
| 226 | |
|---|
| 227 | #define FDGETDRVSTAT _IOR(2, 0x12, struct floppy_drive_struct) |
|---|
| 228 | #define FDPOLLDRVSTAT _IOR(2, 0x13, struct floppy_drive_struct) |
|---|
| 229 | /* get drive state: GET returns the cached state, POLL polls for new state */ |
|---|
| 230 | |
|---|
| 231 | |
|---|
| 232 | /* |
|---|
| 233 | * reset FDC |
|---|
| 234 | */ |
|---|
| 235 | enum reset_mode { |
|---|
| 236 | FD_RESET_IF_NEEDED, /* reset only if the reset flags is set */ |
|---|
| 237 | FD_RESET_IF_RAWCMD, /* obsolete */ |
|---|
| 238 | FD_RESET_ALWAYS /* reset always */ |
|---|
| 239 | }; |
|---|
| 240 | #define FDRESET _IO(2, 0x54) |
|---|
| 241 | |
|---|
| 242 | |
|---|
| 243 | /* |
|---|
| 244 | * FDC state |
|---|
| 245 | */ |
|---|
| 246 | struct floppy_fdc_state { |
|---|
| 247 | int spec1; /* spec1 value last used */ |
|---|
| 248 | int spec2; /* spec2 value last used */ |
|---|
| 249 | int dtr; |
|---|
| 250 | unsigned char version; /* FDC version code */ |
|---|
| 251 | unsigned char dor; |
|---|
| 252 | unsigned long address; /* io address */ |
|---|
| 253 | unsigned int rawcmd:2; |
|---|
| 254 | unsigned int reset:1; |
|---|
| 255 | unsigned int need_configure:1; |
|---|
| 256 | unsigned int perp_mode:2; |
|---|
| 257 | unsigned int has_fifo:1; |
|---|
| 258 | unsigned int driver_version; /* version code for floppy driver */ |
|---|
| 259 | #define FD_DRIVER_VERSION 0x100 |
|---|
| 260 | /* user programs using the floppy API should use floppy_fdc_state to |
|---|
| 261 | * get the version number of the floppy driver that they are running |
|---|
| 262 | * on. If this version number is bigger than the one compiled into the |
|---|
| 263 | * user program (the FD_DRIVER_VERSION define), it should be prepared |
|---|
| 264 | * to bigger structures |
|---|
| 265 | */ |
|---|
| 266 | |
|---|
| 267 | unsigned char track[4]; |
|---|
| 268 | /* Position of the heads of the 4 units attached to this FDC, |
|---|
| 269 | * as stored on the FDC. In the future, the position as stored |
|---|
| 270 | * on the FDC might not agree with the actual physical |
|---|
| 271 | * position of these drive heads. By allowing such |
|---|
| 272 | * disagreement, it will be possible to reset the FDC without |
|---|
| 273 | * incurring the expensive cost of repositioning all heads. |
|---|
| 274 | * Right now, these positions are hard wired to 0. */ |
|---|
| 275 | |
|---|
| 276 | }; |
|---|
| 277 | |
|---|
| 278 | #define FDGETFDCSTAT _IOR(2, 0x15, struct floppy_fdc_state) |
|---|
| 279 | |
|---|
| 280 | |
|---|
| 281 | /* |
|---|
| 282 | * Asynchronous Write error tracking |
|---|
| 283 | */ |
|---|
| 284 | struct floppy_write_errors { |
|---|
| 285 | /* Write error logging. |
|---|
| 286 | * |
|---|
| 287 | * These fields can be cleared with the FDWERRORCLR ioctl. |
|---|
| 288 | * Only writes that were attempted but failed due to a physical media |
|---|
| 289 | * error are logged. write(2) calls that fail and return an error code |
|---|
| 290 | * to the user process are not counted. |
|---|
| 291 | */ |
|---|
| 292 | |
|---|
| 293 | unsigned int write_errors; /* number of physical write errors |
|---|
| 294 | * encountered */ |
|---|
| 295 | |
|---|
| 296 | /* position of first and last write errors */ |
|---|
| 297 | unsigned long first_error_sector; |
|---|
| 298 | int first_error_generation; |
|---|
| 299 | unsigned long last_error_sector; |
|---|
| 300 | int last_error_generation; |
|---|
| 301 | |
|---|
| 302 | unsigned int badness; /* highest retry count for a read or write |
|---|
| 303 | * operation */ |
|---|
| 304 | }; |
|---|
| 305 | |
|---|
| 306 | #define FDWERRORCLR _IO(2, 0x56) |
|---|
| 307 | /* clear write error and badness information */ |
|---|
| 308 | #define FDWERRORGET _IOR(2, 0x17, struct floppy_write_errors) |
|---|
| 309 | /* get write error and badness information */ |
|---|
| 310 | |
|---|
| 311 | |
|---|
| 312 | /* |
|---|
| 313 | * Raw commands |
|---|
| 314 | */ |
|---|
| 315 | /* new interface flag: now we can do them in batches */ |
|---|
| 316 | #define FDHAVEBATCHEDRAWCMD |
|---|
| 317 | |
|---|
| 318 | struct floppy_raw_cmd { |
|---|
| 319 | unsigned int flags; |
|---|
| 320 | #define FD_RAW_READ 1 |
|---|
| 321 | #define FD_RAW_WRITE 2 |
|---|
| 322 | #define FD_RAW_NO_MOTOR 4 |
|---|
| 323 | #define FD_RAW_DISK_CHANGE 4 /* out: disk change flag was set */ |
|---|
| 324 | #define FD_RAW_INTR 8 /* wait for an interrupt */ |
|---|
| 325 | #define FD_RAW_SPIN 0x10 /* spin up the disk for this command */ |
|---|
| 326 | #define FD_RAW_NO_MOTOR_AFTER 0x20 /* switch the motor off after command |
|---|
| 327 | * completion */ |
|---|
| 328 | #define FD_RAW_NEED_DISK 0x40 /* this command needs a disk to be present */ |
|---|
| 329 | #define FD_RAW_NEED_SEEK 0x80 /* this command uses an implied seek (soft) */ |
|---|
| 330 | |
|---|
| 331 | /* more "in" flags */ |
|---|
| 332 | #define FD_RAW_MORE 0x100 /* more records follow */ |
|---|
| 333 | #define FD_RAW_STOP_IF_FAILURE 0x200 /* stop if we encounter a failure */ |
|---|
| 334 | #define FD_RAW_STOP_IF_SUCCESS 0x400 /* stop if command successful */ |
|---|
| 335 | #define FD_RAW_SOFTFAILURE 0x800 /* consider the return value for failure |
|---|
| 336 | * detection too */ |
|---|
| 337 | |
|---|
| 338 | /* more "out" flags */ |
|---|
| 339 | #define FD_RAW_FAILURE 0x10000 /* command sent to fdc, fdc returned error */ |
|---|
| 340 | #define FD_RAW_HARDFAILURE 0x20000 /* fdc had to be reset, or timed out */ |
|---|
| 341 | |
|---|
| 342 | void *data; |
|---|
| 343 | char *kernel_data; /* location of data buffer in the kernel */ |
|---|
| 344 | struct floppy_raw_cmd *next; /* used for chaining of raw cmd's |
|---|
| 345 | * within the kernel */ |
|---|
| 346 | long length; /* in: length of dma transfer. out: remaining bytes */ |
|---|
| 347 | long phys_length; /* physical length, if different from dma length */ |
|---|
| 348 | int buffer_length; /* length of allocated buffer */ |
|---|
| 349 | |
|---|
| 350 | unsigned char rate; |
|---|
| 351 | unsigned char cmd_count; |
|---|
| 352 | unsigned char cmd[16]; |
|---|
| 353 | unsigned char reply_count; |
|---|
| 354 | unsigned char reply[16]; |
|---|
| 355 | int track; |
|---|
| 356 | int resultcode; |
|---|
| 357 | |
|---|
| 358 | int reserved1; |
|---|
| 359 | int reserved2; |
|---|
| 360 | }; |
|---|
| 361 | |
|---|
| 362 | #define FDRAWCMD _IO(2, 0x58) |
|---|
| 363 | /* send a raw command to the fdc. Structure size not included, because of |
|---|
| 364 | * batches */ |
|---|
| 365 | |
|---|
| 366 | #define FDTWADDLE _IO(2, 0x59) |
|---|
| 367 | /* flicker motor-on bit before reading a sector. Experimental */ |
|---|
| 368 | |
|---|
| 369 | |
|---|
| 370 | #define FDEJECT _IO(2, 0x5a) |
|---|
| 371 | /* eject the disk */ |
|---|
| 372 | |
|---|
| 373 | #endif |
|---|