fd.h 12 KB

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