Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | * |
| 3 | * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved. |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or modify it |
| 6 | * under the terms of version 2 of the GNU General Public License as |
| 7 | * published by the Free Software Foundation. |
| 8 | * |
| 9 | * This program is distributed in the hope that it will be useful, but WITHOUT |
| 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 12 | * more details. |
| 13 | * |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 14 | ******************************************************************************/ |
| 15 | #ifndef _RTW_RECV_H_ |
| 16 | #define _RTW_RECV_H_ |
| 17 | |
| 18 | #include <osdep_service.h> |
| 19 | #include <drv_types.h> |
| 20 | |
| 21 | |
| 22 | #define NR_RECVFRAME 256 |
| 23 | |
| 24 | #define RXFRAME_ALIGN 8 |
| 25 | #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN) |
| 26 | |
| 27 | #define MAX_RXFRAME_CNT 512 |
| 28 | #define MAX_RX_NUMBLKS (32) |
| 29 | #define RECVFRAME_HDR_ALIGN 128 |
| 30 | |
| 31 | #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr) |
| 32 | |
| 33 | #define MAX_SUBFRAME_COUNT 64 |
| 34 | |
| 35 | /* for Rx reordering buffer control */ |
| 36 | struct recv_reorder_ctrl { |
| 37 | struct adapter *padapter; |
| 38 | u8 enable; |
| 39 | u16 indicate_seq;/* wstart_b, init_value=0xffff */ |
| 40 | u16 wend_b; |
| 41 | u8 wsize_b; |
| 42 | struct __queue pending_recvframe_queue; |
| 43 | struct timer_list reordering_ctrl_timer; |
| 44 | }; |
| 45 | |
| 46 | struct stainfo_rxcache { |
| 47 | u16 tid_rxseq[16]; |
| 48 | /* |
| 49 | unsigned short tid0_rxseq; |
| 50 | unsigned short tid1_rxseq; |
| 51 | unsigned short tid2_rxseq; |
| 52 | unsigned short tid3_rxseq; |
| 53 | unsigned short tid4_rxseq; |
| 54 | unsigned short tid5_rxseq; |
| 55 | unsigned short tid6_rxseq; |
| 56 | unsigned short tid7_rxseq; |
| 57 | unsigned short tid8_rxseq; |
| 58 | unsigned short tid9_rxseq; |
| 59 | unsigned short tid10_rxseq; |
| 60 | unsigned short tid11_rxseq; |
| 61 | unsigned short tid12_rxseq; |
| 62 | unsigned short tid13_rxseq; |
| 63 | unsigned short tid14_rxseq; |
| 64 | unsigned short tid15_rxseq; |
| 65 | */ |
| 66 | }; |
| 67 | |
| 68 | struct smooth_rssi_data { |
| 69 | u32 elements[100]; /* array to store values */ |
| 70 | u32 index; /* index to current array to store */ |
| 71 | u32 total_num; /* num of valid elements */ |
| 72 | u32 total_val; /* sum of valid elements */ |
| 73 | }; |
| 74 | |
| 75 | struct signal_stat { |
| 76 | u8 update_req; /* used to indicate */ |
| 77 | u8 avg_val; /* avg of valid elements */ |
| 78 | u32 total_num; /* num of valid elements */ |
| 79 | u32 total_val; /* sum of valid elements */ |
| 80 | }; |
Larry Finger | bdbdc54 | 2013-09-04 15:56:06 -0500 | [diff] [blame] | 81 | #define MAX_PATH_NUM_92CS 3 |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 82 | struct phy_info { |
| 83 | u8 RxPWDBAll; |
| 84 | u8 SignalQuality; /* in 0-100 index. */ |
| 85 | u8 RxMIMOSignalQuality[MAX_PATH_NUM_92CS]; /* EVM */ |
| 86 | u8 RxMIMOSignalStrength[MAX_PATH_NUM_92CS];/* in 0~100 index */ |
| 87 | s8 RxPower; /* in dBm Translate from PWdB */ |
| 88 | /* Real power in dBm for this packet, no beautification and aggregation. |
| 89 | * Keep this raw info to be used for the other procedures. */ |
| 90 | s8 recvpower; |
| 91 | u8 BTRxRSSIPercentage; |
| 92 | u8 SignalStrength; /* in 0-100 index. */ |
| 93 | u8 RxPwr[MAX_PATH_NUM_92CS];/* per-path's pwdb */ |
| 94 | u8 RxSNR[MAX_PATH_NUM_92CS];/* per-path's SNR */ |
| 95 | }; |
| 96 | |
| 97 | struct rx_pkt_attrib { |
| 98 | u16 pkt_len; |
| 99 | u8 physt; |
| 100 | u8 drvinfo_sz; |
| 101 | u8 shift_sz; |
| 102 | u8 hdrlen; /* the WLAN Header Len */ |
| 103 | u8 to_fr_ds; |
| 104 | u8 amsdu; |
| 105 | u8 qos; |
| 106 | u8 priority; |
| 107 | u8 pw_save; |
| 108 | u8 mdata; |
| 109 | u16 seq_num; |
| 110 | u8 frag_num; |
| 111 | u8 mfrag; |
| 112 | u8 order; |
| 113 | u8 privacy; /* in frame_ctrl field */ |
| 114 | u8 bdecrypted; |
| 115 | u8 encrypt; /* when 0 indicate no encrypt. when non-zero, |
| 116 | * indicate the encrypt algorith */ |
| 117 | u8 iv_len; |
| 118 | u8 icv_len; |
| 119 | u8 crc_err; |
| 120 | u8 icv_err; |
| 121 | |
| 122 | u16 eth_type; |
| 123 | |
| 124 | u8 dst[ETH_ALEN]; |
| 125 | u8 src[ETH_ALEN]; |
| 126 | u8 ta[ETH_ALEN]; |
| 127 | u8 ra[ETH_ALEN]; |
| 128 | u8 bssid[ETH_ALEN]; |
| 129 | |
| 130 | u8 ack_policy; |
| 131 | |
| 132 | u8 key_index; |
| 133 | |
| 134 | u8 mcs_rate; |
| 135 | u8 rxht; |
| 136 | u8 sgi; |
| 137 | u8 pkt_rpt_type; |
| 138 | u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */ |
| 139 | |
| 140 | struct phy_info phy_info; |
| 141 | }; |
| 142 | |
| 143 | |
| 144 | /* These definition is used for Rx packet reordering. */ |
| 145 | #define SN_LESS(a, b) (((a - b) & 0x800) != 0) |
| 146 | #define SN_EQUAL(a, b) (a == b) |
| 147 | #define REORDER_WAIT_TIME (50) /* (ms) */ |
| 148 | |
| 149 | #define RECVBUFF_ALIGN_SZ 8 |
| 150 | |
| 151 | #define RXDESC_SIZE 24 |
| 152 | #define RXDESC_OFFSET RXDESC_SIZE |
| 153 | |
| 154 | struct recv_stat { |
| 155 | __le32 rxdw0; |
| 156 | __le32 rxdw1; |
| 157 | __le32 rxdw2; |
| 158 | __le32 rxdw3; |
| 159 | __le32 rxdw4; |
| 160 | __le32 rxdw5; |
| 161 | }; |
| 162 | |
| 163 | #define EOR BIT(30) |
| 164 | |
| 165 | /* |
| 166 | accesser of recv_priv: rtw_recv_entry(dispatch / passive level); |
| 167 | recv_thread(passive) ; returnpkt(dispatch) |
| 168 | ; halt(passive) ; |
| 169 | |
| 170 | using enter_critical section to protect |
| 171 | */ |
| 172 | struct recv_priv { |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 173 | struct __queue free_recv_queue; |
| 174 | struct __queue recv_pending_queue; |
| 175 | struct __queue uc_swdec_pending_queue; |
| 176 | u8 *pallocated_frame_buf; |
| 177 | u8 *precv_frame_buf; |
| 178 | uint free_recvframe_cnt; |
| 179 | struct adapter *adapter; |
| 180 | u32 bIsAnyNonBEPkts; |
| 181 | u64 rx_bytes; |
| 182 | u64 rx_pkts; |
| 183 | u64 rx_drop; |
| 184 | u64 last_rx_bytes; |
| 185 | |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 186 | uint ff_hwaddr; |
| 187 | u8 rx_pending_cnt; |
| 188 | |
| 189 | struct tasklet_struct irq_prepare_beacon_tasklet; |
| 190 | struct tasklet_struct recv_tasklet; |
| 191 | struct sk_buff_head free_recv_skb_queue; |
| 192 | struct sk_buff_head rx_skb_queue; |
| 193 | u8 *pallocated_recv_buf; |
| 194 | u8 *precv_buf; /* 4 alignment */ |
| 195 | struct __queue free_recv_buf_queue; |
| 196 | u32 free_recv_buf_queue_cnt; |
| 197 | /* For display the phy informatiom */ |
| 198 | u8 is_signal_dbg; /* for debug */ |
| 199 | u8 signal_strength_dbg; /* for debug */ |
| 200 | s8 rssi; |
| 201 | s8 rxpwdb; |
| 202 | u8 signal_strength; |
| 203 | u8 signal_qual; |
| 204 | u8 noise; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 205 | s8 RxRssi[2]; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 206 | |
| 207 | struct timer_list signal_stat_timer; |
| 208 | u32 signal_stat_sampling_interval; |
| 209 | struct signal_stat signal_qual_data; |
| 210 | struct signal_stat signal_strength_data; |
| 211 | }; |
| 212 | |
| 213 | #define rtw_set_signal_stat_timer(recvpriv) \ |
Vaishali Thakkar | 4d4efe3 | 2015-03-11 11:41:07 +0530 | [diff] [blame] | 214 | mod_timer(&(recvpriv)->signal_stat_timer, jiffies + \ |
| 215 | msecs_to_jiffies((recvpriv)->signal_stat_sampling_interval)) |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 216 | |
| 217 | struct sta_recv_priv { |
| 218 | spinlock_t lock; |
| 219 | int option; |
| 220 | struct __queue defrag_q; /* keeping the fragment frame until defrag */ |
| 221 | struct stainfo_rxcache rxcache; |
| 222 | }; |
| 223 | |
| 224 | struct recv_buf { |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 225 | struct adapter *adapter; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 226 | struct urb *purb; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 227 | struct sk_buff *pskb; |
| 228 | u8 reuse; |
| 229 | }; |
| 230 | |
| 231 | /* |
| 232 | head -----> |
| 233 | |
| 234 | data -----> |
| 235 | |
| 236 | payload |
| 237 | |
| 238 | tail -----> |
| 239 | |
| 240 | |
| 241 | end -----> |
| 242 | |
| 243 | len = (unsigned int )(tail - data); |
| 244 | |
| 245 | */ |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 246 | struct recv_frame { |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 247 | struct list_head list; |
| 248 | struct sk_buff *pkt; |
| 249 | struct sk_buff *pkt_newalloc; |
| 250 | struct adapter *adapter; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 251 | struct rx_pkt_attrib attrib; |
| 252 | uint len; |
| 253 | u8 *rx_head; |
| 254 | u8 *rx_data; |
| 255 | u8 *rx_tail; |
| 256 | u8 *rx_end; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 257 | struct sta_info *psta; |
| 258 | /* for A-MPDU Rx reordering buffer control */ |
| 259 | struct recv_reorder_ctrl *preorder_ctrl; |
| 260 | }; |
| 261 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 262 | struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue); |
| 263 | struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue); |
| 264 | void rtw_init_recvframe(struct recv_frame *precvframe, |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 265 | struct recv_priv *precvpriv); |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 266 | int rtw_free_recvframe(struct recv_frame *precvframe, |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 267 | struct __queue *pfree_recv_queue); |
| 268 | #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue) |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 269 | int _rtw_enqueue_recvframe(struct recv_frame *precvframe, |
| 270 | struct __queue *queue); |
| 271 | int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue); |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 272 | void rtw_free_recvframe_queue(struct __queue *pframequeue, |
| 273 | struct __queue *pfree_recv_queue); |
| 274 | u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter); |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 275 | |
Vaishali Thakkar | 28af7ea | 2015-03-11 11:41:24 +0530 | [diff] [blame] | 276 | void rtw_reordering_ctrl_timeout_handler(unsigned long data); |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 277 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 278 | static inline u8 *get_rxmem(struct recv_frame *precvframe) |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 279 | { |
| 280 | /* always return rx_head... */ |
| 281 | if (precvframe == NULL) |
| 282 | return NULL; |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 283 | return precvframe->rx_head; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 284 | } |
| 285 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 286 | static inline u8 *recvframe_pull(struct recv_frame *precvframe, int sz) |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 287 | { |
| 288 | /* rx_data += sz; move rx_data sz bytes hereafter */ |
| 289 | |
| 290 | /* used for extract sz bytes from rx_data, update rx_data and return |
| 291 | * the updated rx_data to the caller */ |
| 292 | |
| 293 | if (precvframe == NULL) |
| 294 | return NULL; |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 295 | precvframe->rx_data += sz; |
| 296 | if (precvframe->rx_data > precvframe->rx_tail) { |
| 297 | precvframe->rx_data -= sz; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 298 | return NULL; |
| 299 | } |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 300 | precvframe->len -= sz; |
| 301 | return precvframe->rx_data; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 302 | } |
| 303 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 304 | static inline u8 *recvframe_put(struct recv_frame *precvframe, int sz) |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 305 | { |
| 306 | /* used for append sz bytes from ptr to rx_tail, update rx_tail |
| 307 | * and return the updated rx_tail to the caller */ |
| 308 | /* after putting, rx_tail must be still larger than rx_end. */ |
| 309 | |
| 310 | if (precvframe == NULL) |
| 311 | return NULL; |
| 312 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 313 | precvframe->rx_tail += sz; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 314 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 315 | if (precvframe->rx_tail > precvframe->rx_end) { |
| 316 | precvframe->rx_tail -= sz; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 317 | return NULL; |
| 318 | } |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 319 | precvframe->len += sz; |
| 320 | return precvframe->rx_tail; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 321 | } |
| 322 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 323 | static inline u8 *recvframe_pull_tail(struct recv_frame *precvframe, int sz) |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 324 | { |
| 325 | /* rmv data from rx_tail (by yitsen) */ |
| 326 | |
| 327 | /* used for extract sz bytes from rx_end, update rx_end and return |
| 328 | * the updated rx_end to the caller */ |
| 329 | /* after pulling, rx_end must be still larger than rx_data. */ |
| 330 | |
| 331 | if (precvframe == NULL) |
| 332 | return NULL; |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 333 | precvframe->rx_tail -= sz; |
| 334 | if (precvframe->rx_tail < precvframe->rx_data) { |
| 335 | precvframe->rx_tail += sz; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 336 | return NULL; |
| 337 | } |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 338 | precvframe->len -= sz; |
| 339 | return precvframe->rx_tail; |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 340 | } |
| 341 | |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 342 | static inline s32 translate_percentage_to_dbm(u32 sig_stren_index) |
| 343 | { |
| 344 | s32 power; /* in dBm. */ |
| 345 | |
| 346 | /* Translate to dBm (x=0.5y-95). */ |
| 347 | power = (s32)((sig_stren_index + 1) >> 1); |
| 348 | power -= 95; |
| 349 | |
| 350 | return power; |
| 351 | } |
| 352 | |
| 353 | |
| 354 | struct sta_info; |
| 355 | |
| 356 | void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv); |
| 357 | |
Larry Finger | f31cca8 | 2014-02-14 16:54:07 -0600 | [diff] [blame] | 358 | void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame); |
Larry Finger | fff3340 | 2013-08-21 22:34:11 -0500 | [diff] [blame] | 359 | |
| 360 | #endif |