* [RFC] [PATCH v2 01/13] net: qrtr: support registering endpoint-specific data
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 02/13] net: qrtr: mhi: register mhi_controller as " Mihai Moldovan
` (11 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
This adds the infrastructure for registering endpoint-specific data for
endpoint IDs.
Endpoint-specific data can be used to map an endpoint ID to a specific
endpoint backend.
Additional API is introduced as a common header in include/net to allow
other parts of the kernel to query endpoint IDs for endpoint-specific
data or make the QRTR subsystem assign a new endpoint ID for passed
endpoint-specific data. This will allow other systems to register
endpoint IDs before actual socket creation and usage, which in turn
allows proper binding to endpoint IDs from the start.
The endpoint registration function is changed to re-use endpoint IDs
that match the backend's endpoint-specific data if possible, assign a
new endpoint ID if the endpoint-specific data is not known yet, or
create a new endpoint ID without endpoint-specific data attached to it
if all else fails.
There is one gripe with this implementation: other kernel subsystems
can, theoretically, assign an unlimited number of new endpoint IDs and
thus exhaust endpoint ID space. No API is provided to delete endpoint
IDs and we also do not track which endpoint IDs are in use and which are
not, which means that even the QRTR-internal code cannot easily clean up
unused endpoint IDs. The only exception to this are endpoint IDs
attached to QRTR nodes, which will be deleted when the QRTR nodes
themselves are deleted.
This is probably a potential memory leak that we can live with.
Fixing that is rather difficult. We would either have to add some form
of refcounting, wrap the endpoint-specific data pointer into yet another
structure together with a kref and use that to free unused endpoint IDs,
or periodically clean unused endpoint IDs up in a timer (executing, say,
every 10 minutes), essentially doing garbage collection.
Garbage collection is being frowned upon, especially in the kernel, but
in this case, it really would make the most sense. Clients might
allocate endpoint IDs that are never actually used (for instance because
the client uses a wrong endpoint-specific data pointer, which is not
used by a QRTR backend), and will need to hold a reference to this for
their entire life time, which essentially defeats the concept of
cleanup of unused endpoint IDs via reference counting.
Clients can create endpoint IDs quite some time before the QRTR
subsystem uses them, but there is no way to easily tell when this will
be. The idea is that minutes as orders of magnitude would probably be a
safe value for which to regard an endpoint ID as unused.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Depends-on: 25a7151cdc98 ("net: qrtr: ns: support multiple endpoints")
Link: https://patch.msgid.link/20241018181842.1368394-1-denkenz@gmail.com
---
MAINTAINERS | 1 +
include/net/qrtr.h | 11 ++++
net/qrtr/af_qrtr.c | 124 +++++++++++++++++++++++++++++++++++++++++++--
net/qrtr/qrtr.h | 5 ++
4 files changed, 138 insertions(+), 3 deletions(-)
create mode 100644 include/net/qrtr.h
diff --git a/MAINTAINERS b/MAINTAINERS
index 96b9344c3524..6993067c4194 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -19115,6 +19115,7 @@ QUALCOMM IPC ROUTER (QRTR) DRIVER
M: Manivannan Sadhasivam <manivannan.sadhasivam@linaro.org>
L: linux-arm-msm@vger.kernel.org
S: Maintained
+F: include/net/qrtr.h
F: include/trace/events/qrtr.h
F: include/uapi/linux/qrtr.h
F: net/qrtr/
diff --git a/include/net/qrtr.h b/include/net/qrtr.h
new file mode 100644
index 000000000000..799c84eb35ad
--- /dev/null
+++ b/include/net/qrtr.h
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+#ifndef __NET_QRTR_H
+#define __NET_QRTR_H
+
+#include <linux/types.h>
+
+int qrtr_endpoint_id_get(const void *data, u32 *id);
+int qrtr_endpoint_id_assign(void *data, u32 *id);
+int qrtr_endpoint_id_get_or_assign(void *data, u32 *id);
+
+#endif /* __NET_QRTR_H */
diff --git a/net/qrtr/af_qrtr.c b/net/qrtr/af_qrtr.c
index cf8b5483ba2c..59227b3d49f4 100644
--- a/net/qrtr/af_qrtr.c
+++ b/net/qrtr/af_qrtr.c
@@ -11,6 +11,7 @@
#include <linux/wait.h>
#include <net/sock.h>
+#include <net/qrtr.h>
#include "qrtr.h"
@@ -649,6 +650,114 @@ static struct sk_buff *qrtr_alloc_ctrl_packet(struct qrtr_ctrl_pkt **pkt,
return skb;
}
+/**
+ * qrtr_endpoint_id_get() - get a registered endpoint for given data
+ * @data: endpoint-specific data to fetch ID for
+ * @id: pointer to store endpoint ID into
+ * Return: 0 on success, negative error code on failure
+ *
+ * The endpoint-specific data must not be NULL.
+ * The output parameter id must not be NULL.
+ * If no endpoint ID can be mapped to the endpoint-specific data, id will be
+ * set to 0.
+ */
+int qrtr_endpoint_id_get(const void *data, u32 *id)
+{
+ unsigned long idx = 0;
+ void *iter_data = NULL;
+
+ if (!id)
+ return -EINVAL;
+
+ if (!data)
+ return -EINVAL;
+
+ *id = 0;
+ rcu_read_lock();
+ xa_for_each_range(&qrtr_endpoints, idx, iter_data,
+ QRTR_ENDPOINT_RANGE.min, QRTR_ENDPOINT_RANGE.max) {
+ if (iter_data == data) {
+ *id = idx;
+ break;
+ }
+ }
+ rcu_read_unlock();
+
+ return 0;
+}
+EXPORT_SYMBOL_GPL(qrtr_endpoint_id_get);
+
+/**
+ * qrtr_endpoint_id_assign() - assigns a new endpoint ID for given data
+ * @data: endpoint-specific data to assign new ID for
+ * @id: pointer to store endpoint ID into
+ * Return: 0 on success, negative error code on failure
+ *
+ * The endpoint-specific data must not be NULL.
+ * The output parameter id must not be NULL.
+ * On error, id will be set to 0.
+ */
+int qrtr_endpoint_id_assign(void *data, u32 *id)
+{
+ int rc = 0;
+
+ if (!id)
+ return -EINVAL;
+
+ if (!data)
+ return -EINVAL;
+
+ rc = xa_alloc_cyclic(&qrtr_endpoints, id, data, QRTR_ENDPOINT_RANGE,
+ &next_endpoint_id, GFP_KERNEL);
+ if (rc)
+ *id = 0;
+
+ return rc;
+}
+EXPORT_SYMBOL_GPL(qrtr_endpoint_id_assign);
+
+/**
+ * qrtr_endpoint_id_get_or_assign() - gets or assigns endpoint ID for data
+ * @data: endpoint-specific data to assign new ID for
+ * @id: pointer to store endpoint ID into
+ * Return: positive on success, negative error code on failure
+ *
+ * The endpoint-specific data must not be NULL.
+ *
+ * If the endpoint-specific data is already registered to an endpoint ID, this
+ * ID will be assigned to id. Otherwise, this function assigns a new
+ * endpoint ID and associates it with the given endpoint-specific data.
+ *
+ * The output parameter id must not be NULL. It will either be set to the
+ * fetched or newly assigned endpoint ID on success, or set to 0 on error.
+ */
+int qrtr_endpoint_id_get_or_assign(void *data, u32 *id)
+{
+ int rc = 0;
+
+ if (!data)
+ return -EINVAL;
+
+ if (!id)
+ return -EINVAL;
+
+ rc = qrtr_endpoint_id_get(data, id);
+
+ if (rc) {
+ *id = 0;
+ return rc;
+ }
+
+ if (!*id)
+ rc = qrtr_endpoint_id_assign(data, id);
+
+ if (rc)
+ *id = 0;
+
+ return rc;
+}
+EXPORT_SYMBOL_GPL(qrtr_endpoint_id_get_or_assign);
+
/**
* qrtr_endpoint_register() - register a new endpoint
* @ep: endpoint to register
@@ -670,9 +779,18 @@ int qrtr_endpoint_register(struct qrtr_endpoint *ep, unsigned int nid)
if (!node)
return -ENOMEM;
- rc = xa_alloc_cyclic(&qrtr_endpoints, &endpoint_id, NULL,
- QRTR_ENDPOINT_RANGE, &next_endpoint_id,
- GFP_KERNEL);
+ rc = qrtr_endpoint_id_get_or_assign(ep->endpoint_data, &endpoint_id);
+
+ /*
+ * The previous function fails if ep->endpoint_data is NULL, so retry.
+ *
+ * We're going to assign an endpoint ID without endpoint-specific data
+ * set in this case.
+ */
+ if (rc)
+ rc = xa_alloc_cyclic(&qrtr_endpoints, &endpoint_id, NULL,
+ QRTR_ENDPOINT_RANGE, &next_endpoint_id,
+ GFP_KERNEL);
if (rc < 0)
goto free_node;
diff --git a/net/qrtr/qrtr.h b/net/qrtr/qrtr.h
index b4f50336ae75..3509168e8a40 100644
--- a/net/qrtr/qrtr.h
+++ b/net/qrtr/qrtr.h
@@ -12,13 +12,18 @@ struct sk_buff;
/**
* struct qrtr_endpoint - endpoint handle
* @xmit: Callback for outgoing packets
+ * @endpoint_data: endpoint-specific data pointer, can be NULL
*
* The socket buffer passed to the xmit function becomes owned by the endpoint
* driver. As such, when the driver is done with the buffer, it should
* call kfree_skb() on failure, or consume_skb() on success.
+ *
+ * If endpoint_data is NULL, endpoint IDs can not be directly mapped to a
+ * specific endpoint.
*/
struct qrtr_endpoint {
int (*xmit)(struct qrtr_endpoint *ep, struct sk_buff *skb);
+ void *endpoint_data;
/* private: not for endpoint use */
struct qrtr_node *node;
u32 id;
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 02/13] net: qrtr: mhi: register mhi_controller as endpoint-specific data
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 01/13] net: qrtr: support registering endpoint-specific data Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 03/13] net: qrtr: smd: register rpmsg_device " Mihai Moldovan
` (10 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
For the MHI backend, we will use the mhi_controller pointer as the
endpoint-specific data.
This means that we can only have one endpoint ID per MHI controller, but
since the MHI controller is the bus master in charge of the physical
link, this is probably okay.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
net/qrtr/mhi.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/qrtr/mhi.c b/net/qrtr/mhi.c
index 9a23c888e234..fc6869c3a7ec 100644
--- a/net/qrtr/mhi.c
+++ b/net/qrtr/mhi.c
@@ -95,6 +95,7 @@ static int qcom_mhi_qrtr_probe(struct mhi_device *mhi_dev,
qdev->mhi_dev = mhi_dev;
qdev->dev = &mhi_dev->dev;
qdev->ep.xmit = qcom_mhi_qrtr_send;
+ qdev->ep.endpoint_data = mhi_dev->mhi_cntrl;
dev_set_drvdata(&mhi_dev->dev, qdev);
rc = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NID_AUTO);
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 03/13] net: qrtr: smd: register rpmsg_device as endpoint-specific data
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 01/13] net: qrtr: support registering endpoint-specific data Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 02/13] net: qrtr: mhi: register mhi_controller as " Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 04/13] net: qrtr: tun: register inode " Mihai Moldovan
` (9 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
For the SMD backend, we will use the rpmsg_device pointer as the
endpoint-specific data.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
net/qrtr/smd.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/qrtr/smd.c b/net/qrtr/smd.c
index c91bf030fbc7..cb3eeb6835ca 100644
--- a/net/qrtr/smd.c
+++ b/net/qrtr/smd.c
@@ -68,6 +68,7 @@ static int qcom_smd_qrtr_probe(struct rpmsg_device *rpdev)
qdev->channel = rpdev->ept;
qdev->dev = &rpdev->dev;
qdev->ep.xmit = qcom_smd_qrtr_send;
+ qdev->ep.endpoint_data = rpdev;
rc = qrtr_endpoint_register(&qdev->ep, QRTR_EP_NID_AUTO);
if (rc)
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 04/13] net: qrtr: tun: register inode as endpoint-specific data
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (2 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 03/13] net: qrtr: smd: register rpmsg_device " Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 05/13] soc: qcom: qmi_helpers: add QRTR endpoint ID to qmi_handle Mihai Moldovan
` (8 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
For the TUN backend, we will use the inode pointer as the
endpoint-specific data.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
net/qrtr/tun.c | 1 +
1 file changed, 1 insertion(+)
diff --git a/net/qrtr/tun.c b/net/qrtr/tun.c
index 304b41fea5ab..9dcfecd529f7 100644
--- a/net/qrtr/tun.c
+++ b/net/qrtr/tun.c
@@ -41,6 +41,7 @@ static int qrtr_tun_open(struct inode *inode, struct file *filp)
init_waitqueue_head(&tun->readq);
tun->ep.xmit = qrtr_tun_send;
+ tun->ep.endpoint_data = inode;
filp->private_data = tun;
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 05/13] soc: qcom: qmi_helpers: add QRTR endpoint ID to qmi_handle
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (3 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 04/13] net: qrtr: tun: register inode " Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 06/13] soc: qcom: qmi_helpers: optionally bind to QRTR endpoint ID in qmi_sock_create Mihai Moldovan
` (7 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
Adding this allows us to easily supply an endpoint ID to bind on later
on when creating the socket.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
include/linux/soc/qcom/qmi.h | 3 +++
1 file changed, 3 insertions(+)
diff --git a/include/linux/soc/qcom/qmi.h b/include/linux/soc/qcom/qmi.h
index 469e02d2aa0d..77743c855762 100644
--- a/include/linux/soc/qcom/qmi.h
+++ b/include/linux/soc/qcom/qmi.h
@@ -212,6 +212,7 @@ struct qmi_msg_handler {
* @txns: outstanding transactions
* @txn_lock: lock for modifications of @txns
* @handlers: list of handlers for incoming messages
+ * @endpoint_id: QRTR endpoint ID to bind on
*/
struct qmi_handle {
struct socket *sock;
@@ -235,6 +236,8 @@ struct qmi_handle {
struct mutex txn_lock;
const struct qmi_msg_handler *handlers;
+
+ u32 endpoint_id;
};
int qmi_add_lookup(struct qmi_handle *qmi, unsigned int service,
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 06/13] soc: qcom: qmi_helpers: optionally bind to QRTR endpoint ID in qmi_sock_create
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (4 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 05/13] soc: qcom: qmi_helpers: add QRTR endpoint ID to qmi_handle Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 07/13] wifi: ath11k: add QRTR endpoint ID hif feature Mihai Moldovan
` (6 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
For clients that already know the QRTR endpoint ID before actually
creating the QMI socket and set it in struct qmi_handle, optionally try
to bind to this QRTR endpoint ID when creating the socket.
This can fail, and qmi_sock_create will issue diagnostic messages, but
otherwise ignore the error.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
drivers/soc/qcom/qmi_interface.c | 28 ++++++++++++++++++++++++++++
1 file changed, 28 insertions(+)
diff --git a/drivers/soc/qcom/qmi_interface.c b/drivers/soc/qcom/qmi_interface.c
index bb98b06e87f8..dd3978682c09 100644
--- a/drivers/soc/qcom/qmi_interface.c
+++ b/drivers/soc/qcom/qmi_interface.c
@@ -586,6 +586,7 @@ static struct socket *qmi_sock_create(struct qmi_handle *qmi,
struct sockaddr_qrtr *sq)
{
struct socket *sock;
+ const struct proto_ops *ops = NULL;
int ret;
ret = sock_create_kern(&init_net, AF_QIPCRTR, SOCK_DGRAM,
@@ -593,6 +594,33 @@ static struct socket *qmi_sock_create(struct qmi_handle *qmi,
if (ret < 0)
return ERR_PTR(ret);
+ ops = READ_ONCE(sock->ops);
+
+ if (!ops) {
+ pr_warn("sock->ops not available for QMI socket\n");
+ pr_warn("will not be able to bind to endpoint ID.\n");
+ /* N.B.: this error value will not be passed out. */
+ ret = -ENXIO;
+ }
+
+ if (!ret && !ops->setsockopt) {
+ pr_warn("ops->setsockopt not available for QMI socket\n");
+ pr_warn("will not be able to bind to endpoint ID.\n");
+ /* N.B.: this error value will not be passed out. */
+ ret = -ENXIO;
+ }
+
+ /* Only bind to a specific endpoint if a valid one was provided. */
+ if (!ret && qmi->endpoint_id) {
+ ret = ops->setsockopt(sock, SOL_QRTR, QRTR_BIND_ENDPOINT,
+ KERNEL_SOCKPTR(&qmi->endpoint_id),
+ sizeof(qmi->endpoint_id));
+
+ if (ret < 0)
+ pr_warn("binding to QRTR endpoint ID failed: %d\n",
+ ret);
+ }
+
ret = kernel_getsockname(sock, (struct sockaddr *)sq);
if (ret < 0) {
sock_release(sock);
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 07/13] wifi: ath11k: add QRTR endpoint ID hif feature
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (5 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 06/13] soc: qcom: qmi_helpers: optionally bind to QRTR endpoint ID in qmi_sock_create Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 08/13] wifi: ath11k: stub QRTR endpoint ID fetching for AHB Mihai Moldovan
` (5 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
This will allow fetching the QRTR endpoint ID via hardware-specific
means.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
drivers/net/wireless/ath/ath11k/hif.h | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/net/wireless/ath/ath11k/hif.h b/drivers/net/wireless/ath/ath11k/hif.h
index 674ff772b181..07ba45c9924a 100644
--- a/drivers/net/wireless/ath/ath11k/hif.h
+++ b/drivers/net/wireless/ath/ath11k/hif.h
@@ -31,6 +31,7 @@ struct ath11k_hif_ops {
void (*ce_irq_enable)(struct ath11k_base *ab);
void (*ce_irq_disable)(struct ath11k_base *ab);
void (*get_ce_msi_idx)(struct ath11k_base *ab, u32 ce_id, u32 *msi_idx);
+ int (*set_qrtr_endpoint_id)(struct ath11k_base *ab);
};
static inline void ath11k_hif_ce_irq_enable(struct ath11k_base *ab)
@@ -146,4 +147,12 @@ static inline void ath11k_get_ce_msi_idx(struct ath11k_base *ab, u32 ce_id,
*msi_data_idx = ce_id;
}
+static inline int ath11k_set_qrtr_endpoint_id(struct ath11k_base *ab)
+{
+ if (!ab->hif.ops->set_qrtr_endpoint_id)
+ return -EOPNOTSUPP;
+ else
+ return ab->hif.ops->set_qrtr_endpoint_id(ab);
+}
+
#endif /* _HIF_H_ */
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 08/13] wifi: ath11k: stub QRTR endpoint ID fetching for AHB
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (6 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 07/13] wifi: ath11k: add QRTR endpoint ID hif feature Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 09/13] wifi: ath11k: implement QRTR endpoint ID fetching for PCI Mihai Moldovan
` (4 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
QRTR endpoint ID fetching will currently not be available for AHB.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
drivers/net/wireless/ath/ath11k/ahb.c | 7 +++++++
1 file changed, 7 insertions(+)
diff --git a/drivers/net/wireless/ath/ath11k/ahb.c b/drivers/net/wireless/ath/ath11k/ahb.c
index f2fc04596d48..acb12d6d647f 100644
--- a/drivers/net/wireless/ath/ath11k/ahb.c
+++ b/drivers/net/wireless/ath/ath11k/ahb.c
@@ -773,6 +773,7 @@ static const struct ath11k_hif_ops ath11k_ahb_hif_ops_ipq8074 = {
.map_service_to_pipe = ath11k_ahb_map_service_to_pipe,
.power_down = ath11k_ahb_power_down,
.power_up = ath11k_ahb_power_up,
+ .set_qrtr_endpoint_id = ath11k_ahb_set_qrtr_endpoint_id,
};
static const struct ath11k_hif_ops ath11k_ahb_hif_ops_wcn6750 = {
@@ -792,6 +793,7 @@ static const struct ath11k_hif_ops ath11k_ahb_hif_ops_wcn6750 = {
.resume = ath11k_ahb_hif_resume,
.ce_irq_enable = ath11k_pci_enable_ce_irqs_except_wake_irq,
.ce_irq_disable = ath11k_pci_disable_ce_irqs_except_wake_irq,
+ .set_qrtr_endpoint_id = ath11k_ahb_set_qrtr_endpoint_id,
};
static int ath11k_core_get_rproc(struct ath11k_base *ab)
@@ -1312,6 +1314,11 @@ static void ath11k_ahb_shutdown(struct platform_device *pdev)
ath11k_ahb_free_resources(ab);
}
+static ath11k_ahb_set_qrtr_endpoint_id(struct ath11k_base *ab)
+{
+ return -EOPNOTSUPP;
+}
+
static struct platform_driver ath11k_ahb_driver = {
.driver = {
.name = "ath11k",
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 09/13] wifi: ath11k: implement QRTR endpoint ID fetching for PCI
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (7 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 08/13] wifi: ath11k: stub QRTR endpoint ID fetching for AHB Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 10/13] wifi: ath11k: bind to QRTR endpoint ID in ath11k_qmi_init_service Mihai Moldovan
` (3 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
QRTR endpoint ID fetching for PCIe devices will use MHI.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
drivers/net/wireless/ath/ath11k/mhi.c | 22 ++++++++++++++++++++++
drivers/net/wireless/ath/ath11k/mhi.h | 1 +
drivers/net/wireless/ath/ath11k/pci.c | 1 +
3 files changed, 24 insertions(+)
diff --git a/drivers/net/wireless/ath/ath11k/mhi.c b/drivers/net/wireless/ath/ath11k/mhi.c
index 6e45f464a429..0b3f9f965aee 100644
--- a/drivers/net/wireless/ath/ath11k/mhi.c
+++ b/drivers/net/wireless/ath/ath11k/mhi.c
@@ -11,6 +11,8 @@
#include <linux/of_address.h>
#include <linux/ioport.h>
+#include <net/qrtr.h>
+
#include "core.h"
#include "debug.h"
#include "mhi.h"
@@ -491,3 +493,23 @@ int ath11k_mhi_resume(struct ath11k_pci *ab_pci)
return 0;
}
+
+int ath11k_mhi_set_qrtr_endpoint_id(struct ath11k_base *ab)
+{
+ struct ath11k_pci *ab_pci = ath11k_pci_priv(ab);
+ struct ath11k_qmi *qmi = &ab->qmi;
+ int ret;
+
+ /* Pass endpoint ID up for QMI usage. */
+ ret = qrtr_endpoint_id_get_or_assign(ab_pci->mhi_ctrl,
+ &qmi->handle.endpoint_id);
+ ath11k_dbg(ab, ATH11K_DBG_PCI,
+ "queried mhi_ctrl QRTR endpoint ID: %u\n",
+ qmi->handle.endpoint_id);
+ if (ret) {
+ ath11k_warn(ab, "failed to query QRTR endpoint ID: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/drivers/net/wireless/ath/ath11k/mhi.h b/drivers/net/wireless/ath/ath11k/mhi.h
index a682aad52fc5..84465fb5d5da 100644
--- a/drivers/net/wireless/ath/ath11k/mhi.h
+++ b/drivers/net/wireless/ath/ath11k/mhi.h
@@ -27,4 +27,5 @@ void ath11k_mhi_clear_vector(struct ath11k_base *ab);
int ath11k_mhi_suspend(struct ath11k_pci *ar_pci);
int ath11k_mhi_resume(struct ath11k_pci *ar_pci);
+int ath11k_mhi_set_qrtr_endpoint_id(struct ath11k_base *ab);
#endif
diff --git a/drivers/net/wireless/ath/ath11k/pci.c b/drivers/net/wireless/ath/ath11k/pci.c
index a6cc2a4f072d..6f3c1db11f69 100644
--- a/drivers/net/wireless/ath/ath11k/pci.c
+++ b/drivers/net/wireless/ath/ath11k/pci.c
@@ -744,6 +744,7 @@ static const struct ath11k_hif_ops ath11k_pci_hif_ops = {
.ce_irq_enable = ath11k_pci_hif_ce_irq_enable,
.ce_irq_disable = ath11k_pci_hif_ce_irq_disable,
.get_ce_msi_idx = ath11k_pcic_get_ce_msi_idx,
+ .set_qrtr_endpoint_id = ath11k_mhi_set_qrtr_endpoint_id,
};
static void ath11k_pci_read_hw_version(struct ath11k_base *ab, u32 *major, u32 *minor)
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 10/13] wifi: ath11k: bind to QRTR endpoint ID in ath11k_qmi_init_service
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (8 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 09/13] wifi: ath11k: implement QRTR endpoint ID fetching for PCI Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 11/13] wifi: ath12k: add QRTR endpoint ID hif feature Mihai Moldovan
` (2 subsequent siblings)
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
If possible, fetch the QRTR endpoint ID in ath11k_qmi_init_service, just
before calling qmi_handle_init, and make it available in the qmi_handle.
qmi_helpers will then automatically bind to this endpoint for us.
This finally allows using multiple ath11k-based cards with the same QRTR
node/port combination to work simultanenous (and, for that matter, at
all).
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Tested-on: QCA6390 hw2.0 PCI WLAN.HST.1.0.1-05266-QCAHSTSWPLZ_V2_TO_X86-1
---
drivers/net/wireless/ath/ath11k/qmi.c | 8 ++++++++
1 file changed, 8 insertions(+)
diff --git a/drivers/net/wireless/ath/ath11k/qmi.c b/drivers/net/wireless/ath/ath11k/qmi.c
index 5759fc521316..604d7211b980 100644
--- a/drivers/net/wireless/ath/ath11k/qmi.c
+++ b/drivers/net/wireless/ath/ath11k/qmi.c
@@ -15,6 +15,7 @@
#include <linux/ioport.h>
#include <linux/firmware.h>
#include <linux/of_irq.h>
+#include <net/sock.h>
#define SLEEP_CLOCK_SELECT_INTERNAL_BIT 0x02
#define HOST_CSTATE_BIT 0x04
@@ -3315,6 +3316,13 @@ int ath11k_qmi_init_service(struct ath11k_base *ab)
ab->qmi.ab = ab;
ab->qmi.target_mem_mode = ab->hw_params.fw_mem_mode;
+
+ ret = ath11k_set_qrtr_endpoint_id(ab);
+ if (ret) {
+ ath11k_warn(ab, "failed to set QRTR endpoint ID: %d\n", ret);
+ ath11k_warn(ab, "only one device per system will be supported\n");
+ }
+
ret = qmi_handle_init(&ab->qmi.handle, ATH11K_QMI_RESP_LEN_MAX,
&ath11k_qmi_ops, ath11k_qmi_msg_handlers);
if (ret < 0) {
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 11/13] wifi: ath12k: add QRTR endpoint ID hif feature
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (9 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 10/13] wifi: ath11k: bind to QRTR endpoint ID in ath11k_qmi_init_service Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 12/13] wifi: ath12k: implement QRTR endpoint ID fetching for PCI Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 13/13] wifi: ath12k: bind to QRTR endpoint ID in ath12k_qmi_init_service Mihai Moldovan
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
This will allow fetching the QRTR endpoint ID via hardware-specific
means.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
drivers/net/wireless/ath/ath12k/hif.h | 10 ++++++++++
1 file changed, 10 insertions(+)
diff --git a/drivers/net/wireless/ath/ath12k/hif.h b/drivers/net/wireless/ath/ath12k/hif.h
index e8840fab6061..fcf055c8dae2 100644
--- a/drivers/net/wireless/ath/ath12k/hif.h
+++ b/drivers/net/wireless/ath/ath12k/hif.h
@@ -32,6 +32,7 @@ struct ath12k_hif_ops {
void (*get_ce_msi_idx)(struct ath12k_base *ab, u32 ce_id, u32 *msi_idx);
int (*panic_handler)(struct ath12k_base *ab);
void (*coredump_download)(struct ath12k_base *ab);
+ int (*set_qrtr_endpoint_id)(struct ath12k_base *ab);
};
static inline int ath12k_hif_map_service_to_pipe(struct ath12k_base *ab, u16 service_id,
@@ -162,4 +163,13 @@ static inline void ath12k_hif_coredump_download(struct ath12k_base *ab)
if (ab->hif.ops->coredump_download)
ab->hif.ops->coredump_download(ab);
}
+
+static inline int ath12k_hif_set_qrtr_endpoint_id(struct ath12k_base *ab)
+{
+ if (!ab->hif.ops->set_qrtr_endpoint_id)
+ return -EOPNOTSUPP;
+ else
+ return ab->hif.ops->set_qrtr_endpoint_id(ab);
+}
+
#endif /* ATH12K_HIF_H */
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 12/13] wifi: ath12k: implement QRTR endpoint ID fetching for PCI
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (10 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 11/13] wifi: ath12k: add QRTR endpoint ID hif feature Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
2024-11-25 3:50 ` [RFC] [PATCH v2 13/13] wifi: ath12k: bind to QRTR endpoint ID in ath12k_qmi_init_service Mihai Moldovan
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
QRTR endpoint ID fetching for PCIe devices will use MHI.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
---
drivers/net/wireless/ath/ath12k/mhi.c | 22 ++++++++++++++++++++++
drivers/net/wireless/ath/ath12k/mhi.h | 2 ++
drivers/net/wireless/ath/ath12k/pci.c | 1 +
3 files changed, 25 insertions(+)
diff --git a/drivers/net/wireless/ath/ath12k/mhi.c b/drivers/net/wireless/ath/ath12k/mhi.c
index 2f6d14382ed7..a6067c236c0d 100644
--- a/drivers/net/wireless/ath/ath12k/mhi.c
+++ b/drivers/net/wireless/ath/ath12k/mhi.c
@@ -8,6 +8,8 @@
#include <linux/pci.h>
#include <linux/firmware.h>
+#include <net/qrtr.h>
+
#include "core.h"
#include "debug.h"
#include "mhi.h"
@@ -654,3 +656,23 @@ void ath12k_mhi_coredump(struct mhi_controller *mhi_ctrl, bool in_panic)
{
mhi_download_rddm_image(mhi_ctrl, in_panic);
}
+
+int ath12k_mhi_set_qrtr_endpoint_id(struct ath12k_base *ab)
+{
+ struct ath12k_pci *ab_pci = ath12k_pci_priv(ab);
+ struct ath12k_qmi *qmi = &ab->qmi;
+ int ret;
+
+ /* Pass endpoint ID up for QMI usage. */
+ ret = qrtr_endpoint_id_get_or_assign(ab_pci->mhi_ctrl,
+ &qmi->handle.endpoint_id);
+ ath12k_dbg(ab, ATH12K_DBG_PCI,
+ "queried mhi_ctrl QRTR endpoint ID: %u\n",
+ qmi->handle.endpoint_id);
+ if (ret) {
+ ath12k_warn(ab, "failed to query QRTR endpoint ID: %d\n", ret);
+ return ret;
+ }
+
+ return 0;
+}
diff --git a/drivers/net/wireless/ath/ath12k/mhi.h b/drivers/net/wireless/ath/ath12k/mhi.h
index 7358b8477536..c4e00c1747c8 100644
--- a/drivers/net/wireless/ath/ath12k/mhi.h
+++ b/drivers/net/wireless/ath/ath12k/mhi.h
@@ -44,4 +44,6 @@ void ath12k_mhi_clear_vector(struct ath12k_base *ab);
void ath12k_mhi_suspend(struct ath12k_pci *ar_pci);
void ath12k_mhi_resume(struct ath12k_pci *ar_pci);
void ath12k_mhi_coredump(struct mhi_controller *mhi_ctrl, bool in_panic);
+
+int ath12k_mhi_set_qrtr_endpoint_id(struct ath12k_base *ab);
#endif
diff --git a/drivers/net/wireless/ath/ath12k/pci.c b/drivers/net/wireless/ath/ath12k/pci.c
index cf907550e6a4..3d65c64d1b31 100644
--- a/drivers/net/wireless/ath/ath12k/pci.c
+++ b/drivers/net/wireless/ath/ath12k/pci.c
@@ -1514,6 +1514,7 @@ static const struct ath12k_hif_ops ath12k_pci_hif_ops = {
#ifdef CONFIG_ATH12K_COREDUMP
.coredump_download = ath12k_pci_coredump_download,
#endif
+ .set_qrtr_endpoint_id = ath12k_mhi_set_qrtr_endpoint_id,
};
static
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread* [RFC] [PATCH v2 13/13] wifi: ath12k: bind to QRTR endpoint ID in ath12k_qmi_init_service
2024-11-25 3:50 [RFC] [PATCH v2 00/13] ath1{1,2}k: support multiple PCI devices in one system Mihai Moldovan
` (11 preceding siblings ...)
2024-11-25 3:50 ` [RFC] [PATCH v2 12/13] wifi: ath12k: implement QRTR endpoint ID fetching for PCI Mihai Moldovan
@ 2024-11-25 3:50 ` Mihai Moldovan
12 siblings, 0 replies; 14+ messages in thread
From: Mihai Moldovan @ 2024-11-25 3:50 UTC (permalink / raw)
To: ath11k, ath12k, Kalle Valo, Jeff Johnson, Manivannan Sadhasivam
Cc: Bjorn Andersson, Konrad Dybcio, David S . Miller, Eric Dumazet,
Jakub Kicinski, Paolo Abeni, Simon Horman, linux-wireless,
linux-arm-msm, netdev
If possible, fetch the QRTR endpoint ID in ath12k_qmi_init_service, just
before calling qmi_handle_init, and make it available in the qmi_handle.
qmi_helpers will then automatically bind to this endpoint for us.
This finally allows using multiple ath12k-based cards with the same QRTR
node/port combination to work simultanenous (and, for that matter, at
all), including combinations of ath11k-based and ath12k-based cards.
Signed-off-by: Mihai Moldovan <ionic@ionic.de>
Tested-on: WCN7850 hw2.0 PCI WLAN.HMT.1.0.c5-00481-QCAHMTSWPL_V1.0_V2.0_SILICONZ-3
---
drivers/net/wireless/ath/ath12k/qmi.c | 9 +++++++++
1 file changed, 9 insertions(+)
diff --git a/drivers/net/wireless/ath/ath12k/qmi.c b/drivers/net/wireless/ath/ath12k/qmi.c
index d2d9d03c7a28..a96bad490b10 100644
--- a/drivers/net/wireless/ath/ath12k/qmi.c
+++ b/drivers/net/wireless/ath/ath12k/qmi.c
@@ -9,8 +9,10 @@
#include "qmi.h"
#include "core.h"
#include "debug.h"
+#include "hif.h"
#include <linux/of.h>
#include <linux/firmware.h>
+#include <net/sock.h>
#define SLEEP_CLOCK_SELECT_INTERNAL_BIT 0x02
#define HOST_CSTATE_BIT 0x04
@@ -3371,6 +3373,13 @@ int ath12k_qmi_init_service(struct ath12k_base *ab)
ab->qmi.ab = ab;
ab->qmi.target_mem_mode = ATH12K_QMI_TARGET_MEM_MODE_DEFAULT;
+
+ ret = ath12k_hif_set_qrtr_endpoint_id(ab);
+ if (ret) {
+ ath12k_warn(ab, "failed to set QRTR endpoint ID: %d\n", ret);
+ ath12k_warn(ab, "only one device per system will be supported\n");
+ }
+
ret = qmi_handle_init(&ab->qmi.handle, ATH12K_QMI_RESP_LEN_MAX,
&ath12k_qmi_ops, ath12k_qmi_msg_handlers);
if (ret < 0) {
--
2.45.2
^ permalink raw reply related [flat|nested] 14+ messages in thread