xref: /wlan-driver/qca-wifi-host-cmn/utils/pktlog/include/pktlog_ac.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2012-2020 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2023 Qualcomm Innovation Center, Inc. All rights reserved.
4  *
5  * Permission to use, copy, modify, and/or distribute this software for
6  * any purpose with or without fee is hereby granted, provided that the
7  * above copyright notice and this permission notice appear in all
8  * copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
11  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
12  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
13  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
14  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
15  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
16  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 #ifndef _PKTLOG_AC_H_
21 #define _PKTLOG_AC_H_
22 
23 #include "hif.h"
24 #if defined(CONNECTIVITY_PKTLOG) || !defined(REMOVE_PKT_LOG)
25 #include "ol_if_athvar.h"
26 #include "osdep.h"
27 #include <wmi_unified.h>
28 #include <wmi_unified_api.h>
29 #include <wdi_event_api.h>
30 #include <ol_defines.h>
31 #include <pktlog_ac_api.h>
32 #include <pktlog_ac_fmt.h>
33 
34 #define NO_REG_FUNCS    4
35 
36 /* Locking interface for pktlog */
37 #define PKTLOG_LOCK_INIT(_pl_info)    qdf_spinlock_create(&(_pl_info)->log_lock)
38 #define PKTLOG_LOCK_DESTROY(_pl_info) \
39 				qdf_spinlock_destroy(&(_pl_info)->log_lock)
40 #define PKTLOG_LOCK(_pl_info)         qdf_spin_lock_bh(&(_pl_info)->log_lock)
41 #define PKTLOG_UNLOCK(_pl_info)       qdf_spin_unlock_bh(&(_pl_info)->log_lock)
42 
43 #define PKTLOG_MODE_SYSTEM      1
44 #define PKTLOG_MODE_ADAPTER     2
45 
46 /*
47  * The proc entry starts with magic number and version field which will be
48  * used by post processing scripts. These fields are not needed by applications
49  * that do not use these scripts. This is skipped using the offset value.
50  */
51 #define PKTLOG_READ_OFFSET    8
52 
53 /* forward declaration for cdp_pdev */
54 struct cdp_pdev;
55 
56 /* Opaque softc */
57 struct ol_ath_generic_softc_t;
58 typedef struct ol_ath_generic_softc_t *ol_ath_generic_softc_handle;
59 extern void pktlog_disable_adapter_logging(struct hif_opaque_softc *scn);
60 extern int pktlog_alloc_buf(struct hif_opaque_softc *scn);
61 extern void pktlog_release_buf(struct hif_opaque_softc *scn);
62 
63 ssize_t pktlog_read_proc_entry(char *buf, size_t nbytes, loff_t *ppos,
64 		struct ath_pktlog_info *pl_info, bool *read_complete);
65 
66 /**
67  * wdi_pktlog_unsubscribe() - Unsubscribe pktlog callbacks
68  * @pdev_id: pdev id
69  * @log_state: Pktlog registration
70  *
71  * Return: zero on success, non-zero on failure
72  */
73 A_STATUS wdi_pktlog_unsubscribe(uint8_t pdev_id, uint32_t log_state);
74 
75 struct ol_pl_arch_dep_funcs {
76 	void (*pktlog_init)(struct hif_opaque_softc *scn);
77 	int (*pktlog_enable)(struct hif_opaque_softc *scn, int32_t log_state,
78 			     bool ini, uint8_t user,
79 			     uint32_t is_iwpriv_command);
80 	int (*pktlog_setsize)(struct hif_opaque_softc *scn, int32_t log_state);
81 	int (*pktlog_disable)(struct hif_opaque_softc *scn);
82 };
83 
84 struct ol_pl_os_dep_funcs {
85 	int (*pktlog_attach)(struct hif_opaque_softc *scn);
86 	void (*pktlog_detach)(struct hif_opaque_softc *scn);
87 
88 };
89 
90 struct ath_pktlog_wmi_params {
91 	WMI_PKTLOG_EVENT pktlog_event;
92 	WMI_CMD_ID cmd_id;
93 	bool ini_triggered;
94 	uint8_t user_triggered;
95 };
96 
97 extern struct ol_pl_arch_dep_funcs ol_pl_funcs;
98 extern struct ol_pl_os_dep_funcs *g_ol_pl_os_dep_funcs;
99 
100 /* Pktlog handler to save the state of the pktlogs */
101 struct pktlog_dev_t {
102 	struct ol_pl_arch_dep_funcs *pl_funcs;
103 	struct ath_pktlog_info *pl_info;
104 	ol_ath_generic_softc_handle scn;
105 	uint8_t pdev_id;
106 	char *name;
107 	bool tgt_pktlog_alloced;
108 	bool is_pktlog_cb_subscribed;
109 	bool mt_pktlog_enabled;
110 	uint32_t htc_err_cnt;
111 	uint8_t htc_endpoint;
112 	void *htc_pdev;
113 	bool vendor_cmd_send;
114 	uint8_t callback_type;
115 	uint32_t invalid_packets;
116 };
117 
118 #define PKTLOG_SYSCTL_SIZE      14
119 #define PKTLOG_MAX_SEND_QUEUE_DEPTH 64
120 
121 /*
122  * Linux specific pktlog state information
123  */
124 struct ath_pktlog_info_lnx {
125 	struct ath_pktlog_info info;
126 	struct ctl_table sysctls[PKTLOG_SYSCTL_SIZE];
127 	struct proc_dir_entry *proc_entry;
128 	struct ctl_table_header *sysctl_header;
129 };
130 
131 #define PL_INFO_LNX(_pl_info)   ((struct ath_pktlog_info_lnx *)(_pl_info))
132 
133 /*
134  * WDI related data and functions
135  * Callback function to the WDI events
136  */
137 void pktlog_callback(void *pdev, enum WDI_EVENT event, void *log_data,
138 			u_int16_t peer_id, uint32_t status);
139 
140 void pktlog_init(struct hif_opaque_softc *scn);
141 int pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state,
142 		 bool, uint8_t, uint32_t);
143 int __pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state,
144 		    bool ini_triggered, uint8_t user_triggered,
145 		    uint32_t is_iwpriv_command);
146 int pktlog_setsize(struct hif_opaque_softc *scn, int32_t log_state);
147 int pktlog_clearbuff(struct hif_opaque_softc *scn, bool clear_buff);
148 int pktlog_disable(struct hif_opaque_softc *scn);
149 int pktlogmod_init(void *context);
150 void pktlogmod_exit(void *context);
151 int pktlog_htc_attach(void);
152 
153 /**
154  * pktlog_process_fw_msg() - process packetlog message
155  * @pdev_id: physical device instance id
156  * @msg_word: message buffer
157  * @msg_len: message length
158  *
159  * Return: None
160  */
161 void pktlog_process_fw_msg(uint8_t pdev_id, uint32_t *msg_word,
162 			   uint32_t msg_len);
163 void lit_pktlog_callback(void *context, enum WDI_EVENT event, void *log_data,
164 	u_int16_t peer_id, uint32_t status);
165 
166 #define ol_pktlog_attach(_scn)			\
167 	do {					\
168 		if (g_ol_pl_os_dep_funcs) {	\
169 			g_ol_pl_os_dep_funcs->pktlog_attach(_scn);	\
170 		}				\
171 	} while (0)
172 
173 #define ol_pktlog_detach(_scn)			\
174 	do {					\
175 		if (g_ol_pl_os_dep_funcs) {	\
176 			g_ol_pl_os_dep_funcs->pktlog_detach(_scn);	\
177 		}				\
178 	} while (0)
179 
180 #else                           /* REMOVE_PKT_LOG */
181 #define ol_pktlog_attach(_scn)  ({ (void)_scn; })
182 #define ol_pktlog_detach(_scn)  ({ (void)_scn; })
pktlog_init(struct hif_opaque_softc * scn)183 static inline void pktlog_init(struct hif_opaque_softc *scn)
184 {
185 	return;
186 }
187 
pktlog_enable(struct hif_opaque_softc * scn,int32_t log_state,bool ini,uint8_t user,uint32_t is_iwpriv_command)188 static inline int pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state,
189 				bool ini, uint8_t user,
190 				uint32_t is_iwpriv_command)
191 {
192 	return 0;
193 }
194 
195 static inline
__pktlog_enable(struct hif_opaque_softc * scn,int32_t log_state,bool ini_triggered,uint8_t user_triggered,uint32_t is_iwpriv_command)196 int __pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state,
197 		    bool ini_triggered, uint8_t user_triggered,
198 		    uint32_t is_iwpriv_command)
199 {
200 	return 0;
201 }
202 
pktlog_setsize(struct hif_opaque_softc * scn,int32_t log_state)203 static inline int pktlog_setsize(struct hif_opaque_softc *scn,
204 				 int32_t log_state)
205 {
206 	return 0;
207 }
208 
pktlog_clearbuff(struct hif_opaque_softc * scn,bool clear_buff)209 static inline int pktlog_clearbuff(struct hif_opaque_softc *scn,
210 				   bool clear_buff)
211 {
212 	return 0;
213 }
214 
pktlog_disable(struct hif_opaque_softc * scn)215 static inline int pktlog_disable(struct hif_opaque_softc *scn)
216 {
217 	return 0;
218 }
219 
pktlog_htc_attach(void)220 static inline int pktlog_htc_attach(void)
221 {
222 	return 0;
223 }
224 
pktlog_process_fw_msg(uint8_t pdev_id,uint32_t * msg_word,uint32_t msg_len)225 static inline void pktlog_process_fw_msg(uint8_t pdev_id, uint32_t *msg_word,
226 					 uint32_t msg_len)
227 { }
228 #endif /* REMOVE_PKT_LOG */
229 #endif /* _PKTLOG_AC_H_ */
230