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