Skip to contentSkip to conversation

net: wwan: iosm: firmware flashing and coredump collection

PATCH Applied M Chetan Kumar 4 participants 5 messages Sep 13, 2021 – Sep 14, 2021

Subsystems (4)
lore
Share & tools
lore
#0 lore raw

PATCH 1/1 net: wwan: iosm: firmware flashing and coredump collection

This patch brings-in support for M.2 7560 Device firmware flashing & coredump collection using devlink.
- Driver Registers with Devlink framework.
- Register devlink params callback for configuring device params required in flashing or coredump flow.
- Implements devlink ops flash_update callback that programs modem firmware.
- Creates region & snapshot required for device coredump log collection.

On early detection of device in boot rom stage. Driver registers with Devlink framework and establish transport channel for PSI (Primary Signed Image) injection. Once PSI is injected to device, the device execution stage details are read to determine whether device is in flash or exception mode. The collected information is reported to devlink user space application & based on this informationi, application proceeds with either modem firmware flashing or coredump collection.

---
 drivers/net/wwan/Kconfig                  |   1 +
 drivers/net/wwan/iosm/Makefile            |   5 +-
 drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c |   6 +-
 drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.h |   1 +
 drivers/net/wwan/iosm/iosm_ipc_coredump.c | 110 +++++
 drivers/net/wwan/iosm/iosm_ipc_coredump.h |  75 +++
 drivers/net/wwan/iosm/iosm_ipc_devlink.c  | 360 ++++++++++++++
 drivers/net/wwan/iosm/iosm_ipc_devlink.h  | 207 ++++++++
 drivers/net/wwan/iosm/iosm_ipc_flash.c    | 562 ++++++++++++++++++++++
 drivers/net/wwan/iosm/iosm_ipc_flash.h    | 271 +++++++++++
 drivers/net/wwan/iosm/iosm_ipc_imem.c     | 103 +++-
 drivers/net/wwan/iosm/iosm_ipc_imem.h     |  19 +-
 drivers/net/wwan/iosm/iosm_ipc_imem_ops.c | 317 ++++++++++++
 drivers/net/wwan/iosm/iosm_ipc_imem_ops.h |  49 +-
 14 files changed, 2055 insertions(+), 31 deletions(-)
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_coredump.c
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_coredump.h
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_devlink.c
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_devlink.h
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_flash.c
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_flash.h
drivers/net/wwan/Kconfig +1 -0
index 77dbfc418bce..17543be14665 100644
@@ -71,6 +71,7 @@ config RPMSG_WWAN_CTRL
 config IOSM
 	tristate "IOSM Driver for Intel M.2 WWAN Device"
 	depends on INTEL_IOMMU
+	select NET_DEVLINK
 	help
 	  This driver enables Intel M.2 WWAN Device communication.
 
drivers/net/wwan/iosm/Makefile +4 -1
index 4f9f0ae398e1..b838034bb120 100644
@@ -18,6 +18,9 @@ iosm-y = \
 	iosm_ipc_protocol.o		\
 	iosm_ipc_protocol_ops.o	\
 	iosm_ipc_mux.o			\
-	iosm_ipc_mux_codec.o
+	iosm_ipc_mux_codec.o		\
+	iosm_ipc_devlink.o		\
+	iosm_ipc_flash.o		\
+	iosm_ipc_coredump.o
 
 obj-$(CONFIG_IOSM) := iosm.o
drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c +5 -1
index 519361ec40df..128c999e08bb 100644
@@ -8,7 +8,7 @@
 #include "iosm_ipc_chnl_cfg.h"
 
 /* Max. sizes of a downlink buffers */
-#define IPC_MEM_MAX_DL_FLASH_BUF_SIZE (16 * 1024)
+#define IPC_MEM_MAX_DL_FLASH_BUF_SIZE (64 * 1024)
 #define IPC_MEM_MAX_DL_LOOPBACK_SIZE (1 * 1024 * 1024)
 #define IPC_MEM_MAX_DL_AT_BUF_SIZE 2048
 #define IPC_MEM_MAX_DL_RPC_BUF_SIZE (32 * 1024)
@@ -60,6 +60,10 @@ static struct ipc_chnl_cfg modem_cfg[] = {
 	{ IPC_MEM_CTRL_CHL_ID_6, IPC_MEM_PIPE_12, IPC_MEM_PIPE_13,
 	  IPC_MEM_MAX_TDS_MBIM, IPC_MEM_MAX_TDS_MBIM,
 	  IPC_MEM_MAX_DL_MBIM_BUF_SIZE, WWAN_PORT_MBIM },
+	/* Flash Channel/Coredump Channel */
+	{ IPC_MEM_CTRL_CHL_ID_7, IPC_MEM_PIPE_0, IPC_MEM_PIPE_1,
+	  IPC_MEM_MAX_TDS_FLASH_UL, IPC_MEM_MAX_TDS_FLASH_DL,
+	  IPC_MEM_MAX_DL_FLASH_BUF_SIZE, WWAN_PORT_UNKNOWN },
 };
 
 int ipc_chnl_cfg_get(struct ipc_chnl_cfg *chnl_cfg, int index)
drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.h +1 -0
index 422471367f78..e77084e76718 100644
@@ -23,6 +23,7 @@ enum ipc_channel_id {
 	IPC_MEM_CTRL_CHL_ID_4,
 	IPC_MEM_CTRL_CHL_ID_5,
 	IPC_MEM_CTRL_CHL_ID_6,
+	IPC_MEM_CTRL_CHL_ID_7,
 };
 
 /**
drivers/net/wwan/iosm/iosm_ipc_coredump.c new file +110 -0

110 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_coredump.h new file +75 -0

75 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_devlink.c new file +360 -0

360 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_devlink.h new file +207 -0

207 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_flash.c new file +562 -0

562 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_flash.h new file +271 -0

271 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_imem.c +78 -25

162 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_imem.h +16 -3
index dc65b0712261..8380008232be 100644
@@ -7,6 +7,7 @@
 #define IOSM_IPC_IMEM_H
 
 #include <linux/skbuff.h>
+#include <stdbool.h>
 
 #include "iosm_ipc_mmio.h"
 #include "iosm_ipc_pcie.h"
@@ -69,7 +70,7 @@ struct ipc_chnl_cfg;
 
 #define IMEM_IRQ_DONT_CARE (-1)
 
-#define IPC_MEM_MAX_CHANNELS 7
+#define IPC_MEM_MAX_CHANNELS 8
 
 #define IPC_MEM_MUX_IP_SESSION_ENTRIES 8
 
@@ -98,6 +99,7 @@ struct ipc_chnl_cfg;
 #define IPC_MEM_DL_ETH_OFFSET 16
 
 #define IPC_CB(skb) ((struct ipc_skb_cb *)((skb)->cb))
+#define IOSM_CHIP_INFO_SIZE_MAX 100
 
 #define FULLY_FUNCTIONAL 0
 
@@ -304,9 +306,9 @@ enum ipc_phase {
  * @ipc_port:			IPC PORT data structure pointer
  * @pcie:			IPC PCIe
  * @dev:			Pointer to device structure
- * @flash_channel_id:		Reserved channel id for flashing to RAM.
  * @ipc_requested_state:	Expected IPC state on CP.
  * @channels:			Channel list with UL/DL pipe pairs.
+ * @ipc_devlink:		IPC Devlink data structure pointer
  * @ipc_status:			local ipc_status
  * @nr_of_channels:		number of configured channels
  * @startup_timer:		startup timer for NAND support.
@@ -349,9 +351,9 @@ struct iosm_imem {
 	struct iosm_cdev *ipc_port[IPC_MEM_MAX_CHANNELS];
 	struct iosm_pcie *pcie;
 	struct device *dev;
-	int flash_channel_id;
 	enum ipc_mem_device_ipc_state ipc_requested_state;
 	struct ipc_mem_channel channels[IPC_MEM_MAX_CHANNELS];
+	struct iosm_devlink *ipc_devlink;
 	u32 ipc_status;
 	u32 nr_of_channels;
 	struct hrtimer startup_timer;
@@ -575,4 +577,15 @@ void ipc_imem_ipc_init_check(struct iosm_imem *ipc_imem);
  */
 void ipc_imem_channel_init(struct iosm_imem *ipc_imem, enum ipc_ctype ctype,
 			   struct ipc_chnl_cfg chnl_cfg, u32 irq_moderation);
+
+/**
+ * ipc_imem_devlink_trigger_chip_info - Inform devlink that the chip
+ *					information are available if the
+ *					flashing to RAM interworking shall be
+ *					executed.
+ * @ipc_imem:	Pointer to imem structure
+ *
+ * Returns: 0 on success, -1 on failure
+ */
+int ipc_imem_devlink_trigger_chip_info(struct iosm_imem *ipc_imem);
 #endif
drivers/net/wwan/iosm/iosm_ipc_imem_ops.c +317 -0

326 lines not on this page · raw message

drivers/net/wwan/iosm/iosm_ipc_imem_ops.h +48 -1

59 lines not on this page · raw message

Signature · 1 line
2.26.2
#1 lore raw
This patch was applied to netdev/net-next.git (refs/heads/master):

Hello:

This patch was applied to netdev/net-next.git (refs/heads/master):

Quoted 10 lines · On Mon, 13 Sep 2021 18:34:12 +0530 you wrote:

This patch brings-in support for M.2 7560 Device firmware flashing & coredump collection using devlink.
- Driver Registers with Devlink framework.
- Register devlink params callback for configuring device params required in flashing or coredump flow.
- Implements devlink ops flash_update callback that programs modem firmware.
- Creates region & snapshot required for device coredump log collection.

[...]

Here is the summary with links:
- [net-next] net: wwan: iosm: firmware flashing and coredump collection

    https://git.kernel.org/netdev/net-next/c/13bb8429ca98

You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html

maintainer
#2 lore raw
In reply to M Chetan Kumar
Quoted 9 lines · On Mon, 13 Sep 2021 18:34:12 +0530 M Chetan Kumar wrote:

This patch brings-in support for M.2 7560 Device firmware flashing & coredump collection using devlink.
- Driver Registers with Devlink framework.
- Register devlink params callback for configuring device params required in flashing or coredump flow.
- Implements devlink ops flash_update callback that programs modem firmware.
- Creates region & snapshot required for device coredump log collection.

Quoted 5 lines

On early detection of device in boot rom stage. Driver registers with Devlink framework and establish transport channel for PSI (Primary Signed Image) injection. Once PSI is injected to device, the device execution stage details are read to determine whether device is in flash or exception mode.

Is this normal operation flow for the device? After each boot device boots from the rom image and then user has to "inject" the full FW image with devlink?

Quoted 5 lines

The collected information is reported to devlink user
space application & based on this informationi, application proceeds with either modem firmware flashing or coredump collection.

Quoted 16 lines
---
 drivers/net/wwan/Kconfig                  |   1 +
 drivers/net/wwan/iosm/Makefile            |   5 +-
 drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.c |   6 +-
 drivers/net/wwan/iosm/iosm_ipc_chnl_cfg.h |   1 +
 drivers/net/wwan/iosm/iosm_ipc_coredump.c | 110 +++++
 drivers/net/wwan/iosm/iosm_ipc_coredump.h |  75 +++
 drivers/net/wwan/iosm/iosm_ipc_devlink.c  | 360 ++++++++++++++
 drivers/net/wwan/iosm/iosm_ipc_devlink.h  | 207 ++++++++
 drivers/net/wwan/iosm/iosm_ipc_flash.c    | 562 ++++++++++++++++++++++
 drivers/net/wwan/iosm/iosm_ipc_flash.h    | 271 +++++++++++
 drivers/net/wwan/iosm/iosm_ipc_imem.c     | 103 +++-
 drivers/net/wwan/iosm/iosm_ipc_imem.h     |  19 +-
 drivers/net/wwan/iosm/iosm_ipc_imem_ops.c | 317 ++++++++++++
 drivers/net/wwan/iosm/iosm_ipc_imem_ops.h |  49 +-
 14 files changed, 2055 insertions(+), 31 deletions(-)

Please try to break your patches down, single patch with 2kLoC is hard to review.

Quoted 50 lines
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_coredump.c
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_coredump.h
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_devlink.c
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_devlink.h
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_flash.c
 create mode 100644 drivers/net/wwan/iosm/iosm_ipc_flash.h
drivers/net/wwan/iosm/iosm_ipc_coredump.c new file +43 -0
+/* Get coredump list to be collected from modem */
+int ipc_coredump_get_list(struct iosm_devlink *devlink, u16 cmd)
+{
+	u32 byte_read, num_entries, file_size;
+	struct iosm_cd_table *cd_table;
+	u8 size[MAX_SIZE_LEN], i;
+	char *filename;
+	int ret = 0;
+
+	cd_table = kzalloc(MAX_CD_LIST_SIZE, GFP_KERNEL);
+	if (!cd_table) {
+		ret = -ENOMEM;
+		goto  cd_init_fail;
+	}
+
+	ret = ipc_devlink_send_cmd(devlink, cmd, MAX_CD_LIST_SIZE);
+	if (ret) {
+		dev_err(devlink->dev, "rpsi_cmd_coredump_start failed");
+		goto cd_init_fail;
+	}
+
+	ret = ipc_imem_sys_devlink_read(devlink, (u8 *)cd_table,
+					MAX_CD_LIST_SIZE, &byte_read);
+	if (ret) {
+		dev_err(devlink->dev, "Coredump data is invalid");
+		goto cd_init_fail;
+	}
+
+	if (byte_read != MAX_CD_LIST_SIZE)
+		goto cd_init_fail;
+
+	if (cmd == rpsi_cmd_coredump_start) {
+		num_entries = le32_to_cpu(cd_table->list.num_entries);
+		if (num_entries == 0 || num_entries > IOSM_NOF_CD_REGION) {
+			ret = -EINVAL;
+			goto cd_init_fail;
+		}
+
+		for (i = 0; i < num_entries; i++) {
+			file_size = le32_to_cpu(cd_table->list.entry[i].size);
+			filename = cd_table->list.entry[i].filename;
+
+			if (file_size > devlink->cd_file_info[i].default_size) {

drivers/net/wwan/iosm/iosm_ipc_coredump.c line 99

Quoted 10 lines
drivers/net/wwan/iosm/iosm_ipc_coredump.c new file +10 -0
+				ret = -EINVAL;
+				goto cd_init_fail;
+			}
+
+			devlink->cd_file_info[i].actual_size = file_size;
+			dev_dbg(devlink->dev, "file: %s actual size %d",
+				filename, file_size);
+			devlink_flash_update_status_notify(devlink->devlink_ctx,
+							   filename,
+							   "FILENAME", 0, 0);

Why are you using flash_update_status_notify() in a snapshot collecting function? As the name indicates that helper is for reporting flashing progress.

Quoted 13 lines
(quoted diff) +12 -0
+			snprintf(size, sizeof(size), "%d", file_size);
+			devlink_flash_update_status_notify(devlink->devlink_ctx,
+							   size, "FILE SIZE",
+							   0, 0);
+		}
+	}
+
+cd_init_fail:
+	kfree(cd_table);
+	return ret;
+}
 
+/**

Review

Quoted 10 lines
(quoted diff) +10 -0
+ * ipc_coredump_collect - To collect coredump
+ * @devlink:		Pointer to devlink instance.
+ * @data:		Pointer to snapshot
+ * @entry:		ID of requested snapshot
+ * @region_size:	Region size
+ *
+ * Returns: 0 on success, error on failure
+ */
+int ipc_coredump_collect(struct iosm_devlink *devlink, u8 **data, int entry,
+			 u32 region_size);

kdoc belongs with the code not in the header.

Quoted 22 lines
drivers/net/wwan/iosm/iosm_ipc_devlink.c new file +21 -0
+/**
+ * ipc_coredump_get_list - Get coredump list
+ * @devlink:         Pointer to devlink instance.
+ * @cmd:	     RPSI command to be sent
+ *
+ * Returns: 0 on success, error on failure
+ */
+int ipc_coredump_get_list(struct iosm_devlink *devlink, u16 cmd);
 
+/* Devlink param structure array */
+static const struct devlink_param iosm_devlink_params[] = {
+	DEVLINK_PARAM_DRIVER(IOSM_DEVLINK_PARAM_ID_ERASE_FULL_FLASH,
+			     "erase_full_flash", DEVLINK_PARAM_TYPE_BOOL,
+			     BIT(DEVLINK_PARAM_CMODE_RUNTIME),
+			     ipc_devlink_get_param, ipc_devlink_set_param,
+			     NULL),
+	DEVLINK_PARAM_DRIVER(IOSM_DEVLINK_PARAM_ID_DOWNLOAD_REGION,
+			     "download_region", DEVLINK_PARAM_TYPE_BOOL,
+			     BIT(DEVLINK_PARAM_CMODE_RUNTIME),
+			     ipc_devlink_get_param, ipc_devlink_set_param,
+			     NULL),
+	DEVLINK_PARAM_DRIVER(IOSM_DEVLINK_PARAM_ID_ADDRESS,

drivers/net/wwan/iosm/iosm_ipc_devlink.c line 107

Quoted 10 lines
drivers/net/wwan/iosm/iosm_ipc_devlink.c new file +10 -0
+			     "address", DEVLINK_PARAM_TYPE_U32,
+			     BIT(DEVLINK_PARAM_CMODE_RUNTIME),
+			     ipc_devlink_get_param, ipc_devlink_set_param,
+			     NULL),
+	DEVLINK_PARAM_DRIVER(IOSM_DEVLINK_PARAM_ID_REGION_COUNT,
+			     "region_count", DEVLINK_PARAM_TYPE_U8,
+			     BIT(DEVLINK_PARAM_CMODE_RUNTIME),
+			     ipc_devlink_get_param, ipc_devlink_set_param,
+			     NULL),
+};

Parameters must be documented under Documentation/networking/devlink/

#3 lore raw
Quoted 16 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 13 Sep 2021 18:34:12 +0530 M Chetan Kumar wrote:

This patch brings-in support for M.2 7560 Device firmware flashing & coredump collection using devlink.
- Driver Registers with Devlink framework.
- Register devlink params callback for configuring device params required in flashing or coredump flow.
- Implements devlink ops flash_update callback that programs modem firmware.
- Creates region & snapshot required for device coredump log collection.

Quoted 5 lines

On early detection of device in boot rom stage. Driver registers with Devlink framework and establish transport channel for PSI (Primary Signed Image) injection. Once PSI is injected to device, the device execution stage details are read to determine whether device is in flash or exception mode.

Quoted 3 lines

Is this normal operation flow for the device? After each boot device boots from the rom image and then user has to "inject" the full FW image with devlink?

If it is, then this sounds like to the wrong interface for firmware. The driver should be using request_firmware().

Andrew

#4 lore raw
In reply to Jakub Kicinski
Quoted 16 lines · Jakub Kicinski
Quoted 9 lines · On Mon, 13 Sep 2021 18:34:12 +0530 M Chetan Kumar wrote:

This patch brings-in support for M.2 7560 Device firmware flashing & coredump collection using devlink.
- Driver Registers with Devlink framework.
- Register devlink params callback for configuring device params required in flashing or coredump flow.
- Implements devlink ops flash_update callback that programs modem firmware.
- Creates region & snapshot required for device coredump log collection.

Quoted 5 lines

On early detection of device in boot rom stage. Driver registers with Devlink framework and establish transport channel for PSI (Primary Signed Image) injection. Once PSI is injected to device, the device execution stage details are read to determine whether device is in flash or exception mode.

Quoted 3 lines

Is this normal operation flow for the device? After each boot device boots from the rom image and then user has to "inject" the full FW image with devlink?

No. It's not a normal operation flow for the device.
M.2 7560 Device has a NAND flash. Only when device needs to be reflashed then only fw image is injected via devlink.

In order to keep device in boot rom stage a special AT command or MBIM CID is issued prior to fw flash.

Quoted 48 lines
Quoted 48 lines
drivers/net/wwan/iosm/iosm_ipc_coredump.c new file +48 -0
+int ipc_coredump_get_list(struct iosm_devlink *devlink, u16 cmd)
+{
+	u32 byte_read, num_entries, file_size;
+	struct iosm_cd_table *cd_table;
+	u8 size[MAX_SIZE_LEN], i;
+	char *filename;
+	int ret = 0;
+
+	cd_table = kzalloc(MAX_CD_LIST_SIZE, GFP_KERNEL);
+	if (!cd_table) {
+		ret = -ENOMEM;
+		goto  cd_init_fail;
+	}
+
+	ret = ipc_devlink_send_cmd(devlink, cmd, MAX_CD_LIST_SIZE);
+	if (ret) {
+		dev_err(devlink->dev, "rpsi_cmd_coredump_start failed");
+		goto cd_init_fail;
+	}
+
+	ret = ipc_imem_sys_devlink_read(devlink, (u8 *)cd_table,
+					MAX_CD_LIST_SIZE, &byte_read);
+	if (ret) {
+		dev_err(devlink->dev, "Coredump data is invalid");
+		goto cd_init_fail;
+	}
+
+	if (byte_read != MAX_CD_LIST_SIZE)
+		goto cd_init_fail;
+
+	if (cmd == rpsi_cmd_coredump_start) {
+		num_entries = le32_to_cpu(cd_table->list.num_entries);
+		if (num_entries == 0 || num_entries > IOSM_NOF_CD_REGION) {
+			ret = -EINVAL;
+			goto cd_init_fail;
+		}
+
+		for (i = 0; i < num_entries; i++) {
+			file_size = le32_to_cpu(cd_table->list.entry[i].size);
+			filename = cd_table->list.entry[i].filename;
+
+			if (file_size > devlink->cd_file_info[i].default_size) {
+				ret = -EINVAL;
+				goto cd_init_fail;
+			}
+
+			devlink->cd_file_info[i].actual_size = file_size;
+			dev_dbg(devlink->dev, "file: %s actual size %d",
Quoted 8 lines

drivers/net/wwan/iosm/iosm_ipc_coredump.c line 99

Quoted 4 lines
drivers/net/wwan/iosm/iosm_ipc_coredump.c new file +4 -0
+				filename, file_size);
+			devlink_flash_update_status_notify(devlink->devlink_ctx,
+							   filename,
+							   "FILENAME", 0, 0);

Why are you using flash_update_status_notify() in a snapshot collecting function? As the name indicates that helper is for reporting flashing progress.

Coredump collection process starts with pre-flashing procedure (primary fw injection), depending on current device state either in exception or flash stage the device reported information is notified to devlink via _flash_update_status_notify.

This is an early procedure for coredump collection.