blob: 2ad4d760ad2d3b029c7789ee321d2974579963a5 [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
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800236static int iwl3945_send_rxon_assoc(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700237{
238 int rc = 0;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800239 struct iwl_rx_packet *res = NULL;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800240 struct iwl3945_rxon_assoc_cmd rxon_assoc;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800241 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -0700242 .id = REPLY_RXON_ASSOC,
243 .len = sizeof(rxon_assoc),
244 .meta.flags = CMD_WANT_SKB,
245 .data = &rxon_assoc,
246 };
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800247 const struct iwl_rxon_cmd *rxon1 = &priv->staging_rxon;
248 const struct iwl_rxon_cmd *rxon2 = &priv->active_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700249
250 if ((rxon1->flags == rxon2->flags) &&
251 (rxon1->filter_flags == rxon2->filter_flags) &&
252 (rxon1->cck_basic_rates == rxon2->cck_basic_rates) &&
253 (rxon1->ofdm_basic_rates == rxon2->ofdm_basic_rates)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800254 IWL_DEBUG_INFO(priv, "Using current RXON_ASSOC. Not resending.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700255 return 0;
256 }
257
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800258 rxon_assoc.flags = priv->staging_rxon.flags;
259 rxon_assoc.filter_flags = priv->staging_rxon.filter_flags;
260 rxon_assoc.ofdm_basic_rates = priv->staging_rxon.ofdm_basic_rates;
261 rxon_assoc.cck_basic_rates = priv->staging_rxon.cck_basic_rates;
Zhu Yib481de92007-09-25 17:54:57 -0700262 rxon_assoc.reserved = 0;
263
Samuel Ortiz518099a2009-01-19 15:30:27 -0800264 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -0700265 if (rc)
266 return rc;
267
Tomas Winkler3d24a9f2008-12-19 10:37:07 +0800268 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -0700269 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800270 IWL_ERR(priv, "Bad return from REPLY_RXON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -0700271 rc = -EIO;
272 }
273
274 priv->alloc_rxb_skb--;
275 dev_kfree_skb_any(cmd.meta.u.skb);
276
277 return rc;
278}
279
280/**
Samuel Ortiz7e4bca52009-01-23 13:45:18 -0800281 * iwl3945_get_antenna_flags - Get antenna flags for RXON command
282 * @priv: eeprom and antenna fields are used to determine antenna flags
283 *
284 * priv->eeprom39 is used to determine if antenna AUX/MAIN are reversed
285 * iwl3945_mod_params.antenna specifies the antenna diversity mode:
286 *
287 * IWL_ANTENNA_DIVERSITY - NIC selects best antenna by itself
288 * IWL_ANTENNA_MAIN - Force MAIN antenna
289 * IWL_ANTENNA_AUX - Force AUX antenna
290 */
291__le32 iwl3945_get_antenna_flags(const struct iwl_priv *priv)
292{
293 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
294
295 switch (iwl3945_mod_params.antenna) {
296 case IWL_ANTENNA_DIVERSITY:
297 return 0;
298
299 case IWL_ANTENNA_MAIN:
300 if (eeprom->antenna_switch_type)
301 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
302 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
303
304 case IWL_ANTENNA_AUX:
305 if (eeprom->antenna_switch_type)
306 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_A_MSK;
307 return RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_B_MSK;
308 }
309
310 /* bad antenna selector value */
311 IWL_ERR(priv, "Bad antenna selector value (0x%x)\n",
312 iwl3945_mod_params.antenna);
313
314 return 0; /* "diversity" is default if error */
315}
316
317/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800318 * iwl3945_commit_rxon - commit staging_rxon to hardware
Zhu Yib481de92007-09-25 17:54:57 -0700319 *
Ian Schram01ebd062007-10-25 17:15:22 +0800320 * The RXON command in staging_rxon is committed to the hardware and
Zhu Yib481de92007-09-25 17:54:57 -0700321 * the active_rxon structure is updated with the new data. This
322 * function correctly transitions out of the RXON_ASSOC_MSK state if
323 * a HW tune is required based on the RXON structure changes.
324 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800325static int iwl3945_commit_rxon(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700326{
327 /* cast away the const for active_rxon in this function */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800328 struct iwl3945_rxon_cmd *active_rxon = (void *)&priv->active_rxon;
329 struct iwl3945_rxon_cmd *staging_rxon = (void *)&priv->staging_rxon;
Zhu Yib481de92007-09-25 17:54:57 -0700330 int rc = 0;
331
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800332 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -0700333 return -1;
334
335 /* always get timestamp with Rx frame */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800336 staging_rxon->flags |= RXON_FLG_TSF2HOST_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700337
338 /* select antenna */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800339 staging_rxon->flags &=
Zhu Yib481de92007-09-25 17:54:57 -0700340 ~(RXON_FLG_DIS_DIV_MSK | RXON_FLG_ANT_SEL_MSK);
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800341 staging_rxon->flags |= iwl3945_get_antenna_flags(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700342
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800343 rc = iwl_check_rxon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700344 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800345 IWL_ERR(priv, "Invalid RXON configuration. Not committing.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700346 return -EINVAL;
347 }
348
349 /* If we don't need to send a full RXON, we can use
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800350 * iwl3945_rxon_assoc_cmd which is used to reconfigure filter
Zhu Yib481de92007-09-25 17:54:57 -0700351 * and other flags for the current radio configuration. */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800352 if (!iwl_full_rxon_required(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800353 rc = iwl3945_send_rxon_assoc(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700354 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800355 IWL_ERR(priv, "Error setting RXON_ASSOC "
Zhu Yib481de92007-09-25 17:54:57 -0700356 "configuration (%d).\n", rc);
357 return rc;
358 }
359
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800360 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700361
362 return 0;
363 }
364
365 /* If we are currently associated and the new config requires
366 * an RXON_ASSOC and the new config wants the associated mask enabled,
367 * we must clear the associated from the active configuration
368 * before we apply the new config */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800369 if (iwl_is_associated(priv) &&
370 (staging_rxon->filter_flags & RXON_FILTER_ASSOC_MSK)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800371 IWL_DEBUG_INFO(priv, "Toggling associated bit on current RXON\n");
Zhu Yib481de92007-09-25 17:54:57 -0700372 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
373
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800374 /*
375 * reserved4 and 5 could have been filled by the iwlcore code.
376 * Let's clear them before pushing to the 3945.
377 */
378 active_rxon->reserved4 = 0;
379 active_rxon->reserved5 = 0;
Samuel Ortiz518099a2009-01-19 15:30:27 -0800380 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800381 sizeof(struct iwl3945_rxon_cmd),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800382 &priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700383
384 /* If the mask clearing failed then we set
385 * active_rxon back to what it was previously */
386 if (rc) {
387 active_rxon->filter_flags |= RXON_FILTER_ASSOC_MSK;
Winkler, Tomas15b16872008-12-19 10:37:33 +0800388 IWL_ERR(priv, "Error clearing ASSOC_MSK on current "
Zhu Yib481de92007-09-25 17:54:57 -0700389 "configuration (%d).\n", rc);
390 return rc;
391 }
Zhu Yib481de92007-09-25 17:54:57 -0700392 }
393
Tomas Winklere1623442009-01-27 14:27:56 -0800394 IWL_DEBUG_INFO(priv, "Sending RXON\n"
Zhu Yib481de92007-09-25 17:54:57 -0700395 "* with%s RXON_FILTER_ASSOC_MSK\n"
396 "* channel = %d\n"
Johannes Berge1749612008-10-27 15:59:26 -0700397 "* bssid = %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800398 ((priv->staging_rxon.filter_flags &
Zhu Yib481de92007-09-25 17:54:57 -0700399 RXON_FILTER_ASSOC_MSK) ? "" : "out"),
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800400 le16_to_cpu(staging_rxon->channel),
401 staging_rxon->bssid_addr);
402
403 /*
404 * reserved4 and 5 could have been filled by the iwlcore code.
405 * Let's clear them before pushing to the 3945.
406 */
407 staging_rxon->reserved4 = 0;
408 staging_rxon->reserved5 = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700409
410 /* Apply the new configuration */
Samuel Ortiz518099a2009-01-19 15:30:27 -0800411 rc = iwl_send_cmd_pdu(priv, REPLY_RXON,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800412 sizeof(struct iwl3945_rxon_cmd),
413 staging_rxon);
Zhu Yib481de92007-09-25 17:54:57 -0700414 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800415 IWL_ERR(priv, "Error setting new configuration (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700416 return rc;
417 }
418
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800419 memcpy(active_rxon, staging_rxon, sizeof(*active_rxon));
Zhu Yib481de92007-09-25 17:54:57 -0700420
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800421 iwl3945_clear_stations_table(priv);
Zhu Yi556f8db2007-09-27 11:27:33 +0800422
Zhu Yib481de92007-09-25 17:54:57 -0700423 /* If we issue a new RXON command which required a tune then we must
424 * send a new TXPOWER command or we won't be able to Tx any frames */
Samuel Ortiz75bcfae2009-01-23 13:45:11 -0800425 rc = priv->cfg->ops->lib->send_tx_power(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700426 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800427 IWL_ERR(priv, "Error setting Tx power (%d).\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700428 return rc;
429 }
430
431 /* Add the broadcast address so we can send broadcast frames */
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +0800432 if (iwl3945_add_station(priv, iwl_bcast_addr, 0, 0) ==
Zhu Yib481de92007-09-25 17:54:57 -0700433 IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800434 IWL_ERR(priv, "Error adding BROADCAST address for transmit.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700435 return -EIO;
436 }
437
438 /* If we have set the ASSOC_MSK and we are in BSS mode then
439 * add the IWL_AP_ID to the station rate table */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800440 if (iwl_is_associated(priv) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200441 (priv->iw_mode == NL80211_IFTYPE_STATION))
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800442 if (iwl3945_add_station(priv, priv->active_rxon.bssid_addr,
443 1, 0)
Zhu Yib481de92007-09-25 17:54:57 -0700444 == IWL_INVALID_STATION) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800445 IWL_ERR(priv, "Error adding AP address for transmit\n");
Zhu Yib481de92007-09-25 17:54:57 -0700446 return -EIO;
447 }
448
Johannes Berg8318d782008-01-24 19:38:38 +0100449 /* Init the hardware's rate fallback order based on the band */
Zhu Yib481de92007-09-25 17:54:57 -0700450 rc = iwl3945_init_hw_rate_table(priv);
451 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800452 IWL_ERR(priv, "Error setting HW rate table: %02X\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -0700453 return -EIO;
454 }
455
456 return 0;
457}
458
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800459static int iwl3945_update_sta_key_info(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700460 struct ieee80211_key_conf *keyconf,
461 u8 sta_id)
462{
463 unsigned long flags;
464 __le16 key_flags = 0;
465
466 switch (keyconf->alg) {
467 case ALG_CCMP:
468 key_flags |= STA_KEY_FLG_CCMP;
469 key_flags |= cpu_to_le16(
470 keyconf->keyidx << STA_KEY_FLG_KEYID_POS);
471 key_flags &= ~STA_KEY_FLG_INVALID;
472 break;
473 case ALG_TKIP:
474 case ALG_WEP:
Zhu Yib481de92007-09-25 17:54:57 -0700475 default:
476 return -EINVAL;
477 }
478 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800479 priv->stations_39[sta_id].keyinfo.alg = keyconf->alg;
480 priv->stations_39[sta_id].keyinfo.keylen = keyconf->keylen;
481 memcpy(priv->stations_39[sta_id].keyinfo.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700482 keyconf->keylen);
483
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800484 memcpy(priv->stations_39[sta_id].sta.key.key, keyconf->key,
Zhu Yib481de92007-09-25 17:54:57 -0700485 keyconf->keylen);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800486 priv->stations_39[sta_id].sta.key.key_flags = key_flags;
487 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
488 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700489
490 spin_unlock_irqrestore(&priv->sta_lock, flags);
491
Tomas Winklere1623442009-01-27 14:27:56 -0800492 IWL_DEBUG_INFO(priv, "hwcrypto: modify ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800493 iwl_send_add_sta(priv,
494 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700495 return 0;
496}
497
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800498static int iwl3945_clear_sta_key_info(struct iwl_priv *priv, u8 sta_id)
Zhu Yib481de92007-09-25 17:54:57 -0700499{
500 unsigned long flags;
501
502 spin_lock_irqsave(&priv->sta_lock, flags);
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800503 memset(&priv->stations_39[sta_id].keyinfo, 0, sizeof(struct iwl3945_hw_key));
504 memset(&priv->stations_39[sta_id].sta.key, 0,
Tomas Winkler4c897252008-12-19 10:37:05 +0800505 sizeof(struct iwl4965_keyinfo));
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800506 priv->stations_39[sta_id].sta.key.key_flags = STA_KEY_FLG_NO_ENC;
507 priv->stations_39[sta_id].sta.sta.modify_mask = STA_MODIFY_KEY_MASK;
508 priv->stations_39[sta_id].sta.mode = STA_CONTROL_MODIFY_MSK;
Zhu Yib481de92007-09-25 17:54:57 -0700509 spin_unlock_irqrestore(&priv->sta_lock, flags);
510
Tomas Winklere1623442009-01-27 14:27:56 -0800511 IWL_DEBUG_INFO(priv, "hwcrypto: clear ucode station key info\n");
Samuel Ortiz17f841c2009-01-23 13:45:20 -0800512 iwl_send_add_sta(priv,
513 (struct iwl_addsta_cmd *)&priv->stations_39[sta_id].sta, 0);
Zhu Yib481de92007-09-25 17:54:57 -0700514 return 0;
515}
516
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800517static void iwl3945_clear_free_frames(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700518{
519 struct list_head *element;
520
Tomas Winklere1623442009-01-27 14:27:56 -0800521 IWL_DEBUG_INFO(priv, "%d frames on pre-allocated heap on clear.\n",
Zhu Yib481de92007-09-25 17:54:57 -0700522 priv->frames_count);
523
524 while (!list_empty(&priv->free_frames)) {
525 element = priv->free_frames.next;
526 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800527 kfree(list_entry(element, struct iwl3945_frame, list));
Zhu Yib481de92007-09-25 17:54:57 -0700528 priv->frames_count--;
529 }
530
531 if (priv->frames_count) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800532 IWL_WARN(priv, "%d frames still in use. Did we lose one?\n",
Zhu Yib481de92007-09-25 17:54:57 -0700533 priv->frames_count);
534 priv->frames_count = 0;
535 }
536}
537
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800538static struct iwl3945_frame *iwl3945_get_free_frame(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700539{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800540 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700541 struct list_head *element;
542 if (list_empty(&priv->free_frames)) {
543 frame = kzalloc(sizeof(*frame), GFP_KERNEL);
544 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800545 IWL_ERR(priv, "Could not allocate frame!\n");
Zhu Yib481de92007-09-25 17:54:57 -0700546 return NULL;
547 }
548
549 priv->frames_count++;
550 return frame;
551 }
552
553 element = priv->free_frames.next;
554 list_del(element);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800555 return list_entry(element, struct iwl3945_frame, list);
Zhu Yib481de92007-09-25 17:54:57 -0700556}
557
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800558static void iwl3945_free_frame(struct iwl_priv *priv, struct iwl3945_frame *frame)
Zhu Yib481de92007-09-25 17:54:57 -0700559{
560 memset(frame, 0, sizeof(*frame));
561 list_add(&frame->list, &priv->free_frames);
562}
563
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800564unsigned int iwl3945_fill_beacon_frame(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -0700565 struct ieee80211_hdr *hdr,
Rami Rosen73ec1cc2008-12-16 09:37:07 +0200566 int left)
Zhu Yib481de92007-09-25 17:54:57 -0700567{
568
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800569 if (!iwl_is_associated(priv) || !priv->ibss_beacon ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200570 ((priv->iw_mode != NL80211_IFTYPE_ADHOC) &&
571 (priv->iw_mode != NL80211_IFTYPE_AP)))
Zhu Yib481de92007-09-25 17:54:57 -0700572 return 0;
573
574 if (priv->ibss_beacon->len > left)
575 return 0;
576
577 memcpy(hdr, priv->ibss_beacon->data, priv->ibss_beacon->len);
578
579 return priv->ibss_beacon->len;
580}
581
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800582static int iwl3945_send_beacon_cmd(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700583{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800584 struct iwl3945_frame *frame;
Zhu Yib481de92007-09-25 17:54:57 -0700585 unsigned int frame_size;
586 int rc;
587 u8 rate;
588
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800589 frame = iwl3945_get_free_frame(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700590
591 if (!frame) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800592 IWL_ERR(priv, "Could not obtain free frame buffer for beacon "
Zhu Yib481de92007-09-25 17:54:57 -0700593 "command.\n");
594 return -ENOMEM;
595 }
596
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800597 rate = iwl_rate_get_lowest_plcp(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700598
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800599 frame_size = iwl3945_hw_get_beacon_cmd(priv, frame, rate);
Zhu Yib481de92007-09-25 17:54:57 -0700600
Samuel Ortiz518099a2009-01-19 15:30:27 -0800601 rc = iwl_send_cmd_pdu(priv, REPLY_TX_BEACON, frame_size,
Zhu Yib481de92007-09-25 17:54:57 -0700602 &frame->u.cmd[0]);
603
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800604 iwl3945_free_frame(priv, frame);
Zhu Yib481de92007-09-25 17:54:57 -0700605
606 return rc;
607}
608
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800609static void iwl3945_unset_hw_params(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700610{
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800611 if (priv->shared_virt)
Zhu Yib481de92007-09-25 17:54:57 -0700612 pci_free_consistent(priv->pci_dev,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800613 sizeof(struct iwl3945_shared),
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800614 priv->shared_virt,
615 priv->shared_phys);
Zhu Yib481de92007-09-25 17:54:57 -0700616}
617
Zhu Yib481de92007-09-25 17:54:57 -0700618/*
619 * QoS support
620*/
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800621static int iwl3945_send_qos_params_command(struct iwl_priv *priv,
Tomas Winkler4c897252008-12-19 10:37:05 +0800622 struct iwl_qosparam_cmd *qos)
Zhu Yib481de92007-09-25 17:54:57 -0700623{
624
Samuel Ortiz518099a2009-01-19 15:30:27 -0800625 return iwl_send_cmd_pdu(priv, REPLY_QOS_PARAM,
Tomas Winkler4c897252008-12-19 10:37:05 +0800626 sizeof(struct iwl_qosparam_cmd), qos);
Zhu Yib481de92007-09-25 17:54:57 -0700627}
628
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800629static void iwl3945_activate_qos(struct iwl_priv *priv, u8 force)
Zhu Yib481de92007-09-25 17:54:57 -0700630{
631 unsigned long flags;
632
Zhu Yib481de92007-09-25 17:54:57 -0700633 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
634 return;
635
Zhu Yib481de92007-09-25 17:54:57 -0700636 spin_lock_irqsave(&priv->lock, flags);
637 priv->qos_data.def_qos_parm.qos_flags = 0;
638
639 if (priv->qos_data.qos_cap.q_AP.queue_request &&
640 !priv->qos_data.qos_cap.q_AP.txop_request)
641 priv->qos_data.def_qos_parm.qos_flags |=
642 QOS_PARAM_FLG_TXOP_TYPE_MSK;
643
644 if (priv->qos_data.qos_active)
645 priv->qos_data.def_qos_parm.qos_flags |=
646 QOS_PARAM_FLG_UPDATE_EDCA_MSK;
647
648 spin_unlock_irqrestore(&priv->lock, flags);
649
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800650 if (force || iwl_is_associated(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800651 IWL_DEBUG_QOS(priv, "send QoS cmd with QoS active %d \n",
Zhu Yib481de92007-09-25 17:54:57 -0700652 priv->qos_data.qos_active);
653
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800654 iwl3945_send_qos_params_command(priv,
Zhu Yib481de92007-09-25 17:54:57 -0700655 &(priv->qos_data.def_qos_parm));
656 }
657}
658
Zhu Yib481de92007-09-25 17:54:57 -0700659
Zhu Yib481de92007-09-25 17:54:57 -0700660#define MAX_UCODE_BEACON_INTERVAL 1024
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -0800661#define INTEL_CONN_LISTEN_INTERVAL cpu_to_le16(0xA)
Zhu Yib481de92007-09-25 17:54:57 -0700662
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800663static __le16 iwl3945_adjust_beacon_interval(u16 beacon_val)
Zhu Yib481de92007-09-25 17:54:57 -0700664{
665 u16 new_val = 0;
666 u16 beacon_factor = 0;
667
668 beacon_factor =
669 (beacon_val + MAX_UCODE_BEACON_INTERVAL)
670 / MAX_UCODE_BEACON_INTERVAL;
671 new_val = beacon_val / beacon_factor;
672
673 return cpu_to_le16(new_val);
674}
675
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800676static void iwl3945_setup_rxon_timing(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700677{
678 u64 interval_tm_unit;
679 u64 tsf, result;
680 unsigned long flags;
681 struct ieee80211_conf *conf = NULL;
682 u16 beacon_int = 0;
683
684 conf = ieee80211_get_hw_conf(priv->hw);
685
686 spin_lock_irqsave(&priv->lock, flags);
Tomas Winkler28afaf92008-12-19 10:37:06 +0800687 priv->rxon_timing.timestamp = cpu_to_le64(priv->timestamp);
Zhu Yib481de92007-09-25 17:54:57 -0700688 priv->rxon_timing.listen_interval = INTEL_CONN_LISTEN_INTERVAL;
689
Tomas Winkler28afaf92008-12-19 10:37:06 +0800690 tsf = priv->timestamp;
Zhu Yib481de92007-09-25 17:54:57 -0700691
692 beacon_int = priv->beacon_int;
693 spin_unlock_irqrestore(&priv->lock, flags);
694
Johannes Berg05c914f2008-09-11 00:01:58 +0200695 if (priv->iw_mode == NL80211_IFTYPE_STATION) {
Zhu Yib481de92007-09-25 17:54:57 -0700696 if (beacon_int == 0) {
697 priv->rxon_timing.beacon_interval = cpu_to_le16(100);
698 priv->rxon_timing.beacon_init_val = cpu_to_le32(102400);
699 } else {
700 priv->rxon_timing.beacon_interval =
701 cpu_to_le16(beacon_int);
702 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800703 iwl3945_adjust_beacon_interval(
Zhu Yib481de92007-09-25 17:54:57 -0700704 le16_to_cpu(priv->rxon_timing.beacon_interval));
705 }
706
707 priv->rxon_timing.atim_window = 0;
708 } else {
709 priv->rxon_timing.beacon_interval =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800710 iwl3945_adjust_beacon_interval(conf->beacon_int);
Zhu Yib481de92007-09-25 17:54:57 -0700711 /* TODO: we need to get atim_window from upper stack
712 * for now we set to 0 */
713 priv->rxon_timing.atim_window = 0;
714 }
715
716 interval_tm_unit =
717 (le16_to_cpu(priv->rxon_timing.beacon_interval) * 1024);
718 result = do_div(tsf, interval_tm_unit);
719 priv->rxon_timing.beacon_init_val =
720 cpu_to_le32((u32) ((u64) interval_tm_unit - result));
721
Tomas Winklere1623442009-01-27 14:27:56 -0800722 IWL_DEBUG_ASSOC(priv,
723 "beacon interval %d beacon timer %d beacon tim %d\n",
Zhu Yib481de92007-09-25 17:54:57 -0700724 le16_to_cpu(priv->rxon_timing.beacon_interval),
725 le32_to_cpu(priv->rxon_timing.beacon_init_val),
726 le16_to_cpu(priv->rxon_timing.atim_window));
727}
728
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800729static int iwl3945_scan_initiate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -0700730{
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800731 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800732 IWL_DEBUG_SCAN(priv, "Aborting scan due to not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700733 return -EIO;
734 }
735
736 if (test_bit(STATUS_SCANNING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800737 IWL_DEBUG_SCAN(priv, "Scan already in progress.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700738 return -EAGAIN;
739 }
740
741 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800742 IWL_DEBUG_SCAN(priv, "Scan request while abort pending. "
Zhu Yib481de92007-09-25 17:54:57 -0700743 "Queuing.\n");
744 return -EAGAIN;
745 }
746
Tomas Winklere1623442009-01-27 14:27:56 -0800747 IWL_DEBUG_INFO(priv, "Starting scan...\n");
Ron Rindjunsky66b50042008-06-25 16:46:31 +0800748 if (priv->cfg->sku & IWL_SKU_G)
749 priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ);
750 if (priv->cfg->sku & IWL_SKU_A)
751 priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ);
Zhu Yib481de92007-09-25 17:54:57 -0700752 set_bit(STATUS_SCANNING, &priv->status);
753 priv->scan_start = jiffies;
754 priv->scan_pass_start = priv->scan_start;
755
756 queue_work(priv->workqueue, &priv->request_scan);
757
758 return 0;
759}
760
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800761static int iwl3945_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700762{
Johannes Berg05c914f2008-09-11 00:01:58 +0200763 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800764 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700765
Samuel Ortize6148912009-01-23 13:45:15 -0800766 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100767 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800768 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700769
770 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800771 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800772 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700773 return -EINVAL;
774 }
775 }
776
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800777 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700778
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800779 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700780
Tomas Winklera96a27f2008-10-23 23:48:56 -0700781 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800782 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800783 return -EAGAIN;
784
785 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800786 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800787 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800788 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800789 return -EAGAIN;
790 }
791
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800792 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700793
794 return 0;
795}
796
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800797static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200798 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800799 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700800 struct sk_buff *skb_frag,
801 int last_frag)
802{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800803 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200804 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800805 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700806
807 switch (keyinfo->alg) {
808 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800809 tx->sec_ctl = TX_CMD_SEC_CCM;
810 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800811 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700812 break;
813
814 case ALG_TKIP:
815#if 0
Winkler, Tomase52119c2008-12-22 11:31:19 +0800816 tx->sec_ctl = TX_CMD_SEC_TKIP;
Zhu Yib481de92007-09-25 17:54:57 -0700817
818 if (last_frag)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800819 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
Zhu Yib481de92007-09-25 17:54:57 -0700820 8);
821 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800822 memset(tx->tkip_mic.byte, 0, 8);
Zhu Yib481de92007-09-25 17:54:57 -0700823#endif
824 break;
825
826 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800827 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200828 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700829
830 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800831 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700832
Winkler, Tomase52119c2008-12-22 11:31:19 +0800833 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700834
Tomas Winklere1623442009-01-27 14:27:56 -0800835 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200836 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700837 break;
838
Zhu Yib481de92007-09-25 17:54:57 -0700839 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800840 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700841 break;
842 }
843}
844
845/*
846 * handle build REPLY_TX command notification.
847 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800848static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800849 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200850 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800851 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700852{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800853 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
854 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700855 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200856 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700857
Winkler, Tomase52119c2008-12-22 11:31:19 +0800858 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200859 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700860 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700861 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700862 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700863 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700864 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
865 tx_flags |= TX_CMD_FLG_TSF_MSK;
866 } else {
867 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
868 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
869 }
870
Winkler, Tomase52119c2008-12-22 11:31:19 +0800871 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700872 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700873 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
874
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700875 if (ieee80211_is_data_qos(fc)) {
876 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800877 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700878 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800879 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700880 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800881 }
Zhu Yib481de92007-09-25 17:54:57 -0700882
Johannes Berge6a98542008-10-21 12:40:02 +0200883 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700884 tx_flags |= TX_CMD_FLG_RTS_MSK;
885 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200886 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700887 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
888 tx_flags |= TX_CMD_FLG_CTS_MSK;
889 }
890
891 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
892 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
893
894 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700895 if (ieee80211_is_mgmt(fc)) {
896 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800897 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700898 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800899 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700900 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800901 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700902#ifdef CONFIG_IWL3945_LEDS
903 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
904#endif
905 }
Zhu Yib481de92007-09-25 17:54:57 -0700906
Winkler, Tomase52119c2008-12-22 11:31:19 +0800907 tx->driver_txop = 0;
908 tx->tx_flags = tx_flags;
909 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700910}
911
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800912/**
913 * iwl3945_get_sta_id - Find station's index within station table
914 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800915static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700916{
917 int sta_id;
918 u16 fc = le16_to_cpu(hdr->frame_control);
919
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800920 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700921 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
922 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800923 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700924
925 switch (priv->iw_mode) {
926
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800927 /* If we are a client station in a BSS network, use the special
928 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200929 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700930 return IWL_AP_ID;
931
932 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200933 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800934 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700935 if (sta_id != IWL_INVALID_STATION)
936 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800937 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700938
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800939 /* If this frame is going out to an IBSS network, find the station,
940 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200941 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800942 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800943 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700944 if (sta_id != IWL_INVALID_STATION)
945 return sta_id;
946
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800947 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700948
949 if (sta_id != IWL_INVALID_STATION)
950 return sta_id;
951
Tomas Winklere1623442009-01-27 14:27:56 -0800952 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700953 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700954 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800955 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800956 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700957 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800958 /* If we are in monitor mode, use BCAST. This is required for
959 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200960 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800961 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800962
Zhu Yib481de92007-09-25 17:54:57 -0700963 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800964 IWL_WARN(priv, "Unknown mode of operation: %d\n",
965 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800966 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700967 }
968}
969
970/*
971 * start REPLY_TX command process
972 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800973static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700974{
975 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200976 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800977 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800978 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800979 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800980 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700981 dma_addr_t phys_addr;
982 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800983 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800984 u16 len, idx, len_org, hdr_len;
985 u8 id;
986 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700987 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800988 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700989 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700990 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700991 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800992 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700993 unsigned long flags;
994 int rc;
995
996 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800997 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800998 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700999 goto drop_unlock;
1000 }
1001
Johannes Berge039fa42008-05-15 12:55:29 +02001002 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001003 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001004 goto drop_unlock;
1005 }
1006
1007 unicast = !is_multicast_ether_addr(hdr->addr1);
1008 id = 0;
1009
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001010 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -07001011
Samuel Ortizd08853a2009-01-23 13:45:17 -08001012#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07001013 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001014 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001015 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001016 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001017 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -08001018 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -07001019#endif
1020
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08001021 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +08001022 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +02001023 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001024 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +02001025 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -08001026 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -07001027 goto drop_unlock;
1028 }
1029
1030 spin_unlock_irqrestore(&priv->lock, flags);
1031
Harvey Harrison7294ec92008-07-15 18:43:59 -07001032 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001033
1034 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001035 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001036 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001037 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001038 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001039 goto drop;
1040 }
1041
Tomas Winklere1623442009-01-27 14:27:56 -08001042 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001043
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001044 if (ieee80211_is_data_qos(fc)) {
1045 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001046 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001047 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001048 IEEE80211_SCTL_SEQ;
1049 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1050 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001051 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -07001052 seq_number += 0x10;
1053 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001054
1055 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001056 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001057 q = &txq->q;
1058
1059 spin_lock_irqsave(&priv->lock, flags);
1060
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001061 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001062
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001063 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001064 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001065 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001066
1067 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001068 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001069 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001070 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001071 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001072
1073 /*
1074 * Set up the Tx-command (not MAC!) header.
1075 * Store the chosen Tx queue and TFD index within the sequence field;
1076 * after Tx, uCode's Tx response will return this value so driver can
1077 * locate the frame within the tx queue and do post-tx processing.
1078 */
Zhu Yib481de92007-09-25 17:54:57 -07001079 out_cmd->hdr.cmd = REPLY_TX;
1080 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001081 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001082
1083 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001084 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001085
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001086 /*
1087 * Use the first empty entry in this queue's command buffer array
1088 * to contain the Tx command and MAC header concatenated together
1089 * (payload data will be in another buffer).
1090 * Size of this varies, due to varying MAC header length.
1091 * If end is not dword aligned, we'll have 2 extra bytes at the end
1092 * of the MAC header (device reads on dword boundaries).
1093 * We'll tell device about this padding later.
1094 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001095 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001096 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001097
1098 len_org = len;
1099 len = (len + 3) & ~3;
1100
1101 if (len_org != len)
1102 len_org = 1;
1103 else
1104 len_org = 0;
1105
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001106 /* Physical address of this Tx command's header (not MAC header!),
1107 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001108 txcmd_phys = pci_map_single(priv->pci_dev,
1109 out_cmd, sizeof(struct iwl_cmd),
1110 PCI_DMA_TODEVICE);
1111 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1112 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1113 /* Add buffer containing Tx command and MAC(!) header to TFD's
1114 * first entry */
1115 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001116
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001117 /* Add buffer containing Tx command and MAC(!) header to TFD's
1118 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001119 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1120 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001121
Johannes Bergd0f09802008-07-29 11:32:07 +02001122 if (info->control.hw_key)
Johannes Berge039fa42008-05-15 12:55:29 +02001123 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001124
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001125 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1126 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001127 len = skb->len - hdr_len;
1128 if (len) {
1129 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1130 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001131 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1132 phys_addr, len,
1133 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001134 }
1135
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001136 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001137 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001138 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001139
1140 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001141 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001142
1143 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001144 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001145
Winkler, Tomase52119c2008-12-22 11:31:19 +08001146 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1147 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001148
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001149 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001150 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001151 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001152 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001153 } else {
1154 wait_write_ptr = 1;
1155 txq->need_update = 0;
1156 }
1157
Winkler, Tomase52119c2008-12-22 11:31:19 +08001158 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001159
Winkler, Tomase52119c2008-12-22 11:31:19 +08001160 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001161 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001162
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001163 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001164 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001165 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001166 spin_unlock_irqrestore(&priv->lock, flags);
1167
1168 if (rc)
1169 return rc;
1170
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001171 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001172 && priv->mac80211_registered) {
1173 if (wait_write_ptr) {
1174 spin_lock_irqsave(&priv->lock, flags);
1175 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001176 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001177 spin_unlock_irqrestore(&priv->lock, flags);
1178 }
1179
Johannes Berge2530082008-05-17 00:57:14 +02001180 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001181 }
1182
1183 return 0;
1184
1185drop_unlock:
1186 spin_unlock_irqrestore(&priv->lock, flags);
1187drop:
1188 return -1;
1189}
1190
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001191static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07001192{
1193 unsigned long flags;
1194
1195 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
1196 return;
1197
Tomas Winklere1623442009-01-27 14:27:56 -08001198 IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO %s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001199 disable_radio ? "OFF" : "ON");
1200
1201 if (disable_radio) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001202 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001203 /* FIXME: This is a workaround for AP */
Johannes Berg05c914f2008-09-11 00:01:58 +02001204 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07001205 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001206 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001207 CSR_UCODE_SW_BIT_RFKILL);
1208 spin_unlock_irqrestore(&priv->lock, flags);
Samuel Ortizc4962942008-12-22 11:31:18 +08001209 iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001210 set_bit(STATUS_RF_KILL_SW, &priv->status);
1211 }
1212 return;
1213 }
1214
1215 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001216 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07001217
1218 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1219 spin_unlock_irqrestore(&priv->lock, flags);
1220
1221 /* wake up ucode */
1222 msleep(10);
1223
1224 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001225 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1226 if (!iwl_grab_nic_access(priv))
1227 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001228 spin_unlock_irqrestore(&priv->lock, flags);
1229
1230 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001231 IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - "
Zhu Yib481de92007-09-25 17:54:57 -07001232 "disabled by HW switch\n");
1233 return;
1234 }
1235
Zhu Yi808e72a2008-06-12 09:47:17 +08001236 if (priv->is_open)
1237 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001238 return;
1239}
1240
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001241#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001242
1243#include "iwl-spectrum.h"
1244
1245#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1246#define BEACON_TIME_MASK_HIGH 0xFF000000
1247#define TIME_UNIT 1024
1248
1249/*
1250 * extended beacon time format
1251 * time in usec will be changed into a 32-bit value in 8:24 format
1252 * the high 1 byte is the beacon counts
1253 * the lower 3 bytes is the time in usec within one beacon interval
1254 */
1255
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001256static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001257{
1258 u32 quot;
1259 u32 rem;
1260 u32 interval = beacon_interval * 1024;
1261
1262 if (!interval || !usec)
1263 return 0;
1264
1265 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1266 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1267
1268 return (quot << 24) + rem;
1269}
1270
1271/* base is usually what we get from ucode with each received frame,
1272 * the same as HW timer counter counting down
1273 */
1274
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001275static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001276{
1277 u32 base_low = base & BEACON_TIME_MASK_LOW;
1278 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1279 u32 interval = beacon_interval * TIME_UNIT;
1280 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1281 (addon & BEACON_TIME_MASK_HIGH);
1282
1283 if (base_low > addon_low)
1284 res += base_low - addon_low;
1285 else if (base_low < addon_low) {
1286 res += interval + base_low - addon_low;
1287 res += (1 << 24);
1288 } else
1289 res += (1 << 24);
1290
1291 return cpu_to_le32(res);
1292}
1293
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001294static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001295 struct ieee80211_measurement_params *params,
1296 u8 type)
1297{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001298 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001299 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001300 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001301 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1302 .data = (void *)&spectrum,
1303 .meta.flags = CMD_WANT_SKB,
1304 };
1305 u32 add_time = le64_to_cpu(params->start_time);
1306 int rc;
1307 int spectrum_resp_status;
1308 int duration = le16_to_cpu(params->duration);
1309
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001310 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001311 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001312 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001313 le64_to_cpu(params->start_time) - priv->last_tsf,
1314 le16_to_cpu(priv->rxon_timing.beacon_interval));
1315
1316 memset(&spectrum, 0, sizeof(spectrum));
1317
1318 spectrum.channel_count = cpu_to_le16(1);
1319 spectrum.flags =
1320 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1321 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1322 cmd.len = sizeof(spectrum);
1323 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1324
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001325 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001326 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001327 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001328 add_time,
1329 le16_to_cpu(priv->rxon_timing.beacon_interval));
1330 else
1331 spectrum.start_time = 0;
1332
1333 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1334 spectrum.channels[0].channel = params->channel;
1335 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001336 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001337 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1338 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1339
Samuel Ortiz518099a2009-01-19 15:30:27 -08001340 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001341 if (rc)
1342 return rc;
1343
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001344 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001345 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001346 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001347 rc = -EIO;
1348 }
1349
1350 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1351 switch (spectrum_resp_status) {
1352 case 0: /* Command will be handled */
1353 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001354 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001355 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001356 priv->measurement_status &= ~MEASUREMENT_READY;
1357 }
1358 priv->measurement_status |= MEASUREMENT_ACTIVE;
1359 rc = 0;
1360 break;
1361
1362 case 1: /* Command will not be handled */
1363 rc = -EAGAIN;
1364 break;
1365 }
1366
1367 dev_kfree_skb_any(cmd.meta.u.skb);
1368
1369 return rc;
1370}
1371#endif
1372
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001373static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001374 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001375{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001376 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1377 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001378 struct delayed_work *pwork;
1379
1380 palive = &pkt->u.alive_frame;
1381
Tomas Winklere1623442009-01-27 14:27:56 -08001382 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001383 "0x%01X 0x%01X\n",
1384 palive->is_valid, palive->ver_type,
1385 palive->ver_subtype);
1386
1387 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001388 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001389 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1390 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001391 pwork = &priv->init_alive_start;
1392 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001393 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001394 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001395 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001396 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001397 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001398 }
1399
1400 /* We delay the ALIVE response by 5ms to
1401 * give the HW RF Kill time to activate... */
1402 if (palive->is_valid == UCODE_VALID_OK)
1403 queue_delayed_work(priv->workqueue, pwork,
1404 msecs_to_jiffies(5));
1405 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001406 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001407}
1408
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001409static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001410 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001411{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001412#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001413 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001414#endif
Zhu Yib481de92007-09-25 17:54:57 -07001415
Tomas Winklere1623442009-01-27 14:27:56 -08001416 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001417 return;
1418}
1419
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001420static void iwl3945_rx_reply_error(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001421 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001422{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001423 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001424
Winkler, Tomas15b16872008-12-19 10:37:33 +08001425 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -07001426 "seq 0x%04X ser 0x%08X\n",
1427 le32_to_cpu(pkt->u.err_resp.error_type),
1428 get_cmd_string(pkt->u.err_resp.cmd_id),
1429 pkt->u.err_resp.cmd_id,
1430 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1431 le32_to_cpu(pkt->u.err_resp.error_info));
1432}
1433
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001434static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001435 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001436{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001437#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001438 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001439 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001440
1441 if (!report->state) {
Tomas Winklere1623442009-01-27 14:27:56 -08001442 IWL_DEBUG(priv, IWL_DL_11H | IWL_DL_INFO,
Zhu Yib481de92007-09-25 17:54:57 -07001443 "Spectrum Measure Notification: Start\n");
1444 return;
1445 }
1446
1447 memcpy(&priv->measure_report, report, sizeof(*report));
1448 priv->measurement_status |= MEASUREMENT_READY;
1449#endif
1450}
1451
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001452static void iwl3945_rx_pm_sleep_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001453 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001454{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001455#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001456 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001457 struct iwl_sleep_notification *sleep = &(pkt->u.sleep_notif);
Tomas Winklere1623442009-01-27 14:27:56 -08001458 IWL_DEBUG_RX(priv, "sleep mode: %d, src: %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07001459 sleep->pm_sleep_mode, sleep->pm_wakeup_src);
1460#endif
1461}
1462
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001463static void iwl3945_rx_pm_debug_statistics_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001464 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001465{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001466 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winklere1623442009-01-27 14:27:56 -08001467 IWL_DEBUG_RADIO(priv, "Dumping %d bytes of unhandled "
Zhu Yib481de92007-09-25 17:54:57 -07001468 "notification for %s:\n",
1469 le32_to_cpu(pkt->len), get_cmd_string(pkt->hdr.cmd));
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08001470 iwl_print_hex_dump(priv, IWL_DL_RADIO, pkt->u.raw,
1471 le32_to_cpu(pkt->len));
Zhu Yib481de92007-09-25 17:54:57 -07001472}
1473
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001474static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001475{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001476 struct iwl_priv *priv =
1477 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001478 struct sk_buff *beacon;
1479
1480 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001481 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001482
1483 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001484 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001485 return;
1486 }
1487
1488 mutex_lock(&priv->mutex);
1489 /* new beacon skb is allocated every time; dispose previous.*/
1490 if (priv->ibss_beacon)
1491 dev_kfree_skb(priv->ibss_beacon);
1492
1493 priv->ibss_beacon = beacon;
1494 mutex_unlock(&priv->mutex);
1495
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001496 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001497}
1498
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001499static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001500 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001501{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001502#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001503 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001504 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001505 u8 rate = beacon->beacon_notify_hdr.rate;
1506
Tomas Winklere1623442009-01-27 14:27:56 -08001507 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001508 "tsf %d %d rate %d\n",
1509 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1510 beacon->beacon_notify_hdr.failure_frame,
1511 le32_to_cpu(beacon->ibss_mgr_status),
1512 le32_to_cpu(beacon->high_tsf),
1513 le32_to_cpu(beacon->low_tsf), rate);
1514#endif
1515
Johannes Berg05c914f2008-09-11 00:01:58 +02001516 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001517 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1518 queue_work(priv->workqueue, &priv->beacon_update);
1519}
1520
Zhu Yib481de92007-09-25 17:54:57 -07001521/* Handle notification from uCode that card's power state is changing
1522 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001523static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001524 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001525{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001526 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001527 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1528 unsigned long status = priv->status;
1529
Tomas Winklere1623442009-01-27 14:27:56 -08001530 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001531 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1532 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1533
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001534 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001535 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1536
1537 if (flags & HW_CARD_DISABLED)
1538 set_bit(STATUS_RF_KILL_HW, &priv->status);
1539 else
1540 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1541
1542
1543 if (flags & SW_CARD_DISABLED)
1544 set_bit(STATUS_RF_KILL_SW, &priv->status);
1545 else
1546 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1547
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001548 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001549
1550 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1551 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1552 (test_bit(STATUS_RF_KILL_SW, &status) !=
1553 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1554 queue_work(priv->workqueue, &priv->rf_kill);
1555 else
1556 wake_up_interruptible(&priv->wait_command_queue);
1557}
1558
1559/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001560 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001561 *
1562 * Setup the RX handlers for each of the reply types sent from the uCode
1563 * to the host.
1564 *
1565 * This function chains into the hardware specific files for them to setup
1566 * any hardware specific handlers as well.
1567 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001568static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001569{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001570 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1571 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
1572 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001573 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07001574 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001575 iwl3945_rx_spectrum_measure_notif;
1576 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl3945_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001577 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001578 iwl3945_rx_pm_debug_statistics_notif;
1579 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001580
Ben Cahill9fbab512007-11-29 11:09:47 +08001581 /*
1582 * The same handler is used for both the REPLY to a discrete
1583 * statistics request from the host as well as for the periodic
1584 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001585 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001586 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1587 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001588
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001589 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001590 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001591
Ben Cahill9fbab512007-11-29 11:09:47 +08001592 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001593 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001594}
1595
1596/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08001597 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1598 * When FW advances 'R' index, all entries between old and new 'R' index
1599 * need to be reclaimed.
1600 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001601static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001602 int txq_id, int index)
1603{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001604 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001605 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08001606 int nfreed = 0;
1607
Winkler, Tomas625a3812009-01-08 10:19:55 -08001608 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001609 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08001610 "is out of range [0-%d] %d %d.\n", txq_id,
1611 index, q->n_bd, q->write_ptr, q->read_ptr);
1612 return;
1613 }
1614
1615 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1616 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1617 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001618 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001619 q->write_ptr, q->read_ptr);
1620 queue_work(priv->workqueue, &priv->restart);
1621 break;
1622 }
1623 nfreed++;
1624 }
1625}
1626
1627
1628/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001629 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07001630 * @rxb: Rx buffer to reclaim
1631 *
1632 * If an Rx buffer has an async callback associated with it the callback
1633 * will be executed. The attached skb (if present) will only be freed
1634 * if the callback returns 1
1635 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001636static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001637 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001638{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001639 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001640 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1641 int txq_id = SEQ_TO_QUEUE(sequence);
1642 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08001643 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07001644 int cmd_index;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001645 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001646
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08001647 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1648 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1649 txq_id, sequence,
1650 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1651 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1652 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1653 return;
1654 }
Zhu Yib481de92007-09-25 17:54:57 -07001655
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001656 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1657 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07001658
1659 /* Input error checking is done when commands are added to queue. */
1660 if (cmd->meta.flags & CMD_WANT_SKB) {
1661 cmd->meta.source->u.skb = rxb->skb;
1662 rxb->skb = NULL;
1663 } else if (cmd->meta.u.callback &&
1664 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1665 rxb->skb = NULL;
1666
Tomas Winkler91c066f2008-03-06 17:36:55 -08001667 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07001668
1669 if (!(cmd->meta.flags & CMD_ASYNC)) {
1670 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1671 wake_up_interruptible(&priv->wait_command_queue);
1672 }
1673}
1674
1675/************************** RX-FUNCTIONS ****************************/
1676/*
1677 * Rx theory of operation
1678 *
1679 * The host allocates 32 DMA target addresses and passes the host address
1680 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1681 * 0 to 31
1682 *
1683 * Rx Queue Indexes
1684 * The host/firmware share two index registers for managing the Rx buffers.
1685 *
1686 * The READ index maps to the first position that the firmware may be writing
1687 * to -- the driver can read up to (but not including) this position and get
1688 * good data.
1689 * The READ index is managed by the firmware once the card is enabled.
1690 *
1691 * The WRITE index maps to the last position the driver has read from -- the
1692 * position preceding WRITE is the last slot the firmware can place a packet.
1693 *
1694 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1695 * WRITE = READ.
1696 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001697 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001698 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1699 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001700 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001701 * and fire the RX interrupt. The driver can then query the READ index and
1702 * process as many packets as possible, moving the WRITE index forward as it
1703 * resets the Rx queue buffers with new memory.
1704 *
1705 * The management in the driver is as follows:
1706 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1707 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001708 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001709 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001710 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1711 * 'processed' and 'read' driver indexes as well)
1712 * + A received packet is processed and handed to the kernel network stack,
1713 * detached from the iwl->rxq. The driver 'processed' index is updated.
1714 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1715 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1716 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1717 * were enough free buffers and RX_STALLED is set it is cleared.
1718 *
1719 *
1720 * Driver sequence:
1721 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001722 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001723 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001724 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001725 * queue, updates firmware pointers, and updates
1726 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001727 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001728 *
1729 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001730 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001731 * READ INDEX, detaching the SKB from the pool.
1732 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001733 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001734 * slots.
1735 * ...
1736 *
1737 */
1738
1739/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001740 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001741 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001742static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001743 dma_addr_t dma_addr)
1744{
1745 return cpu_to_le32((u32)dma_addr);
1746}
1747
1748/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001749 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001750 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001751 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001752 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001753 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001754 *
1755 * This moves the 'write' index forward to catch up with 'processed', and
1756 * also updates the memory address in the firmware to reference the new
1757 * target buffer.
1758 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001759static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001760{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001761 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001762 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001763 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001764 unsigned long flags;
1765 int write, rc;
1766
1767 spin_lock_irqsave(&rxq->lock, flags);
1768 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001769 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001770 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001771 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001772 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001773 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001774
1775 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001776 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001777 rxq->queue[rxq->write] = rxb;
1778 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1779 rxq->free_count--;
1780 }
1781 spin_unlock_irqrestore(&rxq->lock, flags);
1782 /* If the pre-allocated buffer pool is dropping low, schedule to
1783 * refill it */
1784 if (rxq->free_count <= RX_LOW_WATERMARK)
1785 queue_work(priv->workqueue, &priv->rx_replenish);
1786
1787
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001788 /* If we've added more space for the firmware to place data, tell it.
1789 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001790 if ((write != (rxq->write & ~0x7))
1791 || (abs(rxq->write - rxq->read) > 7)) {
1792 spin_lock_irqsave(&rxq->lock, flags);
1793 rxq->need_update = 1;
1794 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001795 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001796 if (rc)
1797 return rc;
1798 }
1799
1800 return 0;
1801}
1802
1803/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001804 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001805 *
1806 * When moving to rx_free an SKB is allocated for the slot.
1807 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001808 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001809 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001810 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001811static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001812{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001813 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001814 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001815 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001816 unsigned long flags;
1817 spin_lock_irqsave(&rxq->lock, flags);
1818 while (!list_empty(&rxq->rx_used)) {
1819 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001820 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001821
1822 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001823 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001824 alloc_skb(priv->hw_params.rx_buf_size,
1825 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001826 if (!rxb->skb) {
1827 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001828 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001829 /* We don't reschedule replenish work here -- we will
1830 * call the restock method and if it still needs
1831 * more buffers it will schedule replenish */
1832 break;
1833 }
Zhu Yi12342c42007-12-20 11:27:32 +08001834
1835 /* If radiotap head is required, reserve some headroom here.
1836 * The physical head count is a variable rx_stats->phy_count.
1837 * We reserve 4 bytes here. Plus these extra bytes, the
1838 * headroom of the physical head should be enough for the
1839 * radiotap head that iwl3945 supported. See iwl3945_rt.
1840 */
1841 skb_reserve(rxb->skb, 4);
1842
Zhu Yib481de92007-09-25 17:54:57 -07001843 priv->alloc_rxb_skb++;
1844 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001845
1846 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001847 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1848 rxb->skb->data,
1849 priv->hw_params.rx_buf_size,
1850 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001851 list_add_tail(&rxb->list, &rxq->rx_free);
1852 rxq->free_count++;
1853 }
1854 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001855}
1856
1857/*
1858 * this should be called while priv->lock is locked
1859 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001860static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001861{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001862 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001863
1864 iwl3945_rx_allocate(priv);
1865 iwl3945_rx_queue_restock(priv);
1866}
1867
1868
1869void iwl3945_rx_replenish(void *data)
1870{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001871 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001872 unsigned long flags;
1873
1874 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001875
1876 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001877 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001878 spin_unlock_irqrestore(&priv->lock, flags);
1879}
1880
Zhu Yib481de92007-09-25 17:54:57 -07001881/* Convert linear signal-to-noise ratio into dB */
1882static u8 ratio2dB[100] = {
1883/* 0 1 2 3 4 5 6 7 8 9 */
1884 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1885 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1886 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1887 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1888 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1889 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1890 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1891 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1892 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1893 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1894};
1895
1896/* Calculates a relative dB value from a ratio of linear
1897 * (i.e. not dB) signal levels.
1898 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001899int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001900{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001901 /* 1000:1 or higher just report as 60 dB */
1902 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001903 return 60;
1904
Adrian Bunk221c80c2008-02-02 23:19:01 +02001905 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001906 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001907 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001908 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001909
1910 /* We shouldn't see this */
1911 if (sig_ratio < 1)
1912 return 0;
1913
1914 /* Use table for ratios 1:1 - 99:1 */
1915 return (int)ratio2dB[sig_ratio];
1916}
1917
1918#define PERFECT_RSSI (-20) /* dBm */
1919#define WORST_RSSI (-95) /* dBm */
1920#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1921
1922/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1923 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1924 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001925int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001926{
1927 int sig_qual;
1928 int degradation = PERFECT_RSSI - rssi_dbm;
1929
1930 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1931 * as indicator; formula is (signal dbm - noise dbm).
1932 * SNR at or above 40 is a great signal (100%).
1933 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1934 * Weakest usable signal is usually 10 - 15 dB SNR. */
1935 if (noise_dbm) {
1936 if (rssi_dbm - noise_dbm >= 40)
1937 return 100;
1938 else if (rssi_dbm < noise_dbm)
1939 return 0;
1940 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1941
1942 /* Else use just the signal level.
1943 * This formula is a least squares fit of data points collected and
1944 * compared with a reference system that had a percentage (%) display
1945 * for signal quality. */
1946 } else
1947 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1948 (15 * RSSI_RANGE + 62 * degradation)) /
1949 (RSSI_RANGE * RSSI_RANGE);
1950
1951 if (sig_qual > 100)
1952 sig_qual = 100;
1953 else if (sig_qual < 1)
1954 sig_qual = 0;
1955
1956 return sig_qual;
1957}
1958
1959/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001960 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001961 *
1962 * Uses the priv->rx_handlers callback function array to invoke
1963 * the appropriate handlers, including command responses,
1964 * frame-received notifications, and other notifications.
1965 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001966static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001967{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001968 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001969 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001970 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001971 u32 r, i;
1972 int reclaim;
1973 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001974 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001975 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001976
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001977 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1978 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001979 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001980 i = rxq->read;
1981
Winkler, Tomas37d68312009-01-08 10:19:54 -08001982 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001983 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001984 /* Rx interrupt, but nothing sent from uCode */
1985 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001986 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001987
1988 while (i != r) {
1989 rxb = rxq->queue[i];
1990
Ben Cahill9fbab512007-11-29 11:09:47 +08001991 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001992 * then a bug has been introduced in the queue refilling
1993 * routines -- catch it here */
1994 BUG_ON(rxb == NULL);
1995
1996 rxq->queue[i] = NULL;
1997
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001998 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001999 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07002000 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08002001 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07002002
2003 /* Reclaim a command buffer only if this packet is a response
2004 * to a (driver-originated) command.
2005 * If the packet (e.g. Rx frame) originated from uCode,
2006 * there is no command buffer to reclaim.
2007 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
2008 * but apparently a few don't get set; catch them here. */
2009 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
2010 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
2011 (pkt->hdr.cmd != REPLY_TX);
2012
2013 /* Based on type of command response or notification,
2014 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002015 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07002016 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08002017 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07002018 "r = %d, i = %d, %s, 0x%02x\n", r, i,
2019 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
2020 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
2021 } else {
2022 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08002023 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07002024 "r %d i %d No handler needed for %s, 0x%02x\n",
2025 r, i, get_cmd_string(pkt->hdr.cmd),
2026 pkt->hdr.cmd);
2027 }
2028
2029 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002030 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08002031 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07002032 * as we reclaim the driver command queue */
2033 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002034 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07002035 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002036 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07002037 }
2038
2039 /* For now we just don't re-use anything. We can tweak this
2040 * later to try and re-use notification packets and SKBs that
2041 * fail to Rx correctly */
2042 if (rxb->skb != NULL) {
2043 priv->alloc_rxb_skb--;
2044 dev_kfree_skb_any(rxb->skb);
2045 rxb->skb = NULL;
2046 }
2047
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08002048 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08002049 priv->hw_params.rx_buf_size,
2050 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07002051 spin_lock_irqsave(&rxq->lock, flags);
2052 list_add_tail(&rxb->list, &priv->rxq.rx_used);
2053 spin_unlock_irqrestore(&rxq->lock, flags);
2054 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002055 /* If there are a lot of unused frames,
2056 * restock the Rx queue so ucode won't assert. */
2057 if (fill_rx) {
2058 count++;
2059 if (count >= 8) {
2060 priv->rxq.read = i;
2061 __iwl3945_rx_replenish(priv);
2062 count = 0;
2063 }
2064 }
Zhu Yib481de92007-09-25 17:54:57 -07002065 }
2066
2067 /* Backtrack one entry */
2068 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002069 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002070}
2071
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002072static void iwl3945_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002073{
Tomas Winklere1623442009-01-27 14:27:56 -08002074 IWL_DEBUG_ISR(priv, "Enabling interrupts\n");
Zhu Yib481de92007-09-25 17:54:57 -07002075 set_bit(STATUS_INT_ENABLED, &priv->status);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002076 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07002077}
2078
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002079
2080/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002081static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002082{
Tomas Winklera96a27f2008-10-23 23:48:56 -07002083 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002084 synchronize_irq(priv->pci_dev->irq);
2085 tasklet_kill(&priv->irq_tasklet);
2086}
2087
2088
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002089static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002090{
2091 clear_bit(STATUS_INT_ENABLED, &priv->status);
2092
2093 /* disable interrupts from uCode/NIC to host */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002094 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002095
2096 /* acknowledge/clear/reset any interrupts still pending
2097 * from uCode or flow handler (Rx/Tx DMA) */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002098 iwl_write32(priv, CSR_INT, 0xffffffff);
2099 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Tomas Winklere1623442009-01-27 14:27:56 -08002100 IWL_DEBUG_ISR(priv, "Disabled interrupts\n");
Zhu Yib481de92007-09-25 17:54:57 -07002101}
2102
2103static const char *desc_lookup(int i)
2104{
2105 switch (i) {
2106 case 1:
2107 return "FAIL";
2108 case 2:
2109 return "BAD_PARAM";
2110 case 3:
2111 return "BAD_CHECKSUM";
2112 case 4:
2113 return "NMI_INTERRUPT";
2114 case 5:
2115 return "SYSASSERT";
2116 case 6:
2117 return "FATAL_ERROR";
2118 }
2119
2120 return "UNKNOWN";
2121}
2122
2123#define ERROR_START_OFFSET (1 * sizeof(u32))
2124#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2125
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002126static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002127{
2128 u32 i;
2129 u32 desc, time, count, base, data1;
2130 u32 blink1, blink2, ilink1, ilink2;
2131 int rc;
2132
2133 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2134
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002135 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002136 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002137 return;
2138 }
2139
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002140 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002141 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002142 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002143 return;
2144 }
2145
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002146 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002147
2148 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002149 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2150 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2151 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002152 }
2153
Winkler, Tomas15b16872008-12-19 10:37:33 +08002154 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002155 "ilink1 nmiPC Line\n");
2156 for (i = ERROR_START_OFFSET;
2157 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2158 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002159 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002160 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002161 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002162 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002163 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002164 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002165 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002166 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002167 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002168 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002169 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002170 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002171 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002172
Winkler, Tomas15b16872008-12-19 10:37:33 +08002173 IWL_ERR(priv,
2174 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2175 desc_lookup(desc), desc, time, blink1, blink2,
2176 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002177 }
2178
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002179 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002180
2181}
2182
Ben Cahillf58177b2007-11-29 11:09:43 +08002183#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002184
2185/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002186 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002187 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002188 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002189 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002190static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002191 u32 num_events, u32 mode)
2192{
2193 u32 i;
2194 u32 base; /* SRAM byte address of event log header */
2195 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2196 u32 ptr; /* SRAM byte address of log data */
2197 u32 ev, time, data; /* event log data */
2198
2199 if (num_events == 0)
2200 return;
2201
2202 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2203
2204 if (mode == 0)
2205 event_size = 2 * sizeof(u32);
2206 else
2207 event_size = 3 * sizeof(u32);
2208
2209 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2210
2211 /* "time" is actually "data" for mode 0 (no timestamp).
2212 * place event id # at far right for easier visual parsing. */
2213 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002214 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002215 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002216 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002217 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002218 if (mode == 0) {
2219 /* data, ev */
2220 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2221 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002222 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002223 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002224 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002225 }
2226 }
2227}
2228
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002229static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002230{
2231 int rc;
2232 u32 base; /* SRAM byte address of event log header */
2233 u32 capacity; /* event log capacity in # entries */
2234 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2235 u32 num_wraps; /* # times uCode wrapped to top of log */
2236 u32 next_entry; /* index of next entry to be written by uCode */
2237 u32 size; /* # entries that we'll print */
2238
2239 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002240 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002241 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002242 return;
2243 }
2244
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002245 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002246 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002247 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002248 return;
2249 }
2250
2251 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002252 capacity = iwl_read_targ_mem(priv, base);
2253 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2254 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2255 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002256
2257 size = num_wraps ? capacity : next_entry;
2258
2259 /* bail out if nothing in log */
2260 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002261 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002262 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002263 return;
2264 }
2265
Winkler, Tomas15b16872008-12-19 10:37:33 +08002266 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002267 size, num_wraps);
2268
2269 /* if uCode has wrapped back to top of log, start at the oldest entry,
2270 * i.e the next one that uCode would fill. */
2271 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002272 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002273 capacity - next_entry, mode);
2274
2275 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002276 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002277
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002278 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002279}
2280
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002281static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002282{
2283 unsigned long flags;
2284
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002285 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2286 sizeof(priv->staging_rxon));
2287 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002288 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002289
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002290 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002291
2292 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002293 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002294 priv->error_recovering = 0;
2295 spin_unlock_irqrestore(&priv->lock, flags);
2296}
2297
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002298static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002299{
2300 u32 inta, handled = 0;
2301 u32 inta_fh;
2302 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002303#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002304 u32 inta_mask;
2305#endif
2306
2307 spin_lock_irqsave(&priv->lock, flags);
2308
2309 /* Ack/clear/reset pending uCode interrupts.
2310 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2311 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002312 inta = iwl_read32(priv, CSR_INT);
2313 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002314
2315 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2316 * Any new interrupts that happen after this, either while we're
2317 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002318 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2319 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002320
Samuel Ortizd08853a2009-01-23 13:45:17 -08002321#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002322 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002323 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002324 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002325 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002326 inta, inta_mask, inta_fh);
2327 }
2328#endif
2329
2330 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2331 * atomic, make sure that inta covers all the interrupts that
2332 * we've discovered, even if FH interrupt came in just after
2333 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002334 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002335 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002336 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002337 inta |= CSR_INT_BIT_FH_TX;
2338
2339 /* Now service all interrupt bits discovered above. */
2340 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002341 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002342
2343 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002344 iwl3945_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002345
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002346 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002347
2348 handled |= CSR_INT_BIT_HW_ERR;
2349
2350 spin_unlock_irqrestore(&priv->lock, flags);
2351
2352 return;
2353 }
2354
Samuel Ortizd08853a2009-01-23 13:45:17 -08002355#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002356 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002357 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002358 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002359 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002360 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002361
2362 /* Alive notification via Rx interrupt will do the real work */
2363 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002364 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002365 }
2366#endif
2367 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002368 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002369
Zhu Yib481de92007-09-25 17:54:57 -07002370 /* Error detected by uCode */
2371 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002372 IWL_ERR(priv, "Microcode SW error detected. "
2373 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002374 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002375 handled |= CSR_INT_BIT_SW_ERR;
2376 }
2377
2378 /* uCode wakes up after power-down sleep */
2379 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002380 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002381 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002382 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2383 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2384 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2385 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2386 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2387 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002388
2389 handled |= CSR_INT_BIT_WAKEUP;
2390 }
2391
2392 /* All uCode command responses, including Tx command responses,
2393 * Rx "responses" (frame-received notification), and other
2394 * notifications from uCode come through here*/
2395 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002396 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002397 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2398 }
2399
2400 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002401 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002402
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002403 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2404 if (!iwl_grab_nic_access(priv)) {
2405 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002406 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002407 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002408 }
2409 handled |= CSR_INT_BIT_FH_TX;
2410 }
2411
2412 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002413 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002414
2415 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002416 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002417 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002418 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002419 }
2420
2421 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002422 /* only Re-enable if disabled by irq */
2423 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2424 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002425
Samuel Ortizd08853a2009-01-23 13:45:17 -08002426#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002427 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002428 inta = iwl_read32(priv, CSR_INT);
2429 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2430 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002431 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002432 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2433 }
2434#endif
2435 spin_unlock_irqrestore(&priv->lock, flags);
2436}
2437
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002438static irqreturn_t iwl3945_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07002439{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002440 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07002441 u32 inta, inta_mask;
2442 u32 inta_fh;
2443 if (!priv)
2444 return IRQ_NONE;
2445
2446 spin_lock(&priv->lock);
2447
2448 /* Disable (but don't clear!) interrupts here to avoid
2449 * back-to-back ISRs and sporadic interrupts from our NIC.
2450 * If we have something to service, the tasklet will re-enable ints.
2451 * If we *don't* have something, we'll re-enable before leaving here. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002452 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
2453 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002454
2455 /* Discover which interrupts are active/pending */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002456 inta = iwl_read32(priv, CSR_INT);
2457 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07002458
2459 /* Ignore interrupt if there's nothing in NIC to service.
2460 * This may be due to IRQ shared with another device,
2461 * or due to sporadic interrupts thrown from our NIC. */
2462 if (!inta && !inta_fh) {
Tomas Winklere1623442009-01-27 14:27:56 -08002463 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
Zhu Yib481de92007-09-25 17:54:57 -07002464 goto none;
2465 }
2466
2467 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
2468 /* Hardware disappeared */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002469 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002470 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07002471 }
2472
Tomas Winklere1623442009-01-27 14:27:56 -08002473 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002474 inta, inta_mask, inta_fh);
2475
Joonwoo Park25c03d82008-01-23 10:15:20 -08002476 inta &= ~CSR_INT_BIT_SCD;
2477
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002478 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002479 if (likely(inta || inta_fh))
2480 tasklet_schedule(&priv->irq_tasklet);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002481unplugged:
Zhu Yib481de92007-09-25 17:54:57 -07002482 spin_unlock(&priv->lock);
2483
2484 return IRQ_HANDLED;
2485
2486 none:
2487 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002488 /* only Re-enable if disabled by irq */
2489 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2490 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002491 spin_unlock(&priv->lock);
2492 return IRQ_NONE;
2493}
2494
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002495static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002496 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002497 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002498 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002499{
2500 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002501 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002502 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002503 u16 passive_dwell = 0;
2504 u16 active_dwell = 0;
2505 int added, i;
2506
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002507 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002508 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002509 return 0;
2510
Johannes Berg8318d782008-01-24 19:38:38 +01002511 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002512
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002513 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2514 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002515
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002516 if (passive_dwell <= active_dwell)
2517 passive_dwell = active_dwell + 1;
2518
Johannes Berg8318d782008-01-24 19:38:38 +01002519 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002520 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2521 continue;
2522
Johannes Berg8318d782008-01-24 19:38:38 +01002523 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002524
Samuel Ortize6148912009-01-23 13:45:15 -08002525 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002526 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002527 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002528 scan_ch->channel);
2529 continue;
2530 }
2531
Zhu Yib481de92007-09-25 17:54:57 -07002532 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2533 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002534 /* If passive , set up for auto-switch
2535 * and use long active_dwell time.
2536 */
2537 if (!is_active || is_channel_passive(ch_info) ||
2538 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2539 scan_ch->type = 0; /* passive */
2540 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2541 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2542 } else {
2543 scan_ch->type = 1; /* active */
2544 }
2545
2546 /* Set direct probe bits. These may be used both for active
2547 * scan channels (probes gets sent right away),
2548 * or for passive channels (probes get se sent only after
2549 * hearing clear Rx packet).*/
2550 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2551 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002552 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002553 } else {
2554 /* uCode v1 does not allow setting direct probe bits on
2555 * passive channel. */
2556 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002557 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002558 }
Zhu Yib481de92007-09-25 17:54:57 -07002559
Ben Cahill9fbab512007-11-29 11:09:47 +08002560 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002561 scan_ch->tpc.dsp_atten = 110;
2562 /* scan_pwr_info->tpc.dsp_atten; */
2563
2564 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002565 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002566 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2567 else {
2568 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2569 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002570 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002571 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002572 */
2573 }
2574
Tomas Winklere1623442009-01-27 14:27:56 -08002575 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002576 scan_ch->channel,
2577 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2578 (scan_ch->type & 1) ?
2579 active_dwell : passive_dwell);
2580
2581 scan_ch++;
2582 added++;
2583 }
2584
Tomas Winklere1623442009-01-27 14:27:56 -08002585 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002586 return added;
2587}
2588
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002589static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002590 struct ieee80211_rate *rates)
2591{
2592 int i;
2593
2594 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002595 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2596 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2597 rates[i].hw_value_short = i;
2598 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002599 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002600 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002601 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002602 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002603 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002604 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002605 }
Zhu Yib481de92007-09-25 17:54:57 -07002606 }
2607}
2608
Zhu Yib481de92007-09-25 17:54:57 -07002609/******************************************************************************
2610 *
2611 * uCode download functions
2612 *
2613 ******************************************************************************/
2614
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002615static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002616{
Tomas Winkler98c92212008-01-14 17:46:20 -08002617 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2618 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2619 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2620 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2621 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2622 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002623}
2624
2625/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002626 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002627 * looking at all data.
2628 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002629static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002630{
2631 u32 val;
2632 u32 save_len = len;
2633 int rc = 0;
2634 u32 errcnt;
2635
Tomas Winklere1623442009-01-27 14:27:56 -08002636 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002637
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002638 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002639 if (rc)
2640 return rc;
2641
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002642 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002643 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002644
2645 errcnt = 0;
2646 for (; len > 0; len -= sizeof(u32), image++) {
2647 /* read data comes through single port, auto-incr addr */
2648 /* NOTE: Use the debugless read so we don't flood kernel log
2649 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002650 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002651 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002652 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002653 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2654 save_len - len, val, le32_to_cpu(*image));
2655 rc = -EIO;
2656 errcnt++;
2657 if (errcnt >= 20)
2658 break;
2659 }
2660 }
2661
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002662 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002663
2664 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002665 IWL_DEBUG_INFO(priv,
2666 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002667
2668 return rc;
2669}
2670
2671
2672/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002673 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002674 * using sample data 100 bytes apart. If these sample points are good,
2675 * it's a pretty good bet that everything between them is good, too.
2676 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002677static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002678{
2679 u32 val;
2680 int rc = 0;
2681 u32 errcnt = 0;
2682 u32 i;
2683
Tomas Winklere1623442009-01-27 14:27:56 -08002684 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002685
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002686 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002687 if (rc)
2688 return rc;
2689
2690 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2691 /* read data comes through single port, auto-incr addr */
2692 /* NOTE: Use the debugless read so we don't flood kernel log
2693 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002694 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002695 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002696 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002697 if (val != le32_to_cpu(*image)) {
2698#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002699 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002700 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2701 i, val, *image);
2702#endif
2703 rc = -EIO;
2704 errcnt++;
2705 if (errcnt >= 3)
2706 break;
2707 }
2708 }
2709
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002710 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002711
2712 return rc;
2713}
2714
2715
2716/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002717 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002718 * and verify its contents
2719 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002720static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002721{
2722 __le32 *image;
2723 u32 len;
2724 int rc = 0;
2725
2726 /* Try bootstrap */
2727 image = (__le32 *)priv->ucode_boot.v_addr;
2728 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002729 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002730 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002731 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002732 return 0;
2733 }
2734
2735 /* Try initialize */
2736 image = (__le32 *)priv->ucode_init.v_addr;
2737 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002738 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002739 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002740 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002741 return 0;
2742 }
2743
2744 /* Try runtime/protocol */
2745 image = (__le32 *)priv->ucode_code.v_addr;
2746 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002747 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002748 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002749 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002750 return 0;
2751 }
2752
Winkler, Tomas15b16872008-12-19 10:37:33 +08002753 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002754
Ben Cahill9fbab512007-11-29 11:09:47 +08002755 /* Since nothing seems to match, show first several data entries in
2756 * instruction SRAM, so maybe visual inspection will give a clue.
2757 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002758 image = (__le32 *)priv->ucode_boot.v_addr;
2759 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002760 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002761
2762 return rc;
2763}
2764
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002765static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002766{
2767 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002768 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002769}
2770
2771/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002772 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002773 *
2774 * Copy into buffers for card to fetch via bus-mastering
2775 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002776static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002777{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002778 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002779 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002780 const struct firmware *ucode_raw;
2781 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002782 const char *name_pre = priv->cfg->fw_name_pre;
2783 const unsigned int api_max = priv->cfg->ucode_api_max;
2784 const unsigned int api_min = priv->cfg->ucode_api_min;
2785 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002786 u8 *src;
2787 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002788 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002789
2790 /* Ask kernel firmware_class module to get the boot firmware off disk.
2791 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002792 for (index = api_max; index >= api_min; index--) {
2793 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2794 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2795 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002796 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002797 buf, ret);
2798 if (ret == -ENOENT)
2799 continue;
2800 else
2801 goto error;
2802 } else {
2803 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002804 IWL_ERR(priv, "Loaded firmware %s, "
2805 "which is deprecated. "
2806 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002807 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002808 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2809 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002810 buf, ucode_raw->size);
2811 break;
2812 }
Zhu Yib481de92007-09-25 17:54:57 -07002813 }
2814
Reinette Chatrea0987a82008-12-02 12:14:06 -08002815 if (ret < 0)
2816 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002817
2818 /* Make sure that we got at least our header! */
2819 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002820 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002821 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002822 goto err_release;
2823 }
2824
2825 /* Data from ucode file: header followed by uCode images */
2826 ucode = (void *)ucode_raw->data;
2827
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002828 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002829 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002830 inst_size = le32_to_cpu(ucode->inst_size);
2831 data_size = le32_to_cpu(ucode->data_size);
2832 init_size = le32_to_cpu(ucode->init_size);
2833 init_data_size = le32_to_cpu(ucode->init_data_size);
2834 boot_size = le32_to_cpu(ucode->boot_size);
2835
Reinette Chatrea0987a82008-12-02 12:14:06 -08002836 /* api_ver should match the api version forming part of the
2837 * firmware filename ... but we don't check for that and only rely
2838 * on the API version read from firware header from here on forward */
2839
2840 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002841 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002842 "Driver supports v%u, firmware is v%u.\n",
2843 api_max, api_ver);
2844 priv->ucode_ver = 0;
2845 ret = -EINVAL;
2846 goto err_release;
2847 }
2848 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002849 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002850 "got %u. New firmware can be obtained "
2851 "from http://www.intellinuxwireless.org.\n",
2852 api_max, api_ver);
2853
Tomas Winkler978785a2008-12-19 10:37:31 +08002854 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2855 IWL_UCODE_MAJOR(priv->ucode_ver),
2856 IWL_UCODE_MINOR(priv->ucode_ver),
2857 IWL_UCODE_API(priv->ucode_ver),
2858 IWL_UCODE_SERIAL(priv->ucode_ver));
2859
Tomas Winklere1623442009-01-27 14:27:56 -08002860 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002861 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002862 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2863 inst_size);
2864 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2865 data_size);
2866 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2867 init_size);
2868 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2869 init_data_size);
2870 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2871 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002872
Reinette Chatrea0987a82008-12-02 12:14:06 -08002873
Zhu Yib481de92007-09-25 17:54:57 -07002874 /* Verify size of file vs. image size info in file's header */
2875 if (ucode_raw->size < sizeof(*ucode) +
2876 inst_size + data_size + init_size +
2877 init_data_size + boot_size) {
2878
Tomas Winklere1623442009-01-27 14:27:56 -08002879 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2880 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002881 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002882 goto err_release;
2883 }
2884
2885 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002886 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002887 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002888 inst_size);
2889 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002890 goto err_release;
2891 }
2892
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002893 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002894 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002895 data_size);
2896 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002897 goto err_release;
2898 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002899 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002900 IWL_DEBUG_INFO(priv,
2901 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002902 init_size);
2903 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002904 goto err_release;
2905 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002906 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002907 IWL_DEBUG_INFO(priv,
2908 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002909 init_data_size);
2910 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002911 goto err_release;
2912 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002913 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002914 IWL_DEBUG_INFO(priv,
2915 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002916 boot_size);
2917 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002918 goto err_release;
2919 }
2920
2921 /* Allocate ucode buffers for card's bus-master loading ... */
2922
2923 /* Runtime instructions and 2 copies of data:
2924 * 1) unmodified from disk
2925 * 2) backup cache for save/restore during power-downs */
2926 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002927 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002928
2929 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002930 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002931
2932 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002933 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002934
2935 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002936 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002937 goto err_pci_alloc;
2938
Tomas Winkler90e759d2007-11-29 11:09:41 +08002939 /* Initialization instructions and data */
2940 if (init_size && init_data_size) {
2941 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002942 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002943
2944 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002945 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002946
2947 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2948 goto err_pci_alloc;
2949 }
2950
2951 /* Bootstrap (instructions only, no data) */
2952 if (boot_size) {
2953 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002954 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002955
2956 if (!priv->ucode_boot.v_addr)
2957 goto err_pci_alloc;
2958 }
2959
Zhu Yib481de92007-09-25 17:54:57 -07002960 /* Copy images into buffers for card's bus-master reads ... */
2961
2962 /* Runtime instructions (first block of data in file) */
2963 src = &ucode->data[0];
2964 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002965 IWL_DEBUG_INFO(priv,
2966 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002967 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002968 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002969 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2970
2971 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002972 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002973 src = &ucode->data[inst_size];
2974 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002975 IWL_DEBUG_INFO(priv,
2976 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002977 memcpy(priv->ucode_data.v_addr, src, len);
2978 memcpy(priv->ucode_data_backup.v_addr, src, len);
2979
2980 /* Initialization instructions (3rd block) */
2981 if (init_size) {
2982 src = &ucode->data[inst_size + data_size];
2983 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002984 IWL_DEBUG_INFO(priv,
2985 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002986 memcpy(priv->ucode_init.v_addr, src, len);
2987 }
2988
2989 /* Initialization data (4th block) */
2990 if (init_data_size) {
2991 src = &ucode->data[inst_size + data_size + init_size];
2992 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002993 IWL_DEBUG_INFO(priv,
2994 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002995 memcpy(priv->ucode_init_data.v_addr, src, len);
2996 }
2997
2998 /* Bootstrap instructions (5th block) */
2999 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
3000 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08003001 IWL_DEBUG_INFO(priv,
3002 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07003003 memcpy(priv->ucode_boot.v_addr, src, len);
3004
3005 /* We have our copies now, allow OS release its copies */
3006 release_firmware(ucode_raw);
3007 return 0;
3008
3009 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003010 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08003011 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003012 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003013
3014 err_release:
3015 release_firmware(ucode_raw);
3016
3017 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08003018 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003019}
3020
3021
3022/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003023 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07003024 *
3025 * Tell initialization uCode where to find runtime uCode.
3026 *
3027 * BSM registers initially contain pointers to initialization uCode.
3028 * We need to replace them to load runtime uCode inst and data,
3029 * and to save runtime data when powering down.
3030 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003031static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003032{
3033 dma_addr_t pinst;
3034 dma_addr_t pdata;
3035 int rc = 0;
3036 unsigned long flags;
3037
3038 /* bits 31:0 for 3945 */
3039 pinst = priv->ucode_code.p_addr;
3040 pdata = priv->ucode_data_backup.p_addr;
3041
3042 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003043 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003044 if (rc) {
3045 spin_unlock_irqrestore(&priv->lock, flags);
3046 return rc;
3047 }
3048
3049 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003050 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
3051 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
3052 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003053 priv->ucode_data.len);
3054
Tomas Winklera96a27f2008-10-23 23:48:56 -07003055 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07003056 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003057 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003058 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
3059
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003060 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003061
3062 spin_unlock_irqrestore(&priv->lock, flags);
3063
Tomas Winklere1623442009-01-27 14:27:56 -08003064 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003065
3066 return rc;
3067}
3068
3069/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003070 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003071 *
3072 * Called after REPLY_ALIVE notification received from "initialize" uCode.
3073 *
Zhu Yib481de92007-09-25 17:54:57 -07003074 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08003075 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003076static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003077{
3078 /* Check alive response for "valid" sign from uCode */
3079 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
3080 /* We had an error bringing up the hardware, so take it
3081 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003082 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003083 goto restart;
3084 }
3085
3086 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
3087 * This is a paranoid check, because we would not have gotten the
3088 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003089 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003090 /* Runtime instruction load was bad;
3091 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003092 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003093 goto restart;
3094 }
3095
3096 /* Send pointers to protocol/runtime uCode image ... init code will
3097 * load and launch runtime uCode, which will send us another "Alive"
3098 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08003099 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003100 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003101 /* Runtime instruction load won't happen;
3102 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003103 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003104 goto restart;
3105 }
3106 return;
3107
3108 restart:
3109 queue_work(priv->workqueue, &priv->restart);
3110}
3111
3112
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003113/* temporary */
3114static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
3115 struct sk_buff *skb);
3116
Zhu Yib481de92007-09-25 17:54:57 -07003117/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003118 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003119 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003120 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07003121 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003122static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003123{
3124 int rc = 0;
3125 int thermal_spin = 0;
3126 u32 rfkill;
3127
Tomas Winklere1623442009-01-27 14:27:56 -08003128 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003129
3130 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
3131 /* We had an error bringing up the hardware, so take it
3132 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003133 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003134 goto restart;
3135 }
3136
3137 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
3138 * This is a paranoid check, because we would not have gotten the
3139 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003140 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003141 /* Runtime instruction load was bad;
3142 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003143 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003144 goto restart;
3145 }
3146
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003147 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003148
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003149 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003150 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003151 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003152 return;
3153 }
3154
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003155 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08003156 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003157 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003158
3159 if (rfkill & 0x1) {
3160 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07003161 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07003162 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003163 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07003164 thermal_spin++;
3165 udelay(10);
3166 }
3167
3168 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08003169 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07003170 thermal_spin * 10);
3171 } else
3172 set_bit(STATUS_RF_KILL_HW, &priv->status);
3173
Ben Cahill9fbab512007-11-29 11:09:47 +08003174 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07003175 set_bit(STATUS_ALIVE, &priv->status);
3176
3177 /* Clear out the uCode error bit if it is set */
3178 clear_bit(STATUS_FW_ERROR, &priv->status);
3179
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003180 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003181 return;
3182
Johannes Berg36d68252008-05-15 12:55:26 +02003183 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003184
3185 priv->active_rate = priv->rates_mask;
3186 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3187
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003188 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07003189
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003190 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003191 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003192 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003193
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003194 memcpy(&priv->staging_rxon, &priv->active_rxon,
3195 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003196 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3197 } else {
3198 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003199 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003200 }
3201
Ben Cahill9fbab512007-11-29 11:09:47 +08003202 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003203 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003204
3205 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003206 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003207
Zhu Yib481de92007-09-25 17:54:57 -07003208 iwl3945_reg_txpower_periodic(priv);
3209
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003210 iwl3945_led_register(priv);
3211
Tomas Winklere1623442009-01-27 14:27:56 -08003212 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003213 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003214 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003215
3216 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003217 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003218
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003219 /* reassociate for ADHOC mode */
3220 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3221 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3222 priv->vif);
3223 if (beacon)
3224 iwl3945_mac_beacon_update(priv->hw, beacon);
3225 }
3226
Zhu Yib481de92007-09-25 17:54:57 -07003227 return;
3228
3229 restart:
3230 queue_work(priv->workqueue, &priv->restart);
3231}
3232
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003233static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003234
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003235static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003236{
3237 unsigned long flags;
3238 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3239 struct ieee80211_conf *conf = NULL;
3240
Tomas Winklere1623442009-01-27 14:27:56 -08003241 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003242
3243 conf = ieee80211_get_hw_conf(priv->hw);
3244
3245 if (!exit_pending)
3246 set_bit(STATUS_EXIT_PENDING, &priv->status);
3247
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003248 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003249 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003250
3251 /* Unblock any waiting calls */
3252 wake_up_interruptible_all(&priv->wait_command_queue);
3253
Zhu Yib481de92007-09-25 17:54:57 -07003254 /* Wipe out the EXIT_PENDING status bit if we are not actually
3255 * exiting the module */
3256 if (!exit_pending)
3257 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3258
3259 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003260 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003261
3262 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003263 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003264 iwl3945_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003265 spin_unlock_irqrestore(&priv->lock, flags);
3266 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003267
3268 if (priv->mac80211_registered)
3269 ieee80211_stop_queues(priv->hw);
3270
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003271 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003272 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003273 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003274 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3275 STATUS_RF_KILL_HW |
3276 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3277 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003278 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3279 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003280 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003281 STATUS_IN_SUSPEND |
3282 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3283 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003284 goto exit;
3285 }
3286
3287 /* ...otherwise clear out all the status bits but the RF Kill and
3288 * SUSPEND bits and continue taking the NIC down. */
3289 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3290 STATUS_RF_KILL_HW |
3291 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3292 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003293 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3294 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003295 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3296 STATUS_IN_SUSPEND |
3297 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003298 STATUS_FW_ERROR |
3299 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3300 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003301
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003302 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003303 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003304 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003305 spin_unlock_irqrestore(&priv->lock, flags);
3306
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003307 iwl3945_hw_txq_ctx_stop(priv);
3308 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003309
3310 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003311 if (!iwl_grab_nic_access(priv)) {
3312 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003313 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003314 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003315 }
3316 spin_unlock_irqrestore(&priv->lock, flags);
3317
3318 udelay(5);
3319
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003320 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3321 priv->cfg->ops->lib->apm_ops.stop(priv);
3322 else
3323 priv->cfg->ops->lib->apm_ops.reset(priv);
3324
Zhu Yib481de92007-09-25 17:54:57 -07003325 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003326 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003327
3328 if (priv->ibss_beacon)
3329 dev_kfree_skb(priv->ibss_beacon);
3330 priv->ibss_beacon = NULL;
3331
3332 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003333 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003334}
3335
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003336static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003337{
3338 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003339 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003340 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003341
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003342 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003343}
3344
3345#define MAX_HW_RESTARTS 5
3346
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003347static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003348{
3349 int rc, i;
3350
3351 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003352 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003353 return -EIO;
3354 }
3355
3356 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003357 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003358 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003359 return -ENODEV;
3360 }
3361
Reinette Chatree903fbd2008-01-30 22:05:15 -08003362 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003363 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003364 return -EIO;
3365 }
3366
Zhu Yie655b9f2008-01-24 02:19:38 -08003367 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003368 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003369 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3370 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3371 else {
3372 set_bit(STATUS_RF_KILL_HW, &priv->status);
3373 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003374 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003375 return -ENODEV;
3376 }
Zhu Yib481de92007-09-25 17:54:57 -07003377 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003378
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003379 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003380
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003381 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003382 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003383 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003384 return rc;
3385 }
3386
3387 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003388 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3389 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003390 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3391
3392 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003393 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003394 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003395
3396 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003397 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3398 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003399
3400 /* Copy original ucode data image from disk into backup cache.
3401 * This will be used to initialize the on-board processor's
3402 * data SRAM for a clean start when the runtime program first loads. */
3403 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08003404 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003405
Zhu Yie655b9f2008-01-24 02:19:38 -08003406 /* We return success when we resume from suspend and rf_kill is on. */
3407 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3408 return 0;
3409
Zhu Yib481de92007-09-25 17:54:57 -07003410 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3411
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003412 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003413
3414 /* load bootstrap state machine,
3415 * load bootstrap program into processor's memory,
3416 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003417 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003418
3419 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003420 IWL_ERR(priv,
3421 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003422 continue;
3423 }
3424
3425 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003426 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003427
Tomas Winklere1623442009-01-27 14:27:56 -08003428 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003429
3430 return 0;
3431 }
3432
3433 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003434 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003435 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003436
3437 /* tried to restart and config the device for as long as our
3438 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003439 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003440 return -EIO;
3441}
3442
3443
3444/*****************************************************************************
3445 *
3446 * Workqueue callbacks
3447 *
3448 *****************************************************************************/
3449
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003450static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003451{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003452 struct iwl_priv *priv =
3453 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003454
3455 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3456 return;
3457
3458 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003459 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003460 mutex_unlock(&priv->mutex);
3461}
3462
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003463static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003464{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003465 struct iwl_priv *priv =
3466 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003467
3468 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3469 return;
3470
3471 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003472 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003473 mutex_unlock(&priv->mutex);
3474}
3475
Helmut Schaa26635162009-01-15 09:38:44 +01003476static void iwl3945_rfkill_poll(struct work_struct *data)
3477{
3478 struct iwl_priv *priv =
3479 container_of(data, struct iwl_priv, rfkill_poll.work);
3480 unsigned long status = priv->status;
3481
3482 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3483 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3484 else
3485 set_bit(STATUS_RF_KILL_HW, &priv->status);
3486
3487 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3488 queue_work(priv->workqueue, &priv->rf_kill);
3489
3490 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3491 round_jiffies_relative(2 * HZ));
3492
3493}
3494
Zhu Yib481de92007-09-25 17:54:57 -07003495#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003496static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003497{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003498 struct iwl_priv *priv =
3499 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08003500 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003501 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003502 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003503 .meta.flags = CMD_SIZE_HUGE,
3504 };
3505 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003506 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003507 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003508 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003509 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003510 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003511
3512 conf = ieee80211_get_hw_conf(priv->hw);
3513
3514 mutex_lock(&priv->mutex);
3515
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003516 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003517 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003518 goto done;
3519 }
3520
Tomas Winklera96a27f2008-10-23 23:48:56 -07003521 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003522 * was given the chance to run... */
3523 if (!test_bit(STATUS_SCANNING, &priv->status))
3524 goto done;
3525
3526 /* This should never be called or scheduled if there is currently
3527 * a scan active in the hardware. */
3528 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003529 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3530 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003531 rc = -EIO;
3532 goto done;
3533 }
3534
3535 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003536 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003537 goto done;
3538 }
3539
3540 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003541 IWL_DEBUG_HC(priv,
3542 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003543 goto done;
3544 }
3545
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003546 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003547 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003548 goto done;
3549 }
3550
3551 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003552 IWL_DEBUG_HC(priv,
3553 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003554 goto done;
3555 }
3556
3557 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003558 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003559 goto done;
3560 }
3561
Winkler, Tomas805cee52009-01-19 15:30:28 -08003562 if (!priv->scan) {
3563 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003564 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003565 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003566 rc = -ENOMEM;
3567 goto done;
3568 }
3569 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003570 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003571 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003572
3573 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3574 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3575
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003576 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003577 u16 interval = 0;
3578 u32 extra;
3579 u32 suspend_time = 100;
3580 u32 scan_suspend_time = 100;
3581 unsigned long flags;
3582
Tomas Winklere1623442009-01-27 14:27:56 -08003583 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003584
3585 spin_lock_irqsave(&priv->lock, flags);
3586 interval = priv->beacon_int;
3587 spin_unlock_irqrestore(&priv->lock, flags);
3588
3589 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003590 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003591 if (!interval)
3592 interval = suspend_time;
3593 /*
3594 * suspend time format:
3595 * 0-19: beacon interval in usec (time before exec.)
3596 * 20-23: 0
3597 * 24-31: number of beacons (suspend between channels)
3598 */
3599
3600 extra = (suspend_time / interval) << 24;
3601 scan_suspend_time = 0xFF0FFFFF &
3602 (extra | ((suspend_time % interval) * 1024));
3603
3604 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003605 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003606 scan_suspend_time, interval);
3607 }
3608
3609 /* We should add the ability for user to lock to PASSIVE ONLY */
3610 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003611 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3612 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003613 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003614 scan->direct_scan[0].id = WLAN_EID_SSID;
3615 scan->direct_scan[0].len = priv->direct_ssid_len;
3616 memcpy(scan->direct_scan[0].ssid,
3617 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003618 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003619 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003620 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003621
3622 /* We don't build a direct scan probe request; the uCode will do
3623 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003624 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003625 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003626 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3627
3628 /* flags + rate selection */
3629
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003630 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003631 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3632 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3633 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003634 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003635 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003636 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3637 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003638 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003639 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003640 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003641 goto done;
3642 }
3643
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003644 scan->tx_cmd.len = cpu_to_le16(
3645 iwl_fill_probe_req(priv, band,
3646 (struct ieee80211_mgmt *)scan->data,
3647 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3648
Zhu Yib481de92007-09-25 17:54:57 -07003649 /* select Rx antennas */
3650 scan->flags |= iwl3945_get_antenna_flags(priv);
3651
Johannes Berg05c914f2008-09-11 00:01:58 +02003652 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003653 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3654
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003655 scan->channel_count =
3656 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3657 n_probes,
3658 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003659
Reinette Chatre14b54332008-11-04 12:21:35 -08003660 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003661 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003662 goto done;
3663 }
3664
Zhu Yib481de92007-09-25 17:54:57 -07003665 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003666 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003667 cmd.data = scan;
3668 scan->len = cpu_to_le16(cmd.len);
3669
3670 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003671 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003672 if (rc)
3673 goto done;
3674
3675 queue_delayed_work(priv->workqueue, &priv->scan_check,
3676 IWL_SCAN_CHECK_WATCHDOG);
3677
3678 mutex_unlock(&priv->mutex);
3679 return;
3680
3681 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003682 /* can not perform scan make sure we clear scanning
3683 * bits from status so next scan request can be performed.
3684 * if we dont clear scanning status bit here all next scan
3685 * will fail
3686 */
3687 clear_bit(STATUS_SCAN_HW, &priv->status);
3688 clear_bit(STATUS_SCANNING, &priv->status);
3689
Ian Schram01ebd062007-10-25 17:15:22 +08003690 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003691 queue_work(priv->workqueue, &priv->scan_completed);
3692 mutex_unlock(&priv->mutex);
3693}
3694
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003695static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003696{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003697 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003698
3699 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3700 return;
3701
3702 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003703 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003704 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003705 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003706}
3707
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003708static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003709{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003710 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003711
3712 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3713 return;
3714
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003715 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003716 queue_work(priv->workqueue, &priv->up);
3717}
3718
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003719static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003720{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003721 struct iwl_priv *priv =
3722 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003723
3724 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3725 return;
3726
3727 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003728 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003729 mutex_unlock(&priv->mutex);
3730}
3731
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003732#define IWL_DELAY_NEXT_SCAN (HZ*2)
3733
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003734static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003735{
Zhu Yib481de92007-09-25 17:54:57 -07003736 int rc = 0;
3737 struct ieee80211_conf *conf = NULL;
3738
Johannes Berg05c914f2008-09-11 00:01:58 +02003739 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003740 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003741 return;
3742 }
3743
3744
Tomas Winklere1623442009-01-27 14:27:56 -08003745 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003746 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003747
3748 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3749 return;
3750
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003751 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003752 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003753
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003754 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003755
Zhu Yib481de92007-09-25 17:54:57 -07003756 conf = ieee80211_get_hw_conf(priv->hw);
3757
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003758 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003759 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003760
Tomas Winkler28afaf92008-12-19 10:37:06 +08003761 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003762 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003763 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003764 sizeof(priv->rxon_timing), &priv->rxon_timing);
3765 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003766 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003767 "Attempting to continue.\n");
3768
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003769 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003770
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003771 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003772
Tomas Winklere1623442009-01-27 14:27:56 -08003773 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003774 priv->assoc_id, priv->beacon_int);
3775
3776 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003777 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003778 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003779 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003780
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003781 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003782 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003783 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003784 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003785 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003786
Johannes Berg05c914f2008-09-11 00:01:58 +02003787 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003788 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003789
3790 }
3791
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003792 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003793
3794 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003795 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003796 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003797 break;
3798
Johannes Berg05c914f2008-09-11 00:01:58 +02003799 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003800
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003801 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003802 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003803 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003804 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003805 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3806 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003807 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3808 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003809
3810 break;
3811
3812 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003813 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003814 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003815 break;
3816 }
3817
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003818 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003819
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003820 /* we have just associated, don't start scan too early */
3821 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003822}
3823
Johannes Berge8975582008-10-09 12:18:51 +02003824static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003825
Zhu Yib481de92007-09-25 17:54:57 -07003826/*****************************************************************************
3827 *
3828 * mac80211 entry point functions
3829 *
3830 *****************************************************************************/
3831
Zhu Yi5a66926a2008-01-14 17:46:18 -08003832#define UCODE_READY_TIMEOUT (2 * HZ)
3833
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003834static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003835{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003836 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003837 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003838
Tomas Winklere1623442009-01-27 14:27:56 -08003839 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003840
3841 /* we should be verifying the device is ready to be opened */
3842 mutex_lock(&priv->mutex);
3843
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003844 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003845 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3846 * ucode filename and max sizes are card-specific. */
3847
3848 if (!priv->ucode_code.len) {
3849 ret = iwl3945_read_ucode(priv);
3850 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003851 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003852 mutex_unlock(&priv->mutex);
3853 goto out_release_irq;
3854 }
3855 }
3856
Zhu Yie655b9f2008-01-24 02:19:38 -08003857 ret = __iwl3945_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003858
Zhu Yib481de92007-09-25 17:54:57 -07003859 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003860
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003861 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003862
Zhu Yie655b9f2008-01-24 02:19:38 -08003863 if (ret)
3864 goto out_release_irq;
3865
Tomas Winklere1623442009-01-27 14:27:56 -08003866 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003867
3868 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3869 return 0;
3870
Zhu Yi5a66926a2008-01-14 17:46:18 -08003871 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3872 * mac80211 will not be run successfully. */
3873 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3874 test_bit(STATUS_READY, &priv->status),
3875 UCODE_READY_TIMEOUT);
3876 if (!ret) {
3877 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003878 IWL_ERR(priv,
3879 "Wait for START_ALIVE timeout after %dms.\n",
3880 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003881 ret = -ETIMEDOUT;
3882 goto out_release_irq;
3883 }
3884 }
3885
Helmut Schaa26635162009-01-15 09:38:44 +01003886 /* ucode is running and will send rfkill notifications,
3887 * no need to poll the killswitch state anymore */
3888 cancel_delayed_work(&priv->rfkill_poll);
3889
Zhu Yie655b9f2008-01-24 02:19:38 -08003890 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003891 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003892 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003893
3894out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003895 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003896 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08003897 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003898}
3899
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003900static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003901{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003902 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003903
Tomas Winklere1623442009-01-27 14:27:56 -08003904 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003905
Zhu Yie655b9f2008-01-24 02:19:38 -08003906 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003907 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003908 return;
3909 }
3910
Zhu Yib481de92007-09-25 17:54:57 -07003911 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003912
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003913 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003914 /* stop mac, cancel any scan request and clear
3915 * RXON_FILTER_ASSOC_MSK BIT
3916 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08003917 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003918 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003919 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003920 }
3921
Zhu Yi5a66926a2008-01-14 17:46:18 -08003922 iwl3945_down(priv);
3923
3924 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003925
3926 /* start polling the killswitch state again */
3927 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3928 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003929
Tomas Winklere1623442009-01-27 14:27:56 -08003930 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003931}
3932
Johannes Berge039fa42008-05-15 12:55:29 +02003933static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003934{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003935 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003936
Tomas Winklere1623442009-01-27 14:27:56 -08003937 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003938
Tomas Winklere1623442009-01-27 14:27:56 -08003939 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003940 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003941
Johannes Berge039fa42008-05-15 12:55:29 +02003942 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003943 dev_kfree_skb_any(skb);
3944
Tomas Winklere1623442009-01-27 14:27:56 -08003945 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003946 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003947}
3948
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003949static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003950 struct ieee80211_if_init_conf *conf)
3951{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003952 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003953 unsigned long flags;
3954
Tomas Winklere1623442009-01-27 14:27:56 -08003955 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003956
Johannes Berg32bfd352007-12-19 01:31:26 +01003957 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003958 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003959 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003960 }
3961
3962 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003963 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003964 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003965
3966 spin_unlock_irqrestore(&priv->lock, flags);
3967
3968 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003969
3970 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003971 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003972 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3973 }
3974
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003975 if (iwl_is_ready(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08003976 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003977
Zhu Yib481de92007-09-25 17:54:57 -07003978 mutex_unlock(&priv->mutex);
3979
Tomas Winklere1623442009-01-27 14:27:56 -08003980 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003981 return 0;
3982}
3983
3984/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003985 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003986 *
3987 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3988 * be set inappropriately and the driver currently sets the hardware up to
3989 * use it whenever needed.
3990 */
Johannes Berge8975582008-10-09 12:18:51 +02003991static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003992{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003993 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003994 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003995 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003996 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003997 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003998
3999 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004000 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
4001 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004002
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004003 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004004 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004005 ret = -EIO;
4006 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004007 }
4008
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004009 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07004010 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08004011 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08004012 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004013 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08004014 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004015 }
4016
4017 spin_lock_irqsave(&priv->lock, flags);
4018
Samuel Ortize6148912009-01-23 13:45:15 -08004019 ch_info = iwl_get_channel_info(priv, conf->channel->band,
4020 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07004021 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004022 IWL_DEBUG_SCAN(priv,
4023 "Channel %d [%d] is INVALID for this band.\n",
4024 conf->channel->hw_value, conf->channel->band);
4025 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07004026 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004027 ret = -EINVAL;
4028 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004029 }
4030
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004031 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07004032
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004033 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07004034
4035 /* The list of supported rates and rate mask can be different
4036 * for each phymode; since the phymode may have changed, reset
4037 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004038 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004039
4040 spin_unlock_irqrestore(&priv->lock, flags);
4041
4042#ifdef IEEE80211_CONF_CHANNEL_SWITCH
4043 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004044 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004045 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004046 }
4047#endif
4048
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004049 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07004050
4051 if (!conf->radio_enabled) {
Tomas Winklere1623442009-01-27 14:27:56 -08004052 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004053 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004054 }
4055
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004056 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004057 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004058 ret = -EIO;
4059 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004060 }
4061
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004062 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004063
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004064 if (memcmp(&priv->active_rxon,
4065 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004066 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004067 else
Tomas Winklere1623442009-01-27 14:27:56 -08004068 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07004069
Tomas Winklere1623442009-01-27 14:27:56 -08004070 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004071
Zhu Yi76bb77e2007-11-22 10:53:22 +08004072out:
Zhu Yia0646472007-12-20 14:10:01 +08004073 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004074 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004075 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004076}
4077
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004078static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004079{
4080 int rc = 0;
4081
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08004082 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07004083 return;
4084
4085 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004086 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07004087
4088 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004089 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004090 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004091
4092 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08004093 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004094 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004095 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
4096 sizeof(priv->rxon_timing),
4097 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07004098 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004099 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07004100 "Attempting to continue.\n");
4101
4102 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004103 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07004104 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004105 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004106 RXON_FLG_SHORT_PREAMBLE_MSK;
4107 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004108 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004109 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4110
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004111 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07004112 if (priv->assoc_capability &
4113 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004114 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004115 RXON_FLG_SHORT_SLOT_MSK;
4116 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004117 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004118 ~RXON_FLG_SHORT_SLOT_MSK;
4119
Johannes Berg05c914f2008-09-11 00:01:58 +02004120 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004121 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004122 ~RXON_FLG_SHORT_SLOT_MSK;
4123 }
4124 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004125 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004126 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08004127 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08004128 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004129 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004130
4131 /* FIXME - we need to add code here to detect a totally new
4132 * configuration, reset the AP, unassoc, rxon timing, assoc,
4133 * clear sta table, add BCAST sta... */
4134}
4135
Johannes Berg32bfd352007-12-19 01:31:26 +01004136static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
4137 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004138 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07004139{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004140 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004141 int rc;
4142
4143 if (conf == NULL)
4144 return -EIO;
4145
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004146 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08004147 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004148 return 0;
4149 }
4150
Johannes Berg9d139c82008-07-09 14:40:37 +02004151 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02004152 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02004153 conf->changed & IEEE80211_IFCC_BEACON) {
4154 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
4155 if (!beacon)
4156 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004157 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004158 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004159 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004160 if (rc)
4161 return rc;
4162 }
4163
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004164 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08004165 return -EAGAIN;
4166
Zhu Yib481de92007-09-25 17:54:57 -07004167 mutex_lock(&priv->mutex);
4168
Zhu Yib481de92007-09-25 17:54:57 -07004169 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08004170 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004171
Johannes Berg4150c572007-09-17 01:29:23 -04004172/*
4173 * very dubious code was here; the probe filtering flag is never set:
4174 *
Zhu Yib481de92007-09-25 17:54:57 -07004175 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4176 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04004177 */
Zhu Yib481de92007-09-25 17:54:57 -07004178
Johannes Berg05c914f2008-09-11 00:01:58 +02004179 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07004180 if (!conf->bssid) {
4181 conf->bssid = priv->mac_addr;
4182 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004183 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07004184 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004185 }
4186 if (priv->ibss_beacon)
4187 dev_kfree_skb(priv->ibss_beacon);
4188
Johannes Berg9d139c82008-07-09 14:40:37 +02004189 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07004190 }
4191
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004192 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004193 goto done;
4194
Zhu Yib481de92007-09-25 17:54:57 -07004195 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4196 !is_multicast_ether_addr(conf->bssid)) {
4197 /* If there is currently a HW scan going on in the background
4198 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004199 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004200 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07004201 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08004202 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07004203 mutex_unlock(&priv->mutex);
4204 return -EAGAIN;
4205 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004206 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004207
4208 /* TODO: Audit driver for usage of these members and see
4209 * if mac80211 deprecates them (priv->bssid looks like it
4210 * shouldn't be there, but I haven't scanned the IBSS code
4211 * to verify) - jpk */
4212 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4213
Johannes Berg05c914f2008-09-11 00:01:58 +02004214 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004215 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004216 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004217 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004218 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004219 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004220 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004221 }
4222
4223 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004224 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004225 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004226 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004227 }
4228
Mohamed Abbasfde35712007-11-29 11:10:15 +08004229 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004230 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004231 mutex_unlock(&priv->mutex);
4232
4233 return 0;
4234}
4235
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004236static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004237 struct ieee80211_if_init_conf *conf)
4238{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004239 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004240
Tomas Winklere1623442009-01-27 14:27:56 -08004241 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004242
4243 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004244
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004245 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004246 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004247 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004248 iwl3945_commit_rxon(priv);
4249 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004250 if (priv->vif == conf->vif) {
4251 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004252 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004253 }
4254 mutex_unlock(&priv->mutex);
4255
Tomas Winklere1623442009-01-27 14:27:56 -08004256 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004257}
4258
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004259#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4260
4261static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4262 struct ieee80211_vif *vif,
4263 struct ieee80211_bss_conf *bss_conf,
4264 u32 changes)
4265{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004266 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004267
Tomas Winklere1623442009-01-27 14:27:56 -08004268 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004269
4270 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004271 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004272 bss_conf->use_short_preamble);
4273 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004274 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004275 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004276 priv->staging_rxon.flags &=
4277 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004278 }
4279
4280 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004281 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4282 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004283 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004284 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004285 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004286 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004287 }
4288
4289 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004290 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004291 /* This should never happen as this function should
4292 * never be called from interrupt context. */
4293 if (WARN_ON_ONCE(in_interrupt()))
4294 return;
4295 if (bss_conf->assoc) {
4296 priv->assoc_id = bss_conf->aid;
4297 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004298 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004299 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004300 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004301 priv->next_scan_jiffies = jiffies +
4302 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4303 mutex_lock(&priv->mutex);
4304 iwl3945_post_associate(priv);
4305 mutex_unlock(&priv->mutex);
4306 } else {
4307 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004308 IWL_DEBUG_MAC80211(priv,
4309 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004310 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004311 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004312 IWL_DEBUG_MAC80211(priv,
4313 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004314 iwl3945_send_rxon_assoc(priv);
4315 }
4316
4317}
4318
Johannes Berg2a519312009-02-10 21:25:55 +01004319static int iwl3945_mac_hw_scan(struct ieee80211_hw *hw,
4320 struct cfg80211_scan_request *req)
Zhu Yib481de92007-09-25 17:54:57 -07004321{
4322 int rc = 0;
4323 unsigned long flags;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004324 struct iwl_priv *priv = hw->priv;
Johannes Berg2a519312009-02-10 21:25:55 +01004325 size_t len = 0;
4326 u8 *ssid = NULL;
John W. Linville9387b7c2008-09-30 20:59:05 -04004327 DECLARE_SSID_BUF(ssid_buf);
Zhu Yib481de92007-09-25 17:54:57 -07004328
Tomas Winklere1623442009-01-27 14:27:56 -08004329 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004330
Johannes Berg2a519312009-02-10 21:25:55 +01004331 if (req->n_ssids) {
4332 ssid = req->ssids[0].ssid;
4333 len = req->ssids[0].ssid_len;
4334 }
4335
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004336 mutex_lock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07004337 spin_lock_irqsave(&priv->lock, flags);
4338
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004339 if (!iwl_is_ready_rf(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07004340 rc = -EIO;
Tomas Winklere1623442009-01-27 14:27:56 -08004341 IWL_DEBUG_MAC80211(priv, "leave - not ready or exit pending\n");
Zhu Yib481de92007-09-25 17:54:57 -07004342 goto out_unlock;
4343 }
4344
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08004345 /* we don't schedule scan within next_scan_jiffies period */
4346 if (priv->next_scan_jiffies &&
4347 time_after(priv->next_scan_jiffies, jiffies)) {
4348 rc = -EAGAIN;
4349 goto out_unlock;
4350 }
Bill Moss15dbf1b2008-05-06 11:05:15 +08004351 /* if we just finished scan ask for delay for a broadcast scan */
4352 if ((len == 0) && priv->last_scan_jiffies &&
4353 time_after(priv->last_scan_jiffies + IWL_DELAY_NEXT_SCAN,
4354 jiffies)) {
Zhu Yib481de92007-09-25 17:54:57 -07004355 rc = -EAGAIN;
4356 goto out_unlock;
4357 }
4358 if (len) {
Tomas Winklere1623442009-01-27 14:27:56 -08004359 IWL_DEBUG_SCAN(priv, "direct scan for %s [%zd]\n ",
4360 print_ssid(ssid_buf, ssid, len), len);
Zhu Yib481de92007-09-25 17:54:57 -07004361
4362 priv->one_direct_scan = 1;
Johannes Berg2a519312009-02-10 21:25:55 +01004363 priv->direct_ssid_len = len;
4364 memcpy(priv->direct_ssid, ssid, len);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004365 } else
4366 priv->one_direct_scan = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004367
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004368 rc = iwl3945_scan_initiate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004369
Tomas Winklere1623442009-01-27 14:27:56 -08004370 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004371
4372out_unlock:
4373 spin_unlock_irqrestore(&priv->lock, flags);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004374 mutex_unlock(&priv->mutex);
Zhu Yib481de92007-09-25 17:54:57 -07004375
4376 return rc;
4377}
4378
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004379static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004380 struct ieee80211_vif *vif,
4381 struct ieee80211_sta *sta,
4382 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004383{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004384 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004385 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08004386 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004387 u8 sta_id;
4388
Tomas Winklere1623442009-01-27 14:27:56 -08004389 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004390
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004391 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004392 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004393 return -EOPNOTSUPP;
4394 }
4395
Winkler, Tomas42986792009-01-19 15:30:22 -08004396 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004397 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07004398 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08004399 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07004400 addr);
Zhu Yib481de92007-09-25 17:54:57 -07004401 return -EINVAL;
4402 }
4403
4404 mutex_lock(&priv->mutex);
4405
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004406 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004407
Zhu Yib481de92007-09-25 17:54:57 -07004408 switch (cmd) {
4409 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004410 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
4411 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004412 iwl_set_rxon_hwcrypto(priv, 1);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004413 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004414 key->hw_key_idx = sta_id;
Tomas Winklere1623442009-01-27 14:27:56 -08004415 IWL_DEBUG_MAC80211(priv,
4416 "set_key success, using hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07004417 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4418 }
4419 break;
4420 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004421 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4422 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004423 iwl_set_rxon_hwcrypto(priv, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004424 iwl3945_commit_rxon(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08004425 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004426 }
4427 break;
4428 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004429 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004430 }
4431
Tomas Winklere1623442009-01-27 14:27:56 -08004432 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004433 mutex_unlock(&priv->mutex);
4434
Winkler, Tomas42986792009-01-19 15:30:22 -08004435 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004436}
4437
Johannes Berge100bb62008-04-30 18:51:21 +02004438static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004439 const struct ieee80211_tx_queue_params *params)
4440{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004441 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004442 unsigned long flags;
4443 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004444
Tomas Winklere1623442009-01-27 14:27:56 -08004445 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004446
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004447 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004448 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004449 return -EIO;
4450 }
4451
4452 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004453 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004454 return 0;
4455 }
4456
Zhu Yib481de92007-09-25 17:54:57 -07004457 q = AC_NUM - 1 - queue;
4458
4459 spin_lock_irqsave(&priv->lock, flags);
4460
4461 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4462 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4463 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4464 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004465 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004466
4467 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4468 priv->qos_data.qos_active = 1;
4469
4470 spin_unlock_irqrestore(&priv->lock, flags);
4471
4472 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004473 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004474 iwl3945_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004475 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004476 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004477
4478 mutex_unlock(&priv->mutex);
4479
Tomas Winklere1623442009-01-27 14:27:56 -08004480 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004481 return 0;
4482}
4483
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004484static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004485 struct ieee80211_tx_queue_stats *stats)
4486{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004487 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004488 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004489 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004490 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004491 unsigned long flags;
4492
Tomas Winklere1623442009-01-27 14:27:56 -08004493 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004494
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004495 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004496 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004497 return -EIO;
4498 }
4499
4500 spin_lock_irqsave(&priv->lock, flags);
4501
4502 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004503 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004504 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004505 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004506
Johannes Berg57ffc582008-04-29 17:18:59 +02004507 stats[i].len = q->n_window - avail;
4508 stats[i].limit = q->n_window - q->high_mark;
4509 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004510
4511 }
4512 spin_unlock_irqrestore(&priv->lock, flags);
4513
Tomas Winklere1623442009-01-27 14:27:56 -08004514 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004515
4516 return 0;
4517}
4518
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004519static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004520{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004521 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004522 unsigned long flags;
4523
4524 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004525 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004526
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004527 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004528
Zhu Yib481de92007-09-25 17:54:57 -07004529 spin_lock_irqsave(&priv->lock, flags);
4530 priv->assoc_id = 0;
4531 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004532
4533 /* new association get rid of ibss beacon skb */
4534 if (priv->ibss_beacon)
4535 dev_kfree_skb(priv->ibss_beacon);
4536
4537 priv->ibss_beacon = NULL;
4538
4539 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004540 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004541 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004542 priv->beacon_int = 0;
4543
4544 spin_unlock_irqrestore(&priv->lock, flags);
4545
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004546 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004547 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004548 mutex_unlock(&priv->mutex);
4549 return;
4550 }
4551
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004552 /* we are restarting association process
4553 * clear RXON_FILTER_ASSOC_MSK bit
4554 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004555 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004556 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004557 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004558 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004559 }
4560
Zhu Yib481de92007-09-25 17:54:57 -07004561 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004562 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004563
Tomas Winklere1623442009-01-27 14:27:56 -08004564 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004565 mutex_unlock(&priv->mutex);
4566 return;
4567 }
4568
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004569 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004570
4571 mutex_unlock(&priv->mutex);
4572
Tomas Winklere1623442009-01-27 14:27:56 -08004573 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004574
4575}
4576
Johannes Berge039fa42008-05-15 12:55:29 +02004577static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004578{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004579 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004580 unsigned long flags;
4581
Tomas Winklere1623442009-01-27 14:27:56 -08004582 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004583
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004584 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004585 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004586 return -EIO;
4587 }
4588
Johannes Berg05c914f2008-09-11 00:01:58 +02004589 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004590 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004591 return -EIO;
4592 }
4593
4594 spin_lock_irqsave(&priv->lock, flags);
4595
4596 if (priv->ibss_beacon)
4597 dev_kfree_skb(priv->ibss_beacon);
4598
4599 priv->ibss_beacon = skb;
4600
4601 priv->assoc_id = 0;
4602
Tomas Winklere1623442009-01-27 14:27:56 -08004603 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004604 spin_unlock_irqrestore(&priv->lock, flags);
4605
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004606 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004607
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004608 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004609
Zhu Yib481de92007-09-25 17:54:57 -07004610
4611 return 0;
4612}
4613
4614/*****************************************************************************
4615 *
4616 * sysfs attributes
4617 *
4618 *****************************************************************************/
4619
Samuel Ortizd08853a2009-01-23 13:45:17 -08004620#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004621
4622/*
4623 * The following adds a new attribute to the sysfs representation
4624 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4625 * used for controlling the debug level.
4626 *
4627 * See the level definitions in iwl for details.
4628 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004629static ssize_t show_debug_level(struct device *d,
4630 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004631{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004632 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004633
4634 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004635}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004636static ssize_t store_debug_level(struct device *d,
4637 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004638 const char *buf, size_t count)
4639{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004640 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004641 unsigned long val;
4642 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004643
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004644 ret = strict_strtoul(buf, 0, &val);
4645 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004646 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004647 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004648 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004649
4650 return strnlen(buf, count);
4651}
4652
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004653static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4654 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004655
Samuel Ortizd08853a2009-01-23 13:45:17 -08004656#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004657
Zhu Yib481de92007-09-25 17:54:57 -07004658static ssize_t show_temperature(struct device *d,
4659 struct device_attribute *attr, char *buf)
4660{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004661 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004662
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004663 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004664 return -EAGAIN;
4665
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004666 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004667}
4668
4669static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4670
Zhu Yib481de92007-09-25 17:54:57 -07004671static ssize_t show_tx_power(struct device *d,
4672 struct device_attribute *attr, char *buf)
4673{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004674 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004675 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004676}
4677
4678static ssize_t store_tx_power(struct device *d,
4679 struct device_attribute *attr,
4680 const char *buf, size_t count)
4681{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004682 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004683 char *p = (char *)buf;
4684 u32 val;
4685
4686 val = simple_strtoul(p, &p, 10);
4687 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004688 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004689 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004690 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004691
4692 return count;
4693}
4694
4695static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4696
4697static ssize_t show_flags(struct device *d,
4698 struct device_attribute *attr, char *buf)
4699{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004700 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004701
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004702 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004703}
4704
4705static ssize_t store_flags(struct device *d,
4706 struct device_attribute *attr,
4707 const char *buf, size_t count)
4708{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004709 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004710 u32 flags = simple_strtoul(buf, NULL, 0);
4711
4712 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004713 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004714 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004715 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004716 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004717 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004718 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004719 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004720 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004721 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004722 }
4723 }
4724 mutex_unlock(&priv->mutex);
4725
4726 return count;
4727}
4728
4729static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4730
4731static ssize_t show_filter_flags(struct device *d,
4732 struct device_attribute *attr, char *buf)
4733{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004734 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004735
4736 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004737 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004738}
4739
4740static ssize_t store_filter_flags(struct device *d,
4741 struct device_attribute *attr,
4742 const char *buf, size_t count)
4743{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004744 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004745 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4746
4747 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004748 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004749 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004750 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004751 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004752 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004753 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004754 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004755 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004756 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004757 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004758 }
4759 }
4760 mutex_unlock(&priv->mutex);
4761
4762 return count;
4763}
4764
4765static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4766 store_filter_flags);
4767
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004768#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004769
4770static ssize_t show_measurement(struct device *d,
4771 struct device_attribute *attr, char *buf)
4772{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004773 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004774 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004775 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004776 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004777 unsigned long flags;
4778
4779 spin_lock_irqsave(&priv->lock, flags);
4780 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4781 spin_unlock_irqrestore(&priv->lock, flags);
4782 return 0;
4783 }
4784 memcpy(&measure_report, &priv->measure_report, size);
4785 priv->measurement_status = 0;
4786 spin_unlock_irqrestore(&priv->lock, flags);
4787
4788 while (size && (PAGE_SIZE - len)) {
4789 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4790 PAGE_SIZE - len, 1);
4791 len = strlen(buf);
4792 if (PAGE_SIZE - len)
4793 buf[len++] = '\n';
4794
4795 ofs += 16;
4796 size -= min(size, 16U);
4797 }
4798
4799 return len;
4800}
4801
4802static ssize_t store_measurement(struct device *d,
4803 struct device_attribute *attr,
4804 const char *buf, size_t count)
4805{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004806 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004807 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004808 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004809 .start_time = cpu_to_le64(priv->last_tsf),
4810 .duration = cpu_to_le16(1),
4811 };
4812 u8 type = IWL_MEASURE_BASIC;
4813 u8 buffer[32];
4814 u8 channel;
4815
4816 if (count) {
4817 char *p = buffer;
4818 strncpy(buffer, buf, min(sizeof(buffer), count));
4819 channel = simple_strtoul(p, NULL, 0);
4820 if (channel)
4821 params.channel = channel;
4822
4823 p = buffer;
4824 while (*p && *p != ' ')
4825 p++;
4826 if (*p)
4827 type = simple_strtoul(p + 1, NULL, 0);
4828 }
4829
Tomas Winklere1623442009-01-27 14:27:56 -08004830 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004831 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004832 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004833
4834 return count;
4835}
4836
4837static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4838 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004839#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004840
Zhu Yib481de92007-09-25 17:54:57 -07004841static ssize_t store_retry_rate(struct device *d,
4842 struct device_attribute *attr,
4843 const char *buf, size_t count)
4844{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004845 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004846
4847 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4848 if (priv->retry_rate <= 0)
4849 priv->retry_rate = 1;
4850
4851 return count;
4852}
4853
4854static ssize_t show_retry_rate(struct device *d,
4855 struct device_attribute *attr, char *buf)
4856{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004857 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004858 return sprintf(buf, "%d", priv->retry_rate);
4859}
4860
4861static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4862 store_retry_rate);
4863
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004864
Zhu Yib481de92007-09-25 17:54:57 -07004865static ssize_t store_power_level(struct device *d,
4866 struct device_attribute *attr,
4867 const char *buf, size_t count)
4868{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004869 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004870 int ret;
4871 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004872
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004873
Zhu Yib481de92007-09-25 17:54:57 -07004874 mutex_lock(&priv->mutex);
4875
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004876 if (!iwl_is_ready(priv)) {
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004877 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07004878 goto out;
4879 }
4880
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004881 ret = strict_strtoul(buf, 10, &mode);
4882 if (ret)
4883 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004884
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004885 ret = iwl_power_set_user_mode(priv, mode);
4886 if (ret) {
4887 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4888 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004889 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004890 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004891
4892 out:
4893 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004894 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004895}
4896
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004897static ssize_t show_power_level(struct device *d,
4898 struct device_attribute *attr, char *buf)
4899{
4900 struct iwl_priv *priv = dev_get_drvdata(d);
4901 int mode = priv->power_data.user_power_setting;
4902 int system = priv->power_data.system_power_setting;
4903 int level = priv->power_data.power_mode;
4904 char *p = buf;
4905
4906 switch (system) {
4907 case IWL_POWER_SYS_AUTO:
4908 p += sprintf(p, "SYSTEM:auto");
4909 break;
4910 case IWL_POWER_SYS_AC:
4911 p += sprintf(p, "SYSTEM:ac");
4912 break;
4913 case IWL_POWER_SYS_BATTERY:
4914 p += sprintf(p, "SYSTEM:battery");
4915 break;
4916 }
4917
4918 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4919 "fixed" : "auto");
4920 p += sprintf(p, "\tINDEX:%d", level);
4921 p += sprintf(p, "\n");
4922 return p - buf + 1;
4923}
4924
4925static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4926 show_power_level, store_power_level);
4927
Zhu Yib481de92007-09-25 17:54:57 -07004928#define MAX_WX_STRING 80
4929
4930/* Values are in microsecond */
4931static const s32 timeout_duration[] = {
4932 350000,
4933 250000,
4934 75000,
4935 37000,
4936 25000,
4937};
4938static const s32 period_duration[] = {
4939 400000,
4940 700000,
4941 1000000,
4942 1000000,
4943 1000000
4944};
4945
Zhu Yib481de92007-09-25 17:54:57 -07004946static ssize_t show_channels(struct device *d,
4947 struct device_attribute *attr, char *buf)
4948{
Johannes Berg8318d782008-01-24 19:38:38 +01004949 /* all this shit doesn't belong into sysfs anyway */
4950 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004951}
4952
4953static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4954
4955static ssize_t show_statistics(struct device *d,
4956 struct device_attribute *attr, char *buf)
4957{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004958 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004959 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004960 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004961 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004962 int rc = 0;
4963
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004964 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004965 return -EAGAIN;
4966
4967 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004968 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004969 mutex_unlock(&priv->mutex);
4970
4971 if (rc) {
4972 len = sprintf(buf,
4973 "Error sending statistics request: 0x%08X\n", rc);
4974 return len;
4975 }
4976
4977 while (size && (PAGE_SIZE - len)) {
4978 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4979 PAGE_SIZE - len, 1);
4980 len = strlen(buf);
4981 if (PAGE_SIZE - len)
4982 buf[len++] = '\n';
4983
4984 ofs += 16;
4985 size -= min(size, 16U);
4986 }
4987
4988 return len;
4989}
4990
4991static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4992
4993static ssize_t show_antenna(struct device *d,
4994 struct device_attribute *attr, char *buf)
4995{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004996 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004997
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004998 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004999 return -EAGAIN;
5000
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08005001 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07005002}
5003
5004static ssize_t store_antenna(struct device *d,
5005 struct device_attribute *attr,
5006 const char *buf, size_t count)
5007{
Winkler, Tomas7530f852009-01-27 14:27:53 -08005008 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07005009 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07005010
5011 if (count == 0)
5012 return 0;
5013
5014 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08005015 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005016 return count;
5017 }
5018
5019 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08005020 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08005021 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07005022 } else
Tomas Winklere1623442009-01-27 14:27:56 -08005023 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07005024
5025
5026 return count;
5027}
5028
5029static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
5030
5031static ssize_t show_status(struct device *d,
5032 struct device_attribute *attr, char *buf)
5033{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005034 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08005035 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07005036 return -EAGAIN;
5037 return sprintf(buf, "0x%08x\n", (int)priv->status);
5038}
5039
5040static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
5041
5042static ssize_t dump_error_log(struct device *d,
5043 struct device_attribute *attr,
5044 const char *buf, size_t count)
5045{
5046 char *p = (char *)buf;
5047
5048 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005049 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07005050
5051 return strnlen(buf, count);
5052}
5053
5054static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
5055
5056static ssize_t dump_event_log(struct device *d,
5057 struct device_attribute *attr,
5058 const char *buf, size_t count)
5059{
5060 char *p = (char *)buf;
5061
5062 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005063 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07005064
5065 return strnlen(buf, count);
5066}
5067
5068static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
5069
5070/*****************************************************************************
5071 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07005072 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07005073 *
5074 *****************************************************************************/
5075
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005076static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005077{
Reinette Chatred21050c2009-02-13 11:51:18 -08005078 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07005079
5080 init_waitqueue_head(&priv->wait_command_queue);
5081
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005082 INIT_WORK(&priv->up, iwl3945_bg_up);
5083 INIT_WORK(&priv->restart, iwl3945_bg_restart);
5084 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005085 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005086 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005087 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
5088 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01005089 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08005090 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
5091 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
5092 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
5093 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07005094
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005095 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005096
5097 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005098 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07005099}
5100
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005101static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07005102{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005103 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005104
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09005105 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005106 cancel_delayed_work(&priv->scan_check);
5107 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07005108 cancel_work_sync(&priv->beacon_update);
5109}
5110
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005111static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07005112 &dev_attr_antenna.attr,
5113 &dev_attr_channels.attr,
5114 &dev_attr_dump_errors.attr,
5115 &dev_attr_dump_events.attr,
5116 &dev_attr_flags.attr,
5117 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005118#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005119 &dev_attr_measurement.attr,
5120#endif
5121 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005122 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005123 &dev_attr_statistics.attr,
5124 &dev_attr_status.attr,
5125 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005126 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08005127#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005128 &dev_attr_debug_level.attr,
5129#endif
Zhu Yib481de92007-09-25 17:54:57 -07005130 NULL
5131};
5132
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005133static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07005134 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005135 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07005136};
5137
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005138static struct ieee80211_ops iwl3945_hw_ops = {
5139 .tx = iwl3945_mac_tx,
5140 .start = iwl3945_mac_start,
5141 .stop = iwl3945_mac_stop,
5142 .add_interface = iwl3945_mac_add_interface,
5143 .remove_interface = iwl3945_mac_remove_interface,
5144 .config = iwl3945_mac_config,
5145 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005146 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005147 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005148 .get_tx_stats = iwl3945_mac_get_tx_stats,
5149 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005150 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005151 .bss_info_changed = iwl3945_bss_info_changed,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005152 .hw_scan = iwl3945_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07005153};
5154
Winkler, Tomase52119c2008-12-22 11:31:19 +08005155static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005156{
5157 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08005158 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005159
5160 priv->retry_rate = 1;
5161 priv->ibss_beacon = NULL;
5162
5163 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08005164 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005165 spin_lock_init(&priv->sta_lock);
5166 spin_lock_init(&priv->hcmd_lock);
5167
5168 INIT_LIST_HEAD(&priv->free_frames);
5169
5170 mutex_init(&priv->mutex);
5171
5172 /* Clear the driver's (not device's) station table */
5173 iwl3945_clear_stations_table(priv);
5174
5175 priv->data_retry_limit = -1;
5176 priv->ieee_channels = NULL;
5177 priv->ieee_rates = NULL;
5178 priv->band = IEEE80211_BAND_2GHZ;
5179
5180 priv->iw_mode = NL80211_IFTYPE_STATION;
5181
5182 iwl_reset_qos(priv);
5183
5184 priv->qos_data.qos_active = 0;
5185 priv->qos_data.qos_cap.val = 0;
5186
5187 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005188 /* If power management is turned on, default to CAM mode */
5189 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08005190 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005191
Samuel Ortize6148912009-01-23 13:45:15 -08005192 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
5193 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
5194 eeprom->version);
5195 ret = -EINVAL;
5196 goto err;
5197 }
5198 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005199 if (ret) {
5200 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
5201 goto err;
5202 }
5203
Samuel Ortize6148912009-01-23 13:45:15 -08005204 /* Set up txpower settings in driver for all channels */
5205 if (iwl3945_txpower_set_from_eeprom(priv)) {
5206 ret = -EIO;
5207 goto err_free_channel_map;
5208 }
5209
Samuel Ortiz534166d2009-01-23 13:45:16 -08005210 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005211 if (ret) {
5212 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
5213 goto err_free_channel_map;
5214 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08005215 iwl3945_init_hw_rates(priv, priv->ieee_rates);
5216
5217 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5218 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5219 &priv->bands[IEEE80211_BAND_2GHZ];
5220 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5221 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5222 &priv->bands[IEEE80211_BAND_5GHZ];
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005223
5224 return 0;
5225
5226err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08005227 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005228err:
5229 return ret;
5230}
5231
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005232static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005233{
5234 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005235 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005236 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005237 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005238 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005239 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005240
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005241 /***********************
5242 * 1. Allocating HW data
5243 * ********************/
5244
Zhu Yib481de92007-09-25 17:54:57 -07005245 /* mac80211 allocates memory for this device instance, including
5246 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005247 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005248 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005249 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005250 err = -ENOMEM;
5251 goto out;
5252 }
Zhu Yib481de92007-09-25 17:54:57 -07005253 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005254 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005255
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005256 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5257 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005258 IWL_ERR(priv,
5259 "invalid queues_num, should be between %d and %d\n",
5260 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005261 err = -EINVAL;
5262 goto out;
5263 }
5264
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005265 /*
5266 * Disabling hardware scan means that mac80211 will perform scans
5267 * "the hard way", rather than using device's scan.
5268 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005269 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005270 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005271 iwl3945_hw_ops.hw_scan = NULL;
5272 }
5273
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005274
Tomas Winklere1623442009-01-27 14:27:56 -08005275 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005276 priv->cfg = cfg;
5277 priv->pci_dev = pdev;
5278
Samuel Ortizd08853a2009-01-23 13:45:17 -08005279#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005280 priv->debug_level = iwl3945_mod_params.debug;
5281 atomic_set(&priv->restrict_refcnt, 0);
5282#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005283 hw->rate_control_algorithm = "iwl-3945-rs";
5284 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
5285
Bruno Randolf566bfe52008-05-08 19:15:40 +02005286 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02005287 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02005288 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07005289
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005290 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005291 BIT(NL80211_IFTYPE_STATION) |
5292 BIT(NL80211_IFTYPE_ADHOC);
5293
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08005294 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08005295
Johannes Berg2a519312009-02-10 21:25:55 +01005296 hw->wiphy->max_scan_ssids = 1;
5297
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005298 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07005299 hw->queues = 4;
5300
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005301 /***************************
5302 * 2. Initializing PCI bus
5303 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005304 if (pci_enable_device(pdev)) {
5305 err = -ENODEV;
5306 goto out_ieee80211_free_hw;
5307 }
5308
5309 pci_set_master(pdev);
5310
Zhu Yib481de92007-09-25 17:54:57 -07005311 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5312 if (!err)
5313 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5314 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005315 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005316 goto out_pci_disable_device;
5317 }
5318
5319 pci_set_drvdata(pdev, priv);
5320 err = pci_request_regions(pdev, DRV_NAME);
5321 if (err)
5322 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005323
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005324 /***********************
5325 * 3. Read REV Register
5326 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005327 priv->hw_base = pci_iomap(pdev, 0, 0);
5328 if (!priv->hw_base) {
5329 err = -ENODEV;
5330 goto out_pci_release_regions;
5331 }
5332
Tomas Winklere1623442009-01-27 14:27:56 -08005333 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005334 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005335 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005336
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005337 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5338 * PCI Tx retries from interfering with C3 CPU state */
5339 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005340
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005341 /* amp init */
5342 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005343 if (err < 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08005344 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005345 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005346 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005347
5348 /***********************
5349 * 4. Read EEPROM
5350 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005351
Zhu Yi5a66926a2008-01-14 17:46:18 -08005352 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005353 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005354 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005355 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08005356 goto out_remove_sysfs;
5357 }
5358 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005359 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5360 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005361 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a66926a2008-01-14 17:46:18 -08005362 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5363
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005364 /***********************
5365 * 5. Setup HW Constants
5366 * ********************/
5367 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005368 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005369 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005370 goto out_iounmap;
5371 }
5372
5373 /***********************
5374 * 6. Setup priv
5375 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005376
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005377 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005378 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005379 IWL_ERR(priv, "initializing driver failed\n");
5380 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005381 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005382
Tomas Winkler978785a2008-12-19 10:37:31 +08005383 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5384 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005385
5386 /***********************************
5387 * 7. Initialize Module Parameters
5388 * **********************************/
5389
5390 /* Initialize module parameter values here */
5391 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005392 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005393 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005394 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005395 }
5396
5397
5398 /***********************
5399 * 8. Setup Services
5400 * ********************/
5401
5402 spin_lock_irqsave(&priv->lock, flags);
5403 iwl3945_disable_interrupts(priv);
5404 spin_unlock_irqrestore(&priv->lock, flags);
5405
Helmut Schaa26635162009-01-15 09:38:44 +01005406 pci_enable_msi(priv->pci_dev);
5407
5408 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
5409 DRV_NAME, priv);
5410 if (err) {
5411 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5412 goto out_disable_msi;
5413 }
5414
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005415 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5416 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005417 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005418 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005419 }
5420
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005421 iwl_set_rxon_channel(priv,
5422 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005423 iwl3945_setup_deferred_work(priv);
5424 iwl3945_setup_rx_handlers(priv);
5425
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005426 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005427 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005428 * *******************************/
5429
Zhu Yi5a66926a2008-01-14 17:46:18 -08005430 err = ieee80211_register_hw(priv->hw);
5431 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005432 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005433 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07005434 }
5435
Zhu Yi5a66926a2008-01-14 17:46:18 -08005436 priv->hw->conf.beacon_int = 100;
5437 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005438
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005439 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005440 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005441 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005442 "Ignoring error: %d\n", err);
5443
Helmut Schaa26635162009-01-15 09:38:44 +01005444 /* Start monitoring the killswitch */
5445 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5446 2 * HZ);
5447
Zhu Yib481de92007-09-25 17:54:57 -07005448 return 0;
5449
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005450 out_remove_sysfs:
5451 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005452 out_free_geos:
Samuel Ortiz534166d2009-01-23 13:45:16 -08005453 iwlcore_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005454
5455 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01005456 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07005457 destroy_workqueue(priv->workqueue);
5458 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005459 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005460 out_disable_msi:
5461 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07005462 out_iounmap:
5463 pci_iounmap(pdev, priv->hw_base);
5464 out_pci_release_regions:
5465 pci_release_regions(pdev);
5466 out_pci_disable_device:
5467 pci_disable_device(pdev);
5468 pci_set_drvdata(pdev, NULL);
5469 out_ieee80211_free_hw:
5470 ieee80211_free_hw(priv->hw);
5471 out:
5472 return err;
5473}
5474
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005475static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005476{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005477 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005478 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005479
5480 if (!priv)
5481 return;
5482
Tomas Winklere1623442009-01-27 14:27:56 -08005483 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005484
Zhu Yib481de92007-09-25 17:54:57 -07005485 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005486
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005487 if (priv->mac80211_registered) {
5488 ieee80211_unregister_hw(priv->hw);
5489 priv->mac80211_registered = 0;
5490 } else {
5491 iwl3945_down(priv);
5492 }
Zhu Yib481de92007-09-25 17:54:57 -07005493
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005494 /* make sure we flush any pending irq or
5495 * tasklet for the driver
5496 */
5497 spin_lock_irqsave(&priv->lock, flags);
5498 iwl3945_disable_interrupts(priv);
5499 spin_unlock_irqrestore(&priv->lock, flags);
5500
5501 iwl_synchronize_irq(priv);
5502
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005503 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005504
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005505 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005506 cancel_delayed_work(&priv->rfkill_poll);
5507
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005508 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005509
5510 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005511 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005512 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005513
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005514 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005515 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005516
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005517 /*netif_stop_queue(dev); */
5518 flush_workqueue(priv->workqueue);
5519
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005520 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005521 * priv->workqueue... so we can't take down the workqueue
5522 * until now... */
5523 destroy_workqueue(priv->workqueue);
5524 priv->workqueue = NULL;
5525
Helmut Schaa26635162009-01-15 09:38:44 +01005526 free_irq(pdev->irq, priv);
5527 pci_disable_msi(pdev);
5528
Zhu Yib481de92007-09-25 17:54:57 -07005529 pci_iounmap(pdev, priv->hw_base);
5530 pci_release_regions(pdev);
5531 pci_disable_device(pdev);
5532 pci_set_drvdata(pdev, NULL);
5533
Samuel Ortize6148912009-01-23 13:45:15 -08005534 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005535 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005536 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005537 if (priv->ibss_beacon)
5538 dev_kfree_skb(priv->ibss_beacon);
5539
5540 ieee80211_free_hw(priv->hw);
5541}
5542
5543#ifdef CONFIG_PM
5544
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005545static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005546{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005547 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005548
Zhu Yie655b9f2008-01-24 02:19:38 -08005549 if (priv->is_open) {
5550 set_bit(STATUS_IN_SUSPEND, &priv->status);
5551 iwl3945_mac_stop(priv->hw);
5552 priv->is_open = 1;
5553 }
Helmut Schaa26635162009-01-15 09:38:44 +01005554 pci_save_state(pdev);
5555 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005556 pci_set_power_state(pdev, PCI_D3hot);
5557
Zhu Yib481de92007-09-25 17:54:57 -07005558 return 0;
5559}
5560
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005561static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005562{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005563 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005564 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005565
Zhu Yib481de92007-09-25 17:54:57 -07005566 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005567 ret = pci_enable_device(pdev);
5568 if (ret)
5569 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005570 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005571
Zhu Yie655b9f2008-01-24 02:19:38 -08005572 if (priv->is_open)
5573 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005574
Zhu Yie655b9f2008-01-24 02:19:38 -08005575 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005576 return 0;
5577}
5578
5579#endif /* CONFIG_PM */
5580
5581/*****************************************************************************
5582 *
5583 * driver and module entry point
5584 *
5585 *****************************************************************************/
5586
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005587static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005588 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005589 .id_table = iwl3945_hw_card_ids,
5590 .probe = iwl3945_pci_probe,
5591 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005592#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005593 .suspend = iwl3945_pci_suspend,
5594 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005595#endif
5596};
5597
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005598static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005599{
5600
5601 int ret;
5602 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5603 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005604
5605 ret = iwl3945_rate_control_register();
5606 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005607 printk(KERN_ERR DRV_NAME
5608 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005609 return ret;
5610 }
5611
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005612 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005613 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005614 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005615 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005616 }
Zhu Yib481de92007-09-25 17:54:57 -07005617
5618 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005619
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005620error_register:
5621 iwl3945_rate_control_unregister();
5622 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005623}
5624
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005625static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005626{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005627 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005628 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005629}
5630
Reinette Chatrea0987a82008-12-02 12:14:06 -08005631MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005632
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005633module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005634MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005635module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005636MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005637module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5638MODULE_PARM_DESC(swcrypto,
5639 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005640module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005641MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005642module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005643MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5644
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005645module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005646MODULE_PARM_DESC(queues_num, "number of hw queues.");
5647
Samuel Ortizaf48d042009-01-23 13:45:19 -08005648module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5649MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5650
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005651module_exit(iwl3945_exit);
5652module_init(iwl3945_init);