From: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
To: <linux-pci@vger.kernel.org>
Cc: <linux@yadro.com>, Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
Subject: [PATCH RFC v2 18/21] nvme-pci: Handle movable BARs
Date: Fri, 11 Jan 2019 18:37:04 +0300 [thread overview]
Message-ID: <20190111153707.10140-19-s.miroshnichenko@yadro.com> (raw)
In-Reply-To: <20190111153707.10140-1-s.miroshnichenko@yadro.com>
Hotplugged devices can affect the existing ones by moving their BARs.
PCI subsystem will inform the NVME driver about this by invoking
reset_prepare()+reset_done(), then iounmap()+ioremap() must be called.
Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
---
drivers/nvme/host/pci.c | 29 +++++++++++++++++++++++++++--
1 file changed, 27 insertions(+), 2 deletions(-)
diff --git a/drivers/nvme/host/pci.c b/drivers/nvme/host/pci.c
index 5a0bf6a24d50..bf72f934f20c 100644
--- a/drivers/nvme/host/pci.c
+++ b/drivers/nvme/host/pci.c
@@ -113,6 +113,7 @@ struct nvme_dev {
unsigned int num_vecs;
int q_depth;
u32 db_stride;
+ resource_size_t current_phys_bar;
void __iomem *bar;
unsigned long bar_mapped_size;
struct work_struct remove_work;
@@ -1667,13 +1668,16 @@ static int nvme_remap_bar(struct nvme_dev *dev, unsigned long size)
{
struct pci_dev *pdev = to_pci_dev(dev->dev);
- if (size <= dev->bar_mapped_size)
+ if (dev->bar &&
+ dev->current_phys_bar == pci_resource_start(pdev, 0) &&
+ size <= dev->bar_mapped_size)
return 0;
if (size > pci_resource_len(pdev, 0))
return -ENOMEM;
if (dev->bar)
iounmap(dev->bar);
- dev->bar = ioremap(pci_resource_start(pdev, 0), size);
+ dev->current_phys_bar = pci_resource_start(pdev, 0);
+ dev->bar = ioremap(dev->current_phys_bar, size);
if (!dev->bar) {
dev->bar_mapped_size = 0;
return -ENOMEM;
@@ -2520,6 +2524,8 @@ static void nvme_reset_work(struct work_struct *work)
if (WARN_ON(dev->ctrl.state != NVME_CTRL_RESETTING))
goto out;
+ nvme_remap_bar(dev, db_bar_size(dev, 0));
+
/*
* If we're called to reset a live controller first shut it down before
* moving on.
@@ -2922,6 +2928,23 @@ static void nvme_error_resume(struct pci_dev *pdev)
flush_work(&dev->ctrl.reset_work);
}
+void nvme_rescan_prepare(struct pci_dev *pdev)
+{
+ struct nvme_dev *dev = pci_get_drvdata(pdev);
+
+ nvme_dev_disable(dev, false);
+ nvme_dev_unmap(dev);
+ dev->bar = NULL;
+}
+
+void nvme_rescan_done(struct pci_dev *pdev)
+{
+ struct nvme_dev *dev = pci_get_drvdata(pdev);
+
+ nvme_dev_map(dev);
+ nvme_reset_ctrl_sync(&dev->ctrl);
+}
+
static const struct pci_error_handlers nvme_err_handler = {
.error_detected = nvme_error_detected,
.slot_reset = nvme_slot_reset,
@@ -2984,6 +3007,8 @@ static struct pci_driver nvme_driver = {
},
.sriov_configure = pci_sriov_configure_simple,
.err_handler = &nvme_err_handler,
+ .rescan_prepare = nvme_rescan_prepare,
+ .rescan_done = nvme_rescan_done,
};
static int __init nvme_init(void)
--
2.20.1
next prev parent reply other threads:[~2019-01-11 15:43 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2019-01-11 15:36 [PATCH RFC v2 00/21] PCI: Allow BAR movement during hotplug Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 01/21] PCI: Fix writing invalid BARs during pci_restore_state() Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 02/21] PCI: Define PCI-specific version of the release_child_resources() Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 03/21] PCI: hotplug: Add a flag for the movable BARs feature Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 04/21] PCI: Pause the devices with movable BARs during rescan Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 05/21] PCI: Release and reassign the root bridge resources " Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 06/21] PCI: Don't allow hotplugged devices to steal resources Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 07/21] PCI: Mark immovable BARs with PCI_FIXED Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 08/21] PCI: Include fixed BARs into the bus size calculating Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 09/21] PCI: Don't reserve memory for hotplug when enabled movable BARs Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 10/21] PCI: Allow the failed resources to be reassigned later Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 11/21] PCI: Calculate fixed areas of bridge windows based on fixed BARs Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 12/21] PCI: Calculate boundaries for bridge windows Sergey Miroshnichenko
2019-01-11 15:36 ` [PATCH RFC v2 13/21] PCI: Make sure bridge windows include their fixed BARs Sergey Miroshnichenko
2019-01-11 15:37 ` [PATCH RFC v2 14/21] PCI: Prioritize fixed BAR assigning over the movable ones Sergey Miroshnichenko
2019-01-11 15:37 ` [PATCH RFC v2 15/21] PCI: Fix race condition in pci_enable/disable_device() Sergey Miroshnichenko
2019-01-11 15:37 ` [PATCH RFC v2 16/21] PCI: Enable bridge's I/O and MEM access for hotplugged devices Sergey Miroshnichenko
2019-01-11 15:37 ` [PATCH RFC v2 17/21] PCI: pciehp: Add support for the movable BARs feature Sergey Miroshnichenko
2019-01-11 15:37 ` Sergey Miroshnichenko [this message]
2019-01-11 15:37 ` [PATCH RFC v2 19/21] powerpc/pci: Fix crash with enabled movable BARs Sergey Miroshnichenko
2019-01-11 15:37 ` [PATCH RFC v2 20/21] PCI: Wake up bridges during rescan when movable BARs enabled Sergey Miroshnichenko
2019-01-11 15:37 ` [PATCH RFC v2 21/21] x86: enable movable BARs Sergey Miroshnichenko
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=20190111153707.10140-19-s.miroshnichenko@yadro.com \
--to=s.miroshnichenko@yadro.com \
--cc=linux-pci@vger.kernel.org \
--cc=linux@yadro.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 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).