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