All of lore.kernel.org
 help / color / mirror / Atom feed
From: Jiang Liu <jiang.liu@linux.intel.com>
To: Thomas Gleixner <tglx@linutronix.de>,
	Bjorn Helgaas <bhelgaas@google.com>,
	Arthur Marsh <arthur.marsh@internode.on.net>,
	Dario Ballabio <ballabio_dario@emc.com>,
	"James E.J. Bottomley" <JBottomley@odin.com>
Cc: Jiang Liu <jiang.liu@linux.intel.com>,
	linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
	linux-scsi@vger.kernel.org, x86@kernel.org
Subject: [Bugfix 1/3] eata: Use IDA to manage eata board IDs
Date: Mon, 14 Sep 2015 11:08:57 +0800	[thread overview]
Message-ID: <1442200140-30808-2-git-send-email-jiang.liu@linux.intel.com> (raw)
In-Reply-To: <1442200140-30808-1-git-send-email-jiang.liu@linux.intel.com>

Use IDA to manage eata board IDs, so we could dynamically allocate
and free board IDs later.

Signed-off-by: Jiang Liu <jiang.liu@linux.intel.com>
---
 drivers/scsi/eata.c |   46 ++++++++++++++++++++++++++++++----------------
 1 file changed, 30 insertions(+), 16 deletions(-)

diff --git a/drivers/scsi/eata.c b/drivers/scsi/eata.c
index 227dd2c2ec2f..b45d3b532b70 100644
--- a/drivers/scsi/eata.c
+++ b/drivers/scsi/eata.c
@@ -491,6 +491,7 @@
 #include <linux/spinlock.h>
 #include <linux/dma-mapping.h>
 #include <linux/slab.h>
+#include <linux/idr.h>
 #include <asm/byteorder.h>
 #include <asm/dma.h>
 #include <asm/io.h>
@@ -837,9 +838,8 @@ struct hostdata {
 static struct Scsi_Host *sh[MAX_BOARDS];
 static const char *driver_name = "EATA";
 static char sha[MAX_BOARDS];
-
-/* Initialize num_boards so that ihdlr can work while detect is in progress */
-static unsigned int num_boards = MAX_BOARDS;
+static DEFINE_IDA(eata_ida);
+static DECLARE_BITMAP(eata_board_bitmap, MAX_BOARDS);
 
 static unsigned long io_port[] = {
 
@@ -1509,6 +1509,23 @@ static int option_setup(char *str)
 	return 1;
 }
 
+static unsigned int port_probe(unsigned long port_base,
+			       struct scsi_host_template *tpnt)
+{
+	int id;
+
+	id = ida_simple_get(&eata_ida, 0, MAX_BOARDS, GFP_KERNEL);
+	if (id >= 0) {
+		set_bit(id, eata_board_bitmap);
+		if (port_detect(port_base, id, tpnt))
+			return id;
+		clear_bit(id, eata_board_bitmap);
+		ida_simple_remove(&eata_ida, id);
+	}
+
+	return -1;
+}
+
 static void add_pci_ports(void)
 {
 #if defined(CONFIG_PCI)
@@ -1548,7 +1565,7 @@ static void add_pci_ports(void)
 
 static int eata2x_detect(struct scsi_host_template *tpnt)
 {
-	unsigned int j = 0, k;
+	unsigned int k, count = 0;
 
 	tpnt->proc_name = "eata2x";
 
@@ -1582,17 +1599,12 @@ static int eata2x_detect(struct scsi_host_template *tpnt)
 			enable_pci_ports();
 	}
 
-	for (k = 0; io_port[k]; k++) {
+	for (k = 0; io_port[k]; k++)
+		if (io_port[k] != SKIP &&
+		    port_probe(io_port[k], tpnt) >= 0)
+			count++;
 
-		if (io_port[k] == SKIP)
-			continue;
-
-		if (j < MAX_BOARDS && port_detect(io_port[k], j, tpnt))
-			j++;
-	}
-
-	num_boards = j;
-	return j;
+	return count;
 }
 
 static void map_dma(unsigned int i, struct hostdata *ha)
@@ -2530,14 +2542,16 @@ static irqreturn_t ihdlr(struct Scsi_Host *shost)
 static irqreturn_t do_interrupt_handler(int dummy, void *shap)
 {
 	struct Scsi_Host *shost;
-	unsigned int j;
+	unsigned int j = (unsigned int)((char *)shap - sha);
 	unsigned long spin_flags;
 	irqreturn_t ret;
 
 	/* Check if the interrupt must be processed by this handler */
-	if ((j = (unsigned int)((char *)shap - sha)) >= num_boards)
+	if (j >= MAX_BOARDS || !test_bit(j, eata_board_bitmap))
 		return IRQ_NONE;
 	shost = sh[j];
+	if (!shost)
+		return IRQ_NONE;
 
 	spin_lock_irqsave(shost->host_lock, spin_flags);
 	ret = ihdlr(shost);
-- 
1.7.10.4


  reply	other threads:[~2015-09-14  3:05 UTC|newest]

Thread overview: 55+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-09-06  6:28 eata fails to load on post 4.2 kernels Arthur Marsh
2015-09-06  9:04 ` Arthur Marsh
2015-09-06 11:37   ` Arthur Marsh
2015-09-06 20:31     ` Arthur Marsh
2015-09-07  3:06       ` Jiang Liu
     [not found]         ` <55ED2DFA.6030502@internode.on.net>
2015-09-07  9:24           ` Fwd: " Arthur Marsh
2015-09-08  5:19           ` Jiang Liu
2015-09-08  6:32             ` Arthur Marsh
2015-09-08  6:37               ` Jiang Liu
2015-09-08  7:26               ` [Bugfix] PCI, x86: Correctly allocate IRQs for PCI devices managed by non-PCI drivers Jiang Liu
2015-09-08  9:03                 ` Arthur Marsh
2015-09-08  9:44                   ` Jiang Liu
2015-09-08 16:27                 ` Bjorn Helgaas
2015-09-08 16:49                   ` Jiang Liu
2015-09-09 19:11                     ` Bjorn Helgaas
2015-09-10  8:58                       ` Jiang Liu
2015-09-14  3:08                       ` [Bugfix 0/3] Convert eata driver to a normal PCI device driver Jiang Liu
2015-09-14  3:08                         ` Jiang Liu [this message]
2015-09-14  8:08                           ` [Bugfix 1/3] eata: Use IDA to manage eata board IDs Hannes Reinecke
2015-09-14  8:08                             ` Hannes Reinecke
2015-09-14  3:08                         ` [Bugfix 2/3] eata: Implement PCI driver to manage eata PCI devices Jiang Liu
2015-09-14  8:17                           ` Hannes Reinecke
2015-09-14  8:31                             ` Jiang Liu
2015-09-14  3:08                         ` [Bugfix 3/3] eata: Enhance eata driver to support PCI device hot-removal Jiang Liu
2015-09-14  8:21                           ` Hannes Reinecke
2015-09-14  8:31                             ` Ballabio, Dario
2015-09-14  8:33                               ` Jiang Liu
2015-09-16 13:42                             ` Christoph Hellwig
2015-09-17  6:49                               ` Jiang Liu
2015-09-18 15:08                               ` Arthur Marsh
2015-09-22  7:30                               ` [RFT v3] eata: Convert eata driver as normal PCI and platform device drivers Jiang Liu
2015-09-22 20:27                                 ` Hannes Reinecke
2015-09-22 22:25                                 ` Arthur Marsh
2015-09-22 22:45                                   ` James Bottomley
2015-09-22 23:36                                     ` Arthur Marsh
2015-09-23  5:24                                       ` Jiang Liu
2015-09-23 10:44                                         ` Arthur Marsh
2015-09-23 14:40                                           ` James Bottomley
2015-09-24  4:28                                             ` Jiang Liu
2015-09-24  5:56                                               ` Arthur Marsh
2015-09-26  6:27                                                 ` Arthur Marsh
2015-10-03  8:11                                                   ` Jiang Liu
2015-10-03 11:14                                                     ` Arthur Marsh
2015-10-05  8:29                                                     ` Arthur Marsh
2015-09-14 16:01                         ` [Bugfix 0/3] Convert eata driver to a normal PCI device driver Arthur Marsh
2015-09-15  2:31                           ` Jiang Liu
2015-09-15  7:19                             ` Arthur Marsh
2015-09-16  5:07                               ` Jiang Liu
2015-09-16  7:37                                 ` Arthur Marsh
2015-09-16  8:21                                   ` Jiang Liu
2015-09-16 11:29                                     ` Arthur Marsh
2015-09-09 19:04                 ` [Bugfix] PCI, x86: Correctly allocate IRQs for PCI devices managed by non-PCI drivers Arthur Marsh
2015-09-10  7:50             ` eata fails to load on post 4.2 kernels Arthur Marsh
2015-09-10  8:13               ` Jiang Liu
2015-09-10  9:00                 ` Arthur Marsh

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1442200140-30808-2-git-send-email-jiang.liu@linux.intel.com \
    --to=jiang.liu@linux.intel.com \
    --cc=JBottomley@odin.com \
    --cc=arthur.marsh@internode.on.net \
    --cc=ballabio_dario@emc.com \
    --cc=bhelgaas@google.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux-scsi@vger.kernel.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.