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 __RTL871X_MP_H_
27 #define __RTL871X_MP_H_
28 
29 #define MPT_NOOP			0
30 #define MPT_READ_MAC_1BYTE		1
31 #define MPT_READ_MAC_2BYTE		2
32 #define MPT_READ_MAC_4BYTE		3
33 #define MPT_WRITE_MAC_1BYTE		4
34 #define MPT_WRITE_MAC_2BYTE		5
35 #define MPT_WRITE_MAC_4BYTE		6
36 #define MPT_READ_BB_CCK			7
37 #define MPT_WRITE_BB_CCK		8
38 #define MPT_READ_BB_OFDM		9
39 #define MPT_WRITE_BB_OFDM		10
40 #define MPT_READ_RF			11
41 #define MPT_WRITE_RF			12
42 #define MPT_READ_EEPROM_1BYTE		13
43 #define MPT_WRITE_EEPROM_1BYTE		14
44 #define MPT_READ_EEPROM_2BYTE		15
45 #define MPT_WRITE_EEPROM_2BYTE		16
46 #define MPT_SET_CSTHRESHOLD		21
47 #define MPT_SET_INITGAIN		22
48 #define MPT_SWITCH_BAND			23
49 #define MPT_SWITCH_CHANNEL		24
50 #define MPT_SET_DATARATE		25
51 #define MPT_SWITCH_ANTENNA		26
52 #define MPT_SET_TX_POWER		27
53 #define MPT_SET_CONT_TX			28
54 #define MPT_SET_SINGLE_CARRIER		29
55 #define MPT_SET_CARRIER_SUPPRESSION	30
56 #define MPT_GET_RATE_TABLE		31
57 #define MPT_READ_TSSI			32
58 #define MPT_GET_THERMAL_METER		33
59 #define MAX_MP_XMITBUF_SZ	2048
60 #define NR_MP_XMITFRAME		8
61 
62 struct mp_xmit_frame {
63 	struct list_head list;
64 	struct pkt_attrib attrib;
65 	_pkt *pkt;
66 	int frame_tag;
67 	struct _adapter *padapter;
68 	u8 *mem_addr;
69 	u16 sz[8];
70 	struct urb *pxmit_urb[8];
71 	u8 bpending[8];
72 	u8 last[8];
73 };
74 
75 struct mp_wiparam {
76 	u32 bcompleted;
77 	u32 act_type;
78 	u32 io_offset;
79 	u32 io_value;
80 };
81 
82 struct mp_priv {
83 	struct _adapter *papdater;
84 	/*OID cmd handler*/
85 	struct mp_wiparam workparam;
86 	u8 act_in_progress;
87 	/*Tx Section*/
88 	u8 TID;
89 	u32 tx_pktcount;
90 	/*Rx Section*/
91 	u32 rx_pktcount;
92 	u32 rx_crcerrpktcount;
93 	u32 rx_pktloss;
94 	struct recv_stat rxstat;
95 	/*RF/BB relative*/
96 	u32 curr_ch;
97 	u32 curr_rateidx;
98 	u8 curr_bandwidth;
99 	u8 curr_modem;
100 	u8 curr_txpoweridx;
101 	u32 curr_crystalcap;
102 	u16 antenna_tx;
103 	u16 antenna_rx;
104 	u8 curr_rfpath;
105 	u8 check_mp_pkt;
106 	uint ForcedDataRate;
107 	struct wlan_network mp_network;
108 	unsigned char network_macaddr[6];
109 	/*Testing Flag*/
110 	u32 mode;/*0 for normal type packet,
111 		  * 1 for loopback packet (16bytes TXCMD)
112 		  */
113 	sint prev_fw_state;
114 	u8 *pallocated_mp_xmitframe_buf;
115 	u8 *pmp_xmtframe_buf;
116 	struct  __queue free_mp_xmitqueue;
117 	u32 free_mp_xmitframe_cnt;
118 };
119 
120 struct IOCMD_STRUCT {
121 	u8	cmdclass;
122 	u16	value;
123 	u8	index;
124 };
125 
126 struct rf_reg_param {
127 	u32 path;
128 	u32 offset;
129 	u32 value;
130 };
131 
132 struct bb_reg_param {
133 	u32 offset;
134 	u32 value;
135 };
136 /* ======================================================================= */
137 
138 #define LOWER	true
139 #define RAISE	false
140 #define IOCMD_CTRL_REG			0x10250370
141 #define IOCMD_DATA_REG			0x10250374
142 #define IOCMD_GET_THERMAL_METER		0xFD000028
143 #define IOCMD_CLASS_BB_RF		0xF0
144 #define IOCMD_BB_READ_IDX		0x00
145 #define IOCMD_BB_WRITE_IDX		0x01
146 #define IOCMD_RF_READ_IDX		0x02
147 #define IOCMD_RF_WRIT_IDX		0x03
148 #define BB_REG_BASE_ADDR		0x800
149 #define RF_PATH_A	0
150 #define RF_PATH_B	1
151 #define RF_PATH_C	2
152 #define RF_PATH_D	3
153 #define MAX_RF_PATH_NUMS	2
154 #define _2MAC_MODE_	0
155 #define _LOOPBOOK_MODE_	1
156 
157 /* MP set force data rate base on the definition. */
158 enum {
159 	/* CCK rate. */
160 	MPT_RATE_1M,	/* 0 */
161 	MPT_RATE_2M,
162 	MPT_RATE_55M,
163 	MPT_RATE_11M,	/* 3 */
164 
165 	/* OFDM rate. */
166 	MPT_RATE_6M,	/* 4 */
167 	MPT_RATE_9M,
168 	MPT_RATE_12M,
169 	MPT_RATE_18M,
170 	MPT_RATE_24M,
171 	MPT_RATE_36M,
172 	MPT_RATE_48M,
173 	MPT_RATE_54M,	/* 11 */
174 
175 	/* HT rate. */
176 	MPT_RATE_MCS0,	/* 12 */
177 	MPT_RATE_MCS1,
178 	MPT_RATE_MCS2,
179 	MPT_RATE_MCS3,
180 	MPT_RATE_MCS4,
181 	MPT_RATE_MCS5,
182 	MPT_RATE_MCS6,
183 	MPT_RATE_MCS7,	/* 19 */
184 	MPT_RATE_MCS8,
185 	MPT_RATE_MCS9,
186 	MPT_RATE_MCS10,
187 	MPT_RATE_MCS11,
188 	MPT_RATE_MCS12,
189 	MPT_RATE_MCS13,
190 	MPT_RATE_MCS14,
191 	MPT_RATE_MCS15,	/* 27 */
192 	MPT_RATE_LAST
193 };
194 
195 /* Represent Channel Width in HT Capabilities */
196 enum HT_CHANNEL_WIDTH {
197 	HT_CHANNEL_WIDTH_20 = 0,
198 	HT_CHANNEL_WIDTH_40 = 1,
199 };
200 
201 #define MAX_TX_PWR_INDEX_N_MODE 64	/* 0x3F */
202 
203 enum POWER_MODE {
204 	POWER_LOW = 0,
205 	POWER_NORMAL
206 };
207 
208 #define RX_PKT_BROADCAST	1
209 #define RX_PKT_DEST_ADDR	2
210 #define RX_PKT_PHY_MATCH	3
211 
212 #define RPTMaxCount 0x000FFFFF
213 
214 /* parameter 1 : BitMask
215  *	bit 0  : OFDM PPDU
216  *	bit 1  : OFDM False Alarm
217  *	bit 2  : OFDM MPDU OK
218  *	bit 3  : OFDM MPDU Fail
219  *	bit 4  : CCK PPDU
220  *	bit 5  : CCK False Alarm
221  *	bit 6  : CCK MPDU ok
222  *	bit 7  : CCK MPDU fail
223  *	bit 8  : HT PPDU counter
224  *	bit 9  : HT false alarm
225  *	bit 10 : HT MPDU total
226  *	bit 11 : HT MPDU OK
227  *	bit 12 : HT MPDU fail
228  *	bit 15 : RX full drop
229  */
230 enum RXPHY_BITMASK {
231 	OFDM_PPDU_BIT = 0,
232 	OFDM_MPDU_OK_BIT,
233 	OFDM_MPDU_FAIL_BIT,
234 	CCK_PPDU_BIT,
235 	CCK_MPDU_OK_BIT,
236 	CCK_MPDU_FAIL_BIT,
237 	HT_PPDU_BIT,
238 	HT_MPDU_BIT,
239 	HT_MPDU_OK_BIT,
240 	HT_MPDU_FAIL_BIT,
241 };
242 
243 enum ENCRY_CTRL_STATE {
244 	HW_CONTROL,		/*hw encryption& decryption*/
245 	SW_CONTROL,		/*sw encryption& decryption*/
246 	HW_ENCRY_SW_DECRY,	/*hw encryption & sw decryption*/
247 	SW_ENCRY_HW_DECRY	/*sw encryption & hw decryption*/
248 };
249 
250 /* Bandwidth Offset */
251 #define HAL_PRIME_CHNL_OFFSET_DONT_CARE	0
252 #define HAL_PRIME_CHNL_OFFSET_LOWER	1
253 #define HAL_PRIME_CHNL_OFFSET_UPPER	2
254 /*=======================================================================*/
255 void mp871xinit(struct _adapter *padapter);
256 void mp871xdeinit(struct _adapter *padapter);
257 u32 r8712_bb_reg_read(struct _adapter *Adapter, u16 offset);
258 u8 r8712_bb_reg_write(struct _adapter *Adapter, u16 offset, u32 value);
259 u32 r8712_rf_reg_read(struct _adapter *Adapter, u8 path, u8 offset);
260 u8 r8712_rf_reg_write(struct _adapter *Adapter, u8 path,
261 		      u8 offset, u32 value);
262 u32 r8712_get_bb_reg(struct _adapter *Adapter, u16 offset, u32 bitmask);
263 u8 r8712_set_bb_reg(struct _adapter *Adapter, u16 offset,
264 		    u32 bitmask, u32 value);
265 u32 r8712_get_rf_reg(struct _adapter *Adapter, u8 path, u8 offset,
266 		     u32 bitmask);
267 u8 r8712_set_rf_reg(struct _adapter *Adapter, u8 path, u8 offset,
268 		    u32 bitmask, u32 value);
269 
270 void r8712_SetChannel(struct _adapter *pAdapter);
271 void r8712_SetTxPower(struct _adapter *pAdapte);
272 void r8712_SetTxAGCOffset(struct _adapter *pAdapter, u32 ulTxAGCOffset);
273 void r8712_SetDataRate(struct _adapter *pAdapter);
274 void r8712_SwitchBandwidth(struct _adapter *pAdapter);
275 void r8712_SwitchAntenna(struct _adapter *pAdapter);
276 void r8712_GetThermalMeter(struct _adapter *pAdapter, u32 *value);
277 void r8712_SetContinuousTx(struct _adapter *pAdapter, u8 bStart);
278 void r8712_SetSingleCarrierTx(struct _adapter *pAdapter, u8 bStart);
279 void r8712_SetSingleToneTx(struct _adapter *pAdapter, u8 bStart);
280 void r8712_SetCarrierSuppressionTx(struct _adapter *pAdapter, u8 bStart);
281 void r8712_ResetPhyRxPktCount(struct _adapter *pAdapter);
282 u32 r8712_GetPhyRxPktReceived(struct _adapter *pAdapter);
283 u32 r8712_GetPhyRxPktCRC32Error(struct _adapter *pAdapter);
284 
285 #endif /*__RTL871X_MP_H_*/
286 
287