home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / os / linux / 20131 < prev    next >
Encoding:
Text File  |  1992-12-12  |  10.6 KB  |  304 lines

  1. Organization: Sophomore, Math/Computer Science, Carnegie Mellon, Pittsburgh, PA
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!darwin.sura.net!news.udel.edu!udel!rochester!cantaloupe.srv.cs.cmu.edu!crabapple.srv.cs.cmu.edu!andrew.cmu.edu!fl0p+
  3. Newsgroups: comp.os.linux
  4. Message-ID: <gf_czJ_00awOQX_kME@andrew.cmu.edu>
  5. Date: Sat, 12 Dec 1992 20:20:21 -0500 
  6. From: Frank T Lofaro <fl0p+@andrew.cmu.edu>
  7. Keywords: 0.98.6, patch, kernel, floppy, disk, enhancements, fixes, 82077
  8. Subject: ALPHA PATCH (for 0.98.6 kernel) for floppy disk enhancements/bug fixes.
  9. Lines: 293
  10.  
  11.     This patch is against linux 0.98 patchlevel 6. (It *should* work with
  12. other versions that are reasonably close). This enables and fixes the
  13. enhanced mode support for 82077 type floppy disk controllers, and also
  14. configures the floppy controller right after bootup, which might help
  15. with possible initialization problems (the floppy.c file states
  16. something about being unable to format floppies right after bootup. I
  17. haven't had that problem myself though, so I can not say any more about
  18. that.)
  19.     Anyway, this patch is mostly for those that have an enhanced floppy
  20. disk controller (the kernel reports FDC version 0x90 at bootup), and
  21. those that want to get as much performance out of their system as
  22. possible. But it shouldn't cause trouble for others, and might actually
  23. be helpful. (plus if it breaks anything for anyone, it would be good to
  24. know that.) I have tested all this code myself, and it seems to work for
  25. me. You may or may not need the #define FDC_FIFO_HACK. (I don't know why
  26. my machine needs it, or whether it is normal, or whether the hack is the
  27. best way to solve the problem, but without it, my kernel gets stuck in
  28. an infinite try to send byte, reset controller loop). You can also try
  29. changing the FDC_RATE_CONTROL #define to 0x00 if this patch doesn't work
  30. for you, or to 0x43 if you want to up the speed (but it might not work
  31. at that setting, sync before using the floppy, since the kernel might
  32. get stuck).
  33.     Sorry I can not provide more info, but my only docs are the kernel sources.
  34.     Anyway, here is the patch , to be applied to the root of your kernel
  35. source directory. (usually /usr/src/linux).
  36.  
  37. *** kernel/blk_drv/floppy.c.orig    Sun Nov 29 22:41:34 1992
  38. --- kernel/blk_drv/floppy.c    Sat Dec 12 03:01:47 1992
  39. ***************
  40. *** 53,65 ****
  41.    * modelled after the freeware MS/DOS program fdformat/88 V1.8 by 
  42.    * Christoph H. Hochst\"atter.
  43.    * I have fixed the shift values to the ones I always use. Maybe a new
  44.    * ioctl() should be created to be able to modify them.
  45. !  * There is a bug in the driver that makes it impossible to format a
  46.    * floppy as the first thing after bootup.
  47.    */
  48.   
  49.   #define REALLY_SLOW_IO
  50.   #define FLOPPY_IRQ 6
  51.   #define FLOPPY_DMA 2
  52.   
  53.   #include <linux/sched.h>
  54. --- 53,73 ----
  55.    * modelled after the freeware MS/DOS program fdformat/88 V1.8 by 
  56.    * Christoph H. Hochst\"atter.
  57.    * I have fixed the shift values to the ones I always use. Maybe a new
  58.    * ioctl() should be created to be able to modify them.
  59. !  * There might be a bug in the driver that makes it impossible to format a
  60.    * floppy as the first thing after bootup.
  61.    */
  62.   
  63.   #define REALLY_SLOW_IO
  64. + #define FDC_FIFO_EXPERIMENTAL
  65. + #define FDC_RATE_CONTROL 0x40 /* bit 6: 1=perpendicular mode enabled, 
  66. +                                  0=disabled. 0x00 is conventional mode, 
  67. +                                  0x40 is perpendicular 500 kbps, 
  68. +                                  0x43 is perpendicular 1 Mpbs. */
  69. + #define FDC_FIFO_HACK /* This might not be needed for everyone, but without 
  70. +                          it on some machines it can not send bytes to
  71. the FDC 
  72. +                          if using enhanced modes. */
  73.   #define FLOPPY_IRQ 6
  74.   #define FLOPPY_DMA 2
  75.   
  76.   #include <linux/sched.h>
  77. ***************
  78. *** 406,413 ****
  79. --- 414,442 ----
  80.       reset = 1;
  81.       printk("Unable to send byte to FDC\n");
  82.   }
  83.   
  84. + #ifdef FDC_FIFO_HACK
  85. + static void output_byte_force(char byte)
  86. + {
  87. +         int counter;
  88. +         unsigned char status;
  89. +         if (reset)
  90. +                 return;
  91. +         for(counter = 0 ; counter < 10000 ; counter++) {
  92. +                 status = inb_p(FD_STATUS) & (STATUS_READY);
  93. +                 if (status == STATUS_READY) {
  94. +                         outb(byte,FD_DATA);
  95. +                         return;
  96. +                 }
  97. +         }
  98. +         current_track = NO_TRACK;
  99. +         reset = 1;
  100. +         printk("Unable to send byte to FDC\n");
  101. + }
  102. + #endif
  103.   static int result(void)
  104.   {
  105.       int i = 0, counter, status;
  106.   
  107. ***************
  108. *** 456,464 ****
  109.   }    
  110.   
  111.   
  112.   /* Set perpendicular mode as required, based on data rate, if supported.
  113. !  * 82077 Untested! 1Mbps data rate only possible with 82077-1.
  114.    * TODO: increase MAX_BUFFER_SECTORS, add floppy_type entries.
  115.    */
  116.   static inline void perpendicular_mode(unsigned char rate)
  117.   {
  118. --- 485,493 ----
  119.   }    
  120.   
  121.   
  122.   /* Set perpendicular mode as required, based on data rate, if supported.
  123. !  * 82077 Not well tested! 1Mbps data rate only possible with 82077-1.
  124.    * TODO: increase MAX_BUFFER_SECTORS, add floppy_type entries.
  125.    */
  126.   static inline void perpendicular_mode(unsigned char rate)
  127.   {
  128. ***************
  129. *** 465,482 ****
  130.       if (fdc_version == FDC_TYPE_82077) {
  131.           output_byte(FD_PERPENDICULAR);
  132.           if (rate & 0x40) {
  133.               unsigned char r = rate & 0x03;
  134. !             if (r == 0)
  135.                   output_byte(2);    /* perpendicular, 500 kbps */
  136. !             else if (r == 3)
  137.                   output_byte(3);    /* perpendicular, 1Mbps */
  138.               else {
  139.                   printk(DEVICE_NAME ": Invalid data rate for perpendicular mode!\n");
  140.                   reset = 1;
  141.               }
  142. !         } else
  143.               output_byte(0);        /* conventional mode */
  144.       } else {
  145.           if (rate & 0x40) {
  146.               printk(DEVICE_NAME ": perpendicular mode not supported by this FDC.\n");
  147.               reset = 1;
  148. --- 494,534 ----
  149.       if (fdc_version == FDC_TYPE_82077) {
  150.           output_byte(FD_PERPENDICULAR);
  151.           if (rate & 0x40) {
  152.               unsigned char r = rate & 0x03;
  153. !             if (r == 0) {
  154. !                     if (need_configure) 
  155. !                         printk("floppy: perpendicular mode, 500 Kbps enabled.\n");
  156. ! #ifndef FDC_FIFO_HACK
  157.                   output_byte(2);    /* perpendicular, 500 kbps */
  158. ! #else
  159. !                 output_byte_force(2); /* perpendicular, 500 
  160. !                                                          kbps */
  161. ! #endif
  162. !                   }
  163. !             else if (r == 3) {
  164. !                     if (need_configure)
  165. !                             printk("floppy: perpendicular mode, 1 Mbps enabled.\n");
  166. ! #ifndef FDC_FIFO_HACK
  167.                   output_byte(3);    /* perpendicular, 1Mbps */
  168. + #else
  169. +                 output_byte_force(3); /* perpendicular, 
  170. +                                                          1Mbps */
  171. + #endif
  172. +                   }
  173.               else {
  174.                   printk(DEVICE_NAME ": Invalid data rate for perpendicular mode!\n");
  175.                   reset = 1;
  176.               }
  177. !     } else {
  178. !                 if (need_configure)
  179. !                         printk("floppy: conventional mode for 82077 FDC
  180. selected.\n");
  181. ! #ifndef FDC_FIFO_HACK
  182.               output_byte(0);        /* conventional mode */
  183. + #else
  184. +             output_byte_force(0); /* conventional mode */
  185. + #endif
  186. +               }
  187.       } else {
  188.           if (rate & 0x40) {
  189.               printk(DEVICE_NAME ": perpendicular mode not supported by this FDC.\n");
  190.               reset = 1;
  191. ***************
  192. *** 485,506 ****
  193.   } /* perpendicular_mode */
  194.   
  195.   
  196.   /*
  197. !  * This has only been tested for the case fdc_version == FDC_TYPE_STD.
  198.    * In case you have a 82077 and want to test it, you'll have to compile
  199. !  * with `FDC_FIFO_UNTESTED' defined. You may also want to add support for
  200.    * recognizing drives with vertical recording support.
  201.    */
  202.   static void configure_fdc_mode(void)
  203.   {
  204.       if (need_configure && (fdc_version == FDC_TYPE_82077)) {
  205.           /* Enhanced version with FIFO & vertical recording. */
  206.           output_byte(FD_CONFIGURE);
  207.           output_byte(0);
  208.           output_byte(0x1A);    /* FIFO on, polling off, 10 byte threshold */
  209.           output_byte(0);        /* precompensation from track 0 upwards */
  210. !         need_configure = 0;
  211.           printk(DEVICE_NAME ": FIFO enabled\n");
  212.       }
  213.       if (cur_spec1 != floppy->spec1) {
  214.           cur_spec1 = floppy->spec1;
  215. --- 537,566 ----
  216.   } /* perpendicular_mode */
  217.   
  218.   
  219.   /*
  220. !  * This has only been well tested for the case fdc_version == FDC_TYPE_STD.
  221.    * In case you have a 82077 and want to test it, you'll have to compile
  222. !  * with `FDC_FIFO_EXPERIMENTAL' defined. You may also want to add support for
  223.    * recognizing drives with vertical recording support.
  224.    */
  225.   static void configure_fdc_mode(void)
  226.   {
  227.       if (need_configure && (fdc_version == FDC_TYPE_82077)) {
  228.           /* Enhanced version with FIFO & vertical recording. */
  229.           output_byte(FD_CONFIGURE);
  230. + #ifndef FDC_FIFO_HACK
  231.           output_byte(0);
  232. + #else
  233. +         output_byte_force(0);
  234. + #endif
  235.           output_byte(0x1A);    /* FIFO on, polling off, 10 byte threshold */
  236. + #ifndef FDC_FIFO_HACK
  237.           output_byte(0);        /* precompensation from track 0 upwards */
  238. ! #else
  239. !         output_byte_force(0);    /* precompensation from track 0 
  240. !                                            upwards */
  241. ! #endif
  242.           printk(DEVICE_NAME ": FIFO enabled\n");
  243.       }
  244.       if (cur_spec1 != floppy->spec1) {
  245.           cur_spec1 = floppy->spec1;
  246. ***************
  247. *** 509,518 ****
  248. --- 569,582 ----
  249.           output_byte(6);            /* Head load time =6ms, DMA */
  250.       }
  251.       if (cur_rate != floppy->rate) {
  252.           /* use bit 6 of floppy->rate to indicate perpendicular mode */
  253. + #ifdef FDC_FIFO_EXPERIMENTAL
  254. +             floppy->rate=FDC_RATE_CONTROL;
  255. + #endif
  256.           perpendicular_mode(floppy->rate);
  257.           outb_p((cur_rate = (floppy->rate)) & ~0x40, FD_DCR);
  258. +         need_configure = 0;
  259.       }
  260.   } /* configure_fdc_mode */
  261.   
  262.   
  263. ***************
  264. *** 1273,1283 ****
  265.           printk(DEVICE_NAME ": FDC failed to return version byte\n");
  266.           fdc_version = FDC_TYPE_STD;
  267.       } else
  268.           fdc_version = reply_buffer[0];
  269. !     if (fdc_version != FDC_TYPE_STD) 
  270.           printk(DEVICE_NAME ": FDC version 0x%x\n", fdc_version);
  271. ! #ifndef FDC_FIFO_UNTESTED
  272.       fdc_version = FDC_TYPE_STD;    /* force std fdc type; can't test other. */
  273.   #endif
  274.   
  275.       /* Not all FDCs seem to be able to handle the version command
  276. --- 1337,1349 ----
  277.           printk(DEVICE_NAME ": FDC failed to return version byte\n");
  278.           fdc_version = FDC_TYPE_STD;
  279.       } else
  280.           fdc_version = reply_buffer[0];
  281. !     if (fdc_version == FDC_TYPE_82077)
  282. !             printk(DEVICE_NAME ": FDC version 0x%x (82077 Enhanced
  283. FDC)\n", fdc_version);
  284. !     if ((fdc_version != FDC_TYPE_STD) && (fdc_version != FDC_TYPE_82077)) 
  285.           printk(DEVICE_NAME ": FDC version 0x%x\n", fdc_version);
  286. ! #ifndef FDC_FIFO_EXPERIMENTAL
  287.       fdc_version = FDC_TYPE_STD;    /* force std fdc type; can't test other. */
  288.   #endif
  289.   
  290.       /* Not all FDCs seem to be able to handle the version command
  291. ***************
  292. *** 1288,1292 ****
  293. --- 1354,1360 ----
  294.       if (fdc_version == FDC_TYPE_STD) {
  295.           initial_reset_flag = 1;
  296.           reset_floppy();
  297.       }
  298. +     configure_fdc_mode(); /* It is a good idea to take care of this now, 
  299. +                                  82077 FDC or not. */
  300.   }
  301.  
  302.