iwlagn: move PCI power related functions to the PCI layer
[firefly-linux-kernel-4.4.55.git] / drivers / net / wireless / iwlwifi / iwl-core.c
index 4653deada05b48b1383f1cda6b33c7477a1717d3..360df33585ee507251c9589fb7ae5cc3298e52b0 100644 (file)
 #include "iwl-helpers.h"
 #include "iwl-agn.h"
 
-
-/*
- * set bt_coex_active to true, uCode will do kill/defer
- * every time the priority line is asserted (BT is sending signals on the
- * priority line in the PCIx).
- * set bt_coex_active to false, uCode will ignore the BT activity and
- * perform the normal operation
- *
- * User might experience transmit issue on some platform due to WiFi/BT
- * co-exist problem. The possible behaviors are:
- *   Able to scan and finding all the available AP
- *   Not able to associate with any AP
- * On those platforms, WiFi communication can be restored by set
- * "bt_coex_active" module parameter to "false"
- *
- * default: bt_coex_active = true (BT_COEX_ENABLE)
- */
-bool bt_coex_active = true;
-module_param(bt_coex_active, bool, S_IRUGO);
-MODULE_PARM_DESC(bt_coex_active, "enable wifi/bluetooth co-exist");
-
 u32 iwl_debug_level;
 
 const u8 iwl_bcast_addr[ETH_ALEN] = { 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF };
@@ -164,7 +143,7 @@ int iwlcore_init_geos(struct iwl_priv *priv)
        sband->bitrates = &rates[IWL_FIRST_OFDM_RATE];
        sband->n_bitrates = IWL_RATE_COUNT_LEGACY - IWL_FIRST_OFDM_RATE;
 
-       if (priv->cfg->sku & IWL_SKU_N)
+       if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
                iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
                                         IEEE80211_BAND_5GHZ);
 
@@ -174,7 +153,7 @@ int iwlcore_init_geos(struct iwl_priv *priv)
        sband->bitrates = rates;
        sband->n_bitrates = IWL_RATE_COUNT_LEGACY;
 
-       if (priv->cfg->sku & IWL_SKU_N)
+       if (priv->cfg->sku & EEPROM_SKU_CAP_11N_ENABLE)
                iwlcore_init_ht_hw_capab(priv, &sband->ht_cap,
                                         IEEE80211_BAND_2GHZ);
 
@@ -229,12 +208,12 @@ int iwlcore_init_geos(struct iwl_priv *priv)
        priv->tx_power_next = max_tx_power;
 
        if ((priv->bands[IEEE80211_BAND_5GHZ].n_channels == 0) &&
-            priv->cfg->sku & IWL_SKU_A) {
+            priv->cfg->sku & EEPROM_SKU_CAP_BAND_52GHZ) {
                IWL_INFO(priv, "Incorrectly detected BG card as ABG. "
                        "Please send your PCI ID 0x%04X:0x%04X to maintainer.\n",
                           priv->pci_dev->device,
                           priv->pci_dev->subsystem_device);
-               priv->cfg->sku &= ~IWL_SKU_A;
+               priv->cfg->sku &= ~EEPROM_SKU_CAP_BAND_52GHZ;
        }
 
        IWL_INFO(priv, "Tunable channels: %d 802.11bg, %d 802.11a channels\n",
@@ -843,12 +822,8 @@ void iwl_chswitch_done(struct iwl_priv *priv, bool is_success)
        if (test_bit(STATUS_EXIT_PENDING, &priv->status))
                return;
 
-       if (priv->switch_rxon.switch_in_progress) {
+       if (test_and_clear_bit(STATUS_CHANNEL_SWITCH_PENDING, &priv->status))
                ieee80211_chswitch_done(ctx->vif, is_success);
-               mutex_lock(&priv->mutex);
-               priv->switch_rxon.switch_in_progress = false;
-               mutex_unlock(&priv->mutex);
-       }
 }
 
 #ifdef CONFIG_IWLWIFI_DEBUG
@@ -1022,8 +997,6 @@ void iwl_apm_stop(struct iwl_priv *priv)
 int iwl_apm_init(struct iwl_priv *priv)
 {
        int ret = 0;
-       u16 lctl;
-
        IWL_DEBUG_INFO(priv, "Init card's basic functions\n");
 
        /*
@@ -1052,27 +1025,7 @@ int iwl_apm_init(struct iwl_priv *priv)
        iwl_set_bit(priv, CSR_HW_IF_CONFIG_REG,
                                    CSR_HW_IF_CONFIG_REG_BIT_HAP_WAKE_L1A);
 
-       /*
-        * HW bug W/A for instability in PCIe bus L0->L0S->L1 transition.
-        * Check if BIOS (or OS) enabled L1-ASPM on this device.
-        * If so (likely), disable L0S, so device moves directly L0->L1;
-        *    costs negligible amount of power savings.
-        * If not (unlikely), enable L0S, so there is at least some
-        *    power savings, even without L1.
-        */
-       lctl = iwl_pcie_link_ctl(priv);
-       if ((lctl & PCI_CFG_LINK_CTRL_VAL_L1_EN) ==
-                               PCI_CFG_LINK_CTRL_VAL_L1_EN) {
-               /* L1-ASPM enabled; disable(!) L0S  */
-               iwl_set_bit(priv, CSR_GIO_REG,
-                               CSR_GIO_REG_VAL_L0S_ENABLED);
-               IWL_DEBUG_POWER(priv, "L1 Enabled; Disabling L0S\n");
-       } else {
-               /* L1-ASPM disabled; enable(!) L0S */
-               iwl_clear_bit(priv, CSR_GIO_REG,
-                               CSR_GIO_REG_VAL_L0S_ENABLED);
-               IWL_DEBUG_POWER(priv, "L1 Disabled; Enabling L0S\n");
-       }
+       priv->bus.ops->apm_config(&priv->bus);
 
        /* Configure analog phase-lock-loop before activating to D0A */
        if (priv->cfg->base_params->pll_cfg_val)
@@ -1131,9 +1084,6 @@ int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
        if (priv->tx_power_user_lmt == tx_power && !force)
                return 0;
 
-       if (!priv->cfg->ops->lib->send_tx_power)
-               return -EOPNOTSUPP;
-
        if (tx_power < IWLAGN_TX_POWER_TARGET_POWER_MIN) {
                IWL_WARN(priv,
                         "Requested user TXPOWER %d below lower limit %d.\n",
@@ -1167,7 +1117,7 @@ int iwl_set_tx_power(struct iwl_priv *priv, s8 tx_power, bool force)
        prev_tx_power = priv->tx_power_user_lmt;
        priv->tx_power_user_lmt = tx_power;
 
-       ret = priv->cfg->ops->lib->send_tx_power(priv);
+       ret = iwlagn_send_tx_power(priv);
 
        /* if fail to set tx_power, restore the orig. tx power */
        if (ret) {
@@ -1186,7 +1136,7 @@ void iwl_send_bt_config(struct iwl_priv *priv)
                .kill_cts_mask = 0,
        };
 
-       if (!bt_coex_active)
+       if (!iwlagn_mod_params.bt_coex_active)
                bt_cmd.flags = BT_COEX_DISABLE;
        else
                bt_cmd.flags = BT_COEX_ENABLE;
@@ -1282,7 +1232,7 @@ static int iwl_set_mode(struct iwl_priv *priv, struct iwl_rxon_context *ctx)
        if (priv->cfg->ops->hcmd->set_rxon_chain)
                priv->cfg->ops->hcmd->set_rxon_chain(priv, ctx);
 
-       return iwlcore_commit_rxon(priv, ctx);
+       return iwlagn_commit_rxon(priv, ctx);
 }
 
 static int iwl_setup_interface(struct iwl_priv *priv,
@@ -1976,11 +1926,8 @@ __le32 iwl_add_beacon_time(struct iwl_priv *priv, u32 base,
 
 #ifdef CONFIG_PM
 
-int iwl_pci_suspend(struct device *device)
+int iwl_suspend(struct iwl_priv *priv)
 {
-       struct pci_dev *pdev = to_pci_dev(device);
-       struct iwl_priv *priv = pci_get_drvdata(pdev);
-
        /*
         * This function is called when system goes into suspend state
         * mac80211 will call iwl_mac_stop() from the mac80211 suspend function
@@ -1993,18 +1940,10 @@ int iwl_pci_suspend(struct device *device)
        return 0;
 }
 
-int iwl_pci_resume(struct device *device)
+int iwl_resume(struct iwl_priv *priv)
 {
-       struct pci_dev *pdev = to_pci_dev(device);
-       struct iwl_priv *priv = pci_get_drvdata(pdev);
        bool hw_rfkill = false;
 
-       /*
-        * We disable the RETRY_TIMEOUT register (0x41) to keep
-        * PCI Tx retries from interfering with C3 CPU state.
-        */
-       pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
-
        iwl_enable_interrupts(priv);
 
        if (!(iwl_read32(priv, CSR_GP_CNTRL) &
@@ -2021,13 +1960,4 @@ int iwl_pci_resume(struct device *device)
        return 0;
 }
 
-const struct dev_pm_ops iwl_pm_ops = {
-       .suspend = iwl_pci_suspend,
-       .resume = iwl_pci_resume,
-       .freeze = iwl_pci_suspend,
-       .thaw = iwl_pci_resume,
-       .poweroff = iwl_pci_suspend,
-       .restore = iwl_pci_resume,
-};
-
 #endif /* CONFIG_PM */