Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 1 | /* |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +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 <wni_api.h> |
| 44 | #include <wlan_ptt_sock_svc.h> |
| 45 | #include <linux/wireless.h> |
| 46 | #include <net/cfg80211.h> |
| 47 | #include <linux/rtnetlink.h> |
| 48 | #include <linux/semaphore.h> |
| 49 | #include <linux/ctype.h> |
| 50 | #include "epping_main.h" |
| 51 | #include "epping_internal.h" |
| 52 | #include "epping_test.h" |
| 53 | #include <wlan_hdd_napi.h> |
| 54 | |
| 55 | #define AR6000_MAX_RX_BUFFERS 16 |
| 56 | #define AR6000_BUFFER_SIZE 1664 |
| 57 | #define AR6000_MIN_HEAD_ROOM 64 |
| 58 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 59 | static bool enb_rx_dump; |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 60 | |
| 61 | #ifdef HIF_SDIO |
| 62 | void epping_refill(void *ctx, HTC_ENDPOINT_ID Endpoint) |
| 63 | { |
| 64 | epping_context_t *pEpping_ctx = (epping_context_t *) ctx; |
| 65 | void *osBuf; |
| 66 | int RxBuffers; |
| 67 | int buffersToRefill; |
| 68 | HTC_PACKET *pPacket; |
| 69 | HTC_PACKET_QUEUE queue; |
| 70 | |
| 71 | buffersToRefill = (int)AR6000_MAX_RX_BUFFERS - |
| 72 | htc_get_num_recv_buffers(pEpping_ctx->HTCHandle, Endpoint); |
| 73 | |
| 74 | if (buffersToRefill <= 0) { |
| 75 | /* fast return, nothing to fill */ |
| 76 | return; |
| 77 | } |
| 78 | |
| 79 | INIT_HTC_PACKET_QUEUE(&queue); |
| 80 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 81 | EPPING_LOG(QDF_TRACE_LEVEL_INFO, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 82 | "%s: providing htc with %d buffers at eid=%d\n", |
| 83 | __func__, buffersToRefill, Endpoint); |
| 84 | |
| 85 | for (RxBuffers = 0; RxBuffers < buffersToRefill; RxBuffers++) { |
Nirav Shah | cbc6d72 | 2016-03-01 16:24:53 +0530 | [diff] [blame] | 86 | osBuf = qdf_nbuf_alloc(NULL, AR6000_BUFFER_SIZE, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 87 | AR6000_MIN_HEAD_ROOM, 4, false); |
| 88 | if (NULL == osBuf) { |
| 89 | break; |
| 90 | } |
| 91 | /* the HTC packet wrapper is at the head of the reserved area |
| 92 | * in the skb */ |
| 93 | pPacket = (HTC_PACKET *) (A_NETBUF_HEAD(osBuf)); |
| 94 | /* set re-fill info */ |
| 95 | SET_HTC_PACKET_INFO_RX_REFILL(pPacket, osBuf, |
Nirav Shah | cbc6d72 | 2016-03-01 16:24:53 +0530 | [diff] [blame] | 96 | qdf_nbuf_data(osBuf), |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 97 | AR6000_BUFFER_SIZE, Endpoint); |
| 98 | SET_HTC_PACKET_NET_BUF_CONTEXT(pPacket, osBuf); |
| 99 | /* add to queue */ |
| 100 | HTC_PACKET_ENQUEUE(&queue, pPacket); |
| 101 | } |
| 102 | |
| 103 | if (!HTC_QUEUE_EMPTY(&queue)) { |
| 104 | /* add packets */ |
| 105 | htc_add_receive_pkt_multiple(pEpping_ctx->HTCHandle, &queue); |
| 106 | } |
| 107 | } |
| 108 | #endif /* HIF_SDIO */ |
| 109 | |
| 110 | void epping_rx(void *ctx, HTC_PACKET *pPacket) |
| 111 | { |
| 112 | epping_context_t *pEpping_ctx = (epping_context_t *) ctx; |
| 113 | epping_adapter_t *pAdapter = pEpping_ctx->epping_adapter; |
| 114 | struct net_device *dev = pAdapter->dev; |
| 115 | A_STATUS status = pPacket->Status; |
| 116 | HTC_ENDPOINT_ID eid = pPacket->Endpoint; |
| 117 | struct sk_buff *pktSkb = (struct sk_buff *)pPacket->pPktContext; |
| 118 | |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 119 | EPPING_LOG(QDF_TRACE_LEVEL_INFO, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 120 | "%s: pAdapter = 0x%p eid=%d, skb=0x%p, data=0x%p, len=0x%x status:%d", |
| 121 | __func__, pAdapter, eid, pktSkb, pPacket->pBuffer, |
| 122 | pPacket->ActualLength, status); |
| 123 | |
| 124 | if (status != A_OK) { |
| 125 | if (status != A_ECANCELED) { |
Nirav Shah | cbc6d72 | 2016-03-01 16:24:53 +0530 | [diff] [blame] | 126 | printk("%s: RX ERR (%d)\n", __func__, status); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 127 | } |
Nirav Shah | cbc6d72 | 2016-03-01 16:24:53 +0530 | [diff] [blame] | 128 | qdf_nbuf_free(pktSkb); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 129 | return; |
| 130 | } |
| 131 | |
| 132 | /* deliver to up layer */ |
| 133 | if (pktSkb) { |
| 134 | if (EPPING_ALIGNMENT_PAD > 0) { |
| 135 | A_NETBUF_PULL(pktSkb, EPPING_ALIGNMENT_PAD); |
| 136 | } |
| 137 | if (enb_rx_dump) |
Nirav Shah | cbc6d72 | 2016-03-01 16:24:53 +0530 | [diff] [blame] | 138 | epping_hex_dump((void *)qdf_nbuf_data(pktSkb), |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 139 | pktSkb->len, __func__); |
| 140 | pktSkb->dev = dev; |
| 141 | if ((pktSkb->dev->flags & IFF_UP) == IFF_UP) { |
| 142 | pktSkb->protocol = eth_type_trans(pktSkb, pktSkb->dev); |
| 143 | ++pAdapter->stats.rx_packets; |
| 144 | pAdapter->stats.rx_bytes += pktSkb->len; |
Rajeev Kumar | 8044ede | 2016-04-14 16:08:05 -0700 | [diff] [blame] | 145 | qdf_net_buf_debug_release_skb(pktSkb); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 146 | if (hdd_napi_enabled(HDD_NAPI_ANY)) |
| 147 | netif_receive_skb(pktSkb); |
| 148 | else |
| 149 | netif_rx_ni(pktSkb); |
| 150 | if ((pAdapter->stats.rx_packets % |
| 151 | EPPING_STATS_LOG_COUNT) == 0) { |
Anurag Chouhan | b2dc16f | 2016-02-25 11:47:37 +0530 | [diff] [blame] | 152 | EPPING_LOG(QDF_TRACE_LEVEL_FATAL, |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 153 | "%s: total_rx_pkts = %lu", |
| 154 | __func__, |
| 155 | pAdapter->stats.rx_packets); |
| 156 | } |
| 157 | } else { |
| 158 | ++pAdapter->stats.rx_dropped; |
Nirav Shah | cbc6d72 | 2016-03-01 16:24:53 +0530 | [diff] [blame] | 159 | qdf_nbuf_free(pktSkb); |
Prakash Dhavali | 7090c5f | 2015-11-02 17:55:19 -0800 | [diff] [blame] | 160 | } |
| 161 | } |
| 162 | } |