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