Commit 87dae9e7 authored by M Chetan Kumar's avatar M Chetan Kumar Committed by David S. Miller

net: wwan: t7xx: Enable devlink based fw flashing and coredump collection

This patch brings-in support for t7xx wwan device firmware flashing &
coredump collection using devlink.

Driver Registers with Devlink framework.
Implements devlink ops flash_update callback that programs modem firmware.
Creates region & snapshot required for device coredump log collection.
On early detection of wwan device in fastboot mode driver sets up CLDMA0 HW
tx/rx queues for raw data transfer then registers with devlink framework.
Upon receiving firmware image & partition details driver sends fastboot
commands for flashing the firmware.

In this flow the fastboot command & response gets exchanged between driver
and device. Once firmware flashing is success completion status is reported
to user space application.

Below is the devlink command usage for firmware flashing

$devlink dev flash pci/$BDF file ABC.img component ABC

Note: ABC.img is the firmware to be programmed to "ABC" partition.

In case of coredump collection when wwan device encounters an exception
it reboots & stays in fastboot mode for coredump collection by host driver.
On detecting exception state driver collects the core dump, creates the
devlink region & reports an event to user space application for dump
collection. The user space application invokes devlink region read command
for dump collection.

Below are the devlink commands used for coredump collection.

devlink region new pci/$BDF/mr_dump
devlink region read pci/$BDF/mr_dump snapshot $ID address $ADD length $LEN
devlink region del pci/$BDF/mr_dump snapshot $ID
Signed-off-by: default avatarM Chetan Kumar <m.chetan.kumar@linux.intel.com>
Signed-off-by: default avatarDevegowda Chandrashekar <chandrashekar.devegowda@intel.com>
Signed-off-by: default avatarMishra Soumya Prakash <soumya.prakash.mishra@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 140424d9
......@@ -108,6 +108,7 @@ config IOSM
config MTK_T7XX
tristate "MediaTek PCIe 5G WWAN modem T7xx device"
depends on PCI
select NET_DEVLINK
help
Enables MediaTek PCIe based 5G WWAN modem (T7xx series) device.
Adapts WWAN framework and provides network interface like wwan0
......
......@@ -18,4 +18,6 @@ mtk_t7xx-y:= t7xx_pci.o \
t7xx_hif_dpmaif_rx.o \
t7xx_dpmaif.o \
t7xx_netdev.o \
t7xx_pci_rescan.o
t7xx_pci_rescan.o \
t7xx_uevent.o \
t7xx_port_devlink.o
......@@ -40,6 +40,7 @@
#include "t7xx_pci.h"
#include "t7xx_pci_rescan.h"
#include "t7xx_pcie_mac.h"
#include "t7xx_port_devlink.h"
#include "t7xx_reg.h"
#include "t7xx_state_monitor.h"
......@@ -704,16 +705,20 @@ static int t7xx_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
t7xx_pci_infracfg_ao_calc(t7xx_dev);
t7xx_mhccif_init(t7xx_dev);
ret = t7xx_md_init(t7xx_dev);
ret = t7xx_devlink_register(t7xx_dev);
if (ret)
return ret;
ret = t7xx_md_init(t7xx_dev);
if (ret)
goto err_devlink_unregister;
t7xx_pcie_mac_interrupts_dis(t7xx_dev);
ret = t7xx_interrupt_init(t7xx_dev);
if (ret) {
t7xx_md_exit(t7xx_dev);
return ret;
goto err_devlink_unregister;
}
t7xx_rescan_done();
......@@ -723,6 +728,10 @@ static int t7xx_pci_probe(struct pci_dev *pdev, const struct pci_device_id *id)
pci_ignore_hotplug(pdev);
return 0;
err_devlink_unregister:
t7xx_devlink_unregister(t7xx_dev);
return ret;
}
static void t7xx_pci_remove(struct pci_dev *pdev)
......@@ -732,6 +741,7 @@ static void t7xx_pci_remove(struct pci_dev *pdev)
t7xx_dev = pci_get_drvdata(pdev);
t7xx_md_exit(t7xx_dev);
t7xx_devlink_unregister(t7xx_dev);
for (i = 0; i < EXT_INT_NUM; i++) {
if (!t7xx_dev->intr_handler[i])
......
......@@ -59,6 +59,7 @@ typedef irqreturn_t (*t7xx_intr_callback)(int irq, void *param);
* @md_pm_lock: protects PCIe sleep lock
* @sleep_disable_count: PCIe L1.2 lock counter
* @sleep_lock_acquire: indicates that sleep has been disabled
* @dl: devlink struct
*/
struct t7xx_pci_dev {
t7xx_intr_callback intr_handler[EXT_INT_NUM];
......@@ -79,6 +80,7 @@ struct t7xx_pci_dev {
spinlock_t md_pm_lock; /* Protects PCI resource lock */
unsigned int sleep_disable_count;
struct completion sleep_lock_acquire;
struct t7xx_devlink *dl;
};
enum t7xx_pm_id {
......
......@@ -129,6 +129,7 @@ struct t7xx_port {
int rx_length_th;
bool chan_enable;
struct task_struct *thread;
struct t7xx_devlink *dl;
};
int t7xx_get_port_mtu(struct t7xx_port *port);
......
This diff is collapsed.
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2022, Intel Corporation.
*/
#ifndef __T7XX_PORT_DEVLINK_H__
#define __T7XX_PORT_DEVLINK_H__
#include <net/devlink.h>
#include "t7xx_pci.h"
#define T7XX_MAX_QUEUE_LENGTH 32
#define T7XX_FB_COMMAND_SIZE 64
#define T7XX_FB_RESPONSE_SIZE 64
#define T7XX_FB_MCMD_SIZE 64
#define T7XX_FB_MDATA_SIZE 1024
#define T7XX_FB_RESP_COUNT 30
#define T7XX_FB_CMD_RTS "_RTS"
#define T7XX_FB_CMD_CTS "_CTS"
#define T7XX_FB_CMD_FIN "_FIN"
#define T7XX_FB_CMD_OEM_MRDUMP "oem mrdump"
#define T7XX_FB_CMD_OEM_LKDUMP "oem dump_pllk_log"
#define T7XX_FB_CMD_DOWNLOAD "download"
#define T7XX_FB_CMD_FLASH "flash"
#define T7XX_FB_CMD_REBOOT "reboot"
#define T7XX_FB_RESP_MRDUMP_DONE "MRDUMP08_DONE"
#define T7XX_FB_RESP_OKAY "OKAY"
#define T7XX_FB_RESP_FAIL "FAIL"
#define T7XX_FB_RESP_DATA "DATA"
#define T7XX_FB_RESP_INFO "INFO"
#define T7XX_FB_EVENT_SIZE 50
#define T7XX_MAX_SNAPSHOTS 1
#define T7XX_MAX_REGION_NAME_LENGTH 20
#define T7XX_MRDUMP_SIZE (160 * 1024 * 1024)
#define T7XX_LKDUMP_SIZE (256 * 1024)
#define T7XX_TOTAL_REGIONS 2
#define T7XX_FLASH_STATUS 0
#define T7XX_MRDUMP_STATUS 1
#define T7XX_LKDUMP_STATUS 2
#define T7XX_DEVLINK_IDLE 0
#define T7XX_FB_NO_MODE 0
#define T7XX_FB_DL_MODE 1
#define T7XX_FB_DUMP_MODE 2
#define T7XX_MRDUMP_INDEX 0
#define T7XX_LKDUMP_INDEX 1
struct t7xx_devlink_work {
struct work_struct work;
struct t7xx_port *port;
};
struct t7xx_devlink_region_info {
char region_name[T7XX_MAX_REGION_NAME_LENGTH];
u32 default_size;
u32 actual_size;
u32 entry;
u8 *dump;
};
struct t7xx_devlink {
struct t7xx_pci_dev *mtk_dev;
struct t7xx_port *port;
struct device *dev;
struct devlink *dl_ctx;
struct t7xx_devlink_work *dl_work;
struct workqueue_struct *dl_wq;
struct t7xx_devlink_region_info *dl_region_info[T7XX_TOTAL_REGIONS];
struct devlink_region_ops dl_region_ops[T7XX_TOTAL_REGIONS];
struct devlink_region *dl_region[T7XX_TOTAL_REGIONS];
u8 mode;
unsigned long status;
int set_fastboot_dl;
};
int t7xx_devlink_register(struct t7xx_pci_dev *t7xx_dev);
void t7xx_devlink_unregister(struct t7xx_pci_dev *t7xx_dev);
#endif /*__T7XX_PORT_DEVLINK_H__*/
......@@ -98,6 +98,7 @@ static struct t7xx_port_conf t7xx_early_port_conf[] = {
.rxq_exp_index = 1,
.path_id = CLDMA_ID_AP,
.is_early_port = true,
.ops = &devlink_port_ops,
.name = "ttyDUMP",
},
};
......@@ -493,6 +494,7 @@ static void t7xx_proxy_init_all_ports(struct t7xx_modem *md)
port->t7xx_dev = md->t7xx_dev;
port->dev = &md->t7xx_dev->pdev->dev;
port->dl = md->t7xx_dev->dl;
spin_lock_init(&port->port_update_lock);
port->chan_enable = false;
......
......@@ -93,6 +93,7 @@ struct ctrl_msg_header {
/* Port operations mapping */
extern struct port_ops wwan_sub_port_ops;
extern struct port_ops ctl_port_ops;
extern struct port_ops devlink_port_ops;
void t7xx_port_proxy_reset(struct port_proxy *port_prox);
void t7xx_port_proxy_uninit(struct port_proxy *port_prox);
......
......@@ -101,11 +101,17 @@ enum t7xx_pm_resume_state {
PM_RESUME_REG_STATE_L2_EXP,
};
enum host_event_e {
HOST_EVENT_INIT = 0,
FASTBOOT_DL_NOTY = 0x3,
};
#define T7XX_PCIE_MISC_DEV_STATUS 0x0d1c
#define MISC_RESET_TYPE_FLDR BIT(27)
#define MISC_RESET_TYPE_PLDR BIT(26)
#define MISC_DEV_STATUS_MASK GENMASK(15, 0)
#define LK_EVENT_MASK GENMASK(11, 8)
#define HOST_EVENT_MASK GENMASK(31, 28)
enum lk_event_id {
LK_EVENT_NORMAL = 0,
......
......@@ -38,10 +38,12 @@
#include "t7xx_netdev.h"
#include "t7xx_pci.h"
#include "t7xx_pcie_mac.h"
#include "t7xx_port_devlink.h"
#include "t7xx_port_proxy.h"
#include "t7xx_pci_rescan.h"
#include "t7xx_reg.h"
#include "t7xx_state_monitor.h"
#include "t7xx_uevent.h"
#define FSM_DRM_DISABLE_DELAY_MS 200
#define FSM_EVENT_POLL_INTERVAL_MS 20
......@@ -212,6 +214,16 @@ static void fsm_routine_exception(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_comm
fsm_finish_command(ctl, cmd, 0);
}
static void t7xx_host_event_notify(struct t7xx_modem *md, unsigned int event_id)
{
u32 value;
value = ioread32(IREG_BASE(md->t7xx_dev) + T7XX_PCIE_MISC_DEV_STATUS);
value &= ~HOST_EVENT_MASK;
value |= FIELD_PREP(HOST_EVENT_MASK, event_id);
iowrite32(value, IREG_BASE(md->t7xx_dev) + T7XX_PCIE_MISC_DEV_STATUS);
}
static void t7xx_lk_stage_event_handling(struct t7xx_fsm_ctl *ctl, unsigned int dev_status)
{
struct t7xx_modem *md = ctl->md;
......@@ -228,6 +240,7 @@ static void t7xx_lk_stage_event_handling(struct t7xx_fsm_ctl *ctl, unsigned int
break;
case LK_EVENT_CREATE_PD_PORT:
case LK_EVENT_CREATE_POST_DL_PORT:
md_ctrl = md->md_ctrl[CLDMA_ID_AP];
t7xx_cldma_hif_hw_init(md_ctrl);
t7xx_cldma_stop(md_ctrl);
......@@ -239,8 +252,16 @@ static void t7xx_lk_stage_event_handling(struct t7xx_fsm_ctl *ctl, unsigned int
return;
}
if (lk_event == LK_EVENT_CREATE_PD_PORT)
port->dl->mode = T7XX_FB_DUMP_MODE;
else
port->dl->mode = T7XX_FB_DL_MODE;
port->port_conf->ops->enable_chl(port);
t7xx_cldma_start(md_ctrl);
if (lk_event == LK_EVENT_CREATE_PD_PORT)
t7xx_uevent_send(dev, T7XX_UEVENT_MODEM_FASTBOOT_DUMP_MODE);
else
t7xx_uevent_send(dev, T7XX_UEVENT_MODEM_FASTBOOT_DL_MODE);
break;
case LK_EVENT_RESET:
......@@ -289,13 +310,23 @@ static void fsm_routine_stopping(struct t7xx_fsm_ctl *ctl, struct t7xx_fsm_comma
t7xx_cldma_stop(md_ctrl);
if (!ctl->md->rgu_irq_asserted) {
if (t7xx_dev->dl->set_fastboot_dl)
t7xx_host_event_notify(ctl->md, FASTBOOT_DL_NOTY);
t7xx_mhccif_h2d_swint_trigger(t7xx_dev, H2D_CH_DRM_DISABLE_AP);
/* Wait for the DRM disable to take effect */
msleep(FSM_DRM_DISABLE_DELAY_MS);
err = t7xx_acpi_fldr_func(t7xx_dev);
if (err)
if (t7xx_dev->dl->set_fastboot_dl) {
/* Do not try fldr because device will always wait for
* MHCCIF bit 13 in fastboot download flow.
*/
t7xx_mhccif_h2d_swint_trigger(t7xx_dev, H2D_CH_DEVICE_RESET);
} else {
err = t7xx_acpi_fldr_func(t7xx_dev);
if (err)
t7xx_mhccif_h2d_swint_trigger(t7xx_dev, H2D_CH_DEVICE_RESET);
}
}
fsm_finish_command(ctl, cmd, fsm_stopped_handler(ctl));
......@@ -318,6 +349,7 @@ static void fsm_routine_ready(struct t7xx_fsm_ctl *ctl)
ctl->curr_state = FSM_STATE_READY;
t7xx_fsm_broadcast_ready_state(ctl);
t7xx_uevent_send(&md->t7xx_dev->pdev->dev, T7XX_UEVENT_MODEM_READY);
t7xx_md_event_notify(md, FSM_READY);
}
......
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (c) 2022, Intel Corporation.
*/
#include <linux/slab.h>
#include "t7xx_uevent.h"
/* Update the uevent in work queue context */
static void t7xx_uevent_work(struct work_struct *data)
{
struct t7xx_uevent_info *info;
char *envp[2] = { NULL, NULL };
info = container_of(data, struct t7xx_uevent_info, work);
envp[0] = info->uevent;
if (kobject_uevent_env(&info->dev->kobj, KOBJ_CHANGE, envp))
pr_err("uevent %s failed to sent", info->uevent);
kfree(info);
}
/**
* t7xx_uevent_send - Send modem event to user space.
* @dev: Generic device pointer
* @uevent: Uevent information
*/
void t7xx_uevent_send(struct device *dev, char *uevent)
{
struct t7xx_uevent_info *info = kzalloc(sizeof(*info), GFP_ATOMIC);
if (!info)
return;
INIT_WORK(&info->work, t7xx_uevent_work);
info->dev = dev;
snprintf(info->uevent, T7XX_MAX_UEVENT_LEN, "T7XX_EVENT=%s", uevent);
schedule_work(&info->work);
}
/* SPDX-License-Identifier: GPL-2.0-only
*
* Copyright (c) 2022, Intel Corporation.
*/
#ifndef __T7XX_UEVENT_H__
#define __T7XX_UEVENT_H__
#include <linux/device.h>
#include <linux/kobject.h>
/* Maximum length of user events */
#define T7XX_MAX_UEVENT_LEN 64
/* T7XX Host driver uevents */
#define T7XX_UEVENT_MODEM_READY "T7XX_MODEM_READY"
#define T7XX_UEVENT_MODEM_FASTBOOT_DL_MODE "T7XX_MODEM_FASTBOOT_DL_MODE"
#define T7XX_UEVENT_MODEM_FASTBOOT_DUMP_MODE "T7XX_MODEM_FASTBOOT_DUMP_MODE"
#define T7XX_UEVENT_MRDUMP_READY "T7XX_MRDUMP_READY"
#define T7XX_UEVENT_LKDUMP_READY "T7XX_LKDUMP_READY"
#define T7XX_UEVENT_MRD_DISCD "T7XX_MRDUMP_DISCARDED"
#define T7XX_UEVENT_LKD_DISCD "T7XX_LKDUMP_DISCARDED"
#define T7XX_UEVENT_FLASHING_SUCCESS "T7XX_FLASHING_SUCCESS"
#define T7XX_UEVENT_FLASHING_FAILURE "T7XX_FLASHING_FAILURE"
/**
* struct t7xx_uevent_info - Uevent information structure.
* @dev: Pointer to device structure
* @uevent: Uevent information
* @work: Uevent work struct
*/
struct t7xx_uevent_info {
struct device *dev;
char uevent[T7XX_MAX_UEVENT_LEN];
struct work_struct work;
};
void t7xx_uevent_send(struct device *dev, char *uevent);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment