• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /******************************************************************************
2  *
3  * Copyright(c) 2007 - 2011 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  ******************************************************************************/
15 #define _OS_INTFS_C_
16 
17 #include <osdep_service.h>
18 #include <osdep_intf.h>
19 #include <drv_types.h>
20 #include <xmit_osdep.h>
21 #include <recv_osdep.h>
22 #include <hal_intf.h>
23 #include <rtw_ioctl.h>
24 #include <rtl8188e_hal.h>
25 
26 MODULE_LICENSE("GPL");
27 MODULE_DESCRIPTION("Realtek Wireless Lan Driver");
28 MODULE_AUTHOR("Realtek Semiconductor Corp.");
29 MODULE_VERSION(DRIVERVERSION);
30 
31 #define RTW_NOTCH_FILTER 0 /* 0:Disable, 1:Enable, */
32 
33 /* module param defaults */
34 /* Ndis802_11Infrastructure; infra, ad-hoc, auto */
35 static int rtw_channel = 1;/* ad-hoc support requirement */
36 static int rtw_wireless_mode = WIRELESS_11BG_24N;
37 static int rtw_vrtl_carrier_sense = AUTO_VCS;
38 static int rtw_vcs_type = RTS_CTS;/*  */
39 static int rtw_rts_thresh = 2347;/*  */
40 static int rtw_frag_thresh = 2346;/*  */
41 static int rtw_preamble = PREAMBLE_LONG;/* long, short, auto */
42 static int rtw_power_mgnt = 1;
43 static int rtw_ips_mode = IPS_NORMAL;
44 
45 static int rtw_smart_ps = 2;
46 
47 module_param(rtw_ips_mode, int, 0644);
48 MODULE_PARM_DESC(rtw_ips_mode, "The default IPS mode");
49 
50 static int rtw_debug = 1;
51 
52 static int rtw_software_encrypt;
53 static int rtw_software_decrypt;
54 
55 static int rtw_acm_method;/*  0:By SW 1:By HW. */
56 
57 static int rtw_wmm_enable = 1;/*  default is set to enable the wmm. */
58 static int rtw_uapsd_enable;
59 
60 static int rtw_ht_enable = 1;
61 /* 0 :disable, bit(0): enable 2.4g, bit(1): enable 5g */
62 static int rtw_cbw40_enable = 3;
63 static int rtw_ampdu_enable = 1;/* for enable tx_ampdu */
64 
65 /* 0: disable
66  * bit(0):enable 2.4g
67  * bit(1):enable 5g
68  * default is set to enable 2.4GHZ for IOT issue with bufflao's AP at 5GHZ
69  */
70 static int rtw_rx_stbc = 1;
71 static int rtw_ampdu_amsdu;/*  0: disabled, 1:enabled, 2:auto */
72 
73 static int rtw_wifi_spec;
74 static int rtw_channel_plan = RT_CHANNEL_DOMAIN_MAX;
75 
76 static int rtw_antdiv_cfg = 2; /*  0:OFF , 1:ON, 2:decide by Efuse config */
77 
78 /* 0: decide by efuse
79  * 1: for 88EE, 1Tx and 1RxCG are diversity (2 Ant with SPDT)
80  * 2: for 88EE, 1Tx and 2Rx are diversity (2 Ant, Tx and RxCG are both on aux
81  *    port, RxCS is on main port)
82  * 3: for 88EE, 1Tx and 1RxCG are fixed (1Ant, Tx and RxCG are both on aux port)
83  */
84 static int rtw_antdiv_type;
85 
86 static int rtw_enusbss;/* 0:disable, 1:enable */
87 
88 static int rtw_hwpdn_mode = 2;/* 0:disable, 1:enable, 2: by EFUSE config */
89 
90 int rtw_mc2u_disable;
91 
92 static int rtw_80211d;
93 
94 static char *ifname = "wlan%d";
95 module_param(ifname, charp, 0644);
96 MODULE_PARM_DESC(ifname, "The default name to allocate for first interface");
97 
98 static char *if2name = "wlan%d";
99 module_param(if2name, charp, 0644);
100 MODULE_PARM_DESC(if2name, "The default name to allocate for second interface");
101 
102 /* temp mac address if users want to use instead of the mac address in Efuse */
103 char *rtw_initmac;
104 
105 module_param(rtw_initmac, charp, 0644);
106 module_param(rtw_channel_plan, int, 0644);
107 module_param(rtw_channel, int, 0644);
108 module_param(rtw_wmm_enable, int, 0644);
109 module_param(rtw_vrtl_carrier_sense, int, 0644);
110 module_param(rtw_vcs_type, int, 0644);
111 module_param(rtw_ht_enable, int, 0644);
112 module_param(rtw_cbw40_enable, int, 0644);
113 module_param(rtw_ampdu_enable, int, 0644);
114 module_param(rtw_rx_stbc, int, 0644);
115 module_param(rtw_ampdu_amsdu, int, 0644);
116 module_param(rtw_power_mgnt, int, 0644);
117 module_param(rtw_smart_ps, int, 0644);
118 module_param(rtw_wifi_spec, int, 0644);
119 module_param(rtw_antdiv_cfg, int, 0644);
120 module_param(rtw_antdiv_type, int, 0644);
121 module_param(rtw_enusbss, int, 0644);
122 module_param(rtw_hwpdn_mode, int, 0644);
123 
124 static uint rtw_max_roaming_times = 2;
125 module_param(rtw_max_roaming_times, uint, 0644);
126 MODULE_PARM_DESC(rtw_max_roaming_times, "The max roaming times to try");
127 
128 static int rtw_fw_iol = 1;/*  0:Disable, 1:enable, 2:by usb speed */
129 module_param(rtw_fw_iol, int, 0644);
130 MODULE_PARM_DESC(rtw_fw_iol, "FW IOL");
131 
132 module_param(rtw_mc2u_disable, int, 0644);
133 
134 module_param(rtw_80211d, int, 0644);
135 MODULE_PARM_DESC(rtw_80211d, "Enable 802.11d mechanism");
136 
137 static uint rtw_notch_filter = RTW_NOTCH_FILTER;
138 module_param(rtw_notch_filter, uint, 0644);
139 MODULE_PARM_DESC(rtw_notch_filter, "0:Disable, 1:Enable, 2:Enable only for P2P");
140 module_param_named(debug, rtw_debug, int, 0444);
141 MODULE_PARM_DESC(debug, "Set debug level (1-9) (default 1)");
142 
143 static bool rtw_monitor_enable;
144 module_param_named(monitor_enable, rtw_monitor_enable, bool, 0444);
145 MODULE_PARM_DESC(monitor_enable, "Enable monitor inferface (default: false)");
146 
147 static int netdev_open(struct net_device *pnetdev);
148 static int netdev_close(struct net_device *pnetdev);
149 
loadparam(struct adapter * padapter,struct net_device * pnetdev)150 static void loadparam(struct adapter *padapter, struct net_device *pnetdev)
151 {
152 	struct registry_priv  *registry_par = &padapter->registrypriv;
153 
154 	GlobalDebugLevel = rtw_debug;
155 
156 	memcpy(registry_par->ssid.Ssid, "ANY", 3);
157 	registry_par->ssid.SsidLength = 3;
158 
159 	registry_par->channel = (u8)rtw_channel;
160 	registry_par->wireless_mode = (u8)rtw_wireless_mode;
161 	registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense;
162 	registry_par->vcs_type = (u8)rtw_vcs_type;
163 	registry_par->rts_thresh = (u16)rtw_rts_thresh;
164 	registry_par->frag_thresh = (u16)rtw_frag_thresh;
165 	registry_par->preamble = (u8)rtw_preamble;
166 	registry_par->smart_ps =  (u8)rtw_smart_ps;
167 	registry_par->power_mgnt = (u8)rtw_power_mgnt;
168 	registry_par->ips_mode = (u8)rtw_ips_mode;
169 	registry_par->mp_mode = 0;
170 	registry_par->software_encrypt = (u8)rtw_software_encrypt;
171 	registry_par->software_decrypt = (u8)rtw_software_decrypt;
172 	registry_par->acm_method = (u8)rtw_acm_method;
173 
174 	 /* UAPSD */
175 	registry_par->wmm_enable = (u8)rtw_wmm_enable;
176 	registry_par->uapsd_enable = (u8)rtw_uapsd_enable;
177 
178 	registry_par->ht_enable = (u8)rtw_ht_enable;
179 	registry_par->cbw40_enable = (u8)rtw_cbw40_enable;
180 	registry_par->ampdu_enable = (u8)rtw_ampdu_enable;
181 	registry_par->rx_stbc = (u8)rtw_rx_stbc;
182 	registry_par->ampdu_amsdu = (u8)rtw_ampdu_amsdu;
183 	registry_par->wifi_spec = (u8)rtw_wifi_spec;
184 	registry_par->channel_plan = (u8)rtw_channel_plan;
185 	registry_par->accept_addba_req = true;
186 	registry_par->antdiv_cfg = (u8)rtw_antdiv_cfg;
187 	registry_par->antdiv_type = (u8)rtw_antdiv_type;
188 	registry_par->hwpdn_mode = (u8)rtw_hwpdn_mode;
189 
190 	registry_par->max_roaming_times = (u8)rtw_max_roaming_times;
191 
192 	registry_par->fw_iol = rtw_fw_iol;
193 
194 	registry_par->enable80211d = (u8)rtw_80211d;
195 	snprintf(registry_par->ifname, 16, "%s", ifname);
196 	snprintf(registry_par->if2name, 16, "%s", if2name);
197 	registry_par->notch_filter = (u8)rtw_notch_filter;
198 	registry_par->monitor_enable = rtw_monitor_enable;
199 }
200 
rtw_net_set_mac_address(struct net_device * pnetdev,void * p)201 static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
202 {
203 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
204 	struct sockaddr *addr = p;
205 
206 	if (!padapter->bup)
207 		memcpy(padapter->eeprompriv.mac_addr, addr->sa_data, ETH_ALEN);
208 
209 	return 0;
210 }
211 
rtw_net_get_stats(struct net_device * pnetdev)212 static struct net_device_stats *rtw_net_get_stats(struct net_device *pnetdev)
213 {
214 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
215 	struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
216 	struct recv_priv *precvpriv = &(padapter->recvpriv);
217 
218 	padapter->stats.tx_packets = pxmitpriv->tx_pkts;
219 	padapter->stats.rx_packets = precvpriv->rx_pkts;
220 	padapter->stats.tx_dropped = pxmitpriv->tx_drop;
221 	padapter->stats.rx_dropped = precvpriv->rx_drop;
222 	padapter->stats.tx_bytes = pxmitpriv->tx_bytes;
223 	padapter->stats.rx_bytes = precvpriv->rx_bytes;
224 	return &padapter->stats;
225 }
226 
227 /*
228  * AC to queue mapping
229  *
230  * AC_VO -> queue 0
231  * AC_VI -> queue 1
232  * AC_BE -> queue 2
233  * AC_BK -> queue 3
234  */
235 static const u16 rtw_1d_to_queue[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
236 
237 /* Given a data frame determine the 802.1p/1d tag to use. */
rtw_classify8021d(struct sk_buff * skb)238 static unsigned int rtw_classify8021d(struct sk_buff *skb)
239 {
240 	unsigned int dscp;
241 
242 	/* skb->priority values from 256->263 are magic values to
243 	 * directly indicate a specific 802.1d priority.  This is used
244 	 * to allow 802.1d priority to be passed directly in from VLAN
245 	 * tags, etc.
246 	 */
247 	if (skb->priority >= 256 && skb->priority <= 263)
248 		return skb->priority - 256;
249 
250 	switch (skb->protocol) {
251 	case htons(ETH_P_IP):
252 		dscp = ip_hdr(skb)->tos & 0xfc;
253 		break;
254 	default:
255 		return 0;
256 	}
257 
258 	return dscp >> 5;
259 }
260 
rtw_select_queue(struct net_device * dev,struct sk_buff * skb,void * accel_priv,select_queue_fallback_t fallback)261 static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb,
262 			    void *accel_priv, select_queue_fallback_t fallback)
263 {
264 	struct adapter	*padapter = rtw_netdev_priv(dev);
265 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
266 
267 	skb->priority = rtw_classify8021d(skb);
268 
269 	if (pmlmepriv->acm_mask != 0)
270 		skb->priority = qos_acm(pmlmepriv->acm_mask, skb->priority);
271 
272 	return rtw_1d_to_queue[skb->priority];
273 }
274 
rtw_recv_select_queue(struct sk_buff * skb)275 u16 rtw_recv_select_queue(struct sk_buff *skb)
276 {
277 	struct iphdr *piphdr;
278 	unsigned int dscp;
279 	__be16	eth_type;
280 	u32 priority;
281 	u8 *pdata = skb->data;
282 
283 	memcpy(&eth_type, pdata+(ETH_ALEN<<1), 2);
284 
285 	switch (eth_type) {
286 	case htons(ETH_P_IP):
287 		piphdr = (struct iphdr *)(pdata+ETH_HLEN);
288 		dscp = piphdr->tos & 0xfc;
289 		priority = dscp >> 5;
290 		break;
291 	default:
292 		priority = 0;
293 	}
294 
295 	return rtw_1d_to_queue[priority];
296 }
297 
298 static const struct net_device_ops rtw_netdev_ops = {
299 	.ndo_open = netdev_open,
300 	.ndo_stop = netdev_close,
301 	.ndo_start_xmit = rtw_xmit_entry,
302 	.ndo_select_queue	= rtw_select_queue,
303 	.ndo_set_mac_address = rtw_net_set_mac_address,
304 	.ndo_get_stats = rtw_net_get_stats,
305 	.ndo_do_ioctl = rtw_ioctl,
306 };
307 
rtw_init_netdev_name(struct net_device * pnetdev,const char * ifname)308 int rtw_init_netdev_name(struct net_device *pnetdev, const char *ifname)
309 {
310 	if (dev_alloc_name(pnetdev, ifname) < 0)
311 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("dev_alloc_name, fail!\n"));
312 
313 	netif_carrier_off(pnetdev);
314 	return 0;
315 }
316 
317 static const struct device_type wlan_type = {
318 	.name = "wlan",
319 };
320 
rtw_init_netdev(struct adapter * old_padapter)321 struct net_device *rtw_init_netdev(struct adapter *old_padapter)
322 {
323 	struct adapter *padapter;
324 	struct net_device *pnetdev = NULL;
325 
326 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+init_net_dev\n"));
327 
328 	if (old_padapter != NULL)
329 		pnetdev = rtw_alloc_etherdev_with_old_priv((void *)old_padapter);
330 
331 	if (!pnetdev)
332 		return NULL;
333 
334 	pnetdev->dev.type = &wlan_type;
335 	padapter = rtw_netdev_priv(pnetdev);
336 	padapter->pnetdev = pnetdev;
337 	DBG_88E("register rtw_netdev_ops to netdev_ops\n");
338 	pnetdev->netdev_ops = &rtw_netdev_ops;
339 	pnetdev->watchdog_timeo = HZ*3; /* 3 second timeout */
340 	pnetdev->wireless_handlers = (struct iw_handler_def *)&rtw_handlers_def;
341 
342 	loadparam(padapter, pnetdev);
343 
344 	return pnetdev;
345 }
346 
rtw_start_drv_threads(struct adapter * padapter)347 static int rtw_start_drv_threads(struct adapter *padapter)
348 {
349 	int err = 0;
350 
351 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_start_drv_threads\n"));
352 
353 	padapter->cmdThread = kthread_run(rtw_cmd_thread, padapter,
354 					  "RTW_CMD_THREAD");
355 	if (IS_ERR(padapter->cmdThread))
356 		err = PTR_ERR(padapter->cmdThread);
357 	else
358 		/* wait for cmd_thread to run */
359 		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
360 
361 	return err;
362 }
363 
rtw_stop_drv_threads(struct adapter * padapter)364 void rtw_stop_drv_threads(struct adapter *padapter)
365 {
366 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
367 
368 	/* Below is to terminate rtw_cmd_thread & event_thread... */
369 	complete(&padapter->cmdpriv.cmd_queue_comp);
370 	if (padapter->cmdThread)
371 		wait_for_completion_interruptible(&padapter->cmdpriv.terminate_cmdthread_comp);
372 
373 }
374 
rtw_init_default_value(struct adapter * padapter)375 static u8 rtw_init_default_value(struct adapter *padapter)
376 {
377 	struct registry_priv *pregistrypriv = &padapter->registrypriv;
378 	struct xmit_priv	*pxmitpriv = &padapter->xmitpriv;
379 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
380 	struct security_priv *psecuritypriv = &padapter->securitypriv;
381 
382 	/* xmit_priv */
383 	pxmitpriv->vcs_setting = pregistrypriv->vrtl_carrier_sense;
384 	pxmitpriv->vcs = pregistrypriv->vcs_type;
385 	pxmitpriv->vcs_type = pregistrypriv->vcs_type;
386 	pxmitpriv->frag_len = pregistrypriv->frag_thresh;
387 
388 	/* mlme_priv */
389 	pmlmepriv->scan_interval = SCAN_INTERVAL;/*  30*2 sec = 60sec */
390 	pmlmepriv->scan_mode = SCAN_ACTIVE;
391 
392 	/* ht_priv */
393 	pmlmepriv->htpriv.ampdu_enable = false;/* set to disabled */
394 
395 	/* security_priv */
396 	psecuritypriv->binstallGrpkey = _FAIL;
397 	psecuritypriv->sw_encrypt = pregistrypriv->software_encrypt;
398 	psecuritypriv->sw_decrypt = pregistrypriv->software_decrypt;
399 	psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
400 	psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
401 	psecuritypriv->dot11PrivacyKeyIndex = 0;
402 	psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
403 	psecuritypriv->dot118021XGrpKeyid = 1;
404 	psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
405 	psecuritypriv->ndisencryptstatus = Ndis802_11WEPDisabled;
406 
407 	/* registry_priv */
408 	rtw_init_registrypriv_dev_network(padapter);
409 	rtw_update_registrypriv_dev_network(padapter);
410 
411 	/* hal_priv */
412 	rtw_hal_def_value_init(padapter);
413 
414 	/* misc. */
415 	padapter->bReadPortCancel = false;
416 	padapter->bWritePortCancel = false;
417 	padapter->bRxRSSIDisplay = 0;
418 	return _SUCCESS;
419 }
420 
rtw_reset_drv_sw(struct adapter * padapter)421 u8 rtw_reset_drv_sw(struct adapter *padapter)
422 {
423 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
424 	struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
425 
426 	/* hal_priv */
427 	rtw_hal_def_value_init(padapter);
428 	padapter->bReadPortCancel = false;
429 	padapter->bWritePortCancel = false;
430 	padapter->bRxRSSIDisplay = 0;
431 	pmlmepriv->scan_interval = SCAN_INTERVAL;/*  30*2 sec = 60sec */
432 
433 	padapter->xmitpriv.tx_pkts = 0;
434 	padapter->recvpriv.rx_pkts = 0;
435 
436 	pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
437 
438 	_clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING);
439 	rtw_hal_sreset_init(padapter);
440 	pwrctrlpriv->pwr_state_check_cnts = 0;
441 
442 	/* mlmeextpriv */
443 	padapter->mlmeextpriv.sitesurvey_res.state = SCAN_DISABLE;
444 
445 	rtw_set_signal_stat_timer(&padapter->recvpriv);
446 
447 	return _SUCCESS;
448 }
449 
rtw_init_drv_sw(struct adapter * padapter)450 u8 rtw_init_drv_sw(struct adapter *padapter)
451 {
452 	u8	ret8 = _SUCCESS;
453 
454 
455 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_init_drv_sw\n"));
456 
457 	if ((rtw_init_cmd_priv(&padapter->cmdpriv)) == _FAIL) {
458 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init cmd_priv\n"));
459 		ret8 = _FAIL;
460 		goto exit;
461 	}
462 
463 	padapter->cmdpriv.padapter = padapter;
464 
465 	if (rtw_init_mlme_priv(padapter) == _FAIL) {
466 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init mlme_priv\n"));
467 		ret8 = _FAIL;
468 		goto exit;
469 	}
470 
471 	if (init_mlme_ext_priv(padapter) == _FAIL) {
472 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init mlme_ext_priv\n"));
473 		ret8 = _FAIL;
474 		goto exit;
475 	}
476 
477 	if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) {
478 		DBG_88E("Can't _rtw_init_xmit_priv\n");
479 		ret8 = _FAIL;
480 		goto exit;
481 	}
482 
483 	if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) {
484 		DBG_88E("Can't _rtw_init_recv_priv\n");
485 		ret8 = _FAIL;
486 		goto exit;
487 	}
488 
489 	if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) {
490 		DBG_88E("Can't _rtw_init_sta_priv\n");
491 		ret8 = _FAIL;
492 		goto exit;
493 	}
494 
495 	padapter->stapriv.padapter = padapter;
496 
497 	rtw_init_bcmc_stainfo(padapter);
498 
499 	rtw_init_pwrctrl_priv(padapter);
500 
501 	ret8 = rtw_init_default_value(padapter);
502 
503 	rtw_hal_dm_init(padapter);
504 	rtw_hal_sw_led_init(padapter);
505 
506 	rtw_hal_sreset_init(padapter);
507 
508 exit:
509 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_init_drv_sw\n"));
510 
511 
512 	return ret8;
513 }
514 
rtw_cancel_all_timer(struct adapter * padapter)515 void rtw_cancel_all_timer(struct adapter *padapter)
516 {
517 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_cancel_all_timer\n"));
518 
519 	del_timer_sync(&padapter->mlmepriv.assoc_timer);
520 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel association timer complete!\n"));
521 
522 	del_timer_sync(&padapter->mlmepriv.scan_to_timer);
523 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel scan_to_timer!\n"));
524 
525 	del_timer_sync(&padapter->mlmepriv.dynamic_chk_timer);
526 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel dynamic_chk_timer!\n"));
527 
528 	/*  cancel sw led timer */
529 	rtw_hal_sw_led_deinit(padapter);
530 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel DeInitSwLeds!\n"));
531 
532 	del_timer_sync(&padapter->pwrctrlpriv.pwr_state_check_timer);
533 
534 	del_timer_sync(&padapter->recvpriv.signal_stat_timer);
535 }
536 
rtw_free_drv_sw(struct adapter * padapter)537 u8 rtw_free_drv_sw(struct adapter *padapter)
538 {
539 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("==>rtw_free_drv_sw"));
540 
541 	free_mlme_ext_priv(&padapter->mlmeextpriv);
542 
543 	rtw_free_mlme_priv(&padapter->mlmepriv);
544 	_rtw_free_xmit_priv(&padapter->xmitpriv);
545 
546 	/* will free bcmc_stainfo here */
547 	_rtw_free_sta_priv(&padapter->stapriv);
548 
549 	_rtw_free_recv_priv(&padapter->recvpriv);
550 
551 	rtw_hal_free_data(padapter);
552 
553 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("<== rtw_free_drv_sw\n"));
554 
555 	mutex_destroy(&padapter->hw_init_mutex);
556 
557 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_free_drv_sw\n"));
558 
559 	return _SUCCESS;
560 }
561 
_netdev_open(struct net_device * pnetdev)562 static int _netdev_open(struct net_device *pnetdev)
563 {
564 	uint status;
565 	int err;
566 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
567 	struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
568 
569 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+88eu_drv - dev_open\n"));
570 	DBG_88E("+88eu_drv - drv_open, bup =%d\n", padapter->bup);
571 
572 	if (pwrctrlpriv->ps_flag) {
573 		padapter->net_closed = false;
574 		goto netdev_open_normal_process;
575 	}
576 
577 	if (!padapter->bup) {
578 		padapter->bDriverStopped = false;
579 		padapter->bSurpriseRemoved = false;
580 
581 		status = rtw_hal_init(padapter);
582 		if (status == _FAIL) {
583 			RT_TRACE(_module_os_intfs_c_, _drv_err_, ("rtl88eu_hal_init(): Can't init h/w!\n"));
584 			goto netdev_open_error;
585 		}
586 
587 		pr_info("MAC Address = %pM\n", pnetdev->dev_addr);
588 
589 		err = rtw_start_drv_threads(padapter);
590 		if (err) {
591 			pr_info("Initialize driver software resource Failed!\n");
592 			goto netdev_open_error;
593 		}
594 
595 		if (init_hw_mlme_ext(padapter) == _FAIL) {
596 			pr_info("can't init mlme_ext_priv\n");
597 			goto netdev_open_error;
598 		}
599 		if (padapter->intf_start)
600 			padapter->intf_start(padapter);
601 
602 		rtw_led_control(padapter, LED_CTL_NO_LINK);
603 
604 		padapter->bup = true;
605 	}
606 	padapter->net_closed = false;
607 
608 	mod_timer(&padapter->mlmepriv.dynamic_chk_timer,
609 		  jiffies + msecs_to_jiffies(2000));
610 
611 	padapter->pwrctrlpriv.bips_processing = false;
612 	rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
613 
614 	if (!rtw_netif_queue_stopped(pnetdev))
615 		netif_tx_start_all_queues(pnetdev);
616 	else
617 		netif_tx_wake_all_queues(pnetdev);
618 
619 netdev_open_normal_process:
620 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-88eu_drv - dev_open\n"));
621 	DBG_88E("-88eu_drv - drv_open, bup =%d\n", padapter->bup);
622 	return 0;
623 
624 netdev_open_error:
625 	padapter->bup = false;
626 	netif_carrier_off(pnetdev);
627 	netif_tx_stop_all_queues(pnetdev);
628 	RT_TRACE(_module_os_intfs_c_, _drv_err_, ("-88eu_drv - dev_open, fail!\n"));
629 	DBG_88E("-88eu_drv - drv_open fail, bup =%d\n", padapter->bup);
630 	return -1;
631 }
632 
netdev_open(struct net_device * pnetdev)633 static int netdev_open(struct net_device *pnetdev)
634 {
635 	int ret;
636 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
637 
638 	if (mutex_lock_interruptible(&padapter->hw_init_mutex))
639 		return -ERESTARTSYS;
640 	ret = _netdev_open(pnetdev);
641 	mutex_unlock(&padapter->hw_init_mutex);
642 	return ret;
643 }
644 
ips_netdrv_open(struct adapter * padapter)645 static int  ips_netdrv_open(struct adapter *padapter)
646 {
647 	int status = _SUCCESS;
648 
649 	padapter->net_closed = false;
650 	DBG_88E("===> %s.........\n", __func__);
651 
652 	padapter->bDriverStopped = false;
653 	padapter->bSurpriseRemoved = false;
654 
655 	status = rtw_hal_init(padapter);
656 	if (status == _FAIL) {
657 		RT_TRACE(_module_os_intfs_c_, _drv_err_, ("ips_netdrv_open(): Can't init h/w!\n"));
658 		goto netdev_open_error;
659 	}
660 
661 	if (padapter->intf_start)
662 		padapter->intf_start(padapter);
663 
664 	rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
665 	mod_timer(&padapter->mlmepriv.dynamic_chk_timer,
666 		  jiffies + msecs_to_jiffies(5000));
667 
668 	 return _SUCCESS;
669 
670 netdev_open_error:
671 	DBG_88E("-ips_netdrv_open - drv_open failure, bup =%d\n", padapter->bup);
672 
673 	return _FAIL;
674 }
675 
676 
rtw_ips_pwr_up(struct adapter * padapter)677 int rtw_ips_pwr_up(struct adapter *padapter)
678 {
679 	int result;
680 	unsigned long start_time = jiffies;
681 
682 	DBG_88E("===>  rtw_ips_pwr_up..............\n");
683 	rtw_reset_drv_sw(padapter);
684 
685 	result = ips_netdrv_open(padapter);
686 
687 	rtw_led_control(padapter, LED_CTL_NO_LINK);
688 
689 	DBG_88E("<===  rtw_ips_pwr_up.............. in %dms\n",
690 		jiffies_to_msecs(jiffies - start_time));
691 	return result;
692 }
693 
rtw_ips_pwr_down(struct adapter * padapter)694 void rtw_ips_pwr_down(struct adapter *padapter)
695 {
696 	unsigned long start_time = jiffies;
697 
698 	DBG_88E("===> rtw_ips_pwr_down...................\n");
699 
700 	padapter->net_closed = true;
701 
702 	rtw_led_control(padapter, LED_CTL_POWER_OFF);
703 
704 	rtw_ips_dev_unload(padapter);
705 	DBG_88E("<=== rtw_ips_pwr_down..................... in %dms\n",
706 		jiffies_to_msecs(jiffies - start_time));
707 }
708 
rtw_ips_dev_unload(struct adapter * padapter)709 void rtw_ips_dev_unload(struct adapter *padapter)
710 {
711 	DBG_88E("====> %s...\n", __func__);
712 
713 	rtw_hal_set_hwreg(padapter, HW_VAR_FIFO_CLEARN_UP, NULL);
714 
715 	if (padapter->intf_stop)
716 		padapter->intf_stop(padapter);
717 
718 	/* s5. */
719 	if (!padapter->bSurpriseRemoved)
720 		rtw_hal_deinit(padapter);
721 }
722 
pm_netdev_open(struct net_device * pnetdev,u8 bnormal)723 int pm_netdev_open(struct net_device *pnetdev, u8 bnormal)
724 {
725 	int status;
726 
727 	if (bnormal)
728 		status = netdev_open(pnetdev);
729 	else
730 		status =  (_SUCCESS == ips_netdrv_open((struct adapter *)rtw_netdev_priv(pnetdev))) ? (0) : (-1);
731 	return status;
732 }
733 
netdev_close(struct net_device * pnetdev)734 static int netdev_close(struct net_device *pnetdev)
735 {
736 	struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
737 
738 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+88eu_drv - drv_close\n"));
739 
740 	if (padapter->pwrctrlpriv.bInternalAutoSuspend) {
741 		if (padapter->pwrctrlpriv.rf_pwrstate == rf_off)
742 			padapter->pwrctrlpriv.ps_flag = true;
743 	}
744 	padapter->net_closed = true;
745 
746 	if (padapter->pwrctrlpriv.rf_pwrstate == rf_on) {
747 		DBG_88E("(2)88eu_drv - drv_close, bup =%d, hw_init_completed =%d\n",
748 			padapter->bup, padapter->hw_init_completed);
749 
750 		/* s1. */
751 		if (pnetdev) {
752 			if (!rtw_netif_queue_stopped(pnetdev))
753 				netif_tx_stop_all_queues(pnetdev);
754 		}
755 
756 		/* s2. */
757 		LeaveAllPowerSaveMode(padapter);
758 		rtw_disassoc_cmd(padapter, 500, false);
759 		/* s2-2.  indicate disconnect to os */
760 		rtw_indicate_disconnect(padapter);
761 		/* s2-3. */
762 		rtw_free_assoc_resources(padapter);
763 		/* s2-4. */
764 		rtw_free_network_queue(padapter, true);
765 		/*  Close LED */
766 		rtw_led_control(padapter, LED_CTL_POWER_OFF);
767 	}
768 
769 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-88eu_drv - drv_close\n"));
770 	DBG_88E("-88eu_drv - drv_close, bup =%d\n", padapter->bup);
771 	return 0;
772 }
773