fd.h 11 KB

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