blob: abb9cd39bcda6f385e55d00df234bcf57f45cad4 [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_set_mode(struct iwl_priv *priv, int mode)
Zhu Yib481de92007-09-25 17:54:57 -0700730{
Johannes Berg05c914f2008-09-11 00:01:58 +0200731 if (mode == NL80211_IFTYPE_ADHOC) {
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800732 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -0700733
Samuel Ortize6148912009-01-23 13:45:15 -0800734 ch_info = iwl_get_channel_info(priv,
Johannes Berg8318d782008-01-24 19:38:38 +0100735 priv->band,
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800736 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700737
738 if (!ch_info || !is_channel_ibss(ch_info)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800739 IWL_ERR(priv, "channel %d not IBSS channel\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800740 le16_to_cpu(priv->staging_rxon.channel));
Zhu Yib481de92007-09-25 17:54:57 -0700741 return -EINVAL;
742 }
743 }
744
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800745 iwl_connection_init_rx_config(priv, mode);
Zhu Yib481de92007-09-25 17:54:57 -0700746
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800747 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700748
Tomas Winklera96a27f2008-10-23 23:48:56 -0700749 /* don't commit rxon if rf-kill is on*/
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800750 if (!iwl_is_ready_rf(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +0800751 return -EAGAIN;
752
753 cancel_delayed_work(&priv->scan_check);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -0800754 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800755 IWL_WARN(priv, "Aborted scan still in progress after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -0800756 IWL_DEBUG_MAC80211(priv, "leaving - scan abort failed.\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +0800757 return -EAGAIN;
758 }
759
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800760 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -0700761
762 return 0;
763}
764
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800765static void iwl3945_build_tx_cmd_hwcrypto(struct iwl_priv *priv,
Johannes Berge039fa42008-05-15 12:55:29 +0200766 struct ieee80211_tx_info *info,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800767 struct iwl_cmd *cmd,
Zhu Yib481de92007-09-25 17:54:57 -0700768 struct sk_buff *skb_frag,
769 int last_frag)
770{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800771 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
Ivo van Doorn1c014422008-04-17 19:41:02 +0200772 struct iwl3945_hw_key *keyinfo =
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +0800773 &priv->stations_39[info->control.hw_key->hw_key_idx].keyinfo;
Zhu Yib481de92007-09-25 17:54:57 -0700774
775 switch (keyinfo->alg) {
776 case ALG_CCMP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800777 tx->sec_ctl = TX_CMD_SEC_CCM;
778 memcpy(tx->key, keyinfo->key, keyinfo->keylen);
Tomas Winklere1623442009-01-27 14:27:56 -0800779 IWL_DEBUG_TX(priv, "tx_cmd with AES hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -0700780 break;
781
782 case ALG_TKIP:
783#if 0
Winkler, Tomase52119c2008-12-22 11:31:19 +0800784 tx->sec_ctl = TX_CMD_SEC_TKIP;
Zhu Yib481de92007-09-25 17:54:57 -0700785
786 if (last_frag)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800787 memcpy(tx->tkip_mic.byte, skb_frag->tail - 8,
Zhu Yib481de92007-09-25 17:54:57 -0700788 8);
789 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800790 memset(tx->tkip_mic.byte, 0, 8);
Zhu Yib481de92007-09-25 17:54:57 -0700791#endif
792 break;
793
794 case ALG_WEP:
Winkler, Tomase52119c2008-12-22 11:31:19 +0800795 tx->sec_ctl = TX_CMD_SEC_WEP |
Johannes Berge039fa42008-05-15 12:55:29 +0200796 (info->control.hw_key->hw_key_idx & TX_CMD_SEC_MSK) << TX_CMD_SEC_SHIFT;
Zhu Yib481de92007-09-25 17:54:57 -0700797
798 if (keyinfo->keylen == 13)
Winkler, Tomase52119c2008-12-22 11:31:19 +0800799 tx->sec_ctl |= TX_CMD_SEC_KEY128;
Zhu Yib481de92007-09-25 17:54:57 -0700800
Winkler, Tomase52119c2008-12-22 11:31:19 +0800801 memcpy(&tx->key[3], keyinfo->key, keyinfo->keylen);
Zhu Yib481de92007-09-25 17:54:57 -0700802
Tomas Winklere1623442009-01-27 14:27:56 -0800803 IWL_DEBUG_TX(priv, "Configuring packet for WEP encryption "
Johannes Berge039fa42008-05-15 12:55:29 +0200804 "with key %d\n", info->control.hw_key->hw_key_idx);
Zhu Yib481de92007-09-25 17:54:57 -0700805 break;
806
Zhu Yib481de92007-09-25 17:54:57 -0700807 default:
Tomas Winkler978785a2008-12-19 10:37:31 +0800808 IWL_ERR(priv, "Unknown encode alg %d\n", keyinfo->alg);
Zhu Yib481de92007-09-25 17:54:57 -0700809 break;
810 }
811}
812
813/*
814 * handle build REPLY_TX command notification.
815 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800816static void iwl3945_build_tx_cmd_basic(struct iwl_priv *priv,
Winkler, Tomasc2d79b482008-12-19 10:37:34 +0800817 struct iwl_cmd *cmd,
Johannes Berge039fa42008-05-15 12:55:29 +0200818 struct ieee80211_tx_info *info,
Winkler, Tomase52119c2008-12-22 11:31:19 +0800819 struct ieee80211_hdr *hdr, u8 std_id)
Zhu Yib481de92007-09-25 17:54:57 -0700820{
Winkler, Tomase52119c2008-12-22 11:31:19 +0800821 struct iwl3945_tx_cmd *tx = (struct iwl3945_tx_cmd *)cmd->cmd.payload;
822 __le32 tx_flags = tx->tx_flags;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700823 __le16 fc = hdr->frame_control;
Johannes Berge6a98542008-10-21 12:40:02 +0200824 u8 rc_flags = info->control.rates[0].flags;
Zhu Yib481de92007-09-25 17:54:57 -0700825
Winkler, Tomase52119c2008-12-22 11:31:19 +0800826 tx->stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
Johannes Berge039fa42008-05-15 12:55:29 +0200827 if (!(info->flags & IEEE80211_TX_CTL_NO_ACK)) {
Zhu Yib481de92007-09-25 17:54:57 -0700828 tx_flags |= TX_CMD_FLG_ACK_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700829 if (ieee80211_is_mgmt(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700830 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700831 if (ieee80211_is_probe_resp(fc) &&
Zhu Yib481de92007-09-25 17:54:57 -0700832 !(le16_to_cpu(hdr->seq_ctrl) & 0xf))
833 tx_flags |= TX_CMD_FLG_TSF_MSK;
834 } else {
835 tx_flags &= (~TX_CMD_FLG_ACK_MSK);
836 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
837 }
838
Winkler, Tomase52119c2008-12-22 11:31:19 +0800839 tx->sta_id = std_id;
Harvey Harrison8b7b1e02008-06-11 14:21:56 -0700840 if (ieee80211_has_morefrags(fc))
Zhu Yib481de92007-09-25 17:54:57 -0700841 tx_flags |= TX_CMD_FLG_MORE_FRAG_MSK;
842
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700843 if (ieee80211_is_data_qos(fc)) {
844 u8 *qc = ieee80211_get_qos_ctl(hdr);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800845 tx->tid_tspec = qc[0] & 0xf;
Zhu Yib481de92007-09-25 17:54:57 -0700846 tx_flags &= ~TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800847 } else {
Zhu Yib481de92007-09-25 17:54:57 -0700848 tx_flags |= TX_CMD_FLG_SEQ_CTL_MSK;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800849 }
Zhu Yib481de92007-09-25 17:54:57 -0700850
Johannes Berge6a98542008-10-21 12:40:02 +0200851 if (rc_flags & IEEE80211_TX_RC_USE_RTS_CTS) {
Zhu Yib481de92007-09-25 17:54:57 -0700852 tx_flags |= TX_CMD_FLG_RTS_MSK;
853 tx_flags &= ~TX_CMD_FLG_CTS_MSK;
Johannes Berge6a98542008-10-21 12:40:02 +0200854 } else if (rc_flags & IEEE80211_TX_RC_USE_CTS_PROTECT) {
Zhu Yib481de92007-09-25 17:54:57 -0700855 tx_flags &= ~TX_CMD_FLG_RTS_MSK;
856 tx_flags |= TX_CMD_FLG_CTS_MSK;
857 }
858
859 if ((tx_flags & TX_CMD_FLG_RTS_MSK) || (tx_flags & TX_CMD_FLG_CTS_MSK))
860 tx_flags |= TX_CMD_FLG_FULL_TXOP_PROT_MSK;
861
862 tx_flags &= ~(TX_CMD_FLG_ANT_SEL_MSK);
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700863 if (ieee80211_is_mgmt(fc)) {
864 if (ieee80211_is_assoc_req(fc) || ieee80211_is_reassoc_req(fc))
Winkler, Tomase52119c2008-12-22 11:31:19 +0800865 tx->timeout.pm_frame_timeout = cpu_to_le16(3);
Zhu Yib481de92007-09-25 17:54:57 -0700866 else
Winkler, Tomase52119c2008-12-22 11:31:19 +0800867 tx->timeout.pm_frame_timeout = cpu_to_le16(2);
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700868 } else {
Winkler, Tomase52119c2008-12-22 11:31:19 +0800869 tx->timeout.pm_frame_timeout = 0;
Mohamed Abbasab53d8a2008-03-25 16:33:36 -0700870#ifdef CONFIG_IWL3945_LEDS
871 priv->rxtxpackets += le16_to_cpu(cmd->cmd.tx.len);
872#endif
873 }
Zhu Yib481de92007-09-25 17:54:57 -0700874
Winkler, Tomase52119c2008-12-22 11:31:19 +0800875 tx->driver_txop = 0;
876 tx->tx_flags = tx_flags;
877 tx->next_frame_len = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700878}
879
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800880/**
881 * iwl3945_get_sta_id - Find station's index within station table
882 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800883static int iwl3945_get_sta_id(struct iwl_priv *priv, struct ieee80211_hdr *hdr)
Zhu Yib481de92007-09-25 17:54:57 -0700884{
885 int sta_id;
886 u16 fc = le16_to_cpu(hdr->frame_control);
887
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800888 /* If this frame is broadcast or management, use broadcast station id */
Zhu Yib481de92007-09-25 17:54:57 -0700889 if (((fc & IEEE80211_FCTL_FTYPE) != IEEE80211_FTYPE_DATA) ||
890 is_multicast_ether_addr(hdr->addr1))
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800891 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700892
893 switch (priv->iw_mode) {
894
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800895 /* If we are a client station in a BSS network, use the special
896 * AP station entry (that's the only station we communicate with) */
Johannes Berg05c914f2008-09-11 00:01:58 +0200897 case NL80211_IFTYPE_STATION:
Zhu Yib481de92007-09-25 17:54:57 -0700898 return IWL_AP_ID;
899
900 /* If we are an AP, then find the station, or use BCAST */
Johannes Berg05c914f2008-09-11 00:01:58 +0200901 case NL80211_IFTYPE_AP:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800902 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700903 if (sta_id != IWL_INVALID_STATION)
904 return sta_id;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800905 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700906
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800907 /* If this frame is going out to an IBSS network, find the station,
908 * or create a new station table entry */
Johannes Berg05c914f2008-09-11 00:01:58 +0200909 case NL80211_IFTYPE_ADHOC: {
Cahill, Ben M6440adb2007-11-29 11:09:55 +0800910 /* Create new station table entry */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800911 sta_id = iwl3945_hw_find_station(priv, hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -0700912 if (sta_id != IWL_INVALID_STATION)
913 return sta_id;
914
Christoph Hellwigbb8c0932008-01-27 16:41:47 -0800915 sta_id = iwl3945_add_station(priv, hdr->addr1, 0, CMD_ASYNC);
Zhu Yib481de92007-09-25 17:54:57 -0700916
917 if (sta_id != IWL_INVALID_STATION)
918 return sta_id;
919
Tomas Winklere1623442009-01-27 14:27:56 -0800920 IWL_DEBUG_DROP(priv, "Station %pM not in station map. "
Zhu Yib481de92007-09-25 17:54:57 -0700921 "Defaulting to broadcast...\n",
Johannes Berge1749612008-10-27 15:59:26 -0700922 hdr->addr1);
Samuel Ortiz40b8ec02008-12-19 10:37:08 +0800923 iwl_print_hex_dump(priv, IWL_DL_DROP, (u8 *) hdr, sizeof(*hdr));
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800924 return priv->hw_params.bcast_sta_id;
Joe Perches0795af52007-10-03 17:59:30 -0700925 }
Stefanik Gábor914233d2008-06-30 17:23:30 +0800926 /* If we are in monitor mode, use BCAST. This is required for
927 * packet injection. */
Johannes Berg05c914f2008-09-11 00:01:58 +0200928 case NL80211_IFTYPE_MONITOR:
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800929 return priv->hw_params.bcast_sta_id;
Stefanik Gábor914233d2008-06-30 17:23:30 +0800930
Zhu Yib481de92007-09-25 17:54:57 -0700931 default:
Winkler, Tomas39aadf82008-12-19 10:37:32 +0800932 IWL_WARN(priv, "Unknown mode of operation: %d\n",
933 priv->iw_mode);
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +0800934 return priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -0700935 }
936}
937
938/*
939 * start REPLY_TX command process
940 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +0800941static int iwl3945_tx_skb(struct iwl_priv *priv, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -0700942{
943 struct ieee80211_hdr *hdr = (struct ieee80211_hdr *)skb->data;
Johannes Berge039fa42008-05-15 12:55:29 +0200944 struct ieee80211_tx_info *info = IEEE80211_SKB_CB(skb);
Winkler, Tomase52119c2008-12-22 11:31:19 +0800945 struct iwl3945_tx_cmd *tx;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +0800946 struct iwl_tx_queue *txq = NULL;
Samuel Ortizd20b3c62008-12-19 10:37:15 +0800947 struct iwl_queue *q = NULL;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800948 struct iwl_cmd *out_cmd = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700949 dma_addr_t phys_addr;
950 dma_addr_t txcmd_phys;
Winkler, Tomase52119c2008-12-22 11:31:19 +0800951 int txq_id = skb_get_queue_mapping(skb);
Tomas Winkler54dbb522008-05-15 13:54:06 +0800952 u16 len, idx, len_org, hdr_len;
953 u8 id;
954 u8 unicast;
Zhu Yib481de92007-09-25 17:54:57 -0700955 u8 sta_id;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800956 u8 tid = 0;
Zhu Yib481de92007-09-25 17:54:57 -0700957 u16 seq_number = 0;
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700958 __le16 fc;
Zhu Yib481de92007-09-25 17:54:57 -0700959 u8 wait_write_ptr = 0;
Tomas Winkler54dbb522008-05-15 13:54:06 +0800960 u8 *qc = NULL;
Zhu Yib481de92007-09-25 17:54:57 -0700961 unsigned long flags;
962 int rc;
963
964 spin_lock_irqsave(&priv->lock, flags);
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +0800965 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -0800966 IWL_DEBUG_DROP(priv, "Dropping - RF KILL\n");
Zhu Yib481de92007-09-25 17:54:57 -0700967 goto drop_unlock;
968 }
969
Johannes Berge039fa42008-05-15 12:55:29 +0200970 if ((ieee80211_get_tx_rate(priv->hw, info)->hw_value & 0xFF) == IWL_INVALID_RATE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +0800971 IWL_ERR(priv, "ERROR: No TX rate available.\n");
Zhu Yib481de92007-09-25 17:54:57 -0700972 goto drop_unlock;
973 }
974
975 unicast = !is_multicast_ether_addr(hdr->addr1);
976 id = 0;
977
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700978 fc = hdr->frame_control;
Zhu Yib481de92007-09-25 17:54:57 -0700979
Samuel Ortizd08853a2009-01-23 13:45:17 -0800980#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -0700981 if (ieee80211_is_auth(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800982 IWL_DEBUG_TX(priv, "Sending AUTH frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700983 else if (ieee80211_is_assoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800984 IWL_DEBUG_TX(priv, "Sending ASSOC frame\n");
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -0700985 else if (ieee80211_is_reassoc_req(fc))
Tomas Winklere1623442009-01-27 14:27:56 -0800986 IWL_DEBUG_TX(priv, "Sending REASSOC frame\n");
Zhu Yib481de92007-09-25 17:54:57 -0700987#endif
988
Mohamed Abbas7878a5a2007-11-29 11:10:13 +0800989 /* drop all data frame if we are not associated */
Stefanik Gábor914233d2008-06-30 17:23:30 +0800990 if (ieee80211_is_data(fc) &&
Johannes Berg05c914f2008-09-11 00:01:58 +0200991 (priv->iw_mode != NL80211_IFTYPE_MONITOR) && /* packet injection */
Samuel Ortiz8ccde882009-01-27 14:27:52 -0800992 (!iwl_is_associated(priv) ||
Johannes Berg05c914f2008-09-11 00:01:58 +0200993 ((priv->iw_mode == NL80211_IFTYPE_STATION) && !priv->assoc_id))) {
Tomas Winklere1623442009-01-27 14:27:56 -0800994 IWL_DEBUG_DROP(priv, "Dropping - !iwl_is_associated\n");
Zhu Yib481de92007-09-25 17:54:57 -0700995 goto drop_unlock;
996 }
997
998 spin_unlock_irqrestore(&priv->lock, flags);
999
Harvey Harrison7294ec92008-07-15 18:43:59 -07001000 hdr_len = ieee80211_hdrlen(fc);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001001
1002 /* Find (or create) index into station table for destination station */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001003 sta_id = iwl3945_get_sta_id(priv, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001004 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08001005 IWL_DEBUG_DROP(priv, "Dropping - INVALID STATION: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07001006 hdr->addr1);
Zhu Yib481de92007-09-25 17:54:57 -07001007 goto drop;
1008 }
1009
Tomas Winklere1623442009-01-27 14:27:56 -08001010 IWL_DEBUG_RATE(priv, "station Id %d\n", sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001011
Harvey Harrisonfd7c8a42008-06-11 14:21:56 -07001012 if (ieee80211_is_data_qos(fc)) {
1013 qc = ieee80211_get_qos_ctl(hdr);
Harvey Harrison7294ec92008-07-15 18:43:59 -07001014 tid = qc[0] & IEEE80211_QOS_CTL_TID_MASK;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001015 seq_number = priv->stations_39[sta_id].tid[tid].seq_number &
Zhu Yib481de92007-09-25 17:54:57 -07001016 IEEE80211_SCTL_SEQ;
1017 hdr->seq_ctrl = cpu_to_le16(seq_number) |
1018 (hdr->seq_ctrl &
Harvey Harrisonc1b4aa32009-01-29 13:26:44 -08001019 cpu_to_le16(IEEE80211_SCTL_FRAG));
Zhu Yib481de92007-09-25 17:54:57 -07001020 seq_number += 0x10;
1021 }
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001022
1023 /* Descriptor for chosen Tx queue */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001024 txq = &priv->txq[txq_id];
Zhu Yib481de92007-09-25 17:54:57 -07001025 q = &txq->q;
1026
1027 spin_lock_irqsave(&priv->lock, flags);
1028
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001029 idx = get_cmd_index(q, q->write_ptr, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001030
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001031 /* Set up driver data for this TFD */
Winkler, Tomasdbb66542008-12-22 11:31:14 +08001032 memset(&(txq->txb[q->write_ptr]), 0, sizeof(struct iwl_tx_info));
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001033 txq->txb[q->write_ptr].skb[0] = skb;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001034
1035 /* Init first empty entry in queue's array of Tx/cmd buffers */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001036 out_cmd = txq->cmd[idx];
Winkler, Tomase52119c2008-12-22 11:31:19 +08001037 tx = (struct iwl3945_tx_cmd *)out_cmd->cmd.payload;
Zhu Yib481de92007-09-25 17:54:57 -07001038 memset(&out_cmd->hdr, 0, sizeof(out_cmd->hdr));
Winkler, Tomase52119c2008-12-22 11:31:19 +08001039 memset(tx, 0, sizeof(*tx));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001040
1041 /*
1042 * Set up the Tx-command (not MAC!) header.
1043 * Store the chosen Tx queue and TFD index within the sequence field;
1044 * after Tx, uCode's Tx response will return this value so driver can
1045 * locate the frame within the tx queue and do post-tx processing.
1046 */
Zhu Yib481de92007-09-25 17:54:57 -07001047 out_cmd->hdr.cmd = REPLY_TX;
1048 out_cmd->hdr.sequence = cpu_to_le16((u16)(QUEUE_TO_SEQ(txq_id) |
Tomas Winklerfc4b6852007-10-25 17:15:24 +08001049 INDEX_TO_SEQ(q->write_ptr)));
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001050
1051 /* Copy MAC header from skb into command buffer */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001052 memcpy(tx->hdr, hdr, hdr_len);
Zhu Yib481de92007-09-25 17:54:57 -07001053
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001054 /*
1055 * Use the first empty entry in this queue's command buffer array
1056 * to contain the Tx command and MAC header concatenated together
1057 * (payload data will be in another buffer).
1058 * Size of this varies, due to varying MAC header length.
1059 * If end is not dword aligned, we'll have 2 extra bytes at the end
1060 * of the MAC header (device reads on dword boundaries).
1061 * We'll tell device about this padding later.
1062 */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08001063 len = sizeof(struct iwl3945_tx_cmd) +
Tomas Winkler4c897252008-12-19 10:37:05 +08001064 sizeof(struct iwl_cmd_header) + hdr_len;
Zhu Yib481de92007-09-25 17:54:57 -07001065
1066 len_org = len;
1067 len = (len + 3) & ~3;
1068
1069 if (len_org != len)
1070 len_org = 1;
1071 else
1072 len_org = 0;
1073
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001074 /* Physical address of this Tx command's header (not MAC header!),
1075 * within command buffer array. */
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001076 txcmd_phys = pci_map_single(priv->pci_dev,
1077 out_cmd, sizeof(struct iwl_cmd),
1078 PCI_DMA_TODEVICE);
1079 pci_unmap_addr_set(&out_cmd->meta, mapping, txcmd_phys);
1080 pci_unmap_len_set(&out_cmd->meta, len, sizeof(struct iwl_cmd));
1081 /* Add buffer containing Tx command and MAC(!) header to TFD's
1082 * first entry */
1083 txcmd_phys += offsetof(struct iwl_cmd, hdr);
Zhu Yib481de92007-09-25 17:54:57 -07001084
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001085 /* Add buffer containing Tx command and MAC(!) header to TFD's
1086 * first entry */
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001087 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1088 txcmd_phys, len, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001089
Johannes Bergd0f09802008-07-29 11:32:07 +02001090 if (info->control.hw_key)
Johannes Berge039fa42008-05-15 12:55:29 +02001091 iwl3945_build_tx_cmd_hwcrypto(priv, info, out_cmd, skb, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001092
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001093 /* Set up TFD's 2nd entry to point directly to remainder of skb,
1094 * if any (802.11 null frames have no payload). */
Zhu Yib481de92007-09-25 17:54:57 -07001095 len = skb->len - hdr_len;
1096 if (len) {
1097 phys_addr = pci_map_single(priv->pci_dev, skb->data + hdr_len,
1098 len, PCI_DMA_TODEVICE);
Samuel Ortiz7aaa1d72009-01-19 15:30:26 -08001099 priv->cfg->ops->lib->txq_attach_buf_to_tfd(priv, txq,
1100 phys_addr, len,
1101 0, U32_PAD(len));
Zhu Yib481de92007-09-25 17:54:57 -07001102 }
1103
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001104 /* Total # bytes to be transmitted */
Zhu Yib481de92007-09-25 17:54:57 -07001105 len = (u16)skb->len;
Winkler, Tomase52119c2008-12-22 11:31:19 +08001106 tx->len = cpu_to_le16(len);
Zhu Yib481de92007-09-25 17:54:57 -07001107
1108 /* TODO need this for burst mode later on */
Winkler, Tomase52119c2008-12-22 11:31:19 +08001109 iwl3945_build_tx_cmd_basic(priv, out_cmd, info, hdr, sta_id);
Zhu Yib481de92007-09-25 17:54:57 -07001110
1111 /* set is_hcca to 0; it probably will never be implemented */
Johannes Berge039fa42008-05-15 12:55:29 +02001112 iwl3945_hw_build_tx_cmd_rate(priv, out_cmd, info, hdr, sta_id, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001113
Winkler, Tomase52119c2008-12-22 11:31:19 +08001114 tx->tx_flags &= ~TX_CMD_FLG_ANT_A_MSK;
1115 tx->tx_flags &= ~TX_CMD_FLG_ANT_B_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07001116
Harvey Harrison8b7b1e02008-06-11 14:21:56 -07001117 if (!ieee80211_has_morefrags(hdr->frame_control)) {
Zhu Yib481de92007-09-25 17:54:57 -07001118 txq->need_update = 1;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001119 if (qc)
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08001120 priv->stations_39[sta_id].tid[tid].seq_number = seq_number;
Zhu Yib481de92007-09-25 17:54:57 -07001121 } else {
1122 wait_write_ptr = 1;
1123 txq->need_update = 0;
1124 }
1125
Winkler, Tomase52119c2008-12-22 11:31:19 +08001126 iwl_print_hex_dump(priv, IWL_DL_TX, tx, sizeof(*tx));
Zhu Yib481de92007-09-25 17:54:57 -07001127
Winkler, Tomase52119c2008-12-22 11:31:19 +08001128 iwl_print_hex_dump(priv, IWL_DL_TX, (u8 *)tx->hdr,
Harvey Harrison7294ec92008-07-15 18:43:59 -07001129 ieee80211_hdrlen(fc));
Zhu Yib481de92007-09-25 17:54:57 -07001130
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001131 /* Tell device the write index *just past* this latest filled TFD */
Tomas Winklerc54b6792008-03-06 17:36:53 -08001132 q->write_ptr = iwl_queue_inc_wrap(q->write_ptr, q->n_bd);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001133 rc = iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001134 spin_unlock_irqrestore(&priv->lock, flags);
1135
1136 if (rc)
1137 return rc;
1138
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001139 if ((iwl_queue_space(q) < q->high_mark)
Zhu Yib481de92007-09-25 17:54:57 -07001140 && priv->mac80211_registered) {
1141 if (wait_write_ptr) {
1142 spin_lock_irqsave(&priv->lock, flags);
1143 txq->need_update = 1;
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08001144 iwl_txq_update_write_ptr(priv, txq);
Zhu Yib481de92007-09-25 17:54:57 -07001145 spin_unlock_irqrestore(&priv->lock, flags);
1146 }
1147
Johannes Berge2530082008-05-17 00:57:14 +02001148 ieee80211_stop_queue(priv->hw, skb_get_queue_mapping(skb));
Zhu Yib481de92007-09-25 17:54:57 -07001149 }
1150
1151 return 0;
1152
1153drop_unlock:
1154 spin_unlock_irqrestore(&priv->lock, flags);
1155drop:
1156 return -1;
1157}
1158
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001159static void iwl3945_radio_kill_sw(struct iwl_priv *priv, int disable_radio)
Zhu Yib481de92007-09-25 17:54:57 -07001160{
1161 unsigned long flags;
1162
1163 if (!!disable_radio == test_bit(STATUS_RF_KILL_SW, &priv->status))
1164 return;
1165
Tomas Winklere1623442009-01-27 14:27:56 -08001166 IWL_DEBUG_RF_KILL(priv, "Manual SW RF KILL set to: RADIO %s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001167 disable_radio ? "OFF" : "ON");
1168
1169 if (disable_radio) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001170 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001171 /* FIXME: This is a workaround for AP */
Johannes Berg05c914f2008-09-11 00:01:58 +02001172 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07001173 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001174 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001175 CSR_UCODE_SW_BIT_RFKILL);
1176 spin_unlock_irqrestore(&priv->lock, flags);
Samuel Ortizc4962942008-12-22 11:31:18 +08001177 iwl_send_card_state(priv, CARD_STATE_CMD_DISABLE, 0);
Zhu Yib481de92007-09-25 17:54:57 -07001178 set_bit(STATUS_RF_KILL_SW, &priv->status);
1179 }
1180 return;
1181 }
1182
1183 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001184 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07001185
1186 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1187 spin_unlock_irqrestore(&priv->lock, flags);
1188
1189 /* wake up ucode */
1190 msleep(10);
1191
1192 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001193 iwl_read32(priv, CSR_UCODE_DRV_GP1);
1194 if (!iwl_grab_nic_access(priv))
1195 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001196 spin_unlock_irqrestore(&priv->lock, flags);
1197
1198 if (test_bit(STATUS_RF_KILL_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08001199 IWL_DEBUG_RF_KILL(priv, "Can not turn radio back on - "
Zhu Yib481de92007-09-25 17:54:57 -07001200 "disabled by HW switch\n");
1201 return;
1202 }
1203
Zhu Yi808e72a2008-06-12 09:47:17 +08001204 if (priv->is_open)
1205 queue_work(priv->workqueue, &priv->restart);
Zhu Yib481de92007-09-25 17:54:57 -07001206 return;
1207}
1208
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001209#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07001210
1211#include "iwl-spectrum.h"
1212
1213#define BEACON_TIME_MASK_LOW 0x00FFFFFF
1214#define BEACON_TIME_MASK_HIGH 0xFF000000
1215#define TIME_UNIT 1024
1216
1217/*
1218 * extended beacon time format
1219 * time in usec will be changed into a 32-bit value in 8:24 format
1220 * the high 1 byte is the beacon counts
1221 * the lower 3 bytes is the time in usec within one beacon interval
1222 */
1223
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001224static u32 iwl3945_usecs_to_beacons(u32 usec, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001225{
1226 u32 quot;
1227 u32 rem;
1228 u32 interval = beacon_interval * 1024;
1229
1230 if (!interval || !usec)
1231 return 0;
1232
1233 quot = (usec / interval) & (BEACON_TIME_MASK_HIGH >> 24);
1234 rem = (usec % interval) & BEACON_TIME_MASK_LOW;
1235
1236 return (quot << 24) + rem;
1237}
1238
1239/* base is usually what we get from ucode with each received frame,
1240 * the same as HW timer counter counting down
1241 */
1242
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001243static __le32 iwl3945_add_beacon_time(u32 base, u32 addon, u32 beacon_interval)
Zhu Yib481de92007-09-25 17:54:57 -07001244{
1245 u32 base_low = base & BEACON_TIME_MASK_LOW;
1246 u32 addon_low = addon & BEACON_TIME_MASK_LOW;
1247 u32 interval = beacon_interval * TIME_UNIT;
1248 u32 res = (base & BEACON_TIME_MASK_HIGH) +
1249 (addon & BEACON_TIME_MASK_HIGH);
1250
1251 if (base_low > addon_low)
1252 res += base_low - addon_low;
1253 else if (base_low < addon_low) {
1254 res += interval + base_low - addon_low;
1255 res += (1 << 24);
1256 } else
1257 res += (1 << 24);
1258
1259 return cpu_to_le32(res);
1260}
1261
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001262static int iwl3945_get_measurement(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001263 struct ieee80211_measurement_params *params,
1264 u8 type)
1265{
Tomas Winkler600c0e12008-12-19 10:37:04 +08001266 struct iwl_spectrum_cmd spectrum;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001267 struct iwl_rx_packet *res;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001268 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07001269 .id = REPLY_SPECTRUM_MEASUREMENT_CMD,
1270 .data = (void *)&spectrum,
1271 .meta.flags = CMD_WANT_SKB,
1272 };
1273 u32 add_time = le64_to_cpu(params->start_time);
1274 int rc;
1275 int spectrum_resp_status;
1276 int duration = le16_to_cpu(params->duration);
1277
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001278 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001279 add_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001280 iwl3945_usecs_to_beacons(
Zhu Yib481de92007-09-25 17:54:57 -07001281 le64_to_cpu(params->start_time) - priv->last_tsf,
1282 le16_to_cpu(priv->rxon_timing.beacon_interval));
1283
1284 memset(&spectrum, 0, sizeof(spectrum));
1285
1286 spectrum.channel_count = cpu_to_le16(1);
1287 spectrum.flags =
1288 RXON_FLG_TSF2HOST_MSK | RXON_FLG_ANT_A_MSK | RXON_FLG_DIS_DIV_MSK;
1289 spectrum.filter_flags = MEASUREMENT_FILTER_FLAG;
1290 cmd.len = sizeof(spectrum);
1291 spectrum.len = cpu_to_le16(cmd.len - sizeof(spectrum.len));
1292
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001293 if (iwl_is_associated(priv))
Zhu Yib481de92007-09-25 17:54:57 -07001294 spectrum.start_time =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001295 iwl3945_add_beacon_time(priv->last_beacon_time,
Zhu Yib481de92007-09-25 17:54:57 -07001296 add_time,
1297 le16_to_cpu(priv->rxon_timing.beacon_interval));
1298 else
1299 spectrum.start_time = 0;
1300
1301 spectrum.channels[0].duration = cpu_to_le32(duration * TIME_UNIT);
1302 spectrum.channels[0].channel = params->channel;
1303 spectrum.channels[0].type = type;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001304 if (priv->active_rxon.flags & RXON_FLG_BAND_24G_MSK)
Zhu Yib481de92007-09-25 17:54:57 -07001305 spectrum.flags |= RXON_FLG_BAND_24G_MSK |
1306 RXON_FLG_AUTO_DETECT_MSK | RXON_FLG_TGG_PROTECT_MSK;
1307
Samuel Ortiz518099a2009-01-19 15:30:27 -08001308 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07001309 if (rc)
1310 return rc;
1311
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001312 res = (struct iwl_rx_packet *)cmd.meta.u.skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001313 if (res->hdr.flags & IWL_CMD_FAILED_MSK) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001314 IWL_ERR(priv, "Bad return from REPLY_RX_ON_ASSOC command\n");
Zhu Yib481de92007-09-25 17:54:57 -07001315 rc = -EIO;
1316 }
1317
1318 spectrum_resp_status = le16_to_cpu(res->u.spectrum.status);
1319 switch (spectrum_resp_status) {
1320 case 0: /* Command will be handled */
1321 if (res->u.spectrum.id != 0xff) {
Tomas Winklere1623442009-01-27 14:27:56 -08001322 IWL_DEBUG_INFO(priv, "Replaced existing measurement: %d\n",
Ian Schrambc434dd2007-10-25 17:15:29 +08001323 res->u.spectrum.id);
Zhu Yib481de92007-09-25 17:54:57 -07001324 priv->measurement_status &= ~MEASUREMENT_READY;
1325 }
1326 priv->measurement_status |= MEASUREMENT_ACTIVE;
1327 rc = 0;
1328 break;
1329
1330 case 1: /* Command will not be handled */
1331 rc = -EAGAIN;
1332 break;
1333 }
1334
1335 dev_kfree_skb_any(cmd.meta.u.skb);
1336
1337 return rc;
1338}
1339#endif
1340
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001341static void iwl3945_rx_reply_alive(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001342 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001343{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001344 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
1345 struct iwl_alive_resp *palive;
Zhu Yib481de92007-09-25 17:54:57 -07001346 struct delayed_work *pwork;
1347
1348 palive = &pkt->u.alive_frame;
1349
Tomas Winklere1623442009-01-27 14:27:56 -08001350 IWL_DEBUG_INFO(priv, "Alive ucode status 0x%08X revision "
Zhu Yib481de92007-09-25 17:54:57 -07001351 "0x%01X 0x%01X\n",
1352 palive->is_valid, palive->ver_type,
1353 palive->ver_subtype);
1354
1355 if (palive->ver_subtype == INITIALIZE_SUBTYPE) {
Tomas Winklere1623442009-01-27 14:27:56 -08001356 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001357 memcpy(&priv->card_alive_init, &pkt->u.alive_frame,
1358 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001359 pwork = &priv->init_alive_start;
1360 } else {
Tomas Winklere1623442009-01-27 14:27:56 -08001361 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001362 memcpy(&priv->card_alive, &pkt->u.alive_frame,
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001363 sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07001364 pwork = &priv->alive_start;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001365 iwl3945_disable_events(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001366 }
1367
1368 /* We delay the ALIVE response by 5ms to
1369 * give the HW RF Kill time to activate... */
1370 if (palive->is_valid == UCODE_VALID_OK)
1371 queue_delayed_work(priv->workqueue, pwork,
1372 msecs_to_jiffies(5));
1373 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001374 IWL_WARN(priv, "uCode did not respond OK.\n");
Zhu Yib481de92007-09-25 17:54:57 -07001375}
1376
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001377static void iwl3945_rx_reply_add_sta(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001378 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001379{
Helmut Schaac7e035a2009-01-19 13:02:15 +01001380#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001381 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Helmut Schaac7e035a2009-01-19 13:02:15 +01001382#endif
Zhu Yib481de92007-09-25 17:54:57 -07001383
Tomas Winklere1623442009-01-27 14:27:56 -08001384 IWL_DEBUG_RX(priv, "Received REPLY_ADD_STA: 0x%02X\n", pkt->u.status);
Zhu Yib481de92007-09-25 17:54:57 -07001385 return;
1386}
1387
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001388static void iwl3945_rx_reply_error(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001389 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001390{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001391 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001392
Winkler, Tomas15b16872008-12-19 10:37:33 +08001393 IWL_ERR(priv, "Error Reply type 0x%08X cmd %s (0x%02X) "
Zhu Yib481de92007-09-25 17:54:57 -07001394 "seq 0x%04X ser 0x%08X\n",
1395 le32_to_cpu(pkt->u.err_resp.error_type),
1396 get_cmd_string(pkt->u.err_resp.cmd_id),
1397 pkt->u.err_resp.cmd_id,
1398 le16_to_cpu(pkt->u.err_resp.bad_cmd_seq_num),
1399 le32_to_cpu(pkt->u.err_resp.error_info));
1400}
1401
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001402static void iwl3945_rx_spectrum_measure_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001403 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001404{
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08001405#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001406 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Tomas Winkler600c0e12008-12-19 10:37:04 +08001407 struct iwl_spectrum_notification *report = &(pkt->u.spectrum_notif);
Zhu Yib481de92007-09-25 17:54:57 -07001408
1409 if (!report->state) {
Tomas Winklere1623442009-01-27 14:27:56 -08001410 IWL_DEBUG(priv, IWL_DL_11H | IWL_DL_INFO,
Zhu Yib481de92007-09-25 17:54:57 -07001411 "Spectrum Measure Notification: Start\n");
1412 return;
1413 }
1414
1415 memcpy(&priv->measure_report, report, sizeof(*report));
1416 priv->measurement_status |= MEASUREMENT_READY;
1417#endif
1418}
1419
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001420static void iwl3945_bg_beacon_update(struct work_struct *work)
Zhu Yib481de92007-09-25 17:54:57 -07001421{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001422 struct iwl_priv *priv =
1423 container_of(work, struct iwl_priv, beacon_update);
Zhu Yib481de92007-09-25 17:54:57 -07001424 struct sk_buff *beacon;
1425
1426 /* Pull updated AP beacon from mac80211. will fail if not in AP mode */
Johannes Berge039fa42008-05-15 12:55:29 +02001427 beacon = ieee80211_beacon_get(priv->hw, priv->vif);
Zhu Yib481de92007-09-25 17:54:57 -07001428
1429 if (!beacon) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001430 IWL_ERR(priv, "update beacon failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07001431 return;
1432 }
1433
1434 mutex_lock(&priv->mutex);
1435 /* new beacon skb is allocated every time; dispose previous.*/
1436 if (priv->ibss_beacon)
1437 dev_kfree_skb(priv->ibss_beacon);
1438
1439 priv->ibss_beacon = beacon;
1440 mutex_unlock(&priv->mutex);
1441
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001442 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001443}
1444
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001445static void iwl3945_rx_beacon_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001446 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001447{
Samuel Ortizd08853a2009-01-23 13:45:17 -08001448#ifdef CONFIG_IWLWIFI_DEBUG
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001449 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001450 struct iwl3945_beacon_notif *beacon = &(pkt->u.beacon_status);
Zhu Yib481de92007-09-25 17:54:57 -07001451 u8 rate = beacon->beacon_notify_hdr.rate;
1452
Tomas Winklere1623442009-01-27 14:27:56 -08001453 IWL_DEBUG_RX(priv, "beacon status %x retries %d iss %d "
Zhu Yib481de92007-09-25 17:54:57 -07001454 "tsf %d %d rate %d\n",
1455 le32_to_cpu(beacon->beacon_notify_hdr.status) & TX_STATUS_MSK,
1456 beacon->beacon_notify_hdr.failure_frame,
1457 le32_to_cpu(beacon->ibss_mgr_status),
1458 le32_to_cpu(beacon->high_tsf),
1459 le32_to_cpu(beacon->low_tsf), rate);
1460#endif
1461
Johannes Berg05c914f2008-09-11 00:01:58 +02001462 if ((priv->iw_mode == NL80211_IFTYPE_AP) &&
Zhu Yib481de92007-09-25 17:54:57 -07001463 (!test_bit(STATUS_EXIT_PENDING, &priv->status)))
1464 queue_work(priv->workqueue, &priv->beacon_update);
1465}
1466
Zhu Yib481de92007-09-25 17:54:57 -07001467/* Handle notification from uCode that card's power state is changing
1468 * due to software, hardware, or critical temperature RFKILL */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001469static void iwl3945_rx_card_state_notif(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001470 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001471{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001472 struct iwl_rx_packet *pkt = (void *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001473 u32 flags = le32_to_cpu(pkt->u.card_state_notif.flags);
1474 unsigned long status = priv->status;
1475
Tomas Winklere1623442009-01-27 14:27:56 -08001476 IWL_DEBUG_RF_KILL(priv, "Card state received: HW:%s SW:%s\n",
Zhu Yib481de92007-09-25 17:54:57 -07001477 (flags & HW_CARD_DISABLED) ? "Kill" : "On",
1478 (flags & SW_CARD_DISABLED) ? "Kill" : "On");
1479
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08001480 iwl_write32(priv, CSR_UCODE_DRV_GP1_SET,
Zhu Yib481de92007-09-25 17:54:57 -07001481 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
1482
1483 if (flags & HW_CARD_DISABLED)
1484 set_bit(STATUS_RF_KILL_HW, &priv->status);
1485 else
1486 clear_bit(STATUS_RF_KILL_HW, &priv->status);
1487
1488
1489 if (flags & SW_CARD_DISABLED)
1490 set_bit(STATUS_RF_KILL_SW, &priv->status);
1491 else
1492 clear_bit(STATUS_RF_KILL_SW, &priv->status);
1493
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08001494 iwl_scan_cancel(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001495
1496 if ((test_bit(STATUS_RF_KILL_HW, &status) !=
1497 test_bit(STATUS_RF_KILL_HW, &priv->status)) ||
1498 (test_bit(STATUS_RF_KILL_SW, &status) !=
1499 test_bit(STATUS_RF_KILL_SW, &priv->status)))
1500 queue_work(priv->workqueue, &priv->rf_kill);
1501 else
1502 wake_up_interruptible(&priv->wait_command_queue);
1503}
1504
1505/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001506 * iwl3945_setup_rx_handlers - Initialize Rx handler callbacks
Zhu Yib481de92007-09-25 17:54:57 -07001507 *
1508 * Setup the RX handlers for each of the reply types sent from the uCode
1509 * to the host.
1510 *
1511 * This function chains into the hardware specific files for them to setup
1512 * any hardware specific handlers as well.
1513 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001514static void iwl3945_setup_rx_handlers(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001515{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001516 priv->rx_handlers[REPLY_ALIVE] = iwl3945_rx_reply_alive;
1517 priv->rx_handlers[REPLY_ADD_STA] = iwl3945_rx_reply_add_sta;
1518 priv->rx_handlers[REPLY_ERROR] = iwl3945_rx_reply_error;
Samuel Ortiz8ccde882009-01-27 14:27:52 -08001519 priv->rx_handlers[CHANNEL_SWITCH_NOTIFICATION] = iwl_rx_csa;
Zhu Yib481de92007-09-25 17:54:57 -07001520 priv->rx_handlers[SPECTRUM_MEASURE_NOTIFICATION] =
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001521 iwl3945_rx_spectrum_measure_notif;
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001522 priv->rx_handlers[PM_SLEEP_NOTIFICATION] = iwl_rx_pm_sleep_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001523 priv->rx_handlers[PM_DEBUG_STATISTIC_NOTIFIC] =
Abhijeet Kolekar030f05e2009-02-18 15:54:28 -08001524 iwl_rx_pm_debug_statistics_notif;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001525 priv->rx_handlers[BEACON_NOTIFICATION] = iwl3945_rx_beacon_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001526
Ben Cahill9fbab512007-11-29 11:09:47 +08001527 /*
1528 * The same handler is used for both the REPLY to a discrete
1529 * statistics request from the host as well as for the periodic
1530 * statistics notifications (after received beacons) from the uCode.
Zhu Yib481de92007-09-25 17:54:57 -07001531 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001532 priv->rx_handlers[REPLY_STATISTICS_CMD] = iwl3945_hw_rx_statistics;
1533 priv->rx_handlers[STATISTICS_NOTIFICATION] = iwl3945_hw_rx_statistics;
Zhu Yib481de92007-09-25 17:54:57 -07001534
Abhijeet Kolekarcade0eb2009-02-18 15:54:26 -08001535 iwl_setup_rx_scan_handlers(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001536 priv->rx_handlers[CARD_STATE_NOTIFICATION] = iwl3945_rx_card_state_notif;
Zhu Yib481de92007-09-25 17:54:57 -07001537
Ben Cahill9fbab512007-11-29 11:09:47 +08001538 /* Set up hardware specific Rx handlers */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001539 iwl3945_hw_rx_handler_setup(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001540}
1541
1542/**
Tomas Winkler91c066f2008-03-06 17:36:55 -08001543 * iwl3945_cmd_queue_reclaim - Reclaim CMD queue entries
1544 * When FW advances 'R' index, all entries between old and new 'R' index
1545 * need to be reclaimed.
1546 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001547static void iwl3945_cmd_queue_reclaim(struct iwl_priv *priv,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001548 int txq_id, int index)
1549{
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001550 struct iwl_tx_queue *txq = &priv->txq[txq_id];
Samuel Ortizd20b3c62008-12-19 10:37:15 +08001551 struct iwl_queue *q = &txq->q;
Tomas Winkler91c066f2008-03-06 17:36:55 -08001552 int nfreed = 0;
1553
Winkler, Tomas625a3812009-01-08 10:19:55 -08001554 if ((index >= q->n_bd) || (iwl_queue_used(q, index) == 0)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001555 IWL_ERR(priv, "Read index for DMA queue txq id (%d), index %d, "
Tomas Winkler91c066f2008-03-06 17:36:55 -08001556 "is out of range [0-%d] %d %d.\n", txq_id,
1557 index, q->n_bd, q->write_ptr, q->read_ptr);
1558 return;
1559 }
1560
1561 for (index = iwl_queue_inc_wrap(index, q->n_bd); q->read_ptr != index;
1562 q->read_ptr = iwl_queue_inc_wrap(q->read_ptr, q->n_bd)) {
1563 if (nfreed > 1) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08001564 IWL_ERR(priv, "HCMD skipped: index (%d) %d %d\n", index,
Tomas Winkler91c066f2008-03-06 17:36:55 -08001565 q->write_ptr, q->read_ptr);
1566 queue_work(priv->workqueue, &priv->restart);
1567 break;
1568 }
1569 nfreed++;
1570 }
1571}
1572
1573
1574/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001575 * iwl3945_tx_cmd_complete - Pull unused buffers off the queue and reclaim them
Zhu Yib481de92007-09-25 17:54:57 -07001576 * @rxb: Rx buffer to reclaim
1577 *
1578 * If an Rx buffer has an async callback associated with it the callback
1579 * will be executed. The attached skb (if present) will only be freed
1580 * if the callback returns 1
1581 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001582static void iwl3945_tx_cmd_complete(struct iwl_priv *priv,
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001583 struct iwl_rx_mem_buffer *rxb)
Zhu Yib481de92007-09-25 17:54:57 -07001584{
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001585 struct iwl_rx_packet *pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001586 u16 sequence = le16_to_cpu(pkt->hdr.sequence);
1587 int txq_id = SEQ_TO_QUEUE(sequence);
1588 int index = SEQ_TO_INDEX(sequence);
Tomas Winkler600c0e12008-12-19 10:37:04 +08001589 int huge = !!(pkt->hdr.sequence & SEQ_HUGE_FRAME);
Zhu Yib481de92007-09-25 17:54:57 -07001590 int cmd_index;
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08001591 struct iwl_cmd *cmd;
Zhu Yib481de92007-09-25 17:54:57 -07001592
Chatre, Reinette638d0eb2009-01-19 15:30:24 -08001593 if (WARN(txq_id != IWL_CMD_QUEUE_NUM,
1594 "wrong command queue %d, sequence 0x%X readp=%d writep=%d\n",
1595 txq_id, sequence,
1596 priv->txq[IWL_CMD_QUEUE_NUM].q.read_ptr,
1597 priv->txq[IWL_CMD_QUEUE_NUM].q.write_ptr)) {
1598 iwl_print_hex_dump(priv, IWL_DL_INFO , rxb, 32);
1599 return;
1600 }
Zhu Yib481de92007-09-25 17:54:57 -07001601
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08001602 cmd_index = get_cmd_index(&priv->txq[IWL_CMD_QUEUE_NUM].q, index, huge);
1603 cmd = priv->txq[IWL_CMD_QUEUE_NUM].cmd[cmd_index];
Zhu Yib481de92007-09-25 17:54:57 -07001604
1605 /* Input error checking is done when commands are added to queue. */
1606 if (cmd->meta.flags & CMD_WANT_SKB) {
1607 cmd->meta.source->u.skb = rxb->skb;
1608 rxb->skb = NULL;
1609 } else if (cmd->meta.u.callback &&
1610 !cmd->meta.u.callback(priv, cmd, rxb->skb))
1611 rxb->skb = NULL;
1612
Tomas Winkler91c066f2008-03-06 17:36:55 -08001613 iwl3945_cmd_queue_reclaim(priv, txq_id, index);
Zhu Yib481de92007-09-25 17:54:57 -07001614
1615 if (!(cmd->meta.flags & CMD_ASYNC)) {
1616 clear_bit(STATUS_HCMD_ACTIVE, &priv->status);
1617 wake_up_interruptible(&priv->wait_command_queue);
1618 }
1619}
1620
1621/************************** RX-FUNCTIONS ****************************/
1622/*
1623 * Rx theory of operation
1624 *
1625 * The host allocates 32 DMA target addresses and passes the host address
1626 * to the firmware at register IWL_RFDS_TABLE_LOWER + N * RFD_SIZE where N is
1627 * 0 to 31
1628 *
1629 * Rx Queue Indexes
1630 * The host/firmware share two index registers for managing the Rx buffers.
1631 *
1632 * The READ index maps to the first position that the firmware may be writing
1633 * to -- the driver can read up to (but not including) this position and get
1634 * good data.
1635 * The READ index is managed by the firmware once the card is enabled.
1636 *
1637 * The WRITE index maps to the last position the driver has read from -- the
1638 * position preceding WRITE is the last slot the firmware can place a packet.
1639 *
1640 * The queue is empty (no good data) if WRITE = READ - 1, and is full if
1641 * WRITE = READ.
1642 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001643 * During initialization, the host sets up the READ queue position to the first
Zhu Yib481de92007-09-25 17:54:57 -07001644 * INDEX position, and WRITE to the last (READ - 1 wrapped)
1645 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001646 * When the firmware places a packet in a buffer, it will advance the READ index
Zhu Yib481de92007-09-25 17:54:57 -07001647 * and fire the RX interrupt. The driver can then query the READ index and
1648 * process as many packets as possible, moving the WRITE index forward as it
1649 * resets the Rx queue buffers with new memory.
1650 *
1651 * The management in the driver is as follows:
1652 * + A list of pre-allocated SKBs is stored in iwl->rxq->rx_free. When
1653 * iwl->rxq->free_count drops to or below RX_LOW_WATERMARK, work is scheduled
Ian Schram01ebd062007-10-25 17:15:22 +08001654 * to replenish the iwl->rxq->rx_free.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001655 * + In iwl3945_rx_replenish (scheduled) if 'processed' != 'read' then the
Zhu Yib481de92007-09-25 17:54:57 -07001656 * iwl->rxq is replenished and the READ INDEX is updated (updating the
1657 * 'processed' and 'read' driver indexes as well)
1658 * + A received packet is processed and handed to the kernel network stack,
1659 * detached from the iwl->rxq. The driver 'processed' index is updated.
1660 * + The Host/Firmware iwl->rxq is replenished at tasklet time from the rx_free
1661 * list. If there are no allocated buffers in iwl->rxq->rx_free, the READ
1662 * INDEX is not incremented and iwl->status(RX_STALLED) is set. If there
1663 * were enough free buffers and RX_STALLED is set it is cleared.
1664 *
1665 *
1666 * Driver sequence:
1667 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001668 * iwl3945_rx_replenish() Replenishes rx_free list from rx_used, and calls
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001669 * iwl3945_rx_queue_restock
Ben Cahill9fbab512007-11-29 11:09:47 +08001670 * iwl3945_rx_queue_restock() Moves available buffers from rx_free into Rx
Zhu Yib481de92007-09-25 17:54:57 -07001671 * queue, updates firmware pointers, and updates
1672 * the WRITE index. If insufficient rx_free buffers
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001673 * are available, schedules iwl3945_rx_replenish
Zhu Yib481de92007-09-25 17:54:57 -07001674 *
1675 * -- enable interrupts --
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001676 * ISR - iwl3945_rx() Detach iwl_rx_mem_buffers from pool up to the
Zhu Yib481de92007-09-25 17:54:57 -07001677 * READ INDEX, detaching the SKB from the pool.
1678 * Moves the packet buffer from queue to rx_used.
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001679 * Calls iwl3945_rx_queue_restock to refill any empty
Zhu Yib481de92007-09-25 17:54:57 -07001680 * slots.
1681 * ...
1682 *
1683 */
1684
1685/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001686 * iwl3945_dma_addr2rbd_ptr - convert a DMA address to a uCode read buffer ptr
Zhu Yib481de92007-09-25 17:54:57 -07001687 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001688static inline __le32 iwl3945_dma_addr2rbd_ptr(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07001689 dma_addr_t dma_addr)
1690{
1691 return cpu_to_le32((u32)dma_addr);
1692}
1693
1694/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001695 * iwl3945_rx_queue_restock - refill RX queue from pre-allocated pool
Zhu Yib481de92007-09-25 17:54:57 -07001696 *
Ben Cahill9fbab512007-11-29 11:09:47 +08001697 * If there are slots in the RX queue that need to be restocked,
Zhu Yib481de92007-09-25 17:54:57 -07001698 * and we have free pre-allocated buffers, fill the ranks as much
Ben Cahill9fbab512007-11-29 11:09:47 +08001699 * as we can, pulling from rx_free.
Zhu Yib481de92007-09-25 17:54:57 -07001700 *
1701 * This moves the 'write' index forward to catch up with 'processed', and
1702 * also updates the memory address in the firmware to reference the new
1703 * target buffer.
1704 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001705static int iwl3945_rx_queue_restock(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001706{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001707 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001708 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001709 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001710 unsigned long flags;
1711 int write, rc;
1712
1713 spin_lock_irqsave(&rxq->lock, flags);
1714 write = rxq->write & ~0x7;
Winkler, Tomas37d68312009-01-08 10:19:54 -08001715 while ((iwl_rx_queue_space(rxq) > 0) && (rxq->free_count)) {
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001716 /* Get next free Rx buffer, remove from free list */
Zhu Yib481de92007-09-25 17:54:57 -07001717 element = rxq->rx_free.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001718 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Zhu Yib481de92007-09-25 17:54:57 -07001719 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001720
1721 /* Point to Rx buffer via next RBD in circular buffer */
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001722 rxq->bd[rxq->write] = iwl3945_dma_addr2rbd_ptr(priv, rxb->real_dma_addr);
Zhu Yib481de92007-09-25 17:54:57 -07001723 rxq->queue[rxq->write] = rxb;
1724 rxq->write = (rxq->write + 1) & RX_QUEUE_MASK;
1725 rxq->free_count--;
1726 }
1727 spin_unlock_irqrestore(&rxq->lock, flags);
1728 /* If the pre-allocated buffer pool is dropping low, schedule to
1729 * refill it */
1730 if (rxq->free_count <= RX_LOW_WATERMARK)
1731 queue_work(priv->workqueue, &priv->rx_replenish);
1732
1733
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001734 /* If we've added more space for the firmware to place data, tell it.
1735 * Increment device's write pointer in multiples of 8. */
Zhu Yib481de92007-09-25 17:54:57 -07001736 if ((write != (rxq->write & ~0x7))
1737 || (abs(rxq->write - rxq->read) > 7)) {
1738 spin_lock_irqsave(&rxq->lock, flags);
1739 rxq->need_update = 1;
1740 spin_unlock_irqrestore(&rxq->lock, flags);
Winkler, Tomas141c43a2009-01-08 10:19:53 -08001741 rc = iwl_rx_queue_update_write_ptr(priv, rxq);
Zhu Yib481de92007-09-25 17:54:57 -07001742 if (rc)
1743 return rc;
1744 }
1745
1746 return 0;
1747}
1748
1749/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001750 * iwl3945_rx_replenish - Move all used packet from rx_used to rx_free
Zhu Yib481de92007-09-25 17:54:57 -07001751 *
1752 * When moving to rx_free an SKB is allocated for the slot.
1753 *
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001754 * Also restock the Rx queue via iwl3945_rx_queue_restock.
Ian Schram01ebd062007-10-25 17:15:22 +08001755 * This is called as a scheduled work item (except for during initialization)
Zhu Yib481de92007-09-25 17:54:57 -07001756 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001757static void iwl3945_rx_allocate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001758{
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001759 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001760 struct list_head *element;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001761 struct iwl_rx_mem_buffer *rxb;
Zhu Yib481de92007-09-25 17:54:57 -07001762 unsigned long flags;
1763 spin_lock_irqsave(&rxq->lock, flags);
1764 while (!list_empty(&rxq->rx_used)) {
1765 element = rxq->rx_used.next;
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001766 rxb = list_entry(element, struct iwl_rx_mem_buffer, list);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001767
1768 /* Alloc a new receive buffer */
Zhu Yib481de92007-09-25 17:54:57 -07001769 rxb->skb =
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001770 alloc_skb(priv->hw_params.rx_buf_size,
1771 __GFP_NOWARN | GFP_ATOMIC);
Zhu Yib481de92007-09-25 17:54:57 -07001772 if (!rxb->skb) {
1773 if (net_ratelimit())
Tomas Winkler978785a2008-12-19 10:37:31 +08001774 IWL_CRIT(priv, ": Can not allocate SKB buffers\n");
Zhu Yib481de92007-09-25 17:54:57 -07001775 /* We don't reschedule replenish work here -- we will
1776 * call the restock method and if it still needs
1777 * more buffers it will schedule replenish */
1778 break;
1779 }
Zhu Yi12342c42007-12-20 11:27:32 +08001780
1781 /* If radiotap head is required, reserve some headroom here.
1782 * The physical head count is a variable rx_stats->phy_count.
1783 * We reserve 4 bytes here. Plus these extra bytes, the
1784 * headroom of the physical head should be enough for the
1785 * radiotap head that iwl3945 supported. See iwl3945_rt.
1786 */
1787 skb_reserve(rxb->skb, 4);
1788
Zhu Yib481de92007-09-25 17:54:57 -07001789 priv->alloc_rxb_skb++;
1790 list_del(element);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001791
1792 /* Get physical address of RB/SKB */
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001793 rxb->real_dma_addr = pci_map_single(priv->pci_dev,
1794 rxb->skb->data,
1795 priv->hw_params.rx_buf_size,
1796 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001797 list_add_tail(&rxb->list, &rxq->rx_free);
1798 rxq->free_count++;
1799 }
1800 spin_unlock_irqrestore(&rxq->lock, flags);
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001801}
1802
1803/*
1804 * this should be called while priv->lock is locked
1805 */
Tomas Winkler4fd1f842007-12-05 20:59:58 +02001806static void __iwl3945_rx_replenish(void *data)
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001807{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001808 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001809
1810 iwl3945_rx_allocate(priv);
1811 iwl3945_rx_queue_restock(priv);
1812}
1813
1814
1815void iwl3945_rx_replenish(void *data)
1816{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001817 struct iwl_priv *priv = data;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001818 unsigned long flags;
1819
1820 iwl3945_rx_allocate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001821
1822 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001823 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07001824 spin_unlock_irqrestore(&priv->lock, flags);
1825}
1826
Zhu Yib481de92007-09-25 17:54:57 -07001827/* Convert linear signal-to-noise ratio into dB */
1828static u8 ratio2dB[100] = {
1829/* 0 1 2 3 4 5 6 7 8 9 */
1830 0, 0, 6, 10, 12, 14, 16, 17, 18, 19, /* 00 - 09 */
1831 20, 21, 22, 22, 23, 23, 24, 25, 26, 26, /* 10 - 19 */
1832 26, 26, 26, 27, 27, 28, 28, 28, 29, 29, /* 20 - 29 */
1833 29, 30, 30, 30, 31, 31, 31, 31, 32, 32, /* 30 - 39 */
1834 32, 32, 32, 33, 33, 33, 33, 33, 34, 34, /* 40 - 49 */
1835 34, 34, 34, 34, 35, 35, 35, 35, 35, 35, /* 50 - 59 */
1836 36, 36, 36, 36, 36, 36, 36, 37, 37, 37, /* 60 - 69 */
1837 37, 37, 37, 37, 37, 38, 38, 38, 38, 38, /* 70 - 79 */
1838 38, 38, 38, 38, 38, 39, 39, 39, 39, 39, /* 80 - 89 */
1839 39, 39, 39, 39, 39, 40, 40, 40, 40, 40 /* 90 - 99 */
1840};
1841
1842/* Calculates a relative dB value from a ratio of linear
1843 * (i.e. not dB) signal levels.
1844 * Conversion assumes that levels are voltages (20*log), not powers (10*log). */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001845int iwl3945_calc_db_from_ratio(int sig_ratio)
Zhu Yib481de92007-09-25 17:54:57 -07001846{
Adrian Bunk221c80c2008-02-02 23:19:01 +02001847 /* 1000:1 or higher just report as 60 dB */
1848 if (sig_ratio >= 1000)
Zhu Yib481de92007-09-25 17:54:57 -07001849 return 60;
1850
Adrian Bunk221c80c2008-02-02 23:19:01 +02001851 /* 100:1 or higher, divide by 10 and use table,
Zhu Yib481de92007-09-25 17:54:57 -07001852 * add 20 dB to make up for divide by 10 */
Adrian Bunk221c80c2008-02-02 23:19:01 +02001853 if (sig_ratio >= 100)
Tomas Winkler3ac7f142008-07-21 02:40:14 +03001854 return 20 + (int)ratio2dB[sig_ratio/10];
Zhu Yib481de92007-09-25 17:54:57 -07001855
1856 /* We shouldn't see this */
1857 if (sig_ratio < 1)
1858 return 0;
1859
1860 /* Use table for ratios 1:1 - 99:1 */
1861 return (int)ratio2dB[sig_ratio];
1862}
1863
1864#define PERFECT_RSSI (-20) /* dBm */
1865#define WORST_RSSI (-95) /* dBm */
1866#define RSSI_RANGE (PERFECT_RSSI - WORST_RSSI)
1867
1868/* Calculate an indication of rx signal quality (a percentage, not dBm!).
1869 * See http://www.ces.clemson.edu/linux/signal_quality.shtml for info
1870 * about formulas used below. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001871int iwl3945_calc_sig_qual(int rssi_dbm, int noise_dbm)
Zhu Yib481de92007-09-25 17:54:57 -07001872{
1873 int sig_qual;
1874 int degradation = PERFECT_RSSI - rssi_dbm;
1875
1876 /* If we get a noise measurement, use signal-to-noise ratio (SNR)
1877 * as indicator; formula is (signal dbm - noise dbm).
1878 * SNR at or above 40 is a great signal (100%).
1879 * Below that, scale to fit SNR of 0 - 40 dB within 0 - 100% indicator.
1880 * Weakest usable signal is usually 10 - 15 dB SNR. */
1881 if (noise_dbm) {
1882 if (rssi_dbm - noise_dbm >= 40)
1883 return 100;
1884 else if (rssi_dbm < noise_dbm)
1885 return 0;
1886 sig_qual = ((rssi_dbm - noise_dbm) * 5) / 2;
1887
1888 /* Else use just the signal level.
1889 * This formula is a least squares fit of data points collected and
1890 * compared with a reference system that had a percentage (%) display
1891 * for signal quality. */
1892 } else
1893 sig_qual = (100 * (RSSI_RANGE * RSSI_RANGE) - degradation *
1894 (15 * RSSI_RANGE + 62 * degradation)) /
1895 (RSSI_RANGE * RSSI_RANGE);
1896
1897 if (sig_qual > 100)
1898 sig_qual = 100;
1899 else if (sig_qual < 1)
1900 sig_qual = 0;
1901
1902 return sig_qual;
1903}
1904
1905/**
Ben Cahill9fbab512007-11-29 11:09:47 +08001906 * iwl3945_rx_handle - Main entry function for receiving responses from uCode
Zhu Yib481de92007-09-25 17:54:57 -07001907 *
1908 * Uses the priv->rx_handlers callback function array to invoke
1909 * the appropriate handlers, including command responses,
1910 * frame-received notifications, and other notifications.
1911 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08001912static void iwl3945_rx_handle(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07001913{
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001914 struct iwl_rx_mem_buffer *rxb;
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001915 struct iwl_rx_packet *pkt;
Abhijeet Kolekarcc2f3622008-12-19 10:37:25 +08001916 struct iwl_rx_queue *rxq = &priv->rxq;
Zhu Yib481de92007-09-25 17:54:57 -07001917 u32 r, i;
1918 int reclaim;
1919 unsigned long flags;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001920 u8 fill_rx = 0;
Mohamed Abbasd68ab682008-02-07 13:16:33 -08001921 u32 count = 8;
Zhu Yib481de92007-09-25 17:54:57 -07001922
Cahill, Ben M6440adb2007-11-29 11:09:55 +08001923 /* uCode's read index (stored in shared DRAM) indicates the last Rx
1924 * buffer that the driver may process (last buffer filled by ucode). */
Winkler, Tomas8cd812b2008-12-19 10:37:43 +08001925 r = le16_to_cpu(rxq->rb_stts->closed_rb_num) & 0x0FFF;
Zhu Yib481de92007-09-25 17:54:57 -07001926 i = rxq->read;
1927
Winkler, Tomas37d68312009-01-08 10:19:54 -08001928 if (iwl_rx_queue_space(rxq) > (RX_QUEUE_SIZE / 2))
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08001929 fill_rx = 1;
Zhu Yib481de92007-09-25 17:54:57 -07001930 /* Rx interrupt, but nothing sent from uCode */
1931 if (i == r)
Tomas Winklere1623442009-01-27 14:27:56 -08001932 IWL_DEBUG(priv, IWL_DL_RX | IWL_DL_ISR, "r = %d, i = %d\n", r, i);
Zhu Yib481de92007-09-25 17:54:57 -07001933
1934 while (i != r) {
1935 rxb = rxq->queue[i];
1936
Ben Cahill9fbab512007-11-29 11:09:47 +08001937 /* If an RXB doesn't have a Rx queue slot associated with it,
Zhu Yib481de92007-09-25 17:54:57 -07001938 * then a bug has been introduced in the queue refilling
1939 * routines -- catch it here */
1940 BUG_ON(rxb == NULL);
1941
1942 rxq->queue[i] = NULL;
1943
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001944 pci_dma_sync_single_for_cpu(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001945 priv->hw_params.rx_buf_size,
Zhu Yib481de92007-09-25 17:54:57 -07001946 PCI_DMA_FROMDEVICE);
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08001947 pkt = (struct iwl_rx_packet *)rxb->skb->data;
Zhu Yib481de92007-09-25 17:54:57 -07001948
1949 /* Reclaim a command buffer only if this packet is a response
1950 * to a (driver-originated) command.
1951 * If the packet (e.g. Rx frame) originated from uCode,
1952 * there is no command buffer to reclaim.
1953 * Ucode should set SEQ_RX_FRAME bit if ucode-originated,
1954 * but apparently a few don't get set; catch them here. */
1955 reclaim = !(pkt->hdr.sequence & SEQ_RX_FRAME) &&
1956 (pkt->hdr.cmd != STATISTICS_NOTIFICATION) &&
1957 (pkt->hdr.cmd != REPLY_TX);
1958
1959 /* Based on type of command response or notification,
1960 * handle those that need handling via function in
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001961 * rx_handlers table. See iwl3945_setup_rx_handlers() */
Zhu Yib481de92007-09-25 17:54:57 -07001962 if (priv->rx_handlers[pkt->hdr.cmd]) {
Tomas Winklere1623442009-01-27 14:27:56 -08001963 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001964 "r = %d, i = %d, %s, 0x%02x\n", r, i,
1965 get_cmd_string(pkt->hdr.cmd), pkt->hdr.cmd);
1966 priv->rx_handlers[pkt->hdr.cmd] (priv, rxb);
1967 } else {
1968 /* No handling needed */
Tomas Winklere1623442009-01-27 14:27:56 -08001969 IWL_DEBUG(priv, IWL_DL_HCMD | IWL_DL_RX | IWL_DL_ISR,
Zhu Yib481de92007-09-25 17:54:57 -07001970 "r %d i %d No handler needed for %s, 0x%02x\n",
1971 r, i, get_cmd_string(pkt->hdr.cmd),
1972 pkt->hdr.cmd);
1973 }
1974
1975 if (reclaim) {
Ben Cahill9fbab512007-11-29 11:09:47 +08001976 /* Invoke any callbacks, transfer the skb to caller, and
Samuel Ortiz518099a2009-01-19 15:30:27 -08001977 * fire off the (possibly) blocking iwl_send_cmd()
Zhu Yib481de92007-09-25 17:54:57 -07001978 * as we reclaim the driver command queue */
1979 if (rxb && rxb->skb)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08001980 iwl3945_tx_cmd_complete(priv, rxb);
Zhu Yib481de92007-09-25 17:54:57 -07001981 else
Winkler, Tomas39aadf82008-12-19 10:37:32 +08001982 IWL_WARN(priv, "Claim null rxb?\n");
Zhu Yib481de92007-09-25 17:54:57 -07001983 }
1984
1985 /* For now we just don't re-use anything. We can tweak this
1986 * later to try and re-use notification packets and SKBs that
1987 * fail to Rx correctly */
1988 if (rxb->skb != NULL) {
1989 priv->alloc_rxb_skb--;
1990 dev_kfree_skb_any(rxb->skb);
1991 rxb->skb = NULL;
1992 }
1993
Abhijeet Kolekar6100b582008-12-19 10:37:24 +08001994 pci_unmap_single(priv->pci_dev, rxb->real_dma_addr,
Winkler, Tomas1e33dc62009-01-08 10:19:57 -08001995 priv->hw_params.rx_buf_size,
1996 PCI_DMA_FROMDEVICE);
Zhu Yib481de92007-09-25 17:54:57 -07001997 spin_lock_irqsave(&rxq->lock, flags);
1998 list_add_tail(&rxb->list, &priv->rxq.rx_used);
1999 spin_unlock_irqrestore(&rxq->lock, flags);
2000 i = (i + 1) & RX_QUEUE_MASK;
Mohamed Abbas5c0eef92007-11-29 11:10:14 +08002001 /* If there are a lot of unused frames,
2002 * restock the Rx queue so ucode won't assert. */
2003 if (fill_rx) {
2004 count++;
2005 if (count >= 8) {
2006 priv->rxq.read = i;
2007 __iwl3945_rx_replenish(priv);
2008 count = 0;
2009 }
2010 }
Zhu Yib481de92007-09-25 17:54:57 -07002011 }
2012
2013 /* Backtrack one entry */
2014 priv->rxq.read = i;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002015 iwl3945_rx_queue_restock(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002016}
2017
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002018static void iwl3945_enable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002019{
Tomas Winklere1623442009-01-27 14:27:56 -08002020 IWL_DEBUG_ISR(priv, "Enabling interrupts\n");
Zhu Yib481de92007-09-25 17:54:57 -07002021 set_bit(STATUS_INT_ENABLED, &priv->status);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002022 iwl_write32(priv, CSR_INT_MASK, CSR_INI_SET_MASK);
Zhu Yib481de92007-09-25 17:54:57 -07002023}
2024
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002025
2026/* call this function to flush any scheduled tasklet */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002027static inline void iwl_synchronize_irq(struct iwl_priv *priv)
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002028{
Tomas Winklera96a27f2008-10-23 23:48:56 -07002029 /* wait to make sure we flush pending tasklet*/
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002030 synchronize_irq(priv->pci_dev->irq);
2031 tasklet_kill(&priv->irq_tasklet);
2032}
2033
2034
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002035static inline void iwl3945_disable_interrupts(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002036{
2037 clear_bit(STATUS_INT_ENABLED, &priv->status);
2038
2039 /* disable interrupts from uCode/NIC to host */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002040 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002041
2042 /* acknowledge/clear/reset any interrupts still pending
2043 * from uCode or flow handler (Rx/Tx DMA) */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002044 iwl_write32(priv, CSR_INT, 0xffffffff);
2045 iwl_write32(priv, CSR_FH_INT_STATUS, 0xffffffff);
Tomas Winklere1623442009-01-27 14:27:56 -08002046 IWL_DEBUG_ISR(priv, "Disabled interrupts\n");
Zhu Yib481de92007-09-25 17:54:57 -07002047}
2048
2049static const char *desc_lookup(int i)
2050{
2051 switch (i) {
2052 case 1:
2053 return "FAIL";
2054 case 2:
2055 return "BAD_PARAM";
2056 case 3:
2057 return "BAD_CHECKSUM";
2058 case 4:
2059 return "NMI_INTERRUPT";
2060 case 5:
2061 return "SYSASSERT";
2062 case 6:
2063 return "FATAL_ERROR";
2064 }
2065
2066 return "UNKNOWN";
2067}
2068
2069#define ERROR_START_OFFSET (1 * sizeof(u32))
2070#define ERROR_ELEM_SIZE (7 * sizeof(u32))
2071
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002072static void iwl3945_dump_nic_error_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002073{
2074 u32 i;
2075 u32 desc, time, count, base, data1;
2076 u32 blink1, blink2, ilink1, ilink2;
2077 int rc;
2078
2079 base = le32_to_cpu(priv->card_alive.error_event_table_ptr);
2080
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002081 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002082 IWL_ERR(priv, "Not valid error log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002083 return;
2084 }
2085
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002086 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002087 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002088 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002089 return;
2090 }
2091
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002092 count = iwl_read_targ_mem(priv, base);
Zhu Yib481de92007-09-25 17:54:57 -07002093
2094 if (ERROR_START_OFFSET <= count * ERROR_ELEM_SIZE) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002095 IWL_ERR(priv, "Start IWL Error Log Dump:\n");
2096 IWL_ERR(priv, "Status: 0x%08lX, count: %d\n",
2097 priv->status, count);
Zhu Yib481de92007-09-25 17:54:57 -07002098 }
2099
Winkler, Tomas15b16872008-12-19 10:37:33 +08002100 IWL_ERR(priv, "Desc Time asrtPC blink2 "
Zhu Yib481de92007-09-25 17:54:57 -07002101 "ilink1 nmiPC Line\n");
2102 for (i = ERROR_START_OFFSET;
2103 i < (count * ERROR_ELEM_SIZE) + ERROR_START_OFFSET;
2104 i += ERROR_ELEM_SIZE) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002105 desc = iwl_read_targ_mem(priv, base + i);
Zhu Yib481de92007-09-25 17:54:57 -07002106 time =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002107 iwl_read_targ_mem(priv, base + i + 1 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002108 blink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002109 iwl_read_targ_mem(priv, base + i + 2 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002110 blink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002111 iwl_read_targ_mem(priv, base + i + 3 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002112 ilink1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002113 iwl_read_targ_mem(priv, base + i + 4 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002114 ilink2 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002115 iwl_read_targ_mem(priv, base + i + 5 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002116 data1 =
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002117 iwl_read_targ_mem(priv, base + i + 6 * sizeof(u32));
Zhu Yib481de92007-09-25 17:54:57 -07002118
Winkler, Tomas15b16872008-12-19 10:37:33 +08002119 IWL_ERR(priv,
2120 "%-13s (#%d) %010u 0x%05X 0x%05X 0x%05X 0x%05X %u\n\n",
2121 desc_lookup(desc), desc, time, blink1, blink2,
2122 ilink1, ilink2, data1);
Zhu Yib481de92007-09-25 17:54:57 -07002123 }
2124
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002125 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002126
2127}
2128
Ben Cahillf58177b2007-11-29 11:09:43 +08002129#define EVENT_START_OFFSET (6 * sizeof(u32))
Zhu Yib481de92007-09-25 17:54:57 -07002130
2131/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002132 * iwl3945_print_event_log - Dump error event log to syslog
Zhu Yib481de92007-09-25 17:54:57 -07002133 *
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002134 * NOTE: Must be called with iwl_grab_nic_access() already obtained!
Zhu Yib481de92007-09-25 17:54:57 -07002135 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002136static void iwl3945_print_event_log(struct iwl_priv *priv, u32 start_idx,
Zhu Yib481de92007-09-25 17:54:57 -07002137 u32 num_events, u32 mode)
2138{
2139 u32 i;
2140 u32 base; /* SRAM byte address of event log header */
2141 u32 event_size; /* 2 u32s, or 3 u32s if timestamp recorded */
2142 u32 ptr; /* SRAM byte address of log data */
2143 u32 ev, time, data; /* event log data */
2144
2145 if (num_events == 0)
2146 return;
2147
2148 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
2149
2150 if (mode == 0)
2151 event_size = 2 * sizeof(u32);
2152 else
2153 event_size = 3 * sizeof(u32);
2154
2155 ptr = base + EVENT_START_OFFSET + (start_idx * event_size);
2156
2157 /* "time" is actually "data" for mode 0 (no timestamp).
2158 * place event id # at far right for easier visual parsing. */
2159 for (i = 0; i < num_events; i++) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002160 ev = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002161 ptr += sizeof(u32);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002162 time = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002163 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002164 if (mode == 0) {
2165 /* data, ev */
2166 IWL_ERR(priv, "0x%08x\t%04u\n", time, ev);
2167 } else {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002168 data = iwl_read_targ_mem(priv, ptr);
Zhu Yib481de92007-09-25 17:54:57 -07002169 ptr += sizeof(u32);
Winkler, Tomas15b16872008-12-19 10:37:33 +08002170 IWL_ERR(priv, "%010u\t0x%08x\t%04u\n", time, data, ev);
Zhu Yib481de92007-09-25 17:54:57 -07002171 }
2172 }
2173}
2174
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002175static void iwl3945_dump_nic_event_log(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002176{
2177 int rc;
2178 u32 base; /* SRAM byte address of event log header */
2179 u32 capacity; /* event log capacity in # entries */
2180 u32 mode; /* 0 - no timestamp, 1 - timestamp recorded */
2181 u32 num_wraps; /* # times uCode wrapped to top of log */
2182 u32 next_entry; /* index of next entry to be written by uCode */
2183 u32 size; /* # entries that we'll print */
2184
2185 base = le32_to_cpu(priv->card_alive.log_event_table_ptr);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002186 if (!iwl3945_hw_valid_rtc_data_addr(base)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002187 IWL_ERR(priv, "Invalid event log pointer 0x%08X\n", base);
Zhu Yib481de92007-09-25 17:54:57 -07002188 return;
2189 }
2190
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002191 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002192 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002193 IWL_WARN(priv, "Can not read from adapter at this time.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002194 return;
2195 }
2196
2197 /* event log header */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002198 capacity = iwl_read_targ_mem(priv, base);
2199 mode = iwl_read_targ_mem(priv, base + (1 * sizeof(u32)));
2200 num_wraps = iwl_read_targ_mem(priv, base + (2 * sizeof(u32)));
2201 next_entry = iwl_read_targ_mem(priv, base + (3 * sizeof(u32)));
Zhu Yib481de92007-09-25 17:54:57 -07002202
2203 size = num_wraps ? capacity : next_entry;
2204
2205 /* bail out if nothing in log */
2206 if (size == 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002207 IWL_ERR(priv, "Start IWL Event Log Dump: nothing in log\n");
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002208 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002209 return;
2210 }
2211
Winkler, Tomas15b16872008-12-19 10:37:33 +08002212 IWL_ERR(priv, "Start IWL Event Log Dump: display count %d, wraps %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07002213 size, num_wraps);
2214
2215 /* if uCode has wrapped back to top of log, start at the oldest entry,
2216 * i.e the next one that uCode would fill. */
2217 if (num_wraps)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002218 iwl3945_print_event_log(priv, next_entry,
Zhu Yib481de92007-09-25 17:54:57 -07002219 capacity - next_entry, mode);
2220
2221 /* (then/else) start at top of log */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002222 iwl3945_print_event_log(priv, 0, next_entry, mode);
Zhu Yib481de92007-09-25 17:54:57 -07002223
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002224 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002225}
2226
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002227static void iwl3945_error_recovery(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002228{
2229 unsigned long flags;
2230
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002231 memcpy(&priv->staging_rxon, &priv->recovery_rxon,
2232 sizeof(priv->staging_rxon));
2233 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002234 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002235
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002236 iwl3945_add_station(priv, priv->bssid, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002237
2238 spin_lock_irqsave(&priv->lock, flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002239 priv->assoc_id = le16_to_cpu(priv->staging_rxon.assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07002240 priv->error_recovering = 0;
2241 spin_unlock_irqrestore(&priv->lock, flags);
2242}
2243
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002244static void iwl3945_irq_tasklet(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002245{
2246 u32 inta, handled = 0;
2247 u32 inta_fh;
2248 unsigned long flags;
Samuel Ortizd08853a2009-01-23 13:45:17 -08002249#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07002250 u32 inta_mask;
2251#endif
2252
2253 spin_lock_irqsave(&priv->lock, flags);
2254
2255 /* Ack/clear/reset pending uCode interrupts.
2256 * Note: Some bits in CSR_INT are "OR" of bits in CSR_FH_INT_STATUS,
2257 * and will clear only when CSR_FH_INT_STATUS gets cleared. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002258 inta = iwl_read32(priv, CSR_INT);
2259 iwl_write32(priv, CSR_INT, inta);
Zhu Yib481de92007-09-25 17:54:57 -07002260
2261 /* Ack/clear/reset pending flow-handler (DMA) interrupts.
2262 * Any new interrupts that happen after this, either while we're
2263 * in this tasklet, or later, will show up in next ISR/tasklet. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002264 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
2265 iwl_write32(priv, CSR_FH_INT_STATUS, inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002266
Samuel Ortizd08853a2009-01-23 13:45:17 -08002267#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002268 if (priv->debug_level & IWL_DL_ISR) {
Ben Cahill9fbab512007-11-29 11:09:47 +08002269 /* just for debug */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002270 inta_mask = iwl_read32(priv, CSR_INT_MASK);
Tomas Winklere1623442009-01-27 14:27:56 -08002271 IWL_DEBUG_ISR(priv, "inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002272 inta, inta_mask, inta_fh);
2273 }
2274#endif
2275
2276 /* Since CSR_INT and CSR_FH_INT_STATUS reads and clears are not
2277 * atomic, make sure that inta covers all the interrupts that
2278 * we've discovered, even if FH interrupt came in just after
2279 * reading CSR_INT. */
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002280 if (inta_fh & CSR39_FH_INT_RX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002281 inta |= CSR_INT_BIT_FH_RX;
Tomas Winkler6f83eaa2008-03-04 18:09:28 -08002282 if (inta_fh & CSR39_FH_INT_TX_MASK)
Zhu Yib481de92007-09-25 17:54:57 -07002283 inta |= CSR_INT_BIT_FH_TX;
2284
2285 /* Now service all interrupt bits discovered above. */
2286 if (inta & CSR_INT_BIT_HW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002287 IWL_ERR(priv, "Microcode HW error detected. Restarting.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002288
2289 /* Tell the device to stop sending interrupts */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002290 iwl3945_disable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002291
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002292 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002293
2294 handled |= CSR_INT_BIT_HW_ERR;
2295
2296 spin_unlock_irqrestore(&priv->lock, flags);
2297
2298 return;
2299 }
2300
Samuel Ortizd08853a2009-01-23 13:45:17 -08002301#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002302 if (priv->debug_level & (IWL_DL_ISR)) {
Zhu Yib481de92007-09-25 17:54:57 -07002303 /* NIC fires this, but we don't use it, redundant with WAKEUP */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002304 if (inta & CSR_INT_BIT_SCD)
Tomas Winklere1623442009-01-27 14:27:56 -08002305 IWL_DEBUG_ISR(priv, "Scheduler finished to transmit "
Joonwoo Park25c03d82008-01-23 10:15:20 -08002306 "the frame/frames.\n");
Zhu Yib481de92007-09-25 17:54:57 -07002307
2308 /* Alive notification via Rx interrupt will do the real work */
2309 if (inta & CSR_INT_BIT_ALIVE)
Tomas Winklere1623442009-01-27 14:27:56 -08002310 IWL_DEBUG_ISR(priv, "Alive interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002311 }
2312#endif
2313 /* Safely ignore these bits for debug checks below */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002314 inta &= ~(CSR_INT_BIT_SCD | CSR_INT_BIT_ALIVE);
Zhu Yib481de92007-09-25 17:54:57 -07002315
Zhu Yib481de92007-09-25 17:54:57 -07002316 /* Error detected by uCode */
2317 if (inta & CSR_INT_BIT_SW_ERR) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002318 IWL_ERR(priv, "Microcode SW error detected. "
2319 "Restarting 0x%X.\n", inta);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08002320 iwl_irq_handle_error(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002321 handled |= CSR_INT_BIT_SW_ERR;
2322 }
2323
2324 /* uCode wakes up after power-down sleep */
2325 if (inta & CSR_INT_BIT_WAKEUP) {
Tomas Winklere1623442009-01-27 14:27:56 -08002326 IWL_DEBUG_ISR(priv, "Wakeup interrupt\n");
Winkler, Tomas141c43a2009-01-08 10:19:53 -08002327 iwl_rx_queue_update_write_ptr(priv, &priv->rxq);
Samuel Ortiz4f3602c2009-01-19 15:30:25 -08002328 iwl_txq_update_write_ptr(priv, &priv->txq[0]);
2329 iwl_txq_update_write_ptr(priv, &priv->txq[1]);
2330 iwl_txq_update_write_ptr(priv, &priv->txq[2]);
2331 iwl_txq_update_write_ptr(priv, &priv->txq[3]);
2332 iwl_txq_update_write_ptr(priv, &priv->txq[4]);
2333 iwl_txq_update_write_ptr(priv, &priv->txq[5]);
Zhu Yib481de92007-09-25 17:54:57 -07002334
2335 handled |= CSR_INT_BIT_WAKEUP;
2336 }
2337
2338 /* All uCode command responses, including Tx command responses,
2339 * Rx "responses" (frame-received notification), and other
2340 * notifications from uCode come through here*/
2341 if (inta & (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002342 iwl3945_rx_handle(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002343 handled |= (CSR_INT_BIT_FH_RX | CSR_INT_BIT_SW_RX);
2344 }
2345
2346 if (inta & CSR_INT_BIT_FH_TX) {
Tomas Winklere1623442009-01-27 14:27:56 -08002347 IWL_DEBUG_ISR(priv, "Tx interrupt\n");
Zhu Yib481de92007-09-25 17:54:57 -07002348
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002349 iwl_write32(priv, CSR_FH_INT_STATUS, (1 << 6));
2350 if (!iwl_grab_nic_access(priv)) {
2351 iwl_write_direct32(priv, FH39_TCSR_CREDIT
Tomas Winklerbddadf82008-12-19 10:37:01 +08002352 (FH39_SRVC_CHNL), 0x0);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002353 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002354 }
2355 handled |= CSR_INT_BIT_FH_TX;
2356 }
2357
2358 if (inta & ~handled)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002359 IWL_ERR(priv, "Unhandled INTA bits 0x%08x\n", inta & ~handled);
Zhu Yib481de92007-09-25 17:54:57 -07002360
2361 if (inta & ~CSR_INI_SET_MASK) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002362 IWL_WARN(priv, "Disabled INTA bits 0x%08x were pending\n",
Zhu Yib481de92007-09-25 17:54:57 -07002363 inta & ~CSR_INI_SET_MASK);
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002364 IWL_WARN(priv, " with FH_INT = 0x%08x\n", inta_fh);
Zhu Yib481de92007-09-25 17:54:57 -07002365 }
2366
2367 /* Re-enable all interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002368 /* only Re-enable if disabled by irq */
2369 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2370 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002371
Samuel Ortizd08853a2009-01-23 13:45:17 -08002372#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08002373 if (priv->debug_level & (IWL_DL_ISR)) {
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002374 inta = iwl_read32(priv, CSR_INT);
2375 inta_mask = iwl_read32(priv, CSR_INT_MASK);
2376 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Tomas Winklere1623442009-01-27 14:27:56 -08002377 IWL_DEBUG_ISR(priv, "End inta 0x%08x, enabled 0x%08x, fh 0x%08x, "
Zhu Yib481de92007-09-25 17:54:57 -07002378 "flags 0x%08lx\n", inta, inta_mask, inta_fh, flags);
2379 }
2380#endif
2381 spin_unlock_irqrestore(&priv->lock, flags);
2382}
2383
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002384static irqreturn_t iwl3945_isr(int irq, void *data)
Zhu Yib481de92007-09-25 17:54:57 -07002385{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002386 struct iwl_priv *priv = data;
Zhu Yib481de92007-09-25 17:54:57 -07002387 u32 inta, inta_mask;
2388 u32 inta_fh;
2389 if (!priv)
2390 return IRQ_NONE;
2391
2392 spin_lock(&priv->lock);
2393
2394 /* Disable (but don't clear!) interrupts here to avoid
2395 * back-to-back ISRs and sporadic interrupts from our NIC.
2396 * If we have something to service, the tasklet will re-enable ints.
2397 * If we *don't* have something, we'll re-enable before leaving here. */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002398 inta_mask = iwl_read32(priv, CSR_INT_MASK); /* just for debug */
2399 iwl_write32(priv, CSR_INT_MASK, 0x00000000);
Zhu Yib481de92007-09-25 17:54:57 -07002400
2401 /* Discover which interrupts are active/pending */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002402 inta = iwl_read32(priv, CSR_INT);
2403 inta_fh = iwl_read32(priv, CSR_FH_INT_STATUS);
Zhu Yib481de92007-09-25 17:54:57 -07002404
2405 /* Ignore interrupt if there's nothing in NIC to service.
2406 * This may be due to IRQ shared with another device,
2407 * or due to sporadic interrupts thrown from our NIC. */
2408 if (!inta && !inta_fh) {
Tomas Winklere1623442009-01-27 14:27:56 -08002409 IWL_DEBUG_ISR(priv, "Ignore interrupt, inta == 0, inta_fh == 0\n");
Zhu Yib481de92007-09-25 17:54:57 -07002410 goto none;
2411 }
2412
2413 if ((inta == 0xFFFFFFFF) || ((inta & 0xFFFFFFF0) == 0xa5a5a5a0)) {
2414 /* Hardware disappeared */
Winkler, Tomas39aadf82008-12-19 10:37:32 +08002415 IWL_WARN(priv, "HARDWARE GONE?? INTA == 0x%08x\n", inta);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002416 goto unplugged;
Zhu Yib481de92007-09-25 17:54:57 -07002417 }
2418
Tomas Winklere1623442009-01-27 14:27:56 -08002419 IWL_DEBUG_ISR(priv, "ISR inta 0x%08x, enabled 0x%08x, fh 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002420 inta, inta_mask, inta_fh);
2421
Joonwoo Park25c03d82008-01-23 10:15:20 -08002422 inta &= ~CSR_INT_BIT_SCD;
2423
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002424 /* iwl3945_irq_tasklet() will service interrupts and re-enable them */
Joonwoo Park25c03d82008-01-23 10:15:20 -08002425 if (likely(inta || inta_fh))
2426 tasklet_schedule(&priv->irq_tasklet);
Oliver Neukumcb4da1a2007-11-13 21:10:32 -08002427unplugged:
Zhu Yib481de92007-09-25 17:54:57 -07002428 spin_unlock(&priv->lock);
2429
2430 return IRQ_HANDLED;
2431
2432 none:
2433 /* re-enable interrupts here since we don't have anything to service. */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07002434 /* only Re-enable if disabled by irq */
2435 if (test_bit(STATUS_INT_ENABLED, &priv->status))
2436 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002437 spin_unlock(&priv->lock);
2438 return IRQ_NONE;
2439}
2440
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002441static int iwl3945_get_channels_for_scan(struct iwl_priv *priv,
Johannes Berg8318d782008-01-24 19:38:38 +01002442 enum ieee80211_band band,
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08002443 u8 is_active, u8 n_probes,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002444 struct iwl3945_scan_channel *scan_ch)
Zhu Yib481de92007-09-25 17:54:57 -07002445{
2446 const struct ieee80211_channel *channels = NULL;
Johannes Berg8318d782008-01-24 19:38:38 +01002447 const struct ieee80211_supported_band *sband;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08002448 const struct iwl_channel_info *ch_info;
Zhu Yib481de92007-09-25 17:54:57 -07002449 u16 passive_dwell = 0;
2450 u16 active_dwell = 0;
2451 int added, i;
2452
Kolekar, Abhijeetcbba18c2008-12-19 10:37:42 +08002453 sband = iwl_get_hw_mode(priv, band);
Johannes Berg8318d782008-01-24 19:38:38 +01002454 if (!sband)
Zhu Yib481de92007-09-25 17:54:57 -07002455 return 0;
2456
Johannes Berg8318d782008-01-24 19:38:38 +01002457 channels = sband->channels;
Zhu Yib481de92007-09-25 17:54:57 -07002458
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08002459 active_dwell = iwl_get_active_dwell_time(priv, band, n_probes);
2460 passive_dwell = iwl_get_passive_dwell_time(priv, band);
Zhu Yib481de92007-09-25 17:54:57 -07002461
Abhijeet Kolekar8f4807a2008-09-03 11:26:31 +08002462 if (passive_dwell <= active_dwell)
2463 passive_dwell = active_dwell + 1;
2464
Johannes Berg8318d782008-01-24 19:38:38 +01002465 for (i = 0, added = 0; i < sband->n_channels; i++) {
Johannes Berg182e2e62008-04-04 10:41:56 +02002466 if (channels[i].flags & IEEE80211_CHAN_DISABLED)
2467 continue;
2468
Johannes Berg8318d782008-01-24 19:38:38 +01002469 scan_ch->channel = channels[i].hw_value;
Zhu Yib481de92007-09-25 17:54:57 -07002470
Samuel Ortize6148912009-01-23 13:45:15 -08002471 ch_info = iwl_get_channel_info(priv, band, scan_ch->channel);
Zhu Yib481de92007-09-25 17:54:57 -07002472 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08002473 IWL_DEBUG_SCAN(priv, "Channel %d is INVALID for this band.\n",
Zhu Yib481de92007-09-25 17:54:57 -07002474 scan_ch->channel);
2475 continue;
2476 }
2477
Zhu Yib481de92007-09-25 17:54:57 -07002478 scan_ch->active_dwell = cpu_to_le16(active_dwell);
2479 scan_ch->passive_dwell = cpu_to_le16(passive_dwell);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002480 /* If passive , set up for auto-switch
2481 * and use long active_dwell time.
2482 */
2483 if (!is_active || is_channel_passive(ch_info) ||
2484 (channels[i].flags & IEEE80211_CHAN_PASSIVE_SCAN)) {
2485 scan_ch->type = 0; /* passive */
2486 if (IWL_UCODE_API(priv->ucode_ver) == 1)
2487 scan_ch->active_dwell = cpu_to_le16(passive_dwell - 1);
2488 } else {
2489 scan_ch->type = 1; /* active */
2490 }
2491
2492 /* Set direct probe bits. These may be used both for active
2493 * scan channels (probes gets sent right away),
2494 * or for passive channels (probes get se sent only after
2495 * hearing clear Rx packet).*/
2496 if (IWL_UCODE_API(priv->ucode_ver) >= 2) {
2497 if (n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002498 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002499 } else {
2500 /* uCode v1 does not allow setting direct probe bits on
2501 * passive channel. */
2502 if ((scan_ch->type & 1) && n_probes)
Winkler, Tomas0d210442009-01-23 13:45:21 -08002503 scan_ch->type |= IWL39_SCAN_PROBE_MASK(n_probes);
Abhijeet Kolekar011a0332008-12-02 12:14:07 -08002504 }
Zhu Yib481de92007-09-25 17:54:57 -07002505
Ben Cahill9fbab512007-11-29 11:09:47 +08002506 /* Set txpower levels to defaults */
Zhu Yib481de92007-09-25 17:54:57 -07002507 scan_ch->tpc.dsp_atten = 110;
2508 /* scan_pwr_info->tpc.dsp_atten; */
2509
2510 /*scan_pwr_info->tpc.tx_gain; */
Johannes Berg8318d782008-01-24 19:38:38 +01002511 if (band == IEEE80211_BAND_5GHZ)
Zhu Yib481de92007-09-25 17:54:57 -07002512 scan_ch->tpc.tx_gain = ((1 << 5) | (3 << 3)) | 3;
2513 else {
2514 scan_ch->tpc.tx_gain = ((1 << 5) | (5 << 3));
2515 /* NOTE: if we were doing 6Mb OFDM for scans we'd use
Ben Cahill9fbab512007-11-29 11:09:47 +08002516 * power level:
Reinette Chatre8a1b0242008-01-14 17:46:25 -08002517 * scan_ch->tpc.tx_gain = ((1 << 5) | (2 << 3)) | 3;
Zhu Yib481de92007-09-25 17:54:57 -07002518 */
2519 }
2520
Tomas Winklere1623442009-01-27 14:27:56 -08002521 IWL_DEBUG_SCAN(priv, "Scanning %d [%s %d]\n",
Zhu Yib481de92007-09-25 17:54:57 -07002522 scan_ch->channel,
2523 (scan_ch->type & 1) ? "ACTIVE" : "PASSIVE",
2524 (scan_ch->type & 1) ?
2525 active_dwell : passive_dwell);
2526
2527 scan_ch++;
2528 added++;
2529 }
2530
Tomas Winklere1623442009-01-27 14:27:56 -08002531 IWL_DEBUG_SCAN(priv, "total channels to scan %d \n", added);
Zhu Yib481de92007-09-25 17:54:57 -07002532 return added;
2533}
2534
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002535static void iwl3945_init_hw_rates(struct iwl_priv *priv,
Zhu Yib481de92007-09-25 17:54:57 -07002536 struct ieee80211_rate *rates)
2537{
2538 int i;
2539
2540 for (i = 0; i < IWL_RATE_COUNT; i++) {
Johannes Berg8318d782008-01-24 19:38:38 +01002541 rates[i].bitrate = iwl3945_rates[i].ieee * 5;
2542 rates[i].hw_value = i; /* Rate scaling will work on indexes */
2543 rates[i].hw_value_short = i;
2544 rates[i].flags = 0;
Samuel Ortizd9829a62008-12-19 10:37:12 +08002545 if ((i > IWL39_LAST_OFDM_RATE) || (i < IWL_FIRST_OFDM_RATE)) {
Zhu Yib481de92007-09-25 17:54:57 -07002546 /*
Johannes Berg8318d782008-01-24 19:38:38 +01002547 * If CCK != 1M then set short preamble rate flag.
Zhu Yib481de92007-09-25 17:54:57 -07002548 */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002549 rates[i].flags |= (iwl3945_rates[i].plcp == 10) ?
Johannes Berg8318d782008-01-24 19:38:38 +01002550 0 : IEEE80211_RATE_SHORT_PREAMBLE;
Zhu Yib481de92007-09-25 17:54:57 -07002551 }
Zhu Yib481de92007-09-25 17:54:57 -07002552 }
2553}
2554
Zhu Yib481de92007-09-25 17:54:57 -07002555/******************************************************************************
2556 *
2557 * uCode download functions
2558 *
2559 ******************************************************************************/
2560
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002561static void iwl3945_dealloc_ucode_pci(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002562{
Tomas Winkler98c92212008-01-14 17:46:20 -08002563 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_code);
2564 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data);
2565 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
2566 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init);
2567 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_init_data);
2568 iwl_free_fw_desc(priv->pci_dev, &priv->ucode_boot);
Zhu Yib481de92007-09-25 17:54:57 -07002569}
2570
2571/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002572 * iwl3945_verify_inst_full - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002573 * looking at all data.
2574 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002575static int iwl3945_verify_inst_full(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002576{
2577 u32 val;
2578 u32 save_len = len;
2579 int rc = 0;
2580 u32 errcnt;
2581
Tomas Winklere1623442009-01-27 14:27:56 -08002582 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002583
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002584 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002585 if (rc)
2586 return rc;
2587
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002588 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002589 IWL39_RTC_INST_LOWER_BOUND);
Zhu Yib481de92007-09-25 17:54:57 -07002590
2591 errcnt = 0;
2592 for (; len > 0; len -= sizeof(u32), image++) {
2593 /* read data comes through single port, auto-incr addr */
2594 /* NOTE: Use the debugless read so we don't flood kernel log
2595 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002596 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002597 if (val != le32_to_cpu(*image)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002598 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002599 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2600 save_len - len, val, le32_to_cpu(*image));
2601 rc = -EIO;
2602 errcnt++;
2603 if (errcnt >= 20)
2604 break;
2605 }
2606 }
2607
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002608 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002609
2610 if (!errcnt)
Tomas Winklere1623442009-01-27 14:27:56 -08002611 IWL_DEBUG_INFO(priv,
2612 "ucode image in INSTRUCTION memory is good\n");
Zhu Yib481de92007-09-25 17:54:57 -07002613
2614 return rc;
2615}
2616
2617
2618/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002619 * iwl3945_verify_inst_sparse - verify runtime uCode image in card vs. host,
Zhu Yib481de92007-09-25 17:54:57 -07002620 * using sample data 100 bytes apart. If these sample points are good,
2621 * it's a pretty good bet that everything between them is good, too.
2622 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002623static int iwl3945_verify_inst_sparse(struct iwl_priv *priv, __le32 *image, u32 len)
Zhu Yib481de92007-09-25 17:54:57 -07002624{
2625 u32 val;
2626 int rc = 0;
2627 u32 errcnt = 0;
2628 u32 i;
2629
Tomas Winklere1623442009-01-27 14:27:56 -08002630 IWL_DEBUG_INFO(priv, "ucode inst image size is %u\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002631
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002632 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002633 if (rc)
2634 return rc;
2635
2636 for (i = 0; i < len; i += 100, image += 100/sizeof(u32)) {
2637 /* read data comes through single port, auto-incr addr */
2638 /* NOTE: Use the debugless read so we don't flood kernel log
2639 * if IWL_DL_IO is set */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002640 iwl_write_direct32(priv, HBUS_TARG_MEM_RADDR,
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002641 i + IWL39_RTC_INST_LOWER_BOUND);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002642 val = _iwl_read_direct32(priv, HBUS_TARG_MEM_RDAT);
Zhu Yib481de92007-09-25 17:54:57 -07002643 if (val != le32_to_cpu(*image)) {
2644#if 0 /* Enable this if you want to see details */
Winkler, Tomas15b16872008-12-19 10:37:33 +08002645 IWL_ERR(priv, "uCode INST section is invalid at "
Zhu Yib481de92007-09-25 17:54:57 -07002646 "offset 0x%x, is 0x%x, s/b 0x%x\n",
2647 i, val, *image);
2648#endif
2649 rc = -EIO;
2650 errcnt++;
2651 if (errcnt >= 3)
2652 break;
2653 }
2654 }
2655
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002656 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002657
2658 return rc;
2659}
2660
2661
2662/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002663 * iwl3945_verify_ucode - determine which instruction image is in SRAM,
Zhu Yib481de92007-09-25 17:54:57 -07002664 * and verify its contents
2665 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002666static int iwl3945_verify_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002667{
2668 __le32 *image;
2669 u32 len;
2670 int rc = 0;
2671
2672 /* Try bootstrap */
2673 image = (__le32 *)priv->ucode_boot.v_addr;
2674 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002675 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002676 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002677 IWL_DEBUG_INFO(priv, "Bootstrap uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002678 return 0;
2679 }
2680
2681 /* Try initialize */
2682 image = (__le32 *)priv->ucode_init.v_addr;
2683 len = priv->ucode_init.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002684 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002685 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002686 IWL_DEBUG_INFO(priv, "Initialize uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002687 return 0;
2688 }
2689
2690 /* Try runtime/protocol */
2691 image = (__le32 *)priv->ucode_code.v_addr;
2692 len = priv->ucode_code.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002693 rc = iwl3945_verify_inst_sparse(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002694 if (rc == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08002695 IWL_DEBUG_INFO(priv, "Runtime uCode is good in inst SRAM\n");
Zhu Yib481de92007-09-25 17:54:57 -07002696 return 0;
2697 }
2698
Winkler, Tomas15b16872008-12-19 10:37:33 +08002699 IWL_ERR(priv, "NO VALID UCODE IMAGE IN INSTRUCTION SRAM!!\n");
Zhu Yib481de92007-09-25 17:54:57 -07002700
Ben Cahill9fbab512007-11-29 11:09:47 +08002701 /* Since nothing seems to match, show first several data entries in
2702 * instruction SRAM, so maybe visual inspection will give a clue.
2703 * Selection of bootstrap image (vs. other images) is arbitrary. */
Zhu Yib481de92007-09-25 17:54:57 -07002704 image = (__le32 *)priv->ucode_boot.v_addr;
2705 len = priv->ucode_boot.len;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002706 rc = iwl3945_verify_inst_full(priv, image, len);
Zhu Yib481de92007-09-25 17:54:57 -07002707
2708 return rc;
2709}
2710
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002711static void iwl3945_nic_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002712{
2713 /* Remove all resets to allow NIC to operate */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002714 iwl_write32(priv, CSR_RESET, 0);
Zhu Yib481de92007-09-25 17:54:57 -07002715}
2716
2717/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002718 * iwl3945_read_ucode - Read uCode images from disk file.
Zhu Yib481de92007-09-25 17:54:57 -07002719 *
2720 * Copy into buffers for card to fetch via bus-mastering
2721 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002722static int iwl3945_read_ucode(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002723{
Kolekar, Abhijeeta78fe752008-12-19 10:37:21 +08002724 struct iwl_ucode *ucode;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002725 int ret = -EINVAL, index;
Zhu Yib481de92007-09-25 17:54:57 -07002726 const struct firmware *ucode_raw;
2727 /* firmware file name contains uCode/driver compatibility version */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002728 const char *name_pre = priv->cfg->fw_name_pre;
2729 const unsigned int api_max = priv->cfg->ucode_api_max;
2730 const unsigned int api_min = priv->cfg->ucode_api_min;
2731 char buf[25];
Zhu Yib481de92007-09-25 17:54:57 -07002732 u8 *src;
2733 size_t len;
Reinette Chatrea0987a82008-12-02 12:14:06 -08002734 u32 api_ver, inst_size, data_size, init_size, init_data_size, boot_size;
Zhu Yib481de92007-09-25 17:54:57 -07002735
2736 /* Ask kernel firmware_class module to get the boot firmware off disk.
2737 * request_firmware() is synchronous, file is in memory on return. */
Reinette Chatrea0987a82008-12-02 12:14:06 -08002738 for (index = api_max; index >= api_min; index--) {
2739 sprintf(buf, "%s%u%s", name_pre, index, ".ucode");
2740 ret = request_firmware(&ucode_raw, buf, &priv->pci_dev->dev);
2741 if (ret < 0) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002742 IWL_ERR(priv, "%s firmware file req failed: %d\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002743 buf, ret);
2744 if (ret == -ENOENT)
2745 continue;
2746 else
2747 goto error;
2748 } else {
2749 if (index < api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002750 IWL_ERR(priv, "Loaded firmware %s, "
2751 "which is deprecated. "
2752 " Please use API v%u instead.\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002753 buf, api_max);
Tomas Winklere1623442009-01-27 14:27:56 -08002754 IWL_DEBUG_INFO(priv, "Got firmware '%s' file "
2755 "(%zd bytes) from disk\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002756 buf, ucode_raw->size);
2757 break;
2758 }
Zhu Yib481de92007-09-25 17:54:57 -07002759 }
2760
Reinette Chatrea0987a82008-12-02 12:14:06 -08002761 if (ret < 0)
2762 goto error;
Zhu Yib481de92007-09-25 17:54:57 -07002763
2764 /* Make sure that we got at least our header! */
2765 if (ucode_raw->size < sizeof(*ucode)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002766 IWL_ERR(priv, "File size way too small!\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002767 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002768 goto err_release;
2769 }
2770
2771 /* Data from ucode file: header followed by uCode images */
2772 ucode = (void *)ucode_raw->data;
2773
Chatre, Reinettec02b3ac2008-12-02 12:14:05 -08002774 priv->ucode_ver = le32_to_cpu(ucode->ver);
Reinette Chatrea0987a82008-12-02 12:14:06 -08002775 api_ver = IWL_UCODE_API(priv->ucode_ver);
Zhu Yib481de92007-09-25 17:54:57 -07002776 inst_size = le32_to_cpu(ucode->inst_size);
2777 data_size = le32_to_cpu(ucode->data_size);
2778 init_size = le32_to_cpu(ucode->init_size);
2779 init_data_size = le32_to_cpu(ucode->init_data_size);
2780 boot_size = le32_to_cpu(ucode->boot_size);
2781
Reinette Chatrea0987a82008-12-02 12:14:06 -08002782 /* api_ver should match the api version forming part of the
2783 * firmware filename ... but we don't check for that and only rely
2784 * on the API version read from firware header from here on forward */
2785
2786 if (api_ver < api_min || api_ver > api_max) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08002787 IWL_ERR(priv, "Driver unable to support your firmware API. "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002788 "Driver supports v%u, firmware is v%u.\n",
2789 api_max, api_ver);
2790 priv->ucode_ver = 0;
2791 ret = -EINVAL;
2792 goto err_release;
2793 }
2794 if (api_ver != api_max)
Winkler, Tomas15b16872008-12-19 10:37:33 +08002795 IWL_ERR(priv, "Firmware has old API version. Expected %u, "
Reinette Chatrea0987a82008-12-02 12:14:06 -08002796 "got %u. New firmware can be obtained "
2797 "from http://www.intellinuxwireless.org.\n",
2798 api_max, api_ver);
2799
Tomas Winkler978785a2008-12-19 10:37:31 +08002800 IWL_INFO(priv, "loaded firmware version %u.%u.%u.%u\n",
2801 IWL_UCODE_MAJOR(priv->ucode_ver),
2802 IWL_UCODE_MINOR(priv->ucode_ver),
2803 IWL_UCODE_API(priv->ucode_ver),
2804 IWL_UCODE_SERIAL(priv->ucode_ver));
2805
Tomas Winklere1623442009-01-27 14:27:56 -08002806 IWL_DEBUG_INFO(priv, "f/w package hdr ucode version raw = 0x%x\n",
Reinette Chatrea0987a82008-12-02 12:14:06 -08002807 priv->ucode_ver);
Tomas Winklere1623442009-01-27 14:27:56 -08002808 IWL_DEBUG_INFO(priv, "f/w package hdr runtime inst size = %u\n",
2809 inst_size);
2810 IWL_DEBUG_INFO(priv, "f/w package hdr runtime data size = %u\n",
2811 data_size);
2812 IWL_DEBUG_INFO(priv, "f/w package hdr init inst size = %u\n",
2813 init_size);
2814 IWL_DEBUG_INFO(priv, "f/w package hdr init data size = %u\n",
2815 init_data_size);
2816 IWL_DEBUG_INFO(priv, "f/w package hdr boot inst size = %u\n",
2817 boot_size);
Zhu Yib481de92007-09-25 17:54:57 -07002818
Reinette Chatrea0987a82008-12-02 12:14:06 -08002819
Zhu Yib481de92007-09-25 17:54:57 -07002820 /* Verify size of file vs. image size info in file's header */
2821 if (ucode_raw->size < sizeof(*ucode) +
2822 inst_size + data_size + init_size +
2823 init_data_size + boot_size) {
2824
Tomas Winklere1623442009-01-27 14:27:56 -08002825 IWL_DEBUG_INFO(priv, "uCode file size %zd too small\n",
2826 ucode_raw->size);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002827 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002828 goto err_release;
2829 }
2830
2831 /* Verify that uCode images will fit in card's SRAM */
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002832 if (inst_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002833 IWL_DEBUG_INFO(priv, "uCode instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002834 inst_size);
2835 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002836 goto err_release;
2837 }
2838
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002839 if (data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002840 IWL_DEBUG_INFO(priv, "uCode data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002841 data_size);
2842 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002843 goto err_release;
2844 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002845 if (init_size > IWL39_MAX_INST_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002846 IWL_DEBUG_INFO(priv,
2847 "uCode init instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002848 init_size);
2849 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002850 goto err_release;
2851 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002852 if (init_data_size > IWL39_MAX_DATA_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002853 IWL_DEBUG_INFO(priv,
2854 "uCode init data len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002855 init_data_size);
2856 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002857 goto err_release;
2858 }
Samuel Ortiz250bdd22008-12-19 10:37:11 +08002859 if (boot_size > IWL39_MAX_BSM_SIZE) {
Tomas Winklere1623442009-01-27 14:27:56 -08002860 IWL_DEBUG_INFO(priv,
2861 "uCode boot instr len %d too large to fit in\n",
Tomas Winkler90e759d2007-11-29 11:09:41 +08002862 boot_size);
2863 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07002864 goto err_release;
2865 }
2866
2867 /* Allocate ucode buffers for card's bus-master loading ... */
2868
2869 /* Runtime instructions and 2 copies of data:
2870 * 1) unmodified from disk
2871 * 2) backup cache for save/restore during power-downs */
2872 priv->ucode_code.len = inst_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002873 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_code);
Zhu Yib481de92007-09-25 17:54:57 -07002874
2875 priv->ucode_data.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002876 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data);
Zhu Yib481de92007-09-25 17:54:57 -07002877
2878 priv->ucode_data_backup.len = data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002879 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_data_backup);
Zhu Yib481de92007-09-25 17:54:57 -07002880
2881 if (!priv->ucode_code.v_addr || !priv->ucode_data.v_addr ||
Tomas Winkler90e759d2007-11-29 11:09:41 +08002882 !priv->ucode_data_backup.v_addr)
Zhu Yib481de92007-09-25 17:54:57 -07002883 goto err_pci_alloc;
2884
Tomas Winkler90e759d2007-11-29 11:09:41 +08002885 /* Initialization instructions and data */
2886 if (init_size && init_data_size) {
2887 priv->ucode_init.len = init_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002888 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002889
2890 priv->ucode_init_data.len = init_data_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002891 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_init_data);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002892
2893 if (!priv->ucode_init.v_addr || !priv->ucode_init_data.v_addr)
2894 goto err_pci_alloc;
2895 }
2896
2897 /* Bootstrap (instructions only, no data) */
2898 if (boot_size) {
2899 priv->ucode_boot.len = boot_size;
Tomas Winkler98c92212008-01-14 17:46:20 -08002900 iwl_alloc_fw_desc(priv->pci_dev, &priv->ucode_boot);
Tomas Winkler90e759d2007-11-29 11:09:41 +08002901
2902 if (!priv->ucode_boot.v_addr)
2903 goto err_pci_alloc;
2904 }
2905
Zhu Yib481de92007-09-25 17:54:57 -07002906 /* Copy images into buffers for card's bus-master reads ... */
2907
2908 /* Runtime instructions (first block of data in file) */
2909 src = &ucode->data[0];
2910 len = priv->ucode_code.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002911 IWL_DEBUG_INFO(priv,
2912 "Copying (but not loading) uCode instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002913 memcpy(priv->ucode_code.v_addr, src, len);
Tomas Winklere1623442009-01-27 14:27:56 -08002914 IWL_DEBUG_INFO(priv, "uCode instr buf vaddr = 0x%p, paddr = 0x%08x\n",
Zhu Yib481de92007-09-25 17:54:57 -07002915 priv->ucode_code.v_addr, (u32)priv->ucode_code.p_addr);
2916
2917 /* Runtime data (2nd block)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002918 * NOTE: Copy into backup buffer will be done in iwl3945_up() */
Zhu Yib481de92007-09-25 17:54:57 -07002919 src = &ucode->data[inst_size];
2920 len = priv->ucode_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002921 IWL_DEBUG_INFO(priv,
2922 "Copying (but not loading) uCode data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002923 memcpy(priv->ucode_data.v_addr, src, len);
2924 memcpy(priv->ucode_data_backup.v_addr, src, len);
2925
2926 /* Initialization instructions (3rd block) */
2927 if (init_size) {
2928 src = &ucode->data[inst_size + data_size];
2929 len = priv->ucode_init.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002930 IWL_DEBUG_INFO(priv,
2931 "Copying (but not loading) init instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002932 memcpy(priv->ucode_init.v_addr, src, len);
2933 }
2934
2935 /* Initialization data (4th block) */
2936 if (init_data_size) {
2937 src = &ucode->data[inst_size + data_size + init_size];
2938 len = priv->ucode_init_data.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002939 IWL_DEBUG_INFO(priv,
2940 "Copying (but not loading) init data len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002941 memcpy(priv->ucode_init_data.v_addr, src, len);
2942 }
2943
2944 /* Bootstrap instructions (5th block) */
2945 src = &ucode->data[inst_size + data_size + init_size + init_data_size];
2946 len = priv->ucode_boot.len;
Tomas Winklere1623442009-01-27 14:27:56 -08002947 IWL_DEBUG_INFO(priv,
2948 "Copying (but not loading) boot instr len %zd\n", len);
Zhu Yib481de92007-09-25 17:54:57 -07002949 memcpy(priv->ucode_boot.v_addr, src, len);
2950
2951 /* We have our copies now, allow OS release its copies */
2952 release_firmware(ucode_raw);
2953 return 0;
2954
2955 err_pci_alloc:
Winkler, Tomas15b16872008-12-19 10:37:33 +08002956 IWL_ERR(priv, "failed to allocate pci memory\n");
Tomas Winkler90e759d2007-11-29 11:09:41 +08002957 ret = -ENOMEM;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002958 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002959
2960 err_release:
2961 release_firmware(ucode_raw);
2962
2963 error:
Tomas Winkler90e759d2007-11-29 11:09:41 +08002964 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07002965}
2966
2967
2968/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08002969 * iwl3945_set_ucode_ptrs - Set uCode address location
Zhu Yib481de92007-09-25 17:54:57 -07002970 *
2971 * Tell initialization uCode where to find runtime uCode.
2972 *
2973 * BSM registers initially contain pointers to initialization uCode.
2974 * We need to replace them to load runtime uCode inst and data,
2975 * and to save runtime data when powering down.
2976 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08002977static int iwl3945_set_ucode_ptrs(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07002978{
2979 dma_addr_t pinst;
2980 dma_addr_t pdata;
2981 int rc = 0;
2982 unsigned long flags;
2983
2984 /* bits 31:0 for 3945 */
2985 pinst = priv->ucode_code.p_addr;
2986 pdata = priv->ucode_data_backup.p_addr;
2987
2988 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002989 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07002990 if (rc) {
2991 spin_unlock_irqrestore(&priv->lock, flags);
2992 return rc;
2993 }
2994
2995 /* Tell bootstrap uCode where to find image to load */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08002996 iwl_write_prph(priv, BSM_DRAM_INST_PTR_REG, pinst);
2997 iwl_write_prph(priv, BSM_DRAM_DATA_PTR_REG, pdata);
2998 iwl_write_prph(priv, BSM_DRAM_DATA_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07002999 priv->ucode_data.len);
3000
Tomas Winklera96a27f2008-10-23 23:48:56 -07003001 /* Inst byte count must be last to set up, bit 31 signals uCode
Zhu Yib481de92007-09-25 17:54:57 -07003002 * that all new ptr/size info is in place */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003003 iwl_write_prph(priv, BSM_DRAM_INST_BYTECOUNT_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003004 priv->ucode_code.len | BSM_DRAM_INST_LOAD);
3005
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003006 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003007
3008 spin_unlock_irqrestore(&priv->lock, flags);
3009
Tomas Winklere1623442009-01-27 14:27:56 -08003010 IWL_DEBUG_INFO(priv, "Runtime uCode pointers are set.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003011
3012 return rc;
3013}
3014
3015/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003016 * iwl3945_init_alive_start - Called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003017 *
3018 * Called after REPLY_ALIVE notification received from "initialize" uCode.
3019 *
Zhu Yib481de92007-09-25 17:54:57 -07003020 * Tell "initialize" uCode to go ahead and load the runtime uCode.
Ben Cahill9fbab512007-11-29 11:09:47 +08003021 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003022static void iwl3945_init_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003023{
3024 /* Check alive response for "valid" sign from uCode */
3025 if (priv->card_alive_init.is_valid != UCODE_VALID_OK) {
3026 /* We had an error bringing up the hardware, so take it
3027 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003028 IWL_DEBUG_INFO(priv, "Initialize Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003029 goto restart;
3030 }
3031
3032 /* Bootstrap uCode has loaded initialize uCode ... verify inst image.
3033 * This is a paranoid check, because we would not have gotten the
3034 * "initialize" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003035 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003036 /* Runtime instruction load was bad;
3037 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003038 IWL_DEBUG_INFO(priv, "Bad \"initialize\" uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003039 goto restart;
3040 }
3041
3042 /* Send pointers to protocol/runtime uCode image ... init code will
3043 * load and launch runtime uCode, which will send us another "Alive"
3044 * notification. */
Tomas Winklere1623442009-01-27 14:27:56 -08003045 IWL_DEBUG_INFO(priv, "Initialization Alive received.\n");
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003046 if (iwl3945_set_ucode_ptrs(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003047 /* Runtime instruction load won't happen;
3048 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003049 IWL_DEBUG_INFO(priv, "Couldn't set up uCode pointers.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003050 goto restart;
3051 }
3052 return;
3053
3054 restart:
3055 queue_work(priv->workqueue, &priv->restart);
3056}
3057
3058
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003059/* temporary */
3060static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw,
3061 struct sk_buff *skb);
3062
Zhu Yib481de92007-09-25 17:54:57 -07003063/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003064 * iwl3945_alive_start - called after REPLY_ALIVE notification received
Zhu Yib481de92007-09-25 17:54:57 -07003065 * from protocol/runtime uCode (initialization uCode's
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003066 * Alive gets handled by iwl3945_init_alive_start()).
Zhu Yib481de92007-09-25 17:54:57 -07003067 */
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003068static void iwl3945_alive_start(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003069{
3070 int rc = 0;
3071 int thermal_spin = 0;
3072 u32 rfkill;
3073
Tomas Winklere1623442009-01-27 14:27:56 -08003074 IWL_DEBUG_INFO(priv, "Runtime Alive received.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003075
3076 if (priv->card_alive.is_valid != UCODE_VALID_OK) {
3077 /* We had an error bringing up the hardware, so take it
3078 * all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003079 IWL_DEBUG_INFO(priv, "Alive failed.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003080 goto restart;
3081 }
3082
3083 /* Initialize uCode has loaded Runtime uCode ... verify inst image.
3084 * This is a paranoid check, because we would not have gotten the
3085 * "runtime" alive if code weren't properly loaded. */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003086 if (iwl3945_verify_ucode(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003087 /* Runtime instruction load was bad;
3088 * take it all the way back down so we can try again */
Tomas Winklere1623442009-01-27 14:27:56 -08003089 IWL_DEBUG_INFO(priv, "Bad runtime uCode load.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003090 goto restart;
3091 }
3092
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003093 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003094
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003095 rc = iwl_grab_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003096 if (rc) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003097 IWL_WARN(priv, "Can not read RFKILL status from adapter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003098 return;
3099 }
3100
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003101 rfkill = iwl_read_prph(priv, APMG_RFKILL_REG);
Tomas Winklere1623442009-01-27 14:27:56 -08003102 IWL_DEBUG_INFO(priv, "RFKILL status: 0x%x\n", rfkill);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003103 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003104
3105 if (rfkill & 0x1) {
3106 clear_bit(STATUS_RF_KILL_HW, &priv->status);
Tomas Winklera96a27f2008-10-23 23:48:56 -07003107 /* if RFKILL is not on, then wait for thermal
Zhu Yib481de92007-09-25 17:54:57 -07003108 * sensor in adapter to kick in */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003109 while (iwl3945_hw_get_temperature(priv) == 0) {
Zhu Yib481de92007-09-25 17:54:57 -07003110 thermal_spin++;
3111 udelay(10);
3112 }
3113
3114 if (thermal_spin)
Tomas Winklere1623442009-01-27 14:27:56 -08003115 IWL_DEBUG_INFO(priv, "Thermal calibration took %dus\n",
Zhu Yib481de92007-09-25 17:54:57 -07003116 thermal_spin * 10);
3117 } else
3118 set_bit(STATUS_RF_KILL_HW, &priv->status);
3119
Ben Cahill9fbab512007-11-29 11:09:47 +08003120 /* After the ALIVE response, we can send commands to 3945 uCode */
Zhu Yib481de92007-09-25 17:54:57 -07003121 set_bit(STATUS_ALIVE, &priv->status);
3122
3123 /* Clear out the uCode error bit if it is set */
3124 clear_bit(STATUS_FW_ERROR, &priv->status);
3125
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003126 if (iwl_is_rfkill(priv))
Zhu Yib481de92007-09-25 17:54:57 -07003127 return;
3128
Johannes Berg36d68252008-05-15 12:55:26 +02003129 ieee80211_wake_queues(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07003130
3131 priv->active_rate = priv->rates_mask;
3132 priv->active_rate_basic = priv->rates_mask & IWL_BASIC_RATES_MASK;
3133
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08003134 iwl_power_update_mode(priv, false);
Zhu Yib481de92007-09-25 17:54:57 -07003135
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003136 if (iwl_is_associated(priv)) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003137 struct iwl3945_rxon_cmd *active_rxon =
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003138 (struct iwl3945_rxon_cmd *)(&priv->active_rxon);
Zhu Yib481de92007-09-25 17:54:57 -07003139
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003140 memcpy(&priv->staging_rxon, &priv->active_rxon,
3141 sizeof(priv->staging_rxon));
Zhu Yib481de92007-09-25 17:54:57 -07003142 active_rxon->filter_flags &= ~RXON_FILTER_ASSOC_MSK;
3143 } else {
3144 /* Initialize our rx_config data */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003145 iwl_connection_init_rx_config(priv, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003146 }
3147
Ben Cahill9fbab512007-11-29 11:09:47 +08003148 /* Configure Bluetooth device coexistence support */
Samuel Ortiz17f841c2009-01-23 13:45:20 -08003149 iwl_send_bt_config(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003150
3151 /* Configure the adapter for unassociated operation */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003152 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003153
Zhu Yib481de92007-09-25 17:54:57 -07003154 iwl3945_reg_txpower_periodic(priv);
3155
Reinette Chatrefe00b5a2008-04-03 16:05:23 -07003156 iwl3945_led_register(priv);
3157
Tomas Winklere1623442009-01-27 14:27:56 -08003158 IWL_DEBUG_INFO(priv, "ALIVE processing complete.\n");
Rick Farringtona9f46782008-03-18 14:57:49 -07003159 set_bit(STATUS_READY, &priv->status);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003160 wake_up_interruptible(&priv->wait_command_queue);
Zhu Yib481de92007-09-25 17:54:57 -07003161
3162 if (priv->error_recovering)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003163 iwl3945_error_recovery(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003164
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08003165 /* reassociate for ADHOC mode */
3166 if (priv->vif && (priv->iw_mode == NL80211_IFTYPE_ADHOC)) {
3167 struct sk_buff *beacon = ieee80211_beacon_get(priv->hw,
3168 priv->vif);
3169 if (beacon)
3170 iwl3945_mac_beacon_update(priv->hw, beacon);
3171 }
3172
Zhu Yib481de92007-09-25 17:54:57 -07003173 return;
3174
3175 restart:
3176 queue_work(priv->workqueue, &priv->restart);
3177}
3178
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003179static void iwl3945_cancel_deferred_work(struct iwl_priv *priv);
Zhu Yib481de92007-09-25 17:54:57 -07003180
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003181static void __iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003182{
3183 unsigned long flags;
3184 int exit_pending = test_bit(STATUS_EXIT_PENDING, &priv->status);
3185 struct ieee80211_conf *conf = NULL;
3186
Tomas Winklere1623442009-01-27 14:27:56 -08003187 IWL_DEBUG_INFO(priv, DRV_NAME " is going down\n");
Zhu Yib481de92007-09-25 17:54:57 -07003188
3189 conf = ieee80211_get_hw_conf(priv->hw);
3190
3191 if (!exit_pending)
3192 set_bit(STATUS_EXIT_PENDING, &priv->status);
3193
Mohamed Abbasab53d8a2008-03-25 16:33:36 -07003194 iwl3945_led_unregister(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003195 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003196
3197 /* Unblock any waiting calls */
3198 wake_up_interruptible_all(&priv->wait_command_queue);
3199
Zhu Yib481de92007-09-25 17:54:57 -07003200 /* Wipe out the EXIT_PENDING status bit if we are not actually
3201 * exiting the module */
3202 if (!exit_pending)
3203 clear_bit(STATUS_EXIT_PENDING, &priv->status);
3204
3205 /* stop and reset the on-board processor */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003206 iwl_write32(priv, CSR_RESET, CSR_RESET_REG_FLAG_NEVO_RESET);
Zhu Yib481de92007-09-25 17:54:57 -07003207
3208 /* tell the device to stop sending interrupts */
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003209 spin_lock_irqsave(&priv->lock, flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003210 iwl3945_disable_interrupts(priv);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07003211 spin_unlock_irqrestore(&priv->lock, flags);
3212 iwl_synchronize_irq(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003213
3214 if (priv->mac80211_registered)
3215 ieee80211_stop_queues(priv->hw);
3216
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003217 /* If we have not previously called iwl3945_init() then
Zhu Yib481de92007-09-25 17:54:57 -07003218 * clear all bits but the RF Kill and SUSPEND bits and return */
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003219 if (!iwl_is_init(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003220 priv->status = test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3221 STATUS_RF_KILL_HW |
3222 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3223 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003224 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3225 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003226 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003227 STATUS_IN_SUSPEND |
3228 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3229 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003230 goto exit;
3231 }
3232
3233 /* ...otherwise clear out all the status bits but the RF Kill and
3234 * SUSPEND bits and continue taking the NIC down. */
3235 priv->status &= test_bit(STATUS_RF_KILL_HW, &priv->status) <<
3236 STATUS_RF_KILL_HW |
3237 test_bit(STATUS_RF_KILL_SW, &priv->status) <<
3238 STATUS_RF_KILL_SW |
Reinette Chatre97888642008-02-06 11:20:38 -08003239 test_bit(STATUS_GEO_CONFIGURED, &priv->status) <<
3240 STATUS_GEO_CONFIGURED |
Zhu Yib481de92007-09-25 17:54:57 -07003241 test_bit(STATUS_IN_SUSPEND, &priv->status) <<
3242 STATUS_IN_SUSPEND |
3243 test_bit(STATUS_FW_ERROR, &priv->status) <<
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003244 STATUS_FW_ERROR |
3245 test_bit(STATUS_EXIT_PENDING, &priv->status) <<
3246 STATUS_EXIT_PENDING;
Zhu Yib481de92007-09-25 17:54:57 -07003247
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003248 priv->cfg->ops->lib->apm_ops.reset(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003249 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003250 iwl_clear_bit(priv, CSR_GP_CNTRL, CSR_GP_CNTRL_REG_FLAG_MAC_ACCESS_REQ);
Zhu Yib481de92007-09-25 17:54:57 -07003251 spin_unlock_irqrestore(&priv->lock, flags);
3252
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003253 iwl3945_hw_txq_ctx_stop(priv);
3254 iwl3945_hw_rxq_stop(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003255
3256 spin_lock_irqsave(&priv->lock, flags);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003257 if (!iwl_grab_nic_access(priv)) {
3258 iwl_write_prph(priv, APMG_CLK_DIS_REG,
Zhu Yib481de92007-09-25 17:54:57 -07003259 APMG_CLK_VAL_DMA_CLK_RQT);
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003260 iwl_release_nic_access(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003261 }
3262 spin_unlock_irqrestore(&priv->lock, flags);
3263
3264 udelay(5);
3265
Abbas, Mohamede9414b62009-01-20 21:33:55 -08003266 if (exit_pending || test_bit(STATUS_IN_SUSPEND, &priv->status))
3267 priv->cfg->ops->lib->apm_ops.stop(priv);
3268 else
3269 priv->cfg->ops->lib->apm_ops.reset(priv);
3270
Zhu Yib481de92007-09-25 17:54:57 -07003271 exit:
Tomas Winkler3d24a9f2008-12-19 10:37:07 +08003272 memset(&priv->card_alive, 0, sizeof(struct iwl_alive_resp));
Zhu Yib481de92007-09-25 17:54:57 -07003273
3274 if (priv->ibss_beacon)
3275 dev_kfree_skb(priv->ibss_beacon);
3276 priv->ibss_beacon = NULL;
3277
3278 /* clear out any free frames */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003279 iwl3945_clear_free_frames(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003280}
3281
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003282static void iwl3945_down(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003283{
3284 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003285 __iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003286 mutex_unlock(&priv->mutex);
Zhu Yib24d22b2007-12-19 13:59:52 +08003287
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003288 iwl3945_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003289}
3290
3291#define MAX_HW_RESTARTS 5
3292
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003293static int __iwl3945_up(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003294{
3295 int rc, i;
3296
3297 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003298 IWL_WARN(priv, "Exit pending; will not bring the NIC up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003299 return -EIO;
3300 }
3301
3302 if (test_bit(STATUS_RF_KILL_SW, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003303 IWL_WARN(priv, "Radio disabled by SW RF kill (module "
Zhu Yib481de92007-09-25 17:54:57 -07003304 "parameter)\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003305 return -ENODEV;
3306 }
3307
Reinette Chatree903fbd2008-01-30 22:05:15 -08003308 if (!priv->ucode_data_backup.v_addr || !priv->ucode_data.v_addr) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003309 IWL_ERR(priv, "ucode not available for device bring up\n");
Reinette Chatree903fbd2008-01-30 22:05:15 -08003310 return -EIO;
3311 }
3312
Zhu Yie655b9f2008-01-24 02:19:38 -08003313 /* If platform's RF_KILL switch is NOT set to KILL */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003314 if (iwl_read32(priv, CSR_GP_CNTRL) &
Zhu Yie655b9f2008-01-24 02:19:38 -08003315 CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3316 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3317 else {
3318 set_bit(STATUS_RF_KILL_HW, &priv->status);
3319 if (!test_bit(STATUS_IN_SUSPEND, &priv->status)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003320 IWL_WARN(priv, "Radio disabled by HW RF Kill switch\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003321 return -ENODEV;
3322 }
Zhu Yib481de92007-09-25 17:54:57 -07003323 }
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003324
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003325 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Zhu Yib481de92007-09-25 17:54:57 -07003326
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003327 rc = iwl3945_hw_nic_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003328 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003329 IWL_ERR(priv, "Unable to int nic\n");
Zhu Yib481de92007-09-25 17:54:57 -07003330 return rc;
3331 }
3332
3333 /* make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003334 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3335 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR,
Zhu Yib481de92007-09-25 17:54:57 -07003336 CSR_UCODE_DRV_GP1_BIT_CMD_BLOCKED);
3337
3338 /* clear (again), then enable host interrupts */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003339 iwl_write32(priv, CSR_INT, 0xFFFFFFFF);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003340 iwl3945_enable_interrupts(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003341
3342 /* really make sure rfkill handshake bits are cleared */
Abhijeet Kolekar5d49f492008-12-19 10:37:29 +08003343 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
3344 iwl_write32(priv, CSR_UCODE_DRV_GP1_CLR, CSR_UCODE_SW_BIT_RFKILL);
Zhu Yib481de92007-09-25 17:54:57 -07003345
3346 /* Copy original ucode data image from disk into backup cache.
3347 * This will be used to initialize the on-board processor's
3348 * data SRAM for a clean start when the runtime program first loads. */
3349 memcpy(priv->ucode_data_backup.v_addr, priv->ucode_data.v_addr,
Zhu Yi5a66926a2008-01-14 17:46:18 -08003350 priv->ucode_data.len);
Zhu Yib481de92007-09-25 17:54:57 -07003351
Zhu Yie655b9f2008-01-24 02:19:38 -08003352 /* We return success when we resume from suspend and rf_kill is on. */
3353 if (test_bit(STATUS_RF_KILL_HW, &priv->status))
3354 return 0;
3355
Zhu Yib481de92007-09-25 17:54:57 -07003356 for (i = 0; i < MAX_HW_RESTARTS; i++) {
3357
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003358 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003359
3360 /* load bootstrap state machine,
3361 * load bootstrap program into processor's memory,
3362 * prepare to load the "initialize" uCode */
Kolekar, Abhijeet0164b9b2008-12-19 10:37:37 +08003363 priv->cfg->ops->lib->load_ucode(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003364
3365 if (rc) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003366 IWL_ERR(priv,
3367 "Unable to set up bootstrap uCode: %d\n", rc);
Zhu Yib481de92007-09-25 17:54:57 -07003368 continue;
3369 }
3370
3371 /* start card; "initialize" will load runtime ucode */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003372 iwl3945_nic_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003373
Tomas Winklere1623442009-01-27 14:27:56 -08003374 IWL_DEBUG_INFO(priv, DRV_NAME " is coming up\n");
Zhu Yib481de92007-09-25 17:54:57 -07003375
3376 return 0;
3377 }
3378
3379 set_bit(STATUS_EXIT_PENDING, &priv->status);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003380 __iwl3945_down(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08003381 clear_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003382
3383 /* tried to restart and config the device for as long as our
3384 * patience could withstand */
Winkler, Tomas15b16872008-12-19 10:37:33 +08003385 IWL_ERR(priv, "Unable to initialize device after %d attempts.\n", i);
Zhu Yib481de92007-09-25 17:54:57 -07003386 return -EIO;
3387}
3388
3389
3390/*****************************************************************************
3391 *
3392 * Workqueue callbacks
3393 *
3394 *****************************************************************************/
3395
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003396static void iwl3945_bg_init_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003397{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003398 struct iwl_priv *priv =
3399 container_of(data, struct iwl_priv, init_alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003400
3401 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3402 return;
3403
3404 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003405 iwl3945_init_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003406 mutex_unlock(&priv->mutex);
3407}
3408
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003409static void iwl3945_bg_alive_start(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003410{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003411 struct iwl_priv *priv =
3412 container_of(data, struct iwl_priv, alive_start.work);
Zhu Yib481de92007-09-25 17:54:57 -07003413
3414 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3415 return;
3416
3417 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003418 iwl3945_alive_start(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003419 mutex_unlock(&priv->mutex);
3420}
3421
Helmut Schaa26635162009-01-15 09:38:44 +01003422static void iwl3945_rfkill_poll(struct work_struct *data)
3423{
3424 struct iwl_priv *priv =
3425 container_of(data, struct iwl_priv, rfkill_poll.work);
3426 unsigned long status = priv->status;
3427
3428 if (iwl_read32(priv, CSR_GP_CNTRL) & CSR_GP_CNTRL_REG_FLAG_HW_RF_KILL_SW)
3429 clear_bit(STATUS_RF_KILL_HW, &priv->status);
3430 else
3431 set_bit(STATUS_RF_KILL_HW, &priv->status);
3432
3433 if (test_bit(STATUS_RF_KILL_HW, &status) != test_bit(STATUS_RF_KILL_HW, &priv->status))
3434 queue_work(priv->workqueue, &priv->rf_kill);
3435
3436 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3437 round_jiffies_relative(2 * HZ));
3438
3439}
3440
Zhu Yib481de92007-09-25 17:54:57 -07003441#define IWL_SCAN_CHECK_WATCHDOG (7 * HZ)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003442static void iwl3945_bg_request_scan(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003443{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003444 struct iwl_priv *priv =
3445 container_of(data, struct iwl_priv, request_scan);
Winkler, Tomasc2d79b482008-12-19 10:37:34 +08003446 struct iwl_host_cmd cmd = {
Zhu Yib481de92007-09-25 17:54:57 -07003447 .id = REPLY_SCAN_CMD,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003448 .len = sizeof(struct iwl3945_scan_cmd),
Zhu Yib481de92007-09-25 17:54:57 -07003449 .meta.flags = CMD_SIZE_HUGE,
3450 };
3451 int rc = 0;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003452 struct iwl3945_scan_cmd *scan;
Zhu Yib481de92007-09-25 17:54:57 -07003453 struct ieee80211_conf *conf = NULL;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003454 u8 n_probes = 2;
Johannes Berg8318d782008-01-24 19:38:38 +01003455 enum ieee80211_band band;
John W. Linville9387b7c2008-09-30 20:59:05 -04003456 DECLARE_SSID_BUF(ssid);
Zhu Yib481de92007-09-25 17:54:57 -07003457
3458 conf = ieee80211_get_hw_conf(priv->hw);
3459
3460 mutex_lock(&priv->mutex);
3461
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003462 if (!iwl_is_ready(priv)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003463 IWL_WARN(priv, "request scan called when driver not ready.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003464 goto done;
3465 }
3466
Tomas Winklera96a27f2008-10-23 23:48:56 -07003467 /* Make sure the scan wasn't canceled before this queued work
Zhu Yib481de92007-09-25 17:54:57 -07003468 * was given the chance to run... */
3469 if (!test_bit(STATUS_SCANNING, &priv->status))
3470 goto done;
3471
3472 /* This should never be called or scheduled if there is currently
3473 * a scan active in the hardware. */
3474 if (test_bit(STATUS_SCAN_HW, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003475 IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests "
3476 "Ignoring second request.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003477 rc = -EIO;
3478 goto done;
3479 }
3480
3481 if (test_bit(STATUS_EXIT_PENDING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003482 IWL_DEBUG_SCAN(priv, "Aborting scan due to device shutdown\n");
Zhu Yib481de92007-09-25 17:54:57 -07003483 goto done;
3484 }
3485
3486 if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003487 IWL_DEBUG_HC(priv,
3488 "Scan request while abort pending. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003489 goto done;
3490 }
3491
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003492 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003493 IWL_DEBUG_HC(priv, "Aborting scan due to RF Kill activation\n");
Zhu Yib481de92007-09-25 17:54:57 -07003494 goto done;
3495 }
3496
3497 if (!test_bit(STATUS_READY, &priv->status)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003498 IWL_DEBUG_HC(priv,
3499 "Scan request while uninitialized. Queuing.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003500 goto done;
3501 }
3502
3503 if (!priv->scan_bands) {
Tomas Winklere1623442009-01-27 14:27:56 -08003504 IWL_DEBUG_HC(priv, "Aborting scan due to no requested bands\n");
Zhu Yib481de92007-09-25 17:54:57 -07003505 goto done;
3506 }
3507
Winkler, Tomas805cee52009-01-19 15:30:28 -08003508 if (!priv->scan) {
3509 priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) +
Zhu Yib481de92007-09-25 17:54:57 -07003510 IWL_MAX_SCAN_SIZE, GFP_KERNEL);
Winkler, Tomas805cee52009-01-19 15:30:28 -08003511 if (!priv->scan) {
Zhu Yib481de92007-09-25 17:54:57 -07003512 rc = -ENOMEM;
3513 goto done;
3514 }
3515 }
Winkler, Tomas805cee52009-01-19 15:30:28 -08003516 scan = priv->scan;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003517 memset(scan, 0, sizeof(struct iwl3945_scan_cmd) + IWL_MAX_SCAN_SIZE);
Zhu Yib481de92007-09-25 17:54:57 -07003518
3519 scan->quiet_plcp_th = IWL_PLCP_QUIET_THRESH;
3520 scan->quiet_time = IWL_ACTIVE_QUIET_TIME;
3521
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003522 if (iwl_is_associated(priv)) {
Zhu Yib481de92007-09-25 17:54:57 -07003523 u16 interval = 0;
3524 u32 extra;
3525 u32 suspend_time = 100;
3526 u32 scan_suspend_time = 100;
3527 unsigned long flags;
3528
Tomas Winklere1623442009-01-27 14:27:56 -08003529 IWL_DEBUG_INFO(priv, "Scanning while associated...\n");
Zhu Yib481de92007-09-25 17:54:57 -07003530
3531 spin_lock_irqsave(&priv->lock, flags);
3532 interval = priv->beacon_int;
3533 spin_unlock_irqrestore(&priv->lock, flags);
3534
3535 scan->suspend_time = 0;
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003536 scan->max_out_time = cpu_to_le32(200 * 1024);
Zhu Yib481de92007-09-25 17:54:57 -07003537 if (!interval)
3538 interval = suspend_time;
3539 /*
3540 * suspend time format:
3541 * 0-19: beacon interval in usec (time before exec.)
3542 * 20-23: 0
3543 * 24-31: number of beacons (suspend between channels)
3544 */
3545
3546 extra = (suspend_time / interval) << 24;
3547 scan_suspend_time = 0xFF0FFFFF &
3548 (extra | ((suspend_time % interval) * 1024));
3549
3550 scan->suspend_time = cpu_to_le32(scan_suspend_time);
Tomas Winklere1623442009-01-27 14:27:56 -08003551 IWL_DEBUG_SCAN(priv, "suspend_time 0x%X beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003552 scan_suspend_time, interval);
3553 }
3554
3555 /* We should add the ability for user to lock to PASSIVE ONLY */
3556 if (priv->one_direct_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08003557 IWL_DEBUG_SCAN(priv, "Kicking off one direct scan for '%s'\n",
3558 print_ssid(ssid, priv->direct_ssid,
John W. Linville9387b7c2008-09-30 20:59:05 -04003559 priv->direct_ssid_len));
Zhu Yib481de92007-09-25 17:54:57 -07003560 scan->direct_scan[0].id = WLAN_EID_SSID;
3561 scan->direct_scan[0].len = priv->direct_ssid_len;
3562 memcpy(scan->direct_scan[0].ssid,
3563 priv->direct_ssid, priv->direct_ssid_len);
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003564 n_probes++;
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003565 } else
Tomas Winklere1623442009-01-27 14:27:56 -08003566 IWL_DEBUG_SCAN(priv, "Kicking off one indirect scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07003567
3568 /* We don't build a direct scan probe request; the uCode will do
3569 * that based on the direct_mask added to each channel entry */
Zhu Yib481de92007-09-25 17:54:57 -07003570 scan->tx_cmd.tx_flags = TX_CMD_FLG_SEQ_CTL_MSK;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08003571 scan->tx_cmd.sta_id = priv->hw_params.bcast_sta_id;
Zhu Yib481de92007-09-25 17:54:57 -07003572 scan->tx_cmd.stop_time.life_time = TX_CMD_LIFE_TIME_INFINITE;
3573
3574 /* flags + rate selection */
3575
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003576 if (priv->scan_bands & BIT(IEEE80211_BAND_2GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003577 scan->flags = RXON_FLG_BAND_24G_MSK | RXON_FLG_AUTO_DETECT_MSK;
3578 scan->tx_cmd.rate = IWL_RATE_1M_PLCP;
3579 scan->good_CRC_th = 0;
Johannes Berg8318d782008-01-24 19:38:38 +01003580 band = IEEE80211_BAND_2GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003581 } else if (priv->scan_bands & BIT(IEEE80211_BAND_5GHZ)) {
Zhu Yib481de92007-09-25 17:54:57 -07003582 scan->tx_cmd.rate = IWL_RATE_6M_PLCP;
3583 scan->good_CRC_th = IWL_GOOD_CRC_TH;
Johannes Berg8318d782008-01-24 19:38:38 +01003584 band = IEEE80211_BAND_5GHZ;
Ron Rindjunsky66b50042008-06-25 16:46:31 +08003585 } else {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003586 IWL_WARN(priv, "Invalid scan band count\n");
Zhu Yib481de92007-09-25 17:54:57 -07003587 goto done;
3588 }
3589
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08003590 scan->tx_cmd.len = cpu_to_le16(
3591 iwl_fill_probe_req(priv, band,
3592 (struct ieee80211_mgmt *)scan->data,
3593 IWL_MAX_SCAN_SIZE - sizeof(*scan)));
3594
Zhu Yib481de92007-09-25 17:54:57 -07003595 /* select Rx antennas */
3596 scan->flags |= iwl3945_get_antenna_flags(priv);
3597
Johannes Berg05c914f2008-09-11 00:01:58 +02003598 if (priv->iw_mode == NL80211_IFTYPE_MONITOR)
Zhu Yib481de92007-09-25 17:54:57 -07003599 scan->filter_flags = RXON_FILTER_PROMISC_MSK;
3600
Abhijeet Kolekarf9340522008-09-03 11:26:58 +08003601 scan->channel_count =
3602 iwl3945_get_channels_for_scan(priv, band, 1, /* active */
3603 n_probes,
3604 (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]);
Zhu Yib481de92007-09-25 17:54:57 -07003605
Reinette Chatre14b54332008-11-04 12:21:35 -08003606 if (scan->channel_count == 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08003607 IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count);
Reinette Chatre14b54332008-11-04 12:21:35 -08003608 goto done;
3609 }
3610
Zhu Yib481de92007-09-25 17:54:57 -07003611 cmd.len += le16_to_cpu(scan->tx_cmd.len) +
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003612 scan->channel_count * sizeof(struct iwl3945_scan_channel);
Zhu Yib481de92007-09-25 17:54:57 -07003613 cmd.data = scan;
3614 scan->len = cpu_to_le16(cmd.len);
3615
3616 set_bit(STATUS_SCAN_HW, &priv->status);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003617 rc = iwl_send_cmd_sync(priv, &cmd);
Zhu Yib481de92007-09-25 17:54:57 -07003618 if (rc)
3619 goto done;
3620
3621 queue_delayed_work(priv->workqueue, &priv->scan_check,
3622 IWL_SCAN_CHECK_WATCHDOG);
3623
3624 mutex_unlock(&priv->mutex);
3625 return;
3626
3627 done:
Mohamed Abbas2420ebc2008-11-04 12:21:34 -08003628 /* can not perform scan make sure we clear scanning
3629 * bits from status so next scan request can be performed.
3630 * if we dont clear scanning status bit here all next scan
3631 * will fail
3632 */
3633 clear_bit(STATUS_SCAN_HW, &priv->status);
3634 clear_bit(STATUS_SCANNING, &priv->status);
3635
Ian Schram01ebd062007-10-25 17:15:22 +08003636 /* inform mac80211 scan aborted */
Zhu Yib481de92007-09-25 17:54:57 -07003637 queue_work(priv->workqueue, &priv->scan_completed);
3638 mutex_unlock(&priv->mutex);
3639}
3640
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003641static void iwl3945_bg_up(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003642{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003643 struct iwl_priv *priv = container_of(data, struct iwl_priv, up);
Zhu Yib481de92007-09-25 17:54:57 -07003644
3645 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3646 return;
3647
3648 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003649 __iwl3945_up(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003650 mutex_unlock(&priv->mutex);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003651 iwl_rfkill_set_hw_state(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003652}
3653
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003654static void iwl3945_bg_restart(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003655{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003656 struct iwl_priv *priv = container_of(data, struct iwl_priv, restart);
Zhu Yib481de92007-09-25 17:54:57 -07003657
3658 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3659 return;
3660
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003661 iwl3945_down(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003662 queue_work(priv->workqueue, &priv->up);
3663}
3664
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003665static void iwl3945_bg_rx_replenish(struct work_struct *data)
Zhu Yib481de92007-09-25 17:54:57 -07003666{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003667 struct iwl_priv *priv =
3668 container_of(data, struct iwl_priv, rx_replenish);
Zhu Yib481de92007-09-25 17:54:57 -07003669
3670 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3671 return;
3672
3673 mutex_lock(&priv->mutex);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003674 iwl3945_rx_replenish(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003675 mutex_unlock(&priv->mutex);
3676}
3677
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003678#define IWL_DELAY_NEXT_SCAN (HZ*2)
3679
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003680static void iwl3945_post_associate(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07003681{
Zhu Yib481de92007-09-25 17:54:57 -07003682 int rc = 0;
3683 struct ieee80211_conf *conf = NULL;
3684
Johannes Berg05c914f2008-09-11 00:01:58 +02003685 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003686 IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__);
Zhu Yib481de92007-09-25 17:54:57 -07003687 return;
3688 }
3689
3690
Tomas Winklere1623442009-01-27 14:27:56 -08003691 IWL_DEBUG_ASSOC(priv, "Associated as %d to: %pM\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003692 priv->assoc_id, priv->active_rxon.bssid_addr);
Zhu Yib481de92007-09-25 17:54:57 -07003693
3694 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
3695 return;
3696
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003697 if (!priv->vif || !priv->is_open)
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003698 return;
Abhijeet Kolekar322a9812008-09-03 11:26:27 +08003699
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003700 iwl_scan_cancel_timeout(priv, 200);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08003701
Zhu Yib481de92007-09-25 17:54:57 -07003702 conf = ieee80211_get_hw_conf(priv->hw);
3703
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003704 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003705 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003706
Tomas Winkler28afaf92008-12-19 10:37:06 +08003707 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003708 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08003709 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
Zhu Yib481de92007-09-25 17:54:57 -07003710 sizeof(priv->rxon_timing), &priv->rxon_timing);
3711 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08003712 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07003713 "Attempting to continue.\n");
3714
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003715 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003716
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003717 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07003718
Tomas Winklere1623442009-01-27 14:27:56 -08003719 IWL_DEBUG_ASSOC(priv, "assoc id %d beacon interval %d\n",
Zhu Yib481de92007-09-25 17:54:57 -07003720 priv->assoc_id, priv->beacon_int);
3721
3722 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003723 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003724 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003725 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_PREAMBLE_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003726
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003727 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07003728 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003729 priv->staging_rxon.flags |= RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003730 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003731 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003732
Johannes Berg05c914f2008-09-11 00:01:58 +02003733 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003734 priv->staging_rxon.flags &= ~RXON_FLG_SHORT_SLOT_MSK;
Zhu Yib481de92007-09-25 17:54:57 -07003735
3736 }
3737
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003738 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003739
3740 switch (priv->iw_mode) {
Johannes Berg05c914f2008-09-11 00:01:58 +02003741 case NL80211_IFTYPE_STATION:
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003742 iwl3945_rate_scale_init(priv->hw, IWL_AP_ID);
Zhu Yib481de92007-09-25 17:54:57 -07003743 break;
3744
Johannes Berg05c914f2008-09-11 00:01:58 +02003745 case NL80211_IFTYPE_ADHOC:
Zhu Yib481de92007-09-25 17:54:57 -07003746
Abhijeet Kolekarce546fd2008-11-19 15:32:22 -08003747 priv->assoc_id = 1;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003748 iwl3945_add_station(priv, priv->bssid, 0, 0);
Zhu Yib481de92007-09-25 17:54:57 -07003749 iwl3945_sync_sta(priv, IWL_STA_ID,
Johannes Berg8318d782008-01-24 19:38:38 +01003750 (priv->band == IEEE80211_BAND_5GHZ) ?
Zhu Yib481de92007-09-25 17:54:57 -07003751 IWL_RATE_6M_PLCP : IWL_RATE_1M_PLCP,
3752 CMD_ASYNC);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003753 iwl3945_rate_scale_init(priv->hw, IWL_STA_ID);
3754 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003755
3756 break;
3757
3758 default:
Winkler, Tomas15b16872008-12-19 10:37:33 +08003759 IWL_ERR(priv, "%s Should not be called in %d mode\n",
Tomas Winkler3ac7f142008-07-21 02:40:14 +03003760 __func__, priv->iw_mode);
Zhu Yib481de92007-09-25 17:54:57 -07003761 break;
3762 }
3763
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003764 iwl3945_activate_qos(priv, 0);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08003765
Mohamed Abbas7878a5a2007-11-29 11:10:13 +08003766 /* we have just associated, don't start scan too early */
3767 priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08003768}
3769
Johannes Berge8975582008-10-09 12:18:51 +02003770static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003771
Zhu Yib481de92007-09-25 17:54:57 -07003772/*****************************************************************************
3773 *
3774 * mac80211 entry point functions
3775 *
3776 *****************************************************************************/
3777
Zhu Yi5a66926a2008-01-14 17:46:18 -08003778#define UCODE_READY_TIMEOUT (2 * HZ)
3779
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003780static int iwl3945_mac_start(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003781{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003782 struct iwl_priv *priv = hw->priv;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003783 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07003784
Tomas Winklere1623442009-01-27 14:27:56 -08003785 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003786
3787 /* we should be verifying the device is ready to be opened */
3788 mutex_lock(&priv->mutex);
3789
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003790 memset(&priv->staging_rxon, 0, sizeof(priv->staging_rxon));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003791 /* fetch ucode file from disk, alloc and copy to bus-master buffers ...
3792 * ucode filename and max sizes are card-specific. */
3793
3794 if (!priv->ucode_code.len) {
3795 ret = iwl3945_read_ucode(priv);
3796 if (ret) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003797 IWL_ERR(priv, "Could not read microcode: %d\n", ret);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003798 mutex_unlock(&priv->mutex);
3799 goto out_release_irq;
3800 }
3801 }
3802
Zhu Yie655b9f2008-01-24 02:19:38 -08003803 ret = __iwl3945_up(priv);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003804
Zhu Yib481de92007-09-25 17:54:57 -07003805 mutex_unlock(&priv->mutex);
Zhu Yi5a66926a2008-01-14 17:46:18 -08003806
Samuel Ortizc0af96a2009-01-21 18:27:54 +01003807 iwl_rfkill_set_hw_state(priv);
Adel Gadllah80fcc9e2008-07-01 17:49:50 +02003808
Zhu Yie655b9f2008-01-24 02:19:38 -08003809 if (ret)
3810 goto out_release_irq;
3811
Tomas Winklere1623442009-01-27 14:27:56 -08003812 IWL_DEBUG_INFO(priv, "Start UP work.\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003813
3814 if (test_bit(STATUS_IN_SUSPEND, &priv->status))
3815 return 0;
3816
Zhu Yi5a66926a2008-01-14 17:46:18 -08003817 /* Wait for START_ALIVE from ucode. Otherwise callbacks from
3818 * mac80211 will not be run successfully. */
3819 ret = wait_event_interruptible_timeout(priv->wait_command_queue,
3820 test_bit(STATUS_READY, &priv->status),
3821 UCODE_READY_TIMEOUT);
3822 if (!ret) {
3823 if (!test_bit(STATUS_READY, &priv->status)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08003824 IWL_ERR(priv,
3825 "Wait for START_ALIVE timeout after %dms.\n",
3826 jiffies_to_msecs(UCODE_READY_TIMEOUT));
Zhu Yi5a66926a2008-01-14 17:46:18 -08003827 ret = -ETIMEDOUT;
3828 goto out_release_irq;
3829 }
3830 }
3831
Helmut Schaa26635162009-01-15 09:38:44 +01003832 /* ucode is running and will send rfkill notifications,
3833 * no need to poll the killswitch state anymore */
3834 cancel_delayed_work(&priv->rfkill_poll);
3835
Zhu Yie655b9f2008-01-24 02:19:38 -08003836 priv->is_open = 1;
Tomas Winklere1623442009-01-27 14:27:56 -08003837 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003838 return 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003839
3840out_release_irq:
Zhu Yie655b9f2008-01-24 02:19:38 -08003841 priv->is_open = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08003842 IWL_DEBUG_MAC80211(priv, "leave - failed\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08003843 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07003844}
3845
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003846static void iwl3945_mac_stop(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07003847{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003848 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003849
Tomas Winklere1623442009-01-27 14:27:56 -08003850 IWL_DEBUG_MAC80211(priv, "enter\n");
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003851
Zhu Yie655b9f2008-01-24 02:19:38 -08003852 if (!priv->is_open) {
Tomas Winklere1623442009-01-27 14:27:56 -08003853 IWL_DEBUG_MAC80211(priv, "leave - skip\n");
Zhu Yie655b9f2008-01-24 02:19:38 -08003854 return;
3855 }
3856
Zhu Yib481de92007-09-25 17:54:57 -07003857 priv->is_open = 0;
Zhu Yi5a66926a2008-01-14 17:46:18 -08003858
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003859 if (iwl_is_ready_rf(priv)) {
Zhu Yie655b9f2008-01-24 02:19:38 -08003860 /* stop mac, cancel any scan request and clear
3861 * RXON_FILTER_ASSOC_MSK BIT
3862 */
Zhu Yi5a66926a2008-01-14 17:46:18 -08003863 mutex_lock(&priv->mutex);
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08003864 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003865 mutex_unlock(&priv->mutex);
Mohamed Abbasfde35712007-11-29 11:10:15 +08003866 }
3867
Zhu Yi5a66926a2008-01-14 17:46:18 -08003868 iwl3945_down(priv);
3869
3870 flush_workqueue(priv->workqueue);
Helmut Schaa26635162009-01-15 09:38:44 +01003871
3872 /* start polling the killswitch state again */
3873 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
3874 round_jiffies_relative(2 * HZ));
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08003875
Tomas Winklere1623442009-01-27 14:27:56 -08003876 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003877}
3878
Johannes Berge039fa42008-05-15 12:55:29 +02003879static int iwl3945_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07003880{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003881 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003882
Tomas Winklere1623442009-01-27 14:27:56 -08003883 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07003884
Tomas Winklere1623442009-01-27 14:27:56 -08003885 IWL_DEBUG_TX(priv, "dev->xmit(%d bytes) at rate 0x%02x\n", skb->len,
Johannes Berge039fa42008-05-15 12:55:29 +02003886 ieee80211_get_tx_rate(hw, IEEE80211_SKB_CB(skb))->bitrate);
Zhu Yib481de92007-09-25 17:54:57 -07003887
Johannes Berge039fa42008-05-15 12:55:29 +02003888 if (iwl3945_tx_skb(priv, skb))
Zhu Yib481de92007-09-25 17:54:57 -07003889 dev_kfree_skb_any(skb);
3890
Tomas Winklere1623442009-01-27 14:27:56 -08003891 IWL_DEBUG_MAC80211(priv, "leave\n");
Reinette Chatre637f8832009-01-19 15:30:32 -08003892 return NETDEV_TX_OK;
Zhu Yib481de92007-09-25 17:54:57 -07003893}
3894
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003895static int iwl3945_mac_add_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07003896 struct ieee80211_if_init_conf *conf)
3897{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003898 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07003899 unsigned long flags;
3900
Tomas Winklere1623442009-01-27 14:27:56 -08003901 IWL_DEBUG_MAC80211(priv, "enter: type %d\n", conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003902
Johannes Berg32bfd352007-12-19 01:31:26 +01003903 if (priv->vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08003904 IWL_DEBUG_MAC80211(priv, "leave - vif != NULL\n");
Tomas Winkler864792e2007-11-27 21:00:52 +02003905 return -EOPNOTSUPP;
Zhu Yib481de92007-09-25 17:54:57 -07003906 }
3907
3908 spin_lock_irqsave(&priv->lock, flags);
Johannes Berg32bfd352007-12-19 01:31:26 +01003909 priv->vif = conf->vif;
Zhu, Yi60294de2008-10-29 14:05:45 -07003910 priv->iw_mode = conf->type;
Zhu Yib481de92007-09-25 17:54:57 -07003911
3912 spin_unlock_irqrestore(&priv->lock, flags);
3913
3914 mutex_lock(&priv->mutex);
Tomas Winkler864792e2007-11-27 21:00:52 +02003915
3916 if (conf->mac_addr) {
Tomas Winklere1623442009-01-27 14:27:56 -08003917 IWL_DEBUG_MAC80211(priv, "Set: %pM\n", conf->mac_addr);
Tomas Winkler864792e2007-11-27 21:00:52 +02003918 memcpy(priv->mac_addr, conf->mac_addr, ETH_ALEN);
3919 }
3920
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003921 if (iwl_is_ready(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08003922 iwl3945_set_mode(priv, conf->type);
Zhu Yib481de92007-09-25 17:54:57 -07003923
Zhu Yib481de92007-09-25 17:54:57 -07003924 mutex_unlock(&priv->mutex);
3925
Tomas Winklere1623442009-01-27 14:27:56 -08003926 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07003927 return 0;
3928}
3929
3930/**
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003931 * iwl3945_mac_config - mac80211 config callback
Zhu Yib481de92007-09-25 17:54:57 -07003932 *
3933 * We ignore conf->flags & IEEE80211_CONF_SHORT_SLOT_TIME since it seems to
3934 * be set inappropriately and the driver currently sets the hardware up to
3935 * use it whenever needed.
3936 */
Johannes Berge8975582008-10-09 12:18:51 +02003937static int iwl3945_mac_config(struct ieee80211_hw *hw, u32 changed)
Zhu Yib481de92007-09-25 17:54:57 -07003938{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08003939 struct iwl_priv *priv = hw->priv;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08003940 const struct iwl_channel_info *ch_info;
Johannes Berge8975582008-10-09 12:18:51 +02003941 struct ieee80211_conf *conf = &hw->conf;
Zhu Yib481de92007-09-25 17:54:57 -07003942 unsigned long flags;
Zhu Yi76bb77e2007-11-22 10:53:22 +08003943 int ret = 0;
Zhu Yib481de92007-09-25 17:54:57 -07003944
3945 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08003946 IWL_DEBUG_MAC80211(priv, "enter to channel %d\n",
3947 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003948
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08003949 if (!iwl_is_ready(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003950 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003951 ret = -EIO;
3952 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003953 }
3954
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08003955 if (unlikely(!iwl3945_mod_params.disable_hw_scan &&
Zhu Yib481de92007-09-25 17:54:57 -07003956 test_bit(STATUS_SCANNING, &priv->status))) {
Tomas Winklere1623442009-01-27 14:27:56 -08003957 IWL_DEBUG_MAC80211(priv, "leave - scanning\n");
Zhu Yia0646472007-12-20 14:10:01 +08003958 set_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07003959 mutex_unlock(&priv->mutex);
Zhu Yia0646472007-12-20 14:10:01 +08003960 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07003961 }
3962
3963 spin_lock_irqsave(&priv->lock, flags);
3964
Samuel Ortize6148912009-01-23 13:45:15 -08003965 ch_info = iwl_get_channel_info(priv, conf->channel->band,
3966 conf->channel->hw_value);
Zhu Yib481de92007-09-25 17:54:57 -07003967 if (!is_channel_valid(ch_info)) {
Tomas Winklere1623442009-01-27 14:27:56 -08003968 IWL_DEBUG_SCAN(priv,
3969 "Channel %d [%d] is INVALID for this band.\n",
3970 conf->channel->hw_value, conf->channel->band);
3971 IWL_DEBUG_MAC80211(priv, "leave - invalid channel\n");
Zhu Yib481de92007-09-25 17:54:57 -07003972 spin_unlock_irqrestore(&priv->lock, flags);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003973 ret = -EINVAL;
3974 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003975 }
3976
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003977 iwl_set_rxon_channel(priv, conf->channel);
Zhu Yib481de92007-09-25 17:54:57 -07003978
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003979 iwl_set_flags_for_band(priv, conf->channel->band);
Zhu Yib481de92007-09-25 17:54:57 -07003980
3981 /* The list of supported rates and rate mask can be different
3982 * for each phymode; since the phymode may have changed, reset
3983 * the rate mask to what mac80211 lists */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08003984 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07003985
3986 spin_unlock_irqrestore(&priv->lock, flags);
3987
3988#ifdef IEEE80211_CONF_CHANNEL_SWITCH
3989 if (conf->flags & IEEE80211_CONF_CHANNEL_SWITCH) {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003990 iwl3945_hw_channel_switch(priv, conf->channel);
Zhu Yi76bb77e2007-11-22 10:53:22 +08003991 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07003992 }
3993#endif
3994
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08003995 iwl3945_radio_kill_sw(priv, !conf->radio_enabled);
Zhu Yib481de92007-09-25 17:54:57 -07003996
3997 if (!conf->radio_enabled) {
Tomas Winklere1623442009-01-27 14:27:56 -08003998 IWL_DEBUG_MAC80211(priv, "leave - radio disabled\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08003999 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004000 }
4001
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004002 if (iwl_is_rfkill(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004003 IWL_DEBUG_MAC80211(priv, "leave - RF kill\n");
Zhu Yi76bb77e2007-11-22 10:53:22 +08004004 ret = -EIO;
4005 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004006 }
4007
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004008 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004009
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004010 if (memcmp(&priv->active_rxon,
4011 &priv->staging_rxon, sizeof(priv->staging_rxon)))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004012 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004013 else
Tomas Winklere1623442009-01-27 14:27:56 -08004014 IWL_DEBUG_INFO(priv, "Not re-sending same RXON configuration\n");
Zhu Yib481de92007-09-25 17:54:57 -07004015
Tomas Winklere1623442009-01-27 14:27:56 -08004016 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004017
Zhu Yi76bb77e2007-11-22 10:53:22 +08004018out:
Zhu Yia0646472007-12-20 14:10:01 +08004019 clear_bit(STATUS_CONF_PENDING, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07004020 mutex_unlock(&priv->mutex);
Zhu Yi76bb77e2007-11-22 10:53:22 +08004021 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004022}
4023
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004024static void iwl3945_config_ap(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004025{
4026 int rc = 0;
4027
Maarten Lankhorstd986bcd2008-01-23 10:15:16 -08004028 if (test_bit(STATUS_EXIT_PENDING, &priv->status))
Zhu Yib481de92007-09-25 17:54:57 -07004029 return;
4030
4031 /* The following should be done only at AP bring up */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004032 if (!(iwl_is_associated(priv))) {
Zhu Yib481de92007-09-25 17:54:57 -07004033
4034 /* RXON - unassoc (to set timing command) */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004035 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004036 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004037
4038 /* RXON Timing */
Tomas Winkler28afaf92008-12-19 10:37:06 +08004039 memset(&priv->rxon_timing, 0, sizeof(struct iwl_rxon_time_cmd));
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004040 iwl3945_setup_rxon_timing(priv);
Samuel Ortiz518099a2009-01-19 15:30:27 -08004041 rc = iwl_send_cmd_pdu(priv, REPLY_RXON_TIMING,
4042 sizeof(priv->rxon_timing),
4043 &priv->rxon_timing);
Zhu Yib481de92007-09-25 17:54:57 -07004044 if (rc)
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004045 IWL_WARN(priv, "REPLY_RXON_TIMING failed - "
Zhu Yib481de92007-09-25 17:54:57 -07004046 "Attempting to continue.\n");
4047
4048 /* FIXME: what should be the assoc_id for AP? */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004049 priv->staging_rxon.assoc_id = cpu_to_le16(priv->assoc_id);
Zhu Yib481de92007-09-25 17:54:57 -07004050 if (priv->assoc_capability & WLAN_CAPABILITY_SHORT_PREAMBLE)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004051 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004052 RXON_FLG_SHORT_PREAMBLE_MSK;
4053 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004054 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004055 ~RXON_FLG_SHORT_PREAMBLE_MSK;
4056
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004057 if (priv->staging_rxon.flags & RXON_FLG_BAND_24G_MSK) {
Zhu Yib481de92007-09-25 17:54:57 -07004058 if (priv->assoc_capability &
4059 WLAN_CAPABILITY_SHORT_SLOT_TIME)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004060 priv->staging_rxon.flags |=
Zhu Yib481de92007-09-25 17:54:57 -07004061 RXON_FLG_SHORT_SLOT_MSK;
4062 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004063 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004064 ~RXON_FLG_SHORT_SLOT_MSK;
4065
Johannes Berg05c914f2008-09-11 00:01:58 +02004066 if (priv->iw_mode == NL80211_IFTYPE_ADHOC)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004067 priv->staging_rxon.flags &=
Zhu Yib481de92007-09-25 17:54:57 -07004068 ~RXON_FLG_SHORT_SLOT_MSK;
4069 }
4070 /* restore RXON assoc */
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004071 priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004072 iwl3945_commit_rxon(priv);
Kolekar, Abhijeetb5323d32008-12-19 10:37:22 +08004073 iwl3945_add_station(priv, iwl_bcast_addr, 0, 0);
Zhu Yi556f8db2007-09-27 11:27:33 +08004074 }
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004075 iwl3945_send_beacon_cmd(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004076
4077 /* FIXME - we need to add code here to detect a totally new
4078 * configuration, reset the AP, unassoc, rxon timing, assoc,
4079 * clear sta table, add BCAST sta... */
4080}
4081
Johannes Berg32bfd352007-12-19 01:31:26 +01004082static int iwl3945_mac_config_interface(struct ieee80211_hw *hw,
4083 struct ieee80211_vif *vif,
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004084 struct ieee80211_if_conf *conf)
Zhu Yib481de92007-09-25 17:54:57 -07004085{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004086 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004087 int rc;
4088
4089 if (conf == NULL)
4090 return -EIO;
4091
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004092 if (priv->vif != vif) {
Tomas Winklere1623442009-01-27 14:27:56 -08004093 IWL_DEBUG_MAC80211(priv, "leave - priv->vif != vif\n");
Emmanuel Grumbachb716bb92008-03-04 18:09:32 -08004094 return 0;
4095 }
4096
Johannes Berg9d139c82008-07-09 14:40:37 +02004097 /* handle this temporarily here */
Johannes Berg05c914f2008-09-11 00:01:58 +02004098 if (priv->iw_mode == NL80211_IFTYPE_ADHOC &&
Johannes Berg9d139c82008-07-09 14:40:37 +02004099 conf->changed & IEEE80211_IFCC_BEACON) {
4100 struct sk_buff *beacon = ieee80211_beacon_get(hw, vif);
4101 if (!beacon)
4102 return -ENOMEM;
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004103 mutex_lock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004104 rc = iwl3945_mac_beacon_update(hw, beacon);
Mohamed Abbas9bdf5ec2008-11-07 09:58:35 -08004105 mutex_unlock(&priv->mutex);
Johannes Berg9d139c82008-07-09 14:40:37 +02004106 if (rc)
4107 return rc;
4108 }
4109
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004110 if (!iwl_is_alive(priv))
Zhu Yi5a66926a2008-01-14 17:46:18 -08004111 return -EAGAIN;
4112
Zhu Yib481de92007-09-25 17:54:57 -07004113 mutex_lock(&priv->mutex);
4114
Zhu Yib481de92007-09-25 17:54:57 -07004115 if (conf->bssid)
Tomas Winklere1623442009-01-27 14:27:56 -08004116 IWL_DEBUG_MAC80211(priv, "bssid: %pM\n", conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004117
Johannes Berg4150c572007-09-17 01:29:23 -04004118/*
4119 * very dubious code was here; the probe filtering flag is never set:
4120 *
Zhu Yib481de92007-09-25 17:54:57 -07004121 if (unlikely(test_bit(STATUS_SCANNING, &priv->status)) &&
4122 !(priv->hw->flags & IEEE80211_HW_NO_PROBE_FILTERING)) {
Johannes Berg4150c572007-09-17 01:29:23 -04004123 */
Zhu Yib481de92007-09-25 17:54:57 -07004124
Johannes Berg05c914f2008-09-11 00:01:58 +02004125 if (priv->iw_mode == NL80211_IFTYPE_AP) {
Zhu Yib481de92007-09-25 17:54:57 -07004126 if (!conf->bssid) {
4127 conf->bssid = priv->mac_addr;
4128 memcpy(priv->bssid, priv->mac_addr, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08004129 IWL_DEBUG_MAC80211(priv, "bssid was set to: %pM\n",
Johannes Berge1749612008-10-27 15:59:26 -07004130 conf->bssid);
Zhu Yib481de92007-09-25 17:54:57 -07004131 }
4132 if (priv->ibss_beacon)
4133 dev_kfree_skb(priv->ibss_beacon);
4134
Johannes Berg9d139c82008-07-09 14:40:37 +02004135 priv->ibss_beacon = ieee80211_beacon_get(hw, vif);
Zhu Yib481de92007-09-25 17:54:57 -07004136 }
4137
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004138 if (iwl_is_rfkill(priv))
Mohamed Abbasfde35712007-11-29 11:10:15 +08004139 goto done;
4140
Zhu Yib481de92007-09-25 17:54:57 -07004141 if (conf->bssid && !is_zero_ether_addr(conf->bssid) &&
4142 !is_multicast_ether_addr(conf->bssid)) {
4143 /* If there is currently a HW scan going on in the background
4144 * then we need to cancel it else the RXON below will fail. */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004145 if (iwl_scan_cancel_timeout(priv, 100)) {
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004146 IWL_WARN(priv, "Aborted scan still in progress "
Zhu Yib481de92007-09-25 17:54:57 -07004147 "after 100ms\n");
Tomas Winklere1623442009-01-27 14:27:56 -08004148 IWL_DEBUG_MAC80211(priv, "leaving:scan abort failed\n");
Zhu Yib481de92007-09-25 17:54:57 -07004149 mutex_unlock(&priv->mutex);
4150 return -EAGAIN;
4151 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004152 memcpy(priv->staging_rxon.bssid_addr, conf->bssid, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004153
4154 /* TODO: Audit driver for usage of these members and see
4155 * if mac80211 deprecates them (priv->bssid looks like it
4156 * shouldn't be there, but I haven't scanned the IBSS code
4157 * to verify) - jpk */
4158 memcpy(priv->bssid, conf->bssid, ETH_ALEN);
4159
Johannes Berg05c914f2008-09-11 00:01:58 +02004160 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004161 iwl3945_config_ap(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004162 else {
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004163 rc = iwl3945_commit_rxon(priv);
Johannes Berg05c914f2008-09-11 00:01:58 +02004164 if ((priv->iw_mode == NL80211_IFTYPE_STATION) && rc)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004165 iwl3945_add_station(priv,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004166 priv->active_rxon.bssid_addr, 1, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004167 }
4168
4169 } else {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004170 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004171 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004172 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004173 }
4174
Mohamed Abbasfde35712007-11-29 11:10:15 +08004175 done:
Tomas Winklere1623442009-01-27 14:27:56 -08004176 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004177 mutex_unlock(&priv->mutex);
4178
4179 return 0;
4180}
4181
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004182static void iwl3945_mac_remove_interface(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004183 struct ieee80211_if_init_conf *conf)
4184{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004185 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004186
Tomas Winklere1623442009-01-27 14:27:56 -08004187 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004188
4189 mutex_lock(&priv->mutex);
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08004190
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004191 if (iwl_is_ready_rf(priv)) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004192 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004193 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Mohamed Abbasfde35712007-11-29 11:10:15 +08004194 iwl3945_commit_rxon(priv);
4195 }
Johannes Berg32bfd352007-12-19 01:31:26 +01004196 if (priv->vif == conf->vif) {
4197 priv->vif = NULL;
Zhu Yib481de92007-09-25 17:54:57 -07004198 memset(priv->bssid, 0, ETH_ALEN);
Zhu Yib481de92007-09-25 17:54:57 -07004199 }
4200 mutex_unlock(&priv->mutex);
4201
Tomas Winklere1623442009-01-27 14:27:56 -08004202 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004203}
4204
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004205#define IWL_DELAY_NEXT_SCAN_AFTER_ASSOC (HZ*6)
4206
4207static void iwl3945_bss_info_changed(struct ieee80211_hw *hw,
4208 struct ieee80211_vif *vif,
4209 struct ieee80211_bss_conf *bss_conf,
4210 u32 changes)
4211{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004212 struct iwl_priv *priv = hw->priv;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004213
Tomas Winklere1623442009-01-27 14:27:56 -08004214 IWL_DEBUG_MAC80211(priv, "changes = 0x%X\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004215
4216 if (changes & BSS_CHANGED_ERP_PREAMBLE) {
Tomas Winklere1623442009-01-27 14:27:56 -08004217 IWL_DEBUG_MAC80211(priv, "ERP_PREAMBLE %d\n",
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004218 bss_conf->use_short_preamble);
4219 if (bss_conf->use_short_preamble)
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004220 priv->staging_rxon.flags |= RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004221 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004222 priv->staging_rxon.flags &=
4223 ~RXON_FLG_SHORT_PREAMBLE_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004224 }
4225
4226 if (changes & BSS_CHANGED_ERP_CTS_PROT) {
Tomas Winklere1623442009-01-27 14:27:56 -08004227 IWL_DEBUG_MAC80211(priv, "ERP_CTS %d\n",
4228 bss_conf->use_cts_prot);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004229 if (bss_conf->use_cts_prot && (priv->band != IEEE80211_BAND_5GHZ))
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004230 priv->staging_rxon.flags |= RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004231 else
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004232 priv->staging_rxon.flags &= ~RXON_FLG_TGG_PROTECT_MSK;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004233 }
4234
4235 if (changes & BSS_CHANGED_ASSOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004236 IWL_DEBUG_MAC80211(priv, "ASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004237 /* This should never happen as this function should
4238 * never be called from interrupt context. */
4239 if (WARN_ON_ONCE(in_interrupt()))
4240 return;
4241 if (bss_conf->assoc) {
4242 priv->assoc_id = bss_conf->aid;
4243 priv->beacon_int = bss_conf->beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004244 priv->timestamp = bss_conf->timestamp;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004245 priv->assoc_capability = bss_conf->assoc_capability;
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08004246 priv->power_data.dtim_period = bss_conf->dtim_period;
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004247 priv->next_scan_jiffies = jiffies +
4248 IWL_DELAY_NEXT_SCAN_AFTER_ASSOC;
4249 mutex_lock(&priv->mutex);
4250 iwl3945_post_associate(priv);
4251 mutex_unlock(&priv->mutex);
4252 } else {
4253 priv->assoc_id = 0;
Tomas Winklere1623442009-01-27 14:27:56 -08004254 IWL_DEBUG_MAC80211(priv,
4255 "DISASSOC %d\n", bss_conf->assoc);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004256 }
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004257 } else if (changes && iwl_is_associated(priv) && priv->assoc_id) {
Tomas Winklere1623442009-01-27 14:27:56 -08004258 IWL_DEBUG_MAC80211(priv,
4259 "Associated Changes %d\n", changes);
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08004260 iwl3945_send_rxon_assoc(priv);
4261 }
4262
4263}
4264
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004265static int iwl3945_mac_set_key(struct ieee80211_hw *hw, enum set_key_cmd cmd,
Johannes Bergdc822b52008-12-29 12:55:09 +01004266 struct ieee80211_vif *vif,
4267 struct ieee80211_sta *sta,
4268 struct ieee80211_key_conf *key)
Zhu Yib481de92007-09-25 17:54:57 -07004269{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004270 struct iwl_priv *priv = hw->priv;
Johannes Bergdc822b52008-12-29 12:55:09 +01004271 const u8 *addr;
Winkler, Tomas42986792009-01-19 15:30:22 -08004272 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004273 u8 sta_id;
4274
Tomas Winklere1623442009-01-27 14:27:56 -08004275 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004276
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08004277 if (iwl3945_mod_params.sw_crypto) {
Tomas Winklere1623442009-01-27 14:27:56 -08004278 IWL_DEBUG_MAC80211(priv, "leave - hwcrypto disabled\n");
Zhu Yib481de92007-09-25 17:54:57 -07004279 return -EOPNOTSUPP;
4280 }
4281
Winkler, Tomas42986792009-01-19 15:30:22 -08004282 addr = sta ? sta->addr : iwl_bcast_addr;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004283 sta_id = iwl3945_hw_find_station(priv, addr);
Zhu Yib481de92007-09-25 17:54:57 -07004284 if (sta_id == IWL_INVALID_STATION) {
Tomas Winklere1623442009-01-27 14:27:56 -08004285 IWL_DEBUG_MAC80211(priv, "leave - %pM not in station map.\n",
Johannes Berge1749612008-10-27 15:59:26 -07004286 addr);
Zhu Yib481de92007-09-25 17:54:57 -07004287 return -EINVAL;
4288 }
4289
4290 mutex_lock(&priv->mutex);
4291
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004292 iwl_scan_cancel_timeout(priv, 100);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004293
Zhu Yib481de92007-09-25 17:54:57 -07004294 switch (cmd) {
4295 case SET_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004296 ret = iwl3945_update_sta_key_info(priv, key, sta_id);
4297 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004298 iwl_set_rxon_hwcrypto(priv, 1);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004299 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004300 key->hw_key_idx = sta_id;
Tomas Winklere1623442009-01-27 14:27:56 -08004301 IWL_DEBUG_MAC80211(priv,
4302 "set_key success, using hwcrypto\n");
Zhu Yib481de92007-09-25 17:54:57 -07004303 key->flags |= IEEE80211_KEY_FLAG_GENERATE_IV;
4304 }
4305 break;
4306 case DISABLE_KEY:
Winkler, Tomas42986792009-01-19 15:30:22 -08004307 ret = iwl3945_clear_sta_key_info(priv, sta_id);
4308 if (!ret) {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004309 iwl_set_rxon_hwcrypto(priv, 0);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004310 iwl3945_commit_rxon(priv);
Tomas Winklere1623442009-01-27 14:27:56 -08004311 IWL_DEBUG_MAC80211(priv, "disable hwcrypto key\n");
Zhu Yib481de92007-09-25 17:54:57 -07004312 }
4313 break;
4314 default:
Winkler, Tomas42986792009-01-19 15:30:22 -08004315 ret = -EINVAL;
Zhu Yib481de92007-09-25 17:54:57 -07004316 }
4317
Tomas Winklere1623442009-01-27 14:27:56 -08004318 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004319 mutex_unlock(&priv->mutex);
4320
Winkler, Tomas42986792009-01-19 15:30:22 -08004321 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004322}
4323
Johannes Berge100bb62008-04-30 18:51:21 +02004324static int iwl3945_mac_conf_tx(struct ieee80211_hw *hw, u16 queue,
Zhu Yib481de92007-09-25 17:54:57 -07004325 const struct ieee80211_tx_queue_params *params)
4326{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004327 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004328 unsigned long flags;
4329 int q;
Zhu Yib481de92007-09-25 17:54:57 -07004330
Tomas Winklere1623442009-01-27 14:27:56 -08004331 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004332
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004333 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004334 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004335 return -EIO;
4336 }
4337
4338 if (queue >= AC_NUM) {
Tomas Winklere1623442009-01-27 14:27:56 -08004339 IWL_DEBUG_MAC80211(priv, "leave - queue >= AC_NUM %d\n", queue);
Zhu Yib481de92007-09-25 17:54:57 -07004340 return 0;
4341 }
4342
Zhu Yib481de92007-09-25 17:54:57 -07004343 q = AC_NUM - 1 - queue;
4344
4345 spin_lock_irqsave(&priv->lock, flags);
4346
4347 priv->qos_data.def_qos_parm.ac[q].cw_min = cpu_to_le16(params->cw_min);
4348 priv->qos_data.def_qos_parm.ac[q].cw_max = cpu_to_le16(params->cw_max);
4349 priv->qos_data.def_qos_parm.ac[q].aifsn = params->aifs;
4350 priv->qos_data.def_qos_parm.ac[q].edca_txop =
Johannes Berg3330d7b2008-02-10 16:49:38 +01004351 cpu_to_le16((params->txop * 32));
Zhu Yib481de92007-09-25 17:54:57 -07004352
4353 priv->qos_data.def_qos_parm.ac[q].reserved1 = 0;
4354 priv->qos_data.qos_active = 1;
4355
4356 spin_unlock_irqrestore(&priv->lock, flags);
4357
4358 mutex_lock(&priv->mutex);
Johannes Berg05c914f2008-09-11 00:01:58 +02004359 if (priv->iw_mode == NL80211_IFTYPE_AP)
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004360 iwl3945_activate_qos(priv, 1);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004361 else if (priv->assoc_id && iwl_is_associated(priv))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004362 iwl3945_activate_qos(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004363
4364 mutex_unlock(&priv->mutex);
4365
Tomas Winklere1623442009-01-27 14:27:56 -08004366 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004367 return 0;
4368}
4369
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004370static int iwl3945_mac_get_tx_stats(struct ieee80211_hw *hw,
Zhu Yib481de92007-09-25 17:54:57 -07004371 struct ieee80211_tx_queue_stats *stats)
4372{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004373 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004374 int i, avail;
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004375 struct iwl_tx_queue *txq;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004376 struct iwl_queue *q;
Zhu Yib481de92007-09-25 17:54:57 -07004377 unsigned long flags;
4378
Tomas Winklere1623442009-01-27 14:27:56 -08004379 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004380
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004381 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004382 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004383 return -EIO;
4384 }
4385
4386 spin_lock_irqsave(&priv->lock, flags);
4387
4388 for (i = 0; i < AC_NUM; i++) {
Samuel Ortiz188cf6c2008-12-22 11:31:16 +08004389 txq = &priv->txq[i];
Zhu Yib481de92007-09-25 17:54:57 -07004390 q = &txq->q;
Samuel Ortizd20b3c62008-12-19 10:37:15 +08004391 avail = iwl_queue_space(q);
Zhu Yib481de92007-09-25 17:54:57 -07004392
Johannes Berg57ffc582008-04-29 17:18:59 +02004393 stats[i].len = q->n_window - avail;
4394 stats[i].limit = q->n_window - q->high_mark;
4395 stats[i].count = q->n_window;
Zhu Yib481de92007-09-25 17:54:57 -07004396
4397 }
4398 spin_unlock_irqrestore(&priv->lock, flags);
4399
Tomas Winklere1623442009-01-27 14:27:56 -08004400 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004401
4402 return 0;
4403}
4404
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004405static void iwl3945_mac_reset_tsf(struct ieee80211_hw *hw)
Zhu Yib481de92007-09-25 17:54:57 -07004406{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004407 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004408 unsigned long flags;
4409
4410 mutex_lock(&priv->mutex);
Tomas Winklere1623442009-01-27 14:27:56 -08004411 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004412
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004413 iwl_reset_qos(priv);
Ron Rindjunsky292ae172008-02-06 11:20:39 -08004414
Zhu Yib481de92007-09-25 17:54:57 -07004415 spin_lock_irqsave(&priv->lock, flags);
4416 priv->assoc_id = 0;
4417 priv->assoc_capability = 0;
Zhu Yib481de92007-09-25 17:54:57 -07004418
4419 /* new association get rid of ibss beacon skb */
4420 if (priv->ibss_beacon)
4421 dev_kfree_skb(priv->ibss_beacon);
4422
4423 priv->ibss_beacon = NULL;
4424
4425 priv->beacon_int = priv->hw->conf.beacon_int;
Tomas Winkler28afaf92008-12-19 10:37:06 +08004426 priv->timestamp = 0;
Johannes Berg05c914f2008-09-11 00:01:58 +02004427 if ((priv->iw_mode == NL80211_IFTYPE_STATION))
Zhu Yib481de92007-09-25 17:54:57 -07004428 priv->beacon_int = 0;
4429
4430 spin_unlock_irqrestore(&priv->lock, flags);
4431
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004432 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004433 IWL_DEBUG_MAC80211(priv, "leave - not ready\n");
Mohamed Abbasfde35712007-11-29 11:10:15 +08004434 mutex_unlock(&priv->mutex);
4435 return;
4436 }
4437
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004438 /* we are restarting association process
4439 * clear RXON_FILTER_ASSOC_MSK bit
4440 */
Johannes Berg05c914f2008-09-11 00:01:58 +02004441 if (priv->iw_mode != NL80211_IFTYPE_AP) {
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004442 iwl_scan_cancel_timeout(priv, 100);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004443 priv->staging_rxon.filter_flags &= ~RXON_FILTER_ASSOC_MSK;
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004444 iwl3945_commit_rxon(priv);
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004445 }
4446
Zhu Yib481de92007-09-25 17:54:57 -07004447 /* Per mac80211.h: This is only used in IBSS mode... */
Johannes Berg05c914f2008-09-11 00:01:58 +02004448 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Mohamed Abbas15e869d2007-10-25 17:15:46 +08004449
Tomas Winklere1623442009-01-27 14:27:56 -08004450 IWL_DEBUG_MAC80211(priv, "leave - not in IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004451 mutex_unlock(&priv->mutex);
4452 return;
4453 }
4454
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004455 iwl_set_rate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004456
4457 mutex_unlock(&priv->mutex);
4458
Tomas Winklere1623442009-01-27 14:27:56 -08004459 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004460
4461}
4462
Johannes Berge039fa42008-05-15 12:55:29 +02004463static int iwl3945_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb)
Zhu Yib481de92007-09-25 17:54:57 -07004464{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004465 struct iwl_priv *priv = hw->priv;
Zhu Yib481de92007-09-25 17:54:57 -07004466 unsigned long flags;
4467
Tomas Winklere1623442009-01-27 14:27:56 -08004468 IWL_DEBUG_MAC80211(priv, "enter\n");
Zhu Yib481de92007-09-25 17:54:57 -07004469
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004470 if (!iwl_is_ready_rf(priv)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004471 IWL_DEBUG_MAC80211(priv, "leave - RF not ready\n");
Zhu Yib481de92007-09-25 17:54:57 -07004472 return -EIO;
4473 }
4474
Johannes Berg05c914f2008-09-11 00:01:58 +02004475 if (priv->iw_mode != NL80211_IFTYPE_ADHOC) {
Tomas Winklere1623442009-01-27 14:27:56 -08004476 IWL_DEBUG_MAC80211(priv, "leave - not IBSS\n");
Zhu Yib481de92007-09-25 17:54:57 -07004477 return -EIO;
4478 }
4479
4480 spin_lock_irqsave(&priv->lock, flags);
4481
4482 if (priv->ibss_beacon)
4483 dev_kfree_skb(priv->ibss_beacon);
4484
4485 priv->ibss_beacon = skb;
4486
4487 priv->assoc_id = 0;
4488
Tomas Winklere1623442009-01-27 14:27:56 -08004489 IWL_DEBUG_MAC80211(priv, "leave\n");
Zhu Yib481de92007-09-25 17:54:57 -07004490 spin_unlock_irqrestore(&priv->lock, flags);
4491
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004492 iwl_reset_qos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004493
Abhijeet Kolekardc4b1e72008-09-03 11:26:30 +08004494 iwl3945_post_associate(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004495
Zhu Yib481de92007-09-25 17:54:57 -07004496
4497 return 0;
4498}
4499
4500/*****************************************************************************
4501 *
4502 * sysfs attributes
4503 *
4504 *****************************************************************************/
4505
Samuel Ortizd08853a2009-01-23 13:45:17 -08004506#ifdef CONFIG_IWLWIFI_DEBUG
Zhu Yib481de92007-09-25 17:54:57 -07004507
4508/*
4509 * The following adds a new attribute to the sysfs representation
4510 * of this device driver (i.e. a new file in /sys/bus/pci/drivers/iwl/)
4511 * used for controlling the debug level.
4512 *
4513 * See the level definitions in iwl for details.
4514 */
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004515static ssize_t show_debug_level(struct device *d,
4516 struct device_attribute *attr, char *buf)
Zhu Yib481de92007-09-25 17:54:57 -07004517{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004518 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004519
4520 return sprintf(buf, "0x%08X\n", priv->debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004521}
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004522static ssize_t store_debug_level(struct device *d,
4523 struct device_attribute *attr,
Zhu Yib481de92007-09-25 17:54:57 -07004524 const char *buf, size_t count)
4525{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004526 struct iwl_priv *priv = d->driver_data;
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004527 unsigned long val;
4528 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07004529
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004530 ret = strict_strtoul(buf, 0, &val);
4531 if (ret)
Tomas Winkler978785a2008-12-19 10:37:31 +08004532 IWL_INFO(priv, "%s is not in hex or decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004533 else
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004534 priv->debug_level = val;
Zhu Yib481de92007-09-25 17:54:57 -07004535
4536 return strnlen(buf, count);
4537}
4538
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08004539static DEVICE_ATTR(debug_level, S_IWUSR | S_IRUGO,
4540 show_debug_level, store_debug_level);
Zhu Yib481de92007-09-25 17:54:57 -07004541
Samuel Ortizd08853a2009-01-23 13:45:17 -08004542#endif /* CONFIG_IWLWIFI_DEBUG */
Zhu Yib481de92007-09-25 17:54:57 -07004543
Zhu Yib481de92007-09-25 17:54:57 -07004544static ssize_t show_temperature(struct device *d,
4545 struct device_attribute *attr, char *buf)
4546{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004547 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004548
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004549 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004550 return -EAGAIN;
4551
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004552 return sprintf(buf, "%d\n", iwl3945_hw_get_temperature(priv));
Zhu Yib481de92007-09-25 17:54:57 -07004553}
4554
4555static DEVICE_ATTR(temperature, S_IRUGO, show_temperature, NULL);
4556
Zhu Yib481de92007-09-25 17:54:57 -07004557static ssize_t show_tx_power(struct device *d,
4558 struct device_attribute *attr, char *buf)
4559{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004560 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08004561 return sprintf(buf, "%d\n", priv->tx_power_user_lmt);
Zhu Yib481de92007-09-25 17:54:57 -07004562}
4563
4564static ssize_t store_tx_power(struct device *d,
4565 struct device_attribute *attr,
4566 const char *buf, size_t count)
4567{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004568 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004569 char *p = (char *)buf;
4570 u32 val;
4571
4572 val = simple_strtoul(p, &p, 10);
4573 if (p == buf)
Tomas Winkler978785a2008-12-19 10:37:31 +08004574 IWL_INFO(priv, ": %s is not in decimal form.\n", buf);
Zhu Yib481de92007-09-25 17:54:57 -07004575 else
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004576 iwl3945_hw_reg_set_txpower(priv, val);
Zhu Yib481de92007-09-25 17:54:57 -07004577
4578 return count;
4579}
4580
4581static DEVICE_ATTR(tx_power, S_IWUSR | S_IRUGO, show_tx_power, store_tx_power);
4582
4583static ssize_t show_flags(struct device *d,
4584 struct device_attribute *attr, char *buf)
4585{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004586 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004587
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004588 return sprintf(buf, "0x%04X\n", priv->active_rxon.flags);
Zhu Yib481de92007-09-25 17:54:57 -07004589}
4590
4591static ssize_t store_flags(struct device *d,
4592 struct device_attribute *attr,
4593 const char *buf, size_t count)
4594{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004595 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004596 u32 flags = simple_strtoul(buf, NULL, 0);
4597
4598 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004599 if (le32_to_cpu(priv->staging_rxon.flags) != flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004600 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004601 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004602 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004603 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004604 IWL_DEBUG_INFO(priv, "Committing rxon.flags = 0x%04X\n",
Zhu Yib481de92007-09-25 17:54:57 -07004605 flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004606 priv->staging_rxon.flags = cpu_to_le32(flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004607 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004608 }
4609 }
4610 mutex_unlock(&priv->mutex);
4611
4612 return count;
4613}
4614
4615static DEVICE_ATTR(flags, S_IWUSR | S_IRUGO, show_flags, store_flags);
4616
4617static ssize_t show_filter_flags(struct device *d,
4618 struct device_attribute *attr, char *buf)
4619{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004620 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004621
4622 return sprintf(buf, "0x%04X\n",
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004623 le32_to_cpu(priv->active_rxon.filter_flags));
Zhu Yib481de92007-09-25 17:54:57 -07004624}
4625
4626static ssize_t store_filter_flags(struct device *d,
4627 struct device_attribute *attr,
4628 const char *buf, size_t count)
4629{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004630 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Zhu Yib481de92007-09-25 17:54:57 -07004631 u32 filter_flags = simple_strtoul(buf, NULL, 0);
4632
4633 mutex_lock(&priv->mutex);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004634 if (le32_to_cpu(priv->staging_rxon.filter_flags) != filter_flags) {
Zhu Yib481de92007-09-25 17:54:57 -07004635 /* Cancel any currently running scans... */
Winkler, Tomasaf0053d2009-01-19 15:30:23 -08004636 if (iwl_scan_cancel_timeout(priv, 100))
Winkler, Tomas39aadf82008-12-19 10:37:32 +08004637 IWL_WARN(priv, "Could not cancel scan.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004638 else {
Tomas Winklere1623442009-01-27 14:27:56 -08004639 IWL_DEBUG_INFO(priv, "Committing rxon.filter_flags = "
Zhu Yib481de92007-09-25 17:54:57 -07004640 "0x%04X\n", filter_flags);
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004641 priv->staging_rxon.filter_flags =
Zhu Yib481de92007-09-25 17:54:57 -07004642 cpu_to_le32(filter_flags);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004643 iwl3945_commit_rxon(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004644 }
4645 }
4646 mutex_unlock(&priv->mutex);
4647
4648 return count;
4649}
4650
4651static DEVICE_ATTR(filter_flags, S_IWUSR | S_IRUGO, show_filter_flags,
4652 store_filter_flags);
4653
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004654#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07004655
4656static ssize_t show_measurement(struct device *d,
4657 struct device_attribute *attr, char *buf)
4658{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004659 struct iwl_priv *priv = dev_get_drvdata(d);
Tomas Winkler600c0e12008-12-19 10:37:04 +08004660 struct iwl_spectrum_notification measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004661 u32 size = sizeof(measure_report), len = 0, ofs = 0;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03004662 u8 *data = (u8 *)&measure_report;
Zhu Yib481de92007-09-25 17:54:57 -07004663 unsigned long flags;
4664
4665 spin_lock_irqsave(&priv->lock, flags);
4666 if (!(priv->measurement_status & MEASUREMENT_READY)) {
4667 spin_unlock_irqrestore(&priv->lock, flags);
4668 return 0;
4669 }
4670 memcpy(&measure_report, &priv->measure_report, size);
4671 priv->measurement_status = 0;
4672 spin_unlock_irqrestore(&priv->lock, flags);
4673
4674 while (size && (PAGE_SIZE - len)) {
4675 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4676 PAGE_SIZE - len, 1);
4677 len = strlen(buf);
4678 if (PAGE_SIZE - len)
4679 buf[len++] = '\n';
4680
4681 ofs += 16;
4682 size -= min(size, 16U);
4683 }
4684
4685 return len;
4686}
4687
4688static ssize_t store_measurement(struct device *d,
4689 struct device_attribute *attr,
4690 const char *buf, size_t count)
4691{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004692 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004693 struct ieee80211_measurement_params params = {
Samuel Ortiz8ccde882009-01-27 14:27:52 -08004694 .channel = le16_to_cpu(priv->active_rxon.channel),
Zhu Yib481de92007-09-25 17:54:57 -07004695 .start_time = cpu_to_le64(priv->last_tsf),
4696 .duration = cpu_to_le16(1),
4697 };
4698 u8 type = IWL_MEASURE_BASIC;
4699 u8 buffer[32];
4700 u8 channel;
4701
4702 if (count) {
4703 char *p = buffer;
4704 strncpy(buffer, buf, min(sizeof(buffer), count));
4705 channel = simple_strtoul(p, NULL, 0);
4706 if (channel)
4707 params.channel = channel;
4708
4709 p = buffer;
4710 while (*p && *p != ' ')
4711 p++;
4712 if (*p)
4713 type = simple_strtoul(p + 1, NULL, 0);
4714 }
4715
Tomas Winklere1623442009-01-27 14:27:56 -08004716 IWL_DEBUG_INFO(priv, "Invoking measurement of type %d on "
Zhu Yib481de92007-09-25 17:54:57 -07004717 "channel %d (for '%s')\n", type, params.channel, buf);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004718 iwl3945_get_measurement(priv, &params, type);
Zhu Yib481de92007-09-25 17:54:57 -07004719
4720 return count;
4721}
4722
4723static DEVICE_ATTR(measurement, S_IRUSR | S_IWUSR,
4724 show_measurement, store_measurement);
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08004725#endif /* CONFIG_IWL3945_SPECTRUM_MEASUREMENT */
Zhu Yib481de92007-09-25 17:54:57 -07004726
Zhu Yib481de92007-09-25 17:54:57 -07004727static ssize_t store_retry_rate(struct device *d,
4728 struct device_attribute *attr,
4729 const char *buf, size_t count)
4730{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004731 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004732
4733 priv->retry_rate = simple_strtoul(buf, NULL, 0);
4734 if (priv->retry_rate <= 0)
4735 priv->retry_rate = 1;
4736
4737 return count;
4738}
4739
4740static ssize_t show_retry_rate(struct device *d,
4741 struct device_attribute *attr, char *buf)
4742{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004743 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004744 return sprintf(buf, "%d", priv->retry_rate);
4745}
4746
4747static DEVICE_ATTR(retry_rate, S_IWUSR | S_IRUSR, show_retry_rate,
4748 store_retry_rate);
4749
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004750
Zhu Yib481de92007-09-25 17:54:57 -07004751static ssize_t store_power_level(struct device *d,
4752 struct device_attribute *attr,
4753 const char *buf, size_t count)
4754{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004755 struct iwl_priv *priv = dev_get_drvdata(d);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004756 int ret;
4757 unsigned long mode;
Zhu Yib481de92007-09-25 17:54:57 -07004758
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004759
Zhu Yib481de92007-09-25 17:54:57 -07004760 mutex_lock(&priv->mutex);
4761
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004762 if (!iwl_is_ready(priv)) {
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004763 ret = -EAGAIN;
Zhu Yib481de92007-09-25 17:54:57 -07004764 goto out;
4765 }
4766
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004767 ret = strict_strtoul(buf, 10, &mode);
4768 if (ret)
4769 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004770
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004771 ret = iwl_power_set_user_mode(priv, mode);
4772 if (ret) {
4773 IWL_DEBUG_MAC80211(priv, "failed setting power mode.\n");
4774 goto out;
Zhu Yib481de92007-09-25 17:54:57 -07004775 }
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004776 ret = count;
Zhu Yib481de92007-09-25 17:54:57 -07004777
4778 out:
4779 mutex_unlock(&priv->mutex);
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004780 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07004781}
4782
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08004783static ssize_t show_power_level(struct device *d,
4784 struct device_attribute *attr, char *buf)
4785{
4786 struct iwl_priv *priv = dev_get_drvdata(d);
4787 int mode = priv->power_data.user_power_setting;
4788 int system = priv->power_data.system_power_setting;
4789 int level = priv->power_data.power_mode;
4790 char *p = buf;
4791
4792 switch (system) {
4793 case IWL_POWER_SYS_AUTO:
4794 p += sprintf(p, "SYSTEM:auto");
4795 break;
4796 case IWL_POWER_SYS_AC:
4797 p += sprintf(p, "SYSTEM:ac");
4798 break;
4799 case IWL_POWER_SYS_BATTERY:
4800 p += sprintf(p, "SYSTEM:battery");
4801 break;
4802 }
4803
4804 p += sprintf(p, "\tMODE:%s", (mode < IWL_POWER_AUTO) ?
4805 "fixed" : "auto");
4806 p += sprintf(p, "\tINDEX:%d", level);
4807 p += sprintf(p, "\n");
4808 return p - buf + 1;
4809}
4810
4811static DEVICE_ATTR(power_level, S_IWUSR | S_IRUSR,
4812 show_power_level, store_power_level);
4813
Zhu Yib481de92007-09-25 17:54:57 -07004814#define MAX_WX_STRING 80
4815
4816/* Values are in microsecond */
4817static const s32 timeout_duration[] = {
4818 350000,
4819 250000,
4820 75000,
4821 37000,
4822 25000,
4823};
4824static const s32 period_duration[] = {
4825 400000,
4826 700000,
4827 1000000,
4828 1000000,
4829 1000000
4830};
4831
Zhu Yib481de92007-09-25 17:54:57 -07004832static ssize_t show_channels(struct device *d,
4833 struct device_attribute *attr, char *buf)
4834{
Johannes Berg8318d782008-01-24 19:38:38 +01004835 /* all this shit doesn't belong into sysfs anyway */
4836 return 0;
Zhu Yib481de92007-09-25 17:54:57 -07004837}
4838
4839static DEVICE_ATTR(channels, S_IRUSR, show_channels, NULL);
4840
4841static ssize_t show_statistics(struct device *d,
4842 struct device_attribute *attr, char *buf)
4843{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004844 struct iwl_priv *priv = dev_get_drvdata(d);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004845 u32 size = sizeof(struct iwl3945_notif_statistics);
Zhu Yib481de92007-09-25 17:54:57 -07004846 u32 len = 0, ofs = 0;
Abhijeet Kolekarf2c7e522008-12-19 10:37:27 +08004847 u8 *data = (u8 *)&priv->statistics_39;
Zhu Yib481de92007-09-25 17:54:57 -07004848 int rc = 0;
4849
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004850 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004851 return -EAGAIN;
4852
4853 mutex_lock(&priv->mutex);
Samuel Ortiz17f841c2009-01-23 13:45:20 -08004854 rc = iwl_send_statistics_request(priv, 0);
Zhu Yib481de92007-09-25 17:54:57 -07004855 mutex_unlock(&priv->mutex);
4856
4857 if (rc) {
4858 len = sprintf(buf,
4859 "Error sending statistics request: 0x%08X\n", rc);
4860 return len;
4861 }
4862
4863 while (size && (PAGE_SIZE - len)) {
4864 hex_dump_to_buffer(data + ofs, size, 16, 1, buf + len,
4865 PAGE_SIZE - len, 1);
4866 len = strlen(buf);
4867 if (PAGE_SIZE - len)
4868 buf[len++] = '\n';
4869
4870 ofs += 16;
4871 size -= min(size, 16U);
4872 }
4873
4874 return len;
4875}
4876
4877static DEVICE_ATTR(statistics, S_IRUGO, show_statistics, NULL);
4878
4879static ssize_t show_antenna(struct device *d,
4880 struct device_attribute *attr, char *buf)
4881{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004882 struct iwl_priv *priv = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004883
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004884 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004885 return -EAGAIN;
4886
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004887 return sprintf(buf, "%d\n", iwl3945_mod_params.antenna);
Zhu Yib481de92007-09-25 17:54:57 -07004888}
4889
4890static ssize_t store_antenna(struct device *d,
4891 struct device_attribute *attr,
4892 const char *buf, size_t count)
4893{
Winkler, Tomas7530f852009-01-27 14:27:53 -08004894 struct iwl_priv *priv __maybe_unused = dev_get_drvdata(d);
Zhu Yib481de92007-09-25 17:54:57 -07004895 int ant;
Zhu Yib481de92007-09-25 17:54:57 -07004896
4897 if (count == 0)
4898 return 0;
4899
4900 if (sscanf(buf, "%1i", &ant) != 1) {
Tomas Winklere1623442009-01-27 14:27:56 -08004901 IWL_DEBUG_INFO(priv, "not in hex or decimal form.\n");
Zhu Yib481de92007-09-25 17:54:57 -07004902 return count;
4903 }
4904
4905 if ((ant >= 0) && (ant <= 2)) {
Tomas Winklere1623442009-01-27 14:27:56 -08004906 IWL_DEBUG_INFO(priv, "Setting antenna select to %d.\n", ant);
Samuel Ortiz7e4bca52009-01-23 13:45:18 -08004907 iwl3945_mod_params.antenna = (enum iwl3945_antenna)ant;
Zhu Yib481de92007-09-25 17:54:57 -07004908 } else
Tomas Winklere1623442009-01-27 14:27:56 -08004909 IWL_DEBUG_INFO(priv, "Bad antenna select value %d.\n", ant);
Zhu Yib481de92007-09-25 17:54:57 -07004910
4911
4912 return count;
4913}
4914
4915static DEVICE_ATTR(antenna, S_IWUSR | S_IRUGO, show_antenna, store_antenna);
4916
4917static ssize_t show_status(struct device *d,
4918 struct device_attribute *attr, char *buf)
4919{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004920 struct iwl_priv *priv = (struct iwl_priv *)d->driver_data;
Kolekar, Abhijeet775a6e22008-12-19 10:37:36 +08004921 if (!iwl_is_alive(priv))
Zhu Yib481de92007-09-25 17:54:57 -07004922 return -EAGAIN;
4923 return sprintf(buf, "0x%08x\n", (int)priv->status);
4924}
4925
4926static DEVICE_ATTR(status, S_IRUGO, show_status, NULL);
4927
4928static ssize_t dump_error_log(struct device *d,
4929 struct device_attribute *attr,
4930 const char *buf, size_t count)
4931{
4932 char *p = (char *)buf;
4933
4934 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004935 iwl3945_dump_nic_error_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004936
4937 return strnlen(buf, count);
4938}
4939
4940static DEVICE_ATTR(dump_errors, S_IWUSR, NULL, dump_error_log);
4941
4942static ssize_t dump_event_log(struct device *d,
4943 struct device_attribute *attr,
4944 const char *buf, size_t count)
4945{
4946 char *p = (char *)buf;
4947
4948 if (p[0] == '1')
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004949 iwl3945_dump_nic_event_log((struct iwl_priv *)d->driver_data);
Zhu Yib481de92007-09-25 17:54:57 -07004950
4951 return strnlen(buf, count);
4952}
4953
4954static DEVICE_ATTR(dump_events, S_IWUSR, NULL, dump_event_log);
4955
4956/*****************************************************************************
4957 *
Tomas Winklera96a27f2008-10-23 23:48:56 -07004958 * driver setup and tear down
Zhu Yib481de92007-09-25 17:54:57 -07004959 *
4960 *****************************************************************************/
4961
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004962static void iwl3945_setup_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004963{
Reinette Chatred21050c2009-02-13 11:51:18 -08004964 priv->workqueue = create_singlethread_workqueue(DRV_NAME);
Zhu Yib481de92007-09-25 17:54:57 -07004965
4966 init_waitqueue_head(&priv->wait_command_queue);
4967
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004968 INIT_WORK(&priv->up, iwl3945_bg_up);
4969 INIT_WORK(&priv->restart, iwl3945_bg_restart);
4970 INIT_WORK(&priv->rx_replenish, iwl3945_bg_rx_replenish);
Samuel Ortizc0af96a2009-01-21 18:27:54 +01004971 INIT_WORK(&priv->rf_kill, iwl_bg_rf_kill);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004972 INIT_WORK(&priv->beacon_update, iwl3945_bg_beacon_update);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004973 INIT_DELAYED_WORK(&priv->init_alive_start, iwl3945_bg_init_alive_start);
4974 INIT_DELAYED_WORK(&priv->alive_start, iwl3945_bg_alive_start);
Helmut Schaa26635162009-01-15 09:38:44 +01004975 INIT_DELAYED_WORK(&priv->rfkill_poll, iwl3945_rfkill_poll);
Samuel Ortiz77fecfb82009-01-23 13:45:12 -08004976 INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed);
4977 INIT_WORK(&priv->request_scan, iwl3945_bg_request_scan);
4978 INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan);
4979 INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check);
Zhu Yib481de92007-09-25 17:54:57 -07004980
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004981 iwl3945_hw_setup_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004982
4983 tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long))
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004984 iwl3945_irq_tasklet, (unsigned long)priv);
Zhu Yib481de92007-09-25 17:54:57 -07004985}
4986
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08004987static void iwl3945_cancel_deferred_work(struct iwl_priv *priv)
Zhu Yib481de92007-09-25 17:54:57 -07004988{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004989 iwl3945_hw_cancel_deferred_work(priv);
Zhu Yib481de92007-09-25 17:54:57 -07004990
Joonwoo Parke47eb6a2007-11-29 10:42:49 +09004991 cancel_delayed_work_sync(&priv->init_alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004992 cancel_delayed_work(&priv->scan_check);
4993 cancel_delayed_work(&priv->alive_start);
Zhu Yib481de92007-09-25 17:54:57 -07004994 cancel_work_sync(&priv->beacon_update);
4995}
4996
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08004997static struct attribute *iwl3945_sysfs_entries[] = {
Zhu Yib481de92007-09-25 17:54:57 -07004998 &dev_attr_antenna.attr,
4999 &dev_attr_channels.attr,
5000 &dev_attr_dump_errors.attr,
5001 &dev_attr_dump_events.attr,
5002 &dev_attr_flags.attr,
5003 &dev_attr_filter_flags.attr,
Christoph Hellwigc8b0e6e2007-10-25 17:15:51 +08005004#ifdef CONFIG_IWL3945_SPECTRUM_MEASUREMENT
Zhu Yib481de92007-09-25 17:54:57 -07005005 &dev_attr_measurement.attr,
5006#endif
5007 &dev_attr_power_level.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005008 &dev_attr_retry_rate.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005009 &dev_attr_statistics.attr,
5010 &dev_attr_status.attr,
5011 &dev_attr_temperature.attr,
Zhu Yib481de92007-09-25 17:54:57 -07005012 &dev_attr_tx_power.attr,
Samuel Ortizd08853a2009-01-23 13:45:17 -08005013#ifdef CONFIG_IWLWIFI_DEBUG
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005014 &dev_attr_debug_level.attr,
5015#endif
Zhu Yib481de92007-09-25 17:54:57 -07005016 NULL
5017};
5018
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005019static struct attribute_group iwl3945_attribute_group = {
Zhu Yib481de92007-09-25 17:54:57 -07005020 .name = NULL, /* put in device directory */
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005021 .attrs = iwl3945_sysfs_entries,
Zhu Yib481de92007-09-25 17:54:57 -07005022};
5023
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005024static struct ieee80211_ops iwl3945_hw_ops = {
5025 .tx = iwl3945_mac_tx,
5026 .start = iwl3945_mac_start,
5027 .stop = iwl3945_mac_stop,
5028 .add_interface = iwl3945_mac_add_interface,
5029 .remove_interface = iwl3945_mac_remove_interface,
5030 .config = iwl3945_mac_config,
5031 .config_interface = iwl3945_mac_config_interface,
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005032 .configure_filter = iwl_configure_filter,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005033 .set_key = iwl3945_mac_set_key,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005034 .get_tx_stats = iwl3945_mac_get_tx_stats,
5035 .conf_tx = iwl3945_mac_conf_tx,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005036 .reset_tsf = iwl3945_mac_reset_tsf,
Abhijeet Kolekarcd56d332008-09-03 11:26:21 +08005037 .bss_info_changed = iwl3945_bss_info_changed,
Abhijeet Kolekare9dde6f62009-02-18 15:54:27 -08005038 .hw_scan = iwl_mac_hw_scan
Zhu Yib481de92007-09-25 17:54:57 -07005039};
5040
Winkler, Tomase52119c2008-12-22 11:31:19 +08005041static int iwl3945_init_drv(struct iwl_priv *priv)
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005042{
5043 int ret;
Samuel Ortize6148912009-01-23 13:45:15 -08005044 struct iwl3945_eeprom *eeprom = (struct iwl3945_eeprom *)priv->eeprom;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005045
5046 priv->retry_rate = 1;
5047 priv->ibss_beacon = NULL;
5048
5049 spin_lock_init(&priv->lock);
Winkler, Tomas3dae0c42009-01-19 15:30:30 -08005050 spin_lock_init(&priv->power_data.lock);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005051 spin_lock_init(&priv->sta_lock);
5052 spin_lock_init(&priv->hcmd_lock);
5053
5054 INIT_LIST_HEAD(&priv->free_frames);
5055
5056 mutex_init(&priv->mutex);
5057
5058 /* Clear the driver's (not device's) station table */
5059 iwl3945_clear_stations_table(priv);
5060
5061 priv->data_retry_limit = -1;
5062 priv->ieee_channels = NULL;
5063 priv->ieee_rates = NULL;
5064 priv->band = IEEE80211_BAND_2GHZ;
5065
5066 priv->iw_mode = NL80211_IFTYPE_STATION;
5067
5068 iwl_reset_qos(priv);
5069
5070 priv->qos_data.qos_active = 0;
5071 priv->qos_data.qos_cap.val = 0;
5072
5073 priv->rates_mask = IWL_RATES_MASK;
Winkler, Tomasd25aabb2009-01-27 14:27:58 -08005074 /* If power management is turned on, default to CAM mode */
5075 priv->power_mode = IWL_POWER_MODE_CAM;
Winkler, Tomas62ea9c52009-01-19 15:30:29 -08005076 priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005077
Samuel Ortize6148912009-01-23 13:45:15 -08005078 if (eeprom->version < EEPROM_3945_EEPROM_VERSION) {
5079 IWL_WARN(priv, "Unsupported EEPROM version: 0x%04X\n",
5080 eeprom->version);
5081 ret = -EINVAL;
5082 goto err;
5083 }
5084 ret = iwl_init_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005085 if (ret) {
5086 IWL_ERR(priv, "initializing regulatory failed: %d\n", ret);
5087 goto err;
5088 }
5089
Samuel Ortize6148912009-01-23 13:45:15 -08005090 /* Set up txpower settings in driver for all channels */
5091 if (iwl3945_txpower_set_from_eeprom(priv)) {
5092 ret = -EIO;
5093 goto err_free_channel_map;
5094 }
5095
Samuel Ortiz534166d2009-01-23 13:45:16 -08005096 ret = iwlcore_init_geos(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005097 if (ret) {
5098 IWL_ERR(priv, "initializing geos failed: %d\n", ret);
5099 goto err_free_channel_map;
5100 }
Samuel Ortiz534166d2009-01-23 13:45:16 -08005101 iwl3945_init_hw_rates(priv, priv->ieee_rates);
5102
5103 if (priv->bands[IEEE80211_BAND_2GHZ].n_channels)
5104 priv->hw->wiphy->bands[IEEE80211_BAND_2GHZ] =
5105 &priv->bands[IEEE80211_BAND_2GHZ];
5106 if (priv->bands[IEEE80211_BAND_5GHZ].n_channels)
5107 priv->hw->wiphy->bands[IEEE80211_BAND_5GHZ] =
5108 &priv->bands[IEEE80211_BAND_5GHZ];
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005109
5110 return 0;
5111
5112err_free_channel_map:
Samuel Ortize6148912009-01-23 13:45:15 -08005113 iwl_free_channel_map(priv);
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005114err:
5115 return ret;
5116}
5117
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005118static int iwl3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
Zhu Yib481de92007-09-25 17:54:57 -07005119{
5120 int err = 0;
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005121 struct iwl_priv *priv;
Zhu Yib481de92007-09-25 17:54:57 -07005122 struct ieee80211_hw *hw;
Kolekar, Abhijeetc0f20d92008-12-19 10:37:19 +08005123 struct iwl_cfg *cfg = (struct iwl_cfg *)(ent->driver_data);
Samuel Ortize6148912009-01-23 13:45:15 -08005124 struct iwl3945_eeprom *eeprom;
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005125 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005126
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005127 /***********************
5128 * 1. Allocating HW data
5129 * ********************/
5130
Zhu Yib481de92007-09-25 17:54:57 -07005131 /* mac80211 allocates memory for this device instance, including
5132 * space for this driver's private structure */
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005133 hw = iwl_alloc_all(cfg, &iwl3945_hw_ops);
Zhu Yib481de92007-09-25 17:54:57 -07005134 if (hw == NULL) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005135 printk(KERN_ERR DRV_NAME "Can not allocate network device\n");
Zhu Yib481de92007-09-25 17:54:57 -07005136 err = -ENOMEM;
5137 goto out;
5138 }
Zhu Yib481de92007-09-25 17:54:57 -07005139 priv = hw->priv;
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005140 SET_IEEE80211_DEV(hw, &pdev->dev);
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005141
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005142 if ((iwl3945_mod_params.num_of_queues > IWL39_MAX_NUM_QUEUES) ||
5143 (iwl3945_mod_params.num_of_queues < IWL_MIN_NUM_QUEUES)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005144 IWL_ERR(priv,
5145 "invalid queues_num, should be between %d and %d\n",
5146 IWL_MIN_NUM_QUEUES, IWL39_MAX_NUM_QUEUES);
Samuel Ortiza3139c52008-12-19 10:37:09 +08005147 err = -EINVAL;
5148 goto out;
5149 }
5150
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005151 /*
5152 * Disabling hardware scan means that mac80211 will perform scans
5153 * "the hard way", rather than using device's scan.
5154 */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005155 if (iwl3945_mod_params.disable_hw_scan) {
Tomas Winklere1623442009-01-27 14:27:56 -08005156 IWL_DEBUG_INFO(priv, "Disabling hw_scan\n");
Samuel Ortiz40b8ec02008-12-19 10:37:08 +08005157 iwl3945_hw_ops.hw_scan = NULL;
5158 }
5159
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005160
Tomas Winklere1623442009-01-27 14:27:56 -08005161 IWL_DEBUG_INFO(priv, "*** LOAD DRIVER ***\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005162 priv->cfg = cfg;
5163 priv->pci_dev = pdev;
5164
Samuel Ortizd08853a2009-01-23 13:45:17 -08005165#ifdef CONFIG_IWLWIFI_DEBUG
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005166 priv->debug_level = iwl3945_mod_params.debug;
5167 atomic_set(&priv->restrict_refcnt, 0);
5168#endif
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005169 hw->rate_control_algorithm = "iwl-3945-rs";
5170 hw->sta_data_size = sizeof(struct iwl3945_sta_priv);
5171
Bruno Randolf566bfe52008-05-08 19:15:40 +02005172 /* Tell mac80211 our characteristics */
Johannes Berg605a0bd2008-07-15 10:10:01 +02005173 hw->flags = IEEE80211_HW_SIGNAL_DBM |
Bruno Randolf566bfe52008-05-08 19:15:40 +02005174 IEEE80211_HW_NOISE_DBM;
Zhu Yib481de92007-09-25 17:54:57 -07005175
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005176 hw->wiphy->interface_modes =
Luis R. Rodriguezf59ac042008-08-29 16:26:43 -07005177 BIT(NL80211_IFTYPE_STATION) |
5178 BIT(NL80211_IFTYPE_ADHOC);
5179
Luis R. Rodriguez2a44f912009-01-22 15:05:49 -08005180 hw->wiphy->custom_regulatory = true;
Luis R. Rodriguezea4a82dc2008-11-12 14:22:04 -08005181
Johannes Berg2a519312009-02-10 21:25:55 +01005182 hw->wiphy->max_scan_ssids = 1;
5183
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005184 /* 4 EDCA QOS priorities */
Zhu Yib481de92007-09-25 17:54:57 -07005185 hw->queues = 4;
5186
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005187 /***************************
5188 * 2. Initializing PCI bus
5189 * *************************/
Zhu Yib481de92007-09-25 17:54:57 -07005190 if (pci_enable_device(pdev)) {
5191 err = -ENODEV;
5192 goto out_ieee80211_free_hw;
5193 }
5194
5195 pci_set_master(pdev);
5196
Zhu Yib481de92007-09-25 17:54:57 -07005197 err = pci_set_dma_mask(pdev, DMA_32BIT_MASK);
5198 if (!err)
5199 err = pci_set_consistent_dma_mask(pdev, DMA_32BIT_MASK);
5200 if (err) {
Tomas Winkler978785a2008-12-19 10:37:31 +08005201 IWL_WARN(priv, "No suitable DMA available.\n");
Zhu Yib481de92007-09-25 17:54:57 -07005202 goto out_pci_disable_device;
5203 }
5204
5205 pci_set_drvdata(pdev, priv);
5206 err = pci_request_regions(pdev, DRV_NAME);
5207 if (err)
5208 goto out_pci_disable_device;
Cahill, Ben M6440adb2007-11-29 11:09:55 +08005209
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005210 /***********************
5211 * 3. Read REV Register
5212 * ********************/
Zhu Yib481de92007-09-25 17:54:57 -07005213 priv->hw_base = pci_iomap(pdev, 0, 0);
5214 if (!priv->hw_base) {
5215 err = -ENODEV;
5216 goto out_pci_release_regions;
5217 }
5218
Tomas Winklere1623442009-01-27 14:27:56 -08005219 IWL_DEBUG_INFO(priv, "pci_resource_len = 0x%08llx\n",
Zhu Yib481de92007-09-25 17:54:57 -07005220 (unsigned long long) pci_resource_len(pdev, 0));
Tomas Winklere1623442009-01-27 14:27:56 -08005221 IWL_DEBUG_INFO(priv, "pci_resource_base = %p\n", priv->hw_base);
Zhu Yib481de92007-09-25 17:54:57 -07005222
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005223 /* We disable the RETRY_TIMEOUT register (0x41) to keep
5224 * PCI Tx retries from interfering with C3 CPU state */
5225 pci_write_config_byte(pdev, 0x41, 0x00);
Zhu Yib481de92007-09-25 17:54:57 -07005226
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005227 /* amp init */
5228 err = priv->cfg->ops->lib->apm_ops.init(priv);
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005229 if (err < 0) {
Tomas Winklere1623442009-01-27 14:27:56 -08005230 IWL_DEBUG_INFO(priv, "Failed to init APMG\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005231 goto out_iounmap;
Tomas Winkler3ac7f142008-07-21 02:40:14 +03005232 }
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005233
5234 /***********************
5235 * 4. Read EEPROM
5236 * ********************/
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005237
Zhu Yi5a66926a2008-01-14 17:46:18 -08005238 /* Read the EEPROM */
Samuel Ortize6148912009-01-23 13:45:15 -08005239 err = iwl_eeprom_init(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005240 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005241 IWL_ERR(priv, "Unable to init EEPROM\n");
Zhu Yi5a66926a2008-01-14 17:46:18 -08005242 goto out_remove_sysfs;
5243 }
5244 /* MAC Address location in EEPROM same for 3945/4965 */
Samuel Ortize6148912009-01-23 13:45:15 -08005245 eeprom = (struct iwl3945_eeprom *)priv->eeprom;
5246 memcpy(priv->mac_addr, eeprom->mac_address, ETH_ALEN);
Tomas Winklere1623442009-01-27 14:27:56 -08005247 IWL_DEBUG_INFO(priv, "MAC address: %pM\n", priv->mac_addr);
Zhu Yi5a66926a2008-01-14 17:46:18 -08005248 SET_IEEE80211_PERM_ADDR(priv->hw, priv->mac_addr);
5249
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005250 /***********************
5251 * 5. Setup HW Constants
5252 * ********************/
5253 /* Device-specific setup */
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005254 if (iwl3945_hw_set_hw_params(priv)) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005255 IWL_ERR(priv, "failed to set hw settings\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005256 goto out_iounmap;
5257 }
5258
5259 /***********************
5260 * 6. Setup priv
5261 * ********************/
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005262
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005263 err = iwl3945_init_drv(priv);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005264 if (err) {
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005265 IWL_ERR(priv, "initializing driver failed\n");
5266 goto out_free_geos;
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005267 }
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005268
Tomas Winkler978785a2008-12-19 10:37:31 +08005269 IWL_INFO(priv, "Detected Intel Wireless WiFi Link %s\n",
5270 priv->cfg->name);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005271
5272 /***********************************
5273 * 7. Initialize Module Parameters
5274 * **********************************/
5275
5276 /* Initialize module parameter values here */
5277 /* Disable radio (SW RF KILL) via parameter when loading driver */
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005278 if (iwl3945_mod_params.disable) {
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005279 set_bit(STATUS_RF_KILL_SW, &priv->status);
Tomas Winklere1623442009-01-27 14:27:56 -08005280 IWL_DEBUG_INFO(priv, "Radio disabled.\n");
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005281 }
5282
5283
5284 /***********************
5285 * 8. Setup Services
5286 * ********************/
5287
5288 spin_lock_irqsave(&priv->lock, flags);
5289 iwl3945_disable_interrupts(priv);
5290 spin_unlock_irqrestore(&priv->lock, flags);
5291
Helmut Schaa26635162009-01-15 09:38:44 +01005292 pci_enable_msi(priv->pci_dev);
5293
5294 err = request_irq(priv->pci_dev->irq, iwl3945_isr, IRQF_SHARED,
5295 DRV_NAME, priv);
5296 if (err) {
5297 IWL_ERR(priv, "Error allocating IRQ %d\n", priv->pci_dev->irq);
5298 goto out_disable_msi;
5299 }
5300
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005301 err = sysfs_create_group(&pdev->dev.kobj, &iwl3945_attribute_group);
5302 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005303 IWL_ERR(priv, "failed to create sysfs device attributes\n");
Kolekar, Abhijeet90a30a02008-12-19 10:37:40 +08005304 goto out_release_irq;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005305 }
5306
Samuel Ortiz8ccde882009-01-27 14:27:52 -08005307 iwl_set_rxon_channel(priv,
5308 &priv->bands[IEEE80211_BAND_2GHZ].channels[5]);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005309 iwl3945_setup_deferred_work(priv);
5310 iwl3945_setup_rx_handlers(priv);
5311
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005312 /*********************************
Helmut Schaa26635162009-01-15 09:38:44 +01005313 * 9. Setup and Register mac80211
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005314 * *******************************/
5315
Zhu Yi5a66926a2008-01-14 17:46:18 -08005316 err = ieee80211_register_hw(priv->hw);
5317 if (err) {
Winkler, Tomas15b16872008-12-19 10:37:33 +08005318 IWL_ERR(priv, "Failed to register network device: %d\n", err);
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005319 goto out_remove_sysfs;
Zhu Yib481de92007-09-25 17:54:57 -07005320 }
5321
Zhu Yi5a66926a2008-01-14 17:46:18 -08005322 priv->hw->conf.beacon_int = 100;
5323 priv->mac80211_registered = 1;
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005324
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005325 err = iwl_rfkill_init(priv);
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005326 if (err)
Winkler, Tomas15b16872008-12-19 10:37:33 +08005327 IWL_ERR(priv, "Unable to initialize RFKILL system. "
Abhijeet Kolekarebef2002008-06-30 17:23:18 +08005328 "Ignoring error: %d\n", err);
5329
Helmut Schaa26635162009-01-15 09:38:44 +01005330 /* Start monitoring the killswitch */
5331 queue_delayed_work(priv->workqueue, &priv->rfkill_poll,
5332 2 * HZ);
5333
Zhu Yib481de92007-09-25 17:54:57 -07005334 return 0;
5335
Kolekar, Abhijeetcee53dd2008-11-12 13:14:04 -08005336 out_remove_sysfs:
5337 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Reinette Chatre849e0dc2008-01-23 10:15:18 -08005338 out_free_geos:
Samuel Ortiz534166d2009-01-23 13:45:16 -08005339 iwlcore_free_geos(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005340
5341 out_release_irq:
Helmut Schaa26635162009-01-15 09:38:44 +01005342 free_irq(priv->pci_dev->irq, priv);
Zhu Yib481de92007-09-25 17:54:57 -07005343 destroy_workqueue(priv->workqueue);
5344 priv->workqueue = NULL;
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005345 iwl3945_unset_hw_params(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005346 out_disable_msi:
5347 pci_disable_msi(priv->pci_dev);
Zhu Yib481de92007-09-25 17:54:57 -07005348 out_iounmap:
5349 pci_iounmap(pdev, priv->hw_base);
5350 out_pci_release_regions:
5351 pci_release_regions(pdev);
5352 out_pci_disable_device:
5353 pci_disable_device(pdev);
5354 pci_set_drvdata(pdev, NULL);
5355 out_ieee80211_free_hw:
5356 ieee80211_free_hw(priv->hw);
5357 out:
5358 return err;
5359}
5360
Reinette Chatrec83dbf62008-03-21 13:53:41 -07005361static void __devexit iwl3945_pci_remove(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005362{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005363 struct iwl_priv *priv = pci_get_drvdata(pdev);
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005364 unsigned long flags;
Zhu Yib481de92007-09-25 17:54:57 -07005365
5366 if (!priv)
5367 return;
5368
Tomas Winklere1623442009-01-27 14:27:56 -08005369 IWL_DEBUG_INFO(priv, "*** UNLOAD DRIVER ***\n");
Zhu Yib481de92007-09-25 17:54:57 -07005370
Zhu Yib481de92007-09-25 17:54:57 -07005371 set_bit(STATUS_EXIT_PENDING, &priv->status);
Zhu Yib24d22b2007-12-19 13:59:52 +08005372
Kolekar, Abhijeetd552bfb2008-12-19 10:37:41 +08005373 if (priv->mac80211_registered) {
5374 ieee80211_unregister_hw(priv->hw);
5375 priv->mac80211_registered = 0;
5376 } else {
5377 iwl3945_down(priv);
5378 }
Zhu Yib481de92007-09-25 17:54:57 -07005379
Mohamed Abbas0359fac2008-03-28 16:21:08 -07005380 /* make sure we flush any pending irq or
5381 * tasklet for the driver
5382 */
5383 spin_lock_irqsave(&priv->lock, flags);
5384 iwl3945_disable_interrupts(priv);
5385 spin_unlock_irqrestore(&priv->lock, flags);
5386
5387 iwl_synchronize_irq(priv);
5388
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005389 sysfs_remove_group(&pdev->dev.kobj, &iwl3945_attribute_group);
Zhu Yib481de92007-09-25 17:54:57 -07005390
Samuel Ortizc0af96a2009-01-21 18:27:54 +01005391 iwl_rfkill_unregister(priv);
Helmut Schaa26635162009-01-15 09:38:44 +01005392 cancel_delayed_work(&priv->rfkill_poll);
5393
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005394 iwl3945_dealloc_ucode_pci(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005395
5396 if (priv->rxq.bd)
Winkler, Tomas51af3d32008-12-22 11:31:23 +08005397 iwl_rx_queue_free(priv, &priv->rxq);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005398 iwl3945_hw_txq_ctx_free(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005399
Abhijeet Kolekar3832ec92008-12-19 10:37:26 +08005400 iwl3945_unset_hw_params(priv);
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005401 iwl3945_clear_stations_table(priv);
Zhu Yib481de92007-09-25 17:54:57 -07005402
Mohamed Abbas6ef89d02007-10-25 17:15:47 +08005403 /*netif_stop_queue(dev); */
5404 flush_workqueue(priv->workqueue);
5405
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005406 /* ieee80211_unregister_hw calls iwl3945_mac_stop, which flushes
Zhu Yib481de92007-09-25 17:54:57 -07005407 * priv->workqueue... so we can't take down the workqueue
5408 * until now... */
5409 destroy_workqueue(priv->workqueue);
5410 priv->workqueue = NULL;
5411
Helmut Schaa26635162009-01-15 09:38:44 +01005412 free_irq(pdev->irq, priv);
5413 pci_disable_msi(pdev);
5414
Zhu Yib481de92007-09-25 17:54:57 -07005415 pci_iounmap(pdev, priv->hw_base);
5416 pci_release_regions(pdev);
5417 pci_disable_device(pdev);
5418 pci_set_drvdata(pdev, NULL);
5419
Samuel Ortize6148912009-01-23 13:45:15 -08005420 iwl_free_channel_map(priv);
Samuel Ortiz534166d2009-01-23 13:45:16 -08005421 iwlcore_free_geos(priv);
Winkler, Tomas805cee52009-01-19 15:30:28 -08005422 kfree(priv->scan);
Zhu Yib481de92007-09-25 17:54:57 -07005423 if (priv->ibss_beacon)
5424 dev_kfree_skb(priv->ibss_beacon);
5425
5426 ieee80211_free_hw(priv->hw);
5427}
5428
5429#ifdef CONFIG_PM
5430
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005431static int iwl3945_pci_suspend(struct pci_dev *pdev, pm_message_t state)
Zhu Yib481de92007-09-25 17:54:57 -07005432{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005433 struct iwl_priv *priv = pci_get_drvdata(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005434
Zhu Yie655b9f2008-01-24 02:19:38 -08005435 if (priv->is_open) {
5436 set_bit(STATUS_IN_SUSPEND, &priv->status);
5437 iwl3945_mac_stop(priv->hw);
5438 priv->is_open = 1;
5439 }
Helmut Schaa26635162009-01-15 09:38:44 +01005440 pci_save_state(pdev);
5441 pci_disable_device(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005442 pci_set_power_state(pdev, PCI_D3hot);
5443
Zhu Yib481de92007-09-25 17:54:57 -07005444 return 0;
5445}
5446
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005447static int iwl3945_pci_resume(struct pci_dev *pdev)
Zhu Yib481de92007-09-25 17:54:57 -07005448{
Abhijeet Kolekar4a8a4322008-12-19 10:37:28 +08005449 struct iwl_priv *priv = pci_get_drvdata(pdev);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005450 int ret;
Zhu Yib481de92007-09-25 17:54:57 -07005451
Zhu Yib481de92007-09-25 17:54:57 -07005452 pci_set_power_state(pdev, PCI_D0);
Winkler, Tomas450154e2009-01-27 14:27:55 -08005453 ret = pci_enable_device(pdev);
5454 if (ret)
5455 return ret;
Helmut Schaa26635162009-01-15 09:38:44 +01005456 pci_restore_state(pdev);
Zhu Yib481de92007-09-25 17:54:57 -07005457
Zhu Yie655b9f2008-01-24 02:19:38 -08005458 if (priv->is_open)
5459 iwl3945_mac_start(priv->hw);
Zhu Yib481de92007-09-25 17:54:57 -07005460
Zhu Yie655b9f2008-01-24 02:19:38 -08005461 clear_bit(STATUS_IN_SUSPEND, &priv->status);
Zhu Yib481de92007-09-25 17:54:57 -07005462 return 0;
5463}
5464
5465#endif /* CONFIG_PM */
5466
5467/*****************************************************************************
5468 *
5469 * driver and module entry point
5470 *
5471 *****************************************************************************/
5472
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005473static struct pci_driver iwl3945_driver = {
Zhu Yib481de92007-09-25 17:54:57 -07005474 .name = DRV_NAME,
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005475 .id_table = iwl3945_hw_card_ids,
5476 .probe = iwl3945_pci_probe,
5477 .remove = __devexit_p(iwl3945_pci_remove),
Zhu Yib481de92007-09-25 17:54:57 -07005478#ifdef CONFIG_PM
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005479 .suspend = iwl3945_pci_suspend,
5480 .resume = iwl3945_pci_resume,
Zhu Yib481de92007-09-25 17:54:57 -07005481#endif
5482};
5483
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005484static int __init iwl3945_init(void)
Zhu Yib481de92007-09-25 17:54:57 -07005485{
5486
5487 int ret;
5488 printk(KERN_INFO DRV_NAME ": " DRV_DESCRIPTION ", " DRV_VERSION "\n");
5489 printk(KERN_INFO DRV_NAME ": " DRV_COPYRIGHT "\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005490
5491 ret = iwl3945_rate_control_register();
5492 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005493 printk(KERN_ERR DRV_NAME
5494 "Unable to register rate control algorithm: %d\n", ret);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005495 return ret;
5496 }
5497
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005498 ret = pci_register_driver(&iwl3945_driver);
Zhu Yib481de92007-09-25 17:54:57 -07005499 if (ret) {
Samuel Ortiza3139c52008-12-19 10:37:09 +08005500 printk(KERN_ERR DRV_NAME "Unable to initialize PCI module\n");
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005501 goto error_register;
Zhu Yib481de92007-09-25 17:54:57 -07005502 }
Zhu Yib481de92007-09-25 17:54:57 -07005503
5504 return ret;
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005505
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005506error_register:
5507 iwl3945_rate_control_unregister();
5508 return ret;
Zhu Yib481de92007-09-25 17:54:57 -07005509}
5510
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005511static void __exit iwl3945_exit(void)
Zhu Yib481de92007-09-25 17:54:57 -07005512{
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005513 pci_unregister_driver(&iwl3945_driver);
Reinette Chatre897e1cf2008-03-28 16:21:09 -07005514 iwl3945_rate_control_unregister();
Zhu Yib481de92007-09-25 17:54:57 -07005515}
5516
Reinette Chatrea0987a82008-12-02 12:14:06 -08005517MODULE_FIRMWARE(IWL3945_MODULE_FIRMWARE(IWL3945_UCODE_API_MAX));
Zhu Yi25cb6ca2008-09-11 11:45:22 +08005518
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005519module_param_named(antenna, iwl3945_mod_params.antenna, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005520MODULE_PARM_DESC(antenna, "select antenna (1=Main, 2=Aux, default 0 [both])");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005521module_param_named(disable, iwl3945_mod_params.disable, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005522MODULE_PARM_DESC(disable, "manually disable the radio (default 0 [radio on])");
Samuel Ortiz9c74d9f2009-01-08 10:19:59 -08005523module_param_named(swcrypto, iwl3945_mod_params.sw_crypto, int, 0444);
5524MODULE_PARM_DESC(swcrypto,
5525 "using software crypto (default 1 [software])\n");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005526module_param_named(debug, iwl3945_mod_params.debug, uint, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005527MODULE_PARM_DESC(debug, "debug output mask");
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005528module_param_named(disable_hw_scan, iwl3945_mod_params.disable_hw_scan, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005529MODULE_PARM_DESC(disable_hw_scan, "disable hardware scanning (default 0)");
5530
Kolekar, Abhijeetdf878d82008-12-19 10:37:35 +08005531module_param_named(queues_num, iwl3945_mod_params.num_of_queues, int, 0444);
Zhu Yib481de92007-09-25 17:54:57 -07005532MODULE_PARM_DESC(queues_num, "number of hw queues.");
5533
Samuel Ortizaf48d042009-01-23 13:45:19 -08005534module_param_named(fw_restart3945, iwl3945_mod_params.restart_fw, int, 0444);
5535MODULE_PARM_DESC(fw_restart3945, "restart firmware in case of error");
5536
Christoph Hellwigbb8c0932008-01-27 16:41:47 -08005537module_exit(iwl3945_exit);
5538module_init(iwl3945_init);