[PATCH] floppy driver initialization

Andrzej Krzysztofowicz (ankry@green.mif.pg.gda.pl)
Mon, 24 Aug 1998 10:16:07 +0200 (CEST)


Hi,

1. While testing behaviour of floppy driver with different floppy controller
i/o addresses I found that it became in "uninitialized" state when no
floppy controller is found. It should cleanly unload. (kernels 2.1.117
& Alan's 2.0.36pre6)
2. Also, in 2.1.117 if only the secondary controller is present (no primary)
and "floppy=two_fdc" option is used driver still registers primary
controller's i/o addresses - and doesn't free them when unloaded causing
an oops during any attempt to access /proc/ioports.
3. In default_drive_params[] there is an incorrect format (11) among
autodetected formats for 5 1/4" 1.2M drive.

Ad 1.
While debugging the driver I found that wait_til_done() called from
user_reset_fdc() [WAIT(reset_fdc);] is locating a new task in tq_immediate
queue. This task is still waiting for execution when init_module() returns
with non-zero value (wait_til_done() awaken by timeout fails). So reserved
resources are freed after(!!!) init_module() returns.
Fixed by replacing deferred task's function by empty() and manually
freeing resources (patches for 2.1.117 & Alan's 2.0.36pre6 included).
I'm still not sure if the deffered task executes with properly
allocated code memory or not (the code memory can be already deallocated
by kernel as init_module() already returned) so it may need another fix
in future.

Ad 2.
In 2.1.117 floppy driver release_region()'s are moved to
floppy_release_irq_and_dma() and not executed if FDCS->address = -1 (for
not detected controllers). release_region() needs to be executed in each
case before FDCS->address is set to -1. Fixed in patches.

Ad 3.
Format 11 is 1.68MB 3.5" and should be replaced by any 5 1/4" or
removed by resetting to zero. Suggested change to format 12 (410KB 5.25")
in patches.

Regards
Andrzej

****************************************************************************
diff -u linux-2.1.117/drivers/block/floppy.c linux/drivers/block/floppy.c
--- linux-2.1.117/drivers/block/floppy.c Wed Jun 24 23:30:09 1998
+++ linux/drivers/block/floppy.c Sun Aug 23 23:15:24 1998
@@ -348,7 +348,7 @@
0, { 1, 0, 0, 0, 0, 0, 0, 0}, 3*HZ/2, 1 }, "360K PC" }, /*5 1/4 360 KB PC*/

{{2, 500, 16, 16, 6000, 4*HZ/10, 3*HZ, 14, SEL_DLY, 6, 83, 3*HZ, 17, {3,1,2,0,2}, 0,
- 0, { 2, 5, 6,23,10,20,11, 0}, 3*HZ/2, 2 }, "1.2M" }, /*5 1/4 HD AT*/
+ 0, { 2, 5, 6,23,10,20,12, 0}, 3*HZ/2, 2 }, "1.2M" }, /*5 1/4 HD AT*/

{{3, 250, 16, 16, 3000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 83, 3*HZ, 20, {3,1,2,0,2}, 0,
0, { 4,22,21,30, 3, 0, 0, 0}, 3*HZ/2, 4 }, "720k" }, /*3 1/2 DD*/
@@ -4107,6 +4107,7 @@
if (floppy_grab_irq_and_dma()){
unregister_blkdev(MAJOR_NR,"fd");
del_timer(&fd_timeout);
+ blk_dev[MAJOR_NR].request_fn = NULL;
return -EBUSY;
}

@@ -4129,6 +4130,9 @@
continue;
FDCS->rawcmd = 2;
if (user_reset_fdc(-1,FD_RESET_ALWAYS,0)){
+ /* free ioports reserved by floppy_grab_irq_and_dma() */
+ release_region(FDCS->address, 6);
+ release_region(FDCS->address+7, 1);
FDCS->address = -1;
FDCS->version = FDC_NONE;
continue;
@@ -4136,6 +4140,9 @@
/* Try to determine the floppy controller type */
FDCS->version = get_fdc_version();
if (FDCS->version == FDC_NONE){
+ /* free ioports reserved by floppy_grab_irq_and_dma() */
+ release_region(FDCS->address, 6);
+ release_region(FDCS->address+7, 1);
FDCS->address = -1;
continue;
}
@@ -4156,6 +4163,10 @@
initialising=0;
if (have_no_fdc) {
DPRINT("no floppy controllers found\n");
+ floppy_tq.routine = (void *)(void *) empty;
+ if (usage_count)
+ floppy_release_irq_and_dma();
+ blk_dev[MAJOR_NR].request_fn = NULL;
unregister_blkdev(MAJOR_NR,"fd");
}
return have_no_fdc;
******************************************************************************
diff -u linux-2.0.36pre6/drivers/block/floppy.c linux/drivers/block/floppy.c
--- linux-2.0.36pre6/drivers/block/floppy.c Thu Jun 4 00:17:47 1998
+++ linux/drivers/block/floppy.c Sun Aug 23 23:16:37 1998
@@ -328,7 +328,7 @@
0, { 1, 0, 0, 0, 0, 0, 0, 0}, 3*HZ/2, 1 }, "360K PC" }, /*5 1/4 360 KB PC*/

{{2, 500, 16, 16, 6000, 4*HZ/10, 3*HZ, 14, SEL_DLY, 6, 83, 3*HZ, 17, {3,1,2,0,2}, 0,
- 0, { 2, 5, 6,23,10,20,11, 0}, 3*HZ/2, 2 }, "1.2M" }, /*5 1/4 HD AT*/
+ 0, { 2, 5, 6,23,10,20,12, 0}, 3*HZ/2, 2 }, "1.2M" }, /*5 1/4 HD AT*/

{{3, 250, 16, 16, 3000, 1*HZ, 3*HZ, 0, SEL_DLY, 5, 83, 3*HZ, 20, {3,1,2,0,2}, 0,
0, { 4,22,21,30, 3, 0, 0, 0}, 3*HZ/2, 4 }, "720k" }, /*3 1/2 DD*/
@@ -3989,6 +3989,8 @@
#endif

if (floppy_grab_irq_and_dma()){
+ del_timer(&fd_timeout);
+ blk_dev[MAJOR_NR].request_fn = NULL;
unregister_blkdev(MAJOR_NR,"fd");
return -EBUSY;
}
@@ -4042,6 +4044,10 @@
initialising=0;
if (have_no_fdc) {
DPRINT("no floppy controllers found\n");
+ request_tq.routine = (void *)(void *) empty;
+ if (usage_count)
+ floppy_release_irq_and_dma();
+ blk_dev[MAJOR_NR].request_fn = NULL;
unregister_blkdev(MAJOR_NR,"fd");
}
return have_no_fdc;
***********************************************************************

-- 
=======================================================================
  Andrzej M. Krzysztofowicz               ankry@mif.pg.gda.pl
  phone (48)(58) 347 14 61
Faculty of Applied Phys. & Math.,   Technical University of Gdansk

- To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to majordomo@vger.rutgers.edu Please read the FAQ at http://www.altern.org/andrebalsa/doc/lkml-faq.html