Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Anurag Chouhan | 6d76066 | 2016-02-20 16:05:43 +0530 | [diff] [blame] | 2 | * Copyright (c) 2014-2016 The Linux Foundation. All rights reserved. |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 3 | * |
| 4 | * Previously licensed under the ISC license by Qualcomm Atheros, Inc. |
| 5 | * |
| 6 | * |
| 7 | * Permission to use, copy, modify, and/or distribute this software for |
| 8 | * any purpose with or without fee is hereby granted, provided that the |
| 9 | * above copyright notice and this permission notice appear in all |
| 10 | * copies. |
| 11 | * |
| 12 | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL |
| 13 | * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED |
| 14 | * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE |
| 15 | * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL |
| 16 | * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR |
| 17 | * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER |
| 18 | * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR |
| 19 | * PERFORMANCE OF THIS SOFTWARE. |
| 20 | */ |
| 21 | |
| 22 | /* |
| 23 | * This file was originally distributed by Qualcomm Atheros, Inc. |
| 24 | * under proprietary terms before Copyright ownership was assigned |
| 25 | * to the Linux Foundation. |
| 26 | */ |
| 27 | |
| 28 | /*======================================================================== |
| 29 | |
| 30 | \file epping_main.c |
| 31 | |
| 32 | \brief WLAN End Point Ping test tool implementation |
| 33 | |
| 34 | ========================================================================*/ |
| 35 | |
| 36 | /*-------------------------------------------------------------------------- |
| 37 | Include Files |
| 38 | ------------------------------------------------------------------------*/ |
| 39 | #include <cds_api.h> |
| 40 | #include <cds_sched.h> |
| 41 | #include <linux/etherdevice.h> |
| 42 | #include <linux/firmware.h> |
| 43 | #include <linux/delay.h> |
| 44 | #include <wni_api.h> |
| 45 | #include <wlan_ptt_sock_svc.h> |
| 46 | #include <linux/wireless.h> |
| 47 | #include <net/cfg80211.h> |
| 48 | #include <linux/rtnetlink.h> |
| 49 | #include <linux/semaphore.h> |
| 50 | #include <linux/delay.h> |
| 51 | #include <linux/ctype.h> |
| 52 | #include "epping_main.h" |
| 53 | #include "epping_internal.h" |
| 54 | |
| 55 | int epping_cookie_init(epping_context_t *pEpping_ctx) |
| 56 | { |
| 57 | A_UINT32 i, j; |
| 58 | |
| 59 | pEpping_ctx->cookie_list = NULL; |
| 60 | pEpping_ctx->cookie_count = 0; |
| 61 | for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) { |
| 62 | pEpping_ctx->s_cookie_mem[i] = |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 63 | qdf_mem_malloc(sizeof(struct epping_cookie) * |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 64 | MAX_COOKIE_SLOT_SIZE); |
Yingying Tang | 86492de | 2016-09-28 17:28:03 +0800 | [diff] [blame] | 65 | if (pEpping_ctx->s_cookie_mem[i] == NULL) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 66 | EPPING_LOG(QDF_TRACE_LEVEL_FATAL, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 67 | "%s: no mem for cookie (idx = %d)", __func__, |
| 68 | i); |
| 69 | goto error; |
| 70 | } |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 71 | } |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 72 | qdf_spinlock_create(&pEpping_ctx->cookie_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 73 | |
| 74 | for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) { |
| 75 | struct epping_cookie *cookie_mem = pEpping_ctx->s_cookie_mem[i]; |
| 76 | for (j = 0; j < MAX_COOKIE_SLOT_SIZE; j++) { |
| 77 | epping_free_cookie(pEpping_ctx, &cookie_mem[j]); |
| 78 | } |
| 79 | } |
| 80 | return 0; |
| 81 | error: |
| 82 | for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) { |
| 83 | if (pEpping_ctx->s_cookie_mem[i]) { |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 84 | qdf_mem_free(pEpping_ctx->s_cookie_mem[i]); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 85 | pEpping_ctx->s_cookie_mem[i] = NULL; |
| 86 | } |
| 87 | } |
| 88 | return -ENOMEM; |
| 89 | } |
| 90 | |
| 91 | /* cleanup cookie queue */ |
| 92 | void epping_cookie_cleanup(epping_context_t *pEpping_ctx) |
| 93 | { |
| 94 | int i; |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 95 | qdf_spin_lock_bh(&pEpping_ctx->cookie_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 96 | pEpping_ctx->cookie_list = NULL; |
| 97 | pEpping_ctx->cookie_count = 0; |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 98 | qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 99 | for (i = 0; i < MAX_COOKIE_SLOTS_NUM; i++) { |
| 100 | if (pEpping_ctx->s_cookie_mem[i]) { |
Anurag Chouhan | 600c3a0 | 2016-03-01 10:33:54 +0530 | [diff] [blame] | 101 | qdf_mem_free(pEpping_ctx->s_cookie_mem[i]); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 102 | pEpping_ctx->s_cookie_mem[i] = NULL; |
| 103 | } |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | void epping_free_cookie(epping_context_t *pEpping_ctx, |
| 108 | struct epping_cookie *cookie) |
| 109 | { |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 110 | qdf_spin_lock_bh(&pEpping_ctx->cookie_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 111 | cookie->next = pEpping_ctx->cookie_list; |
| 112 | pEpping_ctx->cookie_list = cookie; |
| 113 | pEpping_ctx->cookie_count++; |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 114 | qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | struct epping_cookie *epping_alloc_cookie(epping_context_t *pEpping_ctx) |
| 118 | { |
| 119 | struct epping_cookie *cookie; |
| 120 | |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 121 | qdf_spin_lock_bh(&pEpping_ctx->cookie_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 122 | cookie = pEpping_ctx->cookie_list; |
| 123 | if (cookie != NULL) { |
| 124 | pEpping_ctx->cookie_list = cookie->next; |
| 125 | pEpping_ctx->cookie_count--; |
| 126 | } |
Anurag Chouhan | a37b5b7 | 2016-02-21 14:53:42 +0530 | [diff] [blame] | 127 | qdf_spin_unlock_bh(&pEpping_ctx->cookie_lock); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 128 | return cookie; |
| 129 | } |
| 130 | |
| 131 | void epping_get_dummy_mac_addr(tSirMacAddr macAddr) |
| 132 | { |
| 133 | macAddr[0] = 69; /* E */ |
| 134 | macAddr[1] = 80; /* P */ |
| 135 | macAddr[2] = 80; /* P */ |
| 136 | macAddr[3] = 73; /* I */ |
| 137 | macAddr[4] = 78; /* N */ |
| 138 | macAddr[5] = 71; /* G */ |
| 139 | } |
| 140 | |
| 141 | void epping_hex_dump(void *data, int buf_len, const char *str) |
| 142 | { |
| 143 | char *buf = (char *)data; |
| 144 | int i; |
| 145 | |
| 146 | printk("%s: E, %s\n", __func__, str); |
| 147 | for (i = 0; (i + 7) < buf_len; i += 8) { |
| 148 | printk("%02x %02x %02x %02x %02x %02x %02x %02x\n", |
| 149 | buf[i], |
| 150 | buf[i + 1], |
| 151 | buf[i + 2], |
| 152 | buf[i + 3], |
| 153 | buf[i + 4], buf[i + 5], buf[i + 6], buf[i + 7]); |
| 154 | } |
| 155 | |
| 156 | /* Dump the bytes in the last line */ |
| 157 | for (; i < buf_len; i++) { |
| 158 | printk("%02x ", buf[i]); |
| 159 | } |
| 160 | printk("\n%s: X %s\n", __func__, str); |
| 161 | } |
| 162 | |
Anurag Chouhan | f04e84f | 2016-03-03 10:12:12 +0530 | [diff] [blame] | 163 | void *epping_get_qdf_ctx(void) |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 164 | { |
Anurag Chouhan | f04e84f | 2016-03-03 10:12:12 +0530 | [diff] [blame] | 165 | qdf_device_t *qdf_ctx; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 166 | |
Anurag Chouhan | f04e84f | 2016-03-03 10:12:12 +0530 | [diff] [blame] | 167 | qdf_ctx = cds_get_context(QDF_MODULE_ID_QDF_DEVICE); |
| 168 | return qdf_ctx; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 169 | } |
| 170 | |
| 171 | void epping_log_packet(epping_adapter_t *pAdapter, |
| 172 | EPPING_HEADER *eppingHdr, int ret, const char *str) |
| 173 | { |
| 174 | if (eppingHdr->Cmd_h & EPPING_LOG_MASK) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 175 | EPPING_LOG(QDF_TRACE_LEVEL_FATAL, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 176 | "%s: cmd = %d, seqNo = %u, flag = 0x%x, ret = %d, " |
| 177 | "txCount = %lu, txDrop = %lu, txBytes = %lu," |
| 178 | "rxCount = %lu, rxDrop = %lu, rxBytes = %lu\n", |
| 179 | str, eppingHdr->Cmd_h, eppingHdr->SeqNo, |
| 180 | eppingHdr->CmdFlags_h, ret, |
| 181 | pAdapter->stats.tx_packets, |
| 182 | pAdapter->stats.tx_dropped, |
| 183 | pAdapter->stats.tx_bytes, |
| 184 | pAdapter->stats.rx_packets, |
| 185 | pAdapter->stats.rx_dropped, |
| 186 | pAdapter->stats.rx_bytes); |
| 187 | } |
| 188 | } |
| 189 | |
| 190 | void epping_log_stats(epping_adapter_t *pAdapter, const char *str) |
| 191 | { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 192 | EPPING_LOG(QDF_TRACE_LEVEL_FATAL, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 193 | "%s: txCount = %lu, txDrop = %lu, tx_bytes = %lu, " |
| 194 | "rxCount = %lu, rxDrop = %lu, rx_bytes = %lu, tx_acks = %u\n", |
| 195 | str, |
| 196 | pAdapter->stats.tx_packets, |
| 197 | pAdapter->stats.tx_dropped, |
| 198 | pAdapter->stats.tx_bytes, |
| 199 | pAdapter->stats.rx_packets, |
| 200 | pAdapter->stats.rx_dropped, |
| 201 | pAdapter->stats.rx_bytes, |
| 202 | pAdapter->pEpping_ctx->total_tx_acks); |
| 203 | } |
| 204 | |
| 205 | void epping_set_kperf_flag(epping_adapter_t *pAdapter, |
| 206 | HTC_ENDPOINT_ID eid, A_UINT8 kperf_flag) |
| 207 | { |
| 208 | pAdapter->pEpping_ctx->kperf_num_rx_recv[eid] = 0; |
| 209 | pAdapter->pEpping_ctx->kperf_num_tx_acks[eid] = 0; |
| 210 | } |