blob: 2d2ce98032678353628a8a954dd2b0cf27df2cbc [file] [log] [blame]
Johannes Berg8ca151b2013-01-24 14:25:36 +01001/******************************************************************************
2 *
3 * This file is provided under a dual BSD/GPLv2 license. When using or
4 * redistributing this file, you may do so under either license.
5 *
6 * GPL LICENSE SUMMARY
7 *
8 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of version 2 of the GNU General Public License as
12 * published by the Free Software Foundation.
13 *
14 * This program is distributed in the hope that it will be useful, but
15 * WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 * General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
22 * USA
23 *
24 * The full GNU General Public License is included in this distribution
Emmanuel Grumbach410dc5a2013-02-18 09:22:28 +020025 * in the file called COPYING.
Johannes Berg8ca151b2013-01-24 14:25:36 +010026 *
27 * Contact Information:
28 * Intel Linux Wireless <ilw@linux.intel.com>
29 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
30 *
31 * BSD LICENSE
32 *
33 * Copyright(c) 2012 - 2013 Intel Corporation. All rights reserved.
34 * All rights reserved.
35 *
36 * Redistribution and use in source and binary forms, with or without
37 * modification, are permitted provided that the following conditions
38 * are met:
39 *
40 * * Redistributions of source code must retain the above copyright
41 * notice, this list of conditions and the following disclaimer.
42 * * Redistributions in binary form must reproduce the above copyright
43 * notice, this list of conditions and the following disclaimer in
44 * the documentation and/or other materials provided with the
45 * distribution.
46 * * Neither the name Intel Corporation nor the names of its
47 * contributors may be used to endorse or promote products derived
48 * from this software without specific prior written permission.
49 *
50 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
51 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
52 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
53 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
54 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
55 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
56 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
57 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
58 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
59 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
60 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
61 *
62 *****************************************************************************/
63
64#include <linux/kernel.h>
65#include <linux/module.h>
66#include <linux/slab.h>
67#include <linux/init.h>
68
69#include <net/mac80211.h>
70
71#include "iwl-debug.h"
72#include "mvm.h"
73#include "iwl-modparams.h"
74#include "fw-api-power.h"
75
76#define POWER_KEEP_ALIVE_PERIOD_SEC 25
77
Alexander Bondar3f0b2b32013-03-05 14:08:23 +020078static void iwl_mvm_power_log(struct iwl_mvm *mvm,
79 struct iwl_powertable_cmd *cmd)
80{
81 IWL_DEBUG_POWER(mvm,
82 "Sending power table command for power level %d, flags = 0x%X\n",
83 iwlmvm_mod_params.power_scheme,
84 le16_to_cpu(cmd->flags));
85 IWL_DEBUG_POWER(mvm, "Keep alive = %u sec\n", cmd->keep_alive_seconds);
86
87 if (cmd->flags & cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK)) {
88 IWL_DEBUG_POWER(mvm, "Rx timeout = %u usec\n",
89 le32_to_cpu(cmd->rx_data_timeout));
90 IWL_DEBUG_POWER(mvm, "Tx timeout = %u usec\n",
91 le32_to_cpu(cmd->tx_data_timeout));
92 IWL_DEBUG_POWER(mvm, "LP RX RSSI threshold = %u\n",
93 cmd->lprx_rssi_threshold);
94 }
95}
96
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +020097static void iwl_mvm_power_build_cmd(struct iwl_mvm *mvm,
98 struct ieee80211_vif *vif,
99 struct iwl_powertable_cmd *cmd)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100100{
101 struct ieee80211_hw *hw = mvm->hw;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100102 struct ieee80211_chanctx_conf *chanctx_conf;
103 struct ieee80211_channel *chan;
104 int dtimper, dtimper_msec;
105 int keep_alive;
106 bool radar_detect = false;
107
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200108 /*
109 * Regardless of power management state the driver must set
110 * keep alive period. FW will use it for sending keep alive NDPs
111 * immediately after association.
112 */
113 cmd->keep_alive_seconds = POWER_KEEP_ALIVE_PERIOD_SEC;
114
Alexander Bondar9a613042013-03-05 12:54:00 +0200115 if ((iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_CAM) ||
116 !iwlwifi_mod_params.power_save)
Johannes Berg8ca151b2013-01-24 14:25:36 +0100117 return;
118
Alexander Bondar9a613042013-03-05 12:54:00 +0200119 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
120
121 if (!vif->bss_conf.ps)
122 return;
123
124 cmd->flags |= cpu_to_le16(POWER_FLAGS_POWER_MANAGEMENT_ENA_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100125
126 dtimper = hw->conf.ps_dtim_period ?: 1;
127
128 /* Check if radar detection is required on current channel */
129 rcu_read_lock();
130 chanctx_conf = rcu_dereference(vif->chanctx_conf);
131 WARN_ON(!chanctx_conf);
132 if (chanctx_conf) {
133 chan = chanctx_conf->def.chan;
134 radar_detect = chan->flags & IEEE80211_CHAN_RADAR;
135 }
136 rcu_read_unlock();
137
138 /* Check skip over DTIM conditions */
139 if (!radar_detect && (dtimper <= 10) &&
Alexander Bondar83bdad52013-02-03 21:26:44 +0200140 (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP))
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200141 cmd->flags |= cpu_to_le16(POWER_FLAGS_SKIP_OVER_DTIM_MSK);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100142
143 /* Check that keep alive period is at least 3 * DTIM */
144 dtimper_msec = dtimper * vif->bss_conf.beacon_int;
145 keep_alive = max_t(int, 3 * dtimper_msec,
Alexander Bondare16cf7e2013-03-05 14:01:27 +0200146 MSEC_PER_SEC * cmd->keep_alive_seconds);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100147 keep_alive = DIV_ROUND_UP(keep_alive, MSEC_PER_SEC);
Alexander Bondar83bdad52013-02-03 21:26:44 +0200148 cmd->keep_alive_seconds = keep_alive;
Johannes Berg8ca151b2013-01-24 14:25:36 +0100149
150 if (iwlmvm_mod_params.power_scheme == IWL_POWER_SCHEME_LP) {
151 /* TODO: Also for D3 (device sleep / WoWLAN) */
Alexander Bondar7c1bf932013-03-05 10:41:34 +0200152 cmd->rx_data_timeout = cpu_to_le32(10 * USEC_PER_MSEC);
153 cmd->tx_data_timeout = cpu_to_le32(10 * USEC_PER_MSEC);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100154 } else {
Alexander Bondar7c1bf932013-03-05 10:41:34 +0200155 cmd->rx_data_timeout = cpu_to_le32(50 * USEC_PER_MSEC);
156 cmd->tx_data_timeout = cpu_to_le32(50 * USEC_PER_MSEC);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100157 }
158}
159
160int iwl_mvm_power_update_mode(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
161{
162 struct iwl_powertable_cmd cmd = {};
163
Johannes Berg8ca151b2013-01-24 14:25:36 +0100164 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
165 return 0;
166
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200167 iwl_mvm_power_build_cmd(mvm, vif, &cmd);
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200168 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100169
170 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_SYNC,
171 sizeof(cmd), &cmd);
172}
173
174int iwl_mvm_power_disable(struct iwl_mvm *mvm, struct ieee80211_vif *vif)
175{
176 struct iwl_powertable_cmd cmd = {};
Johannes Berg8ca151b2013-01-24 14:25:36 +0100177
Johannes Berg8ca151b2013-01-24 14:25:36 +0100178 if (vif->type != NL80211_IFTYPE_STATION || vif->p2p)
179 return 0;
180
Alexander Bondar9a613042013-03-05 12:54:00 +0200181 if ((iwlmvm_mod_params.power_scheme != IWL_POWER_SCHEME_CAM) &&
182 iwlwifi_mod_params.power_save)
183 cmd.flags |= cpu_to_le16(POWER_FLAGS_POWER_SAVE_ENA_MSK);
184
Alexander Bondar3f0b2b32013-03-05 14:08:23 +0200185 iwl_mvm_power_log(mvm, &cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100186
Emmanuel Grumbach5360cfb2013-02-11 15:56:01 +0200187 return iwl_mvm_send_cmd_pdu(mvm, POWER_TABLE_CMD, CMD_ASYNC,
Johannes Berg8ca151b2013-01-24 14:25:36 +0100188 sizeof(cmd), &cmd);
189}
190
191#ifdef CONFIG_IWLWIFI_DEBUGFS
192void iwl_power_get_params(struct iwl_mvm *mvm, struct ieee80211_vif *vif,
193 struct iwl_powertable_cmd *cmd)
194{
Alexander Bondarf4a3e2f2013-03-05 13:47:04 +0200195 iwl_mvm_power_build_cmd(mvm, vif, cmd);
Johannes Berg8ca151b2013-01-24 14:25:36 +0100196}
197#endif /* CONFIG_IWLWIFI_DEBUGFS */