blob: 7f65d9123b2ac01944f0cff56c947a2608b99a3c [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,
Rick Farrington25b3f572008-06-30 17:23:28 +0800761 le16_to_cpu(priv->active_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700762
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
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800797 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700798 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
799
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800800 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700801
Mohamed Abbasfde35712007-11-29 11:10:15 +0800802 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -0700803 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800804 return -EAGAIN;
805
806 cancel_delayed_work(&priv->scan_check);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800807 if (iwl_scan_cancel_timeout(priv, 100)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +0800808 IWL_WARNING("Aborted scan still in progress after 100ms\n");
809 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
810 return -EAGAIN;
811 }
812
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800813 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700814
815 return 0;
816}
817
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700818static void iwl4965_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700819{
Johannes Berg8318d782008-01-24 19:38:38 +0100820 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700821 struct ieee80211_rate *rate;
822 int i;
823
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700824 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800825 if (!hw) {
826 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
827 return;
828 }
Zhu Yib481de92007-09-25 17:54:57 -0700829
830 priv->active_rate = 0;
831 priv->active_rate_basic = 0;
832
Johannes Berg8318d782008-01-24 19:38:38 +0100833 for (i = 0; i < hw->n_bitrates; i++) {
834 rate = &(hw->bitrates[i]);
835 if (rate->hw_value < IWL_RATE_COUNT)
836 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -0700837 }
838
839 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
840 priv->active_rate, priv->active_rate_basic);
841
842 /*
843 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
844 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
845 * OFDM
846 */
847 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
848 priv->staging_rxon.cck_basic_rates =
849 ((priv->active_rate_basic &
850 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
851 else
852 priv->staging_rxon.cck_basic_rates =
853 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
854
855 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
856 priv->staging_rxon.ofdm_basic_rates =
857 ((priv->active_rate_basic &
858 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
859 IWL_FIRST_OFDM_RATE) & 0xFF;
860 else
861 priv->staging_rxon.ofdm_basic_rates =
862 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
863}
864
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800865#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -0700866
867#include "iwl-spectrum.h"
868
869#define BEACON_TIME_MASK_LOW 0x00FFFFFF
870#define BEACON_TIME_MASK_HIGH 0xFF000000
871#define TIME_UNIT 1024
872
873/*
874 * extended beacon time format
875 * time in usec will be changed into a 32-bit value in 8:24 format
876 * the high 1 byte is the beacon counts
877 * the lower 3 bytes is the time in usec within one beacon interval
878 */
879
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800880static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700881{
882 u32 quot;
883 u32 rem;
884 u32 interval = beacon_interval * 1024;
885
886 if (!interval || !usec)
887 return 0;
888
889 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
890 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
891
892 return (quot << 24) + rem;
893}
894
895/* base is usually what we get from ucode with each received frame,
896 * the same as HW timer counter counting down
897 */
898
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800899static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700900{
901 u32 base_low = base & BEACON_TIME_MASK_LOW;
902 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
903 u32 interval = beacon_interval * TIME_UNIT;
904 u32 res = (base & BEACON_TIME_MASK_HIGH) +
905 (addon & BEACON_TIME_MASK_HIGH);
906
907 if (base_low > addon_low)
908 res += base_low - addon_low;
909 else if (base_low < addon_low) {
910 res += interval + base_low - addon_low;
911 res += (1 << 24);
912 } else
913 res += (1 << 24);
914
915 return cpu_to_le32(res);
916}
917
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700918static int iwl4965_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700919 struct ieee80211_measurement_params *params,
920 u8 type)
921{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800922 struct iwl4965_spectrum_cmd spectrum;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800923 struct iwl_rx_packet *res;
Tomas Winkler857485c2008-03-21 13:53:44 -0700924 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700925 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
926 .data = (void *)&spectrum,
927 .meta.flags = CMD_WANT_SKB,
928 };
929 u32 add_time = le64_to_cpu(params->start_time);
930 int rc;
931 int spectrum_resp_status;
932 int duration = le16_to_cpu(params->duration);
933
Tomas Winkler3109ece2008-03-28 16:33:35 -0700934 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700935 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800936 iwl4965_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -0700937 le64_to_cpu(params->start_time) - priv->last_tsf,
938 le16_to_cpu(priv->rxon_timing.beacon_interval));
939
940 memset(&spectrum, 0, sizeof(spectrum));
941
942 spectrum.channel_count = cpu_to_le16(1);
943 spectrum.flags =
944 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
945 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
946 cmd.len = sizeof(spectrum);
947 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
948
Tomas Winkler3109ece2008-03-28 16:33:35 -0700949 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700950 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800951 iwl4965_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -0700952 add_time,
953 le16_to_cpu(priv->rxon_timing.beacon_interval));
954 else
955 spectrum.start_time = 0;
956
957 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
958 spectrum.channels[0].channel = params->channel;
959 spectrum.channels[0].type = type;
960 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
961 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
962 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
963
Tomas Winkler857485c2008-03-21 13:53:44 -0700964 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700965 if (rc)
966 return rc;
967
Tomas Winklerdb11d632008-05-05 10:22:33 +0800968 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700969 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
970 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
971 rc = -EIO;
972 }
973
974 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
975 switch (spectrum_resp_status) {
976 case 0: /* Command will be handled */
977 if (res->u.spectrum.id != 0xff) {
978 IWL_DEBUG_INFO
979 ("Replaced existing measurement: %d\n",
980 res->u.spectrum.id);
981 priv->measurement_status &= ~MEASUREMENT_READY;
982 }
983 priv->measurement_status |= MEASUREMENT_ACTIVE;
984 rc = 0;
985 break;
986
987 case 1: /* Command will not be handled */
988 rc = -EAGAIN;
989 break;
990 }
991
992 dev_kfree_skb_any(cmd.meta.u.skb);
993
994 return rc;
995}
996#endif
997
Zhu Yib481de92007-09-25 17:54:57 -0700998/******************************************************************************
999 *
1000 * Generic RX handler implementations
1001 *
1002 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +08001003static void iwl_rx_reply_alive(struct iwl_priv *priv,
1004 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001005{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001006 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +08001007 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001008 struct delayed_work *pwork;
1009
1010 palive = &pkt->u.alive_frame;
1011
1012 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1013 "0x%01X 0x%01X\n",
1014 palive->is_valid, palive->ver_type,
1015 palive->ver_subtype);
1016
1017 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1018 IWL_DEBUG_INFO("Initialization Alive received.\n");
1019 memcpy(&priv->card_alive_init,
1020 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001021 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001022 pwork = &priv->init_alive_start;
1023 } else {
1024 IWL_DEBUG_INFO("Runtime Alive received.\n");
1025 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001026 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001027 pwork = &priv->alive_start;
1028 }
1029
1030 /* We delay the ALIVE response by 5ms to
1031 * give the HW RF Kill time to activate... */
1032 if (palive->is_valid == UCODE_VALID_OK)
1033 queue_delayed_work(priv->workqueue, pwork,
1034 msecs_to_jiffies(5));
1035 else
1036 IWL_WARNING("uCode did not respond OK.\n");
1037}
1038
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001039static void iwl4965_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001040 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001041{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001042 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001043
1044 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1045 "seq 0x%04X ser 0x%08X\n",
1046 le32_to_cpu(pkt->u.err_resp.error_type),
1047 get_cmd_string(pkt->u.err_resp.cmd_id),
1048 pkt->u.err_resp.cmd_id,
1049 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1050 le32_to_cpu(pkt->u.err_resp.error_info));
1051}
1052
1053#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1054
Tomas Winklera55360e2008-05-05 10:22:28 +08001055static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001056{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001057 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001058 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001059 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001060 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1061 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1062 rxon->channel = csa->channel;
1063 priv->staging_rxon.channel = csa->channel;
1064}
1065
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001066static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001067 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001068{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001069#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Tomas Winklerdb11d632008-05-05 10:22:33 +08001070 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001071 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001072
1073 if (!report->state) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001074 IWL_DEBUG(IWL_DL_11H,
1075 "Spectrum Measure Notification: Start\n");
Zhu Yib481de92007-09-25 17:54:57 -07001076 return;
1077 }
1078
1079 memcpy(&priv->measure_report, report, sizeof(*report));
1080 priv->measurement_status |= MEASUREMENT_READY;
1081#endif
1082}
1083
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001084static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001085 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001086{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001087#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001088 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001089 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001090 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1091 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1092#endif
1093}
1094
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001095static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001096 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001097{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001098 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001099 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1100 "notification for %s:\n",
1101 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001102 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001103}
1104
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001105static void iwl4965_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001106{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001107 struct iwl_priv *priv =
1108 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001109 struct sk_buff *beacon;
1110
1111 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001112 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001113
1114 if (!beacon) {
1115 IWL_ERROR("update beacon failed\n");
1116 return;
1117 }
1118
1119 mutex_lock(&priv->mutex);
1120 /* new beacon skb is allocated every time; dispose previous.*/
1121 if (priv->ibss_beacon)
1122 dev_kfree_skb(priv->ibss_beacon);
1123
1124 priv->ibss_beacon = beacon;
1125 mutex_unlock(&priv->mutex);
1126
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001127 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001128}
1129
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001130/**
1131 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
1132 *
1133 * This callback is provided in order to send a statistics request.
1134 *
1135 * This timer function is continually reset to execute within
1136 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1137 * was received. We need to ensure we receive the statistics in order
1138 * to update the temperature used for calibrating the TXPOWER.
1139 */
1140static void iwl4965_bg_statistics_periodic(unsigned long data)
1141{
1142 struct iwl_priv *priv = (struct iwl_priv *)data;
1143
1144 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1145 return;
1146
1147 iwl_send_statistics_request(priv, CMD_ASYNC);
1148}
1149
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001150static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001151 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001152{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001153#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001154 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001155 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
Tomas Winklere7d326a2008-06-12 09:47:11 +08001156 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001157
1158 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1159 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +08001160 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -07001161 beacon->beacon_notify_hdr.failure_frame,
1162 le32_to_cpu(beacon->ibss_mgr_status),
1163 le32_to_cpu(beacon->high_tsf),
1164 le32_to_cpu(beacon->low_tsf), rate);
1165#endif
1166
1167 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
1168 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1169 queue_work(priv->workqueue, &priv->beacon_update);
1170}
1171
Zhu Yib481de92007-09-25 17:54:57 -07001172/* Handle notification from uCode that card's power state is changing
1173 * due to software, hardware, or critical temperature RFKILL */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001174static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001175 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001176{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001177 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001178 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1179 unsigned long status = priv->status;
1180
1181 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1182 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1183 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1184
1185 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1186 RF_CARD_DISABLED)) {
1187
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001188 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001189 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1190
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001191 if (!iwl_grab_nic_access(priv)) {
1192 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001193 priv, HBUS_TARG_MBX_C,
1194 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1195
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001196 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001197 }
1198
1199 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001200 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001201 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001202 if (!iwl_grab_nic_access(priv)) {
1203 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001204 priv, HBUS_TARG_MBX_C,
1205 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1206
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001207 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001208 }
1209 }
1210
1211 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001212 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001213 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001214 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1215 if (!iwl_grab_nic_access(priv))
1216 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001217 }
1218 }
1219
1220 if (flags & HW_CARD_DISABLED)
1221 set_bit(STATUS_RF_KILL_HW, &priv->status);
1222 else
1223 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1224
1225
1226 if (flags & SW_CARD_DISABLED)
1227 set_bit(STATUS_RF_KILL_SW, &priv->status);
1228 else
1229 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1230
1231 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +08001232 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001233
1234 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1235 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1236 (test_bit(STATUS_RF_KILL_SW, &status) !=
1237 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1238 queue_work(priv->workqueue, &priv->rf_kill);
1239 else
1240 wake_up_interruptible(&priv->wait_command_queue);
1241}
1242
1243/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001244 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001245 *
1246 * Setup the RX handlers for each of the reply types sent from the uCode
1247 * to the host.
1248 *
1249 * This function chains into the hardware specific files for them to setup
1250 * any hardware specific handlers as well.
1251 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001252static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001253{
Tomas Winkler885ba202008-05-29 16:34:55 +08001254 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001255 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
1256 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07001257 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001258 iwl4965_rx_spectrum_measure_notif;
1259 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001260 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001261 iwl4965_rx_pm_debug_statistics_notif;
1262 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001263
Ben Cahill9fbab512007-11-29 11:09:47 +08001264 /*
1265 * The same handler is used for both the REPLY to a discrete
1266 * statistics request from the host as well as for the periodic
1267 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001268 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001269 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1270 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +08001271
1272 iwl_setup_rx_scan_handlers(priv);
1273
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001274 /* status change handler */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001275 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001276
Tomas Winklerc1354752008-05-29 16:35:04 +08001277 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1278 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001279 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +08001280 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1281 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001282 /* block ack */
1283 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001284 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001285 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001286}
1287
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001288/*
1289 * this should be called while priv->lock is locked
1290*/
Tomas Winklera55360e2008-05-05 10:22:28 +08001291static void __iwl_rx_replenish(struct iwl_priv *priv)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001292{
Tomas Winklera55360e2008-05-05 10:22:28 +08001293 iwl_rx_allocate(priv);
1294 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001295}
1296
1297
Zhu Yib481de92007-09-25 17:54:57 -07001298/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001299 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001300 *
1301 * Uses the priv->rx_handlers callback function array to invoke
1302 * the appropriate handlers, including command responses,
1303 * frame-received notifications, and other notifications.
1304 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001305void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001306{
Tomas Winklera55360e2008-05-05 10:22:28 +08001307 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001308 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001309 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001310 u32 r, i;
1311 int reclaim;
1312 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001313 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001314 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001315
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001316 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1317 * buffer that the driver may process (last buffer filled by ucode). */
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001318 r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001319 i = rxq->read;
1320
1321 /* Rx interrupt, but nothing sent from uCode */
1322 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08001323 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001324
Tomas Winklera55360e2008-05-05 10:22:28 +08001325 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001326 fill_rx = 1;
1327
Zhu Yib481de92007-09-25 17:54:57 -07001328 while (i != r) {
1329 rxb = rxq->queue[i];
1330
Ben Cahill9fbab512007-11-29 11:09:47 +08001331 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001332 * then a bug has been introduced in the queue refilling
1333 * routines -- catch it here */
1334 BUG_ON(rxb == NULL);
1335
1336 rxq->queue[i] = NULL;
1337
1338 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07001339 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001340 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08001341 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001342
1343 /* Reclaim a command buffer only if this packet is a response
1344 * to a (driver-originated) command.
1345 * If the packet (e.g. Rx frame) originated from uCode,
1346 * there is no command buffer to reclaim.
1347 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1348 * but apparently a few don't get set; catch them here. */
1349 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1350 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001351 (pkt->hdr.cmd != REPLY_RX) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001352 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001353 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1354 (pkt->hdr.cmd != REPLY_TX);
1355
1356 /* Based on type of command response or notification,
1357 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001358 * rx_handlers table. See iwl4965_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001359 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001360 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1361 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001362 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1363 } else {
1364 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08001365 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07001366 "r %d i %d No handler needed for %s, 0x%02x\n",
1367 r, i, get_cmd_string(pkt->hdr.cmd),
1368 pkt->hdr.cmd);
1369 }
1370
1371 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001372 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07001373 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001374 * as we reclaim the driver command queue */
1375 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +08001376 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001377 else
1378 IWL_WARNING("Claim null rxb?\n");
1379 }
1380
1381 /* For now we just don't re-use anything. We can tweak this
1382 * later to try and re-use notification packets and SKBs that
1383 * fail to Rx correctly */
1384 if (rxb->skb != NULL) {
1385 priv->alloc_rxb_skb--;
1386 dev_kfree_skb_any(rxb->skb);
1387 rxb->skb = NULL;
1388 }
1389
1390 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07001391 priv->hw_params.rx_buf_size,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001392 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001393 spin_lock_irqsave(&rxq->lock, flags);
1394 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1395 spin_unlock_irqrestore(&rxq->lock, flags);
1396 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001397 /* If there are a lot of unused frames,
1398 * restock the Rx queue so ucode wont assert. */
1399 if (fill_rx) {
1400 count++;
1401 if (count >= 8) {
1402 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001403 __iwl_rx_replenish(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001404 count = 0;
1405 }
1406 }
Zhu Yib481de92007-09-25 17:54:57 -07001407 }
1408
1409 /* Backtrack one entry */
1410 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001411 iwl_rx_queue_restock(priv);
1412}
Tomas Winklera55360e2008-05-05 10:22:28 +08001413
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001414#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001415static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001416{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001417 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001418 DECLARE_MAC_BUF(mac);
1419
Zhu Yib481de92007-09-25 17:54:57 -07001420 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08001421 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001422 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1423 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1424 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1425 le32_to_cpu(rxon->filter_flags));
1426 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1427 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1428 rxon->ofdm_basic_rates);
1429 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Joe Perches0795af52007-10-03 17:59:30 -07001430 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
1431 print_mac(mac, rxon->node_addr));
1432 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
1433 print_mac(mac, rxon->bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07001434 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1435}
1436#endif
1437
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001438static void iwl4965_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001439{
1440 IWL_DEBUG_ISR("Enabling interrupts\n");
1441 set_bit(STATUS_INT_ENABLED, &priv->status);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001442 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001443}
1444
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001445/* call this function to flush any scheduled tasklet */
1446static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1447{
1448 /* wait to make sure we flush pedding tasklet*/
1449 synchronize_irq(priv->pci_dev->irq);
1450 tasklet_kill(&priv->irq_tasklet);
1451}
1452
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001453static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001454{
1455 clear_bit(STATUS_INT_ENABLED, &priv->status);
1456
1457 /* disable interrupts from uCode/NIC to host */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001458 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001459
1460 /* acknowledge/clear/reset any interrupts still pending
1461 * from uCode or flow handler (Rx/Tx DMA) */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001462 iwl_write32(priv, CSR_INT, 0xffffffff);
1463 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07001464 IWL_DEBUG_ISR("Disabled interrupts\n");
1465}
1466
Zhu Yib481de92007-09-25 17:54:57 -07001467
Zhu Yib481de92007-09-25 17:54:57 -07001468/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001469 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07001470 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001471static void iwl4965_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001472{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001473 /* Set the FW error flag -- cleared on iwl4965_down */
Zhu Yib481de92007-09-25 17:54:57 -07001474 set_bit(STATUS_FW_ERROR, &priv->status);
1475
1476 /* Cancel currently queued command. */
1477 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1478
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001479#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001480 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08001481 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08001482 iwl_dump_nic_event_log(priv);
Ester Kummerbf403db2008-05-05 10:22:40 +08001483 iwl4965_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001484 }
1485#endif
1486
1487 wake_up_interruptible(&priv->wait_command_queue);
1488
1489 /* Keep the restart process from trying to send host
1490 * commands by clearing the INIT status bit */
1491 clear_bit(STATUS_READY, &priv->status);
1492
1493 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001494 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07001495 "Restarting adapter due to uCode error.\n");
1496
Tomas Winkler3109ece2008-03-28 16:33:35 -07001497 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001498 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1499 sizeof(priv->recovery_rxon));
1500 priv->error_recovering = 1;
1501 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08001502 if (priv->cfg->mod_params->restart_fw)
1503 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001504 }
1505}
1506
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001507static void iwl4965_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001508{
1509 unsigned long flags;
1510
1511 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1512 sizeof(priv->staging_rxon));
1513 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001514 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001515
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001516 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07001517
1518 spin_lock_irqsave(&priv->lock, flags);
1519 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1520 priv->error_recovering = 0;
1521 spin_unlock_irqrestore(&priv->lock, flags);
1522}
1523
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001524static void iwl4965_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001525{
1526 u32 inta, handled = 0;
1527 u32 inta_fh;
1528 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001529#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001530 u32 inta_mask;
1531#endif
1532
1533 spin_lock_irqsave(&priv->lock, flags);
1534
1535 /* Ack/clear/reset pending uCode interrupts.
1536 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1537 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001538 inta = iwl_read32(priv, CSR_INT);
1539 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001540
1541 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1542 * Any new interrupts that happen after this, either while we're
1543 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001544 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1545 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001546
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001547#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001548 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001549 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001550 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001551 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1552 inta, inta_mask, inta_fh);
1553 }
1554#endif
1555
1556 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1557 * atomic, make sure that inta covers all the interrupts that
1558 * we've discovered, even if FH interrupt came in just after
1559 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001560 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001561 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001562 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001563 inta |= CSR_INT_BIT_FH_TX;
1564
1565 /* Now service all interrupt bits discovered above. */
1566 if (inta & CSR_INT_BIT_HW_ERR) {
1567 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1568
1569 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001570 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001571
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001572 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001573
1574 handled |= CSR_INT_BIT_HW_ERR;
1575
1576 spin_unlock_irqrestore(&priv->lock, flags);
1577
1578 return;
1579 }
1580
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001581#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001582 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001583 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001584 if (inta & CSR_INT_BIT_SCD)
1585 IWL_DEBUG_ISR("Scheduler finished to transmit "
1586 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001587
1588 /* Alive notification via Rx interrupt will do the real work */
1589 if (inta & CSR_INT_BIT_ALIVE)
1590 IWL_DEBUG_ISR("Alive interrupt\n");
1591 }
1592#endif
1593 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001594 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001595
Ben Cahill9fbab512007-11-29 11:09:47 +08001596 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001597 if (inta & CSR_INT_BIT_RF_KILL) {
1598 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001599 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001600 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1601 hw_rf_kill = 1;
1602
Ester Kummerf3d67992008-05-06 11:05:12 +08001603 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Zhu Yib481de92007-09-25 17:54:57 -07001604 hw_rf_kill ? "disable radio":"enable radio");
1605
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001606 /* driver only loads ucode once setting the interface up.
1607 * the driver as well won't allow loading if RFKILL is set
1608 * therefore no need to restart the driver from this handler
1609 */
1610 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status))
Zhu Yi53e49092007-12-06 16:08:44 +08001611 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001612
1613 handled |= CSR_INT_BIT_RF_KILL;
1614 }
1615
Ben Cahill9fbab512007-11-29 11:09:47 +08001616 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001617 if (inta & CSR_INT_BIT_CT_KILL) {
1618 IWL_ERROR("Microcode CT kill error detected.\n");
1619 handled |= CSR_INT_BIT_CT_KILL;
1620 }
1621
1622 /* Error detected by uCode */
1623 if (inta & CSR_INT_BIT_SW_ERR) {
1624 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1625 inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001626 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001627 handled |= CSR_INT_BIT_SW_ERR;
1628 }
1629
1630 /* uCode wakes up after power-down sleep */
1631 if (inta & CSR_INT_BIT_WAKEUP) {
1632 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001633 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001634 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1635 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1636 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1637 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1638 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1639 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001640
1641 handled |= CSR_INT_BIT_WAKEUP;
1642 }
1643
1644 /* All uCode command responses, including Tx command responses,
1645 * Rx "responses" (frame-received notification), and other
1646 * notifications from uCode come through here*/
1647 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001648 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001649 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1650 }
1651
1652 if (inta & CSR_INT_BIT_FH_TX) {
1653 IWL_DEBUG_ISR("Tx interrupt\n");
1654 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001655 /* FH finished to write, send event */
1656 priv->ucode_write_complete = 1;
1657 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001658 }
1659
1660 if (inta & ~handled)
1661 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1662
1663 if (inta & ~CSR_INI_SET_MASK) {
1664 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
1665 inta & ~CSR_INI_SET_MASK);
1666 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
1667 }
1668
1669 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001670 /* only Re-enable if diabled by irq */
1671 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1672 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001673
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001674#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001675 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001676 inta = iwl_read32(priv, CSR_INT);
1677 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1678 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001679 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1680 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1681 }
1682#endif
1683 spin_unlock_irqrestore(&priv->lock, flags);
1684}
1685
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001686static irqreturn_t iwl4965_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07001687{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001688 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07001689 u32 inta, inta_mask;
1690 u32 inta_fh;
1691 if (!priv)
1692 return IRQ_NONE;
1693
1694 spin_lock(&priv->lock);
1695
1696 /* Disable (but don't clear!) interrupts here to avoid
1697 * back-to-back ISRs and sporadic interrupts from our NIC.
1698 * If we have something to service, the tasklet will re-enable ints.
1699 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001700 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1701 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001702
1703 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001704 inta = iwl_read32(priv, CSR_INT);
1705 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001706
1707 /* Ignore interrupt if there's nothing in NIC to service.
1708 * This may be due to IRQ shared with another device,
1709 * or due to sporadic interrupts thrown from our NIC. */
1710 if (!inta && !inta_fh) {
1711 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1712 goto none;
1713 }
1714
1715 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08001716 /* Hardware disappeared. It might have already raised
1717 * an interrupt */
Zhu Yib481de92007-09-25 17:54:57 -07001718 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08001719 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07001720 }
1721
1722 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1723 inta, inta_mask, inta_fh);
1724
Joonwoo Park25c03d82008-01-23 10:15:20 -08001725 inta &= ~CSR_INT_BIT_SCD;
1726
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001727 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001728 if (likely(inta || inta_fh))
1729 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07001730
Oliver Neukum66fbb542007-11-15 09:31:10 +08001731 unplugged:
1732 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07001733 return IRQ_HANDLED;
1734
1735 none:
1736 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001737 /* only Re-enable if diabled by irq */
1738 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1739 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001740 spin_unlock(&priv->lock);
1741 return IRQ_NONE;
1742}
1743
Zhu Yib481de92007-09-25 17:54:57 -07001744/******************************************************************************
1745 *
1746 * uCode download functions
1747 *
1748 ******************************************************************************/
1749
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001750static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001751{
Tomas Winkler98c92212008-01-14 17:46:20 -08001752 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1753 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1754 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1755 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1756 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1757 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001758}
1759
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001760static void iwl4965_nic_start(struct iwl_priv *priv)
1761{
1762 /* Remove all resets to allow NIC to operate */
1763 iwl_write32(priv, CSR_RESET, 0);
1764}
1765
1766
Zhu Yib481de92007-09-25 17:54:57 -07001767/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001768 * iwl4965_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001769 *
1770 * Copy into buffers for card to fetch via bus-mastering
1771 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001772static int iwl4965_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001773{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001774 struct iwl_ucode *ucode;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001775 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001776 const struct firmware *ucode_raw;
Tomas Winkler4bf775c2008-03-04 18:09:31 -08001777 const char *name = priv->cfg->fw_name;
Zhu Yib481de92007-09-25 17:54:57 -07001778 u8 *src;
1779 size_t len;
1780 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
1781
1782 /* Ask kernel firmware_class module to get the boot firmware off disk.
1783 * request_firmware() is synchronous, file is in memory on return. */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001784 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
1785 if (ret < 0) {
1786 IWL_ERROR("%s firmware file req failed: Reason %d\n",
1787 name, ret);
Zhu Yib481de92007-09-25 17:54:57 -07001788 goto error;
1789 }
1790
1791 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1792 name, ucode_raw->size);
1793
1794 /* Make sure that we got at least our header! */
1795 if (ucode_raw->size < sizeof(*ucode)) {
1796 IWL_ERROR("File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001797 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001798 goto err_release;
1799 }
1800
1801 /* Data from ucode file: header followed by uCode images */
1802 ucode = (void *)ucode_raw->data;
1803
1804 ver = le32_to_cpu(ucode->ver);
1805 inst_size = le32_to_cpu(ucode->inst_size);
1806 data_size = le32_to_cpu(ucode->data_size);
1807 init_size = le32_to_cpu(ucode->init_size);
1808 init_data_size = le32_to_cpu(ucode->init_data_size);
1809 boot_size = le32_to_cpu(ucode->boot_size);
1810
1811 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
1812 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1813 inst_size);
1814 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1815 data_size);
1816 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1817 init_size);
1818 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1819 init_data_size);
1820 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1821 boot_size);
1822
1823 /* Verify size of file vs. image size info in file's header */
1824 if (ucode_raw->size < sizeof(*ucode) +
1825 inst_size + data_size + init_size +
1826 init_data_size + boot_size) {
1827
1828 IWL_DEBUG_INFO("uCode file size %d too small\n",
1829 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001830 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001831 goto err_release;
1832 }
1833
1834 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001835 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001836 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1837 inst_size);
1838 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001839 goto err_release;
1840 }
1841
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001842 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001843 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1844 data_size);
1845 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001846 goto err_release;
1847 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001848 if (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001849 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001850 ("uCode init instr len %d too large to fit in\n",
1851 init_size);
1852 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001853 goto err_release;
1854 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001855 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001856 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001857 ("uCode init data len %d too large to fit in\n",
1858 init_data_size);
1859 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001860 goto err_release;
1861 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001862 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001863 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001864 ("uCode boot instr len %d too large to fit in\n",
1865 boot_size);
1866 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001867 goto err_release;
1868 }
1869
1870 /* Allocate ucode buffers for card's bus-master loading ... */
1871
1872 /* Runtime instructions and 2 copies of data:
1873 * 1) unmodified from disk
1874 * 2) backup cache for save/restore during power-downs */
1875 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001876 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001877
1878 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001879 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001880
1881 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001882 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001883
1884 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001885 if (init_size && init_data_size) {
1886 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001887 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001888
Tomas Winkler90e759d2007-11-29 11:09:41 +08001889 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001890 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001891
1892 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1893 goto err_pci_alloc;
1894 }
Zhu Yib481de92007-09-25 17:54:57 -07001895
1896 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001897 if (boot_size) {
1898 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001899 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001900
Tomas Winkler90e759d2007-11-29 11:09:41 +08001901 if (!priv->ucode_boot.v_addr)
1902 goto err_pci_alloc;
1903 }
Zhu Yib481de92007-09-25 17:54:57 -07001904
1905 /* Copy images into buffers for card's bus-master reads ... */
1906
1907 /* Runtime instructions (first block of data in file) */
1908 src = &ucode->data[0];
1909 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001910 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001911 memcpy(priv->ucode_code.v_addr, src, len);
1912 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1913 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1914
1915 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001916 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001917 src = &ucode->data[inst_size];
1918 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001919 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001920 memcpy(priv->ucode_data.v_addr, src, len);
1921 memcpy(priv->ucode_data_backup.v_addr, src, len);
1922
1923 /* Initialization instructions (3rd block) */
1924 if (init_size) {
1925 src = &ucode->data[inst_size + data_size];
1926 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001927 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1928 len);
Zhu Yib481de92007-09-25 17:54:57 -07001929 memcpy(priv->ucode_init.v_addr, src, len);
1930 }
1931
1932 /* Initialization data (4th block) */
1933 if (init_data_size) {
1934 src = &ucode->data[inst_size + data_size + init_size];
1935 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001936 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1937 len);
Zhu Yib481de92007-09-25 17:54:57 -07001938 memcpy(priv->ucode_init_data.v_addr, src, len);
1939 }
1940
1941 /* Bootstrap instructions (5th block) */
1942 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1943 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001944 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001945 memcpy(priv->ucode_boot.v_addr, src, len);
1946
1947 /* We have our copies now, allow OS release its copies */
1948 release_firmware(ucode_raw);
1949 return 0;
1950
1951 err_pci_alloc:
1952 IWL_ERROR("failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001953 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001954 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001955
1956 err_release:
1957 release_firmware(ucode_raw);
1958
1959 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001960 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001961}
1962
Zhu Yib481de92007-09-25 17:54:57 -07001963/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001964 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001965 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001966 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001967 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001968static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001969{
Tomas Winkler57aab752008-04-14 21:16:03 -07001970 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001971
1972 IWL_DEBUG_INFO("Runtime Alive received.\n");
1973
1974 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1975 /* We had an error bringing up the hardware, so take it
1976 * all the way back down so we can try again */
1977 IWL_DEBUG_INFO("Alive failed.\n");
1978 goto restart;
1979 }
1980
1981 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1982 * This is a paranoid check, because we would not have gotten the
1983 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001984 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001985 /* Runtime instruction load was bad;
1986 * take it all the way back down so we can try again */
1987 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
1988 goto restart;
1989 }
1990
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08001991 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001992 ret = priv->cfg->ops->lib->alive_notify(priv);
1993 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -07001994 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
Tomas Winkler57aab752008-04-14 21:16:03 -07001995 ret);
Zhu Yib481de92007-09-25 17:54:57 -07001996 goto restart;
1997 }
1998
Ben Cahill9fbab512007-11-29 11:09:47 +08001999 /* After the ALIVE response, we can send host commands to 4965 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002000 set_bit(STATUS_ALIVE, &priv->status);
2001
Tomas Winklerfee12472008-04-03 16:05:21 -07002002 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002003 return;
2004
Johannes Berg36d68252008-05-15 12:55:26 +02002005 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002006
2007 priv->active_rate = priv->rates_mask;
2008 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2009
Tomas Winkler3109ece2008-03-28 16:33:35 -07002010 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002011 struct iwl_rxon_cmd *active_rxon =
2012 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002013
2014 memcpy(&priv->staging_rxon, &priv->active_rxon,
2015 sizeof(priv->staging_rxon));
2016 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2017 } else {
2018 /* Initialize our rx_config data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002019 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002020 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2021 }
2022
Ben Cahill9fbab512007-11-29 11:09:47 +08002023 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002024 iwl4965_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002025
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002026 iwl_reset_run_time_calib(priv);
2027
Zhu Yib481de92007-09-25 17:54:57 -07002028 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002029 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002030
2031 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002032 iwl_rf_kill_ct_config(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002033
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002034 iwl_leds_register(priv);
2035
Zhu Yib481de92007-09-25 17:54:57 -07002036 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002037 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002038 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002039
2040 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002041 iwl4965_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002042
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08002043 iwl_power_update_mode(priv, 1);
Mohamed Abbas84363e62008-04-04 16:59:58 -07002044 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002045
2046 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2047 iwl4965_set_mode(priv, priv->iw_mode);
2048
Zhu Yib481de92007-09-25 17:54:57 -07002049 return;
2050
2051 restart:
2052 queue_work(priv->workqueue, &priv->restart);
2053}
2054
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002055static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002056
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002057static void __iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002058{
2059 unsigned long flags;
2060 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002061
2062 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2063
Zhu Yib481de92007-09-25 17:54:57 -07002064 if (!exit_pending)
2065 set_bit(STATUS_EXIT_PENDING, &priv->status);
2066
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002067 iwl_leds_unregister(priv);
2068
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002069 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002070
2071 /* Unblock any waiting calls */
2072 wake_up_interruptible_all(&priv->wait_command_queue);
2073
Zhu Yib481de92007-09-25 17:54:57 -07002074 /* Wipe out the EXIT_PENDING status bit if we are not actually
2075 * exiting the module */
2076 if (!exit_pending)
2077 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2078
2079 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002080 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002081
2082 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002083 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002084 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002085 spin_unlock_irqrestore(&priv->lock, flags);
2086 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002087
2088 if (priv->mac80211_registered)
2089 ieee80211_stop_queues(priv->hw);
2090
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002091 /* If we have not previously called iwl4965_init() then
Zhu Yib481de92007-09-25 17:54:57 -07002092 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002093 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002094 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2095 STATUS_RF_KILL_HW |
2096 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2097 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002098 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2099 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002100 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002101 STATUS_IN_SUSPEND |
2102 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2103 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002104 goto exit;
2105 }
2106
2107 /* ...otherwise clear out all the status bits but the RF Kill and
2108 * SUSPEND bits and continue taking the NIC down. */
2109 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2110 STATUS_RF_KILL_HW |
2111 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2112 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002113 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2114 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002115 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2116 STATUS_IN_SUSPEND |
2117 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002118 STATUS_FW_ERROR |
2119 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2120 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002121
2122 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002123 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08002124 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002125 spin_unlock_irqrestore(&priv->lock, flags);
2126
Tomas Winklerda1bc452008-05-29 16:35:00 +08002127 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002128 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002129
2130 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002131 if (!iwl_grab_nic_access(priv)) {
2132 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002133 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002134 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002135 }
2136 spin_unlock_irqrestore(&priv->lock, flags);
2137
2138 udelay(5);
2139
Tomas Winkler7f066102008-05-29 16:34:57 +08002140 /* FIXME: apm_ops.suspend(priv) */
2141 priv->cfg->ops->lib->apm_ops.reset(priv);
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002142 priv->cfg->ops->lib->free_shared_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002143
2144 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002145 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002146
2147 if (priv->ibss_beacon)
2148 dev_kfree_skb(priv->ibss_beacon);
2149 priv->ibss_beacon = NULL;
2150
2151 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002152 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002153}
2154
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002155static void iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002156{
2157 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002158 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002159 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002160
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002161 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002162}
2163
2164#define MAX_HW_RESTARTS 5
2165
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002166static int __iwl4965_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002167{
Tomas Winkler57aab752008-04-14 21:16:03 -07002168 int i;
2169 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002170
2171 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2172 IWL_WARNING("Exit pending; will not bring the NIC up\n");
2173 return -EIO;
2174 }
2175
Reinette Chatree903fbd2008-01-30 22:05:15 -08002176 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
2177 IWL_ERROR("ucode not available for device bringup\n");
2178 return -EIO;
2179 }
2180
Zhu Yie655b9f2008-01-24 02:19:38 -08002181 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002182 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08002183 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2184 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002185 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002186 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002187
2188 if (!test_bit(STATUS_IN_SUSPEND, &priv->status) &&
2189 iwl_is_rfkill(priv)) {
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002190 IWL_WARNING("Radio disabled by %s RF Kill switch\n",
2191 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
2192 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07002193 }
2194
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002195 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002196
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002197 ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
2198 if (ret) {
2199 IWL_ERROR("Unable to allocate shared memory\n");
2200 return ret;
2201 }
2202
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002203 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002204 if (ret) {
2205 IWL_ERROR("Unable to init nic\n");
2206 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002207 }
2208
2209 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002210 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2211 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002212 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2213
2214 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002215 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002216 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002217
2218 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002219 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2220 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002221
2222 /* Copy original ucode data image from disk into backup cache.
2223 * This will be used to initialize the on-board processor's
2224 * data SRAM for a clean start when the runtime program first loads. */
2225 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08002226 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002227
Zhu Yie655b9f2008-01-24 02:19:38 -08002228 /* We return success when we resume from suspend and rf_kill is on. */
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002229 if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
2230 test_bit(STATUS_RF_KILL_SW, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002231 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002232
2233 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2234
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002235 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002236
2237 /* load bootstrap state machine,
2238 * load bootstrap program into processor's memory,
2239 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002240 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002241
Tomas Winkler57aab752008-04-14 21:16:03 -07002242 if (ret) {
2243 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07002244 continue;
2245 }
2246
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08002247 /* Clear out the uCode error bit if it is set */
2248 clear_bit(STATUS_FW_ERROR, &priv->status);
2249
Zhu Yib481de92007-09-25 17:54:57 -07002250 /* start card; "initialize" will load runtime ucode */
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08002251 iwl4965_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002252
Zhu Yib481de92007-09-25 17:54:57 -07002253 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2254
2255 return 0;
2256 }
2257
2258 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002259 __iwl4965_down(priv);
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002260 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002261
2262 /* tried to restart and config the device for as long as our
2263 * patience could withstand */
2264 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
2265 return -EIO;
2266}
2267
2268
2269/*****************************************************************************
2270 *
2271 * Workqueue callbacks
2272 *
2273 *****************************************************************************/
2274
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002275static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002276{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002277 struct iwl_priv *priv =
2278 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002279
2280 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2281 return;
2282
2283 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002284 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002285 mutex_unlock(&priv->mutex);
2286}
2287
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002288static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002289{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002290 struct iwl_priv *priv =
2291 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002292
2293 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2294 return;
2295
2296 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002297 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002298 mutex_unlock(&priv->mutex);
2299}
2300
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002301static void iwl4965_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002302{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002303 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07002304
2305 wake_up_interruptible(&priv->wait_command_queue);
2306
2307 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2308 return;
2309
2310 mutex_lock(&priv->mutex);
2311
Tomas Winklerfee12472008-04-03 16:05:21 -07002312 if (!iwl_is_rfkill(priv)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08002313 IWL_DEBUG(IWL_DL_RF_KILL,
Zhu Yib481de92007-09-25 17:54:57 -07002314 "HW and/or SW RF Kill no longer active, restarting "
2315 "device\n");
2316 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
2317 queue_work(priv->workqueue, &priv->restart);
2318 } else {
Mohamed Abbasad97edd2008-03-28 16:21:06 -07002319 /* make sure mac80211 stop sending Tx frame */
2320 if (priv->mac80211_registered)
2321 ieee80211_stop_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002322
2323 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2324 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2325 "disabled by SW switch\n");
2326 else
2327 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2328 "Kill switch must be turned off for "
2329 "wireless networking to work.\n");
2330 }
2331 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002332 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002333}
2334
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002335static void iwl4965_bg_set_monitor(struct work_struct *work)
2336{
2337 struct iwl_priv *priv = container_of(work,
2338 struct iwl_priv, set_monitor);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002339 int ret;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002340
2341 IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
2342
2343 mutex_lock(&priv->mutex);
2344
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002345 ret = iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR);
2346
2347 if (ret) {
2348 if (ret == -EAGAIN)
2349 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
2350 else
2351 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
2352 }
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002353
2354 mutex_unlock(&priv->mutex);
2355}
2356
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002357static void iwl_bg_run_time_calib_work(struct work_struct *work)
2358{
2359 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2360 run_time_calib_work);
2361
2362 mutex_lock(&priv->mutex);
2363
2364 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2365 test_bit(STATUS_SCANNING, &priv->status)) {
2366 mutex_unlock(&priv->mutex);
2367 return;
2368 }
2369
2370 if (priv->start_calib) {
2371 iwl_chain_noise_calibration(priv, &priv->statistics);
2372
2373 iwl_sensitivity_calibration(priv, &priv->statistics);
2374 }
2375
2376 mutex_unlock(&priv->mutex);
2377 return;
2378}
2379
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002380static void iwl4965_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002381{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002382 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002383
2384 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2385 return;
2386
2387 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002388 __iwl4965_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002389 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002390 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002391}
2392
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002393static void iwl4965_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002394{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002395 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002396
2397 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2398 return;
2399
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002400 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002401 queue_work(priv->workqueue, &priv->up);
2402}
2403
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002404static void iwl4965_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002405{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002406 struct iwl_priv *priv =
2407 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002408
2409 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2410 return;
2411
2412 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002413 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002414 mutex_unlock(&priv->mutex);
2415}
2416
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002417#define IWL_DELAY_NEXT_SCAN (HZ*2)
2418
Reinette Chatre508e32e2008-04-14 21:16:13 -07002419static void iwl4965_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002420{
Zhu Yib481de92007-09-25 17:54:57 -07002421 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002422 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07002423 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002424
2425 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2426 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
2427 return;
2428 }
2429
Joe Perches0795af52007-10-03 17:59:30 -07002430 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
2431 priv->assoc_id,
2432 print_mac(mac, priv->active_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07002433
2434
2435 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2436 return;
2437
Zhu Yib481de92007-09-25 17:54:57 -07002438
Reinette Chatre508e32e2008-04-14 21:16:13 -07002439 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002440 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002441
Tomas Winkler2a421b92008-06-12 09:47:10 +08002442 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002443
Zhu Yib481de92007-09-25 17:54:57 -07002444 conf = ieee80211_get_hw_conf(priv->hw);
2445
2446 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002447 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002448
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002449 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2450 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002451 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002452 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002453 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07002454 IWL_WARNING("REPLY_RXON_TIMING failed - "
2455 "Attempting to continue.\n");
2456
2457 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2458
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02002459 if (priv->current_ht_config.is_ht)
Tomas Winkler47c51962008-05-05 10:22:41 +08002460 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002461
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002462 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002463 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2464
2465 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2466 priv->assoc_id, priv->beacon_int);
2467
2468 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2469 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2470 else
2471 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2472
2473 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2474 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2475 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2476 else
2477 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2478
2479 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2480 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2481
2482 }
2483
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002484 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002485
2486 switch (priv->iw_mode) {
2487 case IEEE80211_IF_TYPE_STA:
Zhu Yib481de92007-09-25 17:54:57 -07002488 break;
2489
2490 case IEEE80211_IF_TYPE_IBSS:
2491
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002492 /* assume default assoc id */
2493 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002494
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002495 iwl_rxon_add_station(priv, priv->bssid, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002496 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002497
2498 break;
2499
2500 default:
2501 IWL_ERROR("%s Should not be called in %d mode\n",
2502 __FUNCTION__, priv->iw_mode);
2503 break;
2504 }
2505
Zhu Yib481de92007-09-25 17:54:57 -07002506 /* Enable Rx differential gain and sensitivity calibrations */
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07002507 iwl_chain_noise_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002508 priv->start_calib = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002509
2510 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2511 priv->assoc_station_added = 1;
2512
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002513 iwl4965_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002514
Mohamed Abbas5da4b552008-04-21 15:41:51 -07002515 iwl_power_update_mode(priv, 0);
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002516 /* we have just associated, don't start scan too early */
2517 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002518}
2519
2520
2521static void iwl4965_bg_post_associate(struct work_struct *data)
2522{
2523 struct iwl_priv *priv = container_of(data, struct iwl_priv,
2524 post_associate.work);
2525
2526 mutex_lock(&priv->mutex);
2527 iwl4965_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002528 mutex_unlock(&priv->mutex);
Reinette Chatre508e32e2008-04-14 21:16:13 -07002529
Zhu Yib481de92007-09-25 17:54:57 -07002530}
2531
Zhu Yi76bb77e2007-11-22 10:53:22 +08002532static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
2533
Tomas Winkler2a421b92008-06-12 09:47:10 +08002534static void iwl_bg_scan_completed(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002535{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002536 struct iwl_priv *priv =
2537 container_of(work, struct iwl_priv, scan_completed);
Zhu Yib481de92007-09-25 17:54:57 -07002538
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002539 IWL_DEBUG_SCAN("SCAN complete scan\n");
Zhu Yib481de92007-09-25 17:54:57 -07002540
2541 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2542 return;
2543
Zhu Yia0646472007-12-20 14:10:01 +08002544 if (test_bit(STATUS_CONF_PENDING, &priv->status))
2545 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
Zhu Yi76bb77e2007-11-22 10:53:22 +08002546
Zhu Yib481de92007-09-25 17:54:57 -07002547 ieee80211_scan_completed(priv->hw);
2548
2549 /* Since setting the TXPOWER may have been deferred while
2550 * performing the scan, fire one off */
2551 mutex_lock(&priv->mutex);
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002552 iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
Zhu Yib481de92007-09-25 17:54:57 -07002553 mutex_unlock(&priv->mutex);
2554}
2555
2556/*****************************************************************************
2557 *
2558 * mac80211 entry point functions
2559 *
2560 *****************************************************************************/
2561
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002562#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a66926a2008-01-14 17:46:18 -08002563
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002564static int iwl4965_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002565{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002566 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002567 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002568
2569 IWL_DEBUG_MAC80211("enter\n");
2570
Zhu Yi5a66926a2008-01-14 17:46:18 -08002571 if (pci_enable_device(priv->pci_dev)) {
2572 IWL_ERROR("Fail to pci_enable_device\n");
2573 return -ENODEV;
2574 }
2575 pci_restore_state(priv->pci_dev);
2576 pci_enable_msi(priv->pci_dev);
2577
2578 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
2579 DRV_NAME, priv);
2580 if (ret) {
2581 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
2582 goto out_disable_msi;
2583 }
2584
Zhu Yib481de92007-09-25 17:54:57 -07002585 /* we should be verifying the device is ready to be opened */
2586 mutex_lock(&priv->mutex);
2587
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002588 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a66926a2008-01-14 17:46:18 -08002589 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2590 * ucode filename and max sizes are card-specific. */
2591
2592 if (!priv->ucode_code.len) {
2593 ret = iwl4965_read_ucode(priv);
2594 if (ret) {
2595 IWL_ERROR("Could not read microcode: %d\n", ret);
2596 mutex_unlock(&priv->mutex);
2597 goto out_release_irq;
2598 }
2599 }
2600
Zhu Yie655b9f2008-01-24 02:19:38 -08002601 ret = __iwl4965_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002602
Zhu Yib481de92007-09-25 17:54:57 -07002603 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002604
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002605 iwl_rfkill_set_hw_state(priv);
2606
Zhu Yie655b9f2008-01-24 02:19:38 -08002607 if (ret)
2608 goto out_release_irq;
2609
2610 IWL_DEBUG_INFO("Start UP work done.\n");
2611
2612 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2613 return 0;
2614
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002615 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a66926a2008-01-14 17:46:18 -08002616 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002617 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2618 test_bit(STATUS_READY, &priv->status),
2619 UCODE_READY_TIMEOUT);
2620 if (!ret) {
2621 if (!test_bit(STATUS_READY, &priv->status)) {
2622 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2623 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2624 ret = -ETIMEDOUT;
2625 goto out_release_irq;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002626 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002627 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002628
2629 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002630 IWL_DEBUG_MAC80211("leave\n");
2631 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002632
2633out_release_irq:
2634 free_irq(priv->pci_dev->irq, priv);
2635out_disable_msi:
2636 pci_disable_msi(priv->pci_dev);
Zhu Yie655b9f2008-01-24 02:19:38 -08002637 pci_disable_device(priv->pci_dev);
2638 priv->is_open = 0;
2639 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08002640 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002641}
2642
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002643static void iwl4965_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002644{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002645 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002646
2647 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002648
Zhu Yie655b9f2008-01-24 02:19:38 -08002649 if (!priv->is_open) {
2650 IWL_DEBUG_MAC80211("leave - skip\n");
2651 return;
2652 }
2653
Zhu Yib481de92007-09-25 17:54:57 -07002654 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08002655
Tomas Winklerfee12472008-04-03 16:05:21 -07002656 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002657 /* stop mac, cancel any scan request and clear
2658 * RXON_FILTER_ASSOC_MSK BIT
2659 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08002660 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002661 iwl_scan_cancel_timeout(priv, 100);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002662 cancel_delayed_work(&priv->post_associate);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002663 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002664 }
2665
Zhu Yi5a66926a2008-01-14 17:46:18 -08002666 iwl4965_down(priv);
2667
2668 flush_workqueue(priv->workqueue);
2669 free_irq(priv->pci_dev->irq, priv);
2670 pci_disable_msi(priv->pci_dev);
2671 pci_save_state(priv->pci_dev);
2672 pci_disable_device(priv->pci_dev);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002673
Zhu Yib481de92007-09-25 17:54:57 -07002674 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002675}
2676
Johannes Berge039fa42008-05-15 12:55:29 +02002677static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002678{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002679 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002680
2681 IWL_DEBUG_MAC80211("enter\n");
2682
2683 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2684 IWL_DEBUG_MAC80211("leave - monitor\n");
Zhu Yi6afe6822008-07-01 09:20:34 +08002685 dev_kfree_skb_any(skb);
2686 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002687 }
2688
2689 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002690 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002691
Johannes Berge039fa42008-05-15 12:55:29 +02002692 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002693 dev_kfree_skb_any(skb);
2694
2695 IWL_DEBUG_MAC80211("leave\n");
2696 return 0;
2697}
2698
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002699static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002700 struct ieee80211_if_init_conf *conf)
2701{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002702 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002703 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -07002704 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002705
Johannes Berg32bfd352007-12-19 01:31:26 +01002706 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07002707
Johannes Berg32bfd352007-12-19 01:31:26 +01002708 if (priv->vif) {
2709 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08002710 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07002711 }
2712
2713 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01002714 priv->vif = conf->vif;
Zhu Yib481de92007-09-25 17:54:57 -07002715
2716 spin_unlock_irqrestore(&priv->lock, flags);
2717
2718 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02002719
2720 if (conf->mac_addr) {
2721 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
2722 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2723 }
Zhu Yib481de92007-09-25 17:54:57 -07002724
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002725 if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
2726 /* we are not ready, will run again when ready */
2727 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002728
Zhu Yib481de92007-09-25 17:54:57 -07002729 mutex_unlock(&priv->mutex);
2730
Zhu Yi5a66926a2008-01-14 17:46:18 -08002731 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002732 return 0;
2733}
2734
2735/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002736 * iwl4965_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07002737 *
2738 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2739 * be set inappropriately and the driver currently sets the hardware up to
2740 * use it whenever needed.
2741 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002742static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07002743{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002744 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002745 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002746 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08002747 int ret = 0;
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002748 u16 channel;
Zhu Yib481de92007-09-25 17:54:57 -07002749
2750 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002751 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002752
Zhu Yi12342c42007-12-20 11:27:32 +08002753 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
2754
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002755 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002756 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002757 goto out;
Mohamed Abbas64e72c3e2008-06-12 09:47:03 +08002758 }
2759
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002760 if (!conf->radio_enabled)
2761 iwl_radio_kill_sw_disable_radio(priv);
2762
Tomas Winklerfee12472008-04-03 16:05:21 -07002763 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002764 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002765 ret = -EIO;
2766 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002767 }
2768
Assaf Krauss1ea87392008-03-18 14:57:50 -07002769 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07002770 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08002771 IWL_DEBUG_MAC80211("leave - scanning\n");
2772 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002773 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08002774 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002775 }
2776
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002777 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2778 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002779 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07002780 IWL_DEBUG_MAC80211("leave - invalid channel\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002781 ret = -EINVAL;
2782 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002783 }
2784
Assaf Krauss398f9e72008-06-12 09:47:06 +08002785 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
2786 !is_channel_ibss(ch_info)) {
2787 IWL_ERROR("channel %d in band %d not IBSS channel\n",
2788 conf->channel->hw_value, conf->channel->band);
2789 ret = -EINVAL;
2790 goto out;
2791 }
2792
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002793 spin_lock_irqsave(&priv->lock, flags);
2794
Tomas Winkler78330fd2008-02-06 02:37:18 +02002795 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07002796 * from any ht related info since 2.4 does not
2797 * support ht */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002798 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
Zhu Yib481de92007-09-25 17:54:57 -07002799#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2800 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2801#endif
2802 )
2803 priv->staging_rxon.flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002804
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002805 iwl_set_rxon_channel(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002806
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002807 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07002808
2809 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01002810 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07002811 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002812 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002813
2814 spin_unlock_irqrestore(&priv->lock, flags);
2815
2816#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2817 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002818 iwl4965_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002819 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002820 }
2821#endif
2822
Zhu Yib481de92007-09-25 17:54:57 -07002823 if (!conf->radio_enabled) {
2824 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002825 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002826 }
2827
Tomas Winklerfee12472008-04-03 16:05:21 -07002828 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002829 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002830 ret = -EIO;
2831 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002832 }
2833
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002834 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2835 priv->tx_power_user_lmt, conf->power_level);
2836
2837 iwl_set_tx_power(priv, conf->power_level, false);
2838
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002839 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002840
2841 if (memcmp(&priv->active_rxon,
2842 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002843 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002844 else
2845 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2846
2847 IWL_DEBUG_MAC80211("leave\n");
2848
Zhu Yia0646472007-12-20 14:10:01 +08002849out:
2850 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08002851 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002852 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002853}
2854
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002855static void iwl4965_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002856{
Tomas Winkler857485c2008-03-21 13:53:44 -07002857 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002858
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002859 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002860 return;
2861
2862 /* The following should be done only at AP bring up */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +08002863 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07002864
2865 /* RXON - unassoc (to set timing command) */
2866 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002867 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002868
2869 /* RXON Timing */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002870 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2871 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002872 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002873 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002874 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07002875 IWL_WARNING("REPLY_RXON_TIMING failed - "
2876 "Attempting to continue.\n");
2877
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002878 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002879
2880 /* FIXME: what should be the assoc_id for AP? */
2881 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2882 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2883 priv->staging_rxon.flags |=
2884 RXON_FLG_SHORT_PREAMBLE_MSK;
2885 else
2886 priv->staging_rxon.flags &=
2887 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2888
2889 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2890 if (priv->assoc_capability &
2891 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2892 priv->staging_rxon.flags |=
2893 RXON_FLG_SHORT_SLOT_MSK;
2894 else
2895 priv->staging_rxon.flags &=
2896 ~RXON_FLG_SHORT_SLOT_MSK;
2897
2898 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2899 priv->staging_rxon.flags &=
2900 ~RXON_FLG_SHORT_SLOT_MSK;
2901 }
2902 /* restore RXON assoc */
2903 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002904 iwl4965_commit_rxon(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002905 iwl4965_activate_qos(priv, 1);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002906 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002907 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002908 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002909
2910 /* FIXME - we need to add code here to detect a totally new
2911 * configuration, reset the AP, unassoc, rxon timing, assoc,
2912 * clear sta table, add BCAST sta... */
2913}
2914
Johannes Berg32bfd352007-12-19 01:31:26 +01002915static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
2916 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002917 struct ieee80211_if_conf *conf)
2918{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002919 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07002920 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002921 unsigned long flags;
2922 int rc;
2923
2924 if (conf == NULL)
2925 return -EIO;
2926
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002927 if (priv->vif != vif) {
2928 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002929 return 0;
2930 }
2931
Zhu Yib481de92007-09-25 17:54:57 -07002932 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
2933 (!conf->beacon || !conf->ssid_len)) {
2934 IWL_DEBUG_MAC80211
2935 ("Leaving in AP mode because HostAPD is not ready.\n");
2936 return 0;
2937 }
2938
Tomas Winklerfee12472008-04-03 16:05:21 -07002939 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08002940 return -EAGAIN;
2941
Zhu Yib481de92007-09-25 17:54:57 -07002942 mutex_lock(&priv->mutex);
2943
Zhu Yib481de92007-09-25 17:54:57 -07002944 if (conf->bssid)
Joe Perches0795af52007-10-03 17:59:30 -07002945 IWL_DEBUG_MAC80211("bssid: %s\n",
2946 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07002947
Johannes Berg4150c572007-09-17 01:29:23 -04002948/*
2949 * very dubious code was here; the probe filtering flag is never set:
2950 *
Zhu Yib481de92007-09-25 17:54:57 -07002951 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2952 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002953 */
Zhu Yib481de92007-09-25 17:54:57 -07002954
2955 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2956 if (!conf->bssid) {
2957 conf->bssid = priv->mac_addr;
2958 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Joe Perches0795af52007-10-03 17:59:30 -07002959 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
2960 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07002961 }
2962 if (priv->ibss_beacon)
2963 dev_kfree_skb(priv->ibss_beacon);
2964
2965 priv->ibss_beacon = conf->beacon;
2966 }
2967
Tomas Winklerfee12472008-04-03 16:05:21 -07002968 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08002969 goto done;
2970
Zhu Yib481de92007-09-25 17:54:57 -07002971 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2972 !is_multicast_ether_addr(conf->bssid)) {
2973 /* If there is currently a HW scan going on in the background
2974 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002975 if (iwl_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07002976 IWL_WARNING("Aborted scan still in progress "
2977 "after 100ms\n");
2978 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2979 mutex_unlock(&priv->mutex);
2980 return -EAGAIN;
2981 }
2982 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2983
2984 /* TODO: Audit driver for usage of these members and see
2985 * if mac80211 deprecates them (priv->bssid looks like it
2986 * shouldn't be there, but I haven't scanned the IBSS code
2987 * to verify) - jpk */
2988 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
2989
2990 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002991 iwl4965_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002992 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002993 rc = iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002994 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002995 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07002996 priv, priv->active_rxon.bssid_addr, 1);
2997 }
2998
2999 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003000 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07003001 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003002 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003003 }
3004
Mohamed Abbasfde35712007-11-29 11:10:15 +08003005 done:
Zhu Yib481de92007-09-25 17:54:57 -07003006 spin_lock_irqsave(&priv->lock, flags);
3007 if (!conf->ssid_len)
3008 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3009 else
3010 memcpy(priv->essid, conf->ssid, conf->ssid_len);
3011
3012 priv->essid_len = conf->ssid_len;
3013 spin_unlock_irqrestore(&priv->lock, flags);
3014
3015 IWL_DEBUG_MAC80211("leave\n");
3016 mutex_unlock(&priv->mutex);
3017
3018 return 0;
3019}
3020
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003021static void iwl4965_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04003022 unsigned int changed_flags,
3023 unsigned int *total_flags,
3024 int mc_count, struct dev_addr_list *mc_list)
3025{
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08003026 struct iwl_priv *priv = hw->priv;
Rick Farrington25b3f572008-06-30 17:23:28 +08003027
3028 if (changed_flags & (*total_flags) & FIF_OTHER_BSS) {
3029 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
3030 IEEE80211_IF_TYPE_MNTR,
3031 changed_flags, *total_flags);
3032 /* queue work 'cuz mac80211 is holding a lock which
3033 * prevents us from issuing (synchronous) f/w cmds */
3034 queue_work(priv->workqueue, &priv->set_monitor);
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08003035 }
Rick Farrington25b3f572008-06-30 17:23:28 +08003036 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI |
3037 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04003038}
3039
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003040static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003041 struct ieee80211_if_init_conf *conf)
3042{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003043 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003044
3045 IWL_DEBUG_MAC80211("enter\n");
3046
3047 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003048
Tomas Winklerfee12472008-04-03 16:05:21 -07003049 if (iwl_is_ready_rf(priv)) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003050 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003051 cancel_delayed_work(&priv->post_associate);
3052 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3053 iwl4965_commit_rxon(priv);
3054 }
Johannes Berg32bfd352007-12-19 01:31:26 +01003055 if (priv->vif == conf->vif) {
3056 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003057 memset(priv->bssid, 0, ETH_ALEN);
3058 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3059 priv->essid_len = 0;
3060 }
3061 mutex_unlock(&priv->mutex);
3062
3063 IWL_DEBUG_MAC80211("leave\n");
3064
3065}
Johannes Berg471b3ef2007-12-28 14:32:58 +01003066
Tomas Winkler3109ece2008-03-28 16:33:35 -07003067#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Johannes Berg471b3ef2007-12-28 14:32:58 +01003068static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
3069 struct ieee80211_vif *vif,
3070 struct ieee80211_bss_conf *bss_conf,
3071 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02003072{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003073 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02003074
Tomas Winkler3109ece2008-03-28 16:33:35 -07003075 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
3076
Johannes Berg471b3ef2007-12-28 14:32:58 +01003077 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003078 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
3079 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003080 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02003081 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3082 else
3083 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3084 }
3085
Johannes Berg471b3ef2007-12-28 14:32:58 +01003086 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003087 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01003088 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02003089 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
3090 else
3091 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
3092 }
3093
Tomas Winkler98952d52008-03-28 16:33:33 -07003094 if (changes & BSS_CHANGED_HT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003095 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
Tomas Winkler98952d52008-03-28 16:33:33 -07003096 iwl4965_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003097 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07003098 }
3099
Johannes Berg471b3ef2007-12-28 14:32:58 +01003100 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003101 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003102 /* This should never happen as this function should
3103 * never be called from interrupt context. */
3104 if (WARN_ON_ONCE(in_interrupt()))
3105 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003106 if (bss_conf->assoc) {
3107 priv->assoc_id = bss_conf->aid;
3108 priv->beacon_int = bss_conf->beacon_int;
3109 priv->timestamp = bss_conf->timestamp;
3110 priv->assoc_capability = bss_conf->assoc_capability;
3111 priv->next_scan_jiffies = jiffies +
3112 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003113 mutex_lock(&priv->mutex);
3114 iwl4965_post_associate(priv);
3115 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003116 } else {
3117 priv->assoc_id = 0;
3118 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3119 }
3120 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3121 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003122 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003123 }
3124
Tomas Winkler220173b2007-10-16 00:50:25 +02003125}
Zhu Yib481de92007-09-25 17:54:57 -07003126
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003127static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07003128{
3129 int rc = 0;
3130 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003131 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003132
3133 IWL_DEBUG_MAC80211("enter\n");
3134
mabbas052c4b92007-10-25 17:15:43 +08003135 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003136 spin_lock_irqsave(&priv->lock, flags);
3137
Tomas Winklerfee12472008-04-03 16:05:21 -07003138 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003139 rc = -EIO;
3140 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3141 goto out_unlock;
3142 }
3143
3144 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
3145 rc = -EIO;
3146 IWL_ERROR("ERROR: APs don't scan\n");
3147 goto out_unlock;
3148 }
3149
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003150 /* we don't schedule scan within next_scan_jiffies period */
3151 if (priv->next_scan_jiffies &&
3152 time_after(priv->next_scan_jiffies, jiffies)) {
3153 rc = -EAGAIN;
3154 goto out_unlock;
3155 }
Zhu Yib481de92007-09-25 17:54:57 -07003156 /* if we just finished scan ask for delay */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003157 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
3158 IWL_DELAY_NEXT_SCAN, jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07003159 rc = -EAGAIN;
3160 goto out_unlock;
3161 }
3162 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003163 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
Tomas Winkler2a421b92008-06-12 09:47:10 +08003164 iwl_escape_essid(ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07003165
3166 priv->one_direct_scan = 1;
3167 priv->direct_ssid_len = (u8)
3168 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
3169 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003170 } else
3171 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003172
Tomas Winkler2a421b92008-06-12 09:47:10 +08003173 rc = iwl_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003174
3175 IWL_DEBUG_MAC80211("leave\n");
3176
3177out_unlock:
3178 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08003179 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003180
3181 return rc;
3182}
3183
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003184static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
3185 struct ieee80211_key_conf *keyconf, const u8 *addr,
3186 u32 iv32, u16 *phase1key)
3187{
3188 struct iwl_priv *priv = hw->priv;
3189 u8 sta_id = IWL_INVALID_STATION;
3190 unsigned long flags;
3191 __le16 key_flags = 0;
3192 int i;
3193 DECLARE_MAC_BUF(mac);
3194
3195 IWL_DEBUG_MAC80211("enter\n");
3196
Tomas Winkler947b13a2008-04-16 16:34:48 -07003197 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003198 if (sta_id == IWL_INVALID_STATION) {
3199 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3200 print_mac(mac, addr));
3201 return;
3202 }
3203
Tomas Winkler2a421b92008-06-12 09:47:10 +08003204 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003205
3206 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
3207 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
3208 key_flags &= ~STA_KEY_FLG_INVALID;
3209
Tomas Winkler5425e492008-04-15 16:01:38 -07003210 if (sta_id == priv->hw_params.bcast_sta_id)
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003211 key_flags |= STA_KEY_MULTICAST_MSK;
3212
3213 spin_lock_irqsave(&priv->sta_lock, flags);
3214
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003215 priv->stations[sta_id].sta.key.key_flags = key_flags;
3216 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
3217
3218 for (i = 0; i < 5; i++)
3219 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
3220 cpu_to_le16(phase1key[i]);
3221
3222 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
3223 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3224
Tomas Winkler133636d2008-05-05 10:22:34 +08003225 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003226
3227 spin_unlock_irqrestore(&priv->sta_lock, flags);
3228
3229 IWL_DEBUG_MAC80211("leave\n");
3230}
3231
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003232static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Zhu Yib481de92007-09-25 17:54:57 -07003233 const u8 *local_addr, const u8 *addr,
3234 struct ieee80211_key_conf *key)
3235{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003236 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07003237 DECLARE_MAC_BUF(mac);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003238 int ret = 0;
3239 u8 sta_id = IWL_INVALID_STATION;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003240 u8 is_default_wep_key = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003241
3242 IWL_DEBUG_MAC80211("enter\n");
3243
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003244 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07003245 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3246 return -EOPNOTSUPP;
3247 }
3248
3249 if (is_zero_ether_addr(addr))
3250 /* only support pairwise keys */
3251 return -EOPNOTSUPP;
3252
Tomas Winkler947b13a2008-04-16 16:34:48 -07003253 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003254 if (sta_id == IWL_INVALID_STATION) {
3255 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3256 print_mac(mac, addr));
3257 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003258
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003259 }
Zhu Yib481de92007-09-25 17:54:57 -07003260
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003261 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003262 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003263 mutex_unlock(&priv->mutex);
3264
3265 /* If we are getting WEP group key and we didn't receive any key mapping
3266 * so far, we are in legacy wep mode (group key only), otherwise we are
3267 * in 1X mode.
3268 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07003269 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003270 priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3271 if (cmd == SET_KEY)
3272 is_default_wep_key = !priv->key_mapping_key;
3273 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003274 is_default_wep_key =
3275 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003276 }
mabbas052c4b92007-10-25 17:15:43 +08003277
Zhu Yib481de92007-09-25 17:54:57 -07003278 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003279 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003280 if (is_default_wep_key)
3281 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003282 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003283 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003284
3285 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003286 break;
3287 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003288 if (is_default_wep_key)
3289 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003290 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003291 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003292
3293 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003294 break;
3295 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003296 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003297 }
3298
3299 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003300
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003301 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003302}
3303
Johannes Berge100bb62008-04-30 18:51:21 +02003304static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07003305 const struct ieee80211_tx_queue_params *params)
3306{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003307 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003308 unsigned long flags;
3309 int q;
Zhu Yib481de92007-09-25 17:54:57 -07003310
3311 IWL_DEBUG_MAC80211("enter\n");
3312
Tomas Winklerfee12472008-04-03 16:05:21 -07003313 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003314 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3315 return -EIO;
3316 }
3317
3318 if (queue >= AC_NUM) {
3319 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3320 return 0;
3321 }
3322
Zhu Yib481de92007-09-25 17:54:57 -07003323 if (!priv->qos_data.qos_enable) {
3324 priv->qos_data.qos_active = 0;
3325 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
3326 return 0;
3327 }
3328 q = AC_NUM - 1 - queue;
3329
3330 spin_lock_irqsave(&priv->lock, flags);
3331
3332 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3333 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3334 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3335 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01003336 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07003337
3338 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3339 priv->qos_data.qos_active = 1;
3340
3341 spin_unlock_irqrestore(&priv->lock, flags);
3342
3343 mutex_lock(&priv->mutex);
3344 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003345 iwl4965_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003346 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003347 iwl4965_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003348
3349 mutex_unlock(&priv->mutex);
3350
Zhu Yib481de92007-09-25 17:54:57 -07003351 IWL_DEBUG_MAC80211("leave\n");
3352 return 0;
3353}
3354
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003355static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003356 struct ieee80211_tx_queue_stats *stats)
3357{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003358 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003359 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003360 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003361 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003362 unsigned long flags;
3363
3364 IWL_DEBUG_MAC80211("enter\n");
3365
Tomas Winklerfee12472008-04-03 16:05:21 -07003366 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003367 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3368 return -EIO;
3369 }
3370
3371 spin_lock_irqsave(&priv->lock, flags);
3372
3373 for (i = 0; i < AC_NUM; i++) {
3374 txq = &priv->txq[i];
3375 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003376 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003377
Johannes Berg57ffc582008-04-29 17:18:59 +02003378 stats[i].len = q->n_window - avail;
3379 stats[i].limit = q->n_window - q->high_mark;
3380 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003381
3382 }
3383 spin_unlock_irqrestore(&priv->lock, flags);
3384
3385 IWL_DEBUG_MAC80211("leave\n");
3386
3387 return 0;
3388}
3389
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003390static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003391 struct ieee80211_low_level_stats *stats)
3392{
Ester Kummerbf403db2008-05-05 10:22:40 +08003393 struct iwl_priv *priv = hw->priv;
3394
3395 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003396 IWL_DEBUG_MAC80211("enter\n");
3397 IWL_DEBUG_MAC80211("leave\n");
3398
3399 return 0;
3400}
3401
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003402static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003403{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003404 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003405 unsigned long flags;
3406
3407 mutex_lock(&priv->mutex);
3408 IWL_DEBUG_MAC80211("enter\n");
3409
Zhu Yib481de92007-09-25 17:54:57 -07003410 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003411 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07003412 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003413
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003414 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003415
3416 cancel_delayed_work(&priv->post_associate);
3417
3418 spin_lock_irqsave(&priv->lock, flags);
3419 priv->assoc_id = 0;
3420 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003421 priv->assoc_station_added = 0;
3422
3423 /* new association get rid of ibss beacon skb */
3424 if (priv->ibss_beacon)
3425 dev_kfree_skb(priv->ibss_beacon);
3426
3427 priv->ibss_beacon = NULL;
3428
3429 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003430 priv->timestamp = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003431 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
3432 priv->beacon_int = 0;
3433
3434 spin_unlock_irqrestore(&priv->lock, flags);
3435
Tomas Winklerfee12472008-04-03 16:05:21 -07003436 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08003437 IWL_DEBUG_MAC80211("leave - not ready\n");
3438 mutex_unlock(&priv->mutex);
3439 return;
3440 }
3441
mabbas052c4b92007-10-25 17:15:43 +08003442 /* we are restarting association process
3443 * clear RXON_FILTER_ASSOC_MSK bit
3444 */
3445 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003446 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08003447 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003448 iwl4965_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08003449 }
3450
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003451 iwl_power_update_mode(priv, 0);
3452
Zhu Yib481de92007-09-25 17:54:57 -07003453 /* Per mac80211.h: This is only used in IBSS mode... */
3454 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
mabbas052c4b92007-10-25 17:15:43 +08003455
Zhu Yib481de92007-09-25 17:54:57 -07003456 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3457 mutex_unlock(&priv->mutex);
3458 return;
3459 }
3460
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003461 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003462
3463 mutex_unlock(&priv->mutex);
3464
3465 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003466}
3467
Johannes Berge039fa42008-05-15 12:55:29 +02003468static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003469{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003470 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003471 unsigned long flags;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003472 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07003473
3474 mutex_lock(&priv->mutex);
3475 IWL_DEBUG_MAC80211("enter\n");
3476
Tomas Winklerfee12472008-04-03 16:05:21 -07003477 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003478 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3479 mutex_unlock(&priv->mutex);
3480 return -EIO;
3481 }
3482
3483 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
3484 IWL_DEBUG_MAC80211("leave - not IBSS\n");
3485 mutex_unlock(&priv->mutex);
3486 return -EIO;
3487 }
3488
3489 spin_lock_irqsave(&priv->lock, flags);
3490
3491 if (priv->ibss_beacon)
3492 dev_kfree_skb(priv->ibss_beacon);
3493
3494 priv->ibss_beacon = skb;
3495
3496 priv->assoc_id = 0;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003497 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
3498 priv->timestamp = le64_to_cpu(timestamp) + (priv->beacon_int * 1000);
Zhu Yib481de92007-09-25 17:54:57 -07003499
3500 IWL_DEBUG_MAC80211("leave\n");
3501 spin_unlock_irqrestore(&priv->lock, flags);
3502
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003503 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003504
Assaf Kraussc46fbef2008-06-12 09:47:05 +08003505 iwl4965_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003506
3507 mutex_unlock(&priv->mutex);
3508
3509 return 0;
3510}
3511
Zhu Yib481de92007-09-25 17:54:57 -07003512/*****************************************************************************
3513 *
3514 * sysfs attributes
3515 *
3516 *****************************************************************************/
3517
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003518#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003519
3520/*
3521 * The following adds a new attribute to the sysfs representation
3522 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3523 * used for controlling the debug level.
3524 *
3525 * See the level definitions in iwl for details.
3526 */
3527
Ester Kummer8cf769c2008-05-06 11:05:11 +08003528static ssize_t show_debug_level(struct device *d,
3529 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003530{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003531 struct iwl_priv *priv = d->driver_data;
3532
3533 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003534}
Ester Kummer8cf769c2008-05-06 11:05:11 +08003535static ssize_t store_debug_level(struct device *d,
3536 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003537 const char *buf, size_t count)
3538{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003539 struct iwl_priv *priv = d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003540 char *p = (char *)buf;
3541 u32 val;
3542
3543 val = simple_strtoul(p, &p, 0);
3544 if (p == buf)
3545 printk(KERN_INFO DRV_NAME
3546 ": %s is not in hex or decimal form.\n", buf);
3547 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08003548 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003549
3550 return strnlen(buf, count);
3551}
3552
Ester Kummer8cf769c2008-05-06 11:05:11 +08003553static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3554 show_debug_level, store_debug_level);
3555
Zhu Yib481de92007-09-25 17:54:57 -07003556
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003557#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003558
Zhu Yib481de92007-09-25 17:54:57 -07003559
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003560static ssize_t show_version(struct device *d,
3561 struct device_attribute *attr, char *buf)
3562{
3563 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08003564 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08003565 ssize_t pos = 0;
3566 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003567
3568 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08003569 pos += sprintf(buf + pos,
3570 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3571 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003572 palive->ucode_major, palive->ucode_minor,
3573 palive->sw_rev[0], palive->sw_rev[1],
3574 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003575 else
Tomas Winklerf236a262008-06-30 17:23:02 +08003576 pos += sprintf(buf + pos, "fw not loaded\n");
3577
3578 if (priv->eeprom) {
3579 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3580 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3581 eeprom_ver);
3582 } else {
3583 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3584 }
3585
3586 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003587}
3588
3589static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3590
Zhu Yib481de92007-09-25 17:54:57 -07003591static ssize_t show_temperature(struct device *d,
3592 struct device_attribute *attr, char *buf)
3593{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003594 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003595
Tomas Winklerfee12472008-04-03 16:05:21 -07003596 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003597 return -EAGAIN;
3598
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003599 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003600}
3601
3602static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3603
3604static ssize_t show_rs_window(struct device *d,
3605 struct device_attribute *attr,
3606 char *buf)
3607{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003608 struct iwl_priv *priv = d->driver_data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003609 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003610}
3611static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
3612
3613static ssize_t show_tx_power(struct device *d,
3614 struct device_attribute *attr, char *buf)
3615{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003616 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003617 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003618}
3619
3620static ssize_t store_tx_power(struct device *d,
3621 struct device_attribute *attr,
3622 const char *buf, size_t count)
3623{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003624 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003625 char *p = (char *)buf;
3626 u32 val;
3627
3628 val = simple_strtoul(p, &p, 10);
3629 if (p == buf)
3630 printk(KERN_INFO DRV_NAME
3631 ": %s is not in decimal form.\n", buf);
3632 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003633 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07003634
3635 return count;
3636}
3637
3638static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3639
3640static ssize_t show_flags(struct device *d,
3641 struct device_attribute *attr, char *buf)
3642{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003643 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003644
3645 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3646}
3647
3648static ssize_t store_flags(struct device *d,
3649 struct device_attribute *attr,
3650 const char *buf, size_t count)
3651{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003652 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003653 u32 flags = simple_strtoul(buf, NULL, 0);
3654
3655 mutex_lock(&priv->mutex);
3656 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3657 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003658 if (iwl_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07003659 IWL_WARNING("Could not cancel scan.\n");
3660 else {
3661 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
3662 flags);
3663 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003664 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003665 }
3666 }
3667 mutex_unlock(&priv->mutex);
3668
3669 return count;
3670}
3671
3672static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3673
3674static ssize_t show_filter_flags(struct device *d,
3675 struct device_attribute *attr, char *buf)
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
3679 return sprintf(buf, "0x%04X\n",
3680 le32_to_cpu(priv->active_rxon.filter_flags));
3681}
3682
3683static ssize_t store_filter_flags(struct device *d,
3684 struct device_attribute *attr,
3685 const char *buf, size_t count)
3686{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003687 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003688 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3689
3690 mutex_lock(&priv->mutex);
3691 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3692 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003693 if (iwl_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07003694 IWL_WARNING("Could not cancel scan.\n");
3695 else {
3696 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3697 "0x%04X\n", filter_flags);
3698 priv->staging_rxon.filter_flags =
3699 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003700 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003701 }
3702 }
3703 mutex_unlock(&priv->mutex);
3704
3705 return count;
3706}
3707
3708static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3709 store_filter_flags);
3710
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003711#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003712
3713static ssize_t show_measurement(struct device *d,
3714 struct device_attribute *attr, char *buf)
3715{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003716 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003717 struct iwl4965_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003718 u32 size = sizeof(measure_report), len = 0, ofs = 0;
3719 u8 *data = (u8 *) & measure_report;
3720 unsigned long flags;
3721
3722 spin_lock_irqsave(&priv->lock, flags);
3723 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3724 spin_unlock_irqrestore(&priv->lock, flags);
3725 return 0;
3726 }
3727 memcpy(&measure_report, &priv->measure_report, size);
3728 priv->measurement_status = 0;
3729 spin_unlock_irqrestore(&priv->lock, flags);
3730
3731 while (size && (PAGE_SIZE - len)) {
3732 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3733 PAGE_SIZE - len, 1);
3734 len = strlen(buf);
3735 if (PAGE_SIZE - len)
3736 buf[len++] = '\n';
3737
3738 ofs += 16;
3739 size -= min(size, 16U);
3740 }
3741
3742 return len;
3743}
3744
3745static ssize_t store_measurement(struct device *d,
3746 struct device_attribute *attr,
3747 const char *buf, size_t count)
3748{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003749 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003750 struct ieee80211_measurement_params params = {
3751 .channel = le16_to_cpu(priv->active_rxon.channel),
3752 .start_time = cpu_to_le64(priv->last_tsf),
3753 .duration = cpu_to_le16(1),
3754 };
3755 u8 type = IWL_MEASURE_BASIC;
3756 u8 buffer[32];
3757 u8 channel;
3758
3759 if (count) {
3760 char *p = buffer;
3761 strncpy(buffer, buf, min(sizeof(buffer), count));
3762 channel = simple_strtoul(p, NULL, 0);
3763 if (channel)
3764 params.channel = channel;
3765
3766 p = buffer;
3767 while (*p && *p != ' ')
3768 p++;
3769 if (*p)
3770 type = simple_strtoul(p + 1, NULL, 0);
3771 }
3772
3773 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3774 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003775 iwl4965_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07003776
3777 return count;
3778}
3779
3780static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3781 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003782#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07003783
3784static ssize_t store_retry_rate(struct device *d,
3785 struct device_attribute *attr,
3786 const char *buf, size_t count)
3787{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003788 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003789
3790 priv->retry_rate = simple_strtoul(buf, NULL, 0);
3791 if (priv->retry_rate <= 0)
3792 priv->retry_rate = 1;
3793
3794 return count;
3795}
3796
3797static ssize_t show_retry_rate(struct device *d,
3798 struct device_attribute *attr, char *buf)
3799{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003800 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003801 return sprintf(buf, "%d", priv->retry_rate);
3802}
3803
3804static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3805 store_retry_rate);
3806
3807static ssize_t store_power_level(struct device *d,
3808 struct device_attribute *attr,
3809 const char *buf, size_t count)
3810{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003811 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003812 int rc;
3813 int mode;
3814
3815 mode = simple_strtoul(buf, NULL, 0);
3816 mutex_lock(&priv->mutex);
3817
Tomas Winklerfee12472008-04-03 16:05:21 -07003818 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003819 rc = -EAGAIN;
3820 goto out;
3821 }
3822
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003823 rc = iwl_power_set_user_mode(priv, mode);
3824 if (rc) {
3825 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3826 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003827 }
Zhu Yib481de92007-09-25 17:54:57 -07003828 rc = count;
3829
3830 out:
3831 mutex_unlock(&priv->mutex);
3832 return rc;
3833}
3834
3835#define MAX_WX_STRING 80
3836
3837/* Values are in microsecond */
3838static const s32 timeout_duration[] = {
3839 350000,
3840 250000,
3841 75000,
3842 37000,
3843 25000,
3844};
3845static const s32 period_duration[] = {
3846 400000,
3847 700000,
3848 1000000,
3849 1000000,
3850 1000000
3851};
3852
3853static ssize_t show_power_level(struct device *d,
3854 struct device_attribute *attr, char *buf)
3855{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003856 struct iwl_priv *priv = dev_get_drvdata(d);
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003857 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07003858 char *p = buf;
3859
3860 p += sprintf(p, "%d ", level);
3861 switch (level) {
3862 case IWL_POWER_MODE_CAM:
3863 case IWL_POWER_AC:
3864 p += sprintf(p, "(AC)");
3865 break;
3866 case IWL_POWER_BATTERY:
3867 p += sprintf(p, "(BATTERY)");
3868 break;
3869 default:
3870 p += sprintf(p,
3871 "(Timeout %dms, Period %dms)",
3872 timeout_duration[level - 1] / 1000,
3873 period_duration[level - 1] / 1000);
3874 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003875/*
Zhu Yib481de92007-09-25 17:54:57 -07003876 if (!(priv->power_mode & IWL_POWER_ENABLED))
3877 p += sprintf(p, " OFF\n");
3878 else
3879 p += sprintf(p, " \n");
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003880*/
3881 p += sprintf(p, " \n");
Zhu Yib481de92007-09-25 17:54:57 -07003882 return (p - buf + 1);
Zhu Yib481de92007-09-25 17:54:57 -07003883}
3884
3885static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3886 store_power_level);
3887
3888static ssize_t show_channels(struct device *d,
3889 struct device_attribute *attr, char *buf)
3890{
Ester Kummer5d72a1f2008-06-13 15:44:53 +08003891
3892 struct iwl_priv *priv = dev_get_drvdata(d);
3893 struct ieee80211_channel *channels = NULL;
3894 const struct ieee80211_supported_band *supp_band = NULL;
3895 int len = 0, i;
3896 int count = 0;
3897
3898 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
3899 return -EAGAIN;
3900
3901 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
3902 channels = supp_band->channels;
3903 count = supp_band->n_channels;
3904
3905 len += sprintf(&buf[len],
3906 "Displaying %d channels in 2.4GHz band "
3907 "(802.11bg):\n", count);
3908
3909 for (i = 0; i < count; i++)
3910 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3911 ieee80211_frequency_to_channel(
3912 channels[i].center_freq),
3913 channels[i].max_power,
3914 channels[i].flags & IEEE80211_CHAN_RADAR ?
3915 " (IEEE 802.11h required)" : "",
3916 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3917 || (channels[i].flags &
3918 IEEE80211_CHAN_RADAR)) ? "" :
3919 ", IBSS",
3920 channels[i].flags &
3921 IEEE80211_CHAN_PASSIVE_SCAN ?
3922 "passive only" : "active/passive");
3923
3924 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
3925 channels = supp_band->channels;
3926 count = supp_band->n_channels;
3927
3928 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
3929 "(802.11a):\n", count);
3930
3931 for (i = 0; i < count; i++)
3932 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3933 ieee80211_frequency_to_channel(
3934 channels[i].center_freq),
3935 channels[i].max_power,
3936 channels[i].flags & IEEE80211_CHAN_RADAR ?
3937 " (IEEE 802.11h required)" : "",
3938 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3939 || (channels[i].flags &
3940 IEEE80211_CHAN_RADAR)) ? "" :
3941 ", IBSS",
3942 channels[i].flags &
3943 IEEE80211_CHAN_PASSIVE_SCAN ?
3944 "passive only" : "active/passive");
3945
3946 return len;
Zhu Yib481de92007-09-25 17:54:57 -07003947}
3948
3949static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
3950
3951static ssize_t show_statistics(struct device *d,
3952 struct device_attribute *attr, char *buf)
3953{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003954 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003955 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003956 u32 len = 0, ofs = 0;
3957 u8 *data = (u8 *) & priv->statistics;
3958 int rc = 0;
3959
Tomas Winklerfee12472008-04-03 16:05:21 -07003960 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003961 return -EAGAIN;
3962
3963 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07003964 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003965 mutex_unlock(&priv->mutex);
3966
3967 if (rc) {
3968 len = sprintf(buf,
3969 "Error sending statistics request: 0x%08X\n", rc);
3970 return len;
3971 }
3972
3973 while (size && (PAGE_SIZE - len)) {
3974 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3975 PAGE_SIZE - len, 1);
3976 len = strlen(buf);
3977 if (PAGE_SIZE - len)
3978 buf[len++] = '\n';
3979
3980 ofs += 16;
3981 size -= min(size, 16U);
3982 }
3983
3984 return len;
3985}
3986
3987static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
3988
Zhu Yib481de92007-09-25 17:54:57 -07003989static ssize_t show_status(struct device *d,
3990 struct device_attribute *attr, char *buf)
3991{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003992 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winklerfee12472008-04-03 16:05:21 -07003993 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003994 return -EAGAIN;
3995 return sprintf(buf, "0x%08x\n", (int)priv->status);
3996}
3997
3998static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
3999
Zhu Yib481de92007-09-25 17:54:57 -07004000/*****************************************************************************
4001 *
4002 * driver setup and teardown
4003 *
4004 *****************************************************************************/
4005
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004006static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004007{
4008 priv->workqueue = create_workqueue(DRV_NAME);
4009
4010 init_waitqueue_head(&priv->wait_command_queue);
4011
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004012 INIT_WORK(&priv->up, iwl4965_bg_up);
4013 INIT_WORK(&priv->restart, iwl4965_bg_restart);
4014 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004015 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
4016 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08004017 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08004018 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004019 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08004020 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
4021 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08004022
4023 /* FIXME : remove when resolved PENDING */
4024 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4025 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004026
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004027 if (priv->cfg->ops->lib->setup_deferred_work)
4028 priv->cfg->ops->lib->setup_deferred_work(priv);
4029
4030 init_timer(&priv->statistics_periodic);
4031 priv->statistics_periodic.data = (unsigned long)priv;
4032 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07004033
4034 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004035 iwl4965_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004036}
4037
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004038static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004039{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004040 if (priv->cfg->ops->lib->cancel_deferred_work)
4041 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004042
Joonwoo Park3ae6a052007-11-29 10:43:16 +09004043 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004044 cancel_delayed_work(&priv->scan_check);
4045 cancel_delayed_work(&priv->alive_start);
4046 cancel_delayed_work(&priv->post_associate);
4047 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004048 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07004049}
4050
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004051static struct attribute *iwl4965_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004052 &dev_attr_channels.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004053 &dev_attr_flags.attr,
4054 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004055#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004056 &dev_attr_measurement.attr,
4057#endif
4058 &dev_attr_power_level.attr,
4059 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004060 &dev_attr_rs_window.attr,
4061 &dev_attr_statistics.attr,
4062 &dev_attr_status.attr,
4063 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004064 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08004065#ifdef CONFIG_IWLWIFI_DEBUG
4066 &dev_attr_debug_level.attr,
4067#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08004068 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004069
4070 NULL
4071};
4072
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004073static struct attribute_group iwl4965_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004074 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004075 .attrs = iwl4965_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004076};
4077
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004078static struct ieee80211_ops iwl4965_hw_ops = {
4079 .tx = iwl4965_mac_tx,
4080 .start = iwl4965_mac_start,
4081 .stop = iwl4965_mac_stop,
4082 .add_interface = iwl4965_mac_add_interface,
4083 .remove_interface = iwl4965_mac_remove_interface,
4084 .config = iwl4965_mac_config,
4085 .config_interface = iwl4965_mac_config_interface,
4086 .configure_filter = iwl4965_configure_filter,
4087 .set_key = iwl4965_mac_set_key,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004088 .update_tkip_key = iwl4965_mac_update_tkip_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004089 .get_stats = iwl4965_mac_get_stats,
4090 .get_tx_stats = iwl4965_mac_get_tx_stats,
4091 .conf_tx = iwl4965_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004092 .reset_tsf = iwl4965_mac_reset_tsf,
4093 .beacon_update = iwl4965_mac_beacon_update,
Johannes Berg471b3ef2007-12-28 14:32:58 +01004094 .bss_info_changed = iwl4965_bss_info_changed,
Ron Rindjunsky9ab46172007-12-25 17:00:38 +02004095 .ampdu_action = iwl4965_mac_ampdu_action,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004096 .hw_scan = iwl4965_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004097};
4098
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004099static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004100{
4101 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004102 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004103 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08004104 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004105 unsigned long flags;
Zhu Yi5a66926a2008-01-14 17:46:18 -08004106 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07004107
Assaf Krauss316c30d2008-03-14 10:38:46 -07004108 /************************
4109 * 1. Allocating HW data
4110 ************************/
4111
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004112 /* Disabling hardware scan means that mac80211 will perform scans
4113 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004114 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08004115 if (cfg->mod_params->debug & IWL_DL_INFO)
4116 dev_printk(KERN_DEBUG, &(pdev->dev),
4117 "Disabling hw_scan\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004118 iwl4965_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004119 }
4120
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004121 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
4122 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07004123 err = -ENOMEM;
4124 goto out;
4125 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004126 priv = hw->priv;
4127 /* At this point both hw and priv are allocated. */
4128
Zhu Yib481de92007-09-25 17:54:57 -07004129 SET_IEEE80211_DEV(hw, &pdev->dev);
4130
4131 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08004132 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07004133 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004134
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004135#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08004136 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07004137 atomic_set(&priv->restrict_refcnt, 0);
4138#endif
Zhu Yib481de92007-09-25 17:54:57 -07004139
Assaf Krauss316c30d2008-03-14 10:38:46 -07004140 /**************************
4141 * 2. Initializing PCI bus
4142 **************************/
4143 if (pci_enable_device(pdev)) {
4144 err = -ENODEV;
4145 goto out_ieee80211_free_hw;
4146 }
4147
4148 pci_set_master(pdev);
4149
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004150 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004151 if (!err)
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004152 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4153 if (err) {
4154 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4155 if (!err)
4156 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4157 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004158 if (err) {
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004159 printk(KERN_WARNING "%s: No suitable DMA available.\n",
4160 DRV_NAME);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004161 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004162 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004163 }
4164
4165 err = pci_request_regions(pdev, DRV_NAME);
4166 if (err)
4167 goto out_pci_disable_device;
4168
4169 pci_set_drvdata(pdev, priv);
4170
4171 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4172 * PCI Tx retries from interfering with C3 CPU state */
4173 pci_write_config_byte(pdev, 0x41, 0x00);
4174
4175 /***********************
4176 * 3. Read REV register
4177 ***********************/
4178 priv->hw_base = pci_iomap(pdev, 0, 0);
4179 if (!priv->hw_base) {
4180 err = -ENODEV;
4181 goto out_pci_release_regions;
4182 }
4183
4184 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
4185 (unsigned long long) pci_resource_len(pdev, 0));
4186 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
4187
Tomas Winklerb661c812008-04-23 17:14:54 -07004188 iwl_hw_detect(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004189 printk(KERN_INFO DRV_NAME
Tomas Winklerb661c812008-04-23 17:14:54 -07004190 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
4191 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004192
Tomas Winkler91238712008-04-23 17:14:53 -07004193 /* amp init */
4194 err = priv->cfg->ops->lib->apm_ops.init(priv);
4195 if (err < 0) {
4196 IWL_DEBUG_INFO("Failed to init APMG\n");
4197 goto out_iounmap;
4198 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004199 /*****************
4200 * 4. Read EEPROM
4201 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07004202 /* Read the EEPROM */
4203 err = iwl_eeprom_init(priv);
4204 if (err) {
4205 IWL_ERROR("Unable to init EEPROM\n");
4206 goto out_iounmap;
4207 }
Tomas Winkler8614f362008-04-23 17:14:55 -07004208 err = iwl_eeprom_check_version(priv);
4209 if (err)
4210 goto out_iounmap;
4211
Ron Rindjunsky02883012008-05-15 13:53:53 +08004212 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004213 iwl_eeprom_get_mac(priv, priv->mac_addr);
4214 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
4215 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4216
4217 /************************
4218 * 5. Setup HW constants
4219 ************************/
Ron Rindjunskyda154e302008-06-30 17:23:20 +08004220 if (iwl_set_hw_params(priv)) {
Tomas Winkler5425e492008-04-15 16:01:38 -07004221 IWL_ERROR("failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07004222 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004223 }
4224
4225 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08004226 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07004227 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07004228
Tomas Winkler6ba87952008-05-15 13:54:17 +08004229 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004230 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07004231 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004232 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004233
4234 /**********************************
4235 * 7. Initialize module parameters
4236 **********************************/
4237
4238 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004239 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07004240 set_bit(STATUS_RF_KILL_SW, &priv->status);
4241 IWL_DEBUG_INFO("Radio disabled.\n");
4242 }
4243
Assaf Krauss316c30d2008-03-14 10:38:46 -07004244 /********************
4245 * 8. Setup services
4246 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004247 spin_lock_irqsave(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004248 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004249 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004250
4251 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4252 if (err) {
4253 IWL_ERROR("failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08004254 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004255 }
4256
Assaf Krauss316c30d2008-03-14 10:38:46 -07004257
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004258 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08004259 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004260
4261 /********************
4262 * 9. Conclude
4263 ********************/
Zhu Yi5a66926a2008-01-14 17:46:18 -08004264 pci_save_state(pdev);
4265 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004266
Tomas Winkler6ba87952008-05-15 13:54:17 +08004267 /**********************************
4268 * 10. Setup and register mac80211
4269 **********************************/
4270
4271 err = iwl_setup_mac(priv);
4272 if (err)
4273 goto out_remove_sysfs;
4274
4275 err = iwl_dbgfs_register(priv, DRV_NAME);
4276 if (err)
4277 IWL_ERROR("failed to create debugfs files\n");
4278
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004279 err = iwl_rfkill_init(priv);
4280 if (err)
4281 IWL_ERROR("Unable to initialize RFKILL system. "
4282 "Ignoring error: %d\n", err);
4283 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004284 return 0;
4285
Assaf Krauss316c30d2008-03-14 10:38:46 -07004286 out_remove_sysfs:
4287 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004288 out_uninit_drv:
4289 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004290 out_free_eeprom:
4291 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004292 out_iounmap:
4293 pci_iounmap(pdev, priv->hw_base);
4294 out_pci_release_regions:
4295 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004296 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07004297 out_pci_disable_device:
4298 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004299 out_ieee80211_free_hw:
4300 ieee80211_free_hw(priv->hw);
4301 out:
4302 return err;
4303}
4304
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004305static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004306{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004307 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004308 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004309
4310 if (!priv)
4311 return;
4312
4313 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4314
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004315 iwl_dbgfs_unregister(priv);
4316 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4317
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004318 if (priv->mac80211_registered) {
4319 ieee80211_unregister_hw(priv->hw);
4320 priv->mac80211_registered = 0;
4321 }
4322
Zhu Yib481de92007-09-25 17:54:57 -07004323 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004324
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004325 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004326
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004327 /* make sure we flush any pending irq or
4328 * tasklet for the driver
4329 */
4330 spin_lock_irqsave(&priv->lock, flags);
4331 iwl4965_disable_interrupts(priv);
4332 spin_unlock_irqrestore(&priv->lock, flags);
4333
4334 iwl_synchronize_irq(priv);
4335
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004336 iwl_rfkill_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004337 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004338
4339 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08004340 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08004341 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004342
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08004343 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004344 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004345
Zhu Yib481de92007-09-25 17:54:57 -07004346
Mohamed Abbas948c1712007-10-25 17:15:45 +08004347 /*netif_stop_queue(dev); */
4348 flush_workqueue(priv->workqueue);
4349
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004350 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004351 * priv->workqueue... so we can't take down the workqueue
4352 * until now... */
4353 destroy_workqueue(priv->workqueue);
4354 priv->workqueue = NULL;
4355
Zhu Yib481de92007-09-25 17:54:57 -07004356 pci_iounmap(pdev, priv->hw_base);
4357 pci_release_regions(pdev);
4358 pci_disable_device(pdev);
4359 pci_set_drvdata(pdev, NULL);
4360
Tomas Winkler6ba87952008-05-15 13:54:17 +08004361 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004362
4363 if (priv->ibss_beacon)
4364 dev_kfree_skb(priv->ibss_beacon);
4365
4366 ieee80211_free_hw(priv->hw);
4367}
4368
4369#ifdef CONFIG_PM
4370
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004371static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07004372{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004373 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004374
Zhu Yie655b9f2008-01-24 02:19:38 -08004375 if (priv->is_open) {
4376 set_bit(STATUS_IN_SUSPEND, &priv->status);
4377 iwl4965_mac_stop(priv->hw);
4378 priv->is_open = 1;
4379 }
Zhu Yib481de92007-09-25 17:54:57 -07004380
Zhu Yib481de92007-09-25 17:54:57 -07004381 pci_set_power_state(pdev, PCI_D3hot);
4382
Zhu Yib481de92007-09-25 17:54:57 -07004383 return 0;
4384}
4385
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004386static int iwl4965_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004387{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004388 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004389
Zhu Yib481de92007-09-25 17:54:57 -07004390 pci_set_power_state(pdev, PCI_D0);
Zhu Yib481de92007-09-25 17:54:57 -07004391
Zhu Yie655b9f2008-01-24 02:19:38 -08004392 if (priv->is_open)
4393 iwl4965_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004394
Zhu Yie655b9f2008-01-24 02:19:38 -08004395 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004396 return 0;
4397}
4398
4399#endif /* CONFIG_PM */
4400
4401/*****************************************************************************
4402 *
4403 * driver and module entry point
4404 *
4405 *****************************************************************************/
4406
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004407/* Hardware specific file defines the PCI IDs table for that hardware module */
4408static struct pci_device_id iwl_hw_card_ids[] = {
4409 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4410 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004411#ifdef CONFIG_IWL5000
4412 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4413 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
4414 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
4415#endif /* CONFIG_IWL5000 */
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004416 {0}
4417};
4418MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4419
4420static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004421 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004422 .id_table = iwl_hw_card_ids,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004423 .probe = iwl4965_pci_probe,
4424 .remove = __devexit_p(iwl4965_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004425#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004426 .suspend = iwl4965_pci_suspend,
4427 .resume = iwl4965_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004428#endif
4429};
4430
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004431static int __init iwl4965_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004432{
4433
4434 int ret;
4435 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4436 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004437
4438 ret = iwl4965_rate_control_register();
4439 if (ret) {
4440 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
4441 return ret;
4442 }
4443
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004444 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004445 if (ret) {
4446 IWL_ERROR("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004447 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004448 }
Zhu Yib481de92007-09-25 17:54:57 -07004449
4450 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004451
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004452error_register:
4453 iwl4965_rate_control_unregister();
4454 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004455}
4456
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004457static void __exit iwl4965_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004458{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004459 pci_unregister_driver(&iwl_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004460 iwl4965_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004461}
4462
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004463module_exit(iwl4965_exit);
4464module_init(iwl4965_init);