linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Dmitry Torokhov <dmitry.torokhov@gmail.com>
To: Borislav Petkov <bp@alien8.de>,
	Doug Thompson <dougthompson@xmission.com>,
	Tejun Heo <tj@kernel.org>
Cc: linux-kernel@vger.kernel.org, linux-edac@vger.kernel.org,
	Mauro Carvalho Chehab <mchehab@osg.samsung.com>,
	Tetsuo Handa <penguin-kernel@I-love.SAKURA.ne.jp>,
	Olof Johansson <olof@lixom.net>,
	Arjan van de Ven <arjan@linux.intel.com>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	"Luis R . Rodriguez" <mcgrof@suse.com>
Subject: [PATCH 3/3] EDAC: amd64_edac: decide if driver can load successfully early.
Date: Wed, 18 Mar 2015 17:49:10 -0700	[thread overview]
Message-ID: <1426726150-983-4-git-send-email-dmitry.torokhov@gmail.com> (raw)
In-Reply-To: <1426726150-983-1-git-send-email-dmitry.torokhov@gmail.com>

This change moves setting up PCI control that used to be done after
driver tried to bind to present PCI devices into the probe() method,
thus allowing probing to be done asynchronously, if needed.

To keep as close as possible to the previous behavior we explicitly
check for presence of supported PCI devices; still we may end up with
driver loaded even if we did not bind to any of them (for example if ECC
is disabled).

Signed-off-by: Dmitry Torokhov <dmitry.torokhov@gmail.com>
---
 drivers/edac/amd64_edac.c | 49 ++++++++++++++---------------------------------
 1 file changed, 14 insertions(+), 35 deletions(-)

diff --git a/drivers/edac/amd64_edac.c b/drivers/edac/amd64_edac.c
index d23dad9..0b9e14f 100644
--- a/drivers/edac/amd64_edac.c
+++ b/drivers/edac/amd64_edac.c
@@ -16,11 +16,6 @@ module_param(ecc_enable_override, int, 0644);
 static struct msr __percpu *msrs;
 
 /*
- * count successfully initialized driver instances for setup_pci_device()
- */
-static atomic_t drv_instances = ATOMIC_INIT(0);
-
-/*
  * Valid scrub rates for the K8 hardware memory scrubber. We map the scrubbing
  * bandwidth to a valid bit pattern. The 'set' operation finds the 'matching-
  * or higher value'.
@@ -2851,7 +2846,14 @@ static int init_one_instance(struct pci_dev *F2)
 
 	pci_set_drvdata(F2, pvt);
 
-	atomic_inc(&drv_instances);
+	if (nid == 0 && !pci_ctl) {
+		pci_ctl = edac_pci_create_generic_ctl(&pvt->F2->dev,
+						      EDAC_MOD_STR);
+		if (!pci_ctl) {
+			pr_warn("%s(): Unable to create PCI control\n", __func__);
+			pr_warn("%s(): PCI error report via EDAC not set\n", __func__);
+		}
+	}
 
 	return 0;
 
@@ -2895,6 +2897,9 @@ static void remove_one_instance(struct pci_dev *pdev)
 	struct amd64_pvt *pvt = pci_get_drvdata(pdev);
 	struct mem_ctl_info *mci;
 
+	if (pvt->mc_node_id == 0 && pci_ctl)
+		edac_pci_release_generic_ctl(pci_ctl);
+
 	/* Remove from EDAC CORE tracking list */
 	mci = edac_mc_del_mc(&pdev->dev);
 	if (WARN_ON(!mci))
@@ -2939,26 +2944,6 @@ static struct pci_driver amd64_pci_driver = {
 	.id_table	= amd64_pci_table,
 };
 
-static void setup_pci_device(void)
-{
-	struct mem_ctl_info *mci;
-	struct amd64_pvt *pvt;
-
-	if (pci_ctl)
-		return;
-
-	mci = edac_mc_find(0);
-	if (!mci)
-		return;
-
-	pvt = mci->pvt_info;
-	pci_ctl = edac_pci_create_generic_ctl(&pvt->F2->dev, EDAC_MOD_STR);
-	if (!pci_ctl) {
-		pr_warn("%s(): Unable to create PCI control\n", __func__);
-		pr_warn("%s(): PCI error report via EDAC not set\n", __func__);
-	}
-}
-
 static int __init amd64_edac_init(void)
 {
 	int err = -ENODEV;
@@ -2967,6 +2952,9 @@ static int __init amd64_edac_init(void)
 
 	opstate_init();
 
+	if (!pci_dev_present(amd64_pci_table))
+		goto err_ret;
+
 	if (amd_cache_northbridges() < 0)
 		goto err_ret;
 
@@ -2979,21 +2967,12 @@ static int __init amd64_edac_init(void)
 	if (err)
 		goto err_pci;
 
-	err = -ENODEV;
-	if (!atomic_read(&drv_instances))
-		goto err_no_instances;
-
-	setup_pci_device();
-
 #ifdef CONFIG_X86_32
 	amd64_err("%s on 32-bit is unsupported. USE AT YOUR OWN RISK!\n", EDAC_MOD_STR);
 #endif
 
 	return 0;
 
-err_no_instances:
-	pci_unregister_driver(&amd64_pci_driver);
-
 err_pci:
 	msrs_free(msrs);
 	msrs = NULL;
-- 
2.2.0.rc0.207.ga3a616c


  parent reply	other threads:[~2015-03-19  0:49 UTC|newest]

Thread overview: 30+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-19  0:49 [RFC/RFT] amd64_edac: avoid doing post-probe setup Dmitry Torokhov
2015-03-19  0:49 ` [PATCH 1/3] EDAC: amd64: stop allocating ecc settings separately Dmitry Torokhov
2015-03-19  0:49 ` [PATCH 2/3] EDAC: amd64_edac: clean up remove_one_instance() Dmitry Torokhov
2015-03-19  0:49 ` Dmitry Torokhov [this message]
2015-03-19  9:40   ` [PATCH 3/3] EDAC: amd64_edac: decide if driver can load successfully early Borislav Petkov
2015-03-19 15:29     ` Tejun Heo
2015-03-19 15:35       ` Borislav Petkov
2015-03-19 15:52         ` Dmitry Torokhov
2015-03-19 15:59           ` Borislav Petkov
2015-03-19 16:12             ` Dmitry Torokhov
2015-03-19 16:23               ` Borislav Petkov
2015-03-19 16:33                 ` Tejun Heo
2015-03-19 16:45                   ` Borislav Petkov
2015-03-19 16:49                     ` Tejun Heo
2015-03-19 16:56                       ` Borislav Petkov
2015-03-19 17:03                         ` Tejun Heo
2015-03-19 17:04                           ` Borislav Petkov
2015-03-19 17:10                             ` Tejun Heo
2015-03-19 17:15                               ` Tejun Heo
2015-03-19 17:27                                 ` Borislav Petkov
2015-03-19 17:47                                   ` Tejun Heo
2015-03-19 17:54                                     ` Borislav Petkov
2015-03-19 18:05                                       ` Tejun Heo
2015-03-19 16:52                   ` Dmitry Torokhov
2015-03-19 17:09                     ` Tejun Heo
2015-03-19 15:55         ` Tejun Heo
2015-03-19 16:01           ` Borislav Petkov
2015-03-19 16:12             ` Tejun Heo
2015-03-19 16:57               ` Dmitry Torokhov
2015-03-19 17:22                 ` Tejun Heo

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=1426726150-983-4-git-send-email-dmitry.torokhov@gmail.com \
    --to=dmitry.torokhov@gmail.com \
    --cc=arjan@linux.intel.com \
    --cc=bp@alien8.de \
    --cc=dougthompson@xmission.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-edac@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mcgrof@suse.com \
    --cc=mchehab@osg.samsung.com \
    --cc=olof@lixom.net \
    --cc=penguin-kernel@I-love.SAKURA.ne.jp \
    --cc=tj@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 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).