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 RXDESC_SIZE 24
143 #define RXDESC_OFFSET RXDESC_SIZE
157 accesser of recv_priv: rtw_recv_entry(dispatch / passive level);
158 recv_thread(passive) ; returnpkt(dispatch)
161 using enter_critical section to protect
164 struct __queue free_recv_queue;
165 struct __queue recv_pending_queue;
166 struct __queue uc_swdec_pending_queue;
167 void *pallocated_frame_buf;
168 struct adapter *adapter;
175 struct tasklet_struct irq_prepare_beacon_tasklet;
176 struct tasklet_struct recv_tasklet;
177 struct sk_buff_head free_recv_skb_queue;
178 struct sk_buff_head rx_skb_queue;
179 struct recv_buf *precv_buf; /* 4 alignment */
180 struct __queue free_recv_buf_queue;
181 /* For display the phy informatiom */
189 struct timer_list signal_stat_timer;
190 u32 signal_stat_sampling_interval;
191 struct signal_stat signal_qual_data;
192 struct signal_stat signal_strength_data;
195 #define rtw_set_signal_stat_timer(recvpriv) \
196 mod_timer(&(recvpriv)->signal_stat_timer, jiffies + \
197 msecs_to_jiffies((recvpriv)->signal_stat_sampling_interval))
199 struct sta_recv_priv {
202 struct __queue defrag_q; /* keeping the fragment frame until defrag */
203 struct stainfo_rxcache rxcache;
207 struct adapter *adapter;
209 struct sk_buff *pskb;
225 len = (unsigned int )(tail - data);
229 struct list_head list;
231 struct adapter *adapter;
232 struct rx_pkt_attrib attrib;
238 struct sta_info *psta;
239 /* for A-MPDU Rx reordering buffer control */
240 struct recv_reorder_ctrl *preorder_ctrl;
243 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
244 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
245 void rtw_init_recvframe(struct recv_frame *precvframe,
246 struct recv_priv *precvpriv);
247 int rtw_free_recvframe(struct recv_frame *precvframe,
248 struct __queue *pfree_recv_queue);
249 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
250 int _rtw_enqueue_recvframe(struct recv_frame *precvframe,
251 struct __queue *queue);
252 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue);
253 void rtw_free_recvframe_queue(struct __queue *pframequeue,
254 struct __queue *pfree_recv_queue);
255 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
257 void rtw_reordering_ctrl_timeout_handler(unsigned long data);
259 static inline u8 *get_rxmem(struct recv_frame *precvframe)
261 /* always return rx_head... */
262 if (precvframe == NULL)
264 return precvframe->rx_head;
267 static inline u8 *recvframe_pull(struct recv_frame *precvframe, int sz)
269 /* rx_data += sz; move rx_data sz bytes hereafter */
271 /* used for extract sz bytes from rx_data, update rx_data and return
272 * the updated rx_data to the caller */
274 if (precvframe == NULL)
276 precvframe->rx_data += sz;
277 if (precvframe->rx_data > precvframe->rx_tail) {
278 precvframe->rx_data -= sz;
281 precvframe->len -= sz;
282 return precvframe->rx_data;
285 static inline u8 *recvframe_put(struct recv_frame *precvframe, int sz)
287 /* used for append sz bytes from ptr to rx_tail, update rx_tail
288 * and return the updated rx_tail to the caller */
289 /* after putting, rx_tail must be still larger than rx_end. */
291 if (precvframe == NULL)
294 precvframe->rx_tail += sz;
296 if (precvframe->rx_tail > precvframe->rx_end) {
297 precvframe->rx_tail -= sz;
300 precvframe->len += sz;
301 return precvframe->rx_tail;
304 static inline u8 *recvframe_pull_tail(struct recv_frame *precvframe, int sz)
306 /* rmv data from rx_tail (by yitsen) */
308 /* used for extract sz bytes from rx_end, update rx_end and return
309 * the updated rx_end to the caller */
310 /* after pulling, rx_end must be still larger than rx_data. */
312 if (precvframe == NULL)
314 precvframe->rx_tail -= sz;
315 if (precvframe->rx_tail < precvframe->rx_data) {
316 precvframe->rx_tail += sz;
319 precvframe->len -= sz;
320 return precvframe->rx_tail;
323 static inline s32 translate_percentage_to_dbm(u32 sig_stren_index)
325 s32 power; /* in dBm. */
327 /* Translate to dBm (x=0.5y-95). */
328 power = (s32)((sig_stren_index + 1) >> 1);
337 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
339 void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame);