hc
2024-05-14 bedbef8ad3e75a304af6361af235302bcc61d06b
kernel/drivers/block/floppy.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * linux/drivers/block/floppy.c
34 *
....@@ -170,7 +171,6 @@
170171 #include <linux/kernel.h>
171172 #include <linux/timer.h>
172173 #include <linux/workqueue.h>
173
-#define FDPATCHES
174174 #include <linux/fdreg.h>
175175 #include <linux/fd.h>
176176 #include <linux/hdreg.h>
....@@ -252,13 +252,13 @@
252252
253253 static int irqdma_allocated;
254254
255
-#include <linux/blkdev.h>
255
+#include <linux/blk-mq.h>
256256 #include <linux/blkpg.h>
257257 #include <linux/cdrom.h> /* for the compatibility eject ioctl */
258258 #include <linux/completion.h>
259259
260
+static LIST_HEAD(floppy_reqs);
260261 static struct request *current_req;
261
-static void do_fd_request(struct request_queue *q);
262262 static int set_next_request(void);
263263
264264 #ifndef fd_get_dma_residue
....@@ -305,36 +305,26 @@
305305 /* reverse mapping from unit and fdc to drive */
306306 #define REVDRIVE(fdc, unit) ((unit) + ((fdc) << 2))
307307
308
-#define DP (&drive_params[current_drive])
309
-#define DRS (&drive_state[current_drive])
310
-#define DRWE (&write_errors[current_drive])
311
-#define FDCS (&fdc_state[fdc])
312
-
313
-#define UDP (&drive_params[drive])
314
-#define UDRS (&drive_state[drive])
315
-#define UDRWE (&write_errors[drive])
316
-#define UFDCS (&fdc_state[FDC(drive)])
317
-
318308 #define PH_HEAD(floppy, head) (((((floppy)->stretch & 2) >> 1) ^ head) << 2)
319309 #define STRETCH(floppy) ((floppy)->stretch & FD_STRETCH)
320310
321
-/* read/write */
322
-#define COMMAND (raw_cmd->cmd[0])
323
-#define DR_SELECT (raw_cmd->cmd[1])
324
-#define TRACK (raw_cmd->cmd[2])
325
-#define HEAD (raw_cmd->cmd[3])
326
-#define SECTOR (raw_cmd->cmd[4])
327
-#define SIZECODE (raw_cmd->cmd[5])
328
-#define SECT_PER_TRACK (raw_cmd->cmd[6])
329
-#define GAP (raw_cmd->cmd[7])
330
-#define SIZECODE2 (raw_cmd->cmd[8])
311
+/* read/write commands */
312
+#define COMMAND 0
313
+#define DR_SELECT 1
314
+#define TRACK 2
315
+#define HEAD 3
316
+#define SECTOR 4
317
+#define SIZECODE 5
318
+#define SECT_PER_TRACK 6
319
+#define GAP 7
320
+#define SIZECODE2 8
331321 #define NR_RW 9
332322
333
-/* format */
334
-#define F_SIZECODE (raw_cmd->cmd[2])
335
-#define F_SECT_PER_TRACK (raw_cmd->cmd[3])
336
-#define F_GAP (raw_cmd->cmd[4])
337
-#define F_FILL (raw_cmd->cmd[5])
323
+/* format commands */
324
+#define F_SIZECODE 2
325
+#define F_SECT_PER_TRACK 3
326
+#define F_GAP 4
327
+#define F_FILL 5
338328 #define NR_F 6
339329
340330 /*
....@@ -347,17 +337,16 @@
347337 /*
348338 * globals used by 'result()'
349339 */
350
-#define MAX_REPLIES 16
351
-static unsigned char reply_buffer[MAX_REPLIES];
340
+static unsigned char reply_buffer[FD_RAW_REPLY_SIZE];
352341 static int inr; /* size of reply buffer, when called from interrupt */
353
-#define ST0 (reply_buffer[0])
354
-#define ST1 (reply_buffer[1])
355
-#define ST2 (reply_buffer[2])
356
-#define ST3 (reply_buffer[0]) /* result of GETSTATUS */
357
-#define R_TRACK (reply_buffer[3])
358
-#define R_HEAD (reply_buffer[4])
359
-#define R_SECTOR (reply_buffer[5])
360
-#define R_SIZECODE (reply_buffer[6])
342
+#define ST0 0
343
+#define ST1 1
344
+#define ST2 2
345
+#define ST3 0 /* result of GETSTATUS */
346
+#define R_TRACK 3
347
+#define R_HEAD 4
348
+#define R_SECTOR 5
349
+#define R_SIZECODE 6
361350
362351 #define SEL_DLY (2 * HZ / 100)
363352
....@@ -414,10 +403,10 @@
414403 static struct floppy_write_errors write_errors[N_DRIVE];
415404 static struct timer_list motor_off_timer[N_DRIVE];
416405 static struct gendisk *disks[N_DRIVE];
406
+static struct blk_mq_tag_set tag_sets[N_DRIVE];
417407 static struct block_device *opened_bdev[N_DRIVE];
418408 static DEFINE_MUTEX(open_lock);
419409 static struct floppy_raw_cmd *raw_cmd, default_raw_cmd;
420
-static int fdc_queue;
421410
422411 /*
423412 * This struct defines the different floppy types.
....@@ -520,8 +509,8 @@
520509 static DECLARE_WAIT_QUEUE_HEAD(fdc_wait);
521510 static DECLARE_WAIT_QUEUE_HEAD(command_done);
522511
523
-/* Errors during formatting are counted here. */
524
-static int format_errors;
512
+/* errors encountered on the current (or last) request */
513
+static int floppy_errors;
525514
526515 /* Format request descriptor. */
527516 static struct format_descr format_req;
....@@ -541,7 +530,6 @@
541530 static char *floppy_track_buffer;
542531 static int max_buffer_sectors;
543532
544
-static int *errors;
545533 typedef void (*done_f)(int);
546534 static const struct cont_t {
547535 void (*interrupt)(void);
....@@ -572,6 +560,7 @@
572560 * output_byte is automatically disabled when reset is set.
573561 */
574562 static void reset_fdc(void);
563
+static int floppy_revalidate(struct gendisk *disk);
575564
576565 /*
577566 * These are global variables, as that's the easiest way to give
....@@ -592,7 +581,7 @@
592581
593582 /* fdc related variables, should end up in a struct */
594583 static struct floppy_fdc_state fdc_state[N_FDC];
595
-static int fdc; /* current fdc */
584
+static int current_fdc; /* current fdc */
596585
597586 static struct workqueue_struct *floppy_wq;
598587
....@@ -603,9 +592,19 @@
603592 static unsigned char in_sector_offset; /* offset within physical sector,
604593 * expressed in units of 512 bytes */
605594
595
+static inline unsigned char fdc_inb(int fdc, int reg)
596
+{
597
+ return fd_inb(fdc_state[fdc].address, reg);
598
+}
599
+
600
+static inline void fdc_outb(unsigned char value, int fdc, int reg)
601
+{
602
+ fd_outb(value, fdc_state[fdc].address, reg);
603
+}
604
+
606605 static inline bool drive_no_geom(int drive)
607606 {
608
- return !current_type[drive] && !ITYPE(UDRS->fd_device);
607
+ return !current_type[drive] && !ITYPE(drive_state[drive].fd_device);
609608 }
610609
611610 #ifndef fd_eject
....@@ -629,7 +628,7 @@
629628
630629 static inline void debugt(const char *func, const char *msg)
631630 {
632
- if (DP->flags & DEBUGT)
631
+ if (drive_params[current_drive].flags & DEBUGT)
633632 pr_info("%s:%s dtime=%lu\n", func, msg, jiffies - debugtimer);
634633 }
635634 #else
....@@ -668,24 +667,20 @@
668667
669668 static int output_log_pos;
670669
671
-#define current_reqD -1
672670 #define MAXTIMEOUT -2
673671
674672 static void __reschedule_timeout(int drive, const char *message)
675673 {
676674 unsigned long delay;
677675
678
- if (drive == current_reqD)
679
- drive = current_drive;
680
-
681676 if (drive < 0 || drive >= N_DRIVE) {
682677 delay = 20UL * HZ;
683678 drive = 0;
684679 } else
685
- delay = UDP->timeout;
680
+ delay = drive_params[drive].timeout;
686681
687682 mod_delayed_work(floppy_wq, &fd_timeout, delay);
688
- if (UDP->flags & FD_DEBUG)
683
+ if (drive_params[drive].flags & FD_DEBUG)
689684 DPRINT("reschedule timeout %s\n", message);
690685 timeout_message = message;
691686 }
....@@ -739,33 +734,37 @@
739734 {
740735 int fdc = FDC(drive);
741736
742
- if (time_before(jiffies, UDRS->select_date + UDP->select_delay))
737
+ if (time_before(jiffies, drive_state[drive].select_date + drive_params[drive].select_delay))
743738 DPRINT("WARNING disk change called early\n");
744
- if (!(FDCS->dor & (0x10 << UNIT(drive))) ||
745
- (FDCS->dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
739
+ if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))) ||
740
+ (fdc_state[fdc].dor & 3) != UNIT(drive) || fdc != FDC(drive)) {
746741 DPRINT("probing disk change on unselected drive\n");
747742 DPRINT("drive=%d fdc=%d dor=%x\n", drive, FDC(drive),
748
- (unsigned int)FDCS->dor);
743
+ (unsigned int)fdc_state[fdc].dor);
749744 }
750745
751
- debug_dcl(UDP->flags,
746
+ debug_dcl(drive_params[drive].flags,
752747 "checking disk change line for drive %d\n", drive);
753
- debug_dcl(UDP->flags, "jiffies=%lu\n", jiffies);
754
- debug_dcl(UDP->flags, "disk change line=%x\n", fd_inb(FD_DIR) & 0x80);
755
- debug_dcl(UDP->flags, "flags=%lx\n", UDRS->flags);
748
+ debug_dcl(drive_params[drive].flags, "jiffies=%lu\n", jiffies);
749
+ debug_dcl(drive_params[drive].flags, "disk change line=%x\n",
750
+ fdc_inb(fdc, FD_DIR) & 0x80);
751
+ debug_dcl(drive_params[drive].flags, "flags=%lx\n",
752
+ drive_state[drive].flags);
756753
757
- if (UDP->flags & FD_BROKEN_DCL)
758
- return test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
759
- if ((fd_inb(FD_DIR) ^ UDP->flags) & 0x80) {
760
- set_bit(FD_VERIFY_BIT, &UDRS->flags);
754
+ if (drive_params[drive].flags & FD_BROKEN_DCL)
755
+ return test_bit(FD_DISK_CHANGED_BIT,
756
+ &drive_state[drive].flags);
757
+ if ((fdc_inb(fdc, FD_DIR) ^ drive_params[drive].flags) & 0x80) {
758
+ set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
761759 /* verify write protection */
762760
763
- if (UDRS->maxblock) /* mark it changed */
764
- set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
761
+ if (drive_state[drive].maxblock) /* mark it changed */
762
+ set_bit(FD_DISK_CHANGED_BIT,
763
+ &drive_state[drive].flags);
765764
766765 /* invalidate its geometry */
767
- if (UDRS->keep_data >= 0) {
768
- if ((UDP->flags & FTD_MSG) &&
766
+ if (drive_state[drive].keep_data >= 0) {
767
+ if ((drive_params[drive].flags & FTD_MSG) &&
769768 current_type[drive] != NULL)
770769 DPRINT("Disk type is undefined after disk change\n");
771770 current_type[drive] = NULL;
....@@ -774,8 +773,8 @@
774773
775774 return 1;
776775 } else {
777
- UDRS->last_checked = jiffies;
778
- clear_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags);
776
+ drive_state[drive].last_checked = jiffies;
777
+ clear_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
779778 }
780779 return 0;
781780 }
....@@ -798,82 +797,95 @@
798797 unsigned char newdor;
799798 unsigned char olddor;
800799
801
- if (FDCS->address == -1)
800
+ if (fdc_state[fdc].address == -1)
802801 return -1;
803802
804
- olddor = FDCS->dor;
803
+ olddor = fdc_state[fdc].dor;
805804 newdor = (olddor & mask) | data;
806805 if (newdor != olddor) {
807806 unit = olddor & 0x3;
808807 if (is_selected(olddor, unit) && !is_selected(newdor, unit)) {
809808 drive = REVDRIVE(fdc, unit);
810
- debug_dcl(UDP->flags,
809
+ debug_dcl(drive_params[drive].flags,
811810 "calling disk change from set_dor\n");
812811 disk_change(drive);
813812 }
814
- FDCS->dor = newdor;
815
- fd_outb(newdor, FD_DOR);
813
+ fdc_state[fdc].dor = newdor;
814
+ fdc_outb(newdor, fdc, FD_DOR);
816815
817816 unit = newdor & 0x3;
818817 if (!is_selected(olddor, unit) && is_selected(newdor, unit)) {
819818 drive = REVDRIVE(fdc, unit);
820
- UDRS->select_date = jiffies;
819
+ drive_state[drive].select_date = jiffies;
821820 }
822821 }
823822 return olddor;
824823 }
825824
826
-static void twaddle(void)
825
+static void twaddle(int fdc, int drive)
827826 {
828
- if (DP->select_delay)
827
+ if (drive_params[drive].select_delay)
829828 return;
830
- fd_outb(FDCS->dor & ~(0x10 << UNIT(current_drive)), FD_DOR);
831
- fd_outb(FDCS->dor, FD_DOR);
832
- DRS->select_date = jiffies;
829
+ fdc_outb(fdc_state[fdc].dor & ~(0x10 << UNIT(drive)),
830
+ fdc, FD_DOR);
831
+ fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
832
+ drive_state[drive].select_date = jiffies;
833833 }
834834
835835 /*
836
- * Reset all driver information about the current fdc.
836
+ * Reset all driver information about the specified fdc.
837837 * This is needed after a reset, and after a raw command.
838838 */
839
-static void reset_fdc_info(int mode)
839
+static void reset_fdc_info(int fdc, int mode)
840840 {
841841 int drive;
842842
843
- FDCS->spec1 = FDCS->spec2 = -1;
844
- FDCS->need_configure = 1;
845
- FDCS->perp_mode = 1;
846
- FDCS->rawcmd = 0;
843
+ fdc_state[fdc].spec1 = fdc_state[fdc].spec2 = -1;
844
+ fdc_state[fdc].need_configure = 1;
845
+ fdc_state[fdc].perp_mode = 1;
846
+ fdc_state[fdc].rawcmd = 0;
847847 for (drive = 0; drive < N_DRIVE; drive++)
848
- if (FDC(drive) == fdc && (mode || UDRS->track != NEED_1_RECAL))
849
- UDRS->track = NEED_2_RECAL;
848
+ if (FDC(drive) == fdc &&
849
+ (mode || drive_state[drive].track != NEED_1_RECAL))
850
+ drive_state[drive].track = NEED_2_RECAL;
850851 }
851852
852
-/* selects the fdc and drive, and enables the fdc's input/dma. */
853
+/*
854
+ * selects the fdc and drive, and enables the fdc's input/dma.
855
+ * Both current_drive and current_fdc are changed to match the new drive.
856
+ */
853857 static void set_fdc(int drive)
854858 {
855
- unsigned int new_fdc = fdc;
859
+ unsigned int fdc;
856860
857
- if (drive >= 0 && drive < N_DRIVE) {
858
- new_fdc = FDC(drive);
859
- current_drive = drive;
861
+ if (drive < 0 || drive >= N_DRIVE) {
862
+ pr_info("bad drive value %d\n", drive);
863
+ return;
860864 }
861
- if (new_fdc >= N_FDC) {
865
+
866
+ fdc = FDC(drive);
867
+ if (fdc >= N_FDC) {
862868 pr_info("bad fdc value\n");
863869 return;
864870 }
865
- fdc = new_fdc;
871
+
866872 set_dor(fdc, ~0, 8);
867873 #if N_FDC > 1
868874 set_dor(1 - fdc, ~8, 0);
869875 #endif
870
- if (FDCS->rawcmd == 2)
871
- reset_fdc_info(1);
872
- if (fd_inb(FD_STATUS) != STATUS_READY)
873
- FDCS->reset = 1;
876
+ if (fdc_state[fdc].rawcmd == 2)
877
+ reset_fdc_info(fdc, 1);
878
+ if (fdc_inb(fdc, FD_STATUS) != STATUS_READY)
879
+ fdc_state[fdc].reset = 1;
880
+
881
+ current_drive = drive;
882
+ current_fdc = fdc;
874883 }
875884
876
-/* locks the driver */
885
+/*
886
+ * locks the driver.
887
+ * Both current_drive and current_fdc are changed to match the new drive.
888
+ */
877889 static int lock_fdc(int drive)
878890 {
879891 if (WARN(atomic_read(&usage_count) == 0,
....@@ -923,19 +935,19 @@
923935 unsigned long volatile delta;
924936 int fdc = FDC(drive);
925937
926
- if (!(FDCS->dor & (0x10 << UNIT(drive))))
938
+ if (!(fdc_state[fdc].dor & (0x10 << UNIT(drive))))
927939 return;
928940
929941 del_timer(motor_off_timer + drive);
930942
931943 /* make spindle stop in a position which minimizes spinup time
932944 * next time */
933
- if (UDP->rps) {
934
- delta = jiffies - UDRS->first_read_date + HZ -
935
- UDP->spindown_offset;
936
- delta = ((delta * UDP->rps) % HZ) / UDP->rps;
945
+ if (drive_params[drive].rps) {
946
+ delta = jiffies - drive_state[drive].first_read_date + HZ -
947
+ drive_params[drive].spindown_offset;
948
+ delta = ((delta * drive_params[drive].rps) % HZ) / drive_params[drive].rps;
937949 motor_off_timer[drive].expires =
938
- jiffies + UDP->spindown - delta;
950
+ jiffies + drive_params[drive].spindown - delta;
939951 }
940952 add_timer(motor_off_timer + drive);
941953 }
....@@ -951,20 +963,20 @@
951963 int drive;
952964 int saved_drive;
953965
954
- if (DP->select_delay)
966
+ if (drive_params[current_drive].select_delay)
955967 return;
956968
957969 saved_drive = current_drive;
958970 for (i = 0; i < N_DRIVE; i++) {
959971 drive = (saved_drive + i + 1) % N_DRIVE;
960
- if (UDRS->fd_ref == 0 || UDP->select_delay != 0)
972
+ if (drive_state[drive].fd_ref == 0 || drive_params[drive].select_delay != 0)
961973 continue; /* skip closed drives */
962974 set_fdc(drive);
963
- if (!(set_dor(fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) &
975
+ if (!(set_dor(current_fdc, ~3, UNIT(drive) | (0x10 << UNIT(drive))) &
964976 (0x10 << UNIT(drive))))
965977 /* switch the motor off again, if it was off to
966978 * begin with */
967
- set_dor(fdc, ~(0x10 << UNIT(drive)), 0);
979
+ set_dor(current_fdc, ~(0x10 << UNIT(drive)), 0);
968980 }
969981 set_fdc(saved_drive);
970982 }
....@@ -1010,7 +1022,8 @@
10101022 * transfer */
10111023 static void fd_watchdog(void)
10121024 {
1013
- debug_dcl(DP->flags, "calling disk change from watchdog\n");
1025
+ debug_dcl(drive_params[current_drive].flags,
1026
+ "calling disk change from watchdog\n");
10141027
10151028 if (disk_change(current_drive)) {
10161029 DPRINT("disk removed during i/o\n");
....@@ -1034,7 +1047,7 @@
10341047 static int fd_wait_for_completion(unsigned long expires,
10351048 void (*function)(void))
10361049 {
1037
- if (FDCS->reset) {
1050
+ if (fdc_state[current_fdc].reset) {
10381051 reset_fdc(); /* do the reset during sleep to win time
10391052 * if we don't need to sleep, it's a good
10401053 * occasion anyways */
....@@ -1055,20 +1068,17 @@
10551068 unsigned long f;
10561069
10571070 if (raw_cmd->length == 0) {
1058
- int i;
1059
-
1060
- pr_info("zero dma transfer size:");
1061
- for (i = 0; i < raw_cmd->cmd_count; i++)
1062
- pr_cont("%x,", raw_cmd->cmd[i]);
1063
- pr_cont("\n");
1071
+ print_hex_dump(KERN_INFO, "zero dma transfer size: ",
1072
+ DUMP_PREFIX_NONE, 16, 1,
1073
+ raw_cmd->fullcmd, raw_cmd->cmd_count, false);
10641074 cont->done(0);
1065
- FDCS->reset = 1;
1075
+ fdc_state[current_fdc].reset = 1;
10661076 return;
10671077 }
10681078 if (((unsigned long)raw_cmd->kernel_data) % 512) {
10691079 pr_info("non aligned address: %p\n", raw_cmd->kernel_data);
10701080 cont->done(0);
1071
- FDCS->reset = 1;
1081
+ fdc_state[current_fdc].reset = 1;
10721082 return;
10731083 }
10741084 f = claim_dma_lock();
....@@ -1076,10 +1086,11 @@
10761086 #ifdef fd_dma_setup
10771087 if (fd_dma_setup(raw_cmd->kernel_data, raw_cmd->length,
10781088 (raw_cmd->flags & FD_RAW_READ) ?
1079
- DMA_MODE_READ : DMA_MODE_WRITE, FDCS->address) < 0) {
1089
+ DMA_MODE_READ : DMA_MODE_WRITE,
1090
+ fdc_state[current_fdc].address) < 0) {
10801091 release_dma_lock(f);
10811092 cont->done(0);
1082
- FDCS->reset = 1;
1093
+ fdc_state[current_fdc].reset = 1;
10831094 return;
10841095 }
10851096 release_dma_lock(f);
....@@ -1090,68 +1101,68 @@
10901101 DMA_MODE_READ : DMA_MODE_WRITE);
10911102 fd_set_dma_addr(raw_cmd->kernel_data);
10921103 fd_set_dma_count(raw_cmd->length);
1093
- virtual_dma_port = FDCS->address;
1104
+ virtual_dma_port = fdc_state[current_fdc].address;
10941105 fd_enable_dma();
10951106 release_dma_lock(f);
10961107 #endif
10971108 }
10981109
1099
-static void show_floppy(void);
1110
+static void show_floppy(int fdc);
11001111
11011112 /* waits until the fdc becomes ready */
1102
-static int wait_til_ready(void)
1113
+static int wait_til_ready(int fdc)
11031114 {
11041115 int status;
11051116 int counter;
11061117
1107
- if (FDCS->reset)
1118
+ if (fdc_state[fdc].reset)
11081119 return -1;
11091120 for (counter = 0; counter < 10000; counter++) {
1110
- status = fd_inb(FD_STATUS);
1121
+ status = fdc_inb(fdc, FD_STATUS);
11111122 if (status & STATUS_READY)
11121123 return status;
11131124 }
11141125 if (initialized) {
11151126 DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc);
1116
- show_floppy();
1127
+ show_floppy(fdc);
11171128 }
1118
- FDCS->reset = 1;
1129
+ fdc_state[fdc].reset = 1;
11191130 return -1;
11201131 }
11211132
11221133 /* sends a command byte to the fdc */
1123
-static int output_byte(char byte)
1134
+static int output_byte(int fdc, char byte)
11241135 {
1125
- int status = wait_til_ready();
1136
+ int status = wait_til_ready(fdc);
11261137
11271138 if (status < 0)
11281139 return -1;
11291140
11301141 if (is_ready_state(status)) {
1131
- fd_outb(byte, FD_DATA);
1142
+ fdc_outb(byte, fdc, FD_DATA);
11321143 output_log[output_log_pos].data = byte;
11331144 output_log[output_log_pos].status = status;
11341145 output_log[output_log_pos].jiffies = jiffies;
11351146 output_log_pos = (output_log_pos + 1) % OLOGSIZE;
11361147 return 0;
11371148 }
1138
- FDCS->reset = 1;
1149
+ fdc_state[fdc].reset = 1;
11391150 if (initialized) {
11401151 DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
11411152 byte, fdc, status);
1142
- show_floppy();
1153
+ show_floppy(fdc);
11431154 }
11441155 return -1;
11451156 }
11461157
11471158 /* gets the response from the fdc */
1148
-static int result(void)
1159
+static int result(int fdc)
11491160 {
11501161 int i;
11511162 int status = 0;
11521163
1153
- for (i = 0; i < MAX_REPLIES; i++) {
1154
- status = wait_til_ready();
1164
+ for (i = 0; i < FD_RAW_REPLY_SIZE; i++) {
1165
+ status = wait_til_ready(fdc);
11551166 if (status < 0)
11561167 break;
11571168 status &= STATUS_DIR | STATUS_READY | STATUS_BUSY | STATUS_DMA;
....@@ -1161,24 +1172,24 @@
11611172 return i;
11621173 }
11631174 if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
1164
- reply_buffer[i] = fd_inb(FD_DATA);
1175
+ reply_buffer[i] = fdc_inb(fdc, FD_DATA);
11651176 else
11661177 break;
11671178 }
11681179 if (initialized) {
11691180 DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
11701181 fdc, status, i);
1171
- show_floppy();
1182
+ show_floppy(fdc);
11721183 }
1173
- FDCS->reset = 1;
1184
+ fdc_state[fdc].reset = 1;
11741185 return -1;
11751186 }
11761187
11771188 #define MORE_OUTPUT -2
11781189 /* does the fdc need more output? */
1179
-static int need_more_output(void)
1190
+static int need_more_output(int fdc)
11801191 {
1181
- int status = wait_til_ready();
1192
+ int status = wait_til_ready(fdc);
11821193
11831194 if (status < 0)
11841195 return -1;
....@@ -1186,13 +1197,13 @@
11861197 if (is_ready_state(status))
11871198 return MORE_OUTPUT;
11881199
1189
- return result();
1200
+ return result(fdc);
11901201 }
11911202
11921203 /* Set perpendicular mode as required, based on data rate, if supported.
11931204 * 82077 Now tested. 1Mbps data rate only possible with 82077-1.
11941205 */
1195
-static void perpendicular_mode(void)
1206
+static void perpendicular_mode(int fdc)
11961207 {
11971208 unsigned char perp_mode;
11981209
....@@ -1207,7 +1218,7 @@
12071218 default:
12081219 DPRINT("Invalid data rate for perpendicular mode!\n");
12091220 cont->done(0);
1210
- FDCS->reset = 1;
1221
+ fdc_state[fdc].reset = 1;
12111222 /*
12121223 * convenient way to return to
12131224 * redo without too much hassle
....@@ -1218,12 +1229,12 @@
12181229 } else
12191230 perp_mode = 0;
12201231
1221
- if (FDCS->perp_mode == perp_mode)
1232
+ if (fdc_state[fdc].perp_mode == perp_mode)
12221233 return;
1223
- if (FDCS->version >= FDC_82077_ORIG) {
1224
- output_byte(FD_PERPENDICULAR);
1225
- output_byte(perp_mode);
1226
- FDCS->perp_mode = perp_mode;
1234
+ if (fdc_state[fdc].version >= FDC_82077_ORIG) {
1235
+ output_byte(fdc, FD_PERPENDICULAR);
1236
+ output_byte(fdc, perp_mode);
1237
+ fdc_state[fdc].perp_mode = perp_mode;
12271238 } else if (perp_mode) {
12281239 DPRINT("perpendicular mode not supported by this FDC.\n");
12291240 }
....@@ -1232,16 +1243,15 @@
12321243 static int fifo_depth = 0xa;
12331244 static int no_fifo;
12341245
1235
-static int fdc_configure(void)
1246
+static int fdc_configure(int fdc)
12361247 {
12371248 /* Turn on FIFO */
1238
- output_byte(FD_CONFIGURE);
1239
- if (need_more_output() != MORE_OUTPUT)
1249
+ output_byte(fdc, FD_CONFIGURE);
1250
+ if (need_more_output(fdc) != MORE_OUTPUT)
12401251 return 0;
1241
- output_byte(0);
1242
- output_byte(0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
1243
- output_byte(0); /* pre-compensation from track
1244
- 0 upwards */
1252
+ output_byte(fdc, 0);
1253
+ output_byte(fdc, 0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
1254
+ output_byte(fdc, 0); /* pre-compensation from track 0 upwards */
12451255 return 1;
12461256 }
12471257
....@@ -1266,7 +1276,7 @@
12661276 *
12671277 * These values are rounded up to the next highest available delay time.
12681278 */
1269
-static void fdc_specify(void)
1279
+static void fdc_specify(int fdc, int drive)
12701280 {
12711281 unsigned char spec1;
12721282 unsigned char spec2;
....@@ -1278,9 +1288,10 @@
12781288 int hlt_max_code = 0x7f;
12791289 int hut_max_code = 0xf;
12801290
1281
- if (FDCS->need_configure && FDCS->version >= FDC_82072A) {
1282
- fdc_configure();
1283
- FDCS->need_configure = 0;
1291
+ if (fdc_state[fdc].need_configure &&
1292
+ fdc_state[fdc].version >= FDC_82072A) {
1293
+ fdc_configure(fdc);
1294
+ fdc_state[fdc].need_configure = 0;
12841295 }
12851296
12861297 switch (raw_cmd->rate & 0x03) {
....@@ -1289,13 +1300,13 @@
12891300 break;
12901301 case 1:
12911302 dtr = 300;
1292
- if (FDCS->version >= FDC_82078) {
1303
+ if (fdc_state[fdc].version >= FDC_82078) {
12931304 /* chose the default rate table, not the one
12941305 * where 1 = 2 Mbps */
1295
- output_byte(FD_DRIVESPEC);
1296
- if (need_more_output() == MORE_OUTPUT) {
1297
- output_byte(UNIT(current_drive));
1298
- output_byte(0xc0);
1306
+ output_byte(fdc, FD_DRIVESPEC);
1307
+ if (need_more_output(fdc) == MORE_OUTPUT) {
1308
+ output_byte(fdc, UNIT(drive));
1309
+ output_byte(fdc, 0xc0);
12991310 }
13001311 }
13011312 break;
....@@ -1304,27 +1315,30 @@
13041315 break;
13051316 }
13061317
1307
- if (FDCS->version >= FDC_82072) {
1318
+ if (fdc_state[fdc].version >= FDC_82072) {
13081319 scale_dtr = dtr;
13091320 hlt_max_code = 0x00; /* 0==256msec*dtr0/dtr (not linear!) */
13101321 hut_max_code = 0x0; /* 0==256msec*dtr0/dtr (not linear!) */
13111322 }
13121323
13131324 /* Convert step rate from microseconds to milliseconds and 4 bits */
1314
- srt = 16 - DIV_ROUND_UP(DP->srt * scale_dtr / 1000, NOMINAL_DTR);
1325
+ srt = 16 - DIV_ROUND_UP(drive_params[drive].srt * scale_dtr / 1000,
1326
+ NOMINAL_DTR);
13151327 if (slow_floppy)
13161328 srt = srt / 4;
13171329
13181330 SUPBOUND(srt, 0xf);
13191331 INFBOUND(srt, 0);
13201332
1321
- hlt = DIV_ROUND_UP(DP->hlt * scale_dtr / 2, NOMINAL_DTR);
1333
+ hlt = DIV_ROUND_UP(drive_params[drive].hlt * scale_dtr / 2,
1334
+ NOMINAL_DTR);
13221335 if (hlt < 0x01)
13231336 hlt = 0x01;
13241337 else if (hlt > 0x7f)
13251338 hlt = hlt_max_code;
13261339
1327
- hut = DIV_ROUND_UP(DP->hut * scale_dtr / 16, NOMINAL_DTR);
1340
+ hut = DIV_ROUND_UP(drive_params[drive].hut * scale_dtr / 16,
1341
+ NOMINAL_DTR);
13281342 if (hut < 0x1)
13291343 hut = 0x1;
13301344 else if (hut > 0xf)
....@@ -1334,11 +1348,12 @@
13341348 spec2 = (hlt << 1) | (use_virtual_dma & 1);
13351349
13361350 /* If these parameters did not change, just return with success */
1337
- if (FDCS->spec1 != spec1 || FDCS->spec2 != spec2) {
1351
+ if (fdc_state[fdc].spec1 != spec1 ||
1352
+ fdc_state[fdc].spec2 != spec2) {
13381353 /* Go ahead and set spec1 and spec2 */
1339
- output_byte(FD_SPECIFY);
1340
- output_byte(FDCS->spec1 = spec1);
1341
- output_byte(FDCS->spec2 = spec2);
1354
+ output_byte(fdc, FD_SPECIFY);
1355
+ output_byte(fdc, fdc_state[fdc].spec1 = spec1);
1356
+ output_byte(fdc, fdc_state[fdc].spec2 = spec2);
13421357 }
13431358 } /* fdc_specify */
13441359
....@@ -1349,52 +1364,55 @@
13491364 static int fdc_dtr(void)
13501365 {
13511366 /* If data rate not already set to desired value, set it. */
1352
- if ((raw_cmd->rate & 3) == FDCS->dtr)
1367
+ if ((raw_cmd->rate & 3) == fdc_state[current_fdc].dtr)
13531368 return 0;
13541369
13551370 /* Set dtr */
1356
- fd_outb(raw_cmd->rate & 3, FD_DCR);
1371
+ fdc_outb(raw_cmd->rate & 3, current_fdc, FD_DCR);
13571372
13581373 /* TODO: some FDC/drive combinations (C&T 82C711 with TEAC 1.2MB)
13591374 * need a stabilization period of several milliseconds to be
13601375 * enforced after data rate changes before R/W operations.
13611376 * Pause 5 msec to avoid trouble. (Needs to be 2 jiffies)
13621377 */
1363
- FDCS->dtr = raw_cmd->rate & 3;
1378
+ fdc_state[current_fdc].dtr = raw_cmd->rate & 3;
13641379 return fd_wait_for_completion(jiffies + 2UL * HZ / 100, floppy_ready);
13651380 } /* fdc_dtr */
13661381
13671382 static void tell_sector(void)
13681383 {
13691384 pr_cont(": track %d, head %d, sector %d, size %d",
1370
- R_TRACK, R_HEAD, R_SECTOR, R_SIZECODE);
1385
+ reply_buffer[R_TRACK], reply_buffer[R_HEAD],
1386
+ reply_buffer[R_SECTOR],
1387
+ reply_buffer[R_SIZECODE]);
13711388 } /* tell_sector */
13721389
13731390 static void print_errors(void)
13741391 {
13751392 DPRINT("");
1376
- if (ST0 & ST0_ECE) {
1393
+ if (reply_buffer[ST0] & ST0_ECE) {
13771394 pr_cont("Recalibrate failed!");
1378
- } else if (ST2 & ST2_CRC) {
1395
+ } else if (reply_buffer[ST2] & ST2_CRC) {
13791396 pr_cont("data CRC error");
13801397 tell_sector();
1381
- } else if (ST1 & ST1_CRC) {
1398
+ } else if (reply_buffer[ST1] & ST1_CRC) {
13821399 pr_cont("CRC error");
13831400 tell_sector();
1384
- } else if ((ST1 & (ST1_MAM | ST1_ND)) ||
1385
- (ST2 & ST2_MAM)) {
1401
+ } else if ((reply_buffer[ST1] & (ST1_MAM | ST1_ND)) ||
1402
+ (reply_buffer[ST2] & ST2_MAM)) {
13861403 if (!probing) {
13871404 pr_cont("sector not found");
13881405 tell_sector();
13891406 } else
13901407 pr_cont("probe failed...");
1391
- } else if (ST2 & ST2_WC) { /* seek error */
1408
+ } else if (reply_buffer[ST2] & ST2_WC) { /* seek error */
13921409 pr_cont("wrong cylinder");
1393
- } else if (ST2 & ST2_BC) { /* cylinder marked as bad */
1410
+ } else if (reply_buffer[ST2] & ST2_BC) { /* cylinder marked as bad */
13941411 pr_cont("bad cylinder");
13951412 } else {
13961413 pr_cont("unknown error. ST[0..2] are: 0x%x 0x%x 0x%x",
1397
- ST0, ST1, ST2);
1414
+ reply_buffer[ST0], reply_buffer[ST1],
1415
+ reply_buffer[ST2]);
13981416 tell_sector();
13991417 }
14001418 pr_cont("\n");
....@@ -1413,33 +1431,35 @@
14131431
14141432 if (inr != 7) {
14151433 DPRINT("-- FDC reply error\n");
1416
- FDCS->reset = 1;
1434
+ fdc_state[current_fdc].reset = 1;
14171435 return 1;
14181436 }
14191437
14201438 /* check IC to find cause of interrupt */
1421
- switch (ST0 & ST0_INTR) {
1439
+ switch (reply_buffer[ST0] & ST0_INTR) {
14221440 case 0x40: /* error occurred during command execution */
1423
- if (ST1 & ST1_EOC)
1441
+ if (reply_buffer[ST1] & ST1_EOC)
14241442 return 0; /* occurs with pseudo-DMA */
14251443 bad = 1;
1426
- if (ST1 & ST1_WP) {
1444
+ if (reply_buffer[ST1] & ST1_WP) {
14271445 DPRINT("Drive is write protected\n");
1428
- clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
1446
+ clear_bit(FD_DISK_WRITABLE_BIT,
1447
+ &drive_state[current_drive].flags);
14291448 cont->done(0);
14301449 bad = 2;
1431
- } else if (ST1 & ST1_ND) {
1432
- set_bit(FD_NEED_TWADDLE_BIT, &DRS->flags);
1433
- } else if (ST1 & ST1_OR) {
1434
- if (DP->flags & FTD_MSG)
1450
+ } else if (reply_buffer[ST1] & ST1_ND) {
1451
+ set_bit(FD_NEED_TWADDLE_BIT,
1452
+ &drive_state[current_drive].flags);
1453
+ } else if (reply_buffer[ST1] & ST1_OR) {
1454
+ if (drive_params[current_drive].flags & FTD_MSG)
14351455 DPRINT("Over/Underrun - retrying\n");
14361456 bad = 0;
1437
- } else if (*errors >= DP->max_errors.reporting) {
1457
+ } else if (floppy_errors >= drive_params[current_drive].max_errors.reporting) {
14381458 print_errors();
14391459 }
1440
- if (ST2 & ST2_WC || ST2 & ST2_BC)
1460
+ if (reply_buffer[ST2] & ST2_WC || reply_buffer[ST2] & ST2_BC)
14411461 /* wrong cylinder => recal */
1442
- DRS->track = NEED_2_RECAL;
1462
+ drive_state[current_drive].track = NEED_2_RECAL;
14431463 return bad;
14441464 case 0x80: /* invalid command given */
14451465 DPRINT("Invalid FDC command given!\n");
....@@ -1472,13 +1492,13 @@
14721492 flags |= FD_RAW_INTR;
14731493
14741494 if ((flags & FD_RAW_SPIN) && !(flags & FD_RAW_NO_MOTOR)) {
1475
- ready_date = DRS->spinup_date + DP->spinup;
1495
+ ready_date = drive_state[current_drive].spinup_date + drive_params[current_drive].spinup;
14761496 /* If spinup will take a long time, rerun scandrives
14771497 * again just before spinup completion. Beware that
14781498 * after scandrives, we must again wait for selection.
14791499 */
1480
- if (time_after(ready_date, jiffies + DP->select_delay)) {
1481
- ready_date -= DP->select_delay;
1500
+ if (time_after(ready_date, jiffies + drive_params[current_drive].select_delay)) {
1501
+ ready_date -= drive_params[current_drive].select_delay;
14821502 function = floppy_start;
14831503 } else
14841504 function = setup_rw_floppy;
....@@ -1495,7 +1515,7 @@
14951515
14961516 r = 0;
14971517 for (i = 0; i < raw_cmd->cmd_count; i++)
1498
- r |= output_byte(raw_cmd->cmd[i]);
1518
+ r |= output_byte(current_fdc, raw_cmd->fullcmd[i]);
14991519
15001520 debugt(__func__, "rw_command");
15011521
....@@ -1506,7 +1526,7 @@
15061526 }
15071527
15081528 if (!(flags & FD_RAW_INTR)) {
1509
- inr = result();
1529
+ inr = result(current_fdc);
15101530 cont->interrupt();
15111531 } else if (flags & FD_RAW_NEED_DISK)
15121532 fd_watchdog();
....@@ -1521,44 +1541,52 @@
15211541 static void seek_interrupt(void)
15221542 {
15231543 debugt(__func__, "");
1524
- if (inr != 2 || (ST0 & 0xF8) != 0x20) {
1544
+ if (inr != 2 || (reply_buffer[ST0] & 0xF8) != 0x20) {
15251545 DPRINT("seek failed\n");
1526
- DRS->track = NEED_2_RECAL;
1546
+ drive_state[current_drive].track = NEED_2_RECAL;
15271547 cont->error();
15281548 cont->redo();
15291549 return;
15301550 }
1531
- if (DRS->track >= 0 && DRS->track != ST1 && !blind_seek) {
1532
- debug_dcl(DP->flags,
1551
+ if (drive_state[current_drive].track >= 0 &&
1552
+ drive_state[current_drive].track != reply_buffer[ST1] &&
1553
+ !blind_seek) {
1554
+ debug_dcl(drive_params[current_drive].flags,
15331555 "clearing NEWCHANGE flag because of effective seek\n");
1534
- debug_dcl(DP->flags, "jiffies=%lu\n", jiffies);
1535
- clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
1556
+ debug_dcl(drive_params[current_drive].flags, "jiffies=%lu\n",
1557
+ jiffies);
1558
+ clear_bit(FD_DISK_NEWCHANGE_BIT,
1559
+ &drive_state[current_drive].flags);
15361560 /* effective seek */
1537
- DRS->select_date = jiffies;
1561
+ drive_state[current_drive].select_date = jiffies;
15381562 }
1539
- DRS->track = ST1;
1563
+ drive_state[current_drive].track = reply_buffer[ST1];
15401564 floppy_ready();
15411565 }
15421566
1543
-static void check_wp(void)
1567
+static void check_wp(int fdc, int drive)
15441568 {
1545
- if (test_bit(FD_VERIFY_BIT, &DRS->flags)) {
1569
+ if (test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)) {
15461570 /* check write protection */
1547
- output_byte(FD_GETSTATUS);
1548
- output_byte(UNIT(current_drive));
1549
- if (result() != 1) {
1550
- FDCS->reset = 1;
1571
+ output_byte(fdc, FD_GETSTATUS);
1572
+ output_byte(fdc, UNIT(drive));
1573
+ if (result(fdc) != 1) {
1574
+ fdc_state[fdc].reset = 1;
15511575 return;
15521576 }
1553
- clear_bit(FD_VERIFY_BIT, &DRS->flags);
1554
- clear_bit(FD_NEED_TWADDLE_BIT, &DRS->flags);
1555
- debug_dcl(DP->flags,
1577
+ clear_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
1578
+ clear_bit(FD_NEED_TWADDLE_BIT,
1579
+ &drive_state[drive].flags);
1580
+ debug_dcl(drive_params[drive].flags,
15561581 "checking whether disk is write protected\n");
1557
- debug_dcl(DP->flags, "wp=%x\n", ST3 & 0x40);
1558
- if (!(ST3 & 0x40))
1559
- set_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
1582
+ debug_dcl(drive_params[drive].flags, "wp=%x\n",
1583
+ reply_buffer[ST3] & 0x40);
1584
+ if (!(reply_buffer[ST3] & 0x40))
1585
+ set_bit(FD_DISK_WRITABLE_BIT,
1586
+ &drive_state[drive].flags);
15601587 else
1561
- clear_bit(FD_DISK_WRITABLE_BIT, &DRS->flags);
1588
+ clear_bit(FD_DISK_WRITABLE_BIT,
1589
+ &drive_state[drive].flags);
15621590 }
15631591 }
15641592
....@@ -1568,40 +1596,42 @@
15681596
15691597 blind_seek = 0;
15701598
1571
- debug_dcl(DP->flags, "calling disk change from %s\n", __func__);
1599
+ debug_dcl(drive_params[current_drive].flags,
1600
+ "calling disk change from %s\n", __func__);
15721601
1573
- if (!test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) &&
1602
+ if (!test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
15741603 disk_change(current_drive) && (raw_cmd->flags & FD_RAW_NEED_DISK)) {
15751604 /* the media changed flag should be cleared after the seek.
15761605 * If it isn't, this means that there is really no disk in
15771606 * the drive.
15781607 */
1579
- set_bit(FD_DISK_CHANGED_BIT, &DRS->flags);
1608
+ set_bit(FD_DISK_CHANGED_BIT,
1609
+ &drive_state[current_drive].flags);
15801610 cont->done(0);
15811611 cont->redo();
15821612 return;
15831613 }
1584
- if (DRS->track <= NEED_1_RECAL) {
1614
+ if (drive_state[current_drive].track <= NEED_1_RECAL) {
15851615 recalibrate_floppy();
15861616 return;
1587
- } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags) &&
1617
+ } else if (test_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags) &&
15881618 (raw_cmd->flags & FD_RAW_NEED_DISK) &&
1589
- (DRS->track <= NO_TRACK || DRS->track == raw_cmd->track)) {
1619
+ (drive_state[current_drive].track <= NO_TRACK || drive_state[current_drive].track == raw_cmd->track)) {
15901620 /* we seek to clear the media-changed condition. Does anybody
15911621 * know a more elegant way, which works on all drives? */
15921622 if (raw_cmd->track)
15931623 track = raw_cmd->track - 1;
15941624 else {
1595
- if (DP->flags & FD_SILENT_DCL_CLEAR) {
1596
- set_dor(fdc, ~(0x10 << UNIT(current_drive)), 0);
1625
+ if (drive_params[current_drive].flags & FD_SILENT_DCL_CLEAR) {
1626
+ set_dor(current_fdc, ~(0x10 << UNIT(current_drive)), 0);
15971627 blind_seek = 1;
15981628 raw_cmd->flags |= FD_RAW_NEED_SEEK;
15991629 }
16001630 track = 1;
16011631 }
16021632 } else {
1603
- check_wp();
1604
- if (raw_cmd->track != DRS->track &&
1633
+ check_wp(current_fdc, current_drive);
1634
+ if (raw_cmd->track != drive_state[current_drive].track &&
16051635 (raw_cmd->flags & FD_RAW_NEED_SEEK))
16061636 track = raw_cmd->track;
16071637 else {
....@@ -1611,9 +1641,9 @@
16111641 }
16121642
16131643 do_floppy = seek_interrupt;
1614
- output_byte(FD_SEEK);
1615
- output_byte(UNIT(current_drive));
1616
- if (output_byte(track) < 0) {
1644
+ output_byte(current_fdc, FD_SEEK);
1645
+ output_byte(current_fdc, UNIT(current_drive));
1646
+ if (output_byte(current_fdc, track) < 0) {
16171647 reset_fdc();
16181648 return;
16191649 }
....@@ -1624,9 +1654,9 @@
16241654 {
16251655 debugt(__func__, "");
16261656 if (inr != 2)
1627
- FDCS->reset = 1;
1628
- else if (ST0 & ST0_ECE) {
1629
- switch (DRS->track) {
1657
+ fdc_state[current_fdc].reset = 1;
1658
+ else if (reply_buffer[ST0] & ST0_ECE) {
1659
+ switch (drive_state[current_drive].track) {
16301660 case NEED_1_RECAL:
16311661 debugt(__func__, "need 1 recal");
16321662 /* after a second recalibrate, we still haven't
....@@ -1644,12 +1674,13 @@
16441674 * not to move at recalibration is to
16451675 * be already at track 0.) Clear the
16461676 * new change flag */
1647
- debug_dcl(DP->flags,
1677
+ debug_dcl(drive_params[current_drive].flags,
16481678 "clearing NEWCHANGE flag because of second recalibrate\n");
16491679
1650
- clear_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
1651
- DRS->select_date = jiffies;
1652
- /* fall through */
1680
+ clear_bit(FD_DISK_NEWCHANGE_BIT,
1681
+ &drive_state[current_drive].flags);
1682
+ drive_state[current_drive].select_date = jiffies;
1683
+ fallthrough;
16531684 default:
16541685 debugt(__func__, "default");
16551686 /* Recalibrate moves the head by at
....@@ -1658,11 +1689,11 @@
16581689 * track 0, this might mean that we
16591690 * started beyond track 80. Try
16601691 * again. */
1661
- DRS->track = NEED_1_RECAL;
1692
+ drive_state[current_drive].track = NEED_1_RECAL;
16621693 break;
16631694 }
16641695 } else
1665
- DRS->track = ST1;
1696
+ drive_state[current_drive].track = reply_buffer[ST1];
16661697 floppy_ready();
16671698 }
16681699
....@@ -1692,20 +1723,20 @@
16921723 release_dma_lock(f);
16931724
16941725 do_floppy = NULL;
1695
- if (fdc >= N_FDC || FDCS->address == -1) {
1726
+ if (current_fdc >= N_FDC || fdc_state[current_fdc].address == -1) {
16961727 /* we don't even know which FDC is the culprit */
16971728 pr_info("DOR0=%x\n", fdc_state[0].dor);
1698
- pr_info("floppy interrupt on bizarre fdc %d\n", fdc);
1699
- pr_info("handler=%pf\n", handler);
1729
+ pr_info("floppy interrupt on bizarre fdc %d\n", current_fdc);
1730
+ pr_info("handler=%ps\n", handler);
17001731 is_alive(__func__, "bizarre fdc");
17011732 return IRQ_NONE;
17021733 }
17031734
1704
- FDCS->reset = 0;
1735
+ fdc_state[current_fdc].reset = 0;
17051736 /* We have to clear the reset flag here, because apparently on boxes
17061737 * with level triggered interrupts (PS/2, Sparc, ...), it is needed to
1707
- * emit SENSEI's to clear the interrupt line. And FDCS->reset blocks the
1708
- * emission of the SENSEI's.
1738
+ * emit SENSEI's to clear the interrupt line. And fdc_state[fdc].reset
1739
+ * blocks the emission of the SENSEI's.
17091740 * It is OK to emit floppy commands because we are in an interrupt
17101741 * handler here, and thus we have to fear no interference of other
17111742 * activity.
....@@ -1713,22 +1744,22 @@
17131744
17141745 do_print = !handler && print_unex && initialized;
17151746
1716
- inr = result();
1747
+ inr = result(current_fdc);
17171748 if (do_print)
17181749 print_result("unexpected interrupt", inr);
17191750 if (inr == 0) {
17201751 int max_sensei = 4;
17211752 do {
1722
- output_byte(FD_SENSEI);
1723
- inr = result();
1753
+ output_byte(current_fdc, FD_SENSEI);
1754
+ inr = result(current_fdc);
17241755 if (do_print)
17251756 print_result("sensei", inr);
17261757 max_sensei--;
1727
- } while ((ST0 & 0x83) != UNIT(current_drive) &&
1758
+ } while ((reply_buffer[ST0] & 0x83) != UNIT(current_drive) &&
17281759 inr == 2 && max_sensei);
17291760 }
17301761 if (!handler) {
1731
- FDCS->reset = 1;
1762
+ fdc_state[current_fdc].reset = 1;
17321763 return IRQ_NONE;
17331764 }
17341765 schedule_bh(handler);
....@@ -1742,8 +1773,8 @@
17421773 {
17431774 debugt(__func__, "");
17441775 do_floppy = recal_interrupt;
1745
- output_byte(FD_RECALIBRATE);
1746
- if (output_byte(UNIT(current_drive)) < 0)
1776
+ output_byte(current_fdc, FD_RECALIBRATE);
1777
+ if (output_byte(current_fdc, UNIT(current_drive)) < 0)
17471778 reset_fdc();
17481779 }
17491780
....@@ -1753,9 +1784,9 @@
17531784 static void reset_interrupt(void)
17541785 {
17551786 debugt(__func__, "");
1756
- result(); /* get the status ready for set_fdc */
1757
- if (FDCS->reset) {
1758
- pr_info("reset set in interrupt, calling %pf\n", cont->error);
1787
+ result(current_fdc); /* get the status ready for set_fdc */
1788
+ if (fdc_state[current_fdc].reset) {
1789
+ pr_info("reset set in interrupt, calling %ps\n", cont->error);
17591790 cont->error(); /* a reset just after a reset. BAD! */
17601791 }
17611792 cont->redo();
....@@ -1763,15 +1794,17 @@
17631794
17641795 /*
17651796 * reset is done by pulling bit 2 of DOR low for a while (old FDCs),
1766
- * or by setting the self clearing bit 7 of STATUS (newer FDCs)
1797
+ * or by setting the self clearing bit 7 of STATUS (newer FDCs).
1798
+ * This WILL trigger an interrupt, causing the handlers in the current
1799
+ * cont's ->redo() to be called via reset_interrupt().
17671800 */
17681801 static void reset_fdc(void)
17691802 {
17701803 unsigned long flags;
17711804
17721805 do_floppy = reset_interrupt;
1773
- FDCS->reset = 0;
1774
- reset_fdc_info(0);
1806
+ fdc_state[current_fdc].reset = 0;
1807
+ reset_fdc_info(current_fdc, 0);
17751808
17761809 /* Pseudo-DMA may intercept 'reset finished' interrupt. */
17771810 /* Irrelevant for systems with true DMA (i386). */
....@@ -1780,23 +1813,24 @@
17801813 fd_disable_dma();
17811814 release_dma_lock(flags);
17821815
1783
- if (FDCS->version >= FDC_82072A)
1784
- fd_outb(0x80 | (FDCS->dtr & 3), FD_STATUS);
1816
+ if (fdc_state[current_fdc].version >= FDC_82072A)
1817
+ fdc_outb(0x80 | (fdc_state[current_fdc].dtr & 3),
1818
+ current_fdc, FD_STATUS);
17851819 else {
1786
- fd_outb(FDCS->dor & ~0x04, FD_DOR);
1820
+ fdc_outb(fdc_state[current_fdc].dor & ~0x04, current_fdc, FD_DOR);
17871821 udelay(FD_RESET_DELAY);
1788
- fd_outb(FDCS->dor, FD_DOR);
1822
+ fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
17891823 }
17901824 }
17911825
1792
-static void show_floppy(void)
1826
+static void show_floppy(int fdc)
17931827 {
17941828 int i;
17951829
17961830 pr_info("\n");
17971831 pr_info("floppy driver state\n");
17981832 pr_info("-------------------\n");
1799
- pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%pf\n",
1833
+ pr_info("now=%lu last interrupt=%lu diff=%lu last called handler=%ps\n",
18001834 jiffies, interruptjiffies, jiffies - interruptjiffies,
18011835 lasthandler);
18021836
....@@ -1812,12 +1846,12 @@
18121846 print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
18131847 reply_buffer, resultsize, true);
18141848
1815
- pr_info("status=%x\n", fd_inb(FD_STATUS));
1849
+ pr_info("status=%x\n", fdc_inb(fdc, FD_STATUS));
18161850 pr_info("fdc_busy=%lu\n", fdc_busy);
18171851 if (do_floppy)
1818
- pr_info("do_floppy=%pf\n", do_floppy);
1852
+ pr_info("do_floppy=%ps\n", do_floppy);
18191853 if (work_pending(&floppy_work))
1820
- pr_info("floppy_work.func=%pf\n", floppy_work.func);
1854
+ pr_info("floppy_work.func=%ps\n", floppy_work.func);
18211855 if (delayed_work_pending(&fd_timer))
18221856 pr_info("delayed work.function=%p expires=%ld\n",
18231857 fd_timer.work.func,
....@@ -1838,7 +1872,7 @@
18381872 unsigned long flags;
18391873
18401874 if (initialized)
1841
- show_floppy();
1875
+ show_floppy(current_fdc);
18421876 cancel_activity();
18431877
18441878 flags = claim_dma_lock();
....@@ -1849,7 +1883,7 @@
18491883
18501884 if (initialized)
18511885 DPRINT("floppy timeout called\n");
1852
- FDCS->reset = 1;
1886
+ fdc_state[current_fdc].reset = 1;
18531887 if (cont) {
18541888 cont->done(0);
18551889 cont->redo(); /* this will recall reset when needed */
....@@ -1869,29 +1903,29 @@
18691903 mask = 0xfc;
18701904 data = UNIT(current_drive);
18711905 if (!(raw_cmd->flags & FD_RAW_NO_MOTOR)) {
1872
- if (!(FDCS->dor & (0x10 << UNIT(current_drive)))) {
1906
+ if (!(fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))) {
18731907 set_debugt();
18741908 /* no read since this drive is running */
1875
- DRS->first_read_date = 0;
1909
+ drive_state[current_drive].first_read_date = 0;
18761910 /* note motor start time if motor is not yet running */
1877
- DRS->spinup_date = jiffies;
1911
+ drive_state[current_drive].spinup_date = jiffies;
18781912 data |= (0x10 << UNIT(current_drive));
18791913 }
1880
- } else if (FDCS->dor & (0x10 << UNIT(current_drive)))
1914
+ } else if (fdc_state[current_fdc].dor & (0x10 << UNIT(current_drive)))
18811915 mask &= ~(0x10 << UNIT(current_drive));
18821916
18831917 /* starts motor and selects floppy */
18841918 del_timer(motor_off_timer + current_drive);
1885
- set_dor(fdc, mask, data);
1919
+ set_dor(current_fdc, mask, data);
18861920
18871921 /* wait_for_completion also schedules reset if needed. */
1888
- return fd_wait_for_completion(DRS->select_date + DP->select_delay,
1922
+ return fd_wait_for_completion(drive_state[current_drive].select_date + drive_params[current_drive].select_delay,
18891923 function);
18901924 }
18911925
18921926 static void floppy_ready(void)
18931927 {
1894
- if (FDCS->reset) {
1928
+ if (fdc_state[current_fdc].reset) {
18951929 reset_fdc();
18961930 return;
18971931 }
....@@ -1900,10 +1934,11 @@
19001934 if (fdc_dtr())
19011935 return;
19021936
1903
- debug_dcl(DP->flags, "calling disk change from floppy_ready\n");
1937
+ debug_dcl(drive_params[current_drive].flags,
1938
+ "calling disk change from floppy_ready\n");
19041939 if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) &&
1905
- disk_change(current_drive) && !DP->select_delay)
1906
- twaddle(); /* this clears the dcl on certain
1940
+ disk_change(current_drive) && !drive_params[current_drive].select_delay)
1941
+ twaddle(current_fdc, current_drive); /* this clears the dcl on certain
19071942 * drive/controller combinations */
19081943
19091944 #ifdef fd_chose_dma_mode
....@@ -1915,24 +1950,25 @@
19151950 #endif
19161951
19171952 if (raw_cmd->flags & (FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK)) {
1918
- perpendicular_mode();
1919
- fdc_specify(); /* must be done here because of hut, hlt ... */
1953
+ perpendicular_mode(current_fdc);
1954
+ fdc_specify(current_fdc, current_drive); /* must be done here because of hut, hlt ... */
19201955 seek_floppy();
19211956 } else {
19221957 if ((raw_cmd->flags & FD_RAW_READ) ||
19231958 (raw_cmd->flags & FD_RAW_WRITE))
1924
- fdc_specify();
1959
+ fdc_specify(current_fdc, current_drive);
19251960 setup_rw_floppy();
19261961 }
19271962 }
19281963
19291964 static void floppy_start(void)
19301965 {
1931
- reschedule_timeout(current_reqD, "floppy start");
1966
+ reschedule_timeout(current_drive, "floppy start");
19321967
19331968 scandrives();
1934
- debug_dcl(DP->flags, "setting NEWCHANGE in floppy_start\n");
1935
- set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
1969
+ debug_dcl(drive_params[current_drive].flags,
1970
+ "setting NEWCHANGE in floppy_start\n");
1971
+ set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
19361972 floppy_ready();
19371973 }
19381974
....@@ -1972,6 +2008,9 @@
19722008 .done = (done_f)empty
19732009 };
19742010
2011
+/* schedules handler, waiting for completion. May be interrupted, will then
2012
+ * return -EINTR, in which case the driver will automatically be unlocked.
2013
+ */
19752014 static int wait_til_done(void (*handler)(void), bool interruptible)
19762015 {
19772016 int ret;
....@@ -1990,7 +2029,7 @@
19902029 return -EINTR;
19912030 }
19922031
1993
- if (FDCS->reset)
2032
+ if (fdc_state[current_fdc].reset)
19942033 command_status = FD_COMMAND_ERROR;
19952034 if (command_status == FD_COMMAND_OKAY)
19962035 ret = 0;
....@@ -2027,18 +2066,19 @@
20272066 * ==========================
20282067 */
20292068
2030
-static int next_valid_format(void)
2069
+static int next_valid_format(int drive)
20312070 {
20322071 int probed_format;
20332072
2034
- probed_format = DRS->probed_format;
2073
+ probed_format = drive_state[drive].probed_format;
20352074 while (1) {
2036
- if (probed_format >= 8 || !DP->autodetect[probed_format]) {
2037
- DRS->probed_format = 0;
2075
+ if (probed_format >= FD_AUTODETECT_SIZE ||
2076
+ !drive_params[drive].autodetect[probed_format]) {
2077
+ drive_state[drive].probed_format = 0;
20382078 return 1;
20392079 }
2040
- if (floppy_type[DP->autodetect[probed_format]].sect) {
2041
- DRS->probed_format = probed_format;
2080
+ if (floppy_type[drive_params[drive].autodetect[probed_format]].sect) {
2081
+ drive_state[drive].probed_format = probed_format;
20422082 return 0;
20432083 }
20442084 probed_format++;
....@@ -2050,23 +2090,23 @@
20502090 int err_count;
20512091
20522092 if (probing) {
2053
- DRS->probed_format++;
2054
- if (!next_valid_format())
2093
+ drive_state[current_drive].probed_format++;
2094
+ if (!next_valid_format(current_drive))
20552095 return;
20562096 }
2057
- err_count = ++(*errors);
2058
- INFBOUND(DRWE->badness, err_count);
2059
- if (err_count > DP->max_errors.abort)
2097
+ err_count = ++floppy_errors;
2098
+ INFBOUND(write_errors[current_drive].badness, err_count);
2099
+ if (err_count > drive_params[current_drive].max_errors.abort)
20602100 cont->done(0);
2061
- if (err_count > DP->max_errors.reset)
2062
- FDCS->reset = 1;
2063
- else if (err_count > DP->max_errors.recal)
2064
- DRS->track = NEED_2_RECAL;
2101
+ if (err_count > drive_params[current_drive].max_errors.reset)
2102
+ fdc_state[current_fdc].reset = 1;
2103
+ else if (err_count > drive_params[current_drive].max_errors.recal)
2104
+ drive_state[current_drive].track = NEED_2_RECAL;
20652105 }
20662106
20672107 static void set_floppy(int drive)
20682108 {
2069
- int type = ITYPE(UDRS->fd_device);
2109
+ int type = ITYPE(drive_state[drive].fd_device);
20702110
20712111 if (type)
20722112 _floppy = floppy_type + type;
....@@ -2112,28 +2152,28 @@
21122152 FD_RAW_NEED_DISK | FD_RAW_NEED_SEEK);
21132153 raw_cmd->rate = _floppy->rate & 0x43;
21142154 raw_cmd->cmd_count = NR_F;
2115
- COMMAND = FM_MODE(_floppy, FD_FORMAT);
2116
- DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head);
2117
- F_SIZECODE = FD_SIZECODE(_floppy);
2118
- F_SECT_PER_TRACK = _floppy->sect << 2 >> F_SIZECODE;
2119
- F_GAP = _floppy->fmt_gap;
2120
- F_FILL = FD_FILL_BYTE;
2155
+ raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_FORMAT);
2156
+ raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, format_req.head);
2157
+ raw_cmd->cmd[F_SIZECODE] = FD_SIZECODE(_floppy);
2158
+ raw_cmd->cmd[F_SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[F_SIZECODE];
2159
+ raw_cmd->cmd[F_GAP] = _floppy->fmt_gap;
2160
+ raw_cmd->cmd[F_FILL] = FD_FILL_BYTE;
21212161
21222162 raw_cmd->kernel_data = floppy_track_buffer;
2123
- raw_cmd->length = 4 * F_SECT_PER_TRACK;
2163
+ raw_cmd->length = 4 * raw_cmd->cmd[F_SECT_PER_TRACK];
21242164
2125
- if (!F_SECT_PER_TRACK)
2165
+ if (!raw_cmd->cmd[F_SECT_PER_TRACK])
21262166 return;
21272167
21282168 /* allow for about 30ms for data transport per track */
2129
- head_shift = (F_SECT_PER_TRACK + 5) / 6;
2169
+ head_shift = (raw_cmd->cmd[F_SECT_PER_TRACK] + 5) / 6;
21302170
21312171 /* a ``cylinder'' is two tracks plus a little stepping time */
21322172 track_shift = 2 * head_shift + 3;
21332173
21342174 /* position of logical sector 1 on this track */
21352175 n = (track_shift * format_req.track + head_shift * format_req.head)
2136
- % F_SECT_PER_TRACK;
2176
+ % raw_cmd->cmd[F_SECT_PER_TRACK];
21372177
21382178 /* determine interleave */
21392179 il = 1;
....@@ -2141,27 +2181,27 @@
21412181 il++;
21422182
21432183 /* initialize field */
2144
- for (count = 0; count < F_SECT_PER_TRACK; ++count) {
2184
+ for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) {
21452185 here[count].track = format_req.track;
21462186 here[count].head = format_req.head;
21472187 here[count].sect = 0;
2148
- here[count].size = F_SIZECODE;
2188
+ here[count].size = raw_cmd->cmd[F_SIZECODE];
21492189 }
21502190 /* place logical sectors */
2151
- for (count = 1; count <= F_SECT_PER_TRACK; ++count) {
2191
+ for (count = 1; count <= raw_cmd->cmd[F_SECT_PER_TRACK]; ++count) {
21522192 here[n].sect = count;
2153
- n = (n + il) % F_SECT_PER_TRACK;
2193
+ n = (n + il) % raw_cmd->cmd[F_SECT_PER_TRACK];
21542194 if (here[n].sect) { /* sector busy, find next free sector */
21552195 ++n;
2156
- if (n >= F_SECT_PER_TRACK) {
2157
- n -= F_SECT_PER_TRACK;
2196
+ if (n >= raw_cmd->cmd[F_SECT_PER_TRACK]) {
2197
+ n -= raw_cmd->cmd[F_SECT_PER_TRACK];
21582198 while (here[n].sect)
21592199 ++n;
21602200 }
21612201 }
21622202 }
21632203 if (_floppy->stretch & FD_SECTBASEMASK) {
2164
- for (count = 0; count < F_SECT_PER_TRACK; count++)
2204
+ for (count = 0; count < raw_cmd->cmd[F_SECT_PER_TRACK]; count++)
21652205 here[count].sect += FD_SECTBASE(_floppy) - 1;
21662206 }
21672207 }
....@@ -2190,7 +2230,7 @@
21902230
21912231 set_floppy(drive);
21922232 if (!_floppy ||
2193
- _floppy->track > DP->tracks ||
2233
+ _floppy->track > drive_params[current_drive].tracks ||
21942234 tmp_format_req->track >= _floppy->track ||
21952235 tmp_format_req->head >= _floppy->head ||
21962236 (_floppy->sect << 2) % (1 << FD_SIZECODE(_floppy)) ||
....@@ -2199,9 +2239,8 @@
21992239 return -EINVAL;
22002240 }
22012241 format_req = *tmp_format_req;
2202
- format_errors = 0;
22032242 cont = &format_cont;
2204
- errors = &format_errors;
2243
+ floppy_errors = 0;
22052244 ret = wait_til_done(redo_format, true);
22062245 if (ret == -EINTR)
22072246 return -EINTR;
....@@ -2222,8 +2261,9 @@
22222261 /* current_count_sectors can be zero if transfer failed */
22232262 if (error)
22242263 nr_sectors = blk_rq_cur_sectors(req);
2225
- if (__blk_end_request(req, error, nr_sectors << 9))
2264
+ if (blk_update_request(req, error, nr_sectors << 9))
22262265 return;
2266
+ __blk_mq_end_request(req, error);
22272267
22282268 /* We're done with the request */
22292269 floppy_off(drive);
....@@ -2235,8 +2275,6 @@
22352275 static void request_done(int uptodate)
22362276 {
22372277 struct request *req = current_req;
2238
- struct request_queue *q;
2239
- unsigned long flags;
22402278 int block;
22412279 char msg[sizeof("request done ") + sizeof(int) * 3];
22422280
....@@ -2249,34 +2287,27 @@
22492287 return;
22502288 }
22512289
2252
- q = req->q;
2253
-
22542290 if (uptodate) {
22552291 /* maintain values for invalidation on geometry
22562292 * change */
22572293 block = current_count_sectors + blk_rq_pos(req);
2258
- INFBOUND(DRS->maxblock, block);
2294
+ INFBOUND(drive_state[current_drive].maxblock, block);
22592295 if (block > _floppy->sect)
2260
- DRS->maxtrack = 1;
2296
+ drive_state[current_drive].maxtrack = 1;
22612297
2262
- /* unlock chained buffers */
2263
- spin_lock_irqsave(q->queue_lock, flags);
22642298 floppy_end_request(req, 0);
2265
- spin_unlock_irqrestore(q->queue_lock, flags);
22662299 } else {
22672300 if (rq_data_dir(req) == WRITE) {
22682301 /* record write error information */
2269
- DRWE->write_errors++;
2270
- if (DRWE->write_errors == 1) {
2271
- DRWE->first_error_sector = blk_rq_pos(req);
2272
- DRWE->first_error_generation = DRS->generation;
2302
+ write_errors[current_drive].write_errors++;
2303
+ if (write_errors[current_drive].write_errors == 1) {
2304
+ write_errors[current_drive].first_error_sector = blk_rq_pos(req);
2305
+ write_errors[current_drive].first_error_generation = drive_state[current_drive].generation;
22732306 }
2274
- DRWE->last_error_sector = blk_rq_pos(req);
2275
- DRWE->last_error_generation = DRS->generation;
2307
+ write_errors[current_drive].last_error_sector = blk_rq_pos(req);
2308
+ write_errors[current_drive].last_error_generation = drive_state[current_drive].generation;
22762309 }
2277
- spin_lock_irqsave(q->queue_lock, flags);
22782310 floppy_end_request(req, BLK_STS_IOERR);
2279
- spin_unlock_irqrestore(q->queue_lock, flags);
22802311 }
22812312 }
22822313
....@@ -2288,43 +2319,46 @@
22882319 int heads;
22892320 int nr_sectors;
22902321
2291
- if (R_HEAD >= 2) {
2322
+ if (reply_buffer[R_HEAD] >= 2) {
22922323 /* some Toshiba floppy controllers occasionnally seem to
22932324 * return bogus interrupts after read/write operations, which
22942325 * can be recognized by a bad head number (>= 2) */
22952326 return;
22962327 }
22972328
2298
- if (!DRS->first_read_date)
2299
- DRS->first_read_date = jiffies;
2329
+ if (!drive_state[current_drive].first_read_date)
2330
+ drive_state[current_drive].first_read_date = jiffies;
23002331
23012332 nr_sectors = 0;
2302
- ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
2333
+ ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
23032334
2304
- if (ST1 & ST1_EOC)
2335
+ if (reply_buffer[ST1] & ST1_EOC)
23052336 eoc = 1;
23062337 else
23072338 eoc = 0;
23082339
2309
- if (COMMAND & 0x80)
2340
+ if (raw_cmd->cmd[COMMAND] & 0x80)
23102341 heads = 2;
23112342 else
23122343 heads = 1;
23132344
2314
- nr_sectors = (((R_TRACK - TRACK) * heads +
2315
- R_HEAD - HEAD) * SECT_PER_TRACK +
2316
- R_SECTOR - SECTOR + eoc) << SIZECODE >> 2;
2345
+ nr_sectors = (((reply_buffer[R_TRACK] - raw_cmd->cmd[TRACK]) * heads +
2346
+ reply_buffer[R_HEAD] - raw_cmd->cmd[HEAD]) * raw_cmd->cmd[SECT_PER_TRACK] +
2347
+ reply_buffer[R_SECTOR] - raw_cmd->cmd[SECTOR] + eoc) << raw_cmd->cmd[SIZECODE] >> 2;
23172348
23182349 if (nr_sectors / ssize >
23192350 DIV_ROUND_UP(in_sector_offset + current_count_sectors, ssize)) {
23202351 DPRINT("long rw: %x instead of %lx\n",
23212352 nr_sectors, current_count_sectors);
2322
- pr_info("rs=%d s=%d\n", R_SECTOR, SECTOR);
2323
- pr_info("rh=%d h=%d\n", R_HEAD, HEAD);
2324
- pr_info("rt=%d t=%d\n", R_TRACK, TRACK);
2353
+ pr_info("rs=%d s=%d\n", reply_buffer[R_SECTOR],
2354
+ raw_cmd->cmd[SECTOR]);
2355
+ pr_info("rh=%d h=%d\n", reply_buffer[R_HEAD],
2356
+ raw_cmd->cmd[HEAD]);
2357
+ pr_info("rt=%d t=%d\n", reply_buffer[R_TRACK],
2358
+ raw_cmd->cmd[TRACK]);
23252359 pr_info("heads=%d eoc=%d\n", heads, eoc);
23262360 pr_info("spt=%d st=%d ss=%d\n",
2327
- SECT_PER_TRACK, fsector_t, ssize);
2361
+ raw_cmd->cmd[SECT_PER_TRACK], fsector_t, ssize);
23282362 pr_info("in_sector_offset=%d\n", in_sector_offset);
23292363 }
23302364
....@@ -2354,7 +2388,7 @@
23542388 }
23552389
23562390 if (probing) {
2357
- if (DP->flags & FTD_MSG)
2391
+ if (drive_params[current_drive].flags & FTD_MSG)
23582392 DPRINT("Auto-detected floppy type %s in fd%d\n",
23592393 _floppy->name, current_drive);
23602394 current_type[current_drive] = _floppy;
....@@ -2362,11 +2396,11 @@
23622396 probing = 0;
23632397 }
23642398
2365
- if (CT(COMMAND) != FD_READ ||
2399
+ if (CT(raw_cmd->cmd[COMMAND]) != FD_READ ||
23662400 raw_cmd->kernel_data == bio_data(current_req->bio)) {
23672401 /* transfer directly from buffer */
23682402 cont->done(1);
2369
- } else if (CT(COMMAND) == FD_READ) {
2403
+ } else if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) {
23702404 buffer_track = raw_cmd->track;
23712405 buffer_drive = current_drive;
23722406 INFBOUND(buffer_max, nr_sectors + fsector_t);
....@@ -2425,13 +2459,13 @@
24252459 min(max_sector, max_sector_2),
24262460 blk_rq_sectors(current_req));
24272461
2428
- if (current_count_sectors <= 0 && CT(COMMAND) == FD_WRITE &&
2462
+ if (current_count_sectors <= 0 && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE &&
24292463 buffer_max > fsector_t + blk_rq_sectors(current_req))
24302464 current_count_sectors = min_t(int, buffer_max - fsector_t,
24312465 blk_rq_sectors(current_req));
24322466
24332467 remaining = current_count_sectors << 9;
2434
- if (remaining > blk_rq_bytes(current_req) && CT(COMMAND) == FD_WRITE) {
2468
+ if (remaining > blk_rq_bytes(current_req) && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
24352469 DPRINT("in copy buffer\n");
24362470 pr_info("current_count_sectors=%ld\n", current_count_sectors);
24372471 pr_info("remaining=%d\n", remaining >> 9);
....@@ -2466,16 +2500,16 @@
24662500 fsector_t, buffer_min);
24672501 pr_info("current_count_sectors=%ld\n",
24682502 current_count_sectors);
2469
- if (CT(COMMAND) == FD_READ)
2503
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
24702504 pr_info("read\n");
2471
- if (CT(COMMAND) == FD_WRITE)
2505
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE)
24722506 pr_info("write\n");
24732507 break;
24742508 }
24752509 if (((unsigned long)buffer) % 512)
24762510 DPRINT("%p buffer not aligned\n", buffer);
24772511
2478
- if (CT(COMMAND) == FD_READ)
2512
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
24792513 memcpy(buffer, dma_buffer, size);
24802514 else
24812515 memcpy(dma_buffer, buffer, size);
....@@ -2493,7 +2527,7 @@
24932527 /* work around a bug in pseudo DMA
24942528 * (on some FDCs) pseudo DMA does not stop when the CPU stops
24952529 * sending data. Hence we need a different way to signal the
2496
- * transfer length: We use SECT_PER_TRACK. Unfortunately, this
2530
+ * transfer length: We use raw_cmd->cmd[SECT_PER_TRACK]. Unfortunately, this
24972531 * does not work with MT, hence we can only transfer one head at
24982532 * a time
24992533 */
....@@ -2502,18 +2536,18 @@
25022536 int hard_sectors;
25032537 int end_sector;
25042538
2505
- if (CT(COMMAND) == FD_WRITE) {
2506
- COMMAND &= ~0x80; /* switch off multiple track mode */
2539
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
2540
+ raw_cmd->cmd[COMMAND] &= ~0x80; /* switch off multiple track mode */
25072541
2508
- hard_sectors = raw_cmd->length >> (7 + SIZECODE);
2509
- end_sector = SECTOR + hard_sectors - 1;
2510
- if (end_sector > SECT_PER_TRACK) {
2542
+ hard_sectors = raw_cmd->length >> (7 + raw_cmd->cmd[SIZECODE]);
2543
+ end_sector = raw_cmd->cmd[SECTOR] + hard_sectors - 1;
2544
+ if (end_sector > raw_cmd->cmd[SECT_PER_TRACK]) {
25112545 pr_info("too many sectors %d > %d\n",
2512
- end_sector, SECT_PER_TRACK);
2546
+ end_sector, raw_cmd->cmd[SECT_PER_TRACK]);
25132547 return;
25142548 }
2515
- SECT_PER_TRACK = end_sector;
2516
- /* make sure SECT_PER_TRACK
2549
+ raw_cmd->cmd[SECT_PER_TRACK] = end_sector;
2550
+ /* make sure raw_cmd->cmd[SECT_PER_TRACK]
25172551 * points to end of transfer */
25182552 }
25192553 }
....@@ -2546,10 +2580,10 @@
25462580 raw_cmd->cmd_count = NR_RW;
25472581 if (rq_data_dir(current_req) == READ) {
25482582 raw_cmd->flags |= FD_RAW_READ;
2549
- COMMAND = FM_MODE(_floppy, FD_READ);
2583
+ raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ);
25502584 } else if (rq_data_dir(current_req) == WRITE) {
25512585 raw_cmd->flags |= FD_RAW_WRITE;
2552
- COMMAND = FM_MODE(_floppy, FD_WRITE);
2586
+ raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_WRITE);
25532587 } else {
25542588 DPRINT("%s: unknown command\n", __func__);
25552589 return 0;
....@@ -2557,24 +2591,24 @@
25572591
25582592 max_sector = _floppy->sect * _floppy->head;
25592593
2560
- TRACK = (int)blk_rq_pos(current_req) / max_sector;
2594
+ raw_cmd->cmd[TRACK] = (int)blk_rq_pos(current_req) / max_sector;
25612595 fsector_t = (int)blk_rq_pos(current_req) % max_sector;
2562
- if (_floppy->track && TRACK >= _floppy->track) {
2596
+ if (_floppy->track && raw_cmd->cmd[TRACK] >= _floppy->track) {
25632597 if (blk_rq_cur_sectors(current_req) & 1) {
25642598 current_count_sectors = 1;
25652599 return 1;
25662600 } else
25672601 return 0;
25682602 }
2569
- HEAD = fsector_t / _floppy->sect;
2603
+ raw_cmd->cmd[HEAD] = fsector_t / _floppy->sect;
25702604
25712605 if (((_floppy->stretch & (FD_SWAPSIDES | FD_SECTBASEMASK)) ||
2572
- test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags)) &&
2606
+ test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags)) &&
25732607 fsector_t < _floppy->sect)
25742608 max_sector = _floppy->sect;
25752609
25762610 /* 2M disks have phantom sectors on the first track */
2577
- if ((_floppy->rate & FD_2M) && (!TRACK) && (!HEAD)) {
2611
+ if ((_floppy->rate & FD_2M) && (!raw_cmd->cmd[TRACK]) && (!raw_cmd->cmd[HEAD])) {
25782612 max_sector = 2 * _floppy->sect / 3;
25792613 if (fsector_t >= max_sector) {
25802614 current_count_sectors =
....@@ -2582,23 +2616,24 @@
25822616 blk_rq_sectors(current_req));
25832617 return 1;
25842618 }
2585
- SIZECODE = 2;
2619
+ raw_cmd->cmd[SIZECODE] = 2;
25862620 } else
2587
- SIZECODE = FD_SIZECODE(_floppy);
2621
+ raw_cmd->cmd[SIZECODE] = FD_SIZECODE(_floppy);
25882622 raw_cmd->rate = _floppy->rate & 0x43;
2589
- if ((_floppy->rate & FD_2M) && (TRACK || HEAD) && raw_cmd->rate == 2)
2623
+ if ((_floppy->rate & FD_2M) &&
2624
+ (raw_cmd->cmd[TRACK] || raw_cmd->cmd[HEAD]) && raw_cmd->rate == 2)
25902625 raw_cmd->rate = 1;
25912626
2592
- if (SIZECODE)
2593
- SIZECODE2 = 0xff;
2627
+ if (raw_cmd->cmd[SIZECODE])
2628
+ raw_cmd->cmd[SIZECODE2] = 0xff;
25942629 else
2595
- SIZECODE2 = 0x80;
2596
- raw_cmd->track = TRACK << STRETCH(_floppy);
2597
- DR_SELECT = UNIT(current_drive) + PH_HEAD(_floppy, HEAD);
2598
- GAP = _floppy->gap;
2599
- ssize = DIV_ROUND_UP(1 << SIZECODE, 4);
2600
- SECT_PER_TRACK = _floppy->sect << 2 >> SIZECODE;
2601
- SECTOR = ((fsector_t % _floppy->sect) << 2 >> SIZECODE) +
2630
+ raw_cmd->cmd[SIZECODE2] = 0x80;
2631
+ raw_cmd->track = raw_cmd->cmd[TRACK] << STRETCH(_floppy);
2632
+ raw_cmd->cmd[DR_SELECT] = UNIT(current_drive) + PH_HEAD(_floppy, raw_cmd->cmd[HEAD]);
2633
+ raw_cmd->cmd[GAP] = _floppy->gap;
2634
+ ssize = DIV_ROUND_UP(1 << raw_cmd->cmd[SIZECODE], 4);
2635
+ raw_cmd->cmd[SECT_PER_TRACK] = _floppy->sect << 2 >> raw_cmd->cmd[SIZECODE];
2636
+ raw_cmd->cmd[SECTOR] = ((fsector_t % _floppy->sect) << 2 >> raw_cmd->cmd[SIZECODE]) +
26022637 FD_SECTBASE(_floppy);
26032638
26042639 /* tracksize describes the size which can be filled up with sectors
....@@ -2606,24 +2641,24 @@
26062641 */
26072642 tracksize = _floppy->sect - _floppy->sect % ssize;
26082643 if (tracksize < _floppy->sect) {
2609
- SECT_PER_TRACK++;
2644
+ raw_cmd->cmd[SECT_PER_TRACK]++;
26102645 if (tracksize <= fsector_t % _floppy->sect)
2611
- SECTOR--;
2646
+ raw_cmd->cmd[SECTOR]--;
26122647
26132648 /* if we are beyond tracksize, fill up using smaller sectors */
26142649 while (tracksize <= fsector_t % _floppy->sect) {
26152650 while (tracksize + ssize > _floppy->sect) {
2616
- SIZECODE--;
2651
+ raw_cmd->cmd[SIZECODE]--;
26172652 ssize >>= 1;
26182653 }
2619
- SECTOR++;
2620
- SECT_PER_TRACK++;
2654
+ raw_cmd->cmd[SECTOR]++;
2655
+ raw_cmd->cmd[SECT_PER_TRACK]++;
26212656 tracksize += ssize;
26222657 }
2623
- max_sector = HEAD * _floppy->sect + tracksize;
2624
- } else if (!TRACK && !HEAD && !(_floppy->rate & FD_2M) && probing) {
2658
+ max_sector = raw_cmd->cmd[HEAD] * _floppy->sect + tracksize;
2659
+ } else if (!raw_cmd->cmd[TRACK] && !raw_cmd->cmd[HEAD] && !(_floppy->rate & FD_2M) && probing) {
26252660 max_sector = _floppy->sect;
2626
- } else if (!HEAD && CT(COMMAND) == FD_WRITE) {
2661
+ } else if (!raw_cmd->cmd[HEAD] && CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
26272662 /* for virtual DMA bug workaround */
26282663 max_sector = _floppy->sect;
26292664 }
....@@ -2635,12 +2670,12 @@
26352670 (current_drive == buffer_drive) &&
26362671 (fsector_t >= buffer_min) && (fsector_t < buffer_max)) {
26372672 /* data already in track buffer */
2638
- if (CT(COMMAND) == FD_READ) {
2673
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ) {
26392674 copy_buffer(1, max_sector, buffer_max);
26402675 return 1;
26412676 }
26422677 } else if (in_sector_offset || blk_rq_sectors(current_req) < ssize) {
2643
- if (CT(COMMAND) == FD_WRITE) {
2678
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
26442679 unsigned int sectors;
26452680
26462681 sectors = fsector_t + blk_rq_sectors(current_req);
....@@ -2651,7 +2686,7 @@
26512686 }
26522687 raw_cmd->flags &= ~FD_RAW_WRITE;
26532688 raw_cmd->flags |= FD_RAW_READ;
2654
- COMMAND = FM_MODE(_floppy, FD_READ);
2689
+ raw_cmd->cmd[COMMAND] = FM_MODE(_floppy, FD_READ);
26552690 } else if ((unsigned long)bio_data(current_req->bio) < MAX_DMA_ADDRESS) {
26562691 unsigned long dma_limit;
26572692 int direct, indirect;
....@@ -2684,9 +2719,9 @@
26842719 */
26852720 if (!direct ||
26862721 (indirect * 2 > direct * 3 &&
2687
- *errors < DP->max_errors.read_track &&
2722
+ floppy_errors < drive_params[current_drive].max_errors.read_track &&
26882723 ((!probing ||
2689
- (DP->read_track & (1 << DRS->probed_format)))))) {
2724
+ (drive_params[current_drive].read_track & (1 << drive_state[current_drive].probed_format)))))) {
26902725 max_size = blk_rq_sectors(current_req);
26912726 } else {
26922727 raw_cmd->kernel_data = bio_data(current_req->bio);
....@@ -2702,7 +2737,7 @@
27022737 }
27032738 }
27042739
2705
- if (CT(COMMAND) == FD_READ)
2740
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
27062741 max_size = max_sector; /* unbounded */
27072742
27082743 /* claim buffer track if needed */
....@@ -2710,7 +2745,7 @@
27102745 buffer_drive != current_drive || /* bad drive */
27112746 fsector_t > buffer_max ||
27122747 fsector_t < buffer_min ||
2713
- ((CT(COMMAND) == FD_READ ||
2748
+ ((CT(raw_cmd->cmd[COMMAND]) == FD_READ ||
27142749 (!in_sector_offset && blk_rq_sectors(current_req) >= ssize)) &&
27152750 max_sector > 2 * max_buffer_sectors + buffer_min &&
27162751 max_size + fsector_t > 2 * max_buffer_sectors + buffer_min)) {
....@@ -2722,7 +2757,7 @@
27222757 raw_cmd->kernel_data = floppy_track_buffer +
27232758 ((aligned_sector_t - buffer_min) << 9);
27242759
2725
- if (CT(COMMAND) == FD_WRITE) {
2760
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE) {
27262761 /* copy write buffer to track buffer.
27272762 * if we get here, we know that the write
27282763 * is either aligned or the data already in the buffer
....@@ -2744,10 +2779,10 @@
27442779 raw_cmd->length <<= 9;
27452780 if ((raw_cmd->length < current_count_sectors << 9) ||
27462781 (raw_cmd->kernel_data != bio_data(current_req->bio) &&
2747
- CT(COMMAND) == FD_WRITE &&
2782
+ CT(raw_cmd->cmd[COMMAND]) == FD_WRITE &&
27482783 (aligned_sector_t + (raw_cmd->length >> 9) > buffer_max ||
27492784 aligned_sector_t < buffer_min)) ||
2750
- raw_cmd->length % (128 << SIZECODE) ||
2785
+ raw_cmd->length % (128 << raw_cmd->cmd[SIZECODE]) ||
27512786 raw_cmd->length <= 0 || current_count_sectors <= 0) {
27522787 DPRINT("fractionary current count b=%lx s=%lx\n",
27532788 raw_cmd->length, current_count_sectors);
....@@ -2758,9 +2793,10 @@
27582793 current_count_sectors);
27592794 pr_info("st=%d ast=%d mse=%d msi=%d\n",
27602795 fsector_t, aligned_sector_t, max_sector, max_size);
2761
- pr_info("ssize=%x SIZECODE=%d\n", ssize, SIZECODE);
2796
+ pr_info("ssize=%x SIZECODE=%d\n", ssize, raw_cmd->cmd[SIZECODE]);
27622797 pr_info("command=%x SECTOR=%d HEAD=%d, TRACK=%d\n",
2763
- COMMAND, SECTOR, HEAD, TRACK);
2798
+ raw_cmd->cmd[COMMAND], raw_cmd->cmd[SECTOR],
2799
+ raw_cmd->cmd[HEAD], raw_cmd->cmd[TRACK]);
27642800 pr_info("buffer drive=%d\n", buffer_drive);
27652801 pr_info("buffer track=%d\n", buffer_track);
27662802 pr_info("buffer_min=%d\n", buffer_min);
....@@ -2779,9 +2815,9 @@
27792815 fsector_t, buffer_min, raw_cmd->length >> 9);
27802816 pr_info("current_count_sectors=%ld\n",
27812817 current_count_sectors);
2782
- if (CT(COMMAND) == FD_READ)
2818
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_READ)
27832819 pr_info("read\n");
2784
- if (CT(COMMAND) == FD_WRITE)
2820
+ if (CT(raw_cmd->cmd[COMMAND]) == FD_WRITE)
27852821 pr_info("write\n");
27862822 return 0;
27872823 }
....@@ -2803,30 +2839,21 @@
28032839 return 2;
28042840 }
28052841
2806
-/*
2807
- * Round-robin between our available drives, doing one request from each
2808
- */
28092842 static int set_next_request(void)
28102843 {
2811
- struct request_queue *q;
2812
- int old_pos = fdc_queue;
2813
-
2814
- do {
2815
- q = disks[fdc_queue]->queue;
2816
- if (++fdc_queue == N_DRIVE)
2817
- fdc_queue = 0;
2818
- if (q) {
2819
- current_req = blk_fetch_request(q);
2820
- if (current_req) {
2821
- current_req->error_count = 0;
2822
- break;
2823
- }
2824
- }
2825
- } while (fdc_queue != old_pos);
2826
-
2827
- return current_req != NULL;
2844
+ current_req = list_first_entry_or_null(&floppy_reqs, struct request,
2845
+ queuelist);
2846
+ if (current_req) {
2847
+ floppy_errors = 0;
2848
+ list_del_init(&current_req->queuelist);
2849
+ return 1;
2850
+ }
2851
+ return 0;
28282852 }
28292853
2854
+/* Starts or continues processing request. Will automatically unlock the
2855
+ * driver at end of request.
2856
+ */
28302857 static void redo_fd_request(void)
28312858 {
28322859 int drive;
....@@ -2851,7 +2878,7 @@
28512878 }
28522879 drive = (long)current_req->rq_disk->private_data;
28532880 set_fdc(drive);
2854
- reschedule_timeout(current_reqD, "redo fd request");
2881
+ reschedule_timeout(current_drive, "redo fd request");
28552882
28562883 set_floppy(drive);
28572884 raw_cmd = &default_raw_cmd;
....@@ -2861,15 +2888,15 @@
28612888
28622889 disk_change(current_drive);
28632890 if (test_bit(current_drive, &fake_change) ||
2864
- test_bit(FD_DISK_CHANGED_BIT, &DRS->flags)) {
2891
+ test_bit(FD_DISK_CHANGED_BIT, &drive_state[current_drive].flags)) {
28652892 DPRINT("disk absent or changed during operation\n");
28662893 request_done(0);
28672894 goto do_request;
28682895 }
28692896 if (!_floppy) { /* Autodetection */
28702897 if (!probing) {
2871
- DRS->probed_format = 0;
2872
- if (next_valid_format()) {
2898
+ drive_state[current_drive].probed_format = 0;
2899
+ if (next_valid_format(current_drive)) {
28732900 DPRINT("no autodetectable formats\n");
28742901 _floppy = NULL;
28752902 request_done(0);
....@@ -2877,18 +2904,17 @@
28772904 }
28782905 }
28792906 probing = 1;
2880
- _floppy = floppy_type + DP->autodetect[DRS->probed_format];
2907
+ _floppy = floppy_type + drive_params[current_drive].autodetect[drive_state[current_drive].probed_format];
28812908 } else
28822909 probing = 0;
2883
- errors = &(current_req->error_count);
28842910 tmp = make_raw_rw_request();
28852911 if (tmp < 2) {
28862912 request_done(tmp);
28872913 goto do_request;
28882914 }
28892915
2890
- if (test_bit(FD_NEED_TWADDLE_BIT, &DRS->flags))
2891
- twaddle();
2916
+ if (test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags))
2917
+ twaddle(current_fdc, current_drive);
28922918 schedule_bh(floppy_start);
28932919 debugt(__func__, "queue fd request");
28942920 return;
....@@ -2901,35 +2927,45 @@
29012927 .done = request_done
29022928 };
29032929
2930
+/* schedule the request and automatically unlock the driver on completion */
29042931 static void process_fd_request(void)
29052932 {
29062933 cont = &rw_cont;
29072934 schedule_bh(redo_fd_request);
29082935 }
29092936
2910
-static void do_fd_request(struct request_queue *q)
2937
+static blk_status_t floppy_queue_rq(struct blk_mq_hw_ctx *hctx,
2938
+ const struct blk_mq_queue_data *bd)
29112939 {
2940
+ blk_mq_start_request(bd->rq);
2941
+
29122942 if (WARN(max_buffer_sectors == 0,
29132943 "VFS: %s called on non-open device\n", __func__))
2914
- return;
2944
+ return BLK_STS_IOERR;
29152945
29162946 if (WARN(atomic_read(&usage_count) == 0,
29172947 "warning: usage count=0, current_req=%p sect=%ld flags=%llx\n",
29182948 current_req, (long)blk_rq_pos(current_req),
29192949 (unsigned long long) current_req->cmd_flags))
2920
- return;
2950
+ return BLK_STS_IOERR;
29212951
29222952 if (test_and_set_bit(0, &fdc_busy)) {
29232953 /* fdc busy, this new request will be treated when the
29242954 current one is done */
29252955 is_alive(__func__, "old request running");
2926
- return;
2956
+ return BLK_STS_RESOURCE;
29272957 }
2958
+
2959
+ spin_lock_irq(&floppy_lock);
2960
+ list_add_tail(&bd->rq->queuelist, &floppy_reqs);
2961
+ spin_unlock_irq(&floppy_lock);
2962
+
29282963 command_status = FD_COMMAND_NONE;
29292964 __reschedule_timeout(MAXTIMEOUT, "fd_request");
29302965 set_fdc(0);
29312966 process_fd_request();
29322967 is_alive(__func__, "");
2968
+ return BLK_STS_OK;
29332969 }
29342970
29352971 static const struct cont_t poll_cont = {
....@@ -2947,8 +2983,9 @@
29472983 raw_cmd->track = 0;
29482984 raw_cmd->cmd_count = 0;
29492985 cont = &poll_cont;
2950
- debug_dcl(DP->flags, "setting NEWCHANGE in poll_drive\n");
2951
- set_bit(FD_DISK_NEWCHANGE_BIT, &DRS->flags);
2986
+ debug_dcl(drive_params[current_drive].flags,
2987
+ "setting NEWCHANGE in poll_drive\n");
2988
+ set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[current_drive].flags);
29522989
29532990 return wait_til_done(floppy_ready, interruptible);
29542991 }
....@@ -2970,6 +3007,10 @@
29703007 .done = generic_done
29713008 };
29723009
3010
+/*
3011
+ * Resets the FDC connected to drive <drive>.
3012
+ * Both current_drive and current_fdc are changed to match the new drive.
3013
+ */
29733014 static int user_reset_fdc(int drive, int arg, bool interruptible)
29743015 {
29753016 int ret;
....@@ -2978,8 +3019,11 @@
29783019 return -EINTR;
29793020
29803021 if (arg == FD_RESET_ALWAYS)
2981
- FDCS->reset = 1;
2982
- if (FDCS->reset) {
3022
+ fdc_state[current_fdc].reset = 1;
3023
+ if (fdc_state[current_fdc].reset) {
3024
+ /* note: reset_fdc will take care of unlocking the driver
3025
+ * on completion.
3026
+ */
29833027 cont = &reset_cont;
29843028 ret = wait_til_done(reset_fdc, interruptible);
29853029 if (ret == -EINTR)
....@@ -3012,8 +3056,8 @@
30123056 if (type)
30133057 floppy = floppy_type + type;
30143058 else {
3015
- if (UDP->native_format)
3016
- floppy = floppy_type + UDP->native_format;
3059
+ if (drive_params[drive].native_format)
3060
+ floppy = floppy_type + drive_params[drive].native_format;
30173061 else
30183062 return "(null)";
30193063 }
....@@ -3022,6 +3066,8 @@
30223066 else
30233067 return "(null)";
30243068 }
3069
+
3070
+#ifdef CONFIG_BLK_DEV_FD_RAWCMD
30253071
30263072 /* raw commands */
30273073 static void raw_cmd_done(int flag)
....@@ -3033,7 +3079,7 @@
30333079 raw_cmd->flags |= FD_RAW_HARDFAILURE;
30343080 } else {
30353081 raw_cmd->reply_count = inr;
3036
- if (raw_cmd->reply_count > MAX_REPLIES)
3082
+ if (raw_cmd->reply_count > FD_RAW_REPLY_SIZE)
30373083 raw_cmd->reply_count = 0;
30383084 for (i = 0; i < raw_cmd->reply_count; i++)
30393085 raw_cmd->reply[i] = reply_buffer[i];
....@@ -3146,18 +3192,10 @@
31463192 if (ret)
31473193 return -EFAULT;
31483194 param += sizeof(struct floppy_raw_cmd);
3149
- if (ptr->cmd_count > 33)
3150
- /* the command may now also take up the space
3151
- * initially intended for the reply & the
3152
- * reply count. Needed for long 82078 commands
3153
- * such as RESTORE, which takes ... 17 command
3154
- * bytes. Murphy's law #137: When you reserve
3155
- * 16 bytes for a structure, you'll one day
3156
- * discover that you really need 17...
3157
- */
3195
+ if (ptr->cmd_count > FD_RAW_CMD_FULLSIZE)
31583196 return -EINVAL;
31593197
3160
- for (i = 0; i < 16; i++)
3198
+ for (i = 0; i < FD_RAW_REPLY_SIZE; i++)
31613199 ptr->reply[i] = 0;
31623200 ptr->resultcode = 0;
31633201
....@@ -3192,23 +3230,23 @@
31923230 int ret2;
31933231 int ret;
31943232
3195
- if (FDCS->rawcmd <= 1)
3196
- FDCS->rawcmd = 1;
3233
+ if (fdc_state[current_fdc].rawcmd <= 1)
3234
+ fdc_state[current_fdc].rawcmd = 1;
31973235 for (drive = 0; drive < N_DRIVE; drive++) {
3198
- if (FDC(drive) != fdc)
3236
+ if (FDC(drive) != current_fdc)
31993237 continue;
32003238 if (drive == current_drive) {
3201
- if (UDRS->fd_ref > 1) {
3202
- FDCS->rawcmd = 2;
3239
+ if (drive_state[drive].fd_ref > 1) {
3240
+ fdc_state[current_fdc].rawcmd = 2;
32033241 break;
32043242 }
3205
- } else if (UDRS->fd_ref) {
3206
- FDCS->rawcmd = 2;
3243
+ } else if (drive_state[drive].fd_ref) {
3244
+ fdc_state[current_fdc].rawcmd = 2;
32073245 break;
32083246 }
32093247 }
32103248
3211
- if (FDCS->reset)
3249
+ if (fdc_state[current_fdc].reset)
32123250 return -EIO;
32133251
32143252 ret = raw_cmd_copyin(cmd, param, &my_raw_cmd);
....@@ -3220,12 +3258,13 @@
32203258 raw_cmd = my_raw_cmd;
32213259 cont = &raw_cmd_cont;
32223260 ret = wait_til_done(floppy_start, true);
3223
- debug_dcl(DP->flags, "calling disk change from raw_cmd ioctl\n");
3261
+ debug_dcl(drive_params[current_drive].flags,
3262
+ "calling disk change from raw_cmd ioctl\n");
32243263
3225
- if (ret != -EINTR && FDCS->reset)
3264
+ if (ret != -EINTR && fdc_state[current_fdc].reset)
32263265 ret = -EIO;
32273266
3228
- DRS->track = NO_TRACK;
3267
+ drive_state[current_drive].track = NO_TRACK;
32293268
32303269 ret2 = raw_cmd_copyout(cmd, param, my_raw_cmd);
32313270 if (!ret)
....@@ -3234,12 +3273,42 @@
32343273 return ret;
32353274 }
32363275
3276
+static int floppy_raw_cmd_ioctl(int type, int drive, int cmd,
3277
+ void __user *param)
3278
+{
3279
+ int ret;
3280
+
3281
+ pr_warn_once("Note: FDRAWCMD is deprecated and will be removed from the kernel in the near future.\n");
3282
+
3283
+ if (type)
3284
+ return -EINVAL;
3285
+ if (lock_fdc(drive))
3286
+ return -EINTR;
3287
+ set_floppy(drive);
3288
+ ret = raw_cmd_ioctl(cmd, param);
3289
+ if (ret == -EINTR)
3290
+ return -EINTR;
3291
+ process_fd_request();
3292
+ return ret;
3293
+}
3294
+
3295
+#else /* CONFIG_BLK_DEV_FD_RAWCMD */
3296
+
3297
+static int floppy_raw_cmd_ioctl(int type, int drive, int cmd,
3298
+ void __user *param)
3299
+{
3300
+ return -EOPNOTSUPP;
3301
+}
3302
+
3303
+#endif
3304
+
32373305 static int invalidate_drive(struct block_device *bdev)
32383306 {
32393307 /* invalidate the buffer track to force a reread */
32403308 set_bit((long)bdev->bd_disk->private_data, &fake_change);
32413309 process_fd_request();
3242
- check_disk_change(bdev);
3310
+ if (bdev_check_media_change(bdev))
3311
+ floppy_revalidate(bdev->bd_disk);
32433312 return 0;
32443313 }
32453314
....@@ -3253,9 +3322,9 @@
32533322 (int)g->head <= 0 ||
32543323 /* check for overflow in max_sector */
32553324 (int)(g->sect * g->head) <= 0 ||
3256
- /* check for zero in F_SECT_PER_TRACK */
3325
+ /* check for zero in raw_cmd->cmd[F_SECT_PER_TRACK] */
32573326 (unsigned char)((g->sect << 2) >> FD_SIZECODE(g)) == 0 ||
3258
- g->track <= 0 || g->track > UDP->tracks >> STRETCH(g) ||
3327
+ g->track <= 0 || g->track > drive_params[drive].tracks >> STRETCH(g) ||
32593328 /* check if reserved bits are set */
32603329 (g->stretch & ~(FD_STRETCH | FD_SWAPSIDES | FD_SECTBASEMASK)) != 0)
32613330 return -EINVAL;
....@@ -3298,16 +3367,16 @@
32983367 current_type[drive] = &user_params[drive];
32993368 floppy_sizes[drive] = user_params[drive].size;
33003369 if (cmd == FDDEFPRM)
3301
- DRS->keep_data = -1;
3370
+ drive_state[current_drive].keep_data = -1;
33023371 else
3303
- DRS->keep_data = 1;
3372
+ drive_state[current_drive].keep_data = 1;
33043373 /* invalidation. Invalidate only when needed, i.e.
33053374 * when there are already sectors in the buffer cache
33063375 * whose number will change. This is useful, because
33073376 * mtools often changes the geometry of the disk after
33083377 * looking at the boot block */
3309
- if (DRS->maxblock > user_params[drive].sect ||
3310
- DRS->maxtrack ||
3378
+ if (drive_state[current_drive].maxblock > user_params[drive].sect ||
3379
+ drive_state[current_drive].maxtrack ||
33113380 ((user_params[drive].sect ^ oldStretch) &
33123381 (FD_SWAPSIDES | FD_SECTBASEMASK)))
33133382 invalidate_drive(bdev);
....@@ -3398,13 +3467,13 @@
33983467 return 0;
33993468 }
34003469
3401
-static bool valid_floppy_drive_params(const short autodetect[8],
3470
+static bool valid_floppy_drive_params(const short autodetect[FD_AUTODETECT_SIZE],
34023471 int native_format)
34033472 {
34043473 size_t floppy_type_size = ARRAY_SIZE(floppy_type);
34053474 size_t i = 0;
34063475
3407
- for (i = 0; i < 8; ++i) {
3476
+ for (i = 0; i < FD_AUTODETECT_SIZE; ++i) {
34083477 if (autodetect[i] < 0 ||
34093478 autodetect[i] >= floppy_type_size)
34103479 return false;
....@@ -3420,8 +3489,7 @@
34203489 unsigned long param)
34213490 {
34223491 int drive = (long)bdev->bd_disk->private_data;
3423
- int type = ITYPE(UDRS->fd_device);
3424
- int i;
3492
+ int type = ITYPE(drive_state[drive].fd_device);
34253493 int ret;
34263494 int size;
34273495 union inparam {
....@@ -3468,7 +3536,7 @@
34683536
34693537 switch (cmd) {
34703538 case FDEJECT:
3471
- if (UDRS->fd_ref != 1)
3539
+ if (drive_state[drive].fd_ref != 1)
34723540 /* somebody else has this drive open */
34733541 return -EBUSY;
34743542 if (lock_fdc(drive))
....@@ -3478,8 +3546,8 @@
34783546 * non-Sparc architectures */
34793547 ret = fd_eject(UNIT(drive));
34803548
3481
- set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
3482
- set_bit(FD_VERIFY_BIT, &UDRS->flags);
3549
+ set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
3550
+ set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
34833551 process_fd_request();
34843552 return ret;
34853553 case FDCLRPRM:
....@@ -3487,7 +3555,7 @@
34873555 return -EINTR;
34883556 current_type[drive] = NULL;
34893557 floppy_sizes[drive] = MAX_DISK_SIZE << 1;
3490
- UDRS->keep_data = 0;
3558
+ drive_state[drive].keep_data = 0;
34913559 return invalidate_drive(bdev);
34923560 case FDSETPRM:
34933561 case FDDEFPRM:
....@@ -3502,17 +3570,17 @@
35023570 outparam = &inparam.g;
35033571 break;
35043572 case FDMSGON:
3505
- UDP->flags |= FTD_MSG;
3573
+ drive_params[drive].flags |= FTD_MSG;
35063574 return 0;
35073575 case FDMSGOFF:
3508
- UDP->flags &= ~FTD_MSG;
3576
+ drive_params[drive].flags &= ~FTD_MSG;
35093577 return 0;
35103578 case FDFMTBEG:
35113579 if (lock_fdc(drive))
35123580 return -EINTR;
35133581 if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
35143582 return -EINTR;
3515
- ret = UDRS->flags;
3583
+ ret = drive_state[drive].flags;
35163584 process_fd_request();
35173585 if (ret & FD_VERIFY)
35183586 return -ENODEV;
....@@ -3520,7 +3588,7 @@
35203588 return -EROFS;
35213589 return 0;
35223590 case FDFMTTRK:
3523
- if (UDRS->fd_ref != 1)
3591
+ if (drive_state[drive].fd_ref != 1)
35243592 return -EBUSY;
35253593 return do_format(drive, &inparam.f);
35263594 case FDFMTEND:
....@@ -3529,13 +3597,13 @@
35293597 return -EINTR;
35303598 return invalidate_drive(bdev);
35313599 case FDSETEMSGTRESH:
3532
- UDP->max_errors.reporting = (unsigned short)(param & 0x0f);
3600
+ drive_params[drive].max_errors.reporting = (unsigned short)(param & 0x0f);
35333601 return 0;
35343602 case FDGETMAXERRS:
3535
- outparam = &UDP->max_errors;
3603
+ outparam = &drive_params[drive].max_errors;
35363604 break;
35373605 case FDSETMAXERRS:
3538
- UDP->max_errors = inparam.max_errors;
3606
+ drive_params[drive].max_errors = inparam.max_errors;
35393607 break;
35403608 case FDGETDRVTYP:
35413609 outparam = drive_name(type, drive);
....@@ -3545,10 +3613,10 @@
35453613 if (!valid_floppy_drive_params(inparam.dp.autodetect,
35463614 inparam.dp.native_format))
35473615 return -EINVAL;
3548
- *UDP = inparam.dp;
3616
+ drive_params[drive] = inparam.dp;
35493617 break;
35503618 case FDGETDRVPRM:
3551
- outparam = UDP;
3619
+ outparam = &drive_params[drive];
35523620 break;
35533621 case FDPOLLDRVSTAT:
35543622 if (lock_fdc(drive))
....@@ -3556,36 +3624,27 @@
35563624 if (poll_drive(true, FD_RAW_NEED_DISK) == -EINTR)
35573625 return -EINTR;
35583626 process_fd_request();
3559
- /* fall through */
3627
+ fallthrough;
35603628 case FDGETDRVSTAT:
3561
- outparam = UDRS;
3629
+ outparam = &drive_state[drive];
35623630 break;
35633631 case FDRESET:
35643632 return user_reset_fdc(drive, (int)param, true);
35653633 case FDGETFDCSTAT:
3566
- outparam = UFDCS;
3634
+ outparam = &fdc_state[FDC(drive)];
35673635 break;
35683636 case FDWERRORCLR:
3569
- memset(UDRWE, 0, sizeof(*UDRWE));
3637
+ memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
35703638 return 0;
35713639 case FDWERRORGET:
3572
- outparam = UDRWE;
3640
+ outparam = &write_errors[drive];
35733641 break;
35743642 case FDRAWCMD:
3575
- if (type)
3576
- return -EINVAL;
3577
- if (lock_fdc(drive))
3578
- return -EINTR;
3579
- set_floppy(drive);
3580
- i = raw_cmd_ioctl(cmd, (void __user *)param);
3581
- if (i == -EINTR)
3582
- return -EINTR;
3583
- process_fd_request();
3584
- return i;
3643
+ return floppy_raw_cmd_ioctl(type, drive, cmd, (void __user *)param);
35853644 case FDTWADDLE:
35863645 if (lock_fdc(drive))
35873646 return -EINTR;
3588
- twaddle();
3647
+ twaddle(current_fdc, current_drive);
35893648 process_fd_request();
35903649 return 0;
35913650 default:
....@@ -3629,7 +3688,7 @@
36293688 struct floppy_max_errors max_errors;
36303689 char flags;
36313690 char read_track;
3632
- short autodetect[8];
3691
+ short autodetect[FD_AUTODETECT_SIZE];
36333692 compat_int_t checkfreq;
36343693 compat_int_t native_format;
36353694 };
....@@ -3705,7 +3764,7 @@
37053764
37063765 mutex_lock(&floppy_mutex);
37073766 drive = (long)bdev->bd_disk->private_data;
3708
- type = ITYPE(UDRS->fd_device);
3767
+ type = ITYPE(drive_state[drive].fd_device);
37093768 err = set_geometry(cmd == FDSETPRM32 ? FDSETPRM : FDDEFPRM,
37103769 &v, drive, type, bdev);
37113770 mutex_unlock(&floppy_mutex);
....@@ -3721,7 +3780,8 @@
37213780
37223781 memset(&v, 0, sizeof(v));
37233782 mutex_lock(&floppy_mutex);
3724
- err = get_floppy_geometry(drive, ITYPE(UDRS->fd_device), &p);
3783
+ err = get_floppy_geometry(drive, ITYPE(drive_state[drive].fd_device),
3784
+ &p);
37253785 if (err) {
37263786 mutex_unlock(&floppy_mutex);
37273787 return err;
....@@ -3745,25 +3805,26 @@
37453805 if (!valid_floppy_drive_params(v.autodetect, v.native_format))
37463806 return -EINVAL;
37473807 mutex_lock(&floppy_mutex);
3748
- UDP->cmos = v.cmos;
3749
- UDP->max_dtr = v.max_dtr;
3750
- UDP->hlt = v.hlt;
3751
- UDP->hut = v.hut;
3752
- UDP->srt = v.srt;
3753
- UDP->spinup = v.spinup;
3754
- UDP->spindown = v.spindown;
3755
- UDP->spindown_offset = v.spindown_offset;
3756
- UDP->select_delay = v.select_delay;
3757
- UDP->rps = v.rps;
3758
- UDP->tracks = v.tracks;
3759
- UDP->timeout = v.timeout;
3760
- UDP->interleave_sect = v.interleave_sect;
3761
- UDP->max_errors = v.max_errors;
3762
- UDP->flags = v.flags;
3763
- UDP->read_track = v.read_track;
3764
- memcpy(UDP->autodetect, v.autodetect, sizeof(v.autodetect));
3765
- UDP->checkfreq = v.checkfreq;
3766
- UDP->native_format = v.native_format;
3808
+ drive_params[drive].cmos = v.cmos;
3809
+ drive_params[drive].max_dtr = v.max_dtr;
3810
+ drive_params[drive].hlt = v.hlt;
3811
+ drive_params[drive].hut = v.hut;
3812
+ drive_params[drive].srt = v.srt;
3813
+ drive_params[drive].spinup = v.spinup;
3814
+ drive_params[drive].spindown = v.spindown;
3815
+ drive_params[drive].spindown_offset = v.spindown_offset;
3816
+ drive_params[drive].select_delay = v.select_delay;
3817
+ drive_params[drive].rps = v.rps;
3818
+ drive_params[drive].tracks = v.tracks;
3819
+ drive_params[drive].timeout = v.timeout;
3820
+ drive_params[drive].interleave_sect = v.interleave_sect;
3821
+ drive_params[drive].max_errors = v.max_errors;
3822
+ drive_params[drive].flags = v.flags;
3823
+ drive_params[drive].read_track = v.read_track;
3824
+ memcpy(drive_params[drive].autodetect, v.autodetect,
3825
+ sizeof(v.autodetect));
3826
+ drive_params[drive].checkfreq = v.checkfreq;
3827
+ drive_params[drive].native_format = v.native_format;
37673828 mutex_unlock(&floppy_mutex);
37683829 return 0;
37693830 }
....@@ -3775,25 +3836,26 @@
37753836
37763837 memset(&v, 0, sizeof(struct compat_floppy_drive_params));
37773838 mutex_lock(&floppy_mutex);
3778
- v.cmos = UDP->cmos;
3779
- v.max_dtr = UDP->max_dtr;
3780
- v.hlt = UDP->hlt;
3781
- v.hut = UDP->hut;
3782
- v.srt = UDP->srt;
3783
- v.spinup = UDP->spinup;
3784
- v.spindown = UDP->spindown;
3785
- v.spindown_offset = UDP->spindown_offset;
3786
- v.select_delay = UDP->select_delay;
3787
- v.rps = UDP->rps;
3788
- v.tracks = UDP->tracks;
3789
- v.timeout = UDP->timeout;
3790
- v.interleave_sect = UDP->interleave_sect;
3791
- v.max_errors = UDP->max_errors;
3792
- v.flags = UDP->flags;
3793
- v.read_track = UDP->read_track;
3794
- memcpy(v.autodetect, UDP->autodetect, sizeof(v.autodetect));
3795
- v.checkfreq = UDP->checkfreq;
3796
- v.native_format = UDP->native_format;
3839
+ v.cmos = drive_params[drive].cmos;
3840
+ v.max_dtr = drive_params[drive].max_dtr;
3841
+ v.hlt = drive_params[drive].hlt;
3842
+ v.hut = drive_params[drive].hut;
3843
+ v.srt = drive_params[drive].srt;
3844
+ v.spinup = drive_params[drive].spinup;
3845
+ v.spindown = drive_params[drive].spindown;
3846
+ v.spindown_offset = drive_params[drive].spindown_offset;
3847
+ v.select_delay = drive_params[drive].select_delay;
3848
+ v.rps = drive_params[drive].rps;
3849
+ v.tracks = drive_params[drive].tracks;
3850
+ v.timeout = drive_params[drive].timeout;
3851
+ v.interleave_sect = drive_params[drive].interleave_sect;
3852
+ v.max_errors = drive_params[drive].max_errors;
3853
+ v.flags = drive_params[drive].flags;
3854
+ v.read_track = drive_params[drive].read_track;
3855
+ memcpy(v.autodetect, drive_params[drive].autodetect,
3856
+ sizeof(v.autodetect));
3857
+ v.checkfreq = drive_params[drive].checkfreq;
3858
+ v.native_format = drive_params[drive].native_format;
37973859 mutex_unlock(&floppy_mutex);
37983860
37993861 if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_params)))
....@@ -3816,20 +3878,20 @@
38163878 goto Eintr;
38173879 process_fd_request();
38183880 }
3819
- v.spinup_date = UDRS->spinup_date;
3820
- v.select_date = UDRS->select_date;
3821
- v.first_read_date = UDRS->first_read_date;
3822
- v.probed_format = UDRS->probed_format;
3823
- v.track = UDRS->track;
3824
- v.maxblock = UDRS->maxblock;
3825
- v.maxtrack = UDRS->maxtrack;
3826
- v.generation = UDRS->generation;
3827
- v.keep_data = UDRS->keep_data;
3828
- v.fd_ref = UDRS->fd_ref;
3829
- v.fd_device = UDRS->fd_device;
3830
- v.last_checked = UDRS->last_checked;
3831
- v.dmabuf = (uintptr_t)UDRS->dmabuf;
3832
- v.bufblocks = UDRS->bufblocks;
3881
+ v.spinup_date = drive_state[drive].spinup_date;
3882
+ v.select_date = drive_state[drive].select_date;
3883
+ v.first_read_date = drive_state[drive].first_read_date;
3884
+ v.probed_format = drive_state[drive].probed_format;
3885
+ v.track = drive_state[drive].track;
3886
+ v.maxblock = drive_state[drive].maxblock;
3887
+ v.maxtrack = drive_state[drive].maxtrack;
3888
+ v.generation = drive_state[drive].generation;
3889
+ v.keep_data = drive_state[drive].keep_data;
3890
+ v.fd_ref = drive_state[drive].fd_ref;
3891
+ v.fd_device = drive_state[drive].fd_device;
3892
+ v.last_checked = drive_state[drive].last_checked;
3893
+ v.dmabuf = (uintptr_t) drive_state[drive].dmabuf;
3894
+ v.bufblocks = drive_state[drive].bufblocks;
38333895 mutex_unlock(&floppy_mutex);
38343896
38353897 if (copy_to_user(arg, &v, sizeof(struct compat_floppy_drive_struct)))
....@@ -3847,7 +3909,7 @@
38473909 struct floppy_fdc_state v;
38483910
38493911 mutex_lock(&floppy_mutex);
3850
- v = *UFDCS;
3912
+ v = fdc_state[FDC(drive)];
38513913 mutex_unlock(&floppy_mutex);
38523914
38533915 memset(&v32, 0, sizeof(struct compat_floppy_fdc_state));
....@@ -3877,7 +3939,7 @@
38773939
38783940 memset(&v32, 0, sizeof(struct compat_floppy_write_errors));
38793941 mutex_lock(&floppy_mutex);
3880
- v = *UDRWE;
3942
+ v = write_errors[drive];
38813943 mutex_unlock(&floppy_mutex);
38823944 v32.write_errors = v.write_errors;
38833945 v32.first_error_sector = v.first_error_sector;
....@@ -3895,6 +3957,9 @@
38953957 {
38963958 int drive = (long)bdev->bd_disk->private_data;
38973959 switch (cmd) {
3960
+ case CDROMEJECT: /* CD-ROM eject */
3961
+ case 0x6470: /* SunOS floppy eject */
3962
+
38983963 case FDMSGON:
38993964 case FDMSGOFF:
39003965 case FDSETEMSGTRESH:
....@@ -3943,16 +4008,16 @@
39434008
39444009 /* read drive info out of physical CMOS */
39454010 drive = 0;
3946
- if (!UDP->cmos)
3947
- UDP->cmos = FLOPPY0_TYPE;
4011
+ if (!drive_params[drive].cmos)
4012
+ drive_params[drive].cmos = FLOPPY0_TYPE;
39484013 drive = 1;
3949
- if (!UDP->cmos && FLOPPY1_TYPE)
3950
- UDP->cmos = FLOPPY1_TYPE;
4014
+ if (!drive_params[drive].cmos)
4015
+ drive_params[drive].cmos = FLOPPY1_TYPE;
39514016
39524017 /* FIXME: additional physical CMOS drive detection should go here */
39534018
39544019 for (drive = 0; drive < N_DRIVE; drive++) {
3955
- unsigned int type = UDP->cmos;
4020
+ unsigned int type = drive_params[drive].cmos;
39564021 struct floppy_drive_params *params;
39574022 const char *name = NULL;
39584023 char temparea[32];
....@@ -3982,7 +4047,7 @@
39824047
39834048 pr_cont("%s fd%d is %s", prepend, drive, name);
39844049 }
3985
- *UDP = *params;
4050
+ drive_params[drive] = *params;
39864051 }
39874052
39884053 if (has_drive)
....@@ -3995,11 +4060,11 @@
39954060
39964061 mutex_lock(&floppy_mutex);
39974062 mutex_lock(&open_lock);
3998
- if (!UDRS->fd_ref--) {
4063
+ if (!drive_state[drive].fd_ref--) {
39994064 DPRINT("floppy_release with fd_ref == 0");
4000
- UDRS->fd_ref = 0;
4065
+ drive_state[drive].fd_ref = 0;
40014066 }
4002
- if (!UDRS->fd_ref)
4067
+ if (!drive_state[drive].fd_ref)
40034068 opened_bdev[drive] = NULL;
40044069 mutex_unlock(&open_lock);
40054070 mutex_unlock(&floppy_mutex);
....@@ -4020,16 +4085,16 @@
40204085
40214086 mutex_lock(&floppy_mutex);
40224087 mutex_lock(&open_lock);
4023
- old_dev = UDRS->fd_device;
4088
+ old_dev = drive_state[drive].fd_device;
40244089 if (opened_bdev[drive] && opened_bdev[drive] != bdev)
40254090 goto out2;
40264091
4027
- if (!UDRS->fd_ref && (UDP->flags & FD_BROKEN_DCL)) {
4028
- set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
4029
- set_bit(FD_VERIFY_BIT, &UDRS->flags);
4092
+ if (!drive_state[drive].fd_ref && (drive_params[drive].flags & FD_BROKEN_DCL)) {
4093
+ set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
4094
+ set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
40304095 }
40314096
4032
- UDRS->fd_ref++;
4097
+ drive_state[drive].fd_ref++;
40334098
40344099 opened_bdev[drive] = bdev;
40354100
....@@ -4038,7 +4103,7 @@
40384103 if (!floppy_track_buffer) {
40394104 /* if opening an ED drive, reserve a big buffer,
40404105 * else reserve a small one */
4041
- if ((UDP->cmos == 6) || (UDP->cmos == 5))
4106
+ if ((drive_params[drive].cmos == 6) || (drive_params[drive].cmos == 5))
40424107 try = 64; /* Only 48 actually useful */
40434108 else
40444109 try = 32; /* Only 24 actually useful */
....@@ -4066,38 +4131,40 @@
40664131 }
40674132
40684133 new_dev = MINOR(bdev->bd_dev);
4069
- UDRS->fd_device = new_dev;
4134
+ drive_state[drive].fd_device = new_dev;
40704135 set_capacity(disks[drive], floppy_sizes[new_dev]);
40714136 if (old_dev != -1 && old_dev != new_dev) {
40724137 if (buffer_drive == drive)
40734138 buffer_track = -1;
40744139 }
40754140
4076
- if (UFDCS->rawcmd == 1)
4077
- UFDCS->rawcmd = 2;
4141
+ if (fdc_state[FDC(drive)].rawcmd == 1)
4142
+ fdc_state[FDC(drive)].rawcmd = 2;
40784143
40794144 if (!(mode & FMODE_NDELAY)) {
40804145 if (mode & (FMODE_READ|FMODE_WRITE)) {
4081
- UDRS->last_checked = 0;
4082
- clear_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
4083
- check_disk_change(bdev);
4084
- if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags))
4146
+ drive_state[drive].last_checked = 0;
4147
+ clear_bit(FD_OPEN_SHOULD_FAIL_BIT,
4148
+ &drive_state[drive].flags);
4149
+ if (bdev_check_media_change(bdev))
4150
+ floppy_revalidate(bdev->bd_disk);
4151
+ if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags))
40854152 goto out;
4086
- if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags))
4153
+ if (test_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags))
40874154 goto out;
40884155 }
40894156 res = -EROFS;
40904157 if ((mode & FMODE_WRITE) &&
4091
- !test_bit(FD_DISK_WRITABLE_BIT, &UDRS->flags))
4158
+ !test_bit(FD_DISK_WRITABLE_BIT, &drive_state[drive].flags))
40924159 goto out;
40934160 }
40944161 mutex_unlock(&open_lock);
40954162 mutex_unlock(&floppy_mutex);
40964163 return 0;
40974164 out:
4098
- UDRS->fd_ref--;
4165
+ drive_state[drive].fd_ref--;
40994166
4100
- if (!UDRS->fd_ref)
4167
+ if (!drive_state[drive].fd_ref)
41014168 opened_bdev[drive] = NULL;
41024169 out2:
41034170 mutex_unlock(&open_lock);
....@@ -4113,19 +4180,19 @@
41134180 {
41144181 int drive = (long)disk->private_data;
41154182
4116
- if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
4117
- test_bit(FD_VERIFY_BIT, &UDRS->flags))
4183
+ if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
4184
+ test_bit(FD_VERIFY_BIT, &drive_state[drive].flags))
41184185 return DISK_EVENT_MEDIA_CHANGE;
41194186
4120
- if (time_after(jiffies, UDRS->last_checked + UDP->checkfreq)) {
4187
+ if (time_after(jiffies, drive_state[drive].last_checked + drive_params[drive].checkfreq)) {
41214188 if (lock_fdc(drive))
41224189 return 0;
41234190 poll_drive(false, 0);
41244191 process_fd_request();
41254192 }
41264193
4127
- if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
4128
- test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
4194
+ if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
4195
+ test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
41294196 test_bit(drive, &fake_change) ||
41304197 drive_no_geom(drive))
41314198 return DISK_EVENT_MEDIA_CHANGE;
....@@ -4151,7 +4218,7 @@
41514218 if (bio->bi_status) {
41524219 pr_info("floppy: error %d while reading block 0\n",
41534220 bio->bi_status);
4154
- set_bit(FD_OPEN_SHOULD_FAIL_BIT, &UDRS->flags);
4221
+ set_bit(FD_OPEN_SHOULD_FAIL_BIT, &drive_state[drive].flags);
41554222 }
41564223 complete(&cbdata->complete);
41574224 }
....@@ -4162,7 +4229,6 @@
41624229 struct bio_vec bio_vec;
41634230 struct page *page;
41644231 struct rb0_cbdata cbdata;
4165
- size_t size;
41664232
41674233 page = alloc_page(GFP_NOIO);
41684234 if (!page) {
....@@ -4170,15 +4236,11 @@
41704236 return -ENOMEM;
41714237 }
41724238
4173
- size = bdev->bd_block_size;
4174
- if (!size)
4175
- size = 1024;
4176
-
41774239 cbdata.drive = drive;
41784240
41794241 bio_init(&bio, &bio_vec, 1);
41804242 bio_set_dev(&bio, bdev);
4181
- bio_add_page(&bio, page, size, 0);
4243
+ bio_add_page(&bio, page, block_size(bdev), 0);
41824244
41834245 bio.bi_iter.bi_sector = 0;
41844246 bio.bi_flags |= (1 << BIO_QUIET);
....@@ -4208,8 +4270,8 @@
42084270 int cf;
42094271 int res = 0;
42104272
4211
- if (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
4212
- test_bit(FD_VERIFY_BIT, &UDRS->flags) ||
4273
+ if (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
4274
+ test_bit(FD_VERIFY_BIT, &drive_state[drive].flags) ||
42134275 test_bit(drive, &fake_change) ||
42144276 drive_no_geom(drive)) {
42154277 if (WARN(atomic_read(&usage_count) == 0,
....@@ -4219,20 +4281,20 @@
42194281 res = lock_fdc(drive);
42204282 if (res)
42214283 return res;
4222
- cf = (test_bit(FD_DISK_CHANGED_BIT, &UDRS->flags) ||
4223
- test_bit(FD_VERIFY_BIT, &UDRS->flags));
4284
+ cf = (test_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags) ||
4285
+ test_bit(FD_VERIFY_BIT, &drive_state[drive].flags));
42244286 if (!(cf || test_bit(drive, &fake_change) || drive_no_geom(drive))) {
42254287 process_fd_request(); /*already done by another thread */
42264288 return 0;
42274289 }
4228
- UDRS->maxblock = 0;
4229
- UDRS->maxtrack = 0;
4290
+ drive_state[drive].maxblock = 0;
4291
+ drive_state[drive].maxtrack = 0;
42304292 if (buffer_drive == drive)
42314293 buffer_track = -1;
42324294 clear_bit(drive, &fake_change);
4233
- clear_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
4295
+ clear_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
42344296 if (cf)
4235
- UDRS->generation++;
4297
+ drive_state[drive].generation++;
42364298 if (drive_no_geom(drive)) {
42374299 /* auto-sensing */
42384300 res = __floppy_read_block_0(opened_bdev[drive], drive);
....@@ -4242,7 +4304,7 @@
42424304 process_fd_request();
42434305 }
42444306 }
4245
- set_capacity(disk, floppy_sizes[UDRS->fd_device]);
4307
+ set_capacity(disk, floppy_sizes[drive_state[drive].fd_device]);
42464308 return res;
42474309 }
42484310
....@@ -4253,7 +4315,6 @@
42534315 .ioctl = fd_ioctl,
42544316 .getgeo = fd_getgeo,
42554317 .check_events = floppy_check_events,
4256
- .revalidate_disk = floppy_revalidate,
42574318 #ifdef CONFIG_COMPAT
42584319 .compat_ioctl = fd_compat_ioctl,
42594320 #endif
....@@ -4266,14 +4327,14 @@
42664327
42674328 /* Determine the floppy disk controller type */
42684329 /* This routine was written by David C. Niemi */
4269
-static char __init get_fdc_version(void)
4330
+static char __init get_fdc_version(int fdc)
42704331 {
42714332 int r;
42724333
4273
- output_byte(FD_DUMPREGS); /* 82072 and better know DUMPREGS */
4274
- if (FDCS->reset)
4334
+ output_byte(fdc, FD_DUMPREGS); /* 82072 and better know DUMPREGS */
4335
+ if (fdc_state[fdc].reset)
42754336 return FDC_NONE;
4276
- r = result();
4337
+ r = result(fdc);
42774338 if (r <= 0x00)
42784339 return FDC_NONE; /* No FDC present ??? */
42794340 if ((r == 1) && (reply_buffer[0] == 0x80)) {
....@@ -4286,21 +4347,21 @@
42864347 return FDC_UNKNOWN;
42874348 }
42884349
4289
- if (!fdc_configure()) {
4350
+ if (!fdc_configure(fdc)) {
42904351 pr_info("FDC %d is an 82072\n", fdc);
42914352 return FDC_82072; /* 82072 doesn't know CONFIGURE */
42924353 }
42934354
4294
- output_byte(FD_PERPENDICULAR);
4295
- if (need_more_output() == MORE_OUTPUT) {
4296
- output_byte(0);
4355
+ output_byte(fdc, FD_PERPENDICULAR);
4356
+ if (need_more_output(fdc) == MORE_OUTPUT) {
4357
+ output_byte(fdc, 0);
42974358 } else {
42984359 pr_info("FDC %d is an 82072A\n", fdc);
42994360 return FDC_82072A; /* 82072A as found on Sparcs. */
43004361 }
43014362
4302
- output_byte(FD_UNLOCK);
4303
- r = result();
4363
+ output_byte(fdc, FD_UNLOCK);
4364
+ r = result(fdc);
43044365 if ((r == 1) && (reply_buffer[0] == 0x80)) {
43054366 pr_info("FDC %d is a pre-1991 82077\n", fdc);
43064367 return FDC_82077_ORIG; /* Pre-1991 82077, doesn't know
....@@ -4311,8 +4372,8 @@
43114372 fdc, r);
43124373 return FDC_UNKNOWN;
43134374 }
4314
- output_byte(FD_PARTID);
4315
- r = result();
4375
+ output_byte(fdc, FD_PARTID);
4376
+ r = result(fdc);
43164377 if (r != 1) {
43174378 pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n",
43184379 fdc, r);
....@@ -4394,7 +4455,7 @@
43944455 if (current_drive >= 4 && !FDC2)
43954456 FDC2 = 0x370;
43964457 #endif
4397
- DP->cmos = ints[2];
4458
+ drive_params[current_drive].cmos = ints[2];
43984459 DPRINT("setting CMOS code to %d\n", ints[2]);
43994460 }
44004461
....@@ -4470,7 +4531,7 @@
44704531 pr_cont("\n");
44714532 } else
44724533 DPRINT("botched floppy option\n");
4473
- DPRINT("Read Documentation/blockdev/floppy.txt\n");
4534
+ DPRINT("Read Documentation/admin-guide/blockdev/floppy.rst\n");
44744535 return 0;
44754536 }
44764537
....@@ -4483,7 +4544,7 @@
44834544 int drive;
44844545
44854546 drive = p->id;
4486
- return sprintf(buf, "%X\n", UDP->cmos);
4547
+ return sprintf(buf, "%X\n", drive_params[drive].cmos);
44874548 }
44884549
44894550 static DEVICE_ATTR(cmos, 0444, floppy_cmos_show, NULL);
....@@ -4502,11 +4563,13 @@
45024563 static int floppy_resume(struct device *dev)
45034564 {
45044565 int fdc;
4566
+ int saved_drive;
45054567
4568
+ saved_drive = current_drive;
45064569 for (fdc = 0; fdc < N_FDC; fdc++)
4507
- if (FDCS->address != -1)
4508
- user_reset_fdc(-1, FD_RESET_ALWAYS, false);
4509
-
4570
+ if (fdc_state[fdc].address != -1)
4571
+ user_reset_fdc(REVDRIVE(fdc, 0), FD_RESET_ALWAYS, false);
4572
+ set_fdc(saved_drive);
45104573 return 0;
45114574 }
45124575
....@@ -4520,6 +4583,10 @@
45204583 .name = "floppy",
45214584 .pm = &floppy_pm_ops,
45224585 },
4586
+};
4587
+
4588
+static const struct blk_mq_ops floppy_mq_ops = {
4589
+ .queue_rq = floppy_queue_rq,
45234590 };
45244591
45254592 static struct platform_device floppy_device[N_DRIVE];
....@@ -4569,9 +4636,12 @@
45694636 goto out_put_disk;
45704637 }
45714638
4572
- disks[drive]->queue = blk_init_queue(do_fd_request, &floppy_lock);
4573
- if (!disks[drive]->queue) {
4574
- err = -ENOMEM;
4639
+ disks[drive]->queue = blk_mq_init_sq_queue(&tag_sets[drive],
4640
+ &floppy_mq_ops, 2,
4641
+ BLK_MQ_F_SHOULD_MERGE);
4642
+ if (IS_ERR(disks[drive]->queue)) {
4643
+ err = PTR_ERR(disks[drive]->queue);
4644
+ disks[drive]->queue = NULL;
45754645 goto out_put_disk;
45764646 }
45774647
....@@ -4580,6 +4650,7 @@
45804650 disks[drive]->major = FLOPPY_MAJOR;
45814651 disks[drive]->first_minor = TOMINOR(drive);
45824652 disks[drive]->fops = &floppy_fops;
4653
+ disks[drive]->events = DISK_EVENT_MEDIA_CHANGE;
45834654 sprintf(disks[drive]->disk_name, "fd%d", drive);
45844655
45854656 timer_setup(&motor_off_timer[drive], motor_off_callback, 0);
....@@ -4606,16 +4677,15 @@
46064677 config_types();
46074678
46084679 for (i = 0; i < N_FDC; i++) {
4609
- fdc = i;
4610
- memset(FDCS, 0, sizeof(*FDCS));
4611
- FDCS->dtr = -1;
4612
- FDCS->dor = 0x4;
4680
+ memset(&fdc_state[i], 0, sizeof(*fdc_state));
4681
+ fdc_state[i].dtr = -1;
4682
+ fdc_state[i].dor = 0x4;
46134683 #if defined(__sparc__) || defined(__mc68000__)
46144684 /*sparcs/sun3x don't have a DOR reset which we can fall back on to */
46154685 #ifdef __mc68000__
46164686 if (MACH_IS_SUN3X)
46174687 #endif
4618
- FDCS->version = FDC_82072A;
4688
+ fdc_state[i].version = FDC_82072A;
46194689 #endif
46204690 }
46214691
....@@ -4630,7 +4700,7 @@
46304700 fdc_state[1].address = FDC2;
46314701 #endif
46324702
4633
- fdc = 0; /* reset fdc in case of unexpected interrupt */
4703
+ current_fdc = 0; /* reset fdc in case of unexpected interrupt */
46344704 err = floppy_grab_irq_and_dma();
46354705 if (err) {
46364706 cancel_delayed_work(&fd_timeout);
....@@ -4640,12 +4710,12 @@
46404710
46414711 /* initialise drive state */
46424712 for (drive = 0; drive < N_DRIVE; drive++) {
4643
- memset(UDRS, 0, sizeof(*UDRS));
4644
- memset(UDRWE, 0, sizeof(*UDRWE));
4645
- set_bit(FD_DISK_NEWCHANGE_BIT, &UDRS->flags);
4646
- set_bit(FD_DISK_CHANGED_BIT, &UDRS->flags);
4647
- set_bit(FD_VERIFY_BIT, &UDRS->flags);
4648
- UDRS->fd_device = -1;
4713
+ memset(&drive_state[drive], 0, sizeof(drive_state[drive]));
4714
+ memset(&write_errors[drive], 0, sizeof(write_errors[drive]));
4715
+ set_bit(FD_DISK_NEWCHANGE_BIT, &drive_state[drive].flags);
4716
+ set_bit(FD_DISK_CHANGED_BIT, &drive_state[drive].flags);
4717
+ set_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
4718
+ drive_state[drive].fd_device = -1;
46494719 floppy_track_buffer = NULL;
46504720 max_buffer_sectors = 0;
46514721 }
....@@ -4657,29 +4727,29 @@
46574727 msleep(10);
46584728
46594729 for (i = 0; i < N_FDC; i++) {
4660
- fdc = i;
4661
- FDCS->driver_version = FD_DRIVER_VERSION;
4730
+ fdc_state[i].driver_version = FD_DRIVER_VERSION;
46624731 for (unit = 0; unit < 4; unit++)
4663
- FDCS->track[unit] = 0;
4664
- if (FDCS->address == -1)
4732
+ fdc_state[i].track[unit] = 0;
4733
+ if (fdc_state[i].address == -1)
46654734 continue;
4666
- FDCS->rawcmd = 2;
4667
- if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) {
4735
+ fdc_state[i].rawcmd = 2;
4736
+ if (user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false)) {
46684737 /* free ioports reserved by floppy_grab_irq_and_dma() */
4669
- floppy_release_regions(fdc);
4670
- FDCS->address = -1;
4671
- FDCS->version = FDC_NONE;
4738
+ floppy_release_regions(i);
4739
+ fdc_state[i].address = -1;
4740
+ fdc_state[i].version = FDC_NONE;
46724741 continue;
46734742 }
46744743 /* Try to determine the floppy controller type */
4675
- FDCS->version = get_fdc_version();
4676
- if (FDCS->version == FDC_NONE) {
4744
+ fdc_state[i].version = get_fdc_version(i);
4745
+ if (fdc_state[i].version == FDC_NONE) {
46774746 /* free ioports reserved by floppy_grab_irq_and_dma() */
4678
- floppy_release_regions(fdc);
4679
- FDCS->address = -1;
4747
+ floppy_release_regions(i);
4748
+ fdc_state[i].address = -1;
46804749 continue;
46814750 }
4682
- if (can_use_virtual_dma == 2 && FDCS->version < FDC_82072A)
4751
+ if (can_use_virtual_dma == 2 &&
4752
+ fdc_state[i].version < FDC_82072A)
46834753 can_use_virtual_dma = 0;
46844754
46854755 have_no_fdc = 0;
....@@ -4687,9 +4757,9 @@
46874757 * properly, so force a reset for the standard FDC clones,
46884758 * to avoid interrupt garbage.
46894759 */
4690
- user_reset_fdc(-1, FD_RESET_ALWAYS, false);
4760
+ user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false);
46914761 }
4692
- fdc = 0;
4762
+ current_fdc = 0;
46934763 cancel_delayed_work(&fd_timeout);
46944764 current_drive = 0;
46954765 initialized = true;
....@@ -4715,7 +4785,7 @@
47154785 /* to be cleaned up... */
47164786 disks[drive]->private_data = (void *)(long)drive;
47174787 disks[drive]->flags |= GENHD_FL_REMOVABLE;
4718
- device_add_disk(&floppy_device[drive].dev, disks[drive]);
4788
+ device_add_disk(&floppy_device[drive].dev, disks[drive], NULL);
47194789 }
47204790
47214791 return 0;
....@@ -4744,6 +4814,7 @@
47444814 del_timer_sync(&motor_off_timer[drive]);
47454815 blk_cleanup_queue(disks[drive]->queue);
47464816 disks[drive]->queue = NULL;
4817
+ blk_mq_free_tag_set(&tag_sets[drive]);
47474818 }
47484819 put_disk(disks[drive]);
47494820 }
....@@ -4784,7 +4855,7 @@
47844855 {
47854856 while (p != io_regions) {
47864857 p--;
4787
- release_region(FDCS->address + p->offset, p->size);
4858
+ release_region(fdc_state[fdc].address + p->offset, p->size);
47884859 }
47894860 }
47904861
....@@ -4795,10 +4866,10 @@
47954866 const struct io_region *p;
47964867
47974868 for (p = io_regions; p < ARRAY_END(io_regions); p++) {
4798
- if (!request_region(FDCS->address + p->offset,
4869
+ if (!request_region(fdc_state[fdc].address + p->offset,
47994870 p->size, "floppy")) {
48004871 DPRINT("Floppy io-port 0x%04lx in use\n",
4801
- FDCS->address + p->offset);
4872
+ fdc_state[fdc].address + p->offset);
48024873 floppy_release_allocated_regions(fdc, p);
48034874 return -EBUSY;
48044875 }
....@@ -4813,6 +4884,8 @@
48134884
48144885 static int floppy_grab_irq_and_dma(void)
48154886 {
4887
+ int fdc;
4888
+
48164889 if (atomic_inc_return(&usage_count) > 1)
48174890 return 0;
48184891
....@@ -4841,28 +4914,28 @@
48414914 }
48424915
48434916 for (fdc = 0; fdc < N_FDC; fdc++) {
4844
- if (FDCS->address != -1) {
4917
+ if (fdc_state[fdc].address != -1) {
48454918 if (floppy_request_regions(fdc))
48464919 goto cleanup;
48474920 }
48484921 }
48494922 for (fdc = 0; fdc < N_FDC; fdc++) {
4850
- if (FDCS->address != -1) {
4851
- reset_fdc_info(1);
4852
- fd_outb(FDCS->dor, FD_DOR);
4923
+ if (fdc_state[fdc].address != -1) {
4924
+ reset_fdc_info(fdc, 1);
4925
+ fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
48534926 }
48544927 }
4855
- fdc = 0;
4928
+
48564929 set_dor(0, ~0, 8); /* avoid immediate interrupt */
48574930
48584931 for (fdc = 0; fdc < N_FDC; fdc++)
4859
- if (FDCS->address != -1)
4860
- fd_outb(FDCS->dor, FD_DOR);
4932
+ if (fdc_state[fdc].address != -1)
4933
+ fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
48614934 /*
48624935 * The driver will try and free resources and relies on us
48634936 * to know if they were allocated or not.
48644937 */
4865
- fdc = 0;
4938
+ current_fdc = 0;
48664939 irqdma_allocated = 1;
48674940 return 0;
48684941 cleanup:
....@@ -4870,13 +4943,14 @@
48704943 fd_free_dma();
48714944 while (--fdc >= 0)
48724945 floppy_release_regions(fdc);
4946
+ current_fdc = 0;
48734947 atomic_dec(&usage_count);
48744948 return -1;
48754949 }
48764950
48774951 static void floppy_release_irq_and_dma(void)
48784952 {
4879
- int old_fdc;
4953
+ int fdc;
48804954 #ifndef __sparc__
48814955 int drive;
48824956 #endif
....@@ -4917,11 +4991,9 @@
49174991 pr_info("auxiliary floppy timer still active\n");
49184992 if (work_pending(&floppy_work))
49194993 pr_info("work still pending\n");
4920
- old_fdc = fdc;
49214994 for (fdc = 0; fdc < N_FDC; fdc++)
4922
- if (FDCS->address != -1)
4995
+ if (fdc_state[fdc].address != -1)
49234996 floppy_release_regions(fdc);
4924
- fdc = old_fdc;
49254997 }
49264998
49274999 #ifdef MODULE
....@@ -4971,6 +5043,7 @@
49715043 platform_device_unregister(&floppy_device[drive]);
49725044 }
49735045 blk_cleanup_queue(disks[drive]->queue);
5046
+ blk_mq_free_tag_set(&tag_sets[drive]);
49745047
49755048 /*
49765049 * These disks have not called add_disk(). Don't put down