linux-pci.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Tianfei Zhang <tianfei.zhang@intel.com>
To: bhelgaas@google.com, linux-pci@vger.kernel.org,
	linux-fpga@vger.kernel.org, lukas@wunner.de, kabel@kernel.org,
	mani@kernel.org, pali@kernel.org, mdf@kernel.org,
	hao.wu@intel.com, yilun.xu@intel.com, trix@redhat.com,
	jgg@ziepe.ca, ira.weiny@intel.com,
	andriy.shevchenko@linux.intel.com, dan.j.williams@intel.com,
	keescook@chromium.org, rafael@kernel.org,
	russell.h.weight@intel.com, corbet@lwn.net,
	linux-doc@vger.kernel.org, ilpo.jarvinen@linux.intel.com,
	lee@kernel.org, gregkh@linuxfoundation.org,
	matthew.gerlach@linux.intel.com
Cc: Tianfei Zhang <tianfei.zhang@intel.com>
Subject: [PATCH v1 01/12] PCI: hotplug: add new callbacks on hotplug_slot_ops
Date: Wed, 18 Jan 2023 20:35:51 -0500	[thread overview]
Message-ID: <20230119013602.607466-2-tianfei.zhang@intel.com> (raw)
In-Reply-To: <20230119013602.607466-1-tianfei.zhang@intel.com>

To reprogram an PCIe-based FPGA card, a new image is
burned into FLASH on the card and then the card BMC is
triggered to reboot the card and load the new image.

Two new operation callbacks are defined in hotplug_slot_ops
to trigger the reprogramming of an FPGA-based PCIe card:

  - available_images: Optional: available FPGA images
  - image_load: Optional: trigger the FPGA to load a new image

Signed-off-by: Tianfei Zhang <tianfei.zhang@intel.com>
Reviewed-by: Ilpo Järvinen <ilpo.jarvinen@linux.intel.com>
---
 drivers/pci/hotplug/pci_hotplug_core.c | 88 ++++++++++++++++++++++++++
 include/linux/pci_hotplug.h            |  5 ++
 2 files changed, 93 insertions(+)

diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
index 058d5937d8a9..2b14b6513a03 100644
--- a/drivers/pci/hotplug/pci_hotplug_core.c
+++ b/drivers/pci/hotplug/pci_hotplug_core.c
@@ -231,6 +231,52 @@ static struct pci_slot_attribute hotplug_slot_attr_test = {
 	.store = test_write_file
 };
 
+static ssize_t available_images_read_file(struct pci_slot *pci_slot, char *buf)
+{
+	struct hotplug_slot *slot = pci_slot->hotplug;
+	ssize_t count = 0;
+
+	if (!try_module_get(slot->owner))
+		return -ENODEV;
+
+	if (slot->ops->available_images(slot, buf))
+		count = slot->ops->available_images(slot, buf);
+
+	module_put(slot->owner);
+
+	return count;
+}
+
+static struct pci_slot_attribute hotplug_slot_attr_available_images = {
+	.attr = { .name = "available_images", .mode = 0444 },
+	.show = available_images_read_file,
+};
+
+static ssize_t image_load_write_file(struct pci_slot *pci_slot,
+				     const char *buf, size_t count)
+{
+	struct hotplug_slot *slot = pci_slot->hotplug;
+	int retval = 0;
+
+	if (!try_module_get(slot->owner))
+		return -ENODEV;
+
+	if (slot->ops->image_load)
+		retval = slot->ops->image_load(slot, buf);
+
+	module_put(slot->owner);
+
+	if (retval)
+		return retval;
+
+	return count;
+}
+
+static struct pci_slot_attribute hotplug_slot_attr_image_load = {
+	.attr = { .name = "image_load", .mode = 0644 },
+	.store = image_load_write_file,
+};
+
 static bool has_power_file(struct pci_slot *pci_slot)
 {
 	struct hotplug_slot *slot = pci_slot->hotplug;
@@ -289,6 +335,20 @@ static bool has_test_file(struct pci_slot *pci_slot)
 	return false;
 }
 
+static bool has_available_images_file(struct pci_slot *pci_slot)
+{
+	struct hotplug_slot *slot = pci_slot->hotplug;
+
+	return slot && slot->ops && slot->ops->available_images;
+}
+
+static bool has_image_load_file(struct pci_slot *pci_slot)
+{
+	struct hotplug_slot *slot = pci_slot->hotplug;
+
+	return slot && slot->ops && slot->ops->image_load;
+}
+
 static int fs_add_slot(struct pci_slot *pci_slot)
 {
 	int retval = 0;
@@ -331,8 +391,30 @@ static int fs_add_slot(struct pci_slot *pci_slot)
 			goto exit_test;
 	}
 
+	if (has_available_images_file(pci_slot)) {
+		retval = sysfs_create_file(&pci_slot->kobj,
+					   &hotplug_slot_attr_available_images.attr);
+		if (retval)
+			goto exit_available_images;
+	}
+
+	if (has_image_load_file(pci_slot)) {
+		retval = sysfs_create_file(&pci_slot->kobj,
+					   &hotplug_slot_attr_image_load.attr);
+		if (retval)
+			goto exit_image_load;
+	}
+
 	goto exit;
 
+exit_image_load:
+	if (has_adapter_file(pci_slot))
+		sysfs_remove_file(&pci_slot->kobj,
+				  &hotplug_slot_attr_available_images.attr);
+exit_available_images:
+	if (has_adapter_file(pci_slot))
+		sysfs_remove_file(&pci_slot->kobj,
+				  &hotplug_slot_attr_test.attr);
 exit_test:
 	if (has_adapter_file(pci_slot))
 		sysfs_remove_file(&pci_slot->kobj,
@@ -372,6 +454,12 @@ static void fs_remove_slot(struct pci_slot *pci_slot)
 	if (has_test_file(pci_slot))
 		sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_test.attr);
 
+	if (has_available_images_file(pci_slot))
+		sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_available_images.attr);
+
+	if (has_image_load_file(pci_slot))
+		sysfs_remove_file(&pci_slot->kobj, &hotplug_slot_attr_image_load.attr);
+
 	pci_hp_remove_module_link(pci_slot);
 }
 
diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
index 3a10d6ec3ee7..b7f39c20ad8b 100644
--- a/include/linux/pci_hotplug.h
+++ b/include/linux/pci_hotplug.h
@@ -29,6 +29,9 @@
  * @reset_slot: Optional interface to allow override of a bus reset for the
  *	slot for cases where a secondary bus reset can result in spurious
  *	hotplug events or where a slot can be reset independent of the bus.
+ * @available_images: Optional: called to get the available images for accelerator,
+ *	like FPGA.
+ * @image_load: Optional: called to load a new image for accelerator like FPGA.
  *
  * The table of function pointers that is passed to the hotplug pci core by a
  * hotplug pci driver.  These functions are called by the hotplug pci core when
@@ -45,6 +48,8 @@ struct hotplug_slot_ops {
 	int (*get_latch_status)		(struct hotplug_slot *slot, u8 *value);
 	int (*get_adapter_status)	(struct hotplug_slot *slot, u8 *value);
 	int (*reset_slot)		(struct hotplug_slot *slot, bool probe);
+	int (*available_images)		(struct hotplug_slot *slot, char *buf);
+	int (*image_load)		(struct hotplug_slot *slot, const char *buf);
 };
 
 /**
-- 
2.38.1


  reply	other threads:[~2023-01-19  1:31 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-19  1:35 [PATCH v1 00/12] add FPGA hotplug manager driver Tianfei Zhang
2023-01-19  1:35 ` Tianfei Zhang [this message]
2023-01-19 13:31   ` [PATCH v1 01/12] PCI: hotplug: add new callbacks on hotplug_slot_ops Greg KH
2023-01-19  1:35 ` [PATCH v1 02/12] PCI: hotplug: expose APIs from pciehp driver Tianfei Zhang
2023-01-19  1:35 ` [PATCH v1 03/12] PCI: hotplug: add and expose link disable API Tianfei Zhang
2023-01-19  1:35 ` [PATCH v1 04/12] PCI: hotplug: add FPGA PCI hotplug manager driver Tianfei Zhang
2023-01-19  1:35 ` [PATCH v1 05/12] fpga: dfl: register dfl-pci device into fpgahph driver Tianfei Zhang
2023-01-19  1:35 ` [PATCH v1 06/12] driver core: expose device_is_ancestor() API Tianfei Zhang
2023-01-19  1:35 ` [PATCH v1 07/12] PCI: hotplug: add register/unregister function for BMC device Tianfei Zhang
2023-01-19  1:35 ` [PATCH v1 08/12] fpga: m10bmc-sec: register BMC device into fpgahp driver Tianfei Zhang
2023-01-19  1:35 ` [PATCH v1 09/12] fpga: dfl: remove non-reserved devices Tianfei Zhang
2023-01-19  1:36 ` [PATCH v1 10/12] PCI: hotplug: implement the hotplug_slot_ops callback for fpgahp Tianfei Zhang
2023-01-19 13:28   ` Greg KH
2023-01-20 22:38     ` Russ Weight
2023-01-21  7:35       ` Greg KH
2023-01-19  1:36 ` [PATCH v1 11/12] fpga: m10bmc-sec: add m10bmc_sec_retimer_load callback Tianfei Zhang
2023-01-19 14:22   ` Lee Jones
2023-01-19  1:36 ` [PATCH v1 12/12] Documentation: fpga: add description of fpgahp driver Tianfei Zhang
2023-01-19  9:38   ` Bagas Sanjaya
2023-01-19  8:06 ` [PATCH v1 00/12] add FPGA hotplug manager driver Pali Rohár
2023-01-19  8:17   ` Zhang, Tianfei
2023-01-19 11:27     ` andriy.shevchenko
2023-01-19 12:09       ` Zhang, Tianfei
2023-01-19 13:33 ` Greg KH
2023-01-19 13:43   ` Rafael J. Wysocki
2023-01-19 15:33     ` Greg KH
2023-01-20 16:28   ` Russ Weight
2023-01-20 18:42     ` Lukas Wunner
2023-01-21  7:34       ` Greg KH

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=20230119013602.607466-2-tianfei.zhang@intel.com \
    --to=tianfei.zhang@intel.com \
    --cc=andriy.shevchenko@linux.intel.com \
    --cc=bhelgaas@google.com \
    --cc=corbet@lwn.net \
    --cc=dan.j.williams@intel.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=hao.wu@intel.com \
    --cc=ilpo.jarvinen@linux.intel.com \
    --cc=ira.weiny@intel.com \
    --cc=jgg@ziepe.ca \
    --cc=kabel@kernel.org \
    --cc=keescook@chromium.org \
    --cc=lee@kernel.org \
    --cc=linux-doc@vger.kernel.org \
    --cc=linux-fpga@vger.kernel.org \
    --cc=linux-pci@vger.kernel.org \
    --cc=lukas@wunner.de \
    --cc=mani@kernel.org \
    --cc=matthew.gerlach@linux.intel.com \
    --cc=mdf@kernel.org \
    --cc=pali@kernel.org \
    --cc=rafael@kernel.org \
    --cc=russell.h.weight@intel.com \
    --cc=trix@redhat.com \
    --cc=yilun.xu@intel.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).