From patchwork Mon Sep 14 03:08:57 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiang Liu X-Patchwork-Id: 7172601 X-Patchwork-Delegate: bhelgaas@google.com Return-Path: X-Original-To: patchwork-linux-pci@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id A4CFABEEC1 for ; Mon, 14 Sep 2015 03:07:34 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id CAF4B204B0 for ; Mon, 14 Sep 2015 03:07:33 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C213E2047D for ; Mon, 14 Sep 2015 03:07:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754689AbbINDHK (ORCPT ); Sun, 13 Sep 2015 23:07:10 -0400 Received: from mga11.intel.com ([192.55.52.93]:33946 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1753881AbbINDF7 (ORCPT ); Sun, 13 Sep 2015 23:05:59 -0400 Received: from orsmga002.jf.intel.com ([10.7.209.21]) by fmsmga102.fm.intel.com with ESMTP; 13 Sep 2015 20:05:59 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.17,525,1437462000"; d="scan'208";a="803788110" Received: from gerry-dev.bj.intel.com ([10.238.158.61]) by orsmga002.jf.intel.com with ESMTP; 13 Sep 2015 20:05:56 -0700 From: Jiang Liu To: Thomas Gleixner , Bjorn Helgaas , Arthur Marsh , Dario Ballabio , "James E.J. Bottomley" Cc: Jiang Liu , 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 Message-Id: <1442200140-30808-2-git-send-email-jiang.liu@linux.intel.com> X-Mailer: git-send-email 1.7.10.4 In-Reply-To: <1442200140-30808-1-git-send-email-jiang.liu@linux.intel.com> References: <1442200140-30808-1-git-send-email-jiang.liu@linux.intel.com> Sender: linux-pci-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pci@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use IDA to manage eata board IDs, so we could dynamically allocate and free board IDs later. Signed-off-by: Jiang Liu Reviewed-by: Hannes Reinecke --- 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 #include #include +#include #include #include #include @@ -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);