1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2010 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  * Modifications for inclusion into the Linux staging tree are
19  * Copyright(c) 2010 Larry Finger. All rights reserved.
20  *
21  * Contact information:
22  * WLAN FAE <wlanfae@realtek.com>
23  * Larry Finger <Larry.Finger@lwfinger.net>
24  *
25  ******************************************************************************/
26 #ifndef _RTL8712_RECV_H_
27 #define _RTL8712_RECV_H_
28 
29 #include "osdep_service.h"
30 #include "drv_types.h"
31 
32 /* Realtek's v2.6.6 reduced this to 4. However, under heavy network and CPU
33  * loads, even 8 receive buffers might not be enough; cutting it to 4 seemed
34  * unwise.
35  */
36 #define NR_RECVBUFF (8)
37 
38 #define NR_PREALLOC_RECV_SKB (8)
39 #define RXDESC_SIZE	24
40 #define RXDESC_OFFSET RXDESC_SIZE
41 #define RECV_BLK_SZ 512
42 #define RECV_BLK_CNT 16
43 #define RECV_BLK_TH RECV_BLK_CNT
44 #define MAX_RECVBUF_SZ 9100
45 #define RECVBUFF_ALIGN_SZ 512
46 #define RSVD_ROOM_SZ (0)
47 /*These definition is used for Rx packet reordering.*/
48 #define SN_LESS(a, b)		(((a-b) & 0x800) != 0)
49 #define SN_EQUAL(a, b)	(a == b)
50 #define REORDER_WAIT_TIME	30 /* (ms)*/
51 
52 struct recv_stat {
53 	unsigned int rxdw0;
54 	unsigned int rxdw1;
55 	unsigned int rxdw2;
56 	unsigned int rxdw3;
57 	unsigned int rxdw4;
58 	unsigned int rxdw5;
59 };
60 
61 struct phy_cck_rx_status {
62 	/* For CCK rate descriptor. This is a unsigned 8:1 variable.
63 	 * LSB bit present 0.5. And MSB 7 bts present a signed value.
64 	 * Range from -64~+63.5.
65 	 */
66 	u8	adc_pwdb_X[4];
67 	u8	sq_rpt;
68 	u8	cck_agc_rpt;
69 };
70 
71 struct phy_stat {
72 	unsigned int phydw0;
73 	unsigned int phydw1;
74 	unsigned int phydw2;
75 	unsigned int phydw3;
76 	unsigned int phydw4;
77 	unsigned int phydw5;
78 	unsigned int phydw6;
79 	unsigned int phydw7;
80 };
81 #define PHY_STAT_GAIN_TRSW_SHT 0
82 #define PHY_STAT_PWDB_ALL_SHT 4
83 #define PHY_STAT_CFOSHO_SHT 5
84 #define PHY_STAT_CCK_AGC_RPT_SHT 5
85 #define PHY_STAT_CFOTAIL_SHT 9
86 #define PHY_STAT_RXEVM_SHT 13
87 #define PHY_STAT_RXSNR_SHT 15
88 #define PHY_STAT_PDSNR_SHT 19
89 #define PHY_STAT_CSI_CURRENT_SHT 21
90 #define PHY_STAT_CSI_TARGET_SHT 23
91 #define PHY_STAT_SIGEVM_SHT 25
92 #define PHY_STAT_MAX_EX_PWR_SHT 26
93 
94 union recvstat {
95 	struct recv_stat recv_stat;
96 	unsigned int value[RXDESC_SIZE>>2];
97 };
98 
99 
100 struct recv_buf {
101 	struct list_head list;
102 	spinlock_t recvbuf_lock;
103 	u32	ref_cnt;
104 	struct _adapter  *adapter;
105 	struct urb *purb;
106 	_pkt *pskb;
107 	u8  irp_pending;
108 	u32  transfer_len;
109 	uint  len;
110 	u8 *phead;
111 	u8 *pdata;
112 	u8 *ptail;
113 	u8 *pend;
114 	u8 *pbuf;
115 	u8 *pallocated_buf;
116 };
117 
118 /*
119  *	head  ----->
120  *		data  ----->
121  *			payload
122  *		tail  ----->
123  *	end   ----->
124  *	len = (unsigned int )(tail - data);
125  */
126 struct recv_frame_hdr {
127 	struct list_head list;
128 	_pkt	*pkt;
129 	_pkt *pkt_newalloc;
130 	struct _adapter  *adapter;
131 	u8 fragcnt;
132 	struct rx_pkt_attrib attrib;
133 	uint  len;
134 	u8 *rx_head;
135 	u8 *rx_data;
136 	u8 *rx_tail;
137 	u8 *rx_end;
138 	void *precvbuf;
139 	struct sta_info *psta;
140 	/*for A-MPDU Rx reordering buffer control*/
141 	struct recv_reorder_ctrl *preorder_ctrl;
142 };
143 
144 union recv_frame {
145 	union {
146 		struct list_head list;
147 		struct recv_frame_hdr hdr;
148 	} u;
149 };
150 
151 int r8712_init_recvbuf(struct _adapter *padapter, struct recv_buf *precvbuf);
152 void r8712_rxcmd_event_hdl(struct _adapter *padapter, void *prxcmdbuf);
153 s32 r8712_signal_scale_mapping(s32 cur_sig);
154 void r8712_reordering_ctrl_timeout_handler(void *pcontext);
155 
156 #endif
157 
158