All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
To: <linux-pci@vger.kernel.org>, <linuxppc-dev@lists.ozlabs.org>
Cc: Bjorn Helgaas <helgaas@kernel.org>, <linux@yadro.com>,
	Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
Subject: [PATCH RFC 05/11] drivers: base: Add bus_disconnect_device()
Date: Thu, 24 Oct 2019 20:21:51 +0300	[thread overview]
Message-ID: <20191024172157.878735-6-s.miroshnichenko@yadro.com> (raw)
In-Reply-To: <20191024172157.878735-1-s.miroshnichenko@yadro.com>

Add bus_disconnect_device(), which is similar to bus_remove_device(), but
it doesn't detach the device from its driver, so it can be reconnected to
the same or another bus later.

This is a yet another preparation to hotplugging large PCIe bridges, which
may entail changes in BDF addresses of working devices due to movable bus
numbers. Changed addresses require rebuilding the affected entries in
/sys/bus/pci and /proc/bus/pci.

Using bus_disconnect_device()+bus_add_device() during PCI rescan allows the
drivers to work with their devices uninterruptedly, regardless of changes
in PCI addresses.

Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
---
 drivers/base/bus.c     | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/device.h |  1 +
 2 files changed, 37 insertions(+)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 8f3445cc533e..52d77fb90218 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -497,6 +497,42 @@ void bus_probe_device(struct device *dev)
 	mutex_unlock(&bus->p->mutex);
 }
 
+/**
+ * bus_disconnect_device - disconnect device from bus,
+ * but don't detach it from driver
+ * @dev: device to be disconnected
+ *
+ * - Remove device from all interfaces.
+ * - Remove symlink from bus' directory.
+ * - Delete device from bus's list.
+ */
+void bus_disconnect_device(struct device *dev)
+{
+	struct bus_type *bus = dev->bus;
+	struct subsys_interface *sif;
+
+	if (!bus)
+		return;
+
+	mutex_lock(&bus->p->mutex);
+	list_for_each_entry(sif, &bus->p->interfaces, node)
+		if (sif->remove_dev)
+			sif->remove_dev(dev, sif);
+	mutex_unlock(&bus->p->mutex);
+
+	sysfs_remove_link(&dev->kobj, "subsystem");
+	sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
+			  dev_name(dev));
+	device_remove_groups(dev, dev->bus->dev_groups);
+	if (klist_node_attached(&dev->p->knode_bus))
+		klist_del(&dev->p->knode_bus);
+
+	pr_debug("bus: '%s': remove device %s\n",
+		 dev->bus->name, dev_name(dev));
+	bus_put(dev->bus);
+}
+EXPORT_SYMBOL_GPL(bus_disconnect_device);
+
 /**
  * bus_remove_device - remove device from bus
  * @dev: device to be removed
diff --git a/include/linux/device.h b/include/linux/device.h
index 420228ab9c4b..9f098c32a4ad 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -268,6 +268,7 @@ void bus_sort_breadthfirst(struct bus_type *bus,
 			   int (*compare)(const struct device *a,
 					  const struct device *b));
 extern int bus_add_device(struct device *dev);
+extern void bus_disconnect_device(struct device *dev);
 extern int device_add_class_symlinks(struct device *dev);
 extern void device_remove_class_symlinks(struct device *dev);
 
-- 
2.23.0


WARNING: multiple messages have this Message-ID (diff)
From: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
To: <linux-pci@vger.kernel.org>, <linuxppc-dev@lists.ozlabs.org>
Cc: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>,
	Bjorn Helgaas <helgaas@kernel.org>,
	linux@yadro.com
Subject: [PATCH RFC 05/11] drivers: base: Add bus_disconnect_device()
Date: Thu, 24 Oct 2019 20:21:51 +0300	[thread overview]
Message-ID: <20191024172157.878735-6-s.miroshnichenko@yadro.com> (raw)
In-Reply-To: <20191024172157.878735-1-s.miroshnichenko@yadro.com>

Add bus_disconnect_device(), which is similar to bus_remove_device(), but
it doesn't detach the device from its driver, so it can be reconnected to
the same or another bus later.

This is a yet another preparation to hotplugging large PCIe bridges, which
may entail changes in BDF addresses of working devices due to movable bus
numbers. Changed addresses require rebuilding the affected entries in
/sys/bus/pci and /proc/bus/pci.

Using bus_disconnect_device()+bus_add_device() during PCI rescan allows the
drivers to work with their devices uninterruptedly, regardless of changes
in PCI addresses.

Signed-off-by: Sergey Miroshnichenko <s.miroshnichenko@yadro.com>
---
 drivers/base/bus.c     | 36 ++++++++++++++++++++++++++++++++++++
 include/linux/device.h |  1 +
 2 files changed, 37 insertions(+)

diff --git a/drivers/base/bus.c b/drivers/base/bus.c
index 8f3445cc533e..52d77fb90218 100644
--- a/drivers/base/bus.c
+++ b/drivers/base/bus.c
@@ -497,6 +497,42 @@ void bus_probe_device(struct device *dev)
 	mutex_unlock(&bus->p->mutex);
 }
 
+/**
+ * bus_disconnect_device - disconnect device from bus,
+ * but don't detach it from driver
+ * @dev: device to be disconnected
+ *
+ * - Remove device from all interfaces.
+ * - Remove symlink from bus' directory.
+ * - Delete device from bus's list.
+ */
+void bus_disconnect_device(struct device *dev)
+{
+	struct bus_type *bus = dev->bus;
+	struct subsys_interface *sif;
+
+	if (!bus)
+		return;
+
+	mutex_lock(&bus->p->mutex);
+	list_for_each_entry(sif, &bus->p->interfaces, node)
+		if (sif->remove_dev)
+			sif->remove_dev(dev, sif);
+	mutex_unlock(&bus->p->mutex);
+
+	sysfs_remove_link(&dev->kobj, "subsystem");
+	sysfs_remove_link(&dev->bus->p->devices_kset->kobj,
+			  dev_name(dev));
+	device_remove_groups(dev, dev->bus->dev_groups);
+	if (klist_node_attached(&dev->p->knode_bus))
+		klist_del(&dev->p->knode_bus);
+
+	pr_debug("bus: '%s': remove device %s\n",
+		 dev->bus->name, dev_name(dev));
+	bus_put(dev->bus);
+}
+EXPORT_SYMBOL_GPL(bus_disconnect_device);
+
 /**
  * bus_remove_device - remove device from bus
  * @dev: device to be removed
diff --git a/include/linux/device.h b/include/linux/device.h
index 420228ab9c4b..9f098c32a4ad 100644
--- a/include/linux/device.h
+++ b/include/linux/device.h
@@ -268,6 +268,7 @@ void bus_sort_breadthfirst(struct bus_type *bus,
 			   int (*compare)(const struct device *a,
 					  const struct device *b));
 extern int bus_add_device(struct device *dev);
+extern void bus_disconnect_device(struct device *dev);
 extern int device_add_class_symlinks(struct device *dev);
 extern void device_remove_class_symlinks(struct device *dev);
 
-- 
2.23.0


  parent reply	other threads:[~2019-10-24 17:22 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-24 17:21 [PATCH RFC 00/11] PCI: hotplug: Movable bus numbers Sergey Miroshnichenko
2019-10-24 17:21 ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 01/11] PCI: sysfs: Nullify freed pointers Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 02/11] PCI: proc: Nullify a freed pointer Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 03/11] drivers: base: Make bus_add_device() public Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 04/11] drivers: base: Make device_{add|remove}_class_symlinks() public Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` Sergey Miroshnichenko [this message]
2019-10-24 17:21   ` [PATCH RFC 05/11] drivers: base: Add bus_disconnect_device() Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 06/11] powerpc/pci: Enable assigning bus numbers instead of reading them from DT Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 07/11] powerpc/pci: Don't reduce the host bridge bus range Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 08/11] PCI: Allow expanding the bridges Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 09/11] PCI: hotplug: Add initial support for movable bus numbers Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 10/11] PCI: hotplug: movable bus numbers: rename proc and sysfs entries Sergey Miroshnichenko
2019-10-24 17:21   ` Sergey Miroshnichenko
2019-10-24 17:21 ` [PATCH RFC 11/11] PCI: hotplug: movable bus numbers: compact the gaps in numbering Sergey Miroshnichenko
2019-10-24 17:21   ` 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=20191024172157.878735-6-s.miroshnichenko@yadro.com \
    --to=s.miroshnichenko@yadro.com \
    --cc=helgaas@kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=linux@yadro.com \
    --cc=linuxppc-dev@lists.ozlabs.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 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.