Skip to contentSkip to conversation

Add versal-pci driver

PATCH In review Yidong Zhang 3 participants 28 messages Dec 10, 2024 – Mar 3, 2025 FPGA manager framework

lore
Share & tools
lore
#0 lore raw

v2 cover Add versal-pci driver

This patchset introduces a new Linux Kernel Driver, versal-pci for AMD Alevo Versal based PCIe Card. The driver is based on Linux fpga driver framework.

The AMD Alevo Versal based PCIe Card, including V70, is the first Alevo production card leveraging AMD XDNA architecture with AI Engines. It is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications [1].

This versal-pci driver provides services, including:
- leveraging linux firmware and FPGA framework to download management firmware
- program additional bit-streams for AMD Xilinx specific hardware
- communicate with PCIe user function
- communicate with firmware running on the PCIe Card
- monitor device health

The driver is licensed under GPL-2.0.

The firmware and bit-streams are distributed as a closed binary, delivered by AMD. Please see [1] for more information.

[1] https://www.amd.com/en/products/accelerators/alveo/v70.html

Refactor driver to address all comments from v1.
Changes since v1:
- Add driver architecture description.
- Change the driver name to versal-pci
- Remove unnecessary memcpy in versal-pci-comm-chan.c
- Keep mod_timer because we need single_threaded_queue with delayed_work.
- Change the "comms" to "comm_chan".
- Remove regmap, use base+offset directly.
- Add skeleton ops with on implementation (TODO) for fpga_manager in early patch (0001) and add implementation in later patch(0004).
- Remove br_ops and FPGA region, no need.
- Add load_xclbin request from user PF driver via comm_chan service, and read firmware from local cached data.
- Remove pcim_iomap_table and pcim_iomap_regions. Use pcim_iomap_region.
- Redo patches, remove no-used definitions for each patch itself. Use /* TODO */ to mark dependencies that will be addressed in later patch.
- Fix memory leak in rm_check_health.
- Fix cmd with error status in rm_check_health.
- Change to vzalloc in all places.
- Add rm_queue_withdraw_cmd in fw_cancel.

Yidong Zhang (4):
drivers/fpga/amd: Add new driver amd versal-pci drivers/fpga/amd: Add communication channel drivers/fpga/amd: Add remote queue drivers/fpga/amd: Add load xclbin and load firmware

 MAINTAINERS                              |   6 +
 drivers/fpga/Kconfig                     |   3 +
 drivers/fpga/Makefile                    |   3 +
 drivers/fpga/amd/Kconfig                 |  15 +
 drivers/fpga/amd/Makefile                |   8 +
 drivers/fpga/amd/versal-pci-comm-chan.c  | 271 ++++++++++++
 drivers/fpga/amd/versal-pci-comm-chan.h  |  14 +
 drivers/fpga/amd/versal-pci-main.c       | 445 ++++++++++++++++++++
 drivers/fpga/amd/versal-pci-rm-queue.c   | 324 +++++++++++++++
 drivers/fpga/amd/versal-pci-rm-queue.h   |  21 +
 drivers/fpga/amd/versal-pci-rm-service.c | 497 +++++++++++++++++++++++
 drivers/fpga/amd/versal-pci-rm-service.h | 229 +++++++++++
 drivers/fpga/amd/versal-pci.h            |  90 ++++
 13 files changed, 1926 insertions(+)
 create mode 100644 drivers/fpga/amd/Kconfig
 create mode 100644 drivers/fpga/amd/Makefile
 create mode 100644 drivers/fpga/amd/versal-pci-comm-chan.c
 create mode 100644 drivers/fpga/amd/versal-pci-comm-chan.h
 create mode 100644 drivers/fpga/amd/versal-pci-main.c
 create mode 100644 drivers/fpga/amd/versal-pci-rm-queue.c
 create mode 100644 drivers/fpga/amd/versal-pci-rm-queue.h
 create mode 100644 drivers/fpga/amd/versal-pci-rm-service.c
 create mode 100644 drivers/fpga/amd/versal-pci-rm-service.h
 create mode 100644 drivers/fpga/amd/versal-pci.h
Signature · 1 line
2.34.1
#1 lore raw

PATCH v2 1/4 drivers/fpga/amd: Add new driver amd versal-pci

AMD Versal based PCIe card, including V70, is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications.

The driver architecture:

  +---------+  Communication +---------+  Remote  +-----+------+
  |         |  Channel       |         |  Queue   |     |      |
  | User PF | <============> | Mgmt PF | <=======>| FW  | FPGA |
  +---------+                +---------+          +-----+------+
    PL Data                    base FW

APU FW
PL Data (copy)
- PL (FPGA Program Logic)
- FW (Firmware)

There are 2 separate drivers from the original XRT[1] design.
- UserPF driver
- MgmtPF driver

The new AMD versal-pci driver will replace the MgmtPF driver for Versal PCIe card.

The XRT[1] is already open-sourced. It includes solution of runtime for many different type of PCIe Based cards. It also provides utilities for managing and programming the devices.

The AMD versal-pci stands for AMD Versal brand PCIe device management driver. This driver provides the following functionalities:

- module and PCI device initialization
this driver will attach to specific device id of V70 card; the driver will initialize itself based on bar resources for
- communication channel:
a hardware message service between mgmt PF and user PF
- remote queue:
a hardware queue based ring buffer service between mgmt PF and PCIe hardware firmware for programming FPGA Program Logic, loading firmware and checking card healthy status.

- programming FW
- The base FW is downloaded onto the flash of the card.
- The APU FW is downloaded once after a POR (power on reset).
- Reloading the MgmtPF driver will not change any existing hardware.

- programming FPGA hardware binaries - PL Data
- using fpga framework ops to support re-programing FPGA
- the re-programming request will be initiated from the existing UserPF driver only, and the MgmtPF driver load the matched PL Data after receiving request from the communication channel. The matching PL Data is indexed by the PL Data UUID and Base FW UUID.
- The Base FW UUID identifies unique based hardware. Often called the interface UUID.
- The PL Data UUID identifies unique PL design that is generated based on the base hardware. Often called xclbin UUID.

- Example:
4fdebe35[...trimmed...]_96df7d[...trimmed...].xclbin
| | | |
+-- xclbin UUID --+ +--interface UUID --+

[1] https://github.com/Xilinx/XRT/blob/master/README.rst

---
 MAINTAINERS                        |   6 +
 drivers/fpga/Kconfig               |   3 +
 drivers/fpga/Makefile              |   3 +
 drivers/fpga/amd/Kconfig           |  15 ++
 drivers/fpga/amd/Makefile          |   5 +
 drivers/fpga/amd/versal-pci-main.c | 328 +++++++++++++++++++++++++++++
 drivers/fpga/amd/versal-pci.h      |  86 ++++++++
 7 files changed, 446 insertions(+)
 create mode 100644 drivers/fpga/amd/Kconfig
 create mode 100644 drivers/fpga/amd/Makefile
 create mode 100644 drivers/fpga/amd/versal-pci-main.c
 create mode 100644 drivers/fpga/amd/versal-pci.h
MAINTAINERS +6 -0
index 17daa9ee9384..302c10004c5d 100644
@@ -1194,6 +1194,12 @@ L:	[email protected]
 S:	Supported
 F:	drivers/spi/spi-amd.c
 
+AMD VERSAL PCI DRIVER
+M:	Yidong Zhang <[email protected]>
+L:	[email protected]
+S:	Supported
+F:	drivers/fpga/amd/
+
 AMD XGBE DRIVER
 M:	"Shyam Sundar S K" <[email protected]>
 L:	[email protected]
drivers/fpga/Kconfig +3 -0
index 37b35f58f0df..dce060a7bd8f 100644
@@ -290,4 +290,7 @@ config FPGA_MGR_LATTICE_SYSCONFIG_SPI
 
 source "drivers/fpga/tests/Kconfig"
 
+# Driver files
+source "drivers/fpga/amd/Kconfig"
+
 endif # FPGA
drivers/fpga/Makefile +3 -0
index aeb89bb13517..8412f3e211cc 100644
@@ -58,5 +58,8 @@ obj-$(CONFIG_FPGA_DFL_NIOS_INTEL_PAC_N3000)	+= dfl-n3000-nios.o
 # Drivers for FPGAs which implement DFL
 obj-$(CONFIG_FPGA_DFL_PCI)		+= dfl-pci.o
 
+# AMD PCIe Versal Management Driver
+obj-$(CONFIG_AMD_VERSAL_PCI)		+= amd/
+
 # KUnit tests
 obj-$(CONFIG_FPGA_KUNIT_TESTS)		+= tests/
drivers/fpga/amd/Kconfig new file +15 -0
new file mode 100644
index 000000000000..b18a42a340ba
@@ -0,0 +1,15 @@
+# SPDX-License-Identifier: GPL-2.0-only
+
+config AMD_VERSAL_PCI
+	tristate "AMD Versal PCIe Management Driver"
+	select FW_LOADER
+	select FW_UPLOAD
+	depends on FPGA
+	depends on HAS_IOMEM
+	depends on PCI
+	help
+	  AMD Versal PCIe Management Driver provides management services to
+	  download firmware, program bitstream, and communicate with the User
+	  function.
+
+	  If "M" is selected, the driver module will be versal-pci
drivers/fpga/amd/Makefile new file +5 -0
new file mode 100644
index 000000000000..5d1ef04b5e80
@@ -0,0 +1,5 @@
+# SPDX-License-Identifier: GPL-2.0
+
+obj-$(CONFIG_AMD_VERSAL_PCI)			+= versal-pci.o
+
+versal-pci-$(CONFIG_AMD_VERSAL_PCI)		:= versal-pci-main.o
drivers/fpga/amd/versal-pci-main.c new file +328 -0

328 lines not on this page · raw message

drivers/fpga/amd/versal-pci.h new file +86 -0

86 lines not on this page · raw message

Signature · 1 line
2.34.1
#2 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 4 lines
drivers/fpga/amd/versal-pci-main.c new file +4 -0
+static int versal_pci_program_axlf(struct versal_pci_device *vdev, char *data, size_t size)
+{
+	const struct axlf *axlf = (struct axlf *)data;
+	struct fpga_image_info *image_info;

drivers/fpga/amd/versal-pci-main.c line 118

Quoted 10 lines
drivers/fpga/amd/versal-pci-main.c new file +10 -0
+	int ret;
+
+	image_info = fpga_image_info_alloc(&vdev->pdev->dev);
+	if (!image_info)
+		return -ENOMEM;
+
+	image_info->count = axlf->header.length;
+	image_info->buf = (char *)axlf;
+
+	ret = fpga_mgr_load(vdev->fdev->mgr, image_info);

I see, but this is not working like this. fpga_mgr_load() is intended to be called by fpga_region, any reprogramming API should come from fpga_region, and fpga_region could provide uAPI for userspace reprogramming.

If your driver act both as a fpga_mgr backend and a fpga_mgr kAPI user, then you don't have to bother using fpga framework at all.

Thanks,
Yilun

Quoted 13 lines
drivers/fpga/amd/versal-pci-main.c new file +13 -0
+	if (ret) {
+		vdev_err(vdev, "failed to load xclbin: %d", ret);
+		goto exit;
+	}
+
+	vdev_info(vdev, "Downloaded axlf %pUb of size %zu Bytes", &axlf->header.uuid, size);
+	uuid_copy(&vdev->xclbin_uuid, &axlf->header.uuid);
+
+exit:
+	fpga_image_info_free(image_info);
+
+	return ret;
+}
#3 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 22 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 4 lines
drivers/fpga/amd/versal-pci-main.c new file +4 -0
+static int versal_pci_program_axlf(struct versal_pci_device *vdev, char *data, size_t size)
+{
+     const struct axlf *axlf = (struct axlf *)data;
+     struct fpga_image_info *image_info;

drivers/fpga/amd/versal-pci-main.c line 118

Quoted 10 lines
drivers/fpga/amd/versal-pci-main.c new file +10 -0
+     int ret;
+
+     image_info = fpga_image_info_alloc(&vdev->pdev->dev);
+     if (!image_info)
+             return -ENOMEM;
+
+     image_info->count = axlf->header.length;
+     image_info->buf = (char *)axlf;
+
+     ret = fpga_mgr_load(vdev->fdev->mgr, image_info);

I see, but this is not working like this. fpga_mgr_load() is intended to be called by fpga_region, any reprogramming API should come from fpga_region, and fpga_region could provide uAPI for userspace reprogramming.

Quoted 2 lines

If your driver act both as a fpga_mgr backend and a fpga_mgr kAPI user, then you don't have to bother using fpga framework at all.

The versal-pci is more like a util driver that handles requests from the separate userPF driver.

Thanks,
David

Quoted 17 lines

Thanks,
Yilun

Quoted 13 lines
drivers/fpga/amd/versal-pci-main.c new file +13 -0
+     if (ret) {
+             vdev_err(vdev, "failed to load xclbin: %d", ret);
+             goto exit;
+     }
+
+     vdev_info(vdev, "Downloaded axlf %pUb of size %zu Bytes", &axlf->header.uuid, size);
+     uuid_copy(&vdev->xclbin_uuid, &axlf->header.uuid);
+
+exit:
+     fpga_image_info_free(image_info);
+
+     return ret;
+}
#4 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

In reply to Yidong Zhang

Le 10/12/2024 à 19:37, Yidong Zhang a écrit :

Quoted 3 lines

AMD Versal based PCIe card, including V70, is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications.

...

drivers/fpga/amd/versal-pci-main.c line 63

Quoted 7 lines
drivers/fpga/amd/versal-pci-main.c new file +7 -0
+static void versal_pci_uuid_parse(struct versal_pci_device *vdev, uuid_t *uuid)
+{
+	char str[UUID_STRING_LEN];
+	u8 i, j;
+
+	/* parse uuid into a valid uuid string format */
+	for (i  = 0, j = 0; i < strlen(vdev->fw_id) && i < sizeof(str); i++) {

Unneeded extra space in "i = 0"

I think that the compiler already does it on its own, but the strlen could be computed before the for loop.

drivers/fpga/amd/versal-pci-main.c line 76

Quoted 13 lines
drivers/fpga/amd/versal-pci-main.c new file +13 -0
+		str[j++] = vdev->fw_id[i];
+		if (j == 8 || j == 13 || j == 18 || j == 23)
+			str[j++] = '-';
+	}
+
+	uuid_parse(str, uuid);
+	vdev_info(vdev, "Interface uuid %pU", uuid);
+}
+
+static struct fpga_device *versal_pci_fpga_init(struct versal_pci_device *vdev)
+{
+	struct device *dev = &vdev->pdev->dev;
+	struct fpga_manager_info info = { 0 };

Is the { 0 } needed?
Isn't the assigment below enough?

Quoted 27 lines
drivers/fpga/amd/versal-pci-main.c new file +27 -0
+	struct fpga_device *fdev;
+	int ret;
+
+	fdev = devm_kzalloc(dev, sizeof(*fdev), GFP_KERNEL);
+	if (!fdev)
+		return ERR_PTR(-ENOMEM);
+
+	fdev->vdev = vdev;
+
+	info = (struct fpga_manager_info) {
+		.name = "AMD Versal FPGA Manager",
+		.mops = &versal_pci_fpga_ops,
+		.priv = fdev,
+	};
+
+	fdev->mgr = fpga_mgr_register_full(dev, &info);
+	if (IS_ERR(fdev->mgr)) {
+		ret = PTR_ERR(fdev->mgr);
+		vdev_err(vdev, "Failed to register FPGA manager, err %d", ret);
+		return ERR_PTR(ret);
+	}
+
+	/* Place holder for rm_queue_get_fw_id(vdev->rdev) */
+	versal_pci_uuid_parse(vdev, &vdev->intf_uuid);
+
+	return fdev;
+}

...

drivers/fpga/amd/versal-pci-main.c line 221

Quoted 12 lines
drivers/fpga/amd/versal-pci-main.c new file +12 -0
+static struct firmware_device *versal_pci_fw_upload_init(struct versal_pci_device *vdev)
+{
+	struct device *dev = &vdev->pdev->dev;
+	struct firmware_device *fwdev;
+	u32 devid;
+
+	fwdev = devm_kzalloc(dev, sizeof(*fwdev), GFP_KERNEL);
+	if (!fwdev)
+		return ERR_PTR(-ENOMEM);
+
+	devid = versal_pci_devid(vdev);
+	fwdev->name = kasprintf(GFP_KERNEL, "%s%x", DRV_NAME, devid);

Why is fwdev managed, and not fwdev->name?
It looks ok as-is, but using devm_kasprintf() would save a few lines of code.

Quoted 14 lines
drivers/fpga/amd/versal-pci-main.c new file +14 -0
+	if (!fwdev->name)
+		return ERR_PTR(-ENOMEM);
+
+	fwdev->fw = firmware_upload_register(THIS_MODULE, dev, fwdev->name,
+					     &versal_pci_fw_ops, fwdev);
+	if (IS_ERR(fwdev->fw)) {
+		kfree(fwdev->name);
+		return ERR_CAST(fwdev->fw);
+	}
+
+	fwdev->vdev = vdev;
+
+	return fwdev;
+}

...

Quoted 21 lines
drivers/fpga/amd/versal-pci-main.c new file +21 -0
+static int versal_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pdev_id)
+{
+	struct versal_pci_device *vdev;
+	int ret;
+
+	vdev = devm_kzalloc(&pdev->dev, sizeof(*vdev), GFP_KERNEL);
+	if (!vdev)
+		return -ENOMEM;
+
+	pci_set_drvdata(pdev, vdev);
+	vdev->pdev = pdev;
+
+	ret = pcim_enable_device(pdev);
+	if (ret) {
+		vdev_err(vdev, "Failed to enable device %d", ret);
+		return ret;
+	}
+
+	vdev->io_regs = pcim_iomap_region(vdev->pdev, MGMT_BAR, DRV_NAME);
+	if (IS_ERR(vdev->io_regs)) {
+		vdev_err(vdev, "Failed to map RM shared memory BAR%d", MGMT_BAR);

drivers/fpga/amd/versal-pci-main.c line 306

Quoted 10 lines
drivers/fpga/amd/versal-pci-main.c new file +10 -0
+		return PTR_ERR(vdev->io_regs);
+	}
+
+	ret = versal_pci_device_setup(vdev);
+	if (ret) {
+		vdev_err(vdev, "Failed to setup Versal device %d", ret);
+		return ret;
+	}
+
+	vdev_dbg(vdev, "Successfully probed %s driver!", DRV_NAME);

Usually, such debug messages are not needed. No strong opinion about it.

Review

Quoted 2 lines
(quoted diff) +2 -0
+	return 0;
+}

...

CJ

#5 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 10 lines · Christophe JAILLET

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 3 lines · Yidong Zhang

AMD Versal based PCIe card, including V70, is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications.

...

Quoted 11 lines
Quoted 9 lines

+static void versal_pci_uuid_parse(struct versal_pci_device *vdev, uuid_t *uuid)

drivers/fpga/amd/versal-pci-main.c new file +6 -0
+{
+     char str[UUID_STRING_LEN];
+     u8 i, j;
+
+     /* parse uuid into a valid uuid string format */
+     for (i  = 0, j = 0; i < strlen(vdev->fw_id) && i < sizeof(str); 

i++) {

Unneeded extra space in "i  = 0"

Great catch! I will fix this.

Quoted 3 lines

I think that the compiler already does it on its own, but the strlen could be computed before the for loop.

I will change the code.

Quoted 10 lines
Quoted 10 lines

+             str[j++] = vdev->fw_id[i];
+             if (j == 8 || j == 13 || j == 18 || j == 23) +                     str[j++] = '-';
+     }

drivers/fpga/amd/versal-pci-main.c new file +5 -0
+
+     uuid_parse(str, uuid);
+     vdev_info(vdev, "Interface uuid %pU", uuid);
+}
+
Quoted 8 lines
Quoted 5 lines

+static struct fpga_device *versal_pci_fpga_init(struct versal_pci_device *vdev)
+{
+     struct device *dev = &vdev->pdev->dev;
+     struct fpga_manager_info info = { 0 };

Is the { 0 } needed?
Isn't the assigment below enough?

Right. I will remove the unnecessary { 0 }.

Quoted 41 lines
Quoted 29 lines

+     struct fpga_device *fdev;
+     int ret;

drivers/fpga/amd/versal-pci-main.c new file +17 -0
+
+     fdev = devm_kzalloc(dev, sizeof(*fdev), GFP_KERNEL);
+     if (!fdev)
+             return ERR_PTR(-ENOMEM);
+
+     fdev->vdev = vdev;
+
+     info = (struct fpga_manager_info) {
+             .name = "AMD Versal FPGA Manager",
+             .mops = &versal_pci_fpga_ops,
+             .priv = fdev,
+     };
+
+     fdev->mgr = fpga_mgr_register_full(dev, &info);
+     if (IS_ERR(fdev->mgr)) {
+             ret = PTR_ERR(fdev->mgr);
+             vdev_err(vdev, "Failed to register FPGA manager, err 

%d", ret);
+             return ERR_PTR(ret);
+     }

drivers/fpga/amd/versal-pci-main.c new file +6 -0
+
+     /* Place holder for rm_queue_get_fw_id(vdev->rdev) */
+     versal_pci_uuid_parse(vdev, &vdev->intf_uuid);
+
+     return fdev;
+}

...

Quoted 9 lines

+static struct firmware_device *versal_pci_fw_upload_init(struct versal_pci_device *vdev)

drivers/fpga/amd/versal-pci-main.c new file +7 -0
+{
+     struct device *dev = &vdev->pdev->dev;
+     struct firmware_device *fwdev;
+     u32 devid;
+
+     fwdev = devm_kzalloc(dev, sizeof(*fwdev), GFP_KERNEL);
+     if (!fwdev)
Quoted 8 lines
Quoted 4 lines

+             return ERR_PTR(-ENOMEM);
+
+     devid = versal_pci_devid(vdev);
+     fwdev->name = kasprintf(GFP_KERNEL, "%s%x", DRV_NAME, devid);

Why is fwdev managed, and not fwdev->name?
It looks ok as-is, but using devm_kasprintf() would save a few lines of code.

I will change the code. Great suggestion.

Quoted 46 lines
Quoted 15 lines

+     if (!fwdev->name)
+             return ERR_PTR(-ENOMEM);

drivers/fpga/amd/versal-pci-main.c new file +12 -0
+
+     fwdev->fw = firmware_upload_register(THIS_MODULE, dev, fwdev->name,
+                                          &versal_pci_fw_ops, fwdev);
+     if (IS_ERR(fwdev->fw)) {
+             kfree(fwdev->name);
+             return ERR_CAST(fwdev->fw);
+     }
+
+     fwdev->vdev = vdev;
+
+     return fwdev;
+}

...

Quoted 28 lines

+static int versal_pci_probe(struct pci_dev *pdev, const struct pci_device_id *pdev_id)

drivers/fpga/amd/versal-pci-main.c new file +20 -0
+{
+     struct versal_pci_device *vdev;
+     int ret;
+
+     vdev = devm_kzalloc(&pdev->dev, sizeof(*vdev), GFP_KERNEL);
+     if (!vdev)
+             return -ENOMEM;
+
+     pci_set_drvdata(pdev, vdev);
+     vdev->pdev = pdev;
+
+     ret = pcim_enable_device(pdev);
+     if (ret) {
+             vdev_err(vdev, "Failed to enable device %d", ret);
+             return ret;
+     }
+
+     vdev->io_regs = pcim_iomap_region(vdev->pdev, MGMT_BAR, DRV_NAME);
+     if (IS_ERR(vdev->io_regs)) {
+             vdev_err(vdev, "Failed to map RM shared memory BAR%d", 

MGMT_BAR);
+             return PTR_ERR(vdev->io_regs);
+     }
+
+     ret = versal_pci_device_setup(vdev);
+     if (ret) {

Quoted 8 lines
Quoted 5 lines

+             vdev_err(vdev, "Failed to setup Versal device %d", ret); +             return ret;
+     }
+
+     vdev_dbg(vdev, "Successfully probed %s driver!", DRV_NAME);

Usually, such debug messages are not needed.
No strong opinion about it.

I will remove this. The dbg only enable in the debug kernel, but this line isn't necessary. I will fix it.

Quoted 7 lines
Quoted 3 lines

+     return 0;
+}

...

CJ

#6 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

In reply to Yidong Zhang

Le 10/12/2024 à 19:37, Yidong Zhang a écrit :

Quoted 3 lines

AMD Versal based PCIe card, including V70, is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications.

...

drivers/fpga/amd/versal-pci.h line 26

Quoted 11 lines
drivers/fpga/amd/versal-pci.h new file +11 -0
+#define vdev_info(vdev, fmt, args...)					\
+	dev_info(&(vdev)->pdev->dev, "%s: "fmt, __func__, ##args)
+
+#define vdev_warn(vdev, fmt, args...)					\
+	dev_warn(&(vdev)->pdev->dev, "%s: "fmt, __func__, ##args)
+
+#define vdev_err(vdev, fmt, args...)					\
+	dev_err(&(vdev)->pdev->dev, "%s: "fmt, __func__, ##args)
+
+#define vdev_dbg(vdev, fmt, args...)					\
+	dev_dbg(&(vdev)->pdev->dev, fmt, ##args)

These helpers could also add the trailing \n. It is apparently not added in the messages themselves.

CJ

#7 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

In reply to Yidong Zhang
Quoted 45 lines · Yidong Zhang

AMD Versal based PCIe card, including V70, is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications.

The driver architecture:

  +---------+  Communication +---------+  Remote  +-----+------+
  |         |  Channel       |         |  Queue   |     |      |
  | User PF | <============> | Mgmt PF | <=======>| FW  | FPGA |
  +---------+                +---------+          +-----+------+
    PL Data                    base FW

APU FW
PL Data (copy)
- PL (FPGA Program Logic)
- FW (Firmware)

There are 2 separate drivers from the original XRT[1] design.
- UserPF driver
- MgmtPF driver

The new AMD versal-pci driver will replace the MgmtPF driver for Versal PCIe card.

The XRT[1] is already open-sourced. It includes solution of runtime for many different type of PCIe Based cards. It also provides utilities for managing and programming the devices.

The AMD versal-pci stands for AMD Versal brand PCIe device management driver. This driver provides the following functionalities:

- module and PCI device initialization
this driver will attach to specific device id of V70 card; the driver will initialize itself based on bar resources for
- communication channel:
a hardware message service between mgmt PF and user PF
- remote queue:
a hardware queue based ring buffer service between mgmt PF and PCIe hardware firmware for programming FPGA Program Logic, loading firmware and checking card healthy status.

- programming FW
- The base FW is downloaded onto the flash of the card.
- The APU FW is downloaded once after a POR (power on reset).
- Reloading the MgmtPF driver will not change any existing hardware.

Quoted 5 lines

- programming FPGA hardware binaries - PL Data
- using fpga framework ops to support re-programing FPGA
- the re-programming request will be initiated from the existing UserPF driver only, and the MgmtPF driver load the matched PL Data after receiving request from the communication channel. The matching PL

I think this is not the way the FPGA generic framework should do. A FPGA region user (your userPF driver) should not also be the reprogram requester. The user driver cannot deal with the unexpected HW change if it happens. Maybe after reprogramming, the user driver cannot match the device anymore, and if user driver is still working on it, crash.

The expected behavior is, the FPGA region removes user devices (thus detaches user drivers), does reprogramming, re-enumerates/rescans and matches new devices with new drivers. And I think that's what Nava is working on.

BTW, AFAICS the expected flow is easier to implement for of-fpga-region, but harder for PCI devices. But I think that's the right direction and should try to work it out.

Thanks,
Yilun

#8 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 55 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 45 lines · Yidong Zhang

AMD Versal based PCIe card, including V70, is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications.

The driver architecture:

   +---------+  Communication +---------+  Remote  +-----+------+
   |         |  Channel       |         |  Queue   |     |      |
   | User PF | <============> | Mgmt PF | <=======>| FW  | FPGA |
   +---------+                +---------+          +-----+------+
     PL Data                    base FW

APU FW
PL Data (copy)
- PL (FPGA Program Logic)
- FW (Firmware)

There are 2 separate drivers from the original XRT[1] design.
- UserPF driver
- MgmtPF driver

The new AMD versal-pci driver will replace the MgmtPF driver for Versal PCIe card.

The XRT[1] is already open-sourced. It includes solution of runtime for many different type of PCIe Based cards. It also provides utilities for managing and programming the devices.

The AMD versal-pci stands for AMD Versal brand PCIe device management driver. This driver provides the following functionalities:

- module and PCI device initialization
this driver will attach to specific device id of V70 card; the driver will initialize itself based on bar resources for
- communication channel:
a hardware message service between mgmt PF and user PF
- remote queue:
a hardware queue based ring buffer service between mgmt PF and PCIe hardware firmware for programming FPGA Program Logic, loading firmware and checking card healthy status.

- programming FW
- The base FW is downloaded onto the flash of the card.
- The APU FW is downloaded once after a POR (power on reset).
- Reloading the MgmtPF driver will not change any existing hardware.

Quoted 5 lines

- programming FPGA hardware binaries - PL Data
- using fpga framework ops to support re-programing FPGA
- the re-programming request will be initiated from the existing UserPF driver only, and the MgmtPF driver load the matched PL Data after receiving request from the communication channel. The matching PL

Quoted 5 lines

I think this is not the way the FPGA generic framework should do. A FPGA region user (your userPF driver) should not also be the reprogram requester. The user driver cannot deal with the unexpected HW change if it happens. Maybe after reprogramming, the user driver cannot match the device anymore, and if user driver is still working on it, crash.

One thing to clarify. The current design is:

The userPF driver is the only requester. The mgmtPF has no uAPI to reprogram the FPGA.

Quoted 6 lines

The expected behavior is, the FPGA region removes user devices (thus detaches user drivers), does reprogramming, re-enumerates/rescans and matches new devices with new drivers. And I think that's what Nava is working on.

Nava's work is different than our current design, our current design is:

the separate userPF driver will detach all services before requesting to the mgmtPF to program the FPGA, and after the programming is done, the userPF will re-enumerate/rescan the matching new devices.

The mgmtPF is a util driver which is responsible for communicating with the mgmtPF PCIe bar resources.

Quoted 3 lines

BTW, AFAICS the expected flow is easier to implement for of-fpga-region, but harder for PCI devices. But I think that's the right direction and should try to work it out.

Could I recap the suggested design if I understand that correctly...

You are thinking that the mgmtPF (aka. versal-pci) driver should have a uAPI to trigger the FPGA re-programing; and using Nava's callback ops to detach the separate userPF driver; after re-programing is done, re-attch the userPF driver and allow the userPF driver re-enumerate all to match the new hardware.

I think my understanding is correct, it is doable.

As long as we can keep our userPF driver as separate driver, the code change won't be too big.

Quoted 3 lines

Thanks,
Yilun

#9 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 77 lines · Yidong Zhang
Quoted 55 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 45 lines · Yidong Zhang

AMD Versal based PCIe card, including V70, is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications.

The driver architecture:

   +---------+  Communication +---------+  Remote  +-----+------+
   |         |  Channel       |         |  Queue   |     |      |
   | User PF | <============> | Mgmt PF | <=======>| FW  | FPGA |
   +---------+                +---------+          +-----+------+
     PL Data                    base FW

APU FW
PL Data (copy)
- PL (FPGA Program Logic)
- FW (Firmware)

There are 2 separate drivers from the original XRT[1] design.
- UserPF driver
- MgmtPF driver

The new AMD versal-pci driver will replace the MgmtPF driver for Versal PCIe card.

The XRT[1] is already open-sourced. It includes solution of runtime for many different type of PCIe Based cards. It also provides utilities for managing and programming the devices.

The AMD versal-pci stands for AMD Versal brand PCIe device management driver. This driver provides the following functionalities:

- module and PCI device initialization
this driver will attach to specific device id of V70 card; the driver will initialize itself based on bar resources for
- communication channel:
a hardware message service between mgmt PF and user PF
- remote queue:
a hardware queue based ring buffer service between mgmt PF and PCIe hardware firmware for programming FPGA Program Logic, loading firmware and checking card healthy status.

- programming FW
- The base FW is downloaded onto the flash of the card.
- The APU FW is downloaded once after a POR (power on reset).
- Reloading the MgmtPF driver will not change any existing hardware.

Quoted 5 lines

- programming FPGA hardware binaries - PL Data
- using fpga framework ops to support re-programing FPGA
- the re-programming request will be initiated from the existing UserPF driver only, and the MgmtPF driver load the matched PL Data after receiving request from the communication channel. The matching PL

Quoted 5 lines

I think this is not the way the FPGA generic framework should do. A FPGA region user (your userPF driver) should not also be the reprogram requester. The user driver cannot deal with the unexpected HW change if it happens. Maybe after reprogramming, the user driver cannot match the device anymore, and if user driver is still working on it, crash.

One thing to clarify. The current design is:

The userPF driver is the only requester. The mgmtPF has no uAPI to reprogram the FPGA.

Quoted 6 lines

The expected behavior is, the FPGA region removes user devices (thus detaches user drivers), does reprogramming, re-enumerates/rescans and matches new devices with new drivers. And I think that's what Nava is working on.

Quoted 5 lines

Nava's work is different than our current design, our current design is:

the separate userPF driver will detach all services before requesting to the mgmtPF to program the FPGA, and after the programming is done, the userPF will re-enumerate/rescan the matching new devices.

That's not align with the Device-Driver Model, A device driver should not re-enumerate/rescan a matching device.

Quoted 5 lines

The mgmtPF is a util driver which is responsible for communicating with the mgmtPF PCIe bar resources.

Quoted 7 lines
Quoted 3 lines

BTW, AFAICS the expected flow is easier to implement for of-fpga-region, but harder for PCI devices. But I think that's the right direction and should try to work it out.

Could I recap the suggested design if I understand that correctly...

You are thinking that the mgmtPF (aka. versal-pci) driver should have a uAPI

This should be the unified fpga-region class uAPI.

Quoted 2 lines

to trigger the FPGA re-programing; and using Nava's callback ops to detach the separate userPF driver; after re-programing is done, re-attch the userPF

No need to detach a specific driver, remove all devices in the fpga-region. I imagine this could also be a generic flow for all PCI/e based FPGA cards.

Thanks,
Yilun

Quoted 11 lines

driver and allow the userPF driver re-enumerate all to match the new hardware.

I think my understanding is correct, it is doable.

As long as we can keep our userPF driver as separate driver, the code change won't be too big.

Quoted 3 lines

Thanks,
Yilun

#10 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 81 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 77 lines · Yidong Zhang
Quoted 55 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 45 lines · Yidong Zhang

AMD Versal based PCIe card, including V70, is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications.

The driver architecture:

    +---------+  Communication +---------+  Remote  +-----+------+
    |         |  Channel       |         |  Queue   |     |      |
    | User PF | <============> | Mgmt PF | <=======>| FW  | FPGA |
    +---------+                +---------+          +-----+------+
      PL Data                    base FW

APU FW
PL Data (copy)
- PL (FPGA Program Logic)
- FW (Firmware)

There are 2 separate drivers from the original XRT[1] design.
- UserPF driver
- MgmtPF driver

The new AMD versal-pci driver will replace the MgmtPF driver for Versal PCIe card.

The XRT[1] is already open-sourced. It includes solution of runtime for many different type of PCIe Based cards. It also provides utilities for managing and programming the devices.

The AMD versal-pci stands for AMD Versal brand PCIe device management driver. This driver provides the following functionalities:

- module and PCI device initialization
this driver will attach to specific device id of V70 card; the driver will initialize itself based on bar resources for
- communication channel:
a hardware message service between mgmt PF and user PF
- remote queue:
a hardware queue based ring buffer service between mgmt PF and PCIe hardware firmware for programming FPGA Program Logic, loading firmware and checking card healthy status.

- programming FW
- The base FW is downloaded onto the flash of the card.
- The APU FW is downloaded once after a POR (power on reset).
- Reloading the MgmtPF driver will not change any existing hardware.

Quoted 5 lines

- programming FPGA hardware binaries - PL Data
- using fpga framework ops to support re-programing FPGA
- the re-programming request will be initiated from the existing UserPF driver only, and the MgmtPF driver load the matched PL Data after receiving request from the communication channel. The matching PL

Quoted 5 lines

I think this is not the way the FPGA generic framework should do. A FPGA region user (your userPF driver) should not also be the reprogram requester. The user driver cannot deal with the unexpected HW change if it happens. Maybe after reprogramming, the user driver cannot match the device anymore, and if user driver is still working on it, crash.

One thing to clarify. The current design is:

The userPF driver is the only requester. The mgmtPF has no uAPI to reprogram the FPGA.

Quoted 6 lines

The expected behavior is, the FPGA region removes user devices (thus detaches user drivers), does reprogramming, re-enumerates/rescans and matches new devices with new drivers. And I think that's what Nava is working on.

Quoted 8 lines
Quoted 5 lines

Nava's work is different than our current design, our current design is:

the separate userPF driver will detach all services before requesting to the mgmtPF to program the FPGA, and after the programming is done, the userPF will re-enumerate/rescan the matching new devices.

That's not align with the Device-Driver Model, A device driver should not re-enumerate/rescan a matching device.

Thanks! Yilun.

I will need to discuss this in my team. Our current userPF driver organize services (rom, sensor, msix, etc.) as platform driver and re-enumerate (online/offline) when there is a hardware change.

Quoted 14 lines
Quoted 6 lines

The mgmtPF is a util driver which is responsible for communicating with the mgmtPF PCIe bar resources.

Quoted 7 lines
Quoted 3 lines

BTW, AFAICS the expected flow is easier to implement for of-fpga-region, but harder for PCI devices. But I think that's the right direction and should try to work it out.

Could I recap the suggested design if I understand that correctly...

You are thinking that the mgmtPF (aka. versal-pci) driver should have a uAPI

Quoted 8 lines

This should be the unified fpga-region class uAPI.

Quoted 2 lines

to trigger the FPGA re-programing; and using Nava's callback ops to detach the separate userPF driver; after re-programing is done, re-attch the userPF

No need to detach a specific driver, remove all devices in the fpga-region. I imagine this could also be a generic flow for all PCI/e based FPGA cards.

I see your point. Is there an existing example in current fpga driver for PCI/e based cards?

We will need to talk to our management team and re-design our driver.
I think we have 2 approaches:
1) Align with linux fpga, having one driver for both userPF and mgmtPF; or
2) find a different location (maybe driver/misc) for the version-pci driver, because it is an utility driver, not need to be tied with fpga framework.

Please let me know you thoughts. Which way is acceptable by you.

Thanks,
David

Quoted 15 lines

Thanks,
Yilun

Quoted 11 lines

driver and allow the userPF driver re-enumerate all to match the new hardware.

I think my understanding is correct, it is doable.

As long as we can keep our userPF driver as separate driver, the code change won't be too big.

Quoted 3 lines

Thanks,
Yilun

#11 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 6 lines
Quoted 3 lines

No need to detach a specific driver, remove all devices in the fpga-region. I imagine this could also be a generic flow for all PCI/e based FPGA cards.

I see your point. Is there an existing example in current fpga driver for PCI/e based cards?

No. The fpga-region re-enumeration arch is still WIP, so no existing implementation.

Quoted 4 lines

We will need to talk to our management team and re-design our driver. I think we have 2 approaches:
1) Align with linux fpga, having one driver for both userPF and mgmtPF; or

Don't get you. Linux FPGA doesn't require one driver for both PFs.

Quoted 2 lines

2) find a different location (maybe driver/misc) for the version-pci driver, because it is an utility driver, not need to be tied with fpga framework.

I'm not the misc maintainer, but I assume in-tree utility driver + out-of-tree client driver is not generally welcomed.

Thanks,
Yilun

Quoted 20 lines

Please let me know you thoughts. Which way is acceptable by you.

Thanks,
David

Quoted 15 lines

Thanks,
Yilun

Quoted 11 lines

driver and allow the userPF driver re-enumerate all to match the new hardware.

I think my understanding is correct, it is doable.

As long as we can keep our userPF driver as separate driver, the code change won't be too big.

Quoted 3 lines

Thanks,
Yilun

#12 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 7 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 4 lines
Quoted 3 lines

No need to detach a specific driver, remove all devices in the fpga-region. I imagine this could also be a generic flow for all PCI/e based FPGA cards.

Quoted 5 lines
Quoted 2 lines

I see your point. Is there an existing example in current fpga driver for PCI/e based cards?

No. The fpga-region re-enumeration arch is still WIP, so no existing implementation.

Got you. I can also help to test or provide feedback.
Actually, I had sent Nava my protype of using configfs for the non-OF driver. He should have the updated patch soon.

Quoted 7 lines
Quoted 5 lines

We will need to talk to our management team and re-design our driver. I think we have 2 approaches:
1) Align with linux fpga, having one driver for both userPF and mgmtPF; or

Don't get you. Linux FPGA doesn't require one driver for both PFs.

I assume when you said "generic flow for removing all devices in fpga-region" means that there is a single driver which use the fpga-region callbacks to remove all devices and then re-progream the FPGA.

On AMD V70 hardware, the userPF has different deviceid than the mgmtPF. Thus, our current design is having 2 separate pcie drivers for each different deviceid.

Thus, in our current design, the fpga-region should be in the userPF driver which has callbacks to remove all devices. But in mgmtPF, it is more like a utility which only handles request from the userPF but it has the management privilege. Usually, cloud vendors require the mgmtPF deployed in their secured domain (can be a separate physical machine).

We can keep 2 drivers, one for userPF, one for mgmtPF. The userPF and mgmtPF communicate each other via the communication channel because they can be physically on different machine.

Are you looking for us to upstream both of them together?
If yes, I still think that the fpga-region should be in the userPF driver. The mgmtPF driver is still a utility driver.

Please correct me if I am wrong.:)

Quoted 6 lines
Quoted 3 lines

2) find a different location (maybe driver/misc) for the version-pci driver, because it is an utility driver, not need to be tied with fpga framework.

I'm not the misc maintainer, but I assume in-tree utility driver + out-of-tree client driver is not generally welcomed.

Great info! Thanks! I will have to discuss this with my team too.

My understanding, so far based on your comments above, the drivers/fpga prefer to use fpga-region ops to handle FPGA re-program changes.

The current versal-pci driver is a utility driver. The fpga-region should be within the userPF driver.

We can try to make our userPF driver in-tree as well. But the current plan is to do it later.

If you prefer we do both of them together. I can talk to my team.

Thanks,
David

Quoted 24 lines

Thanks,
Yilun

Quoted 20 lines

Please let me know you thoughts. Which way is acceptable by you.

Thanks,
David

Quoted 15 lines

Thanks,
Yilun

Quoted 11 lines

driver and allow the userPF driver re-enumerate all to match the new hardware.

I think my understanding is correct, it is doable.

As long as we can keep our userPF driver as separate driver, the code change won't be too big.

Quoted 3 lines

Thanks,
Yilun

#13 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 32 lines · Yidong Zhang
Quoted 7 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 4 lines
Quoted 3 lines

No need to detach a specific driver, remove all devices in the fpga-region. I imagine this could also be a generic flow for all PCI/e based FPGA cards.

Quoted 5 lines
Quoted 2 lines

I see your point. Is there an existing example in current fpga driver for PCI/e based cards?

No. The fpga-region re-enumeration arch is still WIP, so no existing implementation.

Got you. I can also help to test or provide feedback. Actually, I had sent Nava my protype of using configfs for the non-OF driver. He should have the updated patch soon.

Quoted 7 lines
Quoted 5 lines

We will need to talk to our management team and re-design our driver. I think we have 2 approaches:
1) Align with linux fpga, having one driver for both userPF and mgmtPF; or

Don't get you. Linux FPGA doesn't require one driver for both PFs.

I assume when you said "generic flow for removing all devices in fpga-region" means that there is a single driver which use the fpga-region callbacks to remove all devices and then re-progream the FPGA.

Quoted 6 lines

On AMD V70 hardware, the userPF has different deviceid than the mgmtPF. Thus, our current design is having 2 separate pcie drivers for each different deviceid.

Thus, in our current design, the fpga-region should be in the userPF driver which has callbacks to remove all devices. But in mgmtPF, it is more like a

A question, if the FPGA logic is cleared, does the userPF still exist on PCIe bus?

Quoted 3 lines

utility which only handles request from the userPF but it has the management privilege. Usually, cloud vendors require the mgmtPF deployed in their secured domain (can be a separate physical machine).

I though mgmtPF & userPF are just 2 functions on one PCIe card, they are not? Then how the mgmtPF writes data to another physical machine and influence the userPF?

Thanks,
Yilun

Quoted 57 lines

We can keep 2 drivers, one for userPF, one for mgmtPF. The userPF and mgmtPF communicate each other via the communication channel because they can be physically on different machine.

Are you looking for us to upstream both of them together?
If yes, I still think that the fpga-region should be in the userPF driver. The mgmtPF driver is still a utility driver.

Please correct me if I am wrong.:)

Quoted 6 lines
Quoted 3 lines

2) find a different location (maybe driver/misc) for the version-pci driver, because it is an utility driver, not need to be tied with fpga framework.

I'm not the misc maintainer, but I assume in-tree utility driver + out-of-tree client driver is not generally welcomed.

Great info! Thanks! I will have to discuss this with my team too.

My understanding, so far based on your comments above, the drivers/fpga prefer to use fpga-region ops to handle FPGA re-program changes.

The current versal-pci driver is a utility driver. The fpga-region should be within the userPF driver.

We can try to make our userPF driver in-tree as well. But the current plan is to do it later.

If you prefer we do both of them together. I can talk to my team.

Thanks,
David

Quoted 24 lines

Thanks,
Yilun

Quoted 20 lines

Please let me know you thoughts. Which way is acceptable by you.

Thanks,
David

Quoted 15 lines

Thanks,
Yilun

Quoted 11 lines

driver and allow the userPF driver re-enumerate all to match the new hardware.

I think my understanding is correct, it is doable.

As long as we can keep our userPF driver as separate driver, the code change won't be too big.

Quoted 3 lines

Thanks,
Yilun

#14 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 40 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 36 lines · Yidong Zhang
Quoted 7 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 4 lines
Quoted 3 lines

No need to detach a specific driver, remove all devices in the fpga-region. I imagine this could also be a generic flow for all PCI/e based FPGA cards.

Quoted 5 lines
Quoted 2 lines

I see your point. Is there an existing example in current fpga driver for PCI/e based cards?

No. The fpga-region re-enumeration arch is still WIP, so no existing implementation.

Got you. I can also help to test or provide feedback. Actually, I had sent Nava my protype of using configfs for the non-OF driver. He should have the updated patch soon.

Quoted 7 lines
Quoted 5 lines

We will need to talk to our management team and re-design our driver. I think we have 2 approaches:
1) Align with linux fpga, having one driver for both userPF and mgmtPF; or

Don't get you. Linux FPGA doesn't require one driver for both PFs.

I assume when you said "generic flow for removing all devices in fpga-region" means that there is a single driver which use the fpga-region callbacks to remove all devices and then re-progream the FPGA.

On AMD V70 hardware, the userPF has different deviceid than the mgmtPF. Thus, our current design is having 2 separate pcie drivers for each different deviceid.

Quoted 5 lines
Quoted 2 lines

Thus, in our current design, the fpga-region should be in the userPF driver which has callbacks to remove all devices. But in mgmtPF, it is more like a

A question, if the FPGA logic is cleared, does the userPF still exist on PCIe bus?

I am not sure I fully understand your question by "FPGA logic is cleared". Based on our design, the userPF exists, but all services need to be re-configured after hardware is changed.

Quoted 9 lines
Quoted 4 lines

utility which only handles request from the userPF but it has the management privilege. Usually, cloud vendors require the mgmtPF deployed in their secured domain (can be a separate physical machine).

I though mgmtPF & userPF are just 2 functions on one PCIe card, they are not? Then how the mgmtPF writes data to another physical machine and influence the userPF?

They are functions but they also have different device id thus we can bind different driver onto each of them.

I think I should interrupt it accurately as Host and VM. See details here please:
https://xilinx.github.io/XRT/2019.2/html/cloud_vendor_support.html

But, my point is that we do have 2 separate drivers.

Please let me know if you need more detailed info.

/David

Quoted 60 lines

Thanks,
Yilun

Quoted 57 lines

We can keep 2 drivers, one for userPF, one for mgmtPF. The userPF and mgmtPF communicate each other via the communication channel because they can be physically on different machine.

Are you looking for us to upstream both of them together?
If yes, I still think that the fpga-region should be in the userPF driver. The mgmtPF driver is still a utility driver.

Please correct me if I am wrong.:)

Quoted 6 lines
Quoted 3 lines

2) find a different location (maybe driver/misc) for the version-pci driver, because it is an utility driver, not need to be tied with fpga framework.

I'm not the misc maintainer, but I assume in-tree utility driver + out-of-tree client driver is not generally welcomed.

Great info! Thanks! I will have to discuss this with my team too.

My understanding, so far based on your comments above, the drivers/fpga prefer to use fpga-region ops to handle FPGA re-program changes.

The current versal-pci driver is a utility driver. The fpga-region should be within the userPF driver.

We can try to make our userPF driver in-tree as well. But the current plan is to do it later.

If you prefer we do both of them together. I can talk to my team.

Thanks,
David

Quoted 24 lines

Thanks,
Yilun

Quoted 20 lines

Please let me know you thoughts. Which way is acceptable by you.

Thanks,
David

Quoted 15 lines

Thanks,
Yilun

Quoted 11 lines

driver and allow the userPF driver re-enumerate all to match the new hardware.

I think my understanding is correct, it is doable.

As long as we can keep our userPF driver as separate driver, the code change won't be too big.

Quoted 3 lines

Thanks,
Yilun

#15 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 46 lines · Yidong Zhang
Quoted 43 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 38 lines · Yidong Zhang
Quoted 7 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 4 lines
Quoted 3 lines

No need to detach a specific driver, remove all devices in the fpga-region. I imagine this could also be a generic flow for all PCI/e based FPGA cards.

Quoted 5 lines
Quoted 2 lines

I see your point. Is there an existing example in current fpga driver for PCI/e based cards?

No. The fpga-region re-enumeration arch is still WIP, so no existing implementation.

Got you. I can also help to test or provide feedback. Actually, I had sent Nava my protype of using configfs for the non-OF driver. He should have the updated patch soon.

Quoted 7 lines
Quoted 5 lines

We will need to talk to our management team and re-design our driver. I think we have 2 approaches:
1) Align with linux fpga, having one driver for both userPF and mgmtPF; or

Don't get you. Linux FPGA doesn't require one driver for both PFs.

I assume when you said "generic flow for removing all devices in fpga-region" means that there is a single driver which use the fpga-region callbacks to remove all devices and then re-progream the FPGA.

On AMD V70 hardware, the userPF has different deviceid than the mgmtPF. Thus, our current design is having 2 separate pcie drivers for each different deviceid.

Thus, in our current design, the fpga-region should be in the userPF driver which has callbacks to remove all devices. But in mgmtPF, it is more like a

Quoted 6 lines
Quoted 2 lines

A question, if the FPGA logic is cleared, does the userPF still exist on PCIe bus?

I am not sure I fully understand your question by "FPGA logic is cleared". Based on our design, the userPF exists, but all services need to be re-configured after hardware is changed.

I briefly read your XRT docs. IIUC we are talking about reprogramming the "Dynamic Region", not the "Shell".

The userPF's PCIe basic functionality is in Shell and is out of our reprograming discussion. So userPF PCI device always exists even if the "Dynamic Region" is being reprogrammed. In this case, we should create fpga-region for this "Dynamic Region" in userPF driver.

userPF uses some HW communication channel to require reprograming, so fpga-manager could also be implemented in userPF driver.

And I agree the mgmtPF driver is a utility driver that just monitor on the communication channel and serve requirements, nothing to do with FPGA framework. I have no objection to put it in misc or firmware directory.

What I'm not sure is whether a standalone utility driver in kernel tree is preferred (at least I don't). You may talk to other maintainers.

Quoted 12 lines
Quoted 11 lines
Quoted 6 lines

utility which only handles request from the userPF but it has the management privilege. Usually, cloud vendors require the mgmtPF deployed in their secured domain (can be a separate physical machine).

I though mgmtPF & userPF are just 2 functions on one PCIe card, they are not? Then how the mgmtPF writes data to another physical machine and influence the userPF?

Quoted 8 lines

They are functions but they also have different device id thus we can bind different driver onto each of them.

I think I should interrupt it accurately as Host and VM. See details here please:
https://xilinx.github.io/XRT/2019.2/html/cloud_vendor_support.html

But, my point is that we do have 2 separate drivers.

OK, having 2 separate drivers is definitely fine.

Thanks,
Yilun

#16 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 60 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 46 lines · Yidong Zhang
Quoted 43 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 38 lines · Yidong Zhang
Quoted 7 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 4 lines
Quoted 3 lines

No need to detach a specific driver, remove all devices in the fpga-region. I imagine this could also be a generic flow for all PCI/e based FPGA cards.

Quoted 5 lines
Quoted 2 lines

I see your point. Is there an existing example in current fpga driver for PCI/e based cards?

No. The fpga-region re-enumeration arch is still WIP, so no existing implementation.

Got you. I can also help to test or provide feedback. Actually, I had sent Nava my protype of using configfs for the non-OF driver. He should have the updated patch soon.

Quoted 7 lines
Quoted 5 lines

We will need to talk to our management team and re-design our driver. I think we have 2 approaches:
1) Align with linux fpga, having one driver for both userPF and mgmtPF; or

Don't get you. Linux FPGA doesn't require one driver for both PFs.

I assume when you said "generic flow for removing all devices in fpga-region" means that there is a single driver which use the fpga-region callbacks to remove all devices and then re-progream the FPGA.

On AMD V70 hardware, the userPF has different deviceid than the mgmtPF. Thus, our current design is having 2 separate pcie drivers for each different deviceid.

Thus, in our current design, the fpga-region should be in the userPF driver which has callbacks to remove all devices. But in mgmtPF, it is more like a

Quoted 6 lines
Quoted 2 lines

A question, if the FPGA logic is cleared, does the userPF still exist on PCIe bus?

I am not sure I fully understand your question by "FPGA logic is cleared". Based on our design, the userPF exists, but all services need to be re-configured after hardware is changed.

I briefly read your XRT docs. IIUC we are talking about reprogramming the "Dynamic Region", not the "Shell".

Quoted 8 lines

The userPF's PCIe basic functionality is in Shell and is out of our reprograming discussion. So userPF PCI device always exists even if the "Dynamic Region" is being reprogrammed. In this case, we should create fpga-region for this "Dynamic Region" in userPF driver.

userPF uses some HW communication channel to require reprograming, so fpga-manager could also be implemented in userPF driver.

Thanks for taking your time reading our documents. You are exactly correct. We will use fpga-manager and fpga-region in our userPF driver for upstreaming. If you think this is acceptable by linux fpga framework. I will talk to my team for next step.

Quoted 8 lines

And I agree the mgmtPF driver is a utility driver that just monitor on the communication channel and serve requirements, nothing to do with FPGA framework. I have no objection to put it in misc or firmware directory.

What I'm not sure is whether a standalone utility driver in kernel tree is preferred (at least I don't). You may talk to other maintainers.

My last question for this topic:
If we decide to upstream both userPF and mgmtPF driver together, could them be both within the drivers/fpga/amd as in-tree driver? This will help user find source code easily.

Thanks,
David

Quoted 25 lines
Quoted 12 lines
Quoted 11 lines
Quoted 6 lines

utility which only handles request from the userPF but it has the management privilege. Usually, cloud vendors require the mgmtPF deployed in their secured domain (can be a separate physical machine).

I though mgmtPF & userPF are just 2 functions on one PCIe card, they are not? Then how the mgmtPF writes data to another physical machine and influence the userPF?

Quoted 8 lines

They are functions but they also have different device id thus we can bind different driver onto each of them.

I think I should interrupt it accurately as Host and VM. See details here please:
https://xilinx.github.io/XRT/2019.2/html/cloud_vendor_support.html

But, my point is that we do have 2 separate drivers.

OK, having 2 separate drivers is definitely fine.

Thanks,
Yilun

#17 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 3 lines

My last question for this topic:
If we decide to upstream both userPF and mgmtPF driver together, could them be both within the drivers/fpga/amd as in-tree driver? This will help user

I don't look into your full driver stack. Generally, if your drivers are all about reprogramming, then yes. If they are also about all kinds of accelaration functions you'd better split them out in different domains. I may not have enough knowledge to make them correct.

Thanks,
Yilun

Quoted 1 line

find source code easily.

#18 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 12 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 3 lines

My last question for this topic:
If we decide to upstream both userPF and mgmtPF driver together, could them be both within the drivers/fpga/amd as in-tree driver? This will help user

I don't look into your full driver stack. Generally, if your drivers are all about reprogramming, then yes. If they are also about all kinds of accelaration functions you'd better split them out in different domains. I may not have enough knowledge to make them correct.

The driver has more features than just re-programing. The re-programing is already done in the embedded firmware that's why the mgmtPF driver is just a utility driver.

The userPF driver has features such as:
xdma (already in drivers/xilinx/xdma as platform driver) qdma (already in drivers/amd/qdma as platform driver) mailbox and more which have not been upstreamed in linux kernel yet.

The driver architecture is:

  userPF driver (as pci_driver)
    qdma (as platform_driver)
    ..
    mailbox (as platform_driver)
       /\
       ||
       \/
    mailbox (as platform_driver)
  mgmtPF driver (as pci_driver)
       /\
       ||
       \/
    Embedded firmware (re-programing done here)

Right now, I am working on upstreaming the mgmtPF driver as pci_driver.
In the future, I think the userPF driver should be fitting into the
"drivers/fpga", given that should manage all these platform_drivers and utilize the fpga_region callbacks to online/offline services due to hardware changes after re-programing.

Thanks,
David

Quoted 4 lines

Thanks,
Yilun

Quoted 1 line

find source code easily.

#19 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 41 lines · Yidong Zhang
Quoted 12 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 3 lines

My last question for this topic:
If we decide to upstream both userPF and mgmtPF driver together, could them be both within the drivers/fpga/amd as in-tree driver? This will help user

I don't look into your full driver stack. Generally, if your drivers are all about reprogramming, then yes. If they are also about all kinds of accelaration functions you'd better split them out in different domains. I may not have enough knowledge to make them correct.

The driver has more features than just re-programing. The re-programing is already done in the embedded firmware that's why the mgmtPF driver is just a utility driver.

The userPF driver has features such as:
xdma (already in drivers/xilinx/xdma as platform driver) qdma (already in drivers/amd/qdma as platform driver) mailbox and more which have not been upstreamed in linux kernel yet.

The driver architecture is:

  userPF driver (as pci_driver)
    qdma (as platform_driver)
    ..
    mailbox (as platform_driver)
       /\
       ||
       \/
    mailbox (as platform_driver)
  mgmtPF driver (as pci_driver)
       /\
       ||
       \/
    Embedded firmware (re-programing done here)
Quoted 3 lines

Right now, I am working on upstreaming the mgmtPF driver as pci_driver. In the future, I think the userPF driver should be fitting into the "drivers/fpga", given that should manage all these platform_drivers and

No I think userPF driver should manage all these *platform_devices*. Platform_drivers could be independent and put into proper domain folders.

Quoted 1 line

utilize the fpga_region callbacks to online/offline services due to hardware

fpga_region should online/offline platform devices. Not services, which is the job of each platform_driver.

Thanks,
Yilun

Quoted 9 lines

changes after re-programing.

Thanks,
David

Quoted 4 lines

Thanks,
Yilun

Quoted 1 line

find source code easily.

#20 lore raw

Re: [PATCH V2 1/4] drivers/fpga/amd: Add new driver amd versal-pci

Quoted 45 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 41 lines · Yidong Zhang
Quoted 12 lines · Xu Yilun

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 3 lines

My last question for this topic:
If we decide to upstream both userPF and mgmtPF driver together, could them be both within the drivers/fpga/amd as in-tree driver? This will help user

I don't look into your full driver stack. Generally, if your drivers are all about reprogramming, then yes. If they are also about all kinds of accelaration functions you'd better split them out in different domains. I may not have enough knowledge to make them correct.

The driver has more features than just re-programing. The re-programing is already done in the embedded firmware that's why the mgmtPF driver is just a utility driver.

The userPF driver has features such as:
xdma (already in drivers/xilinx/xdma as platform driver) qdma (already in drivers/amd/qdma as platform driver) mailbox and more which have not been upstreamed in linux kernel yet.

The driver architecture is:

   userPF driver (as pci_driver)
     qdma (as platform_driver)
     ..
     mailbox (as platform_driver)
        /\
        ||
        \/
     mailbox (as platform_driver)
   mgmtPF driver (as pci_driver)
        /\
        ||
        \/
     Embedded firmware (re-programing done here)
Quoted 5 lines
Quoted 3 lines

Right now, I am working on upstreaming the mgmtPF driver as pci_driver. In the future, I think the userPF driver should be fitting into the "drivers/fpga", given that should manage all these platform_drivers and

No I think userPF driver should manage all these *platform_devices*.

Yes, userPF driver manage all these "platform_devices" by leveraging the fpga_region callback ops. That's why I am thinking the userPF should be in drivers/fpga.

Quoted 1 line

Platform_drivers could be independent and put into proper domain folders.

Yes. All these "platform_devices" - drivers - should be put into proper domain. Aka, not in the drivers/fpga.

Quoted 5 lines
Quoted 2 lines

utilize the fpga_region callbacks to online/offline services due to hardware

fpga_region should online/offline platform devices. Not services, which is the job of each platform_driver.

Yes. I think we are thinking the same concept - online/offline platform devices. Not the services like probe/remove. The online/offline are separate ops just designed for the platform_devices to be online/offline.

Thanks,
David

Quoted 13 lines

Thanks,
Yilun

Quoted 9 lines

changes after re-programing.

Thanks,
David

Quoted 4 lines

Thanks,
Yilun

Quoted 1 line

find source code easily.

#21 lore raw

PATCH v2 2/4 drivers/fpga/amd: Add communication channel

In reply to Yidong Zhang

The communication channel (comm_chan) service is between versal-pci and the user PF driver. When the user PF driver requests PL data download, the comm_chan service will handle the request by versal_pci_load_xclbin.

---
 drivers/fpga/amd/Makefile               |   3 +-
 drivers/fpga/amd/versal-pci-comm-chan.c | 271 ++++++++++++++++++++++++
 drivers/fpga/amd/versal-pci-comm-chan.h |  14 ++
 drivers/fpga/amd/versal-pci-main.c      |  14 +-
 drivers/fpga/amd/versal-pci.h           |   2 +
 5 files changed, 301 insertions(+), 3 deletions(-)
 create mode 100644 drivers/fpga/amd/versal-pci-comm-chan.c
 create mode 100644 drivers/fpga/amd/versal-pci-comm-chan.h
drivers/fpga/amd/Makefile +2 -1
index 5d1ef04b5e80..7a604785e5f9 100644
@@ -2,4 +2,5 @@
 
 obj-$(CONFIG_AMD_VERSAL_PCI)			+= versal-pci.o
 
-versal-pci-$(CONFIG_AMD_VERSAL_PCI)		:= versal-pci-main.o
+versal-pci-$(CONFIG_AMD_VERSAL_PCI)		:= versal-pci-main.o \
+						   versal-pci-comm-chan.o
drivers/fpga/amd/versal-pci-comm-chan.c new file +271 -0

271 lines not on this page · raw message

drivers/fpga/amd/versal-pci-comm-chan.h new file +14 -0
new file mode 100644
index 000000000000..7605abc5527f
@@ -0,0 +1,14 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Driver for Versal PCIe device
+ *
+ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#ifndef __VERSAL_PCI_COMM_CHAN_H
+#define __VERSAL_PCI_COMM_CHAN_H
+
+struct comm_chan_device *versal_pci_comm_chan_init(struct versal_pci_device *vdev);
+void versal_pci_comm_chan_fini(struct comm_chan_device *ccdev);
+
+#endif	/* __VERSAL_PCI_COMM_CHAN_H */
drivers/fpga/amd/versal-pci-main.c +12 -2
index a10ccf86802b..a3b83197c6d5 100644
@@ -8,6 +8,7 @@
 #include <linux/pci.h>
 
 #include "versal-pci.h"
+#include "versal-pci-comm-chan.h"
 
 #define DRV_NAME			"amd-versal-pci"
 
@@ -238,6 +239,7 @@ static void versal_pci_device_teardown(struct versal_pci_device *vdev)
 {
 	versal_pci_fpga_fini(vdev->fdev);
 	versal_pci_fw_upload_fini(vdev->fwdev);
+	versal_pci_comm_chan_fini(vdev->ccdev);
 }
 
 static int versal_pci_device_setup(struct versal_pci_device *vdev)
@@ -251,15 +253,23 @@ static int versal_pci_device_setup(struct versal_pci_device *vdev)
 		return ret;
 	}
 
+	vdev->ccdev = versal_pci_comm_chan_init(vdev);
+	if (IS_ERR(vdev->ccdev)) {
+		ret = PTR_ERR(vdev->ccdev);
+		vdev_err(vdev, "Failed to init comms channel, err %d", ret);
+		goto upload_fini;
+	}
+
 	vdev->fdev = versal_pci_fpga_init(vdev);
 	if (IS_ERR(vdev->fdev)) {
 		ret = PTR_ERR(vdev->fdev);
 		vdev_err(vdev, "Failed to init FPGA manager, err %d", ret);
-		goto upload_fini;
+		goto comm_chan_fini;
 	}
 
 	return 0;
-
+comm_chan_fini:
+	versal_pci_comm_chan_fini(vdev->ccdev);
 upload_fini:
 	versal_pci_fw_upload_fini(vdev->fwdev);
 
drivers/fpga/amd/versal-pci.h +2 -0
index 1509bd0532ea..6c1ca3ce505d 100644
@@ -26,6 +26,7 @@
 	dev_dbg(&(vdev)->pdev->dev, fmt, ##args)
 
 struct versal_pci_device;
+struct comm_chan_device;
 
 struct axlf_header {
 	__u64				length;
@@ -69,6 +70,7 @@ struct versal_pci_device {
 	struct pci_dev			*pdev;
 
 	struct fpga_device		*fdev;
+	struct comm_chan_device         *ccdev;
 	struct firmware_device		*fwdev;
 	struct device			*device;
 
Signature · 1 line
2.34.1
#22 lore raw

Re: [PATCH V2 2/4] drivers/fpga/amd: Add communication channel

Le 10/12/2024 à 19:37, Yidong Zhang a écrit :

Quoted 3 lines

The communication channel (comm_chan) service is between versal-pci and the user PF driver. When the user PF driver requests PL data download, the comm_chan service will handle the request by versal_pci_load_xclbin.

...

drivers/fpga/amd/versal-pci-comm-chan.c line 43

Quoted 6 lines
drivers/fpga/amd/versal-pci-comm-chan.c new file +6 -0
+enum comm_chan_req_ops {
+	COMM_CHAN_REQ_OPS_UNKNOWN		= 0,
+	COMM_CHAN_REQ_OPS_HOT_RESET		= 5,
+	COMM_CHAN_REQ_OPS_GET_PROTOCOL_VERSION	= 19,
+	COMM_CHAN_REQ_OPS_LOAD_XCLBIN_UUID	= 20,
+	COMM_CHAN_REQ_OPS_MAX,

Unneeded comma after a terminator.

Quoted 1 line

+};

...

drivers/fpga/amd/versal-pci-comm-chan.c line 180

Quoted 4 lines
drivers/fpga/amd/versal-pci-comm-chan.c new file +4 -0
+static void comm_chan_check_request(struct work_struct *w)
+{
+	struct comm_chan_device *ccdev = to_ccdev_work(w);
+	u32 status = 0, request[COMM_CHAN_DATA_LEN] = {0};

These 2 initialisations are not needed.

Quoted 8 lines
drivers/fpga/amd/versal-pci-comm-chan.c new file +8 -0
+	struct comm_chan_hw_msg *hw_msg;
+	u8 type, eom;
+	int i;
+
+	status = comm_chan_read(ccdev, COMM_CHAN_REG_IS_OFF);
+	if (!STATUS_IS_READY(status))
+		return;
+	if (STATUS_IS_ERROR(status)) {

drivers/fpga/amd/versal-pci-comm-chan.c line 198

Quoted 10 lines
drivers/fpga/amd/versal-pci-comm-chan.c new file +10 -0
+		vdev_err(ccdev->vdev, "An error has occurred with comms");
+		return;
+	}
+
+	/* ACK status */
+	comm_chan_write(ccdev, COMM_CHAN_REG_IS_OFF, status);
+
+	for (i = 0; i < COMM_CHAN_DATA_LEN; i++)
+		request[i] = comm_chan_read(ccdev, COMM_CHAN_REG_RDDATA_OFF);
+

...

CJ

#23 lore raw

Re: [PATCH V2 2/4] drivers/fpga/amd: Add communication channel

Quoted 10 lines · Christophe JAILLET

Caution: This message originated from an External Source. Use proper caution when opening attachments, clicking links, or responding.

Quoted 3 lines · Yidong Zhang

The communication channel (comm_chan) service is between versal-pci and the user PF driver. When the user PF driver requests PL data download, the comm_chan service will handle the request by versal_pci_load_xclbin.

...

Quoted 8 lines
Quoted 6 lines

+enum comm_chan_req_ops {
+     COMM_CHAN_REQ_OPS_UNKNOWN               = 0, +     COMM_CHAN_REQ_OPS_HOT_RESET             = 5, +     COMM_CHAN_REQ_OPS_GET_PROTOCOL_VERSION  = 19, +     COMM_CHAN_REQ_OPS_LOAD_XCLBIN_UUID      = 20, +     COMM_CHAN_REQ_OPS_MAX,

Unneeded comma after a terminator.

Will fix this.

Quoted 11 lines
Quoted 2 lines

+};

...

drivers/fpga/amd/versal-pci-comm-chan.c line 180

Quoted 4 lines
drivers/fpga/amd/versal-pci-comm-chan.c new file +4 -0
+static void comm_chan_check_request(struct work_struct *w)
+{
+     struct comm_chan_device *ccdev = to_ccdev_work(w);
+     u32 status = 0, request[COMM_CHAN_DATA_LEN] = {0};

These 2 initialisations are not needed.

Will fix this.

Quoted 24 lines
Quoted 18 lines

+     struct comm_chan_hw_msg *hw_msg;
+     u8 type, eom;
+     int i;

drivers/fpga/amd/versal-pci-comm-chan.c new file +14 -0
+
+     status = comm_chan_read(ccdev, COMM_CHAN_REG_IS_OFF);
+     if (!STATUS_IS_READY(status))
+             return;
+     if (STATUS_IS_ERROR(status)) {
+             vdev_err(ccdev->vdev, "An error has occurred with comms");
+             return;
+     }
+
+     /* ACK status */
+     comm_chan_write(ccdev, COMM_CHAN_REG_IS_OFF, status);
+
+     for (i = 0; i < COMM_CHAN_DATA_LEN; i++)
+             request[i] = comm_chan_read(ccdev, 
Quoted 2 lines

COMM_CHAN_REG_RDDATA_OFF);
+

...

CJ

#24 lore raw

PATCH v2 3/4 drivers/fpga/amd: Add remote queue

In reply to Yidong Zhang

The remote queue is a hardware queue based ring buffer service between mgmt PF and PCIe hardware firmware for programming FPGA Program Logic, loading versal firmware and checking card healthy status.

---
 drivers/fpga/amd/Makefile                |   3 +-
 drivers/fpga/amd/versal-pci-rm-queue.c   | 326 +++++++++++++++++++++++
 drivers/fpga/amd/versal-pci-rm-queue.h   |  21 ++
 drivers/fpga/amd/versal-pci-rm-service.h | 209 +++++++++++++++
 4 files changed, 558 insertions(+), 1 deletion(-)
 create mode 100644 drivers/fpga/amd/versal-pci-rm-queue.c
 create mode 100644 drivers/fpga/amd/versal-pci-rm-queue.h
 create mode 100644 drivers/fpga/amd/versal-pci-rm-service.h
drivers/fpga/amd/Makefile +2 -1
index 7a604785e5f9..b2ffdbf23400 100644
@@ -3,4 +3,5 @@
 obj-$(CONFIG_AMD_VERSAL_PCI)			+= versal-pci.o
 
 versal-pci-$(CONFIG_AMD_VERSAL_PCI)		:= versal-pci-main.o \
-						   versal-pci-comm-chan.o
+						   versal-pci-comm-chan.o \
+						   versal-pci-rm-queue.o
drivers/fpga/amd/versal-pci-rm-queue.c new file +326 -0

326 lines not on this page · raw message

drivers/fpga/amd/versal-pci-rm-queue.h new file +21 -0
new file mode 100644
index 000000000000..3bc7102c6a58
@@ -0,0 +1,21 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+/*
+ * Driver for Versal PCIe device
+ *
+ * Copyright (C) 2024 Advanced Micro Devices, Inc. All rights reserved.
+ */
+
+#ifndef __RM_QUEUE_H
+#define __RM_QUEUE_H
+
+struct rm_device;
+
+/* rm queue hardware setup */
+int rm_queue_init(struct rm_device *rdev);
+void rm_queue_fini(struct rm_device *rdev);
+
+/* rm queue common API */
+int rm_queue_send_cmd(struct rm_cmd *cmd, unsigned long timeout);
+void rm_queue_withdraw_cmd(struct rm_cmd *cmd);
+
+#endif	/* __RM_QUEUE_H */
drivers/fpga/amd/versal-pci-rm-service.h new file +209 -0

209 lines not on this page · raw message

Signature · 1 line
2.34.1
#25 lore raw

Re: [PATCH V2 3/4] drivers/fpga/amd: Add remote queue

Le 10/12/2024 à 19:37, Yidong Zhang a écrit :

Quoted 3 lines

The remote queue is a hardware queue based ring buffer service between mgmt PF and PCIe hardware firmware for programming FPGA Program Logic, loading versal firmware and checking card healthy status.

...

drivers/fpga/amd/versal-pci-rm-queue.c line 127

Quoted 8 lines
drivers/fpga/amd/versal-pci-rm-queue.c new file +8 -0
+static int rm_queue_submit_cmd(struct rm_cmd *cmd)
+{
+	struct versal_pci_device *vdev = cmd->rdev->vdev;
+	struct rm_device *rdev = cmd->rdev;
+	u32 offset;
+	int ret;
+
+	mutex_lock(&rdev->queue);

Using guardmutex) would slightly simplify the code.

Quoted 16 lines
drivers/fpga/amd/versal-pci-rm-queue.c new file +16 -0
+
+	offset = rm_queue_get_sq_slot_offset(rdev);
+	if (!offset) {
+		vdev_err(vdev, "No SQ slot available");
+		ret = -ENOSPC;
+		goto exit;
+	}
+
+	rm_queue_bulk_write(rdev, offset, (u32 *)&cmd->sq_msg,
+			    sizeof(cmd->sq_msg));
+
+	ret = rm_queue_set_pidx(rdev, RM_QUEUE_SQ, ++rdev->sq.pidx);
+	if (ret) {
+		vdev_err(vdev, "Failed to update PIDX, ret %d", ret);
+		goto exit;
+	}

drivers/fpga/amd/versal-pci-rm-queue.c line 153

Quoted 10 lines
drivers/fpga/amd/versal-pci-rm-queue.c new file +10 -0
+
+	list_add_tail(&cmd->list, &rdev->submitted_cmds);
+exit:
+	mutex_unlock(&rdev->queue);
+	return ret;
+}
+
+void rm_queue_withdraw_cmd(struct rm_cmd *cmd)
+{
+	mutex_lock(&cmd->rdev->queue);

Using guardmutex) would slightly simplify the code.

Quoted 3 lines
drivers/fpga/amd/versal-pci-rm-queue.c new file +3 -0
+	list_del(&cmd->list);
+	mutex_unlock(&cmd->rdev->queue);
+}

...

drivers/fpga/amd/versal-pci-rm-queue.c line 234

Quoted 6 lines
drivers/fpga/amd/versal-pci-rm-queue.c new file +6 -0
+static void rm_check_msg(struct work_struct *w)
+{
+	struct rm_device *rdev = to_rdev_msg_monitor(w);
+	int ret;
+
+	mutex_lock(&rdev->queue);

Using guardmutex) would slightly simplify the code.

Quoted 16 lines
drivers/fpga/amd/versal-pci-rm-queue.c new file +16 -0
+
+	rdev->sq.cidx = rm_queue_get_cidx(rdev, RM_QUEUE_SQ);
+	rdev->cq.pidx = rm_queue_get_pidx(rdev, RM_QUEUE_CQ);
+
+	while (rdev->cq.cidx < rdev->cq.pidx) {
+		ret = rm_process_msg(rdev);
+		if (ret)
+			break;
+
+		rdev->cq.cidx++;
+
+		rm_queue_set_cidx(rdev, RM_QUEUE_CQ, rdev->cq.cidx);
+	}
+
+	mutex_unlock(&rdev->queue);
+}

...

drivers/fpga/amd/versal-pci-rm-queue.c line 276

Quoted 8 lines
drivers/fpga/amd/versal-pci-rm-queue.c new file +8 -0
+int rm_queue_init(struct rm_device *rdev)
+{
+	struct versal_pci_device *vdev = rdev->vdev;
+	struct rm_queue_header header = {0};
+	int ret;
+
+	INIT_LIST_HEAD(&rdev->submitted_cmds);
+	mutex_init(&rdev->queue);

devm_mutex_init()?
In order to slightly simplify the code.

drivers/fpga/amd/versal-pci-rm-queue.c line 284

Quoted 8 lines
drivers/fpga/amd/versal-pci-rm-queue.c new file +8 -0
+
+	rm_queue_bulk_read(rdev, RM_HDR_OFF, (u32 *)&header, sizeof(header));
+
+	if (header.magic != RM_QUEUE_HDR_MAGIC_NUM) {
+		vdev_err(vdev, "Invalid RM queue header");
+		ret = -ENODEV;
+		goto error;
+	}

...

CJ

#26 lore raw

PATCH v2 4/4 drivers/fpga/amd: Add load xclbin and load firmware

In reply to Yidong Zhang

- programming FW
- The base FW is downloaded onto the flash of the card.
- The APU FW is downloaded once after a POR (power on reset).
- Reloading the MgmtPF driver will not change any existing hardware.

- programming FPGA hardware binaries - PL Data
- using fpga framework ops to support re-programing FPGA
- the re-programming request will be initiated from the existing UserPF driver only, and the MgmtPF driver load the matched PL Data after receiving request from the communication channel. The matching PL Data is indexed by the PL Data UUID and Base FW UUID.
- The Base FW UUID identifies unique based hardware. Often called the interface UUID.
- The PL Data UUID identifies unique PL design that is generated based on the base hardware. Often called xclbin UUID.

- Example:
4fdebe35[...trimmed...]_96df7d[...trimmed...].xclbin
| | | |
+-- xclbin UUID --+ +--interface UUID --+

---
 drivers/fpga/amd/Makefile                |   3 +-
 drivers/fpga/amd/versal-pci-main.c       | 137 ++++++-
 drivers/fpga/amd/versal-pci-rm-queue.c   |  14 +-
 drivers/fpga/amd/versal-pci-rm-service.c | 497 +++++++++++++++++++++++
 drivers/fpga/amd/versal-pci-rm-service.h |  20 +
 drivers/fpga/amd/versal-pci.h            |   2 +
 6 files changed, 649 insertions(+), 24 deletions(-)
 create mode 100644 drivers/fpga/amd/versal-pci-rm-service.c
drivers/fpga/amd/Makefile +2 -1
index b2ffdbf23400..ffe4ead0d55e 100644
@@ -4,4 +4,5 @@ obj-$(CONFIG_AMD_VERSAL_PCI)			+= versal-pci.o
 
 versal-pci-$(CONFIG_AMD_VERSAL_PCI)		:= versal-pci-main.o \
 						   versal-pci-comm-chan.o \
-						   versal-pci-rm-queue.o
+						   versal-pci-rm-queue.o \
+						   versal-pci-rm-service.o
drivers/fpga/amd/versal-pci-main.c +122 -15

221 lines not on this page · raw message

drivers/fpga/amd/versal-pci-rm-queue.c +6 -8
index 92f2e1165052..e62aa6791a95 100644
@@ -23,37 +23,35 @@ static inline struct rm_device *to_rdev_msg_timer(struct timer_list *t)
 
 static inline u32 rm_io_read(struct rm_device *rdev, u32 offset)
 {
-	/* TODO */
-	return 0;
+	return rm_reg_read(rdev, RM_PCI_IO_BAR_OFF + offset);
 }
 
 static inline int rm_io_write(struct rm_device *rdev, u32 offset, u32 value)
 {
-	/* TODO */
+	rm_reg_write(rdev, RM_PCI_IO_BAR_OFF + offset, value);
 	return 0;
 }
 
 static inline u32 rm_queue_read(struct rm_device *rdev, u32 offset)
 {
-	/* TODO */
-	return 0;
+	return rm_reg_read(rdev, RM_PCI_SHMEM_BAR_OFF + rdev->queue_base + offset);
 }
 
 static inline void rm_queue_write(struct rm_device *rdev, u32 offset, u32 value)
 {
-	/* TODO */
+	rm_reg_write(rdev, RM_PCI_SHMEM_BAR_OFF + rdev->queue_base + offset, value);
 }
 
 static inline void rm_queue_bulk_read(struct rm_device *rdev, u32 offset,
 				      u32 *value, u32 size)
 {
-	/* TODO */
+	rm_bulk_reg_read(rdev, RM_PCI_SHMEM_BAR_OFF + rdev->queue_base + offset, value, size);
 }
 
 static inline void rm_queue_bulk_write(struct rm_device *rdev, u32 offset,
 				       u32 *value, u32 size)
 {
-	/* TODO */
+	rm_bulk_reg_write(rdev, RM_PCI_SHMEM_BAR_OFF + rdev->queue_base + offset, value, size);
 }
 
 static inline u32 rm_queue_get_cidx(struct rm_device *rdev, enum rm_queue_type type)
drivers/fpga/amd/versal-pci-rm-service.c new file +497 -0

497 lines not on this page · raw message

drivers/fpga/amd/versal-pci-rm-service.h +20 -0
index 85a78257770a..90796567f0d3 100644
@@ -206,4 +206,24 @@ struct rm_device {
 	__u32			firewall_tripped;
 };
 
+/* rm service init api */
+struct rm_device *versal_pci_rm_init(struct versal_pci_device *vdev);
+void versal_pci_rm_fini(struct rm_device *rdev);
+
+/* rm services APIs */
+int rm_queue_create_cmd(struct rm_device *rdev, enum rm_queue_opcode opcode,
+			struct rm_cmd **cmd_ptr);
+void rm_queue_destory_cmd(struct rm_cmd *cmd);
+
+int rm_queue_data_init(struct rm_cmd *cmd, const char *buffer, ssize_t size);
+void rm_queue_data_fini(struct rm_cmd *cmd);
+int rm_queue_get_fw_id(struct rm_device *rdev);
+int rm_queue_boot_apu(struct rm_device *rdev);
+
+/* rm bar register operation APIs */
+u32 rm_reg_read(struct rm_device *rdev, u32 offset);
+void rm_reg_write(struct rm_device *rdev, u32 offset, const u32 value);
+void rm_bulk_reg_read(struct rm_device *rdev, u32 offset, u32 *value, size_t size);
+void rm_bulk_reg_write(struct rm_device *rdev, u32 offset, const void *value, size_t size);
+
 #endif	/* __RM_SERVICE_H */
drivers/fpga/amd/versal-pci.h +2 -0
index 6c1ca3ce505d..5d3f793a5b68 100644
@@ -27,6 +27,7 @@
 
 struct versal_pci_device;
 struct comm_chan_device;
+struct rm_cmd;
 
 struct axlf_header {
 	__u64				length;
@@ -69,6 +70,7 @@ struct firmware_device {
 struct versal_pci_device {
 	struct pci_dev			*pdev;
 
+	struct rm_device		*rdev;
 	struct fpga_device		*fdev;
 	struct comm_chan_device         *ccdev;
 	struct firmware_device		*fwdev;
Signature · 1 line
2.34.1
#27 lore raw
In reply to Yidong Zhang
Quoted 24 lines · Yidong Zhang

This patchset introduces a new Linux Kernel Driver, versal-pci for AMD Alevo Versal based PCIe Card. The driver is based on Linux fpga driver framework.

The AMD Alevo Versal based PCIe Card, including V70, is the first Alevo production card leveraging AMD XDNA architecture with AI Engines. It is designed for AI inference efficiency and is tuned for video analytics and natural language processing applications [1].

This versal-pci driver provides services, including:
- leveraging linux firmware and FPGA framework to download management firmware
- program additional bit-streams for AMD Xilinx specific hardware
- communicate with PCIe user function
- communicate with firmware running on the PCIe Card
- monitor device health

The driver is licensed under GPL-2.0.

The firmware and bit-streams are distributed as a closed binary, delivered by AMD. Please see [1] for more information.

[1] https://www.amd.com/en/products/accelerators/alveo/v70.html

Quoted 11 lines

Refactor driver to address all comments from v1.
Changes since v1:
- Add driver architecture description.
- Change the driver name to versal-pci
- Remove unnecessary memcpy in versal-pci-comm-chan.c
- Keep mod_timer because we need single_threaded_queue with delayed_work.
- Change the "comms" to "comm_chan".
- Remove regmap, use base+offset directly.
- Add skeleton ops with on implementation (TODO) for fpga_manager in early patch (0001) and add implementation in later patch(0004).
- Remove br_ops and FPGA region, no need.

I never said FPGA region is no need. FPGA region is the essential for managing the reprogramming and re-enumeration.

Thanks,
Yilun