add FPGA hotplug manager driver
Subsystems (8)
cover add FPGA hotplug manager driver
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver. Two new operation callbacks are defined in hotplug_slot_ops:
- available_images: Optional: available FPGA images
- image_load: Optional: trigger the FPGA to load a new image
The process of reprogramming an FPGA card begins by removing all devices associated with the card that are not required for the reprogramming of the card. This includes PCIe devices (PFs and VFs) associated with the card as well as any other types of devices (platform, etc.) defined within the FPGA. The remaining devices are referred to here as "reserved" devices. After triggering the update of the FPGA card, the reserved devices are also removed.
The complete process for reprogramming the FPGA are:
1. remove all PFs and VFs except for PF0 (reserved).
2. remove all non-reserved devices of PF0.
3. trigger FPGA card to do the image update.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under hotplug bridge.
6. wait for image reload done via BMC, e.g. 10s.
7. re-enable the link of hotplug bridge
8. enumerate PCI devices below the hotplug bridge
usage example:
[root@localhost]# cd /sys/bus/pci/slot/X-X/
Get the available images.
[root@localhost 2-1]# cat available_imagesbmc_factory bmc_user retimer_fw
Load the request images for FPGA Card, for example load the BMC user image:
[root@localhost 2-1]# echo bmc_user > image_load
Tianfei Zhang (12):
PCI: hotplug: add new callbacks on hotplug_slot_ops
PCI: hotplug: expose APIs from pciehp driver
PCI: hotplug: add and expose link disable API
PCI: hotplug: add FPGA PCI hotplug manager driver
fpga: dfl: register dfl-pci device into fpgahph driver driver core: expose device_is_ancestor() API
PCI: hotplug: add register/unregister function for BMC device
fpga: m10bmc-sec: register BMC device into fpgahp driver
fpga: dfl: remove non-reserved devices
PCI: hotplug: implement the hotplug_slot_ops callback for fpgahp
fpga: m10bmc-sec: add m10bmc_sec_retimer_load callback
Documentation: fpga: add description of fpgahp driver
Documentation/ABI/testing/sysfs-driver-fpgahp | 21 + Documentation/fpga/fpgahp.rst | 29 + Documentation/fpga/index.rst | 1 + MAINTAINERS | 10 + drivers/base/core.c | 3 +- drivers/fpga/Kconfig | 2 + drivers/fpga/dfl-pci.c | 95 +++- drivers/fpga/dfl.c | 58 ++ drivers/fpga/dfl.h | 4 + drivers/fpga/intel-m10-bmc-sec-update.c | 246 ++++++++ drivers/pci/hotplug/Kconfig | 14 + drivers/pci/hotplug/Makefile | 1 + drivers/pci/hotplug/fpgahp.c | 526 ++++++++++++++++++ drivers/pci/hotplug/pci_hotplug_core.c | 88 +++ drivers/pci/hotplug/pciehp.h | 3 + drivers/pci/hotplug/pciehp_hpc.c | 11 +- drivers/pci/hotplug/pciehp_pci.c | 2 + include/linux/device.h | 1 + include/linux/fpga/fpgahp_manager.h | 100 ++++ include/linux/mfd/intel-m10-bmc.h | 31 ++ include/linux/pci_hotplug.h | 5 + 21 files changed, 1243 insertions(+), 8 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-fpgahp create mode 100644 Documentation/fpga/fpgahp.rst create mode 100644 drivers/pci/hotplug/fpgahp.c create mode 100644 include/linux/fpga/fpgahp_manager.h
base-commit: 5dc4c995db9eb45f6373a956eb1f69460e69e6d4
Signature · 1 line
2.38.1
PATCH 1/12 PCI: hotplug: add new callbacks on hotplug_slot_ops
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
--- drivers/pci/hotplug/pci_hotplug_core.c | 88 ++++++++++++++++++++++++++ include/linux/pci_hotplug.h | 5 ++ 2 files changed, 93 insertions(+)
drivers/pci/hotplug/pci_hotplug_core.c +88 -0
@@ -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); }
include/linux/pci_hotplug.h +5 -0
@@ -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); };/**
Signature · 1 line
2.38.1
Greg KH
maintainerRe: [PATCH v1 01/12] PCI: hotplug: add new callbacks on hotplug_slot_ops
Quoted 34 lines · Tianfei Zhang
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_opsto 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 imageSigned-off-by Tianfei Zhang <[email protected]>Reviewed-by Ilpo Järvinen <[email protected]>--- drivers/pci/hotplug/pci_hotplug_core.c | 88 ++++++++++++++++++++++++++ include/linux/pci_hotplug.h | 5 ++ 2 files changed, 93 insertions(+)drivers/pci/hotplug/pci_hotplug_core.c +9
-0@@ -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))
drivers/pci/hotplug/pci_hotplug_core.c static struct pci_slot_attribute hotplug_slot_attr_test = { · line 252
Quoted 10 lines
drivers/pci/hotplug/pci_hotplug_core.c +10
-0+ 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,
If you name things properly, you can use the correct macros and not have to open-code any of this :(
Quoted 13 lines
drivers/pci/hotplug/pci_hotplug_core.c +13
-0+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);
drivers/pci/hotplug/pci_hotplug_core.c static struct pci_slot_attribute hotplug_slot_attr_test = { · line 277
Quoted 10 lines
drivers/pci/hotplug/pci_hotplug_core.c +10
-0+ +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,
Same here, don't open-code this.
Quoted 58 lines
drivers/pci/hotplug/pci_hotplug_core.c +38
-0+}; +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,
drivers/pci/hotplug/pci_hotplug_core.c static void fs_remove_slot(struct pci_slot *pci_slot) · line 462
Quoted 9 lines
drivers/pci/hotplug/pci_hotplug_core.c +6
-0@@ -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); +
Ick no, please just make this an attribute group that properly shows or does not show, the attribute when created. Do not manually add individual sysfs files.
Yes, I know the existing code does this, so it's not really your fault, but let's not persist in making this code even messier. Convert to a group first and then your new files will be added automagically without having to care about anything here at all.
thanks,
greg k-h
PATCH 2/12 PCI: hotplug: expose APIs from pciehp driver
In reply to Tianfei ZhangWhen a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed by disabling the link to avoid PCIe errors while the device is not present. Also, re-enabling the link and rescan the PCI devices must be performed after loading the new images. Export functions from pciehp driver necessary for removing and reconfiguring the PCI devices below a PCI hotplug bridge.
--- drivers/pci/hotplug/pciehp.h | 2 ++ drivers/pci/hotplug/pciehp_hpc.c | 5 ++++- drivers/pci/hotplug/pciehp_pci.c | 2 ++ 3 files changed, 8 insertions(+), 1 deletion(-)
drivers/pci/hotplug/pciehp.h +2 -0
@@ -194,6 +194,8 @@ int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status);int pciehp_slot_reset (struct pcie_device *dev); +int pciehp_link_enable (struct controller *ctrl); +static inline const char *slot_name (struct controller *ctrl) {return hotplug_slot_name (&ctrl->hotplug_slot);
drivers/pci/hotplug/pciehp_hpc.c +4 -1
@@ -328,6 +328,7 @@ int pciehp_check_link_status(struct controller *ctrl)return 0 ; } +EXPORT_SYMBOL_NS_GPL (pciehp_check_link_status,PCIEHP );static int __pciehp_link_set (struct controller *ctrl,bool enable) {
@@ -346,10 +347,11 @@ static int __pciehp_link_set(struct controller *ctrl, bool enable)return 0 ; } -static int pciehp_link_enable (struct controller *ctrl) +int pciehp_link_enable (struct controller *ctrl) {return __pciehp_link_set (ctrl, true); } +EXPORT_SYMBOL_NS_GPL (pciehp_link_enable,PCIEHP );int pciehp_get_raw_indicator_status (struct hotplug_slot *hotplug_slot,u8 *status)
@@ -482,6 +484,7 @@ int pciehp_query_power_fault(struct controller *ctrl)pcie_capability_read_word (pdev,PCI_EXP_SLTSTA , &slot_status);return !!(slot_status &PCI_EXP_SLTSTA_PFD ); } +EXPORT_SYMBOL_NS_GPL (pciehp_query_power_fault,PCIEHP );int pciehp_set_raw_indicator_status (struct hotplug_slot *hotplug_slot,u8 status)
drivers/pci/hotplug/pciehp_pci.c +2 -0
@@ -69,6 +69,7 @@ int pciehp_configure_device(struct controller *ctrl)pci_unlock_rescan_remove ();return ret; } +EXPORT_SYMBOL_NS_GPL (pciehp_configure_device,PCIEHP );/** * pciehp_unconfigure_device() - remove PCI devices below a hotplug bridge
@@ -120,3 +121,4 @@ void pciehp_unconfigure_device(struct controller *ctrl, bool presence)pci_unlock_rescan_remove (); } +EXPORT_SYMBOL_NS_GPL (pciehp_unconfigure_device,PCIEHP );
Signature · 1 line
2.38.1
PATCH 3/12 PCI: hotplug: add and expose link disable API
In reply to Tianfei ZhangWhen a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors while the device is not present. Also, re-probing and rescan the PCI devices must be performed after loading the new images. Export functions from pciehp driver necessary for disable and enable the PCI link of a PCI hotplug bridge.
--- drivers/pci/hotplug/pciehp.h | 1 + drivers/pci/hotplug/pciehp_hpc.c | 6 ++++++ 2 files changed, 7 insertions(+)
drivers/pci/hotplug/pciehp.h +1 -0
@@ -195,6 +195,7 @@ int pciehp_get_raw_indicator_status(struct hotplug_slot *h_slot, u8 *status);int pciehp_slot_reset (struct pcie_device *dev);int pciehp_link_enable (struct controller *ctrl); +int pciehp_link_disable (struct controller *ctrl);static inline const char *slot_name (struct controller *ctrl) {
drivers/pci/hotplug/pciehp_hpc.c +6 -0
@@ -353,6 +353,12 @@ int pciehp_link_enable(struct controller *ctrl) }EXPORT_SYMBOL_NS_GPL (pciehp_link_enable,PCIEHP ); +int pciehp_link_disable (struct controller *ctrl) +{ +return __pciehp_link_set (ctrl, false); +} +EXPORT_SYMBOL_NS_GPL (pciehp_link_disable,PCIEHP ); +int pciehp_get_raw_indicator_status (struct hotplug_slot *hotplug_slot,u8 *status) {
Signature · 1 line
2.38.1
PATCH 4/12 PCI: hotplug: add FPGA PCI hotplug manager driver
In reply to Tianfei ZhangAfter burning a new FPGA/BMC image, the driver should stop the current running FPGA image and load a new image from the flash to FPGA. Before reloading a new image, the driver needs to remove all of PCI devices like PFs/VFs and as well as any other types of devices (platform, etc.) defined within the FPGA which are running in the old image. To help manage the PCIe-based FPGA card, leverage the PCIe hotplug framework to implement the card management during loading the new FPGA image.
Introduce new APIs to register/unregister a PCI device into PCI hotplug core. The fpgahp driver instances a hotplug controller and then registers into pci hotplug core which leverages the hotplug_slot_ops callbacks to manage the FPGA card.
The new data structure fpgahp_manager is used for a fpga hotplug manager instance. The fpgahp_manager has some callbacks in fpgahp_manager_ops. The hotplug_prepare callback does some preparations, like removing sub-devices below the PCI device to avoid data corruption during the hotplug.
--- MAINTAINERS | 8 + drivers/pci/hotplug/Kconfig | 14 ++ drivers/pci/hotplug/Makefile | 1 + drivers/pci/hotplug/fpgahp.c | 269 ++++++++++++++++++++++++++++ include/linux/fpga/fpgahp_manager.h | 62 +++++++ 5 files changed, 354 insertions(+) create mode 100644 drivers/pci/hotplug/fpgahp.c create mode 100644 include/linux/fpga/fpgahp_manager.h
MAINTAINERS +8 -0
@@ -8163,6 +8163,14 @@ F: drivers/uio/uio_dfl.c F: include/linux/dfl.h F: include/uapi/linux/fpga-dfl.h +FPGA PCI Hotplug Driver +M: Tianfei Zhang <[email protected]> +L: [email protected] +L: [email protected] +S: Maintained +F: drivers/pci/hotplug/fpgahp.c +F: include/linux/fpga/fpgahp_manager.h + FPGA MANAGER FRAMEWORK M: Moritz Fischer <[email protected]> M: Wu Hao <[email protected]>
drivers/pci/hotplug/Kconfig +14 -0
@@ -61,6 +61,20 @@ config HOTPLUG_PCI_ACPI When in doubt, say N. +config HOTPLUG_PCI_FPGA + tristate "FPGA PCI Hotplug Manager Driver" + depends on HOTPLUG_PCI_PCIE + help + Select this option to enable FPGA hotplug driver for PCIe-based + Field-Programmable Gate Array (FPGA) solutions. This driver provides + sysfs files for userspace applications to manager the FPGA card like + load a new FPGA image, reset the FPGA card. + + To compile this driver as a module, choose M here: the + module will be called fpgahp. + + When in doubt, say N. + config HOTPLUG_PCI_ACPI_IBM tristate "ACPI PCI Hotplug driver IBM extensions" depends on HOTPLUG_PCI_ACPI
drivers/pci/hotplug/Makefile +1 -0
@@ -19,6 +19,7 @@ obj-$(CONFIG_HOTPLUG_PCI_POWERNV) += pnv-php.o obj-$(CONFIG_HOTPLUG_PCI_RPA) += rpaphp.o obj-$(CONFIG_HOTPLUG_PCI_RPA_DLPAR) += rpadlpar_io.o obj-$(CONFIG_HOTPLUG_PCI_ACPI) += acpiphp.o +obj-$(CONFIG_HOTPLUG_PCI_FPGA) += fpgahp.o obj-$(CONFIG_HOTPLUG_PCI_S390) += s390_pci_hpc.o # acpiphp_ibm extends acpiphp, so should be linked afterwards.
drivers/pci/hotplug/fpgahp.c new file +269 -0
269 lines not on this page · raw message
include/linux/fpga/fpgahp_manager.h new file +62 -0
62 lines not on this page · raw message
Signature · 1 line
2.38.1
PATCH 5/12 fpga: dfl: register dfl-pci device into fpgahph driver
In reply to Tianfei ZhangAdd a registration of dfl-pci device into fpgahp driver by fpgahp_register() API.
For Intel N3000 Card, FPGA devices like PFs/VFs and some ethernet controllers are connected with a PCI switch, so the hotplug bridge is the root hub of PCI device. This patch instances this hotplug bridge as a hotplug controller.
--- drivers/fpga/Kconfig | 1 + drivers/fpga/dfl-pci.c | 77 ++++++++++++++++++++++++++++++++++++++---- drivers/fpga/dfl.h | 2 ++ 3 files changed, 74 insertions(+), 6 deletions(-)
drivers/fpga/Kconfig +1 -0
@@ -213,6 +213,7 @@ config FPGA_DFL_NIOS_INTEL_PAC_N3000 config FPGA_DFL_PCI tristate "FPGA DFL PCIe Device Driver" depends on PCI && FPGA_DFL + depends on HOTPLUG_PCI_FPGA help Select this option to enable PCIe driver for PCIe-based Field-Programmable Gate Array (FPGA) solutions which implement
drivers/fpga/dfl-pci.c +71 -6
135 lines not on this page · raw message
drivers/fpga/dfl.h +2 -0
@@ -469,6 +469,7 @@ void dfl_fpga_enum_info_free(struct dfl_fpga_enum_info *info);* @fme_dev: FME feature device under this container device. * @lock: mutex lock to protect the port device list. * @port_dev_list: list of all port feature devices under this container device. +* @fpgahp_mgr: fpga hotplug manager. * @released_port_num: released port number under this container device. */ struct dfl_fpga_cdev {
@@ -477,6 +478,7 @@ struct dfl_fpga_cdev {struct device *fme_dev;struct mutex lock;struct list_head port_dev_list; +struct fpgahp_manager *fpgahp_mgr;int released_port_num; };
Signature · 1 line
2.38.1
PATCH 6/12 driver core: expose device_is_ancestor() API
In reply to Tianfei ZhangExposes device_is_ancestor() API which can be used for check the device is the target device's ancestor or not.
--- drivers/base/core.c | 3 ++- include/linux/device.h | 1 + 2 files changed, 3 insertions(+), 1 deletion(-)
drivers/base/core.c +2 -1
@@ -262,7 +262,7 @@ static void device_link_remove_from_lists(struct device_link *link) }#endif /* !CONFIG_SRCU */ -static bool device_is_ancestor (struct device *dev,struct device *target) +bool device_is_ancestor (struct device *dev,struct device *target) {while (target->parent) { target = target->parent;
@@ -271,6 +271,7 @@ static bool device_is_ancestor(struct device *dev, struct device *target) }return false; } +EXPORT_SYMBOL_GPL (device_is_ancestor);/** * device_is_dependent - Check if one device depends on another one
include/linux/device.h +1 -0
@@ -909,6 +909,7 @@ int device_move(struct device *dev, struct device *new_parent,int device_change_owner (struct device *dev,kuid_t kuid,kgid_t kgid);const char *device_get_devnode (struct device *dev,umode_t *mode,kuid_t *uid,kgid_t *gid,const char **tmp); +bool device_is_ancestor (struct device *dev,struct device *target);int device_is_dependent (struct device *dev,void *target);static inline bool device_supports_offline (struct device *dev)
Signature · 1 line
2.38.1
PATCH 7/12 PCI: hotplug: add register/unregister function for BMC device
In reply to Tianfei ZhangIntroduce new APIs to register/unregister a BMC device instance for fpgahp driver.
The fpgahp_bmc_device data structure represents a FPGA BMC device which has some specific callbacks for FPGA hotplug operations. The first one is available_images, which will return a list of available images for FPGA. The second one is the image_load, which will provide a reload trigger operation to BMC via secure update driver for Intel PAC N3000 Card.
--- drivers/pci/hotplug/fpgahp.c | 78 +++++++++++++++++++++++++++++ include/linux/fpga/fpgahp_manager.h | 38 ++++++++++++++ 2 files changed, 116 insertions(+)
drivers/pci/hotplug/fpgahp.c +78 -0
@@ -34,6 +34,84 @@ static void fpgahp_add_fhpc(struct fpgahp_controller *fhpc)mutex_unlock (&fhpc_lock); } +static struct fpgahp_bmc_device *fpgahp_find_bmc (struct device *bmc_device) +{ +struct fpgahp_bmc_device *bmc =NULL ; +struct fpgahp_controller *fhpc; + +mutex_lock (&fhpc_lock); + +list_for_each_entry (fhpc, &fhpc_list, node) { +struct fpgahp_manager *mgr = &fhpc->mgr; +struct pci_dev *pcidev = mgr->priv; + +if (!mgr->registered) +continue ; + +/* +* BMC device (like security dev) is a subordinate device under +* PCI device, so check if the parent device of BMC device recursively +*/ +if (device_is_ancestor (&pcidev->dev, bmc_device)) { + bmc = &mgr->bmc; +break ; + } + } + +mutex_unlock (&fhpc_lock); + +return bmc; +} + +/** +* fpgahp_bmc_device_register - register FPGA BMC device into fpgahp driver +* @ops: pointer to structure of fpgahp manager ops +* @dev: device struct of BMC device +* @priv: private data for FPGA device +* +* Return: pointer to struct fpgahp_manager pointer or ERR_PTR() +*/ +struct fpgahp_bmc_device * +fpgahp_bmc_device_register (const struct fpgahp_bmc_ops *ops, +struct device *dev,void *priv) +{ +struct fpgahp_manager *mgr; +struct fpgahp_bmc_device *bmc; + +if (!ops) +return ERR_PTR (-EINVAL ); + + bmc =fpgahp_find_bmc (dev); +if (!bmc) +return ERR_PTR (-EINVAL ); + + mgr =to_fpgahp_mgr (bmc); + +mutex_lock (&mgr->lock); + bmc->priv = priv; + bmc->device = dev; + bmc->ops = ops; + bmc->registered = true; +mutex_unlock (&mgr->lock); + +return bmc; +} +EXPORT_SYMBOL_NS_GPL (fpgahp_bmc_device_register,FPGAHP ); + +/** +* fpgahp_bmc_device_unregister - unregister FPGA BMC device from fpgahp driver +* @bmc: point to the fpgahp_bmc_device +*/ +void fpgahp_bmc_device_unregister (struct fpgahp_bmc_device *bmc) +{ +struct fpgahp_manager *mgr =to_fpgahp_mgr (bmc); + +mutex_lock (&mgr->lock); + bmc->registered = false; +mutex_unlock (&mgr->lock); +} +EXPORT_SYMBOL_NS_GPL (fpgahp_bmc_device_unregister,FPGAHP ); +static int fpgahp_init_controller (struct controller *ctrl,struct pcie_device *dev) {struct pci_dev *hotplug_bridge = dev->port;
include/linux/fpga/fpgahp_manager.h +38 -0
@@ -11,6 +11,33 @@struct pci_dev ;struct fpgahp_manager ; +struct fpgahp_bmc_device ; + +/** +* struct fpgahp_bmc_ops - fpga hotplug BMC specific operations +* @available_images: Required: available images for fpgahp trigger +* @image_trigger: Required: trigger the image reload on BMC +*/ +struct fpgahp_bmc_ops { +ssize_t (*available_images)(struct fpgahp_bmc_device *bmc,char *buf); +int (*image_trigger)(struct fpgahp_bmc_device *bmc,const char *buf, +u32 *wait_time_msec); +}; + +/** +* struct fpgahp_bmc_device - represent a fpga hotplug BMC device +* +* @ops: ops of this fpgahp_bmc_device +* @priv: private data for fpgahp_bmc_device +* @device: device of BMC device +* @registered: register status +*/ +struct fpgahp_bmc_device { +const struct fpgahp_bmc_ops *ops; +void *priv; +struct device *device; +bool registered; +};/** * struct fpgahp_manager_ops - fpgahp manager specific operations
@@ -43,6 +70,7 @@ enum fpgahp_manager_states {* @ops: ops of this fpgahp_manager * @state: the status of fpgahp_manager * @name: name of the fpgahp_manager +* @bmc: fpgahp BMC device * @registered: register status */ struct fpgahp_manager {
@@ -51,12 +79,22 @@ struct fpgahp_manager {const struct fpgahp_manager_ops *ops;enum fpgahp_manager_states state;const char *name; +struct fpgahp_bmc_device bmc;bool registered; }; +static inline struct fpgahp_manager *to_fpgahp_mgr (struct fpgahp_bmc_device *bmc) +{ + return container_of(bmc, struct fpgahp_manager, bmc); +} +struct fpgahp_manager *fpgahp_register (struct pci_dev *hotplug_bridge,const char *name,const struct fpgahp_manager_ops *ops,void *priv);void fpgahp_unregister (struct fpgahp_manager *mgr); +struct fpgahp_bmc_device *fpgahp_bmc_device_register (const struct fpgahp_bmc_ops *ops, +struct device *dev,void *priv); +void fpgahp_bmc_device_unregister (struct fpgahp_bmc_device *bmc); +#endif
Signature · 1 line
2.38.1
PATCH 8/12 fpga: m10bmc-sec: register BMC device into fpgahp driver
In reply to Tianfei ZhangAdd a registration of Intel M10 BMC security update device into fpgahp driver by fpgahp_bmc_device_register() API.
--- drivers/fpga/Kconfig | 1 + drivers/fpga/intel-m10-bmc-sec-update.c | 110 ++++++++++++++++++++++++ 2 files changed, 111 insertions(+)
drivers/fpga/Kconfig +1 -0
@@ -248,6 +248,7 @@ config FPGA_MGR_VERSAL_FPGA config FPGA_M10_BMC_SEC_UPDATE tristate "Intel MAX10 BMC Secure Update driver" depends on MFD_INTEL_M10_BMC + depends on HOTPLUG_PCI_FPGA select FW_LOADER select FW_UPLOAD help
drivers/fpga/intel-m10-bmc-sec-update.c +110 -0
159 lines not on this page · raw message
Signature · 1 line
2.38.1
PATCH 9/12 fpga: dfl: remove non-reserved devices
In reply to Tianfei ZhangIntroduce a new concept of non-reserved devices and reserved devices on DFL bus. Reserved devices mean that devices under DFL bus will be reserved before triggering the image load, because those devices are provided a communication link to BMC during the trigger, for example SPI/NIOS private feature device on Intel PAC N3000 card, security update device. On the other hand, the reset of devices are non-reserved devices, which will be removed before triggering the image load.
After loading a new image, all of reserved and non-reserved devices will be removed.
--- drivers/fpga/dfl-pci.c | 18 +++++++++++++ drivers/fpga/dfl.c | 58 ++++++++++++++++++++++++++++++++++++++++++ drivers/fpga/dfl.h | 2 ++ 3 files changed, 78 insertions(+)
drivers/fpga/dfl-pci.c +18 -0
@@ -42,7 +42,24 @@ struct cci_drvdata {struct dfl_fpga_cdev *cdev;/* container device */ }; +static int dfl_hp_prepare (struct fpgahp_manager *mgr) +{ +struct pci_dev *pcidev = mgr->priv; +struct cci_drvdata *drvdata =pci_get_drvdata (pcidev); +struct dfl_fpga_cdev *cdev = drvdata->cdev; +struct platform_device *fme =to_platform_device (cdev->fme_dev); + +/* remove all of non-reserved fme devices of PF0 */ +dfl_reload_remove_non_reserved_devs (fme, mgr->bmc.device); + +/* remove all AFU devices of PF0 */ +dfl_reload_remove_afus (cdev); + +return 0 ; +} +static const struct fpgahp_manager_ops fpgahp_ops = { + .hotplug_prepare = dfl_hp_prepare, };static void __iomem *cci_pci_ioremap_bar0 (struct pci_dev *pcidev)
@@ -529,3 +546,4 @@ MODULE_DESCRIPTION("FPGA DFL PCIe Device Driver");MODULE_AUTHOR ("Intel Corporation" );MODULE_LICENSE ("GPL v2" );MODULE_IMPORT_NS (FPGAHP ); +MODULE_IMPORT_NS (DFL_CORE );
drivers/fpga/dfl.c +58 -0
70 lines not on this page · raw message
drivers/fpga/dfl.h +2 -0
@@ -485,6 +485,8 @@ struct dfl_fpga_cdev {struct dfl_fpga_cdev *dfl_fpga_feature_devs_enumerate (struct dfl_fpga_enum_info *info);void dfl_fpga_feature_devs_remove (struct dfl_fpga_cdev *cdev); +void dfl_reload_remove_afus (struct dfl_fpga_cdev *cdev); +void dfl_reload_remove_non_reserved_devs (struct platform_device *pdev,struct device *trigger_dev);/* * need to drop the device reference with put_device() after use port platform
Signature · 1 line
2.38.1
PATCH 10/12 PCI: hotplug: implement the hotplug_slot_ops callback for fpgahp
In reply to Tianfei ZhangImplement the image_load and available_images callback functions for fpgahp driver. This patch leverages some APIs from pciehp driver to implement the device reconfiguration below the PCI hotplug bridge.
Here are the steps for a process of image load.
1. remove all PFs and VFs except the PF0.
2. remove all non-reserved devices of PF0.
3. trigger a image load via BMC.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under PF0 and PCI devices below the hotplug bridge.
6. wait for image load done via BMC, e.g. 10s.
7. re-enable the link of the hotplug bridge.
8. re-enumerate PCI devices below the hotplug bridge.
--- Documentation/ABI/testing/sysfs-driver-fpgahp | 21 ++ MAINTAINERS | 1 + drivers/pci/hotplug/fpgahp.c | 179 ++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-fpgahp
Documentation/ABI/testing/sysfs-driver-fpgahp new file +21 -0
@@ -0,0 +1,21 @@ +What: /sys/bus/pci/slots/X-X/available_images +Date: May 2023 +KernelVersion: 6.3 +Contact: Tianfei Zhang <[email protected]> +Description: Read-only. This file returns a space separated list of + key words that may be written into the image_load file + described below. These keywords decribe an FPGA, BMC, + or firmware image in FLASH or EEPROM storage that may + be loaded. + +What: /sys/bus/pci/slots/X-X/image_load +Date: May 2023 +KernelVersion: 6.3 +Contact: Tianfei Zhang <[email protected]> +Description: Write-only. A key word may be written to this file to + trigger a new image loading of an FPGA, BMC, or firmware + image from FLASH or EEPROM. Refer to the available_images + file for a list of supported key words for the underlying + device. + Writing an unsupported string to this file will result in + EINVAL being returned.
MAINTAINERS +1 -0
@@ -8168,6 +8168,7 @@ M: Tianfei Zhang <[email protected]> L: [email protected] L: [email protected] S: Maintained +F: Documentation/ABI/testing/sysfs-driver-fpgahp F: drivers/pci/hotplug/fpgahp.c F: include/linux/fpga/fpgahp_manager.h
drivers/pci/hotplug/fpgahp.c +179 -0
208 lines not on this page · raw message
Signature · 1 line
2.38.1
Greg KH
maintainerRe: [PATCH v1 10/12] PCI: hotplug: implement the hotplug_slot_ops callback for fpgahp
Quoted 30 lines · Tianfei Zhang
Implement the
image_loadandavailable_imagescallback functions for fpgahp driver. This patch leverages some APIs from pciehp driver to implement the device reconfiguration below the PCI hotplug bridge.Here are the steps for a process of image load.
1. remove all PFs and VFs except the PF0.
2. remove all non-reserved devices of PF0.
3. trigger a image load via BMC.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under PF0 and PCI devices below the hotplug bridge.
6. wait for image load done via BMC, e.g. 10s.
7. re-enable the link of the hotplug bridge.
8. re-enumerate PCI devices below the hotplug bridge.Signed-off-by Tianfei Zhang <[email protected]>--- Documentation/ABI/testing/sysfs-driver-fpgahp | 21 ++ MAINTAINERS | 1 + drivers/pci/hotplug/fpgahp.c | 179 ++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-fpgahpDocumentation/ABI/testing/sysfs-driver-fpgahp new file +0
-0
Documentation/ABI/testing/sysfs-driver-fpgahp line 9
Quoted 9 lines
Documentation/ABI/testing/sysfs-driver-fpgahp new file +9
-0@@ -0,0 +1,21 @@ +What: /sys/bus/pci/slots/X-X/available_images +Date: May 2023 +KernelVersion: 6.3 +Contact: Tianfei Zhang <[email protected]> +Description: Read-only. This file returns a space separated list of + key words that may be written into the image_load file + described below. These keywords decribe an FPGA, BMC, + or firmware image in FLASH or EEPROM storage that may + be loaded.
No, sysfs is "one value per file", why is this a list?
And what exactly defines the values in this list?
Documentation/ABI/testing/sysfs-driver-fpgahp line 21
Quoted 12 lines
Documentation/ABI/testing/sysfs-driver-fpgahp new file +12
-0+ +What: /sys/bus/pci/slots/X-X/image_load +Date: May 2023 +KernelVersion: 6.3 +Contact: Tianfei Zhang <[email protected]> +Description: Write-only. A key word may be written to this file to + trigger a new image loading of an FPGA, BMC, or firmware + image from FLASH or EEPROM. Refer to the available_images + file for a list of supported key words for the underlying + device. + Writing an unsupported string to this file will result in + EINVAL being returned.
Why is this a separate file from the "read the list" file?
That feels wrong.
thanks,
greg k-h
Re: [PATCH v1 10/12] PCI: hotplug: implement the hotplug_slot_ops callback for fpgahp
Quoted 44 lines · Greg KH
Quoted 30 lines · Tianfei Zhang
Implement the
image_loadandavailable_imagescallback functions for fpgahp driver. This patch leverages some APIs from pciehp driver to implement the device reconfiguration below the PCI hotplug bridge.Here are the steps for a process of image load.
1. remove all PFs and VFs except the PF0.
2. remove all non-reserved devices of PF0.
3. trigger a image load via BMC.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under PF0 and PCI devices below the hotplug bridge.
6. wait for image load done via BMC, e.g. 10s.
7. re-enable the link of the hotplug bridge.
8. re-enumerate PCI devices below the hotplug bridge.Signed-off-by Tianfei Zhang <[email protected]>--- Documentation/ABI/testing/sysfs-driver-fpgahp | 21 ++ MAINTAINERS | 1 + drivers/pci/hotplug/fpgahp.c | 179 ++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-fpgahpDocumentation/ABI/testing/sysfs-driver-fpgahp new file +0
-0Documentation/ABI/testing/sysfs-driver-fpgahp line 9
Quoted 9 lines
Documentation/ABI/testing/sysfs-driver-fpgahp new file +9
-0@@ -0,0 +1,21 @@ +What: /sys/bus/pci/slots/X-X/available_images +Date: May 2023 +KernelVersion: 6.3 +Contact: Tianfei Zhang <[email protected]> +Description: Read-only. This file returns a space separated list of + key words that may be written into the image_load file + described below. These keywords decribe an FPGA, BMC, + or firmware image in FLASH or EEPROM storage that may + be loaded.No, sysfs is "one value per file", why is this a list?
And what exactly defines the values in this list?
Quoted 13 lines
Documentation/ABI/testing/sysfs-driver-fpgahp line 21
Quoted 12 lines
Documentation/ABI/testing/sysfs-driver-fpgahp new file +12
-0+ +What: /sys/bus/pci/slots/X-X/image_load +Date: May 2023 +KernelVersion: 6.3 +Contact: Tianfei Zhang <[email protected]> +Description: Write-only. A key word may be written to this file to + trigger a new image loading of an FPGA, BMC, or firmware + image from FLASH or EEPROM. Refer to the available_images + file for a list of supported key words for the underlying + device. + Writing an unsupported string to this file will result in + EINVAL being returned.Why is this a separate file from the "read the list" file?
The intended usage is like this:
$ cat available_images bmc_factory bmc_user fpga_factory fpga_user1 fpga_user2 $ echo bmc_user > image_load
This specifies which image stored in flash that you want to have activated on the device.
An existing example of something like this is in the tracing code:available_tracers and current_tracer
Would it be preferable to just create a file for each possible image, and echo 1 to trigger the event? (echo 1 > bmc_user)
Thanks,
- Russ
Quoted 5 lines
That feels wrong.
thanks,
greg k-h
Greg KH
maintainerRe: [PATCH v1 10/12] PCI: hotplug: implement the hotplug_slot_ops callback for fpgahp
Quoted 67 lines · Russ Weight
Quoted 44 lines · Greg KH
Quoted 30 lines · Tianfei Zhang
Implement the
image_loadandavailable_imagescallback functions for fpgahp driver. This patch leverages some APIs from pciehp driver to implement the device reconfiguration below the PCI hotplug bridge.Here are the steps for a process of image load.
1. remove all PFs and VFs except the PF0.
2. remove all non-reserved devices of PF0.
3. trigger a image load via BMC.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under PF0 and PCI devices below the hotplug bridge.
6. wait for image load done via BMC, e.g. 10s.
7. re-enable the link of the hotplug bridge.
8. re-enumerate PCI devices below the hotplug bridge.Signed-off-by Tianfei Zhang <[email protected]>--- Documentation/ABI/testing/sysfs-driver-fpgahp | 21 ++ MAINTAINERS | 1 + drivers/pci/hotplug/fpgahp.c | 179 ++++++++++++++++++ 3 files changed, 201 insertions(+) create mode 100644 Documentation/ABI/testing/sysfs-driver-fpgahpDocumentation/ABI/testing/sysfs-driver-fpgahp new file +0
-0Documentation/ABI/testing/sysfs-driver-fpgahp line 9
Quoted 9 lines
Documentation/ABI/testing/sysfs-driver-fpgahp new file +9
-0@@ -0,0 +1,21 @@ +What: /sys/bus/pci/slots/X-X/available_images +Date: May 2023 +KernelVersion: 6.3 +Contact: Tianfei Zhang <[email protected]> +Description: Read-only. This file returns a space separated list of + key words that may be written into the image_load file + described below. These keywords decribe an FPGA, BMC, + or firmware image in FLASH or EEPROM storage that may + be loaded.No, sysfs is "one value per file", why is this a list?
And what exactly defines the values in this list?
Quoted 13 lines
Documentation/ABI/testing/sysfs-driver-fpgahp line 21
Quoted 12 lines
Documentation/ABI/testing/sysfs-driver-fpgahp new file +12
-0+ +What: /sys/bus/pci/slots/X-X/image_load +Date: May 2023 +KernelVersion: 6.3 +Contact: Tianfei Zhang <[email protected]> +Description: Write-only. A key word may be written to this file to + trigger a new image loading of an FPGA, BMC, or firmware + image from FLASH or EEPROM. Refer to the available_images + file for a list of supported key words for the underlying + device. + Writing an unsupported string to this file will result in + EINVAL being returned.Why is this a separate file from the "read the list" file?
The intended usage is like this:
$ cat available_images bmc_factory bmc_user fpga_factory fpga_user1 fpga_user2 $ echo bmc_user > image_load
Quoted 8 lines
This specifies which image stored in flash that you want to have activated on the device.
An existing example of something like this is in the tracing code:
available_tracersandcurrent_tracerWould it be preferable to just create a file for each possible image, and echo 1 to trigger the event? (echo 1 >
bmc_user)
That would make things much more simpler overall and not force people to have to parse a sysfs file, which is the main reason we created sysfs in the first place.
thanks,
greg k-h
PATCH 11/12 fpga: m10bmc-sec: add m10bmc_sec_retimer_load callback
In reply to Tianfei ZhangCreate m10bmc_sec_retimer_load() callback function to provide a trigger to update a new retimer (Intel C827 Ethernet transceiver) firmware on Intel PAC N3000 Card.
--- drivers/fpga/intel-m10-bmc-sec-update.c | 136 ++++++++++++++++++++++++ include/linux/mfd/intel-m10-bmc.h | 31 ++++++ 2 files changed, 167 insertions(+)
drivers/fpga/intel-m10-bmc-sec-update.c +136 -0
@@ -291,6 +291,137 @@ static int m10bmc_sec_bmc_image_load_1(struct m10bmc_sec *sec)return m10bmc_sec_bmc_image_load (sec,1 ); } +static int trigger_retimer_eeprom_load (struct m10bmc_sec *sec) +{ +struct intel_m10bmc *m10bmc = sec->m10bmc; +unsigned int val; +int ret; + + ret =regmap_update_bits (m10bmc->regmap,M10BMC_SYS_BASE +M10BMC_DOORBELL , +DRBL_PKVL_EEPROM_LOAD_SEC ,DRBL_PKVL_EEPROM_LOAD_SEC ); +if (ret) +return ret; + +/* +* If the current NIOS FW supports this retimer update feature, then +* it will clear the same PKVL_EEPROM_LOAD bit in 2 seconds. Otherwise +* the driver needs to clear the PKVL_EEPROM_LOAD bit manually and +* return an error code. +*/ + ret =regmap_read_poll_timeout (m10bmc->regmap,M10BMC_SYS_BASE +M10BMC_DOORBELL , + val, !(val &DRBL_PKVL_EEPROM_LOAD_SEC ), +M10BMC_PKVL_LOAD_INTERVAL_US ,M10BMC_PKVL_LOAD_TIMEOUT_US ); +if (ret == -ETIMEDOUT ) { +dev_err (sec->dev,"PKVL_EEPROM_LOAD clear timeout\n" ); +regmap_update_bits (m10bmc->regmap,M10BMC_SYS_BASE +M10BMC_DOORBELL , +DRBL_PKVL_EEPROM_LOAD_SEC ,0 ); + }else if (ret) { +dev_err (sec->dev,"EEPROM_LOAD poll error %d\n" , ret); + } + +return ret; +} + +static int poll_retimer_eeprom_load_done (struct m10bmc_sec *sec) +{ +struct intel_m10bmc *m10bmc = sec->m10bmc; +unsigned int doorbell; +int ret; + +/* +* RSU_STAT_PKVL_REJECT indicates that the current image is +* already programmed. RSU_PROG_PKVL_PROM_DONE that the firmware +* update process has finished, but does not necessarily indicate +* a successful update. +*/ + ret =regmap_read_poll_timeout (m10bmc->regmap,M10BMC_SYS_BASE +M10BMC_DOORBELL , + doorbell, (rsu_prog (doorbell) ==RSU_PROG_PKVL_PROM_DONE ) || + (rsu_stat (doorbell) ==RSU_STAT_PKVL_REJECT ), +M10BMC_PKVL_PRELOAD_INTERVAL_US , +M10BMC_PKVL_PRELOAD_TIMEOUT_US ); +if (ret) { +if (ret == -ETIMEDOUT ) +dev_err (sec->dev, +"Doorbell check timeout, last value 0x%08x\n" , doorbell); +else +dev_err (sec->dev,"Doorbell poll error\n" ); +return ret; + } + +if (rsu_stat (doorbell) ==RSU_STAT_PKVL_REJECT ) { +dev_err (sec->dev,"Duplicate image rejected\n" ); +return -EEXIST ; + } + +return 0 ; +} + +static int poll_retimer_preload_done (struct m10bmc_sec *sec) +{ +struct intel_m10bmc *m10bmc = sec->m10bmc; +unsigned int val; +int ret; + +/* +* Wait for the updated firmware to be loaded by the PKVL device +* and confirm that the updated firmware is operational +*/ + ret =regmap_read_poll_timeout (m10bmc->regmap, +M10BMC_SYS_BASE +M10BMC_PKVL_POLL_CTRL , val, + (val &M10BMC_PKVL_PRELOAD ) ==M10BMC_PKVL_PRELOAD , +M10BMC_PKVL_PRELOAD_INTERVAL_US , +M10BMC_PKVL_PRELOAD_TIMEOUT_US ); +if (ret) { +dev_err (sec->dev,"M10BMC_PKVL_PRELOAD poll error %d\n" , ret); +return ret; + } + +if ((val &M10BMC_PKVL_UPG_STATUS_MASK ) !=M10BMC_PKVL_UPG_STATUS_GOOD ) { +dev_err (sec->dev,"Error detected during upgrade\n" ); +return -EIO ; + } + +return 0 ; +} + +static int retimer_check_idle (struct m10bmc_sec *sec) +{ +u32 doorbell; +int ret; + + ret =m10bmc_sys_read (sec->m10bmc,M10BMC_DOORBELL , &doorbell); +if (ret) +return -EIO ; + +if (rsu_prog (doorbell) !=RSU_PROG_IDLE && +rsu_prog (doorbell) !=RSU_PROG_RSU_DONE && +rsu_prog (doorbell) !=RSU_PROG_PKVL_PROM_DONE ) { +log_error_regs (sec, doorbell); +return -EBUSY ; + } + +return 0 ; +} + +static int m10bmc_sec_retimer_eeprom_load (struct m10bmc_sec *sec) +{ +int ret; + + ret =retimer_check_idle (sec); +if (ret) +return ret; + + ret =trigger_retimer_eeprom_load (sec); +if (ret) +return ret; + + ret =poll_retimer_eeprom_load_done (sec); +if (ret) +return ret; + +return poll_retimer_preload_done (sec); +} +static struct image_load m10bmc_image_load_hndlrs[] = { { .name ="bmc_factory" ,
@@ -302,6 +433,11 @@ static struct image_load m10bmc_image_load_hndlrs[] = { .load_image = m10bmc_sec_bmc_image_load_0, .wait_time_msec = RELOAD_DEFAULT_WAIT_MSECS, }, + { + .name = "retimer_fw", + .load_image = m10bmc_sec_retimer_eeprom_load, + .wait_time_msec = 2 * RELOAD_DEFAULT_WAIT_MSECS, + }, {} };
include/linux/mfd/intel-m10-bmc.h +31 -0
@@ -36,6 +36,37 @@#define M10BMC_VER_PCB_INFO_MSK GENMASK(31, 24)#define M10BMC_VER_LEGACY_INVALID 0xffffffff +/* Retimer related registers, in system register region */ +#define M10BMC_PKVL_POLL_CTRL 0x80 +#define M10BMC_PKVL_A_PRELOAD BIT(16) +#define M10BMC_PKVL_A_PRELOAD_TO BIT(17) +#define M10BMC_PKVL_A_DATA_TOO_BIG BIT(18) +#define M10BMC_PKVL_A_HDR_CKSUM BIT(20) +#define M10BMC_PKVL_B_PRELOAD BIT(24) +#define M10BMC_PKVL_B_PRELOAD_TO BIT(25) +#define M10BMC_PKVL_B_DATA_TOO_BIG BIT(26) +#define M10BMC_PKVL_B_HDR_CKSUM BIT(28) + +#define M10BMC_PKVL_PRELOAD (M10BMC_PKVL_A_PRELOAD | M10BMC_PKVL_B_PRELOAD) +#define M10BMC_PKVL_PRELOAD_TIMEOUT (M10BMC_PKVL_A_PRELOAD_TO | M10BMC_PKVL_B_PRELOAD_TO) +#define M10BMC_PKVL_DATA_TOO_BIG (M10BMC_PKVL_A_DATA_TOO_BIG | M10BMC_PKVL_B_DATA_TOO_BIG) +#define M10BMC_PKVL_HDR_CHECKSUM (M10BMC_PKVL_A_HDR_CKSUM | M10BMC_PKVL_B_HDR_CKSUM) + +#define M10BMC_PKVL_UPG_STATUS_MASK \ + (M10BMC_PKVL_PRELOAD | \ + M10BMC_PKVL_PRELOAD_TIMEOUT | \ + M10BMC_PKVL_DATA_TOO_BIG | \ + M10BMC_PKVL_HDR_CHECKSUM) +#define M10BMC_PKVL_UPG_STATUS_GOOD (M10BMC_PKVL_PRELOAD | M10BMC_PKVL_HDR_CHECKSUM) + +/* interval 100ms and timeout 2s */ +#define M10BMC_PKVL_LOAD_INTERVAL_US (100 * USEC_PER_MSEC) +#define M10BMC_PKVL_LOAD_TIMEOUT_US (2 * USEC_PER_SEC) + +/* interval 100ms and timeout 30s */ +#define M10BMC_PKVL_PRELOAD_INTERVAL_US (100 * USEC_PER_MSEC) +#define M10BMC_PKVL_PRELOAD_TIMEOUT_US (30 * USEC_PER_SEC) +/* Secure update doorbell register, in system register region */ #define M10BMC_DOORBELL 0x400
Signature · 1 line
2.38.1
Re: [PATCH v1 11/12] fpga: m10bmc-sec: add m10bmc_sec_retimer_load callback
Quoted 9 lines · Tianfei Zhang
Create
m10bmc_sec_retimer_load()callback function to provide a trigger to update a new retimer (Intel C827 Ethernet transceiver) firmware on Intel PAC N3000 Card.Signed-off-by Russ Weight <[email protected]>Signed-off-by Tianfei Zhang <[email protected]>--- drivers/fpga/intel-m10-bmc-sec-update.c | 136 ++++++++++++++++++++++++ include/linux/mfd/intel-m10-bmc.h | 31 ++++++
Looks mostly fine - no need to send this to me again, thanks:
Signature · 1 line
Lee Jones [李琼斯]
PATCH 12/12 Documentation: fpga: add description of fpgahp driver
In reply to Tianfei ZhangAdd the description of fpgahp driver.
--- Documentation/fpga/fpgahp.rst | 29 +++++++++++++++++++++++++++++ Documentation/fpga/index.rst | 1 + MAINTAINERS | 1 + 3 files changed, 31 insertions(+) create mode 100644 Documentation/fpga/fpgahp.rst
Documentation/fpga/fpgahp.rst new file +29 -0
@@ -0,0 +1,29 @@ +.. SPDX-License-Identifier: GPL-2.0 + +=========================== +FPGA Hotplug Manager Driver +=========================== + +Authors: + +- Tianfei Zhang <[email protected]> + +There are some board managements for PCIe-based FPGA card like burning the entire +image, loading a new FPGA image or BMC firmware in FPGA deployment of data center +or cloud. For example, loading a new FPGA image, the driver needs to remove all of +PCI devices like PFs/VFs and as well as any other types of devices (platform, etc.) +defined within the FPGA. After triggering the image load of the FPGA card via BMC, +the driver reconfigures the PCI bus. The FPGA Hotplug Manager (fpgahp) driver manages +those devices and functions leveraging the PCI hotplug framework to deal with the +reconfiguration of the PCI bus and removal/probe of PCI devices below the FPGA card. + +This fpgahp driver adds 2 new callbacks to extend the hotplug mechanism to +allow selecting and loading a new FPGA image. + + - available_images: Optional: called to return the available images of a FPGA card. + - image_load: Optional: called to load a new image for a FPGA card. + +In general, the fpgahp driver provides some sysfs files:: + + /sys/bus/pci/slots/<X-X>/available_images + /sys/bus/pci/slots/<X-X>/image_load
Documentation/fpga/index.rst +1 -0
@@ -8,6 +8,7 @@ fpga :maxdepth: 1 dfl + fpgahp .. only:: subproject and html
MAINTAINERS +1 -0
@@ -8169,6 +8169,7 @@ L: [email protected] L: [email protected] S: Maintained F: Documentation/ABI/testing/sysfs-driver-fpgahp +F: Documentation/fpga/fpgahp.rst F: drivers/pci/hotplug/fpgahp.c F: include/linux/fpga/fpgahp_manager.h
Signature · 1 line
2.38.1
Re: [PATCH v1 12/12] Documentation: fpga: add description of fpgahp driver
Quoted 17 lines · Tianfei Zhang
+===========================
(quoted diff) +16
-0+FPGA Hotplug Manager Driver +=========================== + +Authors: + +- Tianfei Zhang <[email protected]> + +There are some board managements for PCIe-based FPGA card like burning the entire +image, loading a new FPGA image or BMC firmware in FPGA deployment of data center +or cloud. For example, loading a new FPGA image, the driver needs to remove all of +PCI devices like PFs/VFs and as well as any other types of devices (platform, etc.) +defined within the FPGA. After triggering the image load of the FPGA card via BMC, +the driver reconfigures the PCI bus. The FPGA Hotplug Manager (fpgahp) driver manages +those devices and functions leveraging the PCI hotplug framework to deal with the +reconfiguration of the PCI bus and removal/probe of PCI devices below the FPGA card. +
Review
Quoted 10 lines
(quoted diff) +10
-0+This fpgahp driver adds 2 new callbacks to extend the hotplug mechanism to +allow selecting and loading a new FPGA image. + + - available_images: Optional: called to return the available images of a FPGA card. + - image_load: Optional: called to load a new image for a FPGA card. + +In general, the fpgahp driver provides some sysfs files:: + + /sys/bus/pci/slots/<X-X>/available_images + /sys/bus/pci/slots/<X-X>/image_load
The doc reads a rather confused to me, so I have to make wording improv:
---- >8 ----
Documentation/fpga/fpgahp.rst +15 -15
@@ -8,22 +8,22 @@ Authors: - Tianfei Zhang <[email protected]> -There are some board managements for PCIe-based FPGA card like burning the entire -image, loading a new FPGA image or BMC firmware in FPGA deployment of data center -or cloud. For example, loading a new FPGA image, the driver needs to remove all of -PCI devices like PFs/VFs and as well as any other types of devices (platform, etc.) -defined within the FPGA. After triggering the image load of the FPGA card via BMC, -the driver reconfigures the PCI bus. The FPGA Hotplug Manager (fpgahp) driver manages -those devices and functions leveraging the PCI hotplug framework to deal with the -reconfiguration of the PCI bus and removal/probe of PCI devices below the FPGA card. -This fpgahp driver adds 2 new callbacks to extend the hotplug mechanism to -allow selecting and loading a new FPGA image. +The FPGA Hotplug Manager (fpgahp) manages PCIe-based FPGA card devices. +The PCI bus reconfiguration and device probe for devices below the FPGA +card are done by leveraging the PCI hotplug framework. - - available_images: Optional: called to return the available images of a FPGA card. - - image_load: Optional: called to load a new image for a FPGA card. +The driver can be helpful in device management tasks like burning the entire +image and loading a new FPGA image or BMC firmware in FPGA deployment of data +center or cloud. For example, when loading the image, the driver needs to +remove all of PCI devices like PFs/VFs and as well as any other types of +devices (platform, etc.) defined within the FPGA. After triggering the image +load of the FPGA card via BMC, the driver reconfigures the appropriate PCI bus. -In general, the fpgahp driver provides some sysfs files:: +The driver adds 2 new sysfs callbacks to extend the hotplug mechanism to +allow selecting and loading a new FPGA image: + + - ``/sys/bus/pci/slots/<X-X>/available_images``: list available images for + a FPGA card. + - ``/sys/bus/pci/slots/<X-X>/image_load``: load the image. - /sys/bus/pci/slots/<X-X>/available_images - /sys/bus/pci/slots/<X-X>/image_load
Thanks.
Signature · 1 line
An old man doll... just what I always wanted! - Clara
Hello!
Quoted 7 lines · On Wednesday 18 January 2023 20:35:50 Tianfei Zhang wrote:
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
Quoted 6 lines
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver.
Just I'm thinking about one thing. PCIe cards can support PCIe hotplug mechanism (via standard PCIe capabilities). So what would happen when FPGA based PCIe card is also hotplug-able? Will be there two PCI hotplug drivers/devices (one fpgahp and one pciehp)? Or just one and which?
Quoted 81 lines
Two new operation
callbacks are defined inhotplug_slot_ops:-
available_images: Optional: available FPGA images
-image_load: Optional: trigger the FPGA to load a new imageThe process of reprogramming an FPGA card begins by removing all devices associated with the card that are not required for the reprogramming of the card. This includes PCIe devices (PFs and VFs) associated with the card as well as any other types of devices (platform, etc.) defined within the FPGA. The remaining devices are referred to here as "reserved" devices. After triggering the update of the FPGA card, the reserved devices are also removed.
The complete process for reprogramming the FPGA are:
1. remove all PFs and VFs except for PF0 (reserved).
2. remove all non-reserved devices of PF0.
3. trigger FPGA card to do the image update.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under hotplug bridge.
6. wait for image reload done via BMC, e.g. 10s.
7. re-enable the link of hotplug bridge
8. enumerate PCI devices below the hotplug bridgeusage example:
[root@localhost]# cd /sys/bus/pci/slot/X-X/Get the available images.
[root@localhost 2-1]# catavailable_imagesbmc_factorybmc_userretimer_fwLoad the request images for FPGA Card, for example load the BMC user image:
[root@localhost 2-1]# echobmc_user>image_loadTianfei Zhang (12):
PCI: hotplug: add new callbacks onhotplug_slot_ops
PCI: hotplug: expose APIs from pciehp driver
PCI: hotplug: add and expose link disable API
PCI: hotplug: add FPGA PCI hotplug manager driver
fpga: dfl: register dfl-pci device into fpgahph driver driver core: exposedevice_is_ancestor()API
PCI: hotplug: add register/unregister function for BMC device
fpga: m10bmc-sec: register BMC device into fpgahp driver
fpga: dfl: remove non-reserved devices
PCI: hotplug: implement thehotplug_slot_opscallback for fpgahp
fpga: m10bmc-sec: addm10bmc_sec_retimer_loadcallback
Documentation: fpga: add description of fpgahp driverDocumentation/ABI/testing/sysfs-driver-fpgahp | 21 + Documentation/fpga/fpgahp.rst | 29 + Documentation/fpga/index.rst | 1 + MAINTAINERS | 10 + drivers/base/core.c | 3 +- drivers/fpga/Kconfig | 2 + drivers/fpga/dfl-pci.c | 95 +++- drivers/fpga/dfl.c | 58 ++ drivers/fpga/dfl.h | 4 + drivers/fpga/intel-m10-bmc-sec-update.c | 246 ++++++++ drivers/pci/hotplug/Kconfig | 14 + drivers/pci/hotplug/Makefile | 1 + drivers/pci/hotplug/fpgahp.c | 526 ++++++++++++++++++ drivers/pci/hotplug/pci_hotplug_core.c | 88 +++ drivers/pci/hotplug/pciehp.h | 3 + drivers/pci/hotplug/pciehp_hpc.c | 11 +- drivers/pci/hotplug/pciehp_pci.c | 2 + include/linux/device.h | 1 + include/linux/fpga/fpgahp_manager.h | 100 ++++ include/linux/mfd/intel-m10-bmc.h | 31 ++ include/linux/pci_hotplug.h | 5 + 21 files changed, 1243 insertions(+), 8 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-fpgahp create mode 100644 Documentation/fpga/fpgahp.rst create mode 100644 drivers/pci/hotplug/fpgahp.c create mode 100644 include/linux/fpga/fpgahp_manager.hbase-commit:
5dc4c995db9eb45f6373a956eb1f69460e69e6d4Signature · 1 line
2.38.1
Quoted 34 lines
-----Original Message-----
From: Pali Rohár <[email protected]>
Sent: Thursday, January 19, 2023 4:06 PM
To: Zhang, Tianfei <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wu, Hao <[email protected]>; Xu, Yilun <[email protected]>; Rix, Tom <[email protected]>; [email protected]; Weiny, Ira <[email protected]>; [email protected]; Williams, Dan J <[email protected]>; [email protected]; [email protected]; Weight, Russell H <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 00/12] add FPGA hotplug manager driverHello!
Quoted 7 lines · On Wednesday 18 January 2023 20:35:50 Tianfei Zhang wrote:
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
Quoted 6 lines
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver.
Quoted 4 lines
Just I'm thinking about one thing. PCIe cards can support PCIe hotplug mechanism (via standard PCIe capabilities). So what would happen when FPGA based PCIe card is also hotplug-able? Will be there two PCI hotplug
drivers/devices(one fpgahp and one pciehp)? Or just one and which?
For our Intel PAC N3000 and N6000 FPGA card, there are not support PCIe hotplug capability from hardware side now, but from software perspective, the process of FPGA image load is very similar with PCIe hotplug, like removing all of devices under PCIe bridge, re-scan the PCIe device under the bridge, so we are looking for the PCIe hotplug framework and APIs from pciehp driver to manager this process, and reduce some duplicate code.
Quoted 83 lines
Quoted 8 lines
Two new operation
callbacks are defined inhotplug_slot_ops:-
available_images: Optional: available FPGA images
-image_load: Optional: trigger the FPGA to load a new imageQuoted 5 lines
The process of reprogramming an FPGA card begins by removing all devices associated with the card that are not required for the reprogramming of the card. This includes PCIe devices (PFs and VFs) associated with the card as well as any other types of devices (platform, etc.) defined within the FPGA. The remaining devices are referred to
here as "reserved" devices.
Quoted 69 lines
After triggering the update of the FPGA card, the reserved devices are also removed.
The complete process for reprogramming the FPGA are:
1. remove all PFs and VFs except for PF0 (reserved).
2. remove all non-reserved devices of PF0.
3. trigger FPGA card to do the image update.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under hotplug bridge.
6. wait for image reload done via BMC, e.g. 10s.
7. re-enable the link of hotplug bridge
8. enumerate PCI devices below the hotplug bridgeusage example:
[root@localhost]# cd /sys/bus/pci/slot/X-X/Get the available images.
[root@localhost 2-1]# catavailable_imagesbmc_factorybmc_userretimer_fwLoad the request images for FPGA Card, for example load the BMC user image:
[root@localhost 2-1]# echobmc_user>image_loadTianfei Zhang (12):
PCI: hotplug: add new callbacks onhotplug_slot_ops
PCI: hotplug: expose APIs from pciehp driver
PCI: hotplug: add and expose link disable API
PCI: hotplug: add FPGA PCI hotplug manager driver
fpga: dfl: register dfl-pci device into fpgahph driver driver core: exposedevice_is_ancestor()API
PCI: hotplug: add register/unregister function for BMC device
fpga: m10bmc-sec: register BMC device into fpgahp driver
fpga: dfl: remove non-reserved devices
PCI: hotplug: implement thehotplug_slot_opscallback for fpgahp
fpga: m10bmc-sec: addm10bmc_sec_retimer_loadcallback
Documentation: fpga: add description of fpgahp driverDocumentation/ABI/testing/sysfs-driver-fpgahp | 21 + Documentation/fpga/fpgahp.rst | 29 + Documentation/fpga/index.rst | 1 + MAINTAINERS | 10 + drivers/base/core.c | 3 +- drivers/fpga/Kconfig | 2 + drivers/fpga/dfl-pci.c | 95 +++- drivers/fpga/dfl.c | 58 ++ drivers/fpga/dfl.h | 4 + drivers/fpga/intel-m10-bmc-sec-update.c | 246 ++++++++ drivers/pci/hotplug/Kconfig | 14 + drivers/pci/hotplug/Makefile | 1 + drivers/pci/hotplug/fpgahp.c | 526 ++++++++++++++++++ drivers/pci/hotplug/pci_hotplug_core.c | 88 +++ drivers/pci/hotplug/pciehp.h | 3 + drivers/pci/hotplug/pciehp_hpc.c | 11 +- drivers/pci/hotplug/pciehp_pci.c | 2 + include/linux/device.h | 1 + include/linux/fpga/fpgahp_manager.h | 100 ++++ include/linux/mfd/intel-m10-bmc.h | 31 ++ include/linux/pci_hotplug.h | 5 + 21 files changed, 1243 insertions(+), 8 deletions(-) create mode 100644 Documentation/ABI/testing/sysfs-driver-fpgahp create mode 100644 Documentation/fpga/fpgahp.rst create mode 100644
drivers/pci/hotplug/fpgahp.ccreate mode 100644include/linux/fpga/fpgahp_manager.hbase-commit:
5dc4c995db9eb45f6373a956eb1f69460e69e6d4--
2.38.1
Quoted 3 lines · Tianfei
Quoted 3 lines
From: Pali Rohár <[email protected]>
Sent: Thursday, January 19, 2023 4:06 PM
On Wednesday 18 January 2023 20:35:50 Tianfei Zhang wrote:
...
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver.
Just I'm thinking about one thing. PCIe cards can support PCIe hotplug mechanism (via standard PCIe capabilities). So what would happen when FPGA based PCIe card is also hotplug-able? Will be there two PCI hotplug
drivers/devices(one fpgahp and one pciehp)? Or just one and which?
Quoted 6 lines
For our Intel PAC N3000 and N6000 FPGA card, there are not support PCIe hotplug capability from hardware side now, but from software perspective, the process of FPGA image load is very similar with PCIe hotplug, like removing all of devices under PCIe bridge, re-scan the PCIe device under the bridge, so we are looking for the PCIe hotplug framework and APIs from pciehp driver to manager this process, and reduce some duplicate code.
Exactly, from the OS perspective they both should be equivalent.
Signature · 2 lines
With Best Regards, Andy Shevchenko
Quoted 45 lines
-----Original Message-----
From: [email protected] <[email protected]>
Sent: Thursday, January 19, 2023 7:28 PM
To: Zhang, Tianfei <[email protected]>
Cc: Pali Rohár <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; Wu, Hao <[email protected]>; Xu, Yilun <[email protected]>; Rix, Tom <[email protected]>; [email protected]; Weiny, Ira <[email protected]>; Williams, Dan J <[email protected]>; [email protected]; [email protected]; Weight, Russell H <[email protected]>; [email protected]; linux- [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [PATCH v1 00/12] add FPGA hotplug manager driverQuoted 3 lines · Tianfei
Quoted 3 lines
From: Pali Rohár <[email protected]>
Sent: Thursday, January 19, 2023 4:06 PM On Wednesday 18 January 2023 20:35:50 Tianfei Zhang wrote:...
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into
FPGA.
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the
PCIe bus.
Quoted 6 lines
Quoted 6 lines
Quoted 1 line
The fpgahp driver uses APIs from the pciehp driver.
Just I'm thinking about one thing. PCIe cards can support PCIe hotplug mechanism (via standard PCIe capabilities). So what would happen when FPGA based PCIe card is also hotplug-able? Will be there two PCI hotplug
drivers/devices(one fpgahp and one pciehp)? Or just one andwhich?
Quoted 7 lines
For our Intel PAC N3000 and N6000 FPGA card, there are not support PCIe hotplug capability from hardware side now, but from software perspective, the process of FPGA image load is very similar with PCIe hotplug, like removing all of devices under PCIe bridge, re-scan the PCIe device under the bridge, so we are looking for the PCIe hotplug framework and APIs from pciehp driver to manager this process, and reduce some
Quoted 3 lines
duplicate code.
Exactly, from the OS perspective they both should be equivalent.
Additionally, for FPGA usage, it doesn't need physical hot-add and hot-removal of the card for FPGA card managements like load a new FPGA image in FPGA deployment of data center or cloud. So whatever the card support PCIe hotplug capability or not, it can be done by leveraging the PCI hotplug framework and APIs from pciehp driver. I think it also has benefits for other vendor's FPGA Card to do some card managements by using fpgahp driver.
Greg KH
maintainerQuoted 38 lines · Tianfei Zhang
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver. Two new operation callbacks are defined in
hotplug_slot_ops:-
available_images: Optional: available FPGA images
-image_load: Optional: trigger the FPGA to load a new imageThe process of reprogramming an FPGA card begins by removing all devices associated with the card that are not required for the reprogramming of the card. This includes PCIe devices (PFs and VFs) associated with the card as well as any other types of devices (platform, etc.) defined within the FPGA. The remaining devices are referred to here as "reserved" devices. After triggering the update of the FPGA card, the reserved devices are also removed.
The complete process for reprogramming the FPGA are:
1. remove all PFs and VFs except for PF0 (reserved).
2. remove all non-reserved devices of PF0.
3. trigger FPGA card to do the image update.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under hotplug bridge.
6. wait for image reload done via BMC, e.g. 10s.
7. re-enable the link of hotplug bridge
8. enumerate PCI devices below the hotplug bridgeusage example:
Quoted 8 lines
[root@localhost]# cd /sys/bus/pci/slot/X-X/Get the available images.
[root@localhost 2-1]# catavailable_imagesbmc_factorybmc_userretimer_fwLoad the request images for FPGA Card, for example load the BMC user image:
[root@localhost 2-1]# echobmc_user>image_load
Why is all of this tied into the pci hotplug code? Shouldn't it be specific to this one driver instead? pci hotplug is for removing/adding PCI devices to the system, not messing with FPGA images.
This feels like an abuse of the pci hotplug bus to me as this is NOT really a PCI hotplug bus at all, right?
Or is it? If so, then the slots should show up under the PCI device itself, not in /sys/bus/pci/slot/. That location is there for old old stuff, we probably should move it one of these days as there's lots of special-cases in the driver core just because of that :(
thanks,
greg k-h
Rafael J. Wysocki
maintainerQuoted 53 lines · Greg KH
Quoted 38 lines · Tianfei Zhang
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver. Two new operation callbacks are defined in
hotplug_slot_ops:-
available_images: Optional: available FPGA images
-image_load: Optional: trigger the FPGA to load a new imageThe process of reprogramming an FPGA card begins by removing all devices associated with the card that are not required for the reprogramming of the card. This includes PCIe devices (PFs and VFs) associated with the card as well as any other types of devices (platform, etc.) defined within the FPGA. The remaining devices are referred to here as "reserved" devices. After triggering the update of the FPGA card, the reserved devices are also removed.
The complete process for reprogramming the FPGA are:
1. remove all PFs and VFs except for PF0 (reserved).
2. remove all non-reserved devices of PF0.
3. trigger FPGA card to do the image update.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under hotplug bridge.
6. wait for image reload done via BMC, e.g. 10s.
7. re-enable the link of hotplug bridge
8. enumerate PCI devices below the hotplug bridgeusage example:
Quoted 8 lines
[root@localhost]# cd /sys/bus/pci/slot/X-X/Get the available images.
[root@localhost 2-1]# catavailable_imagesbmc_factorybmc_userretimer_fwLoad the request images for FPGA Card, for example load the BMC user image:
[root@localhost 2-1]# echobmc_user>image_loadWhy is all of this tied into the pci hotplug code? Shouldn't it be specific to this one driver instead? pci hotplug is for removing/adding PCI devices to the system, not messing with FPGA images.
Quoted 7 lines
This feels like an abuse of the pci hotplug bus to me as this is NOT really a PCI hotplug bus at all, right?
Or is it? If so, then the slots should show up under the PCI device itself, not in
/sys/bus/pci/slot/. That location is there for old old stuff, we probably should move it one of these days as there's lots of special-cases in the driver core just because of that :(
I'm not sure if I can agree with this statement.
The slot here is what is registered via pci_hp_register(), isn't it?
There are multiple users of this in the tree, including ACPI-based PCI hotplug, which is not really that old.
Are you saying that this should not be used?
Greg KH
maintainerQuoted 57 lines · Rafael J. Wysocki
Quoted 56 lines · Greg KH
Quoted 38 lines · Tianfei Zhang
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver. Two new operation callbacks are defined in
hotplug_slot_ops:-
available_images: Optional: available FPGA images
-image_load: Optional: trigger the FPGA to load a new imageThe process of reprogramming an FPGA card begins by removing all devices associated with the card that are not required for the reprogramming of the card. This includes PCIe devices (PFs and VFs) associated with the card as well as any other types of devices (platform, etc.) defined within the FPGA. The remaining devices are referred to here as "reserved" devices. After triggering the update of the FPGA card, the reserved devices are also removed.
The complete process for reprogramming the FPGA are:
1. remove all PFs and VFs except for PF0 (reserved).
2. remove all non-reserved devices of PF0.
3. trigger FPGA card to do the image update.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under hotplug bridge.
6. wait for image reload done via BMC, e.g. 10s.
7. re-enable the link of hotplug bridge
8. enumerate PCI devices below the hotplug bridgeusage example:
Quoted 8 lines
[root@localhost]# cd /sys/bus/pci/slot/X-X/Get the available images.
[root@localhost 2-1]# catavailable_imagesbmc_factorybmc_userretimer_fwLoad the request images for FPGA Card, for example load the BMC user image:
[root@localhost 2-1]# echobmc_user>image_loadWhy is all of this tied into the pci hotplug code? Shouldn't it be specific to this one driver instead? pci hotplug is for removing/adding PCI devices to the system, not messing with FPGA images.
This feels like an abuse of the pci hotplug bus to me as this is NOT really a PCI hotplug bus at all, right?
Quoted 8 lines
Quoted 4 lines
Or is it? If so, then the slots should show up under the PCI device itself, not in
/sys/bus/pci/slot/. That location is there for old old stuff, we probably should move it one of these days as there's lots of special-cases in the driver core just because of that :(I'm not sure if I can agree with this statement.
The slot here is what is registered via
pci_hp_register(), isn't it?
Yes, but is it really a "slot" like a normal PCI slot?
Quoted 2 lines
There are multiple users of this in the tree, including ACPI-based PCI hotplug, which is not really that old.
It's really old, I think I worked on that in the 2.4/2.5 days? Anyway, it's been around a long time.
Quoted 1 line
Are you saying that this should not be used?
I'm saying that PCI is the only subsystem/bus that has something like this and we have a number of functions exported in the driver core only for the pci hotplug slot list. Which kind of implies that maybe it should be moved to something else? I don't have any specific ideas what it should be, just that it feels really odd as-is still.
thanks,
greg k-h
Quoted 45 lines · Greg KH
Quoted 44 lines · Tianfei Zhang
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver. Two new operation callbacks are defined in
hotplug_slot_ops:-
available_images: Optional: available FPGA images
-image_load: Optional: trigger the FPGA to load a new imageThe process of reprogramming an FPGA card begins by removing all devices associated with the card that are not required for the reprogramming of the card. This includes PCIe devices (PFs and VFs) associated with the card as well as any other types of devices (platform, etc.) defined within the FPGA. The remaining devices are referred to here as "reserved" devices. After triggering the update of the FPGA card, the reserved devices are also removed.
The complete process for reprogramming the FPGA are:
1. remove all PFs and VFs except for PF0 (reserved).
2. remove all non-reserved devices of PF0.
3. trigger FPGA card to do the image update.
4. disable the link of the hotplug bridge.
5. remove all reserved devices under hotplug bridge.
6. wait for image reload done via BMC, e.g. 10s.
7. re-enable the link of hotplug bridge
8. enumerate PCI devices below the hotplug bridgeusage example:
[root@localhost]# cd /sys/bus/pci/slot/X-X/Get the available images.
[root@localhost 2-1]# catavailable_imagesbmc_factorybmc_userretimer_fw
Quoted 8 lines
Quoted 2 lines
Load the request images for FPGA Card, for example load the BMC user image:
[root@localhost 2-1]# echobmc_user>image_loadWhy is all of this tied into the pci hotplug code? Shouldn't it be specific to this one driver instead? pci hotplug is for removing/adding PCI devices to the system, not messing with FPGA images.
This feels like an abuse of the pci hotplug bus to me as this is NOT really a PCI hotplug bus at all, right?
While it is true that triggering an FPGA image-load does not involve hotplug specific registers to be managed, the RTL that comprises the PCIe interface will disappear and then reappear after the FPGA is reprogrammed. When it reappears, it_could/_/have a different PCI ID. The process of managing this event has a lot of similarity to a PCIe hotplug event; there is a lot of existing PCIe hotplug related code that could be leveraged.
As alternatives to the idea of creating a hotplug driver, we have considered creating a new PCIe service driver specifically to handle FPGA reprogramming, or modifying the existing hotplug driver(s) to add FPGA support. We have also considered a separate fpga-reload driver that would not be bound to a PCIe interface, but would still leverage the PCIe code to manage the event. Do any of these options sound preferable to creating an FPGA hotplug driver?
Quoted 9 lines
Or is it? If so, then the slots should show up under the PCI device itself, not in
/sys/bus/pci/slot/. That location is there for old old stuff, we probably should move it one of these days as there's lots of special-cases in the driver core just because of that :(thanks,
greg k-h
Quoted 27 lines · Russ Weight
Quoted 19 lines · Greg KH
Quoted 15 lines · Tianfei Zhang
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver. Two new operation callbacks are defined in
hotplug_slot_ops:Quoted 2 lines
-
available_images: Optional: available FPGA images
-image_load: Optional: trigger the FPGA to load a new imageQuoted 6 lines
Why is all of this tied into the pci hotplug code? Shouldn't it be specific to this one driver instead? pci hotplug is for removing/adding PCI devices to the system, not messing with FPGA images.
This feels like an abuse of the pci hotplug bus to me as this is NOT really a PCI hotplug bus at all, right?
Quoted 7 lines
While it is true that triggering an FPGA image-load does not involve hotplug specific registers to be managed, the RTL that comprises the PCIe interface will disappear and then reappear after the FPGA is reprogrammed. When it reappears, it_could/_/have a different PCI ID. The process of managing this event has a lot of similarity to a PCIe hotplug event; there is a lot of existing PCIe hotplug related code that could be leveraged.
It sounds like the N3000 is a PCI endpoint device which, when reprogrammed, briefly disappears from the bus and then may reappear under a different device ID.
What you want to do then is make sure that the slot into which the N3000 is plugged is hotplug-capable. In that case, pciehp will handle disappearance and reappearance of the card just fine. Once the N3000 disables the link, pciehp will bring down the slot. Once it re-enables the link, it will bring the slot up again. It's as if the card was removed and replaced with a different one. pciehp will bind to the Root Port or Downstream Port associated with the hotplug slot.
The pci_hotplug_port infrastructure is for hotplug controllers which handle devices disappearing and reappearing *below* them. It is not for endpoint devices.
Thanks,
Lukas
Greg KH
maintainerQuoted 48 lines · Lukas Wunner
Quoted 27 lines · Russ Weight
Quoted 19 lines · Greg KH
Quoted 15 lines · Tianfei Zhang
This patchset introduces the FPGA hotplug manager (fpgahp) driver which has been verified on the Intel N3000 card.
When a PCIe-based FPGA card is reprogrammed, it temporarily disappears from the PCIe bus. This needs to be managed to avoid PCIe errors and to reprobe the device after reprogramming.
To change the FPGA image, the kernel burns a new image into the flash on the card, and then triggers the card BMC to load the new image into FPGA. A new FPGA hotplug manager driver is introduced that leverages the PCIe hotplug framework to trigger and manage the update of the FPGA image, including the disappearance and reappearance of the card on the PCIe bus. The fpgahp driver uses APIs from the pciehp driver. Two new operation callbacks are defined in
hotplug_slot_ops:Quoted 2 lines
-
available_images: Optional: available FPGA images
-image_load: Optional: trigger the FPGA to load a new imageQuoted 6 lines
Why is all of this tied into the pci hotplug code? Shouldn't it be specific to this one driver instead? pci hotplug is for removing/adding PCI devices to the system, not messing with FPGA images.
This feels like an abuse of the pci hotplug bus to me as this is NOT really a PCI hotplug bus at all, right?
Quoted 7 lines
While it is true that triggering an FPGA image-load does not involve hotplug specific registers to be managed, the RTL that comprises the PCIe interface will disappear and then reappear after the FPGA is reprogrammed. When it reappears, it_could/_/have a different PCI ID. The process of managing this event has a lot of similarity to a PCIe hotplug event; there is a lot of existing PCIe hotplug related code that could be leveraged.
It sounds like the N3000 is a PCI endpoint device which, when reprogrammed, briefly disappears from the bus and then may reappear under a different device ID.
What you want to do then is make sure that the slot into which the N3000 is plugged is hotplug-capable. In that case, pciehp will handle disappearance and reappearance of the card just fine. Once the N3000 disables the link, pciehp will bring down the slot. Once it re-enables the link, it will bring the slot up again. It's as if the card was removed and replaced with a different one. pciehp will bind to the Root Port or Downstream Port associated with the hotplug slot.
Quoted 3 lines
The
pci_hotplug_portinfrastructure is for hotplug controllers which handle devices disappearing and reappearing *below* them. It is not for endpoint devices.
Yes, thank you for expressing my concerns about this design much better than I originally did. I totally agree.
thanks,
greg k-h