1 /* 2 * Copyright (c) 2014-2020 The Linux Foundation. All rights reserved. 3 * Copyright (c) 2023 Qualcomm Innovation Center, Inc. All rights reserved. 4 * 5 * Permission to use, copy, modify, and/or distribute this software for 6 * any purpose with or without fee is hereby granted, provided that the 7 * above copyright notice and this permission notice appear in all 8 * copies. 9 * 10 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL 11 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED 12 * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE 13 * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL 14 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR 15 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER 16 * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR 17 * PERFORMANCE OF THIS SOFTWARE. 18 */ 19 20 #ifndef EPPING_INTERNAL_H 21 #define EPPING_INTERNAL_H 22 /** 23 * DOC: epping_internal.h 24 * Linux epping internal head file 25 */ 26 27 #include <linux/netdevice.h> 28 #include <linux/skbuff.h> 29 #include <linux/spinlock.h> 30 #include <linux/kthread.h> 31 #include <linux/semaphore.h> 32 #if defined(CONFIG_HAS_WAKELOCK) 33 #include <linux/wakelock.h> 34 #endif 35 #include "htc_api.h" 36 #include "htc_packet.h" 37 #include "epping_test.h" 38 #include <qdf_atomic.h> 39 #include <sir_mac_prot_def.h> 40 #include <sir_debug.h> 41 42 #define EPPING_LOG_MASK (1<<EPPING_CMD_CAPTURE_RECV_CNT) 43 #define EPPING_STATS_LOG_COUNT 50000 44 #define EPPING_KTID_KILL_WAIT_TIME_MS 50 45 46 #define EPPING_FRAG_PER_MSDU 1 47 #ifndef EPPING_TXBUF 48 #define EPPING_TXBUF (512/EPPING_FRAG_PER_MSDU) 49 #endif 50 51 /*--------------------------------------------------------------------------- 52 Preprocessor definitions and constants 53 -------------------------------------------------------------------------*/ 54 #define EPPING_MAX_ADAPTERS 1 55 56 #define EPPING_LOG(level, args ...) QDF_TRACE(QDF_MODULE_ID_HDD, level, ## args) 57 #define EPPING_HEX_DUMP(level, data, len) qdf_trace_hex_dump( \ 58 QDF_MODULE_ID_HDD, \ 59 level, \ 60 data, buf_len) 61 62 struct epping_cookie { 63 HTC_PACKET HtcPkt; /* HTC packet wrapper */ 64 struct epping_cookie *next; 65 }; 66 67 typedef enum { 68 EPPING_CTX_STATE_INITIAL = 0, 69 EPPING_CTX_STATE_HIF_INIT, 70 EPPING_CTX_STATE_STARTUP, 71 EPPING_CTX_STATE_STARTED, 72 EPPING_CTX_STATE_STOP 73 } epping_ctx_state_t; 74 75 #define EPPING_MAX_NUM_EPIDS 4 76 #define MAX_COOKIE_SLOTS_NUM 4 77 #define MAX_COOKIE_SLOT_SIZE 512 78 #define MAX_TX_PKT_DUP_NUM 4 79 80 #if defined(HIF_PCI) || defined(HIF_IPCI) 81 #define WLAN_EPPING_DELAY_TIMEOUT_US 10 82 #define EPPING_MAX_CE_NUMS 8 83 #define EPPING_MAX_WATER_MARK 8 84 typedef struct { 85 struct task_struct *pid; 86 void *arg; 87 bool done; 88 qdf_nbuf_t skb; 89 HTC_ENDPOINT_ID eid; 90 struct semaphore sem; 91 bool inited; 92 qdf_atomic_t atm; 93 } epping_poll_t; 94 #endif 95 96 typedef struct epping_context { 97 int32_t con_mode; 98 char *pwlan_module_name; 99 uint32_t target_type; 100 void *p_cds_context; /* CDS context */ 101 struct device *parent_dev; /* Pointer to the parent device */ 102 epping_ctx_state_t e_ctx_state; 103 bool wow_nack; 104 void *epping_adapter; 105 HTC_HANDLE HTCHandle; 106 HTC_ENDPOINT_ID EppingEndpoint[EPPING_MAX_NUM_EPIDS]; 107 unsigned int kperf_num_rx_recv[EPPING_MAX_NUM_EPIDS]; 108 unsigned int kperf_num_tx_acks[EPPING_MAX_NUM_EPIDS]; 109 unsigned int total_rx_recv; 110 unsigned int total_tx_acks; 111 #if defined(HIF_PCI) || defined(HIF_IPCI) 112 epping_poll_t epping_poll[EPPING_MAX_NUM_EPIDS]; 113 #endif 114 struct epping_cookie *cookie_list; 115 int cookie_count; 116 struct epping_cookie *s_cookie_mem[MAX_COOKIE_SLOTS_NUM]; 117 qdf_spinlock_t cookie_lock; 118 } epping_context_t; 119 120 typedef enum { 121 EPPING_TX_TIMER_STOPPED, 122 EPPING_TX_TIMER_RUNNING 123 } epping_tx_timer_state_t; 124 125 typedef struct epping_adapter_s { 126 epping_context_t *pEpping_ctx; 127 enum QDF_OPMODE device_mode; 128 /** Handle to the network device */ 129 struct net_device *dev; 130 struct qdf_mac_addr macAddressCurrent; 131 uint8_t sessionId; 132 /* for mboxping */ 133 qdf_spinlock_t data_lock; 134 qdf_nbuf_queue_t nodrop_queue; 135 qdf_timer_t epping_timer; 136 epping_tx_timer_state_t epping_timer_state; 137 bool registered; 138 bool started; 139 struct net_device_stats stats; 140 } epping_adapter_t; 141 142 /* epping_helper signatures */ 143 int epping_cookie_init(epping_context_t *pEpping_ctx); 144 void epping_cookie_cleanup(epping_context_t *pEpping_ctx); 145 void epping_free_cookie(epping_context_t *pEpping_ctx, 146 struct epping_cookie *cookie); 147 struct epping_cookie *epping_alloc_cookie(epping_context_t *pEpping_ctx); 148 void epping_get_dummy_mac_addr(tSirMacAddr macAddr); 149 void epping_hex_dump(void *data, int buf_len, const char *str); 150 void *epping_get_qdf_ctx(void); 151 void epping_log_packet(epping_adapter_t *adapter, 152 EPPING_HEADER *eppingHdr, int ret, const char *str); 153 void epping_log_stats(epping_adapter_t *adapter, const char *str); 154 void epping_set_kperf_flag(epping_adapter_t *adapter, 155 HTC_ENDPOINT_ID eid, uint8_t kperf_flag); 156 157 /* epping_tx signatures */ 158 void epping_tx_timer_expire(epping_adapter_t *adapter); 159 void epping_tx_complete(void *ctx, HTC_PACKET *htc_pkt); 160 int epping_tx_send(qdf_nbuf_t skb, epping_adapter_t *adapter); 161 162 #ifdef HIF_SDIO 163 enum htc_send_full_action epping_tx_queue_full(void *Context, 164 struct _HTC_PACKET *pPacket); 165 #endif 166 void epping_tx_dup_pkt(epping_adapter_t *adapter, 167 HTC_ENDPOINT_ID eid, qdf_nbuf_t skb); 168 /* epping_rx signatures */ 169 void epping_rx(void *Context, HTC_PACKET *pPacket); 170 171 #ifdef HIF_SDIO 172 void epping_refill(void *ctx, HTC_ENDPOINT_ID Endpoint); 173 #endif 174 175 /* epping_txrx signatures */ 176 epping_adapter_t *epping_add_adapter(epping_context_t *pEpping_ctx, 177 tSirMacAddr macAddr, 178 enum QDF_OPMODE device_mode, 179 bool rtnl_held); 180 void epping_destroy_adapter(epping_adapter_t *adapter); 181 int epping_connect_service(epping_context_t *pEpping_ctx); 182 #if defined(HIF_PCI) || defined(HIF_IPCI) 183 void epping_register_tx_copier(HTC_ENDPOINT_ID eid, 184 epping_context_t *pEpping_ctx); 185 void epping_unregister_tx_copier(HTC_ENDPOINT_ID eid, 186 epping_context_t *pEpping_ctx); 187 void epping_tx_copier_schedule(epping_context_t *pEpping_ctx, 188 HTC_ENDPOINT_ID eid, qdf_nbuf_t skb); 189 #endif /* HIF_PCI || HIF_IPCI */ 190 #endif /* end #ifndef EPPING_INTERNAL_H */ 191