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 (30720) /* 30K */
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 	u8	adc_pwdb_X[4];
66 	u8	sq_rpt;
67 	u8	cck_agc_rpt;
68 };
69 
70 struct phy_stat {
71 	unsigned int phydw0;
72 	unsigned int phydw1;
73 	unsigned int phydw2;
74 	unsigned int phydw3;
75 	unsigned int phydw4;
76 	unsigned int phydw5;
77 	unsigned int phydw6;
78 	unsigned int phydw7;
79 };
80 #define PHY_STAT_GAIN_TRSW_SHT 0
81 #define PHY_STAT_PWDB_ALL_SHT 4
82 #define PHY_STAT_CFOSHO_SHT 5
83 #define PHY_STAT_CCK_AGC_RPT_SHT 5
84 #define PHY_STAT_CFOTAIL_SHT 9
85 #define PHY_STAT_RXEVM_SHT 13
86 #define PHY_STAT_RXSNR_SHT 15
87 #define PHY_STAT_PDSNR_SHT 19
88 #define PHY_STAT_CSI_CURRENT_SHT 21
89 #define PHY_STAT_CSI_TARGET_SHT 23
90 #define PHY_STAT_SIGEVM_SHT 25
91 #define PHY_STAT_MAX_EX_PWR_SHT 26
92 
93 union recvstat {
94 	struct recv_stat recv_stat;
95 	unsigned int value[RXDESC_SIZE>>2];
96 };
97 
98 
99 struct recv_buf {
100 	struct list_head list;
101 	spinlock_t recvbuf_lock;
102 	u32	ref_cnt;
103 	struct _adapter  *adapter;
104 	struct urb *purb;
105 	_pkt *pskb;
106 	u8 reuse;
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