xref: /wlan-dirver/qca-wifi-host-cmn/dp/wifi3.0/dp_internal.h (revision 1b9674e21e24478fba4530f5ae7396b9555e9c6a)
1 /*
2  * Copyright (c) 2016-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 _DP_INTERNAL_H_
20 #define _DP_INTERNAL_H_
21 
22 #include "dp_types.h"
23 
24 #define RX_BUFFER_SIZE_PKTLOG_LITE 1024
25 
26 /* Macro For NYSM value received in VHT TLV */
27 #define VHT_SGI_NYSM 3
28 
29 #if DP_PRINT_ENABLE
30 #include <stdarg.h>       /* va_list */
31 #include <qdf_types.h> /* qdf_vprint */
32 #include <cdp_txrx_handle.h>
33 
34 enum {
35 	/* FATAL_ERR - print only irrecoverable error messages */
36 	DP_PRINT_LEVEL_FATAL_ERR,
37 
38 	/* ERR - include non-fatal err messages */
39 	DP_PRINT_LEVEL_ERR,
40 
41 	/* WARN - include warnings */
42 	DP_PRINT_LEVEL_WARN,
43 
44 	/* INFO1 - include fundamental, infrequent events */
45 	DP_PRINT_LEVEL_INFO1,
46 
47 	/* INFO2 - include non-fundamental but infrequent events */
48 	DP_PRINT_LEVEL_INFO2,
49 };
50 
51 
52 #define dp_print(level, fmt, ...) do { \
53 	if (level <= g_txrx_print_level) \
54 		qdf_print(fmt, ## __VA_ARGS__); \
55 while (0)
56 #define DP_PRINT(level, fmt, ...) do { \
57 	dp_print(level, "DP: " fmt, ## __VA_ARGS__); \
58 while (0)
59 #else
60 #define DP_PRINT(level, fmt, ...)
61 #endif /* DP_PRINT_ENABLE */
62 
63 #define DP_TRACE(LVL, fmt, args ...)                             \
64 	QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_##LVL,       \
65 		fmt, ## args)
66 
67 #define DP_TRACE_STATS(LVL, fmt, args ...)                             \
68 	QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_##LVL,       \
69 		fmt, ## args)
70 
71 #define DP_PRINT_STATS(fmt, args ...)	\
72 	QDF_TRACE(QDF_MODULE_ID_DP, QDF_TRACE_LEVEL_FATAL,       \
73 		fmt, ## args)
74 
75 #define DP_STATS_INIT(_handle) \
76 	qdf_mem_set(&((_handle)->stats), sizeof((_handle)->stats), 0x0)
77 
78 #define DP_STATS_CLR(_handle) \
79 	qdf_mem_set(&((_handle)->stats), sizeof((_handle)->stats), 0x0)
80 
81 #ifndef DISABLE_DP_STATS
82 #define DP_STATS_INC(_handle, _field, _delta) \
83 { \
84 	if (likely(_handle)) \
85 		_handle->stats._field += _delta; \
86 }
87 
88 #define DP_STATS_INCC(_handle, _field, _delta, _cond) \
89 { \
90 	if (_cond && likely(_handle)) \
91 		_handle->stats._field += _delta; \
92 }
93 
94 #define DP_STATS_DEC(_handle, _field, _delta) \
95 { \
96 	if (likely(_handle)) \
97 		_handle->stats._field -= _delta; \
98 }
99 
100 #define DP_STATS_UPD(_handle, _field, _delta) \
101 { \
102 	if (likely(_handle)) \
103 		_handle->stats._field = _delta; \
104 }
105 
106 #define DP_STATS_INC_PKT(_handle, _field, _count, _bytes) \
107 { \
108 	DP_STATS_INC(_handle, _field.num, _count); \
109 	DP_STATS_INC(_handle, _field.bytes, _bytes) \
110 }
111 
112 #define DP_STATS_INCC_PKT(_handle, _field, _count, _bytes, _cond) \
113 { \
114 	DP_STATS_INCC(_handle, _field.num, _count, _cond); \
115 	DP_STATS_INCC(_handle, _field.bytes, _bytes, _cond) \
116 }
117 
118 #define DP_STATS_AGGR(_handle_a, _handle_b, _field) \
119 { \
120 	_handle_a->stats._field += _handle_b->stats._field; \
121 }
122 
123 #define DP_STATS_AGGR_PKT(_handle_a, _handle_b, _field) \
124 { \
125 	DP_STATS_AGGR(_handle_a, _handle_b, _field.num); \
126 	DP_STATS_AGGR(_handle_a, _handle_b, _field.bytes);\
127 }
128 
129 #define DP_STATS_UPD_STRUCT(_handle_a, _handle_b, _field) \
130 { \
131 	_handle_a->stats._field = _handle_b->stats._field; \
132 }
133 
134 #define DP_HIST_INIT() \
135 	uint32_t num_of_packets[MAX_PDEV_CNT] = {0};
136 
137 #define DP_HIST_PACKET_COUNT_INC(_pdev_id) \
138 { \
139 		++num_of_packets[_pdev_id]; \
140 }
141 
142 #define DP_TX_HISTOGRAM_UPDATE(_pdev, _p_cntrs) \
143 	do {                                                              \
144 		if (_p_cntrs == 1) {                                      \
145 			DP_STATS_INC(_pdev,                               \
146 				tx_comp_histogram.pkts_1, 1);             \
147 		} else if (_p_cntrs > 1 && _p_cntrs <= 20) {              \
148 			DP_STATS_INC(_pdev,                               \
149 				tx_comp_histogram.pkts_2_20, 1);          \
150 		} else if (_p_cntrs > 20 && _p_cntrs <= 40) {             \
151 			DP_STATS_INC(_pdev,                               \
152 				tx_comp_histogram.pkts_21_40, 1);         \
153 		} else if (_p_cntrs > 40 && _p_cntrs <= 60) {             \
154 			DP_STATS_INC(_pdev,                               \
155 				tx_comp_histogram.pkts_41_60, 1);         \
156 		} else if (_p_cntrs > 60 && _p_cntrs <= 80) {             \
157 			DP_STATS_INC(_pdev,                               \
158 				tx_comp_histogram.pkts_61_80, 1);         \
159 		} else if (_p_cntrs > 80 && _p_cntrs <= 100) {            \
160 			DP_STATS_INC(_pdev,                               \
161 				tx_comp_histogram.pkts_81_100, 1);        \
162 		} else if (_p_cntrs > 100 && _p_cntrs <= 200) {           \
163 			DP_STATS_INC(_pdev,                               \
164 				tx_comp_histogram.pkts_101_200, 1);       \
165 		} else if (_p_cntrs > 200) {                              \
166 			DP_STATS_INC(_pdev,                               \
167 				tx_comp_histogram.pkts_201_plus, 1);      \
168 		}                                                         \
169 	} while (0)
170 
171 #define DP_RX_HISTOGRAM_UPDATE(_pdev, _p_cntrs) \
172 	do {                                                              \
173 		if (_p_cntrs == 1) {                                      \
174 			DP_STATS_INC(_pdev,                               \
175 				rx_ind_histogram.pkts_1, 1);              \
176 		} else if (_p_cntrs > 1 && _p_cntrs <= 20) {              \
177 			DP_STATS_INC(_pdev,                               \
178 				rx_ind_histogram.pkts_2_20, 1);           \
179 		} else if (_p_cntrs > 20 && _p_cntrs <= 40) {             \
180 			DP_STATS_INC(_pdev,                               \
181 				rx_ind_histogram.pkts_21_40, 1);          \
182 		} else if (_p_cntrs > 40 && _p_cntrs <= 60) {             \
183 			DP_STATS_INC(_pdev,                               \
184 				rx_ind_histogram.pkts_41_60, 1);          \
185 		} else if (_p_cntrs > 60 && _p_cntrs <= 80) {             \
186 			DP_STATS_INC(_pdev,                               \
187 				rx_ind_histogram.pkts_61_80, 1);          \
188 		} else if (_p_cntrs > 80 && _p_cntrs <= 100) {            \
189 			DP_STATS_INC(_pdev,                               \
190 				rx_ind_histogram.pkts_81_100, 1);         \
191 		} else if (_p_cntrs > 100 && _p_cntrs <= 200) {           \
192 			DP_STATS_INC(_pdev,                               \
193 				rx_ind_histogram.pkts_101_200, 1);        \
194 		} else if (_p_cntrs > 200) {                              \
195 			DP_STATS_INC(_pdev,                               \
196 				rx_ind_histogram.pkts_201_plus, 1);       \
197 		}                                                         \
198 	} while (0)
199 
200 #define DP_TX_HIST_STATS_PER_PDEV() \
201 	do { \
202 		uint8_t hist_stats = 0; \
203 		for (hist_stats = 0; hist_stats < soc->pdev_count; \
204 				hist_stats++) { \
205 			DP_TX_HISTOGRAM_UPDATE(soc->pdev_list[hist_stats], \
206 					num_of_packets[hist_stats]); \
207 		} \
208 	}  while (0)
209 
210 
211 #define DP_RX_HIST_STATS_PER_PDEV() \
212 	do { \
213 		uint8_t hist_stats = 0; \
214 		for (hist_stats = 0; hist_stats < soc->pdev_count; \
215 				hist_stats++) { \
216 			DP_RX_HISTOGRAM_UPDATE(soc->pdev_list[hist_stats], \
217 					num_of_packets[hist_stats]); \
218 		} \
219 	}  while (0)
220 
221 
222 #else
223 #define DP_STATS_INC(_handle, _field, _delta)
224 #define DP_STATS_INCC(_handle, _field, _delta, _cond)
225 #define DP_STATS_DEC(_handle, _field, _delta)
226 #define DP_STATS_UPD(_handle, _field, _delta)
227 #define DP_STATS_INC_PKT(_handle, _field, _count, _bytes)
228 #define DP_STATS_INCC_PKT(_handle, _field, _count, _bytes, _cond)
229 #define DP_STATS_AGGR(_handle_a, _handle_b, _field)
230 #define DP_STATS_AGGR_PKT(_handle_a, _handle_b, _field)
231 #define DP_HIST_INIT()
232 #define DP_HIST_PACKET_COUNT_INC(_pdev_id)
233 #define DP_TX_HISTOGRAM_UPDATE(_pdev, _p_cntrs)
234 #define DP_RX_HISTOGRAM_UPDATE(_pdev, _p_cntrs)
235 #define DP_RX_HIST_STATS_PER_PDEV()
236 #define DP_TX_HIST_STATS_PER_PDEV()
237 #endif
238 
239 #define DP_HTT_T2H_HP_PIPE 5
240 static inline void dp_update_pdev_stats(struct dp_pdev *tgtobj,
241 					struct cdp_vdev_stats *srcobj)
242 {
243 	uint8_t i;
244 	uint8_t pream_type;
245 
246 	for (pream_type = 0; pream_type < DOT11_MAX; pream_type++) {
247 		for (i = 0; i < MAX_MCS; i++) {
248 			tgtobj->stats.tx.pkt_type[pream_type].
249 				mcs_count[i] +=
250 			srcobj->tx.pkt_type[pream_type].
251 				mcs_count[i];
252 			tgtobj->stats.rx.pkt_type[pream_type].
253 				mcs_count[i] +=
254 			srcobj->rx.pkt_type[pream_type].
255 				mcs_count[i];
256 		}
257 	}
258 
259 	for (i = 0; i < MAX_BW; i++) {
260 		tgtobj->stats.tx.bw[i] += srcobj->tx.bw[i];
261 		tgtobj->stats.rx.bw[i] += srcobj->rx.bw[i];
262 	}
263 
264 	for (i = 0; i < SS_COUNT; i++) {
265 		tgtobj->stats.tx.nss[i] += srcobj->tx.nss[i];
266 		tgtobj->stats.rx.nss[i] += srcobj->rx.nss[i];
267 	}
268 
269 	for (i = 0; i < WME_AC_MAX; i++) {
270 		tgtobj->stats.tx.wme_ac_type[i] +=
271 			srcobj->tx.wme_ac_type[i];
272 		tgtobj->stats.rx.wme_ac_type[i] +=
273 			srcobj->rx.wme_ac_type[i];
274 		tgtobj->stats.tx.excess_retries_per_ac[i] +=
275 			srcobj->tx.excess_retries_per_ac[i];
276 	}
277 
278 	for (i = 0; i < MAX_GI; i++) {
279 		tgtobj->stats.tx.sgi_count[i] +=
280 			srcobj->tx.sgi_count[i];
281 		tgtobj->stats.rx.sgi_count[i] +=
282 			srcobj->rx.sgi_count[i];
283 	}
284 
285 	for (i = 0; i < MAX_RECEPTION_TYPES; i++)
286 		tgtobj->stats.rx.reception_type[i] +=
287 			srcobj->rx.reception_type[i];
288 
289 	tgtobj->stats.tx.comp_pkt.bytes += srcobj->tx.comp_pkt.bytes;
290 	tgtobj->stats.tx.comp_pkt.num += srcobj->tx.comp_pkt.num;
291 	tgtobj->stats.tx.ucast.num += srcobj->tx.ucast.num;
292 	tgtobj->stats.tx.ucast.bytes += srcobj->tx.ucast.bytes;
293 	tgtobj->stats.tx.mcast.num += srcobj->tx.mcast.num;
294 	tgtobj->stats.tx.mcast.bytes += srcobj->tx.mcast.bytes;
295 	tgtobj->stats.tx.bcast.num += srcobj->tx.bcast.num;
296 	tgtobj->stats.tx.bcast.bytes += srcobj->tx.bcast.bytes;
297 	tgtobj->stats.tx.tx_success.num += srcobj->tx.tx_success.num;
298 	tgtobj->stats.tx.tx_success.bytes +=
299 		srcobj->tx.tx_success.bytes;
300 	tgtobj->stats.tx.nawds_mcast.num +=
301 		srcobj->tx.nawds_mcast.num;
302 	tgtobj->stats.tx.nawds_mcast.bytes +=
303 		srcobj->tx.nawds_mcast.bytes;
304 	tgtobj->stats.tx.tx_failed += srcobj->tx.tx_failed;
305 	tgtobj->stats.tx.ofdma += srcobj->tx.ofdma;
306 	tgtobj->stats.tx.stbc += srcobj->tx.stbc;
307 	tgtobj->stats.tx.ldpc += srcobj->tx.ldpc;
308 	tgtobj->stats.tx.retries += srcobj->tx.retries;
309 	tgtobj->stats.tx.non_amsdu_cnt += srcobj->tx.non_amsdu_cnt;
310 	tgtobj->stats.tx.amsdu_cnt += srcobj->tx.amsdu_cnt;
311 	tgtobj->stats.tx.dropped.fw_rem += srcobj->tx.dropped.fw_rem;
312 	tgtobj->stats.tx.dropped.fw_rem_tx +=
313 			srcobj->tx.dropped.fw_rem_tx;
314 	tgtobj->stats.tx.dropped.fw_rem_notx +=
315 			srcobj->tx.dropped.fw_rem_notx;
316 	tgtobj->stats.tx.dropped.fw_reason1 +=
317 			srcobj->tx.dropped.fw_reason1;
318 	tgtobj->stats.tx.dropped.fw_reason2 +=
319 			srcobj->tx.dropped.fw_reason2;
320 	tgtobj->stats.tx.dropped.fw_reason3 +=
321 			srcobj->tx.dropped.fw_reason3;
322 	tgtobj->stats.tx.dropped.age_out += srcobj->tx.dropped.age_out;
323 	tgtobj->stats.rx.err.mic_err += srcobj->rx.err.mic_err;
324 	tgtobj->stats.rx.rssi = srcobj->rx.rssi;
325 	tgtobj->stats.rx.rx_rate = srcobj->rx.rx_rate;
326 	tgtobj->stats.rx.err.decrypt_err += srcobj->rx.err.decrypt_err;
327 	tgtobj->stats.rx.non_ampdu_cnt += srcobj->rx.non_ampdu_cnt;
328 	tgtobj->stats.rx.amsdu_cnt += srcobj->rx.ampdu_cnt;
329 	tgtobj->stats.rx.non_amsdu_cnt += srcobj->rx.non_amsdu_cnt;
330 	tgtobj->stats.rx.amsdu_cnt += srcobj->rx.amsdu_cnt;
331 	tgtobj->stats.rx.to_stack.num += srcobj->rx.to_stack.num;
332 	tgtobj->stats.rx.to_stack.bytes += srcobj->rx.to_stack.bytes;
333 
334 	for (i = 0; i <  CDP_MAX_RX_RINGS; i++) {
335 		tgtobj->stats.rx.rcvd_reo[i].num +=
336 			srcobj->rx.rcvd_reo[i].num;
337 		tgtobj->stats.rx.rcvd_reo[i].bytes +=
338 			srcobj->rx.rcvd_reo[i].bytes;
339 	}
340 
341 	srcobj->rx.unicast.num =
342 		srcobj->rx.to_stack.num -
343 				(srcobj->rx.multicast.num +
344 				srcobj->rx.bcast.num);
345 	srcobj->rx.unicast.bytes =
346 		srcobj->rx.to_stack.bytes -
347 				(srcobj->rx.multicast.bytes +
348 				srcobj->rx.bcast.bytes);
349 
350 	tgtobj->stats.rx.unicast.num += srcobj->rx.unicast.num;
351 	tgtobj->stats.rx.unicast.bytes += srcobj->rx.unicast.bytes;
352 	tgtobj->stats.rx.multicast.num += srcobj->rx.multicast.num;
353 	tgtobj->stats.rx.multicast.bytes += srcobj->rx.multicast.bytes;
354 	tgtobj->stats.rx.bcast.num += srcobj->rx.bcast.num;
355 	tgtobj->stats.rx.bcast.bytes += srcobj->rx.bcast.bytes;
356 	tgtobj->stats.rx.raw.num += srcobj->rx.raw.num;
357 	tgtobj->stats.rx.raw.bytes += srcobj->rx.raw.bytes;
358 	tgtobj->stats.rx.intra_bss.pkts.num +=
359 			srcobj->rx.intra_bss.pkts.num;
360 	tgtobj->stats.rx.intra_bss.pkts.bytes +=
361 			srcobj->rx.intra_bss.pkts.bytes;
362 	tgtobj->stats.rx.intra_bss.fail.num +=
363 			srcobj->rx.intra_bss.fail.num;
364 	tgtobj->stats.rx.intra_bss.fail.bytes +=
365 			srcobj->rx.intra_bss.fail.bytes;
366 
367 	tgtobj->stats.tx.last_ack_rssi =
368 		srcobj->tx.last_ack_rssi;
369 }
370 
371 static inline void dp_update_vdev_stats(struct cdp_vdev_stats *tgtobj,
372 					struct dp_peer *srcobj)
373 {
374 	uint8_t i;
375 	uint8_t pream_type;
376 
377 	for (pream_type = 0; pream_type < DOT11_MAX; pream_type++) {
378 		for (i = 0; i < MAX_MCS; i++) {
379 			tgtobj->tx.pkt_type[pream_type].
380 				mcs_count[i] +=
381 			srcobj->stats.tx.pkt_type[pream_type].
382 				mcs_count[i];
383 			tgtobj->rx.pkt_type[pream_type].
384 				mcs_count[i] +=
385 			srcobj->stats.rx.pkt_type[pream_type].
386 				mcs_count[i];
387 		}
388 	}
389 
390 	for (i = 0; i < MAX_BW; i++) {
391 		tgtobj->tx.bw[i] += srcobj->stats.tx.bw[i];
392 		tgtobj->rx.bw[i] += srcobj->stats.rx.bw[i];
393 	}
394 
395 	for (i = 0; i < SS_COUNT; i++) {
396 		tgtobj->tx.nss[i] += srcobj->stats.tx.nss[i];
397 		tgtobj->rx.nss[i] += srcobj->stats.rx.nss[i];
398 	}
399 
400 	for (i = 0; i < WME_AC_MAX; i++) {
401 		tgtobj->tx.wme_ac_type[i] +=
402 			srcobj->stats.tx.wme_ac_type[i];
403 		tgtobj->rx.wme_ac_type[i] +=
404 			srcobj->stats.rx.wme_ac_type[i];
405 		tgtobj->tx.excess_retries_per_ac[i] +=
406 			srcobj->stats.tx.excess_retries_per_ac[i];
407 	}
408 
409 	for (i = 0; i < MAX_GI; i++) {
410 		tgtobj->tx.sgi_count[i] +=
411 			srcobj->stats.tx.sgi_count[i];
412 		tgtobj->rx.sgi_count[i] +=
413 			srcobj->stats.rx.sgi_count[i];
414 	}
415 
416 	for (i = 0; i < MAX_RECEPTION_TYPES; i++)
417 		tgtobj->rx.reception_type[i] +=
418 			srcobj->stats.rx.reception_type[i];
419 
420 	tgtobj->tx.comp_pkt.bytes += srcobj->stats.tx.comp_pkt.bytes;
421 	tgtobj->tx.comp_pkt.num += srcobj->stats.tx.comp_pkt.num;
422 	tgtobj->tx.ucast.num += srcobj->stats.tx.ucast.num;
423 	tgtobj->tx.ucast.bytes += srcobj->stats.tx.ucast.bytes;
424 	tgtobj->tx.mcast.num += srcobj->stats.tx.mcast.num;
425 	tgtobj->tx.mcast.bytes += srcobj->stats.tx.mcast.bytes;
426 	tgtobj->tx.bcast.num += srcobj->stats.tx.bcast.num;
427 	tgtobj->tx.bcast.bytes += srcobj->stats.tx.bcast.bytes;
428 	tgtobj->tx.tx_success.num += srcobj->stats.tx.tx_success.num;
429 	tgtobj->tx.tx_success.bytes +=
430 		srcobj->stats.tx.tx_success.bytes;
431 	tgtobj->tx.nawds_mcast.num +=
432 		srcobj->stats.tx.nawds_mcast.num;
433 	tgtobj->tx.nawds_mcast.bytes +=
434 		srcobj->stats.tx.nawds_mcast.bytes;
435 	tgtobj->tx.tx_failed += srcobj->stats.tx.tx_failed;
436 	tgtobj->tx.ofdma += srcobj->stats.tx.ofdma;
437 	tgtobj->tx.stbc += srcobj->stats.tx.stbc;
438 	tgtobj->tx.ldpc += srcobj->stats.tx.ldpc;
439 	tgtobj->tx.retries += srcobj->stats.tx.retries;
440 	tgtobj->tx.non_amsdu_cnt += srcobj->stats.tx.non_amsdu_cnt;
441 	tgtobj->tx.amsdu_cnt += srcobj->stats.tx.amsdu_cnt;
442 	tgtobj->tx.dropped.fw_rem += srcobj->stats.tx.dropped.fw_rem;
443 	tgtobj->tx.dropped.fw_rem_tx +=
444 			srcobj->stats.tx.dropped.fw_rem_tx;
445 	tgtobj->tx.dropped.fw_rem_notx +=
446 			srcobj->stats.tx.dropped.fw_rem_notx;
447 	tgtobj->tx.dropped.fw_reason1 +=
448 			srcobj->stats.tx.dropped.fw_reason1;
449 	tgtobj->tx.dropped.fw_reason2 +=
450 			srcobj->stats.tx.dropped.fw_reason2;
451 	tgtobj->tx.dropped.fw_reason3 +=
452 			srcobj->stats.tx.dropped.fw_reason3;
453 	tgtobj->tx.dropped.age_out += srcobj->stats.tx.dropped.age_out;
454 	tgtobj->rx.err.mic_err += srcobj->stats.rx.err.mic_err;
455 	tgtobj->rx.rssi = srcobj->stats.rx.rssi;
456 	tgtobj->rx.rx_rate = srcobj->stats.rx.rx_rate;
457 	tgtobj->rx.err.decrypt_err += srcobj->stats.rx.err.decrypt_err;
458 	tgtobj->rx.non_ampdu_cnt += srcobj->stats.rx.non_ampdu_cnt;
459 	tgtobj->rx.amsdu_cnt += srcobj->stats.rx.ampdu_cnt;
460 	tgtobj->rx.non_amsdu_cnt += srcobj->stats.rx.non_amsdu_cnt;
461 	tgtobj->rx.amsdu_cnt += srcobj->stats.rx.amsdu_cnt;
462 	tgtobj->rx.to_stack.num += srcobj->stats.rx.to_stack.num;
463 	tgtobj->rx.to_stack.bytes += srcobj->stats.rx.to_stack.bytes;
464 
465 	for (i = 0; i <  CDP_MAX_RX_RINGS; i++) {
466 		tgtobj->rx.rcvd_reo[i].num +=
467 			srcobj->stats.rx.rcvd_reo[i].num;
468 		tgtobj->rx.rcvd_reo[i].bytes +=
469 			srcobj->stats.rx.rcvd_reo[i].bytes;
470 	}
471 
472 	srcobj->stats.rx.unicast.num =
473 		srcobj->stats.rx.to_stack.num -
474 				(srcobj->stats.rx.multicast.num +
475 				 srcobj->stats.rx.bcast.num);
476 	srcobj->stats.rx.unicast.bytes =
477 		srcobj->stats.rx.to_stack.bytes -
478 				(srcobj->stats.rx.multicast.bytes +
479 				 srcobj->stats.rx.bcast.bytes);
480 
481 	tgtobj->rx.unicast.num += srcobj->stats.rx.unicast.num;
482 	tgtobj->rx.unicast.bytes += srcobj->stats.rx.unicast.bytes;
483 	tgtobj->rx.multicast.num += srcobj->stats.rx.multicast.num;
484 	tgtobj->rx.multicast.bytes += srcobj->stats.rx.multicast.bytes;
485 	tgtobj->rx.bcast.num += srcobj->stats.rx.bcast.num;
486 	tgtobj->rx.bcast.bytes += srcobj->stats.rx.bcast.bytes;
487 	tgtobj->rx.raw.num += srcobj->stats.rx.raw.num;
488 	tgtobj->rx.raw.bytes += srcobj->stats.rx.raw.bytes;
489 	tgtobj->rx.intra_bss.pkts.num +=
490 			srcobj->stats.rx.intra_bss.pkts.num;
491 	tgtobj->rx.intra_bss.pkts.bytes +=
492 			srcobj->stats.rx.intra_bss.pkts.bytes;
493 	tgtobj->rx.intra_bss.fail.num +=
494 			srcobj->stats.rx.intra_bss.fail.num;
495 	tgtobj->rx.intra_bss.fail.bytes +=
496 			srcobj->stats.rx.intra_bss.fail.bytes;
497 	tgtobj->tx.last_ack_rssi =
498 		srcobj->stats.tx.last_ack_rssi;
499 }
500 
501 #define DP_UPDATE_STATS(_tgtobj, _srcobj)	\
502 	do {				\
503 		uint8_t i;		\
504 		uint8_t pream_type;	\
505 		for (pream_type = 0; pream_type < DOT11_MAX; pream_type++) { \
506 			for (i = 0; i < MAX_MCS; i++) { \
507 				DP_STATS_AGGR(_tgtobj, _srcobj, \
508 					tx.pkt_type[pream_type].mcs_count[i]); \
509 				DP_STATS_AGGR(_tgtobj, _srcobj, \
510 					rx.pkt_type[pream_type].mcs_count[i]); \
511 			} \
512 		} \
513 		  \
514 		for (i = 0; i < MAX_BW; i++) { \
515 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.bw[i]); \
516 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.bw[i]); \
517 		} \
518 		  \
519 		for (i = 0; i < SS_COUNT; i++) { \
520 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.nss[i]); \
521 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.nss[i]); \
522 		} \
523 		for (i = 0; i < WME_AC_MAX; i++) { \
524 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.wme_ac_type[i]); \
525 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.wme_ac_type[i]); \
526 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.excess_retries_per_ac[i]); \
527 		\
528 		} \
529 		\
530 		for (i = 0; i < MAX_GI; i++) { \
531 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.sgi_count[i]); \
532 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.sgi_count[i]); \
533 		} \
534 		\
535 		for (i = 0; i < MAX_RECEPTION_TYPES; i++) \
536 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.reception_type[i]); \
537 		\
538 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.comp_pkt); \
539 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.ucast); \
540 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.mcast); \
541 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.bcast); \
542 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.tx_success); \
543 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.nawds_mcast); \
544 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.nawds_mcast_drop); \
545 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.tx_failed); \
546 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.ofdma); \
547 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.stbc); \
548 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.ldpc); \
549 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.retries); \
550 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.non_amsdu_cnt); \
551 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.amsdu_cnt); \
552 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_rem); \
553 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_rem_tx); \
554 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_rem_notx); \
555 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_reason1); \
556 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_reason2); \
557 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_reason3); \
558 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.age_out); \
559 								\
560 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.err.mic_err); \
561 		DP_STATS_UPD_STRUCT(_tgtobj, _srcobj, rx.rssi); \
562 		DP_STATS_UPD_STRUCT(_tgtobj, _srcobj, rx.rx_rate); \
563 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.err.decrypt_err); \
564 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.non_ampdu_cnt); \
565 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.ampdu_cnt); \
566 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.non_amsdu_cnt); \
567 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.amsdu_cnt); \
568 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.to_stack); \
569 								\
570 		for (i = 0; i <  CDP_MAX_RX_RINGS; i++)	\
571 			DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.rcvd_reo[i]); \
572 									\
573 		_srcobj->stats.rx.unicast.num = \
574 			_srcobj->stats.rx.to_stack.num - \
575 					(_srcobj->stats.rx.multicast.num +  \
576 					_srcobj->stats.rx.bcast.num); \
577 		_srcobj->stats.rx.unicast.bytes = \
578 			_srcobj->stats.rx.to_stack.bytes - \
579 					(_srcobj->stats.rx.multicast.bytes + \
580 					_srcobj->stats.rx.bcast.bytes); \
581 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.unicast); \
582 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.multicast); \
583 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.bcast); \
584 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.raw); \
585 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.intra_bss.pkts); \
586 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.intra_bss.fail); \
587 								  \
588 		_tgtobj->stats.tx.last_ack_rssi =	\
589 			_srcobj->stats.tx.last_ack_rssi; \
590 	}  while (0)
591 
592 extern int dp_peer_find_attach(struct dp_soc *soc);
593 extern void dp_peer_find_detach(struct dp_soc *soc);
594 extern void dp_peer_find_hash_add(struct dp_soc *soc, struct dp_peer *peer);
595 extern void dp_peer_find_hash_remove(struct dp_soc *soc, struct dp_peer *peer);
596 extern void dp_peer_find_hash_erase(struct dp_soc *soc);
597 extern void dp_peer_rx_init(struct dp_pdev *pdev, struct dp_peer *peer);
598 extern void dp_peer_cleanup(struct dp_vdev *vdev, struct dp_peer *peer);
599 extern void dp_peer_rx_cleanup(struct dp_vdev *vdev, struct dp_peer *peer);
600 extern void dp_peer_unref_delete(void *peer_handle);
601 extern void dp_rx_discard(struct dp_vdev *vdev, struct dp_peer *peer,
602 	unsigned tid, qdf_nbuf_t msdu_list);
603 extern void *dp_find_peer_by_addr(struct cdp_pdev *dev,
604 	uint8_t *peer_mac_addr, uint8_t *peer_id);
605 extern struct dp_peer *dp_peer_find_hash_find(struct dp_soc *soc,
606 	uint8_t *peer_mac_addr, int mac_addr_is_aligned, uint8_t vdev_id);
607 
608 #ifndef CONFIG_WIN
609 QDF_STATUS dp_register_peer(struct cdp_pdev *pdev_handle,
610 		struct ol_txrx_desc_type *sta_desc);
611 QDF_STATUS dp_clear_peer(struct cdp_pdev *pdev_handle, uint8_t local_id);
612 void *dp_find_peer_by_addr_and_vdev(struct cdp_pdev *pdev_handle,
613 		struct cdp_vdev *vdev,
614 		uint8_t *peer_addr, uint8_t *local_id);
615 uint16_t dp_local_peer_id(void *peer);
616 void *dp_peer_find_by_local_id(struct cdp_pdev *pdev_handle, uint8_t local_id);
617 QDF_STATUS dp_peer_state_update(struct cdp_pdev *pdev_handle, uint8_t *peer_mac,
618 		enum ol_txrx_peer_state state);
619 QDF_STATUS dp_get_vdevid(void *peer_handle, uint8_t *vdev_id);
620 struct cdp_vdev *dp_get_vdev_by_sta_id(struct cdp_pdev *pdev_handle,
621 		uint8_t sta_id);
622 struct cdp_vdev *dp_get_vdev_for_peer(void *peer);
623 uint8_t *dp_peer_get_peer_mac_addr(void *peer);
624 int dp_get_peer_state(void *peer_handle);
625 void dp_local_peer_id_pool_init(struct dp_pdev *pdev);
626 void dp_local_peer_id_alloc(struct dp_pdev *pdev, struct dp_peer *peer);
627 void dp_local_peer_id_free(struct dp_pdev *pdev, struct dp_peer *peer);
628 bool dp_get_last_mgmt_timestamp(struct cdp_pdev *ppdev, u8 *peer_addr,
629 				u8 subtype, qdf_time_t *timestamp);
630 bool dp_update_last_mgmt_timestamp(struct cdp_pdev *ppdev, u8 *peer_addr,
631 				   qdf_time_t timestamp, u8 subtype);
632 #else
633 static inline void dp_local_peer_id_pool_init(struct dp_pdev *pdev)
634 {
635 }
636 
637 static inline
638 void dp_local_peer_id_alloc(struct dp_pdev *pdev, struct dp_peer *peer)
639 {
640 }
641 
642 static inline
643 void dp_local_peer_id_free(struct dp_pdev *pdev, struct dp_peer *peer)
644 {
645 }
646 #endif
647 int dp_addba_resp_tx_completion_wifi3(void *peer_handle, uint8_t tid,
648 	int status);
649 extern int dp_addba_requestprocess_wifi3(void *peer_handle,
650 	uint8_t dialogtoken, uint16_t tid, uint16_t batimeout,
651 	uint16_t buffersize, uint16_t startseqnum);
652 extern void dp_addba_responsesetup_wifi3(void *peer_handle, uint8_t tid,
653 	uint8_t *dialogtoken, uint16_t *statuscode,
654 	uint16_t *buffersize, uint16_t *batimeout);
655 extern void dp_set_addba_response(void *peer_handle, uint8_t tid,
656 	uint16_t statuscode);
657 extern int dp_delba_process_wifi3(void *peer_handle,
658 	int tid, uint16_t reasoncode);
659 
660 extern int dp_rx_tid_setup_wifi3(struct dp_peer *peer, int tid,
661 	uint32_t ba_window_size, uint32_t start_seq);
662 
663 extern QDF_STATUS dp_reo_send_cmd(struct dp_soc *soc,
664 	enum hal_reo_cmd_type type, struct hal_reo_cmd_params *params,
665 	void (*callback_fn), void *data);
666 
667 extern void dp_reo_cmdlist_destroy(struct dp_soc *soc);
668 extern void dp_reo_status_ring_handler(struct dp_soc *soc);
669 void dp_aggregate_vdev_stats(struct dp_vdev *vdev,
670 			     struct cdp_vdev_stats *vdev_stats);
671 void dp_rx_tid_stats_cb(struct dp_soc *soc, void *cb_ctxt,
672 	union hal_reo_status *reo_status);
673 void dp_rx_bar_stats_cb(struct dp_soc *soc, void *cb_ctxt,
674 		union hal_reo_status *reo_status);
675 uint16_t dp_tx_me_send_convert_ucast(struct cdp_vdev *vdev_handle,
676 		qdf_nbuf_t nbuf, uint8_t newmac[][DP_MAC_ADDR_LEN],
677 		uint8_t new_mac_cnt);
678 void dp_tx_me_alloc_descriptor(struct cdp_pdev *pdev);
679 
680 void dp_tx_me_free_descriptor(struct cdp_pdev *pdev);
681 QDF_STATUS dp_h2t_ext_stats_msg_send(struct dp_pdev *pdev,
682 		uint32_t stats_type_upload_mask, uint32_t config_param_0,
683 		uint32_t config_param_1, uint32_t config_param_2,
684 		uint32_t config_param_3, int cookie, int cookie_msb,
685 		uint8_t mac_id);
686 void dp_htt_stats_print_tag(uint8_t tag_type, uint32_t *tag_buf);
687 void dp_htt_stats_copy_tag(struct dp_pdev *pdev, uint8_t tag_type, uint32_t *tag_buf);
688 void dp_peer_rxtid_stats(struct dp_peer *peer, void (*callback_fn),
689 		void *cb_ctxt);
690 void dp_set_pn_check_wifi3(struct cdp_vdev *vdev_handle,
691 	struct cdp_peer *peer_handle, enum cdp_sec_type sec_type,
692 	 uint32_t *rx_pn);
693 
694 void *dp_get_pdev_for_mac_id(struct dp_soc *soc, uint32_t mac_id);
695 void dp_mark_peer_inact(void *peer_handle, bool inactive);
696 bool dp_set_inact_params(struct cdp_pdev *pdev_handle,
697 		 u_int16_t inact_check_interval,
698 		 u_int16_t inact_normal, u_int16_t inact_overload);
699 bool dp_start_inact_timer(struct cdp_pdev *pdev_handle, bool enable);
700 void dp_set_overload(struct cdp_pdev *pdev_handle, bool overload);
701 bool dp_peer_is_inact(void *peer_handle);
702 void dp_init_inact_timer(struct dp_soc *soc);
703 void dp_free_inact_timer(struct dp_soc *soc);
704 void dp_set_michael_key(struct cdp_peer *peer_handle,
705 			bool is_unicast, uint32_t *key);
706 
707 /*
708  * dp_get_mac_id_for_pdev() -  Return mac corresponding to pdev for mac
709  *
710  * @mac_id: MAC id
711  * @pdev_id: pdev_id corresponding to pdev, 0 for MCL
712  *
713  * Single pdev using both MACs will operate on both MAC rings,
714  * which is the case for MCL.
715  * For WIN each PDEV will operate one ring, so index is zero.
716  *
717  */
718 static inline int dp_get_mac_id_for_pdev(uint32_t mac_id, uint32_t pdev_id)
719 {
720 	if (mac_id && pdev_id) {
721 		qdf_print("Both mac_id and pdev_id cannot be non zero");
722 		QDF_BUG(0);
723 		return 0;
724 	}
725 	return (mac_id + pdev_id);
726 }
727 
728 /*
729  * dp_get_mac_id_for_mac() -  Return mac corresponding WIN and MCL mac_ids
730  *
731  * @soc: handle to DP soc
732  * @mac_id: MAC id
733  *
734  * Single pdev using both MACs will operate on both MAC rings,
735  * which is the case for MCL.
736  * For WIN each PDEV will operate one ring, so index is zero.
737  *
738  */
739 static inline int dp_get_mac_id_for_mac(struct dp_soc *soc, uint32_t mac_id)
740 {
741 	/*
742 	 * Single pdev using both MACs will operate on both MAC rings,
743 	 * which is the case for MCL.
744 	 */
745 	if (!wlan_cfg_per_pdev_lmac_ring(soc->wlan_cfg_ctx))
746 		return mac_id;
747 
748 	/* For WIN each PDEV will operate one ring, so index is zero. */
749 	return 0;
750 }
751 
752 #ifdef WDI_EVENT_ENABLE
753 QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
754 				uint32_t stats_type_upload_mask,
755 				uint8_t mac_id);
756 
757 int dp_wdi_event_unsub(struct cdp_pdev *txrx_pdev_handle,
758 	void *event_cb_sub_handle,
759 	uint32_t event);
760 
761 int dp_wdi_event_sub(struct cdp_pdev *txrx_pdev_handle,
762 	void *event_cb_sub_handle,
763 	uint32_t event);
764 
765 void dp_wdi_event_handler(enum WDI_EVENT event, void *soc,
766 		void *data, u_int16_t peer_id,
767 		int status, u_int8_t pdev_id);
768 
769 int dp_wdi_event_attach(struct dp_pdev *txrx_pdev);
770 int dp_wdi_event_detach(struct dp_pdev *txrx_pdev);
771 int dp_set_pktlog_wifi3(struct dp_pdev *pdev, uint32_t event,
772 	bool enable);
773 void *dp_get_pldev(struct cdp_pdev *txrx_pdev);
774 void dp_pkt_log_init(struct cdp_pdev *ppdev, void *scn);
775 
776 static inline void dp_hif_update_pipe_callback(void *soc, void *cb_context,
777 	QDF_STATUS (*callback)(void *, qdf_nbuf_t, uint8_t), uint8_t pipe_id)
778 {
779 	struct hif_msg_callbacks hif_pipe_callbacks;
780 	struct dp_soc *dp_soc = (struct dp_soc *)soc;
781 
782 	/* TODO: Temporary change to bypass HTC connection for this new
783 	 * HIF pipe, which will be used for packet log and other high-
784 	 * priority HTT messages. Proper HTC connection to be added
785 	 * later once required FW changes are available
786 	 */
787 	hif_pipe_callbacks.rxCompletionHandler = callback;
788 	hif_pipe_callbacks.Context = cb_context;
789 	hif_update_pipe_callback(dp_soc->hif_handle,
790 		DP_HTT_T2H_HP_PIPE, &hif_pipe_callbacks);
791 }
792 
793 QDF_STATUS dp_peer_stats_notify(struct dp_peer *peer);
794 
795 #else
796 static inline int dp_wdi_event_unsub(struct cdp_pdev *txrx_pdev_handle,
797 	void *event_cb_sub_handle,
798 	uint32_t event)
799 {
800 	return 0;
801 }
802 
803 static inline int dp_wdi_event_sub(struct cdp_pdev *txrx_pdev_handle,
804 	void *event_cb_sub_handle,
805 	uint32_t event)
806 {
807 	return 0;
808 }
809 
810 static inline void dp_wdi_event_handler(enum WDI_EVENT event, void *soc,
811 		void *data, u_int16_t peer_id,
812 		int status, u_int8_t pdev_id)
813 {
814 }
815 
816 static inline int dp_wdi_event_attach(struct dp_pdev *txrx_pdev)
817 {
818 	return 0;
819 }
820 
821 static inline int dp_wdi_event_detach(struct dp_pdev *txrx_pdev)
822 {
823 	return 0;
824 }
825 
826 static inline int dp_set_pktlog_wifi3(struct dp_pdev *pdev, uint32_t event,
827 	bool enable)
828 {
829 	return 0;
830 }
831 static inline QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
832 		uint32_t stats_type_upload_mask, uint8_t mac_id)
833 {
834 	return 0;
835 }
836 static inline void dp_hif_update_pipe_callback(void *soc, void *cb_context,
837 	QDF_STATUS (*callback)(void *, qdf_nbuf_t, uint8_t), uint8_t pipe_id)
838 {
839 }
840 
841 static inline QDF_STATUS dp_peer_stats_notify(struct dp_peer *peer)
842 {
843 	return QDF_STATUS_SUCCESS;
844 }
845 
846 #endif /* CONFIG_WIN */
847 #ifdef QCA_LL_TX_FLOW_CONTROL_V2
848 void dp_tx_dump_flow_pool_info(void *soc);
849 int dp_tx_delete_flow_pool(struct dp_soc *soc, struct dp_tx_desc_pool_s *pool,
850 	bool force);
851 #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
852 #endif /* #ifndef _DP_INTERNAL_H_ */
853