linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH 1/4] g_NCR5380: Check for chip presence before calling NCR5380_init()
  2016-12-05  6:07 [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Finn Thain
@ 2016-12-05  6:07 ` Finn Thain
  2016-12-05  6:07 ` [PATCH 4/4] g_NCR5380: Autoprobe board IRQ by default Finn Thain
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Finn Thain @ 2016-12-05  6:07 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Ondrej Zary
  Cc: Michael Schmitz, linux-scsi, linux-kernel

From: Ondrej Zary <linux@rainbow-software.org>

Write and read back mode register to check that a chip is really there.
If no card is present, reads result in 0xff.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
 drivers/scsi/g_NCR5380.c | 7 +++++++
 1 file changed, 7 insertions(+)

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index de5147a..76e3745 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -248,6 +248,13 @@ static int generic_NCR5380_init_one(struct scsi_host_template *tpnt,
 		}
 	}
 
+	/* Check for vacant slot */
+	NCR5380_write(MODE_REG, 0);
+	if (NCR5380_read(MODE_REG) != 0) {
+		ret = -ENODEV;
+		goto out_unregister;
+	}
+
 	ret = NCR5380_init(instance, flags | FLAG_LATE_DMA_SETUP);
 	if (ret)
 		goto out_unregister;
-- 
2.7.3

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

* [PATCH 0/4] g_NCR5380: Bug fix and some enhancements
@ 2016-12-05  6:07 Finn Thain
  2016-12-05  6:07 ` [PATCH 1/4] g_NCR5380: Check for chip presence before calling NCR5380_init() Finn Thain
                   ` (5 more replies)
  0 siblings, 6 replies; 8+ messages in thread
From: Finn Thain @ 2016-12-05  6:07 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Ondrej Zary
  Cc: Michael Schmitz, linux-scsi, linux-kernel

This patch series is based on the one submitted recently by Ondrej Zary.

This version has a different irq probing fix for HP C2502 boards and
a more comprehensive patch to change the default irq parameter.

It needs testing on actual ISA hardware.


Finn Thain (4):
  g_NCR5380: Check for chip presence before calling NCR5380_init()
  g_NCR5380: Use probe_irq_*() for IRQ probing
  g_NCR5380: Fix automatic IRQ on HP C2502 cards
  g_NCR5380: Autoprobe board IRQ by default

 Documentation/scsi/g_NCR5380.txt |  46 ++++++------
 drivers/scsi/NCR5380.c           |  77 +-------------------
 drivers/scsi/NCR5380.h           |  11 ---
 drivers/scsi/g_NCR5380.c         | 153 +++++++++++++++++++++++++++++++++------
 drivers/scsi/g_NCR5380.h         |   2 +
 5 files changed, 156 insertions(+), 133 deletions(-)

-- 
2.7.3

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

* [PATCH 2/4] g_NCR5380: Use probe_irq_*() for IRQ probing
  2016-12-05  6:07 [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Finn Thain
                   ` (2 preceding siblings ...)
  2016-12-05  6:07 ` [PATCH 3/4] g_NCR5380: Fix automatic IRQ on HP C2502 cards Finn Thain
@ 2016-12-05  6:07 ` Finn Thain
  2016-12-08 18:45 ` [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Ondrej Zary
  2016-12-08 21:59 ` Martin K. Petersen
  5 siblings, 0 replies; 8+ messages in thread
From: Finn Thain @ 2016-12-05  6:07 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Ondrej Zary
  Cc: Michael Schmitz, linux-scsi, linux-kernel

From: Ondrej Zary <linux@rainbow-software.org>

Use standard probe_irq_on() and probe_irq_off() functions instead of
own implementation.
This prevents warning messages like this in the kernel log:
genirq: Flags mismatch irq 1. 00000000 (NCR-probe) vs. 00000080 (i8042)

Move the IRQ trigger code from NCR5380 to g_NCR5380 where it is used.

Also clear interrupt flag before and after the probe.

Signed-off-by: Ondrej Zary <linux@rainbow-software.org>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
 drivers/scsi/NCR5380.c   | 77 +-----------------------------------------------
 drivers/scsi/NCR5380.h   | 11 -------
 drivers/scsi/g_NCR5380.c | 52 +++++++++++++++++++++++++++++++-
 drivers/scsi/g_NCR5380.h |  2 ++
 4 files changed, 54 insertions(+), 88 deletions(-)

diff --git a/drivers/scsi/NCR5380.c b/drivers/scsi/NCR5380.c
index d849ffa..4f5ca79 100644
--- a/drivers/scsi/NCR5380.c
+++ b/drivers/scsi/NCR5380.c
@@ -97,9 +97,6 @@
  * and macros and include this file in your driver.
  *
  * These macros control options :
- * AUTOPROBE_IRQ - if defined, the NCR5380_probe_irq() function will be
- * defined.
- *
  * AUTOSENSE - if defined, REQUEST SENSE will be performed automatically
  * for commands that return with a CHECK CONDITION status.
  *
@@ -127,9 +124,7 @@
  * NCR5380_dma_residual   - residual byte count
  *
  * The generic driver is initialized by calling NCR5380_init(instance),
- * after setting the appropriate host specific fields and ID.  If the
- * driver wishes to autoprobe for an IRQ line, the NCR5380_probe_irq(instance,
- * possible) function may be used.
+ * after setting the appropriate host specific fields and ID.
  */
 
 #ifndef NCR5380_io_delay
@@ -351,76 +346,6 @@ static void NCR5380_print_phase(struct Scsi_Host *instance)
 }
 #endif
 
-
-static int probe_irq;
-
-/**
- * probe_intr	-	helper for IRQ autoprobe
- * @irq: interrupt number
- * @dev_id: unused
- * @regs: unused
- *
- * Set a flag to indicate the IRQ in question was received. This is
- * used by the IRQ probe code.
- */
-
-static irqreturn_t probe_intr(int irq, void *dev_id)
-{
-	probe_irq = irq;
-	return IRQ_HANDLED;
-}
-
-/**
- * NCR5380_probe_irq	-	find the IRQ of an NCR5380
- * @instance: NCR5380 controller
- * @possible: bitmask of ISA IRQ lines
- *
- * Autoprobe for the IRQ line used by the NCR5380 by triggering an IRQ
- * and then looking to see what interrupt actually turned up.
- */
-
-static int __maybe_unused NCR5380_probe_irq(struct Scsi_Host *instance,
-						int possible)
-{
-	struct NCR5380_hostdata *hostdata = shost_priv(instance);
-	unsigned long timeout;
-	int trying_irqs, i, mask;
-
-	for (trying_irqs = 0, i = 1, mask = 2; i < 16; ++i, mask <<= 1)
-		if ((mask & possible) && (request_irq(i, &probe_intr, 0, "NCR-probe", NULL) == 0))
-			trying_irqs |= mask;
-
-	timeout = jiffies + msecs_to_jiffies(250);
-	probe_irq = NO_IRQ;
-
-	/*
-	 * A interrupt is triggered whenever BSY = false, SEL = true
-	 * and a bit set in the SELECT_ENABLE_REG is asserted on the
-	 * SCSI bus.
-	 *
-	 * Note that the bus is only driven when the phase control signals
-	 * (I/O, C/D, and MSG) match those in the TCR, so we must reset that
-	 * to zero.
-	 */
-
-	NCR5380_write(TARGET_COMMAND_REG, 0);
-	NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
-	NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
-	NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE | ICR_ASSERT_DATA | ICR_ASSERT_SEL);
-
-	while (probe_irq == NO_IRQ && time_before(jiffies, timeout))
-		schedule_timeout_uninterruptible(1);
-
-	NCR5380_write(SELECT_ENABLE_REG, 0);
-	NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
-
-	for (i = 1, mask = 2; i < 16; ++i, mask <<= 1)
-		if (trying_irqs & mask)
-			free_irq(i, NULL);
-
-	return probe_irq;
-}
-
 /**
  * NCR58380_info - report driver and host information
  * @instance: relevant scsi host instance
diff --git a/drivers/scsi/NCR5380.h b/drivers/scsi/NCR5380.h
index 3c6ce54..51a3567 100644
--- a/drivers/scsi/NCR5380.h
+++ b/drivers/scsi/NCR5380.h
@@ -199,16 +199,6 @@
 
 #define PHASE_SR_TO_TCR(phase) ((phase) >> 2)
 
-/*
- * These are "special" values for the irq and dma_channel fields of the 
- * Scsi_Host structure
- */
-
-#define DMA_NONE	255
-#define IRQ_AUTO	254
-#define DMA_AUTO	254
-#define PORT_AUTO	0xffff	/* autoprobe io port for 53c400a */
-
 #ifndef NO_IRQ
 #define NO_IRQ		0
 #endif
@@ -290,7 +280,6 @@ static void NCR5380_print(struct Scsi_Host *instance);
 #define NCR5380_dprint_phase(flg, arg) do {} while (0)
 #endif
 
-static int NCR5380_probe_irq(struct Scsi_Host *instance, int possible);
 static int NCR5380_init(struct Scsi_Host *instance, int flags);
 static int NCR5380_maybe_reset_bus(struct Scsi_Host *);
 static void NCR5380_exit(struct Scsi_Host *instance);
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 76e3745..6d245a7 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -67,6 +67,56 @@ MODULE_PARM_DESC(card, "card type (0=NCR5380, 1=NCR53C400, 2=NCR53C400A, 3=DTC31
 MODULE_ALIAS("g_NCR5380_mmio");
 MODULE_LICENSE("GPL");
 
+static void g_NCR5380_trigger_irq(struct Scsi_Host *instance)
+{
+	struct NCR5380_hostdata *hostdata = shost_priv(instance);
+
+	/*
+	 * An interrupt is triggered whenever BSY = false, SEL = true
+	 * and a bit set in the SELECT_ENABLE_REG is asserted on the
+	 * SCSI bus.
+	 *
+	 * Note that the bus is only driven when the phase control signals
+	 * (I/O, C/D, and MSG) match those in the TCR.
+	 */
+	NCR5380_write(TARGET_COMMAND_REG,
+	              PHASE_SR_TO_TCR(NCR5380_read(STATUS_REG) & PHASE_MASK));
+	NCR5380_write(SELECT_ENABLE_REG, hostdata->id_mask);
+	NCR5380_write(OUTPUT_DATA_REG, hostdata->id_mask);
+	NCR5380_write(INITIATOR_COMMAND_REG,
+	              ICR_BASE | ICR_ASSERT_DATA | ICR_ASSERT_SEL);
+
+	msleep(1);
+
+	NCR5380_write(INITIATOR_COMMAND_REG, ICR_BASE);
+	NCR5380_write(SELECT_ENABLE_REG, 0);
+	NCR5380_write(TARGET_COMMAND_REG, 0);
+}
+
+/**
+ * g_NCR5380_probe_irq - find the IRQ of a NCR5380 or equivalent
+ * @instance: SCSI host instance
+ *
+ * Autoprobe for the IRQ line used by the card by triggering an IRQ
+ * and then looking to see what interrupt actually turned up.
+ */
+
+static int g_NCR5380_probe_irq(struct Scsi_Host *instance)
+{
+	struct NCR5380_hostdata *hostdata = shost_priv(instance);
+	int irq_mask, irq;
+
+	NCR5380_read(RESET_PARITY_INTERRUPT_REG);
+	irq_mask = probe_irq_on();
+	g_NCR5380_trigger_irq(instance);
+	irq = probe_irq_off(irq_mask);
+	NCR5380_read(RESET_PARITY_INTERRUPT_REG);
+
+	if (irq <= 0)
+		return NO_IRQ;
+	return irq;
+}
+
 /*
  * Configure I/O address of 53C400A or DTC436 by writing magic numbers
  * to ports 0x779 and 0x379.
@@ -272,7 +322,7 @@ static int generic_NCR5380_init_one(struct scsi_host_template *tpnt,
 	if (irq != IRQ_AUTO)
 		instance->irq = irq;
 	else
-		instance->irq = NCR5380_probe_irq(instance, 0xffff);
+		instance->irq = g_NCR5380_probe_irq(instance);
 
 	/* Compatibility with documented NCR5380 kernel parameters */
 	if (instance->irq == 255)
diff --git a/drivers/scsi/g_NCR5380.h b/drivers/scsi/g_NCR5380.h
index 3ce5b65..81b22d9 100644
--- a/drivers/scsi/g_NCR5380.h
+++ b/drivers/scsi/g_NCR5380.h
@@ -51,4 +51,6 @@
 #define BOARD_DTC3181E	3
 #define BOARD_HP_C2502	4
 
+#define IRQ_AUTO	254
+
 #endif /* GENERIC_NCR5380_H */
-- 
2.7.3

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

* [PATCH 4/4] g_NCR5380: Autoprobe board IRQ by default
  2016-12-05  6:07 [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Finn Thain
  2016-12-05  6:07 ` [PATCH 1/4] g_NCR5380: Check for chip presence before calling NCR5380_init() Finn Thain
@ 2016-12-05  6:07 ` Finn Thain
  2016-12-05  6:07 ` [PATCH 3/4] g_NCR5380: Fix automatic IRQ on HP C2502 cards Finn Thain
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Finn Thain @ 2016-12-05  6:07 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Ondrej Zary,
	Jonathan Corbet, linux-doc
  Cc: Michael Schmitz, linux-scsi, linux-kernel

Automatically probe the board irq when no irq parameter is provided,
to simulate PnP. The old default behaviour was to disable the irq.

Update driver documentation accordingly and add some printk messages
to make this behaviour visible.

Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
 Documentation/scsi/g_NCR5380.txt | 46 ++++++++++++++++++++--------------------
 drivers/scsi/g_NCR5380.c         | 30 +++++++++++++++-----------
 2 files changed, 41 insertions(+), 35 deletions(-)

diff --git a/Documentation/scsi/g_NCR5380.txt b/Documentation/scsi/g_NCR5380.txt
index e2c1879..37b1967 100644
--- a/Documentation/scsi/g_NCR5380.txt
+++ b/Documentation/scsi/g_NCR5380.txt
@@ -6,17 +6,15 @@ NCR53c400 extensions (c) 1994,1995,1996 Kevin Lentin
 This file documents the NCR53c400 extensions by Kevin Lentin and some
 enhancements to the NCR5380 core.
 
-This driver supports both NCR5380 and NCR53c400 cards in port or memory
-mapped modes. Currently this driver can only support one of those mapping
-modes at a time but it does support both of these chips at the same time.
-The next release of this driver will support port & memory mapped cards at
-the same time. It should be able to handle multiple different cards in the
-same machine.
+This driver supports NCR5380 and NCR53c400 and compatible cards in port or
+memory mapped modes.
 
-The drivers/scsi/Makefile has an override in it for the most common
-NCR53c400 card, the Trantor T130B in its default configuration:
-	Port: 0x350
-	IRQ : 5
+Use of an interrupt is recommended, if supported by the board, as this will
+allow targets to disconnect and thereby improve SCSI bus utilization.
+
+If the irq parameter is 254 or is omitted entirely, the driver will probe
+for the correct IRQ line automatically. If the irq parameter is 0 or 255
+then no IRQ will be used.
 
 The NCR53c400 does not support DMA but it does have Pseudo-DMA which is
 supported by the driver.
@@ -47,22 +45,24 @@ These old-style parameters can support only one card:
   dtc_3181e=1  to set up for a Domex Technology Corp 3181E board
   hp_c2502=1   to set up for a Hewlett Packard C2502 board
 
-e.g.
-OLD: modprobe g_NCR5380 ncr_irq=5 ncr_addr=0x350 ncr_5380=1
-NEW: modprobe g_NCR5380 irq=5 base=0x350 card=0
-  for a port mapped NCR5380 board or
-
-OLD: modprobe g_NCR5380 ncr_irq=255 ncr_addr=0xc8000 ncr_53c400=1
-NEW: modprobe g_NCR5380 irq=255 base=0xc8000 card=1
-  for a memory mapped NCR53C400 board with interrupts disabled or
+E.g. Trantor T130B in its default configuration:
+modprobe g_NCR5380 irq=5 base=0x350 card=1
+or alternatively, using the old syntax,
+modprobe g_NCR5380 ncr_irq=5 ncr_addr=0x350 ncr_53c400=1
 
-NEW: modprobe g_NCR5380 irq=0,7 base=0x240,0x300 card=3,4
-  for two cards: DTC3181 (in non-PnP mode) at 0x240 with no IRQ
-             and HP C2502 at 0x300 with IRQ 7
+E.g. a port mapped NCR5380 board, driver to probe for IRQ:
+modprobe g_NCR5380 base=0x350 card=0
+or alternatively,
+modprobe g_NCR5380 ncr_addr=0x350 ncr_5380=1
 
-(255 should be specified for no or DMA interrupt, 254 to autoprobe for an 
-     IRQ line if overridden on the command line.)
+E.g. a memory mapped NCR53C400 board with no IRQ:
+modprobe g_NCR5380 irq=255 base=0xc8000 card=1
+or alternatively,
+modprobe g_NCR5380 ncr_irq=255 ncr_addr=0xc8000 ncr_53c400=1
 
+E.g. two cards, DTC3181 (in non-PnP mode) at 0x240 with no IRQ
+and HP C2502 at 0x300 with IRQ 7:
+modprobe g_NCR5380 irq=0,7 base=0x240,0x300 card=3,4
 
 Kevin Lentin
 K.Lentin@cs.monash.edu.au
diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 58a0b82..6f9665d 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -37,7 +37,7 @@
 #define MAX_CARDS 8
 
 /* old-style parameters for compatibility */
-static int ncr_irq;
+static int ncr_irq = -1;
 static int ncr_addr;
 static int ncr_5380;
 static int ncr_53c400;
@@ -52,9 +52,9 @@ module_param(ncr_53c400a, int, 0);
 module_param(dtc_3181e, int, 0);
 module_param(hp_c2502, int, 0);
 
-static int irq[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
+static int irq[] = { -1, -1, -1, -1, -1, -1, -1, -1 };
 module_param_array(irq, int, NULL, 0);
-MODULE_PARM_DESC(irq, "IRQ number(s)");
+MODULE_PARM_DESC(irq, "IRQ number(s) (0=none, 254=auto [default])");
 
 static int base[] = { 0, 0, 0, 0, 0, 0, 0, 0 };
 module_param_array(base, int, NULL, 0);
@@ -344,6 +344,8 @@ static int generic_NCR5380_init_one(struct scsi_host_template *tpnt,
 	/* Compatibility with documented NCR5380 kernel parameters */
 	if (irq == 255 || irq == 0)
 		irq = NO_IRQ;
+	else if (irq == -1)
+		irq = IRQ_AUTO;
 
 	if (board == BOARD_HP_C2502) {
 		int *irq_table = hp_c2502_irqs;
@@ -370,24 +372,28 @@ static int generic_NCR5380_init_one(struct scsi_host_template *tpnt,
 		magic_configure(port_idx, board_irq, magic);
 	}
 
-	if (irq == IRQ_AUTO)
+	if (irq == IRQ_AUTO) {
 		instance->irq = g_NCR5380_probe_irq(instance);
-	else
+		if (instance->irq == NO_IRQ)
+			shost_printk(KERN_INFO, instance, "no irq detected\n");
+	} else {
 		instance->irq = irq;
+		if (instance->irq == NO_IRQ)
+			shost_printk(KERN_INFO, instance, "no irq provided\n");
+	}
 
 	if (instance->irq != NO_IRQ) {
 		if (request_irq(instance->irq, generic_NCR5380_intr,
 				0, "NCR5380", instance)) {
-			printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
 			instance->irq = NO_IRQ;
+			shost_printk(KERN_INFO, instance,
+			             "irq %d denied\n", instance->irq);
+		} else {
+			shost_printk(KERN_INFO, instance,
+			             "irq %d acquired\n", instance->irq);
 		}
 	}
 
-	if (instance->irq == NO_IRQ) {
-		printk(KERN_INFO "scsi%d : interrupts not enabled. for better interactive performance,\n", instance->host_no);
-		printk(KERN_INFO "scsi%d : please jumper the board for a free IRQ.\n", instance->host_no);
-	}
-
 	ret = scsi_add_host(instance, pdev);
 	if (ret)
 		goto out_free_irq;
@@ -698,7 +704,7 @@ static int __init generic_NCR5380_init(void)
 	int ret = 0;
 
 	/* compatibility with old-style parameters */
-	if (irq[0] == 0 && base[0] == 0 && card[0] == -1) {
+	if (irq[0] == -1 && base[0] == 0 && card[0] == -1) {
 		irq[0] = ncr_irq;
 		base[0] = ncr_addr;
 		if (ncr_5380)
-- 
2.7.3

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

* [PATCH 3/4] g_NCR5380: Fix automatic IRQ on HP C2502 cards
  2016-12-05  6:07 [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Finn Thain
  2016-12-05  6:07 ` [PATCH 1/4] g_NCR5380: Check for chip presence before calling NCR5380_init() Finn Thain
  2016-12-05  6:07 ` [PATCH 4/4] g_NCR5380: Autoprobe board IRQ by default Finn Thain
@ 2016-12-05  6:07 ` Finn Thain
  2016-12-05  6:07 ` [PATCH 2/4] g_NCR5380: Use probe_irq_*() for IRQ probing Finn Thain
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 8+ messages in thread
From: Finn Thain @ 2016-12-05  6:07 UTC (permalink / raw)
  To: James E.J. Bottomley, Martin K. Petersen, Ondrej Zary
  Cc: Michael Schmitz, linux-scsi, linux-kernel

When IRQ_AUTO is used, the interrupt for HP C2502 cards gets disabled.
Fix this by programming the card for a suitable free irq. The code for
the free irq search comes from ALSA.

Also allow IRQ 9 to work (it aliases to IRQ 2 on the card), as per
Ondrej Zary's patch.

Suggested-by: Ondrej Zary <linux@rainbow-software.org>
Signed-off-by: Finn Thain <fthain@telegraphics.com.au>
---
 drivers/scsi/g_NCR5380.c | 70 +++++++++++++++++++++++++++++++++++++++---------
 1 file changed, 57 insertions(+), 13 deletions(-)

diff --git a/drivers/scsi/g_NCR5380.c b/drivers/scsi/g_NCR5380.c
index 6d245a7..58a0b82 100644
--- a/drivers/scsi/g_NCR5380.c
+++ b/drivers/scsi/g_NCR5380.c
@@ -131,14 +131,33 @@ static void magic_configure(int idx, u8 irq, u8 magic[])
 	outb(magic[3], 0x379);
 	outb(magic[4], 0x379);
 
-	/* allowed IRQs for HP C2502 */
-	if (irq != 2 && irq != 3 && irq != 4 && irq != 5 && irq != 7)
-		irq = 0;
+	if (irq == 9)
+		irq = 2;
+
 	if (idx >= 0 && idx <= 7)
 		cfg = 0x80 | idx | (irq << 4);
 	outb(cfg, 0x379);
 }
 
+static irqreturn_t legacy_empty_irq_handler(int irq, void *dev_id)
+{
+	return IRQ_HANDLED;
+}
+
+static int legacy_find_free_irq(int *irq_table)
+{
+	while (*irq_table != -1) {
+		if (!request_irq(*irq_table, legacy_empty_irq_handler,
+		                 IRQF_PROBE_SHARED, "Test IRQ",
+		                 (void *)irq_table)) {
+			free_irq(*irq_table, (void *) irq_table);
+			return *irq_table;
+		}
+		irq_table++;
+	}
+	return -1;
+}
+
 static unsigned int ncr_53c400a_ports[] = {
 	0x280, 0x290, 0x300, 0x310, 0x330, 0x340, 0x348, 0x350, 0
 };
@@ -151,6 +170,9 @@ static u8 ncr_53c400a_magic[] = {	/* 53C400A & DTC436 */
 static u8 hp_c2502_magic[] = {	/* HP C2502 */
 	0x0f, 0x22, 0xf0, 0x20, 0x80
 };
+static int hp_c2502_irqs[] = {
+	9, 5, 7, 3, 4, -1
+};
 
 static int generic_NCR5380_init_one(struct scsi_host_template *tpnt,
 			struct device *pdev, int base, int irq, int board)
@@ -319,19 +341,41 @@ static int generic_NCR5380_init_one(struct scsi_host_template *tpnt,
 
 	NCR5380_maybe_reset_bus(instance);
 
-	if (irq != IRQ_AUTO)
-		instance->irq = irq;
-	else
-		instance->irq = g_NCR5380_probe_irq(instance);
-
 	/* Compatibility with documented NCR5380 kernel parameters */
-	if (instance->irq == 255)
-		instance->irq = NO_IRQ;
+	if (irq == 255 || irq == 0)
+		irq = NO_IRQ;
+
+	if (board == BOARD_HP_C2502) {
+		int *irq_table = hp_c2502_irqs;
+		int board_irq = -1;
+
+		switch (irq) {
+		case NO_IRQ:
+			board_irq = 0;
+			break;
+		case IRQ_AUTO:
+			board_irq = legacy_find_free_irq(irq_table);
+			break;
+		default:
+			while (*irq_table != -1)
+				if (*irq_table++ == irq)
+					board_irq = irq;
+		}
+
+		if (board_irq <= 0) {
+			board_irq = 0;
+			irq = NO_IRQ;
+		}
+
+		magic_configure(port_idx, board_irq, magic);
+	}
+
+	if (irq == IRQ_AUTO)
+		instance->irq = g_NCR5380_probe_irq(instance);
+	else
+		instance->irq = irq;
 
 	if (instance->irq != NO_IRQ) {
-		/* set IRQ for HP C2502 */
-		if (board == BOARD_HP_C2502)
-			magic_configure(port_idx, instance->irq, magic);
 		if (request_irq(instance->irq, generic_NCR5380_intr,
 				0, "NCR5380", instance)) {
 			printk(KERN_WARNING "scsi%d : IRQ%d not free, interrupts disabled\n", instance->host_no, instance->irq);
-- 
2.7.3

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

* Re: [PATCH 0/4] g_NCR5380: Bug fix and some enhancements
  2016-12-05  6:07 [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Finn Thain
                   ` (3 preceding siblings ...)
  2016-12-05  6:07 ` [PATCH 2/4] g_NCR5380: Use probe_irq_*() for IRQ probing Finn Thain
@ 2016-12-08 18:45 ` Ondrej Zary
  2016-12-08 22:27   ` Finn Thain
  2016-12-08 21:59 ` Martin K. Petersen
  5 siblings, 1 reply; 8+ messages in thread
From: Ondrej Zary @ 2016-12-08 18:45 UTC (permalink / raw)
  To: Finn Thain
  Cc: James E.J. Bottomley, Martin K. Petersen, Michael Schmitz,
	linux-scsi, linux-kernel

On Monday 05 December 2016 07:07:19 Finn Thain wrote:
> This patch series is based on the one submitted recently by Ondrej Zary.
>
> This version has a different irq probing fix for HP C2502 boards and
> a more comprehensive patch to change the default irq parameter.
>
> It needs testing on actual ISA hardware.

Tested on HP C2502 (53C400A chip), Canon FG2-5202 (53C400 chip), DTC-3181L 
(DTCT-436P chip) and MS-PNR (53C400A chip) ISA cards - everything works fine!

Thanks.

Tested-by: Ondrej Zary <linux@rainbow-software.org>

BTW. The release-region fix (my previous patch 6/6) has disappeared somehow. 
Should I resubmit?

-- 
Ondrej Zary

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

* Re: [PATCH 0/4] g_NCR5380: Bug fix and some enhancements
  2016-12-05  6:07 [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Finn Thain
                   ` (4 preceding siblings ...)
  2016-12-08 18:45 ` [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Ondrej Zary
@ 2016-12-08 21:59 ` Martin K. Petersen
  5 siblings, 0 replies; 8+ messages in thread
From: Martin K. Petersen @ 2016-12-08 21:59 UTC (permalink / raw)
  To: Finn Thain
  Cc: James E.J. Bottomley, Martin K. Petersen, Ondrej Zary,
	Michael Schmitz, linux-scsi, linux-kernel

>>>>> "Finn" == Finn Thain <fthain@telegraphics.com.au> writes:

Finn> This patch series is based on the one submitted recently by Ondrej
Finn> Zary.  This version has a different irq probing fix for HP C2502
Finn> boards and a more comprehensive patch to change the default irq
Finn> parameter.

Applied to 4.10/scsi-queue.

-- 
Martin K. Petersen	Oracle Linux Engineering

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

* Re: [PATCH 0/4] g_NCR5380: Bug fix and some enhancements
  2016-12-08 18:45 ` [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Ondrej Zary
@ 2016-12-08 22:27   ` Finn Thain
  0 siblings, 0 replies; 8+ messages in thread
From: Finn Thain @ 2016-12-08 22:27 UTC (permalink / raw)
  To: Ondrej Zary
  Cc: James E.J. Bottomley, Martin K. Petersen, Michael Schmitz,
	linux-scsi, linux-kernel


On Thu, 8 Dec 2016, Ondrej Zary wrote:

> On Monday 05 December 2016 07:07:19 Finn Thain wrote:
> > This patch series is based on the one submitted recently by Ondrej 
> > Zary.
> >
> > This version has a different irq probing fix for HP C2502 boards and a 
> > more comprehensive patch to change the default irq parameter.
> >
> > It needs testing on actual ISA hardware.
> 
> Tested on HP C2502 (53C400A chip), Canon FG2-5202 (53C400 chip), 
> DTC-3181L (DTCT-436P chip) and MS-PNR (53C400A chip) ISA cards - 
> everything works fine!
> 
> Thanks.
> 

Thanks for testing! I don't recall the MS-PNR board -- some additional 
test coverage is always good.

> Tested-by: Ondrej Zary <linux@rainbow-software.org>
> 
> BTW. The release-region fix (my previous patch 6/6) has disappeared 
> somehow. Should I resubmit?
> 

No need to resubmit it. The patch appears in jejb-scsi/for-next and 
mkp-scsi/4.10/scsi-queue. It fixes a resource leak on an error path, so 
presumably it wasn't important enough for -stable or 4.9-rc.

-- 

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

end of thread, other threads:[~2016-12-08 22:27 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-12-05  6:07 [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Finn Thain
2016-12-05  6:07 ` [PATCH 1/4] g_NCR5380: Check for chip presence before calling NCR5380_init() Finn Thain
2016-12-05  6:07 ` [PATCH 4/4] g_NCR5380: Autoprobe board IRQ by default Finn Thain
2016-12-05  6:07 ` [PATCH 3/4] g_NCR5380: Fix automatic IRQ on HP C2502 cards Finn Thain
2016-12-05  6:07 ` [PATCH 2/4] g_NCR5380: Use probe_irq_*() for IRQ probing Finn Thain
2016-12-08 18:45 ` [PATCH 0/4] g_NCR5380: Bug fix and some enhancements Ondrej Zary
2016-12-08 22:27   ` Finn Thain
2016-12-08 21:59 ` Martin K. Petersen

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).