All of lore.kernel.org
 help / color / mirror / Atom feed
From: Heiner Kallweit <hkallweit1@gmail.com>
To: Philipp Stanner <pstanner@redhat.com>,
	Bjorn Helgaas <bhelgaas@google.com>
Cc: "linux-pci@vger.kernel.org" <linux-pci@vger.kernel.org>
Subject: [PATCH RFC 1/2] PCI: Restore original PCI_COMMAND value in pcim_release
Date: Fri, 29 Mar 2024 22:41:45 +0100	[thread overview]
Message-ID: <3bdea180-e0ea-451d-ac14-5b02c192467e@gmail.com> (raw)
In-Reply-To: <cb48fd68-9bfa-45b7-ac4f-d1c2b9b1f207@gmail.com>

Instead of the complex handling of INTX and MWI in PCi devres, let's
simply restore the original vale of PCI_COMMAND in pcim_release().

Only side effect I've seen so far is that the "enabling device" info
message is printed each time a driver is re-probed after a EPROBE_DEFER.
I propose to silence this message by changing it to debug level.

Signed-off-by: Heiner Kallweit <hkallweit1@gmail.com>
---
 drivers/pci/devres.c | 8 ++------
 drivers/pci/probe.c  | 3 +++
 include/linux/pci.h  | 1 +
 3 files changed, 6 insertions(+), 6 deletions(-)

diff --git a/drivers/pci/devres.c b/drivers/pci/devres.c
index 2c562b9ea..7766f4df4 100644
--- a/drivers/pci/devres.c
+++ b/drivers/pci/devres.c
@@ -172,14 +172,10 @@ static void pcim_release(struct device *gendev, void *res)
 		if (this->region_mask & (1 << i))
 			pci_release_region(dev, i);
 
-	if (this->mwi)
-		pci_clear_mwi(dev);
-
-	if (this->restore_intx)
-		pci_intx(dev, this->orig_intx);
-
 	if (this->enabled && !this->pinned)
 		pci_disable_device(dev);
+
+	pci_write_config_word(dev, PCI_COMMAND, dev->pci_command);
 }
 
 /*
diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
index 1325fbae2..60052c979 100644
--- a/drivers/pci/probe.c
+++ b/drivers/pci/probe.c
@@ -2558,6 +2558,9 @@ void pci_device_add(struct pci_dev *dev, struct pci_bus *bus)
 
 	pci_init_capabilities(dev);
 
+	/* Store original register value */
+	pci_read_config_word(dev, PCI_COMMAND, &dev->pci_command);
+
 	/*
 	 * Add the device to our list of discovered devices
 	 * and the bus list for fixup functions, etc.
diff --git a/include/linux/pci.h b/include/linux/pci.h
index 16493426a..92c3c99c9 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -352,6 +352,7 @@ struct pci_dev {
 	u8		rom_base_reg;	/* Config register controlling ROM */
 	u8		pin;		/* Interrupt pin this device uses */
 	u16		pcie_flags_reg;	/* Cached PCIe Capabilities Register */
+	u16		pci_command;	/* Restore original value in pci_disable_device */
 	unsigned long	*dma_alias_mask;/* Mask of enabled devfn aliases */
 
 	struct pci_driver *driver;	/* Driver bound to this device */
-- 
2.44.0



  reply	other threads:[~2024-03-29 21:41 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-03-29 21:40 [PATCH RFC 0/2] PCI: Restore original PCI_COMMAND value in pcim_release Heiner Kallweit
2024-03-29 21:41 ` Heiner Kallweit [this message]
2024-03-29 21:42 ` [PATCH RFC 2/2] PCI: Remove MWI and INTX related members from struct pci_devres Heiner Kallweit

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=3bdea180-e0ea-451d-ac14-5b02c192467e@gmail.com \
    --to=hkallweit1@gmail.com \
    --cc=bhelgaas@google.com \
    --cc=linux-pci@vger.kernel.org \
    --cc=pstanner@redhat.com \
    /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.