2011-02-21 12:27:26 -07:00
|
|
|
/******************************************************************************
|
|
|
|
*
|
|
|
|
* Copyright(c) 2007 - 2011 Intel Corporation. All rights reserved.
|
|
|
|
*
|
|
|
|
* Portions of this file are derived from the ipw3945 project, as well
|
|
|
|
* as portions of the ieee80211 subsystem header files.
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of version 2 of the GNU General Public License as
|
|
|
|
* published by the Free Software Foundation.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
|
|
|
|
* more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License along with
|
|
|
|
* this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
* 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
|
|
|
|
*
|
|
|
|
* The full GNU General Public License is included in this distribution in the
|
|
|
|
* file called LICENSE.
|
|
|
|
*
|
|
|
|
* Contact Information:
|
|
|
|
* Intel Linux Wireless <ilw@linux.intel.com>
|
|
|
|
* Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
|
|
|
|
*****************************************************************************/
|
|
|
|
|
|
|
|
|
|
|
|
#include <linux/kernel.h>
|
|
|
|
#include <linux/module.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include <linux/init.h>
|
|
|
|
|
|
|
|
#include <net/mac80211.h>
|
|
|
|
|
|
|
|
#include "iwl-eeprom.h"
|
|
|
|
#include "iwl-dev.h"
|
|
|
|
#include "iwl-core.h"
|
|
|
|
#include "iwl-io.h"
|
|
|
|
#include "iwl-commands.h"
|
|
|
|
#include "iwl-debug.h"
|
|
|
|
#include "iwl-power.h"
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Setting power level allows the card to go to sleep when not busy.
|
|
|
|
*
|
|
|
|
* We calculate a sleep command based on the required latency, which
|
|
|
|
* we get from mac80211. In order to handle thermal throttling, we can
|
|
|
|
* also use pre-defined power levels.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* This defines the old power levels. They are still used by default
|
|
|
|
* (level 1) and for thermal throttle (levels 3 through 5)
|
|
|
|
*/
|
|
|
|
|
2011-10-24 07:41:30 -06:00
|
|
|
struct il_power_vec_entry {
|
|
|
|
struct il_powertable_cmd cmd;
|
2011-02-21 12:27:26 -07:00
|
|
|
u8 no_dtim; /* number of skip dtim */
|
|
|
|
};
|
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
static void il_power_sleep_cam_cmd(struct il_priv *il,
|
2011-10-24 07:41:30 -06:00
|
|
|
struct il_powertable_cmd *cmd)
|
2011-02-21 12:27:26 -07:00
|
|
|
{
|
|
|
|
memset(cmd, 0, sizeof(*cmd));
|
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
if (il->power_data.pci_pm)
|
2011-10-24 07:41:30 -06:00
|
|
|
cmd->flags |= IL_POWER_PCI_PM_MSK;
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-11-15 03:21:01 -07:00
|
|
|
D_POWER("Sleep command for CAM\n");
|
2011-02-21 12:27:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
2011-10-24 08:49:25 -06:00
|
|
|
il_set_power(struct il_priv *il, struct il_powertable_cmd *cmd)
|
2011-02-21 12:27:26 -07:00
|
|
|
{
|
2011-11-15 03:21:01 -07:00
|
|
|
D_POWER("Sending power/sleep command\n");
|
|
|
|
D_POWER("Flags value = 0x%08X\n", cmd->flags);
|
|
|
|
D_POWER("Tx timeout = %u\n",
|
2011-02-21 12:27:26 -07:00
|
|
|
le32_to_cpu(cmd->tx_data_timeout));
|
2011-11-15 03:21:01 -07:00
|
|
|
D_POWER("Rx timeout = %u\n",
|
2011-02-21 12:27:26 -07:00
|
|
|
le32_to_cpu(cmd->rx_data_timeout));
|
2011-11-15 03:21:01 -07:00
|
|
|
D_POWER(
|
2011-02-21 12:27:26 -07:00
|
|
|
"Sleep interval vector = { %d , %d , %d , %d , %d }\n",
|
|
|
|
le32_to_cpu(cmd->sleep_interval[0]),
|
|
|
|
le32_to_cpu(cmd->sleep_interval[1]),
|
|
|
|
le32_to_cpu(cmd->sleep_interval[2]),
|
|
|
|
le32_to_cpu(cmd->sleep_interval[3]),
|
|
|
|
le32_to_cpu(cmd->sleep_interval[4]));
|
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
return il_send_cmd_pdu(il, POWER_TABLE_CMD,
|
2011-10-24 07:41:30 -06:00
|
|
|
sizeof(struct il_powertable_cmd), cmd);
|
2011-02-21 12:27:26 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2011-10-24 08:49:25 -06:00
|
|
|
il_power_set_mode(struct il_priv *il, struct il_powertable_cmd *cmd,
|
2011-02-21 12:27:26 -07:00
|
|
|
bool force)
|
|
|
|
{
|
|
|
|
int ret;
|
|
|
|
bool update_chains;
|
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
lockdep_assert_held(&il->mutex);
|
2011-02-21 12:27:26 -07:00
|
|
|
|
|
|
|
/* Don't update the RX chain when chain noise calibration is running */
|
2011-10-24 08:49:25 -06:00
|
|
|
update_chains = il->chain_noise_data.state == IL_CHAIN_NOISE_DONE ||
|
|
|
|
il->chain_noise_data.state == IL_CHAIN_NOISE_ALIVE;
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
if (!memcmp(&il->power_data.sleep_cmd, cmd, sizeof(*cmd)) && !force)
|
2011-02-21 12:27:26 -07:00
|
|
|
return 0;
|
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
if (!il_is_ready_rf(il))
|
2011-02-21 12:27:26 -07:00
|
|
|
return -EIO;
|
|
|
|
|
|
|
|
/* scan complete use sleep_power_next, need to be updated */
|
2011-10-24 08:49:25 -06:00
|
|
|
memcpy(&il->power_data.sleep_cmd_next, cmd, sizeof(*cmd));
|
|
|
|
if (test_bit(STATUS_SCANNING, &il->status) && !force) {
|
2011-11-15 03:21:01 -07:00
|
|
|
D_INFO("Defer power set mode while scanning\n");
|
2011-02-21 12:27:26 -07:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2011-10-24 07:41:30 -06:00
|
|
|
if (cmd->flags & IL_POWER_DRIVER_ALLOW_SLEEP_MSK)
|
2011-10-24 08:49:25 -06:00
|
|
|
set_bit(STATUS_POWER_PMI, &il->status);
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
ret = il_set_power(il, cmd);
|
2011-02-21 12:27:26 -07:00
|
|
|
if (!ret) {
|
2011-10-24 07:41:30 -06:00
|
|
|
if (!(cmd->flags & IL_POWER_DRIVER_ALLOW_SLEEP_MSK))
|
2011-10-24 08:49:25 -06:00
|
|
|
clear_bit(STATUS_POWER_PMI, &il->status);
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
if (il->cfg->ops->lib->update_chain_flags && update_chains)
|
|
|
|
il->cfg->ops->lib->update_chain_flags(il);
|
|
|
|
else if (il->cfg->ops->lib->update_chain_flags)
|
2011-11-15 03:21:01 -07:00
|
|
|
D_POWER(
|
2011-02-21 12:27:26 -07:00
|
|
|
"Cannot update the power, chain noise "
|
|
|
|
"calibration running: %d\n",
|
2011-10-24 08:49:25 -06:00
|
|
|
il->chain_noise_data.state);
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
memcpy(&il->power_data.sleep_cmd, cmd, sizeof(*cmd));
|
2011-02-21 12:27:26 -07:00
|
|
|
} else
|
2011-08-18 14:07:57 -06:00
|
|
|
IL_ERR("set power fail, ret = %d", ret);
|
2011-02-21 12:27:26 -07:00
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
int il_power_update_mode(struct il_priv *il, bool force)
|
2011-02-21 12:27:26 -07:00
|
|
|
{
|
2011-10-24 07:41:30 -06:00
|
|
|
struct il_powertable_cmd cmd;
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
il_power_sleep_cam_cmd(il, &cmd);
|
|
|
|
return il_power_set_mode(il, &cmd, force);
|
2011-02-21 12:27:26 -07:00
|
|
|
}
|
2011-10-24 07:41:30 -06:00
|
|
|
EXPORT_SYMBOL(il_power_update_mode);
|
2011-02-21 12:27:26 -07:00
|
|
|
|
|
|
|
/* initialize to default */
|
2011-10-24 08:49:25 -06:00
|
|
|
void il_power_initialize(struct il_priv *il)
|
2011-02-21 12:27:26 -07:00
|
|
|
{
|
2011-10-24 08:49:25 -06:00
|
|
|
u16 lctl = il_pcie_link_ctl(il);
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
il->power_data.pci_pm = !(lctl & PCI_CFG_LINK_CTRL_VAL_L0S_EN);
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
il->power_data.debug_sleep_level_override = -1;
|
2011-02-21 12:27:26 -07:00
|
|
|
|
2011-10-24 08:49:25 -06:00
|
|
|
memset(&il->power_data.sleep_cmd, 0,
|
|
|
|
sizeof(il->power_data.sleep_cmd));
|
2011-02-21 12:27:26 -07:00
|
|
|
}
|
2011-10-24 07:41:30 -06:00
|
|
|
EXPORT_SYMBOL(il_power_initialize);
|