blob: 516508f5fd49cdf161ee1a5891ac2911e7569433 [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;
Emmanuel Grumbacha326a5d2008-07-11 11:53:31 +0800253 /* allow CTS-to-self if possible. this is relevant only for
254 * 5000, but will not damage 4965 */
255 priv->staging_rxon.flags |= RXON_FLG_SELF_CTS_EN;
Zhu Yib481de92007-09-25 17:54:57 -0700256
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800257 ret = iwl4965_check_rxon_cmd(&priv->staging_rxon);
258 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700259 IWL_ERROR("Invalid RXON configuration. Not committing.\n");
260 return -EINVAL;
261 }
262
263 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800264 * iwl4965_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700265 * and other flags for the current radio configuration. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800266 if (!iwl4965_full_rxon_required(priv)) {
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800267 ret = iwl_send_rxon_assoc(priv);
268 if (ret) {
269 IWL_ERROR("Error setting RXON_ASSOC (%d)\n", ret);
270 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700271 }
272
273 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700274 return 0;
275 }
276
277 /* station table will be cleared */
278 priv->assoc_station_added = 0;
279
Zhu Yib481de92007-09-25 17:54:57 -0700280 /* If we are currently associated and the new config requires
281 * an RXON_ASSOC and the new config wants the associated mask enabled,
282 * we must clear the associated from the active configuration
283 * before we apply the new config */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800284 if (iwl_is_associated(priv) && new_assoc) {
Zhu Yib481de92007-09-25 17:54:57 -0700285 IWL_DEBUG_INFO("Toggling associated bit on current RXON\n");
286 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
287
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800288 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800289 sizeof(struct iwl_rxon_cmd),
Zhu Yib481de92007-09-25 17:54:57 -0700290 &priv->active_rxon);
291
292 /* If the mask clearing failed then we set
293 * active_rxon back to what it was previously */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800294 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -0700295 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800296 IWL_ERROR("Error clearing ASSOC_MSK (%d)\n", ret);
297 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700298 }
Zhu Yib481de92007-09-25 17:54:57 -0700299 }
300
301 IWL_DEBUG_INFO("Sending RXON\n"
302 "* with%s RXON_FILTER_ASSOC_MSK\n"
303 "* channel = %d\n"
Joe Perches0795af52007-10-03 17:59:30 -0700304 "* bssid = %s\n",
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800305 (new_assoc ? "" : "out"),
Zhu Yib481de92007-09-25 17:54:57 -0700306 le16_to_cpu(priv->staging_rxon.channel),
Joe Perches0795af52007-10-03 17:59:30 -0700307 print_mac(mac, priv->staging_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -0700308
Ron Rindjunsky099b40b2008-04-21 15:41:53 -0700309 iwl4965_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800310
311 /* Apply the new configuration
312 * RXON unassoc clears the station table in uCode, send it before
313 * we add the bcast station. If assoc bit is set, we will send RXON
314 * after having added the bcast and bssid station.
315 */
316 if (!new_assoc) {
317 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +0800318 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800319 if (ret) {
320 IWL_ERROR("Error setting new RXON (%d)\n", ret);
321 return ret;
322 }
323 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700324 }
325
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800326 iwl_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800327
Zhu Yib481de92007-09-25 17:54:57 -0700328 if (!priv->error_recovering)
329 priv->start_calib = 0;
330
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -0700331 iwl_init_sensitivity(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700332
Zhu Yib481de92007-09-25 17:54:57 -0700333 /* If we issue a new RXON command which required a tune then we must
334 * send a new TXPOWER command or we won't be able to Tx any frames */
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800335 ret = iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
336 if (ret) {
337 IWL_ERROR("Error sending TX power (%d)\n", ret);
338 return ret;
Zhu Yib481de92007-09-25 17:54:57 -0700339 }
340
341 /* Add the broadcast address so we can send broadcast frames */
Tomas Winkler4f40e4d2008-05-15 13:54:04 +0800342 if (iwl_rxon_add_station(priv, iwl_bcast_addr, 0) ==
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800343 IWL_INVALID_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700344 IWL_ERROR("Error adding BROADCAST address for transmit.\n");
345 return -EIO;
346 }
347
348 /* If we have set the ASSOC_MSK and we are in BSS mode then
349 * add the IWL_AP_ID to the station rate table */
Tomas Winkler91851592008-06-30 17:23:14 +0800350 if (new_assoc) {
351 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
352 ret = iwl_rxon_add_station(priv,
353 priv->active_rxon.bssid_addr, 1);
354 if (ret == IWL_INVALID_STATION) {
355 IWL_ERROR("Error adding AP address for TX.\n");
356 return -EIO;
357 }
358 priv->assoc_station_added = 1;
359 if (priv->default_wep_key &&
360 iwl_send_static_wepkey_cmd(priv, 0))
361 IWL_ERROR("Could not send WEP static key.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700362 }
Emmanuel Grumbach43d59b32008-06-30 17:23:06 +0800363
364 /* Apply the new configuration
365 * RXON assoc doesn't clear the station table in uCode,
366 */
367 ret = iwl_send_cmd_pdu(priv, REPLY_RXON,
368 sizeof(struct iwl_rxon_cmd), &priv->staging_rxon);
369 if (ret) {
370 IWL_ERROR("Error setting new RXON (%d)\n", ret);
371 return ret;
372 }
373 memcpy(active_rxon, &priv->staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700374 }
375
376 return 0;
377}
378
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700379void iwl4965_update_chain_flags(struct iwl_priv *priv)
380{
381
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700382 iwl_set_rxon_chain(priv);
Mohamed Abbas5da4b552008-04-21 15:41:51 -0700383 iwl4965_commit_rxon(priv);
384}
385
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700386static int iwl4965_send_bt_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700387{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800388 struct iwl4965_bt_cmd bt_cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700389 .flags = 3,
390 .lead_time = 0xAA,
391 .max_kill = 1,
392 .kill_ack_mask = 0,
393 .kill_cts_mask = 0,
394 };
395
Tomas Winkler857485c2008-03-21 13:53:44 -0700396 return iwl_send_cmd_pdu(priv, REPLY_BT_CONFIG,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800397 sizeof(struct iwl4965_bt_cmd), &bt_cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700398}
399
Tomas Winklerfcab4232008-05-15 13:54:01 +0800400static void iwl_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700401{
402 struct list_head *element;
403
404 IWL_DEBUG_INFO("%d frames on pre-allocated heap on clear.\n",
405 priv->frames_count);
406
407 while (!list_empty(&priv->free_frames)) {
408 element = priv->free_frames.next;
409 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800410 kfree(list_entry(element, struct iwl_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700411 priv->frames_count--;
412 }
413
414 if (priv->frames_count) {
415 IWL_WARNING("%d frames still in use. Did we lose one?\n",
416 priv->frames_count);
417 priv->frames_count = 0;
418 }
419}
420
Tomas Winklerfcab4232008-05-15 13:54:01 +0800421static struct iwl_frame *iwl_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700422{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800423 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700424 struct list_head *element;
425 if (list_empty(&priv->free_frames)) {
426 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
427 if (!frame) {
428 IWL_ERROR("Could not allocate frame!\n");
429 return NULL;
430 }
431
432 priv->frames_count++;
433 return frame;
434 }
435
436 element = priv->free_frames.next;
437 list_del(element);
Tomas Winklerfcab4232008-05-15 13:54:01 +0800438 return list_entry(element, struct iwl_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700439}
440
Tomas Winklerfcab4232008-05-15 13:54:01 +0800441static void iwl_free_frame(struct iwl_priv *priv, struct iwl_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700442{
443 memset(frame, 0, sizeof(*frame));
444 list_add(&frame->list, &priv->free_frames);
445}
446
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700447unsigned int iwl4965_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700448 struct ieee80211_hdr *hdr,
449 const u8 *dest, int left)
450{
451
Tomas Winkler3109ece2008-03-28 16:33:35 -0700452 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Zhu Yib481de92007-09-25 17:54:57 -0700453 ((priv->iw_mode != IEEE80211_IF_TYPE_IBSS) &&
454 (priv->iw_mode != IEEE80211_IF_TYPE_AP)))
455 return 0;
456
457 if (priv->ibss_beacon->len > left)
458 return 0;
459
460 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
461
462 return priv->ibss_beacon->len;
463}
464
Guy Cohen39e88502008-04-23 17:14:57 -0700465static u8 iwl4965_rate_get_lowest_plcp(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700466{
Guy Cohen39e88502008-04-23 17:14:57 -0700467 int i;
468 int rate_mask;
Zhu Yib481de92007-09-25 17:54:57 -0700469
Guy Cohen39e88502008-04-23 17:14:57 -0700470 /* Set rate mask*/
471 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
472 rate_mask = priv->active_rate_basic & 0xF;
473 else
474 rate_mask = priv->active_rate_basic & 0xFF0;
475
476 /* Find lowest valid rate */
Zhu Yib481de92007-09-25 17:54:57 -0700477 for (i = IWL_RATE_1M_INDEX; i != IWL_RATE_INVALID;
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800478 i = iwl_rates[i].next_ieee) {
Zhu Yib481de92007-09-25 17:54:57 -0700479 if (rate_mask & (1 << i))
Tomas Winkler1826dcc2008-05-15 13:54:02 +0800480 return iwl_rates[i].plcp;
Zhu Yib481de92007-09-25 17:54:57 -0700481 }
482
Guy Cohen39e88502008-04-23 17:14:57 -0700483 /* No valid rate was found. Assign the lowest one */
484 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK)
485 return IWL_RATE_1M_PLCP;
486 else
487 return IWL_RATE_6M_PLCP;
Zhu Yib481de92007-09-25 17:54:57 -0700488}
489
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700490static int iwl4965_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700491{
Tomas Winklerfcab4232008-05-15 13:54:01 +0800492 struct iwl_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700493 unsigned int frame_size;
494 int rc;
495 u8 rate;
496
Tomas Winklerfcab4232008-05-15 13:54:01 +0800497 frame = iwl_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700498
499 if (!frame) {
500 IWL_ERROR("Could not obtain free frame buffer for beacon "
501 "command.\n");
502 return -ENOMEM;
503 }
504
Guy Cohen39e88502008-04-23 17:14:57 -0700505 rate = iwl4965_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700506
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800507 frame_size = iwl4965_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700508
Tomas Winkler857485c2008-03-21 13:53:44 -0700509 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700510 &frame->u.cmd[0]);
511
Tomas Winklerfcab4232008-05-15 13:54:01 +0800512 iwl_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700513
514 return rc;
515}
516
517/******************************************************************************
518 *
Zhu Yib481de92007-09-25 17:54:57 -0700519 * Misc. internal state and helper functions
520 *
521 ******************************************************************************/
Zhu Yib481de92007-09-25 17:54:57 -0700522
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700523static void iwl4965_ht_conf(struct iwl_priv *priv,
524 struct ieee80211_bss_conf *bss_conf)
525{
526 struct ieee80211_ht_info *ht_conf = bss_conf->ht_conf;
527 struct ieee80211_ht_bss_info *ht_bss_conf = bss_conf->ht_bss_conf;
528 struct iwl_ht_info *iwl_conf = &priv->current_ht_config;
529
530 IWL_DEBUG_MAC80211("enter: \n");
531
532 iwl_conf->is_ht = bss_conf->assoc_ht;
533
534 if (!iwl_conf->is_ht)
535 return;
536
537 priv->ps_mode = (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
538
539 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_20)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800540 iwl_conf->sgf |= HT_SHORT_GI_20MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700541 if (ht_conf->cap & IEEE80211_HT_CAP_SGI_40)
Emmanuel Grumbacha9841012008-05-15 13:54:08 +0800542 iwl_conf->sgf |= HT_SHORT_GI_40MHZ;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700543
544 iwl_conf->is_green_field = !!(ht_conf->cap & IEEE80211_HT_CAP_GRN_FLD);
545 iwl_conf->max_amsdu_size =
546 !!(ht_conf->cap & IEEE80211_HT_CAP_MAX_AMSDU);
547
548 iwl_conf->supported_chan_width =
549 !!(ht_conf->cap & IEEE80211_HT_CAP_SUP_WIDTH);
550 iwl_conf->extension_chan_offset =
551 ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_SEC_OFFSET;
552 /* If no above or below channel supplied disable FAT channel */
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800553 if (iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_ABOVE &&
554 iwl_conf->extension_chan_offset != IEEE80211_HT_IE_CHA_SEC_BELOW) {
555 iwl_conf->extension_chan_offset = IEEE80211_HT_IE_CHA_SEC_NONE;
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700556 iwl_conf->supported_chan_width = 0;
Emmanuel Grumbach963f5512008-06-12 09:47:00 +0800557 }
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700558
559 iwl_conf->tx_mimo_ps_mode =
560 (u8)((ht_conf->cap & IEEE80211_HT_CAP_MIMO_PS) >> 2);
561 memcpy(iwl_conf->supp_mcs_set, ht_conf->supp_mcs_set, 16);
562
563 iwl_conf->control_channel = ht_bss_conf->primary_channel;
564 iwl_conf->tx_chan_width =
565 !!(ht_bss_conf->bss_cap & IEEE80211_HT_IE_CHA_WIDTH);
566 iwl_conf->ht_protection =
567 ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_HT_PROTECTION;
568 iwl_conf->non_GF_STA_present =
569 !!(ht_bss_conf->bss_op_mode & IEEE80211_HT_IE_NON_GF_STA_PRSNT);
570
571 IWL_DEBUG_MAC80211("control channel %d\n", iwl_conf->control_channel);
572 IWL_DEBUG_MAC80211("leave\n");
573}
574
Zhu Yib481de92007-09-25 17:54:57 -0700575/*
576 * QoS support
577*/
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700578static int iwl4965_send_qos_params_command(struct iwl_priv *priv,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800579 struct iwl4965_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700580{
581
Tomas Winkler857485c2008-03-21 13:53:44 -0700582 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800583 sizeof(struct iwl4965_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700584}
585
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700586static void iwl4965_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700587{
588 unsigned long flags;
589
Zhu Yib481de92007-09-25 17:54:57 -0700590 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
591 return;
592
593 if (!priv->qos_data.qos_enable)
594 return;
595
596 spin_lock_irqsave(&priv->lock, flags);
597 priv->qos_data.def_qos_parm.qos_flags = 0;
598
599 if (priv->qos_data.qos_cap.q_AP.queue_request &&
600 !priv->qos_data.qos_cap.q_AP.txop_request)
601 priv->qos_data.def_qos_parm.qos_flags |=
602 QOS_PARAM_FLG_TXOP_TYPE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700603 if (priv->qos_data.qos_active)
604 priv->qos_data.def_qos_parm.qos_flags |=
605 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
606
Ron Rindjunskyfd105e72007-11-26 16:14:39 +0200607 if (priv->current_ht_config.is_ht)
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800608 priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK;
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800609
Zhu Yib481de92007-09-25 17:54:57 -0700610 spin_unlock_irqrestore(&priv->lock, flags);
611
Tomas Winkler3109ece2008-03-28 16:33:35 -0700612 if (force || iwl_is_associated(priv)) {
Tomas Winklerf1f1f5c2007-10-25 17:15:26 +0800613 IWL_DEBUG_QOS("send QoS cmd with Qos active=%d FLAGS=0x%X\n",
614 priv->qos_data.qos_active,
615 priv->qos_data.def_qos_parm.qos_flags);
Zhu Yib481de92007-09-25 17:54:57 -0700616
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800617 iwl4965_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700618 &(priv->qos_data.def_qos_parm));
619 }
620}
621
Zhu Yib481de92007-09-25 17:54:57 -0700622#define MAX_UCODE_BEACON_INTERVAL 4096
623#define INTEL_CONN_LISTEN_INTERVAL __constant_cpu_to_le16(0xA)
624
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800625static __le16 iwl4965_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700626{
627 u16 new_val = 0;
628 u16 beacon_factor = 0;
629
630 beacon_factor =
631 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
632 / MAX_UCODE_BEACON_INTERVAL;
633 new_val = beacon_val / beacon_factor;
634
635 return cpu_to_le16(new_val);
636}
637
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700638static void iwl4965_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700639{
640 u64 interval_tm_unit;
641 u64 tsf, result;
642 unsigned long flags;
643 struct ieee80211_conf *conf = NULL;
644 u16 beacon_int = 0;
645
646 conf = ieee80211_get_hw_conf(priv->hw);
647
648 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3109ece2008-03-28 16:33:35 -0700649 priv->rxon_timing.timestamp.dw[1] = cpu_to_le32(priv->timestamp >> 32);
650 priv->rxon_timing.timestamp.dw[0] =
651 cpu_to_le32(priv->timestamp & 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -0700652
653 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
654
Tomas Winkler3109ece2008-03-28 16:33:35 -0700655 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700656
657 beacon_int = priv->beacon_int;
658 spin_unlock_irqrestore(&priv->lock, flags);
659
660 if (priv->iw_mode == IEEE80211_IF_TYPE_STA) {
661 if (beacon_int == 0) {
662 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
663 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
664 } else {
665 priv->rxon_timing.beacon_interval =
666 cpu_to_le16(beacon_int);
667 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800668 iwl4965_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700669 le16_to_cpu(priv->rxon_timing.beacon_interval));
670 }
671
672 priv->rxon_timing.atim_window = 0;
673 } else {
674 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800675 iwl4965_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700676 /* TODO: we need to get atim_window from upper stack
677 * for now we set to 0 */
678 priv->rxon_timing.atim_window = 0;
679 }
680
681 interval_tm_unit =
682 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
683 result = do_div(tsf, interval_tm_unit);
684 priv->rxon_timing.beacon_init_val =
685 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
686
687 IWL_DEBUG_ASSOC
688 ("beacon interval %d beacon timer %d beacon tim %d\n",
689 le16_to_cpu(priv->rxon_timing.beacon_interval),
690 le32_to_cpu(priv->rxon_timing.beacon_init_val),
691 le16_to_cpu(priv->rxon_timing.atim_window));
692}
693
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800694static void iwl_set_flags_for_band(struct iwl_priv *priv,
695 enum ieee80211_band band)
Zhu Yib481de92007-09-25 17:54:57 -0700696{
Johannes Berg8318d782008-01-24 19:38:38 +0100697 if (band == IEEE80211_BAND_5GHZ) {
Zhu Yib481de92007-09-25 17:54:57 -0700698 priv->staging_rxon.flags &=
699 ~(RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK
700 | RXON_FLG_CCK_MSK);
701 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
702 } else {
Reinette Chatre508e32e2008-04-14 21:16:13 -0700703 /* Copied from iwl4965_post_associate() */
Zhu Yib481de92007-09-25 17:54:57 -0700704 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
705 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
706 else
707 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
708
709 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
710 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
711
712 priv->staging_rxon.flags |= RXON_FLG_BAND_24G_MSK;
713 priv->staging_rxon.flags |= RXON_FLG_AUTO_DETECT_MSK;
714 priv->staging_rxon.flags &= ~RXON_FLG_CCK_MSK;
715 }
716}
717
718/*
Ian Schram01ebd062007-10-25 17:15:22 +0800719 * initialize rxon structure with default values from eeprom
Zhu Yib481de92007-09-25 17:54:57 -0700720 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700721static void iwl4965_connection_init_rx_config(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700722{
Assaf Kraussbf85ea42008-03-14 10:38:49 -0700723 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700724
725 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
726
727 switch (priv->iw_mode) {
728 case IEEE80211_IF_TYPE_AP:
729 priv->staging_rxon.dev_type = RXON_DEV_TYPE_AP;
730 break;
731
732 case IEEE80211_IF_TYPE_STA:
733 priv->staging_rxon.dev_type = RXON_DEV_TYPE_ESS;
734 priv->staging_rxon.filter_flags = RXON_FILTER_ACCEPT_GRP_MSK;
735 break;
736
737 case IEEE80211_IF_TYPE_IBSS:
738 priv->staging_rxon.dev_type = RXON_DEV_TYPE_IBSS;
739 priv->staging_rxon.flags = RXON_FLG_SHORT_PREAMBLE_MSK;
740 priv->staging_rxon.filter_flags = RXON_FILTER_BCON_AWARE_MSK |
741 RXON_FILTER_ACCEPT_GRP_MSK;
742 break;
743
744 case IEEE80211_IF_TYPE_MNTR:
745 priv->staging_rxon.dev_type = RXON_DEV_TYPE_SNIFFER;
746 priv->staging_rxon.filter_flags = RXON_FILTER_PROMISC_MSK |
747 RXON_FILTER_CTL2HOST_MSK | RXON_FILTER_ACCEPT_GRP_MSK;
748 break;
Tomas Winkler69dc5d92008-03-25 16:33:41 -0700749 default:
750 IWL_ERROR("Unsupported interface type %d\n", priv->iw_mode);
751 break;
Zhu Yib481de92007-09-25 17:54:57 -0700752 }
753
754#if 0
755 /* TODO: Figure out when short_preamble would be set and cache from
756 * that */
757 if (!hw_to_local(priv->hw)->short_preamble)
758 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
759 else
760 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
761#endif
762
Assaf Krauss8622e702008-03-21 13:53:43 -0700763 ch_info = iwl_get_channel_info(priv, priv->band,
Rick Farrington25b3f572008-06-30 17:23:28 +0800764 le16_to_cpu(priv->active_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700765
766 if (!ch_info)
767 ch_info = &priv->channel_info[0];
768
769 /*
770 * in some case A channels are all non IBSS
771 * in this case force B/G channel
772 */
773 if ((priv->iw_mode == IEEE80211_IF_TYPE_IBSS) &&
774 !(is_channel_ibss(ch_info)))
775 ch_info = &priv->channel_info[0];
776
777 priv->staging_rxon.channel = cpu_to_le16(ch_info->channel);
Johannes Berg8318d782008-01-24 19:38:38 +0100778 priv->band = ch_info->band;
Zhu Yib481de92007-09-25 17:54:57 -0700779
Tomas Winkler82a66bb2008-05-29 16:35:28 +0800780 iwl_set_flags_for_band(priv, priv->band);
Zhu Yib481de92007-09-25 17:54:57 -0700781
782 priv->staging_rxon.ofdm_basic_rates =
783 (IWL_OFDM_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
784 priv->staging_rxon.cck_basic_rates =
785 (IWL_CCK_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
786
787 priv->staging_rxon.flags &= ~(RXON_FLG_CHANNEL_MODE_MIXED_MSK |
788 RXON_FLG_CHANNEL_MODE_PURE_40_MSK);
789 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
790 memcpy(priv->staging_rxon.wlap_bssid_addr, priv->mac_addr, ETH_ALEN);
791 priv->staging_rxon.ofdm_ht_single_stream_basic_rates = 0xff;
792 priv->staging_rxon.ofdm_ht_dual_stream_basic_rates = 0xff;
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -0700793 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700794}
795
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700796static int iwl4965_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700797{
Zhu Yib481de92007-09-25 17:54:57 -0700798 priv->iw_mode = mode;
799
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800800 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700801 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
802
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +0800803 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700804
Mohamed Abbasfde35712007-11-29 11:10:15 +0800805 /* dont commit rxon if rf-kill is on*/
Tomas Winklerfee12472008-04-03 16:05:21 -0700806 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800807 return -EAGAIN;
808
809 cancel_delayed_work(&priv->scan_check);
Tomas Winkler2a421b92008-06-12 09:47:10 +0800810 if (iwl_scan_cancel_timeout(priv, 100)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +0800811 IWL_WARNING("Aborted scan still in progress after 100ms\n");
812 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
813 return -EAGAIN;
814 }
815
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800816 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700817
818 return 0;
819}
820
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700821static void iwl4965_set_rate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700822{
Johannes Berg8318d782008-01-24 19:38:38 +0100823 const struct ieee80211_supported_band *hw = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700824 struct ieee80211_rate *rate;
825 int i;
826
Emmanuel Grumbachd1141df2008-04-21 15:42:00 -0700827 hw = iwl_get_hw_mode(priv, priv->band);
Saleem Abdulrasoolc4ba9622007-11-18 23:59:08 -0800828 if (!hw) {
829 IWL_ERROR("Failed to set rate: unable to get hw mode\n");
830 return;
831 }
Zhu Yib481de92007-09-25 17:54:57 -0700832
833 priv->active_rate = 0;
834 priv->active_rate_basic = 0;
835
Johannes Berg8318d782008-01-24 19:38:38 +0100836 for (i = 0; i < hw->n_bitrates; i++) {
837 rate = &(hw->bitrates[i]);
838 if (rate->hw_value < IWL_RATE_COUNT)
839 priv->active_rate |= (1 << rate->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -0700840 }
841
842 IWL_DEBUG_RATE("Set active_rate = %0x, active_rate_basic = %0x\n",
843 priv->active_rate, priv->active_rate_basic);
844
845 /*
846 * If a basic rate is configured, then use it (adding IWL_RATE_1M_MASK)
847 * otherwise set it to the default of all CCK rates and 6, 12, 24 for
848 * OFDM
849 */
850 if (priv->active_rate_basic & IWL_CCK_BASIC_RATES_MASK)
851 priv->staging_rxon.cck_basic_rates =
852 ((priv->active_rate_basic &
853 IWL_CCK_RATES_MASK) >> IWL_FIRST_CCK_RATE) & 0xF;
854 else
855 priv->staging_rxon.cck_basic_rates =
856 (IWL_CCK_BASIC_RATES_MASK >> IWL_FIRST_CCK_RATE) & 0xF;
857
858 if (priv->active_rate_basic & IWL_OFDM_BASIC_RATES_MASK)
859 priv->staging_rxon.ofdm_basic_rates =
860 ((priv->active_rate_basic &
861 (IWL_OFDM_BASIC_RATES_MASK | IWL_RATE_6M_MASK)) >>
862 IWL_FIRST_OFDM_RATE) & 0xFF;
863 else
864 priv->staging_rxon.ofdm_basic_rates =
865 (IWL_OFDM_BASIC_RATES_MASK >> IWL_FIRST_OFDM_RATE) & 0xFF;
866}
867
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +0800868#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -0700869
870#include "iwl-spectrum.h"
871
872#define BEACON_TIME_MASK_LOW 0x00FFFFFF
873#define BEACON_TIME_MASK_HIGH 0xFF000000
874#define TIME_UNIT 1024
875
876/*
877 * extended beacon time format
878 * time in usec will be changed into a 32-bit value in 8:24 format
879 * the high 1 byte is the beacon counts
880 * the lower 3 bytes is the time in usec within one beacon interval
881 */
882
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800883static u32 iwl4965_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700884{
885 u32 quot;
886 u32 rem;
887 u32 interval = beacon_interval * 1024;
888
889 if (!interval || !usec)
890 return 0;
891
892 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
893 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
894
895 return (quot << 24) + rem;
896}
897
898/* base is usually what we get from ucode with each received frame,
899 * the same as HW timer counter counting down
900 */
901
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800902static __le32 iwl4965_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -0700903{
904 u32 base_low = base & BEACON_TIME_MASK_LOW;
905 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
906 u32 interval = beacon_interval * TIME_UNIT;
907 u32 res = (base & BEACON_TIME_MASK_HIGH) +
908 (addon & BEACON_TIME_MASK_HIGH);
909
910 if (base_low > addon_low)
911 res += base_low - addon_low;
912 else if (base_low < addon_low) {
913 res += interval + base_low - addon_low;
914 res += (1 << 24);
915 } else
916 res += (1 << 24);
917
918 return cpu_to_le32(res);
919}
920
Tomas Winklerc79dd5b2008-03-12 16:58:50 -0700921static int iwl4965_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700922 struct ieee80211_measurement_params *params,
923 u8 type)
924{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800925 struct iwl4965_spectrum_cmd spectrum;
Tomas Winklerdb11d632008-05-05 10:22:33 +0800926 struct iwl_rx_packet *res;
Tomas Winkler857485c2008-03-21 13:53:44 -0700927 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700928 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
929 .data = (void *)&spectrum,
930 .meta.flags = CMD_WANT_SKB,
931 };
932 u32 add_time = le64_to_cpu(params->start_time);
933 int rc;
934 int spectrum_resp_status;
935 int duration = le16_to_cpu(params->duration);
936
Tomas Winkler3109ece2008-03-28 16:33:35 -0700937 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700938 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800939 iwl4965_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -0700940 le64_to_cpu(params->start_time) - priv->last_tsf,
941 le16_to_cpu(priv->rxon_timing.beacon_interval));
942
943 memset(&spectrum, 0, sizeof(spectrum));
944
945 spectrum.channel_count = cpu_to_le16(1);
946 spectrum.flags =
947 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
948 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
949 cmd.len = sizeof(spectrum);
950 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
951
Tomas Winkler3109ece2008-03-28 16:33:35 -0700952 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700953 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800954 iwl4965_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -0700955 add_time,
956 le16_to_cpu(priv->rxon_timing.beacon_interval));
957 else
958 spectrum.start_time = 0;
959
960 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
961 spectrum.channels[0].channel = params->channel;
962 spectrum.channels[0].type = type;
963 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
964 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
965 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
966
Tomas Winkler857485c2008-03-21 13:53:44 -0700967 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700968 if (rc)
969 return rc;
970
Tomas Winklerdb11d632008-05-05 10:22:33 +0800971 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700972 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
973 IWL_ERROR("Bad return from REPLY_RX_ON_ASSOC command\n");
974 rc = -EIO;
975 }
976
977 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
978 switch (spectrum_resp_status) {
979 case 0: /* Command will be handled */
980 if (res->u.spectrum.id != 0xff) {
981 IWL_DEBUG_INFO
982 ("Replaced existing measurement: %d\n",
983 res->u.spectrum.id);
984 priv->measurement_status &= ~MEASUREMENT_READY;
985 }
986 priv->measurement_status |= MEASUREMENT_ACTIVE;
987 rc = 0;
988 break;
989
990 case 1: /* Command will not be handled */
991 rc = -EAGAIN;
992 break;
993 }
994
995 dev_kfree_skb_any(cmd.meta.u.skb);
996
997 return rc;
998}
999#endif
1000
Zhu Yib481de92007-09-25 17:54:57 -07001001/******************************************************************************
1002 *
1003 * Generic RX handler implementations
1004 *
1005 ******************************************************************************/
Tomas Winkler885ba202008-05-29 16:34:55 +08001006static void iwl_rx_reply_alive(struct iwl_priv *priv,
1007 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001008{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001009 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Tomas Winkler885ba202008-05-29 16:34:55 +08001010 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001011 struct delayed_work *pwork;
1012
1013 palive = &pkt->u.alive_frame;
1014
1015 IWL_DEBUG_INFO("Alive ucode status 0x%08X revision "
1016 "0x%01X 0x%01X\n",
1017 palive->is_valid, palive->ver_type,
1018 palive->ver_subtype);
1019
1020 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
1021 IWL_DEBUG_INFO("Initialization Alive received.\n");
1022 memcpy(&priv->card_alive_init,
1023 &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001024 sizeof(struct iwl_init_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001025 pwork = &priv->init_alive_start;
1026 } else {
1027 IWL_DEBUG_INFO("Runtime Alive received.\n");
1028 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler885ba202008-05-29 16:34:55 +08001029 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001030 pwork = &priv->alive_start;
1031 }
1032
1033 /* We delay the ALIVE response by 5ms to
1034 * give the HW RF Kill time to activate... */
1035 if (palive->is_valid == UCODE_VALID_OK)
1036 queue_delayed_work(priv->workqueue, pwork,
1037 msecs_to_jiffies(5));
1038 else
1039 IWL_WARNING("uCode did not respond OK.\n");
1040}
1041
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001042static void iwl4965_rx_reply_error(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001043 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001044{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001045 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001046
1047 IWL_ERROR("Error Reply type 0x%08X cmd %s (0x%02X) "
1048 "seq 0x%04X ser 0x%08X\n",
1049 le32_to_cpu(pkt->u.err_resp.error_type),
1050 get_cmd_string(pkt->u.err_resp.cmd_id),
1051 pkt->u.err_resp.cmd_id,
1052 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1053 le32_to_cpu(pkt->u.err_resp.error_info));
1054}
1055
1056#define TX_STATUS_ENTRY(x) case TX_STATUS_FAIL_ ## x: return #x
1057
Tomas Winklera55360e2008-05-05 10:22:28 +08001058static void iwl4965_rx_csa(struct iwl_priv *priv, struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001059{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001060 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001061 struct iwl_rxon_cmd *rxon = (void *)&priv->active_rxon;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001062 struct iwl4965_csa_notification *csa = &(pkt->u.csa_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001063 IWL_DEBUG_11H("CSA notif: channel %d, status %d\n",
1064 le16_to_cpu(csa->channel), le32_to_cpu(csa->status));
1065 rxon->channel = csa->channel;
1066 priv->staging_rxon.channel = csa->channel;
1067}
1068
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001069static void iwl4965_rx_spectrum_measure_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001070 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001071{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001072#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Tomas Winklerdb11d632008-05-05 10:22:33 +08001073 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001074 struct iwl4965_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001075
1076 if (!report->state) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001077 IWL_DEBUG(IWL_DL_11H,
1078 "Spectrum Measure Notification: Start\n");
Zhu Yib481de92007-09-25 17:54:57 -07001079 return;
1080 }
1081
1082 memcpy(&priv->measure_report, report, sizeof(*report));
1083 priv->measurement_status |= MEASUREMENT_READY;
1084#endif
1085}
1086
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001087static void iwl4965_rx_pm_sleep_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001088 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001089{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001090#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001091 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001092 struct iwl4965_sleep_notification *sleep = &(pkt->u.sleep_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001093 IWL_DEBUG_RX("sleep mode: %d, src: %d\n",
1094 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1095#endif
1096}
1097
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001098static void iwl4965_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001099 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001100{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001101 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001102 IWL_DEBUG_RADIO("Dumping %d bytes of unhandled "
1103 "notification for %s:\n",
1104 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Ester Kummerbf403db2008-05-05 10:22:40 +08001105 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw, le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001106}
1107
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001108static void iwl4965_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001109{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001110 struct iwl_priv *priv =
1111 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001112 struct sk_buff *beacon;
1113
1114 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001115 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001116
1117 if (!beacon) {
1118 IWL_ERROR("update beacon failed\n");
1119 return;
1120 }
1121
1122 mutex_lock(&priv->mutex);
1123 /* new beacon skb is allocated every time; dispose previous.*/
1124 if (priv->ibss_beacon)
1125 dev_kfree_skb(priv->ibss_beacon);
1126
1127 priv->ibss_beacon = beacon;
1128 mutex_unlock(&priv->mutex);
1129
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001130 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001131}
1132
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08001133/**
1134 * iwl4965_bg_statistics_periodic - Timer callback to queue statistics
1135 *
1136 * This callback is provided in order to send a statistics request.
1137 *
1138 * This timer function is continually reset to execute within
1139 * REG_RECALIB_PERIOD seconds since the last STATISTICS_NOTIFICATION
1140 * was received. We need to ensure we receive the statistics in order
1141 * to update the temperature used for calibrating the TXPOWER.
1142 */
1143static void iwl4965_bg_statistics_periodic(unsigned long data)
1144{
1145 struct iwl_priv *priv = (struct iwl_priv *)data;
1146
1147 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
1148 return;
1149
1150 iwl_send_statistics_request(priv, CMD_ASYNC);
1151}
1152
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001153static void iwl4965_rx_beacon_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001154 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001155{
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001156#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winklerdb11d632008-05-05 10:22:33 +08001157 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001158 struct iwl4965_beacon_notif *beacon = &(pkt->u.beacon_status);
Tomas Winklere7d326a2008-06-12 09:47:11 +08001159 u8 rate = iwl_hw_get_rate(beacon->beacon_notify_hdr.rate_n_flags);
Zhu Yib481de92007-09-25 17:54:57 -07001160
1161 IWL_DEBUG_RX("beacon status %x retries %d iss %d "
1162 "tsf %d %d rate %d\n",
Tomas Winkler25a65722008-06-12 09:47:07 +08001163 le32_to_cpu(beacon->beacon_notify_hdr.u.status) & TX_STATUS_MSK,
Zhu Yib481de92007-09-25 17:54:57 -07001164 beacon->beacon_notify_hdr.failure_frame,
1165 le32_to_cpu(beacon->ibss_mgr_status),
1166 le32_to_cpu(beacon->high_tsf),
1167 le32_to_cpu(beacon->low_tsf), rate);
1168#endif
1169
1170 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
1171 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1172 queue_work(priv->workqueue, &priv->beacon_update);
1173}
1174
Zhu Yib481de92007-09-25 17:54:57 -07001175/* Handle notification from uCode that card's power state is changing
1176 * due to software, hardware, or critical temperature RFKILL */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001177static void iwl4965_rx_card_state_notif(struct iwl_priv *priv,
Tomas Winklera55360e2008-05-05 10:22:28 +08001178 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001179{
Tomas Winklerdb11d632008-05-05 10:22:33 +08001180 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001181 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1182 unsigned long status = priv->status;
1183
1184 IWL_DEBUG_RF_KILL("Card state received: HW:%s SW:%s\n",
1185 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1186 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1187
1188 if (flags & (SW_CARD_DISABLED | HW_CARD_DISABLED |
1189 RF_CARD_DISABLED)) {
1190
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001191 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001192 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1193
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001194 if (!iwl_grab_nic_access(priv)) {
1195 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001196 priv, HBUS_TARG_MBX_C,
1197 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1198
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001199 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001200 }
1201
1202 if (!(flags & RXON_CARD_DISABLED)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001203 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07001204 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001205 if (!iwl_grab_nic_access(priv)) {
1206 iwl_write_direct32(
Zhu Yib481de92007-09-25 17:54:57 -07001207 priv, HBUS_TARG_MBX_C,
1208 HBUS_TARG_MBX_C_REG_BIT_CMD_BLOCKED);
1209
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001210 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001211 }
1212 }
1213
1214 if (flags & RF_CARD_DISABLED) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001215 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001216 CSR_UCODE_DRV_GP1_REG_BIT_CT_KILL_EXIT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001217 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1218 if (!iwl_grab_nic_access(priv))
1219 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001220 }
1221 }
1222
1223 if (flags & HW_CARD_DISABLED)
1224 set_bit(STATUS_RF_KILL_HW, &priv->status);
1225 else
1226 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1227
1228
1229 if (flags & SW_CARD_DISABLED)
1230 set_bit(STATUS_RF_KILL_SW, &priv->status);
1231 else
1232 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1233
1234 if (!(flags & RXON_CARD_DISABLED))
Tomas Winkler2a421b92008-06-12 09:47:10 +08001235 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001236
1237 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1238 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1239 (test_bit(STATUS_RF_KILL_SW, &status) !=
1240 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1241 queue_work(priv->workqueue, &priv->rf_kill);
1242 else
1243 wake_up_interruptible(&priv->wait_command_queue);
1244}
1245
1246/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001247 * iwl4965_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001248 *
1249 * Setup the RX handlers for each of the reply types sent from the uCode
1250 * to the host.
1251 *
1252 * This function chains into the hardware specific files for them to setup
1253 * any hardware specific handlers as well.
1254 */
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001255static void iwl_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001256{
Tomas Winkler885ba202008-05-29 16:34:55 +08001257 priv->rx_handlers[REPLY_ALIVE] = iwl_rx_reply_alive;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001258 priv->rx_handlers[REPLY_ERROR] = iwl4965_rx_reply_error;
1259 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl4965_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07001260 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001261 iwl4965_rx_spectrum_measure_notif;
1262 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl4965_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001263 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001264 iwl4965_rx_pm_debug_statistics_notif;
1265 priv->rx_handlers[BEACON_NOTIFICATION] = iwl4965_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001266
Ben Cahill9fbab512007-11-29 11:09:47 +08001267 /*
1268 * The same handler is used for both the REPLY to a discrete
1269 * statistics request from the host as well as for the periodic
1270 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001271 */
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08001272 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl_rx_statistics;
1273 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl_rx_statistics;
Tomas Winkler2a421b92008-06-12 09:47:10 +08001274
1275 iwl_setup_rx_scan_handlers(priv);
1276
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001277 /* status change handler */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001278 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl4965_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001279
Tomas Winklerc1354752008-05-29 16:35:04 +08001280 priv->rx_handlers[MISSED_BEACONS_NOTIFICATION] =
1281 iwl_rx_missed_beacon_notif;
Ron Rindjunsky37a44212008-05-29 16:35:18 +08001282 /* Rx handlers */
Emmanuel Grumbach1781a072008-06-30 17:23:09 +08001283 priv->rx_handlers[REPLY_RX_PHY_CMD] = iwl_rx_reply_rx_phy;
1284 priv->rx_handlers[REPLY_RX_MPDU_CMD] = iwl_rx_reply_rx;
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08001285 /* block ack */
1286 priv->rx_handlers[REPLY_COMPRESSED_BA] = iwl_rx_reply_compressed_ba;
Ben Cahill9fbab512007-11-29 11:09:47 +08001287 /* Set up hardware specific Rx handlers */
Emmanuel Grumbachd4789ef2008-04-24 11:55:20 -07001288 priv->cfg->ops->lib->rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001289}
1290
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001291/*
1292 * this should be called while priv->lock is locked
1293*/
Tomas Winklera55360e2008-05-05 10:22:28 +08001294static void __iwl_rx_replenish(struct iwl_priv *priv)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001295{
Tomas Winklera55360e2008-05-05 10:22:28 +08001296 iwl_rx_allocate(priv);
1297 iwl_rx_queue_restock(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001298}
1299
1300
Zhu Yib481de92007-09-25 17:54:57 -07001301/**
Tomas Winklera55360e2008-05-05 10:22:28 +08001302 * iwl_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001303 *
1304 * Uses the priv->rx_handlers callback function array to invoke
1305 * the appropriate handlers, including command responses,
1306 * frame-received notifications, and other notifications.
1307 */
Tomas Winklera55360e2008-05-05 10:22:28 +08001308void iwl_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001309{
Tomas Winklera55360e2008-05-05 10:22:28 +08001310 struct iwl_rx_mem_buffer *rxb;
Tomas Winklerdb11d632008-05-05 10:22:33 +08001311 struct iwl_rx_packet *pkt;
Tomas Winklera55360e2008-05-05 10:22:28 +08001312 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001313 u32 r, i;
1314 int reclaim;
1315 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001316 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001317 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001318
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001319 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1320 * buffer that the driver may process (last buffer filled by ucode). */
Ron Rindjunskyd67f5482008-05-05 10:22:49 +08001321 r = priv->cfg->ops->lib->shared_mem_rx_idx(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001322 i = rxq->read;
1323
1324 /* Rx interrupt, but nothing sent from uCode */
1325 if (i == r)
Ester Kummerf3d67992008-05-06 11:05:12 +08001326 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001327
Tomas Winklera55360e2008-05-05 10:22:28 +08001328 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001329 fill_rx = 1;
1330
Zhu Yib481de92007-09-25 17:54:57 -07001331 while (i != r) {
1332 rxb = rxq->queue[i];
1333
Ben Cahill9fbab512007-11-29 11:09:47 +08001334 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001335 * then a bug has been introduced in the queue refilling
1336 * routines -- catch it here */
1337 BUG_ON(rxb == NULL);
1338
1339 rxq->queue[i] = NULL;
1340
1341 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07001342 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001343 PCI_DMA_FROMDEVICE);
Tomas Winklerdb11d632008-05-05 10:22:33 +08001344 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001345
1346 /* Reclaim a command buffer only if this packet is a response
1347 * to a (driver-originated) command.
1348 * If the packet (e.g. Rx frame) originated from uCode,
1349 * there is no command buffer to reclaim.
1350 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1351 * but apparently a few don't get set; catch them here. */
1352 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1353 (pkt->hdr.cmd != REPLY_RX_PHY_CMD) &&
Tomas Winkler857485c2008-03-21 13:53:44 -07001354 (pkt->hdr.cmd != REPLY_RX) &&
Zhu Yicfe01702007-09-27 11:27:31 +08001355 (pkt->hdr.cmd != REPLY_COMPRESSED_BA) &&
Zhu Yib481de92007-09-25 17:54:57 -07001356 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1357 (pkt->hdr.cmd != REPLY_TX);
1358
1359 /* Based on type of command response or notification,
1360 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001361 * rx_handlers table. See iwl4965_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001362 if (priv->rx_handlers[pkt->hdr.cmd]) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001363 IWL_DEBUG(IWL_DL_RX, "r = %d, i = %d, %s, 0x%02x\n", r,
1364 i, get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001365 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1366 } else {
1367 /* No handling needed */
Ester Kummerf3d67992008-05-06 11:05:12 +08001368 IWL_DEBUG(IWL_DL_RX,
Zhu Yib481de92007-09-25 17:54:57 -07001369 "r %d i %d No handler needed for %s, 0x%02x\n",
1370 r, i, get_cmd_string(pkt->hdr.cmd),
1371 pkt->hdr.cmd);
1372 }
1373
1374 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001375 /* Invoke any callbacks, transfer the skb to caller, and
Tomas Winkler857485c2008-03-21 13:53:44 -07001376 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001377 * as we reclaim the driver command queue */
1378 if (rxb && rxb->skb)
Tomas Winkler17b88922008-05-29 16:35:12 +08001379 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001380 else
1381 IWL_WARNING("Claim null rxb?\n");
1382 }
1383
1384 /* For now we just don't re-use anything. We can tweak this
1385 * later to try and re-use notification packets and SKBs that
1386 * fail to Rx correctly */
1387 if (rxb->skb != NULL) {
1388 priv->alloc_rxb_skb--;
1389 dev_kfree_skb_any(rxb->skb);
1390 rxb->skb = NULL;
1391 }
1392
1393 pci_unmap_single(priv->pci_dev, rxb->dma_addr,
Tomas Winkler5425e492008-04-15 16:01:38 -07001394 priv->hw_params.rx_buf_size,
Ron Rindjunsky9ee1ba42007-11-26 16:14:42 +02001395 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001396 spin_lock_irqsave(&rxq->lock, flags);
1397 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1398 spin_unlock_irqrestore(&rxq->lock, flags);
1399 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001400 /* If there are a lot of unused frames,
1401 * restock the Rx queue so ucode wont assert. */
1402 if (fill_rx) {
1403 count++;
1404 if (count >= 8) {
1405 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001406 __iwl_rx_replenish(priv);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001407 count = 0;
1408 }
1409 }
Zhu Yib481de92007-09-25 17:54:57 -07001410 }
1411
1412 /* Backtrack one entry */
1413 priv->rxq.read = i;
Tomas Winklera55360e2008-05-05 10:22:28 +08001414 iwl_rx_queue_restock(priv);
1415}
Tomas Winklera55360e2008-05-05 10:22:28 +08001416
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001417#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001418static void iwl4965_print_rx_config_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001419{
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08001420 struct iwl_rxon_cmd *rxon = &priv->staging_rxon;
Joe Perches0795af52007-10-03 17:59:30 -07001421 DECLARE_MAC_BUF(mac);
1422
Zhu Yib481de92007-09-25 17:54:57 -07001423 IWL_DEBUG_RADIO("RX CONFIG:\n");
Ester Kummerbf403db2008-05-05 10:22:40 +08001424 iwl_print_hex_dump(priv, IWL_DL_RADIO, (u8 *) rxon, sizeof(*rxon));
Zhu Yib481de92007-09-25 17:54:57 -07001425 IWL_DEBUG_RADIO("u16 channel: 0x%x\n", le16_to_cpu(rxon->channel));
1426 IWL_DEBUG_RADIO("u32 flags: 0x%08X\n", le32_to_cpu(rxon->flags));
1427 IWL_DEBUG_RADIO("u32 filter_flags: 0x%08x\n",
1428 le32_to_cpu(rxon->filter_flags));
1429 IWL_DEBUG_RADIO("u8 dev_type: 0x%x\n", rxon->dev_type);
1430 IWL_DEBUG_RADIO("u8 ofdm_basic_rates: 0x%02x\n",
1431 rxon->ofdm_basic_rates);
1432 IWL_DEBUG_RADIO("u8 cck_basic_rates: 0x%02x\n", rxon->cck_basic_rates);
Joe Perches0795af52007-10-03 17:59:30 -07001433 IWL_DEBUG_RADIO("u8[6] node_addr: %s\n",
1434 print_mac(mac, rxon->node_addr));
1435 IWL_DEBUG_RADIO("u8[6] bssid_addr: %s\n",
1436 print_mac(mac, rxon->bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07001437 IWL_DEBUG_RADIO("u16 assoc_id: 0x%x\n", le16_to_cpu(rxon->assoc_id));
1438}
1439#endif
1440
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001441static void iwl4965_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001442{
1443 IWL_DEBUG_ISR("Enabling interrupts\n");
1444 set_bit(STATUS_INT_ENABLED, &priv->status);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001445 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001446}
1447
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001448/* call this function to flush any scheduled tasklet */
1449static inline void iwl_synchronize_irq(struct iwl_priv *priv)
1450{
1451 /* wait to make sure we flush pedding tasklet*/
1452 synchronize_irq(priv->pci_dev->irq);
1453 tasklet_kill(&priv->irq_tasklet);
1454}
1455
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001456static inline void iwl4965_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001457{
1458 clear_bit(STATUS_INT_ENABLED, &priv->status);
1459
1460 /* disable interrupts from uCode/NIC to host */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001461 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001462
1463 /* acknowledge/clear/reset any interrupts still pending
1464 * from uCode or flow handler (Rx/Tx DMA) */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001465 iwl_write32(priv, CSR_INT, 0xffffffff);
1466 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Zhu Yib481de92007-09-25 17:54:57 -07001467 IWL_DEBUG_ISR("Disabled interrupts\n");
1468}
1469
Zhu Yib481de92007-09-25 17:54:57 -07001470
Zhu Yib481de92007-09-25 17:54:57 -07001471/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001472 * iwl4965_irq_handle_error - called for HW or SW error interrupt from card
Zhu Yib481de92007-09-25 17:54:57 -07001473 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001474static void iwl4965_irq_handle_error(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001475{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001476 /* Set the FW error flag -- cleared on iwl4965_down */
Zhu Yib481de92007-09-25 17:54:57 -07001477 set_bit(STATUS_FW_ERROR, &priv->status);
1478
1479 /* Cancel currently queued command. */
1480 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1481
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001482#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001483 if (priv->debug_level & IWL_DL_FW_ERRORS) {
Ester Kummerede0cba2008-05-29 16:34:46 +08001484 iwl_dump_nic_error_log(priv);
Ester Kummer189a2b52008-05-15 13:54:18 +08001485 iwl_dump_nic_event_log(priv);
Ester Kummerbf403db2008-05-05 10:22:40 +08001486 iwl4965_print_rx_config_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001487 }
1488#endif
1489
1490 wake_up_interruptible(&priv->wait_command_queue);
1491
1492 /* Keep the restart process from trying to send host
1493 * commands by clearing the INIT status bit */
1494 clear_bit(STATUS_READY, &priv->status);
1495
1496 if (!test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08001497 IWL_DEBUG(IWL_DL_FW_ERRORS,
Zhu Yib481de92007-09-25 17:54:57 -07001498 "Restarting adapter due to uCode error.\n");
1499
Tomas Winkler3109ece2008-03-28 16:33:35 -07001500 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001501 memcpy(&priv->recovery_rxon, &priv->active_rxon,
1502 sizeof(priv->recovery_rxon));
1503 priv->error_recovering = 1;
1504 }
Ester Kummer3a1081e2008-05-06 11:05:14 +08001505 if (priv->cfg->mod_params->restart_fw)
1506 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001507 }
1508}
1509
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001510static void iwl4965_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001511{
1512 unsigned long flags;
1513
1514 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
1515 sizeof(priv->staging_rxon));
1516 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001517 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001518
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08001519 iwl_rxon_add_station(priv, priv->bssid, 1);
Zhu Yib481de92007-09-25 17:54:57 -07001520
1521 spin_lock_irqsave(&priv->lock, flags);
1522 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
1523 priv->error_recovering = 0;
1524 spin_unlock_irqrestore(&priv->lock, flags);
1525}
1526
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001527static void iwl4965_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001528{
1529 u32 inta, handled = 0;
1530 u32 inta_fh;
1531 unsigned long flags;
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001532#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001533 u32 inta_mask;
1534#endif
1535
1536 spin_lock_irqsave(&priv->lock, flags);
1537
1538 /* Ack/clear/reset pending uCode interrupts.
1539 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
1540 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001541 inta = iwl_read32(priv, CSR_INT);
1542 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07001543
1544 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
1545 * Any new interrupts that happen after this, either while we're
1546 * in this tasklet, or later, will show up in next ISR/tasklet. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001547 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
1548 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07001549
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001550#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001551 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001552 /* just for debug */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001553 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07001554 IWL_DEBUG_ISR("inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1555 inta, inta_mask, inta_fh);
1556 }
1557#endif
1558
1559 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
1560 * atomic, make sure that inta covers all the interrupts that
1561 * we've discovered, even if FH interrupt came in just after
1562 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001563 if (inta_fh & CSR49_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001564 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08001565 if (inta_fh & CSR49_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07001566 inta |= CSR_INT_BIT_FH_TX;
1567
1568 /* Now service all interrupt bits discovered above. */
1569 if (inta & CSR_INT_BIT_HW_ERR) {
1570 IWL_ERROR("Microcode HW error detected. Restarting.\n");
1571
1572 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001573 iwl4965_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001574
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001575 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001576
1577 handled |= CSR_INT_BIT_HW_ERR;
1578
1579 spin_unlock_irqrestore(&priv->lock, flags);
1580
1581 return;
1582 }
1583
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001584#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001585 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07001586 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001587 if (inta & CSR_INT_BIT_SCD)
1588 IWL_DEBUG_ISR("Scheduler finished to transmit "
1589 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001590
1591 /* Alive notification via Rx interrupt will do the real work */
1592 if (inta & CSR_INT_BIT_ALIVE)
1593 IWL_DEBUG_ISR("Alive interrupt\n");
1594 }
1595#endif
1596 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001597 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07001598
Ben Cahill9fbab512007-11-29 11:09:47 +08001599 /* HW RF KILL switch toggled */
Zhu Yib481de92007-09-25 17:54:57 -07001600 if (inta & CSR_INT_BIT_RF_KILL) {
1601 int hw_rf_kill = 0;
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001602 if (!(iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yib481de92007-09-25 17:54:57 -07001603 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW))
1604 hw_rf_kill = 1;
1605
Ester Kummerf3d67992008-05-06 11:05:12 +08001606 IWL_DEBUG(IWL_DL_RF_KILL, "RF_KILL bit toggled to %s.\n",
Zhu Yib481de92007-09-25 17:54:57 -07001607 hw_rf_kill ? "disable radio":"enable radio");
1608
Emmanuel Grumbacha9efa652008-06-30 17:23:25 +08001609 /* driver only loads ucode once setting the interface up.
1610 * the driver as well won't allow loading if RFKILL is set
1611 * therefore no need to restart the driver from this handler
1612 */
1613 if (!hw_rf_kill && !test_bit(STATUS_ALIVE, &priv->status))
Zhu Yi53e49092007-12-06 16:08:44 +08001614 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07001615
1616 handled |= CSR_INT_BIT_RF_KILL;
1617 }
1618
Ben Cahill9fbab512007-11-29 11:09:47 +08001619 /* Chip got too hot and stopped itself */
Zhu Yib481de92007-09-25 17:54:57 -07001620 if (inta & CSR_INT_BIT_CT_KILL) {
1621 IWL_ERROR("Microcode CT kill error detected.\n");
1622 handled |= CSR_INT_BIT_CT_KILL;
1623 }
1624
1625 /* Error detected by uCode */
1626 if (inta & CSR_INT_BIT_SW_ERR) {
1627 IWL_ERROR("Microcode SW error detected. Restarting 0x%X.\n",
1628 inta);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001629 iwl4965_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001630 handled |= CSR_INT_BIT_SW_ERR;
1631 }
1632
1633 /* uCode wakes up after power-down sleep */
1634 if (inta & CSR_INT_BIT_WAKEUP) {
1635 IWL_DEBUG_ISR("Wakeup interrupt\n");
Tomas Winklera55360e2008-05-05 10:22:28 +08001636 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Tomas Winklerbabcebf2008-05-15 13:54:00 +08001637 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
1638 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
1639 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
1640 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
1641 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
1642 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07001643
1644 handled |= CSR_INT_BIT_WAKEUP;
1645 }
1646
1647 /* All uCode command responses, including Tx command responses,
1648 * Rx "responses" (frame-received notification), and other
1649 * notifications from uCode come through here*/
1650 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Tomas Winklera55360e2008-05-05 10:22:28 +08001651 iwl_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001652 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
1653 }
1654
1655 if (inta & CSR_INT_BIT_FH_TX) {
1656 IWL_DEBUG_ISR("Tx interrupt\n");
1657 handled |= CSR_INT_BIT_FH_TX;
Ron Rindjunskydbb983b2008-05-15 13:54:12 +08001658 /* FH finished to write, send event */
1659 priv->ucode_write_complete = 1;
1660 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07001661 }
1662
1663 if (inta & ~handled)
1664 IWL_ERROR("Unhandled INTA bits 0x%08x\n", inta & ~handled);
1665
1666 if (inta & ~CSR_INI_SET_MASK) {
1667 IWL_WARNING("Disabled INTA bits 0x%08x were pending\n",
1668 inta & ~CSR_INI_SET_MASK);
1669 IWL_WARNING(" with FH_INT = 0x%08x\n", inta_fh);
1670 }
1671
1672 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001673 /* only Re-enable if diabled by irq */
1674 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1675 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001676
Tomas Winkler0a6857e2008-03-12 16:58:49 -07001677#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08001678 if (priv->debug_level & (IWL_DL_ISR)) {
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001679 inta = iwl_read32(priv, CSR_INT);
1680 inta_mask = iwl_read32(priv, CSR_INT_MASK);
1681 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001682 IWL_DEBUG_ISR("End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
1683 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
1684 }
1685#endif
1686 spin_unlock_irqrestore(&priv->lock, flags);
1687}
1688
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001689static irqreturn_t iwl4965_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07001690{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001691 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07001692 u32 inta, inta_mask;
1693 u32 inta_fh;
1694 if (!priv)
1695 return IRQ_NONE;
1696
1697 spin_lock(&priv->lock);
1698
1699 /* Disable (but don't clear!) interrupts here to avoid
1700 * back-to-back ISRs and sporadic interrupts from our NIC.
1701 * If we have something to service, the tasklet will re-enable ints.
1702 * If we *don't* have something, we'll re-enable before leaving here. */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001703 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
1704 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07001705
1706 /* Discover which interrupts are active/pending */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07001707 inta = iwl_read32(priv, CSR_INT);
1708 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07001709
1710 /* Ignore interrupt if there's nothing in NIC to service.
1711 * This may be due to IRQ shared with another device,
1712 * or due to sporadic interrupts thrown from our NIC. */
1713 if (!inta && !inta_fh) {
1714 IWL_DEBUG_ISR("Ignore interrupt, inta == 0, inta_fh == 0\n");
1715 goto none;
1716 }
1717
1718 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
Oliver Neukum66fbb542007-11-15 09:31:10 +08001719 /* Hardware disappeared. It might have already raised
1720 * an interrupt */
Zhu Yib481de92007-09-25 17:54:57 -07001721 IWL_WARNING("HARDWARE GONE?? INTA == 0x%080x\n", inta);
Oliver Neukum66fbb542007-11-15 09:31:10 +08001722 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07001723 }
1724
1725 IWL_DEBUG_ISR("ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
1726 inta, inta_mask, inta_fh);
1727
Joonwoo Park25c03d82008-01-23 10:15:20 -08001728 inta &= ~CSR_INT_BIT_SCD;
1729
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001730 /* iwl4965_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08001731 if (likely(inta || inta_fh))
1732 tasklet_schedule(&priv->irq_tasklet);
Zhu Yib481de92007-09-25 17:54:57 -07001733
Oliver Neukum66fbb542007-11-15 09:31:10 +08001734 unplugged:
1735 spin_unlock(&priv->lock);
Zhu Yib481de92007-09-25 17:54:57 -07001736 return IRQ_HANDLED;
1737
1738 none:
1739 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001740 /* only Re-enable if diabled by irq */
1741 if (test_bit(STATUS_INT_ENABLED, &priv->status))
1742 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001743 spin_unlock(&priv->lock);
1744 return IRQ_NONE;
1745}
1746
Zhu Yib481de92007-09-25 17:54:57 -07001747/******************************************************************************
1748 *
1749 * uCode download functions
1750 *
1751 ******************************************************************************/
1752
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001753static void iwl4965_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001754{
Tomas Winkler98c92212008-01-14 17:46:20 -08001755 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
1756 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
1757 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
1758 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
1759 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
1760 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001761}
1762
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08001763static void iwl4965_nic_start(struct iwl_priv *priv)
1764{
1765 /* Remove all resets to allow NIC to operate */
1766 iwl_write32(priv, CSR_RESET, 0);
1767}
1768
1769
Zhu Yib481de92007-09-25 17:54:57 -07001770/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001771 * iwl4965_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07001772 *
1773 * Copy into buffers for card to fetch via bus-mastering
1774 */
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07001775static int iwl4965_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001776{
Ron Rindjunsky14b3d332008-06-13 15:44:54 +08001777 struct iwl_ucode *ucode;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001778 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07001779 const struct firmware *ucode_raw;
Tomas Winkler4bf775c2008-03-04 18:09:31 -08001780 const char *name = priv->cfg->fw_name;
Zhu Yib481de92007-09-25 17:54:57 -07001781 u8 *src;
1782 size_t len;
1783 u32 ver, inst_size, data_size, init_size, init_data_size, boot_size;
1784
1785 /* Ask kernel firmware_class module to get the boot firmware off disk.
1786 * request_firmware() is synchronous, file is in memory on return. */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001787 ret = request_firmware(&ucode_raw, name, &priv->pci_dev->dev);
1788 if (ret < 0) {
1789 IWL_ERROR("%s firmware file req failed: Reason %d\n",
1790 name, ret);
Zhu Yib481de92007-09-25 17:54:57 -07001791 goto error;
1792 }
1793
1794 IWL_DEBUG_INFO("Got firmware '%s' file (%zd bytes) from disk\n",
1795 name, ucode_raw->size);
1796
1797 /* Make sure that we got at least our header! */
1798 if (ucode_raw->size < sizeof(*ucode)) {
1799 IWL_ERROR("File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001800 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001801 goto err_release;
1802 }
1803
1804 /* Data from ucode file: header followed by uCode images */
1805 ucode = (void *)ucode_raw->data;
1806
1807 ver = le32_to_cpu(ucode->ver);
1808 inst_size = le32_to_cpu(ucode->inst_size);
1809 data_size = le32_to_cpu(ucode->data_size);
1810 init_size = le32_to_cpu(ucode->init_size);
1811 init_data_size = le32_to_cpu(ucode->init_data_size);
1812 boot_size = le32_to_cpu(ucode->boot_size);
1813
1814 IWL_DEBUG_INFO("f/w package hdr ucode version = 0x%x\n", ver);
1815 IWL_DEBUG_INFO("f/w package hdr runtime inst size = %u\n",
1816 inst_size);
1817 IWL_DEBUG_INFO("f/w package hdr runtime data size = %u\n",
1818 data_size);
1819 IWL_DEBUG_INFO("f/w package hdr init inst size = %u\n",
1820 init_size);
1821 IWL_DEBUG_INFO("f/w package hdr init data size = %u\n",
1822 init_data_size);
1823 IWL_DEBUG_INFO("f/w package hdr boot inst size = %u\n",
1824 boot_size);
1825
1826 /* Verify size of file vs. image size info in file's header */
1827 if (ucode_raw->size < sizeof(*ucode) +
1828 inst_size + data_size + init_size +
1829 init_data_size + boot_size) {
1830
1831 IWL_DEBUG_INFO("uCode file size %d too small\n",
1832 (int)ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001833 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001834 goto err_release;
1835 }
1836
1837 /* Verify that uCode images will fit in card's SRAM */
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001838 if (inst_size > priv->hw_params.max_inst_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001839 IWL_DEBUG_INFO("uCode instr len %d too large to fit in\n",
1840 inst_size);
1841 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001842 goto err_release;
1843 }
1844
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001845 if (data_size > priv->hw_params.max_data_size) {
Tomas Winkler90e759d2007-11-29 11:09:41 +08001846 IWL_DEBUG_INFO("uCode data len %d too large to fit in\n",
1847 data_size);
1848 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001849 goto err_release;
1850 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001851 if (init_size > priv->hw_params.max_inst_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001852 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001853 ("uCode init instr len %d too large to fit in\n",
1854 init_size);
1855 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001856 goto err_release;
1857 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001858 if (init_data_size > priv->hw_params.max_data_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001859 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001860 ("uCode init data len %d too large to fit in\n",
1861 init_data_size);
1862 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001863 goto err_release;
1864 }
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07001865 if (boot_size > priv->hw_params.max_bsm_size) {
Zhu Yib481de92007-09-25 17:54:57 -07001866 IWL_DEBUG_INFO
Tomas Winkler90e759d2007-11-29 11:09:41 +08001867 ("uCode boot instr len %d too large to fit in\n",
1868 boot_size);
1869 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07001870 goto err_release;
1871 }
1872
1873 /* Allocate ucode buffers for card's bus-master loading ... */
1874
1875 /* Runtime instructions and 2 copies of data:
1876 * 1) unmodified from disk
1877 * 2) backup cache for save/restore during power-downs */
1878 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001879 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07001880
1881 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001882 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07001883
1884 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001885 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07001886
1887 /* Initialization instructions and data */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001888 if (init_size && init_data_size) {
1889 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001890 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Zhu Yib481de92007-09-25 17:54:57 -07001891
Tomas Winkler90e759d2007-11-29 11:09:41 +08001892 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001893 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08001894
1895 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
1896 goto err_pci_alloc;
1897 }
Zhu Yib481de92007-09-25 17:54:57 -07001898
1899 /* Bootstrap (instructions only, no data) */
Tomas Winkler90e759d2007-11-29 11:09:41 +08001900 if (boot_size) {
1901 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08001902 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07001903
Tomas Winkler90e759d2007-11-29 11:09:41 +08001904 if (!priv->ucode_boot.v_addr)
1905 goto err_pci_alloc;
1906 }
Zhu Yib481de92007-09-25 17:54:57 -07001907
1908 /* Copy images into buffers for card's bus-master reads ... */
1909
1910 /* Runtime instructions (first block of data in file) */
1911 src = &ucode->data[0];
1912 len = priv->ucode_code.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001913 IWL_DEBUG_INFO("Copying (but not loading) uCode instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001914 memcpy(priv->ucode_code.v_addr, src, len);
1915 IWL_DEBUG_INFO("uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
1916 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
1917
1918 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001919 * NOTE: Copy into backup buffer will be done in iwl4965_up() */
Zhu Yib481de92007-09-25 17:54:57 -07001920 src = &ucode->data[inst_size];
1921 len = priv->ucode_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001922 IWL_DEBUG_INFO("Copying (but not loading) uCode data len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001923 memcpy(priv->ucode_data.v_addr, src, len);
1924 memcpy(priv->ucode_data_backup.v_addr, src, len);
1925
1926 /* Initialization instructions (3rd block) */
1927 if (init_size) {
1928 src = &ucode->data[inst_size + data_size];
1929 len = priv->ucode_init.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001930 IWL_DEBUG_INFO("Copying (but not loading) init instr len %Zd\n",
1931 len);
Zhu Yib481de92007-09-25 17:54:57 -07001932 memcpy(priv->ucode_init.v_addr, src, len);
1933 }
1934
1935 /* Initialization data (4th block) */
1936 if (init_data_size) {
1937 src = &ucode->data[inst_size + data_size + init_size];
1938 len = priv->ucode_init_data.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001939 IWL_DEBUG_INFO("Copying (but not loading) init data len %Zd\n",
1940 len);
Zhu Yib481de92007-09-25 17:54:57 -07001941 memcpy(priv->ucode_init_data.v_addr, src, len);
1942 }
1943
1944 /* Bootstrap instructions (5th block) */
1945 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
1946 len = priv->ucode_boot.len;
Tomas Winkler90e759d2007-11-29 11:09:41 +08001947 IWL_DEBUG_INFO("Copying (but not loading) boot instr len %Zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07001948 memcpy(priv->ucode_boot.v_addr, src, len);
1949
1950 /* We have our copies now, allow OS release its copies */
1951 release_firmware(ucode_raw);
1952 return 0;
1953
1954 err_pci_alloc:
1955 IWL_ERROR("failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08001956 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001957 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001958
1959 err_release:
1960 release_firmware(ucode_raw);
1961
1962 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08001963 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07001964}
1965
Zhu Yib481de92007-09-25 17:54:57 -07001966/**
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001967 * iwl_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07001968 * from protocol/runtime uCode (initialization uCode's
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001969 * Alive gets handled by iwl_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07001970 */
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08001971static void iwl_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001972{
Tomas Winkler57aab752008-04-14 21:16:03 -07001973 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07001974
1975 IWL_DEBUG_INFO("Runtime Alive received.\n");
1976
1977 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
1978 /* We had an error bringing up the hardware, so take it
1979 * all the way back down so we can try again */
1980 IWL_DEBUG_INFO("Alive failed.\n");
1981 goto restart;
1982 }
1983
1984 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
1985 * This is a paranoid check, because we would not have gotten the
1986 * "runtime" alive if code weren't properly loaded. */
Emmanuel Grumbachb0692f22008-04-24 11:55:18 -07001987 if (iwl_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07001988 /* Runtime instruction load was bad;
1989 * take it all the way back down so we can try again */
1990 IWL_DEBUG_INFO("Bad runtime uCode load.\n");
1991 goto restart;
1992 }
1993
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08001994 iwl_clear_stations_table(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07001995 ret = priv->cfg->ops->lib->alive_notify(priv);
1996 if (ret) {
Zhu Yib481de92007-09-25 17:54:57 -07001997 IWL_WARNING("Could not complete ALIVE transition [ntf]: %d\n",
Tomas Winkler57aab752008-04-14 21:16:03 -07001998 ret);
Zhu Yib481de92007-09-25 17:54:57 -07001999 goto restart;
2000 }
2001
Ben Cahill9fbab512007-11-29 11:09:47 +08002002 /* After the ALIVE response, we can send host commands to 4965 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002003 set_bit(STATUS_ALIVE, &priv->status);
2004
Tomas Winklerfee12472008-04-03 16:05:21 -07002005 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002006 return;
2007
Johannes Berg36d68252008-05-15 12:55:26 +02002008 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002009
2010 priv->active_rate = priv->rates_mask;
2011 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2012
Tomas Winkler3109ece2008-03-28 16:33:35 -07002013 if (iwl_is_associated(priv)) {
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002014 struct iwl_rxon_cmd *active_rxon =
2015 (struct iwl_rxon_cmd *)&priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -07002016
2017 memcpy(&priv->staging_rxon, &priv->active_rxon,
2018 sizeof(priv->staging_rxon));
2019 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2020 } else {
2021 /* Initialize our rx_config data */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002022 iwl4965_connection_init_rx_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002023 memcpy(priv->staging_rxon.node_addr, priv->mac_addr, ETH_ALEN);
2024 }
2025
Ben Cahill9fbab512007-11-29 11:09:47 +08002026 /* Configure Bluetooth device coexistence support */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002027 iwl4965_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002028
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002029 iwl_reset_run_time_calib(priv);
2030
Zhu Yib481de92007-09-25 17:54:57 -07002031 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002032 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002033
2034 /* At this point, the NIC is initialized and operational */
Emmanuel Grumbach47f4a582008-06-12 09:47:13 +08002035 iwl_rf_kill_ct_config(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002036
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002037 iwl_leds_register(priv);
2038
Zhu Yib481de92007-09-25 17:54:57 -07002039 IWL_DEBUG_INFO("ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002040 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002041 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002042
2043 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002044 iwl4965_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002045
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08002046 iwl_power_update_mode(priv, 1);
Mohamed Abbas84363e62008-04-04 16:59:58 -07002047 ieee80211_notify_mac(priv->hw, IEEE80211_NOTIFY_RE_ASSOC);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002048
2049 if (test_and_clear_bit(STATUS_MODE_PENDING, &priv->status))
2050 iwl4965_set_mode(priv, priv->iw_mode);
2051
Zhu Yib481de92007-09-25 17:54:57 -07002052 return;
2053
2054 restart:
2055 queue_work(priv->workqueue, &priv->restart);
2056}
2057
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002058static void iwl_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002059
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002060static void __iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002061{
2062 unsigned long flags;
2063 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002064
2065 IWL_DEBUG_INFO(DRV_NAME " is going down\n");
2066
Zhu Yib481de92007-09-25 17:54:57 -07002067 if (!exit_pending)
2068 set_bit(STATUS_EXIT_PENDING, &priv->status);
2069
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002070 iwl_leds_unregister(priv);
2071
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002072 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002073
2074 /* Unblock any waiting calls */
2075 wake_up_interruptible_all(&priv->wait_command_queue);
2076
Zhu Yib481de92007-09-25 17:54:57 -07002077 /* Wipe out the EXIT_PENDING status bit if we are not actually
2078 * exiting the module */
2079 if (!exit_pending)
2080 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2081
2082 /* stop and reset the on-board processor */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002083 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002084
2085 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002086 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002087 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002088 spin_unlock_irqrestore(&priv->lock, flags);
2089 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002090
2091 if (priv->mac80211_registered)
2092 ieee80211_stop_queues(priv->hw);
2093
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002094 /* If we have not previously called iwl4965_init() then
Zhu Yib481de92007-09-25 17:54:57 -07002095 * clear all bits but the RF Kill and SUSPEND bits and return */
Tomas Winklerfee12472008-04-03 16:05:21 -07002096 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002097 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2098 STATUS_RF_KILL_HW |
2099 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2100 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002101 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2102 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002103 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002104 STATUS_IN_SUSPEND |
2105 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2106 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002107 goto exit;
2108 }
2109
2110 /* ...otherwise clear out all the status bits but the RF Kill and
2111 * SUSPEND bits and continue taking the NIC down. */
2112 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2113 STATUS_RF_KILL_HW |
2114 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2115 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002116 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2117 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002118 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
2119 STATUS_IN_SUSPEND |
2120 test_bit(STATUS_FW_ERROR, &priv->status) <<
Mohamed Abbas052ec3f2008-06-30 17:23:15 +08002121 STATUS_FW_ERROR |
2122 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2123 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002124
2125 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002126 iwl_clear_bit(priv, CSR_GP_CNTRL,
Ben Cahill9fbab512007-11-29 11:09:47 +08002127 CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002128 spin_unlock_irqrestore(&priv->lock, flags);
2129
Tomas Winklerda1bc452008-05-29 16:35:00 +08002130 iwl_txq_ctx_stop(priv);
Tomas Winklerb3bbacb2008-05-29 16:35:01 +08002131 iwl_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002132
2133 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002134 if (!iwl_grab_nic_access(priv)) {
2135 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002136 APMG_CLK_VAL_DMA_CLK_RQT);
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002137 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002138 }
2139 spin_unlock_irqrestore(&priv->lock, flags);
2140
2141 udelay(5);
2142
Tomas Winkler7f066102008-05-29 16:34:57 +08002143 /* FIXME: apm_ops.suspend(priv) */
2144 priv->cfg->ops->lib->apm_ops.reset(priv);
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002145 priv->cfg->ops->lib->free_shared_mem(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002146
2147 exit:
Tomas Winkler885ba202008-05-29 16:34:55 +08002148 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07002149
2150 if (priv->ibss_beacon)
2151 dev_kfree_skb(priv->ibss_beacon);
2152 priv->ibss_beacon = NULL;
2153
2154 /* clear out any free frames */
Tomas Winklerfcab4232008-05-15 13:54:01 +08002155 iwl_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002156}
2157
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002158static void iwl4965_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002159{
2160 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002161 __iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002162 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08002163
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08002164 iwl_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002165}
2166
2167#define MAX_HW_RESTARTS 5
2168
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002169static int __iwl4965_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002170{
Tomas Winkler57aab752008-04-14 21:16:03 -07002171 int i;
2172 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002173
2174 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
2175 IWL_WARNING("Exit pending; will not bring the NIC up\n");
2176 return -EIO;
2177 }
2178
Reinette Chatree903fbd2008-01-30 22:05:15 -08002179 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
2180 IWL_ERROR("ucode not available for device bringup\n");
2181 return -EIO;
2182 }
2183
Zhu Yie655b9f2008-01-24 02:19:38 -08002184 /* If platform's RF_KILL switch is NOT set to KILL */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002185 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08002186 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
2187 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002188 else
Zhu Yie655b9f2008-01-24 02:19:38 -08002189 set_bit(STATUS_RF_KILL_HW, &priv->status);
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002190
2191 if (!test_bit(STATUS_IN_SUSPEND, &priv->status) &&
2192 iwl_is_rfkill(priv)) {
Emmanuel Grumbach3bff19c2008-06-30 17:23:19 +08002193 IWL_WARNING("Radio disabled by %s RF Kill switch\n",
2194 test_bit(STATUS_RF_KILL_HW, &priv->status) ? "HW" : "SW");
2195 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07002196 }
2197
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002198 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07002199
Ron Rindjunsky399f4902008-04-23 17:14:56 -07002200 ret = priv->cfg->ops->lib->alloc_shared_mem(priv);
2201 if (ret) {
2202 IWL_ERROR("Unable to allocate shared memory\n");
2203 return ret;
2204 }
2205
Ron Rindjunsky1053d352008-05-05 10:22:43 +08002206 ret = iwl_hw_nic_init(priv);
Tomas Winkler57aab752008-04-14 21:16:03 -07002207 if (ret) {
2208 IWL_ERROR("Unable to init nic\n");
2209 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002210 }
2211
2212 /* make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002213 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2214 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07002215 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
2216
2217 /* clear (again), then enable host interrupts */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002218 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002219 iwl4965_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002220
2221 /* really make sure rfkill handshake bits are cleared */
Tomas Winkler3395f6e2008-03-25 16:33:37 -07002222 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
2223 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07002224
2225 /* Copy original ucode data image from disk into backup cache.
2226 * This will be used to initialize the on-board processor's
2227 * data SRAM for a clean start when the runtime program first loads. */
2228 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08002229 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07002230
Zhu Yie655b9f2008-01-24 02:19:38 -08002231 /* We return success when we resume from suspend and rf_kill is on. */
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002232 if (test_bit(STATUS_RF_KILL_HW, &priv->status) ||
2233 test_bit(STATUS_RF_KILL_SW, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002234 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002235
2236 for (i = 0; i < MAX_HW_RESTARTS; i++) {
2237
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08002238 iwl_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002239
2240 /* load bootstrap state machine,
2241 * load bootstrap program into processor's memory,
2242 * prepare to load the "initialize" uCode */
Tomas Winkler57aab752008-04-14 21:16:03 -07002243 ret = priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002244
Tomas Winkler57aab752008-04-14 21:16:03 -07002245 if (ret) {
2246 IWL_ERROR("Unable to set up bootstrap uCode: %d\n", ret);
Zhu Yib481de92007-09-25 17:54:57 -07002247 continue;
2248 }
2249
Emmanuel Grumbachf3d5b452008-06-12 09:47:04 +08002250 /* Clear out the uCode error bit if it is set */
2251 clear_bit(STATUS_FW_ERROR, &priv->status);
2252
Zhu Yib481de92007-09-25 17:54:57 -07002253 /* start card; "initialize" will load runtime ucode */
Ron Rindjunskyedcdf8b2008-05-15 13:53:55 +08002254 iwl4965_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002255
Zhu Yib481de92007-09-25 17:54:57 -07002256 IWL_DEBUG_INFO(DRV_NAME " is coming up\n");
2257
2258 return 0;
2259 }
2260
2261 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002262 __iwl4965_down(priv);
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002263 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002264
2265 /* tried to restart and config the device for as long as our
2266 * patience could withstand */
2267 IWL_ERROR("Unable to initialize device after %d attempts.\n", i);
2268 return -EIO;
2269}
2270
2271
2272/*****************************************************************************
2273 *
2274 * Workqueue callbacks
2275 *
2276 *****************************************************************************/
2277
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002278static void iwl_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002279{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002280 struct iwl_priv *priv =
2281 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002282
2283 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2284 return;
2285
2286 mutex_lock(&priv->mutex);
Emmanuel Grumbachf3ccc082008-05-05 10:22:45 +08002287 priv->cfg->ops->lib->init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002288 mutex_unlock(&priv->mutex);
2289}
2290
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002291static void iwl_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002292{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002293 struct iwl_priv *priv =
2294 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07002295
2296 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2297 return;
2298
2299 mutex_lock(&priv->mutex);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08002300 iwl_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002301 mutex_unlock(&priv->mutex);
2302}
2303
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002304static void iwl4965_bg_rf_kill(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002305{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002306 struct iwl_priv *priv = container_of(work, struct iwl_priv, rf_kill);
Zhu Yib481de92007-09-25 17:54:57 -07002307
2308 wake_up_interruptible(&priv->wait_command_queue);
2309
2310 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2311 return;
2312
2313 mutex_lock(&priv->mutex);
2314
Tomas Winklerfee12472008-04-03 16:05:21 -07002315 if (!iwl_is_rfkill(priv)) {
Ester Kummerf3d67992008-05-06 11:05:12 +08002316 IWL_DEBUG(IWL_DL_RF_KILL,
Zhu Yib481de92007-09-25 17:54:57 -07002317 "HW and/or SW RF Kill no longer active, restarting "
2318 "device\n");
2319 if (!test_bit(STATUS_EXIT_PENDING, &priv->status))
2320 queue_work(priv->workqueue, &priv->restart);
2321 } else {
Mohamed Abbasad97edd2008-03-28 16:21:06 -07002322 /* make sure mac80211 stop sending Tx frame */
2323 if (priv->mac80211_registered)
2324 ieee80211_stop_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002325
2326 if (!test_bit(STATUS_RF_KILL_HW, &priv->status))
2327 IWL_DEBUG_RF_KILL("Can not turn radio back on - "
2328 "disabled by SW switch\n");
2329 else
2330 IWL_WARNING("Radio Frequency Kill Switch is On:\n"
2331 "Kill switch must be turned off for "
2332 "wireless networking to work.\n");
2333 }
2334 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002335 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002336}
2337
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002338static void iwl4965_bg_set_monitor(struct work_struct *work)
2339{
2340 struct iwl_priv *priv = container_of(work,
2341 struct iwl_priv, set_monitor);
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002342 int ret;
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002343
2344 IWL_DEBUG(IWL_DL_STATE, "setting monitor mode\n");
2345
2346 mutex_lock(&priv->mutex);
2347
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002348 ret = iwl4965_set_mode(priv, IEEE80211_IF_TYPE_MNTR);
2349
2350 if (ret) {
2351 if (ret == -EAGAIN)
2352 IWL_DEBUG(IWL_DL_STATE, "leave - not ready\n");
2353 else
2354 IWL_ERROR("iwl4965_set_mode() failed ret = %d\n", ret);
2355 }
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08002356
2357 mutex_unlock(&priv->mutex);
2358}
2359
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08002360static void iwl_bg_run_time_calib_work(struct work_struct *work)
2361{
2362 struct iwl_priv *priv = container_of(work, struct iwl_priv,
2363 run_time_calib_work);
2364
2365 mutex_lock(&priv->mutex);
2366
2367 if (test_bit(STATUS_EXIT_PENDING, &priv->status) ||
2368 test_bit(STATUS_SCANNING, &priv->status)) {
2369 mutex_unlock(&priv->mutex);
2370 return;
2371 }
2372
2373 if (priv->start_calib) {
2374 iwl_chain_noise_calibration(priv, &priv->statistics);
2375
2376 iwl_sensitivity_calibration(priv, &priv->statistics);
2377 }
2378
2379 mutex_unlock(&priv->mutex);
2380 return;
2381}
2382
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002383static void iwl4965_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002384{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002385 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07002386
2387 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2388 return;
2389
2390 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002391 __iwl4965_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002392 mutex_unlock(&priv->mutex);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002393 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002394}
2395
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002396static void iwl4965_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002397{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002398 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07002399
2400 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2401 return;
2402
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002403 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002404 queue_work(priv->workqueue, &priv->up);
2405}
2406
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002407static void iwl4965_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07002408{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002409 struct iwl_priv *priv =
2410 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07002411
2412 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2413 return;
2414
2415 mutex_lock(&priv->mutex);
Tomas Winklera55360e2008-05-05 10:22:28 +08002416 iwl_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002417 mutex_unlock(&priv->mutex);
2418}
2419
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002420#define IWL_DELAY_NEXT_SCAN (HZ*2)
2421
Reinette Chatre508e32e2008-04-14 21:16:13 -07002422static void iwl4965_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002423{
Zhu Yib481de92007-09-25 17:54:57 -07002424 struct ieee80211_conf *conf = NULL;
Tomas Winkler857485c2008-03-21 13:53:44 -07002425 int ret = 0;
Joe Perches0795af52007-10-03 17:59:30 -07002426 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002427
2428 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2429 IWL_ERROR("%s Should not be called in AP mode\n", __FUNCTION__);
2430 return;
2431 }
2432
Joe Perches0795af52007-10-03 17:59:30 -07002433 IWL_DEBUG_ASSOC("Associated as %d to: %s\n",
2434 priv->assoc_id,
2435 print_mac(mac, priv->active_rxon.bssid_addr));
Zhu Yib481de92007-09-25 17:54:57 -07002436
2437
2438 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2439 return;
2440
Zhu Yib481de92007-09-25 17:54:57 -07002441
Reinette Chatre508e32e2008-04-14 21:16:13 -07002442 if (!priv->vif || !priv->is_open)
Mohamed Abbas948c1712007-10-25 17:15:45 +08002443 return;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002444
Tomas Winkler2a421b92008-06-12 09:47:10 +08002445 iwl_scan_cancel_timeout(priv, 200);
mabbas052c4b92007-10-25 17:15:43 +08002446
Zhu Yib481de92007-09-25 17:54:57 -07002447 conf = ieee80211_get_hw_conf(priv->hw);
2448
2449 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002450 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002451
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002452 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2453 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002454 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002455 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002456 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07002457 IWL_WARNING("REPLY_RXON_TIMING failed - "
2458 "Attempting to continue.\n");
2459
2460 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
2461
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02002462 if (priv->current_ht_config.is_ht)
Tomas Winkler47c51962008-05-05 10:22:41 +08002463 iwl_set_rxon_ht(priv, &priv->current_ht_config);
Ron Rindjunsky4f85f5b2008-06-09 22:54:35 +03002464
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002465 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002466 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2467
2468 IWL_DEBUG_ASSOC("assoc id %d beacon interval %d\n",
2469 priv->assoc_id, priv->beacon_int);
2470
2471 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2472 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
2473 else
2474 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
2475
2476 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2477 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
2478 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
2479 else
2480 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2481
2482 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2483 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
2484
2485 }
2486
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002487 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002488
2489 switch (priv->iw_mode) {
2490 case IEEE80211_IF_TYPE_STA:
Zhu Yib481de92007-09-25 17:54:57 -07002491 break;
2492
2493 case IEEE80211_IF_TYPE_IBSS:
2494
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002495 /* assume default assoc id */
2496 priv->assoc_id = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002497
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002498 iwl_rxon_add_station(priv, priv->bssid, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002499 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002500
2501 break;
2502
2503 default:
2504 IWL_ERROR("%s Should not be called in %d mode\n",
2505 __FUNCTION__, priv->iw_mode);
2506 break;
2507 }
2508
Zhu Yib481de92007-09-25 17:54:57 -07002509 /* Enable Rx differential gain and sensitivity calibrations */
Emmanuel Grumbachf0832f12008-04-16 16:34:47 -07002510 iwl_chain_noise_reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002511 priv->start_calib = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002512
2513 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2514 priv->assoc_station_added = 1;
2515
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002516 iwl4965_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08002517
Mohamed Abbas5da4b552008-04-21 15:41:51 -07002518 iwl_power_update_mode(priv, 0);
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08002519 /* we have just associated, don't start scan too early */
2520 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Reinette Chatre508e32e2008-04-14 21:16:13 -07002521}
2522
2523
2524static void iwl4965_bg_post_associate(struct work_struct *data)
2525{
2526 struct iwl_priv *priv = container_of(data, struct iwl_priv,
2527 post_associate.work);
2528
2529 mutex_lock(&priv->mutex);
2530 iwl4965_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002531 mutex_unlock(&priv->mutex);
Reinette Chatre508e32e2008-04-14 21:16:13 -07002532
Zhu Yib481de92007-09-25 17:54:57 -07002533}
2534
Zhu Yi76bb77e2007-11-22 10:53:22 +08002535static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf);
2536
Tomas Winkler2a421b92008-06-12 09:47:10 +08002537static void iwl_bg_scan_completed(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07002538{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002539 struct iwl_priv *priv =
2540 container_of(work, struct iwl_priv, scan_completed);
Zhu Yib481de92007-09-25 17:54:57 -07002541
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002542 IWL_DEBUG_SCAN("SCAN complete scan\n");
Zhu Yib481de92007-09-25 17:54:57 -07002543
2544 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
2545 return;
2546
Zhu Yia0646472007-12-20 14:10:01 +08002547 if (test_bit(STATUS_CONF_PENDING, &priv->status))
2548 iwl4965_mac_config(priv->hw, ieee80211_get_hw_conf(priv->hw));
Zhu Yi76bb77e2007-11-22 10:53:22 +08002549
Zhu Yib481de92007-09-25 17:54:57 -07002550 ieee80211_scan_completed(priv->hw);
2551
2552 /* Since setting the TXPOWER may have been deferred while
2553 * performing the scan, fire one off */
2554 mutex_lock(&priv->mutex);
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002555 iwl_set_tx_power(priv, priv->tx_power_user_lmt, true);
Zhu Yib481de92007-09-25 17:54:57 -07002556 mutex_unlock(&priv->mutex);
2557}
2558
2559/*****************************************************************************
2560 *
2561 * mac80211 entry point functions
2562 *
2563 *****************************************************************************/
2564
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002565#define UCODE_READY_TIMEOUT (4 * HZ)
Zhu Yi5a669262008-01-14 17:46:18 -08002566
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002567static int iwl4965_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002568{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002569 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08002570 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07002571
2572 IWL_DEBUG_MAC80211("enter\n");
2573
Zhu Yi5a669262008-01-14 17:46:18 -08002574 if (pci_enable_device(priv->pci_dev)) {
2575 IWL_ERROR("Fail to pci_enable_device\n");
2576 return -ENODEV;
2577 }
2578 pci_restore_state(priv->pci_dev);
2579 pci_enable_msi(priv->pci_dev);
2580
2581 ret = request_irq(priv->pci_dev->irq, iwl4965_isr, IRQF_SHARED,
2582 DRV_NAME, priv);
2583 if (ret) {
2584 IWL_ERROR("Error allocating IRQ %d\n", priv->pci_dev->irq);
2585 goto out_disable_msi;
2586 }
2587
Zhu Yib481de92007-09-25 17:54:57 -07002588 /* we should be verifying the device is ready to be opened */
2589 mutex_lock(&priv->mutex);
2590
Gregory Greenmanc1adf9f2008-05-15 13:53:59 +08002591 memset(&priv->staging_rxon, 0, sizeof(struct iwl_rxon_cmd));
Zhu Yi5a669262008-01-14 17:46:18 -08002592 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
2593 * ucode filename and max sizes are card-specific. */
2594
2595 if (!priv->ucode_code.len) {
2596 ret = iwl4965_read_ucode(priv);
2597 if (ret) {
2598 IWL_ERROR("Could not read microcode: %d\n", ret);
2599 mutex_unlock(&priv->mutex);
2600 goto out_release_irq;
2601 }
2602 }
2603
Zhu Yie655b9f2008-01-24 02:19:38 -08002604 ret = __iwl4965_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08002605
Zhu Yib481de92007-09-25 17:54:57 -07002606 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08002607
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02002608 iwl_rfkill_set_hw_state(priv);
2609
Zhu Yie655b9f2008-01-24 02:19:38 -08002610 if (ret)
2611 goto out_release_irq;
2612
2613 IWL_DEBUG_INFO("Start UP work done.\n");
2614
2615 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
2616 return 0;
2617
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002618 /* Wait for START_ALIVE from Run Time ucode. Otherwise callbacks from
Zhu Yi5a669262008-01-14 17:46:18 -08002619 * mac80211 will not be run successfully. */
Emmanuel Grumbach154b25c2008-06-30 17:23:24 +08002620 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
2621 test_bit(STATUS_READY, &priv->status),
2622 UCODE_READY_TIMEOUT);
2623 if (!ret) {
2624 if (!test_bit(STATUS_READY, &priv->status)) {
2625 IWL_ERROR("START_ALIVE timeout after %dms.\n",
2626 jiffies_to_msecs(UCODE_READY_TIMEOUT));
2627 ret = -ETIMEDOUT;
2628 goto out_release_irq;
Zhu Yi5a669262008-01-14 17:46:18 -08002629 }
Ron Rindjunskyfe9b6b72008-05-29 16:35:06 +08002630 }
Tomas Winkler0a078ff2008-06-30 17:23:26 +08002631
2632 priv->is_open = 1;
Zhu Yib481de92007-09-25 17:54:57 -07002633 IWL_DEBUG_MAC80211("leave\n");
2634 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08002635
2636out_release_irq:
2637 free_irq(priv->pci_dev->irq, priv);
2638out_disable_msi:
2639 pci_disable_msi(priv->pci_dev);
Zhu Yie655b9f2008-01-24 02:19:38 -08002640 pci_disable_device(priv->pci_dev);
2641 priv->is_open = 0;
2642 IWL_DEBUG_MAC80211("leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08002643 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002644}
2645
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002646static void iwl4965_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07002647{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002648 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002649
2650 IWL_DEBUG_MAC80211("enter\n");
Mohamed Abbas948c1712007-10-25 17:15:45 +08002651
Zhu Yie655b9f2008-01-24 02:19:38 -08002652 if (!priv->is_open) {
2653 IWL_DEBUG_MAC80211("leave - skip\n");
2654 return;
2655 }
2656
Zhu Yib481de92007-09-25 17:54:57 -07002657 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08002658
Tomas Winklerfee12472008-04-03 16:05:21 -07002659 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08002660 /* stop mac, cancel any scan request and clear
2661 * RXON_FILTER_ASSOC_MSK BIT
2662 */
Zhu Yi5a669262008-01-14 17:46:18 -08002663 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08002664 iwl_scan_cancel_timeout(priv, 100);
Zhu Yi5a669262008-01-14 17:46:18 -08002665 cancel_delayed_work(&priv->post_associate);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002666 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08002667 }
2668
Zhu Yi5a669262008-01-14 17:46:18 -08002669 iwl4965_down(priv);
2670
2671 flush_workqueue(priv->workqueue);
2672 free_irq(priv->pci_dev->irq, priv);
2673 pci_disable_msi(priv->pci_dev);
2674 pci_save_state(priv->pci_dev);
2675 pci_disable_device(priv->pci_dev);
Mohamed Abbas948c1712007-10-25 17:15:45 +08002676
Zhu Yib481de92007-09-25 17:54:57 -07002677 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002678}
2679
Johannes Berge039fa42008-05-15 12:55:29 +02002680static int iwl4965_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07002681{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002682 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002683
2684 IWL_DEBUG_MAC80211("enter\n");
2685
2686 if (priv->iw_mode == IEEE80211_IF_TYPE_MNTR) {
2687 IWL_DEBUG_MAC80211("leave - monitor\n");
Zhu Yi6afe6822008-07-01 09:20:34 +08002688 dev_kfree_skb_any(skb);
2689 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002690 }
2691
2692 IWL_DEBUG_TX("dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02002693 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07002694
Johannes Berge039fa42008-05-15 12:55:29 +02002695 if (iwl_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07002696 dev_kfree_skb_any(skb);
2697
2698 IWL_DEBUG_MAC80211("leave\n");
2699 return 0;
2700}
2701
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002702static int iwl4965_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07002703 struct ieee80211_if_init_conf *conf)
2704{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002705 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07002706 unsigned long flags;
Joe Perches0795af52007-10-03 17:59:30 -07002707 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002708
Johannes Berg32bfd352007-12-19 01:31:26 +01002709 IWL_DEBUG_MAC80211("enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07002710
Johannes Berg32bfd352007-12-19 01:31:26 +01002711 if (priv->vif) {
2712 IWL_DEBUG_MAC80211("leave - vif != NULL\n");
Reinette Chatre75849d22008-01-23 10:15:17 -08002713 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07002714 }
2715
2716 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01002717 priv->vif = conf->vif;
Zhu Yib481de92007-09-25 17:54:57 -07002718
2719 spin_unlock_irqrestore(&priv->lock, flags);
2720
2721 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02002722
2723 if (conf->mac_addr) {
2724 IWL_DEBUG_MAC80211("Set %s\n", print_mac(mac, conf->mac_addr));
2725 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
2726 }
Zhu Yib481de92007-09-25 17:54:57 -07002727
Assaf Kraussc46fbef2008-06-12 09:47:05 +08002728 if (iwl4965_set_mode(priv, conf->type) == -EAGAIN)
2729 /* we are not ready, will run again when ready */
2730 set_bit(STATUS_MODE_PENDING, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002731
Zhu Yib481de92007-09-25 17:54:57 -07002732 mutex_unlock(&priv->mutex);
2733
Zhu Yi5a669262008-01-14 17:46:18 -08002734 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07002735 return 0;
2736}
2737
2738/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002739 * iwl4965_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07002740 *
2741 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
2742 * be set inappropriately and the driver currently sets the hardware up to
2743 * use it whenever needed.
2744 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002745static int iwl4965_mac_config(struct ieee80211_hw *hw, struct ieee80211_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07002746{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002747 struct iwl_priv *priv = hw->priv;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07002748 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002749 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08002750 int ret = 0;
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002751 u16 channel;
Zhu Yib481de92007-09-25 17:54:57 -07002752
2753 mutex_lock(&priv->mutex);
Johannes Berg8318d782008-01-24 19:38:38 +01002754 IWL_DEBUG_MAC80211("enter to channel %d\n", conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07002755
Zhu Yi12342c42007-12-20 11:27:32 +08002756 priv->add_radiotap = !!(conf->flags & IEEE80211_CONF_RADIOTAP);
2757
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002758 if (conf->radio_enabled && iwl_radio_kill_sw_enable_radio(priv)) {
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002759 IWL_DEBUG_MAC80211("leave - RF-KILL - waiting for uCode\n");
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002760 goto out;
Mohamed Abbas64e72c32008-06-12 09:47:03 +08002761 }
2762
Emmanuel Grumbach14a08a72008-06-13 15:44:55 +08002763 if (!conf->radio_enabled)
2764 iwl_radio_kill_sw_disable_radio(priv);
2765
Tomas Winklerfee12472008-04-03 16:05:21 -07002766 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002767 IWL_DEBUG_MAC80211("leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002768 ret = -EIO;
2769 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002770 }
2771
Assaf Krauss1ea87392008-03-18 14:57:50 -07002772 if (unlikely(!priv->cfg->mod_params->disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07002773 test_bit(STATUS_SCANNING, &priv->status))) {
Zhu Yia0646472007-12-20 14:10:01 +08002774 IWL_DEBUG_MAC80211("leave - scanning\n");
2775 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07002776 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08002777 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07002778 }
2779
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002780 channel = ieee80211_frequency_to_channel(conf->channel->center_freq);
2781 ch_info = iwl_get_channel_info(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002782 if (!is_channel_valid(ch_info)) {
Zhu Yib481de92007-09-25 17:54:57 -07002783 IWL_DEBUG_MAC80211("leave - invalid channel\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002784 ret = -EINVAL;
2785 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002786 }
2787
Assaf Krauss398f9e72008-06-12 09:47:06 +08002788 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
2789 !is_channel_ibss(ch_info)) {
2790 IWL_ERROR("channel %d in band %d not IBSS channel\n",
2791 conf->channel->hw_value, conf->channel->band);
2792 ret = -EINVAL;
2793 goto out;
2794 }
2795
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002796 spin_lock_irqsave(&priv->lock, flags);
2797
Tomas Winkler78330fd2008-02-06 02:37:18 +02002798 /* if we are switching from ht to 2.4 clear flags
Zhu Yib481de92007-09-25 17:54:57 -07002799 * from any ht related info since 2.4 does not
2800 * support ht */
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002801 if ((le16_to_cpu(priv->staging_rxon.channel) != channel)
Zhu Yib481de92007-09-25 17:54:57 -07002802#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2803 && !(conf->flags & IEEE80211_CONF_CHANNEL_SWITCH)
2804#endif
2805 )
2806 priv->staging_rxon.flags = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002807
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002808 iwl_set_rxon_channel(priv, conf->channel->band, channel);
Zhu Yib481de92007-09-25 17:54:57 -07002809
Tomas Winkler82a66bb2008-05-29 16:35:28 +08002810 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07002811
2812 /* The list of supported rates and rate mask can be different
Johannes Berg8318d782008-01-24 19:38:38 +01002813 * for each band; since the band may have changed, reset
Zhu Yib481de92007-09-25 17:54:57 -07002814 * the rate mask to what mac80211 lists */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002815 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002816
2817 spin_unlock_irqrestore(&priv->lock, flags);
2818
2819#ifdef IEEE80211_CONF_CHANNEL_SWITCH
2820 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002821 iwl4965_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002822 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002823 }
2824#endif
2825
Zhu Yib481de92007-09-25 17:54:57 -07002826 if (!conf->radio_enabled) {
2827 IWL_DEBUG_MAC80211("leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002828 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002829 }
2830
Tomas Winklerfee12472008-04-03 16:05:21 -07002831 if (iwl_is_rfkill(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002832 IWL_DEBUG_MAC80211("leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08002833 ret = -EIO;
2834 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07002835 }
2836
Tomas Winkler630fe9b2008-06-12 09:47:08 +08002837 IWL_DEBUG_MAC80211("TX Power old=%d new=%d\n",
2838 priv->tx_power_user_lmt, conf->power_level);
2839
2840 iwl_set_tx_power(priv, conf->power_level, false);
2841
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002842 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002843
2844 if (memcmp(&priv->active_rxon,
2845 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002846 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002847 else
2848 IWL_DEBUG_INFO("No re-sending same RXON configuration.\n");
2849
2850 IWL_DEBUG_MAC80211("leave\n");
2851
Zhu Yia0646472007-12-20 14:10:01 +08002852out:
2853 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002854 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08002855 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002856}
2857
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002858static void iwl4965_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002859{
Tomas Winkler857485c2008-03-21 13:53:44 -07002860 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07002861
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08002862 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07002863 return;
2864
2865 /* The following should be done only at AP bring up */
Ron Rindjunsky5d1e2322008-06-30 17:23:04 +08002866 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07002867
2868 /* RXON - unassoc (to set timing command) */
2869 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002870 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002871
2872 /* RXON Timing */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002873 memset(&priv->rxon_timing, 0, sizeof(struct iwl4965_rxon_time_cmd));
2874 iwl4965_setup_rxon_timing(priv);
Tomas Winkler857485c2008-03-21 13:53:44 -07002875 ret = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07002876 sizeof(priv->rxon_timing), &priv->rxon_timing);
Tomas Winkler857485c2008-03-21 13:53:44 -07002877 if (ret)
Zhu Yib481de92007-09-25 17:54:57 -07002878 IWL_WARNING("REPLY_RXON_TIMING failed - "
2879 "Attempting to continue.\n");
2880
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07002881 iwl_set_rxon_chain(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002882
2883 /* FIXME: what should be the assoc_id for AP? */
2884 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
2885 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
2886 priv->staging_rxon.flags |=
2887 RXON_FLG_SHORT_PREAMBLE_MSK;
2888 else
2889 priv->staging_rxon.flags &=
2890 ~RXON_FLG_SHORT_PREAMBLE_MSK;
2891
2892 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
2893 if (priv->assoc_capability &
2894 WLAN_CAPABILITY_SHORT_SLOT_TIME)
2895 priv->staging_rxon.flags |=
2896 RXON_FLG_SHORT_SLOT_MSK;
2897 else
2898 priv->staging_rxon.flags &=
2899 ~RXON_FLG_SHORT_SLOT_MSK;
2900
2901 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS)
2902 priv->staging_rxon.flags &=
2903 ~RXON_FLG_SHORT_SLOT_MSK;
2904 }
2905 /* restore RXON assoc */
2906 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002907 iwl4965_commit_rxon(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002908 iwl4965_activate_qos(priv, 1);
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08002909 iwl_rxon_add_station(priv, iwl_bcast_addr, 0);
Zhu Yie1493de2007-09-27 11:27:32 +08002910 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002911 iwl4965_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002912
2913 /* FIXME - we need to add code here to detect a totally new
2914 * configuration, reset the AP, unassoc, rxon timing, assoc,
2915 * clear sta table, add BCAST sta... */
2916}
2917
Johannes Berg9d139c82008-07-09 14:40:37 +02002918/* temporary */
2919static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb);
2920
Johannes Berg32bfd352007-12-19 01:31:26 +01002921static int iwl4965_mac_config_interface(struct ieee80211_hw *hw,
2922 struct ieee80211_vif *vif,
Zhu Yib481de92007-09-25 17:54:57 -07002923 struct ieee80211_if_conf *conf)
2924{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07002925 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07002926 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07002927 unsigned long flags;
2928 int rc;
2929
2930 if (conf == NULL)
2931 return -EIO;
2932
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002933 if (priv->vif != vif) {
2934 IWL_DEBUG_MAC80211("leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08002935 return 0;
2936 }
2937
Johannes Berg9d139c82008-07-09 14:40:37 +02002938 if (priv->iw_mode == IEEE80211_IF_TYPE_IBSS &&
2939 conf->changed & IEEE80211_IFCC_BEACON) {
2940 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
2941 if (!beacon)
2942 return -ENOMEM;
2943 rc = iwl4965_mac_beacon_update(hw, beacon);
2944 if (rc)
2945 return rc;
2946 }
2947
Zhu Yib481de92007-09-25 17:54:57 -07002948 if ((priv->iw_mode == IEEE80211_IF_TYPE_AP) &&
Johannes Berg9d139c82008-07-09 14:40:37 +02002949 (!conf->ssid_len)) {
Zhu Yib481de92007-09-25 17:54:57 -07002950 IWL_DEBUG_MAC80211
2951 ("Leaving in AP mode because HostAPD is not ready.\n");
2952 return 0;
2953 }
2954
Tomas Winklerfee12472008-04-03 16:05:21 -07002955 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08002956 return -EAGAIN;
2957
Zhu Yib481de92007-09-25 17:54:57 -07002958 mutex_lock(&priv->mutex);
2959
Zhu Yib481de92007-09-25 17:54:57 -07002960 if (conf->bssid)
Joe Perches0795af52007-10-03 17:59:30 -07002961 IWL_DEBUG_MAC80211("bssid: %s\n",
2962 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07002963
Johannes Berg4150c572007-09-17 01:29:23 -04002964/*
2965 * very dubious code was here; the probe filtering flag is never set:
2966 *
Zhu Yib481de92007-09-25 17:54:57 -07002967 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
2968 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04002969 */
Zhu Yib481de92007-09-25 17:54:57 -07002970
2971 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) {
2972 if (!conf->bssid) {
2973 conf->bssid = priv->mac_addr;
2974 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Joe Perches0795af52007-10-03 17:59:30 -07002975 IWL_DEBUG_MAC80211("bssid was set to: %s\n",
2976 print_mac(mac, conf->bssid));
Zhu Yib481de92007-09-25 17:54:57 -07002977 }
2978 if (priv->ibss_beacon)
2979 dev_kfree_skb(priv->ibss_beacon);
2980
Johannes Berg9d139c82008-07-09 14:40:37 +02002981 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07002982 }
2983
Tomas Winklerfee12472008-04-03 16:05:21 -07002984 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08002985 goto done;
2986
Zhu Yib481de92007-09-25 17:54:57 -07002987 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
2988 !is_multicast_ether_addr(conf->bssid)) {
2989 /* If there is currently a HW scan going on in the background
2990 * then we need to cancel it else the RXON below will fail. */
Tomas Winkler2a421b92008-06-12 09:47:10 +08002991 if (iwl_scan_cancel_timeout(priv, 100)) {
Zhu Yib481de92007-09-25 17:54:57 -07002992 IWL_WARNING("Aborted scan still in progress "
2993 "after 100ms\n");
2994 IWL_DEBUG_MAC80211("leaving - scan abort failed.\n");
2995 mutex_unlock(&priv->mutex);
2996 return -EAGAIN;
2997 }
2998 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
2999
3000 /* TODO: Audit driver for usage of these members and see
3001 * if mac80211 deprecates them (priv->bssid looks like it
3002 * shouldn't be there, but I haven't scanned the IBSS code
3003 * to verify) - jpk */
3004 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
3005
3006 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003007 iwl4965_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003008 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003009 rc = iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003010 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA) && rc)
Tomas Winkler4f40e4d2008-05-15 13:54:04 +08003011 iwl_rxon_add_station(
Zhu Yib481de92007-09-25 17:54:57 -07003012 priv, priv->active_rxon.bssid_addr, 1);
3013 }
3014
3015 } else {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003016 iwl_scan_cancel_timeout(priv, 100);
Zhu Yib481de92007-09-25 17:54:57 -07003017 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003018 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003019 }
3020
Mohamed Abbasfde35712007-11-29 11:10:15 +08003021 done:
Zhu Yib481de92007-09-25 17:54:57 -07003022 spin_lock_irqsave(&priv->lock, flags);
3023 if (!conf->ssid_len)
3024 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3025 else
3026 memcpy(priv->essid, conf->ssid, conf->ssid_len);
3027
3028 priv->essid_len = conf->ssid_len;
3029 spin_unlock_irqrestore(&priv->lock, flags);
3030
3031 IWL_DEBUG_MAC80211("leave\n");
3032 mutex_unlock(&priv->mutex);
3033
3034 return 0;
3035}
3036
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003037static void iwl4965_configure_filter(struct ieee80211_hw *hw,
Johannes Berg4150c572007-09-17 01:29:23 -04003038 unsigned int changed_flags,
3039 unsigned int *total_flags,
3040 int mc_count, struct dev_addr_list *mc_list)
3041{
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08003042 struct iwl_priv *priv = hw->priv;
Rick Farrington25b3f572008-06-30 17:23:28 +08003043
3044 if (changed_flags & (*total_flags) & FIF_OTHER_BSS) {
3045 IWL_DEBUG_MAC80211("Enter: type %d (0x%x, 0x%x)\n",
3046 IEEE80211_IF_TYPE_MNTR,
3047 changed_flags, *total_flags);
3048 /* queue work 'cuz mac80211 is holding a lock which
3049 * prevents us from issuing (synchronous) f/w cmds */
3050 queue_work(priv->workqueue, &priv->set_monitor);
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08003051 }
Rick Farrington25b3f572008-06-30 17:23:28 +08003052 *total_flags &= FIF_OTHER_BSS | FIF_ALLMULTI |
3053 FIF_BCN_PRBRESP_PROMISC | FIF_CONTROL;
Johannes Berg4150c572007-09-17 01:29:23 -04003054}
3055
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003056static void iwl4965_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003057 struct ieee80211_if_init_conf *conf)
3058{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003059 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003060
3061 IWL_DEBUG_MAC80211("enter\n");
3062
3063 mutex_lock(&priv->mutex);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003064
Tomas Winklerfee12472008-04-03 16:05:21 -07003065 if (iwl_is_ready_rf(priv)) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003066 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003067 cancel_delayed_work(&priv->post_associate);
3068 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3069 iwl4965_commit_rxon(priv);
3070 }
Johannes Berg32bfd352007-12-19 01:31:26 +01003071 if (priv->vif == conf->vif) {
3072 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003073 memset(priv->bssid, 0, ETH_ALEN);
3074 memset(priv->essid, 0, IW_ESSID_MAX_SIZE);
3075 priv->essid_len = 0;
3076 }
3077 mutex_unlock(&priv->mutex);
3078
3079 IWL_DEBUG_MAC80211("leave\n");
3080
3081}
Johannes Berg471b3ef2007-12-28 14:32:58 +01003082
Tomas Winkler3109ece2008-03-28 16:33:35 -07003083#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
Johannes Berg471b3ef2007-12-28 14:32:58 +01003084static void iwl4965_bss_info_changed(struct ieee80211_hw *hw,
3085 struct ieee80211_vif *vif,
3086 struct ieee80211_bss_conf *bss_conf,
3087 u32 changes)
Tomas Winkler220173b2007-10-16 00:50:25 +02003088{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003089 struct iwl_priv *priv = hw->priv;
Tomas Winkler220173b2007-10-16 00:50:25 +02003090
Tomas Winkler3109ece2008-03-28 16:33:35 -07003091 IWL_DEBUG_MAC80211("changes = 0x%X\n", changes);
3092
Johannes Berg471b3ef2007-12-28 14:32:58 +01003093 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003094 IWL_DEBUG_MAC80211("ERP_PREAMBLE %d\n",
3095 bss_conf->use_short_preamble);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003096 if (bss_conf->use_short_preamble)
Tomas Winkler220173b2007-10-16 00:50:25 +02003097 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
3098 else
3099 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
3100 }
3101
Johannes Berg471b3ef2007-12-28 14:32:58 +01003102 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003103 IWL_DEBUG_MAC80211("ERP_CTS %d\n", bss_conf->use_cts_prot);
Johannes Berg8318d782008-01-24 19:38:38 +01003104 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Tomas Winkler220173b2007-10-16 00:50:25 +02003105 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
3106 else
3107 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
3108 }
3109
Tomas Winkler98952d52008-03-28 16:33:33 -07003110 if (changes & BSS_CHANGED_HT) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003111 IWL_DEBUG_MAC80211("HT %d\n", bss_conf->assoc_ht);
Tomas Winkler98952d52008-03-28 16:33:33 -07003112 iwl4965_ht_conf(priv, bss_conf);
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003113 iwl_set_rxon_chain(priv);
Tomas Winkler98952d52008-03-28 16:33:33 -07003114 }
3115
Johannes Berg471b3ef2007-12-28 14:32:58 +01003116 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winkler3109ece2008-03-28 16:33:35 -07003117 IWL_DEBUG_MAC80211("ASSOC %d\n", bss_conf->assoc);
Reinette Chatre508e32e2008-04-14 21:16:13 -07003118 /* This should never happen as this function should
3119 * never be called from interrupt context. */
3120 if (WARN_ON_ONCE(in_interrupt()))
3121 return;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003122 if (bss_conf->assoc) {
3123 priv->assoc_id = bss_conf->aid;
3124 priv->beacon_int = bss_conf->beacon_int;
3125 priv->timestamp = bss_conf->timestamp;
3126 priv->assoc_capability = bss_conf->assoc_capability;
3127 priv->next_scan_jiffies = jiffies +
3128 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
Reinette Chatre508e32e2008-04-14 21:16:13 -07003129 mutex_lock(&priv->mutex);
3130 iwl4965_post_associate(priv);
3131 mutex_unlock(&priv->mutex);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003132 } else {
3133 priv->assoc_id = 0;
3134 IWL_DEBUG_MAC80211("DISASSOC %d\n", bss_conf->assoc);
3135 }
3136 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
3137 IWL_DEBUG_MAC80211("Associated Changes %d\n", changes);
Tomas Winkler7e8c5192008-04-15 16:01:43 -07003138 iwl_send_rxon_assoc(priv);
Johannes Berg471b3ef2007-12-28 14:32:58 +01003139 }
3140
Tomas Winkler220173b2007-10-16 00:50:25 +02003141}
Zhu Yib481de92007-09-25 17:54:57 -07003142
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003143static int iwl4965_mac_hw_scan(struct ieee80211_hw *hw, u8 *ssid, size_t len)
Zhu Yib481de92007-09-25 17:54:57 -07003144{
3145 int rc = 0;
3146 unsigned long flags;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003147 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003148
3149 IWL_DEBUG_MAC80211("enter\n");
3150
mabbas052c4b92007-10-25 17:15:43 +08003151 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003152 spin_lock_irqsave(&priv->lock, flags);
3153
Tomas Winklerfee12472008-04-03 16:05:21 -07003154 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003155 rc = -EIO;
3156 IWL_DEBUG_MAC80211("leave - not ready or exit pending\n");
3157 goto out_unlock;
3158 }
3159
3160 if (priv->iw_mode == IEEE80211_IF_TYPE_AP) { /* APs don't scan */
3161 rc = -EIO;
3162 IWL_ERROR("ERROR: APs don't scan\n");
3163 goto out_unlock;
3164 }
3165
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003166 /* we don't schedule scan within next_scan_jiffies period */
3167 if (priv->next_scan_jiffies &&
3168 time_after(priv->next_scan_jiffies, jiffies)) {
3169 rc = -EAGAIN;
3170 goto out_unlock;
3171 }
Zhu Yib481de92007-09-25 17:54:57 -07003172 /* if we just finished scan ask for delay */
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003173 if (priv->last_scan_jiffies && time_after(priv->last_scan_jiffies +
3174 IWL_DELAY_NEXT_SCAN, jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07003175 rc = -EAGAIN;
3176 goto out_unlock;
3177 }
3178 if (len) {
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003179 IWL_DEBUG_SCAN("direct scan for %s [%d]\n ",
Tomas Winkler2a421b92008-06-12 09:47:10 +08003180 iwl_escape_essid(ssid, len), (int)len);
Zhu Yib481de92007-09-25 17:54:57 -07003181
3182 priv->one_direct_scan = 1;
3183 priv->direct_ssid_len = (u8)
3184 min((u8) len, (u8) IW_ESSID_MAX_SIZE);
3185 memcpy(priv->direct_ssid, ssid, priv->direct_ssid_len);
Mohamed Abbas948c1712007-10-25 17:15:45 +08003186 } else
3187 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003188
Tomas Winkler2a421b92008-06-12 09:47:10 +08003189 rc = iwl_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003190
3191 IWL_DEBUG_MAC80211("leave\n");
3192
3193out_unlock:
3194 spin_unlock_irqrestore(&priv->lock, flags);
mabbas052c4b92007-10-25 17:15:43 +08003195 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07003196
3197 return rc;
3198}
3199
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003200static void iwl4965_mac_update_tkip_key(struct ieee80211_hw *hw,
3201 struct ieee80211_key_conf *keyconf, const u8 *addr,
3202 u32 iv32, u16 *phase1key)
3203{
3204 struct iwl_priv *priv = hw->priv;
3205 u8 sta_id = IWL_INVALID_STATION;
3206 unsigned long flags;
3207 __le16 key_flags = 0;
3208 int i;
3209 DECLARE_MAC_BUF(mac);
3210
3211 IWL_DEBUG_MAC80211("enter\n");
3212
Tomas Winkler947b13a2008-04-16 16:34:48 -07003213 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003214 if (sta_id == IWL_INVALID_STATION) {
3215 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3216 print_mac(mac, addr));
3217 return;
3218 }
3219
Tomas Winkler2a421b92008-06-12 09:47:10 +08003220 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003221
3222 key_flags |= (STA_KEY_FLG_TKIP | STA_KEY_FLG_MAP_KEY_MSK);
3223 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
3224 key_flags &= ~STA_KEY_FLG_INVALID;
3225
Tomas Winkler5425e492008-04-15 16:01:38 -07003226 if (sta_id == priv->hw_params.bcast_sta_id)
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003227 key_flags |= STA_KEY_MULTICAST_MSK;
3228
3229 spin_lock_irqsave(&priv->sta_lock, flags);
3230
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003231 priv->stations[sta_id].sta.key.key_flags = key_flags;
3232 priv->stations[sta_id].sta.key.tkip_rx_tsc_byte2 = (u8) iv32;
3233
3234 for (i = 0; i < 5; i++)
3235 priv->stations[sta_id].sta.key.tkip_rx_ttak[i] =
3236 cpu_to_le16(phase1key[i]);
3237
3238 priv->stations[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
3239 priv->stations[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
3240
Tomas Winkler133636d2008-05-05 10:22:34 +08003241 iwl_send_add_sta(priv, &priv->stations[sta_id].sta, CMD_ASYNC);
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02003242
3243 spin_unlock_irqrestore(&priv->sta_lock, flags);
3244
3245 IWL_DEBUG_MAC80211("leave\n");
3246}
3247
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003248static int iwl4965_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Zhu Yib481de92007-09-25 17:54:57 -07003249 const u8 *local_addr, const u8 *addr,
3250 struct ieee80211_key_conf *key)
3251{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003252 struct iwl_priv *priv = hw->priv;
Joe Perches0795af52007-10-03 17:59:30 -07003253 DECLARE_MAC_BUF(mac);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003254 int ret = 0;
3255 u8 sta_id = IWL_INVALID_STATION;
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003256 u8 is_default_wep_key = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003257
3258 IWL_DEBUG_MAC80211("enter\n");
3259
Ron Rindjunsky099b40b2008-04-21 15:41:53 -07003260 if (priv->hw_params.sw_crypto) {
Zhu Yib481de92007-09-25 17:54:57 -07003261 IWL_DEBUG_MAC80211("leave - hwcrypto disabled\n");
3262 return -EOPNOTSUPP;
3263 }
3264
3265 if (is_zero_ether_addr(addr))
3266 /* only support pairwise keys */
3267 return -EOPNOTSUPP;
3268
Tomas Winkler947b13a2008-04-16 16:34:48 -07003269 sta_id = iwl_find_station(priv, addr);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003270 if (sta_id == IWL_INVALID_STATION) {
3271 IWL_DEBUG_MAC80211("leave - %s not in station map.\n",
3272 print_mac(mac, addr));
3273 return -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003274
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003275 }
Zhu Yib481de92007-09-25 17:54:57 -07003276
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003277 mutex_lock(&priv->mutex);
Tomas Winkler2a421b92008-06-12 09:47:10 +08003278 iwl_scan_cancel_timeout(priv, 100);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003279 mutex_unlock(&priv->mutex);
3280
3281 /* If we are getting WEP group key and we didn't receive any key mapping
3282 * so far, we are in legacy wep mode (group key only), otherwise we are
3283 * in 1X mode.
3284 * In legacy wep mode, we use another host command to the uCode */
Tomas Winkler5425e492008-04-15 16:01:38 -07003285 if (key->alg == ALG_WEP && sta_id == priv->hw_params.bcast_sta_id &&
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003286 priv->iw_mode != IEEE80211_IF_TYPE_AP) {
3287 if (cmd == SET_KEY)
3288 is_default_wep_key = !priv->key_mapping_key;
3289 else
Emmanuel Grumbachccc038a2008-05-15 13:54:09 +08003290 is_default_wep_key =
3291 (key->hw_key_idx == HW_KEY_DEFAULT);
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003292 }
mabbas052c4b92007-10-25 17:15:43 +08003293
Zhu Yib481de92007-09-25 17:54:57 -07003294 switch (cmd) {
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003295 case SET_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003296 if (is_default_wep_key)
3297 ret = iwl_set_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003298 else
Emmanuel Grumbach74805132008-04-14 21:16:09 -07003299 ret = iwl_set_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003300
3301 IWL_DEBUG_MAC80211("enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003302 break;
3303 case DISABLE_KEY:
Emmanuel Grumbach6974e362008-04-14 21:16:06 -07003304 if (is_default_wep_key)
3305 ret = iwl_remove_default_wep_key(priv, key);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003306 else
Emmanuel Grumbach3ec47732008-04-17 16:03:36 -07003307 ret = iwl_remove_dynamic_key(priv, key, sta_id);
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003308
3309 IWL_DEBUG_MAC80211("disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003310 break;
3311 default:
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003312 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003313 }
3314
3315 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003316
Emmanuel Grumbachdeb09c42008-03-19 16:41:41 -07003317 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003318}
3319
Johannes Berge100bb62008-04-30 18:51:21 +02003320static int iwl4965_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07003321 const struct ieee80211_tx_queue_params *params)
3322{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003323 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003324 unsigned long flags;
3325 int q;
Zhu Yib481de92007-09-25 17:54:57 -07003326
3327 IWL_DEBUG_MAC80211("enter\n");
3328
Tomas Winklerfee12472008-04-03 16:05:21 -07003329 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003330 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3331 return -EIO;
3332 }
3333
3334 if (queue >= AC_NUM) {
3335 IWL_DEBUG_MAC80211("leave - queue >= AC_NUM %d\n", queue);
3336 return 0;
3337 }
3338
Zhu Yib481de92007-09-25 17:54:57 -07003339 if (!priv->qos_data.qos_enable) {
3340 priv->qos_data.qos_active = 0;
3341 IWL_DEBUG_MAC80211("leave - qos not enabled\n");
3342 return 0;
3343 }
3344 q = AC_NUM - 1 - queue;
3345
3346 spin_lock_irqsave(&priv->lock, flags);
3347
3348 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
3349 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
3350 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
3351 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01003352 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07003353
3354 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
3355 priv->qos_data.qos_active = 1;
3356
3357 spin_unlock_irqrestore(&priv->lock, flags);
3358
3359 mutex_lock(&priv->mutex);
3360 if (priv->iw_mode == IEEE80211_IF_TYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003361 iwl4965_activate_qos(priv, 1);
Tomas Winkler3109ece2008-03-28 16:33:35 -07003362 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003363 iwl4965_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003364
3365 mutex_unlock(&priv->mutex);
3366
Zhu Yib481de92007-09-25 17:54:57 -07003367 IWL_DEBUG_MAC80211("leave\n");
3368 return 0;
3369}
3370
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003371static int iwl4965_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003372 struct ieee80211_tx_queue_stats *stats)
3373{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003374 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003375 int i, avail;
Ron Rindjunsky16466902008-05-05 10:22:50 +08003376 struct iwl_tx_queue *txq;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003377 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07003378 unsigned long flags;
3379
3380 IWL_DEBUG_MAC80211("enter\n");
3381
Tomas Winklerfee12472008-04-03 16:05:21 -07003382 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003383 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3384 return -EIO;
3385 }
3386
3387 spin_lock_irqsave(&priv->lock, flags);
3388
3389 for (i = 0; i < AC_NUM; i++) {
3390 txq = &priv->txq[i];
3391 q = &txq->q;
Tomas Winkler443cfd42008-05-15 13:53:57 +08003392 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07003393
Johannes Berg57ffc582008-04-29 17:18:59 +02003394 stats[i].len = q->n_window - avail;
3395 stats[i].limit = q->n_window - q->high_mark;
3396 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07003397
3398 }
3399 spin_unlock_irqrestore(&priv->lock, flags);
3400
3401 IWL_DEBUG_MAC80211("leave\n");
3402
3403 return 0;
3404}
3405
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003406static int iwl4965_mac_get_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003407 struct ieee80211_low_level_stats *stats)
3408{
Ester Kummerbf403db2008-05-05 10:22:40 +08003409 struct iwl_priv *priv = hw->priv;
3410
3411 priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003412 IWL_DEBUG_MAC80211("enter\n");
3413 IWL_DEBUG_MAC80211("leave\n");
3414
3415 return 0;
3416}
3417
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003418static void iwl4965_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003419{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003420 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003421 unsigned long flags;
3422
3423 mutex_lock(&priv->mutex);
3424 IWL_DEBUG_MAC80211("enter\n");
3425
Zhu Yib481de92007-09-25 17:54:57 -07003426 spin_lock_irqsave(&priv->lock, flags);
Ron Rindjunskyfd105e72007-11-26 16:14:39 +02003427 memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_info));
Zhu Yib481de92007-09-25 17:54:57 -07003428 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yib481de92007-09-25 17:54:57 -07003429
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003430 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003431
3432 cancel_delayed_work(&priv->post_associate);
3433
3434 spin_lock_irqsave(&priv->lock, flags);
3435 priv->assoc_id = 0;
3436 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003437 priv->assoc_station_added = 0;
3438
3439 /* new association get rid of ibss beacon skb */
3440 if (priv->ibss_beacon)
3441 dev_kfree_skb(priv->ibss_beacon);
3442
3443 priv->ibss_beacon = NULL;
3444
3445 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler3109ece2008-03-28 16:33:35 -07003446 priv->timestamp = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003447 if ((priv->iw_mode == IEEE80211_IF_TYPE_STA))
3448 priv->beacon_int = 0;
3449
3450 spin_unlock_irqrestore(&priv->lock, flags);
3451
Tomas Winklerfee12472008-04-03 16:05:21 -07003452 if (!iwl_is_ready_rf(priv)) {
Mohamed Abbasfde35712007-11-29 11:10:15 +08003453 IWL_DEBUG_MAC80211("leave - not ready\n");
3454 mutex_unlock(&priv->mutex);
3455 return;
3456 }
3457
mabbas052c4b92007-10-25 17:15:43 +08003458 /* we are restarting association process
3459 * clear RXON_FILTER_ASSOC_MSK bit
3460 */
3461 if (priv->iw_mode != IEEE80211_IF_TYPE_AP) {
Tomas Winkler2a421b92008-06-12 09:47:10 +08003462 iwl_scan_cancel_timeout(priv, 100);
mabbas052c4b92007-10-25 17:15:43 +08003463 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003464 iwl4965_commit_rxon(priv);
mabbas052c4b92007-10-25 17:15:43 +08003465 }
3466
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003467 iwl_power_update_mode(priv, 0);
3468
Zhu Yib481de92007-09-25 17:54:57 -07003469 /* Per mac80211.h: This is only used in IBSS mode... */
3470 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
mabbas052c4b92007-10-25 17:15:43 +08003471
Zhu Yib481de92007-09-25 17:54:57 -07003472 IWL_DEBUG_MAC80211("leave - not in IBSS\n");
3473 mutex_unlock(&priv->mutex);
3474 return;
3475 }
3476
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003477 iwl4965_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003478
3479 mutex_unlock(&priv->mutex);
3480
3481 IWL_DEBUG_MAC80211("leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003482}
3483
Johannes Berge039fa42008-05-15 12:55:29 +02003484static int iwl4965_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003485{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003486 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003487 unsigned long flags;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003488 __le64 timestamp;
Zhu Yib481de92007-09-25 17:54:57 -07003489
3490 mutex_lock(&priv->mutex);
3491 IWL_DEBUG_MAC80211("enter\n");
3492
Tomas Winklerfee12472008-04-03 16:05:21 -07003493 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003494 IWL_DEBUG_MAC80211("leave - RF not ready\n");
3495 mutex_unlock(&priv->mutex);
3496 return -EIO;
3497 }
3498
3499 if (priv->iw_mode != IEEE80211_IF_TYPE_IBSS) {
3500 IWL_DEBUG_MAC80211("leave - not IBSS\n");
3501 mutex_unlock(&priv->mutex);
3502 return -EIO;
3503 }
3504
3505 spin_lock_irqsave(&priv->lock, flags);
3506
3507 if (priv->ibss_beacon)
3508 dev_kfree_skb(priv->ibss_beacon);
3509
3510 priv->ibss_beacon = skb;
3511
3512 priv->assoc_id = 0;
Assaf Krauss2ff75b72008-06-30 17:23:17 +08003513 timestamp = ((struct ieee80211_mgmt *)skb->data)->u.beacon.timestamp;
3514 priv->timestamp = le64_to_cpu(timestamp) + (priv->beacon_int * 1000);
Zhu Yib481de92007-09-25 17:54:57 -07003515
3516 IWL_DEBUG_MAC80211("leave\n");
3517 spin_unlock_irqrestore(&priv->lock, flags);
3518
Ron Rindjunskyc7de35c2008-04-23 17:15:05 -07003519 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003520
Assaf Kraussc46fbef2008-06-12 09:47:05 +08003521 iwl4965_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003522
3523 mutex_unlock(&priv->mutex);
3524
3525 return 0;
3526}
3527
Zhu Yib481de92007-09-25 17:54:57 -07003528/*****************************************************************************
3529 *
3530 * sysfs attributes
3531 *
3532 *****************************************************************************/
3533
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003534#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07003535
3536/*
3537 * The following adds a new attribute to the sysfs representation
3538 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
3539 * used for controlling the debug level.
3540 *
3541 * See the level definitions in iwl for details.
3542 */
3543
Ester Kummer8cf769c2008-05-06 11:05:11 +08003544static ssize_t show_debug_level(struct device *d,
3545 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07003546{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003547 struct iwl_priv *priv = d->driver_data;
3548
3549 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07003550}
Ester Kummer8cf769c2008-05-06 11:05:11 +08003551static ssize_t store_debug_level(struct device *d,
3552 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07003553 const char *buf, size_t count)
3554{
Ester Kummer8cf769c2008-05-06 11:05:11 +08003555 struct iwl_priv *priv = d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003556 char *p = (char *)buf;
3557 u32 val;
3558
3559 val = simple_strtoul(p, &p, 0);
3560 if (p == buf)
3561 printk(KERN_INFO DRV_NAME
3562 ": %s is not in hex or decimal form.\n", buf);
3563 else
Ester Kummer8cf769c2008-05-06 11:05:11 +08003564 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07003565
3566 return strnlen(buf, count);
3567}
3568
Ester Kummer8cf769c2008-05-06 11:05:11 +08003569static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
3570 show_debug_level, store_debug_level);
3571
Zhu Yib481de92007-09-25 17:54:57 -07003572
Tomas Winkler0a6857e2008-03-12 16:58:49 -07003573#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07003574
Zhu Yib481de92007-09-25 17:54:57 -07003575
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003576static ssize_t show_version(struct device *d,
3577 struct device_attribute *attr, char *buf)
3578{
3579 struct iwl_priv *priv = d->driver_data;
Tomas Winkler885ba202008-05-29 16:34:55 +08003580 struct iwl_alive_resp *palive = &priv->card_alive;
Tomas Winklerf236a262008-06-30 17:23:02 +08003581 ssize_t pos = 0;
3582 u16 eeprom_ver;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003583
3584 if (palive->is_valid)
Tomas Winklerf236a262008-06-30 17:23:02 +08003585 pos += sprintf(buf + pos,
3586 "fw version: 0x%01X.0x%01X.0x%01X.0x%01X\n"
3587 "fw type: 0x%01X 0x%01X\n",
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003588 palive->ucode_major, palive->ucode_minor,
3589 palive->sw_rev[0], palive->sw_rev[1],
3590 palive->ver_type, palive->ver_subtype);
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003591 else
Tomas Winklerf236a262008-06-30 17:23:02 +08003592 pos += sprintf(buf + pos, "fw not loaded\n");
3593
3594 if (priv->eeprom) {
3595 eeprom_ver = iwl_eeprom_query16(priv, EEPROM_VERSION);
3596 pos += sprintf(buf + pos, "EEPROM version: 0x%x\n",
3597 eeprom_ver);
3598 } else {
3599 pos += sprintf(buf + pos, "EEPROM not initialzed\n");
3600 }
3601
3602 return pos;
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08003603}
3604
3605static DEVICE_ATTR(version, S_IWUSR | S_IRUGO, show_version, NULL);
3606
Zhu Yib481de92007-09-25 17:54:57 -07003607static ssize_t show_temperature(struct device *d,
3608 struct device_attribute *attr, char *buf)
3609{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003610 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003611
Tomas Winklerfee12472008-04-03 16:05:21 -07003612 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003613 return -EAGAIN;
3614
Emmanuel Grumbach91dbc5b2008-06-12 09:47:14 +08003615 return sprintf(buf, "%d\n", priv->temperature);
Zhu Yib481de92007-09-25 17:54:57 -07003616}
3617
3618static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
3619
3620static ssize_t show_rs_window(struct device *d,
3621 struct device_attribute *attr,
3622 char *buf)
3623{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003624 struct iwl_priv *priv = d->driver_data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003625 return iwl4965_fill_rs_info(priv->hw, buf, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003626}
3627static DEVICE_ATTR(rs_window, S_IRUGO, show_rs_window, NULL);
3628
3629static ssize_t show_tx_power(struct device *d,
3630 struct device_attribute *attr, char *buf)
3631{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003632 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003633 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07003634}
3635
3636static ssize_t store_tx_power(struct device *d,
3637 struct device_attribute *attr,
3638 const char *buf, size_t count)
3639{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003640 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003641 char *p = (char *)buf;
3642 u32 val;
3643
3644 val = simple_strtoul(p, &p, 10);
3645 if (p == buf)
3646 printk(KERN_INFO DRV_NAME
3647 ": %s is not in decimal form.\n", buf);
3648 else
Tomas Winkler630fe9b2008-06-12 09:47:08 +08003649 iwl_set_tx_power(priv, val, false);
Zhu Yib481de92007-09-25 17:54:57 -07003650
3651 return count;
3652}
3653
3654static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
3655
3656static ssize_t show_flags(struct device *d,
3657 struct device_attribute *attr, char *buf)
3658{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003659 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003660
3661 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
3662}
3663
3664static ssize_t store_flags(struct device *d,
3665 struct device_attribute *attr,
3666 const char *buf, size_t count)
3667{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003668 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003669 u32 flags = simple_strtoul(buf, NULL, 0);
3670
3671 mutex_lock(&priv->mutex);
3672 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
3673 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003674 if (iwl_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07003675 IWL_WARNING("Could not cancel scan.\n");
3676 else {
3677 IWL_DEBUG_INFO("Committing rxon.flags = 0x%04X\n",
3678 flags);
3679 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003680 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003681 }
3682 }
3683 mutex_unlock(&priv->mutex);
3684
3685 return count;
3686}
3687
3688static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
3689
3690static ssize_t show_filter_flags(struct device *d,
3691 struct device_attribute *attr, char *buf)
3692{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003693 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003694
3695 return sprintf(buf, "0x%04X\n",
3696 le32_to_cpu(priv->active_rxon.filter_flags));
3697}
3698
3699static ssize_t store_filter_flags(struct device *d,
3700 struct device_attribute *attr,
3701 const char *buf, size_t count)
3702{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003703 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07003704 u32 filter_flags = simple_strtoul(buf, NULL, 0);
3705
3706 mutex_lock(&priv->mutex);
3707 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
3708 /* Cancel any currently running scans... */
Tomas Winkler2a421b92008-06-12 09:47:10 +08003709 if (iwl_scan_cancel_timeout(priv, 100))
Zhu Yib481de92007-09-25 17:54:57 -07003710 IWL_WARNING("Could not cancel scan.\n");
3711 else {
3712 IWL_DEBUG_INFO("Committing rxon.filter_flags = "
3713 "0x%04X\n", filter_flags);
3714 priv->staging_rxon.filter_flags =
3715 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003716 iwl4965_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003717 }
3718 }
3719 mutex_unlock(&priv->mutex);
3720
3721 return count;
3722}
3723
3724static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
3725 store_filter_flags);
3726
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003727#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07003728
3729static ssize_t show_measurement(struct device *d,
3730 struct device_attribute *attr, char *buf)
3731{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003732 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003733 struct iwl4965_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07003734 u32 size = sizeof(measure_report), len = 0, ofs = 0;
3735 u8 *data = (u8 *) & measure_report;
3736 unsigned long flags;
3737
3738 spin_lock_irqsave(&priv->lock, flags);
3739 if (!(priv->measurement_status & MEASUREMENT_READY)) {
3740 spin_unlock_irqrestore(&priv->lock, flags);
3741 return 0;
3742 }
3743 memcpy(&measure_report, &priv->measure_report, size);
3744 priv->measurement_status = 0;
3745 spin_unlock_irqrestore(&priv->lock, flags);
3746
3747 while (size && (PAGE_SIZE - len)) {
3748 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3749 PAGE_SIZE - len, 1);
3750 len = strlen(buf);
3751 if (PAGE_SIZE - len)
3752 buf[len++] = '\n';
3753
3754 ofs += 16;
3755 size -= min(size, 16U);
3756 }
3757
3758 return len;
3759}
3760
3761static ssize_t store_measurement(struct device *d,
3762 struct device_attribute *attr,
3763 const char *buf, size_t count)
3764{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003765 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003766 struct ieee80211_measurement_params params = {
3767 .channel = le16_to_cpu(priv->active_rxon.channel),
3768 .start_time = cpu_to_le64(priv->last_tsf),
3769 .duration = cpu_to_le16(1),
3770 };
3771 u8 type = IWL_MEASURE_BASIC;
3772 u8 buffer[32];
3773 u8 channel;
3774
3775 if (count) {
3776 char *p = buffer;
3777 strncpy(buffer, buf, min(sizeof(buffer), count));
3778 channel = simple_strtoul(p, NULL, 0);
3779 if (channel)
3780 params.channel = channel;
3781
3782 p = buffer;
3783 while (*p && *p != ' ')
3784 p++;
3785 if (*p)
3786 type = simple_strtoul(p + 1, NULL, 0);
3787 }
3788
3789 IWL_DEBUG_INFO("Invoking measurement of type %d on "
3790 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003791 iwl4965_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07003792
3793 return count;
3794}
3795
3796static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
3797 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08003798#endif /* CONFIG_IWL4965_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07003799
3800static ssize_t store_retry_rate(struct device *d,
3801 struct device_attribute *attr,
3802 const char *buf, size_t count)
3803{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003804 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003805
3806 priv->retry_rate = simple_strtoul(buf, NULL, 0);
3807 if (priv->retry_rate <= 0)
3808 priv->retry_rate = 1;
3809
3810 return count;
3811}
3812
3813static ssize_t show_retry_rate(struct device *d,
3814 struct device_attribute *attr, char *buf)
3815{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003816 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003817 return sprintf(buf, "%d", priv->retry_rate);
3818}
3819
3820static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
3821 store_retry_rate);
3822
3823static ssize_t store_power_level(struct device *d,
3824 struct device_attribute *attr,
3825 const char *buf, size_t count)
3826{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003827 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07003828 int rc;
3829 int mode;
3830
3831 mode = simple_strtoul(buf, NULL, 0);
3832 mutex_lock(&priv->mutex);
3833
Tomas Winklerfee12472008-04-03 16:05:21 -07003834 if (!iwl_is_ready(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003835 rc = -EAGAIN;
3836 goto out;
3837 }
3838
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003839 rc = iwl_power_set_user_mode(priv, mode);
3840 if (rc) {
3841 IWL_DEBUG_MAC80211("failed setting power mode.\n");
3842 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003843 }
Zhu Yib481de92007-09-25 17:54:57 -07003844 rc = count;
3845
3846 out:
3847 mutex_unlock(&priv->mutex);
3848 return rc;
3849}
3850
3851#define MAX_WX_STRING 80
3852
3853/* Values are in microsecond */
3854static const s32 timeout_duration[] = {
3855 350000,
3856 250000,
3857 75000,
3858 37000,
3859 25000,
3860};
3861static const s32 period_duration[] = {
3862 400000,
3863 700000,
3864 1000000,
3865 1000000,
3866 1000000
3867};
3868
3869static ssize_t show_power_level(struct device *d,
3870 struct device_attribute *attr, char *buf)
3871{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003872 struct iwl_priv *priv = dev_get_drvdata(d);
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003873 int level = priv->power_data.power_mode;
Zhu Yib481de92007-09-25 17:54:57 -07003874 char *p = buf;
3875
3876 p += sprintf(p, "%d ", level);
3877 switch (level) {
3878 case IWL_POWER_MODE_CAM:
3879 case IWL_POWER_AC:
3880 p += sprintf(p, "(AC)");
3881 break;
3882 case IWL_POWER_BATTERY:
3883 p += sprintf(p, "(BATTERY)");
3884 break;
3885 default:
3886 p += sprintf(p,
3887 "(Timeout %dms, Period %dms)",
3888 timeout_duration[level - 1] / 1000,
3889 period_duration[level - 1] / 1000);
3890 }
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003891/*
Zhu Yib481de92007-09-25 17:54:57 -07003892 if (!(priv->power_mode & IWL_POWER_ENABLED))
3893 p += sprintf(p, " OFF\n");
3894 else
3895 p += sprintf(p, " \n");
Mohamed Abbas5da4b552008-04-21 15:41:51 -07003896*/
3897 p += sprintf(p, " \n");
Zhu Yib481de92007-09-25 17:54:57 -07003898 return (p - buf + 1);
Zhu Yib481de92007-09-25 17:54:57 -07003899}
3900
3901static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR, show_power_level,
3902 store_power_level);
3903
3904static ssize_t show_channels(struct device *d,
3905 struct device_attribute *attr, char *buf)
3906{
Ester Kummer5d72a1f2008-06-13 15:44:53 +08003907
3908 struct iwl_priv *priv = dev_get_drvdata(d);
3909 struct ieee80211_channel *channels = NULL;
3910 const struct ieee80211_supported_band *supp_band = NULL;
3911 int len = 0, i;
3912 int count = 0;
3913
3914 if (!test_bit(STATUS_GEO_CONFIGURED, &priv->status))
3915 return -EAGAIN;
3916
3917 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_2GHZ);
3918 channels = supp_band->channels;
3919 count = supp_band->n_channels;
3920
3921 len += sprintf(&buf[len],
3922 "Displaying %d channels in 2.4GHz band "
3923 "(802.11bg):\n", count);
3924
3925 for (i = 0; i < count; i++)
3926 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3927 ieee80211_frequency_to_channel(
3928 channels[i].center_freq),
3929 channels[i].max_power,
3930 channels[i].flags & IEEE80211_CHAN_RADAR ?
3931 " (IEEE 802.11h required)" : "",
3932 (!(channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3933 || (channels[i].flags &
3934 IEEE80211_CHAN_RADAR)) ? "" :
3935 ", IBSS",
3936 channels[i].flags &
3937 IEEE80211_CHAN_PASSIVE_SCAN ?
3938 "passive only" : "active/passive");
3939
3940 supp_band = iwl_get_hw_mode(priv, IEEE80211_BAND_5GHZ);
3941 channels = supp_band->channels;
3942 count = supp_band->n_channels;
3943
3944 len += sprintf(&buf[len], "Displaying %d channels in 5.2GHz band "
3945 "(802.11a):\n", count);
3946
3947 for (i = 0; i < count; i++)
3948 len += sprintf(&buf[len], "%d: %ddBm: BSS%s%s, %s.\n",
3949 ieee80211_frequency_to_channel(
3950 channels[i].center_freq),
3951 channels[i].max_power,
3952 channels[i].flags & IEEE80211_CHAN_RADAR ?
3953 " (IEEE 802.11h required)" : "",
3954 ((channels[i].flags & IEEE80211_CHAN_NO_IBSS)
3955 || (channels[i].flags &
3956 IEEE80211_CHAN_RADAR)) ? "" :
3957 ", IBSS",
3958 channels[i].flags &
3959 IEEE80211_CHAN_PASSIVE_SCAN ?
3960 "passive only" : "active/passive");
3961
3962 return len;
Zhu Yib481de92007-09-25 17:54:57 -07003963}
3964
3965static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
3966
3967static ssize_t show_statistics(struct device *d,
3968 struct device_attribute *attr, char *buf)
3969{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07003970 struct iwl_priv *priv = dev_get_drvdata(d);
Emmanuel Grumbach8f91aec2008-06-30 17:23:07 +08003971 u32 size = sizeof(struct iwl_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07003972 u32 len = 0, ofs = 0;
3973 u8 *data = (u8 *) & priv->statistics;
3974 int rc = 0;
3975
Tomas Winklerfee12472008-04-03 16:05:21 -07003976 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003977 return -EAGAIN;
3978
3979 mutex_lock(&priv->mutex);
Emmanuel Grumbach49ea8592008-04-15 16:01:37 -07003980 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003981 mutex_unlock(&priv->mutex);
3982
3983 if (rc) {
3984 len = sprintf(buf,
3985 "Error sending statistics request: 0x%08X\n", rc);
3986 return len;
3987 }
3988
3989 while (size && (PAGE_SIZE - len)) {
3990 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
3991 PAGE_SIZE - len, 1);
3992 len = strlen(buf);
3993 if (PAGE_SIZE - len)
3994 buf[len++] = '\n';
3995
3996 ofs += 16;
3997 size -= min(size, 16U);
3998 }
3999
4000 return len;
4001}
4002
4003static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4004
Zhu Yib481de92007-09-25 17:54:57 -07004005static ssize_t show_status(struct device *d,
4006 struct device_attribute *attr, char *buf)
4007{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004008 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Tomas Winklerfee12472008-04-03 16:05:21 -07004009 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004010 return -EAGAIN;
4011 return sprintf(buf, "0x%08x\n", (int)priv->status);
4012}
4013
4014static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4015
Zhu Yib481de92007-09-25 17:54:57 -07004016/*****************************************************************************
4017 *
4018 * driver setup and teardown
4019 *
4020 *****************************************************************************/
4021
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004022static void iwl_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004023{
4024 priv->workqueue = create_workqueue(DRV_NAME);
4025
4026 init_waitqueue_head(&priv->wait_command_queue);
4027
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004028 INIT_WORK(&priv->up, iwl4965_bg_up);
4029 INIT_WORK(&priv->restart, iwl4965_bg_restart);
4030 INIT_WORK(&priv->rx_replenish, iwl4965_bg_rx_replenish);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004031 INIT_WORK(&priv->rf_kill, iwl4965_bg_rf_kill);
4032 INIT_WORK(&priv->beacon_update, iwl4965_bg_beacon_update);
Abhijeet Kolekar4419e392008-05-05 10:22:47 +08004033 INIT_WORK(&priv->set_monitor, iwl4965_bg_set_monitor);
Emmanuel Grumbach16e727e2008-06-12 09:46:52 +08004034 INIT_WORK(&priv->run_time_calib_work, iwl_bg_run_time_calib_work);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004035 INIT_DELAYED_WORK(&priv->post_associate, iwl4965_bg_post_associate);
Tomas Winkler4a4a9e82008-05-29 16:34:54 +08004036 INIT_DELAYED_WORK(&priv->init_alive_start, iwl_bg_init_alive_start);
4037 INIT_DELAYED_WORK(&priv->alive_start, iwl_bg_alive_start);
Tomas Winkler2a421b92008-06-12 09:47:10 +08004038
4039 /* FIXME : remove when resolved PENDING */
4040 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4041 iwl_setup_scan_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004042
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004043 if (priv->cfg->ops->lib->setup_deferred_work)
4044 priv->cfg->ops->lib->setup_deferred_work(priv);
4045
4046 init_timer(&priv->statistics_periodic);
4047 priv->statistics_periodic.data = (unsigned long)priv;
4048 priv->statistics_periodic.function = iwl4965_bg_statistics_periodic;
Zhu Yib481de92007-09-25 17:54:57 -07004049
4050 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004051 iwl4965_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004052}
4053
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004054static void iwl_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004055{
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004056 if (priv->cfg->ops->lib->cancel_deferred_work)
4057 priv->cfg->ops->lib->cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004058
Joonwoo Park3ae6a052007-11-29 10:43:16 +09004059 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004060 cancel_delayed_work(&priv->scan_check);
4061 cancel_delayed_work(&priv->alive_start);
4062 cancel_delayed_work(&priv->post_associate);
4063 cancel_work_sync(&priv->beacon_update);
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004064 del_timer_sync(&priv->statistics_periodic);
Zhu Yib481de92007-09-25 17:54:57 -07004065}
4066
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004067static struct attribute *iwl4965_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004068 &dev_attr_channels.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004069 &dev_attr_flags.attr,
4070 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004071#ifdef CONFIG_IWL4965_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004072 &dev_attr_measurement.attr,
4073#endif
4074 &dev_attr_power_level.attr,
4075 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004076 &dev_attr_rs_window.attr,
4077 &dev_attr_statistics.attr,
4078 &dev_attr_status.attr,
4079 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004080 &dev_attr_tx_power.attr,
Ester Kummer8cf769c2008-05-06 11:05:11 +08004081#ifdef CONFIG_IWLWIFI_DEBUG
4082 &dev_attr_debug_level.attr,
4083#endif
Tomas Winklerbc6f59b2008-05-06 11:05:13 +08004084 &dev_attr_version.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004085
4086 NULL
4087};
4088
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004089static struct attribute_group iwl4965_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004090 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004091 .attrs = iwl4965_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004092};
4093
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004094static struct ieee80211_ops iwl4965_hw_ops = {
4095 .tx = iwl4965_mac_tx,
4096 .start = iwl4965_mac_start,
4097 .stop = iwl4965_mac_stop,
4098 .add_interface = iwl4965_mac_add_interface,
4099 .remove_interface = iwl4965_mac_remove_interface,
4100 .config = iwl4965_mac_config,
4101 .config_interface = iwl4965_mac_config_interface,
4102 .configure_filter = iwl4965_configure_filter,
4103 .set_key = iwl4965_mac_set_key,
Emmanuel Grumbachab885f82008-03-20 15:06:43 +02004104 .update_tkip_key = iwl4965_mac_update_tkip_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004105 .get_stats = iwl4965_mac_get_stats,
4106 .get_tx_stats = iwl4965_mac_get_tx_stats,
4107 .conf_tx = iwl4965_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004108 .reset_tsf = iwl4965_mac_reset_tsf,
Johannes Berg471b3ef2007-12-28 14:32:58 +01004109 .bss_info_changed = iwl4965_bss_info_changed,
Ron Rindjunsky9ab46172007-12-25 17:00:38 +02004110 .ampdu_action = iwl4965_mac_ampdu_action,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004111 .hw_scan = iwl4965_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004112};
4113
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004114static int iwl4965_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004115{
4116 int err = 0;
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004117 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004118 struct ieee80211_hw *hw;
Tomas Winkler82b9a122008-03-04 18:09:30 -08004119 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004120 unsigned long flags;
Zhu Yi5a669262008-01-14 17:46:18 -08004121 DECLARE_MAC_BUF(mac);
Zhu Yib481de92007-09-25 17:54:57 -07004122
Assaf Krauss316c30d2008-03-14 10:38:46 -07004123 /************************
4124 * 1. Allocating HW data
4125 ************************/
4126
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004127 /* Disabling hardware scan means that mac80211 will perform scans
4128 * "the hard way", rather than using device's scan. */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004129 if (cfg->mod_params->disable_hw_scan) {
Ester Kummerbf403db2008-05-05 10:22:40 +08004130 if (cfg->mod_params->debug & IWL_DL_INFO)
4131 dev_printk(KERN_DEBUG, &(pdev->dev),
4132 "Disabling hw_scan\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004133 iwl4965_hw_ops.hw_scan = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004134 }
4135
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004136 hw = iwl_alloc_all(cfg, &iwl4965_hw_ops);
4137 if (!hw) {
Zhu Yib481de92007-09-25 17:54:57 -07004138 err = -ENOMEM;
4139 goto out;
4140 }
Assaf Krauss1d0a0822008-03-14 10:38:48 -07004141 priv = hw->priv;
4142 /* At this point both hw and priv are allocated. */
4143
Zhu Yib481de92007-09-25 17:54:57 -07004144 SET_IEEE80211_DEV(hw, &pdev->dev);
4145
4146 IWL_DEBUG_INFO("*** LOAD DRIVER ***\n");
Tomas Winkler82b9a122008-03-04 18:09:30 -08004147 priv->cfg = cfg;
Zhu Yib481de92007-09-25 17:54:57 -07004148 priv->pci_dev = pdev;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004149
Tomas Winkler0a6857e2008-03-12 16:58:49 -07004150#ifdef CONFIG_IWLWIFI_DEBUG
Ester Kummerbf403db2008-05-05 10:22:40 +08004151 priv->debug_level = priv->cfg->mod_params->debug;
Zhu Yib481de92007-09-25 17:54:57 -07004152 atomic_set(&priv->restrict_refcnt, 0);
4153#endif
Zhu Yib481de92007-09-25 17:54:57 -07004154
Assaf Krauss316c30d2008-03-14 10:38:46 -07004155 /**************************
4156 * 2. Initializing PCI bus
4157 **************************/
4158 if (pci_enable_device(pdev)) {
4159 err = -ENODEV;
4160 goto out_ieee80211_free_hw;
4161 }
4162
4163 pci_set_master(pdev);
4164
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004165 err = pci_set_dma_mask(pdev, DMA_64BIT_MASK);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004166 if (!err)
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004167 err = pci_set_consistent_dma_mask(pdev, DMA_64BIT_MASK);
4168 if (err) {
4169 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
4170 if (!err)
4171 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
4172 /* both attempts failed: */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004173 if (err) {
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004174 printk(KERN_WARNING "%s: No suitable DMA available.\n",
4175 DRV_NAME);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004176 goto out_pci_disable_device;
Ron Rindjunskycc2a8ea2008-04-21 15:41:59 -07004177 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004178 }
4179
4180 err = pci_request_regions(pdev, DRV_NAME);
4181 if (err)
4182 goto out_pci_disable_device;
4183
4184 pci_set_drvdata(pdev, priv);
4185
4186 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4187 * PCI Tx retries from interfering with C3 CPU state */
4188 pci_write_config_byte(pdev, 0x41, 0x00);
4189
4190 /***********************
4191 * 3. Read REV register
4192 ***********************/
4193 priv->hw_base = pci_iomap(pdev, 0, 0);
4194 if (!priv->hw_base) {
4195 err = -ENODEV;
4196 goto out_pci_release_regions;
4197 }
4198
4199 IWL_DEBUG_INFO("pci_resource_len = 0x%08llx\n",
4200 (unsigned long long) pci_resource_len(pdev, 0));
4201 IWL_DEBUG_INFO("pci_resource_base = %p\n", priv->hw_base);
4202
Tomas Winklerb661c812008-04-23 17:14:54 -07004203 iwl_hw_detect(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004204 printk(KERN_INFO DRV_NAME
Tomas Winklerb661c812008-04-23 17:14:54 -07004205 ": Detected Intel Wireless WiFi Link %s REV=0x%X\n",
4206 priv->cfg->name, priv->hw_rev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004207
Tomas Winkler91238712008-04-23 17:14:53 -07004208 /* amp init */
4209 err = priv->cfg->ops->lib->apm_ops.init(priv);
4210 if (err < 0) {
4211 IWL_DEBUG_INFO("Failed to init APMG\n");
4212 goto out_iounmap;
4213 }
Assaf Krauss316c30d2008-03-14 10:38:46 -07004214 /*****************
4215 * 4. Read EEPROM
4216 *****************/
Assaf Krauss316c30d2008-03-14 10:38:46 -07004217 /* Read the EEPROM */
4218 err = iwl_eeprom_init(priv);
4219 if (err) {
4220 IWL_ERROR("Unable to init EEPROM\n");
4221 goto out_iounmap;
4222 }
Tomas Winkler8614f362008-04-23 17:14:55 -07004223 err = iwl_eeprom_check_version(priv);
4224 if (err)
4225 goto out_iounmap;
4226
Ron Rindjunsky02883012008-05-15 13:53:53 +08004227 /* extract MAC Address */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004228 iwl_eeprom_get_mac(priv, priv->mac_addr);
4229 IWL_DEBUG_INFO("MAC address: %s\n", print_mac(mac, priv->mac_addr));
4230 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4231
4232 /************************
4233 * 5. Setup HW constants
4234 ************************/
Ron Rindjunskyda154e32008-06-30 17:23:20 +08004235 if (iwl_set_hw_params(priv)) {
Tomas Winkler5425e492008-04-15 16:01:38 -07004236 IWL_ERROR("failed to set hw parameters\n");
Tomas Winkler073d3f52008-04-21 15:41:52 -07004237 goto out_free_eeprom;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004238 }
4239
4240 /*******************
Tomas Winkler6ba87952008-05-15 13:54:17 +08004241 * 6. Setup priv
Assaf Krauss316c30d2008-03-14 10:38:46 -07004242 *******************/
Zhu Yib481de92007-09-25 17:54:57 -07004243
Tomas Winkler6ba87952008-05-15 13:54:17 +08004244 err = iwl_init_drv(priv);
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004245 if (err)
Ron Rindjunsky399f4902008-04-23 17:14:56 -07004246 goto out_free_eeprom;
Assaf Kraussbf85ea42008-03-14 10:38:49 -07004247 /* At this point both hw and priv are initialized. */
Assaf Krauss316c30d2008-03-14 10:38:46 -07004248
4249 /**********************************
4250 * 7. Initialize module parameters
4251 **********************************/
4252
4253 /* Disable radio (SW RF KILL) via parameter when loading driver */
Assaf Krauss1ea87392008-03-18 14:57:50 -07004254 if (priv->cfg->mod_params->disable) {
Assaf Krauss316c30d2008-03-14 10:38:46 -07004255 set_bit(STATUS_RF_KILL_SW, &priv->status);
4256 IWL_DEBUG_INFO("Radio disabled.\n");
4257 }
4258
Assaf Krauss316c30d2008-03-14 10:38:46 -07004259 /********************
4260 * 8. Setup services
4261 ********************/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004262 spin_lock_irqsave(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004263 iwl4965_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004264 spin_unlock_irqrestore(&priv->lock, flags);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004265
4266 err = sysfs_create_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4267 if (err) {
4268 IWL_ERROR("failed to create sysfs device attributes\n");
Tomas Winkler6ba87952008-05-15 13:54:17 +08004269 goto out_uninit_drv;
Assaf Krauss316c30d2008-03-14 10:38:46 -07004270 }
4271
Assaf Krauss316c30d2008-03-14 10:38:46 -07004272
Emmanuel Grumbach4e393172008-06-12 09:46:53 +08004273 iwl_setup_deferred_work(priv);
Emmanuel Grumbach653fa4a2008-06-30 17:23:11 +08004274 iwl_setup_rx_handlers(priv);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004275
4276 /********************
4277 * 9. Conclude
4278 ********************/
Zhu Yi5a669262008-01-14 17:46:18 -08004279 pci_save_state(pdev);
4280 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004281
Tomas Winkler6ba87952008-05-15 13:54:17 +08004282 /**********************************
4283 * 10. Setup and register mac80211
4284 **********************************/
4285
4286 err = iwl_setup_mac(priv);
4287 if (err)
4288 goto out_remove_sysfs;
4289
4290 err = iwl_dbgfs_register(priv, DRV_NAME);
4291 if (err)
4292 IWL_ERROR("failed to create debugfs files\n");
4293
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004294 err = iwl_rfkill_init(priv);
4295 if (err)
4296 IWL_ERROR("Unable to initialize RFKILL system. "
4297 "Ignoring error: %d\n", err);
4298 iwl_power_initialize(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004299 return 0;
4300
Assaf Krauss316c30d2008-03-14 10:38:46 -07004301 out_remove_sysfs:
4302 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
Tomas Winkler6ba87952008-05-15 13:54:17 +08004303 out_uninit_drv:
4304 iwl_uninit_drv(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004305 out_free_eeprom:
4306 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004307 out_iounmap:
4308 pci_iounmap(pdev, priv->hw_base);
4309 out_pci_release_regions:
4310 pci_release_regions(pdev);
Assaf Krauss316c30d2008-03-14 10:38:46 -07004311 pci_set_drvdata(pdev, NULL);
Zhu Yib481de92007-09-25 17:54:57 -07004312 out_pci_disable_device:
4313 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004314 out_ieee80211_free_hw:
4315 ieee80211_free_hw(priv->hw);
4316 out:
4317 return err;
4318}
4319
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004320static void __devexit iwl4965_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004321{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004322 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004323 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004324
4325 if (!priv)
4326 return;
4327
4328 IWL_DEBUG_INFO("*** UNLOAD DRIVER ***\n");
4329
Emmanuel Grumbach67249622008-05-29 16:35:26 +08004330 iwl_dbgfs_unregister(priv);
4331 sysfs_remove_group(&pdev->dev.kobj, &iwl4965_attribute_group);
4332
Ron Rindjunskyc4f55232008-03-28 16:21:10 -07004333 if (priv->mac80211_registered) {
4334 ieee80211_unregister_hw(priv->hw);
4335 priv->mac80211_registered = 0;
4336 }
4337
Zhu Yib481de92007-09-25 17:54:57 -07004338 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004339
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004340 iwl4965_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004341
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004342 /* make sure we flush any pending irq or
4343 * tasklet for the driver
4344 */
4345 spin_lock_irqsave(&priv->lock, flags);
4346 iwl4965_disable_interrupts(priv);
4347 spin_unlock_irqrestore(&priv->lock, flags);
4348
4349 iwl_synchronize_irq(priv);
4350
Emmanuel Grumbach58d0f362008-06-12 09:47:19 +08004351 iwl_rfkill_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004352 iwl4965_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004353
4354 if (priv->rxq.bd)
Tomas Winklera55360e2008-05-05 10:22:28 +08004355 iwl_rx_queue_free(priv, &priv->rxq);
Ron Rindjunsky1053d352008-05-05 10:22:43 +08004356 iwl_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004357
Emmanuel Grumbach37deb2a2008-06-30 17:23:08 +08004358 iwl_clear_stations_table(priv);
Tomas Winkler073d3f52008-04-21 15:41:52 -07004359 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004360
Zhu Yib481de92007-09-25 17:54:57 -07004361
Mohamed Abbas948c1712007-10-25 17:15:45 +08004362 /*netif_stop_queue(dev); */
4363 flush_workqueue(priv->workqueue);
4364
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004365 /* ieee80211_unregister_hw calls iwl4965_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07004366 * priv->workqueue... so we can't take down the workqueue
4367 * until now... */
4368 destroy_workqueue(priv->workqueue);
4369 priv->workqueue = NULL;
4370
Zhu Yib481de92007-09-25 17:54:57 -07004371 pci_iounmap(pdev, priv->hw_base);
4372 pci_release_regions(pdev);
4373 pci_disable_device(pdev);
4374 pci_set_drvdata(pdev, NULL);
4375
Tomas Winkler6ba87952008-05-15 13:54:17 +08004376 iwl_uninit_drv(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004377
4378 if (priv->ibss_beacon)
4379 dev_kfree_skb(priv->ibss_beacon);
4380
4381 ieee80211_free_hw(priv->hw);
4382}
4383
4384#ifdef CONFIG_PM
4385
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004386static int iwl4965_pci_suspend(struct pci_dev *pdev, pm_message_t state)
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 Yie655b9f2008-01-24 02:19:38 -08004390 if (priv->is_open) {
4391 set_bit(STATUS_IN_SUSPEND, &priv->status);
4392 iwl4965_mac_stop(priv->hw);
4393 priv->is_open = 1;
4394 }
Zhu Yib481de92007-09-25 17:54:57 -07004395
Zhu Yib481de92007-09-25 17:54:57 -07004396 pci_set_power_state(pdev, PCI_D3hot);
4397
Zhu Yib481de92007-09-25 17:54:57 -07004398 return 0;
4399}
4400
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004401static int iwl4965_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004402{
Tomas Winklerc79dd5b2008-03-12 16:58:50 -07004403 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004404
Zhu Yib481de92007-09-25 17:54:57 -07004405 pci_set_power_state(pdev, PCI_D0);
Zhu Yib481de92007-09-25 17:54:57 -07004406
Zhu Yie655b9f2008-01-24 02:19:38 -08004407 if (priv->is_open)
4408 iwl4965_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07004409
Zhu Yie655b9f2008-01-24 02:19:38 -08004410 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004411 return 0;
4412}
4413
4414#endif /* CONFIG_PM */
4415
4416/*****************************************************************************
4417 *
4418 * driver and module entry point
4419 *
4420 *****************************************************************************/
4421
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004422/* Hardware specific file defines the PCI IDs table for that hardware module */
4423static struct pci_device_id iwl_hw_card_ids[] = {
4424 {IWL_PCI_DEVICE(0x4229, PCI_ANY_ID, iwl4965_agn_cfg)},
4425 {IWL_PCI_DEVICE(0x4230, PCI_ANY_ID, iwl4965_agn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004426#ifdef CONFIG_IWL5000
Esti Kummer47408632008-07-11 11:53:30 +08004427 {IWL_PCI_DEVICE(0x4232, 0x1205, iwl5100_bg_cfg)},
4428 {IWL_PCI_DEVICE(0x4232, 0x1305, iwl5100_bg_cfg)},
4429 {IWL_PCI_DEVICE(0x4232, 0x1206, iwl5100_abg_cfg)},
4430 {IWL_PCI_DEVICE(0x4232, 0x1306, iwl5100_abg_cfg)},
4431 {IWL_PCI_DEVICE(0x4232, 0x1326, iwl5100_abg_cfg)},
4432 {IWL_PCI_DEVICE(0x4237, 0x1216, iwl5100_abg_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004433 {IWL_PCI_DEVICE(0x4232, PCI_ANY_ID, iwl5100_agn_cfg)},
Esti Kummer47408632008-07-11 11:53:30 +08004434 {IWL_PCI_DEVICE(0x4235, PCI_ANY_ID, iwl5300_agn_cfg)},
4435 {IWL_PCI_DEVICE(0x4236, PCI_ANY_ID, iwl5300_agn_cfg)},
4436 {IWL_PCI_DEVICE(0x4237, PCI_ANY_ID, iwl5100_agn_cfg)},
Tomas Winkler5a6a2562008-04-24 11:55:23 -07004437 {IWL_PCI_DEVICE(0x423A, PCI_ANY_ID, iwl5350_agn_cfg)},
4438#endif /* CONFIG_IWL5000 */
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004439 {0}
4440};
4441MODULE_DEVICE_TABLE(pci, iwl_hw_card_ids);
4442
4443static struct pci_driver iwl_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07004444 .name = DRV_NAME,
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004445 .id_table = iwl_hw_card_ids,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004446 .probe = iwl4965_pci_probe,
4447 .remove = __devexit_p(iwl4965_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07004448#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004449 .suspend = iwl4965_pci_suspend,
4450 .resume = iwl4965_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07004451#endif
4452};
4453
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004454static int __init iwl4965_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07004455{
4456
4457 int ret;
4458 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
4459 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004460
4461 ret = iwl4965_rate_control_register();
4462 if (ret) {
4463 IWL_ERROR("Unable to register rate control algorithm: %d\n", ret);
4464 return ret;
4465 }
4466
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004467 ret = pci_register_driver(&iwl_driver);
Zhu Yib481de92007-09-25 17:54:57 -07004468 if (ret) {
4469 IWL_ERROR("Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004470 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07004471 }
Zhu Yib481de92007-09-25 17:54:57 -07004472
4473 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004474
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004475error_register:
4476 iwl4965_rate_control_unregister();
4477 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004478}
4479
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004480static void __exit iwl4965_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07004481{
Ron Rindjunskyfed90172008-04-15 16:01:41 -07004482 pci_unregister_driver(&iwl_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07004483 iwl4965_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07004484}
4485
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004486module_exit(iwl4965_exit);
4487module_init(iwl4965_init);