1 /******************************************************************************
3 * Copyright(c) 2007 - 2012 Realtek Corporation. All rights reserved.
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.
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
14 ******************************************************************************/
18 #include <osdep_service.h>
19 #include <drv_types.h>
22 #define NR_RECVFRAME 256
24 #define RXFRAME_ALIGN 8
25 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
27 #define MAX_RXFRAME_CNT 512
28 #define MAX_RX_NUMBLKS (32)
29 #define RECVFRAME_HDR_ALIGN 128
31 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
33 #define MAX_SUBFRAME_COUNT 64
35 /* for Rx reordering buffer control */
36 struct recv_reorder_ctrl {
37 struct adapter *padapter;
39 u16 indicate_seq;/* wstart_b, init_value=0xffff */
42 struct __queue pending_recvframe_queue;
43 struct timer_list reordering_ctrl_timer;
46 struct stainfo_rxcache {
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;
69 u8 update_req; /* used to indicate */
70 u8 avg_val; /* avg of valid elements */
71 u32 total_num; /* num of valid elements */
72 u32 total_val; /* sum of valid elements */
74 #define MAX_PATH_NUM_92CS 3
77 u8 SignalQuality; /* in 0-100 index. */
78 u8 RxMIMOSignalQuality[MAX_PATH_NUM_92CS]; /* EVM */
79 u8 RxMIMOSignalStrength[MAX_PATH_NUM_92CS];/* in 0~100 index */
80 s8 RxPower; /* in dBm Translate from PWdB */
81 /* Real power in dBm for this packet, no beautification and aggregation.
82 * Keep this raw info to be used for the other procedures. */
84 u8 BTRxRSSIPercentage;
85 u8 SignalStrength; /* in 0-100 index. */
86 u8 RxPwr[MAX_PATH_NUM_92CS];/* per-path's pwdb */
87 u8 RxSNR[MAX_PATH_NUM_92CS];/* per-path's SNR */
90 struct rx_pkt_attrib {
95 u8 hdrlen; /* the WLAN Header Len */
106 u8 privacy; /* in frame_ctrl field */
108 u8 encrypt; /* when 0 indicate no encrypt. when non-zero,
109 * indicate the encrypt algorith */
131 u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */
133 struct phy_info phy_info;
137 /* These definition is used for Rx packet reordering. */
138 #define SN_LESS(a, b) (((a - b) & 0x800) != 0)
139 #define SN_EQUAL(a, b) (a == b)
140 #define REORDER_WAIT_TIME (50) /* (ms) */
142 #define RECVBUFF_ALIGN_SZ 8
144 #define RXDESC_SIZE 24
145 #define RXDESC_OFFSET RXDESC_SIZE
159 accesser of recv_priv: rtw_recv_entry(dispatch / passive level);
160 recv_thread(passive) ; returnpkt(dispatch)
163 using enter_critical section to protect
166 struct __queue free_recv_queue;
167 struct __queue recv_pending_queue;
168 struct __queue uc_swdec_pending_queue;
169 u8 *pallocated_frame_buf;
171 uint free_recvframe_cnt;
172 struct adapter *adapter;
182 struct tasklet_struct irq_prepare_beacon_tasklet;
183 struct tasklet_struct recv_tasklet;
184 struct sk_buff_head free_recv_skb_queue;
185 struct sk_buff_head rx_skb_queue;
186 u8 *pallocated_recv_buf;
187 u8 *precv_buf; /* 4 alignment */
188 struct __queue free_recv_buf_queue;
189 u32 free_recv_buf_queue_cnt;
190 /* For display the phy informatiom */
191 u8 is_signal_dbg; /* for debug */
192 u8 signal_strength_dbg; /* for debug */
200 struct timer_list signal_stat_timer;
201 u32 signal_stat_sampling_interval;
202 struct signal_stat signal_qual_data;
203 struct signal_stat signal_strength_data;
206 #define rtw_set_signal_stat_timer(recvpriv) \
207 mod_timer(&(recvpriv)->signal_stat_timer, jiffies + \
208 msecs_to_jiffies((recvpriv)->signal_stat_sampling_interval))
210 struct sta_recv_priv {
213 struct __queue defrag_q; /* keeping the fragment frame until defrag */
214 struct stainfo_rxcache rxcache;
218 struct adapter *adapter;
220 struct sk_buff *pskb;
236 len = (unsigned int )(tail - data);
240 struct list_head list;
242 struct adapter *adapter;
243 struct rx_pkt_attrib attrib;
249 struct sta_info *psta;
250 /* for A-MPDU Rx reordering buffer control */
251 struct recv_reorder_ctrl *preorder_ctrl;
254 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
255 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
256 void rtw_init_recvframe(struct recv_frame *precvframe,
257 struct recv_priv *precvpriv);
258 int rtw_free_recvframe(struct recv_frame *precvframe,
259 struct __queue *pfree_recv_queue);
260 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
261 int _rtw_enqueue_recvframe(struct recv_frame *precvframe,
262 struct __queue *queue);
263 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue);
264 void rtw_free_recvframe_queue(struct __queue *pframequeue,
265 struct __queue *pfree_recv_queue);
266 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
268 void rtw_reordering_ctrl_timeout_handler(unsigned long data);
270 static inline u8 *get_rxmem(struct recv_frame *precvframe)
272 /* always return rx_head... */
273 if (precvframe == NULL)
275 return precvframe->rx_head;
278 static inline u8 *recvframe_pull(struct recv_frame *precvframe, int sz)
280 /* rx_data += sz; move rx_data sz bytes hereafter */
282 /* used for extract sz bytes from rx_data, update rx_data and return
283 * the updated rx_data to the caller */
285 if (precvframe == NULL)
287 precvframe->rx_data += sz;
288 if (precvframe->rx_data > precvframe->rx_tail) {
289 precvframe->rx_data -= sz;
292 precvframe->len -= sz;
293 return precvframe->rx_data;
296 static inline u8 *recvframe_put(struct recv_frame *precvframe, int sz)
298 /* used for append sz bytes from ptr to rx_tail, update rx_tail
299 * and return the updated rx_tail to the caller */
300 /* after putting, rx_tail must be still larger than rx_end. */
302 if (precvframe == NULL)
305 precvframe->rx_tail += sz;
307 if (precvframe->rx_tail > precvframe->rx_end) {
308 precvframe->rx_tail -= sz;
311 precvframe->len += sz;
312 return precvframe->rx_tail;
315 static inline u8 *recvframe_pull_tail(struct recv_frame *precvframe, int sz)
317 /* rmv data from rx_tail (by yitsen) */
319 /* used for extract sz bytes from rx_end, update rx_end and return
320 * the updated rx_end to the caller */
321 /* after pulling, rx_end must be still larger than rx_data. */
323 if (precvframe == NULL)
325 precvframe->rx_tail -= sz;
326 if (precvframe->rx_tail < precvframe->rx_data) {
327 precvframe->rx_tail += sz;
330 precvframe->len -= sz;
331 return precvframe->rx_tail;
334 static inline s32 translate_percentage_to_dbm(u32 sig_stren_index)
336 s32 power; /* in dBm. */
338 /* Translate to dBm (x=0.5y-95). */
339 power = (s32)((sig_stren_index + 1) >> 1);
348 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
350 void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame);