• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // SPDX-License-Identifier: GPL-2.0
2 /******************************************************************************
3  * rtl871x_mp_ioctl.c
4  *
5  * Copyright(c) 2007 - 2010 Realtek Corporation. All rights reserved.
6  * Linux device driver for RTL8192SU
7  *
8  * Modifications for inclusion into the Linux staging tree are
9  * Copyright(c) 2010 Larry Finger. All rights reserved.
10  *
11  * Contact information:
12  * WLAN FAE <wlanfae@realtek.com>
13  * Larry Finger <Larry.Finger@lwfinger.net>
14  *
15  ******************************************************************************/
16 
17 #include <linux/rndis.h>
18 #include "osdep_service.h"
19 #include "drv_types.h"
20 #include "mlme_osdep.h"
21 #include "rtl871x_mp.h"
22 #include "rtl871x_mp_ioctl.h"
23 
oid_null_function(struct oid_par_priv * poid_par_priv)24 uint oid_null_function(struct oid_par_priv *poid_par_priv)
25 {
26 	return RNDIS_STATUS_SUCCESS;
27 }
28 
oid_rt_wireless_mode_hdl(struct oid_par_priv * poid_par_priv)29 uint oid_rt_wireless_mode_hdl(struct oid_par_priv *poid_par_priv)
30 {
31 	uint status = RNDIS_STATUS_SUCCESS;
32 	struct _adapter *Adapter = (struct _adapter *)
33 				   (poid_par_priv->adapter_context);
34 
35 	if (poid_par_priv->type_of_oid == SET_OID) {
36 		if (poid_par_priv->information_buf_len >= sizeof(u8))
37 			Adapter->registrypriv.wireless_mode =
38 					*(u8 *)poid_par_priv->information_buf;
39 		else
40 			status = RNDIS_STATUS_INVALID_LENGTH;
41 	} else if (poid_par_priv->type_of_oid == QUERY_OID) {
42 		if (poid_par_priv->information_buf_len >= sizeof(u8)) {
43 			*(u8 *)poid_par_priv->information_buf =
44 					 Adapter->registrypriv.wireless_mode;
45 			*poid_par_priv->bytes_rw =
46 					poid_par_priv->information_buf_len;
47 		} else {
48 			status = RNDIS_STATUS_INVALID_LENGTH;
49 		}
50 	} else {
51 		status = RNDIS_STATUS_NOT_ACCEPTED;
52 	}
53 	return status;
54 }
55 
oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv * poid_par_priv)56 uint oid_rt_pro_write_bb_reg_hdl(struct oid_par_priv *poid_par_priv)
57 {
58 	struct _adapter *Adapter = (struct _adapter *)
59 				   (poid_par_priv->adapter_context);
60 	struct bb_reg_param *pbbreg;
61 	u16 offset;
62 	u32 value;
63 
64 	if (poid_par_priv->type_of_oid != SET_OID)
65 		return RNDIS_STATUS_NOT_ACCEPTED;
66 	if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param))
67 		return RNDIS_STATUS_INVALID_LENGTH;
68 	pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf);
69 	offset = (u16)(pbbreg->offset) & 0xFFF; /*0ffset :0x800~0xfff*/
70 	if (offset < BB_REG_BASE_ADDR)
71 		offset |= BB_REG_BASE_ADDR;
72 	value = pbbreg->value;
73 	r8712_bb_reg_write(Adapter, offset, value);
74 	return RNDIS_STATUS_SUCCESS;
75 }
76 
oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv * poid_par_priv)77 uint oid_rt_pro_read_bb_reg_hdl(struct oid_par_priv *poid_par_priv)
78 {
79 	struct _adapter *Adapter = (struct _adapter *)
80 				   (poid_par_priv->adapter_context);
81 	struct bb_reg_param *pbbreg;
82 	u16 offset;
83 	u32 value;
84 
85 	if (poid_par_priv->type_of_oid != QUERY_OID)
86 		return RNDIS_STATUS_NOT_ACCEPTED;
87 	if (poid_par_priv->information_buf_len < sizeof(struct bb_reg_param))
88 		return RNDIS_STATUS_INVALID_LENGTH;
89 	pbbreg = (struct bb_reg_param *)(poid_par_priv->information_buf);
90 	offset = (u16)(pbbreg->offset) & 0xFFF; /*0ffset :0x800~0xfff*/
91 	if (offset < BB_REG_BASE_ADDR)
92 		offset |= BB_REG_BASE_ADDR;
93 	value = r8712_bb_reg_read(Adapter, offset);
94 	pbbreg->value = value;
95 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
96 	return RNDIS_STATUS_SUCCESS;
97 }
98 
oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv * poid_par_priv)99 uint oid_rt_pro_write_rf_reg_hdl(struct oid_par_priv *poid_par_priv)
100 {
101 	struct _adapter *Adapter = (struct _adapter *)
102 				   (poid_par_priv->adapter_context);
103 	struct rf_reg_param *pbbreg;
104 	u8 path;
105 	u8 offset;
106 	u32 value;
107 
108 	if (poid_par_priv->type_of_oid != SET_OID)
109 		return RNDIS_STATUS_NOT_ACCEPTED;
110 	if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param))
111 		return RNDIS_STATUS_INVALID_LENGTH;
112 	pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf);
113 	path = (u8)pbbreg->path;
114 	if (path > RF_PATH_B)
115 		return RNDIS_STATUS_NOT_ACCEPTED;
116 	offset = (u8)pbbreg->offset;
117 	value = pbbreg->value;
118 	r8712_rf_reg_write(Adapter, path, offset, value);
119 	return RNDIS_STATUS_SUCCESS;
120 }
121 
oid_rt_pro_read_rf_reg_hdl(struct oid_par_priv * poid_par_priv)122 uint oid_rt_pro_read_rf_reg_hdl(struct oid_par_priv *poid_par_priv)
123 {
124 	struct _adapter *Adapter = (struct _adapter *)
125 				   (poid_par_priv->adapter_context);
126 	struct rf_reg_param *pbbreg;
127 	u8 path;
128 	u8 offset;
129 	u32 value;
130 
131 	if (poid_par_priv->type_of_oid != QUERY_OID)
132 		return RNDIS_STATUS_NOT_ACCEPTED;
133 	if (poid_par_priv->information_buf_len < sizeof(struct rf_reg_param))
134 		return RNDIS_STATUS_INVALID_LENGTH;
135 	pbbreg = (struct rf_reg_param *)(poid_par_priv->information_buf);
136 	path = (u8)pbbreg->path;
137 	if (path > RF_PATH_B) /* 1T2R  path_a /path_b */
138 		return RNDIS_STATUS_NOT_ACCEPTED;
139 	offset = (u8)pbbreg->offset;
140 	value = r8712_rf_reg_read(Adapter, path, offset);
141 	pbbreg->value = value;
142 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
143 	return RNDIS_STATUS_SUCCESS;
144 }
145 
146 /*This function initializes the DUT to the MP test mode*/
mp_start_test(struct _adapter * padapter)147 static int mp_start_test(struct _adapter *padapter)
148 {
149 	struct mp_priv *pmppriv = &padapter->mppriv;
150 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
151 	struct wlan_network *tgt_network = &pmlmepriv->cur_network;
152 	struct wlan_bssid_ex *bssid;
153 	struct sta_info *psta;
154 	unsigned long length;
155 	unsigned long irqL;
156 	int res = 0;
157 
158 	bssid = kzalloc(sizeof(*bssid), GFP_KERNEL);
159 	if (!bssid)
160 		return -ENOMEM;
161 
162 	/* 3 1. initialize a new struct wlan_bssid_ex */
163 	memcpy(bssid->MacAddress, pmppriv->network_macaddr, ETH_ALEN);
164 	bssid->Ssid.SsidLength = 16;
165 	memcpy(bssid->Ssid.Ssid, (unsigned char *)"mp_pseudo_adhoc",
166 		bssid->Ssid.SsidLength);
167 	bssid->InfrastructureMode = Ndis802_11IBSS;
168 	bssid->NetworkTypeInUse = Ndis802_11DS;
169 	bssid->IELength = 0;
170 	length = r8712_get_wlan_bssid_ex_sz(bssid);
171 	if (length % 4) {
172 		/*round up to multiple of 4 bytes.*/
173 		bssid->Length = ((length >> 2) + 1) << 2;
174 	} else {
175 		bssid->Length = length;
176 	}
177 	spin_lock_irqsave(&pmlmepriv->lock, irqL);
178 	if (check_fwstate(pmlmepriv, WIFI_MP_STATE))
179 		goto end_of_mp_start_test;
180 	/*init mp_start_test status*/
181 	pmppriv->prev_fw_state = get_fwstate(pmlmepriv);
182 	pmlmepriv->fw_state = WIFI_MP_STATE;
183 	if (pmppriv->mode == _LOOPBOOK_MODE_)
184 		set_fwstate(pmlmepriv, WIFI_MP_LPBK_STATE); /*append txdesc*/
185 	set_fwstate(pmlmepriv, _FW_UNDER_LINKING);
186 	/* 3 2. create a new psta for mp driver */
187 	/* clear psta in the cur_network, if any */
188 	psta = r8712_get_stainfo(&padapter->stapriv,
189 				 tgt_network->network.MacAddress);
190 	if (psta)
191 		r8712_free_stainfo(padapter, psta);
192 	psta = r8712_alloc_stainfo(&padapter->stapriv, bssid->MacAddress);
193 	if (!psta) {
194 		res = -ENOMEM;
195 		goto end_of_mp_start_test;
196 	}
197 	/* 3 3. join pseudo AdHoc */
198 	tgt_network->join_res = 1;
199 	tgt_network->aid = psta->aid = 1;
200 	memcpy(&tgt_network->network, bssid, length);
201 	_clr_fwstate_(pmlmepriv, _FW_UNDER_LINKING);
202 	r8712_os_indicate_connect(padapter);
203 	/* Set to LINKED STATE for MP TRX Testing */
204 	set_fwstate(pmlmepriv, _FW_LINKED);
205 end_of_mp_start_test:
206 	spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
207 	kfree(bssid);
208 	return res;
209 }
210 
211 /*This function change the DUT from the MP test mode into normal mode */
mp_stop_test(struct _adapter * padapter)212 static int mp_stop_test(struct _adapter *padapter)
213 {
214 	struct mp_priv *pmppriv = &padapter->mppriv;
215 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
216 	struct wlan_network *tgt_network = &pmlmepriv->cur_network;
217 	struct sta_info *psta;
218 	unsigned long irqL;
219 
220 	spin_lock_irqsave(&pmlmepriv->lock, irqL);
221 	if (!check_fwstate(pmlmepriv, WIFI_MP_STATE))
222 		goto end_of_mp_stop_test;
223 	/* 3 1. disconnect pseudo AdHoc */
224 	r8712_os_indicate_disconnect(padapter);
225 	/* 3 2. clear psta used in mp test mode. */
226 	psta = r8712_get_stainfo(&padapter->stapriv,
227 				 tgt_network->network.MacAddress);
228 	if (psta)
229 		r8712_free_stainfo(padapter, psta);
230 	/* 3 3. return to normal state (default:station mode) */
231 	pmlmepriv->fw_state = pmppriv->prev_fw_state; /* WIFI_STATION_STATE;*/
232 	/*flush the cur_network*/
233 	memset(tgt_network, 0, sizeof(struct wlan_network));
234 end_of_mp_stop_test:
235 	spin_unlock_irqrestore(&pmlmepriv->lock, irqL);
236 	return _SUCCESS;
237 }
238 
oid_rt_pro_set_data_rate_hdl(struct oid_par_priv * poid_par_priv)239 uint oid_rt_pro_set_data_rate_hdl(struct oid_par_priv *poid_par_priv)
240 {
241 	struct _adapter *Adapter = (struct _adapter *)
242 				   (poid_par_priv->adapter_context);
243 	u32 ratevalue;
244 
245 	if (poid_par_priv->type_of_oid != SET_OID)
246 		return RNDIS_STATUS_NOT_ACCEPTED;
247 	if (poid_par_priv->information_buf_len != sizeof(u32))
248 		return RNDIS_STATUS_INVALID_LENGTH;
249 	ratevalue = *((u32 *)poid_par_priv->information_buf);
250 	if (ratevalue >= MPT_RATE_LAST)
251 		return RNDIS_STATUS_INVALID_DATA;
252 	Adapter->mppriv.curr_rateidx = ratevalue;
253 	r8712_SetDataRate(Adapter);
254 	return RNDIS_STATUS_SUCCESS;
255 }
256 
oid_rt_pro_start_test_hdl(struct oid_par_priv * poid_par_priv)257 uint oid_rt_pro_start_test_hdl(struct oid_par_priv *poid_par_priv)
258 {
259 	struct _adapter *Adapter = (struct _adapter *)
260 				   (poid_par_priv->adapter_context);
261 	uint status = RNDIS_STATUS_SUCCESS;
262 	u32 mode;
263 	u8 val8;
264 
265 	if (poid_par_priv->type_of_oid != SET_OID)
266 		return  RNDIS_STATUS_NOT_ACCEPTED;
267 	mode = *((u32 *)poid_par_priv->information_buf);
268 	Adapter->mppriv.mode = mode;/* 1 for loopback*/
269 	if (mp_start_test(Adapter))
270 		status = RNDIS_STATUS_NOT_ACCEPTED;
271 	r8712_write8(Adapter, MSR, 1); /* Link in ad hoc network, 0x1025004C */
272 	r8712_write8(Adapter, RCR, 0); /* RCR : disable all pkt, 0x10250048 */
273 	/* RCR disable Check BSSID, 0x1025004a */
274 	r8712_write8(Adapter, RCR + 2, 0x57);
275 	/* disable RX filter map , mgt frames will put in RX FIFO 0 */
276 	r8712_write16(Adapter, RXFLTMAP0, 0x0);
277 	val8 = r8712_read8(Adapter, EE_9346CR);
278 	if (!(val8 & _9356SEL)) { /*boot from EFUSE*/
279 		r8712_efuse_reg_init(Adapter);
280 		r8712_efuse_change_max_size(Adapter);
281 		r8712_efuse_reg_uninit(Adapter);
282 	}
283 	return status;
284 }
285 
oid_rt_pro_stop_test_hdl(struct oid_par_priv * poid_par_priv)286 uint oid_rt_pro_stop_test_hdl(struct oid_par_priv *poid_par_priv)
287 {
288 	struct _adapter *Adapter = (struct _adapter *)
289 				   (poid_par_priv->adapter_context);
290 
291 	if (poid_par_priv->type_of_oid != SET_OID)
292 		return RNDIS_STATUS_NOT_ACCEPTED;
293 	if (mp_stop_test(Adapter) == _FAIL)
294 		return RNDIS_STATUS_NOT_ACCEPTED;
295 	return RNDIS_STATUS_SUCCESS;
296 }
297 
oid_rt_pro_set_channel_direct_call_hdl(struct oid_par_priv * poid_par_priv)298 uint oid_rt_pro_set_channel_direct_call_hdl(struct oid_par_priv *poid_par_priv)
299 {
300 	struct _adapter *Adapter = (struct _adapter *)
301 				   (poid_par_priv->adapter_context);
302 	u32		Channel;
303 
304 	if (poid_par_priv->type_of_oid != SET_OID)
305 		return RNDIS_STATUS_NOT_ACCEPTED;
306 	if (poid_par_priv->information_buf_len != sizeof(u32))
307 		return RNDIS_STATUS_INVALID_LENGTH;
308 	Channel = *((u32 *)poid_par_priv->information_buf);
309 	if (Channel > 14)
310 		return RNDIS_STATUS_NOT_ACCEPTED;
311 	Adapter->mppriv.curr_ch = Channel;
312 	r8712_SetChannel(Adapter);
313 	return RNDIS_STATUS_SUCCESS;
314 }
315 
oid_rt_pro_set_antenna_bb_hdl(struct oid_par_priv * poid_par_priv)316 uint oid_rt_pro_set_antenna_bb_hdl(struct oid_par_priv *poid_par_priv)
317 {
318 	struct _adapter *Adapter = (struct _adapter *)
319 				   (poid_par_priv->adapter_context);
320 	u32 antenna;
321 
322 	if (poid_par_priv->type_of_oid != SET_OID)
323 		return RNDIS_STATUS_NOT_ACCEPTED;
324 	if (poid_par_priv->information_buf_len != sizeof(u32))
325 		return RNDIS_STATUS_INVALID_LENGTH;
326 	antenna = *((u32 *)poid_par_priv->information_buf);
327 	Adapter->mppriv.antenna_tx = (u16)((antenna & 0xFFFF0000) >> 16);
328 	Adapter->mppriv.antenna_rx = (u16)(antenna & 0x0000FFFF);
329 	r8712_SwitchAntenna(Adapter);
330 	return RNDIS_STATUS_SUCCESS;
331 }
332 
oid_rt_pro_set_tx_power_control_hdl(struct oid_par_priv * poid_par_priv)333 uint oid_rt_pro_set_tx_power_control_hdl(struct oid_par_priv *poid_par_priv)
334 {
335 	struct _adapter *Adapter = (struct _adapter *)
336 				   (poid_par_priv->adapter_context);
337 	u32 tx_pwr_idx;
338 
339 	if (poid_par_priv->type_of_oid != SET_OID)
340 		return RNDIS_STATUS_NOT_ACCEPTED;
341 	if (poid_par_priv->information_buf_len != sizeof(u32))
342 		return RNDIS_STATUS_INVALID_LENGTH;
343 	tx_pwr_idx = *((u32 *)poid_par_priv->information_buf);
344 	if (tx_pwr_idx > MAX_TX_PWR_INDEX_N_MODE)
345 		return RNDIS_STATUS_NOT_ACCEPTED;
346 	Adapter->mppriv.curr_txpoweridx = (u8)tx_pwr_idx;
347 	r8712_SetTxPower(Adapter);
348 	return RNDIS_STATUS_SUCCESS;
349 }
350 
oid_rt_pro_query_tx_packet_sent_hdl(struct oid_par_priv * poid_par_priv)351 uint oid_rt_pro_query_tx_packet_sent_hdl(struct oid_par_priv *poid_par_priv)
352 {
353 	struct _adapter *Adapter = (struct _adapter *)
354 				   (poid_par_priv->adapter_context);
355 
356 	if (poid_par_priv->type_of_oid != QUERY_OID)
357 		return RNDIS_STATUS_NOT_ACCEPTED;
358 
359 	if (poid_par_priv->information_buf_len == sizeof(u32)) {
360 		*(u32 *)poid_par_priv->information_buf =
361 					Adapter->mppriv.tx_pktcount;
362 		*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
363 	} else {
364 		return RNDIS_STATUS_INVALID_LENGTH;
365 	}
366 	return RNDIS_STATUS_SUCCESS;
367 }
368 
oid_rt_pro_query_rx_packet_received_hdl(struct oid_par_priv * poid_par_priv)369 uint oid_rt_pro_query_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv)
370 {
371 	struct _adapter *Adapter = (struct _adapter *)
372 				   (poid_par_priv->adapter_context);
373 
374 	if (poid_par_priv->type_of_oid != QUERY_OID)
375 		return RNDIS_STATUS_NOT_ACCEPTED;
376 
377 	if (poid_par_priv->information_buf_len == sizeof(u32)) {
378 		*(u32 *)poid_par_priv->information_buf =
379 					Adapter->mppriv.rx_pktcount;
380 		*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
381 	} else {
382 		return RNDIS_STATUS_INVALID_LENGTH;
383 	}
384 	return RNDIS_STATUS_SUCCESS;
385 }
386 
oid_rt_pro_query_rx_packet_crc32_error_hdl(struct oid_par_priv * poid_par_priv)387 uint oid_rt_pro_query_rx_packet_crc32_error_hdl(struct oid_par_priv *poid_par_priv)
388 {
389 	struct _adapter *Adapter = (struct _adapter *)
390 				   (poid_par_priv->adapter_context);
391 
392 	if (poid_par_priv->type_of_oid != QUERY_OID)
393 		return RNDIS_STATUS_NOT_ACCEPTED;
394 
395 	if (poid_par_priv->information_buf_len == sizeof(u32)) {
396 		*(u32 *)poid_par_priv->information_buf =
397 					Adapter->mppriv.rx_crcerrpktcount;
398 		*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
399 	} else {
400 		return RNDIS_STATUS_INVALID_LENGTH;
401 	}
402 	return RNDIS_STATUS_SUCCESS;
403 }
404 
oid_rt_pro_reset_tx_packet_sent_hdl(struct oid_par_priv * poid_par_priv)405 uint oid_rt_pro_reset_tx_packet_sent_hdl(struct oid_par_priv *poid_par_priv)
406 {
407 	struct _adapter *Adapter = (struct _adapter *)
408 				   (poid_par_priv->adapter_context);
409 
410 	if (poid_par_priv->type_of_oid != SET_OID)
411 		return RNDIS_STATUS_NOT_ACCEPTED;
412 	Adapter->mppriv.tx_pktcount = 0;
413 	return RNDIS_STATUS_SUCCESS;
414 }
415 
oid_rt_pro_reset_rx_packet_received_hdl(struct oid_par_priv * poid_par_priv)416 uint oid_rt_pro_reset_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv)
417 {
418 	struct _adapter *Adapter = (struct _adapter *)
419 				   (poid_par_priv->adapter_context);
420 
421 	if (poid_par_priv->type_of_oid != SET_OID)
422 		return RNDIS_STATUS_NOT_ACCEPTED;
423 	if (poid_par_priv->information_buf_len == sizeof(u32)) {
424 		Adapter->mppriv.rx_pktcount = 0;
425 		Adapter->mppriv.rx_crcerrpktcount = 0;
426 	} else {
427 		return RNDIS_STATUS_INVALID_LENGTH;
428 	}
429 	return RNDIS_STATUS_SUCCESS;
430 }
431 
oid_rt_reset_phy_rx_packet_count_hdl(struct oid_par_priv * poid_par_priv)432 uint oid_rt_reset_phy_rx_packet_count_hdl(struct oid_par_priv *poid_par_priv)
433 {
434 	struct _adapter *Adapter = (struct _adapter *)
435 				   (poid_par_priv->adapter_context);
436 
437 	if (poid_par_priv->type_of_oid != SET_OID)
438 		return RNDIS_STATUS_NOT_ACCEPTED;
439 	r8712_ResetPhyRxPktCount(Adapter);
440 	return RNDIS_STATUS_SUCCESS;
441 }
442 
oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv * poid_par_priv)443 uint oid_rt_get_phy_rx_packet_received_hdl(struct oid_par_priv *poid_par_priv)
444 {
445 	struct _adapter *Adapter = (struct _adapter *)
446 				   (poid_par_priv->adapter_context);
447 
448 	if (poid_par_priv->type_of_oid != QUERY_OID)
449 		return RNDIS_STATUS_NOT_ACCEPTED;
450 	if (poid_par_priv->information_buf_len != sizeof(u32))
451 		return RNDIS_STATUS_INVALID_LENGTH;
452 	*(u32 *)poid_par_priv->information_buf =
453 					 r8712_GetPhyRxPktReceived(Adapter);
454 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
455 	return RNDIS_STATUS_SUCCESS;
456 }
457 
oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv * poid_par_priv)458 uint oid_rt_get_phy_rx_packet_crc32_error_hdl(struct oid_par_priv *poid_par_priv)
459 {
460 	struct _adapter *Adapter = (struct _adapter *)
461 				   (poid_par_priv->adapter_context);
462 
463 	if (poid_par_priv->type_of_oid != QUERY_OID)
464 		return RNDIS_STATUS_NOT_ACCEPTED;
465 	if (poid_par_priv->information_buf_len != sizeof(u32))
466 		return RNDIS_STATUS_INVALID_LENGTH;
467 	*(u32 *)poid_par_priv->information_buf =
468 					 r8712_GetPhyRxPktCRC32Error(Adapter);
469 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
470 	return RNDIS_STATUS_SUCCESS;
471 }
472 
oid_rt_pro_set_modulation_hdl(struct oid_par_priv * poid_par_priv)473 uint oid_rt_pro_set_modulation_hdl(struct oid_par_priv *poid_par_priv)
474 {
475 	struct _adapter *Adapter = (struct _adapter *)
476 				   (poid_par_priv->adapter_context);
477 
478 	if (poid_par_priv->type_of_oid != SET_OID)
479 		return RNDIS_STATUS_NOT_ACCEPTED;
480 
481 	Adapter->mppriv.curr_modem = *((u8 *)poid_par_priv->information_buf);
482 	return RNDIS_STATUS_SUCCESS;
483 }
484 
oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv * poid_par_priv)485 uint oid_rt_pro_set_continuous_tx_hdl(struct oid_par_priv *poid_par_priv)
486 {
487 	struct _adapter *Adapter = (struct _adapter *)
488 				   (poid_par_priv->adapter_context);
489 	u32		bStartTest;
490 
491 	if (poid_par_priv->type_of_oid != SET_OID)
492 		return RNDIS_STATUS_NOT_ACCEPTED;
493 	bStartTest = *((u32 *)poid_par_priv->information_buf);
494 	r8712_SetContinuousTx(Adapter, (u8)bStartTest);
495 	return RNDIS_STATUS_SUCCESS;
496 }
497 
oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv * poid_par_priv)498 uint oid_rt_pro_set_single_carrier_tx_hdl(struct oid_par_priv *poid_par_priv)
499 {
500 	struct _adapter *Adapter = (struct _adapter *)
501 				   (poid_par_priv->adapter_context);
502 	u32		bStartTest;
503 
504 	if (poid_par_priv->type_of_oid != SET_OID)
505 		return RNDIS_STATUS_NOT_ACCEPTED;
506 	bStartTest = *((u32 *)poid_par_priv->information_buf);
507 	r8712_SetSingleCarrierTx(Adapter, (u8)bStartTest);
508 	return RNDIS_STATUS_SUCCESS;
509 }
510 
oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv * poid_par_priv)511 uint oid_rt_pro_set_carrier_suppression_tx_hdl(struct oid_par_priv *poid_par_priv)
512 {
513 	struct _adapter *Adapter = (struct _adapter *)
514 				   (poid_par_priv->adapter_context);
515 	u32		bStartTest;
516 
517 	if (poid_par_priv->type_of_oid != SET_OID)
518 		return RNDIS_STATUS_NOT_ACCEPTED;
519 	bStartTest = *((u32 *)poid_par_priv->information_buf);
520 	r8712_SetCarrierSuppressionTx(Adapter, (u8)bStartTest);
521 	return RNDIS_STATUS_SUCCESS;
522 }
523 
oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv * poid_par_priv)524 uint oid_rt_pro_set_single_tone_tx_hdl(struct oid_par_priv *poid_par_priv)
525 {
526 	struct _adapter *Adapter = (struct _adapter *)
527 				   (poid_par_priv->adapter_context);
528 	u32		bStartTest;
529 
530 	if (poid_par_priv->type_of_oid != SET_OID)
531 		return RNDIS_STATUS_NOT_ACCEPTED;
532 	bStartTest = *((u32 *)poid_par_priv->information_buf);
533 	r8712_SetSingleToneTx(Adapter, (u8)bStartTest);
534 	return RNDIS_STATUS_SUCCESS;
535 }
536 
oid_rt_pro_read_register_hdl(struct oid_par_priv * poid_par_priv)537 uint oid_rt_pro_read_register_hdl(struct oid_par_priv *poid_par_priv)
538 {
539 	struct _adapter *Adapter = (struct _adapter *)
540 				   (poid_par_priv->adapter_context);
541 	uint status = RNDIS_STATUS_SUCCESS;
542 	struct mp_rw_reg *RegRWStruct;
543 	u16		offset;
544 
545 	if (poid_par_priv->type_of_oid != QUERY_OID)
546 		return RNDIS_STATUS_NOT_ACCEPTED;
547 	RegRWStruct = (struct mp_rw_reg *)poid_par_priv->information_buf;
548 	if ((RegRWStruct->offset >= 0x10250800) &&
549 	    (RegRWStruct->offset <= 0x10250FFF)) {
550 		/*baseband register*/
551 		/*0ffset :0x800~0xfff*/
552 		offset = (u16)(RegRWStruct->offset) & 0xFFF;
553 		RegRWStruct->value = r8712_bb_reg_read(Adapter, offset);
554 	} else {
555 		switch (RegRWStruct->width) {
556 		case 1:
557 			RegRWStruct->value = r8712_read8(Adapter,
558 						   RegRWStruct->offset);
559 			break;
560 		case 2:
561 			RegRWStruct->value = r8712_read16(Adapter,
562 						    RegRWStruct->offset);
563 			break;
564 		case 4:
565 			RegRWStruct->value = r8712_read32(Adapter,
566 						    RegRWStruct->offset);
567 			break;
568 		default:
569 			status = RNDIS_STATUS_NOT_ACCEPTED;
570 			break;
571 		}
572 	}
573 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
574 	return status;
575 }
576 
oid_rt_pro_write_register_hdl(struct oid_par_priv * poid_par_priv)577 uint oid_rt_pro_write_register_hdl(struct oid_par_priv *poid_par_priv)
578 {
579 	struct _adapter *Adapter = (struct _adapter *)
580 				   (poid_par_priv->adapter_context);
581 	uint status = RNDIS_STATUS_SUCCESS;
582 	struct mp_rw_reg *RegRWStruct;
583 	u16		offset;
584 	u32		value;
585 	u32 oldValue = 0;
586 
587 	if (poid_par_priv->type_of_oid != SET_OID)
588 		return RNDIS_STATUS_NOT_ACCEPTED;
589 	RegRWStruct = (struct mp_rw_reg *)poid_par_priv->information_buf;
590 	if ((RegRWStruct->offset >= 0x10250800) &&
591 	    (RegRWStruct->offset <= 0x10250FFF)) {
592 		/*baseband register*/
593 		offset = (u16)(RegRWStruct->offset) & 0xFFF;
594 		value = RegRWStruct->value;
595 		switch (RegRWStruct->width) {
596 		case 1:
597 			oldValue = r8712_bb_reg_read(Adapter, offset);
598 			oldValue &= 0xFFFFFF00;
599 			value &= 0x000000FF;
600 			value |= oldValue;
601 			break;
602 		case 2:
603 			oldValue = r8712_bb_reg_read(Adapter, offset);
604 			oldValue &= 0xFFFF0000;
605 			value &= 0x0000FFFF;
606 			value |= oldValue;
607 			break;
608 		}
609 		r8712_bb_reg_write(Adapter, offset, value);
610 	} else {
611 		switch (RegRWStruct->width) {
612 		case 1:
613 			r8712_write8(Adapter, RegRWStruct->offset,
614 			       (unsigned char)RegRWStruct->value);
615 			break;
616 		case 2:
617 			r8712_write16(Adapter, RegRWStruct->offset,
618 				(unsigned short)RegRWStruct->value);
619 			break;
620 		case 4:
621 			r8712_write32(Adapter, RegRWStruct->offset,
622 				(unsigned int)RegRWStruct->value);
623 			break;
624 		default:
625 			status = RNDIS_STATUS_NOT_ACCEPTED;
626 			break;
627 		}
628 	}
629 	return status;
630 }
631 
oid_rt_get_thermal_meter_hdl(struct oid_par_priv * poid_par_priv)632 uint oid_rt_get_thermal_meter_hdl(struct oid_par_priv *poid_par_priv)
633 {
634 	struct _adapter *Adapter = (struct _adapter *)
635 				   (poid_par_priv->adapter_context);
636 
637 	if (poid_par_priv->type_of_oid != QUERY_OID)
638 		return RNDIS_STATUS_NOT_ACCEPTED;
639 
640 	if (Adapter->mppriv.act_in_progress)
641 		return RNDIS_STATUS_NOT_ACCEPTED;
642 
643 	if (poid_par_priv->information_buf_len < sizeof(u8))
644 		return RNDIS_STATUS_INVALID_LENGTH;
645 	/*init workparam*/
646 	Adapter->mppriv.act_in_progress = true;
647 	Adapter->mppriv.workparam.bcompleted = false;
648 	Adapter->mppriv.workparam.act_type = MPT_GET_THERMAL_METER;
649 	Adapter->mppriv.workparam.io_offset = 0;
650 	Adapter->mppriv.workparam.io_value = 0xFFFFFFFF;
651 	r8712_GetThermalMeter(Adapter, &Adapter->mppriv.workparam.io_value);
652 	Adapter->mppriv.workparam.bcompleted = true;
653 	Adapter->mppriv.act_in_progress = false;
654 	*(u32 *)poid_par_priv->information_buf =
655 				 Adapter->mppriv.workparam.io_value;
656 	*poid_par_priv->bytes_rw = sizeof(u32);
657 	return RNDIS_STATUS_SUCCESS;
658 }
659 
oid_rt_pro_read_efuse_hdl(struct oid_par_priv * poid_par_priv)660 uint oid_rt_pro_read_efuse_hdl(struct oid_par_priv *poid_par_priv)
661 {
662 	struct _adapter *Adapter = (struct _adapter *)
663 				   (poid_par_priv->adapter_context);
664 
665 	uint status = RNDIS_STATUS_SUCCESS;
666 
667 	struct EFUSE_ACCESS_STRUCT *pefuse;
668 	u8 *data;
669 	u16 addr = 0, cnts = 0;
670 
671 	if (poid_par_priv->type_of_oid != QUERY_OID)
672 		return RNDIS_STATUS_NOT_ACCEPTED;
673 	if (poid_par_priv->information_buf_len <
674 	    sizeof(struct EFUSE_ACCESS_STRUCT))
675 		return RNDIS_STATUS_INVALID_LENGTH;
676 	pefuse = (struct EFUSE_ACCESS_STRUCT *)poid_par_priv->information_buf;
677 	addr = pefuse->start_addr;
678 	cnts = pefuse->cnts;
679 	data = pefuse->data;
680 	memset(data, 0xFF, cnts);
681 	if ((addr > 511) || (cnts < 1) || (cnts > 512) || (addr + cnts) >
682 	     EFUSE_MAX_SIZE)
683 		return RNDIS_STATUS_NOT_ACCEPTED;
684 	if (!r8712_efuse_access(Adapter, true, addr, cnts, data))
685 		status = RNDIS_STATUS_FAILURE;
686 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
687 	return status;
688 }
689 
690 /*------------------------------------------------------------------------*/
oid_rt_pro_write_efuse_hdl(struct oid_par_priv * poid_par_priv)691 uint oid_rt_pro_write_efuse_hdl(struct oid_par_priv *poid_par_priv)
692 {
693 	struct _adapter *Adapter = (struct _adapter *)
694 				   (poid_par_priv->adapter_context);
695 
696 	uint status = RNDIS_STATUS_SUCCESS;
697 
698 	struct EFUSE_ACCESS_STRUCT *pefuse;
699 	u8 *data;
700 	u16 addr = 0, cnts = 0;
701 
702 	if (poid_par_priv->type_of_oid != SET_OID)
703 		return RNDIS_STATUS_NOT_ACCEPTED;
704 
705 	pefuse = (struct EFUSE_ACCESS_STRUCT *)poid_par_priv->information_buf;
706 	addr = pefuse->start_addr;
707 	cnts = pefuse->cnts;
708 	data = pefuse->data;
709 
710 	if ((addr > 511) || (cnts < 1) || (cnts > 512) ||
711 	    (addr + cnts) > r8712_efuse_get_max_size(Adapter))
712 		return RNDIS_STATUS_NOT_ACCEPTED;
713 	if (!r8712_efuse_access(Adapter, false, addr, cnts, data))
714 		status = RNDIS_STATUS_FAILURE;
715 	return status;
716 }
717 
718 /*----------------------------------------------------------------------*/
719 
oid_rt_get_efuse_current_size_hdl(struct oid_par_priv * poid_par_priv)720 uint oid_rt_get_efuse_current_size_hdl(struct oid_par_priv *poid_par_priv)
721 {
722 	struct _adapter *Adapter = (struct _adapter *)
723 				   (poid_par_priv->adapter_context);
724 
725 	if (poid_par_priv->type_of_oid != QUERY_OID)
726 		return RNDIS_STATUS_NOT_ACCEPTED;
727 	if (poid_par_priv->information_buf_len < sizeof(int))
728 		return RNDIS_STATUS_INVALID_LENGTH;
729 	r8712_efuse_reg_init(Adapter);
730 	*(int *)poid_par_priv->information_buf =
731 				 r8712_efuse_get_current_size(Adapter);
732 	r8712_efuse_reg_uninit(Adapter);
733 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
734 	return RNDIS_STATUS_SUCCESS;
735 }
736 
oid_rt_get_efuse_max_size_hdl(struct oid_par_priv * poid_par_priv)737 uint oid_rt_get_efuse_max_size_hdl(struct oid_par_priv *poid_par_priv)
738 {
739 	struct _adapter *Adapter = (struct _adapter *)
740 				   (poid_par_priv->adapter_context);
741 
742 	if (poid_par_priv->type_of_oid != QUERY_OID)
743 		return RNDIS_STATUS_NOT_ACCEPTED;
744 	if (poid_par_priv->information_buf_len < sizeof(u32))
745 		return RNDIS_STATUS_INVALID_LENGTH;
746 	*(int *)poid_par_priv->information_buf =
747 					 r8712_efuse_get_max_size(Adapter);
748 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
749 	return RNDIS_STATUS_SUCCESS;
750 }
751 
oid_rt_pro_efuse_hdl(struct oid_par_priv * poid_par_priv)752 uint oid_rt_pro_efuse_hdl(struct oid_par_priv *poid_par_priv)
753 {
754 	uint status = RNDIS_STATUS_SUCCESS;
755 
756 	if (poid_par_priv->type_of_oid == QUERY_OID)
757 		status = oid_rt_pro_read_efuse_hdl(poid_par_priv);
758 	else
759 		status = oid_rt_pro_write_efuse_hdl(poid_par_priv);
760 	return status;
761 }
762 
oid_rt_pro_efuse_map_hdl(struct oid_par_priv * poid_par_priv)763 uint oid_rt_pro_efuse_map_hdl(struct oid_par_priv *poid_par_priv)
764 {
765 	struct _adapter *Adapter = (struct _adapter *)
766 				   (poid_par_priv->adapter_context);
767 	uint status = RNDIS_STATUS_SUCCESS;
768 	u8		*data;
769 
770 	*poid_par_priv->bytes_rw = 0;
771 	if (poid_par_priv->information_buf_len < EFUSE_MAP_MAX_SIZE)
772 		return RNDIS_STATUS_INVALID_LENGTH;
773 	data = (u8 *)poid_par_priv->information_buf;
774 	if (poid_par_priv->type_of_oid == QUERY_OID) {
775 		if (r8712_efuse_map_read(Adapter, 0, EFUSE_MAP_MAX_SIZE, data))
776 			*poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE;
777 		else
778 			status = RNDIS_STATUS_FAILURE;
779 	} else {
780 		/* SET_OID */
781 		if (r8712_efuse_reg_init(Adapter)) {
782 			if (r8712_efuse_map_write(Adapter, 0,
783 			    EFUSE_MAP_MAX_SIZE, data))
784 				*poid_par_priv->bytes_rw = EFUSE_MAP_MAX_SIZE;
785 			else
786 				status = RNDIS_STATUS_FAILURE;
787 			r8712_efuse_reg_uninit(Adapter);
788 		} else {
789 			status = RNDIS_STATUS_FAILURE;
790 		}
791 	}
792 	return status;
793 }
794 
oid_rt_set_bandwidth_hdl(struct oid_par_priv * poid_par_priv)795 uint oid_rt_set_bandwidth_hdl(struct oid_par_priv *poid_par_priv)
796 {
797 	struct _adapter *Adapter = (struct _adapter *)
798 				   (poid_par_priv->adapter_context);
799 	u32		bandwidth;
800 
801 	if (poid_par_priv->type_of_oid != SET_OID)
802 		return RNDIS_STATUS_NOT_ACCEPTED;
803 	if (poid_par_priv->information_buf_len < sizeof(u32))
804 		return RNDIS_STATUS_INVALID_LENGTH;
805 	bandwidth = *((u32 *)poid_par_priv->information_buf);/*4*/
806 	if (bandwidth != HT_CHANNEL_WIDTH_20)
807 		bandwidth = HT_CHANNEL_WIDTH_40;
808 	Adapter->mppriv.curr_bandwidth = (u8)bandwidth;
809 	r8712_SwitchBandwidth(Adapter);
810 	return RNDIS_STATUS_SUCCESS;
811 }
812 
oid_rt_set_rx_packet_type_hdl(struct oid_par_priv * poid_par_priv)813 uint oid_rt_set_rx_packet_type_hdl(struct oid_par_priv *poid_par_priv)
814 {
815 	struct _adapter *Adapter = (struct _adapter *)
816 				   (poid_par_priv->adapter_context);
817 	u8		rx_pkt_type;
818 	u32		rcr_val32;
819 
820 	if (poid_par_priv->type_of_oid != SET_OID)
821 		return RNDIS_STATUS_NOT_ACCEPTED;
822 	if (poid_par_priv->information_buf_len < sizeof(u8))
823 		return RNDIS_STATUS_INVALID_LENGTH;
824 	rx_pkt_type = *((u8 *)poid_par_priv->information_buf);/*4*/
825 	rcr_val32 = r8712_read32(Adapter, RCR);/*RCR = 0x10250048*/
826 	rcr_val32 &= ~(RCR_CBSSID | RCR_AB | RCR_AM | RCR_APM | RCR_AAP);
827 	switch (rx_pkt_type) {
828 	case RX_PKT_BROADCAST:
829 		rcr_val32 |= (RCR_AB | RCR_AM | RCR_APM | RCR_AAP | RCR_ACRC32);
830 		break;
831 	case RX_PKT_DEST_ADDR:
832 		rcr_val32 |= (RCR_AB | RCR_AM | RCR_APM | RCR_AAP | RCR_ACRC32);
833 		break;
834 	case RX_PKT_PHY_MATCH:
835 		rcr_val32 |= (RCR_APM | RCR_ACRC32);
836 		break;
837 	default:
838 		rcr_val32 &= ~(RCR_AAP |
839 			       RCR_APM |
840 			       RCR_AM |
841 			       RCR_AB |
842 			       RCR_ACRC32);
843 		break;
844 	}
845 	if (rx_pkt_type == RX_PKT_DEST_ADDR)
846 		Adapter->mppriv.check_mp_pkt = 1;
847 	else
848 		Adapter->mppriv.check_mp_pkt = 0;
849 	r8712_write32(Adapter, RCR, rcr_val32);
850 	return RNDIS_STATUS_SUCCESS;
851 }
852 
853 /*--------------------------------------------------------------------------*/
854 /*Linux*/
mp_ioctl_xmit_packet_hdl(struct oid_par_priv * poid_par_priv)855 unsigned int mp_ioctl_xmit_packet_hdl(struct oid_par_priv *poid_par_priv)
856 {
857 	return _SUCCESS;
858 }
859 
860 /*-------------------------------------------------------------------------*/
oid_rt_set_power_down_hdl(struct oid_par_priv * poid_par_priv)861 uint oid_rt_set_power_down_hdl(struct oid_par_priv *poid_par_priv)
862 {
863 	if (poid_par_priv->type_of_oid != SET_OID)
864 		return RNDIS_STATUS_NOT_ACCEPTED;
865 	/*CALL  the power_down function*/
866 	return RNDIS_STATUS_SUCCESS;
867 }
868 
869 /*-------------------------------------------------------------------------- */
oid_rt_get_power_mode_hdl(struct oid_par_priv * poid_par_priv)870 uint oid_rt_get_power_mode_hdl(struct oid_par_priv *poid_par_priv)
871 {
872 	struct _adapter *Adapter = (struct _adapter *)
873 				   (poid_par_priv->adapter_context);
874 
875 	if (poid_par_priv->type_of_oid != QUERY_OID)
876 		return RNDIS_STATUS_NOT_ACCEPTED;
877 	if (poid_par_priv->information_buf_len < sizeof(u32))
878 		return RNDIS_STATUS_INVALID_LENGTH;
879 	*(int *)poid_par_priv->information_buf =
880 		 Adapter->registrypriv.low_power ? POWER_LOW : POWER_NORMAL;
881 	*poid_par_priv->bytes_rw = poid_par_priv->information_buf_len;
882 	return RNDIS_STATUS_SUCCESS;
883 }
884