blob: 2af9a14446e4ce564475a9b561a9b25362fb2932 [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatreeb7ae892008-03-11 16:17:17 -07003 * Copyright(c) 2003 - 2008 Intel Corporation. All rights reserved.
Zhu Yib481de92007-09-25 17:54:57 -07004 *
5 * Portions of this file are derived from the ipw3945 project, as well
6 * as portions of the ieee80211 subsystem header files.
7 *
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.
11 *
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
15 * more details.
16 *
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
20 *
21 * The full GNU General Public License is included in this distribution in the
22 * file called LICENSE.
23 *
24 * Contact Information:
25 * James P. Ketrenos <ipw2100-admin@linux.intel.com>
26 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
Zhu Yib481de92007-09-25 17:54:57 -070043#include <net/mac80211.h>
44
45#include <asm/div64.h>
46
Assaf Krauss6bc913b2008-03-11 16:17:18 -070047#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070048#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070049#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070050#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070051#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070052#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070053#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070054
Christoph Hellwig416e1432007-10-25 17:15:49 +080055
Zhu Yib481de92007-09-25 17:54:57 -070056/******************************************************************************
57 *
58 * module boiler plate
59 *
60 ******************************************************************************/
61
Zhu Yib481de92007-09-25 17:54:57 -070062/*
63 * module name, copyright, version, etc.
64 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
65 */
66
Tomas Winklerd783b062008-07-18 13:53:02 +080067#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link AGN driver for Linux"
Zhu Yib481de92007-09-25 17:54:57 -070068
Tomas Winkler0a6857e2008-03-12 16:58:49 -070069#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070070#define VD "d"
71#else
72#define VD
73#endif
74
Tomas Winkler4fc22b22008-07-21 18:54:42 +030075#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070076#define VS "s"
77#else
78#define VS
79#endif
80
Tomas Winklerdf48c322008-03-06 10:40:19 -080081#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070082
Zhu Yib481de92007-09-25 17:54:57 -070083
84MODULE_DESCRIPTION(DRV_DESCRIPTION);
85MODULE_VERSION(DRV_VERSION);
86MODULE_AUTHOR(DRV_COPYRIGHT);
87MODULE_LICENSE("GPL");
Tomas Winkler4fc22b22008-07-21 18:54:42 +030088MODULE_ALIAS("iwl4965");
Zhu Yib481de92007-09-25 17:54:57 -070089
Zhu Yib481de92007-09-25 17:54:57 -070090/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080091 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -070092 * the functionality provided here
93 */
94
95/**************************************************************/
96
Zhu Yib481de92007-09-25 17:54:57 -070097
Zhu Yib481de92007-09-25 17:54:57 -070098
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -070099static void iwl4965_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt)
100{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800101 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -0700102
103 if (hw_decrypt)
104 rxon->filter_flags &= ~RXON_FILTER_DIS_DECRYPT_MSK;
105 else
106 rxon->filter_flags |= RXON_FILTER_DIS_DECRYPT_MSK;
107
108}
109
Zhu Yib481de92007-09-25 17:54:57 -0700110/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800111 * iwl4965_check_rxon_cmd - validate RXON structure is valid
Zhu Yib481de92007-09-25 17:54:57 -0700112 *
113 * NOTE: This is really only useful during development and can eventually
114 * be #ifdef'd out once the driver is stable and folks aren't actively
115 * making changes
116 */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800117static int iwl4965_check_rxon_cmd(struct iwl_rxon_cmd *rxon)
Zhu Yib481de92007-09-25 17:54:57 -0700118{
119 int error = 0;
120 int counter = 1;
121
122 if (rxon->flags & RXON_FLG_BAND_24G_MSK) {
123 error |= le32_to_cpu(rxon->flags &
124 (RXON_FLG_TGJ_NARROW_BAND_MSK |
125 RXON_FLG_RADAR_DETECT_MSK));
126 if (error)
127 IWL_WARNING("check 24G fields %d | %d\n",
128 counter++, error);
129 } else {
130 error |= (rxon->flags & RXON_FLG_SHORT_SLOT_MSK) ?
131 0 : le32_to_cpu(RXON_FLG_SHORT_SLOT_MSK);
132 if (error)
133 IWL_WARNING("check 52 fields %d | %d\n",
134 counter++, error);
135 error |= le32_to_cpu(rxon->flags & RXON_FLG_CCK_MSK);
136 if (error)
137 IWL_WARNING("check 52 CCK %d | %d\n",
138 counter++, error);
139 }
140 error |= (rxon->node_addr[0] | rxon->bssid_addr[0]) & 0x1;
141 if (error)
142 IWL_WARNING("check mac addr %d | %d\n", counter++, error);
143
144 /* make sure basic rates 6Mbps and 1Mbps are supported */
145 error |= (((rxon->ofdm_basic_rates & IWL_RATE_6M_MASK) == 0) &&
146 ((rxon->cck_basic_rates & IWL_RATE_1M_MASK) == 0));
147 if (error)
148 IWL_WARNING("check basic rate %d | %d\n", counter++, error);
149
150 error |= (le16_to_cpu(rxon->assoc_id) > 2007);
151 if (error)
152 IWL_WARNING("check assoc id %d | %d\n", counter++, error);
153
154 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK))
155 == (RXON_FLG_CCK_MSK | RXON_FLG_SHORT_SLOT_MSK));
156 if (error)
157 IWL_WARNING("check CCK and short slot %d | %d\n",
158 counter++, error);
159
160 error |= ((rxon->flags & (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK))
161 == (RXON_FLG_CCK_MSK | RXON_FLG_AUTO_DETECT_MSK));
162 if (error)
163 IWL_WARNING("check CCK & auto detect %d | %d\n",
164 counter++, error);
165
166 error |= ((rxon->flags & (RXON_FLG_AUTO_DETECT_MSK |
167 RXON_FLG_TGG_PROTECT_MSK)) == RXON_FLG_TGG_PROTECT_MSK);
168 if (error)
169 IWL_WARNING("check TGG and auto detect %d | %d\n",
170 counter++, error);
171
172 if (error)
173 IWL_WARNING("Tuning to channel %d\n",
174 le16_to_cpu(rxon->channel));
175
176 if (error) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800177 IWL_ERROR("Not a valid iwl4965_rxon_assoc_cmd field values\n");
Zhu Yib481de92007-09-25 17:54:57 -0700178 return -1;
179 }
180 return 0;
181}
182
183/**
Mohamed Abbas54559702008-09-03 11:18:44 +0800184 * iwl_full_rxon_required - check if full RXON (vs RXON_ASSOC) cmd is needed
Ian Schram01ebd062007-10-25 17:15:22 +0800185 * @priv: staging_rxon is compared to active_rxon
Zhu Yib481de92007-09-25 17:54:57 -0700186 *
Ben Cahill9fbab512007-11-29 11:09:47 +0800187 * If the RXON structure is changing enough to require a new tune,
188 * or is clearing the RXON_FILTER_ASSOC_MSK, then return 1 to indicate that
189 * a new tune (full RXON command, rather than RXON_ASSOC cmd) is required.
Zhu Yib481de92007-09-25 17:54:57 -0700190 */
Mohamed Abbas54559702008-09-03 11:18:44 +0800191static int iwl_full_rxon_required(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700192{
193
194 /* These items are only settable from the full RXON command */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +0800195 if (!(iwl_is_associated(priv)) ||
Zhu Yib481de92007-09-25 17:54:57 -0700196 compare_ether_addr(priv->staging_rxon.bssid_addr,
197 priv->active_rxon.bssid_addr) ||
198 compare_ether_addr(priv->staging_rxon.node_addr,
199 priv->active_rxon.node_addr) ||
200 compare_ether_addr(priv->staging_rxon.wlap_bssid_addr,
201 priv->active_rxon.wlap_bssid_addr) ||
202 (priv->staging_rxon.dev_type != priv->active_rxon.dev_type) ||
203 (priv->staging_rxon.channel != priv->active_rxon.channel) ||
204 (priv->staging_rxon.air_propagation !=
205 priv->active_rxon.air_propagation) ||
206 (priv->staging_rxon.ofdm_ht_single_stream_basic_rates !=
207 priv->active_rxon.ofdm_ht_single_stream_basic_rates) ||
208 (priv->staging_rxon.ofdm_ht_dual_stream_basic_rates !=
209 priv->active_rxon.ofdm_ht_dual_stream_basic_rates) ||
Zhu Yib481de92007-09-25 17:54:57 -0700210 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
211 return 1;
212
213 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
214 * be updated with the RXON_ASSOC command -- however only some
215 * flag transitions are allowed using RXON_ASSOC */
216
217 /* Check if we are not switching bands */
218 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
219 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
220 return 1;
221
222 /* Check if we are switching association toggle */
223 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
224 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
225 return 1;
226
227 return 0;
228}
229
Zhu Yib481de92007-09-25 17:54:57 -0700230/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800231 * iwl4965_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700232 *
Ian Schram01ebd062007-10-25 17:15:22 +0800233 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700234 * the active_rxon structure is updated with the new data. This
235 * function correctly transitions out of the RXON_ASSOC_MSK state if
236 * a HW tune is required based on the RXON structure changes.
237 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700238static int iwl4965_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700239{
240 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800241 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800242 int ret;
243 bool new_assoc =
244 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700245
Tomas Winklerfee12472008-04-03 16:05:21 -0700246 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800247 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700248
249 /* always get timestamp with Rx frame */
250 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
Emmanuel Grumbacha326a5d2008-07-11 11:53:31 +0800251 /* allow CTS-to-self if possible. this is relevant only for
252 * 5000, but will not damage 4965 */
253 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
Zhu Yib481de92007-09-25 17:54:57 -0700254
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800255 ret = iwl4965_check_rxon_cmd(&priv->staging_rxon);
256 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700257 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
258 return -EINVAL;
259 }
260
261 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800262 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700263 * and other flags for the current radio configuration. */
Mohamed Abbas54559702008-09-03 11:18:44 +0800264 if (!iwl_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800265 ret = iwl_send_rxon_assoc(priv);
266 if (ret) {
267 IWL_ERROR("Error setting RXON_ASSOC (%d)\n", ret);
268 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700269 }
270
271 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700272 return 0;
273 }
274
275 /* station table will be cleared */
276 priv->assoc_station_added = 0;
277
Zhu Yib481de92007-09-25 17:54:57 -0700278 /* If we are currently associated and the new config requires
279 * an RXON_ASSOC and the new config wants the associated mask enabled,
280 * we must clear the associated from the active configuration
281 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800282 if (iwl_is_associated(priv) && new_assoc) {
Zhu Yib481de92007-09-25 17:54:57 -0700283 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
284 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
285
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800286 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800287 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700288 &priv->active_rxon);
289
290 /* If the mask clearing failed then we set
291 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800292 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700293 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800294 IWL_ERROR("Error clearing ASSOC_MSK (%d)\n", ret);
295 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700296 }
Zhu Yib481de92007-09-25 17:54:57 -0700297 }
298
299 IWL_DEBUG_INFO("Sending RXON\n"
300 "* with%s RXON_FILTER_ASSOC_MSK\n"
301 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700302 "* bssid = %pM\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800303 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700304 le16_to_cpu(priv->staging_rxon.channel),
Johannes Berge1749612008-10-27 15:59:26 -0700305 priv->staging_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -0700306
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700307 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800308
309 /* Apply the new configuration
310 * RXON unassoc clears the station table in uCode, send it before
311 * we add the bcast station. If assoc bit is set, we will send RXON
312 * after having added the bcast and bssid station.
313 */
314 if (!new_assoc) {
315 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800316 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800317 if (ret) {
318 IWL_ERROR("Error setting new RXON (%d)\n", ret);
319 return ret;
320 }
321 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700322 }
323
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800324 iwl_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800325
Zhu Yib481de92007-09-25 17:54:57 -0700326 if (!priv->error_recovering)
327 priv->start_calib = 0;
328
Zhu Yib481de92007-09-25 17:54:57 -0700329 /* Add the broadcast address so we can send broadcast frames */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800330 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800331 IWL_INVALID_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700332 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
333 return -EIO;
334 }
335
336 /* If we have set the ASSOC_MSK and we are in BSS mode then
337 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800338 if (new_assoc) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200339 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Tomas Winkler91851592008-06-30 17:23:14 +0800340 ret = iwl_rxon_add_station(priv,
341 priv->active_rxon.bssid_addr, 1);
342 if (ret == IWL_INVALID_STATION) {
343 IWL_ERROR("Error adding AP address for TX.\n");
344 return -EIO;
345 }
346 priv->assoc_station_added = 1;
347 if (priv->default_wep_key &&
348 iwl_send_static_wepkey_cmd(priv, 0))
349 IWL_ERROR("Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700350 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800351
352 /* Apply the new configuration
353 * RXON assoc doesn't clear the station table in uCode,
354 */
355 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
356 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
357 if (ret) {
358 IWL_ERROR("Error setting new RXON (%d)\n", ret);
359 return ret;
360 }
361 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700362 }
363
Zhu Yi36da7d72008-07-11 11:53:40 +0800364 iwl_init_sensitivity(priv);
365
366 /* If we issue a new RXON command which required a tune then we must
367 * send a new TXPOWER command or we won't be able to Tx any frames */
368 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
369 if (ret) {
370 IWL_ERROR("Error sending TX power (%d)\n", ret);
371 return ret;
372 }
373
Zhu Yib481de92007-09-25 17:54:57 -0700374 return 0;
375}
376
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700377void iwl4965_update_chain_flags(struct iwl_priv *priv)
378{
379
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700380 iwl_set_rxon_chain(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700381 iwl4965_commit_rxon(priv);
382}
383
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700384static int iwl4965_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700385{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800386 struct iwl4965_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700387 .flags = 3,
388 .lead_time = 0xAA,
389 .max_kill = 1,
390 .kill_ack_mask = 0,
391 .kill_cts_mask = 0,
392 };
393
Tomas Winkler857485c2008-03-21 13:53:44 -0700394 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800395 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700396}
397
Tomas Winklerfcab4232008-05-15 13:54:01 +0800398static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700399{
400 struct list_head *element;
401
402 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
403 priv->frames_count);
404
405 while (!list_empty(&priv->free_frames)) {
406 element = priv->free_frames.next;
407 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800408 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700409 priv->frames_count--;
410 }
411
412 if (priv->frames_count) {
413 IWL_WARNING("%d frames still in use. Did we lose one?\n",
414 priv->frames_count);
415 priv->frames_count = 0;
416 }
417}
418
Tomas Winklerfcab4232008-05-15 13:54:01 +0800419static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700420{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800421 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700422 struct list_head *element;
423 if (list_empty(&priv->free_frames)) {
424 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
425 if (!frame) {
426 IWL_ERROR("Could not allocate frame!\n");
427 return NULL;
428 }
429
430 priv->frames_count++;
431 return frame;
432 }
433
434 element = priv->free_frames.next;
435 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800436 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700437}
438
Tomas Winklerfcab4232008-05-15 13:54:01 +0800439static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700440{
441 memset(frame, 0, sizeof(*frame));
442 list_add(&frame->list, &priv->free_frames);
443}
444
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800445static unsigned int iwl_fill_beacon_frame(struct iwl_priv *priv,
446 struct ieee80211_hdr *hdr,
447 const u8 *dest, int left)
Zhu Yib481de92007-09-25 17:54:57 -0700448{
Tomas Winkler3109ece2008-03-28 16:33:35 -0700449 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200450 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
451 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700452 return 0;
453
454 if (priv->ibss_beacon->len > left)
455 return 0;
456
457 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
458
459 return priv->ibss_beacon->len;
460}
461
Guy Cohen39e88502008-04-23 17:14:57 -0700462static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700463{
Guy Cohen39e88502008-04-23 17:14:57 -0700464 int i;
465 int rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -0700466
Guy Cohen39e88502008-04-23 17:14:57 -0700467 /* Set rate mask*/
468 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
469 rate_mask = priv->active_rate_basic & 0xF;
470 else
471 rate_mask = priv->active_rate_basic & 0xFF0;
472
473 /* Find lowest valid rate */
Zhu Yib481de92007-09-25 17:54:57 -0700474 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800475 i = iwl_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -0700476 if (rate_mask & (1 << i))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800477 return iwl_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700478 }
479
Guy Cohen39e88502008-04-23 17:14:57 -0700480 /* No valid rate was found. Assign the lowest one */
481 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
482 return IWL_RATE_1M_PLCP;
483 else
484 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -0700485}
486
Emmanuel Grumbacha33c2f42008-09-03 11:26:56 +0800487static unsigned int iwl4965_hw_get_beacon_cmd(struct iwl_priv *priv,
Tomas Winkler4bf64ef2008-07-18 13:53:03 +0800488 struct iwl_frame *frame, u8 rate)
489{
490 struct iwl_tx_beacon_cmd *tx_beacon_cmd;
491 unsigned int frame_size;
492
493 tx_beacon_cmd = &frame->u.beacon;
494 memset(tx_beacon_cmd, 0, sizeof(*tx_beacon_cmd));
495
496 tx_beacon_cmd->tx.sta_id = priv->hw_params.bcast_sta_id;
497 tx_beacon_cmd->tx.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
498
499 frame_size = iwl_fill_beacon_frame(priv, tx_beacon_cmd->frame,
500 iwl_bcast_addr,
501 sizeof(frame->u) - sizeof(*tx_beacon_cmd));
502
503 BUG_ON(frame_size > MAX_MPDU_SIZE);
504 tx_beacon_cmd->tx.len = cpu_to_le16((u16)frame_size);
505
506 if ((rate == IWL_RATE_1M_PLCP) || (rate >= IWL_RATE_2M_PLCP))
507 tx_beacon_cmd->tx.rate_n_flags =
508 iwl_hw_set_rate_n_flags(rate, RATE_MCS_CCK_MSK);
509 else
510 tx_beacon_cmd->tx.rate_n_flags =
511 iwl_hw_set_rate_n_flags(rate, 0);
512
513 tx_beacon_cmd->tx.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK |
514 TX_CMD_FLG_TSF_MSK |
515 TX_CMD_FLG_STA_RATE_MSK;
516
517 return sizeof(*tx_beacon_cmd) + frame_size;
518}
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700519static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700520{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800521 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700522 unsigned int frame_size;
523 int rc;
524 u8 rate;
525
Tomas Winklerfcab4232008-05-15 13:54:01 +0800526 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700527
528 if (!frame) {
529 IWL_ERROR("Could not obtain free frame buffer for beacon "
530 "command.\n");
531 return -ENOMEM;
532 }
533
Guy Cohen39e88502008-04-23 17:14:57 -0700534 rate = iwl4965_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700535
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800536 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700537
Tomas Winkler857485c2008-03-21 13:53:44 -0700538 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700539 &frame->u.cmd[0]);
540
Tomas Winklerfcab4232008-05-15 13:54:01 +0800541 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700542
543 return rc;
544}
545
546/******************************************************************************
547 *
Zhu Yib481de92007-09-25 17:54:57 -0700548 * Misc. internal state and helper functions
549 *
550 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700551
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700552static void iwl4965_ht_conf(struct iwl_priv *priv,
553 struct ieee80211_bss_conf *bss_conf)
554{
555 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
556 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
557 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
558
559 IWL_DEBUG_MAC80211("enter: \n");
560
561 iwl_conf->is_ht = bss_conf->assoc_ht;
562
563 if (!iwl_conf->is_ht)
564 return;
565
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700566 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800567 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700568 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800569 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700570
571 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
572 iwl_conf->max_amsdu_size =
573 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
574
575 iwl_conf->supported_chan_width =
576 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
577 iwl_conf->extension_chan_offset =
578 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
579 /* If no above or below channel supplied disable FAT channel */
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800580 if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE &&
581 iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) {
582 iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700583 iwl_conf->supported_chan_width = 0;
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800584 }
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700585
Ron Rindjunsky12837be2008-09-03 11:26:47 +0800586 iwl_conf->sm_ps = (u8)((ht_conf->cap & IEEE80211_HT_CAP_SM_PS) >> 2);
587
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700588 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
589
590 iwl_conf->control_channel = ht_bss_conf->primary_channel;
591 iwl_conf->tx_chan_width =
592 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
593 iwl_conf->ht_protection =
594 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
595 iwl_conf->non_GF_STA_present =
596 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
597
598 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
599 IWL_DEBUG_MAC80211("leave\n");
600}
601
Zhu Yib481de92007-09-25 17:54:57 -0700602/*
603 * QoS support
604*/
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800605static void iwl_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700606{
Zhu Yib481de92007-09-25 17:54:57 -0700607 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
608 return;
609
610 if (!priv->qos_data.qos_enable)
611 return;
612
Zhu Yib481de92007-09-25 17:54:57 -0700613 priv->qos_data.def_qos_parm.qos_flags = 0;
614
615 if (priv->qos_data.qos_cap.q_AP.queue_request &&
616 !priv->qos_data.qos_cap.q_AP.txop_request)
617 priv->qos_data.def_qos_parm.qos_flags |=
618 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700619 if (priv->qos_data.qos_active)
620 priv->qos_data.def_qos_parm.qos_flags |=
621 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
622
Ron Rindjunskyfd105e72007-11-26 16:14:39 +0200623 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800624 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800625
Tomas Winkler3109ece2008-03-28 16:33:35 -0700626 if (force || iwl_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800627 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
628 priv->qos_data.qos_active,
629 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700630
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +0800631 iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM,
632 sizeof(struct iwl_qosparam_cmd),
633 &priv->qos_data.def_qos_parm, NULL);
Zhu Yib481de92007-09-25 17:54:57 -0700634 }
635}
636
Zhu Yib481de92007-09-25 17:54:57 -0700637#define MAX_UCODE_BEACON_INTERVAL 4096
Zhu Yib481de92007-09-25 17:54:57 -0700638
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800639static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700640{
641 u16 new_val = 0;
642 u16 beacon_factor = 0;
643
644 beacon_factor =
645 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
646 / MAX_UCODE_BEACON_INTERVAL;
647 new_val = beacon_val / beacon_factor;
648
649 return cpu_to_le16(new_val);
650}
651
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700652static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700653{
654 u64 interval_tm_unit;
655 u64 tsf, result;
656 unsigned long flags;
657 struct ieee80211_conf *conf = NULL;
658 u16 beacon_int = 0;
659
660 conf = ieee80211_get_hw_conf(priv->hw);
661
662 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3109ece2008-03-28 16:33:35 -0700663 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
664 priv->rxon_timing.timestamp.dw[0] =
665 cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -0700666
Tomas Winklerb5d7be52008-07-19 04:41:24 +0300667 priv->rxon_timing.listen_interval = cpu_to_le16(conf->listen_interval);
Zhu Yib481de92007-09-25 17:54:57 -0700668
Tomas Winkler3109ece2008-03-28 16:33:35 -0700669 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700670
671 beacon_int = priv->beacon_int;
672 spin_unlock_irqrestore(&priv->lock, flags);
673
Johannes Berg05c914f2008-09-11 00:01:58 +0200674 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700675 if (beacon_int == 0) {
676 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
677 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
678 } else {
679 priv->rxon_timing.beacon_interval =
680 cpu_to_le16(beacon_int);
681 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800682 iwl4965_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700683 le16_to_cpu(priv->rxon_timing.beacon_interval));
684 }
685
686 priv->rxon_timing.atim_window = 0;
687 } else {
688 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800689 iwl4965_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700690 /* TODO: we need to get atim_window from upper stack
691 * for now we set to 0 */
692 priv->rxon_timing.atim_window = 0;
693 }
694
695 interval_tm_unit =
696 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
697 result = do_div(tsf, interval_tm_unit);
698 priv->rxon_timing.beacon_init_val =
699 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
700
701 IWL_DEBUG_ASSOC
702 ("beacon interval %d beacon timer %d beacon tim %d\n",
703 le16_to_cpu(priv->rxon_timing.beacon_interval),
704 le32_to_cpu(priv->rxon_timing.beacon_init_val),
705 le16_to_cpu(priv->rxon_timing.atim_window));
706}
707
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800708static void iwl_set_flags_for_band(struct iwl_priv *priv,
709 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -0700710{
Johannes Berg8318d782008-01-24 19:38:38 +0100711 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -0700712 priv->staging_rxon.flags &=
713 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
714 | RXON_FLG_CCK_MSK);
715 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
716 } else {
Reinette Chatre508e32e2008-04-14 21:16:13 -0700717 /* Copied from iwl4965_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -0700718 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
719 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
720 else
721 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
722
Johannes Berg05c914f2008-09-11 00:01:58 +0200723 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -0700724 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
725
726 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
727 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
728 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
729 }
730}
731
732/*
Ian Schram01ebd062007-10-25 17:15:22 +0800733 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -0700734 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700735static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700736{
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700737 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700738
739 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
740
741 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +0200742 case NL80211_IFTYPE_AP:
Zhu Yib481de92007-09-25 17:54:57 -0700743 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
744 break;
745
Johannes Berg05c914f2008-09-11 00:01:58 +0200746 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700747 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
748 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
749 break;
750
Johannes Berg05c914f2008-09-11 00:01:58 +0200751 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -0700752 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
753 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
754 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
755 RXON_FILTER_ACCEPT_GRP_MSK;
756 break;
757
Johannes Berg05c914f2008-09-11 00:01:58 +0200758 case NL80211_IFTYPE_MONITOR:
Zhu Yib481de92007-09-25 17:54:57 -0700759 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
760 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
761 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
762 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700763 default:
764 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
765 break;
Zhu Yib481de92007-09-25 17:54:57 -0700766 }
767
768#if 0
769 /* TODO: Figure out when short_preamble would be set and cache from
770 * that */
771 if (!hw_to_local(priv->hw)->short_preamble)
772 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
773 else
774 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
775#endif
776
Assaf Krauss8622e702008-03-21 13:53:43 -0700777 ch_info = iwl_get_channel_info(priv, priv->band,
Rick Farrington25b3f572008-06-30 17:23:28 +0800778 le16_to_cpu(priv->active_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700779
780 if (!ch_info)
781 ch_info = &priv->channel_info[0];
782
783 /*
784 * in some case A channels are all non IBSS
785 * in this case force B/G channel
786 */
Johannes Berg05c914f2008-09-11 00:01:58 +0200787 if ((priv->iw_mode == NL80211_IFTYPE_ADHOC) &&
Zhu Yib481de92007-09-25 17:54:57 -0700788 !(is_channel_ibss(ch_info)))
789 ch_info = &priv->channel_info[0];
790
791 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100792 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -0700793
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800794 iwl_set_flags_for_band(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -0700795
796 priv->staging_rxon.ofdm_basic_rates =
797 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
798 priv->staging_rxon.cck_basic_rates =
799 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
800
801 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
802 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
803 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
804 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
805 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
806 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700807 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700808}
809
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700810static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700811{
Zhu Yib481de92007-09-25 17:54:57 -0700812 priv->iw_mode = mode;
813
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800814 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700815 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
816
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800817 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700818
Mohamed Abbasfde35712007-11-29 11:10:15 +0800819 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -0700820 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800821 return -EAGAIN;
822
823 cancel_delayed_work(&priv->scan_check);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800824 if (iwl_scan_cancel_timeout(priv, 100)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +0800825 IWL_WARNING("Aborted scan still in progress after 100ms\n");
826 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
827 return -EAGAIN;
828 }
829
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800830 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700831
832 return 0;
833}
834
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700835static void iwl4965_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700836{
Johannes Berg8318d782008-01-24 19:38:38 +0100837 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700838 struct ieee80211_rate *rate;
839 int i;
840
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700841 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800842 if (!hw) {
843 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
844 return;
845 }
Zhu Yib481de92007-09-25 17:54:57 -0700846
847 priv->active_rate = 0;
848 priv->active_rate_basic = 0;
849
Johannes Berg8318d782008-01-24 19:38:38 +0100850 for (i = 0; i < hw->n_bitrates; i++) {
851 rate = &(hw->bitrates[i]);
852 if (rate->hw_value < IWL_RATE_COUNT)
853 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -0700854 }
855
856 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
857 priv->active_rate, priv->active_rate_basic);
858
859 /*
860 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
861 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
862 * OFDM
863 */
864 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
865 priv->staging_rxon.cck_basic_rates =
866 ((priv->active_rate_basic &
867 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
868 else
869 priv->staging_rxon.cck_basic_rates =
870 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
871
872 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
873 priv->staging_rxon.ofdm_basic_rates =
874 ((priv->active_rate_basic &
875 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
876 IWL_FIRST_OFDM_RATE) & 0xFF;
877 else
878 priv->staging_rxon.ofdm_basic_rates =
879 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
880}
881
Tomas Winkler4fc22b22008-07-21 18:54:42 +0300882#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -0700883
884#include "iwl-spectrum.h"
885
886#define BEACON_TIME_MASK_LOW 0x00FFFFFF
887#define BEACON_TIME_MASK_HIGH 0xFF000000
888#define TIME_UNIT 1024
889
890/*
891 * extended beacon time format
892 * time in usec will be changed into a 32-bit value in 8:24 format
893 * the high 1 byte is the beacon counts
894 * the lower 3 bytes is the time in usec within one beacon interval
895 */
896
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800897static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700898{
899 u32 quot;
900 u32 rem;
901 u32 interval = beacon_interval * 1024;
902
903 if (!interval || !usec)
904 return 0;
905
906 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
907 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
908
909 return (quot << 24) + rem;
910}
911
912/* base is usually what we get from ucode with each received frame,
913 * the same as HW timer counter counting down
914 */
915
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800916static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700917{
918 u32 base_low = base & BEACON_TIME_MASK_LOW;
919 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
920 u32 interval = beacon_interval * TIME_UNIT;
921 u32 res = (base & BEACON_TIME_MASK_HIGH) +
922 (addon & BEACON_TIME_MASK_HIGH);
923
924 if (base_low > addon_low)
925 res += base_low - addon_low;
926 else if (base_low < addon_low) {
927 res += interval + base_low - addon_low;
928 res += (1 << 24);
929 } else
930 res += (1 << 24);
931
932 return cpu_to_le32(res);
933}
934
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700935static int iwl4965_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700936 struct ieee80211_measurement_params *params,
937 u8 type)
938{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800939 struct iwl4965_spectrum_cmd spectrum;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800940 struct iwl_rx_packet *res;
Tomas Winkler857485c2008-03-21 13:53:44 -0700941 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700942 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
943 .data = (void *)&spectrum,
944 .meta.flags = CMD_WANT_SKB,
945 };
946 u32 add_time = le64_to_cpu(params->start_time);
947 int rc;
948 int spectrum_resp_status;
949 int duration = le16_to_cpu(params->duration);
950
Tomas Winkler3109ece2008-03-28 16:33:35 -0700951 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700952 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800953 iwl4965_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -0700954 le64_to_cpu(params->start_time) - priv->last_tsf,
955 le16_to_cpu(priv->rxon_timing.beacon_interval));
956
957 memset(&spectrum, 0, sizeof(spectrum));
958
959 spectrum.channel_count = cpu_to_le16(1);
960 spectrum.flags =
961 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
962 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
963 cmd.len = sizeof(spectrum);
964 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
965
Tomas Winkler3109ece2008-03-28 16:33:35 -0700966 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700967 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800968 iwl4965_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -0700969 add_time,
970 le16_to_cpu(priv->rxon_timing.beacon_interval));
971 else
972 spectrum.start_time = 0;
973
974 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
975 spectrum.channels[0].channel = params->channel;
976 spectrum.channels[0].type = type;
977 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
978 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
979 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
980
Tomas Winkler857485c2008-03-21 13:53:44 -0700981 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700982 if (rc)
983 return rc;
984
Tomas Winklerdb11d632008-05-05 10:22:33 +0800985 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700986 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
987 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
988 rc = -EIO;
989 }
990
991 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
992 switch (spectrum_resp_status) {
993 case 0: /* Command will be handled */
994 if (res->u.spectrum.id != 0xff) {
995 IWL_DEBUG_INFO
996 ("Replaced existing measurement: %d\n",
997 res->u.spectrum.id);
998 priv->measurement_status &= ~MEASUREMENT_READY;
999 }
1000 priv->measurement_status |= MEASUREMENT_ACTIVE;
1001 rc = 0;
1002 break;
1003
1004 case 1: /* Command will not be handled */
1005 rc = -EAGAIN;
1006 break;
1007 }
1008
1009 dev_kfree_skb_any(cmd.meta.u.skb);
1010
1011 return rc;
1012}
1013#endif
1014
Zhu Yib481de92007-09-25 17:54:57 -07001015/******************************************************************************
1016 *
1017 * Generic RX handler implementations
1018 *
1019 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +08001020static void iwl_rx_reply_alive(struct iwl_priv *priv,
1021 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001022{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001023 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +08001024 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001025 struct delayed_work *pwork;
1026
1027 palive = &pkt->u.alive_frame;
1028
1029 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1030 "0x%01X 0x%01X\n",
1031 palive->is_valid, palive->ver_type,
1032 palive->ver_subtype);
1033
1034 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1035 IWL_DEBUG_INFO("Initialization Alive received.\n");
1036 memcpy(&priv->card_alive_init,
1037 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001038 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001039 pwork = &priv->init_alive_start;
1040 } else {
1041 IWL_DEBUG_INFO("Runtime Alive received.\n");
1042 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001043 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001044 pwork = &priv->alive_start;
1045 }
1046
1047 /* We delay the ALIVE response by 5ms to
1048 * give the HW RF Kill time to activate... */
1049 if (palive->is_valid == UCODE_VALID_OK)
1050 queue_delayed_work(priv->workqueue, pwork,
1051 msecs_to_jiffies(5));
1052 else
1053 IWL_WARNING("uCode did not respond OK.\n");
1054}
1055
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001056static void iwl4965_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001057 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001058{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001059 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001060
1061 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1062 "seq 0x%04X ser 0x%08X\n",
1063 le32_to_cpu(pkt->u.err_resp.error_type),
1064 get_cmd_string(pkt->u.err_resp.cmd_id),
1065 pkt->u.err_resp.cmd_id,
1066 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1067 le32_to_cpu(pkt->u.err_resp.error_info));
1068}
1069
1070#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1071
Tomas Winklera55360e2008-05-05 10:22:28 +08001072static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001073{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001074 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001075 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001076 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001077 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1078 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1079 rxon->channel = csa->channel;
1080 priv->staging_rxon.channel = csa->channel;
1081}
1082
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001083static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001084 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001085{
Tomas Winkler4fc22b22008-07-21 18:54:42 +03001086#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
Tomas Winklerdb11d632008-05-05 10:22:33 +08001087 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001088 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001089
1090 if (!report->state) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001091 IWL_DEBUG(IWL_DL_11H,
1092 "Spectrum Measure Notification: Start\n");
Zhu Yib481de92007-09-25 17:54:57 -07001093 return;
1094 }
1095
1096 memcpy(&priv->measure_report, report, sizeof(*report));
1097 priv->measurement_status |= MEASUREMENT_READY;
1098#endif
1099}
1100
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001101static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001102 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001103{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001104#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001105 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001106 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001107 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1108 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1109#endif
1110}
1111
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001112static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001113 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001114{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001115 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001116 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1117 "notification for %s:\n",
1118 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001119 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001120}
1121
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001122static void iwl4965_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001123{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001124 struct iwl_priv *priv =
1125 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001126 struct sk_buff *beacon;
1127
1128 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001129 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001130
1131 if (!beacon) {
1132 IWL_ERROR("update beacon failed\n");
1133 return;
1134 }
1135
1136 mutex_lock(&priv->mutex);
1137 /* new beacon skb is allocated every time; dispose previous.*/
1138 if (priv->ibss_beacon)
1139 dev_kfree_skb(priv->ibss_beacon);
1140
1141 priv->ibss_beacon = beacon;
1142 mutex_unlock(&priv->mutex);
1143
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001144 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001145}
1146
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001147/**
1148 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
1149 *
1150 * This callback is provided in order to send a statistics request.
1151 *
1152 * This timer function is continually reset to execute within
1153 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1154 * was received. We need to ensure we receive the statistics in order
1155 * to update the temperature used for calibrating the TXPOWER.
1156 */
1157static void iwl4965_bg_statistics_periodic(unsigned long data)
1158{
1159 struct iwl_priv *priv = (struct iwl_priv *)data;
1160
1161 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1162 return;
1163
1164 iwl_send_statistics_request(priv, CMD_ASYNC);
1165}
1166
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001167static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001168 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001169{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001170#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001171 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001172 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
Tomas Winklere7d326a2008-06-12 09:47:11 +08001173 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001174
1175 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1176 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +08001177 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -07001178 beacon->beacon_notify_hdr.failure_frame,
1179 le32_to_cpu(beacon->ibss_mgr_status),
1180 le32_to_cpu(beacon->high_tsf),
1181 le32_to_cpu(beacon->low_tsf), rate);
1182#endif
1183
Johannes Berg05c914f2008-09-11 00:01:58 +02001184 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001185 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1186 queue_work(priv->workqueue, &priv->beacon_update);
1187}
1188
Zhu Yib481de92007-09-25 17:54:57 -07001189/* Handle notification from uCode that card's power state is changing
1190 * due to software, hardware, or critical temperature RFKILL */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001191static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001192 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001193{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001194 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001195 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1196 unsigned long status = priv->status;
1197
1198 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1199 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1200 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1201
1202 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1203 RF_CARD_DISABLED)) {
1204
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001205 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001206 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1207
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001208 if (!iwl_grab_nic_access(priv)) {
1209 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001210 priv, HBUS_TARG_MBX_C,
1211 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1212
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001213 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001214 }
1215
1216 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001217 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001218 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001219 if (!iwl_grab_nic_access(priv)) {
1220 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001221 priv, HBUS_TARG_MBX_C,
1222 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1223
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001224 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001225 }
1226 }
1227
1228 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001229 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001230 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001231 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1232 if (!iwl_grab_nic_access(priv))
1233 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001234 }
1235 }
1236
1237 if (flags & HW_CARD_DISABLED)
1238 set_bit(STATUS_RF_KILL_HW, &priv->status);
1239 else
1240 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1241
1242
1243 if (flags & SW_CARD_DISABLED)
1244 set_bit(STATUS_RF_KILL_SW, &priv->status);
1245 else
1246 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1247
1248 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +08001249 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001250
1251 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1252 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1253 (test_bit(STATUS_RF_KILL_SW, &status) !=
1254 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1255 queue_work(priv->workqueue, &priv->rf_kill);
1256 else
1257 wake_up_interruptible(&priv->wait_command_queue);
1258}
1259
Tomas Winklere2e3c572008-07-18 13:53:04 +08001260int iwl4965_set_pwr_src(struct iwl_priv *priv, enum iwl_pwr_src src)
1261{
1262 int ret;
1263 unsigned long flags;
1264
1265 spin_lock_irqsave(&priv->lock, flags);
1266 ret = iwl_grab_nic_access(priv);
1267 if (ret)
1268 goto err;
1269
1270 if (src == IWL_PWR_SRC_VAUX) {
1271 u32 val;
Tomas Winklere7b63582008-09-03 11:26:49 +08001272 ret = pci_read_config_dword(priv->pci_dev, PCI_CFG_POWER_SOURCE,
Tomas Winklere2e3c572008-07-18 13:53:04 +08001273 &val);
1274
1275 if (val & PCI_CFG_PMC_PME_FROM_D3COLD_SUPPORT)
1276 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1277 APMG_PS_CTRL_VAL_PWR_SRC_VAUX,
1278 ~APMG_PS_CTRL_MSK_PWR_SRC);
1279 } else {
1280 iwl_set_bits_mask_prph(priv, APMG_PS_CTRL_REG,
1281 APMG_PS_CTRL_VAL_PWR_SRC_VMAIN,
1282 ~APMG_PS_CTRL_MSK_PWR_SRC);
1283 }
1284
1285 iwl_release_nic_access(priv);
1286err:
1287 spin_unlock_irqrestore(&priv->lock, flags);
1288 return ret;
1289}
1290
Zhu Yib481de92007-09-25 17:54:57 -07001291/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001292 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001293 *
1294 * Setup the RX handlers for each of the reply types sent from the uCode
1295 * to the host.
1296 *
1297 * This function chains into the hardware specific files for them to setup
1298 * any hardware specific handlers as well.
1299 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001300static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001301{
Tomas Winkler885ba202008-05-29 16:34:55 +08001302 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001303 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
1304 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07001305 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001306 iwl4965_rx_spectrum_measure_notif;
1307 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001308 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001309 iwl4965_rx_pm_debug_statistics_notif;
1310 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001311
Ben Cahill9fbab512007-11-29 11:09:47 +08001312 /*
1313 * The same handler is used for both the REPLY to a discrete
1314 * statistics request from the host as well as for the periodic
1315 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001316 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001317 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1318 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +08001319
1320 iwl_setup_rx_scan_handlers(priv);
1321
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001322 /* status change handler */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001323 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001324
Tomas Winklerc1354752008-05-29 16:35:04 +08001325 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1326 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001327 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +08001328 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1329 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001330 /* block ack */
1331 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001332 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001333 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001334}
1335
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001336/*
1337 * this should be called while priv->lock is locked
1338*/
Tomas Winklera55360e2008-05-05 10:22:28 +08001339static void __iwl_rx_replenish(struct iwl_priv *priv)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001340{
Tomas Winklera55360e2008-05-05 10:22:28 +08001341 iwl_rx_allocate(priv);
1342 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001343}
1344
1345
Zhu Yib481de92007-09-25 17:54:57 -07001346/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001347 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001348 *
1349 * Uses the priv->rx_handlers callback function array to invoke
1350 * the appropriate handlers, including command responses,
1351 * frame-received notifications, and other notifications.
1352 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001353void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001354{
Tomas Winklera55360e2008-05-05 10:22:28 +08001355 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001356 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001357 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001358 u32 r, i;
1359 int reclaim;
1360 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001361 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001362 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001363
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001364 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1365 * buffer that the driver may process (last buffer filled by ucode). */
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001366 r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001367 i = rxq->read;
1368
1369 /* Rx interrupt, but nothing sent from uCode */
1370 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08001371 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001372
Tomas Winklera55360e2008-05-05 10:22:28 +08001373 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001374 fill_rx = 1;
1375
Zhu Yib481de92007-09-25 17:54:57 -07001376 while (i != r) {
1377 rxb = rxq->queue[i];
1378
Ben Cahill9fbab512007-11-29 11:09:47 +08001379 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001380 * then a bug has been introduced in the queue refilling
1381 * routines -- catch it here */
1382 BUG_ON(rxb == NULL);
1383
1384 rxq->queue[i] = NULL;
1385
1386 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07001387 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001388 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08001389 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001390
1391 /* Reclaim a command buffer only if this packet is a response
1392 * to a (driver-originated) command.
1393 * If the packet (e.g. Rx frame) originated from uCode,
1394 * there is no command buffer to reclaim.
1395 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1396 * but apparently a few don't get set; catch them here. */
1397 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1398 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001399 (pkt->hdr.cmd != REPLY_RX) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001400 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001401 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1402 (pkt->hdr.cmd != REPLY_TX);
1403
1404 /* Based on type of command response or notification,
1405 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001406 * rx_handlers table. See iwl4965_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001407 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001408 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1409 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001410 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1411 } else {
1412 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08001413 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07001414 "r %d i %d No handler needed for %s, 0x%02x\n",
1415 r, i, get_cmd_string(pkt->hdr.cmd),
1416 pkt->hdr.cmd);
1417 }
1418
1419 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001420 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07001421 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001422 * as we reclaim the driver command queue */
1423 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +08001424 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001425 else
1426 IWL_WARNING("Claim null rxb?\n");
1427 }
1428
1429 /* For now we just don't re-use anything. We can tweak this
1430 * later to try and re-use notification packets and SKBs that
1431 * fail to Rx correctly */
1432 if (rxb->skb != NULL) {
1433 priv->alloc_rxb_skb--;
1434 dev_kfree_skb_any(rxb->skb);
1435 rxb->skb = NULL;
1436 }
1437
1438 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07001439 priv->hw_params.rx_buf_size,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001440 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001441 spin_lock_irqsave(&rxq->lock, flags);
1442 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1443 spin_unlock_irqrestore(&rxq->lock, flags);
1444 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001445 /* If there are a lot of unused frames,
1446 * restock the Rx queue so ucode wont assert. */
1447 if (fill_rx) {
1448 count++;
1449 if (count >= 8) {
1450 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001451 __iwl_rx_replenish(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001452 count = 0;
1453 }
1454 }
Zhu Yib481de92007-09-25 17:54:57 -07001455 }
1456
1457 /* Backtrack one entry */
1458 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001459 iwl_rx_queue_restock(priv);
1460}
Tomas Winklera55360e2008-05-05 10:22:28 +08001461
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001462#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001463static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001464{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001465 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001466
Zhu Yib481de92007-09-25 17:54:57 -07001467 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08001468 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001469 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1470 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1471 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1472 le32_to_cpu(rxon->filter_flags));
1473 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1474 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1475 rxon->ofdm_basic_rates);
1476 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Johannes Berge1749612008-10-27 15:59:26 -07001477 IWL_DEBUG_RADIO("u8[6] node_addr: %pM\n", rxon->node_addr);
1478 IWL_DEBUG_RADIO("u8[6] bssid_addr: %pM\n", rxon->bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001479 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1480}
1481#endif
1482
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001483static void iwl4965_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001484{
1485 IWL_DEBUG_ISR("Enabling interrupts\n");
1486 set_bit(STATUS_INT_ENABLED, &priv->status);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001487 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001488}
1489
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001490/* call this function to flush any scheduled tasklet */
1491static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1492{
1493 /* wait to make sure we flush pedding tasklet*/
1494 synchronize_irq(priv->pci_dev->irq);
1495 tasklet_kill(&priv->irq_tasklet);
1496}
1497
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001498static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001499{
1500 clear_bit(STATUS_INT_ENABLED, &priv->status);
1501
1502 /* disable interrupts from uCode/NIC to host */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001503 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001504
1505 /* acknowledge/clear/reset any interrupts still pending
1506 * from uCode or flow handler (Rx/Tx DMA) */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001507 iwl_write32(priv, CSR_INT, 0xffffffff);
1508 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07001509 IWL_DEBUG_ISR("Disabled interrupts\n");
1510}
1511
Zhu Yib481de92007-09-25 17:54:57 -07001512
Zhu Yib481de92007-09-25 17:54:57 -07001513/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001514 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07001515 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001516static void iwl4965_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001517{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001518 /* Set the FW error flag -- cleared on iwl4965_down */
Zhu Yib481de92007-09-25 17:54:57 -07001519 set_bit(STATUS_FW_ERROR, &priv->status);
1520
1521 /* Cancel currently queued command. */
1522 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1523
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001524#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001525 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08001526 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08001527 iwl_dump_nic_event_log(priv);
Ester Kummerbf403db2008-05-05 10:22:40 +08001528 iwl4965_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001529 }
1530#endif
1531
1532 wake_up_interruptible(&priv->wait_command_queue);
1533
1534 /* Keep the restart process from trying to send host
1535 * commands by clearing the INIT status bit */
1536 clear_bit(STATUS_READY, &priv->status);
1537
1538 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001539 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07001540 "Restarting adapter due to uCode error.\n");
1541
Tomas Winkler3109ece2008-03-28 16:33:35 -07001542 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001543 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1544 sizeof(priv->recovery_rxon));
1545 priv->error_recovering = 1;
1546 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08001547 if (priv->cfg->mod_params->restart_fw)
1548 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001549 }
1550}
1551
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001552static void iwl4965_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001553{
1554 unsigned long flags;
1555
1556 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1557 sizeof(priv->staging_rxon));
1558 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001559 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001560
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001561 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07001562
1563 spin_lock_irqsave(&priv->lock, flags);
1564 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1565 priv->error_recovering = 0;
1566 spin_unlock_irqrestore(&priv->lock, flags);
1567}
1568
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001569static void iwl4965_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001570{
1571 u32 inta, handled = 0;
1572 u32 inta_fh;
1573 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001574#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001575 u32 inta_mask;
1576#endif
1577
1578 spin_lock_irqsave(&priv->lock, flags);
1579
1580 /* Ack/clear/reset pending uCode interrupts.
1581 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1582 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001583 inta = iwl_read32(priv, CSR_INT);
1584 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001585
1586 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1587 * Any new interrupts that happen after this, either while we're
1588 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001589 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1590 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001591
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001592#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001593 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001594 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001595 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001596 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1597 inta, inta_mask, inta_fh);
1598 }
1599#endif
1600
1601 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1602 * atomic, make sure that inta covers all the interrupts that
1603 * we've discovered, even if FH interrupt came in just after
1604 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001605 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001606 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001607 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001608 inta |= CSR_INT_BIT_FH_TX;
1609
1610 /* Now service all interrupt bits discovered above. */
1611 if (inta & CSR_INT_BIT_HW_ERR) {
1612 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1613
1614 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001615 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001616
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001617 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001618
1619 handled |= CSR_INT_BIT_HW_ERR;
1620
1621 spin_unlock_irqrestore(&priv->lock, flags);
1622
1623 return;
1624 }
1625
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001626#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001627 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001628 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001629 if (inta & CSR_INT_BIT_SCD)
1630 IWL_DEBUG_ISR("Scheduler finished to transmit "
1631 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001632
1633 /* Alive notification via Rx interrupt will do the real work */
1634 if (inta & CSR_INT_BIT_ALIVE)
1635 IWL_DEBUG_ISR("Alive interrupt\n");
1636 }
1637#endif
1638 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001639 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001640
Ben Cahill9fbab512007-11-29 11:09:47 +08001641 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001642 if (inta & CSR_INT_BIT_RF_KILL) {
1643 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001644 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001645 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1646 hw_rf_kill = 1;
1647
Ester Kummerf3d67992008-05-06 11:05:12 +08001648 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Zhu Yib481de92007-09-25 17:54:57 -07001649 hw_rf_kill ? "disable radio":"enable radio");
1650
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001651 /* driver only loads ucode once setting the interface up.
1652 * the driver as well won't allow loading if RFKILL is set
1653 * therefore no need to restart the driver from this handler
1654 */
1655 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status))
Zhu Yi53e49092007-12-06 16:08:44 +08001656 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001657
1658 handled |= CSR_INT_BIT_RF_KILL;
1659 }
1660
Ben Cahill9fbab512007-11-29 11:09:47 +08001661 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001662 if (inta & CSR_INT_BIT_CT_KILL) {
1663 IWL_ERROR("Microcode CT kill error detected.\n");
1664 handled |= CSR_INT_BIT_CT_KILL;
1665 }
1666
1667 /* Error detected by uCode */
1668 if (inta & CSR_INT_BIT_SW_ERR) {
1669 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1670 inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001671 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001672 handled |= CSR_INT_BIT_SW_ERR;
1673 }
1674
1675 /* uCode wakes up after power-down sleep */
1676 if (inta & CSR_INT_BIT_WAKEUP) {
1677 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001678 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001679 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1680 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1681 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1682 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1683 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1684 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001685
1686 handled |= CSR_INT_BIT_WAKEUP;
1687 }
1688
1689 /* All uCode command responses, including Tx command responses,
1690 * Rx "responses" (frame-received notification), and other
1691 * notifications from uCode come through here*/
1692 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001693 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001694 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1695 }
1696
1697 if (inta & CSR_INT_BIT_FH_TX) {
1698 IWL_DEBUG_ISR("Tx interrupt\n");
1699 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001700 /* FH finished to write, send event */
1701 priv->ucode_write_complete = 1;
1702 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001703 }
1704
1705 if (inta & ~handled)
1706 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1707
1708 if (inta & ~CSR_INI_SET_MASK) {
1709 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
1710 inta & ~CSR_INI_SET_MASK);
1711 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
1712 }
1713
1714 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001715 /* only Re-enable if diabled by irq */
1716 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1717 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001718
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001719#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001720 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001721 inta = iwl_read32(priv, CSR_INT);
1722 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1723 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001724 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1725 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1726 }
1727#endif
1728 spin_unlock_irqrestore(&priv->lock, flags);
1729}
1730
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001731static irqreturn_t iwl4965_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07001732{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001733 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07001734 u32 inta, inta_mask;
1735 u32 inta_fh;
1736 if (!priv)
1737 return IRQ_NONE;
1738
1739 spin_lock(&priv->lock);
1740
1741 /* Disable (but don't clear!) interrupts here to avoid
1742 * back-to-back ISRs and sporadic interrupts from our NIC.
1743 * If we have something to service, the tasklet will re-enable ints.
1744 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001745 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1746 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001747
1748 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001749 inta = iwl_read32(priv, CSR_INT);
1750 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001751
1752 /* Ignore interrupt if there's nothing in NIC to service.
1753 * This may be due to IRQ shared with another device,
1754 * or due to sporadic interrupts thrown from our NIC. */
1755 if (!inta && !inta_fh) {
1756 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1757 goto none;
1758 }
1759
1760 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08001761 /* Hardware disappeared. It might have already raised
1762 * an interrupt */
Zhu Yib481de92007-09-25 17:54:57 -07001763 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08001764 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07001765 }
1766
1767 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1768 inta, inta_mask, inta_fh);
1769
Joonwoo Park25c03d82008-01-23 10:15:20 -08001770 inta &= ~CSR_INT_BIT_SCD;
1771
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001772 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001773 if (likely(inta || inta_fh))
1774 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07001775
Oliver Neukum66fbb542007-11-15 09:31:10 +08001776 unplugged:
1777 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07001778 return IRQ_HANDLED;
1779
1780 none:
1781 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001782 /* only Re-enable if diabled by irq */
1783 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1784 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001785 spin_unlock(&priv->lock);
1786 return IRQ_NONE;
1787}
1788
Zhu Yib481de92007-09-25 17:54:57 -07001789/******************************************************************************
1790 *
1791 * uCode download functions
1792 *
1793 ******************************************************************************/
1794
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001795static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001796{
Tomas Winkler98c92212008-01-14 17:46:20 -08001797 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1798 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1799 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1800 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1801 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1802 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001803}
1804
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001805static void iwl4965_nic_start(struct iwl_priv *priv)
1806{
1807 /* Remove all resets to allow NIC to operate */
1808 iwl_write32(priv, CSR_RESET, 0);
1809}
1810
1811
Zhu Yib481de92007-09-25 17:54:57 -07001812/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001813 * iwl4965_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001814 *
1815 * Copy into buffers for card to fetch via bus-mastering
1816 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001817static int iwl4965_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001818{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001819 struct iwl_ucode *ucode;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001820 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001821 const struct firmware *ucode_raw;
Tomas Winkler4bf775c2008-03-04 18:09:31 -08001822 const char *name = priv->cfg->fw_name;
Zhu Yib481de92007-09-25 17:54:57 -07001823 u8 *src;
1824 size_t len;
1825 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
1826
1827 /* Ask kernel firmware_class module to get the boot firmware off disk.
1828 * request_firmware() is synchronous, file is in memory on return. */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001829 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
1830 if (ret < 0) {
1831 IWL_ERROR("%s firmware file req failed: Reason %d\n",
1832 name, ret);
Zhu Yib481de92007-09-25 17:54:57 -07001833 goto error;
1834 }
1835
1836 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1837 name, ucode_raw->size);
1838
1839 /* Make sure that we got at least our header! */
1840 if (ucode_raw->size < sizeof(*ucode)) {
1841 IWL_ERROR("File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001842 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001843 goto err_release;
1844 }
1845
1846 /* Data from ucode file: header followed by uCode images */
1847 ucode = (void *)ucode_raw->data;
1848
1849 ver = le32_to_cpu(ucode->ver);
1850 inst_size = le32_to_cpu(ucode->inst_size);
1851 data_size = le32_to_cpu(ucode->data_size);
1852 init_size = le32_to_cpu(ucode->init_size);
1853 init_data_size = le32_to_cpu(ucode->init_data_size);
1854 boot_size = le32_to_cpu(ucode->boot_size);
1855
1856 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
1857 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1858 inst_size);
1859 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1860 data_size);
1861 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1862 init_size);
1863 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1864 init_data_size);
1865 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1866 boot_size);
1867
1868 /* Verify size of file vs. image size info in file's header */
1869 if (ucode_raw->size < sizeof(*ucode) +
1870 inst_size + data_size + init_size +
1871 init_data_size + boot_size) {
1872
1873 IWL_DEBUG_INFO("uCode file size %d too small\n",
1874 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001875 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001876 goto err_release;
1877 }
1878
1879 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001880 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001881 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1882 inst_size);
1883 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001884 goto err_release;
1885 }
1886
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001887 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001888 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1889 data_size);
1890 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001891 goto err_release;
1892 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001893 if (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001894 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001895 ("uCode init instr len %d too large to fit in\n",
1896 init_size);
1897 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001898 goto err_release;
1899 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001900 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001901 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001902 ("uCode init data len %d too large to fit in\n",
1903 init_data_size);
1904 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001905 goto err_release;
1906 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001907 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001908 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001909 ("uCode boot instr len %d too large to fit in\n",
1910 boot_size);
1911 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001912 goto err_release;
1913 }
1914
1915 /* Allocate ucode buffers for card's bus-master loading ... */
1916
1917 /* Runtime instructions and 2 copies of data:
1918 * 1) unmodified from disk
1919 * 2) backup cache for save/restore during power-downs */
1920 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001921 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001922
1923 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001924 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001925
1926 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001927 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001928
1929 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001930 if (init_size && init_data_size) {
1931 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001932 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001933
Tomas Winkler90e759d2007-11-29 11:09:41 +08001934 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001935 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001936
1937 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1938 goto err_pci_alloc;
1939 }
Zhu Yib481de92007-09-25 17:54:57 -07001940
1941 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001942 if (boot_size) {
1943 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001944 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001945
Tomas Winkler90e759d2007-11-29 11:09:41 +08001946 if (!priv->ucode_boot.v_addr)
1947 goto err_pci_alloc;
1948 }
Zhu Yib481de92007-09-25 17:54:57 -07001949
1950 /* Copy images into buffers for card's bus-master reads ... */
1951
1952 /* Runtime instructions (first block of data in file) */
1953 src = &ucode->data[0];
1954 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001955 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001956 memcpy(priv->ucode_code.v_addr, src, len);
1957 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1958 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1959
1960 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001961 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001962 src = &ucode->data[inst_size];
1963 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001964 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001965 memcpy(priv->ucode_data.v_addr, src, len);
1966 memcpy(priv->ucode_data_backup.v_addr, src, len);
1967
1968 /* Initialization instructions (3rd block) */
1969 if (init_size) {
1970 src = &ucode->data[inst_size + data_size];
1971 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001972 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1973 len);
Zhu Yib481de92007-09-25 17:54:57 -07001974 memcpy(priv->ucode_init.v_addr, src, len);
1975 }
1976
1977 /* Initialization data (4th block) */
1978 if (init_data_size) {
1979 src = &ucode->data[inst_size + data_size + init_size];
1980 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001981 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1982 len);
Zhu Yib481de92007-09-25 17:54:57 -07001983 memcpy(priv->ucode_init_data.v_addr, src, len);
1984 }
1985
1986 /* Bootstrap instructions (5th block) */
1987 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1988 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001989 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001990 memcpy(priv->ucode_boot.v_addr, src, len);
1991
1992 /* We have our copies now, allow OS release its copies */
1993 release_firmware(ucode_raw);
1994 return 0;
1995
1996 err_pci_alloc:
1997 IWL_ERROR("failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001998 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001999 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002000
2001 err_release:
2002 release_firmware(ucode_raw);
2003
2004 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002005 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002006}
2007
Zhu Yib481de92007-09-25 17:54:57 -07002008/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002009 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002010 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002011 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002012 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002013static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002014{
Tomas Winkler57aab752008-04-14 21:16:03 -07002015 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002016
2017 IWL_DEBUG_INFO("Runtime Alive received.\n");
2018
2019 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2020 /* We had an error bringing up the hardware, so take it
2021 * all the way back down so we can try again */
2022 IWL_DEBUG_INFO("Alive failed.\n");
2023 goto restart;
2024 }
2025
2026 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2027 * This is a paranoid check, because we would not have gotten the
2028 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07002029 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002030 /* Runtime instruction load was bad;
2031 * take it all the way back down so we can try again */
2032 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
2033 goto restart;
2034 }
2035
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002036 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002037 ret = priv->cfg->ops->lib->alive_notify(priv);
2038 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -07002039 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
Tomas Winkler57aab752008-04-14 21:16:03 -07002040 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002041 goto restart;
2042 }
2043
Ben Cahill9fbab512007-11-29 11:09:47 +08002044 /* After the ALIVE response, we can send host commands to 4965 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002045 set_bit(STATUS_ALIVE, &priv->status);
2046
Tomas Winklerfee12472008-04-03 16:05:21 -07002047 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002048 return;
2049
Johannes Berg36d68252008-05-15 12:55:26 +02002050 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002051
2052 priv->active_rate = priv->rates_mask;
2053 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2054
Tomas Winkler3109ece2008-03-28 16:33:35 -07002055 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002056 struct iwl_rxon_cmd *active_rxon =
2057 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002058
2059 memcpy(&priv->staging_rxon, &priv->active_rxon,
2060 sizeof(priv->staging_rxon));
2061 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2062 } else {
2063 /* Initialize our rx_config data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002064 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002065 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2066 }
2067
Ben Cahill9fbab512007-11-29 11:09:47 +08002068 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002069 iwl4965_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002070
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002071 iwl_reset_run_time_calib(priv);
2072
Zhu Yib481de92007-09-25 17:54:57 -07002073 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002074 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002075
2076 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002077 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002078
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002079 iwl_leds_register(priv);
2080
Zhu Yib481de92007-09-25 17:54:57 -07002081 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002082 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002083 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002084
2085 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002086 iwl4965_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002087
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08002088 iwl_power_update_mode(priv, 1);
Mohamed Abbas84363e62008-04-04 16:59:58 -07002089 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002090
2091 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2092 iwl4965_set_mode(priv, priv->iw_mode);
2093
Zhu Yib481de92007-09-25 17:54:57 -07002094 return;
2095
2096 restart:
2097 queue_work(priv->workqueue, &priv->restart);
2098}
2099
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002100static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002101
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002102static void __iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002103{
2104 unsigned long flags;
2105 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002106
2107 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2108
Zhu Yib481de92007-09-25 17:54:57 -07002109 if (!exit_pending)
2110 set_bit(STATUS_EXIT_PENDING, &priv->status);
2111
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002112 iwl_leds_unregister(priv);
2113
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002114 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002115
2116 /* Unblock any waiting calls */
2117 wake_up_interruptible_all(&priv->wait_command_queue);
2118
Zhu Yib481de92007-09-25 17:54:57 -07002119 /* Wipe out the EXIT_PENDING status bit if we are not actually
2120 * exiting the module */
2121 if (!exit_pending)
2122 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2123
2124 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002125 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002126
2127 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002128 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002129 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002130 spin_unlock_irqrestore(&priv->lock, flags);
2131 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002132
2133 if (priv->mac80211_registered)
2134 ieee80211_stop_queues(priv->hw);
2135
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002136 /* If we have not previously called iwl4965_init() then
Zhu Yib481de92007-09-25 17:54:57 -07002137 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002138 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002139 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2140 STATUS_RF_KILL_HW |
2141 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2142 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002143 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2144 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002145 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002146 STATUS_IN_SUSPEND |
2147 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2148 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002149 goto exit;
2150 }
2151
2152 /* ...otherwise clear out all the status bits but the RF Kill and
2153 * SUSPEND bits and continue taking the NIC down. */
2154 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2155 STATUS_RF_KILL_HW |
2156 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2157 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002158 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2159 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002160 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2161 STATUS_IN_SUSPEND |
2162 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002163 STATUS_FW_ERROR |
2164 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2165 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002166
2167 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002168 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08002169 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002170 spin_unlock_irqrestore(&priv->lock, flags);
2171
Tomas Winklerda1bc452008-05-29 16:35:00 +08002172 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002173 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002174
2175 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002176 if (!iwl_grab_nic_access(priv)) {
2177 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002178 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002179 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002180 }
2181 spin_unlock_irqrestore(&priv->lock, flags);
2182
2183 udelay(5);
2184
Tomas Winkler7f066102008-05-29 16:34:57 +08002185 /* FIXME: apm_ops.suspend(priv) */
Gregory Greenmand5353112008-09-03 11:18:49 +08002186 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
2187 priv->cfg->ops->lib->apm_ops.stop(priv);
2188 else
2189 priv->cfg->ops->lib->apm_ops.reset(priv);
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002190 priv->cfg->ops->lib->free_shared_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002191
2192 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002193 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002194
2195 if (priv->ibss_beacon)
2196 dev_kfree_skb(priv->ibss_beacon);
2197 priv->ibss_beacon = NULL;
2198
2199 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002200 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002201}
2202
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002203static void iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002204{
2205 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002206 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002207 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002208
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002209 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002210}
2211
2212#define MAX_HW_RESTARTS 5
2213
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002214static int __iwl4965_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002215{
Tomas Winkler57aab752008-04-14 21:16:03 -07002216 int i;
2217 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002218
2219 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2220 IWL_WARNING("Exit pending; will not bring the NIC up\n");
2221 return -EIO;
2222 }
2223
Reinette Chatree903fbd2008-01-30 22:05:15 -08002224 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
2225 IWL_ERROR("ucode not available for device bringup\n");
2226 return -EIO;
2227 }
2228
Zhu Yie655b9f2008-01-24 02:19:38 -08002229 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winklerc1842d62008-08-04 16:00:43 +08002230 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
Zhu Yie655b9f2008-01-24 02:19:38 -08002231 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002232 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002233 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002234
Tomas Winklerc1842d62008-08-04 16:00:43 +08002235 if (iwl_is_rfkill(priv)) {
2236 iwl4965_enable_interrupts(priv);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002237 IWL_WARNING("Radio disabled by %s RF Kill switch\n",
2238 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
Tomas Winklerc1842d62008-08-04 16:00:43 +08002239 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002240 }
2241
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002242 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002243
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002244 ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
2245 if (ret) {
2246 IWL_ERROR("Unable to allocate shared memory\n");
2247 return ret;
2248 }
2249
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002250 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002251 if (ret) {
2252 IWL_ERROR("Unable to init nic\n");
2253 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002254 }
2255
2256 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002257 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2258 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002259 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2260
2261 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002262 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002263 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002264
2265 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002266 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2267 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002268
2269 /* Copy original ucode data image from disk into backup cache.
2270 * This will be used to initialize the on-board processor's
2271 * data SRAM for a clean start when the runtime program first loads. */
2272 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002273 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002274
Zhu Yib481de92007-09-25 17:54:57 -07002275 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2276
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002277 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002278
2279 /* load bootstrap state machine,
2280 * load bootstrap program into processor's memory,
2281 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002282 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002283
Tomas Winkler57aab752008-04-14 21:16:03 -07002284 if (ret) {
2285 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07002286 continue;
2287 }
2288
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08002289 /* Clear out the uCode error bit if it is set */
2290 clear_bit(STATUS_FW_ERROR, &priv->status);
2291
Zhu Yib481de92007-09-25 17:54:57 -07002292 /* start card; "initialize" will load runtime ucode */
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08002293 iwl4965_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002294
Zhu Yib481de92007-09-25 17:54:57 -07002295 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2296
2297 return 0;
2298 }
2299
2300 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002301 __iwl4965_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002302 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002303
2304 /* tried to restart and config the device for as long as our
2305 * patience could withstand */
2306 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
2307 return -EIO;
2308}
2309
2310
2311/*****************************************************************************
2312 *
2313 * Workqueue callbacks
2314 *
2315 *****************************************************************************/
2316
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002317static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002318{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002319 struct iwl_priv *priv =
2320 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002321
2322 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2323 return;
2324
2325 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002326 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002327 mutex_unlock(&priv->mutex);
2328}
2329
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002330static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002331{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002332 struct iwl_priv *priv =
2333 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002334
2335 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2336 return;
2337
2338 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002339 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002340 mutex_unlock(&priv->mutex);
2341}
2342
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002343static void iwl4965_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002344{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002345 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07002346
2347 wake_up_interruptible(&priv->wait_command_queue);
2348
2349 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2350 return;
2351
2352 mutex_lock(&priv->mutex);
2353
Tomas Winklerfee12472008-04-03 16:05:21 -07002354 if (!iwl_is_rfkill(priv)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08002355 IWL_DEBUG(IWL_DL_RF_KILL,
Zhu Yib481de92007-09-25 17:54:57 -07002356 "HW and/or SW RF Kill no longer active, restarting "
2357 "device\n");
2358 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
2359 queue_work(priv->workqueue, &priv->restart);
2360 } else {
Mohamed Abbasad97edd2008-03-28 16:21:06 -07002361 /* make sure mac80211 stop sending Tx frame */
2362 if (priv->mac80211_registered)
2363 ieee80211_stop_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002364
2365 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2366 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2367 "disabled by SW switch\n");
2368 else
2369 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2370 "Kill switch must be turned off for "
2371 "wireless networking to work.\n");
2372 }
2373 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002374 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002375}
2376
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002377static void iwl4965_bg_set_monitor(struct work_struct *work)
2378{
2379 struct iwl_priv *priv = container_of(work,
2380 struct iwl_priv, set_monitor);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002381 int ret;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002382
2383 IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
2384
2385 mutex_lock(&priv->mutex);
2386
Johannes Berg05c914f2008-09-11 00:01:58 +02002387 ret = iwl4965_set_mode(priv, NL80211_IFTYPE_MONITOR);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002388
2389 if (ret) {
2390 if (ret == -EAGAIN)
2391 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
2392 else
2393 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
2394 }
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002395
2396 mutex_unlock(&priv->mutex);
2397}
2398
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002399static void iwl_bg_run_time_calib_work(struct work_struct *work)
2400{
2401 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2402 run_time_calib_work);
2403
2404 mutex_lock(&priv->mutex);
2405
2406 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2407 test_bit(STATUS_SCANNING, &priv->status)) {
2408 mutex_unlock(&priv->mutex);
2409 return;
2410 }
2411
2412 if (priv->start_calib) {
2413 iwl_chain_noise_calibration(priv, &priv->statistics);
2414
2415 iwl_sensitivity_calibration(priv, &priv->statistics);
2416 }
2417
2418 mutex_unlock(&priv->mutex);
2419 return;
2420}
2421
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002422static void iwl4965_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002423{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002424 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002425
2426 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2427 return;
2428
2429 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002430 __iwl4965_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002431 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002432 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002433}
2434
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002435static void iwl4965_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002436{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002437 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002438
2439 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2440 return;
2441
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002442 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002443 queue_work(priv->workqueue, &priv->up);
2444}
2445
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002446static void iwl4965_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002447{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002448 struct iwl_priv *priv =
2449 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002450
2451 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2452 return;
2453
2454 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002455 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002456 mutex_unlock(&priv->mutex);
2457}
2458
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002459#define IWL_DELAY_NEXT_SCAN (HZ*2)
2460
Reinette Chatre508e32e2008-04-14 21:16:13 -07002461static void iwl4965_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002462{
Zhu Yib481de92007-09-25 17:54:57 -07002463 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002464 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002465 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002466
Johannes Berg05c914f2008-09-11 00:01:58 +02002467 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002468 IWL_ERROR("%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07002469 return;
2470 }
2471
Johannes Berge1749612008-10-27 15:59:26 -07002472 IWL_DEBUG_ASSOC("Associated as %d to: %pM\n",
2473 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07002474
2475
2476 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2477 return;
2478
Zhu Yib481de92007-09-25 17:54:57 -07002479
Reinette Chatre508e32e2008-04-14 21:16:13 -07002480 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002481 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002482
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002483 iwl_power_cancel_timeout(priv);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002484 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002485
Zhu Yib481de92007-09-25 17:54:57 -07002486 conf = ieee80211_get_hw_conf(priv->hw);
2487
2488 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002489 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002490
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002491 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2492 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002493 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002494 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002495 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07002496 IWL_WARNING("REPLY_RXON_TIMING failed - "
2497 "Attempting to continue.\n");
2498
2499 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2500
Emmanuel Grumbach42eb7c62008-09-17 10:10:05 +08002501 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002502
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002503 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002504 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2505
2506 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2507 priv->assoc_id, priv->beacon_int);
2508
2509 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2510 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2511 else
2512 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2513
2514 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2515 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2516 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2517 else
2518 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2519
Johannes Berg05c914f2008-09-11 00:01:58 +02002520 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002521 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2522
2523 }
2524
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002525 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002526
2527 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02002528 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -07002529 break;
2530
Johannes Berg05c914f2008-09-11 00:01:58 +02002531 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07002532
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002533 /* assume default assoc id */
2534 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002535
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002536 iwl_rxon_add_station(priv, priv->bssid, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002537 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002538
2539 break;
2540
2541 default:
2542 IWL_ERROR("%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03002543 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002544 break;
2545 }
2546
Johannes Berg05c914f2008-09-11 00:01:58 +02002547 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002548 priv->assoc_station_added = 1;
2549
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002550 spin_lock_irqsave(&priv->lock, flags);
2551 iwl_activate_qos(priv, 0);
2552 spin_unlock_irqrestore(&priv->lock, flags);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002553
Grumbach, Emmanuel04816442008-09-03 11:26:53 +08002554 /* the chain noise calibration will enabled PM upon completion
2555 * If chain noise has already been run, then we need to enable
2556 * power management here */
2557 if (priv->chain_noise_data.state == IWL_CHAIN_NOISE_DONE)
2558 iwl_power_enable_management(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08002559
2560 /* Enable Rx differential gain and sensitivity calibrations */
2561 iwl_chain_noise_reset(priv);
2562 priv->start_calib = 1;
2563
Reinette Chatre508e32e2008-04-14 21:16:13 -07002564}
2565
Zhu Yib481de92007-09-25 17:54:57 -07002566/*****************************************************************************
2567 *
2568 * mac80211 entry point functions
2569 *
2570 *****************************************************************************/
2571
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002572#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08002573
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002574static int iwl4965_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002575{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002576 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002577 int ret;
Tomas Winklercf88c432008-08-28 17:25:04 +08002578 u16 pci_cmd;
Zhu Yib481de92007-09-25 17:54:57 -07002579
2580 IWL_DEBUG_MAC80211("enter\n");
2581
Zhu Yi5a66926a2008-01-14 17:46:18 -08002582 if (pci_enable_device(priv->pci_dev)) {
2583 IWL_ERROR("Fail to pci_enable_device\n");
2584 return -ENODEV;
2585 }
2586 pci_restore_state(priv->pci_dev);
2587 pci_enable_msi(priv->pci_dev);
2588
Tomas Winklercf88c432008-08-28 17:25:04 +08002589 /* enable interrupts if needed: hw bug w/a */
2590 pci_read_config_word(priv->pci_dev, PCI_COMMAND, &pci_cmd);
2591 if (pci_cmd & PCI_COMMAND_INTX_DISABLE) {
2592 pci_cmd &= ~PCI_COMMAND_INTX_DISABLE;
2593 pci_write_config_word(priv->pci_dev, PCI_COMMAND, pci_cmd);
2594 }
2595
Zhu Yi5a66926a2008-01-14 17:46:18 -08002596 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
2597 DRV_NAME, priv);
2598 if (ret) {
2599 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
2600 goto out_disable_msi;
2601 }
2602
Zhu Yib481de92007-09-25 17:54:57 -07002603 /* we should be verifying the device is ready to be opened */
2604 mutex_lock(&priv->mutex);
2605
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002606 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a66926a2008-01-14 17:46:18 -08002607 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2608 * ucode filename and max sizes are card-specific. */
2609
2610 if (!priv->ucode_code.len) {
2611 ret = iwl4965_read_ucode(priv);
2612 if (ret) {
2613 IWL_ERROR("Could not read microcode: %d\n", ret);
2614 mutex_unlock(&priv->mutex);
2615 goto out_release_irq;
2616 }
2617 }
2618
Zhu Yie655b9f2008-01-24 02:19:38 -08002619 ret = __iwl4965_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002620
Zhu Yib481de92007-09-25 17:54:57 -07002621 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002622
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002623 iwl_rfkill_set_hw_state(priv);
2624
Zhu Yie655b9f2008-01-24 02:19:38 -08002625 if (ret)
2626 goto out_release_irq;
2627
Tomas Winklerc1842d62008-08-04 16:00:43 +08002628 if (iwl_is_rfkill(priv))
2629 goto out;
2630
Zhu Yie655b9f2008-01-24 02:19:38 -08002631 IWL_DEBUG_INFO("Start UP work done.\n");
2632
2633 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2634 return 0;
2635
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002636 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08002637 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002638 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2639 test_bit(STATUS_READY, &priv->status),
2640 UCODE_READY_TIMEOUT);
2641 if (!ret) {
2642 if (!test_bit(STATUS_READY, &priv->status)) {
2643 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2644 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2645 ret = -ETIMEDOUT;
2646 goto out_release_irq;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002647 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002648 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002649
Tomas Winklerc1842d62008-08-04 16:00:43 +08002650out:
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002651 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002652 IWL_DEBUG_MAC80211("leave\n");
2653 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002654
2655out_release_irq:
2656 free_irq(priv->pci_dev->irq, priv);
2657out_disable_msi:
2658 pci_disable_msi(priv->pci_dev);
Zhu Yie655b9f2008-01-24 02:19:38 -08002659 pci_disable_device(priv->pci_dev);
2660 priv->is_open = 0;
2661 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08002662 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002663}
2664
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002665static void iwl4965_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002666{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002667 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002668
2669 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002670
Zhu Yie655b9f2008-01-24 02:19:38 -08002671 if (!priv->is_open) {
2672 IWL_DEBUG_MAC80211("leave - skip\n");
2673 return;
2674 }
2675
Zhu Yib481de92007-09-25 17:54:57 -07002676 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002677
Tomas Winklerfee12472008-04-03 16:05:21 -07002678 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002679 /* stop mac, cancel any scan request and clear
2680 * RXON_FILTER_ASSOC_MSK BIT
2681 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002682 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002683 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002684 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002685 }
2686
Zhu Yi5a66926a2008-01-14 17:46:18 -08002687 iwl4965_down(priv);
2688
2689 flush_workqueue(priv->workqueue);
2690 free_irq(priv->pci_dev->irq, priv);
2691 pci_disable_msi(priv->pci_dev);
2692 pci_save_state(priv->pci_dev);
2693 pci_disable_device(priv->pci_dev);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002694
Zhu Yib481de92007-09-25 17:54:57 -07002695 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002696}
2697
Johannes Berge039fa42008-05-15 12:55:29 +02002698static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002699{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002700 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002701
Tomas Winklerf3674222008-08-04 16:00:44 +08002702 IWL_DEBUG_MACDUMP("enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002703
Zhu Yib481de92007-09-25 17:54:57 -07002704 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002705 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002706
Johannes Berge039fa42008-05-15 12:55:29 +02002707 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002708 dev_kfree_skb_any(skb);
2709
Tomas Winklerf3674222008-08-04 16:00:44 +08002710 IWL_DEBUG_MACDUMP("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002711 return 0;
2712}
2713
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002714static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002715 struct ieee80211_if_init_conf *conf)
2716{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002717 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002718 unsigned long flags;
2719
Johannes Berg32bfd352007-12-19 01:31:26 +01002720 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07002721
Johannes Berg32bfd352007-12-19 01:31:26 +01002722 if (priv->vif) {
2723 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08002724 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07002725 }
2726
2727 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01002728 priv->vif = conf->vif;
Zhu Yib481de92007-09-25 17:54:57 -07002729
2730 spin_unlock_irqrestore(&priv->lock, flags);
2731
2732 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02002733
2734 if (conf->mac_addr) {
Johannes Berge1749612008-10-27 15:59:26 -07002735 IWL_DEBUG_MAC80211("Set %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02002736 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2737 }
Zhu Yib481de92007-09-25 17:54:57 -07002738
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002739 if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
2740 /* we are not ready, will run again when ready */
2741 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002742
Zhu Yib481de92007-09-25 17:54:57 -07002743 mutex_unlock(&priv->mutex);
2744
Zhu Yi5a66926a2008-01-14 17:46:18 -08002745 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002746 return 0;
2747}
2748
2749/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002750 * iwl4965_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07002751 *
2752 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2753 * be set inappropriately and the driver currently sets the hardware up to
2754 * use it whenever needed.
2755 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002756static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07002757{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002758 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002759 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002760 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08002761 int ret = 0;
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002762 u16 channel;
Zhu Yib481de92007-09-25 17:54:57 -07002763
2764 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002765 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002766
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002767 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002768 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002769 goto out;
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002770 }
2771
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002772 if (!conf->radio_enabled)
2773 iwl_radio_kill_sw_disable_radio(priv);
2774
Tomas Winklerfee12472008-04-03 16:05:21 -07002775 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002776 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002777 ret = -EIO;
2778 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002779 }
2780
Assaf Krauss1ea87392008-03-18 14:57:50 -07002781 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07002782 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08002783 IWL_DEBUG_MAC80211("leave - scanning\n");
Zhu Yib481de92007-09-25 17:54:57 -07002784 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08002785 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002786 }
2787
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002788 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2789 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002790 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07002791 IWL_DEBUG_MAC80211("leave - invalid channel\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002792 ret = -EINVAL;
2793 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002794 }
2795
Johannes Berg05c914f2008-09-11 00:01:58 +02002796 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Assaf Krauss398f9e72008-06-12 09:47:06 +08002797 !is_channel_ibss(ch_info)) {
2798 IWL_ERROR("channel %d in band %d not IBSS channel\n",
2799 conf->channel->hw_value, conf->channel->band);
2800 ret = -EINVAL;
2801 goto out;
2802 }
2803
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002804 spin_lock_irqsave(&priv->lock, flags);
2805
Tomas Winklerb5d7be52008-07-19 04:41:24 +03002806
Tomas Winkler78330fd2008-02-06 02:37:18 +02002807 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07002808 * from any ht related info since 2.4 does not
2809 * support ht */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002810 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
Zhu Yib481de92007-09-25 17:54:57 -07002811#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2812 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2813#endif
2814 )
2815 priv->staging_rxon.flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002816
Tomas Winkler17e72782008-09-03 11:26:26 +08002817 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002818
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002819 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07002820
2821 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01002822 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07002823 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002824 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002825
2826 spin_unlock_irqrestore(&priv->lock, flags);
2827
2828#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2829 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002830 iwl4965_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002831 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002832 }
2833#endif
2834
Zhu Yib481de92007-09-25 17:54:57 -07002835 if (!conf->radio_enabled) {
2836 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002837 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002838 }
2839
Tomas Winklerfee12472008-04-03 16:05:21 -07002840 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002841 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002842 ret = -EIO;
2843 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002844 }
2845
Ester Kummere602cb12008-09-26 15:09:33 +08002846 if (conf->flags & IEEE80211_CONF_PS)
2847 ret = iwl_power_set_user_mode(priv, IWL_POWER_INDEX_3);
2848 else
2849 ret = iwl_power_set_user_mode(priv, IWL_POWER_MODE_CAM);
2850 if (ret)
2851 IWL_DEBUG_MAC80211("Error setting power level\n");
2852
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002853 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2854 priv->tx_power_user_lmt, conf->power_level);
2855
2856 iwl_set_tx_power(priv, conf->power_level, false);
2857
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002858 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002859
2860 if (memcmp(&priv->active_rxon,
2861 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002862 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002863 else
2864 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2865
2866 IWL_DEBUG_MAC80211("leave\n");
2867
Zhu Yia0646472007-12-20 14:10:01 +08002868out:
Zhu Yi5a66926a2008-01-14 17:46:18 -08002869 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002870 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002871}
2872
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002873static void iwl4965_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002874{
Tomas Winkler857485c2008-03-21 13:53:44 -07002875 int ret = 0;
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002876 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07002877
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002878 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002879 return;
2880
2881 /* The following should be done only at AP bring up */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +08002882 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07002883
2884 /* RXON - unassoc (to set timing command) */
2885 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002886 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002887
2888 /* RXON Timing */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002889 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2890 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002891 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002892 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002893 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07002894 IWL_WARNING("REPLY_RXON_TIMING failed - "
2895 "Attempting to continue.\n");
2896
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002897 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002898
2899 /* FIXME: what should be the assoc_id for AP? */
2900 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2901 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2902 priv->staging_rxon.flags |=
2903 RXON_FLG_SHORT_PREAMBLE_MSK;
2904 else
2905 priv->staging_rxon.flags &=
2906 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2907
2908 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2909 if (priv->assoc_capability &
2910 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2911 priv->staging_rxon.flags |=
2912 RXON_FLG_SHORT_SLOT_MSK;
2913 else
2914 priv->staging_rxon.flags &=
2915 ~RXON_FLG_SHORT_SLOT_MSK;
2916
Johannes Berg05c914f2008-09-11 00:01:58 +02002917 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Zhu Yib481de92007-09-25 17:54:57 -07002918 priv->staging_rxon.flags &=
2919 ~RXON_FLG_SHORT_SLOT_MSK;
2920 }
2921 /* restore RXON assoc */
2922 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002923 iwl4965_commit_rxon(priv);
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08002924 spin_lock_irqsave(&priv->lock, flags);
2925 iwl_activate_qos(priv, 1);
2926 spin_unlock_irqrestore(&priv->lock, flags);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002927 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002928 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002929 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002930
2931 /* FIXME - we need to add code here to detect a totally new
2932 * configuration, reset the AP, unassoc, rxon timing, assoc,
2933 * clear sta table, add BCAST sta... */
2934}
2935
Johannes Berg9d139c82008-07-09 14:40:37 +02002936/* temporary */
2937static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
2938
Johannes Berg32bfd352007-12-19 01:31:26 +01002939static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
2940 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002941 struct ieee80211_if_conf *conf)
2942{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002943 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002944 unsigned long flags;
2945 int rc;
2946
2947 if (conf == NULL)
2948 return -EIO;
2949
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002950 if (priv->vif != vif) {
2951 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002952 return 0;
2953 }
2954
Johannes Berg05c914f2008-09-11 00:01:58 +02002955 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02002956 conf->changed & IEEE80211_IFCC_BEACON) {
2957 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2958 if (!beacon)
2959 return -ENOMEM;
2960 rc = iwl4965_mac_beacon_update(hw, beacon);
2961 if (rc)
2962 return rc;
2963 }
2964
Johannes Berg05c914f2008-09-11 00:01:58 +02002965 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Johannes Berg9d139c82008-07-09 14:40:37 +02002966 (!conf->ssid_len)) {
Zhu Yib481de92007-09-25 17:54:57 -07002967 IWL_DEBUG_MAC80211
2968 ("Leaving in AP mode because HostAPD is not ready.\n");
2969 return 0;
2970 }
2971
Tomas Winklerfee12472008-04-03 16:05:21 -07002972 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08002973 return -EAGAIN;
2974
Zhu Yib481de92007-09-25 17:54:57 -07002975 mutex_lock(&priv->mutex);
2976
Zhu Yib481de92007-09-25 17:54:57 -07002977 if (conf->bssid)
Johannes Berge1749612008-10-27 15:59:26 -07002978 IWL_DEBUG_MAC80211("bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002979
Johannes Berg4150c572007-09-17 01:29:23 -04002980/*
2981 * very dubious code was here; the probe filtering flag is never set:
2982 *
Zhu Yib481de92007-09-25 17:54:57 -07002983 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2984 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002985 */
Zhu Yib481de92007-09-25 17:54:57 -07002986
Johannes Berg05c914f2008-09-11 00:01:58 +02002987 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07002988 if (!conf->bssid) {
2989 conf->bssid = priv->mac_addr;
2990 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Johannes Berge1749612008-10-27 15:59:26 -07002991 IWL_DEBUG_MAC80211("bssid was set to: %pM\n",
2992 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07002993 }
2994 if (priv->ibss_beacon)
2995 dev_kfree_skb(priv->ibss_beacon);
2996
Johannes Berg9d139c82008-07-09 14:40:37 +02002997 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07002998 }
2999
Tomas Winklerfee12472008-04-03 16:05:21 -07003000 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08003001 goto done;
3002
Zhu Yib481de92007-09-25 17:54:57 -07003003 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3004 !is_multicast_ether_addr(conf->bssid)) {
3005 /* If there is currently a HW scan going on in the background
3006 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003007 if (iwl_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07003008 IWL_WARNING("Aborted scan still in progress "
3009 "after 100ms\n");
3010 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
3011 mutex_unlock(&priv->mutex);
3012 return -EAGAIN;
3013 }
3014 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
3015
3016 /* TODO: Audit driver for usage of these members and see
3017 * if mac80211 deprecates them (priv->bssid looks like it
3018 * shouldn't be there, but I haven't scanned the IBSS code
3019 * to verify) - jpk */
3020 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
3021
Johannes Berg05c914f2008-09-11 00:01:58 +02003022 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003023 iwl4965_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003024 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003025 rc = iwl4965_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02003026 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08003027 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07003028 priv, priv->active_rxon.bssid_addr, 1);
3029 }
3030
3031 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003032 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07003033 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003034 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003035 }
3036
Mohamed Abbasfde35712007-11-29 11:10:15 +08003037 done:
Zhu Yib481de92007-09-25 17:54:57 -07003038 spin_lock_irqsave(&priv->lock, flags);
3039 if (!conf->ssid_len)
3040 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3041 else
3042 memcpy(priv->essid, conf->ssid, conf->ssid_len);
3043
3044 priv->essid_len = conf->ssid_len;
3045 spin_unlock_irqrestore(&priv->lock, flags);
3046
3047 IWL_DEBUG_MAC80211("leave\n");
3048 mutex_unlock(&priv->mutex);
3049
3050 return 0;
3051}
3052
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003053static void iwl4965_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04003054 unsigned int changed_flags,
3055 unsigned int *total_flags,
3056 int mc_count, struct dev_addr_list *mc_list)
3057{
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08003058 struct iwl_priv *priv = hw->priv;
Rick Farrington25b3f572008-06-30 17:23:28 +08003059
3060 if (changed_flags & (*total_flags) & FIF_OTHER_BSS) {
3061 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
Johannes Berg05c914f2008-09-11 00:01:58 +02003062 NL80211_IFTYPE_MONITOR,
Rick Farrington25b3f572008-06-30 17:23:28 +08003063 changed_flags, *total_flags);
3064 /* queue work 'cuz mac80211 is holding a lock which
3065 * prevents us from issuing (synchronous) f/w cmds */
3066 queue_work(priv->workqueue, &priv->set_monitor);
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08003067 }
Rick Farrington25b3f572008-06-30 17:23:28 +08003068 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI |
3069 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04003070}
3071
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003072static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003073 struct ieee80211_if_init_conf *conf)
3074{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003075 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003076
3077 IWL_DEBUG_MAC80211("enter\n");
3078
3079 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003080
Tomas Winklerfee12472008-04-03 16:05:21 -07003081 if (iwl_is_ready_rf(priv)) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003082 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003083 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3084 iwl4965_commit_rxon(priv);
3085 }
Johannes Berg32bfd352007-12-19 01:31:26 +01003086 if (priv->vif == conf->vif) {
3087 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003088 memset(priv->bssid, 0, ETH_ALEN);
3089 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3090 priv->essid_len = 0;
3091 }
3092 mutex_unlock(&priv->mutex);
3093
3094 IWL_DEBUG_MAC80211("leave\n");
3095
3096}
Johannes Berg471b3ef2007-12-28 14:32:58 +01003097
Tomas Winkler3109ece2008-03-28 16:33:35 -07003098#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Johannes Berg471b3ef2007-12-28 14:32:58 +01003099static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
3100 struct ieee80211_vif *vif,
3101 struct ieee80211_bss_conf *bss_conf,
3102 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02003103{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003104 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02003105
Tomas Winkler3109ece2008-03-28 16:33:35 -07003106 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
3107
Johannes Berg471b3ef2007-12-28 14:32:58 +01003108 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003109 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
3110 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003111 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02003112 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3113 else
3114 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3115 }
3116
Johannes Berg471b3ef2007-12-28 14:32:58 +01003117 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003118 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01003119 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02003120 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
3121 else
3122 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
3123 }
3124
Tomas Winkler98952d52008-03-28 16:33:33 -07003125 if (changes & BSS_CHANGED_HT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003126 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
Tomas Winkler98952d52008-03-28 16:33:33 -07003127 iwl4965_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003128 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07003129 }
3130
Johannes Berg471b3ef2007-12-28 14:32:58 +01003131 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003132 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003133 /* This should never happen as this function should
3134 * never be called from interrupt context. */
3135 if (WARN_ON_ONCE(in_interrupt()))
3136 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003137 if (bss_conf->assoc) {
3138 priv->assoc_id = bss_conf->aid;
3139 priv->beacon_int = bss_conf->beacon_int;
Tomas Winklerb5d7be52008-07-19 04:41:24 +03003140 priv->power_data.dtim_period = bss_conf->dtim_period;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003141 priv->timestamp = bss_conf->timestamp;
3142 priv->assoc_capability = bss_conf->assoc_capability;
Tomas Winkler9ccacb82008-09-16 14:01:03 +08003143
3144 /* we have just associated, don't start scan too early
3145 * leave time for EAPOL exchange to complete
3146 */
Tomas Winkler3109ece2008-03-28 16:33:35 -07003147 priv->next_scan_jiffies = jiffies +
3148 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003149 mutex_lock(&priv->mutex);
3150 iwl4965_post_associate(priv);
3151 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003152 } else {
3153 priv->assoc_id = 0;
3154 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3155 }
3156 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3157 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003158 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003159 }
3160
Tomas Winkler220173b2007-10-16 00:50:25 +02003161}
Zhu Yib481de92007-09-25 17:54:57 -07003162
Tomas Winklercb43dc22008-09-03 11:26:23 +08003163static int iwl_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t ssid_len)
Zhu Yib481de92007-09-25 17:54:57 -07003164{
Zhu Yib481de92007-09-25 17:54:57 -07003165 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003166 struct iwl_priv *priv = hw->priv;
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003167 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003168
3169 IWL_DEBUG_MAC80211("enter\n");
3170
mabbas052c4b92007-10-25 17:15:43 +08003171 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003172 spin_lock_irqsave(&priv->lock, flags);
3173
Tomas Winklerfee12472008-04-03 16:05:21 -07003174 if (!iwl_is_ready_rf(priv)) {
Tomas Winklercb43dc22008-09-03 11:26:23 +08003175 ret = -EIO;
Zhu Yib481de92007-09-25 17:54:57 -07003176 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3177 goto out_unlock;
3178 }
3179
Johannes Berg05c914f2008-09-11 00:01:58 +02003180 if (priv->iw_mode == NL80211_IFTYPE_AP) { /* APs don't scan */
Tomas Winklercb43dc22008-09-03 11:26:23 +08003181 ret = -EIO;
Zhu Yib481de92007-09-25 17:54:57 -07003182 IWL_ERROR("ERROR: APs don't scan\n");
3183 goto out_unlock;
3184 }
3185
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003186 /* We don't schedule scan within next_scan_jiffies period.
3187 * Avoid scanning during possible EAPOL exchange, return
3188 * success immediately.
3189 */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003190 if (priv->next_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003191 time_after(priv->next_scan_jiffies, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003192 IWL_DEBUG_SCAN("scan rejected: within next scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003193 queue_work(priv->workqueue, &priv->scan_completed);
3194 ret = 0;
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003195 goto out_unlock;
3196 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003197
Zhu Yib481de92007-09-25 17:54:57 -07003198 /* if we just finished scan ask for delay */
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003199 if (iwl_is_associated(priv) && priv->last_scan_jiffies &&
Tomas Winklercb43dc22008-09-03 11:26:23 +08003200 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN, jiffies)) {
Ron Rindjunsky681c0052008-09-03 11:26:25 +08003201 IWL_DEBUG_SCAN("scan rejected: within previous scan period\n");
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003202 queue_work(priv->workqueue, &priv->scan_completed);
3203 ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003204 goto out_unlock;
3205 }
Tomas Winkler8d09a5e2008-09-24 13:57:46 +08003206
Tomas Winklercb43dc22008-09-03 11:26:23 +08003207 if (ssid_len) {
Zhu Yib481de92007-09-25 17:54:57 -07003208 priv->one_direct_scan = 1;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003209 priv->direct_ssid_len = min_t(u8, ssid_len, IW_ESSID_MAX_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003210 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Tomas Winklercb43dc22008-09-03 11:26:23 +08003211 } else {
Mohamed Abbas948c1712007-10-25 17:15:45 +08003212 priv->one_direct_scan = 0;
Tomas Winklercb43dc22008-09-03 11:26:23 +08003213 }
Zhu Yib481de92007-09-25 17:54:57 -07003214
Tomas Winklercb43dc22008-09-03 11:26:23 +08003215 ret = iwl_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003216
3217 IWL_DEBUG_MAC80211("leave\n");
3218
3219out_unlock:
3220 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08003221 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003222
Tomas Winklercb43dc22008-09-03 11:26:23 +08003223 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003224}
3225
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003226static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
3227 struct ieee80211_key_conf *keyconf, const u8 *addr,
3228 u32 iv32, u16 *phase1key)
3229{
3230 struct iwl_priv *priv = hw->priv;
3231 u8 sta_id = IWL_INVALID_STATION;
3232 unsigned long flags;
3233 __le16 key_flags = 0;
3234 int i;
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003235
3236 IWL_DEBUG_MAC80211("enter\n");
3237
Tomas Winkler947b13a2008-04-16 16:34:48 -07003238 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003239 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07003240 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
3241 addr);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003242 return;
3243 }
3244
Tomas Winkler2a421b92008-06-12 09:47:10 +08003245 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003246
3247 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
3248 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
3249 key_flags &= ~STA_KEY_FLG_INVALID;
3250
Tomas Winkler5425e492008-04-15 16:01:38 -07003251 if (sta_id == priv->hw_params.bcast_sta_id)
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003252 key_flags |= STA_KEY_MULTICAST_MSK;
3253
3254 spin_lock_irqsave(&priv->sta_lock, flags);
3255
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003256 priv->stations[sta_id].sta.key.key_flags = key_flags;
3257 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
3258
3259 for (i = 0; i < 5; i++)
3260 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
3261 cpu_to_le16(phase1key[i]);
3262
3263 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
3264 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3265
Tomas Winkler133636d2008-05-05 10:22:34 +08003266 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003267
3268 spin_unlock_irqrestore(&priv->sta_lock, flags);
3269
3270 IWL_DEBUG_MAC80211("leave\n");
3271}
3272
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003273static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Zhu Yib481de92007-09-25 17:54:57 -07003274 const u8 *local_addr, const u8 *addr,
3275 struct ieee80211_key_conf *key)
3276{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003277 struct iwl_priv *priv = hw->priv;
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003278 int ret = 0;
3279 u8 sta_id = IWL_INVALID_STATION;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003280 u8 is_default_wep_key = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003281
3282 IWL_DEBUG_MAC80211("enter\n");
3283
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003284 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07003285 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3286 return -EOPNOTSUPP;
3287 }
3288
3289 if (is_zero_ether_addr(addr))
3290 /* only support pairwise keys */
3291 return -EOPNOTSUPP;
3292
Tomas Winkler947b13a2008-04-16 16:34:48 -07003293 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003294 if (sta_id == IWL_INVALID_STATION) {
Johannes Berge1749612008-10-27 15:59:26 -07003295 IWL_DEBUG_MAC80211("leave - %pM not in station map.\n",
3296 addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003297 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003298
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003299 }
Zhu Yib481de92007-09-25 17:54:57 -07003300
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003301 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003302 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003303 mutex_unlock(&priv->mutex);
3304
3305 /* If we are getting WEP group key and we didn't receive any key mapping
3306 * so far, we are in legacy wep mode (group key only), otherwise we are
3307 * in 1X mode.
3308 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07003309 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Johannes Berg05c914f2008-09-11 00:01:58 +02003310 priv->iw_mode != NL80211_IFTYPE_AP) {
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003311 if (cmd == SET_KEY)
3312 is_default_wep_key = !priv->key_mapping_key;
3313 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003314 is_default_wep_key =
3315 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003316 }
mabbas052c4b92007-10-25 17:15:43 +08003317
Zhu Yib481de92007-09-25 17:54:57 -07003318 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003319 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003320 if (is_default_wep_key)
3321 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003322 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003323 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003324
3325 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003326 break;
3327 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003328 if (is_default_wep_key)
3329 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003330 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003331 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003332
3333 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003334 break;
3335 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003336 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003337 }
3338
3339 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003340
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003341 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003342}
3343
Johannes Berge100bb62008-04-30 18:51:21 +02003344static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07003345 const struct ieee80211_tx_queue_params *params)
3346{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003347 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003348 unsigned long flags;
3349 int q;
Zhu Yib481de92007-09-25 17:54:57 -07003350
3351 IWL_DEBUG_MAC80211("enter\n");
3352
Tomas Winklerfee12472008-04-03 16:05:21 -07003353 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003354 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3355 return -EIO;
3356 }
3357
3358 if (queue >= AC_NUM) {
3359 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3360 return 0;
3361 }
3362
Zhu Yib481de92007-09-25 17:54:57 -07003363 if (!priv->qos_data.qos_enable) {
3364 priv->qos_data.qos_active = 0;
3365 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
3366 return 0;
3367 }
3368 q = AC_NUM - 1 - queue;
3369
3370 spin_lock_irqsave(&priv->lock, flags);
3371
3372 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3373 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3374 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3375 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01003376 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07003377
3378 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3379 priv->qos_data.qos_active = 1;
3380
Johannes Berg05c914f2008-09-11 00:01:58 +02003381 if (priv->iw_mode == NL80211_IFTYPE_AP)
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003382 iwl_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003383 else if (priv->assoc_id && iwl_is_associated(priv))
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003384 iwl_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003385
Emmanuel Grumbach1ff50bd2008-07-11 11:53:34 +08003386 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003387
Zhu Yib481de92007-09-25 17:54:57 -07003388 IWL_DEBUG_MAC80211("leave\n");
3389 return 0;
3390}
3391
Tomas Winklerd783b062008-07-18 13:53:02 +08003392static int iwl4965_mac_ampdu_action(struct ieee80211_hw *hw,
3393 enum ieee80211_ampdu_mlme_action action,
Johannes Berg17741cd2008-09-11 00:02:02 +02003394 struct ieee80211_sta *sta, u16 tid, u16 *ssn)
Tomas Winklerd783b062008-07-18 13:53:02 +08003395{
3396 struct iwl_priv *priv = hw->priv;
Tomas Winklerd783b062008-07-18 13:53:02 +08003397
Johannes Berge1749612008-10-27 15:59:26 -07003398 IWL_DEBUG_HT("A-MPDU action on addr %pM tid %d\n",
3399 sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003400
3401 if (!(priv->cfg->sku & IWL_SKU_N))
3402 return -EACCES;
3403
3404 switch (action) {
3405 case IEEE80211_AMPDU_RX_START:
3406 IWL_DEBUG_HT("start Rx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003407 return iwl_rx_agg_start(priv, sta->addr, tid, *ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003408 case IEEE80211_AMPDU_RX_STOP:
3409 IWL_DEBUG_HT("stop Rx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003410 return iwl_rx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003411 case IEEE80211_AMPDU_TX_START:
3412 IWL_DEBUG_HT("start Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003413 return iwl_tx_agg_start(priv, sta->addr, tid, ssn);
Tomas Winklerd783b062008-07-18 13:53:02 +08003414 case IEEE80211_AMPDU_TX_STOP:
3415 IWL_DEBUG_HT("stop Tx\n");
Johannes Berg17741cd2008-09-11 00:02:02 +02003416 return iwl_tx_agg_stop(priv, sta->addr, tid);
Tomas Winklerd783b062008-07-18 13:53:02 +08003417 default:
3418 IWL_DEBUG_HT("unknown\n");
3419 return -EINVAL;
3420 break;
3421 }
3422 return 0;
3423}
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003424static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003425 struct ieee80211_tx_queue_stats *stats)
3426{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003427 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003428 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003429 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003430 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003431 unsigned long flags;
3432
3433 IWL_DEBUG_MAC80211("enter\n");
3434
Tomas Winklerfee12472008-04-03 16:05:21 -07003435 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003436 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3437 return -EIO;
3438 }
3439
3440 spin_lock_irqsave(&priv->lock, flags);
3441
3442 for (i = 0; i < AC_NUM; i++) {
3443 txq = &priv->txq[i];
3444 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003445 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003446
Johannes Berg57ffc582008-04-29 17:18:59 +02003447 stats[i].len = q->n_window - avail;
3448 stats[i].limit = q->n_window - q->high_mark;
3449 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003450
3451 }
3452 spin_unlock_irqrestore(&priv->lock, flags);
3453
3454 IWL_DEBUG_MAC80211("leave\n");
3455
3456 return 0;
3457}
3458
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003459static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003460 struct ieee80211_low_level_stats *stats)
3461{
Ester Kummerbf403db2008-05-05 10:22:40 +08003462 struct iwl_priv *priv = hw->priv;
3463
3464 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003465 IWL_DEBUG_MAC80211("enter\n");
3466 IWL_DEBUG_MAC80211("leave\n");
3467
3468 return 0;
3469}
3470
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003471static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003472{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003473 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003474 unsigned long flags;
3475
3476 mutex_lock(&priv->mutex);
3477 IWL_DEBUG_MAC80211("enter\n");
3478
Zhu Yib481de92007-09-25 17:54:57 -07003479 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003480 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07003481 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003482
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003483 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003484
Zhu Yib481de92007-09-25 17:54:57 -07003485 spin_lock_irqsave(&priv->lock, flags);
3486 priv->assoc_id = 0;
3487 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003488 priv->assoc_station_added = 0;
3489
3490 /* new association get rid of ibss beacon skb */
3491 if (priv->ibss_beacon)
3492 dev_kfree_skb(priv->ibss_beacon);
3493
3494 priv->ibss_beacon = NULL;
3495
3496 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003497 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02003498 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07003499 priv->beacon_int = 0;
3500
3501 spin_unlock_irqrestore(&priv->lock, flags);
3502
Tomas Winklerfee12472008-04-03 16:05:21 -07003503 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08003504 IWL_DEBUG_MAC80211("leave - not ready\n");
3505 mutex_unlock(&priv->mutex);
3506 return;
3507 }
3508
mabbas052c4b92007-10-25 17:15:43 +08003509 /* we are restarting association process
3510 * clear RXON_FILTER_ASSOC_MSK bit
3511 */
Johannes Berg05c914f2008-09-11 00:01:58 +02003512 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003513 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08003514 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003515 iwl4965_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08003516 }
3517
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003518 iwl_power_update_mode(priv, 0);
3519
Zhu Yib481de92007-09-25 17:54:57 -07003520 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02003521 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
mabbas052c4b92007-10-25 17:15:43 +08003522
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08003523 /* switch to CAM during association period.
3524 * the ucode will block any association/authentication
3525 * frome during assiciation period if it can not hear
3526 * the AP because of PM. the timer enable PM back is
3527 * association do not complete
3528 */
3529 if (priv->hw->conf.channel->flags & (IEEE80211_CHAN_PASSIVE_SCAN |
3530 IEEE80211_CHAN_RADAR))
3531 iwl_power_disable_management(priv, 3000);
3532
Zhu Yib481de92007-09-25 17:54:57 -07003533 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3534 mutex_unlock(&priv->mutex);
3535 return;
3536 }
3537
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003538 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003539
3540 mutex_unlock(&priv->mutex);
3541
3542 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003543}
3544
Johannes Berge039fa42008-05-15 12:55:29 +02003545static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003546{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003547 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003548 unsigned long flags;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003549 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07003550
3551 mutex_lock(&priv->mutex);
3552 IWL_DEBUG_MAC80211("enter\n");
3553
Tomas Winklerfee12472008-04-03 16:05:21 -07003554 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003555 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3556 mutex_unlock(&priv->mutex);
3557 return -EIO;
3558 }
3559
Johannes Berg05c914f2008-09-11 00:01:58 +02003560 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Zhu Yib481de92007-09-25 17:54:57 -07003561 IWL_DEBUG_MAC80211("leave - not IBSS\n");
3562 mutex_unlock(&priv->mutex);
3563 return -EIO;
3564 }
3565
3566 spin_lock_irqsave(&priv->lock, flags);
3567
3568 if (priv->ibss_beacon)
3569 dev_kfree_skb(priv->ibss_beacon);
3570
3571 priv->ibss_beacon = skb;
3572
3573 priv->assoc_id = 0;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003574 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
Assaf Kraussb94d8ee2008-09-03 11:18:42 +08003575 priv->timestamp = le64_to_cpu(timestamp);
Zhu Yib481de92007-09-25 17:54:57 -07003576
3577 IWL_DEBUG_MAC80211("leave\n");
3578 spin_unlock_irqrestore(&priv->lock, flags);
3579
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003580 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003581
Assaf Kraussc46fbef2008-06-12 09:47:05 +08003582 iwl4965_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003583
3584 mutex_unlock(&priv->mutex);
3585
3586 return 0;
3587}
3588
Zhu Yib481de92007-09-25 17:54:57 -07003589/*****************************************************************************
3590 *
3591 * sysfs attributes
3592 *
3593 *****************************************************************************/
3594
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003595#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003596
3597/*
3598 * The following adds a new attribute to the sysfs representation
3599 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3600 * used for controlling the debug level.
3601 *
3602 * See the level definitions in iwl for details.
3603 */
3604
Ester Kummer8cf769c2008-05-06 11:05:11 +08003605static ssize_t show_debug_level(struct device *d,
3606 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003607{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003608 struct iwl_priv *priv = d->driver_data;
3609
3610 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003611}
Ester Kummer8cf769c2008-05-06 11:05:11 +08003612static ssize_t store_debug_level(struct device *d,
3613 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003614 const char *buf, size_t count)
3615{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003616 struct iwl_priv *priv = d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003617 unsigned long val;
3618 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003619
Tomas Winkler9257746f2008-09-03 11:26:32 +08003620 ret = strict_strtoul(buf, 0, &val);
3621 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07003622 printk(KERN_INFO DRV_NAME
3623 ": %s is not in hex or decimal form.\n", buf);
3624 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08003625 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003626
3627 return strnlen(buf, count);
3628}
3629
Ester Kummer8cf769c2008-05-06 11:05:11 +08003630static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3631 show_debug_level, store_debug_level);
3632
Zhu Yib481de92007-09-25 17:54:57 -07003633
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003634#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003635
Zhu Yib481de92007-09-25 17:54:57 -07003636
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003637static ssize_t show_version(struct device *d,
3638 struct device_attribute *attr, char *buf)
3639{
3640 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08003641 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08003642 ssize_t pos = 0;
3643 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003644
3645 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08003646 pos += sprintf(buf + pos,
3647 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3648 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003649 palive->ucode_major, palive->ucode_minor,
3650 palive->sw_rev[0], palive->sw_rev[1],
3651 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003652 else
Tomas Winklerf236a262008-06-30 17:23:02 +08003653 pos += sprintf(buf + pos, "fw not loaded\n");
3654
3655 if (priv->eeprom) {
3656 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3657 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3658 eeprom_ver);
3659 } else {
3660 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3661 }
3662
3663 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003664}
3665
3666static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3667
Zhu Yib481de92007-09-25 17:54:57 -07003668static ssize_t show_temperature(struct device *d,
3669 struct device_attribute *attr, char *buf)
3670{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003671 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003672
Tomas Winklerfee12472008-04-03 16:05:21 -07003673 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003674 return -EAGAIN;
3675
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003676 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003677}
3678
3679static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3680
Zhu Yib481de92007-09-25 17:54:57 -07003681static ssize_t show_tx_power(struct device *d,
3682 struct device_attribute *attr, char *buf)
3683{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003684 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003685 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003686}
3687
3688static ssize_t store_tx_power(struct device *d,
3689 struct device_attribute *attr,
3690 const char *buf, size_t count)
3691{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003692 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003693 unsigned long val;
3694 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003695
Tomas Winkler9257746f2008-09-03 11:26:32 +08003696 ret = strict_strtoul(buf, 10, &val);
3697 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07003698 printk(KERN_INFO DRV_NAME
3699 ": %s is not in decimal form.\n", buf);
3700 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003701 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07003702
3703 return count;
3704}
3705
3706static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3707
3708static ssize_t show_flags(struct device *d,
3709 struct device_attribute *attr, char *buf)
3710{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003711 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003712
3713 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3714}
3715
3716static ssize_t store_flags(struct device *d,
3717 struct device_attribute *attr,
3718 const char *buf, size_t count)
3719{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003720 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003721 unsigned long val;
3722 u32 flags;
3723 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003724 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003725 return ret;
3726 flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003727
3728 mutex_lock(&priv->mutex);
3729 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3730 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003731 if (iwl_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07003732 IWL_WARNING("Could not cancel scan.\n");
3733 else {
Tomas Winkler9257746f2008-09-03 11:26:32 +08003734 IWL_DEBUG_INFO("Commit rxon.flags = 0x%04X\n", flags);
Zhu Yib481de92007-09-25 17:54:57 -07003735 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003736 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003737 }
3738 }
3739 mutex_unlock(&priv->mutex);
3740
3741 return count;
3742}
3743
3744static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3745
3746static ssize_t show_filter_flags(struct device *d,
3747 struct device_attribute *attr, char *buf)
3748{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003749 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003750
3751 return sprintf(buf, "0x%04X\n",
3752 le32_to_cpu(priv->active_rxon.filter_flags));
3753}
3754
3755static ssize_t store_filter_flags(struct device *d,
3756 struct device_attribute *attr,
3757 const char *buf, size_t count)
3758{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003759 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003760 unsigned long val;
3761 u32 filter_flags;
3762 int ret = strict_strtoul(buf, 0, &val);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003763 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003764 return ret;
3765 filter_flags = (u32)val;
Zhu Yib481de92007-09-25 17:54:57 -07003766
3767 mutex_lock(&priv->mutex);
3768 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3769 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003770 if (iwl_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07003771 IWL_WARNING("Could not cancel scan.\n");
3772 else {
3773 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3774 "0x%04X\n", filter_flags);
3775 priv->staging_rxon.filter_flags =
3776 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003777 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003778 }
3779 }
3780 mutex_unlock(&priv->mutex);
3781
3782 return count;
3783}
3784
3785static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3786 store_filter_flags);
3787
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003788#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003789
3790static ssize_t show_measurement(struct device *d,
3791 struct device_attribute *attr, char *buf)
3792{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003793 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003794 struct iwl4965_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003795 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003796 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003797 unsigned long flags;
3798
3799 spin_lock_irqsave(&priv->lock, flags);
3800 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3801 spin_unlock_irqrestore(&priv->lock, flags);
3802 return 0;
3803 }
3804 memcpy(&measure_report, &priv->measure_report, size);
3805 priv->measurement_status = 0;
3806 spin_unlock_irqrestore(&priv->lock, flags);
3807
3808 while (size && (PAGE_SIZE - len)) {
3809 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3810 PAGE_SIZE - len, 1);
3811 len = strlen(buf);
3812 if (PAGE_SIZE - len)
3813 buf[len++] = '\n';
3814
3815 ofs += 16;
3816 size -= min(size, 16U);
3817 }
3818
3819 return len;
3820}
3821
3822static ssize_t store_measurement(struct device *d,
3823 struct device_attribute *attr,
3824 const char *buf, size_t count)
3825{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003826 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003827 struct ieee80211_measurement_params params = {
3828 .channel = le16_to_cpu(priv->active_rxon.channel),
3829 .start_time = cpu_to_le64(priv->last_tsf),
3830 .duration = cpu_to_le16(1),
3831 };
3832 u8 type = IWL_MEASURE_BASIC;
3833 u8 buffer[32];
3834 u8 channel;
3835
3836 if (count) {
3837 char *p = buffer;
3838 strncpy(buffer, buf, min(sizeof(buffer), count));
3839 channel = simple_strtoul(p, NULL, 0);
3840 if (channel)
3841 params.channel = channel;
3842
3843 p = buffer;
3844 while (*p && *p != ' ')
3845 p++;
3846 if (*p)
3847 type = simple_strtoul(p + 1, NULL, 0);
3848 }
3849
3850 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3851 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003852 iwl4965_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07003853
3854 return count;
3855}
3856
3857static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3858 show_measurement, store_measurement);
Tomas Winkler4fc22b22008-07-21 18:54:42 +03003859#endif /* CONFIG_IWLAGN_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07003860
3861static ssize_t store_retry_rate(struct device *d,
3862 struct device_attribute *attr,
3863 const char *buf, size_t count)
3864{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003865 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler9257746f2008-09-03 11:26:32 +08003866 long val;
3867 int ret = strict_strtol(buf, 10, &val);
3868 if (!ret)
3869 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003870
Tomas Winkler9257746f2008-09-03 11:26:32 +08003871 priv->retry_rate = (val > 0) ? val : 1;
Zhu Yib481de92007-09-25 17:54:57 -07003872
3873 return count;
3874}
3875
3876static ssize_t show_retry_rate(struct device *d,
3877 struct device_attribute *attr, char *buf)
3878{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003879 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003880 return sprintf(buf, "%d", priv->retry_rate);
3881}
3882
3883static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3884 store_retry_rate);
3885
3886static ssize_t store_power_level(struct device *d,
3887 struct device_attribute *attr,
3888 const char *buf, size_t count)
3889{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003890 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003891 int ret;
Tomas Winkler9257746f2008-09-03 11:26:32 +08003892 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07003893
Tomas Winkler9257746f2008-09-03 11:26:32 +08003894
Zhu Yib481de92007-09-25 17:54:57 -07003895 mutex_lock(&priv->mutex);
3896
Tomas Winklerfee12472008-04-03 16:05:21 -07003897 if (!iwl_is_ready(priv)) {
Esti Kummer298df1f2008-07-18 13:52:58 +08003898 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07003899 goto out;
3900 }
3901
Tomas Winkler9257746f2008-09-03 11:26:32 +08003902 ret = strict_strtoul(buf, 10, &mode);
Emmanuel Grumbach926f0b22008-09-03 11:26:39 +08003903 if (ret)
Tomas Winkler9257746f2008-09-03 11:26:32 +08003904 goto out;
3905
Esti Kummer298df1f2008-07-18 13:52:58 +08003906 ret = iwl_power_set_user_mode(priv, mode);
3907 if (ret) {
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003908 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3909 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003910 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003911 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07003912
3913 out:
3914 mutex_unlock(&priv->mutex);
Esti Kummer298df1f2008-07-18 13:52:58 +08003915 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003916}
3917
Zhu Yib481de92007-09-25 17:54:57 -07003918static ssize_t show_power_level(struct device *d,
3919 struct device_attribute *attr, char *buf)
3920{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003921 struct iwl_priv *priv = dev_get_drvdata(d);
Esti Kummer298df1f2008-07-18 13:52:58 +08003922 int mode = priv->power_data.user_power_setting;
3923 int system = priv->power_data.system_power_setting;
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003924 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07003925 char *p = buf;
3926
Esti Kummer298df1f2008-07-18 13:52:58 +08003927 switch (system) {
3928 case IWL_POWER_SYS_AUTO:
3929 p += sprintf(p, "SYSTEM:auto");
Zhu Yib481de92007-09-25 17:54:57 -07003930 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003931 case IWL_POWER_SYS_AC:
3932 p += sprintf(p, "SYSTEM:ac");
Zhu Yib481de92007-09-25 17:54:57 -07003933 break;
Esti Kummer298df1f2008-07-18 13:52:58 +08003934 case IWL_POWER_SYS_BATTERY:
3935 p += sprintf(p, "SYSTEM:battery");
3936 break;
Zhu Yib481de92007-09-25 17:54:57 -07003937 }
Esti Kummer298df1f2008-07-18 13:52:58 +08003938
3939 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO)?"fixed":"auto");
3940 p += sprintf(p, "\tINDEX:%d", level);
3941 p += sprintf(p, "\n");
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003942 return p - buf + 1;
Zhu Yib481de92007-09-25 17:54:57 -07003943}
3944
3945static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3946 store_power_level);
3947
3948static ssize_t show_channels(struct device *d,
3949 struct device_attribute *attr, char *buf)
3950{
Ester Kummer5d72a1f2008-06-13 15:44:53 +08003951
3952 struct iwl_priv *priv = dev_get_drvdata(d);
3953 struct ieee80211_channel *channels = NULL;
3954 const struct ieee80211_supported_band *supp_band = NULL;
3955 int len = 0, i;
3956 int count = 0;
3957
3958 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
3959 return -EAGAIN;
3960
3961 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
3962 channels = supp_band->channels;
3963 count = supp_band->n_channels;
3964
3965 len += sprintf(&buf[len],
3966 "Displaying %d channels in 2.4GHz band "
3967 "(802.11bg):\n", count);
3968
3969 for (i = 0; i < count; i++)
3970 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3971 ieee80211_frequency_to_channel(
3972 channels[i].center_freq),
3973 channels[i].max_power,
3974 channels[i].flags & IEEE80211_CHAN_RADAR ?
3975 " (IEEE 802.11h required)" : "",
3976 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3977 || (channels[i].flags &
3978 IEEE80211_CHAN_RADAR)) ? "" :
3979 ", IBSS",
3980 channels[i].flags &
3981 IEEE80211_CHAN_PASSIVE_SCAN ?
3982 "passive only" : "active/passive");
3983
3984 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
3985 channels = supp_band->channels;
3986 count = supp_band->n_channels;
3987
3988 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
3989 "(802.11a):\n", count);
3990
3991 for (i = 0; i < count; i++)
3992 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3993 ieee80211_frequency_to_channel(
3994 channels[i].center_freq),
3995 channels[i].max_power,
3996 channels[i].flags & IEEE80211_CHAN_RADAR ?
3997 " (IEEE 802.11h required)" : "",
3998 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3999 || (channels[i].flags &
4000 IEEE80211_CHAN_RADAR)) ? "" :
4001 ", IBSS",
4002 channels[i].flags &
4003 IEEE80211_CHAN_PASSIVE_SCAN ?
4004 "passive only" : "active/passive");
4005
4006 return len;
Zhu Yib481de92007-09-25 17:54:57 -07004007}
4008
4009static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4010
4011static ssize_t show_statistics(struct device *d,
4012 struct device_attribute *attr, char *buf)
4013{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004014 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08004015 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004016 u32 len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004017 u8 *data = (u8 *)&priv->statistics;
Zhu Yib481de92007-09-25 17:54:57 -07004018 int rc = 0;
4019
Tomas Winklerfee12472008-04-03 16:05:21 -07004020 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004021 return -EAGAIN;
4022
4023 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07004024 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004025 mutex_unlock(&priv->mutex);
4026
4027 if (rc) {
4028 len = sprintf(buf,
4029 "Error sending statistics request: 0x%08X\n", rc);
4030 return len;
4031 }
4032
4033 while (size && (PAGE_SIZE - len)) {
4034 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4035 PAGE_SIZE - len, 1);
4036 len = strlen(buf);
4037 if (PAGE_SIZE - len)
4038 buf[len++] = '\n';
4039
4040 ofs += 16;
4041 size -= min(size, 16U);
4042 }
4043
4044 return len;
4045}
4046
4047static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4048
Zhu Yib481de92007-09-25 17:54:57 -07004049static ssize_t show_status(struct device *d,
4050 struct device_attribute *attr, char *buf)
4051{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004052 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winklerfee12472008-04-03 16:05:21 -07004053 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004054 return -EAGAIN;
4055 return sprintf(buf, "0x%08x\n", (int)priv->status);
4056}
4057
4058static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4059
Zhu Yib481de92007-09-25 17:54:57 -07004060/*****************************************************************************
4061 *
4062 * driver setup and teardown
4063 *
4064 *****************************************************************************/
4065
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004066static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004067{
4068 priv->workqueue = create_workqueue(DRV_NAME);
4069
4070 init_waitqueue_head(&priv->wait_command_queue);
4071
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004072 INIT_WORK(&priv->up, iwl4965_bg_up);
4073 INIT_WORK(&priv->restart, iwl4965_bg_restart);
4074 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004075 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
4076 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08004077 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08004078 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08004079 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
4080 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08004081
Tomas Winkler2a421b92008-06-12 09:47:10 +08004082 iwl_setup_scan_deferred_work(priv);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08004083 iwl_setup_power_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004084
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004085 if (priv->cfg->ops->lib->setup_deferred_work)
4086 priv->cfg->ops->lib->setup_deferred_work(priv);
4087
4088 init_timer(&priv->statistics_periodic);
4089 priv->statistics_periodic.data = (unsigned long)priv;
4090 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07004091
4092 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004093 iwl4965_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004094}
4095
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004096static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004097{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004098 if (priv->cfg->ops->lib->cancel_deferred_work)
4099 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004100
Joonwoo Park3ae6a052007-11-29 10:43:16 +09004101 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004102 cancel_delayed_work(&priv->scan_check);
Emmanuel Grumbachc90a74ba2008-09-03 11:26:50 +08004103 cancel_delayed_work_sync(&priv->set_power_save);
Zhu Yib481de92007-09-25 17:54:57 -07004104 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004105 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004106 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07004107}
4108
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004109static struct attribute *iwl4965_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004110 &dev_attr_channels.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004111 &dev_attr_flags.attr,
4112 &dev_attr_filter_flags.attr,
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004113#ifdef CONFIG_IWLAGN_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004114 &dev_attr_measurement.attr,
4115#endif
4116 &dev_attr_power_level.attr,
4117 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004118 &dev_attr_statistics.attr,
4119 &dev_attr_status.attr,
4120 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004121 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08004122#ifdef CONFIG_IWLWIFI_DEBUG
4123 &dev_attr_debug_level.attr,
4124#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08004125 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004126
4127 NULL
4128};
4129
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004130static struct attribute_group iwl4965_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004131 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004132 .attrs = iwl4965_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004133};
4134
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004135static struct ieee80211_ops iwl4965_hw_ops = {
4136 .tx = iwl4965_mac_tx,
4137 .start = iwl4965_mac_start,
4138 .stop = iwl4965_mac_stop,
4139 .add_interface = iwl4965_mac_add_interface,
4140 .remove_interface = iwl4965_mac_remove_interface,
4141 .config = iwl4965_mac_config,
4142 .config_interface = iwl4965_mac_config_interface,
4143 .configure_filter = iwl4965_configure_filter,
4144 .set_key = iwl4965_mac_set_key,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004145 .update_tkip_key = iwl4965_mac_update_tkip_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004146 .get_stats = iwl4965_mac_get_stats,
4147 .get_tx_stats = iwl4965_mac_get_tx_stats,
4148 .conf_tx = iwl4965_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004149 .reset_tsf = iwl4965_mac_reset_tsf,
Johannes Berg471b3ef2007-12-28 14:32:58 +01004150 .bss_info_changed = iwl4965_bss_info_changed,
Ron Rindjunsky9ab46172007-12-25 17:00:38 +02004151 .ampdu_action = iwl4965_mac_ampdu_action,
Tomas Winklercb43dc22008-09-03 11:26:23 +08004152 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004153};
4154
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004155static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004156{
4157 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004158 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004159 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08004160 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004161 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004162
Assaf Krauss316c30d2008-03-14 10:38:46 -07004163 /************************
4164 * 1. Allocating HW data
4165 ************************/
4166
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004167 /* Disabling hardware scan means that mac80211 will perform scans
4168 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004169 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08004170 if (cfg->mod_params->debug & IWL_DL_INFO)
4171 dev_printk(KERN_DEBUG, &(pdev->dev),
4172 "Disabling hw_scan\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004173 iwl4965_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004174 }
4175
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004176 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
4177 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07004178 err = -ENOMEM;
4179 goto out;
4180 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004181 priv = hw->priv;
4182 /* At this point both hw and priv are allocated. */
4183
Zhu Yib481de92007-09-25 17:54:57 -07004184 SET_IEEE80211_DEV(hw, &pdev->dev);
4185
4186 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08004187 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07004188 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004189
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004190#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08004191 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07004192 atomic_set(&priv->restrict_refcnt, 0);
4193#endif
Zhu Yib481de92007-09-25 17:54:57 -07004194
Assaf Krauss316c30d2008-03-14 10:38:46 -07004195 /**************************
4196 * 2. Initializing PCI bus
4197 **************************/
4198 if (pci_enable_device(pdev)) {
4199 err = -ENODEV;
4200 goto out_ieee80211_free_hw;
4201 }
4202
4203 pci_set_master(pdev);
4204
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004205 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(36));
Assaf Krauss316c30d2008-03-14 10:38:46 -07004206 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004207 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(36));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004208 if (err) {
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004209 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004210 if (!err)
Winkler, Tomas093d874c2008-09-26 15:09:34 +08004211 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004212 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004213 if (err) {
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004214 printk(KERN_WARNING "%s: No suitable DMA available.\n",
4215 DRV_NAME);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004216 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004217 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004218 }
4219
4220 err = pci_request_regions(pdev, DRV_NAME);
4221 if (err)
4222 goto out_pci_disable_device;
4223
4224 pci_set_drvdata(pdev, priv);
4225
Assaf Krauss316c30d2008-03-14 10:38:46 -07004226
4227 /***********************
4228 * 3. Read REV register
4229 ***********************/
4230 priv->hw_base = pci_iomap(pdev, 0, 0);
4231 if (!priv->hw_base) {
4232 err = -ENODEV;
4233 goto out_pci_release_regions;
4234 }
4235
4236 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
4237 (unsigned long long) pci_resource_len(pdev, 0));
4238 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
4239
Tomas Winklerb661c812008-04-23 17:14:54 -07004240 iwl_hw_detect(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004241 printk(KERN_INFO DRV_NAME
Tomas Winklerb661c812008-04-23 17:14:54 -07004242 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
4243 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004244
Tomas Winklere7b63582008-09-03 11:26:49 +08004245 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4246 * PCI Tx retries from interfering with C3 CPU state */
4247 pci_write_config_byte(pdev, PCI_CFG_RETRY_TIMEOUT, 0x00);
4248
Tomas Winkler91238712008-04-23 17:14:53 -07004249 /* amp init */
4250 err = priv->cfg->ops->lib->apm_ops.init(priv);
4251 if (err < 0) {
4252 IWL_DEBUG_INFO("Failed to init APMG\n");
4253 goto out_iounmap;
4254 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004255 /*****************
4256 * 4. Read EEPROM
4257 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07004258 /* Read the EEPROM */
4259 err = iwl_eeprom_init(priv);
4260 if (err) {
4261 IWL_ERROR("Unable to init EEPROM\n");
4262 goto out_iounmap;
4263 }
Tomas Winkler8614f362008-04-23 17:14:55 -07004264 err = iwl_eeprom_check_version(priv);
4265 if (err)
4266 goto out_iounmap;
4267
Ron Rindjunsky02883012008-05-15 13:53:53 +08004268 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004269 iwl_eeprom_get_mac(priv, priv->mac_addr);
Johannes Berge1749612008-10-27 15:59:26 -07004270 IWL_DEBUG_INFO("MAC address: %pM\n", priv->mac_addr);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004271 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4272
4273 /************************
4274 * 5. Setup HW constants
4275 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08004276 if (iwl_set_hw_params(priv)) {
Tomas Winkler5425e492008-04-15 16:01:38 -07004277 IWL_ERROR("failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07004278 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004279 }
4280
4281 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08004282 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07004283 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07004284
Tomas Winkler6ba87952008-05-15 13:54:17 +08004285 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004286 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07004287 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004288 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004289
4290 /**********************************
4291 * 7. Initialize module parameters
4292 **********************************/
4293
4294 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004295 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07004296 set_bit(STATUS_RF_KILL_SW, &priv->status);
4297 IWL_DEBUG_INFO("Radio disabled.\n");
4298 }
4299
Assaf Krauss316c30d2008-03-14 10:38:46 -07004300 /********************
4301 * 8. Setup services
4302 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004303 spin_lock_irqsave(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004304 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004305 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004306
4307 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4308 if (err) {
4309 IWL_ERROR("failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08004310 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004311 }
4312
Assaf Krauss316c30d2008-03-14 10:38:46 -07004313
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004314 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08004315 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004316
4317 /********************
4318 * 9. Conclude
4319 ********************/
Zhu Yi5a66926a2008-01-14 17:46:18 -08004320 pci_save_state(pdev);
4321 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004322
Tomas Winkler6ba87952008-05-15 13:54:17 +08004323 /**********************************
4324 * 10. Setup and register mac80211
4325 **********************************/
4326
4327 err = iwl_setup_mac(priv);
4328 if (err)
4329 goto out_remove_sysfs;
4330
4331 err = iwl_dbgfs_register(priv, DRV_NAME);
4332 if (err)
4333 IWL_ERROR("failed to create debugfs files\n");
4334
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004335 err = iwl_rfkill_init(priv);
4336 if (err)
4337 IWL_ERROR("Unable to initialize RFKILL system. "
4338 "Ignoring error: %d\n", err);
4339 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004340 return 0;
4341
Assaf Krauss316c30d2008-03-14 10:38:46 -07004342 out_remove_sysfs:
4343 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004344 out_uninit_drv:
4345 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004346 out_free_eeprom:
4347 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004348 out_iounmap:
4349 pci_iounmap(pdev, priv->hw_base);
4350 out_pci_release_regions:
4351 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004352 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07004353 out_pci_disable_device:
4354 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004355 out_ieee80211_free_hw:
4356 ieee80211_free_hw(priv->hw);
4357 out:
4358 return err;
4359}
4360
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004361static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004362{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004363 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004364 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004365
4366 if (!priv)
4367 return;
4368
4369 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4370
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004371 iwl_dbgfs_unregister(priv);
4372 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4373
Gregory Greenman0b124c32008-09-03 11:18:50 +08004374 /* ieee80211_unregister_hw call wil cause iwl4965_mac_stop to
4375 * to be called and iwl4965_down since we are removing the device
4376 * we need to set STATUS_EXIT_PENDING bit.
4377 */
4378 set_bit(STATUS_EXIT_PENDING, &priv->status);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004379 if (priv->mac80211_registered) {
4380 ieee80211_unregister_hw(priv->hw);
4381 priv->mac80211_registered = 0;
Gregory Greenman0b124c32008-09-03 11:18:50 +08004382 } else {
4383 iwl4965_down(priv);
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004384 }
4385
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004386 /* make sure we flush any pending irq or
4387 * tasklet for the driver
4388 */
4389 spin_lock_irqsave(&priv->lock, flags);
4390 iwl4965_disable_interrupts(priv);
4391 spin_unlock_irqrestore(&priv->lock, flags);
4392
4393 iwl_synchronize_irq(priv);
4394
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004395 iwl_rfkill_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004396 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004397
4398 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08004399 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08004400 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004401
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08004402 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004403 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004404
Zhu Yib481de92007-09-25 17:54:57 -07004405
Mohamed Abbas948c1712007-10-25 17:15:45 +08004406 /*netif_stop_queue(dev); */
4407 flush_workqueue(priv->workqueue);
4408
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004409 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004410 * priv->workqueue... so we can't take down the workqueue
4411 * until now... */
4412 destroy_workqueue(priv->workqueue);
4413 priv->workqueue = NULL;
4414
Zhu Yib481de92007-09-25 17:54:57 -07004415 pci_iounmap(pdev, priv->hw_base);
4416 pci_release_regions(pdev);
4417 pci_disable_device(pdev);
4418 pci_set_drvdata(pdev, NULL);
4419
Tomas Winkler6ba87952008-05-15 13:54:17 +08004420 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004421
4422 if (priv->ibss_beacon)
4423 dev_kfree_skb(priv->ibss_beacon);
4424
4425 ieee80211_free_hw(priv->hw);
4426}
4427
4428#ifdef CONFIG_PM
4429
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004430static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07004431{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004432 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004433
Zhu Yie655b9f2008-01-24 02:19:38 -08004434 if (priv->is_open) {
4435 set_bit(STATUS_IN_SUSPEND, &priv->status);
4436 iwl4965_mac_stop(priv->hw);
4437 priv->is_open = 1;
4438 }
Zhu Yib481de92007-09-25 17:54:57 -07004439
Zhu Yib481de92007-09-25 17:54:57 -07004440 pci_set_power_state(pdev, PCI_D3hot);
4441
Zhu Yib481de92007-09-25 17:54:57 -07004442 return 0;
4443}
4444
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004445static int iwl4965_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004446{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004447 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004448
Zhu Yib481de92007-09-25 17:54:57 -07004449 pci_set_power_state(pdev, PCI_D0);
Zhu Yib481de92007-09-25 17:54:57 -07004450
Zhu Yie655b9f2008-01-24 02:19:38 -08004451 if (priv->is_open)
4452 iwl4965_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004453
Zhu Yie655b9f2008-01-24 02:19:38 -08004454 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004455 return 0;
4456}
4457
4458#endif /* CONFIG_PM */
4459
4460/*****************************************************************************
4461 *
4462 * driver and module entry point
4463 *
4464 *****************************************************************************/
4465
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004466/* Hardware specific file defines the PCI IDs table for that hardware module */
4467static struct pci_device_id iwl_hw_card_ids[] = {
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004468#ifdef CONFIG_IWL4965
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004469 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4470 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler4fc22b22008-07-21 18:54:42 +03004471#endif /* CONFIG_IWL4965 */
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004472#ifdef CONFIG_IWL5000
Esti Kummer47408632008-07-11 11:53:30 +08004473 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
4474 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
4475 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
4476 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
4477 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
4478 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004479 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
Esti Kummer47408632008-07-11 11:53:30 +08004480 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4481 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
4482 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
Tomas Winklere96a8492008-09-11 11:45:20 +08004483/* 5350 WiFi/WiMax */
4484 {IWL_PCI_DEVICE(0x423A, 0x1001, iwl5350_agn_cfg)},
4485 {IWL_PCI_DEVICE(0x423A, 0x1021, iwl5350_agn_cfg)},
4486 {IWL_PCI_DEVICE(0x423B, 0x1011, iwl5350_agn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004487#endif /* CONFIG_IWL5000 */
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004488 {0}
4489};
4490MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4491
4492static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004493 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004494 .id_table = iwl_hw_card_ids,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004495 .probe = iwl4965_pci_probe,
4496 .remove = __devexit_p(iwl4965_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004497#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004498 .suspend = iwl4965_pci_suspend,
4499 .resume = iwl4965_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004500#endif
4501};
4502
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004503static int __init iwl4965_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004504{
4505
4506 int ret;
4507 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4508 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004509
Tomas Winklere227cea2008-07-18 13:53:05 +08004510 ret = iwlagn_rate_control_register();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004511 if (ret) {
4512 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
4513 return ret;
4514 }
4515
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004516 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004517 if (ret) {
4518 IWL_ERROR("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004519 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004520 }
Zhu Yib481de92007-09-25 17:54:57 -07004521
4522 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004523
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004524error_register:
Tomas Winklere227cea2008-07-18 13:53:05 +08004525 iwlagn_rate_control_unregister();
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004526 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004527}
4528
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004529static void __exit iwl4965_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004530{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004531 pci_unregister_driver(&iwl_driver);
Tomas Winklere227cea2008-07-18 13:53:05 +08004532 iwlagn_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004533}
4534
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004535module_exit(iwl4965_exit);
4536module_init(iwl4965_init);