From patchwork Thu Dec 11 06:03:12 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gavin Shan X-Patchwork-Id: 5474241 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.19.201]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E7FE2BEEA8 for ; Thu, 11 Dec 2014 06:04:27 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 306EA20166 for ; Thu, 11 Dec 2014 06:04:23 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4A9D720114 for ; Thu, 11 Dec 2014 06:04:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755474AbaLKGER (ORCPT ); Thu, 11 Dec 2014 01:04:17 -0500 Received: from e23smtp07.au.ibm.com ([202.81.31.140]:37022 "EHLO e23smtp07.au.ibm.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1758822AbaLKGEQ (ORCPT ); Thu, 11 Dec 2014 01:04:16 -0500 Received: from /spool/local by e23smtp07.au.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 11 Dec 2014 16:04:14 +1000 Received: from d23dlp02.au.ibm.com (202.81.31.213) by e23smtp07.au.ibm.com (202.81.31.204) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Thu, 11 Dec 2014 16:04:12 +1000 Received: from d23relay06.au.ibm.com (d23relay06.au.ibm.com [9.185.63.219]) by d23dlp02.au.ibm.com (Postfix) with ESMTP id 969B42BB0057 for ; Thu, 11 Dec 2014 17:04:10 +1100 (EST) Received: from d23av03.au.ibm.com (d23av03.au.ibm.com [9.190.234.97]) by d23relay06.au.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id sBB642D737486592 for ; Thu, 11 Dec 2014 17:04:10 +1100 Received: from d23av03.au.ibm.com (localhost [127.0.0.1]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVout) with ESMTP id sBB63bKl012945 for ; Thu, 11 Dec 2014 17:03:38 +1100 Received: from shangw (haven.au.ibm.com [9.192.253.15]) by d23av03.au.ibm.com (8.14.4/8.14.4/NCO v10.0 AVin) with ESMTP id sBB63bBb012344; Thu, 11 Dec 2014 17:03:37 +1100 Received: by shangw (Postfix, from userid 1000) id 664823E0299; Thu, 11 Dec 2014 17:03:13 +1100 (EST) From: Gavin Shan To: linux-pci@vger.kernel.org Cc: bhelgaas@google.com, rjw@sisk.pl, Gavin Shan Subject: [PATCH RFC] PCI: Turn off BARs when disabling device Date: Thu, 11 Dec 2014 17:03:12 +1100 Message-Id: <1418277792-4090-1-git-send-email-gwshan@linux.vnet.ibm.com> X-Mailer: git-send-email 1.8.3.2 X-TM-AS-MML: disable X-Content-Scanned: Fidelis XPS MAILER x-cbid: 14121106-0025-0000-0000-000000B4D50D 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 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 --- 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);