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