blob: 857393a690163557294c5cf0c97357fec07e69be [file] [log] [blame]
Zhu Yib481de92007-09-25 17:54:57 -07001/******************************************************************************
2 *
Reinette Chatre01f81622009-01-08 10:20:02 -08003 * Copyright(c) 2003 - 2009 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:
Winkler, Tomas759ef892008-12-09 11:28:58 -080025 * Intel Linux Wireless <ilw@linux.intel.com>
Zhu Yib481de92007-09-25 17:54:57 -070026 * Intel Corporation, 5200 N.E. Elam Young Parkway, Hillsboro, OR 97124-6497
27 *
28 *****************************************************************************/
29
Zhu Yib481de92007-09-25 17:54:57 -070030#include <linux/kernel.h>
31#include <linux/module.h>
Zhu Yib481de92007-09-25 17:54:57 -070032#include <linux/init.h>
33#include <linux/pci.h>
34#include <linux/dma-mapping.h>
35#include <linux/delay.h>
36#include <linux/skbuff.h>
37#include <linux/netdevice.h>
38#include <linux/wireless.h>
39#include <linux/firmware.h>
Zhu Yib481de92007-09-25 17:54:57 -070040#include <linux/etherdevice.h>
41#include <linux/if_arp.h>
42
43#include <net/ieee80211_radiotap.h>
John W. Linville7e272fc2008-09-24 18:13:14 -040044#include <net/lib80211.h>
Zhu Yib481de92007-09-25 17:54:57 -070045#include <net/mac80211.h>
46
47#include <asm/div64.h>
48
Samuel Ortiza3139c52008-12-19 10:37:09 +080049#define DRV_NAME "iwl3945"
50
Winkler, Tomasdbb66542008-12-22 11:31:14 +080051#include "iwl-fh.h"
52#include "iwl-3945-fh.h"
Tomas Winkler600c0e12008-12-19 10:37:04 +080053#include "iwl-commands.h"
Samuel Ortiz17f841c2009-01-23 13:45:20 -080054#include "iwl-sta.h"
Zhu Yib481de92007-09-25 17:54:57 -070055#include "iwl-3945.h"
56#include "iwl-helpers.h"
Kolekar, Abhijeet5747d472008-12-19 10:37:18 +080057#include "iwl-core.h"
Samuel Ortizd20b3c62008-12-19 10:37:15 +080058#include "iwl-dev.h"
Zhu Yib481de92007-09-25 17:54:57 -070059
Zhu Yib481de92007-09-25 17:54:57 -070060/*
61 * module name, copyright, version, etc.
Zhu Yib481de92007-09-25 17:54:57 -070062 */
63
64#define DRV_DESCRIPTION \
65"Intel(R) PRO/Wireless 3945ABG/BG Network Connection driver for Linux"
66
Samuel Ortizd08853a2009-01-23 13:45:17 -080067#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -070068#define VD "d"
69#else
70#define VD
71#endif
72
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +080073#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -070074#define VS "s"
75#else
76#define VS
77#endif
78
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080079#define IWL39_VERSION "1.2.26k" VD VS
Reinette Chatre01f81622009-01-08 10:20:02 -080080#define DRV_COPYRIGHT "Copyright(c) 2003-2009 Intel Corporation"
Tomas Winklera7b75202008-12-11 10:33:41 -080081#define DRV_AUTHOR "<ilw@linux.intel.com>"
Kolekar, Abhijeeteaa686c2008-12-19 10:37:17 +080082#define DRV_VERSION IWL39_VERSION
Zhu Yib481de92007-09-25 17:54:57 -070083
Zhu Yib481de92007-09-25 17:54:57 -070084
85MODULE_DESCRIPTION(DRV_DESCRIPTION);
86MODULE_VERSION(DRV_VERSION);
Tomas Winklera7b75202008-12-11 10:33:41 -080087MODULE_AUTHOR(DRV_COPYRIGHT " " DRV_AUTHOR);
Zhu Yib481de92007-09-25 17:54:57 -070088MODULE_LICENSE("GPL");
89
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080090 /* module parameters */
91struct iwl_mod_params iwl3945_mod_params = {
92 .num_of_queues = IWL39_MAX_NUM_QUEUES,
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -080093 .sw_crypto = 1,
Samuel Ortizaf48d042009-01-23 13:45:19 -080094 .restart_fw = 1,
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +080095 /* the rest are 0 by default */
96};
97
Zhu Yib481de92007-09-25 17:54:57 -070098/*************** STATION TABLE MANAGEMENT ****
Ben Cahill9fbab512007-11-29 11:09:47 +080099 * mac80211 should be examined to determine if sta_info is duplicating
Zhu Yib481de92007-09-25 17:54:57 -0700100 * the functionality provided here
101 */
102
103/**************************************************************/
Ian Schram01ebd062007-10-25 17:15:22 +0800104#if 0 /* temporary disable till we add real remove station */
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800105/**
106 * iwl3945_remove_station - Remove driver's knowledge of station.
107 *
108 * NOTE: This does not remove station from device's station table.
109 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800110static u8 iwl3945_remove_station(struct iwl_priv *priv, const u8 *addr, int is_ap)
Zhu Yib481de92007-09-25 17:54:57 -0700111{
112 int index = IWL_INVALID_STATION;
113 int i;
114 unsigned long flags;
115
116 spin_lock_irqsave(&priv->sta_lock, flags);
117
118 if (is_ap)
119 index = IWL_AP_ID;
120 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800121 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700122 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800123 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800124 if (priv->stations_39[i].used &&
125 !compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700126 addr)) {
127 index = i;
128 break;
129 }
130
131 if (unlikely(index == IWL_INVALID_STATION))
132 goto out;
133
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800134 if (priv->stations_39[index].used) {
135 priv->stations_39[index].used = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700136 priv->num_stations--;
137 }
138
139 BUG_ON(priv->num_stations < 0);
140
141out:
142 spin_unlock_irqrestore(&priv->sta_lock, flags);
143 return 0;
144}
Zhu Yi556f8db2007-09-27 11:27:33 +0800145#endif
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800146
147/**
148 * iwl3945_clear_stations_table - Clear the driver's station table
149 *
150 * NOTE: This does not clear or otherwise alter the device's station table.
151 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800152static void iwl3945_clear_stations_table(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700153{
154 unsigned long flags;
155
156 spin_lock_irqsave(&priv->sta_lock, flags);
157
158 priv->num_stations = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800159 memset(priv->stations_39, 0, sizeof(priv->stations_39));
Zhu Yib481de92007-09-25 17:54:57 -0700160
161 spin_unlock_irqrestore(&priv->sta_lock, flags);
162}
163
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800164/**
165 * iwl3945_add_station - Add station to station tables in driver and device
166 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800167u8 iwl3945_add_station(struct iwl_priv *priv, const u8 *addr, int is_ap, u8 flags)
Zhu Yib481de92007-09-25 17:54:57 -0700168{
169 int i;
170 int index = IWL_INVALID_STATION;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800171 struct iwl3945_station_entry *station;
Zhu Yib481de92007-09-25 17:54:57 -0700172 unsigned long flags_spin;
Zhu Yic14c5212007-09-27 11:27:35 +0800173 u8 rate;
Zhu Yib481de92007-09-25 17:54:57 -0700174
175 spin_lock_irqsave(&priv->sta_lock, flags_spin);
176 if (is_ap)
177 index = IWL_AP_ID;
178 else if (is_broadcast_ether_addr(addr))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800179 index = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700180 else
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800181 for (i = IWL_STA_ID; i < priv->hw_params.max_stations; i++) {
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800182 if (!compare_ether_addr(priv->stations_39[i].sta.sta.addr,
Zhu Yib481de92007-09-25 17:54:57 -0700183 addr)) {
184 index = i;
185 break;
186 }
187
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800188 if (!priv->stations_39[i].used &&
Zhu Yib481de92007-09-25 17:54:57 -0700189 index == IWL_INVALID_STATION)
190 index = i;
191 }
192
Ian Schram01ebd062007-10-25 17:15:22 +0800193 /* These two conditions has the same outcome but keep them separate
Zhu Yib481de92007-09-25 17:54:57 -0700194 since they have different meaning */
195 if (unlikely(index == IWL_INVALID_STATION)) {
196 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
197 return index;
198 }
199
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800200 if (priv->stations_39[index].used &&
201 !compare_ether_addr(priv->stations_39[index].sta.sta.addr, addr)) {
Zhu Yib481de92007-09-25 17:54:57 -0700202 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
203 return index;
204 }
205
Tomas Winklere1623442009-01-27 14:27:56 -0800206 IWL_DEBUG_ASSOC(priv, "Add STA ID %d: %pM\n", index, addr);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800207 station = &priv->stations_39[index];
Zhu Yib481de92007-09-25 17:54:57 -0700208 station->used = 1;
209 priv->num_stations++;
210
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800211 /* Set up the REPLY_ADD_STA command to send to device */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800212 memset(&station->sta, 0, sizeof(struct iwl3945_addsta_cmd));
Zhu Yib481de92007-09-25 17:54:57 -0700213 memcpy(station->sta.sta.addr, addr, ETH_ALEN);
214 station->sta.mode = 0;
215 station->sta.sta.sta_id = index;
216 station->sta.station_flags = 0;
217
Johannes Berg8318d782008-01-24 19:38:38 +0100218 if (priv->band == IEEE80211_BAND_5GHZ)
Tomas Winkler69946332007-10-25 17:15:27 +0800219 rate = IWL_RATE_6M_PLCP;
220 else
221 rate = IWL_RATE_1M_PLCP;
Zhu Yic14c5212007-09-27 11:27:35 +0800222
223 /* Turn on both antennas for the station... */
224 station->sta.rate_n_flags =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800225 iwl3945_hw_set_rate_n_flags(rate, RATE_MCS_ANT_AB_MSK);
Zhu Yic14c5212007-09-27 11:27:35 +0800226
Zhu Yib481de92007-09-25 17:54:57 -0700227 spin_unlock_irqrestore(&priv->sta_lock, flags_spin);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800228
229 /* Add station to device's station table */
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800230 iwl_send_add_sta(priv,
231 (struct iwl_addsta_cmd *)&station->sta, flags);
Zhu Yib481de92007-09-25 17:54:57 -0700232 return index;
233
234}
235
Zhu Yib481de92007-09-25 17:54:57 -0700236/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800237 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
238 * @priv: eeprom and antenna fields are used to determine antenna flags
239 *
240 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
241 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
242 *
243 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
244 * IWL_ANTENNA_MAIN - Force MAIN antenna
245 * IWL_ANTENNA_AUX - Force AUX antenna
246 */
247__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
248{
249 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
250
251 switch (iwl3945_mod_params.antenna) {
252 case IWL_ANTENNA_DIVERSITY:
253 return 0;
254
255 case IWL_ANTENNA_MAIN:
256 if (eeprom->antenna_switch_type)
257 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
258 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
259
260 case IWL_ANTENNA_AUX:
261 if (eeprom->antenna_switch_type)
262 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
263 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
264 }
265
266 /* bad antenna selector value */
267 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
268 iwl3945_mod_params.antenna);
269
270 return 0; /* "diversity" is default if error */
271}
272
273/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800274 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700275 *
Ian Schram01ebd062007-10-25 17:15:22 +0800276 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700277 * the active_rxon structure is updated with the new data. This
278 * function correctly transitions out of the RXON_ASSOC_MSK state if
279 * a HW tune is required based on the RXON structure changes.
280 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800281static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700282{
283 /* cast away the const for active_rxon in this function */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800284 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
285 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700286 int rc = 0;
Abhijeet Kolekar83370312009-03-06 13:52:54 -0800287 bool new_assoc =
288 !!(priv->staging_rxon.filter_flags & RXON_FILTER_ASSOC_MSK);
Zhu Yib481de92007-09-25 17:54:57 -0700289
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800290 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700291 return -1;
292
293 /* always get timestamp with Rx frame */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800294 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700295
296 /* select antenna */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800297 staging_rxon->flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700298 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800299 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700300
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800301 rc = iwl_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700302 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800303 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700304 return -EINVAL;
305 }
306
307 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800308 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700309 * and other flags for the current radio configuration. */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800310 if (!iwl_full_rxon_required(priv)) {
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -0700311 rc = iwl_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700312 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800313 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700314 "configuration (%d).\n", rc);
315 return rc;
316 }
317
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800318 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700319
320 return 0;
321 }
322
323 /* If we are currently associated and the new config requires
324 * an RXON_ASSOC and the new config wants the associated mask enabled,
325 * we must clear the associated from the active configuration
326 * before we apply the new config */
Abhijeet Kolekar83370312009-03-06 13:52:54 -0800327 if (iwl_is_associated(priv) && new_assoc) {
Tomas Winklere1623442009-01-27 14:27:56 -0800328 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700329 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
330
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800331 /*
332 * reserved4 and 5 could have been filled by the iwlcore code.
333 * Let's clear them before pushing to the 3945.
334 */
335 active_rxon->reserved4 = 0;
336 active_rxon->reserved5 = 0;
Samuel Ortiz518099a2009-01-19 15:30:27 -0800337 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800338 sizeof(struct iwl3945_rxon_cmd),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800339 &priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700340
341 /* If the mask clearing failed then we set
342 * active_rxon back to what it was previously */
343 if (rc) {
344 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800345 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700346 "configuration (%d).\n", rc);
347 return rc;
348 }
Zhu Yib481de92007-09-25 17:54:57 -0700349 }
350
Tomas Winklere1623442009-01-27 14:27:56 -0800351 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700352 "* with%s RXON_FILTER_ASSOC_MSK\n"
353 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700354 "* bssid = %pM\n",
Abhijeet Kolekar83370312009-03-06 13:52:54 -0800355 (new_assoc ? "" : "out"),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800356 le16_to_cpu(staging_rxon->channel),
357 staging_rxon->bssid_addr);
358
359 /*
360 * reserved4 and 5 could have been filled by the iwlcore code.
361 * Let's clear them before pushing to the 3945.
362 */
363 staging_rxon->reserved4 = 0;
364 staging_rxon->reserved5 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700365
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800366 iwl_set_rxon_hwcrypto(priv, !priv->hw_params.sw_crypto);
367
Zhu Yib481de92007-09-25 17:54:57 -0700368 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800369 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800370 sizeof(struct iwl3945_rxon_cmd),
371 staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700372 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800373 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700374 return rc;
375 }
376
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800377 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700378
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800379 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800380
Zhu Yib481de92007-09-25 17:54:57 -0700381 /* If we issue a new RXON command which required a tune then we must
382 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800383 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700384 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800385 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700386 return rc;
387 }
388
389 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800390 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700391 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800392 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700393 return -EIO;
394 }
395
396 /* If we have set the ASSOC_MSK and we are in BSS mode then
397 * add the IWL_AP_ID to the station rate table */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800398 if (iwl_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200399 (priv->iw_mode == NL80211_IFTYPE_STATION))
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800400 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
401 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700402 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800403 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700404 return -EIO;
405 }
406
Johannes Berg8318d782008-01-24 19:38:38 +0100407 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700408 rc = iwl3945_init_hw_rate_table(priv);
409 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800410 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700411 return -EIO;
412 }
413
414 return 0;
415}
416
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800417static int iwl3945_set_ccmp_dynamic_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700418 struct ieee80211_key_conf *keyconf,
419 u8 sta_id)
420{
421 unsigned long flags;
422 __le16 key_flags = 0;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800423 int ret;
Zhu Yib481de92007-09-25 17:54:57 -0700424
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800425 key_flags |= (STA_KEY_FLG_CCMP | STA_KEY_FLG_MAP_KEY_MSK);
426 key_flags |= cpu_to_le16(keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
427
428 if (sta_id == priv->hw_params.bcast_sta_id)
429 key_flags |= STA_KEY_MULTICAST_MSK;
430
431 keyconf->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
432 keyconf->hw_key_idx = keyconf->keyidx;
433 key_flags &= ~STA_KEY_FLG_INVALID;
434
Zhu Yib481de92007-09-25 17:54:57 -0700435 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800436 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
437 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
438 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700439 keyconf->keylen);
440
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800441 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700442 keyconf->keylen);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800443
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700444 if ((priv->stations_39[sta_id].sta.key.key_flags & STA_KEY_FLG_ENCRYPT_MSK)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800445 == STA_KEY_FLG_NO_ENC)
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700446 priv->stations_39[sta_id].sta.key.key_offset =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800447 iwl_get_free_ucode_key_index(priv);
448 /* else, we are overriding an existing key => no need to allocated room
449 * in uCode. */
450
Abhijeet Kolekar43da9192009-03-17 21:51:53 -0700451 WARN(priv->stations_39[sta_id].sta.key.key_offset == WEP_INVALID_OFFSET,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800452 "no space for a new key");
453
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800454 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
455 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
456 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700457
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800458 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
459
460 ret = iwl_send_add_sta(priv,
461 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, CMD_ASYNC);
462
Zhu Yib481de92007-09-25 17:54:57 -0700463 spin_unlock_irqrestore(&priv->sta_lock, flags);
464
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800465 return ret;
466}
467
468static int iwl3945_set_tkip_dynamic_key_info(struct iwl_priv *priv,
469 struct ieee80211_key_conf *keyconf,
470 u8 sta_id)
471{
472 return -EOPNOTSUPP;
473}
474
475static int iwl3945_set_wep_dynamic_key_info(struct iwl_priv *priv,
476 struct ieee80211_key_conf *keyconf,
477 u8 sta_id)
478{
479 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -0700480}
481
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800482static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700483{
484 unsigned long flags;
485
486 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800487 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
488 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800489 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800490 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
491 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
492 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700493 spin_unlock_irqrestore(&priv->sta_lock, flags);
494
Tomas Winklere1623442009-01-27 14:27:56 -0800495 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800496 iwl_send_add_sta(priv,
497 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700498 return 0;
499}
500
Abhijeet Kolekarfa11d522009-03-11 11:17:54 -0700501static int iwl3945_set_dynamic_key(struct iwl_priv *priv,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800502 struct ieee80211_key_conf *keyconf, u8 sta_id)
503{
504 int ret = 0;
505
506 keyconf->hw_key_idx = HW_KEY_DYNAMIC;
507
508 switch (keyconf->alg) {
509 case ALG_CCMP:
510 ret = iwl3945_set_ccmp_dynamic_key_info(priv, keyconf, sta_id);
511 break;
512 case ALG_TKIP:
513 ret = iwl3945_set_tkip_dynamic_key_info(priv, keyconf, sta_id);
514 break;
515 case ALG_WEP:
516 ret = iwl3945_set_wep_dynamic_key_info(priv, keyconf, sta_id);
517 break;
518 default:
Abhijeet Kolekar1e680232009-03-17 21:51:50 -0700519 IWL_ERR(priv, "Unknown alg: %s alg = %d\n", __func__, keyconf->alg);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800520 ret = -EINVAL;
521 }
522
523 IWL_DEBUG_WEP(priv, "Set dynamic key: alg= %d len=%d idx=%d sta=%d ret=%d\n",
524 keyconf->alg, keyconf->keylen, keyconf->keyidx,
525 sta_id, ret);
526
527 return ret;
528}
529
530static int iwl3945_remove_static_key(struct iwl_priv *priv)
531{
532 int ret = -EOPNOTSUPP;
533
534 return ret;
535}
536
537static int iwl3945_set_static_key(struct iwl_priv *priv,
538 struct ieee80211_key_conf *key)
539{
540 if (key->alg == ALG_WEP)
541 return -EOPNOTSUPP;
542
543 IWL_ERR(priv, "Static key invalid: alg %d\n", key->alg);
544 return -EINVAL;
545}
546
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800547static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700548{
549 struct list_head *element;
550
Tomas Winklere1623442009-01-27 14:27:56 -0800551 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700552 priv->frames_count);
553
554 while (!list_empty(&priv->free_frames)) {
555 element = priv->free_frames.next;
556 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800557 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700558 priv->frames_count--;
559 }
560
561 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800562 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700563 priv->frames_count);
564 priv->frames_count = 0;
565 }
566}
567
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800568static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700569{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800570 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700571 struct list_head *element;
572 if (list_empty(&priv->free_frames)) {
573 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
574 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800575 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700576 return NULL;
577 }
578
579 priv->frames_count++;
580 return frame;
581 }
582
583 element = priv->free_frames.next;
584 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800585 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700586}
587
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800588static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700589{
590 memset(frame, 0, sizeof(*frame));
591 list_add(&frame->list, &priv->free_frames);
592}
593
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800594unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700595 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200596 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700597{
598
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800599 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200600 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
601 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700602 return 0;
603
604 if (priv->ibss_beacon->len > left)
605 return 0;
606
607 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
608
609 return priv->ibss_beacon->len;
610}
611
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800612static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700613{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800614 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700615 unsigned int frame_size;
616 int rc;
617 u8 rate;
618
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800619 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700620
621 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800622 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700623 "command.\n");
624 return -ENOMEM;
625 }
626
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800627 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700628
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800629 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700630
Samuel Ortiz518099a2009-01-19 15:30:27 -0800631 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700632 &frame->u.cmd[0]);
633
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800634 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700635
636 return rc;
637}
638
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800639static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700640{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800641 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700642 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800643 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800644 priv->shared_virt,
645 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700646}
647
Zhu Yib481de92007-09-25 17:54:57 -0700648#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800649#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700650
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800651static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700652{
653 u16 new_val = 0;
654 u16 beacon_factor = 0;
655
656 beacon_factor =
657 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
658 / MAX_UCODE_BEACON_INTERVAL;
659 new_val = beacon_val / beacon_factor;
660
661 return cpu_to_le16(new_val);
662}
663
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800664static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700665{
666 u64 interval_tm_unit;
667 u64 tsf, result;
668 unsigned long flags;
669 struct ieee80211_conf *conf = NULL;
670 u16 beacon_int = 0;
671
672 conf = ieee80211_get_hw_conf(priv->hw);
673
674 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800675 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700676 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
677
Tomas Winkler28afaf92008-12-19 10:37:06 +0800678 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700679
680 beacon_int = priv->beacon_int;
681 spin_unlock_irqrestore(&priv->lock, flags);
682
Johannes Berg05c914f2008-09-11 00:01:58 +0200683 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700684 if (beacon_int == 0) {
685 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
686 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
687 } else {
688 priv->rxon_timing.beacon_interval =
689 cpu_to_le16(beacon_int);
690 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800691 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700692 le16_to_cpu(priv->rxon_timing.beacon_interval));
693 }
694
695 priv->rxon_timing.atim_window = 0;
696 } else {
697 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800698 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700699 /* TODO: we need to get atim_window from upper stack
700 * for now we set to 0 */
701 priv->rxon_timing.atim_window = 0;
702 }
703
704 interval_tm_unit =
705 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
706 result = do_div(tsf, interval_tm_unit);
707 priv->rxon_timing.beacon_init_val =
708 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
709
Tomas Winklere1623442009-01-27 14:27:56 -0800710 IWL_DEBUG_ASSOC(priv,
711 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700712 le16_to_cpu(priv->rxon_timing.beacon_interval),
713 le32_to_cpu(priv->rxon_timing.beacon_init_val),
714 le16_to_cpu(priv->rxon_timing.atim_window));
715}
716
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800717static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700718{
Johannes Berg05c914f2008-09-11 00:01:58 +0200719 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800720 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700721
Samuel Ortize6148912009-01-23 13:45:15 -0800722 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100723 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800724 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700725
726 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800727 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800728 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700729 return -EINVAL;
730 }
731 }
732
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800733 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700734
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800735 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700736
Tomas Winklera96a27f2008-10-23 23:48:56 -0700737 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800738 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800739 return -EAGAIN;
740
741 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800742 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800743 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800744 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800745 return -EAGAIN;
746 }
747
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800748 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700749
750 return 0;
751}
752
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800753static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200754 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800755 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700756 struct sk_buff *skb_frag,
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800757 int sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700758{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800759 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200760 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -0800761 &priv->stations_39[sta_id].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700762
763 switch (keyinfo->alg) {
764 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800765 tx->sec_ctl = TX_CMD_SEC_CCM;
766 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800767 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700768 break;
769
770 case ALG_TKIP:
Zhu Yib481de92007-09-25 17:54:57 -0700771 break;
772
773 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800774 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200775 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700776
777 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800778 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700779
Winkler, Tomase52119c2008-12-22 11:31:19 +0800780 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700781
Tomas Winklere1623442009-01-27 14:27:56 -0800782 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200783 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700784 break;
785
Zhu Yib481de92007-09-25 17:54:57 -0700786 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800787 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700788 break;
789 }
790}
791
792/*
793 * handle build REPLY_TX command notification.
794 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800795static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b42008-12-19 10:37:34 +0800796 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200797 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800798 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700799{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800800 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
801 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700802 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200803 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700804
Winkler, Tomase52119c2008-12-22 11:31:19 +0800805 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200806 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700807 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700808 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700809 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700810 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700811 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
812 tx_flags |= TX_CMD_FLG_TSF_MSK;
813 } else {
814 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
815 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
816 }
817
Winkler, Tomase52119c2008-12-22 11:31:19 +0800818 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700819 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700820 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
821
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700822 if (ieee80211_is_data_qos(fc)) {
823 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800824 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700825 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800826 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700827 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800828 }
Zhu Yib481de92007-09-25 17:54:57 -0700829
Johannes Berge6a98542008-10-21 12:40:02 +0200830 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700831 tx_flags |= TX_CMD_FLG_RTS_MSK;
832 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200833 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700834 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
835 tx_flags |= TX_CMD_FLG_CTS_MSK;
836 }
837
838 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
839 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
840
841 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700842 if (ieee80211_is_mgmt(fc)) {
843 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800844 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700845 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800846 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700847 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800848 tx->timeout.pm_frame_timeout = 0;
Abhijeet Kolekar5c8df2d2009-03-11 11:17:55 -0700849#ifdef CONFIG_IWLWIFI_LEDS
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700850 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
851#endif
852 }
Zhu Yib481de92007-09-25 17:54:57 -0700853
Winkler, Tomase52119c2008-12-22 11:31:19 +0800854 tx->driver_txop = 0;
855 tx->tx_flags = tx_flags;
856 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700857}
858
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800859/**
860 * iwl3945_get_sta_id - Find station's index within station table
861 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800862static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700863{
864 int sta_id;
865 u16 fc = le16_to_cpu(hdr->frame_control);
866
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800867 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700868 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
869 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800870 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700871
872 switch (priv->iw_mode) {
873
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800874 /* If we are a client station in a BSS network, use the special
875 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200876 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700877 return IWL_AP_ID;
878
879 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200880 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800881 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700882 if (sta_id != IWL_INVALID_STATION)
883 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800884 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700885
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800886 /* If this frame is going out to an IBSS network, find the station,
887 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200888 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800889 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800890 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700891 if (sta_id != IWL_INVALID_STATION)
892 return sta_id;
893
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800894 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700895
896 if (sta_id != IWL_INVALID_STATION)
897 return sta_id;
898
Tomas Winklere1623442009-01-27 14:27:56 -0800899 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700900 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700901 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800902 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800903 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700904 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800905 /* If we are in monitor mode, use BCAST. This is required for
906 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200907 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800908 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800909
Zhu Yib481de92007-09-25 17:54:57 -0700910 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800911 IWL_WARN(priv, "Unknown mode of operation: %d\n",
912 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800913 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700914 }
915}
916
917/*
918 * start REPLY_TX command process
919 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800920static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700921{
922 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200923 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800924 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800925 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800926 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800927 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700928 dma_addr_t phys_addr;
929 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800930 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800931 u16 len, idx, len_org, hdr_len;
932 u8 id;
933 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700934 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800935 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700936 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700937 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700938 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800939 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700940 unsigned long flags;
941 int rc;
942
943 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800944 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800945 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700946 goto drop_unlock;
947 }
948
Johannes Berge039fa42008-05-15 12:55:29 +0200949 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800950 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700951 goto drop_unlock;
952 }
953
954 unicast = !is_multicast_ether_addr(hdr->addr1);
955 id = 0;
956
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700957 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700958
Samuel Ortizd08853a2009-01-23 13:45:17 -0800959#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700960 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800961 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700962 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800963 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700964 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800965 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700966#endif
967
Mohamed Abbas7878a5a2007-11-29 11:10:13 +0800968 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +0800969 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200970 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800971 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200972 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -0800973 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -0700974 goto drop_unlock;
975 }
976
977 spin_unlock_irqrestore(&priv->lock, flags);
978
Harvey Harrison7294ec92008-07-15 18:43:59 -0700979 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800980
981 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800982 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -0700983 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -0800984 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -0700985 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700986 goto drop;
987 }
988
Tomas Winklere1623442009-01-27 14:27:56 -0800989 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -0700990
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700991 if (ieee80211_is_data_qos(fc)) {
992 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -0700993 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800994 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -0700995 IEEE80211_SCTL_SEQ;
996 hdr->seq_ctrl = cpu_to_le16(seq_number) |
997 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800998 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -0700999 seq_number += 0x10;
1000 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001001
1002 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001003 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001004 q = &txq->q;
1005
1006 spin_lock_irqsave(&priv->lock, flags);
1007
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001008 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001009
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001010 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001011 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001012 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001013
1014 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001015 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001016 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001017 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001018 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001019
1020 /*
1021 * Set up the Tx-command (not MAC!) header.
1022 * Store the chosen Tx queue and TFD index within the sequence field;
1023 * after Tx, uCode's Tx response will return this value so driver can
1024 * locate the frame within the tx queue and do post-tx processing.
1025 */
Zhu Yib481de92007-09-25 17:54:57 -07001026 out_cmd->hdr.cmd = REPLY_TX;
1027 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001028 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001029
1030 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001031 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001032
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001033 /*
1034 * Use the first empty entry in this queue's command buffer array
1035 * to contain the Tx command and MAC header concatenated together
1036 * (payload data will be in another buffer).
1037 * Size of this varies, due to varying MAC header length.
1038 * If end is not dword aligned, we'll have 2 extra bytes at the end
1039 * of the MAC header (device reads on dword boundaries).
1040 * We'll tell device about this padding later.
1041 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001042 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001043 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001044
1045 len_org = len;
1046 len = (len + 3) & ~3;
1047
1048 if (len_org != len)
1049 len_org = 1;
1050 else
1051 len_org = 0;
1052
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001053 /* Physical address of this Tx command's header (not MAC header!),
1054 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001055 txcmd_phys = pci_map_single(priv->pci_dev,
1056 out_cmd, sizeof(struct iwl_cmd),
1057 PCI_DMA_TODEVICE);
1058 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1059 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1060 /* Add buffer containing Tx command and MAC(!) header to TFD's
1061 * first entry */
1062 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001063
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001064 /* Add buffer containing Tx command and MAC(!) header to TFD's
1065 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001066 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1067 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001068
Johannes Bergd0f09802008-07-29 11:32:07 +02001069 if (info->control.hw_key)
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08001070 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001071
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001072 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1073 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001074 len = skb->len - hdr_len;
1075 if (len) {
1076 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1077 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001078 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1079 phys_addr, len,
1080 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001081 }
1082
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001083 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001084 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001085 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001086
1087 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001088 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001089
1090 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001091 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001092
Winkler, Tomase52119c2008-12-22 11:31:19 +08001093 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1094 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001095
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001096 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001097 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001098 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001099 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001100 } else {
1101 wait_write_ptr = 1;
1102 txq->need_update = 0;
1103 }
1104
Winkler, Tomase52119c2008-12-22 11:31:19 +08001105 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001106
Winkler, Tomase52119c2008-12-22 11:31:19 +08001107 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001108 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001109
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001110 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001111 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001112 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001113 spin_unlock_irqrestore(&priv->lock, flags);
1114
1115 if (rc)
1116 return rc;
1117
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001118 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001119 && priv->mac80211_registered) {
1120 if (wait_write_ptr) {
1121 spin_lock_irqsave(&priv->lock, flags);
1122 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001123 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001124 spin_unlock_irqrestore(&priv->lock, flags);
1125 }
1126
Johannes Berge4e72fb2009-03-23 17:28:42 +01001127 iwl_stop_queue(priv, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001128 }
1129
1130 return 0;
1131
1132drop_unlock:
1133 spin_unlock_irqrestore(&priv->lock, flags);
1134drop:
1135 return -1;
1136}
1137
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001138#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001139
1140#include "iwl-spectrum.h"
1141
1142#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1143#define BEACON_TIME_MASK_HIGH 0xFF000000
1144#define TIME_UNIT 1024
1145
1146/*
1147 * extended beacon time format
1148 * time in usec will be changed into a 32-bit value in 8:24 format
1149 * the high 1 byte is the beacon counts
1150 * the lower 3 bytes is the time in usec within one beacon interval
1151 */
1152
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001153static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001154{
1155 u32 quot;
1156 u32 rem;
1157 u32 interval = beacon_interval * 1024;
1158
1159 if (!interval || !usec)
1160 return 0;
1161
1162 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1163 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1164
1165 return (quot << 24) + rem;
1166}
1167
1168/* base is usually what we get from ucode with each received frame,
1169 * the same as HW timer counter counting down
1170 */
1171
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001172static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001173{
1174 u32 base_low = base & BEACON_TIME_MASK_LOW;
1175 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1176 u32 interval = beacon_interval * TIME_UNIT;
1177 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1178 (addon & BEACON_TIME_MASK_HIGH);
1179
1180 if (base_low > addon_low)
1181 res += base_low - addon_low;
1182 else if (base_low < addon_low) {
1183 res += interval + base_low - addon_low;
1184 res += (1 << 24);
1185 } else
1186 res += (1 << 24);
1187
1188 return cpu_to_le32(res);
1189}
1190
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001191static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001192 struct ieee80211_measurement_params *params,
1193 u8 type)
1194{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001195 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001196 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08001197 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001198 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1199 .data = (void *)&spectrum,
1200 .meta.flags = CMD_WANT_SKB,
1201 };
1202 u32 add_time = le64_to_cpu(params->start_time);
1203 int rc;
1204 int spectrum_resp_status;
1205 int duration = le16_to_cpu(params->duration);
1206
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001207 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001208 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001209 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001210 le64_to_cpu(params->start_time) - priv->last_tsf,
1211 le16_to_cpu(priv->rxon_timing.beacon_interval));
1212
1213 memset(&spectrum, 0, sizeof(spectrum));
1214
1215 spectrum.channel_count = cpu_to_le16(1);
1216 spectrum.flags =
1217 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1218 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1219 cmd.len = sizeof(spectrum);
1220 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1221
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001222 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001223 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001224 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001225 add_time,
1226 le16_to_cpu(priv->rxon_timing.beacon_interval));
1227 else
1228 spectrum.start_time = 0;
1229
1230 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1231 spectrum.channels[0].channel = params->channel;
1232 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001233 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001234 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1235 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1236
Samuel Ortiz518099a2009-01-19 15:30:27 -08001237 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001238 if (rc)
1239 return rc;
1240
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001241 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001242 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001243 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001244 rc = -EIO;
1245 }
1246
1247 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1248 switch (spectrum_resp_status) {
1249 case 0: /* Command will be handled */
1250 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001251 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001252 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001253 priv->measurement_status &= ~MEASUREMENT_READY;
1254 }
1255 priv->measurement_status |= MEASUREMENT_ACTIVE;
1256 rc = 0;
1257 break;
1258
1259 case 1: /* Command will not be handled */
1260 rc = -EAGAIN;
1261 break;
1262 }
1263
1264 dev_kfree_skb_any(cmd.meta.u.skb);
1265
1266 return rc;
1267}
1268#endif
1269
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001270static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001271 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001272{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001273 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1274 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001275 struct delayed_work *pwork;
1276
1277 palive = &pkt->u.alive_frame;
1278
Tomas Winklere1623442009-01-27 14:27:56 -08001279 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001280 "0x%01X 0x%01X\n",
1281 palive->is_valid, palive->ver_type,
1282 palive->ver_subtype);
1283
1284 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001285 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001286 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1287 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001288 pwork = &priv->init_alive_start;
1289 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001290 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001291 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001292 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001293 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001294 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001295 }
1296
1297 /* We delay the ALIVE response by 5ms to
1298 * give the HW RF Kill time to activate... */
1299 if (palive->is_valid == UCODE_VALID_OK)
1300 queue_delayed_work(priv->workqueue, pwork,
1301 msecs_to_jiffies(5));
1302 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001303 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001304}
1305
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001306static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001307 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001308{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001309#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001310 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001311#endif
Zhu Yib481de92007-09-25 17:54:57 -07001312
Tomas Winklere1623442009-01-27 14:27:56 -08001313 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001314 return;
1315}
1316
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001317static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001318{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001319 struct iwl_priv *priv =
1320 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001321 struct sk_buff *beacon;
1322
1323 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001324 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001325
1326 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001327 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001328 return;
1329 }
1330
1331 mutex_lock(&priv->mutex);
1332 /* new beacon skb is allocated every time; dispose previous.*/
1333 if (priv->ibss_beacon)
1334 dev_kfree_skb(priv->ibss_beacon);
1335
1336 priv->ibss_beacon = beacon;
1337 mutex_unlock(&priv->mutex);
1338
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001339 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001340}
1341
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001342static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001343 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001344{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001345#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001346 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001347 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001348 u8 rate = beacon->beacon_notify_hdr.rate;
1349
Tomas Winklere1623442009-01-27 14:27:56 -08001350 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001351 "tsf %d %d rate %d\n",
1352 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1353 beacon->beacon_notify_hdr.failure_frame,
1354 le32_to_cpu(beacon->ibss_mgr_status),
1355 le32_to_cpu(beacon->high_tsf),
1356 le32_to_cpu(beacon->low_tsf), rate);
1357#endif
1358
Johannes Berg05c914f2008-09-11 00:01:58 +02001359 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001360 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1361 queue_work(priv->workqueue, &priv->beacon_update);
1362}
1363
Zhu Yib481de92007-09-25 17:54:57 -07001364/* Handle notification from uCode that card's power state is changing
1365 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001366static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001367 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001368{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001369 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001370 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1371 unsigned long status = priv->status;
1372
Tomas Winklere1623442009-01-27 14:27:56 -08001373 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001374 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1375 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1376
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001377 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001378 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1379
1380 if (flags & HW_CARD_DISABLED)
1381 set_bit(STATUS_RF_KILL_HW, &priv->status);
1382 else
1383 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1384
1385
1386 if (flags & SW_CARD_DISABLED)
1387 set_bit(STATUS_RF_KILL_SW, &priv->status);
1388 else
1389 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1390
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001391 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001392
1393 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1394 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1395 (test_bit(STATUS_RF_KILL_SW, &status) !=
1396 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1397 queue_work(priv->workqueue, &priv->rf_kill);
1398 else
1399 wake_up_interruptible(&priv->wait_command_queue);
1400}
1401
1402/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001403 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001404 *
1405 * Setup the RX handlers for each of the reply types sent from the uCode
1406 * to the host.
1407 *
1408 * This function chains into the hardware specific files for them to setup
1409 * any hardware specific handlers as well.
1410 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001411static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001412{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001413 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1414 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001415 priv->rx_handlers[REPLY_ERROR] = iwl_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001416 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001417 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001418 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001419 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001420 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001421
Ben Cahill9fbab512007-11-29 11:09:47 +08001422 /*
1423 * The same handler is used for both the REPLY to a discrete
1424 * statistics request from the host as well as for the periodic
1425 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001426 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001427 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1428 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001429
Abhijeet Kolekar261b9c32009-02-18 15:54:29 -08001430 iwl_setup_spectrum_handlers(priv);
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001431 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001432 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001433
Ben Cahill9fbab512007-11-29 11:09:47 +08001434 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001435 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001436}
1437
Zhu Yib481de92007-09-25 17:54:57 -07001438/************************** RX-FUNCTIONS ****************************/
1439/*
1440 * Rx theory of operation
1441 *
1442 * The host allocates 32 DMA target addresses and passes the host address
1443 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1444 * 0 to 31
1445 *
1446 * Rx Queue Indexes
1447 * The host/firmware share two index registers for managing the Rx buffers.
1448 *
1449 * The READ index maps to the first position that the firmware may be writing
1450 * to -- the driver can read up to (but not including) this position and get
1451 * good data.
1452 * The READ index is managed by the firmware once the card is enabled.
1453 *
1454 * The WRITE index maps to the last position the driver has read from -- the
1455 * position preceding WRITE is the last slot the firmware can place a packet.
1456 *
1457 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1458 * WRITE = READ.
1459 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001460 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001461 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1462 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001463 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001464 * and fire the RX interrupt. The driver can then query the READ index and
1465 * process as many packets as possible, moving the WRITE index forward as it
1466 * resets the Rx queue buffers with new memory.
1467 *
1468 * The management in the driver is as follows:
1469 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1470 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001471 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001472 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001473 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1474 * 'processed' and 'read' driver indexes as well)
1475 * + A received packet is processed and handed to the kernel network stack,
1476 * detached from the iwl->rxq. The driver 'processed' index is updated.
1477 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1478 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1479 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1480 * were enough free buffers and RX_STALLED is set it is cleared.
1481 *
1482 *
1483 * Driver sequence:
1484 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001485 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001486 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001487 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001488 * queue, updates firmware pointers, and updates
1489 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001490 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001491 *
1492 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001493 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001494 * READ INDEX, detaching the SKB from the pool.
1495 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001496 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001497 * slots.
1498 * ...
1499 *
1500 */
1501
1502/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001503 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001504 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001505static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001506 dma_addr_t dma_addr)
1507{
1508 return cpu_to_le32((u32)dma_addr);
1509}
1510
1511/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001512 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001513 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001514 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001515 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001516 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001517 *
1518 * This moves the 'write' index forward to catch up with 'processed', and
1519 * also updates the memory address in the firmware to reference the new
1520 * target buffer.
1521 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001522static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001523{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001524 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001525 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001526 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001527 unsigned long flags;
1528 int write, rc;
1529
1530 spin_lock_irqsave(&rxq->lock, flags);
1531 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001532 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001533 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001534 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001535 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001536 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001537
1538 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001539 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001540 rxq->queue[rxq->write] = rxb;
1541 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1542 rxq->free_count--;
1543 }
1544 spin_unlock_irqrestore(&rxq->lock, flags);
1545 /* If the pre-allocated buffer pool is dropping low, schedule to
1546 * refill it */
1547 if (rxq->free_count <= RX_LOW_WATERMARK)
1548 queue_work(priv->workqueue, &priv->rx_replenish);
1549
1550
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001551 /* If we've added more space for the firmware to place data, tell it.
1552 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001553 if ((write != (rxq->write & ~0x7))
1554 || (abs(rxq->write - rxq->read) > 7)) {
1555 spin_lock_irqsave(&rxq->lock, flags);
1556 rxq->need_update = 1;
1557 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001558 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001559 if (rc)
1560 return rc;
1561 }
1562
1563 return 0;
1564}
1565
1566/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001567 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001568 *
1569 * When moving to rx_free an SKB is allocated for the slot.
1570 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001571 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001572 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001573 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001574static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001575{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001576 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001577 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001578 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001579 unsigned long flags;
1580 spin_lock_irqsave(&rxq->lock, flags);
1581 while (!list_empty(&rxq->rx_used)) {
1582 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001583 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001584
1585 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001586 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001587 alloc_skb(priv->hw_params.rx_buf_size,
1588 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001589 if (!rxb->skb) {
1590 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001591 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001592 /* We don't reschedule replenish work here -- we will
1593 * call the restock method and if it still needs
1594 * more buffers it will schedule replenish */
1595 break;
1596 }
Zhu Yi12342c42007-12-20 11:27:32 +08001597
1598 /* If radiotap head is required, reserve some headroom here.
1599 * The physical head count is a variable rx_stats->phy_count.
1600 * We reserve 4 bytes here. Plus these extra bytes, the
1601 * headroom of the physical head should be enough for the
1602 * radiotap head that iwl3945 supported. See iwl3945_rt.
1603 */
1604 skb_reserve(rxb->skb, 4);
1605
Zhu Yib481de92007-09-25 17:54:57 -07001606 priv->alloc_rxb_skb++;
1607 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001608
1609 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001610 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1611 rxb->skb->data,
1612 priv->hw_params.rx_buf_size,
1613 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001614 list_add_tail(&rxb->list, &rxq->rx_free);
1615 rxq->free_count++;
1616 }
1617 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001618}
1619
1620/*
1621 * this should be called while priv->lock is locked
1622 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001623static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001624{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001625 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001626
1627 iwl3945_rx_allocate(priv);
1628 iwl3945_rx_queue_restock(priv);
1629}
1630
1631
1632void iwl3945_rx_replenish(void *data)
1633{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001634 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001635 unsigned long flags;
1636
1637 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001638
1639 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001640 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001641 spin_unlock_irqrestore(&priv->lock, flags);
1642}
1643
Zhu Yib481de92007-09-25 17:54:57 -07001644/* Convert linear signal-to-noise ratio into dB */
1645static u8 ratio2dB[100] = {
1646/* 0 1 2 3 4 5 6 7 8 9 */
1647 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1648 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1649 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1650 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1651 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1652 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1653 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1654 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1655 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1656 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1657};
1658
1659/* Calculates a relative dB value from a ratio of linear
1660 * (i.e. not dB) signal levels.
1661 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001662int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001663{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001664 /* 1000:1 or higher just report as 60 dB */
1665 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001666 return 60;
1667
Adrian Bunk221c80c2008-02-02 23:19:01 +02001668 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001669 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001670 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001671 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001672
1673 /* We shouldn't see this */
1674 if (sig_ratio < 1)
1675 return 0;
1676
1677 /* Use table for ratios 1:1 - 99:1 */
1678 return (int)ratio2dB[sig_ratio];
1679}
1680
1681#define PERFECT_RSSI (-20) /* dBm */
1682#define WORST_RSSI (-95) /* dBm */
1683#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1684
1685/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1686 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1687 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001688int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001689{
1690 int sig_qual;
1691 int degradation = PERFECT_RSSI - rssi_dbm;
1692
1693 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1694 * as indicator; formula is (signal dbm - noise dbm).
1695 * SNR at or above 40 is a great signal (100%).
1696 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1697 * Weakest usable signal is usually 10 - 15 dB SNR. */
1698 if (noise_dbm) {
1699 if (rssi_dbm - noise_dbm >= 40)
1700 return 100;
1701 else if (rssi_dbm < noise_dbm)
1702 return 0;
1703 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1704
1705 /* Else use just the signal level.
1706 * This formula is a least squares fit of data points collected and
1707 * compared with a reference system that had a percentage (%) display
1708 * for signal quality. */
1709 } else
1710 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1711 (15 * RSSI_RANGE + 62 * degradation)) /
1712 (RSSI_RANGE * RSSI_RANGE);
1713
1714 if (sig_qual > 100)
1715 sig_qual = 100;
1716 else if (sig_qual < 1)
1717 sig_qual = 0;
1718
1719 return sig_qual;
1720}
1721
1722/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001723 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001724 *
1725 * Uses the priv->rx_handlers callback function array to invoke
1726 * the appropriate handlers, including command responses,
1727 * frame-received notifications, and other notifications.
1728 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001729static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001730{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001731 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001732 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001733 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001734 u32 r, i;
1735 int reclaim;
1736 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001737 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001738 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001739
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001740 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1741 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001742 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001743 i = rxq->read;
1744
Winkler, Tomas37d68312009-01-08 10:19:54 -08001745 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001746 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001747 /* Rx interrupt, but nothing sent from uCode */
1748 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001749 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001750
1751 while (i != r) {
1752 rxb = rxq->queue[i];
1753
Ben Cahill9fbab512007-11-29 11:09:47 +08001754 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001755 * then a bug has been introduced in the queue refilling
1756 * routines -- catch it here */
1757 BUG_ON(rxb == NULL);
1758
1759 rxq->queue[i] = NULL;
1760
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001761 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001762 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001763 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001764 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001765
1766 /* Reclaim a command buffer only if this packet is a response
1767 * to a (driver-originated) command.
1768 * If the packet (e.g. Rx frame) originated from uCode,
1769 * there is no command buffer to reclaim.
1770 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1771 * but apparently a few don't get set; catch them here. */
1772 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1773 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1774 (pkt->hdr.cmd != REPLY_TX);
1775
1776 /* Based on type of command response or notification,
1777 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001778 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001779 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001780 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001781 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1782 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1783 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1784 } else {
1785 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001786 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001787 "r %d i %d No handler needed for %s, 0x%02x\n",
1788 r, i, get_cmd_string(pkt->hdr.cmd),
1789 pkt->hdr.cmd);
1790 }
1791
1792 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001793 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001794 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001795 * as we reclaim the driver command queue */
1796 if (rxb && rxb->skb)
Abhijeet Kolekar732587a2009-03-11 11:17:57 -07001797 iwl_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001798 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001799 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001800 }
1801
1802 /* For now we just don't re-use anything. We can tweak this
1803 * later to try and re-use notification packets and SKBs that
1804 * fail to Rx correctly */
1805 if (rxb->skb != NULL) {
1806 priv->alloc_rxb_skb--;
1807 dev_kfree_skb_any(rxb->skb);
1808 rxb->skb = NULL;
1809 }
1810
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001811 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001812 priv->hw_params.rx_buf_size,
1813 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001814 spin_lock_irqsave(&rxq->lock, flags);
1815 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1816 spin_unlock_irqrestore(&rxq->lock, flags);
1817 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001818 /* If there are a lot of unused frames,
1819 * restock the Rx queue so ucode won't assert. */
1820 if (fill_rx) {
1821 count++;
1822 if (count >= 8) {
1823 priv->rxq.read = i;
1824 __iwl3945_rx_replenish(priv);
1825 count = 0;
1826 }
1827 }
Zhu Yib481de92007-09-25 17:54:57 -07001828 }
1829
1830 /* Backtrack one entry */
1831 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001832 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001833}
1834
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001835/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001836static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001837{
Tomas Winklera96a27f2008-10-23 23:48:56 -07001838 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07001839 synchronize_irq(priv->pci_dev->irq);
1840 tasklet_kill(&priv->irq_tasklet);
1841}
1842
Zhu Yib481de92007-09-25 17:54:57 -07001843static const char *desc_lookup(int i)
1844{
1845 switch (i) {
1846 case 1:
1847 return "FAIL";
1848 case 2:
1849 return "BAD_PARAM";
1850 case 3:
1851 return "BAD_CHECKSUM";
1852 case 4:
1853 return "NMI_INTERRUPT";
1854 case 5:
1855 return "SYSASSERT";
1856 case 6:
1857 return "FATAL_ERROR";
1858 }
1859
1860 return "UNKNOWN";
1861}
1862
1863#define ERROR_START_OFFSET (1 * sizeof(u32))
1864#define ERROR_ELEM_SIZE (7 * sizeof(u32))
1865
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001866static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001867{
1868 u32 i;
1869 u32 desc, time, count, base, data1;
1870 u32 blink1, blink2, ilink1, ilink2;
1871 int rc;
1872
1873 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
1874
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001875 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001876 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001877 return;
1878 }
1879
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001880 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001881 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001882 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001883 return;
1884 }
1885
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001886 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07001887
1888 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001889 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
1890 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
1891 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07001892 }
1893
Winkler, Tomas15b16872008-12-19 10:37:33 +08001894 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07001895 "ilink1 nmiPC Line\n");
1896 for (i = ERROR_START_OFFSET;
1897 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
1898 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001899 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07001900 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001901 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001902 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001903 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001904 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001905 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001906 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001907 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001908 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001909 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001910 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001911 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07001912
Winkler, Tomas15b16872008-12-19 10:37:33 +08001913 IWL_ERR(priv,
1914 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
1915 desc_lookup(desc), desc, time, blink1, blink2,
1916 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07001917 }
1918
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001919 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001920
1921}
1922
Ben Cahillf58177b2007-11-29 11:09:43 +08001923#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07001924
1925/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001926 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07001927 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001928 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07001929 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001930static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07001931 u32 num_events, u32 mode)
1932{
1933 u32 i;
1934 u32 base; /* SRAM byte address of event log header */
1935 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
1936 u32 ptr; /* SRAM byte address of log data */
1937 u32 ev, time, data; /* event log data */
1938
1939 if (num_events == 0)
1940 return;
1941
1942 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
1943
1944 if (mode == 0)
1945 event_size = 2 * sizeof(u32);
1946 else
1947 event_size = 3 * sizeof(u32);
1948
1949 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
1950
1951 /* "time" is actually "data" for mode 0 (no timestamp).
1952 * place event id # at far right for easier visual parsing. */
1953 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001954 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001955 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001956 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001957 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001958 if (mode == 0) {
1959 /* data, ev */
1960 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
1961 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001962 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07001963 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08001964 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07001965 }
1966 }
1967}
1968
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001969static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001970{
1971 int rc;
1972 u32 base; /* SRAM byte address of event log header */
1973 u32 capacity; /* event log capacity in # entries */
1974 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
1975 u32 num_wraps; /* # times uCode wrapped to top of log */
1976 u32 next_entry; /* index of next entry to be written by uCode */
1977 u32 size; /* # entries that we'll print */
1978
1979 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001980 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001981 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07001982 return;
1983 }
1984
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001985 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001986 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001987 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001988 return;
1989 }
1990
1991 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001992 capacity = iwl_read_targ_mem(priv, base);
1993 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
1994 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
1995 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07001996
1997 size = num_wraps ? capacity : next_entry;
1998
1999 /* bail out if nothing in log */
2000 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002001 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002002 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002003 return;
2004 }
2005
Winkler, Tomas15b16872008-12-19 10:37:33 +08002006 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002007 size, num_wraps);
2008
2009 /* if uCode has wrapped back to top of log, start at the oldest entry,
2010 * i.e the next one that uCode would fill. */
2011 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002012 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002013 capacity - next_entry, mode);
2014
2015 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002016 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002017
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002018 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002019}
2020
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002021static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002022{
2023 unsigned long flags;
2024
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002025 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2026 sizeof(priv->staging_rxon));
2027 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002028 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002029
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002030 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002031
2032 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002033 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002034 priv->error_recovering = 0;
2035 spin_unlock_irqrestore(&priv->lock, flags);
2036}
2037
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002038static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002039{
2040 u32 inta, handled = 0;
2041 u32 inta_fh;
2042 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002043#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002044 u32 inta_mask;
2045#endif
2046
2047 spin_lock_irqsave(&priv->lock, flags);
2048
2049 /* Ack/clear/reset pending uCode interrupts.
2050 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2051 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002052 inta = iwl_read32(priv, CSR_INT);
2053 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002054
2055 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2056 * Any new interrupts that happen after this, either while we're
2057 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002058 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2059 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002060
Samuel Ortizd08853a2009-01-23 13:45:17 -08002061#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002062 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002063 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002064 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002065 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002066 inta, inta_mask, inta_fh);
2067 }
2068#endif
2069
2070 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2071 * atomic, make sure that inta covers all the interrupts that
2072 * we've discovered, even if FH interrupt came in just after
2073 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002074 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002075 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002076 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002077 inta |= CSR_INT_BIT_FH_TX;
2078
2079 /* Now service all interrupt bits discovered above. */
2080 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002081 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002082
2083 /* Tell the device to stop sending interrupts */
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002084 iwl_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002085
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002086 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002087
2088 handled |= CSR_INT_BIT_HW_ERR;
2089
2090 spin_unlock_irqrestore(&priv->lock, flags);
2091
2092 return;
2093 }
2094
Samuel Ortizd08853a2009-01-23 13:45:17 -08002095#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002096 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002097 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002098 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002099 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002100 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002101
2102 /* Alive notification via Rx interrupt will do the real work */
2103 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002104 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002105 }
2106#endif
2107 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002108 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002109
Zhu Yib481de92007-09-25 17:54:57 -07002110 /* Error detected by uCode */
2111 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002112 IWL_ERR(priv, "Microcode SW error detected. "
2113 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002114 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002115 handled |= CSR_INT_BIT_SW_ERR;
2116 }
2117
2118 /* uCode wakes up after power-down sleep */
2119 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002120 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002121 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002122 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2123 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2124 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2125 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2126 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2127 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002128
2129 handled |= CSR_INT_BIT_WAKEUP;
2130 }
2131
2132 /* All uCode command responses, including Tx command responses,
2133 * Rx "responses" (frame-received notification), and other
2134 * notifications from uCode come through here*/
2135 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002136 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002137 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2138 }
2139
2140 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002141 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002142
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002143 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2144 if (!iwl_grab_nic_access(priv)) {
2145 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002146 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002147 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002148 }
2149 handled |= CSR_INT_BIT_FH_TX;
2150 }
2151
2152 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002153 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002154
2155 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002156 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002157 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002158 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002159 }
2160
2161 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002162 /* only Re-enable if disabled by irq */
2163 if (test_bit(STATUS_INT_ENABLED, &priv->status))
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002164 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002165
Samuel Ortizd08853a2009-01-23 13:45:17 -08002166#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002167 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002168 inta = iwl_read32(priv, CSR_INT);
2169 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2170 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002171 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002172 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2173 }
2174#endif
2175 spin_unlock_irqrestore(&priv->lock, flags);
2176}
2177
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002178static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002179 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002180 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002181 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002182{
2183 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002184 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002185 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002186 u16 passive_dwell = 0;
2187 u16 active_dwell = 0;
2188 int added, i;
2189
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002190 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002191 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002192 return 0;
2193
Johannes Berg8318d782008-01-24 19:38:38 +01002194 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002195
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002196 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2197 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002198
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002199 if (passive_dwell <= active_dwell)
2200 passive_dwell = active_dwell + 1;
2201
Johannes Berg8318d782008-01-24 19:38:38 +01002202 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002203 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2204 continue;
2205
Johannes Berg8318d782008-01-24 19:38:38 +01002206 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002207
Samuel Ortize6148912009-01-23 13:45:15 -08002208 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002209 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002210 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002211 scan_ch->channel);
2212 continue;
2213 }
2214
Zhu Yib481de92007-09-25 17:54:57 -07002215 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2216 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002217 /* If passive , set up for auto-switch
2218 * and use long active_dwell time.
2219 */
2220 if (!is_active || is_channel_passive(ch_info) ||
2221 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2222 scan_ch->type = 0; /* passive */
2223 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2224 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2225 } else {
2226 scan_ch->type = 1; /* active */
2227 }
2228
2229 /* Set direct probe bits. These may be used both for active
2230 * scan channels (probes gets sent right away),
2231 * or for passive channels (probes get se sent only after
2232 * hearing clear Rx packet).*/
2233 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2234 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002235 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002236 } else {
2237 /* uCode v1 does not allow setting direct probe bits on
2238 * passive channel. */
2239 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002240 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002241 }
Zhu Yib481de92007-09-25 17:54:57 -07002242
Ben Cahill9fbab512007-11-29 11:09:47 +08002243 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002244 scan_ch->tpc.dsp_atten = 110;
2245 /* scan_pwr_info->tpc.dsp_atten; */
2246
2247 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002248 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002249 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2250 else {
2251 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2252 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002253 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002254 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002255 */
2256 }
2257
Tomas Winklere1623442009-01-27 14:27:56 -08002258 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002259 scan_ch->channel,
2260 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2261 (scan_ch->type & 1) ?
2262 active_dwell : passive_dwell);
2263
2264 scan_ch++;
2265 added++;
2266 }
2267
Tomas Winklere1623442009-01-27 14:27:56 -08002268 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002269 return added;
2270}
2271
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002272static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002273 struct ieee80211_rate *rates)
2274{
2275 int i;
2276
2277 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002278 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2279 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2280 rates[i].hw_value_short = i;
2281 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002282 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002283 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002284 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002285 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002286 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002287 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002288 }
Zhu Yib481de92007-09-25 17:54:57 -07002289 }
2290}
2291
Zhu Yib481de92007-09-25 17:54:57 -07002292/******************************************************************************
2293 *
2294 * uCode download functions
2295 *
2296 ******************************************************************************/
2297
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002298static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002299{
Tomas Winkler98c92212008-01-14 17:46:20 -08002300 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2301 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2302 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2303 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2304 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2305 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002306}
2307
2308/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002309 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002310 * looking at all data.
2311 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002312static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002313{
2314 u32 val;
2315 u32 save_len = len;
2316 int rc = 0;
2317 u32 errcnt;
2318
Tomas Winklere1623442009-01-27 14:27:56 -08002319 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002320
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002321 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002322 if (rc)
2323 return rc;
2324
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002325 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002326 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002327
2328 errcnt = 0;
2329 for (; len > 0; len -= sizeof(u32), image++) {
2330 /* read data comes through single port, auto-incr addr */
2331 /* NOTE: Use the debugless read so we don't flood kernel log
2332 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002333 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002334 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002335 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002336 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2337 save_len - len, val, le32_to_cpu(*image));
2338 rc = -EIO;
2339 errcnt++;
2340 if (errcnt >= 20)
2341 break;
2342 }
2343 }
2344
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002345 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002346
2347 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002348 IWL_DEBUG_INFO(priv,
2349 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002350
2351 return rc;
2352}
2353
2354
2355/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002356 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002357 * using sample data 100 bytes apart. If these sample points are good,
2358 * it's a pretty good bet that everything between them is good, too.
2359 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002360static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002361{
2362 u32 val;
2363 int rc = 0;
2364 u32 errcnt = 0;
2365 u32 i;
2366
Tomas Winklere1623442009-01-27 14:27:56 -08002367 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002368
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002369 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002370 if (rc)
2371 return rc;
2372
2373 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2374 /* read data comes through single port, auto-incr addr */
2375 /* NOTE: Use the debugless read so we don't flood kernel log
2376 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002377 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002378 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002379 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002380 if (val != le32_to_cpu(*image)) {
2381#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002382 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002383 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2384 i, val, *image);
2385#endif
2386 rc = -EIO;
2387 errcnt++;
2388 if (errcnt >= 3)
2389 break;
2390 }
2391 }
2392
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002393 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002394
2395 return rc;
2396}
2397
2398
2399/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002400 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002401 * and verify its contents
2402 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002403static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002404{
2405 __le32 *image;
2406 u32 len;
2407 int rc = 0;
2408
2409 /* Try bootstrap */
2410 image = (__le32 *)priv->ucode_boot.v_addr;
2411 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002412 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002413 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002414 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002415 return 0;
2416 }
2417
2418 /* Try initialize */
2419 image = (__le32 *)priv->ucode_init.v_addr;
2420 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002421 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002422 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002423 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002424 return 0;
2425 }
2426
2427 /* Try runtime/protocol */
2428 image = (__le32 *)priv->ucode_code.v_addr;
2429 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002430 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002431 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002432 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002433 return 0;
2434 }
2435
Winkler, Tomas15b16872008-12-19 10:37:33 +08002436 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002437
Ben Cahill9fbab512007-11-29 11:09:47 +08002438 /* Since nothing seems to match, show first several data entries in
2439 * instruction SRAM, so maybe visual inspection will give a clue.
2440 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002441 image = (__le32 *)priv->ucode_boot.v_addr;
2442 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002443 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002444
2445 return rc;
2446}
2447
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002448static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002449{
2450 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002451 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002452}
2453
2454/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002455 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002456 *
2457 * Copy into buffers for card to fetch via bus-mastering
2458 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002459static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002460{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002461 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002462 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002463 const struct firmware *ucode_raw;
2464 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002465 const char *name_pre = priv->cfg->fw_name_pre;
2466 const unsigned int api_max = priv->cfg->ucode_api_max;
2467 const unsigned int api_min = priv->cfg->ucode_api_min;
2468 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002469 u8 *src;
2470 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002471 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002472
2473 /* Ask kernel firmware_class module to get the boot firmware off disk.
2474 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002475 for (index = api_max; index >= api_min; index--) {
2476 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2477 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2478 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002479 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002480 buf, ret);
2481 if (ret == -ENOENT)
2482 continue;
2483 else
2484 goto error;
2485 } else {
2486 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002487 IWL_ERR(priv, "Loaded firmware %s, "
2488 "which is deprecated. "
2489 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002490 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002491 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2492 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002493 buf, ucode_raw->size);
2494 break;
2495 }
Zhu Yib481de92007-09-25 17:54:57 -07002496 }
2497
Reinette Chatrea0987a82008-12-02 12:14:06 -08002498 if (ret < 0)
2499 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002500
2501 /* Make sure that we got at least our header! */
2502 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002503 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002504 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002505 goto err_release;
2506 }
2507
2508 /* Data from ucode file: header followed by uCode images */
2509 ucode = (void *)ucode_raw->data;
2510
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002511 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002512 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002513 inst_size = le32_to_cpu(ucode->inst_size);
2514 data_size = le32_to_cpu(ucode->data_size);
2515 init_size = le32_to_cpu(ucode->init_size);
2516 init_data_size = le32_to_cpu(ucode->init_data_size);
2517 boot_size = le32_to_cpu(ucode->boot_size);
2518
Reinette Chatrea0987a82008-12-02 12:14:06 -08002519 /* api_ver should match the api version forming part of the
2520 * firmware filename ... but we don't check for that and only rely
Nick Andrew877d0312009-01-26 11:06:57 +01002521 * on the API version read from firmware header from here on forward */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002522
2523 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002524 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002525 "Driver supports v%u, firmware is v%u.\n",
2526 api_max, api_ver);
2527 priv->ucode_ver = 0;
2528 ret = -EINVAL;
2529 goto err_release;
2530 }
2531 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002532 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002533 "got %u. New firmware can be obtained "
2534 "from http://www.intellinuxwireless.org.\n",
2535 api_max, api_ver);
2536
Tomas Winkler978785a2008-12-19 10:37:31 +08002537 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2538 IWL_UCODE_MAJOR(priv->ucode_ver),
2539 IWL_UCODE_MINOR(priv->ucode_ver),
2540 IWL_UCODE_API(priv->ucode_ver),
2541 IWL_UCODE_SERIAL(priv->ucode_ver));
2542
Tomas Winklere1623442009-01-27 14:27:56 -08002543 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002544 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002545 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2546 inst_size);
2547 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2548 data_size);
2549 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2550 init_size);
2551 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2552 init_data_size);
2553 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2554 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002555
Reinette Chatrea0987a82008-12-02 12:14:06 -08002556
Zhu Yib481de92007-09-25 17:54:57 -07002557 /* Verify size of file vs. image size info in file's header */
2558 if (ucode_raw->size < sizeof(*ucode) +
2559 inst_size + data_size + init_size +
2560 init_data_size + boot_size) {
2561
Tomas Winklere1623442009-01-27 14:27:56 -08002562 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2563 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002564 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002565 goto err_release;
2566 }
2567
2568 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002569 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002570 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002571 inst_size);
2572 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002573 goto err_release;
2574 }
2575
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002576 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002577 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002578 data_size);
2579 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002580 goto err_release;
2581 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002582 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002583 IWL_DEBUG_INFO(priv,
2584 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002585 init_size);
2586 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002587 goto err_release;
2588 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002589 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002590 IWL_DEBUG_INFO(priv,
2591 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002592 init_data_size);
2593 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002594 goto err_release;
2595 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002596 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002597 IWL_DEBUG_INFO(priv,
2598 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002599 boot_size);
2600 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002601 goto err_release;
2602 }
2603
2604 /* Allocate ucode buffers for card's bus-master loading ... */
2605
2606 /* Runtime instructions and 2 copies of data:
2607 * 1) unmodified from disk
2608 * 2) backup cache for save/restore during power-downs */
2609 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002610 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002611
2612 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002613 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002614
2615 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002616 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002617
2618 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002619 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002620 goto err_pci_alloc;
2621
Tomas Winkler90e759d2007-11-29 11:09:41 +08002622 /* Initialization instructions and data */
2623 if (init_size && init_data_size) {
2624 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002625 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002626
2627 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002628 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002629
2630 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2631 goto err_pci_alloc;
2632 }
2633
2634 /* Bootstrap (instructions only, no data) */
2635 if (boot_size) {
2636 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002637 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002638
2639 if (!priv->ucode_boot.v_addr)
2640 goto err_pci_alloc;
2641 }
2642
Zhu Yib481de92007-09-25 17:54:57 -07002643 /* Copy images into buffers for card's bus-master reads ... */
2644
2645 /* Runtime instructions (first block of data in file) */
2646 src = &ucode->data[0];
2647 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002648 IWL_DEBUG_INFO(priv,
2649 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002650 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002651 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002652 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2653
2654 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002655 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002656 src = &ucode->data[inst_size];
2657 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002658 IWL_DEBUG_INFO(priv,
2659 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002660 memcpy(priv->ucode_data.v_addr, src, len);
2661 memcpy(priv->ucode_data_backup.v_addr, src, len);
2662
2663 /* Initialization instructions (3rd block) */
2664 if (init_size) {
2665 src = &ucode->data[inst_size + data_size];
2666 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002667 IWL_DEBUG_INFO(priv,
2668 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002669 memcpy(priv->ucode_init.v_addr, src, len);
2670 }
2671
2672 /* Initialization data (4th block) */
2673 if (init_data_size) {
2674 src = &ucode->data[inst_size + data_size + init_size];
2675 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002676 IWL_DEBUG_INFO(priv,
2677 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002678 memcpy(priv->ucode_init_data.v_addr, src, len);
2679 }
2680
2681 /* Bootstrap instructions (5th block) */
2682 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2683 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002684 IWL_DEBUG_INFO(priv,
2685 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002686 memcpy(priv->ucode_boot.v_addr, src, len);
2687
2688 /* We have our copies now, allow OS release its copies */
2689 release_firmware(ucode_raw);
2690 return 0;
2691
2692 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002693 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002694 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002695 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002696
2697 err_release:
2698 release_firmware(ucode_raw);
2699
2700 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002701 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002702}
2703
2704
2705/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002706 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002707 *
2708 * Tell initialization uCode where to find runtime uCode.
2709 *
2710 * BSM registers initially contain pointers to initialization uCode.
2711 * We need to replace them to load runtime uCode inst and data,
2712 * and to save runtime data when powering down.
2713 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002714static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002715{
2716 dma_addr_t pinst;
2717 dma_addr_t pdata;
2718 int rc = 0;
2719 unsigned long flags;
2720
2721 /* bits 31:0 for 3945 */
2722 pinst = priv->ucode_code.p_addr;
2723 pdata = priv->ucode_data_backup.p_addr;
2724
2725 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002726 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002727 if (rc) {
2728 spin_unlock_irqrestore(&priv->lock, flags);
2729 return rc;
2730 }
2731
2732 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002733 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2734 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2735 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002736 priv->ucode_data.len);
2737
Tomas Winklera96a27f2008-10-23 23:48:56 -07002738 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07002739 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002740 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002741 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
2742
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002743 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002744
2745 spin_unlock_irqrestore(&priv->lock, flags);
2746
Tomas Winklere1623442009-01-27 14:27:56 -08002747 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002748
2749 return rc;
2750}
2751
2752/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002753 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002754 *
2755 * Called after REPLY_ALIVE notification received from "initialize" uCode.
2756 *
Zhu Yib481de92007-09-25 17:54:57 -07002757 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08002758 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002759static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002760{
2761 /* Check alive response for "valid" sign from uCode */
2762 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
2763 /* We had an error bringing up the hardware, so take it
2764 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002765 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002766 goto restart;
2767 }
2768
2769 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
2770 * This is a paranoid check, because we would not have gotten the
2771 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002772 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002773 /* Runtime instruction load was bad;
2774 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002775 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002776 goto restart;
2777 }
2778
2779 /* Send pointers to protocol/runtime uCode image ... init code will
2780 * load and launch runtime uCode, which will send us another "Alive"
2781 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08002782 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002783 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002784 /* Runtime instruction load won't happen;
2785 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002786 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002787 goto restart;
2788 }
2789 return;
2790
2791 restart:
2792 queue_work(priv->workqueue, &priv->restart);
2793}
2794
Zhu Yib481de92007-09-25 17:54:57 -07002795/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002796 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07002797 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002798 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07002799 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002800static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002801{
2802 int rc = 0;
2803 int thermal_spin = 0;
2804 u32 rfkill;
2805
Tomas Winklere1623442009-01-27 14:27:56 -08002806 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002807
2808 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
2809 /* We had an error bringing up the hardware, so take it
2810 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002811 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002812 goto restart;
2813 }
2814
2815 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
2816 * This is a paranoid check, because we would not have gotten the
2817 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002818 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002819 /* Runtime instruction load was bad;
2820 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08002821 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002822 goto restart;
2823 }
2824
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002825 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002826
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002827 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002828 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002829 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07002830 return;
2831 }
2832
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002833 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08002834 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002835 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002836
2837 if (rfkill & 0x1) {
2838 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07002839 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07002840 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002841 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07002842 thermal_spin++;
2843 udelay(10);
2844 }
2845
2846 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08002847 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07002848 thermal_spin * 10);
2849 } else
2850 set_bit(STATUS_RF_KILL_HW, &priv->status);
2851
Ben Cahill9fbab512007-11-29 11:09:47 +08002852 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07002853 set_bit(STATUS_ALIVE, &priv->status);
2854
2855 /* Clear out the uCode error bit if it is set */
2856 clear_bit(STATUS_FW_ERROR, &priv->status);
2857
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002858 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07002859 return;
2860
Johannes Berg36d68252008-05-15 12:55:26 +02002861 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07002862
2863 priv->active_rate = priv->rates_mask;
2864 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
2865
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08002866 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07002867
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002868 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002869 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002870 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07002871
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002872 memcpy(&priv->staging_rxon, &priv->active_rxon,
2873 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07002874 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
2875 } else {
2876 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002877 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07002878 }
2879
Ben Cahill9fbab512007-11-29 11:09:47 +08002880 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08002881 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002882
2883 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002884 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002885
Zhu Yib481de92007-09-25 17:54:57 -07002886 iwl3945_reg_txpower_periodic(priv);
2887
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07002888 iwl3945_led_register(priv);
2889
Tomas Winklere1623442009-01-27 14:27:56 -08002890 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07002891 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a669262008-01-14 17:46:18 -08002892 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07002893
2894 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002895 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002896
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002897 /* reassociate for ADHOC mode */
2898 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
2899 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
2900 priv->vif);
2901 if (beacon)
Abhijeet Kolekar9944b932009-04-08 11:26:36 -07002902 iwl_mac_beacon_update(priv->hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08002903 }
2904
Zhu Yib481de92007-09-25 17:54:57 -07002905 return;
2906
2907 restart:
2908 queue_work(priv->workqueue, &priv->restart);
2909}
2910
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002911static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07002912
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002913static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002914{
2915 unsigned long flags;
2916 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
2917 struct ieee80211_conf *conf = NULL;
2918
Tomas Winklere1623442009-01-27 14:27:56 -08002919 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07002920
2921 conf = ieee80211_get_hw_conf(priv->hw);
2922
2923 if (!exit_pending)
2924 set_bit(STATUS_EXIT_PENDING, &priv->status);
2925
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07002926 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002927 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002928
2929 /* Unblock any waiting calls */
2930 wake_up_interruptible_all(&priv->wait_command_queue);
2931
Zhu Yib481de92007-09-25 17:54:57 -07002932 /* Wipe out the EXIT_PENDING status bit if we are not actually
2933 * exiting the module */
2934 if (!exit_pending)
2935 clear_bit(STATUS_EXIT_PENDING, &priv->status);
2936
2937 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002938 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07002939
2940 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002941 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08002942 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002943 spin_unlock_irqrestore(&priv->lock, flags);
2944 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002945
2946 if (priv->mac80211_registered)
2947 ieee80211_stop_queues(priv->hw);
2948
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002949 /* If we have not previously called iwl3945_init() then
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002950 * clear all bits but the RF Kill bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08002951 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07002952 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2953 STATUS_RF_KILL_HW |
2954 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2955 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002956 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2957 STATUS_GEO_CONFIGURED |
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002958 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2959 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002960 goto exit;
2961 }
2962
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002963 /* ...otherwise clear out all the status bits but the RF Kill
2964 * bits and continue taking the NIC down. */
Zhu Yib481de92007-09-25 17:54:57 -07002965 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
2966 STATUS_RF_KILL_HW |
2967 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
2968 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08002969 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
2970 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07002971 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08002972 STATUS_FW_ERROR |
2973 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
2974 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07002975
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002976 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002977 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002978 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07002979 spin_unlock_irqrestore(&priv->lock, flags);
2980
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002981 iwl3945_hw_txq_ctx_stop(priv);
2982 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002983
2984 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002985 if (!iwl_grab_nic_access(priv)) {
2986 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002987 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002988 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002989 }
2990 spin_unlock_irqrestore(&priv->lock, flags);
2991
2992 udelay(5);
2993
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07002994 if (exit_pending)
Abbas, Mohamede9414b62009-01-20 21:33:55 -08002995 priv->cfg->ops->lib->apm_ops.stop(priv);
2996 else
2997 priv->cfg->ops->lib->apm_ops.reset(priv);
2998
Zhu Yib481de92007-09-25 17:54:57 -07002999 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003000 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003001
3002 if (priv->ibss_beacon)
3003 dev_kfree_skb(priv->ibss_beacon);
3004 priv->ibss_beacon = NULL;
3005
3006 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003007 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003008}
3009
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003010static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003011{
3012 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003013 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003014 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003015
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003016 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003017}
3018
3019#define MAX_HW_RESTARTS 5
3020
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003021static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003022{
3023 int rc, i;
3024
3025 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003026 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003027 return -EIO;
3028 }
3029
3030 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003031 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003032 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003033 return -ENODEV;
3034 }
3035
Reinette Chatree903fbd2008-01-30 22:05:15 -08003036 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003037 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003038 return -EIO;
3039 }
3040
Zhu Yie655b9f2008-01-24 02:19:38 -08003041 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003042 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003043 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3044 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3045 else {
3046 set_bit(STATUS_RF_KILL_HW, &priv->status);
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07003047 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
3048 return -ENODEV;
Zhu Yib481de92007-09-25 17:54:57 -07003049 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003050
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003051 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003052
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003053 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003054 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003055 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003056 return rc;
3057 }
3058
3059 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003060 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3061 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003062 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3063
3064 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003065 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08003066 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003067
3068 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003069 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3070 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003071
3072 /* Copy original ucode data image from disk into backup cache.
3073 * This will be used to initialize the on-board processor's
3074 * data SRAM for a clean start when the runtime program first loads. */
3075 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a669262008-01-14 17:46:18 -08003076 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003077
Zhu Yie655b9f2008-01-24 02:19:38 -08003078 /* We return success when we resume from suspend and rf_kill is on. */
3079 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3080 return 0;
3081
Zhu Yib481de92007-09-25 17:54:57 -07003082 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3083
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003084 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003085
3086 /* load bootstrap state machine,
3087 * load bootstrap program into processor's memory,
3088 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003089 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003090
3091 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003092 IWL_ERR(priv,
3093 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003094 continue;
3095 }
3096
3097 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003098 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003099
Tomas Winklere1623442009-01-27 14:27:56 -08003100 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003101
3102 return 0;
3103 }
3104
3105 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003106 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003107 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003108
3109 /* tried to restart and config the device for as long as our
3110 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003111 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003112 return -EIO;
3113}
3114
3115
3116/*****************************************************************************
3117 *
3118 * Workqueue callbacks
3119 *
3120 *****************************************************************************/
3121
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003122static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003123{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003124 struct iwl_priv *priv =
3125 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003126
3127 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3128 return;
3129
3130 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003131 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003132 mutex_unlock(&priv->mutex);
3133}
3134
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003135static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003136{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003137 struct iwl_priv *priv =
3138 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003139
3140 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3141 return;
3142
3143 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003144 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003145 mutex_unlock(&priv->mutex);
3146}
3147
Helmut Schaa26635162009-01-15 09:38:44 +01003148static void iwl3945_rfkill_poll(struct work_struct *data)
3149{
3150 struct iwl_priv *priv =
3151 container_of(data, struct iwl_priv, rfkill_poll.work);
3152 unsigned long status = priv->status;
3153
3154 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3155 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3156 else
3157 set_bit(STATUS_RF_KILL_HW, &priv->status);
3158
3159 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3160 queue_work(priv->workqueue, &priv->rf_kill);
3161
3162 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3163 round_jiffies_relative(2 * HZ));
3164
3165}
3166
Zhu Yib481de92007-09-25 17:54:57 -07003167#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003168static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003169{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003170 struct iwl_priv *priv =
3171 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b42008-12-19 10:37:34 +08003172 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003173 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003174 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003175 .meta.flags = CMD_SIZE_HUGE,
3176 };
3177 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003178 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003179 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003180 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003181 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003182 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003183
3184 conf = ieee80211_get_hw_conf(priv->hw);
3185
3186 mutex_lock(&priv->mutex);
3187
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003188 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003189 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003190 goto done;
3191 }
3192
Tomas Winklera96a27f2008-10-23 23:48:56 -07003193 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003194 * was given the chance to run... */
3195 if (!test_bit(STATUS_SCANNING, &priv->status))
3196 goto done;
3197
3198 /* This should never be called or scheduled if there is currently
3199 * a scan active in the hardware. */
3200 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003201 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3202 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003203 rc = -EIO;
3204 goto done;
3205 }
3206
3207 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003208 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003209 goto done;
3210 }
3211
3212 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003213 IWL_DEBUG_HC(priv,
3214 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003215 goto done;
3216 }
3217
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003218 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003219 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003220 goto done;
3221 }
3222
3223 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003224 IWL_DEBUG_HC(priv,
3225 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003226 goto done;
3227 }
3228
3229 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003230 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003231 goto done;
3232 }
3233
Winkler, Tomas805cee52009-01-19 15:30:28 -08003234 if (!priv->scan) {
3235 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003236 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003237 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003238 rc = -ENOMEM;
3239 goto done;
3240 }
3241 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003242 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003243 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003244
3245 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3246 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3247
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003248 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003249 u16 interval = 0;
3250 u32 extra;
3251 u32 suspend_time = 100;
3252 u32 scan_suspend_time = 100;
3253 unsigned long flags;
3254
Tomas Winklere1623442009-01-27 14:27:56 -08003255 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003256
3257 spin_lock_irqsave(&priv->lock, flags);
3258 interval = priv->beacon_int;
3259 spin_unlock_irqrestore(&priv->lock, flags);
3260
3261 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003262 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003263 if (!interval)
3264 interval = suspend_time;
3265 /*
3266 * suspend time format:
3267 * 0-19: beacon interval in usec (time before exec.)
3268 * 20-23: 0
3269 * 24-31: number of beacons (suspend between channels)
3270 */
3271
3272 extra = (suspend_time / interval) << 24;
3273 scan_suspend_time = 0xFF0FFFFF &
3274 (extra | ((suspend_time % interval) * 1024));
3275
3276 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003277 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003278 scan_suspend_time, interval);
3279 }
3280
3281 /* We should add the ability for user to lock to PASSIVE ONLY */
3282 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003283 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3284 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003285 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003286 scan->direct_scan[0].id = WLAN_EID_SSID;
3287 scan->direct_scan[0].len = priv->direct_ssid_len;
3288 memcpy(scan->direct_scan[0].ssid,
3289 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003290 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003291 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003292 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003293
3294 /* We don't build a direct scan probe request; the uCode will do
3295 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003296 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003297 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003298 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3299
3300 /* flags + rate selection */
3301
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003302 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003303 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3304 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3305 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003306 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003307 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003308 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3309 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003310 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003311 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003312 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003313 goto done;
3314 }
3315
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003316 scan->tx_cmd.len = cpu_to_le16(
3317 iwl_fill_probe_req(priv, band,
3318 (struct ieee80211_mgmt *)scan->data,
3319 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3320
Zhu Yib481de92007-09-25 17:54:57 -07003321 /* select Rx antennas */
3322 scan->flags |= iwl3945_get_antenna_flags(priv);
3323
Johannes Berg05c914f2008-09-11 00:01:58 +02003324 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003325 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3326
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003327 scan->channel_count =
3328 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3329 n_probes,
3330 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003331
Reinette Chatre14b54332008-11-04 12:21:35 -08003332 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003333 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003334 goto done;
3335 }
3336
Zhu Yib481de92007-09-25 17:54:57 -07003337 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003338 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003339 cmd.data = scan;
3340 scan->len = cpu_to_le16(cmd.len);
3341
3342 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003343 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003344 if (rc)
3345 goto done;
3346
3347 queue_delayed_work(priv->workqueue, &priv->scan_check,
3348 IWL_SCAN_CHECK_WATCHDOG);
3349
3350 mutex_unlock(&priv->mutex);
3351 return;
3352
3353 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003354 /* can not perform scan make sure we clear scanning
3355 * bits from status so next scan request can be performed.
3356 * if we dont clear scanning status bit here all next scan
3357 * will fail
3358 */
3359 clear_bit(STATUS_SCAN_HW, &priv->status);
3360 clear_bit(STATUS_SCANNING, &priv->status);
3361
Ian Schram01ebd062007-10-25 17:15:22 +08003362 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003363 queue_work(priv->workqueue, &priv->scan_completed);
3364 mutex_unlock(&priv->mutex);
3365}
3366
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003367static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003368{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003369 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003370
3371 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3372 return;
3373
3374 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003375 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003376 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003377 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003378}
3379
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003380static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003381{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003382 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003383
3384 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3385 return;
3386
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003387 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003388 queue_work(priv->workqueue, &priv->up);
3389}
3390
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003391static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003392{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003393 struct iwl_priv *priv =
3394 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003395
3396 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3397 return;
3398
3399 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003400 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003401 mutex_unlock(&priv->mutex);
3402}
3403
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003404static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
3405
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003406#define IWL_DELAY_NEXT_SCAN (HZ*2)
3407
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07003408void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003409{
Zhu Yib481de92007-09-25 17:54:57 -07003410 int rc = 0;
3411 struct ieee80211_conf *conf = NULL;
3412
Johannes Berg05c914f2008-09-11 00:01:58 +02003413 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003414 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003415 return;
3416 }
3417
3418
Tomas Winklere1623442009-01-27 14:27:56 -08003419 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003420 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003421
3422 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3423 return;
3424
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003425 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003426 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003427
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003428 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003429
Zhu Yib481de92007-09-25 17:54:57 -07003430 conf = ieee80211_get_hw_conf(priv->hw);
3431
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003432 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003433 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003434
Tomas Winkler28afaf92008-12-19 10:37:06 +08003435 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003436 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003437 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003438 sizeof(priv->rxon_timing), &priv->rxon_timing);
3439 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003440 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003441 "Attempting to continue.\n");
3442
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003443 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003444
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003445 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003446
Tomas Winklere1623442009-01-27 14:27:56 -08003447 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003448 priv->assoc_id, priv->beacon_int);
3449
3450 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003451 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003452 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003453 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003454
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003455 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003456 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003457 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003458 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003459 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003460
Johannes Berg05c914f2008-09-11 00:01:58 +02003461 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003462 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003463
3464 }
3465
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003466 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003467
3468 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003469 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003470 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003471 break;
3472
Johannes Berg05c914f2008-09-11 00:01:58 +02003473 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003474
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003475 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003476 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003477 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003478 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003479 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3480 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003481 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3482 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003483
3484 break;
3485
3486 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003487 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003488 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003489 break;
3490 }
3491
Abhijeet Kolekar14d2aac2009-02-27 16:21:24 -08003492 iwl_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003493
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003494 /* we have just associated, don't start scan too early */
3495 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003496}
3497
Zhu Yib481de92007-09-25 17:54:57 -07003498/*****************************************************************************
3499 *
3500 * mac80211 entry point functions
3501 *
3502 *****************************************************************************/
3503
Zhu Yi5a669262008-01-14 17:46:18 -08003504#define UCODE_READY_TIMEOUT (2 * HZ)
3505
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003506static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003507{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003508 struct iwl_priv *priv = hw->priv;
Zhu Yi5a669262008-01-14 17:46:18 -08003509 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003510
Tomas Winklere1623442009-01-27 14:27:56 -08003511 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003512
3513 /* we should be verifying the device is ready to be opened */
3514 mutex_lock(&priv->mutex);
3515
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003516 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a669262008-01-14 17:46:18 -08003517 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3518 * ucode filename and max sizes are card-specific. */
3519
3520 if (!priv->ucode_code.len) {
3521 ret = iwl3945_read_ucode(priv);
3522 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003523 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a669262008-01-14 17:46:18 -08003524 mutex_unlock(&priv->mutex);
3525 goto out_release_irq;
3526 }
3527 }
3528
Zhu Yie655b9f2008-01-24 02:19:38 -08003529 ret = __iwl3945_up(priv);
Zhu Yi5a669262008-01-14 17:46:18 -08003530
Zhu Yib481de92007-09-25 17:54:57 -07003531 mutex_unlock(&priv->mutex);
Zhu Yi5a669262008-01-14 17:46:18 -08003532
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003533 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003534
Zhu Yie655b9f2008-01-24 02:19:38 -08003535 if (ret)
3536 goto out_release_irq;
3537
Tomas Winklere1623442009-01-27 14:27:56 -08003538 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003539
Zhu Yi5a669262008-01-14 17:46:18 -08003540 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3541 * mac80211 will not be run successfully. */
3542 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3543 test_bit(STATUS_READY, &priv->status),
3544 UCODE_READY_TIMEOUT);
3545 if (!ret) {
3546 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003547 IWL_ERR(priv,
3548 "Wait for START_ALIVE timeout after %dms.\n",
3549 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a669262008-01-14 17:46:18 -08003550 ret = -ETIMEDOUT;
3551 goto out_release_irq;
3552 }
3553 }
3554
Helmut Schaa26635162009-01-15 09:38:44 +01003555 /* ucode is running and will send rfkill notifications,
3556 * no need to poll the killswitch state anymore */
3557 cancel_delayed_work(&priv->rfkill_poll);
3558
Zhu Yie655b9f2008-01-24 02:19:38 -08003559 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003560 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003561 return 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003562
3563out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003564 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003565 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a669262008-01-14 17:46:18 -08003566 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003567}
3568
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003569static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003570{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003571 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003572
Tomas Winklere1623442009-01-27 14:27:56 -08003573 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003574
Zhu Yie655b9f2008-01-24 02:19:38 -08003575 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003576 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003577 return;
3578 }
3579
Zhu Yib481de92007-09-25 17:54:57 -07003580 priv->is_open = 0;
Zhu Yi5a669262008-01-14 17:46:18 -08003581
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003582 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003583 /* stop mac, cancel any scan request and clear
3584 * RXON_FILTER_ASSOC_MSK BIT
3585 */
Zhu Yi5a669262008-01-14 17:46:18 -08003586 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003587 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003588 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003589 }
3590
Zhu Yi5a669262008-01-14 17:46:18 -08003591 iwl3945_down(priv);
3592
3593 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003594
3595 /* start polling the killswitch state again */
3596 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3597 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003598
Tomas Winklere1623442009-01-27 14:27:56 -08003599 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003600}
3601
Johannes Berge039fa42008-05-15 12:55:29 +02003602static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003603{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003604 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003605
Tomas Winklere1623442009-01-27 14:27:56 -08003606 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003607
Tomas Winklere1623442009-01-27 14:27:56 -08003608 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003609 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003610
Johannes Berge039fa42008-05-15 12:55:29 +02003611 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003612 dev_kfree_skb_any(skb);
3613
Tomas Winklere1623442009-01-27 14:27:56 -08003614 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003615 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003616}
3617
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003618static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003619 struct ieee80211_if_init_conf *conf)
3620{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003621 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003622 unsigned long flags;
3623
Tomas Winklere1623442009-01-27 14:27:56 -08003624 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003625
Johannes Berg32bfd352007-12-19 01:31:26 +01003626 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003627 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003628 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003629 }
3630
3631 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003632 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003633 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003634
3635 spin_unlock_irqrestore(&priv->lock, flags);
3636
3637 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003638
3639 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003640 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003641 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3642 }
3643
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003644 if (iwl_is_ready(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003645 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003646
Zhu Yib481de92007-09-25 17:54:57 -07003647 mutex_unlock(&priv->mutex);
3648
Tomas Winklere1623442009-01-27 14:27:56 -08003649 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003650 return 0;
3651}
3652
3653/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003654 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003655 *
3656 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3657 * be set inappropriately and the driver currently sets the hardware up to
3658 * use it whenever needed.
3659 */
Johannes Berge8975582008-10-09 12:18:51 +02003660static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003661{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003662 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003663 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003664 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003665 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003666 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003667
3668 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003669 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3670 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003671
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003672 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003673 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003674 ret = -EIO;
3675 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003676 }
3677
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003678 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003679 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003680 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003681 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003682 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003683 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003684 }
3685
3686 spin_lock_irqsave(&priv->lock, flags);
3687
Samuel Ortize6148912009-01-23 13:45:15 -08003688 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3689 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003690 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003691 IWL_DEBUG_SCAN(priv,
3692 "Channel %d [%d] is INVALID for this band.\n",
3693 conf->channel->hw_value, conf->channel->band);
3694 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003695 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003696 ret = -EINVAL;
3697 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003698 }
3699
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003700 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003701
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003702 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003703
3704 /* The list of supported rates and rate mask can be different
3705 * for each phymode; since the phymode may have changed, reset
3706 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003707 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003708
3709 spin_unlock_irqrestore(&priv->lock, flags);
3710
3711#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3712 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003713 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003714 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003715 }
3716#endif
3717
Mohamed Abbas37fec382009-03-17 21:51:42 -07003718 if (changed & IEEE80211_CONF_CHANGE_RADIO_ENABLED) {
3719 if (conf->radio_enabled &&
3720 iwl_radio_kill_sw_enable_radio(priv)) {
3721 IWL_DEBUG_MAC80211(priv, "leave - RF-KILL - "
3722 "waiting for uCode\n");
3723 goto out;
3724 }
Zhu Yib481de92007-09-25 17:54:57 -07003725
Mohamed Abbas37fec382009-03-17 21:51:42 -07003726 if (!conf->radio_enabled) {
3727 iwl_radio_kill_sw_disable_radio(priv);
3728 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
3729 goto out;
3730 }
Zhu Yib481de92007-09-25 17:54:57 -07003731 }
3732
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003733 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003734 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003735 ret = -EIO;
3736 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003737 }
3738
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003739 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003740
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003741 if (memcmp(&priv->active_rxon,
3742 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003743 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003744 else
Tomas Winklere1623442009-01-27 14:27:56 -08003745 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07003746
Tomas Winklere1623442009-01-27 14:27:56 -08003747 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003748
Zhu Yi76bb77e2007-11-22 10:53:22 +08003749out:
Zhu Yia0646472007-12-20 14:10:01 +08003750 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003751 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003752 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003753}
3754
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003755static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003756{
3757 int rc = 0;
3758
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08003759 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07003760 return;
3761
3762 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003763 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07003764
3765 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003766 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003767 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003768
3769 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08003770 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003771 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003772 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
3773 sizeof(priv->rxon_timing),
3774 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07003775 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003776 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003777 "Attempting to continue.\n");
3778
3779 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003780 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003781 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003782 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003783 RXON_FLG_SHORT_PREAMBLE_MSK;
3784 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003785 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003786 ~RXON_FLG_SHORT_PREAMBLE_MSK;
3787
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003788 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003789 if (priv->assoc_capability &
3790 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003791 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07003792 RXON_FLG_SHORT_SLOT_MSK;
3793 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003794 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003795 ~RXON_FLG_SHORT_SLOT_MSK;
3796
Johannes Berg05c914f2008-09-11 00:01:58 +02003797 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003798 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07003799 ~RXON_FLG_SHORT_SLOT_MSK;
3800 }
3801 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003802 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003803 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08003804 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08003805 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003806 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003807
3808 /* FIXME - we need to add code here to detect a totally new
3809 * configuration, reset the AP, unassoc, rxon timing, assoc,
3810 * clear sta table, add BCAST sta... */
3811}
3812
Johannes Berg32bfd352007-12-19 01:31:26 +01003813static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
3814 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003815 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07003816{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003817 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003818 int rc;
3819
3820 if (conf == NULL)
3821 return -EIO;
3822
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003823 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003824 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08003825 return 0;
3826 }
3827
Johannes Berg9d139c82008-07-09 14:40:37 +02003828 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02003829 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02003830 conf->changed & IEEE80211_IFCC_BEACON) {
3831 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
3832 if (!beacon)
3833 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003834 mutex_lock(&priv->mutex);
Abhijeet Kolekar9944b932009-04-08 11:26:36 -07003835 rc = iwl_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003836 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02003837 if (rc)
3838 return rc;
3839 }
3840
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003841 if (!iwl_is_alive(priv))
Zhu Yi5a669262008-01-14 17:46:18 -08003842 return -EAGAIN;
3843
Zhu Yib481de92007-09-25 17:54:57 -07003844 mutex_lock(&priv->mutex);
3845
Zhu Yib481de92007-09-25 17:54:57 -07003846 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08003847 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003848
Johannes Berg4150c572007-09-17 01:29:23 -04003849/*
3850 * very dubious code was here; the probe filtering flag is never set:
3851 *
Zhu Yib481de92007-09-25 17:54:57 -07003852 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
3853 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04003854 */
Zhu Yib481de92007-09-25 17:54:57 -07003855
Johannes Berg05c914f2008-09-11 00:01:58 +02003856 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07003857 if (!conf->bssid) {
3858 conf->bssid = priv->mac_addr;
3859 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08003860 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07003861 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07003862 }
3863 if (priv->ibss_beacon)
3864 dev_kfree_skb(priv->ibss_beacon);
3865
Johannes Berg9d139c82008-07-09 14:40:37 +02003866 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07003867 }
3868
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003869 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08003870 goto done;
3871
Zhu Yib481de92007-09-25 17:54:57 -07003872 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
3873 !is_multicast_ether_addr(conf->bssid)) {
3874 /* If there is currently a HW scan going on in the background
3875 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003876 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003877 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07003878 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08003879 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07003880 mutex_unlock(&priv->mutex);
3881 return -EAGAIN;
3882 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003883 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07003884
3885 /* TODO: Audit driver for usage of these members and see
3886 * if mac80211 deprecates them (priv->bssid looks like it
3887 * shouldn't be there, but I haven't scanned the IBSS code
3888 * to verify) - jpk */
3889 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
3890
Johannes Berg05c914f2008-09-11 00:01:58 +02003891 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003892 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003893 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003894 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02003895 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003896 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003897 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003898 }
3899
3900 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003901 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003902 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003903 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003904 }
3905
Mohamed Abbasfde35712007-11-29 11:10:15 +08003906 done:
Tomas Winklere1623442009-01-27 14:27:56 -08003907 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003908 mutex_unlock(&priv->mutex);
3909
3910 return 0;
3911}
3912
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003913static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003914 struct ieee80211_if_init_conf *conf)
3915{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003916 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003917
Tomas Winklere1623442009-01-27 14:27:56 -08003918 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003919
3920 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003921
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003922 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003923 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003924 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08003925 iwl3945_commit_rxon(priv);
3926 }
Johannes Berg32bfd352007-12-19 01:31:26 +01003927 if (priv->vif == conf->vif) {
3928 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07003929 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07003930 }
3931 mutex_unlock(&priv->mutex);
3932
Tomas Winklere1623442009-01-27 14:27:56 -08003933 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003934}
3935
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003936static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01003937 struct ieee80211_vif *vif,
3938 struct ieee80211_sta *sta,
3939 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07003940{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003941 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01003942 const u8 *addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003943 int ret = 0;
3944 u8 sta_id = IWL_INVALID_STATION;
3945 u8 static_key;
Zhu Yib481de92007-09-25 17:54:57 -07003946
Tomas Winklere1623442009-01-27 14:27:56 -08003947 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003948
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003949 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08003950 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07003951 return -EOPNOTSUPP;
3952 }
3953
Winkler, Tomas42986792009-01-19 15:30:22 -08003954 addr = sta ? sta->addr : iwl_bcast_addr;
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003955 static_key = !iwl_is_associated(priv);
3956
3957 if (!static_key) {
3958 sta_id = iwl3945_hw_find_station(priv, addr);
3959 if (sta_id == IWL_INVALID_STATION) {
Joe Perches12514392009-04-16 16:23:26 -07003960 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003961 addr);
3962 return -EINVAL;
3963 }
Zhu Yib481de92007-09-25 17:54:57 -07003964 }
3965
3966 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003967 iwl_scan_cancel_timeout(priv, 100);
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003968 mutex_unlock(&priv->mutex);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003969
Zhu Yib481de92007-09-25 17:54:57 -07003970 switch (cmd) {
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003971 case SET_KEY:
3972 if (static_key)
3973 ret = iwl3945_set_static_key(priv, key);
3974 else
3975 ret = iwl3945_set_dynamic_key(priv, key, sta_id);
3976 IWL_DEBUG_MAC80211(priv, "enable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003977 break;
3978 case DISABLE_KEY:
Abhijeet Kolekar6e21f152009-02-27 16:21:21 -08003979 if (static_key)
3980 ret = iwl3945_remove_static_key(priv);
3981 else
3982 ret = iwl3945_clear_sta_key_info(priv, sta_id);
3983 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07003984 break;
3985 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08003986 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07003987 }
3988
Tomas Winklere1623442009-01-27 14:27:56 -08003989 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003990
Winkler, Tomas42986792009-01-19 15:30:22 -08003991 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003992}
3993
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003994static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003995 struct ieee80211_tx_queue_stats *stats)
3996{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003997 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003998 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08003999 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004000 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004001 unsigned long flags;
4002
Tomas Winklere1623442009-01-27 14:27:56 -08004003 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004004
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004005 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004006 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004007 return -EIO;
4008 }
4009
4010 spin_lock_irqsave(&priv->lock, flags);
4011
4012 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004013 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004014 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004015 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004016
Johannes Berg57ffc582008-04-29 17:18:59 +02004017 stats[i].len = q->n_window - avail;
4018 stats[i].limit = q->n_window - q->high_mark;
4019 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004020
4021 }
4022 spin_unlock_irqrestore(&priv->lock, flags);
4023
Tomas Winklere1623442009-01-27 14:27:56 -08004024 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004025
4026 return 0;
4027}
4028
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004029static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004030{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004031 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004032 unsigned long flags;
4033
4034 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004035 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004036
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004037 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004038
Zhu Yib481de92007-09-25 17:54:57 -07004039 spin_lock_irqsave(&priv->lock, flags);
4040 priv->assoc_id = 0;
4041 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004042
4043 /* new association get rid of ibss beacon skb */
4044 if (priv->ibss_beacon)
4045 dev_kfree_skb(priv->ibss_beacon);
4046
4047 priv->ibss_beacon = NULL;
4048
4049 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004050 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004051 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004052 priv->beacon_int = 0;
4053
4054 spin_unlock_irqrestore(&priv->lock, flags);
4055
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004056 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004057 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004058 mutex_unlock(&priv->mutex);
4059 return;
4060 }
4061
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004062 /* we are restarting association process
4063 * clear RXON_FILTER_ASSOC_MSK bit
4064 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004065 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004066 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004067 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004068 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004069 }
4070
Zhu Yib481de92007-09-25 17:54:57 -07004071 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004072 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004073
Tomas Winklere1623442009-01-27 14:27:56 -08004074 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004075 mutex_unlock(&priv->mutex);
4076 return;
4077 }
4078
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004079 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004080
4081 mutex_unlock(&priv->mutex);
4082
Tomas Winklere1623442009-01-27 14:27:56 -08004083 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004084
4085}
4086
Zhu Yib481de92007-09-25 17:54:57 -07004087/*****************************************************************************
4088 *
4089 * sysfs attributes
4090 *
4091 *****************************************************************************/
4092
Samuel Ortizd08853a2009-01-23 13:45:17 -08004093#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004094
4095/*
4096 * The following adds a new attribute to the sysfs representation
4097 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4098 * used for controlling the debug level.
4099 *
4100 * See the level definitions in iwl for details.
4101 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004102static ssize_t show_debug_level(struct device *d,
4103 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004104{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004105 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004106
4107 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004108}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004109static ssize_t store_debug_level(struct device *d,
4110 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004111 const char *buf, size_t count)
4112{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004113 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004114 unsigned long val;
4115 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004116
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004117 ret = strict_strtoul(buf, 0, &val);
4118 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004119 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004120 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004121 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004122
4123 return strnlen(buf, count);
4124}
4125
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004126static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4127 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004128
Samuel Ortizd08853a2009-01-23 13:45:17 -08004129#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004130
Zhu Yib481de92007-09-25 17:54:57 -07004131static ssize_t show_temperature(struct device *d,
4132 struct device_attribute *attr, char *buf)
4133{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004134 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004135
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004136 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004137 return -EAGAIN;
4138
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004139 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004140}
4141
4142static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4143
Zhu Yib481de92007-09-25 17:54:57 -07004144static ssize_t show_tx_power(struct device *d,
4145 struct device_attribute *attr, char *buf)
4146{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004147 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004148 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004149}
4150
4151static ssize_t store_tx_power(struct device *d,
4152 struct device_attribute *attr,
4153 const char *buf, size_t count)
4154{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004155 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004156 char *p = (char *)buf;
4157 u32 val;
4158
4159 val = simple_strtoul(p, &p, 10);
4160 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004161 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004162 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004163 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004164
4165 return count;
4166}
4167
4168static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4169
4170static ssize_t show_flags(struct device *d,
4171 struct device_attribute *attr, char *buf)
4172{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004173 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004174
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004175 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004176}
4177
4178static ssize_t store_flags(struct device *d,
4179 struct device_attribute *attr,
4180 const char *buf, size_t count)
4181{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004182 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004183 u32 flags = simple_strtoul(buf, NULL, 0);
4184
4185 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004186 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004187 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004188 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004189 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004190 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004191 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004192 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004193 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004194 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004195 }
4196 }
4197 mutex_unlock(&priv->mutex);
4198
4199 return count;
4200}
4201
4202static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4203
4204static ssize_t show_filter_flags(struct device *d,
4205 struct device_attribute *attr, char *buf)
4206{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004207 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004208
4209 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004210 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004211}
4212
4213static ssize_t store_filter_flags(struct device *d,
4214 struct device_attribute *attr,
4215 const char *buf, size_t count)
4216{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004217 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004218 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4219
4220 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004221 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004222 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004223 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004224 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004225 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004226 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004227 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004228 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004229 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004230 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004231 }
4232 }
4233 mutex_unlock(&priv->mutex);
4234
4235 return count;
4236}
4237
4238static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4239 store_filter_flags);
4240
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004241#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004242
4243static ssize_t show_measurement(struct device *d,
4244 struct device_attribute *attr, char *buf)
4245{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004246 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004247 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004248 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004249 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004250 unsigned long flags;
4251
4252 spin_lock_irqsave(&priv->lock, flags);
4253 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4254 spin_unlock_irqrestore(&priv->lock, flags);
4255 return 0;
4256 }
4257 memcpy(&measure_report, &priv->measure_report, size);
4258 priv->measurement_status = 0;
4259 spin_unlock_irqrestore(&priv->lock, flags);
4260
4261 while (size && (PAGE_SIZE - len)) {
4262 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4263 PAGE_SIZE - len, 1);
4264 len = strlen(buf);
4265 if (PAGE_SIZE - len)
4266 buf[len++] = '\n';
4267
4268 ofs += 16;
4269 size -= min(size, 16U);
4270 }
4271
4272 return len;
4273}
4274
4275static ssize_t store_measurement(struct device *d,
4276 struct device_attribute *attr,
4277 const char *buf, size_t count)
4278{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004279 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004280 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004281 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004282 .start_time = cpu_to_le64(priv->last_tsf),
4283 .duration = cpu_to_le16(1),
4284 };
4285 u8 type = IWL_MEASURE_BASIC;
4286 u8 buffer[32];
4287 u8 channel;
4288
4289 if (count) {
4290 char *p = buffer;
4291 strncpy(buffer, buf, min(sizeof(buffer), count));
4292 channel = simple_strtoul(p, NULL, 0);
4293 if (channel)
4294 params.channel = channel;
4295
4296 p = buffer;
4297 while (*p && *p != ' ')
4298 p++;
4299 if (*p)
4300 type = simple_strtoul(p + 1, NULL, 0);
4301 }
4302
Tomas Winklere1623442009-01-27 14:27:56 -08004303 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004304 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004305 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004306
4307 return count;
4308}
4309
4310static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4311 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004312#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004313
Zhu Yib481de92007-09-25 17:54:57 -07004314static ssize_t store_retry_rate(struct device *d,
4315 struct device_attribute *attr,
4316 const char *buf, size_t count)
4317{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004318 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004319
4320 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4321 if (priv->retry_rate <= 0)
4322 priv->retry_rate = 1;
4323
4324 return count;
4325}
4326
4327static ssize_t show_retry_rate(struct device *d,
4328 struct device_attribute *attr, char *buf)
4329{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004330 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004331 return sprintf(buf, "%d", priv->retry_rate);
4332}
4333
4334static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4335 store_retry_rate);
4336
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004337
Zhu Yib481de92007-09-25 17:54:57 -07004338static ssize_t store_power_level(struct device *d,
4339 struct device_attribute *attr,
4340 const char *buf, size_t count)
4341{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004342 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004343 int ret;
4344 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004345
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004346
Zhu Yib481de92007-09-25 17:54:57 -07004347 mutex_lock(&priv->mutex);
4348
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004349 ret = strict_strtoul(buf, 10, &mode);
4350 if (ret)
4351 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004352
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004353 ret = iwl_power_set_user_mode(priv, mode);
4354 if (ret) {
4355 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4356 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004357 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004358 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004359
4360 out:
4361 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004362 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004363}
4364
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004365static ssize_t show_power_level(struct device *d,
4366 struct device_attribute *attr, char *buf)
4367{
4368 struct iwl_priv *priv = dev_get_drvdata(d);
4369 int mode = priv->power_data.user_power_setting;
4370 int system = priv->power_data.system_power_setting;
4371 int level = priv->power_data.power_mode;
4372 char *p = buf;
4373
4374 switch (system) {
4375 case IWL_POWER_SYS_AUTO:
4376 p += sprintf(p, "SYSTEM:auto");
4377 break;
4378 case IWL_POWER_SYS_AC:
4379 p += sprintf(p, "SYSTEM:ac");
4380 break;
4381 case IWL_POWER_SYS_BATTERY:
4382 p += sprintf(p, "SYSTEM:battery");
4383 break;
4384 }
4385
4386 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4387 "fixed" : "auto");
4388 p += sprintf(p, "\tINDEX:%d", level);
4389 p += sprintf(p, "\n");
4390 return p - buf + 1;
4391}
4392
4393static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4394 show_power_level, store_power_level);
4395
Zhu Yib481de92007-09-25 17:54:57 -07004396#define MAX_WX_STRING 80
4397
4398/* Values are in microsecond */
4399static const s32 timeout_duration[] = {
4400 350000,
4401 250000,
4402 75000,
4403 37000,
4404 25000,
4405};
4406static const s32 period_duration[] = {
4407 400000,
4408 700000,
4409 1000000,
4410 1000000,
4411 1000000
4412};
4413
Zhu Yib481de92007-09-25 17:54:57 -07004414static ssize_t show_channels(struct device *d,
4415 struct device_attribute *attr, char *buf)
4416{
Johannes Berg8318d782008-01-24 19:38:38 +01004417 /* all this shit doesn't belong into sysfs anyway */
4418 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004419}
4420
4421static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4422
4423static ssize_t show_statistics(struct device *d,
4424 struct device_attribute *attr, char *buf)
4425{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004426 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004427 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004428 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004429 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004430 int rc = 0;
4431
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004432 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004433 return -EAGAIN;
4434
4435 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004436 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004437 mutex_unlock(&priv->mutex);
4438
4439 if (rc) {
4440 len = sprintf(buf,
4441 "Error sending statistics request: 0x%08X\n", rc);
4442 return len;
4443 }
4444
4445 while (size && (PAGE_SIZE - len)) {
4446 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4447 PAGE_SIZE - len, 1);
4448 len = strlen(buf);
4449 if (PAGE_SIZE - len)
4450 buf[len++] = '\n';
4451
4452 ofs += 16;
4453 size -= min(size, 16U);
4454 }
4455
4456 return len;
4457}
4458
4459static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4460
4461static ssize_t show_antenna(struct device *d,
4462 struct device_attribute *attr, char *buf)
4463{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004464 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004465
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004466 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004467 return -EAGAIN;
4468
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004469 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004470}
4471
4472static ssize_t store_antenna(struct device *d,
4473 struct device_attribute *attr,
4474 const char *buf, size_t count)
4475{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004476 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004477 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004478
4479 if (count == 0)
4480 return 0;
4481
4482 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004483 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004484 return count;
4485 }
4486
4487 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004488 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004489 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004490 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004491 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004492
4493
4494 return count;
4495}
4496
4497static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4498
4499static ssize_t show_status(struct device *d,
4500 struct device_attribute *attr, char *buf)
4501{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004502 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004503 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004504 return -EAGAIN;
4505 return sprintf(buf, "0x%08x\n", (int)priv->status);
4506}
4507
4508static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4509
4510static ssize_t dump_error_log(struct device *d,
4511 struct device_attribute *attr,
4512 const char *buf, size_t count)
4513{
4514 char *p = (char *)buf;
4515
4516 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004517 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004518
4519 return strnlen(buf, count);
4520}
4521
4522static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4523
4524static ssize_t dump_event_log(struct device *d,
4525 struct device_attribute *attr,
4526 const char *buf, size_t count)
4527{
4528 char *p = (char *)buf;
4529
4530 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004531 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004532
4533 return strnlen(buf, count);
4534}
4535
4536static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4537
4538/*****************************************************************************
4539 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004540 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004541 *
4542 *****************************************************************************/
4543
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004544static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004545{
Reinette Chatred21050c2009-02-13 11:51:18 -08004546 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004547
4548 init_waitqueue_head(&priv->wait_command_queue);
4549
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004550 INIT_WORK(&priv->up, iwl3945_bg_up);
4551 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4552 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004553 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004554 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004555 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4556 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004557 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004558 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4559 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4560 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4561 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004562
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004563 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004564
4565 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004566 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004567}
4568
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004569static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004570{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004571 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004572
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004573 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004574 cancel_delayed_work(&priv->scan_check);
4575 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004576 cancel_work_sync(&priv->beacon_update);
4577}
4578
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004579static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004580 &dev_attr_antenna.attr,
4581 &dev_attr_channels.attr,
4582 &dev_attr_dump_errors.attr,
4583 &dev_attr_dump_events.attr,
4584 &dev_attr_flags.attr,
4585 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004586#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004587 &dev_attr_measurement.attr,
4588#endif
4589 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004590 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004591 &dev_attr_statistics.attr,
4592 &dev_attr_status.attr,
4593 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07004594 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08004595#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004596 &dev_attr_debug_level.attr,
4597#endif
Zhu Yib481de92007-09-25 17:54:57 -07004598 NULL
4599};
4600
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004601static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07004602 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004603 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07004604};
4605
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004606static struct ieee80211_ops iwl3945_hw_ops = {
4607 .tx = iwl3945_mac_tx,
4608 .start = iwl3945_mac_start,
4609 .stop = iwl3945_mac_stop,
4610 .add_interface = iwl3945_mac_add_interface,
4611 .remove_interface = iwl3945_mac_remove_interface,
4612 .config = iwl3945_mac_config,
4613 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004614 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004615 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004616 .get_tx_stats = iwl3945_mac_get_tx_stats,
Abhijeet Kolekar488829f2009-03-26 10:14:10 -07004617 .conf_tx = iwl_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004618 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekar5bbe2332009-04-08 11:26:35 -07004619 .bss_info_changed = iwl_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08004620 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07004621};
4622
Winkler, Tomase52119c2008-12-22 11:31:19 +08004623static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004624{
4625 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08004626 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004627
4628 priv->retry_rate = 1;
4629 priv->ibss_beacon = NULL;
4630
4631 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004632 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004633 spin_lock_init(&priv->sta_lock);
4634 spin_lock_init(&priv->hcmd_lock);
4635
4636 INIT_LIST_HEAD(&priv->free_frames);
4637
4638 mutex_init(&priv->mutex);
4639
4640 /* Clear the driver's (not device's) station table */
4641 iwl3945_clear_stations_table(priv);
4642
4643 priv->data_retry_limit = -1;
4644 priv->ieee_channels = NULL;
4645 priv->ieee_rates = NULL;
4646 priv->band = IEEE80211_BAND_2GHZ;
4647
4648 priv->iw_mode = NL80211_IFTYPE_STATION;
4649
4650 iwl_reset_qos(priv);
4651
4652 priv->qos_data.qos_active = 0;
4653 priv->qos_data.qos_cap.val = 0;
4654
4655 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004656 /* If power management is turned on, default to CAM mode */
4657 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004658 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004659
Samuel Ortize6148912009-01-23 13:45:15 -08004660 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
4661 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
4662 eeprom->version);
4663 ret = -EINVAL;
4664 goto err;
4665 }
4666 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004667 if (ret) {
4668 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
4669 goto err;
4670 }
4671
Samuel Ortize6148912009-01-23 13:45:15 -08004672 /* Set up txpower settings in driver for all channels */
4673 if (iwl3945_txpower_set_from_eeprom(priv)) {
4674 ret = -EIO;
4675 goto err_free_channel_map;
4676 }
4677
Samuel Ortiz534166d2009-01-23 13:45:16 -08004678 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004679 if (ret) {
4680 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
4681 goto err_free_channel_map;
4682 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08004683 iwl3945_init_hw_rates(priv, priv->ieee_rates);
4684
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004685 return 0;
4686
4687err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08004688 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004689err:
4690 return ret;
4691}
4692
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004693static int iwl3945_setup_mac(struct iwl_priv *priv)
4694{
4695 int ret;
4696 struct ieee80211_hw *hw = priv->hw;
4697
4698 hw->rate_control_algorithm = "iwl-3945-rs";
4699 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
4700
4701 /* Tell mac80211 our characteristics */
4702 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Mohamed Abbasb1c60192009-03-17 21:51:47 -07004703 IEEE80211_HW_NOISE_DBM |
4704 IEEE80211_HW_SPECTRUM_MGMT;
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004705
4706 hw->wiphy->interface_modes =
4707 BIT(NL80211_IFTYPE_STATION) |
4708 BIT(NL80211_IFTYPE_ADHOC);
4709
4710 hw->wiphy->custom_regulatory = true;
4711
Johannes Bergd60cc912009-04-09 09:56:02 +02004712 hw->wiphy->max_scan_ssids = 1; /* WILL FIX */
4713
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004714 /* Default value; 4 EDCA QOS priorities */
4715 hw->queues = 4;
4716
4717 hw->conf.beacon_int = 100;
4718
4719 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
4720 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
4721 &priv->bands[IEEE80211_BAND_2GHZ];
4722
4723 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
4724 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
4725 &priv->bands[IEEE80211_BAND_5GHZ];
4726
4727 ret = ieee80211_register_hw(priv->hw);
4728 if (ret) {
4729 IWL_ERR(priv, "Failed to register hw (error %d)\n", ret);
4730 return ret;
4731 }
4732 priv->mac80211_registered = 1;
4733
4734 return 0;
4735}
4736
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004737static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07004738{
4739 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004740 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07004741 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08004742 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08004743 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004744 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004745
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004746 /***********************
4747 * 1. Allocating HW data
4748 * ********************/
4749
Zhu Yib481de92007-09-25 17:54:57 -07004750 /* mac80211 allocates memory for this device instance, including
4751 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004752 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07004753 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08004754 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07004755 err = -ENOMEM;
4756 goto out;
4757 }
Zhu Yib481de92007-09-25 17:54:57 -07004758 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004759 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004760
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004761 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
4762 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004763 IWL_ERR(priv,
4764 "invalid queues_num, should be between %d and %d\n",
4765 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08004766 err = -EINVAL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004767 goto out_ieee80211_free_hw;
Samuel Ortiza3139c52008-12-19 10:37:09 +08004768 }
4769
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004770 /*
4771 * Disabling hardware scan means that mac80211 will perform scans
4772 * "the hard way", rather than using device's scan.
4773 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004774 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08004775 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004776 iwl3945_hw_ops.hw_scan = NULL;
4777 }
4778
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004779
Tomas Winklere1623442009-01-27 14:27:56 -08004780 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004781 priv->cfg = cfg;
4782 priv->pci_dev = pdev;
4783
Samuel Ortizd08853a2009-01-23 13:45:17 -08004784#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004785 priv->debug_level = iwl3945_mod_params.debug;
4786 atomic_set(&priv->restrict_refcnt, 0);
4787#endif
Zhu Yib481de92007-09-25 17:54:57 -07004788
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004789 /***************************
4790 * 2. Initializing PCI bus
4791 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07004792 if (pci_enable_device(pdev)) {
4793 err = -ENODEV;
4794 goto out_ieee80211_free_hw;
4795 }
4796
4797 pci_set_master(pdev);
4798
Yang Hongyang284901a2009-04-06 19:01:15 -07004799 err = pci_set_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07004800 if (!err)
Yang Hongyang284901a2009-04-06 19:01:15 -07004801 err = pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32));
Zhu Yib481de92007-09-25 17:54:57 -07004802 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08004803 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004804 goto out_pci_disable_device;
4805 }
4806
4807 pci_set_drvdata(pdev, priv);
4808 err = pci_request_regions(pdev, DRV_NAME);
4809 if (err)
4810 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08004811
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004812 /***********************
4813 * 3. Read REV Register
4814 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07004815 priv->hw_base = pci_iomap(pdev, 0, 0);
4816 if (!priv->hw_base) {
4817 err = -ENODEV;
4818 goto out_pci_release_regions;
4819 }
4820
Tomas Winklere1623442009-01-27 14:27:56 -08004821 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07004822 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08004823 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07004824
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004825 /* We disable the RETRY_TIMEOUT register (0x41) to keep
4826 * PCI Tx retries from interfering with C3 CPU state */
4827 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07004828
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004829 /* amp init */
4830 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004831 if (err < 0) {
David S. Millerd5df2a12009-03-10 05:04:16 -07004832 IWL_DEBUG_INFO(priv, "Failed to init the card\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004833 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004834 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004835
4836 /***********************
4837 * 4. Read EEPROM
4838 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004839
Zhu Yi5a669262008-01-14 17:46:18 -08004840 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08004841 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004842 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004843 IWL_ERR(priv, "Unable to init EEPROM\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004844 goto out_iounmap;
Zhu Yi5a669262008-01-14 17:46:18 -08004845 }
4846 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08004847 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
4848 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004849 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a669262008-01-14 17:46:18 -08004850 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
4851
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004852 /***********************
4853 * 5. Setup HW Constants
4854 * ********************/
4855 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08004856 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004857 IWL_ERR(priv, "failed to set hw settings\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004858 goto out_eeprom_free;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004859 }
4860
4861 /***********************
4862 * 6. Setup priv
4863 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004864
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004865 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004866 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004867 IWL_ERR(priv, "initializing driver failed\n");
Reinette Chatrec8f16132009-02-27 16:21:22 -08004868 goto out_unset_hw_params;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004869 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08004870
Tomas Winkler978785a2008-12-19 10:37:31 +08004871 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
4872 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004873
4874 /***********************************
4875 * 7. Initialize Module Parameters
4876 * **********************************/
4877
4878 /* Initialize module parameter values here */
4879 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004880 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004881 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08004882 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004883 }
4884
4885
4886 /***********************
4887 * 8. Setup Services
4888 * ********************/
4889
4890 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004891 iwl_disable_interrupts(priv);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004892 spin_unlock_irqrestore(&priv->lock, flags);
4893
Helmut Schaa26635162009-01-15 09:38:44 +01004894 pci_enable_msi(priv->pci_dev);
4895
Abhijeet Kolekarf17d08a2009-02-18 15:54:31 -08004896 err = request_irq(priv->pci_dev->irq, iwl_isr, IRQF_SHARED,
Helmut Schaa26635162009-01-15 09:38:44 +01004897 DRV_NAME, priv);
4898 if (err) {
4899 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
4900 goto out_disable_msi;
4901 }
4902
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004903 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4904 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08004905 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08004906 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004907 }
4908
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004909 iwl_set_rxon_channel(priv,
4910 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004911 iwl3945_setup_deferred_work(priv);
4912 iwl3945_setup_rx_handlers(priv);
4913
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004914 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01004915 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004916 * *******************************/
4917
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004918 iwl_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004919
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004920 err = iwl3945_setup_mac(priv);
4921 if (err)
4922 goto out_remove_sysfs;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004923
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004924 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004925 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08004926 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004927 "Ignoring error: %d\n", err);
Abhijeet Kolekar2a4ddaa2009-02-27 16:21:23 -08004928 else
4929 iwl_rfkill_set_hw_state(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08004930
Helmut Schaa26635162009-01-15 09:38:44 +01004931 /* Start monitoring the killswitch */
4932 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
4933 2 * HZ);
4934
Zhu Yib481de92007-09-25 17:54:57 -07004935 return 0;
4936
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08004937 out_remove_sysfs:
Zhu Yib481de92007-09-25 17:54:57 -07004938 destroy_workqueue(priv->workqueue);
4939 priv->workqueue = NULL;
Reinette Chatrec8f16132009-02-27 16:21:22 -08004940 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
4941 out_release_irq:
4942 free_irq(priv->pci_dev->irq, priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004943 out_disable_msi:
4944 pci_disable_msi(priv->pci_dev);
Reinette Chatrec8f16132009-02-27 16:21:22 -08004945 iwlcore_free_geos(priv);
4946 iwl_free_channel_map(priv);
4947 out_unset_hw_params:
4948 iwl3945_unset_hw_params(priv);
4949 out_eeprom_free:
4950 iwl_eeprom_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004951 out_iounmap:
4952 pci_iounmap(pdev, priv->hw_base);
4953 out_pci_release_regions:
4954 pci_release_regions(pdev);
4955 out_pci_disable_device:
Zhu Yib481de92007-09-25 17:54:57 -07004956 pci_set_drvdata(pdev, NULL);
Reinette Chatre623d5632009-03-03 11:37:04 -08004957 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07004958 out_ieee80211_free_hw:
4959 ieee80211_free_hw(priv->hw);
4960 out:
4961 return err;
4962}
4963
Reinette Chatrec83dbf62008-03-21 13:53:41 -07004964static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07004965{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004966 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004967 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07004968
4969 if (!priv)
4970 return;
4971
Tomas Winklere1623442009-01-27 14:27:56 -08004972 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07004973
Zhu Yib481de92007-09-25 17:54:57 -07004974 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08004975
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08004976 if (priv->mac80211_registered) {
4977 ieee80211_unregister_hw(priv->hw);
4978 priv->mac80211_registered = 0;
4979 } else {
4980 iwl3945_down(priv);
4981 }
Zhu Yib481de92007-09-25 17:54:57 -07004982
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004983 /* make sure we flush any pending irq or
4984 * tasklet for the driver
4985 */
4986 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekared3b9322009-02-18 15:54:30 -08004987 iwl_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07004988 spin_unlock_irqrestore(&priv->lock, flags);
4989
4990 iwl_synchronize_irq(priv);
4991
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004992 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07004993
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004994 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01004995 cancel_delayed_work(&priv->rfkill_poll);
4996
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004997 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004998
4999 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005000 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005001 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005002
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005003 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005004 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005005
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005006 /*netif_stop_queue(dev); */
5007 flush_workqueue(priv->workqueue);
5008
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005009 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005010 * priv->workqueue... so we can't take down the workqueue
5011 * until now... */
5012 destroy_workqueue(priv->workqueue);
5013 priv->workqueue = NULL;
5014
Helmut Schaa26635162009-01-15 09:38:44 +01005015 free_irq(pdev->irq, priv);
5016 pci_disable_msi(pdev);
5017
Zhu Yib481de92007-09-25 17:54:57 -07005018 pci_iounmap(pdev, priv->hw_base);
5019 pci_release_regions(pdev);
5020 pci_disable_device(pdev);
5021 pci_set_drvdata(pdev, NULL);
5022
Samuel Ortize6148912009-01-23 13:45:15 -08005023 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005024 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005025 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005026 if (priv->ibss_beacon)
5027 dev_kfree_skb(priv->ibss_beacon);
5028
5029 ieee80211_free_hw(priv->hw);
5030}
5031
Zhu Yib481de92007-09-25 17:54:57 -07005032
5033/*****************************************************************************
5034 *
5035 * driver and module entry point
5036 *
5037 *****************************************************************************/
5038
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005039static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005040 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005041 .id_table = iwl3945_hw_card_ids,
5042 .probe = iwl3945_pci_probe,
5043 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005044#ifdef CONFIG_PM
Wey-Yi Guy6da3a132009-03-26 10:14:08 -07005045 .suspend = iwl_pci_suspend,
5046 .resume = iwl_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005047#endif
5048};
5049
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005050static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005051{
5052
5053 int ret;
5054 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5055 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005056
5057 ret = iwl3945_rate_control_register();
5058 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005059 printk(KERN_ERR DRV_NAME
5060 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005061 return ret;
5062 }
5063
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005064 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005065 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005066 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005067 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005068 }
Zhu Yib481de92007-09-25 17:54:57 -07005069
5070 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005071
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005072error_register:
5073 iwl3945_rate_control_unregister();
5074 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005075}
5076
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005077static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005078{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005079 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005080 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005081}
5082
Reinette Chatrea0987a82008-12-02 12:14:06 -08005083MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005084
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005085module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005086MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005087module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005088MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005089module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5090MODULE_PARM_DESC(swcrypto,
5091 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005092module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005093MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005094module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005095MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5096
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005097module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005098MODULE_PARM_DESC(queues_num, "number of hw queues.");
5099
Samuel Ortizaf48d042009-01-23 13:45:19 -08005100module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5101MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5102
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005103module_exit(iwl3945_exit);
5104module_init(iwl3945_init);