Skip to content

Commit 16daf3d

Browse files
committed
Merge branch 'wwan-debugfs-tweaks'
Sergey Ryazanov says: ==================== WWAN debugfs tweaks This is a follow-up series to just applied IOSM (and WWAN) debugfs interface support [1]. The series has two main goals: 1. move the driver-specific debugfs knobs to a subdirectory; 2. make the debugfs interface optional for both IOSM and for the WWAN core. As for the first part, I must say that it was my mistake. I suggested to place debugfs entries under a common per WWAN device directory. But I missed the driver subdirectory in the example, so it become: /sys/kernel/debugfs/wwan/wwan0/trace Since the traces collection is a driver-specific feature, it is better to keep it under the driver-specific subdirectory: /sys/kernel/debugfs/wwan/wwan0/iosm/trace It is desirable to be able to entirely disable the debugfs interface. It can be disabled for several reasons, including security and consumed storage space. See detailed rationale with usage example in the 4th patch. The changes themselves are relatively simple, but require a code rearrangement. So to make changes clear, I chose to split them into preparatory and main changes and properly describe each of them. IOSM part is compile-tested only since I do not have IOSM supported device, so it needs Ack from the driver developers. I would like to thank Johannes Berg and Leon Romanovsky. Their suggestions and comments helped a lot to rework the initial over-engineered solution to something less confusing and much more simple. Thanks! 1. https://lore.kernel.org/netdev/[email protected] 2. https://patchwork.kernel.org/project/netdevbpf/patch/[email protected]/ ==================== Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
2 parents a43a072 + 283e6f5 commit 16daf3d

File tree

12 files changed

+134
-41
lines changed

12 files changed

+134
-41
lines changed

drivers/net/wwan/Kconfig

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,17 @@ config WWAN
1616

1717
if WWAN
1818

19+
config WWAN_DEBUGFS
20+
bool "WWAN devices debugfs interface" if EXPERT
21+
depends on DEBUG_FS
22+
default y
23+
help
24+
Enables debugfs infrastructure for the WWAN core and device drivers.
25+
26+
If this option is selected, then you can find the debug interface
27+
elements for each WWAN device in a directory that is corresponding to
28+
the device name: debugfs/wwan/wwanX.
29+
1930
config WWAN_HWSIM
2031
tristate "Simulated WWAN device"
2132
help
@@ -85,7 +96,7 @@ config IOSM
8596
tristate "IOSM Driver for Intel M.2 WWAN Device"
8697
depends on INTEL_IOMMU
8798
select NET_DEVLINK
88-
select RELAY
99+
select RELAY if WWAN_DEBUGFS
89100
help
90101
This driver enables Intel M.2 WWAN Device communication.
91102

drivers/net/wwan/iosm/Makefile

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,10 @@ iosm-y = \
2121
iosm_ipc_mux_codec.o \
2222
iosm_ipc_devlink.o \
2323
iosm_ipc_flash.o \
24-
iosm_ipc_coredump.o \
24+
iosm_ipc_coredump.o
25+
26+
iosm-$(CONFIG_WWAN_DEBUGFS) += \
27+
iosm_ipc_debugfs.o \
2528
iosm_ipc_trace.o
2629

2730
obj-$(CONFIG_IOSM) := iosm.o
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// SPDX-License-Identifier: GPL-2.0-only
2+
/*
3+
* Copyright (C) 2020-2021 Intel Corporation.
4+
*/
5+
6+
#include <linux/debugfs.h>
7+
#include <linux/wwan.h>
8+
9+
#include "iosm_ipc_imem.h"
10+
#include "iosm_ipc_trace.h"
11+
#include "iosm_ipc_debugfs.h"
12+
13+
void ipc_debugfs_init(struct iosm_imem *ipc_imem)
14+
{
15+
struct dentry *debugfs_pdev = wwan_get_debugfs_dir(ipc_imem->dev);
16+
17+
ipc_imem->debugfs_dir = debugfs_create_dir(KBUILD_MODNAME,
18+
debugfs_pdev);
19+
20+
ipc_imem->trace = ipc_trace_init(ipc_imem);
21+
if (!ipc_imem->trace)
22+
dev_warn(ipc_imem->dev, "trace channel init failed");
23+
}
24+
25+
void ipc_debugfs_deinit(struct iosm_imem *ipc_imem)
26+
{
27+
ipc_trace_deinit(ipc_imem->trace);
28+
debugfs_remove_recursive(ipc_imem->debugfs_dir);
29+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
/* SPDX-License-Identifier: GPL-2.0-only
2+
*
3+
* Copyright (C) 2020-2021 Intel Corporation.
4+
*/
5+
6+
#ifndef IOSM_IPC_DEBUGFS_H
7+
#define IOSM_IPC_DEBUGFS_H
8+
9+
#ifdef CONFIG_WWAN_DEBUGFS
10+
void ipc_debugfs_init(struct iosm_imem *ipc_imem);
11+
void ipc_debugfs_deinit(struct iosm_imem *ipc_imem);
12+
#else
13+
static inline void ipc_debugfs_init(struct iosm_imem *ipc_imem) {}
14+
static inline void ipc_debugfs_deinit(struct iosm_imem *ipc_imem) {}
15+
#endif
16+
17+
#endif

drivers/net/wwan/iosm/iosm_ipc_imem.c

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include "iosm_ipc_imem.h"
1212
#include "iosm_ipc_port.h"
1313
#include "iosm_ipc_trace.h"
14+
#include "iosm_ipc_debugfs.h"
1415

1516
/* Check the wwan ips if it is valid with Channel as input. */
1617
static int ipc_imem_check_wwan_ips(struct ipc_mem_channel *chnl)
@@ -272,8 +273,8 @@ static void ipc_imem_dl_skb_process(struct iosm_imem *ipc_imem,
272273
if (port_id == IPC_MEM_CTRL_CHL_ID_7)
273274
ipc_imem_sys_devlink_notify_rx(ipc_imem->ipc_devlink,
274275
skb);
275-
else if (port_id == ipc_imem->trace->chl_id)
276-
ipc_trace_port_rx(ipc_imem->trace, skb);
276+
else if (ipc_is_trace_channel(ipc_imem, port_id))
277+
ipc_trace_port_rx(ipc_imem, skb);
277278
else
278279
wwan_port_rx(ipc_imem->ipc_port[port_id]->iosm_port,
279280
skb);
@@ -554,11 +555,7 @@ static void ipc_imem_run_state_worker(struct work_struct *instance)
554555
ctrl_chl_idx++;
555556
}
556557

557-
ipc_imem->trace = ipc_imem_trace_channel_init(ipc_imem);
558-
if (!ipc_imem->trace) {
559-
dev_err(ipc_imem->dev, "trace channel init failed");
560-
return;
561-
}
558+
ipc_debugfs_init(ipc_imem);
562559

563560
ipc_task_queue_send_task(ipc_imem, ipc_imem_send_mdm_rdy_cb, 0, NULL, 0,
564561
false);
@@ -1175,7 +1172,7 @@ void ipc_imem_cleanup(struct iosm_imem *ipc_imem)
11751172

11761173
if (test_and_clear_bit(FULLY_FUNCTIONAL, &ipc_imem->flag)) {
11771174
ipc_mux_deinit(ipc_imem->mux);
1178-
ipc_trace_deinit(ipc_imem->trace);
1175+
ipc_debugfs_deinit(ipc_imem);
11791176
ipc_wwan_deinit(ipc_imem->wwan);
11801177
ipc_port_deinit(ipc_imem->ipc_port);
11811178
}

drivers/net/wwan/iosm/iosm_ipc_imem.h

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ enum ipc_phase {
341341
* @ev_mux_net_transmit_pending:0 means inform the IPC tasklet to pass
342342
* @reset_det_n: Reset detect flag
343343
* @pcie_wake_n: Pcie wake flag
344+
* @debugfs_dir: Debug FS directory for driver-specific entries
344345
*/
345346
struct iosm_imem {
346347
struct iosm_mmio *mmio;
@@ -350,7 +351,9 @@ struct iosm_imem {
350351
struct iosm_mux *mux;
351352
struct iosm_cdev *ipc_port[IPC_MEM_MAX_CHANNELS];
352353
struct iosm_pcie *pcie;
354+
#ifdef CONFIG_WWAN_DEBUGFS
353355
struct iosm_trace *trace;
356+
#endif
354357
struct device *dev;
355358
enum ipc_mem_device_ipc_state ipc_requested_state;
356359
struct ipc_mem_channel channels[IPC_MEM_MAX_CHANNELS];
@@ -380,6 +383,9 @@ struct iosm_imem {
380383
ev_mux_net_transmit_pending:1,
381384
reset_det_n:1,
382385
pcie_wake_n:1;
386+
#ifdef CONFIG_WWAN_DEBUGFS
387+
struct dentry *debugfs_dir;
388+
#endif
383389
};
384390

385391
/**

drivers/net/wwan/iosm/iosm_ipc_imem_ops.c

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include "iosm_ipc_imem_ops.h"
1212
#include "iosm_ipc_port.h"
1313
#include "iosm_ipc_task_queue.h"
14-
#include "iosm_ipc_trace.h"
1514

1615
/* Open a packet data online channel between the network layer and CP. */
1716
int ipc_imem_sys_wwan_open(struct iosm_imem *ipc_imem, int if_id)
@@ -108,23 +107,6 @@ void ipc_imem_wwan_channel_init(struct iosm_imem *ipc_imem,
108107
"failed to register the ipc_wwan interfaces");
109108
}
110109

111-
/**
112-
* ipc_imem_trace_channel_init - Initializes trace channel.
113-
* @ipc_imem: Pointer to iosm_imem struct.
114-
*
115-
* Returns: Pointer to trace instance on success else NULL
116-
*/
117-
struct iosm_trace *ipc_imem_trace_channel_init(struct iosm_imem *ipc_imem)
118-
{
119-
struct ipc_chnl_cfg chnl_cfg = { 0 };
120-
121-
ipc_chnl_cfg_get(&chnl_cfg, IPC_MEM_CTRL_CHL_ID_3);
122-
ipc_imem_channel_init(ipc_imem, IPC_CTYPE_CTRL, chnl_cfg,
123-
IRQ_MOD_OFF);
124-
125-
return ipc_trace_init(ipc_imem);
126-
}
127-
128110
/* Map SKB to DMA for transfer */
129111
static int ipc_imem_map_skb_to_dma(struct iosm_imem *ipc_imem,
130112
struct sk_buff *skb)

drivers/net/wwan/iosm/iosm_ipc_imem_ops.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,5 +141,5 @@ int ipc_imem_sys_devlink_read(struct iosm_devlink *ipc_devlink, u8 *data,
141141
*/
142142
int ipc_imem_sys_devlink_write(struct iosm_devlink *ipc_devlink,
143143
unsigned char *buf, int count);
144-
struct iosm_trace *ipc_imem_trace_channel_init(struct iosm_imem *ipc_imem);
144+
145145
#endif

drivers/net/wwan/iosm/iosm_ipc_trace.c

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,13 @@
1717

1818
/**
1919
* ipc_trace_port_rx - Receive trace packet from cp and write to relay buffer
20-
* @ipc_trace: Pointer to the ipc trace data-struct
20+
* @ipc_imem: Pointer to iosm_imem structure
2121
* @skb: Pointer to struct sk_buff
2222
*/
23-
void ipc_trace_port_rx(struct iosm_trace *ipc_trace, struct sk_buff *skb)
23+
void ipc_trace_port_rx(struct iosm_imem *ipc_imem, struct sk_buff *skb)
2424
{
25+
struct iosm_trace *ipc_trace = ipc_imem->trace;
26+
2527
if (ipc_trace->ipc_rchan)
2628
relay_write(ipc_trace->ipc_rchan, skb->data, skb->len);
2729

@@ -132,9 +134,14 @@ static const struct file_operations ipc_trace_fops = {
132134
*/
133135
struct iosm_trace *ipc_trace_init(struct iosm_imem *ipc_imem)
134136
{
135-
struct iosm_trace *ipc_trace = kzalloc(sizeof(*ipc_trace), GFP_KERNEL);
136-
struct dentry *debugfs_pdev;
137+
struct ipc_chnl_cfg chnl_cfg = { 0 };
138+
struct iosm_trace *ipc_trace;
139+
140+
ipc_chnl_cfg_get(&chnl_cfg, IPC_MEM_CTRL_CHL_ID_3);
141+
ipc_imem_channel_init(ipc_imem, IPC_CTYPE_CTRL, chnl_cfg,
142+
IRQ_MOD_OFF);
137143

144+
ipc_trace = kzalloc(sizeof(*ipc_trace), GFP_KERNEL);
138145
if (!ipc_trace)
139146
return NULL;
140147

@@ -144,15 +151,14 @@ struct iosm_trace *ipc_trace_init(struct iosm_imem *ipc_imem)
144151
ipc_trace->chl_id = IPC_MEM_CTRL_CHL_ID_3;
145152

146153
mutex_init(&ipc_trace->trc_mutex);
147-
debugfs_pdev = wwan_get_debugfs_dir(ipc_imem->dev);
148154

149155
ipc_trace->ctrl_file = debugfs_create_file(IOSM_TRC_DEBUGFS_TRACE_CTRL,
150156
IOSM_TRC_FILE_PERM,
151-
debugfs_pdev,
157+
ipc_imem->debugfs_dir,
152158
ipc_trace, &ipc_trace_fops);
153159

154160
ipc_trace->ipc_rchan = relay_open(IOSM_TRC_DEBUGFS_TRACE,
155-
debugfs_pdev,
161+
ipc_imem->debugfs_dir,
156162
IOSM_TRC_SUB_BUFF_SIZE,
157163
IOSM_TRC_N_SUB_BUFF,
158164
&relay_callbacks, NULL);
@@ -166,6 +172,9 @@ struct iosm_trace *ipc_trace_init(struct iosm_imem *ipc_imem)
166172
*/
167173
void ipc_trace_deinit(struct iosm_trace *ipc_trace)
168174
{
175+
if (!ipc_trace)
176+
return;
177+
169178
debugfs_remove(ipc_trace->ctrl_file);
170179
relay_close(ipc_trace->ipc_rchan);
171180
mutex_destroy(&ipc_trace->trc_mutex);

drivers/net/wwan/iosm/iosm_ipc_trace.h

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,30 @@ struct iosm_trace {
4545
enum trace_ctrl_mode mode;
4646
};
4747

48+
#ifdef CONFIG_WWAN_DEBUGFS
49+
50+
static inline bool ipc_is_trace_channel(struct iosm_imem *ipc_mem, u16 chl_id)
51+
{
52+
return ipc_mem->trace && ipc_mem->trace->chl_id == chl_id;
53+
}
54+
4855
struct iosm_trace *ipc_trace_init(struct iosm_imem *ipc_imem);
4956
void ipc_trace_deinit(struct iosm_trace *ipc_trace);
50-
void ipc_trace_port_rx(struct iosm_trace *ipc_trace, struct sk_buff *skb);
57+
void ipc_trace_port_rx(struct iosm_imem *ipc_imem, struct sk_buff *skb);
58+
59+
#else
60+
61+
static inline bool ipc_is_trace_channel(struct iosm_imem *ipc_mem, u16 chl_id)
62+
{
63+
return false;
64+
}
65+
66+
static inline void ipc_trace_port_rx(struct iosm_imem *ipc_imem,
67+
struct sk_buff *skb)
68+
{
69+
dev_kfree_skb(skb);
70+
}
71+
72+
#endif
73+
5174
#endif

0 commit comments

Comments
 (0)