In-kernel QMI helpers and sysmon
v3 cover In-kernel QMI helpers and sysmon
This series introduces a helper library for drivers that needs to implement clients or services in the kernel for communicating with QMI encoded messages.
This is used by a set of drivers in order to implement control signaling that needs to happen between a driver and a service on a remote processor, such as the synchronization of states during a remoteproc shutdown/restart; as seen in the sysmon implementation.
Finally a sample driver provides an implementation of the "test" protocol, which is a service typically implemented by Qualcomm remoteproc firmware.
Changes since v2:
- Fix reported typos
- Checkpatch fixes
- Use non-gpl EXPORT_SYMBOL
Changes since v1:
- Lot of modifications to QMI interface, from feedback and implementation and testing of sysmon.
- Added sysmon driver.
- Added patch for remoteproc to pass gracefulness on subdev remove.
- QRTR patches part of v1 was merged separately
Bjorn Andersson (5):
soc: qcom: Introduce QMI encoder/decoder
soc: qcom: Introduce QMI helpers
remoteproc: Pass type of shutdown to subdev remove
remoteproc: qcom: Introduce sysmon
samples: Introduce Qualcomm QMI sample client
drivers/remoteproc/Kconfig | 17 + drivers/remoteproc/Makefile | 1 + drivers/remoteproc/qcom_adsp_pil.c | 12 + drivers/remoteproc/qcom_common.c | 6 +- drivers/remoteproc/qcom_common.h | 21 + drivers/remoteproc/qcom_q6v5_pil.c | 3 + drivers/remoteproc/qcom_sysmon.c | 585 ++++++++++++++++++++++++ drivers/remoteproc/qcom_wcnss.c | 4 + drivers/remoteproc/remoteproc_core.c | 18 +- drivers/soc/qcom/Kconfig | 9 + drivers/soc/qcom/Makefile | 3 + drivers/soc/qcom/qmi_encdec.c | 821 +++++++++++++++++++++++++++++++++ drivers/soc/qcom/qmi_interface.c | 849 +++++++++++++++++++++++++++++++++++ include/linux/remoteproc.h | 4 +- include/linux/soc/qcom/qmi.h | 272 +++++++++++ samples/Kconfig | 9 + samples/Makefile | 2 +- samples/qmi/Makefile | 1 + samples/qmi/qmi_sample_client.c | 631 ++++++++++++++++++++++++++ 19 files changed, 3253 insertions(+), 15 deletions(-) create mode 100644 drivers/remoteproc/qcom_sysmon.c create mode 100644 drivers/soc/qcom/qmi_encdec.c create mode 100644 drivers/soc/qcom/qmi_interface.c create mode 100644 include/linux/soc/qcom/qmi.h create mode 100644 samples/qmi/Makefile create mode 100644 samples/qmi/qmi_sample_client.c
Signature · 1 line
2.15.0
PATCH v3 1/5 soc: qcom: Introduce QMI encoder/decoder
Add the helper library for encoding and decoding QMI encoded messages. The implementation is taken from lib/qmi_encdec.c of the Qualcomm kernel (msm-3.18).
Modifications has been made to the public API, source buffers has been made const and the debug-logging part was omitted, for now.
---
Changes since v2:
- Checkpatch fixes
Changes since v1:
- None
drivers/soc/qcom/Kconfig | 8 + drivers/soc/qcom/Makefile | 2 + drivers/soc/qcom/qmi_encdec.c | 821 ++++++++++++++++++++++++++++++++++++++++++ include/linux/soc/qcom/qmi.h | 115 ++++++ 4 files changed, 946 insertions(+) create mode 100644 drivers/soc/qcom/qmi_encdec.c create mode 100644 include/linux/soc/qcom/qmi.h
drivers/soc/qcom/Kconfig +8 -0
@@ -35,6 +35,14 @@ config QCOM_PM modes. It interface with various system drivers to put the cores in low power modes. +config QCOM_QMI_HELPERS + tristate + help + Helper library for handling QMI encoded messages. QMI encoded + messages are used in communication between the majority of QRTR + clients and this helpers provide the common functionality needed for + doing this from a kernel driver. + config QCOM_SMEM tristate "Qualcomm Shared Memory Manager (SMEM)" depends on ARCH_QCOM
drivers/soc/qcom/Makefile +2 -0
@@ -2,6 +2,8 @@ obj-$(CONFIG_QCOM_GLINK_SSR) += glink_ssr.o obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o obj-$(CONFIG_QCOM_PM) += spm.o +obj-$(CONFIG_QCOM_QMI_HELPERS) += qmi_helpers.o +qmi_helpers-y += qmi_encdec.o obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o obj-$(CONFIG_QCOM_SMEM) += smem.o obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
drivers/soc/qcom/qmi_encdec.c new file +821 -0
821 lines not on this page · raw message
include/linux/soc/qcom/qmi.h new file +115 -0
115 lines not on this page · raw message
Signature · 1 line
2.15.0
Re: [PATCH v3 1/5] soc: qcom: Introduce QMI encoder/decoder
Quoted 1 line · Bjorn Andersson
drivers/soc/qcom/qmi_encdec.c +0
-0
[..]
Quoted 18 lines
drivers/soc/qcom/qmi_encdec.c +18
-0+void *qmi_encode_message (int type,unsigned int msg_id,size_t *len, +unsigned int txn_id,struct qmi_elem_info *ei, +const void *c_struct) +{ +struct qmi_header *hdr; +ssize_t msglen =0 ; +void *msg; +int ret; + +/* Check the possibility of a zero length QMI message */ +if (!c_struct) { + ret =qmi_calc_min_msg_len (ei,1 ); +if (ret) { +pr_err ("%s: Calc. len %d != 0, but NULL c_struct\n" , + __func__, ret); +return ERR_PTR (-EINVAL ); + } + }
drivers/soc/qcom/qmi_encdec.c line 748
Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c +10
-0+ + msg =kzalloc (sizeof (*hdr) + *len,GFP_KERNEL ); +if (!msg) +return ERR_PTR (-ENOMEM ); + + msglen =qmi_encode (ei, msg +sizeof (*hdr), c_struct, *len,1 ); +if (msglen <0 ) { +kfree (msg); +return ERR_PTR (msglen); + }
Talked to Chris Lew about this earlier today;
The check above implies that it's valid to call this function with a valid ei of minimum message length of 0 and c_struct being NULL. But the call to qmi_encdec() will dereference c_struct in order to know that the optional elements described in ei are unset.
So the call to qmi_encode() needs to only be done conditionally on c_struct being non-NULL, logically interpreting c_struct being NULL as all optional fields are unset.
Will post an update with this fixed.
drivers/soc/qcom/qmi_encdec.c line 760
Quoted 12 lines
drivers/soc/qcom/qmi_encdec.c +12
-0+ + hdr = msg; + hdr->type = type; + hdr->txn_id = txn_id; + hdr->msg_id = msg_id; + hdr->msg_len = msglen; + + *len =sizeof (*hdr) + msglen; + +return msg; +} +EXPORT_SYMBOL (qmi_encode_message);
Regards,
Bjorn
Chris Lew
Tested-byRe: [PATCH v3 1/5] soc: qcom: Introduce QMI encoder/decoder
Quoted 39 lines · Bjorn Andersson
Quoted 1 line · Bjorn Andersson
drivers/soc/qcom/qmi_encdec.c +0
-0[..]
Quoted 18 lines
drivers/soc/qcom/qmi_encdec.c +18
-0+void *qmi_encode_message (int type,unsigned int msg_id,size_t *len, +unsigned int txn_id,struct qmi_elem_info *ei, +const void *c_struct) +{ +struct qmi_header *hdr; +ssize_t msglen =0 ; +void *msg; +int ret; + +/* Check the possibility of a zero length QMI message */ +if (!c_struct) { + ret =qmi_calc_min_msg_len (ei,1 ); +if (ret) { +pr_err ("%s: Calc. len %d != 0, but NULL c_struct\n" , + __func__, ret); +return ERR_PTR (-EINVAL ); + } + }drivers/soc/qcom/qmi_encdec.c line 748
Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c +10
-0+ + msg =kzalloc (sizeof (*hdr) + *len,GFP_KERNEL ); +if (!msg) +return ERR_PTR (-ENOMEM ); + + msglen =qmi_encode (ei, msg +sizeof (*hdr), c_struct, *len,1 ); +if (msglen <0 ) { +kfree (msg); +return ERR_PTR (msglen); + }Talked to Chris Lew about this earlier today;
The check above implies that it's valid to call this function with a valid ei of minimum message length of 0 and
c_structbeing NULL. But the call toqmi_encdec()will dereferencec_structin order to know that the optional elements described in ei are unset.
Quoted 6 lines
So the call to
qmi_encode()needs to only be done conditionally onc_structbeing non-NULL, logically interpretingc_structbeing NULL as all optional fields are unset.Will post an update with this fixed.
I have tested this patch with QMI loopback servers, Qualcomm diag and slimbus ngd.
Quoted 16 lines
drivers/soc/qcom/qmi_encdec.c line 760
Quoted 12 lines
drivers/soc/qcom/qmi_encdec.c +12
-0+ + hdr = msg; + hdr->type = type; + hdr->txn_id = txn_id; + hdr->msg_id = msg_id; + hdr->msg_len = msglen; + + *len =sizeof (*hdr) + msglen; + +return msg; +} +EXPORT_SYMBOL (qmi_encode_message);Regards,
Bjorn
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v3 1/5] soc: qcom: Introduce QMI encoder/decoder
In reply to Bjorn AnderssonQuoted 16 lines · Bjorn Andersson
Add the helper library for encoding and decoding QMI encoded messages. The implementation is taken from
lib/qmi_encdec.cof the Qualcomm kernel (msm-3.18).Modifications has been made to the public API, source buffers has been made const and the debug-logging part was omitted, for now.
Signed-off-by Bjorn Andersson <[email protected]>---
Changes since v2:
- Checkpatch fixesChanges since v1:
- None
Quoted 8 lines
drivers/soc/qcom/Kconfig | 8 + drivers/soc/qcom/Makefile | 2 + drivers/soc/qcom/qmi_encdec.c | 821 ++++++++++++++++++++++++++++++++++++++++++ include/linux/soc/qcom/qmi.h | 115 ++++++ 4 files changed, 946 insertions(+)create mode 100644
drivers/soc/qcom/qmi_encdec.ccreate mode 100644include/linux/soc/qcom/qmi.h
I have tested this patch along with slimbus ngd for wcd9335 analog audio
playback.
Few minor comments though!!
drivers/soc/qcom/Kconfig config QCOM_PM · line 38
Quoted 9 lines
drivers/soc/qcom/Kconfig +1
-0@@ -35,6 +35,14 @@ config QCOM_PM modes. It interface with various system drivers to put the cores in low power modes. +config QCOM_QMI_HELPERS
Should'nt this be part of second patch? atleast the patch subject suggests that its just enc/decoder but you are actually adding qmi helper symbol ? Or change the order of the patch.
drivers/soc/qcom/Kconfig config QCOM_PM · line 39
Quoted 1 line
drivers/soc/qcom/Kconfig +1
-0+ tristate
we added help to this symbol but there is no promt text associated with it, so it will not show up as in menuconfig.. may be
tristate "QMI Helpers"
would be better
Quoted 40 lines
drivers/soc/qcom/Kconfig +6
-0+ help + Helper library for handling QMI encoded messages. QMI encoded + messages are used in communication between the majority of QRTR + clients and this helpers provide the common functionality needed for + doing this from a kernel driver. + config QCOM_SMEM tristate "Qualcomm Shared Memory Manager (SMEM)"depends on
ARCH_QCOMdrivers/soc/qcom/Makefile +2
-0@@ -2,6 +2,8 @@ obj-$(CONFIG_QCOM_GLINK_SSR) += glink_ssr.o obj-$(CONFIG_QCOM_GSBI) += qcom_gsbi.o obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o obj-$(CONFIG_QCOM_PM) += spm.o +obj-$(CONFIG_QCOM_QMI_HELPERS) += qmi_helpers.o +qmi_helpers-y += qmi_encdec.o obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o obj-$(CONFIG_QCOM_SMEM) += smem.o obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.odrivers/soc/qcom/qmi_encdec.c new file +11
-0@@ -0,0 +1,821 @@ +/* +* Copyright (c) 2012-2015, The Linux Foundation. All rights reserved. +* Copyright (C) 2017 Linaro Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
drivers/soc/qcom/qmi_encdec.c line 21
Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10
-0+* GNU General Public License for more details. +* +*/ + +#include <linux/slab.h> +#include <linux/uaccess.h> +#include <linux/module.h> +#include <linux/kernel.h> +#include <linux/errno.h> +#include <linux/io.h>
do we need this?
Quoted 6 lines
drivers/soc/qcom/qmi_encdec.c new file +6
-0+#include <linux/string.h> +#include <linux/soc/qcom/qmi.h> +static int qmi_encode (struct qmi_elem_info *ei_array,void *out_buf, +const void *in_c_struct,u32 out_buf_len, +int enc_level); +
drivers/soc/qcom/qmi_encdec.c line 84
Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10
-0+static int qmi_decode (struct qmi_elem_info *ei_array,void *out_c_struct, +const void *in_buf,u32 in_buf_len,int dec_level); + +/** +* skip_to_next_elem() - Skip to next element in the structure to be encoded +* @ei_array: Struct info describing the element to be skipped. +* @level: Depth level of encoding/decoding to identify nested structures. +* +* Returns struct info of the next element that can be encoded. +*
Should be Return: according to Documentation/doc-guide/kernel-doc.rst
Same comment appies to most of the functions..
Quoted 7 lines
drivers/soc/qcom/qmi_encdec.c new file +6
-0+* This function is used while encoding optional elements. If the flag +* corresponding to an optional element is not set, then encoding the +* optional element can be skipped. This function can be used to perform +* that operation. +*/ +static struct qmi_elem_info *skip_to_next_elem(struct qmi_elem_info *ei_array,
drivers/soc/qcom/qmi_encdec.c line 120
Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10
-0+/** +* qmi_decode_string_elem() - Decodes elements of string data type +* @ei_array: Struct info array descibing the string element. +* @buf_dst: Buffer to store the decoded element. +* @buf_src: Buffer containing the elements in QMI wire format. +* @tlv_len: Total size of the encoded inforation corresponding to +* this string element. +* @dec_level: Depth of the string element from the main structure. +* +
bad Line??
Quoted 3 lines
+ * Returns the total size of the decoded data elements on success, negative
+ * errno on error.
+
Dito..
Quoted 15 lines
+ *
+ * This function decodes the string element of maximum length
+ * "ei_array->elem_len" from the source buffer "buf_src" and puts it into
+ * the destination buffer "buf_dst". This function returns number of bytes
+ * decoded from the input buffer.
+ */drivers/soc/qcom/qmi_encdec.c new file +8
-0+static int qmi_decode_string_elem (struct qmi_elem_info *ei_array, +void *buf_dst,const void *buf_src, +u32 tlv_len,int dec_level) +{ +int rc; +int decoded_bytes =0 ; +u32 string_len =0 ; +u32 string_len_sz =0 ;
...
drivers/soc/qcom/qmi_encdec.c line 559
Quoted 5 lines
drivers/soc/qcom/qmi_encdec.c new file +5
-0+ + rc =qmi_decode_basic_elem (buf_dst, buf_src + decoded_bytes, + string_len, temp_ei->elem_size); + *((char *)buf_dst + string_len) ='\0' ; + decoded_bytes += rc;
An empty line here could be nice... same for most of the functions..
Quoted 17 lines
drivers/soc/qcom/qmi_encdec.c new file +4
-0+return decoded_bytes; +} + +MODULE_LICENSE ("GPL v2" );include/linux/soc/qcom/qmi.h new file +7
-0@@ -0,0 +1,115 @@ +/* +* Copyright (c) 2012-2014, The Linux Foundation. All rights reserved. +* Copyright (c) 2017, Linaro Ltd. +* +* This program is free software; you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 2 and +* only version 2 as published by the Free Software Foundation.
include/linux/soc/qcom/qmi.h line 17
Quoted 10 lines
include/linux/soc/qcom/qmi.h new file +10
-0+* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ +#ifndef __QMI_HELPERS_H__ +#define __QMI_HELPERS_H__ + +#include <linux/qrtr.h>
Is this include needed as part of this patch?
Quoted 18 lines
include/linux/soc/qcom/qmi.h new file +17
-0+#include <linux/types.h> + + +enum qmi_array_type { +NO_ARRAY , +STATIC_ARRAY , +VAR_LEN_ARRAY , +}; + +/** +* struct qmi_elem_info - describes how to encode a single QMI element +* @data_type: Data type of this element. +* @elem_len: Array length of this element, if an array. +* @elem_size: Size of a single instance of this data type. +* @is_array: Array type of this element. +* @tlv_type: QMI message specific type to identify which element +* is present in an incoming message.
include/linux/soc/qcom/qmi.h line 77
Quoted 10 lines
include/linux/soc/qcom/qmi.h new file +10
-0+* @offset: Specifies the offset of the first instance of this +* element in the data structure. +* @ei_array: Null-terminated array of @qmi_elem_info to describe nested +* structures. +*/ +struct qmi_elem_info { +enum qmi_elem_type data_type; +u32 elem_len; +u32 elem_size; +enum qmi_array_type is_array;
naming it array_type makes it more readable.
Quoted 4 lines
include/linux/soc/qcom/qmi.h new file +4
-0+u8 tlv_type; +u32 offset; +struct qmi_elem_info *ei_array; +};
...
include/linux/soc/qcom/qmi.h line 113
Quoted 10 lines
include/linux/soc/qcom/qmi.h new file +10
-0+}; + +extern struct qmi_elem_info qmi_response_type_v01_ei[]; + +void *qmi_encode_message (int type,unsigned int msg_id,size_t *len, +unsigned int txn_id,struct qmi_elem_info *ei, +const void *c_struct); + +int qmi_decode_message (const void *buf,size_t len, +struct qmi_elem_info *ei,void *c_struct);
Should we consider adding dummy functions to allow COMPILE_TEST on drivers using this api?
Quoted 3 lines
include/linux/soc/qcom/qmi.h new file +2
-0+ +#endif
Re: [PATCH v3 1/5] soc: qcom: Introduce QMI encoder/decoder
Quoted 1 line · Srinivas Kandagatla
On 15/11/17 20:10, Bjorn Andersson wrote:
[..]
Quoted 12 lines
drivers/soc/qcom/Kconfig config QCOM_PM · line 37
Quoted 8 lines
drivers/soc/qcom/Kconfig +1
-0@@ -35,6 +35,14 @@ config QCOM_PM modes. It interface with various system drivers to put the cores in low power modes. +config QCOM_QMI_HELPERSShould'nt this be part of second patch? atleast the patch subject suggests that its just enc/decoder but you are actually adding qmi helper symbol ? Or change the order of the patch.
The encoder/decoder is, and should be, compilable on its own; so this config option does ensure that the newly added c-file isn't just dead code - although it's unlikely to matter in practice.
I don't see a reason for adding a QCOM_QMI_ENCDEC here and then rename that in the following commit and I don't see a reason to split it in two config options. So I think this is reasonable...
Quoted 8 lines
drivers/soc/qcom/Kconfig config QCOM_PM · line 39
Quoted 1 line
drivers/soc/qcom/Kconfig +1
-0+ tristatewe added help to this symbol but there is no promt text associated with it, so it will not show up as in menuconfig.. may be
tristate "QMI Helpers"
would be better
The idea is that users of these functions would "select" QCOM_QMI_HELPERS.
I don't think there is a particular point in allowing the user to select this without any of the clients and a "depends on" in the client just results in the user being forced to find this option to be able to enable any of the clients.
[..]
Quoted 1 line
Quoted 1 line
drivers/soc/qcom/qmi_encdec.c +0
-0
[..]
Quoted 4 lines
Quoted 1 line
+#include <
linux/io.h>do we need this?
Nope.
[..]
Quoted 8 lines
Quoted 7 lines
+/**
+ *skip_to_next_elem()- Skip to next element in the structure to be encoded
+ * @ei_array: Struct info describing the element to be skipped.
+ * @level: Depth level of encoding/decoding to identify nested structures.
+ *
+ * Returns struct info of the next element that can be encoded.
+ *
Quoted 4 lines
Should be Return: according to
Documentation/doc-guide/kernel-doc.rstSame comment appies to most of the functions..
Thanks, I have been looking for that document! Will update the comments throughout the patch series.
[..]
Quoted 4 lines
Quoted 4 lines
+/**
+ *qmi_decode_string_elem()- Decodes elements of string data type
+ * @ei_array: Struct info array descibing the string element.
+ * @buf_dst: Buffer to store the decoded element.
Quoted 8 lines
Quoted 6 lines
+ * @buf_src: Buffer containing the elements in QMI wire format.
+ * @tlv_len: Total size of the encoded inforation corresponding to
+ * this string element.
+ * @dec_level: Depth of the string element from the main structure.
+ *
+bad Line??
Looks like it.
Quoted 9 lines
Quoted 3 lines
+ * Returns the total size of the decoded data elements on success, negative
+ * errno on error.
+Dito..
Quoted 5 lines
+ *
+ * This function decodes the string element of maximum length
+ * "ei_array->elem_len" from the source buffer "buf_src" and puts it into
+ * the destination buffer "buf_dst". This function returns number of bytes
+ * decoded from the input buffer.
And this should go above the "return" description.
[..]
Quoted 7 lines
drivers/soc/qcom/qmi_encdec.c line 559
Quoted 5 lines
drivers/soc/qcom/qmi_encdec.c +5
-0+ + rc =qmi_decode_basic_elem (buf_dst, buf_src + decoded_bytes, + string_len, temp_ei->elem_size); + *((char *)buf_dst + string_len) ='\0' ; + decoded_bytes += rc;An empty line here could be nice... same for most of the functions..
I agree, I'll run over the file again.
There are a few other style things that I would like to change, e.g. replacing u32 with size_t in a bunch of places; but I also didn't want to change too much from the downstream version.
But fixing the spacing in the initial commit makes sense.
[..]
Quoted 1 line
Quoted 1 line
include/linux/soc/qcom/qmi.h +0
-0
[..]
Quoted 4 lines
Quoted 1 line
+#include <
linux/qrtr.h>Is this include needed as part of this patch?
This should be able to go in the next patch.
Quoted 22 lines
Quoted 22 lines
include/linux/soc/qcom/qmi.h +21
-0+#include <linux/types.h> + + +enum qmi_array_type { +NO_ARRAY , +STATIC_ARRAY , +VAR_LEN_ARRAY , +}; + +/** +* struct qmi_elem_info - describes how to encode a single QMI element +* @data_type: Data type of this element. +* @elem_len: Array length of this element, if an array. +* @elem_size: Size of a single instance of this data type. +* @is_array: Array type of this element. +* @tlv_type: QMI message specific type to identify which element +* is present in an incoming message. +* @offset: Specifies the offset of the first instance of this +* element in the data structure. +* @ei_array: Null-terminated array of @qmi_elem_info to describe nested +* structures.
Quoted 9 lines
include/linux/soc/qcom/qmi.h line 77
Quoted 6 lines
+ */
include/linux/soc/qcom/qmi.h +5
-0+struct qmi_elem_info { +enum qmi_elem_type data_type; +u32 elem_len; +u32 elem_size; +enum qmi_array_type is_array;naming it
array_typemakes it more readable.
Agreed.
[..]
Quoted 6 lines
include/linux/soc/qcom/qmi.h line 113
Quoted 2 lines
include/linux/soc/qcom/qmi.h +2
-0+int qmi_decode_message (const void *buf,size_t len, +struct qmi_elem_info *ei,void *c_struct);Should we consider adding dummy functions to allow
COMPILE_TESTon drivers using this api?
Unfortunately drivers/soc/qcom isn't built unless ARCH_QCOM is set, but I would prefer that we sort that out and have client drivers trigger the build of this as well.
For other drivers I've seen the benefit of Coverity running on the x86 target, so this would be nice to do here too.
Thanks for the review!
Regards,
Bjorn
PATCH v3 2/5 soc: qcom: Introduce QMI helpers
In reply to Bjorn AnderssonDrivers that needs to communicate with a remote QMI service all has to perform the operations of discovering the service, encoding and decoding the messages and operate the socket. This introduces an abstraction for these common operations, reducing most of the duplication in such cases.
---
Changes since v2:
- Fix typos
- Checkpatch fixes
- Use non-GPL EXPORT_SYMBOL
Changes since v1:
- Squashed notion of qmi vs qrtr in interface, to simplify client code
- Lookup and service registration is cached and handled by core on ENETRESET
- Introduce callbacks for BYE and DEL_CLIENT control messages
- Revisited locking for socket and transaction objects, squashed a few races and made it possible to send "indication" messages from message handlers.
- kerneldoc updates
- Moved handling of net_reset from clients to this code, greatly simplifies typical drivers and reduces duplication
- Pass transaction id of QMI message to handlers even though it's not a response, allows sending a response with the txn id of an incoming request.
- Split qmi_send_message() in three, instead of passing type as parameter - to clean up handling of "indication" messages.
drivers/soc/qcom/Kconfig | 1 + drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/qmi_interface.c | 849 +++++++++++++++++++++++++++++++++++++++ include/linux/soc/qcom/qmi.h | 157 ++++++++ 4 files changed, 1008 insertions(+) create mode 100644 drivers/soc/qcom/qmi_interface.c
drivers/soc/qcom/Kconfig +1 -0
@@ -37,6 +37,7 @@ config QCOM_PM config QCOM_QMI_HELPERS tristate + depends on ARCH_QCOM help Helper library for handling QMI encoded messages. QMI encoded messages are used in communication between the majority of QRTR
drivers/soc/qcom/Makefile +1 -0
@@ -4,6 +4,7 @@ obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o obj-$(CONFIG_QCOM_PM) += spm.o obj-$(CONFIG_QCOM_QMI_HELPERS) += qmi_helpers.o qmi_helpers-y += qmi_encdec.o +qmi_helpers-y += qmi_interface.o obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o obj-$(CONFIG_QCOM_SMEM) += smem.o obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.o
drivers/soc/qcom/qmi_interface.c new file +849 -0
849 lines not on this page · raw message
include/linux/soc/qcom/qmi.h +157 -0
167 lines not on this page · raw message
Signature · 1 line
2.15.0
Re: [PATCH v3 2/5] soc: qcom: Introduce QMI helpers
Quoted 27 lines · Bjorn Andersson
Drivers that needs to communicate with a remote QMI service all has to perform the operations of discovering the service, encoding and decoding the messages and operate the socket. This introduces an abstraction for these common operations, reducing most of the duplication in such cases.
Signed-off-by Bjorn Andersson <[email protected]>---
Changes since v2:
- Fix typos
- Checkpatch fixes
- Use non-GPLEXPORT_SYMBOLChanges since v1:
- Squashed notion of qmi vs qrtr in interface, to simplify client code
- Lookup and service registration is cached and handled by core on ENETRESET
- Introduce callbacks for BYE andDEL_CLIENTcontrol messages
- Revisited locking for socket and transaction objects, squashed a few races and made it possible to send "indication" messages from message handlers.
- kerneldoc updates
- Moved handling ofnet_resetfrom clients to this code, greatly simplifies typical drivers and reduces duplication
- Pass transaction id of QMI message to handlers even though it's not a response, allows sending a response with the txn id of an incoming request.
- Splitqmi_send_message()in three, instead of passing type as parameter - to clean up handling of "indication" messages.
Quoted 7 lines
drivers/soc/qcom/Kconfig | 1 + drivers/soc/qcom/Makefile | 1 + drivers/soc/qcom/qmi_interface.c | 849 +++++++++++++++++++++++++++++++++++++++ include/linux/soc/qcom/qmi.h | 157 ++++++++ 4 files changed, 1008 insertions(+)create mode 100644
drivers/soc/qcom/qmi_interface.c
I have tested this patch along with slimbus ngd for wcd9335 analog audio
playback.
Few minor comments though!!
drivers/soc/qcom/Kconfig config QCOM_PM · line 40
Quoted 9 lines
drivers/soc/qcom/Kconfig +1
-0@@ -37,6 +37,7 @@ config QCOM_PM config QCOM_QMI_HELPERS tristate + depends on ARCH_QCOM
This bit is confusing!!, first patch added this symbol and this patch added the depends. either we move this to first patch or move out the QCOM_QMI_HELPERS from first patch and include in this patch
drivers/soc/qcom/Makefile obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o · line 7
Quoted 12 lines
drivers/soc/qcom/Kconfig +0
-0help Helper library for handling QMI encoded messages. QMI encoded messages are used in communication between the majority of QRTRdrivers/soc/qcom/Makefile +1
-0@@ -4,6 +4,7 @@ obj-$(CONFIG_QCOM_MDT_LOADER) += mdt_loader.o obj-$(CONFIG_QCOM_PM) += spm.o obj-$(CONFIG_QCOM_QMI_HELPERS) += qmi_helpers.o qmi_helpers-y += qmi_encdec.o +qmi_helpers-y += qmi_interface.o
for better reading.. i would suggest..
qmi_helpers-y += qmi_encdec.o qmi_interface.o
Quoted 16 lines
drivers/soc/qcom/Makefile +0
-0obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o obj-$(CONFIG_QCOM_SMEM) += smem.o obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.odrivers/soc/qcom/qmi_interface.c new file +7
-0@@ -0,0 +1,849 @@ +/* +* Copyright (C) 2017 Linaro Ltd. +* +* This software is licensed under the terms of the GNU General Public +* License version 2, as published by the Free Software Foundation, and +* may be copied, distributed, and modified under those terms. +*
drivers/soc/qcom/qmi_interface.c line 17
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10
-0+* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +*/ + +#include <linux/kernel.h> +#include <linux/module.h> +#include <linux/device.h> +#include <linux/platform_device.h>
Do we need this?
Quoted 8 lines
drivers/soc/qcom/qmi_interface.c new file +8
-0+#include <linux/qrtr.h> +#include <linux/net.h> +#include <linux/completion.h> +#include <linux/idr.h> +#include <linux/string.h> +#include <net/sock.h> +#include <linux/workqueue.h> +#include <linux/soc/qcom/qmi.h>
drivers/soc/qcom/qmi_interface.c line 35
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10
-0+ +static struct socket *qmi_sock_create (struct qmi_handle *qmi, +struct sockaddr_qrtr *sq); + +/** +* qmi_recv_new_server() - handler of NEW_SERVER control message +* @qmi: qmi handle +* @node: node of the new server +* @port: port of the new server +*
service and instance is not documented here.
Quoted 9 lines
drivers/soc/qcom/qmi_interface.c new file +9
-0+ * Calls the new_server callback to inform the client about + msg.msg_name = &sq; + msg.msg_namelen =sizeof (sq); + +mutex_lock (&qmi->sock_lock); +if (qmi->sock) { + ret =kernel_sendmsg (qmi->sock, &msg, &iv,1 ,sizeof (pkt)); +if (ret <0 ) +pr_err ("failed to send lookup registration: %d\n" , ret);
drivers/soc/qcom/qmi_interface.c line 206
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10
-0+ } +mutex_unlock (&qmi->sock_lock); +} + +/** +* qmi_add_lookup() - register a new lookup with the name service +* @qmi: qmi handle +* @service: service id of the request +* @instance: instance id of the request +*
version not documented.
Quoted 22 lines
drivers/soc/qcom/qmi_interface.c new file +22
-0+* Returns 0 on success, negative errno on failure. +* +* Registering a lookup query with the name server will cause the name server +* to send NEW_SERVER and DEL_SERVER control messages to this socket as +* matching services are registered. +*/ +int qmi_add_lookup (struct qmi_handle *qmi,unsigned int service, +unsigned int version,unsigned int instance) +{ +struct qmi_service *svc; + + svc =kzalloc (sizeof (*svc),GFP_KERNEL ); +if (!svc) +return -ENOMEM ; + + svc->service = service; + svc->version = version; + svc->instance = instance; + +list_add (&svc->list_node, &qmi->lookups); + +qmi_send_new_lookup (qmi, svc);
drivers/soc/qcom/qmi_interface.c line 270
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10
-0+ +return 0 ; +} +EXPORT_SYMBOL (qmi_add_lookup); +** + * qmi_add_server() - register a service with the name service + * @qmi: qmi handle + * @service: type of the service + * @instance: instance of the service + *
version not documented.
Quoted 33 lines
drivers/soc/qcom/qmi_interface.c new file +33
-0+* Returns 0 on success, negative errno on failure. +* +* Register a new service with the name service. This allows clients to find +* and start sending messages to the client associated with @qmi. +*/ +int qmi_add_server (struct qmi_handle *qmi,unsigned int service, +unsigned int version,unsigned int instance) +{ +struct qmi_service *svc; + + svc =kzalloc (sizeof (*svc),GFP_KERNEL ); +if (!svc) +return -ENOMEM ; + +static struct socket *qmi_sock_create (struct qmi_handle *qmi, +struct sockaddr_qrtr *sq) +{ +struct socket *sock; +int sl =sizeof (*sq); +int ret; + + ret =sock_create_kern (&init_net,AF_QIPCRTR ,SOCK_DGRAM , +PF_QIPCRTR , &sock); +if (ret <0 ) +return ERR_PTR (ret); + + ret =kernel_getsockname (sock, (struct sockaddr *)sq, &sl); +if (ret <0 ) { +sock_release (sock); +return ERR_PTR (ret); + } + + sock->sk->sk_user_data = qmi;
drivers/soc/qcom/qmi_interface.c line 615
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10
-0+ sock->sk->sk_data_ready = qmi_data_ready; + sock->sk->sk_error_report = qmi_data_ready; + +return sock; +} + +/** +* qmi_handle_init() - initialize a QMI client handle +* @qmi: QMI handle to initialize +* @max_msg_len: maximum size of incoming message
do we need this??
drivers/soc/qcom/qmi_interface.c line 131
Quoted 2 lines
drivers/soc/qcom/qmi_interface.c new file +2
-0+* @handlers: NULL-terminated list of QMI message handlers +*
recv_buf_size and ops not documented
Quoted 11 lines
drivers/soc/qcom/qmi_interface.c new file +10
-0+* Returns 0 on success, negative errno on failure. +* +* This initializes the QMI client handle to allow sending and receiving QMI +* messages. As messages are received the appropriate handler will be invoked. +*/ +int qmi_handle_init (struct qmi_handle *qmi,size_t recv_buf_size, +struct qmi_ops *ops,struct qmi_msg_handler *handlers) +{ +int ret; +
.....
Quoted 5 lines
+ */
drivers/soc/qcom/qmi_interface.c new file +4
-0+ssize_t qmi_send_response (struct qmi_handle *qmi,struct sockaddr_qrtr *sq, +struct qmi_txn *txn,int msg_id,size_t len, +struct qmi_elem_info *ei,const void *c_struct) +{
drivers/soc/qcom/qmi_interface.c line 821
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10
-0+return qmi_send_message (qmi, sq, txn,QMI_RESPONSE , msg_id, len, ei, + c_struct); +} +EXPORT_SYMBOL (qmi_send_response); + +/** +* qmi_send_indication() - send an indication QMI message +* @qmi: QMI client handle +* @sq: destination sockaddr +* @txn: transaction object to use for the message
txn is not required here?
Quoted 13 lines
+ * @msg_id: message id
+ * @len: max length of the QMI message
+ * @ei: QMI message description
+ * @c_struct: object to be encoded
+ *
+ * Returns 0 on success, negative errno on failure.
+ */drivers/soc/qcom/qmi_interface.c new file +6
-0+ssize_t qmi_send_indication (struct qmi_handle *qmi,struct sockaddr_qrtr *sq, +int msg_id,size_t len,struct qmi_elem_info *ei, +const void *c_struct) +{ +struct qmi_txn txn; +ssize_t rval;
...
include/linux/soc/qcom/qmi.h
Quoted 4 lines
include/linux/soc/qcom/qmi.h +0
-0
Looks like this patch added few things like list, wq and so to this header file, should we not add headers for those ??
Quoted 4 lines
include/linux/soc/qcom/qmi.h +0
-0@@ -105,6 +105,158 @@ struct qmi_response_type_v01 {extern struct qmi_elem_info qmi_response_type_v01_ei[];
..
Quoted 47 lines
include/linux/soc/qcom/qmi.h +43
-0+struct qmi_handle { +struct socket *sock; +struct mutex sock_lock; + +struct sockaddr_qrtr sq; + +struct work_struct work; +struct workqueue_struct *wq; + +void *recv_buf; +size_t recv_buf_size; + +struct list_head lookups; +struct list_head lookup_results; +struct list_head services; + +struct qmi_ops ops; + +struct idr txns; +struct mutex txn_lock; + +struct qmi_msg_handler *handlers; +}; + +int qmi_add_lookup (struct qmi_handle *qmi,unsigned int service, +unsigned int version,unsigned int instance); +int qmi_add_server (struct qmi_handle *qmi,unsigned int service, +unsigned int version,unsigned int instance); + +int qmi_handle_init (struct qmi_handle *qmi,size_t max_msg_len, +struct qmi_ops *ops,struct qmi_msg_handler *handlers); +void qmi_handle_release (struct qmi_handle *qmi); + +ssize_t qmi_send_request (struct qmi_handle *qmi,struct sockaddr_qrtr *sq, +struct qmi_txn *txn,int msg_id,size_t len, +struct qmi_elem_info *ei,const void *c_struct); +ssize_t qmi_send_response (struct qmi_handle *qmi,struct sockaddr_qrtr *sq, +struct qmi_txn *txn,int msg_id,size_t len, +struct qmi_elem_info *ei,const void *c_struct); +ssize_t qmi_send_indication (struct qmi_handle *qmi,struct sockaddr_qrtr *sq, +int msg_id,size_t len,struct qmi_elem_info *ei, +const void *c_struct); +void *qmi_encode_message (int type,unsigned int msg_id,size_t *len,unsigned int txn_id,struct qmi_elem_info *ei,const void *c_struct);
include/linux/soc/qcom/qmi.h void *qmi_encode_message(int type, unsigned int msg_id, size_t *len, · line 270
Quoted 7 lines
include/linux/soc/qcom/qmi.h +4
-0@@ -112,4 +264,9 @@ void *qmi_encode_message(int type, unsigned int msg_id, size_t *len,int qmi_decode_message (const void *buf,size_t len,struct qmi_elem_info *ei,void *c_struct); +int qmi_txn_init (struct qmi_handle *qmi,struct qmi_txn *txn, +struct qmi_elem_info *ei,void *c_struct); +int qmi_txn_wait (struct qmi_txn *txn,unsigned long timeout); +void qmi_txn_cancel (struct qmi_txn *txn);
Same comment as first patch, should we consider adding dummy functions to facilitate COMPILE_TEST for drivers using this apis?
Quoted 3 lines
include/linux/soc/qcom/qmi.h +1
-0+#endif
Re: [PATCH v3 2/5] soc: qcom: Introduce QMI helpers
Quoted 1 line · Srinivas Kandagatla
On 15/11/17 20:10, Bjorn Andersson wrote:
[..]
Quoted 4 lines
Quoted 4 lines
drivers/soc/qcom/Kconfig +0
-0
Quoted 9 lines
drivers/soc/qcom/Kconfig config QCOM_PM · line 39
Quoted 4 lines
drivers/soc/qcom/Kconfig +1
-0@@ -37,6 +37,7 @@ config QCOM_PM config QCOM_QMI_HELPERS tristate + depends on ARCH_QCOMThis bit is confusing!!, first patch added this symbol and this patch added the depends. either we move this to first patch or move out the
QCOM_QMI_HELPERSfrom first patch and include in this patch
Ohh, that's not right. The depends should be in the same patch.
And we don't really depends on ARCH_QCOM here, but without it Kconfig doesn't know that make won't enter drivers/soc/qcom so we will end up with a link error. I'm hoping we can fix this issue, to get some more compile testing of these things.
Quoted 4 lines
Quoted 4 lines
drivers/soc/qcom/Kconfig +0
-0help Helper library for handling QMI encoded messages. QMI encoded messages are used in communication between the majority of QRTRdrivers/soc/qcom/Makefile +0
-0
[..]
Quoted 6 lines
Quoted 3 lines
obj-$(CONFIG_QCOM_QMI_HELPERS) += qmi_helpers.o
qmi_helpers-y += qmi_encdec.o
+qmi_helpers-y += qmi_interface.ofor better reading.. i would suggest..
qmi_helpers-y += qmi_encdec.o qmi_interface.o
Sounds reasonable.
Quoted 5 lines
Quoted 5 lines
obj-$(CONFIG_QCOM_SMD_RPM) += smd-rpm.o obj-$(CONFIG_QCOM_SMEM) += smem.o obj-$(CONFIG_QCOM_SMEM_STATE) += smem_state.odrivers/soc/qcom/qmi_interface.c +0
-0
[..]
Quoted 4 lines
Quoted 1 line
+#include <
linux/platform_device.h>Do we need this?
I don't think so.
[..]
Quoted 8 lines
Quoted 6 lines
+/**
+ *qmi_recv_new_server()- handler ofNEW_SERVERcontrol message
+ * @qmi: qmi handle
+ * @node: node of the new server
+ * @port: port of the new server
+ *service and instance is not documented here.
Thanks for noticing, will fix these.
[..]
Quoted 6 lines
Quoted 4 lines
+/**
+ *qmi_handle_init()- initialize a QMI client handle
+ * @qmi: QMI handle to initialize
+ * @max_msg_len: maximum size of incoming messagedo we need this??
We need a buffer into which we can receive incoming packets, so either we allocate a large enough buffer up front or we have to ask qrtr before each packet how much space we will need.
I think largest possible buffer is 64kB, but typically we need much less. And the IDL compiler seems to output this constant, so it seems reasonable to pass it here.
Quoted 5 lines
Quoted 3 lines
+ * @handlers: NULL-terminated list of QMI message handlers
+ *
recv_buf_sizeand ops not documented
Looks like I've renamed max_msg_len to recv_buf_size, and forgot to add ops. Will fix.
[..]
Quoted 9 lines
drivers/soc/qcom/qmi_interface.c line 821
Quoted 6 lines
drivers/soc/qcom/qmi_interface.c +6
-0+ +/** +* qmi_send_indication() - send an indication QMI message +* @qmi: QMI client handle +* @sq: destination sockaddr +* @txn: transaction object to use for the message txn is not required here?
No. Indications are fire-and-forget messages, but still need a transaction id, so it's confusing for the client to have to create a txn, use it and then cancel it (or to add another txn operation for this). Therefor I'm hiding the txn handling inside this function.
Will fix the kerneldoc.
[..]
Quoted 8 lines
include/linux/soc/qcom/qmi.h
Quoted 4 lines
include/linux/soc/qcom/qmi.h +0
-0Looks like this patch added few things like list, wq and so to this header file, should we not add headers for those ??
Will review these.
Thanks for the review!
Regards,
Bjorn
Re: [PATCH v3 2/5] soc: qcom: Introduce QMI helpers
In reply to Bjorn AnderssonOn 11/15/2017 12:10 PM, Bjorn Andersson wrote:
[..]> +static void qmi_handle_message(struct qmi_handle *qmi,
Quoted 33 lines
drivers/soc/qcom/qmi_interface.c new file +33
-0+struct sockaddr_qrtr *sq, + const void *buf, size_t len) +{ + const struct qmi_header *hdr; +struct qmi_txn tmp_txn; +struct qmi_txn *txn =NULL ; +int ret; + +if (len <sizeof (*hdr)) { +pr_err ("ignoring short QMI packet\n" ); +return ; + } + + hdr = buf; + +/* If this is a response, find the matching transaction handle */ +if (hdr->type ==QMI_RESPONSE ) { +mutex_lock (&qmi->txn_lock); + txn =idr_find (&qmi->txns, hdr->txn_id); +if (txn) +mutex_lock (&txn->lock); +mutex_unlock (&qmi->txn_lock); + } + +if (txn && txn->dest && txn->ei) { + ret =qmi_decode_message (buf, len, txn->ei, txn->dest); +if (ret <0 ) +pr_err ("failed to decode incoming message\n" ); + + txn->result = ret; +complete (&txn->completion); + +mutex_unlock (&txn->lock);
drivers/soc/qcom/qmi_interface.c line 523
Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10
-0+ }else if (txn) { +qmi_invoke_handler (qmi, sq, txn, buf, len); + +mutex_unlock (&txn->lock); + }else { +/* Create a txn based on the txn_id of the incoming message */ +memset (&tmp_txn,0 ,sizeof (tmp_txn)); + tmp_txn.id = hdr->txn_id; + +qmi_invoke_handler (qmi, sq, &tmp_txn, buf, len);
I'm seeing an opportunity for user error with timed out transactions. If txn_wait gets timed out the txn is removed from the txns list. Later if we get the response, it comes down to this else with the tmp_txn. Some handlers may try to do a complete(&txn->completion) like the qmi_sample_client ping_pong_cb. This leads to a null pointer dereference since the temp txn was never initialized.
Should clients not call complete and we can call the complete in the else if(txn) condition?
Thanks,
Chris
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v3 2/5] soc: qcom: Introduce QMI helpers
Quoted 44 lines · Chris Lew
On 11/15/2017 12:10 PM, Bjorn Andersson wrote:
[..]> +static void qmi_handle_message(structqmi_handle*qmi,Quoted 42 lines
drivers/soc/qcom/qmi_interface.c new file +42
-0+struct sockaddr_qrtr *sq, + const void *buf, size_t len) +{ + const struct qmi_header *hdr; +struct qmi_txn tmp_txn; +struct qmi_txn *txn =NULL ; +int ret; + +if (len <sizeof (*hdr)) { +pr_err ("ignoring short QMI packet\n" ); +return ; + } + + hdr = buf; + +/* If this is a response, find the matching transaction handle */ +if (hdr->type ==QMI_RESPONSE ) { +mutex_lock (&qmi->txn_lock); + txn =idr_find (&qmi->txns, hdr->txn_id); +if (txn) +mutex_lock (&txn->lock); +mutex_unlock (&qmi->txn_lock); + } + +if (txn && txn->dest && txn->ei) { + ret =qmi_decode_message (buf, len, txn->ei, txn->dest); +if (ret <0 ) +pr_err ("failed to decode incoming message\n" ); + + txn->result = ret; +complete (&txn->completion); + +mutex_unlock (&txn->lock); + }else if (txn) { +qmi_invoke_handler (qmi, sq, txn, buf, len); + +mutex_unlock (&txn->lock); + }else { +/* Create a txn based on the txn_id of the incoming message */ +memset (&tmp_txn,0 ,sizeof (tmp_txn)); + tmp_txn.id = hdr->txn_id; +
Quoted 9 lines
drivers/soc/qcom/qmi_interface.c line 523
Quoted 1 line
drivers/soc/qcom/qmi_interface.c new file +1
-0+qmi_invoke_handler (qmi, sq, &tmp_txn, buf, len);I'm seeing an opportunity for user error with timed out transactions. If
txn_waitgets timed out the txn is removed from the txns list. Later if we get the response, it comes down to this else with thetmp_txn. Some handlers may try to do acomplete(&txn->completion)like theqmi_sample_clientping_pong_cb. This leads to a null pointer dereference since the temp txn was never initialized.
You're right, that's no good.
Quoted 3 lines
Should clients not call complete and we can call the complete in the else if(txn) condition?
I don't think the problem is limited to the completion. A typical design pattern for these things could be to wrap the txn in a struct and use container_of() in the response handler to access or fill in additional information. If the txn in this scenario happens to be the temporal one we've just messed up the stack.
The else statement was added to deal with requests and indications. The case I can think of where this would make sense is for a client to send a request but not wait for the result and then have some logic to happen once the response arrives (but unrelated to the requesting context).
The quick solution would be to not allow this to happen, i.e. only take the else block if it's a request or a indication. The alternative is to allow the response-handler to know if it was called from the else-statement, but that would mean that every response-handler would have to check this.
Regards,
Bjorn
PATCH v3 3/5 remoteproc: Pass type of shutdown to subdev remove
In reply to Bjorn Anderssonremoteproc instances can be stopped either by invoking shutdown or by an attempt to recover from a crash. For some subdev types it's expected to clean up gracefully during a shutdown, but are unable to do so during a crash - so pass this information to the subdev remove functions.
---
Changes since v2:
- None
Changes since v1:
- New patch
drivers/remoteproc/qcom_common.c | 6 +++--- drivers/remoteproc/remoteproc_core.c | 18 +++++++++--------- include/linux/remoteproc.h | 4 ++-- 3 files changed, 14 insertions(+), 14 deletions(-)
drivers/remoteproc/qcom_common.c +3 -3
@@ -60,7 +60,7 @@ static int glink_subdev_probe(struct rproc_subdev *subdev)return IS_ERR (glink->edge) ?PTR_ERR (glink->edge) :0 ; } -static void glink_subdev_remove (struct rproc_subdev *subdev) +static void glink_subdev_remove (struct rproc_subdev *subdev,bool graceful) {struct qcom_rproc_glink *glink =to_glink_subdev (subdev);
@@ -107,7 +107,7 @@ static int smd_subdev_probe(struct rproc_subdev *subdev)return PTR_ERR_OR_ZERO (smd->edge); } -static void smd_subdev_remove (struct rproc_subdev *subdev) +static void smd_subdev_remove (struct rproc_subdev *subdev,bool graceful) {struct qcom_rproc_subdev *smd =to_smd_subdev (subdev);
@@ -176,7 +176,7 @@ static int ssr_notify_start(struct rproc_subdev *subdev)return 0 ; } -static void ssr_notify_stop (struct rproc_subdev *subdev) +static void ssr_notify_stop (struct rproc_subdev *subdev,bool graceful) {struct qcom_rproc_ssr *ssr =to_ssr_subdev (subdev);
drivers/remoteproc/remoteproc_core.c +9 -9
@@ -307,7 +307,7 @@ static int rproc_vdev_do_probe(struct rproc_subdev *subdev)return rproc_add_virtio_dev (rvdev, rvdev->id); } -static void rproc_vdev_do_remove (struct rproc_subdev *subdev) +static void rproc_vdev_do_remove (struct rproc_subdev *subdev,bool graceful) { struct rproc_vdev *rvdev = container_of(subdev, struct rproc_vdev, subdev);
@@ -785,17 +785,17 @@ static int rproc_probe_subdevices(struct rproc *rproc) unroll_registration:list_for_each_entry_continue_reverse (subdev, &rproc->subdevs, node) - subdev->remove (subdev); + subdev->remove (subdev, false);return ret; } -static void rproc_remove_subdevices (struct rproc *rproc) +static void rproc_remove_subdevices (struct rproc *rproc,bool graceful) {struct rproc_subdev *subdev;list_for_each_entry_reverse (subdev, &rproc->subdevs, node) - subdev->remove (subdev); + subdev->remove (subdev, graceful); }/**
@@ -1013,13 +1013,13 @@ static int rproc_trigger_auto_boot(struct rproc *rproc)return ret; } -static int rproc_stop (struct rproc *rproc) +static int rproc_stop (struct rproc *rproc,bool graceful) {struct device *dev = &rproc->dev;int ret;/* remove any subdevices for the remote processor */ -rproc_remove_subdevices (rproc); +rproc_remove_subdevices (rproc, graceful);/* power off the remote processor */ ret = rproc->ops->stop (rproc);
@@ -1063,7 +1063,7 @@ int rproc_trigger_recovery(struct rproc *rproc)if (ret)return ret; - ret =rproc_stop (rproc); + ret =rproc_stop (rproc, false);if (ret) goto unlock_mutex;
@@ -1216,7 +1216,7 @@ void rproc_shutdown(struct rproc *rproc)if (!atomic_dec_and_test (&rproc->power)) goto out; - ret =rproc_stop (rproc); + ret =rproc_stop (rproc, true);if (ret) {atomic_inc (&rproc->power); goto out;
@@ -1550,7 +1550,7 @@ EXPORT_SYMBOL(rproc_del);void rproc_add_subdev (struct rproc *rproc,struct rproc_subdev *subdev,int (*probe)(struct rproc_subdev *subdev), -void (*remove)(struct rproc_subdev *subdev)) +void (*remove)(struct rproc_subdev *subdev,bool graceful)) { subdev->probe = probe; subdev->remove = remove;
include/linux/remoteproc.h +2 -2
@@ -456,7 +456,7 @@ struct rproc_subdev {struct list_head node;int (*probe)(struct rproc_subdev *subdev); -void (*remove)(struct rproc_subdev *subdev); +void (*remove)(struct rproc_subdev *subdev,bool graceful); };/* we currently support only two vrings per rvdev */
@@ -539,7 +539,7 @@ static inline struct rproc *vdev_to_rproc(struct virtio_device *vdev)void rproc_add_subdev (struct rproc *rproc,struct rproc_subdev *subdev,int (*probe)(struct rproc_subdev *subdev), -void (*remove)(struct rproc_subdev *subdev)); +void (*remove)(struct rproc_subdev *subdev,bool graceful));void rproc_remove_subdev (struct rproc *rproc,struct rproc_subdev *subdev);
Signature · 1 line
2.15.0
PATCH v3 4/5 remoteproc: qcom: Introduce sysmon
In reply to Bjorn AnderssonThe sysmon client communicates either via a dedicated SMD/GLINK channel or via QMI encoded messages over IPCROUTER with remote processors in order to perform graceful shutdown and inform about other remote processors shutting down.
---
Changes since v2:
- Checkpatch fixes
Changes since v1:
- New patch
drivers/remoteproc/Kconfig | 17 ++ drivers/remoteproc/Makefile | 1 + drivers/remoteproc/qcom_adsp_pil.c | 12 + drivers/remoteproc/qcom_common.h | 21 ++ drivers/remoteproc/qcom_q6v5_pil.c | 3 + drivers/remoteproc/qcom_sysmon.c | 585 +++++++++++++++++++++++++++++++++++++ drivers/remoteproc/qcom_wcnss.c | 4 + 7 files changed, 643 insertions(+) create mode 100644 drivers/remoteproc/qcom_sysmon.c
drivers/remoteproc/Kconfig +17 -0
@@ -93,6 +93,7 @@ config QCOM_ADSP_PIL depends on QCOM_SMEM depends on RPMSG_QCOM_SMD || (COMPILE_TEST && RPMSG_QCOM_SMD=n) depends on RPMSG_QCOM_GLINK_SMEM || RPMSG_QCOM_GLINK_SMEM=n + depends on QCOM_SYSMON || QCOM_SYSMON=n select MFD_SYSCON select QCOM_MDT_LOADER select QCOM_RPROC_COMMON
@@ -109,6 +110,7 @@ config QCOM_Q6V5_PIL depends on OF && ARCH_QCOM depends on QCOM_SMEM depends on RPMSG_QCOM_SMD || (COMPILE_TEST && RPMSG_QCOM_SMD=n) + depends on QCOM_SYSMON || QCOM_SYSMON=n select MFD_SYSCON select QCOM_RPROC_COMMON select QCOM_SCM
@@ -116,11 +118,26 @@ config QCOM_Q6V5_PIL Say y here to support the Qualcomm Peripherial Image Loader for the Hexagon V5 based remote processors. +config QCOM_SYSMON + tristate "Qualcomm sysmon driver" + depends on RPMSG + depends on ARCH_QCOM + select QCOM_QMI_HELPERS + help + The sysmon driver implements a sysmon QMI client and a handler for + the sys_mon SMD and GLINK channel, which are used for graceful + shutdown, retrieving failure information and propagating information + about other subsystems being shut down. + + Say y here if your system runs firmware on any other subsystems, e.g. + modem or DSP. + config QCOM_WCNSS_PIL tristate "Qualcomm WCNSS Peripheral Image Loader" depends on OF && ARCH_QCOM depends on RPMSG_QCOM_SMD || (COMPILE_TEST && RPMSG_QCOM_SMD=n) depends on QCOM_SMEM + depends on QCOM_SYSMON || QCOM_SYSMON=n select QCOM_MDT_LOADER select QCOM_RPROC_COMMON select QCOM_SCM
drivers/remoteproc/Makefile +1 -0
@@ -16,6 +16,7 @@ obj-$(CONFIG_KEYSTONE_REMOTEPROC) += keystone_remoteproc.o obj-$(CONFIG_QCOM_ADSP_PIL) += qcom_adsp_pil.o obj-$(CONFIG_QCOM_RPROC_COMMON) += qcom_common.o obj-$(CONFIG_QCOM_Q6V5_PIL) += qcom_q6v5_pil.o +obj-$(CONFIG_QCOM_SYSMON) += qcom_sysmon.o obj-$(CONFIG_QCOM_WCNSS_PIL) += qcom_wcnss_pil.o qcom_wcnss_pil-y += qcom_wcnss.o qcom_wcnss_pil-y += qcom_wcnss_iris.o
drivers/remoteproc/qcom_adsp_pil.c +12 -0
@@ -38,7 +38,10 @@ struct adsp_data {const char *firmware_name;int pas_id;bool has_aggre2_clk; +const char *ssr_name; +const char *sysmon_name; +int ssctl_id; };struct qcom_adsp {
@@ -75,6 +78,7 @@ struct qcom_adsp {struct qcom_rproc_glink glink_subdev;struct qcom_rproc_subdev smd_subdev;struct qcom_rproc_ssr ssr_subdev; +struct qcom_sysmon *sysmon; };static int adsp_load (struct rproc *rproc,const struct firmware *fw)
@@ -404,6 +408,9 @@ static int adsp_probe(struct platform_device *pdev)qcom_add_glink_subdev (rproc, &adsp->glink_subdev);qcom_add_smd_subdev (rproc, &adsp->smd_subdev);qcom_add_ssr_subdev (rproc, &adsp->ssr_subdev, desc->ssr_name); + adsp->sysmon =qcom_add_sysmon_subdev (rproc, + desc->sysmon_name, + desc->ssctl_id); ret =rproc_add (rproc);if (ret)
@@ -425,6 +432,7 @@ static int adsp_remove(struct platform_device *pdev)rproc_del (adsp->rproc);qcom_remove_glink_subdev (adsp->rproc, &adsp->glink_subdev); +qcom_remove_sysmon_subdev (adsp->sysmon);qcom_remove_smd_subdev (adsp->rproc, &adsp->smd_subdev);qcom_remove_ssr_subdev (adsp->rproc, &adsp->ssr_subdev);rproc_free (adsp->rproc);
@@ -438,6 +446,8 @@ static const struct adsp_data adsp_resource_init = { .pas_id = 1, .has_aggre2_clk = false, .ssr_name = "lpass", + .sysmon_name = "adsp", + .ssctl_id = 0x14, };static const struct adsp_data slpi_resource_init = {
@@ -446,6 +456,8 @@ static const struct adsp_data slpi_resource_init = { .pas_id = 12, .has_aggre2_clk = true, .ssr_name = "dsps", + .sysmon_name = "slpi", + .ssctl_id = 0x16, };static const struct of_device_id adsp_of_match[] = {
drivers/remoteproc/qcom_common.h +21 -0
@@ -3,6 +3,9 @@#include <linux/remoteproc.h> #include "remoteproc_internal.h" +#include <linux/soc/qcom/qmi.h> + +struct qcom_sysmon ;struct qcom_rproc_glink {struct rproc_subdev subdev;
@@ -40,4 +43,22 @@ void qcom_add_ssr_subdev(struct rproc *rproc, struct qcom_rproc_ssr *ssr, const char *ssr_name);void qcom_remove_ssr_subdev (struct rproc *rproc,struct qcom_rproc_ssr *ssr); +#if IS_ENABLED (CONFIG_QCOM_SYSMON ) +struct qcom_sysmon *qcom_add_sysmon_subdev (struct rproc *rproc, +const char *name, +int ssctl_instance); +void qcom_remove_sysmon_subdev (struct qcom_sysmon *sysmon); +#else +static inline struct qcom_sysmon *qcom_add_sysmon_subdev (struct rproc *rproc, +const char *name, +int ssctl_instance) +{ +return NULL ; +} + +static inline void qcom_remove_sysmon_subdev (struct qcom_sysmon *sysmon) +{ +} +#endif +#endif
drivers/remoteproc/qcom_q6v5_pil.c +3 -0
@@ -154,6 +154,7 @@ struct q6v5 {struct qcom_rproc_subdev smd_subdev;struct qcom_rproc_ssr ssr_subdev; +struct qcom_sysmon *sysmon; }; static int q6v5_regulator_init(struct device *dev, struct reg_info *regs,
@@ -1041,6 +1042,7 @@ static int q6v5_probe(struct platform_device *pdev)qcom_add_smd_subdev (rproc, &qproc->smd_subdev);qcom_add_ssr_subdev (rproc, &qproc->ssr_subdev,"mpss" ); + qproc->sysmon =qcom_add_sysmon_subdev (rproc,"modem" ,0x12 ); ret =rproc_add (rproc);if (ret)
@@ -1060,6 +1062,7 @@ static int q6v5_remove(struct platform_device *pdev)rproc_del (qproc->rproc); +qcom_remove_sysmon_subdev (qproc->sysmon);qcom_remove_smd_subdev (qproc->rproc, &qproc->smd_subdev);qcom_remove_ssr_subdev (qproc->rproc, &qproc->ssr_subdev);rproc_free (qproc->rproc);
drivers/remoteproc/qcom_sysmon.c new file +585 -0
585 lines not on this page · raw message
drivers/remoteproc/qcom_wcnss.c +4 -0
@@ -40,6 +40,7 @@#define WCNSS_CRASH_REASON_SMEM 422#define WCNSS_FIRMWARE_NAME "wcnss.mdt"#define WCNSS_PAS_ID 6 +#define WCNSS_SSCTL_ID 0x13#define WCNSS_SPARE_NVBIN_DLND BIT(25)
@@ -98,6 +99,7 @@ struct qcom_wcnss {size_t mem_size;struct qcom_rproc_subdev smd_subdev; +struct qcom_sysmon *sysmon; };static const struct wcnss_data riva_data = {
@@ -557,6 +559,7 @@ static int wcnss_probe(struct platform_device *pdev) }qcom_add_smd_subdev (rproc, &wcnss->smd_subdev); + wcnss->sysmon =qcom_add_sysmon_subdev (rproc,"wcnss" ,WCNSS_SSCTL_ID ); ret =rproc_add (rproc);if (ret)
@@ -579,6 +582,7 @@ static int wcnss_remove(struct platform_device *pdev)qcom_smem_state_put (wcnss->state);rproc_del (wcnss->rproc); +qcom_remove_sysmon_subdev (wcnss->sysmon);qcom_remove_smd_subdev (wcnss->rproc, &wcnss->smd_subdev);rproc_free (wcnss->rproc);
Signature · 1 line
2.15.0
Re: [PATCH v3 4/5] remoteproc: qcom: Introduce sysmon
Hi Bjorn,
Question about the SSR events for sysmon.
Thanks,
Chris
On 11/15/2017 12:10 PM, Bjorn Andersson wrote:
[..]
Quoted 13 lines
drivers/remoteproc/qcom_sysmon.c new file +13
-0+/** +* ssctl_send_event() - send notification of other remote's SSR event +* @sysmon: sysmon context +* @name: other remote's name +*/ +static void ssctl_send_event (struct qcom_sysmon *sysmon,const char *name) +{ +struct ssctl_subsys_event_resp resp; +struct ssctl_subsys_event_req req; +struct qmi_txn txn; +int ret; + +memset (&resp,0 ,sizeof (resp));
drivers/remoteproc/qcom_sysmon.c line 316
Quoted 10 lines
drivers/remoteproc/qcom_sysmon.c new file +10
-0+ ret =qmi_txn_init (&sysmon->qmi, &txn, ssctl_subsys_event_resp_ei, &resp); +if (ret <0 ) { +dev_err (sysmon->dev,"failed to allocate QMI txn\n" ); +return ; + } + +memset (&req,0 ,sizeof (req)); +strlcpy (req.subsys_name, name,sizeof (req.subsys_name)); + req.subsys_name_len =strlen (req.subsys_name); + req.event =SSCTL_SSR_EVENT_BEFORE_SHUTDOWN ;
Are there plans to add the other SSR events to sysmon notifiers? I think the SSCTL service expects to receive events about remote procs starting as well.
Quoted 20 lines
drivers/remoteproc/qcom_sysmon.c new file +20
-0+ req.evt_driven_valid = true; + req.evt_driven =SSCTL_SSR_EVENT_FORCED ; + + ret =qmi_send_request (&sysmon->qmi, &sysmon->ssctl, &txn, +SSCTL_SUBSYS_EVENT_REQ ,40 , + ssctl_subsys_event_req_ei, &req); +if (ret <0 ) { +dev_err (sysmon->dev,"failed to send shutdown request\n" ); +qmi_txn_cancel (&txn); +return ; + } + + ret =qmi_txn_wait (&txn,5 *HZ ); +if (ret <0 ) +dev_err (sysmon->dev,"failed receiving QMI response\n" ); +else if (resp.resp.result) +dev_err (sysmon->dev,"ssr event send failed\n" ); +else +dev_dbg (sysmon->dev,"ssr event send completed\n" ); +}
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
Re: [PATCH v3 4/5] remoteproc: qcom: Introduce sysmon
Quoted 5 lines · Chris Lew
drivers/remoteproc/qcom_sysmon.c line 316
Quoted 1 line
drivers/remoteproc/qcom_sysmon.c new file +1
-0+ req.event =SSCTL_SSR_EVENT_BEFORE_SHUTDOWN ;Are there plans to add the other SSR events to sysmon notifiers? I think the SSCTL service expects to receive events about remote procs starting as well.
We could easily add support here to send out the AFTER_BOOTUP notification, beyond that we would need to extend the subdev notifiers as well.
But the downstream code paths does confuse me, can you confirm that these messages are actually sent to the remote ssctl services?
Regards,
Bjorn
Re: [PATCH v3 4/5] remoteproc: qcom: Introduce sysmon
Quoted 11 lines · Bjorn Andersson
Quoted 5 lines · Chris Lew
drivers/remoteproc/qcom_sysmon.c line 316
Quoted 1 line
drivers/remoteproc/qcom_sysmon.c new file +1
-0+ req.event =SSCTL_SSR_EVENT_BEFORE_SHUTDOWN ;Are there plans to add the other SSR events to sysmon notifiers? I think the SSCTL service expects to receive events about remote procs starting as well.
We could easily add support here to send out the
AFTER_BOOTUPnotification, beyond that we would need to extend the subdev notifiers as well.
Quoted 6 lines
But the downstream code paths does confuse me, can you confirm that these messages are actually sent to the remote ssctl services?
Regards,
Bjorn
Yea the other three events are definitely sent to the remote. The remote side posts the events for other modules to query. I'm not sure if all of the events are used by other other modules though.
Thanks,
Chris
Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum, a Linux Foundation Collaborative Project
PATCH v3 5/5 samples: Introduce Qualcomm QMI sample client
In reply to Bjorn AnderssonIntroduce a sample driver that register for server notifications and spawn clients for each available test service (service 15). The spawned clients implements the interface for encoding "ping" and "data" requests and decode the responses from the remote.
---
Changes since v2:
- Fix some kerneldoc typos
- Checkpatch fixes
Changes since v1:
- Adapted to updated QMI helper interface
- Moved user space interface to debugfs
samples/Kconfig | 9 + samples/Makefile | 2 +- samples/qmi/Makefile | 1 + samples/qmi/qmi_sample_client.c | 631 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 642 insertions(+), 1 deletion(-) create mode 100644 samples/qmi/Makefile create mode 100644 samples/qmi/qmi_sample_client.c
samples/Kconfig +9 -0
@@ -62,6 +62,15 @@ config SAMPLE_KDB Build an example of how to dynamically add the hello command to the kdb shell. +config SAMPLE_QMI_CLIENT + tristate "Build qmi client sample -- loadable modules only" + depends on m + depends on ARCH_QCOM + select QCOM_QMI_HELPERS + help + Build an QMI client sample driver, which demonstrates how to + communicate with a remote QRTR service, using QMI encoded messages. + config SAMPLE_RPMSG_CLIENT tristate "Build rpmsg client sample -- loadable modules only" depends on RPMSG && m
samples/Makefile +1 -1
@@ -3,4 +3,4 @@ obj-$(CONFIG_SAMPLES) += kobject/ kprobes/ trace_events/ livepatch/ \ hw_breakpoint/ kfifo/ kdb/ hidraw/ rpmsg/ seccomp/ \ configfs/ connector/ v4l/ trace_printk/ blackfin/ \ - vfio-mdev/ statx/ + vfio-mdev/ statx/ qmi/
samples/qmi/Makefile new file +1 -0
@@ -0,0 +1 @@ +obj-$(CONFIG_SAMPLE_QMI_CLIENT) += qmi_sample_client.o
samples/qmi/qmi_sample_client.c new file +631 -0
631 lines not on this page · raw message
Signature · 1 line
2.15.0