root/drivers/staging/rtl8723bs/os_dep/os_intfs.c

/* [<][>][^][v][top][bottom][index][help] */

DEFINITIONS

This source file includes following definitions.
  1. loadparam
  2. rtw_net_set_mac_address
  3. rtw_net_get_stats
  4. rtw_classify8021d
  5. rtw_select_queue
  6. rtw_recv_select_queue
  7. rtw_ndev_notifier_call
  8. rtw_ndev_notifier_register
  9. rtw_ndev_notifier_unregister
  10. rtw_ndev_init
  11. rtw_ndev_uninit
  12. rtw_init_netdev_name
  13. rtw_init_netdev
  14. rtw_unregister_netdevs
  15. rtw_start_drv_threads
  16. rtw_stop_drv_threads
  17. rtw_init_default_value
  18. devobj_init
  19. devobj_deinit
  20. rtw_reset_drv_sw
  21. rtw_init_drv_sw
  22. rtw_cancel_all_timer
  23. rtw_free_drv_sw
  24. _rtw_drv_register_netdev
  25. rtw_drv_register_netdev
  26. _netdev_open
  27. netdev_open
  28. ips_netdrv_open
  29. rtw_ips_pwr_up
  30. rtw_ips_pwr_down
  31. rtw_ips_dev_unload
  32. pm_netdev_open
  33. netdev_close
  34. rtw_ndev_destructor
  35. rtw_dev_unload
  36. rtw_suspend_free_assoc_resource
  37. rtw_suspend_wow
  38. rtw_suspend_ap_wow
  39. rtw_suspend_normal
  40. rtw_suspend_common
  41. rtw_resume_process_wow
  42. rtw_resume_process_ap_wow
  43. rtw_resume_process_normal
  44. rtw_resume_common

   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 <drv_types.h>
  10 #include <rtw_debug.h>
  11 #include <hal_data.h>
  12 
  13 MODULE_LICENSE("GPL");
  14 MODULE_DESCRIPTION("Realtek Wireless Lan Driver");
  15 MODULE_AUTHOR("Realtek Semiconductor Corp.");
  16 MODULE_VERSION(DRIVERVERSION);
  17 
  18 /* module param defaults */
  19 static int rtw_chip_version;
  20 static int rtw_rfintfs = HWPI;
  21 static int rtw_lbkmode;/* RTL8712_AIR_TRX; */
  22 
  23 
  24 static int rtw_network_mode = Ndis802_11IBSS;/* Ndis802_11Infrastructure;infra, ad-hoc, auto */
  25 /* struct ndis_802_11_ssid      ssid; */
  26 static int rtw_channel = 1;/* ad-hoc support requirement */
  27 static int rtw_wireless_mode = WIRELESS_MODE_MAX;
  28 static int rtw_vrtl_carrier_sense = AUTO_VCS;
  29 static int rtw_vcs_type = RTS_CTS;/*  */
  30 static int rtw_rts_thresh = 2347;/*  */
  31 static int rtw_frag_thresh = 2346;/*  */
  32 static int rtw_preamble = PREAMBLE_LONG;/* long, short, auto */
  33 static int rtw_scan_mode = 1;/* active, passive */
  34 static int rtw_adhoc_tx_pwr = 1;
  35 static int rtw_soft_ap;
  36 /* int smart_ps = 1; */
  37 static int rtw_power_mgnt = 1;
  38 static int rtw_ips_mode = IPS_NORMAL;
  39 module_param(rtw_ips_mode, int, 0644);
  40 MODULE_PARM_DESC(rtw_ips_mode, "The default IPS mode");
  41 
  42 static int rtw_smart_ps = 2;
  43 
  44 static int rtw_check_fw_ps = 1;
  45 
  46 static int rtw_usb_rxagg_mode = 2;/* USB_RX_AGG_DMA = 1, USB_RX_AGG_USB =2 */
  47 module_param(rtw_usb_rxagg_mode, int, 0644);
  48 
  49 static int rtw_radio_enable = 1;
  50 static int rtw_long_retry_lmt = 7;
  51 static int rtw_short_retry_lmt = 7;
  52 static int rtw_busy_thresh = 40;
  53 /* int qos_enable = 0; */
  54 static int rtw_ack_policy = NORMAL_ACK;
  55 
  56 static int rtw_software_encrypt;
  57 static int rtw_software_decrypt;
  58 
  59 static int rtw_acm_method;/*  0:By SW 1:By HW. */
  60 
  61 static int rtw_wmm_enable = 1;/*  default is set to enable the wmm. */
  62 static int rtw_uapsd_enable;
  63 static int rtw_uapsd_max_sp = NO_LIMIT;
  64 static int rtw_uapsd_acbk_en;
  65 static int rtw_uapsd_acbe_en;
  66 static int rtw_uapsd_acvi_en;
  67 static int rtw_uapsd_acvo_en;
  68 
  69 int rtw_ht_enable = 1;
  70 /*  0: 20 MHz, 1: 40 MHz, 2: 80 MHz, 3: 160MHz, 4: 80+80MHz */
  71 /*  2.4G use bit 0 ~ 3, 5G use bit 4 ~ 7 */
  72 /*  0x21 means enable 2.4G 40MHz & 5G 80MHz */
  73 static int rtw_bw_mode = 0x21;
  74 static int rtw_ampdu_enable = 1;/* for enable tx_ampdu ,0: disable, 0x1:enable (but wifi_spec should be 0), 0x2: force enable (don't care wifi_spec) */
  75 static int rtw_rx_stbc = 1;/*  0: disable, 1:enable 2.4g */
  76 static int rtw_ampdu_amsdu;/*  0: disabled, 1:enabled, 2:auto . There is an IOT issu with DLINK DIR-629 when the flag turn on */
  77 /*  Short GI support Bit Map */
  78 /*  BIT0 - 20MHz, 0: non-support, 1: support */
  79 /*  BIT1 - 40MHz, 0: non-support, 1: support */
  80 /*  BIT2 - 80MHz, 0: non-support, 1: support */
  81 /*  BIT3 - 160MHz, 0: non-support, 1: support */
  82 static int rtw_short_gi = 0xf;
  83 /*  BIT0: Enable VHT LDPC Rx, BIT1: Enable VHT LDPC Tx, BIT4: Enable HT LDPC Rx, BIT5: Enable HT LDPC Tx */
  84 static int rtw_ldpc_cap = 0x33;
  85 /*  BIT0: Enable VHT STBC Rx, BIT1: Enable VHT STBC Tx, BIT4: Enable HT STBC Rx, BIT5: Enable HT STBC Tx */
  86 static int rtw_stbc_cap = 0x13;
  87 /*  BIT0: Enable VHT Beamformer, BIT1: Enable VHT Beamformee, BIT4: Enable HT Beamformer, BIT5: Enable HT Beamformee */
  88 static int rtw_beamform_cap = 0x2;
  89 
  90 static int rtw_lowrate_two_xmit = 1;/* Use 2 path Tx to transmit MCS0~7 and legacy mode */
  91 
  92 /* int rf_config = RF_1T2R;  1T2R */
  93 static int rtw_rf_config = RF_MAX_TYPE;  /* auto */
  94 static int rtw_low_power;
  95 static int rtw_wifi_spec;
  96 static int rtw_channel_plan = RT_CHANNEL_DOMAIN_MAX;
  97 
  98 static int rtw_btcoex_enable = 1;
  99 module_param(rtw_btcoex_enable, int, 0644);
 100 MODULE_PARM_DESC(rtw_btcoex_enable, "Enable BT co-existence mechanism");
 101 static int rtw_bt_iso = 2;/*  0:Low, 1:High, 2:From Efuse */
 102 static int rtw_bt_sco = 3;/*  0:Idle, 1:None-SCO, 2:SCO, 3:From Counter, 4.Busy, 5.OtherBusy */
 103 static int rtw_bt_ampdu = 1 ;/*  0:Disable BT control A-MPDU, 1:Enable BT control A-MPDU. */
 104 static int rtw_ant_num = -1; /*  <0: undefined, >0: Antenna number */
 105 module_param(rtw_ant_num, int, 0644);
 106 MODULE_PARM_DESC(rtw_ant_num, "Antenna number setting");
 107 
 108 static int rtw_antdiv_cfg = 1; /*  0:OFF , 1:ON, 2:decide by Efuse config */
 109 static int rtw_antdiv_type; /* 0:decide by efuse  1: for 88EE, 1Tx and 1RxCG are diversity.(2 Ant with SPDT), 2:  for 88EE, 1Tx and 2Rx are diversity.(2 Ant, Tx and RxCG are both on aux port, RxCS is on main port), 3: for 88EE, 1Tx and 1RxCG are fixed.(1Ant, Tx and RxCG are both on aux port) */
 110 
 111 
 112 static int rtw_enusbss;/* 0:disable, 1:enable */
 113 
 114 static int rtw_hwpdn_mode = 2;/* 0:disable, 1:enable, 2: by EFUSE config */
 115 
 116 #ifdef CONFIG_HW_PWRP_DETECTION
 117 static int rtw_hwpwrp_detect = 1;
 118 #else
 119 static int rtw_hwpwrp_detect; /* HW power  ping detect 0:disable , 1:enable */
 120 #endif
 121 
 122 static int rtw_hw_wps_pbc;
 123 
 124 int rtw_mc2u_disable = 0;
 125 
 126 static int rtw_80211d;
 127 
 128 #ifdef CONFIG_QOS_OPTIMIZATION
 129 static int rtw_qos_opt_enable = 1;/* 0: disable, 1:enable */
 130 #else
 131 static int rtw_qos_opt_enable;/* 0: disable, 1:enable */
 132 #endif
 133 module_param(rtw_qos_opt_enable, int, 0644);
 134 
 135 static char *ifname = "wlan%d";
 136 module_param(ifname, charp, 0644);
 137 MODULE_PARM_DESC(ifname, "The default name to allocate for first interface");
 138 
 139 char *rtw_initmac = NULL;  /*  temp mac address if users want to use instead of the mac address in Efuse */
 140 
 141 module_param(rtw_initmac, charp, 0644);
 142 module_param(rtw_channel_plan, int, 0644);
 143 module_param(rtw_chip_version, int, 0644);
 144 module_param(rtw_rfintfs, int, 0644);
 145 module_param(rtw_lbkmode, int, 0644);
 146 module_param(rtw_network_mode, int, 0644);
 147 module_param(rtw_channel, int, 0644);
 148 module_param(rtw_wmm_enable, int, 0644);
 149 module_param(rtw_vrtl_carrier_sense, int, 0644);
 150 module_param(rtw_vcs_type, int, 0644);
 151 module_param(rtw_busy_thresh, int, 0644);
 152 
 153 module_param(rtw_ht_enable, int, 0644);
 154 module_param(rtw_bw_mode, int, 0644);
 155 module_param(rtw_ampdu_enable, int, 0644);
 156 module_param(rtw_rx_stbc, int, 0644);
 157 module_param(rtw_ampdu_amsdu, int, 0644);
 158 
 159 module_param(rtw_lowrate_two_xmit, int, 0644);
 160 
 161 module_param(rtw_rf_config, int, 0644);
 162 module_param(rtw_power_mgnt, int, 0644);
 163 module_param(rtw_smart_ps, int, 0644);
 164 module_param(rtw_low_power, int, 0644);
 165 module_param(rtw_wifi_spec, int, 0644);
 166 
 167 module_param(rtw_antdiv_cfg, int, 0644);
 168 module_param(rtw_antdiv_type, int, 0644);
 169 
 170 module_param(rtw_enusbss, int, 0644);
 171 module_param(rtw_hwpdn_mode, int, 0644);
 172 module_param(rtw_hwpwrp_detect, int, 0644);
 173 
 174 module_param(rtw_hw_wps_pbc, int, 0644);
 175 
 176 static uint rtw_max_roaming_times = 2;
 177 module_param(rtw_max_roaming_times, uint, 0644);
 178 MODULE_PARM_DESC(rtw_max_roaming_times, "The max roaming times to try");
 179 
 180 module_param(rtw_mc2u_disable, int, 0644);
 181 
 182 module_param(rtw_80211d, int, 0644);
 183 MODULE_PARM_DESC(rtw_80211d, "Enable 802.11d mechanism");
 184 
 185 static uint rtw_notch_filter;
 186 module_param(rtw_notch_filter, uint, 0644);
 187 MODULE_PARM_DESC(rtw_notch_filter, "0:Disable, 1:Enable, 2:Enable only for P2P");
 188 
 189 #define CONFIG_RTW_HIQ_FILTER 1
 190 
 191 static uint rtw_hiq_filter = CONFIG_RTW_HIQ_FILTER;
 192 module_param(rtw_hiq_filter, uint, 0644);
 193 MODULE_PARM_DESC(rtw_hiq_filter, "0:allow all, 1:allow special, 2:deny all");
 194 
 195 static int rtw_tx_pwr_lmt_enable;
 196 static int rtw_tx_pwr_by_rate;
 197 
 198 module_param(rtw_tx_pwr_lmt_enable, int, 0644);
 199 MODULE_PARM_DESC(rtw_tx_pwr_lmt_enable, "0:Disable, 1:Enable, 2: Depend on efuse");
 200 
 201 module_param(rtw_tx_pwr_by_rate, int, 0644);
 202 MODULE_PARM_DESC(rtw_tx_pwr_by_rate, "0:Disable, 1:Enable, 2: Depend on efuse");
 203 
 204 char *rtw_phy_file_path = "";
 205 module_param(rtw_phy_file_path, charp, 0644);
 206 MODULE_PARM_DESC(rtw_phy_file_path, "The path of phy parameter");
 207 /*  PHY FILE Bit Map */
 208 /*  BIT0 - MAC,                         0: non-support, 1: support */
 209 /*  BIT1 - BB,                                  0: non-support, 1: support */
 210 /*  BIT2 - BB_PG,                               0: non-support, 1: support */
 211 /*  BIT3 - BB_MP,                               0: non-support, 1: support */
 212 /*  BIT4 - RF,                                  0: non-support, 1: support */
 213 /*  BIT5 - RF_TXPWR_TRACK,      0: non-support, 1: support */
 214 /*  BIT6 - RF_TXPWR_LMT,                0: non-support, 1: support */
 215 static int rtw_load_phy_file = (BIT2 | BIT6);
 216 module_param(rtw_load_phy_file, int, 0644);
 217 MODULE_PARM_DESC(rtw_load_phy_file, "PHY File Bit Map");
 218 static int rtw_decrypt_phy_file;
 219 module_param(rtw_decrypt_phy_file, int, 0644);
 220 MODULE_PARM_DESC(rtw_decrypt_phy_file, "Enable Decrypt PHY File");
 221 
 222 int _netdev_open(struct net_device *pnetdev);
 223 int netdev_open (struct net_device *pnetdev);
 224 static int netdev_close (struct net_device *pnetdev);
 225 
 226 static void loadparam(struct adapter *padapter, _nic_hdl pnetdev)
 227 {
 228         struct registry_priv  *registry_par = &padapter->registrypriv;
 229 
 230         registry_par->chip_version = (u8)rtw_chip_version;
 231         registry_par->rfintfs = (u8)rtw_rfintfs;
 232         registry_par->lbkmode = (u8)rtw_lbkmode;
 233         /* registry_par->hci = (u8)hci; */
 234         registry_par->network_mode  = (u8)rtw_network_mode;
 235 
 236         memcpy(registry_par->ssid.Ssid, "ANY", 3);
 237         registry_par->ssid.SsidLength = 3;
 238 
 239         registry_par->channel = (u8)rtw_channel;
 240         registry_par->wireless_mode = (u8)rtw_wireless_mode;
 241 
 242         registry_par->vrtl_carrier_sense = (u8)rtw_vrtl_carrier_sense ;
 243         registry_par->vcs_type = (u8)rtw_vcs_type;
 244         registry_par->rts_thresh = (u16)rtw_rts_thresh;
 245         registry_par->frag_thresh = (u16)rtw_frag_thresh;
 246         registry_par->preamble = (u8)rtw_preamble;
 247         registry_par->scan_mode = (u8)rtw_scan_mode;
 248         registry_par->adhoc_tx_pwr = (u8)rtw_adhoc_tx_pwr;
 249         registry_par->soft_ap =  (u8)rtw_soft_ap;
 250         registry_par->smart_ps =  (u8)rtw_smart_ps;
 251         registry_par->check_fw_ps = (u8)rtw_check_fw_ps;
 252         registry_par->power_mgnt = (u8)rtw_power_mgnt;
 253         registry_par->ips_mode = (u8)rtw_ips_mode;
 254         registry_par->radio_enable = (u8)rtw_radio_enable;
 255         registry_par->long_retry_lmt = (u8)rtw_long_retry_lmt;
 256         registry_par->short_retry_lmt = (u8)rtw_short_retry_lmt;
 257         registry_par->busy_thresh = (u16)rtw_busy_thresh;
 258         /* registry_par->qos_enable = (u8)rtw_qos_enable; */
 259         registry_par->ack_policy = (u8)rtw_ack_policy;
 260         registry_par->software_encrypt = (u8)rtw_software_encrypt;
 261         registry_par->software_decrypt = (u8)rtw_software_decrypt;
 262 
 263         registry_par->acm_method = (u8)rtw_acm_method;
 264         registry_par->usb_rxagg_mode = (u8)rtw_usb_rxagg_mode;
 265 
 266          /* UAPSD */
 267         registry_par->wmm_enable = (u8)rtw_wmm_enable;
 268         registry_par->uapsd_enable = (u8)rtw_uapsd_enable;
 269         registry_par->uapsd_max_sp = (u8)rtw_uapsd_max_sp;
 270         registry_par->uapsd_acbk_en = (u8)rtw_uapsd_acbk_en;
 271         registry_par->uapsd_acbe_en = (u8)rtw_uapsd_acbe_en;
 272         registry_par->uapsd_acvi_en = (u8)rtw_uapsd_acvi_en;
 273         registry_par->uapsd_acvo_en = (u8)rtw_uapsd_acvo_en;
 274 
 275         registry_par->ht_enable = (u8)rtw_ht_enable;
 276         registry_par->bw_mode = (u8)rtw_bw_mode;
 277         registry_par->ampdu_enable = (u8)rtw_ampdu_enable;
 278         registry_par->rx_stbc = (u8)rtw_rx_stbc;
 279         registry_par->ampdu_amsdu = (u8)rtw_ampdu_amsdu;
 280         registry_par->short_gi = (u8)rtw_short_gi;
 281         registry_par->ldpc_cap = (u8)rtw_ldpc_cap;
 282         registry_par->stbc_cap = (u8)rtw_stbc_cap;
 283         registry_par->beamform_cap = (u8)rtw_beamform_cap;
 284 
 285         registry_par->lowrate_two_xmit = (u8)rtw_lowrate_two_xmit;
 286         registry_par->rf_config = (u8)rtw_rf_config;
 287         registry_par->low_power = (u8)rtw_low_power;
 288 
 289 
 290         registry_par->wifi_spec = (u8)rtw_wifi_spec;
 291 
 292         registry_par->channel_plan = (u8)rtw_channel_plan;
 293 
 294         registry_par->btcoex = (u8)rtw_btcoex_enable;
 295         registry_par->bt_iso = (u8)rtw_bt_iso;
 296         registry_par->bt_sco = (u8)rtw_bt_sco;
 297         registry_par->bt_ampdu = (u8)rtw_bt_ampdu;
 298         registry_par->ant_num = (s8)rtw_ant_num;
 299 
 300         registry_par->accept_addba_req = true;
 301 
 302         registry_par->antdiv_cfg = (u8)rtw_antdiv_cfg;
 303         registry_par->antdiv_type = (u8)rtw_antdiv_type;
 304 
 305         registry_par->hw_wps_pbc = (u8)rtw_hw_wps_pbc;
 306 
 307         registry_par->max_roaming_times = (u8)rtw_max_roaming_times;
 308 
 309         registry_par->enable80211d = (u8)rtw_80211d;
 310 
 311         snprintf(registry_par->ifname, 16, "%s", ifname);
 312 
 313         registry_par->notch_filter = (u8)rtw_notch_filter;
 314 
 315         registry_par->RegEnableTxPowerLimit = (u8)rtw_tx_pwr_lmt_enable;
 316         registry_par->RegEnableTxPowerByRate = (u8)rtw_tx_pwr_by_rate;
 317 
 318         registry_par->RegPowerBase = 14;
 319         registry_par->TxBBSwing_2G = 0xFF;
 320         registry_par->TxBBSwing_5G = 0xFF;
 321         registry_par->bEn_RFE = 1;
 322         registry_par->RFE_Type = 64;
 323 
 324         registry_par->load_phy_file = (u8)rtw_load_phy_file;
 325         registry_par->RegDecryptCustomFile = (u8)rtw_decrypt_phy_file;
 326         registry_par->qos_opt_enable = (u8)rtw_qos_opt_enable;
 327 
 328         registry_par->hiq_filter = (u8)rtw_hiq_filter;
 329 }
 330 
 331 static int rtw_net_set_mac_address(struct net_device *pnetdev, void *p)
 332 {
 333         struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
 334         struct sockaddr *addr = p;
 335 
 336         if (padapter->bup == false) {
 337                 /* DBG_871X("r8711_net_set_mac_address(), MAC =%x:%x:%x:%x:%x:%x\n", addr->sa_data[0], addr->sa_data[1], addr->sa_data[2], addr->sa_data[3], */
 338                 /* addr->sa_data[4], addr->sa_data[5]); */
 339                 memcpy(padapter->eeprompriv.mac_addr, addr->sa_data, ETH_ALEN);
 340                 /* memcpy(pnetdev->dev_addr, addr->sa_data, ETH_ALEN); */
 341                 /* padapter->bset_hwaddr = true; */
 342         }
 343 
 344         return 0;
 345 }
 346 
 347 static struct net_device_stats *rtw_net_get_stats(struct net_device *pnetdev)
 348 {
 349         struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
 350         struct xmit_priv *pxmitpriv = &(padapter->xmitpriv);
 351         struct recv_priv *precvpriv = &(padapter->recvpriv);
 352 
 353         padapter->stats.tx_packets = pxmitpriv->tx_pkts;/* pxmitpriv->tx_pkts++; */
 354         padapter->stats.rx_packets = precvpriv->rx_pkts;/* precvpriv->rx_pkts++; */
 355         padapter->stats.tx_dropped = pxmitpriv->tx_drop;
 356         padapter->stats.rx_dropped = precvpriv->rx_drop;
 357         padapter->stats.tx_bytes = pxmitpriv->tx_bytes;
 358         padapter->stats.rx_bytes = precvpriv->rx_bytes;
 359 
 360         return &padapter->stats;
 361 }
 362 
 363 /*
 364  * AC to queue mapping
 365  *
 366  * AC_VO -> queue 0
 367  * AC_VI -> queue 1
 368  * AC_BE -> queue 2
 369  * AC_BK -> queue 3
 370  */
 371 static const u16 rtw_1d_to_queue[8] = { 2, 3, 3, 2, 1, 1, 0, 0 };
 372 
 373 /* Given a data frame determine the 802.1p/1d tag to use. */
 374 static unsigned int rtw_classify8021d(struct sk_buff *skb)
 375 {
 376         unsigned int dscp;
 377 
 378         /* skb->priority values from 256->263 are magic values to
 379          * directly indicate a specific 802.1d priority.  This is used
 380          * to allow 802.1d priority to be passed directly in from VLAN
 381          * tags, etc.
 382          */
 383         if (skb->priority >= 256 && skb->priority <= 263)
 384                 return skb->priority - 256;
 385 
 386         switch (skb->protocol) {
 387         case htons(ETH_P_IP):
 388                 dscp = ip_hdr(skb)->tos & 0xfc;
 389                 break;
 390         default:
 391                 return 0;
 392         }
 393 
 394         return dscp >> 5;
 395 }
 396 
 397 
 398 static u16 rtw_select_queue(struct net_device *dev, struct sk_buff *skb,
 399                             struct net_device *sb_dev)
 400 {
 401         struct adapter  *padapter = rtw_netdev_priv(dev);
 402         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 403 
 404         skb->priority = rtw_classify8021d(skb);
 405 
 406         if (pmlmepriv->acm_mask != 0)
 407                 skb->priority = qos_acm(pmlmepriv->acm_mask, skb->priority);
 408 
 409         return rtw_1d_to_queue[skb->priority];
 410 }
 411 
 412 u16 rtw_recv_select_queue(struct sk_buff *skb)
 413 {
 414         struct iphdr *piphdr;
 415         unsigned int dscp;
 416         __be16  eth_type;
 417         u32 priority;
 418         u8 *pdata = skb->data;
 419 
 420         memcpy(&eth_type, pdata + (ETH_ALEN << 1), 2);
 421 
 422         switch (be16_to_cpu(eth_type)) {
 423                 case ETH_P_IP:
 424 
 425                         piphdr = (struct iphdr *)(pdata + ETH_HLEN);
 426 
 427                         dscp = piphdr->tos & 0xfc;
 428 
 429                         priority = dscp >> 5;
 430 
 431                         break;
 432                 default:
 433                         priority = 0;
 434         }
 435 
 436         return rtw_1d_to_queue[priority];
 437 }
 438 
 439 static int rtw_ndev_notifier_call(struct notifier_block *nb, unsigned long state, void *ptr)
 440 {
 441         struct net_device *dev = netdev_notifier_info_to_dev(ptr);
 442 
 443         if (dev->netdev_ops->ndo_do_ioctl != rtw_ioctl)
 444                 return NOTIFY_DONE;
 445 
 446         DBG_871X_LEVEL(_drv_info_, FUNC_NDEV_FMT " state:%lu\n", FUNC_NDEV_ARG(dev), state);
 447 
 448         return NOTIFY_DONE;
 449 }
 450 
 451 static struct notifier_block rtw_ndev_notifier = {
 452         .notifier_call = rtw_ndev_notifier_call,
 453 };
 454 
 455 int rtw_ndev_notifier_register(void)
 456 {
 457         return register_netdevice_notifier(&rtw_ndev_notifier);
 458 }
 459 
 460 void rtw_ndev_notifier_unregister(void)
 461 {
 462         unregister_netdevice_notifier(&rtw_ndev_notifier);
 463 }
 464 
 465 
 466 static int rtw_ndev_init(struct net_device *dev)
 467 {
 468         struct adapter *adapter = rtw_netdev_priv(dev);
 469 
 470         DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter));
 471         strncpy(adapter->old_ifname, dev->name, IFNAMSIZ);
 472 
 473         return 0;
 474 }
 475 
 476 static void rtw_ndev_uninit(struct net_device *dev)
 477 {
 478         struct adapter *adapter = rtw_netdev_priv(dev);
 479 
 480         DBG_871X_LEVEL(_drv_always_, FUNC_ADPT_FMT "\n", FUNC_ADPT_ARG(adapter));
 481 }
 482 
 483 static const struct net_device_ops rtw_netdev_ops = {
 484         .ndo_init = rtw_ndev_init,
 485         .ndo_uninit = rtw_ndev_uninit,
 486         .ndo_open = netdev_open,
 487         .ndo_stop = netdev_close,
 488         .ndo_start_xmit = rtw_xmit_entry,
 489         .ndo_select_queue       = rtw_select_queue,
 490         .ndo_set_mac_address = rtw_net_set_mac_address,
 491         .ndo_get_stats = rtw_net_get_stats,
 492         .ndo_do_ioctl = rtw_ioctl,
 493 };
 494 
 495 int rtw_init_netdev_name(struct net_device *pnetdev, const char *ifname)
 496 {
 497         if (dev_alloc_name(pnetdev, ifname) < 0) {
 498                 pr_err("dev_alloc_name, fail for %s\n", ifname);
 499                 return 1;
 500         }
 501         netif_carrier_off(pnetdev);
 502         /* rtw_netif_stop_queue(pnetdev); */
 503 
 504         return 0;
 505 }
 506 
 507 struct net_device *rtw_init_netdev(struct adapter *old_padapter)
 508 {
 509         struct adapter *padapter;
 510         struct net_device *pnetdev;
 511 
 512         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+init_net_dev\n"));
 513 
 514         if (old_padapter != NULL)
 515                 pnetdev = rtw_alloc_etherdev_with_old_priv(sizeof(struct adapter), (void *)old_padapter);
 516         else
 517                 pnetdev = rtw_alloc_etherdev(sizeof(struct adapter));
 518 
 519         pr_info("pnetdev = %p\n", pnetdev);
 520         if (!pnetdev)
 521                 return NULL;
 522 
 523         padapter = rtw_netdev_priv(pnetdev);
 524         padapter->pnetdev = pnetdev;
 525 
 526         /* pnetdev->init = NULL; */
 527 
 528         DBG_871X("register rtw_netdev_ops to netdev_ops\n");
 529         pnetdev->netdev_ops = &rtw_netdev_ops;
 530 
 531         /* pnetdev->tx_timeout = NULL; */
 532         pnetdev->watchdog_timeo = HZ * 3; /* 3 second timeout */
 533         pnetdev->wireless_handlers = (struct iw_handler_def *)&rtw_handlers_def;
 534 
 535         /* step 2. */
 536         loadparam(padapter, pnetdev);
 537 
 538         return pnetdev;
 539 }
 540 
 541 void rtw_unregister_netdevs(struct dvobj_priv *dvobj)
 542 {
 543         struct adapter *padapter = NULL;
 544         struct net_device *pnetdev = NULL;
 545 
 546         padapter = dvobj->padapters;
 547 
 548         if (padapter == NULL)
 549                 return;
 550 
 551         pnetdev = padapter->pnetdev;
 552 
 553         if ((padapter->DriverState != DRIVER_DISAPPEAR) && pnetdev)
 554                 unregister_netdev(pnetdev); /* will call netdev_close() */
 555         rtw_wdev_unregister(padapter->rtw_wdev);
 556 }
 557 
 558 u32 rtw_start_drv_threads(struct adapter *padapter)
 559 {
 560         u32 _status = _SUCCESS;
 561 
 562         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_start_drv_threads\n"));
 563         padapter->xmitThread = kthread_run(rtw_xmit_thread, padapter, "RTW_XMIT_THREAD");
 564         if (IS_ERR(padapter->xmitThread))
 565                 _status = _FAIL;
 566 
 567         padapter->cmdThread = kthread_run(rtw_cmd_thread, padapter, "RTW_CMD_THREAD");
 568         if (IS_ERR(padapter->cmdThread))
 569                 _status = _FAIL;
 570         else
 571                 wait_for_completion(&padapter->cmdpriv.terminate_cmdthread_comp); /* wait for cmd_thread to run */
 572 
 573         rtw_hal_start_thread(padapter);
 574         return _status;
 575 }
 576 
 577 void rtw_stop_drv_threads (struct adapter *padapter)
 578 {
 579         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_stop_drv_threads\n"));
 580 
 581         rtw_stop_cmd_thread(padapter);
 582 
 583         /*  Below is to termindate tx_thread... */
 584         complete(&padapter->xmitpriv.xmit_comp);
 585         wait_for_completion(&padapter->xmitpriv.terminate_xmitthread_comp);
 586         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("\n drv_halt: rtw_xmit_thread can be terminated !\n"));
 587 
 588         rtw_hal_stop_thread(padapter);
 589 }
 590 
 591 static void rtw_init_default_value(struct adapter *padapter)
 592 {
 593         struct registry_priv *pregistrypriv = &padapter->registrypriv;
 594         struct xmit_priv *pxmitpriv = &padapter->xmitpriv;
 595         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 596         struct security_priv *psecuritypriv = &padapter->securitypriv;
 597 
 598         /* xmit_priv */
 599         pxmitpriv->vcs_setting = pregistrypriv->vrtl_carrier_sense;
 600         pxmitpriv->vcs = pregistrypriv->vcs_type;
 601         pxmitpriv->vcs_type = pregistrypriv->vcs_type;
 602         /* pxmitpriv->rts_thresh = pregistrypriv->rts_thresh; */
 603         pxmitpriv->frag_len = pregistrypriv->frag_thresh;
 604 
 605         /* recv_priv */
 606 
 607         /* mlme_priv */
 608         pmlmepriv->scan_mode = SCAN_ACTIVE;
 609 
 610         /* qos_priv */
 611         /* pmlmepriv->qospriv.qos_option = pregistrypriv->wmm_enable; */
 612 
 613         /* ht_priv */
 614         pmlmepriv->htpriv.ampdu_enable = false;/* set to disabled */
 615 
 616         /* security_priv */
 617         /* rtw_get_encrypt_decrypt_from_registrypriv(padapter); */
 618         psecuritypriv->binstallGrpkey = _FAIL;
 619 #ifdef CONFIG_GTK_OL
 620         psecuritypriv->binstallKCK_KEK = _FAIL;
 621 #endif /* CONFIG_GTK_OL */
 622         psecuritypriv->sw_encrypt = pregistrypriv->software_encrypt;
 623         psecuritypriv->sw_decrypt = pregistrypriv->software_decrypt;
 624 
 625         psecuritypriv->dot11AuthAlgrthm = dot11AuthAlgrthm_Open; /* open system */
 626         psecuritypriv->dot11PrivacyAlgrthm = _NO_PRIVACY_;
 627 
 628         psecuritypriv->dot11PrivacyKeyIndex = 0;
 629 
 630         psecuritypriv->dot118021XGrpPrivacy = _NO_PRIVACY_;
 631         psecuritypriv->dot118021XGrpKeyid = 1;
 632 
 633         psecuritypriv->ndisauthtype = Ndis802_11AuthModeOpen;
 634         psecuritypriv->ndisencryptstatus = Ndis802_11WEPDisabled;
 635 
 636         /* registry_priv */
 637         rtw_init_registrypriv_dev_network(padapter);
 638         rtw_update_registrypriv_dev_network(padapter);
 639 
 640         /* hal_priv */
 641         rtw_hal_def_value_init(padapter);
 642 
 643         /* misc. */
 644         RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
 645         RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
 646         padapter->bLinkInfoDump = 0;
 647         padapter->bNotifyChannelChange = 0;
 648 
 649         /* for debug purpose */
 650         padapter->fix_rate = 0xFF;
 651         padapter->driver_ampdu_spacing = 0xFF;
 652         padapter->driver_rx_ampdu_factor =  0xFF;
 653 
 654 }
 655 
 656 struct dvobj_priv *devobj_init(void)
 657 {
 658         struct dvobj_priv *pdvobj = NULL;
 659 
 660         pdvobj = rtw_zmalloc(sizeof(*pdvobj));
 661         if (pdvobj == NULL)
 662                 return NULL;
 663 
 664         mutex_init(&pdvobj->hw_init_mutex);
 665         mutex_init(&pdvobj->h2c_fwcmd_mutex);
 666         mutex_init(&pdvobj->setch_mutex);
 667         mutex_init(&pdvobj->setbw_mutex);
 668 
 669         spin_lock_init(&pdvobj->lock);
 670 
 671         pdvobj->macid[1] = true; /* macid = 1 for bc/mc stainfo */
 672 
 673         pdvobj->processing_dev_remove = false;
 674 
 675         atomic_set(&pdvobj->disable_func, 0);
 676 
 677         spin_lock_init(&pdvobj->cam_ctl.lock);
 678 
 679         return pdvobj;
 680 }
 681 
 682 void devobj_deinit(struct dvobj_priv *pdvobj)
 683 {
 684         if (!pdvobj)
 685                 return;
 686 
 687         mutex_destroy(&pdvobj->hw_init_mutex);
 688         mutex_destroy(&pdvobj->h2c_fwcmd_mutex);
 689         mutex_destroy(&pdvobj->setch_mutex);
 690         mutex_destroy(&pdvobj->setbw_mutex);
 691 
 692         kfree(pdvobj);
 693 }
 694 
 695 void rtw_reset_drv_sw(struct adapter *padapter)
 696 {
 697         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
 698         struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
 699 
 700         /* hal_priv */
 701         if (is_primary_adapter(padapter))
 702                 rtw_hal_def_value_init(padapter);
 703 
 704         RTW_ENABLE_FUNC(padapter, DF_RX_BIT);
 705         RTW_ENABLE_FUNC(padapter, DF_TX_BIT);
 706         padapter->bLinkInfoDump = 0;
 707 
 708         padapter->xmitpriv.tx_pkts = 0;
 709         padapter->recvpriv.rx_pkts = 0;
 710 
 711         pmlmepriv->LinkDetectInfo.bBusyTraffic = false;
 712 
 713         /* pmlmepriv->LinkDetectInfo.TrafficBusyState = false; */
 714         pmlmepriv->LinkDetectInfo.TrafficTransitionCount = 0;
 715         pmlmepriv->LinkDetectInfo.LowPowerTransitionCount = 0;
 716 
 717         _clr_fwstate_(pmlmepriv, _FW_UNDER_SURVEY | _FW_UNDER_LINKING);
 718 
 719         pwrctrlpriv->pwr_state_check_cnts = 0;
 720 
 721         /* mlmeextpriv */
 722         padapter->mlmeextpriv.sitesurvey_res.state = SCAN_DISABLE;
 723 
 724         rtw_set_signal_stat_timer(&padapter->recvpriv);
 725 
 726 }
 727 
 728 
 729 u8 rtw_init_drv_sw(struct adapter *padapter)
 730 {
 731         u8 ret8 = _SUCCESS;
 732 
 733         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_init_drv_sw\n"));
 734 
 735         rtw_init_default_value(padapter);
 736 
 737         rtw_init_hal_com_default_value(padapter);
 738 
 739         if (rtw_init_cmd_priv(&padapter->cmdpriv)) {
 740                 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init cmd_priv\n"));
 741                 ret8 = _FAIL;
 742                 goto exit;
 743         }
 744 
 745         padapter->cmdpriv.padapter = padapter;
 746 
 747         if (rtw_init_evt_priv(&padapter->evtpriv)) {
 748                 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init evt_priv\n"));
 749                 ret8 = _FAIL;
 750                 goto exit;
 751         }
 752 
 753 
 754         if (rtw_init_mlme_priv(padapter) == _FAIL) {
 755                 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("\n Can't init mlme_priv\n"));
 756                 ret8 = _FAIL;
 757                 goto exit;
 758         }
 759 
 760         init_mlme_ext_priv(padapter);
 761 
 762         if (_rtw_init_xmit_priv(&padapter->xmitpriv, padapter) == _FAIL) {
 763                 DBG_871X("Can't _rtw_init_xmit_priv\n");
 764                 ret8 = _FAIL;
 765                 goto exit;
 766         }
 767 
 768         if (_rtw_init_recv_priv(&padapter->recvpriv, padapter) == _FAIL) {
 769                 DBG_871X("Can't _rtw_init_recv_priv\n");
 770                 ret8 = _FAIL;
 771                 goto exit;
 772         }
 773         /*  add for CONFIG_IEEE80211W, none 11w also can use */
 774         spin_lock_init(&padapter->security_key_mutex);
 775 
 776         /*  We don't need to memset padapter->XXX to zero, because adapter is allocated by vzalloc(). */
 777         /* memset((unsigned char *)&padapter->securitypriv, 0, sizeof (struct security_priv)); */
 778 
 779         if (_rtw_init_sta_priv(&padapter->stapriv) == _FAIL) {
 780                 DBG_871X("Can't _rtw_init_sta_priv\n");
 781                 ret8 = _FAIL;
 782                 goto exit;
 783         }
 784 
 785         padapter->stapriv.padapter = padapter;
 786         padapter->setband = GHZ24_50;
 787         padapter->fix_rate = 0xFF;
 788         rtw_init_bcmc_stainfo(padapter);
 789 
 790         rtw_init_pwrctrl_priv(padapter);
 791 
 792         rtw_hal_dm_init(padapter);
 793 
 794 exit:
 795 
 796         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_init_drv_sw\n"));
 797 
 798         return ret8;
 799 }
 800 
 801 void rtw_cancel_all_timer(struct adapter *padapter)
 802 {
 803         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+rtw_cancel_all_timer\n"));
 804 
 805         del_timer_sync(&padapter->mlmepriv.assoc_timer);
 806         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel association timer complete!\n"));
 807 
 808         del_timer_sync(&padapter->mlmepriv.scan_to_timer);
 809         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel scan_to_timer!\n"));
 810 
 811         del_timer_sync(&padapter->mlmepriv.dynamic_chk_timer);
 812         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel dynamic_chk_timer!\n"));
 813 
 814         del_timer_sync(&(adapter_to_pwrctl(padapter)->pwr_state_check_timer));
 815 
 816         del_timer_sync(&padapter->mlmepriv.set_scan_deny_timer);
 817         rtw_clear_scan_deny(padapter);
 818         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("rtw_cancel_all_timer:cancel set_scan_deny_timer!\n"));
 819 
 820         del_timer_sync(&padapter->recvpriv.signal_stat_timer);
 821 
 822         /* cancel dm timer */
 823         rtw_hal_dm_deinit(padapter);
 824 }
 825 
 826 u8 rtw_free_drv_sw(struct adapter *padapter)
 827 {
 828         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("==>rtw_free_drv_sw"));
 829 
 830         free_mlme_ext_priv(&padapter->mlmeextpriv);
 831 
 832         rtw_free_cmd_priv(&padapter->cmdpriv);
 833 
 834         rtw_free_evt_priv(&padapter->evtpriv);
 835 
 836         rtw_free_mlme_priv(&padapter->mlmepriv);
 837 
 838         /* free_io_queue(padapter); */
 839 
 840         _rtw_free_xmit_priv(&padapter->xmitpriv);
 841 
 842         _rtw_free_sta_priv(&padapter->stapriv); /* will free bcmc_stainfo here */
 843 
 844         _rtw_free_recv_priv(&padapter->recvpriv);
 845 
 846         rtw_free_pwrctrl_priv(padapter);
 847 
 848         /* kfree((void *)padapter); */
 849 
 850         rtw_hal_free_data(padapter);
 851 
 852         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("<==rtw_free_drv_sw\n"));
 853 
 854         /* free the old_pnetdev */
 855         if (padapter->rereg_nd_name_priv.old_pnetdev) {
 856                 free_netdev(padapter->rereg_nd_name_priv.old_pnetdev);
 857                 padapter->rereg_nd_name_priv.old_pnetdev = NULL;
 858         }
 859 
 860         /*  clear pbuddystruct adapter to avoid access wrong pointer. */
 861         if (padapter->pbuddy_adapter != NULL)
 862                 padapter->pbuddy_adapter->pbuddy_adapter = NULL;
 863 
 864         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-rtw_free_drv_sw\n"));
 865 
 866         return _SUCCESS;
 867 }
 868 
 869 static int _rtw_drv_register_netdev(struct adapter *padapter, char *name)
 870 {
 871         int ret = _SUCCESS;
 872         struct net_device *pnetdev = padapter->pnetdev;
 873 
 874         /* alloc netdev name */
 875         if (rtw_init_netdev_name(pnetdev, name))
 876                 return _FAIL;
 877 
 878         memcpy(pnetdev->dev_addr, padapter->eeprompriv.mac_addr, ETH_ALEN);
 879 
 880         /* Tell the network stack we exist */
 881         if (register_netdev(pnetdev) != 0) {
 882                 DBG_871X(FUNC_NDEV_FMT "Failed!\n", FUNC_NDEV_ARG(pnetdev));
 883                 ret = _FAIL;
 884                 goto error_register_netdev;
 885         }
 886 
 887         DBG_871X("%s, MAC Address (if%d) = " MAC_FMT "\n", __func__, (padapter->iface_id + 1), MAC_ARG(pnetdev->dev_addr));
 888 
 889         return ret;
 890 
 891 error_register_netdev:
 892 
 893         rtw_free_drv_sw(padapter);
 894 
 895         rtw_free_netdev(pnetdev);
 896 
 897         return ret;
 898 }
 899 
 900 int rtw_drv_register_netdev(struct adapter *if1)
 901 {
 902         struct dvobj_priv *dvobj = if1->dvobj;
 903         struct adapter *padapter = dvobj->padapters;
 904         char *name = if1->registrypriv.ifname;
 905 
 906         return _rtw_drv_register_netdev(padapter, name);
 907 }
 908 
 909 int _netdev_open(struct net_device *pnetdev)
 910 {
 911         uint status;
 912         struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
 913         struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
 914 
 915         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+871x_drv - dev_open\n"));
 916         DBG_871X("+871x_drv - drv_open, bup =%d\n", padapter->bup);
 917 
 918         padapter->netif_up = true;
 919 
 920         if (pwrctrlpriv->ps_flag == true) {
 921                 padapter->net_closed = false;
 922                 goto netdev_open_normal_process;
 923         }
 924 
 925         if (padapter->bup == false) {
 926                 padapter->bDriverStopped = false;
 927                 padapter->bSurpriseRemoved = false;
 928                 padapter->bCardDisableWOHSM = false;
 929 
 930                 status = rtw_hal_init(padapter);
 931                 if (status == _FAIL) {
 932                         RT_TRACE(_module_os_intfs_c_, _drv_err_, ("rtl871x_hal_init(): Can't init h/w!\n"));
 933                         goto netdev_open_error;
 934                 }
 935 
 936                 DBG_871X("MAC Address = " MAC_FMT "\n", MAC_ARG(pnetdev->dev_addr));
 937 
 938                 status = rtw_start_drv_threads(padapter);
 939                 if (status == _FAIL) {
 940                         DBG_871X("Initialize driver software resource Failed!\n");
 941                         goto netdev_open_error;
 942                 }
 943 
 944                 if (padapter->intf_start)
 945                         padapter->intf_start(padapter);
 946 
 947                 rtw_cfg80211_init_wiphy(padapter);
 948 
 949                 padapter->bup = true;
 950                 pwrctrlpriv->bips_processing = false;
 951         }
 952         padapter->net_closed = false;
 953 
 954         _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
 955 
 956         if (!rtw_netif_queue_stopped(pnetdev))
 957                 rtw_netif_start_queue(pnetdev);
 958         else
 959                 rtw_netif_wake_queue(pnetdev);
 960 
 961 netdev_open_normal_process:
 962 
 963         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-871x_drv - dev_open\n"));
 964         DBG_871X("-871x_drv - drv_open, bup =%d\n", padapter->bup);
 965 
 966         return 0;
 967 
 968 netdev_open_error:
 969 
 970         padapter->bup = false;
 971 
 972         netif_carrier_off(pnetdev);
 973         rtw_netif_stop_queue(pnetdev);
 974 
 975         RT_TRACE(_module_os_intfs_c_, _drv_err_, ("-871x_drv - dev_open, fail!\n"));
 976         DBG_871X("-871x_drv - drv_open fail, bup =%d\n", padapter->bup);
 977 
 978         return (-1);
 979 }
 980 
 981 int netdev_open(struct net_device *pnetdev)
 982 {
 983         int ret;
 984         struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
 985         struct pwrctrl_priv *pwrctrlpriv = adapter_to_pwrctl(padapter);
 986 
 987         if (pwrctrlpriv->bInSuspend == true) {
 988                 DBG_871X("+871x_drv - drv_open, bInSuspend =%d\n", pwrctrlpriv->bInSuspend);
 989                 return 0;
 990         }
 991 
 992         if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->hw_init_mutex)))
 993                 return -1;
 994 
 995         ret = _netdev_open(pnetdev);
 996         mutex_unlock(&(adapter_to_dvobj(padapter)->hw_init_mutex));
 997 
 998         return ret;
 999 }
1000 
1001 static int  ips_netdrv_open(struct adapter *padapter)
1002 {
1003         int status = _SUCCESS;
1004         /* struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter); */
1005 
1006         padapter->net_closed = false;
1007 
1008         DBG_871X("===> %s.........\n", __func__);
1009 
1010 
1011         padapter->bDriverStopped = false;
1012         padapter->bCardDisableWOHSM = false;
1013         /* padapter->bup = true; */
1014 
1015         status = rtw_hal_init(padapter);
1016         if (status == _FAIL) {
1017                 RT_TRACE(_module_os_intfs_c_, _drv_err_, ("ips_netdrv_open(): Can't init h/w!\n"));
1018                 goto netdev_open_error;
1019         }
1020 
1021         if (padapter->intf_start)
1022                 padapter->intf_start(padapter);
1023 
1024         _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
1025 
1026         return _SUCCESS;
1027 
1028 netdev_open_error:
1029         /* padapter->bup = false; */
1030         DBG_871X("-ips_netdrv_open - drv_open failure, bup =%d\n", padapter->bup);
1031 
1032         return _FAIL;
1033 }
1034 
1035 
1036 int rtw_ips_pwr_up(struct adapter *padapter)
1037 {
1038         int result;
1039         DBG_871X("===>  rtw_ips_pwr_up..............\n");
1040 
1041         result = ips_netdrv_open(padapter);
1042 
1043         DBG_871X("<===  rtw_ips_pwr_up..............\n");
1044         return result;
1045 }
1046 
1047 void rtw_ips_pwr_down(struct adapter *padapter)
1048 {
1049         DBG_871X("===> rtw_ips_pwr_down...................\n");
1050 
1051         padapter->bCardDisableWOHSM = true;
1052         padapter->net_closed = true;
1053 
1054         rtw_ips_dev_unload(padapter);
1055         padapter->bCardDisableWOHSM = false;
1056         DBG_871X("<=== rtw_ips_pwr_down.....................\n");
1057 }
1058 
1059 void rtw_ips_dev_unload(struct adapter *padapter)
1060 {
1061         DBG_871X("====> %s...\n", __func__);
1062 
1063 
1064         if (padapter->bSurpriseRemoved == false)
1065                 rtw_hal_deinit(padapter);
1066 }
1067 
1068 
1069 static int pm_netdev_open(struct net_device *pnetdev, u8 bnormal)
1070 {
1071         int status = -1;
1072 
1073         struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
1074 
1075         if (true == bnormal) {
1076                 if (mutex_lock_interruptible(&(adapter_to_dvobj(padapter)->hw_init_mutex)) == 0) {
1077                         status = _netdev_open(pnetdev);
1078                         mutex_unlock(&(adapter_to_dvobj(padapter)->hw_init_mutex));
1079                 }
1080         }
1081         else
1082                 status =  (_SUCCESS == ips_netdrv_open(padapter)) ? (0) : (-1);
1083 
1084         return status;
1085 }
1086 
1087 static int netdev_close(struct net_device *pnetdev)
1088 {
1089         struct adapter *padapter = (struct adapter *)rtw_netdev_priv(pnetdev);
1090         struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
1091 
1092         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("+871x_drv - drv_close\n"));
1093 
1094         if (pwrctl->bInternalAutoSuspend == true) {
1095                 /* rtw_pwr_wakeup(padapter); */
1096                 if (pwrctl->rf_pwrstate == rf_off)
1097                         pwrctl->ps_flag = true;
1098         }
1099         padapter->net_closed = true;
1100         padapter->netif_up = false;
1101 
1102 /*if (!padapter->hw_init_completed)
1103         {
1104                 DBG_871X("(1)871x_drv - drv_close, bup =%d, hw_init_completed =%d\n", padapter->bup, padapter->hw_init_completed);
1105 
1106                 padapter->bDriverStopped = true;
1107 
1108                 rtw_dev_unload(padapter);
1109         }
1110         else*/
1111         if (pwrctl->rf_pwrstate == rf_on) {
1112                 DBG_871X("(2)871x_drv - drv_close, bup =%d, hw_init_completed =%d\n", padapter->bup, padapter->hw_init_completed);
1113 
1114                 /* s1. */
1115                 if (pnetdev) {
1116                         if (!rtw_netif_queue_stopped(pnetdev))
1117                                 rtw_netif_stop_queue(pnetdev);
1118                 }
1119 
1120                 /* s2. */
1121                 LeaveAllPowerSaveMode(padapter);
1122                 rtw_disassoc_cmd(padapter, 500, false);
1123                 /* s2-2.  indicate disconnect to os */
1124                 rtw_indicate_disconnect(padapter);
1125                 /* s2-3. */
1126                 rtw_free_assoc_resources(padapter, 1);
1127                 /* s2-4. */
1128                 rtw_free_network_queue(padapter, true);
1129         }
1130 
1131         rtw_scan_abort(padapter);
1132         adapter_wdev_data(padapter)->bandroid_scan = false;
1133 
1134         RT_TRACE(_module_os_intfs_c_, _drv_info_, ("-871x_drv - drv_close\n"));
1135         DBG_871X("-871x_drv - drv_close, bup =%d\n", padapter->bup);
1136 
1137         return 0;
1138 }
1139 
1140 void rtw_ndev_destructor(struct net_device *ndev)
1141 {
1142         DBG_871X(FUNC_NDEV_FMT "\n", FUNC_NDEV_ARG(ndev));
1143 
1144         if (ndev->ieee80211_ptr)
1145                 kfree((u8 *)ndev->ieee80211_ptr);
1146 }
1147 
1148 void rtw_dev_unload(struct adapter *padapter)
1149 {
1150         struct pwrctrl_priv *pwrctl = adapter_to_pwrctl(padapter);
1151         struct dvobj_priv *pobjpriv = padapter->dvobj;
1152         struct debug_priv *pdbgpriv = &pobjpriv->drv_dbg;
1153         struct cmd_priv *pcmdpriv = &padapter->cmdpriv;
1154         u8 cnt = 0;
1155 
1156         RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("+%s\n", __func__));
1157 
1158         if (padapter->bup == true) {
1159                 DBG_871X("===> %s\n", __func__);
1160 
1161                 padapter->bDriverStopped = true;
1162                 if (padapter->xmitpriv.ack_tx)
1163                         rtw_ack_tx_done(&padapter->xmitpriv, RTW_SCTX_DONE_DRV_STOP);
1164 
1165                 if (padapter->intf_stop)
1166                         padapter->intf_stop(padapter);
1167 
1168                 RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ rtw_dev_unload: stop intf complete!\n"));
1169 
1170                 if (!pwrctl->bInternalAutoSuspend)
1171                         rtw_stop_drv_threads(padapter);
1172 
1173                 while (atomic_read(&(pcmdpriv->cmdthd_running)) == true) {
1174                         if (cnt > 5) {
1175                                 DBG_871X("stop cmdthd timeout\n");
1176                                 break;
1177                         } else {
1178                                 cnt ++;
1179                                 DBG_871X("cmdthd is running(%d)\n", cnt);
1180                                 msleep(10);
1181                         }
1182                 }
1183 
1184                 RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("@ %s: stop thread complete!\n", __func__));
1185 
1186                 /* check the status of IPS */
1187                 if (rtw_hal_check_ips_status(padapter) == true || pwrctl->rf_pwrstate == rf_off) { /* check HW status and SW state */
1188                         DBG_871X_LEVEL(_drv_always_, "%s: driver in IPS-FWLPS\n", __func__);
1189                         pdbgpriv->dbg_dev_unload_inIPS_cnt++;
1190                         LeaveAllPowerSaveMode(padapter);
1191                 } else {
1192                         DBG_871X_LEVEL(_drv_always_, "%s: driver not in IPS\n", __func__);
1193                 }
1194 
1195                 if (padapter->bSurpriseRemoved == false) {
1196                         hal_btcoex_IpsNotify(padapter, pwrctl->ips_mode_req);
1197 #ifdef CONFIG_WOWLAN
1198                         if (pwrctl->bSupportRemoteWakeup == true &&
1199                                 pwrctl->wowlan_mode == true) {
1200                                 DBG_871X_LEVEL(_drv_always_, "%s bSupportRemoteWakeup ==true  do not run rtw_hal_deinit()\n", __func__);
1201                         }
1202                         else
1203 #endif
1204                         {
1205                                 /* amy modify 20120221 for power seq is different between driver open and ips */
1206                                 rtw_hal_deinit(padapter);
1207                         }
1208                         padapter->bSurpriseRemoved = true;
1209                 }
1210                 RT_TRACE(_module_hci_intfs_c_, _drv_notice_,
1211                          ("@ %s: deinit hal complete!\n", __func__));
1212 
1213                 padapter->bup = false;
1214 
1215                 DBG_871X("<=== %s\n", __func__);
1216         }
1217         else {
1218                 RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("%s: bup ==false\n", __func__));
1219                 DBG_871X("%s: bup ==false\n", __func__);
1220         }
1221 
1222         RT_TRACE(_module_hci_intfs_c_, _drv_notice_, ("-%s\n", __func__));
1223 }
1224 
1225 static int rtw_suspend_free_assoc_resource(struct adapter *padapter)
1226 {
1227         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1228 
1229         DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1230 
1231         if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) {
1232                 if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)
1233                         && check_fwstate(pmlmepriv, _FW_LINKED)) {
1234                         DBG_871X("%s %s(" MAC_FMT "), length:%d assoc_ssid.length:%d\n", __func__,
1235                                         pmlmepriv->cur_network.network.Ssid.Ssid,
1236                                         MAC_ARG(pmlmepriv->cur_network.network.MacAddress),
1237                                         pmlmepriv->cur_network.network.Ssid.SsidLength,
1238                                         pmlmepriv->assoc_ssid.SsidLength);
1239                         rtw_set_to_roam(padapter, 1);
1240                 }
1241         }
1242 
1243         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) && check_fwstate(pmlmepriv, _FW_LINKED)) {
1244                 rtw_disassoc_cmd(padapter, 0, false);
1245                 /* s2-2.  indicate disconnect to os */
1246                 rtw_indicate_disconnect(padapter);
1247         }
1248         else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1249                 rtw_sta_flush(padapter);
1250         }
1251 
1252         /* s2-3. */
1253         rtw_free_assoc_resources(padapter, 1);
1254 
1255         /* s2-4. */
1256         rtw_free_network_queue(padapter, true);
1257 
1258         if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY))
1259                 rtw_indicate_scan_done(padapter, 1);
1260 
1261         if (check_fwstate(pmlmepriv, _FW_UNDER_LINKING) == true) {
1262                 DBG_871X_LEVEL(_drv_always_, "%s: fw_under_linking\n", __func__);
1263                 rtw_indicate_disconnect(padapter);
1264         }
1265 
1266         DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1267         return _SUCCESS;
1268 }
1269 
1270 #ifdef CONFIG_WOWLAN
1271 void rtw_suspend_wow(struct adapter *padapter)
1272 {
1273         u8 ch, bw, offset;
1274         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1275         struct net_device *pnetdev = padapter->pnetdev;
1276         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1277         struct wowlan_ioctl_param poidparam;
1278 
1279         DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1280 
1281 
1282         DBG_871X("wowlan_mode: %d\n", pwrpriv->wowlan_mode);
1283         DBG_871X("wowlan_pno_enable: %d\n", pwrpriv->wowlan_pno_enable);
1284 
1285         if (pwrpriv->wowlan_mode == true) {
1286                 if (pnetdev)
1287                         rtw_netif_stop_queue(pnetdev);
1288                 /*  1. stop thread */
1289                 padapter->bDriverStopped = true;        /* for stop thread */
1290                 rtw_stop_drv_threads(padapter);
1291                 padapter->bDriverStopped = false;       /* for 32k command */
1292 
1293                 /*  2. disable interrupt */
1294                 if (padapter->intf_stop) {
1295                         padapter->intf_stop(padapter);
1296                 }
1297 
1298                 /*  2.1 clean interupt */
1299                 if (padapter->HalFunc.clear_interrupt)
1300                         padapter->HalFunc.clear_interrupt(padapter);
1301 
1302                 /*  2.2 free irq */
1303                 /* sdio_free_irq(adapter_to_dvobj(padapter)); */
1304                 if (padapter->intf_free_irq)
1305                         padapter->intf_free_irq(adapter_to_dvobj(padapter));
1306 
1307                 poidparam.subcode = WOWLAN_ENABLE;
1308                 padapter->HalFunc.SetHwRegHandler(padapter, HW_VAR_WOWLAN, (u8 *)&poidparam);
1309                 if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) {
1310                         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)
1311                                 && check_fwstate(pmlmepriv, _FW_LINKED)) {
1312                                 DBG_871X("%s %s(" MAC_FMT "), length:%d assoc_ssid.length:%d\n", __func__,
1313                                                 pmlmepriv->cur_network.network.Ssid.Ssid,
1314                                                 MAC_ARG(pmlmepriv->cur_network.network.MacAddress),
1315                                                 pmlmepriv->cur_network.network.Ssid.SsidLength,
1316                                                 pmlmepriv->assoc_ssid.SsidLength);
1317 
1318                                 rtw_set_to_roam(padapter, 0);
1319                         }
1320                 }
1321 
1322                 DBG_871X_LEVEL(_drv_always_, "%s: wowmode suspending\n", __func__);
1323 
1324                 if (check_fwstate(pmlmepriv, _FW_UNDER_SURVEY) == true) {
1325                         DBG_871X_LEVEL(_drv_always_, "%s: fw_under_survey\n", __func__);
1326                         rtw_indicate_scan_done(padapter, 1);
1327                         clr_fwstate(pmlmepriv, _FW_UNDER_SURVEY);
1328                 }
1329 
1330                 if (rtw_get_ch_setting_union(padapter, &ch, &bw, &offset) != 0) {
1331                         DBG_871X(FUNC_ADPT_FMT " back to linked/linking union - ch:%u, bw:%u, offset:%u\n",
1332                                 FUNC_ADPT_ARG(padapter), ch, bw, offset);
1333                         set_channel_bwmode(padapter, ch, offset, bw);
1334                 }
1335 
1336                 if (pwrpriv->wowlan_pno_enable)
1337                         DBG_871X_LEVEL(_drv_always_, "%s: pno: %d\n", __func__, pwrpriv->wowlan_pno_enable);
1338                 else
1339                         rtw_set_ps_mode(padapter, PS_MODE_DTIM, 0, 0, "WOWLAN");
1340         }
1341         else {
1342                 DBG_871X_LEVEL(_drv_always_, "%s: ### ERROR ### wowlan_mode =%d\n", __func__, pwrpriv->wowlan_mode);
1343         }
1344         DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1345 }
1346 #endif /* ifdef CONFIG_WOWLAN */
1347 
1348 #ifdef CONFIG_AP_WOWLAN
1349 void rtw_suspend_ap_wow(struct adapter *padapter)
1350 {
1351         u8 ch, bw, offset;
1352         struct net_device *pnetdev = padapter->pnetdev;
1353         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1354         struct wowlan_ioctl_param poidparam;
1355 
1356         DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1357 
1358         pwrpriv->wowlan_ap_mode = true;
1359 
1360         DBG_871X("wowlan_ap_mode: %d\n", pwrpriv->wowlan_ap_mode);
1361 
1362         if (pnetdev)
1363                 rtw_netif_stop_queue(pnetdev);
1364         /*  1. stop thread */
1365         padapter->bDriverStopped = true;        /* for stop thread */
1366         rtw_stop_drv_threads(padapter);
1367         padapter->bDriverStopped = false;       /* for 32k command */
1368 
1369         /*  2. disable interrupt */
1370         rtw_hal_disable_interrupt(padapter); /*  It need wait for leaving 32K. */
1371 
1372         /*  2.1 clean interupt */
1373         if (padapter->HalFunc.clear_interrupt)
1374                 padapter->HalFunc.clear_interrupt(padapter);
1375 
1376         /*  2.2 free irq */
1377         /* sdio_free_irq(adapter_to_dvobj(padapter)); */
1378         if (padapter->intf_free_irq)
1379                 padapter->intf_free_irq(adapter_to_dvobj(padapter));
1380 
1381         poidparam.subcode = WOWLAN_AP_ENABLE;
1382         padapter->HalFunc.SetHwRegHandler(padapter,
1383                                         HW_VAR_AP_WOWLAN, (u8 *)&poidparam);
1384 
1385         DBG_871X_LEVEL(_drv_always_, "%s: wowmode suspending\n", __func__);
1386 
1387         if (rtw_get_ch_setting_union(padapter, &ch, &bw, &offset) != 0) {
1388                 DBG_871X(FUNC_ADPT_FMT " back to linked/linking union - ch:%u, bw:%u, offset:%u\n",
1389                          FUNC_ADPT_ARG(padapter), ch, bw, offset);
1390                 set_channel_bwmode(padapter, ch, offset, bw);
1391         }
1392 
1393         rtw_set_ps_mode(padapter, PS_MODE_MIN, 0, 0, "AP-WOWLAN");
1394 
1395         DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1396 }
1397 #endif /* ifdef CONFIG_AP_WOWLAN */
1398 
1399 
1400 static void rtw_suspend_normal(struct adapter *padapter)
1401 {
1402         struct net_device *pnetdev = padapter->pnetdev;
1403 
1404         DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1405         if (pnetdev) {
1406                 netif_carrier_off(pnetdev);
1407                 rtw_netif_stop_queue(pnetdev);
1408         }
1409 
1410         rtw_suspend_free_assoc_resource(padapter);
1411 
1412         if ((rtw_hal_check_ips_status(padapter) == true)
1413                 || (adapter_to_pwrctl(padapter)->rf_pwrstate == rf_off)) {
1414                 DBG_871X_LEVEL(_drv_always_, "%s: ### ERROR #### driver in IPS ####ERROR###!!!\n", __func__);
1415         }
1416 
1417         rtw_dev_unload(padapter);
1418 
1419         /* sdio_deinit(adapter_to_dvobj(padapter)); */
1420         if (padapter->intf_deinit)
1421                 padapter->intf_deinit(adapter_to_dvobj(padapter));
1422 
1423         DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1424 }
1425 
1426 int rtw_suspend_common(struct adapter *padapter)
1427 {
1428         struct dvobj_priv *psdpriv = padapter->dvobj;
1429         struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
1430         struct pwrctrl_priv *pwrpriv = dvobj_to_pwrctl(psdpriv);
1431         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1432 
1433         int ret = 0;
1434         unsigned long start_time = jiffies;
1435 
1436         DBG_871X_LEVEL(_drv_always_, " suspend start\n");
1437         DBG_871X("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
1438         pdbgpriv->dbg_suspend_cnt++;
1439 
1440         pwrpriv->bInSuspend = true;
1441 
1442         while (pwrpriv->bips_processing == true)
1443                 msleep(1);
1444 
1445         if ((!padapter->bup) || (padapter->bDriverStopped) || (padapter->bSurpriseRemoved)) {
1446                 DBG_871X("%s bup =%d bDriverStopped =%d bSurpriseRemoved = %d\n", __func__
1447                         , padapter->bup, padapter->bDriverStopped, padapter->bSurpriseRemoved);
1448                 pdbgpriv->dbg_suspend_error_cnt++;
1449                 goto exit;
1450         }
1451         rtw_ps_deny(padapter, PS_DENY_SUSPEND);
1452 
1453         rtw_cancel_all_timer(padapter);
1454 
1455         LeaveAllPowerSaveModeDirect(padapter);
1456 
1457         rtw_stop_cmd_thread(padapter);
1458 
1459         /*  wait for the latest FW to remove this condition. */
1460         if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
1461                 hal_btcoex_SuspendNotify(padapter, 0);
1462                 DBG_871X("WIFI_AP_STATE\n");
1463         } else if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
1464                 hal_btcoex_SuspendNotify(padapter, 1);
1465                 DBG_871X("STATION\n");
1466         }
1467 
1468         rtw_ps_deny_cancel(padapter, PS_DENY_SUSPEND);
1469 
1470         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
1471         #ifdef CONFIG_WOWLAN
1472                 if (check_fwstate(pmlmepriv, _FW_LINKED)) {
1473                         pwrpriv->wowlan_mode = true;
1474                 } else if (pwrpriv->wowlan_pno_enable == true) {
1475                         pwrpriv->wowlan_mode |= pwrpriv->wowlan_pno_enable;
1476                 }
1477 
1478                 if (pwrpriv->wowlan_mode == true)
1479                 rtw_suspend_wow(padapter);
1480                 else
1481                         rtw_suspend_normal(padapter);
1482 
1483         #else /* CONFIG_WOWLAN */
1484                 rtw_suspend_normal(padapter);
1485         #endif /* CONFIG_WOWLAN */
1486         } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
1487         #ifdef CONFIG_AP_WOWLAN
1488                 rtw_suspend_ap_wow(padapter);
1489         #else
1490                 rtw_suspend_normal(padapter);
1491         #endif /* CONFIG_AP_WOWLAN */
1492         } else {
1493                 rtw_suspend_normal(padapter);
1494         }
1495 
1496         DBG_871X_LEVEL(_drv_always_, "rtw suspend success in %d ms\n",
1497                 jiffies_to_msecs(jiffies - start_time));
1498 
1499 exit:
1500         DBG_871X("<===  %s return %d.............. in %dms\n", __func__
1501                 , ret, jiffies_to_msecs(jiffies - start_time));
1502 
1503         return ret;
1504 }
1505 
1506 #ifdef CONFIG_WOWLAN
1507 int rtw_resume_process_wow(struct adapter *padapter)
1508 {
1509         struct mlme_ext_priv *pmlmeext = &padapter->mlmeextpriv;
1510         struct mlme_ext_info *pmlmeinfo = &(pmlmeext->mlmext_info);
1511         struct net_device *pnetdev = padapter->pnetdev;
1512         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1513         struct dvobj_priv *psdpriv = padapter->dvobj;
1514         struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
1515         struct wowlan_ioctl_param poidparam;
1516         struct sta_info *psta = NULL;
1517         int ret = _SUCCESS;
1518 
1519         DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1520 
1521         if (padapter) {
1522                 pnetdev = padapter->pnetdev;
1523                 pwrpriv = adapter_to_pwrctl(padapter);
1524         } else {
1525                 pdbgpriv->dbg_resume_error_cnt++;
1526                 ret = -1;
1527                 goto exit;
1528         }
1529 
1530         if (padapter->bDriverStopped || padapter->bSurpriseRemoved) {
1531                 DBG_871X("%s pdapter %p bDriverStopped %d bSurpriseRemoved %d\n",
1532                                 __func__, padapter, padapter->bDriverStopped,
1533                                 padapter->bSurpriseRemoved);
1534                 goto exit;
1535         }
1536 
1537 #ifdef CONFIG_PNO_SUPPORT
1538         pwrpriv->pno_in_resume = true;
1539 #endif
1540 
1541         if (pwrpriv->wowlan_mode == true) {
1542                 rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, "WOWLAN");
1543 
1544                 pwrpriv->bFwCurrentInPSMode = false;
1545 
1546                 if (padapter->intf_stop) {
1547                         padapter->intf_stop(padapter);
1548                 }
1549 
1550                 if (padapter->HalFunc.clear_interrupt)
1551                         padapter->HalFunc.clear_interrupt(padapter);
1552 
1553                 /* if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) { */
1554                 if ((padapter->intf_alloc_irq) && (padapter->intf_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS)) {
1555                         ret = -1;
1556                         RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __func__));
1557                         goto exit;
1558                 }
1559 
1560                 /* Disable WOW, set H2C command */
1561                 poidparam.subcode = WOWLAN_DISABLE;
1562                 padapter->HalFunc.SetHwRegHandler(padapter, HW_VAR_WOWLAN, (u8 *)&poidparam);
1563 
1564                 psta = rtw_get_stainfo(&padapter->stapriv, get_bssid(&padapter->mlmepriv));
1565                 if (psta) {
1566                         set_sta_rate(padapter, psta);
1567                 }
1568 
1569 
1570                 padapter->bDriverStopped = false;
1571                 DBG_871X("%s: wowmode resuming, DriverStopped:%d\n", __func__, padapter->bDriverStopped);
1572                 rtw_start_drv_threads(padapter);
1573 
1574                 if (padapter->intf_start) {
1575                         padapter->intf_start(padapter);
1576                 }
1577 
1578                 /*  start netif queue */
1579                 if (pnetdev) {
1580                         if (!rtw_netif_queue_stopped(pnetdev))
1581                                 rtw_netif_start_queue(pnetdev);
1582                         else
1583                                 rtw_netif_wake_queue(pnetdev);
1584                 }
1585         }
1586         else {
1587                 DBG_871X_LEVEL(_drv_always_, "%s: ### ERROR ### wowlan_mode =%d\n", __func__, pwrpriv->wowlan_mode);
1588         }
1589 
1590         if (padapter->pid[1] != 0) {
1591                 DBG_871X("pid[1]:%d\n", padapter->pid[1]);
1592                 rtw_signal_process(padapter->pid[1], SIGUSR2);
1593         }
1594 
1595         if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME)) {
1596                 if (pwrpriv->wowlan_wake_reason == FWDecisionDisconnect ||
1597                         pwrpriv->wowlan_wake_reason == Rx_DisAssoc ||
1598                         pwrpriv->wowlan_wake_reason == Rx_DeAuth) {
1599                         DBG_871X("%s: disconnect reason: %02x\n", __func__,
1600                                                 pwrpriv->wowlan_wake_reason);
1601                         rtw_indicate_disconnect(padapter);
1602 
1603                         rtw_sta_media_status_rpt(padapter,
1604                                 rtw_get_stainfo(&padapter->stapriv,
1605                                         get_bssid(&padapter->mlmepriv)), 0);
1606 
1607                         rtw_free_assoc_resources(padapter, 1);
1608                         pmlmeinfo->state = WIFI_FW_NULL_STATE;
1609 
1610                 } else {
1611                         DBG_871X("%s: do roaming\n", __func__);
1612                         rtw_roaming(padapter, NULL);
1613                 }
1614         }
1615 
1616         if (pwrpriv->wowlan_mode == true) {
1617                 pwrpriv->bips_processing = false;
1618                 _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
1619         } else {
1620                 DBG_871X_LEVEL(_drv_always_, "do not reset timer\n");
1621         }
1622 
1623         pwrpriv->wowlan_mode = false;
1624 
1625         /* clean driver side wake up reason. */
1626         pwrpriv->wowlan_wake_reason = 0;
1627 exit:
1628         DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1629         return ret;
1630 }
1631 #endif /* ifdef CONFIG_WOWLAN */
1632 
1633 #ifdef CONFIG_AP_WOWLAN
1634 int rtw_resume_process_ap_wow(struct adapter *padapter)
1635 {
1636         struct net_device *pnetdev = padapter->pnetdev;
1637         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1638         struct dvobj_priv *psdpriv = padapter->dvobj;
1639         struct debug_priv *pdbgpriv = &psdpriv->drv_dbg;
1640         struct wowlan_ioctl_param poidparam;
1641         int ret = _SUCCESS;
1642 
1643         DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1644 
1645         if (padapter) {
1646                 pnetdev = padapter->pnetdev;
1647                 pwrpriv = adapter_to_pwrctl(padapter);
1648         } else {
1649                 pdbgpriv->dbg_resume_error_cnt++;
1650                 ret = -1;
1651                 goto exit;
1652         }
1653 
1654         rtw_set_ps_mode(padapter, PS_MODE_ACTIVE, 0, 0, "AP-WOWLAN");
1655 
1656         pwrpriv->bFwCurrentInPSMode = false;
1657 
1658         rtw_hal_disable_interrupt(padapter);
1659 
1660         if (padapter->HalFunc.clear_interrupt)
1661                 padapter->HalFunc.clear_interrupt(padapter);
1662 
1663         /* if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) { */
1664         if ((padapter->intf_alloc_irq) && (padapter->intf_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS)) {
1665                 ret = -1;
1666                 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __func__));
1667                 goto exit;
1668         }
1669 
1670         /* Disable WOW, set H2C command */
1671         poidparam.subcode = WOWLAN_AP_DISABLE;
1672         padapter->HalFunc.SetHwRegHandler(padapter,
1673                 HW_VAR_AP_WOWLAN, (u8 *)&poidparam);
1674         pwrpriv->wowlan_ap_mode = false;
1675 
1676         padapter->bDriverStopped = false;
1677         DBG_871X("%s: wowmode resuming, DriverStopped:%d\n", __func__, padapter->bDriverStopped);
1678         rtw_start_drv_threads(padapter);
1679 
1680         if (padapter->intf_start) {
1681                 padapter->intf_start(padapter);
1682         }
1683 
1684         /*  start netif queue */
1685         if (pnetdev) {
1686                 if (!rtw_netif_queue_stopped(pnetdev))
1687                         rtw_netif_start_queue(pnetdev);
1688                 else
1689                         rtw_netif_wake_queue(pnetdev);
1690         }
1691 
1692         if (padapter->pid[1] != 0) {
1693                 DBG_871X("pid[1]:%d\n", padapter->pid[1]);
1694                 rtw_signal_process(padapter->pid[1], SIGUSR2);
1695         }
1696 
1697         pwrpriv->bips_processing = false;
1698         _set_timer(&padapter->mlmepriv.dynamic_chk_timer, 2000);
1699 
1700         /* clean driver side wake up reason. */
1701         pwrpriv->wowlan_wake_reason = 0;
1702 exit:
1703         DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1704         return ret;
1705 }
1706 #endif /* ifdef CONFIG_APWOWLAN */
1707 
1708 static int rtw_resume_process_normal(struct adapter *padapter)
1709 {
1710         struct net_device *pnetdev;
1711         struct pwrctrl_priv *pwrpriv;
1712         struct mlme_priv *pmlmepriv;
1713         struct dvobj_priv *psdpriv;
1714         struct debug_priv *pdbgpriv;
1715 
1716         int ret = _SUCCESS;
1717 
1718         if (!padapter) {
1719                 ret = -1;
1720                 goto exit;
1721         }
1722 
1723         pnetdev = padapter->pnetdev;
1724         pwrpriv = adapter_to_pwrctl(padapter);
1725         pmlmepriv = &padapter->mlmepriv;
1726         psdpriv = padapter->dvobj;
1727         pdbgpriv = &psdpriv->drv_dbg;
1728 
1729         DBG_871X("==> " FUNC_ADPT_FMT " entry....\n", FUNC_ADPT_ARG(padapter));
1730         /*  interface init */
1731         /* if (sdio_init(adapter_to_dvobj(padapter)) != _SUCCESS) */
1732         if ((padapter->intf_init) && (padapter->intf_init(adapter_to_dvobj(padapter)) != _SUCCESS)) {
1733                 ret = -1;
1734                 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: initialize SDIO Failed!!\n", __func__));
1735                 goto exit;
1736         }
1737         rtw_hal_disable_interrupt(padapter);
1738         /* if (sdio_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS) */
1739         if ((padapter->intf_alloc_irq) && (padapter->intf_alloc_irq(adapter_to_dvobj(padapter)) != _SUCCESS)) {
1740                 ret = -1;
1741                 RT_TRACE(_module_hci_intfs_c_, _drv_err_, ("%s: sdio_alloc_irq Failed!!\n", __func__));
1742                 goto exit;
1743         }
1744 
1745         rtw_reset_drv_sw(padapter);
1746         pwrpriv->bkeepfwalive = false;
1747 
1748         DBG_871X("bkeepfwalive(%x)\n", pwrpriv->bkeepfwalive);
1749         if (pm_netdev_open(pnetdev, true) != 0) {
1750                 ret = -1;
1751                 pdbgpriv->dbg_resume_error_cnt++;
1752                 goto exit;
1753         }
1754 
1755         netif_device_attach(pnetdev);
1756         netif_carrier_on(pnetdev);
1757 
1758         if (padapter->pid[1] != 0) {
1759                 DBG_871X("pid[1]:%d\n", padapter->pid[1]);
1760                 rtw_signal_process(padapter->pid[1], SIGUSR2);
1761         }
1762 
1763 
1764         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE)) {
1765                 DBG_871X(FUNC_ADPT_FMT " fwstate:0x%08x - WIFI_STATION_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
1766 
1767                 if (rtw_chk_roam_flags(padapter, RTW_ROAM_ON_RESUME))
1768                         rtw_roaming(padapter, NULL);
1769 
1770         } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE)) {
1771                 DBG_871X(FUNC_ADPT_FMT " fwstate:0x%08x - WIFI_AP_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
1772                 rtw_ap_restore_network(padapter);
1773         } else if (check_fwstate(pmlmepriv, WIFI_ADHOC_STATE)) {
1774                 DBG_871X(FUNC_ADPT_FMT " fwstate:0x%08x - WIFI_ADHOC_STATE\n", FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
1775         } else {
1776                 DBG_871X(FUNC_ADPT_FMT " fwstate:0x%08x - ???\n", FUNC_ADPT_ARG(padapter), get_fwstate(pmlmepriv));
1777         }
1778 
1779         DBG_871X("<== " FUNC_ADPT_FMT " exit....\n", FUNC_ADPT_ARG(padapter));
1780 
1781 exit:
1782         return ret;
1783 }
1784 
1785 int rtw_resume_common(struct adapter *padapter)
1786 {
1787         int ret = 0;
1788         unsigned long start_time = jiffies;
1789         struct pwrctrl_priv *pwrpriv = adapter_to_pwrctl(padapter);
1790         struct mlme_priv *pmlmepriv = &padapter->mlmepriv;
1791 
1792         DBG_871X_LEVEL(_drv_always_, "resume start\n");
1793         DBG_871X("==> %s (%s:%d)\n", __func__, current->comm, current->pid);
1794 
1795         if (check_fwstate(pmlmepriv, WIFI_STATION_STATE) == true) {
1796         #ifdef CONFIG_WOWLAN
1797                 if (pwrpriv->wowlan_mode == true)
1798                         rtw_resume_process_wow(padapter);
1799                 else
1800                         rtw_resume_process_normal(padapter);
1801         #else
1802                 rtw_resume_process_normal(padapter);
1803         #endif
1804 
1805         } else if (check_fwstate(pmlmepriv, WIFI_AP_STATE) == true) {
1806         #ifdef CONFIG_AP_WOWLAN
1807                 rtw_resume_process_ap_wow(padapter);
1808         #else
1809                 rtw_resume_process_normal(padapter);
1810         #endif /* CONFIG_AP_WOWLAN */
1811         } else {
1812                 rtw_resume_process_normal(padapter);
1813         }
1814 
1815         hal_btcoex_SuspendNotify(padapter, 0);
1816 
1817         if (pwrpriv) {
1818                 pwrpriv->bInSuspend = false;
1819         #ifdef CONFIG_PNO_SUPPORT
1820                 pwrpriv->pno_in_resume = false;
1821         #endif
1822         }
1823         DBG_871X_LEVEL(_drv_always_, "%s:%d in %d ms\n", __func__ , ret,
1824                 jiffies_to_msecs(jiffies - start_time));
1825 
1826         return ret;
1827 }

/* [<][>][^][v][top][bottom][index][help] */