xref: /wlan-dirver/qca-wifi-host-cmn/dp/wifi3.0/dp_internal.h (revision 0626a4da6c07f30da06dd6747e8cc290a60371d8)
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.unicast.bytes =
476 		srcobj->stats.rx.to_stack.bytes -
477 				srcobj->stats.rx.multicast.bytes;
478 
479 	tgtobj->rx.unicast.num += srcobj->stats.rx.unicast.num;
480 	tgtobj->rx.unicast.bytes += srcobj->stats.rx.unicast.bytes;
481 	tgtobj->rx.multicast.num += srcobj->stats.rx.multicast.num;
482 	tgtobj->rx.multicast.bytes += srcobj->stats.rx.multicast.bytes;
483 	tgtobj->rx.bcast.num += srcobj->stats.rx.bcast.num;
484 	tgtobj->rx.bcast.bytes += srcobj->stats.rx.bcast.bytes;
485 	tgtobj->rx.raw.num += srcobj->stats.rx.raw.num;
486 	tgtobj->rx.raw.bytes += srcobj->stats.rx.raw.bytes;
487 	tgtobj->rx.intra_bss.pkts.num +=
488 			srcobj->stats.rx.intra_bss.pkts.num;
489 	tgtobj->rx.intra_bss.pkts.bytes +=
490 			srcobj->stats.rx.intra_bss.pkts.bytes;
491 	tgtobj->rx.intra_bss.fail.num +=
492 			srcobj->stats.rx.intra_bss.fail.num;
493 	tgtobj->rx.intra_bss.fail.bytes +=
494 			srcobj->stats.rx.intra_bss.fail.bytes;
495 	tgtobj->tx.last_ack_rssi =
496 		srcobj->stats.tx.last_ack_rssi;
497 }
498 
499 #define DP_UPDATE_STATS(_tgtobj, _srcobj)	\
500 	do {				\
501 		uint8_t i;		\
502 		uint8_t pream_type;	\
503 		for (pream_type = 0; pream_type < DOT11_MAX; pream_type++) { \
504 			for (i = 0; i < MAX_MCS; i++) { \
505 				DP_STATS_AGGR(_tgtobj, _srcobj, \
506 					tx.pkt_type[pream_type].mcs_count[i]); \
507 				DP_STATS_AGGR(_tgtobj, _srcobj, \
508 					rx.pkt_type[pream_type].mcs_count[i]); \
509 			} \
510 		} \
511 		  \
512 		for (i = 0; i < MAX_BW; i++) { \
513 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.bw[i]); \
514 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.bw[i]); \
515 		} \
516 		  \
517 		for (i = 0; i < SS_COUNT; i++) { \
518 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.nss[i]); \
519 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.nss[i]); \
520 		} \
521 		for (i = 0; i < WME_AC_MAX; i++) { \
522 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.wme_ac_type[i]); \
523 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.wme_ac_type[i]); \
524 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.excess_retries_per_ac[i]); \
525 		\
526 		} \
527 		\
528 		for (i = 0; i < MAX_GI; i++) { \
529 			DP_STATS_AGGR(_tgtobj, _srcobj, tx.sgi_count[i]); \
530 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.sgi_count[i]); \
531 		} \
532 		\
533 		for (i = 0; i < MAX_RECEPTION_TYPES; i++) \
534 			DP_STATS_AGGR(_tgtobj, _srcobj, rx.reception_type[i]); \
535 		\
536 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.comp_pkt); \
537 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.ucast); \
538 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.mcast); \
539 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.bcast); \
540 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.tx_success); \
541 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, tx.nawds_mcast); \
542 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.nawds_mcast_drop); \
543 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.tx_failed); \
544 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.ofdma); \
545 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.stbc); \
546 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.ldpc); \
547 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.retries); \
548 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.non_amsdu_cnt); \
549 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.amsdu_cnt); \
550 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_rem); \
551 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_rem_tx); \
552 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_rem_notx); \
553 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_reason1); \
554 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_reason2); \
555 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.fw_reason3); \
556 		DP_STATS_AGGR(_tgtobj, _srcobj, tx.dropped.age_out); \
557 								\
558 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.err.mic_err); \
559 		DP_STATS_UPD_STRUCT(_tgtobj, _srcobj, rx.rssi); \
560 		DP_STATS_UPD_STRUCT(_tgtobj, _srcobj, rx.rx_rate); \
561 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.err.decrypt_err); \
562 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.non_ampdu_cnt); \
563 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.ampdu_cnt); \
564 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.non_amsdu_cnt); \
565 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.amsdu_cnt); \
566 		DP_STATS_AGGR(_tgtobj, _srcobj, rx.nawds_mcast_drop); \
567 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.to_stack); \
568 								\
569 		for (i = 0; i <  CDP_MAX_RX_RINGS; i++)	\
570 			DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.rcvd_reo[i]); \
571 									\
572 		_srcobj->stats.rx.unicast.num = \
573 			_srcobj->stats.rx.to_stack.num - \
574 					_srcobj->stats.rx.multicast.num; \
575 		_srcobj->stats.rx.unicast.bytes = \
576 			_srcobj->stats.rx.to_stack.bytes - \
577 					_srcobj->stats.rx.multicast.bytes; \
578 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.unicast); \
579 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.multicast); \
580 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.bcast); \
581 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.raw); \
582 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.intra_bss.pkts); \
583 		DP_STATS_AGGR_PKT(_tgtobj, _srcobj, rx.intra_bss.fail); \
584 								  \
585 		_tgtobj->stats.tx.last_ack_rssi =	\
586 			_srcobj->stats.tx.last_ack_rssi; \
587 	}  while (0)
588 
589 extern int dp_peer_find_attach(struct dp_soc *soc);
590 extern void dp_peer_find_detach(struct dp_soc *soc);
591 extern void dp_peer_find_hash_add(struct dp_soc *soc, struct dp_peer *peer);
592 extern void dp_peer_find_hash_remove(struct dp_soc *soc, struct dp_peer *peer);
593 extern void dp_peer_find_hash_erase(struct dp_soc *soc);
594 extern void dp_peer_rx_init(struct dp_pdev *pdev, struct dp_peer *peer);
595 extern void dp_peer_cleanup(struct dp_vdev *vdev, struct dp_peer *peer);
596 extern void dp_peer_rx_cleanup(struct dp_vdev *vdev, struct dp_peer *peer);
597 extern void dp_peer_unref_delete(void *peer_handle);
598 extern void dp_rx_discard(struct dp_vdev *vdev, struct dp_peer *peer,
599 	unsigned tid, qdf_nbuf_t msdu_list);
600 extern void *dp_find_peer_by_addr(struct cdp_pdev *dev,
601 	uint8_t *peer_mac_addr, uint8_t *peer_id);
602 extern struct dp_peer *dp_peer_find_hash_find(struct dp_soc *soc,
603 	uint8_t *peer_mac_addr, int mac_addr_is_aligned, uint8_t vdev_id);
604 
605 #ifndef CONFIG_WIN
606 QDF_STATUS dp_register_peer(struct cdp_pdev *pdev_handle,
607 		struct ol_txrx_desc_type *sta_desc);
608 QDF_STATUS dp_clear_peer(struct cdp_pdev *pdev_handle, uint8_t local_id);
609 void *dp_find_peer_by_addr_and_vdev(struct cdp_pdev *pdev_handle,
610 		struct cdp_vdev *vdev,
611 		uint8_t *peer_addr, uint8_t *local_id);
612 uint16_t dp_local_peer_id(void *peer);
613 void *dp_peer_find_by_local_id(struct cdp_pdev *pdev_handle, uint8_t local_id);
614 QDF_STATUS dp_peer_state_update(struct cdp_pdev *pdev_handle, uint8_t *peer_mac,
615 		enum ol_txrx_peer_state state);
616 QDF_STATUS dp_get_vdevid(void *peer_handle, uint8_t *vdev_id);
617 struct cdp_vdev *dp_get_vdev_by_sta_id(struct cdp_pdev *pdev_handle,
618 		uint8_t sta_id);
619 struct cdp_vdev *dp_get_vdev_for_peer(void *peer);
620 uint8_t *dp_peer_get_peer_mac_addr(void *peer);
621 int dp_get_peer_state(void *peer_handle);
622 void dp_local_peer_id_pool_init(struct dp_pdev *pdev);
623 void dp_local_peer_id_alloc(struct dp_pdev *pdev, struct dp_peer *peer);
624 void dp_local_peer_id_free(struct dp_pdev *pdev, struct dp_peer *peer);
625 #else
626 static inline void dp_local_peer_id_pool_init(struct dp_pdev *pdev)
627 {
628 }
629 
630 static inline
631 void dp_local_peer_id_alloc(struct dp_pdev *pdev, struct dp_peer *peer)
632 {
633 }
634 
635 static inline
636 void dp_local_peer_id_free(struct dp_pdev *pdev, struct dp_peer *peer)
637 {
638 }
639 #endif
640 int dp_addba_resp_tx_completion_wifi3(void *peer_handle, uint8_t tid,
641 	int status);
642 extern int dp_addba_requestprocess_wifi3(void *peer_handle,
643 	uint8_t dialogtoken, uint16_t tid, uint16_t batimeout,
644 	uint16_t buffersize, uint16_t startseqnum);
645 extern void dp_addba_responsesetup_wifi3(void *peer_handle, uint8_t tid,
646 	uint8_t *dialogtoken, uint16_t *statuscode,
647 	uint16_t *buffersize, uint16_t *batimeout);
648 extern void dp_set_addba_response(void *peer_handle, uint8_t tid,
649 	uint16_t statuscode);
650 extern int dp_delba_process_wifi3(void *peer_handle,
651 	int tid, uint16_t reasoncode);
652 /*
653  * dp_delba_tx_completion_wifi3() -  Handle delba tx completion
654  *
655  * @peer_handle: Peer handle
656  * @tid: Tid number
657  * @status: Tx completion status
658  * Indicate status of delba Tx to DP for stats update and retry
659  * delba if tx failed.
660  *
661  */
662 int dp_delba_tx_completion_wifi3(void *peer_handle, uint8_t tid,
663 				  int status);
664 extern int dp_rx_tid_setup_wifi3(struct dp_peer *peer, int tid,
665 	uint32_t ba_window_size, uint32_t start_seq);
666 
667 extern QDF_STATUS dp_reo_send_cmd(struct dp_soc *soc,
668 	enum hal_reo_cmd_type type, struct hal_reo_cmd_params *params,
669 	void (*callback_fn), void *data);
670 
671 extern void dp_reo_cmdlist_destroy(struct dp_soc *soc);
672 extern void dp_reo_status_ring_handler(struct dp_soc *soc);
673 void dp_aggregate_vdev_stats(struct dp_vdev *vdev,
674 			     struct cdp_vdev_stats *vdev_stats);
675 void dp_rx_tid_stats_cb(struct dp_soc *soc, void *cb_ctxt,
676 	union hal_reo_status *reo_status);
677 void dp_rx_bar_stats_cb(struct dp_soc *soc, void *cb_ctxt,
678 		union hal_reo_status *reo_status);
679 uint16_t dp_tx_me_send_convert_ucast(struct cdp_vdev *vdev_handle,
680 		qdf_nbuf_t nbuf, uint8_t newmac[][DP_MAC_ADDR_LEN],
681 		uint8_t new_mac_cnt);
682 void dp_tx_me_alloc_descriptor(struct cdp_pdev *pdev);
683 
684 void dp_tx_me_free_descriptor(struct cdp_pdev *pdev);
685 QDF_STATUS dp_h2t_ext_stats_msg_send(struct dp_pdev *pdev,
686 		uint32_t stats_type_upload_mask, uint32_t config_param_0,
687 		uint32_t config_param_1, uint32_t config_param_2,
688 		uint32_t config_param_3, int cookie, int cookie_msb,
689 		uint8_t mac_id);
690 void dp_htt_stats_print_tag(uint8_t tag_type, uint32_t *tag_buf);
691 void dp_htt_stats_copy_tag(struct dp_pdev *pdev, uint8_t tag_type, uint32_t *tag_buf);
692 void dp_peer_rxtid_stats(struct dp_peer *peer, void (*callback_fn),
693 		void *cb_ctxt);
694 void dp_set_pn_check_wifi3(struct cdp_vdev *vdev_handle,
695 	struct cdp_peer *peer_handle, enum cdp_sec_type sec_type,
696 	 uint32_t *rx_pn);
697 
698 void *dp_get_pdev_for_mac_id(struct dp_soc *soc, uint32_t mac_id);
699 void dp_mark_peer_inact(void *peer_handle, bool inactive);
700 bool dp_set_inact_params(struct cdp_pdev *pdev_handle,
701 		 u_int16_t inact_check_interval,
702 		 u_int16_t inact_normal, u_int16_t inact_overload);
703 bool dp_start_inact_timer(struct cdp_pdev *pdev_handle, bool enable);
704 void dp_set_overload(struct cdp_pdev *pdev_handle, bool overload);
705 bool dp_peer_is_inact(void *peer_handle);
706 void dp_init_inact_timer(struct dp_soc *soc);
707 void dp_free_inact_timer(struct dp_soc *soc);
708 void dp_set_michael_key(struct cdp_peer *peer_handle,
709 			bool is_unicast, uint32_t *key);
710 
711 /*
712  * dp_get_mac_id_for_pdev() -  Return mac corresponding to pdev for mac
713  *
714  * @mac_id: MAC id
715  * @pdev_id: pdev_id corresponding to pdev, 0 for MCL
716  *
717  * Single pdev using both MACs will operate on both MAC rings,
718  * which is the case for MCL.
719  * For WIN each PDEV will operate one ring, so index is zero.
720  *
721  */
722 static inline int dp_get_mac_id_for_pdev(uint32_t mac_id, uint32_t pdev_id)
723 {
724 	if (mac_id && pdev_id) {
725 		qdf_print("Both mac_id and pdev_id cannot be non zero");
726 		QDF_BUG(0);
727 		return 0;
728 	}
729 	return (mac_id + pdev_id);
730 }
731 
732 /*
733  * dp_get_mac_id_for_mac() -  Return mac corresponding WIN and MCL mac_ids
734  *
735  * @soc: handle to DP soc
736  * @mac_id: MAC id
737  *
738  * Single pdev using both MACs will operate on both MAC rings,
739  * which is the case for MCL.
740  * For WIN each PDEV will operate one ring, so index is zero.
741  *
742  */
743 static inline int dp_get_mac_id_for_mac(struct dp_soc *soc, uint32_t mac_id)
744 {
745 	/*
746 	 * Single pdev using both MACs will operate on both MAC rings,
747 	 * which is the case for MCL.
748 	 */
749 	if (!wlan_cfg_per_pdev_lmac_ring(soc->wlan_cfg_ctx))
750 		return mac_id;
751 
752 	/* For WIN each PDEV will operate one ring, so index is zero. */
753 	return 0;
754 }
755 
756 #ifdef WDI_EVENT_ENABLE
757 QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
758 				uint32_t stats_type_upload_mask,
759 				uint8_t mac_id);
760 
761 int dp_wdi_event_unsub(struct cdp_pdev *txrx_pdev_handle,
762 	void *event_cb_sub_handle,
763 	uint32_t event);
764 
765 int dp_wdi_event_sub(struct cdp_pdev *txrx_pdev_handle,
766 	void *event_cb_sub_handle,
767 	uint32_t event);
768 
769 void dp_wdi_event_handler(enum WDI_EVENT event, void *soc,
770 		void *data, u_int16_t peer_id,
771 		int status, u_int8_t pdev_id);
772 
773 int dp_wdi_event_attach(struct dp_pdev *txrx_pdev);
774 int dp_wdi_event_detach(struct dp_pdev *txrx_pdev);
775 int dp_set_pktlog_wifi3(struct dp_pdev *pdev, uint32_t event,
776 	bool enable);
777 void *dp_get_pldev(struct cdp_pdev *txrx_pdev);
778 void dp_pkt_log_init(struct cdp_pdev *ppdev, void *scn);
779 
780 static inline void dp_hif_update_pipe_callback(void *soc, void *cb_context,
781 	QDF_STATUS (*callback)(void *, qdf_nbuf_t, uint8_t), uint8_t pipe_id)
782 {
783 	struct hif_msg_callbacks hif_pipe_callbacks;
784 	struct dp_soc *dp_soc = (struct dp_soc *)soc;
785 
786 	/* TODO: Temporary change to bypass HTC connection for this new
787 	 * HIF pipe, which will be used for packet log and other high-
788 	 * priority HTT messages. Proper HTC connection to be added
789 	 * later once required FW changes are available
790 	 */
791 	hif_pipe_callbacks.rxCompletionHandler = callback;
792 	hif_pipe_callbacks.Context = cb_context;
793 	hif_update_pipe_callback(dp_soc->hif_handle,
794 		DP_HTT_T2H_HP_PIPE, &hif_pipe_callbacks);
795 }
796 
797 QDF_STATUS dp_peer_stats_notify(struct dp_peer *peer);
798 
799 #else
800 static inline int dp_wdi_event_unsub(struct cdp_pdev *txrx_pdev_handle,
801 	void *event_cb_sub_handle,
802 	uint32_t event)
803 {
804 	return 0;
805 }
806 
807 static inline int dp_wdi_event_sub(struct cdp_pdev *txrx_pdev_handle,
808 	void *event_cb_sub_handle,
809 	uint32_t event)
810 {
811 	return 0;
812 }
813 
814 static inline void dp_wdi_event_handler(enum WDI_EVENT event, void *soc,
815 		void *data, u_int16_t peer_id,
816 		int status, u_int8_t pdev_id)
817 {
818 }
819 
820 static inline int dp_wdi_event_attach(struct dp_pdev *txrx_pdev)
821 {
822 	return 0;
823 }
824 
825 static inline int dp_wdi_event_detach(struct dp_pdev *txrx_pdev)
826 {
827 	return 0;
828 }
829 
830 static inline int dp_set_pktlog_wifi3(struct dp_pdev *pdev, uint32_t event,
831 	bool enable)
832 {
833 	return 0;
834 }
835 static inline QDF_STATUS dp_h2t_cfg_stats_msg_send(struct dp_pdev *pdev,
836 		uint32_t stats_type_upload_mask, uint8_t mac_id)
837 {
838 	return 0;
839 }
840 static inline void dp_hif_update_pipe_callback(void *soc, void *cb_context,
841 	QDF_STATUS (*callback)(void *, qdf_nbuf_t, uint8_t), uint8_t pipe_id)
842 {
843 }
844 
845 static inline QDF_STATUS dp_peer_stats_notify(struct dp_peer *peer)
846 {
847 	return QDF_STATUS_SUCCESS;
848 }
849 
850 #endif /* CONFIG_WIN */
851 #ifdef QCA_LL_TX_FLOW_CONTROL_V2
852 void dp_tx_dump_flow_pool_info(void *soc);
853 int dp_tx_delete_flow_pool(struct dp_soc *soc, struct dp_tx_desc_pool_s *pool,
854 	bool force);
855 #endif /* QCA_LL_TX_FLOW_CONTROL_V2 */
856 
857 #ifdef PEER_PROTECTED_ACCESS
858 /**
859  * dp_peer_unref_del_find_by_id() - dec ref and del peer if ref count is
860  *                                  taken by dp_peer_find_by_id
861  * @peer: peer context
862  *
863  * Return: none
864  */
865 static inline void dp_peer_unref_del_find_by_id(struct dp_peer *peer)
866 {
867 	dp_peer_unref_delete(peer);
868 }
869 #else
870 static inline void dp_peer_unref_del_find_by_id(struct dp_peer *peer)
871 {
872 }
873 #endif
874 
875 #endif /* #ifndef _DP_INTERNAL_H_ */
876