@@ -551,7 +551,7 @@ static void floppy_ready(void);
551551static void floppy_start (void );
552552static void process_fd_request (void );
553553static void recalibrate_floppy (void );
554- static void floppy_shutdown (unsigned long );
554+ static void floppy_shutdown (struct work_struct * );
555555
556556static int floppy_request_regions (int );
557557static void floppy_release_regions (int );
@@ -588,6 +588,8 @@ static int buffer_max = -1;
588588static struct floppy_fdc_state fdc_state [N_FDC ];
589589static int fdc ; /* current fdc */
590590
591+ static struct workqueue_struct * floppy_wq ;
592+
591593static struct floppy_struct * _floppy = floppy_type ;
592594static unsigned char current_drive ;
593595static long current_count_sectors ;
@@ -629,16 +631,15 @@ static inline void set_debugt(void) { }
629631static inline void debugt (const char * func , const char * msg ) { }
630632#endif /* DEBUGT */
631633
632- typedef void (* timeout_fn )(unsigned long );
633- static DEFINE_TIMER (fd_timeout , floppy_shutdown , 0 , 0 ) ;
634634
635+ static DECLARE_DELAYED_WORK (fd_timeout , floppy_shutdown ) ;
635636static const char * timeout_message ;
636637
637638static void is_alive (const char * func , const char * message )
638639{
639640 /* this routine checks whether the floppy driver is "alive" */
640641 if (test_bit (0 , & fdc_busy ) && command_status < 2 &&
641- !timer_pending (& fd_timeout )) {
642+ !delayed_work_pending (& fd_timeout )) {
642643 DPRINT ("%s: timeout handler died. %s\n" , func , message );
643644 }
644645}
@@ -666,15 +667,18 @@ static int output_log_pos;
666667
667668static void __reschedule_timeout (int drive , const char * message )
668669{
670+ unsigned long delay ;
671+
669672 if (drive == current_reqD )
670673 drive = current_drive ;
671- del_timer ( & fd_timeout );
674+
672675 if (drive < 0 || drive >= N_DRIVE ) {
673- fd_timeout . expires = jiffies + 20UL * HZ ;
676+ delay = 20UL * HZ ;
674677 drive = 0 ;
675678 } else
676- fd_timeout .expires = jiffies + UDP -> timeout ;
677- add_timer (& fd_timeout );
679+ delay = UDP -> timeout ;
680+
681+ queue_delayed_work (floppy_wq , & fd_timeout , delay );
678682 if (UDP -> flags & FD_DEBUG )
679683 DPRINT ("reschedule timeout %s\n" , message );
680684 timeout_message = message ;
@@ -872,31 +876,23 @@ static int lock_fdc(int drive, bool interruptible)
872876
873877 command_status = FD_COMMAND_NONE ;
874878
875- __reschedule_timeout (drive , "lock fdc" );
879+ reschedule_timeout (drive , "lock fdc" );
876880 set_fdc (drive );
877881 return 0 ;
878882}
879883
880884/* unlocks the driver */
881885static void unlock_fdc (void )
882886{
883- unsigned long flags ;
884-
885- raw_cmd = NULL ;
886887 if (!test_bit (0 , & fdc_busy ))
887888 DPRINT ("FDC access conflict!\n" );
888889
889- if (do_floppy )
890- DPRINT ("device interrupt still active at FDC release: %pf!\n" ,
891- do_floppy );
890+ raw_cmd = NULL ;
892891 command_status = FD_COMMAND_NONE ;
893- spin_lock_irqsave ( & floppy_lock , flags );
894- del_timer ( & fd_timeout ) ;
892+ __cancel_delayed_work ( & fd_timeout );
893+ do_floppy = NULL ;
895894 cont = NULL ;
896895 clear_bit (0 , & fdc_busy );
897- if (current_req || set_next_request ())
898- do_fd_request (current_req -> q );
899- spin_unlock_irqrestore (& floppy_lock , flags );
900896 wake_up (& fdc_wait );
901897}
902898
@@ -968,26 +964,24 @@ static DECLARE_WORK(floppy_work, NULL);
968964
969965static void schedule_bh (void (* handler )(void ))
970966{
967+ WARN_ON (work_pending (& floppy_work ));
968+
971969 PREPARE_WORK (& floppy_work , (work_func_t )handler );
972- schedule_work ( & floppy_work );
970+ queue_work ( floppy_wq , & floppy_work );
973971}
974972
975- static DEFINE_TIMER (fd_timer , NULL, 0 , 0 ) ;
973+ static DECLARE_DELAYED_WORK (fd_timer , NULL) ;
976974
977975static void cancel_activity (void )
978976{
979- unsigned long flags ;
980-
981- spin_lock_irqsave (& floppy_lock , flags );
982977 do_floppy = NULL ;
983- PREPARE_WORK (& floppy_work , (work_func_t )empty );
984- del_timer (& fd_timer );
985- spin_unlock_irqrestore (& floppy_lock , flags );
978+ cancel_delayed_work_sync (& fd_timer );
979+ cancel_work_sync (& floppy_work );
986980}
987981
988982/* this function makes sure that the disk stays in the drive during the
989983 * transfer */
990- static void fd_watchdog (void )
984+ static void fd_watchdog (struct work_struct * arg )
991985{
992986 debug_dcl (DP -> flags , "calling disk change from watchdog\n" );
993987
@@ -997,21 +991,20 @@ static void fd_watchdog(void)
997991 cont -> done (0 );
998992 reset_fdc ();
999993 } else {
1000- del_timer (& fd_timer );
1001- fd_timer .function = (timeout_fn )fd_watchdog ;
1002- fd_timer .expires = jiffies + HZ / 10 ;
1003- add_timer (& fd_timer );
994+ cancel_delayed_work (& fd_timer );
995+ PREPARE_DELAYED_WORK (& fd_timer , fd_watchdog );
996+ queue_delayed_work (floppy_wq , & fd_timer , HZ / 10 );
1004997 }
1005998}
1006999
10071000static void main_command_interrupt (void )
10081001{
1009- del_timer (& fd_timer );
1002+ cancel_delayed_work (& fd_timer );
10101003 cont -> interrupt ();
10111004}
10121005
10131006/* waits for a delay (spinup or select) to pass */
1014- static int fd_wait_for_completion (unsigned long delay , timeout_fn function )
1007+ static int fd_wait_for_completion (unsigned long expires , work_func_t function )
10151008{
10161009 if (FDCS -> reset ) {
10171010 reset_fdc (); /* do the reset during sleep to win time
@@ -1020,11 +1013,10 @@ static int fd_wait_for_completion(unsigned long delay, timeout_fn function)
10201013 return 1 ;
10211014 }
10221015
1023- if (time_before (jiffies , delay )) {
1024- del_timer (& fd_timer );
1025- fd_timer .function = function ;
1026- fd_timer .expires = delay ;
1027- add_timer (& fd_timer );
1016+ if (time_before (jiffies , expires )) {
1017+ cancel_delayed_work (& fd_timer );
1018+ PREPARE_DELAYED_WORK (& fd_timer , function );
1019+ queue_delayed_work (floppy_wq , & fd_timer , expires - jiffies );
10281020 return 1 ;
10291021 }
10301022 return 0 ;
@@ -1342,7 +1334,7 @@ static int fdc_dtr(void)
13421334 */
13431335 FDCS -> dtr = raw_cmd -> rate & 3 ;
13441336 return fd_wait_for_completion (jiffies + 2UL * HZ / 100 ,
1345- (timeout_fn )floppy_ready );
1337+ (work_func_t )floppy_ready );
13461338} /* fdc_dtr */
13471339
13481340static void tell_sector (void )
@@ -1447,7 +1439,7 @@ static void setup_rw_floppy(void)
14471439 int flags ;
14481440 int dflags ;
14491441 unsigned long ready_date ;
1450- timeout_fn function ;
1442+ work_func_t function ;
14511443
14521444 flags = raw_cmd -> flags ;
14531445 if (flags & (FD_RAW_READ | FD_RAW_WRITE ))
@@ -1461,9 +1453,9 @@ static void setup_rw_floppy(void)
14611453 */
14621454 if (time_after (ready_date , jiffies + DP -> select_delay )) {
14631455 ready_date -= DP -> select_delay ;
1464- function = (timeout_fn )floppy_start ;
1456+ function = (work_func_t )floppy_start ;
14651457 } else
1466- function = (timeout_fn )setup_rw_floppy ;
1458+ function = (work_func_t )setup_rw_floppy ;
14671459
14681460 /* wait until the floppy is spinning fast enough */
14691461 if (fd_wait_for_completion (ready_date , function ))
@@ -1493,7 +1485,7 @@ static void setup_rw_floppy(void)
14931485 inr = result ();
14941486 cont -> interrupt ();
14951487 } else if (flags & FD_RAW_NEED_DISK )
1496- fd_watchdog ();
1488+ fd_watchdog (NULL );
14971489}
14981490
14991491static int blind_seek ;
@@ -1802,20 +1794,22 @@ static void show_floppy(void)
18021794 pr_info ("do_floppy=%pf\n" , do_floppy );
18031795 if (work_pending (& floppy_work ))
18041796 pr_info ("floppy_work.func=%pf\n" , floppy_work .func );
1805- if (timer_pending (& fd_timer ))
1806- pr_info ("fd_timer.function=%pf\n" , fd_timer .function );
1807- if (timer_pending (& fd_timeout )) {
1808- pr_info ("timer_function=%pf\n" , fd_timeout .function );
1809- pr_info ("expires=%lu\n" , fd_timeout .expires - jiffies );
1810- pr_info ("now=%lu\n" , jiffies );
1811- }
1797+ if (delayed_work_pending (& fd_timer ))
1798+ pr_info ("delayed work.function=%p expires=%ld\n" ,
1799+ fd_timer .work .func ,
1800+ fd_timer .timer .expires - jiffies );
1801+ if (delayed_work_pending (& fd_timeout ))
1802+ pr_info ("timer_function=%p expires=%ld\n" ,
1803+ fd_timeout .work .func ,
1804+ fd_timeout .timer .expires - jiffies );
1805+
18121806 pr_info ("cont=%p\n" , cont );
18131807 pr_info ("current_req=%p\n" , current_req );
18141808 pr_info ("command_status=%d\n" , command_status );
18151809 pr_info ("\n" );
18161810}
18171811
1818- static void floppy_shutdown (unsigned long data )
1812+ static void floppy_shutdown (struct work_struct * arg )
18191813{
18201814 unsigned long flags ;
18211815
@@ -1868,7 +1862,7 @@ static int start_motor(void (*function)(void))
18681862
18691863 /* wait_for_completion also schedules reset if needed. */
18701864 return fd_wait_for_completion (DRS -> select_date + DP -> select_delay ,
1871- (timeout_fn )function );
1865+ (work_func_t )function );
18721866}
18731867
18741868static void floppy_ready (void )
@@ -2821,7 +2815,6 @@ static void redo_fd_request(void)
28212815 spin_lock_irq (& floppy_lock );
28222816 pending = set_next_request ();
28232817 spin_unlock_irq (& floppy_lock );
2824-
28252818 if (!pending ) {
28262819 do_floppy = NULL ;
28272820 unlock_fdc ();
@@ -2898,13 +2891,15 @@ static void do_fd_request(struct request_queue *q)
28982891 current_req -> cmd_flags ))
28992892 return ;
29002893
2901- if (test_bit (0 , & fdc_busy )) {
2894+ if (test_and_set_bit (0 , & fdc_busy )) {
29022895 /* fdc busy, this new request will be treated when the
29032896 current one is done */
29042897 is_alive (__func__ , "old request running" );
29052898 return ;
29062899 }
2907- lock_fdc (MAXTIMEOUT , false);
2900+ command_status = FD_COMMAND_NONE ;
2901+ __reschedule_timeout (MAXTIMEOUT , "fd_request" );
2902+ set_fdc (0 );
29082903 process_fd_request ();
29092904 is_alive (__func__ , "" );
29102905}
@@ -4159,10 +4154,16 @@ static int __init floppy_init(void)
41594154 goto out_put_disk ;
41604155 }
41614156
4157+ floppy_wq = alloc_ordered_workqueue ("floppy" , 0 );
4158+ if (!floppy_wq ) {
4159+ err = - ENOMEM ;
4160+ goto out_put_disk ;
4161+ }
4162+
41624163 disks [dr ]-> queue = blk_init_queue (do_fd_request , & floppy_lock );
41634164 if (!disks [dr ]-> queue ) {
41644165 err = - ENOMEM ;
4165- goto out_put_disk ;
4166+ goto out_destroy_workq ;
41664167 }
41674168
41684169 blk_queue_max_hw_sectors (disks [dr ]-> queue , 64 );
@@ -4213,7 +4214,7 @@ static int __init floppy_init(void)
42134214 use_virtual_dma = can_use_virtual_dma & 1 ;
42144215 fdc_state [0 ].address = FDC1 ;
42154216 if (fdc_state [0 ].address == -1 ) {
4216- del_timer_sync (& fd_timeout );
4217+ cancel_delayed_work (& fd_timeout );
42174218 err = - ENODEV ;
42184219 goto out_unreg_region ;
42194220 }
@@ -4224,7 +4225,7 @@ static int __init floppy_init(void)
42244225 fdc = 0 ; /* reset fdc in case of unexpected interrupt */
42254226 err = floppy_grab_irq_and_dma ();
42264227 if (err ) {
4227- del_timer_sync (& fd_timeout );
4228+ cancel_delayed_work (& fd_timeout );
42284229 err = - EBUSY ;
42294230 goto out_unreg_region ;
42304231 }
@@ -4281,13 +4282,13 @@ static int __init floppy_init(void)
42814282 user_reset_fdc (-1 , FD_RESET_ALWAYS , false);
42824283 }
42834284 fdc = 0 ;
4284- del_timer_sync (& fd_timeout );
4285+ cancel_delayed_work (& fd_timeout );
42854286 current_drive = 0 ;
42864287 initialized = true;
42874288 if (have_no_fdc ) {
42884289 DPRINT ("no floppy controllers found\n" );
42894290 err = have_no_fdc ;
4290- goto out_flush_work ;
4291+ goto out_release_dma ;
42914292 }
42924293
42934294 for (drive = 0 ; drive < N_DRIVE ; drive ++ ) {
@@ -4302,7 +4303,7 @@ static int __init floppy_init(void)
43024303
43034304 err = platform_device_register (& floppy_device [drive ]);
43044305 if (err )
4305- goto out_flush_work ;
4306+ goto out_release_dma ;
43064307
43074308 err = device_create_file (& floppy_device [drive ].dev ,
43084309 & dev_attr_cmos );
@@ -4320,13 +4321,14 @@ static int __init floppy_init(void)
43204321
43214322out_unreg_platform_dev :
43224323 platform_device_unregister (& floppy_device [drive ]);
4323- out_flush_work :
4324- flush_work_sync (& floppy_work );
4324+ out_release_dma :
43254325 if (atomic_read (& usage_count ))
43264326 floppy_release_irq_and_dma ();
43274327out_unreg_region :
43284328 blk_unregister_region (MKDEV (FLOPPY_MAJOR , 0 ), 256 );
43294329 platform_driver_unregister (& floppy_driver );
4330+ out_destroy_workq :
4331+ destroy_workqueue (floppy_wq );
43304332out_unreg_blkdev :
43314333 unregister_blkdev (FLOPPY_MAJOR , "fd" );
43324334out_put_disk :
@@ -4397,7 +4399,7 @@ static int floppy_grab_irq_and_dma(void)
43974399 * We might have scheduled a free_irq(), wait it to
43984400 * drain first:
43994401 */
4400- flush_work_sync ( & floppy_work );
4402+ flush_workqueue ( floppy_wq );
44014403
44024404 if (fd_request_irq ()) {
44034405 DPRINT ("Unable to grab IRQ%d for the floppy driver\n" ,
@@ -4488,9 +4490,9 @@ static void floppy_release_irq_and_dma(void)
44884490 pr_info ("motor off timer %d still active\n" , drive );
44894491#endif
44904492
4491- if (timer_pending (& fd_timeout ))
4493+ if (delayed_work_pending (& fd_timeout ))
44924494 pr_info ("floppy timer still active:%s\n" , timeout_message );
4493- if (timer_pending (& fd_timer ))
4495+ if (delayed_work_pending (& fd_timer ))
44944496 pr_info ("auxiliary floppy timer still active\n" );
44954497 if (work_pending (& floppy_work ))
44964498 pr_info ("work still pending\n" );
@@ -4560,8 +4562,9 @@ static void __exit floppy_module_exit(void)
45604562 put_disk (disks [drive ]);
45614563 }
45624564
4563- del_timer_sync (& fd_timeout );
4564- del_timer_sync (& fd_timer );
4565+ cancel_delayed_work_sync (& fd_timeout );
4566+ cancel_delayed_work_sync (& fd_timer );
4567+ destroy_workqueue (floppy_wq );
45654568
45664569 if (atomic_read (& usage_count ))
45674570 floppy_release_irq_and_dma ();
0 commit comments