Thread View: linux.kernel.netdev
2 messages
2 total messages
Started by han.junyang
Fri, 13 Nov 2026 05:53
[PATCH net-next v6 3/3] dinghai: add async event queue for firmware notifications
Author: han.junyang
Date: Fri, 13 Nov 2026 05:53
Date: Fri, 13 Nov 2026 05:53
316 lines
19502 bytes
19502 bytes
From: Junyang Han <han.junyang@zte.com.cn>
Add the event queue table and the first async event queue, fed by the
RISC-V management core of the firmware. The queue owns one MSI-X
vector taken from the async pool and, on interrupt, reads the event_id
from the PF receive sub-channel of the BAR message area, maps it to
an event type and fans it out through the per-event-type notifier
chains of the table. The PF probe creates and tears down the queue
through the existing IRQ pool interfaces.
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. Subscribers for the RISCV_READY event register on the
notifier chains in later series as well.
Signed-off-by: Junyang Han <han.junyang@zte.com.cn>
---
drivers/net/ethernet/zte/dinghai/Makefile | 2 +-
drivers/net/ethernet/zte/dinghai/en_pf.c | 16 ++-
drivers/net/ethernet/zte/dinghai/en_pf.h | 2 +
drivers/net/ethernet/zte/dinghai/zxdh_eq.c | 137 +++++++++++++++++++++
drivers/net/ethernet/zte/dinghai/zxdh_eq.h | 60 +++++++++
5 files changed, 211 insertions(+), 6 deletions(-)
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/Makefile b/drivers/net/ethernet/zte/dinghai/Makefile
index f4a8f9480291..2dc6d68cc0e1 100644
--- a/drivers/net/ethernet/zte/dinghai/Makefile
+++ b/drivers/net/ethernet/zte/dinghai/Makefile
@@ -4,4 +4,4 @@
#
obj-$(CONFIG_DINGHAI_PF) += dinghai10e.o
-dinghai10e-y := en_pf.o zxdh_irq.o
+dinghai10e-y := en_pf.o zxdh_irq.o zxdh_eq.o
diff --git a/drivers/net/ethernet/zte/dinghai/en_pf.c b/drivers/net/ethernet/zte/dinghai/en_pf.c
index 5927f1f39b02..f7400d66bc69 100644
--- a/drivers/net/ethernet/zte/dinghai/en_pf.c
+++ b/drivers/net/ethernet/zte/dinghai/en_pf.c
@@ -552,13 +552,10 @@ void zxdh_pf_irq_table_destroy(struct zxdh_core_dev *zxdh_dev)
pci_free_irq_vectors(zxdh_dev->pdev);
}
+/* Fetch a vector from the async pool for one async event queue. */
struct zxdh_irq *zxdh_pf_async_irq_request(struct zxdh_core_dev *zxdh_dev)
{
- struct zxdh_irq_table *table = &zxdh_dev->irq_table;
- struct zxdh_pf_irq_table *pf_irq_table = table->priv;
-
- if (!pf_irq_table->async_pool)
- return NULL;
+ struct zxdh_pf_irq_table *pf_irq_table = zxdh_dev->irq_table.priv;
return zxdh_get_irq_of_pool(pf_irq_table->async_pool);
}
@@ -617,10 +614,18 @@ static int zxdh_pf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
goto err_irq_table;
}
+ ret = zxdh_pf_eq_table_init(zxdh_dev);
+ if (ret) {
+ dev_err(&pdev->dev, "zxdh_pf_eq_table_init failed: %d\n", ret);
+ goto err_eq_table;
+ }
+
devlink_register(devlink);
return 0;
+err_eq_table:
+ zxdh_pf_eq_table_destroy(zxdh_dev);
err_irq_table:
zxdh_pf_irq_table_destroy(zxdh_dev);
err_modern_cfg:
@@ -640,6 +645,7 @@ static void zxdh_pf_remove(struct pci_dev *pdev)
struct devlink *devlink = priv_to_devlink(zxdh_dev);
devlink_unregister(devlink);
+ zxdh_pf_eq_table_destroy(zxdh_dev);
zxdh_pf_irq_table_destroy(zxdh_dev);
zxdh_pf_modern_cfg_uninit(zxdh_dev);
zxdh_pf_pci_close(zxdh_dev);
diff --git a/drivers/net/ethernet/zte/dinghai/en_pf.h b/drivers/net/ethernet/zte/dinghai/en_pf.h
index 3de96488a810..b48c786ef48a 100644
--- a/drivers/net/ethernet/zte/dinghai/en_pf.h
+++ b/drivers/net/ethernet/zte/dinghai/en_pf.h
@@ -9,6 +9,7 @@
#include <linux/types.h>
+#include "zxdh_eq.h"
#include "zxdh_irq.h"
#define ZXDH_PF_VENDOR_ID 0x1cf2
@@ -81,6 +82,7 @@ struct zxdh_core_dev {
struct pci_dev *pdev;
struct devlink *devlink;
struct zxdh_irq_table irq_table;
+ struct zxdh_eq_table eq_table;
void *priv;
};
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..3e70f4f3063f
--- /dev/null
+++ b/drivers/net/ethernet/zte/dinghai/zxdh_eq.c
@@ -0,0 +1,137 @@
+// 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/mutex.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;
+};
+
+/* Fetch the event_id the RISC-V core posted in the PF receive
+ * sub-channel of the BAR message area. The field lives at byte offset
+ * 2 of the 12-byte message header, so a single 32-bit read of the
+ * sub-channel start covers it.
+ */
+static u16 zxdh_eq_event_id_get(struct zxdh_core_dev *zxdh_dev)
+{
+ struct zxdh_pf_dev *pf_dev = zxdh_dev->priv;
+ void __iomem *subchan;
+
+ subchan = pf_dev->pci_ioremap_addr[0] + ZXDH_BAR_MSG_SUBCHAN_RECV;
+
+ return ioread32(subchan) >> 16;
+}
+
+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;
+
+ event_type = zxdh_eq_event_type_get(zxdh_eq_event_id_get(zxdh_dev));
+ if (event_type == ZXDH_EQ_EVENT_TYPE_MAX)
+ return NOTIFY_DONE;
+
+ atomic_notifier_call_chain(&zxdh_dev->eq_table.nh[event_type],
+ event_type, NULL);
+
+ 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;
+
+ mutex_init(&table->lock);
+ 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;
+
+ mutex_lock(&table->lock);
+ if (eq->irq) {
+ zxdh_irq_detach_nb(eq->irq, &eq->irq_nb);
+ zxdh_irqs_release_vectors(&eq->irq, 1);
+ eq->irq = NULL;
+ }
+ mutex_unlock(&table->lock);
+
+ mutex_destroy(&table->lock);
+ 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..ac9df4763059
--- /dev/null
+++ b/drivers/net/ethernet/zte/dinghai/zxdh_eq.h
@@ -0,0 +1,60 @@
+/* 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/mutex.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)
+
+/* event_id of the "RISC-V core ready" firmware notification, carried
+ * at byte offset 2 of the BAR message header.
+ */
+#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];
+ /* Serializes async EQ setup/teardown. */
+ struct mutex lock;
+ 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
Re: [PATCH net-next v6 3/3] dinghai: add async event queue for firmware notifications
Author: Jakub Kicinski
Date: Sat, 21 Nov 2026 23:31
Date: Sat, 21 Nov 2026 23:31
206 lines
15036 bytes
15036 bytes
This is an AI-generated review of your patch. The human sending this
email has considered the AI review valid, or at least plausible.
---
--- Patch [3]: [PATCH net-next v6 3/3] dinghai: add async event queue for firmware
notifications ---
commit 0beec1cea24be93e6e75a8732e384d617376a13d
Author: Junyang Han <han.junyang@zte.com.cn>
dinghai: add async event queue for firmware notifications
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. Its interrupt handler reads an
event_id from the PF receive sub-channel of the BAR message area and
dispatches it through per-event-type notifier chains, and the PF
probe/remove paths create and tear down the queue.
> diff --git a/drivers/net/ethernet/zte/dinghai/en_pf.c b/drivers/net/ethernet/zte/dinghai/en_pf.c
> index 5927f1f39b02a..f7400d66bc690 100644
> --- a/drivers/net/ethernet/zte/dinghai/en_pf.c
> +++ b/drivers/net/ethernet/zte/dinghai/en_pf.c
[ ... ]
> @@ -617,10 +614,18 @@ static int zxdh_pf_probe(struct pci_dev *pdev, const struct pci_device_id *id)
> goto err_irq_table;
> }
>
> + ret = zxdh_pf_eq_table_init(zxdh_dev);
> + if (ret) {
> + dev_err(&pdev->dev, "zxdh_pf_eq_table_init failed: %d\n", ret);
> + goto err_eq_table;
> + }
[Severity: Low]
Does this queue have any users in this series? Every probe now takes an
async-pool vector and installs a hard IRQ handler:
zxdh_pf_eq_table_init()
zxdh_pf_async_irq_request()
zxdh_get_irq_of_pool()
zxdh_irq_affinity_request()
zxdh_irq_pool_request_irq()
zxdh_irq_alloc()
request_irq()
When the interrupt fires, zxdh_eq_async_riscv_int() dispatches to
zxdh_dev->eq_table.nh[], but nothing registers on those chains. Under
drivers/net/ethernet/zte/, the only reference to eq_table.nh[] is the
atomic_notifier_call_chain() call in zxdh_eq_async_riscv_int().
zxdh_eq.h also exports only zxdh_pf_eq_table_init() and
zxdh_pf_eq_table_destroy(), with no register/unregister helper. Later
subscribers would have to reach into struct zxdh_eq_table directly.
The commit message says:
"the PF side wired here is live as soon as that channel is enabled.
Subscribers for the RISCV_READY event register on the notifier chains
in later series as well."
Even with the channel enabled, every RISCV_READY dispatch would go to an
empty chain. Could this be merged together with the BAR message channel
and the first subscriber? Then the design could be reviewed against its
consumers, including the event payload, valid/ack handling and ownership
of the mailbox offsets.
[ ... ]
> 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 0000000000000..3e70f4f3063fe
> --- /dev/null
> +++ b/drivers/net/ethernet/zte/dinghai/zxdh_eq.c
[ ... ]
> +/* Fetch the event_id the RISC-V core posted in the PF receive
> + * sub-channel of the BAR message area. The field lives at byte offset
> + * 2 of the 12-byte message header, so a single 32-bit read of the
> + * sub-channel start covers it.
> + */
> +static u16 zxdh_eq_event_id_get(struct zxdh_core_dev *zxdh_dev)
> +{
> + struct zxdh_pf_dev *pf_dev = zxdh_dev->priv;
> + void __iomem *subchan;
> +
> + subchan = pf_dev->pci_ioremap_addr[0] + ZXDH_BAR_MSG_SUBCHAN_RECV;
> +
> + return ioread32(subchan) >> 16;
[Severity: Medium]
Should the handler check that a new message was actually posted before
it uses this event_id?
The >> 16 discards bytes 0-1 of the header. In the 12-byte BAR message
header, byte 0 holds the per-message flag bits (valid, sync, emec, ack,
poll, usr).
The BAR mailbox protocol isn't in the tree yet, so this is based on the
DPDK zxdh PMD. Its header layout matches the comment here (event_id at
offset 2, RISC_READY = 13). Its receive path rejects any header without
the valid bit in zxdh_bar_chan_msg_header_check().
zxdh_irq_int_handler() calls the chain on every interrupt:
atomic_notifier_call_chain(&zxdh_irq->nh, 0, NULL);
return IRQ_HANDLED;
so nothing earlier filters these events. If the mailbox still says 13,
ZXDH_EQ_EVENT_TYPE_RISCV_READY would be dispatched again on any
interrupt on this vector. That includes a stale header from an earlier
notification, an uninitialized mailbox, or a spurious MSI-X. It also
covers interrupts meant for other users if zxdh_irq_affinity_request()
shares the vector when the pool runs out.
Can subscribers then receive a RISCV_READY event that the firmware
didn't post for this interrupt?
> +}
[ ... ]
> +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;
> +
> + event_type = zxdh_eq_event_type_get(zxdh_eq_event_id_get(zxdh_dev));
> + if (event_type == ZXDH_EQ_EVENT_TYPE_MAX)
> + return NOTIFY_DONE;
> +
> + atomic_notifier_call_chain(&zxdh_dev->eq_table.nh[event_type],
> + event_type, NULL);
> +
> + return NOTIFY_OK;
[Severity: Medium]
What gives the receive sub-channel back to the firmware once the
message is handled? This handler is its only consumer, and it returns
without writing anything to the mailbox.
In the DPDK zxdh receive path, zxdh_bar_irq_recv() resets the header's
valid field to usable. For sync messages it also writes a reply header
with the ack bit set.
Without this, could the RISC-V core keep seeing an unconsumed message
and fail to post the next notification? Could a sync-flagged sender
wait for an ack until it times out? The old header would also stay in
the mailbox, so the stale re-dispatch described above could repeat on
every later interrupt.
> +}
[ ... ]
> +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;
> +
> + mutex_lock(&table->lock);
> + if (eq->irq) {
> + zxdh_irq_detach_nb(eq->irq, &eq->irq_nb);
> + zxdh_irqs_release_vectors(&eq->irq, 1);
> + eq->irq = NULL;
> + }
> + mutex_unlock(&table->lock);
[Severity: Low]
This isn't a bug, but what does table->lock protect? zxdh_eq.h
documents it as:
/* Serializes async EQ setup/teardown. */
struct mutex lock;
zxdh_pf_eq_table_init() only calls mutex_init(). It then sets eq->irq
and calls zxdh_irq_attach_nb() without taking the lock. This
mutex_lock() in zxdh_pf_eq_table_destroy() is the only place it is
acquired.
The driver core already serializes probe and remove, and the hard IRQ
path can't take a mutex. Holding the lock here also keeps it held across
synchronize_rcu() in atomic_notifier_chain_unregister(),
synchronize_irq(), pool->lock and free_irq().
Could the lock be removed, or the comment changed to match what it
actually guarantees?
> +
> + mutex_destroy(&table->lock);
> + kvfree(table->priv);
> + table->priv = NULL;
> +}
[ ... ]
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads