1 /******************************************************************************
3 * Copyright(c) 2007 - 2011 Intel Corporation. All rights reserved.
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of version 2 of the GNU General Public License as
10 * published by the Free Software Foundation.
12 * This program is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
17 * You should have received a copy of the GNU General Public License along with
18 * this program; if not, write to the Free Software Foundation, Inc.,
19 * 51 Franklin Street, Fifth Floor, Boston, MA 02110, USA
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
24 * Contact Information:
25 * Intel Linux Wireless <ilw@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
30 #include <linux/kernel.h>
31 #include <linux/module.h>
32 #include <linux/slab.h>
33 #include <linux/init.h>
35 #include <net/mac80211.h>
37 #include "iwl-eeprom.h"
41 #include "iwl-commands.h"
42 #include "iwl-debug.h"
43 #include "iwl-power.h"
46 * Setting power level allows the card to go to sleep when not busy.
48 * We calculate a sleep command based on the required latency, which
49 * we get from mac80211. In order to handle thermal throttling, we can
50 * also use pre-defined power levels.
54 * This defines the old power levels. They are still used by default
55 * (level 1) and for thermal throttle (levels 3 through 5)
58 struct il_power_vec_entry
{
59 struct il_powertable_cmd cmd
;
60 u8 no_dtim
; /* number of skip dtim */
63 static void il_power_sleep_cam_cmd(struct il_priv
*il
,
64 struct il_powertable_cmd
*cmd
)
66 memset(cmd
, 0, sizeof(*cmd
));
68 if (il
->power_data
.pci_pm
)
69 cmd
->flags
|= IL_POWER_PCI_PM_MSK
;
71 D_POWER("Sleep command for CAM\n");
75 il_set_power(struct il_priv
*il
, struct il_powertable_cmd
*cmd
)
77 D_POWER("Sending power/sleep command\n");
78 D_POWER("Flags value = 0x%08X\n", cmd
->flags
);
79 D_POWER("Tx timeout = %u\n",
80 le32_to_cpu(cmd
->tx_data_timeout
));
81 D_POWER("Rx timeout = %u\n",
82 le32_to_cpu(cmd
->rx_data_timeout
));
84 "Sleep interval vector = { %d , %d , %d , %d , %d }\n",
85 le32_to_cpu(cmd
->sleep_interval
[0]),
86 le32_to_cpu(cmd
->sleep_interval
[1]),
87 le32_to_cpu(cmd
->sleep_interval
[2]),
88 le32_to_cpu(cmd
->sleep_interval
[3]),
89 le32_to_cpu(cmd
->sleep_interval
[4]));
91 return il_send_cmd_pdu(il
, POWER_TBL_CMD
,
92 sizeof(struct il_powertable_cmd
), cmd
);
96 il_power_set_mode(struct il_priv
*il
, struct il_powertable_cmd
*cmd
,
102 lockdep_assert_held(&il
->mutex
);
104 /* Don't update the RX chain when chain noise calibration is running */
105 update_chains
= il
->chain_noise_data
.state
== IL_CHAIN_NOISE_DONE
||
106 il
->chain_noise_data
.state
== IL_CHAIN_NOISE_ALIVE
;
108 if (!memcmp(&il
->power_data
.sleep_cmd
, cmd
, sizeof(*cmd
)) && !force
)
111 if (!il_is_ready_rf(il
))
114 /* scan complete use sleep_power_next, need to be updated */
115 memcpy(&il
->power_data
.sleep_cmd_next
, cmd
, sizeof(*cmd
));
116 if (test_bit(STATUS_SCANNING
, &il
->status
) && !force
) {
117 D_INFO("Defer power set mode while scanning\n");
121 if (cmd
->flags
& IL_POWER_DRIVER_ALLOW_SLEEP_MSK
)
122 set_bit(STATUS_POWER_PMI
, &il
->status
);
124 ret
= il_set_power(il
, cmd
);
126 if (!(cmd
->flags
& IL_POWER_DRIVER_ALLOW_SLEEP_MSK
))
127 clear_bit(STATUS_POWER_PMI
, &il
->status
);
129 if (il
->cfg
->ops
->lib
->update_chain_flags
&& update_chains
)
130 il
->cfg
->ops
->lib
->update_chain_flags(il
);
131 else if (il
->cfg
->ops
->lib
->update_chain_flags
)
133 "Cannot update the power, chain noise "
134 "calibration running: %d\n",
135 il
->chain_noise_data
.state
);
137 memcpy(&il
->power_data
.sleep_cmd
, cmd
, sizeof(*cmd
));
139 IL_ERR("set power fail, ret = %d", ret
);
144 int il_power_update_mode(struct il_priv
*il
, bool force
)
146 struct il_powertable_cmd cmd
;
148 il_power_sleep_cam_cmd(il
, &cmd
);
149 return il_power_set_mode(il
, &cmd
, force
);
151 EXPORT_SYMBOL(il_power_update_mode
);
153 /* initialize to default */
154 void il_power_initialize(struct il_priv
*il
)
156 u16 lctl
= il_pcie_link_ctl(il
);
158 il
->power_data
.pci_pm
= !(lctl
& PCI_CFG_LINK_CTRL_VAL_L0S_EN
);
160 il
->power_data
.debug_sleep_level_override
= -1;
162 memset(&il
->power_data
.sleep_cmd
, 0,
163 sizeof(il
->power_data
.sleep_cmd
));
165 EXPORT_SYMBOL(il_power_initialize
);