1 /******************************************************************************
5 * Copyright(c) 2008 Intel Corporation. All rights reserved.
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of version 2 of the GNU General Public License as
9 * published by the Free Software Foundation.
11 * This program is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
16 * You should have received a copy of the GNU General Public License
17 * along with this program; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110,
21 * The full GNU General Public License is included in this distribution
22 * in the file called LICENSE.GPL.
24 * Contact Information:
25 * Tomas Winkler <tomas.winkler@intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *****************************************************************************/
29 #include <linux/kernel.h>
30 #include <linux/module.h>
31 #include <linux/version.h>
32 #include <net/mac80211.h>
34 struct iwl_priv; /* FIXME: remove */
35 #include "iwl-debug.h"
36 #include "iwl-eeprom.h"
37 #include "iwl-4965.h" /* FIXME: remove */
39 #include "iwl-rfkill.h"
42 MODULE_DESCRIPTION("iwl core");
43 MODULE_VERSION(IWLWIFI_VERSION);
44 MODULE_AUTHOR(DRV_COPYRIGHT);
45 MODULE_LICENSE("GPL");
47 #ifdef CONFIG_IWLWIFI_DEBUG
49 EXPORT_SYMBOL(iwl_debug_level);
52 /* This function both allocates and initializes hw and priv. */
53 struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg,
54 struct ieee80211_ops *hw_ops)
56 struct iwl_priv *priv;
58 /* mac80211 allocates memory for this device instance, including
59 * space for this driver's private structure */
60 struct ieee80211_hw *hw =
61 ieee80211_alloc_hw(sizeof(struct iwl_priv), hw_ops);
63 IWL_ERROR("Can not allocate network device\n");
73 EXPORT_SYMBOL(iwl_alloc_all);
76 * iwlcore_clear_stations_table - Clear the driver's station table
78 * NOTE: This does not clear or otherwise alter the device's station table.
80 void iwlcore_clear_stations_table(struct iwl_priv *priv)
84 spin_lock_irqsave(&priv->sta_lock, flags);
86 priv->num_stations = 0;
87 memset(priv->stations, 0, sizeof(priv->stations));
89 spin_unlock_irqrestore(&priv->sta_lock, flags);
91 EXPORT_SYMBOL(iwlcore_clear_stations_table);
93 void iwlcore_reset_qos(struct iwl_priv *priv)
102 spin_lock_irqsave(&priv->lock, flags);
103 priv->qos_data.qos_active = 0;
105 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS) {
106 if (priv->qos_data.qos_enable)
107 priv->qos_data.qos_active = 1;
108 if (!(priv->active_rate & 0xfff0)) {
112 } else if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
113 if (priv->qos_data.qos_enable)
114 priv->qos_data.qos_active = 1;
115 } else if (!(priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK)) {
120 if (priv->qos_data.qos_active)
123 priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min);
124 priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max);
125 priv->qos_data.def_qos_parm.ac[0].aifsn = aifs;
126 priv->qos_data.def_qos_parm.ac[0].edca_txop = 0;
127 priv->qos_data.def_qos_parm.ac[0].reserved1 = 0;
129 if (priv->qos_data.qos_active) {
131 priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min);
132 priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max);
133 priv->qos_data.def_qos_parm.ac[i].aifsn = 7;
134 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
135 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
138 priv->qos_data.def_qos_parm.ac[i].cw_min =
139 cpu_to_le16((cw_min + 1) / 2 - 1);
140 priv->qos_data.def_qos_parm.ac[i].cw_max =
142 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
144 priv->qos_data.def_qos_parm.ac[i].edca_txop =
147 priv->qos_data.def_qos_parm.ac[i].edca_txop =
149 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
152 priv->qos_data.def_qos_parm.ac[i].cw_min =
153 cpu_to_le16((cw_min + 1) / 4 - 1);
154 priv->qos_data.def_qos_parm.ac[i].cw_max =
155 cpu_to_le16((cw_max + 1) / 2 - 1);
156 priv->qos_data.def_qos_parm.ac[i].aifsn = 2;
157 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
159 priv->qos_data.def_qos_parm.ac[i].edca_txop =
162 priv->qos_data.def_qos_parm.ac[i].edca_txop =
165 for (i = 1; i < 4; i++) {
166 priv->qos_data.def_qos_parm.ac[i].cw_min =
168 priv->qos_data.def_qos_parm.ac[i].cw_max =
170 priv->qos_data.def_qos_parm.ac[i].aifsn = aifs;
171 priv->qos_data.def_qos_parm.ac[i].edca_txop = 0;
172 priv->qos_data.def_qos_parm.ac[i].reserved1 = 0;
175 IWL_DEBUG_QOS("set QoS to default \n");
177 spin_unlock_irqrestore(&priv->lock, flags);
179 EXPORT_SYMBOL(iwlcore_reset_qos);
182 * iwlcore_set_rxon_channel - Set the phymode and channel values in staging RXON
183 * @phymode: MODE_IEEE80211A sets to 5.2GHz; all else set to 2.4GHz
184 * @channel: Any channel valid for the requested phymode
186 * In addition to setting the staging RXON, priv->phymode is also set.
188 * NOTE: Does not commit to the hardware; it sets appropriate bit fields
189 * in the staging RXON flag structure based on the phymode
191 int iwlcore_set_rxon_channel(struct iwl_priv *priv,
192 enum ieee80211_band band,
195 if (!iwl_get_channel_info(priv, band, channel)) {
196 IWL_DEBUG_INFO("Could not set channel to %d [%d]\n",
201 if ((le16_to_cpu(priv->staging_rxon.channel) == channel) &&
202 (priv->band == band))
205 priv->staging_rxon.channel = cpu_to_le16(channel);
206 if (band == IEEE80211_BAND_5GHZ)
207 priv->staging_rxon.flags &= ~RXON_FLG_BAND_24G_MSK;
209 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
213 IWL_DEBUG_INFO("Staging channel set to %d [%d]\n", channel, band);
217 EXPORT_SYMBOL(iwlcore_set_rxon_channel);
219 static void iwlcore_init_hw(struct iwl_priv *priv)
221 struct ieee80211_hw *hw = priv->hw;
222 hw->rate_control_algorithm = "iwl-4965-rs";
224 /* Tell mac80211 and its clients (e.g. Wireless Extensions)
225 * the range of signal quality values that we'll provide.
226 * Negative values for level/noise indicate that we'll provide dBm.
227 * For WE, at least, non-0 values here *enable* display of values
228 * in app (iwconfig). */
229 hw->max_rssi = -20; /* signal level, negative indicates dBm */
230 hw->max_noise = -20; /* noise level, negative indicates dBm */
231 hw->max_signal = 100; /* link quality indication (%) */
233 /* Tell mac80211 our Tx characteristics */
234 hw->flags = IEEE80211_HW_HOST_GEN_BEACON_TEMPLATE;
236 /* Default value; 4 EDCA QOS priorities */
238 #ifdef CONFIG_IWL4965_HT
239 /* Enhanced value; more queues, to support 11n aggregation */
241 #endif /* CONFIG_IWL4965_HT */
244 int iwl_setup(struct iwl_priv *priv)
247 iwlcore_init_hw(priv);
248 ret = priv->cfg->ops->lib->init_drv(priv);
251 EXPORT_SYMBOL(iwl_setup);
253 /* Low level driver call this function to update iwlcore with
256 int iwlcore_low_level_notify(struct iwl_priv *priv,
257 enum iwlcore_card_notify notify)
261 case IWLCORE_INIT_EVT:
262 ret = iwl_rfkill_init(priv);
264 IWL_ERROR("Unable to initialize RFKILL system. "
265 "Ignoring error: %d\n", ret);
267 case IWLCORE_START_EVT:
269 case IWLCORE_STOP_EVT:
271 case IWLCORE_REMOVE_EVT:
272 iwl_rfkill_unregister(priv);
278 EXPORT_SYMBOL(iwlcore_low_level_notify);