xref: /wlan-driver/qcacld-3.0/uapi/linux/pktlog_ac_fmt.h (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2012-2019 The Linux Foundation. All rights reserved.
3  * Copyright (c) 2022-2024 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_FMT_H_
21 #define _PKTLOG_FMT_H_
22 
23 #if defined(CONNECTIVITY_PKTLOG) || !defined(REMOVE_PKT_LOG)
24 
25 #define CUR_PKTLOG_VER          10010   /* Packet log version */
26 #define PKTLOG_MAGIC_NUM        7735225
27 
28 #ifdef __linux__
29 #ifdef MULTI_IF_NAME
30 #define PKTLOG_PROC_DIR "ath_pktlog" MULTI_IF_NAME
31 #define WLANDEV_BASENAME "cld" MULTI_IF_NAME
32 #else
33 #define PKTLOG_PROC_DIR "ath_pktlog"
34 #define WLANDEV_BASENAME "cld"
35 #endif
36 #endif
37 #define PKTLOG_PROC_SYSTEM "system"
38 #ifdef WIN32
39 #pragma pack(push, pktlog_fmt, 1)
40 #define __ATTRIB_PACK
41 #elif defined(__EFI__)
42 #define __ATTRIB_PACK
43 #else
44 #ifndef __ATTRIB_PACK
45 #define __ATTRIB_PACK __attribute__ ((packed))
46 #endif
47 #endif
48 #include <a_types.h>
49 /*
50  * Each packet log entry consists of the following fixed length header
51  * followed by variable length log information determined by log_type
52  */
53 
54 struct ath_pktlog_hdr {
55 	uint16_t flags;
56 	uint16_t missed_cnt;
57 #ifdef HELIUMPLUS
58 	uint8_t log_type;
59 	uint8_t macId;
60 #else
61 	uint16_t log_type;
62 #endif
63 	uint16_t size;
64 	uint32_t timestamp;
65 #ifdef PKTLOG_HAS_SPECIFIC_DATA
66 	uint32_t type_specific_data;
67 #endif
68 } __ATTRIB_PACK;
69 
70 #define ATH_PKTLOG_HDR_FLAGS_MASK 0xffff
71 #define ATH_PKTLOG_HDR_FLAGS_SHIFT 0
72 #define ATH_PKTLOG_HDR_FLAGS_OFFSET 0
73 #define ATH_PKTLOG_HDR_MISSED_CNT_MASK 0xffff0000
74 #define ATH_PKTLOG_HDR_MISSED_CNT_SHIFT 16
75 #define ATH_PKTLOG_HDR_MISSED_CNT_OFFSET 0
76 #ifdef HELIUMPLUS
77 #define ATH_PKTLOG_HDR_LOG_TYPE_MASK 0x00ff
78 #define ATH_PKTLOG_HDR_LOG_TYPE_SHIFT 0
79 #define ATH_PKTLOG_HDR_LOG_TYPE_OFFSET 1
80 #define ATH_PKTLOG_HDR_MAC_ID_MASK 0xff00
81 #define ATH_PKTLOG_HDR_MAC_ID_SHIFT 8
82 #define ATH_PKTLOG_HDR_MAC_ID_OFFSET 1
83 #else
84 #define ATH_PKTLOG_HDR_LOG_TYPE_MASK 0xffff
85 #define ATH_PKTLOG_HDR_LOG_TYPE_SHIFT 0
86 #define ATH_PKTLOG_HDR_LOG_TYPE_OFFSET 1
87 #endif
88 
89 #define ATH_PKTLOG_HDR_SIZE_MASK 0xffff0000
90 #define ATH_PKTLOG_HDR_SIZE_SHIFT 16
91 #define ATH_PKTLOG_HDR_SIZE_OFFSET 1
92 #define ATH_PKTLOG_HDR_TIMESTAMP_OFFSET 2
93 #define ATH_PKTLOG_HDR_TYPE_SPECIFIC_DATA_OFFSET 3
94 
95 /**
96  * enum - Pktlog flag field details
97  * @PKTLOG_FLG_FRM_TYPE_LOCAL_S: local-generated frame (tx)
98  * @PKTLOG_FLG_FRM_TYPE_REMOTE_S: remote-generated frame (rx)
99  * @PKTLOG_FLG_FRM_TYPE_CLONE_S: cloned frame
100  * @PKTLOG_FLG_FRM_TYPE_CBF_S: CBF remote frame
101  * @PKTLOG_FLG_FRM_TYPE_UNKNOWN_S: Unknown
102  *
103  * struct ath_pktlog_hdr flags field bit definitions,
104  * (use 1 << [enum] to assign)
105  */
106 enum {
107 	PKTLOG_FLG_FRM_TYPE_LOCAL_S = 0,
108 	PKTLOG_FLG_FRM_TYPE_REMOTE_S,
109 	PKTLOG_FLG_FRM_TYPE_CLONE_S,
110 	PKTLOG_FLG_FRM_TYPE_CBF_S,
111 	PKTLOG_FLG_FRM_TYPE_UNKNOWN_S
112 };
113 
114 #define PHFLAGS_INTERRUPT_CONTEXT 0x80000000
115 
116 /* Masks for setting pktlog events filters */
117 #define ATH_PKTLOG_TX       0x000000001
118 #define ATH_PKTLOG_RX       0x000000002
119 #define ATH_PKTLOG_RCFIND   0x000000004
120 #define ATH_PKTLOG_RCUPDATE 0x000000008
121 #define ATH_PKTLOG_ANI      0x000000010
122 #define ATH_PKTLOG_TEXT     0x000000020
123 #define ATH_PKTLOG_PHYERR   0x000000040
124 #define ATH_PKTLOG_PROMISC  0x000000080
125 #define ATH_PKTLOG_SW_EVENT 0x000000100
126 
127 /* WIN defns */
128 #define ATH_PKTLOG_H_INFO   0x000000200
129 #define ATH_PKTLOG_STEERING 0x000000400
130 #define ATH_PKTLOG_REMOTE_LOGGING_ENABLE  0x000000800
131 #define ATH_PKTLOG_TX_CAPTURE_ENABLE  0x000001000
132 #define ATH_PKTLOG_LITE_T2H  0x000002000
133 #define ATH_PKTLOG_LITE_RX   0x000004000
134 
135 /* Types of packet log events */
136 #define PKTLOG_TYPE_TX_CTRL      1
137 #define PKTLOG_TYPE_TX_STAT      2
138 #define PKTLOG_TYPE_TX_MSDU_ID   3
139 #define PKTLOG_TYPE_TX_FRM_HDR   4
140 #define PKTLOG_TYPE_RX_STAT      5
141 #define PKTLOG_TYPE_RC_FIND      6
142 #define PKTLOG_TYPE_RC_UPDATE    7
143 #define PKTLOG_TYPE_TX_VIRT_ADDR 8
144 #define PKTLOG_TYPE_SMART_ANTENNA 9
145 #define PKTLOG_TYPE_SW_EVENT     10
146 #define PKTLOG_TYPE_PKT_DUMP     11
147 /* Command to process Monitor status ring (Rx) buffers */
148 #define PKTLOG_TYPE_RX_STATBUF   22
149 /* Command to process PPDU Tx buffers from CE */
150 #define PKTLOG_TYPE_LITE_T2H     23
151 /* Command to process PPDU Rx buffers from Monitor status ring */
152 #define PKTLOG_TYPE_LITE_RX      24
153 #define PKTLOG_TYPE_MAX          25
154 
155 #define PKTLOG_MAX_TXCTL_WORDS 57       /* +2 words for bitmap */
156 #define PKTLOG_MAX_TXSTATUS_WORDS 32
157 #define PKTLOG_MAX_PROTO_WORDS  16
158 #define PKTLOG_MAX_RXDESC_WORDS 62
159 #define PKTLOG_HDR_SIZE_16      0x8000
160 
161 struct txctl_frm_hdr {
162 	uint16_t framectrl;     /* frame control field from header */
163 	uint16_t seqctrl;       /* frame control field from header */
164 	uint16_t bssid_tail;    /* last two octets of bssid */
165 	uint16_t sa_tail;       /* last two octets of SA */
166 	uint16_t da_tail;       /* last two octets of DA */
167 	uint16_t resvd;
168 };
169 
170 #if defined(HELIUMPLUS)
171 /* Peregrine 11ac based */
172 #define MAX_PKT_INFO_MSDU_ID 1
173 #else
174 /* Peregrine 11ac based */
175 #define MAX_PKT_INFO_MSDU_ID 192
176 #endif /* defined(HELIUMPLUS) */
177 
178 /*
179  * msdu_id_info_t is defined for reference only
180  */
181 struct msdu_id_info {
182 	uint32_t num_msdu;
183 	uint8_t bound_bmap[(MAX_PKT_INFO_MSDU_ID + 7)>>3];
184 	/* TODO:
185 	*  Convert the id's to uint32_t
186 	*  Reduces computation in the driver code
187 	*/
188 	uint16_t id[MAX_PKT_INFO_MSDU_ID];
189 } __ATTRIB_PACK;
190 #define MSDU_ID_INFO_NUM_MSDU_OFFSET 0 /* char offset */
191 #define MSDU_ID_INFO_BOUND_BM_OFFSET offsetof(struct msdu_id_info, bound_bmap)
192 #define MSDU_ID_INFO_ID_OFFSET  offsetof(struct msdu_id_info, id)
193 
194 
195 struct ath_pktlog_txctl {
196 	struct ath_pktlog_hdr pl_hdr;
197 	/* struct txctl_frm_hdr frm_hdr; */
198 	void *txdesc_hdr_ctl;   /* frm_hdr + Tx descriptor words */
199 	struct {
200 		struct txctl_frm_hdr frm_hdr;
201 		uint32_t txdesc_ctl[PKTLOG_MAX_TXCTL_WORDS];
202 		/* uint32_t *proto_hdr;   / * protocol header (variable length!) * / */
203 		/* uint32_t *misc; / * Can be used for HT specific or other misc info * / */
204 	} priv;
205 } __ATTRIB_PACK;
206 
207 struct ath_pktlog_tx_status {
208 	struct ath_pktlog_hdr pl_hdr;
209 	void *ds_status;
210 	int32_t misc[];	/* Can be used for HT specific or other misc info */
211 } __ATTRIB_PACK;
212 
213 struct ath_pktlog_msdu_info {
214 	struct ath_pktlog_hdr pl_hdr;
215 	void *ath_msdu_info;
216 	A_UINT32 num_msdu;
217 	struct {
218 		/*
219 		 * Provision to add more information fields
220 		 */
221 		struct msdu_info_t {
222 			A_UINT32 num_msdu;
223 			A_UINT8 bound_bmap[MAX_PKT_INFO_MSDU_ID >> 3];
224 		} msdu_id_info;
225 		/*
226 		 * array of num_msdu
227 		 * Static implementation will consume unwanted memory
228 		 * Need to split the pktlog_get_buf to get the buffer pointer only
229 		 */
230 		uint16_t msdu_len[MAX_PKT_INFO_MSDU_ID];
231 	} priv;
232 	size_t priv_size;
233 
234 } __ATTRIB_PACK;
235 
236 struct ath_pktlog_rx_info {
237 	struct ath_pktlog_hdr pl_hdr;
238 	void *rx_desc;
239 } __ATTRIB_PACK;
240 
241 struct ath_pktlog_rc_find {
242 	struct ath_pktlog_hdr pl_hdr;
243 	void *rcFind;
244 } __ATTRIB_PACK;
245 
246 struct ath_pktlog_sw_event {
247 	struct ath_pktlog_hdr pl_hdr;
248 	void *sw_event;
249 } __ATTRIB_PACK;
250 
251 struct ath_pktlog_rc_update {
252 	struct ath_pktlog_hdr pl_hdr;
253 	void *txRateCtrl;       /* rate control state proper */
254 } __ATTRIB_PACK;
255 
256 #ifdef WIN32
257 #pragma pack(pop, pktlog_fmt)
258 #endif
259 #ifdef __ATTRIB_PACK
260 #undef __ATTRIB_PACK
261 #endif /* __ATTRIB_PACK */
262 
263 /*
264  * The following header is included in the beginning of the file,
265  * followed by log entries when the log buffer is read through procfs
266  */
267 
268 struct ath_pktlog_bufhdr {
269 	uint32_t magic_num;     /* Used by post processing scripts */
270 	uint32_t version;       /* Set to CUR_PKTLOG_VER */
271 };
272 
273 struct ath_pktlog_buf {
274 	struct ath_pktlog_bufhdr bufhdr;
275 	int32_t rd_offset;
276 	volatile int32_t wr_offset;
277 	/* Whenever this bytes written value croses 4K bytes,
278 	 * logging will be triggered
279 	 */
280 	int32_t bytes_written;
281 	/* Index of the messages sent to userspace */
282 	uint32_t msg_index;
283 	/* Offset for read */
284 	loff_t offset;
285 	char log_data[];
286 };
287 
288 #define PKTLOG_MOV_RD_IDX(_rd_offset, _log_buf, _log_size)  \
289 	do { \
290 		if ((_rd_offset + sizeof(struct ath_pktlog_hdr) + \
291 		    ((struct ath_pktlog_hdr *)((_log_buf)->log_data + \
292 					       (_rd_offset)))->size) <= _log_size) { \
293 			_rd_offset = ((_rd_offset) + sizeof(struct ath_pktlog_hdr) + \
294 				      ((struct ath_pktlog_hdr *)((_log_buf)->log_data +	\
295 								 (_rd_offset)))->size);	\
296 		} else { \
297 			_rd_offset = ((struct ath_pktlog_hdr *)((_log_buf)->log_data +	\
298 								(_rd_offset)))->size;  \
299 		} \
300 		(_rd_offset) = (((_log_size) - (_rd_offset)) >=	\
301 				sizeof(struct ath_pktlog_hdr)) ? _rd_offset : 0; \
302 	} while (0)
303 
304 #endif /* REMOVE_PKT_LOG */
305 
306 /**
307  * enum pkt_type - packet type
308  * @START_MONITOR: indicates parser to start packetdump parsing
309  * @STOP_MONITOR: indicates parser to stop packetdump parsing
310  * @TX_MGMT_PKT: TX management Packet
311  * @TX_DATA_PKT: TX data Packet
312  * @RX_MGMT_PKT: RX management Packet
313  * @RX_DATA_PKT: RX data Packet
314  * @INVALID_PKT: Invalid packet
315  *
316  * This enum has packet types
317  */
318 enum pkt_type {
319 	START_MONITOR = 1,
320 	STOP_MONITOR,
321 	TX_MGMT_PKT,
322 	TX_DATA_PKT,
323 	RX_MGMT_PKT,
324 	RX_DATA_PKT,
325 	INVALID_PKT,
326 };
327 
328 /**
329  * enum tx_pkt_fate - tx packet fate
330  * @TX_PKT_FATE_ACKED: Sent over air and ACKed
331  * @TX_PKT_FATE_SENT: Sent over air but not ACKed.
332  * @TX_PKT_FATE_FW_QUEUED: Queued within firmware,
333  * but not yet sent over air
334  * @TX_PKT_FATE_FW_DROP_INVALID: Dropped by firmware as invalid.
335  * E.g. bad source address, bad checksum, or invalid for current state.
336  * @TX_PKT_FATE_FW_DROP_NOBUFS: Dropped by firmware due
337  * to lack of buffer space
338  * @TX_PKT_FATE_FW_DROP_OTHER: Dropped by firmware for any other
339  * reason. Includes frames that were sent by driver to firmware, but
340  * unaccounted for by firmware.
341  * @TX_PKT_FATE_DRV_QUEUED: Queued within driver, not yet sent to firmware.
342  * @TX_PKT_FATE_DRV_DROP_INVALID: Dropped by driver as invalid.
343  * E.g. bad source address, or invalid for current state.
344  * @TX_PKT_FATE_DRV_DROP_NOBUFS: Dropped by driver due to lack of buffer space
345  * @TX_PKT_FATE_DRV_DROP_OTHER: Dropped by driver for any other reason.
346  * E.g. out of buffers.
347  *
348  * This enum has packet fate types
349  */
350 
351 enum tx_pkt_fate {
352 	TX_PKT_FATE_ACKED,
353 	TX_PKT_FATE_SENT,
354 	TX_PKT_FATE_FW_QUEUED,
355 	TX_PKT_FATE_FW_DROP_INVALID,
356 	TX_PKT_FATE_FW_DROP_NOBUFS,
357 	TX_PKT_FATE_FW_DROP_OTHER,
358 	TX_PKT_FATE_DRV_QUEUED,
359 	TX_PKT_FATE_DRV_DROP_INVALID,
360 	TX_PKT_FATE_DRV_DROP_NOBUFS,
361 	TX_PKT_FATE_DRV_DROP_OTHER,
362 };
363 
364 /**
365  * enum rx_pkt_fate - rx packet fate
366  * @RX_PKT_FATE_SUCCESS: Valid and delivered to
367  * network stack (e.g., netif_rx()).
368  * @RX_PKT_FATE_FW_QUEUED: Queued within firmware,
369  * but not yet sent to driver.
370  * @RX_PKT_FATE_FW_DROP_FILTER: Dropped by firmware
371  * due to host-programmable filters.
372  * @RX_PKT_FATE_FW_DROP_INVALID: Dropped by firmware
373  * as invalid. E.g. bad checksum, decrypt failed, or invalid for current state.
374  * @RX_PKT_FATE_FW_DROP_NOBUFS: Dropped by firmware
375  * due to lack of buffer space.
376  * @RX_PKT_FATE_FW_DROP_OTHER: Dropped by firmware
377  * for any other reason.
378  * @RX_PKT_FATE_DRV_QUEUED: Queued within driver,
379  * not yet delivered to network stack.
380  * @RX_PKT_FATE_DRV_DROP_FILTER: Dropped by driver
381  * due to filter rules.
382  * @RX_PKT_FATE_DRV_DROP_INVALID: Dropped by driver as invalid.
383  * E.g. not permitted in current state.
384  * @RX_PKT_FATE_DRV_DROP_NOBUFS: Dropped by driver
385  * due to lack of buffer space.
386  * @RX_PKT_FATE_DRV_DROP_OTHER: Dropped by driver for any other reason.
387  *
388  * This enum has packet fate types
389  */
390 
391 enum rx_pkt_fate {
392 	RX_PKT_FATE_SUCCESS,
393 	RX_PKT_FATE_FW_QUEUED,
394 	RX_PKT_FATE_FW_DROP_FILTER,
395 	RX_PKT_FATE_FW_DROP_INVALID,
396 	RX_PKT_FATE_FW_DROP_NOBUFS,
397 	RX_PKT_FATE_FW_DROP_OTHER,
398 	RX_PKT_FATE_DRV_QUEUED,
399 	RX_PKT_FATE_DRV_DROP_FILTER,
400 	RX_PKT_FATE_DRV_DROP_INVALID,
401 	RX_PKT_FATE_DRV_DROP_NOBUFS,
402 	RX_PKT_FATE_DRV_DROP_OTHER,
403 };
404 
405 #endif /* _PKTLOG_FMT_H_ */
406