linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Gavin Shan <gwshan@linux.vnet.ibm.com>
To: linux-pci@vger.kernel.org
Cc: bhelgaas@google.com, rjw@sisk.pl, Gavin Shan <gwshan@linux.vnet.ibm.com>
Subject: [PATCH RFC] PCI: Turn off BARs when disabling device
Date: Thu, 11 Dec 2014 17:03:12 +1100	[thread overview]
Message-ID: <1418277792-4090-1-git-send-email-gwshan@linux.vnet.ibm.com> (raw)

When unbinding PCI device mlx4 from its driver, the PCI device is
disabled by pci_disable_device() and the BARs (IO and memory) should
be disabled at the point. However, the memory BARs are still active
after the mlx4_core driver is unloaded as following logs show.

 # lspci -vv -s 0003:0f:00.0
 0003:0f:00.0 Network controller: Mellanox Technologies \
              MT27500 Family [ConnectX-3]
 Subsystem: Mellanox Technologies Device 0061
 Control: I/O- Mem+ BusMaster+ SpecCycle- MemWINV- VGASnoop- \
          ParErr+ Stepping- SERR+ FastB2B- DisINTx+
    :
 Kernel driver in use: mlx4_core
 # echo 0003:0f:00.0 > /sys/bus/pci/drivers/mlx4_core/unbind
 # lspci -vv -s 0003:0f:00.0
 0003:0f:00.0 Network controller: Mellanox Technologies \
              MT27500 Family [ConnectX-3]
 Subsystem: Mellanox Technologies Device 0061
 Control: I/O- Mem+ BusMaster- SpecCycle- MemWINV- VGASnoop- \
          ParErr+ Stepping- SERR+ FastB2B- DisINTx-

The patch turns off all BARs (IO and memory) in do_pci_disable_device().

Signed-off-by: Gavin Shan <gwshan@linux.vnet.ibm.com>
---
 drivers/pci/pci.c | 12 +++++++-----
 1 file changed, 7 insertions(+), 5 deletions(-)

diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c
index 625a4ac..8d2924b 100644
--- a/drivers/pci/pci.c
+++ b/drivers/pci/pci.c
@@ -1496,12 +1496,14 @@ void __weak pcibios_penalize_isa_irq(int irq, int active) {}
 
 static void do_pci_disable_device(struct pci_dev *dev)
 {
-	u16 pci_command;
+	u16 cmd, flags = (PCI_COMMAND_IO |
+			  PCI_COMMAND_MEMORY |
+			  PCI_COMMAND_MASTER);
 
-	pci_read_config_word(dev, PCI_COMMAND, &pci_command);
-	if (pci_command & PCI_COMMAND_MASTER) {
-		pci_command &= ~PCI_COMMAND_MASTER;
-		pci_write_config_word(dev, PCI_COMMAND, pci_command);
+	pci_read_config_word(dev, PCI_COMMAND, &cmd);
+	if (cmd & flags) {
+		cmd &= ~flags;
+		pci_write_config_word(dev, PCI_COMMAND, cmd);
 	}
 
 	pcibios_disable_device(dev);
-- 
1.8.3.2


             reply	other threads:[~2014-12-11  6:04 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-12-11  6:03 Gavin Shan [this message]
2014-12-11 16:49 ` [PATCH RFC] PCI: Turn off BARs when disabling device Bjorn Helgaas
2014-12-11 23:23   ` Gavin Shan

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=1418277792-4090-1-git-send-email-gwshan@linux.vnet.ibm.com \
    --to=gwshan@linux.vnet.ibm.com \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=rjw@sisk.pl \
    /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).