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 ******************************************************************************/
24 #include <osdep_service.h>
25 #include <drv_types.h>
28 #define NR_RECVFRAME 256
30 #define RXFRAME_ALIGN 8
31 #define RXFRAME_ALIGN_SZ (1<<RXFRAME_ALIGN)
33 #define MAX_RXFRAME_CNT 512
34 #define MAX_RX_NUMBLKS (32)
35 #define RECVFRAME_HDR_ALIGN 128
37 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
39 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
41 static u8 SNAP_ETH_TYPE_APPLETALK_AARP[2] = {0x80, 0xf3};
42 static u8 SNAP_ETH_TYPE_APPLETALK_DDP[2] = {0x80, 0x9b};
43 static u8 SNAP_ETH_TYPE_TDLS[2] = {0x89, 0x0d};
44 static u8 SNAP_HDR_APPLETALK_DDP[3] = {0x08, 0x00, 0x07}; // Datagram Delivery Protocol
46 static u8 oui_8021h[] = {0x00, 0x00, 0xf8};
47 static u8 oui_rfc1042[]= {0x00,0x00,0x00};
49 #define MAX_SUBFRAME_COUNT 64
50 static u8 rtw_rfc1042_header[] =
51 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0x00 };
52 /* Bridge-Tunnel header (for EtherTypes ETH_P_AARP and ETH_P_IPX) */
53 static u8 rtw_bridge_tunnel_header[] =
54 { 0xaa, 0xaa, 0x03, 0x00, 0x00, 0xf8 };
56 //for Rx reordering buffer control
57 struct recv_reorder_ctrl
61 u16 indicate_seq;//=wstart_b, init_value=0xffff
64 _queue pending_recvframe_queue;
65 _timer reordering_ctrl_timer;
68 struct stainfo_rxcache {
71 unsigned short tid0_rxseq;
72 unsigned short tid1_rxseq;
73 unsigned short tid2_rxseq;
74 unsigned short tid3_rxseq;
75 unsigned short tid4_rxseq;
76 unsigned short tid5_rxseq;
77 unsigned short tid6_rxseq;
78 unsigned short tid7_rxseq;
79 unsigned short tid8_rxseq;
80 unsigned short tid9_rxseq;
81 unsigned short tid10_rxseq;
82 unsigned short tid11_rxseq;
83 unsigned short tid12_rxseq;
84 unsigned short tid13_rxseq;
85 unsigned short tid14_rxseq;
86 unsigned short tid15_rxseq;
91 struct smooth_rssi_data {
92 u32 elements[100]; //array to store values
93 u32 index; //index to current array to store
94 u32 total_num; //num of valid elements
95 u32 total_val; //sum of valid elements
99 u8 update_req; //used to indicate
100 u8 avg_val; //avg of valid elements
101 u32 total_num; //num of valid elements
102 u32 total_val; //sum of valid elements
104 #define MAX_PATH_NUM_92CS 2
105 struct phy_info //ODM_PHY_INFO_T
108 u8 SignalQuality; // in 0-100 index.
109 u8 RxMIMOSignalQuality[MAX_PATH_NUM_92CS]; //EVM
110 u8 RxMIMOSignalStrength[MAX_PATH_NUM_92CS];// in 0~100 index
111 //#if (DM_ODM_SUPPORT_TYPE & (ODM_MP|ODM_CE))
112 s8 RxPower; // in dBm Translate from PWdB
113 s8 RecvSignalPower;// Real power in dBm for this packet, no beautification and aggregation. Keep this raw info to be used for the other procedures.
114 u8 BTRxRSSIPercentage;
115 u8 SignalStrength; // in 0-100 index.
116 u8 RxPwr[MAX_PATH_NUM_92CS];//per-path's pwdb
117 u8 RxSNR[MAX_PATH_NUM_92CS];//per-path's SNR
122 struct rx_pkt_attrib {
127 u8 hdrlen; //the WLAN Header Len
138 u8 privacy; //in frame_ctrl field
140 u8 encrypt; //when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith
156 //#ifdef CONFIG_TCP_CSUM_OFFLOAD_RX
157 u8 tcpchk_valid; // 0: invalid, 1: valid
158 u8 ip_chkrpt; //0: incorrect, 1: correct
159 u8 tcp_chkrpt; //0: incorrect, 1: correct
167 u32 MacIDValidEntry[2]; // 64 bits present 64 entry.
171 s8 rx_mimo_signal_qual[2];
176 struct phy_info phy_info;
180 //These definition is used for Rx packet reordering.
181 #define SN_LESS(a, b) (((a-b)&0x800)!=0)
182 #define SN_EQUAL(a, b) (a == b)
183 //#define REORDER_WIN_SIZE 128
184 //#define REORDER_ENTRY_NUM 128
185 #define REORDER_WAIT_TIME (50) // (ms)
187 #define RECVBUFF_ALIGN_SZ 8
189 #define RXDESC_SIZE 24
190 #define RXDESC_OFFSET RXDESC_SIZE
210 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
213 using enter_critical section to protect
219 #ifdef CONFIG_RECV_THREAD_MODE
220 struct semaphore recv_sema;
221 struct semaphore terminate_recvthread_sema;
224 //_queue blk_strms[MAX_RX_NUMBLKS]; // keeping the block ack frame until return ack
225 _queue free_recv_queue;
226 _queue recv_pending_queue;
227 _queue uc_swdec_pending_queue;
230 u8 *pallocated_frame_buf;
233 uint free_recvframe_cnt;
244 uint rx_largepacket_crcerr;
245 uint rx_smallpacket_crcerr;
246 uint rx_middlepacket_crcerr;
248 #ifdef CONFIG_USB_HCI
249 //u8 *pallocated_urb_buf;
250 struct semaphore allrxreturnevt;
254 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
258 #endif //CONFIG_USB_INTERRUPT_IN_PIPE
261 struct tasklet_struct irq_prepare_beacon_tasklet;
262 struct tasklet_struct recv_tasklet;
263 struct sk_buff_head free_recv_skb_queue;
264 struct sk_buff_head rx_skb_queue;
265 #ifdef CONFIG_RX_INDICATE_QUEUE
266 struct task rx_indicate_tasklet;
267 struct ifqueue rx_indicate_queue;
268 #endif // CONFIG_RX_INDICATE_QUEUE
270 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
271 _queue recv_buf_pending_queue;
272 #endif // CONFIG_USE_USB_BUFFER_ALLOC_RX
274 u8 *pallocated_recv_buf;
275 u8 *precv_buf; // 4 alignment
276 _queue free_recv_buf_queue;
277 u32 free_recv_buf_queue_cnt;
279 #if defined(CONFIG_GSPI_HCI)
280 _queue recv_buf_pending_queue;
283 //For display the phy informatiom
284 u8 is_signal_dbg; // for debug
285 u8 signal_strength_dbg; // for debug
295 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
296 _timer signal_stat_timer;
297 u32 signal_stat_sampling_interval;
298 //u32 signal_stat_converging_constant;
299 struct signal_stat signal_qual_data;
300 struct signal_stat signal_strength_data;
301 #else //CONFIG_NEW_SIGNAL_STAT_PROCESS
302 struct smooth_rssi_data signal_qual_data;
303 struct smooth_rssi_data signal_strength_data;
304 #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
308 #ifdef CONFIG_NEW_SIGNAL_STAT_PROCESS
309 #define rtw_set_signal_stat_timer(recvpriv) _set_timer(&(recvpriv)->signal_stat_timer, (recvpriv)->signal_stat_sampling_interval)
310 #endif //CONFIG_NEW_SIGNAL_STAT_PROCESS
312 struct sta_recv_priv {
317 //_queue blk_strms[MAX_RX_NUMBLKS];
318 _queue defrag_q; //keeping the fragment frame until defrag
320 struct stainfo_rxcache rxcache;
333 spinlock_t recvbuf_lock;
348 #ifdef CONFIG_USB_HCI
351 dma_addr_t dma_transfer_addr; /* (in) dma addr for transfer_buffer */
375 len = (unsigned int )(tail - data);
378 struct recv_frame_hdr
381 #ifndef CONFIG_BSD_RX_USE_MBUF
383 struct sk_buff *pkt_newalloc;
384 #else // CONFIG_BSD_RX_USE_MBUF
387 #endif // CONFIG_BSD_RX_USE_MBUF
395 struct rx_pkt_attrib attrib;
407 struct sta_info *psta;
409 //for A-MPDU Rx reordering buffer control
410 struct recv_reorder_ctrl *preorder_ctrl;
412 #ifdef CONFIG_WAPI_SUPPORT
416 u8 bWapiCheckPNInDecrypt;
427 struct recv_frame_hdr hdr;
428 uint mem[RECVFRAME_HDR_ALIGN>>2];
431 //uint mem[MAX_RXSZ>>2];
436 extern union recv_frame *_rtw_alloc_recvframe (_queue *pfree_recv_queue); //get a free recv_frame from pfree_recv_queue
437 extern union recv_frame *rtw_alloc_recvframe (_queue *pfree_recv_queue); //get a free recv_frame from pfree_recv_queue
438 extern void rtw_init_recvframe(union recv_frame *precvframe ,struct recv_priv *precvpriv);
439 extern int rtw_free_recvframe(union recv_frame *precvframe, _queue *pfree_recv_queue);
441 #define rtw_dequeue_recvframe(queue) rtw_alloc_recvframe(queue)
442 extern int _rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
443 extern int rtw_enqueue_recvframe(union recv_frame *precvframe, _queue *queue);
445 extern void rtw_free_recvframe_queue(_queue *pframequeue, _queue *pfree_recv_queue);
446 u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter);
448 int rtw_enqueue_recvbuf_to_head(struct recv_buf *precvbuf, _queue *queue);
449 int rtw_enqueue_recvbuf(struct recv_buf *precvbuf, _queue *queue);
450 struct recv_buf *rtw_dequeue_recvbuf (_queue *queue);
452 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
454 __inline static u8 *get_rxmem(union recv_frame *precvframe)
456 //always return rx_head...
460 return precvframe->u.hdr.rx_head;
463 __inline static u8 *get_rx_status(union recv_frame *precvframe)
466 return get_rxmem(precvframe);
470 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
473 //alwasy return rx_data
477 return precvframe->u.hdr.rx_data;
481 __inline static u8 *recvframe_push(union recv_frame *precvframe, int sz)
483 // append data before rx_data
485 /* add data to the start of recv_frame
487 * This function extends the used data area of the recv_frame at the buffer
488 * start. rx_data must be still larger than rx_head, after pushing.
495 precvframe->u.hdr.rx_data -= sz ;
496 if( precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head )
498 precvframe->u.hdr.rx_data += sz ;
502 precvframe->u.hdr.len +=sz;
504 return precvframe->u.hdr.rx_data;
509 __inline static u8 *recvframe_pull(union recv_frame *precvframe, int sz)
511 // rx_data += sz; move rx_data sz bytes hereafter
513 //used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller
520 precvframe->u.hdr.rx_data += sz;
522 if(precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail)
524 precvframe->u.hdr.rx_data -= sz;
528 precvframe->u.hdr.len -=sz;
530 return precvframe->u.hdr.rx_data;
534 __inline static u8 *recvframe_put(union recv_frame *precvframe, int sz)
536 // rx_tai += sz; move rx_tail sz bytes hereafter
538 //used for append sz bytes from ptr to rx_tail, update rx_tail and return the updated rx_tail to the caller
539 //after putting, rx_tail must be still larger than rx_end.
540 unsigned char * prev_rx_tail;
545 prev_rx_tail = precvframe->u.hdr.rx_tail;
547 precvframe->u.hdr.rx_tail += sz;
549 if(precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end)
551 precvframe->u.hdr.rx_tail -= sz;
555 precvframe->u.hdr.len +=sz;
557 return precvframe->u.hdr.rx_tail;
563 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, int sz)
565 // rmv data from rx_tail (by yitsen)
567 //used for extract sz bytes from rx_end, update rx_end and return the updated rx_end to the caller
568 //after pulling, rx_end must be still larger than rx_data.
573 precvframe->u.hdr.rx_tail -= sz;
575 if(precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data)
577 precvframe->u.hdr.rx_tail += sz;
581 precvframe->u.hdr.len -=sz;
583 return precvframe->u.hdr.rx_tail;
589 __inline static _buffer * get_rxbuf_desc(union recv_frame *precvframe)
600 __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
602 //due to the design of 2048 bytes alignment of recv_frame, we can reference the union recv_frame
603 //from any given member of recv_frame.
604 // rxmem indicates the any member/address in recv_frame
606 return (union recv_frame*)(((unsigned long)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
610 __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt)
614 union recv_frame * precv_frame;
615 precv_frame = rxmem_to_recvframe((unsigned char*)buf_star);
620 __inline static u8 *pkt_to_recvmem(_pkt *pkt)
622 // return the rx_head
624 union recv_frame * precv_frame = pkt_to_recvframe(pkt);
626 return precv_frame->u.hdr.rx_head;
630 __inline static u8 *pkt_to_recvdata(_pkt *pkt)
632 // return the rx_data
634 union recv_frame * precv_frame =pkt_to_recvframe(pkt);
636 return precv_frame->u.hdr.rx_data;
641 __inline static int get_recvframe_len(union recv_frame *precvframe)
643 return precvframe->u.hdr.len;
647 __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
649 s32 SignalPower; // in dBm.
651 // Translate to dBm (x=0.5y-95).
652 SignalPower = (s32)((SignalStrengthIndex + 1) >> 1);
661 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
663 extern void mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);