Back to home page

OSCL-LXR

 
 

    


0001 /* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */
0002 #ifndef _UAPI_LINUX_FD_H
0003 #define _UAPI_LINUX_FD_H
0004 
0005 #include <linux/ioctl.h>
0006 #include <linux/compiler.h>
0007 
0008 /* New file layout: Now the ioctl definitions immediately follow the
0009  * definitions of the structures that they use */
0010 
0011 /*
0012  * Geometry
0013  */
0014 struct floppy_struct {
0015     unsigned int    size,       /* nr of sectors total */
0016             sect,       /* sectors per track */
0017             head,       /* nr of heads */
0018             track,      /* nr of tracks */
0019             stretch;    /* bit 0 !=0 means double track steps */
0020                     /* bit 1 != 0 means swap sides */
0021                     /* bits 2..9 give the first sector */
0022                     /*  number (the LSB is flipped) */
0023 #define FD_STRETCH 1
0024 #define FD_SWAPSIDES 2
0025 #define FD_ZEROBASED 4
0026 #define FD_SECTBASEMASK 0x3FC
0027 #define FD_MKSECTBASE(s) (((s) ^ 1) << 2)
0028 #define FD_SECTBASE(floppy) ((((floppy)->stretch & FD_SECTBASEMASK) >> 2) ^ 1)
0029 
0030     unsigned char   gap,        /* gap1 size */
0031 
0032             rate,       /* data rate. |= 0x40 for perpendicular */
0033 #define FD_2M 0x4
0034 #define FD_SIZECODEMASK 0x38
0035 #define FD_SIZECODE(floppy) (((((floppy)->rate&FD_SIZECODEMASK)>> 3)+ 2) %8)
0036 #define FD_SECTSIZE(floppy) ( (floppy)->rate & FD_2M ? \
0037                  512 : 128 << FD_SIZECODE(floppy) )
0038 #define FD_PERP 0x40
0039 
0040             spec1,      /* stepping rate, head unload time */
0041             fmt_gap;    /* gap2 size */
0042     const char  * name; /* used only for predefined formats */
0043 };
0044 
0045 
0046 /* commands needing write access have 0x40 set */
0047 /* commands needing super user access have 0x80 set */
0048 
0049 #define FDCLRPRM _IO(2, 0x41)
0050 /* clear user-defined parameters */
0051 
0052 #define FDSETPRM _IOW(2, 0x42, struct floppy_struct)
0053 #define FDSETMEDIAPRM FDSETPRM
0054 /* set user-defined parameters for current media */
0055 
0056 #define FDDEFPRM _IOW(2, 0x43, struct floppy_struct)
0057 #define FDGETPRM _IOR(2, 0x04, struct floppy_struct)
0058 #define FDDEFMEDIAPRM FDDEFPRM
0059 #define FDGETMEDIAPRM FDGETPRM
0060 /* set/get disk parameters */
0061 
0062 
0063 #define FDMSGON  _IO(2,0x45)
0064 #define FDMSGOFF _IO(2,0x46)
0065 /* issue/don't issue kernel messages on media type change */
0066 
0067 
0068 /*
0069  * Formatting (obsolete)
0070  */
0071 #define FD_FILL_BYTE 0xF6 /* format fill byte. */
0072 
0073 struct format_descr {
0074     unsigned int device,head,track;
0075 };
0076 
0077 #define FDFMTBEG _IO(2,0x47)
0078 /* begin formatting a disk */
0079 #define FDFMTTRK _IOW(2,0x48, struct format_descr)
0080 /* format the specified track */
0081 #define FDFMTEND _IO(2,0x49)
0082 /* end formatting a disk */
0083 
0084 
0085 /*
0086  * Error thresholds
0087  */
0088 struct floppy_max_errors {
0089     unsigned int
0090       abort,      /* number of errors to be reached before aborting */
0091       read_track, /* maximal number of errors permitted to read an
0092                * entire track at once */
0093       reset,      /* maximal number of errors before a reset is tried */
0094       recal,      /* maximal number of errors before a recalibrate is
0095                * tried */
0096 
0097       /*
0098        * Threshold for reporting FDC errors to the console.
0099        * Setting this to zero may flood your screen when using
0100        * ultra cheap floppies ;-)
0101        */
0102       reporting;
0103 
0104 };
0105 
0106 #define FDSETEMSGTRESH  _IO(2,0x4a)
0107 /* set fdc error reporting threshold */
0108 
0109 #define FDFLUSH  _IO(2,0x4b)
0110 /* flush buffers for media; either for verifying media, or for
0111  * handling a media change without closing the file descriptor */
0112 
0113 #define FDSETMAXERRS _IOW(2, 0x4c, struct floppy_max_errors)
0114 #define FDGETMAXERRS _IOR(2, 0x0e, struct floppy_max_errors)
0115 /* set/get abortion and read_track threshold. See also floppy_drive_params
0116  * structure */
0117 
0118 
0119 typedef char floppy_drive_name[16];
0120 #define FDGETDRVTYP _IOR(2, 0x0f, floppy_drive_name)
0121 /* get drive type: 5 1/4 or 3 1/2 */
0122 
0123 
0124 /*
0125  * Drive parameters (user modifiable)
0126  */
0127 struct floppy_drive_params {
0128     signed char cmos;       /* CMOS type */
0129 
0130     /* Spec2 is (HLD<<1 | ND), where HLD is head load time (1=2ms, 2=4 ms
0131      * etc) and ND is set means no DMA. Hardcoded to 6 (HLD=6ms, use DMA).
0132      */
0133     unsigned long max_dtr;      /* Step rate, usec */
0134     unsigned long hlt;          /* Head load/settle time, msec */
0135     unsigned long hut;          /* Head unload time (remnant of
0136                      * 8" drives) */
0137     unsigned long srt;          /* Step rate, usec */
0138 
0139     unsigned long spinup;       /* time needed for spinup (expressed
0140                      * in jiffies) */
0141     unsigned long spindown;     /* timeout needed for spindown */
0142     unsigned char spindown_offset;  /* decides in which position the disk
0143                      * will stop */
0144     unsigned char select_delay; /* delay to wait after select */
0145     unsigned char rps;      /* rotations per second */
0146     unsigned char tracks;       /* maximum number of tracks */
0147     unsigned long timeout;      /* timeout for interrupt requests */
0148 
0149     unsigned char interleave_sect;  /* if there are more sectors, use
0150                      * interleave */
0151 
0152     struct floppy_max_errors max_errors;
0153 
0154     char flags;         /* various flags, including ftd_msg */
0155 /*
0156  * Announce successful media type detection and media information loss after
0157  * disk changes.
0158  * Also used to enable/disable printing of overrun warnings.
0159  */
0160 
0161 #define FTD_MSG 0x10
0162 #define FD_BROKEN_DCL 0x20
0163 #define FD_DEBUG 0x02
0164 #define FD_SILENT_DCL_CLEAR 0x4
0165 #define FD_INVERTED_DCL 0x80 /* must be 0x80, because of hardware
0166                 considerations */
0167 
0168     char read_track;        /* use readtrack during probing? */
0169 
0170 /*
0171  * Auto-detection. Each drive type has eight formats which are
0172  * used in succession to try to read the disk. If the FDC cannot lock onto
0173  * the disk, the next format is tried. This uses the variable 'probing'.
0174  */
0175 
0176 #define FD_AUTODETECT_SIZE 8
0177 
0178     short autodetect[FD_AUTODETECT_SIZE]; /* autodetected formats */
0179 
0180     int checkfreq; /* how often should the drive be checked for disk
0181             * changes */
0182     int native_format; /* native format of this drive */
0183 };
0184 
0185 enum {
0186     FD_NEED_TWADDLE_BIT,    /* more magic */
0187     FD_VERIFY_BIT,      /* inquire for write protection */
0188     FD_DISK_NEWCHANGE_BIT,  /* change detected, and no action undertaken yet
0189                  * to clear media change status */
0190     FD_UNUSED_BIT,
0191     FD_DISK_CHANGED_BIT,    /* disk has been changed since last i/o */
0192     FD_DISK_WRITABLE_BIT,   /* disk is writable */
0193     FD_OPEN_SHOULD_FAIL_BIT
0194 };
0195 
0196 #define FDSETDRVPRM _IOW(2, 0x90, struct floppy_drive_params)
0197 #define FDGETDRVPRM _IOR(2, 0x11, struct floppy_drive_params)
0198 /* set/get drive parameters */
0199 
0200 
0201 /*
0202  * Current drive state (not directly modifiable by user, readonly)
0203  */
0204 struct floppy_drive_struct {
0205     unsigned long flags;
0206 /* values for these flags */
0207 #define FD_NEED_TWADDLE (1 << FD_NEED_TWADDLE_BIT)
0208 #define FD_VERIFY (1 << FD_VERIFY_BIT)
0209 #define FD_DISK_NEWCHANGE (1 << FD_DISK_NEWCHANGE_BIT)
0210 #define FD_DISK_CHANGED (1 << FD_DISK_CHANGED_BIT)
0211 #define FD_DISK_WRITABLE (1 << FD_DISK_WRITABLE_BIT)
0212 
0213     unsigned long spinup_date;
0214     unsigned long select_date;
0215     unsigned long first_read_date;
0216     short probed_format;
0217     short track; /* current track */
0218     short maxblock; /* id of highest block read */
0219     short maxtrack; /* id of highest half track read */
0220     int generation; /* how many diskchanges? */
0221 
0222 /*
0223  * (User-provided) media information is _not_ discarded after a media change
0224  * if the corresponding keep_data flag is non-zero. Positive values are
0225  * decremented after each probe.
0226  */
0227     int keep_data;
0228 
0229     /* Prevent "aliased" accesses. */
0230     int fd_ref;
0231     int fd_device;
0232     unsigned long last_checked; /* when was the drive last checked for a disk
0233                * change? */
0234 
0235     char *dmabuf;
0236     int bufblocks;
0237 };
0238 
0239 #define FDGETDRVSTAT _IOR(2, 0x12, struct floppy_drive_struct)
0240 #define FDPOLLDRVSTAT _IOR(2, 0x13, struct floppy_drive_struct)
0241 /* get drive state: GET returns the cached state, POLL polls for new state */
0242 
0243 
0244 /*
0245  * reset FDC
0246  */
0247 enum reset_mode {
0248     FD_RESET_IF_NEEDED, /* reset only if the reset flags is set */
0249     FD_RESET_IF_RAWCMD, /* obsolete */
0250     FD_RESET_ALWAYS     /* reset always */
0251 };
0252 #define FDRESET _IO(2, 0x54)
0253 
0254 
0255 /*
0256  * FDC state
0257  */
0258 struct floppy_fdc_state {
0259     int spec1;      /* spec1 value last used */
0260     int spec2;      /* spec2 value last used */
0261     int dtr;
0262     unsigned char version;  /* FDC version code */
0263     unsigned char dor;
0264     unsigned long address;  /* io address */
0265     unsigned int rawcmd:2;
0266     unsigned int reset:1;
0267     unsigned int need_configure:1;
0268     unsigned int perp_mode:2;
0269     unsigned int has_fifo:1;
0270     unsigned int driver_version;    /* version code for floppy driver */
0271 #define FD_DRIVER_VERSION 0x100
0272 /* user programs using the floppy API should use floppy_fdc_state to
0273  * get the version number of the floppy driver that they are running
0274  * on. If this version number is bigger than the one compiled into the
0275  * user program (the FD_DRIVER_VERSION define), it should be prepared
0276  * to bigger structures
0277  */
0278 
0279     unsigned char track[4];
0280     /* Position of the heads of the 4 units attached to this FDC,
0281      * as stored on the FDC. In the future, the position as stored
0282      * on the FDC might not agree with the actual physical
0283      * position of these drive heads. By allowing such
0284      * disagreement, it will be possible to reset the FDC without
0285      * incurring the expensive cost of repositioning all heads.
0286      * Right now, these positions are hard wired to 0. */
0287 
0288 };
0289 
0290 #define FDGETFDCSTAT _IOR(2, 0x15, struct floppy_fdc_state)
0291 
0292 
0293 /*
0294  * Asynchronous Write error tracking
0295  */
0296 struct floppy_write_errors {
0297     /* Write error logging.
0298      *
0299      * These fields can be cleared with the FDWERRORCLR ioctl.
0300      * Only writes that were attempted but failed due to a physical media
0301      * error are logged.  write(2) calls that fail and return an error code
0302      * to the user process are not counted.
0303      */
0304 
0305     unsigned int write_errors;  /* number of physical write errors
0306                      * encountered */
0307 
0308     /* position of first and last write errors */
0309     unsigned long first_error_sector;
0310     int           first_error_generation;
0311     unsigned long last_error_sector;
0312     int           last_error_generation;
0313 
0314     unsigned int badness; /* highest retry count for a read or write
0315                    * operation */
0316 };
0317 
0318 #define FDWERRORCLR  _IO(2, 0x56)
0319 /* clear write error and badness information */
0320 #define FDWERRORGET  _IOR(2, 0x17, struct floppy_write_errors)
0321 /* get write error and badness information */
0322 
0323 
0324 /*
0325  * Raw commands
0326  */
0327 /* new interface flag: now we can do them in batches */
0328 #define FDHAVEBATCHEDRAWCMD
0329 
0330 struct floppy_raw_cmd {
0331     unsigned int flags;
0332 #define FD_RAW_READ 1
0333 #define FD_RAW_WRITE 2
0334 #define FD_RAW_NO_MOTOR 4
0335 #define FD_RAW_DISK_CHANGE 4 /* out: disk change flag was set */
0336 #define FD_RAW_INTR 8    /* wait for an interrupt */
0337 #define FD_RAW_SPIN 0x10 /* spin up the disk for this command */
0338 #define FD_RAW_NO_MOTOR_AFTER 0x20 /* switch the motor off after command
0339                     * completion */
0340 #define FD_RAW_NEED_DISK 0x40  /* this command needs a disk to be present */
0341 #define FD_RAW_NEED_SEEK 0x80  /* this command uses an implied seek (soft) */
0342 
0343 /* more "in" flags */
0344 #define FD_RAW_MORE 0x100  /* more records follow */
0345 #define FD_RAW_STOP_IF_FAILURE 0x200 /* stop if we encounter a failure */
0346 #define FD_RAW_STOP_IF_SUCCESS 0x400 /* stop if command successful */
0347 #define FD_RAW_SOFTFAILURE 0x800 /* consider the return value for failure
0348                   * detection too */
0349 
0350 /* more "out" flags */
0351 #define FD_RAW_FAILURE 0x10000 /* command sent to fdc, fdc returned error */
0352 #define FD_RAW_HARDFAILURE 0x20000 /* fdc had to be reset, or timed out */
0353 
0354     void __user *data;
0355     char *kernel_data; /* location of data buffer in the kernel */
0356     struct floppy_raw_cmd *next; /* used for chaining of raw cmd's
0357                       * within the kernel */
0358     long length; /* in: length of dma transfer. out: remaining bytes */
0359     long phys_length; /* physical length, if different from dma length */
0360     int buffer_length; /* length of allocated buffer */
0361 
0362     unsigned char rate;
0363 
0364 #define FD_RAW_CMD_SIZE 16
0365 #define FD_RAW_REPLY_SIZE 16
0366 #define FD_RAW_CMD_FULLSIZE (FD_RAW_CMD_SIZE + 1 + FD_RAW_REPLY_SIZE)
0367 
0368     /* The command may take up the space initially intended for the reply
0369      * and the reply count. Needed for long 82078 commands such as RESTORE,
0370      * which takes 17 command bytes.
0371      */
0372 
0373     unsigned char cmd_count;
0374     union {
0375         struct {
0376             unsigned char cmd[FD_RAW_CMD_SIZE];
0377             unsigned char reply_count;
0378             unsigned char reply[FD_RAW_REPLY_SIZE];
0379         };
0380         unsigned char fullcmd[FD_RAW_CMD_FULLSIZE];
0381     };
0382     int track;
0383     int resultcode;
0384 
0385     int reserved1;
0386     int reserved2;
0387 };
0388 
0389 #define FDRAWCMD _IO(2, 0x58)
0390 /* send a raw command to the fdc. Structure size not included, because of
0391  * batches */
0392 
0393 #define FDTWADDLE _IO(2, 0x59)
0394 /* flicker motor-on bit before reading a sector. Experimental */
0395 
0396 
0397 #define FDEJECT _IO(2, 0x5a)
0398 /* eject the disk */
0399 
0400 
0401 
0402 #endif /* _UAPI_LINUX_FD_H */