From: Manivannan Sadhasivam via B4 Relay <devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org>
To: Manivannan Sadhasivam <mani@kernel.org>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>,
Paolo Abeni <pabeni@redhat.com>, Simon Horman <horms@kernel.org>,
Jeff Johnson <jjohnson@kernel.org>
Cc: linux-arm-msm@vger.kernel.org, netdev@vger.kernel.org,
linux-kernel@vger.kernel.org, linux-wireless@vger.kernel.org,
ath11k@lists.infradead.org, ath12k@lists.infradead.org,
Bjorn Andersson <andersson@kernel.org>,
Chris Lew <christopher.lew@oss.qualcomm.com>,
Deepak Kumar Singh <deepak.singh@oss.qualcomm.com>,
Raj Kumar Bhagat <raj.bhagat@oss.qualcomm.com>,
Juha-Matti Tilli <juha-matti.tilli@iki.fi>,
Jeff Hugo <jeff.hugo@oss.qualcomm.com>,
Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Subject: [PATCH v4 1/4] net: qrtr: Allow the host QRTR to assign a unique node id
Date: Thu, 22 Oct 2026 19:43:07 +0200 [thread overview]
Message-ID: <20261022-qrtr-multi-ep-v4-1-c6fdb75fcd3e@oss.qualcomm.com> (raw)
In-Reply-To: <20261022-qrtr-multi-ep-v4-0-c6fdb75fcd3e@oss.qualcomm.com>
From: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
Currently, QRTR identifies each remote node by the value of the
'src_node_id' field in the received packet and uses the node id as the key
to store the node to the internal 'qrtr_nodes' radix tree.
But this approach comes with a limitation. When more than one remote node
share the same id, then QRTR can only add the first node to the radix tree
and has to drop the successive nodes with the same node id as the 'key' in
radix tree has to be unique. This prevents connecting identical Qcom PCIe
WLAN devices to a single host at the same time.
To fix this limitation, allow the host QRTR to use the node id (nid)
received from the endpoint driver during qrtr_endpoint_register() as the
unique node id and use it as the 'key' for the internal radix tree. Also,
store the received 'src_id' in a new 'qrtr_node->ep_nid' field and replace
the 'ep_nid' with the unique 'nid' in the QRTR control packets if both
differ i.e., an endpoint driver has passed a unique 'nid' during
qrtr_endpoint_register(). To maintain symmetry, replace the 'nid' with the
'ep_nid' while sending the packet back to the remote node if both differ.
A node can also bridge other distant nodes, so the source id of an
incoming packet is not always the id the endpoint advertises for itself.
Keep adding such ids to the radix tree as additional keys for the same
node, as it was done before this change. Otherwise the bridged nodes would
lose their route and qrtr_sendmsg() would start failing with -ECONNRESET
for them.
Currently, all QRTR endpoint drivers pass 'QRTR_EP_NID_AUTO' as the 'nid'
during qrtr_endpoint_register(). So 'ep_nid' and 'nid' are same and the
routing behavior is not changed.
Finally, since qrtr_node_rewrite_ctrl() dereferences the control packet for
DEL_SERVER and DEL_CLIENT as well, extend the existing length check in
qrtr_endpoint_post() to cover both types.
Signed-off-by: Manivannan Sadhasivam <manivannan.sadhasivam@oss.qualcomm.com>
---
net/qrtr/af_qrtr.c | 132 ++++++++++++++++++++++++++++++++++++++++++++++-------
1 file changed, 116 insertions(+), 16 deletions(-)
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index 78347c937af7..efa70b95f8a7 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -118,7 +118,8 @@ static DEFINE_XARRAY_ALLOC(qrtr_ports);
* @ep_lock: lock for endpoint management and callbacks
* @ep: endpoint
* @ref: reference count for node
- * @nid: node id
+ * @nid: node id assigned by the host QRTR
+ * @ep_nid: endpoint's own node id as received
* @qrtr_tx_flow: xarray of qrtr_tx_flow, keyed by node << 32 | port
* @qrtr_tx_lock: lock for qrtr_tx_flow inserts
* @hello_sent: hello packet send successful
@@ -131,6 +132,7 @@ struct qrtr_node {
struct qrtr_endpoint *ep;
struct kref ref;
unsigned int nid;
+ unsigned int ep_nid;
struct xarray qrtr_tx_flow;
struct mutex qrtr_tx_lock; /* for qrtr_tx_flow */
@@ -347,6 +349,7 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
{
struct qrtr_hdr_v1 *hdr;
size_t len = skb->len;
+ unsigned int dst_node;
int rc, confirm_rx;
mutex_lock(&node->ep_lock);
@@ -369,10 +372,14 @@ static int qrtr_node_enqueue(struct qrtr_node *node, struct sk_buff *skb,
hdr->src_node_id = cpu_to_le32(from->sq_node);
hdr->src_port_id = cpu_to_le32(from->sq_port);
if (to->sq_port == QRTR_PORT_CTRL) {
- hdr->dst_node_id = cpu_to_le32(READ_ONCE(node->nid));
+ hdr->dst_node_id = cpu_to_le32(READ_ONCE(node->ep_nid));
hdr->dst_port_id = cpu_to_le32(QRTR_PORT_CTRL);
} else {
- hdr->dst_node_id = cpu_to_le32(to->sq_node);
+ /* Put back the endpoint's own node id */
+ dst_node = to->sq_node;
+ if (dst_node == READ_ONCE(node->nid))
+ dst_node = READ_ONCE(node->ep_nid);
+ hdr->dst_node_id = cpu_to_le32(dst_node);
hdr->dst_port_id = cpu_to_le32(to->sq_port);
}
@@ -422,23 +429,72 @@ static struct qrtr_node *qrtr_node_lookup(unsigned int nid)
return node;
}
-/* Assign node id to node.
+/* Add 'nid' as a lookup key for 'node', and adopt it as the node's own id if
+ * the node does not have one yet.
+ *
+ * Callers must hold 'qrtr_nodes_lock'.
*
- * This is mostly useful for automatic node id assignment, based on
- * the source id in the incoming packet.
+ * Return: 0 on success; negative error code on failure
*/
-static void qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
+static int __qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
{
- unsigned long flags;
+ int rc;
if (nid == QRTR_EP_NID_AUTO)
- return;
+ return 0;
+
+ if (radix_tree_lookup(&qrtr_nodes, nid) == node)
+ return 0;
+
+ rc = radix_tree_insert(&qrtr_nodes, nid, node);
+ if (rc)
+ return rc;
- spin_lock_irqsave(&qrtr_nodes_lock, flags);
- radix_tree_insert(&qrtr_nodes, nid, node);
if (node->nid == QRTR_EP_NID_AUTO)
WRITE_ONCE(node->nid, nid);
+
+ return 0;
+}
+
+/* Assign node id to node.
+ *
+ * Return: 0 on success; negative error code on failure
+ */
+static int qrtr_node_assign(struct qrtr_node *node, unsigned int nid)
+{
+ unsigned long flags;
+ int rc;
+
+ spin_lock_irqsave(&qrtr_nodes_lock, flags);
+ rc = __qrtr_node_assign(node, nid);
spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+
+ return rc;
+}
+
+/* Replace the node id in the control packet with 'node->nid', if both are
+ * different.
+ */
+static void qrtr_node_rewrite_ctrl(struct qrtr_node *node, unsigned int type,
+ struct sk_buff *skb)
+{
+ unsigned int ep_nid = READ_ONCE(node->ep_nid);
+ unsigned int host_nid = READ_ONCE(node->nid);
+ struct qrtr_ctrl_pkt *pkt;
+ __le32 *nid;
+
+ if (host_nid == ep_nid)
+ return;
+
+ pkt = (struct qrtr_ctrl_pkt *)skb->data;
+ if (type == QRTR_TYPE_DEL_CLIENT || type == QRTR_TYPE_RESUME_TX)
+ nid = &pkt->client.node;
+ else
+ nid = &pkt->server.node;
+
+ /* Rewrite only the endpoint's node id, not those of bridged nodes */
+ if (le32_to_cpu(*nid) == ep_nid)
+ *nid = cpu_to_le32(host_nid);
}
/**
@@ -457,9 +513,12 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
struct qrtr_sock *ipc;
struct sk_buff *skb;
struct qrtr_cb *cb;
+ unsigned long flags;
size_t size;
unsigned int ver;
+ unsigned int nid;
size_t hdrlen;
+ int rc = 0;
if (len == 0 || len & 3)
return -EINVAL;
@@ -521,6 +580,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
goto err;
if ((cb->type == QRTR_TYPE_NEW_SERVER ||
+ cb->type == QRTR_TYPE_DEL_SERVER ||
+ cb->type == QRTR_TYPE_DEL_CLIENT ||
cb->type == QRTR_TYPE_RESUME_TX) &&
size < sizeof(struct qrtr_ctrl_pkt))
goto err;
@@ -531,16 +592,46 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
skb_put_data(skb, data + hdrlen, size);
- qrtr_node_assign(node, cb->src_node);
+ nid = cb->src_node;
+
+ spin_lock_irqsave(&qrtr_nodes_lock, flags);
+
+ if (node->ep_nid == QRTR_EP_NID_AUTO)
+ WRITE_ONCE(node->ep_nid, nid);
+
+ /* Add the source id to the lookup table only if 'node->nid' is auto
+ * assigned or the packet came from a bridged node.
+ */
+ if (node->nid == QRTR_EP_NID_AUTO || nid != node->ep_nid)
+ rc = __qrtr_node_assign(node, nid);
+
+ spin_unlock_irqrestore(&qrtr_nodes_lock, flags);
+
+ if (rc)
+ goto err_nid;
if (cb->type == QRTR_TYPE_NEW_SERVER) {
/* Remote node endpoint can bridge other distant nodes */
- const struct qrtr_ctrl_pkt *pkt;
+ const struct qrtr_ctrl_pkt *pkt = data + hdrlen;
+
+ nid = le32_to_cpu(pkt->server.node);
- pkt = data + hdrlen;
- qrtr_node_assign(node, le32_to_cpu(pkt->server.node));
+ if (nid != READ_ONCE(node->ep_nid)) {
+ rc = qrtr_node_assign(node, nid);
+ if (rc)
+ goto err_nid;
+ }
}
+ if (cb->src_node == READ_ONCE(node->ep_nid))
+ cb->src_node = READ_ONCE(node->nid);
+
+ if (cb->type == QRTR_TYPE_NEW_SERVER ||
+ cb->type == QRTR_TYPE_DEL_SERVER ||
+ cb->type == QRTR_TYPE_DEL_CLIENT ||
+ cb->type == QRTR_TYPE_RESUME_TX)
+ qrtr_node_rewrite_ctrl(node, cb->type, skb);
+
if (cb->type == QRTR_TYPE_RESUME_TX) {
qrtr_tx_resume(node, skb);
} else {
@@ -558,6 +649,8 @@ int qrtr_endpoint_post(struct qrtr_endpoint *ep, const void *data, size_t len)
return 0;
+err_nid:
+ pr_err_ratelimited("qrtr: cannot route node id %u: %d\n", nid, rc);
err:
kfree_skb(skb);
return -EINVAL;
@@ -634,6 +727,7 @@ static void qrtr_hello_work(struct work_struct *work)
int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
{
struct qrtr_node *node;
+ int rc;
if (!ep || !ep->xmit)
return -EINVAL;
@@ -646,6 +740,7 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
mutex_init(&node->ep_lock);
skb_queue_head_init(&node->rx_queue);
node->nid = QRTR_EP_NID_AUTO;
+ node->ep_nid = QRTR_EP_NID_AUTO;
node->ep = ep;
node->hello_sent = false;
@@ -654,7 +749,12 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
xa_init(&node->qrtr_tx_flow);
mutex_init(&node->qrtr_tx_lock);
- qrtr_node_assign(node, nid);
+ rc = qrtr_node_assign(node, nid);
+ if (rc) {
+ pr_err("qrtr: cannot assign node id %u: %d\n", nid, rc);
+ kfree(node);
+ return rc;
+ }
mutex_lock(&qrtr_node_lock);
list_add(&node->item, &qrtr_all_nodes);
--
2.43.0
next prev parent reply other threads:[~2026-10-22 17:43 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-22 17:43 [PATCH v4 0/4] net: qrtr: Add support for using identical MHI endpoint devices Manivannan Sadhasivam via B4 Relay
2026-10-22 17:43 ` Manivannan Sadhasivam via B4 Relay [this message]
2026-10-22 17:43 ` [PATCH v4 2/4] net: qrtr: Assign unique node id for MHI endpoints Manivannan Sadhasivam via B4 Relay
2026-10-22 17:43 ` [PATCH v4 3/4] wifi: ath11k: Connect to the QMI server belonging to the device owned by this driver Manivannan Sadhasivam via B4 Relay
2026-10-22 17:43 ` [PATCH v4 4/4] wifi: ath12k: " Manivannan Sadhasivam via B4 Relay
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20261022-qrtr-multi-ep-v4-1-c6fdb75fcd3e@oss.qualcomm.com \
--to=devnull+manivannan.sadhasivam.oss.qualcomm.com@kernel.org \
--cc=andersson@kernel.org \
--cc=ath11k@lists.infradead.org \
--cc=ath12k@lists.infradead.org \
--cc=christopher.lew@oss.qualcomm.com \
--cc=davem@davemloft.net \
--cc=deepak.singh@oss.qualcomm.com \
--cc=edumazet@google.com \
--cc=horms@kernel.org \
--cc=jeff.hugo@oss.qualcomm.com \
--cc=jjohnson@kernel.org \
--cc=juha-matti.tilli@iki.fi \
--cc=kuba@kernel.org \
--cc=linux-arm-msm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-wireless@vger.kernel.org \
--cc=mani@kernel.org \
--cc=manivannan.sadhasivam@oss.qualcomm.com \
--cc=netdev@vger.kernel.org \
--cc=pabeni@redhat.com \
--cc=raj.bhagat@oss.qualcomm.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®