Skip to contentSkip to conversation

Add support for AMD AE4DMA controller driver

PATCH In review Sanjay R Mehta 2 participants 10 messages Sep 11, 2023 – Oct 23, 2023 dmaengine

lore
Share & tools
lore
#0 lore raw

cover Add support for AMD AE4DMA controller driver

From: Sanjay R Mehta <[email protected]>

This patch series add support for AMD AE4DMA controller which performs high bandwidth memory-to-memory and IO copy operation, performs DMA transfer through queue based descriptor management.

The AE4DMA controller allows for configuration of the number of queues per controller, with a range from 1 to 16. This configuration can be conveniently adjusted using the driver's "max_hw_q" parameter.

The AMD Processor features multiple ae4dma device instances, with each controller supporting a maximum of 16 DMA queues.

Sanjay R Mehta (3):
dmaengine: ae4dma: Initial ae4dma controller driver with multi channel
dmaengine: ae4dma: register AE4DMA controller as a DMA resource
dmaengine: ae4dma: Add debugfs entries for AE4DMA

 MAINTAINERS                           |   6 +
 drivers/dma/Kconfig                   |   2 +
 drivers/dma/Makefile                  |   1 +
 drivers/dma/ae4dma/Kconfig            |  13 ++
 drivers/dma/ae4dma/Makefile           |  10 +
 drivers/dma/ae4dma/ae4dma-debugfs.c   |  98 ++++++++
 drivers/dma/ae4dma/ae4dma-dev.c       | 353 ++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma-dmaengine.c | 425 ++++++++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma-pci.c       | 247 ++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma.h           | 374 ++++++++++++++++++++++++++++++
 10 files changed, 1529 insertions(+)
 create mode 100644 drivers/dma/ae4dma/Kconfig
 create mode 100644 drivers/dma/ae4dma/Makefile
 create mode 100644 drivers/dma/ae4dma/ae4dma-debugfs.c
 create mode 100644 drivers/dma/ae4dma/ae4dma-dev.c
 create mode 100644 drivers/dma/ae4dma/ae4dma-dmaengine.c
 create mode 100644 drivers/dma/ae4dma/ae4dma-pci.c
 create mode 100644 drivers/dma/ae4dma/ae4dma.h
Signature · 1 line
2.7.4
#1 lore raw

PATCH 1/3 dmaengine: ae4dma: Initial ae4dma controller driver with multi channel

From: Sanjay R Mehta <[email protected]>

Add support for AMD AE4DMA controller. It performs high-bandwidth memory to memory and IO copy operation. Device commands are managed via a circular queue of 'descriptors', each of which specifies source and destination addresses for copying a single buffer of data.

---
 MAINTAINERS                     |   6 +
 drivers/dma/Kconfig             |   2 +
 drivers/dma/Makefile            |   1 +
 drivers/dma/ae4dma/Kconfig      |  11 ++
 drivers/dma/ae4dma/Makefile     |  10 ++
 drivers/dma/ae4dma/ae4dma-dev.c | 320 +++++++++++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma-pci.c | 247 +++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma.h     | 338 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 935 insertions(+)
 create mode 100644 drivers/dma/ae4dma/Kconfig
 create mode 100644 drivers/dma/ae4dma/Makefile
 create mode 100644 drivers/dma/ae4dma/ae4dma-dev.c
 create mode 100644 drivers/dma/ae4dma/ae4dma-pci.c
 create mode 100644 drivers/dma/ae4dma/ae4dma.h
MAINTAINERS +6 -0
index d590ce3..fdcc6d9 100644
@@ -891,6 +891,12 @@ Q:	https://patchwork.kernel.org/project/linux-rdma/list/
 F:	drivers/infiniband/hw/efa/
 F:	include/uapi/rdma/efa-abi.h
 
+AMD AE4DMA DRIVER
+M:	Sanjay R Mehta <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/dma/ae4dma/
+
 AMD CDX BUS DRIVER
 M:	Nipun Gupta <[email protected]>
 M:	Nikhil Agarwal <[email protected]>
drivers/dma/Kconfig +2 -0
index 08fdd0e..b26dbfb 100644
@@ -777,6 +777,8 @@ source "drivers/dma/fsl-dpaa2-qdma/Kconfig"
 
 source "drivers/dma/lgm/Kconfig"
 
+source "drivers/dma/ae4dma/Kconfig"
+
 # clients
 comment "DMA Clients"
 	depends on DMA_ENGINE
drivers/dma/Makefile +1 -0
index a4fd1ce..513d87f 100644
@@ -81,6 +81,7 @@ obj-$(CONFIG_XGENE_DMA) += xgene-dma.o
 obj-$(CONFIG_ST_FDMA) += st_fdma.o
 obj-$(CONFIG_FSL_DPAA2_QDMA) += fsl-dpaa2-qdma/
 obj-$(CONFIG_INTEL_LDMA) += lgm/
+obj-$(CONFIG_AMD_AE4DMA) += ae4dma/
 
 obj-y += mediatek/
 obj-y += qcom/
drivers/dma/ae4dma/Kconfig new file +11 -0
new file mode 100644
index 0000000..1cda9de
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config AMD_AE4DMA
+	tristate  "AMD AE4DMA Engine"
+	depends on X86_64 && PCI
+	help
+	  Enabling this option provides support for the AMD AE4DMA controller,
+	  which offers DMA capabilities for high-bandwidth memory-to-memory and
+	  I/O copy operations. The controller utilizes a queue-based descriptor
+	  management system for efficient DMA transfers. It is specifically
+	  designed to be used in conjunction with AMD Non-Transparent Bridge devices
+	  and is not intended for general-purpose peripheral DMA functionality.
drivers/dma/ae4dma/Makefile new file +10 -0
new file mode 100644
index 0000000..db9cab1
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# AMD AE4DMA driver
+#
+
+obj-$(CONFIG_AMD_AE4DMA) += ae4dma.o
+
+ae4dma-objs := ae4dma-dev.o
+
+ae4dma-$(CONFIG_PCI) += ae4dma-pci.o
drivers/dma/ae4dma/ae4dma-dev.c new file +320 -0

320 lines not on this page · raw message

drivers/dma/ae4dma/ae4dma-pci.c new file +247 -0

247 lines not on this page · raw message

drivers/dma/ae4dma/ae4dma.h new file +338 -0

338 lines not on this page · raw message

Signature · 1 line
2.7.4
maintainer
#2 lore raw

Re: [PATCH 1/3] dmaengine: ae4dma: Initial ae4dma controller driver with multi channel

Quoted 46 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

Add support for AMD AE4DMA controller. It performs high-bandwidth memory to memory and IO copy operation. Device commands are managed via a circular queue of 'descriptors', each of which specifies source and destination addresses for copying a single buffer of data.

---
 MAINTAINERS                     |   6 +
 drivers/dma/Kconfig             |   2 +
 drivers/dma/Makefile            |   1 +
 drivers/dma/ae4dma/Kconfig      |  11 ++
 drivers/dma/ae4dma/Makefile     |  10 ++
 drivers/dma/ae4dma/ae4dma-dev.c | 320 +++++++++++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma-pci.c | 247 +++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma.h     | 338 ++++++++++++++++++++++++++++++++++++++++
 8 files changed, 935 insertions(+)
 create mode 100644 drivers/dma/ae4dma/Kconfig
 create mode 100644 drivers/dma/ae4dma/Makefile
 create mode 100644 drivers/dma/ae4dma/ae4dma-dev.c
 create mode 100644 drivers/dma/ae4dma/ae4dma-pci.c
 create mode 100644 drivers/dma/ae4dma/ae4dma.h
MAINTAINERS +6 -0
index d590ce3..fdcc6d9 100644
@@ -891,6 +891,12 @@ Q:	https://patchwork.kernel.org/project/linux-rdma/list/
 F:	drivers/infiniband/hw/efa/
 F:	include/uapi/rdma/efa-abi.h
 
+AMD AE4DMA DRIVER
+M:	Sanjay R Mehta <[email protected]>
+L:	[email protected]
+S:	Maintained
+F:	drivers/dma/ae4dma/
+
 AMD CDX BUS DRIVER
 M:	Nipun Gupta <[email protected]>
 M:	Nikhil Agarwal <[email protected]>
drivers/dma/Kconfig +0 -0
index 08fdd0e..b26dbfb 100644

drivers/dma/Kconfig source "drivers/dma/fsl-dpaa2-qdma/Kconfig" · line 780

Quoted 4 lines
drivers/dma/Kconfig +1 -0
@@ -777,6 +777,8 @@ source "drivers/dma/fsl-dpaa2-qdma/Kconfig"
 
 source "drivers/dma/lgm/Kconfig"
 
+source "drivers/dma/ae4dma/Kconfig"

There is another amd driver on the list, I suggest move all of these to amd/ and have one kconfig inside amd/

Quoted 98 lines
drivers/dma/Kconfig +1 -0
+
 # clients
 comment "DMA Clients"
 	depends on DMA_ENGINE
drivers/dma/Makefile +1 -0
index a4fd1ce..513d87f 100644
@@ -81,6 +81,7 @@ obj-$(CONFIG_XGENE_DMA) += xgene-dma.o
 obj-$(CONFIG_ST_FDMA) += st_fdma.o
 obj-$(CONFIG_FSL_DPAA2_QDMA) += fsl-dpaa2-qdma/
 obj-$(CONFIG_INTEL_LDMA) += lgm/
+obj-$(CONFIG_AMD_AE4DMA) += ae4dma/
 
 obj-y += mediatek/
 obj-y += qcom/
drivers/dma/ae4dma/Kconfig new file +11 -0
new file mode 100644
index 0000000..1cda9de
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only
+config AMD_AE4DMA
+	tristate  "AMD AE4DMA Engine"
+	depends on X86_64 && PCI
+	help
+	  Enabling this option provides support for the AMD AE4DMA controller,
+	  which offers DMA capabilities for high-bandwidth memory-to-memory and
+	  I/O copy operations. The controller utilizes a queue-based descriptor
+	  management system for efficient DMA transfers. It is specifically
+	  designed to be used in conjunction with AMD Non-Transparent Bridge devices
+	  and is not intended for general-purpose peripheral DMA functionality.
drivers/dma/ae4dma/Makefile new file +10 -0
new file mode 100644
index 0000000..db9cab1
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only
+#
+# AMD AE4DMA driver
+#
+
+obj-$(CONFIG_AMD_AE4DMA) += ae4dma.o
+
+ae4dma-objs := ae4dma-dev.o
+
+ae4dma-$(CONFIG_PCI) += ae4dma-pci.o
drivers/dma/ae4dma/ae4dma-dev.c new file +43 -0
new file mode 100644
index 0000000..a3c50a2
@@ -0,0 +1,320 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD AE4DMA device driver
+ * -- Based on the PTDMA driver
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Sanjay R Mehta <[email protected]>
+ */
+
+#include <linux/bitfield.h>
+#include <linux/dma-mapping.h>
+#include <linux/debugfs.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>
+#include <linux/pci.h>
+#include <linux/delay.h>
+
+#include "ae4dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
+
+static unsigned int max_hw_q = 1;
+module_param(max_hw_q, uint, 0444);
+MODULE_PARM_DESC(max_hw_q, "Max queues per engine (any non-zero value less than or equal to 16, default: 1)");
+
+/* Human-readable error strings */
+static char *ae4_error_codes[] = {
+	"",
+	"ERR 01: INVALID HEADER DW0",
+	"ERR 02: INVALID STATUS",
+	"ERR 03: INVALID LENGTH - 4 BYTE ALIGNMENT",
+	"ERR 04: INVALID SRC ADDR - 4 BYTE ALIGNMENT",
+	"ERR 05: INVALID DST ADDR - 4 BYTE ALIGNMENT",
+	"ERR 06: INVALID ALIGNMENT",
+	"ERR 07: INVALID DESCRIPTOR",
+};
+
+static void ae4_log_error(struct ae4_device *d, int e)
+{
+	if (e <= 7)
+		dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", ae4_error_codes[e], e);

drivers/dma/ae4dma/ae4dma-dev.c line 53

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+	else if (e > 7 && e <= 15)
+		dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "INVALID DESCRIPTOR", e);
+	else if (e > 15 && e <= 31)
+		dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "INVALID DESCRIPTOR", e);
+	else if (e > 31 && e <= 63)
+		dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "INVALID DESCRIPTOR", e);
+	else if (e > 63 && e <= 127)
+		dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "PTE ERROR", e);
+	else if (e > 127 && e <= 255)
+		dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "PTE ERROR", e);

why info level? It should err going by fn description

Quoted 39 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +39 -0
+}
+
+void ae4_start_queue(struct ae4_cmd_queue *cmd_q)
+{
+	/* Turn on the run bit */
+	iowrite32(cmd_q->qcontrol | CMD_Q_RUN, cmd_q->reg_control);
+}
+
+void ae4_stop_queue(struct ae4_cmd_queue *cmd_q)
+{
+	/* Turn off the run bit */
+	iowrite32(cmd_q->qcontrol & ~CMD_Q_RUN, cmd_q->reg_control);
+}
+
+static int ae4_core_execute_cmd(struct ae4dma_desc *desc, struct ae4_cmd_queue *cmd_q)
+{
+	bool soc = FIELD_GET(DWORD0_SOC, desc->dw0);
+	u8 *q_desc = (u8 *)&cmd_q->qbase[0];
+	u32 tail_wi;
+
+	cmd_q->int_rcvd = 0;
+
+	if (soc) {
+		desc->dw0 |= FIELD_PREP(DWORD0_IOC, desc->dw0);
+		desc->dw0 &= ~DWORD0_SOC;
+	}
+	mutex_lock(&cmd_q->q_mutex);
+
+	/* Write Index of circular queue */
+	tail_wi =  ioread32(cmd_q->reg_control + 0x10);
+	q_desc += (tail_wi * 32);
+
+	/* Copy 32-byte command descriptor to hw queue. */
+	memcpy(q_desc, desc, 32);
+	cmd_q->qidx = (cmd_q->qidx + 1) % CMD_Q_LEN; // Increment q_desc id.
+
+	/* The data used by this command must be flushed to memory */
+	wmb();
+

drivers/dma/ae4dma/ae4dma-dev.c line 102

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+	/* Write the new tail_wi address back to the queue register */
+	tail_wi = (tail_wi + 1) % CMD_Q_LEN;
+	iowrite32(tail_wi, cmd_q->reg_control + 0x10);
+
+	mutex_unlock(&cmd_q->q_mutex);
+
+	return 0;
+}
+
+int ae4_core_perform_passthru(struct ae4_cmd_queue *cmd_q, struct ae4_passthru_engine *ae4_engine)

Who calls this, pls document the arguments for apis

drivers/dma/ae4dma/ae4dma-dev.c line 112

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+{
+	struct ae4dma_desc desc;
+	struct ae4_device *ae4 = cmd_q->ae4;
+
+	cmd_q->cmd_error = 0;
+	memset(&desc, 0, sizeof(desc));
+	desc.dw0 = CMD_DESC_DW0_VAL;
+	desc.dw1.status = 0;
+	desc.dw1.err_code = 0;
+	desc.dw1.desc_id = 0;

these are redundant, u already did memset

Quoted 31 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +31 -0
+	desc.length = ae4_engine->src_len;
+	desc.src_lo = upper_32_bits(ae4_engine->src_dma);
+	desc.src_hi = lower_32_bits(ae4_engine->src_dma);
+	desc.dst_lo = upper_32_bits(ae4_engine->dst_dma);
+	desc.dst_hi = lower_32_bits(ae4_engine->dst_dma);
+
+	if (cmd_q->int_en)
+		ae4_core_enable_queue_interrupts(ae4, cmd_q);
+	else
+		ae4_core_disable_queue_interrupts(ae4, cmd_q);
+
+	return ae4_core_execute_cmd(&desc, cmd_q);
+}
+
+static void ae4_do_cmd_complete(struct tasklet_struct *t)
+{
+	struct ae4_cmd_queue *cmd_q = from_tasklet(cmd_q, t, irq_tasklet);
+	unsigned long flags;
+	struct ae4_cmd *cmd;
+
+	spin_lock_irqsave(&cmd_q->cmd_lock, flags);
+	cmd = list_first_entry(&cmd_q->cmd, struct ae4_cmd, entry);
+	list_del(&cmd->entry);
+	spin_unlock_irqrestore(&cmd_q->cmd_lock, flags);
+
+	cmd->ae4_cmd_callback(cmd->data, cmd->ret);
+}
+
+void ae4_check_status_trans(struct ae4_device *ae4, struct ae4_cmd_queue *cmd_q)
+{
+	u8 status;

drivers/dma/ae4dma/ae4dma-dev.c line 153

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+	int head = ioread32(cmd_q->reg_control + 0x0C);
+	struct ae4dma_desc *desc;
+
+	head = (head - 1) & (CMD_Q_LEN - 1);
+	desc = &cmd_q->qbase[head];
+
+	status = desc->dw1.status;
+	if (status) {
+		cmd_q->int_status = status;
+		if (status != 0x3) {

magic number

Quoted 18 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +18 -0
+			/* On error, only save the first error value */
+			cmd_q->cmd_error = desc->dw1.err_code;
+			if (cmd_q->cmd_error) {
+				/*
+				 * Log the error and flush the queue by
+				 * moving the head pointer
+				 */
+				ae4_log_error(cmd_q->ae4, cmd_q->cmd_error);
+			}
+		}
+	}
+}
+
+static irqreturn_t ae4_core_irq_handler(int irq, void *data)
+{
+	struct ae4_cmd_queue *cmd_q = data;
+	struct ae4_device *ae4 = cmd_q->ae4;
+	u32 status = ioread32(cmd_q->reg_control + 0x4);

drivers/dma/ae4dma/ae4dma-dev.c line 181

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+	u8 q_intr_type = (status >> 24) & 0xf;
+
+	if (q_intr_type ==  0x4)
+		dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "queue desc error", q_intr_type);
+	else if (q_intr_type ==  0x2)
+		dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "queue stopped", q_intr_type);
+	else if (q_intr_type ==  0x1)
+		dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "queue empty", q_intr_type);
+	else
+		dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "unknown error", q_intr_type);

better use a switch

Quoted 49 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +49 -0
+
+	ae4_check_status_trans(ae4, cmd_q);
+
+	tasklet_schedule(&cmd_q->irq_tasklet);
+
+	return IRQ_HANDLED;
+}
+
+int ae4_core_init(struct ae4_device *ae4)
+{
+	char dma_pool_name[MAX_DMAPOOL_NAME_LEN];
+	struct ae4_cmd_queue *cmd_q;
+	u32 dma_addr_lo, dma_addr_hi;
+	struct device *dev = ae4->dev;
+	struct dma_pool *dma_pool;
+	unsigned int i;
+	int ret;
+	u32 q_per_eng = max_hw_q;
+
+	/* Update the device registers with queue information. */
+	iowrite32(q_per_eng, ae4->io_regs);
+
+	q_per_eng = ioread32(ae4->io_regs);
+
+	for (i = 0; i < q_per_eng; i++) {
+		/* Allocate a dma pool for the queue */
+		snprintf(dma_pool_name, sizeof(dma_pool_name), "%s_q%d", dev_name(ae4->dev), i);
+		dma_pool = dma_pool_create(dma_pool_name, dev,
+					   AE4_DMAPOOL_MAX_SIZE,
+					   AE4_DMAPOOL_ALIGN, 0);
+		if (!dma_pool)
+			return -ENOMEM;
+
+		/* ae4dma core initialisation */
+		cmd_q = &ae4->cmd_q[i];
+		cmd_q->id = ae4->cmd_q_count;
+		ae4->cmd_q_count++;
+		cmd_q->ae4 = ae4;
+		cmd_q->dma_pool = dma_pool;
+		mutex_init(&cmd_q->q_mutex);
+		spin_lock_init(&cmd_q->q_lock);
+
+		/* Preset some register values (Q size is 32byte (0x20)) */
+		cmd_q->reg_control = ae4->io_regs + ((i + 1) * 0x20);
+
+		/* Page alignment satisfies our needs for N <= 128 */
+		cmd_q->qsize = Q_SIZE(Q_DESC_SIZE);
+		cmd_q->qbase = dma_alloc_coherent(dev, cmd_q->qsize, &cmd_q->qbase_dma, GFP_KERNEL);
+

drivers/dma/ae4dma/ae4dma-dev.c line 240

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+		if (!cmd_q->qbase) {
+			ret = -ENOMEM;
+			goto e_destroy_pool;
+		}
+
+		cmd_q->qidx = 0;
+		cmd_q->q_space_available = 0;
+
+		init_waitqueue_head(&cmd_q->int_queue);
+		init_waitqueue_head(&cmd_q->q_space);

why do you need two waitqueues here?

Quoted 86 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +80 -0
+
+		dev_dbg(dev, "queue #%u available\n", i);
+	}
+
+	if (ae4->cmd_q_count == 0) {
+		dev_notice(dev, "no command queues available\n");
+		ret = -EIO;
+		goto e_destroy_pool;
+	}
+	for (i = 0; i < ae4->cmd_q_count; i++) {
+		cmd_q = &ae4->cmd_q[i];
+		cmd_q->qcontrol = 0;
+		ret = request_irq(ae4->ae4_irq[i], ae4_core_irq_handler, 0,
+				  dev_name(ae4->dev), cmd_q);
+		if (ret) {
+			dev_err(dev, "unable to allocate an IRQ\n");
+			goto e_free_dma;
+		}
+
+		/* Update the device registers with cnd queue length (Max Index reg). */
+		iowrite32(CMD_Q_LEN, cmd_q->reg_control + 0x08);
+		cmd_q->qdma_tail = cmd_q->qbase_dma;
+		dma_addr_lo = lower_32_bits(cmd_q->qdma_tail);
+		iowrite32((u32)dma_addr_lo, cmd_q->reg_control + 0x18);
+		dma_addr_lo = ioread32(cmd_q->reg_control + 0x18);
+		dma_addr_hi = upper_32_bits(cmd_q->qdma_tail);
+		iowrite32((u32)dma_addr_hi, cmd_q->reg_control + 0x1C);
+		dma_addr_hi = ioread32(cmd_q->reg_control + 0x1C);
+		ae4_core_enable_queue_interrupts(ae4, cmd_q);
+		INIT_LIST_HEAD(&cmd_q->cmd);
+
+		/* Initialize the ISR tasklet */
+		tasklet_setup(&cmd_q->irq_tasklet, ae4_do_cmd_complete);
+	}
+
+	return 0;
+
+e_free_dma:
+	dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase, cmd_q->qbase_dma);
+
+e_destroy_pool:
+	for (i = 0; i < ae4->cmd_q_count; i++)
+		dma_pool_destroy(ae4->cmd_q[i].dma_pool);
+
+	return ret;
+}
+
+void ae4_core_destroy(struct ae4_device *ae4)
+{
+	struct device *dev = ae4->dev;
+	struct ae4_cmd_queue *cmd_q;
+	struct ae4_cmd *cmd;
+	unsigned int i;
+
+	for (i = 0; i < ae4->cmd_q_count; i++) {
+		cmd_q = &ae4->cmd_q[i];
+
+		wake_up_all(&cmd_q->q_space);
+		wake_up_all(&cmd_q->int_queue);
+
+		/* Disable and clear interrupts */
+		ae4_core_disable_queue_interrupts(ae4, cmd_q);
+
+		/* Turn off the run bit */
+		ae4_stop_queue(cmd_q);
+
+		free_irq(ae4->ae4_irq[i], cmd_q);
+
+		dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase,
+				  cmd_q->qbase_dma);
+	}
+
+	/* Flush the cmd queue */
+	while (!list_empty(&ae4->cmd)) {
+		/* Invoke the callback directly with an error code */
+		cmd = list_first_entry(&ae4->cmd, struct ae4_cmd, entry);
+		list_del(&cmd->entry);
+		cmd->ae4_cmd_callback(cmd->data, -ENODEV);
+	}
+}
drivers/dma/ae4dma/ae4dma-pci.c new file +0 -0
new file mode 100644
index 0000000..a77fbb5

drivers/dma/ae4dma/ae4dma-pci.c line 4

Quoted 4 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +4 -0
@@ -0,0 +1,247 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD AE4DMA device driver
+ * -- Based on the PTDMA driver

cant we use ptdma driver to support both cores?

Quoted 25 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +25 -0
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Sanjay R Mehta <[email protected]>
+ */
+
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/kthread.h>
+#include <linux/module.h>
+#include <linux/pci_ids.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+
+#include "ae4dma.h"
+
+struct ae4_msix {
+	int msix_count;
+	struct msix_entry msix_entry[MAX_HW_QUEUES];
+};
+
+/*

drivers/dma/ae4dma/ae4dma-pci.c line 39

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +10 -0
+ * ae4_alloc_struct - allocate and initialize the ae4_device struct
+ *
+ * @dev: device struct of the AE4DMA
+ */
+static struct ae4_device *ae4_alloc_struct(struct device *dev)
+{
+	struct ae4_device *ae4;
+
+	ae4 = devm_kzalloc(dev, sizeof(*ae4), GFP_KERNEL);
+

This empty line here doesnt make sense

drivers/dma/ae4dma/ae4dma-pci.c line 41

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +2 -0
+	if (!ae4)
+		return NULL;

it should be here instead :-)

Quoted 173 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +173 -0
+	ae4->dev = dev;
+
+	INIT_LIST_HEAD(&ae4->cmd);
+
+	return ae4;
+}
+
+static int ae4_get_msix_irqs(struct ae4_device *ae4)
+{
+	struct ae4_msix *ae4_msix = ae4->ae4_msix;
+	struct device *dev = ae4->dev;
+	struct pci_dev *pdev = to_pci_dev(dev);
+	int v, i, ret;
+
+	for (v = 0; v < ARRAY_SIZE(ae4_msix->msix_entry); v++)
+		ae4_msix->msix_entry[v].entry = v;
+
+	ret = pci_enable_msix_range(pdev, ae4_msix->msix_entry, 1, v);
+	if (ret < 0)
+		return ret;
+
+	ae4_msix->msix_count = ret;
+
+	for (i = 0; i < MAX_HW_QUEUES; i++)
+		ae4->ae4_irq[i] = ae4_msix->msix_entry[i].vector;
+
+	return 0;
+}
+
+static int ae4_get_msi_irq(struct ae4_device *ae4)
+{
+	struct device *dev = ae4->dev;
+	struct pci_dev *pdev = to_pci_dev(dev);
+	int ret, i;
+
+	ret = pci_enable_msi(pdev);
+	if (ret)
+		return ret;
+
+	for (i = 0; i < MAX_HW_QUEUES; i++)
+		ae4->ae4_irq[i] = pdev->irq;
+
+	return 0;
+}
+
+static int ae4_get_irqs(struct ae4_device *ae4)
+{
+	struct device *dev = ae4->dev;
+	int ret;
+
+	ret = ae4_get_msix_irqs(ae4);
+	if (!ret)
+		return 0;
+
+	/* Couldn't get MSI-X vectors, try MSI */
+	dev_err(dev, "could not enable MSI-X (%d), trying MSI\n", ret);
+	ret = ae4_get_msi_irq(ae4);
+	if (!ret)
+		return 0;
+
+	/* Couldn't get MSI interrupt */
+	dev_err(dev, "could not enable MSI (%d)\n", ret);
+
+	return ret;
+}
+
+static void ae4_free_irqs(struct ae4_device *ae4)
+{
+	struct ae4_msix *ae4_msix = ae4->ae4_msix;
+	struct device *dev = ae4->dev;
+	struct pci_dev *pdev = to_pci_dev(dev);
+	unsigned int i;
+
+	if (ae4_msix->msix_count)
+		pci_disable_msix(pdev);
+	else if (ae4->ae4_irq)
+		pci_disable_msi(pdev);
+
+	for (i = 0; i < MAX_HW_QUEUES; i++)
+		ae4->ae4_irq[i] = 0;
+}
+
+static int ae4_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
+{
+	struct ae4_device *ae4;
+	struct ae4_msix *ae4_msix;
+	struct device *dev = &pdev->dev;
+	void __iomem * const *iomap_table;
+	int bar_mask;
+	int ret = -ENOMEM;
+
+	ae4 = ae4_alloc_struct(dev);
+	if (!ae4)
+		goto e_err;
+
+	ae4_msix = devm_kzalloc(dev, sizeof(*ae4_msix), GFP_KERNEL);
+	if (!ae4_msix)
+		goto e_err;
+
+	ae4->ae4_msix = ae4_msix;
+	ae4->dev_vdata = (struct ae4_dev_vdata *)id->driver_data;
+	if (!ae4->dev_vdata) {
+		ret = -ENODEV;
+		dev_err(dev, "missing driver data\n");
+		goto e_err;
+	}
+
+	ret = pcim_enable_device(pdev);
+	if (ret) {
+		dev_err(dev, "pcim_enable_device failed (%d)\n", ret);
+		goto e_err;
+	}
+
+	bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
+	ret = pcim_iomap_regions(pdev, bar_mask, "ae4dma");
+	if (ret) {
+		dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
+		goto e_err;
+	}
+
+	iomap_table = pcim_iomap_table(pdev);
+	if (!iomap_table) {
+		dev_err(dev, "pcim_iomap_table failed\n");
+		ret = -ENOMEM;
+		goto e_err;
+	}
+
+	ae4->io_regs = iomap_table[ae4->dev_vdata->bar];
+	if (!ae4->io_regs) {
+		dev_err(dev, "ioremap failed\n");
+		ret = -ENOMEM;
+		goto e_err;
+	}
+
+	ret = ae4_get_irqs(ae4);
+	if (ret)
+		goto e_err;
+
+	pci_set_master(pdev);
+
+	ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
+	if (ret) {
+		ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(32));
+		if (ret) {
+			dev_err(dev, "dma_set_mask_and_coherent failed (%d)\n",
+				ret);
+			goto e_err;
+		}
+	}
+
+	dev_set_drvdata(dev, ae4);
+
+	if (ae4->dev_vdata)
+		ret = ae4_core_init(ae4);
+
+	if (ret)
+		goto e_err;
+
+	return 0;
+
+e_err:
+	dev_err(dev, "initialization failed ret = %d\n", ret);
+
+	return ret;
+}
+
+static void ae4_pci_remove(struct pci_dev *pdev)
+{
+	struct device *dev = &pdev->dev;
+	struct ae4_device *ae4 = dev_get_drvdata(dev);
+
+	if (!ae4)
+		return;

drivers/dma/ae4dma/ae4dma-pci.c line 224

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +10 -0
+
+	if (ae4->dev_vdata)
+		ae4_core_destroy(ae4);
+
+	ae4_free_irqs(ae4);
+}
+
+static const struct ae4_dev_vdata dev_vdata[] = {
+	{
+		.bar = 0,

why pass zero data?

Quoted 62 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +23 -0
+	},
+};
+
+static const struct pci_device_id ae4_pci_table[] = {
+	{ PCI_VDEVICE(AMD, 0x14C8), (kernel_ulong_t)&dev_vdata[0] },
+	{ PCI_VDEVICE(AMD, 0x14DC), (kernel_ulong_t)&dev_vdata[0] },
+	/* Last entry must be zero */
+	{ 0, }
+};
+MODULE_DEVICE_TABLE(pci, ae4_pci_table);
+
+static struct pci_driver ae4_pci_driver = {
+	.name = "ae4dma",
+	.id_table = ae4_pci_table,
+	.probe = ae4_pci_probe,
+	.remove = ae4_pci_remove,
+};
+
+module_pci_driver(ae4_pci_driver);
+
+MODULE_AUTHOR("Sanjay R Mehta <[email protected]>");
+MODULE_LICENSE("GPL");
+MODULE_DESCRIPTION("AMD AE4DMA driver");
drivers/dma/ae4dma/ae4dma.h new file +33 -0
new file mode 100644
index 0000000..0ae46ee
@@ -0,0 +1,338 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * AMD AE4DMA device driver
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Sanjay R Mehta <[email protected]>
+ */
+
+#ifndef __AE4_DEV_H__
+#define __AE4_DEV_H__
+
+#include <linux/device.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <linux/mutex.h>
+#include <linux/list.h>
+#include <linux/wait.h>
+#include <linux/dmapool.h>
+
+#define MAX_AE4_NAME_LEN			16
+#define MAX_DMAPOOL_NAME_LEN		32
+
+#define MAX_HW_QUEUES			16
+#define MAX_CMD_QLEN			32
+
+#define AE4_ENGINE_PASSTHRU		5
+
+/* Register Mappings */
+#define IRQ_MASK_REG			0x040
+#define IRQ_STATUS_REG			0x200
+
+#define CMD_Q_ERROR(__qs)		((__qs) & 0x0000003f)

drivers/dma/ae4dma/ae4dma.h line 43

Quoted 10 lines
drivers/dma/ae4dma/ae4dma.h new file +10 -0
+
+#define CMD_QUEUE_PRIO_OFFSET		0x00
+#define CMD_REQID_CONFIG_OFFSET		0x04
+#define CMD_TIMEOUT_OFFSET		0x08
+#define CMD_AE4_VERSION			0x10
+
+#define CMD_Q_CONTROL_BASE		0x0000
+#define CMD_Q_TAIL_LO_BASE		0x0004
+#define CMD_Q_HEAD_LO_BASE		0x0008
+#define CMD_Q_INT_ENABLE_BASE		0x000C

lower case please (here and elsewhere)

Signature · 1 line
~Vinod
#3 lore raw

RE: [PATCH 1/3] dmaengine: ae4dma: Initial ae4dma controller driver with multi channel

[AMD Official Use Only - General]

Quoted 61 lines

From: Vinod Koul <[email protected]>
Sent: Wednesday, October 4, 2023 3:24 PM
To: Mehta, Sanju <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] dmaengine: ae4dma: Initial ae4dma controller driver with multi channel

Quoted 4 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

Add support for AMD AE4DMA controller. It performs high-bandwidth memory to memory and IO copy operation. Device commands are

managed

Quoted 4 lines

via a circular queue of 'descriptors', each of which specifies source and destination addresses for copying a single buffer of data.

Quoted 9 lines
---
 MAINTAINERS                     |   6 +
 drivers/dma/Kconfig             |   2 +
 drivers/dma/Makefile            |   1 +
 drivers/dma/ae4dma/Kconfig      |  11 ++
 drivers/dma/ae4dma/Makefile     |  10 ++
 drivers/dma/ae4dma/ae4dma-dev.c | 320
+++++++++++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma-pci.c | 247

+++++++++++++++++++++++++++++

Quoted 1 line
 drivers/dma/ae4dma/ae4dma.h     | 338

++++++++++++++++++++++++++++++++++++++++

MAINTAINERS Q: https://patchwork.kernel.org/project/linux-

Quoted 11 lines
 8 files changed, 935 insertions(+)
 create mode 100644 drivers/dma/ae4dma/Kconfig  create mode 100644

drivers/dma/ae4dma/Makefile create mode 100644 drivers/dma/ae4dma/ae4dma-dev.c create mode 100644 drivers/dma/ae4dma/ae4dma-pci.c create mode 100644 drivers/dma/ae4dma/ae4dma.h

MAINTAINERS +0 -0
@@ -891,6 +891,12 @@ Q:     https://patchwork.kernel.org/project/linux-

rdma/list/

Quoted 18 lines
MAINTAINERS +6 -0
 F: drivers/infiniband/hw/efa/
 F: include/uapi/rdma/efa-abi.h
 
+AMD AE4DMA DRIVER
+M: Sanjay R Mehta <[email protected]>
+L: [email protected]
+S: Maintained
+F: drivers/dma/ae4dma/
+
 AMD CDX BUS DRIVER
 M: Nipun Gupta <[email protected]>
 M: Nikhil Agarwal <[email protected]>
drivers/dma/Kconfig index renamed from drivers/dma/Kconfig +0 -0

08fdd0e..b26dbfb 100644

drivers/dma/Kconfig +0 -0
@@ -777,6 +777,8 @@ source "drivers/dma/fsl-dpaa2-qdma/Kconfig"
 
Quoted 7 lines

drivers/dma/Kconfig source "drivers/dma/fsl-dpaa2-qdma/Kconfig" · line 780

Quoted 3 lines
drivers/dma/Kconfig +1 -0
 source "drivers/dma/lgm/Kconfig"
 
+source "drivers/dma/ae4dma/Kconfig"

There is another amd driver on the list, I suggest move all of these to amd/ and have one kconfig inside amd/

Sure Vinod. As you suggested will do this.

Quoted 106 lines
Quoted 21 lines
drivers/dma/Kconfig +1 -0
+
 # clients
 comment "DMA Clients"
    depends on DMA_ENGINE
drivers/dma/Makefile index renamed from drivers/dma/Makefile +0 -0

a4fd1ce..513d87f 100644

drivers/dma/Makefile +1 -0
@@ -81,6 +81,7 @@ obj-$(CONFIG_XGENE_DMA) += xgene-dma.o
 obj-$(CONFIG_ST_FDMA) += st_fdma.o
 obj-$(CONFIG_FSL_DPAA2_QDMA) += fsl-dpaa2-qdma/
 obj-$(CONFIG_INTEL_LDMA) += lgm/
+obj-$(CONFIG_AMD_AE4DMA) += ae4dma/
 
 obj-y += mediatek/
 obj-y += qcom/
drivers/dma/ae4dma/Kconfig new file +0 -0
new file mode 100644 index 0000000..1cda9de

drivers/dma/ae4dma/Kconfig line 5

Quoted 5 lines
drivers/dma/ae4dma/Kconfig new file +5 -0
@@ -0,0 +1,11 @@
+# SPDX-License-Identifier: GPL-2.0-only config AMD_AE4DMA
+   tristate  "AMD AE4DMA Engine"
+   depends on X86_64 && PCI
+   help
+     Enabling this option provides support for the AMD AE4DMA

controller,

drivers/dma/ae4dma/Kconfig line 6

Quoted 1 line
drivers/dma/ae4dma/Kconfig new file +1 -0
+     which offers DMA capabilities for high-bandwidth memory-to-

memory and

drivers/dma/ae4dma/Kconfig

Quoted 3 lines
drivers/dma/ae4dma/Kconfig new file +3 -0
+     I/O copy operations. The controller utilizes a queue-based descriptor
+     management system for efficient DMA transfers. It is specifically
+     designed to be used in conjunction with AMD Non-Transparent

Bridge devices

drivers/dma/ae4dma/Kconfig line 10

Quoted 1 line
drivers/dma/ae4dma/Kconfig new file +1 -0
+     and is not intended for general-purpose peripheral DMA

functionality.

Quoted 33 lines
drivers/dma/ae4dma/Makefile new file +7 -0
new file mode 100644 index 0000000..db9cab1
@@ -0,0 +1,10 @@
+# SPDX-License-Identifier: GPL-2.0-only # # AMD AE4DMA driver #
+
+obj-$(CONFIG_AMD_AE4DMA) += ae4dma.o
+
+ae4dma-objs := ae4dma-dev.o
+
+ae4dma-$(CONFIG_PCI) += ae4dma-pci.o
(quoted diff) +0 -0

b/drivers/dma/ae4dma/ae4dma-dev.c new file mode 100644 index 0000000..a3c50a2

drivers/dma/ae4dma/ae4dma-dev.c new file +15 -0
@@ -0,0 +1,320 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD AE4DMA device driver
+ * -- Based on the PTDMA driver
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Sanjay R Mehta <[email protected]>  */
+
+#include <linux/bitfield.h>
+#include <linux/dma-mapping.h>
+#include <linux/debugfs.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/module.h>

drivers/dma/ae4dma/ae4dma-dev.c line 25

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+#include <linux/pci.h>
+#include <linux/delay.h>
+
+#include "ae4dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
+
+static unsigned int max_hw_q = 1;
+module_param(max_hw_q, uint, 0444);
+MODULE_PARM_DESC(max_hw_q, "Max queues per engine (any non-zero

value

Quoted 7 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +7 -0
+less than or equal to 16, default: 1)");
+
+/* Human-readable error strings */
+static char *ae4_error_codes[] = {
+   "",
+   "ERR 01: INVALID HEADER DW0",
+   "ERR 02: INVALID STATUS",

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+   "ERR 03: INVALID LENGTH - 4 BYTE ALIGNMENT",
+   "ERR 04: INVALID SRC ADDR - 4 BYTE ALIGNMENT",
+   "ERR 05: INVALID DST ADDR - 4 BYTE ALIGNMENT",
+   "ERR 06: INVALID ALIGNMENT",
+   "ERR 07: INVALID DESCRIPTOR",
+};
+
+static void ae4_log_error(struct ae4_device *d, int e) {
+   if (e <= 7)
+           dev_info(d->dev, "AE4DMA error: %s (0x%x)\n",

ae4_error_codes[e], e);

drivers/dma/ae4dma/ae4dma-dev.c line 44

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +2 -0
+   else if (e > 7 && e <= 15)
+           dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "INVALID

DESCRIPTOR", e);

drivers/dma/ae4dma/ae4dma-dev.c line 46

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +2 -0
+   else if (e > 15 && e <= 31)
+           dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "INVALID

DESCRIPTOR", e);

drivers/dma/ae4dma/ae4dma-dev.c line 48

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +2 -0
+   else if (e > 31 && e <= 63)
+           dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "INVALID

DESCRIPTOR", e);

Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dev.c line 50

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +2 -0
+   else if (e > 63 && e <= 127)
+           dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "PTE ERROR",

e);

drivers/dma/ae4dma/ae4dma-dev.c line 52

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +2 -0
+   else if (e > 127 && e <= 255)
+           dev_info(d->dev, "AE4DMA error: %s (0x%x)\n", "PTE ERROR",

e);

why info level? It should err going by fn description

Right, I'll remove that in v2.

Quoted 41 lines
Quoted 21 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +21 -0
+}
+
+void ae4_start_queue(struct ae4_cmd_queue *cmd_q) {
+   /* Turn on the run bit */
+   iowrite32(cmd_q->qcontrol | CMD_Q_RUN, cmd_q->reg_control); }
+
+void ae4_stop_queue(struct ae4_cmd_queue *cmd_q) {
+   /* Turn off the run bit */
+   iowrite32(cmd_q->qcontrol & ~CMD_Q_RUN, cmd_q->reg_control); }
+
+static int ae4_core_execute_cmd(struct ae4dma_desc *desc, struct
+ae4_cmd_queue *cmd_q) {
+   bool soc = FIELD_GET(DWORD0_SOC, desc->dw0);
+   u8 *q_desc = (u8 *)&cmd_q->qbase[0];
+   u32 tail_wi;
+
+   cmd_q->int_rcvd = 0;
+
+   if (soc) {
+           desc->dw0 |= FIELD_PREP(DWORD0_IOC, desc->dw0);
+           desc->dw0 &= ~DWORD0_SOC;

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+   }
+   mutex_lock(&cmd_q->q_mutex);
+
+   /* Write Index of circular queue */
+   tail_wi =  ioread32(cmd_q->reg_control + 0x10);
+   q_desc += (tail_wi * 32);
+
+   /* Copy 32-byte command descriptor to hw queue. */
+   memcpy(q_desc, desc, 32);
+   cmd_q->qidx = (cmd_q->qidx + 1) % CMD_Q_LEN; // Increment

q_desc id.

Quoted 9 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +9 -0
+
+   /* The data used by this command must be flushed to memory */
+   wmb();
+
+   /* Write the new tail_wi address back to the queue register */
+   tail_wi = (tail_wi + 1) % CMD_Q_LEN;
+   iowrite32(tail_wi, cmd_q->reg_control + 0x10);
+
+   mutex_unlock(&cmd_q->q_mutex);
Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +6 -0
+
+   return 0;
+}
+
+int ae4_core_perform_passthru(struct ae4_cmd_queue *cmd_q, struct
+ae4_passthru_engine *ae4_engine)

Who calls this, pls document the arguments for apis

Sure will document this in v2.

Quoted 14 lines

drivers/dma/ae4dma/ae4dma-dev.c line 112

Quoted 11 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+{
+   struct ae4dma_desc desc;
+   struct ae4_device *ae4 = cmd_q->ae4;
+
+   cmd_q->cmd_error = 0;
+   memset(&desc, 0, sizeof(desc));
+   desc.dw0 = CMD_DESC_DW0_VAL;
+   desc.dw1.status = 0;
+   desc.dw1.err_code = 0;
+   desc.dw1.desc_id = 0;

these are redundant, u already did memset

Right, I'll remove that in v2.

Quoted 32 lines
Quoted 32 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +32 -0
+   desc.length = ae4_engine->src_len;
+   desc.src_lo = upper_32_bits(ae4_engine->src_dma);
+   desc.src_hi = lower_32_bits(ae4_engine->src_dma);
+   desc.dst_lo = upper_32_bits(ae4_engine->dst_dma);
+   desc.dst_hi = lower_32_bits(ae4_engine->dst_dma);
+
+   if (cmd_q->int_en)
+           ae4_core_enable_queue_interrupts(ae4, cmd_q);
+   else
+           ae4_core_disable_queue_interrupts(ae4, cmd_q);
+
+   return ae4_core_execute_cmd(&desc, cmd_q); }
+
+static void ae4_do_cmd_complete(struct tasklet_struct *t) {
+   struct ae4_cmd_queue *cmd_q = from_tasklet(cmd_q, t, irq_tasklet);
+   unsigned long flags;
+   struct ae4_cmd *cmd;
+
+   spin_lock_irqsave(&cmd_q->cmd_lock, flags);
+   cmd = list_first_entry(&cmd_q->cmd, struct ae4_cmd, entry);
+   list_del(&cmd->entry);
+   spin_unlock_irqrestore(&cmd_q->cmd_lock, flags);
+
+   cmd->ae4_cmd_callback(cmd->data, cmd->ret); }
+
+void ae4_check_status_trans(struct ae4_device *ae4, struct
+ae4_cmd_queue *cmd_q) {
+   u8 status;
+   int head = ioread32(cmd_q->reg_control + 0x0C);
+   struct ae4dma_desc *desc;
+
+   head = (head - 1) & (CMD_Q_LEN - 1);
Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dev.c line 153

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +6 -0
+   desc = &cmd_q->qbase[head];
+
+   status = desc->dw1.status;
+   if (status) {
+           cmd_q->int_status = status;
+           if (status != 0x3) {

magic number

Sure. Will fix in V2.

Quoted 28 lines
Quoted 12 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +8 -0
+                   /* On error, only save the first error value */
+                   cmd_q->cmd_error = desc->dw1.err_code;
+                   if (cmd_q->cmd_error) {
+                           /*
+                            * Log the error and flush the queue by
+                            * moving the head pointer
+                            */
+                           ae4_log_error(cmd_q->ae4, cmd_q-

cmd_error);

drivers/dma/ae4dma/ae4dma-dev.c new file +3 -0
+                   }
+           }
+   }

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+}
+
+static irqreturn_t ae4_core_irq_handler(int irq, void *data) {
+   struct ae4_cmd_queue *cmd_q = data;
+   struct ae4_device *ae4 = cmd_q->ae4;
+   u32 status = ioread32(cmd_q->reg_control + 0x4);
+   u8 q_intr_type = (status >> 24) & 0xf;
+
+   if (q_intr_type ==  0x4)
+           dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "queue

desc error", q_intr_type);

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +2 -0
+   else if (q_intr_type ==  0x2)
+           dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "queue

stopped", q_intr_type);

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +2 -0
+   else if (q_intr_type ==  0x1)
+           dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "queue
Quoted 8 lines

empty", q_intr_type);

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +2 -0
+   else
+           dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "unknown

error",

Quoted 1 line

+q_intr_type);

better use a switch

Right, Will use switch here in v2.

Quoted 54 lines
Quoted 16 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +16 -0
+
+   ae4_check_status_trans(ae4, cmd_q);
+
+   tasklet_schedule(&cmd_q->irq_tasklet);
+
+   return IRQ_HANDLED;
+}
+
+int ae4_core_init(struct ae4_device *ae4) {
+   char dma_pool_name[MAX_DMAPOOL_NAME_LEN];
+   struct ae4_cmd_queue *cmd_q;
+   u32 dma_addr_lo, dma_addr_hi;
+   struct device *dev = ae4->dev;
+   struct dma_pool *dma_pool;
+   unsigned int i;
+   int ret;

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+   u32 q_per_eng = max_hw_q;
+
+   /* Update the device registers with queue information. */
+   iowrite32(q_per_eng, ae4->io_regs);
+
+   q_per_eng = ioread32(ae4->io_regs);
+
+   for (i = 0; i < q_per_eng; i++) {
+           /* Allocate a dma pool for the queue */
+           snprintf(dma_pool_name, sizeof(dma_pool_name),

"%s_q%d", dev_name(ae4->dev), i);

Quoted 27 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +27 -0
+           dma_pool = dma_pool_create(dma_pool_name, dev,
+                                      AE4_DMAPOOL_MAX_SIZE,
+                                      AE4_DMAPOOL_ALIGN, 0);
+           if (!dma_pool)
+                   return -ENOMEM;
+
+           /* ae4dma core initialisation */
+           cmd_q = &ae4->cmd_q[i];
+           cmd_q->id = ae4->cmd_q_count;
+           ae4->cmd_q_count++;
+           cmd_q->ae4 = ae4;
+           cmd_q->dma_pool = dma_pool;
+           mutex_init(&cmd_q->q_mutex);
+           spin_lock_init(&cmd_q->q_lock);
+
+           /* Preset some register values (Q size is 32byte (0x20)) */
+           cmd_q->reg_control = ae4->io_regs + ((i + 1) * 0x20);
+
+           /* Page alignment satisfies our needs for N <= 128 */
+           cmd_q->qsize = Q_SIZE(Q_DESC_SIZE);
+           cmd_q->qbase = dma_alloc_coherent(dev, cmd_q->qsize,
+&cmd_q->qbase_dma, GFP_KERNEL);
+
+           if (!cmd_q->qbase) {
+                   ret = -ENOMEM;
+                   goto e_destroy_pool;
+           }
Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dev.c line 240

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +6 -0
+
+           cmd_q->qidx = 0;
+           cmd_q->q_space_available = 0;
+
+           init_waitqueue_head(&cmd_q->int_queue);
+           init_waitqueue_head(&cmd_q->q_space);

why do you need two waitqueues here?

These are not used anymore. Will cleanup them in V2.

Quoted 85 lines
Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+
+           dev_dbg(dev, "queue #%u available\n", i);
+   }
+
+   if (ae4->cmd_q_count == 0) {
+           dev_notice(dev, "no command queues available\n");
+           ret = -EIO;
+           goto e_destroy_pool;
+   }
+   for (i = 0; i < ae4->cmd_q_count; i++) {

drivers/dma/ae4dma/ae4dma-dev.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +10 -0
+           cmd_q = &ae4->cmd_q[i];
+           cmd_q->qcontrol = 0;
+           ret = request_irq(ae4->ae4_irq[i], ae4_core_irq_handler, 0,
+                             dev_name(ae4->dev), cmd_q);
+           if (ret) {
+                   dev_err(dev, "unable to allocate an IRQ\n");
+                   goto e_free_dma;
+           }
+
+           /* Update the device registers with cnd queue length (Max

Index reg). */

Quoted 64 lines
drivers/dma/ae4dma/ae4dma-dev.c new file +60 -0
+           iowrite32(CMD_Q_LEN, cmd_q->reg_control + 0x08);
+           cmd_q->qdma_tail = cmd_q->qbase_dma;
+           dma_addr_lo = lower_32_bits(cmd_q->qdma_tail);
+           iowrite32((u32)dma_addr_lo, cmd_q->reg_control + 0x18);
+           dma_addr_lo = ioread32(cmd_q->reg_control + 0x18);
+           dma_addr_hi = upper_32_bits(cmd_q->qdma_tail);
+           iowrite32((u32)dma_addr_hi, cmd_q->reg_control + 0x1C);
+           dma_addr_hi = ioread32(cmd_q->reg_control + 0x1C);
+           ae4_core_enable_queue_interrupts(ae4, cmd_q);
+           INIT_LIST_HEAD(&cmd_q->cmd);
+
+           /* Initialize the ISR tasklet */
+           tasklet_setup(&cmd_q->irq_tasklet, ae4_do_cmd_complete);
+   }
+
+   return 0;
+
+e_free_dma:
+   dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase,
+cmd_q->qbase_dma);
+
+e_destroy_pool:
+   for (i = 0; i < ae4->cmd_q_count; i++)
+           dma_pool_destroy(ae4->cmd_q[i].dma_pool);
+
+   return ret;
+}
+
+void ae4_core_destroy(struct ae4_device *ae4) {
+   struct device *dev = ae4->dev;
+   struct ae4_cmd_queue *cmd_q;
+   struct ae4_cmd *cmd;
+   unsigned int i;
+
+   for (i = 0; i < ae4->cmd_q_count; i++) {
+           cmd_q = &ae4->cmd_q[i];
+
+           wake_up_all(&cmd_q->q_space);
+           wake_up_all(&cmd_q->int_queue);
+
+           /* Disable and clear interrupts */
+           ae4_core_disable_queue_interrupts(ae4, cmd_q);
+
+           /* Turn off the run bit */
+           ae4_stop_queue(cmd_q);
+
+           free_irq(ae4->ae4_irq[i], cmd_q);
+
+           dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase,
+                             cmd_q->qbase_dma);
+   }
+
+   /* Flush the cmd queue */
+   while (!list_empty(&ae4->cmd)) {
+           /* Invoke the callback directly with an error code */
+           cmd = list_first_entry(&ae4->cmd, struct ae4_cmd, entry);
+           list_del(&cmd->entry);
+           cmd->ae4_cmd_callback(cmd->data, -ENODEV);
+   }
+}
(quoted diff) +0 -0

b/drivers/dma/ae4dma/ae4dma-pci.c new file mode 100644 index 0000000..a77fbb5
--- /dev/null

Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dev.c line 4

Quoted 6 lines

+++ b/drivers/dma/ae4dma/ae4dma-pci.c

drivers/dma/ae4dma/ae4dma-dev.c new file +4 -0
@@ -0,0 +1,247 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD AE4DMA device driver
+ * -- Based on the PTDMA driver

cant we use ptdma driver to support both cores?

AE4DMA has multiple channels per engine, whereas PTDMA is limited to a single channel per engine. Furthermore, there are significant disparities in both the DMA engines and their respective handling methods. Hence wanted to keep separate codes for PTDMA and AE4DMA.

Quoted 26 lines
Quoted 26 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +26 -0
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Sanjay R Mehta <[email protected]> */
+
+#include <linux/device.h>
+#include <linux/dma-mapping.h>
+#include <linux/delay.h>
+#include <linux/interrupt.h>
+#include <linux/kernel.h>
+#include <linux/kthread.h>
+#include <linux/module.h>
+#include <linux/pci_ids.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+
+#include "ae4dma.h"
+
+struct ae4_msix {
+   int msix_count;
+   struct msix_entry msix_entry[MAX_HW_QUEUES]; };
+
+/*
+ * ae4_alloc_struct - allocate and initialize the ae4_device struct
+ *
+ * @dev: device struct of the AE4DMA
Quoted 8 lines

drivers/dma/ae4dma/ae4dma-pci.c line 39

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +6 -0
+ */
+static struct ae4_device *ae4_alloc_struct(struct device *dev) {
+   struct ae4_device *ae4;
+
+   ae4 = devm_kzalloc(dev, sizeof(*ae4), GFP_KERNEL);
+

This empty line here doesnt make sense

Sure. Will fix this in v2.

Quoted 5 lines

drivers/dma/ae4dma/ae4dma-pci.c line 41

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +2 -0
+   if (!ae4)
+           return NULL;

it should be here instead :-)

Sure. Will fix this in v2.

Quoted 174 lines
Quoted 129 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +129 -0
+   ae4->dev = dev;
+
+   INIT_LIST_HEAD(&ae4->cmd);
+
+   return ae4;
+}
+
+static int ae4_get_msix_irqs(struct ae4_device *ae4) {
+   struct ae4_msix *ae4_msix = ae4->ae4_msix;
+   struct device *dev = ae4->dev;
+   struct pci_dev *pdev = to_pci_dev(dev);
+   int v, i, ret;
+
+   for (v = 0; v < ARRAY_SIZE(ae4_msix->msix_entry); v++)
+           ae4_msix->msix_entry[v].entry = v;
+
+   ret = pci_enable_msix_range(pdev, ae4_msix->msix_entry, 1, v);
+   if (ret < 0)
+           return ret;
+
+   ae4_msix->msix_count = ret;
+
+   for (i = 0; i < MAX_HW_QUEUES; i++)
+           ae4->ae4_irq[i] = ae4_msix->msix_entry[i].vector;
+
+   return 0;
+}
+
+static int ae4_get_msi_irq(struct ae4_device *ae4) {
+   struct device *dev = ae4->dev;
+   struct pci_dev *pdev = to_pci_dev(dev);
+   int ret, i;
+
+   ret = pci_enable_msi(pdev);
+   if (ret)
+           return ret;
+
+   for (i = 0; i < MAX_HW_QUEUES; i++)
+           ae4->ae4_irq[i] = pdev->irq;
+
+   return 0;
+}
+
+static int ae4_get_irqs(struct ae4_device *ae4) {
+   struct device *dev = ae4->dev;
+   int ret;
+
+   ret = ae4_get_msix_irqs(ae4);
+   if (!ret)
+           return 0;
+
+   /* Couldn't get MSI-X vectors, try MSI */
+   dev_err(dev, "could not enable MSI-X (%d), trying MSI\n", ret);
+   ret = ae4_get_msi_irq(ae4);
+   if (!ret)
+           return 0;
+
+   /* Couldn't get MSI interrupt */
+   dev_err(dev, "could not enable MSI (%d)\n", ret);
+
+   return ret;
+}
+
+static void ae4_free_irqs(struct ae4_device *ae4) {
+   struct ae4_msix *ae4_msix = ae4->ae4_msix;
+   struct device *dev = ae4->dev;
+   struct pci_dev *pdev = to_pci_dev(dev);
+   unsigned int i;
+
+   if (ae4_msix->msix_count)
+           pci_disable_msix(pdev);
+   else if (ae4->ae4_irq)
+           pci_disable_msi(pdev);
+
+   for (i = 0; i < MAX_HW_QUEUES; i++)
+           ae4->ae4_irq[i] = 0;
+}
+
+static int ae4_pci_probe(struct pci_dev *pdev, const struct
+pci_device_id *id) {
+   struct ae4_device *ae4;
+   struct ae4_msix *ae4_msix;
+   struct device *dev = &pdev->dev;
+   void __iomem * const *iomap_table;
+   int bar_mask;
+   int ret = -ENOMEM;
+
+   ae4 = ae4_alloc_struct(dev);
+   if (!ae4)
+           goto e_err;
+
+   ae4_msix = devm_kzalloc(dev, sizeof(*ae4_msix), GFP_KERNEL);
+   if (!ae4_msix)
+           goto e_err;
+
+   ae4->ae4_msix = ae4_msix;
+   ae4->dev_vdata = (struct ae4_dev_vdata *)id->driver_data;
+   if (!ae4->dev_vdata) {
+           ret = -ENODEV;
+           dev_err(dev, "missing driver data\n");
+           goto e_err;
+   }
+
+   ret = pcim_enable_device(pdev);
+   if (ret) {
+           dev_err(dev, "pcim_enable_device failed (%d)\n", ret);
+           goto e_err;
+   }
+
+   bar_mask = pci_select_bars(pdev, IORESOURCE_MEM);
+   ret = pcim_iomap_regions(pdev, bar_mask, "ae4dma");
+   if (ret) {
+           dev_err(dev, "pcim_iomap_regions failed (%d)\n", ret);
+           goto e_err;
+   }
+
+   iomap_table = pcim_iomap_table(pdev);
+   if (!iomap_table) {
+           dev_err(dev, "pcim_iomap_table failed\n");
+           ret = -ENOMEM;
+           goto e_err;
+   }
+
+   ae4->io_regs = iomap_table[ae4->dev_vdata->bar];
+   if (!ae4->io_regs) {
+           dev_err(dev, "ioremap failed\n");
+           ret = -ENOMEM;
+           goto e_err;
+   }

drivers/dma/ae4dma/ae4dma-pci.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +10 -0
+
+   ret = ae4_get_irqs(ae4);
+   if (ret)
+           goto e_err;
+
+   pci_set_master(pdev);
+
+   ret = dma_set_mask_and_coherent(dev, DMA_BIT_MASK(48));
+   if (ret) {
+           ret = dma_set_mask_and_coherent(dev,

DMA_BIT_MASK(32));

Review line 179

Quoted 2 lines
(quoted diff) +2 -0
+           if (ret) {
+                   dev_err(dev, "dma_set_mask_and_coherent failed

(%d)\n",

Quoted 31 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +31 -0
+                           ret);
+                   goto e_err;
+           }
+   }
+
+   dev_set_drvdata(dev, ae4);
+
+   if (ae4->dev_vdata)
+           ret = ae4_core_init(ae4);
+
+   if (ret)
+           goto e_err;
+
+   return 0;
+
+e_err:
+   dev_err(dev, "initialization failed ret = %d\n", ret);
+
+   return ret;
+}
+
+static void ae4_pci_remove(struct pci_dev *pdev) {
+   struct device *dev = &pdev->dev;
+   struct ae4_device *ae4 = dev_get_drvdata(dev);
+
+   if (!ae4)
+           return;
+
+   if (ae4->dev_vdata)
+           ae4_core_destroy(ae4);
+
Quoted 9 lines

drivers/dma/ae4dma/ae4dma-pci.c line 224

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +6 -0
+   ae4_free_irqs(ae4);
+}
+
+static const struct ae4_dev_vdata dev_vdata[] = {
+   {
+           .bar = 0,

why pass zero data?

Initially, during the bringup phase, the base address was included part of BAR2. However, it was subsequently resolved to BAR0 in the latest silicon. Hence storing BAR info is not needed anymore. Will fix in v2.

Quoted 65 lines
Quoted 12 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +12 -0
+   },
+};
+
+static const struct pci_device_id ae4_pci_table[] = {
+   { PCI_VDEVICE(AMD, 0x14C8), (kernel_ulong_t)&dev_vdata[0] },
+   { PCI_VDEVICE(AMD, 0x14DC), (kernel_ulong_t)&dev_vdata[0] },
+   /* Last entry must be zero */
+   { 0, }
+};
+MODULE_DEVICE_TABLE(pci, ae4_pci_table);
+
+static struct pci_driver ae4_pci_driver = {

drivers/dma/ae4dma/ae4dma-pci.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-pci.c new file +10 -0
+   .name = "ae4dma",
+   .id_table = ae4_pci_table,
+   .probe = ae4_pci_probe,
+   .remove = ae4_pci_remove,
+};
+
+module_pci_driver(ae4_pci_driver);
+
+MODULE_AUTHOR("Sanjay R Mehta <[email protected]>");
+MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("AMD AE4DMA

driver");

Review

Quoted 1 line
(quoted diff) +0 -0

b/drivers/dma/ae4dma/ae4dma.h

Quoted 40 lines

new file mode 100644 index 0000000..0ae46ee

drivers/dma/ae4dma/ae4dma.h new file +36 -0
@@ -0,0 +1,338 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * AMD AE4DMA device driver
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Sanjay R Mehta <[email protected]>  */
+
+#ifndef __AE4_DEV_H__
+#define __AE4_DEV_H__
+
+#include <linux/device.h>
+#include <linux/pci.h>
+#include <linux/spinlock.h>
+#include <linux/mutex.h>
+#include <linux/list.h>
+#include <linux/wait.h>
+#include <linux/dmapool.h>
+
+#define MAX_AE4_NAME_LEN                   16
+#define MAX_DMAPOOL_NAME_LEN               32
+
+#define MAX_HW_QUEUES                      16
+#define MAX_CMD_QLEN                       32
+
+#define AE4_ENGINE_PASSTHRU                5
+
+/* Register Mappings */
+#define IRQ_MASK_REG                       0x040
+#define IRQ_STATUS_REG                     0x200
+
+#define CMD_Q_ERROR(__qs)          ((__qs) & 0x0000003f)
+
+#define CMD_QUEUE_PRIO_OFFSET              0x00
+#define CMD_REQID_CONFIG_OFFSET            0x04
+#define CMD_TIMEOUT_OFFSET         0x08
Quoted 9 lines

drivers/dma/ae4dma/ae4dma.h line 43

Quoted 6 lines
drivers/dma/ae4dma/ae4dma.h new file +6 -0
+#define CMD_AE4_VERSION                    0x10
+
+#define CMD_Q_CONTROL_BASE         0x0000
+#define CMD_Q_TAIL_LO_BASE         0x0004
+#define CMD_Q_HEAD_LO_BASE         0x0008
+#define CMD_Q_INT_ENABLE_BASE              0x000C

lower case please (here and elsewhere)

Sure. Will fix in V2.

Quoted 2 lines

--
~Vinod

maintainer
#4 lore raw

Re: [PATCH 1/3] dmaengine: ae4dma: Initial ae4dma controller driver with multi channel

Quoted 1 line · Sanju

[AMD Official Use Only - General]

??

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0

b/drivers/dma/ae4dma/ae4dma-pci.c new file mode 100644 index 0000000..a77fbb5
--- /dev/null

Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dev.c line 4

Quoted 6 lines

+++ b/drivers/dma/ae4dma/ae4dma-pci.c

drivers/dma/ae4dma/ae4dma-dev.c new file +4 -0
@@ -0,0 +1,247 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD AE4DMA device driver
+ * -- Based on the PTDMA driver

cant we use ptdma driver to support both cores?

Quoted 1 line

AE4DMA has multiple channels per engine, whereas PTDMA is limited to a single channel per engine. Furthermore, there are significant disparities in both the DMA engines and their respective handling methods. Hence wanted to keep separate codes for PTDMA and AE4DMA.

Pls wrap your replies to 80chars!

The channel count should be configurable and for the handling methods, you can have low level handler functions for each controller which can be selected based on device probe

I feel reuse of code is better idea than having two different drivers

Signature · 1 line
~Vinod
#5 lore raw

RE: [PATCH 1/3] dmaengine: ae4dma: Initial ae4dma controller driver with multi channel

[AMD Official Use Only - General]

Quoted 33 lines

-----Original Message-----
From: Vinod Koul <[email protected]>
Sent: Monday, October 16, 2023 12:15 PM
To: Mehta, Sanju <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 1/3] dmaengine: ae4dma: Initial ae4dma controller driver with multi channel

Quoted 1 line · Sanju

[AMD Official Use Only - General]

??

Quoted 13 lines
Quoted 4 lines
Quoted 4 lines
(quoted diff) +0 -0

b/drivers/dma/ae4dma/ae4dma-pci.c new file mode 100644 index 0000000..a77fbb5
--- /dev/null

Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dev.c line 4

Quoted 6 lines

+++ b/drivers/dma/ae4dma/ae4dma-pci.c

drivers/dma/ae4dma/ae4dma-dev.c new file +4 -0
@@ -0,0 +1,247 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD AE4DMA device driver
+ * -- Based on the PTDMA driver

cant we use ptdma driver to support both cores?

Quoted 1 line

AE4DMA has multiple channels per engine, whereas PTDMA is limited to a

single channel per engine. Furthermore, there are significant disparities in both the DMA engines and their respective handling methods. Hence wanted to keep separate codes for PTDMA and AE4DMA.

Quoted 7 lines

Pls wrap your replies to 80chars!

The channel count should be configurable and for the handling methods, you can have low level handler functions for each controller which can be selected based on device probe

I feel reuse of code is better idea than having two different drivers

Yes, I agree. I will combine both so that code can be reused.

- Sanjay

Quoted 2 lines

--
~Vinod

#6 lore raw

PATCH 2/3 dmaengine: ae4dma: register AE4DMA controller as a DMA resource

In reply to Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

Register ae4dma queue's to Linux dmaengine framework as general-purpose DMA channels.

---
 drivers/dma/ae4dma/Kconfig            |   2 +
 drivers/dma/ae4dma/Makefile           |   2 +-
 drivers/dma/ae4dma/ae4dma-dev.c       |  17 ++
 drivers/dma/ae4dma/ae4dma-dmaengine.c | 425 ++++++++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma.h           |  28 +++
 5 files changed, 473 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/ae4dma/ae4dma-dmaengine.c
drivers/dma/ae4dma/Kconfig +2 -0
index 1cda9de..3d1dbb7 100644
@@ -2,6 +2,8 @@
 config AMD_AE4DMA
 	tristate  "AMD AE4DMA Engine"
 	depends on X86_64 && PCI
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
 	help
 	  Enabling this option provides support for the AMD AE4DMA controller,
 	  which offers DMA capabilities for high-bandwidth memory-to-memory and
drivers/dma/ae4dma/Makefile +1 -1
index db9cab1..b1e4318 100644
@@ -5,6 +5,6 @@
 
 obj-$(CONFIG_AMD_AE4DMA) += ae4dma.o
 
-ae4dma-objs := ae4dma-dev.o
+ae4dma-objs := ae4dma-dev.o ae4dma-dmaengine.o
 
 ae4dma-$(CONFIG_PCI) += ae4dma-pci.o
drivers/dma/ae4dma/ae4dma-dev.c +17 -0
index a3c50a2..af7e510 100644
@@ -25,6 +25,11 @@ static unsigned int max_hw_q = 1;
 module_param(max_hw_q, uint, 0444);
 MODULE_PARM_DESC(max_hw_q, "Max queues per engine (any non-zero value less than or equal to 16, default: 1)");
 
+static inline struct ae4_dma_chan *to_ae4_chan(struct dma_chan *dma_chan)
+{
+	return container_of(dma_chan, struct ae4_dma_chan, vc.chan);
+}
+
 /* Human-readable error strings */
 static char *ae4_error_codes[] = {
 	"",
@@ -273,8 +278,17 @@ int ae4_core_init(struct ae4_device *ae4)
 		tasklet_setup(&cmd_q->irq_tasklet, ae4_do_cmd_complete);
 	}
 
+	/* register to the DMA engine */
+	ret = ae4_dmaengine_register(ae4);
+	if (ret)
+		goto e_free_irq;
+
 	return 0;
 
+e_free_irq:
+	for (i = 0; i < ae4->cmd_q_count; i++)
+		free_irq(ae4->ae4_irq[i], ae4);
+
 e_free_dma:
 	dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase, cmd_q->qbase_dma);
 
@@ -292,6 +306,9 @@ void ae4_core_destroy(struct ae4_device *ae4)
 	struct ae4_cmd *cmd;
 	unsigned int i;
 
+	/* Unregister the DMA engine */
+	ae4_dmaengine_unregister(ae4);
+
 	for (i = 0; i < ae4->cmd_q_count; i++) {
 		cmd_q = &ae4->cmd_q[i];
 
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +425 -0

425 lines not on this page · raw message

drivers/dma/ae4dma/ae4dma.h +28 -0
index 0ae46ee..d341c35 100644
@@ -11,6 +11,7 @@
 #define __AE4_DEV_H__
 
 #include <linux/device.h>
+#include <linux/dmaengine.h>
 #include <linux/pci.h>
 #include <linux/spinlock.h>
 #include <linux/mutex.h>
@@ -18,6 +19,8 @@
 #include <linux/wait.h>
 #include <linux/dmapool.h>
 
+#include "../virt-dma.h"
+
 #define MAX_AE4_NAME_LEN			16
 #define MAX_DMAPOOL_NAME_LEN		32
 
@@ -168,6 +171,22 @@ struct ae4_cmd {
 	u8 qid;
 };
 
+struct ae4_dma_desc {
+	struct virt_dma_desc vd;
+	struct ae4_device *ae4;
+	enum dma_status status;
+	size_t len;
+	bool issued_to_hw;
+	struct ae4_cmd ae4_cmd;
+};
+
+struct ae4_dma_chan {
+	struct virt_dma_chan vc;
+	struct ae4_device *ae4;
+	struct ae4_cmd_queue *cmd_q;
+	u32 id;
+};
+
 struct ae4_cmd_queue {
 	struct ae4_device *ae4;
 
@@ -248,6 +267,12 @@ struct ae4_device {
 	struct ae4_cmd_queue cmd_q[MAX_HW_QUEUES];
 	unsigned int cmd_q_count;
 
+	/* Support for the DMA Engine capabilities */
+	struct dma_device dma_dev;
+	struct ae4_dma_chan *ae4_dma_chan;
+	struct kmem_cache *dma_cmd_cache;
+	struct kmem_cache *dma_desc_cache;
+
 	wait_queue_head_t lsb_queue;
 };
 
@@ -298,6 +323,9 @@ struct ae4_dev_vdata {
 	const unsigned int bar;
 };
 
+int ae4_dmaengine_register(struct ae4_device *ae4);
+void ae4_dmaengine_unregister(struct ae4_device *ae4);
+
 int ae4_core_init(struct ae4_device *ae4);
 void ae4_core_destroy(struct ae4_device *ae4);
 
Signature · 1 line
2.7.4
maintainer
#7 lore raw

Re: [PATCH 2/3] dmaengine: ae4dma: register AE4DMA controller as a DMA resource

Quoted 90 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

Register ae4dma queue's to Linux dmaengine framework as general-purpose DMA channels.

---
 drivers/dma/ae4dma/Kconfig            |   2 +
 drivers/dma/ae4dma/Makefile           |   2 +-
 drivers/dma/ae4dma/ae4dma-dev.c       |  17 ++
 drivers/dma/ae4dma/ae4dma-dmaengine.c | 425 ++++++++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma.h           |  28 +++
 5 files changed, 473 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/ae4dma/ae4dma-dmaengine.c
drivers/dma/ae4dma/Kconfig +2 -0
index 1cda9de..3d1dbb7 100644
@@ -2,6 +2,8 @@
 config AMD_AE4DMA
 	tristate  "AMD AE4DMA Engine"
 	depends on X86_64 && PCI
+	select DMA_ENGINE
+	select DMA_VIRTUAL_CHANNELS
 	help
 	  Enabling this option provides support for the AMD AE4DMA controller,
 	  which offers DMA capabilities for high-bandwidth memory-to-memory and
drivers/dma/ae4dma/Makefile +1 -1
index db9cab1..b1e4318 100644
@@ -5,6 +5,6 @@
 
 obj-$(CONFIG_AMD_AE4DMA) += ae4dma.o
 
-ae4dma-objs := ae4dma-dev.o
+ae4dma-objs := ae4dma-dev.o ae4dma-dmaengine.o
 
 ae4dma-$(CONFIG_PCI) += ae4dma-pci.o
drivers/dma/ae4dma/ae4dma-dev.c +17 -0
index a3c50a2..af7e510 100644
@@ -25,6 +25,11 @@ static unsigned int max_hw_q = 1;
 module_param(max_hw_q, uint, 0444);
 MODULE_PARM_DESC(max_hw_q, "Max queues per engine (any non-zero value less than or equal to 16, default: 1)");
 
+static inline struct ae4_dma_chan *to_ae4_chan(struct dma_chan *dma_chan)
+{
+	return container_of(dma_chan, struct ae4_dma_chan, vc.chan);
+}
+
 /* Human-readable error strings */
 static char *ae4_error_codes[] = {
 	"",
@@ -273,8 +278,17 @@ int ae4_core_init(struct ae4_device *ae4)
 		tasklet_setup(&cmd_q->irq_tasklet, ae4_do_cmd_complete);
 	}
 
+	/* register to the DMA engine */
+	ret = ae4_dmaengine_register(ae4);
+	if (ret)
+		goto e_free_irq;
+
 	return 0;
 
+e_free_irq:
+	for (i = 0; i < ae4->cmd_q_count; i++)
+		free_irq(ae4->ae4_irq[i], ae4);
+
 e_free_dma:
 	dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase, cmd_q->qbase_dma);
 
@@ -292,6 +306,9 @@ void ae4_core_destroy(struct ae4_device *ae4)
 	struct ae4_cmd *cmd;
 	unsigned int i;
 
+	/* Unregister the DMA engine */
+	ae4_dmaengine_unregister(ae4);
+
 	for (i = 0; i < ae4->cmd_q_count; i++) {
 		cmd_q = &ae4->cmd_q[i];
 
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +0 -0
new file mode 100644
index 0000000..a50e4f5

drivers/dma/ae4dma/ae4dma-dmaengine.c line 4

Quoted 4 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +4 -0
@@ -0,0 +1,425 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD AE4DMA device driver
+ * -- Based on the PTDMA driver

How different is it from PTDMA, why cant this be incorporated in ptdma driver

Quoted 90 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +90 -0
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Sanjay R Mehta <[email protected]>
+ */
+#include <linux/delay.h>
+#include "ae4dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
+
+static inline struct ae4_dma_chan *to_ae4_chan(struct dma_chan *dma_chan)
+{
+	return container_of(dma_chan, struct ae4_dma_chan, vc.chan);
+}
+
+static inline struct ae4_dma_desc *to_ae4_desc(struct virt_dma_desc *vd)
+{
+	return container_of(vd, struct ae4_dma_desc, vd);
+}
+
+static void ae4_free_chan_resources(struct dma_chan *dma_chan)
+{
+	struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+
+	vchan_free_chan_resources(&chan->vc);
+}
+
+static void ae4_synchronize(struct dma_chan *dma_chan)
+{
+	struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+
+	vchan_synchronize(&chan->vc);
+}
+
+static void ae4_do_cleanup(struct virt_dma_desc *vd)
+{
+	struct ae4_dma_desc *desc = to_ae4_desc(vd);
+	struct ae4_device *ae4 = desc->ae4;
+
+	kmem_cache_free(ae4->dma_desc_cache, desc);
+}
+
+static int ae4_dma_start_desc(struct ae4_dma_desc *desc, struct ae4_dma_chan *chan)
+{
+	struct ae4_passthru_engine *ae4_engine;
+	struct ae4_device *ae4;
+	struct ae4_cmd *ae4_cmd;
+	struct ae4_cmd_queue *cmd_q;
+
+	desc->issued_to_hw = 1;
+	list_del(&desc->vd.node);
+
+	ae4_cmd = &desc->ae4_cmd;
+	ae4 = ae4_cmd->ae4;
+	cmd_q = chan->cmd_q;
+	ae4_engine = &ae4_cmd->passthru;
+
+	ae4_cmd->qid = cmd_q->qidx;
+	cmd_q->tdata.cmd = ae4_cmd;
+
+	/* Execute the command */
+	ae4_cmd->ret = ae4_core_perform_passthru(cmd_q, ae4_engine);
+
+	return 0;
+}
+
+static struct ae4_dma_desc *ae4_next_dma_desc(struct ae4_dma_chan *chan)
+{
+	/* Get the next DMA descriptor on the active list */
+	struct virt_dma_desc *vd = vchan_next_desc(&chan->vc);
+
+	return vd ? to_ae4_desc(vd) : NULL;
+}
+
+static void ae4_cmd_callback_tasklet(void *data, int err)
+{
+	struct ae4_dma_desc *desc = data;
+	struct dma_chan *dma_chan;
+	struct ae4_dma_chan *chan;
+	struct dma_async_tx_descriptor *tx_desc;
+	struct virt_dma_desc *vd;
+	unsigned long flags;
+
+	dma_chan = desc->vd.tx.chan;
+	chan = to_ae4_chan(dma_chan);
+
+	if (err == -EINPROGRESS)
+		return;
+
+	tx_desc = &desc->vd.tx;

drivers/dma/ae4dma/ae4dma-dmaengine.c line 104

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+	vd = &desc->vd;
+
+	if (err)
+		desc->status = DMA_ERROR;
+
+	spin_lock_irqsave(&chan->vc.lock, flags);
+	if (desc) {
+		if (desc->status != DMA_COMPLETE) {
+			if (desc->status != DMA_ERROR)
+				desc->status = DMA_COMPLETE;

So a DMA_IN_PROGRESS descriptor would be marked complete?

Quoted 137 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +137 -0
+
+			dma_cookie_complete(tx_desc);
+			dma_descriptor_unmap(tx_desc);
+		} else {
+			/* Don't handle it twice */
+			tx_desc = NULL;
+		}
+	}
+	spin_unlock_irqrestore(&chan->vc.lock, flags);
+
+	if (tx_desc) {
+		dmaengine_desc_get_callback_invoke(tx_desc, NULL);
+		dma_run_dependencies(tx_desc);
+	}
+}
+
+static struct ae4_dma_desc *ae4_handle_active_desc(struct ae4_dma_chan *chan,
+						   struct ae4_dma_desc *desc)
+{
+	struct dma_async_tx_descriptor *tx_desc;
+	struct virt_dma_desc *vd;
+	unsigned long flags;
+
+	/* Loop over descriptors until one is found with commands */
+	do {
+		if (desc) {
+			if (!desc->issued_to_hw) {
+				/* No errors, keep going */
+				if (desc->status != DMA_ERROR)
+					return desc;
+			}
+			tx_desc = &desc->vd.tx;
+			vd = &desc->vd;
+		} else {
+			tx_desc = NULL;
+		}
+		spin_lock_irqsave(&chan->vc.lock, flags);
+		desc = ae4_next_dma_desc(chan);
+		spin_unlock_irqrestore(&chan->vc.lock, flags);
+	} while (desc);
+
+	return NULL;
+}
+
+static void ae4_cmd_callback(void *data, int err)
+{
+	struct ae4_dma_desc *desc = data;
+	struct dma_chan *dma_chan;
+	struct ae4_dma_chan *chan;
+	struct ae4_device *ae4;
+	int ret;
+
+	if (err == -EINPROGRESS)
+		return;
+
+	dma_chan = desc->vd.tx.chan;
+	chan = to_ae4_chan(dma_chan);
+	ae4 = chan->ae4;
+
+	if (err)
+		desc->status = DMA_ERROR;
+
+	while (true) {
+		/* Check for DMA descriptor completion */
+		desc = ae4_handle_active_desc(chan, desc);
+
+		/* Don't submit cmd if no descriptor or DMA is paused */
+		if (!desc)
+			break;
+
+		/* if queue is full dont submit to queue */
+		if (ae4_core_queue_full(ae4, chan->cmd_q)) {
+			usleep_range(100, 200);
+			continue;
+		}
+
+		ret = ae4_dma_start_desc(desc, chan);
+		if (!ret)
+			break;
+
+		desc->status = DMA_ERROR;
+	}
+}
+
+static struct ae4_dma_desc *ae4_alloc_dma_desc(struct ae4_dma_chan *chan, unsigned long flags)
+{
+	struct ae4_dma_desc *desc;
+	struct ae4_cmd_queue *cmd_q = chan->cmd_q;
+
+	desc = kmem_cache_zalloc(chan->ae4->dma_desc_cache, GFP_NOWAIT);
+	if (!desc)
+		return NULL;
+
+	vchan_tx_prep(&chan->vc, &desc->vd, flags);
+
+	desc->ae4 = chan->ae4;
+	cmd_q->int_en = !!(flags & DMA_PREP_INTERRUPT);
+	desc->issued_to_hw = 0;
+	desc->status = DMA_IN_PROGRESS;
+
+	return desc;
+}
+
+static struct ae4_dma_desc *ae4_create_desc(struct dma_chan *dma_chan,
+					    dma_addr_t dst,
+					    dma_addr_t src,
+					    unsigned int len,
+					    unsigned long flags)
+{
+	struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+	struct ae4_cmd_queue *cmd_q = chan->cmd_q;
+	struct ae4_passthru_engine *ae4_engine;
+	struct ae4_dma_desc *desc;
+	struct ae4_cmd *ae4_cmd;
+
+	desc = ae4_alloc_dma_desc(chan, flags);
+	if (!desc)
+		return NULL;
+
+	ae4_cmd = &desc->ae4_cmd;
+	ae4_cmd->ae4 = chan->ae4;
+	ae4_engine = &ae4_cmd->passthru;
+	ae4_cmd->engine = AE4_ENGINE_PASSTHRU;
+	ae4_engine->src_dma = src;
+	ae4_engine->dst_dma = dst;
+	ae4_engine->src_len = len;
+	ae4_cmd->ae4_cmd_callback = ae4_cmd_callback_tasklet;
+	ae4_cmd->data = desc;
+
+	desc->len = len;
+
+	spin_lock_irqsave(&cmd_q->cmd_lock, flags);
+	list_add_tail(&ae4_cmd->entry, &cmd_q->cmd);
+	spin_unlock_irqrestore(&cmd_q->cmd_lock, flags);
+
+	return desc;
+}

drivers/dma/ae4dma/ae4dma-dmaengine.c line 251

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+
+static struct dma_async_tx_descriptor *
+ae4_prep_dma_memcpy(struct dma_chan *dma_chan, dma_addr_t dst,
+		    dma_addr_t src, size_t len, unsigned long flags)
+{
+	struct ae4_dma_desc *desc;
+
+	desc = ae4_create_desc(dma_chan, dst, src, len, flags);
+	if (!desc)
+		return NULL;

I dont see any logic in splitting these into two!

Quoted 28 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +28 -0
+
+	return &desc->vd.tx;
+}
+
+static struct dma_async_tx_descriptor *
+ae4_prep_dma_interrupt(struct dma_chan *dma_chan, unsigned long flags)
+{
+	struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+	struct ae4_dma_desc *desc;
+
+	desc = ae4_alloc_dma_desc(chan, flags);
+	if (!desc)
+		return NULL;
+
+	return &desc->vd.tx;
+}
+
+static void ae4_issue_pending(struct dma_chan *dma_chan)
+{
+	struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+	struct ae4_dma_desc *desc;
+	unsigned long flags;
+
+	spin_lock_irqsave(&chan->vc.lock, flags);
+	vchan_issue_pending(&chan->vc);
+	desc = ae4_next_dma_desc(chan);
+	spin_unlock_irqrestore(&chan->vc.lock, flags);
+

drivers/dma/ae4dma/ae4dma-dmaengine.c line 289

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+	ae4_cmd_callback(desc, 0);
+}
+
+static int ae4_pause(struct dma_chan *dma_chan)
+{
+	struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+	unsigned long flags;
+
+	spin_lock_irqsave(&chan->vc.lock, flags);
+	//TODO : implemnt pause

typo implemnt and drop this and add when you add support! No dummy code please

Quoted 9 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +9 -0
+	spin_unlock_irqrestore(&chan->vc.lock, flags);
+
+	return 0;
+}
+
+static int ae4_resume(struct dma_chan *dma_chan)
+{
+	struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+	struct ae4_dma_desc *desc = NULL;

drivers/dma/ae4dma/ae4dma-dmaengine.c line 308

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+	unsigned long flags;
+
+	spin_lock_irqsave(&chan->vc.lock, flags);
+	ae4_start_queue(chan->cmd_q);
+	desc = ae4_next_dma_desc(chan);
+	spin_unlock_irqrestore(&chan->vc.lock, flags);
+
+	/* If there was something active, re-start */
+	if (desc)
+		ae4_cmd_callback(desc, 0);

resume when no pause is supported..??

Signature · 1 line
~Vinod
#8 lore raw

RE: [PATCH 2/3] dmaengine: ae4dma: register AE4DMA controller as a DMA resource

[Public]

Quoted 215 lines

-----Original Message-----
From: Vinod Koul <[email protected]>
Sent: Wednesday, October 4, 2023 6:18 PM
To: Mehta, Sanju <[email protected]>
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]; linux- [email protected]; [email protected]
Subject: Re: [PATCH 2/3] dmaengine: ae4dma: register AE4DMA controller as a DMA resource

Quoted 3 lines · Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

Register ae4dma queue's to Linux dmaengine framework as general-

purpose

Quoted 8 lines

DMA channels.

---
 drivers/dma/ae4dma/Kconfig            |   2 +
 drivers/dma/ae4dma/Makefile           |   2 +-
 drivers/dma/ae4dma/ae4dma-dev.c       |  17 ++
 drivers/dma/ae4dma/ae4dma-dmaengine.c | 425

++++++++++++++++++++++++++++++++++

Quoted 9 lines
 drivers/dma/ae4dma/ae4dma.h           |  28 +++
 5 files changed, 473 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/ae4dma/ae4dma-dmaengine.c
drivers/dma/ae4dma/Kconfig +0 -0
index 1cda9de..3d1dbb7 100644

drivers/dma/ae4dma/Kconfig line 8

Quoted 7 lines
drivers/dma/ae4dma/Kconfig +2 -0
@@ -2,6 +2,8 @@
 config AMD_AE4DMA
    tristate  "AMD AE4DMA Engine"
    depends on X86_64 && PCI
+   select DMA_ENGINE
+   select DMA_VIRTUAL_CHANNELS
    help
      Enabling this option provides support for the AMD AE4DMA

controller,

drivers/dma/ae4dma/Kconfig line 9

Quoted 1 line
drivers/dma/ae4dma/Kconfig +0 -0
      which offers DMA capabilities for high-bandwidth memory-to-

memory and

Review

Quoted 13 lines
drivers/dma/ae4dma/Makefile +1 -1
index db9cab1..b1e4318 100644
@@ -5,6 +5,6 @@
 
 obj-$(CONFIG_AMD_AE4DMA) += ae4dma.o
 
-ae4dma-objs := ae4dma-dev.o
+ae4dma-objs := ae4dma-dev.o ae4dma-dmaengine.o
 
 ae4dma-$(CONFIG_PCI) += ae4dma-pci.o
(quoted diff) +0 -0

b/drivers/dma/ae4dma/ae4dma-dev.c

drivers/dma/ae4dma/ae4dma-dev.c static unsigned int max_hw_q = 1; · line 26

Quoted 6 lines

index a3c50a2..af7e510 100644

drivers/dma/ae4dma/ae4dma-dev.c +0 -0
@@ -25,6 +25,11 @@ static unsigned int max_hw_q = 1;
 module_param(max_hw_q, uint, 0444);
 MODULE_PARM_DESC(max_hw_q, "Max queues per engine (any non-zero

value less than or equal to 16, default: 1)");

drivers/dma/ae4dma/ae4dma-dev.c static unsigned int max_hw_q = 1; · line 27

Quoted 2 lines
drivers/dma/ae4dma/ae4dma-dev.c +1 -0
+static inline struct ae4_dma_chan *to_ae4_chan(struct dma_chan

*dma_chan)

Review

Quoted 37 lines
drivers/dma/ae4dma/ae4dma-dev.c +16 -0
+{
+   return container_of(dma_chan, struct ae4_dma_chan, vc.chan);
+}
+
 /* Human-readable error strings */
 static char *ae4_error_codes[] = {
    "",
@@ -273,8 +278,17 @@ int ae4_core_init(struct ae4_device *ae4)
            tasklet_setup(&cmd_q->irq_tasklet, ae4_do_cmd_complete);
    }
 
+   /* register to the DMA engine */
+   ret = ae4_dmaengine_register(ae4);
+   if (ret)
+           goto e_free_irq;
+
    return 0;
 
+e_free_irq:
+   for (i = 0; i < ae4->cmd_q_count; i++)
+           free_irq(ae4->ae4_irq[i], ae4);
+
 e_free_dma:
    dma_free_coherent(dev, cmd_q->qsize, cmd_q->qbase, cmd_q-
 qbase_dma);
@@ -292,6 +306,9 @@ void ae4_core_destroy(struct ae4_device *ae4)
    struct ae4_cmd *cmd;
    unsigned int i;
 
+   /* Unregister the DMA engine */
+   ae4_dmaengine_unregister(ae4);
+
    for (i = 0; i < ae4->cmd_q_count; i++) {
            cmd_q = &ae4->cmd_q[i];
 
(quoted diff) +0 -0

b/drivers/dma/ae4dma/ae4dma-dmaengine.c

drivers/dma/ae4dma/ae4dma-dmaengine.c line 4

Quoted 9 lines

new file mode 100644
index 0000000..a50e4f5

drivers/dma/ae4dma/ae4dma-dmaengine.c new file +4 -0
@@ -0,0 +1,425 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * AMD AE4DMA device driver
+ * -- Based on the PTDMA driver

How different is it from PTDMA, why cant this be incorporated in ptdma driver

drivers/dma/ae4dma/ae4dma-dmaengine.c

Quoted 11 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +11 -0
+ *
+ * Copyright (C) 2023 Advanced Micro Devices, Inc.
+ *
+ * Author: Sanjay R Mehta <[email protected]>
+ */
+#include <linux/delay.h>
+#include "ae4dma.h"
+#include "../dmaengine.h"
+#include "../virt-dma.h"
+
+static inline struct ae4_dma_chan *to_ae4_chan(struct dma_chan

*dma_chan)

Quoted 22 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +22 -0
+{
+   return container_of(dma_chan, struct ae4_dma_chan, vc.chan);
+}
+
+static inline struct ae4_dma_desc *to_ae4_desc(struct virt_dma_desc *vd)
+{
+   return container_of(vd, struct ae4_dma_desc, vd);
+}
+
+static void ae4_free_chan_resources(struct dma_chan *dma_chan)
+{
+   struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+
+   vchan_free_chan_resources(&chan->vc);
+}
+
+static void ae4_synchronize(struct dma_chan *dma_chan)
+{
+   struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+
+   vchan_synchronize(&chan->vc);
+}

drivers/dma/ae4dma/ae4dma-dmaengine.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+
+static void ae4_do_cleanup(struct virt_dma_desc *vd)
+{
+   struct ae4_dma_desc *desc = to_ae4_desc(vd);
+   struct ae4_device *ae4 = desc->ae4;
+
+   kmem_cache_free(ae4->dma_desc_cache, desc);
+}
+
+static int ae4_dma_start_desc(struct ae4_dma_desc *desc, struct

ae4_dma_chan *chan)

Quoted 14 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +14 -0
+{
+   struct ae4_passthru_engine *ae4_engine;
+   struct ae4_device *ae4;
+   struct ae4_cmd *ae4_cmd;
+   struct ae4_cmd_queue *cmd_q;
+
+   desc->issued_to_hw = 1;
+   list_del(&desc->vd.node);
+
+   ae4_cmd = &desc->ae4_cmd;
+   ae4 = ae4_cmd->ae4;
+   cmd_q = chan->cmd_q;
+   ae4_engine = &ae4_cmd->passthru;
+

drivers/dma/ae4dma/ae4dma-dmaengine.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+   ae4_cmd->qid = cmd_q->qidx;
+   cmd_q->tdata.cmd = ae4_cmd;
+
+   /* Execute the command */
+   ae4_cmd->ret = ae4_core_perform_passthru(cmd_q, ae4_engine);
+
+   return 0;
+}
+
+static struct ae4_dma_desc *ae4_next_dma_desc(struct ae4_dma_chan

*chan)

Quoted 27 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +27 -0
+{
+   /* Get the next DMA descriptor on the active list */
+   struct virt_dma_desc *vd = vchan_next_desc(&chan->vc);
+
+   return vd ? to_ae4_desc(vd) : NULL;
+}
+
+static void ae4_cmd_callback_tasklet(void *data, int err)
+{
+   struct ae4_dma_desc *desc = data;
+   struct dma_chan *dma_chan;
+   struct ae4_dma_chan *chan;
+   struct dma_async_tx_descriptor *tx_desc;
+   struct virt_dma_desc *vd;
+   unsigned long flags;
+
+   dma_chan = desc->vd.tx.chan;
+   chan = to_ae4_chan(dma_chan);
+
+   if (err == -EINPROGRESS)
+           return;
+
+   tx_desc = &desc->vd.tx;
+   vd = &desc->vd;
+
+   if (err)
+           desc->status = DMA_ERROR;
Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dmaengine.c line 104

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +6 -0
+
+   spin_lock_irqsave(&chan->vc.lock, flags);
+   if (desc) {
+           if (desc->status != DMA_COMPLETE) {
+                   if (desc->status != DMA_ERROR)
+                           desc->status = DMA_COMPLETE;

So a DMA_IN_PROGRESS descriptor would be marked complete?

Upon successful completion of the DMA, the interrupt handler will schedule the execution of this tasklet function, therefore indicating the status as complete.

Quoted 145 lines
Quoted 7 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +7 -0
+
+                   dma_cookie_complete(tx_desc);
+                   dma_descriptor_unmap(tx_desc);
+           } else {
+                   /* Don't handle it twice */
+                   tx_desc = NULL;
+           }

drivers/dma/ae4dma/ae4dma-dmaengine.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+   }
+   spin_unlock_irqrestore(&chan->vc.lock, flags);
+
+   if (tx_desc) {
+           dmaengine_desc_get_callback_invoke(tx_desc, NULL);
+           dma_run_dependencies(tx_desc);
+   }
+}
+
+static struct ae4_dma_desc *ae4_handle_active_desc(struct

ae4_dma_chan *chan,

Quoted 58 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +58 -0
+                                              struct ae4_dma_desc *desc)
+{
+   struct dma_async_tx_descriptor *tx_desc;
+   struct virt_dma_desc *vd;
+   unsigned long flags;
+
+   /* Loop over descriptors until one is found with commands */
+   do {
+           if (desc) {
+                   if (!desc->issued_to_hw) {
+                           /* No errors, keep going */
+                           if (desc->status != DMA_ERROR)
+                                   return desc;
+                   }
+                   tx_desc = &desc->vd.tx;
+                   vd = &desc->vd;
+           } else {
+                   tx_desc = NULL;
+           }
+           spin_lock_irqsave(&chan->vc.lock, flags);
+           desc = ae4_next_dma_desc(chan);
+           spin_unlock_irqrestore(&chan->vc.lock, flags);
+   } while (desc);
+
+   return NULL;
+}
+
+static void ae4_cmd_callback(void *data, int err)
+{
+   struct ae4_dma_desc *desc = data;
+   struct dma_chan *dma_chan;
+   struct ae4_dma_chan *chan;
+   struct ae4_device *ae4;
+   int ret;
+
+   if (err == -EINPROGRESS)
+           return;
+
+   dma_chan = desc->vd.tx.chan;
+   chan = to_ae4_chan(dma_chan);
+   ae4 = chan->ae4;
+
+   if (err)
+           desc->status = DMA_ERROR;
+
+   while (true) {
+           /* Check for DMA descriptor completion */
+           desc = ae4_handle_active_desc(chan, desc);
+
+           /* Don't submit cmd if no descriptor or DMA is paused */
+           if (!desc)
+                   break;
+
+           /* if queue is full dont submit to queue */
+           if (ae4_core_queue_full(ae4, chan->cmd_q)) {
+                   usleep_range(100, 200);
+                   continue;
+           }

drivers/dma/ae4dma/ae4dma-dmaengine.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+
+           ret = ae4_dma_start_desc(desc, chan);
+           if (!ret)
+                   break;
+
+           desc->status = DMA_ERROR;
+   }
+}
+
+static struct ae4_dma_desc *ae4_alloc_dma_desc(struct ae4_dma_chan

*chan, unsigned long flags)

drivers/dma/ae4dma/ae4dma-dmaengine.c

Quoted 5 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +5 -0
+{
+   struct ae4_dma_desc *desc;
+   struct ae4_cmd_queue *cmd_q = chan->cmd_q;
+
+   desc = kmem_cache_zalloc(chan->ae4->dma_desc_cache,

GFP_NOWAIT);

Quoted 4 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +4 -0
+   if (!desc)
+           return NULL;
+
+   vchan_tx_prep(&chan->vc, &desc->vd, flags);

drivers/dma/ae4dma/ae4dma-dmaengine.c

Quoted 10 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +10 -0
+
+   desc->ae4 = chan->ae4;
+   cmd_q->int_en = !!(flags & DMA_PREP_INTERRUPT);
+   desc->issued_to_hw = 0;
+   desc->status = DMA_IN_PROGRESS;
+
+   return desc;
+}
+
+static struct ae4_dma_desc *ae4_create_desc(struct dma_chan

*dma_chan,

Quoted 37 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +37 -0
+                                       dma_addr_t dst,
+                                       dma_addr_t src,
+                                       unsigned int len,
+                                       unsigned long flags)
+{
+   struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+   struct ae4_cmd_queue *cmd_q = chan->cmd_q;
+   struct ae4_passthru_engine *ae4_engine;
+   struct ae4_dma_desc *desc;
+   struct ae4_cmd *ae4_cmd;
+
+   desc = ae4_alloc_dma_desc(chan, flags);
+   if (!desc)
+           return NULL;
+
+   ae4_cmd = &desc->ae4_cmd;
+   ae4_cmd->ae4 = chan->ae4;
+   ae4_engine = &ae4_cmd->passthru;
+   ae4_cmd->engine = AE4_ENGINE_PASSTHRU;
+   ae4_engine->src_dma = src;
+   ae4_engine->dst_dma = dst;
+   ae4_engine->src_len = len;
+   ae4_cmd->ae4_cmd_callback = ae4_cmd_callback_tasklet;
+   ae4_cmd->data = desc;
+
+   desc->len = len;
+
+   spin_lock_irqsave(&cmd_q->cmd_lock, flags);
+   list_add_tail(&ae4_cmd->entry, &cmd_q->cmd);
+   spin_unlock_irqrestore(&cmd_q->cmd_lock, flags);
+
+   return desc;
+}
+
+static struct dma_async_tx_descriptor *
+ae4_prep_dma_memcpy(struct dma_chan *dma_chan, dma_addr_t dst,
+               dma_addr_t src, size_t len, unsigned long flags)
Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dmaengine.c line 251

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +6 -0
+{
+   struct ae4_dma_desc *desc;
+
+   desc = ae4_create_desc(dma_chan, dst, src, len, flags);
+   if (!desc)
+           return NULL;

I dont see any logic in splitting these into two!

Right, I will remove in V2.

Quoted 34 lines

drivers/dma/ae4dma/ae4dma-dmaengine.c

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +6 -0
+
+   return &desc->vd.tx;
+}
+
+static struct dma_async_tx_descriptor *
+ae4_prep_dma_interrupt(struct dma_chan *dma_chan, unsigned long

flags)

Quoted 27 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +27 -0
+{
+   struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+   struct ae4_dma_desc *desc;
+
+   desc = ae4_alloc_dma_desc(chan, flags);
+   if (!desc)
+           return NULL;
+
+   return &desc->vd.tx;
+}
+
+static void ae4_issue_pending(struct dma_chan *dma_chan)
+{
+   struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+   struct ae4_dma_desc *desc;
+   unsigned long flags;
+
+   spin_lock_irqsave(&chan->vc.lock, flags);
+   vchan_issue_pending(&chan->vc);
+   desc = ae4_next_dma_desc(chan);
+   spin_unlock_irqrestore(&chan->vc.lock, flags);
+
+   ae4_cmd_callback(desc, 0);
+}
+
+static int ae4_pause(struct dma_chan *dma_chan)
+{
Quoted 9 lines

drivers/dma/ae4dma/ae4dma-dmaengine.c line 289

Quoted 5 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +5 -0
+   struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+   unsigned long flags;
+
+   spin_lock_irqsave(&chan->vc.lock, flags);
+   //TODO : implemnt pause

typo implemnt and drop this and add when you add support! No dummy code please

Sure, I will fix this in V2.

Quoted 14 lines
Quoted 14 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +13 -0
+   spin_unlock_irqrestore(&chan->vc.lock, flags);
+
+   return 0;
+}
+
+static int ae4_resume(struct dma_chan *dma_chan)
+{
+   struct ae4_dma_chan *chan = to_ae4_chan(dma_chan);
+   struct ae4_dma_desc *desc = NULL;
+   unsigned long flags;
+
+   spin_lock_irqsave(&chan->vc.lock, flags);
+   ae4_start_queue(chan->cmd_q);
Quoted 8 lines

drivers/dma/ae4dma/ae4dma-dmaengine.c line 308

Quoted 6 lines
drivers/dma/ae4dma/ae4dma-dmaengine.c new file +6 -0
+   desc = ae4_next_dma_desc(chan);
+   spin_unlock_irqrestore(&chan->vc.lock, flags);
+
+   /* If there was something active, re-start */
+   if (desc)
+           ae4_cmd_callback(desc, 0);

resume when no pause is supported..??

Sure.

Quoted 2 lines

--
~Vinod

#9 lore raw

PATCH 3/3 dmaengine: ae4dma: Add debugfs entries for AE4DMA

In reply to Sanjay R Mehta

From: Sanjay R Mehta <[email protected]>

Expose data about the configuration and operation of the AE4DMA through debugfs entries: device name, capabilities, configuration, statistics.

---
 drivers/dma/ae4dma/Makefile         |  2 +-
 drivers/dma/ae4dma/ae4dma-debugfs.c | 98 +++++++++++++++++++++++++++++++++++++
 drivers/dma/ae4dma/ae4dma-dev.c     | 16 ++++++
 drivers/dma/ae4dma/ae4dma.h         |  8 +++
 4 files changed, 123 insertions(+), 1 deletion(-)
 create mode 100644 drivers/dma/ae4dma/ae4dma-debugfs.c
drivers/dma/ae4dma/Makefile +1 -1
index b1e4318..4082fec 100644
@@ -5,6 +5,6 @@
 
 obj-$(CONFIG_AMD_AE4DMA) += ae4dma.o
 
-ae4dma-objs := ae4dma-dev.o ae4dma-dmaengine.o
+ae4dma-objs := ae4dma-dev.o ae4dma-dmaengine.o ae4dma-debugfs.o
 
 ae4dma-$(CONFIG_PCI) += ae4dma-pci.o
drivers/dma/ae4dma/ae4dma-debugfs.c new file +98 -0

98 lines not on this page · raw message

drivers/dma/ae4dma/ae4dma-dev.c +16 -0
index af7e510..fe5af0c0 100644
@@ -74,6 +74,7 @@ static int ae4_core_execute_cmd(struct ae4dma_desc *desc, struct ae4_cmd_queue *
 {
 	bool soc = FIELD_GET(DWORD0_SOC, desc->dw0);
 	u8 *q_desc = (u8 *)&cmd_q->qbase[0];
+	unsigned long flags;
 	u32 tail_wi;
 
 	cmd_q->int_rcvd = 0;
@@ -99,6 +100,10 @@ static int ae4_core_execute_cmd(struct ae4dma_desc *desc, struct ae4_cmd_queue *
 	tail_wi = (tail_wi + 1) % CMD_Q_LEN;
 	iowrite32(tail_wi, cmd_q->reg_control + 0x10);
 
+	spin_lock_irqsave(&cmd_q->cmd_lock, flags);
+	cmd_q->q_cmd_count++;
+	spin_unlock_irqrestore(&cmd_q->cmd_lock, flags);
+
 	mutex_unlock(&cmd_q->q_mutex);
 
 	return 0;
@@ -110,6 +115,7 @@ int ae4_core_perform_passthru(struct ae4_cmd_queue *cmd_q, struct ae4_passthru_e
 	struct ae4_device *ae4 = cmd_q->ae4;
 
 	cmd_q->cmd_error = 0;
+	cmd_q->total_ae4_ops++;
 	memset(&desc, 0, sizeof(desc));
 	desc.dw0 = CMD_DESC_DW0_VAL;
 	desc.dw1.status = 0;
@@ -173,9 +179,12 @@ static irqreturn_t ae4_core_irq_handler(int irq, void *data)
 {
 	struct ae4_cmd_queue *cmd_q = data;
 	struct ae4_device *ae4 = cmd_q->ae4;
+	unsigned long flags;
 	u32 status = ioread32(cmd_q->reg_control + 0x4);
 	u8 q_intr_type = (status >> 24) & 0xf;
 
+	ae4->total_interrupts++;
+
 	if (q_intr_type ==  0x4)
 		dev_info(ae4->dev, "AE4DMA INTR: %s (0x%x)\n", "queue desc error", q_intr_type);
 	else if (q_intr_type ==  0x2)
@@ -187,6 +196,10 @@ static irqreturn_t ae4_core_irq_handler(int irq, void *data)
 
 	ae4_check_status_trans(ae4, cmd_q);
 
+	spin_lock_irqsave(&cmd_q->cmd_lock, flags);
+	cmd_q->q_cmd_count--;
+	spin_unlock_irqrestore(&cmd_q->cmd_lock, flags);
+
 	tasklet_schedule(&cmd_q->irq_tasklet);
 
 	return IRQ_HANDLED;
@@ -283,6 +296,9 @@ int ae4_core_init(struct ae4_device *ae4)
 	if (ret)
 		goto e_free_irq;
 
+	/* Set up debugfs entries */
+	ae4dma_debugfs_setup(ae4);
+
 	return 0;
 
 e_free_irq:
drivers/dma/ae4dma/ae4dma.h +8 -0
index d341c35..ae31b26 100644
@@ -231,6 +231,10 @@ struct ae4_cmd_queue {
 	wait_queue_head_t q_space;
 	unsigned int q_space_available;
 
+	/* Queue Statistics */
+	unsigned long total_ae4_ops;
+	unsigned long q_cmd_count;
+
 	struct ae4_tasklet_data tdata;
 	struct tasklet_struct irq_tasklet;
 
@@ -274,6 +278,9 @@ struct ae4_device {
 	struct kmem_cache *dma_desc_cache;
 
 	wait_queue_head_t lsb_queue;
+
+	/* Device Statistics */
+	unsigned long total_interrupts;
 };
 
 /*
@@ -326,6 +333,7 @@ struct ae4_dev_vdata {
 int ae4_dmaengine_register(struct ae4_device *ae4);
 void ae4_dmaengine_unregister(struct ae4_device *ae4);
 
+void ae4dma_debugfs_setup(struct ae4_device *ae4);
 int ae4_core_init(struct ae4_device *ae4);
 void ae4_core_destroy(struct ae4_device *ae4);
 
Signature · 1 line
2.7.4