Skip to contentSkip to conversation

In-kernel QMI helpers and sysmon

PATCH Superseded Bjorn Andersson 5 participants 24 messages Nov 30, 2017 – Dec 7, 2017

Subsystems (3)

v4 of 5 Superseded Latest is v5 →

lore
Share & tools
lore
#0 lore raw

v4 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 v3:
- Don't call QMI handler for response type messages without known txn
- Kerneldoc updates
- Style updates

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     | 587 ++++++++++++++++++++++++
 drivers/remoteproc/qcom_wcnss.c      |   4 +
 drivers/remoteproc/remoteproc_core.c |  18 +-
 drivers/soc/qcom/Kconfig             |   9 +
 drivers/soc/qcom/Makefile            |   2 +
 drivers/soc/qcom/qmi_encdec.c        | 826 +++++++++++++++++++++++++++++++++
 drivers/soc/qcom/qmi_interface.c     | 857 +++++++++++++++++++++++++++++++++++
 include/linux/remoteproc.h           |   4 +-
 include/linux/soc/qcom/qmi.h         | 279 ++++++++++++
 samples/Kconfig                      |   9 +
 samples/Makefile                     |   2 +-
 samples/qmi/Makefile                 |   1 +
 samples/qmi/qmi_sample_client.c      | 631 ++++++++++++++++++++++++++
 19 files changed, 3274 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
#1 lore raw

PATCH v4 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 v3:
- Moved depends on ARCH_QCOM from patch 2
- Kerneldoc updates
- Style updates
- Dropped qrtr.h include from header file
- Rename is_array to array_type

Changes since v2:
- Checkpatch fixes

Changes since v1:
- None

 drivers/soc/qcom/Kconfig      |   9 +
 drivers/soc/qcom/Makefile     |   2 +
 drivers/soc/qcom/qmi_encdec.c | 826 ++++++++++++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/qmi.h  | 114 ++++++
 4 files changed, 951 insertions(+)
 create mode 100644 drivers/soc/qcom/qmi_encdec.c
 create mode 100644 include/linux/soc/qcom/qmi.h
drivers/soc/qcom/Kconfig +9 -0
index b81374bb6713..2411df0427d9 100644
@@ -35,6 +35,15 @@ config QCOM_PM
 	  modes. It interface with various system drivers to put the cores in
 	  low power modes.
 
+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
+	  clients and this helpers provide the common functionality needed for
+	  doing this from a kernel driver.
+
 config QCOM_RMTFS_MEM
 	tristate "Qualcomm Remote Filesystem memory driver"
 	depends on ARCH_QCOM
drivers/soc/qcom/Makefile +2 -0
index 40c56f67e94a..37f85b45d0a1 100644
@@ -3,6 +3,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_RMTFS_MEM)	+= rmtfs_mem.o
 obj-$(CONFIG_QCOM_SMD_RPM)	+= smd-rpm.o
 obj-$(CONFIG_QCOM_SMEM) +=	smem.o
drivers/soc/qcom/qmi_encdec.c new file +826 -0

826 lines not on this page · raw message

include/linux/soc/qcom/qmi.h new file +114 -0

114 lines not on this page · raw message

Signature · 1 line
2.15.0
Acked-by on v4 1/5
#2 lore raw

Re: [PATCH v4 1/5] soc: qcom: Introduce QMI encoder/decoder

Quoted 11 lines · Bjorn Andersson

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.

---

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#3 lore raw

Re: [PATCH v4 1/5] soc: qcom: Introduce QMI encoder/decoder

In reply to Bjorn Andersson

Hi Bjorn,

Few minor comments ..

Quoted 179 lines · Bjorn Andersson

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 v3:
- Moved depends on ARCH_QCOM from patch 2
- Kerneldoc updates
- Style updates
- Dropped qrtr.h include from header file
- Rename is_array to array_type

Changes since v2:
- Checkpatch fixes

Changes since v1:
- None

  drivers/soc/qcom/Kconfig      |   9 +
  drivers/soc/qcom/Makefile     |   2 +
  drivers/soc/qcom/qmi_encdec.c | 826 ++++++++++++++++++++++++++++++++++++++++++
  include/linux/soc/qcom/qmi.h  | 114 ++++++
  4 files changed, 951 insertions(+)

create mode 100644 drivers/soc/qcom/qmi_encdec.c create mode 100644 include/linux/soc/qcom/qmi.h

drivers/soc/qcom/Kconfig +9 -0
index b81374bb6713..2411df0427d9 100644
@@ -35,6 +35,15 @@ config QCOM_PM
  	  modes. It interface with various system drivers to put the cores in
  	  low power modes.
 
+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
+	  clients and this helpers provide the common functionality needed for
+	  doing this from a kernel driver.
+
  config QCOM_RMTFS_MEM
  	tristate "Qualcomm Remote Filesystem memory driver"
  	depends on ARCH_QCOM
drivers/soc/qcom/Makefile +2 -0
index 40c56f67e94a..37f85b45d0a1 100644
@@ -3,6 +3,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_RMTFS_MEM)	+= rmtfs_mem.o
  obj-$(CONFIG_QCOM_SMD_RPM)	+= smd-rpm.o
  obj-$(CONFIG_QCOM_SMEM) +=	smem.o
drivers/soc/qcom/qmi_encdec.c new file +107 -0
new file mode 100644
index 000000000000..a197fc0114c3
@@ -0,0 +1,826 @@
+/*
+ * 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
+ * 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/string.h>
+#include <linux/soc/qcom/qmi.h>
+
+#define QMI_ENCDEC_ENCODE_TLV(type, length, p_dst) do { \
+	*p_dst++ = type; \
+	*p_dst++ = ((u8)((length) & 0xFF)); \
+	*p_dst++ = ((u8)(((length) >> 8) & 0xFF)); \
+} while (0)
+
+#define QMI_ENCDEC_DECODE_TLV(p_type, p_length, p_src) do { \
+	*p_type = (u8)*p_src++; \
+	*p_length = (u8)*p_src++; \
+	*p_length |= ((u8)*p_src) << 8; \
+} while (0)
+
+#define QMI_ENCDEC_ENCODE_N_BYTES(p_dst, p_src, size) \
+do { \
+	memcpy(p_dst, p_src, size); \
+	p_dst = (u8 *)p_dst + size; \
+	p_src = (u8 *)p_src + size; \
+} while (0)
+
+#define QMI_ENCDEC_DECODE_N_BYTES(p_dst, p_src, size) \
+do { \
+	memcpy(p_dst, p_src, size); \
+	p_dst = (u8 *)p_dst + size; \
+	p_src = (u8 *)p_src + size; \
+} while (0)
+
+#define UPDATE_ENCODE_VARIABLES(temp_si, buf_dst, \
+				encoded_bytes, tlv_len, encode_tlv, rc) \
+do { \
+	buf_dst = (u8 *)buf_dst + rc; \
+	encoded_bytes += rc; \
+	tlv_len += rc; \
+	temp_si = temp_si + 1; \
+	encode_tlv = 1; \
+} while (0)
+
+#define UPDATE_DECODE_VARIABLES(buf_src, decoded_bytes, rc) \
+do { \
+	buf_src = (u8 *)buf_src + rc; \
+	decoded_bytes += rc; \
+} while (0)
+
+#define TLV_LEN_SIZE sizeof(u16)
+#define TLV_TYPE_SIZE sizeof(u8)
+#define OPTIONAL_TLV_TYPE_START 0x10
+
+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);
+
+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.
+ *
+ * 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.
+ *
+ * Return: struct info of the next element that can be encoded.
+ */
+static struct qmi_elem_info *skip_to_next_elem(struct qmi_elem_info *ei_array,
+					       int level)
+{
+	struct qmi_elem_info *temp_ei = ei_array;
+	u8 tlv_type;
+
+	if (level > 1) {
+		temp_ei = temp_ei + 1;
+	} else {
+		do {
+			tlv_type = temp_ei->tlv_type;
+			temp_ei = temp_ei + 1;
+		} while (tlv_type == temp_ei->tlv_type);
+	}
+
+	return temp_ei;
+}
+
+/**

drivers/soc/qcom/qmi_encdec.c line 117

Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10 -0
+ * qmi_calc_min_msg_len() - Calculate the minimum length of a QMI message
+ * @ei_array: Struct info array describing the structure.
+ * @level: Level to identify the depth of the nested structures.
+ *
+ * Return: Expected minimum length of the QMI message or 0 on error.
+ */
+static int qmi_calc_min_msg_len(struct qmi_elem_info *ei_array,
+				int level)
+{
+	int min_msg_len = 0;

min_msg_len should be u32 as it would not be negative

Quoted 52 lines
drivers/soc/qcom/qmi_encdec.c new file +52 -0
+	struct qmi_elem_info *temp_ei = ei_array;
+
+	if (!ei_array)
+		return min_msg_len;
+
+	while (temp_ei->data_type != QMI_EOTI) {
+		/* Optional elements do not count in minimum length */
+		if (temp_ei->data_type == QMI_OPT_FLAG) {
+			temp_ei = skip_to_next_elem(temp_ei, level);
+			continue;
+		}
+
+		if (temp_ei->data_type == QMI_DATA_LEN) {
+			min_msg_len += (temp_ei->elem_size == sizeof(u8) ?
+					sizeof(u8) : sizeof(u16));
+			temp_ei++;
+			continue;
+		} else if (temp_ei->data_type == QMI_STRUCT) {
+			min_msg_len += qmi_calc_min_msg_len(temp_ei->ei_array,
+							    (level + 1));
+			temp_ei++;
+		} else if (temp_ei->data_type == QMI_STRING) {
+			if (level > 1)
+				min_msg_len += temp_ei->elem_len <= U8_MAX ?
+					sizeof(u8) : sizeof(u16);
+			min_msg_len += temp_ei->elem_len * temp_ei->elem_size;
+			temp_ei++;
+		} else {
+			min_msg_len += (temp_ei->elem_len * temp_ei->elem_size);
+			temp_ei++;
+		}
+
+		/*
+		 * Type & Length info. not prepended for elements in the
+		 * nested structure.
+		 */
+		if (level == 1)
+			min_msg_len += (TLV_TYPE_SIZE + TLV_LEN_SIZE);
+	}
+
+	return min_msg_len;
+}
+
+/**
+ * qmi_encode_basic_elem() - Encodes elements of basic/primary data type
+ * @buf_dst: Buffer to store the encoded information.
+ * @buf_src: Buffer containing the elements to be encoded.
+ * @elem_len: Number of elements, in the buf_src, to be encoded.
+ * @elem_size: Size of a single instance of the element to be encoded.
+ *
+ * This function encodes the "elem_len" number of data elements, each of
+ * size "elem_size" bytes from the source buffer "buf_src" and stores the

drivers/soc/qcom/qmi_encdec.c line 179

Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10 -0
+ * encoded information in the destination buffer "buf_dst". The elements are
+ * of primary data type which include u8 - u64 or similar. This
+ * function returns the number of bytes of encoded information.
+ *
+ * Return: The number of bytes of encoded information.
+ */
+static int qmi_encode_basic_elem(void *buf_dst, const void *buf_src,
+				 u32 elem_len, u32 elem_size)
+{
+	u32 i, rc = 0;

Function return type should not be int

Quoted 62 lines
drivers/soc/qcom/qmi_encdec.c new file +62 -0
+
+	for (i = 0; i < elem_len; i++) {
+		QMI_ENCDEC_ENCODE_N_BYTES(buf_dst, buf_src, elem_size);
+		rc += elem_size;
+	}
+
+	return rc;
+}
+
+/**
+ * qmi_encode_struct_elem() - Encodes elements of struct data type
+ * @ei_array: Struct info array descibing the struct element.
+ * @buf_dst: Buffer to store the encoded information.
+ * @buf_src: Buffer containing the elements to be encoded.
+ * @elem_len: Number of elements, in the buf_src, to be encoded.
+ * @out_buf_len: Available space in the encode buffer.
+ * @enc_level: Depth of the nested structure from the main structure.
+ *
+ * This function encodes the "elem_len" number of struct elements, each of
+ * size "ei_array->elem_size" bytes from the source buffer "buf_src" and
+ * stores the encoded information in the destination buffer "buf_dst". The
+ * elements are of struct data type which includes any C structure. This
+ * function returns the number of bytes of encoded information.
+ *
+ * Return: The number of bytes of encoded information on success or negative
+ * errno on error.
+ */
+static int qmi_encode_struct_elem(struct qmi_elem_info *ei_array,
+				  void *buf_dst, const void *buf_src,
+				  u32 elem_len, u32 out_buf_len,
+				  int enc_level)
+{
+	int i, rc, encoded_bytes = 0;
+	struct qmi_elem_info *temp_ei = ei_array;
+
+	for (i = 0; i < elem_len; i++) {
+		rc = qmi_encode(temp_ei->ei_array, buf_dst, buf_src,
+				out_buf_len - encoded_bytes, enc_level);
+		if (rc < 0) {
+			pr_err("%s: STRUCT Encode failure\n", __func__);
+			return rc;
+		}
+		buf_dst = buf_dst + rc;
+		buf_src = buf_src + temp_ei->elem_size;
+		encoded_bytes += rc;
+	}
+
+	return encoded_bytes;
+}
+
+/**
+ * qmi_encode_string_elem() - Encodes elements of string data type
+ * @ei_array: Struct info array descibing the string element.
+ * @buf_dst: Buffer to store the encoded information.
+ * @buf_src: Buffer containing the elements to be encoded.
+ * @out_buf_len: Available space in the encode buffer.
+ * @enc_level: Depth of the string element from the main structure.
+ *
+ * This function encodes a string element of maximum length "ei_array->elem_len"
+ * bytes from the source buffer "buf_src" and stores the encoded information in
+ * the destination buffer "buf_dst". This function returns the number of bytes
+ * of encoded information.

drivers/soc/qcom/qmi_encdec.c line 251

Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10 -0
+ *
+ * Return: The number of bytes of encoded information on success or negative
+ * errno on error.
+ */
+static int qmi_encode_string_elem(struct qmi_elem_info *ei_array,
+				  void *buf_dst, const void *buf_src,
+				  u32 out_buf_len, int enc_level)
+{
+	int rc;
+	int encoded_bytes = 0;

change rc,encoded_bytes to u32

Quoted 191 lines
drivers/soc/qcom/qmi_encdec.c new file +191 -0
+	struct qmi_elem_info *temp_ei = ei_array;
+	u32 string_len = 0;
+	u32 string_len_sz = 0;
+
+	string_len = strlen(buf_src);
+	string_len_sz = temp_ei->elem_len <= U8_MAX ?
+			sizeof(u8) : sizeof(u16);
+	if (string_len > temp_ei->elem_len) {
+		pr_err("%s: String to be encoded is longer - %d > %d\n",
+		       __func__, string_len, temp_ei->elem_len);
+		return -EINVAL;
+	}
+
+	if (enc_level == 1) {
+		if (string_len + TLV_LEN_SIZE + TLV_TYPE_SIZE >
+		    out_buf_len) {
+			pr_err("%s: Output len %d > Out Buf len %d\n",
+			       __func__, string_len, out_buf_len);
+			return -ETOOSMALL;
+		}
+	} else {
+		if (string_len + string_len_sz > out_buf_len) {
+			pr_err("%s: Output len %d > Out Buf len %d\n",
+			       __func__, string_len, out_buf_len);
+			return -ETOOSMALL;
+		}
+		rc = qmi_encode_basic_elem(buf_dst, &string_len,
+					   1, string_len_sz);
+		encoded_bytes += rc;
+	}
+
+	rc = qmi_encode_basic_elem(buf_dst + encoded_bytes, buf_src,
+				   string_len, temp_ei->elem_size);
+	encoded_bytes += rc;
+
+	return encoded_bytes;
+}
+
+/**
+ * qmi_encode() - Core Encode Function
+ * @ei_array: Struct info array describing the structure to be encoded.
+ * @out_buf: Buffer to hold the encoded QMI message.
+ * @in_c_struct: Pointer to the C structure to be encoded.
+ * @out_buf_len: Available space in the encode buffer.
+ * @enc_level: Encode level to indicate the depth of the nested structure,
+ *             within the main structure, being encoded.
+ *
+ * Return: The number of bytes of encoded information on success or negative
+ * errno on error.
+ */
+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)
+{
+	struct qmi_elem_info *temp_ei = ei_array;
+	u8 opt_flag_value = 0;
+	u32 data_len_value = 0, data_len_sz;
+	u8 *buf_dst = (u8 *)out_buf;
+	u8 *tlv_pointer;
+	u32 tlv_len;
+	u8 tlv_type;
+	u32 encoded_bytes = 0;
+	const void *buf_src;
+	int encode_tlv = 0;
+	int rc;
+
+	if (!ei_array)
+		return 0;
+
+	tlv_pointer = buf_dst;
+	tlv_len = 0;
+	if (enc_level == 1)
+		buf_dst = buf_dst + (TLV_LEN_SIZE + TLV_TYPE_SIZE);
+
+	while (temp_ei->data_type != QMI_EOTI) {
+		buf_src = in_c_struct + temp_ei->offset;
+		tlv_type = temp_ei->tlv_type;
+
+		if (temp_ei->array_type == NO_ARRAY) {
+			data_len_value = 1;
+		} else if (temp_ei->array_type == STATIC_ARRAY) {
+			data_len_value = temp_ei->elem_len;
+		} else if (data_len_value <= 0 ||
+			    temp_ei->elem_len < data_len_value) {
+			pr_err("%s: Invalid data length\n", __func__);
+			return -EINVAL;
+		}
+
+		switch (temp_ei->data_type) {
+		case QMI_OPT_FLAG:
+			rc = qmi_encode_basic_elem(&opt_flag_value, buf_src,
+						   1, sizeof(u8));
+			if (opt_flag_value)
+				temp_ei = temp_ei + 1;
+			else
+				temp_ei = skip_to_next_elem(temp_ei, enc_level);
+			break;
+
+		case QMI_DATA_LEN:
+			memcpy(&data_len_value, buf_src, temp_ei->elem_size);
+			data_len_sz = temp_ei->elem_size == sizeof(u8) ?
+					sizeof(u8) : sizeof(u16);
+			/* Check to avoid out of range buffer access */
+			if ((data_len_sz + encoded_bytes + TLV_LEN_SIZE +
+			    TLV_TYPE_SIZE) > out_buf_len) {
+				pr_err("%s: Too Small Buffer @DATA_LEN\n",
+				       __func__);
+				return -ETOOSMALL;
+			}
+			rc = qmi_encode_basic_elem(buf_dst, &data_len_value,
+						   1, data_len_sz);
+			UPDATE_ENCODE_VARIABLES(temp_ei, buf_dst,
+						encoded_bytes, tlv_len,
+						encode_tlv, rc);
+			if (!data_len_value)
+				temp_ei = skip_to_next_elem(temp_ei, enc_level);
+			else
+				encode_tlv = 0;
+			break;
+
+		case QMI_UNSIGNED_1_BYTE:
+		case QMI_UNSIGNED_2_BYTE:
+		case QMI_UNSIGNED_4_BYTE:
+		case QMI_UNSIGNED_8_BYTE:
+		case QMI_SIGNED_2_BYTE_ENUM:
+		case QMI_SIGNED_4_BYTE_ENUM:
+			/* Check to avoid out of range buffer access */
+			if (((data_len_value * temp_ei->elem_size) +
+			    encoded_bytes + TLV_LEN_SIZE + TLV_TYPE_SIZE) >
+			    out_buf_len) {
+				pr_err("%s: Too Small Buffer @data_type:%d\n",
+				       __func__, temp_ei->data_type);
+				return -ETOOSMALL;
+			}
+			rc = qmi_encode_basic_elem(buf_dst, buf_src,
+						   data_len_value,
+						   temp_ei->elem_size);
+			UPDATE_ENCODE_VARIABLES(temp_ei, buf_dst,
+						encoded_bytes, tlv_len,
+						encode_tlv, rc);
+			break;
+
+		case QMI_STRUCT:
+			rc = qmi_encode_struct_elem(temp_ei, buf_dst, buf_src,
+						    data_len_value,
+						    out_buf_len - encoded_bytes,
+						    enc_level + 1);
+			if (rc < 0)
+				return rc;
+			UPDATE_ENCODE_VARIABLES(temp_ei, buf_dst,
+						encoded_bytes, tlv_len,
+						encode_tlv, rc);
+			break;
+
+		case QMI_STRING:
+			rc = qmi_encode_string_elem(temp_ei, buf_dst, buf_src,
+						    out_buf_len - encoded_bytes,
+						    enc_level);
+			if (rc < 0)
+				return rc;
+			UPDATE_ENCODE_VARIABLES(temp_ei, buf_dst,
+						encoded_bytes, tlv_len,
+						encode_tlv, rc);
+			break;
+		default:
+			pr_err("%s: Unrecognized data type\n", __func__);
+			return -EINVAL;
+		}
+
+		if (encode_tlv && enc_level == 1) {
+			QMI_ENCDEC_ENCODE_TLV(tlv_type, tlv_len, tlv_pointer);
+			encoded_bytes += (TLV_TYPE_SIZE + TLV_LEN_SIZE);
+			tlv_pointer = buf_dst;
+			tlv_len = 0;
+			buf_dst = buf_dst + TLV_LEN_SIZE + TLV_TYPE_SIZE;
+			encode_tlv = 0;
+		}
+	}
+
+	return encoded_bytes;
+}
+
+/**
+ * qmi_decode_basic_elem() - Decodes elements of basic/primary data type
+ * @buf_dst: Buffer to store the decoded element.
+ * @buf_src: Buffer containing the elements in QMI wire format.
+ * @elem_len: Number of elements to be decoded.
+ * @elem_size: Size of a single instance of the element to be decoded.
+ *
+ * This function decodes the "elem_len" number of elements in QMI wire format,
+ * each of size "elem_size" bytes from the source buffer "buf_src" and stores

drivers/soc/qcom/qmi_encdec.c line 452

Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10 -0
+ * the decoded elements in the destination buffer "buf_dst". The elements are
+ * of primary data type which include u8 - u64 or similar. This
+ * function returns the number of bytes of decoded information.
+ *
+ * Return: The total size of the decoded data elements, in bytes.
+ */
+static int qmi_decode_basic_elem(void *buf_dst, const void *buf_src,
+				 u32 elem_len, u32 elem_size)
+{
+	u32 i, rc = 0;

Return type should not be int

Quoted 24 lines
drivers/soc/qcom/qmi_encdec.c new file +24 -0
+
+	for (i = 0; i < elem_len; i++) {
+		QMI_ENCDEC_DECODE_N_BYTES(buf_dst, buf_src, elem_size);
+		rc += elem_size;
+	}
+
+	return rc;
+}
+
+/**
+ * qmi_decode_struct_elem() - Decodes elements of struct data type
+ * @ei_array: Struct info array descibing the struct element.
+ * @buf_dst: Buffer to store the decoded element.
+ * @buf_src: Buffer containing the elements in QMI wire format.
+ * @elem_len: Number of elements to be decoded.
+ * @tlv_len: Total size of the encoded inforation corresponding to
+ *           this struct element.
+ * @dec_level: Depth of the nested structure from the main structure.
+ *
+ * This function decodes the "elem_len" number of elements in QMI wire format,
+ * each of size "(tlv_len/elem_len)" bytes from the source buffer "buf_src"
+ * and stores the decoded elements in the destination buffer "buf_dst". The
+ * elements are of struct data type which includes any C structure. This
+ * function returns the number of bytes of decoded information.

drivers/soc/qcom/qmi_encdec.c line 486

Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10 -0
+ *
+ * Return: The total size of the decoded data elements on success, negative
+ * errno on error.
+ */
+static int qmi_decode_struct_elem(struct qmi_elem_info *ei_array,
+				  void *buf_dst, const void *buf_src,
+				  u32 elem_len, u32 tlv_len,
+				  int dec_level)
+{
+	int i, rc, decoded_bytes = 0;

rc,decoded_bytes should be unsigned and change appropriate function return type

Quoted 36 lines
drivers/soc/qcom/qmi_encdec.c new file +36 -0
+	struct qmi_elem_info *temp_ei = ei_array;
+
+	for (i = 0; i < elem_len && decoded_bytes < tlv_len; i++) {
+		rc = qmi_decode(temp_ei->ei_array, buf_dst, buf_src,
+				tlv_len - decoded_bytes, dec_level);
+		if (rc < 0)
+			return rc;
+		buf_src = buf_src + rc;
+		buf_dst = buf_dst + temp_ei->elem_size;
+		decoded_bytes += rc;
+	}
+
+	if ((dec_level <= 2 && decoded_bytes != tlv_len) ||
+	    (dec_level > 2 && (i < elem_len || decoded_bytes > tlv_len))) {
+		pr_err("%s: Fault in decoding: dl(%d), db(%d), tl(%d), i(%d), el(%d)\n",
+		       __func__, dec_level, decoded_bytes, tlv_len,
+		       i, elem_len);
+		return -EFAULT;
+	}
+
+	return decoded_bytes;
+}
+
+/**
+ * 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.
+ *
+ * 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 line 532

Quoted 10 lines
drivers/soc/qcom/qmi_encdec.c new file +10 -0
+ *
+ * Return: The total size of the decoded data elements on success, negative
+ * errno on error.
+ */
+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;

same as above

Quoted 414 lines
drivers/soc/qcom/qmi_encdec.c new file +294 -0
+	u32 string_len = 0;
+	u32 string_len_sz = 0;
+	struct qmi_elem_info *temp_ei = ei_array;
+
+	if (dec_level == 1) {
+		string_len = tlv_len;
+	} else {
+		string_len_sz = temp_ei->elem_len <= U8_MAX ?
+				sizeof(u8) : sizeof(u16);
+		rc = qmi_decode_basic_elem(&string_len, buf_src,
+					   1, string_len_sz);
+		decoded_bytes += rc;
+	}
+
+	if (string_len > temp_ei->elem_len) {
+		pr_err("%s: String len %d > Max Len %d\n",
+		       __func__, string_len, temp_ei->elem_len);
+		return -ETOOSMALL;
+	} else if (string_len > tlv_len) {
+		pr_err("%s: String len %d > Input Buffer Len %d\n",
+		       __func__, string_len, tlv_len);
+		return -EFAULT;
+	}
+
+	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;
+
+	return decoded_bytes;
+}
+
+/**
+ * find_ei() - Find element info corresponding to TLV Type
+ * @ei_array: Struct info array of the message being decoded.
+ * @type: TLV Type of the element being searched.
+ *
+ * Every element that got encoded in the QMI message will have a type
+ * information associated with it. While decoding the QMI message,
+ * this function is used to find the struct info regarding the element
+ * that corresponds to the type being decoded.
+ *
+ * Return: Pointer to struct info, if found
+ */
+static struct qmi_elem_info *find_ei(struct qmi_elem_info *ei_array,
+				     u32 type)
+{
+	struct qmi_elem_info *temp_ei = ei_array;
+
+	while (temp_ei->data_type != QMI_EOTI) {
+		if (temp_ei->tlv_type == (u8)type)
+			return temp_ei;
+		temp_ei = temp_ei + 1;
+	}
+
+	return NULL;
+}
+
+/**
+ * qmi_decode() - Core Decode Function
+ * @ei_array: Struct info array describing the structure to be decoded.
+ * @out_c_struct: Buffer to hold the decoded C struct
+ * @in_buf: Buffer containing the QMI message to be decoded
+ * @in_buf_len: Length of the QMI message to be decoded
+ * @dec_level: Decode level to indicate the depth of the nested structure,
+ *             within the main structure, being decoded
+ *
+ * Return: The number of bytes of decoded information on success, negative
+ * errno on error.
+ */
+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)
+{
+	struct qmi_elem_info *temp_ei = ei_array;
+	u8 opt_flag_value = 1;
+	u32 data_len_value = 0, data_len_sz = 0;
+	u8 *buf_dst = out_c_struct;
+	const u8 *tlv_pointer;
+	u32 tlv_len = 0;
+	u32 tlv_type;
+	u32 decoded_bytes = 0;
+	const void *buf_src = in_buf;
+	int rc;
+
+	while (decoded_bytes < in_buf_len) {
+		if (dec_level >= 2 && temp_ei->data_type == QMI_EOTI)
+			return decoded_bytes;
+
+		if (dec_level == 1) {
+			tlv_pointer = buf_src;
+			QMI_ENCDEC_DECODE_TLV(&tlv_type,
+					      &tlv_len, tlv_pointer);
+			buf_src += (TLV_TYPE_SIZE + TLV_LEN_SIZE);
+			decoded_bytes += (TLV_TYPE_SIZE + TLV_LEN_SIZE);
+			temp_ei = find_ei(ei_array, tlv_type);
+			if (!temp_ei && tlv_type < OPTIONAL_TLV_TYPE_START) {
+				pr_err("%s: Inval element info\n", __func__);
+				return -EINVAL;
+			} else if (!temp_ei) {
+				UPDATE_DECODE_VARIABLES(buf_src,
+							decoded_bytes, tlv_len);
+				continue;
+			}
+		} else {
+			/*
+			 * No length information for elements in nested
+			 * structures. So use remaining decodable buffer space.
+			 */
+			tlv_len = in_buf_len - decoded_bytes;
+		}
+
+		buf_dst = out_c_struct + temp_ei->offset;
+		if (temp_ei->data_type == QMI_OPT_FLAG) {
+			memcpy(buf_dst, &opt_flag_value, sizeof(u8));
+			temp_ei = temp_ei + 1;
+			buf_dst = out_c_struct + temp_ei->offset;
+		}
+
+		if (temp_ei->data_type == QMI_DATA_LEN) {
+			data_len_sz = temp_ei->elem_size == sizeof(u8) ?
+					sizeof(u8) : sizeof(u16);
+			rc = qmi_decode_basic_elem(&data_len_value, buf_src,
+						   1, data_len_sz);
+			memcpy(buf_dst, &data_len_value, sizeof(u32));
+			temp_ei = temp_ei + 1;
+			buf_dst = out_c_struct + temp_ei->offset;
+			tlv_len -= data_len_sz;
+			UPDATE_DECODE_VARIABLES(buf_src, decoded_bytes, rc);
+		}
+
+		if (temp_ei->array_type == NO_ARRAY) {
+			data_len_value = 1;
+		} else if (temp_ei->array_type == STATIC_ARRAY) {
+			data_len_value = temp_ei->elem_len;
+		} else if (data_len_value > temp_ei->elem_len) {
+			pr_err("%s: Data len %d > max spec %d\n",
+			       __func__, data_len_value, temp_ei->elem_len);
+			return -ETOOSMALL;
+		}
+
+		switch (temp_ei->data_type) {
+		case QMI_UNSIGNED_1_BYTE:
+		case QMI_UNSIGNED_2_BYTE:
+		case QMI_UNSIGNED_4_BYTE:
+		case QMI_UNSIGNED_8_BYTE:
+		case QMI_SIGNED_2_BYTE_ENUM:
+		case QMI_SIGNED_4_BYTE_ENUM:
+			rc = qmi_decode_basic_elem(buf_dst, buf_src,
+						   data_len_value,
+						   temp_ei->elem_size);
+			UPDATE_DECODE_VARIABLES(buf_src, decoded_bytes, rc);
+			break;
+
+		case QMI_STRUCT:
+			rc = qmi_decode_struct_elem(temp_ei, buf_dst, buf_src,
+						    data_len_value, tlv_len,
+						    dec_level + 1);
+			if (rc < 0)
+				return rc;
+			UPDATE_DECODE_VARIABLES(buf_src, decoded_bytes, rc);
+			break;
+
+		case QMI_STRING:
+			rc = qmi_decode_string_elem(temp_ei, buf_dst, buf_src,
+						    tlv_len, dec_level);
+			if (rc < 0)
+				return rc;
+			UPDATE_DECODE_VARIABLES(buf_src, decoded_bytes, rc);
+			break;
+
+		default:
+			pr_err("%s: Unrecognized data type\n", __func__);
+			return -EINVAL;
+		}
+		temp_ei = temp_ei + 1;
+	}
+
+	return decoded_bytes;
+}
+
+/**
+ * qmi_encode_message() - Encode C structure as QMI encoded message
+ * @type:	Type of QMI message
+ * @msg_id:	Message ID of the message
+ * @len:	Passed as max length of the message, updated to actual size
+ * @txn_id:	Transaction ID
+ * @ei:		QMI message descriptor
+ * @c_struct:	Reference to structure to encode
+ *
+ * Return: Buffer with encoded message, or negative ERR_PTR() on error
+ */
+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);
+		}
+	}
+
+	msg = kzalloc(sizeof(*hdr) + *len, GFP_KERNEL);
+	if (!msg)
+		return ERR_PTR(-ENOMEM);
+
+	/* Encode message, if we have a message */
+	if (c_struct) {
+		msglen = qmi_encode(ei, msg + sizeof(*hdr), c_struct, *len, 1);
+		if (msglen < 0) {
+			kfree(msg);
+			return ERR_PTR(msglen);
+		}
+	}
+
+	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);
+
+/**
+ * qmi_decode_message() - Decode QMI encoded message to C structure
+ * @buf:	Buffer with encoded message
+ * @len:	Amount of data in @buf
+ * @ei:		QMI message descriptor
+ * @c_struct:	Reference to structure to decode into
+ *
+ * Return: The number of bytes of decoded information on success, negative
+ * errno on error.
+ */
+int qmi_decode_message(const void *buf, size_t len,
+		       struct qmi_elem_info *ei, void *c_struct)
+{
+	if (!ei)
+		return -EINVAL;
+
+	if (!c_struct || !buf || !len)
+		return -EINVAL;
+
+	return qmi_decode(ei, c_struct, buf + sizeof(struct qmi_header),
+			  len - sizeof(struct qmi_header), 1);
+}
+EXPORT_SYMBOL(qmi_decode_message);
+
+/* Common header in all QMI responses */
+struct qmi_elem_info qmi_response_type_v01_ei[] = {
+	{
+		.data_type	= QMI_SIGNED_2_BYTE_ENUM,
+		.elem_len	= 1,
+		.elem_size	= sizeof(u16),
+		.array_type	= NO_ARRAY,
+		.tlv_type	= QMI_COMMON_TLV_TYPE,
+		.offset		= offsetof(struct qmi_response_type_v01, result),
+		.ei_array	= NULL,
+	},
+	{
+		.data_type	= QMI_SIGNED_2_BYTE_ENUM,
+		.elem_len	= 1,
+		.elem_size	= sizeof(u16),
+		.array_type	= NO_ARRAY,
+		.tlv_type	= QMI_COMMON_TLV_TYPE,
+		.offset		= offsetof(struct qmi_response_type_v01, error),
+		.ei_array	= NULL,
+	},
+	{
+		.data_type	= QMI_EOTI,
+		.elem_len	= 0,
+		.elem_size	= 0,
+		.array_type	= NO_ARRAY,
+		.tlv_type	= QMI_COMMON_TLV_TYPE,
+		.offset		= 0,
+		.ei_array	= NULL,
+	},
+};
+EXPORT_SYMBOL(qmi_response_type_v01_ei);
+
+MODULE_DESCRIPTION("QMI encoder/decoder helper");
+MODULE_LICENSE("GPL v2");
include/linux/soc/qcom/qmi.h new file +114 -0
new file mode 100644
index 000000000000..1b66e9a6074f
@@ -0,0 +1,114 @@
+/*
+ * 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.
+ *
+ * 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/types.h>
+
+/**
+ * qmi_header - wireformat header of QMI messages
+ * @type:	type of message
+ * @txn_id:	transaction id
+ * @msg_id:	message id
+ * @msg_len:	length of message payload following header
+ */
+struct qmi_header {
+	u8 type;
+	u16 txn_id;
+	u16 msg_id;
+	u16 msg_len;
+} __packed;
+
+#define QMI_REQUEST	0
+#define QMI_RESPONSE	2
+#define QMI_INDICATION	4
+
+#define QMI_COMMON_TLV_TYPE 0
+
+enum qmi_elem_type {
+	QMI_EOTI,
+	QMI_OPT_FLAG,
+	QMI_DATA_LEN,
+	QMI_UNSIGNED_1_BYTE,
+	QMI_UNSIGNED_2_BYTE,
+	QMI_UNSIGNED_4_BYTE,
+	QMI_UNSIGNED_8_BYTE,
+	QMI_SIGNED_2_BYTE_ENUM,
+	QMI_SIGNED_4_BYTE_ENUM,
+	QMI_STRUCT,
+	QMI_STRING,
+};
+
+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.
+ * @array_type:	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.
+ */
+struct qmi_elem_info {
+	enum qmi_elem_type data_type;
+	u32 elem_len;
+	u32 elem_size;
+	enum qmi_array_type array_type;
+	u8 tlv_type;
+	u32 offset;
+	struct qmi_elem_info *ei_array;
+};
+
+#define QMI_RESULT_SUCCESS_V01			0
+#define QMI_RESULT_FAILURE_V01			1
+
+#define QMI_ERR_NONE_V01			0
+#define QMI_ERR_MALFORMED_MSG_V01		1
+#define QMI_ERR_NO_MEMORY_V01			2
+#define QMI_ERR_INTERNAL_V01			3
+#define QMI_ERR_CLIENT_IDS_EXHAUSTED_V01	5
+#define QMI_ERR_INVALID_ID_V01			41
+#define QMI_ERR_ENCODING_V01			58
+#define QMI_ERR_INCOMPATIBLE_STATE_V01		90
+#define QMI_ERR_NOT_SUPPORTED_V01		94
+
+/**
+ * qmi_response_type_v01 - common response header (decoded)
+ * @result:	result of the transaction
+ * @error:	error value, when @result is QMI_RESULT_FAILURE_V01
+ */
+struct qmi_response_type_v01 {
+	u16 result;
+	u16 error;
+};
+
+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);
+
+#endif
#4 lore raw

Re: [PATCH v4 1/5] soc: qcom: Introduce QMI encoder/decoder

Quoted 2 lines · Jitendra Sharma

Hi Bjorn,

Hi Jitendra,

Quoted 6 lines · Bjorn Andersson

drivers/soc/qcom/qmi_encdec.c line 117

Quoted 4 lines
drivers/soc/qcom/qmi_encdec.c new file +4 -0
+static int qmi_calc_min_msg_len(struct qmi_elem_info *ei_array,
+				int level)
+{
+	int min_msg_len = 0;

min_msg_len should be u32 as it would not be negative

IMHO all these sizes should be size_t and there are a few places where we should add "const" specifier to pointers. But I refrained from "fixing" these up in an effort to keep things as close to the downstream implementation as possible.

If Andy agrees I'm hoping that we can take this version and then follow up with a separate patch, making the review more explicit and make it easier to track down any potential regressions from such a change.

Thank you for the review!

Regards,
Bjorn

#5 lore raw

PATCH v4 2/5 soc: qcom: Introduce QMI helpers

In reply to 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.

---

Changes since v3:
- Don't invoke handler for responses without registered txn
- Kerneldoc updates
- Make qmi_handle_init parameters const
- Added appropriate includes and forward declarations in header file

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/Makefile        |   2 +-
 drivers/soc/qcom/qmi_interface.c | 857 +++++++++++++++++++++++++++++++++++++++
 include/linux/soc/qcom/qmi.h     | 165 ++++++++
 3 files changed, 1023 insertions(+), 1 deletion(-)
 create mode 100644 drivers/soc/qcom/qmi_interface.c
drivers/soc/qcom/Makefile +1 -1
index 37f85b45d0a1..dcebf2814e6d 100644
@@ -4,7 +4,7 @@ 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
+qmi_helpers-y	+= qmi_encdec.o qmi_interface.o
 obj-$(CONFIG_QCOM_RMTFS_MEM)	+= rmtfs_mem.o
 obj-$(CONFIG_QCOM_SMD_RPM)	+= smd-rpm.o
 obj-$(CONFIG_QCOM_SMEM) +=	smem.o
drivers/soc/qcom/qmi_interface.c new file +857 -0

857 lines not on this page · raw message

include/linux/soc/qcom/qmi.h +165 -0

182 lines not on this page · raw message

Signature · 1 line
2.15.0
#6 lore raw

Re: [PATCH v4 2/5] soc: qcom: Introduce QMI helpers

Bjorn,

On Thu, Nov 30, 2017 at 2:16 AM, Bjorn Andersson
<[email protected]> wrote:
[]

Quoted 8 lines
drivers/soc/qcom/qmi_interface.c new file +2 -0
new file mode 100644
index 000000000000..4027b52b0834
@@ -0,0 +1,857 @@
+/*
+ * Copyright (C) 2017 Linaro Ltd.

drivers/soc/qcom/qmi_interface.c line 12

Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10 -0
+ *
+ * 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.
+ *
+ * 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.
+ */

Could it make sense, especially for new files, to use the new SPDX ids and avoid adding boilerplate that will need to be cleaned up later? e.g. something like this instead, using the new conventions started by greg-kh and by documented tglx?

NB: the // comment style is not a mistake and is what Linus wants there. See the threads on this topic.

drivers/soc/qcom/qmi_interface.c line 4

Quoted 5 lines
drivers/soc/qcom/qmi_interface.c new file +4 -0
@@ -0,0 +1,857 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2017 Linaro Ltd.
+ */

Isn't this shorter and better? :P

BTW, if you need help to fix this on the rest of Linaro contributed code, I maintain a tool that can help there.

Signature · 2 lines
Cordially
Philippe Ombredanne, the licensing janitor bot
#7 lore raw

Re: [PATCH v4 2/5] soc: qcom: Introduce QMI helpers

Quoted 32 lines · Philippe Ombredanne

Bjorn,

On Thu, Nov 30, 2017 at 2:16 AM, Bjorn Andersson
<[email protected]> wrote:
[]

Quoted 8 lines
drivers/soc/qcom/qmi_interface.c new file +2 -0
new file mode 100644
index 000000000000..4027b52b0834
@@ -0,0 +1,857 @@
+/*
+ * Copyright (C) 2017 Linaro Ltd.

drivers/soc/qcom/qmi_interface.c line 12

Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10 -0
+ *
+ * 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.
+ *
+ * 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.
+ */

Could it make sense, especially for new files, to use the new SPDX ids and avoid adding boilerplate that will need to be cleaned up later? e.g. something like this instead, using the new conventions started by greg-kh and by documented tglx?

NB: the // comment style is not a mistake and is what Linus wants there. See the threads on this topic.

Quoted 8 lines

drivers/soc/qcom/qmi_interface.c line 4

Quoted 5 lines
drivers/soc/qcom/qmi_interface.c new file +4 -0
@@ -0,0 +1,857 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2017 Linaro Ltd.
+ */

Isn't this shorter and better? :P

That sounds very reasonable, I will update the patches.

Quoted 3 lines

BTW, if you need help to fix this on the rest of Linaro contributed code, I maintain a tool that can help there.

I haven't seen any guidelines on how this should be introduced throughout the kernel, should I make a similar push for the subsystems I maintain?

Regards,
Bjorn

#8 lore raw

Re: [PATCH v4 2/5] soc: qcom: Introduce QMI helpers

Quoted 43 lines · Bjorn Andersson
Quoted 32 lines · Philippe Ombredanne

Bjorn,

On Thu, Nov 30, 2017 at 2:16 AM, Bjorn Andersson
<[email protected]> wrote:
[]

Quoted 8 lines
drivers/soc/qcom/qmi_interface.c new file +2 -0
new file mode 100644
index 000000000000..4027b52b0834
@@ -0,0 +1,857 @@
+/*
+ * Copyright (C) 2017 Linaro Ltd.

drivers/soc/qcom/qmi_interface.c line 12

Quoted 10 lines
drivers/soc/qcom/qmi_interface.c new file +10 -0
+ *
+ * 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.
+ *
+ * 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.
+ */

Could it make sense, especially for new files, to use the new SPDX ids and avoid adding boilerplate that will need to be cleaned up later? e.g. something like this instead, using the new conventions started by greg-kh and by documented tglx?

NB: the // comment style is not a mistake and is what Linus wants there. See the threads on this topic.

Quoted 8 lines

drivers/soc/qcom/qmi_interface.c line 4

Quoted 5 lines
drivers/soc/qcom/qmi_interface.c new file +4 -0
@@ -0,0 +1,857 @@
+// SPDX-License-Identifier: GPL-2.0
+/*
+ * Copyright (C) 2017 Linaro Ltd.
+ */

Isn't this shorter and better? :P

Quoted 1 line

That sounds very reasonable, I will update the patches.

Note that when you only have a copyright left in a header comment after removing the boilerplate, you might want to consider this even shorter and cleaner form instead. But that's just me telling this:

Quoted 9 lines
Quoted 6 lines

drivers/soc/qcom/qmi_interface.c line 6

Quoted 2 lines
drivers/soc/qcom/qmi_interface.c new file +2 -0
+// SPDX-License-Identifier: GPL-2.0
+// Copyright (C) 2017 Linaro Ltd.

BTW, if you need help to fix this on the rest of Linaro contributed code, I maintain a tool that can help there.

I haven't seen any guidelines on how this should be introduced throughout the kernel,

Thomas has sent a first doc patch [1] set. AFAIK he is working on an updated version whenever his real time body clock yields a few ticks so he can wrap this out. But his real time clock only rarely yield ticks outside of hard real time coding work ;)

Jonathan also wrote a nice background article on the topic at LWN [2].

I heard this was also briefly discussed among maintainers at the plumbers meetup in Los Angeles: for me I only briefly discussed this with Linus and Greg just before the meetup, but I could not stay longer.

Quoted 2 lines

should I make a similar push for the subsystems I
maintain?

That would be great! And beside the fact it always feels good to delete lines of code for once, this is one of the rare areas where you can kill some lines and be pretty sure it will still compile and run afterwards .... well.... in most cases: Greg and Thomas found funny cases of .h headers included in assembly where using the // comment style was actually making things break weirdly and the compilation would go down in flames with a beautiful tail spin : in these cases, the convention is to use /**/ comments instead)

Again, if you need help with this, I can modestly chip in with my scancode-toolkit tool and good intentions.

[1] https://marc.info/?l=linux-kernel&m=151051532322831&w=2
[2] https://lwn.net/SubscriberLink/739183/262749cbe307ddc7/

Signature · 2 lines
Cordially
Philippe Ombredanne, a happy licensing comments cleaner
Acked-by on v4 2/5
#9 lore raw

Re: [PATCH v4 2/5] soc: qcom: Introduce QMI helpers

In reply to Bjorn Andersson
Quoted 8 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.

---

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#10 lore raw

PATCH v4 3/5 remoteproc: Pass type of shutdown to subdev remove

In reply to Bjorn Andersson

remoteproc 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 v3:
- None

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
index d487040b528b..7a862d41503e 100644
@@ -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
index eab14b414bf0..3146e965ca47 100644
@@ -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
index 44e630eb3d94..20a9467744ea 100644
@@ -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
Acked-by on v4 3/5
#11 lore raw

Re: [PATCH v4 3/5] remoteproc: Pass type of shutdown to subdev remove

Quoted 7 lines · Bjorn Andersson

remoteproc 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.

---

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#12 lore raw

Re: [PATCH v4 3/5] remoteproc: Pass type of shutdown to subdev remove

In reply to Bjorn Andersson

hello Bjorn,

Sorry for these late remarks/questions

Quoted 67 lines · Bjorn Andersson

remoteproc 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 v3:
- None

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
index d487040b528b..7a862d41503e 100644
@@ -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 +1 -1
index eab14b414bf0..3146e965ca47 100644
@@ -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);
 

drivers/remoteproc/remoteproc_core.c static int rproc_probe_subdevices(struct rproc *rproc) · line 788

Quoted 5 lines
drivers/remoteproc/remoteproc_core.c +1 -1
@@ -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);

Why do you need to do a non graceful remove in this case? This could lead to side effect like memory leakage...

Quoted 63 lines
drivers/remoteproc/remoteproc_core.c +7 -7
 	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 +0 -0
index 44e630eb3d94..20a9467744ea 100644

include/linux/remoteproc.h struct rproc_subdev { · line 459

Quoted 5 lines
include/linux/remoteproc.h +1 -1
@@ -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);

What about adding a new ops instead of a parameter, like a recovery callback?

Regard
Arnaud

Quoted 13 lines
include/linux/remoteproc.h +1 -1
 };
 
 /* 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);
 
#13 lore raw

Re: [PATCH v4 3/5] remoteproc: Pass type of shutdown to subdev remove

Quoted 4 lines · Arnaud Pouliquen

hello Bjorn,

Sorry for these late remarks/questions

No worries, I'm happy to see you reading the patch!

Quoted 2 lines · Bjorn Andersson

[..]

Quoted 1 line
Quoted 1 line
drivers/remoteproc/qcom_common.c +0 -0

[..]

Quoted 9 lines

drivers/remoteproc/qcom_common.c static int rproc_probe_subdevices(struct rproc *rproc) · line 788

Quoted 6 lines
drivers/remoteproc/qcom_common.c +1 -1
@@ -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);

Why do you need to do a non graceful remove in this case? This could lead to side effect like memory leakage...

Regardless of this being true or false resources should always be reclaimed.

The reason for introducing this is that the modem in the Qualcomm platforms implements persistent storage and it's preferred to tell it to flush the latest data to the storage server (on the Linux side) before pulling the plug. But in the case of a firmware crash this mechanism will not be operational and there's no point in attempting this "graceful shutdown".

[..]

Quoted 7 lines
Quoted 7 lines
include/linux/remoteproc.h +0 -0
index 44e630eb3d94..20a9467744ea 100644
@@ -456,7 +456,7 @@ struct rproc_subdev {
 	struct list_head node;
 
Quoted 6 lines

include/linux/remoteproc.h struct rproc_subdev { · line 459

Quoted 3 lines
include/linux/remoteproc.h +1 -1
 	int (*probe)(struct rproc_subdev *subdev);
-	void (*remove)(struct rproc_subdev *subdev);
+	void (*remove)(struct rproc_subdev *subdev, bool graceful);

What about adding a new ops instead of a parameter, like a recovery callback?

I think that for symmetry purposes it should be probe/remove in both code paths. A possible alternative to the proposal would be to introduce an operation "request_shutdown()" the would be called in the proposed graceful code path.

However, in the Qualcomm SMD and GLINK (conceptually equivalent to virtio-rpmsg) it is possible to open and close communication channels and it's conceivable to see that the graceful case would close all channels cleanly while the non-graceful case would just remove the rpmsg devices (and leave the channel states/memory as is).

In this case a "request_shutdown()" would complicate things, compared to the boolean.

Regards,
Bjorn

#14 lore raw

Re: [PATCH v4 3/5] remoteproc: Pass type of shutdown to subdev remove

Quoted 27 lines · Bjorn Andersson
Quoted 4 lines · Arnaud Pouliquen

hello Bjorn,

Sorry for these late remarks/questions

No worries, I'm happy to see you reading the patch!

Quoted 2 lines · Bjorn Andersson

[..]

Quoted 1 line
Quoted 1 line
drivers/remoteproc/qcom_common.c +0 -0

[..]

Quoted 9 lines

drivers/remoteproc/qcom_common.c static int rproc_probe_subdevices(struct rproc *rproc) · line 788

Quoted 6 lines
drivers/remoteproc/qcom_common.c +1 -1
@@ -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);

Why do you need to do a non graceful remove in this case? This could lead to side effect like memory leakage...

Regardless of this being true or false resources should always be reclaimed.

Quoted 6 lines

The reason for introducing this is that the modem in the Qualcomm platforms implements persistent storage and it's preferred to tell it to flush the latest data to the storage server (on the Linux side) before pulling the plug. But in the case of a firmware crash this mechanism will not be operational and there's no point in attempting this "graceful shutdown".

I understand your usecase for Qualcomm, but in rproc_probe_subdevices there is not crash of the remote firmware , so remove should be graceful.

Quoted 22 lines

[..]

Quoted 7 lines
Quoted 7 lines
include/linux/remoteproc.h +0 -0
index 44e630eb3d94..20a9467744ea 100644
@@ -456,7 +456,7 @@ struct rproc_subdev {
 	struct list_head node;
 
Quoted 6 lines

include/linux/remoteproc.h struct rproc_subdev { · line 459

Quoted 3 lines
include/linux/remoteproc.h +1 -1
 	int (*probe)(struct rproc_subdev *subdev);
-	void (*remove)(struct rproc_subdev *subdev);
+	void (*remove)(struct rproc_subdev *subdev, bool graceful);

What about adding a new ops instead of a parameter, like a recovery callback?

I think that for symmetry purposes it should be probe/remove in both code paths. A possible alternative to the proposal would be to introduce an operation "request_shutdown()" the would be called in the proposed graceful code path.

Quoted 9 lines

However, in the Qualcomm SMD and GLINK (conceptually equivalent to virtio-rpmsg) it is possible to open and close communication channels and it's conceivable to see that the graceful case would close all channels cleanly while the non-graceful case would just remove the rpmsg devices (and leave the channel states/memory as is).

In this case a "request_shutdown()" would complicate things, compared to the boolean.

I would be more for a specific ops that inform sub-dev on a crash. This would allow sub-dev to perform specific action (for instance dump) and store crash information, then on remove, sub_dev would perform specific action.
This could be something like "trigger_recovery" that is propagated to the sub-dev.

That would sound more flexible from my point of view.

Regards
Arnaud

Quoted 3 lines

Regards,
Bjorn

#15 lore raw

Re: [PATCH v4 3/5] remoteproc: Pass type of shutdown to subdev remove

Quoted 30 lines · Arnaud Pouliquen
Quoted 27 lines · Bjorn Andersson
Quoted 4 lines · Arnaud Pouliquen

hello Bjorn,

Sorry for these late remarks/questions

No worries, I'm happy to see you reading the patch!

Quoted 2 lines · Bjorn Andersson

[..]

Quoted 1 line
Quoted 1 line
drivers/remoteproc/qcom_common.c +0 -0

[..]

Quoted 9 lines

drivers/remoteproc/qcom_common.c static int rproc_probe_subdevices(struct rproc *rproc) · line 788

Quoted 6 lines
drivers/remoteproc/qcom_common.c +1 -1
@@ -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);

Why do you need to do a non graceful remove in this case? This could lead to side effect like memory leakage...

Regardless of this being true or false resources should always be reclaimed.

Quoted 9 lines
Quoted 6 lines

The reason for introducing this is that the modem in the Qualcomm platforms implements persistent storage and it's preferred to tell it to flush the latest data to the storage server (on the Linux side) before pulling the plug. But in the case of a firmware crash this mechanism will not be operational and there's no point in attempting this "graceful shutdown".

I understand your usecase for Qualcomm, but in rproc_probe_subdevices there is not crash of the remote firmware , so remove should be graceful.

Now I get your point, sorry. I agree with you, as this is triggering a clean stop of the system this should be marked "graceful".

Will update, thanks.

Quoted 28 lines
Quoted 28 lines

[..]

Quoted 7 lines
Quoted 7 lines
include/linux/remoteproc.h +0 -0
index 44e630eb3d94..20a9467744ea 100644
@@ -456,7 +456,7 @@ struct rproc_subdev {
 	struct list_head node;
 
Quoted 6 lines

include/linux/remoteproc.h struct rproc_subdev { · line 459

Quoted 3 lines
include/linux/remoteproc.h +1 -1
 	int (*probe)(struct rproc_subdev *subdev);
-	void (*remove)(struct rproc_subdev *subdev);
+	void (*remove)(struct rproc_subdev *subdev, bool graceful);

What about adding a new ops instead of a parameter, like a recovery callback?

I think that for symmetry purposes it should be probe/remove in both code paths. A possible alternative to the proposal would be to introduce an operation "request_shutdown()" the would be called in the proposed graceful code path.

However, in the Qualcomm SMD and GLINK (conceptually equivalent to virtio-rpmsg) it is possible to open and close communication channels and it's conceivable to see that the graceful case would close all channels cleanly while the non-graceful case would just remove the rpmsg devices (and leave the channel states/memory as is).

Quoted 7 lines
Quoted 3 lines

In this case a "request_shutdown()" would complicate things, compared to the boolean.

I would be more for a specific ops that inform sub-dev on a crash. This would allow sub-dev to perform specific action (for instance dump) and store crash information, then on remove, sub_dev would perform specific action.

There is a separate discussion (although dormant) on how to gather core dumps, which should cover these cases.

Quoted 3 lines

This could be something like "trigger_recovery" that is propagated to the sub-dev.

Right, this step does make sense, but is the opposite of what I need - i.e. a means to trigger a clean shutdown.

Quoted 2 lines

That would sound more flexible from my point of view.

At this point I see this flexibility as unnecessary complexity, if such need show up (beyond the core dump gathering) we should bring this up again.

Regards,
Bjorn

#16 lore raw

Re: [PATCH v4 3/5] remoteproc: Pass type of shutdown to subdev remove

Hello,

I saw your new version but i 'm answering to this one to continue discussion.

Quoted 86 lines · Bjorn Andersson
Quoted 30 lines · Arnaud Pouliquen
Quoted 27 lines · Bjorn Andersson
Quoted 4 lines · Arnaud Pouliquen

hello Bjorn,

Sorry for these late remarks/questions

No worries, I'm happy to see you reading the patch!

Quoted 2 lines · Bjorn Andersson

[..]

Quoted 1 line
Quoted 1 line
drivers/remoteproc/qcom_common.c +0 -0

[..]

Quoted 9 lines

drivers/remoteproc/qcom_common.c static int rproc_probe_subdevices(struct rproc *rproc) · line 788

Quoted 6 lines
drivers/remoteproc/qcom_common.c +1 -1
@@ -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);

Why do you need to do a non graceful remove in this case? This could lead to side effect like memory leakage...

Regardless of this being true or false resources should always be reclaimed.

Quoted 9 lines
Quoted 6 lines

The reason for introducing this is that the modem in the Qualcomm platforms implements persistent storage and it's preferred to tell it to flush the latest data to the storage server (on the Linux side) before pulling the plug. But in the case of a firmware crash this mechanism will not be operational and there's no point in attempting this "graceful shutdown".

I understand your usecase for Qualcomm, but in rproc_probe_subdevices there is not crash of the remote firmware , so remove should be graceful.

Now I get your point, sorry. I agree with you, as this is triggering a clean stop of the system this should be marked "graceful".

Will update, thanks.

Quoted 28 lines
Quoted 28 lines

[..]

Quoted 7 lines
Quoted 7 lines
include/linux/remoteproc.h +0 -0
index 44e630eb3d94..20a9467744ea 100644
@@ -456,7 +456,7 @@ struct rproc_subdev {
 	struct list_head node;
 
Quoted 6 lines

include/linux/remoteproc.h struct rproc_subdev { · line 459

Quoted 3 lines
include/linux/remoteproc.h +1 -1
 	int (*probe)(struct rproc_subdev *subdev);
-	void (*remove)(struct rproc_subdev *subdev);
+	void (*remove)(struct rproc_subdev *subdev, bool graceful);

What about adding a new ops instead of a parameter, like a recovery callback?

I think that for symmetry purposes it should be probe/remove in both code paths. A possible alternative to the proposal would be to introduce an operation "request_shutdown()" the would be called in the proposed graceful code path.

However, in the Qualcomm SMD and GLINK (conceptually equivalent to virtio-rpmsg) it is possible to open and close communication channels and it's conceivable to see that the graceful case would close all channels cleanly while the non-graceful case would just remove the rpmsg devices (and leave the channel states/memory as is).

Quoted 7 lines
Quoted 3 lines

In this case a "request_shutdown()" would complicate things, compared to the boolean.

I would be more for a specific ops that inform sub-dev on a crash. This would allow sub-dev to perform specific action (for instance dump) and store crash information, then on remove, sub_dev would perform specific action.

There is a separate discussion (although dormant) on how to gather core dumps, which should cover these cases.

Quoted 6 lines
Quoted 3 lines

This could be something like "trigger_recovery" that is propagated to the sub-dev.

Right, this step does make sense, but is the opposite of what I need - i.e. a means to trigger a clean shutdown.

Could you clarify this point? i do not see my proposal as the opposite. In your proposal:
- rproc_trigger_recovery: graceful is set to false
- rproc_shutdown: Graceful is set to true

My proposal is to call an new ops (if defined) before the stop in rproc_trigger_recovery. If you set a local variable in Qualcomm subdev drivers this should do the job for your need.

I tried to have a look in Qualcomm part to understand implementation. but seems that you just add the parameter for time being.

I think that main point that bother me here, is the that the "graceful" mode should be the normal mode. And in your implementation this look like the exception mode. Perhaps more a feeling than anything else...but if you decide to keep argument i would propose to inverse logic using something like "rproc_crashed" instead of "graceful".

Quoted 7 lines
Quoted 3 lines

That would sound more flexible from my point of view.

At this point I see this flexibility as unnecessary complexity, if such need show up (beyond the core dump gathering) we should bring this up again.

I let you decide what is the best solution.
My concerns is to be sure that your solution is enough generic and not too Qualcomm platform oriented. As you mentioned in OpenAMP meeting it is quite difficult to come back on an implementation , especially if it impacts the API.

Regards
Arnaud

Quoted 4 lines

Regards,
Bjorn

#17 lore raw

Re: [PATCH v4 3/5] remoteproc: Pass type of shutdown to subdev remove

Quoted 5 lines · Arnaud Pouliquen

Hello,

I saw your new version but i 'm answering to this one to continue discussion.

That's fine.

Quoted 45 lines · Bjorn Andersson
Quoted 44 lines · Arnaud Pouliquen
Quoted 28 lines · Bjorn Andersson
Quoted 27 lines · Arnaud Pouliquen
Quoted 7 lines
Quoted 7 lines
include/linux/remoteproc.h +0 -0
index 44e630eb3d94..20a9467744ea 100644
@@ -456,7 +456,7 @@ struct rproc_subdev {
 	struct list_head node;
 
Quoted 6 lines

include/linux/remoteproc.h struct rproc_subdev { · line 459

Quoted 3 lines
include/linux/remoteproc.h +1 -1
 	int (*probe)(struct rproc_subdev *subdev);
-	void (*remove)(struct rproc_subdev *subdev);
+	void (*remove)(struct rproc_subdev *subdev, bool graceful);

What about adding a new ops instead of a parameter, like a recovery callback?

I think that for symmetry purposes it should be probe/remove in both code paths. A possible alternative to the proposal would be to introduce an operation "request_shutdown()" the would be called in the proposed graceful code path.

However, in the Qualcomm SMD and GLINK (conceptually equivalent to virtio-rpmsg) it is possible to open and close communication channels and it's conceivable to see that the graceful case would close all channels cleanly while the non-graceful case would just remove the rpmsg devices (and leave the channel states/memory as is).

Quoted 7 lines
Quoted 3 lines

In this case a "request_shutdown()" would complicate things, compared to the boolean.

I would be more for a specific ops that inform sub-dev on a crash. This would allow sub-dev to perform specific action (for instance dump) and store crash information, then on remove, sub_dev would perform specific action.

There is a separate discussion (although dormant) on how to gather core dumps, which should cover these cases.

Quoted 3 lines

This could be something like "trigger_recovery" that is propagated to the sub-dev.

Quoted 7 lines
Quoted 2 lines

Right, this step does make sense, but is the opposite of what I need - i.e. a means to trigger a clean shutdown.

Could you clarify this point? i do not see my proposal as the opposite. In your proposal:
- rproc_trigger_recovery: graceful is set to false
- rproc_shutdown: Graceful is set to true

Correct

Quoted 4 lines

My proposal is to call an new ops (if defined) before the stop in rproc_trigger_recovery. If you set a local variable in Qualcomm subdev drivers this should do the job for your need.

In all use cases that comes to mind the gracefulness makes one step of the teardown operation kick in/be optional, it's not a separate operation. I don't see the benefit of enforcing the subdev to keep this state.

Quoted 3 lines

I tried to have a look in Qualcomm part to understand implementation. but seems that you just add the parameter for time being.

The following patch, adding sysmon, make use of this. But I have yet to post patches that affects the SMD and GLINK implementations.

Quoted 3 lines

I think that main point that bother me here, is the that the "graceful" mode should be the normal mode. And in your implementation this look like the exception mode.

I agree, I consider the recovery path to be the exception, but I'm not seeing the necessity of making the "true" state of this parameter mean "yes we have an exception".

Regardless of the value here, the remove() function's purpose is to clean up resources/state. But in the case of a graceful shutdown (i.e. not recovery path) the subdevices can be expected to tear things down in a fashion that permits the remote side to act, so if anything this "true" would imply that this extra steps should be taken.

Quoted 4 lines

Perhaps more a feeling than anything else...but if you decide to keep argument i would propose to inverse logic using something like "rproc_crashed" instead of "graceful".

The difference between "this is a graceful shutdown, let's inform the remote" and "this is not a crash, let's inform the remote". The prior sounds much more to the point in my view.

Quoted 11 lines
Quoted 7 lines
Quoted 3 lines

That would sound more flexible from my point of view.

At this point I see this flexibility as unnecessary complexity, if such need show up (beyond the core dump gathering) we should bring this up again.

I let you decide what is the best solution.
My concerns is to be sure that your solution is enough generic and not too Qualcomm platform oriented.

That's a fair concern. I'm very interested in finding more complex use cases that requires this type of logic, to see if this is generic enough.

Note that the discussions that we've had related to e.g. clocks that should be on during the life of the remote would not fit into the current subdev life cycle anyways, so this either needs to be complemented or extended.

Quoted 3 lines

As you mentioned in OpenAMP meeting it is quite difficult to come back on an implementation , especially if it impacts the API.

No, what I said is that it's impossible to go back once we have changed the file format, the interface towards the remote or the interface towards user space. All it takes to change an interface within the kernel is a single patch.

Regards,
Bjorn

#18 lore raw

Re: [PATCH v4 3/5] remoteproc: Pass type of shutdown to subdev remove

Quoted 96 lines · Bjorn Andersson
Quoted 5 lines · Arnaud Pouliquen

Hello,

I saw your new version but i 'm answering to this one to continue discussion.

That's fine.

Quoted 45 lines · Bjorn Andersson
Quoted 44 lines · Arnaud Pouliquen
Quoted 28 lines · Bjorn Andersson
Quoted 27 lines · Arnaud Pouliquen
Quoted 7 lines
Quoted 7 lines
include/linux/remoteproc.h +0 -0
index 44e630eb3d94..20a9467744ea 100644
@@ -456,7 +456,7 @@ struct rproc_subdev {
 	struct list_head node;
 
Quoted 6 lines

include/linux/remoteproc.h struct rproc_subdev { · line 459

Quoted 3 lines
include/linux/remoteproc.h +1 -1
 	int (*probe)(struct rproc_subdev *subdev);
-	void (*remove)(struct rproc_subdev *subdev);
+	void (*remove)(struct rproc_subdev *subdev, bool graceful);

What about adding a new ops instead of a parameter, like a recovery callback?

I think that for symmetry purposes it should be probe/remove in both code paths. A possible alternative to the proposal would be to introduce an operation "request_shutdown()" the would be called in the proposed graceful code path.

However, in the Qualcomm SMD and GLINK (conceptually equivalent to virtio-rpmsg) it is possible to open and close communication channels and it's conceivable to see that the graceful case would close all channels cleanly while the non-graceful case would just remove the rpmsg devices (and leave the channel states/memory as is).

Quoted 7 lines
Quoted 3 lines

In this case a "request_shutdown()" would complicate things, compared to the boolean.

I would be more for a specific ops that inform sub-dev on a crash. This would allow sub-dev to perform specific action (for instance dump) and store crash information, then on remove, sub_dev would perform specific action.

There is a separate discussion (although dormant) on how to gather core dumps, which should cover these cases.

Quoted 3 lines

This could be something like "trigger_recovery" that is propagated to the sub-dev.

Quoted 7 lines
Quoted 2 lines

Right, this step does make sense, but is the opposite of what I need - i.e. a means to trigger a clean shutdown.

Could you clarify this point? i do not see my proposal as the opposite. In your proposal:
- rproc_trigger_recovery: graceful is set to false
- rproc_shutdown: Graceful is set to true

Correct

Quoted 4 lines

My proposal is to call an new ops (if defined) before the stop in rproc_trigger_recovery. If you set a local variable in Qualcomm subdev drivers this should do the job for your need.

In all use cases that comes to mind the gracefulness makes one step of the teardown operation kick in/be optional, it's not a separate operation. I don't see the benefit of enforcing the subdev to keep this state.

Quoted 3 lines

I tried to have a look in Qualcomm part to understand implementation. but seems that you just add the parameter for time being.

The following patch, adding sysmon, make use of this. But I have yet to post patches that affects the SMD and GLINK implementations.

Quoted 3 lines

I think that main point that bother me here, is the that the "graceful" mode should be the normal mode. And in your implementation this look like the exception mode.

I agree, I consider the recovery path to be the exception, but I'm not seeing the necessity of making the "true" state of this parameter mean "yes we have an exception".

Regardless of the value here, the remove() function's purpose is to clean up resources/state. But in the case of a graceful shutdown (i.e. not recovery path) the subdevices can be expected to tear things down in a fashion that permits the remote side to act, so if anything this "true" would imply that this extra steps should be taken.

Quoted 8 lines
Quoted 4 lines

Perhaps more a feeling than anything else...but if you decide to keep argument i would propose to inverse logic using something like "rproc_crashed" instead of "graceful".

The difference between "this is a graceful shutdown, let's inform the remote" and "this is not a crash, let's inform the remote". The prior sounds much more to the point in my view.

On the other hand, i consider "graceful" as a normal mode that is implemented in kernel. By informing sub-dev that "this is a graceful shutdown", you just precise a behavior that is already implemented by default.
And in case of recovery, you inform sub-dev that "this is not a graceful shutdown". What does it means "this is not a graceful shutdown"?...This is confusing, from my point of view.

for this reason, I still don't like the "graceful" wording too much, but this is a personal feeling, not a strong argument. :)
So, if you are not convince by my last argument and nobody else comments, consider it as OK for me.

Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 4 lines

That would sound more flexible from my point of view.

Quoted 7 lines
Quoted 3 lines

At this point I see this flexibility as unnecessary complexity, if such need show up (beyond the core dump gathering) we should bring this up again.

I let you decide what is the best solution.
My concerns is to be sure that your solution is enough generic and not too Qualcomm platform oriented.

Quoted 9 lines

That's a fair concern. I'm very interested in finding more complex use cases that requires this type of logic, to see if this is generic enough.

Note that the discussions that we've had related to e.g. clocks that should be on during the life of the remote would not fit into the current subdev life cycle anyways, so this either needs to be complemented or extended.

Today the only other use case, i would have in mind (except dump) is the management of a "hot" restart on a crash... but no concrete example.

Quoted 9 lines
Quoted 3 lines

As you mentioned in OpenAMP meeting it is quite difficult to come back on an implementation , especially if it impacts the API.

No, what I said is that it's impossible to go back once we have changed the file format, the interface towards the remote or the interface towards user space. All it takes to change an interface within the kernel is a single patch.

Thanks for this clarification.

Regards,
Arnaud

Quoted 3 lines

Regards,
Bjorn

#19 lore raw

PATCH v4 4/5 remoteproc: qcom: Introduce sysmon

In reply to Bjorn Andersson

The 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 v3:
- Kerneldoc updates
- Style fixes

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   | 587 +++++++++++++++++++++++++++++++++++++
 drivers/remoteproc/qcom_wcnss.c    |   4 +
 7 files changed, 645 insertions(+)
 create mode 100644 drivers/remoteproc/qcom_sysmon.c
drivers/remoteproc/Kconfig +17 -0
index b609e1d3654b..6556df21318e 100644
@@ -90,6 +90,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
@@ -107,6 +108,7 @@ config QCOM_Q6V5_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_RPROC_COMMON
 	select QCOM_SCM
@@ -114,12 +116,27 @@ 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 RPMSG_QCOM_GLINK_SMEM || RPMSG_QCOM_GLINK_SMEM=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
index 6e16450ce11f..02627ede8d4a 100644
@@ -17,6 +17,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
index 3f6af54dbc96..45e7e66604d4 100644
@@ -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
index 832e20271664..541586e528b3 100644
@@ -4,6 +4,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;
@@ -41,4 +44,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
index 8a3fa2bcc9f6..342d5eb5d6ed 100644
@@ -168,6 +168,7 @@ struct q6v5 {
 
 	struct qcom_rproc_subdev smd_subdev;
 	struct qcom_rproc_ssr ssr_subdev;
+	struct qcom_sysmon *sysmon;
 	bool need_mem_protection;
 	int mpss_perm;
 	int mba_perm;
@@ -1231,6 +1232,7 @@ static int q6v5_probe(struct platform_device *pdev)
 	qproc->mba_perm = BIT(QCOM_SCM_VMID_HLOS);
 	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)
@@ -1250,6 +1252,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 +587 -0

587 lines not on this page · raw message

drivers/remoteproc/qcom_wcnss.c +4 -0
index c7686393d505..dc79239c43f9 100644
@@ -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
Acked-by on v4 4/5
#20 lore raw

Re: [PATCH v4 4/5] remoteproc: qcom: Introduce sysmon

Quoted 7 lines · Bjorn Andersson

The 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.

---

Looked into who is listening to the other notifications besides BEFORE_SHUTDOWN and I think subsequent patches will need to add support for at least AFTER_POWERUP.

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project
#21 lore raw

Re: [PATCH v4 4/5] remoteproc: qcom: Introduce sysmon

Quoted 12 lines · Chris Lew
Quoted 7 lines · Bjorn Andersson

The 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.

---

Thanks

Quoted 4 lines

Looked into who is listening to the other notifications besides BEFORE_SHUTDOWN and I think subsequent patches will need to add support for at least AFTER_POWERUP.

Agreed.

Regards,
Bjorn

#22 lore raw

PATCH v4 5/5 samples: Introduce Qualcomm QMI sample client

In reply to Bjorn Andersson

Introduce 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 v3:
- Kerneldoc updates

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
index c332a3b9de05..4cb8af2f810f 100644
@@ -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
index db54e766ddb1..a30833a2a19e 100644
@@ -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
new file mode 100644
index 000000000000..2b111d2769df
@@ -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
Acked-by on v4 5/5
#23 lore raw

Re: [PATCH v4 5/5] samples: Introduce Qualcomm QMI sample client

Quoted 7 lines · Bjorn Andersson

Introduce 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.

---

Signature · 2 lines
Qualcomm Innovation Center, Inc. is a member of Code Aurora Forum,
a Linux Foundation Collaborative Project