• 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 <drv_types.h>
19 #include <xmit_osdep.h>
20 #include <recv_osdep.h>
21 #include <hal_intf.h>
22 #include <rtw_version.h>
23 
24 #include <rtl8723a_hal.h>
25 
26 MODULE_LICENSE("GPL");
27 MODULE_DESCRIPTION("Realtek Wireless Lan Driver");
28 MODULE_AUTHOR("Realtek Semiconductor Corp.");
29 MODULE_AUTHOR("Larry Finger <Larry.Finger@lwfinger.net>");
30 MODULE_AUTHOR("Jes Sorensen <Jes.Sorensen@redhat.com>");
31 MODULE_VERSION(DRIVERVERSION);
32 MODULE_FIRMWARE("rtlwifi/rtl8723aufw_A.bin");
33 MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B.bin");
34 MODULE_FIRMWARE("rtlwifi/rtl8723aufw_B_NoBT.bin");
35 
36 /* module param defaults */
37 static int rtw_chip_version = 0x00;
38 static int rtw_rfintfs = HWPI;
39 static int rtw_debug = 1;
40 
41 static int rtw_channel = 1;/* ad-hoc support requirement */
42 static int rtw_wireless_mode = WIRELESS_11BG_24N;
43 static int rtw_vrtl_carrier_sense = AUTO_VCS;
44 static int rtw_vcs_type = RTS_CTS;/*  */
45 static int rtw_rts_thresh = 2347;/*  */
46 static int rtw_frag_thresh = 2346;/*  */
47 static int rtw_preamble = PREAMBLE_LONG;/* long, short, auto */
48 static int rtw_scan_mode = 1;/* active, passive */
49 static int rtw_adhoc_tx_pwr = 1;
50 static int rtw_soft_ap;
51 static int rtw_power_mgnt = 1;
52 static int rtw_ips_mode = IPS_NORMAL;
53 
54 static int rtw_smart_ps = 2;
55 
56 module_param(rtw_ips_mode, int, 0644);
57 MODULE_PARM_DESC(rtw_ips_mode, "The default IPS mode");
58 
59 static int rtw_long_retry_lmt = 7;
60 static int rtw_short_retry_lmt = 7;
61 static int rtw_busy_thresh = 40;
62 static int rtw_ack_policy = NORMAL_ACK;
63 
64 static int rtw_acm_method;/*  0:By SW 1:By HW. */
65 
66 static int rtw_wmm_enable = 1;/*  default is set to enable the wmm. */
67 static int rtw_uapsd_enable;
68 
69 static int rtw_ht_enable = 1;
70 /* 0 :diable, bit(0): enable 2.4g, bit(1): enable 5g */
71 static int rtw_cbw40_enable = 3;
72 static int rtw_ampdu_enable = 1;/* for enable tx_ampdu */
73 /*  0: disable, bit(0):enable 2.4g, bit(1):enable 5g, default is set to enable
74  * 2.4GHZ for IOT issue with bufflao's AP at 5GHZ
75  */
76 static int rtw_rx_stbc = 1;
77 static int rtw_ampdu_amsdu;/*  0: disabled, 1:enabled, 2:auto */
78 
79 /* Use 2 path Tx to transmit MCS0~7 and legacy mode */
80 static int rtw_lowrate_two_xmit = 1;
81 
82 /* int rf_config = RF_1T2R;  1T2R */
83 static int rtw_rf_config = RF_819X_MAX_TYPE;  /* auto */
84 static int rtw_low_power;
85 static int rtw_wifi_spec;
86 static int rtw_channel_plan = RT_CHANNEL_DOMAIN_MAX;
87 
88 #ifdef CONFIG_8723AU_BT_COEXIST
89 static int rtw_btcoex_enable = 1;
90 static int rtw_bt_iso = 2;/*  0:Low, 1:High, 2:From Efuse */
91 /*  0:Idle, 1:None-SCO, 2:SCO, 3:From Counter, 4.Busy, 5.OtherBusy */
92 static int rtw_bt_sco = 3;
93 /*  0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
94 static int rtw_bt_ampdu = 1 ;
95 #endif
96 
97 /*  0:Reject AP's Add BA req, 1:Accept AP's Add BA req. */
98 static int rtw_AcceptAddbaReq = true;
99 
100 static int rtw_antdiv_cfg = 2; /*  0:OFF , 1:ON, 2:decide by Efuse config */
101 static int rtw_antdiv_type; /* 0:decide by efuse */
102 
103 static int rtw_enusbss;/* 0:disable, 1:enable */
104 
105 static int rtw_hwpdn_mode = 2;/* 0:disable, 1:enable, 2: by EFUSE config */
106 
107 static int rtw_hwpwrp_detect; /* HW power  ping detect 0:disable , 1:enable */
108 
109 static int rtw_hw_wps_pbc = 1;
110 
111 static int rtw_80211d;
112 
113 static int rtw_regulatory_id = 0xff;/*  Regulatory tab id, 0xff = follow efuse's setting */
114 
115 module_param(rtw_regulatory_id, int, 0644);
116 
117 static char *ifname = "wlan%d";
118 module_param(ifname, charp, 0644);
119 MODULE_PARM_DESC(ifname, "The default name to allocate for first interface");
120 
121 static char *if2name = "wlan%d";
122 module_param(if2name, charp, 0644);
123 MODULE_PARM_DESC(if2name, "The default name to allocate for second interface");
124 
125 module_param(rtw_channel_plan, int, 0644);
126 module_param(rtw_chip_version, int, 0644);
127 module_param(rtw_rfintfs, int, 0644);
128 module_param(rtw_channel, int, 0644);
129 module_param(rtw_wmm_enable, int, 0644);
130 module_param(rtw_vrtl_carrier_sense, int, 0644);
131 module_param(rtw_vcs_type, int, 0644);
132 module_param(rtw_busy_thresh, int, 0644);
133 module_param(rtw_ht_enable, int, 0644);
134 module_param(rtw_cbw40_enable, int, 0644);
135 module_param(rtw_ampdu_enable, int, 0644);
136 module_param(rtw_rx_stbc, int, 0644);
137 module_param(rtw_ampdu_amsdu, int, 0644);
138 
139 module_param(rtw_lowrate_two_xmit, int, 0644);
140 
141 module_param(rtw_rf_config, int, 0644);
142 module_param(rtw_power_mgnt, int, 0644);
143 module_param(rtw_smart_ps, int, 0644);
144 module_param(rtw_low_power, int, 0644);
145 module_param(rtw_wifi_spec, int, 0644);
146 
147 module_param(rtw_antdiv_cfg, int, 0644);
148 
149 module_param(rtw_enusbss, int, 0644);
150 module_param(rtw_hwpdn_mode, int, 0644);
151 module_param(rtw_hwpwrp_detect, int, 0644);
152 
153 module_param(rtw_hw_wps_pbc, int, 0644);
154 
155 static uint rtw_max_roaming_times = 2;
156 module_param(rtw_max_roaming_times, uint, 0644);
157 MODULE_PARM_DESC(rtw_max_roaming_times, "The max roaming times to try");
158 
159 module_param(rtw_80211d, int, 0644);
160 MODULE_PARM_DESC(rtw_80211d, "Enable 802.11d mechanism");
161 
162 #ifdef CONFIG_8723AU_BT_COEXIST
163 module_param(rtw_btcoex_enable, int, 0644);
164 MODULE_PARM_DESC(rtw_btcoex_enable, "Enable BT co-existence mechanism");
165 #endif
166 
167 static uint rtw_notch_filter;
168 module_param(rtw_notch_filter, uint, 0644);
169 MODULE_PARM_DESC(rtw_notch_filter, "0:Disable, 1:Enable, 2:Enable only for P2P");
170 module_param_named(debug, rtw_debug, int, 0444);
171 MODULE_PARM_DESC(debug, "Set debug level (1-9) (default 1)");
172 
173 static int netdev_close(struct net_device *pnetdev);
174 
loadparam(struct rtw_adapter * padapter,struct net_device * pnetdev)175 static int loadparam(struct rtw_adapter *padapter,  struct net_device *pnetdev)
176 {
177 	struct registry_priv  *registry_par = &padapter->registrypriv;
178 	int status = _SUCCESS;
179 
180 	GlobalDebugLevel23A = rtw_debug;
181 	registry_par->chip_version = (u8)rtw_chip_version;
182 	registry_par->rfintfs = (u8)rtw_rfintfs;
183 	memcpy(registry_par->ssid.ssid, "ANY", 3);
184 	registry_par->ssid.ssid_len = 3;
185 	registry_par->channel = (u8)rtw_channel;
186 	registry_par->wireless_mode = (u8)rtw_wireless_mode;
187 	registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense;
188 	registry_par->vcs_type = (u8)rtw_vcs_type;
189 	registry_par->rts_thresh = (u16)rtw_rts_thresh;
190 	registry_par->frag_thresh = (u16)rtw_frag_thresh;
191 	registry_par->preamble = (u8)rtw_preamble;
192 	registry_par->scan_mode = (u8)rtw_scan_mode;
193 	registry_par->adhoc_tx_pwr = (u8)rtw_adhoc_tx_pwr;
194 	registry_par->soft_ap =  (u8)rtw_soft_ap;
195 	registry_par->smart_ps =  (u8)rtw_smart_ps;
196 	registry_par->power_mgnt = (u8)rtw_power_mgnt;
197 	registry_par->ips_mode = (u8)rtw_ips_mode;
198 	registry_par->long_retry_lmt = (u8)rtw_long_retry_lmt;
199 	registry_par->short_retry_lmt = (u8)rtw_short_retry_lmt;
200 	registry_par->busy_thresh = (u16)rtw_busy_thresh;
201 	registry_par->ack_policy = (u8)rtw_ack_policy;
202 	registry_par->acm_method = (u8)rtw_acm_method;
203 	 /* UAPSD */
204 	registry_par->wmm_enable = (u8)rtw_wmm_enable;
205 	registry_par->uapsd_enable = (u8)rtw_uapsd_enable;
206 	registry_par->ht_enable = (u8)rtw_ht_enable;
207 	registry_par->cbw40_enable = (u8)rtw_cbw40_enable;
208 	registry_par->ampdu_enable = (u8)rtw_ampdu_enable;
209 	registry_par->rx_stbc = (u8)rtw_rx_stbc;
210 	registry_par->ampdu_amsdu = (u8)rtw_ampdu_amsdu;
211 	registry_par->lowrate_two_xmit = (u8)rtw_lowrate_two_xmit;
212 	registry_par->rf_config = (u8)rtw_rf_config;
213 	registry_par->low_power = (u8)rtw_low_power;
214 	registry_par->wifi_spec = (u8)rtw_wifi_spec;
215 	registry_par->channel_plan = (u8)rtw_channel_plan;
216 #ifdef CONFIG_8723AU_BT_COEXIST
217 	registry_par->btcoex = (u8)rtw_btcoex_enable;
218 	registry_par->bt_iso = (u8)rtw_bt_iso;
219 	registry_par->bt_sco = (u8)rtw_bt_sco;
220 	registry_par->bt_ampdu = (u8)rtw_bt_ampdu;
221 #endif
222 	registry_par->bAcceptAddbaReq = (u8)rtw_AcceptAddbaReq;
223 	registry_par->antdiv_cfg = (u8)rtw_antdiv_cfg;
224 	registry_par->antdiv_type = (u8)rtw_antdiv_type;
225 
226 	/* 0:disable, 1:enable, 2:by EFUSE config */
227 	registry_par->hwpdn_mode = (u8)rtw_hwpdn_mode;
228 	/* 0:disable, 1:enable */
229 	registry_par->hwpwrp_detect = (u8)rtw_hwpwrp_detect;
230 	registry_par->hw_wps_pbc = (u8)rtw_hw_wps_pbc;
231 	registry_par->max_roaming_times = (u8)rtw_max_roaming_times;
232 	registry_par->enable80211d = (u8)rtw_80211d;
233 	snprintf(registry_par->ifname, 16, "%s", ifname);
234 	snprintf(registry_par->if2name, 16, "%s", if2name);
235 	registry_par->notch_filter = (u8)rtw_notch_filter;
236 	registry_par->regulatory_tid = (u8)rtw_regulatory_id;
237 	return status;
238 }
239 
rtw_net_set_mac_address(struct net_device * pnetdev,void * p)240 static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
241 {
242 	struct rtw_adapter *padapter = netdev_priv(pnetdev);
243 	struct sockaddr *addr = p;
244 
245 	if (!padapter->bup)
246 		ether_addr_copy(padapter->eeprompriv.mac_addr, addr->sa_data);
247 	return 0;
248 }
249 
rtw_net_get_stats(struct net_device * pnetdev)250 static struct net_device_stats *rtw_net_get_stats(struct net_device *pnetdev)
251 {
252 	struct rtw_adapter *padapter = netdev_priv(pnetdev);
253 	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
254 	struct recv_priv *precvpriv = &padapter->recvpriv;
255 
256 	padapter->stats.tx_packets = pxmitpriv->tx_pkts;
257 	padapter->stats.rx_packets = precvpriv->rx_pkts;
258 	padapter->stats.tx_dropped = pxmitpriv->tx_drop;
259 	padapter->stats.rx_dropped = precvpriv->rx_drop;
260 	padapter->stats.tx_bytes = pxmitpriv->tx_bytes;
261 	padapter->stats.rx_bytes = precvpriv->rx_bytes;
262 
263 	return &padapter->stats;
264 }
265 
266 /*
267  * AC to queue mapping
268  *
269  * AC_VO -> queue 0
270  * AC_VI -> queue 1
271  * AC_BE -> queue 2
272  * AC_BK -> queue 3
273  */
274 static const u16 rtw_1d_to_queue[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
275 
276 /* Given a data frame determine the 802.1p/1d tag to use. */
rtw_classify8021d(struct sk_buff * skb)277 static u32 rtw_classify8021d(struct sk_buff *skb)
278 {
279 	u32 dscp;
280 
281 	/* skb->priority values from 256->263 are magic values to
282 	 * directly indicate a specific 802.1d priority.  This is used
283 	 * to allow 802.1d priority to be passed directly in from VLAN
284 	 * tags, etc.
285 	 */
286 	if (skb->priority >= 256 && skb->priority <= 263)
287 		return skb->priority - 256;
288 	switch (skb->protocol) {
289 	case htons(ETH_P_IP):
290 		dscp = ip_hdr(skb)->tos & 0xfc;
291 		break;
292 	default:
293 		return 0;
294 	}
295 	return dscp >> 5;
296 }
297 
rtw_select_queue(struct net_device * dev,struct sk_buff * skb,void * accel_priv,select_queue_fallback_t fallback)298 static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb,
299 			    void *accel_priv,
300 			    select_queue_fallback_t fallback)
301 {
302 	struct rtw_adapter *padapter = netdev_priv(dev);
303 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
304 
305 	skb->priority = rtw_classify8021d(skb);
306 
307 	if (pmlmepriv->acm_mask != 0)
308 		skb->priority = qos_acm23a(pmlmepriv->acm_mask, skb->priority);
309 	return rtw_1d_to_queue[skb->priority];
310 }
311 
rtw_recv_select_queue23a(struct sk_buff * skb)312 u16 rtw_recv_select_queue23a(struct sk_buff *skb)
313 {
314 	struct iphdr *piphdr;
315 	struct ethhdr *eth = (struct ethhdr *)skb->data;
316 	unsigned int dscp;
317 	u16 eth_type = get_unaligned_be16(&eth->h_proto);
318 	u32 priority;
319 	u8 *pdata = skb->data;
320 
321 	switch (eth_type) {
322 	case ETH_P_IP:
323 		piphdr = (struct iphdr *)(pdata + ETH_HLEN);
324 		dscp = piphdr->tos & 0xfc;
325 		priority = dscp >> 5;
326 		break;
327 	default:
328 		priority = 0;
329 	}
330 	return rtw_1d_to_queue[priority];
331 }
332 
333 static const struct net_device_ops rtw_netdev_ops = {
334 	.ndo_open = netdev_open23a,
335 	.ndo_stop = netdev_close,
336 	.ndo_start_xmit = rtw_xmit23a_entry23a,
337 	.ndo_select_queue = rtw_select_queue,
338 	.ndo_set_mac_address = rtw_net_set_mac_address,
339 	.ndo_get_stats = rtw_net_get_stats,
340 };
341 
rtw_init_netdev23a_name23a(struct net_device * pnetdev,const char * ifname)342 int rtw_init_netdev23a_name23a(struct net_device *pnetdev, const char *ifname)
343 {
344 	if (dev_alloc_name(pnetdev, ifname) < 0) {
345 		RT_TRACE(_module_os_intfs_c_, _drv_err_,
346 			 ("dev_alloc_name, fail!\n"));
347 	}
348 	netif_carrier_off(pnetdev);
349 	return 0;
350 }
351 
352 static const struct device_type wlan_type = {
353 	.name = "wlan",
354 };
355 
rtw_init_netdev23a(struct rtw_adapter * old_padapter)356 struct net_device *rtw_init_netdev23a(struct rtw_adapter *old_padapter)
357 {
358 	struct rtw_adapter *padapter;
359 	struct net_device *pnetdev;
360 
361 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+init_net_dev\n"));
362 
363 	pnetdev = alloc_etherdev_mq(sizeof(struct rtw_adapter), 4);
364 	if (!pnetdev)
365 		return NULL;
366 
367 	pnetdev->dev.type = &wlan_type;
368 	padapter = netdev_priv(pnetdev);
369 	padapter->pnetdev = pnetdev;
370 
371 	DBG_8723A("register rtw_netdev_ops to netdev_ops\n");
372 	pnetdev->netdev_ops = &rtw_netdev_ops;
373 
374 	pnetdev->watchdog_timeo = HZ*3; /* 3 second timeout */
375 
376 	/* step 2. */
377 	loadparam(padapter, pnetdev);
378 	return pnetdev;
379 }
380 
rtw_init_default_value(struct rtw_adapter * padapter)381 static int rtw_init_default_value(struct rtw_adapter *padapter)
382 {
383 	struct registry_priv *pregistrypriv = &padapter->registrypriv;
384 	struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
385 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
386 	struct security_priv *psecuritypriv = &padapter->securitypriv;
387 	int ret = _SUCCESS;
388 
389 	/* xmit_priv */
390 	pxmitpriv->vcs_setting = pregistrypriv->vrtl_carrier_sense;
391 	pxmitpriv->vcs = pregistrypriv->vcs_type;
392 	pxmitpriv->vcs_type = pregistrypriv->vcs_type;
393 	/* pxmitpriv->rts_thresh = pregistrypriv->rts_thresh; */
394 	pxmitpriv->frag_len = pregistrypriv->frag_thresh;
395 
396 	/* mlme_priv */
397 	pmlmepriv->scan_interval = SCAN_INTERVAL;/*  30*2 sec = 60sec */
398 	pmlmepriv->scan_mode = SCAN_ACTIVE;
399 
400 	/* ht_priv */
401 	pmlmepriv->htpriv.ampdu_enable = false;/* set to disabled */
402 
403 	/* security_priv */
404 	psecuritypriv->binstallGrpkey = 0;
405 
406 	 /* open system */
407 	psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open;
408 	psecuritypriv->dot11PrivacyAlgrthm = 0;
409 
410 	psecuritypriv->dot11PrivacyKeyIndex = 0;
411 
412 	psecuritypriv->dot118021XGrpPrivacy = 0;
413 	psecuritypriv->dot118021XGrpKeyid = 1;
414 
415 	psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
416 	psecuritypriv->ndisencryptstatus = Ndis802_11WEPDisabled;
417 
418 	/* registry_priv */
419 	rtw_init_registrypriv_dev_network23a(padapter);
420 	rtw_update_registrypriv_dev_network23a(padapter);
421 
422 	/* hal_priv */
423 	rtl8723a_init_default_value(padapter);
424 
425 	/* misc. */
426 	padapter->bReadPortCancel = false;
427 	padapter->bWritePortCancel = false;
428 	return ret;
429 }
430 
rtw_reset_drv_sw23a(struct rtw_adapter * padapter)431 int rtw_reset_drv_sw23a(struct rtw_adapter *padapter)
432 {
433 	struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
434 	struct pwrctrl_priv *pwrctrlpriv = &padapter->pwrctrlpriv;
435 
436 	/* hal_priv */
437 	rtl8723a_init_default_value(padapter);
438 	padapter->bReadPortCancel = false;
439 	padapter->bWritePortCancel = false;
440 	pmlmepriv->scan_interval = SCAN_INTERVAL;/*  30*2 sec = 60sec */
441 
442 	padapter->xmitpriv.tx_pkts = 0;
443 	padapter->recvpriv.rx_pkts = 0;
444 
445 	pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
446 
447 	_clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING);
448 
449 	rtw_sreset_reset_value(padapter);
450 	pwrctrlpriv->pwr_state_check_cnts = 0;
451 
452 	/* mlmeextpriv */
453 	padapter->mlmeextpriv.sitesurvey_res.state = SCAN_DISABLE;
454 
455 	rtw_set_signal_stat_timer(&padapter->recvpriv);
456 	return _SUCCESS;
457 }
458 
rtw_init_drv_sw23a(struct rtw_adapter * padapter)459 int rtw_init_drv_sw23a(struct rtw_adapter *padapter)
460 {
461 	int ret8 = _SUCCESS;
462 
463 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_init_drv_sw23a\n"));
464 
465 	if (rtw_init_cmd_priv23a(&padapter->cmdpriv) == _FAIL) {
466 		RT_TRACE(_module_os_intfs_c_, _drv_err_,
467 			 ("\n Can't init cmd_priv\n"));
468 		ret8 = _FAIL;
469 		goto exit;
470 	}
471 
472 	padapter->cmdpriv.padapter = padapter;
473 
474 	if (rtw_init_evt_priv23a(&padapter->evtpriv) == _FAIL) {
475 		RT_TRACE(_module_os_intfs_c_, _drv_err_,
476 			 ("\n Can't init evt_priv\n"));
477 		ret8 = _FAIL;
478 		goto exit;
479 	}
480 
481 	if (rtw_init_mlme_priv23a(padapter) == _FAIL) {
482 		RT_TRACE(_module_os_intfs_c_, _drv_err_,
483 			 ("\n Can't init mlme_priv\n"));
484 		ret8 = _FAIL;
485 		goto exit;
486 	}
487 
488 
489 	if (init_mlme_ext_priv23a(padapter) == _FAIL) {
490 		RT_TRACE(_module_os_intfs_c_, _drv_err_,
491 			 ("\n Can't init mlme_ext_priv\n"));
492 		ret8 = _FAIL;
493 		goto exit;
494 	}
495 
496 	if (_rtw_init_xmit_priv23a(&padapter->xmitpriv, padapter) == _FAIL) {
497 		DBG_8723A("Can't _rtw_init_xmit_priv23a\n");
498 		ret8 = _FAIL;
499 		goto exit;
500 	}
501 
502 	if (_rtw_init_recv_priv23a(&padapter->recvpriv, padapter) == _FAIL) {
503 		DBG_8723A("Can't _rtw_init_recv_priv23a\n");
504 		ret8 = _FAIL;
505 		goto exit;
506 	}
507 
508 	if (_rtw_init_sta_priv23a(&padapter->stapriv) == _FAIL) {
509 		DBG_8723A("Can't _rtw_init_sta_priv23a\n");
510 		ret8 = _FAIL;
511 		goto exit;
512 	}
513 
514 	padapter->stapriv.padapter = padapter;
515 	padapter->setband = GHZ24_50;
516 	rtw_init_bcmc_stainfo23a(padapter);
517 
518 	rtw_init_pwrctrl_priv23a(padapter);
519 
520 	ret8 = rtw_init_default_value(padapter);
521 
522 	rtl8723a_init_dm_priv(padapter);
523 
524 	rtw_sreset_init(padapter);
525 
526 exit:
527 
528 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_init_drv_sw23a\n"));
529 	return ret8;
530 }
531 
rtw_cancel_all_timer23a(struct rtw_adapter * padapter)532 void rtw_cancel_all_timer23a(struct rtw_adapter *padapter)
533 {
534 	RT_TRACE(_module_os_intfs_c_, _drv_info_,
535 		 ("+rtw_cancel_all_timer23a\n"));
536 
537 	del_timer_sync(&padapter->mlmepriv.assoc_timer);
538 	RT_TRACE(_module_os_intfs_c_, _drv_info_,
539 		 ("%s:cancel association timer complete!\n", __func__));
540 
541 	del_timer_sync(&padapter->mlmepriv.scan_to_timer);
542 	RT_TRACE(_module_os_intfs_c_, _drv_info_,
543 		 ("%s:cancel scan_to_timer!\n", __func__));
544 
545 	del_timer_sync(&padapter->mlmepriv.dynamic_chk_timer);
546 	RT_TRACE(_module_os_intfs_c_, _drv_info_,
547 		 ("%s:cancel dynamic_chk_timer!\n", __func__));
548 
549 	RT_TRACE(_module_os_intfs_c_, _drv_info_,
550 		 ("%s:cancel DeInitSwLeds!\n", __func__));
551 
552 	del_timer_sync(&padapter->pwrctrlpriv.pwr_state_check_timer);
553 
554 	del_timer_sync(&padapter->mlmepriv.set_scan_deny_timer);
555 	rtw_clear_scan_deny(padapter);
556 	RT_TRACE(_module_os_intfs_c_, _drv_info_,
557 		 ("%s:cancel set_scan_deny_timer!\n", __func__));
558 
559 	del_timer_sync(&padapter->recvpriv.signal_stat_timer);
560 }
561 
rtw_free_drv_sw23a(struct rtw_adapter * padapter)562 int rtw_free_drv_sw23a(struct rtw_adapter *padapter)
563 {
564 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("==>rtw_free_drv_sw23a"));
565 
566 	free_mlme_ext_priv23a(&padapter->mlmeextpriv);
567 
568 	rtw_free_evt_priv23a(&padapter->evtpriv);
569 
570 	rtw_free_mlme_priv23a(&padapter->mlmepriv);
571 
572 	_rtw_free_xmit_priv23a(&padapter->xmitpriv);
573 
574 	/* will free bcmc_stainfo here */
575 	_rtw_free_sta_priv23a(&padapter->stapriv);
576 
577 	_rtw_free_recv_priv23a(&padapter->recvpriv);
578 
579 	rtw_free_pwrctrl_priv(padapter);
580 
581 	kfree(padapter->HalData);
582 	padapter->HalData = NULL;
583 
584 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_free_drv_sw23a\n"));
585 	return _SUCCESS;
586 }
587 
_rtw_drv_register_netdev(struct rtw_adapter * padapter,char * name)588 static int _rtw_drv_register_netdev(struct rtw_adapter *padapter, char *name)
589 {
590 	struct net_device *pnetdev = padapter->pnetdev;
591 	int ret = _SUCCESS;
592 
593 	/* alloc netdev name */
594 	rtw_init_netdev23a_name23a(pnetdev, name);
595 
596 	ether_addr_copy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr);
597 
598 	/* Tell the network stack we exist */
599 	if (register_netdev(pnetdev)) {
600 		DBG_8723A("%s(%s): Failed!\n", __func__, pnetdev->name);
601 		ret = _FAIL;
602 		goto error_register_netdev;
603 	}
604 	DBG_8723A("%s, MAC Address (if%d) = " MAC_FMT "\n", __func__,
605 		  (padapter->iface_id + 1), MAC_ARG(pnetdev->dev_addr));
606 	return ret;
607 
608 error_register_netdev:
609 
610 	if (padapter->iface_id > IFACE_ID0) {
611 		rtw_free_drv_sw23a(padapter);
612 
613 		free_netdev(pnetdev);
614 	}
615 	return ret;
616 }
617 
rtw_drv_register_netdev(struct rtw_adapter * if1)618 int rtw_drv_register_netdev(struct rtw_adapter *if1)
619 {
620 	struct dvobj_priv *dvobj = if1->dvobj;
621 	int i, status = _SUCCESS;
622 
623 	if (dvobj->iface_nums >= IFACE_ID_MAX) {
624 		status = _FAIL; /* -EINVAL */
625 		goto exit;
626 	}
627 
628 	for (i = 0; i < dvobj->iface_nums; i++) {
629 		struct rtw_adapter *padapter = dvobj->padapters[i];
630 
631 		if (padapter) {
632 			char *name;
633 
634 			if (padapter->iface_id == IFACE_ID0)
635 				name = if1->registrypriv.ifname;
636 			else if (padapter->iface_id == IFACE_ID1)
637 				name = if1->registrypriv.if2name;
638 			else
639 				name = "wlan%d";
640 			status = _rtw_drv_register_netdev(padapter, name);
641 			if (status != _SUCCESS)
642 				break;
643 		}
644 	}
645 
646 exit:
647 	return status;
648 }
649 
netdev_open23a(struct net_device * pnetdev)650 int netdev_open23a(struct net_device *pnetdev)
651 {
652 	struct rtw_adapter *padapter = netdev_priv(pnetdev);
653 	struct pwrctrl_priv *pwrctrlpriv;
654 	int ret = 0;
655 	int status;
656 
657 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+871x_drv - dev_open\n"));
658 	DBG_8723A("+871x_drv - drv_open, bup =%d\n", padapter->bup);
659 
660 	mutex_lock(&adapter_to_dvobj(padapter)->hw_init_mutex);
661 
662 	pwrctrlpriv = &padapter->pwrctrlpriv;
663 
664 	if (!padapter->bup) {
665 		padapter->bDriverStopped = false;
666 		padapter->bSurpriseRemoved = false;
667 		padapter->bCardDisableWOHSM = false;
668 
669 		status = rtl8723au_hal_init(padapter);
670 		if (status == _FAIL) {
671 			RT_TRACE(_module_os_intfs_c_, _drv_err_,
672 				 ("rtl871x_hal_init(): Can't init h/w!\n"));
673 			goto netdev_open23a_error;
674 		}
675 
676 		DBG_8723A("MAC Address = "MAC_FMT"\n",
677 			  MAC_ARG(pnetdev->dev_addr));
678 
679 		if (init_hw_mlme_ext23a(padapter) == _FAIL) {
680 			DBG_8723A("can't init mlme_ext_priv\n");
681 			goto netdev_open23a_error;
682 		}
683 
684 		rtl8723au_inirp_init(padapter);
685 
686 		rtw_cfg80211_init_wiphy(padapter);
687 
688 		rtw_led_control(padapter, LED_CTL_NO_LINK);
689 
690 		padapter->bup = true;
691 	}
692 	padapter->net_closed = false;
693 
694 	mod_timer(&padapter->mlmepriv.dynamic_chk_timer,
695 		  jiffies + msecs_to_jiffies(2000));
696 
697 	padapter->pwrctrlpriv.bips_processing = false;
698 	rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
699 
700 	/* netif_carrier_on(pnetdev);call this func when
701 	   rtw23a_joinbss_event_cb return success */
702 	if (!rtw_netif_queue_stopped(pnetdev))
703 		netif_tx_start_all_queues(pnetdev);
704 	else
705 		netif_tx_wake_all_queues(pnetdev);
706 
707 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-871x_drv - dev_open\n"));
708 	DBG_8723A("-871x_drv - drv_open, bup =%d\n", padapter->bup);
709 exit:
710 	mutex_unlock(&adapter_to_dvobj(padapter)->hw_init_mutex);
711 	return ret;
712 
713 netdev_open23a_error:
714 	padapter->bup = false;
715 
716 	netif_carrier_off(pnetdev);
717 	netif_tx_stop_all_queues(pnetdev);
718 
719 	RT_TRACE(_module_os_intfs_c_, _drv_err_,
720 		 ("-871x_drv - dev_open, fail!\n"));
721 	DBG_8723A("-871x_drv - drv_open fail, bup =%d\n", padapter->bup);
722 
723 	ret = -1;
724 	goto exit;
725 }
726 
ips_netdrv_open(struct rtw_adapter * padapter)727 static int ips_netdrv_open(struct rtw_adapter *padapter)
728 {
729 	int status = _SUCCESS;
730 
731 	padapter->net_closed = false;
732 	DBG_8723A("===> %s.........\n", __func__);
733 
734 	padapter->bDriverStopped = false;
735 	padapter->bSurpriseRemoved = false;
736 	padapter->bCardDisableWOHSM = false;
737 
738 	status = rtl8723au_hal_init(padapter);
739 	if (status == _FAIL) {
740 		RT_TRACE(_module_os_intfs_c_, _drv_err_,
741 			 ("ips_netdrv_open(): Can't init h/w!\n"));
742 		goto netdev_open23a_error;
743 	}
744 
745 	rtl8723au_inirp_init(padapter);
746 
747 	rtw_set_pwr_state_check_timer(&padapter->pwrctrlpriv);
748 	mod_timer(&padapter->mlmepriv.dynamic_chk_timer,
749 		  jiffies + msecs_to_jiffies(5000));
750 
751 	return _SUCCESS;
752 
753 netdev_open23a_error:
754 	/* padapter->bup = false; */
755 	DBG_8723A("-ips_netdrv_open - drv_open failure, bup =%d\n",
756 		  padapter->bup);
757 
758 	return _FAIL;
759 }
760 
rtw_ips_pwr_up23a(struct rtw_adapter * padapter)761 int rtw_ips_pwr_up23a(struct rtw_adapter *padapter)
762 {
763 	int result;
764 	unsigned long start_time = jiffies;
765 
766 	DBG_8723A("===>  rtw_ips_pwr_up23a..............\n");
767 	rtw_reset_drv_sw23a(padapter);
768 
769 	result = ips_netdrv_open(padapter);
770 
771 	rtw_led_control(padapter, LED_CTL_NO_LINK);
772 
773 	DBG_8723A("<===  rtw_ips_pwr_up23a.............. in %dms\n",
774 		  jiffies_to_msecs(jiffies - start_time));
775 	return result;
776 }
777 
rtw_ips_pwr_down23a(struct rtw_adapter * padapter)778 void rtw_ips_pwr_down23a(struct rtw_adapter *padapter)
779 {
780 	unsigned long start_time = jiffies;
781 
782 	DBG_8723A("===> rtw_ips_pwr_down23a...................\n");
783 
784 	padapter->bCardDisableWOHSM = true;
785 	padapter->net_closed = true;
786 
787 	rtw_led_control(padapter, LED_CTL_POWER_OFF);
788 
789 	rtw_ips_dev_unload23a(padapter);
790 	padapter->bCardDisableWOHSM = false;
791 	DBG_8723A("<=== rtw_ips_pwr_down23a..................... in %dms\n",
792 		  jiffies_to_msecs(jiffies - start_time));
793 }
794 
rtw_ips_dev_unload23a(struct rtw_adapter * padapter)795 void rtw_ips_dev_unload23a(struct rtw_adapter *padapter)
796 {
797 	rtl8723a_fifo_cleanup(padapter);
798 
799 	rtl8723a_usb_intf_stop(padapter);
800 
801 	/* s5. */
802 	if (!padapter->bSurpriseRemoved)
803 		rtl8723au_hal_deinit(padapter);
804 }
805 
pm_netdev_open23a(struct net_device * pnetdev,u8 bnormal)806 int pm_netdev_open23a(struct net_device *pnetdev, u8 bnormal)
807 {
808 	int status;
809 
810 	if (bnormal)
811 		status = netdev_open23a(pnetdev);
812 	else
813 		status = (_SUCCESS == ips_netdrv_open(netdev_priv(pnetdev))) ?
814 			 (0) : (-1);
815 
816 	return status;
817 }
818 
netdev_close(struct net_device * pnetdev)819 static int netdev_close(struct net_device *pnetdev)
820 {
821 	struct rtw_adapter *padapter = netdev_priv(pnetdev);
822 
823 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+871x_drv - drv_close\n"));
824 
825 	padapter->net_closed = true;
826 
827 	if (padapter->pwrctrlpriv.rf_pwrstate == rf_on) {
828 		DBG_8723A("(2)871x_drv - drv_close, bup =%d, "
829 			  "hw_init_completed =%d\n", padapter->bup,
830 			  padapter->hw_init_completed);
831 
832 		/* s1. */
833 		if (pnetdev) {
834 			if (!rtw_netif_queue_stopped(pnetdev))
835 				netif_tx_stop_all_queues(pnetdev);
836 		}
837 
838 		/* s2. */
839 		LeaveAllPowerSaveMode23a(padapter);
840 		rtw_disassoc_cmd23a(padapter, 500, false);
841 		/* s2-2.  indicate disconnect to os */
842 		rtw_indicate_disconnect23a(padapter);
843 		/* s2-3. */
844 		rtw_free_assoc_resources23a(padapter, 1);
845 		/* s2-4. */
846 		rtw_free_network_queue23a(padapter);
847 		/*  Close LED */
848 		rtw_led_control(padapter, LED_CTL_POWER_OFF);
849 	}
850 
851 	rtw_scan_abort23a(padapter);
852 
853 	RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-871x_drv - drv_close\n"));
854 	DBG_8723A("-871x_drv - drv_close, bup =%d\n", padapter->bup);
855 
856 	return 0;
857 }
858 
rtw_ndev_destructor(struct net_device * ndev)859 void rtw_ndev_destructor(struct net_device *ndev)
860 {
861 	DBG_8723A("%s(%s)\n", __func__, ndev->name);
862 	kfree(ndev->ieee80211_ptr);
863 	free_netdev(ndev);
864 }
865 
_rtw_init_queue23a(struct rtw_queue * pqueue)866 void _rtw_init_queue23a(struct rtw_queue *pqueue)
867 {
868 	INIT_LIST_HEAD(&pqueue->queue);
869 	spin_lock_init(&pqueue->lock);
870 }
871