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 * You should have received a copy of the GNU General Public License along with
15 * this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
19 ******************************************************************************/
23 #include <osdep_service.h>
24 #include <drv_types.h>
27 #define NR_RECVFRAME 256
29 #define RXFRAME_ALIGN 8
30 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
32 #define MAX_RXFRAME_CNT 512
33 #define MAX_RX_NUMBLKS (32)
34 #define RECVFRAME_HDR_ALIGN 128
36 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
38 #define MAX_SUBFRAME_COUNT 64
40 /* for Rx reordering buffer control */
41 struct recv_reorder_ctrl {
42 struct adapter *padapter;
44 u16 indicate_seq;/* wstart_b, init_value=0xffff */
47 struct __queue pending_recvframe_queue;
48 struct timer_list reordering_ctrl_timer;
51 struct stainfo_rxcache {
54 unsigned short tid0_rxseq;
55 unsigned short tid1_rxseq;
56 unsigned short tid2_rxseq;
57 unsigned short tid3_rxseq;
58 unsigned short tid4_rxseq;
59 unsigned short tid5_rxseq;
60 unsigned short tid6_rxseq;
61 unsigned short tid7_rxseq;
62 unsigned short tid8_rxseq;
63 unsigned short tid9_rxseq;
64 unsigned short tid10_rxseq;
65 unsigned short tid11_rxseq;
66 unsigned short tid12_rxseq;
67 unsigned short tid13_rxseq;
68 unsigned short tid14_rxseq;
69 unsigned short tid15_rxseq;
73 struct smooth_rssi_data {
74 u32 elements[100]; /* array to store values */
75 u32 index; /* index to current array to store */
76 u32 total_num; /* num of valid elements */
77 u32 total_val; /* sum of valid elements */
81 u8 update_req; /* used to indicate */
82 u8 avg_val; /* avg of valid elements */
83 u32 total_num; /* num of valid elements */
84 u32 total_val; /* sum of valid elements */
86 #define MAX_PATH_NUM_92CS 3
89 u8 SignalQuality; /* in 0-100 index. */
90 u8 RxMIMOSignalQuality[MAX_PATH_NUM_92CS]; /* EVM */
91 u8 RxMIMOSignalStrength[MAX_PATH_NUM_92CS];/* in 0~100 index */
92 s8 RxPower; /* in dBm Translate from PWdB */
93 /* Real power in dBm for this packet, no beautification and aggregation.
94 * Keep this raw info to be used for the other procedures. */
96 u8 BTRxRSSIPercentage;
97 u8 SignalStrength; /* in 0-100 index. */
98 u8 RxPwr[MAX_PATH_NUM_92CS];/* per-path's pwdb */
99 u8 RxSNR[MAX_PATH_NUM_92CS];/* per-path's SNR */
102 struct rx_pkt_attrib {
107 u8 hdrlen; /* the WLAN Header Len */
118 u8 privacy; /* in frame_ctrl field */
120 u8 encrypt; /* when 0 indicate no encrypt. when non-zero,
121 * indicate the encrypt algorith */
143 u32 MacIDValidEntry[2]; /* 64 bits present 64 entry. */
145 struct phy_info phy_info;
149 /* These definition is used for Rx packet reordering. */
150 #define SN_LESS(a, b) (((a - b) & 0x800) != 0)
151 #define SN_EQUAL(a, b) (a == b)
152 #define REORDER_WAIT_TIME (50) /* (ms) */
154 #define RECVBUFF_ALIGN_SZ 8
156 #define RXDESC_SIZE 24
157 #define RXDESC_OFFSET RXDESC_SIZE
171 accesser of recv_priv: rtw_recv_entry(dispatch / passive level);
172 recv_thread(passive) ; returnpkt(dispatch)
175 using enter_critical section to protect
179 struct __queue free_recv_queue;
180 struct __queue recv_pending_queue;
181 struct __queue uc_swdec_pending_queue;
182 u8 *pallocated_frame_buf;
184 uint free_recvframe_cnt;
185 struct adapter *adapter;
193 uint rx_largepacket_crcerr;
194 uint rx_smallpacket_crcerr;
195 uint rx_middlepacket_crcerr;
196 struct semaphore allrxreturnevt;
200 struct tasklet_struct irq_prepare_beacon_tasklet;
201 struct tasklet_struct recv_tasklet;
202 struct sk_buff_head free_recv_skb_queue;
203 struct sk_buff_head rx_skb_queue;
204 u8 *pallocated_recv_buf;
205 u8 *precv_buf; /* 4 alignment */
206 struct __queue free_recv_buf_queue;
207 u32 free_recv_buf_queue_cnt;
208 /* For display the phy informatiom */
209 u8 is_signal_dbg; /* for debug */
210 u8 signal_strength_dbg; /* for debug */
220 struct timer_list signal_stat_timer;
221 u32 signal_stat_sampling_interval;
222 struct signal_stat signal_qual_data;
223 struct signal_stat signal_strength_data;
226 #define rtw_set_signal_stat_timer(recvpriv) \
227 _set_timer(&(recvpriv)->signal_stat_timer, \
228 (recvpriv)->signal_stat_sampling_interval)
230 struct sta_recv_priv {
233 struct __queue defrag_q; /* keeping the fragment frame until defrag */
234 struct stainfo_rxcache rxcache;
238 struct list_head list;
239 spinlock_t recvbuf_lock;
241 struct adapter *adapter;
250 dma_addr_t dma_transfer_addr; /* (in) dma addr for transfer_buffer */
254 struct sk_buff *pskb;
270 len = (unsigned int )(tail - data);
274 struct list_head list;
276 struct sk_buff *pkt_newalloc;
277 struct adapter *adapter;
280 struct rx_pkt_attrib attrib;
287 struct sta_info *psta;
288 /* for A-MPDU Rx reordering buffer control */
289 struct recv_reorder_ctrl *preorder_ctrl;
292 struct recv_frame *_rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
293 struct recv_frame *rtw_alloc_recvframe(struct __queue *pfree_recv_queue);
294 void rtw_init_recvframe(struct recv_frame *precvframe,
295 struct recv_priv *precvpriv);
296 int rtw_free_recvframe(struct recv_frame *precvframe,
297 struct __queue *pfree_recv_queue);
298 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
299 int _rtw_enqueue_recvframe(struct recv_frame *precvframe,
300 struct __queue *queue);
301 int rtw_enqueue_recvframe(struct recv_frame *precvframe, struct __queue *queue);
302 void rtw_free_recvframe_queue(struct __queue *pframequeue,
303 struct __queue *pfree_recv_queue);
304 u32 rtw_free_uc_swdec_pending_queue(struct adapter *adapter);
305 int rtw_enqueue_recvbuf_to_head(struct recv_buf *buf, struct __queue *queue);
306 int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, struct __queue *queue);
307 struct recv_buf *rtw_dequeue_recvbuf(struct __queue *queue);
309 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
311 static inline u8 *get_rxmem(struct recv_frame *precvframe)
313 /* always return rx_head... */
314 if (precvframe == NULL)
316 return precvframe->rx_head;
319 static inline u8 *get_rx_status(struct recv_frame *precvframe)
321 return get_rxmem(precvframe);
324 static inline u8 *get_recvframe_data(struct recv_frame *precvframe)
326 /* always return rx_data */
327 if (precvframe == NULL)
330 return precvframe->rx_data;
333 static inline u8 *recvframe_push(struct recv_frame *precvframe, int sz)
335 /* append data before rx_data */
337 /* add data to the start of recv_frame
339 * This function extends the used data area of the recv_frame at the buffer
340 * start. rx_data must be still larger than rx_head, after pushing.
342 if (precvframe == NULL)
344 precvframe->rx_data -= sz;
345 if (precvframe->rx_data < precvframe->rx_head) {
346 precvframe->rx_data += sz;
349 precvframe->len += sz;
350 return precvframe->rx_data;
353 static inline u8 *recvframe_pull(struct recv_frame *precvframe, int sz)
355 /* rx_data += sz; move rx_data sz bytes hereafter */
357 /* used for extract sz bytes from rx_data, update rx_data and return
358 * the updated rx_data to the caller */
360 if (precvframe == NULL)
362 precvframe->rx_data += sz;
363 if (precvframe->rx_data > precvframe->rx_tail) {
364 precvframe->rx_data -= sz;
367 precvframe->len -= sz;
368 return precvframe->rx_data;
371 static inline u8 *recvframe_put(struct recv_frame *precvframe, int sz)
373 /* used for append sz bytes from ptr to rx_tail, update rx_tail
374 * and return the updated rx_tail to the caller */
375 /* after putting, rx_tail must be still larger than rx_end. */
377 if (precvframe == NULL)
380 precvframe->rx_tail += sz;
382 if (precvframe->rx_tail > precvframe->rx_end) {
383 precvframe->rx_tail -= sz;
386 precvframe->len += sz;
387 return precvframe->rx_tail;
390 static inline u8 *recvframe_pull_tail(struct recv_frame *precvframe, int sz)
392 /* rmv data from rx_tail (by yitsen) */
394 /* used for extract sz bytes from rx_end, update rx_end and return
395 * the updated rx_end to the caller */
396 /* after pulling, rx_end must be still larger than rx_data. */
398 if (precvframe == NULL)
400 precvframe->rx_tail -= sz;
401 if (precvframe->rx_tail < precvframe->rx_data) {
402 precvframe->rx_tail += sz;
405 precvframe->len -= sz;
406 return precvframe->rx_tail;
409 static inline int get_recvframe_len(struct recv_frame *precvframe)
411 return precvframe->len;
414 static inline s32 translate_percentage_to_dbm(u32 sig_stren_index)
416 s32 power; /* in dBm. */
418 /* Translate to dBm (x=0.5y-95). */
419 power = (s32)((sig_stren_index + 1) >> 1);
428 void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
430 void mgt_dispatcher(struct adapter *padapter, struct recv_frame *precv_frame);