linux-block.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 00/23] Floppy driver cleanups
@ 2020-03-31  9:40 Willy Tarreau
  2020-03-31  9:40 ` [PATCH 01/23] floppy: split the base port from the register in I/O accesses Willy Tarreau
                   ` (24 more replies)
  0 siblings, 25 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau,
	David S. Miller, Benjamin Herrenschmidt, Geert Uytterhoeven,
	Helge Deller, Ian Molton, Ivan Kokshaysky, Matt Turner,
	Richard Henderson, Russell King, Thomas Bogendoerfer, x86

This series applies a second batch of cleanups to the floppy driver and
its multiple arch-specific parts. Here the focus was on getting rid of
hard-coded registers and flags values to switch to their symbolic
definitions instead, and on making use of the global current_fdc variable
much more explicit throughout the code to reduce the risk of accidental
misuse as was the case with the most recently fixed bug.

Note that this code base is very old and the purpose is not to rewrite
nor reorganize the driver at all, but instead to make certain things
more obvious while keeping changes reviewable. It does not even address
style issues that make checkpatch continue to complain a little bit (15
total warnings which were already there and don't seem worth addressing
without more careful testing). Some comments were added to document a
few non-obvious assumptions though.

This series was rediffed against today's master (458ef2a25e0c) which
contains the first series. The changes were tested on x86 with real
hardware, and was build-tested on ARM.

Willy Tarreau (23):
  floppy: split the base port from the register in I/O accesses
  floppy: add references to 82077's extra registers
  floppy: use symbolic register names in the m68k port
  floppy: use symbolic register names in the parisc port
  floppy: use symbolic register names in the powerpc port
  floppy: use symbolic register names in the sparc32 port
  floppy: use symbolic register names in the sparc64 port
  floppy: use symbolic register names in the x86 port
  floppy: cleanup: make twaddle() not rely on current_{fdc,drive}
    anymore
  floppy: cleanup: make reset_fdc_info() not rely on current_fdc anymore
  floppy: cleanup: make show_floppy() not rely on current_fdc anymore
  floppy: cleanup: make wait_til_ready() not rely on current_fdc anymore
  floppy: cleanup: make output_byte() not rely on current_fdc anymore
  floppy: cleanup: make result() not rely on current_fdc anymore
  floppy: cleanup: make need_more_output() not rely on current_fdc
    anymore
  floppy: cleanup: make perpendicular_mode() not rely on current_fdc
    anymore
  floppy: cleanup: make fdc_configure() not rely on current_fdc anymore
  floppy: cleanup: make fdc_specify() not rely on current_{fdc,drive}
    anymore
  floppy: cleanup: make check_wp() not rely on current_{fdc,drive}
    anymore
  floppy: cleanup: make next_valid_format() not rely on current_drive
    anymore
  floppy: cleanup: make get_fdc_version() not rely on current_fdc
    anymore
  floppy: cleanup: do not iterate on current_fdc in DMA grab/release
    functions
  floppy: cleanup: add a few comments about expectations in certain
    functions

 arch/alpha/include/asm/floppy.h             |   4 +-
 arch/arm/include/asm/floppy.h               |   8 +-
 arch/m68k/include/asm/floppy.h              |  27 +-
 arch/mips/include/asm/mach-generic/floppy.h |   8 +-
 arch/mips/include/asm/mach-jazz/floppy.h    |   8 +-
 arch/parisc/include/asm/floppy.h            |  19 +-
 arch/powerpc/include/asm/floppy.h           |  19 +-
 arch/sparc/include/asm/floppy_32.h          |  50 +--
 arch/sparc/include/asm/floppy_64.h          |  59 ++--
 arch/x86/include/asm/floppy.h               |  19 +-
 drivers/block/floppy.c                      | 330 ++++++++++----------
 include/uapi/linux/fdreg.h                  |  16 +-
 12 files changed, 299 insertions(+), 268 deletions(-)

Cc: "David S. Miller" <davem@davemloft.net>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Helge Deller <deller@gmx.de>
Cc: Ian Molton <spyro@f2s.com>
Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: x86@kernel.org
-- 
2.20.1


^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH 01/23] floppy: split the base port from the register in I/O accesses
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 02/23] floppy: add references to 82077's extra registers Willy Tarreau
                   ` (23 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau,
	Ivan Kokshaysky, Richard Henderson, Matt Turner, Ian Molton,
	Russell King, Geert Uytterhoeven, Thomas Bogendoerfer,
	Helge Deller, Benjamin Herrenschmidt, David S. Miller, x86

Currently we have architecture-specific fd_inb() and fd_outb() functions
or macros, taking just a port which is in fact made of a base address and
a register. The base address is FDC-specific and derived from the local or
global "fdc" variable through the FD_IOPORT macro used in the base address
calculation.

This change splits this by explicitly passing the FDC's base address and
the register separately to fd_outb() and fd_inb(). It affects the
following archs:
  - x86, alpha, mips, powerpc, parisc, arm, m68k:
    simple remap of port -> base+reg

  - sparc32: use of reg only, since the base address was already masked
    out and the FDC controller is known from a static struct.

  - sparc64: like x86 for PCI, like sparc32 for 82077

Some archs use inline functions and others macros. This was not
unified in order to minimize the number of changes to review. For the
same reason checkpatch still spews a few warnings about things that
were already there before.

The parisc still uses hard-coded register values and could be cleaned up
by taking the register definitions.

The sparc per-controller inb/outb functions could further be refined
to explicitly take an FDC register instead of a port in argument but it
was not needed yet and may be cleaned later.

Cc: Ivan Kokshaysky <ink@jurassic.park.msu.ru>
Cc: Richard Henderson <rth@twiddle.net>
Cc: Matt Turner <mattst88@gmail.com>
Cc: Ian Molton <spyro@f2s.com>
Cc: Russell King <linux@armlinux.org.uk>
Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Cc: Thomas Bogendoerfer <tsbogend@alpha.franken.de>
Cc: Helge Deller <deller@gmx.de>
Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Cc: "David S. Miller" <davem@davemloft.net>
Cc: x86@kernel.org
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 arch/alpha/include/asm/floppy.h             |  4 ++--
 arch/arm/include/asm/floppy.h               |  8 ++++----
 arch/m68k/include/asm/floppy.h              | 12 ++++++------
 arch/mips/include/asm/mach-generic/floppy.h |  8 ++++----
 arch/mips/include/asm/mach-jazz/floppy.h    |  8 ++++----
 arch/parisc/include/asm/floppy.h            | 12 ++++++------
 arch/powerpc/include/asm/floppy.h           |  4 ++--
 arch/sparc/include/asm/floppy_32.h          |  4 ++--
 arch/sparc/include/asm/floppy_64.h          |  4 ++--
 arch/x86/include/asm/floppy.h               |  4 ++--
 drivers/block/floppy.c                      |  4 ++--
 11 files changed, 36 insertions(+), 36 deletions(-)

diff --git a/arch/alpha/include/asm/floppy.h b/arch/alpha/include/asm/floppy.h
index 942924756cf2..8dfdb3aa1d96 100644
--- a/arch/alpha/include/asm/floppy.h
+++ b/arch/alpha/include/asm/floppy.h
@@ -11,8 +11,8 @@
 #define __ASM_ALPHA_FLOPPY_H
 
 
-#define fd_inb(port)			inb_p(port)
-#define fd_outb(value,port)		outb_p(value,port)
+#define fd_inb(base, reg)		inb_p((base) + (reg))
+#define fd_outb(value, base, reg)	outb_p(value, (base) + (reg))
 
 #define fd_enable_dma()         enable_dma(FLOPPY_DMA)
 #define fd_disable_dma()        disable_dma(FLOPPY_DMA)
diff --git a/arch/arm/include/asm/floppy.h b/arch/arm/include/asm/floppy.h
index 79fa327238e8..e1cb04ed5008 100644
--- a/arch/arm/include/asm/floppy.h
+++ b/arch/arm/include/asm/floppy.h
@@ -9,20 +9,20 @@
 #ifndef __ASM_ARM_FLOPPY_H
 #define __ASM_ARM_FLOPPY_H
 
-#define fd_outb(val,port)						\
+#define fd_outb(val, base, reg)						\
 	do {								\
 		int new_val = (val);					\
-		if (((port) & 7) == FD_DOR) {				\
+		if ((reg) == FD_DOR) {					\
 			if (new_val & 0xf0)				\
 				new_val = (new_val & 0x0c) |		\
 					  floppy_selects[new_val & 3];	\
 			else						\
 				new_val &= 0x0c;			\
 		}							\
-		outb(new_val, (port));					\
+		outb(new_val, (base) + (reg));				\
 	} while(0)
 
-#define fd_inb(port)		inb((port))
+#define fd_inb(base, reg)	inb((base) + (reg))
 #define fd_request_irq()	request_irq(IRQ_FLOPPYDISK,floppy_interrupt,\
 					    0,"floppy",NULL)
 #define fd_free_irq()		free_irq(IRQ_FLOPPYDISK,NULL)
diff --git a/arch/m68k/include/asm/floppy.h b/arch/m68k/include/asm/floppy.h
index c3b9ad6732fc..2a6ce29b92aa 100644
--- a/arch/m68k/include/asm/floppy.h
+++ b/arch/m68k/include/asm/floppy.h
@@ -63,21 +63,21 @@ static __inline__ void release_dma_lock(unsigned long flags)
 }
 
 
-static __inline__ unsigned char fd_inb(int port)
+static __inline__ unsigned char fd_inb(int base, int reg)
 {
 	if(MACH_IS_Q40)
-		return inb_p(port);
+		return inb_p(base + reg);
 	else if(MACH_IS_SUN3X)
-		return sun3x_82072_fd_inb(port);
+		return sun3x_82072_fd_inb(base + reg);
 	return 0;
 }
 
-static __inline__ void fd_outb(unsigned char value, int port)
+static __inline__ void fd_outb(unsigned char value, int base, int reg)
 {
 	if(MACH_IS_Q40)
-		outb_p(value, port);
+		outb_p(value, base + reg);
 	else if(MACH_IS_SUN3X)
-		sun3x_82072_fd_outb(value, port);
+		sun3x_82072_fd_outb(value, base + reg);
 }
 
 
diff --git a/arch/mips/include/asm/mach-generic/floppy.h b/arch/mips/include/asm/mach-generic/floppy.h
index 9ec2f6a5200b..e3f446d54827 100644
--- a/arch/mips/include/asm/mach-generic/floppy.h
+++ b/arch/mips/include/asm/mach-generic/floppy.h
@@ -26,14 +26,14 @@
 /*
  * How to access the FDC's registers.
  */
-static inline unsigned char fd_inb(unsigned int port)
+static inline unsigned char fd_inb(unsigned int base, unsigned int reg)
 {
-	return inb_p(port);
+	return inb_p(base + reg);
 }
 
-static inline void fd_outb(unsigned char value, unsigned int port)
+static inline void fd_outb(unsigned char value, unsigned int base, unsigned int reg)
 {
-	outb_p(value, port);
+	outb_p(value, base + reg);
 }
 
 /*
diff --git a/arch/mips/include/asm/mach-jazz/floppy.h b/arch/mips/include/asm/mach-jazz/floppy.h
index 4b86c88a03b7..095000c290e5 100644
--- a/arch/mips/include/asm/mach-jazz/floppy.h
+++ b/arch/mips/include/asm/mach-jazz/floppy.h
@@ -17,19 +17,19 @@
 #include <asm/jazzdma.h>
 #include <asm/pgtable.h>
 
-static inline unsigned char fd_inb(unsigned int port)
+static inline unsigned char fd_inb(unsigned int base, unsigned int reg)
 {
 	unsigned char c;
 
-	c = *(volatile unsigned char *) port;
+	c = *(volatile unsigned char *) (base + reg);
 	udelay(1);
 
 	return c;
 }
 
-static inline void fd_outb(unsigned char value, unsigned int port)
+static inline void fd_outb(unsigned char value, unsigned int base, unsigned int reg)
 {
-	*(volatile unsigned char *) port = value;
+	*(volatile unsigned char *) (base + reg) = value;
 }
 
 /*
diff --git a/arch/parisc/include/asm/floppy.h b/arch/parisc/include/asm/floppy.h
index 09b6f4c1687e..1aebc23b7744 100644
--- a/arch/parisc/include/asm/floppy.h
+++ b/arch/parisc/include/asm/floppy.h
@@ -29,8 +29,8 @@
 #define CSW fd_routine[can_use_virtual_dma & 1]
 
 
-#define fd_inb(port)			readb(port)
-#define fd_outb(value, port)		writeb(value, port)
+#define fd_inb(base, reg)		readb((base) + (reg))
+#define fd_outb(value, base, reg)	writeb(value, (base) + (reg))
 
 #define fd_request_dma()        CSW._request_dma(FLOPPY_DMA,"floppy")
 #define fd_free_dma()           CSW._free_dma(FLOPPY_DMA)
@@ -75,19 +75,19 @@ static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
 		register char *lptr = virtual_dma_addr;
 
 		for (lcount = virtual_dma_count; lcount; lcount--) {
-			st = fd_inb(virtual_dma_port+4) & 0xa0 ;
+			st = fd_inb(virtual_dma_port, 4) & 0xa0;
 			if (st != 0xa0) 
 				break;
 			if (virtual_dma_mode) {
-				fd_outb(*lptr, virtual_dma_port+5);
+				fd_outb(*lptr, virtual_dma_port, 5);
 			} else {
-				*lptr = fd_inb(virtual_dma_port+5);
+				*lptr = fd_inb(virtual_dma_port, 5);
 			}
 			lptr++;
 		}
 		virtual_dma_count = lcount;
 		virtual_dma_addr = lptr;
-		st = fd_inb(virtual_dma_port+4);
+		st = fd_inb(virtual_dma_port, 4);
 	}
 
 #ifdef TRACE_FLPY_INT
diff --git a/arch/powerpc/include/asm/floppy.h b/arch/powerpc/include/asm/floppy.h
index 167c44b58848..ed467eb0c4c8 100644
--- a/arch/powerpc/include/asm/floppy.h
+++ b/arch/powerpc/include/asm/floppy.h
@@ -13,8 +13,8 @@
 
 #include <asm/machdep.h>
 
-#define fd_inb(port)		inb_p(port)
-#define fd_outb(value,port)	outb_p(value,port)
+#define fd_inb(base, reg)		inb_p((base) + (reg))
+#define fd_outb(value, base, reg)	outb_p(value, (base) + (reg))
 
 #define fd_enable_dma()         enable_dma(FLOPPY_DMA)
 #define fd_disable_dma()	 fd_ops->_disable_dma(FLOPPY_DMA)
diff --git a/arch/sparc/include/asm/floppy_32.h b/arch/sparc/include/asm/floppy_32.h
index b519acf4383d..4d08df4f4deb 100644
--- a/arch/sparc/include/asm/floppy_32.h
+++ b/arch/sparc/include/asm/floppy_32.h
@@ -59,8 +59,8 @@ struct sun_floppy_ops {
 
 static struct sun_floppy_ops sun_fdops;
 
-#define fd_inb(port)              sun_fdops.fd_inb(port)
-#define fd_outb(value,port)       sun_fdops.fd_outb(value,port)
+#define fd_inb(base, reg)         sun_fdops.fd_inb(reg)
+#define fd_outb(value, base, reg) sun_fdops.fd_outb(value, reg)
 #define fd_enable_dma()           sun_fd_enable_dma()
 #define fd_disable_dma()          sun_fd_disable_dma()
 #define fd_request_dma()          (0) /* nothing... */
diff --git a/arch/sparc/include/asm/floppy_64.h b/arch/sparc/include/asm/floppy_64.h
index 3729fc35ba83..c0cf157e5b15 100644
--- a/arch/sparc/include/asm/floppy_64.h
+++ b/arch/sparc/include/asm/floppy_64.h
@@ -62,8 +62,8 @@ struct sun_floppy_ops {
 
 static struct sun_floppy_ops sun_fdops;
 
-#define fd_inb(port)              sun_fdops.fd_inb(port)
-#define fd_outb(value,port)       sun_fdops.fd_outb(value,port)
+#define fd_inb(base, reg)         sun_fdops.fd_inb((base) + (reg))
+#define fd_outb(value, base, reg) sun_fdops.fd_outb(value, (base) + (reg))
 #define fd_enable_dma()           sun_fdops.fd_enable_dma()
 #define fd_disable_dma()          sun_fdops.fd_disable_dma()
 #define fd_request_dma()          (0) /* nothing... */
diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
index 7ec59edde154..20088cb08f5e 100644
--- a/arch/x86/include/asm/floppy.h
+++ b/arch/x86/include/asm/floppy.h
@@ -31,8 +31,8 @@
 #define CSW fd_routine[can_use_virtual_dma & 1]
 
 
-#define fd_inb(port)		inb_p(port)
-#define fd_outb(value, port)	outb_p(value, port)
+#define fd_inb(base, reg)		inb_p((base) + (reg))
+#define fd_outb(value, base, reg)	outb_p(value, (base) + (reg))
 
 #define fd_request_dma()	CSW._request_dma(FLOPPY_DMA, "floppy")
 #define fd_free_dma()		CSW._free_dma(FLOPPY_DMA)
diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index c3daa64cb52c..1cda39098b07 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -595,12 +595,12 @@ static unsigned char in_sector_offset;	/* offset within physical sector,
 
 static inline unsigned char fdc_inb(int fdc, int reg)
 {
-	return fd_inb(fdc_state[fdc].address + reg);
+	return fd_inb(fdc_state[fdc].address, reg);
 }
 
 static inline void fdc_outb(unsigned char value, int fdc, int reg)
 {
-	fd_outb(value, fdc_state[fdc].address + reg);
+	fd_outb(value, fdc_state[fdc].address, reg);
 }
 
 static inline bool drive_no_geom(int drive)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 02/23] floppy: add references to 82077's extra registers
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
  2020-03-31  9:40 ` [PATCH 01/23] floppy: split the base port from the register in I/O accesses Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 03/23] floppy: use symbolic register names in the m68k port Willy Tarreau
                   ` (22 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

This controller provides extra status registers SRA and SRB as well
as a tape drive register (TDR) and a data rate select register (DSR),
which are referenced in the sparc port, so let's have their symbolic
definitions centralized.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 include/uapi/linux/fdreg.h | 16 +++++++++++++---
 1 file changed, 13 insertions(+), 3 deletions(-)

diff --git a/include/uapi/linux/fdreg.h b/include/uapi/linux/fdreg.h
index 1318881954e1..10d33632939d 100644
--- a/include/uapi/linux/fdreg.h
+++ b/include/uapi/linux/fdreg.h
@@ -7,13 +7,23 @@
  * Handbook", Sanches and Canton.
  */
 
+/* 82077's auxiliary status registers A & B (R) */
+#define FD_SRA		0
+#define FD_SRB		1
+
+/* Digital Output Register */
+#define FD_DOR		2
+
+/* 82077's tape drive register (R/W) */
+#define FD_TDR		3
+
+/* 82077's data rate select register (W) */
+#define FD_DSR		4
+
 /* Fd controller regs. S&C, about page 340 */
 #define FD_STATUS	4
 #define FD_DATA		5
 
-/* Digital Output Register */
-#define FD_DOR		2
-
 /* Digital Input Register (read) */
 #define FD_DIR		7
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 03/23] floppy: use symbolic register names in the m68k port
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
  2020-03-31  9:40 ` [PATCH 01/23] floppy: split the base port from the register in I/O accesses Willy Tarreau
  2020-03-31  9:40 ` [PATCH 02/23] floppy: add references to 82077's extra registers Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 04/23] floppy: use symbolic register names in the parisc port Willy Tarreau
                   ` (21 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau, Geert Uytterhoeven

Now we can use FD_STATUS and FD_DATA instead of 4 or 5, let's do
this, and also use STATUS_DMA and STATUS_READY for the status bits.

Cc: Geert Uytterhoeven <geert@linux-m68k.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 arch/m68k/include/asm/floppy.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/m68k/include/asm/floppy.h b/arch/m68k/include/asm/floppy.h
index 2a6ce29b92aa..a4d0fea47c6b 100644
--- a/arch/m68k/include/asm/floppy.h
+++ b/arch/m68k/include/asm/floppy.h
@@ -211,26 +211,27 @@ asmlinkage irqreturn_t floppy_hardint(int irq, void *dev_id)
 		st=1;
 		for(lcount=virtual_dma_count, lptr=virtual_dma_addr;
 		    lcount; lcount--, lptr++) {
-			st=inb(virtual_dma_port+4) & 0xa0 ;
-			if(st != 0xa0)
+			st = inb(virtual_dma_port + FD_STATUS);
+			st &= STATUS_DMA | STATUS_READY;
+			if (st != (STATUS_DMA | STATUS_READY))
 				break;
 			if(virtual_dma_mode)
-				outb_p(*lptr, virtual_dma_port+5);
+				outb_p(*lptr, virtual_dma_port + FD_DATA);
 			else
-				*lptr = inb_p(virtual_dma_port+5);
+				*lptr = inb_p(virtual_dma_port + FD_DATA);
 		}
 
 		virtual_dma_count = lcount;
 		virtual_dma_addr = lptr;
-		st = inb(virtual_dma_port+4);
+		st = inb(virtual_dma_port + FD_STATUS);
 	}
 
 #ifdef TRACE_FLPY_INT
 	calls++;
 #endif
-	if(st == 0x20)
+	if (st == STATUS_DMA)
 		return IRQ_HANDLED;
-	if(!(st & 0x20)) {
+	if (!(st & STATUS_DMA)) {
 		virtual_dma_residue += virtual_dma_count;
 		virtual_dma_count=0;
 #ifdef TRACE_FLPY_INT
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 04/23] floppy: use symbolic register names in the parisc port
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (2 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 03/23] floppy: use symbolic register names in the m68k port Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 05/23] floppy: use symbolic register names in the powerpc port Willy Tarreau
                   ` (20 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau, Helge Deller

Now we can use FD_STATUS and FD_DATA instead of 4 or 5, let's do
this, and also use STATUS_DMA and STATUS_READY for the status bits.

Cc: Helge Deller <deller@gmx.de>
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 arch/parisc/include/asm/floppy.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/parisc/include/asm/floppy.h b/arch/parisc/include/asm/floppy.h
index 1aebc23b7744..762cfe7778c0 100644
--- a/arch/parisc/include/asm/floppy.h
+++ b/arch/parisc/include/asm/floppy.h
@@ -75,27 +75,28 @@ static void floppy_hardint(int irq, void *dev_id, struct pt_regs * regs)
 		register char *lptr = virtual_dma_addr;
 
 		for (lcount = virtual_dma_count; lcount; lcount--) {
-			st = fd_inb(virtual_dma_port, 4) & 0xa0;
-			if (st != 0xa0) 
+			st = fd_inb(virtual_dma_port, FD_STATUS);
+			st &= STATUS_DMA | STATUS_READY;
+			if (st != (STATUS_DMA | STATUS_READY))
 				break;
 			if (virtual_dma_mode) {
-				fd_outb(*lptr, virtual_dma_port, 5);
+				fd_outb(*lptr, virtual_dma_port, FD_DATA);
 			} else {
-				*lptr = fd_inb(virtual_dma_port, 5);
+				*lptr = fd_inb(virtual_dma_port, FD_DATA);
 			}
 			lptr++;
 		}
 		virtual_dma_count = lcount;
 		virtual_dma_addr = lptr;
-		st = fd_inb(virtual_dma_port, 4);
+		st = fd_inb(virtual_dma_port, FD_STATUS);
 	}
 
 #ifdef TRACE_FLPY_INT
 	calls++;
 #endif
-	if (st == 0x20)
+	if (st == STATUS_DMA)
 		return;
-	if (!(st & 0x20)) {
+	if (!(st & STATUS_DMA)) {
 		virtual_dma_residue += virtual_dma_count;
 		virtual_dma_count = 0;
 #ifdef TRACE_FLPY_INT
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 05/23] floppy: use symbolic register names in the powerpc port
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (3 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 04/23] floppy: use symbolic register names in the parisc port Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 06/23] floppy: use symbolic register names in the sparc32 port Willy Tarreau
                   ` (19 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau,
	Benjamin Herrenschmidt

Now we can use FD_STATUS and FD_DATA instead of 4 or 5, let's do
this, and also use STATUS_DMA and STATUS_READY for the status bits.

Cc: Benjamin Herrenschmidt <benh@kernel.crashing.org>
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 arch/powerpc/include/asm/floppy.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/powerpc/include/asm/floppy.h b/arch/powerpc/include/asm/floppy.h
index ed467eb0c4c8..7af9a68fd949 100644
--- a/arch/powerpc/include/asm/floppy.h
+++ b/arch/powerpc/include/asm/floppy.h
@@ -61,21 +61,22 @@ static irqreturn_t floppy_hardint(int irq, void *dev_id)
 	st = 1;
 	for (lcount=virtual_dma_count, lptr=virtual_dma_addr;
 	     lcount; lcount--, lptr++) {
-		st=inb(virtual_dma_port+4) & 0xa0 ;
-		if (st != 0xa0)
+		st = inb(virtual_dma_port + FD_STATUS);
+		st &= STATUS_DMA | STATUS_READY;
+		if (st != (STATUS_DMA | STATUS_READY))
 			break;
 		if (virtual_dma_mode)
-			outb_p(*lptr, virtual_dma_port+5);
+			outb_p(*lptr, virtual_dma_port + FD_DATA);
 		else
-			*lptr = inb_p(virtual_dma_port+5);
+			*lptr = inb_p(virtual_dma_port + FD_DATA);
 	}
 	virtual_dma_count = lcount;
 	virtual_dma_addr = lptr;
-	st = inb(virtual_dma_port+4);
+	st = inb(virtual_dma_port + FD_STATUS);
 
-	if (st == 0x20)
+	if (st == STATUS_DMA)
 		return IRQ_HANDLED;
-	if (!(st & 0x20)) {
+	if (!(st & STATUS_DMA)) {
 		virtual_dma_residue += virtual_dma_count;
 		virtual_dma_count=0;
 		doing_vdma = 0;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 06/23] floppy: use symbolic register names in the sparc32 port
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (4 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 05/23] floppy: use symbolic register names in the powerpc port Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 07/23] floppy: use symbolic register names in the sparc64 port Willy Tarreau
                   ` (18 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau, David S. Miller

The sparc port used to be forced to rely on numeric register indexes
with their equivalent in comments. Now that they don't depend on the
IO port we can use their symbolic names.

Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 arch/sparc/include/asm/floppy_32.h | 46 +++++++++++++++---------------
 1 file changed, 23 insertions(+), 23 deletions(-)

diff --git a/arch/sparc/include/asm/floppy_32.h b/arch/sparc/include/asm/floppy_32.h
index 4d08df4f4deb..946dbcbf3a83 100644
--- a/arch/sparc/include/asm/floppy_32.h
+++ b/arch/sparc/include/asm/floppy_32.h
@@ -114,15 +114,15 @@ static unsigned char sun_read_dir(void)
 static unsigned char sun_82072_fd_inb(int port)
 {
 	udelay(5);
-	switch(port & 7) {
+	switch (port) {
 	default:
 		printk("floppy: Asked to read unknown port %d\n", port);
 		panic("floppy: Port bolixed.");
-	case 4: /* FD_STATUS */
+	case FD_STATUS:
 		return sun_fdc->status_82072 & ~STATUS_DMA;
-	case 5: /* FD_DATA */
+	case FD_DATA:
 		return sun_fdc->data_82072;
-	case 7: /* FD_DIR */
+	case FD_DIR:
 		return sun_read_dir();
 	}
 	panic("sun_82072_fd_inb: How did I get here?");
@@ -131,20 +131,20 @@ static unsigned char sun_82072_fd_inb(int port)
 static void sun_82072_fd_outb(unsigned char value, int port)
 {
 	udelay(5);
-	switch(port & 7) {
+	switch (port) {
 	default:
 		printk("floppy: Asked to write to unknown port %d\n", port);
 		panic("floppy: Port bolixed.");
-	case 2: /* FD_DOR */
+	case FD_DOR:
 		sun_set_dor(value, 0);
 		break;
-	case 5: /* FD_DATA */
+	case FD_DATA:
 		sun_fdc->data_82072 = value;
 		break;
-	case 7: /* FD_DCR */
+	case FD_DCR:
 		sun_fdc->dcr_82072 = value;
 		break;
-	case 4: /* FD_STATUS */
+	case FD_DSR:
 		sun_fdc->status_82072 = value;
 		break;
 	}
@@ -154,23 +154,23 @@ static void sun_82072_fd_outb(unsigned char value, int port)
 static unsigned char sun_82077_fd_inb(int port)
 {
 	udelay(5);
-	switch(port & 7) {
+	switch (port) {
 	default:
 		printk("floppy: Asked to read unknown port %d\n", port);
 		panic("floppy: Port bolixed.");
-	case 0: /* FD_STATUS_0 */
+	case FD_SRA:
 		return sun_fdc->status1_82077;
-	case 1: /* FD_STATUS_1 */
+	case FD_SRB:
 		return sun_fdc->status2_82077;
-	case 2: /* FD_DOR */
+	case FD_DOR:
 		return sun_fdc->dor_82077;
-	case 3: /* FD_TDR */
+	case FD_TDR:
 		return sun_fdc->tapectl_82077;
-	case 4: /* FD_STATUS */
+	case FD_STATUS:
 		return sun_fdc->status_82077 & ~STATUS_DMA;
-	case 5: /* FD_DATA */
+	case FD_DATA:
 		return sun_fdc->data_82077;
-	case 7: /* FD_DIR */
+	case FD_DIR:
 		return sun_read_dir();
 	}
 	panic("sun_82077_fd_inb: How did I get here?");
@@ -179,23 +179,23 @@ static unsigned char sun_82077_fd_inb(int port)
 static void sun_82077_fd_outb(unsigned char value, int port)
 {
 	udelay(5);
-	switch(port & 7) {
+	switch (port) {
 	default:
 		printk("floppy: Asked to write to unknown port %d\n", port);
 		panic("floppy: Port bolixed.");
-	case 2: /* FD_DOR */
+	case FD_DOR:
 		sun_set_dor(value, 1);
 		break;
-	case 5: /* FD_DATA */
+	case FD_DATA:
 		sun_fdc->data_82077 = value;
 		break;
-	case 7: /* FD_DCR */
+	case FD_DCR:
 		sun_fdc->dcr_82077 = value;
 		break;
-	case 4: /* FD_STATUS */
+	case FD_DSR:
 		sun_fdc->status_82077 = value;
 		break;
-	case 3: /* FD_TDR */
+	case FD_TDR:
 		sun_fdc->tapectl_82077 = value;
 		break;
 	}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 07/23] floppy: use symbolic register names in the sparc64 port
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (5 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 06/23] floppy: use symbolic register names in the sparc32 port Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-04-14  9:20   ` Denis Efremov
  2020-03-31  9:40 ` [PATCH 08/23] floppy: use symbolic register names in the x86 port Willy Tarreau
                   ` (17 subsequent siblings)
  24 siblings, 1 reply; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau, David S. Miller

Now by splitting the base address from the register index we can
use the symbolic register names instead of the hard-coded numeric
values.

Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 arch/sparc/include/asm/floppy_64.h | 59 ++++++++++++++++--------------
 1 file changed, 32 insertions(+), 27 deletions(-)

diff --git a/arch/sparc/include/asm/floppy_64.h b/arch/sparc/include/asm/floppy_64.h
index c0cf157e5b15..bd7847f2c64a 100644
--- a/arch/sparc/include/asm/floppy_64.h
+++ b/arch/sparc/include/asm/floppy_64.h
@@ -47,8 +47,9 @@ unsigned long fdc_status;
 static struct platform_device *floppy_op = NULL;
 
 struct sun_floppy_ops {
-	unsigned char	(*fd_inb) (unsigned long port);
-	void		(*fd_outb) (unsigned char value, unsigned long port);
+	unsigned char	(*fd_inb) (unsigned long port, unsigned int reg);
+	void		(*fd_outb) (unsigned char value, unsigned long base,
+				    unsigned int reg);
 	void		(*fd_enable_dma) (void);
 	void		(*fd_disable_dma) (void);
 	void		(*fd_set_dma_mode) (int);
@@ -62,8 +63,8 @@ struct sun_floppy_ops {
 
 static struct sun_floppy_ops sun_fdops;
 
-#define fd_inb(base, reg)         sun_fdops.fd_inb((base) + (reg))
-#define fd_outb(value, base, reg) sun_fdops.fd_outb(value, (base) + (reg))
+#define fd_inb(base, reg)         sun_fdops.fd_inb(base, reg)
+#define fd_outb(value, base, reg) sun_fdops.fd_outb(value, base, reg)
 #define fd_enable_dma()           sun_fdops.fd_enable_dma()
 #define fd_disable_dma()          sun_fdops.fd_disable_dma()
 #define fd_request_dma()          (0) /* nothing... */
@@ -97,42 +98,43 @@ static int sun_floppy_types[2] = { 0, 0 };
 /* No 64k boundary crossing problems on the Sparc. */
 #define CROSS_64KB(a,s) (0)
 
-static unsigned char sun_82077_fd_inb(unsigned long port)
+static unsigned char sun_82077_fd_inb(unsigned long base, unsigned int reg)
 {
 	udelay(5);
-	switch(port & 7) {
+	switch (reg) {
 	default:
-		printk("floppy: Asked to read unknown port %lx\n", port);
+		printk("floppy: Asked to read unknown port %lx\n", reg);
 		panic("floppy: Port bolixed.");
-	case 4: /* FD_STATUS */
+	case FD_STATUS:
 		return sbus_readb(&sun_fdc->status_82077) & ~STATUS_DMA;
-	case 5: /* FD_DATA */
+	case FD_DATA:
 		return sbus_readb(&sun_fdc->data_82077);
-	case 7: /* FD_DIR */
+	case FD_DIR:
 		/* XXX: Is DCL on 0x80 in sun4m? */
 		return sbus_readb(&sun_fdc->dir_82077);
 	}
 	panic("sun_82072_fd_inb: How did I get here?");
 }
 
-static void sun_82077_fd_outb(unsigned char value, unsigned long port)
+static void sun_82077_fd_outb(unsigned char value, unsigned long base,
+			      unsigned int reg)
 {
 	udelay(5);
-	switch(port & 7) {
+	switch (reg) {
 	default:
-		printk("floppy: Asked to write to unknown port %lx\n", port);
+		printk("floppy: Asked to write to unknown port %lx\n", reg);
 		panic("floppy: Port bolixed.");
-	case 2: /* FD_DOR */
+	case FD_DOR:
 		/* Happily, the 82077 has a real DOR register. */
 		sbus_writeb(value, &sun_fdc->dor_82077);
 		break;
-	case 5: /* FD_DATA */
+	case FD_DATA:
 		sbus_writeb(value, &sun_fdc->data_82077);
 		break;
-	case 7: /* FD_DCR */
+	case FD_DCR:
 		sbus_writeb(value, &sun_fdc->dcr_82077);
 		break;
-	case 4: /* FD_STATUS */
+	case FD_DSR:
 		sbus_writeb(value, &sun_fdc->status_82077);
 		break;
 	}
@@ -298,19 +300,21 @@ static struct sun_pci_dma_op sun_pci_dma_pending = { -1U, 0, 0, NULL};
 
 irqreturn_t floppy_interrupt(int irq, void *dev_id);
 
-static unsigned char sun_pci_fd_inb(unsigned long port)
+static unsigned char sun_pci_fd_inb(unsigned long base, unsigned int reg)
 {
 	udelay(5);
-	return inb(port);
+	return inb(base + reg);
 }
 
-static void sun_pci_fd_outb(unsigned char val, unsigned long port)
+static void sun_pci_fd_outb(unsigned char val, unsigned long base,
+			    unsigned int reg)
 {
 	udelay(5);
-	outb(val, port);
+	outb(val, base + reg);
 }
 
-static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
+static void sun_pci_fd_broken_outb(unsigned char val, unsigned long base,
+				   unsigned int reg)
 {
 	udelay(5);
 	/*
@@ -320,16 +324,17 @@ static void sun_pci_fd_broken_outb(unsigned char val, unsigned long port)
 	 *      this does not hurt correct hardware like the AXmp.
 	 *      (Eddie, Sep 12 1998).
 	 */
-	if (port == ((unsigned long)sun_fdc) + 2) {
+	if (reg == FD_DOR) {
 		if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x20)) {
 			val |= 0x10;
 		}
 	}
-	outb(val, port);
+	outb(val, base + reg);
 }
 
 #ifdef PCI_FDC_SWAP_DRIVES
-static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
+static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long base,
+				       unsigned int reg)
 {
 	udelay(5);
 	/*
@@ -339,13 +344,13 @@ static void sun_pci_fd_lde_broken_outb(unsigned char val, unsigned long port)
 	 *      this does not hurt correct hardware like the AXmp.
 	 *      (Eddie, Sep 12 1998).
 	 */
-	if (port == ((unsigned long)sun_fdc) + 2) {
+	if (reg == FD_DOR) {
 		if (((val & 0x03) == sun_pci_broken_drive) && (val & 0x10)) {
 			val &= ~(0x03);
 			val |= 0x21;
 		}
 	}
-	outb(val, port);
+	outb(val, base + reg);
 }
 #endif /* PCI_FDC_SWAP_DRIVES */
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 08/23] floppy: use symbolic register names in the x86 port
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (6 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 07/23] floppy: use symbolic register names in the sparc64 port Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 09/23] floppy: cleanup: make twaddle() not rely on current_{fdc,drive} anymore Willy Tarreau
                   ` (16 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau, x86

Now we can use FD_STATUS and FD_DATA instead of 4 or 5, let's do
this, and also use STATUS_DMA and STATUS_READY for the status bits.

Cc: x86@kernel.org
Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 arch/x86/include/asm/floppy.h | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
index 20088cb08f5e..d43717b423cb 100644
--- a/arch/x86/include/asm/floppy.h
+++ b/arch/x86/include/asm/floppy.h
@@ -77,25 +77,26 @@ static irqreturn_t floppy_hardint(int irq, void *dev_id)
 		st = 1;
 		for (lcount = virtual_dma_count, lptr = virtual_dma_addr;
 		     lcount; lcount--, lptr++) {
-			st = inb(virtual_dma_port + 4) & 0xa0;
-			if (st != 0xa0)
+			st = inb(virtual_dma_port + FD_STATUS);
+			st &= STATUS_DMA | STATUS_READY;
+			if (st != (STATUS_DMA | STATUS_READY))
 				break;
 			if (virtual_dma_mode)
-				outb_p(*lptr, virtual_dma_port + 5);
+				outb_p(*lptr, virtual_dma_port + FD_DATA);
 			else
-				*lptr = inb_p(virtual_dma_port + 5);
+				*lptr = inb_p(virtual_dma_port + FD_DATA);
 		}
 		virtual_dma_count = lcount;
 		virtual_dma_addr = lptr;
-		st = inb(virtual_dma_port + 4);
+		st = inb(virtual_dma_port + FD_STATUS);
 	}
 
 #ifdef TRACE_FLPY_INT
 	calls++;
 #endif
-	if (st == 0x20)
+	if (st == STATUS_DMA)
 		return IRQ_HANDLED;
-	if (!(st & 0x20)) {
+	if (!(st & STATUS_DMA)) {
 		virtual_dma_residue += virtual_dma_count;
 		virtual_dma_count = 0;
 #ifdef TRACE_FLPY_INT
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 09/23] floppy: cleanup: make twaddle() not rely on current_{fdc,drive} anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (7 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 08/23] floppy: use symbolic register names in the x86 port Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 10/23] floppy: cleanup: make reset_fdc_info() not rely on current_fdc anymore Willy Tarreau
                   ` (15 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc and drive are passed in argument so that the function does
not use current_fdc nor current_drive anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 1cda39098b07..b1729daa2e2e 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -827,14 +827,14 @@ static int set_dor(int fdc, char mask, char data)
 	return olddor;
 }
 
-static void twaddle(void)
+static void twaddle(int fdc, int drive)
 {
-	if (drive_params[current_drive].select_delay)
+	if (drive_params[drive].select_delay)
 		return;
-	fdc_outb(fdc_state[current_fdc].dor & ~(0x10 << UNIT(current_drive)),
-		 current_fdc, FD_DOR);
-	fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
-	drive_state[current_drive].select_date = jiffies;
+	fdc_outb(fdc_state[fdc].dor & ~(0x10 << UNIT(drive)),
+		 fdc, FD_DOR);
+	fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
+	drive_state[drive].select_date = jiffies;
 }
 
 /*
@@ -1934,7 +1934,7 @@ static void floppy_ready(void)
 		  "calling disk change from floppy_ready\n");
 	if (!(raw_cmd->flags & FD_RAW_NO_MOTOR) &&
 	    disk_change(current_drive) && !drive_params[current_drive].select_delay)
-		twaddle();	/* this clears the dcl on certain
+		twaddle(current_fdc, current_drive);	/* this clears the dcl on certain
 				 * drive/controller combinations */
 
 #ifdef fd_chose_dma_mode
@@ -2904,7 +2904,7 @@ static void redo_fd_request(void)
 	}
 
 	if (test_bit(FD_NEED_TWADDLE_BIT, &drive_state[current_drive].flags))
-		twaddle();
+		twaddle(current_fdc, current_drive);
 	schedule_bh(floppy_start);
 	debugt(__func__, "queue fd request");
 	return;
@@ -3610,7 +3610,7 @@ static int fd_locked_ioctl(struct block_device *bdev, fmode_t mode, unsigned int
 	case FDTWADDLE:
 		if (lock_fdc(drive))
 			return -EINTR;
-		twaddle();
+		twaddle(current_fdc, current_drive);
 		process_fd_request();
 		return 0;
 	default:
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 10/23] floppy: cleanup: make reset_fdc_info() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (8 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 09/23] floppy: cleanup: make twaddle() not rely on current_{fdc,drive} anymore Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 11/23] floppy: cleanup: make show_floppy() " Willy Tarreau
                   ` (14 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index b1729daa2e2e..6c98f8d169a9 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -838,19 +838,19 @@ static void twaddle(int fdc, int drive)
 }
 
 /*
- * Reset all driver information about the current fdc.
+ * Reset all driver information about the specified fdc.
  * This is needed after a reset, and after a raw command.
  */
-static void reset_fdc_info(int mode)
+static void reset_fdc_info(int fdc, int mode)
 {
 	int drive;
 
-	fdc_state[current_fdc].spec1 = fdc_state[current_fdc].spec2 = -1;
-	fdc_state[current_fdc].need_configure = 1;
-	fdc_state[current_fdc].perp_mode = 1;
-	fdc_state[current_fdc].rawcmd = 0;
+	fdc_state[fdc].spec1 = fdc_state[fdc].spec2 = -1;
+	fdc_state[fdc].need_configure = 1;
+	fdc_state[fdc].perp_mode = 1;
+	fdc_state[fdc].rawcmd = 0;
 	for (drive = 0; drive < N_DRIVE; drive++)
-		if (FDC(drive) == current_fdc &&
+		if (FDC(drive) == fdc &&
 		    (mode || drive_state[drive].track != NEED_1_RECAL))
 			drive_state[drive].track = NEED_2_RECAL;
 }
@@ -874,7 +874,7 @@ static void set_fdc(int drive)
 	set_dor(1 - current_fdc, ~8, 0);
 #endif
 	if (fdc_state[current_fdc].rawcmd == 2)
-		reset_fdc_info(1);
+		reset_fdc_info(current_fdc, 1);
 	if (fdc_inb(current_fdc, FD_STATUS) != STATUS_READY)
 		fdc_state[current_fdc].reset = 1;
 }
@@ -1800,7 +1800,7 @@ static void reset_fdc(void)
 
 	do_floppy = reset_interrupt;
 	fdc_state[current_fdc].reset = 0;
-	reset_fdc_info(0);
+	reset_fdc_info(current_fdc, 0);
 
 	/* Pseudo-DMA may intercept 'reset finished' interrupt.  */
 	/* Irrelevant for systems with true DMA (i386).          */
@@ -4890,7 +4890,7 @@ static int floppy_grab_irq_and_dma(void)
 	}
 	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
 		if (fdc_state[current_fdc].address != -1) {
-			reset_fdc_info(1);
+			reset_fdc_info(current_fdc, 1);
 			fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
 		}
 	}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 11/23] floppy: cleanup: make show_floppy() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (9 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 10/23] floppy: cleanup: make reset_fdc_info() not rely on current_fdc anymore Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 12/23] floppy: cleanup: make wait_til_ready() " Willy Tarreau
                   ` (13 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 14 +++++++-------
 1 file changed, 7 insertions(+), 7 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 6c98f8d169a9..dd739594fce7 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1104,7 +1104,7 @@ static void setup_DMA(void)
 #endif
 }
 
-static void show_floppy(void);
+static void show_floppy(int fdc);
 
 /* waits until the fdc becomes ready */
 static int wait_til_ready(void)
@@ -1121,7 +1121,7 @@ static int wait_til_ready(void)
 	}
 	if (initialized) {
 		DPRINT("Getstatus times out (%x) on fdc %d\n", status, current_fdc);
-		show_floppy();
+		show_floppy(current_fdc);
 	}
 	fdc_state[current_fdc].reset = 1;
 	return -1;
@@ -1147,7 +1147,7 @@ static int output_byte(char byte)
 	if (initialized) {
 		DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
 		       byte, current_fdc, status);
-		show_floppy();
+		show_floppy(current_fdc);
 	}
 	return -1;
 }
@@ -1176,7 +1176,7 @@ static int result(void)
 	if (initialized) {
 		DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
 		       current_fdc, status, i);
-		show_floppy();
+		show_floppy(current_fdc);
 	}
 	fdc_state[current_fdc].reset = 1;
 	return -1;
@@ -1819,7 +1819,7 @@ static void reset_fdc(void)
 	}
 }
 
-static void show_floppy(void)
+static void show_floppy(int fdc)
 {
 	int i;
 
@@ -1842,7 +1842,7 @@ static void show_floppy(void)
 	print_hex_dump(KERN_INFO, "", DUMP_PREFIX_NONE, 16, 1,
 		       reply_buffer, resultsize, true);
 
-	pr_info("status=%x\n", fdc_inb(current_fdc, FD_STATUS));
+	pr_info("status=%x\n", fdc_inb(fdc, FD_STATUS));
 	pr_info("fdc_busy=%lu\n", fdc_busy);
 	if (do_floppy)
 		pr_info("do_floppy=%ps\n", do_floppy);
@@ -1868,7 +1868,7 @@ static void floppy_shutdown(struct work_struct *arg)
 	unsigned long flags;
 
 	if (initialized)
-		show_floppy();
+		show_floppy(current_fdc);
 	cancel_activity();
 
 	flags = claim_dma_lock();
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 12/23] floppy: cleanup: make wait_til_ready() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (10 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 11/23] floppy: cleanup: make show_floppy() " Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 13/23] floppy: cleanup: make output_byte() " Willy Tarreau
                   ` (12 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 18 +++++++++---------
 1 file changed, 9 insertions(+), 9 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index dd739594fce7..5dfddd4726fb 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1107,30 +1107,30 @@ static void setup_DMA(void)
 static void show_floppy(int fdc);
 
 /* waits until the fdc becomes ready */
-static int wait_til_ready(void)
+static int wait_til_ready(int fdc)
 {
 	int status;
 	int counter;
 
-	if (fdc_state[current_fdc].reset)
+	if (fdc_state[fdc].reset)
 		return -1;
 	for (counter = 0; counter < 10000; counter++) {
-		status = fdc_inb(current_fdc, FD_STATUS);
+		status = fdc_inb(fdc, FD_STATUS);
 		if (status & STATUS_READY)
 			return status;
 	}
 	if (initialized) {
-		DPRINT("Getstatus times out (%x) on fdc %d\n", status, current_fdc);
-		show_floppy(current_fdc);
+		DPRINT("Getstatus times out (%x) on fdc %d\n", status, fdc);
+		show_floppy(fdc);
 	}
-	fdc_state[current_fdc].reset = 1;
+	fdc_state[fdc].reset = 1;
 	return -1;
 }
 
 /* sends a command byte to the fdc */
 static int output_byte(char byte)
 {
-	int status = wait_til_ready();
+	int status = wait_til_ready(current_fdc);
 
 	if (status < 0)
 		return -1;
@@ -1159,7 +1159,7 @@ static int result(void)
 	int status = 0;
 
 	for (i = 0; i < MAX_REPLIES; i++) {
-		status = wait_til_ready();
+		status = wait_til_ready(current_fdc);
 		if (status < 0)
 			break;
 		status &= STATUS_DIR | STATUS_READY | STATUS_BUSY | STATUS_DMA;
@@ -1186,7 +1186,7 @@ static int result(void)
 /* does the fdc need more output? */
 static int need_more_output(void)
 {
-	int status = wait_til_ready();
+	int status = wait_til_ready(current_fdc);
 
 	if (status < 0)
 		return -1;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 13/23] floppy: cleanup: make output_byte() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (11 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 12/23] floppy: cleanup: make wait_til_ready() " Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 14/23] floppy: cleanup: make result() " Willy Tarreau
                   ` (11 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 64 +++++++++++++++++++++---------------------
 1 file changed, 32 insertions(+), 32 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 5dfddd4726fb..81fd06eaea7d 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1128,26 +1128,26 @@ static int wait_til_ready(int fdc)
 }
 
 /* sends a command byte to the fdc */
-static int output_byte(char byte)
+static int output_byte(int fdc, char byte)
 {
-	int status = wait_til_ready(current_fdc);
+	int status = wait_til_ready(fdc);
 
 	if (status < 0)
 		return -1;
 
 	if (is_ready_state(status)) {
-		fdc_outb(byte, current_fdc, FD_DATA);
+		fdc_outb(byte, fdc, FD_DATA);
 		output_log[output_log_pos].data = byte;
 		output_log[output_log_pos].status = status;
 		output_log[output_log_pos].jiffies = jiffies;
 		output_log_pos = (output_log_pos + 1) % OLOGSIZE;
 		return 0;
 	}
-	fdc_state[current_fdc].reset = 1;
+	fdc_state[fdc].reset = 1;
 	if (initialized) {
 		DPRINT("Unable to send byte %x to FDC. Fdc=%x Status=%x\n",
-		       byte, current_fdc, status);
-		show_floppy(current_fdc);
+		       byte, fdc, status);
+		show_floppy(fdc);
 	}
 	return -1;
 }
@@ -1229,8 +1229,8 @@ static void perpendicular_mode(void)
 	if (fdc_state[current_fdc].perp_mode == perp_mode)
 		return;
 	if (fdc_state[current_fdc].version >= FDC_82077_ORIG) {
-		output_byte(FD_PERPENDICULAR);
-		output_byte(perp_mode);
+		output_byte(current_fdc, FD_PERPENDICULAR);
+		output_byte(current_fdc, perp_mode);
 		fdc_state[current_fdc].perp_mode = perp_mode;
 	} else if (perp_mode) {
 		DPRINT("perpendicular mode not supported by this FDC.\n");
@@ -1243,12 +1243,12 @@ static int no_fifo;
 static int fdc_configure(void)
 {
 	/* Turn on FIFO */
-	output_byte(FD_CONFIGURE);
+	output_byte(current_fdc, FD_CONFIGURE);
 	if (need_more_output() != MORE_OUTPUT)
 		return 0;
-	output_byte(0);
-	output_byte(0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
-	output_byte(0);		/* pre-compensation from track
+	output_byte(current_fdc, 0);
+	output_byte(current_fdc, 0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
+	output_byte(current_fdc, 0);		/* pre-compensation from track
 				   0 upwards */
 	return 1;
 }
@@ -1301,10 +1301,10 @@ static void fdc_specify(void)
 		if (fdc_state[current_fdc].version >= FDC_82078) {
 			/* chose the default rate table, not the one
 			 * where 1 = 2 Mbps */
-			output_byte(FD_DRIVESPEC);
+			output_byte(current_fdc, FD_DRIVESPEC);
 			if (need_more_output() == MORE_OUTPUT) {
-				output_byte(UNIT(current_drive));
-				output_byte(0xc0);
+				output_byte(current_fdc, UNIT(current_drive));
+				output_byte(current_fdc, 0xc0);
 			}
 		}
 		break;
@@ -1349,9 +1349,9 @@ static void fdc_specify(void)
 	if (fdc_state[current_fdc].spec1 != spec1 ||
 	    fdc_state[current_fdc].spec2 != spec2) {
 		/* Go ahead and set spec1 and spec2 */
-		output_byte(FD_SPECIFY);
-		output_byte(fdc_state[current_fdc].spec1 = spec1);
-		output_byte(fdc_state[current_fdc].spec2 = spec2);
+		output_byte(current_fdc, FD_SPECIFY);
+		output_byte(current_fdc, fdc_state[current_fdc].spec1 = spec1);
+		output_byte(current_fdc, fdc_state[current_fdc].spec2 = spec2);
 	}
 }				/* fdc_specify */
 
@@ -1513,7 +1513,7 @@ static void setup_rw_floppy(void)
 
 	r = 0;
 	for (i = 0; i < raw_cmd->cmd_count; i++)
-		r |= output_byte(raw_cmd->cmd[i]);
+		r |= output_byte(current_fdc, raw_cmd->cmd[i]);
 
 	debugt(__func__, "rw_command");
 
@@ -1566,8 +1566,8 @@ static void check_wp(void)
 {
 	if (test_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags)) {
 					/* check write protection */
-		output_byte(FD_GETSTATUS);
-		output_byte(UNIT(current_drive));
+		output_byte(current_fdc, FD_GETSTATUS);
+		output_byte(current_fdc, UNIT(current_drive));
 		if (result() != 1) {
 			fdc_state[current_fdc].reset = 1;
 			return;
@@ -1639,9 +1639,9 @@ static void seek_floppy(void)
 	}
 
 	do_floppy = seek_interrupt;
-	output_byte(FD_SEEK);
-	output_byte(UNIT(current_drive));
-	if (output_byte(track) < 0) {
+	output_byte(current_fdc, FD_SEEK);
+	output_byte(current_fdc, UNIT(current_drive));
+	if (output_byte(current_fdc, track) < 0) {
 		reset_fdc();
 		return;
 	}
@@ -1748,7 +1748,7 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
 	if (inr == 0) {
 		int max_sensei = 4;
 		do {
-			output_byte(FD_SENSEI);
+			output_byte(current_fdc, FD_SENSEI);
 			inr = result();
 			if (do_print)
 				print_result("sensei", inr);
@@ -1771,8 +1771,8 @@ static void recalibrate_floppy(void)
 {
 	debugt(__func__, "");
 	do_floppy = recal_interrupt;
-	output_byte(FD_RECALIBRATE);
-	if (output_byte(UNIT(current_drive)) < 0)
+	output_byte(current_fdc, FD_RECALIBRATE);
+	if (output_byte(current_fdc, UNIT(current_drive)) < 0)
 		reset_fdc();
 }
 
@@ -4302,7 +4302,7 @@ static char __init get_fdc_version(void)
 {
 	int r;
 
-	output_byte(FD_DUMPREGS);	/* 82072 and better know DUMPREGS */
+	output_byte(current_fdc, FD_DUMPREGS);	/* 82072 and better know DUMPREGS */
 	if (fdc_state[current_fdc].reset)
 		return FDC_NONE;
 	r = result();
@@ -4323,15 +4323,15 @@ static char __init get_fdc_version(void)
 		return FDC_82072;	/* 82072 doesn't know CONFIGURE */
 	}
 
-	output_byte(FD_PERPENDICULAR);
+	output_byte(current_fdc, FD_PERPENDICULAR);
 	if (need_more_output() == MORE_OUTPUT) {
-		output_byte(0);
+		output_byte(current_fdc, 0);
 	} else {
 		pr_info("FDC %d is an 82072A\n", current_fdc);
 		return FDC_82072A;	/* 82072A as found on Sparcs. */
 	}
 
-	output_byte(FD_UNLOCK);
+	output_byte(current_fdc, FD_UNLOCK);
 	r = result();
 	if ((r == 1) && (reply_buffer[0] == 0x80)) {
 		pr_info("FDC %d is a pre-1991 82077\n", current_fdc);
@@ -4343,7 +4343,7 @@ static char __init get_fdc_version(void)
 			current_fdc, r);
 		return FDC_UNKNOWN;
 	}
-	output_byte(FD_PARTID);
+	output_byte(current_fdc, FD_PARTID);
 	r = result();
 	if (r != 1) {
 		pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n",
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 14/23] floppy: cleanup: make result() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (12 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 13/23] floppy: cleanup: make output_byte() " Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 15/23] floppy: cleanup: make need_more_output() " Willy Tarreau
                   ` (10 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

It's worth noting that there's still a single reply_buffer[] which
will store the result for the current fdc. It may or may not make
sense to implement one buffer per fdc in the future.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 30 +++++++++++++++---------------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 81fd06eaea7d..4aaf84217b53 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1153,13 +1153,13 @@ static int output_byte(int fdc, char byte)
 }
 
 /* gets the response from the fdc */
-static int result(void)
+static int result(int fdc)
 {
 	int i;
 	int status = 0;
 
 	for (i = 0; i < MAX_REPLIES; i++) {
-		status = wait_til_ready(current_fdc);
+		status = wait_til_ready(fdc);
 		if (status < 0)
 			break;
 		status &= STATUS_DIR | STATUS_READY | STATUS_BUSY | STATUS_DMA;
@@ -1169,16 +1169,16 @@ static int result(void)
 			return i;
 		}
 		if (status == (STATUS_DIR | STATUS_READY | STATUS_BUSY))
-			reply_buffer[i] = fdc_inb(current_fdc, FD_DATA);
+			reply_buffer[i] = fdc_inb(fdc, FD_DATA);
 		else
 			break;
 	}
 	if (initialized) {
 		DPRINT("get result error. Fdc=%d Last status=%x Read bytes=%d\n",
-		       current_fdc, status, i);
-		show_floppy(current_fdc);
+		       fdc, status, i);
+		show_floppy(fdc);
 	}
-	fdc_state[current_fdc].reset = 1;
+	fdc_state[fdc].reset = 1;
 	return -1;
 }
 
@@ -1194,7 +1194,7 @@ static int need_more_output(void)
 	if (is_ready_state(status))
 		return MORE_OUTPUT;
 
-	return result();
+	return result(current_fdc);
 }
 
 /* Set perpendicular mode as required, based on data rate, if supported.
@@ -1524,7 +1524,7 @@ static void setup_rw_floppy(void)
 	}
 
 	if (!(flags & FD_RAW_INTR)) {
-		inr = result();
+		inr = result(current_fdc);
 		cont->interrupt();
 	} else if (flags & FD_RAW_NEED_DISK)
 		fd_watchdog();
@@ -1568,7 +1568,7 @@ static void check_wp(void)
 					/* check write protection */
 		output_byte(current_fdc, FD_GETSTATUS);
 		output_byte(current_fdc, UNIT(current_drive));
-		if (result() != 1) {
+		if (result(current_fdc) != 1) {
 			fdc_state[current_fdc].reset = 1;
 			return;
 		}
@@ -1742,14 +1742,14 @@ irqreturn_t floppy_interrupt(int irq, void *dev_id)
 
 	do_print = !handler && print_unex && initialized;
 
-	inr = result();
+	inr = result(current_fdc);
 	if (do_print)
 		print_result("unexpected interrupt", inr);
 	if (inr == 0) {
 		int max_sensei = 4;
 		do {
 			output_byte(current_fdc, FD_SENSEI);
-			inr = result();
+			inr = result(current_fdc);
 			if (do_print)
 				print_result("sensei", inr);
 			max_sensei--;
@@ -1782,7 +1782,7 @@ static void recalibrate_floppy(void)
 static void reset_interrupt(void)
 {
 	debugt(__func__, "");
-	result();		/* get the status ready for set_fdc */
+	result(current_fdc);		/* get the status ready for set_fdc */
 	if (fdc_state[current_fdc].reset) {
 		pr_info("reset set in interrupt, calling %ps\n", cont->error);
 		cont->error();	/* a reset just after a reset. BAD! */
@@ -4305,7 +4305,7 @@ static char __init get_fdc_version(void)
 	output_byte(current_fdc, FD_DUMPREGS);	/* 82072 and better know DUMPREGS */
 	if (fdc_state[current_fdc].reset)
 		return FDC_NONE;
-	r = result();
+	r = result(current_fdc);
 	if (r <= 0x00)
 		return FDC_NONE;	/* No FDC present ??? */
 	if ((r == 1) && (reply_buffer[0] == 0x80)) {
@@ -4332,7 +4332,7 @@ static char __init get_fdc_version(void)
 	}
 
 	output_byte(current_fdc, FD_UNLOCK);
-	r = result();
+	r = result(current_fdc);
 	if ((r == 1) && (reply_buffer[0] == 0x80)) {
 		pr_info("FDC %d is a pre-1991 82077\n", current_fdc);
 		return FDC_82077_ORIG;	/* Pre-1991 82077, doesn't know
@@ -4344,7 +4344,7 @@ static char __init get_fdc_version(void)
 		return FDC_UNKNOWN;
 	}
 	output_byte(current_fdc, FD_PARTID);
-	r = result();
+	r = result(current_fdc);
 	if (r != 1) {
 		pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n",
 			current_fdc, r);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 15/23] floppy: cleanup: make need_more_output() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (13 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 14/23] floppy: cleanup: make result() " Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 16/23] floppy: cleanup: make perpendicular_mode() " Willy Tarreau
                   ` (9 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 4aaf84217b53..aa2d840bf06b 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1184,9 +1184,9 @@ static int result(int fdc)
 
 #define MORE_OUTPUT -2
 /* does the fdc need more output? */
-static int need_more_output(void)
+static int need_more_output(int fdc)
 {
-	int status = wait_til_ready(current_fdc);
+	int status = wait_til_ready(fdc);
 
 	if (status < 0)
 		return -1;
@@ -1194,7 +1194,7 @@ static int need_more_output(void)
 	if (is_ready_state(status))
 		return MORE_OUTPUT;
 
-	return result(current_fdc);
+	return result(fdc);
 }
 
 /* Set perpendicular mode as required, based on data rate, if supported.
@@ -1244,7 +1244,7 @@ static int fdc_configure(void)
 {
 	/* Turn on FIFO */
 	output_byte(current_fdc, FD_CONFIGURE);
-	if (need_more_output() != MORE_OUTPUT)
+	if (need_more_output(current_fdc) != MORE_OUTPUT)
 		return 0;
 	output_byte(current_fdc, 0);
 	output_byte(current_fdc, 0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
@@ -1302,7 +1302,7 @@ static void fdc_specify(void)
 			/* chose the default rate table, not the one
 			 * where 1 = 2 Mbps */
 			output_byte(current_fdc, FD_DRIVESPEC);
-			if (need_more_output() == MORE_OUTPUT) {
+			if (need_more_output(current_fdc) == MORE_OUTPUT) {
 				output_byte(current_fdc, UNIT(current_drive));
 				output_byte(current_fdc, 0xc0);
 			}
@@ -4324,7 +4324,7 @@ static char __init get_fdc_version(void)
 	}
 
 	output_byte(current_fdc, FD_PERPENDICULAR);
-	if (need_more_output() == MORE_OUTPUT) {
+	if (need_more_output(current_fdc) == MORE_OUTPUT) {
 		output_byte(current_fdc, 0);
 	} else {
 		pr_info("FDC %d is an 82072A\n", current_fdc);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 16/23] floppy: cleanup: make perpendicular_mode() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (14 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 15/23] floppy: cleanup: make need_more_output() " Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 17/23] floppy: cleanup: make fdc_configure() " Willy Tarreau
                   ` (8 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

It's worth noting that there's still a single raw_cmd pointer
specific to the current fdc. It may make sense to have one per
fdc in the future. In addition, cont->done() still relies on the
current drive and current raw_cmd.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index aa2d840bf06b..fcccbb4c143e 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1200,7 +1200,7 @@ static int need_more_output(int fdc)
 /* Set perpendicular mode as required, based on data rate, if supported.
  * 82077 Now tested. 1Mbps data rate only possible with 82077-1.
  */
-static void perpendicular_mode(void)
+static void perpendicular_mode(int fdc)
 {
 	unsigned char perp_mode;
 
@@ -1215,7 +1215,7 @@ static void perpendicular_mode(void)
 		default:
 			DPRINT("Invalid data rate for perpendicular mode!\n");
 			cont->done(0);
-			fdc_state[current_fdc].reset = 1;
+			fdc_state[fdc].reset = 1;
 					/*
 					 * convenient way to return to
 					 * redo without too much hassle
@@ -1226,12 +1226,12 @@ static void perpendicular_mode(void)
 	} else
 		perp_mode = 0;
 
-	if (fdc_state[current_fdc].perp_mode == perp_mode)
+	if (fdc_state[fdc].perp_mode == perp_mode)
 		return;
-	if (fdc_state[current_fdc].version >= FDC_82077_ORIG) {
-		output_byte(current_fdc, FD_PERPENDICULAR);
-		output_byte(current_fdc, perp_mode);
-		fdc_state[current_fdc].perp_mode = perp_mode;
+	if (fdc_state[fdc].version >= FDC_82077_ORIG) {
+		output_byte(fdc, FD_PERPENDICULAR);
+		output_byte(fdc, perp_mode);
+		fdc_state[fdc].perp_mode = perp_mode;
 	} else if (perp_mode) {
 		DPRINT("perpendicular mode not supported by this FDC.\n");
 	}
@@ -1946,7 +1946,7 @@ static void floppy_ready(void)
 #endif
 
 	if (raw_cmd->flags & (FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK)) {
-		perpendicular_mode();
+		perpendicular_mode(current_fdc);
 		fdc_specify();	/* must be done here because of hut, hlt ... */
 		seek_floppy();
 	} else {
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 17/23] floppy: cleanup: make fdc_configure() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (15 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 16/23] floppy: cleanup: make perpendicular_mode() " Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 18/23] floppy: cleanup: make fdc_specify() not rely on current_{fdc,drive} anymore Willy Tarreau
                   ` (7 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 17 ++++++++---------
 1 file changed, 8 insertions(+), 9 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index fcccbb4c143e..c1338c4bb941 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1240,16 +1240,15 @@ static void perpendicular_mode(int fdc)
 static int fifo_depth = 0xa;
 static int no_fifo;
 
-static int fdc_configure(void)
+static int fdc_configure(int fdc)
 {
 	/* Turn on FIFO */
-	output_byte(current_fdc, FD_CONFIGURE);
-	if (need_more_output(current_fdc) != MORE_OUTPUT)
+	output_byte(fdc, FD_CONFIGURE);
+	if (need_more_output(fdc) != MORE_OUTPUT)
 		return 0;
-	output_byte(current_fdc, 0);
-	output_byte(current_fdc, 0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
-	output_byte(current_fdc, 0);		/* pre-compensation from track
-				   0 upwards */
+	output_byte(fdc, 0);
+	output_byte(fdc, 0x10 | (no_fifo & 0x20) | (fifo_depth & 0xf));
+	output_byte(fdc, 0);    /* pre-compensation from track 0 upwards */
 	return 1;
 }
 
@@ -1288,7 +1287,7 @@ static void fdc_specify(void)
 
 	if (fdc_state[current_fdc].need_configure &&
 	    fdc_state[current_fdc].version >= FDC_82072A) {
-		fdc_configure();
+		fdc_configure(current_fdc);
 		fdc_state[current_fdc].need_configure = 0;
 	}
 
@@ -4318,7 +4317,7 @@ static char __init get_fdc_version(void)
 		return FDC_UNKNOWN;
 	}
 
-	if (!fdc_configure()) {
+	if (!fdc_configure(current_fdc)) {
 		pr_info("FDC %d is an 82072\n", current_fdc);
 		return FDC_82072;	/* 82072 doesn't know CONFIGURE */
 	}
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 18/23] floppy: cleanup: make fdc_specify() not rely on current_{fdc,drive} anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (16 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 17/23] floppy: cleanup: make fdc_configure() " Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 19/23] floppy: cleanup: make check_wp() " Willy Tarreau
                   ` (6 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc and drive are passed in argument so that the function does
not use current_fdc nor current_drive anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 42 +++++++++++++++++++++---------------------
 1 file changed, 21 insertions(+), 21 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index c1338c4bb941..b929b60afe9b 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1273,7 +1273,7 @@ static int fdc_configure(int fdc)
  *
  * These values are rounded up to the next highest available delay time.
  */
-static void fdc_specify(void)
+static void fdc_specify(int fdc, int drive)
 {
 	unsigned char spec1;
 	unsigned char spec2;
@@ -1285,10 +1285,10 @@ static void fdc_specify(void)
 	int hlt_max_code = 0x7f;
 	int hut_max_code = 0xf;
 
-	if (fdc_state[current_fdc].need_configure &&
-	    fdc_state[current_fdc].version >= FDC_82072A) {
-		fdc_configure(current_fdc);
-		fdc_state[current_fdc].need_configure = 0;
+	if (fdc_state[fdc].need_configure &&
+	    fdc_state[fdc].version >= FDC_82072A) {
+		fdc_configure(fdc);
+		fdc_state[fdc].need_configure = 0;
 	}
 
 	switch (raw_cmd->rate & 0x03) {
@@ -1297,13 +1297,13 @@ static void fdc_specify(void)
 		break;
 	case 1:
 		dtr = 300;
-		if (fdc_state[current_fdc].version >= FDC_82078) {
+		if (fdc_state[fdc].version >= FDC_82078) {
 			/* chose the default rate table, not the one
 			 * where 1 = 2 Mbps */
-			output_byte(current_fdc, FD_DRIVESPEC);
-			if (need_more_output(current_fdc) == MORE_OUTPUT) {
-				output_byte(current_fdc, UNIT(current_drive));
-				output_byte(current_fdc, 0xc0);
+			output_byte(fdc, FD_DRIVESPEC);
+			if (need_more_output(fdc) == MORE_OUTPUT) {
+				output_byte(fdc, UNIT(drive));
+				output_byte(fdc, 0xc0);
 			}
 		}
 		break;
@@ -1312,14 +1312,14 @@ static void fdc_specify(void)
 		break;
 	}
 
-	if (fdc_state[current_fdc].version >= FDC_82072) {
+	if (fdc_state[fdc].version >= FDC_82072) {
 		scale_dtr = dtr;
 		hlt_max_code = 0x00;	/* 0==256msec*dtr0/dtr (not linear!) */
 		hut_max_code = 0x0;	/* 0==256msec*dtr0/dtr (not linear!) */
 	}
 
 	/* Convert step rate from microseconds to milliseconds and 4 bits */
-	srt = 16 - DIV_ROUND_UP(drive_params[current_drive].srt * scale_dtr / 1000,
+	srt = 16 - DIV_ROUND_UP(drive_params[drive].srt * scale_dtr / 1000,
 				NOMINAL_DTR);
 	if (slow_floppy)
 		srt = srt / 4;
@@ -1327,14 +1327,14 @@ static void fdc_specify(void)
 	SUPBOUND(srt, 0xf);
 	INFBOUND(srt, 0);
 
-	hlt = DIV_ROUND_UP(drive_params[current_drive].hlt * scale_dtr / 2,
+	hlt = DIV_ROUND_UP(drive_params[drive].hlt * scale_dtr / 2,
 			   NOMINAL_DTR);
 	if (hlt < 0x01)
 		hlt = 0x01;
 	else if (hlt > 0x7f)
 		hlt = hlt_max_code;
 
-	hut = DIV_ROUND_UP(drive_params[current_drive].hut * scale_dtr / 16,
+	hut = DIV_ROUND_UP(drive_params[drive].hut * scale_dtr / 16,
 			   NOMINAL_DTR);
 	if (hut < 0x1)
 		hut = 0x1;
@@ -1345,12 +1345,12 @@ static void fdc_specify(void)
 	spec2 = (hlt << 1) | (use_virtual_dma & 1);
 
 	/* If these parameters did not change, just return with success */
-	if (fdc_state[current_fdc].spec1 != spec1 ||
-	    fdc_state[current_fdc].spec2 != spec2) {
+	if (fdc_state[fdc].spec1 != spec1 ||
+	    fdc_state[fdc].spec2 != spec2) {
 		/* Go ahead and set spec1 and spec2 */
-		output_byte(current_fdc, FD_SPECIFY);
-		output_byte(current_fdc, fdc_state[current_fdc].spec1 = spec1);
-		output_byte(current_fdc, fdc_state[current_fdc].spec2 = spec2);
+		output_byte(fdc, FD_SPECIFY);
+		output_byte(fdc, fdc_state[fdc].spec1 = spec1);
+		output_byte(fdc, fdc_state[fdc].spec2 = spec2);
 	}
 }				/* fdc_specify */
 
@@ -1946,12 +1946,12 @@ static void floppy_ready(void)
 
 	if (raw_cmd->flags & (FD_RAW_NEED_SEEK | FD_RAW_NEED_DISK)) {
 		perpendicular_mode(current_fdc);
-		fdc_specify();	/* must be done here because of hut, hlt ... */
+		fdc_specify(current_fdc, current_drive); /* must be done here because of hut, hlt ... */
 		seek_floppy();
 	} else {
 		if ((raw_cmd->flags & FD_RAW_READ) ||
 		    (raw_cmd->flags & FD_RAW_WRITE))
-			fdc_specify();
+			fdc_specify(current_fdc, current_drive);
 		setup_rw_floppy();
 	}
 }
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 19/23] floppy: cleanup: make check_wp() not rely on current_{fdc,drive} anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (17 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 18/23] floppy: cleanup: make fdc_specify() not rely on current_{fdc,drive} anymore Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 20/23] floppy: cleanup: make next_valid_format() not rely on current_drive anymore Willy Tarreau
                   ` (5 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc and drive are passed in argument so that the function does
not use current_fdc nor current_drive anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 26 +++++++++++++-------------
 1 file changed, 13 insertions(+), 13 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index b929b60afe9b..b9a3a04c2636 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1561,29 +1561,29 @@ static void seek_interrupt(void)
 	floppy_ready();
 }
 
-static void check_wp(void)
+static void check_wp(int fdc, int drive)
 {
-	if (test_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags)) {
+	if (test_bit(FD_VERIFY_BIT, &drive_state[drive].flags)) {
 					/* check write protection */
-		output_byte(current_fdc, FD_GETSTATUS);
-		output_byte(current_fdc, UNIT(current_drive));
-		if (result(current_fdc) != 1) {
-			fdc_state[current_fdc].reset = 1;
+		output_byte(fdc, FD_GETSTATUS);
+		output_byte(fdc, UNIT(drive));
+		if (result(fdc) != 1) {
+			fdc_state[fdc].reset = 1;
 			return;
 		}
-		clear_bit(FD_VERIFY_BIT, &drive_state[current_drive].flags);
+		clear_bit(FD_VERIFY_BIT, &drive_state[drive].flags);
 		clear_bit(FD_NEED_TWADDLE_BIT,
-			  &drive_state[current_drive].flags);
-		debug_dcl(drive_params[current_drive].flags,
+			  &drive_state[drive].flags);
+		debug_dcl(drive_params[drive].flags,
 			  "checking whether disk is write protected\n");
-		debug_dcl(drive_params[current_drive].flags, "wp=%x\n",
+		debug_dcl(drive_params[drive].flags, "wp=%x\n",
 			  reply_buffer[ST3] & 0x40);
 		if (!(reply_buffer[ST3] & 0x40))
 			set_bit(FD_DISK_WRITABLE_BIT,
-				&drive_state[current_drive].flags);
+				&drive_state[drive].flags);
 		else
 			clear_bit(FD_DISK_WRITABLE_BIT,
-				  &drive_state[current_drive].flags);
+				  &drive_state[drive].flags);
 	}
 }
 
@@ -1627,7 +1627,7 @@ static void seek_floppy(void)
 			track = 1;
 		}
 	} else {
-		check_wp();
+		check_wp(current_fdc, current_drive);
 		if (raw_cmd->track != drive_state[current_drive].track &&
 		    (raw_cmd->flags & FD_RAW_NEED_SEEK))
 			track = raw_cmd->track;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 20/23] floppy: cleanup: make next_valid_format() not rely on current_drive anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (18 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 19/23] floppy: cleanup: make check_wp() " Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 21/23] floppy: cleanup: make get_fdc_version() not rely on current_fdc anymore Willy Tarreau
                   ` (4 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the drive is passed in argument so that the function does not
use current_drive anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 16 ++++++++--------
 1 file changed, 8 insertions(+), 8 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index b9a3a04c2636..f53810ba486d 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -2058,18 +2058,18 @@ static void success_and_wakeup(void)
  * ==========================
  */
 
-static int next_valid_format(void)
+static int next_valid_format(int drive)
 {
 	int probed_format;
 
-	probed_format = drive_state[current_drive].probed_format;
+	probed_format = drive_state[drive].probed_format;
 	while (1) {
-		if (probed_format >= 8 || !drive_params[current_drive].autodetect[probed_format]) {
-			drive_state[current_drive].probed_format = 0;
+		if (probed_format >= 8 || !drive_params[drive].autodetect[probed_format]) {
+			drive_state[drive].probed_format = 0;
 			return 1;
 		}
-		if (floppy_type[drive_params[current_drive].autodetect[probed_format]].sect) {
-			drive_state[current_drive].probed_format = probed_format;
+		if (floppy_type[drive_params[drive].autodetect[probed_format]].sect) {
+			drive_state[drive].probed_format = probed_format;
 			return 0;
 		}
 		probed_format++;
@@ -2082,7 +2082,7 @@ static void bad_flp_intr(void)
 
 	if (probing) {
 		drive_state[current_drive].probed_format++;
-		if (!next_valid_format())
+		if (!next_valid_format(current_drive))
 			return;
 	}
 	err_count = ++(*errors);
@@ -2884,7 +2884,7 @@ static void redo_fd_request(void)
 	if (!_floppy) {	/* Autodetection */
 		if (!probing) {
 			drive_state[current_drive].probed_format = 0;
-			if (next_valid_format()) {
+			if (next_valid_format(current_drive)) {
 				DPRINT("no autodetectable formats\n");
 				_floppy = NULL;
 				request_done(0);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 21/23] floppy: cleanup: make get_fdc_version() not rely on current_fdc anymore
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (19 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 20/23] floppy: cleanup: make next_valid_format() not rely on current_drive anymore Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31  9:40 ` [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions Willy Tarreau
                   ` (3 subsequent siblings)
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Now the fdc is passed in argument so that the function does not
use current_fdc anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 52 +++++++++++++++++++++---------------------
 1 file changed, 26 insertions(+), 26 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index f53810ba486d..8850baa3372a 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4297,79 +4297,79 @@ static const struct block_device_operations floppy_fops = {
 
 /* Determine the floppy disk controller type */
 /* This routine was written by David C. Niemi */
-static char __init get_fdc_version(void)
+static char __init get_fdc_version(int fdc)
 {
 	int r;
 
-	output_byte(current_fdc, FD_DUMPREGS);	/* 82072 and better know DUMPREGS */
-	if (fdc_state[current_fdc].reset)
+	output_byte(fdc, FD_DUMPREGS);	/* 82072 and better know DUMPREGS */
+	if (fdc_state[fdc].reset)
 		return FDC_NONE;
-	r = result(current_fdc);
+	r = result(fdc);
 	if (r <= 0x00)
 		return FDC_NONE;	/* No FDC present ??? */
 	if ((r == 1) && (reply_buffer[0] == 0x80)) {
-		pr_info("FDC %d is an 8272A\n", current_fdc);
+		pr_info("FDC %d is an 8272A\n", fdc);
 		return FDC_8272A;	/* 8272a/765 don't know DUMPREGS */
 	}
 	if (r != 10) {
 		pr_info("FDC %d init: DUMPREGS: unexpected return of %d bytes.\n",
-			current_fdc, r);
+			fdc, r);
 		return FDC_UNKNOWN;
 	}
 
-	if (!fdc_configure(current_fdc)) {
-		pr_info("FDC %d is an 82072\n", current_fdc);
+	if (!fdc_configure(fdc)) {
+		pr_info("FDC %d is an 82072\n", fdc);
 		return FDC_82072;	/* 82072 doesn't know CONFIGURE */
 	}
 
-	output_byte(current_fdc, FD_PERPENDICULAR);
-	if (need_more_output(current_fdc) == MORE_OUTPUT) {
-		output_byte(current_fdc, 0);
+	output_byte(fdc, FD_PERPENDICULAR);
+	if (need_more_output(fdc) == MORE_OUTPUT) {
+		output_byte(fdc, 0);
 	} else {
-		pr_info("FDC %d is an 82072A\n", current_fdc);
+		pr_info("FDC %d is an 82072A\n", fdc);
 		return FDC_82072A;	/* 82072A as found on Sparcs. */
 	}
 
-	output_byte(current_fdc, FD_UNLOCK);
-	r = result(current_fdc);
+	output_byte(fdc, FD_UNLOCK);
+	r = result(fdc);
 	if ((r == 1) && (reply_buffer[0] == 0x80)) {
-		pr_info("FDC %d is a pre-1991 82077\n", current_fdc);
+		pr_info("FDC %d is a pre-1991 82077\n", fdc);
 		return FDC_82077_ORIG;	/* Pre-1991 82077, doesn't know
 					 * LOCK/UNLOCK */
 	}
 	if ((r != 1) || (reply_buffer[0] != 0x00)) {
 		pr_info("FDC %d init: UNLOCK: unexpected return of %d bytes.\n",
-			current_fdc, r);
+			fdc, r);
 		return FDC_UNKNOWN;
 	}
-	output_byte(current_fdc, FD_PARTID);
-	r = result(current_fdc);
+	output_byte(fdc, FD_PARTID);
+	r = result(fdc);
 	if (r != 1) {
 		pr_info("FDC %d init: PARTID: unexpected return of %d bytes.\n",
-			current_fdc, r);
+			fdc, r);
 		return FDC_UNKNOWN;
 	}
 	if (reply_buffer[0] == 0x80) {
-		pr_info("FDC %d is a post-1991 82077\n", current_fdc);
+		pr_info("FDC %d is a post-1991 82077\n", fdc);
 		return FDC_82077;	/* Revised 82077AA passes all the tests */
 	}
 	switch (reply_buffer[0] >> 5) {
 	case 0x0:
 		/* Either a 82078-1 or a 82078SL running at 5Volt */
-		pr_info("FDC %d is an 82078.\n", current_fdc);
+		pr_info("FDC %d is an 82078.\n", fdc);
 		return FDC_82078;
 	case 0x1:
-		pr_info("FDC %d is a 44pin 82078\n", current_fdc);
+		pr_info("FDC %d is a 44pin 82078\n", fdc);
 		return FDC_82078;
 	case 0x2:
-		pr_info("FDC %d is a S82078B\n", current_fdc);
+		pr_info("FDC %d is a S82078B\n", fdc);
 		return FDC_S82078B;
 	case 0x3:
-		pr_info("FDC %d is a National Semiconductor PC87306\n", current_fdc);
+		pr_info("FDC %d is a National Semiconductor PC87306\n", fdc);
 		return FDC_87306;
 	default:
 		pr_info("FDC %d init: 82078 variant with unknown PARTID=%d.\n",
-			current_fdc, reply_buffer[0] >> 5);
+			fdc, reply_buffer[0] >> 5);
 		return FDC_82078_UNKN;
 	}
 }				/* get_fdc_version */
@@ -4711,7 +4711,7 @@ static int __init do_floppy_init(void)
 			continue;
 		}
 		/* Try to determine the floppy controller type */
-		fdc_state[current_fdc].version = get_fdc_version();
+		fdc_state[current_fdc].version = get_fdc_version(current_fdc);
 		if (fdc_state[current_fdc].version == FDC_NONE) {
 			/* free ioports reserved by floppy_grab_irq_and_dma() */
 			floppy_release_regions(current_fdc);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (20 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 21/23] floppy: cleanup: make get_fdc_version() not rely on current_fdc anymore Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-04-10  8:35   ` Denis Efremov
                     ` (2 more replies)
  2020-03-31  9:40 ` [PATCH 23/23] floppy: cleanup: add a few comments about expectations in certain functions Willy Tarreau
                   ` (2 subsequent siblings)
  24 siblings, 3 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

Both floppy_grab_irq_and_dma() and floppy_release_irq_and_dma() used to
iterate on the global variable while setting up or freeing resources.
Now that they exclusively rely on functions which take the fdc as an
argument, so let's not touch the global one anymore.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 39 ++++++++++++++++++++-------------------
 1 file changed, 20 insertions(+), 19 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 8850baa3372a..77bb9a5fcd33 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4854,6 +4854,8 @@ static void floppy_release_regions(int fdc)
 
 static int floppy_grab_irq_and_dma(void)
 {
+	int fdc;
+
 	if (atomic_inc_return(&usage_count) > 1)
 		return 0;
 
@@ -4881,24 +4883,24 @@ static int floppy_grab_irq_and_dma(void)
 		}
 	}
 
-	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
-		if (fdc_state[current_fdc].address != -1) {
-			if (floppy_request_regions(current_fdc))
+	for (fdc = 0; fdc < N_FDC; fdc++) {
+		if (fdc_state[fdc].address != -1) {
+			if (floppy_request_regions(fdc))
 				goto cleanup;
 		}
 	}
-	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
-		if (fdc_state[current_fdc].address != -1) {
-			reset_fdc_info(current_fdc, 1);
-			fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
+	for (fdc = 0; fdc < N_FDC; fdc++) {
+		if (fdc_state[fdc].address != -1) {
+			reset_fdc_info(fdc, 1);
+			fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
 		}
 	}
-	current_fdc = 0;
+
 	set_dor(0, ~0, 8);	/* avoid immediate interrupt */
 
-	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++)
-		if (fdc_state[current_fdc].address != -1)
-			fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
+	for (fdc = 0; fdc < N_FDC; fdc++)
+		if (fdc_state[fdc].address != -1)
+			fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
 	/*
 	 * The driver will try and free resources and relies on us
 	 * to know if they were allocated or not.
@@ -4909,15 +4911,16 @@ static int floppy_grab_irq_and_dma(void)
 cleanup:
 	fd_free_irq();
 	fd_free_dma();
-	while (--current_fdc >= 0)
-		floppy_release_regions(current_fdc);
+	while (--fdc >= 0)
+		floppy_release_regions(fdc);
+	current_fdc = 0;
 	atomic_dec(&usage_count);
 	return -1;
 }
 
 static void floppy_release_irq_and_dma(void)
 {
-	int old_fdc;
+	int fdc;
 #ifndef __sparc__
 	int drive;
 #endif
@@ -4958,11 +4961,9 @@ static void floppy_release_irq_and_dma(void)
 		pr_info("auxiliary floppy timer still active\n");
 	if (work_pending(&floppy_work))
 		pr_info("work still pending\n");
-	old_fdc = current_fdc;
-	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++)
-		if (fdc_state[current_fdc].address != -1)
-			floppy_release_regions(current_fdc);
-	current_fdc = old_fdc;
+	for (fdc = 0; fdc < N_FDC; fdc++)
+		if (fdc_state[fdc].address != -1)
+			floppy_release_regions(fdc);
 }
 
 #ifdef MODULE
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 23/23] floppy: cleanup: add a few comments about expectations in certain functions
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (21 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions Willy Tarreau
@ 2020-03-31  9:40 ` Willy Tarreau
  2020-03-31 10:10 ` [PATCH 00/23] Floppy driver cleanups Christoph Hellwig
  2020-04-13 22:46 ` Jens Axboe
  24 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31  9:40 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

The locking in the driver is far from being obvious, with unlocking
automatically happening at end of operations scheduled by interrupt,
especially for the error paths where one does not necessarily expect
that such an interrupt may be triggered. Let's add a few comments
about what to expect at certain places to avoid misdetecting bugs
which are not.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 77bb9a5fcd33..07218f8b17f9 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -1791,7 +1791,9 @@ static void reset_interrupt(void)
 
 /*
  * reset is done by pulling bit 2 of DOR low for a while (old FDCs),
- * or by setting the self clearing bit 7 of STATUS (newer FDCs)
+ * or by setting the self clearing bit 7 of STATUS (newer FDCs).
+ * This WILL trigger an interrupt, causing the handlers in the current
+ * cont's ->redo() to be called via reset_interrupt().
  */
 static void reset_fdc(void)
 {
@@ -2003,6 +2005,9 @@ static const struct cont_t intr_cont = {
 	.done		= (done_f)empty
 };
 
+/* schedules handler, waiting for completion. May be interrupted, will then
+ * return -EINTR, in which case the driver will automatically be unlocked.
+ */
 static int wait_til_done(void (*handler)(void), bool interruptible)
 {
 	int ret;
@@ -2842,6 +2847,9 @@ static int set_next_request(void)
 	return current_req != NULL;
 }
 
+/* Starts or continues processing request. Will automatically unlock the
+ * driver at end of request.
+ */
 static void redo_fd_request(void)
 {
 	int drive;
@@ -2916,6 +2924,7 @@ static const struct cont_t rw_cont = {
 	.done		= request_done
 };
 
+/* schedule the request and automatically unlock the driver on completion */
 static void process_fd_request(void)
 {
 	cont = &rw_cont;
@@ -3005,6 +3014,9 @@ static int user_reset_fdc(int drive, int arg, bool interruptible)
 	if (arg == FD_RESET_ALWAYS)
 		fdc_state[current_fdc].reset = 1;
 	if (fdc_state[current_fdc].reset) {
+		/* note: reset_fdc will take care of unlocking the driver
+		 * on completion.
+		 */
 		cont = &reset_cont;
 		ret = wait_til_done(reset_fdc, interruptible);
 		if (ret == -EINTR)
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (22 preceding siblings ...)
  2020-03-31  9:40 ` [PATCH 23/23] floppy: cleanup: add a few comments about expectations in certain functions Willy Tarreau
@ 2020-03-31 10:10 ` Christoph Hellwig
  2020-03-31 11:01   ` Willy Tarreau
  2020-04-13 22:46 ` Jens Axboe
  24 siblings, 1 reply; 42+ messages in thread
From: Christoph Hellwig @ 2020-03-31 10:10 UTC (permalink / raw)
  To: Willy Tarreau
  Cc: Denis Efremov, Jens Axboe, linux-block, linux-kernel,
	David S. Miller, Benjamin Herrenschmidt, Geert Uytterhoeven,
	Helge Deller, Ian Molton, Ivan Kokshaysky, Matt Turner,
	Richard Henderson, Russell King, Thomas Bogendoerfer, x86

Hi Willy,

given that you are actively maintaining the floppy driver now, any
chance I could trick you into proper highmem handling?  I've been trying
to phase out block layer bounce buffering, and any help from a competent
maintainer to move their drivers to properly support highmem by kmapping
for PIO/MMIO I/O would be very helpful.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-03-31 10:10 ` [PATCH 00/23] Floppy driver cleanups Christoph Hellwig
@ 2020-03-31 11:01   ` Willy Tarreau
  2020-03-31 15:28     ` Christoph Hellwig
  0 siblings, 1 reply; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31 11:01 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Denis Efremov, Jens Axboe, linux-block, linux-kernel,
	David S. Miller, Benjamin Herrenschmidt, Geert Uytterhoeven,
	Helge Deller, Ian Molton, Ivan Kokshaysky, Matt Turner,
	Richard Henderson, Russell King, Thomas Bogendoerfer, x86

Hi Christoph,

On Tue, Mar 31, 2020 at 03:10:19AM -0700, Christoph Hellwig wrote:
> Hi Willy,
> 
> given that you are actively maintaining the floppy driver now,

No no no I'm not! Denis is :-) Really, I mean I just proposed some help
to clean up this mess after being tricked into not believing a bug report
just because the code was too confusing.

> any
> chance I could trick you into proper highmem handling?  I've been trying
> to phase out block layer bounce buffering, and any help from a competent
> maintainer to move their drivers to properly support highmem by kmapping
> for PIO/MMIO I/O would be very helpful.

I'm not sure what this implies regarding this code, to be honest. It's
very tricky and implements sort of a state machine using function pointers
within its interrupt handler so you never know exactly what accesses what,
and quite a part of it remains obscure to me :-/  I can accept to help, I
can even run tests since I still have running hardware, but I'd at least
need some guidance. And probably Denis would know better than me there.
Also I doubt we'd get sufficient testing on less common archs. While I
do have sparc64/parisc/alpha available, I haven't booted a recent kernel
on any of them for a while (2.4 used to be the last ones), and I'm not
sure it's reasonable to go into such changes without proper testing.

What do you think ?

Willy

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-03-31 11:01   ` Willy Tarreau
@ 2020-03-31 15:28     ` Christoph Hellwig
  2020-03-31 15:49       ` Willy Tarreau
  0 siblings, 1 reply; 42+ messages in thread
From: Christoph Hellwig @ 2020-03-31 15:28 UTC (permalink / raw)
  To: Willy Tarreau
  Cc: Christoph Hellwig, Denis Efremov, Jens Axboe, linux-block,
	linux-kernel, David S. Miller, Benjamin Herrenschmidt,
	Geert Uytterhoeven, Helge Deller, Ian Molton, Ivan Kokshaysky,
	Matt Turner, Richard Henderson, Russell King,
	Thomas Bogendoerfer, x86

On Tue, Mar 31, 2020 at 01:01:36PM +0200, Willy Tarreau wrote:
> I'm not sure what this implies regarding this code, to be honest. It's
> very tricky and implements sort of a state machine using function pointers
> within its interrupt handler so you never know exactly what accesses what,
> and quite a part of it remains obscure to me :-/  I can accept to help, I
> can even run tests since I still have running hardware, but I'd at least
> need some guidance. And probably Denis would know better than me there.
> Also I doubt we'd get sufficient testing on less common archs. While I
> do have sparc64/parisc/alpha available, I haven't booted a recent kernel
> on any of them for a while (2.4 used to be the last ones), and I'm not
> sure it's reasonable to go into such changes without proper testing.

The basic change is that instead of using bio_data() or page_address
all pages coming from the block layer need to be properly kmap()ed.
I'll try to cook something up an will send it to Denis and you for
review and testing.  The code things about sparc64/parisc/alpha is
that they all don't have highmem, so these changes should be effective
no-ops for them.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-03-31 15:28     ` Christoph Hellwig
@ 2020-03-31 15:49       ` Willy Tarreau
  0 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-03-31 15:49 UTC (permalink / raw)
  To: Christoph Hellwig
  Cc: Denis Efremov, Jens Axboe, linux-block, linux-kernel,
	David S. Miller, Benjamin Herrenschmidt, Geert Uytterhoeven,
	Helge Deller, Ian Molton, Ivan Kokshaysky, Matt Turner,
	Richard Henderson, Russell King, Thomas Bogendoerfer, x86

On Tue, Mar 31, 2020 at 08:28:12AM -0700, Christoph Hellwig wrote:
> On Tue, Mar 31, 2020 at 01:01:36PM +0200, Willy Tarreau wrote:
> > I'm not sure what this implies regarding this code, to be honest. It's
> > very tricky and implements sort of a state machine using function pointers
> > within its interrupt handler so you never know exactly what accesses what,
> > and quite a part of it remains obscure to me :-/  I can accept to help, I
> > can even run tests since I still have running hardware, but I'd at least
> > need some guidance. And probably Denis would know better than me there.
> > Also I doubt we'd get sufficient testing on less common archs. While I
> > do have sparc64/parisc/alpha available, I haven't booted a recent kernel
> > on any of them for a while (2.4 used to be the last ones), and I'm not
> > sure it's reasonable to go into such changes without proper testing.
> 
> The basic change is that instead of using bio_data() or page_address
> all pages coming from the block layer need to be properly kmap()ed.
> I'll try to cook something up an will send it to Denis and you for
> review and testing.  The code things about sparc64/parisc/alpha is
> that they all don't have highmem, so these changes should be effective
> no-ops for them.

OK, thanks for the explanation!
Willy

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions
  2020-03-31  9:40 ` [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions Willy Tarreau
@ 2020-04-10  8:35   ` Denis Efremov
  2020-04-10  8:45     ` Willy Tarreau
  2020-04-10  9:30   ` [PATCH 24/23] floppy: cleanup: do not iterate on current_fdc in do_floppy_init() Willy Tarreau
  2020-04-10 10:19   ` [PATCH 25/23] floppy: make sure to reset all FDCs upon resume() Willy Tarreau
  2 siblings, 1 reply; 42+ messages in thread
From: Denis Efremov @ 2020-04-10  8:35 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: Jens Axboe, linux-block, linux-kernel

I see a couple of similar cycles in do_floppy_init:

for (i = 0; i < N_FDC; i++) {
        current_fdc = i;
        memset(&fdc_state[current_fdc], 0, sizeof(*fdc_state));
        fdc_state[current_fdc].dtr = -1;
        fdc_state[current_fdc].dor = 0x4;
...
}

for (i = 0; i < N_FDC; i++) {
        current_fdc = i;
        fdc_state[current_fdc].driver_version = FD_DRIVER_VERSION;
...
}

On 3/31/20 12:40 PM, Willy Tarreau wrote:
> Both floppy_grab_irq_and_dma() and floppy_release_irq_and_dma() used to
> iterate on the global variable while setting up or freeing resources.
> Now that they exclusively rely on functions which take the fdc as an
> argument, so let's not touch the global one anymore.
> 
> Signed-off-by: Willy Tarreau <w@1wt.eu>
> ---
>  drivers/block/floppy.c | 39 ++++++++++++++++++++-------------------
>  1 file changed, 20 insertions(+), 19 deletions(-)
> 
> diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
> index 8850baa3372a..77bb9a5fcd33 100644
> --- a/drivers/block/floppy.c
> +++ b/drivers/block/floppy.c
> @@ -4854,6 +4854,8 @@ static void floppy_release_regions(int fdc)
>  
>  static int floppy_grab_irq_and_dma(void)
>  {
> +	int fdc;
> +
>  	if (atomic_inc_return(&usage_count) > 1)
>  		return 0;
>  
> @@ -4881,24 +4883,24 @@ static int floppy_grab_irq_and_dma(void)
>  		}
>  	}
>  
> -	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
> -		if (fdc_state[current_fdc].address != -1) {
> -			if (floppy_request_regions(current_fdc))
> +	for (fdc = 0; fdc < N_FDC; fdc++) {
> +		if (fdc_state[fdc].address != -1) {
> +			if (floppy_request_regions(fdc))
>  				goto cleanup;
>  		}
>  	}
> -	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++) {
> -		if (fdc_state[current_fdc].address != -1) {
> -			reset_fdc_info(current_fdc, 1);
> -			fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
> +	for (fdc = 0; fdc < N_FDC; fdc++) {
> +		if (fdc_state[fdc].address != -1) {
> +			reset_fdc_info(fdc, 1);
> +			fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
>  		}
>  	}
> -	current_fdc = 0;
> +
>  	set_dor(0, ~0, 8);	/* avoid immediate interrupt */
>  
> -	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++)
> -		if (fdc_state[current_fdc].address != -1)
> -			fdc_outb(fdc_state[current_fdc].dor, current_fdc, FD_DOR);
> +	for (fdc = 0; fdc < N_FDC; fdc++)
> +		if (fdc_state[fdc].address != -1)
> +			fdc_outb(fdc_state[fdc].dor, fdc, FD_DOR);
>  	/*
>  	 * The driver will try and free resources and relies on us
>  	 * to know if they were allocated or not.
> @@ -4909,15 +4911,16 @@ static int floppy_grab_irq_and_dma(void)
>  cleanup:
>  	fd_free_irq();
>  	fd_free_dma();
> -	while (--current_fdc >= 0)
> -		floppy_release_regions(current_fdc);
> +	while (--fdc >= 0)
> +		floppy_release_regions(fdc);
> +	current_fdc = 0;
>  	atomic_dec(&usage_count);
>  	return -1;
>  }
>  
>  static void floppy_release_irq_and_dma(void)
>  {
> -	int old_fdc;
> +	int fdc;
>  #ifndef __sparc__
>  	int drive;
>  #endif
> @@ -4958,11 +4961,9 @@ static void floppy_release_irq_and_dma(void)
>  		pr_info("auxiliary floppy timer still active\n");
>  	if (work_pending(&floppy_work))
>  		pr_info("work still pending\n");
> -	old_fdc = current_fdc;
> -	for (current_fdc = 0; current_fdc < N_FDC; current_fdc++)
> -		if (fdc_state[current_fdc].address != -1)
> -			floppy_release_regions(current_fdc);
> -	current_fdc = old_fdc;
> +	for (fdc = 0; fdc < N_FDC; fdc++)
> +		if (fdc_state[fdc].address != -1)
> +			floppy_release_regions(fdc);
>  }
>  
>  #ifdef MODULE
> 

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions
  2020-04-10  8:35   ` Denis Efremov
@ 2020-04-10  8:45     ` Willy Tarreau
  2020-04-10  8:48       ` Denis Efremov
  0 siblings, 1 reply; 42+ messages in thread
From: Willy Tarreau @ 2020-04-10  8:45 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel

On Fri, Apr 10, 2020 at 11:35:51AM +0300, Denis Efremov wrote:
> I see a couple of similar cycles in do_floppy_init:
> 
> for (i = 0; i < N_FDC; i++) {
>         current_fdc = i;
>         memset(&fdc_state[current_fdc], 0, sizeof(*fdc_state));
>         fdc_state[current_fdc].dtr = -1;
>         fdc_state[current_fdc].dor = 0x4;
> ...
> }
> 
> for (i = 0; i < N_FDC; i++) {
>         current_fdc = i;
>         fdc_state[current_fdc].driver_version = FD_DRIVER_VERSION;
> ...
> }

Ah thanks, I missed these ones! Do you want me to respin this patch ?

Willy

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions
  2020-04-10  8:45     ` Willy Tarreau
@ 2020-04-10  8:48       ` Denis Efremov
  2020-04-10  9:32         ` Willy Tarreau
  0 siblings, 1 reply; 42+ messages in thread
From: Denis Efremov @ 2020-04-10  8:48 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: Jens Axboe, linux-block, linux-kernel

On 4/10/20 11:45 AM, Willy Tarreau wrote:
> Ah thanks, I missed these ones! Do you want me to respin this patch ?

I think you can resend only this patch, or send an additional one 24/23.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH 24/23] floppy: cleanup: do not iterate on current_fdc in do_floppy_init()
  2020-03-31  9:40 ` [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions Willy Tarreau
  2020-04-10  8:35   ` Denis Efremov
@ 2020-04-10  9:30   ` Willy Tarreau
  2020-04-10 10:19   ` [PATCH 25/23] floppy: make sure to reset all FDCs upon resume() Willy Tarreau
  2 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-04-10  9:30 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

There's no need to iterate on current_fdc in do_floppy_init() anymore,
in the first case it's only used as an array index to access fdc_state[],
so let's get rid of this confusing assignment. The second case is a bit
trickier because user_reset_fdc() needs to already know current_fdc when
called with drive==-1 due to this call chain:

    user_reset_fdc()
      lock_fdc()
        set_fdc()
           drive<0 ==> new_fdc = current_fdc

Note that current_drive is not used in this code part and may even not
match a unit belonging to current_fdc. Instead of passing -1 we can
simply pass the first drive of the FDC being initialized, which is even
cleaner as it will allow the function chain above to consistently assign
both variables.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 38 ++++++++++++++++++--------------------
 1 file changed, 18 insertions(+), 20 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 07218f8b17f9..8da7921659f1 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4657,16 +4657,15 @@ static int __init do_floppy_init(void)
 	config_types();
 
 	for (i = 0; i < N_FDC; i++) {
-		current_fdc = i;
-		memset(&fdc_state[current_fdc], 0, sizeof(*fdc_state));
-		fdc_state[current_fdc].dtr = -1;
-		fdc_state[current_fdc].dor = 0x4;
+		memset(&fdc_state[i], 0, sizeof(*fdc_state));
+		fdc_state[i].dtr = -1;
+		fdc_state[i].dor = 0x4;
 #if defined(__sparc__) || defined(__mc68000__)
 	/*sparcs/sun3x don't have a DOR reset which we can fall back on to */
 #ifdef __mc68000__
 		if (MACH_IS_SUN3X)
 #endif
-			fdc_state[current_fdc].version = FDC_82072A;
+			fdc_state[i].version = FDC_82072A;
 #endif
 	}
 
@@ -4708,30 +4707,29 @@ static int __init do_floppy_init(void)
 	msleep(10);
 
 	for (i = 0; i < N_FDC; i++) {
-		current_fdc = i;
-		fdc_state[current_fdc].driver_version = FD_DRIVER_VERSION;
+		fdc_state[i].driver_version = FD_DRIVER_VERSION;
 		for (unit = 0; unit < 4; unit++)
-			fdc_state[current_fdc].track[unit] = 0;
-		if (fdc_state[current_fdc].address == -1)
+			fdc_state[i].track[unit] = 0;
+		if (fdc_state[i].address == -1)
 			continue;
-		fdc_state[current_fdc].rawcmd = 2;
-		if (user_reset_fdc(-1, FD_RESET_ALWAYS, false)) {
+		fdc_state[i].rawcmd = 2;
+		if (user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false)) {
 			/* free ioports reserved by floppy_grab_irq_and_dma() */
-			floppy_release_regions(current_fdc);
-			fdc_state[current_fdc].address = -1;
-			fdc_state[current_fdc].version = FDC_NONE;
+			floppy_release_regions(i);
+			fdc_state[i].address = -1;
+			fdc_state[i].version = FDC_NONE;
 			continue;
 		}
 		/* Try to determine the floppy controller type */
-		fdc_state[current_fdc].version = get_fdc_version(current_fdc);
-		if (fdc_state[current_fdc].version == FDC_NONE) {
+		fdc_state[i].version = get_fdc_version(i);
+		if (fdc_state[i].version == FDC_NONE) {
 			/* free ioports reserved by floppy_grab_irq_and_dma() */
-			floppy_release_regions(current_fdc);
-			fdc_state[current_fdc].address = -1;
+			floppy_release_regions(i);
+			fdc_state[i].address = -1;
 			continue;
 		}
 		if (can_use_virtual_dma == 2 &&
-		    fdc_state[current_fdc].version < FDC_82072A)
+		    fdc_state[i].version < FDC_82072A)
 			can_use_virtual_dma = 0;
 
 		have_no_fdc = 0;
@@ -4739,7 +4737,7 @@ static int __init do_floppy_init(void)
 		 * properly, so force a reset for the standard FDC clones,
 		 * to avoid interrupt garbage.
 		 */
-		user_reset_fdc(-1, FD_RESET_ALWAYS, false);
+		user_reset_fdc(REVDRIVE(i, 0), FD_RESET_ALWAYS, false);
 	}
 	current_fdc = 0;
 	cancel_delayed_work(&fd_timeout);
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions
  2020-04-10  8:48       ` Denis Efremov
@ 2020-04-10  9:32         ` Willy Tarreau
  0 siblings, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-04-10  9:32 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel

On Fri, Apr 10, 2020 at 11:48:21AM +0300, Denis Efremov wrote:
> On 4/10/20 11:45 AM, Willy Tarreau wrote:
> > Ah thanks, I missed these ones! Do you want me to respin this patch ?
> 
> I think you can resend only this patch, or send an additional one 24/23.

OK, now done as 24/23. Apparently we can now get rid of the code dealing
with drive==-1 in lock_fdc()/set_fdc() etc. It's only used by
user_reset_fdc() and the last call place is in floppy_resume() which
even forgets to set the fdc number, so it only resets the current FDC,
as many times as there are FDCs in the system. I'm going to fix this
one and see make sure we drop this special case of -1.

Willy

^ permalink raw reply	[flat|nested] 42+ messages in thread

* [PATCH 25/23] floppy: make sure to reset all FDCs upon resume()
  2020-03-31  9:40 ` [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions Willy Tarreau
  2020-04-10  8:35   ` Denis Efremov
  2020-04-10  9:30   ` [PATCH 24/23] floppy: cleanup: do not iterate on current_fdc in do_floppy_init() Willy Tarreau
@ 2020-04-10 10:19   ` Willy Tarreau
  2020-04-10 10:19     ` [PATCH 26/23] floppy: cleanup: get rid of current_reqD in favor of current_drive Willy Tarreau
  2020-04-10 10:19     ` [PATCH 27/23] floppy: cleanup: make set_fdc() always set current_drive and current_fd Willy Tarreau
  2 siblings, 2 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-04-10 10:19 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

In floppy_resume() we don't properly reinitialize all FDCs, instead
we reinitialize the current FDC once per available FDC because value
-1 is passed to user_reset_fdc(). Let's simply save the current drive
and properly reinitialize each FDC.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 8da7921659f1..b102f55dfa5d 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -4545,11 +4545,13 @@ static void floppy_device_release(struct device *dev)
 static int floppy_resume(struct device *dev)
 {
 	int fdc;
+	int saved_drive;
 
+	saved_drive = current_drive;
 	for (fdc = 0; fdc < N_FDC; fdc++)
 		if (fdc_state[fdc].address != -1)
-			user_reset_fdc(-1, FD_RESET_ALWAYS, false);
-
+			user_reset_fdc(REVDRIVE(fdc, 0), FD_RESET_ALWAYS, false);
+	set_fdc(saved_drive);
 	return 0;
 }
 
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 26/23] floppy: cleanup: get rid of current_reqD in favor of current_drive
  2020-04-10 10:19   ` [PATCH 25/23] floppy: make sure to reset all FDCs upon resume() Willy Tarreau
@ 2020-04-10 10:19     ` Willy Tarreau
  2020-04-10 10:19     ` [PATCH 27/23] floppy: cleanup: make set_fdc() always set current_drive and current_fd Willy Tarreau
  1 sibling, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-04-10 10:19 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

This macro equals -1 and is used as an alternative for current_drive when
calling reschedule_timeout(), which in turn needs to remap it. This only
adds obfuscation, let's simply use current_drive.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 8 ++------
 1 file changed, 2 insertions(+), 6 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index b102f55dfa5d..20646d4c5437 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -668,16 +668,12 @@ static struct output_log {
 
 static int output_log_pos;
 
-#define current_reqD -1
 #define MAXTIMEOUT -2
 
 static void __reschedule_timeout(int drive, const char *message)
 {
 	unsigned long delay;
 
-	if (drive == current_reqD)
-		drive = current_drive;
-
 	if (drive < 0 || drive >= N_DRIVE) {
 		delay = 20UL * HZ;
 		drive = 0;
@@ -1960,7 +1956,7 @@ static void floppy_ready(void)
 
 static void floppy_start(void)
 {
-	reschedule_timeout(current_reqD, "floppy start");
+	reschedule_timeout(current_drive, "floppy start");
 
 	scandrives();
 	debug_dcl(drive_params[current_drive].flags,
@@ -2874,7 +2870,7 @@ static void redo_fd_request(void)
 	}
 	drive = (long)current_req->rq_disk->private_data;
 	set_fdc(drive);
-	reschedule_timeout(current_reqD, "redo fd request");
+	reschedule_timeout(current_drive, "redo fd request");
 
 	set_floppy(drive);
 	raw_cmd = &default_raw_cmd;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* [PATCH 27/23] floppy: cleanup: make set_fdc() always set current_drive and current_fd
  2020-04-10 10:19   ` [PATCH 25/23] floppy: make sure to reset all FDCs upon resume() Willy Tarreau
  2020-04-10 10:19     ` [PATCH 26/23] floppy: cleanup: get rid of current_reqD in favor of current_drive Willy Tarreau
@ 2020-04-10 10:19     ` Willy Tarreau
  1 sibling, 0 replies; 42+ messages in thread
From: Willy Tarreau @ 2020-04-10 10:19 UTC (permalink / raw)
  To: Denis Efremov; +Cc: Jens Axboe, linux-block, linux-kernel, Willy Tarreau

When called with a negative drive value, set_fdc() would stick to the
current fdc (which was assumed to reflect the current_drive's FDC). We
do not need this anymore as the last call place with a negative value
was just addressed. Let's make this function always set both current_fdc
and current_drive so that there's no more ambiguity. A few comments
stating this were added to a few non-obvious places.

Signed-off-by: Willy Tarreau <w@1wt.eu>
---
 drivers/block/floppy.c | 43 ++++++++++++++++++++++++++++--------------
 1 file changed, 29 insertions(+), 14 deletions(-)

diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c
index 20646d4c5437..2817170dd403 100644
--- a/drivers/block/floppy.c
+++ b/drivers/block/floppy.c
@@ -851,31 +851,42 @@ static void reset_fdc_info(int fdc, int mode)
 			drive_state[drive].track = NEED_2_RECAL;
 }
 
-/* selects the fdc and drive, and enables the fdc's input/dma. */
+/*
+ * selects the fdc and drive, and enables the fdc's input/dma.
+ * Both current_drive and current_fdc are changed to match the new drive.
+ */
 static void set_fdc(int drive)
 {
-	unsigned int new_fdc = current_fdc;
+	unsigned int fdc;
 
-	if (drive >= 0 && drive < N_DRIVE) {
-		new_fdc = FDC(drive);
-		current_drive = drive;
+	if (drive < 0 || drive >= N_DRIVE) {
+		pr_info("bad drive value %d\n", drive);
+		return;
 	}
-	if (new_fdc >= N_FDC) {
+
+	fdc = FDC(drive);
+	if (fdc >= N_FDC) {
 		pr_info("bad fdc value\n");
 		return;
 	}
-	current_fdc = new_fdc;
-	set_dor(current_fdc, ~0, 8);
+
+	set_dor(fdc, ~0, 8);
 #if N_FDC > 1
-	set_dor(1 - current_fdc, ~8, 0);
+	set_dor(1 - fdc, ~8, 0);
 #endif
-	if (fdc_state[current_fdc].rawcmd == 2)
-		reset_fdc_info(current_fdc, 1);
-	if (fdc_inb(current_fdc, FD_STATUS) != STATUS_READY)
-		fdc_state[current_fdc].reset = 1;
+	if (fdc_state[fdc].rawcmd == 2)
+		reset_fdc_info(fdc, 1);
+	if (fdc_inb(fdc, FD_STATUS) != STATUS_READY)
+		fdc_state[fdc].reset = 1;
+
+	current_drive = drive;
+	current_fdc = fdc;
 }
 
-/* locks the driver */
+/*
+ * locks the driver.
+ * Both current_drive and current_fdc are changed to match the new drive.
+ */
 static int lock_fdc(int drive)
 {
 	if (WARN(atomic_read(&usage_count) == 0,
@@ -3000,6 +3011,10 @@ static const struct cont_t reset_cont = {
 	.done		= generic_done
 };
 
+/*
+ * Resets the FDC connected to drive <drive>.
+ * Both current_drive and current_fdc are changed to match the new drive.
+ */
 static int user_reset_fdc(int drive, int arg, bool interruptible)
 {
 	int ret;
-- 
2.20.1


^ permalink raw reply related	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
                   ` (23 preceding siblings ...)
  2020-03-31 10:10 ` [PATCH 00/23] Floppy driver cleanups Christoph Hellwig
@ 2020-04-13 22:46 ` Jens Axboe
  2020-04-14  5:31   ` Willy Tarreau
  24 siblings, 1 reply; 42+ messages in thread
From: Jens Axboe @ 2020-04-13 22:46 UTC (permalink / raw)
  To: Willy Tarreau, Denis Efremov
  Cc: linux-block, linux-kernel, David S. Miller,
	Benjamin Herrenschmidt, Geert Uytterhoeven, Helge Deller,
	Ian Molton, Ivan Kokshaysky, Matt Turner, Richard Henderson,
	Russell King, Thomas Bogendoerfer, x86

On 3/31/20 3:40 AM, Willy Tarreau wrote:
> This series applies a second batch of cleanups to the floppy driver and
> its multiple arch-specific parts. Here the focus was on getting rid of
> hard-coded registers and flags values to switch to their symbolic
> definitions instead, and on making use of the global current_fdc variable
> much more explicit throughout the code to reduce the risk of accidental
> misuse as was the case with the most recently fixed bug.
> 
> Note that this code base is very old and the purpose is not to rewrite
> nor reorganize the driver at all, but instead to make certain things
> more obvious while keeping changes reviewable. It does not even address
> style issues that make checkpatch continue to complain a little bit (15
> total warnings which were already there and don't seem worth addressing
> without more careful testing). Some comments were added to document a
> few non-obvious assumptions though.
> 
> This series was rediffed against today's master (458ef2a25e0c) which
> contains the first series. The changes were tested on x86 with real
> hardware, and was build-tested on ARM.

I'll be happy to queue these up for 5.8 when ready. Would be handy
if you could resend a v2 patchset with the extra patches, makes my
life so much easier...

-- 
Jens Axboe


^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-04-13 22:46 ` Jens Axboe
@ 2020-04-14  5:31   ` Willy Tarreau
  2020-04-14 10:29     ` Denis Efremov
  0 siblings, 1 reply; 42+ messages in thread
From: Willy Tarreau @ 2020-04-14  5:31 UTC (permalink / raw)
  To: Jens Axboe
  Cc: Denis Efremov, linux-block, linux-kernel, David S. Miller,
	Benjamin Herrenschmidt, Geert Uytterhoeven, Helge Deller,
	Ian Molton, Ivan Kokshaysky, Matt Turner, Richard Henderson,
	Russell King, Thomas Bogendoerfer, x86

Hi Jens,

On Mon, Apr 13, 2020 at 04:46:41PM -0600, Jens Axboe wrote:
> I'll be happy to queue these up for 5.8 when ready. Would be handy
> if you could resend a v2 patchset with the extra patches, makes my
> life so much easier...

Sure, will do once Denis confirms he's done with the review and is
OK with the series.

Thanks!
Willy

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 07/23] floppy: use symbolic register names in the sparc64 port
  2020-03-31  9:40 ` [PATCH 07/23] floppy: use symbolic register names in the sparc64 port Willy Tarreau
@ 2020-04-14  9:20   ` Denis Efremov
  0 siblings, 0 replies; 42+ messages in thread
From: Denis Efremov @ 2020-04-14  9:20 UTC (permalink / raw)
  To: Willy Tarreau; +Cc: Jens Axboe, linux-block, linux-kernel, David S. Miller

Hi,

On 3/31/20 12:40 PM, Willy Tarreau wrote:
-		printk("floppy: Asked to read unknown port %lx\n", port);
> +		printk("floppy: Asked to read unknown port %lx\n", reg);

> -		printk("floppy: Asked to write to unknown port %lx\n", port);
> +		printk("floppy: Asked to write to unknown port %lx\n", reg);

sparc64 showed a couple of warnings in printks (I will send fixes)
./arch/sparc/include/asm/floppy_64.h: In function ‘sun_82077_fd_inb’:
./arch/sparc/include/asm/floppy_64.h:106:48: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘unsigned int’ [-Wformat=]
  106 |   printk("floppy: Asked to read unknown port %lx\n", reg);
      |                                              ~~^     ~~~
      |                                                |     |
      |                                                |     unsigned int
      |                                                long unsigned int
      |                                              %x
./arch/sparc/include/asm/floppy_64.h: In function ‘sun_82077_fd_outb’:
./arch/sparc/include/asm/floppy_64.h:125:52: warning: format ‘%lx’ expects argument of type ‘long unsigned int’, but argument 2 has type ‘unsigned int’ [-Wformat=]
  125 |   printk("floppy: Asked to write to unknown port %lx\n", reg);
      |                                                  ~~^     ~~~
      |                                                    |     |
      |                                                    |     unsigned int
      |                                                    long unsigned int
      |                                                  %x

A couple of new warnings.

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-04-14  5:31   ` Willy Tarreau
@ 2020-04-14 10:29     ` Denis Efremov
  2020-04-14 16:12       ` Willy Tarreau
  0 siblings, 1 reply; 42+ messages in thread
From: Denis Efremov @ 2020-04-14 10:29 UTC (permalink / raw)
  To: Willy Tarreau, Jens Axboe
  Cc: linux-block, linux-kernel, David S. Miller,
	Benjamin Herrenschmidt, Geert Uytterhoeven, Helge Deller,
	Ian Molton, Ivan Kokshaysky, Matt Turner, Richard Henderson,
	Russell King, Thomas Bogendoerfer, x86

Hi,

On 4/14/20 8:31 AM, Willy Tarreau wrote:
> Hi Jens,
> 
> On Mon, Apr 13, 2020 at 04:46:41PM -0600, Jens Axboe wrote:
>> I'll be happy to queue these up for 5.8 when ready. Would be handy
>> if you could resend a v2 patchset with the extra patches, makes my
>> life so much easier...
> 
> Sure, will do once Denis confirms he's done with the review and is
> OK with the series.
> 
> Thanks!
> Willy
>
I can see no new issues, respecting that the initial version
was sent privately and additional [24-27] fixups.

[+] eye checked the changes
[+] compile tested the patches on x86, arm, powerpc, sparc64,
    m68k (forced ARCH_MAY_HAVE_PC_FDC by removing BROKEN)
    sparc64 showed a couple of warnings in printks
I was expecting that some of the arch maintainers will at least
ack the patches.
[+] tested on real hardware for x86
[+] local syzkaller fuzzing reveals no new issues

Willy, could you please resend the patchset with printks fix for sparc64?
Or if Jens don't mind and you don't want to send 30 patches again you can
resend only sparc64 patch and I will reapply it and send everything to Jens
with merge request. I applied your patches a couple of days ago here
https://github.com/evdenis/linux-floppy/ to cleanups branch.

I also faced minor ubsan warning in setup_rw_floppy that is not related
to these patches. It's false alarm of cross-boundary access of cmd,
reply_count, reply in floppy_raw_cmd. This access is intentional.
I will send a patch on top of your patchset.

Thanks,
Denis 

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-04-14 10:29     ` Denis Efremov
@ 2020-04-14 16:12       ` Willy Tarreau
  2020-04-21 13:15         ` Denis Efremov
  0 siblings, 1 reply; 42+ messages in thread
From: Willy Tarreau @ 2020-04-14 16:12 UTC (permalink / raw)
  To: Denis Efremov
  Cc: Jens Axboe, linux-block, linux-kernel, David S. Miller,
	Benjamin Herrenschmidt, Geert Uytterhoeven, Helge Deller,
	Ian Molton, Ivan Kokshaysky, Matt Turner, Richard Henderson,
	Russell King, Thomas Bogendoerfer, x86

Hi Denis,

On Tue, Apr 14, 2020 at 01:29:02PM +0300, Denis Efremov wrote:
> I was expecting that some of the arch maintainers will at least
> ack the patches.

TBH, floppy is probably very low on any arch maintainer's priority list.

> Willy, could you please resend the patchset with printks fix for sparc64?
> Or if Jens don't mind and you don't want to send 30 patches again you can
> resend only sparc64 patch and I will reapply it and send everything to Jens
> with merge request. I applied your patches a couple of days ago here
> https://github.com/evdenis/linux-floppy/ to cleanups branch.

Then I'll redo this one only and directly send it to you as I really hate
spamming innocents with patches. This will also help Jens in that you've
already recomposed the whole series for him.

> I also faced minor ubsan warning in setup_rw_floppy that is not related
> to these patches. It's false alarm of cross-boundary access of cmd,
> reply_count, reply in floppy_raw_cmd. This access is intentional.
> I will send a patch on top of your patchset.

OK, cool!

Thanks!
Willy

^ permalink raw reply	[flat|nested] 42+ messages in thread

* Re: [PATCH 00/23] Floppy driver cleanups
  2020-04-14 16:12       ` Willy Tarreau
@ 2020-04-21 13:15         ` Denis Efremov
  0 siblings, 0 replies; 42+ messages in thread
From: Denis Efremov @ 2020-04-21 13:15 UTC (permalink / raw)
  To: Willy Tarreau
  Cc: Jens Axboe, linux-block, linux-kernel, David S. Miller,
	Benjamin Herrenschmidt, Geert Uytterhoeven, Helge Deller,
	Ian Molton, Ivan Kokshaysky, Matt Turner, Richard Henderson,
	Russell King, Thomas Bogendoerfer, x86

Hi,

On 4/14/20 7:12 PM, Willy Tarreau wrote> 
> Then I'll redo this one only and directly send it to you as I really hate
> spamming innocents with patches. This will also help Jens in that you've
> already recomposed the whole series for him.
>

Applied https://github.com/evdenis/linux-floppy/tree/cleanups

With your warnings fix for sparc64 here:
https://github.com/evdenis/linux-floppy/commit/9c51b73efc71afd52c4eb00d93fc09d3c95010c8

I've sent small fix on top of your patches to linux-block. If everything is ok
with my part I will send all patches to Jens for 5.8 in a week.

Thanks,
Denis

^ permalink raw reply	[flat|nested] 42+ messages in thread

end of thread, other threads:[~2020-04-21 13:15 UTC | newest]

Thread overview: 42+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-31  9:40 [PATCH 00/23] Floppy driver cleanups Willy Tarreau
2020-03-31  9:40 ` [PATCH 01/23] floppy: split the base port from the register in I/O accesses Willy Tarreau
2020-03-31  9:40 ` [PATCH 02/23] floppy: add references to 82077's extra registers Willy Tarreau
2020-03-31  9:40 ` [PATCH 03/23] floppy: use symbolic register names in the m68k port Willy Tarreau
2020-03-31  9:40 ` [PATCH 04/23] floppy: use symbolic register names in the parisc port Willy Tarreau
2020-03-31  9:40 ` [PATCH 05/23] floppy: use symbolic register names in the powerpc port Willy Tarreau
2020-03-31  9:40 ` [PATCH 06/23] floppy: use symbolic register names in the sparc32 port Willy Tarreau
2020-03-31  9:40 ` [PATCH 07/23] floppy: use symbolic register names in the sparc64 port Willy Tarreau
2020-04-14  9:20   ` Denis Efremov
2020-03-31  9:40 ` [PATCH 08/23] floppy: use symbolic register names in the x86 port Willy Tarreau
2020-03-31  9:40 ` [PATCH 09/23] floppy: cleanup: make twaddle() not rely on current_{fdc,drive} anymore Willy Tarreau
2020-03-31  9:40 ` [PATCH 10/23] floppy: cleanup: make reset_fdc_info() not rely on current_fdc anymore Willy Tarreau
2020-03-31  9:40 ` [PATCH 11/23] floppy: cleanup: make show_floppy() " Willy Tarreau
2020-03-31  9:40 ` [PATCH 12/23] floppy: cleanup: make wait_til_ready() " Willy Tarreau
2020-03-31  9:40 ` [PATCH 13/23] floppy: cleanup: make output_byte() " Willy Tarreau
2020-03-31  9:40 ` [PATCH 14/23] floppy: cleanup: make result() " Willy Tarreau
2020-03-31  9:40 ` [PATCH 15/23] floppy: cleanup: make need_more_output() " Willy Tarreau
2020-03-31  9:40 ` [PATCH 16/23] floppy: cleanup: make perpendicular_mode() " Willy Tarreau
2020-03-31  9:40 ` [PATCH 17/23] floppy: cleanup: make fdc_configure() " Willy Tarreau
2020-03-31  9:40 ` [PATCH 18/23] floppy: cleanup: make fdc_specify() not rely on current_{fdc,drive} anymore Willy Tarreau
2020-03-31  9:40 ` [PATCH 19/23] floppy: cleanup: make check_wp() " Willy Tarreau
2020-03-31  9:40 ` [PATCH 20/23] floppy: cleanup: make next_valid_format() not rely on current_drive anymore Willy Tarreau
2020-03-31  9:40 ` [PATCH 21/23] floppy: cleanup: make get_fdc_version() not rely on current_fdc anymore Willy Tarreau
2020-03-31  9:40 ` [PATCH 22/23] floppy: cleanup: do not iterate on current_fdc in DMA grab/release functions Willy Tarreau
2020-04-10  8:35   ` Denis Efremov
2020-04-10  8:45     ` Willy Tarreau
2020-04-10  8:48       ` Denis Efremov
2020-04-10  9:32         ` Willy Tarreau
2020-04-10  9:30   ` [PATCH 24/23] floppy: cleanup: do not iterate on current_fdc in do_floppy_init() Willy Tarreau
2020-04-10 10:19   ` [PATCH 25/23] floppy: make sure to reset all FDCs upon resume() Willy Tarreau
2020-04-10 10:19     ` [PATCH 26/23] floppy: cleanup: get rid of current_reqD in favor of current_drive Willy Tarreau
2020-04-10 10:19     ` [PATCH 27/23] floppy: cleanup: make set_fdc() always set current_drive and current_fd Willy Tarreau
2020-03-31  9:40 ` [PATCH 23/23] floppy: cleanup: add a few comments about expectations in certain functions Willy Tarreau
2020-03-31 10:10 ` [PATCH 00/23] Floppy driver cleanups Christoph Hellwig
2020-03-31 11:01   ` Willy Tarreau
2020-03-31 15:28     ` Christoph Hellwig
2020-03-31 15:49       ` Willy Tarreau
2020-04-13 22:46 ` Jens Axboe
2020-04-14  5:31   ` Willy Tarreau
2020-04-14 10:29     ` Denis Efremov
2020-04-14 16:12       ` Willy Tarreau
2020-04-21 13:15         ` Denis Efremov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).