blob: 7c7b1034b707c87aafa36c2d1f5921e43c9da5de [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>
32#include <linux/version.h>
33#include <linux/init.h>
34#include <linux/pci.h>
35#include <linux/dma-mapping.h>
36#include <linux/delay.h>
37#include <linux/skbuff.h>
38#include <linux/netdevice.h>
39#include <linux/wireless.h>
40#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070041#include <linux/etherdevice.h>
42#include <linux/if_arp.h>
43
Zhu Yib481de92007-09-25 17:54:57 -070044#include <net/mac80211.h>
45
46#include <asm/div64.h>
47
Assaf Krauss6bc913b2008-03-11 16:17:18 -070048#include "iwl-eeprom.h"
Tomas Winkler3e0d4cb2008-04-24 11:55:38 -070049#include "iwl-dev.h"
Tomas Winklerfee12472008-04-03 16:05:21 -070050#include "iwl-core.h"
Tomas Winkler3395f6e2008-03-25 16:33:37 -070051#include "iwl-io.h"
Zhu Yib481de92007-09-25 17:54:57 -070052#include "iwl-helpers.h"
Emmanuel Grumbach6974e362008-04-14 21:16:06 -070053#include "iwl-sta.h"
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -070054#include "iwl-calib.h"
Zhu Yib481de92007-09-25 17:54:57 -070055
Christoph Hellwig416e1432007-10-25 17:15:49 +080056
Zhu Yib481de92007-09-25 17:54:57 -070057/******************************************************************************
58 *
59 * module boiler plate
60 *
61 ******************************************************************************/
62
Zhu Yib481de92007-09-25 17:54:57 -070063/*
64 * module name, copyright, version, etc.
65 * NOTE: DRV_NAME is defined in iwlwifi.h for use by iwl-debug.h and printk
66 */
67
68#define DRV_DESCRIPTION "Intel(R) Wireless WiFi Link 4965AGN driver for Linux"
69
Tomas Winkler0a6857e2008-03-12 16:58:49 -070070#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070071#define VD "d"
72#else
73#define VD
74#endif
75
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080076#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070077#define VS "s"
78#else
79#define VS
80#endif
81
Tomas Winklerdf48c322008-03-06 10:40:19 -080082#define DRV_VERSION IWLWIFI_VERSION VD VS
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
87MODULE_AUTHOR(DRV_COPYRIGHT);
88MODULE_LICENSE("GPL");
89
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/**
Ben Cahill9fbab512007-11-29 11:09:47 +0800184 * iwl4965_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 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700191static int iwl4965_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) ||
210 (priv->staging_rxon.rx_chain != priv->active_rxon.rx_chain) ||
211 (priv->staging_rxon.assoc_id != priv->active_rxon.assoc_id))
212 return 1;
213
214 /* flags, filter_flags, ofdm_basic_rates, and cck_basic_rates can
215 * be updated with the RXON_ASSOC command -- however only some
216 * flag transitions are allowed using RXON_ASSOC */
217
218 /* Check if we are not switching bands */
219 if ((priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) !=
220 (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK))
221 return 1;
222
223 /* Check if we are switching association toggle */
224 if ((priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK) !=
225 (priv->active_rxon.filter_flags & RXON_FILTER_ASSOC_MSK))
226 return 1;
227
228 return 0;
229}
230
Zhu Yib481de92007-09-25 17:54:57 -0700231/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800232 * iwl4965_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700233 *
Ian Schram01ebd062007-10-25 17:15:22 +0800234 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700235 * the active_rxon structure is updated with the new data. This
236 * function correctly transitions out of the RXON_ASSOC_MSK state if
237 * a HW tune is required based on the RXON structure changes.
238 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700239static int iwl4965_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700240{
241 /* cast away the const for active_rxon in this function */
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800242 struct iwl_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
Joe Perches0795af52007-10-03 17:59:30 -0700243 DECLARE_MAC_BUF(mac);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800244 int ret;
245 bool new_assoc =
246 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700247
Tomas Winklerfee12472008-04-03 16:05:21 -0700248 if (!iwl_is_alive(priv))
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800249 return -EBUSY;
Zhu Yib481de92007-09-25 17:54:57 -0700250
251 /* always get timestamp with Rx frame */
252 priv->staging_rxon.flags |= RXON_FLG_TSF2HOST_MSK;
253
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800254 ret = iwl4965_check_rxon_cmd(&priv->staging_rxon);
255 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700256 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
257 return -EINVAL;
258 }
259
260 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800261 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700262 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800263 if (!iwl4965_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800264 ret = iwl_send_rxon_assoc(priv);
265 if (ret) {
266 IWL_ERROR("Error setting RXON_ASSOC (%d)\n", ret);
267 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700268 }
269
270 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700271 return 0;
272 }
273
274 /* station table will be cleared */
275 priv->assoc_station_added = 0;
276
Zhu Yib481de92007-09-25 17:54:57 -0700277 /* If we are currently associated and the new config requires
278 * an RXON_ASSOC and the new config wants the associated mask enabled,
279 * we must clear the associated from the active configuration
280 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800281 if (iwl_is_associated(priv) && new_assoc) {
Zhu Yib481de92007-09-25 17:54:57 -0700282 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
283 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
284
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800285 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800286 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700287 &priv->active_rxon);
288
289 /* If the mask clearing failed then we set
290 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800291 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700292 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800293 IWL_ERROR("Error clearing ASSOC_MSK (%d)\n", ret);
294 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700295 }
Zhu Yib481de92007-09-25 17:54:57 -0700296 }
297
298 IWL_DEBUG_INFO("Sending RXON\n"
299 "* with%s RXON_FILTER_ASSOC_MSK\n"
300 "* channel = %d\n"
Joe Perches0795af52007-10-03 17:59:30 -0700301 "* bssid = %s\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800302 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700303 le16_to_cpu(priv->staging_rxon.channel),
Joe Perches0795af52007-10-03 17:59:30 -0700304 print_mac(mac, priv->staging_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -0700305
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700306 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800307
308 /* Apply the new configuration
309 * RXON unassoc clears the station table in uCode, send it before
310 * we add the bcast station. If assoc bit is set, we will send RXON
311 * after having added the bcast and bssid station.
312 */
313 if (!new_assoc) {
314 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800315 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800316 if (ret) {
317 IWL_ERROR("Error setting new RXON (%d)\n", ret);
318 return ret;
319 }
320 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700321 }
322
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800323 iwl_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800324
Zhu Yib481de92007-09-25 17:54:57 -0700325 if (!priv->error_recovering)
326 priv->start_calib = 0;
327
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700328 iwl_init_sensitivity(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700329
Zhu Yib481de92007-09-25 17:54:57 -0700330 /* If we issue a new RXON command which required a tune then we must
331 * send a new TXPOWER command or we won't be able to Tx any frames */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800332 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
333 if (ret) {
334 IWL_ERROR("Error sending TX power (%d)\n", ret);
335 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700336 }
337
338 /* Add the broadcast address so we can send broadcast frames */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800339 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800340 IWL_INVALID_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700341 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
342 return -EIO;
343 }
344
345 /* If we have set the ASSOC_MSK and we are in BSS mode then
346 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800347 if (new_assoc) {
348 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
349 ret = iwl_rxon_add_station(priv,
350 priv->active_rxon.bssid_addr, 1);
351 if (ret == IWL_INVALID_STATION) {
352 IWL_ERROR("Error adding AP address for TX.\n");
353 return -EIO;
354 }
355 priv->assoc_station_added = 1;
356 if (priv->default_wep_key &&
357 iwl_send_static_wepkey_cmd(priv, 0))
358 IWL_ERROR("Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700359 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800360
361 /* Apply the new configuration
362 * RXON assoc doesn't clear the station table in uCode,
363 */
364 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
365 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
366 if (ret) {
367 IWL_ERROR("Error setting new RXON (%d)\n", ret);
368 return ret;
369 }
370 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700371 }
372
373 return 0;
374}
375
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700376void iwl4965_update_chain_flags(struct iwl_priv *priv)
377{
378
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700379 iwl_set_rxon_chain(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700380 iwl4965_commit_rxon(priv);
381}
382
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700383static int iwl4965_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700384{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800385 struct iwl4965_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700386 .flags = 3,
387 .lead_time = 0xAA,
388 .max_kill = 1,
389 .kill_ack_mask = 0,
390 .kill_cts_mask = 0,
391 };
392
Tomas Winkler857485c2008-03-21 13:53:44 -0700393 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800394 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700395}
396
Tomas Winklerfcab4232008-05-15 13:54:01 +0800397static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700398{
399 struct list_head *element;
400
401 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
402 priv->frames_count);
403
404 while (!list_empty(&priv->free_frames)) {
405 element = priv->free_frames.next;
406 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800407 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700408 priv->frames_count--;
409 }
410
411 if (priv->frames_count) {
412 IWL_WARNING("%d frames still in use. Did we lose one?\n",
413 priv->frames_count);
414 priv->frames_count = 0;
415 }
416}
417
Tomas Winklerfcab4232008-05-15 13:54:01 +0800418static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700419{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800420 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700421 struct list_head *element;
422 if (list_empty(&priv->free_frames)) {
423 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
424 if (!frame) {
425 IWL_ERROR("Could not allocate frame!\n");
426 return NULL;
427 }
428
429 priv->frames_count++;
430 return frame;
431 }
432
433 element = priv->free_frames.next;
434 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800435 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700436}
437
Tomas Winklerfcab4232008-05-15 13:54:01 +0800438static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700439{
440 memset(frame, 0, sizeof(*frame));
441 list_add(&frame->list, &priv->free_frames);
442}
443
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700444unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700445 struct ieee80211_hdr *hdr,
446 const u8 *dest, int left)
447{
448
Tomas Winkler3109ece2008-03-28 16:33:35 -0700449 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Zhu Yib481de92007-09-25 17:54:57 -0700450 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
451 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
452 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
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700487static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700488{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800489 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700490 unsigned int frame_size;
491 int rc;
492 u8 rate;
493
Tomas Winklerfcab4232008-05-15 13:54:01 +0800494 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700495
496 if (!frame) {
497 IWL_ERROR("Could not obtain free frame buffer for beacon "
498 "command.\n");
499 return -ENOMEM;
500 }
501
Guy Cohen39e88502008-04-23 17:14:57 -0700502 rate = iwl4965_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700503
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800504 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700505
Tomas Winkler857485c2008-03-21 13:53:44 -0700506 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700507 &frame->u.cmd[0]);
508
Tomas Winklerfcab4232008-05-15 13:54:01 +0800509 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700510
511 return rc;
512}
513
514/******************************************************************************
515 *
Zhu Yib481de92007-09-25 17:54:57 -0700516 * Misc. internal state and helper functions
517 *
518 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700519
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700520static void iwl4965_ht_conf(struct iwl_priv *priv,
521 struct ieee80211_bss_conf *bss_conf)
522{
523 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
524 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
525 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
526
527 IWL_DEBUG_MAC80211("enter: \n");
528
529 iwl_conf->is_ht = bss_conf->assoc_ht;
530
531 if (!iwl_conf->is_ht)
532 return;
533
534 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
535
536 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800537 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700538 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800539 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700540
541 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
542 iwl_conf->max_amsdu_size =
543 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
544
545 iwl_conf->supported_chan_width =
546 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
547 iwl_conf->extension_chan_offset =
548 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
549 /* If no above or below channel supplied disable FAT channel */
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800550 if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE &&
551 iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) {
552 iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700553 iwl_conf->supported_chan_width = 0;
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800554 }
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700555
556 iwl_conf->tx_mimo_ps_mode =
557 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
558 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
559
560 iwl_conf->control_channel = ht_bss_conf->primary_channel;
561 iwl_conf->tx_chan_width =
562 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
563 iwl_conf->ht_protection =
564 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
565 iwl_conf->non_GF_STA_present =
566 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
567
568 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
569 IWL_DEBUG_MAC80211("leave\n");
570}
571
Zhu Yib481de92007-09-25 17:54:57 -0700572/*
573 * QoS support
574*/
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700575static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800576 struct iwl4965_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700577{
578
Tomas Winkler857485c2008-03-21 13:53:44 -0700579 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800580 sizeof(struct iwl4965_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700581}
582
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700583static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700584{
585 unsigned long flags;
586
Zhu Yib481de92007-09-25 17:54:57 -0700587 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
588 return;
589
590 if (!priv->qos_data.qos_enable)
591 return;
592
593 spin_lock_irqsave(&priv->lock, flags);
594 priv->qos_data.def_qos_parm.qos_flags = 0;
595
596 if (priv->qos_data.qos_cap.q_AP.queue_request &&
597 !priv->qos_data.qos_cap.q_AP.txop_request)
598 priv->qos_data.def_qos_parm.qos_flags |=
599 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700600 if (priv->qos_data.qos_active)
601 priv->qos_data.def_qos_parm.qos_flags |=
602 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
603
Ron Rindjunskyfd105e72007-11-26 16:14:39 +0200604 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800605 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800606
Zhu Yib481de92007-09-25 17:54:57 -0700607 spin_unlock_irqrestore(&priv->lock, flags);
608
Tomas Winkler3109ece2008-03-28 16:33:35 -0700609 if (force || iwl_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800610 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
611 priv->qos_data.qos_active,
612 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700613
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800614 iwl4965_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700615 &(priv->qos_data.def_qos_parm));
616 }
617}
618
Zhu Yib481de92007-09-25 17:54:57 -0700619#define MAX_UCODE_BEACON_INTERVAL 4096
620#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
621
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800622static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700623{
624 u16 new_val = 0;
625 u16 beacon_factor = 0;
626
627 beacon_factor =
628 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
629 / MAX_UCODE_BEACON_INTERVAL;
630 new_val = beacon_val / beacon_factor;
631
632 return cpu_to_le16(new_val);
633}
634
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700635static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700636{
637 u64 interval_tm_unit;
638 u64 tsf, result;
639 unsigned long flags;
640 struct ieee80211_conf *conf = NULL;
641 u16 beacon_int = 0;
642
643 conf = ieee80211_get_hw_conf(priv->hw);
644
645 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3109ece2008-03-28 16:33:35 -0700646 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
647 priv->rxon_timing.timestamp.dw[0] =
648 cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -0700649
650 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
651
Tomas Winkler3109ece2008-03-28 16:33:35 -0700652 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700653
654 beacon_int = priv->beacon_int;
655 spin_unlock_irqrestore(&priv->lock, flags);
656
657 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
658 if (beacon_int == 0) {
659 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
660 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
661 } else {
662 priv->rxon_timing.beacon_interval =
663 cpu_to_le16(beacon_int);
664 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800665 iwl4965_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700666 le16_to_cpu(priv->rxon_timing.beacon_interval));
667 }
668
669 priv->rxon_timing.atim_window = 0;
670 } else {
671 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800672 iwl4965_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700673 /* TODO: we need to get atim_window from upper stack
674 * for now we set to 0 */
675 priv->rxon_timing.atim_window = 0;
676 }
677
678 interval_tm_unit =
679 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
680 result = do_div(tsf, interval_tm_unit);
681 priv->rxon_timing.beacon_init_val =
682 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
683
684 IWL_DEBUG_ASSOC
685 ("beacon interval %d beacon timer %d beacon tim %d\n",
686 le16_to_cpu(priv->rxon_timing.beacon_interval),
687 le32_to_cpu(priv->rxon_timing.beacon_init_val),
688 le16_to_cpu(priv->rxon_timing.atim_window));
689}
690
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800691static void iwl_set_flags_for_band(struct iwl_priv *priv,
692 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -0700693{
Johannes Berg8318d782008-01-24 19:38:38 +0100694 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -0700695 priv->staging_rxon.flags &=
696 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
697 | RXON_FLG_CCK_MSK);
698 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
699 } else {
Reinette Chatre508e32e2008-04-14 21:16:13 -0700700 /* Copied from iwl4965_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -0700701 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
702 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
703 else
704 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
705
706 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
707 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
708
709 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
710 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
711 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
712 }
713}
714
715/*
Ian Schram01ebd062007-10-25 17:15:22 +0800716 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -0700717 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700718static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700719{
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700720 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700721
722 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
723
724 switch (priv->iw_mode) {
725 case IEEE80211_IF_TYPE_AP:
726 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
727 break;
728
729 case IEEE80211_IF_TYPE_STA:
730 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
731 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
732 break;
733
734 case IEEE80211_IF_TYPE_IBSS:
735 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
736 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
737 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
738 RXON_FILTER_ACCEPT_GRP_MSK;
739 break;
740
741 case IEEE80211_IF_TYPE_MNTR:
742 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
743 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
744 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
745 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700746 default:
747 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
748 break;
Zhu Yib481de92007-09-25 17:54:57 -0700749 }
750
751#if 0
752 /* TODO: Figure out when short_preamble would be set and cache from
753 * that */
754 if (!hw_to_local(priv->hw)->short_preamble)
755 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
756 else
757 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
758#endif
759
Assaf Krauss8622e702008-03-21 13:53:43 -0700760 ch_info = iwl_get_channel_info(priv, priv->band,
Zhu Yib481de92007-09-25 17:54:57 -0700761 le16_to_cpu(priv->staging_rxon.channel));
762
763 if (!ch_info)
764 ch_info = &priv->channel_info[0];
765
766 /*
767 * in some case A channels are all non IBSS
768 * in this case force B/G channel
769 */
770 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
771 !(is_channel_ibss(ch_info)))
772 ch_info = &priv->channel_info[0];
773
774 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100775 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -0700776
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800777 iwl_set_flags_for_band(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -0700778
779 priv->staging_rxon.ofdm_basic_rates =
780 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
781 priv->staging_rxon.cck_basic_rates =
782 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
783
784 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
785 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
786 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
787 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
788 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
789 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700790 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700791}
792
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700793static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700794{
Zhu Yib481de92007-09-25 17:54:57 -0700795 priv->iw_mode = mode;
796
Assaf Krauss398f9e72008-06-12 09:47:06 +0800797 /* init channel/phymode to values given at driver init */
798 iwl_set_rxon_channel(priv, IEEE80211_BAND_2GHZ, 6);
799
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800800 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700801 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
802
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800803 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700804
Mohamed Abbasfde35712007-11-29 11:10:15 +0800805 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -0700806 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800807 return -EAGAIN;
808
809 cancel_delayed_work(&priv->scan_check);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800810 if (iwl_scan_cancel_timeout(priv, 100)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +0800811 IWL_WARNING("Aborted scan still in progress after 100ms\n");
812 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
813 return -EAGAIN;
814 }
815
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800816 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700817
818 return 0;
819}
820
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700821static void iwl4965_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700822{
Johannes Berg8318d782008-01-24 19:38:38 +0100823 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700824 struct ieee80211_rate *rate;
825 int i;
826
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700827 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800828 if (!hw) {
829 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
830 return;
831 }
Zhu Yib481de92007-09-25 17:54:57 -0700832
833 priv->active_rate = 0;
834 priv->active_rate_basic = 0;
835
Johannes Berg8318d782008-01-24 19:38:38 +0100836 for (i = 0; i < hw->n_bitrates; i++) {
837 rate = &(hw->bitrates[i]);
838 if (rate->hw_value < IWL_RATE_COUNT)
839 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -0700840 }
841
842 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
843 priv->active_rate, priv->active_rate_basic);
844
845 /*
846 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
847 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
848 * OFDM
849 */
850 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
851 priv->staging_rxon.cck_basic_rates =
852 ((priv->active_rate_basic &
853 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
854 else
855 priv->staging_rxon.cck_basic_rates =
856 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
857
858 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
859 priv->staging_rxon.ofdm_basic_rates =
860 ((priv->active_rate_basic &
861 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
862 IWL_FIRST_OFDM_RATE) & 0xFF;
863 else
864 priv->staging_rxon.ofdm_basic_rates =
865 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
866}
867
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800868#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -0700869
870#include "iwl-spectrum.h"
871
872#define BEACON_TIME_MASK_LOW 0x00FFFFFF
873#define BEACON_TIME_MASK_HIGH 0xFF000000
874#define TIME_UNIT 1024
875
876/*
877 * extended beacon time format
878 * time in usec will be changed into a 32-bit value in 8:24 format
879 * the high 1 byte is the beacon counts
880 * the lower 3 bytes is the time in usec within one beacon interval
881 */
882
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800883static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700884{
885 u32 quot;
886 u32 rem;
887 u32 interval = beacon_interval * 1024;
888
889 if (!interval || !usec)
890 return 0;
891
892 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
893 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
894
895 return (quot << 24) + rem;
896}
897
898/* base is usually what we get from ucode with each received frame,
899 * the same as HW timer counter counting down
900 */
901
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800902static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700903{
904 u32 base_low = base & BEACON_TIME_MASK_LOW;
905 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
906 u32 interval = beacon_interval * TIME_UNIT;
907 u32 res = (base & BEACON_TIME_MASK_HIGH) +
908 (addon & BEACON_TIME_MASK_HIGH);
909
910 if (base_low > addon_low)
911 res += base_low - addon_low;
912 else if (base_low < addon_low) {
913 res += interval + base_low - addon_low;
914 res += (1 << 24);
915 } else
916 res += (1 << 24);
917
918 return cpu_to_le32(res);
919}
920
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700921static int iwl4965_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700922 struct ieee80211_measurement_params *params,
923 u8 type)
924{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800925 struct iwl4965_spectrum_cmd spectrum;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800926 struct iwl_rx_packet *res;
Tomas Winkler857485c2008-03-21 13:53:44 -0700927 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700928 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
929 .data = (void *)&spectrum,
930 .meta.flags = CMD_WANT_SKB,
931 };
932 u32 add_time = le64_to_cpu(params->start_time);
933 int rc;
934 int spectrum_resp_status;
935 int duration = le16_to_cpu(params->duration);
936
Tomas Winkler3109ece2008-03-28 16:33:35 -0700937 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700938 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800939 iwl4965_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -0700940 le64_to_cpu(params->start_time) - priv->last_tsf,
941 le16_to_cpu(priv->rxon_timing.beacon_interval));
942
943 memset(&spectrum, 0, sizeof(spectrum));
944
945 spectrum.channel_count = cpu_to_le16(1);
946 spectrum.flags =
947 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
948 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
949 cmd.len = sizeof(spectrum);
950 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
951
Tomas Winkler3109ece2008-03-28 16:33:35 -0700952 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700953 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800954 iwl4965_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -0700955 add_time,
956 le16_to_cpu(priv->rxon_timing.beacon_interval));
957 else
958 spectrum.start_time = 0;
959
960 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
961 spectrum.channels[0].channel = params->channel;
962 spectrum.channels[0].type = type;
963 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
964 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
965 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
966
Tomas Winkler857485c2008-03-21 13:53:44 -0700967 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700968 if (rc)
969 return rc;
970
Tomas Winklerdb11d632008-05-05 10:22:33 +0800971 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700972 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
973 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
974 rc = -EIO;
975 }
976
977 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
978 switch (spectrum_resp_status) {
979 case 0: /* Command will be handled */
980 if (res->u.spectrum.id != 0xff) {
981 IWL_DEBUG_INFO
982 ("Replaced existing measurement: %d\n",
983 res->u.spectrum.id);
984 priv->measurement_status &= ~MEASUREMENT_READY;
985 }
986 priv->measurement_status |= MEASUREMENT_ACTIVE;
987 rc = 0;
988 break;
989
990 case 1: /* Command will not be handled */
991 rc = -EAGAIN;
992 break;
993 }
994
995 dev_kfree_skb_any(cmd.meta.u.skb);
996
997 return rc;
998}
999#endif
1000
Zhu Yib481de92007-09-25 17:54:57 -07001001/******************************************************************************
1002 *
1003 * Generic RX handler implementations
1004 *
1005 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +08001006static void iwl_rx_reply_alive(struct iwl_priv *priv,
1007 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001008{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001009 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +08001010 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001011 struct delayed_work *pwork;
1012
1013 palive = &pkt->u.alive_frame;
1014
1015 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1016 "0x%01X 0x%01X\n",
1017 palive->is_valid, palive->ver_type,
1018 palive->ver_subtype);
1019
1020 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1021 IWL_DEBUG_INFO("Initialization Alive received.\n");
1022 memcpy(&priv->card_alive_init,
1023 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001024 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001025 pwork = &priv->init_alive_start;
1026 } else {
1027 IWL_DEBUG_INFO("Runtime Alive received.\n");
1028 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001029 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001030 pwork = &priv->alive_start;
1031 }
1032
1033 /* We delay the ALIVE response by 5ms to
1034 * give the HW RF Kill time to activate... */
1035 if (palive->is_valid == UCODE_VALID_OK)
1036 queue_delayed_work(priv->workqueue, pwork,
1037 msecs_to_jiffies(5));
1038 else
1039 IWL_WARNING("uCode did not respond OK.\n");
1040}
1041
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001042static void iwl4965_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001043 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001044{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001045 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001046
1047 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1048 "seq 0x%04X ser 0x%08X\n",
1049 le32_to_cpu(pkt->u.err_resp.error_type),
1050 get_cmd_string(pkt->u.err_resp.cmd_id),
1051 pkt->u.err_resp.cmd_id,
1052 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1053 le32_to_cpu(pkt->u.err_resp.error_info));
1054}
1055
1056#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1057
Tomas Winklera55360e2008-05-05 10:22:28 +08001058static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001059{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001060 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001061 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001062 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001063 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1064 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1065 rxon->channel = csa->channel;
1066 priv->staging_rxon.channel = csa->channel;
1067}
1068
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001069static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001070 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001071{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001072#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Tomas Winklerdb11d632008-05-05 10:22:33 +08001073 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001074 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001075
1076 if (!report->state) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001077 IWL_DEBUG(IWL_DL_11H,
1078 "Spectrum Measure Notification: Start\n");
Zhu Yib481de92007-09-25 17:54:57 -07001079 return;
1080 }
1081
1082 memcpy(&priv->measure_report, report, sizeof(*report));
1083 priv->measurement_status |= MEASUREMENT_READY;
1084#endif
1085}
1086
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001087static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001088 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001089{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001090#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001091 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001092 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001093 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1094 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1095#endif
1096}
1097
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001098static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001099 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001100{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001101 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001102 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1103 "notification for %s:\n",
1104 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001105 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001106}
1107
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001108static void iwl4965_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001109{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001110 struct iwl_priv *priv =
1111 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001112 struct sk_buff *beacon;
1113
1114 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001115 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001116
1117 if (!beacon) {
1118 IWL_ERROR("update beacon failed\n");
1119 return;
1120 }
1121
1122 mutex_lock(&priv->mutex);
1123 /* new beacon skb is allocated every time; dispose previous.*/
1124 if (priv->ibss_beacon)
1125 dev_kfree_skb(priv->ibss_beacon);
1126
1127 priv->ibss_beacon = beacon;
1128 mutex_unlock(&priv->mutex);
1129
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001130 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001131}
1132
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001133/**
1134 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
1135 *
1136 * This callback is provided in order to send a statistics request.
1137 *
1138 * This timer function is continually reset to execute within
1139 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1140 * was received. We need to ensure we receive the statistics in order
1141 * to update the temperature used for calibrating the TXPOWER.
1142 */
1143static void iwl4965_bg_statistics_periodic(unsigned long data)
1144{
1145 struct iwl_priv *priv = (struct iwl_priv *)data;
1146
1147 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1148 return;
1149
1150 iwl_send_statistics_request(priv, CMD_ASYNC);
1151}
1152
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001153static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001154 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001155{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001156#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001157 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001158 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
Tomas Winklere7d326a2008-06-12 09:47:11 +08001159 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001160
1161 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1162 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +08001163 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -07001164 beacon->beacon_notify_hdr.failure_frame,
1165 le32_to_cpu(beacon->ibss_mgr_status),
1166 le32_to_cpu(beacon->high_tsf),
1167 le32_to_cpu(beacon->low_tsf), rate);
1168#endif
1169
1170 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
1171 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1172 queue_work(priv->workqueue, &priv->beacon_update);
1173}
1174
Zhu Yib481de92007-09-25 17:54:57 -07001175/* Handle notification from uCode that card's power state is changing
1176 * due to software, hardware, or critical temperature RFKILL */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001177static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001178 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001179{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001180 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001181 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1182 unsigned long status = priv->status;
1183
1184 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1185 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1186 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1187
1188 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1189 RF_CARD_DISABLED)) {
1190
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001191 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001192 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1193
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001194 if (!iwl_grab_nic_access(priv)) {
1195 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001196 priv, HBUS_TARG_MBX_C,
1197 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1198
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001199 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001200 }
1201
1202 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001203 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001204 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001205 if (!iwl_grab_nic_access(priv)) {
1206 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001207 priv, HBUS_TARG_MBX_C,
1208 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1209
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001210 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001211 }
1212 }
1213
1214 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001215 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001216 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001217 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1218 if (!iwl_grab_nic_access(priv))
1219 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001220 }
1221 }
1222
1223 if (flags & HW_CARD_DISABLED)
1224 set_bit(STATUS_RF_KILL_HW, &priv->status);
1225 else
1226 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1227
1228
1229 if (flags & SW_CARD_DISABLED)
1230 set_bit(STATUS_RF_KILL_SW, &priv->status);
1231 else
1232 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1233
1234 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +08001235 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001236
1237 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1238 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1239 (test_bit(STATUS_RF_KILL_SW, &status) !=
1240 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1241 queue_work(priv->workqueue, &priv->rf_kill);
1242 else
1243 wake_up_interruptible(&priv->wait_command_queue);
1244}
1245
1246/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001247 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001248 *
1249 * Setup the RX handlers for each of the reply types sent from the uCode
1250 * to the host.
1251 *
1252 * This function chains into the hardware specific files for them to setup
1253 * any hardware specific handlers as well.
1254 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001255static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001256{
Tomas Winkler885ba202008-05-29 16:34:55 +08001257 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001258 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
1259 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07001260 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001261 iwl4965_rx_spectrum_measure_notif;
1262 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001263 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001264 iwl4965_rx_pm_debug_statistics_notif;
1265 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001266
Ben Cahill9fbab512007-11-29 11:09:47 +08001267 /*
1268 * The same handler is used for both the REPLY to a discrete
1269 * statistics request from the host as well as for the periodic
1270 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001271 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001272 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1273 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +08001274
1275 iwl_setup_rx_scan_handlers(priv);
1276
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001277 /* status change handler */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001278 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001279
Tomas Winklerc1354752008-05-29 16:35:04 +08001280 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1281 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001282 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +08001283 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1284 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001285 /* block ack */
1286 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001287 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001288 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001289}
1290
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001291/*
1292 * this should be called while priv->lock is locked
1293*/
Tomas Winklera55360e2008-05-05 10:22:28 +08001294static void __iwl_rx_replenish(struct iwl_priv *priv)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001295{
Tomas Winklera55360e2008-05-05 10:22:28 +08001296 iwl_rx_allocate(priv);
1297 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001298}
1299
1300
Zhu Yib481de92007-09-25 17:54:57 -07001301/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001302 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001303 *
1304 * Uses the priv->rx_handlers callback function array to invoke
1305 * the appropriate handlers, including command responses,
1306 * frame-received notifications, and other notifications.
1307 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001308void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001309{
Tomas Winklera55360e2008-05-05 10:22:28 +08001310 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001311 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001312 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001313 u32 r, i;
1314 int reclaim;
1315 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001316 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001317 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001318
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001319 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1320 * buffer that the driver may process (last buffer filled by ucode). */
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001321 r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001322 i = rxq->read;
1323
1324 /* Rx interrupt, but nothing sent from uCode */
1325 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08001326 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001327
Tomas Winklera55360e2008-05-05 10:22:28 +08001328 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001329 fill_rx = 1;
1330
Zhu Yib481de92007-09-25 17:54:57 -07001331 while (i != r) {
1332 rxb = rxq->queue[i];
1333
Ben Cahill9fbab512007-11-29 11:09:47 +08001334 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001335 * then a bug has been introduced in the queue refilling
1336 * routines -- catch it here */
1337 BUG_ON(rxb == NULL);
1338
1339 rxq->queue[i] = NULL;
1340
1341 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07001342 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001343 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08001344 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001345
1346 /* Reclaim a command buffer only if this packet is a response
1347 * to a (driver-originated) command.
1348 * If the packet (e.g. Rx frame) originated from uCode,
1349 * there is no command buffer to reclaim.
1350 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1351 * but apparently a few don't get set; catch them here. */
1352 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1353 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001354 (pkt->hdr.cmd != REPLY_RX) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001355 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001356 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1357 (pkt->hdr.cmd != REPLY_TX);
1358
1359 /* Based on type of command response or notification,
1360 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001361 * rx_handlers table. See iwl4965_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001362 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001363 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1364 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001365 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1366 } else {
1367 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08001368 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07001369 "r %d i %d No handler needed for %s, 0x%02x\n",
1370 r, i, get_cmd_string(pkt->hdr.cmd),
1371 pkt->hdr.cmd);
1372 }
1373
1374 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001375 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07001376 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001377 * as we reclaim the driver command queue */
1378 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +08001379 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001380 else
1381 IWL_WARNING("Claim null rxb?\n");
1382 }
1383
1384 /* For now we just don't re-use anything. We can tweak this
1385 * later to try and re-use notification packets and SKBs that
1386 * fail to Rx correctly */
1387 if (rxb->skb != NULL) {
1388 priv->alloc_rxb_skb--;
1389 dev_kfree_skb_any(rxb->skb);
1390 rxb->skb = NULL;
1391 }
1392
1393 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07001394 priv->hw_params.rx_buf_size,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001395 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001396 spin_lock_irqsave(&rxq->lock, flags);
1397 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1398 spin_unlock_irqrestore(&rxq->lock, flags);
1399 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001400 /* If there are a lot of unused frames,
1401 * restock the Rx queue so ucode wont assert. */
1402 if (fill_rx) {
1403 count++;
1404 if (count >= 8) {
1405 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001406 __iwl_rx_replenish(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001407 count = 0;
1408 }
1409 }
Zhu Yib481de92007-09-25 17:54:57 -07001410 }
1411
1412 /* Backtrack one entry */
1413 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001414 iwl_rx_queue_restock(priv);
1415}
Tomas Winklera55360e2008-05-05 10:22:28 +08001416
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001417#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001418static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001419{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001420 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001421 DECLARE_MAC_BUF(mac);
1422
Zhu Yib481de92007-09-25 17:54:57 -07001423 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08001424 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001425 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1426 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1427 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1428 le32_to_cpu(rxon->filter_flags));
1429 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1430 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1431 rxon->ofdm_basic_rates);
1432 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Joe Perches0795af52007-10-03 17:59:30 -07001433 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
1434 print_mac(mac, rxon->node_addr));
1435 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
1436 print_mac(mac, rxon->bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07001437 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1438}
1439#endif
1440
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001441static void iwl4965_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001442{
1443 IWL_DEBUG_ISR("Enabling interrupts\n");
1444 set_bit(STATUS_INT_ENABLED, &priv->status);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001445 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001446}
1447
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001448/* call this function to flush any scheduled tasklet */
1449static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1450{
1451 /* wait to make sure we flush pedding tasklet*/
1452 synchronize_irq(priv->pci_dev->irq);
1453 tasklet_kill(&priv->irq_tasklet);
1454}
1455
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001456static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001457{
1458 clear_bit(STATUS_INT_ENABLED, &priv->status);
1459
1460 /* disable interrupts from uCode/NIC to host */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001461 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001462
1463 /* acknowledge/clear/reset any interrupts still pending
1464 * from uCode or flow handler (Rx/Tx DMA) */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001465 iwl_write32(priv, CSR_INT, 0xffffffff);
1466 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07001467 IWL_DEBUG_ISR("Disabled interrupts\n");
1468}
1469
Zhu Yib481de92007-09-25 17:54:57 -07001470
Zhu Yib481de92007-09-25 17:54:57 -07001471/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001472 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07001473 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001474static void iwl4965_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001475{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001476 /* Set the FW error flag -- cleared on iwl4965_down */
Zhu Yib481de92007-09-25 17:54:57 -07001477 set_bit(STATUS_FW_ERROR, &priv->status);
1478
1479 /* Cancel currently queued command. */
1480 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1481
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001482#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001483 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08001484 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08001485 iwl_dump_nic_event_log(priv);
Ester Kummerbf403db2008-05-05 10:22:40 +08001486 iwl4965_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001487 }
1488#endif
1489
1490 wake_up_interruptible(&priv->wait_command_queue);
1491
1492 /* Keep the restart process from trying to send host
1493 * commands by clearing the INIT status bit */
1494 clear_bit(STATUS_READY, &priv->status);
1495
1496 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001497 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07001498 "Restarting adapter due to uCode error.\n");
1499
Tomas Winkler3109ece2008-03-28 16:33:35 -07001500 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001501 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1502 sizeof(priv->recovery_rxon));
1503 priv->error_recovering = 1;
1504 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08001505 if (priv->cfg->mod_params->restart_fw)
1506 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001507 }
1508}
1509
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001510static void iwl4965_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001511{
1512 unsigned long flags;
1513
1514 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1515 sizeof(priv->staging_rxon));
1516 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001517 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001518
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001519 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07001520
1521 spin_lock_irqsave(&priv->lock, flags);
1522 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1523 priv->error_recovering = 0;
1524 spin_unlock_irqrestore(&priv->lock, flags);
1525}
1526
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001527static void iwl4965_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001528{
1529 u32 inta, handled = 0;
1530 u32 inta_fh;
1531 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001532#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001533 u32 inta_mask;
1534#endif
1535
1536 spin_lock_irqsave(&priv->lock, flags);
1537
1538 /* Ack/clear/reset pending uCode interrupts.
1539 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1540 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001541 inta = iwl_read32(priv, CSR_INT);
1542 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001543
1544 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1545 * Any new interrupts that happen after this, either while we're
1546 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001547 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1548 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001549
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001550#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001551 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001552 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001553 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001554 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1555 inta, inta_mask, inta_fh);
1556 }
1557#endif
1558
1559 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1560 * atomic, make sure that inta covers all the interrupts that
1561 * we've discovered, even if FH interrupt came in just after
1562 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001563 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001564 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001565 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001566 inta |= CSR_INT_BIT_FH_TX;
1567
1568 /* Now service all interrupt bits discovered above. */
1569 if (inta & CSR_INT_BIT_HW_ERR) {
1570 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1571
1572 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001573 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001574
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001575 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001576
1577 handled |= CSR_INT_BIT_HW_ERR;
1578
1579 spin_unlock_irqrestore(&priv->lock, flags);
1580
1581 return;
1582 }
1583
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001584#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001585 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001586 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001587 if (inta & CSR_INT_BIT_SCD)
1588 IWL_DEBUG_ISR("Scheduler finished to transmit "
1589 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001590
1591 /* Alive notification via Rx interrupt will do the real work */
1592 if (inta & CSR_INT_BIT_ALIVE)
1593 IWL_DEBUG_ISR("Alive interrupt\n");
1594 }
1595#endif
1596 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001597 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001598
Ben Cahill9fbab512007-11-29 11:09:47 +08001599 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001600 if (inta & CSR_INT_BIT_RF_KILL) {
1601 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001602 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001603 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1604 hw_rf_kill = 1;
1605
Ester Kummerf3d67992008-05-06 11:05:12 +08001606 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Zhu Yib481de92007-09-25 17:54:57 -07001607 hw_rf_kill ? "disable radio":"enable radio");
1608
1609 /* Queue restart only if RF_KILL switch was set to "kill"
1610 * when we loaded driver, and is now set to "enable".
1611 * After we're Alive, RF_KILL gets handled by
Reinette Chatre32304552008-02-15 14:34:37 -08001612 * iwl4965_rx_card_state_notif() */
Zhu Yi53e49092007-12-06 16:08:44 +08001613 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status)) {
1614 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001615 queue_work(priv->workqueue, &priv->restart);
Zhu Yi53e49092007-12-06 16:08:44 +08001616 }
Zhu Yib481de92007-09-25 17:54:57 -07001617
1618 handled |= CSR_INT_BIT_RF_KILL;
1619 }
1620
Ben Cahill9fbab512007-11-29 11:09:47 +08001621 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001622 if (inta & CSR_INT_BIT_CT_KILL) {
1623 IWL_ERROR("Microcode CT kill error detected.\n");
1624 handled |= CSR_INT_BIT_CT_KILL;
1625 }
1626
1627 /* Error detected by uCode */
1628 if (inta & CSR_INT_BIT_SW_ERR) {
1629 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1630 inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001631 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001632 handled |= CSR_INT_BIT_SW_ERR;
1633 }
1634
1635 /* uCode wakes up after power-down sleep */
1636 if (inta & CSR_INT_BIT_WAKEUP) {
1637 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001638 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001639 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1640 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1641 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1642 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1643 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1644 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001645
1646 handled |= CSR_INT_BIT_WAKEUP;
1647 }
1648
1649 /* All uCode command responses, including Tx command responses,
1650 * Rx "responses" (frame-received notification), and other
1651 * notifications from uCode come through here*/
1652 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001653 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001654 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1655 }
1656
1657 if (inta & CSR_INT_BIT_FH_TX) {
1658 IWL_DEBUG_ISR("Tx interrupt\n");
1659 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001660 /* FH finished to write, send event */
1661 priv->ucode_write_complete = 1;
1662 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001663 }
1664
1665 if (inta & ~handled)
1666 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1667
1668 if (inta & ~CSR_INI_SET_MASK) {
1669 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
1670 inta & ~CSR_INI_SET_MASK);
1671 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
1672 }
1673
1674 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001675 /* only Re-enable if diabled by irq */
1676 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1677 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001678
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001679#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001680 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001681 inta = iwl_read32(priv, CSR_INT);
1682 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1683 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001684 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1685 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1686 }
1687#endif
1688 spin_unlock_irqrestore(&priv->lock, flags);
1689}
1690
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001691static irqreturn_t iwl4965_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07001692{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001693 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07001694 u32 inta, inta_mask;
1695 u32 inta_fh;
1696 if (!priv)
1697 return IRQ_NONE;
1698
1699 spin_lock(&priv->lock);
1700
1701 /* Disable (but don't clear!) interrupts here to avoid
1702 * back-to-back ISRs and sporadic interrupts from our NIC.
1703 * If we have something to service, the tasklet will re-enable ints.
1704 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001705 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1706 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001707
1708 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001709 inta = iwl_read32(priv, CSR_INT);
1710 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001711
1712 /* Ignore interrupt if there's nothing in NIC to service.
1713 * This may be due to IRQ shared with another device,
1714 * or due to sporadic interrupts thrown from our NIC. */
1715 if (!inta && !inta_fh) {
1716 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1717 goto none;
1718 }
1719
1720 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08001721 /* Hardware disappeared. It might have already raised
1722 * an interrupt */
Zhu Yib481de92007-09-25 17:54:57 -07001723 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08001724 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07001725 }
1726
1727 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1728 inta, inta_mask, inta_fh);
1729
Joonwoo Park25c03d82008-01-23 10:15:20 -08001730 inta &= ~CSR_INT_BIT_SCD;
1731
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001732 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001733 if (likely(inta || inta_fh))
1734 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07001735
Oliver Neukum66fbb542007-11-15 09:31:10 +08001736 unplugged:
1737 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07001738 return IRQ_HANDLED;
1739
1740 none:
1741 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001742 /* only Re-enable if diabled by irq */
1743 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1744 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001745 spin_unlock(&priv->lock);
1746 return IRQ_NONE;
1747}
1748
Zhu Yib481de92007-09-25 17:54:57 -07001749/******************************************************************************
1750 *
1751 * uCode download functions
1752 *
1753 ******************************************************************************/
1754
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001755static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001756{
Tomas Winkler98c92212008-01-14 17:46:20 -08001757 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1758 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1759 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1760 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1761 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1762 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001763}
1764
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001765static void iwl4965_nic_start(struct iwl_priv *priv)
1766{
1767 /* Remove all resets to allow NIC to operate */
1768 iwl_write32(priv, CSR_RESET, 0);
1769}
1770
1771
Zhu Yib481de92007-09-25 17:54:57 -07001772/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001773 * iwl4965_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001774 *
1775 * Copy into buffers for card to fetch via bus-mastering
1776 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001777static int iwl4965_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001778{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001779 struct iwl_ucode *ucode;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001780 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001781 const struct firmware *ucode_raw;
Tomas Winkler4bf775c2008-03-04 18:09:31 -08001782 const char *name = priv->cfg->fw_name;
Zhu Yib481de92007-09-25 17:54:57 -07001783 u8 *src;
1784 size_t len;
1785 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
1786
1787 /* Ask kernel firmware_class module to get the boot firmware off disk.
1788 * request_firmware() is synchronous, file is in memory on return. */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001789 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
1790 if (ret < 0) {
1791 IWL_ERROR("%s firmware file req failed: Reason %d\n",
1792 name, ret);
Zhu Yib481de92007-09-25 17:54:57 -07001793 goto error;
1794 }
1795
1796 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1797 name, ucode_raw->size);
1798
1799 /* Make sure that we got at least our header! */
1800 if (ucode_raw->size < sizeof(*ucode)) {
1801 IWL_ERROR("File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001802 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001803 goto err_release;
1804 }
1805
1806 /* Data from ucode file: header followed by uCode images */
1807 ucode = (void *)ucode_raw->data;
1808
1809 ver = le32_to_cpu(ucode->ver);
1810 inst_size = le32_to_cpu(ucode->inst_size);
1811 data_size = le32_to_cpu(ucode->data_size);
1812 init_size = le32_to_cpu(ucode->init_size);
1813 init_data_size = le32_to_cpu(ucode->init_data_size);
1814 boot_size = le32_to_cpu(ucode->boot_size);
1815
1816 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
1817 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1818 inst_size);
1819 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1820 data_size);
1821 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1822 init_size);
1823 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1824 init_data_size);
1825 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1826 boot_size);
1827
1828 /* Verify size of file vs. image size info in file's header */
1829 if (ucode_raw->size < sizeof(*ucode) +
1830 inst_size + data_size + init_size +
1831 init_data_size + boot_size) {
1832
1833 IWL_DEBUG_INFO("uCode file size %d too small\n",
1834 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001835 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001836 goto err_release;
1837 }
1838
1839 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001840 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001841 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1842 inst_size);
1843 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001844 goto err_release;
1845 }
1846
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001847 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001848 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1849 data_size);
1850 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001851 goto err_release;
1852 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001853 if (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001854 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001855 ("uCode init instr len %d too large to fit in\n",
1856 init_size);
1857 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001858 goto err_release;
1859 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001860 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001861 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001862 ("uCode init data len %d too large to fit in\n",
1863 init_data_size);
1864 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001865 goto err_release;
1866 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001867 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001868 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001869 ("uCode boot instr len %d too large to fit in\n",
1870 boot_size);
1871 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001872 goto err_release;
1873 }
1874
1875 /* Allocate ucode buffers for card's bus-master loading ... */
1876
1877 /* Runtime instructions and 2 copies of data:
1878 * 1) unmodified from disk
1879 * 2) backup cache for save/restore during power-downs */
1880 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001881 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001882
1883 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001884 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001885
1886 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001887 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001888
1889 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001890 if (init_size && init_data_size) {
1891 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001892 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001893
Tomas Winkler90e759d2007-11-29 11:09:41 +08001894 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001895 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001896
1897 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1898 goto err_pci_alloc;
1899 }
Zhu Yib481de92007-09-25 17:54:57 -07001900
1901 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001902 if (boot_size) {
1903 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001904 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001905
Tomas Winkler90e759d2007-11-29 11:09:41 +08001906 if (!priv->ucode_boot.v_addr)
1907 goto err_pci_alloc;
1908 }
Zhu Yib481de92007-09-25 17:54:57 -07001909
1910 /* Copy images into buffers for card's bus-master reads ... */
1911
1912 /* Runtime instructions (first block of data in file) */
1913 src = &ucode->data[0];
1914 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001915 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001916 memcpy(priv->ucode_code.v_addr, src, len);
1917 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1918 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1919
1920 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001921 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001922 src = &ucode->data[inst_size];
1923 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001924 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001925 memcpy(priv->ucode_data.v_addr, src, len);
1926 memcpy(priv->ucode_data_backup.v_addr, src, len);
1927
1928 /* Initialization instructions (3rd block) */
1929 if (init_size) {
1930 src = &ucode->data[inst_size + data_size];
1931 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001932 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1933 len);
Zhu Yib481de92007-09-25 17:54:57 -07001934 memcpy(priv->ucode_init.v_addr, src, len);
1935 }
1936
1937 /* Initialization data (4th block) */
1938 if (init_data_size) {
1939 src = &ucode->data[inst_size + data_size + init_size];
1940 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001941 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1942 len);
Zhu Yib481de92007-09-25 17:54:57 -07001943 memcpy(priv->ucode_init_data.v_addr, src, len);
1944 }
1945
1946 /* Bootstrap instructions (5th block) */
1947 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1948 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001949 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001950 memcpy(priv->ucode_boot.v_addr, src, len);
1951
1952 /* We have our copies now, allow OS release its copies */
1953 release_firmware(ucode_raw);
1954 return 0;
1955
1956 err_pci_alloc:
1957 IWL_ERROR("failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001958 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001959 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001960
1961 err_release:
1962 release_firmware(ucode_raw);
1963
1964 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001965 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001966}
1967
Zhu Yib481de92007-09-25 17:54:57 -07001968/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001969 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001970 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001971 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001972 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001973static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001974{
Tomas Winkler57aab752008-04-14 21:16:03 -07001975 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001976
1977 IWL_DEBUG_INFO("Runtime Alive received.\n");
1978
1979 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1980 /* We had an error bringing up the hardware, so take it
1981 * all the way back down so we can try again */
1982 IWL_DEBUG_INFO("Alive failed.\n");
1983 goto restart;
1984 }
1985
1986 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1987 * This is a paranoid check, because we would not have gotten the
1988 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001989 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001990 /* Runtime instruction load was bad;
1991 * take it all the way back down so we can try again */
1992 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
1993 goto restart;
1994 }
1995
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08001996 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001997 ret = priv->cfg->ops->lib->alive_notify(priv);
1998 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -07001999 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
Tomas Winkler57aab752008-04-14 21:16:03 -07002000 ret);
Zhu Yib481de92007-09-25 17:54:57 -07002001 goto restart;
2002 }
2003
Ben Cahill9fbab512007-11-29 11:09:47 +08002004 /* After the ALIVE response, we can send host commands to 4965 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002005 set_bit(STATUS_ALIVE, &priv->status);
2006
Tomas Winklerfee12472008-04-03 16:05:21 -07002007 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002008 return;
2009
Johannes Berg36d68252008-05-15 12:55:26 +02002010 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002011
2012 priv->active_rate = priv->rates_mask;
2013 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2014
Tomas Winkler3109ece2008-03-28 16:33:35 -07002015 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002016 struct iwl_rxon_cmd *active_rxon =
2017 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002018
2019 memcpy(&priv->staging_rxon, &priv->active_rxon,
2020 sizeof(priv->staging_rxon));
2021 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2022 } else {
2023 /* Initialize our rx_config data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002024 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002025 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2026 }
2027
Ben Cahill9fbab512007-11-29 11:09:47 +08002028 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002029 iwl4965_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002030
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002031 iwl_reset_run_time_calib(priv);
2032
Zhu Yib481de92007-09-25 17:54:57 -07002033 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002034 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002035
2036 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002037 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002038
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002039 iwl_leds_register(priv);
2040
Zhu Yib481de92007-09-25 17:54:57 -07002041 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002042 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002043 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002044
2045 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002046 iwl4965_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002047
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08002048 iwl_power_update_mode(priv, 1);
Mohamed Abbas84363e62008-04-04 16:59:58 -07002049 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002050
2051 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2052 iwl4965_set_mode(priv, priv->iw_mode);
2053
Zhu Yib481de92007-09-25 17:54:57 -07002054 return;
2055
2056 restart:
2057 queue_work(priv->workqueue, &priv->restart);
2058}
2059
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002060static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002061
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002062static void __iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002063{
2064 unsigned long flags;
2065 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002066
2067 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2068
Zhu Yib481de92007-09-25 17:54:57 -07002069 if (!exit_pending)
2070 set_bit(STATUS_EXIT_PENDING, &priv->status);
2071
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002072 iwl_leds_unregister(priv);
2073
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002074 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002075
2076 /* Unblock any waiting calls */
2077 wake_up_interruptible_all(&priv->wait_command_queue);
2078
Zhu Yib481de92007-09-25 17:54:57 -07002079 /* Wipe out the EXIT_PENDING status bit if we are not actually
2080 * exiting the module */
2081 if (!exit_pending)
2082 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2083
2084 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002085 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002086
2087 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002088 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002089 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002090 spin_unlock_irqrestore(&priv->lock, flags);
2091 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002092
2093 if (priv->mac80211_registered)
2094 ieee80211_stop_queues(priv->hw);
2095
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002096 /* If we have not previously called iwl4965_init() then
Zhu Yib481de92007-09-25 17:54:57 -07002097 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002098 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002099 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2100 STATUS_RF_KILL_HW |
2101 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2102 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002103 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2104 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002105 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002106 STATUS_IN_SUSPEND |
2107 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2108 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002109 goto exit;
2110 }
2111
2112 /* ...otherwise clear out all the status bits but the RF Kill and
2113 * SUSPEND bits and continue taking the NIC down. */
2114 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2115 STATUS_RF_KILL_HW |
2116 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2117 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002118 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2119 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002120 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2121 STATUS_IN_SUSPEND |
2122 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002123 STATUS_FW_ERROR |
2124 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2125 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002126
2127 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002128 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08002129 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002130 spin_unlock_irqrestore(&priv->lock, flags);
2131
Tomas Winklerda1bc452008-05-29 16:35:00 +08002132 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002133 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002134
2135 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002136 if (!iwl_grab_nic_access(priv)) {
2137 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002138 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002139 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002140 }
2141 spin_unlock_irqrestore(&priv->lock, flags);
2142
2143 udelay(5);
2144
Tomas Winkler7f066102008-05-29 16:34:57 +08002145 /* FIXME: apm_ops.suspend(priv) */
2146 priv->cfg->ops->lib->apm_ops.reset(priv);
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002147 priv->cfg->ops->lib->free_shared_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002148
2149 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002150 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002151
2152 if (priv->ibss_beacon)
2153 dev_kfree_skb(priv->ibss_beacon);
2154 priv->ibss_beacon = NULL;
2155
2156 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002157 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002158}
2159
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002160static void iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002161{
2162 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002163 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002164 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002165
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002166 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002167}
2168
2169#define MAX_HW_RESTARTS 5
2170
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002171static int __iwl4965_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002172{
Tomas Winkler57aab752008-04-14 21:16:03 -07002173 int i;
2174 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002175
2176 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2177 IWL_WARNING("Exit pending; will not bring the NIC up\n");
2178 return -EIO;
2179 }
2180
Reinette Chatree903fbd2008-01-30 22:05:15 -08002181 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
2182 IWL_ERROR("ucode not available for device bringup\n");
2183 return -EIO;
2184 }
2185
Zhu Yie655b9f2008-01-24 02:19:38 -08002186 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002187 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08002188 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2189 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002190 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002191 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002192
2193 if (!test_bit(STATUS_IN_SUSPEND, &priv->status) &&
2194 iwl_is_rfkill(priv)) {
2195 iwl_rfkill_set_hw_state(priv);
2196 IWL_WARNING("Radio disabled by %s RF Kill switch\n",
2197 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
2198 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07002199 }
2200
Mohamed Abbasad97edd2008-03-28 16:21:06 -07002201 iwl_rfkill_set_hw_state(priv);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002202 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002203
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002204 ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
2205 if (ret) {
2206 IWL_ERROR("Unable to allocate shared memory\n");
2207 return ret;
2208 }
2209
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002210 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002211 if (ret) {
2212 IWL_ERROR("Unable to init nic\n");
2213 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002214 }
2215
2216 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002217 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2218 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002219 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2220
2221 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002222 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002223 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002224
2225 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002226 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2227 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002228
2229 /* Copy original ucode data image from disk into backup cache.
2230 * This will be used to initialize the on-board processor's
2231 * data SRAM for a clean start when the runtime program first loads. */
2232 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002233 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002234
Zhu Yie655b9f2008-01-24 02:19:38 -08002235 /* We return success when we resume from suspend and rf_kill is on. */
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002236 if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
2237 test_bit(STATUS_RF_KILL_SW, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002238 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002239
2240 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2241
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002242 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002243
2244 /* load bootstrap state machine,
2245 * load bootstrap program into processor's memory,
2246 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002247 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002248
Tomas Winkler57aab752008-04-14 21:16:03 -07002249 if (ret) {
2250 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07002251 continue;
2252 }
2253
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08002254 /* Clear out the uCode error bit if it is set */
2255 clear_bit(STATUS_FW_ERROR, &priv->status);
2256
Zhu Yib481de92007-09-25 17:54:57 -07002257 /* start card; "initialize" will load runtime ucode */
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08002258 iwl4965_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002259
Zhu Yib481de92007-09-25 17:54:57 -07002260 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2261
2262 return 0;
2263 }
2264
2265 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002266 __iwl4965_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002267 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002268
2269 /* tried to restart and config the device for as long as our
2270 * patience could withstand */
2271 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
2272 return -EIO;
2273}
2274
2275
2276/*****************************************************************************
2277 *
2278 * Workqueue callbacks
2279 *
2280 *****************************************************************************/
2281
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002282static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002283{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002284 struct iwl_priv *priv =
2285 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002286
2287 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2288 return;
2289
2290 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002291 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002292 mutex_unlock(&priv->mutex);
2293}
2294
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002295static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002296{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002297 struct iwl_priv *priv =
2298 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002299
2300 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2301 return;
2302
2303 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002304 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002305 mutex_unlock(&priv->mutex);
2306}
2307
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002308static void iwl4965_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002309{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002310 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07002311
2312 wake_up_interruptible(&priv->wait_command_queue);
2313
2314 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2315 return;
2316
2317 mutex_lock(&priv->mutex);
2318
Tomas Winklerfee12472008-04-03 16:05:21 -07002319 if (!iwl_is_rfkill(priv)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08002320 IWL_DEBUG(IWL_DL_RF_KILL,
Zhu Yib481de92007-09-25 17:54:57 -07002321 "HW and/or SW RF Kill no longer active, restarting "
2322 "device\n");
2323 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
2324 queue_work(priv->workqueue, &priv->restart);
2325 } else {
Mohamed Abbasad97edd2008-03-28 16:21:06 -07002326 /* make sure mac80211 stop sending Tx frame */
2327 if (priv->mac80211_registered)
2328 ieee80211_stop_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002329
2330 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2331 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2332 "disabled by SW switch\n");
2333 else
2334 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2335 "Kill switch must be turned off for "
2336 "wireless networking to work.\n");
2337 }
Mohamed Abbasad97edd2008-03-28 16:21:06 -07002338 iwl_rfkill_set_hw_state(priv);
2339
Zhu Yib481de92007-09-25 17:54:57 -07002340 mutex_unlock(&priv->mutex);
2341}
2342
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002343static void iwl4965_bg_set_monitor(struct work_struct *work)
2344{
2345 struct iwl_priv *priv = container_of(work,
2346 struct iwl_priv, set_monitor);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002347 int ret;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002348
2349 IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
2350
2351 mutex_lock(&priv->mutex);
2352
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002353 ret = iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR);
2354
2355 if (ret) {
2356 if (ret == -EAGAIN)
2357 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
2358 else
2359 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
2360 }
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002361
2362 mutex_unlock(&priv->mutex);
2363}
2364
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002365static void iwl_bg_run_time_calib_work(struct work_struct *work)
2366{
2367 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2368 run_time_calib_work);
2369
2370 mutex_lock(&priv->mutex);
2371
2372 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2373 test_bit(STATUS_SCANNING, &priv->status)) {
2374 mutex_unlock(&priv->mutex);
2375 return;
2376 }
2377
2378 if (priv->start_calib) {
2379 iwl_chain_noise_calibration(priv, &priv->statistics);
2380
2381 iwl_sensitivity_calibration(priv, &priv->statistics);
2382 }
2383
2384 mutex_unlock(&priv->mutex);
2385 return;
2386}
2387
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002388static void iwl4965_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002389{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002390 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002391
2392 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2393 return;
2394
2395 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002396 __iwl4965_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002397 mutex_unlock(&priv->mutex);
2398}
2399
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002400static void iwl4965_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002401{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002402 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002403
2404 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2405 return;
2406
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002407 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002408 queue_work(priv->workqueue, &priv->up);
2409}
2410
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002411static void iwl4965_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002412{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002413 struct iwl_priv *priv =
2414 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002415
2416 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2417 return;
2418
2419 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002420 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002421 mutex_unlock(&priv->mutex);
2422}
2423
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002424#define IWL_DELAY_NEXT_SCAN (HZ*2)
2425
Reinette Chatre508e32e2008-04-14 21:16:13 -07002426static void iwl4965_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002427{
Zhu Yib481de92007-09-25 17:54:57 -07002428 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002429 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07002430 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002431
2432 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2433 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
2434 return;
2435 }
2436
Joe Perches0795af52007-10-03 17:59:30 -07002437 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
2438 priv->assoc_id,
2439 print_mac(mac, priv->active_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07002440
2441
2442 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2443 return;
2444
Zhu Yib481de92007-09-25 17:54:57 -07002445
Reinette Chatre508e32e2008-04-14 21:16:13 -07002446 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002447 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002448
Tomas Winkler2a421b92008-06-12 09:47:10 +08002449 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002450
Zhu Yib481de92007-09-25 17:54:57 -07002451 conf = ieee80211_get_hw_conf(priv->hw);
2452
2453 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002454 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002455
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002456 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2457 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002458 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002459 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002460 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07002461 IWL_WARNING("REPLY_RXON_TIMING failed - "
2462 "Attempting to continue.\n");
2463
2464 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2465
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02002466 if (priv->current_ht_config.is_ht)
Tomas Winkler47c51962008-05-05 10:22:41 +08002467 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002468
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002469 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002470 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2471
2472 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2473 priv->assoc_id, priv->beacon_int);
2474
2475 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2476 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2477 else
2478 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2479
2480 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2481 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2482 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2483 else
2484 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2485
2486 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2487 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2488
2489 }
2490
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002491 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002492
2493 switch (priv->iw_mode) {
2494 case IEEE80211_IF_TYPE_STA:
Zhu Yib481de92007-09-25 17:54:57 -07002495 break;
2496
2497 case IEEE80211_IF_TYPE_IBSS:
2498
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002499 /* assume default assoc id */
2500 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002501
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002502 iwl_rxon_add_station(priv, priv->bssid, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002503 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002504
2505 break;
2506
2507 default:
2508 IWL_ERROR("%s Should not be called in %d mode\n",
2509 __FUNCTION__, priv->iw_mode);
2510 break;
2511 }
2512
Zhu Yib481de92007-09-25 17:54:57 -07002513 /* Enable Rx differential gain and sensitivity calibrations */
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07002514 iwl_chain_noise_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002515 priv->start_calib = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002516
2517 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2518 priv->assoc_station_added = 1;
2519
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002520 iwl4965_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002521
Mohamed Abbas5da4b552008-04-21 15:41:51 -07002522 iwl_power_update_mode(priv, 0);
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002523 /* we have just associated, don't start scan too early */
2524 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002525}
2526
2527
2528static void iwl4965_bg_post_associate(struct work_struct *data)
2529{
2530 struct iwl_priv *priv = container_of(data, struct iwl_priv,
2531 post_associate.work);
2532
2533 mutex_lock(&priv->mutex);
2534 iwl4965_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002535 mutex_unlock(&priv->mutex);
Reinette Chatre508e32e2008-04-14 21:16:13 -07002536
Zhu Yib481de92007-09-25 17:54:57 -07002537}
2538
Zhu Yi76bb77e2007-11-22 10:53:22 +08002539static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
2540
Tomas Winkler2a421b92008-06-12 09:47:10 +08002541static void iwl_bg_scan_completed(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002542{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002543 struct iwl_priv *priv =
2544 container_of(work, struct iwl_priv, scan_completed);
Zhu Yib481de92007-09-25 17:54:57 -07002545
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002546 IWL_DEBUG_SCAN("SCAN complete scan\n");
Zhu Yib481de92007-09-25 17:54:57 -07002547
2548 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2549 return;
2550
Zhu Yia0646472007-12-20 14:10:01 +08002551 if (test_bit(STATUS_CONF_PENDING, &priv->status))
2552 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
Zhu Yi76bb77e2007-11-22 10:53:22 +08002553
Zhu Yib481de92007-09-25 17:54:57 -07002554 ieee80211_scan_completed(priv->hw);
2555
2556 /* Since setting the TXPOWER may have been deferred while
2557 * performing the scan, fire one off */
2558 mutex_lock(&priv->mutex);
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002559 iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
Zhu Yib481de92007-09-25 17:54:57 -07002560 mutex_unlock(&priv->mutex);
2561}
2562
2563/*****************************************************************************
2564 *
2565 * mac80211 entry point functions
2566 *
2567 *****************************************************************************/
2568
Zhu Yi5a66926a2008-01-14 17:46:18 -08002569#define UCODE_READY_TIMEOUT (2 * HZ)
2570
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002571static int iwl4965_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002572{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002573 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002574 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002575
2576 IWL_DEBUG_MAC80211("enter\n");
2577
Zhu Yi5a66926a2008-01-14 17:46:18 -08002578 if (pci_enable_device(priv->pci_dev)) {
2579 IWL_ERROR("Fail to pci_enable_device\n");
2580 return -ENODEV;
2581 }
2582 pci_restore_state(priv->pci_dev);
2583 pci_enable_msi(priv->pci_dev);
2584
2585 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
2586 DRV_NAME, priv);
2587 if (ret) {
2588 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
2589 goto out_disable_msi;
2590 }
2591
Zhu Yib481de92007-09-25 17:54:57 -07002592 /* we should be verifying the device is ready to be opened */
2593 mutex_lock(&priv->mutex);
2594
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002595 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a66926a2008-01-14 17:46:18 -08002596 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2597 * ucode filename and max sizes are card-specific. */
2598
2599 if (!priv->ucode_code.len) {
2600 ret = iwl4965_read_ucode(priv);
2601 if (ret) {
2602 IWL_ERROR("Could not read microcode: %d\n", ret);
2603 mutex_unlock(&priv->mutex);
2604 goto out_release_irq;
2605 }
2606 }
2607
Zhu Yie655b9f2008-01-24 02:19:38 -08002608 ret = __iwl4965_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002609
Zhu Yib481de92007-09-25 17:54:57 -07002610 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002611
Zhu Yie655b9f2008-01-24 02:19:38 -08002612 if (ret)
2613 goto out_release_irq;
2614
2615 IWL_DEBUG_INFO("Start UP work done.\n");
2616
2617 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2618 return 0;
2619
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002620 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08002621 * mac80211 will not be run successfully. */
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002622 if (priv->ucode_type == UCODE_RT) {
2623 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2624 test_bit(STATUS_READY, &priv->status),
2625 UCODE_READY_TIMEOUT);
2626 if (!ret) {
2627 if (!test_bit(STATUS_READY, &priv->status)) {
2628 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2629 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2630 ret = -ETIMEDOUT;
2631 goto out_release_irq;
2632 }
Zhu Yi5a66926a2008-01-14 17:46:18 -08002633 }
Zhu Yi5a66926a2008-01-14 17:46:18 -08002634
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002635 priv->is_open = 1;
2636 }
Zhu Yib481de92007-09-25 17:54:57 -07002637 IWL_DEBUG_MAC80211("leave\n");
2638 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002639
2640out_release_irq:
2641 free_irq(priv->pci_dev->irq, priv);
2642out_disable_msi:
2643 pci_disable_msi(priv->pci_dev);
Zhu Yie655b9f2008-01-24 02:19:38 -08002644 pci_disable_device(priv->pci_dev);
2645 priv->is_open = 0;
2646 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08002647 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002648}
2649
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002650static void iwl4965_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002651{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002652 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002653
2654 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002655
Zhu Yie655b9f2008-01-24 02:19:38 -08002656 if (!priv->is_open) {
2657 IWL_DEBUG_MAC80211("leave - skip\n");
2658 return;
2659 }
2660
Zhu Yib481de92007-09-25 17:54:57 -07002661 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002662
Tomas Winklerfee12472008-04-03 16:05:21 -07002663 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002664 /* stop mac, cancel any scan request and clear
2665 * RXON_FILTER_ASSOC_MSK BIT
2666 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002667 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002668 iwl_scan_cancel_timeout(priv, 100);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002669 cancel_delayed_work(&priv->post_associate);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002670 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002671 }
2672
Zhu Yi5a66926a2008-01-14 17:46:18 -08002673 iwl4965_down(priv);
2674
2675 flush_workqueue(priv->workqueue);
2676 free_irq(priv->pci_dev->irq, priv);
2677 pci_disable_msi(priv->pci_dev);
2678 pci_save_state(priv->pci_dev);
2679 pci_disable_device(priv->pci_dev);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002680
Zhu Yib481de92007-09-25 17:54:57 -07002681 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002682}
2683
Johannes Berge039fa42008-05-15 12:55:29 +02002684static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002685{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002686 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002687
2688 IWL_DEBUG_MAC80211("enter\n");
2689
2690 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2691 IWL_DEBUG_MAC80211("leave - monitor\n");
2692 return -1;
2693 }
2694
2695 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002696 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002697
Johannes Berge039fa42008-05-15 12:55:29 +02002698 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002699 dev_kfree_skb_any(skb);
2700
2701 IWL_DEBUG_MAC80211("leave\n");
2702 return 0;
2703}
2704
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002705static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002706 struct ieee80211_if_init_conf *conf)
2707{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002708 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002709 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -07002710 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002711
Johannes Berg32bfd352007-12-19 01:31:26 +01002712 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07002713
Johannes Berg32bfd352007-12-19 01:31:26 +01002714 if (priv->vif) {
2715 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08002716 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07002717 }
2718
2719 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01002720 priv->vif = conf->vif;
Zhu Yib481de92007-09-25 17:54:57 -07002721
2722 spin_unlock_irqrestore(&priv->lock, flags);
2723
2724 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02002725
2726 if (conf->mac_addr) {
2727 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
2728 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2729 }
Zhu Yib481de92007-09-25 17:54:57 -07002730
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002731 if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
2732 /* we are not ready, will run again when ready */
2733 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002734
Zhu Yib481de92007-09-25 17:54:57 -07002735 mutex_unlock(&priv->mutex);
2736
Zhu Yi5a66926a2008-01-14 17:46:18 -08002737 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002738 return 0;
2739}
2740
2741/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002742 * iwl4965_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07002743 *
2744 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2745 * be set inappropriately and the driver currently sets the hardware up to
2746 * use it whenever needed.
2747 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002748static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07002749{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002750 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002751 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002752 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08002753 int ret = 0;
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002754 u16 channel;
Zhu Yib481de92007-09-25 17:54:57 -07002755
2756 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002757 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002758
Zhu Yi12342c42007-12-20 11:27:32 +08002759 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
2760
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002761 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002762 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002763 goto out;
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002764 }
2765
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002766 if (!conf->radio_enabled)
2767 iwl_radio_kill_sw_disable_radio(priv);
2768
Tomas Winklerfee12472008-04-03 16:05:21 -07002769 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002770 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002771 ret = -EIO;
2772 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002773 }
2774
Assaf Krauss1ea87392008-03-18 14:57:50 -07002775 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07002776 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08002777 IWL_DEBUG_MAC80211("leave - scanning\n");
2778 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002779 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08002780 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002781 }
2782
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002783 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2784 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002785 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07002786 IWL_DEBUG_MAC80211("leave - invalid channel\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002787 ret = -EINVAL;
2788 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002789 }
2790
Assaf Krauss398f9e72008-06-12 09:47:06 +08002791 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
2792 !is_channel_ibss(ch_info)) {
2793 IWL_ERROR("channel %d in band %d not IBSS channel\n",
2794 conf->channel->hw_value, conf->channel->band);
2795 ret = -EINVAL;
2796 goto out;
2797 }
2798
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002799 spin_lock_irqsave(&priv->lock, flags);
2800
Tomas Winkler78330fd2008-02-06 02:37:18 +02002801 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07002802 * from any ht related info since 2.4 does not
2803 * support ht */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002804 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
Zhu Yib481de92007-09-25 17:54:57 -07002805#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2806 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2807#endif
2808 )
2809 priv->staging_rxon.flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002810
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002811 iwl_set_rxon_channel(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002812
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002813 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07002814
2815 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01002816 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07002817 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002818 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002819
2820 spin_unlock_irqrestore(&priv->lock, flags);
2821
2822#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2823 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002824 iwl4965_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002825 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002826 }
2827#endif
2828
Zhu Yib481de92007-09-25 17:54:57 -07002829 if (!conf->radio_enabled) {
2830 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002831 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002832 }
2833
Tomas Winklerfee12472008-04-03 16:05:21 -07002834 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002835 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002836 ret = -EIO;
2837 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002838 }
2839
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002840 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2841 priv->tx_power_user_lmt, conf->power_level);
2842
2843 iwl_set_tx_power(priv, conf->power_level, false);
2844
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002845 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002846
2847 if (memcmp(&priv->active_rxon,
2848 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002849 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002850 else
2851 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2852
2853 IWL_DEBUG_MAC80211("leave\n");
2854
Zhu Yia0646472007-12-20 14:10:01 +08002855out:
2856 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002857 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002858 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002859}
2860
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002861static void iwl4965_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002862{
Tomas Winkler857485c2008-03-21 13:53:44 -07002863 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002864
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002865 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002866 return;
2867
2868 /* The following should be done only at AP bring up */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +08002869 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07002870
2871 /* RXON - unassoc (to set timing command) */
2872 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002873 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002874
2875 /* RXON Timing */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002876 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2877 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002878 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002879 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002880 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07002881 IWL_WARNING("REPLY_RXON_TIMING failed - "
2882 "Attempting to continue.\n");
2883
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002884 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002885
2886 /* FIXME: what should be the assoc_id for AP? */
2887 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2888 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2889 priv->staging_rxon.flags |=
2890 RXON_FLG_SHORT_PREAMBLE_MSK;
2891 else
2892 priv->staging_rxon.flags &=
2893 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2894
2895 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2896 if (priv->assoc_capability &
2897 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2898 priv->staging_rxon.flags |=
2899 RXON_FLG_SHORT_SLOT_MSK;
2900 else
2901 priv->staging_rxon.flags &=
2902 ~RXON_FLG_SHORT_SLOT_MSK;
2903
2904 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2905 priv->staging_rxon.flags &=
2906 ~RXON_FLG_SHORT_SLOT_MSK;
2907 }
2908 /* restore RXON assoc */
2909 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002910 iwl4965_commit_rxon(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002911 iwl4965_activate_qos(priv, 1);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002912 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002913 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002914 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002915
2916 /* FIXME - we need to add code here to detect a totally new
2917 * configuration, reset the AP, unassoc, rxon timing, assoc,
2918 * clear sta table, add BCAST sta... */
2919}
2920
Johannes Berg32bfd352007-12-19 01:31:26 +01002921static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
2922 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002923 struct ieee80211_if_conf *conf)
2924{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002925 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07002926 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002927 unsigned long flags;
2928 int rc;
2929
2930 if (conf == NULL)
2931 return -EIO;
2932
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002933 if (priv->vif != vif) {
2934 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002935 return 0;
2936 }
2937
Zhu Yib481de92007-09-25 17:54:57 -07002938 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
2939 (!conf->beacon || !conf->ssid_len)) {
2940 IWL_DEBUG_MAC80211
2941 ("Leaving in AP mode because HostAPD is not ready.\n");
2942 return 0;
2943 }
2944
Tomas Winklerfee12472008-04-03 16:05:21 -07002945 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08002946 return -EAGAIN;
2947
Zhu Yib481de92007-09-25 17:54:57 -07002948 mutex_lock(&priv->mutex);
2949
Zhu Yib481de92007-09-25 17:54:57 -07002950 if (conf->bssid)
Joe Perches0795af52007-10-03 17:59:30 -07002951 IWL_DEBUG_MAC80211("bssid: %s\n",
2952 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07002953
Johannes Berg4150c572007-09-17 01:29:23 -04002954/*
2955 * very dubious code was here; the probe filtering flag is never set:
2956 *
Zhu Yib481de92007-09-25 17:54:57 -07002957 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2958 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002959 */
Zhu Yib481de92007-09-25 17:54:57 -07002960
2961 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2962 if (!conf->bssid) {
2963 conf->bssid = priv->mac_addr;
2964 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Joe Perches0795af52007-10-03 17:59:30 -07002965 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
2966 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07002967 }
2968 if (priv->ibss_beacon)
2969 dev_kfree_skb(priv->ibss_beacon);
2970
2971 priv->ibss_beacon = conf->beacon;
2972 }
2973
Tomas Winklerfee12472008-04-03 16:05:21 -07002974 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08002975 goto done;
2976
Zhu Yib481de92007-09-25 17:54:57 -07002977 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2978 !is_multicast_ether_addr(conf->bssid)) {
2979 /* If there is currently a HW scan going on in the background
2980 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002981 if (iwl_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07002982 IWL_WARNING("Aborted scan still in progress "
2983 "after 100ms\n");
2984 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2985 mutex_unlock(&priv->mutex);
2986 return -EAGAIN;
2987 }
2988 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2989
2990 /* TODO: Audit driver for usage of these members and see
2991 * if mac80211 deprecates them (priv->bssid looks like it
2992 * shouldn't be there, but I haven't scanned the IBSS code
2993 * to verify) - jpk */
2994 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2995
2996 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002997 iwl4965_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002998 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002999 rc = iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003000 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08003001 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07003002 priv, priv->active_rxon.bssid_addr, 1);
3003 }
3004
3005 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003006 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07003007 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003008 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003009 }
3010
Mohamed Abbasfde35712007-11-29 11:10:15 +08003011 done:
Zhu Yib481de92007-09-25 17:54:57 -07003012 spin_lock_irqsave(&priv->lock, flags);
3013 if (!conf->ssid_len)
3014 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3015 else
3016 memcpy(priv->essid, conf->ssid, conf->ssid_len);
3017
3018 priv->essid_len = conf->ssid_len;
3019 spin_unlock_irqrestore(&priv->lock, flags);
3020
3021 IWL_DEBUG_MAC80211("leave\n");
3022 mutex_unlock(&priv->mutex);
3023
3024 return 0;
3025}
3026
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003027static void iwl4965_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04003028 unsigned int changed_flags,
3029 unsigned int *total_flags,
3030 int mc_count, struct dev_addr_list *mc_list)
3031{
3032 /*
3033 * XXX: dummy
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003034 * see also iwl4965_connection_init_rx_config
Johannes Berg4150c572007-09-17 01:29:23 -04003035 */
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08003036 struct iwl_priv *priv = hw->priv;
3037 int new_flags = 0;
3038 if (changed_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
3039 if (*total_flags & (FIF_PROMISC_IN_BSS | FIF_OTHER_BSS)) {
3040 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
3041 IEEE80211_IF_TYPE_MNTR,
3042 changed_flags, *total_flags);
3043 /* queue work 'cuz mac80211 is holding a lock which
3044 * prevents us from issuing (synchronous) f/w cmds */
3045 queue_work(priv->workqueue, &priv->set_monitor);
3046 new_flags &= FIF_PROMISC_IN_BSS |
3047 FIF_OTHER_BSS |
3048 FIF_ALLMULTI;
3049 }
3050 }
3051 *total_flags = new_flags;
Johannes Berg4150c572007-09-17 01:29:23 -04003052}
3053
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003054static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003055 struct ieee80211_if_init_conf *conf)
3056{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003057 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003058
3059 IWL_DEBUG_MAC80211("enter\n");
3060
3061 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003062
Tomas Winklerfee12472008-04-03 16:05:21 -07003063 if (iwl_is_ready_rf(priv)) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003064 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003065 cancel_delayed_work(&priv->post_associate);
3066 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3067 iwl4965_commit_rxon(priv);
3068 }
Johannes Berg32bfd352007-12-19 01:31:26 +01003069 if (priv->vif == conf->vif) {
3070 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003071 memset(priv->bssid, 0, ETH_ALEN);
3072 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3073 priv->essid_len = 0;
3074 }
3075 mutex_unlock(&priv->mutex);
3076
3077 IWL_DEBUG_MAC80211("leave\n");
3078
3079}
Johannes Berg471b3ef2007-12-28 14:32:58 +01003080
Tomas Winkler3109ece2008-03-28 16:33:35 -07003081#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Johannes Berg471b3ef2007-12-28 14:32:58 +01003082static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
3083 struct ieee80211_vif *vif,
3084 struct ieee80211_bss_conf *bss_conf,
3085 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02003086{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003087 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02003088
Tomas Winkler3109ece2008-03-28 16:33:35 -07003089 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
3090
Johannes Berg471b3ef2007-12-28 14:32:58 +01003091 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003092 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
3093 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003094 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02003095 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3096 else
3097 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3098 }
3099
Johannes Berg471b3ef2007-12-28 14:32:58 +01003100 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003101 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01003102 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02003103 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
3104 else
3105 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
3106 }
3107
Tomas Winkler98952d52008-03-28 16:33:33 -07003108 if (changes & BSS_CHANGED_HT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003109 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
Tomas Winkler98952d52008-03-28 16:33:33 -07003110 iwl4965_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003111 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07003112 }
3113
Johannes Berg471b3ef2007-12-28 14:32:58 +01003114 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003115 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003116 /* This should never happen as this function should
3117 * never be called from interrupt context. */
3118 if (WARN_ON_ONCE(in_interrupt()))
3119 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003120 if (bss_conf->assoc) {
3121 priv->assoc_id = bss_conf->aid;
3122 priv->beacon_int = bss_conf->beacon_int;
3123 priv->timestamp = bss_conf->timestamp;
3124 priv->assoc_capability = bss_conf->assoc_capability;
3125 priv->next_scan_jiffies = jiffies +
3126 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003127 mutex_lock(&priv->mutex);
3128 iwl4965_post_associate(priv);
3129 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003130 } else {
3131 priv->assoc_id = 0;
3132 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3133 }
3134 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3135 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003136 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003137 }
3138
Tomas Winkler220173b2007-10-16 00:50:25 +02003139}
Zhu Yib481de92007-09-25 17:54:57 -07003140
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003141static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07003142{
3143 int rc = 0;
3144 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003145 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003146
3147 IWL_DEBUG_MAC80211("enter\n");
3148
mabbas052c4b92007-10-25 17:15:43 +08003149 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003150 spin_lock_irqsave(&priv->lock, flags);
3151
Tomas Winklerfee12472008-04-03 16:05:21 -07003152 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003153 rc = -EIO;
3154 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3155 goto out_unlock;
3156 }
3157
3158 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
3159 rc = -EIO;
3160 IWL_ERROR("ERROR: APs don't scan\n");
3161 goto out_unlock;
3162 }
3163
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003164 /* we don't schedule scan within next_scan_jiffies period */
3165 if (priv->next_scan_jiffies &&
3166 time_after(priv->next_scan_jiffies, jiffies)) {
3167 rc = -EAGAIN;
3168 goto out_unlock;
3169 }
Zhu Yib481de92007-09-25 17:54:57 -07003170 /* if we just finished scan ask for delay */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003171 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
3172 IWL_DELAY_NEXT_SCAN, jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07003173 rc = -EAGAIN;
3174 goto out_unlock;
3175 }
3176 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003177 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
Tomas Winkler2a421b92008-06-12 09:47:10 +08003178 iwl_escape_essid(ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07003179
3180 priv->one_direct_scan = 1;
3181 priv->direct_ssid_len = (u8)
3182 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
3183 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003184 } else
3185 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003186
Tomas Winkler2a421b92008-06-12 09:47:10 +08003187 rc = iwl_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003188
3189 IWL_DEBUG_MAC80211("leave\n");
3190
3191out_unlock:
3192 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08003193 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003194
3195 return rc;
3196}
3197
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003198static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
3199 struct ieee80211_key_conf *keyconf, const u8 *addr,
3200 u32 iv32, u16 *phase1key)
3201{
3202 struct iwl_priv *priv = hw->priv;
3203 u8 sta_id = IWL_INVALID_STATION;
3204 unsigned long flags;
3205 __le16 key_flags = 0;
3206 int i;
3207 DECLARE_MAC_BUF(mac);
3208
3209 IWL_DEBUG_MAC80211("enter\n");
3210
Tomas Winkler947b13a2008-04-16 16:34:48 -07003211 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003212 if (sta_id == IWL_INVALID_STATION) {
3213 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3214 print_mac(mac, addr));
3215 return;
3216 }
3217
Tomas Winkler2a421b92008-06-12 09:47:10 +08003218 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003219
3220 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
3221 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
3222 key_flags &= ~STA_KEY_FLG_INVALID;
3223
Tomas Winkler5425e492008-04-15 16:01:38 -07003224 if (sta_id == priv->hw_params.bcast_sta_id)
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003225 key_flags |= STA_KEY_MULTICAST_MSK;
3226
3227 spin_lock_irqsave(&priv->sta_lock, flags);
3228
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003229 priv->stations[sta_id].sta.key.key_flags = key_flags;
3230 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
3231
3232 for (i = 0; i < 5; i++)
3233 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
3234 cpu_to_le16(phase1key[i]);
3235
3236 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
3237 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3238
Tomas Winkler133636d2008-05-05 10:22:34 +08003239 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003240
3241 spin_unlock_irqrestore(&priv->sta_lock, flags);
3242
3243 IWL_DEBUG_MAC80211("leave\n");
3244}
3245
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003246static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Zhu Yib481de92007-09-25 17:54:57 -07003247 const u8 *local_addr, const u8 *addr,
3248 struct ieee80211_key_conf *key)
3249{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003250 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07003251 DECLARE_MAC_BUF(mac);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003252 int ret = 0;
3253 u8 sta_id = IWL_INVALID_STATION;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003254 u8 is_default_wep_key = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003255
3256 IWL_DEBUG_MAC80211("enter\n");
3257
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003258 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07003259 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3260 return -EOPNOTSUPP;
3261 }
3262
3263 if (is_zero_ether_addr(addr))
3264 /* only support pairwise keys */
3265 return -EOPNOTSUPP;
3266
Tomas Winkler947b13a2008-04-16 16:34:48 -07003267 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003268 if (sta_id == IWL_INVALID_STATION) {
3269 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3270 print_mac(mac, addr));
3271 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003272
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003273 }
Zhu Yib481de92007-09-25 17:54:57 -07003274
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003275 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003276 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003277 mutex_unlock(&priv->mutex);
3278
3279 /* If we are getting WEP group key and we didn't receive any key mapping
3280 * so far, we are in legacy wep mode (group key only), otherwise we are
3281 * in 1X mode.
3282 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07003283 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003284 priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3285 if (cmd == SET_KEY)
3286 is_default_wep_key = !priv->key_mapping_key;
3287 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003288 is_default_wep_key =
3289 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003290 }
mabbas052c4b92007-10-25 17:15:43 +08003291
Zhu Yib481de92007-09-25 17:54:57 -07003292 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003293 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003294 if (is_default_wep_key)
3295 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003296 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003297 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003298
3299 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003300 break;
3301 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003302 if (is_default_wep_key)
3303 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003304 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003305 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003306
3307 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003308 break;
3309 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003310 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003311 }
3312
3313 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003314
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003315 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003316}
3317
Johannes Berge100bb62008-04-30 18:51:21 +02003318static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07003319 const struct ieee80211_tx_queue_params *params)
3320{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003321 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003322 unsigned long flags;
3323 int q;
Zhu Yib481de92007-09-25 17:54:57 -07003324
3325 IWL_DEBUG_MAC80211("enter\n");
3326
Tomas Winklerfee12472008-04-03 16:05:21 -07003327 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003328 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3329 return -EIO;
3330 }
3331
3332 if (queue >= AC_NUM) {
3333 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3334 return 0;
3335 }
3336
Zhu Yib481de92007-09-25 17:54:57 -07003337 if (!priv->qos_data.qos_enable) {
3338 priv->qos_data.qos_active = 0;
3339 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
3340 return 0;
3341 }
3342 q = AC_NUM - 1 - queue;
3343
3344 spin_lock_irqsave(&priv->lock, flags);
3345
3346 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3347 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3348 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3349 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01003350 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07003351
3352 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3353 priv->qos_data.qos_active = 1;
3354
3355 spin_unlock_irqrestore(&priv->lock, flags);
3356
3357 mutex_lock(&priv->mutex);
3358 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003359 iwl4965_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003360 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003361 iwl4965_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003362
3363 mutex_unlock(&priv->mutex);
3364
Zhu Yib481de92007-09-25 17:54:57 -07003365 IWL_DEBUG_MAC80211("leave\n");
3366 return 0;
3367}
3368
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003369static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003370 struct ieee80211_tx_queue_stats *stats)
3371{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003372 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003373 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003374 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003375 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003376 unsigned long flags;
3377
3378 IWL_DEBUG_MAC80211("enter\n");
3379
Tomas Winklerfee12472008-04-03 16:05:21 -07003380 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003381 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3382 return -EIO;
3383 }
3384
3385 spin_lock_irqsave(&priv->lock, flags);
3386
3387 for (i = 0; i < AC_NUM; i++) {
3388 txq = &priv->txq[i];
3389 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003390 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003391
Johannes Berg57ffc582008-04-29 17:18:59 +02003392 stats[i].len = q->n_window - avail;
3393 stats[i].limit = q->n_window - q->high_mark;
3394 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003395
3396 }
3397 spin_unlock_irqrestore(&priv->lock, flags);
3398
3399 IWL_DEBUG_MAC80211("leave\n");
3400
3401 return 0;
3402}
3403
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003404static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003405 struct ieee80211_low_level_stats *stats)
3406{
Ester Kummerbf403db2008-05-05 10:22:40 +08003407 struct iwl_priv *priv = hw->priv;
3408
3409 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003410 IWL_DEBUG_MAC80211("enter\n");
3411 IWL_DEBUG_MAC80211("leave\n");
3412
3413 return 0;
3414}
3415
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003416static u64 iwl4965_mac_get_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003417{
Ester Kummerbf403db2008-05-05 10:22:40 +08003418 struct iwl_priv *priv;
3419
3420 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003421 IWL_DEBUG_MAC80211("enter\n");
3422 IWL_DEBUG_MAC80211("leave\n");
3423
3424 return 0;
3425}
3426
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003427static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003428{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003429 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003430 unsigned long flags;
3431
3432 mutex_lock(&priv->mutex);
3433 IWL_DEBUG_MAC80211("enter\n");
3434
Zhu Yib481de92007-09-25 17:54:57 -07003435 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003436 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07003437 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003438
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003439 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003440
3441 cancel_delayed_work(&priv->post_associate);
3442
3443 spin_lock_irqsave(&priv->lock, flags);
3444 priv->assoc_id = 0;
3445 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003446 priv->assoc_station_added = 0;
3447
3448 /* new association get rid of ibss beacon skb */
3449 if (priv->ibss_beacon)
3450 dev_kfree_skb(priv->ibss_beacon);
3451
3452 priv->ibss_beacon = NULL;
3453
3454 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003455 priv->timestamp = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003456 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
3457 priv->beacon_int = 0;
3458
3459 spin_unlock_irqrestore(&priv->lock, flags);
3460
Tomas Winklerfee12472008-04-03 16:05:21 -07003461 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08003462 IWL_DEBUG_MAC80211("leave - not ready\n");
3463 mutex_unlock(&priv->mutex);
3464 return;
3465 }
3466
mabbas052c4b92007-10-25 17:15:43 +08003467 /* we are restarting association process
3468 * clear RXON_FILTER_ASSOC_MSK bit
3469 */
3470 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003471 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08003472 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003473 iwl4965_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08003474 }
3475
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003476 iwl_power_update_mode(priv, 0);
3477
Zhu Yib481de92007-09-25 17:54:57 -07003478 /* Per mac80211.h: This is only used in IBSS mode... */
3479 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
mabbas052c4b92007-10-25 17:15:43 +08003480
Zhu Yib481de92007-09-25 17:54:57 -07003481 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3482 mutex_unlock(&priv->mutex);
3483 return;
3484 }
3485
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003486 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003487
3488 mutex_unlock(&priv->mutex);
3489
3490 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003491}
3492
Johannes Berge039fa42008-05-15 12:55:29 +02003493static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003494{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003495 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003496 unsigned long flags;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003497 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07003498
3499 mutex_lock(&priv->mutex);
3500 IWL_DEBUG_MAC80211("enter\n");
3501
Tomas Winklerfee12472008-04-03 16:05:21 -07003502 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003503 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3504 mutex_unlock(&priv->mutex);
3505 return -EIO;
3506 }
3507
3508 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
3509 IWL_DEBUG_MAC80211("leave - not IBSS\n");
3510 mutex_unlock(&priv->mutex);
3511 return -EIO;
3512 }
3513
3514 spin_lock_irqsave(&priv->lock, flags);
3515
3516 if (priv->ibss_beacon)
3517 dev_kfree_skb(priv->ibss_beacon);
3518
3519 priv->ibss_beacon = skb;
3520
3521 priv->assoc_id = 0;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003522 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
3523 priv->timestamp = le64_to_cpu(timestamp) + (priv->beacon_int * 1000);
Zhu Yib481de92007-09-25 17:54:57 -07003524
3525 IWL_DEBUG_MAC80211("leave\n");
3526 spin_unlock_irqrestore(&priv->lock, flags);
3527
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003528 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003529
Assaf Kraussc46fbef2008-06-12 09:47:05 +08003530 iwl4965_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003531
3532 mutex_unlock(&priv->mutex);
3533
3534 return 0;
3535}
3536
Zhu Yib481de92007-09-25 17:54:57 -07003537/*****************************************************************************
3538 *
3539 * sysfs attributes
3540 *
3541 *****************************************************************************/
3542
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003543#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003544
3545/*
3546 * The following adds a new attribute to the sysfs representation
3547 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3548 * used for controlling the debug level.
3549 *
3550 * See the level definitions in iwl for details.
3551 */
3552
Ester Kummer8cf769c2008-05-06 11:05:11 +08003553static ssize_t show_debug_level(struct device *d,
3554 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003555{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003556 struct iwl_priv *priv = d->driver_data;
3557
3558 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003559}
Ester Kummer8cf769c2008-05-06 11:05:11 +08003560static ssize_t store_debug_level(struct device *d,
3561 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003562 const char *buf, size_t count)
3563{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003564 struct iwl_priv *priv = d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003565 char *p = (char *)buf;
3566 u32 val;
3567
3568 val = simple_strtoul(p, &p, 0);
3569 if (p == buf)
3570 printk(KERN_INFO DRV_NAME
3571 ": %s is not in hex or decimal form.\n", buf);
3572 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08003573 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003574
3575 return strnlen(buf, count);
3576}
3577
Ester Kummer8cf769c2008-05-06 11:05:11 +08003578static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3579 show_debug_level, store_debug_level);
3580
Zhu Yib481de92007-09-25 17:54:57 -07003581
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003582#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003583
Zhu Yib481de92007-09-25 17:54:57 -07003584
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003585static ssize_t show_version(struct device *d,
3586 struct device_attribute *attr, char *buf)
3587{
3588 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08003589 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08003590 ssize_t pos = 0;
3591 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003592
3593 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08003594 pos += sprintf(buf + pos,
3595 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3596 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003597 palive->ucode_major, palive->ucode_minor,
3598 palive->sw_rev[0], palive->sw_rev[1],
3599 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003600 else
Tomas Winklerf236a262008-06-30 17:23:02 +08003601 pos += sprintf(buf + pos, "fw not loaded\n");
3602
3603 if (priv->eeprom) {
3604 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3605 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3606 eeprom_ver);
3607 } else {
3608 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3609 }
3610
3611 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003612}
3613
3614static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3615
Zhu Yib481de92007-09-25 17:54:57 -07003616static ssize_t show_temperature(struct device *d,
3617 struct device_attribute *attr, char *buf)
3618{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003619 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003620
Tomas Winklerfee12472008-04-03 16:05:21 -07003621 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003622 return -EAGAIN;
3623
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003624 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003625}
3626
3627static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3628
3629static ssize_t show_rs_window(struct device *d,
3630 struct device_attribute *attr,
3631 char *buf)
3632{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003633 struct iwl_priv *priv = d->driver_data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003634 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003635}
3636static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
3637
3638static ssize_t show_tx_power(struct device *d,
3639 struct device_attribute *attr, char *buf)
3640{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003641 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003642 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003643}
3644
3645static ssize_t store_tx_power(struct device *d,
3646 struct device_attribute *attr,
3647 const char *buf, size_t count)
3648{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003649 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003650 char *p = (char *)buf;
3651 u32 val;
3652
3653 val = simple_strtoul(p, &p, 10);
3654 if (p == buf)
3655 printk(KERN_INFO DRV_NAME
3656 ": %s is not in decimal form.\n", buf);
3657 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003658 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07003659
3660 return count;
3661}
3662
3663static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3664
3665static ssize_t show_flags(struct device *d,
3666 struct device_attribute *attr, char *buf)
3667{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003668 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003669
3670 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3671}
3672
3673static ssize_t store_flags(struct device *d,
3674 struct device_attribute *attr,
3675 const char *buf, size_t count)
3676{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003677 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003678 u32 flags = simple_strtoul(buf, NULL, 0);
3679
3680 mutex_lock(&priv->mutex);
3681 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3682 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003683 if (iwl_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07003684 IWL_WARNING("Could not cancel scan.\n");
3685 else {
3686 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
3687 flags);
3688 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003689 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003690 }
3691 }
3692 mutex_unlock(&priv->mutex);
3693
3694 return count;
3695}
3696
3697static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3698
3699static ssize_t show_filter_flags(struct device *d,
3700 struct device_attribute *attr, char *buf)
3701{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003702 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003703
3704 return sprintf(buf, "0x%04X\n",
3705 le32_to_cpu(priv->active_rxon.filter_flags));
3706}
3707
3708static ssize_t store_filter_flags(struct device *d,
3709 struct device_attribute *attr,
3710 const char *buf, size_t count)
3711{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003712 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003713 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3714
3715 mutex_lock(&priv->mutex);
3716 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3717 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003718 if (iwl_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07003719 IWL_WARNING("Could not cancel scan.\n");
3720 else {
3721 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3722 "0x%04X\n", filter_flags);
3723 priv->staging_rxon.filter_flags =
3724 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003725 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003726 }
3727 }
3728 mutex_unlock(&priv->mutex);
3729
3730 return count;
3731}
3732
3733static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3734 store_filter_flags);
3735
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003736#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003737
3738static ssize_t show_measurement(struct device *d,
3739 struct device_attribute *attr, char *buf)
3740{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003741 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003742 struct iwl4965_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003743 u32 size = sizeof(measure_report), len = 0, ofs = 0;
3744 u8 *data = (u8 *) & measure_report;
3745 unsigned long flags;
3746
3747 spin_lock_irqsave(&priv->lock, flags);
3748 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3749 spin_unlock_irqrestore(&priv->lock, flags);
3750 return 0;
3751 }
3752 memcpy(&measure_report, &priv->measure_report, size);
3753 priv->measurement_status = 0;
3754 spin_unlock_irqrestore(&priv->lock, flags);
3755
3756 while (size && (PAGE_SIZE - len)) {
3757 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3758 PAGE_SIZE - len, 1);
3759 len = strlen(buf);
3760 if (PAGE_SIZE - len)
3761 buf[len++] = '\n';
3762
3763 ofs += 16;
3764 size -= min(size, 16U);
3765 }
3766
3767 return len;
3768}
3769
3770static ssize_t store_measurement(struct device *d,
3771 struct device_attribute *attr,
3772 const char *buf, size_t count)
3773{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003774 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003775 struct ieee80211_measurement_params params = {
3776 .channel = le16_to_cpu(priv->active_rxon.channel),
3777 .start_time = cpu_to_le64(priv->last_tsf),
3778 .duration = cpu_to_le16(1),
3779 };
3780 u8 type = IWL_MEASURE_BASIC;
3781 u8 buffer[32];
3782 u8 channel;
3783
3784 if (count) {
3785 char *p = buffer;
3786 strncpy(buffer, buf, min(sizeof(buffer), count));
3787 channel = simple_strtoul(p, NULL, 0);
3788 if (channel)
3789 params.channel = channel;
3790
3791 p = buffer;
3792 while (*p && *p != ' ')
3793 p++;
3794 if (*p)
3795 type = simple_strtoul(p + 1, NULL, 0);
3796 }
3797
3798 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3799 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003800 iwl4965_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07003801
3802 return count;
3803}
3804
3805static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3806 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003807#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07003808
3809static ssize_t store_retry_rate(struct device *d,
3810 struct device_attribute *attr,
3811 const char *buf, size_t count)
3812{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003813 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003814
3815 priv->retry_rate = simple_strtoul(buf, NULL, 0);
3816 if (priv->retry_rate <= 0)
3817 priv->retry_rate = 1;
3818
3819 return count;
3820}
3821
3822static ssize_t show_retry_rate(struct device *d,
3823 struct device_attribute *attr, char *buf)
3824{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003825 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003826 return sprintf(buf, "%d", priv->retry_rate);
3827}
3828
3829static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3830 store_retry_rate);
3831
3832static ssize_t store_power_level(struct device *d,
3833 struct device_attribute *attr,
3834 const char *buf, size_t count)
3835{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003836 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003837 int rc;
3838 int mode;
3839
3840 mode = simple_strtoul(buf, NULL, 0);
3841 mutex_lock(&priv->mutex);
3842
Tomas Winklerfee12472008-04-03 16:05:21 -07003843 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003844 rc = -EAGAIN;
3845 goto out;
3846 }
3847
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003848 rc = iwl_power_set_user_mode(priv, mode);
3849 if (rc) {
3850 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3851 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003852 }
Zhu Yib481de92007-09-25 17:54:57 -07003853 rc = count;
3854
3855 out:
3856 mutex_unlock(&priv->mutex);
3857 return rc;
3858}
3859
3860#define MAX_WX_STRING 80
3861
3862/* Values are in microsecond */
3863static const s32 timeout_duration[] = {
3864 350000,
3865 250000,
3866 75000,
3867 37000,
3868 25000,
3869};
3870static const s32 period_duration[] = {
3871 400000,
3872 700000,
3873 1000000,
3874 1000000,
3875 1000000
3876};
3877
3878static ssize_t show_power_level(struct device *d,
3879 struct device_attribute *attr, char *buf)
3880{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003881 struct iwl_priv *priv = dev_get_drvdata(d);
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003882 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07003883 char *p = buf;
3884
3885 p += sprintf(p, "%d ", level);
3886 switch (level) {
3887 case IWL_POWER_MODE_CAM:
3888 case IWL_POWER_AC:
3889 p += sprintf(p, "(AC)");
3890 break;
3891 case IWL_POWER_BATTERY:
3892 p += sprintf(p, "(BATTERY)");
3893 break;
3894 default:
3895 p += sprintf(p,
3896 "(Timeout %dms, Period %dms)",
3897 timeout_duration[level - 1] / 1000,
3898 period_duration[level - 1] / 1000);
3899 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003900/*
Zhu Yib481de92007-09-25 17:54:57 -07003901 if (!(priv->power_mode & IWL_POWER_ENABLED))
3902 p += sprintf(p, " OFF\n");
3903 else
3904 p += sprintf(p, " \n");
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003905*/
3906 p += sprintf(p, " \n");
Zhu Yib481de92007-09-25 17:54:57 -07003907 return (p - buf + 1);
Zhu Yib481de92007-09-25 17:54:57 -07003908}
3909
3910static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3911 store_power_level);
3912
3913static ssize_t show_channels(struct device *d,
3914 struct device_attribute *attr, char *buf)
3915{
Ester Kummer5d72a1f2008-06-13 15:44:53 +08003916
3917 struct iwl_priv *priv = dev_get_drvdata(d);
3918 struct ieee80211_channel *channels = NULL;
3919 const struct ieee80211_supported_band *supp_band = NULL;
3920 int len = 0, i;
3921 int count = 0;
3922
3923 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
3924 return -EAGAIN;
3925
3926 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
3927 channels = supp_band->channels;
3928 count = supp_band->n_channels;
3929
3930 len += sprintf(&buf[len],
3931 "Displaying %d channels in 2.4GHz band "
3932 "(802.11bg):\n", count);
3933
3934 for (i = 0; i < count; i++)
3935 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3936 ieee80211_frequency_to_channel(
3937 channels[i].center_freq),
3938 channels[i].max_power,
3939 channels[i].flags & IEEE80211_CHAN_RADAR ?
3940 " (IEEE 802.11h required)" : "",
3941 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3942 || (channels[i].flags &
3943 IEEE80211_CHAN_RADAR)) ? "" :
3944 ", IBSS",
3945 channels[i].flags &
3946 IEEE80211_CHAN_PASSIVE_SCAN ?
3947 "passive only" : "active/passive");
3948
3949 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
3950 channels = supp_band->channels;
3951 count = supp_band->n_channels;
3952
3953 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
3954 "(802.11a):\n", count);
3955
3956 for (i = 0; i < count; i++)
3957 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3958 ieee80211_frequency_to_channel(
3959 channels[i].center_freq),
3960 channels[i].max_power,
3961 channels[i].flags & IEEE80211_CHAN_RADAR ?
3962 " (IEEE 802.11h required)" : "",
3963 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3964 || (channels[i].flags &
3965 IEEE80211_CHAN_RADAR)) ? "" :
3966 ", IBSS",
3967 channels[i].flags &
3968 IEEE80211_CHAN_PASSIVE_SCAN ?
3969 "passive only" : "active/passive");
3970
3971 return len;
Zhu Yib481de92007-09-25 17:54:57 -07003972}
3973
3974static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
3975
3976static ssize_t show_statistics(struct device *d,
3977 struct device_attribute *attr, char *buf)
3978{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003979 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003980 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003981 u32 len = 0, ofs = 0;
3982 u8 *data = (u8 *) & priv->statistics;
3983 int rc = 0;
3984
Tomas Winklerfee12472008-04-03 16:05:21 -07003985 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003986 return -EAGAIN;
3987
3988 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07003989 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003990 mutex_unlock(&priv->mutex);
3991
3992 if (rc) {
3993 len = sprintf(buf,
3994 "Error sending statistics request: 0x%08X\n", rc);
3995 return len;
3996 }
3997
3998 while (size && (PAGE_SIZE - len)) {
3999 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4000 PAGE_SIZE - len, 1);
4001 len = strlen(buf);
4002 if (PAGE_SIZE - len)
4003 buf[len++] = '\n';
4004
4005 ofs += 16;
4006 size -= min(size, 16U);
4007 }
4008
4009 return len;
4010}
4011
4012static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4013
Zhu Yib481de92007-09-25 17:54:57 -07004014static ssize_t show_status(struct device *d,
4015 struct device_attribute *attr, char *buf)
4016{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004017 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winklerfee12472008-04-03 16:05:21 -07004018 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004019 return -EAGAIN;
4020 return sprintf(buf, "0x%08x\n", (int)priv->status);
4021}
4022
4023static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4024
Zhu Yib481de92007-09-25 17:54:57 -07004025/*****************************************************************************
4026 *
4027 * driver setup and teardown
4028 *
4029 *****************************************************************************/
4030
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004031static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004032{
4033 priv->workqueue = create_workqueue(DRV_NAME);
4034
4035 init_waitqueue_head(&priv->wait_command_queue);
4036
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004037 INIT_WORK(&priv->up, iwl4965_bg_up);
4038 INIT_WORK(&priv->restart, iwl4965_bg_restart);
4039 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004040 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
4041 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08004042 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08004043 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004044 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08004045 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
4046 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08004047
4048 /* FIXME : remove when resolved PENDING */
4049 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4050 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004051
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004052 if (priv->cfg->ops->lib->setup_deferred_work)
4053 priv->cfg->ops->lib->setup_deferred_work(priv);
4054
4055 init_timer(&priv->statistics_periodic);
4056 priv->statistics_periodic.data = (unsigned long)priv;
4057 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07004058
4059 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004060 iwl4965_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004061}
4062
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004063static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004064{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004065 if (priv->cfg->ops->lib->cancel_deferred_work)
4066 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004067
Joonwoo Park3ae6a052007-11-29 10:43:16 +09004068 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004069 cancel_delayed_work(&priv->scan_check);
4070 cancel_delayed_work(&priv->alive_start);
4071 cancel_delayed_work(&priv->post_associate);
4072 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004073 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07004074}
4075
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004076static struct attribute *iwl4965_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004077 &dev_attr_channels.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004078 &dev_attr_flags.attr,
4079 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004080#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004081 &dev_attr_measurement.attr,
4082#endif
4083 &dev_attr_power_level.attr,
4084 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004085 &dev_attr_rs_window.attr,
4086 &dev_attr_statistics.attr,
4087 &dev_attr_status.attr,
4088 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004089 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08004090#ifdef CONFIG_IWLWIFI_DEBUG
4091 &dev_attr_debug_level.attr,
4092#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08004093 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004094
4095 NULL
4096};
4097
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004098static struct attribute_group iwl4965_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004099 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004100 .attrs = iwl4965_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004101};
4102
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004103static struct ieee80211_ops iwl4965_hw_ops = {
4104 .tx = iwl4965_mac_tx,
4105 .start = iwl4965_mac_start,
4106 .stop = iwl4965_mac_stop,
4107 .add_interface = iwl4965_mac_add_interface,
4108 .remove_interface = iwl4965_mac_remove_interface,
4109 .config = iwl4965_mac_config,
4110 .config_interface = iwl4965_mac_config_interface,
4111 .configure_filter = iwl4965_configure_filter,
4112 .set_key = iwl4965_mac_set_key,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004113 .update_tkip_key = iwl4965_mac_update_tkip_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004114 .get_stats = iwl4965_mac_get_stats,
4115 .get_tx_stats = iwl4965_mac_get_tx_stats,
4116 .conf_tx = iwl4965_mac_conf_tx,
4117 .get_tsf = iwl4965_mac_get_tsf,
4118 .reset_tsf = iwl4965_mac_reset_tsf,
4119 .beacon_update = iwl4965_mac_beacon_update,
Johannes Berg471b3ef2007-12-28 14:32:58 +01004120 .bss_info_changed = iwl4965_bss_info_changed,
Ron Rindjunsky9ab46172007-12-25 17:00:38 +02004121 .ampdu_action = iwl4965_mac_ampdu_action,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004122 .hw_scan = iwl4965_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004123};
4124
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004125static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004126{
4127 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004128 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004129 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08004130 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004131 unsigned long flags;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004132 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07004133
Assaf Krauss316c30d2008-03-14 10:38:46 -07004134 /************************
4135 * 1. Allocating HW data
4136 ************************/
4137
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004138 /* Disabling hardware scan means that mac80211 will perform scans
4139 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004140 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08004141 if (cfg->mod_params->debug & IWL_DL_INFO)
4142 dev_printk(KERN_DEBUG, &(pdev->dev),
4143 "Disabling hw_scan\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004144 iwl4965_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004145 }
4146
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004147 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
4148 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07004149 err = -ENOMEM;
4150 goto out;
4151 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004152 priv = hw->priv;
4153 /* At this point both hw and priv are allocated. */
4154
Zhu Yib481de92007-09-25 17:54:57 -07004155 SET_IEEE80211_DEV(hw, &pdev->dev);
4156
4157 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08004158 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07004159 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004160
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004161#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08004162 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07004163 atomic_set(&priv->restrict_refcnt, 0);
4164#endif
Zhu Yib481de92007-09-25 17:54:57 -07004165
Assaf Krauss316c30d2008-03-14 10:38:46 -07004166 /**************************
4167 * 2. Initializing PCI bus
4168 **************************/
4169 if (pci_enable_device(pdev)) {
4170 err = -ENODEV;
4171 goto out_ieee80211_free_hw;
4172 }
4173
4174 pci_set_master(pdev);
4175
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004176 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004177 if (!err)
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004178 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4179 if (err) {
4180 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4181 if (!err)
4182 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4183 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004184 if (err) {
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004185 printk(KERN_WARNING "%s: No suitable DMA available.\n",
4186 DRV_NAME);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004187 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004188 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004189 }
4190
4191 err = pci_request_regions(pdev, DRV_NAME);
4192 if (err)
4193 goto out_pci_disable_device;
4194
4195 pci_set_drvdata(pdev, priv);
4196
4197 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4198 * PCI Tx retries from interfering with C3 CPU state */
4199 pci_write_config_byte(pdev, 0x41, 0x00);
4200
4201 /***********************
4202 * 3. Read REV register
4203 ***********************/
4204 priv->hw_base = pci_iomap(pdev, 0, 0);
4205 if (!priv->hw_base) {
4206 err = -ENODEV;
4207 goto out_pci_release_regions;
4208 }
4209
4210 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
4211 (unsigned long long) pci_resource_len(pdev, 0));
4212 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
4213
Tomas Winklerb661c812008-04-23 17:14:54 -07004214 iwl_hw_detect(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004215 printk(KERN_INFO DRV_NAME
Tomas Winklerb661c812008-04-23 17:14:54 -07004216 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
4217 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004218
Tomas Winkler91238712008-04-23 17:14:53 -07004219 /* amp init */
4220 err = priv->cfg->ops->lib->apm_ops.init(priv);
4221 if (err < 0) {
4222 IWL_DEBUG_INFO("Failed to init APMG\n");
4223 goto out_iounmap;
4224 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004225 /*****************
4226 * 4. Read EEPROM
4227 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07004228 /* Read the EEPROM */
4229 err = iwl_eeprom_init(priv);
4230 if (err) {
4231 IWL_ERROR("Unable to init EEPROM\n");
4232 goto out_iounmap;
4233 }
Tomas Winkler8614f362008-04-23 17:14:55 -07004234 err = iwl_eeprom_check_version(priv);
4235 if (err)
4236 goto out_iounmap;
4237
Ron Rindjunsky02883012008-05-15 13:53:53 +08004238 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004239 iwl_eeprom_get_mac(priv, priv->mac_addr);
4240 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
4241 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4242
4243 /************************
4244 * 5. Setup HW constants
4245 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08004246 if (iwl_set_hw_params(priv)) {
Tomas Winkler5425e492008-04-15 16:01:38 -07004247 IWL_ERROR("failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07004248 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004249 }
4250
4251 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08004252 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07004253 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07004254
Tomas Winkler6ba87952008-05-15 13:54:17 +08004255 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004256 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07004257 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004258 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004259
4260 /**********************************
4261 * 7. Initialize module parameters
4262 **********************************/
4263
4264 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004265 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07004266 set_bit(STATUS_RF_KILL_SW, &priv->status);
4267 IWL_DEBUG_INFO("Radio disabled.\n");
4268 }
4269
Assaf Krauss316c30d2008-03-14 10:38:46 -07004270 /********************
4271 * 8. Setup services
4272 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004273 spin_lock_irqsave(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004274 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004275 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004276
4277 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4278 if (err) {
4279 IWL_ERROR("failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08004280 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004281 }
4282
Assaf Krauss316c30d2008-03-14 10:38:46 -07004283
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004284 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08004285 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004286
4287 /********************
4288 * 9. Conclude
4289 ********************/
Zhu Yi5a66926a2008-01-14 17:46:18 -08004290 pci_save_state(pdev);
4291 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004292
Tomas Winkler6ba87952008-05-15 13:54:17 +08004293 /**********************************
4294 * 10. Setup and register mac80211
4295 **********************************/
4296
4297 err = iwl_setup_mac(priv);
4298 if (err)
4299 goto out_remove_sysfs;
4300
4301 err = iwl_dbgfs_register(priv, DRV_NAME);
4302 if (err)
4303 IWL_ERROR("failed to create debugfs files\n");
4304
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004305 err = iwl_rfkill_init(priv);
4306 if (err)
4307 IWL_ERROR("Unable to initialize RFKILL system. "
4308 "Ignoring error: %d\n", err);
4309 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004310 return 0;
4311
Assaf Krauss316c30d2008-03-14 10:38:46 -07004312 out_remove_sysfs:
4313 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004314 out_uninit_drv:
4315 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004316 out_free_eeprom:
4317 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004318 out_iounmap:
4319 pci_iounmap(pdev, priv->hw_base);
4320 out_pci_release_regions:
4321 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004322 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07004323 out_pci_disable_device:
4324 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004325 out_ieee80211_free_hw:
4326 ieee80211_free_hw(priv->hw);
4327 out:
4328 return err;
4329}
4330
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004331static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004332{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004333 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004334 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004335
4336 if (!priv)
4337 return;
4338
4339 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4340
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004341 iwl_dbgfs_unregister(priv);
4342 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4343
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004344 if (priv->mac80211_registered) {
4345 ieee80211_unregister_hw(priv->hw);
4346 priv->mac80211_registered = 0;
4347 }
4348
Zhu Yib481de92007-09-25 17:54:57 -07004349 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004350
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004351 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004352
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004353 /* make sure we flush any pending irq or
4354 * tasklet for the driver
4355 */
4356 spin_lock_irqsave(&priv->lock, flags);
4357 iwl4965_disable_interrupts(priv);
4358 spin_unlock_irqrestore(&priv->lock, flags);
4359
4360 iwl_synchronize_irq(priv);
4361
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004362 iwl_rfkill_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004363 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004364
4365 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08004366 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08004367 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004368
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08004369 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004370 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004371
Zhu Yib481de92007-09-25 17:54:57 -07004372
Mohamed Abbas948c1712007-10-25 17:15:45 +08004373 /*netif_stop_queue(dev); */
4374 flush_workqueue(priv->workqueue);
4375
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004376 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004377 * priv->workqueue... so we can't take down the workqueue
4378 * until now... */
4379 destroy_workqueue(priv->workqueue);
4380 priv->workqueue = NULL;
4381
Zhu Yib481de92007-09-25 17:54:57 -07004382 pci_iounmap(pdev, priv->hw_base);
4383 pci_release_regions(pdev);
4384 pci_disable_device(pdev);
4385 pci_set_drvdata(pdev, NULL);
4386
Tomas Winkler6ba87952008-05-15 13:54:17 +08004387 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004388
4389 if (priv->ibss_beacon)
4390 dev_kfree_skb(priv->ibss_beacon);
4391
4392 ieee80211_free_hw(priv->hw);
4393}
4394
4395#ifdef CONFIG_PM
4396
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004397static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07004398{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004399 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004400
Zhu Yie655b9f2008-01-24 02:19:38 -08004401 if (priv->is_open) {
4402 set_bit(STATUS_IN_SUSPEND, &priv->status);
4403 iwl4965_mac_stop(priv->hw);
4404 priv->is_open = 1;
4405 }
Zhu Yib481de92007-09-25 17:54:57 -07004406
Zhu Yib481de92007-09-25 17:54:57 -07004407 pci_set_power_state(pdev, PCI_D3hot);
4408
Zhu Yib481de92007-09-25 17:54:57 -07004409 return 0;
4410}
4411
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004412static int iwl4965_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004413{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004414 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004415
Zhu Yib481de92007-09-25 17:54:57 -07004416 pci_set_power_state(pdev, PCI_D0);
Zhu Yib481de92007-09-25 17:54:57 -07004417
Zhu Yie655b9f2008-01-24 02:19:38 -08004418 if (priv->is_open)
4419 iwl4965_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004420
Zhu Yie655b9f2008-01-24 02:19:38 -08004421 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004422 return 0;
4423}
4424
4425#endif /* CONFIG_PM */
4426
4427/*****************************************************************************
4428 *
4429 * driver and module entry point
4430 *
4431 *****************************************************************************/
4432
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004433/* Hardware specific file defines the PCI IDs table for that hardware module */
4434static struct pci_device_id iwl_hw_card_ids[] = {
4435 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4436 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004437#ifdef CONFIG_IWL5000
4438 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4439 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
4440 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
4441#endif /* CONFIG_IWL5000 */
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004442 {0}
4443};
4444MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4445
4446static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004447 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004448 .id_table = iwl_hw_card_ids,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004449 .probe = iwl4965_pci_probe,
4450 .remove = __devexit_p(iwl4965_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004451#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004452 .suspend = iwl4965_pci_suspend,
4453 .resume = iwl4965_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004454#endif
4455};
4456
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004457static int __init iwl4965_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004458{
4459
4460 int ret;
4461 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4462 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004463
4464 ret = iwl4965_rate_control_register();
4465 if (ret) {
4466 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
4467 return ret;
4468 }
4469
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004470 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004471 if (ret) {
4472 IWL_ERROR("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004473 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004474 }
Zhu Yib481de92007-09-25 17:54:57 -07004475
4476 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004477
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004478error_register:
4479 iwl4965_rate_control_unregister();
4480 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004481}
4482
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004483static void __exit iwl4965_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004484{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004485 pci_unregister_driver(&iwl_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004486 iwl4965_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004487}
4488
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004489module_exit(iwl4965_exit);
4490module_init(iwl4965_init);