Skip to content

Commit 3349e4a

Browse files
mchetankumardavem330
authored andcommitted
net: wwan: t7xx: Add port for modem logging
The Modem Logging (MDL) port provides an interface to collect modem logs for debugging purposes. MDL is supported by the relay interface, and the mtk_t7xx port infrastructure. MDL allows user-space apps to control logging via mbim command and to collect logs via the relay interface, while port infrastructure facilitates communication between the driver and the modem. Signed-off-by: Moises Veleta <[email protected]> Signed-off-by: M Chetan Kumar <[email protected]> Signed-off-by: Devegowda Chandrashekar <[email protected]> Acked-by: Ricardo Martinez <[email protected]> Reviewed-by: Sergey Ryazanov <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent fece7a8 commit 3349e4a

File tree

8 files changed

+144
-0
lines changed

8 files changed

+144
-0
lines changed

drivers/net/wwan/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ config IOSM
108108
config MTK_T7XX
109109
tristate "MediaTek PCIe 5G WWAN modem T7xx device"
110110
depends on PCI
111+
select RELAY if WWAN_DEBUGFS
111112
help
112113
Enables MediaTek PCIe based 5G WWAN modem (T7xx series) device.
113114
Adapts WWAN framework and provides network interface like wwan0

drivers/net/wwan/t7xx/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,6 @@ mtk_t7xx-y:= t7xx_pci.o \
1818
t7xx_hif_dpmaif_rx.o \
1919
t7xx_dpmaif.o \
2020
t7xx_netdev.o
21+
22+
mtk_t7xx-$(CONFIG_WWAN_DEBUGFS) += \
23+
t7xx_port_trace.o \

drivers/net/wwan/t7xx/t7xx_hif_cldma.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1018,6 +1018,8 @@ static int t7xx_cldma_late_init(struct cldma_ctrl *md_ctrl)
10181018
dev_err(md_ctrl->dev, "control TX ring init fail\n");
10191019
goto err_free_tx_ring;
10201020
}
1021+
1022+
md_ctrl->tx_ring[i].pkt_size = CLDMA_MTU;
10211023
}
10221024

10231025
for (j = 0; j < CLDMA_RXQ_NUM; j++) {

drivers/net/wwan/t7xx/t7xx_pci.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,9 @@ struct t7xx_pci_dev {
7878
spinlock_t md_pm_lock; /* Protects PCI resource lock */
7979
unsigned int sleep_disable_count;
8080
struct completion sleep_lock_acquire;
81+
#ifdef CONFIG_WWAN_DEBUGFS
82+
struct dentry *debugfs_dir;
83+
#endif
8184
};
8285

8386
enum t7xx_pm_id {

drivers/net/wwan/t7xx/t7xx_port.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,9 @@ struct t7xx_port {
125125
struct {
126126
struct wwan_port *wwan_port;
127127
} wwan;
128+
struct {
129+
struct rchan *relaych;
130+
} log;
128131
};
129132
};
130133

drivers/net/wwan/t7xx/t7xx_port_proxy.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,18 @@ static const struct t7xx_port_conf t7xx_md_port_conf[] = {
7070
.name = "MBIM",
7171
.port_type = WWAN_PORT_MBIM,
7272
}, {
73+
#ifdef CONFIG_WWAN_DEBUGFS
74+
.tx_ch = PORT_CH_MD_LOG_TX,
75+
.rx_ch = PORT_CH_MD_LOG_RX,
76+
.txq_index = 7,
77+
.rxq_index = 7,
78+
.txq_exp_index = 7,
79+
.rxq_exp_index = 7,
80+
.path_id = CLDMA_ID_MD,
81+
.ops = &t7xx_trace_port_ops,
82+
.name = "mdlog",
83+
}, {
84+
#endif
7385
.tx_ch = PORT_CH_CONTROL_TX,
7486
.rx_ch = PORT_CH_CONTROL_RX,
7587
.txq_index = Q_IDX_CTRL,

drivers/net/wwan/t7xx/t7xx_port_proxy.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,10 @@ struct ctrl_msg_header {
8787
extern struct port_ops wwan_sub_port_ops;
8888
extern struct port_ops ctl_port_ops;
8989

90+
#ifdef CONFIG_WWAN_DEBUGFS
91+
extern struct port_ops t7xx_trace_port_ops;
92+
#endif
93+
9094
void t7xx_port_proxy_reset(struct port_proxy *port_prox);
9195
void t7xx_port_proxy_uninit(struct port_proxy *port_prox);
9296
int t7xx_port_proxy_init(struct t7xx_modem *md);
Lines changed: 116 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,116 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (C) 2022 Intel Corporation.
4+
*/
5+
6+
#include <linux/debugfs.h>
7+
#include <linux/relay.h>
8+
#include <linux/skbuff.h>
9+
#include <linux/wwan.h>
10+
11+
#include "t7xx_port.h"
12+
#include "t7xx_port_proxy.h"
13+
#include "t7xx_state_monitor.h"
14+
15+
#define T7XX_TRC_SUB_BUFF_SIZE 131072
16+
#define T7XX_TRC_N_SUB_BUFF 32
17+
18+
static struct dentry *t7xx_trace_create_buf_file_handler(const char *filename,
19+
struct dentry *parent,
20+
umode_t mode,
21+
struct rchan_buf *buf,
22+
int *is_global)
23+
{
24+
*is_global = 1;
25+
return debugfs_create_file(filename, mode, parent, buf,
26+
&relay_file_operations);
27+
}
28+
29+
static int t7xx_trace_remove_buf_file_handler(struct dentry *dentry)
30+
{
31+
debugfs_remove(dentry);
32+
return 0;
33+
}
34+
35+
static int t7xx_trace_subbuf_start_handler(struct rchan_buf *buf, void *subbuf,
36+
void *prev_subbuf, size_t prev_padding)
37+
{
38+
if (relay_buf_full(buf)) {
39+
pr_err_ratelimited("Relay_buf full dropping traces");
40+
return 0;
41+
}
42+
43+
return 1;
44+
}
45+
46+
static struct rchan_callbacks relay_callbacks = {
47+
.subbuf_start = t7xx_trace_subbuf_start_handler,
48+
.create_buf_file = t7xx_trace_create_buf_file_handler,
49+
.remove_buf_file = t7xx_trace_remove_buf_file_handler,
50+
};
51+
52+
static void t7xx_trace_port_uninit(struct t7xx_port *port)
53+
{
54+
struct dentry *debugfs_dir = port->t7xx_dev->debugfs_dir;
55+
struct rchan *relaych = port->log.relaych;
56+
57+
if (!relaych)
58+
return;
59+
60+
relay_close(relaych);
61+
debugfs_remove_recursive(debugfs_dir);
62+
}
63+
64+
static int t7xx_trace_port_recv_skb(struct t7xx_port *port, struct sk_buff *skb)
65+
{
66+
struct rchan *relaych = port->log.relaych;
67+
68+
if (!relaych)
69+
return -EINVAL;
70+
71+
relay_write(relaych, skb->data, skb->len);
72+
dev_kfree_skb(skb);
73+
return 0;
74+
}
75+
76+
static void t7xx_port_trace_md_state_notify(struct t7xx_port *port, unsigned int state)
77+
{
78+
struct rchan *relaych = port->log.relaych;
79+
struct dentry *debugfs_wwan_dir;
80+
struct dentry *debugfs_dir;
81+
82+
if (state != MD_STATE_READY || relaych)
83+
return;
84+
85+
debugfs_wwan_dir = wwan_get_debugfs_dir(port->dev);
86+
if (IS_ERR(debugfs_wwan_dir))
87+
return;
88+
89+
debugfs_dir = debugfs_create_dir(KBUILD_MODNAME, debugfs_wwan_dir);
90+
if (IS_ERR_OR_NULL(debugfs_dir)) {
91+
wwan_put_debugfs_dir(debugfs_wwan_dir);
92+
dev_err(port->dev, "Unable to create debugfs for trace");
93+
return;
94+
}
95+
96+
relaych = relay_open("relay_ch", debugfs_dir, T7XX_TRC_SUB_BUFF_SIZE,
97+
T7XX_TRC_N_SUB_BUFF, &relay_callbacks, NULL);
98+
if (!relaych)
99+
goto err_rm_debugfs_dir;
100+
101+
wwan_put_debugfs_dir(debugfs_wwan_dir);
102+
port->log.relaych = relaych;
103+
port->t7xx_dev->debugfs_dir = debugfs_dir;
104+
return;
105+
106+
err_rm_debugfs_dir:
107+
debugfs_remove_recursive(debugfs_dir);
108+
wwan_put_debugfs_dir(debugfs_wwan_dir);
109+
dev_err(port->dev, "Unable to create trace port %s", port->port_conf->name);
110+
}
111+
112+
struct port_ops t7xx_trace_port_ops = {
113+
.recv_skb = t7xx_trace_port_recv_skb,
114+
.uninit = t7xx_trace_port_uninit,
115+
.md_state_notify = t7xx_port_trace_md_state_notify,
116+
};

0 commit comments

Comments
 (0)