From: Junyang Han <han…@zte.com.cn>
This adds an event queue table and one async event queue that receives
firmware notifications from the RISC-V management core. The queue takes
one MSI-X vector from the async pool, and the PF probe/remove paths
create and tear it down.
The interrupt handler reads the message header from the PF receive
sub-channel of the BAR message area and dispatches the event_id over the
per-event-type notifier chains. A header without the valid bit set does
not carry a new message and is ignored; after a message has been
dispatched the valid bit is cleared so that the firmware can post the
next one.
The BAR message channel handshake that tells the firmware which vectors
to signal comes with the BAR message subsystem in a later series.
Signed-off-by: Junyang Han <han…@zte.com.cn>
---
drivers/net/ethernet/zte/dinghai/zxdh_eq.c | 142 +++++++++++++++++++++
drivers/net/ethernet/zte/dinghai/zxdh_eq.h | 62 +++++++++
2 files changed, 204 insertions(+)
create mode 100644 drivers/net/ethernet/zte/dinghai/zxdh_eq.c
create mode 100644 drivers/net/ethernet/zte/dinghai/zxdh_eq.h
diff --git a/drivers/net/ethernet/zte/dinghai/zxdh_eq.c b/drivers/net/ethernet/zte/dinghai/zxdh_eq.c
new file mode 100644
index 000000000000..ff18b70b4aef
--- /dev/null
+++ b/drivers/net/ethernet/zte/dinghai/zxdh_eq.c
@@ -0,0 +1,142 @@
+// SPDX-License-Identifier: GPL-2.0-only
+/*
+ * ZTE DingHai Ethernet driver - event queue plumbing
+ * Copyright (c) 2022-2026, ZTE Corporation.
+ *
+ * Async event queues are the delivery path for firmware notifications:
+ * a queue owns one MSI-X vector of the async pool and fans interrupts
+ * out to the per-event-type notifier chains of the event queue table.
+ * The BAR message channel handshake that tells the firmware which
+ * vectors to signal comes with the BAR message subsystem in a later
+ * series; the PF side wired here is live as soon as that channel is
+ * enabled.
+ */
+
+#include <linux/io.h>
+#include <linux/kernel.h>
+#include <linux/notifier.h>
+#include <linux/slab.h>
+
+#include "en_pf.h"
+#include "zxdh_eq.h"
+#include "zxdh_irq.h"
+
+/* PF side of the event queue table: one async EQ fed by the RISC-V
+ * management core.
+ */
+struct zxdh_pf_eq_table {
+ struct zxdh_eq_async riscv_eq;
+};
+
+static u32 zxdh_eq_hdr_get(struct zxdh_core_dev *zxdh_dev)
+{
+ struct zxdh_pf_dev *pf_dev = zxdh_dev->priv;
+
+ return ioread32(pf_dev->pci_ioremap_addr[0] + ZXDH_BAR_MSG_SUBCHAN_RECV);
+}
+
+/* Clear the valid bit so that the firmware can post the next message. */
+static void zxdh_eq_hdr_release(struct zxdh_core_dev *zxdh_dev)
+{
+ struct zxdh_pf_dev *pf_dev = zxdh_dev->priv;
+ void __iomem *subchan;
+ u32 hdr;
+
+ subchan = pf_dev->pci_ioremap_addr[0] + ZXDH_BAR_MSG_SUBCHAN_RECV;
+ hdr = ioread32(subchan);
+ hdr &= ~ZXDH_BAR_MSG_VALID;
+ iowrite32(hdr, subchan);
+}
+
+static enum zxdh_eq_event_type zxdh_eq_event_type_get(u16 event_id)
+{
+ if (event_id == ZXDH_MSG_MODULE_RISC_READY)
+ return ZXDH_EQ_EVENT_TYPE_RISCV_READY;
+
+ /* Only the RISC-V ready notification is dispatched in this
+ * series; the remaining firmware events arrive with the BAR
+ * message subsystem.
+ */
+ return ZXDH_EQ_EVENT_TYPE_MAX;
+}
+
+static int zxdh_eq_async_riscv_int(struct notifier_block *nb,
+ unsigned long action, void *data)
+{
+ struct zxdh_eq_async *eq = container_of(nb, struct zxdh_eq_async, irq_nb);
+ struct zxdh_core_dev *zxdh_dev = eq->priv;
+ enum zxdh_eq_event_type event_type;
+ u32 hdr;
+
+ hdr = zxdh_eq_hdr_get(zxdh_dev);
+ if (!(hdr & ZXDH_BAR_MSG_VALID))
+ return NOTIFY_DONE;
+
+ event_type = zxdh_eq_event_type_get(ZXDH_BAR_MSG_EVENT_ID(hdr));
+ if (event_type != ZXDH_EQ_EVENT_TYPE_MAX)
+ atomic_notifier_call_chain(&zxdh_dev->eq_table.nh[event_type],
+ event_type, NULL);
+
+ zxdh_eq_hdr_release(zxdh_dev);
+
+ return NOTIFY_OK;
+}
+
+int zxdh_pf_eq_table_init(struct zxdh_core_dev *zxdh_dev)
+{
+ struct zxdh_eq_table *table = &zxdh_dev->eq_table;
+ struct zxdh_pf_eq_table *priv;
+ struct zxdh_eq_async *eq;
+ int err;
+ int i;
+
+ priv = kvzalloc_obj(*priv, GFP_KERNEL);
+ if (!priv)
+ return -ENOMEM;
+ table->priv = priv;
+
+ for (i = 0; i < ZXDH_EQ_EVENT_TYPE_MAX; i++)
+ ATOMIC_INIT_NOTIFIER_HEAD(&table->nh[i]);
+
+ eq = &priv->riscv_eq;
+ eq->priv = zxdh_dev;
+ eq->irq = zxdh_pf_async_irq_request(zxdh_dev);
+ if (IS_ERR(eq->irq)) {
+ err = PTR_ERR(eq->irq);
+ goto err_irq;
+ }
+
+ eq->irq_nb.notifier_call = zxdh_eq_async_riscv_int;
+ err = zxdh_irq_attach_nb(eq->irq, &eq->irq_nb);
+ if (err)
+ goto err_attach;
+
+ return 0;
+
+err_attach:
+ zxdh_irqs_release_vectors(&eq->irq, 1);
+err_irq:
+ eq->irq = NULL;
+ return err;
+}
+
+void zxdh_pf_eq_table_destroy(struct zxdh_core_dev *zxdh_dev)
+{
+ struct zxdh_pf_eq_table *pf_eq_table = zxdh_dev->eq_table.priv;
+ struct zxdh_eq_table *table = &zxdh_dev->eq_table;
+ struct zxdh_eq_async *eq;
+
+ if (!pf_eq_table)
+ return;
+
+ eq = &pf_eq_table->riscv_eq;
+
+ if (eq->irq) {
+ zxdh_irq_detach_nb(eq->irq, &eq->irq_nb);
+ zxdh_irqs_release_vectors(&eq->irq, 1);
+ eq->irq = NULL;
+ }
+
+ kvfree(table->priv);
+ table->priv = NULL;
+}
diff --git a/drivers/net/ethernet/zte/dinghai/zxdh_eq.h b/drivers/net/ethernet/zte/dinghai/zxdh_eq.h
new file mode 100644
index 000000000000..c80c042877c3
--- /dev/null
+++ b/drivers/net/ethernet/zte/dinghai/zxdh_eq.h
@@ -0,0 +1,62 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+/*
+ * ZTE DingHai Ethernet driver - event queue abstraction
+ * Copyright (c) 2022-2026, ZTE Corporation.
+ */
+
+#ifndef __ZXDH_EQ_H__
+#define __ZXDH_EQ_H__
+
+#include <linux/bits.h>
+#include <linux/notifier.h>
+
+struct zxdh_core_dev;
+struct zxdh_irq;
+
+/* BAR message area: shared-memory mailbox between the driver and the
+ * firmware, split into sub-channels of 2048 bytes. Notifications from
+ * the RISC-V management core are posted to the PF receive sub-channel,
+ * one interval above the area base.
+ */
+#define ZXDH_BAR_MSG_OFFSET 0x2000
+#define ZXDH_BAR_MSG_SUBCHAN_INTERVAL 2048
+#define ZXDH_BAR_MSG_SUBCHAN_RECV (ZXDH_BAR_MSG_OFFSET + \
+ ZXDH_BAR_MSG_SUBCHAN_INTERVAL)
+
+/* BAR message header: byte 0 carries the channel flags, the event_id
+ * sits at byte offset 2.
+ */
+#define ZXDH_BAR_MSG_VALID BIT(0)
+#define ZXDH_BAR_MSG_EVENT_ID(hdr) ((hdr) >> 16)
+
+/* event_id of the "RISC-V core ready" firmware notification. */
+#define ZXDH_MSG_MODULE_RISC_READY 13
+
+/* Event types the upper layers can subscribe to over the per-type
+ * notifier chains of the event queue table. The full catalogue lives
+ * in the firmware; only the ones dispatched in this series are named.
+ */
+enum zxdh_eq_event_type {
+ ZXDH_EQ_EVENT_TYPE_RISCV_READY = 0,
+ ZXDH_EQ_EVENT_TYPE_MAX,
+};
+
+/* Asynchronous event queue delivering firmware notifications to the
+ * driver without a request/reply handshake.
+ */
+struct zxdh_eq_async {
+ struct zxdh_irq *irq;
+ struct notifier_block irq_nb;
+ void *priv;
+};
+
+struct zxdh_eq_table {
+ /* Notifier chains fanned out by event type. */
+ struct atomic_notifier_head nh[ZXDH_EQ_EVENT_TYPE_MAX];
+ void *priv;
+};
+
+int zxdh_pf_eq_table_init(struct zxdh_core_dev *zxdh_dev);
+void zxdh_pf_eq_table_destroy(struct zxdh_core_dev *zxdh_dev);
+
+#endif /* __ZXDH_EQ_H__ */
--
2.27.0