1 /* SPDX-License-Identifier: GPL-2.0-only
2  *
3  * Copyright (C) 2020-2021 Intel Corporation.
4  */
5 
6 #ifndef IOSM_IPC_TRACE_H
7 #define IOSM_IPC_TRACE_H
8 
9 #include <linux/debugfs.h>
10 #include <linux/relay.h>
11 
12 #include "iosm_ipc_chnl_cfg.h"
13 #include "iosm_ipc_imem_ops.h"
14 
15 /**
16  * enum trace_ctrl_mode - State of trace channel
17  * @TRACE_DISABLE:	mode for disable trace
18  * @TRACE_ENABLE:	mode for enable trace
19  */
20 enum trace_ctrl_mode {
21 	TRACE_DISABLE = 0,
22 	TRACE_ENABLE,
23 };
24 
25 /**
26  * struct iosm_trace - Struct for trace interface
27  * @ipc_rchan:		Pointer to relay channel
28  * @ctrl_file:		Pointer to trace control file
29  * @ipc_imem:		Imem instance
30  * @dev:		Pointer to device struct
31  * @channel:		Channel instance
32  * @chl_id:		Channel Indentifier
33  * @trc_mutex:		Mutex used for read and write mode
34  * @mode:		Mode for enable and disable trace
35  */
36 
37 struct iosm_trace {
38 	struct rchan *ipc_rchan;
39 	struct dentry *ctrl_file;
40 	struct iosm_imem *ipc_imem;
41 	struct device *dev;
42 	struct ipc_mem_channel *channel;
43 	enum ipc_channel_id chl_id;
44 	struct mutex trc_mutex;	/* Mutex used for read and write mode */
45 	enum trace_ctrl_mode mode;
46 };
47 
48 #ifdef CONFIG_WWAN_DEBUGFS
49 
ipc_is_trace_channel(struct iosm_imem * ipc_mem,u16 chl_id)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 
55 struct iosm_trace *ipc_trace_init(struct iosm_imem *ipc_imem);
56 void ipc_trace_deinit(struct iosm_trace *ipc_trace);
57 void ipc_trace_port_rx(struct iosm_imem *ipc_imem, struct sk_buff *skb);
58 
59 #else
60 
ipc_is_trace_channel(struct iosm_imem * ipc_mem,u16 chl_id)61 static inline bool ipc_is_trace_channel(struct iosm_imem *ipc_mem, u16 chl_id)
62 {
63 	return false;
64 }
65 
ipc_trace_port_rx(struct iosm_imem * ipc_imem,struct sk_buff * skb)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 
74 #endif
75