xref: /wlan-driver/qca-wifi-host-cmn/utils/epping/src/epping_helper.c (revision 5113495b16420b49004c444715d2daae2066e7dc)
1 /*
2  * Copyright (c) 2014-2019 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 /*========================================================================
20 
21    \file  epping_main.c
22 
23    \brief WLAN End Point Ping test tool implementation
24 
25    ========================================================================*/
26 
27 /*--------------------------------------------------------------------------
28    Include Files
29    ------------------------------------------------------------------------*/
30 #include <cds_api.h>
31 #include <cds_sched.h>
32 #include <linux/etherdevice.h>
33 #include <linux/firmware.h>
34 #include <linux/delay.h>
35 #include <wni_api.h>
36 #include <wlan_ptt_sock_svc.h>
37 #include <linux/wireless.h>
38 #include <net/cfg80211.h>
39 #include <linux/rtnetlink.h>
40 #include <linux/semaphore.h>
41 #include <linux/delay.h>
42 #include <linux/ctype.h>
43 #include "epping_main.h"
44 #include "epping_internal.h"
45 
epping_cookie_init(epping_context_t * pEpping_ctx)46 int epping_cookie_init(epping_context_t *pEpping_ctx)
47 {
48 	uint32_t i, j;
49 
50 	pEpping_ctx->cookie_list = NULL;
51 	pEpping_ctx->cookie_count = 0;
52 	for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
53 		pEpping_ctx->s_cookie_mem[i] =
54 			qdf_mem_malloc(sizeof(struct epping_cookie) *
55 				       MAX_COOKIE_SLOT_SIZE);
56 		if (!pEpping_ctx->s_cookie_mem[i])
57 			goto error;
58 	}
59 	qdf_spinlock_create(&pEpping_ctx->cookie_lock);
60 
61 	for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
62 		struct epping_cookie *cookie_mem = pEpping_ctx->s_cookie_mem[i];
63 		for (j = 0; j < MAX_COOKIE_SLOT_SIZE; j++) {
64 			epping_free_cookie(pEpping_ctx, &cookie_mem[j]);
65 		}
66 	}
67 	return 0;
68 error:
69 	for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
70 		if (pEpping_ctx->s_cookie_mem[i]) {
71 			qdf_mem_free(pEpping_ctx->s_cookie_mem[i]);
72 			pEpping_ctx->s_cookie_mem[i] = NULL;
73 		}
74 	}
75 	return -ENOMEM;
76 }
77 
78 /* cleanup cookie queue */
epping_cookie_cleanup(epping_context_t * pEpping_ctx)79 void epping_cookie_cleanup(epping_context_t *pEpping_ctx)
80 {
81 	int i;
82 	qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
83 	pEpping_ctx->cookie_list = NULL;
84 	pEpping_ctx->cookie_count = 0;
85 	qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
86 	for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) {
87 		if (pEpping_ctx->s_cookie_mem[i]) {
88 			qdf_mem_free(pEpping_ctx->s_cookie_mem[i]);
89 			pEpping_ctx->s_cookie_mem[i] = NULL;
90 		}
91 	}
92 }
93 
epping_free_cookie(epping_context_t * pEpping_ctx,struct epping_cookie * cookie)94 void epping_free_cookie(epping_context_t *pEpping_ctx,
95 			struct epping_cookie *cookie)
96 {
97 	qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
98 	cookie->next = pEpping_ctx->cookie_list;
99 	pEpping_ctx->cookie_list = cookie;
100 	pEpping_ctx->cookie_count++;
101 	qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
102 }
103 
epping_alloc_cookie(epping_context_t * pEpping_ctx)104 struct epping_cookie *epping_alloc_cookie(epping_context_t *pEpping_ctx)
105 {
106 	struct epping_cookie *cookie;
107 
108 	qdf_spin_lock_bh(&pEpping_ctx->cookie_lock);
109 	cookie = pEpping_ctx->cookie_list;
110 	if (cookie) {
111 		pEpping_ctx->cookie_list = cookie->next;
112 		pEpping_ctx->cookie_count--;
113 	}
114 	qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock);
115 	return cookie;
116 }
117 
epping_get_dummy_mac_addr(tSirMacAddr macAddr)118 void epping_get_dummy_mac_addr(tSirMacAddr macAddr)
119 {
120 	macAddr[0] = 69;        /* E */
121 	macAddr[1] = 80;        /* P */
122 	macAddr[2] = 80;        /* P */
123 	macAddr[3] = 73;        /* I */
124 	macAddr[4] = 78;        /* N */
125 	macAddr[5] = 71;        /* G */
126 }
127 
epping_hex_dump(void * data,int buf_len,const char * str)128 void epping_hex_dump(void *data, int buf_len, const char *str)
129 {
130 	EPPING_LOG(QDF_TRACE_LEVEL_FATAL, "%s: E, %s", __func__, str);
131 
132 	EPPING_HEX_DUMP(QDF_TRACE_LEVEL_INFO, data, buf_len);
133 
134 	EPPING_LOG(QDF_TRACE_LEVEL_FATAL, "%s: X %s", __func__, str);
135 }
136 
epping_get_qdf_ctx(void)137 void *epping_get_qdf_ctx(void)
138 {
139 	qdf_device_t *qdf_ctx;
140 
141 	qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE);
142 	return qdf_ctx;
143 }
144 
epping_log_packet(epping_adapter_t * adapter,EPPING_HEADER * eppingHdr,int ret,const char * str)145 void epping_log_packet(epping_adapter_t *adapter,
146 		       EPPING_HEADER *eppingHdr, int ret, const char *str)
147 {
148 	if (eppingHdr->Cmd_h & EPPING_LOG_MASK) {
149 		EPPING_LOG(QDF_TRACE_LEVEL_FATAL,
150 			   "%s: cmd = %d, seqNo = %u, flag = 0x%x, ret = %d, "
151 			   "txCount = %lu, txDrop =  %lu, txBytes = %lu,"
152 			   "rxCount = %lu, rxDrop = %lu, rxBytes = %lu\n",
153 			   str, eppingHdr->Cmd_h, eppingHdr->SeqNo,
154 			   eppingHdr->CmdFlags_h, ret,
155 			   adapter->stats.tx_packets,
156 			   adapter->stats.tx_dropped,
157 			   adapter->stats.tx_bytes,
158 			   adapter->stats.rx_packets,
159 			   adapter->stats.rx_dropped,
160 			   adapter->stats.rx_bytes);
161 	}
162 }
163 
epping_log_stats(epping_adapter_t * adapter,const char * str)164 void epping_log_stats(epping_adapter_t *adapter, const char *str)
165 {
166 	EPPING_LOG(QDF_TRACE_LEVEL_FATAL,
167 		   "%s: txCount = %lu, txDrop = %lu, tx_bytes = %lu, "
168 		   "rxCount = %lu, rxDrop = %lu, rx_bytes = %lu, tx_acks = %u\n",
169 		   str,
170 		   adapter->stats.tx_packets,
171 		   adapter->stats.tx_dropped,
172 		   adapter->stats.tx_bytes,
173 		   adapter->stats.rx_packets,
174 		   adapter->stats.rx_dropped,
175 		   adapter->stats.rx_bytes,
176 		   adapter->pEpping_ctx->total_tx_acks);
177 }
178 
epping_set_kperf_flag(epping_adapter_t * adapter,HTC_ENDPOINT_ID eid,uint8_t kperf_flag)179 void epping_set_kperf_flag(epping_adapter_t *adapter,
180 			   HTC_ENDPOINT_ID eid, uint8_t kperf_flag)
181 {
182 	adapter->pEpping_ctx->kperf_num_rx_recv[eid] = 0;
183 	adapter->pEpping_ctx->kperf_num_tx_acks[eid] = 0;
184 }
185