OSDN Git Service

9756e2913e234844f1fd5571665c3aa181d4ad73
[android-x86/external-modules-rtl8723au.git] / include / rtw_recv.h
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  *
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
17  *
18  *
19  ******************************************************************************/
20 #ifndef _RTW_RECV_H_
21 #define _RTW_RECV_H_
22
23 #include <drv_conf.h>
24 #include <osdep_service.h>
25 #include <drv_types.h>
26
27
28 #define NR_RECVFRAME 256
29
30 #define RXFRAME_ALIGN   8
31 #define RXFRAME_ALIGN_SZ        (1<<RXFRAME_ALIGN)
32
33 #define MAX_RXFRAME_CNT 512
34 #define MAX_RX_NUMBLKS          (32)
35 #define RECVFRAME_HDR_ALIGN 128
36
37 #define SNAP_SIZE sizeof(struct ieee80211_snap_hdr)
38
39 static u8 SNAP_ETH_TYPE_IPX[2] = {0x81, 0x37};
40
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
45
46 static u8 oui_8021h[] = {0x00, 0x00, 0xf8};
47 static u8 oui_rfc1042[]= {0x00,0x00,0x00};
48
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 };
55
56 //for Rx reordering buffer control
57 struct recv_reorder_ctrl
58 {
59         _adapter        *padapter;
60         u8 enable;
61         u16 indicate_seq;//=wstart_b, init_value=0xffff
62         u16 wend_b;
63         u8 wsize_b;
64         _queue pending_recvframe_queue;
65         _timer reordering_ctrl_timer;
66 };
67
68 struct  stainfo_rxcache {
69         u16     tid_rxseq[16];
70 /*
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;
87 */
88 };
89
90
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
96 };
97
98 struct signal_stat {
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
103 };
104 #define MAX_PATH_NUM_92CS               2
105 struct phy_info //ODM_PHY_INFO_T
106 {
107         u8              RxPWDBAll;
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
118 //#endif
119 };
120
121
122 struct rx_pkt_attrib    {
123         u16     pkt_len;
124         u8      physt;
125         u8      drvinfo_sz;
126         u8      shift_sz;
127         u8      hdrlen; //the WLAN Header Len
128         u8      to_fr_ds;
129         u8      amsdu;
130         u8      qos;
131         u8      priority;
132         u8      pw_save;
133         u8      mdata;
134         u16     seq_num;
135         u8      frag_num;
136         u8      mfrag;
137         u8      order;
138         u8      privacy; //in frame_ctrl field
139         u8      bdecrypted;
140         u8      encrypt; //when 0 indicate no encrypt. when non-zero, indicate the encrypt algorith
141         u8      iv_len;
142         u8      icv_len;
143         u8      crc_err;
144         u8      icv_err;
145
146         u16 eth_type;
147
148         u8      dst[ETH_ALEN];
149         u8      src[ETH_ALEN];
150         u8      ta[ETH_ALEN];
151         u8      ra[ETH_ALEN];
152         u8      bssid[ETH_ALEN];
153
154         u8 ack_policy;
155
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
160 //#endif
161         u8      key_index;
162
163         u8      mcs_rate;
164         u8      rxht;
165         u8      sgi;
166         u8      pkt_rpt_type;
167         u32     MacIDValidEntry[2];     // 64 bits present 64 entry.
168
169 /*
170         u8      signal_qual;
171         s8      rx_mimo_signal_qual[2];
172         u8      signal_strength;
173         u32     RxPWDBAll;
174         s32     RecvSignalPower;
175 */
176         struct phy_info phy_info;
177 };
178
179
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)
186
187 #define RECVBUFF_ALIGN_SZ 8
188
189 #define RXDESC_SIZE     24
190 #define RXDESC_OFFSET RXDESC_SIZE
191
192 struct recv_stat
193 {
194         unsigned int rxdw0;
195
196         unsigned int rxdw1;
197
198         unsigned int rxdw2;
199
200         unsigned int rxdw3;
201
202         unsigned int rxdw4;
203
204         unsigned int rxdw5;
205 };
206
207 #define EOR BIT(30)
208
209 /*
210 accesser of recv_priv: rtw_recv_entry(dispatch / passive level); recv_thread(passive) ; returnpkt(dispatch)
211 ; halt(passive) ;
212
213 using enter_critical section to protect
214 */
215 struct recv_priv
216 {
217         spinlock_t      lock;
218
219 #ifdef CONFIG_RECV_THREAD_MODE
220         struct semaphore        recv_sema;
221         struct semaphore        terminate_recvthread_sema;
222 #endif
223
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;
228
229
230         u8 *pallocated_frame_buf;
231         u8 *precv_frame_buf;
232
233         uint free_recvframe_cnt;
234
235         _adapter        *adapter;
236
237         u32     bIsAnyNonBEPkts;
238         u64     rx_bytes;
239         u64     rx_pkts;
240         u64     rx_drop;
241         u64     last_rx_bytes;
242
243         uint  rx_icv_err;
244         uint  rx_largepacket_crcerr;
245         uint  rx_smallpacket_crcerr;
246         uint  rx_middlepacket_crcerr;
247
248 #ifdef CONFIG_USB_HCI
249         //u8 *pallocated_urb_buf;
250         struct semaphore allrxreturnevt;
251         uint    ff_hwaddr;
252         u8      rx_pending_cnt;
253
254 #ifdef CONFIG_USB_INTERRUPT_IN_PIPE
255         PURB    int_in_urb;
256
257         u8      *int_in_buf;
258 #endif //CONFIG_USB_INTERRUPT_IN_PIPE
259
260 #endif
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
269
270 #ifdef CONFIG_USE_USB_BUFFER_ALLOC_RX
271         _queue  recv_buf_pending_queue;
272 #endif  // CONFIG_USE_USB_BUFFER_ALLOC_RX
273
274         u8 *pallocated_recv_buf;
275         u8 *precv_buf;    // 4 alignment
276         _queue  free_recv_buf_queue;
277         u32     free_recv_buf_queue_cnt;
278
279 #if defined(CONFIG_GSPI_HCI)
280         _queue  recv_buf_pending_queue;
281 #endif
282
283         //For display the phy informatiom
284         u8 is_signal_dbg;       // for debug
285         u8 signal_strength_dbg; // for debug
286         s8 rssi;
287         s8 rxpwdb;
288         u8 signal_strength;
289         u8 signal_qual;
290         u8 noise;
291         int RxSNRdB[2];
292         s8 RxRssi[2];
293         int FalseAlmCnt_all;
294
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
305
306 };
307
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
311
312 struct sta_recv_priv {
313
314         spinlock_t      lock;
315         int     option;
316
317         //_queue        blk_strms[MAX_RX_NUMBLKS];
318         _queue defrag_q;         //keeping the fragment frame until defrag
319
320         struct  stainfo_rxcache rxcache;
321
322         //uint  sta_rx_bytes;
323         //uint  sta_rx_pkts;
324         //uint  sta_rx_fail;
325
326 };
327
328
329 struct recv_buf
330 {
331         _list list;
332
333         spinlock_t recvbuf_lock;
334
335         u32     ref_cnt;
336
337         PADAPTER adapter;
338
339         u8      *pbuf;
340         u8      *pallocated_buf;
341
342         u32     len;
343         u8      *phead;
344         u8      *pdata;
345         u8      *ptail;
346         u8      *pend;
347
348 #ifdef CONFIG_USB_HCI
349
350         PURB    purb;
351         dma_addr_t dma_transfer_addr;   /* (in) dma addr for transfer_buffer */
352         u32 alloc_sz;
353
354         u8  irp_pending;
355         int  transfer_len;
356 #endif
357
358         _pkt    *pskb;
359         u8      reuse;
360 };
361
362
363 /*
364         head  ----->
365
366                 data  ----->
367
368                         payload
369
370                 tail  ----->
371
372
373         end   ----->
374
375         len = (unsigned int )(tail - data);
376
377 */
378 struct recv_frame_hdr
379 {
380         _list   list;
381 #ifndef CONFIG_BSD_RX_USE_MBUF
382         struct sk_buff   *pkt;
383         struct sk_buff   *pkt_newalloc;
384 #else // CONFIG_BSD_RX_USE_MBUF
385         _pkt    *pkt;
386         _pkt *pkt_newalloc;
387 #endif // CONFIG_BSD_RX_USE_MBUF
388
389         _adapter  *adapter;
390
391         u8 fragcnt;
392
393         int frame_tag;
394
395         struct rx_pkt_attrib attrib;
396
397         uint  len;
398         u8 *rx_head;
399         u8 *rx_data;
400         u8 *rx_tail;
401         u8 *rx_end;
402
403         void *precvbuf;
404
405
406         //
407         struct sta_info *psta;
408
409         //for A-MPDU Rx reordering buffer control
410         struct recv_reorder_ctrl *preorder_ctrl;
411
412 #ifdef CONFIG_WAPI_SUPPORT
413         u8 UserPriority;
414         u8 WapiTempPN[16];
415         u8 WapiSrcAddr[6];
416         u8 bWapiCheckPNInDecrypt;
417         u8 bIsWaiPacket;
418 #endif
419
420 };
421
422
423 union recv_frame{
424
425         union{
426                 _list list;
427                 struct recv_frame_hdr hdr;
428                 uint mem[RECVFRAME_HDR_ALIGN>>2];
429         }u;
430
431         //uint mem[MAX_RXSZ>>2];
432
433 };
434
435
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);
440
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);
444
445 extern void rtw_free_recvframe_queue(_queue *pframequeue,  _queue *pfree_recv_queue);
446 u32 rtw_free_uc_swdec_pending_queue(_adapter *adapter);
447
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);
451
452 void rtw_reordering_ctrl_timeout_handler(void *pcontext);
453
454 __inline static u8 *get_rxmem(union recv_frame *precvframe)
455 {
456         //always return rx_head...
457         if(precvframe==NULL)
458                 return NULL;
459
460         return precvframe->u.hdr.rx_head;
461 }
462
463 __inline static u8 *get_rx_status(union recv_frame *precvframe)
464 {
465
466         return get_rxmem(precvframe);
467
468 }
469
470 __inline static u8 *get_recvframe_data(union recv_frame *precvframe)
471 {
472
473         //alwasy return rx_data
474         if(precvframe==NULL)
475                 return NULL;
476
477         return precvframe->u.hdr.rx_data;
478
479 }
480
481 __inline static u8 *recvframe_push(union recv_frame *precvframe, int sz)
482 {
483         // append data before rx_data
484
485         /* add data to the start of recv_frame
486  *
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.
489  */
490
491         if(precvframe==NULL)
492                 return NULL;
493
494
495         precvframe->u.hdr.rx_data -= sz ;
496         if( precvframe->u.hdr.rx_data < precvframe->u.hdr.rx_head )
497         {
498                 precvframe->u.hdr.rx_data += sz ;
499                 return NULL;
500         }
501
502         precvframe->u.hdr.len +=sz;
503
504         return precvframe->u.hdr.rx_data;
505
506 }
507
508
509 __inline static u8 *recvframe_pull(union recv_frame *precvframe, int sz)
510 {
511         // rx_data += sz; move rx_data sz bytes  hereafter
512
513         //used for extract sz bytes from rx_data, update rx_data and return the updated rx_data to the caller
514
515
516         if(precvframe==NULL)
517                 return NULL;
518
519
520         precvframe->u.hdr.rx_data += sz;
521
522         if(precvframe->u.hdr.rx_data > precvframe->u.hdr.rx_tail)
523         {
524                 precvframe->u.hdr.rx_data -= sz;
525                 return NULL;
526         }
527
528         precvframe->u.hdr.len -=sz;
529
530         return precvframe->u.hdr.rx_data;
531
532 }
533
534 __inline static u8 *recvframe_put(union recv_frame *precvframe, int sz)
535 {
536         // rx_tai += sz; move rx_tail sz bytes  hereafter
537
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;
541
542         if(precvframe==NULL)
543                 return NULL;
544
545         prev_rx_tail = precvframe->u.hdr.rx_tail;
546
547         precvframe->u.hdr.rx_tail += sz;
548
549         if(precvframe->u.hdr.rx_tail > precvframe->u.hdr.rx_end)
550         {
551                 precvframe->u.hdr.rx_tail -= sz;
552                 return NULL;
553         }
554
555         precvframe->u.hdr.len +=sz;
556
557         return precvframe->u.hdr.rx_tail;
558
559 }
560
561
562
563 __inline static u8 *recvframe_pull_tail(union recv_frame *precvframe, int sz)
564 {
565         // rmv data from rx_tail (by yitsen)
566
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.
569
570         if(precvframe==NULL)
571                 return NULL;
572
573         precvframe->u.hdr.rx_tail -= sz;
574
575         if(precvframe->u.hdr.rx_tail < precvframe->u.hdr.rx_data)
576         {
577                 precvframe->u.hdr.rx_tail += sz;
578                 return NULL;
579         }
580
581         precvframe->u.hdr.len -=sz;
582
583         return precvframe->u.hdr.rx_tail;
584
585 }
586
587
588
589 __inline static _buffer * get_rxbuf_desc(union recv_frame *precvframe)
590 {
591         _buffer * buf_desc;
592
593         if(precvframe==NULL)
594                 return NULL;
595
596         return buf_desc;
597 }
598
599
600 __inline static union recv_frame *rxmem_to_recvframe(u8 *rxmem)
601 {
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
605
606         return (union recv_frame*)(((unsigned long)rxmem >> RXFRAME_ALIGN) << RXFRAME_ALIGN);
607
608 }
609
610 __inline static union recv_frame *pkt_to_recvframe(_pkt *pkt)
611 {
612
613         u8 * buf_star;
614         union recv_frame * precv_frame;
615         precv_frame = rxmem_to_recvframe((unsigned char*)buf_star);
616
617         return precv_frame;
618 }
619
620 __inline static u8 *pkt_to_recvmem(_pkt *pkt)
621 {
622         // return the rx_head
623
624         union recv_frame * precv_frame = pkt_to_recvframe(pkt);
625
626         return  precv_frame->u.hdr.rx_head;
627
628 }
629
630 __inline static u8 *pkt_to_recvdata(_pkt *pkt)
631 {
632         // return the rx_data
633
634         union recv_frame * precv_frame =pkt_to_recvframe(pkt);
635
636         return  precv_frame->u.hdr.rx_data;
637
638 }
639
640
641 __inline static int get_recvframe_len(union recv_frame *precvframe)
642 {
643         return precvframe->u.hdr.len;
644 }
645
646
647 __inline static s32 translate_percentage_to_dbm(u32 SignalStrengthIndex)
648 {
649         s32     SignalPower; // in dBm.
650
651         // Translate to dBm (x=0.5y-95).
652         SignalPower = (s32)((SignalStrengthIndex + 1) >> 1);
653         SignalPower -= 95;
654
655         return SignalPower;
656 }
657
658
659 struct sta_info;
660
661 extern void _rtw_init_sta_recv_priv(struct sta_recv_priv *psta_recvpriv);
662
663 extern void  mgt_dispatcher(_adapter *padapter, union recv_frame *precv_frame);
664
665 #endif