xref: /wlan-dirver/qca-wifi-host-cmn/utils/pktlog/include/pktlog_ac.h (revision 6ecd284e5a94a1c96e26d571dd47419ac305990d)
1 /*
2  * Copyright (c) 2012-2018 The Linux Foundation. All rights reserved.
3  *
4  * Previously licensed under the ISC license by Qualcomm Atheros, Inc.
5  *
6  *
7  * Permission to use, copy, modify, and/or distribute this software for
8  * any purpose with or without fee is hereby granted, provided that the
9  * above copyright notice and this permission notice appear in all
10  * copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
13  * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
14  * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
15  * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
16  * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
17  * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
18  * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
19  * PERFORMANCE OF THIS SOFTWARE.
20  */
21 
22 /*
23  * This file was originally distributed by Qualcomm Atheros, Inc.
24  * under proprietary terms before Copyright ownership was assigned
25  * to the Linux Foundation.
26  */
27 
28 #ifndef _PKTLOG_AC_H_
29 #define _PKTLOG_AC_H_
30 
31 #ifndef REMOVE_PKT_LOG
32 #include "ol_if_athvar.h"
33 #include "osdep.h"
34 #include <wmi_unified.h>
35 #include <wmi_unified_api.h>
36 #include <wdi_event_api.h>
37 #include "hif.h"
38 #include <ol_defines.h>
39 #include <pktlog_ac_api.h>
40 #include <pktlog_ac_fmt.h>
41 
42 #define NO_REG_FUNCS    4
43 
44 /* Locking interface for pktlog */
45 #define PKTLOG_LOCK_INIT(_pl_info)      spin_lock_init(&(_pl_info)->log_lock)
46 #define PKTLOG_LOCK_DESTROY(_pl_info)
47 #define PKTLOG_LOCK(_pl_info)           spin_lock(&(_pl_info)->log_lock)
48 #define PKTLOG_UNLOCK(_pl_info)         spin_unlock(&(_pl_info)->log_lock)
49 
50 #define PKTLOG_MODE_SYSTEM      1
51 #define PKTLOG_MODE_ADAPTER     2
52 
53 /*
54  * The proc entry starts with magic number and version field which will be
55  * used by post processing scripts. These fields are not needed by applications
56  * that do not use these scripts. This is skipped using the offset value.
57  */
58 #define PKTLOG_READ_OFFSET    8
59 
60 /* forward declaration for cdp_pdev */
61 struct cdp_pdev;
62 
63 /* Opaque softc */
64 struct ol_ath_generic_softc_t;
65 typedef struct ol_ath_generic_softc_t *ol_ath_generic_softc_handle;
66 extern void pktlog_disable_adapter_logging(struct hif_opaque_softc *scn);
67 extern int pktlog_alloc_buf(struct hif_opaque_softc *scn);
68 extern void pktlog_release_buf(struct hif_opaque_softc *scn);
69 
70 ssize_t pktlog_read_proc_entry(char *buf, size_t nbytes, loff_t *ppos,
71 		struct ath_pktlog_info *pl_info, bool *read_complete);
72 int pktlog_send_per_pkt_stats_to_user(void);
73 A_STATUS wdi_pktlog_unsubscribe(struct cdp_pdev *txrx_pdev, 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 	char *name;
106 	bool tgt_pktlog_alloced;
107 	bool is_pktlog_cb_subscribed;
108 	bool mt_pktlog_enabled;
109 	uint32_t htc_err_cnt;
110 	uint8_t htc_endpoint;
111 	void *htc_pdev;
112 	bool vendor_cmd_send;
113 	uint8_t callback_type;
114 };
115 
116 #define PKTLOG_SYSCTL_SIZE      14
117 #define PKTLOG_MAX_SEND_QUEUE_DEPTH 64
118 
119 /*
120  * Linux specific pktlog state information
121  */
122 struct ath_pktlog_info_lnx {
123 	struct ath_pktlog_info info;
124 	struct ctl_table sysctls[PKTLOG_SYSCTL_SIZE];
125 	struct proc_dir_entry *proc_entry;
126 	struct ctl_table_header *sysctl_header;
127 };
128 
129 #define PL_INFO_LNX(_pl_info)   ((struct ath_pktlog_info_lnx *)(_pl_info))
130 
131 extern struct ol_pktlog_dev_t ol_pl_dev;
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_setsize(struct hif_opaque_softc *scn, int32_t log_state);
144 int pktlog_clearbuff(struct hif_opaque_softc *scn, bool clear_buff);
145 int pktlog_disable(struct hif_opaque_softc *scn);
146 int pktlogmod_init(void *context);
147 void pktlogmod_exit(void *context);
148 int pktlog_htc_attach(void);
149 void pktlog_process_fw_msg(uint32_t *msg_word, uint32_t msg_len);
150 void lit_pktlog_callback(void *context, enum WDI_EVENT event, void *log_data,
151 	u_int16_t peer_id, uint32_t status);
152 
153 #define ol_pktlog_attach(_scn)			\
154 	do {					\
155 		if (g_ol_pl_os_dep_funcs) {	\
156 			g_ol_pl_os_dep_funcs->pktlog_attach(_scn);	\
157 		}				\
158 	} while (0)
159 
160 #define ol_pktlog_detach(_scn)			\
161 	do {					\
162 		if (g_ol_pl_os_dep_funcs) {	\
163 			g_ol_pl_os_dep_funcs->pktlog_detach(_scn);	\
164 		}				\
165 	} while (0)
166 
167 #else                           /* REMOVE_PKT_LOG */
168 #define ol_pktlog_attach(_scn)  ({ (void)_scn; })
169 #define ol_pktlog_detach(_scn)  ({ (void)_scn; })
170 static inline void pktlog_init(struct hif_opaque_softc *scn)
171 {
172 	return;
173 }
174 static int pktlog_enable(struct hif_opaque_softc *scn, int32_t log_state,
175 			 bool ini, uint8_t user, uint32_t is_iwpriv_command)
176 {
177 	return 0;
178 }
179 static int pktlog_setsize(struct hif_opaque_softc *scn, int32_t log_state)
180 {
181 	return 0;
182 }
183 static int pktlog_clearbuff(struct hif_opaque_softc *scn, bool clear_buff)
184 {
185 	return 0;
186 }
187 static int pktlog_disable(struct hif_opaque_softc *scn)
188 {
189 	return 0;
190 }
191 static inline int pktlog_htc_attach(void)
192 {
193 	return 0;
194 }
195 static inline void pktlog_process_fw_msg(uint32_t *msg_word, uint32_t msg_len)
196 { }
197 #endif /* REMOVE_PKT_LOG */
198 #endif /* _PKTLOG_AC_H_ */
199